@atlaskit/editor-plugin-table 7.2.3 → 7.3.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 (135) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/commands/column-resize.js +115 -45
  4. package/dist/cjs/commands/go-to-next-cell.js +7 -11
  5. package/dist/cjs/commands/misc.js +7 -4
  6. package/dist/cjs/commands/selection.js +7 -5
  7. package/dist/cjs/event-handlers.js +38 -25
  8. package/dist/cjs/pm-plugins/drag-and-drop/commands.js +3 -1
  9. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +33 -1
  10. package/dist/cjs/pm-plugins/drag-and-drop/reducer.js +2 -1
  11. package/dist/cjs/pm-plugins/keymap.js +1 -0
  12. package/dist/cjs/pm-plugins/main.js +43 -9
  13. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
  14. package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
  15. package/dist/cjs/pm-plugins/table-selection-keymap.js +2 -2
  16. package/dist/cjs/reducer.js +5 -2
  17. package/dist/cjs/ui/DragHandle/HandleIconComponent.js +1 -3
  18. package/dist/cjs/ui/DragHandle/index.js +22 -10
  19. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +75 -33
  20. package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +123 -0
  21. package/dist/cjs/ui/FloatingDragMenu/index.js +2 -2
  22. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
  23. package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -2
  24. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
  25. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
  26. package/dist/cjs/ui/common-styles.js +1 -1
  27. package/dist/cjs/ui/consts.js +3 -2
  28. package/dist/es2019/commands/column-resize.js +100 -35
  29. package/dist/es2019/commands/go-to-next-cell.js +7 -9
  30. package/dist/es2019/commands/misc.js +7 -6
  31. package/dist/es2019/commands/selection.js +9 -9
  32. package/dist/es2019/event-handlers.js +17 -3
  33. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +3 -3
  34. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +34 -1
  35. package/dist/es2019/pm-plugins/drag-and-drop/reducer.js +2 -1
  36. package/dist/es2019/pm-plugins/keymap.js +3 -2
  37. package/dist/es2019/pm-plugins/main.js +41 -5
  38. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
  39. package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
  40. package/dist/es2019/pm-plugins/table-selection-keymap.js +2 -2
  41. package/dist/es2019/reducer.js +5 -2
  42. package/dist/es2019/ui/DragHandle/HandleIconComponent.js +1 -3
  43. package/dist/es2019/ui/DragHandle/index.js +25 -10
  44. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +72 -32
  45. package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +109 -0
  46. package/dist/es2019/ui/FloatingDragMenu/index.js +2 -2
  47. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
  48. package/dist/es2019/ui/TableFloatingColumnControls/index.js +1 -2
  49. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
  50. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
  51. package/dist/es2019/ui/common-styles.js +11 -1
  52. package/dist/es2019/ui/consts.js +2 -1
  53. package/dist/esm/commands/column-resize.js +105 -35
  54. package/dist/esm/commands/go-to-next-cell.js +7 -11
  55. package/dist/esm/commands/misc.js +7 -4
  56. package/dist/esm/commands/selection.js +9 -7
  57. package/dist/esm/event-handlers.js +38 -25
  58. package/dist/esm/pm-plugins/drag-and-drop/commands.js +3 -2
  59. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +33 -1
  60. package/dist/esm/pm-plugins/drag-and-drop/reducer.js +2 -1
  61. package/dist/esm/pm-plugins/keymap.js +3 -2
  62. package/dist/esm/pm-plugins/main.js +38 -4
  63. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
  64. package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
  65. package/dist/esm/pm-plugins/table-selection-keymap.js +2 -2
  66. package/dist/esm/reducer.js +5 -2
  67. package/dist/esm/ui/DragHandle/HandleIconComponent.js +1 -3
  68. package/dist/esm/ui/DragHandle/index.js +21 -9
  69. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +74 -35
  70. package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +116 -0
  71. package/dist/esm/ui/FloatingDragMenu/index.js +2 -2
  72. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
  73. package/dist/esm/ui/TableFloatingColumnControls/index.js +1 -2
  74. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
  75. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
  76. package/dist/esm/ui/common-styles.js +1 -1
  77. package/dist/esm/ui/consts.js +2 -1
  78. package/dist/types/commands/column-resize.d.ts +2 -0
  79. package/dist/types/commands/misc.d.ts +3 -3
  80. package/dist/types/commands/selection.d.ts +2 -2
  81. package/dist/types/pm-plugins/drag-and-drop/actions.d.ts +1 -0
  82. package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  83. package/dist/types/pm-plugins/drag-and-drop/types.d.ts +2 -0
  84. package/dist/types/types.d.ts +16 -0
  85. package/dist/types/ui/DragHandle/HandleIconComponent.d.ts +1 -2
  86. package/dist/types/ui/DragHandle/index.d.ts +3 -2
  87. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -8
  88. package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +30 -0
  89. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
  90. package/dist/types/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -1
  91. package/dist/types/ui/consts.d.ts +1 -0
  92. package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
  93. package/dist/types-ts4.5/commands/misc.d.ts +3 -3
  94. package/dist/types-ts4.5/commands/selection.d.ts +2 -2
  95. package/dist/types-ts4.5/pm-plugins/drag-and-drop/actions.d.ts +1 -0
  96. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  97. package/dist/types-ts4.5/pm-plugins/drag-and-drop/types.d.ts +2 -0
  98. package/dist/types-ts4.5/types.d.ts +16 -0
  99. package/dist/types-ts4.5/ui/DragHandle/HandleIconComponent.d.ts +1 -2
  100. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +3 -2
  101. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -8
  102. package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +30 -0
  103. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
  104. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -1
  105. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  106. package/package.json +4 -3
  107. package/src/commands/column-resize.ts +155 -40
  108. package/src/commands/go-to-next-cell.ts +6 -15
  109. package/src/commands/misc.ts +19 -4
  110. package/src/commands/selection.ts +17 -9
  111. package/src/event-handlers.ts +21 -4
  112. package/src/pm-plugins/drag-and-drop/actions.ts +1 -0
  113. package/src/pm-plugins/drag-and-drop/commands.ts +3 -0
  114. package/src/pm-plugins/drag-and-drop/plugin.ts +47 -0
  115. package/src/pm-plugins/drag-and-drop/reducer.ts +1 -0
  116. package/src/pm-plugins/drag-and-drop/types.ts +3 -0
  117. package/src/pm-plugins/keymap.ts +3 -0
  118. package/src/pm-plugins/main.ts +47 -2
  119. package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
  120. package/src/pm-plugins/table-resizing/plugin.ts +18 -1
  121. package/src/pm-plugins/table-selection-keymap.ts +2 -2
  122. package/src/reducer.ts +5 -2
  123. package/src/types.ts +16 -0
  124. package/src/ui/DragHandle/HandleIconComponent.tsx +2 -9
  125. package/src/ui/DragHandle/index.tsx +37 -16
  126. package/src/ui/FloatingDragMenu/DragMenu.tsx +362 -310
  127. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +150 -0
  128. package/src/ui/FloatingDragMenu/index.tsx +3 -3
  129. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +72 -91
  130. package/src/ui/TableFloatingColumnControls/index.tsx +1 -2
  131. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +5 -0
  132. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +89 -104
  133. package/src/ui/common-styles.ts +11 -1
  134. package/src/ui/consts.ts +1 -0
  135. package/tsconfig.app.json +3 -0
