@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
@@ -5,7 +5,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { findTable, isColumnSelected, isRowSelected, isTableSelected, selectedRect } from '@atlaskit/editor-tables/utils';
6
6
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
7
  import { selectColumn, selectRow } from '../commands/misc';
8
- import { getPluginState as getResizePluginState } from '../pm-plugins/table-resizing/plugin-factory';
8
+ import { getPluginState } from '../pm-plugins/plugin-factory';
9
9
  import { getClosestSelectionRect } from '../toolbar';
10
10
  export let TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
11
11
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
@@ -69,7 +69,7 @@ const arrowRightFromCellSelection = editorSelectionAPI => selection => (state, d
69
69
  }
70
70
  return false;
71
71
  };
72
- export const selectColumns = editorSelectionAPI => () => (state, dispatch) => {
72
+ export const selectColumns = editorSelectionAPI => (triggeredByKeyboard = false) => (state, dispatch) => {
73
73
  const {
74
74
  selection
75
75
  } = state;
@@ -83,11 +83,11 @@ export const selectColumns = editorSelectionAPI => () => (state, dispatch) => {
83
83
  })(state, dispatch);
84
84
  }
85
85
  if (table && rect) {
86
- return selectColumn(rect.left)(state, dispatch);
86
+ return selectColumn(rect.left, undefined, triggeredByKeyboard)(state, dispatch);
87
87
  }
88
88
  return false;
89
89
  };
90
- export const selectRows = editorSelectionAPI => () => (state, dispatch) => {
90
+ export const selectRows = editorSelectionAPI => (triggeredByKeyboard = false) => (state, dispatch) => {
91
91
  const {
92
92
  selection
93
93
  } = state;
@@ -101,7 +101,7 @@ export const selectRows = editorSelectionAPI => () => (state, dispatch) => {
101
101
  })(state, dispatch);
102
102
  }
103
103
  if (table && rect) {
104
- return selectRow(rect.top)(state, dispatch);
104
+ return selectRow(rect.top, undefined, triggeredByKeyboard)(state, dispatch);
105
105
  }
106
106
  return false;
107
107
  };
@@ -179,8 +179,8 @@ const arrowLeftFromText = editorSelectionAPI => selection => (state, dispatch) =
179
179
  } = selection;
180
180
  let isColumnResizing = false;
181
181
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
182
- const columResizePluginState = getResizePluginState(state) || {};
183
- isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.dragging);
182
+ const columResizePluginState = getPluginState(state) || {};
183
+ isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.isKeyboardResize);
184
184
  }
185
185
  if (isSelectionAtStartOfTable($from, selection) && $from.parent.type.name === 'paragraph' && $from.depth === table.depth + 3 &&
186
186
  // + 3 for: row, cell & paragraph nodes
@@ -211,8 +211,8 @@ const arrowRightFromText = editorSelectionAPI => selection => (state, dispatch)
211
211
  } = selection;
212
212
  let isColumnResizing = false;
213
213
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
214
- const columResizePluginState = getResizePluginState(state) || {};
215
- isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.dragging);
214
+ const columResizePluginState = getPluginState(state) || {};
215
+ isColumnResizing = Boolean(columResizePluginState === null || columResizePluginState === void 0 ? void 0 : columResizePluginState.isKeyboardResize);
216
216
  }
