@lexical/table 0.11.1 → 0.11.3

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.
@@ -501,6 +501,7 @@ class TableSelection {
501
501
  throw new Error('Expected to find TableElement in DOM');
502
502
  }
503
503
 
504
+ utils.removeClassNamesFromElement(tableElement, editor._config.theme.tableSelection);
504
505
  tableElement.classList.remove('disable-selection');
505
506
  this.hasHijackedSelectionStyles = false;
506
507
  });
@@ -515,7 +516,7 @@ class TableSelection {
515
516
  throw new Error('Expected to find TableElement in DOM');
516
517
  }
517
518
 
518
- tableElement.classList.add('disable-selection');
519
+ utils.addClassNamesToElement(tableElement, editor._config.theme.tableSelection);
519
520
  this.hasHijackedSelectionStyles = true;
520
521
  });
521
522
  }
@@ -683,7 +684,7 @@ class TableSelection {
683
684
  *
684
685
  */
685
686
  const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
686
- function applyTableHandlers(tableNode, tableElement, editor) {
687
+ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
687
688
  const rootElement = editor.getRootElement();
688
689
 
689
690
  if (rootElement === null) {
@@ -691,65 +692,42 @@ function applyTableHandlers(tableNode, tableElement, editor) {
691
692
  }
692
693
 
693
694
  const tableSelection = new TableSelection(editor, tableNode.getKey());
695
+ const editorWindow = editor._window || window;
694
696
  attachTableSelectionToTableElement(tableElement, tableSelection);
695
- let isMouseDown = false;
696
- let isRangeSelectionHijacked = false;
697
- tableElement.addEventListener('dblclick', event => {
698
- const cell = getCellFromTarget(event.target);
699
-
700
- if (cell !== null) {
701
- event.preventDefault();
702
- event.stopImmediatePropagation();
703
- event.stopPropagation();
704
- tableSelection.setAnchorCellForSelection(cell);
705
- tableSelection.setFocusCellForSelection(cell, true);
706
- isMouseDown = false;
707
- }
708
- }); // This is the anchor of the selection.
709
-
710
697
  tableElement.addEventListener('mousedown', event => {
711
698
  setTimeout(() => {
712
699
  if (event.button !== 0) {
713
700
  return;
714
701
  }
715
702
 
716
- const cell = getCellFromTarget(event.target);
717
-
718
- if (cell !== null) {
719
- event.preventDefault();
720
- event.stopPropagation();
721
- event.stopImmediatePropagation();
722
- tableSelection.setAnchorCellForSelection(cell);
703
+ if (!editorWindow) {
704
+ return;
723
705
  }
724
- }, 0);
725
- }); // This is adjusting the focus of the selection.
726
706
 
727
- tableElement.addEventListener('mousemove', event => {
728
- if (isRangeSelectionHijacked) {
729
- event.preventDefault();
730
- event.stopPropagation();
731
- event.stopImmediatePropagation();
732
- }
707
+ const anchorCell = getCellFromTarget(event.target);
708
+
709
+ if (anchorCell !== null) {
710
+ stopEvent(event);
711
+ tableSelection.setAnchorCellForSelection(anchorCell);
712
+ }
733
713
 
734
- if (isMouseDown) {
735
- const cell = getCellFromTarget(event.target);
714
+ const onMouseUp = () => {
715
+ editorWindow.removeEventListener('mouseup', onMouseUp);
716
+ editorWindow.removeEventListener('mousemove', onMouseMove);
717
+ };
736
718
 
737
- if (cell !== null) {
738
- const cellX = cell.x;
739
- const cellY = cell.y;
719
+ const onMouseMove = moveEvent => {
720
+ const focusCell = getCellFromTarget(moveEvent.target);
740
721
 
741
- if (isMouseDown && (tableSelection.anchorX !== cellX || tableSelection.anchorY !== cellY || tableSelection.isHighlightingCells)) {
742
- event.preventDefault();
743
- tableSelection.setFocusCellForSelection(cell);
722
+ if (focusCell !== null && (tableSelection.anchorX !== focusCell.x || tableSelection.anchorY !== focusCell.y)) {
723
+ moveEvent.preventDefault();
724
+ tableSelection.setFocusCellForSelection(focusCell);
744
725
  }
745
- }
746
- }
747
- }); // Select entire table at this point, when grid selection is ready.
726
+ };
748
727
 
749
- tableElement.addEventListener('mouseleave', () => {
750
- if (isMouseDown) {
751
- return;
752
- }
728
+ editorWindow.addEventListener('mouseup', onMouseUp);
729
+ editorWindow.addEventListener('mousemove', onMouseMove);
730
+ }, 0);
753
731
  }); // Clear selection when clicking outside of dom.
754
732
 
755
733
  const mouseDownCallback = event => {
@@ -761,251 +739,29 @@ function applyTableHandlers(tableNode, tableElement, editor) {
761
739
  const selection = lexical.$getSelection();
762
740
  const target = event.target;
763
741
 
764
- if (target instanceof Node) {
765
- if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(target)) {
766
- return tableSelection.clearHighlight();
767
- } // TODO Revise this logic; the UX selection boundaries and nested editors
768
-
769
-
770
- const node = lexical.$getNearestNodeFromDOMNode(target);
771
-
772
- if (node !== null && utils.$findMatchingParent(node, lexical.DEPRECATED_$isGridNode)) {
773
- isMouseDown = true;
774
- }
742
+ if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(target)) {
743
+ tableSelection.clearHighlight();
775
744
  }
776
745
  });
777
746
  };
778
747
 
779
- window.addEventListener('mousedown', mouseDownCallback);
780
- tableSelection.listenersToRemove.add(() => window.removeEventListener('mousedown', mouseDownCallback));
781
-
782
- const mouseUpCallback = event => {
783
- if (isMouseDown && !doesTargetContainText(event.target)) {
784
- event.preventDefault();
785
- event.stopPropagation();
786
- }
787
-
788
- isMouseDown = false;
789
- };
790
-
791
- window.addEventListener('mouseup', mouseUpCallback);
792
- tableSelection.listenersToRemove.add(() => window.removeEventListener('mouseup', mouseUpCallback));
793
- tableElement.addEventListener('mouseup', mouseUpCallback);
794
- tableSelection.listenersToRemove.add(() => tableElement.removeEventListener('mouseup', mouseUpCallback));
795
- tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {
796
- const selection = lexical.$getSelection();
797
-
798
- if (!$isSelectionInTable(selection, tableNode)) {
799
- return false;
800
- }
801
-
802
- const direction = 'down';
803
-
804
- if (lexical.$isRangeSelection(selection)) {
805
- if (selection.isCollapsed()) {
806
- const tableCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => $isTableCellNode(n));
807
-
808
- if (!$isTableCellNode(tableCellNode)) {
809
- return false;
810
- }
811
-
812
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
813
- const elementParentNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isElementNode(n));
814
-
815
- if (elementParentNode == null) {
816
- throw new Error('Expected BlockNode Parent');
817
- }
818
-
819
- const lastChild = tableCellNode.getLastChild();
820
- const isSelectionInLastBlock = lastChild && elementParentNode.isParentOf(lastChild) || elementParentNode === lastChild;
821
-
822
- if (isSelectionInLastBlock || event.shiftKey) {
823
- event.preventDefault();
824
- event.stopImmediatePropagation();
825
- event.stopPropagation(); // Start Selection
826
-
827
- if (event.shiftKey) {
828
- tableSelection.setAnchorCellForSelection(tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid));
829
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
830
- }
831
-
832
- return selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
833
- }
834
- }
835
- } else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
836
- const tableCellNode = selection.focus.getNode();
837
-
838
- if (!$isTableCellNode(tableCellNode)) {
839
- return false;
840
- }
841
-
842
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
843
- event.preventDefault();
844
- event.stopImmediatePropagation();
845
- event.stopPropagation();
846
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
847
- }
848
-
849
- return false;
850
- }, lexical.COMMAND_PRIORITY_HIGH));
851
- tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => {
748
+ editorWindow.addEventListener('mousedown', mouseDownCallback);
749
+ tableSelection.listenersToRemove.add(() => editorWindow.removeEventListener('mousedown', mouseDownCallback));
750
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => $handleArrowKey(editor, event, 'down', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
751
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => $handleArrowKey(editor, event, 'up', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
752
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, event => $handleArrowKey(editor, event, 'backward', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
753
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => $handleArrowKey(editor, event, 'forward', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
754
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, event => {
852
755
  const selection = lexical.$getSelection();
853
756
 
854
- if (!$isSelectionInTable(selection, tableNode)) {
855
- return false;
856
- }
857
-
858
- const direction = 'up';
859
-
860
- if (lexical.$isRangeSelection(selection)) {
861
- if (selection.isCollapsed()) {
862
- const tableCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => $isTableCellNode(n));
863
-
864
- if (!$isTableCellNode(tableCellNode)) {
865
- return false;
866
- }
867
-
868
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
869
- const elementParentNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isElementNode(n));
870
-
871
- if (elementParentNode == null) {
872
- throw new Error('Expected BlockNode Parent');
873
- }
874
-
875
- const lastChild = tableCellNode.getLastChild();
876
- const isSelectionInLastBlock = lastChild && elementParentNode.isParentOf(lastChild) || elementParentNode === lastChild;
877
-
878
- if (isSelectionInLastBlock || event.shiftKey) {
879
- event.preventDefault();
880
- event.stopImmediatePropagation();
881
- event.stopPropagation(); // Start Selection
882
-
883
- if (event.shiftKey) {
884
- tableSelection.setAnchorCellForSelection(tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid));
885
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
886
- }
887
-
888
- return selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
889
- }
890
- }
891
- } else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
892
- const tableCellNode = selection.focus.getNode();
893
-
894
- if (!$isTableCellNode(tableCellNode)) {
895
- return false;
896
- }
897
-
898
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
899
- event.preventDefault();
900
- event.stopImmediatePropagation();
901
- event.stopPropagation();
902
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
903
- }
904
-
905
- return false;
906
- }, lexical.COMMAND_PRIORITY_HIGH));
907
- tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, event => {
908
- const selection = lexical.$getSelection();
909
-
910
- if (!$isSelectionInTable(selection, tableNode)) {
911
- return false;
912
- }
913
-
914
- const direction = 'backward';
915
-
916
- if (lexical.$isRangeSelection(selection)) {
917
- if (selection.isCollapsed()) {
918
- const tableCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => $isTableCellNode(n));
919
-
920
- if (!$isTableCellNode(tableCellNode)) {
921
- return false;
922
- }
923
-
924
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
925
- const elementParentNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isElementNode(n));
926
-
927
- if (elementParentNode == null) {
928
- throw new Error('Expected BlockNode Parent');
929
- }
930
-
931
- if (selection.anchor.offset === 0 || event.shiftKey) {
932
- event.preventDefault();
933
- event.stopImmediatePropagation();
934
- event.stopPropagation(); // Start Selection
935
-
936
- if (event.shiftKey) {
937
- tableSelection.setAnchorCellForSelection(tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid));
938
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
939
- }
940
-
941
- return selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
942
- }
943
- }
944
- } else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
945
- const tableCellNode = selection.focus.getNode();
946
-
947
- if (!$isTableCellNode(tableCellNode)) {
948
- return false;
949
- }
950
-
951
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
952
- event.preventDefault();
953
- event.stopImmediatePropagation();
954
- event.stopPropagation();
955
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
956
- }
957
-
958
- return false;
959
- }, lexical.COMMAND_PRIORITY_HIGH));
960
- tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => {
961
- const selection = lexical.$getSelection();
962
-
963
- if (!$isSelectionInTable(selection, tableNode)) {
964
- return false;
965
- }
966
-
967
- const direction = 'forward';
968
-
969
- if (lexical.$isRangeSelection(selection)) {
970
- if (selection.isCollapsed()) {
971
- const tableCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => $isTableCellNode(n));
972
-
973
- if (!$isTableCellNode(tableCellNode)) {
974
- return false;
975
- }
976
-
977
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
978
- const elementParentNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isElementNode(n));
979
-
980
- if (elementParentNode == null) {
981
- throw new Error('Expected BlockNode Parent');
982
- }
983
-
984
- if (selection.anchor.offset === selection.anchor.getNode().getTextContentSize() || event.shiftKey) {
985
- event.preventDefault();
986
- event.stopImmediatePropagation();
987
- event.stopPropagation(); // Start Selection
988
-
989
- if (event.shiftKey) {
990
- tableSelection.setAnchorCellForSelection(tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid));
991
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
992
- }
993
-
994
- return selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
995
- }
996
- }
997
- } else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
998
- const tableCellNode = selection.focus.getNode();
757
+ if (lexical.DEPRECATED_$isGridSelection(selection)) {
758
+ const focusCellNode = utils.$findMatchingParent(selection.focus.getNode(), $isTableCellNode);
999
759
 
1000
- if (!$isTableCellNode(tableCellNode)) {
1001
- return false;
760
+ if ($isTableCellNode(focusCellNode)) {
761
+ stopEvent(event);
762
+ focusCellNode.selectEnd();
763
+ return true;
1002
764
  }
1003
-
1004
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
1005
- event.preventDefault();
1006
- event.stopImmediatePropagation();
1007
- event.stopPropagation();
1008
- return adjustFocusNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, direction);
1009
765
  }
