@atlaskit/editor-plugin-table 23.3.3 → 23.3.5

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 (111) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cjs/pm-plugins/commands/active-table-menu.js +19 -8
  3. package/dist/cjs/pm-plugins/commands/commands-with-analytics.js +9 -49
  4. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +1 -1
  5. package/dist/cjs/pm-plugins/handlers.js +1 -1
  6. package/dist/cjs/pm-plugins/main.js +4 -1
  7. package/dist/cjs/ui/ContentComponent.js +11 -1
  8. package/dist/cjs/ui/FloatingContextualButton/index.js +2 -2
  9. package/dist/cjs/ui/FloatingContextualMenu/CellMenuPopup.js +2 -2
  10. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +6 -2
  11. package/dist/cjs/ui/FloatingDragMenu/index.js +10 -38
  12. package/dist/cjs/ui/FloatingTableMenu/index.js +175 -0
  13. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +43 -11
  14. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +57 -26
  15. package/dist/cjs/ui/TableMenu/cell/items/MergeCellsItem.js +1 -1
  16. package/dist/cjs/ui/TableMenu/cell/items/SplitCellItem.js +1 -1
  17. package/dist/cjs/ui/TableMenu/cell/items/VerticalAlignDropdownItem.js +1 -1
  18. package/dist/cjs/ui/TableMenu/column/items/AddColumnLeftItem.js +1 -1
  19. package/dist/cjs/ui/TableMenu/column/items/AddColumnRightItem.js +1 -1
  20. package/dist/cjs/ui/TableMenu/column/items/DeleteColumnItem.js +1 -1
  21. package/dist/cjs/ui/TableMenu/column/items/DistributeColumnsItem.js +1 -1
  22. package/dist/cjs/ui/TableMenu/column/items/MoveColumnLeftItem.js +1 -1
  23. package/dist/cjs/ui/TableMenu/column/items/MoveColumnRightItem.js +1 -1
  24. package/dist/cjs/ui/TableMenu/column/items/SortDecreasingItem.js +1 -1
  25. package/dist/cjs/ui/TableMenu/column/items/SortIncreasingItem.js +1 -1
  26. package/dist/cjs/ui/TableMenu/row/items/AddRowAboveItem.js +1 -1
  27. package/dist/cjs/ui/TableMenu/row/items/AddRowBelowItem.js +1 -1
  28. package/dist/cjs/ui/TableMenu/row/items/DeleteRowItem.js +1 -1
  29. package/dist/cjs/ui/TableMenu/row/items/MoveRowDownItem.js +1 -1
  30. package/dist/cjs/ui/TableMenu/row/items/MoveRowUpItem.js +1 -1
  31. package/dist/cjs/ui/TableMenu/shared/TableMenu.js +8 -8
  32. package/dist/cjs/ui/TableMenu/shared/consts.js +1 -1
  33. package/dist/cjs/ui/TableMenu/shared/items/BackgroundColorItem.js +1 -1
  34. package/dist/cjs/ui/TableMenu/shared/items/ClearCellsItem.js +1 -1
  35. package/dist/es2019/pm-plugins/commands/active-table-menu.js +19 -8
  36. package/dist/es2019/pm-plugins/commands/commands-with-analytics.js +0 -39
  37. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +1 -1
  38. package/dist/es2019/pm-plugins/handlers.js +1 -1
  39. package/dist/es2019/pm-plugins/main.js +3 -0
  40. package/dist/es2019/ui/ContentComponent.js +11 -1
  41. package/dist/es2019/ui/FloatingContextualButton/index.js +2 -2
  42. package/dist/es2019/ui/FloatingContextualMenu/CellMenuPopup.js +2 -2
  43. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +6 -2
  44. package/dist/es2019/ui/FloatingDragMenu/index.js +11 -40
  45. package/dist/es2019/ui/FloatingTableMenu/index.js +165 -0
  46. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +41 -7
  47. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +40 -7
  48. package/dist/es2019/ui/TableMenu/cell/items/MergeCellsItem.js +1 -1
  49. package/dist/es2019/ui/TableMenu/cell/items/SplitCellItem.js +1 -1
  50. package/dist/es2019/ui/TableMenu/cell/items/VerticalAlignDropdownItem.js +1 -1
  51. package/dist/es2019/ui/TableMenu/column/items/AddColumnLeftItem.js +1 -1
  52. package/dist/es2019/ui/TableMenu/column/items/AddColumnRightItem.js +1 -1
  53. package/dist/es2019/ui/TableMenu/column/items/DeleteColumnItem.js +1 -1
  54. package/dist/es2019/ui/TableMenu/column/items/DistributeColumnsItem.js +1 -1
  55. package/dist/es2019/ui/TableMenu/column/items/MoveColumnLeftItem.js +1 -1
  56. package/dist/es2019/ui/TableMenu/column/items/MoveColumnRightItem.js +1 -1
  57. package/dist/es2019/ui/TableMenu/column/items/SortDecreasingItem.js +1 -1
  58. package/dist/es2019/ui/TableMenu/column/items/SortIncreasingItem.js +1 -1
  59. package/dist/es2019/ui/TableMenu/row/items/AddRowAboveItem.js +1 -1
  60. package/dist/es2019/ui/TableMenu/row/items/AddRowBelowItem.js +1 -1
  61. package/dist/es2019/ui/TableMenu/row/items/DeleteRowItem.js +1 -1
  62. package/dist/es2019/ui/TableMenu/row/items/MoveRowDownItem.js +1 -1
  63. package/dist/es2019/ui/TableMenu/row/items/MoveRowUpItem.js +1 -1
  64. package/dist/es2019/ui/TableMenu/shared/TableMenu.js +8 -8
  65. package/dist/es2019/ui/TableMenu/shared/consts.js +1 -1
  66. package/dist/es2019/ui/TableMenu/shared/items/BackgroundColorItem.js +1 -1
  67. package/dist/es2019/ui/TableMenu/shared/items/ClearCellsItem.js +1 -1
  68. package/dist/esm/pm-plugins/commands/active-table-menu.js +19 -8
  69. package/dist/esm/pm-plugins/commands/commands-with-analytics.js +8 -48
  70. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +1 -1
  71. package/dist/esm/pm-plugins/handlers.js +1 -1
  72. package/dist/esm/pm-plugins/main.js +4 -1
  73. package/dist/esm/ui/ContentComponent.js +11 -1
  74. package/dist/esm/ui/FloatingContextualButton/index.js +2 -2
  75. package/dist/esm/ui/FloatingContextualMenu/CellMenuPopup.js +2 -2
  76. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +8 -2
  77. package/dist/esm/ui/FloatingDragMenu/index.js +11 -39
  78. package/dist/esm/ui/FloatingTableMenu/index.js +167 -0
  79. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +42 -10
  80. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +56 -25
  81. package/dist/esm/ui/TableMenu/cell/items/MergeCellsItem.js +1 -1
  82. package/dist/esm/ui/TableMenu/cell/items/SplitCellItem.js +1 -1
  83. package/dist/esm/ui/TableMenu/cell/items/VerticalAlignDropdownItem.js +1 -1
  84. package/dist/esm/ui/TableMenu/column/items/AddColumnLeftItem.js +1 -1
  85. package/dist/esm/ui/TableMenu/column/items/AddColumnRightItem.js +1 -1
  86. package/dist/esm/ui/TableMenu/column/items/DeleteColumnItem.js +1 -1
  87. package/dist/esm/ui/TableMenu/column/items/DistributeColumnsItem.js +1 -1
  88. package/dist/esm/ui/TableMenu/column/items/MoveColumnLeftItem.js +1 -1
  89. package/dist/esm/ui/TableMenu/column/items/MoveColumnRightItem.js +1 -1
  90. package/dist/esm/ui/TableMenu/column/items/SortDecreasingItem.js +1 -1
  91. package/dist/esm/ui/TableMenu/column/items/SortIncreasingItem.js +1 -1
  92. package/dist/esm/ui/TableMenu/row/items/AddRowAboveItem.js +1 -1
  93. package/dist/esm/ui/TableMenu/row/items/AddRowBelowItem.js +1 -1
  94. package/dist/esm/ui/TableMenu/row/items/DeleteRowItem.js +1 -1
  95. package/dist/esm/ui/TableMenu/row/items/MoveRowDownItem.js +1 -1
  96. package/dist/esm/ui/TableMenu/row/items/MoveRowUpItem.js +1 -1
  97. package/dist/esm/ui/TableMenu/shared/TableMenu.js +8 -8
  98. package/dist/esm/ui/TableMenu/shared/consts.js +1 -1
  99. package/dist/esm/ui/TableMenu/shared/items/BackgroundColorItem.js +1 -1
  100. package/dist/esm/ui/TableMenu/shared/items/ClearCellsItem.js +1 -1
  101. package/dist/types/pm-plugins/commands/active-table-menu.d.ts +3 -3
  102. package/dist/types/pm-plugins/commands/commands-with-analytics.d.ts +1 -3
  103. package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -4
  104. package/dist/types/ui/FloatingTableMenu/index.d.ts +23 -0
  105. package/dist/types/ui/TableMenu/shared/consts.d.ts +1 -1
  106. package/dist/types-ts4.5/pm-plugins/commands/active-table-menu.d.ts +3 -3
  107. package/dist/types-ts4.5/pm-plugins/commands/commands-with-analytics.d.ts +1 -3
  108. package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -4
  109. package/dist/types-ts4.5/ui/FloatingTableMenu/index.d.ts +23 -0
  110. package/dist/types-ts4.5/ui/TableMenu/shared/consts.d.ts +1 -1
  111. package/package.json +3 -3