217
217
  if (isSelectionAtEndOfTable($to, selection) && $to.parent.type.name === 'paragraph' && $to.depth === table.depth + 3 &&
218
218
  // + 3 for: row, cell & paragraph nodes
@@ -4,6 +4,7 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { cellAround, findCellRectClosestToPos, findTable, getSelectionRect, removeTable } from '@atlaskit/editor-tables/utils';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { addResizeHandleDecorations, clearHoverSelection, hideInsertColumnOrRowButton, hideResizeHandleLine, hoverCell, hoverColumns, selectColumn, setEditorFocus, setTableHovered, showInsertColumnButton, showInsertRowButton, showResizeHandleLine } from './commands';
8
9
  import { getPluginState as getDragDropPluginState } from './pm-plugins/drag-and-drop/plugin-factory';
9
10
  import { getPluginState } from './pm-plugins/plugin-factory';
@@ -164,7 +165,18 @@ export const handleMouseOut = (view, mouseEvent) => {
164
165
  state,
165
166
  dispatch
166
167
  } = view;
167
- return hideResizeHandleLine()(state, dispatch);
168
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
169
+ const {
170
+ isKeyboardResize
171
+ } = getPluginState(state);
172
+ if (isKeyboardResize) {
173
+ // no need to hide decoration if column resizing started by keyboard
174
+ return false;
175
+ }
176
+ return hideResizeHandleLine()(state, dispatch);
177
+ } else {
178
+ return hideResizeHandleLine()(state, dispatch);
179
+ }
168
180
  }
169
181
  return false;
170
182
  };
@@ -265,16 +277,18 @@ export const handleMouseMove = (view, event, elementContentRects) => {
265
277
  resizeHandleColumnIndex,
266
278
  resizeHandleRowIndex
267
279
  } = getPluginState(state);
280
+ const isKeyboardResize = getBooleanFF('platform.editor.a11y-column-resizing_emcvz') ? getPluginState(state).isKeyboardResize : false;
268
281
  const tableCell = closestElement(element, 'td, th');
269
282
  const cellStartPosition = view.posAtDOM(tableCell, 0);
270
283
  const rect = findCellRectClosestToPos(state.doc.resolve(cellStartPosition));
271
284
  if (rect) {
272
285
  const columnEndIndexTarget = positionColumn === 'left' ? rect.left : rect.right;
273
286
  const rowIndexTarget = rect.top;
274
- if (columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !hasResizeHandler({
287
+ if ((columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !hasResizeHandler({
275
288
  target: element,
276
289
  columnEndIndexTarget
277
- })) {
290
+ })) && !isKeyboardResize // if initiated by keyboard don't need to react on hover for other resize sliders
291
+ ) {
278
292
  return addResizeHandleDecorations(rowIndexTarget, columnEndIndexTarget, true)(state, dispatch);
279
293
  }
280
294
  }
@@ -6,7 +6,6 @@ import { DragAndDropActionType } from './actions';
6
6
  import { DropTargetType } from './consts';
7
7
  import { createCommand, getPluginState } from './plugin-factory';
8
8
  import { pluginKey } from './plugin-key';
9
-
10
9
  // TODO: This command is a placeholder example. Please replace this if required.
11
10
  export const getDecorations = state => {
12
11
  var _pluginKey$getState;
@@ -68,7 +67,7 @@ export const moveSource = (sourceType, sourceIndexes, targetIndex, tr) => create
68
67
  selectAfterMove: true
69
68
  })(nextTr);
70
69
  });
71
- export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
70
+ export const toggleDragMenu = (isDragMenuOpen, direction, index, trigger = 'mouse') => createCommand(state => {
72
71
  let {
73
72
  isDragMenuOpen: previousOpenState,
74
73
  dragMenuDirection: previousDragMenuDirection,
@@ -95,7 +94,8 @@ export const toggleDragMenu = (isDragMenuOpen, direction, index) => createComman
95
94
  data: {
96
95
  isDragMenuOpen: updatedMenuOpenState,
97
96
  direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
98
- index: index !== null && index !== void 0 ? index : previousDragMenuIndex
97
+ index: index !== null && index !== void 0 ? index : previousDragMenuIndex,
98
+ isKeyboardModeActive: updatedMenuOpenState && trigger === 'keyboard'
99
99
  }
100
100
  };
101
101
  }, tr => {
@@ -177,7 +177,8 @@ export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
177
177
  dropTargetIndex: 0,
178
178
  isDragMenuOpen: false,
179
179
  dragMenuIndex: 0,
180
- isDragging: false
180
+ isDragging: false,
181
+ isKeyboardModeActive: false
181
182
  })),
182
183
  key: pluginKey,
