Closed vj-kimura closed 1 year ago
Official sample code https://lexical.dev/docs/concepts/node-replacement
const editorConfig = { ... nodes=[ // Don't forget to register your custom node separately! CustomParagraphNode, { replace: ParagraphNode, with: (node: ParagraphNode) => { return new CustomParagraphNode(); } } ] }
I tried this code in lexical-vue, but it caused a type error in initialConfig.
initialConfig
I think the reason is that lexical-vue does not define replace in Nodes. ...Or is there any way to work around this error?
replace
Nodes
lexical-vue src/components/LexicalComposer.vue
const props = defineProps<{ initialConfig: { namespace?: string nodes?: Class<LexicalNode>[] editable?: boolean theme?: EditorThemeClasses editorState?: InitialEditorStateType } }>()
Origin (lexical-react) https://github.com/facebook/lexical/blob/main/packages/lexical-react/src/LexicalComposer.tsx
export type InitialConfigType = Readonly<{ editor__DEPRECATED?: LexicalEditor | null; namespace: string; nodes?: ReadonlyArray< | Klass<LexicalNode> | { replace: Klass<LexicalNode>; // eslint-disable-next-line @typescript-eslint/no-explicit-any with: <T extends {new (...args: any): any}>( node: InstanceType<T>, ) => LexicalNode; } >; onError: (error: Error, editor: LexicalEditor) => void; editable?: boolean; theme?: EditorThemeClasses; editorState?: InitialEditorStateType; }>;
Copied the react package types for node. Can you check if it's fixed?
It looks like it's working correctly! There is no error. Thanks.
Cool! Closing this now 😉
Thank you!
Official sample code https://lexical.dev/docs/concepts/node-replacement
I tried this code in lexical-vue, but it caused a type error in
initialConfig
.I think the reason is that lexical-vue does not define
replace
inNodes
. ...Or is there any way to work around this error?lexical-vue src/components/LexicalComposer.vue
Origin (lexical-react) https://github.com/facebook/lexical/blob/main/packages/lexical-react/src/LexicalComposer.tsx