@innoviatech/lexical-text-editor 2.0.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -288
- package/dist/components/AlignmentSelectionList.js +19 -0
- package/dist/components/ColorPicker.js +30 -0
- package/dist/components/ContentPreview.js +11 -0
- package/dist/components/DisplayControls.d.ts +16 -0
- package/dist/components/DropdownList.js +18 -0
- package/dist/components/FindReplaceModal.d.ts +11 -0
- package/dist/components/FindReplaceModal.js +120 -0
- package/dist/components/FontSelectionList.d.ts +17 -0
- package/dist/components/FontSelectionList.js +17 -0
- package/dist/components/HeadingSelectionList.js +19 -0
- package/dist/components/ImageComponent.js +111 -0
- package/dist/components/InsertDropdownList.js +17 -0
- package/dist/components/LexicalTextEditor.d.ts +10 -0
- package/dist/components/LexicalTextEditor.js +128 -0
- package/dist/components/LinkModal.js +47 -0
- package/dist/components/Separator.js +4 -0
- package/dist/components/SourceView.d.ts +13 -0
- package/dist/components/SourceView.js +50 -0
- package/dist/components/StatusBar.d.ts +14 -0
- package/dist/components/StatusBar.js +30 -0
- package/dist/components/ToolbarOverflowModal.d.ts +15 -0
- package/dist/components/common/Dialog.js +27 -0
- package/dist/components/common/Popover.d.ts +10 -1
- package/dist/components/common/Popover.js +37 -0
- package/dist/components/common/Tooltip.d.ts +7 -0
- package/dist/components/common/Tooltip.js +20 -0
- package/dist/components/ui/button.js +35 -0
- package/dist/components/ui/command.js +33 -0
- package/dist/components/ui/dialog.js +35 -0
- package/dist/components/ui/input.js +6 -0
- package/dist/components/ui/popover.js +16 -0
- package/dist/components/ui/scroll-area.js +12 -0
- package/dist/components/ui/tooltip.js +16 -0
- package/dist/constants/index.d.ts +23 -1
- package/dist/constants/index.js +224 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical-editor.css +1 -1
- package/dist/lib/utils.js +5 -0
- package/dist/nodes/ExtendedTextNode.js +140 -0
- package/dist/nodes/ImageNode.js +149 -0
- package/dist/nodes/VideoNode.js +80 -0
- package/dist/nodes/YoutubeNode.js +64 -0
- package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
- package/dist/plugins/CodeBlockPlugin.js +88 -0
- package/dist/plugins/ColorPlugin.js +47 -0
- package/dist/plugins/CustomOnChangePlugin.js +33 -0
- package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
- package/dist/plugins/FontFamilyPlugin.js +53 -0
- package/dist/plugins/FontSizePlugin.d.ts +1 -0
- package/dist/plugins/FontSizePlugin.js +48 -0
- package/dist/plugins/ImagePlugin.js +91 -0
- package/dist/plugins/ListPlugin.js +44 -0
- package/dist/plugins/TablePlugin.d.ts +1 -0
- package/dist/plugins/TablePlugin.js +92 -0
- package/dist/plugins/ToolbarPlugin.d.ts +13 -1
- package/dist/plugins/ToolbarPlugin.js +381 -0
- package/dist/plugins/VideoPlugin.js +49 -0
- package/dist/plugins/YoutubePlugin.js +30 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/editor_screenshot.png +0 -0
- package/package.json +11 -4
- package/googlebd703883f12c69e4.html +0 -1
- package/rollup.config.js +0 -55
- package/src/components/AlignmentSelectionList.tsx +0 -61
- package/src/components/ColorPicker.tsx +0 -66
- package/src/components/ContentPreview.tsx +0 -51
- package/src/components/DropdownList.tsx +0 -57
- package/src/components/HeadingSelectionList.tsx +0 -61
- package/src/components/ImageComponent.tsx +0 -206
- package/src/components/InsertDropdownList.tsx +0 -36
- package/src/components/LexicalTextEditor.tsx +0 -119
- package/src/components/LinkModal.tsx +0 -127
- package/src/components/Separator.tsx +0 -7
- package/src/components/common/Dialog.tsx +0 -47
- package/src/components/common/Popover.tsx +0 -87
- package/src/components/common/Tooltip.tsx +0 -43
- package/src/components/ui/button.tsx +0 -58
- package/src/components/ui/command.tsx +0 -183
- package/src/components/ui/dialog.tsx +0 -142
- package/src/components/ui/input.tsx +0 -21
- package/src/components/ui/popover.tsx +0 -46
- package/src/components/ui/scroll-area.tsx +0 -56
- package/src/components/ui/tooltip.tsx +0 -59
- package/src/constants/index.tsx +0 -177
- package/src/index.ts +0 -6
- package/src/lib/utils.ts +0 -6
- package/src/nodes/ExtendedTextNode.tsx +0 -174
- package/src/nodes/ImageNode.tsx +0 -232
- package/src/nodes/VideoNode.tsx +0 -134
- package/src/nodes/YoutubeNode.tsx +0 -101
- package/src/plugins/ColorPlugin.tsx +0 -85
- package/src/plugins/CustomOnChangePlugin.tsx +0 -50
- package/src/plugins/ImagePlugin.tsx +0 -189
- package/src/plugins/ListPlugin.tsx +0 -58
- package/src/plugins/ToolbarPlugin.tsx +0 -500
- package/src/plugins/VideoPlugin.tsx +0 -100
- package/src/plugins/YoutubePlugin.tsx +0 -83
- package/src/styles/lexical-editor.css +0 -1053
- package/src/types/global.d.ts +0 -34
- package/src/types/other.d.ts +0 -11
- package/src/types/react-icons.d.ts +0 -11
- package/tailwind.config.js +0 -10
- package/tsconfig.json +0 -32
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { HeadingAction, LOW_PRIORIRTY, RICH_BLOCK_OPTIONS, RICH_REDO_UNDO_OPTIONS, RICH_TEXT_OPTIONS, RichTextAction } from "../constants/index";
|
|
3
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
4
|
+
import { $createParagraphNode, $getSelection, $isElementNode, $isRangeSelection, $isTextNode, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from "lexical";
|
|
5
|
+
import { useCallback, useEffect, useState } from "react";
|
|
6
|
+
import { $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
|
|
7
|
+
import { $createHeadingNode, $isHeadingNode } from '@lexical/rich-text';
|
|
8
|
+
import { $wrapNodes } from '@lexical/selection';
|
|
9
|
+
import { $createQuoteNode, $isQuoteNode } from "@lexical/rich-text";
|
|
10
|
+
import { $setBlocksType } from "@lexical/selection";
|
|
11
|
+
import { TOGGLE_LINK_COMMAND, $isLinkNode, } from "@lexical/link";
|
|
12
|
+
import { INSERT_HORIZONTAL_RULE_COMMAND, } from "@lexical/react/LexicalHorizontalRuleNode";
|
|
13
|
+
import { $isListNode, ListNode } from '@lexical/list';
|
|
14
|
+
import { DropdownList } from "../components/DropdownList";
|
|
15
|
+
import Separator from "../components/Separator";
|
|
16
|
+
import { HeadingSelectionList } from "../components/HeadingSelectionList";
|
|
17
|
+
import { IoIosLink } from "react-icons/io";
|
|
18
|
+
import { IoCodeOutline, IoSearchOutline } from "react-icons/io5";
|
|
19
|
+
import { BsFullscreen, BsFullscreenExit } from "react-icons/bs";
|
|
20
|
+
import LinkModal from "../components/LinkModal";
|
|
21
|
+
import FindReplaceModal from "../components/FindReplaceModal";
|
|
22
|
+
import { AlignmentSelectionList } from "../components/AlignmentSelectionList";
|
|
23
|
+
import ColorPlugin from "./ColorPlugin";
|
|
24
|
+
import FontFamilyPlugin from "./FontFamilyPlugin";
|
|
25
|
+
import FontSizePlugin from "./FontSizePlugin";
|
|
26
|
+
import CodeBlockPlugin from "./CodeBlockPlugin";
|
|
27
|
+
import ListPlugin from "./ListPlugin";
|
|
28
|
+
import TablePlugin from "./TablePlugin";
|
|
29
|
+
import ImagePlugin from "./ImagePlugin";
|
|
30
|
+
import VideoPlugin from "./VideoPlugin";
|
|
31
|
+
import ContentPreviewDialog from "../components/ContentPreview";
|
|
32
|
+
import TooltipX from "../components/common/Tooltip";
|
|
33
|
+
export const ToolbarPlugin = ({ value, onImageUpload, sourceView = false, onToggleSourceView, fullscreen = false, onToggleFullscreen, }) => {
|
|
34
|
+
const [editor] = useLexicalComposerContext();
|
|
35
|
+
const [disableMap, setDisableMap] = useState({
|
|
36
|
+
[RichTextAction.Undo]: true,
|
|
37
|
+
[RichTextAction.Redo]: true
|
|
38
|
+
});
|
|
39
|
+
const [linkModalOpen, setLinkModalOpen] = useState(false);
|
|
40
|
+
const [findReplaceOpen, setFindReplaceOpen] = useState(false);
|
|
41
|
+
const [selectionMap, setSelectionMap] = useState({
|
|
42
|
+
[RichTextAction.LeftAlign]: true,
|
|
43
|
+
});
|
|
44
|
+
const [headingSelectionMap, setHeadingSelectionMap] = useState({
|
|
45
|
+
[HeadingAction.Normal]: true,
|
|
46
|
+
});
|
|
47
|
+
const [blockType, setBlockType] = useState('paragraph');
|
|
48
|
+
const [linkUrl, setLinkUrl] = useState("https://");
|
|
49
|
+
let initialLoad = true;
|
|
50
|
+
const updateToolbar = () => {
|
|
51
|
+
if (initialLoad) {
|
|
52
|
+
const root = editor.getRootElement();
|
|
53
|
+
if (root) {
|
|
54
|
+
root.scrollTop = 0;
|
|
55
|
+
initialLoad = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const selection = $getSelection();
|
|
59
|
+
if ($isRangeSelection(selection)) {
|
|
60
|
+
const newSelectionMap = {
|
|
61
|
+
[RichTextAction.Bold]: selection.hasFormat("bold"),
|
|
62
|
+
[RichTextAction.Italics]: selection.hasFormat("italic"),
|
|
63
|
+
[RichTextAction.Underline]: selection.hasFormat("underline"),
|
|
64
|
+
[RichTextAction.Uppercase]: selection.hasFormat("uppercase"),
|
|
65
|
+
[RichTextAction.Lowercase]: selection.hasFormat("lowercase"),
|
|
66
|
+
[RichTextAction.Capitalize]: selection.hasFormat("capitalize"),
|
|
67
|
+
[RichTextAction.Strikethrough]: selection.hasFormat("strikethrough"),
|
|
68
|
+
[RichTextAction.Superscript]: selection.hasFormat("superscript"),
|
|
69
|
+
[RichTextAction.Subscript]: selection.hasFormat("subscript"),
|
|
70
|
+
[RichTextAction.Code]: selection.hasFormat("code"),
|
|
71
|
+
[RichTextAction.Highlight]: selection.hasFormat("highlight"),
|
|
72
|
+
};
|
|
73
|
+
setSelectionMap(newSelectionMap);
|
|
74
|
+
// headings------------------
|
|
75
|
+
const anchorNode = selection.anchor.getNode();
|
|
76
|
+
const element = anchorNode.getKey() === 'root' ? anchorNode : anchorNode.getTopLevelElementOrThrow();
|
|
77
|
+
const elementKey = element.getKey();
|
|
78
|
+
const elementDom = editor.getElementByKey(elementKey);
|
|
79
|
+
if (!elementDom)
|
|
80
|
+
return;
|
|
81
|
+
if ($isListNode(element)) {
|
|
82
|
+
const parentList = $getNearestNodeOfType(anchorNode, ListNode);
|
|
83
|
+
const type = parentList ? parentList.getTag() : element.getTag();
|
|
84
|
+
setBlockType(type);
|
|
85
|
+
}
|
|
86
|
+
else if (element.getType() === "paragraph" || $isHeadingNode(element)) {
|
|
87
|
+
let tag = null;
|
|
88
|
+
if ($isHeadingNode(element)) {
|
|
89
|
+
tag = element.getTag();
|
|
90
|
+
}
|
|
91
|
+
const newHeadingSelectionMap = {
|
|
92
|
+
[HeadingAction.H1]: tag === "h1",
|
|
93
|
+
[HeadingAction.H2]: tag === "h2",
|
|
94
|
+
[HeadingAction.H3]: tag === "h3",
|
|
95
|
+
[HeadingAction.H4]: tag === "h4",
|
|
96
|
+
[HeadingAction.H5]: tag === "h5",
|
|
97
|
+
[HeadingAction.H6]: tag === "h6",
|
|
98
|
+
[HeadingAction.Normal]: element.getType() === "paragraph",
|
|
99
|
+
};
|
|
100
|
+
setBlockType(element.getType());
|
|
101
|
+
setHeadingSelectionMap(newHeadingSelectionMap);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
setBlockType(element.getType());
|
|
105
|
+
}
|
|
106
|
+
// ----------------------- alignments
|
|
107
|
+
const target = $isElementNode(anchorNode) ? anchorNode : element;
|
|
108
|
+
const alignment = target.getFormat();
|
|
109
|
+
// returns: 'left' = 1 | 'right' = 3 | 'center' = 2 | 'justify' = 4 | '' = 0 (default)
|
|
110
|
+
setSelectionMap((prev) => ({
|
|
111
|
+
...prev,
|
|
112
|
+
[RichTextAction.LeftAlign]: alignment === 0 || alignment === 1,
|
|
113
|
+
[RichTextAction.CenterAlign]: alignment === 2,
|
|
114
|
+
[RichTextAction.RightAlign]: alignment === 3,
|
|
115
|
+
[RichTextAction.JustifyAlign]: alignment === 4,
|
|
116
|
+
}));
|
|
117
|
+
// ----------------------- quotes
|
|
118
|
+
if (element.getType() === "quote") {
|
|
119
|
+
setSelectionMap((prev) => ({
|
|
120
|
+
...prev,
|
|
121
|
+
[RichTextAction.Quote]: true,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
setSelectionMap((prev) => ({
|
|
126
|
+
...prev,
|
|
127
|
+
[RichTextAction.Quote]: false,
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
// Update links
|
|
131
|
+
const node = selection.anchor.getNode();
|
|
132
|
+
const parent = node.getParent();
|
|
133
|
+
if ($isLinkNode(parent)) {
|
|
134
|
+
setSelectionMap((prev) => ({
|
|
135
|
+
...prev,
|
|
136
|
+
[RichTextAction.Link]: true,
|
|
137
|
+
}));
|
|
138
|
+
setLinkUrl(parent.getURL());
|
|
139
|
+
setLinkModalOpen(true);
|
|
140
|
+
}
|
|
141
|
+
else if ($isLinkNode(node)) {
|
|
142
|
+
setSelectionMap((prev) => ({
|
|
143
|
+
...prev,
|
|
144
|
+
[RichTextAction.Link]: true,
|
|
145
|
+
}));
|
|
146
|
+
setLinkUrl(node.getURL());
|
|
147
|
+
setLinkModalOpen(true);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
setSelectionMap((prev) => ({
|
|
151
|
+
...prev,
|
|
152
|
+
[RichTextAction.Link]: false,
|
|
153
|
+
}));
|
|
154
|
+
setLinkUrl("https://");
|
|
155
|
+
setLinkModalOpen(false);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
|
|
161
|
+
editorState.read(() => {
|
|
162
|
+
updateToolbar();
|
|
163
|
+
});
|
|
164
|
+
}), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
|
165
|
+
updateToolbar();
|
|
166
|
+
return false;
|
|
167
|
+
}, LOW_PRIORIRTY), editor.registerCommand(CAN_UNDO_COMMAND, (payload) => {
|
|
168
|
+
setDisableMap(prevDisableMap => ({
|
|
169
|
+
...prevDisableMap, undo: !payload
|
|
170
|
+
}));
|
|
171
|
+
return false;
|
|
172
|
+
}, LOW_PRIORIRTY), editor.registerCommand(CAN_REDO_COMMAND, (payload) => {
|
|
173
|
+
setDisableMap(prevDisableMap => ({
|
|
174
|
+
...prevDisableMap, redo: !payload
|
|
175
|
+
}));
|
|
176
|
+
return false;
|
|
177
|
+
}, LOW_PRIORIRTY));
|
|
178
|
+
}, []);
|
|
179
|
+
const onAction = (id) => {
|
|
180
|
+
switch (id) {
|
|
181
|
+
case RichTextAction.Bold: {
|
|
182
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case RichTextAction.Italics: {
|
|
186
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case RichTextAction.Underline: {
|
|
190
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline");
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case RichTextAction.Lowercase: {
|
|
194
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "lowercase");
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case RichTextAction.Uppercase: {
|
|
198
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "uppercase");
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case RichTextAction.Capitalize: {
|
|
202
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "capitalize");
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case RichTextAction.Strikethrough: {
|
|
206
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "strikethrough");
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case RichTextAction.Superscript: {
|
|
210
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "superscript");
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case RichTextAction.Subscript: {
|
|
214
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "subscript");
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case RichTextAction.Highlight: {
|
|
218
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "highlight");
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case RichTextAction.Code: {
|
|
222
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "code");
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case RichTextAction.Quote: {
|
|
226
|
+
editor.update(() => {
|
|
227
|
+
const selection = $getSelection();
|
|
228
|
+
if ($isRangeSelection(selection)) {
|
|
229
|
+
const anchorNode = selection.anchor.getNode();
|
|
230
|
+
const parent = anchorNode.getParent();
|
|
231
|
+
if (parent && $isQuoteNode(parent)) {
|
|
232
|
+
$setBlocksType(selection, () => $createParagraphNode());
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
$wrapNodes(selection, () => $createQuoteNode());
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case RichTextAction.Link: {
|
|
242
|
+
insertLink();
|
|
243
|
+
setLinkModalOpen(true);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
case RichTextAction.LeftAlign: {
|
|
247
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left');
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case RichTextAction.RightAlign: {
|
|
251
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right');
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case RichTextAction.CenterAlign: {
|
|
255
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center');
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case RichTextAction.JustifyAlign: {
|
|
259
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'justify');
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case RichTextAction.Undo: {
|
|
263
|
+
editor.dispatchCommand(UNDO_COMMAND, undefined);
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case RichTextAction.Redo: {
|
|
267
|
+
editor.dispatchCommand(REDO_COMMAND, undefined);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case RichTextAction.ClearFormatting: {
|
|
271
|
+
editor.update(() => {
|
|
272
|
+
const selection = $getSelection();
|
|
273
|
+
if (!$isRangeSelection(selection))
|
|
274
|
+
return;
|
|
275
|
+
const textNodes = selection.getNodes().filter($isTextNode);
|
|
276
|
+
for (const node of textNodes) {
|
|
277
|
+
node.setFormat(0);
|
|
278
|
+
node.setStyle("");
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case RichTextAction.HorizontalRule: {
|
|
284
|
+
editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined);
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
case RichTextAction.Indent: {
|
|
288
|
+
editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case RichTextAction.Outdent: {
|
|
292
|
+
editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
// useKeyBindings({ onAction });
|
|
298
|
+
// const getSelectedBtnProps = (
|
|
299
|
+
// isSelected: boolean
|
|
300
|
+
// ): Partial<IconButtonProps> =>
|
|
301
|
+
// isSelected
|
|
302
|
+
// ? {
|
|
303
|
+
// colorScheme: "blue",
|
|
304
|
+
// variant: "solid",
|
|
305
|
+
// }
|
|
306
|
+
// : {};
|
|
307
|
+
// const ref = useRef<HTMLSelectElement | null>(null)
|
|
308
|
+
const updateHeading = (heading) => {
|
|
309
|
+
editor.update(() => {
|
|
310
|
+
const selection = $getSelection();
|
|
311
|
+
if ($isRangeSelection(selection)) {
|
|
312
|
+
if (heading === "normal") {
|
|
313
|
+
$wrapNodes(selection, () => $createParagraphNode());
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
$wrapNodes(selection, () => $createHeadingNode(heading));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
// const insertLink = useCallback(() => {
|
|
322
|
+
// console.log('insertlink');
|
|
323
|
+
// const selection = $getSelection();
|
|
324
|
+
// if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
325
|
+
// // Nothing selected → do nothing
|
|
326
|
+
// return;
|
|
327
|
+
// }
|
|
328
|
+
// if (!linkModalOpen) {
|
|
329
|
+
// if (linkUrl !== "") {
|
|
330
|
+
// editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
|
|
331
|
+
// }
|
|
332
|
+
// } else {
|
|
333
|
+
// editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
334
|
+
// }
|
|
335
|
+
// }, [editor, linkModalOpen]);
|
|
336
|
+
const insertLink = useCallback(() => {
|
|
337
|
+
editor.update(() => {
|
|
338
|
+
const selection = $getSelection();
|
|
339
|
+
if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
340
|
+
// Nothing selected → do nothing
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!linkModalOpen) {
|
|
344
|
+
if (linkUrl !== "") {
|
|
345
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}, [editor, linkModalOpen, linkUrl]);
|
|
353
|
+
const removeLink = useCallback(() => {
|
|
354
|
+
setLinkUrl("");
|
|
355
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
356
|
+
setLinkModalOpen(false);
|
|
357
|
+
}, [editor]);
|
|
358
|
+
// <div className="flex gap-1.5 justify-start items-center p-1.5 pb-2 mb-1 border-b-[1px] overflow-x-auto overflow-y-hidden scrollbar-thin">
|
|
359
|
+
return (_jsxs("div", { className: "lexical-toolbar-wrapper", style: {
|
|
360
|
+
position: 'relative',
|
|
361
|
+
padding: 12, marginBottom: 4, borderBottom: '1px solid #e5e7eb'
|
|
362
|
+
}, children: [RICH_REDO_UNDO_OPTIONS.map(({ id, label, icon }) => (id === RichTextAction.Divider ? _jsx(Separator, {}, id) :
|
|
363
|
+
_jsx(TooltipX, { content: label, direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${selectionMap[id] ? "toolbarActive" : "toolbar"} icon`, onClick: () => onAction(id), disabled: !!disableMap[id], children: icon }) }, label))), _jsxs("div", { style: { display: 'flex', gap: 6, justifyContent: 'start', alignItems: 'center' }, children: [_jsx(HeadingSelectionList, { updateHeading: updateHeading, headingSelectionMap: headingSelectionMap }), _jsx(Separator, {})] }), RICH_TEXT_OPTIONS.map(({ id, label, icon }) => (id === RichTextAction.Divider ? _jsx(Separator, {}, id) :
|
|
364
|
+
_jsx(TooltipX, { content: label, direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${selectionMap[id] ? "toolbarActive" : "toolbar"} icon`, onClick: () => onAction(id), children: icon }) }, id))), _jsxs("div", { style: { display: 'flex', gap: 6, justifyContent: 'start', alignItems: 'center' }, children: [_jsx(ListPlugin, { blockType: blockType }), _jsx(Separator, {})] }), RICH_BLOCK_OPTIONS.map(({ id, label, icon }) => (id === RichTextAction.Divider ? _jsx(Separator, {}, id) :
|
|
365
|
+
_jsx(TooltipX, { content: label, direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${selectionMap[id] ? "toolbarActive" : "toolbar"} icon`, onClick: () => onAction(id), children: icon }) }, id))), _jsx(FontFamilyPlugin, {}), _jsx(FontSizePlugin, {}), _jsx(ColorPlugin, {}), _jsx(CodeBlockPlugin, {}), _jsx(DropdownList, { onAction: onAction, selectionMap: selectionMap }), _jsxs("div", { style: { display: 'flex', gap: 6, justifyContent: 'start', alignItems: 'center' }, children: [_jsx(AlignmentSelectionList, { onAction: onAction, alignmentSelectionMap: selectionMap }), _jsx(Separator, {})] }), _jsx(TooltipX, { content: "Link", direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${selectionMap[RichTextAction.Link] ? "toolbarActive" : "toolbar"} icon`, onClick: () => onAction(RichTextAction.Link), disabled: !!disableMap[RichTextAction.Link], children: _jsx(IoIosLink, {}) }) }), linkModalOpen &&
|
|
366
|
+
_jsx(LinkModal, { linkUrl: linkUrl, setLinkUrl: setLinkUrl, removeLink: removeLink, onConfirm: (url) => {
|
|
367
|
+
// Dispatch TOGGLE_LINK_COMMAND with the URL directly
|
|
368
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
|
|
369
|
+
url: url,
|
|
370
|
+
target: "_blank",
|
|
371
|
+
});
|
|
372
|
+
// Update state for modal and UI
|
|
373
|
+
setLinkUrl(url);
|
|
374
|
+
setLinkModalOpen(false);
|
|
375
|
+
}, onCancel: () => {
|
|
376
|
+
setLinkUrl("");
|
|
377
|
+
// editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
378
|
+
setLinkModalOpen(false);
|
|
379
|
+
} }), _jsx(ImagePlugin, { onImageUpload: onImageUpload }), _jsx(VideoPlugin, {}), _jsx(TablePlugin, {}), _jsx(Separator, {}), _jsx(TooltipX, { content: "Find & Replace", direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${findReplaceOpen ? "toolbarActive" : "toolbar"} icon`, onClick: () => setFindReplaceOpen((prev) => !prev), children: _jsx(IoSearchOutline, {}) }) }), _jsx(TooltipX, { content: "Source Code View", direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${sourceView ? "toolbarActive" : "toolbar"} icon`, onClick: () => onToggleSourceView?.(), children: _jsx(IoCodeOutline, {}) }) }), _jsx(TooltipX, { content: fullscreen ? "Exit Fullscreen" : "Fullscreen", direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${fullscreen ? "toolbarActive" : "toolbar"} icon`, onClick: () => onToggleFullscreen?.(), children: fullscreen ? _jsx(BsFullscreenExit, {}) : _jsx(BsFullscreen, {}) }) }), _jsx(ContentPreviewDialog, { value: value }), findReplaceOpen &&
|
|
380
|
+
_jsx(FindReplaceModal, { onClose: () => setFindReplaceOpen(false) })] }));
|
|
381
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { FaYoutube } from "react-icons/fa";
|
|
4
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
5
|
+
import { $insertNodes } from "lexical";
|
|
6
|
+
import { $createVideoNode } from "../nodes/VideoNode";
|
|
7
|
+
import RawDialog from "../components/common/Dialog";
|
|
8
|
+
export default function VideoPlugin() {
|
|
9
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
+
const [showMessage, setShowMessage] = useState(false);
|
|
11
|
+
const [url, setURL] = useState("");
|
|
12
|
+
const [editor] = useLexicalComposerContext();
|
|
13
|
+
const onEmbed = () => {
|
|
14
|
+
if (!url)
|
|
15
|
+
return;
|
|
16
|
+
let provider = null;
|
|
17
|
+
let id = null;
|
|
18
|
+
// youtube
|
|
19
|
+
const ytMatch = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(url);
|
|
20
|
+
if (ytMatch && ytMatch[2]?.length === 11) {
|
|
21
|
+
provider = "youtube";
|
|
22
|
+
id = ytMatch[2];
|
|
23
|
+
}
|
|
24
|
+
// drive
|
|
25
|
+
const driveMatch = /drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(url);
|
|
26
|
+
if (driveMatch && driveMatch[1]) {
|
|
27
|
+
provider = "drive";
|
|
28
|
+
id = driveMatch[1];
|
|
29
|
+
}
|
|
30
|
+
if (!id || !provider) {
|
|
31
|
+
setShowMessage(true);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
editor.update(() => {
|
|
35
|
+
const node = $createVideoNode({ id, provider });
|
|
36
|
+
$insertNodes([node]);
|
|
37
|
+
});
|
|
38
|
+
setURL("");
|
|
39
|
+
setShowMessage(false);
|
|
40
|
+
setIsOpen(false);
|
|
41
|
+
};
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!isOpen) {
|
|
44
|
+
setURL("");
|
|
45
|
+
setShowMessage(false);
|
|
46
|
+
}
|
|
47
|
+
}, [isOpen]);
|
|
48
|
+
return (_jsxs("div", { className: "lexical-text-editor-dialog", children: [_jsx("button", { type: "button", className: `size-8 lexical-btn ${isOpen ? "toolbarActive" : "toolbar"} icon`, onClick: () => setIsOpen(true), children: _jsx(FaYoutube, { size: 18, color: "red" }) }), _jsxs(RawDialog, { open: isOpen, onClose: () => setIsOpen(false), children: [_jsx("div", { className: "lte-dialog-header", children: "Embed Video" }), _jsxs("div", { className: "lte-dialog-body", children: [_jsx("input", { className: "lte-input", placeholder: "Add YouTube or Google Drive URL", value: url, onChange: (e) => setURL(e.target.value) }), showMessage && (_jsx("p", { className: "lte-error-text", children: "It's not a valid YouTube or Google Drive URL" }))] }), _jsx("div", { className: "lte-dialog-footer", children: _jsx("button", { type: "button", className: "lte-primary-btn", disabled: !url, onClick: onEmbed, children: "Embed" }) })] })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Youtube } from "lucide-react";
|
|
5
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
6
|
+
import { $insertNodes } from "lexical";
|
|
7
|
+
import { $createYoutubeNode } from "../nodes/YoutubeNode";
|
|
8
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogTrigger, } from "../components/ui/dialog";
|
|
9
|
+
import { Button } from "../components/ui/button";
|
|
10
|
+
import { Input } from "../components/ui/input";
|
|
11
|
+
export default function YoutubePlugin() {
|
|
12
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
13
|
+
const [url, setURL] = useState("");
|
|
14
|
+
const [editor] = useLexicalComposerContext();
|
|
15
|
+
const onEmbed = () => {
|
|
16
|
+
if (!url)
|
|
17
|
+
return;
|
|
18
|
+
const match = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(url);
|
|
19
|
+
const id = match && match?.[2]?.length === 11 ? match?.[2] : null;
|
|
20
|
+
if (!id)
|
|
21
|
+
return;
|
|
22
|
+
editor.update(() => {
|
|
23
|
+
const node = $createYoutubeNode({ id });
|
|
24
|
+
$insertNodes([node]);
|
|
25
|
+
});
|
|
26
|
+
setURL("");
|
|
27
|
+
setIsOpen(false);
|
|
28
|
+
};
|
|
29
|
+
return (_jsx("div", { children: _jsxs(Dialog, { open: isOpen, onOpenChange: setIsOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsx(Button, { size: "icon", variant: "ghost", className: "rounded-md text-gray-700 hover:bg-gray-200", children: _jsx(Youtube, { className: "h-4 w-4 text-red-600" }) }) }), _jsxs(DialogContent, { className: "sm:max-w-md", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { className: "!text-xl", children: "Embed YouTube Video" }) }), _jsx("div", { className: "py-2", children: _jsx(Input, { value: url, onChange: (e) => setURL(e.target.value), placeholder: "Add YouTube URL" }) }), _jsx(DialogFooter, { children: _jsx(Button, { onClick: onEmbed, disabled: !url, className: "bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50", children: "Embed" }) })] })] }) }));
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/components/alignmentselectionlist.tsx","../src/components/colorpicker.tsx","../src/components/contentpreview.tsx","../src/components/dropdownlist.tsx","../src/components/findreplacemodal.tsx","../src/components/fontselectionlist.tsx","../src/components/headingselectionlist.tsx","../src/components/imagecomponent.tsx","../src/components/insertdropdownlist.tsx","../src/components/lexicaltexteditor.tsx","../src/components/linkmodal.tsx","../src/components/separator.tsx","../src/components/sourceview.tsx","../src/components/statusbar.tsx","../src/components/common/dialog.tsx","../src/components/common/popover.tsx","../src/components/common/tooltip.tsx","../src/components/ui/button.tsx","../src/components/ui/command.tsx","../src/components/ui/dialog.tsx","../src/components/ui/input.tsx","../src/components/ui/popover.tsx","../src/components/ui/scroll-area.tsx","../src/components/ui/tooltip.tsx","../src/constants/index.tsx","../src/lib/utils.ts","../src/nodes/extendedtextnode.tsx","../src/nodes/imagenode.tsx","../src/nodes/videonode.tsx","../src/nodes/youtubenode.tsx","../src/plugins/codeblockplugin.tsx","../src/plugins/colorplugin.tsx","../src/plugins/customonchangeplugin.tsx","../src/plugins/fontfamilyplugin.tsx","../src/plugins/fontsizeplugin.tsx","../src/plugins/imageplugin.tsx","../src/plugins/listplugin.tsx","../src/plugins/tableplugin.tsx","../src/plugins/toolbarplugin.tsx","../src/plugins/videoplugin.tsx","../src/plugins/youtubeplugin.tsx","../src/types/global.d.ts","../src/types/other.d.ts","../src/types/react-icons.d.ts"],"version":"5.9.3"}
|
package/editor_screenshot.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innoviatech/lexical-text-editor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"editor_screenshot.png"
|
|
9
|
+
],
|
|
5
10
|
"main": "./dist/index.js",
|
|
6
11
|
"module": "./dist/index.esm.js",
|
|
7
12
|
"types": "./dist/index.d.ts",
|
|
8
13
|
"license": "MIT",
|
|
9
|
-
"homepage": "https://technohaattech.github.io/
|
|
14
|
+
"homepage": "https://technohaattech.github.io/lexical-text-editor/",
|
|
10
15
|
"repository": {
|
|
11
16
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/technohaattech/
|
|
17
|
+
"url": "https://github.com/technohaattech/lexical-text-editor"
|
|
13
18
|
},
|
|
14
19
|
"exports": {
|
|
15
20
|
".": {
|
|
@@ -33,6 +38,7 @@
|
|
|
33
38
|
"@lexical/list": "^0.36.2",
|
|
34
39
|
"@lexical/react": "^0.36.2",
|
|
35
40
|
"@lexical/rich-text": "^0.36.2",
|
|
41
|
+
"@lexical/table": "^0.36.2",
|
|
36
42
|
"lexical": "^0.36.2",
|
|
37
43
|
"react": ">=18",
|
|
38
44
|
"react-color": "^2.19.3",
|
|
@@ -40,6 +46,7 @@
|
|
|
40
46
|
"react-icons": "^5.5.0"
|
|
41
47
|
},
|
|
42
48
|
"devDependencies": {
|
|
49
|
+
"@lexical/table": "^0.36.2",
|
|
43
50
|
"@rollup/plugin-commonjs": "^28.0.0",
|
|
44
51
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
45
52
|
"@rollup/plugin-terser": "^0.4.0",
|
|
@@ -56,4 +63,4 @@
|
|
|
56
63
|
"tslib": "^2.6.0",
|
|
57
64
|
"typescript": "^5.0.0"
|
|
58
65
|
}
|
|
59
|
-
}
|
|
66
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
google-site-verification: googlebd703883f12c69e4.html
|
package/rollup.config.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import typescript from '@rollup/plugin-typescript';
|
|
3
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
-
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
|
5
|
-
import terser from '@rollup/plugin-terser';
|
|
6
|
-
import dts from 'rollup-plugin-dts';
|
|
7
|
-
import postcss from 'rollup-plugin-postcss';
|
|
8
|
-
|
|
9
|
-
export default [
|
|
10
|
-
{
|
|
11
|
-
input: 'src/index.ts',
|
|
12
|
-
output: [
|
|
13
|
-
{
|
|
14
|
-
file: 'dist/index.js',
|
|
15
|
-
format: 'cjs',
|
|
16
|
-
sourcemap: true,
|
|
17
|
-
exports: 'named'
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
file: 'dist/index.esm.js',
|
|
21
|
-
format: 'esm',
|
|
22
|
-
sourcemap: true,
|
|
23
|
-
exports: 'named'
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
plugins: [
|
|
27
|
-
peerDepsExternal(),
|
|
28
|
-
resolve({
|
|
29
|
-
browser: true,
|
|
30
|
-
preferBuiltins: false
|
|
31
|
-
}),
|
|
32
|
-
commonjs(),
|
|
33
|
-
postcss({
|
|
34
|
-
extract: 'lexical-editor.css',
|
|
35
|
-
minimize: true,
|
|
36
|
-
inject: false,
|
|
37
|
-
modules: false
|
|
38
|
-
}),
|
|
39
|
-
typescript({
|
|
40
|
-
tsconfig: './tsconfig.json',
|
|
41
|
-
declaration: true,
|
|
42
|
-
declarationDir: 'dist',
|
|
43
|
-
rootDir: 'src',
|
|
44
|
-
noEmitOnError: false
|
|
45
|
-
}),
|
|
46
|
-
terser()
|
|
47
|
-
]
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
input: 'dist/index.d.ts',
|
|
51
|
-
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
|
|
52
|
-
plugins: [dts()],
|
|
53
|
-
external: [/\.css$/]
|
|
54
|
-
}
|
|
55
|
-
];
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { RICH_ALIGNMENT_OPTIONS, RichTextAction } from "../constants/index";
|
|
4
|
-
|
|
5
|
-
import { useRef, useState } from "react"
|
|
6
|
-
import { HiChevronDown } from "react-icons/hi2";
|
|
7
|
-
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
8
|
-
|
|
9
|
-
interface Props {
|
|
10
|
-
onAction: (id: RichTextAction) => void;
|
|
11
|
-
alignmentSelectionMap: {
|
|
12
|
-
[id: string]: boolean;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export function AlignmentSelectionList({ onAction, alignmentSelectionMap }: Props) {
|
|
16
|
-
const activeAlignment = RICH_ALIGNMENT_OPTIONS.find(h => alignmentSelectionMap[h.id])
|
|
17
|
-
const [isOpen, setIsOpen] = useState(false)
|
|
18
|
-
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
19
|
-
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
20
|
-
return (
|
|
21
|
-
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
22
|
-
<PopoverTrigger triggerRef={triggerRef}>
|
|
23
|
-
|
|
24
|
-
<button type="button"
|
|
25
|
-
className={`lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`}
|
|
26
|
-
onClick={() => setIsOpen((prev) => !prev)}
|
|
27
|
-
style={{
|
|
28
|
-
minWidth: 146
|
|
29
|
-
}}
|
|
30
|
-
>
|
|
31
|
-
{activeAlignment?.icon}
|
|
32
|
-
<span>{activeAlignment?.label}</span>
|
|
33
|
-
<HiChevronDown className={`chevron ${isOpen ? "rotated" : ""}`} />
|
|
34
|
-
</button>
|
|
35
|
-
</PopoverTrigger>
|
|
36
|
-
<PopoverContent open={isOpen} align="start" onClose={() => setIsOpen(false)} contentRef={contentRef}>
|
|
37
|
-
<div
|
|
38
|
-
style={{
|
|
39
|
-
display: 'flex', flexDirection: 'column', gap: 5
|
|
40
|
-
}}>
|
|
41
|
-
{
|
|
42
|
-
RICH_ALIGNMENT_OPTIONS.map(({ id, label, icon }) => (
|
|
43
|
-
<button type="button"
|
|
44
|
-
key={id}
|
|
45
|
-
className={`lexical-btn ${alignmentSelectionMap[id] ? "toolbar-active" : "toolbar"
|
|
46
|
-
}`}
|
|
47
|
-
onClick={() => {
|
|
48
|
-
onAction(id);
|
|
49
|
-
setIsOpen(false)
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
{icon}
|
|
53
|
-
<span className="label">{label}</span>
|
|
54
|
-
</button>
|
|
55
|
-
))
|
|
56
|
-
}
|
|
57
|
-
</div>
|
|
58
|
-
</PopoverContent>
|
|
59
|
-
</Popover>
|
|
60
|
-
)
|
|
61
|
-
}
|