wobsoriano / lexical-vue

An extensible Vue 3 web text-editor based on Lexical.
https://lexical-vue.vercel.app/
MIT License
251 stars 30 forks source link

Node Overrides causes type error in "initialConfig". #19

Closed vj-kimura closed 1 year ago

vj-kimura commented 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.

スクリーンショット 2023-06-21 19 02 00

I think the reason is that lexical-vue does not define replace in Nodes. ...Or is there any way to work around this error?


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;
}>;
wobsoriano commented 1 year ago

Copied the react package types for node. Can you check if it's fixed?

vj-kimura commented 1 year ago

It looks like it's working correctly! There is no error. Thanks.

スクリーンショット 2023-06-24 22 28 22
wobsoriano commented 1 year ago

Cool! Closing this now 😉

vj-kimura commented 1 year ago

Thank you!