@webiny/lexical-editor 5.43.2 → 6.0.0-alpha.0
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/commands/image.js +2 -8
- package/commands/image.js.map +1 -1
- package/commands/index.js +4 -49
- package/commands/index.js.map +1 -1
- package/commands/list.js +4 -10
- package/commands/list.js.map +1 -1
- package/commands/quote.js +2 -8
- package/commands/quote.js.map +1 -1
- package/commands/toolbar.js +2 -8
- package/commands/toolbar.js.map +1 -1
- package/components/Editor/EnsureHeadingTagPlugin.js +10 -16
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
- package/components/Editor/HeadingEditor.js +13 -21
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/ParagraphEditor.js +12 -19
- package/components/Editor/ParagraphEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.js +92 -105
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/Editor/normalizeInputValue.js +2 -8
- package/components/Editor/normalizeInputValue.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +39 -49
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditorConfig/components/Node.js +17 -26
- package/components/LexicalEditorConfig/components/Node.js.map +1 -1
- package/components/LexicalEditorConfig/components/Plugin.js +17 -26
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +17 -26
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
- package/components/LexicalHtmlRenderer.js +37 -46
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.d.ts +3 -1
- package/components/Toolbar/StaticToolbar.js +19 -23
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/Toolbar/Toolbar.js +66 -75
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +16 -21
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +26 -31
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +16 -21
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.js +32 -42
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/FontSizeAction.js +53 -71
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +19 -34
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +16 -21
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +19 -24
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +26 -33
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +20 -25
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.js +36 -45
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +43 -55
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +16 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +2 -9
- package/context/FontColorActionContext.js.map +1 -1
- package/context/RichTextEditorContext.js +15 -26
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.js +12 -20
- package/context/SharedHistoryContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.js +2 -9
- package/context/TextAlignmentActionContextProps.js.map +1 -1
- package/context/TypographyActionContext.js +2 -9
- package/context/TypographyActionContext.js.map +1 -1
- package/hooks/index.js +8 -93
- package/hooks/index.js.map +1 -1
- package/hooks/useCurrentElement.d.ts +2 -2
- package/hooks/useCurrentElement.js +12 -18
- package/hooks/useCurrentElement.js.map +1 -1
- package/hooks/useCurrentSelection.js +27 -40
- package/hooks/useCurrentSelection.js.map +1 -1
- package/hooks/useFontColorPicker.js +5 -11
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useIsMounted.js +6 -14
- package/hooks/useIsMounted.js.map +1 -1
- package/hooks/useList.js +31 -35
- package/hooks/useList.js.map +1 -1
- package/hooks/useQuote.js +12 -17
- package/hooks/useQuote.js.map +1 -1
- package/hooks/useRichTextEditor.js +5 -11
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.js +5 -11
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.js +5 -11
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.js +49 -322
- package/index.js.map +1 -1
- package/package.json +8 -7
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +9 -14
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.js +1 -16
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +16 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +158 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +8 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +62 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +2 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -16
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +11 -180
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +2 -3
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +54 -68
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +16 -26
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +3 -9
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +19 -22
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToNode.js +4 -10
- package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToSelection.js +28 -44
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.js +59 -58
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js +23 -23
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/index.js +1 -16
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.js +30 -37
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/plugins/ListPLugin/ListPlugin.js +10 -15
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +11 -16
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +16 -21
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +6 -38
- package/types.js.map +1 -1
- package/ui/ContentEditable.js +7 -14
- package/ui/ContentEditable.js.map +1 -1
- package/ui/Divider.js +3 -10
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.js +61 -88
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.js +78 -83
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.js +22 -29
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.js +10 -16
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.js +11 -18
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.js +30 -42
- package/ui/ToolbarActionDialog.js.map +1 -1
- package/utils/canUseDOM.js +1 -7
- package/utils/canUseDOM.js.map +1 -1
- package/utils/files.js +9 -26
- package/utils/files.js.map +1 -1
- package/utils/generateInitialLexicalValue.js +2 -8
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getDOMRangeRect.js +4 -10
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getSelectedNode.js +9 -16
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/getTransparentImage.js +1 -7
- package/utils/getTransparentImage.js.map +1 -1
- package/utils/insertImage.js +8 -14
- package/utils/insertImage.js.map +1 -1
- package/utils/isAnchorLink.js +1 -7
- package/utils/isAnchorLink.js.map +1 -1
- package/utils/isChildOfFloatingToolbar.js +3 -9
- package/utils/isChildOfFloatingToolbar.js.map +1 -1
- package/utils/isHTMLElement.js +1 -7
- package/utils/isHTMLElement.js.map +1 -1
- package/utils/isValidJSON.js +3 -9
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +1 -1
- package/utils/isValidLexicalData.js +6 -12
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/point.js +35 -60
- package/utils/point.js.map +1 -1
- package/utils/rect.js +114 -149
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js +6 -13
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.js +11 -19
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +0 -2
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +0 -96
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_emotion","_LexicalComposer","_text","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_reactComposition","_LexicalHistoryPlugin","_LexicalContentEditable","_lexicalTheme","_lexicalNodes","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_Placeholder","_generateInitialLexicalValue","_SharedHistoryContext","_LexicalEditorConfig","_normalizeInputValue","_excluded","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","nodes","placeholder","children","onBlur","focus","styles","width","height","contentEditableStyles","placeholderStyles","_ref$generateInitialV","generateInitialValue","generateInitialLexicalValue","props","_objectWithoutProperties2","default","themeEmotionMap","toTypographyEmotionMap","css","theme","themeStylesTransformer","editorTheme","useRef","createTheme","config","useLexicalEditorConfig","_useSharedHistoryCont","useSharedHistoryContext","historyState","placeholderElem","createElement","Placeholder","scrollRef","_useState","useState","undefined","_useState2","_slicedToArray2","floatingAnchorElem","setFloatingAnchorElem","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","Fragment","key","name","element","value","normalizeInputValue","editorValue","isValidLexicalData","initialConfig","editorState","namespace","onError","concat","_toConsumableArray2","allNodes","_objectSpread2","current","emotionMap","handleOnChange","editor","read","getEditorState","isEditorEmpty","$isRootTextContentEmpty","isComposing","newValue","JSON","stringify","toJSON","SharedHistoryContext","LexicalComposer","length","RichTextEditorProvider","toolbarActionPlugins","className","ref","style","overflow","position","OnChangePlugin","UpdateStatePlugin","ClearEditorPlugin","HistoryPlugin","externalHistoryState","BlurEventPlugin","AutoFocusPlugin","RichTextPlugin","contentEditable","ContentEditable","outline","ErrorBoundary","LexicalErrorBoundary","RichTextEditor","exports","makeDecoratable","LexicalEditorWithConfig"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useRef, useState } from \"react\";\nimport { css } from \"emotion\";\nimport { CSSObject } from \"@emotion/react\";\nimport { Klass, LexicalEditor, LexicalNode } from \"lexical\";\nimport { EditorState } from \"lexical/LexicalEditorState\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { $isRootTextContentEmpty } from \"@lexical/text\";\nimport { OnChangePlugin } from \"@lexical/react/LexicalOnChangePlugin\";\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { ClearEditorPlugin } from \"@lexical/react/LexicalClearEditorPlugin\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport {\n createTheme,\n EditorTheme,\n ThemeEmotionMap,\n toTypographyEmotionMap\n} from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { UpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { LexicalValue, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\nimport { normalizeInputValue } from \"./normalizeInputValue\";\n\nexport interface RichTextEditorProps {\n children?: React.ReactNode | React.ReactNode[];\n classes?: string;\n contentEditableStyles?: React.CSSProperties;\n focus?: boolean;\n height?: number | string;\n nodes?: Klass<LexicalNode>[];\n onBlur?: (editorState: LexicalValue) => void;\n onChange?: (json: LexicalValue) => void;\n placeholder?: string;\n placeholderStyles?: React.CSSProperties;\n staticToolbar?: React.ReactNode;\n styles?: React.CSSProperties;\n tag?: string;\n theme: EditorTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n toolbar?: React.ReactNode;\n value: LexicalValue | null | undefined;\n width?: number | string;\n generateInitialValue?: () => LexicalValue;\n}\n\nconst BaseRichTextEditor = ({\n toolbar,\n staticToolbar,\n onChange,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n contentEditableStyles,\n placeholderStyles,\n generateInitialValue = generateInitialLexicalValue,\n ...props\n}: RichTextEditorProps) => {\n const themeEmotionMap =\n props.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n\n const editorTheme = useRef(createTheme(props.theme));\n const config = useLexicalEditorConfig();\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = (\n <Placeholder styles={placeholderStyles}>{placeholder || \"Enter text...\"}</Placeholder>\n );\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const onRef = (_floatingAnchorElem: HTMLDivElement) => {\n if (_floatingAnchorElem !== null) {\n setFloatingAnchorElem(_floatingAnchorElem);\n }\n };\n\n const sizeStyle = {\n height: height || \"\",\n width: width || \"\"\n };\n\n const configNodes = config.nodes.map(node => node.node);\n const configPlugins = config.plugins.map(plugin => (\n <Fragment key={plugin.name}>{plugin.element}</Fragment>\n ));\n\n const value = normalizeInputValue(props.value);\n const editorValue = isValidLexicalData(value) ? value : generateInitialValue();\n\n const initialConfig = {\n editorState: null,\n namespace: \"webiny\",\n onError: () => {\n // Ignore errors. We don't want to break the app because of errors caused by config/value updates.\n // These are usually resolved in the next component render cycle.\n },\n nodes: [...allNodes, ...configNodes, ...(nodes || [])],\n theme: { ...editorTheme.current, emotionMap: themeEmotionMap }\n };\n\n function handleOnChange(editorState: EditorState, editor: LexicalEditor) {\n editorState.read(() => {\n if (typeof onChange === \"function\") {\n const editorState = editor.getEditorState();\n const isEditorEmpty = $isRootTextContentEmpty(editor.isComposing(), true);\n\n const newValue = JSON.stringify(editorState.toJSON());\n\n // We don't want to call \"onChange\" if editor text is empty, and original `value` is empty.\n if (!value && isEditorEmpty) {\n return;\n }\n\n if (value !== newValue) {\n onChange(newValue);\n }\n }\n });\n }\n\n return (\n /**\n * Once the LexicalComposer is mounted, it caches the `initialConfig` internally, and all future\n * updates to the config will be ignored. This is a problem because we pull in Nodes from our config,\n * and initially, there can be multiple re-renders, while the config object is settled.\n *\n * To bypass this issue, we generate a naive `key` based on the number of Nodes.\n */\n <SharedHistoryContext>\n <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <RichTextEditorProvider\n theme={props.theme}\n themeEmotionMap={themeEmotionMap}\n toolbarActionPlugins={props.toolbarActionPlugins}\n >\n {staticToolbar ? staticToolbar : null}\n <div\n /* This className is necessary for targeting of editor container from CSS files. */\n className={\"editor-shell\"}\n ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\", position: \"relative\" }}\n >\n {/* State plugins. */}\n <OnChangePlugin onChange={handleOnChange} />\n <UpdateStatePlugin value={editorValue} />\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Event plugins. */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components. */}\n {configPlugins}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef}>\n <ContentEditable\n style={{ outline: 0, ...contentEditableStyles }}\n />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar. */}\n {floatingAnchorElem && toolbar}\n </div>\n </RichTextEditorProvider>\n </LexicalComposer>\n </SharedHistoryContext>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeDecoratable(\"RichTextEditor\", (props: RichTextEditorProps) => {\n return (\n <LexicalEditorWithConfig>\n <BaseRichTextEditor {...props} />\n </LexicalEditorWithConfig>\n );\n});\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAIA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;AACA,IAAAK,uBAAA,GAAAL,OAAA;AACA,IAAAM,yBAAA,GAAAN,OAAA;AACA,IAAAO,sBAAA,GAAAP,OAAA;AACA,IAAAQ,qBAAA,GAAAR,OAAA;AACA,IAAAS,iBAAA,GAAAT,OAAA;AACA,IAAAU,qBAAA,GAAAV,OAAA;AACA,IAAAW,uBAAA,GAAAX,OAAA;AACA,IAAAY,aAAA,GAAAZ,OAAA;AAMA,IAAAa,aAAA,GAAAb,OAAA;AACA,IAAAc,sBAAA,GAAAd,OAAA;AACA,IAAAe,mBAAA,GAAAf,OAAA;AACA,IAAAgB,yBAAA,GAAAhB,OAAA;AACA,IAAAiB,gBAAA,GAAAjB,OAAA;AAEA,IAAAkB,YAAA,GAAAlB,OAAA;AACA,IAAAmB,4BAAA,GAAA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AC,EAE5BhD,aAAa,EACb5C,QAAQ,eACTjC,MAAA,CAAA8C,OAAA,CAAAe,aAAA,CAACpD,sBAAA,CAAAqH,cAAc;MACXC,eAAe,eACX/H,MAAA,CAAA8C,OAAA,CAAAe,aAAA;QAAKqD,SAAS,EAAC,iBAAiB;QAACE,KAAK,MAAArB,cAAA,CAAAjD,OAAA,MAAO2B,SAAS;MAAG,gBACrDzE,MAAA,CAAA8C,OAAA,CAAAe,aAAA;QAAKqD,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAE5C;MAAM,gBAC/BvE,MAAA,CAAA8C,OAAA,CAAAe,aAAA,CAAChD,uBAAA,CAAAmH,eAAe;QACZZ,KAAK,MAAArB,cAAA,CAAAjD,OAAA;UAAImF,OAAO,EAAE;QAAC,GAAK1F,qBAAqB;MAAG,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAE4B,eAAgB;MAC7BsE,aAAa,EAAEC;IAAqB,CACvC,CAAC,EAED9D,kBAAkB,IAAIzC,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACO,IAAMwG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAAE,iCAAe,EAAC,gBAAgB,EAAE,UAAC1F,KAA0B,EAAK;EAC5F,oBACI5C,MAAA,CAAA8C,OAAA,CAAAe,aAAA,CAACtC,oBAAA,CAAAgH,uBAAuB,qBACpBvI,MAAA,CAAA8C,OAAA,CAAAe,aAAA,CAACnC,kBAAkB,EAAKkB,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","Fragment","useRef","useState","css","LexicalComposer","$isRootTextContentEmpty","OnChangePlugin","AutoFocusPlugin","ClearEditorPlugin","RichTextPlugin","LexicalErrorBoundary","makeDecoratable","HistoryPlugin","ContentEditable","createTheme","toTypographyEmotionMap","allNodes","RichTextEditorProvider","isValidLexicalData","UpdateStatePlugin","BlurEventPlugin","Placeholder","generateInitialLexicalValue","SharedHistoryContext","useSharedHistoryContext","LexicalEditorWithConfig","useLexicalEditorConfig","normalizeInputValue","BaseRichTextEditor","toolbar","staticToolbar","onChange","nodes","placeholder","children","onBlur","focus","styles","width","height","contentEditableStyles","placeholderStyles","generateInitialValue","props","themeEmotionMap","theme","themeStylesTransformer","editorTheme","config","historyState","placeholderElem","createElement","scrollRef","floatingAnchorElem","setFloatingAnchorElem","undefined","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","key","name","element","value","editorValue","initialConfig","editorState","namespace","onError","current","emotionMap","handleOnChange","editor","read","getEditorState","isEditorEmpty","isComposing","newValue","JSON","stringify","toJSON","length","toolbarActionPlugins","className","ref","style","overflow","position","externalHistoryState","contentEditable","outline","ErrorBoundary","RichTextEditor"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useRef, useState } from \"react\";\nimport { css } from \"emotion\";\nimport { CSSObject } from \"@emotion/react\";\nimport { Klass, LexicalEditor, LexicalNode } from \"lexical\";\nimport { EditorState } from \"lexical/LexicalEditorState\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { $isRootTextContentEmpty } from \"@lexical/text\";\nimport { OnChangePlugin } from \"@lexical/react/LexicalOnChangePlugin\";\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { ClearEditorPlugin } from \"@lexical/react/LexicalClearEditorPlugin\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport {\n createTheme,\n EditorTheme,\n ThemeEmotionMap,\n toTypographyEmotionMap\n} from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { UpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { LexicalValue, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\nimport { normalizeInputValue } from \"./normalizeInputValue\";\n\nexport interface RichTextEditorProps {\n children?: React.ReactNode | React.ReactNode[];\n classes?: string;\n contentEditableStyles?: React.CSSProperties;\n focus?: boolean;\n height?: number | string;\n nodes?: Klass<LexicalNode>[];\n onBlur?: (editorState: LexicalValue) => void;\n onChange?: (json: LexicalValue) => void;\n placeholder?: string;\n placeholderStyles?: React.CSSProperties;\n staticToolbar?: React.ReactNode;\n styles?: React.CSSProperties;\n tag?: string;\n theme: EditorTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n toolbar?: React.ReactNode;\n value: LexicalValue | null | undefined;\n width?: number | string;\n generateInitialValue?: () => LexicalValue;\n}\n\nconst BaseRichTextEditor = ({\n toolbar,\n staticToolbar,\n onChange,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n contentEditableStyles,\n placeholderStyles,\n generateInitialValue = generateInitialLexicalValue,\n ...props\n}: RichTextEditorProps) => {\n const themeEmotionMap =\n props.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n\n const editorTheme = useRef(createTheme(props.theme));\n const config = useLexicalEditorConfig();\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = (\n <Placeholder styles={placeholderStyles}>{placeholder || \"Enter text...\"}</Placeholder>\n );\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const onRef = (_floatingAnchorElem: HTMLDivElement) => {\n if (_floatingAnchorElem !== null) {\n setFloatingAnchorElem(_floatingAnchorElem);\n }\n };\n\n const sizeStyle = {\n height: height || \"\",\n width: width || \"\"\n };\n\n const configNodes = config.nodes.map(node => node.node);\n const configPlugins = config.plugins.map(plugin => (\n <Fragment key={plugin.name}>{plugin.element}</Fragment>\n ));\n\n const value = normalizeInputValue(props.value);\n const editorValue = isValidLexicalData(value) ? value : generateInitialValue();\n\n const initialConfig = {\n editorState: null,\n namespace: \"webiny\",\n onError: () => {\n // Ignore errors. We don't want to break the app because of errors caused by config/value updates.\n // These are usually resolved in the next component render cycle.\n },\n nodes: [...allNodes, ...configNodes, ...(nodes || [])],\n theme: { ...editorTheme.current, emotionMap: themeEmotionMap }\n };\n\n function handleOnChange(editorState: EditorState, editor: LexicalEditor) {\n editorState.read(() => {\n if (typeof onChange === \"function\") {\n const editorState = editor.getEditorState();\n const isEditorEmpty = $isRootTextContentEmpty(editor.isComposing(), true);\n\n const newValue = JSON.stringify(editorState.toJSON());\n\n // We don't want to call \"onChange\" if editor text is empty, and original `value` is empty.\n if (!value && isEditorEmpty) {\n return;\n }\n\n if (value !== newValue) {\n onChange(newValue);\n }\n }\n });\n }\n\n return (\n /**\n * Once the LexicalComposer is mounted, it caches the `initialConfig` internally, and all future\n * updates to the config will be ignored. This is a problem because we pull in Nodes from our config,\n * and initially, there can be multiple re-renders, while the config object is settled.\n *\n * To bypass this issue, we generate a naive `key` based on the number of Nodes.\n */\n <SharedHistoryContext>\n <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <RichTextEditorProvider\n theme={props.theme}\n themeEmotionMap={themeEmotionMap}\n toolbarActionPlugins={props.toolbarActionPlugins}\n >\n {staticToolbar ? staticToolbar : null}\n <div\n /* This className is necessary for targeting of editor container from CSS files. */\n className={\"editor-shell\"}\n ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\", position: \"relative\" }}\n >\n {/* State plugins. */}\n <OnChangePlugin onChange={handleOnChange} />\n <UpdateStatePlugin value={editorValue} />\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Event plugins. */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components. */}\n {configPlugins}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef}>\n <ContentEditable\n style={{ outline: 0, ...contentEditableStyles }}\n />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar. */}\n {floatingAnchorElem && toolbar}\n </div>\n </RichTextEditorProvider>\n </LexicalComposer>\n </SharedHistoryContext>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeDecoratable(\"RichTextEditor\", (props: RichTextEditorProps) => {\n return (\n <LexicalEditorWithConfig>\n <BaseRichTextEditor {...props} />\n </LexicalEditorWithConfig>\n );\n});\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzD,SAASC,GAAG,QAAQ,SAAS;AAI7B,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,uBAAuB,QAAQ,eAAe;AACvD,SAASC,cAAc,QAAQ,sCAAsC;AACrE,SAASC,eAAe,QAAQ,uCAAuC;AACvE,SAASC,iBAAiB,QAAQ,yCAAyC;AAC3E,SAASC,cAAc,QAAQ,sCAAsC;AACrE,SAASC,oBAAoB,QAAQ,qCAAqC;AAC1E,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,aAAa,QAAQ,qCAAqC;AACnE,SAAS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CAAC,EAEpDd,MAAM,iBAAIpC,KAAA,CAAAoD,aAAA,CAAC/B,eAAe;MAACe,MAAM,EAAEA;IAAO,CAAE,CAAC,EAC7CC,KAAK,iBAAIrC,KAAA,CAAAoD,aAAA,CAAC5C,eAAe,MAAE,CAAC,EAE5BuD,aAAa,EACb5B,QAAQ,eACTnC,KAAA,CAAAoD,aAAA,CAAC1C,cAAc;MACXqF,eAAe,eACX/F,KAAA,CAAAoD,aAAA;QAAKqC,SAAS,EAAC,iBAAiB;QAACE,KAAK,EAAE;UAAE,GAAGhC;QAAU;MAAE,gBACrD3D,KAAA,CAAAoD,aAAA;QAAKqC,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAEjC;MAAM,gBAC/BzD,KAAA,CAAAoD,aAAA,CAACtC,eAAe;QACZ6E,KAAK,EAAE;UAAEK,OAAO,EAAE,CAAC;UAAE,GAAGvD;QAAsB;MAAE,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEiB,eAAgB;MAC7B8C,aAAa,EAAEtF;IAAqB,CACvC,CAAC,EAED2C,kBAAkB,IAAIxB,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMoE,cAAc,GAAGtF,eAAe,CAAC,gBAAgB,EAAGgC,KAA0B,IAAK;EAC5F,oBACI5C,KAAA,CAAAoD,aAAA,CAAC1B,uBAAuB,qBACpB1B,KAAA,CAAAoD,aAAA,CAACvB,kBAAkB,EAAKe,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.normalizeInputValue = normalizeInputValue;
|
|
7
|
-
var isValueEmpty = function isValueEmpty(value) {
|
|
1
|
+
const isValueEmpty = value => {
|
|
8
2
|
return [undefined, null, "", '""', "null"].includes(value);
|
|
9
3
|
};
|
|
10
4
|
|
|
@@ -12,7 +6,7 @@ var isValueEmpty = function isValueEmpty(value) {
|
|
|
12
6
|
* Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
|
|
13
7
|
* of input into a value that is either a `null` or a `LexicalValue`.
|
|
14
8
|
*/
|
|
15
|
-
function normalizeInputValue(value) {
|
|
9
|
+
export function normalizeInputValue(value) {
|
|
16
10
|
if (isValueEmpty(value)) {
|
|
17
11
|
return null;
|
|
18
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isValueEmpty","value","undefined","includes","normalizeInputValue"],"sources":["normalizeInputValue.ts"],"sourcesContent":["import { LexicalValue, NormalizedInputValue } from \"~/types\";\n\nconst isValueEmpty = (value: any) => {\n return [undefined, null, \"\", '\"\"', \"null\"].includes(value);\n};\n\n/**\n * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes\n * of input into a value that is either a `null` or a `LexicalValue`.\n */\nexport function normalizeInputValue(value: LexicalValue | null | undefined) {\n if (isValueEmpty(value)) {\n return null;\n }\n\n return value as NormalizedInputValue;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["isValueEmpty","value","undefined","includes","normalizeInputValue"],"sources":["normalizeInputValue.ts"],"sourcesContent":["import { LexicalValue, NormalizedInputValue } from \"~/types\";\n\nconst isValueEmpty = (value: any) => {\n return [undefined, null, \"\", '\"\"', \"null\"].includes(value);\n};\n\n/**\n * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes\n * of input into a value that is either a `null` or a `LexicalValue`.\n */\nexport function normalizeInputValue(value: LexicalValue | null | undefined) {\n if (isValueEmpty(value)) {\n return null;\n }\n\n return value as NormalizedInputValue;\n}\n"],"mappings":"AAEA,MAAMA,YAAY,GAAIC,KAAU,IAAK;EACjC,OAAO,CAACC,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAACC,QAAQ,CAACF,KAAK,CAAC;AAC9D,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASG,mBAAmBA,CAACH,KAAsC,EAAE;EACxE,IAAID,YAAY,CAACC,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EAEA,OAAOA,KAAK;AAChB","ignoreList":[]}
|
|
@@ -1,67 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
var _reactComposition = require("@webiny/react-composition");
|
|
13
|
-
var _reactProperties = require("@webiny/react-properties");
|
|
14
|
-
var _ToolbarElement = require("./components/ToolbarElement");
|
|
15
|
-
var _Plugin = require("./components/Plugin");
|
|
16
|
-
var _Node = require("./components/Node");
|
|
17
|
-
var LexicalEditorConfigApply = (0, _reactComposition.makeDecoratable)("LexicalEditorConfigApply", function (_ref) {
|
|
18
|
-
var children = _ref.children;
|
|
19
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
1
|
+
import React, { useContext, useMemo, useState } from "react";
|
|
2
|
+
import { makeDecoratable, Compose } from "@webiny/react-composition";
|
|
3
|
+
import { Properties, toObject } from "@webiny/react-properties";
|
|
4
|
+
import { ToolbarElement } from "./components/ToolbarElement";
|
|
5
|
+
import { Plugin } from "./components/Plugin";
|
|
6
|
+
import { Node } from "./components/Node";
|
|
7
|
+
const LexicalEditorConfigApply = makeDecoratable("LexicalEditorConfigApply", ({
|
|
8
|
+
children
|
|
9
|
+
}) => {
|
|
10
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
20
11
|
});
|
|
21
|
-
|
|
22
|
-
return function (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
12
|
+
const createHOC = newChildren => BaseComponent => {
|
|
13
|
+
return function ConfigHOC({
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
return /*#__PURE__*/React.createElement(BaseComponent, null, newChildren, children);
|
|
27
17
|
};
|
|
28
18
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
export const LexicalEditorConfig = ({
|
|
20
|
+
children
|
|
21
|
+
}) => {
|
|
22
|
+
return /*#__PURE__*/React.createElement(Compose, {
|
|
32
23
|
component: LexicalEditorConfigApply,
|
|
33
24
|
with: createHOC(children)
|
|
34
25
|
});
|
|
35
26
|
};
|
|
36
|
-
LexicalEditorConfig.ToolbarElement =
|
|
37
|
-
LexicalEditorConfig.Plugin =
|
|
38
|
-
LexicalEditorConfig.Node =
|
|
39
|
-
|
|
27
|
+
LexicalEditorConfig.ToolbarElement = ToolbarElement;
|
|
28
|
+
LexicalEditorConfig.Plugin = Plugin;
|
|
29
|
+
LexicalEditorConfig.Node = Node;
|
|
30
|
+
const ViewContext = /*#__PURE__*/React.createContext({
|
|
40
31
|
properties: []
|
|
41
32
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var context = {
|
|
49
|
-
properties: properties
|
|
33
|
+
export const LexicalEditorWithConfig = ({
|
|
34
|
+
children
|
|
35
|
+
}) => {
|
|
36
|
+
const [properties, setProperties] = useState([]);
|
|
37
|
+
const context = {
|
|
38
|
+
properties
|
|
50
39
|
};
|
|
51
|
-
|
|
40
|
+
const stateUpdater = properties => {
|
|
52
41
|
setProperties(properties);
|
|
53
42
|
};
|
|
54
|
-
return /*#__PURE__*/
|
|
43
|
+
return /*#__PURE__*/React.createElement(ViewContext.Provider, {
|
|
55
44
|
value: context
|
|
56
|
-
}, /*#__PURE__*/
|
|
45
|
+
}, /*#__PURE__*/React.createElement(Properties, {
|
|
57
46
|
onChange: stateUpdater
|
|
58
|
-
}, /*#__PURE__*/
|
|
47
|
+
}, /*#__PURE__*/React.createElement(LexicalEditorConfigApply, null), children));
|
|
59
48
|
};
|
|
60
|
-
function useLexicalEditorConfig() {
|
|
61
|
-
|
|
62
|
-
properties
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
export function useLexicalEditorConfig() {
|
|
50
|
+
const {
|
|
51
|
+
properties
|
|
52
|
+
} = useContext(ViewContext);
|
|
53
|
+
const config = useMemo(() => {
|
|
54
|
+
return toObject(properties);
|
|
65
55
|
}, [properties]);
|
|
66
56
|
return {
|
|
67
57
|
toolbarElements: config.toolbarElements || [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useContext","useMemo","useState","makeDecoratable","Compose","Properties","toObject","ToolbarElement","Plugin","Node","LexicalEditorConfigApply","children","createElement","Fragment","createHOC","newChildren","BaseComponent","ConfigHOC","LexicalEditorConfig","component","with","ViewContext","createContext","properties","LexicalEditorWithConfig","setProperties","context","stateUpdater","Provider","value","onChange","useLexicalEditorConfig","config","toolbarElements","plugins","nodes"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React, { useContext, useMemo, useState } from \"react\";\nimport { makeDecoratable, Compose, Decorator, GenericComponent } from \"@webiny/react-composition\";\nimport { Property, Properties, toObject } from \"@webiny/react-properties\";\nimport { ToolbarElement, ToolbarElementConfig } from \"./components/ToolbarElement\";\nimport { Plugin, PluginConfig } from \"./components/Plugin\";\nimport { Node, NodeConfig } from \"./components/Node\";\n\nconst LexicalEditorConfigApply = makeDecoratable(\"LexicalEditorConfigApply\", ({ children }) => {\n return <>{children}</>;\n});\n\nconst createHOC =\n (newChildren: React.ReactNode): Decorator<GenericComponent> =>\n BaseComponent => {\n return function ConfigHOC({ children }) {\n return (\n <BaseComponent>\n {newChildren}\n {children}\n </BaseComponent>\n );\n };\n };\n\nexport const LexicalEditorConfig = ({ children }: { children: React.ReactNode }) => {\n return <Compose component={LexicalEditorConfigApply} with={createHOC(children)} />;\n};\n\nLexicalEditorConfig.ToolbarElement = ToolbarElement;\nLexicalEditorConfig.Plugin = Plugin;\nLexicalEditorConfig.Node = Node;\n\ninterface ViewContext {\n properties: Property[];\n}\n\nconst ViewContext = React.createContext<ViewContext>({ properties: [] });\n\nexport const LexicalEditorWithConfig = ({ children }: { children: React.ReactNode }) => {\n const [properties, setProperties] = useState<Property[]>([]);\n const context = { properties };\n\n const stateUpdater = (properties: Property[]) => {\n setProperties(properties);\n };\n\n return (\n <ViewContext.Provider value={context}>\n <Properties onChange={stateUpdater}>\n <LexicalEditorConfigApply />\n {children}\n </Properties>\n </ViewContext.Provider>\n );\n};\n\ninterface LexicalEditorConfigData {\n toolbarElements: ToolbarElementConfig[];\n plugins: PluginConfig[];\n nodes: NodeConfig[];\n}\n\nexport function useLexicalEditorConfig() {\n const { properties } = useContext(ViewContext);\n\n const config = useMemo(() => {\n return toObject<LexicalEditorConfigData>(properties);\n }, [properties]);\n\n return {\n toolbarElements: config.toolbarElements || [],\n plugins: config.plugins || [],\n nodes: config.nodes || []\n };\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAC5D,SAASC,eAAe,EAAEC,OAAO,QAAqC,2BAA2B;AACjG,SAAmBC,UAAU,EAAEC,QAAQ,QAAQ,0BAA0B;AACzE,SAASC,cAAc;AACvB,SAASC,MAAM;AACf,SAASC,IAAI;AAEb,MAAMC,wBAAwB,GAAGP,eAAe,CAAC,0BAA0B,EAAE,CAAC;EAAEQ;AAAS,CAAC,KAAK;EAC3F,oBAAOZ,KAAA,CAAAa,aAAA,CAAAb,KAAA,CAAAc,QAAA,QAAGF,QAAW,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAMG,SAAS,GACVC,WAA4B,IAC7BC,aAAa,IAAI;EACb,OAAO,SAASC,SAASA,CAAC;IAAEN;EAAS,CAAC,EAAE;IACpC,oBACIZ,KAAA,CAAAa,aAAA,CAACI,aAAa,QACTD,WAAW,EACXJ,QACU,CAAC;EAExB,CAAC;AACL,CAAC;AAEL,OA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,EAAE;IAC7CC,OAAO,EAAEF,MAAM,CAACE,OAAO,IAAI,EAAE;IAC7BC,KAAK,EAAEH,MAAM,CAACG,KAAK,IAAI;EAC3B,CAAC;AACL","ignoreList":[]}
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
after = _ref$after === void 0 ? undefined : _ref$after,
|
|
15
|
-
_ref$before = _ref.before,
|
|
16
|
-
before = _ref$before === void 0 ? undefined : _ref$before,
|
|
17
|
-
_ref$remove = _ref.remove,
|
|
18
|
-
remove = _ref$remove === void 0 ? false : _ref$remove;
|
|
19
|
-
var placeBefore = before !== undefined ? "node:".concat(before) : undefined;
|
|
20
|
-
var placeAfter = after !== undefined ? "node:".concat(after) : undefined;
|
|
21
|
-
return /*#__PURE__*/_react.default.createElement(_reactProperties.Property, {
|
|
22
|
-
id: "nodes:".concat(name),
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Property } from "@webiny/react-properties";
|
|
3
|
+
export const Node = ({
|
|
4
|
+
name,
|
|
5
|
+
node,
|
|
6
|
+
after = undefined,
|
|
7
|
+
before = undefined,
|
|
8
|
+
remove = false
|
|
9
|
+
}) => {
|
|
10
|
+
const placeBefore = before !== undefined ? `node:${before}` : undefined;
|
|
11
|
+
const placeAfter = after !== undefined ? `node:${after}` : undefined;
|
|
12
|
+
return /*#__PURE__*/React.createElement(Property, {
|
|
13
|
+
id: `nodes:${name}`,
|
|
23
14
|
name: "nodes",
|
|
24
15
|
array: true,
|
|
25
16
|
before: placeBefore,
|
|
26
17
|
after: placeAfter,
|
|
27
18
|
remove: remove
|
|
28
|
-
}, /*#__PURE__*/
|
|
29
|
-
id:
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Property, {
|
|
20
|
+
id: `node:${name}:name`,
|
|
30
21
|
name: "name",
|
|
31
22
|
value: name
|
|
32
|
-
}), node ? /*#__PURE__*/
|
|
33
|
-
id:
|
|
23
|
+
}), node ? /*#__PURE__*/React.createElement(Property, {
|
|
24
|
+
id: `node:${name}:node`,
|
|
34
25
|
name: "node",
|
|
35
26
|
value: node
|
|
36
27
|
}) : null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","Property","Node","name","node","after","undefined","before","remove","placeBefore","placeAfter","createElement","id","array","value"],"sources":["Node.tsx"],"sourcesContent":["import React from \"react\";\nimport { Property } from \"@webiny/react-properties\";\nimport { Klass, LexicalNode } from \"lexical\";\n\nexport interface NodeConfig {\n name: string;\n node: Klass<LexicalNode>;\n}\n\nexport interface NodeProps {\n name: string;\n node?: Klass<LexicalNode>;\n remove?: boolean;\n before?: string;\n after?: string;\n}\n\nexport const Node = ({\n name,\n node,\n after = undefined,\n before = undefined,\n remove = false\n}: NodeProps) => {\n const placeBefore = before !== undefined ? `node:${before}` : undefined;\n const placeAfter = after !== undefined ? `node:${after}` : undefined;\n\n return (\n <Property\n id={`nodes:${name}`}\n name={\"nodes\"}\n array={true}\n before={placeBefore}\n after={placeAfter}\n remove={remove}\n >\n <Property id={`node:${name}:name`} name={\"name\"} value={name} />\n {node ? <Property id={`node:${name}:node`} name={\"node\"} value={node} /> : null}\n </Property>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,0BAA0B;AAgBnD,OAAO,MAAMC,IAAI,GAAGA,CAAC;EACjBC,IAAI;EACJC,IAAI;EACJC,KAAK,GAAGC,SAAS;EACjBC,MAAM,GAAGD,SAAS;EAClBE,MAAM,GAAG;AACF,CAAC,KAAK;EACb,MAAMC,WAAW,GAAGF,MAAM,KAAKD,SAAS,GAAG,QAAQC,MAAM,EAAE,GAAGD,SAAS;EACvE,MAAMI,UAAU,GAAGL,KAAK,KAAKC,SAAS,GAAG,QAAQD,KAAK,EAAE,GAAGC,SAAS;EAEpE,oBACIN,KAAA,CAAAW,aAAA,CAACV,QAAQ;IACLW,EAAE,EAAE,SAAST,IAAI,EAAG;IACpBA,IAAI,EAAE,OAAQ;IACdU,KAAK,EAAE,IAAK;IACZN,MAAM,EAAEE,WAAY;IACpBJ,KAAK,EAAEK,UAAW;IAClBF,MAAM,EAAEA;EAAO,gBAEfR,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACW,EAAE,EAAE,QAAQT,IAAI,OAAQ;IAACA,IAAI,EAAE,MAAO;IAACW,KAAK,EAAEX;EAAK,CAAE,CAAC,EAC/DC,IAAI,gBAAGJ,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACW,EAAE,EAAE,QAAQT,IAAI,OAAQ;IAACA,IAAI,EAAE,MAAO;IAACW,KAAK,EAAEV;EAAK,CAAE,CAAC,GAAG,IACrE,CAAC;AAEnB,CAAC","ignoreList":[]}
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
after = _ref$after === void 0 ? undefined : _ref$after,
|
|
15
|
-
_ref$before = _ref.before,
|
|
16
|
-
before = _ref$before === void 0 ? undefined : _ref$before,
|
|
17
|
-
_ref$remove = _ref.remove,
|
|
18
|
-
remove = _ref$remove === void 0 ? false : _ref$remove;
|
|
19
|
-
var placeBefore = before !== undefined ? "plugin:".concat(before) : undefined;
|
|
20
|
-
var placeAfter = after !== undefined ? "plugin:".concat(after) : undefined;
|
|
21
|
-
return /*#__PURE__*/_react.default.createElement(_reactProperties.Property, {
|
|
22
|
-
id: "plugins:".concat(name),
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Property } from "@webiny/react-properties";
|
|
3
|
+
export const Plugin = ({
|
|
4
|
+
name,
|
|
5
|
+
element,
|
|
6
|
+
after = undefined,
|
|
7
|
+
before = undefined,
|
|
8
|
+
remove = false
|
|
9
|
+
}) => {
|
|
10
|
+
const placeBefore = before !== undefined ? `plugin:${before}` : undefined;
|
|
11
|
+
const placeAfter = after !== undefined ? `plugin:${after}` : undefined;
|
|
12
|
+
return /*#__PURE__*/React.createElement(Property, {
|
|
13
|
+
id: `plugins:${name}`,
|
|
23
14
|
name: "plugins",
|
|
24
15
|
array: true,
|
|
25
16
|
before: placeBefore,
|
|
26
17
|
after: placeAfter,
|
|
27
18
|
remove: remove
|
|
28
|
-
}, /*#__PURE__*/
|
|
29
|
-
id:
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Property, {
|
|
20
|
+
id: `plugin:${name}:name`,
|
|
30
21
|
name: "name",
|
|
31
22
|
value: name
|
|
32
|
-
}), element ? /*#__PURE__*/
|
|
33
|
-
id:
|
|
23
|
+
}), element ? /*#__PURE__*/React.createElement(Property, {
|
|
24
|
+
id: `plugin:${name}:element`,
|
|
34
25
|
name: "element",
|
|
35
26
|
value: element
|
|
36
27
|
}) : null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","Property","Plugin","name","element","after","undefined","before","remove","placeBefore","placeAfter","createElement","id","array","value"],"sources":["Plugin.tsx"],"sourcesContent":["import React from \"react\";\nimport { Property } from \"@webiny/react-properties\";\n\nexport interface PluginConfig {\n name: string;\n element: React.ReactElement;\n}\n\nexport interface PluginProps {\n name: string;\n element?: React.ReactElement<unknown>;\n remove?: boolean;\n before?: string;\n after?: string;\n}\n\nexport const Plugin = ({\n name,\n element,\n after = undefined,\n before = undefined,\n remove = false\n}: PluginProps) => {\n const placeBefore = before !== undefined ? `plugin:${before}` : undefined;\n const placeAfter = after !== undefined ? `plugin:${after}` : undefined;\n\n return (\n <Property\n id={`plugins:${name}`}\n name={\"plugins\"}\n array={true}\n before={placeBefore}\n after={placeAfter}\n remove={remove}\n >\n <Property id={`plugin:${name}:name`} name={\"name\"} value={name} />\n {element ? (\n <Property id={`plugin:${name}:element`} name={\"element\"} value={element} />\n ) : null}\n </Property>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,0BAA0B;AAenD,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACnBC,IAAI;EACJC,OAAO;EACPC,KAAK,GAAGC,SAAS;EACjBC,MAAM,GAAGD,SAAS;EAClBE,MAAM,GAAG;AACA,CAAC,KAAK;EACf,MAAMC,WAAW,GAAGF,MAAM,KAAKD,SAAS,GAAG,UAAUC,MAAM,EAAE,GAAGD,SAAS;EACzE,MAAMI,UAAU,GAAGL,KAAK,KAAKC,SAAS,GAAG,UAAUD,KAAK,EAAE,GAAGC,SAAS;EAEtE,oBACIN,KAAA,CAAAW,aAAA,CAACV,QAAQ;IACLW,EAAE,EAAE,WAAWT,IAAI,EAAG;IACtBA,IAAI,EAAE,SAAU;IAChBU,KAAK,EAAE,IAAK;IACZN,MAAM,EAAEE,WAAY;IACpBJ,KAAK,EAAEK,UAAW;IAClBF,MAAM,EAAEA;EAAO,gBAEfR,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACW,EAAE,EAAE,UAAUT,IAAI,OAAQ;IAACA,IAAI,EAAE,MAAO;IAACW,KAAK,EAAEX;EAAK,CAAE,CAAC,EACjEC,OAAO,gBACJJ,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACW,EAAE,EAAE,UAAUT,IAAI,UAAW;IAACA,IAAI,EAAE,SAAU;IAACW,KAAK,EAAEV;EAAQ,CAAE,CAAC,GAC3E,IACE,CAAC;AAEnB,CAAC","ignoreList":[]}
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
after = _ref$after === void 0 ? undefined : _ref$after,
|
|
15
|
-
_ref$before = _ref.before,
|
|
16
|
-
before = _ref$before === void 0 ? undefined : _ref$before,
|
|
17
|
-
_ref$remove = _ref.remove,
|
|
18
|
-
remove = _ref$remove === void 0 ? false : _ref$remove;
|
|
19
|
-
var placeBefore = before !== undefined ? "element:".concat(before) : undefined;
|
|
20
|
-
var placeAfter = after !== undefined ? "element:".concat(after) : undefined;
|
|
21
|
-
return /*#__PURE__*/_react.default.createElement(_reactProperties.Property, {
|
|
22
|
-
id: "element:".concat(name),
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Property } from "@webiny/react-properties";
|
|
3
|
+
export const ToolbarElement = ({
|
|
4
|
+
name,
|
|
5
|
+
element,
|
|
6
|
+
after = undefined,
|
|
7
|
+
before = undefined,
|
|
8
|
+
remove = false
|
|
9
|
+
}) => {
|
|
10
|
+
const placeBefore = before !== undefined ? `element:${before}` : undefined;
|
|
11
|
+
const placeAfter = after !== undefined ? `element:${after}` : undefined;
|
|
12
|
+
return /*#__PURE__*/React.createElement(Property, {
|
|
13
|
+
id: `element:${name}`,
|
|
23
14
|
name: "toolbarElements",
|
|
24
15
|
array: true,
|
|
25
16
|
before: placeBefore,
|
|
26
17
|
after: placeAfter,
|
|
27
18
|
remove: remove
|
|
28
|
-
}, /*#__PURE__*/
|
|
29
|
-
id:
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Property, {
|
|
20
|
+
id: `element:${name}:name`,
|
|
30
21
|
name: "name",
|
|
31
22
|
value: name
|
|
32
|
-
}), element ? /*#__PURE__*/
|
|
33
|
-
id:
|
|
23
|
+
}), element ? /*#__PURE__*/React.createElement(Property, {
|
|
24
|
+
id: `element:${name}:element`,
|
|
34
25
|
name: "element",
|
|
35
26
|
value: element
|
|
36
27
|
}) : null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","Property","ToolbarElement","name","element","after","undefined","before","remove","placeBefore","placeAfter","createElement","id","array","value"],"sources":["ToolbarElement.tsx"],"sourcesContent":["import React from \"react\";\nimport { Property } from \"@webiny/react-properties\";\n\nexport interface ToolbarElementConfig {\n name: string;\n element: React.ReactElement;\n}\n\nexport interface ToolbarElementProps {\n name: string;\n element?: React.ReactElement<unknown>;\n remove?: boolean;\n before?: string;\n after?: string;\n}\n\nexport const ToolbarElement = ({\n name,\n element,\n after = undefined,\n before = undefined,\n remove = false\n}: ToolbarElementProps) => {\n const placeBefore = before !== undefined ? `element:${before}` : undefined;\n const placeAfter = after !== undefined ? `element:${after}` : undefined;\n\n return (\n <Property\n id={`element:${name}`}\n name={\"toolbarElements\"}\n array={true}\n before={placeBefore}\n after={placeAfter}\n remove={remove}\n >\n <Property id={`element:${name}:name`} name={\"name\"} value={name} />\n {element ? (\n <Property id={`element:${name}:element`} name={\"element\"} value={element} />\n ) : null}\n </Property>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,0BAA0B;AAenD,OAAO,MAAMC,cAAc,GAAGA,CAAC;EAC3BC,IAAI;EACJC,OAAO;EACPC,KAAK,GAAGC,SAAS;EACjBC,MAAM,GAAGD,SAAS;EAClBE,MAAM,GAAG;AACQ,CAAC,KAAK;EACvB,MAAMC,WAAW,GAAGF,MAAM,KAAKD,SAAS,GAAG,WAAWC,MAAM,EAAE,GAAGD,SAAS;EAC1E,MAAMI,UAAU,GAAGL,KAAK,KAAKC,SAAS,GAAG,WAAWD,KAAK,EAAE,GAAGC,SAAS;EAEvE,oBACIN,KAAA,CAAAW,aAAA,CAACV,QAAQ;IACLW,EAAE,EAAE,WAAWT,IAAI,EAAG;IACtBA,IAAI,EAAE,iBAAkB;IACxBU,KAAK,EAAE,IAAK;IACZN,MAAM,EAAEE,WAAY;IACpBJ,KAAK,EAAEK,UAAW;IAClBF,MAAM,EAAEA;EAAO,gBAEfR,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACW,EAAE,EAAE,WAAWT,IAAI,OAAQ;IAACA,IAAI,EAAE,MAAO;IAACW,KAAK,EAAEX;EAAK,CAAE,CAAC,EAClEC,OAAO,gBACJJ,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACW,EAAE,EAAE,WAAWT,IAAI,UAAW;IAACA,IAAI,EAAE,SAAU;IAACW,KAAK,EAAEV;EAAQ,CAAE,CAAC,GAC5E,IACE,CAAC;AAEnB,CAAC","ignoreList":[]}
|
|
@@ -1,66 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
20
|
-
var _isValidLexicalData = require("../utils/isValidLexicalData");
|
|
21
|
-
var _generateInitialLexicalValue = require("../utils/generateInitialLexicalValue");
|
|
22
|
-
var _LexicalUpdateStatePlugin = require("../plugins/LexicalUpdateStatePlugin");
|
|
23
|
-
var _RichTextEditorContext = require("../context/RichTextEditorContext");
|
|
24
|
-
var _excluded = ["nodes", "value"];
|
|
25
|
-
var LexicalHtmlRenderer = exports.LexicalHtmlRenderer = function LexicalHtmlRenderer(_ref) {
|
|
26
|
-
var nodes = _ref.nodes,
|
|
27
|
-
value = _ref.value,
|
|
28
|
-
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
29
|
-
var theme = (0, _objectSpread2.default)({
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
|
+
import { css } from "emotion";
|
|
3
|
+
import { LexicalComposer } from "@lexical/react/LexicalComposer";
|
|
4
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
5
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
6
|
+
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
|
7
|
+
import { allNodes } from "@webiny/lexical-nodes";
|
|
8
|
+
import { createTheme, toTypographyEmotionMap } from "@webiny/lexical-theme";
|
|
9
|
+
import { isValidLexicalData } from "../utils/isValidLexicalData";
|
|
10
|
+
import { generateInitialLexicalValue } from "../utils/generateInitialLexicalValue";
|
|
11
|
+
import { UpdateStatePlugin } from "../plugins/LexicalUpdateStatePlugin";
|
|
12
|
+
import { RichTextEditorProvider } from "../context/RichTextEditorContext";
|
|
13
|
+
export const LexicalHtmlRenderer = ({
|
|
14
|
+
nodes,
|
|
15
|
+
value,
|
|
16
|
+
...props
|
|
17
|
+
}) => {
|
|
18
|
+
const theme = {
|
|
30
19
|
styles: {},
|
|
31
|
-
emotionMap: {}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
emotionMap: {},
|
|
21
|
+
...props.theme
|
|
22
|
+
};
|
|
23
|
+
const themeEmotionMap = props?.themeEmotionMap ?? toTypographyEmotionMap(css, theme, props.themeStylesTransformer);
|
|
24
|
+
const editorTheme = useRef(createTheme(theme));
|
|
25
|
+
const editorValue = isValidLexicalData(value) ? value : generateInitialLexicalValue();
|
|
26
|
+
const initialConfig = {
|
|
37
27
|
// We update the state via the `<LexicalUpdateStatePlugin/>`.
|
|
38
28
|
editorState: null,
|
|
39
29
|
namespace: "webiny",
|
|
40
|
-
onError:
|
|
30
|
+
onError: () => {
|
|
41
31
|
// Ignore errors. We don't want to break the app because of errors caused by config/value updates.
|
|
42
32
|
// These are usually resolved in the next component render cycle.
|
|
43
33
|
},
|
|
44
34
|
editable: false,
|
|
45
|
-
nodes: [
|
|
46
|
-
theme:
|
|
35
|
+
nodes: [...allNodes, ...(nodes || [])],
|
|
36
|
+
theme: {
|
|
37
|
+
...editorTheme.current,
|
|
47
38
|
emotionMap: themeEmotionMap,
|
|
48
39
|
styles: theme.styles
|
|
49
|
-
}
|
|
40
|
+
}
|
|
50
41
|
};
|
|
51
|
-
return /*#__PURE__*/
|
|
42
|
+
return /*#__PURE__*/React.createElement(LexicalComposer, {
|
|
52
43
|
initialConfig: initialConfig,
|
|
53
44
|
key: initialConfig.nodes.length
|
|
54
|
-
}, /*#__PURE__*/
|
|
45
|
+
}, /*#__PURE__*/React.createElement(RichTextEditorProvider, {
|
|
55
46
|
theme: theme,
|
|
56
47
|
themeEmotionMap: themeEmotionMap
|
|
57
|
-
}, /*#__PURE__*/
|
|
58
|
-
contentEditable: /*#__PURE__*/
|
|
48
|
+
}, /*#__PURE__*/React.createElement(RichTextPlugin, {
|
|
49
|
+
contentEditable: /*#__PURE__*/React.createElement("div", {
|
|
59
50
|
className: "editor"
|
|
60
|
-
}, /*#__PURE__*/
|
|
61
|
-
ErrorBoundary:
|
|
51
|
+
}, /*#__PURE__*/React.createElement(ContentEditable, null)),
|
|
52
|
+
ErrorBoundary: LexicalErrorBoundary,
|
|
62
53
|
placeholder: null
|
|
63
|
-
}), /*#__PURE__*/
|
|
54
|
+
}), /*#__PURE__*/React.createElement(UpdateStatePlugin, {
|
|
64
55
|
value: editorValue
|
|
65
56
|
})));
|
|
66
57
|
};
|