@atlaskit/editor-plugin-table 24.2.2 → 24.2.4

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 (59) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/pm-plugins/commands/active-table-menu.js +14 -5
  3. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +3 -1
  4. package/dist/cjs/pm-plugins/main.js +3 -1
  5. package/dist/cjs/pm-plugins/utils/column-controls.js +119 -2
  6. package/dist/cjs/pm-plugins/utils/dom.js +23 -1
  7. package/dist/cjs/pm-plugins/utils/row-controls.js +43 -1
  8. package/dist/cjs/pm-plugins/utils/selection.js +74 -1
  9. package/dist/cjs/ui/DragHandle/index.js +46 -4
  10. package/dist/cjs/ui/FloatingInsertButton/getPopupOptions.js +19 -5
  11. package/dist/cjs/ui/FloatingInsertButton/index.js +37 -3
  12. package/dist/cjs/ui/FloatingTableMenu/index.js +4 -7
  13. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +26 -15
  14. package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -1
  15. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +29 -12
  16. package/dist/cjs/ui/common-styles.js +6 -1
  17. package/dist/cjs/ui/event-handlers.js +61 -8
  18. package/dist/es2019/pm-plugins/commands/active-table-menu.js +14 -5
  19. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +3 -1
  20. package/dist/es2019/pm-plugins/main.js +1 -1
  21. package/dist/es2019/pm-plugins/utils/column-controls.js +114 -2
  22. package/dist/es2019/pm-plugins/utils/dom.js +20 -0
  23. package/dist/es2019/pm-plugins/utils/row-controls.js +42 -0
  24. package/dist/es2019/pm-plugins/utils/selection.js +73 -0
  25. package/dist/es2019/ui/DragHandle/index.js +47 -4
  26. package/dist/es2019/ui/FloatingInsertButton/getPopupOptions.js +24 -5
  27. package/dist/es2019/ui/FloatingInsertButton/index.js +35 -3
  28. package/dist/es2019/ui/FloatingTableMenu/index.js +4 -7
  29. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +27 -16
  30. package/dist/es2019/ui/TableFloatingColumnControls/index.js +2 -2
  31. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +30 -12
  32. package/dist/es2019/ui/common-styles.js +26 -1
  33. package/dist/es2019/ui/event-handlers.js +61 -8
  34. package/dist/esm/pm-plugins/commands/active-table-menu.js +14 -5
  35. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +3 -1
  36. package/dist/esm/pm-plugins/main.js +3 -1
  37. package/dist/esm/pm-plugins/utils/column-controls.js +118 -1
  38. package/dist/esm/pm-plugins/utils/dom.js +22 -0
  39. package/dist/esm/pm-plugins/utils/row-controls.js +42 -0
  40. package/dist/esm/pm-plugins/utils/selection.js +73 -0
  41. package/dist/esm/ui/DragHandle/index.js +47 -5
  42. package/dist/esm/ui/FloatingInsertButton/getPopupOptions.js +19 -5
  43. package/dist/esm/ui/FloatingInsertButton/index.js +37 -3
  44. package/dist/esm/ui/FloatingTableMenu/index.js +4 -7
  45. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +28 -17
  46. package/dist/esm/ui/TableFloatingColumnControls/index.js +2 -2
  47. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +31 -14
  48. package/dist/esm/ui/common-styles.js +7 -2
  49. package/dist/esm/ui/event-handlers.js +63 -10
  50. package/dist/types/pm-plugins/commands/active-table-menu.d.ts +3 -1
  51. package/dist/types/pm-plugins/utils/column-controls.d.ts +35 -1
  52. package/dist/types/pm-plugins/utils/dom.d.ts +11 -0
  53. package/dist/types/pm-plugins/utils/row-controls.d.ts +16 -0
  54. package/dist/types/pm-plugins/utils/selection.d.ts +20 -0
  55. package/dist/types/ui/DragHandle/index.d.ts +3 -2
  56. package/dist/types/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
  57. package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -0
  58. package/dist/types/ui/event-handlers.d.ts +1 -1
  59. package/package.json +4 -4
@@ -33,6 +33,73 @@ export var getColumnsWidths = function getColumnsWidths(view) {
33
33
  }
34
34
  return widths;
35
35
  };
