@payloadcms/richtext-lexical 3.16.0 → 3.16.1-canary.9004205
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.
- package/dist/exports/client/Field-F5XP4HL4.js +2 -0
- package/dist/exports/client/Field-F5XP4HL4.js.map +7 -0
- package/dist/exports/client/{RelationshipComponent-N4C5MX3U.js → RelationshipComponent-AAFBGDZ5.js} +2 -2
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-3LGFOM34.js +2 -0
- package/dist/exports/client/chunk-3LGFOM34.js.map +7 -0
- package/dist/exports/client/chunk-7XFF5VOE.js +12 -0
- package/dist/exports/client/chunk-7XFF5VOE.js.map +7 -0
- package/dist/exports/client/{chunk-JRIUM7SP.js → chunk-CGFQWJ56.js} +2 -2
- package/dist/exports/client/{chunk-422FRG7Z.js → chunk-XI5JV5QT.js} +2 -2
- package/dist/exports/client/{chunk-HTQL4HTC.js → chunk-XXNV22UZ.js} +2 -2
- package/dist/exports/client/{component-TYBPYPLA.js → component-NUQPQ2MC.js} +2 -2
- package/dist/exports/client/componentInline-KDFOWBR5.js +2 -0
- package/dist/exports/client/index.js +9 -11
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/blocks/client/getBlockImageComponent.d.ts +3 -0
- package/dist/features/blocks/client/getBlockImageComponent.d.ts.map +1 -0
- package/dist/features/blocks/client/getBlockImageComponent.js +18 -0
- package/dist/features/blocks/client/getBlockImageComponent.js.map +1 -0
- package/dist/features/blocks/client/index.d.ts.map +1 -1
- package/dist/features/blocks/client/index.js +4 -3
- package/dist/features/blocks/client/index.js.map +1 -1
- package/dist/features/blocks/client/markdownTransformer.d.ts.map +1 -1
- package/dist/features/blocks/client/markdownTransformer.js +1 -2
- package/dist/features/blocks/client/markdownTransformer.js.map +1 -1
- package/dist/features/blocks/server/markdownTransformer.d.ts.map +1 -1
- package/dist/features/blocks/server/markdownTransformer.js +1 -2
- package/dist/features/blocks/server/markdownTransformer.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.js +4 -4
- package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +84 -41
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +37 -41
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +29 -23
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +2 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/experimental_table/markdownTransformer.d.ts.map +1 -1
- package/dist/features/experimental_table/markdownTransformer.js +1 -2
- package/dist/features/experimental_table/markdownTransformer.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +9 -9
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.d.ts.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +3 -3
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/typesClient.d.ts +2 -2
- package/dist/features/typesClient.d.ts.map +1 -1
- package/dist/features/typesClient.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +17 -2
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +13 -1
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts +1 -0
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +32 -56
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts +1 -0
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +8 -1
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.d.ts +1 -0
- package/dist/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.js +5 -2
- package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/dist/lexical/config/client/sanitize.d.ts +2 -2
- package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
- package/dist/lexical/config/client/sanitize.js.map +1 -1
- package/dist/lexical/config/types.d.ts +2 -2
- package/dist/lexical/config/types.d.ts.map +1 -1
- package/dist/lexical/config/types.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.d.ts +4 -0
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.d.ts.map +1 -0
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js +55 -0
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -0
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +2 -2
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/TextPlugin/index.js +0 -4
- package/dist/lexical/plugins/TextPlugin/index.js.map +1 -1
- package/dist/lexical/theme/EditorTheme.d.ts.map +1 -1
- package/dist/lexical/theme/EditorTheme.js +2 -4
- package/dist/lexical/theme/EditorTheme.js.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownTransformers.d.ts +1 -1
- package/dist/packages/@lexical/markdown/MarkdownTransformers.d.ts.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownTransformers.js +26 -8
- package/dist/packages/@lexical/markdown/MarkdownTransformers.js.map +1 -1
- package/dist/packages/@lexical/markdown/index.d.ts.map +1 -1
- package/dist/packages/@lexical/markdown/index.js +1 -1
- package/dist/packages/@lexical/markdown/index.js.map +1 -1
- package/dist/types.d.ts +10 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +28 -28
- package/dist/exports/client/Field-VBZQOYLK.js +0 -2
- package/dist/exports/client/Field-VBZQOYLK.js.map +0 -7
- package/dist/exports/client/chunk-BB2LUWM3.js +0 -2
- package/dist/exports/client/chunk-BB2LUWM3.js.map +0 -7
- package/dist/exports/client/chunk-PZPNMC5Y.js +0 -12
- package/dist/exports/client/chunk-PZPNMC5Y.js.map +0 -7
- package/dist/exports/client/componentInline-VR5HF5DY.js +0 -2
- package/dist/utilities/jsx/lexicalMarkdownCopy.d.ts +0 -11
- package/dist/utilities/jsx/lexicalMarkdownCopy.d.ts.map +0 -1
- package/dist/utilities/jsx/lexicalMarkdownCopy.js +0 -66
- package/dist/utilities/jsx/lexicalMarkdownCopy.js.map +0 -1
- /package/dist/exports/client/{RelationshipComponent-N4C5MX3U.js.map → RelationshipComponent-AAFBGDZ5.js.map} +0 -0
- /package/dist/exports/client/{chunk-JRIUM7SP.js.map → chunk-CGFQWJ56.js.map} +0 -0
- /package/dist/exports/client/{chunk-422FRG7Z.js.map → chunk-XI5JV5QT.js.map} +0 -0
- /package/dist/exports/client/{chunk-HTQL4HTC.js.map → chunk-XXNV22UZ.js.map} +0 -0
- /package/dist/exports/client/{component-TYBPYPLA.js.map → component-NUQPQ2MC.js.map} +0 -0
- /package/dist/exports/client/{componentInline-VR5HF5DY.js.map → componentInline-KDFOWBR5.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LexicalEditor.js","names":["c","_c","useLexicalComposerContext","LexicalErrorBoundary","HistoryPlugin","OnChangePlugin","RichTextPlugin","BLUR_COMMAND","COMMAND_PRIORITY_LOW","FOCUS_COMMAND","React","useEffect","useState","useEditorConfigContext","EditorPlugin","AddBlockHandlePlugin","DraggableBlockPlugin","MarkdownShortcutPlugin","SlashMenuPlugin","TextPlugin","LexicalContentEditable","LexicalEditor","props","$","editorConfig","editorContainerRef","onChange","editorConfigContext","editor","floatingAnchorElem","setFloatingAnchorElem","t0","Symbol","for","_floatingAnchorElem","onRef","t1","t2","uuid","console","error","parentEditor","registerChild","handleFocus","focusEditor","handleBlur","blurEditor","unregisterFocus","registerCommand","unregisterBlur","unregisterChild","isSmallWidthViewport","setIsSmallWidthViewport","t3","t4","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","t5","t6","editorState","editor_0","tags","has","size","t7","features","plugins","_jsxs","Fragment","children","isEditable","_jsx","anchorElem","map","plugin_1","plugin","position","desktopOnly","clientProps","key","_temp","className","ref","_temp2","contentEditable","ignoreSelectionChange","markdownTransformers","length","_temp3","_temp4","_temp5","plugin_0","plugin_2","plugin_3","plugin_4"],"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 { 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 { EditorPlugin } from './EditorPlugin.js'\nimport './LexicalEditor.scss'\nimport { AddBlockHandlePlugin } from './plugins/handles/AddBlockHandlePlugin/index.js'\nimport { DraggableBlockPlugin } from './plugins/handles/DraggableBlockPlugin/index.js'\nimport { MarkdownShortcutPlugin } from './plugins/MarkdownShortcut/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 } & Pick<LexicalProviderProps, 'editorConfig' | 'onChange'>\n> = (props) => {\n const { editorConfig, editorContainerRef, onChange } = props\n const editorConfigContext = useEditorConfigContext()\n const [editor] = useLexicalComposerContext()\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 const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\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 <TextPlugin features={editorConfig.features} />\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 {floatingAnchorElem && (\n <React.Fragment>\n {!isSmallWidthViewport && editor.isEditable() && (\n <React.Fragment>\n <DraggableBlockPlugin anchorElem={floatingAnchorElem} />\n <AddBlockHandlePlugin anchorElem={floatingAnchorElem} />\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 {editor.isEditable() && (\n <React.Fragment>\n <SlashMenuPlugin anchorElem={floatingAnchorElem} />\n </React.Fragment>\n )}\n </React.Fragment>\n )}\n {editor.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"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,oBAAoB,QAAQ;AACrC,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,YAAY,EAAEC,oBAAoB,EAAEC,aAAa,QAAQ;AAClE,YAAYC,KAAA,MAAW;AACvB,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAIpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAE7B,SAASC,oBAAoB,QAAQ;AACrC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,s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A6CA;IAAA,GAApBA,QAAA,CAAAI,GAAU;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"LexicalEditor.js","names":["c","_c","useLexicalComposerContext","LexicalErrorBoundary","HistoryPlugin","OnChangePlugin","RichTextPlugin","BLUR_COMMAND","COMMAND_PRIORITY_LOW","FOCUS_COMMAND","React","useEffect","useState","useEditorConfigContext","EditorPlugin","AddBlockHandlePlugin","DraggableBlockPlugin","InsertParagraphAtEndPlugin","MarkdownShortcutPlugin","SlashMenuPlugin","TextPlugin","LexicalContentEditable","LexicalEditor","props","$","editorConfig","editorContainerRef","isSmallWidthViewport","onChange","editorConfigContext","editor","floatingAnchorElem","setFloatingAnchorElem","t0","Symbol","for","_floatingAnchorElem","onRef","t1","t2","uuid","console","error","parentEditor","registerChild","handleFocus","focusEditor","handleBlur","blurEditor","unregisterFocus","registerCommand","unregisterBlur","unregisterChild","t3","t4","editorState","editor_0","tags","has","size","t5","features","plugins","_jsxs","Fragment","children","isEditable","_jsx","anchorElem","map","plugin_1","plugin","position","desktopOnly","clientProps","key","_temp","className","ref","_temp2","contentEditable","ignoreSelectionChange","markdownTransformers","length","_temp3","_temp4","_temp5","plugin_0","plugin_2","plugin_3","plugin_4"],"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 {\n $createParagraphNode,\n $getRoot,\n BLUR_COMMAND,\n COMMAND_PRIORITY_LOW,\n FOCUS_COMMAND,\n} 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 { EditorPlugin } from './EditorPlugin.js'\nimport './LexicalEditor.scss'\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 { 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\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 <InsertParagraphAtEndPlugin />\n <TextPlugin features={editorConfig.features} />\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 {floatingAnchorElem && (\n <React.Fragment>\n {!isSmallWidthViewport && editor.isEditable() && (\n <React.Fragment>\n <DraggableBlockPlugin anchorElem={floatingAnchorElem} />\n <AddBlockHandlePlugin anchorElem={floatingAnchorElem} />\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 {editor.isEditable() && (\n <React.Fragment>\n <SlashMenuPlugin anchorElem={floatingAnchorElem} />\n </React.Fragment>\n )}\n </React.Fragment>\n )}\n {editor.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"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,oBAAoB,QAAQ;AACrC,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAGEC,YAAY,EACZC,oBAAoB,EACpBC,aAAa,QACR;AACP,YAAYC,KAAA,MAAW;AACvB,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAIpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAE7B,SAASC,oBAAoB,QAAQ;AACrC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,sBAAsB,QAAQ;AACvC,SAASC,eAAe,QAAQ;AAChC,SAASC,UAAU,QAAQ;AAC3B,SAASC,sBAAsB,QAAQ;AAEvC,OAAO,MAAMC,aAAA,GAKTC,KAAA;EAAA,MAAAC,CAAA,GAAAvB,EAAA;EACF;IAAAwB,YAAA;IAAAC,kBAAA;IAAAC,oBAAA;IAAAC;EAAA,IAA6EL,KAAA;EAC7E,MAAAM,mBAAA,GAA4BhB,sBAAA;EAC5B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A;MAAA4D,WAAA,EAA2BH,QAAA,CAAAG,WAAA;MAAAH,MAAA,EAA6CA;IAAA,GAApBA,QAAA,CAAAI,GAAU;EAAA;AAAA;AA7IxE,SAAAW,OAAAI,QAAA;EAAA,IAmJQnB,QAAA,CAAAC,QAAA,KAAoB;IAAA,OACfL,IAAA,CAAArD,YAAA;MAAA4D,WAAA,EAA2BH,QAAA,CAAAG,WAAA;MAAAH,MAAA,EAA6CA;IAAA,GAApBA,QAAA,CAAAI,GAAU;EAAA;AAAA","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ export type LexicalProviderProps = {
|
|
|
6
6
|
composerKey: string;
|
|
7
7
|
editorConfig: SanitizedClientEditorConfig;
|
|
8
8
|
fieldProps: LexicalRichTextFieldProps;
|
|
9
|
+
isSmallWidthViewport: boolean;
|
|
9
10
|
onChange: (editorState: EditorState, editor: LexicalEditor, tags: Set<string>) => void;
|
|
10
11
|
readOnly: boolean;
|
|
11
12
|
value: SerializedEditorState;
|
|
@@ -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,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,
|
|
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"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { LexicalComposer } from '@lexical/react/LexicalComposer.js';
|
|
5
|
+
import { useEditDepth } from '@payloadcms/ui';
|
|
5
6
|
import * as React from 'react';
|
|
6
7
|
import { useMemo } from 'react';
|
|
7
8
|
import { EditorConfigProvider, useEditorConfigContext } from './config/client/EditorConfigProvider.js';
|
|
@@ -32,11 +33,13 @@ export const LexicalProvider = props => {
|
|
|
32
33
|
composerKey,
|
|
33
34
|
editorConfig,
|
|
34
35
|
fieldProps,
|
|
36
|
+
isSmallWidthViewport,
|
|
35
37
|
onChange,
|
|
36
38
|
readOnly,
|
|
37
39
|
value
|
|
38
40
|
} = props;
|
|
39
41
|
const parentContext = useEditorConfigContext();
|
|
42
|
+
const editDepth = useEditDepth();
|
|
40
43
|
const editorContainerRef = React.useRef(null);
|
|
41
44
|
// useMemo for the initialConfig that depends on readOnly and value
|
|
42
45
|
const initialConfig = useMemo(() => {
|
|
@@ -77,12 +80,16 @@ export const LexicalProvider = props => {
|
|
|
77
80
|
editorConfig: editorConfig,
|
|
78
81
|
editorContainerRef: editorContainerRef,
|
|
79
82
|
fieldProps: fieldProps,
|
|
80
|
-
|
|
83
|
+
/**
|
|
84
|
+
* 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.
|
|
85
|
+
*/
|
|
86
|
+
parentContext: parentContext?.editDepth === editDepth ? parentContext : undefined,
|
|
81
87
|
children: /*#__PURE__*/_jsx(NestProviders, {
|
|
82
88
|
providers: editorConfig.features.providers,
|
|
83
89
|
children: /*#__PURE__*/_jsx(LexicalEditorComponent, {
|
|
84
90
|
editorConfig: editorConfig,
|
|
85
91
|
editorContainerRef: editorContainerRef,
|
|
92
|
+
isSmallWidthViewport: isSmallWidthViewport,
|
|
86
93
|
onChange: onChange
|
|
87
94
|
})
|
|
88
95
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LexicalProvider.js","names":["LexicalComposer","React","useMemo","EditorConfigProvider","useEditorConfigContext","LexicalEditor","LexicalEditorComponent","getEnabledNodes","NestProviders","children","providers","length","Component","_jsx","slice","LexicalProvider","props","composerKey","editorConfig","fieldProps","onChange","readOnly","value","parentContext","editorContainerRef","useRef","initialConfig","Error","JSON","stringify","Array","isArray","editable","editorState","undefined","namespace","lexical","nodes","onError","error","theme","features"],"sources":["../../src/lexical/LexicalProvider.tsx"],"sourcesContent":["'use client'\nimport type { InitialConfigType } from '@lexical/react/LexicalComposer.js'\nimport type { EditorState, LexicalEditor, SerializedEditorState } from 'lexical'\nimport
|
|
1
|
+
{"version":3,"file":"LexicalProvider.js","names":["LexicalComposer","useEditDepth","React","useMemo","EditorConfigProvider","useEditorConfigContext","LexicalEditor","LexicalEditorComponent","getEnabledNodes","NestProviders","children","providers","length","Component","_jsx","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","features"],"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"],"mappings":"AAAA;;;AAIA,SAASA,eAAe,QAAQ;AAChC,SAASC,YAAY,QAAQ;AAC7B,YAAYC,KAAA,MAAW;AACvB,SAASC,OAAO,QAAQ;AAKxB,SACEC,oBAAoB,EACpBC,sBAAsB,QACjB;AACP,SAASC,aAAA,IAAiBC,sBAAsB,QAAQ;AACxD,SAASC,eAAe,QAAQ;AAYhC,MAAMC,aAAA,GAAgBA,CAAC;EACrBC,QAAQ;EACRC;AAAS,CAKV;EACC,IAAI,CAACA,SAAA,EAAWC,MAAA,EAAQ;IACtB,OAAOF,QAAA;EACT;EACA,MAAMG,SAAA,GAAYF,SAAS,CAAC,EAAE;EAC9B,IAAIA,SAAA,CAAUC,MAAM,GAAG,GAAG;IACxB,oBACEE,IAAA,CAACD,SAAA;gBACC,aAAAC,IAAA,CAACL,aAAA;QAAcE,SAAA,EAAWA,SAAA,CAAUI,KAAK,CAAC;kBAAKL;;;EAGrD;EACA,oBAAOI,IAAA,CAACD,SAAA;cAAWH;;AACrB;AAEA,OAAO,MAAMM,eAAA,GAAmDC,KAAA;EAC9D,MAAM;IAAEC,WAAW;IAAEC,YAAY;IAAEC,UAAU;IAAEC,oBAAoB;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC;EAAK,CAAE,GAC9FP,KAAA;EAEF,MAAMQ,aAAA,GAAgBpB,sBAAA;EAEtB,MAAMqB,SAAA,GAAYzB,YAAA;EAElB,MAAM0B,kBAAA,GAAqBzB,KAAA,CAAM0B,MAAM,CAAiB;EAExD;EACA,MAAMC,aAAA,GAAgB1B,OAAA,C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BA,kBAAA;UACpBN,oBAAA,EAAsBA,oBAAA;UACtBC,QAAA,EAAUA;;;;KAfkCJ,WAAA,GAAcW,aAAA,CAAcM,QAAQ;AAqB5F","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ export interface EditorConfigContextType {
|
|
|
8
8
|
blurEditor: (editorContext: EditorConfigContextType) => void;
|
|
9
9
|
childrenEditors: React.RefObject<Map<string, EditorConfigContextType>>;
|
|
10
10
|
createdInlineBlock?: InlineBlockNode;
|
|
11
|
+
editDepth: number;
|
|
11
12
|
editor: LexicalEditor;
|
|
12
13
|
editorConfig: SanitizedClientEditorConfig;
|
|
13
14
|
editorContainerRef: React.RefObject<HTMLDivElement>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorConfigProvider.d.ts","sourceRoot":"","sources":["../../../../src/lexical/config/client/EditorConfigProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"EditorConfigProvider.d.ts","sourceRoot":"","sources":["../../../../src/lexical/config/client/EditorConfigProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAIjD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2DAA2D,CAAA;AAChG,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAO9D,MAAM,WAAW,uBAAuB;IAEtC,UAAU,EAAE,CAAC,aAAa,EAAE,uBAAuB,KAAK,IAAI,CAAA;IAC5D,eAAe,EAAE,KAAK,CAAC,SAAS,CA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erContext.js';
|
|
5
|
+
import { useEditDepth } from '@payloadcms/ui';
|
|
5
6
|
import * as React from 'react';
|
|
6
7
|
import { createContext, useContext, useMemo, useRef, useState } from 'react';
|
|
7
8
|
// Should always produce a 20 character pseudo-random string
|
|
@@ -23,11 +24,12 @@ export const EditorConfigProvider = ({
|
|
|
23
24
|
}) => {
|
|
24
25
|
const [editor] = useLexicalComposerContext();
|
|
25
26
|
// State to store the UUID
|
|
26
|
-
const [uuid] = useState(generateQuickGuid());
|
|
27
|
+
const [uuid] = useState(() => generateQuickGuid());
|
|
27
28
|
const childrenEditors = useRef(new Map());
|
|
28
29
|
const [focusedEditor, setFocusedEditor] = useState(null);
|
|
29
30
|
const focusHistory = useRef(new Set());
|
|
30
31
|
const [createdInlineBlock, setCreatedInlineBlock] = useState();
|
|
32
|
+
const editDepth = useEditDepth();
|
|
31
33
|
const editorContext_1 = useMemo(() => ({
|
|
32
34
|
blurEditor: editorContext => {
|
|
33
35
|
//setFocusedEditor(null) // Clear focused editor
|
|
@@ -36,6 +38,7 @@ export const EditorConfigProvider = ({
|
|
|
36
38
|
},
|
|
37
39
|
childrenEditors,
|
|
38
40
|
createdInlineBlock,
|
|
41
|
+
editDepth,
|
|
39
42
|
editor,
|
|
40
43
|
editorConfig,
|
|
41
44
|
editorContainerRef,
|
|
@@ -76,7 +79,7 @@ export const EditorConfigProvider = ({
|
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
81
|
uuid
|
|
79
|
-
}), [createdInlineBlock, setCreatedInlineBlock, editor, childrenEditors, editorConfig, editorContainerRef, fieldProps, focusedEditor, parentContext, uuid]);
|
|
82
|
+
}), [createdInlineBlock, setCreatedInlineBlock, editor, childrenEditors, editorConfig, editorContainerRef, editDepth, fieldProps, focusedEditor, parentContext, uuid]);
|
|
80
83
|
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
81
84
|
value: editorContext_1,
|
|
82
85
|
children: children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorConfigProvider.js","names":["useLexicalComposerContext","React","createContext","useContext","useMemo","useRef","useState","generateQuickGuid","Math","random","toString","substring","Context","editorConfig","fieldProps","uuid","EditorConfigProvider","children","editorContainerRef","parentContext","editor","childrenEditors","Map","focusedEditor","setFocusedEditor","focusHistory","Set","createdInlineBlock","setCreatedInlineBlock","editorContext","blurEditor","current","clear","focusEditor","editorUUID","has","add","forEach","childEditor","parentEditor","registerChild","childUUID","childEditorContext","newMap","set","unregisterChild","delete","_jsx","Provider","value","useEditorConfigContext","context","undefined","Error"],"sources":["../../../../src/lexical/config/client/EditorConfigProvider.tsx"],"sourcesContent":["'use client'\n\nimport type { LexicalEditor } from 'lexical'\nimport type { MarkRequired } from 'ts-essentials'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport * as React from 'react'\nimport { createContext, useContext, useMemo, useRef, useState } from 'react'\n\nimport type { InlineBlockNode } from '../../../features/blocks/client/nodes/InlineBlocksNode.js'\nimport type { LexicalRichTextFieldProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\n// Should always produce a 20 character pseudo-random string\nfunction generateQuickGuid(): string {\n return Math.random().toString(36).substring(2, 12) + Math.random().toString(36).substring(2, 12)\n}\n\nexport interface EditorConfigContextType {\n // Editor focus handling\n blurEditor: (editorContext: EditorConfigContextType) => void\n childrenEditors: React.RefObject<Map<string, EditorConfigContextType>>\n createdInlineBlock?: InlineBlockNode\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n
|
|
1
|
+
{"version":3,"file":"EditorConfigProvider.js","names":["useLexicalComposerContext","useEditDepth","React","createContext","useContext","useMemo","useRef","useState","generateQuickGuid","Math","random","toString","substring","Context","editorConfig","fieldProps","uuid","EditorConfigProvider","children","editorContainerRef","parentContext","editor","childrenEditors","Map","focusedEditor","setFocusedEditor","focusHistory","Set","createdInlineBlock","setCreatedInlineBlock","editDepth","editorContext","blurEditor","current","clear","focusEditor","editorUUID","has","add","forEach","childEditor","parentEditor","registerChild","childUUID","childEditorContext","newMap","set","unregisterChild","delete","_jsx","Provider","value","useEditorConfigContext","context","undefined","Error"],"sources":["../../../../src/lexical/config/client/EditorConfigProvider.tsx"],"sourcesContent":["'use client'\n\nimport type { LexicalEditor } from 'lexical'\nimport type { MarkRequired } from 'ts-essentials'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useEditDepth } from '@payloadcms/ui'\nimport * as React from 'react'\nimport { createContext, useContext, useMemo, useRef, useState } from 'react'\n\nimport type { InlineBlockNode } from '../../../features/blocks/client/nodes/InlineBlocksNode.js'\nimport type { LexicalRichTextFieldProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\n// Should always produce a 20 character pseudo-random string\nfunction generateQuickGuid(): string {\n return Math.random().toString(36).substring(2, 12) + Math.random().toString(36).substring(2, 12)\n}\n\nexport interface EditorConfigContextType {\n // Editor focus handling\n blurEditor: (editorContext: EditorConfigContextType) => void\n childrenEditors: React.RefObject<Map<string, EditorConfigContextType>>\n createdInlineBlock?: InlineBlockNode\n editDepth: number\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n editorContainerRef: React.RefObject<HTMLDivElement>\n fieldProps: MarkRequired<LexicalRichTextFieldProps, 'path' | 'schemaPath'>\n focusedEditor: EditorConfigContextType | null\n // Editor focus handling\n focusEditor: (editorContext: EditorConfigContextType) => void\n parentEditor: EditorConfigContextType\n registerChild: (uuid: string, editorContext: EditorConfigContextType) => void\n setCreatedInlineBlock?: React.Dispatch<React.SetStateAction<InlineBlockNode | undefined>>\n unregisterChild?: (uuid: string) => void\n uuid: string\n}\n\n// @ts-expect-error: TODO: Fix this\nconst Context: React.Context<EditorConfigContextType> = createContext({\n editorConfig: null,\n fieldProps: null,\n uuid: null,\n})\n\nexport const EditorConfigProvider = ({\n children,\n editorConfig,\n editorContainerRef,\n fieldProps,\n parentContext,\n}: {\n children: React.ReactNode\n editorConfig: SanitizedClientEditorConfig\n editorContainerRef: React.RefObject<HTMLDivElement | null>\n\n fieldProps: LexicalRichTextFieldProps\n parentContext?: EditorConfigContextType\n}): React.ReactNode => {\n const [editor] = useLexicalComposerContext()\n // State to store the UUID\n const [uuid] = useState(() => generateQuickGuid())\n\n const childrenEditors = useRef<Map<string, EditorConfigContextType>>(new Map())\n const [focusedEditor, setFocusedEditor] = useState<EditorConfigContextType | null>(null)\n const focusHistory = useRef<Set<string>>(new Set())\n const [createdInlineBlock, setCreatedInlineBlock] = useState<InlineBlockNode>()\n\n const editDepth = useEditDepth()\n\n const editorContext = useMemo(\n () =>\n ({\n blurEditor: (editorContext: EditorConfigContextType) => {\n //setFocusedEditor(null) // Clear focused editor\n focusHistory.current.clear() // Reset focus history when focus is lost\n },\n childrenEditors,\n createdInlineBlock,\n editDepth,\n editor,\n editorConfig,\n editorContainerRef,\n fieldProps,\n focusedEditor,\n focusEditor: (editorContext: EditorConfigContextType) => {\n const editorUUID = editorContext.uuid\n\n // Avoid recursion by checking if this editor is already focused in this cycle\n if (focusHistory.current.has(editorUUID)) {\n return\n }\n\n // Add this editor to the history to prevent future recursions in this cycle\n focusHistory.current.add(editorUUID)\n setFocusedEditor(editorContext)\n\n // Propagate focus event to parent and children, ensuring they do not refocus this editor\n if (parentContext?.uuid) {\n parentContext.focusEditor(editorContext)\n }\n childrenEditors.current.forEach((childEditor) => {\n childEditor.focusEditor(editorContext)\n })\n\n focusHistory.current.clear()\n },\n parentEditor: parentContext,\n registerChild: (childUUID, childEditorContext) => {\n if (!childrenEditors.current.has(childUUID)) {\n const newMap = new Map(childrenEditors.current)\n newMap.set(childUUID, childEditorContext)\n childrenEditors.current = newMap\n }\n },\n setCreatedInlineBlock,\n unregisterChild: (childUUID) => {\n if (childrenEditors.current.has(childUUID)) {\n const newMap = new Map(childrenEditors.current)\n newMap.delete(childUUID)\n childrenEditors.current = newMap\n }\n },\n\n uuid,\n }) as EditorConfigContextType,\n [\n createdInlineBlock,\n setCreatedInlineBlock,\n editor,\n childrenEditors,\n editorConfig,\n editorContainerRef,\n editDepth,\n fieldProps,\n focusedEditor,\n parentContext,\n uuid,\n ],\n )\n\n return <Context.Provider value={editorContext}>{children}</Context.Provider>\n}\n\nexport const useEditorConfigContext = (): EditorConfigContextType => {\n const context = useContext(Context)\n if (context === undefined) {\n throw new Error('useEditorConfigContext must be used within an EditorConfigProvider')\n }\n return context\n}\n"],"mappings":"AAAA;;;AAKA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,YAAY,QAAQ;AAC7B,YAAYC,KAAA,MAAW;AACvB,SAASC,aAAa,EAAEC,UAAU,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAMrE;AACA,SAASC,kBAAA;EACP,OAAOC,IAAA,CAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG,MAAMH,IAAA,CAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG;AAC/F;AAsBA;AACA,MAAMC,OAAA,gBAAkDV,aAAA,CAAc;EACpEW,YAAA,EAAc;EACdC,UAAA,EAAY;EACZC,IAAA,EAAM;AACR;AAEA,OAAO,MAAMC,oBAAA,GAAuBA,CAAC;EACnCC,QAAQ;EACRJ,YAAY;EACZK,kBAAkB;EAClBJ,UAAU;EACVK;AAAa,CAQd;EACC,MAAM,CAACC,MAAA,CAAO,GAAGrB,yBAAA;EACjB;EACA,MAAM,CAACgB,IAAA,CAAK,GAAGT,QAAA,CAAS,MAAMC,iBAAA;EAE9B,MAAMc,eAAA,GAAkBhB,MAAA,CAA6C,IAAIiB,GAAA;EACzE,MAAM,CAACC,aAAA,EAAeC,gBAAA,CAAiB,GAAGlB,QAAA,CAAyC;EACnF,MAAMmB,YAAA,GAAepB,MAAA,CAAoB,IAAIqB,GAAA;EAC7C,MAAM,CAACC,kBAAA,EAAoBC,qBAAA,CAAsB,GAAGtB,QAAA;EAEpD,MAAMuB,SAAA,GAAY7B,YAAA;EAElB,MAAM8B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AAA,CAAgBW,OAAO,GAAGY,QAAA;MAC5B;IACF;IAEA7B;EACF,IACF,CACEY,kBAAA,EACAC,qBAAA,EACAR,MAAA,EACAC,eAAA,EACAR,YAAA,EACAK,kBAAA,EACAW,SAAA,EACAf,UAAA,EACAS,aAAA,EACAJ,aAAA,EACAJ,IAAA,CACD;EAGH,oBAAOiC,IAAA,CAACpC,OAAA,CAAQqC,QAAQ;IAACC,KAAA,EAAOpB,eAAA;cAAgBb;;AAClD;AAEA,OAAO,MAAMkC,sBAAA,GAAyBA,CAAA;EACpC,MAAAC,OAAA,GAAgBjD,UAAA,CAAAS,OAAW;EAAA,IACvBwC,OAAA,KAAAC,SAAY;IAAA,UAAAC,KAAA,CACE;EAAA;EAAA,OAEXF,OAAA;AAAA,CACT","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EditorConfig as LexicalEditorConfig } from 'lexical';
|
|
2
2
|
import type { ResolvedClientFeatureMap, SanitizedClientFeatures } from '../../../features/typesClient.js';
|
|
3
|
-
import type {
|
|
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?:
|
|
6
|
+
export declare function sanitizeClientEditorConfig(resolvedClientFeatureMap: ResolvedClientFeatureMap, lexical?: LexicalEditorConfig, admin?: LexicalFieldAdminClientProps): 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;AAElE,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,
|
|
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;AAElE,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,uBA2MF,CAAA;AAED,wBAAgB,0BAA0B,CACxC,wBAAwB,EAAE,wBAAwB,EAClD,OAAO,CAAC,EAAE,mBAAmB,EAC7B,KAAK,CAAC,EAAE,4BAA4B,GACnC,2BAA2B,CAO7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.js","names":["sanitizeClientFeatures","features","sanitized","enabledFeatures","enabledFormats","markdownTransformers","nodes","plugins","providers","slashMenu","dynamicGroups","groups","toolbarFixed","toolbarInline","size","forEach","feature","length","concat","enableFormats","push","node","plugin","i","clientProps","sanitizedClientFeatureProps","Component","key","position","group","foundGroup","find","sanitizedGroup","items","filter","optionGroup","transformer","allNodes","allTransformers","sort","a","b","order","sanitizeClientEditorConfig","resolvedClientFeatureMap","lexical","admin","resolvedFeatureMap"],"sources":["../../../../src/lexical/config/client/sanitize.ts"],"sourcesContent":["'use client'\n\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport type {\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../../features/typesClient.js'\nimport type { LexicalFieldAdminProps } 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 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 // 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?: LexicalFieldAdminProps,\n): SanitizedClientEditorConfig {\n return {\n admin,\n features: sanitizeClientFeatures(resolvedClientFeatureMap),\n lexical: lexical!,\n resolvedFeatureMap: resolvedClientFeatureMap,\n }\n}\n"],"mappings":"AAAA;;AAWA,OAAO,MAAMA,sBAAA,GACXC,QAAA;EAEA,MAAMC,SAAA,GAAqC;IACzCC,eAAA,EAAiB,EAAE;IACnBC,cAAA,EAAgB,EAAE;IAClBC,oBAAA,EAAsB,EAAE;IACxBC,KAAA,EAAO,EAAE;IACTC,OAAA,EAAS,EAAE;IACXC,SAAA,EAAW,EAAE;IACbC,SAAA,EAAW;MACTC,aAAA,EAAe,EAAE;MACjBC,MAAA,EAAQ;IACV;IACAC,YAAA,EAAc;MACZD,MAAA,EAAQ;IACV;IACAE,aAAA,EAAe;MACbF,MAAA,EAAQ;IACV;EACF;EAEA,IAAI,CAACV,QAAA,EAAUa,IAAA,EAAM;IACnB,OAAOZ,SAAA;EACT;EAEAD,QAAA,CAASc,OAAO,CAAEC,OAAA;IAChB,IAAIA,OAAA,CAAQR,SAAS,EAAES,MAAA,EAAQ;MAC7Bf,SAAA,CAAUM,SAAS,GAAGN,SAAA,CAAUM,SAAS,CAACU,MAAM,CAACF,OAAA,CAAQR,SAAS;IACp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,CAAA,EAAGC,CAAA;MACnB,IAAID,CAAA,CAAEE,KAAK,IAAID,CAAA,CAAEC,KAAK,EAAE;QACtB,OAAOF,CAAA,CAAEE,KAAK,GAAGD,CAAA,CAAEC,KAAK;MAC1B,OAAO,IAAIF,CAAA,CAAEE,KAAK,EAAE;QAClB,OAAO,CAAC;MACV,OAAO,IAAID,CAAA,CAAEC,KAAK,EAAE;QAClB,OAAO;MACT,OAAO;QACL,OAAO;MACT;IACF;EACF;EAEA,OAAOxC,SAAA;AACT;AAEA,OAAO,SAASyC,2BACdC,wBAAkD,EAClDC,OAA6B,EAC7BC,KAA8B;EAE9B,OAAO;IACLA,KAAA;IACA7C,QAAA,EAAUD,sBAAA,CAAuB4C,wBAAA;IACjCC,OAAA,EAASA,OAAA;IACTE,kBAAA,EAAoBH;EACtB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"sanitize.js","names":["sanitizeClientFeatures","features","sanitized","enabledFeatures","enabledFormats","markdownTransformers","nodes","plugins","providers","slashMenu","dynamicGroups","groups","toolbarFixed","toolbarInline","size","forEach","feature","length","concat","enableFormats","push","node","plugin","i","clientProps","sanitizedClientFeatureProps","Component","key","position","group","foundGroup","find","sanitizedGroup","items","filter","optionGroup","transformer","allNodes","allTransformers","sort","a","b","order","sanitizeClientEditorConfig","resolvedClientFeatureMap","lexical","admin","resolvedFeatureMap"],"sources":["../../../../src/lexical/config/client/sanitize.ts"],"sourcesContent":["'use client'\n\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\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 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 // 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"],"mappings":"AAAA;;AAWA,OAAO,MAAMA,sBAAA,GACXC,QAAA;EAEA,MAAMC,SAAA,GAAqC;IACzCC,eAAA,EAAiB,EAAE;IACnBC,cAAA,EAAgB,EAAE;IAClBC,oBAAA,EAAsB,EAAE;IACxBC,KAAA,EAAO,EAAE;IACTC,OAAA,EAAS,EAAE;IACXC,SAAA,EAAW,EAAE;IACbC,SAAA,EAAW;MACTC,aAAA,EAAe,EAAE;MACjBC,MAAA,EAAQ;IACV;IACAC,YAAA,EAAc;MACZD,MAAA,EAAQ;IACV;IACAE,aAAA,EAAe;MACbF,MAAA,EAAQ;IACV;EACF;EAEA,IAAI,CAACV,QAAA,EAAUa,IAAA,EAAM;IACnB,OAAOZ,SAAA;EACT;EAEAD,QAAA,CAASc,OAAO,CAAEC,OAAA;IAChB,IAAIA,OAAA,CAAQR,SAAS,EAAES,MAAA,EAAQ;MAC7Bf,SAAA,CAAUM,SAAS,GAAGN,SAAA,CAAUM,SAAS,CAACU,MAAM,CAACF,OAAA,CAAQR,SAAS;IACpE;IAEA,IAAIQ,OAAA,CAAQG,aAAa,EAAEF,MAAA,EAAQ;MACjCf,SAAA,CAAUE,cAAc,CAACgB,IAAI,IAAIJ,OAAA,CAAQG,aAAa;IACxD;IAEA,IAAIH,OAAA,CAAQV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IAAIF,CAAA,CAAEE,KAAK,EAAE;QAClB,OAAO,CAAC;MACV,OAAO,IAAID,CAAA,CAAEC,KAAK,EAAE;QAClB,OAAO;MACT,OAAO;QACL,OAAO;MACT;IACF;EACF;EAEA,OAAOxC,SAAA;AACT;AAEA,OAAO,SAASyC,2BACdC,wBAAkD,EAClDC,OAA6B,EAC7BC,KAAoC;EAEpC,OAAO;IACLA,KAAA;IACA7C,QAAA,EAAUD,sBAAA,CAAuB4C,wBAAA;IACjCC,OAAA,EAASA,OAAA;IACTE,kBAAA,EAAoBH;EACtB;AACF","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EditorConfig as LexicalEditorConfig } from 'lexical';
|
|
2
2
|
import type { FeatureProviderClient, ResolvedClientFeatureMap, SanitizedClientFeatures } from '../../features/typesClient.js';
|
|
3
3
|
import type { FeatureProviderServer, ResolvedServerFeatureMap, SanitizedServerFeatures } from '../../features/typesServer.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LexicalFieldAdminClientProps } from '../../types.js';
|
|
5
5
|
export type ServerEditorConfig = {
|
|
6
6
|
features: FeatureProviderServer<any, any, any>[];
|
|
7
7
|
lexical?: LexicalEditorConfig | undefined;
|
|
@@ -16,7 +16,7 @@ export type ClientEditorConfig = {
|
|
|
16
16
|
lexical?: LexicalEditorConfig;
|
|
17
17
|
};
|
|
18
18
|
export type SanitizedClientEditorConfig = {
|
|
19
|
-
admin?:
|
|
19
|
+
admin?: LexicalFieldAdminClientProps;
|
|
20
20
|
features: SanitizedClientFeatures;
|
|
21
21
|
lexical: LexicalEditorConfig;
|
|
22
22
|
resolvedFeatureMap: ResolvedClientFeatureMap;
|
|
@@ -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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7C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"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 {
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"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"],"mappings":"AA8BA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lexical/plugins/InsertParagraphAtEnd/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,EAuB9C,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
6
|
+
import { $createParagraphNode, $getRoot } from 'lexical';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { useEditorConfigContext } from '../../config/client/EditorConfigProvider.js';
|
|
9
|
+
const baseClass = 'insert-paragraph-at-end';
|
|
10
|
+
export const InsertParagraphAtEndPlugin = () => {
|
|
11
|
+
const $ = _c(4);
|
|
12
|
+
const [editor] = useLexicalComposerContext();
|
|
13
|
+
const {
|
|
14
|
+
editorConfig
|
|
15
|
+
} = useEditorConfigContext();
|
|
16
|
+
if (editorConfig?.admin?.hideInsertParagraphAtEnd) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
let t0;
|
|
20
|
+
if ($[0] !== editor) {
|
|
21
|
+
t0 = () => {
|
|
22
|
+
editor.update(_temp);
|
|
23
|
+
};
|
|
24
|
+
$[0] = editor;
|
|
25
|
+
$[1] = t0;
|
|
26
|
+
} else {
|
|
27
|
+
t0 = $[1];
|
|
28
|
+
}
|
|
29
|
+
const onClick = t0;
|
|
30
|
+
let t1;
|
|
31
|
+
if ($[2] !== onClick) {
|
|
32
|
+
t1 = _jsx("div", {
|
|
33
|
+
"aria-label": "Insert Paragraph",
|
|
34
|
+
className: baseClass,
|
|
35
|
+
onClick,
|
|
36
|
+
children: _jsx("div", {
|
|
37
|
+
className: `${baseClass}-inside`,
|
|
38
|
+
children: _jsx("span", {
|
|
39
|
+
children: "+"
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
$[2] = onClick;
|
|
44
|
+
$[3] = t1;
|
|
45
|
+
} else {
|
|
46
|
+
t1 = $[3];
|
|
47
|
+
}
|
|
48
|
+
return t1;
|
|
49
|
+
};
|
|
50
|
+
function _temp() {
|
|
51
|
+
const paragraphNode = $createParagraphNode();
|
|
52
|
+
$getRoot().append(paragraphNode);
|
|
53
|
+
paragraphNode.select();
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$createParagraphNode","$getRoot","React","useEditorConfigContext","baseClass","InsertParagraphAtEndPlugin","$","editor","editorConfig","admin","hideInsertParagraphAtEnd","t0","update","_temp","onClick","t1","_jsx","className","children","paragraphNode","append","select"],"sources":["../../../../src/lexical/plugins/InsertParagraphAtEnd/index.tsx"],"sourcesContent":["/* eslint-disable jsx-a11y/no-static-element-interactions */\n/* eslint-disable jsx-a11y/click-events-have-key-events */\n'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { $createParagraphNode, $getRoot } from 'lexical'\nimport React from 'react'\n\nimport './index.scss'\nimport { useEditorConfigContext } from '../../config/client/EditorConfigProvider.js'\nconst baseClass = 'insert-paragraph-at-end'\n\nexport const InsertParagraphAtEndPlugin: React.FC = () => {\n const [editor] = useLexicalComposerContext()\n const { editorConfig } = useEditorConfigContext()\n\n if (editorConfig?.admin?.hideInsertParagraphAtEnd) {\n return null\n }\n\n const onClick = () => {\n editor.update(() => {\n const paragraphNode = $createParagraphNode()\n $getRoot().append(paragraphNode)\n paragraphNode.select()\n })\n }\n\n return (\n <div aria-label=\"Insert Paragraph\" className={baseClass} onClick={onClick}>\n <div className={`${baseClass}-inside`}>\n <span>+</span>\n </div>\n </div>\n )\n}\n"],"mappings":"AAAA,6DACA,0DACA;;AAAA,SAAAA,CAA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,GAAG,IAAI,CAwH/C;AAED,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -4,7 +4,7 @@ import { c as _c } from "react/compiler-runtime";
|
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
|
|
6
6
|
import { mergeRegister } from '@lexical/utils';
|
|
7
|
-
import { $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_LOW, createCommand } from 'lexical';
|
|
7
|
+
import { $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_LOW, createCommand, getDOMSelection } from 'lexical';
|
|
8
8
|
import { useCallback, useEffect, useState } from 'react';
|
|
9
9
|
import * as React from 'react';
|
|
10
10
|
import { LexicalMenu, useMenuAnchorRef } from './LexicalMenu.js';
|
|
@@ -22,7 +22,7 @@ function getTextUpToAnchor(selection) {
|
|
|
22
22
|
return anchorNode.getTextContent().slice(0, anchorOffset);
|
|
23
23
|
}
|
|
24
24
|
function tryToPositionRange(leadOffset, range, editorWindow) {
|
|
25
|
-
const domSelection = editorWindow
|
|
25
|
+
const domSelection = getDOMSelection(editorWindow);
|
|
26
26
|
if (domSelection === null || !domSelection.isCollapsed) {
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","createCommand","useCallback","useEffect","useState","React","LexicalMenu","useMenuAnchorRef","PUNCTUATION","getTextUpToAnchor","selection","anchor","type","anchorNode","getNode","isSimpleText","anchorOffset","offset","getTextContent","slice","tryToPositionRange","leadOffset","range","editorWindow","domSelection","getSelection","isCollapsed","startOffset","endOffset","setStart","setEnd","error","getQueryTextForSearch","editor","text","getEditorState","read","isSelectionOnEntityBoundary","prevSibling","getPreviousSibling","isTextEntity","startTransition","callback","useDynamicPositioning","ENABLE_SLASH_MENU_COMMAND","LexicalTypeaheadMenuPlugin","t0","$","anchorClassName","anchorElem","groups","menuRenderFn","onClose","onOpen","onQueryChange","triggerFn","resolution","setResolution","anchorElementRef","t1","closeTypeahead","t2","res","openTypeahead","t3","t4","registerCommand","t5","node","match","matchingString","replaceableString","_window","window","document","createRange","isRangePositioned","getRect","getBoundingClientRect","updateListener","editorWindow_0","range_0","undefined","match_0","query","isRangePositioned_0","removeUpdateListener","registerUpdateListener","t6","t7","current","_jsx","close","shouldSplitNodeWithQuery"],"sources":["../../../../../src/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand, LexicalEditor, ParagraphNode, RangeSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n createCommand,\n} from 'lexical'\nimport { type JSX, useCallback, useEffect, useState } from 'react'\nimport * as React from 'react'\n\nimport type { MenuTextMatch, TriggerFn } from '../useMenuTriggerMatch.js'\nimport type { MenuRenderFn, MenuResolution } from './LexicalMenu.js'\nimport type { SlashMenuGroupInternal } from './types.js'\n\nimport { LexicalMenu, useMenuAnchorRef } from './LexicalMenu.js'\n\nexport const PUNCTUATION = '\\\\.,\\\\+\\\\*\\\\?\\\\$\\\\@\\\\|#{}\\\\(\\\\)\\\\^\\\\-\\\\[\\\\]\\\\\\\\/!%\\'\"~=<>_:;'\n\nfunction getTextUpToAnchor(selection: RangeSelection): null | string {\n const anchor = selection.anchor\n if (anchor.type !== 'text') {\n return null\n }\n const anchorNode = anchor.getNode()\n if (!anchorNode.isSimpleText()) {\n return null\n }\n const anchorOffset = anchor.offset\n return anchorNode.getTextContent().slice(0, anchorOffset)\n}\n\nfunction tryToPositionRange(leadOffset: number, range: Range, editorWindow: Window): boolean {\n const domSelection = editorWindow.getSelection()\n if (domSelection === null || !domSelection.isCollapsed) {\n return false\n }\n const anchorNode = domSelection.anchorNode\n const startOffset = leadOffset\n const endOffset = domSelection.anchorOffset\n\n if (anchorNode == null || endOffset == null) {\n return false\n }\n\n try {\n range.setStart(anchorNode, startOffset)\n // if endOffset is 0, positioning the range for when you click the plus button to open the slash menu will fial\n range.setEnd(anchorNode, endOffset > 1 ? endOffset : 1)\n } catch (error) {\n return false\n }\n\n return true\n}\n\nfunction getQueryTextForSearch(editor: LexicalEditor): string | undefined {\n let text\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!$isRangeSelection(selection)) {\n return\n }\n text = getTextUpToAnchor(selection)\n })\n return text\n}\n\nfunction isSelectionOnEntityBoundary(editor: LexicalEditor, offset: number): boolean {\n if (offset !== 0) {\n return false\n }\n return editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor\n const anchorNode = anchor.getNode()\n const prevSibling = anchorNode.getPreviousSibling()\n return $isTextNode(prevSibling) && prevSibling.isTextEntity()\n }\n return false\n })\n}\n\nfunction startTransition(callback: () => void) {\n if (React.startTransition) {\n React.startTransition(callback)\n } else {\n callback()\n }\n}\n\nexport { useDynamicPositioning } from './LexicalMenu.js'\n\nexport type TypeaheadMenuPluginProps = {\n anchorClassName?: string\n anchorElem: HTMLElement\n groups: Array<SlashMenuGroupInternal>\n menuRenderFn: MenuRenderFn\n onClose?: () => void\n onOpen?: (resolution: MenuResolution) => void\n onQueryChange: (matchingString: null | string) => void\n triggerFn: TriggerFn\n}\n\nexport const ENABLE_SLASH_MENU_COMMAND: LexicalCommand<{\n node: ParagraphNode\n}> = createCommand('ENABLE_SLASH_MENU_COMMAND')\n\nexport function LexicalTypeaheadMenuPlugin({\n anchorClassName,\n anchorElem,\n groups,\n menuRenderFn,\n onClose,\n onOpen,\n onQueryChange,\n triggerFn,\n}: TypeaheadMenuPluginProps): JSX.Element | null {\n const [editor] = useLexicalComposerContext()\n const [resolution, setResolution] = useState<MenuResolution | null>(null)\n const anchorElementRef = useMenuAnchorRef(anchorElem, resolution, setResolution, anchorClassName)\n\n const closeTypeahead = useCallback(() => {\n setResolution(null)\n if (onClose != null && resolution !== null) {\n onClose()\n }\n }, [onClose, resolution])\n\n const openTypeahead = useCallback(\n (res: MenuResolution) => {\n setResolution(res)\n if (onOpen != null && resolution === null) {\n onOpen(res)\n }\n },\n [onOpen, resolution],\n )\n\n // This is mainly used for the AddBlockHandlePlugin, so that the slash menu can be opened from there\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n ENABLE_SLASH_MENU_COMMAND,\n ({ node }) => {\n editor.getEditorState().read(() => {\n const match: MenuTextMatch = {\n leadOffset: 0,\n matchingString: '',\n replaceableString: '',\n }\n if (!isSelectionOnEntityBoundary(editor, match.leadOffset)) {\n if (node !== null) {\n const editorWindow = editor._window ?? window\n const range = editorWindow.document.createRange()\n\n const isRangePositioned = tryToPositionRange(match.leadOffset, range, editorWindow)\n if (isRangePositioned !== null) {\n startTransition(() =>\n openTypeahead({\n getRect: () => {\n return range.getBoundingClientRect()\n },\n match,\n }),\n )\n }\n\n return\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, openTypeahead])\n\n useEffect(() => {\n const updateListener = () => {\n editor.getEditorState().read(() => {\n const editorWindow = editor._window ?? window\n const range = editorWindow.document.createRange()\n const selection = $getSelection()\n const text = getQueryTextForSearch(editor)\n\n if (\n !$isRangeSelection(selection) ||\n !selection.isCollapsed() ||\n text === undefined ||\n range === null\n ) {\n closeTypeahead()\n return\n }\n\n const match = triggerFn({ editor, query: text })\n onQueryChange(match ? match.matchingString : null)\n\n if (match !== null && !isSelectionOnEntityBoundary(editor, match.leadOffset)) {\n const isRangePositioned = tryToPositionRange(match.leadOffset, range, editorWindow)\n if (isRangePositioned !== null) {\n startTransition(() =>\n openTypeahead({\n getRect: () => {\n return range.getBoundingClientRect()\n },\n match,\n }),\n )\n return\n }\n }\n closeTypeahead()\n })\n }\n\n const removeUpdateListener = editor.registerUpdateListener(updateListener)\n\n return () => {\n removeUpdateListener()\n }\n }, [editor, triggerFn, onQueryChange, resolution, closeTypeahead, openTypeahead])\n\n return anchorElementRef.current === null || resolution === null || editor === null ? null : (\n <LexicalMenu\n anchorElementRef={anchorElementRef}\n close={closeTypeahead}\n editor={editor}\n groups={groups}\n menuRenderFn={menuRenderFn}\n resolution={resolution}\n shouldSplitNodeWithQuery\n />\n )\n}\n\nexport type { MenuRenderFn, MenuResolution, MenuTextMatch, TriggerFn }\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,QAAQ;AAC9B,SACEC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,oBAAoB,EACpBC,aAAa,QACR;AACP,SAAmBC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAC3D,YAAYC,KAAA,MAAW;AAMvB,SAASC,WAAW,EAAEC,gBAAgB,QAAQ;AAE9C,OAAO,MAAMC,WAAA,GAAc;AAE3B,SAASC,kBAAkBC,SAAyB;EAClD,MAAMC,MAAA,GAASD,SAAA,CAAUC,MAAM;EAC/B,IAAIA,MAAA,CAAOC,IAAI,KAAK,QAAQ;IAC1B,OAAO;EACT;EACA,MAAMC,UAAA,GAAaF,MAAA,CAAOG,OAAO;EACjC,IAAI,CAACD,UAAA,CAAWE,YAAY,IAAI;IAC9B,OAAO;EACT;EACA,MAAMC,YAAA,GAAeL,MAAA,CAAOM,MAAM;EAClC,OAAOJ,UAAA,CAAWK,cAAc,GAAGC,KAAK,CAAC,GAAGH,YAAA;AAC9C;AAEA,SAASI,mBAAmBC,UAAkB,EAAEC,KAAY,EAAEC,YAAoB;EAChF,MAAMC,YAAA,GAAeD,YAAA,CAAaE,YAAY;EAC9C,IAAID,YAAA,KAAiB,QAAQ,CAACA,YAAA,CAAa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c","_c","useLexicalComposerContext","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","createCommand","getDOMSelection","useCallback","useEffect","useState","React","LexicalMenu","useMenuAnchorRef","PUNCTUATION","getTextUpToAnchor","selection","anchor","type","anchorNode","getNode","isSimpleText","anchorOffset","offset","getTextContent","slice","tryToPositionRange","leadOffset","range","editorWindow","domSelection","isCollapsed","startOffset","endOffset","setStart","setEnd","error","getQueryTextForSearch","editor","text","getEditorState","read","isSelectionOnEntityBoundary","prevSibling","getPreviousSibling","isTextEntity","startTransition","callback","useDynamicPositioning","ENABLE_SLASH_MENU_COMMAND","LexicalTypeaheadMenuPlugin","t0","$","anchorClassName","anchorElem","groups","menuRenderFn","onClose","onOpen","onQueryChange","triggerFn","resolution","setResolution","anchorElementRef","t1","closeTypeahead","t2","res","openTypeahead","t3","t4","registerCommand","t5","node","match","matchingString","replaceableString","_window","window","document","createRange","isRangePositioned","getRect","getBoundingClientRect","updateListener","editorWindow_0","range_0","undefined","match_0","query","isRangePositioned_0","removeUpdateListener","registerUpdateListener","t6","t7","current","_jsx","close","shouldSplitNodeWithQuery"],"sources":["../../../../../src/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand, LexicalEditor, ParagraphNode, RangeSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n createCommand,\n getDOMSelection,\n} from 'lexical'\nimport { type JSX, useCallback, useEffect, useState } from 'react'\nimport * as React from 'react'\n\nimport type { MenuTextMatch, TriggerFn } from '../useMenuTriggerMatch.js'\nimport type { MenuRenderFn, MenuResolution } from './LexicalMenu.js'\nimport type { SlashMenuGroupInternal } from './types.js'\n\nimport { LexicalMenu, useMenuAnchorRef } from './LexicalMenu.js'\n\nexport const PUNCTUATION = '\\\\.,\\\\+\\\\*\\\\?\\\\$\\\\@\\\\|#{}\\\\(\\\\)\\\\^\\\\-\\\\[\\\\]\\\\\\\\/!%\\'\"~=<>_:;'\n\nfunction getTextUpToAnchor(selection: RangeSelection): null | string {\n const anchor = selection.anchor\n if (anchor.type !== 'text') {\n return null\n }\n const anchorNode = anchor.getNode()\n if (!anchorNode.isSimpleText()) {\n return null\n }\n const anchorOffset = anchor.offset\n return anchorNode.getTextContent().slice(0, anchorOffset)\n}\n\nfunction tryToPositionRange(leadOffset: number, range: Range, editorWindow: Window): boolean {\n const domSelection = getDOMSelection(editorWindow)\n if (domSelection === null || !domSelection.isCollapsed) {\n return false\n }\n\n const anchorNode = domSelection.anchorNode\n const startOffset = leadOffset\n const endOffset = domSelection.anchorOffset\n\n if (anchorNode == null || endOffset == null) {\n return false\n }\n\n try {\n range.setStart(anchorNode, startOffset)\n // if endOffset is 0, positioning the range for when you click the plus button to open the slash menu will fial\n range.setEnd(anchorNode, endOffset > 1 ? endOffset : 1)\n } catch (error) {\n return false\n }\n\n return true\n}\n\nfunction getQueryTextForSearch(editor: LexicalEditor): string | undefined {\n let text\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!$isRangeSelection(selection)) {\n return\n }\n text = getTextUpToAnchor(selection)\n })\n return text\n}\n\nfunction isSelectionOnEntityBoundary(editor: LexicalEditor, offset: number): boolean {\n if (offset !== 0) {\n return false\n }\n return editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor\n const anchorNode = anchor.getNode()\n const prevSibling = anchorNode.getPreviousSibling()\n return $isTextNode(prevSibling) && prevSibling.isTextEntity()\n }\n return false\n })\n}\n\nfunction startTransition(callback: () => void) {\n if (React.startTransition) {\n React.startTransition(callback)\n } else {\n callback()\n }\n}\n\nexport { useDynamicPositioning } from './LexicalMenu.js'\n\nexport type TypeaheadMenuPluginProps = {\n anchorClassName?: string\n anchorElem: HTMLElement\n groups: Array<SlashMenuGroupInternal>\n menuRenderFn: MenuRenderFn\n onClose?: () => void\n onOpen?: (resolution: MenuResolution) => void\n onQueryChange: (matchingString: null | string) => void\n triggerFn: TriggerFn\n}\n\nexport const ENABLE_SLASH_MENU_COMMAND: LexicalCommand<{\n node: ParagraphNode\n}> = createCommand('ENABLE_SLASH_MENU_COMMAND')\n\nexport function LexicalTypeaheadMenuPlugin({\n anchorClassName,\n anchorElem,\n groups,\n menuRenderFn,\n onClose,\n onOpen,\n onQueryChange,\n triggerFn,\n}: TypeaheadMenuPluginProps): JSX.Element | null {\n const [editor] = useLexicalComposerContext()\n const [resolution, setResolution] = useState<MenuResolution | null>(null)\n const anchorElementRef = useMenuAnchorRef(anchorElem, resolution, setResolution, anchorClassName)\n\n const closeTypeahead = useCallback(() => {\n setResolution(null)\n if (onClose != null && resolution !== null) {\n onClose()\n }\n }, [onClose, resolution])\n\n const openTypeahead = useCallback(\n (res: MenuResolution) => {\n setResolution(res)\n if (onOpen != null && resolution === null) {\n onOpen(res)\n }\n },\n [onOpen, resolution],\n )\n\n // This is mainly used for the AddBlockHandlePlugin, so that the slash menu can be opened from there\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n ENABLE_SLASH_MENU_COMMAND,\n ({ node }) => {\n editor.getEditorState().read(() => {\n const match: MenuTextMatch = {\n leadOffset: 0,\n matchingString: '',\n replaceableString: '',\n }\n if (!isSelectionOnEntityBoundary(editor, match.leadOffset)) {\n if (node !== null) {\n const editorWindow = editor._window ?? window\n const range = editorWindow.document.createRange()\n\n const isRangePositioned = tryToPositionRange(match.leadOffset, range, editorWindow)\n if (isRangePositioned !== null) {\n startTransition(() =>\n openTypeahead({\n getRect: () => {\n return range.getBoundingClientRect()\n },\n match,\n }),\n )\n }\n\n return\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, openTypeahead])\n\n useEffect(() => {\n const updateListener = () => {\n editor.getEditorState().read(() => {\n const editorWindow = editor._window ?? window\n const range = editorWindow.document.createRange()\n const selection = $getSelection()\n const text = getQueryTextForSearch(editor)\n\n if (\n !$isRangeSelection(selection) ||\n !selection.isCollapsed() ||\n text === undefined ||\n range === null\n ) {\n closeTypeahead()\n return\n }\n\n const match = triggerFn({ editor, query: text })\n onQueryChange(match ? match.matchingString : null)\n\n if (match !== null && !isSelectionOnEntityBoundary(editor, match.leadOffset)) {\n const isRangePositioned = tryToPositionRange(match.leadOffset, range, editorWindow)\n if (isRangePositioned !== null) {\n startTransition(() =>\n openTypeahead({\n getRect: () => {\n return range.getBoundingClientRect()\n },\n match,\n }),\n )\n return\n }\n }\n closeTypeahead()\n })\n }\n\n const removeUpdateListener = editor.registerUpdateListener(updateListener)\n\n return () => {\n removeUpdateListener()\n }\n }, [editor, triggerFn, onQueryChange, resolution, closeTypeahead, openTypeahead])\n\n return anchorElementRef.current === null || resolution === null || editor === null ? null : (\n <LexicalMenu\n anchorElementRef={anchorElementRef}\n close={closeTypeahead}\n editor={editor}\n groups={groups}\n menuRenderFn={menuRenderFn}\n resolution={resolution}\n shouldSplitNodeWithQuery\n />\n )\n}\n\nexport type { MenuRenderFn, MenuResolution, MenuTextMatch, TriggerFn }\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,QAAQ;AAC9B,SACEC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,oBAAoB,EACpBC,aAAa,EACbC,eAAe,QACV;AACP,SAAmBC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAC3D,YAAYC,KAAA,MAAW;AAMvB,SAASC,WAAW,EAAEC,gBAAgB,QAAQ;AAE9C,OAAO,MAAMC,WAAA,GAAc;AAE3B,SAASC,kBAAkBC,SAAyB;EAClD,MAAMC,MAAA,GAASD,SAAA,CAAUC,MAAM;EAC/B,IAAIA,MAAA,CAAOC,IAAI,KAAK,QAAQ;IAC1B,OAAO;EACT;EACA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AA,IAAAH,CAAA,SAAAI,YAAA,IAAAJ,CAAA,SAAAS,UAAA;IAEzEiC,EAAA,GAAA/B,gBAAA,CAAAgC,OAAA,SAA6B,IAAQlC,UAAA,SAAe,IAAQvB,MAAA,SAAW,UAC5E0D,IAAA,CAAApF,WAAA;MAAAmD,gBAAA;MAAAkC,KAAA,EAEShC,cAAA;MAAA3B,MAAA;MAAAiB,MAAA;MAAAC,YAAA;MAAAK,UAAA;MAAAqC,wBAAA;IAAA,C;;;;;;;;;;;SAHJJ,E","ignoreList":[]}
|
|
@@ -44,10 +44,6 @@ export function TextPlugin(t0) {
|
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
46
|
function getDisabledFormats(enabledFormats) {
|
|
47
|
-
// not sure why Lexical added highlight as TextNode format.
|
|
48
|
-
// see https://github.com/facebook/lexical/pull/3583
|
|
49
|
-
// We are going to implement it in other way to support multiple colors
|
|
50
|
-
delete TEXT_TYPE_TO_FORMAT.highlight;
|
|
51
47
|
const allFormats = Object.keys(TEXT_TYPE_TO_FORMAT);
|
|
52
48
|
const enabledSet = new Set(enabledFormats);
|
|
53
49
|
return allFormats.filter(format => !enabledSet.has(format));
|