@webiny/lexical-editor 5.40.4 → 5.40.5-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.
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
2
  import { CSSObject } from "@emotion/react";
3
3
  import { Klass, LexicalNode } from "lexical";
4
- import { LexicalValue, ToolbarActionPlugin } from "../../types";
5
4
  import { WebinyTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
5
+ import { LexicalValue, ToolbarActionPlugin } from "../../types";
6
6
  export interface RichTextEditorProps {
7
7
  children?: React.ReactNode | React.ReactNode[];
8
8
  classes?: string;
@@ -22,7 +22,7 @@ export interface RichTextEditorProps {
22
22
  toolbarActionPlugins?: ToolbarActionPlugin[];
23
23
  themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;
24
24
  toolbar?: React.ReactNode;
25
- value: LexicalValue | null;
25
+ value: LexicalValue | null | undefined;
26
26
  width?: number | string;
27
27
  }
28
28
  /**
@@ -22,22 +22,22 @@ var _LexicalErrorBoundary = require("@lexical/react/LexicalErrorBoundary");
22
22
  var _reactComposition = require("@webiny/react-composition");
23
23
  var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
24
24
  var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
25
+ var _lexicalTheme = require("@webiny/lexical-theme");
26
+ var _lexicalNodes = require("@webiny/lexical-nodes");
25
27
  var _RichTextEditorContext = require("../../context/RichTextEditorContext");
26
28
  var _isValidLexicalData = require("../../utils/isValidLexicalData");
27
29
  var _LexicalUpdateStatePlugin = require("../../plugins/LexicalUpdateStatePlugin");
28
30
  var _BlurEventPlugin = require("../../plugins/BlurEventPlugin/BlurEventPlugin");
29
31
  var _Placeholder = require("../../ui/Placeholder");
30
32
  var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
31
- var _lexicalTheme = require("@webiny/lexical-theme");
32
- var _lexicalNodes = require("@webiny/lexical-nodes");
33
33
  var _SharedHistoryContext = require("../../context/SharedHistoryContext");
34
34
  var _LexicalEditorConfig = require("../LexicalEditorConfig/LexicalEditorConfig");
35
- var _excluded = ["toolbar", "staticToolbar", "onChange", "value", "nodes", "placeholder", "children", "onBlur", "focus", "styles", "width", "height", "contentEditableStyles", "placeholderStyles"];
35
+ var _normalizeInputValue = require("./normalizeInputValue");
36
+ var _excluded = ["toolbar", "staticToolbar", "onChange", "nodes", "placeholder", "children", "onBlur", "focus", "styles", "width", "height", "contentEditableStyles", "placeholderStyles"];
36
37
  var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
37
38
  var toolbar = _ref.toolbar,
38
39
  staticToolbar = _ref.staticToolbar,
39
40
  onChange = _ref.onChange,
40
- value = _ref.value,
41
41
  nodes = _ref.nodes,
42
42
  placeholder = _ref.placeholder,
43
43
  children = _ref.children,
@@ -79,6 +79,7 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
79
79
  key: plugin.name
80
80
  }, plugin.element);
81
81
  });
82
+ var value = (0, _normalizeInputValue.normalizeInputValue)(props.value);
82
83
  var editorValue = (0, _isValidLexicalData.isValidLexicalData)(value) ? value : (0, _generateInitialLexicalValue.generateInitialLexicalValue)();
83
84
  var initialConfig = {
84
85
  editorState: null,
@@ -96,11 +97,11 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
96
97
  editorState.read(function () {
97
98
  if (typeof onChange === "function") {
98
99
  var _editorState = editor.getEditorState();
99
- var isEmpty = (0, _text.$isRootTextContentEmpty)(editor.isComposing(), true);
100
+ var isEditorEmpty = (0, _text.$isRootTextContentEmpty)(editor.isComposing(), true);
100
101
  var newValue = JSON.stringify(_editorState.toJSON());
101
102
 
102
- // We don't want to call "onChange" if editor text is empty, and original `value` is `undefined`.
103
- if (value === undefined && isEmpty) {
103
+ // We don't want to call "onChange" if editor text is empty, and original `value` is empty.
104
+ if (!value && isEditorEmpty) {
104
105
  return;
105
106
  }
106
107
  if (value !== newValue) {
@@ -125,7 +126,7 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
125
126
  theme: props.theme,
126
127
  themeEmotionMap: themeEmotionMap,
127
128
  toolbarActionPlugins: props.toolbarActionPlugins
128
- }, staticToolbar && staticToolbar, /*#__PURE__*/_react.default.createElement("div", {
129
+ }, staticToolbar ? staticToolbar : null, /*#__PURE__*/_react.default.createElement("div", {
129
130
  /* This className is necessary for targeting of editor container from CSS files. */
130
131
  className: "editor-shell",
131
132
  ref: scrollRef,
@@ -1 +1 @@
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,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,sBAAA,GAAAZ,OAAA;AACA,IAAAa,mBAAA,GAAAb,OAAA;AACA,IAAAc,yBAAA,GAAAd,OAAA;AACA,IAAAe,gBAAA,GAAAf,OAAA;AAEA,IAAAgB,YAAA,GAAAhB,OAAA;AACA,IAAAiB,4BAAA,GAAAjB,OAAA;AACA,IAAAkB,aAAA,GAAAlB,OAAA;AAMA,IAAAmB,aAAA,GAAAnB,OAAA;AACA,IAAAoB,qBAAA,GAAApB,OAAA;AACA,IAAAqB,oBAAA,GAAArB,OAAA;AAG8D,IAAAsB,SAAA;AAyB9D,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAAC,IAAA,EAgBG;EAAA,IAf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AAAe,aAAA,CAAC7C,uBAAA,CAAA+G,eAAe;QACZZ,KAAK,MAAArB,cAAA,CAAAhD,OAAA;UAAIkF,OAAO,EAAE;QAAC,GAAKtF,qBAAqB;MAAG,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEyB,eAAgB;MAC7BqE,aAAa,EAAEC;IAAqB,CACvC,CAAC,EAED7D,kBAAkB,IAAIvC,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACO,IAAMqG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAAE,iCAAe,EAAC,gBAAgB,EAAE,UAACzF,KAA0B,EAAK;EAC5F,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":[]}
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","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","generateInitialLexicalValue","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 WebinyTheme,\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: WebinyTheme;\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}\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 ...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 value = normalizeInputValue(props.value);\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 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,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InC,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACnD,uBAAA,CAAAoH,eAAe,MAAE,CAAC,EAE5BjD,aAAa,EACbzC,QAAQ,eACTjC,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACjD,sBAAA,CAAAmH,cAAc;MACXC,eAAe,eACX7H,MAAA,CAAA2C,OAAA,CAAAe,aAAA;QAAKsD,SAAS,EAAC,iBAAiB;QAACE,KAAK,MAAArB,cAAA,CAAAlD,OAAA,MAAO2B,SAAS;MAAG,gBACrDtE,MAAA,CAAA2C,OAAA,CAAAe,aAAA;QAAKsD,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAE7C;MAAM,gBAC/BpE,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAAC7C,uBAAA,CAAAiH,eAAe;QACZZ,KAAK,MAAArB,cAAA,CAAAlD,OAAA;UAAIoF,OAAO,EAAE;QAAC,GAAKxF,qBAAqB;MAAG,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEyB,eAAgB;MAC7BuE,aAAa,EAAEC;IAAqB,CACvC,CAAC,EAED/D,kBAAkB,IAAItC,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACO,IAAMsG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAAE,iCAAe,EAAC,gBAAgB,EAAE,UAAC3F,KAA0B,EAAK;EAC5F,oBACIzC,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACnC,oBAAA,CAAA8G,uBAAuB,qBACpBrI,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAAChC,kBAAkB,EAAKe,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import { LexicalValue, NormalizedInputValue } from "../../types";
2
+ /**
3
+ * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
4
+ * of input into a value that is either a `null` or a `LexicalValue`.
5
+ */
6
+ export declare function normalizeInputValue(value: LexicalValue | null | undefined): NormalizedInputValue;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeInputValue = normalizeInputValue;
7
+ var isValueEmpty = function isValueEmpty(value) {
8
+ return [undefined, null, "", '""', "null"].includes(value);
9
+ };
10
+
11
+ /**
12
+ * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
13
+ * of input into a value that is either a `null` or a `LexicalValue`.
14
+ */
15
+ function normalizeInputValue(value) {
16
+ if (isValueEmpty(value)) {
17
+ return null;
18
+ }
19
+ return value;
20
+ }
21
+
22
+ //# sourceMappingURL=normalizeInputValue.js.map
@@ -0,0 +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":";;;;;;AAEA,IAAMA,YAAY,GAAG,SAAfA,YAAYA,CAAIC,KAAU,EAAK;EACjC,OAAO,CAACC,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAACC,QAAQ,CAACF,KAAK,CAAC;AAC9D,CAAC;;AAED;AACA;AACA;AACA;AACO,SAASG,mBAAmBA,CAACH,KAAsC,EAAE;EACxE,IAAID,YAAY,CAACC,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EAEA,OAAOA,KAAK;AAChB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/lexical-editor",
3
- "version": "5.40.4",
3
+ "version": "5.40.5-beta.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/webiny/webiny-js.git"
@@ -15,10 +15,10 @@
15
15
  "@lexical/selection": "0.16.1",
16
16
  "@lexical/text": "0.16.1",
17
17
  "@lexical/utils": "0.16.1",
18
- "@webiny/lexical-nodes": "5.40.4",
19
- "@webiny/lexical-theme": "5.40.4",
20
- "@webiny/react-composition": "5.40.4",
21
- "@webiny/react-properties": "5.40.4",
18
+ "@webiny/lexical-nodes": "5.40.5-beta.0",
19
+ "@webiny/lexical-theme": "5.40.5-beta.0",
20
+ "@webiny/react-composition": "5.40.5-beta.0",
21
+ "@webiny/react-properties": "5.40.5-beta.0",
22
22
  "emotion": "10.0.27",
23
23
  "lexical": "0.16.1",
24
24
  "lodash": "4.17.21",
@@ -26,8 +26,8 @@
26
26
  "react-dom": "18.2.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@webiny/cli": "5.40.4",
30
- "@webiny/project-utils": "5.40.4"
29
+ "@webiny/cli": "5.40.5-beta.0",
30
+ "@webiny/project-utils": "5.40.5-beta.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public",
@@ -37,5 +37,5 @@
37
37
  "build": "yarn webiny run build",
38
38
  "watch": "yarn webiny run watch"
39
39
  },
40
- "gitHead": "1be8d8c3ebb404e7582ee9b426d8ec870afb5b99"
40
+ "gitHead": "f67778732392ed88f28da869ddacbf08a98cdec6"
41
41
  }
package/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export declare type ToolbarType = "heading" | "paragraph" | string;
2
1
  export declare type LexicalValue = string;
2
+ export declare type NormalizedInputValue = LexicalValue | null;
3
3
  export { FontColorPicker } from "./components/ToolbarActions/FontColorAction";
4
4
  export declare type ImageActionType = "image-action";
5
5
  export declare type ToolbarActionType = ImageActionType | string;
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_FontColorAction","require","_commands","_RichTextEditor","_lexical"],"sources":["types.ts"],"sourcesContent":["export type ToolbarType = \"heading\" | \"paragraph\" | string;\nexport type LexicalValue = string;\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type ImageActionType = \"image-action\";\nexport type ToolbarActionType = ImageActionType | string;\nexport interface ToolbarActionPlugin {\n targetAction: ToolbarActionType;\n plugin: Record<string, any> | ((cb: (value: any) => void) => any) | undefined;\n}\n\n/* Commands payload types */\nexport { ImagePayload } from \"~/commands\";\n\n/* Lexical editor interfaces */\nexport { RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\n\n// lexical types\nexport { Klass, LexicalNode } from \"lexical\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAUA,IAAAC,SAAA,GAAAD,OAAA;AAGA,IAAAE,eAAA,GAAAF,OAAA;AAGA,IAAAG,QAAA,GAAAH,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_FontColorAction","require","_commands","_RichTextEditor","_lexical"],"sources":["types.ts"],"sourcesContent":["export type LexicalValue = string;\n\nexport type NormalizedInputValue = LexicalValue | null;\n\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type ImageActionType = \"image-action\";\nexport type ToolbarActionType = ImageActionType | string;\nexport interface ToolbarActionPlugin {\n targetAction: ToolbarActionType;\n plugin: Record<string, any> | ((cb: (value: any) => void) => any) | undefined;\n}\n\n/* Commands payload types */\nexport { ImagePayload } from \"~/commands\";\n\n/* Lexical editor interfaces */\nexport { RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\n\n// lexical types\nexport { Klass, LexicalNode } from \"lexical\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAAA,gBAAA,GAAAC,OAAA;AAUA,IAAAC,SAAA,GAAAD,OAAA;AAGA,IAAAE,eAAA,GAAAF,OAAA;AAGA,IAAAG,QAAA,GAAAH,OAAA","ignoreList":[]}