@@ -3,6 +3,7 @@ import type {
3
3
  Command,
4
4
  GetEditorContainerWidth,
5
5
  } from '@atlaskit/editor-common/types';
6
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
7
  import { TableMap } from '@atlaskit/editor-tables';
7
8
  import type { CellAttributes, Direction } from '@atlaskit/editor-tables/types';
8
9
  import {
@@ -15,10 +16,17 @@ import {
15
16
  } from '@atlaskit/editor-tables/utils';
16
17
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
18
 
19
+ import { getDecorations } from '../pm-plugins/decorations/plugin';
20
+ import {
21
+ buildColumnResizingDecorations,
22
+ clearColumnResizingDecorations,
23
+ } from '../pm-plugins/decorations/utils';
24
+ import { createCommand, getPluginState } from '../pm-plugins/plugin-factory';
18
25
  import {
19
26
  getPluginState as getTableResizingPluginState,
20
27
  createCommand as tableResizingPluginCreateCommand,
21
28
  } from '../pm-plugins/table-resizing/plugin-factory';
29
+ import { pluginKey as tableResizingPK } from '../pm-plugins/table-resizing/plugin-key';
22
30
  import {
23
31
  currentColWidth,
24
32
  getResizeState,
@@ -27,9 +35,23 @@ import {
27
35
  updateControls,
28
36
  } from '../pm-plugins/table-resizing/utils';
29
37
  import { updateColumnWidths } from '../transforms';
30
- import { getSelectedColumnIndexes } from '../utils';
38
+ import { TableDecorations } from '../types';
39
+ import type { TablePluginAction } from '../types';
40
+ import {
41
+ createColumnLineResize,
42
+ getSelectedColumnIndexes,
43
+ updateDecorations,
44
+ } from '../utils';
31
45
 
32
- import { addResizeHandleDecorations, showResizeHandleLine } from './index';
46
+ const getTablePluginCommand = (
47
+ actionPayload: TablePluginAction,
48
+ originalTr?: Transaction,
49
+ ): Command => {
50
+ return createCommand(
51
+ () => actionPayload,
52
+ (tr) => (originalTr || tr).setMeta('addToHistory', false),
53
+ );
54
+ };
33
55
 
34
56
  const updateResizeHandleAndStatePosition =
35
57
  (
@@ -38,19 +60,64 @@ const updateResizeHandleAndStatePosition =
38
60
  nextResizeHandlePos: number,
39
61
  ): Command =>
40
62
  (state, dispatch) => {
41
- addResizeHandleDecorations(rowIndex, columnIndex, true)(state, dispatch);
42
- // Currently only 'right' position is used in showResizeHandleLine
43
- showResizeHandleLine({
44
- left: 0,
45
- right: columnIndex,
46
- })(state, dispatch);
63
+ let customTr = state.tr;
64
+ const {
65
+ pluginConfig: { allowColumnResizing },
66
+ getIntl,
67
+ } = getPluginState(state);
47
68
 
48
- tableResizingPluginCreateCommand({
69
+ const fakeDispatch = (tr: Transaction) => {
70
+ customTr = tr;
71
+ };
72
+
73
+ if (!allowColumnResizing) {
74
+ return false;
75
+ }
76
+
77
+ const decorationsWithWidget = buildColumnResizingDecorations(
78
+ rowIndex,
79
+ columnIndex,
80
+ true,
81
+ getIntl,
82
+ )({
83
+ tr: customTr,
84
+ decorationSet: getDecorations(state),
85
+ });
86
+
87
+ const decorationsWithWidgetAndHandle = updateDecorations(
88
+ customTr.doc,
89
+ decorationsWithWidget,
90
+ createColumnLineResize(state.selection, {
91
+ right: columnIndex,
92
+ }),
93
+ TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
94
+ );
95
+
96
+ getTablePluginCommand(
97
+ {
98
+ type: 'START_KEYBOARD_COLUMN_RESIZE',
99
+ data: {
100
+ resizeHandleRowIndex: rowIndex,
101
+ resizeHandleColumnIndex: columnIndex,
102
+ resizeHandleIncludeTooltip: true,
103
+ isKeyboardResize: true,
104
+ decorationSet: decorationsWithWidgetAndHandle,
105
+ },
106
+ },
107
+ customTr,
108
+ )(state, fakeDispatch);
109
+
110
+ customTr.setMeta(tableResizingPK, {
49
111
  type: 'SET_RESIZE_HANDLE_POSITION',
50
112
  data: {
51
113
  resizeHandlePos: nextResizeHandlePos,
52
114
  },
53
- })(state, dispatch);
115
+ });
116
+
117
+ if (dispatch) {
118
+ dispatch(customTr);
119
+ return true;
120
+ }
54
121
  return false;
55
122
  };
56
123
 
@@ -69,39 +136,24 @@ export const initiateKeyboardColumnResizing: Command = (
69
136
  const cell = findCellClosestToPos(selection.$from);
70
137
 
71
138
  if (selectionRect && cell && view) {
72
- const cellAttrs = cell.node.attrs;
73
- const width = currentColWidth(view, cell.pos, cellAttrs as CellAttributes);
74
-
75
- updateResizeHandleAndStatePosition(
139
+ return updateResizeHandleAndStatePosition(
76
140
  selectionRect.top,
77
141
  selectionRect.right,
78
142
  cell.pos,
79
143
  )(state, dispatch);
80
-
81
- tableResizingPluginCreateCommand({
82
- type: 'SET_DRAGGING',
83
- data: {
84
- dragging: {
85
- startX: 0,
86
- startWidth: width,
87
- },
88
- },
89
- })(state, dispatch);
90
- return true;
91
144
  }
92
145
  return false;
93
146
  };
94
147
 
95
148
  export const activateNextResizeArea =
96
149
  (direction: Direction): Command =>
97
- (state, dispatch) => {
150
+ (state, dispatch, view) => {
98
151
  if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
99
152
  return false;
100
153
  }
101
- const { resizeHandlePos, dragging } =
102
- getTableResizingPluginState(state) || {};
154
+ const { resizeHandlePos } = getTableResizingPluginState(state) || {};
103
155
  // If No resizing has initiated, skip to regular handler
104
- if (!resizeHandlePos || !dragging) {
156
+ if (!resizeHandlePos) {
105
157
  return false;
106
158
  }
107
159
 
@@ -135,11 +187,11 @@ export const activateNextResizeArea =
135
187
  // we are somewhere in between the side columns of the table
136
188
  const offset = $nextCell.pos - $nextCell.start(-1);
137
189
  const rectForNextCell = tableMap.findCell(offset);
138
- updateResizeHandleAndStatePosition(
190
+ return updateResizeHandleAndStatePosition(
139
191
  rectForNextCell.top,
140
192
  rectForNextCell.right,
141
193
  $nextCell.pos,
142
- )(state, dispatch);
194
+ )(state, dispatch, view);
143
195
  } else {
144
196
  // current position is in the one of the side columns of the table(left or right)
145
197
  if (currentCellRect.left === 0) {
@@ -151,25 +203,25 @@ export const activateNextResizeArea =
151
203
  ) + closestTable.start;
152
204
  const $lastCell = state.doc.resolve(lastCellInCurrentRow);
153
205
 
154
- updateResizeHandleAndStatePosition(
206
+ return updateResizeHandleAndStatePosition(
155
207
  currentCellRect.top,
156
208
  tableMap.width,
157
209
  $lastCell.pos,
158
- )(state, dispatch);
210
+ )(state, dispatch, view);
159
211
  } else if (tableMap.width === currentCellRect.right) {
160
212
  const firsCellInCurrentRow =
161
213
  tableMap.positionAt(currentCellRect.top, 0, tableNode) +
162
214
  closestTable.start;
163
215
  const $nextCell = state.doc.resolve(firsCellInCurrentRow);
164
216
 
165
- updateResizeHandleAndStatePosition(
217
+ return updateResizeHandleAndStatePosition(
166
218
  currentCellRect.top,
167
219
  1,
168
220
  $nextCell.pos,
169
221
  )(state, dispatch);
170
222
  }
171
223
  }
172
- return true;
224
+ return false;
173
225
  };
174
226
 
175
227
  export const changeColumnWidthByStep =
@@ -178,11 +230,16 @@ export const changeColumnWidthByStep =
178
230
  getEditorContainerWidth: GetEditorContainerWidth,
179
231
  ): Command =>
180
232
  (state, dispatch, view) => {
233
+ let customTr = state.tr;
234
+ const fakeDispatch = (tr: Transaction) => {
235
+ customTr = tr;
236
+ };
181
237
  if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
182
238
  return false;
183
239
  }
184
- const { resizeHandlePos, dragging } = getTableResizingPluginState(state);
185
- if (!view || !resizeHandlePos || !dragging) {
240
+ const { resizeHandlePos } = getTableResizingPluginState(state);
241
+ const cell = findCellClosestToPos(state.selection.$from);
242
+ if (!view || !resizeHandlePos || !cell) {
186
243
  return false;
187
244
  }
188
245
 
@@ -205,6 +262,18 @@ export const changeColumnWidthByStep =
205
262
  dom = dom.closest('table') as HTMLTableElement;
206
263
  }
207
264
 
265
+ const cellAttrs = cell?.node.attrs;
266
+ const width = currentColWidth(view, cell?.pos, cellAttrs as CellAttributes);
267
+ tableResizingPluginCreateCommand({
268
+ type: 'SET_DRAGGING',
269
+ data: {
270
+ dragging: {
271
+ startX: 0,
272
+ startWidth: width,
273
+ },
274
+ },
275
+ })(state, fakeDispatch);
276
+
208
277
  const maxSize = getTableMaxWidth({
209
278
  table: originalTable,
210
279
  tableStart: tableStartPosition,
@@ -240,15 +309,61 @@ export const changeColumnWidthByStep =
240
309
  resizingSelectedColumns ? selectedColumns : undefined,
241
310
  );
242
311
 
243
- const tr = updateColumnWidths(
312
+ customTr = updateColumnWidths(
244
313
  newResizeState,
245
314
  originalTable,
246
315
  tableStartPosition,
247
- )(state.tr);
316
+ )(customTr);
248
317
 
249
318
  if (dispatch) {
250
- dispatch(tr);
319
+ dispatch(customTr);
251
320
  }
252
321
 
253
322
  return true;
254
323
  };
324
+
325
+ export const stopKeyboardColumnResizing =
326
+ (originalTr?: Transaction): Command =>
327
+ (state, dispatch) => {
328
+ if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
329
+ return false;
330
+ }
331
+ let customTr = originalTr || state.tr;
332
+ const fakeDispatch = (tr: Transaction) => {
333
+ customTr = tr;
334
+ };
335
+
336
+ const decorationWithoutWidget = clearColumnResizingDecorations()({
337
+ tr: customTr,
338
+ decorationSet: getDecorations(state),
339
+ });
340
+
341
+ const decorationWithoutWidgetAndHandle = updateDecorations(
342
+ customTr.doc,
343
+ decorationWithoutWidget,
344
+ [],
345
+ TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
346
+ );
347
+ getTablePluginCommand(
348
+ {
349
+ type: 'STOP_KEYBOARD_COLUMN_RESIZE',
350
+ data: {
351
+ decorationSet: decorationWithoutWidgetAndHandle,
352
+ },
353
+ },
354
+ customTr,
355
+ )(state, fakeDispatch);
356
+
357
+ tableResizingPluginCreateCommand(
358
+ {
359
+ type: 'STOP_RESIZING',
360
+ },
361
+ () => customTr.setMeta('scrollIntoView', false),
362
+ )(state, fakeDispatch);
363
+
364
+ if (dispatch) {
365
+ dispatch(customTr);
366
+ return true;
367
+ }
368
+ return false;
369
+ };
@@ -13,12 +13,9 @@ import {
13
13
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
14
 
15
15
  import { insertRowWithAnalytics } from '../commands-with-analytics';
16
- import {
17
- getPluginState as getResizePluginState,
18
- createCommand as tableResizingPluginCreateCommand,
19
- } from '../pm-plugins/table-resizing/plugin-factory';
16
+ import { getPluginState } from '../pm-plugins/plugin-factory';
20
17
 
21
- import { hideResizeHandleLine } from './hover';
18
+ import { stopKeyboardColumnResizing } from './column-resize';
22
19
 
23
20
  const TAB_FORWARD_DIRECTION = 1;
24
21
  const TAB_BACKWARD_DIRECTION = -1;
@@ -26,23 +23,17 @@ const TAB_BACKWARD_DIRECTION = -1;
26
23
  export const goToNextCell =
27
24
  (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
28
25
  (direction: Direction): Command =>
29
- (state, dispatch) => {
26
+ (state, dispatch, view) => {
30
27
  const table = findTable(state.selection);
31
28
  if (!table) {
32
29
  return false;
33
30
  }
34
31
 
35
32
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
36
- const isColumnResizing = !!getResizePluginState(state)?.dragging;
33
+ const isColumnResizing = getPluginState(state)?.isKeyboardResize;
37
34
  if (isColumnResizing) {
38
- tableResizingPluginCreateCommand(
39
- {
40
- type: 'STOP_RESIZING',
41
- },
42
- (originalTr) =>
43
- (state.tr || originalTr).setMeta('scrollIntoView', false),
44
- )(state, dispatch);
45
- hideResizeHandleLine()(state, dispatch);
35
+ stopKeyboardColumnResizing()(state, dispatch, view);
36
+ return true;
46
37
  }
47
38
  }
48
39
 
@@ -463,7 +463,11 @@ export const setMultipleCellAttrs =
463
463
  return false;
464
464
  };
465
465
 
466
- export const selectColumn = (column: number, expand?: boolean) =>
466
+ export const selectColumn = (
467
+ column: number,
468
+ expand?: boolean,
469
+ triggeredByKeyboard = false,
470
+ ) =>
467
471
  createCommand(
468
472
  (state) => {
469
473
  const cells = getCellsInColumn(column)(state.tr.selection);
@@ -487,7 +491,9 @@ export const selectColumn = (column: number, expand?: boolean) =>
487
491
  };
488
492
  },
489
493
  (tr: Transaction) =>
490
- selectColumnTransform(column, expand)(tr).setMeta('addToHistory', false),
494
+ selectColumnTransform(column, expand)(tr)
495
+ .setMeta('addToHistory', false)
496
+ .setMeta('selectedColumnViaKeyboard', triggeredByKeyboard),
491
497
  );
492
498
 
493
499
  export const selectColumns = (columnIndexes: number[]) =>
@@ -537,7 +543,11 @@ export const selectColumns = (columnIndexes: number[]) =>
537
543
  },
538
544
  );
