mirror of https://github.com/buster-so/buster.git
Editor is working
This commit is contained in:
parent
409af5e02e
commit
7e40fbd769
|
@ -42,7 +42,6 @@ export type EditorProps = PlateContentProps & VariantProps<typeof editorVariants
|
|||
|
||||
export const Editor = React.forwardRef<HTMLDivElement, EditorProps>(
|
||||
({ className, disabled, focused, variant, ...props }, ref) => {
|
||||
console.log('Editor', { className, disabled, focused, variant, ...props });
|
||||
return (
|
||||
<PlateContent
|
||||
ref={ref}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { EditorContainer } from './EditorContainer';
|
|||
import { Editor } from './Editor';
|
||||
import { useReportEditor } from './useReportEditor';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
import { ReportElements } from '@buster/server-shared/reports';
|
||||
import { ReportElements, type ReportElement } from '@buster/server-shared/reports';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ThemeWrapper } from './ThemeWrapper/ThemeWrapper';
|
||||
|
||||
|
@ -62,7 +62,7 @@ export const ReportEditor = React.memo(
|
|||
|
||||
const onValueChangePreflight = useMemoizedFn(
|
||||
({ value, editor }: { value: Value; editor: TPlateEditor<Value, AnyPluginConfig> }) => {
|
||||
onValueChange?.(value as ReportElements);
|
||||
onValueChange?.(cleanValueToReportElements(value));
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -92,3 +92,22 @@ export const ReportEditor = React.memo(
|
|||
);
|
||||
|
||||
ReportEditor.displayName = 'ReportEditor';
|
||||
|
||||
const cleanValueToReportElements = (value: Value): ReportElements => {
|
||||
const filteredElements: ReportElements = value
|
||||
.filter((element) => element.type !== 'slash_input')
|
||||
.map<ReportElement>((element) => {
|
||||
// If the element has a children array, filter its children as well
|
||||
if (Array.isArray(element.children)) {
|
||||
return {
|
||||
...element,
|
||||
children: element.children.filter((child) => {
|
||||
return child.type !== 'slash_input';
|
||||
})
|
||||
} as ReportElement;
|
||||
}
|
||||
return element as ReportElement;
|
||||
});
|
||||
|
||||
return filteredElements;
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ export const ReportPageController: React.FC<{
|
|||
updateReport({ reportId, name });
|
||||
});
|
||||
|
||||
const { run: debouncedUpdateReport } = useDebounceFn(updateReport, { wait: 300 });
|
||||
const { run: debouncedUpdateReport } = useDebounceFn(updateReport, { wait: 650 });
|
||||
|
||||
const onChangeContent = useMemoizedFn((content: ReportElements) => {
|
||||
debouncedUpdateReport({ reportId, content });
|
||||
|
|
Loading…
Reference in New Issue