@webiny/lexical-editor 5.40.2-beta.1 → 5.40.3-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.
@@ -17,7 +17,7 @@ var _LexicalOnChangePlugin = require("@lexical/react/LexicalOnChangePlugin");
17
17
  var _LexicalAutoFocusPlugin = require("@lexical/react/LexicalAutoFocusPlugin");
18
18
  var _LexicalClearEditorPlugin = require("@lexical/react/LexicalClearEditorPlugin");
19
19
  var _LexicalRichTextPlugin = require("@lexical/react/LexicalRichTextPlugin");
20
- var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/LexicalErrorBoundary"));
20
+ var _LexicalErrorBoundary = require("@lexical/react/LexicalErrorBoundary");
21
21
  var _reactComposition = require("@webiny/react-composition");
22
22
  var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
23
23
  var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
@@ -145,7 +145,7 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
145
145
  }, contentEditableStyles)
146
146
  }))),
147
147
  placeholder: placeholderElem,
148
- ErrorBoundary: _LexicalErrorBoundary.default
148
+ ErrorBoundary: _LexicalErrorBoundary.LexicalErrorBoundary
149
149
  }), floatingAnchorElem && toolbar))))
150
150
  );
151
151
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_emotion","_LexicalComposer","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_interopRequireDefault","_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","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 onChange(JSON.stringify(editorState.toJSON()));\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,sBAAA,GAAAH,OAAA;AACA,IAAAI,uBAAA,GAAAJ,OAAA;AACA,IAAAK,yBAAA,GAAAL,OAAA;AACA,IAAAM,sBAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAC,sBAAA,CAAAR,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,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KgD,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAEvC;MAAM,gBAC/BpE,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAAC7C,uBAAA,CAAA2G,eAAe;QACZZ,KAAK,MAAAjB,cAAA,CAAAhD,OAAA;UAAI8E,OAAO,EAAE;QAAC,GAAKlF,qBAAqB;MAAG,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEyB,eAAgB;MAC7BiE,aAAa,EAAEC;IAAqB,CACvC,CAAC,EAEDzD,kBAAkB,IAAIvC,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACO,IAAMiG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAAE,iCAAe,EAAC,gBAAgB,EAAE,UAACrF,KAA0B,EAAK;EAC5F,oBACIzC,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACnC,oBAAA,CAAAwG,uBAAuB,qBACpB/H,MAAA,CAAA2C,OAAA,CAAAe,aAAA,CAACjC,kBAAkB,EAAKgB,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
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","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 onChange(JSON.stringify(editorState.toJSON()));\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,sBAAA,GAAAH,OAAA;AACA,IAAAI,uBAAA,GAAAJ,OAAA;AACA,IAAAK,yBAAA,GAAAL,OAAA;AACA,IAAAM,sBAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAP,OAAA;AACA,IAAAQ,iBAAA,GAAAR,OAAA;AACA,IAAAS,qBAAA,GAAAT,OAAA;AACA,IAAAU,uBAAA,GAAAV,OAAA;AACA,IAAAW,sBAAA,GAAAX,OAAA;AACA,IAAAY,mBAAA,GAAAZ,OAAA;AACA,IAAAa,yBAAA,GAAAb,OAAA;AACA,IAAAc,gBAAA,GAAAd,OAAA;AAEA,IAAAe,YAAA,GAAAf,OAAA;AACA,IAAAgB,4BAAA,GAAAhB,OAAA;AACA,IAAAiB,aAAA,GAAAjB,OAAA;AAMA,IAAAkB,aAAA,GAAAlB,OAAA;AAC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AI8E,OAAO,EAAE;QAAC,GAAKlF,qBAAqB;MAAG,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEyB,eAAgB;MAC7BiE,aAAa,EAAEC;IAAqB,CACvC,CAAC,EAEDzD,kBAAkB,IAAIvC,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACO,IAAMiG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAAE,iCAAe,EAAC,gBAAgB,EAAE,UAACrF,KAA0B,EAAK;EAC5F,oBACIxC,MAAA,CAAA0C,OAAA,CAAAe,aAAA,CAACnC,oBAAA,CAAAwG,uBAAuB,qBACpB9H,MAAA,CAAA0C,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.2-beta.1",
3
+ "version": "5.40.3-beta.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/webiny/webiny-js.git"
@@ -14,10 +14,10 @@
14
14
  "@lexical/rich-text": "0.16.0",
15
15
  "@lexical/selection": "0.16.0",
16
16
  "@lexical/utils": "0.16.0",
