@webiny/lexical-editor 5.35.2 → 5.36.0-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.
- package/components/Editor/HeadingEditor.js +1 -1
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.js +1 -1
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +0 -2
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +30 -3
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/hooks/useQuote.d.ts +2 -0
- package/hooks/{useWebinyQuote.js → useQuote.js} +2 -2
- package/hooks/useQuote.js.map +1 -0
- package/nodes/HeadingNode.d.ts +34 -0
- package/nodes/HeadingNode.js +192 -0
- package/nodes/HeadingNode.js.map +1 -0
- package/nodes/ParagraphNode.d.ts +32 -0
- package/nodes/ParagraphNode.js +218 -0
- package/nodes/ParagraphNode.js.map +1 -0
- package/nodes/QuoteNode.d.ts +34 -0
- package/nodes/QuoteNode.js +225 -0
- package/nodes/QuoteNode.js.map +1 -0
- package/nodes/TypographyElementNode.js +2 -1
- package/nodes/TypographyElementNode.js.map +1 -1
- package/nodes/list-node/WebinyListItemNode.js +2 -1
- package/nodes/list-node/WebinyListItemNode.js.map +1 -1
- package/nodes/list-node/formatList.js +3 -2
- package/nodes/list-node/formatList.js.map +1 -1
- package/nodes/types.d.ts +15 -0
- package/nodes/types.js +5 -0
- package/nodes/types.js.map +1 -0
- package/nodes/webinyNodes.js +29 -5
- package/nodes/webinyNodes.js.map +1 -1
- package/package.json +17 -17
- package/plugins/FontColorPlugin/FontColorPlugin.js +2 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +9 -5
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts +1 -1
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +7 -7
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -1
- package/themes/webinyLexicalTheme.css +18 -9
- package/types.d.ts +2 -3
- package/types.js.map +1 -1
- package/ui/DropDown.js +52 -19
- package/ui/DropDown.js.map +1 -1
- package/utils/findTypographyStyleByHtmlTag.d.ts +8 -0
- package/utils/findTypographyStyleByHtmlTag.js +16 -0
- package/utils/findTypographyStyleByHtmlTag.js.map +1 -0
- package/utils/generateInitialLexicalValue.js +2 -1
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getLexicalTextSelectionState.js +19 -3
- package/utils/getLexicalTextSelectionState.js.map +1 -1
- package/utils/nodes/formatToHeading.d.ts +3 -0
- package/utils/nodes/formatToHeading.js +25 -0
- package/utils/nodes/formatToHeading.js.map +1 -0
- package/utils/nodes/formatToParagraph.d.ts +1 -1
- package/utils/nodes/formatToParagraph.js +4 -3
- package/utils/nodes/formatToParagraph.js.map +1 -1
- package/utils/nodes/formatToQuote.js +8 -3
- package/utils/nodes/formatToQuote.js.map +1 -1
- package/hooks/useWebinyQuote.d.ts +0 -2
- package/hooks/useWebinyQuote.js.map +0 -1
- package/nodes/WebinyQuoteNode.d.ts +0 -29
- package/nodes/WebinyQuoteNode.js +0 -148
- package/nodes/WebinyQuoteNode.js.map +0 -1
|
@@ -22,7 +22,7 @@ var HeadingEditor = function HeadingEditor(_ref) {
|
|
|
22
22
|
toolbar: /*#__PURE__*/_react.default.createElement(_HeadingToolbar.HeadingToolbar, null),
|
|
23
23
|
tag: tag !== null && tag !== void 0 ? tag : "h1",
|
|
24
24
|
placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "Enter your heading text here..."
|
|
25
|
-
}, rest), /*#__PURE__*/_react.default.createElement(_LexicalLinkPlugin.LinkPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.
|
|
25
|
+
}, rest), /*#__PURE__*/_react.default.createElement(_LexicalLinkPlugin.LinkPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.QuotePlugin, null), /*#__PURE__*/_react.default.createElement(_ClickableLinkPlugin.ClickableLinkPlugin, null), /*#__PURE__*/_react.default.createElement(_FloatingLinkEditorPlugin.FloatingLinkEditorPlugin, {
|
|
26
26
|
anchorElem: document.body
|
|
27
27
|
}));
|
|
28
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HeadingEditor","tag","placeholder","rest","document","body"],"sources":["HeadingEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nimport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nimport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nimport { HeadingToolbar } from \"~/components/Toolbar/HeadingToolbar\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport {
|
|
1
|
+
{"version":3,"names":["HeadingEditor","tag","placeholder","rest","document","body"],"sources":["HeadingEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nimport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nimport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nimport { HeadingToolbar } from \"~/components/Toolbar/HeadingToolbar\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport { QuotePlugin } from \"~/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin\";\n\ninterface HeadingEditorProps extends RichTextEditorProps {\n tag?: \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n}\n\nexport const HeadingEditor: React.FC<HeadingEditorProps> = ({ tag, placeholder, ...rest }) => {\n return (\n <RichTextEditor\n toolbar={<HeadingToolbar />}\n tag={tag ?? \"h1\"}\n placeholder={placeholder ?? \"Enter your heading text here...\"}\n {...rest}\n >\n <LinkPlugin />\n <QuotePlugin />\n <ClickableLinkPlugin />\n <FloatingLinkEditorPlugin anchorElem={document.body} />\n </RichTextEditor>\n );\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAAoF;AAM7E,IAAMA,aAA2C,GAAG,SAA9CA,aAA2C,OAAsC;EAAA,IAAhCC,GAAG,QAAHA,GAAG;IAAEC,WAAW,QAAXA,WAAW;IAAKC,IAAI;EACnF,oBACI,6BAAC,8BAAc;IACX,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAC5B,GAAG,EAAEF,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,IAAK;IACjB,WAAW,EAAEC,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAI;EAAkC,GAC1DC,IAAI,gBAER,6BAAC,6BAAU,OAAG,eACd,6BAAC,kCAAW,OAAG,eACf,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,kDAAwB;IAAC,UAAU,EAAEC,QAAQ,CAACC;EAAK,EAAG,CAC1C;AAEzB,CAAC;AAAC"}
|
|
@@ -100,7 +100,7 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
100
100
|
onChange: handleOnChange
|
|
101
101
|
}), value && /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.LexicalUpdateStatePlugin, {
|
|
102
102
|
value: value
|
|
103
|
-
}), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_FontColorPlugin.FontColorPlugin, null), /*#__PURE__*/_react.default.createElement(_TypographyPlugin.TypographyPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.
|
|
103
|
+
}), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_FontColorPlugin.FontColorPlugin, null), /*#__PURE__*/_react.default.createElement(_TypographyPlugin.TypographyPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.QuotePlugin, null), /*#__PURE__*/_react.default.createElement(_LexicalHistoryPlugin.HistoryPlugin, {
|
|
104
104
|
externalHistoryState: historyState
|
|
105
105
|
}), onBlur && /*#__PURE__*/_react.default.createElement(_BlurEventPlugin.BlurEventPlugin, {
|
|
106
106
|
onBlur: onBlur
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BaseRichTextEditor","toolbar","onChange","value","nodes","placeholder","children","onBlur","focus","width","height","theme","themeEmotionMap","useSharedHistoryContext","historyState","placeholderElem","scrollRef","useRef","useState","undefined","floatingAnchorElem","setFloatingAnchorElem","useRichTextEditor","setTheme","setThemeEmotionMap","useEffect","onRef","_floatingAnchorElem","sizeStyle","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","WebinyNodes","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","outline","LexicalErrorBoundary","RichTextEditor","makeComposable","props","css","toTypographyEmotionMap"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { LexicalValue, ThemeEmotionMap } 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 { FontColorPlugin } from \"~/plugins/FontColorPlugin/FontColorPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { TypographyPlugin } from \"~/plugins/TypographyPlugin/TypographyPlugin\";\nimport { WebinyQuotePlugin } from \"~/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { ClassNames } from \"@emotion/react\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\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 themeEmotionMap?: ThemeEmotionMap;\n}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\n toolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n width,\n height,\n theme,\n themeEmotionMap\n}: RichTextEditorProps) => {\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = <Placeholder>{placeholder || \"Enter text...\"}</Placeholder>;\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const { setTheme, setThemeEmotionMap } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap]);\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 initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...(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 //TODO: send plain JSON object\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\n }\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <div ref={scrollRef} style={{ ...sizeStyle }}>\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <FontColorPlugin />\n <TypographyPlugin />\n <WebinyQuotePlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components */}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef} style={{ ...sizeStyle }}>\n <ContentEditable style={{ outline: 0, ...sizeStyle }} />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar */}\n {floatingAnchorElem && toolbar}\n </div>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwBA,IAAMA,kBAAiD,GAAG,SAApDA,kBAAiD,OAa5B;EAAA,IAZvBC,OAAO,QAAPA,OAAO;IACPC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;IACXC,QAAQ,QAARA,QAAQ;IACRC,MAAM,QAANA,MAAM;IACNC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,MAAM,QAANA,MAAM;IACNC,KAAK,QAALA,KAAK;IACLC,eAAe,QAAfA,eAAe;EAEf,4BAAyB,IAAAC,6CAAuB,GAAE;IAA1CC,YAAY,yBAAZA,YAAY;EACpB,IAAMC,eAAe,gBAAG,6BAAC,wBAAW,QAAEV,WAAW,IAAI,eAAe,CAAe;EACnF,IAAMW,SAAS,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAC9B,gBAAoD,IAAAC,eAAQ,EACxDC,SAAS,CACZ;IAAA;IAFMC,kBAAkB;IAAEC,qBAAqB;EAGhD,yBAAyC,IAAAC,qCAAiB,GAAE;IAApDC,QAAQ,sBA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C;IAAgB,GAAG,CAChD;EAE/B,CAAC,CACQ,CACQ;AAEjC,CAAC,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["BaseRichTextEditor","toolbar","onChange","value","nodes","placeholder","children","onBlur","focus","width","height","theme","themeEmotionMap","useSharedHistoryContext","historyState","placeholderElem","scrollRef","useRef","useState","undefined","floatingAnchorElem","setFloatingAnchorElem","useRichTextEditor","setTheme","setThemeEmotionMap","useEffect","onRef","_floatingAnchorElem","sizeStyle","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","WebinyNodes","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","outline","LexicalErrorBoundary","RichTextEditor","makeComposable","props","css","toTypographyEmotionMap"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { LexicalValue, ThemeEmotionMap } 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 { FontColorPlugin } from \"~/plugins/FontColorPlugin/FontColorPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { TypographyPlugin } from \"~/plugins/TypographyPlugin/TypographyPlugin\";\nimport { QuotePlugin } from \"~/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { ClassNames } from \"@emotion/react\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\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 themeEmotionMap?: ThemeEmotionMap;\n}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\n toolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n width,\n height,\n theme,\n themeEmotionMap\n}: RichTextEditorProps) => {\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = <Placeholder>{placeholder || \"Enter text...\"}</Placeholder>;\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const { setTheme, setThemeEmotionMap } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap]);\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 initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...(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 //TODO: send plain JSON object\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\n }\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <div ref={scrollRef} style={{ ...sizeStyle }}>\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <FontColorPlugin />\n <TypographyPlugin />\n <QuotePlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components */}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef} style={{ ...sizeStyle }}>\n <ContentEditable style={{ outline: 0, ...sizeStyle }} />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar */}\n {floatingAnchorElem && toolbar}\n </div>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwBA,IAAMA,kBAAiD,GAAG,SAApDA,kBAAiD,OAa5B;EAAA,IAZvBC,OAAO,QAAPA,OAAO;IACPC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;IACXC,QAAQ,QAARA,QAAQ;IACRC,MAAM,QAANA,MAAM;IACNC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,MAAM,QAANA,MAAM;IACNC,KAAK,QAALA,KAAK;IACLC,eAAe,QAAfA,eAAe;EAEf,4BAAyB,IAAAC,6CAAuB,GAAE;IAA1CC,YAAY,yBAAZA,YAAY;EACpB,IAAMC,eAAe,gBAAG,6BAAC,wBAAW,QAAEV,WAAW,IAAI,eAAe,CAAe;EACnF,IAAMW,SAAS,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAC9B,gBAAoD,IAAAC,eAAQ,EACxDC,SAAS,CACZ;IAAA;IAFMC,kBAAkB;IAAEC,qBAAqB;EAGhD,yBAAyC,IAAAC,qCAAiB,GAAE;IAApDC,QAAQ,sBAARA,QAAQ;IAAEC,kBAAkB,sBAAlBA,kBAAkB;EAEpC,IAAAC,gBAAS,EAAC,YAAM;IACZF,QAAQ,CAACZ,KAAK,CAAC;IACfa,kBAAkB,CAACZ,eAAe,CAAC;EACvC,CAAC,EAAE,CAACA,eAAe,CAAC,CAAC;EAErB,IAAMc,KAAK,GAAG,SAARA,KAAK,CAAIC,mBAAmC,EAAK;IACnD,IAAIA,mBAAmB,KAAK,IAAI,EAAE;MAC9BN,qBAAqB,CAACM,mBAAm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AAe;IAAC,MAAM,EAAEA;EAAO,EAAG,EAC7CC,KAAK,iBAAI,6BAAC,uCAAe,OAAG,EAE5BF,QAAQ,eACT,6BAAC,qCAAc;IACX,eAAe,eACX;MAAK,SAAS,EAAC,iBAAiB;MAAC,KAAK,kCAAOsB,SAAS;IAAG,gBACrD;MAAK,SAAS,EAAC,QAAQ;MAAC,GAAG,EAAEF,KAAM;MAAC,KAAK,kCAAOE,SAAS;IAAG,gBACxD,6BAAC,uCAAe;MAAC,KAAK;QAAIkB,OAAO,EAAE;MAAC,GAAKlB,SAAS;IAAG,EAAG,CACtD,CAEb;IACD,WAAW,EAAEb,eAAgB;IAC7B,aAAa,EAAEgC;EAAqB,EACtC,EAED3B,kBAAkB,IAAInB,OAAO,CAC5B,CACQ;AAE1B,CAAC;;AAED;AACA;AACA;AACO,IAAM+C,cAAc,GAAG,IAAAC,gCAAc,EAAsB,gBAAgB,EAAE,UAAAC,KAAK,EAAI;EACzF,oBACI,6BAAC,6CAAsB,qBACnB,6BAAC,kBAAU,QACN,iBAAa;IAAA;IAAA,IAAVC,GAAG,SAAHA,GAAG;IACH,IAAMvC,eAAe,4BACjBsC,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEtC,eAAe,yEAAI,IAAAwC,8CAAsB,EAACD,GAAG,EAAED,KAAK,CAACvC,KAAK,CAAC;IACtE,oBACI,6BAAC,0CAAoB,qBACjB,6BAAC,kBAAkB,oBAAKuC,KAAK;MAAE,eAAe,EAAEtC;IAAgB,GAAG,CAChD;EAE/B,CAAC,CACQ,CACQ;AAEjC,CAAC,CAAC;AAAC"}
|
|
@@ -31,11 +31,9 @@ var QuoteAction = function QuoteAction() {
|
|
|
31
31
|
var DEFAULT_QUOTE_ID = "quote";
|
|
32
32
|
var hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];
|
|
33
33
|
(0, _formatToQuote.formatToQuote)(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);
|
|
34
|
-
setIsActive(true);
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
(0, _formatToParagraph.formatToParagraph)(editor);
|
|
38
|
-
setIsActive(false);
|
|
39
37
|
};
|
|
40
38
|
(0, _react.useEffect)(function () {
|
|
41
39
|
setIsActive(isQuoteSelected);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["QuoteAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","themeEmotionMap","isQuoteSelected","state","quote","isSelected","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","formatToQuote","undefined","formatToParagraph","useEffect"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { formatToQuote } from \"~/utils/nodes/formatToQuote\";\nimport { formatToParagraph } from \"~/utils/nodes/formatToParagraph\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nexport const QuoteAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isActive, setIsActive] = useState<boolean>(false);\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isQuoteSelected = !!textBlockSelection?.state?.quote.isSelected;\n\n const formatText = () => {\n if (!isActive) {\n // Try to set default quote style, when the action button is clicked for first time\n const DEFAULT_QUOTE_ID = \"quote\";\n const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];\n
|
|
1
|
+
{"version":3,"names":["QuoteAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","themeEmotionMap","isQuoteSelected","state","quote","isSelected","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","formatToQuote","undefined","formatToParagraph","useEffect"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { formatToQuote } from \"~/utils/nodes/formatToQuote\";\nimport { formatToParagraph } from \"~/utils/nodes/formatToParagraph\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nexport const QuoteAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isActive, setIsActive] = useState<boolean>(false);\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isQuoteSelected = !!textBlockSelection?.state?.quote.isSelected;\n\n const formatText = () => {\n if (!isActive) {\n // Try to set default quote style, when the action button is clicked for first time\n const DEFAULT_QUOTE_ID = \"quote\";\n const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];\n formatToQuote(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);\n return;\n }\n formatToParagraph(editor);\n };\n\n useEffect(() => {\n setIsActive(isQuoteSelected);\n }, [isQuoteSelected]);\n\n return (\n <button\n onClick={() => formatText()}\n className={\"popup-item \" + (isActive ? \"active\" : \"\")}\n aria-label=\"Format text as quote\"\n >\n <i className=\"icon quote\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,IAAMA,WAAW,GAAG,SAAdA,WAAW,GAAS;EAAA;EAC7B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAgC,IAAAC,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAjDC,QAAQ;IAAEC,WAAW;EAC5B,yBAAgD,IAAAC,qCAAiB,GAAE;IAA3DC,kBAAkB,sBAAlBA,kBAAkB;IAAEC,eAAe,sBAAfA,eAAe;EAC3C,IAAMC,eAAe,GAAG,CAAC,EAACF,kBAAkB,aAAlBA,kBAAkB,wCAAlBA,kBAAkB,CAAEG,KAAK,kDAAzB,sBAA2BC,KAAK,CAACC,UAAU;EAErE,IAAMC,UAAU,GAAG,SAAbA,UAAU,GAAS;IACrB,IAAI,CAACT,QAAQ,EAAE;MACX;MACA,IAAMU,gBAAgB,GAAG,OAAO;MAChC,IAAMC,cAAc,GAAGP,eAAe,IAAIA,eAAe,CAACM,gBAAgB,CAAC;MAC3E,IAAAE,4BAAa,EAACd,MAAM,EAAEa,cAAc,GAAGD,gBAAgB,GAAGG,SAAS,CAAC;MACpE;IACJ;IACA,IAAAC,oCAAiB,EAAChB,MAAM,CAAC;EAC7B,CAAC;EAED,IAAAiB,gBAAS,EAAC,YAAM;IACZd,WAAW,CAACI,eAAe,CAAC;EAChC,CAAC,EAAE,CAACA,eAAe,CAAC,CAAC;EAErB,oBACI;IACI,OAAO,EAAE;MAAA,OAAMI,UAAU,EAAE;IAAA,CAAC;IAC5B,SAAS,EAAE,aAAa,IAAIT,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAE;IACtD,cAAW;EAAsB,gBAEjC;IAAG,SAAS,EAAC;EAAY,EAAG,CACvB;AAEjB,CAAC;AAAC"}
|
|
@@ -15,6 +15,9 @@ var _TypographyElementNode = require("../../nodes/TypographyElementNode");
|
|
|
15
15
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
16
16
|
var _webinyList = require("../../commands/webiny-list");
|
|
17
17
|
var _webinyQuote = require("../../commands/webiny-quote");
|
|
18
|
+
var _ParagraphNode = require("../../nodes/ParagraphNode");
|
|
19
|
+
var _HeadingNode = require("../../nodes/HeadingNode");
|
|
20
|
+
var _QuoteNode = require("../../nodes/QuoteNode");
|
|
18
21
|
/*
|
|
19
22
|
* Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.
|
|
20
23
|
* Note: Toa add custom component access trough @see LexicalEditorConfig API
|
|
@@ -38,7 +41,7 @@ var TypographyActionDropDown = function TypographyActionDropDown(_ref) {
|
|
|
38
41
|
});
|
|
39
42
|
};
|
|
40
43
|
var TypographyAction = function TypographyAction() {
|
|
41
|
-
var _textBlockSelection$s, _textBlockSelection$s2;
|
|
44
|
+
var _textBlockSelection$s, _textBlockSelection$s2, _textBlockSelection$s3, _textBlockSelection$s4, _textBlockSelection$s5;
|
|
42
45
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
43
46
|
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
44
47
|
editor = _useLexicalComposerCo2[0];
|
|
@@ -50,7 +53,10 @@ var TypographyAction = function TypographyAction() {
|
|
|
50
53
|
textBlockSelection = _useRichTextEditor.textBlockSelection,
|
|
51
54
|
themeEmotionMap = _useRichTextEditor.themeEmotionMap;
|
|
52
55
|
var isTypographySelected = (textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s = textBlockSelection.state) === null || _textBlockSelection$s === void 0 ? void 0 : _textBlockSelection$s.typography.isSelected) || false;
|
|
53
|
-
var
|
|
56
|
+
var isParagraphSelected = (textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s2 = textBlockSelection.state) === null || _textBlockSelection$s2 === void 0 ? void 0 : _textBlockSelection$s2.paragraph.isSelected) || false;
|
|
57
|
+
var isHeadingSelected = (textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s3 = textBlockSelection.state) === null || _textBlockSelection$s3 === void 0 ? void 0 : _textBlockSelection$s3.heading.isSelected) || false;
|
|
58
|
+
var textType = textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s4 = textBlockSelection.state) === null || _textBlockSelection$s4 === void 0 ? void 0 : _textBlockSelection$s4.textType;
|
|
59
|
+
var isQuoteSelected = (textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s5 = textBlockSelection.state) === null || _textBlockSelection$s5 === void 0 ? void 0 : _textBlockSelection$s5.quote.isSelected) || false;
|
|
54
60
|
var setTypographySelect = (0, _react.useCallback)(function (value) {
|
|
55
61
|
setTypography(value);
|
|
56
62
|
}, [typography]);
|
|
@@ -86,6 +92,27 @@ var TypographyAction = function TypographyAction() {
|
|
|
86
92
|
setTypography(el.getTypographyValue());
|
|
87
93
|
return;
|
|
88
94
|
}
|
|
95
|
+
if ((0, _ParagraphNode.$isParagraphNode)(textBlockSelection === null || textBlockSelection === void 0 ? void 0 : textBlockSelection.element) || (0, _HeadingNode.$isHeadingNode)(textBlockSelection === null || textBlockSelection === void 0 ? void 0 : textBlockSelection.element) || (0, _QuoteNode.$isQuoteNode)(textBlockSelection === null || textBlockSelection === void 0 ? void 0 : textBlockSelection.element)) {
|
|
96
|
+
var elementWithThemeStyle = textBlockSelection === null || textBlockSelection === void 0 ? void 0 : textBlockSelection.element;
|
|
97
|
+
var styleId = elementWithThemeStyle.getTypographyStyleId();
|
|
98
|
+
if (!styleId) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!themeEmotionMap) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
var style = themeEmotionMap[styleId];
|
|
105
|
+
if (style) {
|
|
106
|
+
setTypography({
|
|
107
|
+
name: style === null || style === void 0 ? void 0 : style.name,
|
|
108
|
+
id: style.id,
|
|
109
|
+
css: style.styles,
|
|
110
|
+
tag: style.tag
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
89
116
|
// list and quote element
|
|
90
117
|
if (themeEmotionMap && textBlockSelection !== null && textBlockSelection !== void 0 && (_textBlockSelection$e = textBlockSelection.element) !== null && _textBlockSelection$e !== void 0 && _textBlockSelection$e.getStyleId) {
|
|
91
118
|
var _textBlockSelection$e2;
|
|
@@ -103,7 +130,7 @@ var TypographyAction = function TypographyAction() {
|
|
|
103
130
|
}
|
|
104
131
|
}
|
|
105
132
|
}
|
|
106
|
-
}, [isTypographySelected, textType]);
|
|
133
|
+
}, [isTypographySelected, textType, isQuoteSelected, isParagraphSelected, isHeadingSelected]);
|
|
107
134
|
return /*#__PURE__*/_react.default.createElement(_TypographyActionContext.TypographyActionContext.Provider, {
|
|
108
135
|
value: {
|
|
109
136
|
value: typography,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BaseTypographyActionDropDown","makeComposable","useEffect","console","log","TypographyActionDropDown","element","TypographyAction","useLexicalComposerContext","editor","useState","typography","setTypography","useRichTextEditor","textBlockSelection","themeEmotionMap","isTypographySelected","state","isSelected","textType","setTypographySelect","useCallback","value","onTypographySelect","tag","includes","dispatchCommand","ADD_TYPOGRAPHY_ELEMENT_COMMAND","INSERT_ORDERED_WEBINY_LIST_COMMAND","themeStyleId","id","INSERT_UNORDERED_WEBINY_LIST_COMMAND","INSERT_WEBINY_QUOTE_COMMAND","$isTypographyElementNode","el","getTypographyValue","getStyleId","undefined","elementStyle","css","styles","name","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\n\nimport { TypographyValue } from \"~/types\";\nimport {\n $isTypographyElementNode,\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n TypographyElementNode,\n TypographyPayload\n} from \"~/nodes/TypographyElementNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n WebinyListCommandPayload\n} from \"~/commands/webiny-list\";\nimport { INSERT_WEBINY_QUOTE_COMMAND, WebinyQuoteCommandPayload } from \"~/commands/webiny-quote\";\n\n/*\n * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const BaseTypographyActionDropDown = makeComposable(\n \"BaseTypographyActionDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTypographyActionDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TypographyActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TypographyActionDropDown: React.FC<TypographyActionDropdownProps> = ({\n element\n}): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport interface TypographyAction extends React.FC<unknown> {\n TypographyDropDown: typeof TypographyActionDropDown;\n}\n\nexport const TypographyAction: TypographyAction = () => {\n const [editor] = useLexicalComposerContext();\n const [typography, setTypography] = useState<TypographyValue>();\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isTypographySelected = textBlockSelection?.state?.typography.isSelected || false;\n const textType = textBlockSelection?.state?.textType;\n const setTypographySelect = useCallback(\n (value: TypographyValue) => {\n setTypography(value);\n },\n [typography]\n );\n\n const onTypographySelect = useCallback((value: TypographyValue) => {\n setTypographySelect(value);\n\n if (value.tag.includes(\"h\") || value.tag.includes(\"p\")) {\n editor.dispatchCommand<LexicalCommand<TypographyPayload>>(\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n {\n value\n }\n );\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<WebinyListCommandPayload>>(\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<WebinyListCommandPayload>>(\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<WebinyQuoteCommandPayload>>(\n INSERT_WEBINY_QUOTE_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n }, []);\n\n useEffect(() => {\n if (textBlockSelection) {\n // header and paragraph elements inserted with typography node\n if ($isTypographyElementNode(textBlockSelection?.element)) {\n const el = textBlockSelection.element as TypographyElementNode;\n setTypography(el.getTypographyValue());\n return;\n }\n // list and quote element\n if (themeEmotionMap && textBlockSelection?.element?.getStyleId) {\n const themeStyleId = textBlockSelection?.element?.getStyleId() || undefined;\n if (themeStyleId) {\n const elementStyle = themeEmotionMap[themeStyleId];\n if (elementStyle) {\n setTypography({\n id: elementStyle.id,\n css: elementStyle.styles,\n name: elementStyle.name,\n tag: elementStyle.tag\n });\n }\n }\n }\n }\n }, [isTypographySelected, textType]);\n\n return (\n <TypographyActionContext.Provider\n value={{\n value: typography,\n applyTypography: onTypographySelect\n }}\n >\n <BaseTypographyActionDropDown />\n </TypographyActionContext.Provider>\n );\n};\n\n{\n /* Color action settings */\n}\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA;AACA;AAGA;AAMA;AACA;AAKA;AAEA;AACA;AACA;AACA;AACO,IAAMA,4BAA4B,GAAG,IAAAC,gCAAc,EACtD,8BAA8B,EAC9B,YAA0B;EACtB,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,qEAAqE,CAAC;EACtF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CAAC,CACJ;AAAC;AAMF,IAAMC,wBAAiE,GAAG,SAApEA,wBAAiE,OAEpD;EAAA,IADfC,OAAO,QAAPA,OAAO;EAEP,oBAAO,6BAAC,yBAAO;IAAC,SAAS,EAAEN,4BAA6B;IAAC,IAAI,EAAE;MAAA,OAAM;QAAA,OAAMM,OAAO;MAAA;IAAA;EAAC,EAAG;AAC1F,CAAC;AAMM,IAAMC,gBAAkC,GAAG,SAArCA,gBAAkC,GAAS;EAAA;EACpD,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAoC,IAAAC,eAAQ,GAAmB;IAAA;IAAxDC,UAAU;IAAEC,aAAa;EAChC,yBAAgD,IAAAC,qCAAiB,GAAE;IAA3DC,kBAAkB,sBAAlBA,kBAAkB;IAAEC,eAAe,sBAAfA,eAAe;EAC3C,IAAMC,oBAAoB,GAAG,CAAAF,kBAAkB,aAAlBA,kBAAkB,gDAAlBA,kBAAkB,CAAEG,KAAK,0DAAzB,sBAA2BN,UAAU,CAACO,UAAU,KAAI,KAAK;EACt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ACvD,IAAM4B,EAAE,GAAGpB,kBAAkB,CAACR,OAAgC;QAC9DM,aAAa,CAACsB,EAAE,CAACC,kBAAkB,EAAE,CAAC;QACtC;MACJ;MACA;MACA,IAAIpB,eAAe,IAAID,kBAAkB,aAAlBA,kBAAkB,wCAAlBA,kBAAkB,CAAER,OAAO,kDAA3B,sBAA6B8B,UAAU,EAAE;QAAA;QAC5D,IAAMP,YAAY,GAAG,CAAAf,kBAAkB,aAAlBA,kBAAkB,iDAAlBA,kBAAkB,CAAER,OAAO,2DAA3B,uBAA6B8B,UAAU,EAAE,KAAIC,SAAS;QAC3E,IAAIR,YAAY,EAAE;UACd,IAAMS,YAAY,GAAGvB,eAAe,CAACc,YAAY,CAAC;UAClD,IAAIS,YAAY,EAAE;YACd1B,aAAa,CAAC;cACVkB,EAAE,EAAEQ,YAAY,CAACR,EAAE;cACnBS,GAAG,EAAED,YAAY,CAACE,MAAM;cACxBC,IAAI,EAAEH,YAAY,CAACG,IAAI;cACvBjB,GAAG,EAAEc,YAAY,CAACd;YACtB,CAAC,CAAC;UACN;QACJ;MACJ;IACJ;EACJ,CAAC,EAAE,CAACR,oBAAoB,EAAEG,QAAQ,CAAC,CAAC;EAEpC,oBACI,6BAAC,gDAAuB,CAAC,QAAQ;IAC7B,KAAK,EAAE;MACHG,KAAK,EAAEX,UAAU;MACjB+B,eAAe,EAAEnB;IACrB;EAAE,gBAEF,6BAAC,4BAA4B,OAAG,CACD;AAE3C,CAAC;AAAC;AAEF;EACI;AAAA;AAEJhB,gBAAgB,CAACoC,kBAAkB,GAAGtC,wBAAwB"}
|
|
1
|
+
{"version":3,"names":["BaseTypographyActionDropDown","makeComposable","useEffect","console","log","TypographyActionDropDown","element","TypographyAction","useLexicalComposerContext","editor","useState","typography","setTypography","useRichTextEditor","textBlockSelection","themeEmotionMap","isTypographySelected","state","isSelected","isParagraphSelected","paragraph","isHeadingSelected","heading","textType","isQuoteSelected","quote","setTypographySelect","useCallback","value","onTypographySelect","tag","includes","dispatchCommand","ADD_TYPOGRAPHY_ELEMENT_COMMAND","INSERT_ORDERED_WEBINY_LIST_COMMAND","themeStyleId","id","INSERT_UNORDERED_WEBINY_LIST_COMMAND","INSERT_WEBINY_QUOTE_COMMAND","$isTypographyElementNode","el","getTypographyValue","$isParagraphNode","$isHeadingNode","$isQuoteNode","elementWithThemeStyle","styleId","getTypographyStyleId","style","name","css","styles","getStyleId","undefined","elementStyle","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\n\nimport { TypographyValue } from \"~/types\";\nimport {\n $isTypographyElementNode,\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n TypographyElementNode,\n TypographyPayload\n} from \"~/nodes/TypographyElementNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n WebinyListCommandPayload\n} from \"~/commands/webiny-list\";\nimport { INSERT_WEBINY_QUOTE_COMMAND, WebinyQuoteCommandPayload } from \"~/commands/webiny-quote\";\nimport { $isParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $isHeadingNode } from \"~/nodes/HeadingNode\";\nimport { $isQuoteNode } from \"~/nodes/QuoteNode\";\n\n/*\n * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const BaseTypographyActionDropDown = makeComposable(\n \"BaseTypographyActionDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTypographyActionDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TypographyActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TypographyActionDropDown: React.FC<TypographyActionDropdownProps> = ({\n element\n}): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport interface TypographyAction extends React.FC<unknown> {\n TypographyDropDown: typeof TypographyActionDropDown;\n}\n\nexport const TypographyAction: TypographyAction = () => {\n const [editor] = useLexicalComposerContext();\n const [typography, setTypography] = useState<TypographyValue>();\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isTypographySelected = textBlockSelection?.state?.typography.isSelected || false;\n const isParagraphSelected = textBlockSelection?.state?.paragraph.isSelected || false;\n const isHeadingSelected = textBlockSelection?.state?.heading.isSelected || false;\n const textType = textBlockSelection?.state?.textType;\n const isQuoteSelected = textBlockSelection?.state?.quote.isSelected || false;\n const setTypographySelect = useCallback(\n (value: TypographyValue) => {\n setTypography(value);\n },\n [typography]\n );\n\n const onTypographySelect = useCallback((value: TypographyValue) => {\n setTypographySelect(value);\n if (value.tag.includes(\"h\") || value.tag.includes(\"p\")) {\n editor.dispatchCommand<LexicalCommand<TypographyPayload>>(\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n {\n value\n }\n );\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<WebinyListCommandPayload>>(\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<WebinyListCommandPayload>>(\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<WebinyQuoteCommandPayload>>(\n INSERT_WEBINY_QUOTE_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n }, []);\n\n useEffect(() => {\n if (textBlockSelection) {\n // header and paragraph elements inserted with typography node\n if ($isTypographyElementNode(textBlockSelection?.element)) {\n const el = textBlockSelection.element as TypographyElementNode;\n setTypography(el.getTypographyValue());\n return;\n }\n\n if (\n $isParagraphNode(textBlockSelection?.element) ||\n $isHeadingNode(textBlockSelection?.element) ||\n $isQuoteNode(textBlockSelection?.element)\n ) {\n const elementWithThemeStyle = textBlockSelection?.element;\n const styleId = elementWithThemeStyle.getTypographyStyleId();\n if (!styleId) {\n return;\n }\n\n if (!themeEmotionMap) {\n return;\n }\n\n const style = themeEmotionMap[styleId];\n if (style) {\n setTypography({\n name: style?.name,\n id: style.id,\n css: style.styles,\n tag: style.tag\n });\n }\n return;\n }\n\n // list and quote element\n if (themeEmotionMap && textBlockSelection?.element?.getStyleId) {\n const themeStyleId = textBlockSelection?.element?.getStyleId() || undefined;\n if (themeStyleId) {\n const elementStyle = themeEmotionMap[themeStyleId];\n if (elementStyle) {\n setTypography({\n id: elementStyle.id,\n css: elementStyle.styles,\n name: elementStyle.name,\n tag: elementStyle.tag\n });\n }\n }\n }\n }\n }, [isTypographySelected, textType, isQuoteSelected, isParagraphSelected, isHeadingSelected]);\n\n return (\n <TypographyActionContext.Provider\n value={{\n value: typography,\n applyTypography: onTypographySelect\n }}\n >\n <BaseTypographyActionDropDown />\n </TypographyActionContext.Provider>\n );\n};\n\n{\n /* Color action settings */\n}\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA;AACA;AAGA;AAMA;AACA;AAKA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACO,IAAMA,4BAA4B,GAAG,IAAAC,gCAAc,EACtD,8BAA8B,EAC9B,YAA0B;EACtB,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,qEAAqE,CAAC;EACtF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CAAC,CACJ;AAAC;AAMF,IAAMC,wBAAiE,GAAG,SAApEA,wBAAiE,OAEpD;EAAA,IADfC,OAAO,QAAPA,OAAO;EAEP,oBAAO,6BAAC,yBAAO;IAAC,SAAS,EA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;IACJ;EACJ,CAAC,EAAE,CAACd,oBAAoB,EAAEO,QAAQ,EAAEC,eAAe,EAAEL,mBAAmB,EAAEE,iBAAiB,CAAC,CAAC;EAE7F,oBACI,6BAAC,gDAAuB,CAAC,QAAQ;IAC7B,KAAK,EAAE;MACHO,KAAK,EAAEjB,UAAU;MACjB4C,eAAe,EAAE1B;IACrB;EAAE,gBAEF,6BAAC,4BAA4B,OAAG,CACD;AAE3C,CAAC;AAAC;AAEF;EACI;AAAA;AAEJtB,gBAAgB,CAACiD,kBAAkB,GAAGnD,wBAAwB"}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.useQuote = useQuote;
|
|
7
7
|
var _utils = require("@lexical/utils");
|
|
8
8
|
var _lexical = require("lexical");
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _webinyQuote = require("../commands/webiny-quote");
|
|
11
11
|
var _formatToQuote = require("../utils/nodes/formatToQuote");
|
|
12
|
-
function
|
|
12
|
+
function useQuote(editor) {
|
|
13
13
|
(0, _react.useEffect)(function () {
|
|
14
14
|
return (0, _utils.mergeRegister)(editor.registerCommand(_webinyQuote.INSERT_WEBINY_QUOTE_COMMAND, function (_ref) {
|
|
15
15
|
var themeStyleId = _ref.themeStyleId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useQuote","editor","useEffect","mergeRegister","registerCommand","INSERT_WEBINY_QUOTE_COMMAND","themeStyleId","formatToQuote","COMMAND_PRIORITY_LOW"],"sources":["useQuote.ts"],"sourcesContent":["import type { LexicalEditor } from \"lexical\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { COMMAND_PRIORITY_LOW } from \"lexical\";\nimport { useEffect } from \"react\";\nimport { INSERT_WEBINY_QUOTE_COMMAND } from \"~/commands/webiny-quote\";\nimport { formatToQuote } from \"~/utils/nodes/formatToQuote\";\n\nexport function useQuote(editor: LexicalEditor): void {\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n INSERT_WEBINY_QUOTE_COMMAND,\n ({ themeStyleId }) => {\n formatToQuote(editor, themeStyleId);\n return false;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor]);\n}\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AACA;AAEO,SAASA,QAAQ,CAACC,MAAqB,EAAQ;EAClD,IAAAC,gBAAS,EAAC,YAAM;IACZ,OAAO,IAAAC,oBAAa,EAChBF,MAAM,CAACG,eAAe,CAClBC,wCAA2B,EAC3B,gBAAsB;MAAA,IAAnBC,YAAY,QAAZA,YAAY;MACX,IAAAC,4BAAa,EAACN,MAAM,EAAEK,YAAY,CAAC;MACnC,OAAO,KAAK;IAChB,CAAC,EACDE,6BAAoB,CACvB,CACJ;EACL,CAAC,EAAE,CAACP,MAAM,CAAC,CAAC;AAChB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/// <reference types="web" />
|
|
3
|
+
import { LexicalNode, NodeKey, RangeSelection, Spread } from "lexical";
|
|
4
|
+
import { EditorConfig } from "lexical";
|
|
5
|
+
import { TypographyStylesNode, ThemeStyleValue, TextNodeThemeStyles } from "./types";
|
|
6
|
+
import { WebinyTheme } from "../themes/webinyLexicalTheme";
|
|
7
|
+
import { ThemeEmotionMap } from "../types";
|
|
8
|
+
import { HeadingNode as BaseHeadingNode, HeadingTagType, SerializedHeadingNode as BaseSerializedHeadingNode } from "@lexical/rich-text";
|
|
9
|
+
import { ParagraphNode } from "./ParagraphNode";
|
|
10
|
+
export declare type SerializeHeadingNode = Spread<{
|
|
11
|
+
styles: ThemeStyleValue[];
|
|
12
|
+
type: "heading-element";
|
|
13
|
+
}, BaseSerializedHeadingNode>;
|
|
14
|
+
export declare class HeadingNode extends BaseHeadingNode implements TextNodeThemeStyles, TypographyStylesNode {
|
|
15
|
+
__styles: ThemeStyleValue[];
|
|
16
|
+
constructor(tag: HeadingTagType, typographyStyleId?: string, key?: NodeKey);
|
|
17
|
+
protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap): void;
|
|
18
|
+
setTypography(typographyStyleId: string): this;
|
|
19
|
+
getTypographyStyleId(): string | undefined;
|
|
20
|
+
clearTypographyStyle(): this;
|
|
21
|
+
hasTypographyStyle(): boolean;
|
|
22
|
+
getThemeStyles(): ThemeStyleValue[];
|
|
23
|
+
setThemeStyles(styles: ThemeStyleValue[]): this;
|
|
24
|
+
static getType(): string;
|
|
25
|
+
static clone(node: HeadingNode): HeadingNode;
|
|
26
|
+
protected updateElementWithThemeClasses(element: HTMLElement, theme: WebinyTheme): HTMLElement;
|
|
27
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
28
|
+
static importJSON(serializedNode: SerializeHeadingNode): BaseHeadingNode;
|
|
29
|
+
exportJSON(): SerializeHeadingNode;
|
|
30
|
+
insertNewAfter(selection?: RangeSelection, restoreSelection?: boolean): ParagraphNode | HeadingNode;
|
|
31
|
+
collapseAtStart(): true;
|
|
32
|
+
}
|
|
33
|
+
export declare function $createHeadingNode(tag: HeadingTagType, typographyStyleId?: string): HeadingNode;
|
|
34
|
+
export declare function $isHeadingNode(node: LexicalNode | null | undefined): node is HeadingNode;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.$createHeadingNode = $createHeadingNode;
|
|
8
|
+
exports.$isHeadingNode = $isHeadingNode;
|
|
9
|
+
exports.HeadingNode = void 0;
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
16
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
18
|
+
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
20
|
+
var _lexical = require("lexical");
|
|
21
|
+
var _utils = require("@lexical/utils");
|
|
22
|
+
var _findTypographyStyleByHtmlTag = require("../utils/findTypographyStyleByHtmlTag");
|
|
23
|
+
var _richText = require("@lexical/rich-text");
|
|
24
|
+
var _ParagraphNode = require("./ParagraphNode");
|
|
25
|
+
var HeadingNode = /*#__PURE__*/function (_BaseHeadingNode) {
|
|
26
|
+
(0, _inherits2.default)(HeadingNode, _BaseHeadingNode);
|
|
27
|
+
var _super = (0, _createSuper2.default)(HeadingNode);
|
|
28
|
+
function HeadingNode(tag, typographyStyleId, key) {
|
|
29
|
+
var _this;
|
|
30
|
+
(0, _classCallCheck2.default)(this, HeadingNode);
|
|
31
|
+
_this = _super.call(this, tag, key);
|
|
32
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "__styles", []);
|
|
33
|
+
if (typographyStyleId) {
|
|
34
|
+
_this.__styles.push({
|
|
35
|
+
styleId: typographyStyleId,
|
|
36
|
+
type: "typography"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return _this;
|
|
40
|
+
}
|
|
41
|
+
(0, _createClass2.default)(HeadingNode, [{
|
|
42
|
+
key: "setDefaultTypography",
|
|
43
|
+
value: function setDefaultTypography(themeEmotionMap) {
|
|
44
|
+
var typographyStyle = (0, _findTypographyStyleByHtmlTag.findTypographyStyleByHtmlTag)(this.__tag, themeEmotionMap);
|
|
45
|
+
if (typographyStyle) {
|
|
46
|
+
this.__styles.push({
|
|
47
|
+
styleId: typographyStyle.id,
|
|
48
|
+
type: "typography"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "setTypography",
|
|
54
|
+
value: function setTypography(typographyStyleId) {
|
|
55
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getWritable", this).call(this);
|
|
56
|
+
if (!this.hasTypographyStyle()) {
|
|
57
|
+
var themeStyle = {
|
|
58
|
+
styleId: typographyStyleId,
|
|
59
|
+
type: "typography"
|
|
60
|
+
};
|
|
61
|
+
self.__styles.push(themeStyle);
|
|
62
|
+
}
|
|
63
|
+
return self;
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "getTypographyStyleId",
|
|
67
|
+
value: function getTypographyStyleId() {
|
|
68
|
+
var style = this.__styles.find(function (x) {
|
|
69
|
+
return x.type === "typography";
|
|
70
|
+
});
|
|
71
|
+
return (style === null || style === void 0 ? void 0 : style.styleId) || undefined;
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "clearTypographyStyle",
|
|
75
|
+
value: function clearTypographyStyle() {
|
|
76
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getWritable", this).call(this);
|
|
77
|
+
self.__styles = self.__styles.filter(function (s) {
|
|
78
|
+
return s.type !== "typography";
|
|
79
|
+
});
|
|
80
|
+
return self;
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "hasTypographyStyle",
|
|
84
|
+
value: function hasTypographyStyle() {
|
|
85
|
+
return !!this.getTypographyStyleId();
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "getThemeStyles",
|
|
89
|
+
value: function getThemeStyles() {
|
|
90
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getLatest", this).call(this);
|
|
91
|
+
return self.__styles;
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
key: "setThemeStyles",
|
|
95
|
+
value: function setThemeStyles(styles) {
|
|
96
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getWritable", this).call(this);
|
|
97
|
+
self.__styles = (0, _toConsumableArray2.default)(styles);
|
|
98
|
+
return self;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "updateElementWithThemeClasses",
|
|
102
|
+
value: function updateElementWithThemeClasses(element, theme) {
|
|
103
|
+
if (!(theme !== null && theme !== void 0 && theme.emotionMap)) {
|
|
104
|
+
return element;
|
|
105
|
+
}
|
|
106
|
+
if (!this.hasTypographyStyle()) {
|
|
107
|
+
this.setDefaultTypography(theme.emotionMap);
|
|
108
|
+
}
|
|
109
|
+
var typoStyleId = this.getTypographyStyleId();
|
|
110
|
+
var themeClasses;
|
|
111
|
+
|
|
112
|
+
// Typography css class
|
|
113
|
+
if (typoStyleId) {
|
|
114
|
+
var typographyStyle = theme.emotionMap[typoStyleId];
|
|
115
|
+
if (typographyStyle) {
|
|
116
|
+
themeClasses = typographyStyle.className;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (themeClasses) {
|
|
120
|
+
(0, _utils.addClassNamesToElement)(element, themeClasses);
|
|
121
|
+
}
|
|
122
|
+
return element;
|
|
123
|
+
}
|
|
124
|
+
}, {
|
|
125
|
+
key: "createDOM",
|
|
126
|
+
value: function createDOM(config) {
|
|
127
|
+
var element = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "createDOM", this).call(this, config);
|
|
128
|
+
return this.updateElementWithThemeClasses(element, config.theme);
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "exportJSON",
|
|
132
|
+
value: function exportJSON() {
|
|
133
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "exportJSON", this).call(this)), {}, {
|
|
134
|
+
styles: this.__styles,
|
|
135
|
+
type: "heading-element",
|
|
136
|
+
version: 1
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Mutation
|
|
141
|
+
}, {
|
|
142
|
+
key: "insertNewAfter",
|
|
143
|
+
value: function insertNewAfter(selection) {
|
|
144
|
+
var restoreSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
145
|
+
// Next line for headings are always headings with the same tag
|
|
146
|
+
var newElement = $createHeadingNode(this.getTag());
|
|
147
|
+
var direction = this.getDirection();
|
|
148
|
+
newElement.setDirection(direction);
|
|
149
|
+
this.insertAfter(newElement, restoreSelection);
|
|
150
|
+
return newElement;
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: "collapseAtStart",
|
|
154
|
+
value: function collapseAtStart() {
|
|
155
|
+
var newElement = !this.isEmpty() ? $createHeadingNode(this.getTag()) : (0, _ParagraphNode.$createParagraphNode)();
|
|
156
|
+
var children = this.getChildren();
|
|
157
|
+
children.forEach(function (child) {
|
|
158
|
+
return newElement.append(child);
|
|
159
|
+
});
|
|
160
|
+
this.replace(newElement);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}], [{
|
|
164
|
+
key: "getType",
|
|
165
|
+
value: function getType() {
|
|
166
|
+
return "heading-element";
|
|
167
|
+
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "clone",
|
|
170
|
+
value: function clone(node) {
|
|
171
|
+
return new HeadingNode(node.getTag(), node.getTypographyStyleId(), node.__key);
|
|
172
|
+
}
|
|
173
|
+
}, {
|
|
174
|
+
key: "importJSON",
|
|
175
|
+
value: function importJSON(serializedNode) {
|
|
176
|
+
var node = $createHeadingNode(serializedNode.tag);
|
|
177
|
+
node.setFormat(serializedNode.format);
|
|
178
|
+
node.setIndent(serializedNode.indent);
|
|
179
|
+
node.setDirection(serializedNode.direction);
|
|
180
|
+
node.setThemeStyles(serializedNode.styles);
|
|
181
|
+
return node;
|
|
182
|
+
}
|
|
183
|
+
}]);
|
|
184
|
+
return HeadingNode;
|
|
185
|
+
}(_richText.HeadingNode);
|
|
186
|
+
exports.HeadingNode = HeadingNode;
|
|
187
|
+
function $createHeadingNode(tag, typographyStyleId) {
|
|
188
|
+
return (0, _lexical.$applyNodeReplacement)(new HeadingNode(tag, typographyStyleId));
|
|
189
|
+
}
|
|
190
|
+
function $isHeadingNode(node) {
|
|
191
|
+
return node instanceof HeadingNode;
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HeadingNode","tag","typographyStyleId","key","__styles","push","styleId","type","themeEmotionMap","typographyStyle","findTypographyStyleByHtmlTag","__tag","id","self","hasTypographyStyle","themeStyle","style","find","x","undefined","filter","s","getTypographyStyleId","styles","element","theme","emotionMap","setDefaultTypography","typoStyleId","themeClasses","className","addClassNamesToElement","config","updateElementWithThemeClasses","version","selection","restoreSelection","newElement","$createHeadingNode","getTag","direction","getDirection","setDirection","insertAfter","isEmpty","$createParagraphNode","children","getChildren","forEach","child","append","replace","node","__key","serializedNode","setFormat","format","setIndent","indent","setThemeStyles","BaseHeadingNode","$applyNodeReplacement","$isHeadingNode"],"sources":["HeadingNode.ts"],"sourcesContent":["import { $applyNodeReplacement, LexicalNode, NodeKey, RangeSelection, Spread } from \"lexical\";\nimport { EditorConfig } from \"lexical\";\nimport { TypographyStylesNode, ThemeStyleValue, TextNodeThemeStyles } from \"~/nodes/types\";\nimport { WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport { findTypographyStyleByHtmlTag } from \"~/utils/findTypographyStyleByHtmlTag\";\nimport { ThemeEmotionMap } from \"~/types\";\nimport {\n HeadingNode as BaseHeadingNode,\n HeadingTagType,\n SerializedHeadingNode as BaseSerializedHeadingNode\n} from \"@lexical/rich-text\";\nimport { $createParagraphNode, ParagraphNode } from \"~/nodes/ParagraphNode\";\n\nexport type SerializeHeadingNode = Spread<\n {\n styles: ThemeStyleValue[];\n type: \"heading-element\";\n },\n BaseSerializedHeadingNode\n>;\n\nexport class HeadingNode\n extends BaseHeadingNode\n implements TextNodeThemeStyles, TypographyStylesNode\n{\n __styles: ThemeStyleValue[] = [];\n\n constructor(tag: HeadingTagType, typographyStyleId?: string, key?: NodeKey) {\n super(tag, key);\n\n if (typographyStyleId) {\n this.__styles.push({ styleId: typographyStyleId, type: \"typography\" });\n }\n }\n\n protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap) {\n const typographyStyle = findTypographyStyleByHtmlTag(this.__tag, themeEmotionMap);\n if (typographyStyle) {\n this.__styles.push({ styleId: typographyStyle.id, type: \"typography\" });\n }\n }\n\n setTypography(typographyStyleId: string): this {\n const self = super.getWritable();\n if (!this.hasTypographyStyle()) {\n const themeStyle = {\n styleId: typographyStyleId,\n type: \"typography\"\n } as ThemeStyleValue;\n self.__styles.push(themeStyle);\n }\n return self;\n }\n\n getTypographyStyleId(): string | undefined {\n const style = this.__styles.find(x => x.type === \"typography\");\n return style?.styleId || undefined;\n }\n\n clearTypographyStyle(): this {\n const self = super.getWritable();\n self.__styles = self.__styles.filter(s => s.type !== \"typography\");\n return self;\n }\n\n hasTypographyStyle(): boolean {\n return !!this.getTypographyStyleId();\n }\n\n getThemeStyles(): ThemeStyleValue[] {\n const self = super.getLatest();\n return self.__styles;\n }\n\n setThemeStyles(styles: ThemeStyleValue[]) {\n const self = super.getWritable();\n self.__styles = [...styles];\n return self;\n }\n\n static override getType(): string {\n return \"heading-element\";\n }\n\n static override clone(node: HeadingNode): HeadingNode {\n return new HeadingNode(node.getTag(), node.getTypographyStyleId(), node.__key);\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: WebinyTheme): HTMLElement {\n if (!theme?.emotionMap) {\n return element;\n }\n\n if (!this.hasTypographyStyle()) {\n this.setDefaultTypography(theme.emotionMap);\n }\n\n const typoStyleId = this.getTypographyStyleId();\n\n let themeClasses;\n\n // Typography css class\n if (typoStyleId) {\n const typographyStyle = theme.emotionMap[typoStyleId];\n if (typographyStyle) {\n themeClasses = typographyStyle.className;\n }\n }\n\n if (themeClasses) {\n addClassNamesToElement(element, themeClasses);\n }\n\n return element;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.updateElementWithThemeClasses(element, config.theme as WebinyTheme);\n }\n\n static override importJSON(serializedNode: SerializeHeadingNode): BaseHeadingNode {\n const node = $createHeadingNode(serializedNode.tag);\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n node.setThemeStyles(serializedNode.styles);\n return node;\n }\n\n override exportJSON(): SerializeHeadingNode {\n return {\n ...super.exportJSON(),\n styles: this.__styles,\n type: \"heading-element\",\n version: 1\n };\n }\n\n // Mutation\n override insertNewAfter(\n selection?: RangeSelection,\n restoreSelection = true\n ): ParagraphNode | HeadingNode {\n // Next line for headings are always headings with the same tag\n const newElement = $createHeadingNode(this.getTag());\n const direction = this.getDirection();\n newElement.setDirection(direction);\n this.insertAfter(newElement, restoreSelection);\n return newElement;\n }\n\n override collapseAtStart(): true {\n const newElement = !this.isEmpty()\n ? $createHeadingNode(this.getTag())\n : $createParagraphNode();\n const children = this.getChildren();\n children.forEach(child => newElement.append(child));\n this.replace(newElement);\n return true;\n }\n}\n\nexport function $createHeadingNode(tag: HeadingTagType, typographyStyleId?: string): HeadingNode {\n return $applyNodeReplacement(new HeadingNode(tag, typographyStyleId));\n}\n\nexport function $isHeadingNode(node: LexicalNode | null | undefined): node is HeadingNode {\n return node instanceof HeadingNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAIA;AACA;AAEA;AAKA;AAA4E,IAU/DA,WAAW;EAAA;EAAA;EAMpB,qBA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I,CAACG,SAAS,CAACD,cAAc,CAACE,MAAM,CAAC;MACrCJ,IAAI,CAACK,SAAS,CAACH,cAAc,CAACI,MAAM,CAAC;MACrCN,IAAI,CAACV,YAAY,CAACY,cAAc,CAACd,SAAS,CAAC;MAC3CY,IAAI,CAACO,cAAc,CAACL,cAAc,CAAC/B,MAAM,CAAC;MAC1C,OAAO6B,IAAI;IACf;EAAC;EAAA;AAAA,EA1GOQ,qBAAe;AAAA;AA6IpB,SAAStB,kBAAkB,CAACrC,GAAmB,EAAEC,iBAA0B,EAAe;EAC7F,OAAO,IAAA2D,8BAAqB,EAAC,IAAI7D,WAAW,CAACC,GAAG,EAAEC,iBAAiB,CAAC,CAAC;AACzE;AAEO,SAAS4D,cAAc,CAACV,IAAoC,EAAuB;EACtF,OAAOA,IAAI,YAAYpD,WAAW;AACtC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/// <reference types="web" />
|
|
3
|
+
import { DOMConversionMap, LexicalNode, NodeKey, ParagraphNode as BaseParagraphNode, SerializedParagraphNode as SerializedBaseParagraphNode, Spread } from "lexical";
|
|
4
|
+
import { EditorConfig } from "lexical";
|
|
5
|
+
import { TypographyStylesNode, ThemeStyleValue, TextNodeThemeStyles } from "./types";
|
|
6
|
+
import { WebinyTheme } from "../themes/webinyLexicalTheme";
|
|
7
|
+
import { ThemeEmotionMap } from "../types";
|
|
8
|
+
export declare type SerializeParagraphNode = Spread<{
|
|
9
|
+
styles: ThemeStyleValue[];
|
|
10
|
+
type: "paragraph-element";
|
|
11
|
+
}, SerializedBaseParagraphNode>;
|
|
12
|
+
export declare class ParagraphNode extends BaseParagraphNode implements TextNodeThemeStyles, TypographyStylesNode {
|
|
13
|
+
__styles: ThemeStyleValue[];
|
|
14
|
+
constructor(typographyStyleId?: string, key?: NodeKey);
|
|
15
|
+
protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap): void;
|
|
16
|
+
setTypography(typographyStyleId: string): this;
|
|
17
|
+
getTypographyStyleId(): string | undefined;
|
|
18
|
+
clearTypographyStyle(): this;
|
|
19
|
+
hasTypographyStyle(): boolean;
|
|
20
|
+
getThemeStyles(): ThemeStyleValue[];
|
|
21
|
+
setThemeStyles(styles: ThemeStyleValue[]): this;
|
|
22
|
+
static getType(): string;
|
|
23
|
+
static clone(node: ParagraphNode): ParagraphNode;
|
|
24
|
+
protected updateElementWithThemeClasses(element: HTMLElement, theme: WebinyTheme): HTMLElement;
|
|
25
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
26
|
+
updateDOM(prevNode: BaseParagraphNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
27
|
+
static importDOM(): DOMConversionMap | null;
|
|
28
|
+
static importJSON(serializedNode: SerializeParagraphNode): BaseParagraphNode;
|
|
29
|
+
exportJSON(): SerializeParagraphNode;
|
|
30
|
+
}
|
|
31
|
+
export declare function $createParagraphNode(typographyStyleId?: string): ParagraphNode;
|
|
32
|
+
export declare function $isParagraphNode(node: LexicalNode | null | undefined): node is ParagraphNode;
|