@atlaskit/editor-plugin-table 7.4.7 → 7.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.4.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#77796](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/77796) [`eab996d08513`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/eab996d08513) - Add new statsig experiement for preserve table width, add support for passing through width to create table. Allow tables to be inserted at full width
8
+
3
9
  ## 7.4.7
4
10
 
5
11
  ### Patch Changes
@@ -89,8 +89,6 @@ var addColumnAfter = exports.addColumnAfter = function addColumnAfter(getEditorC
89
89
  return true;
90
90
  };
91
91
  };
92
-
93
- // #region Commands
94
92
  var insertColumn = exports.insertColumn = function insertColumn(getEditorContainerWidth) {
95
93
  return function (column) {
96
94
  return function (state, dispatch, view) {
@@ -143,28 +141,23 @@ var insertRow = exports.insertRow = function insertRow(row, moveCursorToTheNewRo
143
141
  return true;
144
142
  };
145
143
  };
146
- var createTable = exports.createTable = function createTable() {
144
+ var createTable = exports.createTable = function createTable(isFullWidthModeEnabled, getEditorFeatureFlags) {
147
145
  return function (state, dispatch) {
148
- var table = (0, _utils2.createTable)({
149
- schema: state.schema
150
- });
146
+ var table = (0, _utils3.createTableWithWidth)(isFullWidthModeEnabled, getEditorFeatureFlags)(state.schema);
151
147
  if (dispatch) {
152
148
  dispatch((0, _utils.safeInsert)(table)(state.tr).scrollIntoView());
153
149
  }
154
150
  return true;
155
151
  };
156
152
  };
157
- // #endregion
158
-
159
- var insertTableWithSize = exports.insertTableWithSize = function insertTableWithSize(editorAnalyticsAPI) {
153
+ var insertTableWithSize = exports.insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, getEditorFeatureFlags, editorAnalyticsAPI) {
160
154
  return function (rowsCount, colsCount, inputMethod) {
161
155
  return function (_ref) {
162
156
  var tr = _ref.tr;
163
- var tableNode = (0, _utils2.createTable)({
164
- schema: tr.doc.type.schema,
157
+ var tableNode = (0, _utils3.createTableWithWidth)(isFullWidthModeEnabled, getEditorFeatureFlags, {
165
158
  rowsCount: rowsCount,
166
159
  colsCount: colsCount
167
- });
160
+ })(tr.doc.type.schema);
168
161
  var newTr = (0, _utils.safeInsert)(tableNode)(tr).scrollIntoView();
169
162
  if (inputMethod) {
170
163
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
@@ -16,7 +16,6 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
16
16
  var _utils = require("@atlaskit/editor-common/utils");
17
17
  var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
18
18
  var _pmPlugins = require("@atlaskit/editor-tables/pm-plugins");
19
- var _utils2 = require("@atlaskit/editor-tables/utils");
20
19
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
21
20
  var _insert = require("./commands/insert");
22
21
  var _createPluginConfig = require("./create-plugin-config");
@@ -41,7 +40,7 @@ var _FloatingDeleteButton = _interopRequireDefault(require("./ui/FloatingDeleteB
41
40
  var _FloatingDragMenu = _interopRequireDefault(require("./ui/FloatingDragMenu"));
42
41
  var _FloatingInsertButton = _interopRequireDefault(require("./ui/FloatingInsertButton"));
43
42
  var _LayoutButton = _interopRequireDefault(require("./ui/LayoutButton"));
44
- var _utils3 = require("./utils");
43
+ var _utils2 = require("./utils");
45
44
  var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
46
45
  return {};
47
46
  };
@@ -66,13 +65,19 @@ var tablesPlugin = function tablesPlugin(_ref) {
66
65
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
67
66
  return {
68
67
  name: 'table',
68
+ // Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
69
+ // to most up to date values - passing to createPluginState will not re-initialise the state
70
+ getSharedState: function getSharedState() {
71
+ return {
72
+ isFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.fullWidthEnabled),
73
+ wasFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasFullWidthEnabled)
74
+ };
75
+ },
69
76
  actions: {
70
77
  insertTable: function insertTable(analyticsPayload) {
71
78
  return function (state, dispatch) {
72
79
  var _api$contentInsertion, _api$contentInsertion2;
73
- var node = (0, _utils2.createTable)({
74
- schema: state.schema
75
- });
80
+ var node = (0, _utils2.createTableWithWidth)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema);
76
81
  return (_api$contentInsertion = api === null || api === void 0 || (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 || (_api$contentInsertion2 = _api$contentInsertion2.actions) === null || _api$contentInsertion2 === void 0 ? void 0 : _api$contentInsertion2.insert({
77
82
  state: state,
78
83
  dispatch: dispatch,
@@ -86,7 +91,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
86
91
  }
87
92
  },
88
93
  commands: {
89
- insertTableWithSize: (0, _insert.insertTableWithSize)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
94
+ insertTableWithSize: (0, _insert.insertTableWithSize)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
90
95
  },
91
96
  nodes: function nodes() {
92
97
  var tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? _adfSchema.tableWithCustomWidth : _adfSchema.table;
@@ -208,7 +213,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
208
213
  var _options$fullWidthEna;
209
214
  var dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent,
210
215
  dispatch = _ref12.dispatch;
211
- 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) : undefined;
216
+ 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 === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) : undefined;
212
217
  }
213
218
  },
214
219
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
@@ -300,7 +305,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
300
305
  tableWrapperTarget = _ref17.tableWrapperTarget;
301
306
  var allowControls = pluginConfig.allowControls;
302
307
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
303
- var LayoutContent = options && !options.tableResizingEnabled && (0, _utils3.isLayoutSupported)(state) && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
308
+ var LayoutContent = options && !options.tableResizingEnabled && (0, _utils2.isLayoutSupported)(state) && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
304
309
  editorView: editorView,
305
310
  mountPoint: popupsMountPoint,
306
311
  boundariesElement: popupsBoundariesElement,
@@ -391,9 +396,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
391
396
  return /*#__PURE__*/_react.default.createElement(_icons.IconTable, null);
392
397
  },
393
398
  action: function action(insert, state) {
394
- var tr = insert((0, _utils2.createTable)({
395
- schema: state.schema
396
- }));
399
+ var _api$table;
400
+ // see comment on tablesPlugin.getSharedState on usage
401
+ var tableState = api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
402
+ var tr = insert((0, _utils2.createTableWithWidth)(tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema));
397
403
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
398
404
  action: _analytics.ACTION.INSERTED,
399
405
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
@@ -14,6 +14,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
14
14
  var _transform = require("@atlaskit/editor-prosemirror/transform");
15
15
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
16
  var _utils = require("@atlaskit/editor-tables/utils");
17
+ var _utils2 = require("./table-resizing/utils");
17
18
  var _excluded = ["width"];
18
19
  /**
19
20
  * A plugin for handle table custom widths
@@ -23,7 +24,7 @@ var _excluded = ["width"];
23
24
  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; }
24
25
  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; }
25
26
  var pluginKey = exports.pluginKey = new _state.PluginKey('tableWidthPlugin');
26
- var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled) {
27
+ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, getEditorFeatureFlags) {
27
28
  return new _safePlugin.SafePlugin({
28
29
  key: pluginKey,
29
30
  state: {
@@ -65,6 +66,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
65
66
  }
66
67
  });
67
68
  }
69
+
68
70
  // When document first load in Confluence, initially it is an empty document
69
71
  // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
70
72
  // what we need to do is to add width attr to all tables in the real document
@@ -86,11 +88,15 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
86
88
  });
87
89
  return hasStepReplacingEntireDocument;
88
90
  });
89
- if (!isReplaceDocumentOperation) {
91
+ var referentialityTr = transactions.find(function (tr) {
92
+ return tr.getMeta('referentialityTableInserted');
93
+ });
94
+ var shouldPatchTable = fullWidthEnabled && getEditorFeatureFlags && getEditorFeatureFlags()['tablePreserveWidth'];
95
+ if (!isReplaceDocumentOperation && (!shouldPatchTable || !referentialityTr)) {
90
96
  return null;
91
97
  }
92
- var tr = newState.tr;
93
98
  var table = newState.schema.nodes.table;
99
+ var tr = newState.tr;
94
100
 
95
101
  /**
96
102
  * Select table event
@@ -108,40 +114,53 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
108
114
  }
109
115
  });
110
116
  }
111
- newState.doc.forEach(function (node, offset) {
112
- if (node.type === table) {
113
- var width = node.attrs.width;
114
- var layout = node.attrs.layout;
115
- if (!width && layout) {
116
- var tableWidthCal;
117
- if (fullWidthEnabled) {
118
- tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
119
- } else {
120
- switch (layout) {
121
- case 'wide':
122
- tableWidthCal = _editorSharedStyles.akEditorWideLayoutWidth;
123
- break;
124
- case 'full-width':
125
- tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
126
- break;
127
- // when in fix-width appearance, no need to assign value to table width attr
128
- // as when table is created, width attr is null by default, table rendered using layout attr
129
- default:
130
- tableWidthCal = _editorSharedStyles.akEditorDefaultLayoutWidth;
131
- break;
117
+ if (isReplaceDocumentOperation) {
118
+ newState.doc.forEach(function (node, offset) {
119
+ if (node.type === table) {
120
+ var width = node.attrs.width;
121
+ var layout = node.attrs.layout;
122
+ if (!width && layout) {
123
+ var tableWidthCal;
124
+ if (fullWidthEnabled) {
125
+ tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
126
+ } else {
127
+ switch (layout) {
128
+ case 'wide':
129
+ tableWidthCal = _editorSharedStyles.akEditorWideLayoutWidth;
130
+ break;
131
+ case 'full-width':
132
+ tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
133
+ break;
134
+ // when in fix-width appearance, no need to assign value to table width attr
135
+ // as when table is created, width attr is null by default, table rendered using layout attr
136
+ default:
137
+ tableWidthCal = _editorSharedStyles.akEditorDefaultLayoutWidth;
138
+ break;
139
+ }
140
+ }
141
+ var _node$attrs = node.attrs,
142
+ _width = _node$attrs.width,
143
+ rest = (0, _objectWithoutProperties2.default)(_node$attrs, _excluded);
144
+ if (tableWidthCal) {
145
+ tr.step(new _steps.SetAttrsStep(offset, _objectSpread({
146
+ width: tableWidthCal
147
+ }, rest)));
132
148
  }
133
- }
134
- var _node$attrs = node.attrs,
135
- _width = _node$attrs.width,
136
- rest = (0, _objectWithoutProperties2.default)(_node$attrs, _excluded);
137
- if (tableWidthCal) {
138
- tr.step(new _steps.SetAttrsStep(offset, _objectSpread({
139
- width: tableWidthCal
140
- }, rest)));
141
149
  }
142
150
  }
143
- }
144
- });
151
+ });
152
+ }
153
+ if (referentialityTr) {
154
+ referentialityTr.steps.forEach(function (step) {
155
+ step.getMap().forEach(function (oldStart, oldEnd, newStart, newEnd) {
156
+ newState.doc.nodesBetween(newStart, newEnd, function (node, pos) {
157
+ if (node.type === table && node.attrs.width !== _utils2.TABLE_MAX_WIDTH) {
158
+ tr.setNodeAttribute(pos, 'width', _utils2.TABLE_MAX_WIDTH);
159
+ }
160
+ });
161
+ });
162
+ });
163
+ }
145
164
  return tr;
146
165
  }
147
166
  });
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createTableWithWidth = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _utils = require("@atlaskit/editor-tables/utils");
10
+ var _utils2 = require("../pm-plugins/table-resizing/utils");
11
+ 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; }
12
+ 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; }
13
+ var createTableWithWidth = exports.createTableWithWidth = function createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags, createTableProps) {
14
+ return function (schema) {
15
+ var _ref = getEditorFeatureFlags ? getEditorFeatureFlags() : {},
16
+ _ref$tablePreserveWid = _ref.tablePreserveWidth,
17
+ tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
18
+ if (tablePreserveWidth && isFullWidthModeEnabled) {
19
+ return (0, _utils.createTable)(_objectSpread({
20
+ schema: schema,
21
+ tableWidth: _utils2.TABLE_MAX_WIDTH
22
+ }, createTableProps));
23
+ }
24
+ return (0, _utils.createTable)(_objectSpread({
25
+ schema: schema
26
+ }, createTableProps));
27
+ };
28
+ };
@@ -105,6 +105,12 @@ Object.defineProperty(exports, "createRowInsertLine", {
105
105
  return _decoration.createRowInsertLine;
106
106
  }
107
107
  });
108
+ Object.defineProperty(exports, "createTableWithWidth", {
109
+ enumerable: true,
110
+ get: function get() {
111
+ return _create.createTableWithWidth;
112
+ }
113
+ });
108
114
  Object.defineProperty(exports, "findControlsHoverDecoration", {
109
115
  enumerable: true,
110
116
  get: function get() {
@@ -445,4 +451,5 @@ var _rowControls = require("./row-controls");
445
451
  var _analytics = require("./analytics");
446
452
  var _table = require("./table");
447
453
  var _updatePluginStateDecorations = require("./update-plugin-state-decorations");
448
- var _mergedCells = require("./merged-cells");
454
+ var _mergedCells = require("./merged-cells");
455
+ var _create = require("./create");
@@ -4,12 +4,12 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, TABLE_OVERFLOW_C
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
- import { addColumnAt as addColumnAtPMUtils, addRowAt, createTable as createTableNode, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
7
+ import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
8
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
9
  import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
10
10
  import { META_KEYS } from '../pm-plugins/table-analytics';
11
11
  import { rescaleColumns } from '../transforms/column-width';
12
- import { checkIfHeaderRowEnabled, copyPreviousRow } from '../utils';
12
+ import { checkIfHeaderRowEnabled, copyPreviousRow, createTableWithWidth } from '../utils';
13
13
  import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
14
14
  function addColumnAtCustomStep(column) {
15
15
  return tr => {
@@ -74,8 +74,6 @@ export const addColumnAfter = getEditorContainerWidth => (state, dispatch, view)
74
74
  }
75
75
  return true;
76
76
  };
77
-
78
- // #region Commands
79
77
  export const insertColumn = getEditorContainerWidth => column => (state, dispatch, view) => {
80
78
  let tr = addColumnAt(getEditorContainerWidth)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
81
79
  const table = findTable(tr.selection);
@@ -124,26 +122,21 @@ export const insertRow = (row, moveCursorToTheNewRow) => (state, dispatch) => {
124
122
  }
125
123
  return true;
126
124
  };
127
- export const createTable = () => (state, dispatch) => {
128
- const table = createTableNode({
129
- schema: state.schema
130
- });
125
+ export const createTable = (isFullWidthModeEnabled, getEditorFeatureFlags) => (state, dispatch) => {
126
+ const table = createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags)(state.schema);
131
127
  if (dispatch) {
132
128
  dispatch(safeInsert(table)(state.tr).scrollIntoView());
133
129
  }
134
130
  return true;
135
131
  };
136
- // #endregion
137
-
138
- export const insertTableWithSize = editorAnalyticsAPI => (rowsCount, colsCount, inputMethod) => {
132
+ export const insertTableWithSize = (isFullWidthModeEnabled, getEditorFeatureFlags, editorAnalyticsAPI) => (rowsCount, colsCount, inputMethod) => {
139
133
  return ({
140
134
  tr
141
135
  }) => {
142
- const tableNode = createTableNode({
143
- schema: tr.doc.type.schema,
136
+ const tableNode = createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags, {
144
137
  rowsCount: rowsCount,
145
138
  colsCount: colsCount
146
- });
139
+ })(tr.doc.type.schema);
147
140
  const newTr = safeInsert(tableNode)(tr).scrollIntoView();
148
141
  if (inputMethod) {
149
142
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
@@ -9,7 +9,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
9
  import { browser } from '@atlaskit/editor-common/utils';
10
10
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
11
11
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
12
- import { createTable } from '@atlaskit/editor-tables/utils';
13
12
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
13
  import { insertTableWithSize } from './commands/insert';
15
14
  import { pluginConfig } from './create-plugin-config';
@@ -34,7 +33,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
34
33
  import FloatingDragMenu from './ui/FloatingDragMenu';
35
34
  import FloatingInsertButton from './ui/FloatingInsertButton';
36
35
  import LayoutButton from './ui/LayoutButton';
37
- import { isLayoutSupported } from './utils';
36
+ import { createTableWithWidth, isLayoutSupported } from './utils';
38
37
  const defaultGetEditorFeatureFlags = () => ({});
39
38
  /**
40
39
  * Table plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
@@ -58,12 +57,18 @@ const tablesPlugin = ({
58
57
  const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
59
58
  return {
60
59
  name: 'table',
60
+ // Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
61
+ // to most up to date values - passing to createPluginState will not re-initialise the state
62
+ getSharedState: () => {
63
+ return {
64
+ isFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.fullWidthEnabled),
65
+ wasFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasFullWidthEnabled)
66
+ };
67
+ },
61
68
  actions: {
62
69
  insertTable: analyticsPayload => (state, dispatch) => {
63
70
  var _api$contentInsertion, _api$contentInsertion2, _api$contentInsertion3;
64
- const node = createTable({
65
- schema: state.schema
66
- });
71
+ const node = createTableWithWidth(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema);
67
72
  return (_api$contentInsertion = api === null || api === void 0 ? void 0 : (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 ? void 0 : (_api$contentInsertion3 = _api$contentInsertion2.actions) === null || _api$contentInsertion3 === void 0 ? void 0 : _api$contentInsertion3.insert({
68
73
  state,
69
74
  dispatch,
@@ -76,7 +81,7 @@ const tablesPlugin = ({
76
81
  }
77
82
  },
78
83
  commands: {
79
- insertTableWithSize: insertTableWithSize(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
84
+ insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
80
85
  },
81
86
  nodes() {
82
87
  const tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? tableWithCustomWidth : table;
@@ -198,7 +203,7 @@ const tablesPlugin = ({
198
203
  dispatch
199
204
  }) => {
200
205
  var _options$fullWidthEna;
201
- 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) : undefined;
206
+ 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 === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) : undefined;
202
207
  }
203
208
  },
204
209
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
@@ -386,9 +391,10 @@ const tablesPlugin = ({
386
391
  keyshortcut: tooltip(toggleTable),
387
392
  icon: () => /*#__PURE__*/React.createElement(IconTable, null),
388
393
  action(insert, state) {
389
- const tr = insert(createTable({
390
- schema: state.schema
391
- }));
394
+ var _api$table;
395
+ // see comment on tablesPlugin.getSharedState on usage
396
+ const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
397
+ const tr = insert(createTableWithWidth(tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema));
392
398
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
393
399
  action: ACTION.INSERTED,
394
400
  actionSubject: ACTION_SUBJECT.DOCUMENT,