@atlaskit/editor-plugin-table 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  5. package/dist/es2019/version.json +1 -1
  6. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  7. package/dist/esm/version.json +1 -1
  8. package/examples/99-testing.tsx +35 -30
  9. package/package.json +3 -12
  10. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
  11. package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
  12. package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
  13. package/src/__tests__/integration/resize.ts +1 -2
  14. package/src/__tests__/unit/analytics.ts +33 -32
  15. package/src/__tests__/unit/collab.ts +12 -9
  16. package/src/__tests__/unit/commands/sort.ts +28 -28
  17. package/src/__tests__/unit/copy-paste.ts +6 -8
  18. package/src/__tests__/unit/event-handlers.ts +7 -10
  19. package/src/__tests__/unit/fix-tables.ts +17 -23
  20. package/src/__tests__/unit/get-toolbar-config.ts +0 -5
  21. package/src/__tests__/unit/hover-selection.ts +1 -66
  22. package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
  23. package/src/__tests__/unit/index.ts +5 -5
  24. package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
  25. package/src/__tests__/unit/nodeviews/cell.ts +12 -10
  26. package/src/__tests__/unit/nodeviews/table.ts +25 -26
  27. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
  28. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
  29. package/src/__tests__/unit/toolbar.ts +18 -5
  30. package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
  31. package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
  32. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
  33. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
  34. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
  35. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
  36. package/src/__tests__/unit/ui/RowControls.tsx +112 -141
  37. package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
  38. package/src/__tests__/unit/undo-redo.ts +10 -9
  39. package/src/__tests__/unit/utils/nodes.ts +8 -4
  40. package/src/__tests__/unit/utils/row-controls.ts +8 -4
  41. package/src/plugins/table/commands/clear.ts +30 -29
  42. package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
  43. package/src/plugins/table/commands/insert.ts +91 -91
  44. package/src/plugins/table/commands/misc.ts +123 -125
  45. package/src/plugins/table/commands/selection.ts +329 -319
  46. package/src/plugins/table/commands-with-analytics.ts +299 -294
  47. package/src/plugins/table/event-handlers.ts +111 -111
  48. package/src/plugins/table/handlers.ts +95 -94
  49. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
  50. package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
  51. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
  52. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
  53. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
  54. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
  55. package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
  56. package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
  57. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
  58. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
  60. package/src/plugins/table/toolbar.tsx +116 -113
  61. package/src/plugins/table/transforms/column-width.ts +143 -146
  62. package/src/plugins/table/transforms/delete-columns.ts +144 -142
  63. package/src/plugins/table/transforms/delete-rows.ts +110 -111
  64. package/src/plugins/table/transforms/metadata.ts +9 -9
  65. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
  66. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
  67. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
  68. package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
  69. package/src/plugins/table/ui/common-styles.ts +1 -3
  70. package/src/plugins/table/utils/analytics.ts +24 -25
  71. package/src/plugins/table/utils/dom.ts +3 -3
  72. package/src/plugins/table/utils/row-controls.ts +92 -93
  73. package/dist/types-ts4.0/index.d.ts +0 -1
  74. package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
  75. package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
  76. package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  77. package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
  78. package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
  79. package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
  80. package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
  81. package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
  82. package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
  83. package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
  84. package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
  85. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
  86. package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
  87. package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
  88. package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
  89. package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
  90. package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
  91. package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
  92. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  93. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  94. package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
  95. package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
  96. package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
  97. package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
  98. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  99. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  100. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
  101. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  102. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  103. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  104. package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
  105. package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
  106. package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
  107. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  108. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  109. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
  110. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  111. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  112. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  113. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  114. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
  115. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  116. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  117. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  118. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  119. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  120. package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
  121. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
  122. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  123. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
  124. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  125. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  126. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  127. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  128. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
  129. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  130. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  131. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
  132. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
  133. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
  134. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  135. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  136. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  137. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
  138. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  139. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  140. package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  141. package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
  142. package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
  143. package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
  144. package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
  145. package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
  146. package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
  147. package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
  148. package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
  149. package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
  150. package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
  151. package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
  152. package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
  153. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
  154. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
  155. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  156. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
  157. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  158. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
  159. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  160. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  161. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  162. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
  163. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  164. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  165. package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  166. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  167. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  168. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  169. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
  170. package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
  171. package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
  172. package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
  173. package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
  174. package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
  175. package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
  176. package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
  177. package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
  178. package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
  179. package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  180. package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
  181. package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
  182. package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
  183. package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
  184. package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
  185. package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
  186. package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
  187. package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  188. package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
  189. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
  190. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
