@atlaskit/editor-plugin-table 7.22.0 → 7.24.0

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 (33) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/cjs/plugin.js +1 -1
  3. package/dist/cjs/pm-plugins/main.js +1 -5
  4. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +34 -19
  5. package/dist/cjs/pm-plugins/table-resizing/utils/resize-logic.js +3 -0
  6. package/dist/cjs/toolbar.js +15 -12
  7. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +14 -8
  8. package/dist/cjs/utils/create.js +1 -1
  9. package/dist/es2019/plugin.js +1 -1
  10. package/dist/es2019/pm-plugins/main.js +1 -5
  11. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +41 -25
  12. package/dist/es2019/pm-plugins/table-resizing/utils/resize-logic.js +1 -0
  13. package/dist/es2019/toolbar.js +15 -12
  14. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +14 -8
  15. package/dist/es2019/utils/create.js +1 -1
  16. package/dist/esm/plugin.js +1 -1
  17. package/dist/esm/pm-plugins/main.js +1 -5
  18. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +35 -21
  19. package/dist/esm/pm-plugins/table-resizing/utils/resize-logic.js +3 -0
  20. package/dist/esm/toolbar.js +15 -12
  21. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +14 -8
  22. package/dist/esm/utils/create.js +1 -1
  23. package/dist/types/utils/analytics.d.ts +2 -1
  24. package/dist/types-ts4.5/utils/analytics.d.ts +2 -1
  25. package/package.json +16 -16
  26. package/src/plugin.tsx +1 -0
  27. package/src/pm-plugins/main.ts +1 -4
  28. package/src/pm-plugins/table-resizing/utils/resize-column.ts +59 -31
  29. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +1 -0
  30. package/src/toolbar.tsx +19 -14
  31. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -7
  32. package/src/utils/analytics.ts +6 -1
  33. package/src/utils/create.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#124519](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124519)