@@ -0,0 +1,167 @@
1
+ import React, { useCallback, useContext, useMemo, useRef } from 'react';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
+ import { Popup } from '@atlaskit/editor-common/ui';
4
+ import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
5
+ import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
6
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
7
+ import { ToolbarKeyboardNavigationProvider } from '@atlaskit/editor-toolbar/toolbar-keyboard-navigation-provider';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
9
+ import { closeActiveTableMenu } from '../../pm-plugins/commands';
10
+ import { TableCssClassName as ClassName } from '../../types';
11
+ import { dragTableInsertColumnButtonSize, tablePopupMenuFitHeight } from '../consts';
12
+ import { COLUMN_MENU } from '../TableMenu/column/keys';
13
+ import { ROW_MENU } from '../TableMenu/row/keys';
14
+ import { TABLE_MENU_WIDTH } from '../TableMenu/shared/consts';
15
+ import { TableMenu } from '../TableMenu/shared/TableMenu';
16
+ var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
17
+
18
+ // Defer drag-handle clicks to the drag handle's own toggle/select handlers — those own
19
+ // the open/switch/close semantics for moving between rows/columns.
20
+ var DRAG_HANDLE_CONTROLS_SELECTOR = ".".concat(ClassName.DRAG_ROW_CONTROLS, ", .").concat(ClassName.DRAG_COLUMN_CONTROLS);
21
+ var NESTED_DROPDOWN_SELECTOR = '[data-toolbar-nested-dropdown-menu]';
22
+
23
+ // Marks the menu subtree that ToolbarKeyboardNavigationProvider scopes its
24
+ // keyboard handling to. The provider only reacts to events whose target sits
25
+ // inside this selector.
26
+ var TABLE_MENU_NAV_SELECTOR = '[data-table-drag-menu-nav="true"]';
27
+ var TABLE_MENU_OFFSET = dragTableInsertColumnButtonSize + 4;
28
+ var POPUP_OFFSET = [TABLE_MENU_OFFSET, 0];
29
+
30
+ /**
31
+ * Row and column menu for table.
32
+ */
33
+ var FloatingTableMenu = function FloatingTableMenu(_ref) {
34
+ var api = _ref.api,
35
+ boundariesElement = _ref.boundariesElement,
36
+ editorView = _ref.editorView,
37
+ mountPoint = _ref.mountPoint,
38
+ scrollableElement = _ref.scrollableElement,
39
+ stickyHeaders = _ref.stickyHeaders,
40
+ tableWrapper = _ref.tableWrapper,
41
+ targetCellPosition = _ref.targetCellPosition;
42
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['table'], function (states) {
43
+ var _states$tableState;
44
+ return {
45
+ activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
46
+ };
47
+ }),
48
+ activeTableMenu = _useSharedPluginState.activeTableMenu;
49
+ var isDragMenuOpen = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
50
+ var dragMenuDirection = isDragMenuOpen ? activeTableMenu.type : undefined;
51
+ var isOpenedByKeyboard = isDragMenuOpen && activeTableMenu.openedBy === 'keyboard';
52
+ var popupContentRef = useRef(null);
53
+ var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
54
+ var navWrapperRef = useRef(null);
55
+ var handlePopupRef = useCallback(function (el) {
56
+ popupContentRef.current = el;
57
+ setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 || setOutsideClickTargetRef(el);
58
+ }, [setOutsideClickTargetRef]);
59
+ var dismiss = useCallback(function () {
60
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
61
+ }, [api]);
62
+ var returnFocusToDragHandle = useCallback(function () {
63
+ // Match legacy DragMenu's closeMenu('handle') behaviour.
64
+ var handleId = dragMenuDirection === 'row' ? '#drag-handle-button-row' : '#drag-handle-button-column';
65
+ var handle = document.querySelector(handleId);
66
+ handle === null || handle === void 0 || handle.focus();
67
+ }, [dragMenuDirection]);
68
+ var focusFirstMenuItem = useCallback(function () {
69
+ var root = navWrapperRef.current;
70
+ if (!root) {
71
+ return;
72
+ }
73
+ var firstItem = root.querySelector('[role="menuitem"]:not([disabled]), [role="menuitemcheckbox"]:not([disabled]), [role="menuitemradio"]:not([disabled]), button:not([disabled])');
74
+ firstItem === null || firstItem === void 0 || firstItem.focus();
75
+ }, []);
76
+
77
+ // Focus the first menu item when the menu opens via keyboard (Enter/Space on
78
+ // the drag handle). Mouse-opened menus leave focus where the user clicked.
79
+ var setNavWrapperRef = useCallback(function (el) {
80
+ navWrapperRef.current = el;
81
+ if (el && isOpenedByKeyboard) {
82
+ // rAF allows the popup to finish positioning before focusing.
83
+ requestAnimationFrame(function () {
84
+ focusFirstMenuItem();
85
+ });
86
+ }
87
+ }, [focusFirstMenuItem, isOpenedByKeyboard]);
88
+ var handleKeyboardFocus = useCallback(function (_event) {
89
+ focusFirstMenuItem();
90
+ }, [focusFirstMenuItem]);
91
+ var handleEscape = useCallback(function (event) {
92
+ event.preventDefault();
93
+ event.stopPropagation();
94
+ dismiss();
95
+ returnFocusToDragHandle();
96
+ }, [dismiss, returnFocusToDragHandle]);
97
+
98
+ // Memoize the editor DOM reference so the provider doesn't re-bind listeners
99
+ // on every render (the provider depends on `dom` in its effect's deps).
100
+ var editorDom = useMemo(function () {
101
+ return editorView.dom instanceof HTMLElement ? editorView.dom : undefined;
102
+ }, [editorView.dom]);
103
+
104
+ // The drag menu is opened by interacting with the drag handle directly, not
105
+ // by a global page-level shortcut.
106
+ var isShortcutToFocusToolbar = useCallback(function () {
107
+ return false;
108
+ }, []);
109
+ var handleClickOutside = useCallback(function (event) {
110
+ var _popupContentRef$curr;
111
+ var target = event.target;
112
+ // Ignore clicks handled by this popup, drag handles, or nested portalled
113
+ // dropdowns so those controls can manage their own open/close behavior.
114
+ if (target instanceof Node && (_popupContentRef$curr = popupContentRef.current) !== null && _popupContentRef$curr !== void 0 && _popupContentRef$curr.contains(target) || target instanceof Element && (target.closest(DRAG_HANDLE_CONTROLS_SELECTOR) || target.closest(NESTED_DROPDOWN_SELECTOR))) {
115
+ return;
116
+ }
117
+ dismiss();
118
+ }, [dismiss]);
119
+ if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
120
+ return null;
121
+ }
122
+ var inStickyMode = (stickyHeaders === null || stickyHeaders === void 0 ? void 0 : stickyHeaders.sticky) || (tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.contains(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW)) && fg('platform_editor_table_sticky_header_patch_7');
123
+ var targetHandleRef = dragMenuDirection === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
124
+ if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
125
+ return null;
126
+ }
127
+ return /*#__PURE__*/React.createElement(PopupWithListeners, {
128
+ alignX: dragMenuDirection === 'row' ? 'right' : undefined,
129
+ alignY: dragMenuDirection === 'row' ? 'start' : undefined
130
+ // Ignored via go/ees005
131
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
132
+ ,
133
+ target: targetHandleRef,
134
+ mountTo: mountPoint,
135
+ boundariesElement: boundariesElement,
136
+ scrollableElement: scrollableElement,
137
+ fitWidth: TABLE_MENU_WIDTH,
138
+ fitHeight: tablePopupMenuFitHeight
139
+ // z-index value below is to ensure that this menu is above other floating menu
140
+ // in table, but below floating dialogs like typeaheads, pickers, etc.
141
+ // In sticky mode, we want to show the menu above the sticky header
142
+ ,
143
+ zIndex: inStickyMode ? akEditorFloatingDialogZIndex : akEditorFloatingOverlapPanelZIndex,
144
+ forcePlacement: true,
145
+ preventOverflow: dragMenuDirection === 'row',
146
+ offset: POPUP_OFFSET,
147
+ stick: true,
148
+ handleClickOutside: handleClickOutside
149
+ }, /*#__PURE__*/React.createElement("div", {
150
+ ref: handlePopupRef
151
+ }, /*#__PURE__*/React.createElement(ToolbarKeyboardNavigationProvider, {
152
+ childComponentSelector: TABLE_MENU_NAV_SELECTOR,
153
+ dom: editorDom,
154
+ isShortcutToFocusToolbar: isShortcutToFocusToolbar,
155
+ handleFocus: handleKeyboardFocus,
156
+ handleEscape: handleEscape
157
+ }, /*#__PURE__*/React.createElement("div", {
158
+ "data-table-drag-menu-nav": "true",
159
+ ref: setNavWrapperRef
160
+ }, /*#__PURE__*/React.createElement(TableMenu, {
161
+ api: api,
162
+ editorView: editorView,
163
+ surface: dragMenuDirection === 'row' ? ROW_MENU : COLUMN_MENU
164
+ })))));
165
+ };
166
+ FloatingTableMenu.displayName = 'FloatingTableMenu';
167
+ export default FloatingTableMenu;
@@ -1,15 +1,16 @@
1
1
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
2
 