1010
766
 
1011
767
  return false;
@@ -1137,72 +893,69 @@ function applyTableHandlers(tableNode, tableElement, editor) {
1137
893
 
1138
894
  return false;
1139
895
  }, lexical.COMMAND_PRIORITY_CRITICAL));
1140
- tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
1141
- const selection = lexical.$getSelection();
1142
-
1143
- if (!$isSelectionInTable(selection, tableNode)) {
1144
- return false;
1145
- }
1146
896
 
1147
- if (lexical.$isRangeSelection(selection)) {
1148
- const tableCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => $isTableCellNode(n));
897
+ if (hasTabHandler) {
898
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
899
+ const selection = lexical.$getSelection();
1149
900
 
1150
- if (!$isTableCellNode(tableCellNode)) {
901
+ if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed() || !$isSelectionInTable(selection, tableNode)) {
1151
902
  return false;
1152
903
  }
1153
904
 
1154
- if (selection.isCollapsed()) {
1155
- const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
1156
- event.preventDefault();
1157
- selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, !event.shiftKey ? 'forward' : 'backward');
1158
- return true;
905
+ const tableCellNode = $findCellNode(selection.anchor.getNode());
906
+
907
+ if (tableCellNode === null) {
908
+ return false;
1159
909
  }
1160
- }
1161
910
 
1162
- return false;
1163
- }, lexical.COMMAND_PRIORITY_HIGH));
911
+ stopEvent(event);
912
+ const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
913
+ selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, !event.shiftKey ? 'forward' : 'backward');
914
+ return true;
915
+ }, lexical.COMMAND_PRIORITY_CRITICAL));
916
+ }
917
+
1164
918
  tableSelection.listenersToRemove.add(editor.registerCommand(lexical.FOCUS_COMMAND, payload => {
1165
919
  return tableNode.isSelected();
1166
920
  }, lexical.COMMAND_PRIORITY_HIGH));
1167
- tableSelection.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, payload => {
921
+
922
+ function getCellFromCellNode(tableCellNode) {
923
+ const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
924
+ return tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid);
925
+ }
926
+
927
+ tableSelection.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, () => {
1168
928
  const selection = lexical.$getSelection();
1169
929
  const prevSelection = lexical.$getPreviousSelection();
1170
930
 
1171
- if (selection && lexical.$isRangeSelection(selection) && !selection.isCollapsed()) {
1172
- const anchorNode = selection.anchor.getNode();
1173
- const focusNode = selection.focus.getNode();
1174
- const isAnchorInside = tableNode.isParentOf(anchorNode);
1175
- const isFocusInside = tableNode.isParentOf(focusNode);
1176
- const selectionContainsPartialTable = isAnchorInside && !isFocusInside || isFocusInside && !isAnchorInside;
1177
- const selectionIsInsideTable = isAnchorInside && isFocusInside && !tableNode.isSelected();
1178
-
1179
- if (selectionContainsPartialTable) {
1180
- const isBackward = selection.isBackward();
1181
- const modifiedSelection = lexical.$createRangeSelection();
1182
- const tableKey = tableNode.getKey();
1183
- modifiedSelection.anchor.set(selection.anchor.key, selection.anchor.offset, selection.anchor.type);
1184
- modifiedSelection.focus.set(tableKey, isBackward ? 0 : tableNode.getChildrenSize(), 'element');
1185
- isRangeSelectionHijacked = true;
1186
- lexical.$setSelection(modifiedSelection);
931
+ if (lexical.$isRangeSelection(selection)) {
932
+ const {
933
+ anchor,
934
+ focus
935
+ } = selection;
936
+ const anchorNode = anchor.getNode();
937
+ const focusNode = focus.getNode(); // Using explicit comparison with table node to ensure it's not a nested table
938
+ // as in that case we'll leave selection resolving to that table
939
+
940
+ const anchorCellNode = $findCellNode(anchorNode);
941
+ const focusCellNode = $findCellNode(focusNode);
942
+ const isAnchorInside = anchorCellNode && tableNode.is($findTableNode(anchorCellNode));
943
+ const isFocusInside = focusCellNode && tableNode.is($findTableNode(focusCellNode));
944
+ const isPartialyWithinTable = isAnchorInside !== isFocusInside;
945
+ const isWithinTable = isAnchorInside && isFocusInside;
946
+ const isBackward = selection.isBackward();
947
+
948
+ if (isPartialyWithinTable) {
949
+ const newSelection = selection.clone();
950
+ newSelection.focus.set(tableNode.getKey(), isBackward ? 0 : tableNode.getChildrenSize(), 'element');
951
+ lexical.$setSelection(newSelection);
1187
952
  $addHighlightStyleToTable(editor, tableSelection);
1188
- return true;
1189
- } else if (selectionIsInsideTable) {
1190
- const {
1191
- grid
1192
- } = tableSelection;
1193
-
1194
- if (selection.getNodes().filter($isTableCellNode).length === grid.rows * grid.columns) {
1195
- const gridSelection = lexical.DEPRECATED_$createGridSelection();
1196
- const tableKey = tableNode.getKey();
1197
- const firstCell = tableNode.getFirstChildOrThrow().getFirstChild();
1198
- const lastCell = tableNode.getLastChildOrThrow().getLastChild();
1199
-
1200
- if (firstCell != null && lastCell != null) {
1201
- gridSelection.set(tableKey, firstCell.getKey(), lastCell.getKey());
1202
- lexical.$setSelection(gridSelection);
1203
- tableSelection.updateTableGridSelection(gridSelection);
1204
- return true;
1205
- }
953
+ } else if (isWithinTable) {
954
+ // Handle case when selection spans across multiple cells but still
955
+ // has range selection, then we convert it into grid selection
956
+ if (!anchorCellNode.is(focusCellNode)) {
957
+ tableSelection.setAnchorCellForSelection(getCellFromCellNode(anchorCellNode));
958
+ tableSelection.setFocusCellForSelection(getCellFromCellNode(focusCellNode), true);
1206
959
  }
1207
960
  }
1208
961
  }
@@ -1219,7 +972,6 @@ function applyTableHandlers(tableNode, tableElement, editor) {
1219
972
 
1220
973
  if (tableSelection.hasHijackedSelectionStyles && !tableNode.isSelected()) {
1221
974
  $removeHighlightStyleToTable(editor, tableSelection);
1222
- isRangeSelectionHijacked = false;
1223
975
  } else if (!tableSelection.hasHijackedSelectionStyles && tableNode.isSelected()) {
1224
976
  $addHighlightStyleToTable(editor, tableSelection);
1225
977
  }
@@ -1256,19 +1008,6 @@ function getCellFromTarget(node) {
1256
1008
 
1257
1009
  return null;
1258
1010
  }
1259
- function doesTargetContainText(node) {
1260
- const currentNode = node;
1261
-
1262
- if (currentNode !== null) {
1263
- const nodeName = currentNode.nodeName;
1264
-
1265
- if (nodeName === 'SPAN') {
1266
- return true;
1267
- }
1268
- }
1269
-
1270
- return false;
1271
- }
1272
1011
  function getTableGrid(tableElement) {
1273
1012
  const cells = [];
1274
1013
  const grid = {
@@ -1338,7 +1077,6 @@ function getTableGrid(tableElement) {
1338
1077
  return grid;
1339
1078
  }
1340
1079
  function $updateDOMForSelection(editor, grid, selection) {
1341
- const highlightedCells = [];
1342
1080
  const selectedCellNodes = new Set(selection ? selection.getNodes() : []);
1343
1081
  $forEachGridCell(grid, (cell, lexicalNode) => {
1344
1082
  const elem = cell.elem;
@@ -1346,7 +1084,6 @@ function $updateDOMForSelection(editor, grid, selection) {
1346
1084
  if (selectedCellNodes.has(lexicalNode)) {
1347
1085
  cell.highlighted = true;
1348
1086
  $addHighlightToDOM(editor, cell);
1349
- highlightedCells.push(cell);
1350
1087
  } else {
1351
1088
  cell.highlighted = false;
1352
1089
  $removeHighlightFromDOM(editor, cell);
@@ -1356,7 +1093,6 @@ function $updateDOMForSelection(editor, grid, selection) {
1356
1093
  }
1357
1094
  }
1358
1095
  });
1359
- return highlightedCells;
1360
1096
  }
1361
1097
  function $forEachGridCell(grid, cb) {
1362
1098
  const {
@@ -1406,10 +1142,10 @@ const selectGridNodeInDirection = (tableSelection, tableNode, x, y, direction) =
1406
1142
  case 'backward':
1407
1143
  case 'forward':
1408
1144
  if (x !== (isForward ? tableSelection.grid.columns - 1 : 0)) {
1409
- selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x + (isForward ? 1 : -1), y, tableSelection.grid));
1145
+ selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x + (isForward ? 1 : -1), y, tableSelection.grid), isForward);
1410
1146
  } else {
1411
1147
  if (y !== (isForward ? tableSelection.grid.rows - 1 : 0)) {
1412
- selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(isForward ? 0 : tableSelection.grid.columns - 1, y + (isForward ? 1 : -1), tableSelection.grid));
1148
+ selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(isForward ? 0 : tableSelection.grid.columns - 1, y + (isForward ? 1 : -1), tableSelection.grid), isForward);
1413
1149
  } else if (!isForward) {
1414
1150
  tableNode.selectPrevious();
1415
1151
  } else {
@@ -1421,7 +1157,7 @@ const selectGridNodeInDirection = (tableSelection, tableNode, x, y, direction) =
1421
1157
 
1422
1158
  case 'up':
1423
1159
  if (y !== 0) {
1424
- selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y - 1, tableSelection.grid));
1160
+ selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y - 1, tableSelection.grid), false);
1425
1161
  } else {
1426
1162
  tableNode.selectPrevious();
1427
1163
  }
@@ -1430,7 +1166,7 @@ const selectGridNodeInDirection = (tableSelection, tableNode, x, y, direction) =
1430
1166
 
1431
1167
  case 'down':
1432
1168
  if (y !== tableSelection.grid.rows - 1) {
1433
- selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y + 1, tableSelection.grid));
1169
+ selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y + 1, tableSelection.grid), true);
1434
1170
  } else {
1435
1171
  tableNode.selectNext();
1436
1172
  }