8
+ [`fbd519a29db88`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fbd519a29db88) -
9
+ Don't add merge cell and split cell options to floating toolbar if allowMergedCell is disabled or
10
+ undefined
11
+ - [#124475](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124475)
12
+ [`f1beea7ed5546`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f1beea7ed5546) -
13
+ [ux] [ED-24078] This change is adding aria-labels to the Table Cell Options menu so that the
14
+ screenreader will announce the keyboard shortcuts to keyboard-only users. The change is feature
15
+ flagged behind 'platform_editor_announce_cell_options_hotkeys'.
16
+
17
+ ### Patch Changes
18
+
19
+ - [#124231](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124231)
20
+ [`48ae65e0f36e8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/48ae65e0f36e8) -
21
+ Removed FF platform.editor.transform-slice-for-nested-expand
22
+ - [#124519](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124519)
23
+ [`0d1225bff51ff`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0d1225bff51ff) -
24
+ Use scaled amounts for new column resizing, and update logic to cater for more scenarios
25
+ - Updated dependencies
26
+
27
+ ## 7.23.0
28
+
29
+ ### Minor Changes
30
+
31
+ - [#124209](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124209)
32
+ [`8aa1792f12ed3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8aa1792f12ed3) -
33
+ bump @atlaskit/editor-prosemirror to 5.0.0, bump @atlaskit/adf-schema to 40.1.0
34
+
35
+ ### Patch Changes
36
+
37
+ - [#122783](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122783)
38
+ [`c64ead15aa9d7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c64ead15aa9d7) -
39
+ [ux] Enabled table alignment in comment editor
40
+ - Updated dependencies
41
+
3
42
  ## 7.22.0
4
43
 
5
44
  ### Minor Changes
@@ -169,7 +169,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
169
169
  }
170
170
  },
171
171
  commands: {
172
- insertTableWithSize: (0, _insert.insertTableWithSize)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
172
+ insertTableWithSize: (0, _insert.insertTableWithSize)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
173
173
  },
174
174
  nodes: function nodes() {
175
175
  return [{
@@ -202,11 +202,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
202
202
  if (!pluginConfig.allowBackgroundColor) {
203
203
  slice = (0, _misc.transformSliceRemoveCellBackgroundColor)(slice, schema);
204
204
  }
205
-
206
- // If a partial paste of nested expand, paste only nested-expand's content */
207
- if ((0, _platformFeatureFlags.fg)('platform.editor.transform-slice-for-nested-expand')) {
208
- slice = (0, _transforms.transformSliceToRemoveOpenNestedExpand)(slice, schema);
209
- }
205
+ slice = (0, _transforms.transformSliceToRemoveOpenNestedExpand)(slice, schema);
210
206
  return slice;
211
207
  },
212
208
  handleClick: function handleClick(_ref2, _pos, event) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.scaleResizeState = exports.resizeColumnAndTable = exports.resizeColumn = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _styles = require("@atlaskit/editor-common/styles");
9
10
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
10
11
  var _types = require("../../../types");
11
12
  var _alignment = require("../../../utils/alignment");
@@ -38,17 +39,18 @@ var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnA
38
39
  isTableAlignmentEnabled = _ref.isTableAlignmentEnabled;
39
40
  var editorContainerWidth = getEditorContainerWidth(editorWidth);
40
41
  var isTableLeftAligned = tableNode.attrs.layout === _alignment.ALIGN_START;
42
+ var isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
43
+ var isOverflow = resizeState.tableWidth > resizeState.maxSize;
41
44
  var resizeAmount = isTableLeftAligned ? amount : amount * 2;
42
45
  var willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
43
- var willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
46
+ var willResizedTableStayInOverflow = isOverflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
44
47
 
45
48
  // STEP 1: Update col width
46
49
  if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
47
50
  var _tableRef$closest;
48
51
  var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
49
52
  resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
50
- }
51
- if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
53
+ } else {
52
54
  var diff = -(resizeState.tableWidth - resizeState.maxSize);
53
55
  var rest = amount - diff;
54
56
  var final = isTableLeftAligned ? diff + rest : diff + rest * 2;
@@ -59,25 +61,23 @@ var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnA
59
61
  // STEP 2: Update table container width
60
62
  // columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
61
63
  var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
62
- newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
64
+ newState.maxSize = Math.round(isOverflow ? willResizedTableStayInOverflow ?
63
65
  // CASE 1A: table will stay in overflow
64
66
  // do not grow the table because resize is happening in the overflow region
65
67
  // and the overall table container needs to be retained
66
- resizeState.maxSize :
68
+ isNumberColumnEnabled ? resizeState.maxSize + _editorSharedStyles.akEditorTableNumberColumnWidth : resizeState.maxSize :
67
69
  // CASE 1B: table will no longer be in overflow, so adjust container width
68
70
  // ensure the table is resized without any 'big jumps' by working out
69
71
  // the difference between the new table width and the max size and adding the resize
70
- resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
72
+ isNumberColumnEnabled ? resizeState.maxSize + _editorSharedStyles.akEditorTableNumberColumnWidth + (resizeState.tableWidth - resizeState.maxSize + _editorSharedStyles.akEditorTableNumberColumnWidth + delta) : resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
71
73
  // CASE 2: table will hit editor edge
72
74
  editorContainerWidth :
73
75
  // CASE 3: table is being resized from a non-overflow state
74
- resizeState.maxSize + delta);
76
+ isNumberColumnEnabled ? resizeState.maxSize + _editorSharedStyles.akEditorTableNumberColumnWidth + delta : resizeState.maxSize + delta);
75
77
 
76
78
  // do not apply scaling logic because resize state is already scaled
77
79
  (0, _resizeState.updateColgroup)(newState, tableRef, tableNode, false, false);
78
- if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
79
- updateTablePreview(tableRef, newState.maxSize, (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
80
- }
80
+ updateTablePreview(tableRef, newState.maxSize, (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
81
81
  return newState;
82
82
  };
83
83
  var updateTablePreview = function updateTablePreview(tableRef, newTableWidth, shouldChangeAlignment) {
@@ -105,37 +105,52 @@ var scaleResizeState = exports.scaleResizeState = function scaleResizeState(_ref
105
105
  tableRef = _ref2.tableRef,
106
106
  tableNode = _ref2.tableNode,
107
107
  editorWidth = _ref2.editorWidth;
108
- // check if table is scaled, if not then avoid applying scaling values down
109
- if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
108
+ var isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
109
+ var isTableScaled = isNumberColumnEnabled || resizeState.maxSize > getEditorContainerWidth(editorWidth);
110
+
111
+ // Tables with number column can cause the table to be in two different states:
112
+ // 1. The table sum of col widths will be smaller than the max size, which is incorrect. For this
113
+ // avoid scaling and take the document width
114
+ // 2. The table sum of col widths will be the same size as max width, which happens when the table
115
+ // is scaled using preserve table width logic, for this apply a scaled width
116
+ // return early if table isn't scaled
117
+ if (!isTableScaled || isNumberColumnEnabled && resizeState.maxSize > resizeState.tableWidth) {
110
118
  return resizeState;
111
119
  }
112
120
  var scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
121
+ var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
113
122
  var cols = resizeState.cols.map(function (col) {
114
123
  return _objectSpread(_objectSpread({}, col), {}, {
115
- width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
124
+ minWidth: _styles.tableCellMinWidth,
125
+ width: Math.max(Math.round(col.width * scalePercent), _styles.tableCellMinWidth)
116
126
  });
117
127
  });
118
- var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
119
128
  var calculatedTableWidth = cols.reduce(function (prev, curr) {
120
129
  return prev + curr.width;
121
130
  }, 0);
122
131
 
123
132
  // using Math.round can cause the sum of col widths to be larger than the table width
124
- // distribute the difference to the smallest column
133
+ // distribute the difference to the first column
125
134
  if (calculatedTableWidth > scaledTableWidth) {
126
135
  var diff = calculatedTableWidth - scaledTableWidth;
136
+ var hasDiffBeenDistributed = false;
127
137
  cols = cols.map(function (col) {
128
- return col.width - diff >= col.minWidth ? _objectSpread(_objectSpread({}, col), {}, {
129
- width: col.width - diff
130
- }) : col;
138
+ if (!hasDiffBeenDistributed && col.width - diff >= col.minWidth) {
139
+ hasDiffBeenDistributed = true;
140
+ return _objectSpread(_objectSpread({}, col), {}, {
141
+ width: col.width - diff
142
+ });
143
+ }
144
+ return col;
131
145
  });
132
146
  }
147
+ var maxSize = isNumberColumnEnabled ? Math.round((resizeState.maxSize + _editorSharedStyles.akEditorTableNumberColumnWidth) * scalePercent) : Math.round(resizeState.maxSize * scalePercent);
133
148
  return _objectSpread(_objectSpread({}, resizeState), {}, {
134
149
  widths: cols.map(function (col) {
135
150
  return col.width;
136
151
  }),
137
152
  tableWidth: scaledTableWidth,
138
- maxSize: Math.round(resizeState.maxSize * scalePercent),
153
+ maxSize: maxSize,
139
154
  cols: cols
140
155
  });
141
156
  };
@@ -241,6 +241,9 @@ function updateAffectedColumn(resizeState, colIndex, resizeAmount) {
241
241
  return col;
242
242
  });
243
243
  return _objectSpread(_objectSpread({}, resizeState), {}, {
244
+ tableWidth: updatedCols.reduce(function (acc, col) {
245
+ return acc + col.width;
246
+ }, 0),
244
247
  cols: updatedCols
245
248
  });
246
249
  }
@@ -217,19 +217,22 @@ var getToolbarCellOptionsConfig = exports.getToolbarCellOptionsConfig = function
217
217
  onMouseLeave: (0, _commands.clearHoverSelection)(),
218
218
  selected: false,
219
219
  disabled: false
220
- }, {
221
- id: 'editor.table.mergeCells',
222
- title: formatMessage(_messages.tableMessages.mergeCells),
223
- onClick: (0, _commandsWithAnalytics.mergeCellsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.FLOATING_TB),
224
- selected: false,
225
- disabled: !(0, _transforms.canMergeCells)(editorState.tr)
226
- }, {
227
- id: 'editor.table.splitCell',
228
- title: formatMessage(_messages.tableMessages.splitCell),
229
- onClick: (0, _commandsWithAnalytics.splitCellWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.FLOATING_TB),
230
- selected: false,
231
- disabled: !(0, _utils3.splitCell)(editorState)
232
220
  }];
221
+ if (pluginState.pluginConfig.allowMergeCells) {
222
+ options.push({
223
+ id: 'editor.table.mergeCells',
224
+ title: formatMessage(_messages.tableMessages.mergeCells),
225
+ onClick: (0, _commandsWithAnalytics.mergeCellsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.FLOATING_TB),
226
+ selected: false,
227
+ disabled: !(0, _transforms.canMergeCells)(editorState.tr)
228
+ }, {
229
+ id: 'editor.table.splitCell',
230
+ title: formatMessage(_messages.tableMessages.splitCell),
231
+ onClick: (0, _commandsWithAnalytics.splitCellWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.FLOATING_TB),
232
+ selected: false,
233
+ disabled: !(0, _utils3.splitCell)(editorState)
234
+ });
235
+ }
233
236
  if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
234
237
  var _newResizeStateWithAn;
235
238
  var newResizeStateWithAnalytics = editorView ? (0, _resizeState.getNewResizeStateFromSelectedColumns)(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled) : undefined;
@@ -215,8 +215,9 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
215
215
  editorView = _this$props3.editorView;
216
216
  var _getPluginState3 = (0, _pluginFactory.getPluginState)(editorView.state),
217
217
  isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled;
218
+ var content = formatMessage(isDragAndDropEnabled ? _messages.tableMessages.addColumnRight : _messages.tableMessages.insertColumn);
218
219
  return {
219
- content: formatMessage(isDragAndDropEnabled ? _messages.tableMessages.addColumnRight : _messages.tableMessages.insertColumn),
220
+ content: content,
220
221
  value: {
221
222
  name: 'insert_column'
222
223
  },
@@ -228,7 +229,8 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
228
229
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
229
230
  (0, _react2.jsx)("span", {
230
231
  css: _styles2.elementBeforeIconStyles
231
- }, (0, _react2.jsx)(_icons.AddColRightIcon, null)) : undefined
232
+ }, (0, _react2.jsx)(_icons.AddColRightIcon, null)) : undefined,
233
+ 'aria-label': (0, _platformFeatureFlags.fg)('platform_editor_announce_cell_options_hotkeys') ? (0, _keymaps.tooltip)(_keymaps.addColumnAfter, String(content)) : undefined
232
234
  };
233
235
  });
234
236
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createInsertRowItem", function () {
@@ -237,8 +239,9 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
237
239
  editorView = _this$props4.editorView;
238
240
  var _getPluginState4 = (0, _pluginFactory.getPluginState)(editorView.state),
239
241
  isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled;
242
+ var content = formatMessage(isDragAndDropEnabled ? _messages.tableMessages.addRowBelow : _messages.tableMessages.insertRow);
240
243
  return {
241
- content: formatMessage(isDragAndDropEnabled ? _messages.tableMessages.addRowBelow : _messages.tableMessages.insertRow),
244
+ content: content,
242
245
  value: {
243
246
  name: 'insert_row'
244
247
  },
@@ -250,7 +253,8 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
250
253
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
251
254
  (0, _react2.jsx)("span", {
252
255
  css: _styles2.elementBeforeIconStyles
253
- }, (0, _react2.jsx)(_icons.AddRowBelowIcon, null)) : undefined
256
+ }, (0, _react2.jsx)(_icons.AddRowBelowIcon, null)) : undefined,
257
+ 'aria-label': (0, _platformFeatureFlags.fg)('platform_editor_announce_cell_options_hotkeys') ? (0, _keymaps.tooltip)(_keymaps.addRowAfter, String(content)) : undefined
254
258
  };
255
259
  });
256
260
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createClearCellsItem", function () {
@@ -266,10 +270,11 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
266
270
  left = selectionRect.left;
267
271
  var noOfColumns = right - left;
268
272
  var noOfRows = bottom - top;
273
+ var content = formatMessage(_messages.tableMessages.clearCells, {
274
+ 0: Math.max(noOfColumns, noOfRows)
275
+ });
269
276
  return {
270
- content: formatMessage(_messages.tableMessages.clearCells, {
271
- 0: Math.max(noOfColumns, noOfRows)
272
- }),
277
+ content: content,
273
278
  value: {
274
279
  name: 'clear'
275
280
  },
@@ -285,7 +290,8 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
285
290
  label: formatMessage(_messages.tableMessages.clearCells, {
286
291
  0: Math.max(noOfColumns, noOfRows)
287
292
  })
288
- })) : undefined
293
+ })) : undefined,
294
+ 'aria-label': (0, _platformFeatureFlags.fg)('platform_editor_announce_cell_options_hotkeys') ? (0, _keymaps.tooltip)(_keymaps.backspace, String(content)) : undefined
289
295
  };
290
296
  });
291
297
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createDeleteColumnItem", function () {
@@ -22,7 +22,7 @@ var createTableWithWidth = exports.createTableWithWidth = function createTableWi
22
22
  if (isTableScalingEnabled && isFullWidthModeEnabled && !isCommentEditor) {
23
23
  attrsOverrides.tableWidth = _utils2.TABLE_MAX_WIDTH;
24
24
  }
25
- if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
25
+ if (isTableAlignmentEnabled && (isFullWidthModeEnabled || isCommentEditor)) {
26
26
  attrsOverrides.layout = 'align-start';
27
27
  }
28
28
  if (isCommentEditor && isTableResizingEnabled) {
@@ -159,7 +159,7 @@ const tablesPlugin = ({
159
159
  }
160
160
  },
161
161
  commands: {
162
- insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
162
+ insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
163
163
  },
164
164
  nodes() {
165
165
  return [{
@@ -194,11 +194,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
194
194
  if (!pluginConfig.allowBackgroundColor) {
195
195
  slice = transformSliceRemoveCellBackgroundColor(slice, schema);
196
196
  }
197
-
198
- // If a partial paste of nested expand, paste only nested-expand's content */
199
- if (fg('platform.editor.transform-slice-for-nested-expand')) {
200
- slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
201
- }
197
+ slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
202
198
  return slice;
203
199
  },
204
200
  handleClick: ({
@@ -1,6 +1,6 @@
1
1
  // Resize a given column by an amount from the current state
2
-
3
- import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
2
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
+ import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
4
4
  import { TableCssClassName as ClassName } from '../../../types';
5
5
  import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
6
6
  import { getTableScalingPercent } from './misc';
@@ -29,46 +29,45 @@ export const resizeColumnAndTable = ({
29
29
  }) => {
30
30
  const editorContainerWidth = getEditorContainerWidth(editorWidth);
31
31
  const isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
32
+ const isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
33
+ const isOverflow = resizeState.tableWidth > resizeState.maxSize;
32
34
  let resizeAmount = isTableLeftAligned ? amount : amount * 2;
33
35
  const willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
34
- const willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
36
+ const willResizedTableStayInOverflow = isOverflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
35
37
 
36
38
  // STEP 1: Update col width
37
39
  if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
38
40
  var _tableRef$closest;
39
41
  const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
40
42
  resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
41
- }
42
- if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
43
+ } else {
43
44
  const diff = -(resizeState.tableWidth - resizeState.maxSize);
44
45
  const rest = amount - diff;
45
46
  const final = isTableLeftAligned ? diff + rest : diff + rest * 2;
46
47
  resizeAmount = final;
47
48
  }
48
- let newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
49
+ const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
49
50
 
50
51
  // STEP 2: Update table container width
51
52
  // columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
52
53
  const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
53
- newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
54
+ newState.maxSize = Math.round(isOverflow ? willResizedTableStayInOverflow ?
54
55
  // CASE 1A: table will stay in overflow
55
56
  // do not grow the table because resize is happening in the overflow region
56
57
  // and the overall table container needs to be retained
57
- resizeState.maxSize :
58
+ isNumberColumnEnabled ? resizeState.maxSize + akEditorTableNumberColumnWidth : resizeState.maxSize :
58
59
  // CASE 1B: table will no longer be in overflow, so adjust container width
59
60
  // ensure the table is resized without any 'big jumps' by working out
60
61
  // the difference between the new table width and the max size and adding the resize
61
- resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
62
+ isNumberColumnEnabled ? resizeState.maxSize + akEditorTableNumberColumnWidth + (resizeState.tableWidth - resizeState.maxSize + akEditorTableNumberColumnWidth + delta) : resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
62
63
  // CASE 2: table will hit editor edge
63
64
  editorContainerWidth :
64
65
  // CASE 3: table is being resized from a non-overflow state
65
- resizeState.maxSize + delta);
66
+ isNumberColumnEnabled ? resizeState.maxSize + akEditorTableNumberColumnWidth + delta : resizeState.maxSize + delta);
66
67
 
67
68
  // do not apply scaling logic because resize state is already scaled
68
69
  updateColgroup(newState, tableRef, tableNode, false, false);
69
- if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
70
- updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
71
- }
70
+ updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
72
71
  return newState;
73
72
  };
74
73
  const updateTablePreview = (tableRef, newTableWidth, shouldChangeAlignment) => {
@@ -95,34 +94,51 @@ export const scaleResizeState = ({
95
94
  tableNode,
96
95
  editorWidth
97
96
  }) => {
98
- // check if table is scaled, if not then avoid applying scaling values down
99
- if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
97
+ const isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
98
+ const isTableScaled = isNumberColumnEnabled || resizeState.maxSize > getEditorContainerWidth(editorWidth);
99
+
100
+ // Tables with number column can cause the table to be in two different states:
101
+ // 1. The table sum of col widths will be smaller than the max size, which is incorrect. For this
102
+ // avoid scaling and take the document width
103
+ // 2. The table sum of col widths will be the same size as max width, which happens when the table
104
+ // is scaled using preserve table width logic, for this apply a scaled width
105
+ // return early if table isn't scaled
106
+ if (!isTableScaled || isNumberColumnEnabled && resizeState.maxSize > resizeState.tableWidth) {
100
107
  return resizeState;
101
108
  }
102
109
  const scalePercent = getTableScalingPercent(tableNode, tableRef);
103
- let cols = resizeState.cols.map(col => ({
104
- ...col,
105
- width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
106
- }));
107
110
  const scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
111
+ let cols = resizeState.cols.map(col => {
112
+ return {
113
+ ...col,
114
+ minWidth: tableCellMinWidth,
115
+ width: Math.max(Math.round(col.width * scalePercent), tableCellMinWidth)
116
+ };
117
+ });
108
118
  const calculatedTableWidth = cols.reduce((prev, curr) => prev + curr.width, 0);
109
119
 
110
120
  // using Math.round can cause the sum of col widths to be larger than the table width
111
- // distribute the difference to the smallest column
121
+ // distribute the difference to the first column
112
122
  if (calculatedTableWidth > scaledTableWidth) {
113
123
  const diff = calculatedTableWidth - scaledTableWidth;
124
+ let hasDiffBeenDistributed = false;
114
125
  cols = cols.map(col => {
115
- return col.width - diff >= col.minWidth ? {
116
- ...col,
117
- width: col.width - diff
118
- } : col;
126
+ if (!hasDiffBeenDistributed && col.width - diff >= col.minWidth) {
127
+ hasDiffBeenDistributed = true;
128
+ return {
129
+ ...col,
130
+ width: col.width - diff
131
+ };
132
+ }
133
+ return col;
119
134
  });
120
135
  }
136
+ const maxSize = isNumberColumnEnabled ? Math.round((resizeState.maxSize + akEditorTableNumberColumnWidth) * scalePercent) : Math.round(resizeState.maxSize * scalePercent);
121
137
  return {
122
138
  ...resizeState,
123
139
  widths: cols.map(col => col.width),
124
140
  tableWidth: scaledTableWidth,
125
- maxSize: Math.round(resizeState.maxSize * scalePercent),
141
+ maxSize,
126
142
  cols
127
143
  };
128
144
  };
@@ -211,6 +211,7 @@ export function updateAffectedColumn(resizeState, colIndex, resizeAmount) {
211
211
  });
212
212
  return {
213
213
  ...resizeState,
214
+ tableWidth: updatedCols.reduce((acc, col) => acc + col.width, 0),
214
215
  cols: updatedCols
215
216
  };
216
217
  }
@@ -199,19 +199,22 @@ export const getToolbarCellOptionsConfig = (editorState, editorView, initialSele
199
199
  onMouseLeave: clearHoverSelection(),
200
200
  selected: false,
201
201
  disabled: false
202
- }, {
203
- id: 'editor.table.mergeCells',
204
- title: formatMessage(messages.mergeCells),
205
- onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
206
- selected: false,
207
- disabled: !canMergeCells(editorState.tr)
208
- }, {
209
- id: 'editor.table.splitCell',
210
- title: formatMessage(messages.splitCell),
211
- onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
212
- selected: false,
213
- disabled: !splitCell(editorState)
214
202
  }];
203
+ if (pluginState.pluginConfig.allowMergeCells) {
204
+ options.push({
205
+ id: 'editor.table.mergeCells',
206
+ title: formatMessage(messages.mergeCells),
207
+ onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
208
+ selected: false,
209
+ disabled: !canMergeCells(editorState.tr)
210
+ }, {
211
+ id: 'editor.table.splitCell',
212
+ title: formatMessage(messages.splitCell),
213
+ onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
214
+ selected: false,
215
+ disabled: !splitCell(editorState)
216
+ });
217
+ }
215
218
  if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
216
219
  var _newResizeStateWithAn;
217
220
  const newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled) : undefined;
@@ -208,8 +208,9 @@ export class ContextualMenu extends Component {
208
208
  const {
209
209
  isDragAndDropEnabled
210
210
  } = getPluginState(editorView.state);
211
+ const content = formatMessage(isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn);
211
212
  return {
212
- content: formatMessage(isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn),
213
+ content,
213
214
  value: {
214
215
  name: 'insert_column'
215
216
  },
@@ -221,7 +222,8 @@ export class ContextualMenu extends Component {
221
222
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
222
223
  jsx("span", {
223
224
  css: elementBeforeIconStyles
224
- }, jsx(AddColRightIcon, null)) : undefined
225
+ }, jsx(AddColRightIcon, null)) : undefined,
226
+ 'aria-label': fg('platform_editor_announce_cell_options_hotkeys') ? tooltip(addColumnAfter, String(content)) : undefined
225
227
  };
226
228
  });
227
229
  _defineProperty(this, "createInsertRowItem", () => {
@@ -234,8 +236,9 @@ export class ContextualMenu extends Component {
234
236
  const {
235
237
  isDragAndDropEnabled
236
238
  } = getPluginState(editorView.state);
239
+ const content = formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow);
237
240
  return {
238
- content: formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow),
241
+ content,
239
242
  value: {
240
243
  name: 'insert_row'
241
244
  },
@@ -247,7 +250,8 @@ export class ContextualMenu extends Component {
247
250
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
248
251
  jsx("span", {
249
252
  css: elementBeforeIconStyles
250
- }, jsx(AddRowBelowIcon, null)) : undefined
253
+ }, jsx(AddRowBelowIcon, null)) : undefined,
254
+ 'aria-label': fg('platform_editor_announce_cell_options_hotkeys') ? tooltip(addRowAfter, String(content)) : undefined
251
255
  };
252
256
  });
253
257
  _defineProperty(this, "createClearCellsItem", () => {
@@ -269,10 +273,11 @@ export class ContextualMenu extends Component {
269
273
  } = selectionRect;
270
274
  const noOfColumns = right - left;
271
275
  const noOfRows = bottom - top;
276
+ const content = formatMessage(messages.clearCells, {
277
+ 0: Math.max(noOfColumns, noOfRows)
278
+ });
272
279
  return {
273
- content: formatMessage(messages.clearCells, {
274
- 0: Math.max(noOfColumns, noOfRows)
275
- }),
280
+ content,
276
281
  value: {
277
282
  name: 'clear'
278
283
  },
@@ -288,7 +293,8 @@ export class ContextualMenu extends Component {
288
293
  label: formatMessage(messages.clearCells, {
289
294
  0: Math.max(noOfColumns, noOfRows)
290
295
  })
291
- })) : undefined
296
+ })) : undefined,
297
+ 'aria-label': fg('platform_editor_announce_cell_options_hotkeys') ? tooltip(backspace, String(content)) : undefined
292
298
  };
293
299
  });
294
300
  _defineProperty(this, "createDeleteColumnItem", () => {
@@ -12,7 +12,7 @@ export const createTableWithWidth = ({
12
12
  if (isTableScalingEnabled && isFullWidthModeEnabled && !isCommentEditor) {
13
13
  attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
14
14
  }
15
- if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
15
+ if (isTableAlignmentEnabled && (isFullWidthModeEnabled || isCommentEditor)) {
16
16
  attrsOverrides.layout = 'align-start';
17
17
  }
18
18
  if (isCommentEditor && isTableResizingEnabled) {
@@ -162,7 +162,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
162
162
  }
163
163
  },
164
164
  commands: {
165
- insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
165
+ insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
166
166
  },
167
167
  nodes: function nodes() {
168
168
  return [{
@@ -195,11 +195,7 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
195
195
  if (!pluginConfig.allowBackgroundColor) {
196
196
  slice = transformSliceRemoveCellBackgroundColor(slice, schema);
197
197
  }
198
-
199
- // If a partial paste of nested expand, paste only nested-expand's content */
200
- if (fg('platform.editor.transform-slice-for-nested-expand')) {
201
- slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
202
- }
198
+ slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
203
199
  return slice;
204
200
  },
205
201
  handleClick: function handleClick(_ref2, _pos, event) {