@atlaskit/editor-plugin-table 23.3.4 → 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 (106) hide show
  1. package/CHANGELOG.md +7 -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/FloatingDragMenu/index.js +10 -38
  11. package/dist/cjs/ui/FloatingTableMenu/index.js +175 -0
  12. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +43 -11
  13. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +57 -26
  14. package/dist/cjs/ui/TableMenu/cell/items/MergeCellsItem.js +1 -1
  15. package/dist/cjs/ui/TableMenu/cell/items/SplitCellItem.js +1 -1
  16. package/dist/cjs/ui/TableMenu/cell/items/VerticalAlignDropdownItem.js +1 -1
  17. package/dist/cjs/ui/TableMenu/column/items/AddColumnLeftItem.js +1 -1
  18. package/dist/cjs/ui/TableMenu/column/items/AddColumnRightItem.js +1 -1
  19. package/dist/cjs/ui/TableMenu/column/items/DeleteColumnItem.js +1 -1
  20. package/dist/cjs/ui/TableMenu/column/items/DistributeColumnsItem.js +1 -1
  21. package/dist/cjs/ui/TableMenu/column/items/MoveColumnLeftItem.js +1 -1
  22. package/dist/cjs/ui/TableMenu/column/items/MoveColumnRightItem.js +1 -1
  23. package/dist/cjs/ui/TableMenu/column/items/SortDecreasingItem.js +1 -1
  24. package/dist/cjs/ui/TableMenu/column/items/SortIncreasingItem.js +1 -1
  25. package/dist/cjs/ui/TableMenu/row/items/AddRowAboveItem.js +1 -1
  26. package/dist/cjs/ui/TableMenu/row/items/AddRowBelowItem.js +1 -1
  27. package/dist/cjs/ui/TableMenu/row/items/DeleteRowItem.js +1 -1
  28. package/dist/cjs/ui/TableMenu/row/items/MoveRowDownItem.js +1 -1
  29. package/dist/cjs/ui/TableMenu/row/items/MoveRowUpItem.js +1 -1
  30. package/dist/cjs/ui/TableMenu/shared/TableMenu.js +8 -8
  31. package/dist/cjs/ui/TableMenu/shared/consts.js +1 -1
  32. package/dist/cjs/ui/TableMenu/shared/items/BackgroundColorItem.js +1 -1
  33. package/dist/cjs/ui/TableMenu/shared/items/ClearCellsItem.js +1 -1
  34. package/dist/es2019/pm-plugins/commands/active-table-menu.js +19 -8
  35. package/dist/es2019/pm-plugins/commands/commands-with-analytics.js +0 -39
  36. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +1 -1
  37. package/dist/es2019/pm-plugins/handlers.js +1 -1
  38. package/dist/es2019/pm-plugins/main.js +3 -0
  39. package/dist/es2019/ui/ContentComponent.js +11 -1
  40. package/dist/es2019/ui/FloatingContextualButton/index.js +2 -2
  41. package/dist/es2019/ui/FloatingContextualMenu/CellMenuPopup.js +2 -2
  42. package/dist/es2019/ui/FloatingDragMenu/index.js +11 -40
  43. package/dist/es2019/ui/FloatingTableMenu/index.js +165 -0
  44. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +41 -7
  45. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +40 -7
  46. package/dist/es2019/ui/TableMenu/cell/items/MergeCellsItem.js +1 -1
  47. package/dist/es2019/ui/TableMenu/cell/items/SplitCellItem.js +1 -1
  48. package/dist/es2019/ui/TableMenu/cell/items/VerticalAlignDropdownItem.js +1 -1
  49. package/dist/es2019/ui/TableMenu/column/items/AddColumnLeftItem.js +1 -1
  50. package/dist/es2019/ui/TableMenu/column/items/AddColumnRightItem.js +1 -1
  51. package/dist/es2019/ui/TableMenu/column/items/DeleteColumnItem.js +1 -1
  52. package/dist/es2019/ui/TableMenu/column/items/DistributeColumnsItem.js +1 -1
  53. package/dist/es2019/ui/TableMenu/column/items/MoveColumnLeftItem.js +1 -1
  54. package/dist/es2019/ui/TableMenu/column/items/MoveColumnRightItem.js +1 -1
  55. package/dist/es2019/ui/TableMenu/column/items/SortDecreasingItem.js +1 -1
  56. package/dist/es2019/ui/TableMenu/column/items/SortIncreasingItem.js +1 -1
  57. package/dist/es2019/ui/TableMenu/row/items/AddRowAboveItem.js +1 -1
  58. package/dist/es2019/ui/TableMenu/row/items/AddRowBelowItem.js +1 -1
  59. package/dist/es2019/ui/TableMenu/row/items/DeleteRowItem.js +1 -1
  60. package/dist/es2019/ui/TableMenu/row/items/MoveRowDownItem.js +1 -1
  61. package/dist/es2019/ui/TableMenu/row/items/MoveRowUpItem.js +1 -1
  62. package/dist/es2019/ui/TableMenu/shared/TableMenu.js +8 -8
  63. package/dist/es2019/ui/TableMenu/shared/consts.js +1 -1
  64. package/dist/es2019/ui/TableMenu/shared/items/BackgroundColorItem.js +1 -1
  65. package/dist/es2019/ui/TableMenu/shared/items/ClearCellsItem.js +1 -1
  66. package/dist/esm/pm-plugins/commands/active-table-menu.js +19 -8
  67. package/dist/esm/pm-plugins/commands/commands-with-analytics.js +8 -48
  68. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +1 -1
  69. package/dist/esm/pm-plugins/handlers.js +1 -1
  70. package/dist/esm/pm-plugins/main.js +4 -1
  71. package/dist/esm/ui/ContentComponent.js +11 -1
  72. package/dist/esm/ui/FloatingContextualButton/index.js +2 -2
  73. package/dist/esm/ui/FloatingContextualMenu/CellMenuPopup.js +2 -2
  74. package/dist/esm/ui/FloatingDragMenu/index.js +11 -39
  75. package/dist/esm/ui/FloatingTableMenu/index.js +167 -0
  76. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +42 -10
  77. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +56 -25
  78. package/dist/esm/ui/TableMenu/cell/items/MergeCellsItem.js +1 -1
  79. package/dist/esm/ui/TableMenu/cell/items/SplitCellItem.js +1 -1
  80. package/dist/esm/ui/TableMenu/cell/items/VerticalAlignDropdownItem.js +1 -1
  81. package/dist/esm/ui/TableMenu/column/items/AddColumnLeftItem.js +1 -1
  82. package/dist/esm/ui/TableMenu/column/items/AddColumnRightItem.js +1 -1
  83. package/dist/esm/ui/TableMenu/column/items/DeleteColumnItem.js +1 -1
  84. package/dist/esm/ui/TableMenu/column/items/DistributeColumnsItem.js +1 -1
  85. package/dist/esm/ui/TableMenu/column/items/MoveColumnLeftItem.js +1 -1
  86. package/dist/esm/ui/TableMenu/column/items/MoveColumnRightItem.js +1 -1
  87. package/dist/esm/ui/TableMenu/column/items/SortDecreasingItem.js +1 -1
  88. package/dist/esm/ui/TableMenu/column/items/SortIncreasingItem.js +1 -1
  89. package/dist/esm/ui/TableMenu/row/items/AddRowAboveItem.js +1 -1
  90. package/dist/esm/ui/TableMenu/row/items/AddRowBelowItem.js +1 -1
  91. package/dist/esm/ui/TableMenu/row/items/DeleteRowItem.js +1 -1
  92. package/dist/esm/ui/TableMenu/row/items/MoveRowDownItem.js +1 -1
  93. package/dist/esm/ui/TableMenu/row/items/MoveRowUpItem.js +1 -1
  94. package/dist/esm/ui/TableMenu/shared/TableMenu.js +8 -8
  95. package/dist/esm/ui/TableMenu/shared/consts.js +1 -1
  96. package/dist/esm/ui/TableMenu/shared/items/BackgroundColorItem.js +1 -1
  97. package/dist/esm/ui/TableMenu/shared/items/ClearCellsItem.js +1 -1
  98. package/dist/types/pm-plugins/commands/active-table-menu.d.ts +3 -3
  99. package/dist/types/pm-plugins/commands/commands-with-analytics.d.ts +1 -3
  100. package/dist/types/ui/FloatingTableMenu/index.d.ts +23 -0
  101. package/dist/types/ui/TableMenu/shared/consts.d.ts +1 -1
  102. package/dist/types-ts4.5/pm-plugins/commands/active-table-menu.d.ts +3 -3
  103. package/dist/types-ts4.5/pm-plugins/commands/commands-with-analytics.d.ts +1 -3
  104. package/dist/types-ts4.5/ui/FloatingTableMenu/index.d.ts +23 -0
  105. package/dist/types-ts4.5/ui/TableMenu/shared/consts.d.ts +1 -1
  106. package/package.json +3 -3
