@atlaskit/editor-plugin-table 0.1.0 → 0.1.1

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 +8 -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 +2 -11
  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
@@ -15,42 +15,45 @@ import { insertRowWithAnalytics } from '../commands-with-analytics';
15
15
  const TAB_FORWARD_DIRECTION = 1;
16
16
  const TAB_BACKWARD_DIRECTION = -1;
17
17
 
18
- export const goToNextCell = (
19
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
20
- ) => (direction: Direction): Command => (state, dispatch) => {
21
- const table = findTable(state.selection);
22
- if (!table) {
23
- return false;
24
- }
25
-
26
- const map = TableMap.get(table.node);
27
- const { tableCell, tableHeader } = state.schema.nodes;
28
- const cell = findParentNodeOfType([tableCell, tableHeader])(state.selection)!;
29
- const firstCellPos = map.positionAt(0, 0, table.node) + table.start;
30
- const lastCellPos =
31
- map.positionAt(map.height - 1, map.width - 1, table.node) + table.start;
32
-
33
- // when tabbing backwards at first cell (top left), insert row at the start of table
34
- if (firstCellPos === cell.pos && direction === TAB_BACKWARD_DIRECTION) {
35
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, {
36
- index: 0,
37
- moveCursorToInsertedRow: true,
38
- })(state, dispatch);
39
- return true;
40
- }
41
-
42
- // when tabbing forwards at last cell (bottom right), insert row at the end of table
43
- if (lastCellPos === cell.pos && direction === TAB_FORWARD_DIRECTION) {
44
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, {
45
- index: map.height,
46
- moveCursorToInsertedRow: true,
47
- })(state, dispatch);
48
- return true;
49
- }
18
+ export const goToNextCell =
19
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
20
+ (direction: Direction): Command =>
21
+ (state, dispatch) => {
22
+ const table = findTable(state.selection);
23
+ if (!table) {
24
+ return false;
25
+ }
26
+
27
+ const map = TableMap.get(table.node);
28
+ const { tableCell, tableHeader } = state.schema.nodes;
29
+ const cell = findParentNodeOfType([tableCell, tableHeader])(
30
+ state.selection,
31
+ )!;
32
+ const firstCellPos = map.positionAt(0, 0, table.node) + table.start;
33
+ const lastCellPos =
34
+ map.positionAt(map.height - 1, map.width - 1, table.node) + table.start;
35
+
36
+ // when tabbing backwards at first cell (top left), insert row at the start of table
37
+ if (firstCellPos === cell.pos && direction === TAB_BACKWARD_DIRECTION) {
38
+ insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, {
39
+ index: 0,
40
+ moveCursorToInsertedRow: true,
41
+ })(state, dispatch);
42
+ return true;
43
+ }
44
+
45
+ // when tabbing forwards at last cell (bottom right), insert row at the end of table
46
+ if (lastCellPos === cell.pos && direction === TAB_FORWARD_DIRECTION) {
47
+ insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, {
48
+ index: map.height,
49
+ moveCursorToInsertedRow: true,
50
+ })(state, dispatch);
51
+ return true;
52
+ }
53
+
54
+ if (dispatch) {
55
+ return baseGotoNextCell(direction)(state, dispatch);
56
+ }
50
57
 