3
3
  import React, { useCallback, useMemo, useRef } from 'react';
4
+ import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
4
5
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
6
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
6
7
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
7
8
  import { CellSelection } from '@atlaskit/editor-tables';
8
9
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
9
10
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
- import { clearHoverSelection, hoverCell, hoverColumns, selectColumn, selectColumns } from '../../../pm-plugins/commands';
11
- import { toggleActiveTableMenuWithAnalytics } from '../../../pm-plugins/commands/commands-with-analytics';
11
+ import { clearHoverSelection, closeActiveTableMenu, hoverCell, hoverColumns, selectColumn, selectColumns, toggleActiveTableMenu } from '../../../pm-plugins/commands';
12
12
  import { toggleDragMenuWithAnalytics } from '../../../pm-plugins/drag-and-drop/commands-with-analytics';
13
+ import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
13
14
  import { getRowsParams } from '../../../pm-plugins/utils/row-controls';
14
15
  import { getSelectedColumnIndexes } from '../../../pm-plugins/utils/selection';
15
16
  import { TableCssClassName as ClassName } from '../../../types';
@@ -25,7 +26,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
25
26
  return [];
26
27
  };
27
28
  export var ColumnControls = function ColumnControls(_ref) {
28
- var _colWidths$map$join, _api$analytics3;
29
+ var _colWidths$map$join;
29
30
  var editorView = _ref.editorView,
30
31
  tableActive = _ref.tableActive,
31
32
  tableRef = _ref.tableRef,
@@ -122,17 +123,48 @@ export var ColumnControls = function ColumnControls(_ref) {
122
123
  var state = editorView.state,
123
124
  dispatch = editorView.dispatch;
124
125
  if (event !== null && event !== void 0 && event.shiftKey) {
126
+ // Shift-click extends the selection rather than toggling the menu, but the
127
+ // open drag menu would otherwise stay anchored to a stale column. Close it here
128
+ // for the updated menu (legacy menu closes via outside-click on its dropdown).
129
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
130
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
131
+ }
125
132
  return;
126
133
  }
127
134
  if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
128
- if (colIndex !== undefined) {
129
- var _api$analytics;
130
- toggleActiveTableMenuWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)('column', colIndex, trigger)(state, dispatch);
135
+ if (colIndex !== undefined && api) {
136
+ var _getTablePluginState = getTablePluginState(state),
137
+ currentActiveTableMenu = _getTablePluginState.activeTableMenu;
138
+ var isSameActiveMenu = (currentActiveTableMenu === null || currentActiveTableMenu === void 0 ? void 0 : currentActiveTableMenu.type) === 'column' && currentActiveTableMenu.index === colIndex;
139
+ api.core.actions.execute(function (_ref2) {
140
+ var tr = _ref2.tr;
141
+ if (!isSameActiveMenu) {
142
+ var _api$analytics;
143
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
144
+ action: TABLE_ACTION.DRAG_MENU_OPENED,
145
+ actionSubject: ACTION_SUBJECT.TABLE,
146
+ actionSubjectId: null,
147
+ eventType: EVENT_TYPE.TRACK,
148
+ attributes: {
149
+ inputMethod: trigger === 'keyboard' ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE,
150
+ direction: 'column'
151
+ }
152
+ })(tr);
153
+ }
154
+ toggleActiveTableMenu({
155
+ type: 'column',
156
+ index: colIndex,
157
+ openedBy: trigger
158
+ }, currentActiveTableMenu, api)({
159
+ tr: tr
160
+ });
161
+ return tr;
162
+ });
131
163
  }
