@atlaskit/editor-plugin-table 7.25.18 → 7.25.20

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,23 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.25.20
4
+
5
+ ### Patch Changes
6
+
7
+ - [#137344](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137344)
8
+ [`00c81bdf34c46`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/00c81bdf34c46) -
9
+ [ux] Fixes an issue where tables that existed before "Support Table in Comment" are displayed as
10
+ centered 760px width tables when FF for Support Table in Comment is enabled.
11
+
12
+ ## 7.25.19
13
+
14
+ ### Patch Changes
15
+
16
+ - [#136485](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136485)
17
+ [`96d4b8a73c2ea`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/96d4b8a73c2ea) -
18
+ Refactored table styles so that it is inside the tables plugin and not in the editors critical
19
+ path.
20
+
3
21
  ## 7.25.18
4
22
 
5
23
  ### Patch Changes
@@ -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");
@@ -45,6 +46,7 @@ var _FloatingDeleteButton = _interopRequireDefault(require("./ui/FloatingDeleteB
45
46
  var _FloatingDragMenu = _interopRequireDefault(require("./ui/FloatingDragMenu"));
46
47
  var _FloatingInsertButton = _interopRequireDefault(require("./ui/FloatingInsertButton"));
47
48
  var _FloatingToolbarLabel = require("./ui/FloatingToolbarLabel/FloatingToolbarLabel");
49
+ var _globalStyles = require("./ui/global-styles");
48
50
  var _TableFullWidthLabel = require("./ui/TableFullWidthLabel");
49
51
  var _utils = require("./utils");
50
52
  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; }
@@ -289,21 +291,28 @@ var tablesPlugin = function tablesPlugin(_ref) {
289
291
  dispatch = _ref14.dispatch;
290
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;
291
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
+ }
292
301
  },
293
302
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
294
303
  {
295
304
  name: 'tableOverflowAnalyticsPlugin',
296
- plugin: function plugin(_ref15) {
305
+ plugin: function plugin(_ref16) {
297
306
  var _options$tableResizin;
298
- var dispatch = _ref15.dispatch,
299
- dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
307
+ var dispatch = _ref16.dispatch,
308
+ dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
300
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);
301
310
  }
302
311
  }, {
303
312
  name: 'tableAnalyticsPlugin',
304
- plugin: function plugin(_ref16) {
305
- var dispatch = _ref16.dispatch,
306
- dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
313
+ plugin: function plugin(_ref17) {
314
+ var dispatch = _ref17.dispatch,
315
+ dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
307
316
  return (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent);
308
317
  }
309
318
  }, {
@@ -334,17 +343,20 @@ var tablesPlugin = function tablesPlugin(_ref) {
334
343
  }
335
344
  return plugins;
336
345
  },
337
- contentComponent: function contentComponent(_ref17) {
338
- var editorView = _ref17.editorView,
339
- popupsMountPoint = _ref17.popupsMountPoint,
340
- popupsBoundariesElement = _ref17.popupsBoundariesElement,
341
- popupsScrollableElement = _ref17.popupsScrollableElement,
342
- dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
346
+ contentComponent: function contentComponent(_ref18) {
347
+ var _api$featureFlags;
348
+ var editorView = _ref18.editorView,
349
+ popupsMountPoint = _ref18.popupsMountPoint,
350
+ popupsBoundariesElement = _ref18.popupsBoundariesElement,
351
+ popupsScrollableElement = _ref18.popupsScrollableElement,
352
+ dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
343
353
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
344
354
  component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
345
355
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
346
356
  fallbackComponent: null
347
- }, /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
357
+ }, /*#__PURE__*/_react.default.createElement(_globalStyles.GlobalStylesWrapper, {
358
+ featureFlags: api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()
359
+ }), /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
348
360
  plugins: {
349
361
  tableAnalyticsPluginState: _pluginKey.pluginKey,
350
362
  tablePluginState: _pluginKey2.pluginKey,
@@ -353,32 +365,32 @@ var tablesPlugin = function tablesPlugin(_ref) {
353
365
  stickyHeadersState: _stickyHeaders.pluginKey,
354
366
  dragAndDropState: _dragAndDrop.pluginKey
355
367
  },
356
- render: function render(_ref18) {
357
- var resizingPluginState = _ref18.tableResizingPluginState,
358
- stickyHeadersState = _ref18.stickyHeadersState,
359
- tablePluginState = _ref18.tablePluginState,
360
- tableWidthPluginState = _ref18.tableWidthPluginState,
361
- 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;
362
374
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
363
375
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
364
376
  var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
365
377
  var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
366
378
  var isResizing = isColumnResizing || isTableResizing;
367
379
  var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
368
- var _ref19 = tablePluginState,
369
- tableNode = _ref19.tableNode,
370
- tablePos = _ref19.tablePos,
371
- targetCellPosition = _ref19.targetCellPosition,
372
- isContextualMenuOpen = _ref19.isContextualMenuOpen,
373
- tableRef = _ref19.tableRef,
374
- pluginConfig = _ref19.pluginConfig,
375
- insertColumnButtonIndex = _ref19.insertColumnButtonIndex,
376
- insertRowButtonIndex = _ref19.insertRowButtonIndex,
377
- isHeaderColumnEnabled = _ref19.isHeaderColumnEnabled,
378
- isHeaderRowEnabled = _ref19.isHeaderRowEnabled,
379
- isDragAndDropEnabled = _ref19.isDragAndDropEnabled,
380
- tableWrapperTarget = _ref19.tableWrapperTarget,
381
- 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;
382
394
  var allowControls = pluginConfig.allowControls;
383
395
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
384
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, {
@@ -471,8 +483,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
471
483
  }));
472
484
  },
473
485
  pluginsOptions: {
474
- quickInsert: function quickInsert(_ref20) {
475
- var formatMessage = _ref20.formatMessage;
486
+ quickInsert: function quickInsert(_ref21) {
487
+ var formatMessage = _ref21.formatMessage;
476
488
  return [{
477
489
  id: 'table',
478
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
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GlobalStylesWrapper = void 0;
7
+ var _react = require("@emotion/react");
8
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
+ var _commonStyles = require("./common-styles");
10
+ /**
11
+ * @jsxRuntime classic
12
+ * @jsx jsx
13
+ */
14
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
15
+
16
+ var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper(_ref) {
17
+ var featureFlags = _ref.featureFlags;
18
+ return (0, _platformFeatureFlags.fg)('platform_editor_move_table_styles_to_plugin') ? (0, _react.jsx)(_react.Global, {
19
+ styles: (0, _commonStyles.tableStyles)({
20
+ featureFlags: featureFlags
21
+ })
22
+ }) : null;
23
+ };
@@ -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';
@@ -37,6 +38,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
37
38
  import FloatingDragMenu from './ui/FloatingDragMenu';
38
39
  import FloatingInsertButton from './ui/FloatingInsertButton';
39
40
  import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
41
+ import { GlobalStylesWrapper } from './ui/global-styles';
40
42
  import { FullWidthDisplay } from './ui/TableFullWidthLabel';
41
43
  import { createTableWithWidth } from './utils';
42
44
  const defaultGetEditorFeatureFlags = () => ({});
@@ -277,6 +279,14 @@ const tablesPlugin = ({
277
279
  var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign, _options$isCommentEdi;
278
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;
279
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
+ }
280
290
  },
281
291
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
282
292
  {
@@ -329,11 +339,14 @@ const tablesPlugin = ({
329
339
  popupsScrollableElement,
330
340
  dispatchAnalyticsEvent
331
341
  }) {
342
+ var _api$featureFlags;
332
343
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
333
344
  component: ACTION_SUBJECT.TABLES_PLUGIN,
334
345
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
335
346
  fallbackComponent: null
336
- }, /*#__PURE__*/React.createElement(WithPluginState, {
347
+ }, /*#__PURE__*/React.createElement(GlobalStylesWrapper, {
348
+ featureFlags: api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()
349
+ }), /*#__PURE__*/React.createElement(WithPluginState, {
337
350
  plugins: {
338
351
  tableAnalyticsPluginState: tableAnalyticsPluginKey,
339
352
  tablePluginState: pluginKey,
@@ -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 };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
+ import { Global, jsx } from '@emotion/react';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { tableStyles } from './common-styles';
9
+ export const GlobalStylesWrapper = ({
10
+ featureFlags
11
+ }) => {
12
+ return fg('platform_editor_move_table_styles_to_plugin') ? jsx(Global, {
13
+ styles: tableStyles({
14
+ featureFlags
15
+ })
16
+ }) : null;
17
+ };
@@ -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';
@@ -40,6 +41,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
40
41
  import FloatingDragMenu from './ui/FloatingDragMenu';
41
42
  import FloatingInsertButton from './ui/FloatingInsertButton';
42
43
  import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
44
+ import { GlobalStylesWrapper } from './ui/global-styles';
43
45
  import { FullWidthDisplay } from './ui/TableFullWidthLabel';
44
46
  import { createTableWithWidth } from './utils';
45
47
  var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
@@ -282,21 +284,28 @@ var tablesPlugin = function tablesPlugin(_ref) {
282
284
  dispatch = _ref14.dispatch;
283
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;
284
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
+ }
285
294
  },
286
295
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
287
296
  {
288
297
  name: 'tableOverflowAnalyticsPlugin',
289
- plugin: function plugin(_ref15) {
298
+ plugin: function plugin(_ref16) {
290
299
  var _options$tableResizin;
291
- var dispatch = _ref15.dispatch,
292
- dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
300
+ var dispatch = _ref16.dispatch,
301
+ dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
293
302
  return createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
294
303
  }
295
304
  }, {
296
305
  name: 'tableAnalyticsPlugin',
297
- plugin: function plugin(_ref16) {
298
- var dispatch = _ref16.dispatch,
299
- dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
306
+ plugin: function plugin(_ref17) {
307
+ var dispatch = _ref17.dispatch,
308
+ dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
300
309
  return createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent);
301
310
  }
302
311
  }, {
@@ -327,17 +336,20 @@ var tablesPlugin = function tablesPlugin(_ref) {
327
336
  }
328
337
  return plugins;
329
338
  },
330
- contentComponent: function contentComponent(_ref17) {
331
- var editorView = _ref17.editorView,
332
- popupsMountPoint = _ref17.popupsMountPoint,
333
- popupsBoundariesElement = _ref17.popupsBoundariesElement,
334
- popupsScrollableElement = _ref17.popupsScrollableElement,
335
- dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
339
+ contentComponent: function contentComponent(_ref18) {
340
+ var _api$featureFlags;
341
+ var editorView = _ref18.editorView,
342
+ popupsMountPoint = _ref18.popupsMountPoint,
343
+ popupsBoundariesElement = _ref18.popupsBoundariesElement,
344
+ popupsScrollableElement = _ref18.popupsScrollableElement,
345
+ dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
336
346
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
337
347
  component: ACTION_SUBJECT.TABLES_PLUGIN,
338
348
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
339
349
  fallbackComponent: null
340
- }, /*#__PURE__*/React.createElement(WithPluginState, {
350
+ }, /*#__PURE__*/React.createElement(GlobalStylesWrapper, {
351
+ featureFlags: api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()
352
+ }), /*#__PURE__*/React.createElement(WithPluginState, {
341
353
  plugins: {
342
354
  tableAnalyticsPluginState: tableAnalyticsPluginKey,
343
355
  tablePluginState: pluginKey,
@@ -346,32 +358,32 @@ var tablesPlugin = function tablesPlugin(_ref) {
346
358
  stickyHeadersState: stickyHeadersPluginKey,
347
359
  dragAndDropState: dragAndDropPluginKey
348
360
  },
349
- render: function render(_ref18) {
350
- var resizingPluginState = _ref18.tableResizingPluginState,
351
- stickyHeadersState = _ref18.stickyHeadersState,
352
- tablePluginState = _ref18.tablePluginState,
353
- tableWidthPluginState = _ref18.tableWidthPluginState,
354
- 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;
355
367
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
356
368
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
357
369
  var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
358
370
  var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
359
371
  var isResizing = isColumnResizing || isTableResizing;
360
372
  var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
361
- var _ref19 = tablePluginState,
362
- tableNode = _ref19.tableNode,
363
- tablePos = _ref19.tablePos,
364
- targetCellPosition = _ref19.targetCellPosition,
365
- isContextualMenuOpen = _ref19.isContextualMenuOpen,
366
- tableRef = _ref19.tableRef,
367
- pluginConfig = _ref19.pluginConfig,
368
- insertColumnButtonIndex = _ref19.insertColumnButtonIndex,
369
- insertRowButtonIndex = _ref19.insertRowButtonIndex,
370
- isHeaderColumnEnabled = _ref19.isHeaderColumnEnabled,
371
- isHeaderRowEnabled = _ref19.isHeaderRowEnabled,
372
- isDragAndDropEnabled = _ref19.isDragAndDropEnabled,
373
- tableWrapperTarget = _ref19.tableWrapperTarget,
374
- 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;
375
387
  var allowControls = pluginConfig.allowControls;
376
388
  var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
377
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, {
@@ -464,8 +476,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
464
476
  }));
465
477
  },
466
478
  pluginsOptions: {
467
- quickInsert: function quickInsert(_ref20) {
468
- var formatMessage = _ref20.formatMessage;
479
+ quickInsert: function quickInsert(_ref21) {
480
+ var formatMessage = _ref21.formatMessage;
469
481
  return [{
470
482
  id: 'table',
471
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,16 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
+ import { Global, jsx } from '@emotion/react';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { tableStyles } from './common-styles';
9
+ export var GlobalStylesWrapper = function GlobalStylesWrapper(_ref) {
10
+ var featureFlags = _ref.featureFlags;
11
+ return fg('platform_editor_move_table_styles_to_plugin') ? jsx(Global, {
12
+ styles: tableStyles({
13
+ featureFlags: featureFlags
14
+ })
15
+ }) : null;
16
+ };
@@ -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,9 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { jsx } from '@emotion/react';
6
+ import type { FeatureFlags } from '@atlaskit/editor-common/types';
7
+ export declare const GlobalStylesWrapper: ({ featureFlags, }: {
8
+ featureFlags: FeatureFlags | undefined;
9
+ }) => jsx.JSX.Element | null;
@@ -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,9 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { jsx } from '@emotion/react';
6
+ import type { FeatureFlags } from '@atlaskit/editor-common/types';
7
+ export declare const GlobalStylesWrapper: ({ featureFlags, }: {
8
+ featureFlags: FeatureFlags | undefined;
9
+ }) => jsx.JSX.Element | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.25.18",
3
+ "version": "7.25.20",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -117,6 +117,9 @@
117
117
  "platform_editor_dark_mode_cell_header_color_fix": {
118
118
  "type": "boolean"
119
119
  },
120
+ "platform_editor_move_table_styles_to_plugin": {
121
+ "type": "boolean"
122
+ },
120
123
  "platform_editor_a11y_table_context_menu": {
121
124
  "type": "boolean"
122
125
  },
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';
@@ -82,6 +83,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
82
83
  import FloatingDragMenu from './ui/FloatingDragMenu';
83
84
  import FloatingInsertButton from './ui/FloatingInsertButton';
84
85
  import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
86
+ import { GlobalStylesWrapper } from './ui/global-styles';
85
87
  import { FullWidthDisplay } from './ui/TableFullWidthLabel';
86
88
  import { createTableWithWidth } from './utils';
87
89
 
@@ -456,6 +458,16 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
456
458
  )
457
459
  : undefined,
458
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
+ },
459
471
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
460
472
  {
461
473
  name: 'tableOverflowAnalyticsPlugin',
@@ -515,6 +527,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
515
527
  dispatchAnalyticsEvent={dispatchAnalyticsEvent}
516
528
  fallbackComponent={null}
517
529
  >
530
+ <GlobalStylesWrapper featureFlags={api?.featureFlags?.sharedState.currentState()} />
518
531
  <WithPluginState
519
532
  plugins={{
520
533
  tableAnalyticsPluginState: tableAnalyticsPluginKey,
@@ -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 };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
+ import { Global, jsx } from '@emotion/react';
7
+
8
+ import type { FeatureFlags } from '@atlaskit/editor-common/types';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
10
+
11
+ import { tableStyles } from './common-styles';
12
+
13
+ export const GlobalStylesWrapper = ({
14
+ featureFlags,
15
+ }: {
16
+ featureFlags: FeatureFlags | undefined;
17
+ }) => {
18
+ return fg('platform_editor_move_table_styles_to_plugin') ? (
19
+ <Global styles={tableStyles({ featureFlags })} />
20
+ ) : null;
21
+ };