@atlaskit/editor-plugin-table 7.2.2 → 7.2.3

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 (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  3. package/dist/cjs/utils/drag-menu.js +37 -23
  4. package/dist/cjs/utils/merged-cells.js +66 -1
  5. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  6. package/dist/es2019/utils/drag-menu.js +38 -14
  7. package/dist/es2019/utils/merged-cells.js +73 -0
  8. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  9. package/dist/esm/utils/drag-menu.js +36 -22
  10. package/dist/esm/utils/merged-cells.js +65 -0
  11. package/dist/types/utils/drag-menu.d.ts +4 -1
  12. package/dist/types/utils/merged-cells.d.ts +2 -0
  13. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  14. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  15. package/package.json +9 -16
  16. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  17. package/src/utils/drag-menu.ts +94 -20
  18. package/src/utils/merged-cells.ts +78 -0
  19. package/tsconfig.dev.json +0 -69
  20. package/tsconfig.json +2 -877
  21. package/examples/99-testing.tsx +0 -140
  22. package/examples/config.jsonc +0 -14
  23. package/src/__tests__/unit/analytics.ts +0 -888
  24. package/src/__tests__/unit/collab.ts +0 -93
  25. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  26. package/src/__tests__/unit/commands/insert.ts +0 -137
  27. package/src/__tests__/unit/commands/misc.ts +0 -185
  28. package/src/__tests__/unit/commands/sort.ts +0 -128
  29. package/src/__tests__/unit/commands.ts +0 -745
  30. package/src/__tests__/unit/copy-button.ts +0 -22
  31. package/src/__tests__/unit/copy-paste.ts +0 -677
  32. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  33. package/src/__tests__/unit/event-handlers.ts +0 -296
  34. package/src/__tests__/unit/fix-tables.ts +0 -164
  35. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  36. package/src/__tests__/unit/handlers.ts +0 -98
  37. package/src/__tests__/unit/hover-selection.ts +0 -230
  38. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  39. package/src/__tests__/unit/index.ts +0 -912
  40. package/src/__tests__/unit/layout.ts +0 -146
  41. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  42. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  43. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  44. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  45. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  46. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  47. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  48. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  49. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  50. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  51. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  52. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  53. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  54. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  55. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  56. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  57. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  58. package/src/__tests__/unit/sort-column.ts +0 -399
  59. package/src/__tests__/unit/toolbar.ts +0 -512
  60. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  61. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  62. package/src/__tests__/unit/transforms/merging.ts +0 -392
  63. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  64. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  65. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  66. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  67. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  68. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  69. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  70. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  71. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  72. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  73. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  74. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  75. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  76. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  77. package/src/__tests__/unit/undo-redo.ts +0 -220
  78. package/src/__tests__/unit/utils/analytics.ts +0 -98
  79. package/src/__tests__/unit/utils/collapse.ts +0 -57
  80. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  81. package/src/__tests__/unit/utils/dom.ts +0 -180
  82. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  83. package/src/__tests__/unit/utils/nodes.ts +0 -79
  84. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  85. package/src/__tests__/unit/utils/table.ts +0 -96
  86. package/src/__tests__/unit/utils.ts +0 -670
  87. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  88. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  89. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-should-remove-the-table-column-on-click-1-snap.png +0 -3
  90. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +0 -3
  91. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +0 -3
  92. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +0 -3
  93. package/src/__tests__/visual-regression/__image_snapshots__/copy-button-ts-floating-toolbar-copy-button-table-target-node-displays-blue-border-when-copy-button-is-hovered-1-snap.png +0 -3
  94. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-1-snap.png +0 -3
  95. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-2-snap.png +0 -3
  96. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-3-snap.png +0 -3
  97. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +0 -3
  98. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +0 -3
  99. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  100. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  101. package/src/__tests__/visual-regression/index.ts +0 -62
  102. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#68572](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/68572) [`15d407fe5143`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/15d407fe5143) - Upgrading @atlaskit/editor-prosemirror dependency
8
+ - [#70707](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70707) [`01c10b920070`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/01c10b920070) - [ux] Move options in drag menu now have disabled state when target has merged cells.
9
+ - Updated dependencies
10
+
3
11
  ## 7.2.2
4
12
 
5
13
  ### Patch Changes
@@ -11,6 +11,7 @@ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
11
11
  var _utils = require("@atlaskit/editor-tables/utils");
12
12
  var _utils2 = require("../../utils");
13
13
  var _analytics2 = require("../../utils/analytics");
14
+ var _dragMenu = require("../../utils/drag-menu");
14
15
  var _commands = require("./commands");
15
16
  var clearDropTargetWithAnalytics = exports.clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
16
17
  return function (inputMethod, sourceType, sourceIndexes, status, tr) {
@@ -91,30 +92,13 @@ var moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalyticsViaShort
91
92
  if (selectedIndexes.length === 0) {
92
93
  return false;
93
94
  }
94
-
95
- // const sourceIndex = selectedIndexes[0];
96
- // we can move only by one row/column
97
- // 'direction' can only be 1 (for right or down) or -1 (for left or up)
98
- var targetIndex = Math[direction < 0 ? 'min' : 'max'].apply(Math, (0, _toConsumableArray2.default)(selectedIndexes)) + direction;
99
-
100
- // We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
101
95
  var _getSelectedTableInfo3 = (0, _utils2.getSelectedTableInfo)(selection),
102
96
  totalRowCount = _getSelectedTableInfo3.totalRowCount,
103
97
  totalColumnCount = _getSelectedTableInfo3.totalColumnCount;
104
- var isValidTargetIndex = targetIndex < 0 ? false : isRow ? targetIndex <= totalRowCount - 1 : targetIndex <= totalColumnCount - 1;
105
- if (!isValidTargetIndex) {
106
- return false;
107
- }
108
-
109
- // We can move only if there are no merged cells in the source or target row/column
110
- var hasMergedCellsInSource = isRow ? (0, _utils2.hasMergedCellsInRow)(selectedIndexes)(selection) : (0, _utils2.hasMergedCellsInColumn)(selectedIndexes)(selection);
111
- if (hasMergedCellsInSource) {
112
- return false;
113
- }
114
- var hasMergedCellsInTarget = isRow ? (0, _utils2.hasMergedCellsInRow)(targetIndex)(selection) : (0, _utils2.hasMergedCellsInColumn)(targetIndex)(selection);
115
- if (hasMergedCellsInTarget) {
98
+ if (!(0, _dragMenu.canMove)(sourceType, direction, isRow ? totalRowCount : totalColumnCount, selection, selectionRect)) {
116
99
  return false;
117
100
  }
101
+ var targetIndex = (0, _dragMenu.getTargetIndex)(selectedIndexes, direction);
118
102
  return moveSourceWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
119
103
  };
120
104
  };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getDragMenuConfig = void 0;
7
+ exports.getTargetIndex = exports.getDragMenuConfig = exports.canMove = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _customSteps = require("@atlaskit/custom-steps");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -26,14 +26,36 @@ var _resizeState = require("../pm-plugins/table-resizing/utils/resize-state");
26
26
  var _toolbar = require("../toolbar");
27
27
  var _transforms = require("../transforms");
28
28
  var _icons = require("../ui/icons");
29
+ var _mergedCells = require("./merged-cells");
29
30
  var _selection = require("./selection");
30
- var canDecrease = function canDecrease(index) {
31
- var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
32
- return index !== undefined && index > min;
31
+ var getTargetIndex = exports.getTargetIndex = function getTargetIndex(selectedIndexes, direction) {
32
+ return Math[direction < 0 ? 'min' : 'max'].apply(Math, (0, _toConsumableArray2.default)(selectedIndexes)) + direction;
33
33
  };
34
- var canIncrease = function canIncrease(index) {
35
- var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
36
- return index !== undefined && index < max;
34
+ var canMove = exports.canMove = function canMove(sourceType, direction, totalItemsOfSourceTypeCount, selection, selectionRect) {
35
+ if (!selectionRect) {
36
+ return false;
37
+ }
38
+ var isRow = sourceType === 'table-row';
39
+ var selectedIndexes = isRow ? (0, _selection.getSelectedRowIndexes)(selectionRect) : (0, _selection.getSelectedColumnIndexes)(selectionRect);
40
+ var targetIndex = getTargetIndex(selectedIndexes, direction);
41
+ var isValidTargetIndex = targetIndex >= 0 && targetIndex < totalItemsOfSourceTypeCount;
42
+ if (!isValidTargetIndex) {
43
+ return false;
44
+ }
45
+
46
+ // We can't move column when target has merges with other columns
47
+ // We can't move row when target has merges with other rows
48
+ var hasMergedCellsInTarget = isRow ? (0, _mergedCells.hasMergedCellsWithRowNextToRowIndex)(targetIndex, selection) : (0, _mergedCells.hasMergedCellsWithColumnNextToColumnIndex)(targetIndex, selection);
49
+ if (hasMergedCellsInTarget) {
50
+ return false;
51
+ }
52
+
53
+ // Currently we can't move in any direction if there are merged cells in the source
54
+ var hasMergedCellsInSource = isRow ? (0, _mergedCells.hasMergedCellsInRow)(selectedIndexes)(selection) : (0, _mergedCells.hasMergedCellsInColumn)(selectedIndexes)(selection);
55
+ if (hasMergedCellsInSource) {
56
+ return false;
57
+ }
58
+ return true;
37
59
  };
38
60
  var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
39
61
  var rect = (0, _toolbar.getClosestSelectionRect)(state);
@@ -44,6 +66,7 @@ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
44
66
  return false;
45
67
  };
46
68
  var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI) {
69
+ var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
47
70
  var addOptions = direction === 'row' ? [{
48
71
  label: 'above',
49
72
  offset: 0,
@@ -65,13 +88,12 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
65
88
  icon: _icons.AddColRightIcon,
66
89
  keymap: _keymaps.addColumnAfter
67
90
  }];
91
+ var selection = editorView.state.selection;
68
92
  var moveOptions = direction === 'row' ? [{
69
93
  label: 'up',
70
94
  icon: _arrowUp.default,
71
95
  keymap: _keymaps.moveRowUp,
72
- canMove: function canMove(selectionRect) {
73
- return canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top);
74
- },
96
+ canMove: canDrag && canMove('table-row', -1, (_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0, selection, selectionRect),
75
97
  getOriginIndexes: _selection.getSelectedRowIndexes,
76
98
  getTargetIndex: function getTargetIndex(selectionRect) {
77
99
  return selectionRect.top - 1;
@@ -80,10 +102,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
80
102
  label: 'down',
81
103
  icon: _arrowDown.default,
82
104
  keymap: _keymaps.moveRowDown,
83
- canMove: function canMove(selectionRect) {
84
- var _selectionRect$bottom, _tableMap$height;
85
- return canDrag && canIncrease(((_selectionRect$bottom = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom) !== null && _selectionRect$bottom !== void 0 ? _selectionRect$bottom : 0) - 1, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
86
- },
105
+ canMove: canDrag && canMove('table-row', 1, (_tableMap$height2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height2 !== void 0 ? _tableMap$height2 : 0, selection, selectionRect),
87
106
  getOriginIndexes: _selection.getSelectedRowIndexes,
88
107
  getTargetIndex: function getTargetIndex(selectionRect) {
89
108
  return selectionRect.bottom;
@@ -92,9 +111,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
92
111
  label: 'left',
93
112
  icon: _arrowLeft.default,
94
113
  keymap: _keymaps.moveColumnLeft,
95
- canMove: function canMove(selectionRect) {
96
- return canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left);
97
- },
114
+ canMove: canDrag && canMove('table-column', -1, (_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0, selection, selectionRect),
98
115
  getOriginIndexes: _selection.getSelectedColumnIndexes,
99
116
  getTargetIndex: function getTargetIndex(selectionRect) {
100
117
  return selectionRect.left - 1;
@@ -103,10 +120,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
103
120
  label: 'right',
104
121
  icon: _arrowRight.default,
105
122
  keymap: _keymaps.moveColumnRight,
106
- canMove: function canMove(selectionRect) {
107
- var _selectionRect$right, _tableMap$width;
108
- return canDrag && canIncrease(((_selectionRect$right = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right) !== null && _selectionRect$right !== void 0 ? _selectionRect$right : 0) - 1, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
109
- },
123
+ canMove: canDrag && canMove('table-column', 1, (_tableMap$width2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width2 !== void 0 ? _tableMap$width2 : 0, selection, selectionRect),
110
124
  getOriginIndexes: _selection.getSelectedColumnIndexes,
111
125
  getTargetIndex: function getTargetIndex(selectionRect) {
112
126
  return selectionRect.right;
@@ -191,10 +205,10 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
191
205
  return {
192
206
  id: "move_".concat(direction, "_").concat(label),
193
207
  title: "Move ".concat(direction, " ").concat(label),
194
- disabled: !canMove(selectionRect),
208
+ disabled: !canMove,
195
209
  icon: icon,
196
210
  onClick: function onClick(state, dispatch) {
197
- if (canMove(selectionRect)) {
211
+ if (canMove) {
198
212
  requestAnimationFrame(function () {
199
213
  (0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), getOriginIndexes(selectionRect), getTargetIndex(selectionRect))(editorView.state, editorView.dispatch);
200
214
  });
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.hasMergedCellsInRow = exports.hasMergedCellsInColumn = exports.hasMergedCellsInBetween = void 0;
7
+ exports.hasMergedCellsWithRowNextToRowIndex = exports.hasMergedCellsWithColumnNextToColumnIndex = exports.hasMergedCellsInRow = exports.hasMergedCellsInColumn = exports.hasMergedCellsInBetween = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _editorTables = require("@atlaskit/editor-tables");
10
10
  var hasMergedCells = function hasMergedCells(indexes, normalizeRect) {
@@ -137,4 +137,69 @@ var hasMergedCellsInBetween = exports.hasMergedCellsInBetween = function hasMerg
137
137
  return mergedCellsInRectArr[1].includes(cell);
138
138
  });
139
139
  };
140
+ };
141
+
142
+ // Checks if any cell in the column with colIndex is merged with a cell in a column to the left or to the right of it.
143
+ // colIndex is a logical index of the column. It starts at 0 and goes up to tableMap.width - 1.
144
+ var hasMergedCellsWithColumnNextToColumnIndex = exports.hasMergedCellsWithColumnNextToColumnIndex = function hasMergedCellsWithColumnNextToColumnIndex(colIndex, selection) {
145
+ var table = (0, _editorTables.findTable)(selection);
146
+ if (!table) {
147
+ return false;
148
+ }
149
+ var tableMap = _editorTables.TableMap.get(table.node);
150
+ var width = tableMap.width;
151
+ if (width <= 1) {
152
+ return false;
153
+ }
154
+ if (colIndex < 0 || colIndex > width - 1) {
155
+ return false;
156
+ }
157
+ var map = tableMap.map;
158
+ // j is an index in the tableMap.map array. tableMap.map is a flat array.
159
+ // Each item of this array contains a number.
160
+ // The number represents the position of the corresponding cell in the tableMap. It exists for each cell.
161
+ // If there are merged cells, their positions will be represented by the same number.
162
+ var isFirstColumn = colIndex === 0;
163
+ var isLastColumn = colIndex === width - 1;
164
+ for (var j = colIndex; j < map.length; j += width) {
165
+ if (!isFirstColumn && map[j] === map[j - 1] ||
166
+ // compare with a cell in the column on the left
167
+ !isLastColumn && map[j] === map[j + 1] // compare with a cell in the column on the right
168
+ ) {
169
+ return true;
170
+ }
171
+ }
172
+ return false;
173
+ };
174
+
175
+ // Checks if any cell in the row with rowIndex is merged with a cell in a row above or below it.
176
+ var hasMergedCellsWithRowNextToRowIndex = exports.hasMergedCellsWithRowNextToRowIndex = function hasMergedCellsWithRowNextToRowIndex(rowIndex, selection) {
177
+ var table = (0, _editorTables.findTable)(selection);
178
+ if (!table) {
179
+ return false;
180
+ }
181
+ var tableMap = _editorTables.TableMap.get(table.node);
182
+ var height = tableMap.height;
183
+ if (height <= 1) {
184
+ return false;
185
+ }
186
+ if (rowIndex < 0 || rowIndex > height - 1) {
187
+ return false;
188
+ }
189
+ var map = tableMap.map,
190
+ width = tableMap.width; // map is a flat array representing position of each cell in the table.
191
+ var indexOfFirstCellInTheRow = rowIndex * width;
192
+ var indexOfLastCellInTheRow = indexOfFirstCellInTheRow + width - 1;
193
+ var isFirstRow = rowIndex === 0;
194
+ var isLastRow = rowIndex === height - 1;
195
+ // j is an index of a cell in a row
196
+ for (var j = indexOfFirstCellInTheRow; j <= indexOfLastCellInTheRow; j++) {
197
+ if (!isFirstRow && map[j] === map[j - width] ||
198
+ // compare with a cell in the row above
199
+ !isLastRow && map[j] === map[j + width] // compare with a cell in the row below
200
+ ) {
201
+ return true;
202
+ }
203
+ }
204
+ return false;
140
205
  };
@@ -1,8 +1,9 @@
1
1
  import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
2
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
3
3
  import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
4
- import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
4
+ import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo } from '../../utils';
5
5
  import { withEditorAnalyticsAPI } from '../../utils/analytics';
6
+ import { canMove, getTargetIndex } from '../../utils/drag-menu';
6
7
  import { clearDropTarget, moveSource } from './commands';
7
8
  export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, sourceIndexes, status, tr) => {
8
9
  return withEditorAnalyticsAPI(({
@@ -81,30 +82,13 @@ export const moveSourceWithAnalyticsViaShortcut = editorAnalyticsAPI => (sourceT
81
82
  if (selectedIndexes.length === 0) {
82
83
  return false;
83
84
  }
84
-
85
- // const sourceIndex = selectedIndexes[0];
86
- // we can move only by one row/column
87
- // 'direction' can only be 1 (for right or down) or -1 (for left or up)
88
- const targetIndex = Math[direction < 0 ? 'min' : 'max'](...selectedIndexes) + direction;
89
-
90
- // We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
91
85
  const {
92
86
  totalRowCount,
93
87
  totalColumnCount
94
88
  } = getSelectedTableInfo(selection);
95
- const isValidTargetIndex = targetIndex < 0 ? false : isRow ? targetIndex <= totalRowCount - 1 : targetIndex <= totalColumnCount - 1;
96
- if (!isValidTargetIndex) {
97
- return false;
98
- }
99
-
100
- // We can move only if there are no merged cells in the source or target row/column
101
- const hasMergedCellsInSource = isRow ? hasMergedCellsInRow(selectedIndexes)(selection) : hasMergedCellsInColumn(selectedIndexes)(selection);
102
- if (hasMergedCellsInSource) {
103
- return false;
104
- }
105
- const hasMergedCellsInTarget = isRow ? hasMergedCellsInRow(targetIndex)(selection) : hasMergedCellsInColumn(targetIndex)(selection);
106
- if (hasMergedCellsInTarget) {
89
+ if (!canMove(sourceType, direction, isRow ? totalRowCount : totalColumnCount, selection, selectionRect)) {
107
90
  return false;
108
91
  }
92
+ const targetIndex = getTargetIndex(selectedIndexes, direction);
109
93
  return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
110
94
  };
@@ -18,9 +18,35 @@ import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizi
18
18
  import { getClosestSelectionRect } from '../toolbar';
19
19
  import { deleteRows } from '../transforms';
20
20
  import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
21
+ import { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsWithColumnNextToColumnIndex, hasMergedCellsWithRowNextToRowIndex } from './merged-cells';
21
22
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from './selection';
22
- const canDecrease = (index, min = 0) => index !== undefined && index > min;
23
- const canIncrease = (index, max = 0) => index !== undefined && index < max;
23
+ export const getTargetIndex = (selectedIndexes, direction) => Math[direction < 0 ? 'min' : 'max'](...selectedIndexes) + direction;
24
+ export const canMove = (sourceType, direction, totalItemsOfSourceTypeCount, selection, selectionRect) => {
25
+ if (!selectionRect) {
26
+ return false;
27
+ }
28
+ const isRow = sourceType === 'table-row';
29
+ const selectedIndexes = isRow ? getSelectedRowIndexes(selectionRect) : getSelectedColumnIndexes(selectionRect);
30
+ const targetIndex = getTargetIndex(selectedIndexes, direction);
31
+ const isValidTargetIndex = targetIndex >= 0 && targetIndex < totalItemsOfSourceTypeCount;
32
+ if (!isValidTargetIndex) {
33
+ return false;
34
+ }
35
+
36
+ // We can't move column when target has merges with other columns
37
+ // We can't move row when target has merges with other rows
38
+ const hasMergedCellsInTarget = isRow ? hasMergedCellsWithRowNextToRowIndex(targetIndex, selection) : hasMergedCellsWithColumnNextToColumnIndex(targetIndex, selection);
39
+ if (hasMergedCellsInTarget) {
40
+ return false;
41
+ }
42
+
43
+ // Currently we can't move in any direction if there are merged cells in the source
44
+ const hasMergedCellsInSource = isRow ? hasMergedCellsInRow(selectedIndexes)(selection) : hasMergedCellsInColumn(selectedIndexes)(selection);
45
+ if (hasMergedCellsInSource) {
46
+ return false;
47
+ }
48
+ return true;
49
+ };
24
50
  const isDistributeColumnsEnabled = state => {
25
51
  const rect = getClosestSelectionRect(state);
26
52
  if (rect) {
@@ -30,6 +56,7 @@ const isDistributeColumnsEnabled = state => {
30
56
  return false;
31
57
  };
32
58
  export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI) => {
59
+ var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
33
60
  const addOptions = direction === 'row' ? [{
34
61
  label: 'above',
35
62
  offset: 0,
@@ -51,38 +78,35 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
51
78
  icon: AddColRightIcon,
52
79
  keymap: addColumnAfter
53
80
  }];
81
+ const {
82
+ selection
83
+ } = editorView.state;
54
84
  const moveOptions = direction === 'row' ? [{
55
85
  label: 'up',
56
86
  icon: ArrowUpIcon,
57
87
  keymap: moveRowUp,
58
- canMove: selectionRect => canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top),
88
+ canMove: canDrag && canMove('table-row', -1, (_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0, selection, selectionRect),
59
89
  getOriginIndexes: getSelectedRowIndexes,
60
90
  getTargetIndex: selectionRect => selectionRect.top - 1
61
91
  }, {
62
92
  label: 'down',
63
93
  icon: ArrowDownIcon,
64
94
  keymap: moveRowDown,
65
- canMove: selectionRect => {
66
- var _selectionRect$bottom, _tableMap$height;
67
- return canDrag && canIncrease(((_selectionRect$bottom = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom) !== null && _selectionRect$bottom !== void 0 ? _selectionRect$bottom : 0) - 1, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
68
- },
95
+ canMove: canDrag && canMove('table-row', 1, (_tableMap$height2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height2 !== void 0 ? _tableMap$height2 : 0, selection, selectionRect),
69
96
  getOriginIndexes: getSelectedRowIndexes,
70
97
  getTargetIndex: selectionRect => selectionRect.bottom
71
98
  }] : [{
72
99
  label: 'left',
73
100
  icon: ArrowLeftIcon,
74
101
  keymap: moveColumnLeft,
75
- canMove: selectionRect => canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left),
102
+ canMove: canDrag && canMove('table-column', -1, (_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0, selection, selectionRect),
76
103
  getOriginIndexes: getSelectedColumnIndexes,
77
104
  getTargetIndex: selectionRect => selectionRect.left - 1
78
105
  }, {
79
106
  label: 'right',
80
107
  icon: ArrowRightIcon,
81
108
  keymap: moveColumnRight,
82
- canMove: selectionRect => {
83
- var _selectionRect$right, _tableMap$width;
84
- return canDrag && canIncrease(((_selectionRect$right = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right) !== null && _selectionRect$right !== void 0 ? _selectionRect$right : 0) - 1, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
85
- },
109
+ canMove: canDrag && canMove('table-column', 1, (_tableMap$width2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width2 !== void 0 ? _tableMap$width2 : 0, selection, selectionRect),
86
110
  getOriginIndexes: getSelectedColumnIndexes,
87
111
  getTargetIndex: selectionRect => selectionRect.right
88
112
  }];
@@ -166,10 +190,10 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
166
190
  }) => ({
167
191
  id: `move_${direction}_${label}`,
168
192
  title: `Move ${direction} ${label}`,
169
- disabled: !canMove(selectionRect),
193
+ disabled: !canMove,
170
194
  icon,
171
195
  onClick: (state, dispatch) => {
172
- if (canMove(selectionRect)) {
196
+ if (canMove) {
173
197
  requestAnimationFrame(() => {
174
198
  moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, `table-${direction}`, getOriginIndexes(selectionRect), getTargetIndex(selectionRect))(editorView.state, editorView.dispatch);
175
199
  });
@@ -107,4 +107,77 @@ export const hasMergedCellsInBetween = (indexes, type) => selection => {
107
107
 
108
108
  // Currently only support 2 indexes, but we can extend this to support more indexes in the future.
109
109
  return mergedCellsInRectArr[0].some(cell => mergedCellsInRectArr[1].includes(cell));
110
+ };
111
+
112
+ // Checks if any cell in the column with colIndex is merged with a cell in a column to the left or to the right of it.
113
+ // colIndex is a logical index of the column. It starts at 0 and goes up to tableMap.width - 1.
114
+ export const hasMergedCellsWithColumnNextToColumnIndex = (colIndex, selection) => {
115
+ const table = findTable(selection);
116
+ if (!table) {
117
+ return false;
118
+ }
119
+ const tableMap = TableMap.get(table.node);
120
+ const {
121
+ width
122
+ } = tableMap;
123
+ if (width <= 1) {
124
+ return false;
125
+ }
126
+ if (colIndex < 0 || colIndex > width - 1) {
127
+ return false;
128
+ }
129
+ const {
130
+ map
131
+ } = tableMap;
132
+ // j is an index in the tableMap.map array. tableMap.map is a flat array.
133
+ // Each item of this array contains a number.
134
+ // The number represents the position of the corresponding cell in the tableMap. It exists for each cell.
135
+ // If there are merged cells, their positions will be represented by the same number.
136
+ const isFirstColumn = colIndex === 0;
137
+ const isLastColumn = colIndex === width - 1;
138
+ for (let j = colIndex; j < map.length; j += width) {
139
+ if (!isFirstColumn && map[j] === map[j - 1] ||
140
+ // compare with a cell in the column on the left
141
+ !isLastColumn && map[j] === map[j + 1] // compare with a cell in the column on the right
142
+ ) {
143
+ return true;
144
+ }
145
+ }
146
+ return false;
147
+ };
148
+
149
+ // Checks if any cell in the row with rowIndex is merged with a cell in a row above or below it.
150
+ export const hasMergedCellsWithRowNextToRowIndex = (rowIndex, selection) => {
151
+ const table = findTable(selection);
152
+ if (!table) {
153
+ return false;
154
+ }
155
+ const tableMap = TableMap.get(table.node);
156
+ const {
157
+ height
158
+ } = tableMap;
159
+ if (height <= 1) {
160
+ return false;
161
+ }
162
+ if (rowIndex < 0 || rowIndex > height - 1) {
163
+ return false;
164
+ }
165
+ const {
166
+ map,
167
+ width
168
+ } = tableMap; // map is a flat array representing position of each cell in the table.
169
+ const indexOfFirstCellInTheRow = rowIndex * width;
170
+ const indexOfLastCellInTheRow = indexOfFirstCellInTheRow + width - 1;
171
+ const isFirstRow = rowIndex === 0;
172
+ const isLastRow = rowIndex === height - 1;
173
+ // j is an index of a cell in a row
174
+ for (let j = indexOfFirstCellInTheRow; j <= indexOfLastCellInTheRow; j++) {
175
+ if (!isFirstRow && map[j] === map[j - width] ||
176
+ // compare with a cell in the row above
177
+ !isLastRow && map[j] === map[j + width] // compare with a cell in the row below
178
+ ) {
179
+ return true;
180
+ }
181
+ }
182
+ return false;
110
183
  };
@@ -2,8 +2,9 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
3
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
5
- import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
5
+ import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo } from '../../utils';
6
6
  import { withEditorAnalyticsAPI } from '../../utils/analytics';
7
+ import { canMove, getTargetIndex } from '../../utils/drag-menu';
7
8
  import { clearDropTarget, moveSource } from './commands';
8
9
  export var clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
9
10
  return function (inputMethod, sourceType, sourceIndexes, status, tr) {
@@ -84,30 +85,13 @@ export var moveSourceWithAnalyticsViaShortcut = function moveSourceWithAnalytics
84
85
  if (selectedIndexes.length === 0) {
85
86
  return false;
86
87
  }
87
-
88
- // const sourceIndex = selectedIndexes[0];
89
- // we can move only by one row/column
90
- // 'direction' can only be 1 (for right or down) or -1 (for left or up)
91
- var targetIndex = Math[direction < 0 ? 'min' : 'max'].apply(Math, _toConsumableArray(selectedIndexes)) + direction;
92
-
93
- // We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
94
88
  var _getSelectedTableInfo3 = getSelectedTableInfo(selection),
95
89
  totalRowCount = _getSelectedTableInfo3.totalRowCount,
96
90
  totalColumnCount = _getSelectedTableInfo3.totalColumnCount;
97
- var isValidTargetIndex = targetIndex < 0 ? false : isRow ? targetIndex <= totalRowCount - 1 : targetIndex <= totalColumnCount - 1;
98
- if (!isValidTargetIndex) {
99
- return false;
100
- }
101
-
102
- // We can move only if there are no merged cells in the source or target row/column
103
- var hasMergedCellsInSource = isRow ? hasMergedCellsInRow(selectedIndexes)(selection) : hasMergedCellsInColumn(selectedIndexes)(selection);
104
- if (hasMergedCellsInSource) {
105
- return false;
106
- }
107
- var hasMergedCellsInTarget = isRow ? hasMergedCellsInRow(targetIndex)(selection) : hasMergedCellsInColumn(targetIndex)(selection);
108
- if (hasMergedCellsInTarget) {
91
+ if (!canMove(sourceType, direction, isRow ? totalRowCount : totalColumnCount, selection, selectionRect)) {
109
92
  return false;
110
93
  }
94
+ var targetIndex = getTargetIndex(selectedIndexes, direction);
111
95
  return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
112
96
  };
113
97
  };
@@ -19,14 +19,36 @@ import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizi
19
19
  import { getClosestSelectionRect } from '../toolbar';
20
20
  import { deleteRows } from '../transforms';
21
21
  import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
22
+ import { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsWithColumnNextToColumnIndex, hasMergedCellsWithRowNextToRowIndex } from './merged-cells';
22
23
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from './selection';
23
- var canDecrease = function canDecrease(index) {
24
- var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
25
- return index !== undefined && index > min;
24
+ export var getTargetIndex = function getTargetIndex(selectedIndexes, direction) {
25
+ return Math[direction < 0 ? 'min' : 'max'].apply(Math, _toConsumableArray(selectedIndexes)) + direction;
26
26
  };
27
- var canIncrease = function canIncrease(index) {
28
- var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
29
- return index !== undefined && index < max;
27
+ export var canMove = function canMove(sourceType, direction, totalItemsOfSourceTypeCount, selection, selectionRect) {
28
+ if (!selectionRect) {
29
+ return false;
30
+ }
31
+ var isRow = sourceType === 'table-row';
32
+ var selectedIndexes = isRow ? getSelectedRowIndexes(selectionRect) : getSelectedColumnIndexes(selectionRect);
33
+ var targetIndex = getTargetIndex(selectedIndexes, direction);
34
+ var isValidTargetIndex = targetIndex >= 0 && targetIndex < totalItemsOfSourceTypeCount;
35
+ if (!isValidTargetIndex) {
36
+ return false;
37
+ }
38
+
39
+ // We can't move column when target has merges with other columns
40
+ // We can't move row when target has merges with other rows
41
+ var hasMergedCellsInTarget = isRow ? hasMergedCellsWithRowNextToRowIndex(targetIndex, selection) : hasMergedCellsWithColumnNextToColumnIndex(targetIndex, selection);
42
+ if (hasMergedCellsInTarget) {
43
+ return false;
44
+ }
45
+
46
+ // Currently we can't move in any direction if there are merged cells in the source
47
+ var hasMergedCellsInSource = isRow ? hasMergedCellsInRow(selectedIndexes)(selection) : hasMergedCellsInColumn(selectedIndexes)(selection);
48
+ if (hasMergedCellsInSource) {
49
+ return false;
50
+ }
51
+ return true;
30
52
  };
31
53
  var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
32
54
  var rect = getClosestSelectionRect(state);
@@ -37,6 +59,7 @@ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
37
59
  return false;
38
60
  };
39
61
  export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI) {
62
+ var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
40
63
  var addOptions = direction === 'row' ? [{
41
64
  label: 'above',
42
65
  offset: 0,
@@ -58,13 +81,12 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
58
81
  icon: AddColRightIcon,
59
82
  keymap: addColumnAfter
60
83
  }];
84
+ var selection = editorView.state.selection;
61
85
  var moveOptions = direction === 'row' ? [{
62
86
  label: 'up',
63
87
  icon: ArrowUpIcon,
64
88
  keymap: moveRowUp,
65
- canMove: function canMove(selectionRect) {
66
- return canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top);
67
- },
89
+ canMove: canDrag && canMove('table-row', -1, (_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0, selection, selectionRect),
68
90
  getOriginIndexes: getSelectedRowIndexes,
69
91
  getTargetIndex: function getTargetIndex(selectionRect) {
70
92
  return selectionRect.top - 1;
@@ -73,10 +95,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
73
95
  label: 'down',
74
96
  icon: ArrowDownIcon,
75
97
  keymap: moveRowDown,
76
- canMove: function canMove(selectionRect) {
77
- var _selectionRect$bottom, _tableMap$height;
78
- return canDrag && canIncrease(((_selectionRect$bottom = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom) !== null && _selectionRect$bottom !== void 0 ? _selectionRect$bottom : 0) - 1, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
79
- },
98
+ canMove: canDrag && canMove('table-row', 1, (_tableMap$height2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height2 !== void 0 ? _tableMap$height2 : 0, selection, selectionRect),
80
99
  getOriginIndexes: getSelectedRowIndexes,
81
100
  getTargetIndex: function getTargetIndex(selectionRect) {
82
101
  return selectionRect.bottom;
@@ -85,9 +104,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
85
104
  label: 'left',
86
105
  icon: ArrowLeftIcon,
87
106
  keymap: moveColumnLeft,
88
- canMove: function canMove(selectionRect) {
89
- return canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left);
90
- },
107
+ canMove: canDrag && canMove('table-column', -1, (_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0, selection, selectionRect),
91
108
  getOriginIndexes: getSelectedColumnIndexes,
92
109
  getTargetIndex: function getTargetIndex(selectionRect) {
93
110
  return selectionRect.left - 1;
@@ -96,10 +113,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
96
113
  label: 'right',
97
114
  icon: ArrowRightIcon,
98
115
  keymap: moveColumnRight,
99
- canMove: function canMove(selectionRect) {
100
- var _selectionRect$right, _tableMap$width;
101
- return canDrag && canIncrease(((_selectionRect$right = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right) !== null && _selectionRect$right !== void 0 ? _selectionRect$right : 0) - 1, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
102
- },
116
+ canMove: canDrag && canMove('table-column', 1, (_tableMap$width2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width2 !== void 0 ? _tableMap$width2 : 0, selection, selectionRect),
103
117
  getOriginIndexes: getSelectedColumnIndexes,
104
118
  getTargetIndex: function getTargetIndex(selectionRect) {
105
119
  return selectionRect.right;
@@ -184,10 +198,10 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
184
198
  return {
185
199
  id: "move_".concat(direction, "_").concat(label),
186
200
  title: "Move ".concat(direction, " ").concat(label),
187
- disabled: !canMove(selectionRect),
201
+ disabled: !canMove,
188
202
  icon: icon,
189
203
  onClick: function onClick(state, dispatch) {
190
- if (canMove(selectionRect)) {
204
+ if (canMove) {
191
205
  requestAnimationFrame(function () {
192
206
  moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), getOriginIndexes(selectionRect), getTargetIndex(selectionRect))(editorView.state, editorView.dispatch);
193
207
  });