@@ -18,223 +18,227 @@ export enum TableSelectionDirection {
18
18
  BottomToTop = 'BottomToTop',
19
19
  }
20
20
 
21
- export const arrowLeftFromTable = (
22
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
23
- ) => (): Command => (state, dispatch) => {
24
- const { selection } = state;
25
- if (selection instanceof CellSelection) {
26
- return arrowLeftFromCellSelection(editorSelectionAPI)(selection)(
27
- state,
28
- dispatch,
29
- );
30
- } else if (selection instanceof GapCursorSelection) {
31
- return arrowLeftFromGapCursor(editorSelectionAPI)(selection)(
32
- state,
33
- dispatch,
34
- );
35
- } else if (selection instanceof TextSelection) {
36
- return arrowLeftFromText(editorSelectionAPI)(selection)(state, dispatch);
37
- }
38
- return false;
39
- };
40
-
41
- export const arrowRightFromTable = (
42
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
43
- ) => (): Command => (state, dispatch) => {
44
- const { selection } = state;
45
-
46
- if (selection instanceof CellSelection) {
47
- return arrowRightFromCellSelection(editorSelectionAPI)(selection)(
48
- state,
49
- dispatch,
50
- );
51
- } else if (selection instanceof GapCursorSelection) {
52
- return arrowRightFromGapCursor(editorSelectionAPI)(selection)(
53
- state,
54
- dispatch,
55
- );
56
- } else if (selection instanceof TextSelection) {
57
- return arrowRightFromText(editorSelectionAPI)(selection)(state, dispatch);
58
- }
59
- return false;
60
- };
61
-
62
- const arrowLeftFromCellSelection = (
63
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
64
- ) => (selection: CellSelection): Command => (state, dispatch) => {
65
- if (isTableSelected(state.selection) && editorSelectionAPI) {
66
- const {
67
- selectionRelativeToNode,
68
- } = editorSelectionAPI.getSelectionPluginState(state);
69
- if (selectionRelativeToNode === RelativeSelectionPos.Start) {
70
- // we have full table cell selection and want to set gap cursor selection before table
71
- return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
72
- } else if (selectionRelativeToNode === RelativeSelectionPos.End) {
73
- // we have full table cell selection and want to set selection at end of last cell
74
- return setSelectionAtEndOfLastCell(editorSelectionAPI)(selection)(
21
+ export const arrowLeftFromTable =
22
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
23
+ (): Command =>
24
+ (state, dispatch) => {
25
+ const { selection } = state;
26
+ if (selection instanceof CellSelection) {
27
+ return arrowLeftFromCellSelection(editorSelectionAPI)(selection)(
75
28
  state,
76
29
  dispatch,
77
30
  );
78
- } else if (selectionRelativeToNode === undefined) {
79
- // we have full table cell selection and want to set selection at start of first cell
80
- return setSelectionAtStartOfFirstCell(editorSelectionAPI)(
81
- selection,
82
- RelativeSelectionPos.Before,
83
- )(state, dispatch);
31
+ } else if (selection instanceof GapCursorSelection) {
32
+ return arrowLeftFromGapCursor(editorSelectionAPI)(selection)(
33
+ state,
34
+ dispatch,
35
+ );
36
+ } else if (selection instanceof TextSelection) {
37
+ return arrowLeftFromText(editorSelectionAPI)(selection)(state, dispatch);
84
38
  }
85
- }
86
- return false;
87
- };
39
+ return false;
40
+ };
88
41
 
89
- const arrowRightFromCellSelection = (
90
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
91
- ) => (selection: CellSelection): Command => (state, dispatch) => {
92
- if (isTableSelected(state.selection) && editorSelectionAPI) {
93
- const {
94
- selectionRelativeToNode,
95
- } = editorSelectionAPI.getSelectionPluginState(state);
42
+ export const arrowRightFromTable =
43
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
44
+ (): Command =>
45
+ (state, dispatch) => {
46
+ const { selection } = state;
96
47
 
97
- if (selectionRelativeToNode === RelativeSelectionPos.Start) {
98
- // we have full table cell selection and want to set selection at start of first cell
99
- return setSelectionAtStartOfFirstCell(editorSelectionAPI)(selection)(
48
+ if (selection instanceof CellSelection) {
49
+ return arrowRightFromCellSelection(editorSelectionAPI)(selection)(
100
50
  state,
101
51
  dispatch,
102
52
  );
103
- } else if (
104
- selectionRelativeToNode === RelativeSelectionPos.End ||
105
- selectionRelativeToNode === undefined
106
- ) {
107
- // we have full table cell selection and want to set gap cursor selection after table
108
- return setGapCursorAfterTable(editorSelectionAPI)()(state, dispatch);
53
+ } else if (selection instanceof GapCursorSelection) {
54
+ return arrowRightFromGapCursor(editorSelectionAPI)(selection)(
55
+ state,
56
+ dispatch,
57
+ );
58
+ } else if (selection instanceof TextSelection) {
59
+ return arrowRightFromText(editorSelectionAPI)(selection)(state, dispatch);
60
+ }
61
+ return false;
62
+ };
63
+
64
+ const arrowLeftFromCellSelection =
65
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
66
+ (selection: CellSelection): Command =>
67
+ (state, dispatch) => {
68
+ if (isTableSelected(state.selection) && editorSelectionAPI) {
69
+ const { selectionRelativeToNode } =
70
+ editorSelectionAPI.getSelectionPluginState(state);
71
+ if (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 (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)(
77
+ state,
78
+ dispatch,
79
+ );
80
+ } else if (selectionRelativeToNode === undefined) {
81
+ // we have full table cell selection and want to set selection at start of first cell
82
+ return setSelectionAtStartOfFirstCell(editorSelectionAPI)(
83
+ selection,
84
+ RelativeSelectionPos.Before,
85
+ )(state, dispatch);
86
+ }
109
87
  }
110
- }
111
- return false;
112
- };
88
+ return false;
89
+ };
113
90
 
114
- const arrowLeftFromGapCursor = (
115
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
116
- ) => (selection: GapCursorSelection): Command => (state, dispatch) => {
117
- const { doc } = state;
118
- const { $from, from, side } = selection;
91
+ const arrowRightFromCellSelection =
92
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
93
+ (selection: CellSelection): Command =>
94
+ (state, dispatch) => {
95
+ if (isTableSelected(state.selection) && editorSelectionAPI) {
96
+ const { selectionRelativeToNode } =
97
+ editorSelectionAPI.getSelectionPluginState(state);
119
98
 
120
- if (side === Side.RIGHT) {
121
- if ($from.nodeBefore && $from.nodeBefore.type.name === 'table') {
122
- // we have a gap cursor after a table node and want to set a full table cell selection
123
- return selectFullTable(editorSelectionAPI)({
124
- node: $from.nodeBefore,
125
- startPos: doc.resolve(from - 1).start($from.depth + 1),
126
- dir: TableSelectionDirection.TopToBottom,
127
- })(state, dispatch);
99
+ if (selectionRelativeToNode === RelativeSelectionPos.Start) {
100
+ // we have full table cell selection and want to set selection at start of first cell
101
+ return setSelectionAtStartOfFirstCell(editorSelectionAPI)(selection)(
102
+ state,
103
+ dispatch,
104
+ );
105
+ } else if (
106
+ selectionRelativeToNode === RelativeSelectionPos.End ||
107
+ selectionRelativeToNode === undefined
108
+ ) {
109
+ // we have full table cell selection and want to set gap cursor selection after table
110
+ return setGapCursorAfterTable(editorSelectionAPI)()(state, dispatch);
111
+ }
128
112
  }
129
- } else if (side === Side.LEFT) {
130
- const table = findTable(selection);
131
- if (
132
- table &&
133
- isSelectionAtStartOfTable($from, selection) &&
134
- editorSelectionAPI
135
- ) {
136
- const {
137
- selectionRelativeToNode,
138
- } = editorSelectionAPI.getSelectionPluginState(state);
139
- if (selectionRelativeToNode === RelativeSelectionPos.Before) {
140
- // we have a gap cursor at start of first table cell and want to set a gap cursor selection before table
141
- return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
142
- } else {
143
- // we have a gap cursor at start of first table cell and want to set a full table cell selection
113
+ return false;
114
+ };
115
+
116
+ const arrowLeftFromGapCursor =
117
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
118
+ (selection: GapCursorSelection): Command =>
119
+ (state, dispatch) => {
120
+ const { doc } = state;
121
+ const { $from, from, side } = selection;
122
+
123
+ if (side === Side.RIGHT) {
124
+ if ($from.nodeBefore && $from.nodeBefore.type.name === 'table') {
125
+ // we have a gap cursor after a table node and want to set a full table cell selection
144
126
  return selectFullTable(editorSelectionAPI)({
145
- node: table.node,
146
- startPos: table.start,
147
- dir: TableSelectionDirection.BottomToTop,
127
+ node: $from.nodeBefore,
128
+ startPos: doc.resolve(from - 1).start($from.depth + 1),
129
+ dir: TableSelectionDirection.TopToBottom,
148
130
  })(state, dispatch);
149
131
  }
132
+ } else if (side === Side.LEFT) {
133
+ const table = findTable(selection);
134
+ if (
135
+ table &&
136
+ isSelectionAtStartOfTable($from, selection) &&
137
+ editorSelectionAPI
138
+ ) {
139
+ const { selectionRelativeToNode } =
140
+ editorSelectionAPI.getSelectionPluginState(state);
141
+ if (selectionRelativeToNode === RelativeSelectionPos.Before) {
142
+ // we have a gap cursor at start of first table cell and want to set a gap cursor selection before table
143
+ return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
144
+ } else {
145
+ // we have a gap cursor at start of first table cell and want to set a full table cell selection
146
+ return selectFullTable(editorSelectionAPI)({
147
+ node: table.node,
148
+ startPos: table.start,
149
+ dir: TableSelectionDirection.BottomToTop,
150
+ })(state, dispatch);
151
+ }
152
+ }
150
153
  }
151
- }
152
- return false;
153
- };
154
+ return false;
155
+ };
154
156
 
155
- const arrowRightFromGapCursor = (
156
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
157
- ) => (selection: GapCursorSelection): Command => (state, dispatch) => {
158
- const { $from, from, $to, side } = selection;
157
+ const arrowRightFromGapCursor =
158
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
159
+ (selection: GapCursorSelection): Command =>
160
+ (state, dispatch) => {
161
+ const { $from, from, $to, side } = selection;
159
162
 
160
- if (side === Side.LEFT) {
161
- if ($from.nodeAfter && $from.nodeAfter.type.name === 'table') {
162
- // we have a gap cursor before a table node and want to set a full table cell selection
163
- return selectFullTable(editorSelectionAPI)({
164
- node: $from.nodeAfter,
165
- startPos: from + 1,
166
- dir: TableSelectionDirection.BottomToTop,
167
- })(state, dispatch);
163
+ if (side === Side.LEFT) {
164
+ if ($from.nodeAfter && $from.nodeAfter.type.name === 'table') {
165
+ // we have a gap cursor before a table node and want to set a full table cell selection
166
+ return selectFullTable(editorSelectionAPI)({
167
+ node: $from.nodeAfter,
168
+ startPos: from + 1,
169
+ dir: TableSelectionDirection.BottomToTop,
170
+ })(state, dispatch);
171
+ }
172
+ } else if (side === Side.RIGHT) {
173
+ const table = findTable(selection);
174
+ if (table && isSelectionAtEndOfTable($to, selection)) {
175
+ // we have a gap cursor at end of last table cell and want to set a full table cell selection
176
+ return selectFullTable(editorSelectionAPI)({
177
+ node: table.node,
178
+ startPos: table.start,
179
+ dir: TableSelectionDirection.TopToBottom,
180
+ })(state, dispatch);
181
+ }
168
182
  }
169
- } else if (side === Side.RIGHT) {
183
+ return false;
184
+ };
185
+
186
+ const arrowLeftFromText =
187
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
188
+ (selection: TextSelection): Command =>
189
+ (state, dispatch) => {
170
190
  const table = findTable(selection);
171
- if (table && isSelectionAtEndOfTable($to, selection)) {
172
- // we have a gap cursor at end of last table cell and want to set a full table cell selection
173
- return selectFullTable(editorSelectionAPI)({
174
- node: table.node,
175
- startPos: table.start,
176
- dir: TableSelectionDirection.TopToBottom,
177
- })(state, dispatch);
191
+ if (table) {
192
+ const { $from } = selection;
193
+ if (
194
+ isSelectionAtStartOfTable($from, selection) &&
195
+ $from.parent.type.name === 'paragraph' &&
196
+ $from.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
197
+ editorSelectionAPI
198
+ ) {
199
+ const { selectionRelativeToNode } =
200
+ editorSelectionAPI.getSelectionPluginState(state);
201
+ if (selectionRelativeToNode === RelativeSelectionPos.Before) {
202
+ // we have a text selection at start of first table cell, directly inside a top level paragraph,
203
+ // and want to set gap cursor selection before table
204
+ return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
205
+ } else {
206
+ // we have a text selection at start of first table cell, directly inside a top level paragraph,
207
+ // and want to set a full table cell selection
208
+ return selectFullTable(editorSelectionAPI)({
209
+ node: table.node,
210
+ startPos: table.start,
211
+ dir: TableSelectionDirection.BottomToTop,
212
+ })(state, dispatch);
213
+ }
214
+ }
178
215
  }
179
- }
180
- return false;
181
- };
216
+ return false;
217
+ };
182
218
 
183
- const arrowLeftFromText = (
184
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
185
- ) => (selection: TextSelection): Command => (state, dispatch) => {
186
- const table = findTable(selection);
187
- if (table) {
188
- const { $from } = selection;
189
- if (
190
- isSelectionAtStartOfTable($from, selection) &&
191
- $from.parent.type.name === 'paragraph' &&
192
- $from.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
193
- editorSelectionAPI
194
- ) {
195
- const {
196
- selectionRelativeToNode,
197
- } = editorSelectionAPI.getSelectionPluginState(state);
198
- if (selectionRelativeToNode === RelativeSelectionPos.Before) {
199
- // we have a text selection at start of first table cell, directly inside a top level paragraph,
200
- // and want to set gap cursor selection before table
201
- return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
202
- } else {
203
- // we have a text selection at start of first table cell, directly inside a top level paragraph,
219
+ const arrowRightFromText =
220
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
221
+ (selection: TextSelection): Command =>
222
+ (state, dispatch) => {
223
+ const table = findTable(selection);
224
+ if (table) {
225
+ const { $to } = selection;
226
+ if (
227
+ isSelectionAtEndOfTable($to, selection) &&
228
+ $to.parent.type.name === 'paragraph' &&
229
+ $to.depth === table.depth + 3 // + 3 for: row, cell & paragraph nodes
230
+ ) {
231
+ // we have a text selection at end of last table cell, directly inside a top level paragraph,
204
232
  // and want to set a full table cell selection
205
233
  return selectFullTable(editorSelectionAPI)({
206
234
  node: table.node,
207
235
  startPos: table.start,
208
- dir: TableSelectionDirection.BottomToTop,
236
+ dir: TableSelectionDirection.TopToBottom,
209
237
  })(state, dispatch);
210
238
  }
211
239
  }
212
- }
213
- return false;
214
- };
215
-
216
- const arrowRightFromText = (
217
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
218
- ) => (selection: TextSelection): Command => (state, dispatch) => {
219
- const table = findTable(selection);
220
- if (table) {
221
- const { $to } = selection;
222
- if (
223
- isSelectionAtEndOfTable($to, selection) &&
224
- $to.parent.type.name === 'paragraph' &&
225
- $to.depth === table.depth + 3 // + 3 for: row, cell & paragraph nodes
226
- ) {
227
- // we have a text selection at end of last table cell, directly inside a top level paragraph,
228
- // and want to set a full table cell selection
229
- return selectFullTable(editorSelectionAPI)({
230
- node: table.node,
231
- startPos: table.start,
232
- dir: TableSelectionDirection.TopToBottom,
233
- })(state, dispatch);
234
- }
235
- }
236
- return false;
237
- };
240
+ return false;
241
+ };
238
242
 
239
243
  /**
240
244
  * Sets a cell selection over all the cells in the table node
@@ -242,162 +246,168 @@ const arrowRightFromText = (
242
246
  * cell is the anchor and which is the head, and also so we can set the relative selection
243
247
  * pos in the selection plugin
244
248
  */
245
- const selectFullTable = (
246
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
247
- ) => ({
248
- node,
249
- startPos,
250
- dir,
251
- }: {
252
- node: PmNode;
253
- startPos: number;
254
- dir: TableSelectionDirection;
255
- }): Command => (state, dispatch) => {
256
- const { doc } = state;
257
- const { map } = TableMap.get(node);
258
- const $firstCell = doc.resolve(startPos + map[0]);
259
- const $lastCell = doc.resolve(startPos + map[map.length - 1]);
249
+ const selectFullTable =
250
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
251
+ ({
252
+ node,
253
+ startPos,
254
+ dir,
255
+ }: {
256
+ node: PmNode;
257
+ startPos: number;
258
+ dir: TableSelectionDirection;
259
+ }): Command =>
260
+ (state, dispatch) => {
261
+ const { doc } = state;
262
+ const { map } = TableMap.get(node);
263
+ const $firstCell = doc.resolve(startPos + map[0]);
264
+ const $lastCell = doc.resolve(startPos + map[map.length - 1]);
260
265
 
261
- let fullTableSelection: Selection;
262
- let selectionRelativeToNode: RelativeSelectionPos;
263
- if (dir === TableSelectionDirection.TopToBottom) {
264
- fullTableSelection = new CellSelection($firstCell, $lastCell) as any;
265
- selectionRelativeToNode = RelativeSelectionPos.End;
266
- } else {
267
- fullTableSelection = new CellSelection($lastCell, $firstCell) as any;
268
- selectionRelativeToNode = RelativeSelectionPos.Start;
269
- }
270
- if (editorSelectionAPI) {
271
- const tr = editorSelectionAPI.setSelectionRelativeToNode({
272
- selectionRelativeToNode,
273
- selection: fullTableSelection,
274
- })(state);
266
+ let fullTableSelection: Selection;
267
+ let selectionRelativeToNode: RelativeSelectionPos;
268
+ if (dir === TableSelectionDirection.TopToBottom) {
269
+ fullTableSelection = new CellSelection($firstCell, $lastCell) as any;
270
+ selectionRelativeToNode = RelativeSelectionPos.End;
271
+ } else {
272
+ fullTableSelection = new CellSelection($lastCell, $firstCell) as any;
273
+ selectionRelativeToNode = RelativeSelectionPos.Start;
274
+ }
275
+ if (editorSelectionAPI) {
276
+ const tr = editorSelectionAPI.setSelectionRelativeToNode({
277
+ selectionRelativeToNode,
278
+ selection: fullTableSelection,
279
+ })(state);
275
280
 
276
- if (dispatch) {
277
- dispatch(tr);
278
- return true;
281
+ if (dispatch) {
282
+ dispatch(tr);
283
+ return true;
284
+ }
279
285
  }
280
- }
281
- return false;
282
- };
286
+ return false;
287
+ };
283
288
 
284
- const setSelectionAtStartOfFirstCell = (
285
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
286
- ) => (
287
- selection: CellSelection,
288
- selectionRelativeToNode?: RelativeSelectionPos,
289
- ): Command => (state, dispatch) => {
290
- const { $anchorCell, $headCell } = selection;
291
- const $firstCell = $anchorCell.pos < $headCell.pos ? $anchorCell : $headCell;
292
- const $firstPosInsideCell = state.doc.resolve($firstCell.pos + 1);
289
+ const setSelectionAtStartOfFirstCell =
290
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
291
+ (
292
+ selection: CellSelection,
293
+ selectionRelativeToNode?: RelativeSelectionPos,
294
+ ): Command =>
295
+ (state, dispatch) => {
296
+ const { $anchorCell, $headCell } = selection;
297
+ const $firstCell =
298
+ $anchorCell.pos < $headCell.pos ? $anchorCell : $headCell;
299
+ const $firstPosInsideCell = state.doc.resolve($firstCell.pos + 1);
293
300
 
294
- // check if first pos should have a gap cursor, otherwise find closest text selection
295
- const selectionAtStartOfCell = GapCursorSelection.valid($firstPosInsideCell)
296
- ? new GapCursorSelection($firstPosInsideCell, Side.LEFT)
297
- : Selection.findFrom($firstPosInsideCell, 1);
301
+ // check if first pos should have a gap cursor, otherwise find closest text selection
302
+ const selectionAtStartOfCell = GapCursorSelection.valid($firstPosInsideCell)
303
+ ? new GapCursorSelection($firstPosInsideCell, Side.LEFT)
304
+ : Selection.findFrom($firstPosInsideCell, 1);
298
305
 
299
- if (editorSelectionAPI) {
300
- const tr = editorSelectionAPI.setSelectionRelativeToNode({
301
- selectionRelativeToNode,
302
- selection: selectionAtStartOfCell,
303
- })(state);
306
+ if (editorSelectionAPI) {
307
+ const tr = editorSelectionAPI.setSelectionRelativeToNode({
308
+ selectionRelativeToNode,
309
+ selection: selectionAtStartOfCell,
310
+ })(state);
304
311
 
305
- if (dispatch) {
306
- dispatch(tr);
307
- return true;
312
+ if (dispatch) {
313
+ dispatch(tr);
314
+ return true;
315
+ }
308
316
  }
309
- }
310
- return false;
311
- };
317
+ return false;
318
+ };
312
319
 
313
- const setSelectionAtEndOfLastCell = (
314
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
315
- ) => (
316
- selection: CellSelection,
317
- selectionRelativeToNode?: RelativeSelectionPos,
318
- ): Command => (state, dispatch) => {
319
- const { $anchorCell, $headCell } = selection;
320
- const $lastCell = $anchorCell.pos > $headCell.pos ? $anchorCell : $headCell;
321
- const lastPosInsideCell =
322
- $lastCell.pos +
323
- ($lastCell.nodeAfter ? $lastCell.nodeAfter.content.size : 0) +
324
- 1;
325
- const $lastPosInsideCell = state.doc.resolve(lastPosInsideCell);
320
+ const setSelectionAtEndOfLastCell =
321
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
322
+ (
323
+ selection: CellSelection,
324
+ selectionRelativeToNode?: RelativeSelectionPos,
325
+ ): Command =>
326
+ (state, dispatch) => {
327
+ const { $anchorCell, $headCell } = selection;
328
+ const $lastCell = $anchorCell.pos > $headCell.pos ? $anchorCell : $headCell;
329
+ const lastPosInsideCell =
330
+ $lastCell.pos +
331
+ ($lastCell.nodeAfter ? $lastCell.nodeAfter.content.size : 0) +
332
+ 1;
333
+ const $lastPosInsideCell = state.doc.resolve(lastPosInsideCell);
326
334
 
327
- // check if last pos should have a gap cursor, otherwise find closest text selection
328
- const selectionAtEndOfCell = GapCursorSelection.valid($lastPosInsideCell)
329
- ? new GapCursorSelection($lastPosInsideCell, Side.RIGHT)
330
- : Selection.findFrom($lastPosInsideCell, -1);
335
+ // check if last pos should have a gap cursor, otherwise find closest text selection
336
+ const selectionAtEndOfCell = GapCursorSelection.valid($lastPosInsideCell)
337
+ ? new GapCursorSelection($lastPosInsideCell, Side.RIGHT)
338
+ : Selection.findFrom($lastPosInsideCell, -1);
331
339
 
332
- if (editorSelectionAPI) {
333
- const tr = editorSelectionAPI.setSelectionRelativeToNode({
334
- selectionRelativeToNode,
335
- selection: selectionAtEndOfCell,
336
- })(state);
340
+ if (editorSelectionAPI) {
341
+ const tr = editorSelectionAPI.setSelectionRelativeToNode({
342
+ selectionRelativeToNode,
343
+ selection: selectionAtEndOfCell,
344
+ })(state);
337
345
 
338
- if (dispatch) {
339
- dispatch(tr);
340
- return true;
346
+ if (dispatch) {
347
+ dispatch(tr);
348
+ return true;
349
+ }
341
350
  }
342
- }
343
- return false;
344
- };
351
+ return false;
352
+ };
345
353
 
346
- const setGapCursorBeforeTable = (
347
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
348
- ) => (): Command => (state, dispatch) => {
349
- const table = findTable(state.selection);
350
- if (table) {
351
- const $beforeTablePos = state.doc.resolve(table.pos);
352
- if (GapCursorSelection.valid($beforeTablePos)) {
353
- const selectionBeforeTable = new GapCursorSelection(
354
- $beforeTablePos,
355
- Side.LEFT,
356
- );
357
- if (editorSelectionAPI) {
358
- const tr = editorSelectionAPI.setSelectionRelativeToNode({
359
- selectionRelativeToNode: undefined,
360
- selection: selectionBeforeTable,
361
- })(state);
354
+ const setGapCursorBeforeTable =
355
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
356
+ (): Command =>
357
+ (state, dispatch) => {
358
+ const table = findTable(state.selection);
359
+ if (table) {
360
+ const $beforeTablePos = state.doc.resolve(table.pos);
361
+ if (GapCursorSelection.valid($beforeTablePos)) {
362
+ const selectionBeforeTable = new GapCursorSelection(
363
+ $beforeTablePos,
364
+ Side.LEFT,
365
+ );
366
+ if (editorSelectionAPI) {
367
+ const tr = editorSelectionAPI.setSelectionRelativeToNode({
368
+ selectionRelativeToNode: undefined,
369
+ selection: selectionBeforeTable,
370
+ })(state);
362
371
 
363
- if (dispatch) {
364
- dispatch(tr);
365
- return true;
372
+ if (dispatch) {
373
+ dispatch(tr);
374
+ return true;
375
+ }
366
376
  }
367
377
  }
368
378
  }
369
- }
370
- return false;
371
- };
379
+ return false;
380
+ };
372
381
 
373
- const setGapCursorAfterTable = (
374
- editorSelectionAPI: EditorSelectionAPI | undefined | null,
375
- ) => (): Command => (state, dispatch) => {
376
- const table = findTable(state.selection);
377
- if (table) {
378
- const $afterTablePos = state.doc.resolve(table.pos + table.node.nodeSize);
379
- if (GapCursorSelection.valid($afterTablePos)) {
380
- const selectionAfterTable = new GapCursorSelection(
381
- $afterTablePos,
382
- Side.RIGHT,
383
- );
382
+ const setGapCursorAfterTable =
383
+ (editorSelectionAPI: EditorSelectionAPI | undefined | null) =>
384
+ (): Command =>
385
+ (state, dispatch) => {
386
+ const table = findTable(state.selection);
387
+ if (table) {
388
+ const $afterTablePos = state.doc.resolve(table.pos + table.node.nodeSize);
389
+ if (GapCursorSelection.valid($afterTablePos)) {
390
+ const selectionAfterTable = new GapCursorSelection(
391
+ $afterTablePos,
392
+ Side.RIGHT,
393
+ );
384
394
 
385
- if (editorSelectionAPI) {
386
- const tr = editorSelectionAPI.setSelectionRelativeToNode({
387
- selectionRelativeToNode: undefined,
388
- selection: selectionAfterTable,
389
- })(state);
395
+ if (editorSelectionAPI) {
396
+ const tr = editorSelectionAPI.setSelectionRelativeToNode({
397
+ selectionRelativeToNode: undefined,
398
+ selection: selectionAfterTable,
399
+ })(state);
390
400
 
391
- if (dispatch) {
392
- dispatch(tr);
393
- return true;
401
+ if (dispatch) {
402
+ dispatch(tr);
403
+ return true;
404
+ }
394
405
  }
406
+ return false;
395
407
  }
396
- return false;
397
408
  }
398
- }
399
- return false;
400
- };
409
+ return false;
410
+ };
401
411
 
402
412
  const isSelectionAtStartOfTable = ($pos: ResolvedPos, selection: Selection) =>
403
413
  isSelectionAtStartOfNode($pos, findTable(selection));