51
- if (dispatch) {
52
- return baseGotoNextCell(direction)(state, dispatch);
53
- }
54
-
55
- return true;
56
- };
58
+ return true;
59
+ };
@@ -57,109 +57,109 @@ export function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth) {
57
57
 
58
58
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
59
59
  // Command to add a column before the column with the selection.
60
- export const addColumnBefore = (
61
- getEditorContainerWidth: GetEditorContainerWidth,
62
- ): Command => (state, dispatch, view) => {
63
- const table = findTable(state.selection);
64
- if (!table) {
65
- return false;
66
- }
67
- if (dispatch) {
68
- let rect = selectedRect(state);
69
- dispatch(
70
- addColumnAt(getEditorContainerWidth)(
71
- rect.left,
72
- getAllowAddColumnCustomStep(state),
73
- view,
74
- )(state.tr),
75
- );
76
- }
77
- return true;
78
- };
60
+ export const addColumnBefore =
61
+ (getEditorContainerWidth: GetEditorContainerWidth): Command =>
62
+ (state, dispatch, view) => {
63
+ const table = findTable(state.selection);
64
+ if (!table) {
65
+ return false;
66
+ }
67
+ if (dispatch) {
68
+ let rect = selectedRect(state);
69
+ dispatch(
70
+ addColumnAt(getEditorContainerWidth)(
71
+ rect.left,
72
+ getAllowAddColumnCustomStep(state),
73
+ view,
74
+ )(state.tr),
75
+ );
76
+ }
77
+ return true;
78
+ };
79
79
 
80
80
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
81
81
  // Command to add a column after the column with the selection.
82
- export const addColumnAfter = (
83
- getEditorContainerWidth: GetEditorContainerWidth,
84
- ): Command => (state, dispatch, view) => {
85
- const table = findTable(state.selection);
86
- if (!table) {
87
- return false;
88
- }
89
- if (dispatch) {
90
- let rect = selectedRect(state);
91
- dispatch(
92
- addColumnAt(getEditorContainerWidth)(
93
- rect.right,
94
- getAllowAddColumnCustomStep(state),
95
- view,
96
- )(state.tr),
97
- );
98
- }
99
- return true;
100
- };
82
+ export const addColumnAfter =
83
+ (getEditorContainerWidth: GetEditorContainerWidth): Command =>
84
+ (state, dispatch, view) => {
85
+ const table = findTable(state.selection);
86
+ if (!table) {
87
+ return false;
88
+ }
89
+ if (dispatch) {
90
+ let rect = selectedRect(state);
91
+ dispatch(
92
+ addColumnAt(getEditorContainerWidth)(
93
+ rect.right,
94
+ getAllowAddColumnCustomStep(state),
95
+ view,
96
+ )(state.tr),
97
+ );
98
+ }
99
+ return true;
100
+ };
101
101
 
102
102
  // #region Commands
103
- export const insertColumn = (
104
- getEditorContainerWidth: GetEditorContainerWidth,
105
- ) => (column: number): Command => (state, dispatch, view) => {
106
- let tr = addColumnAt(getEditorContainerWidth)(
107
- column,
108
- getAllowAddColumnCustomStep(state),
109
- view,
110
- )(state.tr);
111
- const table = findTable(tr.selection);
112
- if (!table) {
113
- return false;
114
- }
115
- // move the cursor to the newly created column
116
- const pos = TableMap.get(table.node).positionAt(0, column, table.node);
103
+ export const insertColumn =
104
+ (getEditorContainerWidth: GetEditorContainerWidth) =>
105
+ (column: number): Command =>
106
+ (state, dispatch, view) => {
107
+ let tr = addColumnAt(getEditorContainerWidth)(
108
+ column,
109
+ getAllowAddColumnCustomStep(state),
110
+ view,
111
+ )(state.tr);
112
+ const table = findTable(tr.selection);
113
+ if (!table) {
114
+ return false;
115
+ }
116
+ // move the cursor to the newly created column
117
+ const pos = TableMap.get(table.node).positionAt(0, column, table.node);
117
118
 
118
- if (dispatch) {
119
- dispatch(
120
- tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos))),
121
- );
122
- }
123
- return true;
124
- };
119
+ if (dispatch) {
120
+ dispatch(
121
+ tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos))),
122
+ );
123
+ }
124
+ return true;
125
+ };
125
126
 
