@webiny/lexical-editor 5.36.2-beta.0 → 5.36.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/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/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/package.json +5 -5
- package/types.d.ts +2 -0
- package/types.js.map +1 -1
- package/utils/getLexicalTextSelectionState.js +6 -0
- package/utils/getLexicalTextSelectionState.js.map +1 -1
|
@@ -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,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CAAC;IACzD,OAAO,YAAM;MACTJ,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,U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OAAO,IAAI;EACf;EAEA,oBAAO,IAAAoB,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"}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,70 @@
|
|
|
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.TextAlignmentAction = exports.BaseTextAlignmentDropDown = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _lexical = require("lexical");
|
|
12
|
+
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
13
|
+
var _reactComposition = require("@webiny/react-composition");
|
|
14
|
+
var _TextAlignmentActionContextProps = require("../../context/TextAlignmentActionContextProps");
|
|
15
|
+
/*
|
|
16
|
+
* Base text alignment dropdown composable component.
|
|
17
|
+
* Note: To add a custom dropdown component use @see LexicalEditorConfig API.
|
|
18
|
+
*/
|
|
19
|
+
var BaseTextAlignmentDropDown = (0, _reactComposition.makeComposable)("BaseTextAlignmentDropDown", function () {
|
|
20
|
+
(0, _react.useEffect)(function () {
|
|
21
|
+
console.log("Default BaseTextAlignmentDropDown, please add your own component");
|
|
22
|
+
}, []);
|
|
23
|
+
return null;
|
|
24
|
+
});
|
|
25
|
+
exports.BaseTextAlignmentDropDown = BaseTextAlignmentDropDown;
|
|
26
|
+
var TextAlignmentActionDropDown = function TextAlignmentActionDropDown(_ref) {
|
|
27
|
+
var element = _ref.element;
|
|
28
|
+
return /*#__PURE__*/_react.default.createElement(_reactComposition.Compose, {
|
|
29
|
+
component: BaseTextAlignmentDropDown,
|
|
30
|
+
with: function _with() {
|
|
31
|
+
return function () {
|
|
32
|
+
return element;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var TextAlignmentAction = function TextAlignmentAction() {
|
|
38
|
+
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
39
|
+
activeEditor = _useRichTextEditor.activeEditor;
|
|
40
|
+
var _useState = (0, _react.useState)(""),
|
|
41
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
42
|
+
alignmentValue = _useState2[0],
|
|
43
|
+
setAlignmentValue = _useState2[1];
|
|
44
|
+
var applyTextAlignment = function applyTextAlignment(value) {
|
|
45
|
+
if (activeEditor) {
|
|
46
|
+
activeEditor.dispatchCommand(_lexical.FORMAT_ELEMENT_COMMAND, value);
|
|
47
|
+
setAlignmentValue(value);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var outdentText = function outdentText() {
|
|
51
|
+
if (activeEditor) {
|
|
52
|
+
activeEditor.dispatchCommand(_lexical.OUTDENT_CONTENT_COMMAND, undefined);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var indentText = function indentText() {
|
|
56
|
+
if (activeEditor) {
|
|
57
|
+
activeEditor.dispatchCommand(_lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return /*#__PURE__*/_react.default.createElement(_TextAlignmentActionContextProps.TextAlignmentActionContext.Provider, {
|
|
61
|
+
value: {
|
|
62
|
+
value: alignmentValue,
|
|
63
|
+
applyTextAlignment: applyTextAlignment,
|
|
64
|
+
outdentText: outdentText,
|
|
65
|
+
indentText: indentText
|
|
66
|
+
}
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement(BaseTextAlignmentDropDown, null));
|
|
68
|
+
};
|
|
69
|
+
exports.TextAlignmentAction = TextAlignmentAction;
|
|
70
|
+
TextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BaseTextAlignmentDropDown","makeComposable","useEffect","console","log","TextAlignmentActionDropDown","element","TextAlignmentAction","useRichTextEditor","activeEditor","useState","alignmentValue","setAlignmentValue","applyTextAlignment","value","dispatchCommand","FORMAT_ELEMENT_COMMAND","outdentText","OUTDENT_CONTENT_COMMAND","undefined","indentText","INDENT_CONTENT_COMMAND","TextAlignmentDropDown"],"sources":["TextAlignmentAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport {\n ElementFormatType,\n FORMAT_ELEMENT_COMMAND,\n INDENT_CONTENT_COMMAND,\n OUTDENT_CONTENT_COMMAND\n} from \"lexical\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { TextAlignmentActionContext } from \"~/context/TextAlignmentActionContextProps\";\n\n/*\n * Base text alignment dropdown composable component.\n * Note: To add a custom dropdown component use @see LexicalEditorConfig API.\n */\nexport const BaseTextAlignmentDropDown = makeComposable(\n \"BaseTextAlignmentDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTextAlignmentDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TextAlignmentActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TextAlignmentActionDropDown: React.FC<TextAlignmentActionDropdownProps> = ({\n element\n}): JSX.Element => {\n return <Compose component={BaseTextAlignmentDropDown} with={() => () => element} />;\n};\n\nexport interface TextAlignmentAction extends React.FC<unknown> {\n TextAlignmentDropDown: typeof TextAlignmentActionDropDown;\n}\n\nexport const TextAlignmentAction: TextAlignmentAction = () => {\n const { activeEditor } = useRichTextEditor();\n const [alignmentValue, setAlignmentValue] = useState<ElementFormatType>(\"\");\n const applyTextAlignment = (value: ElementFormatType) => {\n if (activeEditor) {\n activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);\n setAlignmentValue(value);\n }\n };\n\n const outdentText = () => {\n if (activeEditor) {\n activeEditor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);\n }\n };\n\n const indentText = () => {\n if (activeEditor) {\n activeEditor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);\n }\n };\n\n return (\n <TextAlignmentActionContext.Provider\n value={{ value: alignmentValue, applyTextAlignment, outdentText, indentText }}\n >\n <BaseTextAlignmentDropDown />\n </TextAlignmentActionContext.Provider>\n );\n};\n\nTextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;\n"],"mappings":";;;;;;;;;AAAA;AACA;AAMA;AACA;AACA;AAEA;AACA;AACA;AACA;AACO,IAAMA,yBAAyB,GAAG,IAAAC,gCAAc,EACnD,2BAA2B,EAC3B,YAA0B;EACtB,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,kEAAkE,CAAC;EACnF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CAAC,CACJ;AAAC;AAMF,IAAMC,2BAAuE,GAAG,SAA1EA,2BAAuE,OAE1D;EAAA,IADfC,OAAO,QAAPA,OAAO;EAEP,oBAAO,6BAAC,yBAAO;IAAC,SAAS,EAAEN,yBAA0B;IAAC,IAAI,EAAE;MAAA,OAAM;QAAA,OAAMM,OAAO;MAAA;IAAA;EAAC,EAAG;AACvF,CAAC;AAMM,IAAMC,mBAAwC,GAAG,SAA3CA,mBAAwC,GAAS;EAC1D,yBAAyB,IAAAC,qCAAiB,GAAE;IAApCC,YAAY,sBAAZA,YAAY;EACpB,gBAA4C,IAAAC,eAAQ,EAAoB,EAAE,CAAC;IAAA;IAApEC,cAAc;IAAEC,iBAAiB;EACxC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkB,CAAIC,KAAwB,EAAK;IACrD,IAAIL,YAAY,EAAE;MACdA,YAAY,CAACM,eAAe,CAACC,+BAAsB,EAAEF,KAAK,CAAC;MAC3DF,iBAAiB,CAACE,KAAK,CAAC;IAC5B;EACJ,CAAC;EAED,IAAMG,WAAW,GAAG,SAAdA,WAAW,GAAS;IACtB,IAAIR,YAAY,EAAE;MACdA,YAAY,CAACM,eAAe,CAACG,gCAAuB,EAAEC,SAAS,CAAC;IACpE;EACJ,CAAC;EAED,IAAMC,UAAU,GAAG,SAAbA,UAAU,GAAS;IACrB,IAAIX,YAAY,EAAE;MACdA,YAAY,CAACM,eAAe,CAACM,+BAAsB,EAAEF,SAAS,CAAC;IACnE;EACJ,CAAC;EAED,oBACI,6BAAC,2DAA0B,CAAC,QAAQ;IAChC,KAAK,EAAE;MAAEL,KAAK,EAAEH,cAAc;MAAEE,kBAAkB,EAAlBA,kBAAkB;MAAEI,WAAW,EAAXA,WAAW;MAAEG,UAAU,EAAVA;IAAW;EAAE,gBAE9E,6BAAC,yBAAyB,OAAG,CACK;AAE9C,CAAC;AAAC;AAEFb,mBAAmB,CAACe,qBAAqB,GAAGjB,2BAA2B"}
|
|
@@ -16,6 +16,7 @@ var _FontSizeAction = require("../ToolbarActions/FontSizeAction");
|
|
|
16
16
|
var _Divider = require("../../ui/Divider");
|
|
17
17
|
var _FontColorAction = require("../ToolbarActions/FontColorAction");
|
|
18
18
|
var _TypographyAction = require("../ToolbarActions/TypographyAction");
|
|
19
|
+
var _TextAlignmentAction = require("../ToolbarActions/TextAlignmentAction");
|
|
19
20
|
var HeadingToolbarPreset = function HeadingToolbarPreset() {
|
|
20
21
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
21
22
|
element: /*#__PURE__*/_react.default.createElement(_FontSizeAction.FontSizeAction, null),
|
|
@@ -26,6 +27,9 @@ var HeadingToolbarPreset = function HeadingToolbarPreset() {
|
|
|
26
27
|
}), /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
27
28
|
element: /*#__PURE__*/_react.default.createElement(_TypographyAction.TypographyAction, null),
|
|
28
29
|
type: "heading"
|
|
30
|
+
}), /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
31
|
+
element: /*#__PURE__*/_react.default.createElement(_TextAlignmentAction.TextAlignmentAction, null),
|
|
32
|
+
type: "heading"
|
|
29
33
|
}), /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
30
34
|
element: /*#__PURE__*/_react.default.createElement(_Divider.Divider, null),
|
|
31
35
|
type: "heading"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HeadingToolbarPreset"],"sources":["HeadingToolbarPreset.tsx"],"sourcesContent":["import React from \"react\";\nimport { BoldAction } from \"~/components/ToolbarActions/BoldAction\";\nimport { AddToolbarAction } from \"~/components/AddToolbarAction\";\nimport { ItalicAction } from \"~/components/ToolbarActions/ItalicAction\";\nimport { UnderlineAction } from \"~/components/ToolbarActions/UnderlineAction\";\nimport { CodeHighlightAction } from \"~/components/ToolbarActions/CodeHighlightAction\";\nimport { LinkAction } from \"~/components/ToolbarActions/LinkAction\";\nimport { FontSizeAction } from \"~/components/ToolbarActions/FontSizeAction\";\nimport { Divider } from \"~/ui/Divider\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\n\nexport const HeadingToolbarPreset = () => {\n return (\n <>\n <AddToolbarAction element={<FontSizeAction />} type={\"heading\"} />\n <AddToolbarAction element={<FontColorAction />} type={\"heading\"} />\n <AddToolbarAction element={<TypographyAction />} type={\"heading\"} />\n <AddToolbarAction element={<Divider />} type={\"heading\"} />\n <AddToolbarAction element={<BoldAction />} type={\"heading\"} />\n <AddToolbarAction element={<ItalicAction />} type={\"heading\"} />\n <AddToolbarAction element={<UnderlineAction />} type={\"heading\"} />\n <AddToolbarAction element={<CodeHighlightAction />} type={\"heading\"} />\n <AddToolbarAction element={<Divider />} type={\"heading\"} />\n <AddToolbarAction element={<LinkAction />} type={\"heading\"} />\n </>\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoB,GAAS;EACtC,oBACI,yEACI,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAClE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACnE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,kCAAgB,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACpE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAC3D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sBAAU,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAC9D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,0BAAY,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAChE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACnE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,wCAAmB,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACvE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAC3D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sBAAU,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,CAC/D;AAEX,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["HeadingToolbarPreset"],"sources":["HeadingToolbarPreset.tsx"],"sourcesContent":["import React from \"react\";\nimport { BoldAction } from \"~/components/ToolbarActions/BoldAction\";\nimport { AddToolbarAction } from \"~/components/AddToolbarAction\";\nimport { ItalicAction } from \"~/components/ToolbarActions/ItalicAction\";\nimport { UnderlineAction } from \"~/components/ToolbarActions/UnderlineAction\";\nimport { CodeHighlightAction } from \"~/components/ToolbarActions/CodeHighlightAction\";\nimport { LinkAction } from \"~/components/ToolbarActions/LinkAction\";\nimport { FontSizeAction } from \"~/components/ToolbarActions/FontSizeAction\";\nimport { Divider } from \"~/ui/Divider\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\nimport { TextAlignmentAction } from \"~/components/ToolbarActions/TextAlignmentAction\";\n\nexport const HeadingToolbarPreset = () => {\n return (\n <>\n <AddToolbarAction element={<FontSizeAction />} type={\"heading\"} />\n <AddToolbarAction element={<FontColorAction />} type={\"heading\"} />\n <AddToolbarAction element={<TypographyAction />} type={\"heading\"} />\n <AddToolbarAction element={<TextAlignmentAction />} type={\"heading\"} />\n <AddToolbarAction element={<Divider />} type={\"heading\"} />\n <AddToolbarAction element={<BoldAction />} type={\"heading\"} />\n <AddToolbarAction element={<ItalicAction />} type={\"heading\"} />\n <AddToolbarAction element={<UnderlineAction />} type={\"heading\"} />\n <AddToolbarAction element={<CodeHighlightAction />} type={\"heading\"} />\n <AddToolbarAction element={<Divider />} type={\"heading\"} />\n <AddToolbarAction element={<LinkAction />} type={\"heading\"} />\n </>\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoB,GAAS;EACtC,oBACI,yEACI,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAClE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACnE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,kCAAgB,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACpE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,wCAAmB,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACvE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAC3D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sBAAU,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAC9D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,0BAAY,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAChE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACnE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,wCAAmB,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eACvE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,eAC3D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sBAAU,OAAI;IAAC,IAAI,EAAE;EAAU,EAAG,CAC/D;AAEX,CAAC;AAAC"}
|
|
@@ -19,6 +19,7 @@ var _BulletListAction = require("../ToolbarActions/BulletListAction");
|
|
|
19
19
|
var _QuoteAction = require("../ToolbarActions/QuoteAction");
|
|
20
20
|
var _FontColorAction = require("../ToolbarActions/FontColorAction");
|
|
21
21
|
var _TypographyAction = require("../ToolbarActions/TypographyAction");
|
|
22
|
+
var _TextAlignmentAction = require("../ToolbarActions/TextAlignmentAction");
|
|
22
23
|
var ParagraphToolbarPreset = function ParagraphToolbarPreset() {
|
|
23
24
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
24
25
|
element: /*#__PURE__*/_react.default.createElement(_FontSizeAction.FontSizeAction, null),
|
|
@@ -29,6 +30,9 @@ var ParagraphToolbarPreset = function ParagraphToolbarPreset() {
|
|
|
29
30
|
}), /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
30
31
|
element: /*#__PURE__*/_react.default.createElement(_TypographyAction.TypographyAction, null),
|
|
31
32
|
type: "paragraph"
|
|
33
|
+
}), /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
34
|
+
element: /*#__PURE__*/_react.default.createElement(_TextAlignmentAction.TextAlignmentAction, null),
|
|
35
|
+
type: "paragraph"
|
|
32
36
|
}), /*#__PURE__*/_react.default.createElement(_AddToolbarAction.AddToolbarAction, {
|
|
33
37
|
element: /*#__PURE__*/_react.default.createElement(_Divider.Divider, null),
|
|
34
38
|
type: "paragraph"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ParagraphToolbarPreset"],"sources":["ParagraphToolbarPreset.tsx"],"sourcesContent":["import React from \"react\";\nimport { BoldAction } from \"~/components/ToolbarActions/BoldAction\";\nimport { AddToolbarAction } from \"~/components/AddToolbarAction\";\nimport { ItalicAction } from \"~/components/ToolbarActions/ItalicAction\";\nimport { UnderlineAction } from \"~/components/ToolbarActions/UnderlineAction\";\nimport { CodeHighlightAction } from \"~/components/ToolbarActions/CodeHighlightAction\";\nimport { LinkAction } from \"~/components/ToolbarActions/LinkAction\";\nimport { FontSizeAction } from \"~/components/ToolbarActions/FontSizeAction\";\nimport { Divider } from \"~/ui/Divider\";\nimport { NumberedListAction } from \"~/components/ToolbarActions/NumberedListAction\";\nimport { BulletListAction } from \"~/components/ToolbarActions/BulletListAction\";\nimport { QuoteAction } from \"~/components/ToolbarActions/QuoteAction\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\n\nexport const ParagraphToolbarPreset = () => {\n return (\n <>\n <AddToolbarAction element={<FontSizeAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<FontColorAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<TypographyAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<Divider />} type={\"paragraph\"} />\n <AddToolbarAction element={<BoldAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<ItalicAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<UnderlineAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<CodeHighlightAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<Divider />} type={\"paragraph\"} />\n <AddToolbarAction element={<NumberedListAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<BulletListAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<Divider />} type={\"paragraph\"} />\n <AddToolbarAction element={<LinkAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<QuoteAction />} type={\"paragraph\"} />\n </>\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,GAAS;EACxC,oBACI,yEACI,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACpE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACrE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,kCAAgB,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACtE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eAC7D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sBAAU,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eAChE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,0BAAY,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eAClE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACrE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,wCAAmB,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACzE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eAC7D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sCAAkB,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACxE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,kCAAgB,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACtE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gBAAO,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eAC7D,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,sBAAU,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eAChE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,wBAAW,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,CAClE;AAEX,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["ParagraphToolbarPreset"],"sources":["ParagraphToolbarPreset.tsx"],"sourcesContent":["import React from \"react\";\nimport { BoldAction } from \"~/components/ToolbarActions/BoldAction\";\nimport { AddToolbarAction } from \"~/components/AddToolbarAction\";\nimport { ItalicAction } from \"~/components/ToolbarActions/ItalicAction\";\nimport { UnderlineAction } from \"~/components/ToolbarActions/UnderlineAction\";\nimport { CodeHighlightAction } from \"~/components/ToolbarActions/CodeHighlightAction\";\nimport { LinkAction } from \"~/components/ToolbarActions/LinkAction\";\nimport { FontSizeAction } from \"~/components/ToolbarActions/FontSizeAction\";\nimport { Divider } from \"~/ui/Divider\";\nimport { NumberedListAction } from \"~/components/ToolbarActions/NumberedListAction\";\nimport { BulletListAction } from \"~/components/ToolbarActions/BulletListAction\";\nimport { QuoteAction } from \"~/components/ToolbarActions/QuoteAction\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\nimport { TextAlignmentAction } from \"~/components/ToolbarActions/TextAlignmentAction\";\n\nexport const ParagraphToolbarPreset = () => {\n return (\n <>\n <AddToolbarAction element={<FontSizeAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<FontColorAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<TypographyAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<TextAlignmentAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<Divider />} type={\"paragraph\"} />\n <AddToolbarAction element={<BoldAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<ItalicAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<UnderlineAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<CodeHighlightAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<Divider />} type={\"paragraph\"} />\n <AddToolbarAction element={<NumberedListAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<BulletListAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<Divider />} type={\"paragraph\"} />\n <AddToolbarAction element={<LinkAction />} type={\"paragraph\"} />\n <AddToolbarAction element={<QuoteAction />} type={\"paragraph\"} />\n </>\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,GAAS;EACxC,oBACI,yEACI,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACpE,6BAAC,kCAAgB;IAAC,OAAO,eAAE,6BAAC,gCAAe,OAAI;IAAC,IAAI,EAAE;EAAY,EAAG,eACrE,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|
1
1
|
import React from "react";
|
|
2
2
|
import { TextBlockSelection, ThemeEmotionMap, ToolbarType } from "../types";
|
|
3
3
|
import { WebinyTheme } from "../themes/webinyLexicalTheme";
|
|
4
|
+
import { LexicalEditor } from "lexical";
|
|
4
5
|
export interface RichTextEditorContext {
|
|
5
6
|
nodeIsText: boolean;
|
|
6
7
|
setNodeIsText: (nodeIsText: boolean) => void;
|
|
@@ -12,6 +13,10 @@ export interface RichTextEditorContext {
|
|
|
12
13
|
setTheme: (theme: WebinyTheme) => void;
|
|
13
14
|
themeEmotionMap?: ThemeEmotionMap;
|
|
14
15
|
setThemeEmotionMap: (themeEmotionMap?: ThemeEmotionMap) => void;
|
|
16
|
+
activeEditor?: LexicalEditor;
|
|
17
|
+
setActiveEditor: (editor: LexicalEditor) => void;
|
|
18
|
+
isEditable: boolean;
|
|
19
|
+
setIsEditable: (isEditable: boolean) => void;
|
|
15
20
|
}
|
|
16
21
|
export declare const RichTextEditorContext: React.Context<RichTextEditorContext | undefined>;
|
|
17
22
|
interface RichTextEditorProviderProps {
|
|
@@ -28,13 +28,21 @@ var RichTextEditorProvider = function RichTextEditorProvider(_ref) {
|
|
|
28
28
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
29
29
|
themeEmotionMap = _useState8[0],
|
|
30
30
|
setThemeEmotionMap = _useState8[1];
|
|
31
|
+
var _useState9 = (0, _react.useState)(),
|
|
32
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
33
|
+
activeEditor = _useState10[0],
|
|
34
|
+
setActiveEditor = _useState10[1];
|
|
35
|
+
var _useState11 = (0, _react.useState)(false),
|
|
36
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
37
|
+
isEditable = _useState12[0],
|
|
38
|
+
setIsEditable = _useState12[1];
|
|
31
39
|
/*
|
|
32
40
|
* @desc Keeps data from current user text selection like range selection, nodes, node key...
|
|
33
41
|
*/
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
textBlockSelection =
|
|
37
|
-
setTextBlockSelection =
|
|
42
|
+
var _useState13 = (0, _react.useState)(null),
|
|
43
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
44
|
+
textBlockSelection = _useState14[0],
|
|
45
|
+
setTextBlockSelection = _useState14[1];
|
|
38
46
|
var setNodeIsText = function setNodeIsText(nodeIsText) {
|
|
39
47
|
setIsText(nodeIsText);
|
|
40
48
|
};
|
|
@@ -49,7 +57,11 @@ var RichTextEditorProvider = function RichTextEditorProvider(_ref) {
|
|
|
49
57
|
theme: theme,
|
|
50
58
|
setTheme: setTheme,
|
|
51
59
|
themeEmotionMap: themeEmotionMap,
|
|
52
|
-
setThemeEmotionMap: setThemeEmotionMap
|
|
60
|
+
setThemeEmotionMap: setThemeEmotionMap,
|
|
61
|
+
activeEditor: activeEditor,
|
|
62
|
+
setActiveEditor: setActiveEditor,
|
|
63
|
+
isEditable: isEditable,
|
|
64
|
+
setIsEditable: setIsEditable
|
|
53
65
|
}
|
|
54
66
|
}, children);
|
|
55
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RichTextEditorContext","createContext","undefined","RichTextEditorProvider","children","useState","nodeIsText","setIsText","toolbarType","setToolbarType","theme","setTheme","themeEmotionMap","setThemeEmotionMap","textBlockSelection","setTextBlockSelection","setNodeIsText"],"sources":["RichTextEditorContext.tsx"],"sourcesContent":["import React, { createContext, useState } from \"react\";\nimport { TextBlockSelection, ThemeEmotionMap, ToolbarType } from \"~/types\";\nimport { WebinyTheme } from \"~/themes/webinyLexicalTheme\";\n\nexport interface RichTextEditorContext {\n nodeIsText: boolean;\n setNodeIsText: (nodeIsText: boolean) => void;\n toolbarType?: ToolbarType;\n setToolbarType: (type: ToolbarType) => void;\n textBlockSelection: TextBlockSelection | null;\n setTextBlockSelection: (textBlockSelection: TextBlockSelection) => void;\n theme?: WebinyTheme;\n setTheme: (theme: WebinyTheme) => void;\n themeEmotionMap?: ThemeEmotionMap;\n setThemeEmotionMap: (themeEmotionMap?: ThemeEmotionMap) => void;\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContext | undefined>(undefined);\n\ninterface RichTextEditorProviderProps {\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const RichTextEditorProvider: React.FC<RichTextEditorProviderProps> = ({ children }) => {\n const [nodeIsText, setIsText] = useState<boolean>(false);\n const [toolbarType, setToolbarType] = useState<ToolbarType | undefined>();\n const [theme, setTheme] = useState<WebinyTheme | undefined>(undefined);\n const [themeEmotionMap, setThemeEmotionMap] = useState<ThemeEmotionMap | undefined>(undefined);\n /*\n * @desc Keeps data from current user text selection like range selection, nodes, node key...\n */\n const [textBlockSelection, setTextBlockSelection] = useState<TextBlockSelection | null>(null);\n\n const setNodeIsText = (nodeIsText: boolean) => {\n setIsText(nodeIsText);\n };\n\n return (\n <RichTextEditorContext.Provider\n value={{\n nodeIsText,\n setNodeIsText,\n toolbarType,\n setToolbarType,\n textBlockSelection,\n setTextBlockSelection,\n theme,\n setTheme,\n themeEmotionMap,\n setThemeEmotionMap\n }}\n >\n {children}\n </RichTextEditorContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;
|
|
1
|
+
{"version":3,"names":["RichTextEditorContext","createContext","undefined","RichTextEditorProvider","children","useState","nodeIsText","setIsText","toolbarType","setToolbarType","theme","setTheme","themeEmotionMap","setThemeEmotionMap","activeEditor","setActiveEditor","isEditable","setIsEditable","textBlockSelection","setTextBlockSelection","setNodeIsText"],"sources":["RichTextEditorContext.tsx"],"sourcesContent":["import React, { createContext, useState } from \"react\";\nimport { TextBlockSelection, ThemeEmotionMap, ToolbarType } from \"~/types\";\nimport { WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { LexicalEditor } from \"lexical\";\n\nexport interface RichTextEditorContext {\n nodeIsText: boolean;\n setNodeIsText: (nodeIsText: boolean) => void;\n toolbarType?: ToolbarType;\n setToolbarType: (type: ToolbarType) => void;\n textBlockSelection: TextBlockSelection | null;\n setTextBlockSelection: (textBlockSelection: TextBlockSelection) => void;\n theme?: WebinyTheme;\n setTheme: (theme: WebinyTheme) => void;\n themeEmotionMap?: ThemeEmotionMap;\n setThemeEmotionMap: (themeEmotionMap?: ThemeEmotionMap) => void;\n activeEditor?: LexicalEditor;\n setActiveEditor: (editor: LexicalEditor) => void;\n isEditable: boolean;\n setIsEditable: (isEditable: boolean) => void;\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContext | undefined>(undefined);\n\ninterface RichTextEditorProviderProps {\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const RichTextEditorProvider: React.FC<RichTextEditorProviderProps> = ({ children }) => {\n const [nodeIsText, setIsText] = useState<boolean>(false);\n const [toolbarType, setToolbarType] = useState<ToolbarType | undefined>();\n const [theme, setTheme] = useState<WebinyTheme | undefined>(undefined);\n const [themeEmotionMap, setThemeEmotionMap] = useState<ThemeEmotionMap | undefined>(undefined);\n const [activeEditor, setActiveEditor] = useState<LexicalEditor>();\n const [isEditable, setIsEditable] = useState<boolean>(false);\n /*\n * @desc Keeps data from current user text selection like range selection, nodes, node key...\n */\n const [textBlockSelection, setTextBlockSelection] = useState<TextBlockSelection | null>(null);\n\n const setNodeIsText = (nodeIsText: boolean) => {\n setIsText(nodeIsText);\n };\n\n return (\n <RichTextEditorContext.Provider\n value={{\n nodeIsText,\n setNodeIsText,\n toolbarType,\n setToolbarType,\n textBlockSelection,\n setTextBlockSelection,\n theme,\n setTheme,\n themeEmotionMap,\n setThemeEmotionMap,\n activeEditor,\n setActiveEditor,\n isEditable,\n setIsEditable\n }}\n >\n {children}\n </RichTextEditorContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AAsBO,IAAMA,qBAAqB,gBAAG,IAAAC,oBAAa,EAAoCC,SAAS,CAAC;AAAC;AAM1F,IAAMC,sBAA6D,GAAG,SAAhEA,sBAA6D,OAAqB;EAAA,IAAfC,QAAQ,QAARA,QAAQ;EACpF,gBAAgC,IAAAC,eAAQ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face TextAlignmentActionContextProps {
|
|
4
|
+
value: ElementFormatType;
|
|
5
|
+
applyTextAlignment: (value: ElementFormatType) => void;
|
|
6
|
+
outdentText: () => void;
|
|
7
|
+
indentText: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const TextAlignmentActionContext: React.Context<TextAlignmentActionContextProps | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TextAlignmentActionContext = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var TextAlignmentActionContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
10
|
+
exports.TextAlignmentActionContext = TextAlignmentActionContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TextAlignmentActionContext","React","createContext","undefined"],"sources":["TextAlignmentActionContextProps.tsx"],"sourcesContent":["import React from \"react\";\nimport { ElementFormatType } from \"lexical\";\n\nexport interface TextAlignmentActionContextProps {\n /*\n * Selected text alignment value\n * */\n value: ElementFormatType;\n\n /*\n * Apply text alignment to selected text\n */\n applyTextAlignment: (value: ElementFormatType) => void;\n\n outdentText: () => void;\n\n indentText: () => void;\n}\n\nexport const TextAlignmentActionContext = React.createContext<\n TextAlignmentActionContextProps | undefined\n>(undefined);\n"],"mappings":";;;;;;;AAAA;AAmBO,IAAMA,0BAA0B,gBAAGC,cAAK,CAACC,aAAa,CAE3DC,SAAS,CAAC;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useTextAlignmentAction(): import("../context/TextAlignmentActionContextProps").TextAlignmentActionContextProps;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTextAlignmentAction = useTextAlignmentAction;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _TextAlignmentActionContextProps = require("../context/TextAlignmentActionContextProps");
|
|
9
|
+
function useTextAlignmentAction() {
|
|
10
|
+
var context = (0, _react.useContext)(_TextAlignmentActionContextProps.TextAlignmentActionContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw Error("Missing TextAlignmentActionContext in the component hierarchy. Are you using \"useTextAlignmentAction()\" in the right place?");
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useTextAlignmentAction","context","useContext","TextAlignmentActionContext","Error"],"sources":["useTextAlignmentAction.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { TextAlignmentActionContext } from \"~/context/TextAlignmentActionContextProps\";\n\nexport function useTextAlignmentAction() {\n const context = useContext(TextAlignmentActionContext);\n if (!context) {\n throw Error(\n `Missing TextAlignmentActionContext in the component hierarchy. Are you using \"useTextAlignmentAction()\" in the right place?`\n );\n }\n\n return context;\n}\n"],"mappings":";;;;;;AAAA;AACA;AAEO,SAASA,sBAAsB,GAAG;EACrC,IAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACC,2DAA0B,CAAC;EACtD,IAAI,CAACF,OAAO,EAAE;IACV,MAAMG,KAAK,iIAEV;EACL;EAEA,OAAOH,OAAO;AAClB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-left" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm.646 2.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L4.293 8 2.646 6.354a.5.5 0 0 1 0-.708zM7 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5zm-5 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-justify" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-right" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm10.646 2.146a.5.5 0 0 1 .708.708L11.707 8l1.647 1.646a.5.5 0 0 1-.708.708l-2-2a.5.5 0 0 1 0-.708l2-2zM2 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { LexicalHtmlRenderer } from "./components/LexicalHtmlRenderer";
|
|
|
2
2
|
export { useRichTextEditor } from "./hooks/useRichTextEditor";
|
|
3
3
|
export { useFontColorPicker } from "./hooks/useFontColorPicker";
|
|
4
4
|
export { useTypographyAction } from "./hooks/useTypographyAction";
|
|
5
|
+
export { useTextAlignmentAction } from "./hooks/useTextAlignmentAction";
|
|
5
6
|
export { Divider } from "./ui/Divider";
|
|
6
7
|
export { DropDownItem } from "./ui/DropDown";
|
|
7
8
|
export { DropDown } from "./ui/DropDown";
|
|
@@ -16,6 +17,7 @@ export { NumberedListAction } from "./components/ToolbarActions/NumberedListActi
|
|
|
16
17
|
export { QuoteAction } from "./components/ToolbarActions/QuoteAction";
|
|
17
18
|
export { UnderlineAction } from "./components/ToolbarActions/UnderlineAction";
|
|
18
19
|
export { TypographyAction } from "./components/ToolbarActions/TypographyAction";
|
|
20
|
+
export { TextAlignmentAction } from "./components/ToolbarActions/TextAlignmentAction";
|
|
19
21
|
export { HeadingToolbar } from "./components/Toolbar/HeadingToolbar";
|
|
20
22
|
export { ParagraphToolbar } from "./components/Toolbar/ParagraphToolbar";
|
|
21
23
|
export { Toolbar } from "./components/Toolbar/Toolbar";
|
package/index.js
CHANGED
|
@@ -184,6 +184,12 @@ Object.defineProperty(exports, "RichTextEditor", {
|
|
|
184
184
|
return _RichTextEditor.RichTextEditor;
|
|
185
185
|
}
|
|
186
186
|
});
|
|
187
|
+
Object.defineProperty(exports, "TextAlignmentAction", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
get: function get() {
|
|
190
|
+
return _TextAlignmentAction.TextAlignmentAction;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
187
193
|
Object.defineProperty(exports, "Toolbar", {
|
|
188
194
|
enumerable: true,
|
|
189
195
|
get: function get() {
|
|
@@ -233,6 +239,12 @@ Object.defineProperty(exports, "useRichTextEditor", {
|
|
|
233
239
|
return _useRichTextEditor.useRichTextEditor;
|
|
234
240
|
}
|
|
235
241
|
});
|
|
242
|
+
Object.defineProperty(exports, "useTextAlignmentAction", {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function get() {
|
|
245
|
+
return _useTextAlignmentAction.useTextAlignmentAction;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
236
248
|
Object.defineProperty(exports, "useTypographyAction", {
|
|
237
249
|
enumerable: true,
|
|
238
250
|
get: function get() {
|
|
@@ -243,6 +255,7 @@ var _LexicalHtmlRenderer = require("./components/LexicalHtmlRenderer");
|
|
|
243
255
|
var _useRichTextEditor = require("./hooks/useRichTextEditor");
|
|
244
256
|
var _useFontColorPicker = require("./hooks/useFontColorPicker");
|
|
245
257
|
var _useTypographyAction = require("./hooks/useTypographyAction");
|
|
258
|
+
var _useTextAlignmentAction = require("./hooks/useTextAlignmentAction");
|
|
246
259
|
var _Divider = require("./ui/Divider");
|
|
247
260
|
var _DropDown = require("./ui/DropDown");
|
|
248
261
|
var _BoldAction = require("./components/ToolbarActions/BoldAction");
|
|
@@ -256,6 +269,7 @@ var _NumberedListAction = require("./components/ToolbarActions/NumberedListActio
|
|
|
256
269
|
var _QuoteAction = require("./components/ToolbarActions/QuoteAction");
|
|
257
270
|
var _UnderlineAction = require("./components/ToolbarActions/UnderlineAction");
|
|
258
271
|
var _TypographyAction = require("./components/ToolbarActions/TypographyAction");
|
|
272
|
+
var _TextAlignmentAction = require("./components/ToolbarActions/TextAlignmentAction");
|
|
259
273
|
var _HeadingToolbar = require("./components/Toolbar/HeadingToolbar");
|
|
260
274
|
var _ParagraphToolbar = require("./components/Toolbar/ParagraphToolbar");
|
|
261
275
|
var _Toolbar = require("./components/Toolbar/Toolbar");
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.tsx"],"sourcesContent":["// render\nexport { LexicalHtmlRenderer } from \"~/components/LexicalHtmlRenderer\";\n// hooks\nexport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nexport { useFontColorPicker } from \"~/hooks/useFontColorPicker\";\nexport { useTypographyAction } from \"~/hooks/useTypographyAction\";\n// UI elements\nexport { Divider } from \"~/ui/Divider\";\nexport { DropDownItem } from \"~/ui/DropDown\";\nexport { DropDown } from \"~/ui/DropDown\";\n// actions\nexport { BoldAction } from \"~/components/ToolbarActions/BoldAction\";\nexport { BulletListAction } from \"~/components/ToolbarActions/BulletListAction\";\nexport { CodeHighlightAction } from \"~/components/ToolbarActions/CodeHighlightAction\";\nexport { FontSizeAction } from \"~/components/ToolbarActions/FontSizeAction\";\nexport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nexport { ItalicAction } from \"~/components/ToolbarActions/ItalicAction\";\nexport { LinkAction } from \"~/components/ToolbarActions/LinkAction\";\nexport { NumberedListAction } from \"~/components/ToolbarActions/NumberedListAction\";\nexport { QuoteAction } from \"~/components/ToolbarActions/QuoteAction\";\nexport { UnderlineAction } from \"~/components/ToolbarActions/UnderlineAction\";\nexport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\n// toolbars\nexport { HeadingToolbar } from \"~/components/Toolbar/HeadingToolbar\";\nexport { ParagraphToolbar } from \"~/components/Toolbar/ParagraphToolbar\";\nexport { Toolbar } from \"~/components/Toolbar/Toolbar\";\n// presets\nexport { ParagraphToolbarPreset } from \"~/components/ToolbarPresets/ParagraphToolbarPreset\";\nexport { HeadingToolbarPreset } from \"./components/ToolbarPresets/HeadingToolbarPreset\";\n// editor\nexport { RichTextEditor } from \"~/components/Editor/RichTextEditor\";\nexport { HeadingEditor } from \"~/components/Editor/HeadingEditor\";\nexport { ParagraphEditor } from \"~/components/Editor/ParagraphEditor\";\n// plugins\nexport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nexport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nexport { CodeHighlightPlugin } from \"~/plugins/CodeHighlightPlugin/CodeHighlightPlugin\";\nexport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nexport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nexport { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin\";\n// composition\nexport { AddToolbarAction } from \"~/components/AddToolbarAction\";\nexport { AddRichTextEditorPlugin } from \"~/components/AddRichTextEditorPlugin\";\nexport { AddRichTextEditorNodeType } from \"~/components/AddRichTextEditorNodeType\";\n// utils\nexport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nexport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nexport { clearNodeFormatting } from \"~/utils/nodes/clearNodeFormating\";\n// types\nexport * as types from \"./types\";\n// config\nexport { LexicalEditorConfig } from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.tsx"],"sourcesContent":["// render\nexport { LexicalHtmlRenderer } from \"~/components/LexicalHtmlRenderer\";\n// hooks\nexport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nexport { useFontColorPicker } from \"~/hooks/useFontColorPicker\";\nexport { useTypographyAction } from \"~/hooks/useTypographyAction\";\nexport { useTextAlignmentAction } from \"~/hooks/useTextAlignmentAction\";\n// UI elements\nexport { Divider } from \"~/ui/Divider\";\nexport { DropDownItem } from \"~/ui/DropDown\";\nexport { DropDown } from \"~/ui/DropDown\";\n// actions\nexport { BoldAction } from \"~/components/ToolbarActions/BoldAction\";\nexport { BulletListAction } from \"~/components/ToolbarActions/BulletListAction\";\nexport { CodeHighlightAction } from \"~/components/ToolbarActions/CodeHighlightAction\";\nexport { FontSizeAction } from \"~/components/ToolbarActions/FontSizeAction\";\nexport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nexport { ItalicAction } from \"~/components/ToolbarActions/ItalicAction\";\nexport { LinkAction } from \"~/components/ToolbarActions/LinkAction\";\nexport { NumberedListAction } from \"~/components/ToolbarActions/NumberedListAction\";\nexport { QuoteAction } from \"~/components/ToolbarActions/QuoteAction\";\nexport { UnderlineAction } from \"~/components/ToolbarActions/UnderlineAction\";\nexport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\nexport { TextAlignmentAction } from \"~/components/ToolbarActions/TextAlignmentAction\";\n// toolbars\nexport { HeadingToolbar } from \"~/components/Toolbar/HeadingToolbar\";\nexport { ParagraphToolbar } from \"~/components/Toolbar/ParagraphToolbar\";\nexport { Toolbar } from \"~/components/Toolbar/Toolbar\";\n// presets\nexport { ParagraphToolbarPreset } from \"~/components/ToolbarPresets/ParagraphToolbarPreset\";\nexport { HeadingToolbarPreset } from \"./components/ToolbarPresets/HeadingToolbarPreset\";\n// editor\nexport { RichTextEditor } from \"~/components/Editor/RichTextEditor\";\nexport { HeadingEditor } from \"~/components/Editor/HeadingEditor\";\nexport { ParagraphEditor } from \"~/components/Editor/ParagraphEditor\";\n// plugins\nexport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nexport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nexport { CodeHighlightPlugin } from \"~/plugins/CodeHighlightPlugin/CodeHighlightPlugin\";\nexport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nexport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nexport { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin\";\n// composition\nexport { AddToolbarAction } from \"~/components/AddToolbarAction\";\nexport { AddRichTextEditorPlugin } from \"~/components/AddRichTextEditorPlugin\";\nexport { AddRichTextEditorNodeType } from \"~/components/AddRichTextEditorNodeType\";\n// utils\nexport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nexport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nexport { clearNodeFormatting } from \"~/utils/nodes/clearNodeFormating\";\n// types\nexport * as types from \"./types\";\n// config\nexport { LexicalEditorConfig } from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAAuE;AAAA;AAIvE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/lexical-editor",
|
|
3
|
-
"version": "5.36.2-beta.
|
|
3
|
+
"version": "5.36.2-beta.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"@lexical/rich-text": "0.10.0",
|
|
20
20
|
"@lexical/selection": "0.10.0",
|
|
21
21
|
"@lexical/utils": "0.10.0",
|
|
22
|
-
"@webiny/react-composition": "5.36.2-beta.
|
|
22
|
+
"@webiny/react-composition": "5.36.2-beta.2",
|
|
23
23
|
"lexical": "0.10.0",
|
|
24
24
|
"react": "17.0.2",
|
|
25
25
|
"react-dom": "17.0.2",
|
|
26
26
|
"react-style-object-to-css": "1.1.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@webiny/cli": "5.36.2-beta.
|
|
30
|
-
"@webiny/project-utils": "5.36.2-beta.
|
|
29
|
+
"@webiny/cli": "5.36.2-beta.2",
|
|
30
|
+
"@webiny/project-utils": "5.36.2-beta.2"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"build": "yarn webiny run build",
|
|
38
38
|
"watch": "yarn webiny run watch"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "908c591cd08d81da267ed6152e880b52e1157c8b"
|
|
41
41
|
}
|
package/types.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare type ToolbarState = {
|
|
|
19
19
|
underline: boolean;
|
|
20
20
|
italic: boolean;
|
|
21
21
|
code: boolean;
|
|
22
|
+
isRTL: boolean;
|
|
22
23
|
link: NodeState;
|
|
23
24
|
typography: NodeState;
|
|
24
25
|
fontColor: NodeState;
|
|
@@ -36,6 +37,7 @@ export declare type TextBlockSelection = {
|
|
|
36
37
|
node: ElementNode | TextNode;
|
|
37
38
|
anchorNode: ElementNode | TextNode;
|
|
38
39
|
isElementDom: boolean;
|
|
40
|
+
selectedText: string;
|
|
39
41
|
state: ToolbarState | undefined;
|
|
40
42
|
};
|
|
41
43
|
export declare type ListHtmlTag = "ol" | "ul";
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { ElementNode, LexicalNode, NodeSelection, RangeSelection, TextNode } from \"lexical\";\nimport { ListType } from \"@lexical/list\";\nimport { CSSObject } from \"@emotion/react\";\nexport type ToolbarType = \"heading\" | \"paragraph\" | string;\nexport type LexicalValue = string;\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type LexicalTextType =\n | ListType\n | \"paragraph\"\n | \"heading\"\n | \"quoteblock\"\n | \"bullet\"\n | \"number\"\n | \"link\"\n | undefined;\n\nexport type TextFormatting = {\n bold: boolean;\n underline: boolean;\n italic: boolean;\n // highlight: boolean #TODO implement with highlight action\n code: boolean;\n};\n\nexport type NodeState = {\n isSelected: boolean;\n};\n\nexport type ToolbarState = {\n // text format\n bold: boolean;\n underline: boolean;\n italic: boolean;\n code: boolean;\n // nodes selection state\n link: NodeState;\n typography: NodeState;\n fontColor: NodeState;\n list: NodeState;\n quote: NodeState;\n textType: LexicalTextType;\n paragraph: NodeState;\n heading: NodeState;\n};\n\n/*\n * Represent set of data from the current selection of the text and nodes selected by the user.\n * You can access this object through the @see useRichTextEditor context.\n */\nexport type TextBlockSelection = {\n elementKey?: string;\n selection: RangeSelection | NodeSelection | null;\n element: LexicalNode;\n parent: ElementNode | null;\n node: ElementNode | TextNode;\n anchorNode: ElementNode | TextNode;\n isElementDom: boolean;\n state: ToolbarState | undefined;\n};\n\n// Supported HTML tags by webiny lexical implementation\nexport type ListHtmlTag = \"ol\" | \"ul\";\nexport type HeadingHtmlTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\nexport type ParagraphHtmlTag = \"p\";\nexport type QuoteBlockHtmlTag = \"quoteblock\";\n\n// Typography\nexport type TypographyHTMLTag = HeadingHtmlTag | ParagraphHtmlTag | ListHtmlTag | QuoteBlockHtmlTag;\n\nexport type TypographyValue = {\n // CSSObject type\n css: CSSObject;\n id: string;\n tag: TypographyHTMLTag;\n // Display name\n name: string;\n};\n\n/* Nodes */\n\n/*\n * Contains IDs of the styles and Emotion generated classes.\n */\nexport type ThemeEmotionMap = {\n [styleId: string]: {\n id: string;\n tag: TypographyHTMLTag;\n name: string;\n styles: Record<string, any>;\n // emotion generated class\n className: string;\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA"}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { ElementNode, LexicalNode, NodeSelection, RangeSelection, TextNode } from \"lexical\";\nimport { ListType } from \"@lexical/list\";\nimport { CSSObject } from \"@emotion/react\";\nexport type ToolbarType = \"heading\" | \"paragraph\" | string;\nexport type LexicalValue = string;\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type LexicalTextType =\n | ListType\n | \"paragraph\"\n | \"heading\"\n | \"quoteblock\"\n | \"bullet\"\n | \"number\"\n | \"link\"\n | undefined;\n\nexport type TextFormatting = {\n bold: boolean;\n underline: boolean;\n italic: boolean;\n // highlight: boolean #TODO implement with highlight action\n code: boolean;\n};\n\nexport type NodeState = {\n isSelected: boolean;\n};\n\nexport type ToolbarState = {\n // text format\n bold: boolean;\n underline: boolean;\n italic: boolean;\n code: boolean;\n // is direction of the text right-to-left\n isRTL: boolean;\n // nodes selection state\n link: NodeState;\n typography: NodeState;\n fontColor: NodeState;\n list: NodeState;\n quote: NodeState;\n textType: LexicalTextType;\n paragraph: NodeState;\n heading: NodeState;\n};\n\n/*\n * Represent set of data from the current selection of the text and nodes selected by the user.\n * You can access this object through the @see useRichTextEditor context.\n */\nexport type TextBlockSelection = {\n elementKey?: string;\n selection: RangeSelection | NodeSelection | null;\n element: LexicalNode;\n parent: ElementNode | null;\n node: ElementNode | TextNode;\n anchorNode: ElementNode | TextNode;\n isElementDom: boolean;\n selectedText: string;\n state: ToolbarState | undefined;\n};\n\n// Supported HTML tags by webiny lexical implementation\nexport type ListHtmlTag = \"ol\" | \"ul\";\nexport type HeadingHtmlTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\nexport type ParagraphHtmlTag = \"p\";\nexport type QuoteBlockHtmlTag = \"quoteblock\";\n\n// Typography\nexport type TypographyHTMLTag = HeadingHtmlTag | ParagraphHtmlTag | ListHtmlTag | QuoteBlockHtmlTag;\n\nexport type TypographyValue = {\n // CSSObject type\n css: CSSObject;\n id: string;\n tag: TypographyHTMLTag;\n // Display name\n name: string;\n};\n\n/* Nodes */\n\n/*\n * Contains IDs of the styles and Emotion generated classes.\n */\nexport type ThemeEmotionMap = {\n [styleId: string]: {\n id: string;\n tag: TypographyHTMLTag;\n name: string;\n styles: Record<string, any>;\n // emotion generated class\n className: string;\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA"}
|
|
@@ -17,6 +17,7 @@ var _FontColorNode = require("../nodes/FontColorNode");
|
|
|
17
17
|
var _ParagraphNode = require("../nodes/ParagraphNode");
|
|
18
18
|
var _HeadingNode = require("../nodes/HeadingNode");
|
|
19
19
|
var _QuoteNode = require("../nodes/QuoteNode");
|
|
20
|
+
var _selection = require("@lexical/selection");
|
|
20
21
|
var getSelectionTextFormat = function getSelectionTextFormat(selection) {
|
|
21
22
|
return !(0, _lexical.$isRangeSelection)(selection) ? {
|
|
22
23
|
italic: false,
|
|
@@ -37,6 +38,7 @@ var getDefaultToolbarState = function getDefaultToolbarState() {
|
|
|
37
38
|
italic: false,
|
|
38
39
|
underline: false,
|
|
39
40
|
code: false,
|
|
41
|
+
isRTL: false,
|
|
40
42
|
link: {
|
|
41
43
|
isSelected: false
|
|
42
44
|
},
|
|
@@ -70,12 +72,14 @@ var getToolbarState = function getToolbarState(selection, node, parent, element,
|
|
|
70
72
|
underline: textFormat.underline,
|
|
71
73
|
code: textFormat.code
|
|
72
74
|
});
|
|
75
|
+
state.isRTL = (0, _selection.$isParentElementRTL)(selection);
|
|
73
76
|
|
|
74
77
|
// link
|
|
75
78
|
state.link.isSelected = (0, _link.$isLinkNode)(parent) || (0, _link.$isLinkNode)(node);
|
|
76
79
|
if (state.link.isSelected) {
|
|
77
80
|
state.textType = "link";
|
|
78
81
|
}
|
|
82
|
+
|
|
79
83
|
// font color
|
|
80
84
|
if ((0, _FontColorNode.$isFontColorNode)(node)) {
|
|
81
85
|
state.fontColor.isSelected = true;
|
|
@@ -140,6 +144,7 @@ var getLexicalTextSelectionState = function getLexicalTextSelectionState(activeE
|
|
|
140
144
|
var node = (0, _getSelectedNode.getSelectedNode)(selection);
|
|
141
145
|
var parent = node.getParent();
|
|
142
146
|
var isElementDom = elementDOM !== null;
|
|
147
|
+
var selectedText = selection.getTextContent();
|
|
143
148
|
return {
|
|
144
149
|
// node/element data from selection
|
|
145
150
|
elementKey: elementKey,
|
|
@@ -149,6 +154,7 @@ var getLexicalTextSelectionState = function getLexicalTextSelectionState(activeE
|
|
|
149
154
|
anchorNode: anchorNode,
|
|
150
155
|
selection: selection,
|
|
151
156
|
isElementDom: isElementDom,
|
|
157
|
+
selectedText: selectedText,
|
|
152
158
|
state: getToolbarState(selection, node, parent, element, anchorNode)
|
|
153
159
|
};
|
|
154
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getSelectionTextFormat","selection","$isRangeSelection","italic","bold","underline","code","hasFormat","getDefaultToolbarState","link","isSelected","list","typography","fontColor","quote","paragraph","heading","textType","undefined","getToolbarState","node","parent","element","anchorNode","textFormat","state","$isLinkNode","$isFontColorNode","$isListNode","parentList","$getNearestNodeOfType","ListNode","type","getListType","$isBaseHeadingNode","$isHeadingNode","$isBaseParagraphNode","$isParagraphNode","$isTypographyElementNode","value","getTypographyValue","tag","includes","$isQuoteNode","getLexicalTextSelectionState","activeEditor","anchor","getNode","getKey","$findMatchingParent","e","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","elementKey","elementDOM","getElementByKey","getSelectedNode","isElementDom"],"sources":["getLexicalTextSelectionState.ts"],"sourcesContent":["import { TextFormatting, TextBlockSelection, ToolbarState, TypographyValue } from \"~/types\";\nimport {\n $isParagraphNode as $isBaseParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n ElementNode,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n TextNode\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType } from \"@lexical/utils\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { $isListNode, ListNode } from \"~/nodes/ListNode\";\nimport { $isHeadingNode as $isBaseHeadingNode } from \"@lexical/rich-text\";\nimport { $isTypographyElementNode } from \"~/nodes/TypographyElementNode\";\nimport { $isFontColorNode } from \"~/nodes/FontColorNode\";\nimport { $isParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $isHeadingNode } from \"~/nodes/HeadingNode\";\nimport { $isQuoteNode } from \"~/nodes/QuoteNode\";\n\nexport const getSelectionTextFormat = (selection: RangeSelection | undefined): TextFormatting => {\n return !$isRangeSelection(selection)\n ? {\n italic: false,\n bold: false,\n underline: false,\n code: false\n }\n : {\n bold: selection.hasFormat(\"bold\"),\n italic: selection.hasFormat(\"italic\"),\n underline: selection.hasFormat(\"underline\"),\n code: selection.hasFormat(\"code\")\n };\n};\n\nconst getDefaultToolbarState = (): ToolbarState => {\n return {\n bold: false,\n italic: false,\n underline: false,\n code: false,\n link: { isSelected: false },\n list: { isSelected: false },\n typography: { isSelected: false },\n fontColor: { isSelected: false },\n quote: { isSelected: false },\n paragraph: { isSelected: false },\n heading: { isSelected: false },\n textType: undefined\n };\n};\n\nexport const getToolbarState = (\n selection: RangeSelection,\n node: LexicalNode,\n parent: LexicalNode | null,\n element: LexicalNode | null,\n anchorNode: ElementNode | TextNode\n): ToolbarState => {\n const textFormat = getSelectionTextFormat(selection);\n let state: ToolbarState = getDefaultToolbarState();\n state = {\n ...state,\n bold: textFormat.bold,\n italic: textFormat.italic,\n underline: textFormat.underline,\n code: textFormat.code\n };\n\n // link\n state.link.isSelected = $isLinkNode(parent) || $isLinkNode(node);\n if (state.link.isSelected) {\n state.textType = \"link\";\n }\n // font color\n if ($isFontColorNode(node)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isListNode(element)) {\n const parentList = $getNearestNodeOfType<ListNode>(anchorNode, ListNode);\n const type = parentList ? parentList.getListType() : element.getListType();\n state.textType = type;\n }\n\n if ($isBaseHeadingNode(element)) {\n state.textType = \"heading\";\n }\n\n if ($isHeadingNode(element)) {\n state.textType = \"heading\";\n state.heading.isSelected = true;\n }\n\n if ($isBaseParagraphNode(element)) {\n state.textType = \"paragraph\";\n }\n\n if ($isParagraphNode(element)) {\n state.textType = \"paragraph\";\n state.paragraph.isSelected = true;\n }\n\n if ($isTypographyElementNode(element)) {\n state.typography.isSelected = true;\n const value = element?.getTypographyValue() as TypographyValue;\n if (value.tag.includes(\"h\")) {\n state.textType = \"heading\";\n }\n if (value.tag.includes(\"p\")) {\n state.textType = \"paragraph\";\n }\n }\n\n if ($isTypographyElementNode(element)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isQuoteNode(element)) {\n state.textType = \"quoteblock\";\n state.quote.isSelected = true;\n }\n\n return state;\n};\n\n/*\n * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.\n */\nexport const getLexicalTextSelectionState = (\n activeEditor: LexicalEditor,\n selection: RangeSelection\n): TextBlockSelection | null => {\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 const elementKey = element.getKey();\n const elementDOM = activeEditor.getElementByKey(elementKey);\n\n // Update links\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n const isElementDom = elementDOM !== null;\n\n return {\n // node/element data from selection\n elementKey,\n element,\n parent,\n node,\n anchorNode,\n selection,\n isElementDom,\n state: getToolbarState(selection, node, parent, element, anchorNode)\n };\n }\n return null;\n};\n"],"mappings":";;;;;;;;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,CAAIC,SAAqC,EAAqB;EAC7F,OAAO,CAAC,IAAAC,0BAAiB,EAACD,SAAS,CAAC,GAC9B;IACIE,MAAM,EAAE,KAAK;IACbC,IAAI,EAAE,KAAK;IACXC,SAAS,EAAE,KAAK;IAChBC,IAAI,EAAE;EACV,CAAC,GACD;IACIF,IAAI,EAAEH,SAAS,CAACM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O,UAAU,GAAGV,YAAY,CAACW,eAAe,CAACF,UAAU,CAAC;;IAE3D;IACA,IAAMlC,IAAI,GAAG,IAAAqC,gCAAe,EAACxD,SAAS,CAAC;IACvC,IAAMoB,MAAM,GAAGD,IAAI,CAAC+B,SAAS,EAAE;IAC/B,IAAMO,YAAY,GAAGH,UAAU,KAAK,IAAI;IAExC,OAAO;MACH;MACAD,UAAU,EAAVA,UAAU;MACVhC,OAAO,EAAPA,OAAO;MACPD,MAAM,EAANA,MAAM;MACND,IAAI,EAAJA,IAAI;MACJG,UAAU,EAAVA,UAAU;MACVtB,SAAS,EAATA,SAAS;MACTyD,YAAY,EAAZA,YAAY;MACZjC,KAAK,EAAEN,eAAe,CAAClB,SAAS,EAAEmB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,UAAU;IACvE,CAAC;EACL;EACA,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["getSelectionTextFormat","selection","$isRangeSelection","italic","bold","underline","code","hasFormat","getDefaultToolbarState","isRTL","link","isSelected","list","typography","fontColor","quote","paragraph","heading","textType","undefined","getToolbarState","node","parent","element","anchorNode","textFormat","state","$isParentElementRTL","$isLinkNode","$isFontColorNode","$isListNode","parentList","$getNearestNodeOfType","ListNode","type","getListType","$isBaseHeadingNode","$isHeadingNode","$isBaseParagraphNode","$isParagraphNode","$isTypographyElementNode","value","getTypographyValue","tag","includes","$isQuoteNode","getLexicalTextSelectionState","activeEditor","anchor","getNode","getKey","$findMatchingParent","e","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","elementKey","elementDOM","getElementByKey","getSelectedNode","isElementDom","selectedText","getTextContent"],"sources":["getLexicalTextSelectionState.ts"],"sourcesContent":["import { TextFormatting, TextBlockSelection, ToolbarState, TypographyValue } from \"~/types\";\nimport {\n $isParagraphNode as $isBaseParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n ElementNode,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n TextNode\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType } from \"@lexical/utils\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { $isListNode, ListNode } from \"~/nodes/ListNode\";\nimport { $isHeadingNode as $isBaseHeadingNode } from \"@lexical/rich-text\";\nimport { $isTypographyElementNode } from \"~/nodes/TypographyElementNode\";\nimport { $isFontColorNode } from \"~/nodes/FontColorNode\";\nimport { $isParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $isHeadingNode } from \"~/nodes/HeadingNode\";\nimport { $isQuoteNode } from \"~/nodes/QuoteNode\";\nimport { $isParentElementRTL } from \"@lexical/selection\";\n\nexport const getSelectionTextFormat = (selection: RangeSelection | undefined): TextFormatting => {\n return !$isRangeSelection(selection)\n ? {\n italic: false,\n bold: false,\n underline: false,\n code: false\n }\n : {\n bold: selection.hasFormat(\"bold\"),\n italic: selection.hasFormat(\"italic\"),\n underline: selection.hasFormat(\"underline\"),\n code: selection.hasFormat(\"code\")\n };\n};\n\nconst getDefaultToolbarState = (): ToolbarState => {\n return {\n bold: false,\n italic: false,\n underline: false,\n code: false,\n isRTL: false,\n link: { isSelected: false },\n list: { isSelected: false },\n typography: { isSelected: false },\n fontColor: { isSelected: false },\n quote: { isSelected: false },\n paragraph: { isSelected: false },\n heading: { isSelected: false },\n textType: undefined\n };\n};\n\nexport const getToolbarState = (\n selection: RangeSelection,\n node: LexicalNode,\n parent: LexicalNode | null,\n element: LexicalNode | null,\n anchorNode: ElementNode | TextNode\n): ToolbarState => {\n const textFormat = getSelectionTextFormat(selection);\n let state: ToolbarState = getDefaultToolbarState();\n state = {\n ...state,\n bold: textFormat.bold,\n italic: textFormat.italic,\n underline: textFormat.underline,\n code: textFormat.code\n };\n\n state.isRTL = $isParentElementRTL(selection);\n\n // link\n state.link.isSelected = $isLinkNode(parent) || $isLinkNode(node);\n if (state.link.isSelected) {\n state.textType = \"link\";\n }\n\n // font color\n if ($isFontColorNode(node)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isListNode(element)) {\n const parentList = $getNearestNodeOfType<ListNode>(anchorNode, ListNode);\n const type = parentList ? parentList.getListType() : element.getListType();\n state.textType = type;\n }\n\n if ($isBaseHeadingNode(element)) {\n state.textType = \"heading\";\n }\n\n if ($isHeadingNode(element)) {\n state.textType = \"heading\";\n state.heading.isSelected = true;\n }\n\n if ($isBaseParagraphNode(element)) {\n state.textType = \"paragraph\";\n }\n\n if ($isParagraphNode(element)) {\n state.textType = \"paragraph\";\n state.paragraph.isSelected = true;\n }\n\n if ($isTypographyElementNode(element)) {\n state.typography.isSelected = true;\n const value = element?.getTypographyValue() as TypographyValue;\n if (value.tag.includes(\"h\")) {\n state.textType = \"heading\";\n }\n if (value.tag.includes(\"p\")) {\n state.textType = \"paragraph\";\n }\n }\n\n if ($isTypographyElementNode(element)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isQuoteNode(element)) {\n state.textType = \"quoteblock\";\n state.quote.isSelected = true;\n }\n\n return state;\n};\n\n/*\n * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.\n */\nexport const getLexicalTextSelectionState = (\n activeEditor: LexicalEditor,\n selection: RangeSelection\n): TextBlockSelection | null => {\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 const elementKey = element.getKey();\n const elementDOM = activeEditor.getElementByKey(elementKey);\n\n // Update links\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n const isElementDom = elementDOM !== null;\n const selectedText = selection.getTextContent();\n\n return {\n // node/element data from selection\n elementKey,\n element,\n parent,\n node,\n anchorNode,\n selection,\n isElementDom,\n selectedText,\n state: getToolbarState(selection, node, parent, element, anchorNode)\n };\n }\n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