@react-fabric/lexical 1.0.0-beta.9 → 1.0.1
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/{src/editor/Lexical.module.css → css/_lexical.css} +79 -13
- package/css/styles.css +24 -0
- package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +98 -45
- package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +147 -140
- package/dist/cjs/i18n/ar/lexical.json.js +30 -0
- package/dist/cjs/i18n/en/lexical.json.js +30 -0
- package/{src/plugins/StickyPlugin.ts → dist/cjs/i18n/index.js} +10 -15
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/plugins/CommentPlugin.js +481 -0
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +17 -20
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +58 -37
- package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +101 -48
- package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +95 -88
- package/dist/esm/i18n/ar/lexical.json.js +25 -0
- package/dist/esm/i18n/en/lexical.json.js +25 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/plugins/CommentPlugin.js +481 -0
- package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +15 -18
- package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +59 -38
- package/dist/types/editor/LexicalEditor.d.ts +33 -4
- package/dist/types/hooks/useFormatWatcher.d.ts +7 -4
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/plugins/CommentPlugin.d.ts +5 -0
- package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
- package/dist/types/plugins/ToolbarPlugin.d.ts +1 -1
- package/dist/types/utils/index.d.ts +3 -6
- package/package.json +18 -18
- package/src/editor/LexicalEditor.tsx +95 -55
- package/src/hooks/useFormatWatcher.ts +50 -74
- package/src/i18n/ar/lexical.json +18 -0
- package/src/i18n/en/lexical.json +18 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +24 -17
- package/src/plugins/CommentPlugin.tsx +523 -0
- package/src/plugins/DraggableBlockPlugin.tsx +23 -68
- package/src/plugins/ToolbarPlugin.tsx +83 -131
- package/src/utils/index.ts +12 -108
- package/dist/cjs/_virtual/prism.js +0 -5
- package/dist/cjs/editor/Lexical.module.css +0 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -432
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1139
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -50
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -245
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -471
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -24
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1275
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -789
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -976
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -35
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -35
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -2792
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -55
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -888
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -35
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -66
- package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
- package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
- package/dist/cjs/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/cjs/packages/lexical/src/index.js +0 -7
- package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +0 -218
- package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/esm/_virtual/prism.js +0 -5
- package/dist/esm/editor/Lexical.module.css +0 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -423
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1121
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -244
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -463
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1262
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -781
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -957
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -26
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -2754
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -839
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -26
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
- package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
- package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/esm/node_modules/prismjs/prism.js +0 -1951
- package/dist/esm/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/esm/packages/lexical/src/index.js +0 -3
- package/dist/esm/packages/lexical/src/nodes/StickyNode.js +0 -216
- package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/types/components/StickyComponent.d.ts +0 -9
- package/dist/types/nodes/StickyNode.d.ts +0 -35
- package/dist/types/plugins/StickyPlugin.d.ts +0 -1
- package/src/components/StickyComponent.tsx +0 -271
- package/src/nodes/StickyNode.tsx +0 -249
- /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
- /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
|
@@ -36,12 +36,7 @@ import {
|
|
|
36
36
|
DROP_COMMAND,
|
|
37
37
|
type LexicalEditor,
|
|
38
38
|
} from "lexical";
|
|
39
|
-
import {
|
|
40
|
-
useEffect,
|
|
41
|
-
useRef,
|
|
42
|
-
useState,
|
|
43
|
-
type DragEvent as ReactDragEvent,
|
|
44
|
-
} from "react";
|
|
39
|
+
import { useEffect, useRef, useState, type DragEvent as ReactDragEvent } from "react";
|
|
45
40
|
import { createPortal } from "react-dom";
|
|
46
41
|
import { Point, Rect, isHTMLElement } from "../utils";
|
|
47
42
|
|
|
@@ -72,11 +67,7 @@ function getTopLevelNodeKeys(editor: LexicalEditor): string[] {
|
|
|
72
67
|
return editor.getEditorState().read(() => $getRoot().getChildrenKeys());
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
function getBlockElement(
|
|
76
|
-
anchorElem: HTMLElement,
|
|
77
|
-
editor: LexicalEditor,
|
|
78
|
-
event: MouseEvent,
|
|
79
|
-
): HTMLElement | null {
|
|
70
|
+
function getBlockElement(anchorElem: HTMLElement, editor: LexicalEditor, event: MouseEvent): HTMLElement | null {
|
|
80
71
|
const anchorElementRect = anchorElem.getBoundingClientRect();
|
|
81
72
|
const topLevelNodeKeys = getTopLevelNodeKeys(editor);
|
|
82
73
|
|
|
@@ -136,29 +127,19 @@ function isOnMenu(element: HTMLElement): boolean {
|
|
|
136
127
|
return !!element.closest(`.${DRAGGABLE_BLOCK_MENU_CLASSNAME}`);
|
|
137
128
|
}
|
|
138
129
|
|
|
139
|
-
function setMenuPosition(
|
|
140
|
-
targetElem: HTMLElement | null,
|
|
141
|
-
floatingElem: HTMLElement,
|
|
142
|
-
anchorElem: HTMLElement,
|
|
143
|
-
) {
|
|
130
|
+
function setMenuPosition(targetElem: HTMLElement | null, floatingElem: HTMLElement, anchorElem: HTMLElement) {
|
|
144
131
|
if (!targetElem) {
|
|
145
132
|
floatingElem.style.opacity = "0";
|
|
146
133
|
floatingElem.style.transform = "translate(-10000px, -10000px)";
|
|
147
134
|
return;
|
|
148
135
|
}
|
|
149
136
|
|
|
150
|
-
const scrollTop = targetElem.closest(".lexical-scroller")?.scrollTop ?? 0;
|
|
151
|
-
|
|
152
137
|
const targetRect = targetElem.getBoundingClientRect();
|
|
153
138
|
const targetStyle = window.getComputedStyle(targetElem);
|
|
154
139
|
const floatingElemRect = floatingElem.getBoundingClientRect();
|
|
155
140
|
const anchorElementRect = anchorElem.getBoundingClientRect();
|
|
156
141
|
|
|
157
|
-
const top =
|
|
158
|
-
scrollTop +
|
|
159
|
-
targetRect.top +
|
|
160
|
-
(parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 -
|
|
161
|
-
anchorElementRect.top;
|
|
142
|
+
const top = targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.top;
|
|
162
143
|
|
|
163
144
|
const left = SPACE;
|
|
164
145
|
|
|
@@ -166,10 +147,7 @@ function setMenuPosition(
|
|
|
166
147
|
floatingElem.style.transform = `translate(${left}px, ${top}px)`;
|
|
167
148
|
}
|
|
168
149
|
|
|
169
|
-
function setDragImage(
|
|
170
|
-
dataTransfer: DataTransfer,
|
|
171
|
-
draggableBlockElem: HTMLElement,
|
|
172
|
-
) {
|
|
150
|
+
function setDragImage(dataTransfer: DataTransfer, draggableBlockElem: HTMLElement) {
|
|
173
151
|
const { transform } = draggableBlockElem.style;
|
|
174
152
|
|
|
175
153
|
// Remove dragImage borders
|
|
@@ -181,20 +159,12 @@ function setDragImage(
|
|
|
181
159
|
});
|
|
182
160
|
}
|
|
183
161
|
|
|
184
|
-
function setTargetLine(
|
|
185
|
-
targetLineElem: HTMLElement,
|
|
186
|
-
targetBlockElem: HTMLElement,
|
|
187
|
-
mouseY: number,
|
|
188
|
-
anchorElem: HTMLElement,
|
|
189
|
-
) {
|
|
162
|
+
function setTargetLine(targetLineElem: HTMLElement, targetBlockElem: HTMLElement, mouseY: number, anchorElem: HTMLElement) {
|
|
190
163
|
const targetStyle = window.getComputedStyle(targetBlockElem);
|
|
191
|
-
const { top: targetBlockElemTop, height: targetBlockElemHeight } =
|
|
192
|
-
|
|
193
|
-
const { top: anchorTop, width: anchorWidth } =
|
|
194
|
-
anchorElem.getBoundingClientRect();
|
|
164
|
+
const { top: targetBlockElemTop, height: targetBlockElemHeight } = targetBlockElem.getBoundingClientRect();
|
|
165
|
+
const { top: anchorTop, width: anchorWidth } = anchorElem.getBoundingClientRect();
|
|
195
166
|
|
|
196
|
-
const scrollTop =
|
|
197
|
-
targetBlockElem.closest(".editor-container")?.scrollTop ?? 0;
|
|
167
|
+
const scrollTop = targetBlockElem.closest(".editor-container")?.scrollTop ?? 0;
|
|
198
168
|
|
|
199
169
|
let lineTop = targetBlockElemTop;
|
|
200
170
|
// At the bottom of the target
|
|
@@ -208,9 +178,7 @@ function setTargetLine(
|
|
|
208
178
|
const left = TEXT_BOX_HORIZONTAL_PADDING - SPACE;
|
|
209
179
|
|
|
210
180
|
targetLineElem.style.transform = `translate(${left}px, ${top}px)`;
|
|
211
|
-
targetLineElem.style.width = `${
|
|
212
|
-
anchorWidth - (TEXT_BOX_HORIZONTAL_PADDING - SPACE) * 2
|
|
213
|
-
}px`;
|
|
181
|
+
targetLineElem.style.width = `${anchorWidth - (TEXT_BOX_HORIZONTAL_PADDING - SPACE) * 2}px`;
|
|
214
182
|
targetLineElem.style.opacity = ".4";
|
|
215
183
|
}
|
|
216
184
|
|
|
@@ -221,18 +189,13 @@ function hideTargetLine(targetLineElem: HTMLElement | null) {
|
|
|
221
189
|
}
|
|
222
190
|
}
|
|
223
191
|
|
|
224
|
-
function
|
|
225
|
-
editor: LexicalEditor,
|
|
226
|
-
anchorElem: HTMLElement,
|
|
227
|
-
isEditable: boolean,
|
|
228
|
-
): JSX.Element {
|
|
192
|
+
function RenderDraggableBlockMenu(editor: LexicalEditor, anchorElem: HTMLElement): React.ReactElement {
|
|
229
193
|
const scrollerElem = anchorElem.parentElement;
|
|
230
194
|
|
|
231
195
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
232
196
|
const targetLineRef = useRef<HTMLDivElement>(null);
|
|
233
197
|
const isDraggingBlockRef = useRef<boolean>(false);
|
|
234
|
-
const [draggableBlockElem, setDraggableBlockElem] =
|
|
235
|
-
useState<HTMLElement | null>(null);
|
|
198
|
+
const [draggableBlockElem, setDraggableBlockElem] = useState<HTMLElement | null>(null);
|
|
236
199
|
|
|
237
200
|
useEffect(() => {
|
|
238
201
|
function onMouseMove(event: MouseEvent) {
|
|
@@ -324,10 +287,7 @@ function useDraggableBlockMenu(
|
|
|
324
287
|
}
|
|
325
288
|
const { top, height } = targetBlockElem.getBoundingClientRect();
|
|
326
289
|
const shouldInsertAfter = pageY - top > height / 2;
|
|
327
|
-
if (
|
|
328
|
-
shouldInsertAfter ||
|
|
329
|
-
targetBlockElem.classList.contains("editor-cover-page")
|
|
330
|
-
) {
|
|
290
|
+
if (shouldInsertAfter || targetBlockElem.classList.contains("editor-cover-page")) {
|
|
331
291
|
targetNode.insertAfter(draggedNode);
|
|
332
292
|
} else {
|
|
333
293
|
targetNode.insertBefore(draggedNode);
|
|
@@ -377,30 +337,22 @@ function useDraggableBlockMenu(
|
|
|
377
337
|
hideTargetLine(targetLineRef.current);
|
|
378
338
|
}
|
|
379
339
|
|
|
380
|
-
if (draggableBlockElem?.classList?.contains("editor-cover-page")) {
|
|
381
|
-
return <div />;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
340
|
return createPortal(
|
|
385
341
|
<>
|
|
386
342
|
<div
|
|
387
|
-
className="rounded px-0.5 py-px select-none cursor-grab opacity-0 absolute left-0 top-0 will-change-transform active:cursor-grabbing hover:bg-
|
|
343
|
+
className="rounded px-0.5 py-px select-none cursor-grab opacity-0 absolute left-0 top-0 will-change-transform active:cursor-grabbing hover:bg-default"
|
|
388
344
|
ref={menuRef}
|
|
389
345
|
draggable={true}
|
|
390
346
|
onDragStart={onDragStart}
|
|
391
347
|
onDragEnd={onDragEnd}
|
|
392
348
|
>
|
|
393
|
-
<svg
|
|
394
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
395
|
-
viewBox="0 0 24 24"
|
|
396
|
-
className="w-4 h-4 opacity-30 pointer-events-none"
|
|
397
|
-
>
|
|
349
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" className="w-4 h-4 opacity-30 pointer-events-none">
|
|
398
350
|
<title>dots-grid</title>
|
|
399
351
|
<path d="M12 16C13.1 16 14 16.9 14 18S13.1 20 12 20 10 19.1 10 18 10.9 16 12 16M12 10C13.1 10 14 10.9 14 12S13.1 14 12 14 10 13.1 10 12 10.9 10 12 10M12 4C13.1 4 14 4.9 14 6S13.1 8 12 8 10 7.1 10 6 10.9 4 12 4M6 16C7.1 16 8 16.9 8 18S7.1 20 6 20 4 19.1 4 18 4.9 16 6 16M6 10C7.1 10 8 10.9 8 12S7.1 14 6 14 4 13.1 4 12 4.9 10 6 10M6 4C7.1 4 8 4.9 8 6S7.1 8 6 8 4 7.1 4 6 4.9 4 6 4M18 16C19.1 16 20 16.9 20 18S19.1 20 18 20 16 19.1 16 18 16.9 16 18 16M18 10C19.1 10 20 10.9 20 12S19.1 14 18 14 16 13.1 16 12 16.9 10 18 10M18 4C19.1 4 20 4.9 20 6S19.1 8 18 8 16 7.1 16 6 16.9 4 18 4Z" />
|
|
400
352
|
</svg>
|
|
401
353
|
</div>
|
|
402
354
|
<div
|
|
403
|
-
className="pointer-events-none bg-primary h-1 absolute top-0 left-0 opacity-0 will-change-transform"
|
|
355
|
+
className="pointer-events-none bg-primary-200 h-1 absolute top-0 left-0 opacity-0 will-change-transform"
|
|
404
356
|
ref={targetLineRef}
|
|
405
357
|
/>
|
|
406
358
|
</>,
|
|
@@ -408,11 +360,14 @@ function useDraggableBlockMenu(
|
|
|
408
360
|
);
|
|
409
361
|
}
|
|
410
362
|
|
|
411
|
-
export
|
|
363
|
+
export function DraggableBlockPlugin({
|
|
412
364
|
anchorElem = document.body,
|
|
365
|
+
isEditable = true,
|
|
413
366
|
}: {
|
|
414
367
|
anchorElem?: HTMLElement;
|
|
415
|
-
|
|
368
|
+
isEditable: boolean;
|
|
369
|
+
}): React.ReactElement {
|
|
416
370
|
const [editor] = useLexicalComposerContext();
|
|
417
|
-
|
|
418
|
-
|
|
371
|
+
if (!isEditable) return <></>;
|
|
372
|
+
return RenderDraggableBlockMenu(editor, anchorElem);
|
|
373
|
+
}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
3
|
-
* @version
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2025 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
6
22
|
*/
|
|
7
23
|
|
|
8
|
-
import {
|
|
9
|
-
Button,
|
|
10
|
-
ButtonGroup,
|
|
11
|
-
CoreIcons,
|
|
12
|
-
Divider,
|
|
13
|
-
Dropdown,
|
|
14
|
-
Icon,
|
|
15
|
-
Menu,
|
|
16
|
-
MenuItem,
|
|
17
|
-
ToggleButtonGroup,
|
|
18
|
-
Tooltip,
|
|
19
|
-
} from "@react-fabric/core";
|
|
24
|
+
import { Button, ButtonGroup, Divider, Dropdown, Icon, Menu, MenuItem, ToggleButtonGroup, Tooltip } from "@react-fabric/core";
|
|
20
25
|
import { ColorInput } from "@react-fabric/form";
|
|
21
26
|
import { getValue } from "@react-fabric/utilities";
|
|
22
27
|
import { FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND } from "lexical";
|
|
@@ -24,7 +29,7 @@ import { useMemo } from "react";
|
|
|
24
29
|
import { useTranslation } from "react-i18next";
|
|
25
30
|
import { useFormatWatcher } from "../hooks/useFormatWatcher";
|
|
26
31
|
|
|
27
|
-
const blockTypeToBlockName
|
|
32
|
+
const blockTypeToBlockName = {
|
|
28
33
|
bullet: "Bulleted List",
|
|
29
34
|
code: "Block",
|
|
30
35
|
h1: "Heading",
|
|
@@ -33,17 +38,17 @@ const blockTypeToBlockName: KeyValue = {
|
|
|
33
38
|
number: "Numbered List",
|
|
34
39
|
paragraph: "Normal",
|
|
35
40
|
quote: "Quote",
|
|
36
|
-
};
|
|
37
|
-
const blockTypeToBlockIcon
|
|
38
|
-
bullet:
|
|
39
|
-
code:
|
|
41
|
+
} as const;
|
|
42
|
+
const blockTypeToBlockIcon = {
|
|
43
|
+
bullet: "icon-[mdi--format-list-bulleted]",
|
|
44
|
+
code: "icon-[mdi--code-block-tags]",
|
|
40
45
|
h1: " ",
|
|
41
46
|
h2: " ",
|
|
42
47
|
paragraph: "",
|
|
43
|
-
h6:
|
|
44
|
-
number:
|
|
45
|
-
quote:
|
|
46
|
-
};
|
|
48
|
+
h6: "icon-[mdi--comment-text-outline]",
|
|
49
|
+
number: "icon-[mdi--format-list-numbered]",
|
|
50
|
+
quote: "icon-[mdi--format-quote-open]",
|
|
51
|
+
} as const;
|
|
47
52
|
|
|
48
53
|
const SIZES = Object.freeze([
|
|
49
54
|
"8",
|
|
@@ -65,13 +70,13 @@ const SIZES = Object.freeze([
|
|
|
65
70
|
"72",
|
|
66
71
|
]);
|
|
67
72
|
|
|
68
|
-
const ButtonWrapper = ({ label, ...rest }: KeyValue) => (
|
|
73
|
+
const ButtonWrapper = ({ label, ...rest }: KeyValue & { label: string }) => (
|
|
69
74
|
<Tooltip content={label}>
|
|
70
75
|
<Button aria-label={label} tabIndex={-1} variant="link" {...rest} />
|
|
71
76
|
</Tooltip>
|
|
72
77
|
);
|
|
73
78
|
|
|
74
|
-
export
|
|
79
|
+
export function ToolbarPlugin() {
|
|
75
80
|
const watch = useFormatWatcher();
|
|
76
81
|
const { t } = useTranslation("lexical");
|
|
77
82
|
|
|
@@ -89,68 +94,31 @@ export const ToolbarPlugin = () => {
|
|
|
89
94
|
<Button
|
|
90
95
|
variant="link"
|
|
91
96
|
tabIndex={-1}
|
|
92
|
-
altIcon=
|
|
93
|
-
icon={blockTypeToBlockIcon[watch.blockType]}
|
|
97
|
+
altIcon="icon-[mdi--menu-down]"
|
|
98
|
+
icon={blockTypeToBlockIcon[watch.blockType as never]}
|
|
94
99
|
>
|
|
95
|
-
{blockTypeToBlockName[watch.blockType]}
|
|
100
|
+
{blockTypeToBlockName[watch.blockType as never]}
|
|
96
101
|
</Button>
|
|
97
102
|
<Menu>
|
|
98
|
-
<MenuItem
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/>
|
|
103
|
-
<MenuItem
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
onClick={() => watch.formatHeading("h2")}
|
|
107
|
-
/>
|
|
108
|
-
<MenuItem
|
|
109
|
-
icon={blockTypeToBlockIcon.paragraph}
|
|
110
|
-
label={blockTypeToBlockName.paragraph}
|
|
111
|
-
onClick={watch.formatNormal}
|
|
112
|
-
/>
|
|
113
|
-
<MenuItem
|
|
114
|
-
icon={blockTypeToBlockIcon.quote}
|
|
115
|
-
label={blockTypeToBlockName.quote}
|
|
116
|
-
onClick={watch.formatQuote}
|
|
117
|
-
/>
|
|
118
|
-
<MenuItem
|
|
119
|
-
icon={blockTypeToBlockIcon.code}
|
|
120
|
-
label={blockTypeToBlockName.code}
|
|
121
|
-
onClick={watch.formatBlock}
|
|
122
|
-
/>
|
|
123
|
-
<MenuItem
|
|
124
|
-
icon={blockTypeToBlockIcon.h6}
|
|
125
|
-
label={blockTypeToBlockName.h6}
|
|
126
|
-
onClick={() => watch.formatHeading("h6")}
|
|
127
|
-
/>
|
|
128
|
-
<MenuItem
|
|
129
|
-
icon={blockTypeToBlockIcon.bullet}
|
|
130
|
-
label={blockTypeToBlockName.bullet}
|
|
131
|
-
onClick={watch.formatBulletList}
|
|
132
|
-
/>
|
|
133
|
-
<MenuItem
|
|
134
|
-
icon={blockTypeToBlockIcon.number}
|
|
135
|
-
label={blockTypeToBlockName.number}
|
|
136
|
-
onClick={watch.formatNumberedList}
|
|
137
|
-
/>
|
|
103
|
+
<MenuItem icon={blockTypeToBlockIcon.h1} label={blockTypeToBlockName.h1} onClick={() => watch.formatHeading("h1")} />
|
|
104
|
+
<MenuItem icon={blockTypeToBlockIcon.h2} label={blockTypeToBlockName.h2} onClick={() => watch.formatHeading("h2")} />
|
|
105
|
+
<MenuItem icon={blockTypeToBlockIcon.paragraph} label={blockTypeToBlockName.paragraph} onClick={watch.formatNormal} />
|
|
106
|
+
<MenuItem icon={blockTypeToBlockIcon.quote} label={blockTypeToBlockName.quote} onClick={watch.formatQuote} />
|
|
107
|
+
<MenuItem icon={blockTypeToBlockIcon.code} label={blockTypeToBlockName.code} onClick={watch.formatBlock} />
|
|
108
|
+
<MenuItem icon={blockTypeToBlockIcon.h6} label={blockTypeToBlockName.h6} onClick={() => watch.formatHeading("h6")} />
|
|
109
|
+
<MenuItem icon={blockTypeToBlockIcon.bullet} label={blockTypeToBlockName.bullet} onClick={watch.formatBulletList} />
|
|
110
|
+
<MenuItem icon={blockTypeToBlockIcon.number} label={blockTypeToBlockName.number} onClick={watch.formatNumberedList} />
|
|
138
111
|
</Menu>
|
|
139
112
|
</Dropdown>
|
|
140
113
|
<Divider vertical />
|
|
141
114
|
<div>
|
|
142
115
|
<Dropdown>
|
|
143
|
-
<Button variant="link" altIcon={
|
|
116
|
+
<Button variant="link" altIcon="icon-[mdi--menu-down]" tabIndex={-1}>
|
|
144
117
|
{getValue(watch.fontSize + "", "16")}
|
|
145
118
|
</Button>
|
|
146
119
|
<Menu className="hide-icons">
|
|
147
120
|
{SIZES.map((size) => (
|
|
148
|
-
<MenuItem
|
|
149
|
-
key={size}
|
|
150
|
-
label={size}
|
|
151
|
-
active={watch.fontSize === size}
|
|
152
|
-
onClick={() => watch.onSizeChange(size)}
|
|
153
|
-
/>
|
|
121
|
+
<MenuItem key={size} label={size} active={watch.fontSize === size} onClick={() => watch.onSizeChange(size)} />
|
|
154
122
|
))}
|
|
155
123
|
</Menu>
|
|
156
124
|
</Dropdown>
|
|
@@ -159,54 +127,46 @@ export const ToolbarPlugin = () => {
|
|
|
159
127
|
<ButtonGroup variant="link">
|
|
160
128
|
<ButtonWrapper
|
|
161
129
|
value="start"
|
|
162
|
-
rtlFlip
|
|
163
130
|
label={t("tool.alignStart")}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
131
|
+
variant={watch.align === "start" ? "soft" : "link"}
|
|
132
|
+
color={watch.align === "start" ? "primary" : "default"}
|
|
133
|
+
icon={{ icon: "icon-[mdi--format-align-left]", rtlFlip: true }}
|
|
134
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "start")}
|
|
168
135
|
/>
|
|
169
136
|
<ButtonWrapper
|
|
170
137
|
value="center"
|
|
171
138
|
label={t("tool.alignCenter")}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
139
|
+
variant={watch.align === "center" ? "soft" : "link"}
|
|
140
|
+
color={watch.align === "center" ? "primary" : "default"}
|
|
141
|
+
icon="icon-[mdi--format-align-center]"
|
|
142
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "center")}
|
|
176
143
|
/>
|
|
177
144
|
<ButtonWrapper
|
|
178
145
|
value="end"
|
|
179
|
-
rtlFlip
|
|
180
146
|
label={t("tool.alignEnd")}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
147
|
+
variant={watch.align === "end" ? "soft" : "link"}
|
|
148
|
+
color={watch.align === "end" ? "primary" : "default"}
|
|
149
|
+
icon={{ icon: "icon-[mdi--format-align-right]", rtlFlip: true }}
|
|
150
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "end")}
|
|
185
151
|
/>
|
|
186
152
|
<ButtonWrapper
|
|
187
153
|
value="justify"
|
|
188
|
-
rtlFlip
|
|
189
154
|
label={t("tool.alignJustify")}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
"justify",
|
|
195
|
-
)
|
|
196
|
-
}
|
|
155
|
+
variant={watch.align === "justify" ? "soft" : "link"}
|
|
156
|
+
color={watch.align === "justify" ? "primary" : "default"}
|
|
157
|
+
icon={{ icon: "icon-[mdi--format-align-justify]", rtlFlip: true }}
|
|
158
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "justify")}
|
|
197
159
|
/>
|
|
198
160
|
<ButtonWrapper
|
|
199
161
|
value="justify"
|
|
200
|
-
rtlFlip
|
|
201
162
|
label={t("tool.indentOut")}
|
|
202
|
-
icon={
|
|
163
|
+
icon={{ icon: "icon-[mdi--format-indent-decrease]", rtlFlip: true }}
|
|
203
164
|
onClick={() => watch.outdent()}
|
|
204
165
|
/>
|
|
205
166
|
<ButtonWrapper
|
|
206
167
|
value="justify"
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
icon={CoreIcons.formatIndentIncrease}
|
|
168
|
+
label={t("tool.indentIn")}
|
|
169
|
+
icon={{ icon: "icon-[mdi--format-indent-increase]", rtlFlip: true }}
|
|
210
170
|
onClick={() => watch.indent()}
|
|
211
171
|
/>
|
|
212
172
|
</ButtonGroup>
|
|
@@ -215,65 +175,57 @@ export const ToolbarPlugin = () => {
|
|
|
215
175
|
<ButtonWrapper
|
|
216
176
|
value="bold"
|
|
217
177
|
label={t("tool.bold")}
|
|
218
|
-
icon=
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
178
|
+
icon="icon-[mdi--format-bold]"
|
|
179
|
+
color={textFormat.includes("bold") ? "primary" : "default"}
|
|
180
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold")}
|
|
222
181
|
/>
|
|
223
182
|
<ButtonWrapper
|
|
224
183
|
value="italic"
|
|
225
184
|
label={t("tool.italic")}
|
|
226
|
-
icon=
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
185
|
+
icon="icon-[mdi--format-italic]"
|
|
186
|
+
color={textFormat.includes("italic") ? "primary" : "default"}
|
|
187
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic")}
|
|
230
188
|
/>
|
|
231
189
|
<ButtonWrapper
|
|
232
190
|
value="underline"
|
|
233
191
|
label={t("tool.underline")}
|
|
234
|
-
icon=
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
192
|
+
icon="icon-[mdi--format-underline]"
|
|
193
|
+
color={textFormat.includes("underline") ? "primary" : "default"}
|
|
194
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline")}
|
|
238
195
|
/>
|
|
239
196
|
<ButtonWrapper
|
|
240
197
|
value="strikethrough"
|
|
241
198
|
label={t("tool.strikethrough")}
|
|
242
|
-
icon=
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
FORMAT_TEXT_COMMAND,
|
|
246
|
-
"strikethrough",
|
|
247
|
-
)
|
|
248
|
-
}
|
|
199
|
+
icon="icon-[mdi--format-strikethrough-variant]"
|
|
200
|
+
color={textFormat.includes("strikethrough") ? "primary" : "default"}
|
|
201
|
+
onClick={() => watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "strikethrough")}
|
|
249
202
|
/>
|
|
250
203
|
</ToggleButtonGroup>
|
|
251
204
|
<Divider vertical />
|
|
252
205
|
<ColorInput
|
|
253
206
|
{...{ noOutline: true }}
|
|
254
207
|
value={watch.fontColor}
|
|
255
|
-
onChange={(v
|
|
256
|
-
decorateStart={<Icon icon=
|
|
208
|
+
onChange={(v) => watch.onFontColorSelect(v ?? undefined)}
|
|
209
|
+
decorateStart={<Icon icon="icon-[mdi--format-text]" />}
|
|
257
210
|
/>
|
|
258
211
|
<ColorInput
|
|
259
212
|
{...{ noOutline: true }}
|
|
260
213
|
value={watch.bgColor}
|
|
261
|
-
onChange={(v
|
|
262
|
-
decorateStart={<Icon icon=
|
|
214
|
+
onChange={(v) => watch.onBgColorSelect(v ?? undefined)}
|
|
215
|
+
decorateStart={<Icon icon="icon-[mdi--format-color-fill]" />}
|
|
263
216
|
/>
|
|
264
217
|
<ButtonWrapper
|
|
265
218
|
value="hilight"
|
|
266
219
|
label={t("tool.hilight")}
|
|
267
|
-
icon=
|
|
220
|
+
icon="icon-[mdi--format-color-highlight]"
|
|
268
221
|
onClick={() => watch.onBgColorSelect("#fde68a")}
|
|
269
222
|
/>
|
|
270
223
|
<ButtonWrapper
|
|
271
224
|
value="hilight"
|
|
272
225
|
label={t("tool.clear")}
|
|
273
|
-
icon=
|
|
226
|
+
icon="icon-[mdi--format-clear]"
|
|
274
227
|
onClick={() => watch.clearFormatting()}
|
|
275
228
|
/>
|
|
276
|
-
<Divider />
|
|
277
229
|
</div>
|
|
278
230
|
);
|
|
279
|
-
}
|
|
231
|
+
}
|