126
- export const insertRow = (
127
- row: number,
128
- moveCursorToTheNewRow: boolean,
129
- ): Command => (state, dispatch) => {
130
- // Don't clone the header row
131
- const headerRowEnabled = checkIfHeaderRowEnabled(state.selection);
132
- const clonePreviousRow =
133
- (headerRowEnabled && row > 1) || (!headerRowEnabled && row > 0);
127
+ export const insertRow =
128
+ (row: number, moveCursorToTheNewRow: boolean): Command =>
129
+ (state, dispatch) => {
130
+ // Don't clone the header row
131
+ const headerRowEnabled = checkIfHeaderRowEnabled(state.selection);
132
+ const clonePreviousRow =
133
+ (headerRowEnabled && row > 1) || (!headerRowEnabled && row > 0);
134
134
 
135
- // When the table have header row
136
- // we should not add row on the position zero
137
- if (row === 0 && headerRowEnabled) {
138
- return false;
139
- }
135
+ // When the table have header row
136
+ // we should not add row on the position zero
137
+ if (row === 0 && headerRowEnabled) {
138
+ return false;
139
+ }
140
140
 
141
- const tr = clonePreviousRow
142
- ? copyPreviousRow(state.schema)(row)(state.tr)
143
- : addRowAt(row)(state.tr);
141
+ const tr = clonePreviousRow
142
+ ? copyPreviousRow(state.schema)(row)(state.tr)
143
+ : addRowAt(row)(state.tr);
144
144
 
145
- const table = findTable(tr.selection);
146
- if (!table) {
147
- return false;
148
- }
149
- if (dispatch) {
150
- const { selection } = state;
151
- if (moveCursorToTheNewRow) {
152
- // move the cursor to the newly created row
153
- const pos = TableMap.get(table.node).positionAt(row, 0, table.node);
154
- tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos)));
155
- } else {
156
- tr.setSelection(selection.map(tr.doc, tr.mapping));
145
+ const table = findTable(tr.selection);
146
+ if (!table) {
147
+ return false;
157
148
  }
149
+ if (dispatch) {
150
+ const { selection } = state;
151
+ if (moveCursorToTheNewRow) {
152
+ // move the cursor to the newly created row
153
+ const pos = TableMap.get(table.node).positionAt(row, 0, table.node);
154
+ tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos)));
155
+ } else {
156
+ tr.setSelection(selection.map(tr.doc, tr.mapping));
157
+ }
158
158
 
159
- dispatch(tr);
160
- }
161
- return true;
162
- };
159
+ dispatch(tr);
160
+ }
161
+ return true;
162
+ };
163
163
 
