@atlaskit/editor-plugin-table 7.16.6 → 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.
Files changed (32) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/commands/misc.js +11 -1
  3. package/dist/cjs/nodeviews/TableContainer.js +6 -1
  4. package/dist/cjs/nodeviews/TableResizer.js +35 -14
  5. package/dist/cjs/utils/guidelines.js +3 -1
  6. package/dist/cjs/utils/snapping.js +7 -2
  7. package/dist/es2019/commands/misc.js +10 -0
  8. package/dist/es2019/nodeviews/TableContainer.js +5 -1
  9. package/dist/es2019/nodeviews/TableResizer.js +35 -14
  10. package/dist/es2019/utils/guidelines.js +4 -1
  11. package/dist/es2019/utils/snapping.js +7 -4
  12. package/dist/esm/commands/misc.js +10 -0
  13. package/dist/esm/nodeviews/TableContainer.js +6 -1
  14. package/dist/esm/nodeviews/TableResizer.js +37 -16
  15. package/dist/esm/utils/guidelines.js +3 -1
  16. package/dist/esm/utils/snapping.js +7 -2
  17. package/dist/types/commands/misc.d.ts +2 -1
  18. package/dist/types/nodeviews/TableContainer.d.ts +3 -2
  19. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  20. package/dist/types/utils/guidelines.d.ts +1 -1
  21. package/dist/types/utils/snapping.d.ts +2 -2
  22. package/dist/types-ts4.5/commands/misc.d.ts +2 -1
  23. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +3 -2
  24. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  25. package/dist/types-ts4.5/utils/guidelines.d.ts +1 -1
  26. package/dist/types-ts4.5/utils/snapping.d.ts +2 -2
  27. package/package.json +3 -3
  28. package/src/commands/misc.ts +20 -1
  29. package/src/nodeviews/TableContainer.tsx +5 -1
  30. package/src/nodeviews/TableResizer.tsx +87 -13
  31. package/src/utils/guidelines.ts +11 -3
  32. package/src/utils/snapping.ts +16 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
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
+
12
+ ## 7.16.7
13
+
14
+ ### Patch Changes
15
+
16
+ - [#103100](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/103100)
17
+ [`07d25a4f1dd9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/07d25a4f1dd9) -
18
+ Add new parameter to remove inner guidelines, enabled when table alignment is enabled
19
+ - Updated dependencies
20
+
3
21
  ## 7.16.6
4
22
 
5
23
  ### 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,
@@ -132,30 +135,46 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
132
135
  keys = _ref3.keys;
133
136
  if (gap !== currentGap.current) {
134
137
  currentGap.current = gap;
135
- var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth) : _guidelines.defaultGuidelines, containerWidth);
138
+ var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth, isTableAlignmentEnabled) : _guidelines.defaultGuidelines, containerWidth);
136
139
  displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _consts.TABLE_SNAP_GAP, keys, visibleGuidelines));
137
140
  }
138
- }, [isTableScalingEnabled, containerWidth, displayGuideline]);
141
+ }, [isTableScalingEnabled, isTableAlignmentEnabled, containerWidth, displayGuideline]);
139
142
  var guidelineSnaps = (0, _react.useMemo)(function () {
140
143
  return snappingEnabled ? {
141
- x: isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(containerWidth) : _snapping.defaultSnappingWidths
144
+ x: isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(containerWidth, isTableAlignmentEnabled) : _snapping.defaultSnappingWidths
142
145
  } : undefined;
143
- }, [snappingEnabled, isTableScalingEnabled, containerWidth]);
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]);
@@ -174,12 +193,12 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
174
193
  name: _analytics.TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
175
194
  });
176
195
  dispatch(tr);
177
- var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth) : _guidelines.defaultGuidelines, containerWidth);
196
+ var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth, isTableAlignmentEnabled) : _guidelines.defaultGuidelines, containerWidth);
178
197
  setSnappingEnabled(displayGuideline(visibleGuidelines));
179
198
  if (onResizeStart) {
180
199
  onResizeStart();
181
200
  }
182
- }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
201
+ }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, isTableAlignmentEnabled, containerWidth, displayGuideline, onResizeStart]);
183
202
  var handleResize = (0, _react.useCallback)(function (originalState, delta) {
184
203
  var _node$attrs$localId, _node$attrs;
185
204
  countFrames();
@@ -199,22 +218,24 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
199
218
  start: pos + 1,
200
219
  parentWidth: newWidth
201
220
  }, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
202
- var closestSnap = (0, _snapping.findClosestSnap)(newWidth, isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(containerWidth) : _snapping.defaultSnappingWidths, isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth) : _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE);
221
+ var closestSnap = (0, _snapping.findClosestSnap)(newWidth, isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(containerWidth, isTableAlignmentEnabled) : _snapping.defaultSnappingWidths, isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth, isTableAlignmentEnabled) : _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE);
203
222
  updateActiveGuidelines(closestSnap);
204
223
 
205
224
  // When snapping to the full width guideline, resize the table to be 1800px
206
225
  var state = editorView.state,
207
226
  dispatch = editorView.dispatch;
208
227
  var currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
209
- var fullWidthGuideline = (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth).filter(function (guideline) {
228
+ var fullWidthGuideline = (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth, isTableAlignmentEnabled).filter(function (guideline) {
210
229
  return guideline.isFullWidth;
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, 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,
@@ -12,5 +12,7 @@ var _snapping = require("./snapping");
12
12
  // If we don't do this then the guidelines will not align correctly to the edge of the table
13
13
  var defaultGuidelines = exports.defaultGuidelines = (0, _guideline.createFixedGuidelinesFromLengths)([0].concat((0, _toConsumableArray2.default)((0, _snapping.calculateDefaultSnappings)(-1))));
14
14
  var defaultGuidelinesForPreserveTable = exports.defaultGuidelinesForPreserveTable = function defaultGuidelinesForPreserveTable(editorContainerWidth) {
15
- return (0, _guideline.createFixedGuidelinesFromLengths)([0].concat((0, _toConsumableArray2.default)((0, _snapping.calculateDefaultTablePreserveSnappings)(-1, editorContainerWidth))), undefined, true);
15
+ var excludeInnerGuidelines = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
16
+ var lengths = (0, _snapping.calculateDefaultTablePreserveSnappings)(-1, editorContainerWidth, excludeInnerGuidelines);
17
+ return (0, _guideline.createFixedGuidelinesFromLengths)(lengths, undefined, true);
16
18
  };
@@ -24,14 +24,19 @@ var calculateDefaultSnappings = exports.calculateDefaultSnappings = function cal
24
24
  var calculateDefaultTablePreserveSnappings = exports.calculateDefaultTablePreserveSnappings = function calculateDefaultTablePreserveSnappings() {
25
25
  var lengthOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
26
26
  var editorContainerWith = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _editorSharedStyles.akEditorFullWidthLayoutWidth;
27
+ var excludeInnerGuidelines = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
27
28
  var dynamicFullWidthLine = editorContainerWith - _editorSharedStyles.akEditorGutterPadding * 2 >= _editorSharedStyles.akEditorFullWidthLayoutWidth ? _editorSharedStyles.akEditorFullWidthLayoutWidth : editorContainerWith - _editorSharedStyles.akEditorGutterPadding * 2 - _consts.tableResizerWidth;
28
- return [].concat((0, _toConsumableArray2.default)(calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, _editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset)), [_editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset, _editorSharedStyles.akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset]);
29
+ if (excludeInnerGuidelines) {
30
+ return [_editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset, _editorSharedStyles.akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset];
31
+ }
32
+ return [0].concat((0, _toConsumableArray2.default)(calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, _editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset)), [_editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset, _editorSharedStyles.akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset]);
29
33
  };
30
34
  var defaultSnappingWidths = exports.defaultSnappingWidths = calculateDefaultSnappings();
31
35
 
32
36
  // FF TablePreserve for defaultSnappingWidths
33
37
  var defaultTablePreserveSnappingWidths = exports.defaultTablePreserveSnappingWidths = function defaultTablePreserveSnappingWidths(editorContainerWidth) {
34
- return editorContainerWidth - _editorSharedStyles.akEditorGutterPadding * 2 > _editorSharedStyles.akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(0, editorContainerWidth);
38
+ var excludeInnerGuidelines = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
39
+ return editorContainerWidth - _editorSharedStyles.akEditorGutterPadding * 2 > _editorSharedStyles.akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(0, editorContainerWidth, excludeInnerGuidelines);
35
40
  };
36
41
 
37
42
  /**
@@ -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,
@@ -121,13 +124,29 @@ export const TableResizer = ({
121
124
  }) => {
122
125
  if (gap !== currentGap.current) {
123
126
  currentGap.current = gap;
124
- const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, containerWidth);
127
+ const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled) : defaultGuidelines, containerWidth);
125
128
  displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
126
129
  }
127
- }, [isTableScalingEnabled, containerWidth, displayGuideline]);
130
+ }, [isTableScalingEnabled, isTableAlignmentEnabled, containerWidth, displayGuideline]);
128
131
  const guidelineSnaps = useMemo(() => snappingEnabled ? {
129
- x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth) : defaultSnappingWidths
130
- } : undefined, [snappingEnabled, isTableScalingEnabled, containerWidth]);
132
+ x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth, isTableAlignmentEnabled) : defaultSnappingWidths
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
@@ -169,12 +188,12 @@ export const TableResizer = ({
169
188
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
170
189
  });
171
190
  dispatch(tr);
172
- const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, containerWidth);
191
+ const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled) : defaultGuidelines, containerWidth);
173
192
  setSnappingEnabled(displayGuideline(visibleGuidelines));
174
193
  if (onResizeStart) {
175
194
  onResizeStart();
176
195
  }
177
- }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
196
+ }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, isTableAlignmentEnabled, containerWidth, displayGuideline, onResizeStart]);
178
197
  const handleResize = useCallback((originalState, delta) => {
179
198
  var _node$attrs$localId, _node$attrs;
180
199
  countFrames();
@@ -194,7 +213,7 @@ export const TableResizer = ({
194
213
  start: pos + 1,
195
214
  parentWidth: newWidth
196
215
  }, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
197
- const closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
216
+ const closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth, isTableAlignmentEnabled) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
198
217
  updateActiveGuidelines(closestSnap);
199
218
 
200
219
  // When snapping to the full width guideline, resize the table to be 1800px
@@ -203,15 +222,17 @@ export const TableResizer = ({
203
222
  dispatch
204
223
  } = editorView;
205
224
  const currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
206
- const fullWidthGuideline = defaultGuidelinesForPreserveTable(containerWidth).filter(guideline => guideline.isFullWidth)[0];
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, 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,
@@ -4,4 +4,7 @@ import { calculateDefaultSnappings, calculateDefaultTablePreserveSnappings } fro
4
4
  // NOTE: We have to take 1 pixel off every length due to the fact that the tbody is 1px smaller then the table container.
5
5
  // If we don't do this then the guidelines will not align correctly to the edge of the table
6
6
  export const defaultGuidelines = createFixedGuidelinesFromLengths([0, ...calculateDefaultSnappings(-1)]);
7
- export const defaultGuidelinesForPreserveTable = editorContainerWidth => createFixedGuidelinesFromLengths([0, ...calculateDefaultTablePreserveSnappings(-1, editorContainerWidth)], undefined, true);
7
+ export const defaultGuidelinesForPreserveTable = (editorContainerWidth, excludeInnerGuidelines = false) => {
8
+ const lengths = calculateDefaultTablePreserveSnappings(-1, editorContainerWidth, excludeInnerGuidelines);
9
+ return createFixedGuidelinesFromLengths(lengths, undefined, true);
10
+ };
@@ -6,15 +6,18 @@ const calculateSubSnappingWidths = (totalLanes, totalWidth) => new Array(Math.ro
6
6
  export const calculateDefaultSnappings = (lengthOffset = 0) => [...calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset), akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, akEditorFullWidthLayoutWidth + lengthOffset];
7
7
 
8
8
  // FF TablePreserve for calculateDefaultSnappings
9
- export const calculateDefaultTablePreserveSnappings = (lengthOffset = 0, editorContainerWith = akEditorFullWidthLayoutWidth) => {
9
+ export const calculateDefaultTablePreserveSnappings = (lengthOffset = 0, editorContainerWith = akEditorFullWidthLayoutWidth, excludeInnerGuidelines = false) => {
10
10
  const dynamicFullWidthLine = editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth ? akEditorFullWidthLayoutWidth : editorContainerWith - akEditorGutterPadding * 2 - tableResizerWidth;
11
- return [...calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset), akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset];
11
+ if (excludeInnerGuidelines) {
12
+ return [akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset];
13
+ }
14
+ return [0, ...calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset), akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset];
12
15
  };
13
16
  export const defaultSnappingWidths = calculateDefaultSnappings();
14
17
 
15
18
  // FF TablePreserve for defaultSnappingWidths
16
- export const defaultTablePreserveSnappingWidths = editorContainerWidth => {
17
- return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(0, editorContainerWidth);
19
+ export const defaultTablePreserveSnappingWidths = (editorContainerWidth, excludeInnerGuidelines = false) => {
20
+ return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(0, editorContainerWidth, excludeInnerGuidelines);
18
21
  };
19
22
 
20
23
  /**
@@ -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,
@@ -122,30 +125,46 @@ export var TableResizer = function TableResizer(_ref) {
122
125
  keys = _ref3.keys;
123
126
  if (gap !== currentGap.current) {
124
127
  currentGap.current = gap;
125
- var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, containerWidth);
128
+ var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled) : defaultGuidelines, containerWidth);
126
129
  displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
127
130
  }
128
- }, [isTableScalingEnabled, containerWidth, displayGuideline]);
131
+ }, [isTableScalingEnabled, isTableAlignmentEnabled, containerWidth, displayGuideline]);
129
132
  var guidelineSnaps = useMemo(function () {
130
133
  return snappingEnabled ? {
131
- x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth) : defaultSnappingWidths
134
+ x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth, isTableAlignmentEnabled) : defaultSnappingWidths
132
135
  } : undefined;
133
- }, [snappingEnabled, isTableScalingEnabled, containerWidth]);
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]);
@@ -164,12 +183,12 @@ export var TableResizer = function TableResizer(_ref) {
164
183
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
165
184
  });
166
185
  dispatch(tr);
167
- var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, containerWidth);
186
+ var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled) : defaultGuidelines, containerWidth);
168
187
  setSnappingEnabled(displayGuideline(visibleGuidelines));
169
188
  if (onResizeStart) {
170
189
  onResizeStart();
171
190
  }
172
- }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
191
+ }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, isTableAlignmentEnabled, containerWidth, displayGuideline, onResizeStart]);
173
192
  var handleResize = useCallback(function (originalState, delta) {
174
193
  var _node$attrs$localId, _node$attrs;
175
194
  countFrames();
@@ -189,22 +208,24 @@ export var TableResizer = function TableResizer(_ref) {
189
208
  start: pos + 1,
190
209
  parentWidth: newWidth
191
210
  }, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
192
- var closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
211
+ var closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth, isTableAlignmentEnabled) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
193
212
  updateActiveGuidelines(closestSnap);
194
213
 
195
214
  // When snapping to the full width guideline, resize the table to be 1800px
196
215
  var state = editorView.state,
197
216
  dispatch = editorView.dispatch;
198
217
  var currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
199
- var fullWidthGuideline = defaultGuidelinesForPreserveTable(containerWidth).filter(function (guideline) {
218
+ var fullWidthGuideline = defaultGuidelinesForPreserveTable(containerWidth, isTableAlignmentEnabled).filter(function (guideline) {
200
219
  return guideline.isFullWidth;
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, 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,
@@ -6,5 +6,7 @@ import { calculateDefaultSnappings, calculateDefaultTablePreserveSnappings } fro
6
6
  // If we don't do this then the guidelines will not align correctly to the edge of the table
7
7
  export var defaultGuidelines = createFixedGuidelinesFromLengths([0].concat(_toConsumableArray(calculateDefaultSnappings(-1))));
8
8
  export var defaultGuidelinesForPreserveTable = function defaultGuidelinesForPreserveTable(editorContainerWidth) {
9
- return createFixedGuidelinesFromLengths([0].concat(_toConsumableArray(calculateDefaultTablePreserveSnappings(-1, editorContainerWidth))), undefined, true);
9
+ var excludeInnerGuidelines = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
10
+ var lengths = calculateDefaultTablePreserveSnappings(-1, editorContainerWidth, excludeInnerGuidelines);
11
+ return createFixedGuidelinesFromLengths(lengths, undefined, true);
10
12
  };
@@ -17,14 +17,19 @@ export var calculateDefaultSnappings = function calculateDefaultSnappings() {
17
17
  export var calculateDefaultTablePreserveSnappings = function calculateDefaultTablePreserveSnappings() {
18
18
  var lengthOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
19
19
  var editorContainerWith = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : akEditorFullWidthLayoutWidth;
20
+ var excludeInnerGuidelines = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
20
21
  var dynamicFullWidthLine = editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth ? akEditorFullWidthLayoutWidth : editorContainerWith - akEditorGutterPadding * 2 - tableResizerWidth;
21
- return [].concat(_toConsumableArray(calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset)), [akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset]);
22
+ if (excludeInnerGuidelines) {
23
+ return [akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset];
24
+ }
25
+ return [0].concat(_toConsumableArray(calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset)), [akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, dynamicFullWidthLine - lengthOffset]);
22
26
  };
23
27
  export var defaultSnappingWidths = calculateDefaultSnappings();
24
28
 
25
29
  // FF TablePreserve for defaultSnappingWidths
26
30
  export var defaultTablePreserveSnappingWidths = function defaultTablePreserveSnappingWidths(editorContainerWidth) {
27
- return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(0, editorContainerWidth);
31
+ var excludeInnerGuidelines = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
32
+ return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(0, editorContainerWidth, excludeInnerGuidelines);
28
33
  };
29
34
 
30
35
  /**
@@ -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 {};
@@ -1,3 +1,3 @@
1
1
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
2
  export declare const defaultGuidelines: GuidelineConfig[];
3
- export declare const defaultGuidelinesForPreserveTable: (editorContainerWidth: number) => GuidelineConfig[];
3
+ export declare const defaultGuidelinesForPreserveTable: (editorContainerWidth: number, excludeInnerGuidelines?: boolean) => GuidelineConfig[];
@@ -1,8 +1,8 @@
1
1
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
2
  export declare const calculateDefaultSnappings: (lengthOffset?: number) => number[];
3
- export declare const calculateDefaultTablePreserveSnappings: (lengthOffset?: number, editorContainerWith?: number) => number[];
3
+ export declare const calculateDefaultTablePreserveSnappings: (lengthOffset?: number, editorContainerWith?: number, excludeInnerGuidelines?: boolean) => number[];
4
4
  export declare const defaultSnappingWidths: number[];
5
- export declare const defaultTablePreserveSnappingWidths: (editorContainerWidth: number) => number[];
5
+ export declare const defaultTablePreserveSnappingWidths: (editorContainerWidth: number, excludeInnerGuidelines?: boolean) => number[];
6
6
  /**
7
7
  * Returns keys of guidelines that are closest to the table and withthin the snapGap
8
8
  */
@@ -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 {};
@@ -1,3 +1,3 @@
1
1
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
2
  export declare const defaultGuidelines: GuidelineConfig[];
3
- export declare const defaultGuidelinesForPreserveTable: (editorContainerWidth: number) => GuidelineConfig[];
3
+ export declare const defaultGuidelinesForPreserveTable: (editorContainerWidth: number, excludeInnerGuidelines?: boolean) => GuidelineConfig[];
@@ -1,8 +1,8 @@
1
1
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
2
  export declare const calculateDefaultSnappings: (lengthOffset?: number) => number[];
3
- export declare const calculateDefaultTablePreserveSnappings: (lengthOffset?: number, editorContainerWith?: number) => number[];
3
+ export declare const calculateDefaultTablePreserveSnappings: (lengthOffset?: number, editorContainerWith?: number, excludeInnerGuidelines?: boolean) => number[];
4
4
  export declare const defaultSnappingWidths: number[];
5
- export declare const defaultTablePreserveSnappingWidths: (editorContainerWidth: number) => number[];
5
+ export declare const defaultTablePreserveSnappingWidths: (editorContainerWidth: number, excludeInnerGuidelines?: boolean) => number[];
6
6
  /**
7
7
  * Returns keys of guidelines that are closest to the table and withthin the snapGap
8
8
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.16.6",
3
+ "version": "7.16.8",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^36.10.7",
32
- "@atlaskit/button": "^17.16.0",
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,
@@ -203,7 +215,10 @@ export const TableResizer = ({
203
215
  currentGap.current = gap;
204
216
  const visibleGuidelines = getVisibleGuidelines(
205
217
  isTableScalingEnabled
206
- ? defaultGuidelinesForPreserveTable(containerWidth)
218
+ ? defaultGuidelinesForPreserveTable(
219
+ containerWidth,
220
+ isTableAlignmentEnabled,
221
+ )
207
222
  : defaultGuidelines,
208
223
  containerWidth,
209
224
  );
@@ -218,7 +233,12 @@ export const TableResizer = ({
218
233
  );
219
234
  }
220
235
  },
221
- [isTableScalingEnabled, containerWidth, displayGuideline],
236
+ [
237
+ isTableScalingEnabled,
238
+ isTableAlignmentEnabled,
239
+ containerWidth,
240
+ displayGuideline,
241
+ ],
222
242
  );
223
243
 
224
244
  const guidelineSnaps = useMemo(
@@ -226,11 +246,47 @@ export const TableResizer = ({
226
246
  snappingEnabled
227
247
  ? {
228
248
  x: isTableScalingEnabled
229
- ? defaultTablePreserveSnappingWidths(containerWidth)
249
+ ? defaultTablePreserveSnappingWidths(
250
+ containerWidth,
251
+ isTableAlignmentEnabled,
252
+ )
230
253
  : defaultSnappingWidths,
231
254
  }
232
255
  : undefined,
233
- [snappingEnabled, isTableScalingEnabled, containerWidth],
256
+ [
257
+ snappingEnabled,
258
+ isTableScalingEnabled,
259
+ isTableAlignmentEnabled,
260
+ containerWidth,
261
+ ],
262
+ );
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],
234
290
  );
235
291
 
236
292
  useEffect(() => {
@@ -276,7 +332,10 @@ export const TableResizer = ({
276
332
 
277
333
  const visibleGuidelines = getVisibleGuidelines(
278
334
  isTableScalingEnabled
279
- ? defaultGuidelinesForPreserveTable(containerWidth)
335
+ ? defaultGuidelinesForPreserveTable(
336
+ containerWidth,
337
+ isTableAlignmentEnabled,
338
+ )
280
339
  : defaultGuidelines,
281
340
  containerWidth,
282
341
  );
@@ -292,6 +351,7 @@ export const TableResizer = ({
292
351
  node.attrs.localId,
293
352
  tableRef,
294
353
  isTableScalingEnabled,
354
+ isTableAlignmentEnabled,
295
355
  containerWidth,
296
356
  displayGuideline,
297
357
  onResizeStart,
@@ -326,10 +386,16 @@ export const TableResizer = ({
326
386
  const closestSnap = findClosestSnap(
327
387
  newWidth,
328
388
  isTableScalingEnabled
329
- ? defaultTablePreserveSnappingWidths(containerWidth)
389
+ ? defaultTablePreserveSnappingWidths(
390
+ containerWidth,
391
+ isTableAlignmentEnabled,
392
+ )
330
393
  : defaultSnappingWidths,
331
394
  isTableScalingEnabled
332
- ? defaultGuidelinesForPreserveTable(containerWidth)
395
+ ? defaultGuidelinesForPreserveTable(
396
+ containerWidth,
397
+ isTableAlignmentEnabled,
398
+ )
333
399
  : defaultGuidelines,
334
400
  TABLE_HIGHLIGHT_GAP,
335
401
  TABLE_HIGHLIGHT_TOLERANCE,
@@ -343,6 +409,7 @@ export const TableResizer = ({
343
409
 
344
410
  const fullWidthGuideline = defaultGuidelinesForPreserveTable(
345
411
  containerWidth,
412
+ isTableAlignmentEnabled,
346
413
  ).filter((guideline) => guideline.isFullWidth)[0];
347
414
 
348
415
  const isFullWidthGuidelineActive = closestSnap.keys.includes(
@@ -351,9 +418,14 @@ export const TableResizer = ({
351
418
  const shouldUpdateWidthToWidest =
352
419
  !!isTableScalingEnabled && isFullWidthGuidelineActive;
353
420
 
354
- updateWidthToWidest({
355
- [currentTableNodeLocalId]: shouldUpdateWidthToWidest,
356
- })(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);
357
429
 
358
430
  updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
359
431
 
@@ -362,6 +434,7 @@ export const TableResizer = ({
362
434
  [
363
435
  countFrames,
364
436
  isTableScalingEnabled,
437
+ isTableAlignmentEnabled,
365
438
  tableRef,
366
439
  node,
367
440
  editorView,
@@ -369,6 +442,7 @@ export const TableResizer = ({
369
442
  containerWidth,
370
443
  updateWidth,
371
444
  getPos,
445
+ switchToCenterAlignment,
372
446
  ],
373
447
  );
374
448
 
@@ -600,7 +674,7 @@ export const TableResizer = ({
600
674
  const resizeRatio =
601
675
  !isTableAlignmentEnabled ||
602
676
  (isTableAlignmentEnabled &&
603
- normaliseAlignment(node.attrs.layout) === 'center')
677
+ normaliseAlignment(node.attrs.layout) === ALIGN_CENTER)
604
678
  ? 2
605
679
  : 1;
606
680
 
@@ -15,9 +15,17 @@ export const defaultGuidelines = createFixedGuidelinesFromLengths([
15
15
 
16
16
  export const defaultGuidelinesForPreserveTable = (
17
17
  editorContainerWidth: number,
18
- ) =>
19
- createFixedGuidelinesFromLengths(
20
- [0, ...calculateDefaultTablePreserveSnappings(-1, editorContainerWidth)],
18
+ excludeInnerGuidelines = false,
19
+ ) => {
20
+ const lengths = calculateDefaultTablePreserveSnappings(
21
+ -1,
22
+ editorContainerWidth,
23
+ excludeInnerGuidelines,
24
+ );
25
+
26
+ return createFixedGuidelinesFromLengths(
27
+ lengths,
21
28
  undefined,
22
29
  true,
23
30
  ) as GuidelineConfig[];
31
+ };
@@ -30,6 +30,7 @@ export const calculateDefaultSnappings = (lengthOffset: number = 0) => [
30
30
  export const calculateDefaultTablePreserveSnappings = (
31
31
  lengthOffset: number = 0,
32
32
  editorContainerWith: number = akEditorFullWidthLayoutWidth,
33
+ excludeInnerGuidelines = false,
33
34
  ) => {
34
35
  const dynamicFullWidthLine =
35
36
  editorContainerWith - akEditorGutterPadding * 2 >=
@@ -37,7 +38,16 @@ export const calculateDefaultTablePreserveSnappings = (
37
38
  ? akEditorFullWidthLayoutWidth
38
39
  : editorContainerWith - akEditorGutterPadding * 2 - tableResizerWidth;
39
40
 
41
+ if (excludeInnerGuidelines) {
42
+ return [
43
+ akEditorDefaultLayoutWidth + lengthOffset,
44
+ akEditorCalculatedWideLayoutWidth + lengthOffset,
45
+ dynamicFullWidthLine - lengthOffset,
46
+ ];
47
+ }
48
+
40
49
  return [
50
+ 0,
41
51
  ...calculateSubSnappingWidths(
42
52
  numberOfLanesInDefaultLayoutWidth,
43
53
  akEditorDefaultLayoutWidth + lengthOffset,
@@ -53,11 +63,16 @@ export const defaultSnappingWidths = calculateDefaultSnappings();
53
63
  // FF TablePreserve for defaultSnappingWidths
54
64
  export const defaultTablePreserveSnappingWidths = (
55
65
  editorContainerWidth: number,
66
+ excludeInnerGuidelines = false,
56
67
  ) => {
57
68
  return editorContainerWidth - akEditorGutterPadding * 2 >
58
69
  akEditorFullWidthLayoutWidth
59
70
  ? calculateDefaultSnappings()
60
- : calculateDefaultTablePreserveSnappings(0, editorContainerWidth);
71
+ : calculateDefaultTablePreserveSnappings(
72
+ 0,
73
+ editorContainerWidth,
74
+ excludeInnerGuidelines,
75
+ );
61
76
  };
62
77
 
63
78
  /**