@payloadcms/richtext-lexical 3.0.0-beta.57 → 3.0.0-beta.59

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.
Files changed (78) hide show
  1. package/dist/cell/index.d.ts.map +1 -1
  2. package/dist/cell/index.js +2 -2
  3. package/dist/cell/index.js.map +1 -1
  4. package/dist/exports/client/Field-5TCNFYE2.js +2 -0
  5. package/dist/exports/client/Field-5TCNFYE2.js.map +7 -0
  6. package/dist/exports/client/bundled.css +1 -1
  7. package/dist/exports/client/chunk-CUMDYP5E.js +2 -0
  8. package/dist/exports/client/chunk-CUMDYP5E.js.map +7 -0
  9. package/dist/exports/client/component-7J2IXLN3.js +2 -0
  10. package/dist/exports/client/component-7J2IXLN3.js.map +7 -0
  11. package/dist/exports/client/{component-V5QZ7EVZ.js → component-RV346GAA.js} +2 -2
  12. package/dist/exports/client/index.d.ts +1 -0
  13. package/dist/exports/client/index.d.ts.map +1 -1
  14. package/dist/exports/client/index.js +7 -7
  15. package/dist/exports/client/index.js.map +4 -4
  16. package/dist/features/blocks/component/index.js +3 -3
  17. package/dist/features/blocks/component/index.js.map +1 -1
  18. package/dist/features/createFeaturePropComponent.js +1 -1
  19. package/dist/features/createFeaturePropComponent.js.map +1 -1
  20. package/dist/features/experimental_table/feature.client.d.ts +2 -0
  21. package/dist/features/experimental_table/feature.client.d.ts.map +1 -0
  22. package/dist/features/experimental_table/feature.client.js +66 -0
  23. package/dist/features/experimental_table/feature.client.js.map +1 -0
  24. package/dist/features/experimental_table/feature.server.d.ts +2 -0
  25. package/dist/features/experimental_table/feature.server.d.ts.map +1 -0
  26. package/dist/features/experimental_table/feature.server.js +52 -0
  27. package/dist/features/experimental_table/feature.server.js.map +1 -0
  28. package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.d.ts +4 -0
  29. package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.d.ts.map +1 -0
  30. package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.js +602 -0
  31. package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.js.map +1 -0
  32. package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.d.ts +4 -0
  33. package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.d.ts.map +1 -0
  34. package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.js +322 -0
  35. package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.js.map +1 -0
  36. package/dist/features/experimental_table/plugins/TablePlugin/index.d.ts +24 -0
  37. package/dist/features/experimental_table/plugins/TablePlugin/index.d.ts.map +1 -0
  38. package/dist/features/experimental_table/plugins/TablePlugin/index.js +99 -0
  39. package/dist/features/experimental_table/plugins/TablePlugin/index.js.map +1 -0
  40. package/dist/features/typesClient.d.ts +5 -1
  41. package/dist/features/typesClient.d.ts.map +1 -1
  42. package/dist/features/typesClient.js.map +1 -1
  43. package/dist/field/index.d.ts.map +1 -1
  44. package/dist/field/index.js +8 -8
  45. package/dist/field/index.js.map +1 -1
  46. package/dist/index.d.ts +1 -0
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +1 -0
  49. package/dist/index.js.map +1 -1
  50. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  51. package/dist/lexical/LexicalProvider.js +24 -4
  52. package/dist/lexical/LexicalProvider.js.map +1 -1
  53. package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
  54. package/dist/lexical/config/client/sanitize.js +4 -0
  55. package/dist/lexical/config/client/sanitize.js.map +1 -1
  56. package/dist/lexical/ui/icons/Meatballs/index.d.ts +3 -0
  57. package/dist/lexical/ui/icons/Meatballs/index.d.ts.map +1 -0
  58. package/dist/lexical/ui/icons/Meatballs/index.js +25 -0
  59. package/dist/lexical/ui/icons/Meatballs/index.js.map +1 -0
  60. package/dist/lexical/ui/icons/Table/index.d.ts +3 -0
  61. package/dist/lexical/ui/icons/Table/index.d.ts.map +1 -0
  62. package/dist/lexical/ui/icons/Table/index.js +19 -0
  63. package/dist/lexical/ui/icons/Table/index.js.map +1 -0
  64. package/dist/utilities/fieldsDrawer/DrawerContent.js +2 -2
  65. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
  66. package/dist/utilities/generateComponentMap.d.ts.map +1 -1
  67. package/dist/utilities/generateComponentMap.js +3 -3
  68. package/dist/utilities/generateComponentMap.js.map +1 -1
  69. package/dist/utilities/generateSchemaMap.js +1 -1
  70. package/dist/utilities/generateSchemaMap.js.map +1 -1
  71. package/package.json +12 -11
  72. package/dist/exports/client/Field-XBUN6QOM.js +0 -2
  73. package/dist/exports/client/Field-XBUN6QOM.js.map +0 -7
  74. package/dist/exports/client/chunk-OAQL5GDK.js +0 -2
  75. package/dist/exports/client/chunk-OAQL5GDK.js.map +0 -7
  76. package/dist/exports/client/component-YNZTTMBY.js +0 -2
  77. package/dist/exports/client/component-YNZTTMBY.js.map +0 -7
  78. /package/dist/exports/client/{component-V5QZ7EVZ.js.map → component-RV346GAA.js.map} +0 -0
