@atlaskit/editor-plugin-table 7.3.0 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/commands/misc.js +4 -2
  4. package/dist/cjs/commands/selection.js +4 -2
  5. package/dist/cjs/pm-plugins/drag-and-drop/commands.js +3 -1
  6. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +33 -1
  7. package/dist/cjs/pm-plugins/drag-and-drop/reducer.js +2 -1
  8. package/dist/cjs/pm-plugins/table-selection-keymap.js +2 -2
  9. package/dist/cjs/ui/DragHandle/HandleIconComponent.js +1 -3
  10. package/dist/cjs/ui/DragHandle/index.js +24 -10
  11. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +75 -33
  12. package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +123 -0
  13. package/dist/cjs/ui/FloatingDragMenu/index.js +2 -2
  14. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
  15. package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -2
  16. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
  17. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
  18. package/dist/cjs/ui/common-styles.js +1 -1
  19. package/dist/cjs/ui/consts.js +3 -2
  20. package/dist/es2019/commands/misc.js +4 -4
  21. package/dist/es2019/commands/selection.js +4 -4
  22. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +3 -3
  23. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +34 -1
  24. package/dist/es2019/pm-plugins/drag-and-drop/reducer.js +2 -1
  25. package/dist/es2019/pm-plugins/table-selection-keymap.js +2 -2
  26. package/dist/es2019/ui/DragHandle/HandleIconComponent.js +1 -3
  27. package/dist/es2019/ui/DragHandle/index.js +27 -10
  28. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +72 -32
  29. package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +109 -0
  30. package/dist/es2019/ui/FloatingDragMenu/index.js +2 -2
  31. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
  32. package/dist/es2019/ui/TableFloatingColumnControls/index.js +1 -2
  33. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
  34. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
  35. package/dist/es2019/ui/common-styles.js +11 -1
  36. package/dist/es2019/ui/consts.js +2 -1
  37. package/dist/esm/commands/misc.js +4 -2
  38. package/dist/esm/commands/selection.js +4 -2
  39. package/dist/esm/pm-plugins/drag-and-drop/commands.js +3 -2
  40. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +33 -1
  41. package/dist/esm/pm-plugins/drag-and-drop/reducer.js +2 -1
  42. package/dist/esm/pm-plugins/table-selection-keymap.js +2 -2
  43. package/dist/esm/ui/DragHandle/HandleIconComponent.js +1 -3
  44. package/dist/esm/ui/DragHandle/index.js +23 -9
  45. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +74 -35
  46. package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +116 -0
  47. package/dist/esm/ui/FloatingDragMenu/index.js +2 -2
  48. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
  49. package/dist/esm/ui/TableFloatingColumnControls/index.js +1 -2
  50. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
  51. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
  52. package/dist/esm/ui/common-styles.js +1 -1
  53. package/dist/esm/ui/consts.js +2 -1
  54. package/dist/types/commands/misc.d.ts +2 -2
  55. package/dist/types/commands/selection.d.ts +2 -2
  56. package/dist/types/pm-plugins/drag-and-drop/actions.d.ts +1 -0
  57. package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  58. package/dist/types/pm-plugins/drag-and-drop/types.d.ts +2 -0
  59. package/dist/types/ui/DragHandle/HandleIconComponent.d.ts +1 -2
  60. package/dist/types/ui/DragHandle/index.d.ts +3 -2
  61. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -8
  62. package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +30 -0
  63. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
  64. package/dist/types/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -1
  65. package/dist/types/ui/consts.d.ts +1 -0
  66. package/dist/types-ts4.5/commands/misc.d.ts +2 -2
  67. package/dist/types-ts4.5/commands/selection.d.ts +2 -2
  68. package/dist/types-ts4.5/pm-plugins/drag-and-drop/actions.d.ts +1 -0
  69. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  70. package/dist/types-ts4.5/pm-plugins/drag-and-drop/types.d.ts +2 -0
  71. package/dist/types-ts4.5/ui/DragHandle/HandleIconComponent.d.ts +1 -2
  72. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +3 -2
  73. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -8
  74. package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +30 -0
  75. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
  76. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -1
  77. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  78. package/package.json +3 -2
  79. package/src/commands/misc.ts +17 -4
  80. package/src/commands/selection.ts +12 -4
  81. package/src/pm-plugins/drag-and-drop/actions.ts +1 -0
  82. package/src/pm-plugins/drag-and-drop/commands.ts +3 -0
  83. package/src/pm-plugins/drag-and-drop/plugin.ts +47 -0
  84. package/src/pm-plugins/drag-and-drop/reducer.ts +1 -0
  85. package/src/pm-plugins/drag-and-drop/types.ts +3 -0
  86. package/src/pm-plugins/table-selection-keymap.ts +2 -2
  87. package/src/ui/DragHandle/HandleIconComponent.tsx +2 -9
  88. package/src/ui/DragHandle/index.tsx +39 -16
  89. package/src/ui/FloatingDragMenu/DragMenu.tsx +362 -310
  90. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +150 -0
  91. package/src/ui/FloatingDragMenu/index.tsx +3 -3
  92. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +72 -91
  93. package/src/ui/TableFloatingColumnControls/index.tsx +1 -2
  94. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +5 -0
  95. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +89 -104
  96. package/src/ui/common-styles.ts +11 -1
  97. package/src/ui/consts.ts +1 -0
  98. package/tsconfig.app.json +3 -0