183
184
  appendTransaction: (transactions, oldState, newState) => {
@@ -191,6 +192,20 @@ export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
191
192
  isDragMenuOpen,
192
193
  dragMenuIndex
193
194
  } = getPluginState(newState);
195
+ transactions.forEach(transaction => {
196
+ if (transaction.getMeta('selectedRowViaKeyboard')) {
197
+ const button = document.querySelector('#drag-handle-button-row');
198
+ if (button) {
199
+ button.focus();
200
+ }
201
+ }
202
+ if (transaction.getMeta('selectedColumnViaKeyboard')) {
203
+ const button = document.querySelector('#drag-handle-button-column');
204
+ if (button) {
205
+ button.focus();
206
+ }
207
+ }
208
+ });
194
209
 
195
210
  // What's happening here? you asked... In a nutshell;
196
211
  // 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.
@@ -232,6 +247,24 @@ export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
232
247
  decorationSet
233
248
  } = getPluginState(state);
234
249
  return decorationSet;
250
+ },
251
+ handleKeyDown: (view, event) => {
252
+ var _ref;
253
+ const isDragHandleFocused = ['drag-handle-button-row', 'drag-handle-button-column'].includes((_ref = event.target || null) === null || _ref === void 0 ? void 0 : _ref.id);
254
+ const keysToTrap = ['Enter', ' '];
255
+ const keysToTrapWhen = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
256
+ const {
257
+ isDragMenuOpen
258
+ } = getPluginState(view.state);
259
+
260
+ // drag handle is focused, and user presses any key return them back to editing
261
+ if (isDragHandleFocused && !isDragMenuOpen && !keysToTrap.includes(event.key)) {
262
+ view.dom.focus();
263
+ return true;
264
+ }
265
+ if (isDragHandleFocused && keysToTrap.includes(event.key) || isDragMenuOpen && keysToTrapWhen.includes(event.key)) {
266
+ return true;
267
+ }
235
268
  }
236
269
  }
237
270
  });
@@ -23,7 +23,8 @@ export default ((pluginState, action) => {
23
23
  ...pluginState,
24
24
  isDragMenuOpen: action.data.isDragMenuOpen,
25
25
  dragMenuDirection: action.data.direction,
26
- dragMenuIndex: action.data.index
26
+ dragMenuIndex: action.data.index,
27
+ isKeyboardModeActive: action.data.isKeyboardModeActive
27
28
  };
28
29
  default:
29
30
  return pluginState;
@@ -1,11 +1,11 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, decreaseMediaSize, deleteColumn, deleteRow, increaseMediaSize, moveColumnLeft, moveColumnRight, moveLeft, moveRight, moveRowDown, moveRowUp, nextCell, previousCell, startColumnResizing, toggleTable } from '@atlaskit/editor-common/keymaps';
2
+ import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, decreaseMediaSize, deleteColumn, deleteRow, escape, increaseMediaSize, moveColumnLeft, moveColumnRight, moveLeft, moveRight, moveRowDown, moveRowUp, nextCell, previousCell, startColumnResizing, toggleTable } from '@atlaskit/editor-common/keymaps';
3
3
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
4
4
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
6
  import { createTable, goToNextCell, moveCursorBackward } from '../commands';
7
7
  import { addRowAroundSelection, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut, deleteTableIfSelectedWithAnalytics, emptyMultipleCellsWithAnalytics } from '../commands-with-analytics';
8
- import { activateNextResizeArea, changeColumnWidthByStep, initiateKeyboardColumnResizing } from '../commands/column-resize';
8
+ import { activateNextResizeArea, changeColumnWidthByStep, initiateKeyboardColumnResizing, stopKeyboardColumnResizing } from '../commands/column-resize';
9
9
  import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand } from '../commands/insert';
10
10
  import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
11
11
  import { withEditorAnalyticsAPI } from '../utils/analytics';
@@ -48,6 +48,7 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
48
48
  bindKeymapWithCommand(moveLeft.common, activateNextResizeArea(-1), list);
49
49
  bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth), list);
50
50
  bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth), list);
51
+ bindKeymapWithCommand(escape.common, stopKeyboardColumnResizing(), list);
51
52
  }
