@collabchron/notiq 1.1.11 → 1.2.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/dist/AICommandBarPlugin-ZEC755KY.mjs +27 -0
- package/dist/{AIDialog-2WZUFWSC.mjs → AIDialog-HJW6PQPR.mjs} +12 -13
- package/dist/{AudioComponent-CKLMLB5T.mjs → AudioComponent-W5XMZPQB.mjs} +10 -6
- package/dist/{DynamicBlockComponent-2LOADZUX.mjs → DynamicBlockComponent-CHRL2GAQ.mjs} +7 -6
- package/dist/{EquationComponent-4NFG55NQ.mjs → EquationComponent-GNQHG53L.mjs} +26 -7
- package/dist/{ExcalidrawComponent-SIMURTCA.mjs → ExcalidrawComponent-POMYXDSG.mjs} +34 -7
- package/dist/{FileComponent-Y56MX5QD.mjs → FileComponent-EOVCH4V5.mjs} +9 -5
- package/dist/{HintComponet-ET7M2Q7S.mjs → HintComponet-QXL5ESND.mjs} +32 -8
- package/dist/{InlineImageComponent-FVTA4LXZ.mjs → InlineImageComponent-KDN3VGZC.mjs} +8 -3
- package/dist/{StoryBuilderComponent-WQSNFPMM.mjs → StoryBuilderComponent-CBRFPFTR.mjs} +9 -10
- package/dist/{chunk-6UVNHT3T.mjs → chunk-4SYRK2NH.mjs} +23 -1
- package/dist/chunk-5CJZC5IB.mjs +9086 -0
- package/dist/{chunk-MW6MAUY3.mjs → chunk-6NK5DONB.mjs} +1 -1
- package/dist/{chunk-N6ILV6NF.mjs → chunk-ACW4DLVO.mjs} +21 -7
- package/dist/chunk-BCGD2YXP.mjs +574 -0
- package/dist/{chunk-TC3IISJZ.mjs → chunk-BTR3TPIN.mjs} +18 -5
- package/dist/{chunk-XAVQAXOJ.mjs → chunk-CQCS5YPS.mjs} +3 -5
- package/dist/{chunk-YTLUQJE2.mjs → chunk-D4UBNSUW.mjs} +1 -1
- package/dist/{chunk-KNW2CGIP.mjs → chunk-DBRZIA43.mjs} +4 -1
- package/dist/{chunk-CDAMHK63.mjs → chunk-GJK2L7ZM.mjs} +23 -2
- package/dist/{chunk-GYYLZ3MQ.mjs → chunk-IKYVBTCJ.mjs} +43 -20
- package/dist/chunk-IXRA5D53.mjs +10447 -0
- package/dist/{chunk-W6VQSFE5.mjs → chunk-J2CEQXG4.mjs} +1 -1
- package/dist/{chunk-43Z4Z2KD.mjs → chunk-JTNLN4JI.mjs} +1 -1
- package/dist/{chunk-OE5JRLCN.mjs → chunk-ONOHG5NB.mjs} +6 -4
- package/dist/{chunk-XZXGYNTY.mjs → chunk-OO42URWA.mjs} +27 -6
- package/dist/chunk-PBVRSNGU.mjs +129 -0
- package/dist/chunk-QCS57TIF.mjs +1794 -0
- package/dist/chunk-RNEIJRUS.mjs +60 -0
- package/dist/chunk-TJPTGECP.mjs +1556 -0
- package/dist/{chunk-XYMXGU4T.mjs → chunk-TMYRA2W4.mjs} +1 -1
- package/dist/{chunk-ZFV2HGD3.mjs → chunk-UNEFOZTS.mjs} +1 -1
- package/dist/chunk-X4NI7EQS.mjs +282 -0
- package/dist/chunk-XAJ4GACN.mjs +746 -0
- package/dist/{chunk-7QRJVZQY.mjs → chunk-YVUQRJVV.mjs} +63 -18
- package/dist/components/editor/Core.d.ts +15 -2
- package/dist/components/editor/index.d.ts +16 -5
- package/dist/components/editor/nodes/EquationNode/EquationNode.d.ts +1 -0
- package/dist/components/editor/nodes/Hint/index.d.ts +2 -1
- package/dist/components/editor/plugins/AICommandBarPlugin/index.d.ts +73 -1
- package/dist/components/editor/plugins/DraggableBlockPlugin/index.d.ts +25 -3
- package/dist/components/editor/plugins/InlineCopilotPlugin/index.d.ts +16 -3
- package/dist/components/editor/plugins/LinkWithMetaData/index.d.ts +20 -25
- package/dist/components/editor/plugins/MarkdownPastePlugin/index.d.ts +5 -0
- package/dist/components/editor/plugins/MarkdownTransformers/index.d.ts +2 -0
- package/dist/components/editor/plugins/SlashCommand/index.d.ts +18 -1
- package/dist/components/editor/plugins/SmartTypographyPlugin/index.d.ts +26 -0
- package/dist/components/editor/utils/aiStream.d.ts +27 -0
- package/dist/components/editor/utils/excalidrawDiagramBuilder.d.ts +29 -0
- package/dist/components/editor/utils/markdownTransformers.d.ts +4 -1
- package/dist/components/editor/utils/url.d.ts +16 -4
- package/dist/components/providers/AIContext.d.ts +8 -0
- package/dist/components/ui/equation/equationTypography.d.ts +23 -0
- package/dist/core/extension.d.ts +3 -1
- package/dist/core/extensions/blocks-kit.d.ts +22 -1
- package/dist/core/extensions/copilot-and-collab.d.ts +15 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/react/NotiqContent.d.ts +4 -1
- package/dist/core/react/NotiqEditor.d.ts +8 -8
- package/dist/core/react/index.d.ts +1 -0
- package/dist/core/react/node-renderers.d.ts +73 -0
- package/dist/core/types.d.ts +1 -0
- package/dist/core.js +18136 -9084
- package/dist/core.mjs +58 -44
- package/dist/hooks/instructions-messages.d.ts +13 -4
- package/dist/{image-TPW7PZZK.mjs → image-AL6PHM2A.mjs} +18 -13
- package/dist/index.js +15180 -12858
- package/dist/index.mjs +121 -1641
- package/dist/{insert-audio-C66RZRKY.mjs → insert-audio-CRWR7EO5.mjs} +6 -8
- package/dist/{insert-file-3DTGRO7W.mjs → insert-file-I73AZW3L.mjs} +6 -8
- package/dist/{insert-gif-FIMCCBAI.mjs → insert-gif-KWRC3ACT.mjs} +4 -4
- package/dist/{insert-image-CZV6HWQZ.mjs → insert-image-XIY6BGW5.mjs} +6 -5
- package/dist/{insert-poll-6BCIFY5G.mjs → insert-poll-J5YVZNZ4.mjs} +4 -3
- package/dist/{insert-table-ZRJP6X52.mjs → insert-table-OIMJRFFK.mjs} +1 -1
- package/dist/{poll-component-VHMM5KKZ.mjs → poll-component-TVHXIKGQ.mjs} +3 -2
- package/dist/react.js +17933 -9531
- package/dist/react.mjs +41 -34
- package/dist/{stepper-4AO5XMO7.mjs → stepper-ILF7YXTO.mjs} +64 -74
- package/dist/styles/notiq.css +1 -1
- package/package.json +2 -2
- package/src/styles/notiq.css +20 -0
- package/dist/AICommandBarPlugin-TADJ3X2Y.mjs +0 -12
- package/dist/CodeActionMenuPlugin-MRKY67ED.mjs +0 -14
- package/dist/CollaborationPlugin-TIZOQBUT.mjs +0 -405
- package/dist/CollaboratorsBar-TMKBOBJI.mjs +0 -20
- package/dist/CommentsPlugin-5M4RD6YO.mjs +0 -19
- package/dist/ExcalidrawPlugin-2SGPIQ6U.mjs +0 -14
- package/dist/ExportPlugin-OKZOLBGS.mjs +0 -42
- package/dist/FloatingLinkEditorPlugin-MABB34L7.mjs +0 -12
- package/dist/FloatingTextFormatToolbarPlugin-SO5VON7Q.mjs +0 -45
- package/dist/InlineCopilotPlugin-PNS5Y6OO.mjs +0 -360
- package/dist/MobileToolbar-JKP2MLQJ.mjs +0 -984
- package/dist/SlashCommand-2TNOOUBM.mjs +0 -39
- package/dist/TableCellActionMenuPlugin-YWBA64J7.mjs +0 -838
- package/dist/TableHoverActionsPlugin-2EIXHEXN.mjs +0 -265
- package/dist/TemplatePlugin-HNTPEXBB.mjs +0 -9
- package/dist/ToolbarPlugin-IIAOU4P5.mjs +0 -35
- package/dist/VersionHistoryPlugin-23MAZB4G.mjs +0 -371
- package/dist/background-color-OZJCBYCT.mjs +0 -425
- package/dist/block-format-MTSIXWID.mjs +0 -14
- package/dist/chunk-2KESP7OU.mjs +0 -809
- package/dist/chunk-3AHNLIME.mjs +0 -1701
- package/dist/chunk-3IILA3IP.mjs +0 -28
- package/dist/chunk-4DVIYZVB.mjs +0 -193
- package/dist/chunk-4FFTOZGJ.mjs +0 -103
- package/dist/chunk-4UMUPCDK.mjs +0 -68
- package/dist/chunk-6D6QLRYR.mjs +0 -238
- package/dist/chunk-6SRMKQSD.mjs +0 -682
- package/dist/chunk-ACV47ZKE.mjs +0 -201
- package/dist/chunk-AYNKORDO.mjs +0 -6
- package/dist/chunk-BGV62GC2.mjs +0 -26
- package/dist/chunk-D3IOUQFR.mjs +0 -441
- package/dist/chunk-EEBA6OAH.mjs +0 -59
- package/dist/chunk-EIZMKFHF.mjs +0 -32
- package/dist/chunk-EVPWKNE4.mjs +0 -27
- package/dist/chunk-FMJ7DGWP.mjs +0 -144
- package/dist/chunk-FYLRS4BG.mjs +0 -88
- package/dist/chunk-HOZ4QRFV.mjs +0 -536
- package/dist/chunk-IAFCQV3Z.mjs +0 -349
- package/dist/chunk-IU2N42JJ.mjs +0 -1763
- package/dist/chunk-J6ZUY5BY.mjs +0 -202
- package/dist/chunk-K5OAFEVY.mjs +0 -191
- package/dist/chunk-KDA7ZYMJ.mjs +0 -431
- package/dist/chunk-KXRLARGI.mjs +0 -26
- package/dist/chunk-LAUAYRPC.mjs +0 -944
- package/dist/chunk-LLCP7NVE.mjs +0 -449
- package/dist/chunk-LU2XWLOE.mjs +0 -219
- package/dist/chunk-MPTE332I.mjs +0 -787
- package/dist/chunk-MTQZWJHR.mjs +0 -111
- package/dist/chunk-OXWTZV3U.mjs +0 -174
- package/dist/chunk-PD5K4AGP.mjs +0 -64
- package/dist/chunk-PFH63ZU4.mjs +0 -33
- package/dist/chunk-PHRVYPVM.mjs +0 -808
- package/dist/chunk-R7WFRENU.mjs +0 -262
- package/dist/chunk-RAVYEEIC.mjs +0 -36
- package/dist/chunk-RJQTA6HG.mjs +0 -358
- package/dist/chunk-SAOJHVPE.mjs +0 -153
- package/dist/chunk-VGAX6YEY.mjs +0 -399
- package/dist/chunk-W6GAJXUS.mjs +0 -334
- package/dist/chunk-XYDBUQ6Z.mjs +0 -1978
- package/dist/chunk-XYT6XM5S.mjs +0 -496
- package/dist/chunk-YDDBQZ77.mjs +0 -409
- package/dist/chunk-YE7M2VKR.mjs +0 -132
- package/dist/chunk-Z6JAFF55.mjs +0 -555
- package/dist/chunk-ZKZ7MLSS.mjs +0 -165
- package/dist/color-23323E3B.mjs +0 -13
- package/dist/font-IJKFR4BM.mjs +0 -12
- package/dist/font-size-GTL6UVQL.mjs +0 -15
- package/dist/insert-node-MA3FXEYN.mjs +0 -245
- package/dist/table-dropdown-4VCRSQB6.mjs +0 -391
- package/dist/text-align-CSDLJUDA.mjs +0 -121
- package/dist/text-format-6L5N3CHZ.mjs +0 -15
|
@@ -1,838 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useModal
|
|
3
|
-
} from "./chunk-IAFCQV3Z.mjs";
|
|
4
|
-
import {
|
|
5
|
-
Popover,
|
|
6
|
-
PopoverContent,
|
|
7
|
-
PopoverTrigger
|
|
8
|
-
} from "./chunk-IIVB6JNE.mjs";
|
|
9
|
-
import "./chunk-JHXDLYEV.mjs";
|
|
10
|
-
import {
|
|
11
|
-
init_react_shim
|
|
12
|
-
} from "./chunk-WYCFGRFJ.mjs";
|
|
13
|
-
|
|
14
|
-
// src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx
|
|
15
|
-
init_react_shim();
|
|
16
|
-
import { Compact } from "@uiw/react-color";
|
|
17
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
18
|
-
import { useLexicalEditable } from "@lexical/react/useLexicalEditable";
|
|
19
|
-
import {
|
|
20
|
-
$deleteTableColumn__EXPERIMENTAL,
|
|
21
|
-
$deleteTableRow__EXPERIMENTAL,
|
|
22
|
-
$getNodeTriplet,
|
|
23
|
-
$getTableCellNodeFromLexicalNode,
|
|
24
|
-
$getTableColumnIndexFromTableCellNode,
|
|
25
|
-
$getTableNodeFromLexicalNodeOrThrow,
|
|
26
|
-
$getTableRowIndexFromTableCellNode,
|
|
27
|
-
$insertTableColumn__EXPERIMENTAL,
|
|
28
|
-
$insertTableRow__EXPERIMENTAL,
|
|
29
|
-
$isTableCellNode,
|
|
30
|
-
$isTableRowNode,
|
|
31
|
-
$isTableSelection,
|
|
32
|
-
$unmergeCell,
|
|
33
|
-
getTableElement,
|
|
34
|
-
getTableObserverFromTableElement,
|
|
35
|
-
TableCellHeaderStates,
|
|
36
|
-
TableCellNode
|
|
37
|
-
} from "@lexical/table";
|
|
38
|
-
import { mergeRegister } from "@lexical/utils";
|
|
39
|
-
import {
|
|
40
|
-
$createParagraphNode,
|
|
41
|
-
$getRoot,
|
|
42
|
-
$getSelection,
|
|
43
|
-
$isElementNode,
|
|
44
|
-
$isParagraphNode,
|
|
45
|
-
$isRangeSelection,
|
|
46
|
-
$isTextNode,
|
|
47
|
-
COMMAND_PRIORITY_CRITICAL,
|
|
48
|
-
getDOMSelection,
|
|
49
|
-
SELECTION_CHANGE_COMMAND
|
|
50
|
-
} from "lexical";
|
|
51
|
-
import * as React from "react";
|
|
52
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
53
|
-
import { createPortal } from "react-dom";
|
|
54
|
-
import {
|
|
55
|
-
ArrowDown,
|
|
56
|
-
ArrowLeft,
|
|
57
|
-
ArrowRight,
|
|
58
|
-
ArrowUp,
|
|
59
|
-
Merge,
|
|
60
|
-
PaintBucket,
|
|
61
|
-
Split,
|
|
62
|
-
Table,
|
|
63
|
-
Table as TableIcon,
|
|
64
|
-
TableColumnsSplit,
|
|
65
|
-
TableRowsSplit,
|
|
66
|
-
Trash,
|
|
67
|
-
Trash2,
|
|
68
|
-
X
|
|
69
|
-
} from "lucide-react";
|
|
70
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
71
|
-
function computeSelectionCount(selection) {
|
|
72
|
-
const selectionShape = selection.getShape();
|
|
73
|
-
return {
|
|
74
|
-
columns: selectionShape.toX - selectionShape.fromX + 1,
|
|
75
|
-
rows: selectionShape.toY - selectionShape.fromY + 1
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function $canUnmerge() {
|
|
79
|
-
try {
|
|
80
|
-
const selection = $getSelection();
|
|
81
|
-
if ($isRangeSelection(selection) && !selection.isCollapsed() || $isTableSelection(selection) && !selection.anchor.is(selection.focus) || !$isRangeSelection(selection) && !$isTableSelection(selection)) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
const [cell] = $getNodeTriplet(selection.anchor);
|
|
85
|
-
return cell ? cell.__colSpan > 1 || cell.__rowSpan > 1 : false;
|
|
86
|
-
} catch (e) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function $cellContainsEmptyParagraph(cell) {
|
|
91
|
-
if (cell.getChildrenSize() !== 1) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
const firstChild = cell.getFirstChildOrThrow();
|
|
95
|
-
if (!$isParagraphNode(firstChild) || !firstChild.isEmpty()) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
function $selectLastDescendant(node) {
|
|
101
|
-
const lastDescendant = node.getLastDescendant();
|
|
102
|
-
if ($isTextNode(lastDescendant)) {
|
|
103
|
-
lastDescendant.select();
|
|
104
|
-
} else if ($isElementNode(lastDescendant)) {
|
|
105
|
-
lastDescendant.selectEnd();
|
|
106
|
-
} else if (lastDescendant !== null) {
|
|
107
|
-
lastDescendant.selectNext();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function currentCellBackgroundColor(editor) {
|
|
111
|
-
try {
|
|
112
|
-
return editor.getEditorState().read(() => {
|
|
113
|
-
try {
|
|
114
|
-
const selection = $getSelection();
|
|
115
|
-
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
116
|
-
const [cell] = $getNodeTriplet(selection.anchor);
|
|
117
|
-
if ($isTableCellNode(cell)) {
|
|
118
|
-
return cell.getBackgroundColor();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} catch (e) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
});
|
|
126
|
-
} catch (e) {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function TableActionMenu({
|
|
131
|
-
tableCellNode: _tableCellNode,
|
|
132
|
-
contextRef,
|
|
133
|
-
cellMerge
|
|
134
|
-
}) {
|
|
135
|
-
const [editor] = useLexicalComposerContext();
|
|
136
|
-
const dropDownRef = useRef(null);
|
|
137
|
-
const [tableCellNode, updateTableCellNode] = useState(_tableCellNode);
|
|
138
|
-
const [selectionCounts, updateSelectionCounts] = useState({
|
|
139
|
-
columns: 1,
|
|
140
|
-
rows: 1
|
|
141
|
-
});
|
|
142
|
-
const [canMergeCells, setCanMergeCells] = useState(false);
|
|
143
|
-
const [canUnmergeCell, setCanUnmergeCell] = useState(false);
|
|
144
|
-
const [backgroundColor, setBackgroundColor] = useState(
|
|
145
|
-
() => currentCellBackgroundColor(editor) || ""
|
|
146
|
-
);
|
|
147
|
-
const [model, showModal] = useModal();
|
|
148
|
-
useEffect(() => {
|
|
149
|
-
return editor.registerMutationListener(
|
|
150
|
-
TableCellNode,
|
|
151
|
-
(nodeMutations) => {
|
|
152
|
-
const nodeUpdated = nodeMutations.get(tableCellNode.getKey()) === "updated";
|
|
153
|
-
if (nodeUpdated) {
|
|
154
|
-
editor.getEditorState().read(() => {
|
|
155
|
-
updateTableCellNode(tableCellNode.getLatest());
|
|
156
|
-
});
|
|
157
|
-
setBackgroundColor(currentCellBackgroundColor(editor) || "");
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
{ skipInitialization: true }
|
|
161
|
-
);
|
|
162
|
-
}, [editor, tableCellNode]);
|
|
163
|
-
useEffect(() => {
|
|
164
|
-
editor.getEditorState().read(() => {
|
|
165
|
-
const selection = $getSelection();
|
|
166
|
-
if ($isTableSelection(selection)) {
|
|
167
|
-
const currentSelectionCounts = computeSelectionCount(selection);
|
|
168
|
-
updateSelectionCounts(computeSelectionCount(selection));
|
|
169
|
-
setCanMergeCells(
|
|
170
|
-
currentSelectionCounts.columns > 1 || currentSelectionCounts.rows > 1
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
setCanUnmergeCell($canUnmerge());
|
|
174
|
-
});
|
|
175
|
-
}, [editor]);
|
|
176
|
-
useEffect(() => {
|
|
177
|
-
const menuButtonElement = contextRef.current;
|
|
178
|
-
const dropDownElement = dropDownRef.current;
|
|
179
|
-
const rootElement = editor.getRootElement();
|
|
180
|
-
if (menuButtonElement != null && dropDownElement != null && rootElement != null) {
|
|
181
|
-
const rootEleRect = rootElement.getBoundingClientRect();
|
|
182
|
-
const menuButtonRect = menuButtonElement.getBoundingClientRect();
|
|
183
|
-
dropDownElement.style.opacity = "1";
|
|
184
|
-
const dropDownElementRect = dropDownElement.getBoundingClientRect();
|
|
185
|
-
const margin = 5;
|
|
186
|
-
let leftPosition = menuButtonRect.right + margin;
|
|
187
|
-
if (leftPosition + dropDownElementRect.width > window.innerWidth || leftPosition + dropDownElementRect.width > rootEleRect.right) {
|
|
188
|
-
const position = menuButtonRect.left - dropDownElementRect.width - margin;
|
|
189
|
-
leftPosition = (position < 0 ? margin : position) + window.pageXOffset;
|
|
190
|
-
}
|
|
191
|
-
dropDownElement.style.left = `${leftPosition + window.pageXOffset}px`;
|
|
192
|
-
let topPosition = menuButtonRect.top;
|
|
193
|
-
if (topPosition + dropDownElementRect.height > window.innerHeight) {
|
|
194
|
-
const position = menuButtonRect.bottom - dropDownElementRect.height;
|
|
195
|
-
topPosition = (position < 0 ? margin : position) + window.pageYOffset;
|
|
196
|
-
}
|
|
197
|
-
dropDownElement.style.top = `${topPosition + +window.pageYOffset}px`;
|
|
198
|
-
}
|
|
199
|
-
}, [contextRef, dropDownRef, editor]);
|
|
200
|
-
const clearTableSelection = useCallback(() => {
|
|
201
|
-
editor.update(() => {
|
|
202
|
-
if (tableCellNode.isAttached()) {
|
|
203
|
-
try {
|
|
204
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
205
|
-
const tableElement = getTableElement(
|
|
206
|
-
tableNode,
|
|
207
|
-
editor.getElementByKey(tableNode.getKey())
|
|
208
|
-
);
|
|
209
|
-
if (tableElement !== null) {
|
|
210
|
-
const tableObserver = getTableObserverFromTableElement(tableElement);
|
|
211
|
-
if (tableObserver !== null) {
|
|
212
|
-
tableObserver.$clearHighlight();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
tableNode.markDirty();
|
|
216
|
-
updateTableCellNode(tableCellNode.getLatest());
|
|
217
|
-
} catch (e) {
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const rootNode = $getRoot();
|
|
221
|
-
rootNode.selectStart();
|
|
222
|
-
});
|
|
223
|
-
}, [editor, tableCellNode]);
|
|
224
|
-
const mergeTableCellsAtSelection = () => {
|
|
225
|
-
editor.update(() => {
|
|
226
|
-
const selection = $getSelection();
|
|
227
|
-
if ($isTableSelection(selection)) {
|
|
228
|
-
const { columns, rows } = computeSelectionCount(selection);
|
|
229
|
-
const nodes = selection.getNodes();
|
|
230
|
-
let firstCell = null;
|
|
231
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
232
|
-
const node = nodes[i];
|
|
233
|
-
if ($isTableCellNode(node)) {
|
|
234
|
-
if (firstCell === null) {
|
|
235
|
-
node.setColSpan(columns).setRowSpan(rows);
|
|
236
|
-
firstCell = node;
|
|
237
|
-
const isEmpty = $cellContainsEmptyParagraph(node);
|
|
238
|
-
let firstChild;
|
|
239
|
-
if (isEmpty && $isParagraphNode(firstChild = node.getFirstChild())) {
|
|
240
|
-
firstChild.remove();
|
|
241
|
-
}
|
|
242
|
-
} else if ($isTableCellNode(firstCell)) {
|
|
243
|
-
const isEmpty = $cellContainsEmptyParagraph(node);
|
|
244
|
-
if (!isEmpty) {
|
|
245
|
-
firstCell.append(...node.getChildren());
|
|
246
|
-
}
|
|
247
|
-
node.remove();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (firstCell !== null) {
|
|
252
|
-
if (firstCell.getChildrenSize() === 0) {
|
|
253
|
-
firstCell.append($createParagraphNode());
|
|
254
|
-
}
|
|
255
|
-
$selectLastDescendant(firstCell);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
};
|
|
260
|
-
const unmergeTableCellsAtSelection = () => {
|
|
261
|
-
editor.update(() => {
|
|
262
|
-
$unmergeCell();
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
const insertTableRowAtSelection = useCallback(
|
|
266
|
-
(shouldInsertAfter) => {
|
|
267
|
-
editor.update(() => {
|
|
268
|
-
for (let i = 0; i < selectionCounts.rows; i++) {
|
|
269
|
-
$insertTableRow__EXPERIMENTAL(shouldInsertAfter);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
},
|
|
273
|
-
[editor, selectionCounts.rows]
|
|
274
|
-
);
|
|
275
|
-
const insertTableColumnAtSelection = useCallback(
|
|
276
|
-
(shouldInsertAfter) => {
|
|
277
|
-
editor.update(() => {
|
|
278
|
-
for (let i = 0; i < selectionCounts.columns; i++) {
|
|
279
|
-
$insertTableColumn__EXPERIMENTAL(shouldInsertAfter);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
},
|
|
283
|
-
[editor, selectionCounts.columns]
|
|
284
|
-
);
|
|
285
|
-
const deleteTableRowAtSelection = useCallback(() => {
|
|
286
|
-
editor.update(() => {
|
|
287
|
-
$deleteTableRow__EXPERIMENTAL();
|
|
288
|
-
});
|
|
289
|
-
}, [editor]);
|
|
290
|
-
const deleteTableAtSelection = useCallback(() => {
|
|
291
|
-
editor.update(() => {
|
|
292
|
-
try {
|
|
293
|
-
if (tableCellNode.isAttached()) {
|
|
294
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
295
|
-
tableNode.remove();
|
|
296
|
-
}
|
|
297
|
-
} catch (e) {
|
|
298
|
-
}
|
|
299
|
-
clearTableSelection();
|
|
300
|
-
});
|
|
301
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
302
|
-
const deleteTableColumnAtSelection = useCallback(() => {
|
|
303
|
-
editor.update(() => {
|
|
304
|
-
$deleteTableColumn__EXPERIMENTAL();
|
|
305
|
-
});
|
|
306
|
-
}, [editor]);
|
|
307
|
-
const toggleTableRowIsHeader = useCallback(() => {
|
|
308
|
-
editor.update(() => {
|
|
309
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
310
|
-
const tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
|
|
311
|
-
const tableRows = tableNode.getChildren();
|
|
312
|
-
if (tableRowIndex >= tableRows.length || tableRowIndex < 0) {
|
|
313
|
-
throw new Error("Expected table cell to be inside of table row.");
|
|
314
|
-
}
|
|
315
|
-
const tableRow = tableRows[tableRowIndex];
|
|
316
|
-
if (!$isTableRowNode(tableRow)) {
|
|
317
|
-
throw new Error("Expected table row");
|
|
318
|
-
}
|
|
319
|
-
const newStyle = tableCellNode.getHeaderStyles() ^ TableCellHeaderStates.ROW;
|
|
320
|
-
tableRow.getChildren().forEach((tableCell) => {
|
|
321
|
-
if (!$isTableCellNode(tableCell)) {
|
|
322
|
-
throw new Error("Expected table cell");
|
|
323
|
-
}
|
|
324
|
-
tableCell.setHeaderStyles(newStyle, TableCellHeaderStates.ROW);
|
|
325
|
-
});
|
|
326
|
-
clearTableSelection();
|
|
327
|
-
});
|
|
328
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
329
|
-
const toggleTableColumnIsHeader = useCallback(() => {
|
|
330
|
-
editor.update(() => {
|
|
331
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
332
|
-
const tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode);
|
|
333
|
-
const tableRows = tableNode.getChildren();
|
|
334
|
-
const maxRowsLength = Math.max(
|
|
335
|
-
...tableRows.map((row) => row.getChildren().length)
|
|
336
|
-
);
|
|
337
|
-
if (tableColumnIndex >= maxRowsLength || tableColumnIndex < 0) {
|
|
338
|
-
throw new Error("Expected table cell to be inside of table row.");
|
|
339
|
-
}
|
|
340
|
-
const newStyle = tableCellNode.getHeaderStyles() ^ TableCellHeaderStates.COLUMN;
|
|
341
|
-
for (let r = 0; r < tableRows.length; r++) {
|
|
342
|
-
const tableRow = tableRows[r];
|
|
343
|
-
if (!$isTableRowNode(tableRow)) {
|
|
344
|
-
throw new Error("Expected table row");
|
|
345
|
-
}
|
|
346
|
-
const tableCells = tableRow.getChildren();
|
|
347
|
-
if (tableColumnIndex >= tableCells.length) {
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
const tableCell = tableCells[tableColumnIndex];
|
|
351
|
-
if (!$isTableCellNode(tableCell)) {
|
|
352
|
-
throw new Error("Expected table cell");
|
|
353
|
-
}
|
|
354
|
-
tableCell.setHeaderStyles(newStyle, TableCellHeaderStates.COLUMN);
|
|
355
|
-
}
|
|
356
|
-
clearTableSelection();
|
|
357
|
-
});
|
|
358
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
359
|
-
const toggleRowStriping = useCallback(() => {
|
|
360
|
-
editor.update(() => {
|
|
361
|
-
if (tableCellNode.isAttached()) {
|
|
362
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
363
|
-
if (tableNode) {
|
|
364
|
-
tableNode.setRowStriping(!tableNode.getRowStriping());
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
clearTableSelection();
|
|
368
|
-
});
|
|
369
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
370
|
-
const handleCellBackgroundColor = useCallback(
|
|
371
|
-
(value) => {
|
|
372
|
-
editor.update(() => {
|
|
373
|
-
try {
|
|
374
|
-
const selection = $getSelection();
|
|
375
|
-
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
376
|
-
const [cell] = $getNodeTriplet(selection.anchor);
|
|
377
|
-
if ($isTableCellNode(cell)) {
|
|
378
|
-
cell.setBackgroundColor(value);
|
|
379
|
-
}
|
|
380
|
-
if ($isTableSelection(selection)) {
|
|
381
|
-
const nodes = selection.getNodes();
|
|
382
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
383
|
-
const node = nodes[i];
|
|
384
|
-
if ($isTableCellNode(node)) {
|
|
385
|
-
node.setBackgroundColor(value);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
} else if (tableCellNode && tableCellNode.isAttached()) {
|
|
390
|
-
tableCellNode.setBackgroundColor(value);
|
|
391
|
-
}
|
|
392
|
-
} catch (e) {
|
|
393
|
-
if (tableCellNode && tableCellNode.isAttached()) {
|
|
394
|
-
tableCellNode.setBackgroundColor(value);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
setBackgroundColor(value);
|
|
399
|
-
},
|
|
400
|
-
[editor, tableCellNode]
|
|
401
|
-
);
|
|
402
|
-
const commands = React.useMemo(
|
|
403
|
-
() => [
|
|
404
|
-
{
|
|
405
|
-
label: "Background",
|
|
406
|
-
func: () => {
|
|
407
|
-
showModal(
|
|
408
|
-
"Background",
|
|
409
|
-
"Select color",
|
|
410
|
-
(onClose) => /* @__PURE__ */ jsx(
|
|
411
|
-
Compact,
|
|
412
|
-
{
|
|
413
|
-
style: { background: "transparent", width: "100%" },
|
|
414
|
-
color: backgroundColor,
|
|
415
|
-
onChange: (color) => {
|
|
416
|
-
handleCellBackgroundColor(color.hex);
|
|
417
|
-
onClose();
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
),
|
|
421
|
-
true
|
|
422
|
-
);
|
|
423
|
-
},
|
|
424
|
-
icon: /* @__PURE__ */ jsx(PaintBucket, {}),
|
|
425
|
-
style: { backgroundColor: `${currentCellBackgroundColor(editor)}` }
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
label: "Insert Row Above",
|
|
429
|
-
func: () => insertTableRowAtSelection(false),
|
|
430
|
-
icon: /* @__PURE__ */ jsx(TableRowsSplit, {})
|
|
431
|
-
},
|
|
432
|
-
{
|
|
433
|
-
label: "Insert Row Below",
|
|
434
|
-
func: () => insertTableRowAtSelection(true),
|
|
435
|
-
icon: /* @__PURE__ */ jsx(TableRowsSplit, {})
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
label: "Insert Column Left",
|
|
439
|
-
func: () => insertTableColumnAtSelection(false),
|
|
440
|
-
icon: /* @__PURE__ */ jsx(TableColumnsSplit, {})
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
label: "Insert Column Right",
|
|
444
|
-
func: () => insertTableColumnAtSelection(true),
|
|
445
|
-
icon: /* @__PURE__ */ jsx(TableColumnsSplit, {})
|
|
446
|
-
},
|
|
447
|
-
{ label: "Delete Row", func: deleteTableRowAtSelection, icon: /* @__PURE__ */ jsx(Trash, {}) },
|
|
448
|
-
{
|
|
449
|
-
label: "Delete Column",
|
|
450
|
-
func: deleteTableColumnAtSelection,
|
|
451
|
-
icon: /* @__PURE__ */ jsx(Trash, {})
|
|
452
|
-
},
|
|
453
|
-
{ label: "Delete Table", func: deleteTableAtSelection, icon: /* @__PURE__ */ jsx(Trash, {}) },
|
|
454
|
-
{
|
|
455
|
-
label: "Toggle Row Header",
|
|
456
|
-
func: toggleTableRowIsHeader,
|
|
457
|
-
icon: /* @__PURE__ */ jsx(Table, {})
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
label: "Toggle Column Header",
|
|
461
|
-
func: toggleTableColumnIsHeader,
|
|
462
|
-
icon: /* @__PURE__ */ jsx(Table, {})
|
|
463
|
-
},
|
|
464
|
-
{ label: "Toggle Striping", func: toggleRowStriping, icon: /* @__PURE__ */ jsx(Table, {}) }
|
|
465
|
-
],
|
|
466
|
-
[
|
|
467
|
-
backgroundColor,
|
|
468
|
-
canMergeCells,
|
|
469
|
-
canUnmergeCell,
|
|
470
|
-
insertTableRowAtSelection,
|
|
471
|
-
insertTableColumnAtSelection,
|
|
472
|
-
deleteTableRowAtSelection,
|
|
473
|
-
deleteTableColumnAtSelection,
|
|
474
|
-
deleteTableAtSelection,
|
|
475
|
-
toggleTableRowIsHeader,
|
|
476
|
-
toggleTableColumnIsHeader,
|
|
477
|
-
toggleRowStriping,
|
|
478
|
-
backgroundColor,
|
|
479
|
-
editor,
|
|
480
|
-
tableCellNode,
|
|
481
|
-
cellMerge,
|
|
482
|
-
selectionCounts
|
|
483
|
-
]
|
|
484
|
-
);
|
|
485
|
-
if (cellMerge) {
|
|
486
|
-
if (canMergeCells) {
|
|
487
|
-
commands.push({
|
|
488
|
-
label: "Merge Cells",
|
|
489
|
-
func: mergeTableCellsAtSelection,
|
|
490
|
-
icon: /* @__PURE__ */ jsx(Merge, {})
|
|
491
|
-
});
|
|
492
|
-
} else if (canUnmergeCell) {
|
|
493
|
-
commands.push({
|
|
494
|
-
label: "Unmerge Cells",
|
|
495
|
-
func: unmergeTableCellsAtSelection,
|
|
496
|
-
icon: /* @__PURE__ */ jsx(Split, {})
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5 bg-white/95 dark:bg-zinc-900/95 border border-zinc-200 dark:border-zinc-700/80 rounded-xl px-2 py-1 shadow-xl backdrop-blur-md text-zinc-700 dark:text-zinc-300", children: [
|
|
501
|
-
/* @__PURE__ */ jsxs(Popover, { modal: false, children: [
|
|
502
|
-
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
503
|
-
"button",
|
|
504
|
-
{
|
|
505
|
-
type: "button",
|
|
506
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:text-zinc-950 dark:hover:text-white transition-colors",
|
|
507
|
-
title: "Cell background color",
|
|
508
|
-
children: /* @__PURE__ */ jsx(PaintBucket, { className: "w-4 h-4" })
|
|
509
|
-
}
|
|
510
|
-
) }),
|
|
511
|
-
/* @__PURE__ */ jsxs(
|
|
512
|
-
PopoverContent,
|
|
513
|
-
{
|
|
514
|
-
side: "top",
|
|
515
|
-
align: "center",
|
|
516
|
-
sideOffset: 8,
|
|
517
|
-
className: "p-2.5 bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 rounded-xl shadow-2xl w-44 z-50 text-zinc-900 dark:text-zinc-100",
|
|
518
|
-
children: [
|
|
519
|
-
/* @__PURE__ */ jsx("span", { className: "text-[10px] font-semibold text-zinc-500 dark:text-zinc-400 uppercase tracking-wider block mb-2", children: "Cell Color" }),
|
|
520
|
-
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-4 gap-1.5", children: [
|
|
521
|
-
{ label: "Clear", color: "" },
|
|
522
|
-
{ label: "Zinc", color: "#18181b" },
|
|
523
|
-
{ label: "Emerald", color: "#064e3b" },
|
|
524
|
-
{ label: "Indigo", color: "#312e81" },
|
|
525
|
-
{ label: "Rose", color: "#881337" },
|
|
526
|
-
{ label: "Amber", color: "#78350f" },
|
|
527
|
-
{ label: "Cyan", color: "#164e63" },
|
|
528
|
-
{ label: "Violet", color: "#4c1d95" }
|
|
529
|
-
].map((swatch) => /* @__PURE__ */ jsx(
|
|
530
|
-
"button",
|
|
531
|
-
{
|
|
532
|
-
type: "button",
|
|
533
|
-
title: swatch.label,
|
|
534
|
-
onClick: () => handleCellBackgroundColor(swatch.color),
|
|
535
|
-
className: "w-7 h-7 rounded border border-zinc-200 dark:border-zinc-700 hover:scale-110 transition-transform relative flex items-center justify-center",
|
|
536
|
-
style: { backgroundColor: swatch.color || "transparent" },
|
|
537
|
-
children: !swatch.color && /* @__PURE__ */ jsx("span", { className: "w-3.5 h-[1.5px] bg-red-500 rotate-45 block" })
|
|
538
|
-
},
|
|
539
|
-
swatch.label
|
|
540
|
-
)) })
|
|
541
|
-
]
|
|
542
|
-
}
|
|
543
|
-
)
|
|
544
|
-
] }),
|
|
545
|
-
/* @__PURE__ */ jsx(
|
|
546
|
-
"button",
|
|
547
|
-
{
|
|
548
|
-
type: "button",
|
|
549
|
-
onClick: toggleTableRowIsHeader,
|
|
550
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:text-zinc-950 dark:hover:text-white transition-colors",
|
|
551
|
-
title: "Toggle header row",
|
|
552
|
-
children: /* @__PURE__ */ jsx(TableIcon, { className: "w-4 h-4" })
|
|
553
|
-
}
|
|
554
|
-
),
|
|
555
|
-
/* @__PURE__ */ jsx(
|
|
556
|
-
"button",
|
|
557
|
-
{
|
|
558
|
-
type: "button",
|
|
559
|
-
onClick: deleteTableAtSelection,
|
|
560
|
-
className: "p-1.5 rounded-lg hover:bg-red-50 dark:hover:bg-red-950/50 text-zinc-500 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 transition-colors",
|
|
561
|
-
title: "Delete table",
|
|
562
|
-
children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
|
|
563
|
-
}
|
|
564
|
-
),
|
|
565
|
-
/* @__PURE__ */ jsx("div", { className: "w-[1px] h-4 bg-zinc-200 dark:bg-zinc-700/80 mx-1" }),
|
|
566
|
-
/* @__PURE__ */ jsx(
|
|
567
|
-
"button",
|
|
568
|
-
{
|
|
569
|
-
type: "button",
|
|
570
|
-
onClick: () => insertTableRowAtSelection(false),
|
|
571
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:text-zinc-950 dark:hover:text-white transition-colors",
|
|
572
|
-
title: "Insert row above",
|
|
573
|
-
children: /* @__PURE__ */ jsx(ArrowUp, { className: "w-4 h-4" })
|
|
574
|
-
}
|
|
575
|
-
),
|
|
576
|
-
/* @__PURE__ */ jsx(
|
|
577
|
-
"button",
|
|
578
|
-
{
|
|
579
|
-
type: "button",
|
|
580
|
-
onClick: () => insertTableRowAtSelection(true),
|
|
581
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:text-zinc-950 dark:hover:text-white transition-colors",
|
|
582
|
-
title: "Insert row below",
|
|
583
|
-
children: /* @__PURE__ */ jsx(ArrowDown, { className: "w-4 h-4" })
|
|
584
|
-
}
|
|
585
|
-
),
|
|
586
|
-
/* @__PURE__ */ jsx(
|
|
587
|
-
"button",
|
|
588
|
-
{
|
|
589
|
-
type: "button",
|
|
590
|
-
onClick: deleteTableRowAtSelection,
|
|
591
|
-
className: "p-1.5 rounded-lg hover:bg-red-50 dark:hover:bg-red-950/50 text-zinc-500 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 transition-colors",
|
|
592
|
-
title: "Delete row",
|
|
593
|
-
children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
|
|
594
|
-
}
|
|
595
|
-
),
|
|
596
|
-
/* @__PURE__ */ jsx("div", { className: "w-[1px] h-4 bg-zinc-200 dark:bg-zinc-700/80 mx-1" }),
|
|
597
|
-
/* @__PURE__ */ jsx(
|
|
598
|
-
"button",
|
|
599
|
-
{
|
|
600
|
-
type: "button",
|
|
601
|
-
onClick: () => insertTableColumnAtSelection(false),
|
|
602
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:text-zinc-950 dark:hover:text-white transition-colors",
|
|
603
|
-
title: "Insert column left",
|
|
604
|
-
children: /* @__PURE__ */ jsx(ArrowLeft, { className: "w-4 h-4" })
|
|
605
|
-
}
|
|
606
|
-
),
|
|
607
|
-
/* @__PURE__ */ jsx(
|
|
608
|
-
"button",
|
|
609
|
-
{
|
|
610
|
-
type: "button",
|
|
611
|
-
onClick: () => insertTableColumnAtSelection(true),
|
|
612
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:text-zinc-950 dark:hover:text-white transition-colors",
|
|
613
|
-
title: "Insert column right",
|
|
614
|
-
children: /* @__PURE__ */ jsx(ArrowRight, { className: "w-4 h-4" })
|
|
615
|
-
}
|
|
616
|
-
),
|
|
617
|
-
/* @__PURE__ */ jsx(
|
|
618
|
-
"button",
|
|
619
|
-
{
|
|
620
|
-
type: "button",
|
|
621
|
-
onClick: deleteTableColumnAtSelection,
|
|
622
|
-
className: "p-1.5 rounded-lg hover:bg-red-50 dark:hover:bg-red-950/50 text-zinc-500 dark:text-zinc-400 hover:text-red-600 dark:hover:text-red-400 transition-colors",
|
|
623
|
-
title: "Delete column",
|
|
624
|
-
children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
|
|
625
|
-
}
|
|
626
|
-
),
|
|
627
|
-
canMergeCells && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
628
|
-
/* @__PURE__ */ jsx("div", { className: "w-[1px] h-4 bg-zinc-700/80 mx-1" }),
|
|
629
|
-
/* @__PURE__ */ jsx(
|
|
630
|
-
"button",
|
|
631
|
-
{
|
|
632
|
-
type: "button",
|
|
633
|
-
onClick: mergeTableCellsAtSelection,
|
|
634
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-800 text-zinc-300 hover:text-white transition-colors",
|
|
635
|
-
title: "Merge selected cells",
|
|
636
|
-
children: /* @__PURE__ */ jsx(Merge, { className: "w-4 h-4 text-emerald-400" })
|
|
637
|
-
}
|
|
638
|
-
)
|
|
639
|
-
] }),
|
|
640
|
-
canUnmergeCell && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
641
|
-
/* @__PURE__ */ jsx("div", { className: "w-[1px] h-4 bg-zinc-700/80 mx-1" }),
|
|
642
|
-
/* @__PURE__ */ jsx(
|
|
643
|
-
"button",
|
|
644
|
-
{
|
|
645
|
-
type: "button",
|
|
646
|
-
onClick: unmergeTableCellsAtSelection,
|
|
647
|
-
className: "p-1.5 rounded-lg hover:bg-zinc-800 text-zinc-300 hover:text-white transition-colors",
|
|
648
|
-
title: "Unmerge cells",
|
|
649
|
-
children: /* @__PURE__ */ jsx(Split, { className: "w-4 h-4 text-emerald-400" })
|
|
650
|
-
}
|
|
651
|
-
)
|
|
652
|
-
] })
|
|
653
|
-
] });
|
|
654
|
-
}
|
|
655
|
-
function TableCellActionMenuContainer({
|
|
656
|
-
anchorElem,
|
|
657
|
-
cellMerge
|
|
658
|
-
}) {
|
|
659
|
-
const [editor] = useLexicalComposerContext();
|
|
660
|
-
const menuButtonRef = useRef(null);
|
|
661
|
-
const menuRootRef = useRef(null);
|
|
662
|
-
const [tableCellNode, setTableMenuCellNode] = useState(
|
|
663
|
-
null
|
|
664
|
-
);
|
|
665
|
-
const $moveMenu = useCallback(() => {
|
|
666
|
-
const menu = menuButtonRef.current;
|
|
667
|
-
const selection = $getSelection();
|
|
668
|
-
const nativeSelection = getDOMSelection(editor._window);
|
|
669
|
-
let activeElement;
|
|
670
|
-
if (typeof window !== "undefined") {
|
|
671
|
-
activeElement = document == null ? void 0 : document.activeElement;
|
|
672
|
-
}
|
|
673
|
-
function disable() {
|
|
674
|
-
if (menu) {
|
|
675
|
-
menu.style.display = "none";
|
|
676
|
-
menu.style.opacity = "0";
|
|
677
|
-
}
|
|
678
|
-
setTableMenuCellNode(null);
|
|
679
|
-
}
|
|
680
|
-
if (selection == null || menu == null) {
|
|
681
|
-
return disable();
|
|
682
|
-
}
|
|
683
|
-
const rootElement = editor.getRootElement();
|
|
684
|
-
let tableObserver = null;
|
|
685
|
-
let tableCellParentNodeDOM = null;
|
|
686
|
-
let activeTableCellNode = null;
|
|
687
|
-
if ($isRangeSelection(selection) && rootElement !== null && nativeSelection !== null && rootElement.contains(nativeSelection.anchorNode)) {
|
|
688
|
-
const tableCellNodeFromSelection = $getTableCellNodeFromLexicalNode(
|
|
689
|
-
selection.anchor.getNode()
|
|
690
|
-
);
|
|
691
|
-
if (tableCellNodeFromSelection == null) {
|
|
692
|
-
return disable();
|
|
693
|
-
}
|
|
694
|
-
tableCellParentNodeDOM = editor.getElementByKey(
|
|
695
|
-
tableCellNodeFromSelection.getKey()
|
|
696
|
-
);
|
|
697
|
-
if (tableCellParentNodeDOM == null || !tableCellNodeFromSelection.isAttached()) {
|
|
698
|
-
return disable();
|
|
699
|
-
}
|
|
700
|
-
try {
|
|
701
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(
|
|
702
|
-
tableCellNodeFromSelection
|
|
703
|
-
);
|
|
704
|
-
const tableElement = getTableElement(
|
|
705
|
-
tableNode,
|
|
706
|
-
editor.getElementByKey(tableNode.getKey())
|
|
707
|
-
);
|
|
708
|
-
if (tableElement === null) {
|
|
709
|
-
return disable();
|
|
710
|
-
}
|
|
711
|
-
tableObserver = getTableObserverFromTableElement(tableElement);
|
|
712
|
-
activeTableCellNode = tableCellNodeFromSelection;
|
|
713
|
-
setTableMenuCellNode(tableCellNodeFromSelection);
|
|
714
|
-
} catch (e) {
|
|
715
|
-
return disable();
|
|
716
|
-
}
|
|
717
|
-
} else if ($isTableSelection(selection)) {
|
|
718
|
-
try {
|
|
719
|
-
const anchorNode = $getTableCellNodeFromLexicalNode(
|
|
720
|
-
selection.anchor.getNode()
|
|
721
|
-
);
|
|
722
|
-
if (!$isTableCellNode(anchorNode)) {
|
|
723
|
-
return disable();
|
|
724
|
-
}
|
|
725
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(anchorNode);
|
|
726
|
-
const tableElement = getTableElement(
|
|
727
|
-
tableNode,
|
|
728
|
-
editor.getElementByKey(tableNode.getKey())
|
|
729
|
-
);
|
|
730
|
-
if (tableElement === null) {
|
|
731
|
-
return disable();
|
|
732
|
-
}
|
|
733
|
-
tableObserver = getTableObserverFromTableElement(tableElement);
|
|
734
|
-
tableCellParentNodeDOM = editor.getElementByKey(anchorNode.getKey());
|
|
735
|
-
activeTableCellNode = anchorNode;
|
|
736
|
-
setTableMenuCellNode(anchorNode);
|
|
737
|
-
} catch (e) {
|
|
738
|
-
return disable();
|
|
739
|
-
}
|
|
740
|
-
} else if (!activeElement) {
|
|
741
|
-
return disable();
|
|
742
|
-
}
|
|
743
|
-
if (tableObserver === null || tableCellParentNodeDOM === null || activeTableCellNode === null) {
|
|
744
|
-
return disable();
|
|
745
|
-
}
|
|
746
|
-
const enabled = !tableObserver || !tableObserver.isSelecting;
|
|
747
|
-
if (enabled) {
|
|
748
|
-
menu.style.display = "block";
|
|
749
|
-
menu.style.opacity = "1";
|
|
750
|
-
const tableCellRect = tableCellParentNodeDOM.getBoundingClientRect();
|
|
751
|
-
const anchorRect = anchorElem.getBoundingClientRect();
|
|
752
|
-
let targetRect = tableCellRect;
|
|
753
|
-
try {
|
|
754
|
-
const tableNode = $getTableNodeFromLexicalNodeOrThrow(activeTableCellNode);
|
|
755
|
-
const tableDOM = getTableElement(tableNode, editor.getElementByKey(tableNode.getKey()));
|
|
756
|
-
if (tableDOM) {
|
|
757
|
-
targetRect = tableDOM.getBoundingClientRect();
|
|
758
|
-
}
|
|
759
|
-
} catch (e) {
|
|
760
|
-
}
|
|
761
|
-
const top = Math.max(8, targetRect.top - anchorRect.top - 46);
|
|
762
|
-
const left = Math.max(16, targetRect.left - anchorRect.left + targetRect.width / 2 - 160);
|
|
763
|
-
menu.style.transform = `translate(${left}px, ${top}px)`;
|
|
764
|
-
} else {
|
|
765
|
-
menu.style.display = "none";
|
|
766
|
-
menu.style.opacity = "0";
|
|
767
|
-
}
|
|
768
|
-
}, [editor, anchorElem]);
|
|
769
|
-
useEffect(() => {
|
|
770
|
-
let timeoutId = void 0;
|
|
771
|
-
const callback = () => {
|
|
772
|
-
timeoutId = void 0;
|
|
773
|
-
editor.getEditorState().read($moveMenu);
|
|
774
|
-
};
|
|
775
|
-
const delayedCallback = () => {
|
|
776
|
-
if (timeoutId === void 0) {
|
|
777
|
-
timeoutId = setTimeout(callback, 0);
|
|
778
|
-
}
|
|
779
|
-
return false;
|
|
780
|
-
};
|
|
781
|
-
return mergeRegister(
|
|
782
|
-
editor.registerUpdateListener(delayedCallback),
|
|
783
|
-
editor.registerCommand(
|
|
784
|
-
SELECTION_CHANGE_COMMAND,
|
|
785
|
-
delayedCallback,
|
|
786
|
-
COMMAND_PRIORITY_CRITICAL
|
|
787
|
-
),
|
|
788
|
-
editor.registerRootListener((rootElement, prevRootElement) => {
|
|
789
|
-
if (prevRootElement) {
|
|
790
|
-
prevRootElement.removeEventListener("mouseup", delayedCallback);
|
|
791
|
-
}
|
|
792
|
-
if (rootElement) {
|
|
793
|
-
rootElement.addEventListener("mouseup", delayedCallback);
|
|
794
|
-
delayedCallback();
|
|
795
|
-
}
|
|
796
|
-
}),
|
|
797
|
-
() => clearTimeout(timeoutId)
|
|
798
|
-
);
|
|
799
|
-
});
|
|
800
|
-
const prevTableCellDOM = useRef(tableCellNode);
|
|
801
|
-
useEffect(() => {
|
|
802
|
-
prevTableCellDOM.current = tableCellNode;
|
|
803
|
-
}, [prevTableCellDOM, tableCellNode]);
|
|
804
|
-
return /* @__PURE__ */ jsx(
|
|
805
|
-
"div",
|
|
806
|
-
{
|
|
807
|
-
className: "absolute top-1 left-1 will-change-transform z-40 transition-opacity duration-150",
|
|
808
|
-
ref: menuButtonRef,
|
|
809
|
-
children: tableCellNode != null && /* @__PURE__ */ jsx(
|
|
810
|
-
TableActionMenu,
|
|
811
|
-
{
|
|
812
|
-
contextRef: menuRootRef,
|
|
813
|
-
tableCellNode,
|
|
814
|
-
cellMerge
|
|
815
|
-
}
|
|
816
|
-
)
|
|
817
|
-
}
|
|
818
|
-
);
|
|
819
|
-
}
|
|
820
|
-
function TableActionMenuPlugin({
|
|
821
|
-
anchorElem = document.body,
|
|
822
|
-
cellMerge = false
|
|
823
|
-
}) {
|
|
824
|
-
const isEditable = useLexicalEditable();
|
|
825
|
-
return createPortal(
|
|
826
|
-
isEditable ? /* @__PURE__ */ jsx(
|
|
827
|
-
TableCellActionMenuContainer,
|
|
828
|
-
{
|
|
829
|
-
anchorElem,
|
|
830
|
-
cellMerge
|
|
831
|
-
}
|
|
832
|
-
) : null,
|
|
833
|
-
anchorElem
|
|
834
|
-
);
|
|
835
|
-
}
|
|
836
|
-
export {
|
|
837
|
-
TableActionMenuPlugin as default
|
|
838
|
-
};
|