@@ -1,19 +1,11 @@
1
1
  import React from 'react';
2
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
2
  import { Popup } from '@atlaskit/editor-common/ui';
4
- import { UserIntentPopupWrapper } from '@atlaskit/editor-common/user-intent';
5
3
  import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
6
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
7
5
  import { fg } from '@atlaskit/platform-feature-flags';
8
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
6
  import { TableCssClassName as ClassName } from '../../types';
10
- import { dragMenuDropdownWidth, dragTableInsertColumnButtonSize, tablePopupMenuFitHeight } from '../consts';
11
- import { COLUMN_MENU } from '../TableMenu/column/keys';
12
- import { ROW_MENU } from '../TableMenu/row/keys';
13
- import { TABLE_MENU_WIDTH } from '../TableMenu/shared/consts';
14
- import { TableMenu } from '../TableMenu/shared/TableMenu';
7
+ import { dragMenuDropdownWidth, tablePopupMenuFitHeight } from '../consts';
15
8
  import DragMenu from './DragMenu';
16
- const TABLE_MENU_OFFSET = dragTableInsertColumnButtonSize + 4;
17
9
  const FloatingDragMenu = ({
18
10
  mountPoint,
19
11
  boundariesElement,
@@ -36,24 +28,11 @@ const FloatingDragMenu = ({
36
28
  tableWrapper
37
29
  }) => {
38
30
  var _getEditorFeatureFlag;
39
- const {
40
- activeTableMenu
41
- } = useSharedPluginStateWithSelector(api, ['table'], states => {
42
- var _states$tableState;
43
- return {
44
- activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
45
- };
46
- });
47
- const isActiveTableMenuDragMenu = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
48
- const hasActiveTableMenuState = activeTableMenu !== undefined;
49
- const isDragMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu : isOpen;
50
- const dragMenuDirection = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.type : undefined : direction;
51
- const dragMenuIndex = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.index : undefined : index;
52
- if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
31
+ if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
53
32
  return null;
54
33
  }
55
34
  const 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');
56
- const targetHandleRef = dragMenuDirection === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
35
+ const targetHandleRef = direction === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
57
36
  if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
58
37
  return null;
59
38
  }
@@ -62,8 +41,8 @@ const FloatingDragMenu = ({
62
41
  } = (_getEditorFeatureFlag = getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) !== null && _getEditorFeatureFlag !== void 0 ? _getEditorFeatureFlag : {};
63
42
  const shouldUseIncreasedScalingPercent = isTableScalingEnabled && (tableWithFixedColumnWidthsOption || isCommentEditor);
64
43
  return /*#__PURE__*/React.createElement(Popup, {
65
- alignX: dragMenuDirection === 'row' ? 'right' : undefined,
66
- alignY: dragMenuDirection === 'row' ? 'start' : undefined
44
+ alignX: direction === 'row' ? 'right' : undefined,
45
+ alignY: direction === 'row' ? 'start' : undefined
67
46
  // Ignored via go/ees005
68
47
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
69
48
  ,
@@ -71,7 +50,7 @@ const FloatingDragMenu = ({
71
50
  mountTo: mountPoint,
72
51
  boundariesElement: boundariesElement,
73
52
  scrollableElement: scrollableElement,
74
- fitWidth: expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? TABLE_MENU_WIDTH : dragMenuDropdownWidth,
53
+ fitWidth: dragMenuDropdownWidth,
75
54
  fitHeight: tablePopupMenuFitHeight
76
55
  // z-index value below is to ensure that this menu is above other floating menu
77
56
  // in table, but below floating dialogs like typeaheads, pickers, etc.
@@ -79,22 +58,14 @@ const FloatingDragMenu = ({
79
58
  ,
80
59
  zIndex: inStickyMode ? akEditorFloatingDialogZIndex : akEditorFloatingOverlapPanelZIndex,
81
60
  forcePlacement: true,
82
- preventOverflow: expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? dragMenuDirection === 'row' : undefined,
83
- offset: expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? [TABLE_MENU_OFFSET, 0] : direction === 'row' ? [-9, 0] : [0, -7],
61
+ offset: direction === 'row' ? [-9, 0] : [0, -7],
84
62
  stick: true
85
- }, expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? /*#__PURE__*/React.createElement(UserIntentPopupWrapper, {
86
- api: api,
87
- userIntent: "tableDragMenuPopupOpen"
88
- }, /*#__PURE__*/React.createElement(TableMenu, {
89
- api: api,
90
- editorView: editorView,
91
- surface: dragMenuDirection === 'row' ? ROW_MENU : COLUMN_MENU
92
- })) : /*#__PURE__*/React.createElement(DragMenu, {
63
+ }, /*#__PURE__*/React.createElement(DragMenu, {
93
64
  editorView: editorView,
94
- isOpen: isDragMenuOpen,
65
+ isOpen: isOpen,
95
66
  tableNode: tableNode,
96
- direction: dragMenuDirection,
97
- index: dragMenuIndex,
67
+ direction: direction,
68
+ index: index,
98
69
  target: targetHandleRef || undefined,
99
70
  targetCellPosition: targetCellPosition,
100
71
  getEditorContainerWidth: getEditorContainerWidth,
@@ -0,0 +1,165 @@
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
+ const 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
+ const DRAG_HANDLE_CONTROLS_SELECTOR = `.${ClassName.DRAG_ROW_CONTROLS}, .${ClassName.DRAG_COLUMN_CONTROLS}`;
21
+ const 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
+ const TABLE_MENU_NAV_SELECTOR = '[data-table-drag-menu-nav="true"]';
27
+ const TABLE_MENU_OFFSET = dragTableInsertColumnButtonSize + 4;
28
+ const POPUP_OFFSET = [TABLE_MENU_OFFSET, 0];
29
+
30
+ /**
31
+ * Row and column menu for table.
32
+ */
33
+ const FloatingTableMenu = ({
34
+ api,
35
+ boundariesElement,
36
+ editorView,
37
+ mountPoint,
38
+ scrollableElement,
39
+ stickyHeaders,
40
+ tableWrapper,
41
+ targetCellPosition
42
+ }) => {
43
+ const {
44
+ activeTableMenu
45
+ } = useSharedPluginStateWithSelector(api, ['table'], states => {
46
+ var _states$tableState;
47
+ return {
48
+ activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
49
+ };
50
+ });
51
+ const isDragMenuOpen = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
52
+ const dragMenuDirection = isDragMenuOpen ? activeTableMenu.type : undefined;
53
+ const isOpenedByKeyboard = isDragMenuOpen && activeTableMenu.openedBy === 'keyboard';
54
+ const popupContentRef = useRef(null);
55
+ const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
56
+ const navWrapperRef = useRef(null);
57
+ const handlePopupRef = useCallback(el => {
58
+ popupContentRef.current = el;
59
+ setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 ? void 0 : setOutsideClickTargetRef(el);
60
+ }, [setOutsideClickTargetRef]);
61
+ const dismiss = useCallback(() => {
62
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
63
+ }, [api]);
64
+ const returnFocusToDragHandle = useCallback(() => {
65
+ // Match legacy DragMenu's closeMenu('handle') behaviour.
66
+ const handleId = dragMenuDirection === 'row' ? '#drag-handle-button-row' : '#drag-handle-button-column';
67
+ const handle = document.querySelector(handleId);
68
+ handle === null || handle === void 0 ? void 0 : handle.focus();
69
+ }, [dragMenuDirection]);
70
+ const focusFirstMenuItem = useCallback(() => {
71
+ const root = navWrapperRef.current;
72
+ if (!root) {
73
+ return;
74
+ }
75
+ const firstItem = root.querySelector('[role="menuitem"]:not([disabled]), [role="menuitemcheckbox"]:not([disabled]), [role="menuitemradio"]:not([disabled]), button:not([disabled])');
76
+ firstItem === null || firstItem === void 0 ? void 0 : firstItem.focus();
77
+ }, []);
78
+
79
+ // Focus the first menu item when the menu opens via keyboard (Enter/Space on
80
+ // the drag handle). Mouse-opened menus leave focus where the user clicked.
81
+ const setNavWrapperRef = useCallback(el => {
82
+ navWrapperRef.current = el;
83
+ if (el && isOpenedByKeyboard) {
84
+ // rAF allows the popup to finish positioning before focusing.
85
+ requestAnimationFrame(() => {
86
+ focusFirstMenuItem();
87
+ });
88
+ }
89
+ }, [focusFirstMenuItem, isOpenedByKeyboard]);
90
+ const handleKeyboardFocus = useCallback(_event => {
91
+ focusFirstMenuItem();
92
+ }, [focusFirstMenuItem]);
93
+ const handleEscape = useCallback(event => {
94
+ event.preventDefault();
95
+ event.stopPropagation();
96
+ dismiss();
97
+ returnFocusToDragHandle();
98
+ }, [dismiss, returnFocusToDragHandle]);
99
+
100
+ // Memoize the editor DOM reference so the provider doesn't re-bind listeners
101
+ // on every render (the provider depends on `dom` in its effect's deps).
102
+ const editorDom = useMemo(() => editorView.dom instanceof HTMLElement ? editorView.dom : undefined, [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
+ const isShortcutToFocusToolbar = useCallback(() => false, []);
107
+ const handleClickOutside = useCallback(event => {
108
+ var _popupContentRef$curr;
109
+ const target = event.target;
110
+ // Ignore clicks handled by this popup, drag handles, or nested portalled
111
+ // dropdowns so those controls can manage their own open/close behavior.
112
+ 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))) {
113
+ return;
114
+ }
115
+ dismiss();
116
+ }, [dismiss]);
117
+ if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
118
+ return null;
119
+ }
120
+ const 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');
121
+ const targetHandleRef = dragMenuDirection === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
122
+ if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
123
+ return null;
124
+ }
125
+ return /*#__PURE__*/React.createElement(PopupWithListeners, {
126
+ alignX: dragMenuDirection === 'row' ? 'right' : undefined,
127
+ alignY: dragMenuDirection === 'row' ? 'start' : undefined
128
+ // Ignored via go/ees005
129
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
130
+ ,
131
+ target: targetHandleRef,
132
+ mountTo: mountPoint,
133
+ boundariesElement: boundariesElement,
134
+ scrollableElement: scrollableElement,
135
+ fitWidth: TABLE_MENU_WIDTH,
136
+ fitHeight: tablePopupMenuFitHeight
137
+ // z-index value below is to ensure that this menu is above other floating menu
138
+ // in table, but below floating dialogs like typeaheads, pickers, etc.
139
+ // In sticky mode, we want to show the menu above the sticky header
140
+ ,
141
+ zIndex: inStickyMode ? akEditorFloatingDialogZIndex : akEditorFloatingOverlapPanelZIndex,
142
+ forcePlacement: true,
143
+ preventOverflow: dragMenuDirection === 'row',
144
+ offset: POPUP_OFFSET,
145
+ stick: true,
146
+ handleClickOutside: handleClickOutside
147
+ }, /*#__PURE__*/React.createElement("div", {
148
+ ref: handlePopupRef
149
+ }, /*#__PURE__*/React.createElement(ToolbarKeyboardNavigationProvider, {
150
+ childComponentSelector: TABLE_MENU_NAV_SELECTOR,
151
+ dom: editorDom,
152
+ isShortcutToFocusToolbar: isShortcutToFocusToolbar,
153
+ handleFocus: handleKeyboardFocus,
154
+ handleEscape: handleEscape
155
+ }, /*#__PURE__*/React.createElement("div", {
156
+ "data-table-drag-menu-nav": "true",
157
+ ref: setNavWrapperRef
158
+ }, /*#__PURE__*/React.createElement(TableMenu, {
159
+ api: api,
160
+ editorView: editorView,
161
+ surface: dragMenuDirection === 'row' ? ROW_MENU : COLUMN_MENU
162
+ })))));
163
+ };
164
+ FloatingTableMenu.displayName = 'FloatingTableMenu';
165
+ 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';
@@ -41,7 +42,7 @@ export const ColumnControls = ({
41
42
  getScrollOffset,
42
43
  api
43
44
  }) => {
44
- var _colWidths$map$join, _api$analytics3;
45
+ var _colWidths$map$join;
45
46
  const columnControlsRef = useRef(null);
46
47
  const {
47
48
  selection
@@ -131,17 +132,50 @@ export const ColumnControls = ({
131
132
  dispatch
132
133
  } = editorView;
133
134
  if (event !== null && event !== void 0 && event.shiftKey) {
135
+ // Shift-click extends the selection rather than toggling the menu, but the
136
+ // open drag menu would otherwise stay anchored to a stale column. Close it here
137
+ // for the updated menu (legacy menu closes via outside-click on its dropdown).
138
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
139
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
140
+ }
134
141
  return;
135
142
  }
136
143
  if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
137
- if (colIndex !== undefined) {
138
- var _api$analytics;
139
- toggleActiveTableMenuWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)('column', colIndex, trigger)(state, dispatch);
144
+ if (colIndex !== undefined && api) {
145
+ const {
146
+ activeTableMenu: currentActiveTableMenu
147
+ } = getTablePluginState(state);
148
+ const isSameActiveMenu = (currentActiveTableMenu === null || currentActiveTableMenu === void 0 ? void 0 : currentActiveTableMenu.type) === 'column' && currentActiveTableMenu.index === colIndex;
149
+ api.core.actions.execute(({
150
+ tr
151
+ }) => {
152
+ if (!isSameActiveMenu) {
153
+ var _api$analytics, _api$analytics$action;
154
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent({
155
+ action: TABLE_ACTION.DRAG_MENU_OPENED,
156
+ actionSubject: ACTION_SUBJECT.TABLE,
157
+ actionSubjectId: null,
158
+ eventType: EVENT_TYPE.TRACK,
159
+ attributes: {
160
+ inputMethod: trigger === 'keyboard' ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE,
161
+ direction: 'column'
162
+ }
163
+ })(tr);
164
+ }
165
+ toggleActiveTableMenu({
166
+ type: 'column',
167
+ index: colIndex,
168
+ openedBy: trigger
169
+ }, currentActiveTableMenu, api)({
170
+ tr
171
+ });
172
+ return tr;
173
+ });
140
174
  }
141
175
  return;
142
176
  }
143
177
  toggleDragMenuWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(undefined, 'column', colIndex, trigger)(state, dispatch);
144
- }, [editorView, colIndex, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions]);
178
+ }, [editorView, colIndex, api]);
145
179
  const colIndexes = useMemo(() => {
146
180
  // Ignored via go/ees005
147
181
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -1,13 +1,13 @@
1
1
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
2
 
3
3
  import React, { Fragment, useCallback, useEffect, useMemo, useState } 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 { CellSelection } from '@atlaskit/editor-tables';
6
7
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
8
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
8
9
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
- import { clearHoverSelection } from '../../../pm-plugins/commands';
10
- import { toggleActiveTableMenuWithAnalytics } from '../../../pm-plugins/commands/commands-with-analytics';
10
+ import { clearHoverSelection, closeActiveTableMenu, toggleActiveTableMenu } from '../../../pm-plugins/commands';
11
11
  import { toggleDragMenuWithAnalytics } from '../../../pm-plugins/drag-and-drop/commands-with-analytics';
12
12
  import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
13
13
  import { getRowHeights, getRowsParams } from '../../../pm-plugins/utils/row-controls';
@@ -43,7 +43,7 @@ export const DragControls = ({
43
43
  api,
44
44
  selection
45
45
  }) => {
46
- var _tableNode$attrs$loca, _tableNode$attrs, _api$analytics3;
46
+ var _tableNode$attrs$loca, _tableNode$attrs;
47
47
  const [isDragging, setIsDragging] = useState(false);
48
48
  const rowHeights = getRowHeights(tableRef);
49
49
  const rowsParams = getRowsParams(rowHeights);
@@ -81,18 +81,51 @@ export const DragControls = ({
81
81
  const toggleDragMenuHandler = useCallback((trigger, event) => {
82
82
  var _api$analytics2;
83
83
  if (event !== null && event !== void 0 && event.shiftKey) {
84
+ // Shift-click extends the selection rather than toggling the menu, but the
85
+ // open drag menu would otherwise stay anchored to a stale row. Close it here
86
+ // for the updated menu (legacy menu closes via outside-click on its dropdown).
87
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
88
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
89
+ }
84
90
  return;
85
91
  }
86
92
  const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
87
93
  if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
88
- if (rowIndex !== undefined) {
89
- var _api$analytics;
90
- toggleActiveTableMenuWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)('row', rowIndex, trigger)(editorView.state, editorView.dispatch);
94
+ if (rowIndex !== undefined && api) {
95
+ const {
96
+ activeTableMenu: currentActiveTableMenu
97
+ } = getTablePluginState(editorView.state);
98
+ const isSameActiveMenu = (currentActiveTableMenu === null || currentActiveTableMenu === void 0 ? void 0 : currentActiveTableMenu.type) === 'row' && currentActiveTableMenu.index === rowIndex;
99
+ api.core.actions.execute(({
100
+ tr
101
+ }) => {
102
+ if (!isSameActiveMenu) {
103
+ var _api$analytics, _api$analytics$action;
104
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.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
121
+ });
122
+ return tr;
123
+ });
91
124
  }
92
125
  return;
93
126
  }
94
127
  toggleDragMenuWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(undefined, 'row', rowIndex, trigger)(editorView.state, editorView.dispatch);
95
- }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, api === null || api === void 0 ? 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]);
96
129
  const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
97
130
  const handleMouseOut = useCallback(() => {
98
131
  if (tableActive) {
@@ -27,7 +27,7 @@ export const MergeCellsItem = ({
27
27
  return;
28
28
  }
29
29
  mergeCellsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.CONTEXT_MENU)(editorView.state, editorView.dispatch);
30
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
30
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
31
31
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
32
32
  };
33
33
  if (!shouldShowMergeCells(tableMenuContext)) {
@@ -27,7 +27,7 @@ export const SplitCellItem = ({
27
27
  return;
28
28
  }
29
29
  splitCellWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.CONTEXT_MENU)(editorView.state, editorView.dispatch);
30
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
30
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
31
31
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
32
32
  };
33
33
  if (!shouldShowSplitCell(tableMenuContext)) {
@@ -34,7 +34,7 @@ export const VerticalAlignDropdownItem = ({
34
34
  }, targetCellPosition)({
35
35
  tr
36
36
  });
37
- closeActiveTableMenu()({
37
+ closeActiveTableMenu(api)({
38
38
  tr
39
39
  });
40
40
  return tr;
@@ -43,7 +43,7 @@ export const AddColumnLeftItem = ({
43
43
  }
44
44
  const shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
45
45
  insertColumnWithAnalytics(api, api === null || api === void 0 ? 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);
46
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
46
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
47
47
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
48
48
  };
49
49
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -43,7 +43,7 @@ export const AddColumnRightItem = ({
43
43
  }
44
44
  const shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
45
45
  insertColumnWithAnalytics(api, api === null || api === void 0 ? 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);
46
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
46
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
47
47
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
48
48
  };
49
49
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -61,7 +61,7 @@ export const DeleteColumnItem = ({
61
61
  }
62
62
  const shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
63
63
  deleteColumnsWithAnalytics(api === null || api === void 0 ? 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);
64
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
64
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
65
65
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
66
66
  };
67
67
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -48,7 +48,7 @@ export const DistributeColumnsItem = ({
48
48
  return;
49
49
  }
50
50
  distributeColumnsWidthsWithAnalytics(api === null || api === void 0 ? 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 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
51
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
52
52
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
53
53
  };
54
54
  if (!shouldShowDistributeColumns(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount)) {
@@ -45,7 +45,7 @@ export const MoveColumnLeftItem = props => {
45
45
  return;
46
46
  }
47
47
  moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? 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);
48
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
48
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
49
49
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
50
50
  };
51
51
  if (!tableNode || !shouldShowMoveColumnLeft(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn)) {
@@ -44,7 +44,7 @@ export const MoveColumnRightItem = props => {
44
44
  return;
45
45
  }
46
46
  moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? 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);
47
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
47
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
48
48
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
49
49
  };
50
50
  if (!tableNode || !shouldShowMoveColumnRight(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastColumn)) {
@@ -29,7 +29,7 @@ export const SortDecreasingItem = ({
29
29
  return;
30
30
  }
31
31
  sortColumnWithAnalytics(api === null || api === void 0 ? 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);
32
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
32
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
33
33
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
34
34
  };
35
35
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -29,7 +29,7 @@ export const SortIncreasingItem = ({
29
29
  return;
30
30
  }
31
31
  sortColumnWithAnalytics(api === null || api === void 0 ? 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);
32
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
32
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
33
33
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
34
34
  };
35
35
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -33,7 +33,7 @@ export const AddRowAboveItem = props => {
33
33
  index,
34
34
  moveCursorToInsertedRow: true
35
35
  })(editorView.state, editorView.dispatch);
36
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
36
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
37
37
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
38
38
  };
39
39
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -33,7 +33,7 @@ export const AddRowBelowItem = props => {
33
33
  index,
34
34
  moveCursorToInsertedRow: true
35
35
  })(editorView.state, editorView.dispatch);
36
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
36
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
37
37
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
38
38
  };
39
39
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -57,7 +57,7 @@ export const DeleteRowItem = props => {
57
57
  return;
58
58
  }
59
59
  deleteRowsWithAnalytics(api === null || api === void 0 ? 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);
60
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
60
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
61
61
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
62
62
  };
63
63
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
@@ -44,7 +44,7 @@ export const MoveRowDownItem = props => {
44
44
  return;
45
45
  }
46
46
  moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? 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);
47
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
47
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
48
48
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
49
49
  };
50
50
  if (!tableNode || !shouldShowMoveRowDown(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastRow)) {
@@ -44,7 +44,7 @@ export const MoveRowUpItem = props => {
44
44
  return;
45
45
  }
46
46
  moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? 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);
47
- api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu());
47
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu(api));
48
48
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
49
49
  };