36
+
37
+ /**
38
+ * Splits a merged cell's rendered width by `colwidth` ratios, falling back to an even split when
39
+ * usable ratios are unavailable.
40
+ */
41
+ export var getProportionalColumnWidths = function getProportionalColumnWidths(totalWidth, columnCount, ratios) {
42
+ var evenSplit = function evenSplit() {
43
+ return new Array(columnCount).fill(totalWidth / columnCount);
44
+ };
45
+ if (!ratios || ratios.length !== columnCount) {
46
+ return evenSplit();
47
+ }
48
+ var total = ratios.reduce(function (sum, ratio) {
49
+ return sum + (ratio > 0 ? ratio : 0);
50
+ }, 0);
51
+ if (total <= 0) {
52
+ return evenSplit();
53
+ }
54
+ return ratios.map(function (ratio) {
55
+ return totalWidth * ((ratio > 0 ? ratio : 0) / total);
56
+ });
57
+ };
58
+
59
+ /**
60
+ * Like `getColumnsWidths`, but fills every visual column under a first-row `colspan` so column
61
+ * controls can render one grid track per column.
62
+ */
63
+ export var getColumnsWidthsWithMergedCells = function getColumnsWidthsWithMergedCells(view) {
64
+ var selection = view.state.selection;
65
+ var table = findTable(selection);
66
+ if (!table) {
67
+ return [];
68
+ }
69
+ var map = TableMap.get(table.node);
70
+ var domAtPos = view.domAtPos.bind(view);
71
+ var widths = Array.from({
72
+ length: map.width
73
+ });
74
+ for (var i = 0; i < map.width; i++) {
75
+ var _node$attrs$colspan;
76
+ if (map.isCellMergedTopLeft(0, i)) {
77
+ continue;
78
+ }
79
+
80
+ // Ignored via go/ees005
81
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
82
+ var node = table.node.nodeAt(map.map[i]);
83
+ var pos = map.map[i] + table.start;
84
+ // Ignored via go/ees005
85
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
86
+ var cellRef = findDomRefAtPos(pos, domAtPos);
87
+ var rect = cellRef.getBoundingClientRect();
88
+ var measuredWidth = (rect ? rect.width : cellRef.offsetWidth) + 1;
89
+ var colspan = (_node$attrs$colspan = node.attrs.colspan) !== null && _node$attrs$colspan !== void 0 ? _node$attrs$colspan : 1;
90
+ if (colspan <= 1) {
91
+ widths[i] = measuredWidth;
92
+ continue;
93
+ }
94
+ var colwidth = Array.isArray(node.attrs.colwidth) ? node.attrs.colwidth : undefined;
95
+ var perColumnWidths = getProportionalColumnWidths(measuredWidth, colspan, colwidth);
96
+ for (var span = 0; span < colspan && i + span < map.width; span++) {
97
+ widths[i + span] = perColumnWidths[span];
98
+ }
99
+ i += colspan - 1;
100
+ }
101
+ return widths;
102
+ };
36
103
  export var getColumnDeleteButtonParams = function getColumnDeleteButtonParams(columnsWidths, selection) {
37
104
  var rect = getSelectionRect(selection);
38
105
  if (!rect) {
@@ -115,6 +182,9 @@ var getRelativeDomCellWidths = function getRelativeDomCellWidths(_ref) {
115
182
  });
116
183
  };