@@ -2,14 +2,16 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
4
4
  /** @jsx jsx */
5
- import { useState } from 'react';
5
+ /** @jsxFrag */
6
+ import React, { useEffect, useState } from 'react';
6
7
  import { jsx } from '@emotion/react';
7
8
  import { injectIntl } from 'react-intl-next';
8
9
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
9
10
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
10
11
  import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
11
- import { backgroundPaletteTooltipMessages, cellBackgroundColorPalette, ColorPalette } from '@atlaskit/editor-common/ui-color';
12
- import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
12
+ import { withOuterListeners } from '@atlaskit/editor-common/ui';
13
+ import { backgroundPaletteTooltipMessages, cellBackgroundColorPalette, ColorPalette, getSelectedRowAndColumnFromPalette } from '@atlaskit/editor-common/ui-color';
14
+ import { ArrowKeyNavigationProvider, ArrowKeyNavigationType } from '@atlaskit/editor-common/ui-menu';
13
15
  import { closestElement } from '@atlaskit/editor-common/utils';
14
16
  import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
15
17
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
@@ -26,7 +28,8 @@ import { getPluginState as getTablePluginState } from '../../pm-plugins/plugin-f
26
28
  import { TableCssClassName as ClassName } from '../../types';
27
29
  import { checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
28
30
  import { getDragMenuConfig } from '../../utils/drag-menu';
29
- import { dragMenuDropdownWidth } from '../consts';
31
+ import { colorPalletteColumns } from '../consts';
32
+ import { DropdownMenu } from './DropdownMenu';
30
33
  import { cellColourPreviewStyles, dragMenuBackgroundColorStyles, elementBeforeIconStyles, toggleStyles } from './styles';
31
34
  var MapDragMenuOptionIdToMessage = {
32
35
  add_row_above: {
@@ -157,17 +160,16 @@ var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig, for
157
160
  menuCallback: menuCallback
158
161
  };
159
162
  };
160
- export var DragMenu = function DragMenu(_ref) {
163
+ var ColorPaletteWithListeners = withOuterListeners(ColorPalette);
164
+ export var DragMenu = /*#__PURE__*/React.memo(function (_ref) {
161
165
  var _pluginConfig$allowBa;
162
166
  var _ref$direction = _ref.direction,
163
167
  direction = _ref$direction === void 0 ? 'row' : _ref$direction,
164
168
  index = _ref.index,
169
+ target = _ref.target,
165
170
  isOpen = _ref.isOpen,
166
171
  editorView = _ref.editorView,
167
172
  tableNode = _ref.tableNode,
168
- mountPoint = _ref.mountPoint,
169
- boundariesElement = _ref.boundariesElement,
170
- scrollableElement = _ref.scrollableElement,
171
173
  targetCellPosition = _ref.targetCellPosition,
172
174
  getEditorContainerWidth = _ref.getEditorContainerWidth,
173
175
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
@@ -181,6 +183,8 @@ export var DragMenu = function DragMenu(_ref) {
181
183
  _useState2 = _slicedToArray(_useState, 2),
182
184
  isSubmenuOpen = _useState2[0],
183
185
  setIsSubmenuOpen = _useState2[1];
186
+ var _getPluginState = getPluginState(state),
187
+ isKeyboardModeActive = _getPluginState.isKeyboardModeActive;
184
188
  var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
185
189
  var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
186
190
  var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
@@ -216,7 +220,11 @@ export var DragMenu = function DragMenu(_ref) {
216
220
  targetCellPosition = _getTablePluginState2.targetCellPosition;
217
221
  var node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
218
222
  var background = hexToEditorBackgroundPaletteColor((node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
223
+ var _getSelectedRowAndCol = getSelectedRowAndColumnFromPalette(cellBackgroundColorPalette, background, colorPalletteColumns),
224
+ selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
225
+ selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
219
226
  return {
227
+ key: 'background',
220
228
  content: formatMessage(messages.backgroundColor),
221
229
  value: {
222
230
  name: 'background'
@@ -236,16 +244,33 @@ export var DragMenu = function DragMenu(_ref) {
236
244
  }), isSubmenuOpen && jsx("div", {
237
245
  className: ClassName.DRAG_SUBMENU,
238
246
  ref: handleSubMenuRef
239
- }, jsx(ColorPalette, {
240
- cols: 7,
241
- onClick: setColor,
247
+ }, jsx(ArrowKeyNavigationProvider, {
248
+ type: ArrowKeyNavigationType.COLOR,
249
+ selectedRowIndex: selectedRowIndex,
250
+ selectedColumnIndex: selectedColumnIndex,
251
+ handleClose: function handleClose() {
252
+ var keyboardEvent = new KeyboardEvent('keydown', {
253
+ key: 'ArrowDown',
254
+ bubbles: true
255
+ });
256
+ setIsSubmenuOpen(false);
257
+ target === null || target === void 0 || target.focus();
258
+ target === null || target === void 0 || target.dispatchEvent(keyboardEvent);
259
+ },
260
+ isPopupPositioned: true,
261
+ isOpenedByKeyboard: isKeyboardModeActive
262
+ }, jsx(ColorPaletteWithListeners, {
263
+ cols: colorPalletteColumns,
264
+ onClick: function onClick(color) {
265
+ setColor(color);
266
+ },
242
267
  selectedColor: background,
243
268
  paletteOptions: {
244
269
  palette: cellBackgroundColorPalette,
245
270
  paletteColorTooltipMessages: backgroundPaletteTooltipMessages,
246
271
  hexToPaletteColor: hexToEditorBackgroundPaletteColor
247
272
  }
248
- })))
273
+ }))))
249
274
  };
250
275
  };
251
276
  var toggleHeaderColumn = function toggleHeaderColumn() {
@@ -257,8 +282,9 @@ export var DragMenu = function DragMenu(_ref) {
257
282
  var toggleRowNumbers = function toggleRowNumbers() {
258
283
  toggleNumberColumnWithAnalytics(editorAnalyticsAPI)(state, dispatch);
259
284
  };
260
- var createhHeaderRowColumnMenuItem = function createhHeaderRowColumnMenuItem(direction) {
285
+ var createHeaderRowColumnMenuItem = function createHeaderRowColumnMenuItem(direction) {
261
286
  return direction === 'column' ? {
287
+ key: 'header_column',
262
288
  content: formatMessage(messages.headerColumn),
263
289
  value: {
264
290
  name: 'header_column'
@@ -271,6 +297,7 @@ export var DragMenu = function DragMenu(_ref) {
271
297
  isChecked: checkIfHeaderColumnEnabled(selection)
272
298
  }))
273
299
  } : {
300
+ key: 'header_row',
274
301
  content: formatMessage(messages.headerRow),
275
302
  value: {
276
303
  name: 'header_row'
@@ -286,6 +313,7 @@ export var DragMenu = function DragMenu(_ref) {
286
313
  };
287
314
  var createRowNumbersMenuItem = function createRowNumbersMenuItem() {
288
315
  return {
316
+ key: 'row_numbers',
289
317
  content: formatMessage(messages.rowNumbers),
290
318
  value: {
291
319
  name: 'row_numbers'
@@ -307,10 +335,10 @@ export var DragMenu = function DragMenu(_ref) {
307
335
  * @returns true when the menu should be closed, false otherwise
308
336
  */
309
337
  var shouldCloseMenu = function shouldCloseMenu(state) {
310
- var _getPluginState = getPluginState(state),
311
- previousOpenState = _getPluginState.isDragMenuOpen,
312
- previousDragMenuDirection = _getPluginState.dragMenuDirection,
313
- previousDragMenuIndex = _getPluginState.dragMenuIndex;
338
+ var _getPluginState2 = getPluginState(state),
339
+ previousOpenState = _getPluginState2.isDragMenuOpen,
340
+ previousDragMenuDirection = _getPluginState2.dragMenuDirection,
341
+ previousDragMenuIndex = _getPluginState2.dragMenuIndex;
314
342
 
315
343
  // menu open but menu direction changed, means user clicked on drag handle of different row/column
316
344
  // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
@@ -322,9 +350,15 @@ export var DragMenu = function DragMenu(_ref) {
322
350
  }
323
351
  };
324
352
  var closeMenu = function closeMenu() {
353
+ var focusTarget = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'handle';
325
354
  var state = editorView.state,
326
355
  dispatch = editorView.dispatch;
327
356
  if (shouldCloseMenu(state)) {
357
+ if (target && focusTarget === 'handle') {
358
+ target === null || target === void 0 || target.focus();
359
+ } else {
360
+ editorView.dom.focus();
361
+ }
328
362
  toggleDragMenu(false, direction, index)(state, dispatch);
329
363
  }
330
364
  };
@@ -333,6 +367,9 @@ export var DragMenu = function DragMenu(_ref) {
333
367
  var item = _ref2.item;
334
368
  (_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 || _menuCallback$item$va.call(menuCallback, state, dispatch);
335
369
  switch (item.value.name) {
370
+ case 'background':
371
+ setIsSubmenuOpen(!isSubmenuOpen);
372
+ break;
336
373
  case 'header_column':
337
374
  toggleHeaderColumn();
338
375
  break;
@@ -346,7 +383,7 @@ export var DragMenu = function DragMenu(_ref) {
346
383
  break;
347
384
  }
348
385
  if (['header_column', 'header_row', 'row_numbers', 'background'].indexOf(item.value.name) <= -1) {
349
- closeMenu();
386
+ closeMenu('editor');
350
387
  }
351
388
  };
352
389
  var handleItemMouseEnter = function handleItemMouseEnter(_ref3) {
@@ -372,6 +409,17 @@ export var DragMenu = function DragMenu(_ref) {
372
409
  clearHoverSelection()(state, dispatch);
373
410
  }
374
411
  };
412
+ useEffect(function () {
413
+ // focus on first menu item automatically when menu renders
414
+ // and user is using keyboard
415
+ if (isOpen && target && isKeyboardModeActive) {
416
+ var keyboardEvent = new KeyboardEvent('keydown', {
417
+ key: 'ArrowDown',
418
+ bubbles: true
419
+ });
420
+ target.dispatchEvent(keyboardEvent);
421
+ }
422
+ }, [isOpen, target, isKeyboardModeActive]);
375
423
  if (!menuItems) {
376
424
  return null;
377
425
  }
@@ -379,11 +427,11 @@ export var DragMenu = function DragMenu(_ref) {
379
427
  menuItems[0].items.unshift(createBackgroundColorMenuItem());
380
428
  }
381
429
 
382
- // If first row, add toggle for Hearder row, default is true
430
+ // If first row, add toggle for Header row, default is true
383
431
  // If first column, add toggle for Header column, default is false
384
432
  if (getBooleanFF('platform.editor.table.new-cell-context-menu-styling') && index === 0) {
385
433
  menuItems.push({
386
- items: [createhHeaderRowColumnMenuItem(direction)]
434
+ items: [createHeaderRowColumnMenuItem(direction)]
387
435
  });
388
436
  }
389
437
 
@@ -394,25 +442,16 @@ export var DragMenu = function DragMenu(_ref) {
394
442
  });
395
443
  }
396
444
  return jsx(DropdownMenu, {
397
- mountTo: mountPoint
398
- //This needs be removed when the a11y is completely handled
399
- //Disabling key navigation now as it works only partially
400
- ,
401
- arrowKeyNavigationProviderOptions: {
402
- type: ArrowKeyNavigationType.MENU,
403
- disableArrowKeyNavigation: true
445
+ disableKeyboardHandling: isSubmenuOpen,
446
+ section: {
447
+ hasSeparator: true
404
448
  },
449
+ target: target,
405
450
  items: menuItems,
406
- isOpen: isOpen,
407
- onOpenChange: closeMenu,
408
451
  onItemActivated: handleMenuItemActivated,
409
452
  onMouseEnter: handleItemMouseEnter,
410
453
  onMouseLeave: handleItemMouseLeave,
411
- fitWidth: dragMenuDropdownWidth,
412
- boundariesElement: boundariesElement,
413
- section: {
414
- hasSeparator: true
415
- }
454
+ handleClose: closeMenu
416
455
  });
417
- };
456
+ });
418
457
  export default injectIntl(DragMenu);
@@ -0,0 +1,116 @@
1
+ import React from 'react';
2
+ import { DropList } from '@atlaskit/editor-common/ui';
3
+ import { ArrowKeyNavigationProvider, ArrowKeyNavigationType, DropdownMenuItem } from '@atlaskit/editor-common/ui-menu';
4
+ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
5
+ import { MenuGroup, Section } from '@atlaskit/menu';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ import { dragMenuDropdownWidth } from '../consts';
8
+ var DropListWithOutsideListeners = withReactEditorViewOuterListeners(DropList);
9
+ export var DropdownMenu = function DropdownMenu(_ref) {
10
+ var target = _ref.target,
11
+ items = _ref.items,
12
+ section = _ref.section,
13
+ disableKeyboardHandling = _ref.disableKeyboardHandling,
14
+ onItemActivated = _ref.onItemActivated,
15
+ handleClose = _ref.handleClose,
16
+ onMouseEnter = _ref.onMouseEnter,
17
+ onMouseLeave = _ref.onMouseLeave;
18
+ var innerMenu = function innerMenu() {
19
+ return /*#__PURE__*/React.createElement(DropListWithOutsideListeners, {
20
+ isOpen: true,
21
+ shouldFitContainer: true,
22
+ position: ['bottom', 'left'].join(' '),
23
+ handleClickOutside: function handleClickOutside() {
24
+ return handleClose('editor');
25
+ },
26
+ handleEscapeKeydown: function handleEscapeKeydown() {
27
+ if (!disableKeyboardHandling) {
28
+ handleClose('handle');
29
+ }
30
+ },
31
+ handleEnterKeydown: function handleEnterKeydown(e) {
32
+ if (!disableKeyboardHandling) {
33
+ e.preventDefault();
34
+ e.stopPropagation();
35
+ }
36
+ },
37
+ targetRef: target
38
+ }, /*#__PURE__*/React.createElement("div", {
39
+ style: {
40
+ height: 0,
41
+ minWidth: dragMenuDropdownWidth
42
+ }
43
+ }), /*#__PURE__*/React.createElement(MenuGroup, {
44
+ role: "menu"
45
+ }, items.map(function (group, index) {
46
+ return /*#__PURE__*/React.createElement(Section, {
47
+ hasSeparator: (section === null || section === void 0 ? void 0 : section.hasSeparator) && index > 0,
48
+ title: section === null || section === void 0 ? void 0 : section.title,
49
+ key: index
50
+ }, group.items.map(function (item) {
51
+ var _item$key;
52
+ return /*#__PURE__*/React.createElement(DropdownMenuItem, {
53
+ shouldUseDefaultRole: false,
54
+ key: (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : String(item.content),
55
+ item: item,
56
+ onItemActivated: onItemActivated,
57
+ onMouseEnter: onMouseEnter,
58
+ onMouseLeave: onMouseLeave
59
+ });
60
+ }));
61
+ })));
62
+ };
63
+ if (disableKeyboardHandling) {
64
+ return innerMenu();
65
+ }
66
+ return /*#__PURE__*/React.createElement(ArrowKeyNavigationProvider, {
67
+ closeOnTab: true,
68
+ type: ArrowKeyNavigationType.MENU,
69
+ onSelection: function onSelection(index) {
70
+ var results = items.flatMap(function (item) {
71
+ return 'items' in item ? item.items : item;
72
+ });
73
+
74
+ // onSelection is called when any focusable element is 'activated'
75
+ // this is an issue as some menu items have toggles, which cause the index value
76
+ // in the callback to be outside of array length.
77
+ // The logic below normalises the index value based on the number
78
+ // of menu items with 2 focusable elements, and adjusts the index to ensure
79
+ // the correct menu item is sent in onItemActivated callback
80
+ if (getBooleanFF('platform.editor.table.new-cell-context-menu-styling')) {
81
+ var keys = ['row_numbers', 'header_row', 'header_column'];
82
+ var doubleItemCount = 0;
83
+ var firstIndex = results.findIndex(function (value) {
84
+ return keys.includes(value.key);
85
+ });
86
+ if (firstIndex === -1 || index <= firstIndex) {
87
+ onItemActivated && onItemActivated({
88
+ item: results[index]
89
+ });
90
+ return;
91
+ }
92
+ for (var i = firstIndex; i < results.length; i += 1) {
93
+ if (keys.includes(results[i].key)) {
94
+ doubleItemCount += 1;
95
+ }
96
+ if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
97
+ onItemActivated && onItemActivated({
98
+ item: results[i]
99
+ });
100
+ return;
101
+ }
102
+ if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
103
+ onItemActivated && onItemActivated({
104
+ item: results[i]
105
+ });
106
+ return;
107
+ }
108
+ }
109
+ } else {
110
+ onItemActivated && onItemActivated({
111
+ item: results[index]
112
+ });
113
+ }
114
+ }
115
+ }, innerMenu());
116
+ };
@@ -23,10 +23,10 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
23
23
  }
24
24
  var inStickyMode = stickyHeaders === null || stickyHeaders === void 0 ? void 0 : stickyHeaders.sticky;
25
25
  var targetHandleRef = direction === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
26
+ var offset = direction === 'row' ? [-9, 6] : [0, -7];
26
27
  if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
27
28
  return null;
28
29
  }
29
- var offset = direction === 'row' ? [-9, 6] : [0, -7];
30
30
 
31
31
  // TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
32
32
  return /*#__PURE__*/React.createElement(Popup, {
@@ -48,10 +48,10 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
48
48
  }, /*#__PURE__*/React.createElement(DragMenu, {
49
49
  editorView: editorView,
50
50
  isOpen: isOpen,
51
- boundariesElement: boundariesElement,
52
51
  tableNode: tableNode,
53
52
  direction: direction,
54
53
  index: index,
54
+ target: targetHandleRef || undefined,
55
55
  targetCellPosition: targetCellPosition,
56
56
  getEditorContainerWidth: getEditorContainerWidth,
57
57
  editorAnalyticsAPI: editorAnalyticsAPI,
@@ -26,7 +26,6 @@ export var ColumnControls = function ColumnControls(_ref) {
26
26
  tableActive = _ref.tableActive,
27
27
  tableRef = _ref.tableRef,
28
28
  hoveredCell = _ref.hoveredCell,
29
- isResizing = _ref.isResizing,
30
29
  stickyTop = _ref.stickyTop,
31
30
  localId = _ref.localId,
32
31
  isInDanger = _ref.isInDanger,
@@ -96,13 +95,13 @@ export var ColumnControls = function ColumnControls(_ref) {
96
95
  clearHoverSelection()(state, dispatch);
97
96
  }
98
97
  }, [editorView, tableActive]);
99
- var handleMouseUp = useCallback(function (event) {
98
+ var toggleDragMenuHandler = useCallback(function (trigger, event) {
100
99
  var state = editorView.state,
101
100
  dispatch = editorView.dispatch;
102
- if (event.shiftKey) {
101
+ if (event !== null && event !== void 0 && event.shiftKey) {
103
102
  return;
104
103
  }
105
- toggleDragMenu(undefined, 'column', colIndex)(state, dispatch);
104
+ toggleDragMenu(undefined, 'column', colIndex, trigger)(state, dispatch);
106
105
  }, [editorView, colIndex]);
107
106
  var colIndexes = useMemo(function () {
108
107
  return [colIndex];
@@ -111,35 +110,20 @@ export var ColumnControls = function ColumnControls(_ref) {
111
110
  var _getScrollOffset;
112
111
  columnControlsRef.current.scrollLeft = (_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0;
113
112
  }
114
- var generateHandleByType = function generateHandleByType(type) {
113
+ var generateHandleByType = function generateHandleByType(type, appearance, gridColumn, indexes) {
115
114
  var _rowHeights$reduce, _colWidths$reduce;
116
- if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
117
- return null;
118
- }
119
115
  var isHover = type === 'hover';
120
- var isColumnsSelected = selectedColIndexes.length > 0;
121
116
  var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
122
117
  return sum + cur;
123
118
  }, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
124
- var showCondition = isHover ? isColumnsSelected && !selectedColIndexes.includes(colIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedColIndexes.length < (colWidths === null || colWidths === void 0 ? void 0 : colWidths.length) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
125
- if (!showCondition) {
126
- return null;
127
- }
128
- var gridColumnPosition = "".concat(colIndex + 1, " / span 1");
129
- var selectedColumnPosition = "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
130
- var hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
131
- var currentSelectionAppearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
132
- var isSelecting = isColumnsSelected && !isHover;
133
-
134
- // this indexes are used to calculate the drag and drop source
135
- var indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
136
119
  var previewWidth = (_colWidths$reduce = colWidths === null || colWidths === void 0 ? void 0 : colWidths.reduce(function (sum, v, i) {
137
120
  return sum + (v !== null && v !== void 0 ? v : tableCellMinWidth) * (indexes.includes(i) ? 1 : 0);
138
121
  }, 0)) !== null && _colWidths$reduce !== void 0 ? _colWidths$reduce : tableCellMinWidth;
139
122
  return /*#__PURE__*/React.createElement("div", {
140
123
  key: type,
141
124
  style: {
142
- gridColumn: isSelecting ? selectedColumnPosition : gridColumnPosition,
125
+ gridColumn: gridColumn,
126
+ gridRow: '1',
143
127
  display: 'flex',
144
128
  justifyContent: 'center',
145
129
  alignItems: 'center',
@@ -149,33 +133,38 @@ export var ColumnControls = function ColumnControls(_ref) {
149
133
  width: '100%',
150
134
  position: 'relative'
151
135
  },
152
- "data-column-control-index": hoveredCell.colIndex,
153
- "data-testid": "table-floating-column-".concat(isSelecting ? selectedColIndexes[0] : colIndex, "-drag-handle")
136
+ "data-testid": "table-floating-column-".concat(isHover ? colIndex : selectedColIndexes[0], "-drag-handle")
154
137
  }, /*#__PURE__*/React.createElement(DragHandle, {
155
138
  isDragMenuTarget: !isHover,
156
139
  direction: "column",
157
140
  tableLocalId: localId || '',
158
141
  indexes: indexes,
159
- forceDefaultHandle: isHover ? false : isColumnsSelected,
160
142
  previewWidth: previewWidth,
143
+ forceDefaultHandle: !isHover,
161
144
  previewHeight: previewHeight,
162
- appearance: isSelecting ? currentSelectionAppearance : hoveredAppearance,
145
+ appearance: appearance,
163
146
  onClick: handleClick,
164
147
  onMouseOver: handleMouseOver,
165
148
  onMouseOut: handleMouseOut,
166
- onMouseUp: handleMouseUp,
149
+ toggleDragMenu: toggleDragMenuHandler,
167
150
  editorView: editorView
168
151
  }));
169
152
  };
170
- var columnHandles = function columnHandles(hoveredCell) {
171
- if (!hoveredCell) {
153
+ var columnHandles = function columnHandles() {
154
+ var handles = [];
155
+ var isColumnSelected = selectedColIndexes.length > 0;
156
+ var isEntireTableSelected = (colWidths || []).length > selectedColIndexes.length;
157
+ if (!tableActive) {
172
158
  return null;
173
159
  }
174
- if (hoveredCell.colIndex === undefined) {
175
- return generateHandleByType('selected');
160
+
161
+ // placeholder / selected need to always render at least one handle
162
+ // so it can be focused via keyboard shortcuts
163
+ handles.push(generateHandleByType('selected', isColumnSelected && isEntireTableSelected ? isInDanger ? 'danger' : 'selected' : 'placeholder', "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length), selectedColIndexes));
164
+ if (hoveredCell && isTableHovered && colIndex !== undefined && !selectedColIndexes.includes(colIndex)) {
165
+ handles.push(generateHandleByType('hover', 'default', "".concat(colIndex + 1, " / span 1"), colIndexes));
176
166
  }
177
- var sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
178
- return hoveredCell.colIndex < selectedColIndexes[0] ? sortedHandles : sortedHandles.reverse();
167
+ return handles;
179
168
  };
180
169
  var containerWidth = isNumberColumnEnabled && tableContainerWidth ? tableContainerWidth - akEditorTableNumberColumnWidth : tableContainerWidth;
181
170
  return /*#__PURE__*/React.createElement("div", {
@@ -192,7 +181,7 @@ export var ColumnControls = function ColumnControls(_ref) {
192
181
  overflowX: stickyTop ? 'hidden' : 'visible',
193
182
  pointerEvents: isDragging ? 'none' : undefined
194
183
  }
195
- }, !isResizing && columnParams.map(function (_ref2, index) {
184
+ }, columnParams.map(function (_ref2, index) {
196
185
  var startIndex = _ref2.startIndex,
197
186
  endIndex = _ref2.endIndex;
198
187
  return /*#__PURE__*/React.createElement("div", {
@@ -210,6 +199,6 @@ export var ColumnControls = function ColumnControls(_ref) {
210
199
  right: '0'
211
200
  } : {}
212
201
  }));
213
- }), tableActive && isTableHovered && !isResizing && columnHandles(hoveredCell)));
202
+ }), columnHandles()));
214
203
  };
215
204
  export default ColumnControls;
@@ -95,7 +95,7 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
95
95
  }
96
96
  return [0];
97
97
  }, [tableRef, tableRect.height]);
98
- if (!tableRef || !tableActive) {
98
+ if (!tableRef || !tableActive || isResizing) {
99
99
  return null;
100
100
  }
101
101
  var colWidths = getColumnsWidths(editorView);
@@ -116,7 +116,6 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
116
116
  editorView: editorView,
117
117
  hoveredCell: hoveredCell,
118
118
  tableRef: tableRef,
119
- isResizing: isResizing,
120
119
  tableActive: tableActive,
121
120
  isTableHovered: isTableHovered,
122
121
  stickyTop: tableActive ? stickyTop : undefined,
@@ -8,6 +8,7 @@ import { TableCssClassName as ClassName } from '../../../types';
8
8
  var DragCornerControlsComponent = function DragCornerControlsComponent(_ref) {
9
9
  var editorView = _ref.editorView,
10
10
  isInDanger = _ref.isInDanger,
11
+ isResizing = _ref.isResizing,
11
12
  formatMessage = _ref.intl.formatMessage;
12
13
  var handleOnClick = function handleOnClick() {
13
14
  var state = editorView.state,
@@ -27,6 +28,9 @@ var DragCornerControlsComponent = function DragCornerControlsComponent(_ref) {
27
28
  }
28
29
  return isTableSelected(selection);
29
30
  }, [editorView.state]);
31
+ if (isResizing) {
32
+ return null;
33
+ }
30
34
  return /*#__PURE__*/React.createElement("button", {
31
35
  className: classnames(ClassName.DRAG_CORNER_BUTTON, {
32
36
  active: isActive,