17
- "@webiny/lexical-nodes": "5.40.2-beta.1",
18
- "@webiny/lexical-theme": "5.40.2-beta.1",
19
- "@webiny/react-composition": "5.40.2-beta.1",
20
- "@webiny/react-properties": "5.40.2-beta.1",
17
+ "@webiny/lexical-nodes": "5.40.3-beta.0",
18
+ "@webiny/lexical-theme": "5.40.3-beta.0",
19
+ "@webiny/react-composition": "5.40.3-beta.0",
20
+ "@webiny/react-properties": "5.40.3-beta.0",
21
21
  "emotion": "10.0.27",
22
22
  "lexical": "0.16.0",
23
23
  "lodash": "4.17.21",
@@ -25,8 +25,8 @@
25
25
  "react-dom": "18.2.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@webiny/cli": "5.40.2-beta.1",
29
- "@webiny/project-utils": "5.40.2-beta.1"
28
+ "@webiny/cli": "5.40.3-beta.0",
29
+ "@webiny/project-utils": "5.40.3-beta.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public",
@@ -36,5 +36,5 @@
36
36
  "build": "yarn webiny run build",
37
37
  "watch": "yarn webiny run watch"
38
38
  },
39
- "gitHead": "2f0be1d98a87657d119a237d772f66e15736836f"
39
+ "gitHead": "5d0f987f2b140c0383330ece647f3eb8637156ff"
40
40
  }
package/utils/files.d.ts CHANGED
@@ -8,5 +8,4 @@ export interface FileManagerFileItemMetaItem {
8
8
  key: string;
9
9
  value: any;
10
10
  }
11
- export declare const isImageType: (file: FileManagerFileItem) => boolean;
12
11
  export declare const fileToImagePayload: (file: FileManagerFileItem) => ImagePayload | null;
