@payloadcms/richtext-lexical 3.68.0-internal-debug.35482da → 3.68.0-internal-debug.654e4ad

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/exports/client/index.d.ts +1 -0
  2. package/dist/exports/client/index.d.ts.map +1 -1
  3. package/dist/exports/client/index.js +1 -0
  4. package/dist/exports/client/index.js.map +1 -1
  5. package/dist/exports/client/internal-client.d.ts +3 -0
  6. package/dist/exports/client/internal-client.d.ts.map +1 -0
  7. package/dist/exports/client/internal-client.js +4 -0
  8. package/dist/exports/client/internal-client.js.map +1 -0
  9. package/dist/exports/react/index.d.ts +1 -1
  10. package/dist/exports/react/index.d.ts.map +1 -1
  11. package/dist/exports/react/index.js.map +1 -1
  12. package/dist/features/blocks/client/component/index.js +2 -2
  13. package/dist/features/blocks/client/component/index.js.map +1 -1
  14. package/dist/features/blocks/client/componentInline/index.js +2 -2
  15. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  16. package/dist/features/blocks/server/nodes/BlocksNode.js.map +1 -1
  17. package/dist/features/blocks/server/nodes/InlineBlocksNode.js.map +1 -1
  18. package/dist/features/converters/lexicalToJSX/Component/index.d.ts +2 -14
  19. package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
  20. package/dist/features/converters/lexicalToJSX/Component/index.js +4 -9
  21. package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
  22. package/dist/features/converters/lexicalToJSX/converter/index.d.ts +16 -1
  23. package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
  24. package/dist/features/converters/lexicalToJSX/converter/index.js +87 -5
  25. package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
  26. package/dist/features/converters/lexicalToJSX/converter/types.d.ts +14 -10
  27. package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
  28. package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
  29. package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
  30. package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
  31. package/dist/features/link/nodes/LinkNode.js.map +1 -1
  32. package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
  33. package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
  34. package/dist/features/relationship/server/nodes/RelationshipNode.js.map +1 -1
  35. package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
  36. package/dist/field/Field.d.ts.map +1 -1
  37. package/dist/field/Field.js +37 -21
  38. package/dist/field/Field.js.map +1 -1
  39. package/dist/field/RichTextViewProvider.d.ts +83 -0
  40. package/dist/field/RichTextViewProvider.d.ts.map +1 -0
  41. package/dist/field/RichTextViewProvider.js +102 -0
  42. package/dist/field/RichTextViewProvider.js.map +1 -0
  43. package/dist/field/ViewSelector.d.ts +4 -0
  44. package/dist/field/ViewSelector.d.ts.map +1 -0
  45. package/dist/field/ViewSelector.js +90 -0
  46. package/dist/field/ViewSelector.js.map +1 -0
  47. package/dist/field/ViewSelector.scss +34 -0
  48. package/dist/field/index.d.ts +1 -0
  49. package/dist/field/index.d.ts.map +1 -1
  50. package/dist/field/index.js +41 -16
  51. package/dist/field/index.js.map +1 -1
  52. package/dist/field/index.scss +12 -0
  53. package/dist/field/rscEntry.d.ts +1 -1
  54. package/dist/field/rscEntry.d.ts.map +1 -1
  55. package/dist/field/rscEntry.js +13 -1
  56. package/dist/field/rscEntry.js.map +1 -1
  57. package/dist/index.d.ts +1 -1
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +3 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  62. package/dist/lexical/LexicalEditor.js +34 -28
  63. package/dist/lexical/LexicalEditor.js.map +1 -1
  64. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  65. package/dist/lexical/LexicalProvider.js +19 -11
  66. package/dist/lexical/LexicalProvider.js.map +1 -1
  67. package/dist/lexical/config/client/sanitize.d.ts +1 -1
  68. package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
  69. package/dist/lexical/config/client/sanitize.js +3 -2
  70. package/dist/lexical/config/client/sanitize.js.map +1 -1
  71. package/dist/lexical/config/types.d.ts +4 -0
  72. package/dist/lexical/config/types.d.ts.map +1 -1
  73. package/dist/lexical/config/types.js +3 -1
  74. package/dist/lexical/config/types.js.map +1 -1
  75. package/dist/lexical/nodes/index.d.ts +12 -2
  76. package/dist/lexical/nodes/index.d.ts.map +1 -1
  77. package/dist/lexical/nodes/index.js +187 -2
  78. package/dist/lexical/nodes/index.js.map +1 -1
  79. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +2 -0
  80. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +1 -0
  81. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +31 -0
  82. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -0
  83. package/dist/lexical/utils/point.js.map +1 -1
  84. package/dist/lexical/utils/rect.js.map +1 -1
  85. package/dist/types.d.ts +152 -2
  86. package/dist/types.d.ts.map +1 -1
  87. package/dist/types.js +55 -0
  88. package/dist/types.js.map +1 -1
  89. package/dist/utilities/fieldsDrawer/DrawerContent.js +2 -2
  90. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
  91. package/dist/utilities/generateImportMap.d.ts.map +1 -1
  92. package/dist/utilities/generateImportMap.js +1 -0
  93. package/dist/utilities/generateImportMap.js.map +1 -1
  94. package/dist/validate/hasText.d.ts +6 -1
  95. package/dist/validate/hasText.d.ts.map +1 -1
  96. package/dist/validate/hasText.js +10 -4
  97. package/dist/validate/hasText.js.map +1 -1
  98. package/package.json +13 -8
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lexical/LexicalEditor.tsx"],"sourcesContent":["'use client'\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary.js'\nimport { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin.js'\nimport { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin.js'\nimport { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { BLUR_COMMAND, COMMAND_PRIORITY_LOW, FOCUS_COMMAND } from 'lexical'\nimport * as React from 'react'\nimport { useEffect, useState } from 'react'\n\nimport type { LexicalProviderProps } from './LexicalProvider.js'\n\nimport { useEditorConfigContext } from './config/client/EditorConfigProvider.js'\nimport './LexicalEditor.scss'\nimport { EditorPlugin } from './EditorPlugin.js'\nimport { ClipboardPlugin } from './plugins/ClipboardPlugin/index.js'\nimport { DecoratorPlugin } from './plugins/DecoratorPlugin/index.js'\nimport { AddBlockHandlePlugin } from './plugins/handles/AddBlockHandlePlugin/index.js'\nimport { DraggableBlockPlugin } from './plugins/handles/DraggableBlockPlugin/index.js'\nimport { InsertParagraphAtEndPlugin } from './plugins/InsertParagraphAtEnd/index.js'\nimport { MarkdownShortcutPlugin } from './plugins/MarkdownShortcut/index.js'\nimport { NormalizeSelectionPlugin } from './plugins/NormalizeSelection/index.js'\nimport { SelectAllPlugin } from './plugins/SelectAllPlugin/index.js'\nimport { SlashMenuPlugin } from './plugins/SlashMenu/index.js'\nimport { TextPlugin } from './plugins/TextPlugin/index.js'\nimport { LexicalContentEditable } from './ui/ContentEditable.js'\n\nexport const LexicalEditor: React.FC<\n {\n editorContainerRef: React.RefObject<HTMLDivElement | null>\n isSmallWidthViewport: boolean\n } & Pick<LexicalProviderProps, 'editorConfig' | 'onChange'>\n> = (props) => {\n const { editorConfig, editorContainerRef, isSmallWidthViewport, onChange } = props\n const editorConfigContext = useEditorConfigContext()\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLDivElement | null>(null)\n const onRef = (_floatingAnchorElem: HTMLDivElement) => {\n if (_floatingAnchorElem !== null) {\n setFloatingAnchorElem(_floatingAnchorElem)\n }\n }\n\n useEffect(() => {\n if (!editorConfigContext?.uuid) {\n console.error('Lexical Editor must be used within an EditorConfigProvider')\n return\n }\n if (editorConfigContext?.parentEditor?.uuid) {\n editorConfigContext.parentEditor?.registerChild(editorConfigContext.uuid, editorConfigContext)\n }\n\n const handleFocus = () => {\n editorConfigContext.focusEditor(editorConfigContext)\n }\n\n const handleBlur = () => {\n editorConfigContext.blurEditor(editorConfigContext)\n }\n\n const unregisterFocus = editor.registerCommand<MouseEvent>(\n FOCUS_COMMAND,\n () => {\n handleFocus()\n return true\n },\n COMMAND_PRIORITY_LOW,\n )\n\n const unregisterBlur = editor.registerCommand<MouseEvent>(\n BLUR_COMMAND,\n () => {\n handleBlur()\n return true\n },\n COMMAND_PRIORITY_LOW,\n )\n\n return () => {\n unregisterFocus()\n unregisterBlur()\n editorConfigContext.parentEditor?.unregisterChild?.(editorConfigContext.uuid)\n }\n }, [editor, editorConfigContext])\n\n return (\n <React.Fragment>\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'aboveContainer') {\n return <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n }\n })}\n <div className=\"editor-container\" ref={editorContainerRef}>\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'top') {\n return (\n <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n )\n }\n })}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\">\n <div className=\"editor\" ref={onRef}>\n <LexicalContentEditable editorConfig={editorConfig} />\n </div>\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n />\n <NormalizeSelectionPlugin />\n {isEditable && <InsertParagraphAtEndPlugin />}\n <DecoratorPlugin />\n <ClipboardPlugin />\n <TextPlugin features={editorConfig.features} />\n <SelectAllPlugin />\n {isEditable && (\n <OnChangePlugin\n // Selection changes can be ignored here, reducing the\n // frequency that the FieldComponent and Payload receive updates.\n // Selection changes are only needed if you are saving selection state\n ignoreSelectionChange\n onChange={(editorState, editor, tags) => {\n // Ignore any onChange event triggered by focus only\n if (!tags.has('focus') || tags.size > 1) {\n if (onChange != null) {\n onChange(editorState, editor, tags)\n }\n }\n }}\n />\n )}\n {floatingAnchorElem && (\n <React.Fragment>\n {!isSmallWidthViewport && isEditable && (\n <React.Fragment>\n {editorConfig.admin?.hideDraggableBlockElement ? null : (\n <DraggableBlockPlugin anchorElem={floatingAnchorElem} />\n )}\n {editorConfig.admin?.hideAddBlockButton ? null : (\n <AddBlockHandlePlugin anchorElem={floatingAnchorElem} />\n )}\n </React.Fragment>\n )}\n {editorConfig.features.plugins?.map((plugin) => {\n if (\n plugin.position === 'floatingAnchorElem' &&\n !(plugin.desktopOnly === true && isSmallWidthViewport)\n ) {\n return (\n <EditorPlugin\n anchorElem={floatingAnchorElem}\n clientProps={plugin.clientProps}\n key={plugin.key}\n plugin={plugin}\n />\n )\n }\n })}\n {isEditable && (\n <React.Fragment>\n <SlashMenuPlugin anchorElem={floatingAnchorElem} />\n </React.Fragment>\n )}\n </React.Fragment>\n )}\n {isEditable && (\n <React.Fragment>\n <HistoryPlugin />\n {editorConfig?.features?.markdownTransformers?.length > 0 && <MarkdownShortcutPlugin />}\n </React.Fragment>\n )}\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'normal') {\n return (\n <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n )\n }\n })}\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'bottom') {\n return (\n <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n )\n }\n })}\n </div>\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'belowContainer') {\n return <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n }\n })}\n </React.Fragment>\n )\n}\n"],"names":["useLexicalComposerContext","LexicalErrorBoundary","HistoryPlugin","OnChangePlugin","RichTextPlugin","useLexicalEditable","BLUR_COMMAND","COMMAND_PRIORITY_LOW","FOCUS_COMMAND","React","useEffect","useState","useEditorConfigContext","EditorPlugin","ClipboardPlugin","DecoratorPlugin","AddBlockHandlePlugin","DraggableBlockPlugin","InsertParagraphAtEndPlugin","MarkdownShortcutPlugin","NormalizeSelectionPlugin","SelectAllPlugin","SlashMenuPlugin","TextPlugin","LexicalContentEditable","LexicalEditor","props","editorConfig","editorContainerRef","isSmallWidthViewport","onChange","editorConfigContext","editor","isEditable","floatingAnchorElem","setFloatingAnchorElem","onRef","_floatingAnchorElem","uuid","console","error","parentEditor","registerChild","handleFocus","focusEditor","handleBlur","blurEditor","unregisterFocus","registerCommand","unregisterBlur","unregisterChild","Fragment","features","plugins","map","plugin","position","clientProps","key","div","className","ref","contentEditable","ErrorBoundary","ignoreSelectionChange","editorState","tags","has","size","admin","hideDraggableBlockElement","anchorElem","hideAddBlockButton","desktopOnly","markdownTransformers","length"],"mappings":"AAAA;;AACA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,oBAAoB,QAAQ,yCAAwC;AAC7E,SAASC,aAAa,QAAQ,yCAAwC;AACtE,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,YAAY,EAAEC,oBAAoB,EAAEC,aAAa,QAAQ,UAAS;AAC3E,YAAYC,WAAW,QAAO;AAC9B,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAI3C,SAASC,sBAAsB,QAAQ,0CAAyC;AAChF,OAAO,uBAAsB;AAC7B,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,oBAAoB,QAAQ,kDAAiD;AACtF,SAASC,oBAAoB,QAAQ,kDAAiD;AACtF,SAASC,0BAA0B,QAAQ,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or.tsx"],"sourcesContent":["'use client'\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary.js'\nimport { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin.js'\nimport { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin.js'\nimport { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { BLUR_COMMAND, COMMAND_PRIORITY_LOW, FOCUS_COMMAND } from 'lexical'\nimport * as React from 'react'\nimport { useEffect, useState } from 'react'\n\nimport type { LexicalProviderProps } from './LexicalProvider.js'\n\nimport { useEditorConfigContext } from './config/client/EditorConfigProvider.js'\nimport './LexicalEditor.scss'\nimport { EditorPlugin } from './EditorPlugin.js'\nimport { ClipboardPlugin } from './plugins/ClipboardPlugin/index.js'\nimport { DecoratorPlugin } from './plugins/DecoratorPlugin/index.js'\nimport { AddBlockHandlePlugin } from './plugins/handles/AddBlockHandlePlugin/index.js'\nimport { DraggableBlockPlugin } from './plugins/handles/DraggableBlockPlugin/index.js'\nimport { InsertParagraphAtEndPlugin } from './plugins/InsertParagraphAtEnd/index.js'\nimport { MarkdownShortcutPlugin } from './plugins/MarkdownShortcut/index.js'\nimport { NodeViewOverridePlugin } from './plugins/NodeViewOverridePlugin/index.js'\nimport { NormalizeSelectionPlugin } from './plugins/NormalizeSelection/index.js'\nimport { SelectAllPlugin } from './plugins/SelectAllPlugin/index.js'\nimport { SlashMenuPlugin } from './plugins/SlashMenu/index.js'\nimport { TextPlugin } from './plugins/TextPlugin/index.js'\nimport { LexicalContentEditable } from './ui/ContentEditable.js'\n\nexport const LexicalEditor: React.FC<\n {\n editorContainerRef: React.RefObject<HTMLDivElement | null>\n isSmallWidthViewport: boolean\n } & Pick<LexicalProviderProps, 'editorConfig' | 'onChange'>\n> = (props) => {\n const { editorConfig, editorContainerRef, isSmallWidthViewport, onChange } = props\n const editorConfigContext = useEditorConfigContext()\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLDivElement | null>(null)\n const onRef = (_floatingAnchorElem: HTMLDivElement) => {\n if (_floatingAnchorElem !== null) {\n setFloatingAnchorElem(_floatingAnchorElem)\n }\n }\n\n useEffect(() => {\n if (!editorConfigContext?.uuid) {\n console.error('Lexical Editor must be used within an EditorConfigProvider')\n return\n }\n if (editorConfigContext?.parentEditor?.uuid) {\n editorConfigContext.parentEditor?.registerChild(editorConfigContext.uuid, editorConfigContext)\n }\n\n const handleFocus = () => {\n editorConfigContext.focusEditor(editorConfigContext)\n }\n\n const handleBlur = () => {\n editorConfigContext.blurEditor(editorConfigContext)\n }\n\n const unregisterFocus = editor.registerCommand<MouseEvent>(\n FOCUS_COMMAND,\n () => {\n handleFocus()\n return true\n },\n COMMAND_PRIORITY_LOW,\n )\n\n const unregisterBlur = editor.registerCommand<MouseEvent>(\n BLUR_COMMAND,\n () => {\n handleBlur()\n return true\n },\n COMMAND_PRIORITY_LOW,\n )\n\n return () => {\n unregisterFocus()\n unregisterBlur()\n editorConfigContext.parentEditor?.unregisterChild?.(editorConfigContext.uuid)\n }\n }, [editor, editorConfigContext])\n\n return (\n <React.Fragment>\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'aboveContainer') {\n return <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n }\n })}\n <div className=\"editor-container\" ref={editorContainerRef}>\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'top') {\n return (\n <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n )\n }\n })}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\">\n <div className=\"editor\" ref={onRef}>\n <LexicalContentEditable editorConfig={editorConfig} />\n </div>\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n />\n <NormalizeSelectionPlugin />\n {isEditable && <InsertParagraphAtEndPlugin />}\n <DecoratorPlugin />\n <ClipboardPlugin />\n <TextPlugin features={editorConfig.features} />\n <SelectAllPlugin />\n <NodeViewOverridePlugin />\n {isEditable && (\n <OnChangePlugin\n // Selection changes can be ignored here, reducing the\n // frequency that the FieldComponent and Payload receive updates.\n // Selection changes are only needed if you are saving selection state\n ignoreSelectionChange\n onChange={(editorState, editor, tags) => {\n // Ignore any onChange event triggered by focus only\n if (!tags.has('focus') || tags.size > 1) {\n if (onChange != null) {\n onChange(editorState, editor, tags)\n }\n }\n }}\n />\n )}\n {floatingAnchorElem && (\n <React.Fragment>\n {!isSmallWidthViewport && isEditable && (\n <React.Fragment>\n {editorConfig.admin?.hideDraggableBlockElement ? null : (\n <DraggableBlockPlugin anchorElem={floatingAnchorElem} />\n )}\n {editorConfig.admin?.hideAddBlockButton ? null : (\n <AddBlockHandlePlugin anchorElem={floatingAnchorElem} />\n )}\n </React.Fragment>\n )}\n {editorConfig.features.plugins?.map((plugin) => {\n if (\n plugin.position === 'floatingAnchorElem' &&\n !(plugin.desktopOnly === true && isSmallWidthViewport)\n ) {\n return (\n <EditorPlugin\n anchorElem={floatingAnchorElem}\n clientProps={plugin.clientProps}\n key={plugin.key}\n plugin={plugin}\n />\n )\n }\n })}\n {isEditable && (\n <React.Fragment>\n <SlashMenuPlugin anchorElem={floatingAnchorElem} />\n </React.Fragment>\n )}\n </React.Fragment>\n )}\n {isEditable && (\n <React.Fragment>\n <HistoryPlugin />\n {editorConfig?.features?.markdownTransformers?.length > 0 && <MarkdownShortcutPlugin />}\n </React.Fragment>\n )}\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'normal') {\n return (\n <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n )\n }\n })}\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'bottom') {\n return (\n <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n )\n }\n })}\n </div>\n {editorConfig.features.plugins?.map((plugin) => {\n if (plugin.position === 'belowContainer') {\n return <EditorPlugin clientProps={plugin.clientProps} key={plugin.key} plugin={plugin} />\n }\n })}\n </React.Fragment>\n )\n}\n"],"names":["useLexicalComposerContext","LexicalErrorBoundary","HistoryPlugin","OnChangePlugin","RichTextPlugin","useLexicalEditable","BLUR_COMMAND","COMMAND_PRIORITY_LOW","FOCUS_COMMAND","React","useEffect","useState","useEditorConfigContext","EditorPlugin","ClipboardPlugin","DecoratorPlugin","AddBlockHandlePlugin","DraggableBlockPlugin","InsertParagraphAtEndPlugin","MarkdownShortcutPlugin","NodeViewOverridePlugin","NormalizeSelectionPlugin","SelectAllPlugin","SlashMenuPlugin","TextPlugin","LexicalContentEditable","LexicalEditor","props","editorConfig","editorContainerRef","isSmallWidthViewport","onChange","editorConfigContext","editor","isEditable","floatingAnchorElem","setFloatingAnchorElem","onRef","_floatingAnchorElem","uuid","console","error","parentEditor","registerChild","handleFocus","focusEditor","handleBlur","blurEditor","unregisterFocus","registerCommand","unregisterBlur","unregisterChild","Fragment","features","plugins","map","plugin","position","clientProps","key","div","className","ref","contentEditable","ErrorBoundary","ignoreSelectionChange","editorState","tags","has","size","admin","hideDraggableBlockElement","anchorElem","hideAddBlockButton","desktopOnly","markdownTransformers","length"],"mappings":"AAAA;;AACA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,oBAAoB,QAAQ,yCAAwC;AAC7E,SAASC,aAAa,QAAQ,yCAAwC;AACtE,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,YAAY,EAAEC,oBAAoB,EAAEC,aAAa,QAAQ,UAAS;AAC3E,YAAYC,WAAW,QAAO;AAC9B,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAI3C,SAASC,sBAAsB,QAAQ,0CAAyC;AAChF,OAAO,uBAAsB;AAC7B,SAASC,YAAY,QAAQ,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,EAAEC,IAAI,CAACC;gBACnC,IAAIA,OAAOC,QAAQ,KAAK,kBAAkB;oBACxC,qBAAO,QAAC5C;wBAAa6C,aAAaF,OAAOE,WAAW;wBAAmBF,QAAQA;uBAApBA,OAAOG,GAAG;;;;;gBACvE;YACF;;;;;;;AAGN,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"LexicalProvider.d.ts","sourceRoot":"","sources":["../../src/lexical/LexicalProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIhF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAA;AASpE,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,2BAA2B,CAAA;IACzC,UAAU,EAAE,yBAAyB,CAAA;IACrC,oBAAoB,EAAE,OAAO,CAAA;IAC7B,QAAQ,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IACtF,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,qBAAqB,CAAA;CAC7B,CAAA;AAwBD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAyE1D,CAAA"}
1
+ {"version":3,"file":"LexicalProvider.d.ts","sourceRoot":"","sources":["../../src/lexical/LexicalProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIhF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAA;AAUpE,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,2BAA2B,CAAA;IACzC,UAAU,EAAE,yBAAyB,CAAA;IACrC,oBAAoB,EAAE,OAAO,CAAA;IAC7B,QAAQ,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IACtF,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,qBAAqB,CAAA;CAC7B,CAAA;AAwBD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAqF1D,CAAA"}
@@ -4,6 +4,7 @@ import { LexicalComposer } from '@lexical/react/LexicalComposer.js';
4
4
  import { useEditDepth } from '@payloadcms/ui';
5
5
  import * as React from 'react';
6
6
  import { useMemo } from 'react';
7
+ import { useRichTextView } from '../field/RichTextViewProvider.js';
7
8
  import { EditorConfigProvider, useEditorConfigContext } from './config/client/EditorConfigProvider.js';
8
9
  import { LexicalEditor as LexicalEditorComponent } from './LexicalEditor.js';
9
10
  import { getEnabledNodes } from './nodes/index.js';
@@ -20,12 +21,12 @@ const NestProviders = ({ children, providers })=>// eslint-disable-next-line @ty
20
21
  children: children
21
22
  }, void 0, false, {
22
23
  fileName: "src/lexical/LexicalProvider.tsx",
23
- lineNumber: 45,
24
+ lineNumber: 46,
24
25
  columnNumber: 9
25
26
  }, this)