132
164
  return;
133
165
  }
134
166
  toggleDragMenuWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(undefined, 'column', colIndex, trigger)(state, dispatch);
135
- }, [editorView, colIndex, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions]);
167
+ }, [editorView, colIndex, api]);
136
168
  var colIndexes = useMemo(function () {
137
169
  // Ignored via go/ees005
138
170
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -239,9 +271,9 @@ export var ColumnControls = function ColumnControls(_ref) {
239
271
  overflowX: stickyTop ? 'hidden' : 'visible',
240
272
  pointerEvents: isDragging ? 'none' : undefined
241
273
  }
242
- }, columnParams.map(function (_ref2, index) {
243
- var startIndex = _ref2.startIndex,
244
- endIndex = _ref2.endIndex;
274
+ }, columnParams.map(function (_ref3, index) {
275
+ var startIndex = _ref3.startIndex,
276
+ endIndex = _ref3.endIndex;
245
277
  return /*#__PURE__*/React.createElement("div", {
246
278
  style: {
247
279
  gridColumn: "".concat(startIndex + 1, " / span 1")
@@ -2,13 +2,13 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
3
3
 
4
4
  import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
5
+ import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
5
6
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
6
7
  import { CellSelection } from '@atlaskit/editor-tables';
7
8
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
8
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
9
10
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
- import { clearHoverSelection } from '../../../pm-plugins/commands';
11
- import { toggleActiveTableMenuWithAnalytics } from '../../../pm-plugins/commands/commands-with-analytics';
11
+ import { clearHoverSelection, closeActiveTableMenu, toggleActiveTableMenu } from '../../../pm-plugins/commands';
12
12
  import { toggleDragMenuWithAnalytics } from '../../../pm-plugins/drag-and-drop/commands-with-analytics';
13
13
  import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
14
14
  import { getRowHeights, getRowsParams } from '../../../pm-plugins/utils/row-controls';
@@ -28,7 +28,7 @@ var getSelectedRows = function getSelectedRows(selection) {
28
28
  return [];
29
29
  };
30
30
  export var DragControls = function DragControls(_ref) {
31
- var _tableNode$attrs$loca, _tableNode$attrs, _api$analytics3;
31
+ var _tableNode$attrs$loca, _tableNode$attrs;
32
32
  var tableRef = _ref.tableRef,
33
33
  tableNode = _ref.tableNode,
34
34
  tableWidth = _ref.tableWidth,
@@ -83,18 +83,49 @@ export var DragControls = function DragControls(_ref) {
83
83
  var toggleDragMenuHandler = useCallback(function (trigger, event) {
84
84
  var _api$analytics2;
85
85
  if (event !== null && event !== void 0 && event.shiftKey) {
86
+ // Shift-click extends the selection rather than toggling the menu, but the
87
+ // open drag menu would otherwise stay anchored to a stale row. Close it here
88
+ // for the updated menu (legacy menu closes via outside-click on its dropdown).
89
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
90
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
91
+ }
86
92
  return;
87
93
  }
88
94
  var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
89
95
  if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
90
- if (rowIndex !== undefined) {
91
- var _api$analytics;
92
- toggleActiveTableMenuWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)('row', rowIndex, trigger)(editorView.state, editorView.dispatch);
96
+ if (rowIndex !== undefined && api) {
97
+ var _getTablePluginState2 = getTablePluginState(editorView.state),
98
+ currentActiveTableMenu = _getTablePluginState2.activeTableMenu;
99
+ var isSameActiveMenu = (currentActiveTableMenu === null || currentActiveTableMenu === void 0 ? void 0 : currentActiveTableMenu.type) === 'row' && currentActiveTableMenu.index === rowIndex;
100
+ api.core.actions.execute(function (_ref4) {
101
+ var tr = _ref4.tr;
102
+ if (!isSameActiveMenu) {
103
+ var _api$analytics;
104
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
105
+ action: TABLE_ACTION.DRAG_MENU_OPENED,
106
+ actionSubject: ACTION_SUBJECT.TABLE,
107
+ actionSubjectId: null,
108
+ eventType: EVENT_TYPE.TRACK,
109
+ attributes: {
110
+ inputMethod: trigger === 'keyboard' ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE,
111
+ direction: 'row'
112
+ }
113
+ })(tr);
114
+ }
115
+ toggleActiveTableMenu({
116
+ type: 'row',
117
+ index: rowIndex,
118
+ openedBy: trigger
119
+ }, currentActiveTableMenu, api)({
120
+ tr: tr
121
+ });
122
+ return tr;
123
+ });
93
124
  }
94
125
  return;
95
126
  }
96
127
  toggleDragMenuWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(undefined, 'row', rowIndex, trigger)(editorView.state, editorView.dispatch);
97
- }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions]);
128
+ }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, api]);
98
129
  var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
99
130
  var handleMouseOut = useCallback(function () {
100
131
  if (tableActive) {
@@ -225,9 +256,9 @@ export var DragControls = function DragControls(_ref) {
225
256
  },
226
257
  onMouseMove: handleMouseMove,
227
258
  contentEditable: false
228
- }, rowsParams.map(function (_ref4, index) {
229
- var startIndex = _ref4.startIndex,
230
- endIndex = _ref4.endIndex;
259
+ }, rowsParams.map(function (_ref5, index) {
260
+ var startIndex = _ref5.startIndex,
261
+ endIndex = _ref5.endIndex;
231
262
  return (
232
263
  /*#__PURE__*/
233
264
  // Ignored via go/ees005
@@ -278,21 +309,21 @@ export var DragControls = function DragControls(_ref) {
278
309
  );
279
310
  }), rowHandles());
280
311
  };
281
- export var DragControlsWithSelection = function DragControlsWithSelection(_ref5) {
282
- var editorView = _ref5.editorView,
283
- tableRef = _ref5.tableRef,
284
- tableNode = _ref5.tableNode,
285
- tableWidth = _ref5.tableWidth,
286
- tableActive = _ref5.tableActive,
287
- hoveredCell = _ref5.hoveredCell,
288
- isInDanger = _ref5.isInDanger,
289
- isTableHovered = _ref5.isTableHovered,
290
- isResizing = _ref5.isResizing,
291
- hoverRows = _ref5.hoverRows,
292
- selectRow = _ref5.selectRow,
293
- selectRows = _ref5.selectRows,
294
- updateCellHoverLocation = _ref5.updateCellHoverLocation,
295
- api = _ref5.api;
312
+ export var DragControlsWithSelection = function DragControlsWithSelection(_ref6) {
313
+ var editorView = _ref6.editorView,
314
+ tableRef = _ref6.tableRef,
315
+ tableNode = _ref6.tableNode,
316
+ tableWidth = _ref6.tableWidth,
317
+ tableActive = _ref6.tableActive,
318
+ hoveredCell = _ref6.hoveredCell,
319
+ isInDanger = _ref6.isInDanger,
320
+ isTableHovered = _ref6.isTableHovered,
321
+ isResizing = _ref6.isResizing,
322
+ hoverRows = _ref6.hoverRows,
323
+ selectRow = _ref6.selectRow,
324
+ selectRows = _ref6.selectRows,
325
+ updateCellHoverLocation = _ref6.updateCellHoverLocation,
326
+ api = _ref6.api;
296
327
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['selection'], function (states) {
297
328
  var _states$selectionStat;
298
329
  return {
@@ -26,7 +26,7 @@ export var MergeCellsItem = function MergeCellsItem(_ref) {
26
26
  return;
27
27
  }
28
28
  mergeCellsWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.CONTEXT_MENU)(editorView.state, editorView.dispatch);
29
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
29
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
30
30
  api === null || api === void 0 || api.core.actions.focus();
31
31
  };
32
32
  if (!shouldShowMergeCells(tableMenuContext)) {
@@ -26,7 +26,7 @@ export var SplitCellItem = function SplitCellItem(_ref) {
26
26
  return;
27
27
  }
28
28
  splitCellWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.CONTEXT_MENU)(editorView.state, editorView.dispatch);
29
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
29
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
30
30
  api === null || api === void 0 || api.core.actions.focus();
31
31
  };
32
32
  if (!shouldShowSplitCell(tableMenuContext)) {
@@ -31,7 +31,7 @@ export var VerticalAlignDropdownItem = function VerticalAlignDropdownItem(_ref)
31
31
  }, targetCellPosition)({
32
32
  tr: tr
33
33
  });
34
- closeActiveTableMenu()({
34
+ closeActiveTableMenu(api)({
35
35
  tr: tr
36
36
  });
37
37
  return tr;
@@ -39,7 +39,7 @@ export var AddColumnLeftItem = function AddColumnLeftItem(_ref) {
39
39
  }
40
40
  var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
41
41
  insertColumnWithAnalytics(api, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, isCommentEditor)(INPUT_METHOD.TABLE_CONTEXT_MENU, index)(editorView.state, editorView.dispatch, editorView);
42
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
42
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
43
43
  api === null || api === void 0 || api.core.actions.focus();
44
44
  };
45
45
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -39,7 +39,7 @@ export var AddColumnRightItem = function AddColumnRightItem(_ref) {
39
39
  }
40
40
  var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
41
41
  insertColumnWithAnalytics(api, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, isCommentEditor)(INPUT_METHOD.TABLE_CONTEXT_MENU, index)(editorView.state, editorView.dispatch, editorView);
42
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
42
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
43
43
  api === null || api === void 0 || api.core.actions.focus();
44
44
  };
45
45
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -57,7 +57,7 @@ export var DeleteColumnItem = function DeleteColumnItem(_ref) {
57
57
  }
58
58
  var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
59
59
  deleteColumnsWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, isCommentEditor)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect)(editorView.state, editorView.dispatch, editorView);
60
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
60
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
61
61
  api === null || api === void 0 || api.core.actions.focus();
62
62
  };