164
164
  export const createTable = (): Command => (state, dispatch) => {
165
165
  const table = createTableNode({
@@ -97,70 +97,67 @@ export const setTableRef = (ref?: HTMLTableElement) =>
97
97
  (tr) => tr.setMeta('addToHistory', false),
98
98
  );
99
99
 
100
- export const setCellAttr = (name: string, value: any): Command => (
101
- state,
102
- dispatch,
103
- ) => {
104
- const { tr, selection } = state;
105
- if (selection instanceof CellSelection) {
106
- let updated = false;
107
- selection.forEachCell((cell, pos) => {
108
- if (cell.attrs[name] !== value) {
109
- tr.setNodeMarkup(pos, cell.type, { ...cell.attrs, [name]: value });
110
- updated = true;
100
+ export const setCellAttr =
101
+ (name: string, value: any): Command =>
102
+ (state, dispatch) => {
103
+ const { tr, selection } = state;
104
+ if (selection instanceof CellSelection) {
105
+ let updated = false;
106
+ selection.forEachCell((cell, pos) => {
107
+ if (cell.attrs[name] !== value) {
108
+ tr.setNodeMarkup(pos, cell.type, { ...cell.attrs, [name]: value });
109
+ updated = true;
110
+ }
111
+ });
112
+ if (updated) {
113
+ if (dispatch) {
114
+ dispatch(tr);
115
+ }
116
+ return true;
111
117
  }
112
- });
113
- if (updated) {
114
- if (dispatch) {
115
- dispatch(tr);
118
+ } else {
119
+ const cell = selectionCell(state.selection);
120
+ if (cell) {
121
+ if (dispatch) {
122
+ dispatch(
123
+ tr.setNodeMarkup(cell.pos, cell.nodeAfter?.type, {
124
+ ...cell.nodeAfter?.attrs,
125
+ [name]: value,
126
+ }),
127
+ );
128
+ }
129
+ return true;
116
130
  }
117
- return true;
118
131
  }
119
- } else {
120
- const cell = selectionCell(state.selection);
121
- if (cell) {
122
- if (dispatch) {
123
- dispatch(
124
- tr.setNodeMarkup(cell.pos, cell.nodeAfter?.type, {
125
- ...cell.nodeAfter?.attrs,
126
- [name]: value,
127
- }),
128
- );
132
+ return false;
133
+ };
134
+
135
+ export const triggerUnlessTableHeader =
136
+ (command: Command): Command =>
137
+ (state, dispatch, view) => {
138
+ const {
139
+ selection,
140
+ schema: {
141
+ nodes: { tableHeader },
142
+ },
143
+ } = state;
144
+
145
+ if (selection instanceof TextSelection) {
146
+ const cell = findCellClosestToPos(selection.$from);
147
+ if (cell && cell.node.type !== tableHeader) {
148
+ return command(state, dispatch, view);
129
149
  }
130
- return true;
131
150
  }
132
- }
133
- return false;
134
- };
135
151
 
136
- export const triggerUnlessTableHeader = (command: Command): Command => (
137
- state,
138
- dispatch,
139
- view,
140
- ) => {
141
- const {
142
- selection,
143
- schema: {
144
- nodes: { tableHeader },
145
- },
146
- } = state;
147
-
148
- if (selection instanceof TextSelection) {
149
- const cell = findCellClosestToPos(selection.$from);
150
- if (cell && cell.node.type !== tableHeader) {
151
- return command(state, dispatch, view);
152
- }
153
- }
154
-
155
- if (selection instanceof CellSelection) {
156
- const rect = getSelectionRect(selection);
157
- if (!checkIfHeaderRowEnabled(selection) || (rect && rect.top > 0)) {
158
- return command(state, dispatch, view);
152
+ if (selection instanceof CellSelection) {
153
+ const rect = getSelectionRect(selection);
154
+ if (!checkIfHeaderRowEnabled(selection) || (rect && rect.top > 0)) {
155
+ return command(state, dispatch, view);
156
+ }
159
157
  }
160
- }
161
158
 
162
- return false;
163
- };
159
+ return false;
160
+ };
164
161
 
165
162
  export const transformSliceRemoveCellBackgroundColor = (
166
163
  slice: Slice,
@@ -248,21 +245,21 @@ export const deleteTableIfSelected: Command = (state, dispatch) => {
248
245
  return false;
249
246
  };
250
247
 
251
- export const convertFirstRowToHeader = (schema: Schema) => (
252
- tr: Transaction,
253
- ): Transaction => {
254
- const table = findTable(tr.selection)!;
255
- const map = TableMap.get(table.node);
256
- for (let i = 0; i < map.width; i++) {
257
- const cell = table.node.child(0).child(i);
258
- tr.setNodeMarkup(
259
- table.start + map.map[i],
260
- schema.nodes.tableHeader,
261
- cell.attrs,
262
- );
263
- }
264
- return tr;
265
- };
248
+ export const convertFirstRowToHeader =
249
+ (schema: Schema) =>
250
+ (tr: Transaction): Transaction => {
251
+ const table = findTable(tr.selection)!;
252
+ const map = TableMap.get(table.node);
253
+ for (let i = 0; i < map.width; i++) {
254
+ const cell = table.node.child(0).child(i);
255
+ tr.setNodeMarkup(
256
+ table.start + map.map[i],
257
+ schema.nodes.tableHeader,
258
+ cell.attrs,
259
+ );
260
+ }
261
+ return tr;
262
+ };
266
263
 
267
264
  export const moveCursorBackward: Command = (state, dispatch) => {
268
265
  const { $cursor } = state.selection as TextSelection;
@@ -332,36 +329,37 @@ export const moveCursorBackward: Command = (state, dispatch) => {
332
329
  return true;
333
330
  };
334
331
 
335
- export const setMultipleCellAttrs = (
336
- attrs: Object,
337
- targetCellPosition?: number,
338
- ): Command => (state, dispatch) => {
339
- let cursorPos: number | undefined;
340
- let { tr } = state;
341
-
342
- if (isSelectionType(tr.selection, 'cell')) {
343
- const selection = (tr.selection as any) as CellSelection;
344
- selection.forEachCell((_cell, pos) => {
345
- const $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
346
- tr = setCellAttrs(findCellClosestToPos($pos)!, attrs)(tr);
347
- });
348
- cursorPos = selection.$headCell.pos;
349
- } else if (targetCellPosition) {
350
- const cell = findCellClosestToPos(tr.doc.resolve(targetCellPosition + 1))!;
351
- tr = setCellAttrs(cell, attrs)(tr);
352
- cursorPos = cell.pos;
353
- }
332
+ export const setMultipleCellAttrs =
333
+ (attrs: Object, targetCellPosition?: number): Command =>
334
+ (state, dispatch) => {
335
+ let cursorPos: number | undefined;
336
+ let { tr } = state;
337
+
338
+ if (isSelectionType(tr.selection, 'cell')) {
339
+ const selection = tr.selection as any as CellSelection;
340
+ selection.forEachCell((_cell, pos) => {
341
+ const $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
342
+ tr = setCellAttrs(findCellClosestToPos($pos)!, attrs)(tr);
343
+ });
344
+ cursorPos = selection.$headCell.pos;
345
+ } else if (targetCellPosition) {
346
+ const cell = findCellClosestToPos(
347
+ tr.doc.resolve(targetCellPosition + 1),
348
+ )!;
349
+ tr = setCellAttrs(cell, attrs)(tr);
350
+ cursorPos = cell.pos;
351
+ }
354
352
 
355
- if (tr.docChanged && cursorPos !== undefined) {
356
- const $pos = tr.doc.resolve(tr.mapping.map(cursorPos!));
353
+ if (tr.docChanged && cursorPos !== undefined) {
354
+ const $pos = tr.doc.resolve(tr.mapping.map(cursorPos!));
357
355
 
358
- if (dispatch) {
359
- dispatch(tr.setSelection(Selection.near($pos)));
356
+ if (dispatch) {
357
+ dispatch(tr.setSelection(Selection.near($pos)));
358
+ }
359
+ return true;
360
360
  }
361
- return true;
362
- }
363
- return false;
364
- };
361
+ return false;
362
+ };
365
363
 
366
364
  export const selectColumn = (column: number, expand?: boolean) =>
367
365
  createCommand(
@@ -473,34 +471,34 @@ export const autoSizeTable = (
473
471
  return true;
474
472
  };
475
473
 
476
- export const addBoldInEmptyHeaderCells = (
477
- tableCellHeader: ContentNodeWithPos,
478
- ): Command => (state, dispatch): boolean => {
479
- const { tr } = state;
480
- if (
481
- // Avoid infinite loop when the current selection is not a TextSelection
482
- isTextSelection(tr.selection) &&
483
- tr.selection.$cursor &&
484
- // When storedMark is null that means this is the initial state
485
- // if the user press to remove the mark storedMark will be an empty array
486
- // and we shouldn't apply the strong mark
487
- tr.storedMarks == null &&
488
- // Check if the current node is a direct child from paragraph
489
- tr.selection.$from.depth === tableCellHeader.depth + 1 &&
490
- // this logic is applied only for empty paragraph
491
- tableCellHeader.node.nodeSize === 4 &&
492
- isParagraph(tableCellHeader.node.firstChild, state.schema)
493
- ) {
494
- const { strong } = state.schema.marks;
495
- tr.setStoredMarks([strong.create()]).setMeta('addToHistory', false);
474
+ export const addBoldInEmptyHeaderCells =
475
+ (tableCellHeader: ContentNodeWithPos): Command =>
476
+ (state, dispatch): boolean => {
477
+ const { tr } = state;
478
+ if (
479
+ // Avoid infinite loop when the current selection is not a TextSelection
480
+ isTextSelection(tr.selection) &&
481
+ tr.selection.$cursor &&
482
+ // When storedMark is null that means this is the initial state
483
+ // if the user press to remove the mark storedMark will be an empty array
484
+ // and we shouldn't apply the strong mark
485
+ tr.storedMarks == null &&
486
+ // Check if the current node is a direct child from paragraph
487
+ tr.selection.$from.depth === tableCellHeader.depth + 1 &&
488
+ // this logic is applied only for empty paragraph
489
+ tableCellHeader.node.nodeSize === 4 &&
490
+ isParagraph(tableCellHeader.node.firstChild, state.schema)
491
+ ) {
492
+ const { strong } = state.schema.marks;
493
+ tr.setStoredMarks([strong.create()]).setMeta('addToHistory', false);
496
494
 
497
- if (dispatch) {
498
- dispatch(tr);
499
- }
495
+ if (dispatch) {
496
+ dispatch(tr);
497
+ }
500
498
 
501
- return true;
502
- }
499
+ return true;
500
+ }
503
501
 
504
- return false;
505
- };
502
+ return false;
503
+ };
506
504
  // #endregion