26
27
  }, void 0, false, {
27
28
  fileName: "src/lexical/LexicalProvider.tsx",
28
- lineNumber: 44,
29
+ lineNumber: 45,
29
30
  columnNumber: 7
30
31
  }, this);
31
32
  }
@@ -33,12 +34,13 @@ const NestProviders = ({ children, providers })=>// eslint-disable-next-line @ty
33
34
  children: children
34
35
  }, void 0, false, {
35
36
  fileName: "src/lexical/LexicalProvider.tsx",
36
- lineNumber: 49,
37
+ lineNumber: 50,
37
38
  columnNumber: 10
38
39
  }, this);
39
40
  };
40
41
  export const LexicalProvider = (props)=>{
41
42
  const { composerKey, editorConfig, fieldProps, isSmallWidthViewport, onChange, readOnly, value } = props;
43
+ const { currentView, views } = useRichTextView();
42
44
  const parentContext = useEditorConfigContext();
43
45
  const editDepth = useEditDepth();
44
46
  const editorContainerRef = React.useRef(null);
@@ -53,12 +55,15 @@ export const LexicalProvider = (props)=>{
53
55
  if (value && 'jsonContent' in value) {
54
56
  throw new Error('You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical');
55
57
  }
58
+ // Use the 'default' view if available, otherwise undefined
59
+ const nodeViews = views?.[currentView]?.nodes;
56
60
  return {
57
61
  editable: readOnly !== true,
58
62
  editorState: value != null ? JSON.stringify(value) : undefined,
59
63
  namespace: editorConfig.lexical.namespace,
60
64
  nodes: getEnabledNodes({
61
- editorConfig
65
+ editorConfig,
66
+ nodeViews
62
67
  }),
63
68
  onError: (error)=>{
64
69
  throw error;
@@ -68,19 +73,22 @@ export const LexicalProvider = (props)=>{
68
73
  }, // Important: do not add readOnly and value to the dependencies array. This will cause the entire lexical editor to re-render if the document is saved, which will
69
74
  // cause the editor to lose focus.
70
75
  [
71
- editorConfig
76
+ editorConfig,
77
+ views,
78
+ currentView
72
79
  ]);
73
80
  if (!initialConfig) {
74
81
  return /*#__PURE__*/ _jsxDEV("p", {
75
82
  children: "Loading..."
76
83
  }, void 0, false, {
77
84
  fileName: "src/lexical/LexicalProvider.tsx",
78
- lineNumber: 98,
85
+ lineNumber: 107,
79
86
  columnNumber: 12
80
87
  }, this);
81
88
  }
82
89
  // We need to add initialConfig.editable to the key to force a re-render when the readOnly prop changes.
83
90
  // Without it, there were cases where lexical editors inside drawers turn readOnly initially - a few miliseconds later they turn editable, but the editor does not re-render and stays readOnly.
91
+ // We also add currentView to force re-render when the view changes.
84
92
  return /*#__PURE__*/ _jsxDEV(LexicalComposer, {
85
93
  initialConfig: initialConfig,
86
94
  children: /*#__PURE__*/ _jsxDEV(EditorConfigProvider, {
@@ -99,22 +107,22 @@ export const LexicalProvider = (props)=>{
99
107
  onChange: onChange
100
108
  }, void 0, false, {
101
109
  fileName: "src/lexical/LexicalProvider.tsx",
102
- lineNumber: 115,
110
+ lineNumber: 128,
103
111
  columnNumber: 11
104
112
  }, this)
105
113
  }, void 0, false, {
106
114
  fileName: "src/lexical/LexicalProvider.tsx",
107
- lineNumber: 114,
115
+ lineNumber: 127,
108
116
  columnNumber: 9
109
117
  }, this)
110
118
  }, void 0, false, {
111
119
  fileName: "src/lexical/LexicalProvider.tsx",
112
- lineNumber: 105,
120
+ lineNumber: 118,
113
121
  columnNumber: 7
114
122
  }, this)
115
- }, composerKey + initialConfig.editable, false, {
123
+ }, composerKey + initialConfig.editable + currentView, false, {
116
124
  fileName: "src/lexical/LexicalProvider.tsx",
117
- lineNumber: 104,
125
+ lineNumber: 114,
118
126
  columnNumber: 5
119
127
  }, this);