539
545
 
540
- export const selectRow = (row: number, expand?: boolean) =>
546
+ export const selectRow = (
547
+ row: number,
548
+ expand?: boolean,
549
+ triggeredByKeyboard = false,
550
+ ) =>
541
551
  createCommand(
542
552
  (state) => {
543
553
  let targetCellPosition;
@@ -548,7 +558,10 @@ export const selectRow = (row: number, expand?: boolean) =>
548
558
 
549
559
  return { type: 'SET_TARGET_CELL_POSITION', data: { targetCellPosition } };
550
560
  },
551
- (tr) => selectRowTransform(row, expand)(tr).setMeta('addToHistory', false),
561
+ (tr) =>
562
+ selectRowTransform(row, expand)(tr)
563
+ .setMeta('addToHistory', false)
564
+ .setMeta('selectedRowViaKeyboard', triggeredByKeyboard),
552
565
  );
553
566
 
554
567
  export const selectRows = (rowIndexes: number[]) =>
@@ -616,6 +629,7 @@ export const addResizeHandleDecorations = (
616
629
  rowIndex: number,
617
630
  columnIndex: number,
618
631
  includeTooltip: boolean,
632
+ isKeyboardResize?: boolean,
619
633
  ) =>
620
634
  createCommand(
621
635
  (state) => {
@@ -644,6 +658,7 @@ export const addResizeHandleDecorations = (
644
658
  resizeHandleRowIndex: rowIndex,
645
659
  resizeHandleColumnIndex: columnIndex,
646
660
  resizeHandleIncludeTooltip: includeTooltip,
661
+ isKeyboardResize: isKeyboardResize || false,
647
662
  },
648
663
  };
649
664
  },
