@atlaskit/editor-plugin-table 7.16.7 → 7.16.8

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.16.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#103615](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/103615)
8
+ [`fd239f714374`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fd239f714374) -
9
+ [ux] When table with left alignmnent is resized to be wider than line length, alignment
10
+ automatically changes to center.
11
+
3
12
  ## 7.16.7
4
13
 
5
14
  ### Patch Changes
@@ -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.updateWidthToWidest = exports.updateResizeHandleDecorations = exports.triggerUnlessTableHeader = exports.transformSliceToRemoveColumnsWidths = exports.transformSliceToAddTableHeaders = exports.transformSliceRemoveCellBackgroundColor = exports.showInsertRowButton = exports.showInsertColumnButton = exports.setTableRef = exports.setTableAlignment = exports.setMultipleCellAttrs = exports.setEditorFocus = exports.setCellAttr = exports.selectRows = exports.selectRow = exports.selectColumns = exports.selectColumn = exports.removeResizeHandleDecorations = exports.moveCursorBackward = exports.isInsideFirstCellOfRowOrColumn = exports.hideInsertColumnOrRowButton = exports.getTableSelectionType = exports.getTableElementMoveTypeBySlice = exports.deleteTableIfSelected = exports.deleteTable = exports.countCellsInSlice = exports.convertFirstRowToHeader = exports.autoSizeTable = exports.addResizeHandleDecorations = exports.addBoldInEmptyHeaderCells = void 0;
7
+ exports.updateWidthToWidest = exports.updateResizeHandleDecorations = exports.triggerUnlessTableHeader = exports.transformSliceToRemoveColumnsWidths = exports.transformSliceToAddTableHeaders = exports.transformSliceRemoveCellBackgroundColor = exports.showInsertRowButton = exports.showInsertColumnButton = exports.setTableRef = exports.setTableAlignmentWithTableContentWithPos = exports.setTableAlignment = exports.setMultipleCellAttrs = exports.setEditorFocus = exports.setCellAttr = exports.selectRows = exports.selectRow = exports.selectColumns = exports.selectColumn = exports.removeResizeHandleDecorations = exports.moveCursorBackward = exports.isInsideFirstCellOfRowOrColumn = exports.hideInsertColumnOrRowButton = exports.getTableSelectionType = exports.getTableElementMoveTypeBySlice = exports.deleteTableIfSelected = exports.deleteTable = exports.countCellsInSlice = exports.convertFirstRowToHeader = exports.autoSizeTable = exports.addResizeHandleDecorations = exports.addBoldInEmptyHeaderCells = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
@@ -600,4 +600,14 @@ var setTableAlignment = exports.setTableAlignment = function setTableAlignment(n
600
600
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
601
601
  return tr;
602
602
  };
603
+ };
604
+ var setTableAlignmentWithTableContentWithPos = exports.setTableAlignmentWithTableContentWithPos = function setTableAlignmentWithTableContentWithPos(newAlignment, tableNodeWithPos) {
605
+ return function (_ref3) {
606
+ var tr = _ref3.tr;
607
+ var nextTableAttrs = _objectSpread(_objectSpread({}, tableNodeWithPos.node.attrs), {}, {
608
+ layout: newAlignment
609
+ });
610
+ tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
611
+ return tr;
612
+ };
603
613
  };
@@ -73,6 +73,7 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
73
73
  className = _ref4.className,
74
74
  node = _ref4.node,
75
75
  containerWidth = _ref4.containerWidth,
76
+ lineLength = _ref4.lineLength,
76
77
  editorView = _ref4.editorView,
77
78
  getPos = _ref4.getPos,
78
79
  tableRef = _ref4.tableRef,
@@ -155,6 +156,7 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
155
156
  width: width,
156
157
  maxWidth: maxResizerWidth,
157
158
  containerWidth: containerWidth,
159
+ lineLength: lineLength,
158
160
  updateWidth: updateWidth,
159
161
  editorView: editorView,
160
162
  getPos: getPos,