50
50
  if (!tableNode || !shouldShowMoveRowUp(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstRow)) {
@@ -27,17 +27,17 @@ export const TableMenu = /*#__PURE__*/memo(({
27
27
  };
28
28
  });
29
29
  const tableMenuContext = useMemo(() => {
30
- if (!selection || !tableNode) {
31
- return {
32
- editorView
33
- };
30
+ // rely on selection plugins state to re-render the row/column menu, but use editorView.selection
31
+ // for cell menu state as the selection plugin won't update when text selection changes within cells
32
+ if (!tableNode || !editorView || !selection) {
33
+ return undefined;
34
34
  }
35
35
  const tableMap = TableMap.get(tableNode);
36
- const selectionRect = getSelectionRect(selection);
36
+ const selectionRect = getSelectionRect(editorView.state.selection);
37
37
  const cellOps = {
38
38
  editorView,
39
- canMergeCells: canMergeCellSelection(selection),
40
- canSplitCell: canSplitCellSelection(selection),
39
+ canMergeCells: canMergeCellSelection(editorView.state.selection),
40
+ canSplitCell: canSplitCellSelection(editorView.state.selection),
41
41
  hasMergedCellsInTable: tableMap.hasMergedCells()
42
42
  };
43
43
  if (!selectionRect) {
@@ -52,7 +52,7 @@ export const TableMenu = /*#__PURE__*/memo(({
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
  }