@atlaskit/editor-plugin-table 7.16.11 → 7.16.13
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/.eslintrc.js +3 -3
- package/CHANGELOG.md +16 -0
- package/dist/cjs/commands/misc.js +3 -3
- package/dist/cjs/nodeviews/TableCell.js +10 -10
- package/dist/cjs/nodeviews/TableContainer.js +83 -27
- package/dist/cjs/nodeviews/TableResizer.js +40 -19
- package/dist/cjs/nodeviews/TableRow.js +23 -23
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/cjs/ui/common-styles.js +13 -13
- package/dist/cjs/ui/ui-styles.js +25 -25
- package/dist/cjs/utils/guidelines.js +7 -4
- package/dist/cjs/utils/merged-cells.js +3 -3
- package/dist/cjs/utils/snapping.js +7 -8
- package/dist/es2019/commands/misc.js +3 -3
- package/dist/es2019/nodeviews/TableContainer.js +70 -9
- package/dist/es2019/nodeviews/TableResizer.js +42 -21
- package/dist/es2019/nodeviews/TableRow.js +21 -21
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/es2019/ui/FloatingContextualMenu/styles.js +47 -47
- package/dist/es2019/ui/FloatingDragMenu/styles.js +30 -30
- package/dist/es2019/ui/common-styles.js +802 -816
- package/dist/es2019/ui/ui-styles.js +665 -678
- package/dist/es2019/utils/guidelines.js +5 -2
- package/dist/es2019/utils/merged-cells.js +3 -3
- package/dist/es2019/utils/snapping.js +5 -6
- package/dist/esm/commands/misc.js +3 -3
- package/dist/esm/nodeviews/TableCell.js +10 -10
- package/dist/esm/nodeviews/TableContainer.js +85 -29
- package/dist/esm/nodeviews/TableResizer.js +42 -21
- package/dist/esm/nodeviews/TableRow.js +23 -23
- package/dist/esm/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/esm/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/esm/ui/common-styles.js +13 -13
- package/dist/esm/ui/ui-styles.js +25 -25
- package/dist/esm/utils/guidelines.js +6 -3
- package/dist/esm/utils/merged-cells.js +3 -3
- package/dist/esm/utils/snapping.js +6 -7
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types/utils/guidelines.d.ts +2 -1
- package/dist/types/utils/snapping.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types-ts4.5/utils/guidelines.d.ts +2 -1
- package/dist/types-ts4.5/utils/snapping.d.ts +3 -2
- package/docs/0-intro.tsx +9 -7
- package/package.json +3 -3
- package/report.api.md +67 -66
- package/src/commands/clear.ts +36 -44
- package/src/commands/collapse.ts +8 -8
- package/src/commands/column-resize.ts +412 -452
- package/src/commands/delete.ts +14 -14
- package/src/commands/display-mode.ts +10 -11
- package/src/commands/go-to-next-cell.ts +48 -54
- package/src/commands/hover.ts +210 -227
- package/src/commands/index.ts +35 -35
- package/src/commands/insert.ts +208 -235
- package/src/commands/misc.ts +655 -748
- package/src/commands/referentiality.ts +9 -9
- package/src/commands/selection.ts +433 -563
- package/src/commands/sort.ts +68 -86
- package/src/commands/split-cell.ts +14 -14
- package/src/commands/toggle.ts +69 -67
- package/src/commands-with-analytics.ts +570 -639
- package/src/create-plugin-config.ts +13 -13
- package/src/event-handlers.ts +513 -612
- package/src/handlers.ts +120 -133
- package/src/nodeviews/ExternalDropTargets.tsx +68 -73
- package/src/nodeviews/OverflowShadowsObserver.ts +148 -157
- package/src/nodeviews/TableCell.ts +47 -54
- package/src/nodeviews/TableComponent.tsx +1018 -1112
- package/src/nodeviews/TableComponentWithSharedState.tsx +91 -94
- package/src/nodeviews/TableContainer.tsx +384 -340
- package/src/nodeviews/TableNodeViewBase.ts +19 -24
- package/src/nodeviews/TableResizer.tsx +642 -653
- package/src/nodeviews/TableRow.ts +580 -629
- package/src/nodeviews/TableStickyScrollbar.ts +173 -190
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +8 -8
- package/src/nodeviews/__mocks__/OverridableMock.ts +14 -15
- package/src/nodeviews/table.tsx +345 -375
- package/src/nodeviews/types.ts +21 -24
- package/src/nodeviews/update-overflow-shadows.ts +8 -14
- package/src/plugin.tsx +578 -603
- package/src/pm-plugins/analytics/actions.ts +10 -12
- package/src/pm-plugins/analytics/commands.ts +31 -37
- package/src/pm-plugins/analytics/plugin-factory.ts +4 -2
- package/src/pm-plugins/analytics/plugin-key.ts +1 -3
- package/src/pm-plugins/analytics/plugin.ts +60 -70
- package/src/pm-plugins/analytics/reducer.ts +19 -19
- package/src/pm-plugins/analytics/types.ts +10 -10
- package/src/pm-plugins/analytics/utils/moved-event.ts +38 -38
- package/src/pm-plugins/decorations/plugin.ts +58 -77
- package/src/pm-plugins/decorations/utils/column-controls.ts +59 -71
- package/src/pm-plugins/decorations/utils/column-resizing.ts +50 -57
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +6 -6
- package/src/pm-plugins/decorations/utils/index.ts +3 -6
- package/src/pm-plugins/decorations/utils/types.ts +7 -12
- package/src/pm-plugins/default-table-selection.ts +3 -3
- package/src/pm-plugins/drag-and-drop/actions.ts +25 -25
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +158 -190
- package/src/pm-plugins/drag-and-drop/commands.ts +154 -170
- package/src/pm-plugins/drag-and-drop/consts.ts +4 -5
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +23 -20
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +1 -3
- package/src/pm-plugins/drag-and-drop/plugin.ts +329 -383
- package/src/pm-plugins/drag-and-drop/reducer.ts +30 -30
- package/src/pm-plugins/drag-and-drop/types.ts +8 -8
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +38 -41
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +3 -6
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +57 -70
- package/src/pm-plugins/keymap.ts +208 -220
- package/src/pm-plugins/main.ts +348 -400
- package/src/pm-plugins/plugin-factory.ts +32 -34
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +83 -97
- package/src/pm-plugins/sticky-headers/commands.ts +2 -6
- package/src/pm-plugins/sticky-headers/plugin-key.ts +1 -3
- package/src/pm-plugins/sticky-headers/plugin-state.ts +41 -44
- package/src/pm-plugins/sticky-headers/plugin.ts +4 -4
- package/src/pm-plugins/sticky-headers/types.ts +8 -8
- package/src/pm-plugins/sticky-headers/util.ts +10 -10
- package/src/pm-plugins/table-analytics.ts +70 -72
- package/src/pm-plugins/table-local-id.ts +180 -184
- package/src/pm-plugins/table-resizing/commands.ts +72 -85
- package/src/pm-plugins/table-resizing/event-handlers.ts +298 -317
- package/src/pm-plugins/table-resizing/plugin-factory.ts +10 -10
- package/src/pm-plugins/table-resizing/plugin-key.ts +1 -3
- package/src/pm-plugins/table-resizing/plugin.ts +61 -68
- package/src/pm-plugins/table-resizing/reducer.ts +30 -33
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +84 -84
- package/src/pm-plugins/table-resizing/utils/column-state.ts +78 -81
- package/src/pm-plugins/table-resizing/utils/content-width.ts +94 -114
- package/src/pm-plugins/table-resizing/utils/dom.ts +93 -110
- package/src/pm-plugins/table-resizing/utils/index.ts +29 -34
- package/src/pm-plugins/table-resizing/utils/misc.ts +94 -119
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +93 -106
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +240 -257
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +343 -372
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +202 -207
- package/src/pm-plugins/table-resizing/utils/types.ts +17 -17
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +1 -2
- package/src/pm-plugins/table-selection-keymap.ts +25 -51
- package/src/pm-plugins/table-width.ts +191 -204
- package/src/pm-plugins/view-mode-sort/index.ts +223 -227
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +3 -2
- package/src/pm-plugins/view-mode-sort/types.ts +12 -12
- package/src/pm-plugins/view-mode-sort/utils.ts +108 -117
- package/src/reducer.ts +139 -155
- package/src/toolbar.tsx +815 -905
- package/src/transforms/column-width.ts +186 -213
- package/src/transforms/delete-columns.ts +208 -222
- package/src/transforms/delete-rows.ts +117 -121
- package/src/transforms/fix-tables.ts +190 -215
- package/src/transforms/merge.ts +263 -269
- package/src/transforms/replace-table.ts +27 -43
- package/src/transforms/split.ts +65 -75
- package/src/types.ts +421 -427
- package/src/ui/ColumnResizeWidget/index.tsx +40 -47
- package/src/ui/DragHandle/HandleIconComponent.tsx +9 -13
- package/src/ui/DragHandle/index.tsx +221 -250
- package/src/ui/DragPreview/index.tsx +35 -35
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +33 -41
- package/src/ui/FloatingContextualButton/FixedButton.tsx +154 -157
- package/src/ui/FloatingContextualButton/index.tsx +109 -115
- package/src/ui/FloatingContextualButton/styles.ts +43 -46
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +634 -694
- package/src/ui/FloatingContextualMenu/index.tsx +83 -101
- package/src/ui/FloatingContextualMenu/styles.ts +57 -65
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +37 -37
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +47 -57
- package/src/ui/FloatingDeleteButton/index.tsx +319 -350
- package/src/ui/FloatingDragMenu/DragMenu.tsx +555 -596
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +152 -162
- package/src/ui/FloatingDragMenu/index.tsx +88 -102
- package/src/ui/FloatingDragMenu/styles.ts +51 -54
- package/src/ui/FloatingInsertButton/InsertButton.tsx +204 -217
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +100 -115
- package/src/ui/FloatingInsertButton/index.tsx +248 -292
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +24 -29
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +308 -329
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +85 -94
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +46 -46
- package/src/ui/TableFloatingColumnControls/index.tsx +116 -136
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +79 -91
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +95 -102
- package/src/ui/TableFloatingControls/CornerControls/index.tsx +1 -4
- package/src/ui/TableFloatingControls/CornerControls/types.ts +8 -8
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +50 -50
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +111 -124
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +86 -105
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +305 -341
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +72 -75
- package/src/ui/TableFloatingControls/index.tsx +191 -193
- package/src/ui/TableFullWidthLabel/index.tsx +20 -20
- package/src/ui/common-styles.ts +880 -912
- package/src/ui/consts.ts +29 -74
- package/src/ui/icons/AddColLeftIcon.tsx +33 -39
- package/src/ui/icons/AddColRightIcon.tsx +33 -39
- package/src/ui/icons/AddRowAboveIcon.tsx +16 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +33 -39
- package/src/ui/icons/DisplayModeIcon.tsx +31 -31
- package/src/ui/icons/DragHandleDisabledIcon.tsx +19 -21
- package/src/ui/icons/DragHandleIcon.tsx +12 -12
- package/src/ui/icons/DragInMotionIcon.tsx +45 -52
- package/src/ui/icons/MergeCellsIcon.tsx +22 -28
- package/src/ui/icons/MinimisedHandle.tsx +9 -9
- package/src/ui/icons/SplitCellIcon.tsx +30 -36
- package/src/ui/ui-styles.ts +769 -798
- package/src/utils/alignment.ts +1 -1
- package/src/utils/analytics.ts +192 -208
- package/src/utils/collapse.ts +55 -64
- package/src/utils/column-controls.ts +237 -254
- package/src/utils/create.ts +30 -30
- package/src/utils/decoration.ts +482 -502
- package/src/utils/dom.ts +127 -134
- package/src/utils/drag-menu.ts +322 -373
- package/src/utils/get-allow-add-column-custom-step.ts +4 -5
- package/src/utils/guidelines.ts +16 -21
- package/src/utils/index.ts +68 -68
- package/src/utils/merged-cells.ts +245 -254
- package/src/utils/nodes.ts +91 -106
- package/src/utils/paste.ts +119 -135
- package/src/utils/row-controls.ts +199 -213
- package/src/utils/selection.ts +77 -87
- package/src/utils/snapping.ts +87 -100
- package/src/utils/table.ts +44 -44
- package/src/utils/transforms.ts +5 -5
- package/src/utils/update-plugin-state-decorations.ts +5 -9
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
import type { SelectionSharedState } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
GapCursorSelection,
|
|
4
|
+
isSelectionAtEndOfNode,
|
|
5
|
+
isSelectionAtStartOfNode,
|
|
6
|
+
RelativeSelectionPos,
|
|
7
|
+
Side,
|
|
8
8
|
} from '@atlaskit/editor-common/selection';
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
ExtractInjectionAPI,
|
|
12
|
-
} from '@atlaskit/editor-common/types';
|
|
13
|
-
import type {
|
|
14
|
-
Node as PmNode,
|
|
15
|
-
ResolvedPos,
|
|
16
|
-
} from '@atlaskit/editor-prosemirror/model';
|
|
9
|
+
import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
10
|
+
import type { Node as PmNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
17
11
|
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
18
12
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
19
13
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
20
14
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
findTable,
|
|
16
|
+
isColumnSelected,
|
|
17
|
+
isRowSelected,
|
|
18
|
+
isTableSelected,
|
|
19
|
+
selectedRect,
|
|
26
20
|
} from '@atlaskit/editor-tables/utils';
|
|
27
21
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
28
22
|
|
|
@@ -32,345 +26,264 @@ import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
|
32
26
|
import { getClosestSelectionRect } from '../toolbar';
|
|
33
27
|
|
|
34
28
|
export enum TableSelectionDirection {
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
TopToBottom = 'TopToBottom',
|
|
30
|
+
BottomToTop = 'BottomToTop',
|
|
37
31
|
}
|
|
38
32
|
|
|
39
33
|
export const arrowLeftFromTable =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} else if (selection instanceof GapCursorSelection) {
|
|
54
|
-
return arrowLeftFromGapCursor(editorSelectionAPI)(selection)(
|
|
55
|
-
state,
|
|
56
|
-
dispatch,
|
|
57
|
-
);
|
|
58
|
-
} else if (selection instanceof TextSelection) {
|
|
59
|
-
return arrowLeftFromText(editorSelectionAPI)(selection)(state, dispatch);
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
};
|
|
34
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
35
|
+
(): Command =>
|
|
36
|
+
(state, dispatch) => {
|
|
37
|
+
const { selection } = state;
|
|
38
|
+
if (selection instanceof CellSelection) {
|
|
39
|
+
return arrowLeftFromCellSelection(editorSelectionAPI)(selection)(state, dispatch);
|
|
40
|
+
} else if (selection instanceof GapCursorSelection) {
|
|
41
|
+
return arrowLeftFromGapCursor(editorSelectionAPI)(selection)(state, dispatch);
|
|
42
|
+
} else if (selection instanceof TextSelection) {
|
|
43
|
+
return arrowLeftFromText(editorSelectionAPI)(selection)(state, dispatch);
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
63
47
|
|
|
64
48
|
export const arrowRightFromTable =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
} else if (selection instanceof GapCursorSelection) {
|
|
80
|
-
return arrowRightFromGapCursor(editorSelectionAPI)(selection)(
|
|
81
|
-
state,
|
|
82
|
-
dispatch,
|
|
83
|
-
);
|
|
84
|
-
} else if (selection instanceof TextSelection) {
|
|
85
|
-
return arrowRightFromText(editorSelectionAPI)(selection)(state, dispatch);
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
};
|
|
49
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
50
|
+
(): Command =>
|
|
51
|
+
(state, dispatch) => {
|
|
52
|
+
const { selection } = state;
|
|
53
|
+
|
|
54
|
+
if (selection instanceof CellSelection) {
|
|
55
|
+
return arrowRightFromCellSelection(editorSelectionAPI)(selection)(state, dispatch);
|
|
56
|
+
} else if (selection instanceof GapCursorSelection) {
|
|
57
|
+
return arrowRightFromGapCursor(editorSelectionAPI)(selection)(state, dispatch);
|
|
58
|
+
} else if (selection instanceof TextSelection) {
|
|
59
|
+
return arrowRightFromText(editorSelectionAPI)(selection)(state, dispatch);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
};
|
|
89
63
|
|
|
90
64
|
const arrowLeftFromCellSelection =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
} else if (selectionState?.selectionRelativeToNode === undefined) {
|
|
115
|
-
// we have full table cell selection and want to set selection at start of first cell
|
|
116
|
-
return setSelectionAtStartOfFirstCell(editorSelectionAPI)(
|
|
117
|
-
selection,
|
|
118
|
-
RelativeSelectionPos.Before,
|
|
119
|
-
)(state, dispatch);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
};
|
|
65
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
66
|
+
(selection: CellSelection): Command =>
|
|
67
|
+
(state, dispatch) => {
|
|
68
|
+
if (isTableSelected(state.selection) && editorSelectionAPI) {
|
|
69
|
+
const selectionState: SelectionSharedState =
|
|
70
|
+
editorSelectionAPI.sharedState.currentState() || {};
|
|
71
|
+
if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.Start) {
|
|
72
|
+
// we have full table cell selection and want to set gap cursor selection before table
|
|
73
|
+
return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
|
|
74
|
+
} else if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.End) {
|
|
75
|
+
// we have full table cell selection and want to set selection at end of last cell
|
|
76
|
+
return setSelectionAtEndOfLastCell(editorSelectionAPI)(selection)(state, dispatch);
|
|
77
|
+
} else if (selectionState?.selectionRelativeToNode === undefined) {
|
|
78
|
+
// we have full table cell selection and want to set selection at start of first cell
|
|
79
|
+
return setSelectionAtStartOfFirstCell(editorSelectionAPI)(
|
|
80
|
+
selection,
|
|
81
|
+
RelativeSelectionPos.Before,
|
|
82
|
+
)(state, dispatch);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
124
87
|
|
|
125
88
|
const arrowRightFromCellSelection =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
selectionRelativeToNode === undefined
|
|
146
|
-
) {
|
|
147
|
-
// we have full table cell selection and want to set gap cursor selection after table
|
|
148
|
-
return setGapCursorAfterTable(editorSelectionAPI)()(state, dispatch);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
};
|
|
89
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
90
|
+
(selection: CellSelection): Command =>
|
|
91
|
+
(state, dispatch) => {
|
|
92
|
+
if (isTableSelected(state.selection) && editorSelectionAPI) {
|
|
93
|
+
const { selectionRelativeToNode } = editorSelectionAPI.sharedState.currentState() || {};
|
|
94
|
+
|
|
95
|
+
if (selectionRelativeToNode === RelativeSelectionPos.Start) {
|
|
96
|
+
// we have full table cell selection and want to set selection at start of first cell
|
|
97
|
+
return setSelectionAtStartOfFirstCell(editorSelectionAPI)(selection)(state, dispatch);
|
|
98
|
+
} else if (
|
|
99
|
+
selectionRelativeToNode === RelativeSelectionPos.End ||
|
|
100
|
+
selectionRelativeToNode === undefined
|
|
101
|
+
) {
|
|
102
|
+
// we have full table cell selection and want to set gap cursor selection after table
|
|
103
|
+
return setGapCursorAfterTable(editorSelectionAPI)()(state, dispatch);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
153
108
|
|
|
154
109
|
export const selectColumns =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return selectColumn(
|
|
174
|
-
rect.left,
|
|
175
|
-
undefined,
|
|
176
|
-
triggeredByKeyboard,
|
|
177
|
-
)(state, dispatch);
|
|
178
|
-
}
|
|
179
|
-
return false;
|
|
180
|
-
};
|
|
110
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
111
|
+
(triggeredByKeyboard = false): Command =>
|
|
112
|
+
(state, dispatch) => {
|
|
113
|
+
const { selection } = state;
|
|
114
|
+
const table = findTable(selection);
|
|
115
|
+
const rect = selectedRect(state);
|
|
116
|
+
if (table && isRowSelected(rect.top)(selection)) {
|
|
117
|
+
return selectFullTable(editorSelectionAPI)({
|
|
118
|
+
node: table.node,
|
|
119
|
+
startPos: table.start,
|
|
120
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
121
|
+
})(state, dispatch);
|
|
122
|
+
}
|
|
123
|
+
if (table && rect) {
|
|
124
|
+
return selectColumn(rect.left, undefined, triggeredByKeyboard)(state, dispatch);
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
181
128
|
|
|
182
129
|
export const selectRows =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return selectRow(
|
|
202
|
-
rect.top,
|
|
203
|
-
undefined,
|
|
204
|
-
triggeredByKeyboard,
|
|
205
|
-
)(state, dispatch);
|
|
206
|
-
}
|
|
207
|
-
return false;
|
|
208
|
-
};
|
|
130
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
131
|
+
(triggeredByKeyboard = false): Command =>
|
|
132
|
+
(state, dispatch) => {
|
|
133
|
+
const { selection } = state;
|
|
134
|
+
const table = findTable(selection);
|
|
135
|
+
const rect = selectedRect(state);
|
|
136
|
+
if (table && isColumnSelected(rect.left)(selection)) {
|
|
137
|
+
return selectFullTable(editorSelectionAPI)({
|
|
138
|
+
node: table.node,
|
|
139
|
+
startPos: table.start,
|
|
140
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
141
|
+
})(state, dispatch);
|
|
142
|
+
}
|
|
143
|
+
if (table && rect) {
|
|
144
|
+
return selectRow(rect.top, undefined, triggeredByKeyboard)(state, dispatch);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
209
148
|
|
|
210
149
|
const arrowLeftFromGapCursor =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
// we have a gap cursor at start of first table cell and want to set a full table cell selection
|
|
247
|
-
return selectFullTable(editorSelectionAPI)({
|
|
248
|
-
node: table.node,
|
|
249
|
-
startPos: table.start,
|
|
250
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
251
|
-
})(state, dispatch);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return false;
|
|
256
|
-
};
|
|
150
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
151
|
+
(selection: GapCursorSelection): Command =>
|
|
152
|
+
(state, dispatch) => {
|
|
153
|
+
const { doc } = state;
|
|
154
|
+
const { $from, from, side } = selection;
|
|
155
|
+
|
|
156
|
+
if (side === Side.RIGHT) {
|
|
157
|
+
if ($from.nodeBefore && $from.nodeBefore.type.name === 'table') {
|
|
158
|
+
// we have a gap cursor after a table node and want to set a full table cell selection
|
|
159
|
+
return selectFullTable(editorSelectionAPI)({
|
|
160
|
+
node: $from.nodeBefore,
|
|
161
|
+
startPos: doc.resolve(from - 1).start($from.depth + 1),
|
|
162
|
+
dir: TableSelectionDirection.TopToBottom,
|
|
163
|
+
})(state, dispatch);
|
|
164
|
+
}
|
|
165
|
+
} else if (side === Side.LEFT) {
|
|
166
|
+
const table = findTable(selection);
|
|
167
|
+
if (table && isSelectionAtStartOfTable($from, selection) && editorSelectionAPI) {
|
|
168
|
+
const selectionState: SelectionSharedState =
|
|
169
|
+
editorSelectionAPI.sharedState.currentState() || {};
|
|
170
|
+
if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.Before) {
|
|
171
|
+
// we have a gap cursor at start of first table cell and want to set a gap cursor selection before table
|
|
172
|
+
return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
|
|
173
|
+
} else {
|
|
174
|
+
// we have a gap cursor at start of first table cell and want to set a full table cell selection
|
|
175
|
+
return selectFullTable(editorSelectionAPI)({
|
|
176
|
+
node: table.node,
|
|
177
|
+
startPos: table.start,
|
|
178
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
179
|
+
})(state, dispatch);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
};
|
|
257
185
|
|
|
258
186
|
const arrowRightFromGapCursor =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return false;
|
|
289
|
-
};
|
|
187
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
188
|
+
(selection: GapCursorSelection): Command =>
|
|
189
|
+
(state, dispatch) => {
|
|
190
|
+
const { $from, from, $to, side } = selection;
|
|
191
|
+
|
|
192
|
+
if (side === Side.LEFT) {
|
|
193
|
+
if ($from.nodeAfter && $from.nodeAfter.type.name === 'table') {
|
|
194
|
+
// we have a gap cursor before a table node and want to set a full table cell selection
|
|
195
|
+
return selectFullTable(editorSelectionAPI)({
|
|
196
|
+
node: $from.nodeAfter,
|
|
197
|
+
startPos: from + 1,
|
|
198
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
199
|
+
})(state, dispatch);
|
|
200
|
+
}
|
|
201
|
+
} else if (side === Side.RIGHT) {
|
|
202
|
+
const table = findTable(selection);
|
|
203
|
+
if (table && isSelectionAtEndOfTable($to, selection)) {
|
|
204
|
+
// we have a gap cursor at end of last table cell and want to set a full table cell selection
|
|
205
|
+
return selectFullTable(editorSelectionAPI)({
|
|
206
|
+
node: table.node,
|
|
207
|
+
startPos: table.start,
|
|
208
|
+
dir: TableSelectionDirection.TopToBottom,
|
|
209
|
+
})(state, dispatch);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
};
|
|
290
214
|
|
|
291
215
|
const arrowLeftFromText =
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
333
|
-
})(state, dispatch);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return false;
|
|
338
|
-
};
|
|
216
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
217
|
+
(selection: TextSelection): Command =>
|
|
218
|
+
(state, dispatch) => {
|
|
219
|
+
const table = findTable(selection);
|
|
220
|
+
if (table) {
|
|
221
|
+
const { $from } = selection;
|
|
222
|
+
let isColumnResizing = false;
|
|
223
|
+
|
|
224
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
225
|
+
const columResizePluginState = getPluginState(state) || {};
|
|
226
|
+
isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (
|
|
230
|
+
isSelectionAtStartOfTable($from, selection) &&
|
|
231
|
+
$from.parent.type.name === 'paragraph' &&
|
|
232
|
+
$from.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
|
|
233
|
+
editorSelectionAPI &&
|
|
234
|
+
!isColumnResizing
|
|
235
|
+
) {
|
|
236
|
+
const selectionState: SelectionSharedState =
|
|
237
|
+
editorSelectionAPI.sharedState.currentState() || {};
|
|
238
|
+
|
|
239
|
+
if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.Before) {
|
|
240
|
+
// we have a text selection at start of first table cell, directly inside a top level paragraph,
|
|
241
|
+
// and want to set gap cursor selection before table
|
|
242
|
+
return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
|
|
243
|
+
} else {
|
|
244
|
+
// we have a text selection at start of first table cell, directly inside a top level paragraph,
|
|
245
|
+
// and want to set a full table cell selection
|
|
246
|
+
return selectFullTable(editorSelectionAPI)({
|
|
247
|
+
node: table.node,
|
|
248
|
+
startPos: table.start,
|
|
249
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
250
|
+
})(state, dispatch);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
};
|
|
339
256
|
|
|
340
257
|
const arrowRightFromText =
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return false;
|
|
373
|
-
};
|
|
258
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
259
|
+
(selection: TextSelection): Command =>
|
|
260
|
+
(state, dispatch) => {
|
|
261
|
+
const table = findTable(selection);
|
|
262
|
+
if (table) {
|
|
263
|
+
const { $to } = selection;
|
|
264
|
+
let isColumnResizing = false;
|
|
265
|
+
|
|
266
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
267
|
+
const columResizePluginState = getPluginState(state) || {};
|
|
268
|
+
isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
|
|
269
|
+
}
|
|
270
|
+
if (
|
|
271
|
+
isSelectionAtEndOfTable($to, selection) &&
|
|
272
|
+
$to.parent.type.name === 'paragraph' &&
|
|
273
|
+
$to.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
|
|
274
|
+
!isColumnResizing
|
|
275
|
+
) {
|
|
276
|
+
// we have a text selection at end of last table cell, directly inside a top level paragraph,
|
|
277
|
+
// and want to set a full table cell selection
|
|
278
|
+
return selectFullTable(editorSelectionAPI)({
|
|
279
|
+
node: table.node,
|
|
280
|
+
startPos: table.start,
|
|
281
|
+
dir: TableSelectionDirection.TopToBottom,
|
|
282
|
+
})(state, dispatch);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
};
|
|
374
287
|
|
|
375
288
|
/**
|
|
376
289
|
* Sets a cell selection over all the cells in the table node
|
|
@@ -379,246 +292,203 @@ const arrowRightFromText =
|
|
|
379
292
|
* pos in the selection plugin
|
|
380
293
|
*/
|
|
381
294
|
const selectFullTable =
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return false;
|
|
423
|
-
};
|
|
295
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
296
|
+
({
|
|
297
|
+
node,
|
|
298
|
+
startPos,
|
|
299
|
+
dir,
|
|
300
|
+
}: {
|
|
301
|
+
node: PmNode;
|
|
302
|
+
startPos: number;
|
|
303
|
+
dir: TableSelectionDirection;
|
|
304
|
+
}): Command =>
|
|
305
|
+
(state, dispatch) => {
|
|
306
|
+
const { doc } = state;
|
|
307
|
+
const { map } = TableMap.get(node);
|
|
308
|
+
const $firstCell = doc.resolve(startPos + map[0]);
|
|
309
|
+
const $lastCell = doc.resolve(startPos + map[map.length - 1]);
|
|
310
|
+
|
|
311
|
+
let fullTableSelection: Selection;
|
|
312
|
+
let selectionRelativeToNode: RelativeSelectionPos;
|
|
313
|
+
if (dir === TableSelectionDirection.TopToBottom) {
|
|
314
|
+
fullTableSelection = new CellSelection($firstCell, $lastCell) as any;
|
|
315
|
+
selectionRelativeToNode = RelativeSelectionPos.End;
|
|
316
|
+
} else {
|
|
317
|
+
fullTableSelection = new CellSelection($lastCell, $firstCell) as any;
|
|
318
|
+
selectionRelativeToNode = RelativeSelectionPos.Start;
|
|
319
|
+
}
|
|
320
|
+
if (editorSelectionAPI) {
|
|
321
|
+
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
322
|
+
selectionRelativeToNode,
|
|
323
|
+
selection: fullTableSelection,
|
|
324
|
+
})(state);
|
|
325
|
+
|
|
326
|
+
if (dispatch) {
|
|
327
|
+
dispatch(tr);
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
};
|
|
424
333
|
|
|
425
334
|
const setSelectionAtStartOfFirstCell =
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
if (dispatch) {
|
|
453
|
-
dispatch(tr);
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return false;
|
|
458
|
-
};
|
|
335
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
336
|
+
(selection: CellSelection, selectionRelativeToNode?: RelativeSelectionPos): Command =>
|
|
337
|
+
(state, dispatch) => {
|
|
338
|
+
const { $anchorCell, $headCell } = selection;
|
|
339
|
+
const $firstCell = $anchorCell.pos < $headCell.pos ? $anchorCell : $headCell;
|
|
340
|
+
const $firstPosInsideCell = state.doc.resolve($firstCell.pos + 1);
|
|
341
|
+
|
|
342
|
+
// check if first pos should have a gap cursor, otherwise find closest text selection
|
|
343
|
+
const selectionAtStartOfCell = GapCursorSelection.valid($firstPosInsideCell)
|
|
344
|
+
? new GapCursorSelection($firstPosInsideCell, Side.LEFT)
|
|
345
|
+
: Selection.findFrom($firstPosInsideCell, 1);
|
|
346
|
+
|
|
347
|
+
if (editorSelectionAPI) {
|
|
348
|
+
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
349
|
+
selectionRelativeToNode,
|
|
350
|
+
selection: selectionAtStartOfCell,
|
|
351
|
+
})(state);
|
|
352
|
+
|
|
353
|
+
if (dispatch) {
|
|
354
|
+
dispatch(tr);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
359
|
+
};
|
|
459
360
|
|
|
460
361
|
const setSelectionAtEndOfLastCell =
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
})(state);
|
|
489
|
-
|
|
490
|
-
if (dispatch) {
|
|
491
|
-
dispatch(tr);
|
|
492
|
-
return true;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
return false;
|
|
496
|
-
};
|
|
362
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
363
|
+
(selection: CellSelection, selectionRelativeToNode?: RelativeSelectionPos): Command =>
|
|
364
|
+
(state, dispatch) => {
|
|
365
|
+
const { $anchorCell, $headCell } = selection;
|
|
366
|
+
const $lastCell = $anchorCell.pos > $headCell.pos ? $anchorCell : $headCell;
|
|
367
|
+
const lastPosInsideCell =
|
|
368
|
+
$lastCell.pos + ($lastCell.nodeAfter ? $lastCell.nodeAfter.content.size : 0) + 1;
|
|
369
|
+
const $lastPosInsideCell = state.doc.resolve(lastPosInsideCell);
|
|
370
|
+
|
|
371
|
+
// check if last pos should have a gap cursor, otherwise find closest text selection
|
|
372
|
+
const selectionAtEndOfCell = GapCursorSelection.valid($lastPosInsideCell)
|
|
373
|
+
? new GapCursorSelection($lastPosInsideCell, Side.RIGHT)
|
|
374
|
+
: Selection.findFrom($lastPosInsideCell, -1);
|
|
375
|
+
|
|
376
|
+
if (editorSelectionAPI) {
|
|
377
|
+
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
378
|
+
selectionRelativeToNode,
|
|
379
|
+
selection: selectionAtEndOfCell,
|
|
380
|
+
})(state);
|
|
381
|
+
|
|
382
|
+
if (dispatch) {
|
|
383
|
+
dispatch(tr);
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
};
|
|
497
389
|
|
|
498
390
|
const setGapCursorBeforeTable =
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return true;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return false;
|
|
528
|
-
};
|
|
391
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
392
|
+
(): Command =>
|
|
393
|
+
(state, dispatch) => {
|
|
394
|
+
const table = findTable(state.selection);
|
|
395
|
+
if (table) {
|
|
396
|
+
const $beforeTablePos = state.doc.resolve(table.pos);
|
|
397
|
+
if (GapCursorSelection.valid($beforeTablePos)) {
|
|
398
|
+
const selectionBeforeTable = new GapCursorSelection($beforeTablePos, Side.LEFT);
|
|
399
|
+
if (editorSelectionAPI) {
|
|
400
|
+
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
401
|
+
selectionRelativeToNode: undefined,
|
|
402
|
+
selection: selectionBeforeTable,
|
|
403
|
+
})(state);
|
|
404
|
+
|
|
405
|
+
if (dispatch) {
|
|
406
|
+
dispatch(tr);
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
};
|
|
529
414
|
|
|
530
415
|
const setGapCursorAfterTable =
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
return false;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
return false;
|
|
562
|
-
};
|
|
416
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
417
|
+
(): Command =>
|
|
418
|
+
(state, dispatch) => {
|
|
419
|
+
const table = findTable(state.selection);
|
|
420
|
+
if (table) {
|
|
421
|
+
const $afterTablePos = state.doc.resolve(table.pos + table.node.nodeSize);
|
|
422
|
+
if (GapCursorSelection.valid($afterTablePos)) {
|
|
423
|
+
const selectionAfterTable = new GapCursorSelection($afterTablePos, Side.RIGHT);
|
|
424
|
+
|
|
425
|
+
if (editorSelectionAPI) {
|
|
426
|
+
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
427
|
+
selectionRelativeToNode: undefined,
|
|
428
|
+
selection: selectionAfterTable,
|
|
429
|
+
})(state);
|
|
430
|
+
|
|
431
|
+
if (dispatch) {
|
|
432
|
+
dispatch(tr);
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return false;
|
|
440
|
+
};
|
|
563
441
|
|
|
564
442
|
const isSelectionAtStartOfTable = ($pos: ResolvedPos, selection: Selection) =>
|
|
565
|
-
|
|
443
|
+
isSelectionAtStartOfNode($pos, findTable(selection));
|
|
566
444
|
|
|
567
445
|
const isSelectionAtEndOfTable = ($pos: ResolvedPos, selection: Selection) =>
|
|
568
|
-
|
|
446
|
+
isSelectionAtEndOfNode($pos, findTable(selection));
|
|
569
447
|
|
|
570
448
|
export const shiftArrowUpFromTable =
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
return false;
|
|
591
|
-
};
|
|
449
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
450
|
+
(): Command =>
|
|
451
|
+
(state, dispatch) => {
|
|
452
|
+
const { selection } = state;
|
|
453
|
+
const table = findTable(selection);
|
|
454
|
+
const selectionRect = getClosestSelectionRect(state);
|
|
455
|
+
const index = selectionRect?.top;
|
|
456
|
+
if (table && index === 0) {
|
|
457
|
+
return selectFullTable(editorSelectionAPI)({
|
|
458
|
+
node: table.node,
|
|
459
|
+
startPos: table.start,
|
|
460
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
461
|
+
})(state, dispatch);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return false;
|
|
465
|
+
};
|
|
592
466
|
|
|
593
467
|
export const modASelectTable =
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
return false;
|
|
624
|
-
};
|
|
468
|
+
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
469
|
+
(): Command =>
|
|
470
|
+
(state, dispatch) => {
|
|
471
|
+
const { selection } = state;
|
|
472
|
+
const table = findTable(selection);
|
|
473
|
+
|
|
474
|
+
if (!table) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
const { $from, $to } = selection;
|
|
478
|
+
|
|
479
|
+
const tableSelected = isTableSelected(selection);
|
|
480
|
+
|
|
481
|
+
if (
|
|
482
|
+
!tableSelected &&
|
|
483
|
+
$from.pos > table.start + 1 &&
|
|
484
|
+
$to.pos < table.start + table.node.nodeSize
|
|
485
|
+
) {
|
|
486
|
+
return selectFullTable(editorSelectionAPI)({
|
|
487
|
+
node: table.node,
|
|
488
|
+
startPos: table.start,
|
|
489
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
490
|
+
})(state, dispatch);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return false;
|
|
494
|
+
};
|