@atlaskit/editor-plugin-table 7.25.19 → 7.25.21

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,29 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.25.21
4
+
5
+ ### Patch Changes
6
+
7
+ - [#137821](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137821)
8
+ [`4d2173e85f8a6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4d2173e85f8a6) -
9
+ [ux] Fix full-width detection in Comment editor
10
+ - [#137928](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137928)
11
+ [`8b30e4c176e08`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8b30e4c176e08) -
12
+ ED-24841: Fixed number column table shows a scroll in comment editor
13
+ - [#138118](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/138118)
14
+ [`5e4d9eb1aefe4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5e4d9eb1aefe4) -
15
+ NOISSUE: Upgrades editor React peer dependencies to v18
16
+ - Updated dependencies
17
+
18
+ ## 7.25.20
19
+
20
+ ### Patch Changes
21
+
22
+ - [#137344](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137344)
23
+ [`00c81bdf34c46`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/00c81bdf34c46) -
24
+ [ux] Fixes an issue where tables that existed before "Support Table in Comment" are displayed as
25
+ centered 760px width tables when FF for Support Table in Comment is enabled.
26
+
3
27
  ## 7.25.19
4
28
 
5
29
  ### Patch Changes
@@ -551,7 +551,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
551
551
  var _this$props$options4, _this$props$options5, _this$props$options6, _this$props$options7;
552
552
  var resizeState = (0, _utils4.getResizeState)({
553
553
  minWidth: _utils4.COLUMN_MIN_WIDTH,
554
- maxSize: tableRenderWidth,
554
+ // When numbered column enabled, we need to subtract the width of the numbered column
555
+ maxSize: tableNode.attrs.isNumberColumnEnabled ? tableRenderWidth - _editorSharedStyles.akEditorTableNumberColumnWidth : tableRenderWidth,
555
556
  table: tableNode,
556
557
  tableRef: this.table,
557
558
  start: start,
@@ -260,15 +260,9 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
260
260
  if (typeof pos !== 'number') {
261
261
  return;
262
262
  }
263
- (0, _utils2.previewScaleTable)(tableRef, {
264
- node: node,
265
- prevNode: node,
266
- start: pos + 1,
267
- parentWidth: newWidth
268
- }, editorView.domAtPos.bind(editorView), isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isCommentEditor);
269
263
  var editorContainerWidth = isFullWidthModeEnabled ? lineLength + 2 * (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() : containerWidth;
270
- var closestSnap = (0, _snapping.findClosestSnap)(newWidth, isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(_snapping.PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : _snapping.defaultSnappingWidths, isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE);
271
- updateActiveGuidelines(closestSnap);
264
+ var closestSnap = !isCommentEditor && (0, _snapping.findClosestSnap)(newWidth, isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(_snapping.PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : _snapping.defaultSnappingWidths, isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE);
265
+ closestSnap && updateActiveGuidelines(closestSnap);
272
266
 
273
267
  // When snapping to the full width guideline, resize the table to be 1800px
274
268
  var state = editorView.state,
@@ -277,9 +271,16 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
277
271
  var fullWidthGuideline = (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(function (guideline) {
278
272
  return guideline.isFullWidth;
279
273
  })[0];
280
- var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
281
- var tableMaxWidth = isCommentEditor ? containerWidth - _utils2.TABLE_OFFSET_IN_COMMENT_EDITOR : _utils2.TABLE_MAX_WIDTH;
282
- var shouldUpdateWidthToWidest = isCommentEditor && tableMaxWidth === newWidth || !!isTableScalingEnabled && isFullWidthGuidelineActive;
274
+ var isFullWidthGuidelineActive = closestSnap && closestSnap.keys.includes(fullWidthGuideline.key);
275
+ var tableMaxWidth = isCommentEditor ? Math.floor(containerWidth - _utils2.TABLE_OFFSET_IN_COMMENT_EDITOR) : _utils2.TABLE_MAX_WIDTH;
276
+ var shouldUpdateWidthToWidest = isCommentEditor ? tableMaxWidth <= newWidth : !!isTableScalingEnabled && isFullWidthGuidelineActive;
277
+ var previewParentWidth = isCommentEditor && shouldUpdateWidthToWidest ? tableMaxWidth : newWidth;
278
+ (0, _utils2.previewScaleTable)(tableRef, {
279
+ node: node,
280
+ prevNode: node,
281
+ start: pos + 1,
282
+ parentWidth: previewParentWidth
283
+ }, editorView.domAtPos.bind(editorView), isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isCommentEditor);
283
284
  (0, _commands.chainCommands)(function (state, dispatch) {
284
285
  return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
285
286
  }, (0, _misc.updateWidthToWidest)((0, _defineProperty2.default)({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
@@ -36,6 +36,7 @@ var _tableLocalId = require("./pm-plugins/table-local-id");
36
36
  var _tableResizing = require("./pm-plugins/table-resizing");
37
37
  var _tableSelectionKeymap = require("./pm-plugins/table-selection-keymap");
38
38
  var _tableWidth = require("./pm-plugins/table-width");
39
+ var _tableWidthInCommentFix = require("./pm-plugins/table-width-in-comment-fix");
39
40
  var _viewModeSort = require("./pm-plugins/view-mode-sort");
40
41
  var _toDOM = require("./toDOM");
41
42
  var _toolbar = require("./toolbar");
@@ -290,21 +291,28 @@ var tablesPlugin = function tablesPlugin(_ref) {
290
291
  dispatch = _ref14.dispatch;
291
292
  return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
292
293
  }
294
+ }, {
295
+ name: 'tableWidthInCommentFix',
296
+ plugin: function plugin(_ref15) {
297
+ var _options$isTableAlign2;
298
+ var dispatch = _ref15.dispatch;
299
+ return options !== null && options !== void 0 && options.tableResizingEnabled && options !== null && options !== void 0 && options.isCommentEditor ? (0, _tableWidthInCommentFix.createPlugin)(dispatch, (_options$isTableAlign2 = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign2 !== void 0 ? _options$isTableAlign2 : false) : undefined;
300
+ }
293
301
  },
294
302
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
295
303
  {
296
304
  name: 'tableOverflowAnalyticsPlugin',
297
- plugin: function plugin(_ref15) {
305
+ plugin: function plugin(_ref16) {
298
306
  var _options$tableResizin;
299
- var dispatch = _ref15.dispatch,
300
- dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
307
+ var dispatch = _ref16.dispatch,
308
+ dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
301
309
  return (0, _tableAnalytics.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
302
310
  }
303
311
  }, {
304
312
  name: 'tableAnalyticsPlugin',
305
- plugin: function plugin(_ref16) {
306
- var dispatch = _ref16.dispatch,
307
- dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
313
+ plugin: function plugin(_ref17) {
314
+ var dispatch = _ref17.dispatch,
315
+ dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
308
316
  return (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent);
309
317
  }
310
318
  }, {
@@ -335,13 +343,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
335
343
  }
336
344
  return plugins;
337
345
  },
338
- contentComponent: function contentComponent(_ref17) {
346
+ contentComponent: function contentComponent(_ref18) {
339
347
  var _api$featureFlags;
340
- var editorView = _ref17.editorView,
341
- popupsMountPoint = _ref17.popupsMountPoint,
342
- popupsBoundariesElement = _ref17.popupsBoundariesElement,
343
- popupsScrollableElement = _ref17.popupsScrollableElement,
344
- dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
348
+ var editorView = _ref18.editorView,
349
+ popupsMountPoint = _ref18.popupsMountPoint,
350
+ popupsBoundariesElement = _ref18.popupsBoundariesElement,
351
+ popupsScrollableElement = _ref18.popupsScrollableElement,
352
+ dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
345
353
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
346
354
  component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
347
355
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -357,32 +365,32 @@ var tablesPlugin = function tablesPlugin(_ref) {
357
365
  stickyHeadersState: _stickyHeaders.pluginKey,
358
366
  dragAndDropState: _dragAndDrop.pluginKey
359
367
  },
360
- render: function render(_ref18) {
361
- var resizingPluginState = _ref18.tableResizingPluginState,
362
- stickyHeadersState = _ref18.stickyHeadersState,
363
- tablePluginState = _ref18.tablePluginState,
364
- tableWidthPluginState = _ref18.tableWidthPluginState,
365
- dragAndDropState = _ref18.dragAndDropState;
368
+ render: function render(_ref19) {
369
+ var resizingPluginState = _ref19.tableResizingPluginState,
370
+ stickyHeadersState = _ref19.stickyHeadersState,
371
+ tablePluginState = _ref19.tablePluginState,
372
+ tableWidthPluginState = _ref19.tableWidthPluginState,
373
+ dragAndDropState = _ref19.dragAndDropState;
366
374
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
367
375
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
368
376
  var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
369
377
  var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
370
378
  var isResizing = isColumnResizing || isTableResizing;
371
379
  var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
372
- var _ref19 = tablePluginState,
373
- tableNode = _ref19.tableNode,
374
- tablePos = _ref19.tablePos,
375
- targetCellPosition = _ref19.targetCellPosition,
376
- isContextualMenuOpen = _ref19.isContextualMenuOpen,
377
- tableRef = _ref19.tableRef,
378
- pluginConfig = _ref19.pluginConfig,
379
- insertColumnButtonIndex = _ref19.insertColumnButtonIndex,
380
- insertRowButtonIndex = _ref19.insertRowButtonIndex,
381
- isHeaderColumnEnabled = _ref19.isHeaderColumnEnabled,
382
- isHeaderRowEnabled = _ref19.isHeaderRowEnabled,
383
- isDragAndDropEnabled = _ref19.isDragAndDropEnabled,
384
- tableWrapperTarget = _ref19.tableWrapperTarget,
385
- isCellMenuOpenByKeyboard = _ref19.isCellMenuOpenByKeyboard;
380
+ var _ref20 = tablePluginState,
381
+ tableNode = _ref20.tableNode,
382
+ tablePos = _ref20.tablePos,
383
+ targetCellPosition = _ref20.targetCellPosition,
384
+ isContextualMenuOpen = _ref20.isContextualMenuOpen,
385
+ tableRef = _ref20.tableRef,
386
+ pluginConfig = _ref20.pluginConfig,
387
+ insertColumnButtonIndex = _ref20.insertColumnButtonIndex,
388
+ insertRowButtonIndex = _ref20.insertRowButtonIndex,
389
+ isHeaderColumnEnabled = _ref20.isHeaderColumnEnabled,
390
+ isHeaderRowEnabled = _ref20.isHeaderRowEnabled,
391
+ isDragAndDropEnabled = _ref20.isDragAndDropEnabled,
392
+ tableWrapperTarget = _ref20.tableWrapperTarget,
393
+ isCellMenuOpenByKeyboard = _ref20.isCellMenuOpenByKeyboard;
386
394
  var allowControls = pluginConfig.allowControls;
387
395
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
388
396
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard && (0, _platformFeatureFlags.fg)('platform_editor_a11y_table_context_menu')) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/_react.default.createElement(_FloatingContextualButton.default, {
@@ -475,8 +483,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
475
483
  }));
476
484
  },
477
485
  pluginsOptions: {
478
- quickInsert: function quickInsert(_ref20) {
479
- var formatMessage = _ref20.formatMessage;
486
+ quickInsert: function quickInsert(_ref21) {
487
+ var formatMessage = _ref21.formatMessage;
480
488
  return [{
481
489
  id: 'table',
482
490
  title: formatMessage(_messages.toolbarInsertBlockMessages.table),
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.pluginKey = exports.createPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
10
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _state = require("@atlaskit/editor-prosemirror/state");
12
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
13
+ var _alignment = require("../utils/alignment");
14
+ 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; }
15
+ 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; } /*
16
+ Existing legacy tables in Comment editor have set attributes:
17
+ - width = 760
18
+ - layout = 'default'.
19
+
20
+ When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
21
+ It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
22
+ the editor container until a user decided to edit their old comment and set a custom table width themselves.
23
+
24
+ This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
25
+ existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
26
+ */
27
+ var pluginKey = exports.pluginKey = new _state.PluginKey('tableWidthInCommentFixPlugin');
28
+ var getPluginState = function getPluginState(state) {
29
+ return state && pluginKey.getState(state);
30
+ };
31
+ var createPlugin = exports.createPlugin = function createPlugin(dispatch, isTableAlignmentEnabled) {
32
+ return new _safePlugin.SafePlugin({
33
+ key: pluginKey,
34
+ state: {
35
+ init: function init() {
36
+ return {
37
+ documentHasLoadedOnce: false
38
+ };
39
+ },
40
+ apply: function apply(tr, pluginState) {
41
+ var meta = tr.getMeta(pluginKey);
42
+ if (meta) {
43
+ var keys = Object.keys(meta);
44
+ var changed = keys.some(function (key) {
45
+ return pluginState[key] !== meta[key];
46
+ });
47
+ if (changed) {
48
+ var newState = _objectSpread(_objectSpread({}, pluginState), meta);
49
+ dispatch(pluginKey, newState);
50
+ return newState;
51
+ }
52
+ }
53
+ return pluginState;
54
+ }
55
+ },
56
+ view: function view() {
57
+ return {
58
+ update: function update(editorView) {
59
+ var state = editorView.state;
60
+ var pluginState = getPluginState(state);
61
+ if (!pluginState) {
62
+ return;
63
+ }
64
+ var documentHasLoadedOnce = pluginState.documentHasLoadedOnce;
65
+ if (documentHasLoadedOnce) {
66
+ return;
67
+ }
68
+ var table = state.schema.nodes.table;
69
+ (0, _rafSchd.default)(function () {
70
+ var tr = editorView.state.tr;
71
+ var tableWidthAndLayoutUpdated = false;
72
+ editorView.state.doc.descendants(function (node, pos) {
73
+ var isTable = node.type === table;
74
+ var width = node.attrs.width;
75
+ var layout = node.attrs.layout;
76
+ if (isTable && width === _editorSharedStyles.akEditorDefaultLayoutWidth && layout === 'default') {
77
+ tableWidthAndLayoutUpdated = true;
78
+ tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
79
+ width: null,
80
+ layout: isTableAlignmentEnabled ? _alignment.ALIGN_START : 'default'
81
+ }));
82
+ return false;
83
+ }
84
+ // Returning false here because don't need to change nested tables
85
+ return false;
86
+ });
87
+ if (tableWidthAndLayoutUpdated) {
88
+ tr.setMeta('addToHistory', false);
89
+ editorView.dispatch(tr);
90
+ }
91
+ })();
92
+ editorView.dispatch(state.tr.setMeta(pluginKey, {
93
+ documentHasLoadedOnce: true
94
+ }));
95
+ }
96
+ };
97
+ }
98
+ });
99
+ };
@@ -9,7 +9,7 @@ import { tintDirtyTransaction } from '@atlaskit/editor-common/collab';
9
9
  import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
10
10
  import { tableMarginSides } from '@atlaskit/editor-common/styles';
11
11
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
12
- import { akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
12
+ import { akEditorTableNumberColumnWidth, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
13
13
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
14
14
  import { fg } from '@atlaskit/platform-feature-flags';
15
15
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
@@ -532,7 +532,8 @@ class TableComponent extends React.Component {
532
532
  var _this$props$options4, _this$props$options5, _this$props$options6, _this$props$options7;
533
533
  const resizeState = getResizeState({
534
534
  minWidth: COLUMN_MIN_WIDTH,
535
- maxSize: tableRenderWidth,
535
+ // When numbered column enabled, we need to subtract the width of the numbered column
536
+ maxSize: tableNode.attrs.isNumberColumnEnabled ? tableRenderWidth - akEditorTableNumberColumnWidth : tableRenderWidth,
536
537
  table: tableNode,
537
538
  tableRef: this.table,
538
539
  start,
@@ -253,15 +253,9 @@ export const TableResizer = ({
253
253
  if (typeof pos !== 'number') {
254
254
  return;
255
255
  }
256
- previewScaleTable(tableRef, {
257
- node,
258
- prevNode: node,
259
- start: pos + 1,
260
- parentWidth: newWidth
261
- }, editorView.domAtPos.bind(editorView), isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isCommentEditor);
262
256
  const editorContainerWidth = isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPaddingDynamic() : containerWidth;
263
- const closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
264
- updateActiveGuidelines(closestSnap);
257
+ const closestSnap = !isCommentEditor && findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
258
+ closestSnap && updateActiveGuidelines(closestSnap);
265
259
 
266
260
  // When snapping to the full width guideline, resize the table to be 1800px
267
261
  const {
@@ -270,9 +264,16 @@ export const TableResizer = ({
270
264
  } = editorView;
271
265
  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 : '';
272
266
  const fullWidthGuideline = defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(guideline => guideline.isFullWidth)[0];
273
- const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
274
- const tableMaxWidth = isCommentEditor ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR : TABLE_MAX_WIDTH;
275
- const shouldUpdateWidthToWidest = isCommentEditor && tableMaxWidth === newWidth || !!isTableScalingEnabled && isFullWidthGuidelineActive;
267
+ const isFullWidthGuidelineActive = closestSnap && closestSnap.keys.includes(fullWidthGuideline.key);
268
+ const tableMaxWidth = isCommentEditor ? Math.floor(containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR) : TABLE_MAX_WIDTH;
269
+ const shouldUpdateWidthToWidest = isCommentEditor ? tableMaxWidth <= newWidth : !!isTableScalingEnabled && isFullWidthGuidelineActive;
270
+ const previewParentWidth = isCommentEditor && shouldUpdateWidthToWidest ? tableMaxWidth : newWidth;
271
+ previewScaleTable(tableRef, {
272
+ node,
273
+ prevNode: node,
274
+ start: pos + 1,
275
+ parentWidth: previewParentWidth
276
+ }, editorView.domAtPos.bind(editorView), isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isCommentEditor);
276
277
  chainCommands((state, dispatch) => {
277
278
  return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
278
279
  }, updateWidthToWidest({
@@ -28,6 +28,7 @@ import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-loc
28
28
  import { createPlugin as createFlexiResizingPlugin, getPluginState as getFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
29
29
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
30
30
  import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
31
+ import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
31
32
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
32
33
  import { tableNodeSpecWithFixedToDOM } from './toDOM';
33
34
  import { getToolbarConfig } from './toolbar';
@@ -278,6 +279,14 @@ const tablesPlugin = ({
278
279
  var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign, _options$isCommentEdi;
279
280
  return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
280
281
  }
282
+ }, {
283
+ name: 'tableWidthInCommentFix',
284
+ plugin: ({
285
+ dispatch
286
+ }) => {
287
+ var _options$isTableAlign2;
288
+ return options !== null && options !== void 0 && options.tableResizingEnabled && options !== null && options !== void 0 && options.isCommentEditor ? createTableWidthInCommentFixPlugin(dispatch, (_options$isTableAlign2 = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign2 !== void 0 ? _options$isTableAlign2 : false) : undefined;
289
+ }
281
290
  },
282
291
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
283
292
  {
@@ -0,0 +1,100 @@
1
+ /*
2
+ Existing legacy tables in Comment editor have set attributes:
3
+ - width = 760
4
+ - layout = 'default'.
5
+
6
+ When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
7
+ It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
8
+ the editor container until a user decided to edit their old comment and set a custom table width themselves.
9
+
10
+ This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
11
+ existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
12
+ */
13
+
14
+ import rafSchedule from 'raf-schd';
15
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
16
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
17
+ import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
18
+ import { ALIGN_START } from '../utils/alignment';
19
+ export const pluginKey = new PluginKey('tableWidthInCommentFixPlugin');
20
+ const getPluginState = state => state && pluginKey.getState(state);
21
+ const createPlugin = (dispatch, isTableAlignmentEnabled) => {
22
+ return new SafePlugin({
23
+ key: pluginKey,
24
+ state: {
25
+ init() {
26
+ return {
27
+ documentHasLoadedOnce: false
28
+ };
29
+ },
30
+ apply(tr, pluginState) {
31
+ const meta = tr.getMeta(pluginKey);
32
+ if (meta) {
33
+ const keys = Object.keys(meta);
34
+ const changed = keys.some(key => {
35
+ return pluginState[key] !== meta[key];
36
+ });
37
+ if (changed) {
38
+ const newState = {
39
+ ...pluginState,
40
+ ...meta
41
+ };
42
+ dispatch(pluginKey, newState);
43
+ return newState;
44
+ }
45
+ }
46
+ return pluginState;
47
+ }
48
+ },
49
+ view: () => {
50
+ return {
51
+ update(editorView) {
52
+ const {
53
+ state
54
+ } = editorView;
55
+ const pluginState = getPluginState(state);
56
+ if (!pluginState) {
57
+ return;
58
+ }
59
+ const {
60
+ documentHasLoadedOnce
61
+ } = pluginState;
62
+ if (documentHasLoadedOnce) {
63
+ return;
64
+ }
65
+ const {
66
+ table
67
+ } = state.schema.nodes;
68
+ rafSchedule(() => {
69
+ const tr = editorView.state.tr;
70
+ let tableWidthAndLayoutUpdated = false;
71
+ editorView.state.doc.descendants((node, pos) => {
72
+ const isTable = node.type === table;
73
+ const width = node.attrs.width;
74
+ const layout = node.attrs.layout;
75
+ if (isTable && width === akEditorDefaultLayoutWidth && layout === 'default') {
76
+ tableWidthAndLayoutUpdated = true;
77
+ tr.setNodeMarkup(pos, undefined, {
78
+ ...node.attrs,
79
+ width: null,
80
+ layout: isTableAlignmentEnabled ? ALIGN_START : 'default'
81
+ });
82
+ return false;
83
+ }
84
+ // Returning false here because don't need to change nested tables
85
+ return false;
86
+ });
87
+ if (tableWidthAndLayoutUpdated) {
88
+ tr.setMeta('addToHistory', false);
89
+ editorView.dispatch(tr);
90
+ }
91
+ })();
92
+ editorView.dispatch(state.tr.setMeta(pluginKey, {
93
+ documentHasLoadedOnce: true
94
+ }));
95
+ }
96
+ };
97
+ }
98
+ });
99
+ };
100
+ export { createPlugin };
@@ -23,7 +23,7 @@ import { tintDirtyTransaction } from '@atlaskit/editor-common/collab';
23
23
  import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
24
24
  import { tableMarginSides } from '@atlaskit/editor-common/styles';
25
25
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
26
- import { akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
26
+ import { akEditorTableNumberColumnWidth, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
27
27
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
28
28
  import { fg } from '@atlaskit/platform-feature-flags';
29
29
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
@@ -544,7 +544,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
544
544
  var _this$props$options4, _this$props$options5, _this$props$options6, _this$props$options7;
545
545
  var resizeState = getResizeState({
546
546
  minWidth: COLUMN_MIN_WIDTH,
547
- maxSize: tableRenderWidth,
547
+ // When numbered column enabled, we need to subtract the width of the numbered column
548
+ maxSize: tableNode.attrs.isNumberColumnEnabled ? tableRenderWidth - akEditorTableNumberColumnWidth : tableRenderWidth,
548
549
  table: tableNode,
549
550
  tableRef: this.table,
550
551
  start: start,
@@ -250,15 +250,9 @@ export var TableResizer = function TableResizer(_ref) {
250
250
  if (typeof pos !== 'number') {
251
251
  return;
252
252
  }
253
- previewScaleTable(tableRef, {
254
- node: node,
255
- prevNode: node,
256
- start: pos + 1,
257
- parentWidth: newWidth
258
- }, editorView.domAtPos.bind(editorView), isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isCommentEditor);
259
253
  var editorContainerWidth = isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPaddingDynamic() : containerWidth;
260
- var closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
261
- updateActiveGuidelines(closestSnap);
254
+ var closestSnap = !isCommentEditor && findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
255
+ closestSnap && updateActiveGuidelines(closestSnap);
262
256
 
263
257
  // When snapping to the full width guideline, resize the table to be 1800px
264
258
  var state = editorView.state,
@@ -267,9 +261,16 @@ export var TableResizer = function TableResizer(_ref) {
267
261
  var fullWidthGuideline = defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(function (guideline) {
268
262
  return guideline.isFullWidth;
269
263
  })[0];
270
- var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
271
- var tableMaxWidth = isCommentEditor ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR : TABLE_MAX_WIDTH;
272
- var shouldUpdateWidthToWidest = isCommentEditor && tableMaxWidth === newWidth || !!isTableScalingEnabled && isFullWidthGuidelineActive;
264
+ var isFullWidthGuidelineActive = closestSnap && closestSnap.keys.includes(fullWidthGuideline.key);
265
+ var tableMaxWidth = isCommentEditor ? Math.floor(containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR) : TABLE_MAX_WIDTH;
266
+ var shouldUpdateWidthToWidest = isCommentEditor ? tableMaxWidth <= newWidth : !!isTableScalingEnabled && isFullWidthGuidelineActive;
267
+ var previewParentWidth = isCommentEditor && shouldUpdateWidthToWidest ? tableMaxWidth : newWidth;
268
+ previewScaleTable(tableRef, {
269
+ node: node,
270
+ prevNode: node,
271
+ start: pos + 1,
272
+ parentWidth: previewParentWidth
273
+ }, editorView.domAtPos.bind(editorView), isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isCommentEditor);
273
274
  chainCommands(function (state, dispatch) {
274
275
  return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
275
276
  }, updateWidthToWidest(_defineProperty({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
@@ -31,6 +31,7 @@ import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-loc
31
31
  import { createPlugin as createFlexiResizingPlugin, getPluginState as getFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
32
32
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
33
33
  import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
34
+ import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
34
35
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
35
36
  import { tableNodeSpecWithFixedToDOM } from './toDOM';
36
37
  import { getToolbarConfig } from './toolbar';
@@ -283,21 +284,28 @@ var tablesPlugin = function tablesPlugin(_ref) {
283
284
  dispatch = _ref14.dispatch;
284
285
  return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
285
286
  }
287
+ }, {
288
+ name: 'tableWidthInCommentFix',
289
+ plugin: function plugin(_ref15) {
290
+ var _options$isTableAlign2;
291
+ var dispatch = _ref15.dispatch;
292
+ return options !== null && options !== void 0 && options.tableResizingEnabled && options !== null && options !== void 0 && options.isCommentEditor ? createTableWidthInCommentFixPlugin(dispatch, (_options$isTableAlign2 = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign2 !== void 0 ? _options$isTableAlign2 : false) : undefined;
293
+ }
286
294
  },
287
295
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
288
296
  {
289
297
  name: 'tableOverflowAnalyticsPlugin',
290
- plugin: function plugin(_ref15) {
298
+ plugin: function plugin(_ref16) {
291
299
  var _options$tableResizin;
292
- var dispatch = _ref15.dispatch,
293
- dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
300
+ var dispatch = _ref16.dispatch,
301
+ dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
294
302
  return createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
295
303
  }
296
304
  }, {
297
305
  name: 'tableAnalyticsPlugin',
298
- plugin: function plugin(_ref16) {
299
- var dispatch = _ref16.dispatch,
300
- dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
306
+ plugin: function plugin(_ref17) {
307
+ var dispatch = _ref17.dispatch,
308
+ dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
301
309
  return createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent);
302
310
  }
303
311
  }, {
@@ -328,13 +336,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
328
336
  }
329
337
  return plugins;
330
338
  },
331
- contentComponent: function contentComponent(_ref17) {
339
+ contentComponent: function contentComponent(_ref18) {
332
340
  var _api$featureFlags;
333
- var editorView = _ref17.editorView,
334
- popupsMountPoint = _ref17.popupsMountPoint,
335
- popupsBoundariesElement = _ref17.popupsBoundariesElement,
336
- popupsScrollableElement = _ref17.popupsScrollableElement,
337
- dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
341
+ var editorView = _ref18.editorView,
342
+ popupsMountPoint = _ref18.popupsMountPoint,
343
+ popupsBoundariesElement = _ref18.popupsBoundariesElement,
344
+ popupsScrollableElement = _ref18.popupsScrollableElement,
345
+ dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
338
346
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
339
347
  component: ACTION_SUBJECT.TABLES_PLUGIN,
340
348
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -350,32 +358,32 @@ var tablesPlugin = function tablesPlugin(_ref) {
350
358
  stickyHeadersState: stickyHeadersPluginKey,
351
359
  dragAndDropState: dragAndDropPluginKey
352
360
  },
353
- render: function render(_ref18) {
354
- var resizingPluginState = _ref18.tableResizingPluginState,
355
- stickyHeadersState = _ref18.stickyHeadersState,
356
- tablePluginState = _ref18.tablePluginState,
357
- tableWidthPluginState = _ref18.tableWidthPluginState,
358
- dragAndDropState = _ref18.dragAndDropState;
361
+ render: function render(_ref19) {
362
+ var resizingPluginState = _ref19.tableResizingPluginState,
363
+ stickyHeadersState = _ref19.stickyHeadersState,
364
+ tablePluginState = _ref19.tablePluginState,
365
+ tableWidthPluginState = _ref19.tableWidthPluginState,
366
+ dragAndDropState = _ref19.dragAndDropState;
359
367
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
360
368
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
361
369
  var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
362
370
  var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
363
371
  var isResizing = isColumnResizing || isTableResizing;
364
372
  var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
365
- var _ref19 = tablePluginState,
366
- tableNode = _ref19.tableNode,
367
- tablePos = _ref19.tablePos,
368
- targetCellPosition = _ref19.targetCellPosition,
369
- isContextualMenuOpen = _ref19.isContextualMenuOpen,
370
- tableRef = _ref19.tableRef,
371
- pluginConfig = _ref19.pluginConfig,
372
- insertColumnButtonIndex = _ref19.insertColumnButtonIndex,
373
- insertRowButtonIndex = _ref19.insertRowButtonIndex,
374
- isHeaderColumnEnabled = _ref19.isHeaderColumnEnabled,
375
- isHeaderRowEnabled = _ref19.isHeaderRowEnabled,
376
- isDragAndDropEnabled = _ref19.isDragAndDropEnabled,
377
- tableWrapperTarget = _ref19.tableWrapperTarget,
378
- isCellMenuOpenByKeyboard = _ref19.isCellMenuOpenByKeyboard;
373
+ var _ref20 = tablePluginState,
374
+ tableNode = _ref20.tableNode,
375
+ tablePos = _ref20.tablePos,
376
+ targetCellPosition = _ref20.targetCellPosition,
377
+ isContextualMenuOpen = _ref20.isContextualMenuOpen,
378
+ tableRef = _ref20.tableRef,
379
+ pluginConfig = _ref20.pluginConfig,
380
+ insertColumnButtonIndex = _ref20.insertColumnButtonIndex,
381
+ insertRowButtonIndex = _ref20.insertRowButtonIndex,
382
+ isHeaderColumnEnabled = _ref20.isHeaderColumnEnabled,
383
+ isHeaderRowEnabled = _ref20.isHeaderRowEnabled,
384
+ isDragAndDropEnabled = _ref20.isDragAndDropEnabled,
385
+ tableWrapperTarget = _ref20.tableWrapperTarget,
386
+ isCellMenuOpenByKeyboard = _ref20.isCellMenuOpenByKeyboard;
379
387
  var allowControls = pluginConfig.allowControls;
380
388
  var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
381
389
  return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard && fg('platform_editor_a11y_table_context_menu')) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
@@ -468,8 +476,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
468
476
  }));
469
477
  },
470
478
  pluginsOptions: {
471
- quickInsert: function quickInsert(_ref20) {
472
- var formatMessage = _ref20.formatMessage;
479
+ quickInsert: function quickInsert(_ref21) {
480
+ var formatMessage = _ref21.formatMessage;
473
481
  return [{
474
482
  id: 'table',
475
483
  title: formatMessage(messages.table),
@@ -0,0 +1,95 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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) { _defineProperty(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; }
4
+ /*
5
+ Existing legacy tables in Comment editor have set attributes:
6
+ - width = 760
7
+ - layout = 'default'.
8
+
9
+ When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
10
+ It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
11
+ the editor container until a user decided to edit their old comment and set a custom table width themselves.
12
+
13
+ This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
14
+ existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
15
+ */
16
+
17
+ import rafSchedule from 'raf-schd';
18
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
19
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
20
+ import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
21
+ import { ALIGN_START } from '../utils/alignment';
22
+ export var pluginKey = new PluginKey('tableWidthInCommentFixPlugin');
23
+ var getPluginState = function getPluginState(state) {
24
+ return state && pluginKey.getState(state);
25
+ };
26
+ var createPlugin = function createPlugin(dispatch, isTableAlignmentEnabled) {
27
+ return new SafePlugin({
28
+ key: pluginKey,
29
+ state: {
30
+ init: function init() {
31
+ return {
32
+ documentHasLoadedOnce: false
33
+ };
34
+ },
35
+ apply: function apply(tr, pluginState) {
36
+ var meta = tr.getMeta(pluginKey);
37
+ if (meta) {
38
+ var keys = Object.keys(meta);
39
+ var changed = keys.some(function (key) {
40
+ return pluginState[key] !== meta[key];
41
+ });
42
+ if (changed) {
43
+ var newState = _objectSpread(_objectSpread({}, pluginState), meta);
44
+ dispatch(pluginKey, newState);
45
+ return newState;
46
+ }
47
+ }
48
+ return pluginState;
49
+ }
50
+ },
51
+ view: function view() {
52
+ return {
53
+ update: function update(editorView) {
54
+ var state = editorView.state;
55
+ var pluginState = getPluginState(state);
56
+ if (!pluginState) {
57
+ return;
58
+ }
59
+ var documentHasLoadedOnce = pluginState.documentHasLoadedOnce;
60
+ if (documentHasLoadedOnce) {
61
+ return;
62
+ }
63
+ var table = state.schema.nodes.table;
64
+ rafSchedule(function () {
65
+ var tr = editorView.state.tr;
66
+ var tableWidthAndLayoutUpdated = false;
67
+ editorView.state.doc.descendants(function (node, pos) {
68
+ var isTable = node.type === table;
69
+ var width = node.attrs.width;
70
+ var layout = node.attrs.layout;
71
+ if (isTable && width === akEditorDefaultLayoutWidth && layout === 'default') {
72
+ tableWidthAndLayoutUpdated = true;
73
+ tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
74
+ width: null,
75
+ layout: isTableAlignmentEnabled ? ALIGN_START : 'default'
76
+ }));
77
+ return false;
78
+ }
79
+ // Returning false here because don't need to change nested tables
80
+ return false;
81
+ });
82
+ if (tableWidthAndLayoutUpdated) {
83
+ tr.setMeta('addToHistory', false);
84
+ editorView.dispatch(tr);
85
+ }
86
+ })();
87
+ editorView.dispatch(state.tr.setMeta(pluginKey, {
88
+ documentHasLoadedOnce: true
89
+ }));
90
+ }
91
+ };
92
+ }
93
+ });
94
+ };
95
+ export { createPlugin };
@@ -0,0 +1,11 @@
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ type TableWidthInCommentFixPluginState = {
5
+ documentHasLoadedOnce: boolean;
6
+ };
7
+ export declare const pluginKey: PluginKey<TableWidthInCommentFixPluginState>;
8
+ declare const createPlugin: (dispatch: Dispatch, isTableAlignmentEnabled: boolean) => SafePlugin<{
9
+ documentHasLoadedOnce: boolean;
10
+ }>;
11
+ export { createPlugin };
@@ -0,0 +1,11 @@
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ type TableWidthInCommentFixPluginState = {
5
+ documentHasLoadedOnce: boolean;
6
+ };
7
+ export declare const pluginKey: PluginKey<TableWidthInCommentFixPluginState>;
8
+ declare const createPlugin: (dispatch: Dispatch, isTableAlignmentEnabled: boolean) => SafePlugin<{
9
+ documentHasLoadedOnce: boolean;
10
+ }>;
11
+ export { createPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.25.19",
3
+ "version": "7.25.21",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -24,13 +24,13 @@
24
24
  "atlassian": {
25
25
  "team": "Editor: Jenga",
26
26
  "singleton": true,
27
- "runReact18": false
27
+ "runReact18": true
28
28
  },
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^40.9.0",
31
31
  "@atlaskit/button": "^20.1.0",
32
32
  "@atlaskit/custom-steps": "^0.7.0",
33
- "@atlaskit/editor-common": "^88.8.0",
33
+ "@atlaskit/editor-common": "^88.12.0",
34
34
  "@atlaskit/editor-palette": "1.6.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
@@ -43,7 +43,7 @@
43
43
  "@atlaskit/editor-prosemirror": "5.0.1",
44
44
  "@atlaskit/editor-shared-styles": "^2.13.0",
45
45
  "@atlaskit/editor-tables": "^2.8.0",
46
- "@atlaskit/icon": "^22.15.0",
46
+ "@atlaskit/icon": "^22.16.0",
47
47
  "@atlaskit/menu": "^2.12.0",
48
48
  "@atlaskit/platform-feature-flags": "^0.3.0",
49
49
  "@atlaskit/pragmatic-drag-and-drop": "^1.3.0",
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
52
52
  "@atlaskit/primitives": "^12.1.0",
53
53
  "@atlaskit/theme": "^13.0.0",
54
- "@atlaskit/toggle": "^13.3.0",
54
+ "@atlaskit/toggle": "^13.4.0",
55
55
  "@atlaskit/tokens": "^1.59.0",
56
56
  "@atlaskit/tooltip": "^18.7.0",
57
57
  "@babel/runtime": "^7.0.0",
@@ -62,8 +62,8 @@
62
62
  "raf-schd": "^4.0.3"
63
63
  },
64
64
  "peerDependencies": {
65
- "react": "^16.8.0",
66
- "react-dom": "^16.8.0",
65
+ "react": "^16.8.0 || ^17.0.0 || ~18.2.0",
66
+ "react-dom": "^16.8.0 || ^17.0.0 || ~18.2.0",
67
67
  "react-intl-next": "npm:react-intl@^5.18.1"
68
68
  },
69
69
  "devDependencies": {
@@ -18,7 +18,10 @@ import type { EditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/edit
18
18
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
19
19
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
20
20
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
21
- import { akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
21
+ import {
22
+ akEditorTableNumberColumnWidth,
23
+ akEditorTableToolbarSize as tableToolbarSize,
24
+ } from '@atlaskit/editor-shared-styles';
22
25
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
23
26
  import { fg } from '@atlaskit/platform-feature-flags';
24
27
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
@@ -456,7 +459,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
456
459
  if (force || (!isResizing && shouldUpdateColgroup)) {
457
460
  const resizeState = getResizeState({
458
461
  minWidth: COLUMN_MIN_WIDTH,
459
- maxSize: tableRenderWidth,
462
+ // When numbered column enabled, we need to subtract the width of the numbered column
463
+ maxSize: tableNode.attrs.isNumberColumnEnabled
464
+ ? tableRenderWidth - akEditorTableNumberColumnWidth
465
+ : tableRenderWidth,
460
466
  table: tableNode,
461
467
  tableRef: this.table,
462
468
  start,
@@ -436,45 +436,33 @@ export const TableResizer = ({
436
436
  return;
437
437
  }
438
438
 
439
- previewScaleTable(
440
- tableRef,
441
- {
442
- node,
443
- prevNode: node,
444
- start: pos + 1,
445
- parentWidth: newWidth,
446
- },
447
- editorView.domAtPos.bind(editorView),
448
- isTableScalingEnabled,
449
- isTableWithFixedColumnWidthsOptionEnabled,
450
- isCommentEditor,
451
- );
452
-
453
439
  const editorContainerWidth = isFullWidthModeEnabled
454
440
  ? lineLength + 2 * akEditorGutterPaddingDynamic()
455
441
  : containerWidth;
456
442
 
457
- const closestSnap = findClosestSnap(
458
- newWidth,
459
- isTableScalingEnabled
460
- ? defaultTablePreserveSnappingWidths(
461
- PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
462
- editorContainerWidth,
463
- excludeGuidelineConfig,
464
- )
465
- : defaultSnappingWidths,
466
- isTableScalingEnabled
467
- ? defaultGuidelinesForPreserveTable(
468
- PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
469
- editorContainerWidth,
470
- excludeGuidelineConfig,
471
- )
472
- : defaultGuidelines,
473
- TABLE_HIGHLIGHT_GAP,
474
- TABLE_HIGHLIGHT_TOLERANCE,
475
- );
443
+ const closestSnap =
444
+ !isCommentEditor &&
445
+ findClosestSnap(
446
+ newWidth,
447
+ isTableScalingEnabled
448
+ ? defaultTablePreserveSnappingWidths(
449
+ PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
450
+ editorContainerWidth,
451
+ excludeGuidelineConfig,
452
+ )
453
+ : defaultSnappingWidths,
454
+ isTableScalingEnabled
455
+ ? defaultGuidelinesForPreserveTable(
456
+ PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
457
+ editorContainerWidth,
458
+ excludeGuidelineConfig,
459
+ )
460
+ : defaultGuidelines,
461
+ TABLE_HIGHLIGHT_GAP,
462
+ TABLE_HIGHLIGHT_TOLERANCE,
463
+ );
476
464
 
477
- updateActiveGuidelines(closestSnap);
465
+ closestSnap && updateActiveGuidelines(closestSnap);
478
466
 
479
467
  // When snapping to the full width guideline, resize the table to be 1800px
480
468
  const { state, dispatch } = editorView;
@@ -486,13 +474,33 @@ export const TableResizer = ({
486
474
  excludeGuidelineConfig,
487
475
  ).filter((guideline) => guideline.isFullWidth)[0];
488
476
 
489
- const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
477
+ const isFullWidthGuidelineActive =
478
+ closestSnap && closestSnap.keys.includes(fullWidthGuideline.key);
479
+
490
480
  const tableMaxWidth = isCommentEditor
491
- ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR
481
+ ? Math.floor(containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR)
492
482
  : TABLE_MAX_WIDTH;
493
- const shouldUpdateWidthToWidest =
494
- (isCommentEditor && tableMaxWidth === newWidth) ||
495
- (!!isTableScalingEnabled && isFullWidthGuidelineActive);
483
+
484
+ const shouldUpdateWidthToWidest = isCommentEditor
485
+ ? tableMaxWidth <= newWidth
486
+ : !!isTableScalingEnabled && isFullWidthGuidelineActive;
487
+
488
+ const previewParentWidth =
489
+ isCommentEditor && shouldUpdateWidthToWidest ? tableMaxWidth : newWidth;
490
+
491
+ previewScaleTable(
492
+ tableRef,
493
+ {
494
+ node,
495
+ prevNode: node,
496
+ start: pos + 1,
497
+ parentWidth: previewParentWidth,
498
+ },
499
+ editorView.domAtPos.bind(editorView),
500
+ isTableScalingEnabled,
501
+ isTableWithFixedColumnWidthsOptionEnabled,
502
+ isCommentEditor,
503
+ );
496
504
 
497
505
  chainCommands(
498
506
  (state, dispatch) => {
package/src/plugin.tsx CHANGED
@@ -72,6 +72,7 @@ import {
72
72
  createPlugin as createTableWidthPlugin,
73
73
  pluginKey as tableWidthPluginKey,
74
74
  } from './pm-plugins/table-width';
75
+ import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
75
76
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
76
77
  import { tableNodeSpecWithFixedToDOM } from './toDOM';
77
78
  import { getToolbarConfig } from './toolbar';
@@ -457,6 +458,16 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
457
458
  )
458
459
  : undefined,
459
460
  },
461
+ {
462
+ name: 'tableWidthInCommentFix',
463
+ plugin: ({ dispatch }) =>
464
+ options?.tableResizingEnabled && options?.isCommentEditor
465
+ ? createTableWidthInCommentFixPlugin(
466
+ dispatch,
467
+ options?.isTableAlignmentEnabled ?? false,
468
+ )
469
+ : undefined,
470
+ },
460
471
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
461
472
  {
462
473
  name: 'tableOverflowAnalyticsPlugin',
@@ -0,0 +1,113 @@
1
+ /*
2
+ Existing legacy tables in Comment editor have set attributes:
3
+ - width = 760
4
+ - layout = 'default'.
5
+
6
+ When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
7
+ It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
8
+ the editor container until a user decided to edit their old comment and set a custom table width themselves.
9
+
10
+ This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
11
+ existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
12
+ */
13
+
14
+ import rafSchedule from 'raf-schd';
15
+
16
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
17
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
18
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
19
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
20
+ import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
21
+
22
+ import { ALIGN_START } from '../utils/alignment';
23
+
24
+ type TableWidthInCommentFixPluginState = {
25
+ documentHasLoadedOnce: boolean;
26
+ };
27
+
28
+ export const pluginKey = new PluginKey<TableWidthInCommentFixPluginState>(
29
+ 'tableWidthInCommentFixPlugin',
30
+ );
31
+ const getPluginState = (state: EditorState): TableWidthInCommentFixPluginState | undefined | null =>
32
+ state && pluginKey.getState(state);
33
+
34
+ const createPlugin = (dispatch: Dispatch, isTableAlignmentEnabled: boolean) => {
35
+ return new SafePlugin({
36
+ key: pluginKey,
37
+ state: {
38
+ init() {
39
+ return {
40
+ documentHasLoadedOnce: false,
41
+ };
42
+ },
43
+ apply(tr, pluginState) {
44
+ const meta = tr.getMeta(pluginKey);
45
+ if (meta) {
46
+ const keys = Object.keys(meta) as Array<keyof TableWidthInCommentFixPluginState>;
47
+ const changed = keys.some((key) => {
48
+ return pluginState[key] !== meta[key];
49
+ });
50
+
51
+ if (changed) {
52
+ const newState = { ...pluginState, ...meta };
53
+
54
+ dispatch(pluginKey, newState);
55
+ return newState;
56
+ }
57
+ }
58
+
59
+ return pluginState;
60
+ },
61
+ },
62
+ view: () => {
63
+ return {
64
+ update(editorView) {
65
+ const { state } = editorView;
66
+ const pluginState = getPluginState(state);
67
+ if (!pluginState) {
68
+ return;
69
+ }
70
+ const { documentHasLoadedOnce } = pluginState;
71
+
72
+ if (documentHasLoadedOnce) {
73
+ return;
74
+ }
75
+
76
+ const { table } = state.schema.nodes;
77
+ rafSchedule(() => {
78
+ const tr = editorView.state.tr;
79
+ let tableWidthAndLayoutUpdated = false;
80
+ editorView.state.doc.descendants((node, pos) => {
81
+ const isTable = node.type === table;
82
+ const width = node.attrs.width;
83
+ const layout = node.attrs.layout;
84
+ if (isTable && width === akEditorDefaultLayoutWidth && layout === 'default') {
85
+ tableWidthAndLayoutUpdated = true;
86
+ tr.setNodeMarkup(pos, undefined, {
87
+ ...node.attrs,
88
+ width: null,
89
+ layout: isTableAlignmentEnabled ? ALIGN_START : 'default',
90
+ });
91
+ return false;
92
+ }
93
+ // Returning false here because don't need to change nested tables
94
+ return false;
95
+ });
96
+ if (tableWidthAndLayoutUpdated) {
97
+ tr.setMeta('addToHistory', false);
98
+ editorView.dispatch(tr);
99
+ }
100
+ })();
101
+
102
+ editorView.dispatch(
103
+ state.tr.setMeta(pluginKey, {
104
+ documentHasLoadedOnce: true,
105
+ }),
106
+ );
107
+ },
108
+ };
109
+ },
110
+ });
111
+ };
112
+
113
+ export { createPlugin };