@atlaskit/editor-plugin-table 7.16.10 → 7.16.12

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