120
128
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lexical/LexicalProvider.tsx"],"sourcesContent":["'use client'\nimport type { InitialConfigType } from '@lexical/react/LexicalComposer.js'\nimport type { EditorState, LexicalEditor, SerializedEditorState } from 'lexical'\n\nimport { LexicalComposer } from '@lexical/react/LexicalComposer.js'\nimport { useEditDepth } from '@payloadcms/ui'\nimport * as React from 'react'\nimport { useMemo } from 'react'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\nimport type { SanitizedClientEditorConfig } from './config/types.js'\n\nimport {\n EditorConfigProvider,\n useEditorConfigContext,\n} from './config/client/EditorConfigProvider.js'\nimport { LexicalEditor as LexicalEditorComponent } from './LexicalEditor.js'\nimport { getEnabledNodes } from './nodes/index.js'\n\nexport type LexicalProviderProps = {\n composerKey: string\n editorConfig: SanitizedClientEditorConfig\n fieldProps: LexicalRichTextFieldProps\n isSmallWidthViewport: boolean\n onChange: (editorState: EditorState, editor: LexicalEditor, tags: Set<string>) => void\n readOnly: boolean\n value: SerializedEditorState\n}\n\nconst NestProviders = ({\n children,\n providers,\n}: {\n children: React.ReactNode\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n providers: any[]\n}) => {\n if (!providers?.length) {\n return children\n }\n const Component = providers[0]\n if (providers.length > 1) {\n return (\n <Component>\n <NestProviders providers={providers.slice(1)}>{children}</NestProviders>\n </Component>\n )\n }\n return <Component>{children}</Component>\n}\n\nexport const LexicalProvider: React.FC<LexicalProviderProps> = (props) => {\n const { composerKey, editorConfig, fieldProps, isSmallWidthViewport, onChange, readOnly, value } =\n props\n\n const parentContext = useEditorConfigContext()\n\n const editDepth = useEditDepth()\n\n const editorContainerRef = React.useRef<HTMLDivElement>(null)\n\n // useMemo for the initialConfig that depends on readOnly and value\n const initialConfig = useMemo<InitialConfigType>(() => {\n if (value && typeof value !== 'object') {\n throw new Error(\n 'The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: ' +\n JSON.stringify(value),\n )\n }\n\n if (value && Array.isArray(value) && !('root' in value)) {\n throw new Error(\n 'You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended',\n )\n }\n\n if (value && 'jsonContent' in value) {\n throw new Error(\n 'You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical',\n )\n }\n\n return {\n editable: readOnly !== true,\n editorState: value != null ? JSON.stringify(value) : undefined,\n namespace: editorConfig.lexical.namespace,\n nodes: getEnabledNodes({ editorConfig }),\n onError: (error: Error) => {\n throw error\n },\n theme: editorConfig.lexical.theme,\n }\n // Important: do not add readOnly and value to the dependencies array. This will cause the entire lexical editor to re-render if the document is saved, which will\n // cause the editor to lose focus.\n }, [editorConfig])\n\n if (!initialConfig) {\n return <p>Loading...</p>\n }\n\n // We need to add initialConfig.editable to the key to force a re-render when the readOnly prop changes.\n // Without it, there were cases where lexical editors inside drawers turn readOnly initially - a few miliseconds later they turn editable, but the editor does not re-render and stays readOnly.\n return (\n <LexicalComposer initialConfig={initialConfig} key={composerKey + initialConfig.editable}>\n <EditorConfigProvider\n editorConfig={editorConfig}\n editorContainerRef={editorContainerRef}\n fieldProps={fieldProps}\n /**\n * Parent editor is not truly the parent editor, if the current editor is part of a drawer and the parent editor is the main editor.\n */\n parentContext={parentContext?.editDepth === editDepth ? parentContext : undefined}\n >\n <NestProviders providers={editorConfig.features.providers}>\n <LexicalEditorComponent\n editorConfig={editorConfig}\n editorContainerRef={editorContainerRef}\n isSmallWidthViewport={isSmallWidthViewport}\n onChange={onChange}\n />\n </NestProviders>\n </EditorConfigProvider>\n </LexicalComposer>\n )\n}\n"],"names":["LexicalComposer","useEditDepth","React","useMemo","EditorConfigProvider","useEditorConfigContext","LexicalEditor","LexicalEditorComponent","getEnabledNodes","NestProviders","children","providers","length","Component","slice","LexicalProvider","props","composerKey","editorConfig","fieldProps","isSmallWidthViewport","onChange","readOnly","value","parentContext","editDepth","editorContainerRef","useRef","initialConfig","Error","JSON","stringify","Array","isArray","editable","editorState","undefined","namespace","lexical","nodes","onError","error","theme","p","features"],"mappings":"AAAA;;AAIA,SAASA,eAAe,QAAQ,oCAAmC;AACnE,SAASC,YAAY,QAAQ,iBAAgB;AAC7C,YAAYC,WAAW,QAAO;AAC9B,SAASC,OAAO,QAAQ,QAAO;AAK/B,SACEC,oBAAoB,EACpBC,sBAAsB,QACjB,0CAAyC;AAChD,SAASC,iBAAiBC,sBAAsB,QAAQ,qBAAoB;AAC5E,SAASC,eAAe,QAAQ,mBAAkB;AAYlD,MAAMC,gBAAgB,CAAC,EACrBC,QAAQ,EACRC,SAAS,EAKV,GAFC,8DAA8D;;IAG9D,IAAI,CAACA,WAA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C3C;QAAgB4B,eAAeA;kBAC9B,cAAA,QAACxB;YACCc,cAAcA;YACdQ,oBAAoBA;YACpBP,YAAYA;YACZ;;SAEC,GACDK,eAAeA,eAAeC,cAAcA,YAAYD,gBAAgBY;sBAExE,cAAA,QAAC3B;gBAAcE,WAAWO,aAAa0B,QAAQ,CAACjC,SAAS;0BACvD,cAAA,QAACJ;oBACCW,cAAcA;oBACdQ,oBAAoBA;oBACpBN,sBAAsBA;oBACtBC,UAAUA;;;;;;;;;;;;;;;;OAfkCJ,cAAcW,cAAcM,QAAQ;;;;;AAqB5F,EAAC"}
1
+ {"version":3,"sources":["../../src/lexical/LexicalProvider.tsx"],"sourcesContent":["'use client'\nimport type { InitialConfigType } from '@lexical/react/LexicalComposer.js'\nimport type { EditorState, LexicalEditor, SerializedEditorState } from 'lexical'\n\nimport { LexicalComposer } from '@lexical/react/LexicalComposer.js'\nimport { useEditDepth } from '@payloadcms/ui'\nimport * as React from 'react'\nimport { useMemo } from 'react'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\nimport type { SanitizedClientEditorConfig } from './config/types.js'\n\nimport { useRichTextView } from '../field/RichTextViewProvider.js'\nimport {\n EditorConfigProvider,\n useEditorConfigContext,\n} from './config/client/EditorConfigProvider.js'\nimport { LexicalEditor as LexicalEditorComponent } from './LexicalEditor.js'\nimport { getEnabledNodes } from './nodes/index.js'\n\nexport type LexicalProviderProps = {\n composerKey: string\n editorConfig: SanitizedClientEditorConfig\n fieldProps: LexicalRichTextFieldProps\n isSmallWidthViewport: boolean\n onChange: (editorState: EditorState, editor: LexicalEditor, tags: Set<string>) => void\n readOnly: boolean\n value: SerializedEditorState\n}\n\nconst NestProviders = ({\n children,\n providers,\n}: {\n children: React.ReactNode\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n providers: any[]\n}) => {\n if (!providers?.length) {\n return children\n }\n const Component = providers[0]\n if (providers.length > 1) {\n return (\n <Component>\n <NestProviders providers={providers.slice(1)}>{children}</NestProviders>\n </Component>\n )\n }\n return <Component>{children}</Component>\n}\n\nexport const LexicalProvider: React.FC<LexicalProviderProps> = (props) => {\n const { composerKey, editorConfig, fieldProps, isSmallWidthViewport, onChange, readOnly, value } =\n props\n\n const { currentView, views } = useRichTextView()\n\n const parentContext = useEditorConfigContext()\n\n const editDepth = useEditDepth()\n\n const editorContainerRef = React.useRef<HTMLDivElement>(null)\n\n // useMemo for the initialConfig that depends on readOnly and value\n const initialConfig = useMemo<InitialConfigType>(() => {\n if (value && typeof value !== 'object') {\n throw new Error(\n 'The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: ' +\n JSON.stringify(value),\n )\n }\n\n if (value && Array.isArray(value) && !('root' in value)) {\n throw new Error(\n 'You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended',\n )\n }\n\n if (value && 'jsonContent' in value) {\n throw new Error(\n 'You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical',\n )\n }\n\n // Use the 'default' view if available, otherwise undefined\n const nodeViews = views?.[currentView]?.nodes\n\n return {\n editable: readOnly !== true,\n editorState: value != null ? JSON.stringify(value) : undefined,\n namespace: editorConfig.lexical.namespace,\n nodes: getEnabledNodes({\n editorConfig,\n nodeViews,\n }),\n onError: (error: Error) => {\n throw error\n },\n theme: editorConfig.lexical.theme,\n }\n // Important: do not add readOnly and value to the dependencies array. This will cause the entire lexical editor to re-render if the document is saved, which will\n // cause the editor to lose focus.\n }, [editorConfig, views, currentView])\n\n if (!initialConfig) {\n return <p>Loading...</p>\n }\n\n // We need to add initialConfig.editable to the key to force a re-render when the readOnly prop changes.\n // Without it, there were cases where lexical editors inside drawers turn readOnly initially - a few miliseconds later they turn editable, but the editor does not re-render and stays readOnly.\n // We also add currentView to force re-render when the view changes.\n return (\n <LexicalComposer\n initialConfig={initialConfig}\n key={composerKey + initialConfig.editable + currentView}\n >\n <EditorConfigProvider\n editorConfig={editorConfig}\n editorContainerRef={editorContainerRef}\n fieldProps={fieldProps}\n /**\n * Parent editor is not truly the parent editor, if the current editor is part of a drawer and the parent editor is the main editor.\n */\n parentContext={parentContext?.editDepth === editDepth ? parentContext : undefined}\n >\n <NestProviders providers={editorConfig.features.providers}>\n <LexicalEditorComponent\n editorConfig={editorConfig}\n editorContainerRef={editorContainerRef}\n isSmallWidthViewport={isSmallWidthViewport}\n onChange={onChange}\n />\n </NestProviders>\n </EditorConfigProvider>\n </LexicalComposer>\n )\n}\n"],"names":["LexicalComposer","useEditDepth","React","useMemo","useRichTextView","EditorConfigProvider","useEditorConfigContext","LexicalEditor","LexicalEditorComponent","getEnabledNodes","NestProviders","children","providers","length","Component","slice","LexicalProvider","props","composerKey","editorConfig","fieldProps","isSmallWidthViewport","onChange","readOnly","value","currentView","views","parentContext","editDepth","editorContainerRef","useRef","initialConfig","Error","JSON","stringify","Array","isArray","nodeViews","nodes","editable","editorState","undefined","namespace","lexical","onError","error","theme","p","features"],"mappings":"AAAA;;AAIA,SAASA,eAAe,QAAQ,oCAAmC;AACnE,SAASC,YAAY,QAAQ,iBAAgB;AAC7C,YAAYC,WAAW,QAAO;AAC9B,SAASC,OAAO,QAAQ,QAAO;AAK/B,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SACEC,oBAAoB,EACpBC,sBAAsB,QACjB,0CAAyC;AAChD,SAASC,iBAAiBC,sBAAsB,QAAQ,qBAAoB;AAC5E,SAASC,eAAe,QAAQ,mBAAkB;AAYlD,MAAMC,gBAAgB,CAAC,EACrBC,QAAQ,EACRC,SAAS,EAKV,GAFC,8DAA8D;;IAG9D,IAAI,CAACA,WAAWC,QAAQ;QACtB,OAAOF;IACT;IACA,MAAMG,YAAYF,SAAS,CAAC,EAAE;IAC9B,IAAIA,UAAUC,MAAM,GAAG,GAAG;QACxB,qBAC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G,gMAAgM;IAChM,oEAAoE;IACpE,qBACE,QAAC/C;QACC+B,eAAeA;kBAGf,cAAA,QAAC1B;YACCc,cAAcA;YACdU,oBAAoBA;YACpBT,YAAYA;YACZ;;SAEC,GACDO,eAAeA,eAAeC,cAAcA,YAAYD,gBAAgBc;sBAExE,cAAA,QAAC/B;gBAAcE,WAAWO,aAAa6B,QAAQ,CAACpC,SAAS;0BACvD,cAAA,QAACJ;oBACCW,cAAcA;oBACdU,oBAAoBA;oBACpBR,sBAAsBA;oBACtBC,UAAUA;;;;;;;;;;;;;;;;OAhBXJ,cAAca,cAAcQ,QAAQ,GAAGd;;;;;AAsBlD,EAAC"}
@@ -3,5 +3,5 @@ import type { ResolvedClientFeatureMap, SanitizedClientFeatures } from '../../..
3
3
  import type { LexicalFieldAdminClientProps } from '../../../types.js';
4
4
  import type { SanitizedClientEditorConfig } from '../types.js';
5
5
  export declare const sanitizeClientFeatures: (features: ResolvedClientFeatureMap) => SanitizedClientFeatures;
6
- export declare function sanitizeClientEditorConfig(resolvedClientFeatureMap: ResolvedClientFeatureMap, lexical?: LexicalEditorConfig, admin?: LexicalFieldAdminClientProps): SanitizedClientEditorConfig;
6
+ export declare function sanitizeClientEditorConfig(resolvedClientFeatureMap: ResolvedClientFeatureMap, lexical?: LexicalEditorConfig, admin?: LexicalFieldAdminClientProps, view?: string): SanitizedClientEditorConfig;
7
7
  //# sourceMappingURL=sanitize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../../src/lexical/config/client/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAKlE,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAE9D,eAAO,MAAM,sBAAsB,aACvB,wBAAwB,KACjC,uBAiOF,CAAA;AAED,wBAAgB,0BAA0B,CACxC,wBAAwB,EAAE,wBAAwB,EAClD,OAAO,CAAC,EAAE,mBAAmB,EAC7B,KAAK,CAAC,EAAE,4BAA4B,GACnC,2BAA2B,CAO7B"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../../src/lexical/config/client/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAKlE,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAE9D,eAAO,MAAM,sBAAsB,aACvB,wBAAwB,KACjC,uBAiOF,CAAA;AAED,wBAAgB,0BAA0B,CACxC,wBAAwB,EAAE,wBAAwB,EAClD,OAAO,CAAC,EAAE,mBAAmB,EAC7B,KAAK,CAAC,EAAE,4BAA4B,EACpC,IAAI,CAAC,EAAE,MAAM,GACZ,2BAA2B,CAQ7B"}
@@ -195,12 +195,13 @@ export const sanitizeClientFeatures = (features)=>{
195
195
  }
196
196
  return sanitized;
197
197
  };