@@ -197,7 +199,9 @@ var TableContainer = exports.TableContainer = function TableContainer(_ref5) {
197
199
  var children = _ref5.children,
198
200
  node = _ref5.node,
199
201
  className = _ref5.className,
200
- editorWidth = _ref5.containerWidth.width,
202
+ _ref5$containerWidth = _ref5.containerWidth,
203
+ editorWidth = _ref5$containerWidth.width,
204
+ lineLength = _ref5$containerWidth.lineLength,
201
205
  editorView = _ref5.editorView,
202
206
  getPos = _ref5.getPos,
203
207
  tableRef = _ref5.tableRef,
@@ -214,6 +218,7 @@ var TableContainer = exports.TableContainer = function TableContainer(_ref5) {
214
218
  className: className,
215
219
  node: node,
216
220
  containerWidth: editorWidth,
221
+ lineLength: lineLength,
217
222
  editorView: editorView,
218
223
  getPos: getPos,
219
224
  tableRef: tableRef,
@@ -18,6 +18,7 @@ var _keymaps = require("@atlaskit/editor-common/keymaps");
18
18
  var _messages = require("@atlaskit/editor-common/messages");
19
19
  var _resizer = require("@atlaskit/editor-common/resizer");
20
20
  var _utils = require("@atlaskit/editor-common/utils");
21
+ var _commands = require("@atlaskit/editor-prosemirror/commands");
21
22
  var _utils2 = require("@atlaskit/editor-tables/utils");
22
23
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
23
24
  var _misc = require("../commands/misc");
@@ -34,6 +35,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
34
35
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
35
36
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
36
37
  var RESIZE_STEP_VALUE = 10;
38
+ var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
37
39
  var handles = {
38
40
  right: true
39
41
  };
@@ -88,6 +90,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
88
90
  width = _ref.width,
89
91
  maxWidth = _ref.maxWidth,
90
92
  containerWidth = _ref.containerWidth,
93
+ lineLength = _ref.lineLength,
91
94
  updateWidth = _ref.updateWidth,
92
95
  onResizeStop = _ref.onResizeStop,
93
96
  onResizeStart = _ref.onResizeStart,
@@ -141,21 +144,37 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
141
144
  x: isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(containerWidth, isTableAlignmentEnabled) : _snapping.defaultSnappingWidths
142
145
  } : undefined;
143
146
  }, [snappingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, containerWidth]);
147
+ var switchToCenterAlignment = (0, _react.useCallback)(function (pos, node, newWidth, state, dispatch) {
148
+ if (isTableAlignmentEnabled && node && node.attrs.layout === _alignment.ALIGN_START && newWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH &&
149
+ // We don't want to switch alignment in Full-width editor
150
+ isResizing.current) {
151
+ var tableNodeWithPos = {
152
+ pos: pos,
153
+ node: node
154
+ };
155
+ var _tr = (0, _misc.setTableAlignmentWithTableContentWithPos)(_alignment.ALIGN_CENTER, tableNodeWithPos)(state);
156
+ if (_tr) {
157
+ dispatch(_tr);
158
+ }
159
+ return true;
160
+ }
161
+ return false;
162
+ }, [lineLength, isTableAlignmentEnabled, isResizing]);
144
163
  (0, _react.useEffect)(function () {
145
164
  return function () {
146
165
  // only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
147
166
  // deleted this table
148
167
  if (isResizing.current) {
149
168
  var dispatch = editorView.dispatch,
150
- _tr = editorView.state.tr;
169
+ _tr2 = editorView.state.tr;
151
170
  displayGapCursor(true);
152
171
  displayGuideline([]);
153
- _tr.setMeta(_tableWidth.pluginKey, {
172
+ _tr2.setMeta(_tableWidth.pluginKey, {
154
173
  resizing: false,
155
174
  tableLocalId: '',
156
175
  tableRef: null
157
176
  });
158
- dispatch(_tr);
177
+ dispatch(_tr2);
159
178
  }
160
179
  };
161
180
  }, [editorView, displayGuideline, displayGapCursor]);
@@ -211,10 +230,12 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
211
230
  })[0];
212
231
  var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
213
232
  var shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
214
- (0, _misc.updateWidthToWidest)((0, _defineProperty2.default)({}, currentTableNodeLocalId, shouldUpdateWidthToWidest))(state, dispatch);
233
+ (0, _commands.chainCommands)(function (state, dispatch) {
234
+ return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
235
+ }, (0, _misc.updateWidthToWidest)((0, _defineProperty2.default)({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
215
236
  updateWidth(shouldUpdateWidthToWidest ? _utils3.TABLE_MAX_WIDTH : newWidth);
216
237
  return newWidth;
217
- }, [countFrames, isTableScalingEnabled, isTableAlignmentEnabled, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos]);
238
+ }, [countFrames, isTableScalingEnabled, isTableAlignmentEnabled, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos, switchToCenterAlignment]);
218
239
  var scheduleResize = (0, _react.useMemo)(function () {
219
240
  return (0, _rafSchd.default)(handleResize);
220
241
  }, [handleResize]);
@@ -367,7 +388,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
367
388
  (_updateTooltip$curren = updateTooltip.current) === null || _updateTooltip$curren === void 0 || _updateTooltip$curren.call(updateTooltip);
