@webiny/lexical-editor 5.36.1 → 5.37.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/webiny-list.d.ts +1 -1
- package/commands/webiny-list.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +2 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +3 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/Toolbar/Toolbar.css +12 -0
- package/components/Toolbar/Toolbar.js +83 -49
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +7 -2
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/FontSizeAction.js +1 -1
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +7 -2
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +3 -2
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.d.ts +11 -0
- package/components/ToolbarActions/TextAlignmentAction.js +70 -0
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js +4 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -1
- package/components/ToolbarPresets/ParagraphToolbarPreset.js +4 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -1
- package/context/RichTextEditorContext.d.ts +5 -0
- package/context/RichTextEditorContext.js +17 -5
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.d.ts +9 -0
- package/context/TextAlignmentActionContextProps.js +10 -0
- package/context/TextAlignmentActionContextProps.js.map +1 -0
- package/hooks/useList.d.ts +2 -0
- package/hooks/{useWebinyList.js → useList.js} +3 -3
- package/hooks/useList.js.map +1 -0
- package/hooks/useTextAlignmentAction.d.ts +1 -0
- package/hooks/useTextAlignmentAction.js +15 -0
- package/hooks/useTextAlignmentAction.js.map +1 -0
- package/images/icons/indent.svg +3 -0
- package/images/icons/justify.svg +3 -0
- package/images/icons/outdent.svg +3 -0
- package/index.d.ts +2 -0
- package/index.js +14 -0
- package/index.js.map +1 -1
- package/nodes/{list-node/WebinyListItemNode.d.ts → ListItemNode.d.ts} +7 -7
- package/nodes/{list-node/WebinyListItemNode.js → ListItemNode.js} +49 -50
- package/nodes/ListItemNode.js.map +1 -0
- package/nodes/{list-node → ListNode}/formatList.d.ts +6 -6
- package/nodes/{list-node → ListNode}/formatList.js +38 -38
- package/nodes/ListNode/formatList.js.map +1 -0
- package/nodes/{list-node/WebinyListNode.d.ts → ListNode.d.ts} +11 -7
- package/nodes/{list-node/WebinyListNode.js → ListNode.js} +70 -29
- package/nodes/ListNode.js.map +1 -0
- package/nodes/webinyNodes.js +3 -3
- package/nodes/webinyNodes.js.map +1 -1
- package/package.json +5 -5
- package/plugins/WebinyListPLugin/WebinyListPlugin.js +5 -5
- package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +1 -1
- package/types.d.ts +2 -0
- package/types.js.map +1 -1
- package/utils/getLexicalTextSelectionState.js +9 -3
- package/utils/getLexicalTextSelectionState.js.map +1 -1
- package/utils/nodes/listNode.d.ts +11 -0
- package/utils/nodes/{list-node.js → listNode.js} +13 -13
- package/utils/nodes/listNode.js.map +1 -0
- package/hooks/useWebinyList.d.ts +0 -2
- package/hooks/useWebinyList.js.map +0 -1
- package/nodes/list-node/WebinyListItemNode.js.map +0 -1
- package/nodes/list-node/WebinyListNode.js.map +0 -1
- package/nodes/list-node/formatList.js.map +0 -1
- package/utils/nodes/list-node.d.ts +0 -11
- package/utils/nodes/list-node.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LexicalCommand } from "lexical";
|
|
2
2
|
export declare type WebinyListCommandPayload = {
|
|
3
|
-
themeStyleId
|
|
3
|
+
themeStyleId?: string;
|
|
4
4
|
};
|
|
5
5
|
export declare const INSERT_UNORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload>;
|
|
6
6
|
export declare const INSERT_ORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["INSERT_UNORDERED_WEBINY_LIST_COMMAND","createCommand","INSERT_ORDERED_WEBINY_LIST_COMMAND","REMOVE_WEBINY_LIST_COMMAND"],"sources":["webiny-list.ts"],"sourcesContent":["import { createCommand, LexicalCommand } from \"lexical\";\n\nexport type WebinyListCommandPayload = {\n themeStyleId
|
|
1
|
+
{"version":3,"names":["INSERT_UNORDERED_WEBINY_LIST_COMMAND","createCommand","INSERT_ORDERED_WEBINY_LIST_COMMAND","REMOVE_WEBINY_LIST_COMMAND"],"sources":["webiny-list.ts"],"sourcesContent":["import { createCommand, LexicalCommand } from \"lexical\";\n\nexport type WebinyListCommandPayload = {\n themeStyleId?: string;\n};\n\nexport const INSERT_UNORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload> =\n createCommand(\"INSERT_UNORDERED_WEBINY_LIST_COMMAND\");\nexport const INSERT_ORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload> =\n createCommand(\"INSERT_ORDERED_WEBINY_LIST_COMMAND\");\n\nexport const REMOVE_WEBINY_LIST_COMMAND: LexicalCommand<void> = createCommand(\n \"REMOVE_WEBINY_LIST_COMMAND\"\n);\n"],"mappings":";;;;;;AAAA;AAMO,IAAMA,oCAA8E,GACvF,IAAAC,sBAAa,EAAC,sCAAsC,CAAC;AAAC;AACnD,IAAMC,kCAA4E,GACrF,IAAAD,sBAAa,EAAC,oCAAoC,CAAC;AAAC;AAEjD,IAAME,0BAAgD,GAAG,IAAAF,sBAAa,EACzE,4BAA4B,CAC/B;AAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { FontColorAction } from "../ToolbarActions/FontColorAction";
|
|
3
3
|
import { TypographyAction } from "../ToolbarActions/TypographyAction";
|
|
4
|
+
import { TextAlignmentAction } from "../ToolbarActions/TextAlignmentAction";
|
|
4
5
|
interface LexicalEditorConfig extends React.FC<unknown> {
|
|
5
6
|
FontColorAction: typeof FontColorAction;
|
|
6
7
|
TypographyAction: typeof TypographyAction;
|
|
8
|
+
TextAlignmentAction: typeof TextAlignmentAction;
|
|
7
9
|
}
|
|
8
10
|
export declare const LexicalEditorConfig: LexicalEditorConfig;
|
|
9
11
|
export {};
|
|
@@ -8,10 +8,12 @@ exports.LexicalEditorConfig = void 0;
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _FontColorAction = require("../ToolbarActions/FontColorAction");
|
|
10
10
|
var _TypographyAction = require("../ToolbarActions/TypographyAction");
|
|
11
|
+
var _TextAlignmentAction = require("../ToolbarActions/TextAlignmentAction");
|
|
11
12
|
var LexicalEditorConfig = function LexicalEditorConfig(_ref) {
|
|
12
13
|
var children = _ref.children;
|
|
13
14
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
14
15
|
};
|
|
15
16
|
exports.LexicalEditorConfig = LexicalEditorConfig;
|
|
16
17
|
LexicalEditorConfig.FontColorAction = _FontColorAction.FontColorAction;
|
|
17
|
-
LexicalEditorConfig.TypographyAction = _TypographyAction.TypographyAction;
|
|
18
|
+
LexicalEditorConfig.TypographyAction = _TypographyAction.TypographyAction;
|
|
19
|
+
LexicalEditorConfig.TextAlignmentAction = _TextAlignmentAction.TextAlignmentAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LexicalEditorConfig","children","FontColorAction","TypographyAction"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React from \"react\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\n\ninterface LexicalEditorConfig extends React.FC<unknown> {\n FontColorAction: typeof FontColorAction;\n TypographyAction: typeof TypographyAction;\n}\n\nexport const LexicalEditorConfig: LexicalEditorConfig = ({ children }) => {\n return <>{children}</>;\n};\n\nLexicalEditorConfig.FontColorAction = FontColorAction;\nLexicalEditorConfig.TypographyAction = TypographyAction;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;
|
|
1
|
+
{"version":3,"names":["LexicalEditorConfig","children","FontColorAction","TypographyAction","TextAlignmentAction"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React from \"react\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\nimport { TextAlignmentAction } from \"../ToolbarActions/TextAlignmentAction\";\n\ninterface LexicalEditorConfig extends React.FC<unknown> {\n FontColorAction: typeof FontColorAction;\n TypographyAction: typeof TypographyAction;\n TextAlignmentAction: typeof TextAlignmentAction;\n}\n\nexport const LexicalEditorConfig: LexicalEditorConfig = ({ children }) => {\n return <>{children}</>;\n};\n\nLexicalEditorConfig.FontColorAction = FontColorAction;\nLexicalEditorConfig.TypographyAction = TypographyAction;\nLexicalEditorConfig.TextAlignmentAction = TextAlignmentAction;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAQO,IAAMA,mBAAwC,GAAG,SAA3CA,mBAAwC,OAAqB;EAAA,IAAfC,QAAQ,QAARA,QAAQ;EAC/D,oBAAO,4DAAGA,QAAQ,CAAI;AAC1B,CAAC;AAAC;AAEFD,mBAAmB,CAACE,eAAe,GAAGA,gCAAe;AACrDF,mBAAmB,CAACG,gBAAgB,GAAGA,kCAAgB;AACvDH,mBAAmB,CAACI,mBAAmB,GAAGA,wCAAmB"}
|
|
@@ -169,6 +169,18 @@ i.right-align {
|
|
|
169
169
|
background-image: url("../../images/icons/text-right.svg");
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
i.indent {
|
|
173
|
+
background-image: url("../../images/icons/indent.svg");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
i.outdent {
|
|
177
|
+
background-image: url("../../images/icons/outdent.svg");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
i.justify-align {
|
|
181
|
+
background-image: url("../../images/icons/justify.svg");
|
|
182
|
+
}
|
|
183
|
+
|
|
172
184
|
i.chevron-down {
|
|
173
185
|
background-color: transparent;
|
|
174
186
|
background-size: contain;
|
|
@@ -10,15 +10,12 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _lexical = require("lexical");
|
|
12
12
|
var _reactComposition = require("@webiny/react-composition");
|
|
13
|
-
var _link = require("@lexical/link");
|
|
14
13
|
var _reactDom = require("react-dom");
|
|
15
14
|
var _utils = require("@lexical/utils");
|
|
16
|
-
var _code = require("@lexical/code");
|
|
17
15
|
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
18
16
|
require("./Toolbar.css");
|
|
19
17
|
var _getDOMRangeRect = require("../../utils/getDOMRangeRect");
|
|
20
18
|
var _setFloatingElemPosition = require("../../utils/setFloatingElemPosition");
|
|
21
|
-
var _getSelectedNode = require("../../utils/getSelectedNode");
|
|
22
19
|
var _useRichTextEditor3 = require("../../hooks/useRichTextEditor");
|
|
23
20
|
var _getLexicalTextSelectionState = require("../../utils/getLexicalTextSelectionState");
|
|
24
21
|
var FloatingToolbar = function FloatingToolbar(_ref) {
|
|
@@ -29,17 +26,48 @@ var FloatingToolbar = function FloatingToolbar(_ref) {
|
|
|
29
26
|
var popupCharStylesEditorRef = (0, _react.useRef)(null);
|
|
30
27
|
var _useRichTextEditor = (0, _useRichTextEditor3.useRichTextEditor)(),
|
|
31
28
|
toolbarType = _useRichTextEditor.toolbarType,
|
|
32
|
-
setToolbarType = _useRichTextEditor.setToolbarType
|
|
33
|
-
setTextBlockSelection = _useRichTextEditor.setTextBlockSelection;
|
|
34
|
-
var _useState = (0, _react.useState)(editor),
|
|
35
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
36
|
-
activeEditor = _useState2[0],
|
|
37
|
-
setActiveEditor = _useState2[1];
|
|
29
|
+
setToolbarType = _useRichTextEditor.setToolbarType;
|
|
38
30
|
(0, _react.useEffect)(function () {
|
|
39
31
|
if (toolbarType !== type) {
|
|
40
32
|
setToolbarType(type);
|
|
41
33
|
}
|
|
42
34
|
}, [type]);
|
|
35
|
+
var mouseMoveListener = (0, _react.useCallback)(function (e) {
|
|
36
|
+
/* Indicates which mouse button(s) was pressed.
|
|
37
|
+
/ 1 = mouse left button
|
|
38
|
+
/ 3 = mouse left and right button in the same time
|
|
39
|
+
/ More info: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
40
|
+
*/
|
|
41
|
+
if (popupCharStylesEditorRef !== null && popupCharStylesEditorRef !== void 0 && popupCharStylesEditorRef.current && (e.buttons === 1 || e.buttons === 3)) {
|
|
42
|
+
if (popupCharStylesEditorRef.current.style.pointerEvents !== "none") {
|
|
43
|
+
var x = e.clientX;
|
|
44
|
+
var y = e.clientY;
|
|
45
|
+
var elementUnderMouse = document.elementFromPoint(x, y);
|
|
46
|
+
if (!popupCharStylesEditorRef.current.contains(elementUnderMouse)) {
|
|
47
|
+
// Mouse is not over the target element => not a normal click, but probably a drag
|
|
48
|
+
popupCharStylesEditorRef.current.style.pointerEvents = "none";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, [popupCharStylesEditorRef]);
|
|
53
|
+
var mouseUpListener = (0, _react.useCallback)(function () {
|
|
54
|
+
if (popupCharStylesEditorRef !== null && popupCharStylesEditorRef !== void 0 && popupCharStylesEditorRef.current) {
|
|
55
|
+
if (popupCharStylesEditorRef.current.style.pointerEvents !== "auto") {
|
|
56
|
+
popupCharStylesEditorRef.current.style.pointerEvents = "auto";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, [popupCharStylesEditorRef]);
|
|
60
|
+
(0, _react.useEffect)(function () {
|
|
61
|
+
if (popupCharStylesEditorRef !== null && popupCharStylesEditorRef !== void 0 && popupCharStylesEditorRef.current) {
|
|
62
|
+
document.addEventListener("mousemove", mouseMoveListener);
|
|
63
|
+
document.addEventListener("mouseup", mouseUpListener);
|
|
64
|
+
return function () {
|
|
65
|
+
document.removeEventListener("mousemove", mouseMoveListener);
|
|
66
|
+
document.removeEventListener("mouseup", mouseUpListener);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}, [popupCharStylesEditorRef]);
|
|
43
71
|
var updateTextFormatFloatingToolbar = (0, _react.useCallback)(function () {
|
|
44
72
|
var selection = (0, _lexical.$getSelection)();
|
|
45
73
|
var popupCharStylesEditorElem = popupCharStylesEditorRef.current;
|
|
@@ -47,21 +75,8 @@ var FloatingToolbar = function FloatingToolbar(_ref) {
|
|
|
47
75
|
if (popupCharStylesEditorElem === null) {
|
|
48
76
|
return;
|
|
49
77
|
}
|
|
50
|
-
var isLink = false;
|
|
51
|
-
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
52
|
-
var selectionState = (0, _getLexicalTextSelectionState.getLexicalTextSelectionState)(activeEditor, selection);
|
|
53
|
-
if (selectionState) {
|
|
54
|
-
setTextBlockSelection(selectionState);
|
|
55
|
-
}
|
|
56
|
-
var node = (0, _getSelectedNode.getSelectedNode)(selection);
|
|
57
|
-
// Update links
|
|
58
|
-
var parent = node.getParent();
|
|
59
|
-
if ((0, _link.$isLinkNode)(parent) || (0, _link.$isLinkNode)(node)) {
|
|
60
|
-
isLink = true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
78
|
var rootElement = editor.getRootElement();
|
|
64
|
-
if (selection !== null && nativeSelection !== null && !nativeSelection.isCollapsed && rootElement !== null && rootElement.contains(nativeSelection.anchorNode)
|
|
79
|
+
if (selection !== null && nativeSelection !== null && !nativeSelection.isCollapsed && rootElement !== null && rootElement.contains(nativeSelection.anchorNode)) {
|
|
65
80
|
var rangeRect = (0, _getDOMRangeRect.getDOMRangeRect)(nativeSelection, rootElement);
|
|
66
81
|
(0, _setFloatingElemPosition.setFloatingElemPosition)(rangeRect, popupCharStylesEditorElem, anchorElem);
|
|
67
82
|
}
|
|
@@ -93,9 +108,8 @@ var FloatingToolbar = function FloatingToolbar(_ref) {
|
|
|
93
108
|
editorState.read(function () {
|
|
94
109
|
updateTextFormatFloatingToolbar();
|
|
95
110
|
});
|
|
96
|
-
}), editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (
|
|
111
|
+
}), editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function () {
|
|
97
112
|
updateTextFormatFloatingToolbar();
|
|
98
|
-
setActiveEditor(newEditor);
|
|
99
113
|
return false;
|
|
100
114
|
}, _lexical.COMMAND_PRIORITY_LOW));
|
|
101
115
|
}, [editor, updateTextFormatFloatingToolbar]);
|
|
@@ -112,46 +126,66 @@ var useToolbar = function useToolbar(_ref3) {
|
|
|
112
126
|
children = _ref3.children;
|
|
113
127
|
var _useRichTextEditor2 = (0, _useRichTextEditor3.useRichTextEditor)(),
|
|
114
128
|
nodeIsText = _useRichTextEditor2.nodeIsText,
|
|
115
|
-
setNodeIsText = _useRichTextEditor2.setNodeIsText
|
|
116
|
-
|
|
129
|
+
setNodeIsText = _useRichTextEditor2.setNodeIsText,
|
|
130
|
+
setActiveEditor = _useRichTextEditor2.setActiveEditor,
|
|
131
|
+
setIsEditable = _useRichTextEditor2.setIsEditable,
|
|
132
|
+
setTextBlockSelection = _useRichTextEditor2.setTextBlockSelection;
|
|
133
|
+
var _useState = (0, _react.useState)(editor),
|
|
134
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
135
|
+
toolbarActiveEditor = _useState2[0],
|
|
136
|
+
setToolbarActiveEditor = _useState2[1];
|
|
137
|
+
var updateToolbar = (0, _react.useCallback)(function () {
|
|
117
138
|
editor.getEditorState().read(function () {
|
|
118
139
|
// Should not to pop up the floating toolbar when using IME input
|
|
119
140
|
if (editor.isComposing()) {
|
|
120
141
|
return;
|
|
121
142
|
}
|
|
122
143
|
var selection = (0, _lexical.$getSelection)();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
144
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
145
|
+
var selectionState = (0, _getLexicalTextSelectionState.getLexicalTextSelectionState)(toolbarActiveEditor, selection);
|
|
146
|
+
if (selectionState) {
|
|
147
|
+
setTextBlockSelection(selectionState);
|
|
148
|
+
if (selectionState.selectedText !== "") {
|
|
149
|
+
setNodeIsText(true);
|
|
150
|
+
} else {
|
|
151
|
+
setNodeIsText(false);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
128
154
|
}
|
|
129
155
|
if (!(0, _lexical.$isRangeSelection)(selection)) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
var node = (0, _getSelectedNode.getSelectedNode)(selection);
|
|
133
|
-
if (!(0, _code.$isCodeHighlightNode)(selection.anchor.getNode()) && selection.getTextContent() !== "") {
|
|
134
|
-
setNodeIsText((0, _lexical.$isTextNode)(node));
|
|
135
|
-
} else {
|
|
136
156
|
setNodeIsText(false);
|
|
157
|
+
return;
|
|
137
158
|
}
|
|
138
159
|
});
|
|
139
|
-
}, [
|
|
160
|
+
}, [toolbarActiveEditor]);
|
|
140
161
|
(0, _react.useEffect)(function () {
|
|
141
|
-
document.addEventListener("selectionchange",
|
|
162
|
+
document.addEventListener("selectionchange", updateToolbar);
|
|
142
163
|
return function () {
|
|
143
|
-
document.removeEventListener("selectionchange",
|
|
164
|
+
document.removeEventListener("selectionchange", updateToolbar);
|
|
144
165
|
};
|
|
145
|
-
}, [
|
|
166
|
+
}, [updateToolbar]);
|
|
167
|
+
(0, _react.useEffect)(function () {
|
|
168
|
+
return editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
|
|
169
|
+
updateToolbar();
|
|
170
|
+
setToolbarActiveEditor(newEditor);
|
|
171
|
+
setActiveEditor(newEditor);
|
|
172
|
+
return false;
|
|
173
|
+
}, _lexical.COMMAND_PRIORITY_CRITICAL);
|
|
174
|
+
}, [editor, updateToolbar]);
|
|
146
175
|
(0, _react.useEffect)(function () {
|
|
147
|
-
return (0, _utils.mergeRegister)(editor.
|
|
148
|
-
|
|
176
|
+
return (0, _utils.mergeRegister)(editor.registerEditableListener(function (editable) {
|
|
177
|
+
setIsEditable(editable);
|
|
178
|
+
}), toolbarActiveEditor.registerUpdateListener(function (_ref4) {
|
|
179
|
+
var editorState = _ref4.editorState;
|
|
180
|
+
editorState.read(function () {
|
|
181
|
+
updateToolbar();
|
|
182
|
+
});
|
|
149
183
|
}), editor.registerRootListener(function () {
|
|
150
184
|
if (editor.getRootElement() === null) {
|
|
151
185
|
setNodeIsText(false);
|
|
152
186
|
}
|
|
153
187
|
}));
|
|
154
|
-
}, [editor,
|
|
188
|
+
}, [updateToolbar, editor, toolbarActiveEditor]);
|
|
155
189
|
if (!nodeIsText) {
|
|
156
190
|
return null;
|
|
157
191
|
}
|
|
@@ -164,10 +198,10 @@ var useToolbar = function useToolbar(_ref3) {
|
|
|
164
198
|
/**
|
|
165
199
|
* @description Main toolbar container
|
|
166
200
|
*/
|
|
167
|
-
var Toolbar = (0, _reactComposition.makeComposable)("Toolbar", function (
|
|
168
|
-
var anchorElem =
|
|
169
|
-
type =
|
|
170
|
-
children =
|
|
201
|
+
var Toolbar = (0, _reactComposition.makeComposable)("Toolbar", function (_ref5) {
|
|
202
|
+
var anchorElem = _ref5.anchorElem,
|
|
203
|
+
type = _ref5.type,
|
|
204
|
+
children = _ref5.children;
|
|
171
205
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
172
206
|
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
173
207
|
editor = _useLexicalComposerCo2[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FloatingToolbar","children","type","anchorElem","editor","popupCharStylesEditorRef","useRef","useRichTextEditor","toolbarType","setToolbarType","setTextBlockSelection","useState","activeEditor","setActiveEditor","useEffect","updateTextFormatFloatingToolbar","useCallback","selection","$getSelection","popupCharStylesEditorElem","current","nativeSelection","window","getSelection","isLink","$isRangeSelection","selectionState","getLexicalTextSelectionState","node","getSelectedNode","parent","getParent","$isLinkNode","rootElement","getRootElement","isCollapsed","contains","anchorNode","rangeRect","getDOMRangeRect","setFloatingElemPosition","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","mergeRegister","registerUpdateListener","editorState","registerCommand","SELECTION_CHANGE_COMMAND","_payload","newEditor","COMMAND_PRIORITY_LOW","isEditable","useToolbar","document","body","nodeIsText","setNodeIsText","updatePopup","isComposing","$isCodeHighlightNode","anchor","getNode","getTextContent","$isTextNode","registerRootListener","createPortal","Toolbar","makeComposable","useLexicalComposerContext"],"sources":["Toolbar.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useRef, useState } from \"react\";\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n LexicalEditor,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { createPortal } from \"react-dom\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { $isCodeHighlightNode } from \"@lexical/code\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport \"./Toolbar.css\";\nimport { ToolbarType } from \"~/types\";\nimport { getDOMRangeRect } from \"~/utils/getDOMRangeRect\";\nimport { setFloatingElemPosition } from \"~/utils/setFloatingElemPosition\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { getLexicalTextSelectionState } from \"~/utils/getLexicalTextSelectionState\";\n\ninterface FloatingToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n editor: LexicalEditor;\n}\n\nconst FloatingToolbar: FC<FloatingToolbarProps> = ({ children, type, anchorElem, editor }) => {\n const popupCharStylesEditorRef = useRef<HTMLDivElement | null>(null);\n const { toolbarType, setToolbarType, setTextBlockSelection } = useRichTextEditor();\n const [activeEditor, setActiveEditor] = useState(editor);\n\n useEffect(() => {\n if (toolbarType !== type) {\n setToolbarType(type);\n }\n }, [type]);\n\n const updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection();\n\n const popupCharStylesEditorElem = popupCharStylesEditorRef.current;\n const nativeSelection = window.getSelection();\n\n if (popupCharStylesEditorElem === null) {\n return;\n }\n\n let isLink = false;\n if ($isRangeSelection(selection)) {\n const selectionState = getLexicalTextSelectionState(activeEditor, selection);\n if (selectionState) {\n setTextBlockSelection(selectionState);\n }\n const node = getSelectedNode(selection);\n // Update links\n const parent = node.getParent();\n\n if ($isLinkNode(parent) || $isLinkNode(node)) {\n isLink = true;\n }\n }\n\n const rootElement = editor.getRootElement();\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode) &&\n !isLink\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement);\n setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);\n }\n }, [editor, anchorElem]);\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement;\n\n const update = () => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n };\n\n window.addEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.addEventListener(\"scroll\", update);\n }\n\n return () => {\n window.removeEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.removeEventListener(\"scroll\", update);\n }\n };\n }, [editor, updateTextFormatFloatingToolbar, anchorElem]);\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateTextFormatFloatingToolbar();\n });\n }),\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateTextFormatFloatingToolbar();\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor, updateTextFormatFloatingToolbar]);\n\n return (\n <div ref={popupCharStylesEditorRef} className=\"floating-text-format-popup\">\n {editor.isEditable() && children}\n </div>\n );\n};\n\ninterface useToolbarProps {\n editor: LexicalEditor;\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\nconst useToolbar: FC<useToolbarProps> = ({\n editor,\n anchorElem = document.body,\n type,\n children\n}): JSX.Element | null => {\n const { nodeIsText, setNodeIsText } = useRichTextEditor();\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return;\n }\n const selection = $getSelection();\n const nativeSelection = window.getSelection();\n const rootElement = editor.getRootElement();\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setNodeIsText(false);\n return;\n }\n\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n const node = getSelectedNode(selection);\n if (\n !$isCodeHighlightNode(selection.anchor.getNode()) &&\n selection.getTextContent() !== \"\"\n ) {\n setNodeIsText($isTextNode(node));\n } else {\n setNodeIsText(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 useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup();\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setNodeIsText(false);\n }\n })\n );\n }, [editor, updatePopup]);\n\n if (!nodeIsText) {\n return null;\n }\n\n return createPortal(\n <FloatingToolbar type={type} anchorElem={anchorElem} editor={editor}>\n {children}\n </FloatingToolbar>,\n anchorElem\n );\n};\n\nexport interface ToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\n/**\n * @description Main toolbar container\n */\nexport const Toolbar = makeComposable<ToolbarProps>(\n \"Toolbar\",\n ({ anchorElem, type, children }): JSX.Element | null => {\n const [editor] = useLexicalComposerContext();\n return useToolbar({ editor, anchorElem, type, children });\n }\n);\n"],"mappings":";;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AASA,IAAMA,eAAyC,GAAG,SAA5CA,eAAyC,OAA+C;EAAA,IAAzCC,QAAQ,QAARA,QAAQ;IAAEC,IAAI,QAAJA,IAAI;IAAEC,UAAU,QAAVA,UAAU;IAAEC,MAAM,QAANA,MAAM;EACnF,IAAMC,wBAAwB,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EACpE,yBAA+D,IAAAC,qCAAiB,GAAE;IAA1EC,WAAW,sBAAXA,WAAW;IAAEC,cAAc,sBAAdA,cAAc;IAAEC,qBAAqB,sBAArBA,qBAAqB;EAC1D,gBAAwC,IAAAC,eAAQ,EAACP,MAAM,CAAC;IAAA;IAAjDQ,YAAY;IAAEC,eAAe;EAEpC,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAIN,WAAW,KAAKN,IAAI,EAAE;MACtBO,cAAc,CAACP,IAAI,CAAC;IACxB;EACJ,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,IAAMa,+BAA+B,GAAG,IAAAC,kBAAW,EAAC,YAAM;IACtD,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IAEjC,IAAMC,yBAAyB,GAAGd,wBAAwB,CAACe,OAAO;IAClE,IAAMC,eAAe,GAAGC,MAAM,CAACC,YAAY,EAAE;IAE7C,IAAIJ,yBAAyB,KAAK,IAAI,EAAE;MACpC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QAAQ,CAACX,mBAAmB,CAAC,iBAAiB,EAAEe,WAAW,CAAC;IAChE,CAAC;EACL,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAEjB,IAAAhD,gBAAS,EAAC,YAAM;IACZ,OAAO,IAAAkC,oBAAa,EAChB5C,MAAM,CAAC6C,sBAAsB,CAAC,YAAM;MAChCa,WAAW,EAAE;IACjB,CAAC,CAAC,EACF1D,MAAM,CAACiE,oBAAoB,CAAC,YAAM;MAC9B,IAAIjE,MAAM,CAAC8B,cAAc,EAAE,KAAK,IAAI,EAAE;QAClC2B,aAAa,CAAC,KAAK,CAAC;MACxB;IACJ,CAAC,CAAC,CACL;EACL,CAAC,EAAE,CAACzD,MAAM,EAAE0D,WAAW,CAAC,CAAC;EAEzB,IAAI,CAACF,UAAU,EAAE;IACb,OAAO,IAAI;EACf;EAEA,oBAAO,IAAAU,sBAAY,gBACf,6BAAC,eAAe;IAAC,IAAI,EAAEpE,IAAK;IAAC,UAAU,EAAEC,UAAW;IAAC,MAAM,EAAEC;EAAO,GAC/DH,QAAQ,CACK,EAClBE,UAAU,CACb;AACL,CAAC;AAQD;AACA;AACA;AACO,IAAMoE,OAAO,GAAG,IAAAC,gCAAc,EACjC,SAAS,EACT,iBAAwD;EAAA,IAArDrE,UAAU,SAAVA,UAAU;IAAED,IAAI,SAAJA,IAAI;IAAED,QAAQ,SAARA,QAAQ;EACzB,4BAAiB,IAAAwE,iDAAyB,GAAE;IAAA;IAArCrE,MAAM;EACb,OAAOqD,UAAU,CAAC;IAAErD,MAAM,EAANA,MAAM;IAAED,UAAU,EAAVA,UAAU;IAAED,IAAI,EAAJA,IAAI;IAAED,QAAQ,EAARA;EAAS,CAAC,CAAC;AAC7D,CAAC,CACJ;AAAC"}
|
|
1
|
+
{"version":3,"names":["FloatingToolbar","children","type","anchorElem","editor","popupCharStylesEditorRef","useRef","useRichTextEditor","toolbarType","setToolbarType","useEffect","mouseMoveListener","useCallback","e","current","buttons","style","pointerEvents","x","clientX","y","clientY","elementUnderMouse","document","elementFromPoint","contains","mouseUpListener","addEventListener","removeEventListener","updateTextFormatFloatingToolbar","selection","$getSelection","popupCharStylesEditorElem","nativeSelection","window","getSelection","rootElement","getRootElement","isCollapsed","anchorNode","rangeRect","getDOMRangeRect","setFloatingElemPosition","scrollerElem","parentElement","update","getEditorState","read","mergeRegister","registerUpdateListener","editorState","registerCommand","SELECTION_CHANGE_COMMAND","COMMAND_PRIORITY_LOW","isEditable","useToolbar","body","nodeIsText","setNodeIsText","setActiveEditor","setIsEditable","setTextBlockSelection","useState","toolbarActiveEditor","setToolbarActiveEditor","updateToolbar","isComposing","$isRangeSelection","selectionState","getLexicalTextSelectionState","selectedText","_payload","newEditor","COMMAND_PRIORITY_CRITICAL","registerEditableListener","editable","registerRootListener","createPortal","Toolbar","makeComposable","useLexicalComposerContext"],"sources":["Toolbar.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useRef, useState } from \"react\";\nimport {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_CRITICAL,\n COMMAND_PRIORITY_LOW,\n LexicalEditor,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { createPortal } from \"react-dom\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport \"./Toolbar.css\";\nimport { ToolbarType } from \"~/types\";\nimport { getDOMRangeRect } from \"~/utils/getDOMRangeRect\";\nimport { setFloatingElemPosition } from \"~/utils/setFloatingElemPosition\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { getLexicalTextSelectionState } from \"~/utils/getLexicalTextSelectionState\";\n\ninterface FloatingToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n editor: LexicalEditor;\n}\n\nconst FloatingToolbar: FC<FloatingToolbarProps> = ({ children, type, anchorElem, editor }) => {\n const popupCharStylesEditorRef = useRef<HTMLDivElement | null>(null);\n const { toolbarType, setToolbarType } = useRichTextEditor();\n\n useEffect(() => {\n if (toolbarType !== type) {\n setToolbarType(type);\n }\n }, [type]);\n\n const mouseMoveListener = useCallback(\n (e: MouseEvent) => {\n /* Indicates which mouse button(s) was pressed.\n / 1 = mouse left button\n / 3 = mouse left and right button in the same time\n / More info: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n */\n if (popupCharStylesEditorRef?.current && (e.buttons === 1 || e.buttons === 3)) {\n if (popupCharStylesEditorRef.current.style.pointerEvents !== \"none\") {\n const x = e.clientX;\n const y = e.clientY;\n const elementUnderMouse = document.elementFromPoint(x, y);\n\n if (!popupCharStylesEditorRef.current.contains(elementUnderMouse)) {\n // Mouse is not over the target element => not a normal click, but probably a drag\n popupCharStylesEditorRef.current.style.pointerEvents = \"none\";\n }\n }\n }\n },\n [popupCharStylesEditorRef]\n );\n\n const mouseUpListener = useCallback(() => {\n if (popupCharStylesEditorRef?.current) {\n if (popupCharStylesEditorRef.current.style.pointerEvents !== \"auto\") {\n popupCharStylesEditorRef.current.style.pointerEvents = \"auto\";\n }\n }\n }, [popupCharStylesEditorRef]);\n\n useEffect(() => {\n if (popupCharStylesEditorRef?.current) {\n document.addEventListener(\"mousemove\", mouseMoveListener);\n document.addEventListener(\"mouseup\", mouseUpListener);\n\n return () => {\n document.removeEventListener(\"mousemove\", mouseMoveListener);\n document.removeEventListener(\"mouseup\", mouseUpListener);\n };\n }\n return;\n }, [popupCharStylesEditorRef]);\n\n const updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection();\n\n const popupCharStylesEditorElem = popupCharStylesEditorRef.current;\n const nativeSelection = window.getSelection();\n\n if (popupCharStylesEditorElem === null) {\n return;\n }\n\n const rootElement = editor.getRootElement();\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement);\n\n setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);\n }\n }, [editor, anchorElem]);\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement;\n\n const update = () => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n };\n\n window.addEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.addEventListener(\"scroll\", update);\n }\n\n return () => {\n window.removeEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.removeEventListener(\"scroll\", update);\n }\n };\n }, [editor, updateTextFormatFloatingToolbar, anchorElem]);\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateTextFormatFloatingToolbar();\n });\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n updateTextFormatFloatingToolbar();\n return false;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor, updateTextFormatFloatingToolbar]);\n\n return (\n <div ref={popupCharStylesEditorRef} className=\"floating-text-format-popup\">\n {editor.isEditable() && children}\n </div>\n );\n};\n\ninterface useToolbarProps {\n editor: LexicalEditor;\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\nconst useToolbar: FC<useToolbarProps> = ({\n editor,\n anchorElem = document.body,\n type,\n children\n}): JSX.Element | null => {\n const { nodeIsText, setNodeIsText, setActiveEditor, setIsEditable, setTextBlockSelection } =\n useRichTextEditor();\n\n const [toolbarActiveEditor, setToolbarActiveEditor] = useState<LexicalEditor>(editor);\n\n const updateToolbar = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return;\n }\n\n const selection = $getSelection();\n\n if ($isRangeSelection(selection)) {\n const selectionState = getLexicalTextSelectionState(toolbarActiveEditor, selection);\n if (selectionState) {\n setTextBlockSelection(selectionState);\n if (selectionState.selectedText !== \"\") {\n setNodeIsText(true);\n } else {\n setNodeIsText(false);\n }\n }\n }\n\n if (!$isRangeSelection(selection)) {\n setNodeIsText(false);\n return;\n }\n });\n }, [toolbarActiveEditor]);\n\n useEffect(() => {\n document.addEventListener(\"selectionchange\", updateToolbar);\n return () => {\n document.removeEventListener(\"selectionchange\", updateToolbar);\n };\n }, [updateToolbar]);\n\n useEffect(() => {\n return editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateToolbar();\n setToolbarActiveEditor(newEditor);\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_CRITICAL\n );\n }, [editor, updateToolbar]);\n\n useEffect(() => {\n return mergeRegister(\n editor.registerEditableListener(editable => {\n setIsEditable(editable);\n }),\n toolbarActiveEditor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateToolbar();\n });\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setNodeIsText(false);\n }\n })\n );\n }, [updateToolbar, editor, toolbarActiveEditor]);\n\n if (!nodeIsText) {\n return null;\n }\n\n return createPortal(\n <FloatingToolbar type={type} anchorElem={anchorElem} editor={editor}>\n {children}\n </FloatingToolbar>,\n anchorElem\n );\n};\n\nexport interface ToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\n/**\n * @description Main toolbar container\n */\nexport const Toolbar = makeComposable<ToolbarProps>(\n \"Toolbar\",\n ({ anchorElem, type, children }): JSX.Element | null => {\n const [editor] = useLexicalComposerContext();\n return useToolbar({ editor, anchorElem, type, children });\n }\n);\n"],"mappings":";;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AASA,IAAMA,eAAyC,GAAG,SAA5CA,eAAyC,OAA+C;EAAA,IAAzCC,QAAQ,QAARA,QAAQ;IAAEC,IAAI,QAAJA,IAAI;IAAEC,UAAU,QAAVA,UAAU;IAAEC,MAAM,QAANA,MAAM;E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AAAoB,sBAAY,gBACf,6BAAC,eAAe;IAAC,IAAI,EAAE3E,IAAK;IAAC,UAAU,EAAEC,UAAW;IAAC,MAAM,EAAEC;EAAO,GAC/DH,QAAQ,CACK,EAClBE,UAAU,CACb;AACL,CAAC;AAQD;AACA;AACA;AACO,IAAM2E,OAAO,GAAG,IAAAC,gCAAc,EACjC,SAAS,EACT,iBAAwD;EAAA,IAArD5E,UAAU,SAAVA,UAAU;IAAED,IAAI,SAAJA,IAAI;IAAED,QAAQ,SAARA,QAAQ;EACzB,4BAAiB,IAAA+E,iDAAyB,GAAE;IAAA;IAArC5E,MAAM;EACb,OAAOmD,UAAU,CAAC;IAAEnD,MAAM,EAANA,MAAM;IAAED,UAAU,EAAVA,UAAU;IAAED,IAAI,EAAJA,IAAI;IAAED,QAAQ,EAARA;EAAS,CAAC,CAAC;AAC7D,CAAC,CACJ;AAAC"}
|
|
@@ -11,6 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
12
|
var _webinyList = require("../../commands/webiny-list");
|
|
13
13
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
14
|
+
var _findTypographyStyleByHtmlTag = require("../../utils/findTypographyStyleByHtmlTag");
|
|
14
15
|
var BulletListAction = function BulletListAction() {
|
|
15
16
|
var _textBlockSelection$s;
|
|
16
17
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
@@ -21,7 +22,8 @@ var BulletListAction = function BulletListAction() {
|
|
|
21
22
|
isActive = _useState2[0],
|
|
22
23
|
setIsActive = _useState2[1];
|
|
23
24
|
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
24
|
-
textBlockSelection = _useRichTextEditor.textBlockSelection
|
|
25
|
+
textBlockSelection = _useRichTextEditor.textBlockSelection,
|
|
26
|
+
themeEmotionMap = _useRichTextEditor.themeEmotionMap;
|
|
25
27
|
var isListSelected = textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s = textBlockSelection.state) === null || _textBlockSelection$s === void 0 ? void 0 : _textBlockSelection$s.list.isSelected;
|
|
26
28
|
(0, _react.useEffect)(function () {
|
|
27
29
|
var _textBlockSelection$s2;
|
|
@@ -30,10 +32,13 @@ var BulletListAction = function BulletListAction() {
|
|
|
30
32
|
}, [isListSelected]);
|
|
31
33
|
var formatBulletList = function formatBulletList() {
|
|
32
34
|
if (!isActive) {
|
|
35
|
+
var _findTypographyStyleB;
|
|
36
|
+
var styleId = themeEmotionMap ? (_findTypographyStyleB = (0, _findTypographyStyleByHtmlTag.findTypographyStyleByHtmlTag)("ul", themeEmotionMap)) === null || _findTypographyStyleB === void 0 ? void 0 : _findTypographyStyleB.id : undefined;
|
|
33
37
|
// will update the active state in the useEffect
|
|
34
38
|
editor.dispatchCommand(_webinyList.INSERT_UNORDERED_WEBINY_LIST_COMMAND, {
|
|
35
|
-
themeStyleId:
|
|
39
|
+
themeStyleId: styleId
|
|
36
40
|
});
|
|
41
|
+
setIsActive(true);
|
|
37
42
|
} else {
|
|
38
43
|
editor.dispatchCommand(_webinyList.REMOVE_WEBINY_LIST_COMMAND, undefined);
|
|
39
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BulletListAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","isListSelected","state","list","isSelected","useEffect","isListBulletType","textType","formatBulletList","dispatchCommand","INSERT_UNORDERED_WEBINY_LIST_COMMAND","themeStyleId","REMOVE_WEBINY_LIST_COMMAND"
|
|
1
|
+
{"version":3,"names":["BulletListAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","themeEmotionMap","isListSelected","state","list","isSelected","useEffect","isListBulletType","textType","formatBulletList","styleId","findTypographyStyleByHtmlTag","id","undefined","dispatchCommand","INSERT_UNORDERED_WEBINY_LIST_COMMAND","themeStyleId","REMOVE_WEBINY_LIST_COMMAND"],"sources":["BulletListAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport {\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n REMOVE_WEBINY_LIST_COMMAND\n} from \"~/commands/webiny-list\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { findTypographyStyleByHtmlTag } from \"~/utils/findTypographyStyleByHtmlTag\";\n\nexport const BulletListAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isActive, setIsActive] = useState<boolean>(false);\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isListSelected = textBlockSelection?.state?.list.isSelected;\n\n useEffect(() => {\n const isListBulletType = textBlockSelection?.state?.textType === \"bullet\";\n setIsActive(isListBulletType);\n }, [isListSelected]);\n\n const formatBulletList = () => {\n if (!isActive) {\n const styleId = themeEmotionMap\n ? findTypographyStyleByHtmlTag(\"ul\", themeEmotionMap)?.id\n : undefined;\n // will update the active state in the useEffect\n editor.dispatchCommand(INSERT_UNORDERED_WEBINY_LIST_COMMAND, { themeStyleId: styleId });\n setIsActive(true);\n } else {\n editor.dispatchCommand(REMOVE_WEBINY_LIST_COMMAND, undefined);\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;AAIA;AACA;AAEO,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAgB,GAAS;EAAA;EAClC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAgC,IAAAC,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAjDC,QAAQ;IAAEC,WAAW;EAC5B,yBAAgD,IAAAC,qCAAiB,GAAE;IAA3DC,kBAAkB,sBAAlBA,kB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|
(0, _react.useEffect)(function () {
|
|
89
89
|
return editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
|
|
90
90
|
updateToolbar();
|
|
@@ -1 +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\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
|
|
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\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]);\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,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,EACN,MAAM,EACN,MAAM,EACN,MAAM,CACT;AAED,SAASC,mBAAmB,CAACC,MAAe,EAAE;EAC1C,IAAIA,MAAM,EAAE;IACR,OAAO,6BAA6B;EACxC;EACA,OAAO,EAAE;AACb;AAQA,SAASC,gBAAgB,CAACC,KAA4B,EAAe;EACjE,IAAQC,MAAM,GAA8BD,KAAK,CAAzCC,MAAM;IAAEC,KAAK,GAAuBF,KAAK,CAAjCE,KAAK;IAAA,kBAAuBF,KAAK,CAA1BG,QAAQ;IAARA,QAAQ,gCAAG,KAAK;EAEvC,IAAMC,WAAW,GAAG,IAAAC,kBAAW,EAC3B,UAACC,MAAc,EAAK;IAChBL,MAAM,CAACM,MAAM,CAAC,YAAM;MAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;MACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;QAC9B,IAAAG,0BAAe,E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IAAAM,gBAAS,EAAC,YAAM;IACZ,OAAO,IAAAC,oBAAa,EAChBxB,MAAM,CAACyB,wBAAwB,CAAC,UAAAC,QAAQ,EAAI;MACxCV,aAAa,CAACU,QAAQ,CAAC;IAC3B,CAAC,CAAC,EACFT,YAAY,CAACU,sBAAsB,CAAC,gBAAqB;MAAA,IAAlBC,WAAW,QAAXA,WAAW;MAC9CA,WAAW,CAACC,IAAI,CAAC,YAAM;QACnBR,aAAa,EAAE;MACnB,CAAC,CAAC;IACN,CAAC,CAAC,CACL;EACL,CAAC,EAAE,CAACJ,YAAY,EAAEjB,MAAM,CAAC,CAAC;EAE1B,IAAAuB,gBAAS,EAAC,YAAM;IACZ,OAAOvB,MAAM,CAAC8B,eAAe,CACzBC,iCAAwB,EACxB,UAACC,QAAQ,EAAEC,SAAS,EAAK;MACrBZ,aAAa,EAAE;MACfH,eAAe,CAACe,SAAS,CAAC;MAC1B,OAAO,KAAK;IAChB,CAAC,EACDC,kCAAyB,CAC5B;EACL,CAAC,EAAE,CAAClC,MAAM,EAAEqB,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"}
|
|
@@ -11,6 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
12
|
var _webinyList = require("../../commands/webiny-list");
|
|
13
13
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
14
|
+
var _findTypographyStyleByHtmlTag = require("../../utils/findTypographyStyleByHtmlTag");
|
|
14
15
|
var NumberedListAction = function NumberedListAction() {
|
|
15
16
|
var _textBlockSelection$s;
|
|
16
17
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
@@ -21,7 +22,8 @@ var NumberedListAction = function NumberedListAction() {
|
|
|
21
22
|
isActive = _useState2[0],
|
|
22
23
|
setIsActive = _useState2[1];
|
|
23
24
|
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
24
|
-
textBlockSelection = _useRichTextEditor.textBlockSelection
|
|
25
|
+
textBlockSelection = _useRichTextEditor.textBlockSelection,
|
|
26
|
+
themeEmotionMap = _useRichTextEditor.themeEmotionMap;
|
|
25
27
|
var isListSelected = textBlockSelection === null || textBlockSelection === void 0 ? void 0 : (_textBlockSelection$s = textBlockSelection.state) === null || _textBlockSelection$s === void 0 ? void 0 : _textBlockSelection$s.list.isSelected;
|
|
26
28
|
(0, _react.useEffect)(function () {
|
|
27
29
|
var _textBlockSelection$s2;
|
|
@@ -30,10 +32,13 @@ var NumberedListAction = function NumberedListAction() {
|
|
|
30
32
|
}, [isListSelected]);
|
|
31
33
|
var formatNumberedList = function formatNumberedList() {
|
|
32
34
|
if (!isActive) {
|
|
35
|
+
var _findTypographyStyleB;
|
|
36
|
+
var styleId = themeEmotionMap ? (_findTypographyStyleB = (0, _findTypographyStyleByHtmlTag.findTypographyStyleByHtmlTag)("ol", themeEmotionMap)) === null || _findTypographyStyleB === void 0 ? void 0 : _findTypographyStyleB.id : undefined;
|
|
33
37
|
// will update the active state in the useEffect
|
|
34
38
|
editor.dispatchCommand(_webinyList.INSERT_ORDERED_WEBINY_LIST_COMMAND, {
|
|
35
|
-
themeStyleId:
|
|
39
|
+
themeStyleId: styleId
|
|
36
40
|
});
|
|
41
|
+
setIsActive(true);
|
|
37
42
|
} else {
|
|
38
43
|
editor.dispatchCommand(_webinyList.REMOVE_WEBINY_LIST_COMMAND, undefined);
|
|
39
44
|
// removing will not update correctly the active state, so we need to set to false manually.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NumberedListAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","isListSelected","state","list","isSelected","useEffect","isListBulletType","textType","formatNumberedList","dispatchCommand","INSERT_ORDERED_WEBINY_LIST_COMMAND","themeStyleId","REMOVE_WEBINY_LIST_COMMAND"
|
|
1
|
+
{"version":3,"names":["NumberedListAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","themeEmotionMap","isListSelected","state","list","isSelected","useEffect","isListBulletType","textType","formatNumberedList","styleId","findTypographyStyleByHtmlTag","id","undefined","dispatchCommand","INSERT_ORDERED_WEBINY_LIST_COMMAND","themeStyleId","REMOVE_WEBINY_LIST_COMMAND"],"sources":["NumberedListAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport {\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n REMOVE_WEBINY_LIST_COMMAND\n} from \"~/commands/webiny-list\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { findTypographyStyleByHtmlTag } from \"~/utils/findTypographyStyleByHtmlTag\";\n\nexport const NumberedListAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isActive, setIsActive] = useState<boolean>(false);\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isListSelected = textBlockSelection?.state?.list.isSelected;\n\n useEffect(() => {\n const isListBulletType = textBlockSelection?.state?.textType === \"number\";\n setIsActive(isListBulletType);\n }, [isListSelected]);\n\n const formatNumberedList = () => {\n if (!isActive) {\n const styleId = themeEmotionMap\n ? findTypographyStyleByHtmlTag(\"ol\", themeEmotionMap)?.id\n : undefined;\n // will update the active state in the useEffect\n editor.dispatchCommand(INSERT_ORDERED_WEBINY_LIST_COMMAND, { themeStyleId: styleId });\n setIsActive(true);\n } else {\n editor.dispatchCommand(REMOVE_WEBINY_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={() => formatNumberedList()}\n className={\"popup-item spaced \" + (isActive ? \"active\" : \"\")}\n aria-label=\"Format text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;IACI,OAAO,EAAE;MAAA,OAAMW,kBAAkB,EAAE;IAAA,CAAC;IACpC,SAAS,EAAE,oBAAoB,IAAIZ,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC7D,cAAW;EAA8B,gBAEzC;IAAG,SAAS,EAAC;EAAoB,EAAG,CAC/B;AAEjB,CAAC;AAAC"}
|
|
@@ -23,7 +23,8 @@ var QuoteAction = function QuoteAction() {
|
|
|
23
23
|
setIsActive = _useState2[1];
|
|
24
24
|
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
25
25
|
textBlockSelection = _useRichTextEditor.textBlockSelection,
|
|
26
|
-
themeEmotionMap = _useRichTextEditor.themeEmotionMap
|
|
26
|
+
themeEmotionMap = _useRichTextEditor.themeEmotionMap,
|
|
27
|
+
activeEditor = _useRichTextEditor.activeEditor;
|
|
27
28
|
var isQuoteSelected = !!(textBlockSelection !== null && textBlockSelection !== void 0 && (_textBlockSelection$s = textBlockSelection.state) !== null && _textBlockSelection$s !== void 0 && _textBlockSelection$s.quote.isSelected);
|
|
28
29
|
var formatText = function formatText() {
|
|
29
30
|
if (!isActive) {
|
|
@@ -37,7 +38,7 @@ var QuoteAction = function QuoteAction() {
|
|
|
37
38
|
};
|
|
38
39
|
(0, _react.useEffect)(function () {
|
|
39
40
|
setIsActive(isQuoteSelected);
|
|
40
|
-
}, [isQuoteSelected]);
|
|
41
|
+
}, [isQuoteSelected, activeEditor]);
|
|
41
42
|
return /*#__PURE__*/_react.default.createElement("button", {
|
|
42
43
|
onClick: function onClick() {
|
|
43
44
|
return formatText();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["QuoteAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","themeEmotionMap","isQuoteSelected","state","quote","isSelected","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","formatToQuote","undefined","formatToParagraph","useEffect"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { formatToQuote } from \"~/utils/nodes/formatToQuote\";\nimport { formatToParagraph } from \"~/utils/nodes/formatToParagraph\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nexport const QuoteAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isActive, setIsActive] = useState<boolean>(false);\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isQuoteSelected = !!textBlockSelection?.state?.quote.isSelected;\n\n const formatText = () => {\n if (!isActive) {\n // Try to set default quote style, when the action button is clicked for first time\n const DEFAULT_QUOTE_ID = \"quote\";\n const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];\n formatToQuote(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);\n return;\n }\n formatToParagraph(editor);\n };\n\n useEffect(() => {\n setIsActive(isQuoteSelected);\n }, [isQuoteSelected]);\n\n return (\n <button\n onClick={() => formatText()}\n className={\"popup-item \" + (isActive ? \"active\" : \"\")}\n aria-label=\"Format text as quote\"\n >\n <i className=\"icon quote\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,IAAMA,WAAW,GAAG,SAAdA,WAAW,GAAS;EAAA;EAC7B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAgC,IAAAC,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAjDC,QAAQ;IAAEC,WAAW;EAC5B,
|
|
1
|
+
{"version":3,"names":["QuoteAction","useLexicalComposerContext","editor","useState","isActive","setIsActive","useRichTextEditor","textBlockSelection","themeEmotionMap","activeEditor","isQuoteSelected","state","quote","isSelected","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","formatToQuote","undefined","formatToParagraph","useEffect"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { formatToQuote } from \"~/utils/nodes/formatToQuote\";\nimport { formatToParagraph } from \"~/utils/nodes/formatToParagraph\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nexport const QuoteAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isActive, setIsActive] = useState<boolean>(false);\n const { textBlockSelection, themeEmotionMap, activeEditor } = useRichTextEditor();\n const isQuoteSelected = !!textBlockSelection?.state?.quote.isSelected;\n\n const formatText = () => {\n if (!isActive) {\n // Try to set default quote style, when the action button is clicked for first time\n const DEFAULT_QUOTE_ID = \"quote\";\n const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];\n formatToQuote(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);\n return;\n }\n formatToParagraph(editor);\n };\n\n useEffect(() => {\n setIsActive(isQuoteSelected);\n }, [isQuoteSelected, activeEditor]);\n\n return (\n <button\n onClick={() => formatText()}\n className={\"popup-item \" + (isActive ? \"active\" : \"\")}\n aria-label=\"Format text as quote\"\n >\n <i className=\"icon quote\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,IAAMA,WAAW,GAAG,SAAdA,WAAW,GAAS;EAAA;EAC7B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAAgC,IAAAC,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAjDC,QAAQ;IAAEC,WAAW;EAC5B,yBAA8D,IAAAC,qCAAiB,GAAE;IAAzEC,kBAAkB,sBAAlBA,kBAAkB;IAAEC,eAAe,sBAAfA,eAAe;IAAEC,YAAY,sBAAZA,YAAY;EACzD,IAAMC,eAAe,GAAG,CAAC,EAACH,kBAAkB,aAAlBA,kBAAkB,wCAAlBA,kBAAkB,CAAEI,KAAK,kDAAzB,sBAA2BC,KAAK,CAACC,UAAU;EAErE,IAAMC,UAAU,GAAG,SAAbA,UAAU,GAAS;IACrB,IAAI,CAACV,QAAQ,EAAE;MACX;MACA,IAAMW,gBAAgB,GAAG,OAAO;MAChC,IAAMC,cAAc,GAAGR,eAAe,IAAIA,eAAe,CAACO,gBAAgB,CAAC;MAC3E,IAAAE,4BAAa,EAACf,MAAM,EAAEc,cAAc,GAAGD,gBAAgB,GAAGG,SAAS,CAAC;MACpE;IACJ;IACA,IAAAC,oCAAiB,EAACjB,MAAM,CAAC;EAC7B,CAAC;EAED,IAAAkB,gBAAS,EAAC,YAAM;IACZf,WAAW,CAACK,eAAe,CAAC;EAChC,CAAC,EAAE,CAACA,eAAe,EAAED,YAAY,CAAC,CAAC;EAEnC,oBACI;IACI,OAAO,EAAE;MAAA,OAAMK,UAAU,EAAE;IAAA,CAAC;IAC5B,SAAS,EAAE,aAAa,IAAIV,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAE;IACtD,cAAW;EAAsB,gBAEjC;IAAG,SAAS,EAAC;EAAY,EAAG,CACvB;AAEjB,CAAC;AAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const BaseTextAlignmentDropDown: import("@webiny/react-composition").ComposableFC<unknown>;
|
|
3
|
+
interface TextAlignmentActionDropdownProps {
|
|
4
|
+
element: JSX.Element;
|
|
5
|
+
}
|
|
6
|
+
declare const TextAlignmentActionDropDown: React.FC<TextAlignmentActionDropdownProps>;
|
|
7
|
+
export interface TextAlignmentAction extends React.FC<unknown> {
|
|
8
|
+
TextAlignmentDropDown: typeof TextAlignmentActionDropDown;
|
|
9
|
+
}
|
|
10
|
+
export declare const TextAlignmentAction: TextAlignmentAction;
|
|
11
|
+
export {};
|