@webiny/lexical-editor 5.37.2-beta.1 → 5.37.2-beta.2
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
|
-
import {
|
|
2
|
+
import { CSSObject } from "@emotion/react";
|
|
3
3
|
import { Klass, LexicalNode } from "lexical";
|
|
4
|
+
import { LexicalValue, ThemeEmotionMap, ToolbarActionPlugin } from "../../types";
|
|
4
5
|
import { WebinyTheme } from "../../themes/webinyLexicalTheme";
|
|
5
|
-
import { CSSObject } from "@emotion/react";
|
|
6
6
|
export interface RichTextEditorProps {
|
|
7
7
|
toolbar?: React.ReactNode;
|
|
8
8
|
staticToolbar?: React.ReactNode;
|
|
@@ -10,8 +10,7 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
var
|
|
14
|
-
var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
|
|
13
|
+
var _react2 = require("@emotion/react");
|
|
15
14
|
var _LexicalComposer = require("@lexical/react/LexicalComposer");
|
|
16
15
|
var _LexicalOnChangePlugin = require("@lexical/react/LexicalOnChangePlugin");
|
|
17
16
|
var _LexicalAutoFocusPlugin = require("@lexical/react/LexicalAutoFocusPlugin");
|
|
@@ -19,17 +18,18 @@ var _LexicalClearEditorPlugin = require("@lexical/react/LexicalClearEditorPlugin
|
|
|
19
18
|
var _LexicalRichTextPlugin = require("@lexical/react/LexicalRichTextPlugin");
|
|
20
19
|
var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/LexicalErrorBoundary"));
|
|
21
20
|
var _reactComposition = require("@webiny/react-composition");
|
|
21
|
+
var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
|
|
22
22
|
var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
|
|
23
23
|
var _RichTextEditorContext = require("../../context/RichTextEditorContext");
|
|
24
24
|
var _isValidLexicalData = require("../../utils/isValidLexicalData");
|
|
25
25
|
var _LexicalUpdateStatePlugin = require("../../plugins/LexicalUpdateStatePlugin");
|
|
26
26
|
var _BlurEventPlugin = require("../../plugins/BlurEventPlugin/BlurEventPlugin");
|
|
27
|
+
var _Placeholder = require("../../ui/Placeholder");
|
|
28
|
+
var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
|
|
27
29
|
var _webinyLexicalTheme = require("../../themes/webinyLexicalTheme");
|
|
28
30
|
var _webinyNodes = require("../../nodes/webinyNodes");
|
|
29
|
-
var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
|
|
30
31
|
var _SharedHistoryContext = require("../../context/SharedHistoryContext");
|
|
31
32
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
32
|
-
var _react2 = require("@emotion/react");
|
|
33
33
|
var _toTypographyEmotionMap = require("../../utils/toTypographyEmotionMap");
|
|
34
34
|
var _LexicalEditorConfig = require("../LexicalEditorConfig/LexicalEditorConfig");
|
|
35
35
|
var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
@@ -113,10 +113,10 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
113
113
|
return /*#__PURE__*/_react.default.createElement(_LexicalComposer.LexicalComposer, {
|
|
114
114
|
initialConfig: initialConfig
|
|
115
115
|
}, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, staticToolbar && staticToolbar, /*#__PURE__*/_react.default.createElement("div", {
|
|
116
|
-
className: "editor-shell",
|
|
117
116
|
ref: scrollRef,
|
|
118
117
|
style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, styles), sizeStyle), {}, {
|
|
119
|
-
overflow: "auto"
|
|
118
|
+
overflow: "auto",
|
|
119
|
+
position: "relative"
|
|
120
120
|
})
|
|
121
121
|
}, /*#__PURE__*/_react.default.createElement(_LexicalOnChangePlugin.OnChangePlugin, {
|
|
122
122
|
onChange: handleOnChange
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_Placeholder","_generateInitialLexicalValue","_LexicalComposer","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_interopRequireDefault","_reactComposition","_LexicalContentEditable","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_webinyLexicalTheme","_webinyNodes","_LexicalHistoryPlugin","_SharedHistoryContext","_useRichTextEditor2","_react2","_toTypographyEmotionMap","_LexicalEditorConfig","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","theme","themeEmotionMap","toolbarActionPlugins","contentEditableStyles","placeholderStyles","config","useLexicalEditorConfig","_useSharedHistoryCont","useSharedHistoryContext","historyState","placeholderElem","default","createElement","Placeholder","scrollRef","useRef","_useState","useState","undefined","_useState2","_slicedToArray2","floatingAnchorElem","setFloatingAnchorElem","_useRichTextEditor","useRichTextEditor","setTheme","setThemeEmotionMap","setToolbarActionPlugins","useEffect","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","Fragment","key","name","element","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","concat","_toConsumableArray2","WebinyNodes","_objectSpread2","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","LexicalComposer","className","ref","style","overflow","OnChangePlugin","LexicalUpdateStatePlugin","ClearEditorPlugin","HistoryPlugin","externalHistoryState","BlurEventPlugin","AutoFocusPlugin","RichTextPlugin","contentEditable","ContentEditable","outline","ErrorBoundary","LexicalErrorBoundary","RichTextEditor","makeComposable","props","LexicalEditorWithConfig","RichTextEditorProvider","ClassNames","_ref2","_props$themeEmotionMa","css","toTypographyEmotionMap","themeStylesTransformer","SharedHistoryContext","Object","assign","exports"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useEffect, useRef, useState } from \"react\";\nimport { LexicalValue, ThemeEmotionMap, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { EditorState } from \"lexical/LexicalEditorState\";\nimport { Klass, LexicalEditor, LexicalNode } from \"lexical\";\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 { makeComposable } from \"@webiny/react-composition\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { ClassNames, CSSObject } from \"@emotion/react\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\n staticToolbar?: React.ReactNode;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n tag?: string;\n onChange?: (json: LexicalValue) => void;\n value: LexicalValue | null;\n focus?: boolean;\n placeholder?: string;\n nodes?: Klass<LexicalNode>[];\n /**\n * @description Lexical plugins\n */\n children?: React.ReactNode | React.ReactNode[];\n onBlur?: (editorState: LexicalValue) => void;\n height?: number | string;\n width?: number | string;\n /*\n * @description Theme to be injected into lexical editor\n */\n theme: WebinyTheme;\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n themeEmotionMap?: ThemeEmotionMap;\n\n placeholderStyles?: React.CSSProperties;\n /*\n * Set inline styles to lexical editor container\n * */\n styles?: React.CSSProperties;\n\n /*\n * Set inline styles to lexical editor editable content\n * */\n contentEditableStyles?: React.CSSProperties;\n\n /*\n * Set classes to lexical input container\n * */\n classes?: string;\n}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\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 theme,\n themeEmotionMap,\n toolbarActionPlugins,\n contentEditableStyles,\n placeholderStyles\n}: RichTextEditorProps) => {\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 { setTheme, setThemeEmotionMap, setToolbarActionPlugins } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap, theme]);\n\n useEffect(() => {\n if (toolbarActionPlugins) {\n setToolbarActionPlugins(toolbarActionPlugins || []);\n }\n }, [toolbarActionPlugins]);\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 initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...configNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, 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 <LexicalComposer initialConfig={initialConfig}>\n <>\n {staticToolbar && staticToolbar}\n <div\n className={\"editor-shell\"}\n ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\" }}\n >\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\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 </>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <LexicalEditorWithConfig>\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n </LexicalEditorWithConfig>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,4BAAA,GAAAF,OAAA;AAGA,IAAAG,gBAAA,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,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,iBAAA,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;AACA,IAAAgB,mBAAA,GAAAhB,OAAA;AACA,IAAAiB,YAAA,GAAAjB,OAAA;AACA,IAAAkB,qBAAA,GAAAlB,OAAA;AACA,IAAAmB,qBAAA,GAAAnB,OAAA;AACA,IAAAoB,mBAAA,GAAApB,OAAA;AACA,IAAAqB,OAAA,GAAArB,OAAA;AACA,IAAAsB,uBAAA,GAAAtB,OAAA;AACA,IAAAuB,oBAAA,GAAAvB,OAAA;AA8CA,IAAMwB,kBAAiD,GAAG,SAApDA,kBAAiDA,CAAAC,IAAA,EAkB5B;EAAA,IAjBvBC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CACvC,CAAC,EAED1D,kBAAkB,IAAIjC,OACtB,CACP,CACW,CAAC;AAE1B,CAAC;;AAED;AACA;AACA;AACO,IAAM4F,cAAc,GAAG,IAAAC,gCAAc,EAAsB,gBAAgB,EAAE,UAAAC,KAAK,EAAI;EACzF,oBACI1H,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC3B,oBAAA,CAAAkG,uBAAuB,qBACpB3H,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAACtC,sBAAA,CAAA8G,sBAAsB,qBACnB5H,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC7B,OAAA,CAAAsG,UAAU,QACN,UAAAC,KAAA,EAAa;IAAA,IAAAC,qBAAA;IAAA,IAAVC,GAAG,GAAAF,KAAA,CAAHE,GAAG;IACH,IAAMvF,eAAe,IAAAsF,qBAAA,GACjBL,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEjF,eAAe,cAAAsF,qBAAA,cAAAA,qBAAA,GACtB,IAAAE,8CAAsB,EAACD,GAAG,EAAEN,KAAK,CAAClF,KAAK,EAAEkF,KAAK,CAACQ,sBAAsB,CAAC;IAC1E,oBACIlI,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC/B,qBAAA,CAAA8G,oBAAoB,qBACjBnI,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC1B,kBAAkB,EAAA0G,MAAA,CAAAC,MAAA,KAAKX,KAAK;MAAEjF,eAAe,EAAEA;IAAgB,EAAE,CAChD,CAAC;EAE/B,CACQ,CACQ,CACH,CAAC;AAElC,CAAC,CAAC;AAAC6F,OAAA,CAAAd,cAAA,GAAAA,cAAA"}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_react2","_LexicalComposer","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_interopRequireDefault","_reactComposition","_LexicalHistoryPlugin","_LexicalContentEditable","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_Placeholder","_generateInitialLexicalValue","_webinyLexicalTheme","_webinyNodes","_SharedHistoryContext","_useRichTextEditor2","_toTypographyEmotionMap","_LexicalEditorConfig","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","theme","themeEmotionMap","toolbarActionPlugins","contentEditableStyles","placeholderStyles","config","useLexicalEditorConfig","_useSharedHistoryCont","useSharedHistoryContext","historyState","placeholderElem","default","createElement","Placeholder","scrollRef","useRef","_useState","useState","undefined","_useState2","_slicedToArray2","floatingAnchorElem","setFloatingAnchorElem","_useRichTextEditor","useRichTextEditor","setTheme","setThemeEmotionMap","setToolbarActionPlugins","useEffect","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","Fragment","key","name","element","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","concat","_toConsumableArray2","WebinyNodes","_objectSpread2","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","LexicalComposer","ref","style","overflow","position","OnChangePlugin","LexicalUpdateStatePlugin","ClearEditorPlugin","HistoryPlugin","externalHistoryState","BlurEventPlugin","AutoFocusPlugin","RichTextPlugin","contentEditable","className","ContentEditable","outline","ErrorBoundary","LexicalErrorBoundary","RichTextEditor","makeComposable","props","LexicalEditorWithConfig","RichTextEditorProvider","ClassNames","_ref2","_props$themeEmotionMa","css","toTypographyEmotionMap","themeStylesTransformer","SharedHistoryContext","Object","assign","exports"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useEffect, useRef, useState } from \"react\";\nimport { ClassNames, 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 { makeComposable } 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 { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { LexicalValue, ThemeEmotionMap, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\n staticToolbar?: React.ReactNode;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n tag?: string;\n onChange?: (json: LexicalValue) => void;\n value: LexicalValue | null;\n focus?: boolean;\n placeholder?: string;\n nodes?: Klass<LexicalNode>[];\n /**\n * @description Lexical plugins\n */\n children?: React.ReactNode | React.ReactNode[];\n onBlur?: (editorState: LexicalValue) => void;\n height?: number | string;\n width?: number | string;\n /*\n * @description Theme to be injected into lexical editor\n */\n theme: WebinyTheme;\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n themeEmotionMap?: ThemeEmotionMap;\n\n placeholderStyles?: React.CSSProperties;\n /*\n * Set inline styles to lexical editor container\n * */\n styles?: React.CSSProperties;\n\n /*\n * Set inline styles to lexical editor editable content\n * */\n contentEditableStyles?: React.CSSProperties;\n\n /*\n * Set classes to lexical input container\n * */\n classes?: string;\n}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\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 theme,\n themeEmotionMap,\n toolbarActionPlugins,\n contentEditableStyles,\n placeholderStyles\n}: RichTextEditorProps) => {\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 { setTheme, setThemeEmotionMap, setToolbarActionPlugins } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap, theme]);\n\n useEffect(() => {\n if (toolbarActionPlugins) {\n setToolbarActionPlugins(toolbarActionPlugins || []);\n }\n }, [toolbarActionPlugins]);\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 initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...configNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, 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 <LexicalComposer initialConfig={initialConfig}>\n <>\n {staticToolbar && staticToolbar}\n <div\n ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\", position: \"relative\" }}\n >\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\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 </>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <LexicalEditorWithConfig>\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n </LexicalEditorWithConfig>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,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,KAAA,EAAa;IAAA,IAAAC,qBAAA;IAAA,IAAVC,GAAG,GAAAF,KAAA,CAAHE,GAAG;IACH,IAAMxF,eAAe,IAAAuF,qBAAA,GACjBL,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAElF,eAAe,cAAAuF,qBAAA,cAAAA,qBAAA,GACtB,IAAAE,8CAAsB,EAACD,GAAG,EAAEN,KAAK,CAACnF,KAAK,EAAEmF,KAAK,CAACQ,sBAAsB,CAAC;IAC1E,oBACInI,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC9B,qBAAA,CAAA8G,oBAAoB,qBACjBpI,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC1B,kBAAkB,EAAA2G,MAAA,CAAAC,MAAA,KAAKX,KAAK;MAAElF,eAAe,EAAEA;IAAgB,EAAE,CAChD,CAAC;EAE/B,CACQ,CACQ,CACH,CAAC;AAElC,CAAC,CAAC;AAAC8F,OAAA,CAAAd,cAAA,GAAAA,cAAA"}
|
package/nodes/link-node.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare type SerializedLinkNode = Spread<{
|
|
|
9
9
|
export declare class LinkNode extends BaseLinkNode {
|
|
10
10
|
constructor(url: string, attributes?: LinkAttributes, key?: NodeKey);
|
|
11
11
|
static getType(): string;
|
|
12
|
+
static clone(node: LinkNode): LinkNode;
|
|
12
13
|
createDOM(config: EditorConfig): HTMLAnchorElement;
|
|
13
14
|
static importDOM(): DOMConversionMap | null;
|
|
14
15
|
static importJSON(serializedNode: BaseSerializedLinkNode | SerializedLinkNode | SerializedAutoLinkNode): LinkNode;
|
package/nodes/link-node.js
CHANGED
|
@@ -54,6 +54,15 @@ var LinkNode = /*#__PURE__*/function (_BaseLinkNode) {
|
|
|
54
54
|
value: function getType() {
|
|
55
55
|
return "link-node";
|
|
56
56
|
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "clone",
|
|
59
|
+
value: function clone(node) {
|
|
60
|
+
return new LinkNode(node.__url, {
|
|
61
|
+
rel: node.__rel,
|
|
62
|
+
target: node.__target,
|
|
63
|
+
title: node.__title
|
|
64
|
+
}, node.__key);
|
|
65
|
+
}
|
|
57
66
|
}, {
|
|
58
67
|
key: "importDOM",
|
|
59
68
|
value: function importDOM() {
|
package/nodes/link-node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_link","require","_utils","_sanitizeUrl","LinkNode","_BaseLinkNode","_inherits2","default","_super","_createSuper2","url","attributes","arguments","length","undefined","key","_classCallCheck2","call","_createClass2","value","createDOM","config","element","document","createElement","href","sanitizeUrl","__url","__target","target","__rel","rel","__title","title","addClassNamesToElement","theme","link","exportJSON","_objectSpread2","_get2","_getPrototypeOf2","prototype","type","version","getType","importDOM","a","conversion","convertAnchorElement","priority","importJSON","serializedNode","
|
|
1
|
+
{"version":3,"names":["_link","require","_utils","_sanitizeUrl","LinkNode","_BaseLinkNode","_inherits2","default","_super","_createSuper2","url","attributes","arguments","length","undefined","key","_classCallCheck2","call","_createClass2","value","createDOM","config","element","document","createElement","href","sanitizeUrl","__url","__target","target","__rel","rel","__title","title","addClassNamesToElement","theme","link","exportJSON","_objectSpread2","_get2","_getPrototypeOf2","prototype","type","version","getType","clone","node","__key","importDOM","a","conversion","convertAnchorElement","priority","importJSON","serializedNode","$createLinkNode","setFormat","format","setIndent","indent","setDirection","direction","BaseLinkNode","exports","domNode","isHTMLAnchorElement","content","textContent","getAttribute","$isLinkNode"],"sources":["link-node.ts"],"sourcesContent":["import {\n LinkAttributes,\n LinkNode as BaseLinkNode,\n SerializedAutoLinkNode,\n SerializedLinkNode as BaseSerializedLinkNode\n} from \"@lexical/link\";\nimport { DOMConversionMap, DOMConversionOutput, EditorConfig, NodeKey, Spread } from \"lexical\";\nimport { addClassNamesToElement, isHTMLAnchorElement } from \"@lexical/utils\";\nimport { sanitizeUrl } from \"~/utils/sanitizeUrl\";\n\nexport type SerializedLinkNode = Spread<\n {\n type: \"link-node\";\n version: 1;\n },\n Spread<LinkAttributes, BaseSerializedLinkNode>\n>;\n\nexport class LinkNode extends BaseLinkNode {\n constructor(url: string, attributes: LinkAttributes = {}, key?: NodeKey) {\n super(url, attributes, key);\n }\n\n static override getType(): string {\n return \"link-node\";\n }\n\n static override clone(node: LinkNode): LinkNode {\n return new LinkNode(\n node.__url,\n { rel: node.__rel, target: node.__target, title: node.__title },\n node.__key\n );\n }\n\n override createDOM(config: EditorConfig): HTMLAnchorElement {\n const element = document.createElement(\"a\");\n element.href = sanitizeUrl(this.__url);\n if (this.__target !== null) {\n element.target = this.__target;\n }\n if (this.__rel !== null) {\n element.rel = this.__rel;\n }\n if (this.__title !== null) {\n element.title = this.__title;\n }\n addClassNamesToElement(element, config.theme.link);\n return element;\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n a: () => ({\n conversion: convertAnchorElement,\n priority: 1\n })\n };\n }\n\n static override importJSON(\n serializedNode: BaseSerializedLinkNode | SerializedLinkNode | SerializedAutoLinkNode\n ): LinkNode {\n const node = $createLinkNode(serializedNode.url, {\n rel: serializedNode.rel,\n target: serializedNode.target,\n title: serializedNode.title\n });\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n return node;\n }\n\n override exportJSON(): BaseSerializedLinkNode | SerializedLinkNode | SerializedAutoLinkNode {\n return {\n ...super.exportJSON(),\n type: \"link-node\",\n version: 1\n };\n }\n}\n\nfunction convertAnchorElement(domNode: Node): DOMConversionOutput {\n let node = null;\n if (isHTMLAnchorElement(domNode)) {\n const content = domNode.textContent;\n if (content !== null && content !== \"\") {\n node = $createLinkNode(domNode.getAttribute(\"href\") || \"\", {\n rel: domNode.getAttribute(\"rel\"),\n target: domNode.getAttribute(\"target\"),\n title: domNode.getAttribute(\"title\")\n });\n }\n }\n return { node };\n}\n\nexport const $isLinkNode = (node: any): node is LinkNode => {\n return node instanceof LinkNode;\n};\n\nexport const $createLinkNode = (url: string, attributes: LinkAttributes = {}, key?: KeyType) => {\n return new LinkNode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AQ,CAACM,GAAG,EAAEC,UAAU,EAAEI,GAAG,CAAC;AAC7C,CAAC;AAACgD,OAAA,CAAAR,eAAA,GAAAA,eAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/lexical-editor",
|
|
3
|
-
"version": "5.37.2-beta.
|
|
3
|
+
"version": "5.37.2-beta.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"@lexical/rich-text": "0.11.3",
|
|
20
20
|
"@lexical/selection": "0.11.3",
|
|
21
21
|
"@lexical/utils": "0.11.3",
|
|
22
|
-
"@webiny/react-composition": "5.37.2-beta.
|
|
23
|
-
"@webiny/react-properties": "5.37.2-beta.
|
|
22
|
+
"@webiny/react-composition": "5.37.2-beta.2",
|
|
23
|
+
"@webiny/react-properties": "5.37.2-beta.2",
|
|
24
24
|
"lexical": "0.11.3",
|
|
25
25
|
"react": "17.0.2",
|
|
26
26
|
"react-dom": "17.0.2",
|
|
27
27
|
"react-style-object-to-css": "1.1.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@webiny/cli": "5.37.2-beta.
|
|
31
|
-
"@webiny/project-utils": "5.37.2-beta.
|
|
30
|
+
"@webiny/cli": "5.37.2-beta.2",
|
|
31
|
+
"@webiny/project-utils": "5.37.2-beta.2"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"build": "yarn webiny run build",
|
|
39
39
|
"watch": "yarn webiny run watch"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "35ac9634636144d945bede6aaafd99b3255a19f9"
|
|
42
42
|
}
|