package/utils/files.js CHANGED
@@ -4,57 +4,33 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isImageType = exports.fileToImagePayload = void 0;
7
+ exports.fileToImagePayload = void 0;
8
8
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
9
- var isImageType = exports.isImageType = function isImageType(file) {
10
- if (!file?.meta) {
11
- return false;
12
- }
13
- var _iterator = (0, _createForOfIteratorHelper2.default)(file.meta),
14
- _step;
15
- try {
16
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
17
- var metaItem = _step.value;
18
- if (metaItem.key === "type") {
19
- return metaItem.value.includes("image/");
20
- }
21
- }
22
- } catch (err) {
23
- _iterator.e(err);
24
- } finally {
25
- _iterator.f();
26
- }
27
- return false;
28
- };
29
9
  var fileToImagePayload = exports.fileToImagePayload = function fileToImagePayload(file) {
30
- if (!file?.meta) {
31
- return null;
32
- }
33
- if (!isImageType(file)) {
34
- return null;
35
- }
36
10
  var imagePayload = {};
37
11
  imagePayload["id"] = file.id;
38
12
  imagePayload["src"] = file.src;
39
13
  imagePayload["showCaption"] = true;
40
14
  imagePayload["captionsEnabled"] = true;
41
- var _iterator2 = (0, _createForOfIteratorHelper2.default)(file.meta),
42
- _step2;
43
- try {
44
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
45
- var metaValue = _step2.value;
46
- if (metaValue.key === "name") {
47
- imagePayload["altText"] = metaValue.value;
48
- } else if (metaValue.key === "width") {
49
- imagePayload["width"] = metaValue.value;
50
- } else if (metaValue.key === "height") {
51
- imagePayload["height"] = metaValue.value;
15
+ if (file?.meta) {
16
+ var _iterator = (0, _createForOfIteratorHelper2.default)(file.meta),
17
+ _step;
18
+ try {
19
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
20
+ var metaValue = _step.value;
21
+ if (metaValue.key === "name") {
22
+ imagePayload["altText"] = metaValue.value;
23
+ } else if (metaValue.key === "width") {
24
+ imagePayload["width"] = metaValue.value;
25
+ } else if (metaValue.key === "height") {
26
+ imagePayload["height"] = metaValue.value;
27
+ }
52
28
  }
29
+ } catch (err) {
30
+ _iterator.e(err);
31
+ } finally {
32
+ _iterator.f();
53
33
  }
54
- } catch (err) {
55
- _iterator2.e(err);
56
- } finally {
57
- _iterator2.f();
58
34
  }
59
35
  return imagePayload;
60
36
  };
@@ -1 +1 @@
1
- {"version":3,"names":["isImageType","exports","file","meta","_iterator","_createForOfIteratorHelper2","default","_step","s","n","done","metaItem","value","key","includes","err","e","f","fileToImagePayload","imagePayload","id","src","_iterator2","_step2","metaValue"],"sources":["files.ts"],"sourcesContent":["import { ImagePayload } from \"~/commands\";\n\nexport interface FileManagerFileItem {\n id: string;\n src: string;\n meta?: Array<FileManagerFileItemMetaItem>;\n}\n\nexport interface FileManagerFileItemMetaItem {\n key: string;\n value: any;\n}\n\nexport const isImageType = (file: FileManagerFileItem): boolean => {\n if (!file?.meta) {\n return false;\n }\n\n for (const metaItem of file.meta) {\n if (metaItem.key === \"type\") {\n return metaItem.value.includes(\"image/\");\n }\n }\n\n return false;\n};\n\nexport const fileToImagePayload = (file: FileManagerFileItem): ImagePayload | null => {\n if (!file?.meta) {\n return null;\n }\n\n if (!isImageType(file)) {\n return null;\n }\n\n const imagePayload = {} as ImagePayload;\n imagePayload[\"id\"] = file.id;\n imagePayload[\"src\"] = file.src;\n imagePayload[\"showCaption\"] = true;\n imagePayload[\"captionsEnabled\"] = true;\n\n for (const metaValue of file.meta) {\n if (metaValue.key === \"name\") {\n imagePayload[\"altText\"] = metaValue.value;\n } else if (metaValue.key === \"width\") {\n imagePayload[\"width\"] = metaValue.value;\n } else if (metaValue.key === \"height\") {\n imagePayload[\"height\"] = metaValue.value;\n }\n }\n return imagePayload;\n};\n"],"mappings":";;;;;;;;AAaO,IAAMA,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG,SAAdA,WAAWA,CAAIE,IAAyB,EAAc;EAC/D,IAAI,CAACA,IAAI,EAAEC,IAAI,EAAE;IACb,OAAO,KAAK;EAChB;EAAC,IAAAC,SAAA,OAAAC,2BAAA,CAAAC,OAAA,EAEsBJ,IAAI,CAACC,IAAI;IAAAI,KAAA;EAAA;IAAhC,KAAAH,SAAA,CAAAI,CAAA,MAAAD,KAAA,GAAAH,SAAA,CAAAK,CAAA,IAAAC,IAAA,GAAkC;MAAA,IAAvBC,QAAQ,GAAAJ,KAAA,CAAAK,KAAA;MACf,IAAID,QAAQ,CAACE,GAAG,KAAK,MAAM,EAAE;QACzB,OAAOF,QAAQ,CAACC,KAAK,CAACE,QAAQ,CAAC,QAAQ,CAAC;MAC5C;IACJ;EAAC,SAAAC,GAAA;IAAAX,SAAA,CAAAY,CAAA,CAAAD,GAAA;EAAA;IAAAX,SAAA,CAAAa,CAAA;EAAA;EAED,OAAO,KAAK;AAChB,CAAC;AAEM,IAAMC,kBAAkB,GAAAjB,OAAA,CAAAiB,kBAAA,GAAG,SAArBA,kBAAkBA,CAAIhB,IAAyB,EAA0B;EAClF,IAAI,CAACA,IAAI,EAAEC,IAAI,EAAE;IACb,OAAO,IAAI;EACf;EAEA,IAAI,CAACH,WAAW,CAACE,IAAI,CAAC,EAAE;IACpB,OAAO,IAAI;EACf;EAEA,IAAMiB,YAAY,GAAG,CAAC,CAAiB;EACvCA,YAAY,CAAC,IAAI,CAAC,GAAGjB,IAAI,CAACkB,EAAE;EAC5BD,YAAY,CAAC,KAAK,CAAC,GAAGjB,IAAI,CAACmB,GAAG;EAC9BF,YAAY,CAAC,aAAa,CAAC,GAAG,IAAI;EAClCA,YAAY,CAAC,iBAAiB,CAAC,GAAG,IAAI;EAAC,IAAAG,UAAA,OAAAjB,2BAAA,CAAAC,OAAA,EAEfJ,IAAI,CAACC,IAAI;IAAAoB,MAAA;EAAA;IAAjC,KAAAD,UAAA,CAAAd,CAAA,MAAAe,MAAA,GAAAD,UAAA,CAAAb,CAAA,IAAAC,IAAA,GAAmC;MAAA,IAAxBc,SAAS,GAAAD,MAAA,CAAAX,KAAA;MAChB,IAAIY,SAAS,CAACX,GAAG,KAAK,MAAM,EAAE;QAC1BM,YAAY,CAAC,SAAS,CAAC,GAAGK,SAAS,CAACZ,KAAK;MAC7C,CAAC,MAAM,IAAIY,SAAS,CAACX,GAAG,KAAK,OAAO,EAAE;QAClCM,YAAY,CAAC,OAAO,CAAC,GAAGK,SAAS,CAACZ,KAAK;MAC3C,CAAC,MAAM,IAAIY,SAAS,CAACX,GAAG,KAAK,QAAQ,EAAE;QACnCM,YAAY,CAAC,QAAQ,CAAC,GAAGK,SAAS,CAACZ,KAAK;MAC5C;IACJ;EAAC,SAAAG,GAAA;IAAAO,UAAA,CAAAN,CAAA,CAAAD,GAAA;EAAA;IAAAO,UAAA,CAAAL,CAAA;EAAA;EACD,OAAOE,YAAY;AACvB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["fileToImagePayload","exports","file","imagePayload","id","src","meta","_iterator","_createForOfIteratorHelper2","default","_step","s","n","done","metaValue","value","key","err","e","f"],"sources":["files.ts"],"sourcesContent":["import { ImagePayload } from \"~/commands\";\n\nexport interface FileManagerFileItem {\n id: string;\n src: string;\n meta?: Array<FileManagerFileItemMetaItem>;\n}\n\nexport interface FileManagerFileItemMetaItem {\n key: string;\n value: any;\n}\n\nexport const fileToImagePayload = (file: FileManagerFileItem): ImagePayload | null => {\n const imagePayload = {} as ImagePayload;\n imagePayload[\"id\"] = file.id;\n imagePayload[\"src\"] = file.src;\n imagePayload[\"showCaption\"] = true;\n imagePayload[\"captionsEnabled\"] = true;\n\n if (file?.meta) {\n for (const metaValue of file.meta) {\n if (metaValue.key === \"name\") {\n imagePayload[\"altText\"] = metaValue.value;\n } else if (metaValue.key === \"width\") {\n imagePayload[\"width\"] = metaValue.value;\n } else if (metaValue.key === \"height\") {\n imagePayload[\"height\"] = metaValue.value;\n }\n }\n }\n\n return imagePayload;\n};\n"],"mappings":";;;;;;;;AAaO,IAAMA,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG,SAArBA,kBAAkBA,CAAIE,IAAyB,EAA0B;EAClF,IAAMC,YAAY,GAAG,CAAC,CAAiB;EACvCA,YAAY,CAAC,IAAI,CAAC,GAAGD,IAAI,CAACE,EAAE;EAC5BD,YAAY,CAAC,KAAK,CAAC,GAAGD,IAAI,CAACG,GAAG;EAC9BF,YAAY,CAAC,aAAa,CAAC,GAAG,IAAI;EAClCA,YAAY,CAAC,iBAAiB,CAAC,GAAG,IAAI;EAEtC,IAAID,IAAI,EAAEI,IAAI,EAAE;IAAA,IAAAC,SAAA,OAAAC,2BAAA,CAAAC,OAAA,EACYP,IAAI,CAACI,IAAI;MAAAI,KAAA;IAAA;MAAjC,KAAAH,SAAA,CAAAI,CAAA,MAAAD,KAAA,GAAAH,SAAA,CAAAK,CAAA,IAAAC,IAAA,GAAmC;QAAA,IAAxBC,SAAS,GAAAJ,KAAA,CAAAK,KAAA;QAChB,IAAID,SAAS,CAACE,GAAG,KAAK,MAAM,EAAE;UAC1Bb,YAAY,CAAC,SAAS,CAAC,GAAGW,SAAS,CAACC,KAAK;QAC7C,CAAC,MAAM,IAAID,SAAS,CAACE,GAAG,KAAK,OAAO,EAAE;UAClCb,YAAY,CAAC,OAAO,CAAC,GAAGW,SAAS,CAACC,KAAK;QAC3C,CAAC,MAAM,IAAID,SAAS,CAACE,GAAG,KAAK,QAAQ,EAAE;UACnCb,YAAY,CAAC,QAAQ,CAAC,GAAGW,SAAS,CAACC,KAAK;QAC5C;MACJ;IAAC,SAAAE,GAAA;MAAAV,SAAA,CAAAW,CAAA,CAAAD,GAAA;IAAA;MAAAV,SAAA,CAAAY,CAAA;IAAA;EACL;EAEA,OAAOhB,YAAY;AACvB,CAAC","ignoreList":[]}