198
- export function sanitizeClientEditorConfig(resolvedClientFeatureMap, lexical, admin) {
198
+ export function sanitizeClientEditorConfig(resolvedClientFeatureMap, lexical, admin, view) {
199
199
  return {
200
200
  admin,
201
201
  features: sanitizeClientFeatures(resolvedClientFeatureMap),
202
202
  lexical: lexical,
203
- resolvedFeatureMap: resolvedClientFeatureMap
203
+ resolvedFeatureMap: resolvedClientFeatureMap,
204
+ view
204
205
  };
205
206
  }
206
207
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lexical/config/client/sanitize.ts"],"sourcesContent":["'use client'\n\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { ToolbarGroup } from '../../../features/toolbars/types.js'\nimport type {\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../../features/typesClient.js'\nimport type { LexicalFieldAdminClientProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\nexport const sanitizeClientFeatures = (\n features: ResolvedClientFeatureMap,\n): SanitizedClientFeatures => {\n const sanitized: SanitizedClientFeatures = {\n enabledFeatures: [],\n enabledFormats: [],\n markdownTransformers: [],\n nodes: [],\n plugins: [],\n providers: [],\n slashMenu: {\n dynamicGroups: [],\n groups: [],\n },\n toolbarFixed: {\n groups: [],\n },\n toolbarInline: {\n groups: [],\n },\n }\n\n // Allow customization of groups for toolbarFixed\n let customGroups: Record<string, Partial<ToolbarGroup>> = {}\n features.forEach((feature) => {\n if (feature.key === 'toolbarFixed' && feature.sanitizedClientFeatureProps?.customGroups) {\n customGroups = {\n ...customGroups,\n ...feature.sanitizedClientFeatureProps.customGroups,\n }\n }\n })\n\n if (!features?.size) {\n return sanitized\n }\n\n features.forEach((feature) => {\n if (feature.providers?.length) {\n sanitized.providers = sanitized.providers.concat(feature.providers)\n }\n\n if (feature.enableFormats?.length) {\n sanitized.enabledFormats.push(...feature.enableFormats)\n }\n\n if (feature.nodes?.length) {\n // Important: do not use concat\n for (const node of feature.nodes) {\n sanitized.nodes.push(node)\n }\n }\n if (feature.plugins?.length) {\n feature.plugins.forEach((plugin, i) => {\n sanitized.plugins?.push({\n clientProps: feature.sanitizedClientFeatureProps,\n Component: plugin.Component as any, // Appeases strict: true\n key: feature.key + i,\n position: plugin.position,\n })\n })\n }\n\n if (feature.toolbarInline?.groups?.length) {\n for (const group of feature.toolbarInline.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarInline.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarInline.groups = sanitized.toolbarInline.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarInline?.groups.push(foundGroup)\n }\n }\n\n if (feature.toolbarFixed?.groups?.length) {\n for (const group of feature.toolbarFixed.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarFixed.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarFixed?.groups.push(foundGroup)\n }\n }\n\n if (feature.slashMenu?.groups) {\n if (feature.slashMenu.dynamicGroups?.length) {\n sanitized.slashMenu.dynamicGroups = sanitized.slashMenu.dynamicGroups.concat(\n feature.slashMenu.dynamicGroups,\n )\n }\n\n for (const optionGroup of feature.slashMenu.groups) {\n // 1. find the group with the same name or create new one\n let group = sanitized.slashMenu.groups.find((group) => group.key === optionGroup.key)\n if (!group) {\n group = {\n ...optionGroup,\n items: [],\n }\n } else {\n sanitized.slashMenu.groups = sanitized.slashMenu.groups.filter(\n (group) => group.key !== optionGroup.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (optionGroup?.items?.length) {\n group.items = group.items.concat(optionGroup.items)\n }\n sanitized.slashMenu.groups.push(group)\n }\n }\n\n if (feature.markdownTransformers?.length) {\n // Important: do not use concat\n for (const transformer of feature.markdownTransformers) {\n if (typeof transformer === 'function') {\n sanitized.markdownTransformers.push(\n transformer({\n allNodes: sanitized.nodes,\n allTransformers: sanitized.markdownTransformers,\n }),\n )\n } else {\n sanitized.markdownTransformers.push(transformer)\n }\n }\n }\n sanitized.enabledFeatures.push(feature.key)\n })\n\n // Apply custom group configurations to toolbarFixed groups\n if (Object.keys(customGroups).length > 0) {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.map((group) => {\n const customConfig = customGroups[group.key]\n if (customConfig) {\n return deepMerge(group, customConfig)\n }\n return group\n })\n }\n\n // Sort sanitized.toolbarInline.groups by order property\n sanitized.toolbarInline.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n // Sort sanitized.toolbarFixed.groups by order property\n sanitized.toolbarFixed.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n\n // Sort sanitized.toolbarInline.groups.[group].entries by order property\n for (const group of sanitized.toolbarInline.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n // Sort sanitized.toolbarFixed.groups.[group].entries by order property\n for (const group of sanitized.toolbarFixed.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n return sanitized\n}\n\nexport function sanitizeClientEditorConfig(\n resolvedClientFeatureMap: ResolvedClientFeatureMap,\n lexical?: LexicalEditorConfig,\n admin?: LexicalFieldAdminClientProps,\n): SanitizedClientEditorConfig {\n return {\n admin,\n features: sanitizeClientFeatures(resolvedClientFeatureMap),\n lexical: lexical!,\n resolvedFeatureMap: resolvedClientFeatureMap,\n }\n}\n"],"names":["deepMerge","sanitizeClientFeatures","features","sanitized","enabledFeatures","enabledFormats","markdownTransformers","nodes","plugins","providers","slashMenu","dynamicGroups","groups","toolbarFixed","toolbarInline","customGroups","forEach","feature","key","sanitizedClientFeatureProps","size","length","concat","enableFormats","push","node","plugin","i","clientProps","Component","position","group","foundGroup","find","sanitizedGroup","items","filter","optionGroup","transformer","allNodes","allTransformers","Object","keys","map","customConfig","sort","a","b","order","sanitizeClientEditorConfig","resolvedClientFeatureMap","lexical","admin","resolvedFeatureMap"],"mappings":"AAAA;AAIA,SAASA,SAAS,QAAQ,iBAAgB;AAU1C,OAAO,MAAMC,yBAAyB,CACpCC;IAEA,MAAMC,YAAqC;QACzCC,iBAAiB,EAAE;QACnBC,gBAAgB,EAAE;QAClBC,sBAAsB,EAAE;QACxBC,OAAO,EAAE;QACTC,SAAS,EAAE;QACXC,WAAW,EAAE;QACbC,WAAW;YACTC,eAAe,EAAE;YACjBC,QAAQ,EAAE;QACZ;QACAC,cAAc;YACZD,QAAQ,EAAE;QACZ;QACAE,eAAe;YACbF,QAAQ,EAAE;QACZ;IACF;IAEA,iDAAiD;IACjD,IAAIG,eAAsD,CAAC;IAC3Db,SAASc,OAAO,CAAC,CAACC;QAChB,IAAIA,QAAQC,GAAG,KAAK,kBAAkBD,QAAQE,2BAA2B,EAAEJ,cAAc;YACvFA,eAAe;gBACb,GAAGA,YAAY;gBACf,GAAGE,QAAQE,2BAA2B,CAACJ,YAAY;YACrD;QACF;IACF;IAEA,IAAI,CAACb,UAAUkB,MAAM;QACnB,OAAOjB;IACT;IAEAD,SAASc,OAAO,CAAC,CAACC;QAChB,IAAIA,QAAQR,SAAS,EAAEY,QAAQ;YAC7BlB,UAAUM,SAAS,GAAGN,UAAUM,SAAS,CAACa,MAAM,CAACL,QAAQR,SAAS;QACpE;QAEA,IAAIQ,QAAQM,aAAa,EAAEF,QAAQ;YACjClB,UAAUE,cAAc,CAACmB,IAAI,IAAIP,QAAQM,aAAa;QACxD;QAEA,IAAIN,QAAQV,KAAK,EAAEc,QAAQ;YACzB,+BAA+B;YAC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AAID,EAAEC,KAAK,EAAE;YACtB,OAAOF,EAAEE,KAAK,GAAGD,EAAEC,KAAK;QAC1B,OAAO,IAAIF,EAAEE,KAAK,EAAE;YAClB,OAAO,CAAC;QACV,OAAO,IAAID,EAAEC,KAAK,EAAE;YAClB,OAAO;QACT,OAAO;YACL,OAAO;QACT;IACF;IAEA,wEAAwE;IACxE,KAAK,MAAMjB,SAAS5B,UAAUW,aAAa,CAACF,MAAM,CAAE;QAClDmB,MAAMI,KAAK,CAACU,IAAI,CAAC,CAACC,GAAGC;YACnB,IAAID,EAAEE,KAAK,IAAID,EAAEC,KAAK,EAAE;gBACtB,OAAOF,EAAEE,KAAK,GAAGD,EAAEC,KAAK;YAC1B,OAAO,IAAIF,EAAEE,KAAK,EAAE;gBAClB,OAAO,CAAC;YACV,OAAO,IAAID,EAAEC,KAAK,EAAE;gBAClB,OAAO;YACT,OAAO;gBACL,OAAO;YACT;QACF;IACF;IAEA,uEAAuE;IACvE,KAAK,MAAMjB,SAAS5B,UAAUU,YAAY,CAACD,MAAM,CAAE;QACjDmB,MAAMI,KAAK,CAACU,IAAI,CAAC,CAACC,GAAGC;YACnB,IAAID,EAAEE,KAAK,IAAID,EAAEC,KAAK,EAAE;gBACtB,OAAOF,EAAEE,KAAK,GAAGD,EAAEC,KAAK;YAC1B,OAAO,IAAIF,EAAEE,KAAK,EAAE;gBAClB,OAAO,CAAC;YACV,OAAO,IAAID,EAAEC,KAAK,EAAE;gBAClB,OAAO;YACT,OAAO;gBACL,OAAO;YACT;QACF;IACF;IAEA,OAAO7C;AACT,EAAC;AAED,OAAO,SAAS8C,2BACdC,wBAAkD,EAClDC,OAA6B,EAC7BC,KAAoC;IAEpC,OAAO;QACLA;QACAlD,UAAUD,uBAAuBiD;QACjCC,SAASA;QACTE,oBAAoBH;IACtB;AACF"}
1
+ {"version":3,"sources":["../../../../src/lexical/config/client/sanitize.ts"],"sourcesContent":["'use client'\n\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { ToolbarGroup } from '../../../features/toolbars/types.js'\nimport type {\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../../features/typesClient.js'\nimport type { LexicalFieldAdminClientProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\nexport const sanitizeClientFeatures = (\n features: ResolvedClientFeatureMap,\n): SanitizedClientFeatures => {\n const sanitized: SanitizedClientFeatures = {\n enabledFeatures: [],\n enabledFormats: [],\n markdownTransformers: [],\n nodes: [],\n plugins: [],\n providers: [],\n slashMenu: {\n dynamicGroups: [],\n groups: [],\n },\n toolbarFixed: {\n groups: [],\n },\n toolbarInline: {\n groups: [],\n },\n }\n\n // Allow customization of groups for toolbarFixed\n let customGroups: Record<string, Partial<ToolbarGroup>> = {}\n features.forEach((feature) => {\n if (feature.key === 'toolbarFixed' && feature.sanitizedClientFeatureProps?.customGroups) {\n customGroups = {\n ...customGroups,\n ...feature.sanitizedClientFeatureProps.customGroups,\n }\n }\n })\n\n if (!features?.size) {\n return sanitized\n }\n\n features.forEach((feature) => {\n if (feature.providers?.length) {\n sanitized.providers = sanitized.providers.concat(feature.providers)\n }\n\n if (feature.enableFormats?.length) {\n sanitized.enabledFormats.push(...feature.enableFormats)\n }\n\n if (feature.nodes?.length) {\n // Important: do not use concat\n for (const node of feature.nodes) {\n sanitized.nodes.push(node)\n }\n }\n if (feature.plugins?.length) {\n feature.plugins.forEach((plugin, i) => {\n sanitized.plugins?.push({\n clientProps: feature.sanitizedClientFeatureProps,\n Component: plugin.Component as any, // Appeases strict: true\n key: feature.key + i,\n position: plugin.position,\n })\n })\n }\n\n if (feature.toolbarInline?.groups?.length) {\n for (const group of feature.toolbarInline.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarInline.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarInline.groups = sanitized.toolbarInline.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarInline?.groups.push(foundGroup)\n }\n }\n\n if (feature.toolbarFixed?.groups?.length) {\n for (const group of feature.toolbarFixed.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarFixed.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarFixed?.groups.push(foundGroup)\n }\n }\n\n if (feature.slashMenu?.groups) {\n if (feature.slashMenu.dynamicGroups?.length) {\n sanitized.slashMenu.dynamicGroups = sanitized.slashMenu.dynamicGroups.concat(\n feature.slashMenu.dynamicGroups,\n )\n }\n\n for (const optionGroup of feature.slashMenu.groups) {\n // 1. find the group with the same name or create new one\n let group = sanitized.slashMenu.groups.find((group) => group.key === optionGroup.key)\n if (!group) {\n group = {\n ...optionGroup,\n items: [],\n }\n } else {\n sanitized.slashMenu.groups = sanitized.slashMenu.groups.filter(\n (group) => group.key !== optionGroup.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (optionGroup?.items?.length) {\n group.items = group.items.concat(optionGroup.items)\n }\n sanitized.slashMenu.groups.push(group)\n }\n }\n\n if (feature.markdownTransformers?.length) {\n // Important: do not use concat\n for (const transformer of feature.markdownTransformers) {\n if (typeof transformer === 'function') {\n sanitized.markdownTransformers.push(\n transformer({\n allNodes: sanitized.nodes,\n allTransformers: sanitized.markdownTransformers,\n }),\n )\n } else {\n sanitized.markdownTransformers.push(transformer)\n }\n }\n }\n sanitized.enabledFeatures.push(feature.key)\n })\n\n // Apply custom group configurations to toolbarFixed groups\n if (Object.keys(customGroups).length > 0) {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.map((group) => {\n const customConfig = customGroups[group.key]\n if (customConfig) {\n return deepMerge(group, customConfig)\n }\n return group\n })\n }\n\n // Sort sanitized.toolbarInline.groups by order property\n sanitized.toolbarInline.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n // Sort sanitized.toolbarFixed.groups by order property\n sanitized.toolbarFixed.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n\n // Sort sanitized.toolbarInline.groups.[group].entries by order property\n for (const group of sanitized.toolbarInline.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n // Sort sanitized.toolbarFixed.groups.[group].entries by order property\n for (const group of sanitized.toolbarFixed.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n return sanitized\n}\n\nexport function sanitizeClientEditorConfig(\n resolvedClientFeatureMap: ResolvedClientFeatureMap,\n lexical?: LexicalEditorConfig,\n admin?: LexicalFieldAdminClientProps,\n view?: string,\n): SanitizedClientEditorConfig {\n return {\n admin,\n features: sanitizeClientFeatures(resolvedClientFeatureMap),\n lexical: lexical!,\n resolvedFeatureMap: resolvedClientFeatureMap,\n view,\n }\n}\n"],"names":["deepMerge","sanitizeClientFeatures","features","sanitized","enabledFeatures","enabledFormats","markdownTransformers","nodes","plugins","providers","slashMenu","dynamicGroups","groups","toolbarFixed","toolbarInline","customGroups","forEach","feature","key","sanitizedClientFeatureProps","size","length","concat","enableFormats","push","node","plugin","i","clientProps","Component","position","group","foundGroup","find","sanitizedGroup","items","filter","optionGroup","transformer","allNodes","allTransformers","Object","keys","map","customConfig","sort","a","b","order","sanitizeClientEditorConfig","resolvedClientFeatureMap","lexical","admin","view","resolvedFeatureMap"],"mappings":"AAAA;AAIA,SAASA,SAAS,QAAQ,iBAAgB;AAU1C,OAAO,MAAMC,yBAAyB,CACpCC;IAEA,MAAMC,YAAqC;QACzCC,iBAAiB,EAAE;QACnBC,gBAAgB,EAAE;QAClBC,sBAAsB,EAAE;QACxBC,OAAO,EAAE;QACTC,SAAS,EAAE;QACXC,WAAW,EAAE;QACbC,WAAW;YACTC,eAAe,EAAE;YACjBC,QAAQ,EAAE;QACZ;QACAC,cAAc;YACZD,QAAQ,EAAE;QACZ;QACAE,eAAe;YACbF,QAAQ,EAAE;QACZ;IACF;IAEA,iDAAiD;IACjD,IAAIG,eAAsD,CAAC;IAC3Db,SAASc,OAAO,CAAC,CAACC;QAChB,IAAIA,QAAQC,GAAG,KAAK,kBAAkBD,QAAQE,2BAA2B,EAAEJ,cAAc;YACvFA,eAAe;gBACb,GAAGA,YAAY;gBACf,GAAGE,QAAQE,2BAA2B,CAACJ,YAAY;YACrD;QACF;IACF;IAEA,IAAI,CAACb,UAAUkB,MAAM;QACnB,OAAOjB;IACT;IAEAD,SAASc,OAAO,CAAC,CAACC;QAChB,IAAIA,QAAQR,SAAS,EAAEY,QAAQ;YAC7BlB,UAAUM,SAAS,GAAGN,UAAUM,SAAS,CAACa,MAAM,CAACL,QAAQR,SAAS;QACpE;QAEA,IAAIQ,QAAQM,aAAa,EAAEF,QAAQ;YACjClB,UAAUE,cAAc,CAACmB,IAAI,IAAIP,QAAQM,aAAa;QACxD;QAEA,IAAIN,QAAQV,KAAK,EAAEc,QAAQ;YACzB,+BAA+B;YAC/B,KAAK,MAAMI,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,EAAE;YACtB,OAAOF,EAAEE,KAAK,GAAGD,EAAEC,KAAK;QAC1B,OAAO,IAAIF,EAAEE,KAAK,EAAE;YAClB,OAAO,CAAC;QACV,OAAO,IAAID,EAAEC,KAAK,EAAE;YAClB,OAAO;QACT,OAAO;YACL,OAAO;QACT;IACF;IAEA,wEAAwE;IACxE,KAAK,MAAMjB,SAAS5B,UAAUW,aAAa,CAACF,MAAM,CAAE;QAClDmB,MAAMI,KAAK,CAACU,IAAI,CAAC,CAACC,GAAGC;YACnB,IAAID,EAAEE,KAAK,IAAID,EAAEC,KAAK,EAAE;gBACtB,OAAOF,EAAEE,KAAK,GAAGD,EAAEC,KAAK;YAC1B,OAAO,IAAIF,EAAEE,KAAK,EAAE;gBAClB,OAAO,CAAC;YACV,OAAO,IAAID,EAAEC,KAAK,EAAE;gBAClB,OAAO;YACT,OAAO;gBACL,OAAO;YACT;QACF;IACF;IAEA,uEAAuE;IACvE,KAAK,MAAMjB,SAAS5B,UAAUU,YAAY,CAACD,MAAM,CAAE;QACjDmB,MAAMI,KAAK,CAACU,IAAI,CAAC,CAACC,GAAGC;YACnB,IAAID,EAAEE,KAAK,IAAID,EAAEC,KAAK,EAAE;gBACtB,OAAOF,EAAEE,KAAK,GAAGD,EAAEC,KAAK;YAC1B,OAAO,IAAIF,EAAEE,KAAK,EAAE;gBAClB,OAAO,CAAC;YACV,OAAO,IAAID,EAAEC,KAAK,EAAE;gBAClB,OAAO;YACT,OAAO;gBACL,OAAO;YACT;QACF;IACF;IAEA,OAAO7C;AACT,EAAC;AAED,OAAO,SAAS8C,2BACdC,wBAAkD,EAClDC,OAA6B,EAC7BC,KAAoC,EACpCC,IAAa;IAEb,OAAO;QACLD;QACAlD,UAAUD,uBAAuBiD;QACjCC,SAASA;QACTG,oBAAoBJ;QACpBG;IACF;AACF"}
@@ -20,5 +20,9 @@ export type SanitizedClientEditorConfig = {
20
20
  features: SanitizedClientFeatures;
21
21
  lexical: LexicalEditorConfig;
22
22
  resolvedFeatureMap: ResolvedClientFeatureMap;
23
+ /**
24
+ * To identify what view this editor config was created for.
25
+ */
26
+ view?: string;
23
27
  };
24
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lexical/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;IAChD,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAA;IACxC,kBAAkB,EAAE,wBAAwB,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;IAC3C,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,CAAC,EAAE,4BAA4B,CAAA;IACpC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,EAAE,mBAAmB,CAAA;IAC5B,kBAAkB,EAAE,wBAAwB,CAAA;CAC7C,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lexical/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;IAChD,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAA;IACxC,kBAAkB,EAAE,wBAAwB,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;IAC3C,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,CAAC,EAAE,4BAA4B,CAAA;IACpC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,EAAE,mBAAmB,CAAA;IAC5B,kBAAkB,EAAE,wBAAwB,CAAA;IAC5C;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA"}
@@ -1,5 +1,7 @@
1
1
  // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.
2
2
  // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.
3
- export { };
3
+ export { }; /**
4
+ * To identify what view this editor config was created for.
5
+ */
4
6
 
5
7
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lexical/config/types.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport type {\n FeatureProviderClient,\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../features/typesClient.js'\nimport type {\n FeatureProviderServer,\n ResolvedServerFeatureMap,\n SanitizedServerFeatures,\n} from '../../features/typesServer.js'\nimport type { LexicalFieldAdminClientProps } from '../../types.js'\n\nexport type ServerEditorConfig = {\n features: FeatureProviderServer<any, any, any>[]\n lexical?: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n}\n\nexport type SanitizedServerEditorConfig = {\n features: SanitizedServerFeatures\n lexical: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n resolvedFeatureMap: ResolvedServerFeatureMap\n}\n\nexport type ClientEditorConfig = {\n features: FeatureProviderClient<any, any>[]\n lexical?: LexicalEditorConfig\n}\n\nexport type SanitizedClientEditorConfig = {\n admin?: LexicalFieldAdminClientProps\n features: SanitizedClientFeatures\n lexical: LexicalEditorConfig\n resolvedFeatureMap: ResolvedClientFeatureMap\n}\n"],"names":[],"mappings":"AAgB4C,8JAA8J;AAK/J,8JAA8J;AASzM,WAKC"}
1
+ {"version":3,"sources":["../../../src/lexical/config/types.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport type {\n FeatureProviderClient,\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../features/typesClient.js'\nimport type {\n FeatureProviderServer,\n ResolvedServerFeatureMap,\n SanitizedServerFeatures,\n} from '../../features/typesServer.js'\nimport type { LexicalFieldAdminClientProps } from '../../types.js'\n\nexport type ServerEditorConfig = {\n features: FeatureProviderServer<any, any, any>[]\n lexical?: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n}\n\nexport type SanitizedServerEditorConfig = {\n features: SanitizedServerFeatures\n lexical: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n resolvedFeatureMap: ResolvedServerFeatureMap\n}\n\nexport type ClientEditorConfig = {\n features: FeatureProviderClient<any, any>[]\n lexical?: LexicalEditorConfig\n}\n\nexport type SanitizedClientEditorConfig = {\n admin?: LexicalFieldAdminClientProps\n features: SanitizedClientFeatures\n lexical: LexicalEditorConfig\n resolvedFeatureMap: ResolvedClientFeatureMap\n /**\n * To identify what view this editor config was created for.\n */\n view?: string\n}\n"],"names":[],"mappings":"AAgB4C,8JAA8J;AAK/J,8JAA8J;AASzM,WASC,CAJC;;GAEC"}
@@ -1,8 +1,18 @@
1
- import type { Klass, LexicalNode, LexicalNodeReplacement } from 'lexical';
1
+ import type { Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
2
2
  import type { NodeWithHooks } from '../../features/typesServer.js';
3
+ import type { LexicalEditorNodeMap } from '../../types.js';
3
4
  import type { SanitizedClientEditorConfig, SanitizedServerEditorConfig } from '../config/types.js';
4
- export declare function getEnabledNodes({ editorConfig, }: {
5
+ /**
6
+ * Register view definitions for an editor
7
+ */
8
+ export declare function registerEditorNodeViews(editor: LexicalEditor, nodeViews: LexicalEditorNodeMap): void;
9
+ /**
10
+ * Clear all view overrides for an editor (restores default rendering)
11
+ */
12
+ export declare function clearEditorNodeViews(editor: LexicalEditor): void;
13
+ export declare function getEnabledNodes({ editorConfig, nodeViews, }: {
5
14
  editorConfig: SanitizedClientEditorConfig | SanitizedServerEditorConfig;
15
+ nodeViews?: LexicalEditorNodeMap;
6
16
  }): Array<Klass<LexicalNode> | LexicalNodeReplacement>;
7
17
  export declare function getEnabledNodesFromServerNodes({ nodes, }: {
8
18
  nodes: Array<Klass<LexicalNode> | LexicalNodeReplacement> | Array<NodeWithHooks>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lexical/nodes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAElG,wBAAgB,eAAe,CAAC,EAC9B,YAAY,GACb,EAAE;IACD,YAAY,EAAE,2BAA2B,GAAG,2BAA2B,CAAA;CACxE,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAIrD;AAED,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAA;CACjF,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAOrD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lexical/nodes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,KAAK,EACL,aAAa,EACb,WAAW,EACX,sBAAsB,EACvB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAgB,MAAM,gBAAgB,CAAA;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAMlG;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,oBAAoB,GAC9B,IAAI,CAsCN;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAEhE;AAoID,wBAAgB,eAAe,CAAC,EAC9B,YAAY,EACZ,SAAS,GACV,EAAE;IACD,YAAY,EAAE,2BAA2B,GAAG,2BAA2B,CAAA;IACvE,SAAS,CAAC,EAAE,oBAAoB,CAAA;CACjC,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAyCrD;AAED,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAA;CACjF,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAOrD"}
@@ -1,7 +1,192 @@
1
- export function getEnabledNodes({ editorConfig }) {
2
- return getEnabledNodesFromServerNodes({
1
+ import React from 'react';
2
+ // Store view definitions for each editor and node type
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ const editorNodeViews = new WeakMap();
5
+ /**
6
+ * Register view definitions for an editor
7
+ */ export function registerEditorNodeViews(editor, nodeViews) {
8
+ if (!editorNodeViews.has(editor)) {
9
+ editorNodeViews.set(editor, new Map());
10
+ }
11
+ const editorViews = editorNodeViews.get(editor);
12
+ // Register each node type's view
13
+ for (const [nodeType, value] of Object.entries(nodeViews)){
14
+ if (!value || typeof value !== 'object') {
15
+ continue;
16
+ }
17
+ // Handle blocks specially - store each block type with key 'block:blockType'
18
+ if (nodeType === 'blocks') {
19
+ for (const [blockType, viewDef] of Object.entries(// eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ value)){
21
+ editorViews.set(`block:${blockType}`, viewDef);
22
+ }
23
+ continue;
24
+ }
25
+ // Handle inlineBlocks specially - store each block type with key 'inlineBlock:blockType'
26
+ if (nodeType === 'inlineBlocks') {
27
+ for (const [blockType, viewDef] of Object.entries(// eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ value)){
29
+ editorViews.set(`inlineBlock:${blockType}`, viewDef);
30
+ }
31
+ continue;
32
+ }
33
+ // Regular node types
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ editorViews.set(nodeType, value);
36
+ }
37
+ }
38
+ /**
39
+ * Clear all view overrides for an editor (restores default rendering)
40
+ */ export function clearEditorNodeViews(editor) {
41
+ editorNodeViews.delete(editor);
42
+ }
43
+ /**
44
+ * Get the view definition for a specific editor and node
45
+ */ function getEditorNodeView(editor, nodeType, // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ node) // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ {
48
+ const editorViews = editorNodeViews.get(editor);
49
+ // For block nodes, look up by blockType
50
+ if (nodeType === 'block' && node?.['__fields']?.blockType) {
51
+ const blockType = node['__fields'].blockType;
52
+ return editorViews?.get(`block:${blockType}`);
53
+ }
54
+ // For inlineBlock nodes, look up by blockType
55
+ if (nodeType === 'inlineBlock' && node?.['__fields']?.blockType) {
56
+ const blockType = node['__fields'].blockType;
57
+ return editorViews?.get(`inlineBlock:${blockType}`);
58
+ }
59
+ // Regular node types
60
+ return editorViews?.get(nodeType);
61
+ }
62
+ /**
63
+ * Apply view overrides to a specific node type by modifying its prototype
64
+ * Uses WeakMap to check per-editor at runtime
65
+ */ function applyNodeOverride({ node, nodeType }) {
66
+ if (!('getType' in node) || node.getType() !== nodeType) {
67
+ return;
68
+ }
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ const NodeClass = node;
71
+ // Store original methods if not already stored
72
+ if (!NodeClass.prototype._originalDecorate) {
73
+ NodeClass.prototype._originalDecorate = NodeClass.prototype.decorate;
74
+ }
75
+ if (!NodeClass.prototype._originalCreateDOM) {
76
+ NodeClass.prototype._originalCreateDOM = NodeClass.prototype.createDOM;
77
+ }
78
+ // Override decorate method (for DecoratorNodes)
79
+ if (NodeClass.prototype.decorate && !NodeClass.prototype._decorateOverridden) {
80
+ NodeClass.prototype._decorateOverridden = true;
81
+ const hasCreateDOM = !!NodeClass.prototype.createDOM;
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
+ NodeClass.prototype.decorate = function(editor, config) {
84
+ const viewDef = getEditorNodeView(editor, nodeType, this);
85
+ if (viewDef) {
86
+ // Priority 1: If Component is provided, use it
87
+ if (viewDef.Component) {
88
+ return viewDef.Component({
89
+ config,
90
+ editor,
91
+ isEditor: true,
92
+ isJSXConverter: false,
93
+ node: this
94
+ });
95
+ }
96
+ // Priority 2: If custom createDOM is provided, use html in decorate
97
+ if (viewDef.createDOM && viewDef.html) {
98
+ const htmlContent = typeof viewDef.html === 'function' ? viewDef.html({
99
+ config,
100
+ editor,
101
+ isEditor: true,
102
+ isJSXConverter: false,
103
+ node: this
104
+ }) : viewDef.html;
105
+ return React.createElement('span', {
106
+ dangerouslySetInnerHTML: {
107
+ __html: htmlContent
108
+ }
109
+ });
110
+ }
111
+ // Priority 3: If only html is provided (no custom createDOM),
112
+ // createDOM will handle it, so decorate returns empty fragment
113
+ if (viewDef.html && hasCreateDOM && !viewDef.createDOM) {
114
+ return React.createElement(React.Fragment);
115
+ }
116
+ }
117
+ // Otherwise use original
118
+ return NodeClass.prototype._originalDecorate.call(this, editor, config);
119
+ };
120
+ }
121
+ // Override createDOM method (for ElementNodes)
122
+ if (NodeClass.prototype.createDOM && !NodeClass.prototype._createDOMOverridden) {
123
+ NodeClass.prototype._createDOMOverridden = true;
124
+ NodeClass.prototype.createDOM = function(config, editor) {
125
+ const viewDef = getEditorNodeView(editor, nodeType, this);
126
+ if (viewDef) {
127
+ // If createDOM is provided, use it
128
+ if (viewDef.createDOM) {
129
+ return viewDef.createDOM({
130
+ config,
131
+ editor,
132
+ node: this
133
+ });
134
+ }
135
+ // If html is provided (as a function or string), create element from it
136
+ if (viewDef.html) {
137
+ const htmlContent = typeof viewDef.html === 'function' ? viewDef.html({
138
+ config,
139
+ editor,
140
+ isEditor: true,
141
+ isJSXConverter: false,
142
+ node: this
143
+ }) : viewDef.html;
144
+ const tempDiv = document.createElement('div');
145
+ tempDiv.innerHTML = htmlContent;
146
+ return tempDiv.firstElementChild || tempDiv;
147
+ }
148
+ }
149
+ // Otherwise use original
150
+ return NodeClass.prototype._originalCreateDOM.call(this, config, editor);
151
+ };
152
+ }
153
+ }
154
+ export function getEnabledNodes({ editorConfig, nodeViews }) {
155
+ const nodes = getEnabledNodesFromServerNodes({
3
156
  nodes: editorConfig.features.nodes
4
157
  });
158
+ if (nodeViews) {
159
+ // Apply node overrides by modifying prototypes (once globally)
160
+ // The overrides check per-editor at runtime using WeakMap
161
+ const nodeTypesToOverride = new Set();
162
+ for (const [key, value] of Object.entries(nodeViews)){
163
+ if (!value || typeof value !== 'object') {
164
+ continue;
165
+ }
166
+ // If 'blocks' key exists with content, we need to override 'block' nodes
167
+ if (key === 'blocks' && Object.keys(value).length > 0) {
168
+ nodeTypesToOverride.add('block');
169
+ } else // If 'inlineBlocks' key exists with content, we need to override 'inlineBlock' nodes
170
+ if (key === 'inlineBlocks' && Object.keys(value).length > 0) {
171
+ nodeTypesToOverride.add('inlineBlock');
172
+ } else // Regular node types
173
+ {
174
+ nodeTypesToOverride.add(key);
175
+ }
176
+ }
177
+ for (const node of nodes){
178
+ if ('getType' in node) {
179
+ const nodeType = node.getType();
180
+ if (nodeTypesToOverride.has(nodeType)) {
181
+ applyNodeOverride({
182
+ node,
183
+ nodeType
184
+ });
185
+ }
186
+ }
187
+ }
188
+ }
189
+ return nodes;
5
190
  }
6
191
  export function getEnabledNodesFromServerNodes({ nodes }) {
7
192
  return nodes.map((node)=>{