@lexical/table 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalTable.dev.js +221 -367
- package/LexicalTable.prod.js +61 -65
- package/LexicalTableCellNode.d.ts +2 -2
- package/LexicalTableNode.d.ts +1 -1
- package/LexicalTableRowNode.d.ts +1 -1
- package/LexicalTableSelection.d.ts +3 -5
- package/LexicalTableSelectionHelpers.d.ts +3 -3
- package/LexicalTableUtils.d.ts +1 -1
- package/index.d.ts +2 -2
- package/package.json +3 -3
package/LexicalTable.dev.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
|
9
9
|
var lexical = require('lexical');
|
10
10
|
var utils = require('@lexical/utils');
|
11
|
+
var table = require('@lexical/table');
|
11
12
|
|
12
13
|
/**
|
13
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
@@ -501,6 +502,7 @@ class TableSelection {
|
|
501
502
|
throw new Error('Expected to find TableElement in DOM');
|
502
503
|
}
|
503
504
|
|
505
|
+
utils.removeClassNamesFromElement(tableElement, editor._config.theme.tableSelection);
|
504
506
|
tableElement.classList.remove('disable-selection');
|
505
507
|
this.hasHijackedSelectionStyles = false;
|
506
508
|
});
|
@@ -515,7 +517,7 @@ class TableSelection {
|
|
515
517
|
throw new Error('Expected to find TableElement in DOM');
|
516
518
|
}
|
517
519
|
|
518
|
-
tableElement.
|
520
|
+
utils.addClassNamesToElement(tableElement, editor._config.theme.tableSelection);
|
519
521
|
this.hasHijackedSelectionStyles = true;
|
520
522
|
});
|
521
523
|
}
|
@@ -683,7 +685,7 @@ class TableSelection {
|
|
683
685
|
*
|
684
686
|
*/
|
685
687
|
const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
|
686
|
-
function applyTableHandlers(tableNode, tableElement, editor) {
|
688
|
+
function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
687
689
|
const rootElement = editor.getRootElement();
|
688
690
|
|
689
691
|
if (rootElement === null) {
|
@@ -691,65 +693,42 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
691
693
|
}
|
692
694
|
|
693
695
|
const tableSelection = new TableSelection(editor, tableNode.getKey());
|
696
|
+
const editorWindow = editor._window || window;
|
694
697
|
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
698
|
tableElement.addEventListener('mousedown', event => {
|
711
699
|
setTimeout(() => {
|
712
700
|
if (event.button !== 0) {
|
713
701
|
return;
|
714
702
|
}
|
715
703
|
|
716
|
-
|
717
|
-
|
718
|
-
if (cell !== null) {
|
719
|
-
event.preventDefault();
|
720
|
-
event.stopPropagation();
|
721
|
-
event.stopImmediatePropagation();
|
722
|
-
tableSelection.setAnchorCellForSelection(cell);
|
704
|
+
if (!editorWindow) {
|
705
|
+
return;
|
723
706
|
}
|
724
|
-
}, 0);
|
725
|
-
}); // This is adjusting the focus of the selection.
|
726
707
|
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
708
|
+
const anchorCell = getCellFromTarget(event.target);
|
709
|
+
|
710
|
+
if (anchorCell !== null) {
|
711
|
+
stopEvent(event);
|
712
|
+
tableSelection.setAnchorCellForSelection(anchorCell);
|
713
|
+
}
|
733
714
|
|
734
|
-
|
735
|
-
|
715
|
+
const onMouseUp = () => {
|
716
|
+
editorWindow.removeEventListener('mouseup', onMouseUp);
|
717
|
+
editorWindow.removeEventListener('mousemove', onMouseMove);
|
718
|
+
};
|
736
719
|
|
737
|
-
|
738
|
-
const
|
739
|
-
const cellY = cell.y;
|
720
|
+
const onMouseMove = moveEvent => {
|
721
|
+
const focusCell = getCellFromTarget(moveEvent.target);
|
740
722
|
|
741
|
-
if (
|
742
|
-
|
743
|
-
tableSelection.setFocusCellForSelection(
|
723
|
+
if (focusCell !== null && (tableSelection.anchorX !== focusCell.x || tableSelection.anchorY !== focusCell.y)) {
|
724
|
+
moveEvent.preventDefault();
|
725
|
+
tableSelection.setFocusCellForSelection(focusCell);
|
744
726
|
}
|
745
|
-
}
|
746
|
-
}
|
747
|
-
}); // Select entire table at this point, when grid selection is ready.
|
727
|
+
};
|
748
728
|
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
}
|
729
|
+
editorWindow.addEventListener('mouseup', onMouseUp);
|
730
|
+
editorWindow.addEventListener('mousemove', onMouseMove);
|
731
|
+
}, 0);
|
753
732
|
}); // Clear selection when clicking outside of dom.
|
754
733
|
|
755
734
|
const mouseDownCallback = event => {
|
@@ -761,251 +740,29 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
761
740
|
const selection = lexical.$getSelection();
|
762
741
|
const target = event.target;
|
763
742
|
|
764
|
-
if (
|
765
|
-
|
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
|
-
}
|
743
|
+
if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(target)) {
|
744
|
+
tableSelection.clearHighlight();
|
775
745
|
}
|
776
746
|
});
|
777
747
|
};
|
778
748
|
|
779
|
-
|
780
|
-
tableSelection.listenersToRemove.add(() =>
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
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 => {
|
749
|
+
editorWindow.addEventListener('mousedown', mouseDownCallback);
|
750
|
+
tableSelection.listenersToRemove.add(() => editorWindow.removeEventListener('mousedown', mouseDownCallback));
|
751
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => $handleArrowKey(editor, event, 'down', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
|
752
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => $handleArrowKey(editor, event, 'up', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
|
753
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, event => $handleArrowKey(editor, event, 'backward', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
|
754
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => $handleArrowKey(editor, event, 'forward', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
|
755
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, event => {
|
852
756
|
const selection = lexical.$getSelection();
|
853
757
|
|
854
|
-
if (
|
855
|
-
|
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();
|
758
|
+
if (lexical.DEPRECATED_$isGridSelection(selection)) {
|
759
|
+
const focusCellNode = utils.$findMatchingParent(selection.focus.getNode(), $isTableCellNode);
|
999
760
|
|
1000
|
-
if (
|
1001
|
-
|
761
|
+
if ($isTableCellNode(focusCellNode)) {
|
762
|
+
stopEvent(event);
|
763
|
+
focusCellNode.selectEnd();
|
764
|
+
return true;
|
1002
765
|
}
|
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
766
|
}
|
1010
767
|
|
1011
768
|
return false;
|
@@ -1137,72 +894,69 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
1137
894
|
|
1138
895
|
return false;
|
1139
896
|
}, 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
897
|
|
1147
|
-
|
1148
|
-
|
898
|
+
if (hasTabHandler) {
|
899
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
900
|
+
const selection = lexical.$getSelection();
|
1149
901
|
|
1150
|
-
if (!$
|
902
|
+
if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed() || !$isSelectionInTable(selection, tableNode)) {
|
1151
903
|
return false;
|
1152
904
|
}
|
1153
905
|
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
return true;
|
906
|
+
const tableCellNode = $findCellNode(selection.anchor.getNode());
|
907
|
+
|
908
|
+
if (tableCellNode === null) {
|
909
|
+
return false;
|
1159
910
|
}
|
1160
|
-
}
|
1161
911
|
|
1162
|
-
|
1163
|
-
|
912
|
+
stopEvent(event);
|
913
|
+
const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
|
914
|
+
selectGridNodeInDirection(tableSelection, tableNode, currentCords.x, currentCords.y, !event.shiftKey ? 'forward' : 'backward');
|
915
|
+
return true;
|
916
|
+
}, lexical.COMMAND_PRIORITY_CRITICAL));
|
917
|
+
}
|
918
|
+
|
1164
919
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.FOCUS_COMMAND, payload => {
|
1165
920
|
return tableNode.isSelected();
|
1166
921
|
}, lexical.COMMAND_PRIORITY_HIGH));
|
1167
|
-
|
922
|
+
|
923
|
+
function getCellFromCellNode(tableCellNode) {
|
924
|
+
const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
|
925
|
+
return tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid);
|
926
|
+
}
|
927
|
+
|
928
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, () => {
|
1168
929
|
const selection = lexical.$getSelection();
|
1169
930
|
const prevSelection = lexical.$getPreviousSelection();
|
1170
931
|
|
1171
|
-
if (
|
1172
|
-
const
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
const
|
1177
|
-
const
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
932
|
+
if (lexical.$isRangeSelection(selection)) {
|
933
|
+
const {
|
934
|
+
anchor,
|
935
|
+
focus
|
936
|
+
} = selection;
|
937
|
+
const anchorNode = anchor.getNode();
|
938
|
+
const focusNode = focus.getNode(); // Using explicit comparison with table node to ensure it's not a nested table
|
939
|
+
// as in that case we'll leave selection resolving to that table
|
940
|
+
|
941
|
+
const anchorCellNode = $findCellNode(anchorNode);
|
942
|
+
const focusCellNode = $findCellNode(focusNode);
|
943
|
+
const isAnchorInside = anchorCellNode && tableNode.is($findTableNode(anchorCellNode));
|
944
|
+
const isFocusInside = focusCellNode && tableNode.is($findTableNode(focusCellNode));
|
945
|
+
const isPartialyWithinTable = isAnchorInside !== isFocusInside;
|
946
|
+
const isWithinTable = isAnchorInside && isFocusInside;
|
947
|
+
const isBackward = selection.isBackward();
|
948
|
+
|
949
|
+
if (isPartialyWithinTable) {
|
950
|
+
const newSelection = selection.clone();
|
951
|
+
newSelection.focus.set(tableNode.getKey(), isBackward ? 0 : tableNode.getChildrenSize(), 'element');
|
952
|
+
lexical.$setSelection(newSelection);
|
1187
953
|
$addHighlightStyleToTable(editor, tableSelection);
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
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
|
-
}
|
954
|
+
} else if (isWithinTable) {
|
955
|
+
// Handle case when selection spans across multiple cells but still
|
956
|
+
// has range selection, then we convert it into grid selection
|
957
|
+
if (!anchorCellNode.is(focusCellNode)) {
|
958
|
+
tableSelection.setAnchorCellForSelection(getCellFromCellNode(anchorCellNode));
|
959
|
+
tableSelection.setFocusCellForSelection(getCellFromCellNode(focusCellNode), true);
|
1206
960
|
}
|
1207
961
|
}
|
1208
962
|
}
|
@@ -1219,7 +973,6 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
1219
973
|
|
1220
974
|
if (tableSelection.hasHijackedSelectionStyles && !tableNode.isSelected()) {
|
1221
975
|
$removeHighlightStyleToTable(editor, tableSelection);
|
1222
|
-
isRangeSelectionHijacked = false;
|
1223
976
|
} else if (!tableSelection.hasHijackedSelectionStyles && tableNode.isSelected()) {
|
1224
977
|
$addHighlightStyleToTable(editor, tableSelection);
|
1225
978
|
}
|
@@ -1256,19 +1009,6 @@ function getCellFromTarget(node) {
|
|
1256
1009
|
|
1257
1010
|
return null;
|
1258
1011
|
}
|
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
1012
|
function getTableGrid(tableElement) {
|
1273
1013
|
const cells = [];
|
1274
1014
|
const grid = {
|
@@ -1338,7 +1078,6 @@ function getTableGrid(tableElement) {
|
|
1338
1078
|
return grid;
|
1339
1079
|
}
|
1340
1080
|
function $updateDOMForSelection(editor, grid, selection) {
|
1341
|
-
const highlightedCells = [];
|
1342
1081
|
const selectedCellNodes = new Set(selection ? selection.getNodes() : []);
|
1343
1082
|
$forEachGridCell(grid, (cell, lexicalNode) => {
|
1344
1083
|
const elem = cell.elem;
|
@@ -1346,7 +1085,6 @@ function $updateDOMForSelection(editor, grid, selection) {
|
|
1346
1085
|
if (selectedCellNodes.has(lexicalNode)) {
|
1347
1086
|
cell.highlighted = true;
|
1348
1087
|
$addHighlightToDOM(editor, cell);
|
1349
|
-
highlightedCells.push(cell);
|
1350
1088
|
} else {
|
1351
1089
|
cell.highlighted = false;
|
1352
1090
|
$removeHighlightFromDOM(editor, cell);
|
@@ -1356,7 +1094,6 @@ function $updateDOMForSelection(editor, grid, selection) {
|
|
1356
1094
|
}
|
1357
1095
|
}
|
1358
1096
|
});
|
1359
|
-
return highlightedCells;
|
1360
1097
|
}
|
1361
1098
|
function $forEachGridCell(grid, cb) {
|
1362
1099
|
const {
|
@@ -1406,10 +1143,10 @@ const selectGridNodeInDirection = (tableSelection, tableNode, x, y, direction) =
|
|
1406
1143
|
case 'backward':
|
1407
1144
|
case 'forward':
|
1408
1145
|
if (x !== (isForward ? tableSelection.grid.columns - 1 : 0)) {
|
1409
|
-
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x + (isForward ? 1 : -1), y, tableSelection.grid));
|
1146
|
+
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x + (isForward ? 1 : -1), y, tableSelection.grid), isForward);
|
1410
1147
|
} else {
|
1411
1148
|
if (y !== (isForward ? tableSelection.grid.rows - 1 : 0)) {
|
1412
|
-
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(isForward ? 0 : tableSelection.grid.columns - 1, y + (isForward ? 1 : -1), tableSelection.grid));
|
1149
|
+
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(isForward ? 0 : tableSelection.grid.columns - 1, y + (isForward ? 1 : -1), tableSelection.grid), isForward);
|
1413
1150
|
} else if (!isForward) {
|
1414
1151
|
tableNode.selectPrevious();
|
1415
1152
|
} else {
|
@@ -1421,7 +1158,7 @@ const selectGridNodeInDirection = (tableSelection, tableNode, x, y, direction) =
|
|
1421
1158
|
|
1422
1159
|
case 'up':
|
1423
1160
|
if (y !== 0) {
|
1424
|
-
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y - 1, tableSelection.grid));
|
1161
|
+
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y - 1, tableSelection.grid), false);
|
1425
1162
|
} else {
|
1426
1163
|
tableNode.selectPrevious();
|
1427
1164
|
}
|
@@ -1430,7 +1167,7 @@ const selectGridNodeInDirection = (tableSelection, tableNode, x, y, direction) =
|
|
1430
1167
|
|
1431
1168
|
case 'down':
|
1432
1169
|
if (y !== tableSelection.grid.rows - 1) {
|
1433
|
-
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y + 1, tableSelection.grid));
|
1170
|
+
selectTableCellNode(tableNode.getCellNodeFromCordsOrThrow(x, y + 1, tableSelection.grid), true);
|
1434
1171
|
} else {
|
1435
1172
|
tableNode.selectNext();
|
1436
1173
|
}
|
@@ -1485,11 +1222,9 @@ function $isSelectionInTable(selection, tableNode) {
|
|
1485
1222
|
return false;
|
1486
1223
|
}
|
1487
1224
|
|
1488
|
-
function selectTableCellNode(tableCell) {
|
1489
|
-
|
1490
|
-
|
1491
|
-
if (lexical.$isParagraphNode(possibleParagraph)) {
|
1492
|
-
possibleParagraph.selectEnd();
|
1225
|
+
function selectTableCellNode(tableCell, fromStart) {
|
1226
|
+
if (fromStart) {
|
1227
|
+
tableCell.selectStart();
|
1493
1228
|
} else {
|
1494
1229
|
tableCell.selectEnd();
|
1495
1230
|
}
|
@@ -1534,6 +1269,125 @@ function $removeHighlightFromDOM(editor, cell) {
|
|
1534
1269
|
element.style.removeProperty('caret-color');
|
1535
1270
|
}
|
1536
1271
|
|
1272
|
+
function $findCellNode(node) {
|
1273
|
+
const cellNode = utils.$findMatchingParent(node, $isTableCellNode);
|
1274
|
+
return $isTableCellNode(cellNode) ? cellNode : null;
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
function $findTableNode(node) {
|
1278
|
+
const tableNode = utils.$findMatchingParent(node, table.$isTableNode);
|
1279
|
+
return table.$isTableNode(tableNode) ? tableNode : null;
|
1280
|
+
}
|
1281
|
+
|
1282
|
+
function $handleArrowKey(editor, event, direction, tableNode, tableSelection) {
|
1283
|
+
const selection = lexical.$getSelection();
|
1284
|
+
|
1285
|
+
if (!$isSelectionInTable(selection, tableNode)) {
|
1286
|
+
return false;
|
1287
|
+
}
|
1288
|
+
|
1289
|
+
if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
|
1290
|
+
// Horizontal move between cels seem to work well without interruption
|
1291
|
+
// so just exit early, and handle vertical moves
|
1292
|
+
if (direction === 'backward' || direction === 'forward') {
|
1293
|
+
return false;
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
const {
|
1297
|
+
anchor,
|
1298
|
+
focus
|
1299
|
+
} = selection;
|
1300
|
+
const anchorCellNode = utils.$findMatchingParent(anchor.getNode(), $isTableCellNode);
|
1301
|
+
const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
|
1302
|
+
|
1303
|
+
if (!$isTableCellNode(anchorCellNode) || !anchorCellNode.is(focusCellNode)) {
|
1304
|
+
return false;
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
const anchorCellDom = editor.getElementByKey(anchorCellNode.__key);
|
1308
|
+
const anchorDOM = editor.getElementByKey(anchor.key);
|
1309
|
+
|
1310
|
+
if (anchorDOM == null || anchorCellDom == null) {
|
1311
|
+
return false;
|
1312
|
+
}
|
1313
|
+
|
1314
|
+
let edgeSelectionRect;
|
1315
|
+
|
1316
|
+
if (anchor.type === 'element') {
|
1317
|
+
edgeSelectionRect = anchorDOM.getBoundingClientRect();
|
1318
|
+
} else {
|
1319
|
+
const domSelection = window.getSelection();
|
1320
|
+
|
1321
|
+
if (domSelection === null || domSelection.rangeCount === 0) {
|
1322
|
+
return false;
|
1323
|
+
}
|
1324
|
+
|
1325
|
+
const range = domSelection.getRangeAt(0);
|
1326
|
+
edgeSelectionRect = range.getBoundingClientRect();
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
const edgeChild = direction === 'up' ? anchorCellNode.getFirstChild() : anchorCellNode.getLastChild();
|
1330
|
+
|
1331
|
+
if (edgeChild == null) {
|
1332
|
+
return false;
|
1333
|
+
}
|
1334
|
+
|
1335
|
+
const edgeChildDOM = editor.getElementByKey(edgeChild.__key);
|
1336
|
+
|
1337
|
+
if (edgeChildDOM == null) {
|
1338
|
+
return false;
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
const edgeRect = edgeChildDOM.getBoundingClientRect();
|
1342
|
+
const isExiting = direction === 'up' ? edgeRect.top > edgeSelectionRect.top - edgeSelectionRect.height : edgeSelectionRect.bottom + edgeSelectionRect.height > edgeRect.bottom;
|
1343
|
+
|
1344
|
+
if (isExiting) {
|
1345
|
+
stopEvent(event);
|
1346
|
+
const cords = tableNode.getCordsFromCellNode(anchorCellNode, tableSelection.grid);
|
1347
|
+
|
1348
|
+
if (event.shiftKey) {
|
1349
|
+
const cell = tableNode.getCellFromCordsOrThrow(cords.x, cords.y, tableSelection.grid);
|
1350
|
+
tableSelection.setAnchorCellForSelection(cell);
|
1351
|
+
tableSelection.setFocusCellForSelection(cell, true);
|
1352
|
+
} else {
|
1353
|
+
return selectGridNodeInDirection(tableSelection, tableNode, cords.x, cords.y, direction);
|
1354
|
+
}
|
1355
|
+
|
1356
|
+
return true;
|
1357
|
+
}
|
1358
|
+
} else if (lexical.DEPRECATED_$isGridSelection(selection)) {
|
1359
|
+
const {
|
1360
|
+
anchor,
|
1361
|
+
focus
|
1362
|
+
} = selection;
|
1363
|
+
const anchorCellNode = utils.$findMatchingParent(anchor.getNode(), $isTableCellNode);
|
1364
|
+
const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
|
1365
|
+
|
1366
|
+
if (!$isTableCellNode(anchorCellNode) || !$isTableCellNode(focusCellNode)) {
|
1367
|
+
return false;
|
1368
|
+
}
|
1369
|
+
|
1370
|
+
stopEvent(event);
|
1371
|
+
|
1372
|
+
if (event.shiftKey) {
|
1373
|
+
const cords = tableNode.getCordsFromCellNode(focusCellNode, tableSelection.grid);
|
1374
|
+
return adjustFocusNodeInDirection(tableSelection, tableNode, cords.x, cords.y, direction);
|
1375
|
+
} else {
|
1376
|
+
focusCellNode.selectEnd();
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
return true;
|
1380
|
+
}
|
1381
|
+
|
1382
|
+
return false;
|
1383
|
+
}
|
1384
|
+
|
1385
|
+
function stopEvent(event) {
|
1386
|
+
event.preventDefault();
|
1387
|
+
event.stopImmediatePropagation();
|
1388
|
+
event.stopPropagation();
|
1389
|
+
}
|
1390
|
+
|
1537
1391
|
/**
|
1538
1392
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
1539
1393
|
*
|
@@ -2007,14 +1861,14 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
|
2007
1861
|
throw Error(`Expected a RangeSelection or GridSelection`);
|
2008
1862
|
}
|
2009
1863
|
|
1864
|
+
const anchor = selection.anchor.getNode();
|
2010
1865
|
const focus = selection.focus.getNode();
|
1866
|
+
const [anchorCell] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
2011
1867
|
const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
2012
|
-
const [gridMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell,
|
1868
|
+
const [gridMap, focusCellMap, anchorCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, anchorCell);
|
2013
1869
|
const rowCount = gridMap.length;
|
2014
|
-
const
|
2015
|
-
|
2016
|
-
} = focusCellMap;
|
2017
|
-
const insertAfterColumn = insertAfter ? focusStartColumn + focusCell.__colSpan - 1 : focusStartColumn - 1;
|
1870
|
+
const startColumn = insertAfter ? Math.max(focusCellMap.startColumn, anchorCellMap.startColumn) : Math.min(focusCellMap.startColumn, anchorCellMap.startColumn);
|
1871
|
+
const insertAfterColumn = insertAfter ? startColumn + focusCell.__colSpan - 1 : startColumn - 1;
|
2018
1872
|
const gridFirstChild = grid.getFirstChild();
|
2019
1873
|
|
2020
1874
|
if (!lexical.DEPRECATED_$isGridRowNode(gridFirstChild)) {
|
package/LexicalTable.prod.js
CHANGED
@@ -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"),
|
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:
|
9
|
-
b=1,
|
7
|
+
'use strict';var d=require("lexical"),t=require("@lexical/utils"),w=require("@lexical/table");let x=/^(\d+(?:\.\d+)?)px$/,y={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:B,priority:0}),th:()=>({conversion:B,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=C(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=y.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
|
-
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!==
|
13
|
-
function
|
14
|
-
function
|
15
|
-
class
|
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;
|
17
|
-
function
|
18
|
-
class
|
19
|
-
{this.editor.update(()=>{var
|
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(!
|
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.
|
22
|
-
a&&a.gridKey===this.tableNodeKey){let b=this.editor;this.gridSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();
|
23
|
-
ba?(
|
24
|
-
d.DEPRECATED_$createGridSelection(),this.focusCellNodeKey=
|
25
|
-
this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||
|
26
|
-
if(!
|
27
|
-
function
|
28
|
-
function
|
29
|
-
function
|
30
|
-
function
|
31
|
-
let
|
32
|
-
default:return!1}},
|
33
|
-
function
|
34
|
-
function
|
35
|
-
function
|
36
|
-
|
37
|
-
c
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
c
|
45
|
-
exports.$
|
46
|
-
|
47
|
-
|
48
|
-
exports.$
|
49
|
-
|
50
|
-
|
51
|
-
exports.$
|
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!==y.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 B(a){var b=a.nodeName.toLowerCase();let c=void 0;x.test(a.style.width)&&(c=parseFloat(a.style.width));b=C("th"===b?y.ROW:y.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{forChild:(e,g)=>{if(D(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 C(a,b=1,c){return d.$applyNodeReplacement(new z(a,b,c))}
|
14
|
+
function D(a){return a instanceof z}
|
15
|
+
class E extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new E(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:aa,priority:0})}}static importJSON(a){return F(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
|
+
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;x.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:F(b)}}function F(a){return d.$applyNodeReplacement(new E(a))}function G(a){return a instanceof E}
|
17
|
+
function I(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 J{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=K(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=K(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(!L(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=K(b);M(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();M(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(!L(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
|
+
D(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),M(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
|
+
D(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)||I(11);let c=d.$createRangeSelection(),e=c.anchor,g=c.focus;b.getNodes().forEach(h=>{D(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(!L(b))throw Error("Expected TableNode.");var c=d.$getSelection();d.DEPRECATED_$isGridSelection(c)||I(11);c=c.getNodes().filter(D);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()})}}),M(a,this.grid,null),d.$setSelection(null),
|
27
|
+
a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}function N(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 K(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 M(a,b,c){let e=new Set(c?c.getNodes():[]);O(b,(g,h)=>{let f=g.elem;e.has(h)?(g.highlighted=!0,ca(a,g)):(g.highlighted=!1,da(a,g),f.getAttribute("style")||f.removeAttribute("style"))})}function O(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 ea(a,b){b.disableHighlightStyle();O(b.grid,c=>{c.highlighted=!0;ca(a,c)})}
|
30
|
+
function fa(a,b){b.enableHighlightStyle();O(b.grid,c=>{let e=c.elem;c.highlighted=!1;da(a,c);e.getAttribute("style")||e.removeAttribute("style")})}
|
31
|
+
let 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=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}},ia=(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 ca(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);D(b)||I(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 da(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);D(b)||I(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,D);return D(a)?a:null}function ja(a){a=t.$findMatchingParent(a,w.$isTableNode);return w.$isTableNode(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(),D);var f=t.$findMatchingParent(r.getNode(),D);if(!D(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 ha(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
|
+
D);a=t.$findMatchingParent(r.getNode(),D);if(!D(h)||!D(a))return!1;S(b);if(b.shiftKey)return b=e.getCordsFromCellNode(a,g.grid),ia(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:ka,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(!G(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 D(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 ka(){return{node:U()}}function U(){return d.$applyNodeReplacement(new T)}function L(a){return a instanceof T}function W(a){a=t.$findMatchingParent(a,b=>G(b));if(G(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=t.$findMatchingParent(a,b=>L(b));if(L(a))return a;throw Error("Expected table cell to be inside of table.");}
|
43
|
+
function la(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&&I(124);a.getParentOrThrow().selectStart()}function Z(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}let ma=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=C;exports.$createTableNode=U;
|
44
|
+
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let e=U();for(let h=0;h<a;h++){let f=F();for(let m=0;m<b;m++){var g=y.NO_STATUS;"object"===typeof c?(0===h&&c.rows&&(g|=y.ROW),0===m&&c.columns&&(g|=y.COLUMN)):c&&(0===h&&(g|=y.ROW),0===m&&(g|=y.COLUMN));g=C(g);let q=d.$createParagraphNode();q.append(d.$createTextNode());g.append(q);f.append(g)}e.append(f)}return e};exports.$createTableRowNode=F;
|
45
|
+
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let g=0;g<c.length;g++){var e=c[g];if(G(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)||I(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)||I(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&&I(122),0===k)Z(r,n);else{let {cell:u}=q[k-1];u.insertAfter(n)}}k=e.getChildAtIndex(l);d.DEPRECATED_$isGridRowNode(k)||I(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 K(a)};
|
50
|
+
exports.$getTableCellNodeFromLexicalNode=function(a){a=t.$findMatchingParent(a,b=>D(b));return D(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(G(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];D(f)||I(12);let {left:l,right:n}=la(f,g);var m=y.NO_STATUS;if(l&&l.hasHeaderState(y.ROW)||n&&n.hasHeaderState(y.ROW))m|=y.ROW;m=C(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=C(y.NO_STATUS).append(d.$createParagraphNode());null===r&&(r=l);return l}var c=d.$getSelection();d.$isRangeSelection(c)||d.DEPRECATED_$isGridSelection(c)||I(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)||I(120);let r=null;var k=c;a:for(c=0;c<e;c++){0!==c&&(k=k.getNextSibling(),d.DEPRECATED_$isGridRowNode(k)||I(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:na}=l[H];u=V;A=na}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(G(b))for(h=0;h<e;h++){let m=b.getChildren(),q=m.length,r=F();for(let k=0;k<q;k++){var f=m[k];D(f)||I(12);let {above:l,below:n}=la(f,g);f=y.NO_STATUS;let p=l&&l.getWidth()||n&&n.getWidth()||void 0;if(l&&l.hasHeaderState(y.COLUMN)||n&&n.hasHeaderState(y.COLUMN))f|=y.COLUMN;f=C(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)||
|
54
|
-
b.insertAfter(
|
55
|
-
exports.$unmergeCell=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||
|
56
|
-
|
57
|
-
exports.applyTableHandlers=function(a,b,f)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if(
|
67
|
-
|
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)||I(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=F();for(var q=0;q<b;q++){let {cell:r,startRow:k}=m[q];k+r.__rowSpan-1<=a?f.append(C(y.NO_STATUS)):r.setRowSpan(r.__rowSpan+1)}b=e.getChildAtIndex(a);d.DEPRECATED_$isGridRowNode(b)||I(119);
|
57
|
+
b.insertAfter(f)}else{m=g[f];a=F();for(q=0;q<b;q++){let {cell:r,startRow:k}=m[q];k===f?a.append(C(y.NO_STATUS)):r.setRowSpan(r.__rowSpan+1)}b=e.getChildAtIndex(f);d.DEPRECATED_$isGridRowNode(b)||I(119);b.insertBefore(a)}};exports.$isTableCellNode=D;exports.$isTableNode=L;exports.$isTableRowNode=G;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)||I(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(C(y.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)||I(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,C(y.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(C(y.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ma;exports.TableCellHeaderStates=y;exports.TableCellNode=z;exports.TableNode=T;exports.TableRowNode=E;exports.TableSelection=J;
|
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 J(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=N(k.target);null!==l&&(S(k),f.setAnchorCellForSelection(l));var n=()=>{m.removeEventListener("mouseup",n);m.removeEventListener("mousemove",
|
61
|
+
p)},p=v=>{const u=N(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(),D),D(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=>D(u));if(!D(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)&&D(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=>D(n)),D(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=>D(n)),D(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=>D(l)),D(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);ha(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(ja(n)),u=p&&a.is(ja(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),ea(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()?fa(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&ea(c,f);return!1},d.COMMAND_PRIORITY_CRITICAL));
|
70
|
+
return f};exports.getCellFromTarget=N;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
|
17
|
-
export
|
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;
|
package/LexicalTableNode.d.ts
CHANGED
@@ -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
|
12
|
+
export type SerializedTableNode = SerializedElementNode;
|
13
13
|
/** @noInheritDoc */
|
14
14
|
export declare class TableNode extends DEPRECATED_GridNode {
|
15
15
|
/** @internal */
|
package/LexicalTableRowNode.d.ts
CHANGED
@@ -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
|
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
|
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
|
19
|
-
export
|
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
|
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):
|
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;
|
package/LexicalTableUtils.d.ts
CHANGED
@@ -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
|
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
|
21
|
+
export type InsertTableCommandPayloadHeaders = Readonly<{
|
22
22
|
rows: boolean;
|
23
23
|
columns: boolean;
|
24
24
|
}> | boolean;
|
25
|
-
export
|
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.
|
11
|
+
"version": "0.11.2",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"peerDependencies": {
|
14
|
-
"lexical": "0.11.
|
14
|
+
"lexical": "0.11.2"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@lexical/utils": "0.11.
|
17
|
+
"@lexical/utils": "0.11.2"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|