368
389
  }
369
390
  }, [width]);
370
- var resizeRatio = !isTableAlignmentEnabled || isTableAlignmentEnabled && (0, _alignment.normaliseAlignment)(node.attrs.layout) === 'center' ? 2 : 1;
391
+ var resizeRatio = !isTableAlignmentEnabled || isTableAlignmentEnabled && (0, _alignment.normaliseAlignment)(node.attrs.layout) === _alignment.ALIGN_CENTER ? 2 : 1;
371
392
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_resizer.ResizerNext, {
372
393
  ref: resizerRef,
373
394
  enable: handles,
@@ -563,4 +563,14 @@ export const setTableAlignment = newAlignment => ({
563
563
  };
564
564
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
565
565
  return tr;
566
+ };
567
+ export const setTableAlignmentWithTableContentWithPos = (newAlignment, tableNodeWithPos) => ({
568
+ tr
569
+ }) => {
570
+ const nextTableAttrs = {
571
+ ...tableNodeWithPos.node.attrs,
572
+ layout: newAlignment
573
+ };
574
+ tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
575
+ return tr;
566
576
  };
@@ -65,6 +65,7 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
65
65
  className,
66
66
  node,
67
67
  containerWidth,
68
+ lineLength,
68
69
  editorView,
69
70
  getPos,
70
71
  tableRef,
@@ -146,6 +147,7 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
146
147
  width,
147
148
  maxWidth: maxResizerWidth,
148
149
  containerWidth,
150
+ lineLength,
149
151
  updateWidth,
150
152
  editorView,
151
153
  getPos,
@@ -189,7 +191,8 @@ export const TableContainer = ({
189
191
  node,
190
192
  className,
191
193
  containerWidth: {
192
- width: editorWidth
194
+ width: editorWidth,
195
+ lineLength
193
196
  },
194
197
  editorView,
195
198
  getPos,
@@ -208,6 +211,7 @@ export const TableContainer = ({
208
211
  className: className,
209
212
  node: node,
210
213
  containerWidth: editorWidth,
214
+ lineLength: lineLength,
211
215
  editorView: editorView,
212
216
  getPos: getPos,
213
217
  tableRef: tableRef,
@@ -8,18 +8,20 @@ import { focusTableResizer, ToolTipContent } from '@atlaskit/editor-common/keyma
8
8
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
9
9
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
10
10
  import { browser } from '@atlaskit/editor-common/utils';
11
+ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
11
12
  import { findTable } from '@atlaskit/editor-tables/utils';
12
13
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
- import { updateWidthToWidest } from '../commands/misc';
14
+ import { setTableAlignmentWithTableContentWithPos, updateWidthToWidest } from '../commands/misc';
14
15
  import { META_KEYS } from '../pm-plugins/table-analytics';
15
16
  import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
16
17
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
17
18
  import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
18
- import { normaliseAlignment } from '../utils/alignment';
19
+ import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
19
20
  import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
20
21
  import { defaultGuidelines, defaultGuidelinesForPreserveTable } from '../utils/guidelines';
21
22
  import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap } from '../utils/snapping';
22
23
  const RESIZE_STEP_VALUE = 10;
24
+ const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
23
25
  const handles = {
24
26
  right: true
25
27
  };
@@ -73,6 +75,7 @@ export const TableResizer = ({
73
75
  width,
74
76
  maxWidth,
75
77
  containerWidth,
78
+ lineLength,
76
79
  updateWidth,
77
80
  onResizeStop,
78
81
  onResizeStart,
@@ -128,6 +131,22 @@ export const TableResizer = ({
128
131
  const guidelineSnaps = useMemo(() => snappingEnabled ? {
129
132
  x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth, isTableAlignmentEnabled) : defaultSnappingWidths
130
133
  } : undefined, [snappingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, containerWidth]);
134
+ const switchToCenterAlignment = useCallback((pos, node, newWidth, state, dispatch) => {
135
+ if (isTableAlignmentEnabled && node && node.attrs.layout === ALIGN_START && newWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH &&
136
+ // We don't want to switch alignment in Full-width editor
137
+ isResizing.current) {
138
+ const tableNodeWithPos = {
139
+ pos,
140
+ node
141
+ };
142
+ const tr = setTableAlignmentWithTableContentWithPos(ALIGN_CENTER, tableNodeWithPos)(state);
143
+ if (tr) {
144
+ dispatch(tr);
145
+ }
146
+ return true;
147
+ }
148
+ return false;
149
+ }, [lineLength, isTableAlignmentEnabled, isResizing]);
131
150
  useEffect(() => {
132
151
  return () => {
133
152
  // only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
@@ -206,12 +225,14 @@ export const TableResizer = ({
206
225
  const fullWidthGuideline = defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled).filter(guideline => guideline.isFullWidth)[0];
207
226
  const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
208
227
  const shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
209
- updateWidthToWidest({
228
+ chainCommands((state, dispatch) => {
229
+ return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
230
+ }, updateWidthToWidest({
210
231
  [currentTableNodeLocalId]: shouldUpdateWidthToWidest
211
- })(state, dispatch);
232
+ }))(state, dispatch);
212
233
  updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
213
234
  return newWidth;
214
- }, [countFrames, isTableScalingEnabled, isTableAlignmentEnabled, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos]);
235
+ }, [countFrames, isTableScalingEnabled, isTableAlignmentEnabled, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos, switchToCenterAlignment]);
215
236
  const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
216
237
  const handleResizeStop = useCallback((originalState, delta) => {
217
238
  var _node$attrs$localId2, _node$attrs2;
@@ -365,7 +386,7 @@ export const TableResizer = ({
365
386
  (_updateTooltip$curren = updateTooltip.current) === null || _updateTooltip$curren === void 0 ? void 0 : _updateTooltip$curren.call(updateTooltip);
366
387
  }
367
388
  }, [width]);
368
- const resizeRatio = !isTableAlignmentEnabled || isTableAlignmentEnabled && normaliseAlignment(node.attrs.layout) === 'center' ? 2 : 1;
389
+ const resizeRatio = !isTableAlignmentEnabled || isTableAlignmentEnabled && normaliseAlignment(node.attrs.layout) === ALIGN_CENTER ? 2 : 1;
369
390
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ResizerNext, {
370
391
  ref: resizerRef,
371
392
  enable: handles,
@@ -593,4 +593,14 @@ export var setTableAlignment = function setTableAlignment(newAlignment) {
593
593
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
594
594
  return tr;
595
595
  };
596
+ };
597
+ export var setTableAlignmentWithTableContentWithPos = function setTableAlignmentWithTableContentWithPos(newAlignment, tableNodeWithPos) {
598
+ return function (_ref3) {
599
+ var tr = _ref3.tr;
600
+ var nextTableAttrs = _objectSpread(_objectSpread({}, tableNodeWithPos.node.attrs), {}, {
601
+ layout: newAlignment
602
+ });
603
+ tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
604
+ return tr;
605
+ };
596
606
  };
@@ -63,6 +63,7 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
63
63
  className = _ref4.className,
64
64
  node = _ref4.node,
65
65
  containerWidth = _ref4.containerWidth,
66
+ lineLength = _ref4.lineLength,
66
67
  editorView = _ref4.editorView,
67
68
  getPos = _ref4.getPos,
68
69
  tableRef = _ref4.tableRef,
@@ -145,6 +146,7 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
145
146
  width: width,
146
147
  maxWidth: maxResizerWidth,
147
148
  containerWidth: containerWidth,
149
+ lineLength: lineLength,
148
150
  updateWidth: updateWidth,
149
151
  editorView: editorView,
150
152
  getPos: getPos,
@@ -187,7 +189,9 @@ export var TableContainer = function TableContainer(_ref5) {
187
189
  var children = _ref5.children,
188
190
  node = _ref5.node,
189
191
  className = _ref5.className,
190
- editorWidth = _ref5.containerWidth.width,
192
+ _ref5$containerWidth = _ref5.containerWidth,
193
+ editorWidth = _ref5$containerWidth.width,
194
+ lineLength = _ref5$containerWidth.lineLength,
191
195
  editorView = _ref5.editorView,
192
196
  getPos = _ref5.getPos,
193
197
  tableRef = _ref5.tableRef,
@@ -204,6 +208,7 @@ export var TableContainer = function TableContainer(_ref5) {
204
208
  className: className,
205
209
  node: node,
206
210
  containerWidth: editorWidth,
211
+ lineLength: lineLength,
207
212
  editorView: editorView,
208
213
  getPos: getPos,
209
214
  tableRef: tableRef,
@@ -12,18 +12,20 @@ import { focusTableResizer, ToolTipContent } from '@atlaskit/editor-common/keyma
12
12
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
13
13
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
14
14
  import { browser } from '@atlaskit/editor-common/utils';
15
+ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
15
16
  import { findTable } from '@atlaskit/editor-tables/utils';
16
17
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
- import { updateWidthToWidest } from '../commands/misc';
18
+ import { setTableAlignmentWithTableContentWithPos, updateWidthToWidest } from '../commands/misc';
18
19
  import { META_KEYS } from '../pm-plugins/table-analytics';
19
20
  import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
20
21
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
21
22
  import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
22
- import { normaliseAlignment } from '../utils/alignment';
23
+ import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
23
24
  import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
24
25
  import { defaultGuidelines, defaultGuidelinesForPreserveTable } from '../utils/guidelines';
25
26
  import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap } from '../utils/snapping';
26
27
  var RESIZE_STEP_VALUE = 10;
28
+ var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
27
29
  var handles = {
28
30
  right: true
29
31
  };
@@ -78,6 +80,7 @@ export var TableResizer = function TableResizer(_ref) {
78
80
  width = _ref.width,
79
81
  maxWidth = _ref.maxWidth,
80
82
  containerWidth = _ref.containerWidth,
83
+ lineLength = _ref.lineLength,
81
84
  updateWidth = _ref.updateWidth,
82
85
  onResizeStop = _ref.onResizeStop,
83
86
  onResizeStart = _ref.onResizeStart,
@@ -131,21 +134,37 @@ export var TableResizer = function TableResizer(_ref) {
131
134
  x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth, isTableAlignmentEnabled) : defaultSnappingWidths
132
135
  } : undefined;
133
136
  }, [snappingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, containerWidth]);
137
+ var switchToCenterAlignment = useCallback(function (pos, node, newWidth, state, dispatch) {
138
+ if (isTableAlignmentEnabled && node && node.attrs.layout === ALIGN_START && newWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH &&
139
+ // We don't want to switch alignment in Full-width editor
140
+ isResizing.current) {
141
+ var tableNodeWithPos = {
142
+ pos: pos,
143
+ node: node
144
+ };
145
+ var _tr = setTableAlignmentWithTableContentWithPos(ALIGN_CENTER, tableNodeWithPos)(state);
146
+ if (_tr) {
147
+ dispatch(_tr);
148
+ }
149
+ return true;
150
+ }
151
+ return false;
152
+ }, [lineLength, isTableAlignmentEnabled, isResizing]);
134
153
  useEffect(function () {
135
154
  return function () {
136
155
  // only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
137
156
  // deleted this table
138
157
  if (isResizing.current) {
139
158
  var dispatch = editorView.dispatch,
140
- _tr = editorView.state.tr;
159
+ _tr2 = editorView.state.tr;
141
160
  displayGapCursor(true);
142
161
  displayGuideline([]);
143
- _tr.setMeta(tableWidthPluginKey, {
162
+ _tr2.setMeta(tableWidthPluginKey, {
144
163
  resizing: false,
145
164
  tableLocalId: '',
146
165
  tableRef: null
147
166
  });
148
- dispatch(_tr);
167
+ dispatch(_tr2);
149
168
  }
150
169
  };
151
170
  }, [editorView, displayGuideline, displayGapCursor]);
@@ -201,10 +220,12 @@ export var TableResizer = function TableResizer(_ref) {
201
220
  })[0];
202
221
  var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
203
222
  var shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
204
- updateWidthToWidest(_defineProperty({}, currentTableNodeLocalId, shouldUpdateWidthToWidest))(state, dispatch);
223
+ chainCommands(function (state, dispatch) {
224
+ return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
225
+ }, updateWidthToWidest(_defineProperty({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
205
226
  updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
206
227
  return newWidth;
207
- }, [countFrames, isTableScalingEnabled, isTableAlignmentEnabled, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos]);
228
+ }, [countFrames, isTableScalingEnabled, isTableAlignmentEnabled, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos, switchToCenterAlignment]);
208
229
  var scheduleResize = useMemo(function () {
209
230
  return rafSchd(handleResize);
210
231
  }, [handleResize]);
@@ -357,7 +378,7 @@ export var TableResizer = function TableResizer(_ref) {
357
378
  (_updateTooltip$curren = updateTooltip.current) === null || _updateTooltip$curren === void 0 || _updateTooltip$curren.call(updateTooltip);
358
379
  }
359
380
  }, [width]);
360
- var resizeRatio = !isTableAlignmentEnabled || isTableAlignmentEnabled && normaliseAlignment(node.attrs.layout) === 'center' ? 2 : 1;
381
+ var resizeRatio = !isTableAlignmentEnabled || isTableAlignmentEnabled && normaliseAlignment(node.attrs.layout) === ALIGN_CENTER ? 2 : 1;
361
382
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ResizerNext, {
362
383
  ref: resizerRef,
363
384
  enable: handles,
@@ -2,7 +2,7 @@ import type { TableLayout } from '@atlaskit/adf-schema';
2
2
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
3
  import type { Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
5
- import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import type { ContentNodeWithPos, NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { WidthToWidest } from '../types';
8
8
  export declare const setEditorFocus: (editorHasFocus: boolean) => Command;
@@ -37,3 +37,4 @@ export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTML
37
37
  export declare const addBoldInEmptyHeaderCells: (tableCellHeader: ContentNodeWithPos) => Command;
38
38
  export declare const updateWidthToWidest: (widthToWidest: WidthToWidest) => Command;
39
39
  export declare const setTableAlignment: (newAlignment: TableLayout) => EditorCommand;
40
+ export declare const setTableAlignmentWithTableContentWithPos: (newAlignment: TableLayout, tableNodeWithPos: NodeWithPos) => EditorCommand;
@@ -17,6 +17,7 @@ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContai
17
17
  } & React.RefAttributes<HTMLDivElement>>;
18
18
  type ResizableTableContainerProps = {
19
19
  containerWidth: number;
20
+ lineLength: number;
20
21
  node: PMNode;
21
22
  className: string;
22
23
  editorView: EditorView;
@@ -29,7 +30,7 @@ type ResizableTableContainerProps = {
29
30
  isTableScalingEnabled?: boolean;
30
31
  isTableAlignmentEnabled?: boolean;
31
32
  };
32
- export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, tableWrapperHeight, isWholeTableInDanger, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
33
+ export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, containerWidth, lineLength, editorView, getPos, tableRef, isResizing, pluginInjectionApi, tableWrapperHeight, isWholeTableInDanger, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
33
34
  type TableContainerProps = {
34
35
  node: PMNode;
35
36
  className: string;
@@ -46,5 +47,5 @@ type TableContainerProps = {
46
47
  isTableScalingEnabled?: boolean;
47
48
  isTableAlignmentEnabled?: boolean;
48
49
  };
49
- export declare const TableContainer: ({ children, node, className, containerWidth: { width: editorWidth }, editorView, getPos, tableRef, isNested, tableWrapperHeight, isResizing, pluginInjectionApi, isWholeTableInDanger, isTableResizingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
50
+ export declare const TableContainer: ({ children, node, className, containerWidth: { width: editorWidth, lineLength }, editorView, getPos, tableRef, isNested, tableWrapperHeight, isResizing, pluginInjectionApi, isWholeTableInDanger, isTableResizingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
50
51
  export {};
@@ -9,6 +9,7 @@ interface TableResizerProps {
9
9
  width: number;
10
10
  maxWidth: number;
11
11
  containerWidth: number;
12
+ lineLength: number;
12
13
  updateWidth: (width: number) => void;
13
14
  editorView: EditorView;
14
15
  getPos: () => number | undefined;
@@ -26,5 +27,5 @@ export interface TableResizerImprovementProps extends TableResizerProps {
26
27
  onResizeStop?: () => void;
27
28
  onResizeStart?: () => void;
28
29
  }
29
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
30
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
30
31
  export {};
@@ -2,7 +2,7 @@ import type { TableLayout } from '@atlaskit/adf-schema';
2
2
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
3
  import type { Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
5
- import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import type { ContentNodeWithPos, NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { WidthToWidest } from '../types';
8
8
  export declare const setEditorFocus: (editorHasFocus: boolean) => Command;
@@ -37,3 +37,4 @@ export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTML
37
37
  export declare const addBoldInEmptyHeaderCells: (tableCellHeader: ContentNodeWithPos) => Command;
38
38
  export declare const updateWidthToWidest: (widthToWidest: WidthToWidest) => Command;
39
39
  export declare const setTableAlignment: (newAlignment: TableLayout) => EditorCommand;
40
+ export declare const setTableAlignmentWithTableContentWithPos: (newAlignment: TableLayout, tableNodeWithPos: NodeWithPos) => EditorCommand;
@@ -17,6 +17,7 @@ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContai
17
17
  } & React.RefAttributes<HTMLDivElement>>;
18
18
  type ResizableTableContainerProps = {
19
19
  containerWidth: number;
20
+ lineLength: number;
20
21
  node: PMNode;
21
22
  className: string;
22
23
  editorView: EditorView;
@@ -29,7 +30,7 @@ type ResizableTableContainerProps = {
29
30
  isTableScalingEnabled?: boolean;
30
31
  isTableAlignmentEnabled?: boolean;
31
32
  };
32
- export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, tableWrapperHeight, isWholeTableInDanger, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
33
+ export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, containerWidth, lineLength, editorView, getPos, tableRef, isResizing, pluginInjectionApi, tableWrapperHeight, isWholeTableInDanger, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
33
34
  type TableContainerProps = {
34
35
  node: PMNode;
35
36
  className: string;
@@ -46,5 +47,5 @@ type TableContainerProps = {
46
47
  isTableScalingEnabled?: boolean;
47
48
  isTableAlignmentEnabled?: boolean;
48
49
  };
49
- export declare const TableContainer: ({ children, node, className, containerWidth: { width: editorWidth }, editorView, getPos, tableRef, isNested, tableWrapperHeight, isResizing, pluginInjectionApi, isWholeTableInDanger, isTableResizingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
50
+ export declare const TableContainer: ({ children, node, className, containerWidth: { width: editorWidth, lineLength }, editorView, getPos, tableRef, isNested, tableWrapperHeight, isResizing, pluginInjectionApi, isWholeTableInDanger, isTableResizingEnabled, isTableScalingEnabled, isTableAlignmentEnabled, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
50
51
  export {};
@@ -9,6 +9,7 @@ interface TableResizerProps {
9
9
  width: number;
10
10
  maxWidth: number;
11
11
  containerWidth: number;
12
+ lineLength: number;
12
13
  updateWidth: (width: number) => void;
13
14
  editorView: EditorView;
14
15
  getPos: () => number | undefined;
@@ -26,5 +27,5 @@ export interface TableResizerImprovementProps extends TableResizerProps {
26
27
  onResizeStop?: () => void;
27
28
  onResizeStart?: () => void;
28
29
  }
29
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
30
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
30
31
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.16.7",
3
+ "version": "7.16.8",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/adf-schema": "^36.10.7",
32
32
  "@atlaskit/button": "^17.17.0",
33
33
  "@atlaskit/custom-steps": "^0.2.0",
34
- "@atlaskit/editor-common": "^81.0.0",
34
+ "@atlaskit/editor-common": "^81.1.0",
35
35
  "@atlaskit/editor-palette": "1.6.0",
36
36
  "@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.2.0",
@@ -19,7 +19,10 @@ import type {
19
19
  Selection,
20
20
  Transaction,
21
21
  } from '@atlaskit/editor-prosemirror/state';
22
- import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
22
+ import type {
23
+ ContentNodeWithPos,
24
+ NodeWithPos,
25
+ } from '@atlaskit/editor-prosemirror/utils';
23
26
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
24
27
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
25
28
  import { TableMap } from '@atlaskit/editor-tables/table-map';
@@ -831,3 +834,19 @@ export const setTableAlignment =
831
834
 
832
835
  return tr;
833
836
  };
837
+
838
+ export const setTableAlignmentWithTableContentWithPos =
839
+ (newAlignment: TableLayout, tableNodeWithPos: NodeWithPos): EditorCommand =>
840
+ ({ tr }) => {
841
+ const nextTableAttrs = {
842
+ ...tableNodeWithPos.node.attrs,
843
+ layout: newAlignment,
844
+ };
845
+
846
+ tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta(
847
+ 'scrollIntoView',
848
+ false,
849
+ );
850
+
851
+ return tr;
852
+ };
@@ -109,6 +109,7 @@ const AlignmentTableContainerWrapper = ({
109
109
 
110
110
  type ResizableTableContainerProps = {
111
111
  containerWidth: number;
112
+ lineLength: number;
112
113
  node: PMNode;
113
114
  className: string;
114
115
  editorView: EditorView;
@@ -129,6 +130,7 @@ export const ResizableTableContainer = React.memo(
129
130
  className,
130
131
  node,
131
132
  containerWidth,
133
+ lineLength,
132
134
  editorView,
133
135
  getPos,
134
136
  tableRef,
@@ -246,6 +248,7 @@ export const ResizableTableContainer = React.memo(
246
248
  width,
247
249
  maxWidth: maxResizerWidth,
248
250
  containerWidth,
251
+ lineLength,
249
252
  updateWidth,
250
253
  editorView,
251
254
  getPos,
@@ -323,7 +326,7 @@ export const TableContainer = ({
323
326
  children,
324
327
  node,
325
328
  className,
326
- containerWidth: { width: editorWidth },
329
+ containerWidth: { width: editorWidth, lineLength },
327
330
  editorView,
328
331
  getPos,
329
332
  tableRef,
@@ -342,6 +345,7 @@ export const TableContainer = ({
342
345
  className={className}
343
346
  node={node}
344
347
  containerWidth={editorWidth!}
348
+ lineLength={lineLength!}
345
349
  editorView={editorView}
346
350
  getPos={getPos}
347
351
  tableRef={tableRef}
@@ -24,6 +24,7 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
24
24
  import type { HandleResize, HandleSize } from '@atlaskit/editor-common/resizer';
25
25
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
26
26
  import { browser } from '@atlaskit/editor-common/utils';
27
+ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
27
28
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
28
29
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
29
30
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -31,7 +32,10 @@ import { findTable } from '@atlaskit/editor-tables/utils';
31
32
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
32
33
  import { token } from '@atlaskit/tokens';
33
34
 
34
- import { updateWidthToWidest } from '../commands/misc';
35
+ import {
36
+ setTableAlignmentWithTableContentWithPos,
37
+ updateWidthToWidest,
38
+ } from '../commands/misc';
35
39
  import { META_KEYS } from '../pm-plugins/table-analytics';
36
40
  import {
37
41
  COLUMN_MIN_WIDTH,
@@ -48,7 +52,11 @@ import {
48
52
  TABLE_HIGHLIGHT_TOLERANCE,
49
53
  TABLE_SNAP_GAP,
50
54
  } from '../ui/consts';
51
- import { normaliseAlignment } from '../utils/alignment';
55
+ import {
56
+ ALIGN_CENTER,
57
+ ALIGN_START,
58
+ normaliseAlignment,
59
+ } from '../utils/alignment';
52
60
  import {
53
61
  generateResizedPayload,
54
62
  generateResizeFrameRatePayloads,
@@ -68,6 +76,7 @@ interface TableResizerProps {
68
76
  width: number;
69
77
  maxWidth: number;
70
78
  containerWidth: number;
79
+ lineLength: number;
71
80
  updateWidth: (width: number) => void;
72
81
  editorView: EditorView;
73
82
  getPos: () => number | undefined;
@@ -93,6 +102,8 @@ type ResizerNextHandler = React.ElementRef<typeof ResizerNext>;
93
102
 
94
103
  const RESIZE_STEP_VALUE = 10;
95
104
 
105
+ const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
106
+
96
107
  const handles = { right: true };
97
108
  const handleStyles = {
98
109
  right: {
@@ -160,6 +171,7 @@ export const TableResizer = ({
160
171
  width,
161
172
  maxWidth,
162
173
  containerWidth,
174
+ lineLength,
163
175
  updateWidth,
164
176
  onResizeStop,
165
177
  onResizeStart,
@@ -249,6 +261,34 @@ export const TableResizer = ({
249
261
  ],
250
262
  );
251
263
 
264
+ const switchToCenterAlignment = useCallback(
265
+ (pos, node, newWidth, state, dispatch) => {
266
+ if (
267
+ isTableAlignmentEnabled &&
268
+ node &&
269
+ node.attrs.layout === ALIGN_START &&
270
+ newWidth > lineLength &&
271
+ lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH && // We don't want to switch alignment in Full-width editor
272
+ isResizing.current
273
+ ) {
274
+ const tableNodeWithPos = { pos, node };
275
+ const tr = setTableAlignmentWithTableContentWithPos(
276
+ ALIGN_CENTER,
277
+ tableNodeWithPos,
278
+ )(state);
279
+
280
+ if (tr) {
281
+ dispatch(tr);
282
+ }
283
+
284
+ return true;
285
+ }
286
+
287
+ return false;
288
+ },
289
+ [lineLength, isTableAlignmentEnabled, isResizing],
290
+ );
291
+
252
292
  useEffect(() => {
253
293
  return () => {
254
294
  // only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
@@ -378,9 +418,14 @@ export const TableResizer = ({
378
418
  const shouldUpdateWidthToWidest =
379
419
  !!isTableScalingEnabled && isFullWidthGuidelineActive;
380
420
 
381
- updateWidthToWidest({
382
- [currentTableNodeLocalId]: shouldUpdateWidthToWidest,
383
- })(state, dispatch);
421
+ chainCommands(
422
+ (state, dispatch) => {
423
+ return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
424
+ },
425
+ updateWidthToWidest({
426
+ [currentTableNodeLocalId]: shouldUpdateWidthToWidest,
427
+ }),
428
+ )(state, dispatch);
384
429
 
385
430
  updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
386
431
 
@@ -397,6 +442,7 @@ export const TableResizer = ({
397
442
  containerWidth,
398
443
  updateWidth,
399
444
  getPos,
445
+ switchToCenterAlignment,
400
446
  ],
401
447
  );
402
448
 
@@ -628,7 +674,7 @@ export const TableResizer = ({
628
674
  const resizeRatio =
629
675
  !isTableAlignmentEnabled ||
630
676
  (isTableAlignmentEnabled &&
631
- normaliseAlignment(node.attrs.layout) === 'center')
677
+ normaliseAlignment(node.attrs.layout) === ALIGN_CENTER)
632
678
  ? 2
633
679
  : 1;
634
680