@@ -28,7 +28,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
28
28
 
29
29
  import { selectColumn, selectRow } from '../commands/misc';
30
30
  import type tablePlugin from '../plugin';
31
- import { getPluginState as getResizePluginState } from '../pm-plugins/table-resizing/plugin-factory';
31
+ import { getPluginState } from '../pm-plugins/plugin-factory';
32
32
  import { getClosestSelectionRect } from '../toolbar';
33
33
 
34
34
  export enum TableSelectionDirection {
@@ -157,7 +157,7 @@ export const selectColumns =
157
157
  | ExtractInjectionAPI<typeof tablePlugin>['selection']
158
158
  | undefined,
159
159
  ) =>
160
- (): Command =>
160
+ (triggeredByKeyboard = false): Command =>
161
161
  (state, dispatch) => {
162
162
  const { selection } = state;
163
163
  const table = findTable(selection);
@@ -170,7 +170,11 @@ export const selectColumns =
170
170
  })(state, dispatch);
171
171
  }
172
172
  if (table && rect) {
173
- return selectColumn(rect.left)(state, dispatch);
173
+ return selectColumn(
174
+ rect.left,
175
+ undefined,
176
+ triggeredByKeyboard,
177
+ )(state, dispatch);
174
178
  }
175
179
  return false;
