@atlaskit/editor-plugin-table 5.3.25 → 5.3.26

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 (32) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
  3. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
  4. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +26 -1
  5. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
  6. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
  7. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +27 -1
  8. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
  9. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
  10. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +26 -1
  11. package/package.json +2 -2
  12. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +31 -7
  13. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -1
  14. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +33 -1
  15. package/src/__tests__/integration/__snapshots__/auto-size.ts.snap +0 -612
  16. package/src/__tests__/integration/__snapshots__/delete-columns.ts.snap +0 -820
  17. package/src/__tests__/integration/__snapshots__/delete-last-column-in-full-width.ts.snap +0 -120
  18. package/src/__tests__/integration/__snapshots__/delete-last-column-with-empty-action.ts.snap +0 -120
  19. package/src/__tests__/integration/__snapshots__/delete-last-row-with-empty-action.ts.snap +0 -229
  20. package/src/__tests__/integration/__snapshots__/insert-row-inside-layout.ts.snap +0 -239
  21. package/src/__tests__/integration/__snapshots__/resize.ts.snap +0 -2685
  22. package/src/__tests__/integration/__snapshots__/scale.ts.snap +0 -1085
  23. package/src/__tests__/integration/arrow-down-into-table.ts +0 -50
  24. package/src/__tests__/integration/auto-size.ts +0 -92
  25. package/src/__tests__/integration/cell-selection.ts +0 -105
  26. package/src/__tests__/integration/delete-columns.ts +0 -99
  27. package/src/__tests__/integration/delete-last-column-in-full-width.ts +0 -73
  28. package/src/__tests__/integration/delete-last-column-with-empty-action.ts +0 -60
  29. package/src/__tests__/integration/delete-last-row-with-empty-action.ts +0 -99
  30. package/src/__tests__/integration/insert-row-inside-layout.ts +0 -52
  31. package/src/__tests__/integration/resize.ts +0 -333
  32. package/src/__tests__/integration/scale.ts +0 -70
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.26
4
+
5
+ ### Patch Changes
6
+
7
+ - [#42815](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42815) [`7fac5fb48e7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7fac5fb48e7) - ED-20673: Fixed drag menu is not open when clicking on different drag handles consecutively.
8
+ - Updated dependencies
9
+
3
10
  ## 5.3.25
4
11
 
5
12
  ### Patch Changes
@@ -87,17 +87,30 @@ var toggleDragMenu = exports.toggleDragMenu = function toggleDragMenu(isDragMenu
87
87
  return (0, _pluginFactory.createCommand)(function (state) {
88
88
  var _getPluginState3 = (0, _pluginFactory.getPluginState)(state),
89
89
  previousOpenState = _getPluginState3.isDragMenuOpen,
90
- dragMenuDirection = _getPluginState3.dragMenuDirection,
91
- dragMenuIndex = _getPluginState3.dragMenuIndex;
92
- if (previousOpenState === isDragMenuOpen) {
90
+ previousDragMenuDirection = _getPluginState3.dragMenuDirection,
91
+ previousDragMenuIndex = _getPluginState3.dragMenuIndex;
92
+ if (previousOpenState === isDragMenuOpen && previousDragMenuDirection === direction && previousDragMenuIndex === index) {
93
93
  return false;
94
94
  }
95
+ var updatedMenuOpenState;
96
+ if (isDragMenuOpen !== undefined) {
97
+ updatedMenuOpenState = isDragMenuOpen;
98
+ } else {
99
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
100
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
101
+ // 2 scenarios above , menu should remain open.
102
+ if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
103
+ updatedMenuOpenState = true;
104
+ } else {
105
+ updatedMenuOpenState = !previousOpenState;
106
+ }
107
+ }
95
108
  return {
96
109
  type: _actions.DragAndDropActionType.TOGGLE_DRAG_MENU,
97
110
  data: {
98
- isDragMenuOpen: isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
99
- direction: direction !== null && direction !== void 0 ? direction : dragMenuDirection,
100
- index: index !== null && index !== void 0 ? index : dragMenuIndex
111
+ isDragMenuOpen: updatedMenuOpenState,
112
+ direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
113
+ index: index !== null && index !== void 0 ? index : previousDragMenuIndex
101
114
  }
102
115
  };
103
116
  }, function (tr) {
@@ -8,6 +8,7 @@ exports.createPlugin = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
11
12
  var _utils = require("@atlaskit/editor-tables/utils");
12
13
  var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
13
14
  var _pragmaticDragAndDropReactBeautifulDndAutoscroll = require("@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll");
@@ -56,7 +57,11 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
56
57
  };
57
58
  if (newTargetCellPosition !== undefined) {
58
59
  var cells = (0, _utils.getCellsInRow)(dragMenuIndex)(tr.selection);
59
- if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)) {
60
+ // ED-20673 check if it is a cell selection,
61
+ // when true, a drag handle is clicked and isDragMenuOpen is true here
62
+ // should not close the drag menu.
63
+ var isCellSelection = tr.selection instanceof _cellSelection.CellSelection;
64
+ if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
60
65
  return tr.setMeta(_pluginKey.pluginKey, action);
61
66
  } // else NOP
62
67
  } else {
@@ -13,6 +13,7 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
13
13
  var _utils = require("@atlaskit/editor-tables/utils");
14
14
  var _commands = require("../../commands");
15
15
  var _commands2 = require("../../pm-plugins/drag-and-drop/commands");
16
+ var _pluginFactory = require("../../pm-plugins/drag-and-drop/plugin-factory");
16
17
  var _utils2 = require("../../utils");
17
18
  var _dragMenu = require("../../utils/drag-menu");
18
19
  var _consts = require("../consts");
@@ -84,10 +85,34 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
84
85
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
85
86
  menuItems = _convertToDropdownIte.menuItems,
86
87
  menuCallback = _convertToDropdownIte.menuCallback;
88
+
89
+ /**
90
+ * This function is to check if the menu should be closed or not.
91
+ * As when continously clicking on drag handle on different rows/columns,
92
+ * should open the menu corresponding to the position of the drag handle.
93
+ * @returns true when the menu should be closed, false otherwise
94
+ */
95
+ var shouldCloseMenu = function shouldCloseMenu(state) {
96
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
97
+ previousOpenState = _getPluginState.isDragMenuOpen,
98
+ previousDragMenuDirection = _getPluginState.dragMenuDirection,
99
+ previousDragMenuIndex = _getPluginState.dragMenuIndex;
100
+
101
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
102
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
103
+ // 2 scenarios above , menu should not be closed.
104
+ if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
105
+ return false;
106
+ } else {
107
+ return true;
108
+ }
109
+ };
87
110
  var closeMenu = function closeMenu() {
88
111
  var state = editorView.state,
89
112
  dispatch = editorView.dispatch;
90
- (0, _commands2.toggleDragMenu)(false)(state, dispatch);
113
+ if (shouldCloseMenu(state)) {
114
+ (0, _commands2.toggleDragMenu)(false, direction, index)(state, dispatch);
115
+ }
91
116
  };
92
117
  var handleMenuItemActivated = function handleMenuItemActivated(_ref2) {
93
118
  var _menuCallback$item$va;
@@ -71,18 +71,31 @@ export const moveSource = (sourceType, sourceIndex, targetIndex) => createComman
71
71
  export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
72
72
  let {
73
73
  isDragMenuOpen: previousOpenState,
74
- dragMenuDirection,
75
- dragMenuIndex
74
+ dragMenuDirection: previousDragMenuDirection,
75
+ dragMenuIndex: previousDragMenuIndex
76
76
  } = getPluginState(state);
77
- if (previousOpenState === isDragMenuOpen) {
77
+ if (previousOpenState === isDragMenuOpen && previousDragMenuDirection === direction && previousDragMenuIndex === index) {
78
78
  return false;
79
79
  }
80
+ let updatedMenuOpenState;
81
+ if (isDragMenuOpen !== undefined) {
82
+ updatedMenuOpenState = isDragMenuOpen;
83
+ } else {
84
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
85
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
86
+ // 2 scenarios above , menu should remain open.
87
+ if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
88
+ updatedMenuOpenState = true;
89
+ } else {
90
+ updatedMenuOpenState = !previousOpenState;
91
+ }
92
+ }
80
93
  return {
81
94
  type: DragAndDropActionType.TOGGLE_DRAG_MENU,
82
95
  data: {
83
- isDragMenuOpen: isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
84
- direction: direction !== null && direction !== void 0 ? direction : dragMenuDirection,
85
- index: index !== null && index !== void 0 ? index : dragMenuIndex
96
+ isDragMenuOpen: updatedMenuOpenState,
97
+ direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
98
+ index: index !== null && index !== void 0 ? index : previousDragMenuIndex
86
99
  }
87
100
  };
88
101
  }, tr => {
@@ -1,5 +1,6 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
3
4
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
4
5
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
6
  import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
@@ -49,7 +50,11 @@ export const createPlugin = (dispatch, eventDispatcher) => {
49
50
  };
50
51
  if (newTargetCellPosition !== undefined) {
51
52
  const cells = getCellsInRow(dragMenuIndex)(tr.selection);
52
- if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)) {
53
+ // ED-20673 check if it is a cell selection,
54
+ // when true, a drag handle is clicked and isDragMenuOpen is true here
55
+ // should not close the drag menu.
56
+ const isCellSelection = tr.selection instanceof CellSelection;
57
+ if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
53
58
  return tr.setMeta(pluginKey, action);
54
59
  } // else NOP
55
60
  } else {
@@ -6,6 +6,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
7
7
  import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
8
8
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
9
+ import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
9
10
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
10
11
  import { getDragMenuConfig } from '../../utils/drag-menu';
11
12
  import { dragMenuDropdownWidth } from '../consts';
@@ -76,12 +77,37 @@ export const DragMenu = ({
76
77
  menuItems,
77
78
  menuCallback
78
79
  } = convertToDropdownItems(dragMenuConfig);
80
+
81
+ /**
82
+ * This function is to check if the menu should be closed or not.
83
+ * As when continously clicking on drag handle on different rows/columns,
84
+ * should open the menu corresponding to the position of the drag handle.
85
+ * @returns true when the menu should be closed, false otherwise
86
+ */
87
+ const shouldCloseMenu = state => {
88
+ let {
89
+ isDragMenuOpen: previousOpenState,
90
+ dragMenuDirection: previousDragMenuDirection,
91
+ dragMenuIndex: previousDragMenuIndex
92
+ } = getPluginState(state);
93
+
94
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
95
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
96
+ // 2 scenarios above , menu should not be closed.
97
+ if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
98
+ return false;
99
+ } else {
100
+ return true;
101
+ }
102
+ };
79
103
  const closeMenu = () => {
80
104
  const {
81
105
  state,
82
106
  dispatch
83
107
  } = editorView;
84
- toggleDragMenu(false)(state, dispatch);
108
+ if (shouldCloseMenu(state)) {
109
+ toggleDragMenu(false, direction, index)(state, dispatch);
110
+ }
85
111
  };
86
112
  const handleMenuItemActivated = ({
87
113
  item
@@ -82,17 +82,30 @@ export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, i
82
82
  return createCommand(function (state) {
83
83
  var _getPluginState3 = getPluginState(state),
84
84
  previousOpenState = _getPluginState3.isDragMenuOpen,
85
- dragMenuDirection = _getPluginState3.dragMenuDirection,
86
- dragMenuIndex = _getPluginState3.dragMenuIndex;
87
- if (previousOpenState === isDragMenuOpen) {
85
+ previousDragMenuDirection = _getPluginState3.dragMenuDirection,
86
+ previousDragMenuIndex = _getPluginState3.dragMenuIndex;
87
+ if (previousOpenState === isDragMenuOpen && previousDragMenuDirection === direction && previousDragMenuIndex === index) {
88
88
  return false;
89
89
  }
90
+ var updatedMenuOpenState;
91
+ if (isDragMenuOpen !== undefined) {
92
+ updatedMenuOpenState = isDragMenuOpen;
93
+ } else {
94
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
95
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
96
+ // 2 scenarios above , menu should remain open.
97
+ if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
98
+ updatedMenuOpenState = true;
99
+ } else {
100
+ updatedMenuOpenState = !previousOpenState;
101
+ }
102
+ }
90
103
  return {
91
104
  type: DragAndDropActionType.TOGGLE_DRAG_MENU,
92
105
  data: {
93
- isDragMenuOpen: isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
94
- direction: direction !== null && direction !== void 0 ? direction : dragMenuDirection,
95
- index: index !== null && index !== void 0 ? index : dragMenuIndex
106
+ isDragMenuOpen: updatedMenuOpenState,
107
+ direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
108
+ index: index !== null && index !== void 0 ? index : previousDragMenuIndex
96
109
  }
97
110
  };
98
111
  }, function (tr) {
@@ -1,6 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
5
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
5
6
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
7
  import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
@@ -49,7 +50,11 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
49
50
  };
50
51
  if (newTargetCellPosition !== undefined) {
51
52
  var cells = getCellsInRow(dragMenuIndex)(tr.selection);
52
- if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)) {
53
+ // ED-20673 check if it is a cell selection,
54
+ // when true, a drag handle is clicked and isDragMenuOpen is true here
55
+ // should not close the drag menu.
56
+ var isCellSelection = tr.selection instanceof CellSelection;
57
+ if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
53
58
  return tr.setMeta(pluginKey, action);
54
59
  } // else NOP
55
60
  } else {
@@ -7,6 +7,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
8
8
  import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
9
9
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
10
+ import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
10
11
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
11
12
  import { getDragMenuConfig } from '../../utils/drag-menu';
12
13
  import { dragMenuDropdownWidth } from '../consts';
@@ -76,10 +77,34 @@ export var DragMenu = function DragMenu(_ref) {
76
77
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
77
78
  menuItems = _convertToDropdownIte.menuItems,
78
79
  menuCallback = _convertToDropdownIte.menuCallback;
80
+
81
+ /**
82
+ * This function is to check if the menu should be closed or not.
83
+ * As when continously clicking on drag handle on different rows/columns,
84
+ * should open the menu corresponding to the position of the drag handle.
85
+ * @returns true when the menu should be closed, false otherwise
86
+ */
87
+ var shouldCloseMenu = function shouldCloseMenu(state) {
88
+ var _getPluginState = getPluginState(state),
89
+ previousOpenState = _getPluginState.isDragMenuOpen,
90
+ previousDragMenuDirection = _getPluginState.dragMenuDirection,
91
+ previousDragMenuIndex = _getPluginState.dragMenuIndex;
92
+
93
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
94
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
95
+ // 2 scenarios above , menu should not be closed.
96
+ if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
97
+ return false;
98
+ } else {
99
+ return true;
100
+ }
101
+ };
79
102
  var closeMenu = function closeMenu() {
80
103
  var state = editorView.state,
81
104
  dispatch = editorView.dispatch;
82
- toggleDragMenu(false)(state, dispatch);
105
+ if (shouldCloseMenu(state)) {
106
+ toggleDragMenu(false, direction, index)(state, dispatch);
107
+ }
83
108
  };
84
109
  var handleMenuItemActivated = function handleMenuItemActivated(_ref2) {
85
110
  var _menuCallback$item$va;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.25",
3
+ "version": "5.3.26",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^32.0.0",
31
31
  "@atlaskit/custom-steps": "^0.0.2",
32
- "@atlaskit/editor-common": "^76.18.0",
32
+ "@atlaskit/editor-common": "^76.19.0",
33
33
  "@atlaskit/editor-palette": "1.5.2",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.3.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -131,20 +131,44 @@ export const toggleDragMenu = (
131
131
  (state) => {
132
132
  let {
133
133
  isDragMenuOpen: previousOpenState,
134
- dragMenuDirection,
135
- dragMenuIndex,
134
+ dragMenuDirection: previousDragMenuDirection,
135
+ dragMenuIndex: previousDragMenuIndex,
136
136
  } = getPluginState(state);
137
- if (previousOpenState === isDragMenuOpen) {
137
+
138
+ if (
139
+ previousOpenState === isDragMenuOpen &&
140
+ previousDragMenuDirection === direction &&
141
+ previousDragMenuIndex === index
142
+ ) {
138
143
  return false;
139
144
  }
140
145
 
146
+ let updatedMenuOpenState;
147
+ if (isDragMenuOpen !== undefined) {
148
+ updatedMenuOpenState = isDragMenuOpen;
149
+ } else {
150
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
151
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
152
+ // 2 scenarios above , menu should remain open.
153
+ if (
154
+ (previousOpenState === true &&
155
+ previousDragMenuDirection !== direction) ||
156
+ (previousOpenState === true &&
157
+ previousDragMenuDirection === direction &&
158
+ previousDragMenuIndex !== index)
159
+ ) {
160
+ updatedMenuOpenState = true;
161
+ } else {
162
+ updatedMenuOpenState = !previousOpenState;
163
+ }
164
+ }
165
+
141
166
  return {
142
167
  type: DragAndDropActionType.TOGGLE_DRAG_MENU,
143
168
  data: {
144
- isDragMenuOpen:
145
- isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
146
- direction: direction ?? dragMenuDirection,
147
- index: index ?? dragMenuIndex,
169
+ isDragMenuOpen: updatedMenuOpenState,
170
+ direction: direction ?? previousDragMenuDirection,
171
+ index: index ?? previousDragMenuIndex,
148
172
  },
149
173
  };
150
174
  },
@@ -5,6 +5,7 @@ import type {
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
8
9
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
9
10
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
10
11
  import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
@@ -65,10 +66,15 @@ export const createPlugin = (
65
66
 
66
67
  if (newTargetCellPosition !== undefined) {
67
68
  const cells = getCellsInRow(dragMenuIndex)(tr.selection);
69
+ // ED-20673 check if it is a cell selection,
70
+ // when true, a drag handle is clicked and isDragMenuOpen is true here
71
+ // should not close the drag menu.
72
+ const isCellSelection = tr.selection instanceof CellSelection;
68
73
  if (
69
74
  cells &&
70
75
  cells.length &&
71
- cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)
76
+ cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) &&
77
+ !isCellSelection
72
78
  ) {
73
79
  return tr.setMeta(pluginKey, action);
74
80
  } // else NOP
@@ -11,6 +11,7 @@ import {
11
11
  } from '@atlaskit/editor-common/ui-menu';
12
12
  import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
13
13
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
14
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
14
15
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
15
16
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
16
17
  import { TableMap } from '@atlaskit/editor-tables/table-map';
@@ -23,6 +24,7 @@ import { token } from '@atlaskit/tokens';
23
24
 
24
25
  import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
25
26
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
27
+ import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
26
28
  import type { PluginConfig, TableDirection } from '../../types';
27
29
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
28
30
  import type { DragMenuConfig } from '../../utils/drag-menu';
@@ -132,9 +134,39 @@ export const DragMenu = ({
132
134
 
133
135
  const { menuItems, menuCallback } = convertToDropdownItems(dragMenuConfig);
134
136
 
137
+ /**
138
+ * This function is to check if the menu should be closed or not.
139
+ * As when continously clicking on drag handle on different rows/columns,
140
+ * should open the menu corresponding to the position of the drag handle.
141
+ * @returns true when the menu should be closed, false otherwise
142
+ */
143
+ const shouldCloseMenu = (state: EditorState) => {
144
+ let {
145
+ isDragMenuOpen: previousOpenState,
146
+ dragMenuDirection: previousDragMenuDirection,
147
+ dragMenuIndex: previousDragMenuIndex,
148
+ } = getPluginState(state);
149
+
150
+ // menu open but menu direction changed, means user clicked on drag handle of different row/column
151
+ // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
152
+ // 2 scenarios above , menu should not be closed.
153
+ if (
154
+ (previousOpenState === true && previousDragMenuDirection !== direction) ||
155
+ (previousOpenState === true &&
156
+ previousDragMenuDirection === direction &&
157
+ previousDragMenuIndex !== index)
158
+ ) {
159
+ return false;
160
+ } else {
161
+ return true;
162
+ }
163
+ };
164
+
135
165
  const closeMenu = () => {
136
166
  const { state, dispatch } = editorView;
137
- toggleDragMenu(false)(state, dispatch);
167
+ if (shouldCloseMenu(state)) {
168
+ toggleDragMenu(false, direction, index)(state, dispatch);
169
+ }
138
170
  };
139
171
 
140
172
  const handleMenuItemActivated = ({ item }: { item: MenuItem }) => {