@webiny/lexical-editor 0.0.0-unstable.13771d80a8
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/LICENSE +21 -0
- package/README.md +17 -0
- package/components/AddRichTextEditorNodeType.d.ts +6 -0
- package/components/AddRichTextEditorNodeType.js +28 -0
- package/components/AddRichTextEditorNodeType.js.map +1 -0
- package/components/AddRichTextEditorPlugin.d.ts +12 -0
- package/components/AddRichTextEditorPlugin.js +33 -0
- package/components/AddRichTextEditorPlugin.js.map +1 -0
- package/components/AddToolbarAction.d.ts +7 -0
- package/components/AddToolbarAction.js +33 -0
- package/components/AddToolbarAction.js.map +1 -0
- package/components/Editor/HeadingEditor.d.ts +7 -0
- package/components/Editor/HeadingEditor.js +28 -0
- package/components/Editor/HeadingEditor.js.map +1 -0
- package/components/Editor/ParagraphEditor.d.ts +7 -0
- package/components/Editor/ParagraphEditor.js +30 -0
- package/components/Editor/ParagraphEditor.js.map +1 -0
- package/components/Editor/RichTextEditor.d.ts +25 -0
- package/components/Editor/RichTextEditor.js +112 -0
- package/components/Editor/RichTextEditor.js.map +1 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +7 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +15 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -0
- package/components/LexicalHtmlRenderer.d.ts +11 -0
- package/components/LexicalHtmlRenderer.js +48 -0
- package/components/LexicalHtmlRenderer.js.map +1 -0
- package/components/Toolbar/HeadingToolbar.d.ts +12 -0
- package/components/Toolbar/HeadingToolbar.js +23 -0
- package/components/Toolbar/HeadingToolbar.js.map +1 -0
- package/components/Toolbar/ParagraphToolbar.d.ts +12 -0
- package/components/Toolbar/ParagraphToolbar.js +23 -0
- package/components/Toolbar/ParagraphToolbar.js.map +1 -0
- package/components/Toolbar/Toolbar.css +423 -0
- package/components/Toolbar/Toolbar.d.ts +13 -0
- package/components/Toolbar/Toolbar.js +161 -0
- package/components/Toolbar/Toolbar.js.map +1 -0
- package/components/ToolbarActions/BoldAction.d.ts +5 -0
- package/components/ToolbarActions/BoldAction.js +38 -0
- package/components/ToolbarActions/BoldAction.js.map +1 -0
- package/components/ToolbarActions/BulletListAction.d.ts +5 -0
- package/components/ToolbarActions/BulletListAction.js +89 -0
- package/components/ToolbarActions/BulletListAction.js.map +1 -0
- package/components/ToolbarActions/CodeHighlightAction.d.ts +6 -0
- package/components/ToolbarActions/CodeHighlightAction.js +39 -0
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -0
- package/components/ToolbarActions/FontColorAction.d.ts +11 -0
- package/components/ToolbarActions/FontColorAction.js +88 -0
- package/components/ToolbarActions/FontColorAction.js.map +1 -0
- package/components/ToolbarActions/FontSizeAction.d.ts +2 -0
- package/components/ToolbarActions/FontSizeAction.js +104 -0
- package/components/ToolbarActions/FontSizeAction.js.map +1 -0
- package/components/ToolbarActions/ItalicAction.d.ts +5 -0
- package/components/ToolbarActions/ItalicAction.js +38 -0
- package/components/ToolbarActions/ItalicAction.js.map +1 -0
- package/components/ToolbarActions/LinkAction.d.ts +7 -0
- package/components/ToolbarActions/LinkAction.js +69 -0
- package/components/ToolbarActions/LinkAction.js.map +1 -0
- package/components/ToolbarActions/NumberedListAction.d.ts +5 -0
- package/components/ToolbarActions/NumberedListAction.js +89 -0
- package/components/ToolbarActions/NumberedListAction.js.map +1 -0
- package/components/ToolbarActions/QuoteAction.d.ts +4 -0
- package/components/ToolbarActions/QuoteAction.js +66 -0
- package/components/ToolbarActions/QuoteAction.js.map +1 -0
- package/components/ToolbarActions/UnderlineAction.d.ts +5 -0
- package/components/ToolbarActions/UnderlineAction.js +38 -0
- package/components/ToolbarActions/UnderlineAction.js.map +1 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.d.ts +2 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js +48 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.d.ts +2 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.js +63 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -0
- package/context/FontColorActionContext.d.ts +6 -0
- package/context/FontColorActionContext.js +10 -0
- package/context/FontColorActionContext.js.map +1 -0
- package/context/RichTextEditorContext.d.ts +11 -0
- package/context/RichTextEditorContext.js +29 -0
- package/context/RichTextEditorContext.js.map +1 -0
- package/hooks/useFontColorPicker.d.ts +2 -0
- package/hooks/useFontColorPicker.js +15 -0
- package/hooks/useFontColorPicker.js.map +1 -0
- package/hooks/useRichTextEditor.d.ts +2 -0
- package/hooks/useRichTextEditor.js +15 -0
- package/hooks/useRichTextEditor.js.map +1 -0
- package/images/icons/LICENSE.md +5 -0
- package/images/icons/chat-square-quote.svg +1 -0
- package/images/icons/chevron-down.svg +1 -0
- package/images/icons/code.svg +1 -0
- package/images/icons/font-color.svg +1 -0
- package/images/icons/link.svg +1 -0
- package/images/icons/list-ol.svg +1 -0
- package/images/icons/list-ul.svg +1 -0
- package/images/icons/pencil-fill.svg +1 -0
- package/images/icons/text-center.svg +1 -0
- package/images/icons/text-left.svg +1 -0
- package/images/icons/text-paragraph.svg +1 -0
- package/images/icons/text-right.svg +1 -0
- package/images/icons/type-bold.svg +1 -0
- package/images/icons/type-h1.svg +1 -0
- package/images/icons/type-h2.svg +1 -0
- package/images/icons/type-h3.svg +1 -0
- package/images/icons/type-h4.svg +1 -0
- package/images/icons/type-h5.svg +1 -0
- package/images/icons/type-h6.svg +1 -0
- package/images/icons/type-italic.svg +1 -0
- package/images/icons/type-strikethrough.svg +1 -0
- package/images/icons/type-underline.svg +1 -0
- package/images/icons/unlink_icon.svg +1 -0
- package/index.d.ts +37 -0
- package/index.js +260 -0
- package/index.js.map +1 -0
- package/nodes/FontColorNode.d.ts +43 -0
- package/nodes/FontColorNode.js +127 -0
- package/nodes/FontColorNode.js.map +1 -0
- package/nodes/webinyNodes.d.ts +2 -0
- package/nodes/webinyNodes.js +16 -0
- package/nodes/webinyNodes.js.map +1 -0
- package/package.json +38 -0
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.d.ts +11 -0
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.js +46 -0
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +1 -0
- package/plugins/AutoLinkPlugin/index.d.ts +1 -0
- package/plugins/AutoLinkPlugin/index.js +16 -0
- package/plugins/AutoLinkPlugin/index.js.map +1 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +7 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +28 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -0
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.d.ts +17 -0
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js +88 -0
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +1 -0
- package/plugins/ClickableLinkPlugin/index.d.ts +1 -0
- package/plugins/ClickableLinkPlugin/index.js +16 -0
- package/plugins/ClickableLinkPlugin/index.js.map +1 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.d.ts +1 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +20 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -0
- package/plugins/CodeHighlightPlugin/index.d.ts +1 -0
- package/plugins/CodeHighlightPlugin/index.js +16 -0
- package/plugins/CodeHighlightPlugin/index.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +118 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +7 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +222 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -0
- package/plugins/FloatingLinkEditorPlugin/index.js +16 -0
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -0
- package/plugins/FontColorPlugin/FontColorPlugin.d.ts +2 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js +38 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +8 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js +34 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/index.d.ts +1 -0
- package/plugins/LexicalUpdateStatePlugin/index.js +16 -0
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -0
- package/themes/webinyLexicalTheme.css +422 -0
- package/themes/webinyLexicalTheme.d.ts +7 -0
- package/themes/webinyLexicalTheme.js +86 -0
- package/themes/webinyLexicalTheme.js.map +1 -0
- package/types.d.ts +3 -0
- package/types.js +12 -0
- package/types.js.map +1 -0
- package/ui/Divider.d.ts +2 -0
- package/ui/Divider.js +13 -0
- package/ui/Divider.js.map +1 -0
- package/ui/DropDown.d.ts +26 -0
- package/ui/DropDown.js +173 -0
- package/ui/DropDown.js.map +1 -0
- package/ui/Input.css +32 -0
- package/ui/LinkPreview.css +69 -0
- package/ui/LinkPreview.d.ts +12 -0
- package/ui/LinkPreview.js +101 -0
- package/ui/LinkPreview.js.map +1 -0
- package/ui/Placeholder.css +23 -0
- package/ui/Placeholder.d.ts +13 -0
- package/ui/Placeholder.js +24 -0
- package/ui/Placeholder.js.map +1 -0
- package/ui/TextInput.d.ts +18 -0
- package/ui/TextInput.js +39 -0
- package/ui/TextInput.js.map +1 -0
- package/ui/ToolbarActionDialog.d.ts +12 -0
- package/ui/ToolbarActionDialog.js +107 -0
- package/ui/ToolbarActionDialog.js.map +1 -0
- package/utils/generateInitialLexicalValue.d.ts +5 -0
- package/utils/generateInitialLexicalValue.js +29 -0
- package/utils/generateInitialLexicalValue.js.map +1 -0
- package/utils/getDOMRangeRect.d.ts +10 -0
- package/utils/getDOMRangeRect.js +27 -0
- package/utils/getDOMRangeRect.js.map +1 -0
- package/utils/getSelectedNode.d.ts +2 -0
- package/utils/getSelectedNode.js +30 -0
- package/utils/getSelectedNode.js.map +1 -0
- package/utils/isValidJSON.d.ts +1 -0
- package/utils/isValidJSON.js +18 -0
- package/utils/isValidJSON.js.map +1 -0
- package/utils/isValidLexicalData.d.ts +2 -0
- package/utils/isValidLexicalData.js +24 -0
- package/utils/isValidLexicalData.js.map +1 -0
- package/utils/point.d.ts +21 -0
- package/utils/point.js +77 -0
- package/utils/point.js.map +1 -0
- package/utils/rect.d.ts +47 -0
- package/utils/rect.js +169 -0
- package/utils/rect.js.map +1 -0
- package/utils/sanitizeUrl.d.ts +8 -0
- package/utils/sanitizeUrl.js +27 -0
- package/utils/sanitizeUrl.js.map +1 -0
- package/utils/setFloatingElemPosition.d.ts +3 -0
- package/utils/setFloatingElemPosition.js +40 -0
- package/utils/setFloatingElemPosition.js.map +1 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.BulletListAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
|
+
var _list = require("@lexical/list");
|
|
13
|
+
var _lexical = require("lexical");
|
|
14
|
+
var _utils = require("@lexical/utils");
|
|
15
|
+
/**
|
|
16
|
+
* Toolbar button action. On click will wrap the content in bullet list style.
|
|
17
|
+
*/
|
|
18
|
+
var BulletListAction = function BulletListAction() {
|
|
19
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
20
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
21
|
+
editor = _useLexicalComposerCo2[0];
|
|
22
|
+
var _useState = (0, _react.useState)(editor),
|
|
23
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
24
|
+
activeEditor = _useState2[0],
|
|
25
|
+
setActiveEditor = _useState2[1];
|
|
26
|
+
var _useState3 = (0, _react.useState)(false),
|
|
27
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
28
|
+
isActive = _useState4[0],
|
|
29
|
+
setIsActive = _useState4[1];
|
|
30
|
+
var updateToolbar = (0, _react.useCallback)(function () {
|
|
31
|
+
var selection = (0, _lexical.$getSelection)();
|
|
32
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
33
|
+
var anchorNode = selection.anchor.getNode();
|
|
34
|
+
var element = anchorNode.getKey() === "root" ? anchorNode : (0, _utils.$findMatchingParent)(anchorNode, function (e) {
|
|
35
|
+
var parent = e.getParent();
|
|
36
|
+
return parent !== null && (0, _lexical.$isRootOrShadowRoot)(parent);
|
|
37
|
+
});
|
|
38
|
+
if (element === null) {
|
|
39
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
40
|
+
}
|
|
41
|
+
if ((0, _list.$isListNode)(element)) {
|
|
42
|
+
var parentList = (0, _utils.$getNearestNodeOfType)(anchorNode, _list.ListNode);
|
|
43
|
+
// get the type of the list that is selected with the cursor
|
|
44
|
+
var type = parentList ? parentList.getListType() : element.getListType();
|
|
45
|
+
// set the button as active for numbered list
|
|
46
|
+
if (type === "bullet") {
|
|
47
|
+
setIsActive(true);
|
|
48
|
+
} else {
|
|
49
|
+
setIsActive(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [activeEditor]);
|
|
54
|
+
(0, _react.useEffect)(function () {
|
|
55
|
+
return (0, _utils.mergeRegister)(activeEditor.registerUpdateListener(function (_ref) {
|
|
56
|
+
var editorState = _ref.editorState;
|
|
57
|
+
editorState.read(function () {
|
|
58
|
+
updateToolbar();
|
|
59
|
+
});
|
|
60
|
+
}));
|
|
61
|
+
}, [activeEditor, editor, updateToolbar]);
|
|
62
|
+
(0, _react.useEffect)(function () {
|
|
63
|
+
return editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
|
|
64
|
+
updateToolbar();
|
|
65
|
+
setActiveEditor(newEditor);
|
|
66
|
+
return false;
|
|
67
|
+
}, _lexical.COMMAND_PRIORITY_CRITICAL);
|
|
68
|
+
}, [editor, updateToolbar]);
|
|
69
|
+
var formatBulletList = function formatBulletList() {
|
|
70
|
+
if (!isActive) {
|
|
71
|
+
// will update the active state in the useEffect
|
|
72
|
+
editor.dispatchCommand(_list.INSERT_UNORDERED_LIST_COMMAND, undefined);
|
|
73
|
+
} else {
|
|
74
|
+
editor.dispatchCommand(_list.REMOVE_LIST_COMMAND, undefined);
|
|
75
|
+
// removing will not update correctly the active state, so we need to set to false manually.
|
|
76
|
+
setIsActive(false);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
80
|
+
onClick: function onClick() {
|
|
81
|
+
return formatBulletList();
|
|
82
|
+
},
|
|
83
|
+
className: "popup-item spaced " + (isActive ? "active" : ""),
|
|
84
|
+
"aria-label": "Format text as bullet list"
|
|
85
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
86
|
+
className: "icon bullet-list"
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
89
|
+
exports.BulletListAction = BulletListAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BulletListAction","useLexicalComposerContext","editor","useState","activeEditor","setActiveEditor","isActive","setIsActive","updateToolbar","useCallback","selection","$getSelection","$isRangeSelection","anchorNode","anchor","getNode","element","getKey","$findMatchingParent","e","parent","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","$isListNode","parentList","$getNearestNodeOfType","ListNode","type","getListType","useEffect","mergeRegister","registerUpdateListener","editorState","read","registerCommand","SELECTION_CHANGE_COMMAND","_payload","newEditor","COMMAND_PRIORITY_CRITICAL","formatBulletList","dispatchCommand","INSERT_UNORDERED_LIST_COMMAND","undefined","REMOVE_LIST_COMMAND"],"sources":["BulletListAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport {\n $isListNode,\n INSERT_UNORDERED_LIST_COMMAND,\n ListNode,\n REMOVE_LIST_COMMAND\n} from \"@lexical/list\";\nimport {\n $getSelection,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_CRITICAL,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType, mergeRegister } from \"@lexical/utils\";\n\n/**\n * Toolbar button action. On click will wrap the content in bullet list style.\n */\nexport const BulletListAction = () => {\n const [editor] = useLexicalComposerContext();\n const [activeEditor, setActiveEditor] = useState(editor);\n const [isActive, setIsActive] = useState<boolean>(false);\n\n const updateToolbar = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode();\n let element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n if (element === null) {\n element = anchorNode.getTopLevelElementOrThrow();\n }\n\n if ($isListNode(element)) {\n const parentList = $getNearestNodeOfType<ListNode>(anchorNode, ListNode);\n // get the type of the list that is selected with the cursor\n const type = parentList ? parentList.getListType() : element.getListType();\n // set the button as active for numbered list\n if (type === \"bullet\") {\n setIsActive(true);\n } else {\n setIsActive(false);\n }\n }\n }\n }, [activeEditor]);\n\n useEffect(() => {\n return mergeRegister(\n activeEditor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateToolbar();\n });\n })\n );\n }, [activeEditor, editor, updateToolbar]);\n\n useEffect(() => {\n return editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateToolbar();\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_CRITICAL\n );\n }, [editor, updateToolbar]);\n\n const formatBulletList = () => {\n if (!isActive) {\n // will update the active state in the useEffect\n editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);\n } else {\n editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);\n // removing will not update correctly the active state, so we need to set to false manually.\n setIsActive(false);\n }\n };\n\n return (\n <button\n onClick={() => formatBulletList()}\n className={\"popup-item spaced \" + (isActive ? \"active\" : \"\")}\n aria-label=\"Format text as bullet list\"\n >\n <i className=\"icon bullet-list\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAMA;AAOA;AAEA;AACA;AACA;AACO,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAgB,GAAS;EAClC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAwC,IAAAC,eAAQ,EAACD,MAAM,CAAC;IAAA;IAAjDE,YAAY;IAAEC,eAAe;EACpC,iBAAgC,IAAAF,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAjDG,QAAQ;IAAEC,WAAW;EAE5B,IAAMC,aAAa,GAAG,IAAAC,kBAAW,EAAC,YAAM;IACpC,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;MAC9B,IAAMG,UAAU,GAAGH,SAAS,CAACI,MAAM,CAACC,OAAO,EAAE;MAC7C,IAAIC,OAAO,GACPH,UAAU,CAACI,MAAM,EAAE,KAAK,MAAM,GACxBJ,UAAU,GACV,IAAAK,0BAAmB,EAACL,UAAU,EAA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EM,aAAa,CAAC,CAAC;EAE3B,IAAMgC,gBAAgB,GAAG,SAAnBA,gBAAgB,GAAS;IAC3B,IAAI,CAAClC,QAAQ,EAAE;MACX;MACAJ,MAAM,CAACuC,eAAe,CAACC,mCAA6B,EAAEC,SAAS,CAAC;IACpE,CAAC,MAAM;MACHzC,MAAM,CAACuC,eAAe,CAACG,yBAAmB,EAAED,SAAS,CAAC;MACtD;MACApC,WAAW,CAAC,KAAK,CAAC;IACtB;EACJ,CAAC;EAED,oBACI;IACI,OAAO,EAAE;MAAA,OAAMiC,gBAAgB,EAAE;IAAA,CAAC;IAClC,SAAS,EAAE,oBAAoB,IAAIlC,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC7D,cAAW;EAA4B,gBAEvC;IAAG,SAAS,EAAC;EAAkB,EAAG,CAC7B;AAEjB,CAAC;AAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.CodeHighlightAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
|
+
var _lexical = require("lexical");
|
|
13
|
+
/**
|
|
14
|
+
* Toolbar action. User can highlight the selected text.
|
|
15
|
+
* - Gray background will be visible on selected text after clicking on the button.
|
|
16
|
+
*/
|
|
17
|
+
var CodeHighlightAction = function CodeHighlightAction() {
|
|
18
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
19
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
20
|
+
editor = _useLexicalComposerCo2[0];
|
|
21
|
+
var _useState = (0, _react.useState)(false),
|
|
22
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
23
|
+
isCode = _useState2[0],
|
|
24
|
+
setIsCode = _useState2[1];
|
|
25
|
+
var handleClick = function handleClick() {
|
|
26
|
+
editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "code");
|
|
27
|
+
setIsCode(!isCode);
|
|
28
|
+
};
|
|
29
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
30
|
+
onClick: function onClick() {
|
|
31
|
+
return handleClick();
|
|
32
|
+
},
|
|
33
|
+
className: "popup-item spaced " + (isCode ? "active" : ""),
|
|
34
|
+
"aria-label": "Text code highlight"
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
36
|
+
className: "format code"
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
exports.CodeHighlightAction = CodeHighlightAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CodeHighlightAction","useLexicalComposerContext","editor","useState","isCode","setIsCode","handleClick","dispatchCommand","FORMAT_TEXT_COMMAND"],"sources":["CodeHighlightAction.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\n\n/**\n * Toolbar action. User can highlight the selected text.\n * - Gray background will be visible on selected text after clicking on the button.\n */\nexport const CodeHighlightAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isCode, setIsCode] = useState(false);\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"code\");\n setIsCode(!isCode);\n };\n\n return (\n <button\n onClick={() => handleClick()}\n className={\"popup-item spaced \" + (isCode ? \"active\" : \"\")}\n aria-label=\"Text code highlight\"\n >\n <i className=\"format code\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAmB,GAAS;EACrC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAA4B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAApCC,MAAM;IAAEC,SAAS;EACxB,IAAMC,WAAW,GAAG,SAAdA,WAAW,GAAS;IACtBJ,MAAM,CAACK,eAAe,CAACC,4BAAmB,EAAE,MAAM,CAAC;IACnDH,SAAS,CAAC,CAACD,MAAM,CAAC;EACtB,CAAC;EAED,oBACI;IACI,OAAO,EAAE;MAAA,OAAME,WAAW,EAAE;IAAA,CAAC;IAC7B,SAAS,EAAE,oBAAoB,IAAIF,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAqB,gBAEhC;IAAG,SAAS,EAAC;EAAa,EAAG,CACxB;AAEjB,CAAC;AAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const FontColorPicker: import("@webiny/react-composition").ComposableFC<unknown>;
|
|
3
|
+
interface FontActionColorPicker {
|
|
4
|
+
element: JSX.Element;
|
|
5
|
+
}
|
|
6
|
+
declare const FontActionColorPicker: React.FC<FontActionColorPicker>;
|
|
7
|
+
export interface FontColorAction extends React.FC<unknown> {
|
|
8
|
+
ColorPicker: typeof FontActionColorPicker;
|
|
9
|
+
}
|
|
10
|
+
export declare const FontColorAction: FontColorAction;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.FontColorPicker = exports.FontColorAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
|
+
var _lexical = require("lexical");
|
|
13
|
+
var _reactComposition = require("@webiny/react-composition");
|
|
14
|
+
var _FontColorActionContext = require("../../context/FontColorActionContext");
|
|
15
|
+
var _FontColorNode = require("../../nodes/FontColorNode");
|
|
16
|
+
var _getSelectedNode = require("../../utils/getSelectedNode");
|
|
17
|
+
/*
|
|
18
|
+
* Composable Color Picker component that is mounted on toolbar action.
|
|
19
|
+
* Note: Toa add custom component access trough @see LexicalEditorConfig API
|
|
20
|
+
* */
|
|
21
|
+
var FontColorPicker = (0, _reactComposition.makeComposable)("FontColorPicker", function () {
|
|
22
|
+
(0, _react.useEffect)(function () {
|
|
23
|
+
console.log("Default FontColorPicker, please add your own component");
|
|
24
|
+
}, []);
|
|
25
|
+
return null;
|
|
26
|
+
});
|
|
27
|
+
exports.FontColorPicker = FontColorPicker;
|
|
28
|
+
var FontActionColorPicker = function FontActionColorPicker(_ref) {
|
|
29
|
+
var element = _ref.element;
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_reactComposition.Compose, {
|
|
31
|
+
component: FontColorPicker,
|
|
32
|
+
with: function _with() {
|
|
33
|
+
return function () {
|
|
34
|
+
return element;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var FontColorAction = function FontColorAction() {
|
|
40
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
41
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
42
|
+
editor = _useLexicalComposerCo2[0];
|
|
43
|
+
var _useState = (0, _react.useState)("#000"),
|
|
44
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
45
|
+
fontColor = _useState2[0],
|
|
46
|
+
setFontColor = _useState2[1];
|
|
47
|
+
var setFontColorSelect = (0, _react.useCallback)(function (fontColorValue) {
|
|
48
|
+
setFontColor(fontColorValue);
|
|
49
|
+
}, [fontColor]);
|
|
50
|
+
var onFontColorSelect = (0, _react.useCallback)(function (colorValue, themeColorName) {
|
|
51
|
+
setFontColorSelect(colorValue);
|
|
52
|
+
editor.dispatchCommand(_FontColorNode.ADD_FONT_COLOR_COMMAND, {
|
|
53
|
+
color: colorValue,
|
|
54
|
+
themeColorName: themeColorName
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
var updatePopup = (0, _react.useCallback)(function () {
|
|
58
|
+
editor.getEditorState().read(function () {
|
|
59
|
+
var selection = (0, _lexical.$getSelection)();
|
|
60
|
+
if (!(0, _lexical.$isRangeSelection)(selection)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
var node = (0, _getSelectedNode.getSelectedNode)(selection);
|
|
64
|
+
if ((0, _FontColorNode.$isFontColorNode)(node)) {
|
|
65
|
+
debugger;
|
|
66
|
+
var colorStyle = node.getColorStyle();
|
|
67
|
+
setFontColor(colorStyle.color);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}, [editor]);
|
|
71
|
+
(0, _react.useEffect)(function () {
|
|
72
|
+
document.addEventListener("selectionchange", updatePopup);
|
|
73
|
+
return function () {
|
|
74
|
+
document.removeEventListener("selectionchange", updatePopup);
|
|
75
|
+
};
|
|
76
|
+
}, [updatePopup]);
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement(_FontColorActionContext.FontColorActionContext.Provider, {
|
|
78
|
+
value: {
|
|
79
|
+
value: fontColor,
|
|
80
|
+
applyColor: onFontColorSelect
|
|
81
|
+
}
|
|
82
|
+
}, /*#__PURE__*/_react.default.createElement(FontColorPicker, null));
|
|
83
|
+
};
|
|
84
|
+
exports.FontColorAction = FontColorAction;
|
|
85
|
+
{
|
|
86
|
+
/* Color action settings */
|
|
87
|
+
}
|
|
88
|
+
FontColorAction.ColorPicker = FontActionColorPicker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FontColorPicker","makeComposable","useEffect","console","log","FontActionColorPicker","element","FontColorAction","useLexicalComposerContext","editor","useState","fontColor","setFontColor","setFontColorSelect","useCallback","fontColorValue","onFontColorSelect","colorValue","themeColorName","dispatchCommand","ADD_FONT_COLOR_COMMAND","color","updatePopup","getEditorState","read","selection","$getSelection","$isRangeSelection","node","getSelectedNode","$isFontColorNode","colorStyle","getColorStyle","document","addEventListener","removeEventListener","value","applyColor","ColorPicker"],"sources":["FontColorAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $getSelection, $isRangeSelection, LexicalCommand } from \"lexical\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { FontColorActionContext } from \"~/context/FontColorActionContext\";\nimport { $isFontColorNode, ADD_FONT_COLOR_COMMAND, FontColorPayload } from \"~/nodes/FontColorNode\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\n\n/*\n * Composable Color Picker component that is mounted on toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const FontColorPicker = makeComposable(\"FontColorPicker\", (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default FontColorPicker, please add your own component\");\n }, []);\n return null;\n});\n\ninterface FontActionColorPicker {\n element: JSX.Element;\n}\n\nconst FontActionColorPicker: React.FC<FontActionColorPicker> = ({ element }): JSX.Element => {\n return <Compose component={FontColorPicker} with={() => () => element} />;\n};\n\nexport interface FontColorAction extends React.FC<unknown> {\n ColorPicker: typeof FontActionColorPicker;\n}\n\nexport const FontColorAction: FontColorAction = () => {\n const [editor] = useLexicalComposerContext();\n const [fontColor, setFontColor] = useState<string>(\"#000\");\n\n const setFontColorSelect = useCallback(\n (fontColorValue: string) => {\n setFontColor(fontColorValue);\n },\n [fontColor]\n );\n\n const onFontColorSelect = useCallback(\n (colorValue: string, themeColorName: string | undefined) => {\n setFontColorSelect(colorValue);\n editor.dispatchCommand<LexicalCommand<FontColorPayload>>(ADD_FONT_COLOR_COMMAND, {\n color: colorValue,\n themeColorName\n });\n },\n []\n );\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return;\n }\n const node = getSelectedNode(selection);\n if ($isFontColorNode(node)) {\n debugger;\n const colorStyle = node.getColorStyle();\n setFontColor(colorStyle.color);\n }\n });\n }, [editor]);\n\n useEffect(() => {\n document.addEventListener(\"selectionchange\", updatePopup);\n return () => {\n document.removeEventListener(\"selectionchange\", updatePopup);\n };\n }, [updatePopup]);\n\n return (\n <FontColorActionContext.Provider\n value={{\n value: fontColor,\n applyColor: onFontColorSelect\n }}\n >\n <FontColorPicker />\n </FontColorActionContext.Provider>\n );\n};\n\n{\n /* Color action settings */\n}\nFontColorAction.ColorPicker = FontActionColorPicker;\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACO,IAAMA,eAAe,GAAG,IAAAC,gCAAc,EAAC,iBAAiB,EAAE,YAA0B;EACvF,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,wDAAwD,CAAC;EACzE,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CAAC,CAAC;AAAC;AAMH,IAAMC,qBAAsD,GAAG,SAAzDA,qBAAsD,OAAiC;EAAA,IAA3BC,OAAO,QAAPA,OAAO;EACrE,oBAAO,6BAAC,yBAAO;IAAC,SAAS,EAAEN,eAAgB;IAAC,IAAI,EAAE;MAAA,OAAM;QAAA,OAAMM,OAAO;MAAA;IAAA;EAAC,EAAG;AAC7E,CAAC;AAMM,IAAMC,eAAgC,GAAG,SAAnCA,eAAgC,GAAS;EAClD,4BAAiB,I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AAW,CAAC,CAAC;EAEjB,oBACI,6BAAC,8CAAsB,CAAC,QAAQ;IAC5B,KAAK,EAAE;MACHc,KAAK,EAAEzB,SAAS;MAChB0B,UAAU,EAAErB;IAChB;EAAE,gBAEF,6BAAC,eAAe,OAAG,CACW;AAE1C,CAAC;AAAC;AAEF;EACI;AAAA;AAEJT,eAAe,CAAC+B,WAAW,GAAGjC,qBAAqB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.FontSizeAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
13
|
+
var _selection = require("@lexical/selection");
|
|
14
|
+
var _utils = require("@lexical/utils");
|
|
15
|
+
var _lexical = require("lexical");
|
|
16
|
+
var _DropDown = require("../../ui/DropDown");
|
|
17
|
+
/**
|
|
18
|
+
* Toolbar action. Allow user to change font size for selected text.
|
|
19
|
+
*/
|
|
20
|
+
var FONT_SIZE_OPTIONS = ["8px", "9px", "10px", "11px", "12px", "14px", "15px", "16px", "18px", "21px", "24px", "30px", "36px", "48px", "60px", "72px", "96px"];
|
|
21
|
+
function dropDownActiveClass(active) {
|
|
22
|
+
if (active) {
|
|
23
|
+
return "active dropdown-item-active";
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
function FontSizeDropDown(props) {
|
|
28
|
+
var editor = props.editor,
|
|
29
|
+
value = props.value,
|
|
30
|
+
_props$disabled = props.disabled,
|
|
31
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled;
|
|
32
|
+
var handleClick = (0, _react.useCallback)(function (option) {
|
|
33
|
+
editor.update(function () {
|
|
34
|
+
var selection = (0, _lexical.$getSelection)();
|
|
35
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
36
|
+
(0, _selection.$patchStyleText)(selection, (0, _defineProperty2.default)({}, "font-size", option));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}, [editor]);
|
|
40
|
+
return /*#__PURE__*/_react.default.createElement(_DropDown.DropDown, {
|
|
41
|
+
disabled: disabled,
|
|
42
|
+
buttonClassName: "toolbar-item font-size",
|
|
43
|
+
buttonLabel: value,
|
|
44
|
+
buttonAriaLabel: "Formatting options for font size"
|
|
45
|
+
}, FONT_SIZE_OPTIONS.map(function (option) {
|
|
46
|
+
return /*#__PURE__*/_react.default.createElement(_DropDown.DropDownItem, {
|
|
47
|
+
className: "item fontsize-item ".concat(dropDownActiveClass(value === option)),
|
|
48
|
+
onClick: function onClick() {
|
|
49
|
+
return handleClick(option);
|
|
50
|
+
},
|
|
51
|
+
key: option
|
|
52
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
53
|
+
className: "text"
|
|
54
|
+
}, option));
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
var FontSizeAction = function FontSizeAction() {
|
|
58
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
59
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
60
|
+
editor = _useLexicalComposerCo2[0];
|
|
61
|
+
var _useState = (0, _react.useState)(function () {
|
|
62
|
+
return editor.isEditable();
|
|
63
|
+
}),
|
|
64
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
65
|
+
isEditable = _useState2[0],
|
|
66
|
+
setIsEditable = _useState2[1];
|
|
67
|
+
var _useState3 = (0, _react.useState)(editor),
|
|
68
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
69
|
+
activeEditor = _useState4[0],
|
|
70
|
+
setActiveEditor = _useState4[1];
|
|
71
|
+
var _useState5 = (0, _react.useState)("15px"),
|
|
72
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
73
|
+
fontSize = _useState6[0],
|
|
74
|
+
setFontSize = _useState6[1];
|
|
75
|
+
var updateToolbar = (0, _react.useCallback)(function () {
|
|
76
|
+
var selection = (0, _lexical.$getSelection)();
|
|
77
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
78
|
+
setFontSize((0, _selection.$getSelectionStyleValueForProperty)(selection, "font-size", "15px"));
|
|
79
|
+
}
|
|
80
|
+
}, [activeEditor]);
|
|
81
|
+
(0, _react.useEffect)(function () {
|
|
82
|
+
return (0, _utils.mergeRegister)(editor.registerEditableListener(function (editable) {
|
|
83
|
+
setIsEditable(editable);
|
|
84
|
+
}), activeEditor.registerUpdateListener(function (_ref) {
|
|
85
|
+
var editorState = _ref.editorState;
|
|
86
|
+
editorState.read(function () {
|
|
87
|
+
updateToolbar();
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
}, [activeEditor, editor, updateToolbar]);
|
|
91
|
+
(0, _react.useEffect)(function () {
|
|
92
|
+
return editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
|
|
93
|
+
updateToolbar();
|
|
94
|
+
setActiveEditor(newEditor);
|
|
95
|
+
return false;
|
|
96
|
+
}, _lexical.COMMAND_PRIORITY_CRITICAL);
|
|
97
|
+
}, [editor, updateToolbar]);
|
|
98
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(FontSizeDropDown, {
|
|
99
|
+
disabled: !isEditable,
|
|
100
|
+
value: fontSize,
|
|
101
|
+
editor: editor
|
|
102
|
+
}));
|
|
103
|
+
};
|
|
104
|
+
exports.FontSizeAction = FontSizeAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FONT_SIZE_OPTIONS","dropDownActiveClass","active","FontSizeDropDown","props","editor","value","disabled","handleClick","useCallback","option","update","selection","$getSelection","$isRangeSelection","$patchStyleText","map","FontSizeAction","useLexicalComposerContext","useState","isEditable","setIsEditable","activeEditor","setActiveEditor","fontSize","setFontSize","updateToolbar","$getSelectionStyleValueForProperty","useEffect","mergeRegister","registerEditableListener","editable","registerUpdateListener","editorState","read","registerCommand","SELECTION_CHANGE_COMMAND","_payload","newEditor","COMMAND_PRIORITY_CRITICAL"],"sources":["FontSizeAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $getSelectionStyleValueForProperty, $patchStyleText } from \"@lexical/selection\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_CRITICAL,\n LexicalEditor,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { DropDown, DropDownItem } from \"../../ui/DropDown\";\n\n/**\n * Toolbar action. Allow user to change font size for selected text.\n */\nconst FONT_SIZE_OPTIONS: string[] = [\n \"8px\",\n \"9px\",\n \"10px\",\n \"11px\",\n \"12px\",\n \"14px\",\n \"15px\",\n \"16px\",\n \"18px\",\n \"21px\",\n \"24px\",\n \"30px\",\n \"36px\",\n \"48px\",\n \"60px\",\n \"72px\",\n \"96px\"\n];\n\nfunction dropDownActiveClass(active: boolean) {\n if (active) {\n return \"active dropdown-item-active\";\n }\n return \"\";\n}\n\ninterface FontSizeDropDownProps {\n editor: LexicalEditor;\n value: string;\n disabled?: boolean;\n}\n\nfunction FontSizeDropDown(props: FontSizeDropDownProps): JSX.Element {\n const { editor, value, disabled = false } = props;\n\n const handleClick = useCallback(\n (option: string) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n $patchStyleText(selection, {\n [\"font-size\"]: option\n });\n }\n });\n },\n [editor]\n );\n\n return (\n <DropDown\n disabled={disabled}\n buttonClassName=\"toolbar-item font-size\"\n buttonLabel={value}\n buttonAriaLabel={\"Formatting options for font size\"}\n >\n {FONT_SIZE_OPTIONS.map(option => (\n <DropDownItem\n className={`item fontsize-item ${dropDownActiveClass(value === option)}`}\n onClick={() => handleClick(option)}\n key={option}\n >\n <span className=\"text\">{option}</span>\n </DropDownItem>\n ))}\n </DropDown>\n );\n}\n\nexport const FontSizeAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isEditable, setIsEditable] = useState(() => editor.isEditable());\n const [activeEditor, setActiveEditor] = useState(editor);\n const [fontSize, setFontSize] = useState<string>(\"15px\");\n\n const updateToolbar = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n setFontSize($getSelectionStyleValueForProperty(selection, \"font-size\", \"15px\"));\n }\n }, [activeEditor]);\n\n useEffect(() => {\n return mergeRegister(\n editor.registerEditableListener(editable => {\n setIsEditable(editable);\n }),\n activeEditor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateToolbar();\n });\n })\n );\n }, [activeEditor, editor, updateToolbar]);\n\n useEffect(() => {\n return editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateToolbar();\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_CRITICAL\n );\n }, [editor, updateToolbar]);\n return (\n <>\n <FontSizeDropDown disabled={!isEditable} value={fontSize} editor={editor} />\n </>\n );\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAOA;AAEA;AACA;AACA;AACA,IAAMA,iBAA2B,GAAG,CAChC,KAAK,EACL,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM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qB,aAAa,CAAC,CAAC;EAC3B,oBACI,yEACI,6BAAC,gBAAgB;IAAC,QAAQ,EAAE,CAACN,UAAW;IAAC,KAAK,EAAEI,QAAS;IAAC,MAAM,EAAEnB;EAAO,EAAG,CAC7E;AAEX,CAAC;AAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.ItalicAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
|
+
var _lexical = require("lexical");
|
|
13
|
+
/**
|
|
14
|
+
* Toolbar action. On toolbar, you can see the button that is italic.
|
|
15
|
+
*/
|
|
16
|
+
var ItalicAction = function ItalicAction() {
|
|
17
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
18
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
19
|
+
editor = _useLexicalComposerCo2[0];
|
|
20
|
+
var _useState = (0, _react.useState)(false),
|
|
21
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
22
|
+
isItalic = _useState2[0],
|
|
23
|
+
setIsItalic = _useState2[1];
|
|
24
|
+
var handleClick = function handleClick() {
|
|
25
|
+
editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "italic");
|
|
26
|
+
setIsItalic(!isItalic);
|
|
27
|
+
};
|
|
28
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
29
|
+
onClick: function onClick() {
|
|
30
|
+
return handleClick();
|
|
31
|
+
},
|
|
32
|
+
className: "popup-item spaced " + (isItalic ? "active" : ""),
|
|
33
|
+
"aria-label": "Format text as italic"
|
|
34
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
35
|
+
className: "format italic"
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
38
|
+
exports.ItalicAction = ItalicAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ItalicAction","useLexicalComposerContext","editor","useState","isItalic","setIsItalic","handleClick","dispatchCommand","FORMAT_TEXT_COMMAND"],"sources":["ItalicAction.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\n\n/**\n * Toolbar action. On toolbar, you can see the button that is italic.\n */\nexport const ItalicAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isItalic, setIsItalic] = useState(false);\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"italic\");\n setIsItalic(!isItalic);\n };\n\n return (\n <button\n onClick={() => handleClick()}\n className={\"popup-item spaced \" + (isItalic ? \"active\" : \"\")}\n aria-label=\"Format text as italic\"\n >\n <i className=\"format italic\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AACO,IAAMA,YAAY,GAAG,SAAfA,YAAY,GAAS;EAC9B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAgC,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAAxCC,QAAQ;IAAEC,WAAW;EAC5B,IAAMC,WAAW,GAAG,SAAdA,WAAW,GAAS;IACtBJ,MAAM,CAACK,eAAe,CAACC,4BAAmB,EAAE,QAAQ,CAAC;IACrDH,WAAW,CAAC,CAACD,QAAQ,CAAC;EAC1B,CAAC;EAED,oBACI;IACI,OAAO,EAAE;MAAA,OAAME,WAAW,EAAE;IAAA,CAAC;IAC7B,SAAS,EAAE,oBAAoB,IAAIF,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC7D,cAAW;EAAuB,gBAElC;IAAG,SAAS,EAAC;EAAe,EAAG,CAC1B;AAEjB,CAAC;AAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Toolbar action. User can convert selected text in clickble link.
|
|
4
|
+
* - Small size popup will be opened with input so user can enter the link.
|
|
5
|
+
* - To remove the link, user need to select the already added link and click again in the action button.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LinkAction: () => JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.LinkAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
|
+
var _link = require("@lexical/link");
|
|
13
|
+
var _lexical = require("lexical");
|
|
14
|
+
var _getSelectedNode = require("../../utils/getSelectedNode");
|
|
15
|
+
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
16
|
+
/**
|
|
17
|
+
* Toolbar action. User can convert selected text in clickble link.
|
|
18
|
+
* - Small size popup will be opened with input so user can enter the link.
|
|
19
|
+
* - To remove the link, user need to select the already added link and click again in the action button.
|
|
20
|
+
*/
|
|
21
|
+
var LinkAction = function LinkAction() {
|
|
22
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
23
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
24
|
+
editor = _useLexicalComposerCo2[0];
|
|
25
|
+
var _useState = (0, _react.useState)(false),
|
|
26
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
27
|
+
isLink = _useState2[0],
|
|
28
|
+
setIsLink = _useState2[1];
|
|
29
|
+
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
30
|
+
setNodeIsText = _useRichTextEditor.setNodeIsText;
|
|
31
|
+
var insertLink = (0, _react.useCallback)(function () {
|
|
32
|
+
if (!isLink) {
|
|
33
|
+
editor.dispatchCommand(_link.TOGGLE_LINK_COMMAND, "https://");
|
|
34
|
+
setNodeIsText(false);
|
|
35
|
+
} else {
|
|
36
|
+
editor.dispatchCommand(_link.TOGGLE_LINK_COMMAND, null);
|
|
37
|
+
}
|
|
38
|
+
}, [editor, isLink]);
|
|
39
|
+
var updatePopup = (0, _react.useCallback)(function () {
|
|
40
|
+
editor.getEditorState().read(function () {
|
|
41
|
+
var selection = (0, _lexical.$getSelection)();
|
|
42
|
+
if (!(0, _lexical.$isRangeSelection)(selection)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var node = (0, _getSelectedNode.getSelectedNode)(selection);
|
|
46
|
+
// Update links
|
|
47
|
+
var parent = node.getParent();
|
|
48
|
+
if ((0, _link.$isLinkNode)(parent) || (0, _link.$isLinkNode)(node)) {
|
|
49
|
+
setIsLink(true);
|
|
50
|
+
} else {
|
|
51
|
+
setIsLink(false);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}, [editor]);
|
|
55
|
+
(0, _react.useEffect)(function () {
|
|
56
|
+
document.addEventListener("selectionchange", updatePopup);
|
|
57
|
+
return function () {
|
|
58
|
+
document.removeEventListener("selectionchange", updatePopup);
|
|
59
|
+
};
|
|
60
|
+
}, [updatePopup]);
|
|
61
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
62
|
+
onClick: insertLink,
|
|
63
|
+
className: "popup-item spaced " + (isLink ? "active" : ""),
|
|
64
|
+
"aria-label": "Insert link"
|
|
65
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
66
|
+
className: "format link"
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
exports.LinkAction = LinkAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LinkAction","useLexicalComposerContext","editor","useState","isLink","setIsLink","useRichTextEditor","setNodeIsText","insertLink","useCallback","dispatchCommand","TOGGLE_LINK_COMMAND","updatePopup","getEditorState","read","selection","$getSelection","$isRangeSelection","node","getSelectedNode","parent","getParent","$isLinkNode","useEffect","document","addEventListener","removeEventListener"],"sources":["LinkAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $isLinkNode, TOGGLE_LINK_COMMAND } from \"@lexical/link\";\nimport { $getSelection, $isRangeSelection } from \"lexical\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\n\n/**\n * Toolbar action. User can convert selected text in clickble link.\n * - Small size popup will be opened with input so user can enter the link.\n * - To remove the link, user need to select the already added link and click again in the action button.\n */\nexport const LinkAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isLink, setIsLink] = useState(false);\n const { setNodeIsText } = useRichTextEditor();\n\n const insertLink = useCallback(() => {\n if (!isLink) {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, \"https://\");\n setNodeIsText(false);\n } else {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n }\n }, [editor, isLink]);\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return;\n }\n const node = getSelectedNode(selection);\n // Update links\n const parent = node.getParent();\n if ($isLinkNode(parent) || $isLinkNode(node)) {\n setIsLink(true);\n } else {\n setIsLink(false);\n }\n });\n }, [editor]);\n\n useEffect(() => {\n document.addEventListener(\"selectionchange\", updatePopup);\n return () => {\n document.removeEventListener(\"selectionchange\", updatePopup);\n };\n }, [updatePopup]);\n\n return (\n <button\n onClick={insertLink}\n className={\"popup-item spaced \" + (isLink ? \"active\" : \"\")}\n aria-label=\"Insert link\"\n >\n <i className=\"format link\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMA,UAAU,GAAG,SAAbA,UAAU,GAAS;EAC5B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAA4B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAApCC,MAAM;IAAEC,SAAS;EACxB,yBAA0B,IAAAC,qCAAiB,GAAE;IAArCC,aAAa,sBAAbA,aAAa;EAErB,IAAMC,UAAU,GAAG,IAAAC,kBAAW,EAAC,YAAM;IACjC,IAAI,CAACL,MAAM,EAAE;MACTF,MAAM,CAACQ,eAAe,CAACC,yBAAmB,EAAE,UAAU,CAAC;MACvDJ,aAAa,CAAC,KAAK,CAAC;IACxB,CAAC,MAAM;MACHL,MAAM,CAACQ,eAAe,CAACC,yBAAmB,EAAE,IAAI,CAAC;IACrD;EACJ,CAAC,EAAE,CAACT,MAAM,EAAEE,MAAM,CAAC,CAAC;EAEpB,IAAMQ,WAAW,GAAG,IAAAH,kBAAW,EAAC,YAAM;IAClCP,MAAM,CAACW,cAAc,EAAE,CAACC,IAAI,CAAC,YAAM;MAC/B,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;MACjC,IAAI,CAAC,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;QAC/B;MACJ;MACA,IAAMG,IAAI,GAAG,IAAAC,gCAAe,EAACJ,SAAS,CAAC;MACvC;MACA,IAAMK,MAAM,GAAGF,IAAI,CAACG,SAAS,EAAE;MAC/B,IAAI,IAAAC,iBAAW,EAACF,MAAM,CAAC,IAAI,IAAAE,iBAAW,EAACJ,IAAI,CAAC,EAAE;QAC1Cb,SAAS,CAAC,IAAI,CAAC;MACnB,CAAC,MAAM;QACHA,SAAS,CAAC,KAAK,CAAC;MACpB;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CAACH,MAAM,CAAC,CAAC;EAEZ,IAAAqB,gBAAS,EAAC,YAAM;IACZC,QAAQ,CAACC,gBAAgB,CAAC,iBAAiB,EAAEb,WAAW,CAAC;IACzD,OAAO,YAAM;MACTY,QAAQ,CAACE,mBAAmB,CAAC,iBAAiB,EAAEd,WAAW,CAAC;IAChE,CAAC;EACL,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAEjB,oBACI;IACI,OAAO,EAAEJ,UAAW;IACpB,SAAS,EAAE,oBAAoB,IAAIJ,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAa,gBAExB;IAAG,SAAS,EAAC;EAAa,EAAG,CACxB;AAEjB,CAAC;AAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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.NumberedListAction = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
|
+
var _list = require("@lexical/list");
|
|
13
|
+
var _lexical = require("lexical");
|
|
14
|
+
var _utils = require("@lexical/utils");
|
|
15
|
+
/**
|
|
16
|
+
* Toolbar button action. On click will wrap the content in numbered list style.
|
|
17
|
+
*/
|
|
18
|
+
var NumberedListAction = function NumberedListAction() {
|
|
19
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
20
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
21
|
+
editor = _useLexicalComposerCo2[0];
|
|
22
|
+
var _useState = (0, _react.useState)(editor),
|
|
23
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
24
|
+
activeEditor = _useState2[0],
|
|
25
|
+
setActiveEditor = _useState2[1];
|
|
26
|
+
var _useState3 = (0, _react.useState)(false),
|
|
27
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
28
|
+
isActive = _useState4[0],
|
|
29
|
+
setIsActive = _useState4[1];
|
|
30
|
+
var updateToolbar = (0, _react.useCallback)(function () {
|
|
31
|
+
var selection = (0, _lexical.$getSelection)();
|
|
32
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
33
|
+
var anchorNode = selection.anchor.getNode();
|
|
34
|
+
var element = anchorNode.getKey() === "root" ? anchorNode : (0, _utils.$findMatchingParent)(anchorNode, function (e) {
|
|
35
|
+
var parent = e.getParent();
|
|
36
|
+
return parent !== null && (0, _lexical.$isRootOrShadowRoot)(parent);
|
|
37
|
+
});
|
|
38
|
+
if (element === null) {
|
|
39
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
40
|
+
}
|
|
41
|
+
if ((0, _list.$isListNode)(element)) {
|
|
42
|
+
var parentList = (0, _utils.$getNearestNodeOfType)(anchorNode, _list.ListNode);
|
|
43
|
+
// get the type of the list that is selected with the cursor
|
|
44
|
+
var type = parentList ? parentList.getListType() : element.getListType();
|
|
45
|
+
// set the button as active for numbered list
|
|
46
|
+
if (type === "number") {
|
|
47
|
+
setIsActive(true);
|
|
48
|
+
} else {
|
|
49
|
+
setIsActive(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [activeEditor]);
|
|
54
|
+
(0, _react.useEffect)(function () {
|
|
55
|
+
return (0, _utils.mergeRegister)(activeEditor.registerUpdateListener(function (_ref) {
|
|
56
|
+
var editorState = _ref.editorState;
|
|
57
|
+
editorState.read(function () {
|
|
58
|
+
updateToolbar();
|
|
59
|
+
});
|
|
60
|
+
}));
|
|
61
|
+
}, [activeEditor, editor, updateToolbar]);
|
|
62
|
+
(0, _react.useEffect)(function () {
|
|
63
|
+
return editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
|
|
64
|
+
updateToolbar();
|
|
65
|
+
setActiveEditor(newEditor);
|
|
66
|
+
return false;
|
|
67
|
+
}, _lexical.COMMAND_PRIORITY_CRITICAL);
|
|
68
|
+
}, [editor, updateToolbar]);
|
|
69
|
+
var formatNumberedList = function formatNumberedList() {
|
|
70
|
+
if (!isActive) {
|
|
71
|
+
// will update the active state in the useEffect
|
|
72
|
+
editor.dispatchCommand(_list.INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
73
|
+
} else {
|
|
74
|
+
editor.dispatchCommand(_list.REMOVE_LIST_COMMAND, undefined);
|
|
75
|
+
// removing will not update correctly the active state, so we need to set to false manually.
|
|
76
|
+
setIsActive(false);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
80
|
+
onClick: function onClick() {
|
|
81
|
+
return formatNumberedList();
|
|
82
|
+
},
|
|
83
|
+
className: "popup-item spaced " + (isActive ? "active" : ""),
|
|
84
|
+
"aria-label": "Format text as numbered list"
|
|
85
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
86
|
+
className: "icon numbered-list"
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
89
|
+
exports.NumberedListAction = NumberedListAction;
|