@@ -0,0 +1,602 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
+ import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
5
+ import { $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $insertTableColumn__EXPERIMENTAL, $insertTableRow__EXPERIMENTAL, $isTableCellNode, $isTableRowNode, $isTableSelection, $unmergeCell, TableCellHeaderStates, TableCellNode, getTableObserverFromTableElement } from '@lexical/table';
6
+ import { useScrollInfo } from '@payloadcms/ui';
7
+ import { $createParagraphNode, $getRoot, $getSelection, $isElementNode, $isParagraphNode, $isRangeSelection, $isTextNode } from 'lexical';
8
+ import * as React from 'react';
9
+ import { useCallback, useEffect, useRef, useState } from 'react';
10
+ import { createPortal } from 'react-dom';
11
+ import { MeatballsIcon } from '../../../../lexical/ui/icons/Meatballs/index.js';
12
+ import { invariant } from '../../../../lexical/utils/invariant.js';
13
+ function computeSelectionCount(selection) {
14
+ const selectionShape = selection.getShape();
15
+ return {
16
+ columns: selectionShape.toX - selectionShape.fromX + 1,
17
+ rows: selectionShape.toY - selectionShape.fromY + 1
18
+ };
19
+ }
20
+ // This is important when merging cells as there is no good way to re-merge weird shapes (a result
21
+ // of selecting merged cells and non-merged)
22
+ function isTableSelectionRectangular(selection) {
23
+ const nodes = selection.getNodes();
24
+ const currentRows = [];
25
+ let currentRow = null;
26
+ let expectedColumns = null;
27
+ let currentColumns = 0;
28
+ for(let i = 0; i < nodes.length; i++){
29
+ const node = nodes[i];
30
+ if ($isTableCellNode(node)) {
31
+ const row = node.getParentOrThrow();
32
+ invariant($isTableRowNode(row), 'Expected CellNode to have a RowNode parent');
33
+ if (currentRow !== row) {
34
+ if (expectedColumns !== null && currentColumns !== expectedColumns) {
35
+ return false;
36
+ }
37
+ if (currentRow !== null) {
38
+ expectedColumns = currentColumns;
39
+ }
40
+ currentRow = row;
41
+ currentColumns = 0;
42
+ }
43
+ const colSpan = node.__colSpan;
44
+ for(let j = 0; j < colSpan; j++){
45
+ if (currentRows[currentColumns + j] === undefined) {
46
+ currentRows[currentColumns + j] = 0;
47
+ }
48
+ currentRows[currentColumns + j] += node.__rowSpan;
49
+ }
50
+ currentColumns += colSpan;
51
+ }
52
+ }
53
+ return (expectedColumns === null || currentColumns === expectedColumns) && currentRows.every((v)=>v === currentRows[0]);
54
+ }
55
+ function $canUnmerge() {
56
+ const selection = $getSelection();
57
+ if ($isRangeSelection(selection) && !selection.isCollapsed() || $isTableSelection(selection) && !selection.anchor.is(selection.focus) || !$isRangeSelection(selection) && !$isTableSelection(selection)) {
58
+ return false;
59
+ }
60
+ const [cell] = $getNodeTriplet(selection.anchor);
61
+ return cell.__colSpan > 1 || cell.__rowSpan > 1;
62
+ }
63
+ function $cellContainsEmptyParagraph(cell) {
64
+ if (cell.getChildrenSize() !== 1) {
65
+ return false;
66
+ }
67
+ const firstChild = cell.getFirstChildOrThrow();
68
+ if (!$isParagraphNode(firstChild) || !firstChild.isEmpty()) {
69
+ return false;
70
+ }
71
+ return true;
72
+ }
73
+ function $selectLastDescendant(node) {
74
+ const lastDescendant = node.getLastDescendant();
75
+ if ($isTextNode(lastDescendant)) {
76
+ lastDescendant.select();
77
+ } else if ($isElementNode(lastDescendant)) {
78
+ lastDescendant.selectEnd();
79
+ } else if (lastDescendant !== null) {
80
+ lastDescendant.selectNext();
81
+ }
82
+ }
83
+ function TableActionMenu({ cellMerge, contextRef, onClose, setIsMenuOpen, tableCellNode: _tableCellNode }) {
84
+ const [editor] = useLexicalComposerContext();
85
+ const dropDownRef = useRef(null);
86
+ const [tableCellNode, updateTableCellNode] = useState(_tableCellNode);
87
+ const [selectionCounts, updateSelectionCounts] = useState({
88
+ columns: 1,
89
+ rows: 1
90
+ });
91
+ const [canMergeCells, setCanMergeCells] = useState(false);
92
+ const [canUnmergeCell, setCanUnmergeCell] = useState(false);
93
+ const { y } = useScrollInfo();
94
+ useEffect(()=>{
95
+ return editor.registerMutationListener(TableCellNode, (nodeMutations)=>{
96
+ const nodeUpdated = nodeMutations.get(tableCellNode.getKey()) === 'updated';
97
+ if (nodeUpdated) {
98
+ editor.getEditorState().read(()=>{
99
+ updateTableCellNode(tableCellNode.getLatest());
100
+ });
101
+ }
102
+ });
103
+ }, [
104
+ editor,
105
+ tableCellNode
106
+ ]);
107
+ useEffect(()=>{
108
+ editor.getEditorState().read(()=>{
109
+ const selection = $getSelection();
110
+ // Merge cells
111
+ if ($isTableSelection(selection)) {
112
+ const currentSelectionCounts = computeSelectionCount(selection);
113
+ updateSelectionCounts(computeSelectionCount(selection));
114
+ setCanMergeCells(isTableSelectionRectangular(selection) && (currentSelectionCounts.columns > 1 || currentSelectionCounts.rows > 1));
115
+ }
116
+ // Unmerge cell
117
+ setCanUnmergeCell($canUnmerge());
118
+ });
119
+ }, [
120
+ editor
121
+ ]);
122
+ useEffect(()=>{
123
+ const menuButtonElement = contextRef.current;
124
+ const dropDownElement = dropDownRef.current;
125
+ const rootElement = editor.getRootElement();
126
+ if (menuButtonElement != null && dropDownElement != null && rootElement != null) {
127
+ const rootEleRect = rootElement.getBoundingClientRect();
128
+ const menuButtonRect = menuButtonElement.getBoundingClientRect();
129
+ dropDownElement.style.opacity = '1';
130
+ const dropDownElementRect = dropDownElement.getBoundingClientRect();
131
+ const margin = 5;
132
+ let leftPosition = menuButtonRect.right + margin;
133
+ if (leftPosition + dropDownElementRect.width > window.innerWidth || leftPosition + dropDownElementRect.width > rootEleRect.right) {
134
+ const position = menuButtonRect.left - dropDownElementRect.width - margin;
135
+ leftPosition = (position < 0 ? margin : position) + window.pageXOffset;
136
+ }
137
+ dropDownElement.style.left = `${leftPosition + window.pageXOffset}px`;
138
+ let topPosition = menuButtonRect.top;
139
+ if (topPosition + dropDownElementRect.height > window.innerHeight) {
140
+ const position = menuButtonRect.bottom - dropDownElementRect.height;
141
+ topPosition = (position < 0 ? margin : position) + window.pageYOffset;
142
+ }
143
+ dropDownElement.style.top = `${topPosition}px`;
144
+ }
145
+ }, [
146
+ contextRef,
147
+ dropDownRef,
148
+ editor,
149
+ y
150
+ ]);
151
+ useEffect(()=>{
152
+ function handleClickOutside(event) {
153
+ if (dropDownRef.current != null && contextRef.current != null && !dropDownRef.current.contains(event.target) && !contextRef.current.contains(event.target)) {
154
+ setIsMenuOpen(false);
155
+ }
156
+ }
157
+ window.addEventListener('click', handleClickOutside);
158
+ return ()=>window.removeEventListener('click', handleClickOutside);
159
+ }, [
160
+ setIsMenuOpen,
161
+ contextRef
162
+ ]);
163
+ const clearTableSelection = useCallback(()=>{
164
+ editor.update(()=>{
165
+ if (tableCellNode.isAttached()) {
166
+ const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
167
+ const tableElement = editor.getElementByKey(tableNode.getKey());
168
+ if (!tableElement) {
169
+ throw new Error('Expected to find tableElement in DOM');
170
+ }
171
+ const tableSelection = getTableObserverFromTableElement(tableElement);
172
+ if (tableSelection !== null) {
173
+ tableSelection.clearHighlight();
174
+ }
175
+ tableNode.markDirty();
176
+ updateTableCellNode(tableCellNode.getLatest());
177
+ }
178
+ const rootNode = $getRoot();
179
+ rootNode.selectStart();
180
+ });
181
+ }, [
182
+ editor,
183
+ tableCellNode
184
+ ]);
185
+ const mergeTableCellsAtSelection = ()=>{
186
+ editor.update(()=>{
187
+ const selection = $getSelection();
188
+ if ($isTableSelection(selection)) {
189
+ const { columns, rows } = computeSelectionCount(selection);
190
+ const nodes = selection.getNodes();
191
+ let firstCell = null;
192
+ for(let i = 0; i < nodes.length; i++){
193
+ const node = nodes[i];
194
+ if ($isTableCellNode(node)) {
195
+ if (firstCell === null) {
196
+ node.setColSpan(columns).setRowSpan(rows);
197
+ firstCell = node;
198
+ const isEmpty = $cellContainsEmptyParagraph(node);
199
+ let firstChild;
200
+ if (isEmpty && $isParagraphNode(firstChild = node.getFirstChild())) {
201
+ firstChild.remove();
202
+ }
203
+ } else if ($isTableCellNode(firstCell)) {
204
+ const isEmpty = $cellContainsEmptyParagraph(node);
205
+ if (!isEmpty) {
206
+ firstCell.append(...node.getChildren());
207
+ }
208
+ node.remove();
209
+ }
210
+ }
211
+ }
212
+ if (firstCell !== null) {
213
+ if (firstCell.getChildrenSize() === 0) {
214
+ firstCell.append($createParagraphNode());
215
+ }
216
+ $selectLastDescendant(firstCell);
217
+ }
218
+ onClose();
219
+ }
220
+ });
221
+ };
222
+ const unmergeTableCellsAtSelection = ()=>{
223
+ editor.update(()=>{
224
+ $unmergeCell();
225
+ });
226
+ };
227
+ const insertTableRowAtSelection = useCallback((shouldInsertAfter)=>{
228
+ editor.update(()=>{
229
+ $insertTableRow__EXPERIMENTAL(shouldInsertAfter);
230
+ onClose();
231
+ });
232
+ }, [
233
+ editor,
234
+ onClose
235
+ ]);
236
+ const insertTableColumnAtSelection = useCallback((shouldInsertAfter)=>{
237
+ editor.update(()=>{
238
+ for(let i = 0; i < selectionCounts.columns; i++){
239
+ $insertTableColumn__EXPERIMENTAL(shouldInsertAfter);
240
+ }
241
+ onClose();
242
+ });
243
+ }, [
244
+ editor,
245
+ onClose,
246
+ selectionCounts.columns
247
+ ]);
248
+ const deleteTableRowAtSelection = useCallback(()=>{
249
+ editor.update(()=>{
250
+ $deleteTableRow__EXPERIMENTAL();
251
+ onClose();
252
+ });
253
+ }, [
254
+ editor,
255
+ onClose
256
+ ]);
257
+ const deleteTableAtSelection = useCallback(()=>{
258
+ editor.update(()=>{
259
+ const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
260
+ tableNode.remove();
261
+ clearTableSelection();
262
+ onClose();
263
+ });
264
+ }, [
265
+ editor,
266
+ tableCellNode,
267
+ clearTableSelection,
268
+ onClose
269
+ ]);
270
+ const deleteTableColumnAtSelection = useCallback(()=>{
271
+ editor.update(()=>{
272
+ $deleteTableColumn__EXPERIMENTAL();
273
+ onClose();
274
+ });
275
+ }, [
276
+ editor,
277
+ onClose
278
+ ]);
279
+ const toggleTableRowIsHeader = useCallback(()=>{
280
+ editor.update(()=>{
281
+ const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
282
+ const tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
283
+ const tableRows = tableNode.getChildren();
284
+ if (tableRowIndex >= tableRows.length || tableRowIndex < 0) {
285
+ throw new Error('Expected table cell to be inside of table row.');
286
+ }
287
+ const tableRow = tableRows[tableRowIndex];
288
+ if (!$isTableRowNode(tableRow)) {
289
+ throw new Error('Expected table row');
290
+ }
291
+ tableRow.getChildren().forEach((tableCell)=>{
292
+ if (!$isTableCellNode(tableCell)) {
293
+ throw new Error('Expected table cell');
294
+ }
295
+ tableCell.toggleHeaderStyle(TableCellHeaderStates.ROW);
296
+ });
297
+ clearTableSelection();
298
+ onClose();
299
+ });
300
+ }, [
301
+ editor,
302
+ tableCellNode,
303
+ clearTableSelection,
304
+ onClose
305
+ ]);
306
+ const toggleTableColumnIsHeader = useCallback(()=>{
307
+ editor.update(()=>{
308
+ const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
309
+ const tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode);
310
+ const tableRows = tableNode.getChildren();
311
+ const maxRowsLength = Math.max(...tableRows.map((row)=>row.getChildren().length));
312
+ if (tableColumnIndex >= maxRowsLength || tableColumnIndex < 0) {
313
+ throw new Error('Expected table cell to be inside of table row.');
314
+ }
315
+ for(let r = 0; r < tableRows.length; r++){
316
+ const tableRow = tableRows[r];
317
+ if (!$isTableRowNode(tableRow)) {
318
+ throw new Error('Expected table row');
319
+ }
320
+ const tableCells = tableRow.getChildren();
321
+ if (tableColumnIndex >= tableCells.length) {
322
+ continue;
323
+ }
324
+ const tableCell = tableCells[tableColumnIndex];
325
+ if (!$isTableCellNode(tableCell)) {
326
+ throw new Error('Expected table cell');
327
+ }
328
+ tableCell.toggleHeaderStyle(TableCellHeaderStates.COLUMN);
329
+ }
330
+ clearTableSelection();
331
+ onClose();
332
+ });
333
+ }, [
334
+ editor,
335
+ tableCellNode,
336
+ clearTableSelection,
337
+ onClose
338
+ ]);
339
+ let mergeCellButton = null;
340
+ if (cellMerge) {
341
+ if (canMergeCells) {
342
+ mergeCellButton = /*#__PURE__*/ _jsx("button", {
343
+ className: "item",
344
+ "data-test-id": "table-merge-cells",
345
+ onClick: ()=>mergeTableCellsAtSelection(),
346
+ type: "button",
347
+ children: "Merge cells"
348
+ });
349
+ } else if (canUnmergeCell) {
350
+ mergeCellButton = /*#__PURE__*/ _jsx("button", {
351
+ className: "item",
352
+ "data-test-id": "table-unmerge-cells",
353
+ onClick: ()=>unmergeTableCellsAtSelection(),
354
+ type: "button",
355
+ children: "Unmerge cells"
356
+ });
357
+ }
358
+ }
359
+ return /*#__PURE__*/ createPortal(// eslint-disable-next-line jsx-a11y/no-static-element-interactions,jsx-a11y/click-events-have-key-events
360
+ /*#__PURE__*/ _jsxs("div", {
361
+ className: "table-action-menu-dropdown",
362
+ onClick: (e)=>{
363
+ e.stopPropagation();
364
+ },
365
+ ref: dropDownRef,
366
+ children: [
367
+ mergeCellButton ? /*#__PURE__*/ _jsxs(React.Fragment, {
368
+ children: [
369
+ mergeCellButton,
370
+ /*#__PURE__*/ _jsx("hr", {})
371
+ ]
372
+ }) : null,
373
+ /*#__PURE__*/ _jsx("button", {
374
+ className: "item",
375
+ "data-test-id": "table-insert-row-above",
376
+ onClick: ()=>insertTableRowAtSelection(false),
377
+ type: "button",
378
+ children: /*#__PURE__*/ _jsxs("span", {
379
+ className: "text",
380
+ children: [
381
+ "Insert ",
382
+ selectionCounts.rows === 1 ? 'row' : `${selectionCounts.rows} rows`,
383
+ " above"
384
+ ]
385
+ })
386
+ }),
387
+ /*#__PURE__*/ _jsx("button", {
388
+ className: "item",
389
+ "data-test-id": "table-insert-row-below",
390
+ onClick: ()=>insertTableRowAtSelection(true),
391
+ type: "button",
392
+ children: /*#__PURE__*/ _jsxs("span", {
393
+ className: "text",
394
+ children: [
395
+ "Insert ",
396
+ selectionCounts.rows === 1 ? 'row' : `${selectionCounts.rows} rows`,
397
+ " below"
398
+ ]
399
+ })
400
+ }),
401
+ /*#__PURE__*/ _jsx("hr", {}),
402
+ /*#__PURE__*/ _jsx("button", {
403
+ className: "item",
404
+ "data-test-id": "table-insert-column-before",
405
+ onClick: ()=>insertTableColumnAtSelection(false),
406
+ type: "button",
407
+ children: /*#__PURE__*/ _jsxs("span", {
408
+ className: "text",
409
+ children: [
410
+ "Insert ",
411
+ selectionCounts.columns === 1 ? 'column' : `${selectionCounts.columns} columns`,
412
+ ' ',
413
+ "left"
414
+ ]
415
+ })
416
+ }),
417
+ /*#__PURE__*/ _jsx("button", {
418
+ className: "item",
419
+ "data-test-id": "table-insert-column-after",
420
+ onClick: ()=>insertTableColumnAtSelection(true),
421
+ type: "button",
422
+ children: /*#__PURE__*/ _jsxs("span", {
423
+ className: "text",
424
+ children: [
425
+ "Insert ",
426
+ selectionCounts.columns === 1 ? 'column' : `${selectionCounts.columns} columns`,
427
+ ' ',
428
+ "right"
429
+ ]
430
+ })
431
+ }),
432
+ /*#__PURE__*/ _jsx("hr", {}),
433
+ /*#__PURE__*/ _jsx("button", {
434
+ className: "item",
435
+ "data-test-id": "table-delete-columns",
436
+ onClick: ()=>deleteTableColumnAtSelection(),
437
+ type: "button",
438
+ children: /*#__PURE__*/ _jsx("span", {
439
+ className: "text",
440
+ children: "Delete column"
441
+ })
442
+ }),
443
+ /*#__PURE__*/ _jsx("button", {
444
+ className: "item",
445
+ "data-test-id": "table-delete-rows",
446
+ onClick: ()=>deleteTableRowAtSelection(),
447
+ type: "button",
448
+ children: /*#__PURE__*/ _jsx("span", {
449
+ className: "text",
450
+ children: "Delete row"
451
+ })
452
+ }),
453
+ /*#__PURE__*/ _jsx("button", {
454
+ className: "item",
455
+ "data-test-id": "table-delete",
456
+ onClick: ()=>deleteTableAtSelection(),
457
+ type: "button",
458
+ children: /*#__PURE__*/ _jsx("span", {
459
+ className: "text",
460
+ children: "Delete table"
461
+ })
462
+ }),
463
+ /*#__PURE__*/ _jsx("hr", {}),
464
+ /*#__PURE__*/ _jsx("button", {
465
+ className: "item",
466
+ onClick: ()=>toggleTableRowIsHeader(),
467
+ type: "button",
468
+ children: /*#__PURE__*/ _jsxs("span", {
469
+ className: "text",
470
+ children: [
471
+ (tableCellNode.__headerState & TableCellHeaderStates.ROW) === TableCellHeaderStates.ROW ? 'Remove' : 'Add',
472
+ ' ',
473
+ "row header"
474
+ ]
475
+ })
476
+ }),
477
+ /*#__PURE__*/ _jsx("button", {
478
+ className: "item",
479
+ "data-test-id": "table-column-header",
480
+ onClick: ()=>toggleTableColumnIsHeader(),
481
+ type: "button",
482
+ children: /*#__PURE__*/ _jsxs("span", {
483
+ className: "text",
484
+ children: [
485
+ (tableCellNode.__headerState & TableCellHeaderStates.COLUMN) === TableCellHeaderStates.COLUMN ? 'Remove' : 'Add',
486
+ ' ',
487
+ "column header"
488
+ ]
489
+ })
490
+ })
491
+ ]
492
+ }), document.body);
493
+ }
494
+ function TableCellActionMenuContainer({ anchorElem, cellMerge }) {
495
+ const [editor] = useLexicalComposerContext();
496
+ const menuButtonRef = useRef(null);
497
+ const menuRootRef = useRef(null);
498
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
499
+ const [tableCellNode, setTableMenuCellNode] = useState(null);
500
+ const $moveMenu = useCallback(()=>{
501
+ const menu = menuButtonRef.current;
502
+ const selection = $getSelection();
503
+ const nativeSelection = window.getSelection();
504
+ const activeElement = document.activeElement;
505
+ if (selection == null || menu == null) {
506
+ setTableMenuCellNode(null);
507
+ return;
508
+ }
509
+ const rootElement = editor.getRootElement();
510
+ if ($isRangeSelection(selection) && rootElement !== null && nativeSelection !== null && rootElement.contains(nativeSelection.anchorNode)) {
511
+ const tableCellNodeFromSelection = $getTableCellNodeFromLexicalNode(selection.anchor.getNode());
512
+ if (tableCellNodeFromSelection == null) {
513
+ setTableMenuCellNode(null);
514
+ return;
515
+ }
516
+ const tableCellParentNodeDOM = editor.getElementByKey(tableCellNodeFromSelection.getKey());
517
+ if (tableCellParentNodeDOM == null) {
518
+ setTableMenuCellNode(null);
519
+ return;
520
+ }
521
+ setTableMenuCellNode(tableCellNodeFromSelection);
522
+ } else if (!activeElement) {
523
+ setTableMenuCellNode(null);
524
+ }
525
+ }, [
526
+ editor
527
+ ]);
528
+ useEffect(()=>{
529
+ return editor.registerUpdateListener(()=>{
530
+ editor.getEditorState().read(()=>{
531
+ $moveMenu();
532
+ });
533
+ });
534
+ });
535
+ useEffect(()=>{
536
+ const menuButtonDOM = menuButtonRef.current;
537
+ if (menuButtonDOM != null && tableCellNode != null) {
538
+ const tableCellNodeDOM = editor.getElementByKey(tableCellNode.getKey());
539
+ if (tableCellNodeDOM != null) {
540
+ const tableCellRect = tableCellNodeDOM.getBoundingClientRect();
541
+ const menuRect = menuButtonDOM.getBoundingClientRect();
542
+ const anchorRect = anchorElem.getBoundingClientRect();
543
+ const top = tableCellRect.top - anchorRect.top + 4;
544
+ const left = tableCellRect.right - menuRect.width - 10 - anchorRect.left;
545
+ menuButtonDOM.style.opacity = '1';
546
+ menuButtonDOM.style.transform = `translate(${left}px, ${top}px)`;
547
+ } else {
548
+ menuButtonDOM.style.opacity = '0';
549
+ menuButtonDOM.style.transform = 'translate(-10000px, -10000px)';
550
+ }
551
+ }
552
+ }, [
553
+ menuButtonRef,
554
+ tableCellNode,
555
+ editor,
556
+ anchorElem
557
+ ]);
558
+ const prevTableCellDOM = useRef(tableCellNode);
559
+ useEffect(()=>{
560
+ if (prevTableCellDOM.current !== tableCellNode) {
561
+ setIsMenuOpen(false);
562
+ }
563
+ prevTableCellDOM.current = tableCellNode;
564
+ }, [
565
+ prevTableCellDOM,
566
+ tableCellNode
567
+ ]);
568
+ return /*#__PURE__*/ _jsx("div", {
569
+ className: "table-cell-action-button-container",
570
+ ref: menuButtonRef,
571
+ children: tableCellNode != null && /*#__PURE__*/ _jsxs(React.Fragment, {
572
+ children: [
573
+ /*#__PURE__*/ _jsx("button", {
574
+ className: "table-cell-action-button",
575
+ onClick: (e)=>{
576
+ e.stopPropagation();
577
+ setIsMenuOpen(!isMenuOpen);
578
+ },
579
+ ref: menuRootRef,
580
+ type: "button",
581
+ children: /*#__PURE__*/ _jsx(MeatballsIcon, {})
582
+ }),
583
+ isMenuOpen && /*#__PURE__*/ _jsx(TableActionMenu, {
584
+ cellMerge: cellMerge,
585
+ contextRef: menuRootRef,
586
+ onClose: ()=>setIsMenuOpen(false),
587
+ setIsMenuOpen: setIsMenuOpen,
588
+ tableCellNode: tableCellNode
589
+ })
590
+ ]
591
+ })
592
+ });
593
+ }
594
+ export const TableActionMenuPlugin = ({ anchorElem })=>{
595
+ const isEditable = useLexicalEditable();
596
+ return /*#__PURE__*/ createPortal(isEditable ? /*#__PURE__*/ _jsx(TableCellActionMenuContainer, {
597
+ anchorElem: anchorElem ?? document.body,
598
+ cellMerge: true
599
+ }) : null, anchorElem ?? document.body);
600
+ };
601
+
602
+ //# sourceMappingURL=index.js.map