176
180
  };
@@ -181,7 +185,7 @@ export const selectRows =
181
185
  | ExtractInjectionAPI<typeof tablePlugin>['selection']
182
186
  | undefined,
183
187
  ) =>
184
- (): Command =>
188
+ (triggeredByKeyboard = false): Command =>
185
189
  (state, dispatch) => {
186
190
  const { selection } = state;
187
191
  const table = findTable(selection);
@@ -194,7 +198,11 @@ export const selectRows =
194
198
  })(state, dispatch);
195
199
  }
196
200
  if (table && rect) {
197
- return selectRow(rect.top)(state, dispatch);
201
+ return selectRow(
202
+ rect.top,
203
+ undefined,
204
+ triggeredByKeyboard,
205
+ )(state, dispatch);
198
206
  }
199
207
  return false;
200
208
  };
@@ -294,8 +302,8 @@ const arrowLeftFromText =
294
302
  let isColumnResizing = false;
295
303
 
296
304
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
297
- const columResizePluginState = getResizePluginState(state) || {};
298
- isColumnResizing = Boolean(columResizePluginState?.dragging);
305
+ const columResizePluginState = getPluginState(state) || {};
306
+ isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
299
307
  }
300
308
 
301
309
  if (
@@ -343,8 +351,8 @@ const arrowRightFromText =
343
351
  let isColumnResizing = false;
344
352
 
345
353
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
346
- const columResizePluginState = getResizePluginState(state) || {};
347
- isColumnResizing = Boolean(columResizePluginState?.dragging);
354
+ const columResizePluginState = getPluginState(state) || {};
355
+ isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
348
356
  }