63
63
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -48,7 +48,7 @@ export var DistributeColumnsItem = function DistributeColumnsItem(_ref) {
48
48
  return;
49
49
  }
50
50
  distributeColumnsWidthsWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api)(INPUT_METHOD.TABLE_CONTEXT_MENU, newResizeState)(editorView.state, editorView.dispatch);
51
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
51
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
52
52
  api === null || api === void 0 || api.core.actions.focus();
53
53
  };
54
54
  if (!shouldShowDistributeColumns(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount)) {
@@ -42,7 +42,7 @@ export var MoveColumnLeftItem = function MoveColumnLeftItem(props) {
42
42
  return;
43
43
  }
44
44
  moveSourceWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_COLUMN, getSelectedColumnIndexes(selectionRect), selectionRect.left - 1)(editorView.state, editorView.dispatch);
45
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
45
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
46
46
  api === null || api === void 0 || api.core.actions.focus();
47
47
  };
48
48
  if (!tableNode || !shouldShowMoveColumnLeft(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn)) {
@@ -41,7 +41,7 @@ export var MoveColumnRightItem = function MoveColumnRightItem(props) {
41
41
  return;
42
42
  }
43
43
  moveSourceWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_COLUMN, getSelectedColumnIndexes(selectionRect), selectionRect.right)(editorView.state, editorView.dispatch);