52
53
  return keymap(list);
53
54
  }
@@ -4,7 +4,11 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { transformSliceToRemoveOpenBodiedExtension, transformSliceToRemoveOpenExpand, transformSliceToRemoveOpenLayoutNodes, transformSliceToRemoveOpenMultiBodiedExtension } from '@atlaskit/editor-common/transforms';
5
5
  import { browser, closestElement } from '@atlaskit/editor-common/utils';
6
6
  import { findParentDomRefOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
+ import { TableMap } from '@atlaskit/editor-tables';
8
+ import { findTable } from '@atlaskit/editor-tables/utils';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
10
  import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from '../commands';
11
+ import { stopKeyboardColumnResizing } from '../commands/column-resize';
8
12
  import { removeResizeHandleDecorations, transformSliceRemoveCellBackgroundColor, transformSliceToAddTableHeaders, transformSliceToRemoveColumnsWidths } from '../commands/misc';
9
13
  import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseEnter, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus, withCellTracking } from '../event-handlers';
10
14
  import { createTableView } from '../nodeviews/table';
@@ -91,7 +95,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
91
95
  const domAtPos = editorView.domAtPos.bind(editorView);
92
96
  editorViewRef = editorView;
93
97
  return {
94
- update: view => {
98
+ update: (view, prevState) => {
95
99
  const {
96
100
  state,
97
101
  dispatch
@@ -106,6 +110,28 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
106
110
  if (parent) {
107
111
  tableRef = parent.querySelector('table') || undefined;
108
112
  }
113
+ const tableNode = findTable(state.selection);
114
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
115
+ // when cursor leaves the table we need to stop column resizing
116
+ const pluginPrevState = getPluginState(prevState);
117
+ const isStopKeyboardColumResizing = pluginPrevState.isResizeHandleWidgetAdded && pluginPrevState.isKeyboardResize;
118
+ if (isStopKeyboardColumResizing) {
119
+ const isTableNodesDifferent = (pluginPrevState === null || pluginPrevState === void 0 ? void 0 : pluginPrevState.tableNode) !== (tableNode === null || tableNode === void 0 ? void 0 : tableNode.node);
120
+ if (pluginPrevState !== null && pluginPrevState !== void 0 && pluginPrevState.tableNode && tableNode && isTableNodesDifferent) {
121
+ const oldRowsNumber = TableMap.get(pluginPrevState.tableNode).height;
122
+ const newRowsNumber = TableMap.get(tableNode.node).height;
123
+ if (oldRowsNumber !== newRowsNumber ||
124
+ // Add/delete row
125
+ tableNode.node.attrs.localId !== pluginPrevState.tableNode.attrs.localId) {
126
+ // Jump to another table
127
+ stopKeyboardColumnResizing()(state, dispatch);
128
+ }
129
+ } else if (!tableNode) {
130
+ // selection outside of table
131
+ stopKeyboardColumnResizing()(state, dispatch);
132
+ }
133
+ }
134
+ }
109
135
  }
110
136
  if (pluginState.tableRef !== tableRef) {
111
137
  setTableRef(tableRef)(state, dispatch);
@@ -208,10 +234,20 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
208
234
  const maybeTr = closestElement(domRef, 'tr');
209
235
  return maybeTr ? maybeTr.classList.contains('sticky') : false;
210
236
  },
211
- handleTextInput: ({
212
- state,
213
- dispatch
214
- }, _from, _to, text) => {
237
+ handleTextInput: (view, _from, _to, text) => {
238
+ const {
239
+ state,
240
+ dispatch
241
+ } = view;
242
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
243
+ const {
244
+ isKeyboardResize
245
+ } = getPluginState(state);
246
+ if (isKeyboardResize) {
247
+ stopKeyboardColumnResizing()(state, dispatch);
248
+ return false;
249
+ }
250
+ }
215
251
  const tr = replaceSelectedTable(state, text, INPUT_METHOD.KEYBOARD, editorAnalyticsAPI);
216
252
  if (tr.selectionSet) {
217
253
  dispatch(tr);
@@ -5,9 +5,11 @@ import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
7
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
+ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
8
9
  import { updateResizeHandleDecorations } from '../../commands/misc';
9
10
  import { updateColumnWidths } from '../../transforms';
10
11
  import { getSelectedColumnIndexes } from '../../utils';
12
+ import { getPluginState as getTablePluginState } from '../plugin-factory';
11
13
  import { META_KEYS } from '../table-analytics';
12
14
  import { evenColumns, setDragging, stopResizing } from './commands';
13
15
  import { getPluginState } from './plugin-factory';
@@ -22,6 +24,9 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
22
24
  if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
23
25
  return false;
24
26
  }
27
+ const {
28
+ isKeyboardResize
29
+ } = getTablePluginState(state);
25
30
  event.preventDefault();
26
31
  const tr = view.state.tr;
27
32
  tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
@@ -96,6 +101,9 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
96
101
  dragging,
97
102
  resizeHandlePos
98
103
  } = getPluginState(state);
104
+ const {
105
+ isTableHovered
106
+ } = getTablePluginState(state);
99
107
  if (resizeHandlePos === null) {
100
108
  return stopResizing()(state, dispatch);
101
109
  }
@@ -108,9 +116,20 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
108
116
  const start = $cell.start(-1);
109
117
  const table = $cell.node(-1);
110
118
 
111
- // If we let go in the same place we started, dont need to do anything.
119
+ // If we let go in the same place we started, don't need to do anything.
112
120
  if (dragging && clientX === dragging.startX) {
113
- return stopResizing()(state, dispatch);
121
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
122
+ if (isKeyboardResize || !isTableHovered) {
123
+ /** if column resize had started via keyboard but continued by mouse
124
+ * or mouse pointer leaves the table but mouse button still pressed
125
+ */
126
+ return stopKeyboardColumnResizing()(state, dispatch, view);
127
+ } else {
128
+ return stopResizing()(state, dispatch);
129
+ }
130
+ } else {
131
+ return stopResizing()(state, dispatch);
132
+ }
114
133
  }
115
134
  let {
116
135
  tr
@@ -148,7 +167,18 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
148
167
  })(tr);