349
357
  if (
350
358
  isSelectionAtEndOfTable($to, selection) &&
@@ -27,6 +27,7 @@ import {
27
27
  getSelectionRect,
28
28
  removeTable,
29
29
  } from '@atlaskit/editor-tables/utils';
30
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
30
31
 
31
32
  import {
32
33
  addResizeHandleDecorations,
@@ -295,7 +296,16 @@ export const handleMouseOut = (
295
296
  !isResizeHandleDecoration(relatedTarget)
296
297
  ) {
297
298
  const { state, dispatch } = view;
298
- return hideResizeHandleLine()(state, dispatch);
299
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
300
+ const { isKeyboardResize } = getPluginState(state);
301
+ if (isKeyboardResize) {
302
+ // no need to hide decoration if column resizing started by keyboard
303
+ return false;
304
+ }
305
+ return hideResizeHandleLine()(state, dispatch);
306
+ } else {
307
+ return hideResizeHandleLine()(state, dispatch);
308
+ }
299
309
  }
300
310
 
301
311
  return false;
@@ -421,6 +431,12 @@ export const handleMouseMove = (
421
431
  const { state, dispatch } = view;
422
432
  const { resizeHandleColumnIndex, resizeHandleRowIndex } =
423
433
  getPluginState(state);
434
+
435
+ const isKeyboardResize = getBooleanFF(
436
+ 'platform.editor.a11y-column-resizing_emcvz',
437
+ )
438
+ ? getPluginState(state).isKeyboardResize
439
+ : false;
424
440
  const tableCell = closestElement(
425
441
  element,
426
442
  'td, th',
@@ -437,9 +453,10 @@ export const handleMouseMove = (
437
453
  const rowIndexTarget = rect.top;
438
454
 
439
455
  if (
440
- columnEndIndexTarget !== resizeHandleColumnIndex ||
441
- rowIndexTarget !== resizeHandleRowIndex ||
442
- !hasResizeHandler({ target: element, columnEndIndexTarget })
456
+ (columnEndIndexTarget !== resizeHandleColumnIndex ||
457
+ rowIndexTarget !== resizeHandleRowIndex ||
458
+ !hasResizeHandler({ target: element, columnEndIndexTarget })) &&
459
+ !isKeyboardResize // if initiated by keyboard don't need to react on hover for other resize sliders
443
460
  ) {
444
461
  return addResizeHandleDecorations(
445
462
  rowIndexTarget,
@@ -37,6 +37,7 @@ export type DragAndDropToggleDragMenuAction = DragAndDropAction<
37
37
  isDragMenuOpen: boolean;
38
38
  direction: TableDirection;
39
39
  index: number;
40
+ isKeyboardModeActive: boolean;
40
41
  }
41
42
  >;
42
43
 
@@ -18,6 +18,7 @@ import { DragAndDropActionType } from './actions';
18
18
  import { DropTargetType } from './consts';
19
19
  import { createCommand, getPluginState } from './plugin-factory';
20
20
  import { pluginKey } from './plugin-key';
21
+ import type { TriggerType } from './types';
21
22
 
22
23
  // TODO: This command is a placeholder example. Please replace this if required.
23
24
  export const getDecorations = (state: EditorState): DecorationSet => {
@@ -122,6 +123,7 @@ export const toggleDragMenu = (
122
123
  isDragMenuOpen: boolean | undefined,
123
124
  direction?: TableDirection,
124
125
  index?: number,
126
+ trigger: TriggerType = 'mouse',
125
127
  ) =>
126
128
  createCommand(
127
129
  (state) => {
@@ -165,6 +167,7 @@ export const toggleDragMenu = (
165
167
  isDragMenuOpen: updatedMenuOpenState,
166
168
  direction: direction ?? previousDragMenuDirection,
167
169
  index: index ?? previousDragMenuIndex,
170
+ isKeyboardModeActive: updatedMenuOpenState && trigger === 'keyboard',
168
171
  },
169
172
  };
170
173
  },
@@ -242,6 +242,7 @@ export const createPlugin = (
242
242
  isDragMenuOpen: false,
243
243
  dragMenuIndex: 0,
244
244
  isDragging: false,
245
+ isKeyboardModeActive: false,
245
246
  })),
246
247
  key: pluginKey,
247
248
  appendTransaction: (transactions, oldState, newState) => {
@@ -251,6 +252,21 @@ export const createPlugin = (
251
252
  getTablePluginState(newState);
252
253
  const { isDragMenuOpen, dragMenuIndex } = getPluginState(newState);
253
254
 
255
+ transactions.forEach((transaction) => {
256
+ if (transaction.getMeta('selectedRowViaKeyboard')) {
257
+ const button = document.querySelector('#drag-handle-button-row');
258
+ if (button) {
259
+ (button as HTMLButtonElement).focus();
260
+ }
261
+ }
262
+ if (transaction.getMeta('selectedColumnViaKeyboard')) {
263
+ const button = document.querySelector('#drag-handle-button-column');
264
+ if (button) {
265
+ (button as HTMLButtonElement).focus();
266
+ }
267
+ }
268
+ });
269
+
254
270
  // What's happening here? you asked... In a nutshell;
255
271
  // If the target cell position changes while the drag menu is open then we want to close the drag menu if it has been opened.
256
272
  // This will stop the drag menu from moving around the screen to different row/cols. Too achieve this we need
@@ -296,6 +312,37 @@ export const createPlugin = (
296
312
  const { decorationSet } = getPluginState(state);
297
313
  return decorationSet;
298
314
  },
315
+ handleKeyDown: (view, event) => {
316
+ const isDragHandleFocused = [
317
+ 'drag-handle-button-row',
318
+ 'drag-handle-button-column',
319
+ ].includes(((event.target as HTMLElement) || null)?.id);
320
+ const keysToTrap = ['Enter', ' '];
321
+ const keysToTrapWhen = [
322
+ 'ArrowUp',
323
+ 'ArrowDown',
324
+ 'ArrowLeft',
325
+ 'ArrowRight',
326
+ ];
327
+ const { isDragMenuOpen } = getPluginState(view.state);
328
+
329
+ // drag handle is focused, and user presses any key return them back to editing
330
+ if (
331
+ isDragHandleFocused &&
332
+ !isDragMenuOpen &&
333
+ !keysToTrap.includes(event.key)
334
+ ) {
335
+ view.dom.focus();
336
+ return true;
337
+ }
338
+
339
+ if (
340
+ (isDragHandleFocused && keysToTrap.includes(event.key)) ||
341
+ (isDragMenuOpen && keysToTrapWhen.includes(event.key))
342
+ ) {
343
+ return true;
344
+ }
345
+ },
299
346
  },
300
347
  });
301
348
  };
@@ -30,6 +30,7 @@ export default (
30
30
  isDragMenuOpen: action.data.isDragMenuOpen,
31
31
  dragMenuDirection: action.data.direction,
32
32
  dragMenuIndex: action.data.index,
33
+ isKeyboardModeActive: action.data.isKeyboardModeActive,
33
34
  };
34
35
  default:
35
36
  return pluginState;
@@ -12,4 +12,7 @@ export interface DragAndDropPluginState {
12
12
  dragMenuDirection?: TableDirection;
13
13
  dragMenuIndex: number;
14
14
  isDragging: boolean;
15
+ isKeyboardModeActive: boolean;
15
16
  }
17
+
18
+ export type TriggerType = 'mouse' | 'keyboard';
@@ -16,6 +16,7 @@ import {
16
16
  decreaseMediaSize,
17
17
  deleteColumn,
18
18
  deleteRow,
19
+ escape,
19
20
  increaseMediaSize,
20
21
  moveColumnLeft,
21
22
  moveColumnRight,
@@ -45,6 +46,7 @@ import {
45
46
  activateNextResizeArea,
46
47
  changeColumnWidthByStep,
47
48
  initiateKeyboardColumnResizing,
49
+ stopKeyboardColumnResizing,
48
50
  } from '../commands/column-resize';
49
51
  import {
50
52
  addColumnAfter as addColumnAfterCommand,
@@ -190,6 +192,7 @@ export function keymapPlugin(
190
192
  changeColumnWidthByStep(10, getEditorContainerWidth),
191
193
  list,
192
194
  );
195
+ bindKeymapWithCommand(escape.common!, stopKeyboardColumnResizing(), list);
193
196
  }
194
197
 
195
198
  return keymap(list) as SafePlugin;