44
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
44
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
45
45
  api === null || api === void 0 || api.core.actions.focus();
46
46
  };
47
47
  if (!tableNode || !shouldShowMoveColumnRight(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastColumn)) {
@@ -26,7 +26,7 @@ export var SortDecreasingItem = function SortDecreasingItem(_ref) {
26
26
  return;
27
27
  }
28
28
  sortColumnWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, columnIndex, SortOrder.DESC)(editorView.state, editorView.dispatch);
29
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
29
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
30
30
  api === null || api === void 0 || api.core.actions.focus();
31
31
  };
32
32
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -26,7 +26,7 @@ export var SortIncreasingItem = function SortIncreasingItem(_ref) {
26
26
  return;
27
27
  }
28
28
  sortColumnWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, columnIndex, SortOrder.ASC)(editorView.state, editorView.dispatch);
29
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
29
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
30
30
  api === null || api === void 0 || api.core.actions.focus();
31
31
  };
32
32
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -29,7 +29,7 @@ export var AddRowAboveItem = function AddRowAboveItem(props) {
29
29
  index: index,
30
30
  moveCursorToInsertedRow: true
31
31
  })(editorView.state, editorView.dispatch);
32
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
32
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
33
33
  api === null || api === void 0 || api.core.actions.focus();
34
34
  };
