@webiny/lexical-editor 5.40.3 → 5.40.4-beta.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.
@@ -13,6 +13,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
13
13
  var _react = _interopRequireWildcard(require("react"));
14
14
  var _emotion = require("emotion");
15
15
  var _LexicalComposer = require("@lexical/react/LexicalComposer");
16
+ var _text = require("@lexical/text");
16
17
  var _LexicalOnChangePlugin = require("@lexical/react/LexicalOnChangePlugin");
17
18
  var _LexicalAutoFocusPlugin = require("@lexical/react/LexicalAutoFocusPlugin");
18
19
  var _LexicalClearEditorPlugin = require("@lexical/react/LexicalClearEditorPlugin");
@@ -80,7 +81,6 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
80
81
  });
81
82
  var editorValue = (0, _isValidLexicalData.isValidLexicalData)(value) ? value : (0, _generateInitialLexicalValue.generateInitialLexicalValue)();
82
83
  var initialConfig = {
83
- // We update the state via the `<LexicalUpdateStatePlugin/>`.
84
84
  editorState: null,
85
85
  namespace: "webiny",
86
86
  onError: function onError() {
@@ -96,10 +96,16 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
96
96
  editorState.read(function () {
97
97
  if (typeof onChange === "function") {
98
98
  var _editorState = editor.getEditorState();
99
- // The timeout is necessary to prevent the `flushSync` warning by React.
100
- setTimeout(function () {
101
- onChange(JSON.stringify(_editorState.toJSON()));
102
- }, 0);
99
+ var isEmpty = (0, _text.$isRootTextContentEmpty)(editor.isComposing(), true);
100
+ var newValue = JSON.stringify(_editorState.toJSON());
101
+
102
+ // We don't want to call "onChange" if editor text is empty, and original `value` is `undefined`.
103
+ if (value === undefined && isEmpty) {
104
+ return;
105
+ }
106
+ if (value !== newValue) {
107
+ onChange(newValue);
108
+ }
103
109
  }
104
110
  });
105
111
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_emotion","_LexicalComposer","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_reactComposition","_LexicalHistoryPlugin","_LexicalContentEditable","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_Placeholder","_generateInitialLexicalValue","_lexicalTheme","_lexicalNodes","_SharedHistoryContext","_LexicalEditorConfig","_excluded","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","contentEditableStyles","placeholderStyles","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","editorValue","isValidLexicalData","generateInitialLexicalValue","initialConfig","editorState","namespace","onError","concat","_toConsumableArray2","allNodes","_objectSpread2","current","emotionMap","handleOnChange","editor","read","getEditorState","setTimeout","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 { 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 { 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 {\n createTheme,\n WebinyTheme,\n ThemeEmotionMap,\n toTypographyEmotionMap\n} from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\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: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n toolbar?: React.ReactNode;\n value: LexicalValue | null;\n width?: number | string;\n}\n\nconst BaseRichTextEditor = ({\n toolbar,\n staticToolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n contentEditableStyles,\n placeholderStyles,\n ...props\n}: RichTextEditorProps) => {\n const themeEmotionMap =\n props.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n\n const editorTheme = useRef(createTheme());\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 editorValue = isValidLexicalData(value) ? value : generateInitialLexicalValue();\n\n const initialConfig = {\n // We update the state via the `<LexicalUpdateStatePlugin/>`.\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 // The timeout is necessary to prevent the `flushSync` warning by React.\n setTimeout(() => {\n onChange(JSON.stringify(editorState.toJSON()));\n }, 0);\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}\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,gB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AAAoG,eAAe;MAACnF,MAAM,EAAEA;IAAO,CAAE,CAAC,EAC7CC,KAAK,iBAAIlC,MAAA,CAAA0C,OAAA,CAAAe,aAAA,CAACnD,uBAAA,CAAA+G,eAAe,MAAE,CAAC,EAE5B5C,aAAa,EACbzC,QAAQ,eACThC,MAAA,CAAA0C,OAAA,CAAAe,aAAA,CAACjD,sBAAA,CAAA8G,cAAc;MACXC,eAAe,eACXvH,MAAA,CAAA0C,OAAA,CAAAe,aAAA;QAAKiD,SAAS,EAAC,iBAAiB;QAACE,KAAK,MAAAlB,cAAA,CAAAhD,OAAA,MAAO2B,SAAS;MAAG,gBACrDrE,MAAA,CAAA0C,OAAA,CAAAe,aAAA;QAAKiD,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAExC;MAAM,gBAC/BnE,MAAA,CAAA0C,OAAA,CAAAe,aAAA,CAAC7C,uBAAA,CAAA4G,eAAe;QACZZ,KAAK,MAAAlB,cAAA,CAAAhD,OAAA;UAAI+E,OAAO,EAAE;QAAC,GAAKnF,qBAAqB;MAAG,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEyB,eAAgB;MAC7BkE,aAAa,EAAEC;IAAqB,CACvC,CAAC,EAED1D,kBAAkB,IAAIvC,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACO,IAAMkG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAAE,iCAAe,EAAC,gBAAgB,EAAE,UAACtF,KAA0B,EAAK;EAC5F,oBACIxC,MAAA,CAAA0C,OAAA,CAAAe,aAAA,CAACnC,oBAAA,CAAAyG,uBAAuB,qBACpB/H,MAAA,CAAA0C,OAAA,CAAAe,aAAA,CAACjC,kBAAkB,EAAKgB,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_emotion","_LexicalComposer","_text","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_reactComposition","_LexicalHistoryPlugin","_LexicalContentEditable","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_Placeholder","_generateInitialLexicalValue","_lexicalTheme","_lexicalNodes","_SharedHistoryContext","_LexicalEditorConfig","_excluded","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","contentEditableStyles","placeholderStyles","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","editorValue","isValidLexicalData","generateInitialLexicalValue","initialConfig","editorState","namespace","onError","concat","_toConsumableArray2","allNodes","_objectSpread2","current","emotionMap","handleOnChange","editor","read","getEditorState","isEmpty","$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 { 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 {\n createTheme,\n WebinyTheme,\n ThemeEmotionMap,\n toTypographyEmotionMap\n} from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\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: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n toolbar?: React.ReactNode;\n value: LexicalValue | null;\n width?: number | string;\n}\n\nconst BaseRichTextEditor = ({\n toolbar,\n staticToolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n contentEditableStyles,\n placeholderStyles,\n ...props\n}: RichTextEditorProps) => {\n const themeEmotionMap =\n props.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n\n const editorTheme = useRef(createTheme());\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 editorValue = isValidLexicalData(value) ? value : generateInitialLexicalValue();\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 isEmpty = $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 `undefined`.\n if (value === undefined && isEmpty) {\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}\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,G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AC5F,oBACIzC,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACnC,oBAAA,CAAA4G,uBAAuB,qBACpBnI,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACjC,kBAAkB,EAAKgB,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/lexical-editor",
3
- "version": "5.40.3",
3
+ "version": "5.40.4-beta.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/webiny/webiny-js.git"
@@ -8,25 +8,26 @@
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
10
  "@emotion/react": "11.10.8",
11
- "@lexical/code": "0.16.0",
12
- "@lexical/history": "0.16.0",
13
- "@lexical/react": "0.16.0",
14
- "@lexical/rich-text": "0.16.0",
15
- "@lexical/selection": "0.16.0",
16
- "@lexical/utils": "0.16.0",
17
- "@webiny/lexical-nodes": "5.40.3",
18
- "@webiny/lexical-theme": "5.40.3",
19
- "@webiny/react-composition": "5.40.3",
20
- "@webiny/react-properties": "5.40.3",
11
+ "@lexical/code": "0.16.1",
12
+ "@lexical/history": "0.16.1",
13
+ "@lexical/react": "0.16.1",
14
+ "@lexical/rich-text": "0.16.1",
15
+ "@lexical/selection": "0.16.1",
16
+ "@lexical/text": "0.16.1",
17
+ "@lexical/utils": "0.16.1",
18
+ "@webiny/lexical-nodes": "5.40.4-beta.0",
19
+ "@webiny/lexical-theme": "5.40.4-beta.0",
20
+ "@webiny/react-composition": "5.40.4-beta.0",
21
+ "@webiny/react-properties": "5.40.4-beta.0",
21
22
  "emotion": "10.0.27",
22
- "lexical": "0.16.0",
23
+ "lexical": "0.16.1",
23
24
  "lodash": "4.17.21",
24
25
  "react": "18.2.0",
25
26
  "react-dom": "18.2.0"
26
27
  },
27
28
  "devDependencies": {
28
- "@webiny/cli": "5.40.3",
29
- "@webiny/project-utils": "5.40.3"
29
+ "@webiny/cli": "5.40.4-beta.0",
30
+ "@webiny/project-utils": "5.40.4-beta.0"
30
31
  },
31
32
  "publishConfig": {
32
33
  "access": "public",
@@ -36,5 +37,5 @@
36
37
  "build": "yarn webiny run build",
37
38
  "watch": "yarn webiny run watch"
38
39
  },
39
- "gitHead": "deb698c829c8633fd9abdab70cd61ad42387eef7"
40
+ "gitHead": "ac47eaeffd087f0c296abd3eef68c6f8e320cd7d"
40
41
  }
@@ -35,7 +35,10 @@ var UpdateStatePlugin = exports.UpdateStatePlugin = function UpdateStatePlugin(_
35
35
  // We must set the state outside the `editor.update()` callback to prevent freezing.
36
36
  // https://lexical.dev/docs/api/classes/lexical.LexicalEditor#seteditorstate
37
37
  if (newState) {
38
- editor.setEditorState(newState);
38
+ var state = newState;
39
+ queueMicrotask(function () {
40
+ editor.setEditorState(state);
41
+ });
39
42
  }
40
43
  }
41
44
  }, [value, editor]);
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_isValidLexicalData","_generateInitialLexicalValue","_hooks","UpdateStatePlugin","exports","_ref","value","_useRichTextEditor","useRichTextEditor","editor","useEffect","newState","update","editorState","getEditorState","JSON","stringify","toJSON","parsedState","parseLexicalState","parseEditorState","generateInitialLexicalValue","err","console","log","message","setEditorState"],"sources":["UpdateStatePlugin.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { parseLexicalState } from \"~/utils/isValidLexicalData\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { LexicalValue } from \"~/types\";\nimport { useRichTextEditor } from \"~/hooks\";\n\ninterface UpdateStatePluginProps {\n value: LexicalValue | null;\n}\n\n/**\n * Updates the lexical state if new value is provided to the lexical editor through props.\n */\nexport const UpdateStatePlugin = ({ value }: UpdateStatePluginProps) => {\n const { editor } = useRichTextEditor();\n useEffect(() => {\n if (value && editor) {\n let newState;\n\n editor.update(() => {\n const editorState = editor.getEditorState();\n\n if (JSON.stringify(editorState.toJSON()) === value) {\n return;\n }\n\n try {\n const parsedState = parseLexicalState(value);\n newState = editor.parseEditorState(\n parsedState || generateInitialLexicalValue()\n );\n } catch (err) {\n console.log(\"Lexical state update error\", err.message);\n // Ignore errors\n }\n });\n\n // We must set the state outside the `editor.update()` callback to prevent freezing.\n // https://lexical.dev/docs/api/classes/lexical.LexicalEditor#seteditorstate\n if (newState) {\n editor.setEditorState(newState);\n }\n }\n }, [value, editor]);\n\n return null;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,4BAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAMA;AACA;AACA;AACO,IAAMI,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,SAApBA,iBAAiBA,CAAAE,IAAA,EAA0C;EAAA,IAApCC,KAAK,GAAAD,IAAA,CAALC,KAAK;EACrC,IAAAC,kBAAA,GAAmB,IAAAC,wBAAiB,EAAC,CAAC;IAA9BC,MAAM,GAAAF,kBAAA,CAANE,MAAM;EACd,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAIJ,KAAK,IAAIG,MAAM,EAAE;MACjB,IAAIE,QAAQ;MAEZF,MAAM,CAACG,MAAM,CAAC,YAAM;QAChB,IAAMC,WAAW,GAAGJ,MAAM,CAACK,cAAc,CAAC,CAAC;QAE3C,IAAIC,IAAI,CAACC,SAAS,CAACH,WAAW,CAACI,MAAM,CAAC,CAAC,CAAC,KAAKX,KAAK,EAAE;UAChD;QACJ;QAEA,IAAI;UACA,IAAMY,WAAW,GAAG,IAAAC,qCAAiB,EAACb,KAAK,CAAC;UAC5CK,QAAQ,GAAGF,MAAM,CAACW,gBAAgB,CAC9BF,WAAW,IAAI,IAAAG,wDAA2B,EAAC,CAC/C,CAAC;QACL,CAAC,CAAC,OAAOC,GAAG,EAAE;UACVC,OAAO,CAACC,GAAG,CAAC,4BAA4B,EAAEF,GAAG,CAACG,OAAO,CAAC;UACtD;QACJ;MACJ,CAAC,CAAC;;MAEF;MACA;MACA,IAAId,QAAQ,EAAE;QACVF,MAAM,CAACiB,cAAc,CAACf,QAAQ,CAAC;MACnC;IACJ;EACJ,CAAC,EAAE,CAACL,KAAK,EAAEG,MAAM,CAAC,CAAC;EAEnB,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_isValidLexicalData","_generateInitialLexicalValue","_hooks","UpdateStatePlugin","exports","_ref","value","_useRichTextEditor","useRichTextEditor","editor","useEffect","newState","update","editorState","getEditorState","JSON","stringify","toJSON","parsedState","parseLexicalState","parseEditorState","generateInitialLexicalValue","err","console","log","message","state","queueMicrotask","setEditorState"],"sources":["UpdateStatePlugin.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { parseLexicalState } from \"~/utils/isValidLexicalData\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { LexicalValue } from \"~/types\";\nimport { useRichTextEditor } from \"~/hooks\";\n\ninterface UpdateStatePluginProps {\n value: LexicalValue | null;\n}\n\n/**\n * Updates the lexical state if new value is provided to the lexical editor through props.\n */\nexport const UpdateStatePlugin = ({ value }: UpdateStatePluginProps) => {\n const { editor } = useRichTextEditor();\n useEffect(() => {\n if (value && editor) {\n let newState;\n\n editor.update(() => {\n const editorState = editor.getEditorState();\n\n if (JSON.stringify(editorState.toJSON()) === value) {\n return;\n }\n\n try {\n const parsedState = parseLexicalState(value);\n newState = editor.parseEditorState(\n parsedState || generateInitialLexicalValue()\n );\n } catch (err) {\n console.log(\"Lexical state update error\", err.message);\n // Ignore errors\n }\n });\n\n // We must set the state outside the `editor.update()` callback to prevent freezing.\n // https://lexical.dev/docs/api/classes/lexical.LexicalEditor#seteditorstate\n if (newState) {\n const state = newState;\n queueMicrotask(() => {\n editor.setEditorState(state);\n });\n }\n }\n }, [value, editor]);\n\n return null;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAA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