@@ -1485,11 +1221,9 @@ function $isSelectionInTable(selection, tableNode) {
1485
1221
  return false;
1486
1222
  }
1487
1223
 
1488
- function selectTableCellNode(tableCell) {
1489
- const possibleParagraph = tableCell.getChildren().find(n => lexical.$isParagraphNode(n));
1490
-
1491
- if (lexical.$isParagraphNode(possibleParagraph)) {
1492
- possibleParagraph.selectEnd();
1224
+ function selectTableCellNode(tableCell, fromStart) {
1225
+ if (fromStart) {
1226
+ tableCell.selectStart();
1493
1227
  } else {
1494
1228
  tableCell.selectEnd();
1495
1229
  }
@@ -1534,6 +1268,125 @@ function $removeHighlightFromDOM(editor, cell) {
1534
1268
  element.style.removeProperty('caret-color');
1535
1269
  }
1536
1270
 
1271
+ function $findCellNode(node) {
1272
+ const cellNode = utils.$findMatchingParent(node, $isTableCellNode);
1273
+ return $isTableCellNode(cellNode) ? cellNode : null;
1274
+ }
1275
+
1276
+ function $findTableNode(node) {
1277
+ const tableNode = utils.$findMatchingParent(node, $isTableNode);
1278
+ return $isTableNode(tableNode) ? tableNode : null;
1279
+ }
1280
+
1281
+ function $handleArrowKey(editor, event, direction, tableNode, tableSelection) {
1282
+ const selection = lexical.$getSelection();
1283
+
1284
+ if (!$isSelectionInTable(selection, tableNode)) {
1285
+ return false;
1286
+ }
1287
+
1288
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
1289
+ // Horizontal move between cels seem to work well without interruption
1290
+ // so just exit early, and handle vertical moves
1291
+ if (direction === 'backward' || direction === 'forward') {
1292
+ return false;
1293
+ }
1294
+
1295
+ const {
1296
+ anchor,
1297
+ focus
1298
+ } = selection;
1299
+ const anchorCellNode = utils.$findMatchingParent(anchor.getNode(), $isTableCellNode);
1300
+ const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
1301
+
1302
+ if (!$isTableCellNode(anchorCellNode) || !anchorCellNode.is(focusCellNode)) {
1303
+ return false;
1304
+ }
1305
+
1306
+ const anchorCellDom = editor.getElementByKey(anchorCellNode.__key);
1307
+ const anchorDOM = editor.getElementByKey(anchor.key);
1308
+
1309
+ if (anchorDOM == null || anchorCellDom == null) {
1310
+ return false;
1311
+ }
1312
+
1313
+ let edgeSelectionRect;
1314
+
1315
+ if (anchor.type === 'element') {
1316
+ edgeSelectionRect = anchorDOM.getBoundingClientRect();
1317
+ } else {
1318
+ const domSelection = window.getSelection();
1319
+
1320
+ if (domSelection === null || domSelection.rangeCount === 0) {
1321
+ return false;
1322
+ }
1323
+
1324
+ const range = domSelection.getRangeAt(0);
1325
+ edgeSelectionRect = range.getBoundingClientRect();
1326
+ }
1327
+
1328
+ const edgeChild = direction === 'up' ? anchorCellNode.getFirstChild() : anchorCellNode.getLastChild();
1329
+
1330
+ if (edgeChild == null) {
1331
+ return false;
1332
+ }
1333
+
1334
+ const edgeChildDOM = editor.getElementByKey(edgeChild.__key);
1335
+
1336
+ if (edgeChildDOM == null) {
1337
+ return false;
1338
+ }
1339
+
1340
+ const edgeRect = edgeChildDOM.getBoundingClientRect();
1341
+ const isExiting = direction === 'up' ? edgeRect.top > edgeSelectionRect.top - edgeSelectionRect.height : edgeSelectionRect.bottom + edgeSelectionRect.height > edgeRect.bottom;
1342
+
1343
+ if (isExiting) {
1344
+ stopEvent(event);
1345
+ const cords = tableNode.getCordsFromCellNode(anchorCellNode, tableSelection.grid);
1346
+
1347
+ if (event.shiftKey) {
1348
+ const cell = tableNode.getCellFromCordsOrThrow(cords.x, cords.y, tableSelection.grid);
1349
+ tableSelection.setAnchorCellForSelection(cell);
1350
+ tableSelection.setFocusCellForSelection(cell, true);
1351
+ } else {
1352
+ return selectGridNodeInDirection(tableSelection, tableNode, cords.x, cords.y, direction);
1353
+ }
1354
+
1355
+ return true;
1356
+ }
1357
+ } else if (lexical.DEPRECATED_$isGridSelection(selection)) {
1358
+ const {
1359
+ anchor,
1360
+ focus
1361
+ } = selection;
1362
+ const anchorCellNode = utils.$findMatchingParent(anchor.getNode(), $isTableCellNode);
1363
+ const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
1364
+
1365
+ if (!$isTableCellNode(anchorCellNode) || !$isTableCellNode(focusCellNode)) {
1366
+ return false;
1367
+ }
1368
+
1369
+ stopEvent(event);
1370
+
1371
+ if (event.shiftKey) {
1372
+ const cords = tableNode.getCordsFromCellNode(focusCellNode, tableSelection.grid);
1373
+ return adjustFocusNodeInDirection(tableSelection, tableNode, cords.x, cords.y, direction);
1374
+ } else {
1375
+ focusCellNode.selectEnd();
1376
+ }
1377
+
1378
+ return true;
1379
+ }
1380
+
1381
+ return false;
1382
+ }
1383
+
1384
+ function stopEvent(event) {
1385
+ event.preventDefault();
1386
+ event.stopImmediatePropagation();
1387
+ event.stopPropagation();
1388
+ }
1389
+
1537
1390
  /**
1538
1391
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1539
1392
  *
@@ -2007,14 +1860,14 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
2007
1860
  throw Error(`Expected a RangeSelection or GridSelection`);
2008
1861
  }
2009
1862
 
1863
+ const anchor = selection.anchor.getNode();
2010
1864
  const focus = selection.focus.getNode();
1865
+ const [anchorCell] = lexical.DEPRECATED_$getNodeTriplet(anchor);
2011
1866
  const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
2012
- const [gridMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, focusCell);
1867
+ const [gridMap, focusCellMap, anchorCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, anchorCell);
2013
1868
  const rowCount = gridMap.length;
2014
- const {
2015
- startColumn: focusStartColumn
2016
- } = focusCellMap;
2017
- const insertAfterColumn = insertAfter ? focusStartColumn + focusCell.__colSpan - 1 : focusStartColumn - 1;
1869
+ const startColumn = insertAfter ? Math.max(focusCellMap.startColumn, anchorCellMap.startColumn) : Math.min(focusCellMap.startColumn, anchorCellMap.startColumn);
1870
+ const insertAfterColumn = insertAfter ? startColumn + focusCell.__colSpan - 1 : startColumn - 1;
2018
1871
  const gridFirstChild = grid.getFirstChild();
2019
1872
 
2020
1873
  if (!lexical.DEPRECATED_$isGridRowNode(gridFirstChild)) {
@@ -4,71 +4,67 @@
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
- 'use strict';var d=require("lexical"),q=require("@lexical/utils");let w=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
- class z extends d.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){let b=new z(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:A,priority:0}),th:()=>({conversion:A,priority:0})}}static importJSON(a){let b=a.rowSpan||1,f=B(a.headerState,a.colSpan||1,a.width||void 0);f.__rowSpan=b;f.__backgroundColor=a.backgroundColor||null;return f}constructor(a=x.NO_STATUS,
9
- b=1,f,h){super(b,h);this.__headerState=a;this.__width=f;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);q.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
7
+ 'use strict';var d=require("lexical"),t=require("@lexical/utils");let w=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
+ class y extends d.DEPRECATED_GridCellNode{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:z,priority:0}),th:()=>({conversion:z,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=B(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=x.NO_STATUS,
9
+ b=1,c,e){super(b,e);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);t.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
10
10
  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
11
  headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}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=a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=
12
12
  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!==x.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==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}}
13
- function A(a){var b=a.nodeName.toLowerCase();let f=void 0;w.test(a.style.width)&&(f=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,f);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{forChild:(h,c)=>{if(C(c)&&!d.$isElementNode(h)){c=d.$createParagraphNode();if(d.$isLineBreakNode(h)&&"\n"===h.getTextContent())return null;c.append(h);return c}return h},node:b}}function B(a,b=1,f){return d.$applyNodeReplacement(new z(a,b,f))}
14
- function C(a){return a instanceof z}
15
- class D extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new D(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:aa,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);q.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
13
+ function z(a){var b=a.nodeName.toLowerCase();let c=void 0;w.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{forChild:(e,g)=>{if(C(g)&&!d.$isElementNode(e)){g=d.$createParagraphNode();if(d.$isLineBreakNode(e)&&"\n"===e.getTextContent())return null;g.append(e);return g}return e},node:b}}function B(a,b=1,c){return d.$applyNodeReplacement(new y(a,b,c))}
14
+ function C(a){return a instanceof y}
15
+ class D extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new D(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:aa,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);t.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
16
16
  a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function aa(a){let b=void 0;w.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:E(b)}}function E(a){return d.$applyNodeReplacement(new D(a))}function F(a){return a instanceof D}
17
- function G(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}let ba="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
18
- class H{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.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
19
- {this.editor.update(()=>{var f=!1;for(let h=0;h<b.length;h++){const c=b[h].target.nodeName;if("TABLE"===c||"TR"===c){f=!0;break}}if(f){f=this.editor.getElementByKey(this.tableNodeKey);if(!f)throw Error("Expected to find TableElement in DOM");this.grid=I(f)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=I(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
20
- !1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=d.$getNodeByKey(this.tableNodeKey);if(!J(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=I(b);K(a,b,null);d.$setSelection(null);a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,
21
- 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");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");b.classList.add("disable-selection");this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){if(null!=
22
- a&&a.gridKey===this.tableNodeKey){let b=this.editor;this.gridSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();K(b,this.grid,this.gridSelection)}else null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){let f=this.editor;f.update(()=>{var h=d.$getNodeByKey(this.tableNodeKey);if(!J(h))throw Error("Expected TableNode.");if(!f.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");h=a.x;let c=a.y;this.focusCell=a;if(null!==this.anchorCell){let l=
23
- ba?(f._window||window).getSelection():null;l&&l.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==h||this.anchorY!==c||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(h===this.focusX&&c===this.focusY)return;this.focusX=h;this.focusY=c;this.isHighlightingCells&&(h=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&C(h)&&(h=h.getKey(),this.gridSelection=this.gridSelection.clone()||
24
- d.DEPRECATED_$createGridSelection(),this.focusCellNodeKey=h,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),d.$setSelection(this.gridSelection),f.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),K(f,this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=d.$getNearestNodeFromDOMNode(a.elem);C(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),
25
- this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);let f=d.$createRangeSelection(),h=f.anchor,c=f.focus;b.getNodes().forEach(l=>{C(l)&&0!==l.getTextContentSize()&&(h.set(l.getKey(),0,"element"),c.set(l.getKey(),l.getChildrenSize(),"element"),f.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=d.$getNodeByKey(this.tableNodeKey);
26
- if(!J(b))throw Error("Expected TableNode.");var f=d.$getSelection();d.DEPRECATED_$isGridSelection(f)||G(11);f=f.getNodes().filter(C);f.length===this.grid.columns*this.grid.rows?(b.selectPrevious(),b.remove(),d.$getRoot().selectStart()):(f.forEach(h=>{if(d.$isElementNode(h)){let c=d.$createParagraphNode(),l=d.$createTextNode();c.append(l);h.append(c);h.getChildren().forEach(p=>{p!==c&&p.remove()})}}),K(a,this.grid,null),d.$setSelection(null),a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}
27
- function L(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}
28
- function I(a){let b=[],f={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var l=h.nodeName;if("TD"===l||"TH"===l)l=h,l={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:a,y:c},h._cell=l,void 0===b[c]&&(b[c]=[]),b[c][a]=l;else if(l=h.firstChild,null!=l){h=l;continue}l=h.nextSibling;if(null!=l)a++,h=l;else if(l=h.parentNode,null!=l){h=l.nextSibling;if(null==h)break;c++;a=0}}f.columns=a+1;f.rows=c+1;return f}
29
- function K(a,b,f){let h=[],c=new Set(f?f.getNodes():[]);M(b,(l,p)=>{let n=l.elem;c.has(p)?(l.highlighted=!0,N(a,l),h.push(l)):(l.highlighted=!1,O(a,l),n.getAttribute("style")||n.removeAttribute("style"))});return h}function M(a,b){({cells:a}=a);for(let f=0;f<a.length;f++){let h=a[f];for(let c=0;c<h.length;c++){let l=h[c],p=d.$getNearestNodeFromDOMNode(l.elem);null!==p&&b(l,p,{x:c,y:f})}}}function ca(a,b){b.disableHighlightStyle();M(b.grid,f=>{f.highlighted=!0;N(a,f)})}
30
- function da(a,b){b.enableHighlightStyle();M(b.grid,f=>{let h=f.elem;f.highlighted=!1;O(a,f);h.getAttribute("style")||h.removeAttribute("style")})}
31
- let Q=(a,b,f,h,c)=>{const l="forward"===c;switch(c){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)?P(b.getCellNodeFromCordsOrThrow(f+(l?1:-1),h,a.grid)):h!==(l?a.grid.rows-1:0)?P(b.getCellNodeFromCordsOrThrow(l?0:a.grid.columns-1,h+(l?1:-1),a.grid)):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?P(b.getCellNodeFromCordsOrThrow(f,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?P(b.getCellNodeFromCordsOrThrow(f,h+1,a.grid)):b.selectNext(),!0;
32
- default:return!1}},R=(a,b,f,h,c)=>{const l="forward"===c;switch(c){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f+(l?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h+1,a.grid)),!0):!1;default:return!1}};
33
- function S(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let f=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return f&&a}return!1}function P(a){let b=a.getChildren().find(f=>d.$isParagraphNode(f));d.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
34
- function N(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);if(!C(b))throw Error("Expected to find LexicalNode from Table Cell DOMNode");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")}
35
- function O(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);if(!C(b))throw Error("Expected to find LexicalNode from Table Cell DOMNode");null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}
36
- class T extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new T(a.__key)}static importDOM(){return{table:()=>({conversion:ea,priority:1})}}static importJSON(){return V()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");q.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let f=b.cloneNode(),h=document.createElement("colgroup"),
37
- c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let p=document.createElement("col");h.append(p)}f.replaceChildren(h,c);return f}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:f,cells:h}=b;for(b=0;b<f;b++){var c=h[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:l})=>d.$getNearestNodeFromDOMNode(l)===
38
- a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,f){({cells:f}=f);b=f[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,f){a=this.getCellFromCords(a,b,f);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,f){a=this.getCellFromCords(a,b,f);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return C(a)?a:null}getCellNodeFromCordsOrThrow(a,b,f){a=this.getCellNodeFromCords(a,b,f);if(!a)throw Error("Node at cords not TableCellNode.");
39
- return a}canSelectBefore(){return!0}canIndent(){return!1}}function ea(){return{node:V()}}function V(){return d.$applyNodeReplacement(new T)}function J(a){return a instanceof T}function W(a){a=q.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=q.$findMatchingParent(a,b=>J(b));if(J(a))return a;throw Error("Expected table cell to be inside of table.");}
40
- function fa(a,b){let f=X(a),{x:h,y:c}=f.getCordsFromCellNode(a,b);return{above:f.getCellNodeFromCords(h,c-1,b),below:f.getCellNodeFromCords(h,c+1,b),left:f.getCellNodeFromCords(h-1,c,b),right:f.getCellNodeFromCords(h+1,c,b)}}function Y(a){a=a.getFirstDescendant();null===a&&G(124);a.getParentOrThrow().selectStart()}function Z(a,b){let f=a.getFirstChild();null!==f?f.insertBefore(b):a.append(b)}let ha=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=B;exports.$createTableNode=V;
41
- exports.$createTableNodeWithDimensions=function(a,b,f=!0){let h=V();for(let l=0;l<a;l++){let p=E();for(let n=0;n<b;n++){var c=x.NO_STATUS;"object"===typeof f?(0===l&&f.rows&&(c|=x.ROW),0===n&&f.columns&&(c|=x.COLUMN)):f&&(0===l&&(c|=x.ROW),0===n&&(c|=x.COLUMN));c=B(c);let r=d.$createParagraphNode();r.append(d.$createTextNode());c.append(r);p.append(c)}h.append(p)}return h};exports.$createTableRowNode=E;
42
- exports.$deleteTableColumn=function(a,b){let f=a.getChildren();for(let c=0;c<f.length;c++){var h=f[c];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
43
- exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=d.DEPRECATED_$getNodeTriplet(b);[b]=d.DEPRECATED_$getNodeTriplet(a);let [c,l,p]=d.DEPRECATED_$computeGridMap(h,f,b);var {startColumn:n}=l;let {startRow:r,startColumn:u}=p;a=Math.min(n,u);n=Math.max(n+f.__colSpan-1,u+b.__colSpan-1);let t=n-a+1;if(c[0].length===n-a+1)h.selectPrevious(),h.remove();else{var g=
44
- c.length;for(let e=0;e<g;e++)for(let k=a;k<=n;k++){let {cell:m,startColumn:v}=c[e][k];v<a?k===a&&m.setColSpan(m.__colSpan-Math.min(t,m.__colSpan-(a-v))):v+m.__colSpan-1>n?k===n&&m.setColSpan(m.__colSpan-(n-v+1)):m.remove()}a=c[r];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,Y(b)):({cell:b}=a[u-1],Y(b))}};
45
- exports.$deleteTableRow__EXPERIMENTAL=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=d.DEPRECATED_$getNodeTriplet(b);[a]=d.DEPRECATED_$getNodeTriplet(a);let [c,l,p]=d.DEPRECATED_$computeGridMap(h,f,a);({startRow:b}=l);var {startRow:n}=p;a=n+a.__rowSpan-1;if(c.length===a-b+1)h.remove();else{n=c[0].length;var r=c[a+1],u=h.getChildAtIndex(a+1);for(let g=a;g>=b;g--){for(var t=n-1;0<=t;t--){let {cell:e,
46
- startRow:k,startColumn:m}=c[g][t];if(m===t&&(g===b&&k<b&&e.setRowSpan(e.__rowSpan-(k-b)),k>=b&&k+e.__rowSpan-1>a))if(e.setRowSpan(e.__rowSpan-(a-k+1)),null===u&&G(122),0===t)Z(u,e);else{let {cell:v}=r[t-1];v.insertAfter(e)}}t=h.getChildAtIndex(g);d.DEPRECATED_$isGridRowNode(t)||G(123);t.remove()}void 0!==r?({cell:b}=r[0],Y(b)):({cell:b}=c[b-1][0],Y(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return I(a)};
47
- exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=X;exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return X(b).getChildren().findIndex(f=>f.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
48
- exports.$insertTableColumn=function(a,b,f=!0,h,c){let l=a.getChildren();for(let r=0;r<l.length;r++){let u=l[r];if(F(u))for(let t=0;t<h;t++){var p=u.getChildren();if(b>=p.length||0>b)throw Error("Table column target index out of range");p=p[b];C(p)||G(12);let {left:g,right:e}=fa(p,c);var n=x.NO_STATUS;if(g&&g.hasHeaderState(x.ROW)||e&&e.hasHeaderState(x.ROW))n|=x.ROW;n=B(n);n.append(d.$createParagraphNode());f?p.insertAfter(n):p.insertBefore(n)}}return a};
49
- exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(){let t=B(x.NO_STATUS).append(d.$createParagraphNode());null===r&&(r=t);return t}var f=d.$getSelection();d.$isRangeSelection(f)||d.DEPRECATED_$isGridSelection(f)||G(118);f=f.focus.getNode();let [h,,c]=d.DEPRECATED_$getNodeTriplet(f),[l,p]=d.DEPRECATED_$computeGridMap(c,h,h);f=l.length;var {startColumn:n}=p;a=a?n+h.__colSpan-1:n-1;n=c.getFirstChild();d.DEPRECATED_$isGridRowNode(n)||G(120);let r=null;var u=n;a:for(n=0;n<f;n++){0!==n&&
50
- (u=u.getNextSibling(),d.DEPRECATED_$isGridRowNode(u)||G(121));let t=l[n];if(0>a){Z(u,b());continue}let {cell:g,startColumn:e,startRow:k}=t[a];if(e+g.__colSpan-1<=a){let m=g,v=k,y=a;for(;v!==n&&1<m.__rowSpan;)if(y-=g.__colSpan,0<=y){let {cell:U,startRow:ia}=t[y];m=U;v=ia}else{u.append(b());continue a}m.insertAfter(b())}else g.setColSpan(g.__colSpan+1)}null!==r&&Y(r)};
51
- exports.$insertTableRow=function(a,b,f=!0,h,c){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<h;l++){let n=b.getChildren(),r=n.length,u=E();for(let t=0;t<r;t++){var p=n[t];C(p)||G(12);let {above:g,below:e}=fa(p,c);p=x.NO_STATUS;let k=g&&g.getWidth()||e&&e.getWidth()||void 0;if(g&&g.hasHeaderState(x.COLUMN)||e&&e.hasHeaderState(x.COLUMN))p|=x.COLUMN;p=B(p,1,k);p.append(d.$createParagraphNode());u.append(p)}f?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
17
+ function G(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 ba="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
18
+ class I{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.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
19
+ {this.editor.update(()=>{var c=!1;for(let e=0;e<b.length;e++){const g=b[e].target.nodeName;if("TABLE"===g||"TR"===g){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.grid=J(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=J(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
20
+ !1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=d.$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=J(b);L(a,b,null);d.$setSelection(null);a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,
21
+ 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");t.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");t.addClassNamesToElement(b,a._config.theme.tableSelection);
22
+ this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){if(null!=a&&a.gridKey===this.tableNodeKey){let b=this.editor;this.gridSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();L(b,this.grid,this.gridSelection)}else null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var e=d.$getNodeByKey(this.tableNodeKey);if(!K(e))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
23
+ e=a.x;let g=a.y;this.focusCell=a;if(null!==this.anchorCell){let h=ba?(c._window||window).getSelection():null;h&&h.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=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&
24
+ C(e)&&(e=e.getKey(),this.gridSelection=this.gridSelection.clone()||d.DEPRECATED_$createGridSelection(),this.focusCellNodeKey=e,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),d.$setSelection(this.gridSelection),c.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),L(c,this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=d.$getNearestNodeFromDOMNode(a.elem);
25
+ C(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);let c=d.$createRangeSelection(),e=c.anchor,g=c.focus;b.getNodes().forEach(h=>{C(h)&&0!==h.getTextContentSize()&&(e.set(h.getKey(),0,"element"),g.set(h.getKey(),h.getChildrenSize(),"element"),c.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=
26
+ this.editor;a.update(()=>{let b=d.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");var c=d.$getSelection();d.DEPRECATED_$isGridSelection(c)||G(11);c=c.getNodes().filter(C);c.length===this.grid.columns*this.grid.rows?(b.selectPrevious(),b.remove(),d.$getRoot().selectStart()):(c.forEach(e=>{if(d.$isElementNode(e)){let g=d.$createParagraphNode(),h=d.$createTextNode();g.append(h);e.append(g);e.getChildren().forEach(f=>{f!==g&&f.remove()})}}),L(a,this.grid,null),d.$setSelection(null),
27
+ a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}function M(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}
28
+ function J(a){let b=[],c={cells:b,columns:0,rows:0};var e=a.firstChild;let g=a=0;for(b.length=0;null!=e;){var h=e.nodeName;if("TD"===h||"TH"===h)h=e,h={elem:h,hasBackgroundColor:""!==h.style.backgroundColor,highlighted:!1,x:a,y:g},e._cell=h,void 0===b[g]&&(b[g]=[]),b[g][a]=h;else if(h=e.firstChild,null!=h){e=h;continue}h=e.nextSibling;if(null!=h)a++,e=h;else if(h=e.parentNode,null!=h){e=h.nextSibling;if(null==e)break;g++;a=0}}c.columns=a+1;c.rows=g+1;return c}
29
+ function L(a,b,c){let e=new Set(c?c.getNodes():[]);N(b,(g,h)=>{let f=g.elem;e.has(h)?(g.highlighted=!0,O(a,g)):(g.highlighted=!1,ca(a,g),f.getAttribute("style")||f.removeAttribute("style"))})}function N(a,b){({cells:a}=a);for(let c=0;c<a.length;c++){let e=a[c];for(let g=0;g<e.length;g++){let h=e[g],f=d.$getNearestNodeFromDOMNode(h.elem);null!==f&&b(h,f,{x:g,y:c})}}}function da(a,b){b.disableHighlightStyle();N(b.grid,c=>{c.highlighted=!0;O(a,c)})}
30
+ function ea(a,b){b.enableHighlightStyle();N(b.grid,c=>{let e=c.elem;c.highlighted=!1;ca(a,c);e.getAttribute("style")||e.removeAttribute("style")})}
31
+ let fa=(a,b,c,e,g)=>{const h="forward"===g;switch(g){case "backward":case "forward":return c!==(h?a.grid.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(h?1:-1),e,a.grid),h?a.selectStart():a.selectEnd()):e!==(h?a.grid.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(h?0:a.grid.columns-1,e+(h?1:-1),a.grid),h?a.selectStart():a.selectEnd()):h?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==e?b.getCellNodeFromCordsOrThrow(c,e-1,a.grid).selectEnd():b.selectPrevious(),!0;case "down":return e!==a.grid.rows-
32
+ 1?b.getCellNodeFromCordsOrThrow(c,e+1,a.grid).selectStart():b.selectNext(),!0;default:return!1}},ha=(a,b,c,e,g)=>{const h="forward"===g;switch(g){case "backward":case "forward":return c!==(h?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(c+(h?1:-1),e,a.grid)),!0;case "up":return 0!==e?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(c,e-1,a.grid)),!0):!1;case "down":return e!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(c,e+1,a.grid)),!0):!1;
33
+ default:return!1}};function P(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
34
+ function O(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);C(b)||G(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")}
35
+ function ca(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);C(b)||G(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Q(a){a=t.$findMatchingParent(a,C);return C(a)?a:null}function ia(a){a=t.$findMatchingParent(a,K);return K(a)?a:null}
36
+ function R(a,b,c,e,g){var h=d.$getSelection();if(!P(h,e))return!1;if(d.$isRangeSelection(h)&&h.isCollapsed()){if("backward"===c||"forward"===c)return!1;let {anchor:q,focus:r}=h;h=t.$findMatchingParent(q.getNode(),C);var f=t.$findMatchingParent(r.getNode(),C);if(!C(h)||!h.is(f))return!1;f=a.getElementByKey(h.__key);var m=a.getElementByKey(q.key);if(null==m||null==f)return!1;if("element"===q.type)f=m.getBoundingClientRect();else{f=window.getSelection();if(null===f||0===f.rangeCount)return!1;f=f.getRangeAt(0).getBoundingClientRect()}m=
37
+ "up"===c?h.getFirstChild():h.getLastChild();if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>f.top-f.height:f.bottom+f.height>a.bottom){S(b);h=e.getCordsFromCellNode(h,g.grid);if(b.shiftKey)c=e.getCellFromCordsOrThrow(h.x,h.y,g.grid),g.setAnchorCellForSelection(c),g.setFocusCellForSelection(c,!0);else return fa(g,e,h.x,h.y,c);return!0}}else if(d.DEPRECATED_$isGridSelection(h)){let {anchor:q,focus:r}=h;h=t.$findMatchingParent(q.getNode(),
38
+ C);a=t.$findMatchingParent(r.getNode(),C);if(!C(h)||!C(a))return!1;S(b);if(b.shiftKey)return b=e.getCordsFromCellNode(a,g.grid),ha(g,e,b.x,b.y,c);a.selectEnd();return!0}return!1}function S(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
39
+ class T extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new T(a.__key)}static importDOM(){return{table:()=>({conversion:ja,priority:1})}}static importJSON(){return U()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");t.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),e=document.createElement("colgroup"),
40
+ g=document.createElement("tbody");g.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let h=0;h<b;h++){let f=document.createElement("col");e.append(f)}c.replaceChildren(e,g);return c}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,cells:e}=b;for(b=0;b<c;b++){var g=e[b];if(null==g)throw Error(`Row not found at y:${b}`);g=g.findIndex(({elem:h})=>d.$getNearestNodeFromDOMNode(h)===
41
+ a);if(-1!==g)return{x:g,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,c){({cells:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,c){a=this.getCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getCellFromCords(a,b,c);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return C(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);if(!a)throw Error("Node at cords not TableCellNode.");
42
+ return a}canSelectBefore(){return!0}canIndent(){return!1}}function ja(){return{node:U()}}function U(){return d.$applyNodeReplacement(new T)}function K(a){return a instanceof T}function W(a){a=t.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=t.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}
43
+ function ka(a,b){let c=X(a),{x:e,y:g}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(e,g-1,b),below:c.getCellNodeFromCords(e,g+1,b),left:c.getCellNodeFromCords(e-1,g,b),right:c.getCellNodeFromCords(e+1,g,b)}}function Y(a){a=a.getFirstDescendant();null===a&&G(124);a.getParentOrThrow().selectStart()}function Z(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}let la=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=B;exports.$createTableNode=U;
44
+ exports.$createTableNodeWithDimensions=function(a,b,c=!0){let e=U();for(let h=0;h<a;h++){let f=E();for(let m=0;m<b;m++){var g=x.NO_STATUS;"object"===typeof c?(0===h&&c.rows&&(g|=x.ROW),0===m&&c.columns&&(g|=x.COLUMN)):c&&(0===h&&(g|=x.ROW),0===m&&(g|=x.COLUMN));g=B(g);let q=d.$createParagraphNode();q.append(d.$createTextNode());g.append(q);f.append(g)}e.append(f)}return e};exports.$createTableRowNode=E;
45
+ exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let g=0;g<c.length;g++){var e=c[g];if(F(e)){e=e.getChildren();if(b>=e.length||0>b)throw Error("Table column target index out of range");e[b].remove()}}return a};
46
+ exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,e]=d.DEPRECATED_$getNodeTriplet(b);[b]=d.DEPRECATED_$getNodeTriplet(a);let [g,h,f]=d.DEPRECATED_$computeGridMap(e,c,b);var {startColumn:m}=h;let {startRow:q,startColumn:r}=f;a=Math.min(m,r);m=Math.max(m+c.__colSpan-1,r+b.__colSpan-1);let k=m-a+1;if(g[0].length===m-a+1)e.selectPrevious(),e.remove();else{var l=
47
+ g.length;for(let n=0;n<l;n++)for(let p=a;p<=m;p++){let {cell:v,startColumn:u}=g[n][p];u<a?p===a&&v.setColSpan(v.__colSpan-Math.min(k,v.__colSpan-(a-u))):u+v.__colSpan-1>m?p===m&&v.setColSpan(v.__colSpan-(m-u+1)):v.remove()}a=g[q];b=a[r+b.__colSpan];void 0!==b?({cell:b}=b,Y(b)):({cell:b}=a[r-1],Y(b))}};
48
+ exports.$deleteTableRow__EXPERIMENTAL=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,e]=d.DEPRECATED_$getNodeTriplet(b);[a]=d.DEPRECATED_$getNodeTriplet(a);let [g,h,f]=d.DEPRECATED_$computeGridMap(e,c,a);({startRow:b}=h);var {startRow:m}=f;a=m+a.__rowSpan-1;if(g.length===a-b+1)e.remove();else{m=g[0].length;var q=g[a+1],r=e.getChildAtIndex(a+1);for(let l=a;l>=b;l--){for(var k=m-1;0<=k;k--){let {cell:n,
49
+ startRow:p,startColumn:v}=g[l][k];if(v===k&&(l===b&&p<b&&n.setRowSpan(n.__rowSpan-(p-b)),p>=b&&p+n.__rowSpan-1>a))if(n.setRowSpan(n.__rowSpan-(a-p+1)),null===r&&G(122),0===k)Z(r,n);else{let {cell:u}=q[k-1];u.insertAfter(n)}}k=e.getChildAtIndex(l);d.DEPRECATED_$isGridRowNode(k)||G(123,String(l));k.remove()}void 0!==q?({cell:b}=q[0],Y(b)):({cell:b}=g[b-1][0],Y(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return J(a)};
50
+ exports.$getTableCellNodeFromLexicalNode=function(a){a=t.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=X;exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return X(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
51
+ exports.$insertTableColumn=function(a,b,c=!0,e,g){let h=a.getChildren();for(let q=0;q<h.length;q++){let r=h[q];if(F(r))for(let k=0;k<e;k++){var f=r.getChildren();if(b>=f.length||0>b)throw Error("Table column target index out of range");f=f[b];C(f)||G(12);let {left:l,right:n}=ka(f,g);var m=x.NO_STATUS;if(l&&l.hasHeaderState(x.ROW)||n&&n.hasHeaderState(x.ROW))m|=x.ROW;m=B(m);m.append(d.$createParagraphNode());c?f.insertAfter(m):f.insertBefore(m)}}return a};
52
+ exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(){let l=B(x.NO_STATUS).append(d.$createParagraphNode());null===r&&(r=l);return l}var c=d.$getSelection();d.$isRangeSelection(c)||d.DEPRECATED_$isGridSelection(c)||G(118);var e=c.anchor.getNode();c=c.focus.getNode();[e]=d.DEPRECATED_$getNodeTriplet(e);let [g,,h]=d.DEPRECATED_$getNodeTriplet(c),[f,m,q]=d.DEPRECATED_$computeGridMap(h,g,e);e=f.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);a=a?c+
53
+ g.__colSpan-1:c-1;c=h.getFirstChild();d.DEPRECATED_$isGridRowNode(c)||G(120);let r=null;var k=c;a:for(c=0;c<e;c++){0!==c&&(k=k.getNextSibling(),d.DEPRECATED_$isGridRowNode(k)||G(121));let l=f[c];if(0>a){Z(k,b());continue}let {cell:n,startColumn:p,startRow:v}=l[a];if(p+n.__colSpan-1<=a){let u=n,A=v,H=a;for(;A!==c&&1<u.__rowSpan;)if(H-=n.__colSpan,0<=H){let {cell:V,startRow:ma}=l[H];u=V;A=ma}else{k.append(b());continue a}u.insertAfter(b())}else n.setColSpan(n.__colSpan+1)}null!==r&&Y(r)};
54
+ exports.$insertTableRow=function(a,b,c=!0,e,g){var h=a.getChildren();if(b>=h.length||0>b)throw Error("Table row target index out of range");b=h[b];if(F(b))for(h=0;h<e;h++){let m=b.getChildren(),q=m.length,r=E();for(let k=0;k<q;k++){var f=m[k];C(f)||G(12);let {above:l,below:n}=ka(f,g);f=x.NO_STATUS;let p=l&&l.getWidth()||n&&n.getWidth()||void 0;if(l&&l.hasHeaderState(x.COLUMN)||n&&n.hasHeaderState(x.COLUMN))f|=x.COLUMN;f=B(f,1,p);f.append(d.$createParagraphNode());r.append(f)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
52
55
  return a};
53
- exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();d.$isRangeSelection(b)||d.DEPRECATED_$isGridSelection(b)||G(118);b=b.focus.getNode();let [f,,h]=d.DEPRECATED_$getNodeTriplet(b),[c,l]=d.DEPRECATED_$computeGridMap(h,f,f);b=c[0].length;var {startRow:p}=l;if(a){a=p+f.__rowSpan-1;var n=c[a];p=E();for(var r=0;r<b;r++){let {cell:u,startRow:t}=n[r];t+u.__rowSpan-1<=a?p.append(B(x.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(a);d.DEPRECATED_$isGridRowNode(b)||G(119);
54
- b.insertAfter(p)}else{n=c[p];a=E();for(r=0;r<b;r++){let {cell:u,startRow:t}=n[r];t===p?a.append(B(x.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(p);d.DEPRECATED_$isGridRowNode(b)||G(119);b.insertBefore(a)}};exports.$isTableCellNode=C;exports.$isTableNode=J;exports.$isTableRowNode=F;exports.$removeTableRowAtIndex=function(a,b){let f=a.getChildren();if(b>=f.length||0>b)throw Error("Expected table cell to be inside of table row.");f[b].remove();return a};
55
- exports.$unmergeCell=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);a=a.anchor.getNode();let [b,f,h]=d.DEPRECATED_$getNodeTriplet(a);a=b.__colSpan;let c=b.__rowSpan;if(1<a){for(var l=1;l<a;l++)b.insertAfter(B(x.NO_STATUS));b.setColSpan(1)}if(1<c){let [r,u]=d.DEPRECATED_$computeGridMap(h,b,b),{startColumn:t,startRow:g}=u;for(l=1;l<c;l++){let e=g+l,k=r[e];var p=f.getNextSibling();d.DEPRECATED_$isGridRowNode(p)||G(125);var n=null;for(let m=0;m<t;m++){let v=
56
- k[m],y=v.cell;v.startRow===e&&(n=y);1<y.__colSpan&&(m+=y.__colSpan-1)}if(null===n)for(n=0;n<a;n++)Z(p,B(x.NO_STATUS));else for(p=0;p<a;p++)n.insertAfter(B(x.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ha;exports.TableCellHeaderStates=x;exports.TableCellNode=z;exports.TableNode=T;exports.TableRowNode=D;exports.TableSelection=H;
57
- exports.applyTableHandlers=function(a,b,f){let h=f.getRootElement();if(null===h)throw Error("No root element.");let c=new H(f,a.getKey());b.__lexicalTableSelection=c;let l=!1,p=!1;b.addEventListener("dblclick",g=>{let e=L(g.target);null!==e&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),c.setAnchorCellForSelection(e),c.setFocusCellForSelection(e,!0),l=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var e=L(g.target);null!==e&&(g.preventDefault(),g.stopPropagation(),
58
- g.stopImmediatePropagation(),c.setAnchorCellForSelection(e))}},0)});b.addEventListener("mousemove",g=>{p&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(l){let e=L(g.target);if(null!==e){let k=e.x,m=e.y;l&&(c.anchorX!==k||c.anchorY!==m||c.isHighlightingCells)&&(g.preventDefault(),c.setFocusCellForSelection(e))}}});b.addEventListener("mouseleave",()=>{});let n=g=>{0===g.button&&f.update(()=>{var e=d.$getSelection();const k=g.target;if(k instanceof Node){if(d.DEPRECATED_$isGridSelection(e)&&
59
- e.gridKey===c.tableNodeKey&&h.contains(k))return c.clearHighlight();e=d.$getNearestNodeFromDOMNode(k);null!==e&&q.$findMatchingParent(e,d.DEPRECATED_$isGridNode)&&(l=!0)}})};window.addEventListener("mousedown",n);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",n));let r=g=>{var e;if(e=l)e=g.target,e=null!==e&&"SPAN"===e.nodeName?!0:!1,e=!e;e&&(g.preventDefault(),g.stopPropagation());l=!1};window.addEventListener("mouseup",r);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",
60
- r));b.addEventListener("mouseup",r);c.listenersToRemove.add(()=>b.removeEventListener("mouseup",r));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_DOWN_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>C(v));if(!C(k))return!1;var m=a.getCordsFromCellNode(k,c.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>d.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&
61
- e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),R(c,a,m.x,m.y,"down")):Q(c,a,m.x,m.y,"down")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!C(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,m.x,m.y,"down")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_UP_COMMAND,
62
- g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>C(v));if(!C(k))return!1;var m=a.getCordsFromCellNode(k,c.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>d.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,
63
- m.y,c.grid)),R(c,a,m.x,m.y,"up")):Q(c,a,m.x,m.y,"up")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!C(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,m.x,m.y,"up")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_LEFT_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),
64
- m=>C(m));if(!C(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>d.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===e.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),R(c,a,k.x,k.y,"backward")):Q(c,a,k.x,k.y,"backward")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!C(e))return!1;
65
- e=a.getCordsFromCellNode(e,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,e.x,e.y,"backward")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),m=>C(m));if(!C(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>d.$isElementNode(m)))throw Error("Expected BlockNode Parent");
66
- if(e.anchor.offset===e.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),R(c,a,k.x,k.y,"forward")):Q(c,a,k.x,k.y,"forward")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!C(e))return!1;e=a.getCordsFromCellNode(e,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,e.x,e.y,"forward")}return!1},
67
- d.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.DEPRECATED_$isGridSelection(e))return c.clearText(),!0;if(d.$isRangeSelection(e)){const v=q.$findMatchingParent(e.anchor.getNode(),y=>C(y));if(!C(v))return!1;var k=e.anchor.getNode(),m=e.focus.getNode();k=a.isParentOf(k);m=a.isParentOf(m);if(k&&!m||m&&!k)return c.clearText(),!0;k=(m=q.$findMatchingParent(e.anchor.getNode(),y=>d.$isElementNode(y)))&&q.$findMatchingParent(m,y=>d.$isElementNode(y)&&C(y.getParent()));
68
- if(!d.$isElementNode(k)||!d.$isElementNode(m))return!1;if(g===d.DELETE_LINE_COMMAND&&null===k.getPreviousSibling())return!0;if((g===d.DELETE_CHARACTER_COMMAND||g===d.DELETE_WORD_COMMAND)&&e.isCollapsed()&&0===e.anchor.offset&&m!==k){e=m.getChildren();const y=d.$createParagraphNode();e.forEach(U=>y.append(U));m.replace(y);m.getWritable().__parent=v.getKey();return!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(g=>{c.listenersToRemove.add(f.registerCommand(g,
69
- u(g),d.COMMAND_PRIORITY_CRITICAL))});let t=g=>{const e=d.$getSelection();if(!S(e,a))return!1;if(d.DEPRECATED_$isGridSelection(e))return g.preventDefault(),g.stopPropagation(),c.clearText(),!0;d.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>C(k)),C(g));return!1};c.listenersToRemove.add(f.registerCommand(d.KEY_BACKSPACE_COMMAND,t,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.KEY_DELETE_COMMAND,t,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.FORMAT_TEXT_COMMAND,
70
- g=>{let e=d.$getSelection();if(!S(e,a))return!1;if(d.DEPRECATED_$isGridSelection(e))return c.formatCells(g),!0;d.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>C(k)),C(g));return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=d.$getSelection();if(!S(g,a))return!1;d.DEPRECATED_$isGridSelection(g)?c.clearHighlight():d.$isRangeSelection(g)&&(g=q.$findMatchingParent(g.anchor.getNode(),e=>C(e)),C(g));return!1},
71
- d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.KEY_TAB_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){let k=q.$findMatchingParent(e.anchor.getNode(),m=>C(m));if(!C(k))return!1;if(e.isCollapsed())return e=a.getCordsFromCellNode(k,c.grid),g.preventDefault(),Q(c,a,e.x,e.y,g.shiftKey?"backward":"forward"),!0}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),d.COMMAND_PRIORITY_HIGH));
72
- c.listenersToRemove.add(f.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>{let g=d.$getSelection();var e=d.$getPreviousSelection();if(g&&d.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),m=g.focus.getNode();k=a.isParentOf(k);var v=a.isParentOf(m);m=k&&!v||v&&!k;k=k&&v&&!a.isSelected();if(m)return e=g.isBackward(),k=d.$createRangeSelection(),m=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(m,e?0:a.getChildrenSize(),"element"),p=!0,d.$setSelection(k),
73
- ca(f,c),!0;if(k&&({grid:k}=c,g.getNodes().filter(C).length===k.rows*k.columns)){k=d.DEPRECATED_$createGridSelection();m=a.getKey();v=a.getFirstChildOrThrow().getFirstChild();let y=a.getLastChildOrThrow().getLastChild();if(null!=v&&null!=y)return k.set(m,v.getKey(),y.getKey()),d.$setSelection(k),c.updateTableGridSelection(k),!0}}if(g&&!g.is(e)&&(d.DEPRECATED_$isGridSelection(g)||d.DEPRECATED_$isGridSelection(e))&&c.gridSelection&&!c.gridSelection.is(e))return d.DEPRECATED_$isGridSelection(g)&&g.gridKey===
74
- c.tableNodeKey?c.updateTableGridSelection(g):!d.DEPRECATED_$isGridSelection(g)&&d.DEPRECATED_$isGridSelection(e)&&e.gridKey===c.tableNodeKey&&c.updateTableGridSelection(null),!1;c.hasHijackedSelectionStyles&&!a.isSelected()?(da(f,c),p=!1):!c.hasHijackedSelectionStyles&&a.isSelected()&&ca(f,c);return!1},d.COMMAND_PRIORITY_CRITICAL));return c};exports.getCellFromTarget=L;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
56
+ exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();d.$isRangeSelection(b)||d.DEPRECATED_$isGridSelection(b)||G(118);b=b.focus.getNode();let [c,,e]=d.DEPRECATED_$getNodeTriplet(b),[g,h]=d.DEPRECATED_$computeGridMap(e,c,c);b=g[0].length;var {startRow:f}=h;if(a){a=f+c.__rowSpan-1;var m=g[a];f=E();for(var q=0;q<b;q++){let {cell:r,startRow:k}=m[q];k+r.__rowSpan-1<=a?f.append(B(x.NO_STATUS)):r.setRowSpan(r.__rowSpan+1)}b=e.getChildAtIndex(a);d.DEPRECATED_$isGridRowNode(b)||G(119);
57
+ b.insertAfter(f)}else{m=g[f];a=E();for(q=0;q<b;q++){let {cell:r,startRow:k}=m[q];k===f?a.append(B(x.NO_STATUS)):r.setRowSpan(r.__rowSpan+1)}b=e.getChildAtIndex(f);d.DEPRECATED_$isGridRowNode(b)||G(119);b.insertBefore(a)}};exports.$isTableCellNode=C;exports.$isTableNode=K;exports.$isTableRowNode=F;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};
58
+ exports.$unmergeCell=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);a=a.anchor.getNode();let [b,c,e]=d.DEPRECATED_$getNodeTriplet(a);a=b.__colSpan;let g=b.__rowSpan;if(1<a){for(var h=1;h<a;h++)b.insertAfter(B(x.NO_STATUS));b.setColSpan(1)}if(1<g){let [q,r]=d.DEPRECATED_$computeGridMap(e,b,b),{startColumn:k,startRow:l}=r;for(h=1;h<g;h++){let n=l+h,p=q[n];var f=c.getNextSibling();d.DEPRECATED_$isGridRowNode(f)||G(125);var m=null;for(let v=0;v<k;v++){let u=
59
+ p[v],A=u.cell;u.startRow===n&&(m=A);1<A.__colSpan&&(v+=A.__colSpan-1)}if(null===m)for(m=0;m<a;m++)Z(f,B(x.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(B(x.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=la;exports.TableCellHeaderStates=x;exports.TableCellNode=y;exports.TableNode=T;exports.TableRowNode=D;exports.TableSelection=I;
60
+ exports.applyTableHandlers=function(a,b,c,e){function g(k){k=a.getCordsFromCellNode(k,f.grid);return a.getCellFromCordsOrThrow(k.x,k.y,f.grid)}let h=c.getRootElement();if(null===h)throw Error("No root element.");let f=new I(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=M(k.target);null!==l&&(S(k),f.setAnchorCellForSelection(l));var n=()=>{m.removeEventListener("mouseup",n);m.removeEventListener("mousemove",
61
+ p)},p=v=>{const u=M(v.target);null===u||f.anchorX===u.x&&f.anchorY===u.y||(v.preventDefault(),f.setFocusCellForSelection(u))};m.addEventListener("mouseup",n);m.addEventListener("mousemove",p)}},0)});let q=k=>{0===k.button&&c.update(()=>{const l=d.$getSelection(),n=k.target;d.DEPRECATED_$isGridSelection(l)&&l.gridKey===f.tableNodeKey&&h.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",q);f.listenersToRemove.add(()=>m.removeEventListener("mousedown",q));f.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_DOWN_COMMAND,
62
+ k=>R(c,k,"down",a,f),d.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_UP_COMMAND,k=>R(c,k,"up",a,f),d.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_LEFT_COMMAND,k=>R(c,k,"backward",a,f),d.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,k=>R(c,k,"forward",a,f),d.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(d.KEY_ESCAPE_COMMAND,k=>{var l=d.$getSelection();return d.DEPRECATED_$isGridSelection(l)&&
63
+ (l=t.$findMatchingParent(l.focus.getNode(),C),C(l))?(S(k),l.selectEnd(),!0):!1},d.COMMAND_PRIORITY_HIGH));let r=k=>()=>{var l=d.$getSelection();if(!P(l,a))return!1;if(d.DEPRECATED_$isGridSelection(l))return f.clearText(),!0;if(d.$isRangeSelection(l)){const v=t.$findMatchingParent(l.anchor.getNode(),u=>C(u));if(!C(v))return!1;var n=l.anchor.getNode(),p=l.focus.getNode();n=a.isParentOf(n);p=a.isParentOf(p);if(n&&!p||p&&!n)return f.clearText(),!0;n=(p=t.$findMatchingParent(l.anchor.getNode(),u=>d.$isElementNode(u)))&&
64
+ t.$findMatchingParent(p,u=>d.$isElementNode(u)&&C(u.getParent()));if(!d.$isElementNode(n)||!d.$isElementNode(p))return!1;if(k===d.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0;if((k===d.DELETE_CHARACTER_COMMAND||k===d.DELETE_WORD_COMMAND)&&l.isCollapsed()&&0===l.anchor.offset&&p!==n){l=p.getChildren();const u=d.$createParagraphNode();l.forEach(A=>u.append(A));p.replace(u);p.getWritable().__parent=v.getKey();return!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(k=>
65
+ {f.listenersToRemove.add(c.registerCommand(k,r(k),d.COMMAND_PRIORITY_CRITICAL))});b=k=>{const l=d.$getSelection();if(!P(l,a))return!1;if(d.DEPRECATED_$isGridSelection(l))return k.preventDefault(),k.stopPropagation(),f.clearText(),!0;d.$isRangeSelection(l)&&(k=t.$findMatchingParent(l.anchor.getNode(),n=>C(n)),C(k));return!1};f.listenersToRemove.add(c.registerCommand(d.KEY_BACKSPACE_COMMAND,b,d.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(d.KEY_DELETE_COMMAND,b,d.COMMAND_PRIORITY_CRITICAL));
66
+ f.listenersToRemove.add(c.registerCommand(d.FORMAT_TEXT_COMMAND,k=>{let l=d.$getSelection();if(!P(l,a))return!1;if(d.DEPRECATED_$isGridSelection(l))return f.formatCells(k),!0;d.$isRangeSelection(l)&&(k=t.$findMatchingParent(l.anchor.getNode(),n=>C(n)),C(k));return!1},d.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var k=d.$getSelection();if(!P(k,a))return!1;d.DEPRECATED_$isGridSelection(k)?f.clearHighlight():d.$isRangeSelection(k)&&
67
+ (k=t.$findMatchingParent(k.anchor.getNode(),l=>C(l)),C(k));return!1},d.COMMAND_PRIORITY_CRITICAL));e&&f.listenersToRemove.add(c.registerCommand(d.KEY_TAB_COMMAND,k=>{var l=d.$getSelection();if(!d.$isRangeSelection(l)||!l.isCollapsed()||!P(l,a))return!1;l=Q(l.anchor.getNode());if(null===l)return!1;S(k);l=a.getCordsFromCellNode(l,f.grid);fa(f,a,l.x,l.y,k.shiftKey?"backward":"forward");return!0},d.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),
68
+ d.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>{let k=d.$getSelection(),l=d.$getPreviousSelection();if(d.$isRangeSelection(k)){let {anchor:A,focus:H}=k;var n=A.getNode(),p=H.getNode();n=Q(n);p=Q(p);var v=n&&a.is(ia(n)),u=p&&a.is(ia(p));let V=v!==u;u=v&&u;v=k.isBackward();V?(n=k.clone(),n.focus.set(a.getKey(),v?0:a.getChildrenSize(),"element"),d.$setSelection(n),da(c,f)):u&&!n.is(p)&&(f.setAnchorCellForSelection(g(n)),f.setFocusCellForSelection(g(p),
69
+ !0))}if(k&&!k.is(l)&&(d.DEPRECATED_$isGridSelection(k)||d.DEPRECATED_$isGridSelection(l))&&f.gridSelection&&!f.gridSelection.is(l))return d.DEPRECATED_$isGridSelection(k)&&k.gridKey===f.tableNodeKey?f.updateTableGridSelection(k):!d.DEPRECATED_$isGridSelection(k)&&d.DEPRECATED_$isGridSelection(l)&&l.gridKey===f.tableNodeKey&&f.updateTableGridSelection(null),!1;f.hasHijackedSelectionStyles&&!a.isSelected()?ea(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&da(c,f);return!1},d.COMMAND_PRIORITY_CRITICAL));
70
+ return f};exports.getCellFromTarget=M;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
@@ -13,8 +13,8 @@ export declare const TableCellHeaderStates: {
13
13
  NO_STATUS: number;
14
14
  ROW: number;
15
15
  };
16
- export declare type TableCellHeaderState = typeof TableCellHeaderStates[keyof typeof TableCellHeaderStates];
17
- export declare type SerializedTableCellNode = Spread<{
16
+ export type TableCellHeaderState = typeof TableCellHeaderStates[keyof typeof TableCellHeaderStates];
17
+ export type SerializedTableCellNode = Spread<{
18
18
  headerState: TableCellHeaderState;
19
19
  width?: number;
20
20
  backgroundColor?: null | string;
@@ -9,7 +9,7 @@ import type { TableCellNode } from './LexicalTableCellNode';
9
9
  import type { Cell, Grid } from './LexicalTableSelection';
10
10
  import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
11
11
  import { DEPRECATED_GridNode } from 'lexical';
12
- export declare type SerializedTableNode = SerializedElementNode;
12
+ export type SerializedTableNode = SerializedElementNode;
13
13
  /** @noInheritDoc */
14
14
  export declare class TableNode extends DEPRECATED_GridNode {
15
15
  /** @internal */
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import type { Spread } from 'lexical';
9
9
  import { DEPRECATED_GridRowNode, DOMConversionMap, DOMConversionOutput, EditorConfig, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
10
- export declare type SerializedTableRowNode = Spread<{
10
+ export type SerializedTableRowNode = Spread<{
11
11
  height: number;
12
12
  }, SerializedElementNode>;
13
13
  /** @noInheritDoc */
@@ -6,17 +6,15 @@
6
6
  *
7
7
  */
8
8
  import type { GridSelection, LexicalEditor, NodeKey, TextFormatType } from 'lexical';
9
- export declare const BACKGROUND_COLOR = "background-color";
10
- export declare const BACKGROUND_IMAGE = "background-image";
11
- export declare type Cell = {
9
+ export type Cell = {
12
10
  elem: HTMLElement;
13
11
  highlighted: boolean;
14
12
  hasBackgroundColor: boolean;
15
13
  x: number;
16
14
  y: number;
17
15
  };
18
- export declare type Cells = Array<Array<Cell>>;
19
- export declare type Grid = {
16
+ export type Cells = Array<Array<Cell>>;
17
+ export type Grid = {
20
18
  cells: Cells;
21
19
  columns: number;
22
20
  rows: number;
@@ -10,14 +10,14 @@ import type { Cell, Grid } from './LexicalTableSelection';
10
10
  import type { GridSelection, LexicalEditor, LexicalNode, RangeSelection } from 'lexical';
11
11
  import { TableSelection } from './LexicalTableSelection';
12
12
  declare const LEXICAL_ELEMENT_KEY = "__lexicalTableSelection";
13
- export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor): TableSelection;
14
- export declare type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableSelection>;
13
+ export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor, hasTabHandler: boolean): TableSelection;
14
+ export type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableSelection>;
15
15
  export declare function attachTableSelectionToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableSelection: TableSelection): void;
16
16
  export declare function getTableSelectionFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableSelection | null;
17
17
  export declare function getCellFromTarget(node: Node): Cell | null;
18
18
  export declare function doesTargetContainText(node: Node): boolean;
19
19
  export declare function getTableGrid(tableElement: HTMLElement): Grid;
20
- export declare function $updateDOMForSelection(editor: LexicalEditor, grid: Grid, selection: GridSelection | RangeSelection | null): Array<Cell>;
20
+ export declare function $updateDOMForSelection(editor: LexicalEditor, grid: Grid, selection: GridSelection | RangeSelection | null): void;
21
21
  export declare function $forEachGridCell(grid: Grid, cb: (cell: Cell, lexicalNode: LexicalNode, cords: {
22
22
  x: number;
23
23
  y: number;
@@ -17,7 +17,7 @@ export declare function $getTableRowNodeFromTableCellNodeOrThrow(startingNode: L
17
17
  export declare function $getTableNodeFromLexicalNodeOrThrow(startingNode: LexicalNode): TableNode;
18
18
  export declare function $getTableRowIndexFromTableCellNode(tableCellNode: TableCellNode): number;
19
19
  export declare function $getTableColumnIndexFromTableCellNode(tableCellNode: TableCellNode): number;
20
- export declare type TableCellSiblings = {
20
+ export type TableCellSiblings = {
21
21
  above: TableCellNode | null | undefined;
22
22
  below: TableCellNode | null | undefined;
23
23
  left: TableCellNode | null | undefined;
package/index.d.ts CHANGED
@@ -18,11 +18,11 @@ export { TableSelection } from './LexicalTableSelection';
18
18
  export type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
19
19
  export { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement, } from './LexicalTableSelectionHelpers';
20
20
  export { $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
21
- export declare type InsertTableCommandPayloadHeaders = Readonly<{
21
+ export type InsertTableCommandPayloadHeaders = Readonly<{
22
22
  rows: boolean;
23
23
  columns: boolean;
24
24
  }> | boolean;
25
- export declare type InsertTableCommandPayload = Readonly<{
25
+ export type InsertTableCommandPayload = Readonly<{
26
26
  columns: string;
27
27
  rows: string;
28
28
  includeHeaders?: InsertTableCommandPayloadHeaders;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.11.1",
11
+ "version": "0.11.3",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.11.1"
14
+ "lexical": "0.11.3"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.11.1"
17
+ "@lexical/utils": "0.11.3"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",