35
35
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -29,7 +29,7 @@ export var AddRowBelowItem = function AddRowBelowItem(props) {
29
29
  index: index,
30
30
  moveCursorToInsertedRow: true
31
31
  })(editorView.state, editorView.dispatch);
32
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
32
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
33
33
  api === null || api === void 0 || api.core.actions.focus();
34
34
  };
35
35
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -52,7 +52,7 @@ export var DeleteRowItem = function DeleteRowItem(props) {
52
52
  return;
53
53
  }
54
54
  deleteRowsWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect, !!isHeaderRowRequired)(editorView.state, editorView.dispatch);
55
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
55
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
56
56
  api === null || api === void 0 || api.core.actions.focus();
57
57
  };
58
58
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -41,7 +41,7 @@ export var MoveRowDownItem = function MoveRowDownItem(props) {
41
41
  return;
42
42
  }
43
43
  moveSourceWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_ROW, getSelectedRowIndexes(selectionRect), selectionRect.bottom)(editorView.state, editorView.dispatch);
44
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
44
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
45
45
  api === null || api === void 0 || api.core.actions.focus();
46
46
  };
47
47
  if (!tableNode || !shouldShowMoveRowDown(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastRow)) {
@@ -41,7 +41,7 @@ export var MoveRowUpItem = function MoveRowUpItem(props) {
41
41
  return;
42
42
  }
43
43
  moveSourceWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_ROW, getSelectedRowIndexes(selectionRect), selectionRect.top - 1)(editorView.state, editorView.dispatch);
