@lexical/table 0.14.4 → 0.15.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.
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var utils = require('@lexical/utils');
@@ -26,6 +28,7 @@ const PIXEL_VALUE_REG_EXP = /^(\d+(?:\.\d+)?)px$/;
26
28
  * LICENSE file in the root directory of this source tree.
27
29
  *
28
30
  */
31
+
29
32
  const TableCellHeaderStates = {
30
33
  BOTH: 3,
31
34
  COLUMN: 2,
@@ -56,11 +59,11 @@ class TableCellNode extends lexical.ElementNode {
56
59
  static importDOM() {
57
60
  return {
58
61
  td: node => ({
59
- conversion: convertTableCellNodeElement,
62
+ conversion: $convertTableCellNodeElement,
60
63
  priority: 0
61
64
  }),
62
65
  th: node => ({
63
- conversion: convertTableCellNodeElement,
66
+ conversion: $convertTableCellNodeElement,
64
67
  priority: 0
65
68
  })
66
69
  };
@@ -208,7 +211,7 @@ class TableCellNode extends lexical.ElementNode {
208
211
  return false;
209
212
  }
210
213
  }
211
- function convertTableCellNodeElement(domNode) {
214
+ function $convertTableCellNodeElement(domNode) {
212
215
  const domNode_ = domNode;
213
216
  const nodeName = domNode.nodeName.toLowerCase();
214
217
  let width = undefined;
@@ -222,10 +225,11 @@ function convertTableCellNodeElement(domNode) {
222
225
  tableCellNode.__backgroundColor = backgroundColor;
223
226
  }
224
227
  const style = domNode_.style;
228
+ const textDecoration = style.textDecoration.split(' ');
225
229
  const hasBoldFontWeight = style.fontWeight === '700' || style.fontWeight === 'bold';
226
- const hasLinethroughTextDecoration = style.textDecoration === 'line-through';
230
+ const hasLinethroughTextDecoration = textDecoration.includes('line-through');
227
231
  const hasItalicFontStyle = style.fontStyle === 'italic';
228
- const hasUnderlineTextDecoration = style.textDecoration === 'underline';
232
+ const hasUnderlineTextDecoration = textDecoration.includes('underline');
229
233
  return {
230
234
  after: childLexicalNodes => {
231
235
  if (childLexicalNodes.length === 0) {
@@ -275,6 +279,7 @@ function $isTableCellNode(node) {
275
279
  * LICENSE file in the root directory of this source tree.
276
280
  *
277
281
  */
282
+
278
283
  const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
279
284
 
280
285
  /**
@@ -284,6 +289,7 @@ const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
284
289
  * LICENSE file in the root directory of this source tree.
285
290
  *
286
291
  */
292
+
287
293
  /** @noInheritDoc */
288
294
  class TableRowNode extends lexical.ElementNode {
289
295
  /** @internal */
@@ -297,7 +303,7 @@ class TableRowNode extends lexical.ElementNode {
297
303
  static importDOM() {
298
304
  return {
299
305
  tr: node => ({
300
- conversion: convertTableRowElement,
306
+ conversion: $convertTableRowElement,
301
307
  priority: 0
302
308
  })
303
309
  };
@@ -348,7 +354,7 @@ class TableRowNode extends lexical.ElementNode {
348
354
  return false;
349
355
  }
350
356
  }
351
- function convertTableRowElement(domNode) {
357
+ function $convertTableRowElement(domNode) {
352
358
  const domNode_ = domNode;
353
359
  let height = undefined;
354
360
  if (PIXEL_VALUE_REG_EXP.test(domNode_.style.height)) {
@@ -382,6 +388,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
382
388
  * LICENSE file in the root directory of this source tree.
383
389
  *
384
390
  */
391
+
385
392
  function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders = true) {
386
393
  const tableNode = $createTableNode();
387
394
  for (let iRow = 0; iRow < rowCount; iRow++) {
@@ -914,6 +921,16 @@ function $unmergeCell() {
914
921
  }
915
922
  }
916
923
  function $computeTableMap(grid, cellA, cellB) {
924
+ const [tableMap, cellAValue, cellBValue] = $computeTableMapSkipCellCheck(grid, cellA, cellB);
925
+ if (!(cellAValue !== null)) {
926
+ throw Error(`Anchor not found in Grid`);
927
+ }
928
+ if (!(cellBValue !== null)) {
929
+ throw Error(`Focus not found in Grid`);
930
+ }
931
+ return [tableMap, cellAValue, cellBValue];
932
+ }
933
+ function $computeTableMapSkipCellCheck(grid, cellA, cellB) {
917
934
  const tableMap = [];
918
935
  let cellAValue = null;
919
936
  let cellBValue = null;
@@ -933,10 +950,10 @@ function $computeTableMap(grid, cellA, cellB) {
933
950
  tableMap[startRow + i][startColumn + j] = value;
934
951
  }
935
952
  }
936
- if (cellA.is(cell)) {
953
+ if (cellA !== null && cellA.is(cell)) {
937
954
  cellAValue = value;
938
955
  }
939
- if (cellB.is(cell)) {
956
+ if (cellB !== null && cellB.is(cell)) {
940
957
  cellBValue = value;
941
958
  }
942
959
  }
@@ -962,12 +979,6 @@ function $computeTableMap(grid, cellA, cellB) {
962
979
  j += cell.__colSpan;
963
980
  }
964
981
  }
965
- if (!(cellAValue !== null)) {
966
- throw Error(`Anchor not found in Grid`);
967
- }
968
- if (!(cellBValue !== null)) {
969
- throw Error(`Focus not found in Grid`);
970
- }
971
982
  return [tableMap, cellAValue, cellBValue];
972
983
  }
973
984
  function $getNodeTriplet(source) {
@@ -1050,6 +1061,7 @@ function $getTableCellNodeRect(tableCellNode) {
1050
1061
  * LICENSE file in the root directory of this source tree.
1051
1062
  *
1052
1063
  */
1064
+
1053
1065
  class TableSelection {
1054
1066
  constructor(tableKey, anchor, focus) {
1055
1067
  this.anchor = anchor;
@@ -1315,6 +1327,7 @@ function $getChildrenRecursively(node) {
1315
1327
  * LICENSE file in the root directory of this source tree.
1316
1328
  *
1317
1329
  */
1330
+
1318
1331
  class TableObserver {
1319
1332
  constructor(editor, tableNodeKey) {
1320
1333
  this.isHighlightingCells = false;
@@ -1574,8 +1587,12 @@ class TableObserver {
1574
1587
  * LICENSE file in the root directory of this source tree.
1575
1588
  *
1576
1589
  */
1590
+
1577
1591
  const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
1578
1592
  const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
1593
+ const isMouseDownOnEvent = event => {
1594
+ return (event.buttons & 1) === 1;
1595
+ };
1579
1596
  function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1580
1597
  const rootElement = editor.getRootElement();
1581
1598
  if (rootElement === null) {
@@ -1591,11 +1608,20 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1591
1608
  editorWindow.removeEventListener('mousemove', onMouseMove);
1592
1609
  };
1593
1610
  const onMouseMove = moveEvent => {
1594
- const focusCell = getDOMCellFromTarget(moveEvent.target);
1595
- if (focusCell !== null && (tableObserver.anchorX !== focusCell.x || tableObserver.anchorY !== focusCell.y)) {
1596
- moveEvent.preventDefault();
1597
- tableObserver.setFocusCellForSelection(focusCell);
1598
- }
1611
+ // delaying mousemove handler to allow selectionchange handler from LexicalEvents.ts to be executed first
1612
+ setTimeout(() => {
1613
+ if (!isMouseDownOnEvent(moveEvent) && tableObserver.isSelecting) {
1614
+ tableObserver.isSelecting = false;
1615
+ editorWindow.removeEventListener('mouseup', onMouseUp);
1616
+ editorWindow.removeEventListener('mousemove', onMouseMove);
1617
+ return;
1618
+ }
1619
+ const focusCell = getDOMCellFromTarget(moveEvent.target);
1620
+ if (focusCell !== null && (tableObserver.anchorX !== focusCell.x || tableObserver.anchorY !== focusCell.y)) {
1621
+ moveEvent.preventDefault();
1622
+ tableObserver.setFocusCellForSelection(focusCell);
1623
+ }
1624
+ }, 0);
1599
1625
  };
1600
1626
  return {
1601
1627
  onMouseMove: onMouseMove,
@@ -1693,7 +1719,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1693
1719
  [lexical.DELETE_WORD_COMMAND, lexical.DELETE_LINE_COMMAND, lexical.DELETE_CHARACTER_COMMAND].forEach(command => {
1694
1720
  tableObserver.listenersToRemove.add(editor.registerCommand(command, deleteTextHandler(command), lexical.COMMAND_PRIORITY_CRITICAL));
1695
1721
  });
1696
- const deleteCellHandler = event => {
1722
+ const $deleteCellHandler = event => {
1697
1723
  const selection = lexical.$getSelection();
1698
1724
  if (!$isSelectionInTable(selection, tableNode)) {
1699
1725
  return false;
@@ -1711,8 +1737,8 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1711
1737
  }
1712
1738
  return false;
1713
1739
  };
1714
- tableObserver.listenersToRemove.add(editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
1715
- tableObserver.listenersToRemove.add(editor.registerCommand(lexical.KEY_DELETE_COMMAND, deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
1740
+ tableObserver.listenersToRemove.add(editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, $deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
1741
+ tableObserver.listenersToRemove.add(editor.registerCommand(lexical.KEY_DELETE_COMMAND, $deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
1716
1742
  tableObserver.listenersToRemove.add(editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, payload => {
1717
1743
  const selection = lexical.$getSelection();
1718
1744
  if (!$isSelectionInTable(selection, tableNode)) {
@@ -1910,7 +1936,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1910
1936
  if (isPartialyWithinTable) {
1911
1937
  const newSelection = selection.clone();
1912
1938
  if (isFocusInside) {
1913
- newSelection.focus.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() : tableNode.getIndexWithinParent() + 1, 'element');
1939
+ newSelection.focus.set(tableNode.getParentOrThrow().getKey(), tableNode.getIndexWithinParent(), 'element');
1914
1940
  } else {
1915
1941
  newSelection.anchor.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() + 1 : tableNode.getIndexWithinParent(), 'element');
1916
1942
  }
@@ -2234,6 +2260,9 @@ function $findTableNode(node) {
2234
2260
  return $isTableNode(tableNode) ? tableNode : null;
2235
2261
  }
2236
2262
  function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2263
+ if ((direction === 'up' || direction === 'down') && isTypeaheadMenuInView(editor)) {
2264
+ return false;
2265
+ }
2237
2266
  const selection = lexical.$getSelection();
2238
2267
  if (!$isSelectionInTable(selection, tableNode)) {
2239
2268
  if (direction === 'backward' && lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
@@ -2361,13 +2390,22 @@ function stopEvent(event) {
2361
2390
  event.stopImmediatePropagation();
2362
2391
  event.stopPropagation();
2363
2392
  }
2393
+ function isTypeaheadMenuInView(editor) {
2394
+ // There is no inbuilt way to check if the component picker is in view
2395
+ // but we can check if the root DOM element has the aria-controls attribute "typeahead-menu".
2396
+ const root = editor.getRootElement();
2397
+ if (!root) {
2398
+ return false;
2399
+ }
2400
+ return root.hasAttribute('aria-controls') && root.getAttribute('aria-controls') === 'typeahead-menu';
2401
+ }
2364
2402
  function isExitingTableAnchor(type, offset, anchorNode, direction) {
2365
- return isExitingTableElementAnchor(type, anchorNode, direction) || isExitingTableTextAnchor(type, offset, anchorNode, direction);
2403
+ return isExitingTableElementAnchor(type, anchorNode, direction) || $isExitingTableTextAnchor(type, offset, anchorNode, direction);
2366
2404
  }
2367
2405
  function isExitingTableElementAnchor(type, anchorNode, direction) {
2368
2406
  return type === 'element' && (direction === 'backward' ? anchorNode.getPreviousSibling() === null : anchorNode.getNextSibling() === null);
2369
2407
  }
2370
- function isExitingTableTextAnchor(type, offset, anchorNode, direction) {
2408
+ function $isExitingTableTextAnchor(type, offset, anchorNode, direction) {
2371
2409
  const parentNode = utils.$findMatchingParent(anchorNode, n => lexical.$isElementNode(n) && !n.isInline());
2372
2410
  if (!parentNode) {
2373
2411
  return false;
@@ -2384,7 +2422,7 @@ function $handleTableExit(event, anchorNode, tableNode, direction) {
2384
2422
  if (!isExitingCell(tableMap, cellValue, direction)) {
2385
2423
  return false;
2386
2424
  }
2387
- const toNode = getExitingToNode(anchorNode, direction, tableNode);
2425
+ const toNode = $getExitingToNode(anchorNode, direction, tableNode);
2388
2426
  if (!toNode || $isTableNode(toNode)) {
2389
2427
  return false;
2390
2428
  }
@@ -2405,7 +2443,7 @@ function isExitingCell(tableMap, cellValue, direction) {
2405
2443
  } = cellValue;
2406
2444
  return direction === 'backward' ? startColumn === firstCell.startColumn && startRow === firstCell.startRow : startColumn === lastCell.startColumn && startRow === lastCell.startRow;
2407
2445
  }
2408
- function getExitingToNode(anchorNode, direction, tableNode) {
2446
+ function $getExitingToNode(anchorNode, direction, tableNode) {
2409
2447
  const parentNode = utils.$findMatchingParent(anchorNode, n => lexical.$isElementNode(n) && !n.isInline());
2410
2448
  if (!parentNode) {
2411
2449
  return undefined;
@@ -2462,6 +2500,7 @@ function $getTableEdgeCursorPosition(editor, selection, tableNode) {
2462
2500
  * LICENSE file in the root directory of this source tree.
2463
2501
  *
2464
2502
  */
2503
+
2465
2504
  /** @noInheritDoc */
2466
2505
  class TableNode extends lexical.ElementNode {
2467
2506
  static getType() {
@@ -2473,7 +2512,7 @@ class TableNode extends lexical.ElementNode {
2473
2512
  static importDOM() {
2474
2513
  return {
2475
2514
  table: _node => ({
2476
- conversion: convertTableElement,
2515
+ conversion: $convertTableElement,
2477
2516
  priority: 1
2478
2517
  })
2479
2518
  };
@@ -2613,7 +2652,7 @@ function $getElementForTableNode(editor, tableNode) {
2613
2652
  }
2614
2653
  return getTable(tableElement);
2615
2654
  }
2616
- function convertTableElement(_domNode) {
2655
+ function $convertTableElement(_domNode) {
2617
2656
  return {
2618
2657
  node: $createTableNode()
2619
2658
  };
@@ -2626,6 +2665,7 @@ function $isTableNode(node) {
2626
2665
  }
2627
2666
 
2628
2667
  exports.$computeTableMap = $computeTableMap;
2668
+ exports.$computeTableMapSkipCellCheck = $computeTableMapSkipCellCheck;
2629
2669
  exports.$createTableCellNode = $createTableCellNode;
2630
2670
  exports.$createTableNode = $createTableNode;
2631
2671
  exports.$createTableNodeWithDimensions = $createTableNodeWithDimensions;
@@ -3,9 +3,11 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, isHTMLElement } from '@lexical/utils';
8
- import { ElementNode, $applyNodeReplacement, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, createCommand, $createTextNode, $getSelection, $isRangeSelection, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $createPoint, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND } from 'lexical';
10
+ import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND } from 'lexical';
9
11
 
10
12
  /**
11
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -24,6 +26,7 @@ const PIXEL_VALUE_REG_EXP = /^(\d+(?:\.\d+)?)px$/;
24
26
  * LICENSE file in the root directory of this source tree.
25
27
  *
26
28
  */
29
+
27
30
  const TableCellHeaderStates = {
28
31
  BOTH: 3,
29
32
  COLUMN: 2,
@@ -54,11 +57,11 @@ class TableCellNode extends ElementNode {
54
57
  static importDOM() {
55
58
  return {
56
59
  td: node => ({
57
- conversion: convertTableCellNodeElement,
60
+ conversion: $convertTableCellNodeElement,
58
61
  priority: 0
59
62
  }),
60
63
  th: node => ({
61
- conversion: convertTableCellNodeElement,
64
+ conversion: $convertTableCellNodeElement,
62
65
  priority: 0
63
66
  })
64
67
  };
@@ -206,7 +209,7 @@ class TableCellNode extends ElementNode {
206
209
  return false;
207
210
  }
208
211
  }
209
- function convertTableCellNodeElement(domNode) {
212
+ function $convertTableCellNodeElement(domNode) {
210
213
  const domNode_ = domNode;
211
214
  const nodeName = domNode.nodeName.toLowerCase();
212
215
  let width = undefined;
@@ -220,10 +223,11 @@ function convertTableCellNodeElement(domNode) {
220
223
  tableCellNode.__backgroundColor = backgroundColor;
221
224
  }
222
225
  const style = domNode_.style;
226
+ const textDecoration = style.textDecoration.split(' ');
223
227
  const hasBoldFontWeight = style.fontWeight === '700' || style.fontWeight === 'bold';
224
- const hasLinethroughTextDecoration = style.textDecoration === 'line-through';
228
+ const hasLinethroughTextDecoration = textDecoration.includes('line-through');
225
229
  const hasItalicFontStyle = style.fontStyle === 'italic';
226
- const hasUnderlineTextDecoration = style.textDecoration === 'underline';
230
+ const hasUnderlineTextDecoration = textDecoration.includes('underline');
227
231
  return {
228
232
  after: childLexicalNodes => {
229
233
  if (childLexicalNodes.length === 0) {
@@ -273,6 +277,7 @@ function $isTableCellNode(node) {
273
277
  * LICENSE file in the root directory of this source tree.
274
278
  *
275
279
  */
280
+
276
281
  const INSERT_TABLE_COMMAND = createCommand('INSERT_TABLE_COMMAND');
277
282
 
278
283
  /**
@@ -282,6 +287,7 @@ const INSERT_TABLE_COMMAND = createCommand('INSERT_TABLE_COMMAND');
282
287
  * LICENSE file in the root directory of this source tree.
283
288
  *
284
289
  */
290
+
285
291
  /** @noInheritDoc */
286
292
  class TableRowNode extends ElementNode {
287
293
  /** @internal */
@@ -295,7 +301,7 @@ class TableRowNode extends ElementNode {
295
301
  static importDOM() {
296
302
  return {
297
303
  tr: node => ({
298
- conversion: convertTableRowElement,
304
+ conversion: $convertTableRowElement,
299
305
  priority: 0
300
306
  })
301
307
  };
@@ -346,7 +352,7 @@ class TableRowNode extends ElementNode {
346
352
  return false;
347
353
  }
348
354
  }
349
- function convertTableRowElement(domNode) {
355
+ function $convertTableRowElement(domNode) {
350
356
  const domNode_ = domNode;
351
357
  let height = undefined;
352
358
  if (PIXEL_VALUE_REG_EXP.test(domNode_.style.height)) {
@@ -380,6 +386,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
380
386
  * LICENSE file in the root directory of this source tree.
381
387
  *
382
388
  */
389
+
383
390
  function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders = true) {
384
391
  const tableNode = $createTableNode();
385
392
  for (let iRow = 0; iRow < rowCount; iRow++) {
@@ -912,6 +919,16 @@ function $unmergeCell() {
912
919
  }
913
920
  }
914
921
  function $computeTableMap(grid, cellA, cellB) {
922
+ const [tableMap, cellAValue, cellBValue] = $computeTableMapSkipCellCheck(grid, cellA, cellB);
923
+ if (!(cellAValue !== null)) {
924
+ throw Error(`Anchor not found in Grid`);
925
+ }
926
+ if (!(cellBValue !== null)) {
927
+ throw Error(`Focus not found in Grid`);
928
+ }
929
+ return [tableMap, cellAValue, cellBValue];
930
+ }
931
+ function $computeTableMapSkipCellCheck(grid, cellA, cellB) {
915
932
  const tableMap = [];
916
933
  let cellAValue = null;
917
934
  let cellBValue = null;
@@ -931,10 +948,10 @@ function $computeTableMap(grid, cellA, cellB) {
931
948
  tableMap[startRow + i][startColumn + j] = value;
932
949
  }
933
950
  }
934
- if (cellA.is(cell)) {
951
+ if (cellA !== null && cellA.is(cell)) {
935
952
  cellAValue = value;
936
953
  }
937
- if (cellB.is(cell)) {
954
+ if (cellB !== null && cellB.is(cell)) {
938
955
  cellBValue = value;
939
956
  }
940
957
  }
@@ -960,12 +977,6 @@ function $computeTableMap(grid, cellA, cellB) {
960
977
  j += cell.__colSpan;
961
978
  }
962
979
  }
963
- if (!(cellAValue !== null)) {
964
- throw Error(`Anchor not found in Grid`);
965
- }
966
- if (!(cellBValue !== null)) {
967
- throw Error(`Focus not found in Grid`);
968
- }
969
980
  return [tableMap, cellAValue, cellBValue];
970
981
  }
971
982
  function $getNodeTriplet(source) {
@@ -1048,6 +1059,7 @@ function $getTableCellNodeRect(tableCellNode) {
1048
1059
  * LICENSE file in the root directory of this source tree.
1049
1060
  *
1050
1061
  */
1062
+
1051
1063
  class TableSelection {
1052
1064
  constructor(tableKey, anchor, focus) {
1053
1065
  this.anchor = anchor;
@@ -1313,6 +1325,7 @@ function $getChildrenRecursively(node) {
1313
1325
  * LICENSE file in the root directory of this source tree.
1314
1326
  *
1315
1327
  */
1328
+
1316
1329
  class TableObserver {
1317
1330
  constructor(editor, tableNodeKey) {
1318
1331
  this.isHighlightingCells = false;
@@ -1572,8 +1585,12 @@ class TableObserver {
1572
1585
  * LICENSE file in the root directory of this source tree.
1573
1586
  *
1574
1587
  */
1588
+
1575
1589
  const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
1576
1590
  const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
1591
+ const isMouseDownOnEvent = event => {
1592
+ return (event.buttons & 1) === 1;
1593
+ };
1577
1594
  function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1578
1595
  const rootElement = editor.getRootElement();
1579
1596
  if (rootElement === null) {
@@ -1589,11 +1606,20 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1589
1606
  editorWindow.removeEventListener('mousemove', onMouseMove);
1590
1607
  };
1591
1608
  const onMouseMove = moveEvent => {
1592
- const focusCell = getDOMCellFromTarget(moveEvent.target);
1593
- if (focusCell !== null && (tableObserver.anchorX !== focusCell.x || tableObserver.anchorY !== focusCell.y)) {
1594
- moveEvent.preventDefault();
1595
- tableObserver.setFocusCellForSelection(focusCell);
1596
- }
1609
+ // delaying mousemove handler to allow selectionchange handler from LexicalEvents.ts to be executed first
1610
+ setTimeout(() => {
1611
+ if (!isMouseDownOnEvent(moveEvent) && tableObserver.isSelecting) {
1612
+ tableObserver.isSelecting = false;
1613
+ editorWindow.removeEventListener('mouseup', onMouseUp);
1614
+ editorWindow.removeEventListener('mousemove', onMouseMove);
1615
+ return;
1616
+ }
1617
+ const focusCell = getDOMCellFromTarget(moveEvent.target);
1618
+ if (focusCell !== null && (tableObserver.anchorX !== focusCell.x || tableObserver.anchorY !== focusCell.y)) {
1619
+ moveEvent.preventDefault();
1620
+ tableObserver.setFocusCellForSelection(focusCell);
1621
+ }
1622
+ }, 0);
1597
1623
  };
1598
1624
  return {
1599
1625
  onMouseMove: onMouseMove,
@@ -1691,7 +1717,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1691
1717
  [DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND].forEach(command => {
1692
1718
  tableObserver.listenersToRemove.add(editor.registerCommand(command, deleteTextHandler(command), COMMAND_PRIORITY_CRITICAL));
1693
1719
  });
1694
- const deleteCellHandler = event => {
1720
+ const $deleteCellHandler = event => {
1695
1721
  const selection = $getSelection();
1696
1722
  if (!$isSelectionInTable(selection, tableNode)) {
1697
1723
  return false;
@@ -1709,8 +1735,8 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1709
1735
  }
1710
1736
  return false;
1711
1737
  };
1712
- tableObserver.listenersToRemove.add(editor.registerCommand(KEY_BACKSPACE_COMMAND, deleteCellHandler, COMMAND_PRIORITY_CRITICAL));
1713
- tableObserver.listenersToRemove.add(editor.registerCommand(KEY_DELETE_COMMAND, deleteCellHandler, COMMAND_PRIORITY_CRITICAL));
1738
+ tableObserver.listenersToRemove.add(editor.registerCommand(KEY_BACKSPACE_COMMAND, $deleteCellHandler, COMMAND_PRIORITY_CRITICAL));
1739
+ tableObserver.listenersToRemove.add(editor.registerCommand(KEY_DELETE_COMMAND, $deleteCellHandler, COMMAND_PRIORITY_CRITICAL));
1714
1740
  tableObserver.listenersToRemove.add(editor.registerCommand(FORMAT_TEXT_COMMAND, payload => {
1715
1741
  const selection = $getSelection();
1716
1742
  if (!$isSelectionInTable(selection, tableNode)) {
@@ -1908,7 +1934,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
1908
1934
  if (isPartialyWithinTable) {
1909
1935
  const newSelection = selection.clone();
1910
1936
  if (isFocusInside) {
1911
- newSelection.focus.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() : tableNode.getIndexWithinParent() + 1, 'element');
1937
+ newSelection.focus.set(tableNode.getParentOrThrow().getKey(), tableNode.getIndexWithinParent(), 'element');
1912
1938
  } else {
1913
1939
  newSelection.anchor.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() + 1 : tableNode.getIndexWithinParent(), 'element');
1914
1940
  }
@@ -2232,6 +2258,9 @@ function $findTableNode(node) {
2232
2258
  return $isTableNode(tableNode) ? tableNode : null;
2233
2259
  }
2234
2260
  function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2261
+ if ((direction === 'up' || direction === 'down') && isTypeaheadMenuInView(editor)) {
2262
+ return false;
2263
+ }
2235
2264
  const selection = $getSelection();
2236
2265
  if (!$isSelectionInTable(selection, tableNode)) {
2237
2266
  if (direction === 'backward' && $isRangeSelection(selection) && selection.isCollapsed()) {
@@ -2359,13 +2388,22 @@ function stopEvent(event) {
2359
2388
  event.stopImmediatePropagation();
2360
2389
  event.stopPropagation();
2361
2390
  }
2391
+ function isTypeaheadMenuInView(editor) {
2392
+ // There is no inbuilt way to check if the component picker is in view
2393
+ // but we can check if the root DOM element has the aria-controls attribute "typeahead-menu".
2394
+ const root = editor.getRootElement();
2395
+ if (!root) {
2396
+ return false;
2397
+ }
2398
+ return root.hasAttribute('aria-controls') && root.getAttribute('aria-controls') === 'typeahead-menu';
2399
+ }
2362
2400
  function isExitingTableAnchor(type, offset, anchorNode, direction) {
2363
- return isExitingTableElementAnchor(type, anchorNode, direction) || isExitingTableTextAnchor(type, offset, anchorNode, direction);
2401
+ return isExitingTableElementAnchor(type, anchorNode, direction) || $isExitingTableTextAnchor(type, offset, anchorNode, direction);
2364
2402
  }
2365
2403
  function isExitingTableElementAnchor(type, anchorNode, direction) {
2366
2404
  return type === 'element' && (direction === 'backward' ? anchorNode.getPreviousSibling() === null : anchorNode.getNextSibling() === null);
2367
2405
  }
2368
- function isExitingTableTextAnchor(type, offset, anchorNode, direction) {
2406
+ function $isExitingTableTextAnchor(type, offset, anchorNode, direction) {
2369
2407
  const parentNode = $findMatchingParent(anchorNode, n => $isElementNode(n) && !n.isInline());
2370
2408
  if (!parentNode) {
2371
2409
  return false;
@@ -2382,7 +2420,7 @@ function $handleTableExit(event, anchorNode, tableNode, direction) {
2382
2420
  if (!isExitingCell(tableMap, cellValue, direction)) {
2383
2421
  return false;
2384
2422
  }
2385
- const toNode = getExitingToNode(anchorNode, direction, tableNode);
2423
+ const toNode = $getExitingToNode(anchorNode, direction, tableNode);
2386
2424
  if (!toNode || $isTableNode(toNode)) {
2387
2425
  return false;
2388
2426
  }
@@ -2403,7 +2441,7 @@ function isExitingCell(tableMap, cellValue, direction) {
2403
2441
  } = cellValue;
2404
2442
  return direction === 'backward' ? startColumn === firstCell.startColumn && startRow === firstCell.startRow : startColumn === lastCell.startColumn && startRow === lastCell.startRow;
2405
2443
  }
2406
- function getExitingToNode(anchorNode, direction, tableNode) {
2444
+ function $getExitingToNode(anchorNode, direction, tableNode) {
2407
2445
  const parentNode = $findMatchingParent(anchorNode, n => $isElementNode(n) && !n.isInline());
2408
2446
  if (!parentNode) {
2409
2447
  return undefined;
@@ -2460,6 +2498,7 @@ function $getTableEdgeCursorPosition(editor, selection, tableNode) {
2460
2498
  * LICENSE file in the root directory of this source tree.
2461
2499
  *
2462
2500
  */
2501
+
2463
2502
  /** @noInheritDoc */
2464
2503
  class TableNode extends ElementNode {
2465
2504
  static getType() {
@@ -2471,7 +2510,7 @@ class TableNode extends ElementNode {
2471
2510
  static importDOM() {
2472
2511
  return {
2473
2512
  table: _node => ({
2474
- conversion: convertTableElement,
2513
+ conversion: $convertTableElement,
2475
2514
  priority: 1
2476
2515
  })
2477
2516
  };
@@ -2611,7 +2650,7 @@ function $getElementForTableNode(editor, tableNode) {
2611
2650
  }
2612
2651
  return getTable(tableElement);
2613
2652
  }
2614
- function convertTableElement(_domNode) {
2653
+ function $convertTableElement(_domNode) {
2615
2654
  return {
2616
2655
  node: $createTableNode()
2617
2656
  };
@@ -2623,4 +2662,4 @@ function $isTableNode(node) {
2623
2662
  return node instanceof TableNode;
2624
2663
  }
2625
2664
 
2626
- export { $computeTableMap, $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $createTableSelection, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getElementForTableNode, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $isTableCellNode, $isTableNode, $isTableRowNode, $isTableSelection, $removeTableRowAtIndex, $unmergeCell, INSERT_TABLE_COMMAND, TableCellHeaderStates, TableCellNode, TableNode, TableObserver, TableRowNode, applyTableHandlers, getDOMCellFromTarget, getTableObserverFromTableElement };
2665
+ export { $computeTableMap, $computeTableMapSkipCellCheck, $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $createTableSelection, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getElementForTableNode, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $isTableCellNode, $isTableNode, $isTableRowNode, $isTableSelection, $removeTableRowAtIndex, $unmergeCell, INSERT_TABLE_COMMAND, TableCellHeaderStates, TableCellNode, TableNode, TableObserver, TableRowNode, applyTableHandlers, getDOMCellFromTarget, getTableObserverFromTableElement };
package/LexicalTable.js CHANGED
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict'
8
10
  const LexicalTable = process.env.NODE_ENV === 'development' ? require('./LexicalTable.dev.js') : require('./LexicalTable.prod.js');
9
11
  module.exports = LexicalTable;
package/LexicalTable.mjs CHANGED
@@ -3,11 +3,14 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  import * as modDev from './LexicalTable.dev.mjs';
8
10
  import * as modProd from './LexicalTable.prod.mjs';
9
11
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
12
  export const $computeTableMap = mod.$computeTableMap;
13
+ export const $computeTableMapSkipCellCheck = mod.$computeTableMapSkipCellCheck;
11
14
  export const $createTableCellNode = mod.$createTableCellNode;
12
15
  export const $createTableNode = mod.$createTableNode;
13
16
  export const $createTableNodeWithDimensions = mod.$createTableNodeWithDimensions;
@@ -3,9 +3,12 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalTable.dev.mjs') : import('./LexicalTable.prod.mjs'));
8
10
  export const $computeTableMap = mod.$computeTableMap;
11
+ export const $computeTableMapSkipCellCheck = mod.$computeTableMapSkipCellCheck;
9
12
  export const $createTableCellNode = mod.$createTableCellNode;
10
13
  export const $createTableNode = mod.$createTableNode;
11
14
  export const $createTableNodeWithDimensions = mod.$createTableNodeWithDimensions;
@@ -3,90 +3,93 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict';var h=require("@lexical/utils"),u=require("lexical");let aa=/^(\d+(?:\.\d+)?)px$/,w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
- class y extends u.ElementNode{static getType(){return"tablecell"}static clone(a){let b=new y(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:ba,priority:0}),th:()=>({conversion:ba,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=z(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=w.NO_STATUS,b=1,c,d){super(d);
10
+ class x extends u.ElementNode{static getType(){return"tablecell"}static clone(a){let b=new x(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:ba,priority:0}),th:()=>({conversion:ba,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=z(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=w.NO_STATUS,b=1,c,d){super(d);
9
11
  this.__colSpan=b;this.__rowSpan=1;this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);h.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
10
12
  if(a){var b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";b=this.getBackgroundColor();null!==b?a.style.backgroundColor=b:this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),
11
13
  colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(a){this.getWritable().__colSpan=a;return this}getRowSpan(){return this.__rowSpan}setRowSpan(a){this.getWritable().__rowSpan=a;return this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=
12
14
  a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==w.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==
13
15
  this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
14
- function ba(a){var b=a.nodeName.toLowerCase(),c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("th"===b?w.ROW:w.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;let d="700"===a.fontWeight||"bold"===a.fontWeight,e="line-through"===a.textDecoration,g="italic"===a.fontStyle,f="underline"===a.textDecoration;return{after:m=>{0===m.length&&m.push(u.$createParagraphNode());return m},forChild:(m,p)=>{if(A(p)&&!u.$isElementNode(m)){p=
15
- u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),e&&m.toggleFormat("strikethrough"),g&&m.toggleFormat("italic"),f&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function z(a,b=1,c){return u.$applyNodeReplacement(new y(a,b,c))}function A(a){return a instanceof y}let ca=u.createCommand("INSERT_TABLE_COMMAND");
16
- class C extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return D(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);h.addClassNamesToElement(b,
17
- a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function fa(a){let b=void 0;aa.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:D(b)}}function D(a){return u.$applyNodeReplacement(new C(a))}function H(a){return a instanceof C}
18
- function J(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
19
- function ia(a){a=h.$findMatchingParent(a,b=>H(b));if(H(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:e}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,e-1,b),below:c.getCellNodeFromCords(d,e+1,b),left:c.getCellNodeFromCords(d-1,e,b),right:c.getCellNodeFromCords(d+1,e,b)}}
20
- let la=(a,b)=>a===w.BOTH||a===b?b:w.NO_STATUS;function N(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}
21
- function O(a,b,c){let d=[],e=null,g=null;a=a.getChildren();for(let t=0;t<a.length;t++){var f=a[t];H(f)||J(146);var m=f.getChildren();f=0;for(let k of m){for(A(k)||J(147);void 0!==d[t]&&void 0!==d[t][f];)f++;m=t;var p=f,r=k;let l={cell:r,startColumn:p,startRow:m},n=r.__rowSpan,q=r.__colSpan;for(let v=0;v<n;v++){void 0===d[m+v]&&(d[m+v]=[]);for(let x=0;x<q;x++)d[m+v][p+x]=l}b.is(r)&&(e=l);c.is(r)&&(g=l);f+=k.__colSpan}}null===e&&J(110);null===g&&J(111);return[d,e,g]}
22
- function P(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,A),A(a)||J(148)):(a=h.$findMatchingParent(a.getNode(),A),A(a)||J(148)));let b=a.getParent();H(b)||J(149);let c=b.getParent();K(c)||J(150);return[a,b,c]}
23
- function na(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let g=Array(d);for(var f=0;f<d;f++)g[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let p=0;p<f.length;p++){for(;g[e][m];)m++;let r=f[p],t=r.__rowSpan||1,k=r.__colSpan||1;for(let l=0;l<t;l++)for(let n=0;n<k;n++)g[e+l][m+n]=r;if(b===r)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:t};m+=k}}return null}
24
- class oa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return Q(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
25
- this._cachedNodes=null}clone(){return new oa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||J(151);u.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=u.$getNodeByKey(this.anchor.key);A(a)||J(152);a=na(a);null===a&&J(153);var b=u.$getNodeByKey(this.focus.key);A(b)||J(154);let c=na(b);null===c&&J(155);b=Math.min(a.columnIndex,
26
- c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(v){let {cell:x,startColumn:B,startRow:E}=v;p=Math.min(p,B);r=Math.min(r,E);t=Math.max(t,B+x.__colSpan-1);k=Math.max(k,E+x.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=h.$findMatchingParent(c,A);c=h.$findMatchingParent(b,
27
- A);A(d)||J(152);A(c)||J(154);b=d.getParent();H(b)||J(156);b=b.getParent();K(b)||J(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&J(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&J(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [g,f,m]=O(b,d,c),p=Math.min(f.startColumn,m.startColumn),r=Math.min(f.startRow,m.startRow),t=Math.max(f.startColumn+f.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),k=Math.max(f.startRow+
28
- f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=p;d=r;e=p;for(var l=r;p<c||r<d||t>e||k>l;){if(p<c){var n=l-d;--c;for(var q=0;q<=n;q++)a(g[d+q][c])}if(r<d)for(n=e-c,--d,q=0;q<=n;q++)a(g[d][c+q]);if(t>e)for(n=l-d,e+=1,q=0;q<=n;q++)a(g[d+q][e]);if(k>l)for(n=e-c,l+=1,q=0;q<=n;q++)a(g[l][c+q])}b=[b];c=null;for(d=r;d<=k;d++)for(e=p;e<=t;e++)({cell:l}=g[d][e]),n=l.getParent(),H(n)||J(160),n!==c&&b.push(n),b.push(l,...pa(l)),c=n;u.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
29
- this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function Q(a){return a instanceof oa}function R(){let a=u.$createPoint("root",0,"element"),b=u.$createPoint("root",0,"element");return new oa("root",a,b)}function pa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&J(112);u.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
30
- class qa{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTable();this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTable(){let a=
16
+ function ba(a){var b=a.nodeName.toLowerCase(),c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("th"===b?w.ROW:w.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=a.textDecoration.split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),g="italic"===a.fontStyle,f=c.includes("underline");return{after:m=>{0===m.length&&m.push(u.$createParagraphNode());return m},forChild:(m,p)=>{if(A(p)&&
17
+ !u.$isElementNode(m)){p=u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),e&&m.toggleFormat("strikethrough"),g&&m.toggleFormat("italic"),f&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function z(a,b=1,c){return u.$applyNodeReplacement(new x(a,b,c))}function A(a){return a instanceof x}let ca=u.createCommand("INSERT_TABLE_COMMAND");
18
+ class C extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:da,priority:0})}}static importJSON(a){return D(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);h.addClassNamesToElement(b,
19
+ a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function da(a){let b=void 0;aa.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:D(b)}}function D(a){return u.$applyNodeReplacement(new C(a))}function H(a){return a instanceof C}var J;
20
+ function K(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}J=K&&K.__esModule&&Object.prototype.hasOwnProperty.call(K,"default")?K["default"]:K;let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
21
+ function ia(a){a=h.$findMatchingParent(a,b=>H(b));if(H(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>N(b));if(N(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:e}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,e-1,b),below:c.getCellNodeFromCords(d,e+1,b),left:c.getCellNodeFromCords(d-1,e,b),right:c.getCellNodeFromCords(d+1,e,b)}}
22
+ let la=(a,b)=>a===w.BOTH||a===b?b:w.NO_STATUS;function O(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function P(a,b,c){let [d,e,g]=na(a,b,c);null===e&&J(110);null===g&&J(111);return[d,e,g]}
23
+ function na(a,b,c){let d=[],e=null,g=null;a=a.getChildren();for(let t=0;t<a.length;t++){var f=a[t];H(f)||J(146);var m=f.getChildren();f=0;for(let k of m){for(A(k)||J(147);void 0!==d[t]&&void 0!==d[t][f];)f++;m=t;var p=f,r=k;let l={cell:r,startColumn:p,startRow:m},n=r.__rowSpan,q=r.__colSpan;for(let v=0;v<n;v++){void 0===d[m+v]&&(d[m+v]=[]);for(let y=0;y<q;y++)d[m+v][p+y]=l}null!==b&&b.is(r)&&(e=l);null!==c&&c.is(r)&&(g=l);f+=k.__colSpan}}return[d,e,g]}
24
+ function Q(a){a instanceof x||("__type"in a?(a=h.$findMatchingParent(a,A),A(a)||J(148)):(a=h.$findMatchingParent(a.getNode(),A),A(a)||J(148)));let b=a.getParent();H(b)||J(149);let c=b.getParent();N(c)||J(150);return[a,b,c]}
25
+ function oa(a){let [b,,c]=Q(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let g=Array(d);for(var f=0;f<d;f++)g[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let p=0;p<f.length;p++){for(;g[e][m];)m++;let r=f[p],t=r.__rowSpan||1,k=r.__colSpan||1;for(let l=0;l<t;l++)for(let n=0;n<k;n++)g[e+l][m+n]=r;if(b===r)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:t};m+=k}}return null}
26
+ class pa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return R(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
27
+ this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||J(151);u.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=u.$getNodeByKey(this.anchor.key);A(a)||J(152);a=oa(a);null===a&&J(153);var b=u.$getNodeByKey(this.focus.key);A(b)||J(154);let c=oa(b);null===c&&J(155);b=Math.min(a.columnIndex,
28
+ c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(v){let {cell:y,startColumn:B,startRow:E}=v;p=Math.min(p,B);r=Math.min(r,E);t=Math.max(t,B+y.__colSpan-1);k=Math.max(k,E+y.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=h.$findMatchingParent(c,A);c=h.$findMatchingParent(b,
29
+ A);A(d)||J(152);A(c)||J(154);b=d.getParent();H(b)||J(156);b=b.getParent();N(b)||J(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&J(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&J(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [g,f,m]=P(b,d,c),p=Math.min(f.startColumn,m.startColumn),r=Math.min(f.startRow,m.startRow),t=Math.max(f.startColumn+f.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),k=Math.max(f.startRow+
30
+ f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=p;d=r;e=p;for(var l=r;p<c||r<d||t>e||k>l;){if(p<c){var n=l-d;--c;for(var q=0;q<=n;q++)a(g[d+q][c])}if(r<d)for(n=e-c,--d,q=0;q<=n;q++)a(g[d][c+q]);if(t>e)for(n=l-d,e+=1,q=0;q<=n;q++)a(g[d+q][e]);if(k>l)for(n=e-c,l+=1,q=0;q<=n;q++)a(g[l][c+q])}b=[b];c=null;for(d=r;d<=k;d++)for(e=p;e<=t;e++)({cell:l}=g[d][e]),n=l.getParent(),H(n)||J(160),n!==c&&b.push(n),b.push(l,...qa(l)),c=n;u.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
31
+ this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function R(a){return a instanceof pa}function ra(){let a=u.$createPoint("root",0,"element"),b=u.$createPoint("root",0,"element");return new pa("root",a,b)}function qa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&J(112);u.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
32
+ class sa{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTable();this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTable(){let a=
31
33
  new MutationObserver(b=>{this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=S(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.table=S(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=
32
- this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=u.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=S(b);ra(a,b,null);u.$setSelection(null);a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
34
+ this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=u.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=S(b);ta(a,b,null);u.$setSelection(null);a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
33
35
  void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.addClassNamesToElement(b,a._config.theme.tableSelection);
34
- this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();ra(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=u.$getNodeByKey(this.tableNodeKey);if(!K(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
36
+ this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();ta(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=u.$getNodeByKey(this.tableNodeKey);if(!N(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
35
37
  var e=a.x;let g=a.y;this.focusCell=a;if(null!==this.anchorCell){let f=ha?(c._window||window).getSelection():null;f&&f.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==g||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&g===this.focusY)return;this.focusX=e;this.focusY=g;this.isHighlightingCells&&(e=u.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&
36
- A(e)&&d.is(T(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||R(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),u.$setSelection(this.tableSelection),c.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0),ra(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=u.$getNearestNodeFromDOMNode(a.elem);
37
- A(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():R(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();Q(b)||J(11);let c=u.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(g=>{A(g)&&0!==g.getTextContentSize()&&(d.set(g.getKey(),0,"element"),e.set(g.getKey(),g.getChildrenSize(),"element"),c.formatText(a))});u.$setSelection(b);this.editor.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=
38
- this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");var c=u.$getSelection();Q(c)||J(11);c=c.getNodes().filter(A);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),u.$getRoot().selectStart()):(c.forEach(d=>{if(u.$isElementNode(d)){let e=u.$createParagraphNode(),g=u.$createTextNode();e.append(g);d.append(e);d.getChildren().forEach(f=>{f!==e&&f.remove()})}}),ra(a,this.table,null),u.$setSelection(null),a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
39
- void 0))})}}function sa(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
38
+ A(e)&&d.is(T(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||ra(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),u.$setSelection(this.tableSelection),c.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0),ta(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=u.$getNearestNodeFromDOMNode(a.elem);
39
+ A(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();R(b)||J(11);let c=u.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(g=>{A(g)&&0!==g.getTextContentSize()&&(d.set(g.getKey(),0,"element"),e.set(g.getKey(),g.getChildrenSize(),"element"),c.formatText(a))});u.$setSelection(b);this.editor.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=
40
+ this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");var c=u.$getSelection();R(c)||J(11);c=c.getNodes().filter(A);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),u.$getRoot().selectStart()):(c.forEach(d=>{if(u.$isElementNode(d)){let e=u.$createParagraphNode(),g=u.$createTextNode();e.append(g);d.append(e);d.getChildren().forEach(f=>{f!==e&&f.remove()})}}),ta(a,this.table,null),u.$setSelection(null),a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
41
+ void 0))})}}function ua(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
40
42
  function S(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.firstChild;let e=a=0;for(b.length=0;null!=d;){var g=d.nodeName;if("TD"===g||"TH"===g){g=d;g={elem:g,hasBackgroundColor:""!==g.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=g;let f=b[e];void 0===f&&(f=b[e]=[]);f[a]=g}else if(g=d.firstChild,null!=g){d=g;continue}g=d.nextSibling;if(null!=g)a++,d=g;else if(g=d.parentNode,null!=g){d=g.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
41
- function ra(a,b,c){let d=new Set(c?c.getNodes():[]);ta(b,(e,g)=>{let f=e.elem;d.has(g)?(e.highlighted=!0,ua(a,e)):(e.highlighted=!1,va(a,e),f.getAttribute("style")||f.removeAttribute("style"))})}function ta(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let g=d[e];if(!g)continue;let f=u.$getNearestNodeFromDOMNode(g.elem);null!==f&&b(g,f,{x:e,y:c})}}}function wa(a,b){b.disableHighlightStyle();ta(b.table,c=>{c.highlighted=!0;ua(a,c)})}
42
- function xa(a,b){b.enableHighlightStyle();ta(b.table,c=>{let d=c.elem;c.highlighted=!1;va(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
43
- let ya=(a,b,c,d,e)=>{const g="forward"===e;switch(e){case "backward":case "forward":return c!==(g?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(g?1:-1),d,a.table),g?a.selectStart():a.selectEnd()):d!==(g?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(g?0:a.table.columns-1,d+(g?1:-1),a.table),g?a.selectStart():a.selectEnd()):g?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==d?b.getCellNodeFromCordsOrThrow(c,d-1,a.table).selectEnd():b.selectPrevious(),!0;case "down":return d!==
44
- a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},za=(a,b,c,d,e)=>{const g="forward"===e;switch(e){case "backward":case "forward":return c!==(g?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(g?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
45
- d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(u.$isRangeSelection(a)||Q(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
46
- function ua(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);A(b)||J(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
47
- function va(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);A(b)||J(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Ba(a){a=h.$findMatchingParent(a,A);return A(a)?a:null}function T(a){a=h.$findMatchingParent(a,K);return K(a)?a:null}
48
- function Y(a,b,c,d,e){var g=u.$getSelection();if(!U(g,d)){if("backward"===c&&u.$isRangeSelection(g)&&g.isCollapsed()){c=g.anchor.type;d=g.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=g.anchor.getNode();if(!c)return!1;c=h.$findMatchingParent(c,p=>u.$isElementNode(p)&&!p.isInline());if(!c)return!1;c=c.getPreviousSibling();if(!c||!K(c))return!1;Z(b);c.selectEnd();return!0}return!1}if(u.$isRangeSelection(g)&&g.isCollapsed()){let {anchor:p,focus:r}=g;var f=h.$findMatchingParent(p.getNode(),
49
- A),m=h.$findMatchingParent(r.getNode(),A);if(!A(f)||!f.is(m))return!1;m=T(f);if(m!==d&&null!=m&&(g=a.getElementByKey(m.getKey()),null!=g))return e.table=S(g),Y(a,b,c,m,e);if("backward"===c||"forward"===c)return e=p.type,a=p.offset,(f=p.getNode())?Ca(e,a,f,c)?Da(b,f,d,c):!1:!1;m=a.getElementByKey(f.__key);g=a.getElementByKey(p.key);if(null==g||null==m)return!1;if("element"===p.type)m=g.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;m=m.getRangeAt(0).getBoundingClientRect()}g=
50
- "up"===c?f.getFirstChild():f.getLastChild();if(null==g)return!1;a=a.getElementByKey(g.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){Z(b);a=d.getCordsFromCellNode(f,e.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(a.x,a.y,e.table),e.setAnchorCellForSelection(b),e.setFocusCellForSelection(b,!0);else return ya(e,d,a.x,a.y,c);return!0}}else if(Q(g)){let {anchor:p,focus:r}=g,t=h.$findMatchingParent(p.getNode(),A);m=h.$findMatchingParent(r.getNode(),
51
- A);[f]=g.getNodes();a=a.getElementByKey(f.getKey());if(!A(t)||!A(m)||!K(f)||null==a)return!1;e.updateTableTableSelection(g);a=S(a);g=d.getCordsFromCellNode(t,a);g=d.getDOMCellFromCordsOrThrow(g.x,g.y,a);e.setAnchorCellForSelection(g);Z(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,a),za(e,f,b.x,b.y,c);m.selectEnd();return!0}return!1}function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
52
- function Ca(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||Ea(a,b,c,d)}function Ea(a,b,c,d){let e=h.$findMatchingParent(c,g=>u.$isElementNode(g)&&!g.isInline());if(!e)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===e.getPreviousSibling():null===e.getNextSibling())}
53
- function Da(a,b,c,d){var e=h.$findMatchingParent(b,A);if(!A(e))return!1;let [g,f]=O(c,e,e);e=g[0][0];let m=g[g.length-1][g[0].length-1],{startColumn:p,startRow:r}=f;if("backward"===d?p!==e.startColumn||r!==e.startRow:p!==m.startColumn||r!==m.startRow)return!1;b=Fa(b,d,c);if(!b||K(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
54
- function Fa(a,b,c){if(a=h.$findMatchingParent(a,d=>u.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&K(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function Ga(a,b,c){let d=u.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
55
- function Ha(a,b,c){let d=window.getSelection();if(d&&d.anchorNode===a.getRootElement()&&(a=h.$findMatchingParent(b.anchor.getNode(),p=>A(p)))&&(b=h.$findMatchingParent(a,p=>K(p)),K(b)&&b.is(c))){var [e,g]=O(c,a,a);c=e[0][0];a=e[e.length-1][e[0].length-1];var {startRow:f,startColumn:m}=g;if(f===c.startRow&&m===c.startColumn)return"first";if(f===a.startRow&&m===a.startColumn)return"last"}}
56
- class Ia extends u.ElementNode{static getType(){return"table"}static clone(a){return new Ia(a.__key)}static importDOM(){return{table:()=>({conversion:Ja,priority:1})}}static importJSON(){return Ka()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");h.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),d=document.createElement("colgroup"),
43
+ function ta(a,b,c){let d=new Set(c?c.getNodes():[]);va(b,(e,g)=>{let f=e.elem;d.has(g)?(e.highlighted=!0,wa(a,e)):(e.highlighted=!1,xa(a,e),f.getAttribute("style")||f.removeAttribute("style"))})}function va(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let g=d[e];if(!g)continue;let f=u.$getNearestNodeFromDOMNode(g.elem);null!==f&&b(g,f,{x:e,y:c})}}}function ya(a,b){b.disableHighlightStyle();va(b.table,c=>{c.highlighted=!0;wa(a,c)})}
44
+ function za(a,b){b.enableHighlightStyle();va(b.table,c=>{let d=c.elem;c.highlighted=!1;xa(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
45
+ let Aa=(a,b,c,d,e)=>{const g="forward"===e;switch(e){case "backward":case "forward":return c!==(g?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(g?1:-1),d,a.table),g?a.selectStart():a.selectEnd()):d!==(g?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(g?0:a.table.columns-1,d+(g?1:-1),a.table),g?a.selectStart():a.selectEnd()):g?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==d?b.getCellNodeFromCordsOrThrow(c,d-1,a.table).selectEnd():b.selectPrevious(),!0;case "down":return d!==
46
+ a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},Ba=(a,b,c,d,e)=>{const g="forward"===e;switch(e){case "backward":case "forward":return c!==(g?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(g?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
47
+ d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(u.$isRangeSelection(a)||R(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
48
+ function wa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);A(b)||J(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
49
+ function xa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);A(b)||J(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Da(a){a=h.$findMatchingParent(a,A);return A(a)?a:null}function T(a){a=h.$findMatchingParent(a,N);return N(a)?a:null}
50
+ function V(a,b,c,d,e){if(("up"===c||"down"===c)&&Ea(a))return!1;var g=u.$getSelection();if(!U(g,d)){if("backward"===c&&u.$isRangeSelection(g)&&g.isCollapsed()){c=g.anchor.type;d=g.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=g.anchor.getNode();if(!c)return!1;c=h.$findMatchingParent(c,p=>u.$isElementNode(p)&&!p.isInline());if(!c)return!1;c=c.getPreviousSibling();if(!c||!N(c))return!1;Z(b);c.selectEnd();return!0}return!1}if(u.$isRangeSelection(g)&&g.isCollapsed()){let {anchor:p,focus:r}=
51
+ g;var f=h.$findMatchingParent(p.getNode(),A),m=h.$findMatchingParent(r.getNode(),A);if(!A(f)||!f.is(m))return!1;m=T(f);if(m!==d&&null!=m&&(g=a.getElementByKey(m.getKey()),null!=g))return e.table=S(g),V(a,b,c,m,e);if("backward"===c||"forward"===c)return e=p.type,a=p.offset,(f=p.getNode())?Fa(e,a,f,c)?Ga(b,f,d,c):!1:!1;m=a.getElementByKey(f.__key);g=a.getElementByKey(p.key);if(null==g||null==m)return!1;if("element"===p.type)m=g.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;
52
+ m=m.getRangeAt(0).getBoundingClientRect()}g="up"===c?f.getFirstChild():f.getLastChild();if(null==g)return!1;a=a.getElementByKey(g.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){Z(b);a=d.getCordsFromCellNode(f,e.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(a.x,a.y,e.table),e.setAnchorCellForSelection(b),e.setFocusCellForSelection(b,!0);else return Aa(e,d,a.x,a.y,c);return!0}}else if(R(g)){let {anchor:p,focus:r}=g,t=h.$findMatchingParent(p.getNode(),
53
+ A);m=h.$findMatchingParent(r.getNode(),A);[f]=g.getNodes();a=a.getElementByKey(f.getKey());if(!A(t)||!A(m)||!N(f)||null==a)return!1;e.updateTableTableSelection(g);a=S(a);g=d.getCordsFromCellNode(t,a);g=d.getDOMCellFromCordsOrThrow(g.x,g.y,a);e.setAnchorCellForSelection(g);Z(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,a),Ba(e,f,b.x,b.y,c);m.selectEnd();return!0}return!1}function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
54
+ function Ea(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function Fa(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||Ha(a,b,c,d)}
55
+ function Ha(a,b,c,d){let e=h.$findMatchingParent(c,g=>u.$isElementNode(g)&&!g.isInline());if(!e)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===e.getPreviousSibling():null===e.getNextSibling())}
56
+ function Ga(a,b,c,d){var e=h.$findMatchingParent(b,A);if(!A(e))return!1;let [g,f]=P(c,e,e);e=g[0][0];let m=g[g.length-1][g[0].length-1],{startColumn:p,startRow:r}=f;if("backward"===d?p!==e.startColumn||r!==e.startRow:p!==m.startColumn||r!==m.startRow)return!1;b=Ia(b,d,c);if(!b||N(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
57
+ function Ia(a,b,c){if(a=h.$findMatchingParent(a,d=>u.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&N(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function Ja(a,b,c){let d=u.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
58
+ function Ka(a,b,c){let d=window.getSelection();if(d&&d.anchorNode===a.getRootElement()&&(a=h.$findMatchingParent(b.anchor.getNode(),p=>A(p)))&&(b=h.$findMatchingParent(a,p=>N(p)),N(b)&&b.is(c))){var [e,g]=P(c,a,a);c=e[0][0];a=e[e.length-1][e[0].length-1];var {startRow:f,startColumn:m}=g;if(f===c.startRow&&m===c.startColumn)return"first";if(f===a.startRow&&m===a.startColumn)return"last"}}
59
+ class La extends u.ElementNode{static getType(){return"table"}static clone(a){return new La(a.__key)}static importDOM(){return{table:()=>({conversion:Ma,priority:1})}}static importJSON(){return Na()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");h.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),d=document.createElement("colgroup"),
57
60
  e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!H(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let g=0;g<b;g++){let f=document.createElement("col");d.append(f)}c.replaceChildren(d,e);return c}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var e=d[b];if(null!=e&&(e=e.findIndex(g=>{if(g)return{elem:g}=g,u.$getNearestNodeFromDOMNode(g)===a}),
58
61
  -1!==e))return{x:e,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getDOMCellFromCordsOrThrow(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=u.$getNearestNodeFromDOMNode(a.elem);return A(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);
59
- if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function Ja(){return{node:Ka()}}function Ka(){return u.$applyNodeReplacement(new Ia)}function K(a){return a instanceof Ia}exports.$computeTableMap=O;exports.$createTableCellNode=z;exports.$createTableNode=Ka;
60
- exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Ka();for(let g=0;g<a;g++){let f=D();for(let m=0;m<b;m++){var e=w.NO_STATUS;"object"===typeof c?(0===g&&c.rows&&(e|=w.ROW),0===m&&c.columns&&(e|=w.COLUMN)):c&&(0===g&&(e|=w.ROW),0===m&&(e|=w.COLUMN));e=z(e);let p=u.$createParagraphNode();p.append(u.$createTextNode());e.append(p);f.append(e)}d.append(f)}return d};exports.$createTableRowNode=D;exports.$createTableSelection=R;
62
+ if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function Ma(){return{node:Na()}}function Na(){return u.$applyNodeReplacement(new La)}function N(a){return a instanceof La}exports.$computeTableMap=P;exports.$computeTableMapSkipCellCheck=na;exports.$createTableCellNode=z;exports.$createTableNode=Na;
63
+ exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Na();for(let g=0;g<a;g++){let f=D();for(let m=0;m<b;m++){var e=w.NO_STATUS;"object"===typeof c?(0===g&&c.rows&&(e|=w.ROW),0===m&&c.columns&&(e|=w.COLUMN)):c&&(0===g&&(e|=w.ROW),0===m&&(e|=w.COLUMN));e=z(e);let p=u.$createParagraphNode();p.append(u.$createTextNode());e.append(p);f.append(e)}d.append(f)}return d};exports.$createTableRowNode=D;exports.$createTableSelection=ra;
61
64
  exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(H(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
62
- exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);[b]=P(a);let [e,g,f]=O(d,c,b);var {startColumn:m}=g;let {startRow:p,startColumn:r}=f;a=Math.min(m,r);m=Math.max(m+c.__colSpan-1,r+b.__colSpan-1);let t=m-a+1;if(e[0].length===m-a+1)d.selectPrevious(),d.remove();else{var k=e.length;for(let l=0;l<k;l++)for(let n=a;n<=m;n++){let {cell:q,startColumn:v}=e[l][n];v<a?n===a&&q.setColSpan(q.__colSpan-
63
- Math.min(t,q.__colSpan-(a-v))):v+q.__colSpan-1>m?n===m&&q.setColSpan(q.__colSpan-(m-v+1)):q.remove()}a=e[p];b=a[r+b.__colSpan];void 0!==b?({cell:b}=b,N(b)):({cell:b}=a[r-1],N(b))}};
64
- exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);[a]=P(a);let [e,g,f]=O(d,c,a);({startRow:b}=g);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var p=e[a+1],r=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var t=m-1;0<=t;t--){let {cell:l,startRow:n,startColumn:q}=e[k][t];if(q===t&&(k===b&&n<b&&l.setRowSpan(l.__rowSpan-(n-b)),n>=b&&n+l.__rowSpan-
65
- 1>a))if(l.setRowSpan(l.__rowSpan-(a-n+1)),null===r&&J(122),0===t)ma(r,l);else{let {cell:v}=p[t-1];v.insertAfter(l)}}t=d.getChildAtIndex(k);H(t)||J(123,String(k));t.remove()}void 0!==p?({cell:b}=p[0],N(b)):({cell:b}=e[b-1][0],N(b))}};exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return S(a)};exports.$getNodeTriplet=P;
66
- exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>A(b));return A(a)?a:null};exports.$getTableCellNodeRect=na;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
65
+ exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[b]=Q(a);let [e,g,f]=P(d,c,b);var {startColumn:m}=g;let {startRow:p,startColumn:r}=f;a=Math.min(m,r);m=Math.max(m+c.__colSpan-1,r+b.__colSpan-1);let t=m-a+1;if(e[0].length===m-a+1)d.selectPrevious(),d.remove();else{var k=e.length;for(let l=0;l<k;l++)for(let n=a;n<=m;n++){let {cell:q,startColumn:v}=e[l][n];v<a?n===a&&q.setColSpan(q.__colSpan-
66
+ Math.min(t,q.__colSpan-(a-v))):v+q.__colSpan-1>m?n===m&&q.setColSpan(q.__colSpan-(m-v+1)):q.remove()}a=e[p];b=a[r+b.__colSpan];void 0!==b?({cell:b}=b,O(b)):({cell:b}=a[r-1],O(b))}};
67
+ exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[a]=Q(a);let [e,g,f]=P(d,c,a);({startRow:b}=g);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var p=e[a+1],r=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var t=m-1;0<=t;t--){let {cell:l,startRow:n,startColumn:q}=e[k][t];if(q===t&&(k===b&&n<b&&l.setRowSpan(l.__rowSpan-(n-b)),n>=b&&n+l.__rowSpan-
68
+ 1>a))if(l.setRowSpan(l.__rowSpan-(a-n+1)),null===r&&J(122),0===t)ma(r,l);else{let {cell:v}=p[t-1];v.insertAfter(l)}}t=d.getChildAtIndex(k);H(t)||J(123,String(k));t.remove()}void 0!==p?({cell:b}=p[0],O(b)):({cell:b}=e[b-1][0],O(b))}};exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return S(a)};exports.$getNodeTriplet=Q;
69
+ exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>A(b));return A(a)?a:null};exports.$getTableCellNodeRect=oa;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
67
70
  exports.$insertTableColumn=function(a,b,c=!0,d,e){let g=a.getChildren(),f=[];for(let r=0;r<g.length;r++){let t=g[r];if(H(t))for(let k=0;k<d;k++){var m=t.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];A(m)||J(12);let {left:l,right:n}=ka(m,e);var p=w.NO_STATUS;if(l&&l.hasHeaderState(w.ROW)||n&&n.hasHeaderState(w.ROW))p|=w.ROW;p=z(p);p.append(u.$createParagraphNode());f.push({newTableCell:p,targetCell:m})}}f.forEach(({newTableCell:r,targetCell:t})=>{c?
68
71
  t.insertAfter(r):t.insertBefore(r)});return a};
69
- exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=w.NO_STATUS){k=z(k).append(u.$createParagraphNode());null===r&&(r=k);return k}var c=u.$getSelection();u.$isRangeSelection(c)||Q(c)||J(118);var d=c.anchor.getNode();c=c.focus.getNode();[d]=P(d);let [e,,g]=P(c),[f,m,p]=O(g,e,d);d=f.length;c=a?Math.max(m.startColumn,p.startColumn):Math.min(m.startColumn,p.startColumn);a=a?c+e.__colSpan-1:c-1;c=g.getFirstChild();H(c)||J(120);let r=null;var t=c;a:for(c=0;c<d;c++){0!==c&&(t=t.getNextSibling(),
70
- H(t)||J(121));let k=f[c],l=la(k[0>a?0:a].cell.__headerState,w.ROW);if(0>a){ma(t,b(l));continue}let {cell:n,startColumn:q,startRow:v}=k[a];if(q+n.__colSpan-1<=a){let x=n,B=v,E=a;for(;B!==c&&1<x.__rowSpan;)if(E-=n.__colSpan,0<=E){let {cell:F,startRow:G}=k[E];x=F;B=G}else{t.append(b(l));continue a}x.insertAfter(b(l))}else n.setColSpan(n.__colSpan+1)}null!==r&&N(r)};
72
+ exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=w.NO_STATUS){k=z(k).append(u.$createParagraphNode());null===r&&(r=k);return k}var c=u.$getSelection();u.$isRangeSelection(c)||R(c)||J(118);var d=c.anchor.getNode();c=c.focus.getNode();[d]=Q(d);let [e,,g]=Q(c),[f,m,p]=P(g,e,d);d=f.length;c=a?Math.max(m.startColumn,p.startColumn):Math.min(m.startColumn,p.startColumn);a=a?c+e.__colSpan-1:c-1;c=g.getFirstChild();H(c)||J(120);let r=null;var t=c;a:for(c=0;c<d;c++){0!==c&&(t=t.getNextSibling(),
73
+ H(t)||J(121));let k=f[c],l=la(k[0>a?0:a].cell.__headerState,w.ROW);if(0>a){ma(t,b(l));continue}let {cell:n,startColumn:q,startRow:v}=k[a];if(q+n.__colSpan-1<=a){let y=n,B=v,E=a;for(;B!==c&&1<y.__rowSpan;)if(E-=n.__colSpan,0<=E){let {cell:F,startRow:G}=k[E];y=F;B=G}else{t.append(b(l));continue a}y.insertAfter(b(l))}else n.setColSpan(n.__colSpan+1)}null!==r&&O(r)};
71
74
  exports.$insertTableRow=function(a,b,c=!0,d,e){var g=a.getChildren();if(b>=g.length||0>b)throw Error("Table row target index out of range");b=g[b];if(H(b))for(g=0;g<d;g++){let m=b.getChildren(),p=m.length,r=D();for(let t=0;t<p;t++){var f=m[t];A(f)||J(12);let {above:k,below:l}=ka(f,e);f=w.NO_STATUS;let n=k&&k.getWidth()||l&&l.getWidth()||void 0;if(k&&k.hasHeaderState(w.COLUMN)||l&&l.hasHeaderState(w.COLUMN))f|=w.COLUMN;f=z(f,1,n);f.append(u.$createParagraphNode());r.append(f)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
72
75
  return a};
73
- exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||Q(b)||J(118);b=b.focus.getNode();let [c,,d]=P(b),[e,g]=O(d,c,c);b=e[0].length;var {startRow:f}=g;if(a){a=f+c.__rowSpan-1;var m=e[a];f=D();for(var p=0;p<b;p++){let {cell:t,startRow:k}=m[p];if(k+t.__rowSpan-1<=a){var r=la(m[p].cell.__headerState,w.COLUMN);f.append(z(r).append(u.$createParagraphNode()))}else t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(a);H(b)||J(145);b.insertAfter(f)}else{m=e[f];
74
- a=D();for(p=0;p<b;p++){let {cell:t,startRow:k}=m[p];k===f?(r=la(m[p].cell.__headerState,w.COLUMN),a.append(z(r).append(u.$createParagraphNode()))):t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(f);H(b)||J(145);b.insertBefore(a)}};exports.$isTableCellNode=A;exports.$isTableNode=K;exports.$isTableRowNode=H;exports.$isTableSelection=Q;exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
75
- exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||J(118);a=a.anchor.getNode();let [b,c,d]=P(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var g=1;g<a;g++)b.insertAfter(z(w.NO_STATUS));b.setColSpan(1)}if(1<e){let [p,r]=O(d,b,b),{startColumn:t,startRow:k}=r,l;for(g=1;g<e;g++){var f=k+g;let n=p[f];l=(l||c).getNextSibling();H(l)||J(125);var m=null;for(let q=0;q<t;q++){let v=n[q],x=v.cell;v.startRow===f&&(m=x);1<x.__colSpan&&(q+=x.__colSpan-1)}if(null===m)for(m=0;m<
76
- a;m++)ma(l,z(w.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ca;exports.TableCellHeaderStates=w;exports.TableCellNode=y;exports.TableNode=Ia;exports.TableObserver=qa;exports.TableRowNode=C;
77
- exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,f.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,f.table)}let g=c.getRootElement();if(null===g)throw Error("No root element.");let f=new qa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;let p=()=>{const k=()=>{f.isSelecting=!1;m.removeEventListener("mouseup",k);m.removeEventListener("mousemove",l)},l=n=>{const q=sa(n.target);null===q||f.anchorX===q.x&&f.anchorY===q.y||(n.preventDefault(),f.setFocusCellForSelection(q))};
78
- return{onMouseMove:l,onMouseUp:k}};b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=sa(k.target);null!==l&&(Z(k),f.setAnchorCellForSelection(l));var {onMouseUp:n,onMouseMove:q}=p();f.isSelecting=!0;m.addEventListener("mouseup",n);m.addEventListener("mousemove",q)}},0)});let r=k=>{0===k.button&&c.update(()=>{const l=u.$getSelection(),n=k.target;Q(l)&&l.tableKey===f.tableNodeKey&&g.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",r);f.listenersToRemove.add(()=>
79
- m.removeEventListener("mousedown",r));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_DOWN_COMMAND,k=>Y(c,k,"down",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_UP_COMMAND,k=>Y(c,k,"up",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_LEFT_COMMAND,k=>Y(c,k,"backward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_RIGHT_COMMAND,k=>Y(c,k,"forward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ESCAPE_COMMAND,
80
- k=>{var l=u.$getSelection();return Q(l)&&(l=h.$findMatchingParent(l.focus.getNode(),A),A(l))?(Z(k),l.selectEnd(),!0):!1},u.COMMAND_PRIORITY_HIGH));let t=k=>()=>{var l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))return f.clearText(),!0;if(u.$isRangeSelection(l)){var n=h.$findMatchingParent(l.anchor.getNode(),v=>A(v));if(!A(n))return!1;var q=l.anchor.getNode();n=l.focus.getNode();q=a.isParentOf(q);n=a.isParentOf(n);if(q&&!n||n&&!q)return f.clearText(),!0;n=(l=h.$findMatchingParent(l.anchor.getNode(),
81
- v=>u.$isElementNode(v)))&&h.$findMatchingParent(l,v=>u.$isElementNode(v)&&A(v.getParent()));if(!u.$isElementNode(n)||!u.$isElementNode(l))return!1;if(k===u.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0}return!1};[u.DELETE_WORD_COMMAND,u.DELETE_LINE_COMMAND,u.DELETE_CHARACTER_COMMAND].forEach(k=>{f.listenersToRemove.add(c.registerCommand(k,t(k),u.COMMAND_PRIORITY_CRITICAL))});b=k=>{const l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))return k.preventDefault(),k.stopPropagation(),f.clearText(),
82
- !0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>A(n)),A(k));return!1};f.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.KEY_DELETE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,k=>{let l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))return f.formatCells(k),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),
83
- n=>A(n)),A(k));return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,k=>{var l=u.$getSelection();if(!Q(l)||!U(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!A(n)||!A(l))return!1;let [q,v,x]=O(a,n,l);n=Math.max(v.startRow,x.startRow);l=Math.max(v.startColumn,x.startColumn);var B=Math.min(v.startRow,x.startRow);let E=Math.min(v.startColumn,x.startColumn);for(;B<=n;B++)for(let G=E;G<=l;G++){var F=q[B][G].cell;F.setFormat(k);F=F.getChildren();
84
- for(let L=0;L<F.length;L++){let M=F[L];u.$isElementNode(M)&&!M.isInline()&&M.setFormat(k)}}return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))f.clearHighlight();else if(u.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),q=>A(q));if(!A(n))return!1;if("string"===typeof k&&(l=Ha(c,l,a)))return Ga(l,a,[u.$createTextNode(k)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));
85
- d&&f.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,k=>{var l=u.$getSelection();if(!u.$isRangeSelection(l)||!l.isCollapsed()||!U(l,a))return!1;l=Ba(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,f.table);ya(f,a,l.x,l.y,k.shiftKey?"backward":"forward");return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,
86
- k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var q=Q(n);q=u.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),I=>A(I))&&null!==h.$findMatchingParent(n.focus.getNode(),I=>A(I))||q;if(1!==l.length||!K(l[0])||!q||null===k)return!1;var [v]=k,x=l[0];k=x.getChildren();q=x.getFirstChildOrThrow().getChildrenSize();x=x.getChildrenSize();var B=h.$findMatchingParent(v.getNode(),I=>A(I)),E=(v=B&&h.$findMatchingParent(B,I=>H(I)))&&h.$findMatchingParent(v,I=>K(I));if(!A(B)||!H(v)||
87
- !K(E))return!1;var F=v.getIndexWithinParent(),G=Math.min(E.getChildrenSize()-1,F+x-1);x=B.getIndexWithinParent();B=Math.min(v.getChildrenSize()-1,x+q-1);q=Math.min(x,B);v=Math.min(F,G);x=Math.max(x,B);F=Math.max(F,G);E=E.getChildren();G=0;let L,M;for(B=v;B<=F;B++){var da=E[B];if(!H(da))return!1;var ea=k[G];if(!H(ea))return!1;da=da.getChildren();ea=ea.getChildren();let I=0;for(let V=q;V<=x;V++){let W=da[V];if(!A(W))return!1;let Aa=ea[I];if(!A(Aa))return!1;B===v&&V===q?L=W.getKey():B===F&&V===x&&(M=
88
- W.getKey());let La=W.getChildren();Aa.getChildren().forEach(X=>{u.$isTextNode(X)&&u.$createParagraphNode().append(X);W.append(X)});La.forEach(X=>X.remove());I++}G++}L&&M&&(k=R(),k.set(l[0].getKey(),L,M),u.$setSelection(k));return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,()=>{let k=u.$getSelection(),l=u.$getPreviousSelection();if(u.$isRangeSelection(k)){let {anchor:B,focus:E}=k;var n=B.getNode(),q=E.getNode();n=Ba(n);var v=Ba(q),x=!(!n||
89
- !a.is(T(n)));q=!(!v||!a.is(T(v)));let F=x!==q,G=x&&q;x=k.isBackward();F?(n=k.clone(),q?n.focus.set(a.getParentOrThrow().getKey(),x?a.getIndexWithinParent():a.getIndexWithinParent()+1,"element"):n.anchor.set(a.getParentOrThrow().getKey(),x?a.getIndexWithinParent()+1:a.getIndexWithinParent(),"element"),u.$setSelection(n),wa(c,f)):G&&!n.is(v)&&(f.setAnchorCellForSelection(e(n)),f.setFocusCellForSelection(e(v),!0),f.isSelecting||setTimeout(()=>{let {onMouseUp:L,onMouseMove:M}=p();f.isSelecting=!0;m.addEventListener("mouseup",
90
- L);m.addEventListener("mousemove",M)},0))}else k&&Q(k)&&k.is(l)&&k.tableKey===a.getKey()&&(n=ha?(c._window||window).getSelection():null)&&n.anchorNode&&n.focusNode&&(q=(q=u.$getNearestNodeFromDOMNode(n.focusNode))&&!a.is(T(q)),v=(v=u.$getNearestNodeFromDOMNode(n.anchorNode))&&a.is(T(v)),q&&v&&0<n.rangeCount&&(q=u.$createRangeSelectionFromDom(n,c)))&&(q.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),n.removeAllRanges(),u.$setSelection(q));if(k&&!k.is(l)&&(Q(k)||Q(l))&&f.tableSelection&&
91
- !f.tableSelection.is(l))return Q(k)&&k.tableKey===f.tableNodeKey?f.updateTableTableSelection(k):!Q(k)&&Q(l)&&l.tableKey===f.tableNodeKey&&f.updateTableTableSelection(null),!1;f.hasHijackedSelectionStyles&&!a.isSelected()?xa(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&wa(c,f);return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,()=>{var k=u.$getSelection();return u.$isRangeSelection(k)&&k.isCollapsed()&&U(k,a)?(k=Ha(c,k,a))?(Ga(k,a),!0):
92
- !1:!1},u.COMMAND_PRIORITY_CRITICAL));return f};exports.getDOMCellFromTarget=sa;exports.getTableObserverFromTableElement=function(a){return a.__lexicalTableSelection}
76
+ exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||R(b)||J(118);b=b.focus.getNode();let [c,,d]=Q(b),[e,g]=P(d,c,c);b=e[0].length;var {startRow:f}=g;if(a){a=f+c.__rowSpan-1;var m=e[a];f=D();for(var p=0;p<b;p++){let {cell:t,startRow:k}=m[p];if(k+t.__rowSpan-1<=a){var r=la(m[p].cell.__headerState,w.COLUMN);f.append(z(r).append(u.$createParagraphNode()))}else t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(a);H(b)||J(145);b.insertAfter(f)}else{m=e[f];
77
+ a=D();for(p=0;p<b;p++){let {cell:t,startRow:k}=m[p];k===f?(r=la(m[p].cell.__headerState,w.COLUMN),a.append(z(r).append(u.$createParagraphNode()))):t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(f);H(b)||J(145);b.insertBefore(a)}};exports.$isTableCellNode=A;exports.$isTableNode=N;exports.$isTableRowNode=H;exports.$isTableSelection=R;exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
78
+ exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);a=a.anchor.getNode();let [b,c,d]=Q(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var g=1;g<a;g++)b.insertAfter(z(w.NO_STATUS));b.setColSpan(1)}if(1<e){let [p,r]=P(d,b,b),{startColumn:t,startRow:k}=r,l;for(g=1;g<e;g++){var f=k+g;let n=p[f];l=(l||c).getNextSibling();H(l)||J(125);var m=null;for(let q=0;q<t;q++){let v=n[q],y=v.cell;v.startRow===f&&(m=y);1<y.__colSpan&&(q+=y.__colSpan-1)}if(null===m)for(m=0;m<
79
+ a;m++)ma(l,z(w.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ca;exports.TableCellHeaderStates=w;exports.TableCellNode=x;exports.TableNode=La;exports.TableObserver=sa;exports.TableRowNode=C;
80
+ exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,f.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,f.table)}let g=c.getRootElement();if(null===g)throw Error("No root element.");let f=new sa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;let p=()=>{const k=()=>{f.isSelecting=!1;m.removeEventListener("mouseup",k);m.removeEventListener("mousemove",l)},l=n=>{setTimeout(()=>{if(1!==(n.buttons&1)&&f.isSelecting)f.isSelecting=!1,m.removeEventListener("mouseup",
81
+ k),m.removeEventListener("mousemove",l);else{var q=ua(n.target);null===q||f.anchorX===q.x&&f.anchorY===q.y||(n.preventDefault(),f.setFocusCellForSelection(q))}},0)};return{onMouseMove:l,onMouseUp:k}};b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=ua(k.target);null!==l&&(Z(k),f.setAnchorCellForSelection(l));var {onMouseUp:n,onMouseMove:q}=p();f.isSelecting=!0;m.addEventListener("mouseup",n);m.addEventListener("mousemove",q)}},0)});let r=k=>{0===k.button&&c.update(()=>
82
+ {const l=u.$getSelection(),n=k.target;R(l)&&l.tableKey===f.tableNodeKey&&g.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",r);f.listenersToRemove.add(()=>m.removeEventListener("mousedown",r));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_DOWN_COMMAND,k=>V(c,k,"down",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_UP_COMMAND,k=>V(c,k,"up",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_LEFT_COMMAND,
83
+ k=>V(c,k,"backward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_RIGHT_COMMAND,k=>V(c,k,"forward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ESCAPE_COMMAND,k=>{var l=u.$getSelection();return R(l)&&(l=h.$findMatchingParent(l.focus.getNode(),A),A(l))?(Z(k),l.selectEnd(),!0):!1},u.COMMAND_PRIORITY_HIGH));let t=k=>()=>{var l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return f.clearText(),!0;if(u.$isRangeSelection(l)){var n=
84
+ h.$findMatchingParent(l.anchor.getNode(),v=>A(v));if(!A(n))return!1;var q=l.anchor.getNode();n=l.focus.getNode();q=a.isParentOf(q);n=a.isParentOf(n);if(q&&!n||n&&!q)return f.clearText(),!0;n=(l=h.$findMatchingParent(l.anchor.getNode(),v=>u.$isElementNode(v)))&&h.$findMatchingParent(l,v=>u.$isElementNode(v)&&A(v.getParent()));if(!u.$isElementNode(n)||!u.$isElementNode(l))return!1;if(k===u.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0}return!1};[u.DELETE_WORD_COMMAND,u.DELETE_LINE_COMMAND,
85
+ u.DELETE_CHARACTER_COMMAND].forEach(k=>{f.listenersToRemove.add(c.registerCommand(k,t(k),u.COMMAND_PRIORITY_CRITICAL))});b=k=>{const l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return k.preventDefault(),k.stopPropagation(),f.clearText(),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>A(n)),A(k));return!1};f.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.KEY_DELETE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));
86
+ f.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,k=>{let l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return f.formatCells(k),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>A(n)),A(k));return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,k=>{var l=u.$getSelection();if(!R(l)||!U(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!A(n)||!A(l))return!1;let [q,v,y]=P(a,n,l);n=Math.max(v.startRow,
87
+ y.startRow);l=Math.max(v.startColumn,y.startColumn);var B=Math.min(v.startRow,y.startRow);let E=Math.min(v.startColumn,y.startColumn);for(;B<=n;B++)for(let G=E;G<=l;G++){var F=q[B][G].cell;F.setFormat(k);F=F.getChildren();for(let L=0;L<F.length;L++){let M=F[L];u.$isElementNode(M)&&!M.isInline()&&M.setFormat(k)}}return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=u.$getSelection();if(!U(l,a))return!1;if(R(l))f.clearHighlight();
88
+ else if(u.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),q=>A(q));if(!A(n))return!1;if("string"===typeof k&&(l=Ka(c,l,a)))return Ja(l,a,[u.$createTextNode(k)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));d&&f.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,k=>{var l=u.$getSelection();if(!u.$isRangeSelection(l)||!l.isCollapsed()||!U(l,a))return!1;l=Da(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,f.table);Aa(f,a,l.x,l.y,k.shiftKey?"backward":
89
+ "forward");return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var q=R(n);q=u.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),I=>A(I))&&null!==h.$findMatchingParent(n.focus.getNode(),I=>A(I))||q;if(1!==l.length||!N(l[0])||!q||null===k)return!1;var [v]=
90
+ k,y=l[0];k=y.getChildren();q=y.getFirstChildOrThrow().getChildrenSize();y=y.getChildrenSize();var B=h.$findMatchingParent(v.getNode(),I=>A(I)),E=(v=B&&h.$findMatchingParent(B,I=>H(I)))&&h.$findMatchingParent(v,I=>N(I));if(!A(B)||!H(v)||!N(E))return!1;var F=v.getIndexWithinParent(),G=Math.min(E.getChildrenSize()-1,F+y-1);y=B.getIndexWithinParent();B=Math.min(v.getChildrenSize()-1,y+q-1);q=Math.min(y,B);v=Math.min(F,G);y=Math.max(y,B);F=Math.max(F,G);E=E.getChildren();G=0;let L,M;for(B=v;B<=F;B++){var ea=
91
+ E[B];if(!H(ea))return!1;var fa=k[G];if(!H(fa))return!1;ea=ea.getChildren();fa=fa.getChildren();let I=0;for(let W=q;W<=y;W++){let X=ea[W];if(!A(X))return!1;let Ca=fa[I];if(!A(Ca))return!1;B===v&&W===q?L=X.getKey():B===F&&W===y&&(M=X.getKey());let Oa=X.getChildren();Ca.getChildren().forEach(Y=>{u.$isTextNode(Y)&&u.$createParagraphNode().append(Y);X.append(Y)});Oa.forEach(Y=>Y.remove());I++}G++}L&&M&&(k=ra(),k.set(l[0].getKey(),L,M),u.$setSelection(k));return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,
92
+ ()=>{let k=u.$getSelection(),l=u.$getPreviousSelection();if(u.$isRangeSelection(k)){let {anchor:B,focus:E}=k;var n=B.getNode(),q=E.getNode();n=Da(n);var v=Da(q),y=!(!n||!a.is(T(n)));q=!(!v||!a.is(T(v)));let F=y!==q,G=y&&q;y=k.isBackward();F?(n=k.clone(),q?n.focus.set(a.getParentOrThrow().getKey(),a.getIndexWithinParent(),"element"):n.anchor.set(a.getParentOrThrow().getKey(),y?a.getIndexWithinParent()+1:a.getIndexWithinParent(),"element"),u.$setSelection(n),ya(c,f)):G&&!n.is(v)&&(f.setAnchorCellForSelection(e(n)),
93
+ f.setFocusCellForSelection(e(v),!0),f.isSelecting||setTimeout(()=>{let {onMouseUp:L,onMouseMove:M}=p();f.isSelecting=!0;m.addEventListener("mouseup",L);m.addEventListener("mousemove",M)},0))}else k&&R(k)&&k.is(l)&&k.tableKey===a.getKey()&&(n=ha?(c._window||window).getSelection():null)&&n.anchorNode&&n.focusNode&&(q=(q=u.$getNearestNodeFromDOMNode(n.focusNode))&&!a.is(T(q)),v=(v=u.$getNearestNodeFromDOMNode(n.anchorNode))&&a.is(T(v)),q&&v&&0<n.rangeCount&&(q=u.$createRangeSelectionFromDom(n,c)))&&
94
+ (q.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),n.removeAllRanges(),u.$setSelection(q));if(k&&!k.is(l)&&(R(k)||R(l))&&f.tableSelection&&!f.tableSelection.is(l))return R(k)&&k.tableKey===f.tableNodeKey?f.updateTableTableSelection(k):!R(k)&&R(l)&&l.tableKey===f.tableNodeKey&&f.updateTableTableSelection(null),!1;f.hasHijackedSelectionStyles&&!a.isSelected()?za(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&ya(c,f);return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,
95
+ ()=>{var k=u.$getSelection();return u.$isRangeSelection(k)&&k.isCollapsed()&&U(k,a)?(k=Ka(c,k,a))?(Ja(k,a),!0):!1:!1},u.COMMAND_PRIORITY_CRITICAL));return f};exports.getDOMCellFromTarget=ua;exports.getTableObserverFromTableElement=function(a){return a.__lexicalTableSelection}
@@ -3,5 +3,7 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
7
- import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,isHTMLElement as o}from"@lexical/utils";import{ElementNode as r,$applyNodeReplacement as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as a,$isTextNode as c,createCommand as h,$createTextNode as d,$getSelection as u,$isRangeSelection as g,$normalizeSelection__EXPERIMENTAL as f,$getNodeByKey as m,isCurrentlyReadOnlyMode as p,$createPoint as C,$setSelection as S,SELECTION_CHANGE_COMMAND as _,$getNearestNodeFromDOMNode as w,$createRangeSelection as b,$getRoot as y,KEY_ARROW_DOWN_COMMAND as N,COMMAND_PRIORITY_HIGH as x,KEY_ARROW_UP_COMMAND as T,KEY_ARROW_LEFT_COMMAND as v,KEY_ARROW_RIGHT_COMMAND as E,KEY_ESCAPE_COMMAND as O,DELETE_WORD_COMMAND as M,DELETE_LINE_COMMAND as R,DELETE_CHARACTER_COMMAND as K,COMMAND_PRIORITY_CRITICAL as k,KEY_BACKSPACE_COMMAND as F,KEY_DELETE_COMMAND as H,FORMAT_TEXT_COMMAND as P,FORMAT_ELEMENT_COMMAND as A,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as D,FOCUS_COMMAND as I,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as L,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as z}from"lexical";const X=/^(\d+(?:\.\d+)?)px$/,Y={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class J extends r{static getType(){return"tablecell"}static clone(e){const t=new J(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:$,priority:0}),th:e=>({conversion:$,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=j(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=Y.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t,n=700,o=this.getParentOrThrow().getChildrenSize();e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||Math.max(90,n/o)}px`,e.style.verticalAlign="top",e.style.textAlign="start";const r=this.getBackgroundColor();null!==r?e.style.backgroundColor=r:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){return this.getWritable().__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){return this.getWritable().__width=e,this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Y.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function $(e){const t=e,n=e.nodeName.toLowerCase();let o;X.test(t.style.width)&&(o=parseFloat(t.style.width));const r=j("th"===n?Y.ROW:Y.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const h=t.style,d="700"===h.fontWeight||"bold"===h.fontWeight,u="line-through"===h.textDecoration,g="italic"===h.fontStyle,f="underline"===h.textDecoration;return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(q(t)&&!i(e)){const t=s();return a(e)&&"\n"===e.getTextContent()?null:(c(e)&&(d&&e.toggleFormat("bold"),u&&e.toggleFormat("strikethrough"),g&&e.toggleFormat("italic"),f&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function j(e,t=1,n){return l(new J(e,t,n))}function q(e){return e instanceof J}const G=h("INSERT_TABLE_COMMAND");class Q extends r{static getType(){return"tablerow"}static clone(e){return new Q(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:V,priority:0})}}static importJSON(e){return Z(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function V(e){const t=e;let n;return X.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:Z(n)}}function Z(e){return l(new Q(e))}function ee(e){return e instanceof Q}var te=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};const ne="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function oe(e,t,n=!0){const o=tt();for(let r=0;r<e;r++){const e=Z();for(let o=0;o<t;o++){let t=Y.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Y.ROW),0===o&&n.columns&&(t|=Y.COLUMN)):n&&(0===r&&(t|=Y.ROW),0===o&&(t|=Y.COLUMN));const l=j(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function re(e){const n=t(e,(e=>q(e)));return q(n)?n:null}function le(e){const n=t(e,(e=>ee(e)));if(ee(n))return n;throw new Error("Expected table cell to be inside of table row.")}function se(e){const n=t(e,(e=>nt(e)));if(nt(n))return n;throw new Error("Expected table cell to be inside of table.")}function ie(e){const t=le(e);return se(t).getChildren().findIndex((e=>e.is(t)))}function ae(e){return le(e).getChildren().findIndex((t=>t.is(e)))}function ce(e,t){const n=se(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function he(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function de(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const i=l[t];if(!ee(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=Z();for(let n=0;n<t;n++){const t=e[n];q(t)||te(12);const{above:l,below:i}=ce(t,r);let a=Y.NO_STATUS;const c=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Y.COLUMN)||i&&i.hasHeaderState(Y.COLUMN))&&(a|=Y.COLUMN);const h=j(a,1,c);h.append(s()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const ue=(e,t)=>e===Y.BOTH||e===t?t:Y.NO_STATUS;function ge(e=!0){const t=u();g(t)||ve(t)||te(118);const n=t.focus.getNode(),[o,,r]=Ne(n),[l,i]=ye(r,o,o),a=l[0].length,{startRow:c}=i;if(e){const e=c+o.__rowSpan-1,t=l[e],n=Z();for(let o=0;o<a;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=ue(e,Y.COLUMN);n.append(j(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ee(i)||te(145),i.insertAfter(n)}else{const e=l[c],t=Z();for(let n=0;n<a;n++){const{cell:o,startRow:r}=e[n];if(r===c){const o=e[n].cell.__headerState,r=ue(o,Y.COLUMN);t.append(j(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(c);ee(n)||te(145),n.insertBefore(t)}}function fe(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(ee(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];q(o)||te(12);const{left:l,right:a}=ce(o,r);let c=Y.NO_STATUS;(l&&l.hasHeaderState(Y.ROW)||a&&a.hasHeaderState(Y.ROW))&&(c|=Y.ROW);const h=j(c);h.append(s()),i.push({newTableCell:h,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function me(e=!0){const t=u();g(t)||ve(t)||te(118);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ne(n),[l,,i]=Ne(o),[a,c,h]=ye(i,l,r),d=a.length,f=e?Math.max(c.startColumn,h.startColumn):Math.min(c.startColumn,h.startColumn),m=e?f+l.__colSpan-1:f-1,p=i.getFirstChild();ee(p)||te(120);let C=null;function S(e=Y.NO_STATUS){const t=j(e).append(s());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<d;e++){if(0!==e){const e=_.getNextSibling();ee(e)||te(121),_=e}const t=a[e],n=t[m<0?0:m].cell.__headerState,o=ue(n,Y.ROW);if(m<0){we(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(S(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(S(o))}else r.setColSpan(r.__colSpan+1)}null!==C&&_e(C)}function pe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ee(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function Ce(){const e=u();g(e)||ve(e)||te(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ne(t),[l]=Ne(n),[s,i,a]=ye(r,o,l),{startRow:c}=i,{startRow:h}=a,d=h+l.__rowSpan-1;if(s.length===d-c+1)return void r.remove();const f=s[0].length,m=s[d+1],p=r.getChildAtIndex(d+1);for(let e=d;e>=c;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===c&&o<c&&n.setRowSpan(n.__rowSpan-(o-c)),o>=c&&o+n.__rowSpan-1>d))if(n.setRowSpan(n.__rowSpan-(d-o+1)),null===p&&te(122),0===t)we(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ee(t)||te(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];_e(e)}else{const e=s[c-1],{cell:t}=e[0];_e(t)}}function Se(){const e=u();g(e)||ve(e)||te(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ne(t),[l]=Ne(n),[s,i,a]=ye(r,o,l),{startColumn:c}=i,{startRow:h,startColumn:d}=a,f=Math.min(c,d),m=Math.max(c+o.__colSpan-1,d+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[h],_=S[d+l.__colSpan];if(void 0!==_){const{cell:e}=_;_e(e)}else{const e=S[d-1],{cell:t}=e;_e(t)}}function _e(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function we(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function be(){const e=u();g(e)||ve(e)||te(118);const t=e.anchor.getNode(),[n,o,r]=Ne(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(j(Y.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=ye(r,n,n),{startColumn:i,startRow:a}=t;let c;for(let t=1;t<s;t++){const n=a+t,r=e[n];c=(c||o).getNextSibling(),ee(c)||te(125);let s=null;for(let e=0;e<i;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let e=0;e<l;e++)we(c,j(Y.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(j(Y.NO_STATUS))}n.setRowSpan(1)}}function ye(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const a={cell:i,startColumn:s,startRow:e},c=i.__rowSpan,h=i.__colSpan;for(let t=0;t<c;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<h;n++)o[e+t][s+n]=a}t.is(i)&&(r=a),n.is(i)&&(l=a)}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const a=e.getChildren();for(let e=0;e<a.length;e++){const t=a[e];ee(t)||te(146);const n=t.getChildren();let o=0;for(const t of n){for(q(t)||te(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return null===r&&te(110),null===l&&te(111),[o,r,l]}function Ne(e){let n;if(e instanceof J)n=e;else if("__type"in e){const o=t(e,q);q(o)||te(148),n=o}else{const o=t(e.getNode(),q);q(o)||te(148),n=o}const o=n.getParent();ee(o)||te(149);const r=o.getParent();return nt(r)||te(150),[n,o,r]}function xe(e){const[t,,n]=Ne(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}class Te{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!ve(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Te(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();i(t)||te(151);f(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=m(this.anchor.key);q(e)||te(152);const t=xe(e);null===t&&te(153);const n=m(this.focus.key);q(n)||te(154);const o=xe(n);null===o&&te(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex,o.columnIndex),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex,o.rowIndex);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,q),l=t(o,q);q(r)||te(152),q(l)||te(154);const s=r.getParent();ee(s)||te(156);const i=s.getParent();nt(i)||te(157);const a=l.getParents()[1];if(a!==i){if(i.isParentOf(l)){const e=a.getParent();null==e&&te(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&te(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[c,h,d]=ye(i,r,l);let u=Math.min(h.startColumn,d.startColumn),g=Math.min(h.startRow,d.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,d.startColumn+d.cell.__colSpan-1),m=Math.max(h.startRow+h.cell.__rowSpan-1,d.startRow+d.cell.__rowSpan-1),C=u,S=g,_=u,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;u=Math.min(u,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1)}for(;u<C||g<S||f>_||m>w;){if(u<C){const e=w-S,t=C-1;for(let n=0;n<=e;n++)b(c[S+n][t]);C=t}if(g<S){const e=_-C,t=S-1;for(let n=0;n<=e;n++)b(c[t][C+n]);S=t}if(f>_){const e=w-S,t=_+1;for(let n=0;n<=e;n++)b(c[S+n][t]);_=t}if(m>w){const e=_-C,t=w+1;for(let n=0;n<=e;n++)b(c[t][C+n]);w=t}}const y=[i];let N=null;for(let e=g;e<=m;e++)for(let t=u;t<=f;t++){const{cell:n}=c[e][t],o=n.getParent();ee(o)||te(160),o!==N&&y.push(o),y.push(n,...Oe(n)),N=o}return p()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function ve(e){return e instanceof Te}function Ee(){const e=C("root",0,"element"),t=C("root",0,"element");return new Te("root",e,t)}function Oe(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&te(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class Me{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.trackTable(),this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach((e=>e()))}trackTable(){const e=new MutationObserver((e=>{this.editor.update((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TR"===o){t=!0;break}}if(!t)return;const n=this.editor.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");this.table=Pe(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Pe(t),e.observe(t,{childList:!0,subtree:!0})}))}clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),e.update((()=>{if(!nt(m(this.tableNodeKey)))throw new Error("Expected TableNode.");const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");const n=Pe(t);Ae(e,n,null),S(null),e.dispatchCommand(_,void 0)}))}enableHighlightStyle(){const e=this.editor;e.update((()=>{const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}))}disableHighlightStyle(){const t=this.editor;t.update((()=>{const n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}))}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ae(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const o=m(this.tableNodeKey);if(!nt(o))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");const r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=Ke(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=w(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&q(t)&&o.is($e(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Ee(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),S(this.tableSelection),n.dispatchCommand(_,void 0),Ae(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=w(e.elem);if(q(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ee(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=u();ve(t)||te(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{q(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),S(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=m(this.tableNodeKey);if(!nt(t))throw new Error("Expected TableNode.");const n=u();ve(n)||te(11);const o=n.getNodes().filter(q);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ae(e,this.table,null),S(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const Re="__lexicalTableSelection",Ke=e=>ne?(e||window).getSelection():null;function ke(e,n,o,r){const l=o.getRootElement();if(null===l)throw new Error("No root element.");const a=new Me(o,e.getKey()),h=o._window||window;!function(e,t){e[Re]=t}(n,a);const f=()=>{const e=()=>{a.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=e=>{const t=He(e.target);null===t||a.anchorX===t.x&&a.anchorY===t.y||(e.preventDefault(),a.setFocusCellForSelection(t))};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=He(e.target);null!==t&&(qe(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();a.isSelecting=!0,h.addEventListener("mouseup",n),h.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=u(),n=e.target;ve(t)&&t.tableKey===a.tableNodeKey&&l.contains(n)&&a.clearHighlight()}))};h.addEventListener("mousedown",m),a.listenersToRemove.add((()=>h.removeEventListener("mousedown",m))),a.listenersToRemove.add(o.registerCommand(N,(t=>je(o,t,"down",e,a)),x)),a.listenersToRemove.add(o.registerCommand(T,(t=>je(o,t,"up",e,a)),x)),a.listenersToRemove.add(o.registerCommand(v,(t=>je(o,t,"backward",e,a)),x)),a.listenersToRemove.add(o.registerCommand(E,(t=>je(o,t,"forward",e,a)),x)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=u();if(ve(n)){const o=t(n.focus.getNode(),q);if(q(o))return qe(e),o.selectEnd(),!0}return!1}),x));[M,R,K].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=u();if(!We(o,e))return!1;if(ve(o))return a.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>q(e)));if(!q(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),h=e.isParentOf(s);if(c&&!h||h&&!c)return a.clearText(),!0;const d=t(o.anchor.getNode(),(e=>i(e))),u=d&&t(d,(e=>i(e)&&q(e.getParent())));if(!i(u)||!i(d))return!1;if(n===R&&null===u.getPreviousSibling())return!0}return!1})(n),k))}));const p=n=>{const o=u();if(!We(o,e))return!1;if(ve(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>q(e)));if(!q(e))return!1}return!1};function C(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(F,p,k)),a.listenersToRemove.add(o.registerCommand(H,p,k)),a.listenersToRemove.add(o.registerCommand(P,(n=>{const o=u();if(!We(o,e))return!1;if(ve(o))return a.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>q(e)));if(!q(e))return!1}return!1}),k)),a.listenersToRemove.add(o.registerCommand(A,(t=>{const n=u();if(!ve(n)||!We(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!q(o)||!q(r))return!1;const[l,s,a]=ye(e,o,r),c=Math.max(s.startRow,a.startRow),h=Math.max(s.startColumn,a.startColumn),d=Math.min(s.startRow,a.startRow),g=Math.min(s.startColumn,a.startColumn);for(let e=d;e<=c;e++)for(let n=g;n<=h;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),k)),a.listenersToRemove.add(o.registerCommand(B,(n=>{const r=u();if(!We(r,e))return!1;if(ve(r))return a.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>q(e)));if(!q(l))return!1;if("string"==typeof n){const t=Qe(o,r,e);if(t)return Ge(t,e,[d(n)]),!0}}return!1}),k)),r&&a.listenersToRemove.add(o.registerCommand(D,(t=>{const n=u();if(!g(n)||!n.isCollapsed()||!We(n,e))return!1;const o=Je(n.anchor.getNode());if(null===o)return!1;qe(t);const r=e.getCordsFromCellNode(o,a.table);return Ie(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),k)),a.listenersToRemove.add(o.registerCommand(I,(t=>e.isSelected()),x)),a.listenersToRemove.add(o.registerCommand(L,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=ve(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>q(e)))&&null!==t(o.focus.getNode(),(e=>q(e)))||l;if(1!==n.length||!nt(n[0])||!i||null===r)return!1;const[a]=r,h=n[0],d=h.getChildren(),u=h.getFirstChildOrThrow().getChildrenSize(),f=h.getChildrenSize(),m=t(a.getNode(),(e=>q(e))),p=m&&t(m,(e=>ee(e))),C=p&&t(p,(e=>nt(e)));if(!q(m)||!ee(p)||!nt(C))return!1;const _=p.getIndexWithinParent(),w=Math.min(C.getChildrenSize()-1,_+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+u-1),N=Math.min(b,y),x=Math.min(_,w),T=Math.max(b,y),v=Math.max(_,w),E=C.getChildren();let O,M,R=0;for(let e=x;e<=v;e++){const t=E[e];if(!ee(t))return!1;const n=d[R];if(!ee(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let t=N;t<=T;t++){const n=o[t];if(!q(n))return!1;const i=r[l];if(!q(i))return!1;e===x&&t===N?O=n.getKey():e===v&&t===T&&(M=n.getKey());const a=n.getChildren();i.getChildren().forEach((e=>{if(c(e)){s().append(e),n.append(e)}else n.append(e)})),a.forEach((e=>e.remove())),l++}R++}if(O&&M){const e=Ee();e.set(n[0].getKey(),O,M),S(e)}return!0}),k)),a.listenersToRemove.add(o.registerCommand(_,(()=>{const t=u(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Je(l),c=Je(s),d=!(!i||!e.is($e(i))),u=!(!c||!e.is($e(c))),g=d!==u,m=d&&u,p=t.isBackward();if(g){const n=t.clone();u?n.focus.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent():e.getIndexWithinParent()+1,"element"):n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element"),S(n),De(o,a)}else m&&(i.is(c)||(a.setAnchorCellForSelection(C(i)),a.setFocusCellForSelection(C(c),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();a.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&ve(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ke(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is($e(r)),s=w(n.anchorNode),i=s&&e.is($e(s));if(l&&i&&n.rangeCount>0){const r=U(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),S(r))}}}return t&&!t.is(n)&&(ve(t)||ve(n))&&a.tableSelection&&!a.tableSelection.is(n)?(ve(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!ve(t)&&ve(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Be(t.table,(t=>{const n=t.elem;t.highlighted=!1,Ye(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&De(o,a),!1)}),k)),a.listenersToRemove.add(o.registerCommand(z,(()=>{const t=u();if(!g(t)||!t.isCollapsed()||!We(t,e))return!1;const n=Qe(o,t,e);return!!n&&(Ge(n,e),!0)}),k)),a}function Fe(e){return e[Re]}function He(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function Pe(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.firstChild,r=0,l=0;for(t.length=0;null!=o;){const e=o.nodeName;if("TD"===e||"TH"===e){const e={elem:o,hasBackgroundColor:""!==o.style.backgroundColor,highlighted:!1,x:r,y:l};o._cell=e;let n=t[l];void 0===n&&(n=t[l]=[]),n[r]=e}else{const e=o.firstChild;if(null!=e){o=e;continue}}const n=o.nextSibling;if(null!=n){r++,o=n;continue}const s=o.parentNode;if(null!=s){const e=s.nextSibling;if(null==e)break;l++,r=0,o=e}}return n.columns=r+1,n.rows=l+1,n}function Ae(e,t,n){const o=new Set(n?n.getNodes():[]);Be(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Xe(e,t)):(t.highlighted=!1,Ye(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Be(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=w(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function De(e,t){t.disableHighlightStyle(),Be(t.table,(t=>{t.highlighted=!0,Xe(e,t)}))}const Ie=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ue(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ue(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Ue(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ue(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Le=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function We(e,t){if(g(e)||ve(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Ue(e,t){t?e.selectStart():e.selectEnd()}const ze="172,206,247";function Xe(e,t){const n=t.elem,o=w(n);q(o)||te(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${ze})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${ze},0.85), rgba(${ze},0.85))`),n.style.setProperty("caret-color","transparent")}function Ye(e,t){const n=t.elem,o=w(n);q(o)||te(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function Je(e){const n=t(e,q);return q(n)?n:null}function $e(e){const n=t(e,nt);return nt(n)?n:null}function je(e,n,o,r,l){const s=u();if(!We(s,r)){if("backward"===o&&g(s)&&s.isCollapsed()){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const a=l.getPreviousSibling();return!(!a||!nt(a))&&(qe(n),a.selectEnd(),!0)}return!1}if(g(s)&&s.isCollapsed()){const{anchor:a,focus:c}=s,h=t(a.getNode(),q),d=t(c.getNode(),q);if(!q(h)||!h.is(d))return!1;const u=$e(h);if(u!==r&&null!=u){const t=e.getElementByKey(u.getKey());if(null!=t)return l.table=Pe(t),je(e,n,o,u,l)}if("backward"===o||"forward"===o){const e=a.type,l=a.offset,s=a.getNode();return!!s&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,s,o)&&function(e,n,o,r){const l=t(n,q);if(!q(l))return!1;const[s,a]=ye(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,a,r))return!1;const c=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&nt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!c||nt(c))return!1;qe(e),"backward"===r?c.selectEnd():c.selectStart();return!0}(n,s,r,o))}const g=e.getElementByKey(h.__key),f=e.getElementByKey(a.key);if(null==f||null==g)return!1;let m;if("element"===a.type)m=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;m=e.getRangeAt(0).getBoundingClientRect()}const p="up"===o?h.getFirstChild():h.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){qe(n);const e=r.getCordsFromCellNode(h,l.table);if(!n.shiftKey)return Ie(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.setAnchorCellForSelection(t),l.setFocusCellForSelection(t,!0)}return!0}}else if(ve(s)){const{anchor:i,focus:a}=s,c=t(i.getNode(),q),h=t(a.getNode(),q),[d]=s.getNodes(),u=e.getElementByKey(d.getKey());if(!q(c)||!q(h)||!nt(d)||null==u)return!1;l.updateTableTableSelection(s);const g=Pe(u),f=r.getCordsFromCellNode(c,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),qe(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return Le(l,d,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function qe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ge(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Qe(e,n,o){const r=window.getSelection();if(!r||r.anchorNode!==e.getRootElement())return;const l=t(n.anchor.getNode(),(e=>q(e)));if(!l)return;const s=t(l,(e=>nt(e)));if(!nt(s)||!s.is(o))return;const[i,a]=ye(o,l,l),c=i[0][0],h=i[i.length-1][i[0].length-1],{startRow:d,startColumn:u}=a,g=d===c.startRow&&u===c.startColumn,f=d===h.startRow&&u===h.startColumn;return g?"first":f?"last":void 0}class Ve extends r{static getType(){return"table"}static clone(e){return new Ve(e.__key)}static importDOM(){return{table:e=>({conversion:et,priority:1})}}static importJSON(e){return tt()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(o,t.theme.table),o}updateDOM(){return!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!ee(l))throw new Error("Expected to find row node.");const s=l.getChildrenSize();for(let e=0;e<s;e++){const e=document.createElement("col");n.append(e)}return t.replaceChildren(n,r),t}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return w(n)===e}));if(-1!==r)return{x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=w(o.elem);return q(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}canSelectBefore(){return!0}canIndent(){return!1}}function Ze(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Pe(n)}function et(e){return{node:tt()}}function tt(){return l(new Ve)}function nt(e){return e instanceof Ve}export{ye as $computeTableMap,j as $createTableCellNode,tt as $createTableNode,oe as $createTableNodeWithDimensions,Z as $createTableRowNode,Ee as $createTableSelection,pe as $deleteTableColumn,Se as $deleteTableColumn__EXPERIMENTAL,Ce as $deleteTableRow__EXPERIMENTAL,Ze as $getElementForTableNode,Ne as $getNodeTriplet,re as $getTableCellNodeFromLexicalNode,xe as $getTableCellNodeRect,ae as $getTableColumnIndexFromTableCellNode,se as $getTableNodeFromLexicalNodeOrThrow,ie as $getTableRowIndexFromTableCellNode,le as $getTableRowNodeFromTableCellNodeOrThrow,fe as $insertTableColumn,me as $insertTableColumn__EXPERIMENTAL,de as $insertTableRow,ge as $insertTableRow__EXPERIMENTAL,q as $isTableCellNode,nt as $isTableNode,ee as $isTableRowNode,ve as $isTableSelection,he as $removeTableRowAtIndex,be as $unmergeCell,G as INSERT_TABLE_COMMAND,Y as TableCellHeaderStates,J as TableCellNode,Ve as TableNode,Me as TableObserver,Q as TableRowNode,ke as applyTableHandlers,He as getDOMCellFromTarget,Fe as getTableObserverFromTableElement};
8
+
9
+ import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,isHTMLElement as o}from"@lexical/utils";import{ElementNode as r,$createParagraphNode as l,$isElementNode as s,$isLineBreakNode as i,$isTextNode as a,$applyNodeReplacement as c,createCommand as h,$createTextNode as d,$getSelection as u,$isRangeSelection as g,$createPoint as f,$normalizeSelection__EXPERIMENTAL as m,$getNodeByKey as p,isCurrentlyReadOnlyMode as S,$setSelection as C,SELECTION_CHANGE_COMMAND as _,$getNearestNodeFromDOMNode as w,$createRangeSelection as b,$getRoot as y,KEY_ARROW_DOWN_COMMAND as N,COMMAND_PRIORITY_HIGH as T,KEY_ARROW_UP_COMMAND as x,KEY_ARROW_LEFT_COMMAND as v,KEY_ARROW_RIGHT_COMMAND as E,KEY_ESCAPE_COMMAND as O,DELETE_WORD_COMMAND as M,DELETE_LINE_COMMAND as R,DELETE_CHARACTER_COMMAND as K,COMMAND_PRIORITY_CRITICAL as k,KEY_BACKSPACE_COMMAND as F,KEY_DELETE_COMMAND as A,FORMAT_TEXT_COMMAND as H,FORMAT_ELEMENT_COMMAND as P,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as D,FOCUS_COMMAND as L,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as z}from"lexical";const X=/^(\d+(?:\.\d+)?)px$/,Y={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class J extends r{static getType(){return"tablecell"}static clone(e){const t=new J(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:$,priority:0}),th:e=>({conversion:$,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=j(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=Y.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t,n=700,o=this.getParentOrThrow().getChildrenSize();e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||Math.max(90,n/o)}px`,e.style.verticalAlign="top",e.style.textAlign="start";const r=this.getBackgroundColor();null!==r?e.style.backgroundColor=r:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){return this.getWritable().__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){return this.getWritable().__width=e,this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Y.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function $(e){const t=e,n=e.nodeName.toLowerCase();let o;X.test(t.style.width)&&(o=parseFloat(t.style.width));const r=j("th"===n?Y.ROW:Y.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const c=t.style.backgroundColor;""!==c&&(r.__backgroundColor=c);const h=t.style,d=h.textDecoration.split(" "),u="700"===h.fontWeight||"bold"===h.fontWeight,g=d.includes("line-through"),f="italic"===h.fontStyle,m=d.includes("underline");return{after:e=>(0===e.length&&e.push(l()),e),forChild:(e,t)=>{if(q(t)&&!s(e)){const t=l();return i(e)&&"\n"===e.getTextContent()?null:(a(e)&&(u&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function j(e,t=1,n){return c(new J(e,t,n))}function q(e){return e instanceof J}const G=h("INSERT_TABLE_COMMAND");class Q extends r{static getType(){return"tablerow"}static clone(e){return new Q(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:V,priority:0})}}static importJSON(e){return Z(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function V(e){const t=e;let n;return X.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:Z(n)}}function Z(e){return c(new Q(e))}function ee(e){return e instanceof Q}function te(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ne=te((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const oe="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function re(e,t,n=!0){const o=ot();for(let r=0;r<e;r++){const e=Z();for(let o=0;o<t;o++){let t=Y.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Y.ROW),0===o&&n.columns&&(t|=Y.COLUMN)):n&&(0===r&&(t|=Y.ROW),0===o&&(t|=Y.COLUMN));const s=j(t),i=l();i.append(d()),s.append(i),e.append(s)}o.append(e)}return o}function le(e){const n=t(e,(e=>q(e)));return q(n)?n:null}function se(e){const n=t(e,(e=>ee(e)));if(ee(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ie(e){const n=t(e,(e=>rt(e)));if(rt(n))return n;throw new Error("Expected table cell to be inside of table.")}function ae(e){const t=se(e);return ie(t).getChildren().findIndex((e=>e.is(t)))}function ce(e){return se(e).getChildren().findIndex((t=>t.is(e)))}function he(e,t){const n=ie(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function de(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function ue(e,t,n=!0,o,r){const s=e.getChildren();if(t>=s.length||t<0)throw new Error("Table row target index out of range");const i=s[t];if(!ee(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=Z();for(let n=0;n<t;n++){const t=e[n];q(t)||ne(12);const{above:s,below:i}=he(t,r);let a=Y.NO_STATUS;const c=s&&s.getWidth()||i&&i.getWidth()||void 0;(s&&s.hasHeaderState(Y.COLUMN)||i&&i.hasHeaderState(Y.COLUMN))&&(a|=Y.COLUMN);const h=j(a,1,c);h.append(l()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const ge=(e,t)=>e===Y.BOTH||e===t?t:Y.NO_STATUS;function fe(e=!0){const t=u();g(t)||Oe(t)||ne(118);const n=t.focus.getNode(),[o,,r]=xe(n),[s,i]=Ne(r,o,o),a=s[0].length,{startRow:c}=i;if(e){const e=c+o.__rowSpan-1,t=s[e],n=Z();for(let o=0;o<a;o++){const{cell:r,startRow:s}=t[o];if(s+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=ge(e,Y.COLUMN);n.append(j(r).append(l()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ee(i)||ne(145),i.insertAfter(n)}else{const e=s[c],t=Z();for(let n=0;n<a;n++){const{cell:o,startRow:r}=e[n];if(r===c){const o=e[n].cell.__headerState,r=ge(o,Y.COLUMN);t.append(j(r).append(l()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(c);ee(n)||ne(145),n.insertBefore(t)}}function me(e,t,n=!0,o,r){const s=e.getChildren(),i=[];for(let e=0;e<s.length;e++){const n=s[e];if(ee(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];q(o)||ne(12);const{left:s,right:a}=he(o,r);let c=Y.NO_STATUS;(s&&s.hasHeaderState(Y.ROW)||a&&a.hasHeaderState(Y.ROW))&&(c|=Y.ROW);const h=j(c);h.append(l()),i.push({newTableCell:h,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function pe(e=!0){const t=u();g(t)||Oe(t)||ne(118);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=xe(n),[s,,i]=xe(o),[a,c,h]=Ne(i,s,r),d=a.length,f=e?Math.max(c.startColumn,h.startColumn):Math.min(c.startColumn,h.startColumn),m=e?f+s.__colSpan-1:f-1,p=i.getFirstChild();ee(p)||ne(120);let S=null;function C(e=Y.NO_STATUS){const t=j(e).append(l());return null===S&&(S=t),t}let _=p;e:for(let e=0;e<d;e++){if(0!==e){const e=_.getNextSibling();ee(e)||ne(121),_=e}const t=a[e],n=t[m<0?0:m].cell.__headerState,o=ge(n,Y.ROW);if(m<0){be(_,C(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(C(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(C(o))}else r.setColSpan(r.__colSpan+1)}null!==S&&we(S)}function Se(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ee(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function Ce(){const e=u();g(e)||Oe(e)||ne(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=xe(t),[l]=xe(n),[s,i,a]=Ne(r,o,l),{startRow:c}=i,{startRow:h}=a,d=h+l.__rowSpan-1;if(s.length===d-c+1)return void r.remove();const f=s[0].length,m=s[d+1],p=r.getChildAtIndex(d+1);for(let e=d;e>=c;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===c&&o<c&&n.setRowSpan(n.__rowSpan-(o-c)),o>=c&&o+n.__rowSpan-1>d))if(n.setRowSpan(n.__rowSpan-(d-o+1)),null===p&&ne(122),0===t)be(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ee(t)||ne(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];we(e)}else{const e=s[c-1],{cell:t}=e[0];we(t)}}function _e(){const e=u();g(e)||Oe(e)||ne(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=xe(t),[l]=xe(n),[s,i,a]=Ne(r,o,l),{startColumn:c}=i,{startRow:h,startColumn:d}=a,f=Math.min(c,d),m=Math.max(c+o.__colSpan-1,d+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const S=s.length;for(let e=0;e<S;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const C=s[h],_=C[d+l.__colSpan];if(void 0!==_){const{cell:e}=_;we(e)}else{const e=C[d-1],{cell:t}=e;we(t)}}function we(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function be(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function ye(){const e=u();g(e)||Oe(e)||ne(118);const t=e.anchor.getNode(),[n,o,r]=xe(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(j(Y.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=Ne(r,n,n),{startColumn:i,startRow:a}=t;let c;for(let t=1;t<s;t++){const n=a+t,r=e[n];c=(c||o).getNextSibling(),ee(c)||ne(125);let s=null;for(let e=0;e<i;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let e=0;e<l;e++)be(c,j(Y.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(j(Y.NO_STATUS))}n.setRowSpan(1)}}function Ne(e,t,n){const[o,r,l]=Te(e,t,n);return null===r&&ne(110),null===l&&ne(111),[o,r,l]}function Te(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const a={cell:i,startColumn:s,startRow:e},c=i.__rowSpan,h=i.__colSpan;for(let t=0;t<c;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<h;n++)o[e+t][s+n]=a}null!==t&&t.is(i)&&(r=a),null!==n&&n.is(i)&&(l=a)}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const a=e.getChildren();for(let e=0;e<a.length;e++){const t=a[e];ee(t)||ne(146);const n=t.getChildren();let o=0;for(const t of n){for(q(t)||ne(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function xe(e){let n;if(e instanceof J)n=e;else if("__type"in e){const o=t(e,q);q(o)||ne(148),n=o}else{const o=t(e.getNode(),q);q(o)||ne(148),n=o}const o=n.getParent();ee(o)||ne(149);const r=o.getParent();return rt(r)||ne(150),[n,o,r]}function ve(e){const[t,,n]=xe(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}class Ee{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!Oe(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Ee(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();s(t)||ne(151);m(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=p(this.anchor.key);q(e)||ne(152);const t=ve(e);null===t&&ne(153);const n=p(this.focus.key);q(n)||ne(154);const o=ve(n);null===o&&ne(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex,o.columnIndex),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex,o.rowIndex);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,q),l=t(o,q);q(r)||ne(152),q(l)||ne(154);const s=r.getParent();ee(s)||ne(156);const i=s.getParent();rt(i)||ne(157);const a=l.getParents()[1];if(a!==i){if(i.isParentOf(l)){const e=a.getParent();null==e&&ne(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&ne(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[c,h,d]=Ne(i,r,l);let u=Math.min(h.startColumn,d.startColumn),g=Math.min(h.startRow,d.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,d.startColumn+d.cell.__colSpan-1),m=Math.max(h.startRow+h.cell.__rowSpan-1,d.startRow+d.cell.__rowSpan-1),p=u,C=g,_=u,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;u=Math.min(u,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1)}for(;u<p||g<C||f>_||m>w;){if(u<p){const e=w-C,t=p-1;for(let n=0;n<=e;n++)b(c[C+n][t]);p=t}if(g<C){const e=_-p,t=C-1;for(let n=0;n<=e;n++)b(c[t][p+n]);C=t}if(f>_){const e=w-C,t=_+1;for(let n=0;n<=e;n++)b(c[C+n][t]);_=t}if(m>w){const e=_-p,t=w+1;for(let n=0;n<=e;n++)b(c[t][p+n]);w=t}}const y=[i];let N=null;for(let e=g;e<=m;e++)for(let t=u;t<=f;t++){const{cell:n}=c[e][t],o=n.getParent();ee(o)||ne(160),o!==N&&y.push(o),y.push(n,...Re(n)),N=o}return S()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function Oe(e){return e instanceof Ee}function Me(){const e=f("root",0,"element"),t=f("root",0,"element");return new Ee("root",e,t)}function Re(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&ne(112),s(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class Ke{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.trackTable(),this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach((e=>e()))}trackTable(){const e=new MutationObserver((e=>{this.editor.update((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TR"===o){t=!0;break}}if(!t)return;const n=this.editor.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");this.table=Be(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Be(t),e.observe(t,{childList:!0,subtree:!0})}))}clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),e.update((()=>{if(!rt(p(this.tableNodeKey)))throw new Error("Expected TableNode.");const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");const n=Be(t);De(e,n,null),C(null),e.dispatchCommand(_,void 0)}))}enableHighlightStyle(){const e=this.editor;e.update((()=>{const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}))}disableHighlightStyle(){const t=this.editor;t.update((()=>{const n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}))}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),De(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const o=p(this.tableNodeKey);if(!rt(o))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");const r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=Fe(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=w(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&q(t)&&o.is(qe(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Me(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),C(this.tableSelection),n.dispatchCommand(_,void 0),De(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=w(e.elem);if(q(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Me(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=u();Oe(t)||ne(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{q(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),C(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=p(this.tableNodeKey);if(!rt(t))throw new Error("Expected TableNode.");const n=u();Oe(n)||ne(11);const o=n.getNodes().filter(q);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(s(e)){const t=l(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),De(e,this.table,null),C(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const ke="__lexicalTableSelection",Fe=e=>oe?(e||window).getSelection():null;function Ae(e,n,o,r){const i=o.getRootElement();if(null===i)throw new Error("No root element.");const c=new Ke(o,e.getKey()),h=o._window||window;!function(e,t){e[ke]=t}(n,c);const f=()=>{const e=()=>{c.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&c.isSelecting)return c.isSelecting=!1,h.removeEventListener("mouseup",e),void h.removeEventListener("mousemove",t);const o=Pe(n.target);null===o||c.anchorX===o.x&&c.anchorY===o.y||(n.preventDefault(),c.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=Pe(e.target);null!==t&&(Qe(e),c.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();c.isSelecting=!0,h.addEventListener("mouseup",n),h.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=u(),n=e.target;Oe(t)&&t.tableKey===c.tableNodeKey&&i.contains(n)&&c.clearHighlight()}))};h.addEventListener("mousedown",m),c.listenersToRemove.add((()=>h.removeEventListener("mousedown",m))),c.listenersToRemove.add(o.registerCommand(N,(t=>Ge(o,t,"down",e,c)),T)),c.listenersToRemove.add(o.registerCommand(x,(t=>Ge(o,t,"up",e,c)),T)),c.listenersToRemove.add(o.registerCommand(v,(t=>Ge(o,t,"backward",e,c)),T)),c.listenersToRemove.add(o.registerCommand(E,(t=>Ge(o,t,"forward",e,c)),T)),c.listenersToRemove.add(o.registerCommand(O,(e=>{const n=u();if(Oe(n)){const o=t(n.focus.getNode(),q);if(q(o))return Qe(e),o.selectEnd(),!0}return!1}),T));[M,R,K].forEach((n=>{c.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=u();if(!ze(o,e))return!1;if(Oe(o))return c.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>q(e)));if(!q(r))return!1;const l=o.anchor.getNode(),i=o.focus.getNode(),a=e.isParentOf(l),h=e.isParentOf(i);if(a&&!h||h&&!a)return c.clearText(),!0;const d=t(o.anchor.getNode(),(e=>s(e))),u=d&&t(d,(e=>s(e)&&q(e.getParent())));if(!s(u)||!s(d))return!1;if(n===R&&null===u.getPreviousSibling())return!0}return!1})(n),k))}));const p=n=>{const o=u();if(!ze(o,e))return!1;if(Oe(o))return n.preventDefault(),n.stopPropagation(),c.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>q(e)));if(!q(e))return!1}return!1};function S(t){const n=e.getCordsFromCellNode(t,c.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,c.table)}return c.listenersToRemove.add(o.registerCommand(F,p,k)),c.listenersToRemove.add(o.registerCommand(A,p,k)),c.listenersToRemove.add(o.registerCommand(H,(n=>{const o=u();if(!ze(o,e))return!1;if(Oe(o))return c.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>q(e)));if(!q(e))return!1}return!1}),k)),c.listenersToRemove.add(o.registerCommand(P,(t=>{const n=u();if(!Oe(n)||!ze(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!q(o)||!q(r))return!1;const[l,i,a]=Ne(e,o,r),c=Math.max(i.startRow,a.startRow),h=Math.max(i.startColumn,a.startColumn),d=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn);for(let e=d;e<=c;e++)for(let n=g;n<=h;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];s(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),k)),c.listenersToRemove.add(o.registerCommand(B,(n=>{const r=u();if(!ze(r,e))return!1;if(Oe(r))return c.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>q(e)));if(!q(l))return!1;if("string"==typeof n){const t=Ze(o,r,e);if(t)return Ve(t,e,[d(n)]),!0}}return!1}),k)),r&&c.listenersToRemove.add(o.registerCommand(D,(t=>{const n=u();if(!g(n)||!n.isCollapsed()||!ze(n,e))return!1;const o=je(n.anchor.getNode());if(null===o)return!1;Qe(t);const r=e.getCordsFromCellNode(o,c.table);return We(c,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),k)),c.listenersToRemove.add(o.registerCommand(L,(t=>e.isSelected()),T)),c.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),s=Oe(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>q(e)))&&null!==t(o.focus.getNode(),(e=>q(e)))||s;if(1!==n.length||!rt(n[0])||!i||null===r)return!1;const[c]=r,h=n[0],d=h.getChildren(),u=h.getFirstChildOrThrow().getChildrenSize(),f=h.getChildrenSize(),m=t(c.getNode(),(e=>q(e))),p=m&&t(m,(e=>ee(e))),S=p&&t(p,(e=>rt(e)));if(!q(m)||!ee(p)||!rt(S))return!1;const _=p.getIndexWithinParent(),w=Math.min(S.getChildrenSize()-1,_+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+u-1),N=Math.min(b,y),T=Math.min(_,w),x=Math.max(b,y),v=Math.max(_,w),E=S.getChildren();let O,M,R=0;for(let e=T;e<=v;e++){const t=E[e];if(!ee(t))return!1;const n=d[R];if(!ee(n))return!1;const o=t.getChildren(),r=n.getChildren();let s=0;for(let t=N;t<=x;t++){const n=o[t];if(!q(n))return!1;const i=r[s];if(!q(i))return!1;e===T&&t===N?O=n.getKey():e===v&&t===x&&(M=n.getKey());const c=n.getChildren();i.getChildren().forEach((e=>{if(a(e)){l().append(e),n.append(e)}else n.append(e)})),c.forEach((e=>e.remove())),s++}R++}if(O&&M){const e=Me();e.set(n[0].getKey(),O,M),C(e)}return!0}),k)),c.listenersToRemove.add(o.registerCommand(_,(()=>{const t=u(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=je(l),a=je(s),d=!(!i||!e.is(qe(i))),u=!(!a||!e.is(qe(a))),g=d!==u,m=d&&u,p=t.isBackward();if(g){const n=t.clone();u?n.focus.set(e.getParentOrThrow().getKey(),e.getIndexWithinParent(),"element"):n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element"),C(n),Ie(o,c)}else m&&(i.is(a)||(c.setAnchorCellForSelection(S(i)),c.setFocusCellForSelection(S(a),!0),c.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();c.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&Oe(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Fe(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is(qe(r)),s=w(n.anchorNode),i=s&&e.is(qe(s));if(l&&i&&n.rangeCount>0){const r=U(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),C(r))}}}return t&&!t.is(n)&&(Oe(t)||Oe(n))&&c.tableSelection&&!c.tableSelection.is(n)?(Oe(t)&&t.tableKey===c.tableNodeKey?c.updateTableTableSelection(t):!Oe(t)&&Oe(n)&&n.tableKey===c.tableNodeKey&&c.updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Le(t.table,(t=>{const n=t.elem;t.highlighted=!1,$e(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Ie(o,c),!1)}),k)),c.listenersToRemove.add(o.registerCommand(z,(()=>{const t=u();if(!g(t)||!t.isCollapsed()||!ze(t,e))return!1;const n=Ze(o,t,e);return!!n&&(Ve(n,e),!0)}),k)),c}function He(e){return e[ke]}function Pe(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function Be(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.firstChild,r=0,l=0;for(t.length=0;null!=o;){const e=o.nodeName;if("TD"===e||"TH"===e){const e={elem:o,hasBackgroundColor:""!==o.style.backgroundColor,highlighted:!1,x:r,y:l};o._cell=e;let n=t[l];void 0===n&&(n=t[l]=[]),n[r]=e}else{const e=o.firstChild;if(null!=e){o=e;continue}}const n=o.nextSibling;if(null!=n){r++,o=n;continue}const s=o.parentNode;if(null!=s){const e=s.nextSibling;if(null==e)break;l++,r=0,o=e}}return n.columns=r+1,n.rows=l+1,n}function De(e,t,n){const o=new Set(n?n.getNodes():[]);Le(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Je(e,t)):(t.highlighted=!1,$e(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Le(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=w(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ie(e,t){t.disableHighlightStyle(),Le(t.table,(t=>{t.highlighted=!0,Je(e,t)}))}const We=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Xe(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Xe(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Xe(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Xe(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ue=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function ze(e,t){if(g(e)||Oe(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Xe(e,t){t?e.selectStart():e.selectEnd()}const Ye="172,206,247";function Je(e,t){const n=t.elem,o=w(n);q(o)||ne(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Ye})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Ye},0.85), rgba(${Ye},0.85))`),n.style.setProperty("caret-color","transparent")}function $e(e,t){const n=t.elem,o=w(n);q(o)||ne(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function je(e){const n=t(e,q);return q(n)?n:null}function qe(e){const n=t(e,rt);return rt(n)?n:null}function Ge(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=u();if(!ze(i,r)){if("backward"===o&&g(i)&&i.isCollapsed()){const e=i.anchor.type,o=i.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=i.anchor.getNode();if(!r)return!1;const l=t(r,(e=>s(e)&&!e.isInline()));if(!l)return!1;const a=l.getPreviousSibling();return!(!a||!rt(a))&&(Qe(n),a.selectEnd(),!0)}return!1}if(g(i)&&i.isCollapsed()){const{anchor:a,focus:c}=i,h=t(a.getNode(),q),d=t(c.getNode(),q);if(!q(h)||!h.is(d))return!1;const u=qe(h);if(u!==r&&null!=u){const t=e.getElementByKey(u.getKey());if(null!=t)return l.table=Be(t),Ge(e,n,o,u,l)}if("backward"===o||"forward"===o){const e=a.type,l=a.offset,i=a.getNode();return!!i&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>s(e)&&!e.isInline()));if(!l)return!1;const i="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&i&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,i,o)&&function(e,n,o,r){const l=t(n,q);if(!q(l))return!1;const[i,a]=Ne(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(i,a,r))return!1;const c=function(e,n,o){const r=t(e,(e=>s(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&rt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!c||rt(c))return!1;Qe(e),"backward"===r?c.selectEnd():c.selectStart();return!0}(n,i,r,o))}const g=e.getElementByKey(h.__key),f=e.getElementByKey(a.key);if(null==f||null==g)return!1;let m;if("element"===a.type)m=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;m=e.getRangeAt(0).getBoundingClientRect()}const p="up"===o?h.getFirstChild():h.getLastChild();if(null==p)return!1;const S=e.getElementByKey(p.__key);if(null==S)return!1;const C=S.getBoundingClientRect();if("up"===o?C.top>m.top-m.height:m.bottom+m.height>C.bottom){Qe(n);const e=r.getCordsFromCellNode(h,l.table);if(!n.shiftKey)return We(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.setAnchorCellForSelection(t),l.setFocusCellForSelection(t,!0)}return!0}}else if(Oe(i)){const{anchor:s,focus:a}=i,c=t(s.getNode(),q),h=t(a.getNode(),q),[d]=i.getNodes(),u=e.getElementByKey(d.getKey());if(!q(c)||!q(h)||!rt(d)||null==u)return!1;l.updateTableTableSelection(i);const g=Be(u),f=r.getCordsFromCellNode(c,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Qe(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return Ue(l,d,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function Qe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ve(e,t,n){const o=l();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Ze(e,n,o){const r=window.getSelection();if(!r||r.anchorNode!==e.getRootElement())return;const l=t(n.anchor.getNode(),(e=>q(e)));if(!l)return;const s=t(l,(e=>rt(e)));if(!rt(s)||!s.is(o))return;const[i,a]=Ne(o,l,l),c=i[0][0],h=i[i.length-1][i[0].length-1],{startRow:d,startColumn:u}=a,g=d===c.startRow&&u===c.startColumn,f=d===h.startRow&&u===h.startColumn;return g?"first":f?"last":void 0}class et extends r{static getType(){return"table"}static clone(e){return new et(e.__key)}static importDOM(){return{table:e=>({conversion:nt,priority:1})}}static importJSON(e){return ot()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(o,t.theme.table),o}updateDOM(){return!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!ee(l))throw new Error("Expected to find row node.");const s=l.getChildrenSize();for(let e=0;e<s;e++){const e=document.createElement("col");n.append(e)}return t.replaceChildren(n,r),t}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return w(n)===e}));if(-1!==r)return{x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=w(o.elem);return q(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}canSelectBefore(){return!0}canIndent(){return!1}}function tt(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Be(n)}function nt(e){return{node:ot()}}function ot(){return c(new et)}function rt(e){return e instanceof et}export{Ne as $computeTableMap,Te as $computeTableMapSkipCellCheck,j as $createTableCellNode,ot as $createTableNode,re as $createTableNodeWithDimensions,Z as $createTableRowNode,Me as $createTableSelection,Se as $deleteTableColumn,_e as $deleteTableColumn__EXPERIMENTAL,Ce as $deleteTableRow__EXPERIMENTAL,tt as $getElementForTableNode,xe as $getNodeTriplet,le as $getTableCellNodeFromLexicalNode,ve as $getTableCellNodeRect,ce as $getTableColumnIndexFromTableCellNode,ie as $getTableNodeFromLexicalNodeOrThrow,ae as $getTableRowIndexFromTableCellNode,se as $getTableRowNodeFromTableCellNodeOrThrow,me as $insertTableColumn,pe as $insertTableColumn__EXPERIMENTAL,ue as $insertTableRow,fe as $insertTableRow__EXPERIMENTAL,q as $isTableCellNode,rt as $isTableNode,ee as $isTableRowNode,Oe as $isTableSelection,de as $removeTableRowAtIndex,ye as $unmergeCell,G as INSERT_TABLE_COMMAND,Y as TableCellHeaderStates,J as TableCellNode,et as TableNode,Ke as TableObserver,Q as TableRowNode,Ae as applyTableHandlers,Pe as getDOMCellFromTarget,He as getTableObserverFromTableElement};
@@ -61,6 +61,6 @@ export declare class TableCellNode extends ElementNode {
61
61
  canBeEmpty(): false;
62
62
  canIndent(): false;
63
63
  }
64
- export declare function convertTableCellNodeElement(domNode: Node): DOMConversionOutput;
64
+ export declare function $convertTableCellNodeElement(domNode: Node): DOMConversionOutput;
65
65
  export declare function $createTableCellNode(headerState: TableCellHeaderState, colSpan?: number, width?: number): TableCellNode;
66
66
  export declare function $isTableCellNode(node: LexicalNode | null | undefined): node is TableCellNode;
@@ -35,6 +35,6 @@ export declare class TableNode extends ElementNode {
35
35
  canIndent(): false;
36
36
  }
37
37
  export declare function $getElementForTableNode(editor: LexicalEditor, tableNode: TableNode): TableDOMTable;
38
- export declare function convertTableElement(_domNode: Node): DOMConversionOutput;
38
+ export declare function $convertTableElement(_domNode: Node): DOMConversionOutput;
39
39
  export declare function $createTableNode(): TableNode;
40
40
  export declare function $isTableNode(node: LexicalNode | null | undefined): node is TableNode;
@@ -28,6 +28,6 @@ export declare class TableRowNode extends ElementNode {
28
28
  canBeEmpty(): false;
29
29
  canIndent(): false;
30
30
  }
31
- export declare function convertTableRowElement(domNode: Node): DOMConversionOutput;
31
+ export declare function $convertTableRowElement(domNode: Node): DOMConversionOutput;
32
32
  export declare function $createTableRowNode(height?: number): TableRowNode;
33
33
  export declare function $isTableRowNode(node: LexicalNode | null | undefined): node is TableRowNode;
@@ -36,6 +36,7 @@ export declare function $deleteTableRow__EXPERIMENTAL(): void;
36
36
  export declare function $deleteTableColumn__EXPERIMENTAL(): void;
37
37
  export declare function $unmergeCell(): void;
38
38
  export declare function $computeTableMap(grid: TableNode, cellA: TableCellNode, cellB: TableCellNode): [TableMapType, TableMapValueType, TableMapValueType];
39
+ export declare function $computeTableMapSkipCellCheck(grid: TableNode, cellA: null | TableCellNode, cellB: null | TableCellNode): [TableMapType, TableMapValueType | null, TableMapValueType | null];
39
40
  export declare function $getNodeTriplet(source: PointType | LexicalNode | TableCellNode): [TableCellNode, TableRowNode, TableNode];
40
41
  export declare function $getTableCellNodeRect(tableCellNode: TableCellNode): {
41
42
  rowIndex: number;
package/index.d.ts CHANGED
@@ -19,4 +19,4 @@ export type { TableSelection, TableSelectionShape, } from './LexicalTableSelecti
19
19
  export { $createTableSelection, $isTableSelection, } from './LexicalTableSelection';
20
20
  export type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
21
21
  export { applyTableHandlers, getDOMCellFromTarget, getTableObserverFromTableElement, } from './LexicalTableSelectionHelpers';
22
- export { $computeTableMap, $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
22
+ export { $computeTableMap, $computeTableMapSkipCellCheck, $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.14.4",
11
+ "version": "0.15.0",
12
12
  "main": "LexicalTable.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.14.4",
16
- "lexical": "0.14.4"
15
+ "@lexical/utils": "0.15.0",
16
+ "lexical": "0.15.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",