117
184
  export var colWidthsForRow = function colWidthsForRow(tr) {
185
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
186
+ _ref2$useColwidthRati = _ref2.useColwidthRatios,
187
+ useColwidthRatios = _ref2$useColwidthRati === void 0 ? false : _ref2$useColwidthRati;
118
188
  // get the colspans
119
189
  var rowColSpans = maphElem(tr, function (cell) {
120
190
  return Number(cell.getAttribute('colspan') || 1 /* default to span of 1 */);
@@ -142,7 +212,7 @@ export var colWidthsForRow = function colWidthsForRow(tr) {
142
212
  // reverse engineer cell widths from table widths
143
213
  var domBasedCellWidths = [];
144
214
  cellInfos.map(function (cell) {
145
- domBasedCellWidths.push.apply(domBasedCellWidths, _toConsumableArray(getRelativeDomCellWidths(cell)));
215
+ domBasedCellWidths.push.apply(domBasedCellWidths, _toConsumableArray(useColwidthRatios ? getRelativeDomCellWidths(cell) : new Array(cell.colspan).fill(cell.width / cell.colspan)));
146
216
  });
147
217
  if (cellInfos.reduce(function (acc, cell) {
148
218
  return acc + cell.width;
@@ -166,6 +236,53 @@ export var colWidthsForRow = function colWidthsForRow(tr) {
166
236
  return "".concat(pct, "%");
167
237
  }).join(' ');
168
238
  };
239
+
240
+ /**
241
+ * Returns the visual column index that the mouse pointer is over within a column-spanned
242
+ * cell, by walking the per-column boundaries of the spanned cell and finding the column whose
243
+ * horizontal range contains `mouseEvent.clientX`.
244
+ *
245
+ * `<td>.cellIndex` for a cell with `colspan > 1` only resolves to the first column the cell
246
+ * occupies, so hovering anywhere inside a colspanned first-row cell pins the column drag handle
247
+ * to that first column. This resolver disambiguates which visual column the pointer is actually
248
+ * over so the handle/menu can target a single column.
249
+ *
250
+ * The search is restricted to columns in `[startIndex, endIndex)` (the cell's own span). The
251
+ * spanned cell's bounding rect is read once and split into per-column boundaries using the cell's
252
+ * `data-colwidth` ratios (falling back to an even split for unresized columns) — this keeps the
253
+ * work bounded by the colspan size and avoids measuring the whole table.
254
+ *
255
+ * Returns `undefined` when the mouse is outside the spanned range (so callers can fall back to
256
+ * the converted HTML column index).
257
+ */
258
+ export var getColumnIndexByMousePosition = function getColumnIndexByMousePosition(cellElement, mouseEvent, columnIndexRange) {
259
+ var _cellElement$dataset$;
260
+ var startIndex = columnIndexRange.startIndex,
261
+ endIndex = columnIndexRange.endIndex;
262
+ var columnCount = endIndex - startIndex;
263
+ if (columnCount <= 0) {
264
+ return undefined;
265
+ }
266
+ var cellRect = cellElement.getBoundingClientRect();
267
+ if (mouseEvent.clientX < cellRect.left || mouseEvent.clientX >= cellRect.right) {
268
+ return undefined;
269
+ }
270
+
271
+ // Read DOM ratios here to avoid resolving the ProseMirror node on this mouse-move path.
272
+ var ratios = (_cellElement$dataset$ = cellElement.dataset.colwidth) === null || _cellElement$dataset$ === void 0 ? void 0 : _cellElement$dataset$.split(',').map(Number).filter(function (value) {
273
+ return !Number.isNaN(value);
274
+ });
275
+ var perColumnWidths = getProportionalColumnWidths(cellRect.width, columnCount, ratios);
276
+ var offsetFromLeft = mouseEvent.clientX - cellRect.left;
277
+ var cumulativeWidth = 0;
278
+ for (var column = 0; column < columnCount; column++) {
279
+ cumulativeWidth += perColumnWidths[column];
280
+ if (offsetFromLeft < cumulativeWidth) {
281
+ return startIndex + column;
282
+ }
283
+ }
284
+ return endIndex - 1;
285
+ };
169
286
  export var convertHTMLCellIndexToColumnIndex = function convertHTMLCellIndexToColumnIndex(htmlColIndex, htmlRowIndex, tableMap) {
170
287
  // Same numbers (positions) in tableMap.map array mean that there are merged cells.
171
288
  // Cells can be merged across columns. So we need to check if the cell on the left and current cell have the same value.
@@ -12,6 +12,25 @@ export var isInsertRowButton = function isInsertRowButton(node) {
12
12
  export var getColumnOrRowIndex = function getColumnOrRowIndex(target) {
13
13
  return [parseInt(target.getAttribute('data-start-index') || '-1', 10), parseInt(target.getAttribute('data-end-index') || '-1', 10)];
14
14
  };
15
+
16
+ /**
17
+ * Returns the element that carries the `data-start-index` / `data-end-index` attributes for a
18
+ * column/row control.
19
+ *
20
+ * The floating insert dot is a child of a wrapper that holds the index attributes, so when the
21
+ * pointer is directly over the dot the attributes are not on the event target. This walks up to
22
+ * the nearest ancestor that has `data-start-index`, falling back to the original element so the
23
+ * behaviour is unchanged when the target already carries the attributes.
24
+ */
25
+ export var getIndexAttributeSourceElement = function getIndexAttributeSourceElement(target) {
26
+ if (target.hasAttribute('data-start-index')) {
27
+ return target;
28
+ }
29
+ // Ignored via go/ees005
30
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
31
+ var closestWithIndex = target.closest('[data-start-index]');
32
+ return closestWithIndex !== null && closestWithIndex !== void 0 ? closestWithIndex : target;
33
+ };
15
34
  export var isColumnControlsDecorations = function isColumnControlsDecorations(node) {
16
35
  return containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS);
17
36
  };
@@ -38,6 +57,9 @@ export var isDragColumnFloatingInsertDot = function isDragColumnFloatingInsertDo
38
57
  export var isDragCornerButton = function isDragCornerButton(node) {
39
58
  return containsClassName(node, ClassName.DRAG_CORNER_BUTTON) || containsClassName(node, ClassName.DRAG_CORNER_BUTTON_INNER);
40
59
  };
60
+ export var isTableDragHandleButton = function isTableDragHandleButton(target) {
61
+ return target instanceof HTMLElement && Boolean(target.closest(".".concat(ClassName.DRAG_HANDLE_BUTTON_CONTAINER)));
62
+ };
41
63
 
42
64
  /*
43
65
  * This function returns which side of a given element the mouse cursor is,
@@ -78,6 +78,48 @@ export var getRowsParams = function getRowsParams(rowsHeights) {
78
78
  }
79
79
  return rows;
80
80
  };
81
+
82
+ /**
83
+ * Returns the visual row index that the mouse pointer is over, by walking the row heights
84
+ * inside `tbody` and finding the row whose vertical range contains `mouseEvent.clientY`.
85
+ *
86
+ * When `rowIndexRange` is provided, the search is restricted to rows in that range (the
87
+ * `endIndex` is exclusive). This is the hot path used on `mousemove` when hovering over a
88
+ * row-spanned cell — restricting the range to `[startIndex, endIndex)` keeps the number
89
+ * of forced layout reads bounded by the row-span size, not the table size.
90
+ *
91
+ * Returns `undefined` when the mouse is above the search range or below it (so callers can
92
+ * fall back to the HTML row index).
93
+ */
94
+ export var getRowIndexByMousePosition = function getRowIndexByMousePosition(tableRef, mouseEvent, rowIndexRange) {
95
+ var _rowIndexRange$startI, _rowIndexRange$endInd;
96
+ var tableBody = tableRef.querySelector('tbody');
97
+ if (!tableBody) {
98
+ return undefined;
99
+ }
100
+ var rows = tableBody.children;
101
+ var startIndex = (_rowIndexRange$startI = rowIndexRange === null || rowIndexRange === void 0 ? void 0 : rowIndexRange.startIndex) !== null && _rowIndexRange$startI !== void 0 ? _rowIndexRange$startI : 0;
102
+ var endIndex = Math.min((_rowIndexRange$endInd = rowIndexRange === null || rowIndexRange === void 0 ? void 0 : rowIndexRange.endIndex) !== null && _rowIndexRange$endInd !== void 0 ? _rowIndexRange$endInd : rows.length, rows.length);
103
+ if (startIndex >= endIndex) {
104
+ return undefined;
105
+ }
106
+ var firstRowRect = rows[startIndex].getBoundingClientRect();
107
+ if (mouseEvent.clientY < firstRowRect.top) {
108
+ return undefined;
109
+ }
110
+ var rowBottom = firstRowRect.bottom;
111
+ if (mouseEvent.clientY < rowBottom) {
112
+ return startIndex;
113
+ }
114
+ for (var rowIndex = startIndex + 1; rowIndex < endIndex; rowIndex++) {
115
+ var rowRect = rows[rowIndex].getBoundingClientRect();
116
+ rowBottom = rowRect.bottom;
117
+ if (mouseEvent.clientY < rowBottom) {
118
+ return rowIndex;
119
+ }
120
+ }
121
+ return undefined;
122
+ };
81
123
  export var getRowClassNames = function getRowClassNames(index, selection) {
82
124
  var hoveredRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
83
125
  var isInDanger = arguments.length > 3 ? arguments[3] : undefined;
@@ -1,3 +1,6 @@
1
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
2
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
3
+ import { findTableClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
1
4
  export var getSelectedColumnIndexes = function getSelectedColumnIndexes(selectionRect) {
2
5
  var columnIndexes = [];
3
6
  for (var i = selectionRect.left; i < selectionRect.right; i++) {
@@ -11,4 +14,74 @@ export var getSelectedRowIndexes = function getSelectedRowIndexes(selectionRect)
11
14
  rowIndexes.push(i);
12
15
  }
13
16
  return rowIndexes;
17
+ };
18
+
19
+ /**
20
+ * Treats a column as fully selected when its first-row area is covered by a horizontal merge and
21
+ * the explicit `CellSelection` starts below that merged cell. `CellSelection.isColSelection()`
22
+ * returns `false` in this case because the selection does not include the merged first-row cell.
23
+ */
24
+ export var isColumnSelectionWithMergedFirstRow = function isColumnSelectionWithMergedFirstRow(selection) {
25
+ var rect = getSelectionRect(selection);
26
+ if (!rect) {
27
+ return false;
28
+ }
29
+ var table = findTableClosestToPos(selection.$anchorCell);
30
+ if (!table) {
31
+ return false;
32
+ }
33
+ var map = TableMap.get(table.node);
34
+ if (rect.bottom !== map.height || rect.top === 0) {
35
+ return false;
36
+ }
37
+ for (var col = rect.left; col < rect.right; col++) {
38
+ var topCellRect = map.findCell(map.map[col]);
39
+ var isHorizontallyMerged = topCellRect.right - topCellRect.left > 1;
40
+ var bridgesGapAboveSelection = topCellRect.bottom >= rect.top;
41
+ if (!isHorizontallyMerged || !bridgesGapAboveSelection) {
42
+ return false;
43
+ }
44
+ }
45
+ return true;
46
+ };
47
+
48
+ /**
49
+ * Treats a row as fully selected when its first-column area is covered by a vertical merge and the
50
+ * explicit `CellSelection` starts to the right of that merged cell. `CellSelection.isRowSelection()`
51
+ * returns `false` in this case because the selection does not include the merged first-column cell.
52
+ */
53
+ export var isRowSelectionWithMergedFirstColumn = function isRowSelectionWithMergedFirstColumn(selection) {
54
+ var rect = getSelectionRect(selection);
55
+ if (!rect) {
56
+ return false;
57
+ }
58
+ var table = findTableClosestToPos(selection.$anchorCell);
59
+ if (!table) {
60
+ return false;
61
+ }
62
+ var map = TableMap.get(table.node);
63
+ if (rect.right !== map.width || rect.left === 0) {
64
+ return false;
65
+ }
66
+ for (var row = rect.top; row < rect.bottom; row++) {
67
+ var leftCellRect = map.findCell(map.map[row * map.width]);
68
+ var isVerticallyMerged = leftCellRect.bottom - leftCellRect.top > 1;
69
+ var bridgesGapLeftOfSelection = leftCellRect.right >= rect.left;
70
+ if (!isVerticallyMerged || !bridgesGapLeftOfSelection) {
71
+ return false;
72
+ }
73
+ }
74
+ return true;
75
+ };
76
+
77
+ /**
78
+ * Returns `true` when the selection covers one or more complete rows or columns (the kind of
79
+ * selection produced by clicking a row/column drag handle), including the merged-cell variants
80
+ * where `CellSelection.isRowSelection()` / `isColSelection()` return `false`.
81
+ */
82
+ export var isFullRowOrColumnSelected = function isFullRowOrColumnSelected(selection) {
83
+ if (!(selection instanceof CellSelection)) {
84
+ return false;
85
+ }
86
+ return selection.isRowSelection() || selection.isColSelection() || isRowSelectionWithMergedFirstColumn(selection) || isColumnSelectionWithMergedFirstRow(selection);
14
87
  };
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  /* eslint-disable @atlaskit/design-system/no-html-button */
4
4
 
5
- import React, { useEffect, useMemo, useRef, useState } from 'react';
5
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
6
  import classnames from 'classnames';
7
7
  import ReactDOM from 'react-dom';
8
8
  import { injectIntl } from 'react-intl';
@@ -13,6 +13,7 @@ import { findTable, TableMap } from '@atlaskit/editor-tables';
13
13
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
14
14
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
15
15
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
16
+ import { closeActiveTableMenu } from '../../pm-plugins/commands/active-table-menu';
16
17
  import { getPluginState as getDnDPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
17
18
  import { findDuplicatePosition, hasMergedCellsInSelection } from '../../pm-plugins/utils/merged-cells';
18
19
  import { TableCssClassName as ClassName } from '../../types';
@@ -20,7 +21,8 @@ import { dragTableInsertColumnButtonSize } from '../consts';
20
21
  import { DragPreview } from '../DragPreview';
21
22
  import { HandleIconComponent } from './HandleIconComponent';
22
23
  var DragHandleComponent = function DragHandleComponent(_ref) {
23
- var isDragMenuTarget = _ref.isDragMenuTarget,
24
+ var api = _ref.api,
25
+ isDragMenuTarget = _ref.isDragMenuTarget,
24
26
  tableLocalId = _ref.tableLocalId,
25
27
  _ref$direction = _ref.direction,
26
28
  direction = _ref$direction === void 0 ? 'row' : _ref$direction,
@@ -151,6 +153,35 @@ var DragHandleComponent = function DragHandleComponent(_ref) {
151
153
  }, [tableLocalId, direction, indexes, isRow, editorView.state.selection, hasMergedCells]);
152
154
  var showDragMenuAnchorId = isRow ? 'drag-handle-button-row' : 'drag-handle-button-column';
153
155
  var browser = getBrowserInfo();
156
+
157
+ // Clicking the drag handle's clickable zone is a plain row/column selection (not the menu
158
+ // trigger), so the selection toolbar should appear. The floating menu defers closing for clicks
159
+ // inside the drag controls, so we close it here and reset the user intent to 'default' (in the
160
+ // same transaction) so the toolbar is shown.
161
+ var closeActiveDragMenuAndShowToolbar = useCallback(function () {
162
+ var _api$table, _api$core;
163
+ if (!api) {
164
+ return;
165
+ }
166
+ var activeTableMenu = (_api$table = api.table) === null || _api$table === void 0 || (_api$table = _api$table.sharedState.currentState()) === null || _api$table === void 0 ? void 0 : _api$table.activeTableMenu;
167
+ var isActiveTableMenuOpen = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
168
+ if (!isActiveTableMenuOpen) {
169
+ return;
170
+ }
171
+ (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref5) {
172
+ var _api$userIntent;
173
+ var tr = _ref5.tr;
174
+ closeActiveTableMenu(api, {
175
+ skipUserIntent: true
176
+ })({
177
+ tr: tr
178
+ });
179
+ (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 || _api$userIntent.commands.setCurrentUserIntent('default')({
180
+ tr: tr
181
+ });
182
+ return tr;
183
+ });
184
+ }, [api]);
154
185
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
155
186
  type: "button"
156
187
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -176,7 +207,10 @@ var DragHandleComponent = function DragHandleComponent(_ref) {
176
207
  // return focus to editor so copying table selections whilst still works, i cannot call e.preventDefault in a mousemove event as this stops dragstart events from firing
177
208
  // -> this is bad for a11y but is the current standard new copy/paste keyboard shortcuts should be introduced instead
178
209
  editorView.focus();
179
- if (isDragMenuOpen) {
210
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
211
+ // New menu: close the open row/column menu (and show the selection toolbar).
212
+ closeActiveDragMenuAndShowToolbar();
213
+ } else if (isDragMenuOpen) {
180
214
  toggleDragMenu && toggleDragMenu('mouse', e);
181
215
  }
182
216
  },
@@ -215,12 +249,20 @@ var DragHandleComponent = function DragHandleComponent(_ref) {
215
249
  // return focus to editor so copying table selections whilst still works, i cannot call e.preventDefault in a mousemove event as this stops dragstart events from firing
216
250
  // -> this is bad for a11y but is the current standard new copy/paste keyboard shortcuts should be introduced instead
217
251
  editorView.focus();
218
- toggleDragMenu && toggleDragMenu('mouse', e);
252
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
253
+ toggleDragMenu && toggleDragMenu('mouse', e, indexes[0]);
254
+ } else {
255
+ toggleDragMenu && toggleDragMenu('mouse', e);
256
+ }
219
257
  },
220
258
  onClick: onClick,
221
259
  onKeyDown: function onKeyDown(e) {
222
260
  if (e.key === 'Enter' || e.key === ' ') {
223
- toggleDragMenu && toggleDragMenu('keyboard');
261
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
262
+ toggleDragMenu && toggleDragMenu('keyboard', undefined, indexes[0]);
263
+ } else {
264
+ toggleDragMenu && toggleDragMenu('keyboard');
265
+ }
224
266
  }
225
267
  }
226
268
  }, appearance !== 'placeholder' ?
@@ -31,6 +31,7 @@ function getRowOptions(index) {
31
31
  });
32
32
  }
33
33
  function getColumnOptions(index, tableContainer, hasNumberedColumns) {
34
+ var verticalOffsetCorrection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
34
35
  var options = {
35
36
  alignX: 'end',
36
37
  alignY: 'top',
@@ -41,20 +42,32 @@ function getColumnOptions(index, tableContainer, hasNumberedColumns) {
41
42
  // we should always set the InsertButton on the start,
42
43
  // considering the offset from the first column
43
44
  onPositionCalculated: function onPositionCalculated(position) {
45
+ // Move the popup upward whether the offset parent provides `top` or `bottom`.
46
+ var verticalCorrection;
47
+ if (verticalOffsetCorrection) {
48
+ if (position.top !== undefined) {
49
+ verticalCorrection = {
50
+ top: position.top - verticalOffsetCorrection
51
+ };
52
+ } else if (position.bottom !== undefined) {
53
+ verticalCorrection = {
54
+ bottom: position.bottom + verticalOffsetCorrection
55
+ };
56
+ }
57
+ }
44
58
  var left = position.left;
45
59
  if (!left) {
46
- // If not left, lest skip expensive next calculations.
47
- return position;
60
+ return _objectSpread(_objectSpread({}, position), verticalCorrection);
48
61
  }
49
62
  if (index === 0) {
50
- return _objectSpread(_objectSpread({}, position), {}, {
63
+ return _objectSpread(_objectSpread(_objectSpread({}, position), verticalCorrection), {}, {
51
64
  left: hasNumberedColumns ? HORIZONTAL_ALIGN_NUMBERED_COLUMN_BUTTON : HORIZONTAL_ALIGN_COLUMN_BUTTON
52
65
  });
53
66
  }
54
67
 
55
68
  // Check if current position is greater than the available container width
56
69
  var rect = tableContainer ? tableContainer.getBoundingClientRect() : null;
57
- return _objectSpread(_objectSpread({}, position), {}, {
70
+ return _objectSpread(_objectSpread(_objectSpread({}, position), verticalCorrection), {}, {
58
71
  left: rect && left > rect.width ? rect.width : left
59
72
  });
60
73
  }
@@ -71,9 +84,10 @@ function getColumnOptions(index, tableContainer, hasNumberedColumns) {
71
84
  return options;
72
85
  }
73
86
  function getPopupOptions(direction, index, hasNumberedColumns, tableContainer) {
87
+ var verticalOffsetCorrection = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
74
88
  switch (direction) {
75
89
  case 'column':
76
- return getColumnOptions(index, tableContainer, hasNumberedColumns);
90
+ return getColumnOptions(index, tableContainer, hasNumberedColumns, verticalOffsetCorrection);
77
91
  case 'row':
78
92
  return getRowOptions(index);
79
93
  default:
@@ -20,6 +20,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
20
20
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
21
21
  import { insertColumnWithAnalytics, insertRowWithAnalytics } from '../../pm-plugins/commands/commands-with-analytics';
22
22
  import { checkIfNumberColumnEnabled } from '../../pm-plugins/utils/nodes';
23
+ import { isFullRowOrColumnSelected } from '../../pm-plugins/utils/selection';
23
24
  import { TableCssClassName as ClassName } from '../../types';
24
25
  import getPopupOptions from './getPopupOptions';
25
26
  import { DragAndDropInsertButton } from './InsertButton';
@@ -73,8 +74,14 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
73
74
  return null;
74
75
  }
75
76
  var tr = editorView.state.tr;
76
- if (tr.selection instanceof CellSelection && (tr.selection.isColSelection() || tr.selection.isRowSelection())) {
77
- return null;
77
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
78
+ if (isFullRowOrColumnSelected(tr.selection)) {
79
+ return null;
80
+ }
81
+ } else {
82
+ if (tr.selection instanceof CellSelection && (tr.selection.isColSelection() || tr.selection.isRowSelection())) {
83
+ return null;
84
+ }
78
85
  }
79
86
  var tablePos = findTable(tr.selection);
80
87
  if (!tablePos) {
@@ -128,6 +135,15 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
128
135
  var index = type === 'column' ? insertColumnButtonIndex : insertRowButtonIndex;
129
136
  var hasNumberedColumns = checkIfNumberColumnEnabled(editorView.state.selection);
130
137
 
138
+ // If row 0 has a colspan, anchor to a lower row for the real column boundary (X),
139
+ // then move back up to the table top (Y):
140
+ // row 0: [ colspan=2 ]
141
+ // row 1: [ col 1 ][ col 2 ] ← anchor here for X
142
+ // ↑ button should render at row 0/table top
143
+ var verticalOffsetCorrection = 0;
144
+ if (type === 'column' && expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
145
+ verticalOffsetCorrection = Math.max(0, targetCellRef.getBoundingClientRect().top - tableRef.getBoundingClientRect().top);
146
+ }
131
147
  // Fixed the 'add column button' not visible issue when sticky header is enabled
132
148
  // By setting the Popup z-index higher than the sticky header z-index ( common-styles.ts tr.sticky)
133
149
  // Only when inserting a column, otherwise set to undefined
@@ -145,7 +161,7 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
145
161
  allowOutOfBounds: true
146
162
  // Ignored via go/ees005
147
163
  // eslint-disable-next-line react/jsx-props-no-spreading
148
- }, getPopupOptions(type, index, hasNumberedColumns, tableContainerWrapper), {
164
+ }, getPopupOptions(type, index, hasNumberedColumns, tableContainerWrapper, verticalOffsetCorrection), {
149
165
  zIndex: zIndex
150
166
  }), /*#__PURE__*/React.createElement(DragAndDropInsertButton, {
151
167
  type: type,
@@ -155,6 +171,20 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
155
171
  isChromelessEditor: isChromelessEditor
156
172
  }));
157
173
  }
174
+
175
+ // Finds a row where `columnIndex` has real left/right cell boundaries.
176
+ }, {
177
+ key: "findRowWithUnmergedColumn",
178
+ value: function findRowWithUnmergedColumn(tableMap, columnIndex) {
179
+ for (var row = 0; row < tableMap.height; row++) {
180
+ var pos = tableMap.map[row * tableMap.width + columnIndex];
181
+ var rect = tableMap.findCell(pos);
182
+ if (rect.left === columnIndex && rect.right === columnIndex + 1) {
183
+ return row;
184
+ }
185
+ }
186
+ return null;
187
+ }
158
188
  }, {
159
189
  key: "getCellPosition",
160
190
  value: function getCellPosition(type, tableNode) {
@@ -172,6 +202,10 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
172
202
  if (columnIndex > tableMap.width - 1) {
173
203
  return null;
174
204
  }
205
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
206
+ var rowWithRealColumn = this.findRowWithUnmergedColumn(tableMap, columnIndex);
207
+ return rowWithRealColumn === null ? null : tableMap.positionAt(rowWithRealColumn, columnIndex, tableNode);
208
+ }
175
209
  return tableMap.positionAt(0, columnIndex, tableNode);
176
210
  } else {
177
211
  // This condition is to make typescript happy.
@@ -56,9 +56,6 @@ var FloatingTableMenu = function FloatingTableMenu(_ref) {
56
56
  popupContentRef.current = el;
57
57
  setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 || setOutsideClickTargetRef(el);
58
58
  }, [setOutsideClickTargetRef]);
59
- var dismiss = useCallback(function () {
60
- api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
61
- }, [api]);
62
59
  var returnFocusToDragHandle = useCallback(function () {
63
60
  // Match legacy DragMenu's closeMenu('handle') behaviour.
64
61
  var handleId = dragMenuDirection === 'row' ? '#drag-handle-button-row' : '#drag-handle-button-column';
@@ -91,9 +88,9 @@ var FloatingTableMenu = function FloatingTableMenu(_ref) {
91
88
  var handleEscape = useCallback(function (event) {
92
89
  event.preventDefault();
93
90
  event.stopPropagation();
94
- dismiss();
91
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
95
92
  returnFocusToDragHandle();
96
- }, [dismiss, returnFocusToDragHandle]);
93
+ }, [api, returnFocusToDragHandle]);
97
94
 
98
95
  // Memoize the editor DOM reference so the provider doesn't re-bind listeners
99
96
  // on every render (the provider depends on `dom` in its effect's deps).
@@ -114,8 +111,8 @@ var FloatingTableMenu = function FloatingTableMenu(_ref) {
114
111
  if (target instanceof Node && (_popupContentRef$curr = popupContentRef.current) !== null && _popupContentRef$curr !== void 0 && _popupContentRef$curr.contains(target) || target instanceof Element && (target.closest(DRAG_HANDLE_CONTROLS_SELECTOR) || target.closest(NESTED_DROPDOWN_SELECTOR))) {
115
112
  return;
116
113
  }
117
- dismiss();
118
- }, [dismiss]);
114
+ api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api));
115
+ }, [api]);
119
116
  if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
120
117
  return null;
121
118
  }