44
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
44
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
45
45
  api === null || api === void 0 || api.core.actions.focus();
46
46
  };
47
47
  if (!tableNode || !shouldShowMoveRowUp(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstRow)) {
@@ -28,17 +28,17 @@ export var TableMenu = /*#__PURE__*/memo(function (_ref) {
28
28
  tableNode = _useSharedPluginState.tableNode,
29
29
  selection = _useSharedPluginState.selection;
30
30
  var tableMenuContext = useMemo(function () {
31
- if (!selection || !tableNode) {
32
- return {
33
- editorView: editorView
34
- };
31
+ // rely on selection plugins state to re-render the row/column menu, but use editorView.selection
32
+ // for cell menu state as the selection plugin won't update when text selection changes within cells
33
+ if (!tableNode || !editorView || !selection) {
34
+ return undefined;
35
35
  }
36
36
  var tableMap = TableMap.get(tableNode);
37
- var selectionRect = getSelectionRect(selection);
37
+ var selectionRect = getSelectionRect(editorView.state.selection);
38
38
  var cellOps = {
39
39
  editorView: editorView,
40
- canMergeCells: canMergeCellSelection(selection),
41
- canSplitCell: canSplitCellSelection(selection),
40
+ canMergeCells: canMergeCellSelection(editorView.state.selection),
41
+ canSplitCell: canSplitCellSelection(editorView.state.selection),
42
42
  hasMergedCellsInTable: tableMap.hasMergedCells()
43
43
  };
44
44
  if (!selectionRect) {
@@ -52,7 +52,7 @@ export var TableMenu = /*#__PURE__*/memo(function (_ref) {
52
52
  isLastColumn: selectionRect.right === tableMap.width,
53
53
  selectedColumnCount: selectionRect.right - selectionRect.left
54
54
  });
55
- }, [editorView, selection, tableNode]);
55
+ }, [editorView, tableNode, selection]);
56
56
  if (components.length === 0) {
57
57
  return null;
58
58
  }
@@ -1,4 +1,4 @@
1
1
  export var TABLE_MENU_WIDTH = 280;
2
- export var TABLE_MENU_SELECTOR = '[data-testid="column-handle-menu"], [data-testid="row-handle-menu"], [data-toolbar-nested-dropdown-menu]';
2
+ export var TABLE_MENU_SELECTOR = '[data-testid="column-handle-menu"], [data-testid="row-handle-menu"], [data-toolbar-component="menu"], [data-toolbar-nested-dropdown-menu]';
3
3
  export var TABLE_ROW = 'table-row';
4
4
  export var TABLE_COLUMN = 'table-column';
@@ -42,7 +42,7 @@ export var BackgroundColorItem = function BackgroundColorItem(_ref) {
42
42
  return;
43
43
  }
44
44
  setColorWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, color, editorView)(editorView.state, editorView.dispatch);
45
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
45
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
46
46
  api === null || api === void 0 || api.core.actions.focus();
47
47
  }, [api, editorView]);
48
48
  // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
@@ -25,7 +25,7 @@ export var ClearCellsItem = function ClearCellsItem(_ref) {
25
25
  var _getPluginState = getPluginState(editorView.state),
26
26
  targetCellPosition = _getPluginState.targetCellPosition;
27
27
  emptyMultipleCellsWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, targetCellPosition)(editorView.state, editorView.dispatch);
28
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu());
28
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
29
29
  api === null || api === void 0 || api.core.actions.focus();
30
30
  };
31
31
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -1,6 +1,6 @@
1
1
  import type { EditorCommand } from '@atlaskit/editor-common/types';
2
- import type { ActiveTableMenu } from '../../types';
3
- export declare const closeActiveTableMenu: () => EditorCommand;
2
+ import type { ActiveTableMenu, PluginInjectionAPI } from '../../types';
3
+ export declare const closeActiveTableMenu: (api?: PluginInjectionAPI | null) => EditorCommand;
4
4
  export declare const toggleActiveTableMenu: (activeTableMenu: Exclude<ActiveTableMenu, {
5
5
  type: "none";
6
- }>, currentActiveTableMenu: ActiveTableMenu | undefined) => EditorCommand;
6
+ }>, currentActiveTableMenu: ActiveTableMenu | undefined, api?: PluginInjectionAPI | null) => EditorCommand;