@webiny/lexical-editor 5.43.2-beta.0 → 6.0.0-alpha.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/commands/image.js +2 -8
- package/commands/image.js.map +1 -1
- package/commands/index.js +4 -49
- package/commands/index.js.map +1 -1
- package/commands/list.js +4 -10
- package/commands/list.js.map +1 -1
- package/commands/quote.js +2 -8
- package/commands/quote.js.map +1 -1
- package/commands/toolbar.js +2 -8
- package/commands/toolbar.js.map +1 -1
- package/components/Editor/EnsureHeadingTagPlugin.js +10 -16
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
- package/components/Editor/HeadingEditor.js +13 -21
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/ParagraphEditor.js +12 -19
- package/components/Editor/ParagraphEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.js +92 -105
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/Editor/normalizeInputValue.js +2 -8
- package/components/Editor/normalizeInputValue.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +39 -49
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditorConfig/components/Node.js +17 -26
- package/components/LexicalEditorConfig/components/Node.js.map +1 -1
- package/components/LexicalEditorConfig/components/Plugin.js +17 -26
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +17 -26
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
- package/components/LexicalHtmlRenderer.js +37 -46
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.d.ts +3 -1
- package/components/Toolbar/StaticToolbar.js +19 -23
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/Toolbar/Toolbar.js +66 -75
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +16 -21
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +26 -31
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +16 -21
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.js +32 -42
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/FontSizeAction.js +53 -71
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +19 -34
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +16 -21
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +19 -24
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +26 -33
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +20 -25
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.js +36 -45
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +43 -55
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +16 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +2 -9
- package/context/FontColorActionContext.js.map +1 -1
- package/context/RichTextEditorContext.js +15 -26
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.js +12 -20
- package/context/SharedHistoryContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.js +2 -9
- package/context/TextAlignmentActionContextProps.js.map +1 -1
- package/context/TypographyActionContext.js +2 -9
- package/context/TypographyActionContext.js.map +1 -1
- package/hooks/index.js +8 -93
- package/hooks/index.js.map +1 -1
- package/hooks/useCurrentElement.d.ts +2 -2
- package/hooks/useCurrentElement.js +12 -18
- package/hooks/useCurrentElement.js.map +1 -1
- package/hooks/useCurrentSelection.js +27 -40
- package/hooks/useCurrentSelection.js.map +1 -1
- package/hooks/useFontColorPicker.js +5 -11
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useIsMounted.js +6 -14
- package/hooks/useIsMounted.js.map +1 -1
- package/hooks/useList.js +31 -35
- package/hooks/useList.js.map +1 -1
- package/hooks/useQuote.js +12 -17
- package/hooks/useQuote.js.map +1 -1
- package/hooks/useRichTextEditor.js +5 -11
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.js +5 -11
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.js +5 -11
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.js +49 -322
- package/index.js.map +1 -1
- package/package.json +8 -7
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +9 -14
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.js +1 -16
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +16 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +158 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +8 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +62 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +2 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -16
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +11 -180
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +2 -3
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +54 -68
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +16 -26
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +3 -9
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +19 -22
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToNode.js +4 -10
- package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToSelection.js +28 -44
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.js +59 -58
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js +23 -23
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/index.js +1 -16
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.js +30 -37
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/plugins/ListPLugin/ListPlugin.js +10 -15
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +11 -16
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +16 -21
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +6 -38
- package/types.js.map +1 -1
- package/ui/ContentEditable.js +7 -14
- package/ui/ContentEditable.js.map +1 -1
- package/ui/Divider.js +3 -10
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.js +61 -88
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.js +78 -83
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.js +22 -29
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.js +10 -16
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.js +11 -18
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.js +30 -42
- package/ui/ToolbarActionDialog.js.map +1 -1
- package/utils/canUseDOM.js +1 -7
- package/utils/canUseDOM.js.map +1 -1
- package/utils/files.js +9 -26
- package/utils/files.js.map +1 -1
- package/utils/generateInitialLexicalValue.js +2 -8
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getDOMRangeRect.js +4 -10
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getSelectedNode.js +9 -16
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/getTransparentImage.js +1 -7
- package/utils/getTransparentImage.js.map +1 -1
- package/utils/insertImage.js +8 -14
- package/utils/insertImage.js.map +1 -1
- package/utils/isAnchorLink.js +1 -7
- package/utils/isAnchorLink.js.map +1 -1
- package/utils/isChildOfFloatingToolbar.js +3 -9
- package/utils/isChildOfFloatingToolbar.js.map +1 -1
- package/utils/isHTMLElement.js +1 -7
- package/utils/isHTMLElement.js.map +1 -1
- package/utils/isValidJSON.js +3 -9
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +1 -1
- package/utils/isValidLexicalData.js +6 -12
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/point.js +35 -60
- package/utils/point.js.map +1 -1
- package/utils/rect.js +114 -149
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js +6 -13
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.js +11 -19
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +0 -2
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +0 -96
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +0 -1
|
@@ -1,53 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
editor = _useRichTextEditor.editor,
|
|
19
|
-
themeEmotionMap = _useRichTextEditor.themeEmotionMap;
|
|
20
|
-
var isList = (0, _lexicalNodes.$isListNode)(element);
|
|
21
|
-
var isNumbered = isList && element.getListType() === "number";
|
|
22
|
-
var getStyleId = function getStyleId() {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { $isListNode } from "@webiny/lexical-nodes";
|
|
3
|
+
import { findTypographyStyleByHtmlTag } from "@webiny/lexical-theme";
|
|
4
|
+
import { INSERT_ORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND } from "../../commands";
|
|
5
|
+
import { useRichTextEditor } from "../../hooks/useRichTextEditor";
|
|
6
|
+
import { useCurrentElement } from "../../hooks/useCurrentElement";
|
|
7
|
+
export const NumberedListAction = () => {
|
|
8
|
+
const {
|
|
9
|
+
element
|
|
10
|
+
} = useCurrentElement();
|
|
11
|
+
const {
|
|
12
|
+
editor,
|
|
13
|
+
themeEmotionMap
|
|
14
|
+
} = useRichTextEditor();
|
|
15
|
+
const isList = $isListNode(element);
|
|
16
|
+
const isNumbered = isList && element.getListType() === "number";
|
|
17
|
+
const getStyleId = () => {
|
|
23
18
|
if (!themeEmotionMap) {
|
|
24
19
|
return undefined;
|
|
25
20
|
}
|
|
26
21
|
// check default style for numbered list
|
|
27
|
-
|
|
22
|
+
const id = findTypographyStyleByHtmlTag("ol", themeEmotionMap)?.id;
|
|
28
23
|
if (id) {
|
|
29
24
|
return id;
|
|
30
25
|
}
|
|
31
26
|
// fallback to ul list styles
|
|
32
|
-
return
|
|
27
|
+
return findTypographyStyleByHtmlTag("ul", themeEmotionMap)?.id;
|
|
33
28
|
};
|
|
34
|
-
|
|
29
|
+
const formatNumberedList = () => {
|
|
35
30
|
if (!isNumbered) {
|
|
36
|
-
|
|
37
|
-
editor.dispatchCommand(
|
|
31
|
+
const styleId = themeEmotionMap ? getStyleId() : undefined;
|
|
32
|
+
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, {
|
|
38
33
|
themeStyleId: styleId
|
|
39
34
|
});
|
|
40
35
|
} else {
|
|
41
|
-
editor.dispatchCommand(
|
|
36
|
+
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
|
|
42
37
|
}
|
|
43
38
|
};
|
|
44
|
-
return /*#__PURE__*/
|
|
45
|
-
onClick:
|
|
46
|
-
return formatNumberedList();
|
|
47
|
-
},
|
|
39
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
40
|
+
onClick: () => formatNumberedList(),
|
|
48
41
|
className: "popup-item spaced " + (isNumbered ? "active" : ""),
|
|
49
42
|
"aria-label": "Format text as numbered list"
|
|
50
|
-
}, /*#__PURE__*/
|
|
43
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
51
44
|
className: "icon numbered-list"
|
|
52
45
|
}));
|
|
53
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","$isListNode","findTypographyStyleByHtmlTag","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND","useRichTextEditor","useCurrentElement","NumberedListAction","element","editor","themeEmotionMap","isList","isNumbered","getListType","getStyleId","undefined","id","formatNumberedList","styleId","dispatchCommand","themeStyleId","createElement","onClick","className"],"sources":["NumberedListAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { $isListNode, ListNode } from \"@webiny/lexical-nodes\";\nimport { findTypographyStyleByHtmlTag } from \"@webiny/lexical-theme\";\nimport { INSERT_ORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND } from \"~/commands\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\n\nexport const NumberedListAction = () => {\n const { element } = useCurrentElement();\n const { editor, themeEmotionMap } = useRichTextEditor();\n const isList = $isListNode(element);\n const isNumbered = isList && (element as ListNode).getListType() === \"number\";\n\n const getStyleId = (): string | undefined => {\n if (!themeEmotionMap) {\n return undefined;\n }\n // check default style for numbered list\n const id = findTypographyStyleByHtmlTag(\"ol\", themeEmotionMap)?.id;\n if (id) {\n return id;\n }\n // fallback to ul list styles\n return findTypographyStyleByHtmlTag(\"ul\", themeEmotionMap)?.id;\n };\n\n const formatNumberedList = () => {\n if (!isNumbered) {\n const styleId = themeEmotionMap ? getStyleId() : undefined;\n editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, { themeStyleId: styleId });\n } else {\n editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);\n }\n };\n\n return (\n <button\n onClick={() => formatNumberedList()}\n className={\"popup-item spaced \" + (isNumbered ? \"active\" : \"\")}\n aria-label=\"Format text as numbered list\"\n >\n <i className=\"icon numbered-list\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,QAAkB,uBAAuB;AAC7D,SAASC,4BAA4B,QAAQ,uBAAuB;AACpE,SAASC,2BAA2B,EAAEC,mBAAmB;AACzD,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAM;EACpC,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
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
themeEmotionMap = _useRichTextEditor.themeEmotionMap;
|
|
16
|
-
var _useCurrentElement = (0, _useCurrentElement2.useCurrentElement)(),
|
|
17
|
-
element = _useCurrentElement.element;
|
|
18
|
-
var isQuote = (0, _lexicalNodes.$isQuoteNode)(element);
|
|
19
|
-
var formatText = function formatText() {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { $isQuoteNode, formatToQuote, formatToParagraph } from "@webiny/lexical-nodes";
|
|
3
|
+
import { useRichTextEditor } from "../../hooks/useRichTextEditor";
|
|
4
|
+
import { useCurrentElement } from "../../hooks/useCurrentElement";
|
|
5
|
+
export const QuoteAction = () => {
|
|
6
|
+
const {
|
|
7
|
+
editor,
|
|
8
|
+
themeEmotionMap
|
|
9
|
+
} = useRichTextEditor();
|
|
10
|
+
const {
|
|
11
|
+
element
|
|
12
|
+
} = useCurrentElement();
|
|
13
|
+
const isQuote = $isQuoteNode(element);
|
|
14
|
+
const formatText = () => {
|
|
20
15
|
if (!isQuote) {
|
|
21
16
|
// Try to set default quote style, when the action button is clicked for first time
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const DEFAULT_QUOTE_ID = "quote";
|
|
18
|
+
const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];
|
|
19
|
+
formatToQuote(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);
|
|
25
20
|
return;
|
|
26
21
|
}
|
|
27
|
-
|
|
22
|
+
formatToParagraph(editor);
|
|
28
23
|
};
|
|
29
|
-
return /*#__PURE__*/
|
|
24
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
30
25
|
onClick: formatText,
|
|
31
26
|
className: "popup-item " + (isQuote ? "active" : ""),
|
|
32
27
|
"aria-label": "Format text as quote"
|
|
33
|
-
}, /*#__PURE__*/
|
|
28
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
34
29
|
className: "icon quote"
|
|
35
30
|
}));
|
|
36
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","$isQuoteNode","formatToQuote","formatToParagraph","useRichTextEditor","useCurrentElement","QuoteAction","editor","themeEmotionMap","element","isQuote","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","undefined","createElement","onClick","className"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { $isQuoteNode, formatToQuote, formatToParagraph } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\n\nexport const QuoteAction = () => {\n const { editor, themeEmotionMap } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isQuote = $isQuoteNode(element);\n\n const formatText = () => {\n if (!isQuote) {\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 return (\n <button\n onClick={formatText}\n className={\"popup-item \" + (isQuote ? \"active\" : \"\")}\n aria-label=\"Format text as quote\"\n >\n <i className=\"icon quote\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,uBAAuB;AACtF,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,WAAW,GAAGA,CAAA,KAAM;EAC7B,MAAM;IAAEC,MAAM;IAAEC;EAAgB,CAAC,GAAGJ,iBAAiB,CAAC,CAAC;EACvD,MAAM;IAAEK;EAAQ,CAAC,GAAGJ,iBAAiB,CAAC,CAAC;EACvC,MAAMK,OAAO,GAAGT,YAAY,CAACQ,OAAO,CAAC;EAErC,MAAME,UAAU,GAAGA,CAAA,KAAM;IACrB,IAAI,CAACD,OAAO,EAAE;MACV;MACA,MAAME,gBAAgB,GAAG,OAAO;MAChC,MAAMC,cAAc,GAAGL,eAAe,IAAIA,eAAe,CAACI,gBAAgB,CAAC;MAC3EV,aAAa,CAACK,MAAM,EAAEM,cAAc,GAAGD,gBAAgB,GAAGE,SAAS,CAAC;MACpE;IACJ;IACAX,iBAAiB,CAACI,MAAM,CAAC;EAC7B,CAAC;EAED,oBACIP,KAAA,CAAAe,aAAA;IACIC,OAAO,EAAEL,UAAW;IACpBM,SAAS,EAAE,aAAa,IAAIP,OAAO,GAAG,QAAQ,GAAG,EAAE,CAAE;IACrD,cAAW;EAAsB,gBAEjCV,KAAA,CAAAe,aAAA;IAAGE,SAAS,EAAC;EAAY,CAAE,CACvB,CAAC;AAEjB,CAAC","ignoreList":[]}
|
|
@@ -1,69 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { useEffect, useMemo } from "react";
|
|
2
|
+
import { FORMAT_ELEMENT_COMMAND, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND } from "lexical";
|
|
3
|
+
import { Compose, makeDecoratable } from "@webiny/react-composition";
|
|
4
|
+
import { TextAlignmentActionContext } from "../../context/TextAlignmentActionContextProps";
|
|
5
|
+
import { useDeriveValueFromSelection } from "../../hooks/useCurrentSelection";
|
|
6
|
+
import { getSelectedNode } from "../../utils/getSelectedNode";
|
|
7
|
+
import { useRichTextEditor } from "../../hooks";
|
|
2
8
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.TextAlignmentAction = exports.BaseTextAlignmentDropDown = void 0;
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _lexical = require("lexical");
|
|
10
|
-
var _reactComposition = require("@webiny/react-composition");
|
|
11
|
-
var _TextAlignmentActionContextProps = require("../../context/TextAlignmentActionContextProps");
|
|
12
|
-
var _useCurrentSelection = require("../../hooks/useCurrentSelection");
|
|
13
|
-
var _getSelectedNode = require("../../utils/getSelectedNode");
|
|
14
|
-
var _hooks = require("../../hooks");
|
|
15
9
|
/*
|
|
16
10
|
* Base text alignment dropdown composable component.
|
|
17
11
|
* Note: To add a custom dropdown component use @see LexicalEditorConfig API.
|
|
18
12
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
export const BaseTextAlignmentDropDown = makeDecoratable("BaseTextAlignmentDropDown", () => {
|
|
14
|
+
useEffect(() => {
|
|
21
15
|
console.log("Default BaseTextAlignmentDropDown, please add your own component");
|
|
22
16
|
}, []);
|
|
23
17
|
return null;
|
|
24
18
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
const TextAlignmentActionDropDown = ({
|
|
20
|
+
element
|
|
21
|
+
}) => {
|
|
22
|
+
return /*#__PURE__*/React.createElement(Compose, {
|
|
28
23
|
component: BaseTextAlignmentDropDown,
|
|
29
|
-
with:
|
|
30
|
-
return function () {
|
|
31
|
-
return element;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
24
|
+
with: () => () => element
|
|
34
25
|
});
|
|
35
26
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
editor
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
export const TextAlignmentAction = () => {
|
|
28
|
+
const {
|
|
29
|
+
editor
|
|
30
|
+
} = useRichTextEditor();
|
|
31
|
+
const alignmentValue = useDeriveValueFromSelection(({
|
|
32
|
+
rangeSelection
|
|
33
|
+
}) => {
|
|
34
|
+
const node = rangeSelection ? getSelectedNode(rangeSelection) : null;
|
|
42
35
|
if (node) {
|
|
43
36
|
return node.getParent()?.getFormatType() || "";
|
|
44
37
|
}
|
|
45
38
|
return "";
|
|
46
39
|
});
|
|
47
|
-
|
|
48
|
-
editor.dispatchCommand(
|
|
40
|
+
const applyTextAlignment = value => {
|
|
41
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);
|
|
49
42
|
};
|
|
50
|
-
|
|
51
|
-
editor.dispatchCommand(
|
|
43
|
+
const outdentText = () => {
|
|
44
|
+
editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
|
|
52
45
|
};
|
|
53
|
-
|
|
54
|
-
editor.dispatchCommand(
|
|
46
|
+
const indentText = () => {
|
|
47
|
+
editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
|
|
55
48
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}, [alignmentValue]);
|
|
64
|
-
return /*#__PURE__*/_react.default.createElement(_TextAlignmentActionContextProps.TextAlignmentActionContext.Provider, {
|
|
49
|
+
const context = useMemo(() => ({
|
|
50
|
+
value: alignmentValue,
|
|
51
|
+
applyTextAlignment,
|
|
52
|
+
outdentText,
|
|
53
|
+
indentText
|
|
54
|
+
}), [alignmentValue]);
|
|
55
|
+
return /*#__PURE__*/React.createElement(TextAlignmentActionContext.Provider, {
|
|
65
56
|
value: context
|
|
66
|
-
}, /*#__PURE__*/
|
|
57
|
+
}, /*#__PURE__*/React.createElement(BaseTextAlignmentDropDown, null));
|
|
67
58
|
};
|
|
68
59
|
TextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;
|
|
69
60
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useEffect","useMemo","FORMAT_ELEMENT_COMMAND","INDENT_CONTENT_COMMAND","OUTDENT_CONTENT_COMMAND","Compose","makeDecoratable","TextAlignmentActionContext","useDeriveValueFromSelection","getSelectedNode","useRichTextEditor","BaseTextAlignmentDropDown","console","log","TextAlignmentActionDropDown","element","createElement","component","with","TextAlignmentAction","editor","alignmentValue","rangeSelection","node","getParent","getFormatType","applyTextAlignment","value","dispatchCommand","outdentText","undefined","indentText","context","Provider","TextAlignmentDropDown"],"sources":["TextAlignmentAction.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport {\n ElementFormatType,\n FORMAT_ELEMENT_COMMAND,\n INDENT_CONTENT_COMMAND,\n OUTDENT_CONTENT_COMMAND\n} from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { TextAlignmentActionContext } from \"~/context/TextAlignmentActionContextProps\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useRichTextEditor } from \"~/hooks\";\n\n/*\n * Base text alignment dropdown composable component.\n * Note: To add a custom dropdown component use @see LexicalEditorConfig API.\n */\nexport const BaseTextAlignmentDropDown = makeDecoratable(\n \"BaseTextAlignmentDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTextAlignmentDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TextAlignmentActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TextAlignmentActionDropDown = ({\n element\n}: TextAlignmentActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTextAlignmentDropDown} with={() => () => element} />;\n};\n\nexport type TextAlignmentAction = React.ComponentType<unknown> & {\n TextAlignmentDropDown: typeof TextAlignmentActionDropDown;\n};\n\nexport const TextAlignmentAction: TextAlignmentAction = () => {\n const { editor } = useRichTextEditor();\n const alignmentValue: ElementFormatType = useDeriveValueFromSelection(({ rangeSelection }) => {\n const node = rangeSelection ? getSelectedNode(rangeSelection) : null;\n if (node) {\n return node.getParent()?.getFormatType() || \"\";\n }\n return \"\";\n });\n\n const applyTextAlignment = (value: ElementFormatType) => {\n editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);\n };\n\n const outdentText = () => {\n editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);\n };\n\n const indentText = () => {\n editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);\n };\n\n const context = useMemo(\n () => ({\n value: alignmentValue,\n applyTextAlignment,\n outdentText,\n indentText\n }),\n [alignmentValue]\n );\n\n return (\n <TextAlignmentActionContext.Provider value={context}>\n <BaseTextAlignmentDropDown />\n </TextAlignmentActionContext.Provider>\n );\n};\n\nTextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACjD,SAEIC,sBAAsB,EACtBC,sBAAsB,EACtBC,uBAAuB,QACpB,SAAS;AAChB,SAASC,OAAO,EAAEC,eAAe,QAAQ,2BAA2B;AACpE,SAASC,0BAA0B;AACnC,SAASC,2BAA2B;AACpC,SAASC,eAAe;AACxB,SAASC,iBAAiB;;AAE1B;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,GAAGL,eAAe,CACpD,2BAA2B,EAC3B,MAA0B;EACtBN,SAAS,CAAC,MAAM;IACZY,OAAO,CAACC,GAAG,CAAC,kEAAkE,CAAC;EACnF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CACJ,CAAC;AAMD,MAAMC,2BAA2B,GAAGA,CAAC;EACjCC;AAC8B,CAAC,KAAkB;EACjD,oBAAOhB,KAAA,CAAAiB,aAAA,CAACX,OAAO;IAACY,SAAS,EAAEN,yBAA0B;IAACO,IAAI,EAAEA,CAAA,KAAM,MAAMH;EAAQ,CAAE,CAAC;AACvF,CAAC;AAMD,OAAO,MAAMI,mBAAwC,GAAGA,CAAA,KAAM;EAC1D,MAAM;IAAEC;EAAO,CAAC,GAAGV,iBAAiB,CAAC,CAAC;EACtC,MAAMW,cAAiC,GAAGb,2BAA2B,CAAC,CAAC;IAAEc;EAAe,CAAC,KAAK;IAC1F,MAAMC,IAAI,GAAGD,cAAc,GAAGb,eAAe,CAACa,cAAc,CAAC,GAAG,IAAI;IACpE,IAAIC,IAAI,EAAE;MACN,OAAOA,IAAI,CAACC,SAAS,CAAC,CAAC,EAAEC,aAAa,CAAC,CAAC,IAAI,EAAE;IAClD;IACA,OAAO,EAAE;EACb,CAAC,CAAC;EAEF,MAAMC,kBAAkB,GAAIC,KAAwB,IAAK;IACrDP,MAAM,CAACQ,eAAe,CAAC1B,sBAAsB,EAAEyB,KAAK,CAAC;EACzD,CAAC;EAED,MAAME,WAAW,GAAGA,CAAA,KAAM;IACtBT,MAAM,CAACQ,eAAe,CAACxB,uBAAuB,EAAE0B,SAAS,CAAC;EAC9D,CAAC;EAED,MAAMC,UAAU,GAAGA,CAAA,KAAM;IACrBX,MAAM,CAACQ,eAAe,CAACzB,sBAAsB,EAAE2B,SAAS,CAAC;EAC7D,CAAC;EAED,MAAME,OAAO,GAAG/B,OAAO,CACnB,OAAO;IACH0B,KAAK,EAAEN,cAAc;IACrBK,kBAAkB;IAClBG,WAAW;IACXE;EACJ,CAAC,CAAC,EACF,CAACV,cAAc,CACnB,CAAC;EAED,oBACItB,KAAA,CAAAiB,aAAA,CAACT,0BAA0B,CAAC0B,QAAQ;IAACN,KAAK,EAAEK;EAAQ,gBAChDjC,KAAA,CAAAiB,aAAA,CAACL,yBAAyB,MAAE,CACK,CAAC;AAE9C,CAAC;AAEDQ,mBAAmB,CAACe,qBAAqB,GAAGpB,2BAA2B","ignoreList":[]}
|
|
@@ -1,99 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { Compose, makeDecoratable } from "@webiny/react-composition";
|
|
3
|
+
import { TypographyActionContext } from "../../context/TypographyActionContext";
|
|
4
|
+
import { $isHeadingNode, $isListNode, $isParagraphNode, $isQuoteNode, $isTypographyNode, ADD_TYPOGRAPHY_COMMAND } from "@webiny/lexical-nodes";
|
|
5
|
+
import { useRichTextEditor } from "../../hooks/useRichTextEditor";
|
|
6
|
+
import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, INSERT_QUOTE_COMMAND } from "../../commands";
|
|
7
|
+
import { useCurrentElement } from "../../hooks/useCurrentElement";
|
|
2
8
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.TypographyAction = exports.BaseTypographyActionDropDown = void 0;
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _reactComposition = require("@webiny/react-composition");
|
|
12
|
-
var _TypographyActionContext = require("../../context/TypographyActionContext");
|
|
13
|
-
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
14
|
-
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
15
|
-
var _commands = require("../../commands");
|
|
16
|
-
var _useCurrentElement2 = require("../../hooks/useCurrentElement");
|
|
17
9
|
/*
|
|
18
10
|
* Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.
|
|
19
11
|
* Note: Toa add custom component access trough @see LexicalEditorConfig API
|
|
20
12
|
* */
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
export const BaseTypographyActionDropDown = makeDecoratable("BaseTypographyActionDropDown", () => {
|
|
14
|
+
useEffect(() => {
|
|
23
15
|
console.log("Default BaseTypographyActionDropDown, please add your own component");
|
|
24
16
|
}, []);
|
|
25
17
|
return null;
|
|
26
18
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
const TypographyActionDropDown = ({
|
|
20
|
+
element
|
|
21
|
+
}) => {
|
|
22
|
+
return /*#__PURE__*/React.createElement(Compose, {
|
|
30
23
|
component: BaseTypographyActionDropDown,
|
|
31
|
-
with:
|
|
32
|
-
return function () {
|
|
33
|
-
return element;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
24
|
+
with: () => () => element
|
|
36
25
|
});
|
|
37
26
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var setTypographySelect = (0, _react.useCallback)(function (value) {
|
|
27
|
+
export const TypographyAction = () => {
|
|
28
|
+
const [typography, setTypography] = useState();
|
|
29
|
+
const {
|
|
30
|
+
editor,
|
|
31
|
+
themeEmotionMap
|
|
32
|
+
} = useRichTextEditor();
|
|
33
|
+
const {
|
|
34
|
+
element
|
|
35
|
+
} = useCurrentElement();
|
|
36
|
+
const isTypographySelected = $isTypographyNode(element);
|
|
37
|
+
const isParagraphSelected = $isParagraphNode(element);
|
|
38
|
+
const isHeadingSelected = $isHeadingNode(element);
|
|
39
|
+
const isQuoteSelected = $isQuoteNode(element);
|
|
40
|
+
const setTypographySelect = useCallback(value => {
|
|
53
41
|
setTypography(value);
|
|
54
42
|
}, [typography]);
|
|
55
|
-
|
|
43
|
+
const onTypographySelect = useCallback(value => {
|
|
56
44
|
setTypographySelect(value);
|
|
57
45
|
if (value.tag.includes("h") || value.tag.includes("p")) {
|
|
58
|
-
editor.dispatchCommand(
|
|
59
|
-
value
|
|
46
|
+
editor.dispatchCommand(ADD_TYPOGRAPHY_COMMAND, {
|
|
47
|
+
value
|
|
60
48
|
});
|
|
61
49
|
}
|
|
62
50
|
if (value.tag === "ol") {
|
|
63
|
-
editor.dispatchCommand(
|
|
51
|
+
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, {
|
|
64
52
|
themeStyleId: value.id
|
|
65
53
|
});
|
|
66
54
|
}
|
|
67
55
|
if (value.tag === "ul") {
|
|
68
|
-
editor.dispatchCommand(
|
|
56
|
+
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, {
|
|
69
57
|
themeStyleId: value.id
|
|
70
58
|
});
|
|
71
59
|
}
|
|
72
60
|
if (value.tag === "quoteblock") {
|
|
73
|
-
editor.dispatchCommand(
|
|
61
|
+
editor.dispatchCommand(INSERT_QUOTE_COMMAND, {
|
|
74
62
|
themeStyleId: value.id
|
|
75
63
|
});
|
|
76
64
|
}
|
|
77
65
|
}, []);
|
|
78
|
-
|
|
66
|
+
useEffect(() => {
|
|
79
67
|
if (!element) {
|
|
80
68
|
return;
|
|
81
69
|
}
|
|
82
70
|
// header and paragraph elements inserted with typography node
|
|
83
71
|
if (isTypographySelected) {
|
|
84
|
-
|
|
72
|
+
const el = element;
|
|
85
73
|
setTypography(el.getTypographyValue());
|
|
86
74
|
return;
|
|
87
75
|
}
|
|
88
76
|
if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {
|
|
89
|
-
|
|
77
|
+
const styleId = element.getTypographyStyleId();
|
|
90
78
|
if (!styleId) {
|
|
91
79
|
return;
|
|
92
80
|
}
|
|
93
81
|
if (!themeEmotionMap) {
|
|
94
82
|
return;
|
|
95
83
|
}
|
|
96
|
-
|
|
84
|
+
const style = themeEmotionMap[styleId];
|
|
97
85
|
if (style) {
|
|
98
86
|
setTypography({
|
|
99
87
|
name: style?.name,
|
|
@@ -106,10 +94,10 @@ var TypographyAction = exports.TypographyAction = function TypographyAction() {
|
|
|
106
94
|
}
|
|
107
95
|
|
|
108
96
|
// list and quote element
|
|
109
|
-
if (themeEmotionMap && (
|
|
110
|
-
|
|
97
|
+
if (themeEmotionMap && ($isListNode(element) || $isQuoteNode(element))) {
|
|
98
|
+
const themeStyleId = element?.getStyleId() || undefined;
|
|
111
99
|
if (themeStyleId) {
|
|
112
|
-
|
|
100
|
+
const elementStyle = themeEmotionMap[themeStyleId];
|
|
113
101
|
if (elementStyle) {
|
|
114
102
|
setTypography({
|
|
115
103
|
id: elementStyle.id,
|
|
@@ -121,12 +109,12 @@ var TypographyAction = exports.TypographyAction = function TypographyAction() {
|
|
|
121
109
|
}
|
|
122
110
|
}
|
|
123
111
|
}, [element, isTypographySelected, isQuoteSelected, isParagraphSelected, isHeadingSelected]);
|
|
124
|
-
return /*#__PURE__*/
|
|
112
|
+
return /*#__PURE__*/React.createElement(TypographyActionContext.Provider, {
|
|
125
113
|
value: {
|
|
126
114
|
value: typography,
|
|
127
115
|
applyTypography: onTypographySelect
|
|
128
116
|
}
|
|
129
|
-
}, /*#__PURE__*/
|
|
117
|
+
}, /*#__PURE__*/React.createElement(BaseTypographyActionDropDown, null));
|
|
130
118
|
};
|
|
131
119
|
TypographyAction.TypographyDropDown = TypographyActionDropDown;
|
|
132
120
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","_TypographyActionContext","_lexicalNodes","_useRichTextEditor2","_commands","_useCurrentElement2","BaseTypographyActionDropDown","exports","makeDecoratable","useEffect","console","log","TypographyActionDropDown","_ref","element","default","createElement","Compose","component","with","_with","TypographyAction","_useState","useState","_useState2","_slicedToArray2","typography","setTypography","_useRichTextEditor","useRichTextEditor","editor","themeEmotionMap","_useCurrentElement","useCurrentElement","isTypographySelected","$isTypographyNode","isParagraphSelected","$isParagraphNode","isHeadingSelected","$isHeadingNode","isQuoteSelected","$isQuoteNode","setTypographySelect","useCallback","value","onTypographySelect","tag","includes","dispatchCommand","ADD_TYPOGRAPHY_COMMAND","INSERT_ORDERED_LIST_COMMAND","themeStyleId","id","INSERT_UNORDERED_LIST_COMMAND","INSERT_QUOTE_COMMAND","el","getTypographyValue","styleId","getTypographyStyleId","style","name","css","styles","$isListNode","getStyleId","undefined","elementStyle","TypographyActionContext","Provider","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { TypographyValue } from \"@webiny/lexical-theme\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\nimport {\n $isHeadingNode,\n $isListNode,\n $isParagraphNode,\n $isQuoteNode,\n $isTypographyNode,\n ADD_TYPOGRAPHY_COMMAND,\n TypographyNode,\n TypographyPayload\n} from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_LIST_COMMAND,\n INSERT_UNORDERED_LIST_COMMAND,\n INSERT_QUOTE_COMMAND,\n ListCommandPayload,\n QuoteCommandPayload\n} from \"~/commands\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\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 = makeDecoratable(\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 = ({ element }: TypographyActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport type TypographyAction = React.ComponentType<unknown> & {\n TypographyDropDown: typeof TypographyActionDropDown;\n};\n\nexport const TypographyAction: TypographyAction = () => {\n const [typography, setTypography] = useState<TypographyValue>();\n const { editor, themeEmotionMap } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isTypographySelected = $isTypographyNode(element);\n const isParagraphSelected = $isParagraphNode(element);\n const isHeadingSelected = $isHeadingNode(element);\n const isQuoteSelected = $isQuoteNode(element);\n\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>>(ADD_TYPOGRAPHY_COMMAND, {\n value\n });\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_ORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_UNORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<QuoteCommandPayload>>(INSERT_QUOTE_COMMAND, {\n themeStyleId: value.id\n });\n }\n }, []);\n\n useEffect(() => {\n if (!element) {\n return;\n }\n // header and paragraph elements inserted with typography node\n if (isTypographySelected) {\n const el = element as TypographyNode;\n setTypography(el.getTypographyValue());\n return;\n }\n\n if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {\n const styleId = element.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 && ($isListNode(element) || $isQuoteNode(element))) {\n const themeStyleId = 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 }, [element, isTypographySelected, 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\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,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CAAC,CAAC;QACN;MACJ;IACJ;EACJ,CAAC,EAAE,CAAChC,OAAO,EAAEoB,oBAAoB,EAAEM,eAAe,EAAEJ,mBAAmB,EAAEE,iBAAiB,CAAC,CAAC;EAE5F,oBACIzC,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACf,wBAAA,CAAAkE,uBAAuB,CAACC,QAAQ;IAC7BxB,KAAK,EAAE;MACHA,KAAK,EAAElB,UAAU;MACjB2C,eAAe,EAAExB;IACrB;EAAE,gBAEFhD,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACV,4BAA4B,MAAE,CACD,CAAC;AAE3C,CAAC;AAEDe,gBAAgB,CAACiD,kBAAkB,GAAG1D,wBAAwB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useState","Compose","makeDecoratable","TypographyActionContext","$isHeadingNode","$isListNode","$isParagraphNode","$isQuoteNode","$isTypographyNode","ADD_TYPOGRAPHY_COMMAND","useRichTextEditor","INSERT_ORDERED_LIST_COMMAND","INSERT_UNORDERED_LIST_COMMAND","INSERT_QUOTE_COMMAND","useCurrentElement","BaseTypographyActionDropDown","console","log","TypographyActionDropDown","element","createElement","component","with","TypographyAction","typography","setTypography","editor","themeEmotionMap","isTypographySelected","isParagraphSelected","isHeadingSelected","isQuoteSelected","setTypographySelect","value","onTypographySelect","tag","includes","dispatchCommand","themeStyleId","id","el","getTypographyValue","styleId","getTypographyStyleId","style","name","css","styles","getStyleId","undefined","elementStyle","Provider","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { TypographyValue } from \"@webiny/lexical-theme\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\nimport {\n $isHeadingNode,\n $isListNode,\n $isParagraphNode,\n $isQuoteNode,\n $isTypographyNode,\n ADD_TYPOGRAPHY_COMMAND,\n TypographyNode,\n TypographyPayload\n} from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_LIST_COMMAND,\n INSERT_UNORDERED_LIST_COMMAND,\n INSERT_QUOTE_COMMAND,\n ListCommandPayload,\n QuoteCommandPayload\n} from \"~/commands\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\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 = makeDecoratable(\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 = ({ element }: TypographyActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport type TypographyAction = React.ComponentType<unknown> & {\n TypographyDropDown: typeof TypographyActionDropDown;\n};\n\nexport const TypographyAction: TypographyAction = () => {\n const [typography, setTypography] = useState<TypographyValue>();\n const { editor, themeEmotionMap } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isTypographySelected = $isTypographyNode(element);\n const isParagraphSelected = $isParagraphNode(element);\n const isHeadingSelected = $isHeadingNode(element);\n const isQuoteSelected = $isQuoteNode(element);\n\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>>(ADD_TYPOGRAPHY_COMMAND, {\n value\n });\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_ORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_UNORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<QuoteCommandPayload>>(INSERT_QUOTE_COMMAND, {\n themeStyleId: value.id\n });\n }\n }, []);\n\n useEffect(() => {\n if (!element) {\n return;\n }\n // header and paragraph elements inserted with typography node\n if (isTypographySelected) {\n const el = element as TypographyNode;\n setTypography(el.getTypographyValue());\n return;\n }\n\n if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {\n const styleId = element.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 && ($isListNode(element) || $isQuoteNode(element))) {\n const themeStyleId = 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 }, [element, isTypographySelected, 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\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE/D,SAASC,OAAO,EAAEC,eAAe,QAAQ,2BAA2B;AAEpE,SAASC,uBAAuB;AAChC,SACIC,cAAc,EACdC,WAAW,EACXC,gBAAgB,EAChBC,YAAY,EACZC,iBAAi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13
|
-
editor
|
|
14
|
-
var _useCurrentSelection = (0, _hooks.useCurrentSelection)(),
|
|
15
|
-
rangeSelection = _useCurrentSelection.rangeSelection;
|
|
16
|
-
var isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat("underline") : false;
|
|
17
|
-
var handleClick = function handleClick() {
|
|
18
|
-
editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "underline");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FORMAT_TEXT_COMMAND } from "lexical";
|
|
3
|
+
import { useCurrentSelection, useRichTextEditor } from "../../hooks";
|
|
4
|
+
export const UnderlineAction = () => {
|
|
5
|
+
const {
|
|
6
|
+
editor
|
|
7
|
+
} = useRichTextEditor();
|
|
8
|
+
const {
|
|
9
|
+
rangeSelection
|
|
10
|
+
} = useCurrentSelection();
|
|
11
|
+
const isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat("underline") : false;
|
|
12
|
+
const handleClick = () => {
|
|
13
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline");
|
|
19
14
|
};
|
|
20
|
-
return /*#__PURE__*/
|
|
15
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
21
16
|
onClick: handleClick,
|
|
22
17
|
className: "popup-item spaced " + (isUnderlineSelected ? "active" : ""),
|
|
23
|
-
"aria-label": "
|
|
24
|
-
}, /*#__PURE__*/
|
|
18
|
+
"aria-label": "Underline text"
|
|
19
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
25
20
|
className: "format underline"
|
|
26
21
|
}));
|
|
27
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","FORMAT_TEXT_COMMAND","useCurrentSelection","useRichTextEditor","UnderlineAction","editor","rangeSelection","isUnderlineSelected","hasFormat","handleClick","dispatchCommand","createElement","onClick","className"],"sources":["UnderlineAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useCurrentSelection, useRichTextEditor } from \"~/hooks\";\n\nexport const UnderlineAction = () => {\n const { editor } = useRichTextEditor();\n const { rangeSelection } = useCurrentSelection();\n const isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat(\"underline\") : false;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"underline\");\n };\n\n return (\n <button\n onClick={handleClick}\n className={\"popup-item spaced \" + (isUnderlineSelected ? \"active\" : \"\")}\n aria-label=\"Underline text\"\n >\n <i className=\"format underline\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,mBAAmB,EAAEC,iBAAiB;AAE/C,OAAO,MAAMC,eAAe,GAAGA,CAAA,KAAM;EACjC,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAM;IAAEG;EAAe,CAAC,GAAGJ,mBAAmB,CAAC,CAAC;EAChD,MAAMK,mBAAmB,GAAGD,cAAc,GAAGA,cAAc,CAACE,SAAS,CAAC,WAAW,CAAC,GAAG,KAAK;EAE1F,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACtBJ,MAAM,CAACK,eAAe,CAACT,mBAAmB,EAAE,WAAW,CAAC;EAC5D,CAAC;EAED,oBACID,KAAA,CAAAW,aAAA;IACIC,OAAO,EAAEH,WAAY;IACrBI,SAAS,EAAE,oBAAoB,IAAIN,mBAAmB,GAAG,QAAQ,GAAG,EAAE,CAAE;IACxE,cAAW;EAAgB,gBAE3BP,KAAA,CAAAW,aAAA;IAAGE,SAAS,EAAC;EAAkB,CAAE,CAC7B,CAAC;AAEjB,CAAC","ignoreList":[]}
|