149
168
  }
150
169
  }
151
- return stopResizing(tr)(state, dispatch);
170
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
171
+ if (isKeyboardResize || !isTableHovered) {
172
+ /** if column resize had started via keyboard but continued by mouse
173
+ * or mouse pointer leaves the table but mouse button still pressed
174
+ */
175
+ return stopKeyboardColumnResizing(tr)(state, dispatch, view);
176
+ } else {
177
+ return stopResizing(tr)(state, dispatch);
178
+ }
179
+ } else {
180
+ return stopResizing(tr)(state, dispatch);
181
+ }
152
182
  }
153
183
  }
154
184
  function move(event) {
@@ -163,7 +193,10 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
163
193
  dragging,
164
194
  resizeHandlePos
165
195
  } = getPluginState(state);
166
- if (!which || !dragging || resizeHandlePos === null || !pointsAtCell(state.doc.resolve(resizeHandlePos))) {
196
+ const {
197
+ isTableHovered
198
+ } = getTablePluginState(state);
199
+ if (!which || !dragging || resizeHandlePos === null || !pointsAtCell(state.doc.resolve(resizeHandlePos)) || !isTableHovered && getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
167
200
  return finish(event);
168
201
  }
169
202
  const $cell = state.doc.resolve(resizeHandlePos);
@@ -1,6 +1,8 @@
1
1
  import classnames from 'classnames';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { TableCssClassName as ClassName } from '../../types';
5
+ import { getPluginState as getTablePluginState } from '../plugin-factory';
4
6
  import { setResizeHandlePos } from './commands';
5
7
  import { handleMouseDown } from './event-handlers';
6
8
  import { createPluginState, getPluginState } from './plugin-factory';
@@ -38,7 +40,20 @@ export function createPlugin(dispatch, {
38
40
  const {
39
41
  dragging
40
42
  } = getPluginState(state);
41
- if (resizeHandlePos !== null && !dragging) {
43
+ let isColumnKeyboardResizeStarted = false;
44
+ if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
45
+ /*
46
+ We need to start listening mouse events if column resize started from keyboard.
47
+ This will allow continue resizing via mouse
48
+ */
49
+ const {
50
+ isKeyboardResize
51
+ } = getTablePluginState(state);
52
+ if (isKeyboardResize) {
53
+ isColumnKeyboardResizeStarted = isKeyboardResize;
54
+ }
55
+ }
56
+ if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
42
57
  if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI)) {
43
58
  const {
44
59
  state,
@@ -7,8 +7,8 @@ export function tableSelectionKeymapPlugin(editorSelectionAPI) {
7
7
  bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
8
8
  bindKeymapWithCommand(moveLeft.common, arrowLeftFromTable(editorSelectionAPI)(), list);
9
9
  if (getBooleanFF('platform.editor.a11y.table-selection_9uv33')) {
10
- bindKeymapArrayWithCommand(selectColumn, selectColumns(editorSelectionAPI)(), list);
11
- bindKeymapArrayWithCommand(selectRow, selectRows(editorSelectionAPI)(), list);
10
+ bindKeymapArrayWithCommand(selectColumn, selectColumns(editorSelectionAPI)(true), list);
11
+ bindKeymapArrayWithCommand(selectRow, selectRows(editorSelectionAPI)(true), list);
12
12
  }
13
13
  if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
14
14
  bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
@@ -75,8 +75,9 @@ export default ((pluginState, action) => {
75
75
  resizeHandleColumnIndex: undefined,
76
76
  resizeHandleRowIndex: undefined
77
77
  };
78
+ case 'START_KEYBOARD_COLUMN_RESIZE':
78
79
  case 'ADD_RESIZE_HANDLE_DECORATIONS':
79
- if (action.data.resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex && action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex && action.data.resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip) {
80
+ if (action.data.resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex && action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex && action.data.resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip && action.data.isKeyboardResize === pluginState.isKeyboardResize) {
80
81
  return pluginState;
81
82
  }
82
83
  return {
@@ -99,6 +100,7 @@ export default ((pluginState, action) => {
99
100
  resizeHandleRowIndex: resizeHandleRowIndex !== null && resizeHandleRowIndex !== void 0 ? resizeHandleRowIndex : pluginState.resizeHandleRowIndex,
100
101
  resizeHandleIncludeTooltip: resizeHandleIncludeTooltip !== null && resizeHandleIncludeTooltip !== void 0 ? resizeHandleIncludeTooltip : pluginState.resizeHandleIncludeTooltip
101
102
  };
103
+ case 'STOP_KEYBOARD_COLUMN_RESIZE':
102
104
  case 'REMOVE_RESIZE_HANDLE_DECORATIONS':
103
105
  if (!pluginState.isResizeHandleWidgetAdded) {
104
106
  return pluginState;
@@ -108,7 +110,8 @@ export default ((pluginState, action) => {
108
110
  ...action.data,
109
111
  resizeHandleColumnIndex: undefined,
110
112
  resizeHandleRowIndex: undefined,
111
- isResizeHandleWidgetAdded: false
113
+ isResizeHandleWidgetAdded: false,
114
+ isKeyboardResize: undefined
112
115
  };
113
116
  case 'SET_TABLE_REF':
114
117
  case 'HOVER_ROWS':
@@ -3,11 +3,9 @@ import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../
3
3
  export const HandleIconComponent = props => {
4
4
  const {
5
5
  forceDefaultHandle,
6
- isRowHandleHovered,
7
- isColumnHandleHovered,
6
+ isHandleHovered,
8
7
  hasMergedCells
9
8
  } = props;
10
- const isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
11
9
  if (isHandleHovered || forceDefaultHandle) {
12
10
  return hasMergedCells ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
13
11
  }
@@ -6,6 +6,7 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
6
  import { browser } from '@atlaskit/editor-common/utils';
7
7
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
8
8
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
9
+ import { getPluginState as getDnDPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
9
10
  import { getPluginState } from '../../pm-plugins/plugin-factory';
10
11
  import { TableCssClassName as ClassName } from '../../types';
11
12
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
@@ -23,7 +24,7 @@ const DragHandleComponent = ({
23
24
  previewHeight,
24
25
  onMouseOver,
25
26
  onMouseOut,
26
- onMouseUp,
27
+ toggleDragMenu,
27
28
  onClick,
28
29
  editorView,
29
30
  intl: {
@@ -32,13 +33,19 @@ const DragHandleComponent = ({
32
33
  }) => {
33
34
  const dragHandleDivRef = useRef(null);
34
35
  const [previewContainer, setPreviewContainer] = useState(null);
36
+ const {
37
+ state,
38
+ state: {
39
+ selection
40
+ }
41
+ } = editorView;
35
42
  const {
36
43
  hoveredColumns,
37
44
  hoveredRows
38
- } = getPluginState(editorView.state);
45
+ } = getPluginState(state);
39
46
  const {
40
- selection
41
- } = editorView.state;
47
+ isDragMenuOpen
48
+ } = getDnDPluginState(state);
42
49
  const isRow = direction === 'row';
43
50
  const isColumn = direction === 'column';
44
51
  const isRowHandleHovered = isRow && hoveredRows.length > 0;
@@ -46,8 +53,7 @@ const DragHandleComponent = ({
46
53
  const hasMergedCells = useMemo(() => isRow ? hasMergedCellsInRow(indexes[0])(selection) : hasMergedCellsInColumn(indexes[0])(selection), [indexes, isRow, selection]);
47
54
  const handleIconProps = {
48
55
  forceDefaultHandle,
49
- isColumnHandleHovered,
50
- isRowHandleHovered,
56
+ isHandleHovered: isColumnHandleHovered || isRowHandleHovered,
51
57
  hasMergedCells
52
58
  };
53
59
  useEffect(() => {
@@ -133,20 +139,29 @@ const DragHandleComponent = ({
133
139
  },
134
140
  "data-testid": "table-drag-handle-button",
135
141
  "aria-label": formatMessage(isRow ? messages.rowDragHandle : messages.columnDragHandle),
142
+ "aria-expanded": isDragMenuOpen && isDragMenuTarget ? 'true' : 'false',
143
+ "aria-haspopup": "menu",
136
144
  onMouseOver: onMouseOver,
137
145
  onMouseOut: onMouseOut,
138
146
  onMouseUp: e => {
139
147
  // return focus to editor so copying table selections whilst still works, i cannot call e.preventDefault in a mousemove event as this stops dragstart events from firing
140
148
  // -> this is bad for a11y but is the current standard new copy/paste keyboard shortcuts should be introduced instead
141
149
  editorView.focus();
142
- onMouseUp && onMouseUp(e);
150
+ toggleDragMenu && toggleDragMenu('mouse', e);
143
151
  },
144
- onClick: onClick
145
- }, browser.gecko ? /*#__PURE__*/React.createElement(HandleIconComponent, handleIconProps) : /*#__PURE__*/React.createElement("span", {
152
+ onClick: onClick,
153
+ onKeyDown: e => {
154
+ if (e.key === 'Enter' || e.key === ' ') {
155
+ toggleDragMenu && toggleDragMenu('keyboard');
156
+ }
157
+ }
158
+ }, appearance !== 'placeholder' ?
159
+ // cannot block pointer events in Firefox as it breaks Dragging functionality
160
+ browser.gecko ? /*#__PURE__*/React.createElement(HandleIconComponent, handleIconProps) : /*#__PURE__*/React.createElement("span", {
146
161
  style: {
147
162
  pointerEvents: 'none'
148
163
  }
149
- }, /*#__PURE__*/React.createElement(HandleIconComponent, handleIconProps))), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
164
+ }, /*#__PURE__*/React.createElement(HandleIconComponent, handleIconProps)) : null), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
150
165
  direction: direction,
151
166
  width: previewWidth,
152
167
  height: previewHeight