@atlaskit/editor-plugin-table 1.6.8 → 1.6.9

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
+ ## 1.6.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6e54d9fbeea`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6e54d9fbeea) - Added tableAddWidthPlugin
8
+
3
9
  ## 1.6.8
4
10
 
5
11
  ### Patch Changes
@@ -18,6 +18,7 @@ var _messages = require("@atlaskit/editor-common/messages");
18
18
  var _icons = require("@atlaskit/editor-common/icons");
19
19
  var _createPluginConfig = require("./create-plugin-config");
20
20
  var _tableLocalId = require("./pm-plugins/table-local-id");
21
+ var _tableAddWidth = require("./pm-plugins/table-add-width");
21
22
  var _safariDeleteCompositionTextIssueWorkaround = require("./pm-plugins/safari-delete-composition-text-issue-workaround");
22
23
  var _plugin = require("./pm-plugins/decorations/plugin");
23
24
  var _keymap = require("./pm-plugins/keymap");
@@ -175,6 +176,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
175
176
  var dispatch = _ref7.dispatch;
176
177
  return (0, _tableLocalId.createPlugin)(dispatch);
177
178
  }
179
+ }, {
180
+ name: 'tableAddWidth',
181
+ plugin: function plugin(_ref8) {
182
+ var dispatch = _ref8.dispatch;
183
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && options ? (0, _tableAddWidth.createPlugin)(dispatch, options.fullWidthEnabled || false) : undefined;
184
+ }
178
185
  }, {
179
186
  name: 'tableGetEditorViewReferencePlugin',
180
187
  plugin: function plugin() {
@@ -203,12 +210,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
203
210
  }
204
211
  return plugins;
205
212
  },
206
- contentComponent: function contentComponent(_ref8) {
207
- var editorView = _ref8.editorView,
208
- popupsMountPoint = _ref8.popupsMountPoint,
209
- popupsBoundariesElement = _ref8.popupsBoundariesElement,
210
- popupsScrollableElement = _ref8.popupsScrollableElement,
211
- dispatchAnalyticsEvent = _ref8.dispatchAnalyticsEvent;
213
+ contentComponent: function contentComponent(_ref9) {
214
+ var editorView = _ref9.editorView,
215
+ popupsMountPoint = _ref9.popupsMountPoint,
216
+ popupsBoundariesElement = _ref9.popupsBoundariesElement,
217
+ popupsScrollableElement = _ref9.popupsScrollableElement,
218
+ dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
212
219
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
213
220
  component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
214
221
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -219,25 +226,25 @@ var tablesPlugin = function tablesPlugin(options, api) {
219
226
  tableResizingPluginState: _tableResizing.pluginKey,
220
227
  stickyHeadersState: _stickyHeaders.pluginKey
221
228
  },
222
- render: function render(_ref9) {
223
- var resizingPluginState = _ref9.tableResizingPluginState,
224
- stickyHeadersState = _ref9.stickyHeadersState,
225
- tablePluginState = _ref9.tablePluginState;
229
+ render: function render(_ref10) {
230
+ var resizingPluginState = _ref10.tableResizingPluginState,
231
+ stickyHeadersState = _ref10.stickyHeadersState,
232
+ tablePluginState = _ref10.tablePluginState;
226
233
  var state = editorView.state;
227
234
  var isDragging = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
228
- var _ref10 = tablePluginState,
229
- tableNode = _ref10.tableNode,
230
- tablePos = _ref10.tablePos,
231
- targetCellPosition = _ref10.targetCellPosition,
232
- isContextualMenuOpen = _ref10.isContextualMenuOpen,
233
- layout = _ref10.layout,
234
- tableRef = _ref10.tableRef,
235
- pluginConfig = _ref10.pluginConfig,
236
- insertColumnButtonIndex = _ref10.insertColumnButtonIndex,
237
- insertRowButtonIndex = _ref10.insertRowButtonIndex,
238
- isHeaderColumnEnabled = _ref10.isHeaderColumnEnabled,
239
- isHeaderRowEnabled = _ref10.isHeaderRowEnabled,
240
- tableWrapperTarget = _ref10.tableWrapperTarget;
235
+ var _ref11 = tablePluginState,
236
+ tableNode = _ref11.tableNode,
237
+ tablePos = _ref11.tablePos,
238
+ targetCellPosition = _ref11.targetCellPosition,
239
+ isContextualMenuOpen = _ref11.isContextualMenuOpen,
240
+ layout = _ref11.layout,
241
+ tableRef = _ref11.tableRef,
242
+ pluginConfig = _ref11.pluginConfig,
243
+ insertColumnButtonIndex = _ref11.insertColumnButtonIndex,
244
+ insertRowButtonIndex = _ref11.insertRowButtonIndex,
245
+ isHeaderColumnEnabled = _ref11.isHeaderColumnEnabled,
246
+ isHeaderRowEnabled = _ref11.isHeaderRowEnabled,
247
+ tableWrapperTarget = _ref11.tableWrapperTarget;
241
248
  var allowControls = pluginConfig.allowControls;
242
249
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
243
250
  var LayoutContent = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? null : (0, _utils3.isLayoutSupported)(state) && options && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
@@ -303,8 +310,8 @@ var tablesPlugin = function tablesPlugin(options, api) {
303
310
  }));
304
311
  },
305
312
  pluginsOptions: {
306
- quickInsert: function quickInsert(_ref11) {
307
- var formatMessage = _ref11.formatMessage;
313
+ quickInsert: function quickInsert(_ref12) {
314
+ var formatMessage = _ref12.formatMessage;
308
315
  return [{
309
316
  id: 'table',
310
317
  title: formatMessage(_messages.toolbarInsertBlockMessages.table),
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
+ var _steps = require("@atlaskit/adf-schema/steps");
13
+ var _prosemirrorTransform = require("prosemirror-transform");
14
+ var _excluded = ["width"];
15
+ /**
16
+ * A plugin for scan the document, add width value to table's width attribute when necessary
17
+ *
18
+ */
19
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
+ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
22
+ return new _safePlugin.SafePlugin({
23
+ appendTransaction: function appendTransaction(transactions, _oldState, newState) {
24
+ // When document first load in Confluence, initially it is an empty document
25
+ // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
26
+ // what we need to do is to add width attr to all tables in the real document
27
+ // isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
28
+ var isReplaceDocumentOperation = transactions.some(function (tr) {
29
+ if (tr.getMeta('replaceDocument')) {
30
+ return true;
31
+ }
32
+ var hasStepReplacingEntireDocument = tr.steps.some(function (step) {
33
+ if (!(step instanceof _prosemirrorTransform.ReplaceStep)) {
34
+ return false;
35
+ }
36
+ var isStepReplacingFromDocStart = step.from === 0;
37
+ var isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
38
+ if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
39
+ return false;
40
+ }
41
+ return true;
42
+ });
43
+ return hasStepReplacingEntireDocument;
44
+ });
45
+ if (!isReplaceDocumentOperation) {
46
+ return null;
47
+ }
48
+ var tr = newState.tr;
49
+ var table = newState.schema.nodes.table;
50
+ newState.doc.forEach(function (node, offset, index) {
51
+ if (node.type === table) {
52
+ var width = node.attrs.width;
53
+ var layout = node.attrs.layout;
54
+ if (!width && layout) {
55
+ var tableWidthCal;
56
+ if (fullWidthEnabled) {
57
+ tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
58
+ } else {
59
+ switch (layout) {
60
+ case 'wide':
61
+ tableWidthCal = _editorSharedStyles.akEditorWideLayoutWidth;
62
+ break;
63
+ case 'full-width':
64
+ tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
65
+ break;
66
+ // when in fix-width apprearance, no need to assign value to table width attr
67
+ // as when table is created, width attr is null by default, table rendered using layout attr
68
+ default:
69
+ break;
70
+ }
71
+ }
72
+ var _node$attrs = node.attrs,
73
+ _width = _node$attrs.width,
74
+ rest = (0, _objectWithoutProperties2.default)(_node$attrs, _excluded);
75
+ if (tableWidthCal) {
76
+ tr.step(new _steps.SetAttrsStep(offset, _objectSpread({
77
+ width: tableWidthCal
78
+ }, rest)));
79
+ }
80
+ }
81
+ }
82
+ });
83
+ return tr;
84
+ }
85
+ });
86
+ };
87
+ exports.createPlugin = createPlugin;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "sideEffects": false
5
5
  }
@@ -11,6 +11,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
11
11
  import { IconTable } from '@atlaskit/editor-common/icons';
12
12
  import { pluginConfig } from './create-plugin-config';
13
13
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
14
+ import { createPlugin as createTableAddWidthPlugin } from './pm-plugins/table-add-width';
14
15
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
15
16
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
16
17
  import { keymapPlugin } from './pm-plugins/keymap';
@@ -158,6 +159,11 @@ const tablesPlugin = (options, api) => {
158
159
  plugin: ({
159
160
  dispatch
160
161
  }) => createTableLocalIdPlugin(dispatch)
162
+ }, {
163
+ name: 'tableAddWidth',
164
+ plugin: ({
165
+ dispatch
166
+ }) => getBooleanFF('platform.editor.custom-table-width') && options ? createTableAddWidthPlugin(dispatch, options.fullWidthEnabled || false) : undefined
161
167
  }, {
162
168
  name: 'tableGetEditorViewReferencePlugin',
163
169
  plugin: () => {
@@ -0,0 +1,78 @@
1
+ /**
2
+ * A plugin for scan the document, add width value to table's width attribute when necessary
3
+ *
4
+ */
5
+
6
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ import { akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
8
+ import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
9
+ import { ReplaceStep } from 'prosemirror-transform';
10
+ const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
11
+ appendTransaction: (transactions, _oldState, newState) => {
12
+ // When document first load in Confluence, initially it is an empty document
13
+ // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
14
+ // what we need to do is to add width attr to all tables in the real document
15
+ // isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
16
+ const isReplaceDocumentOperation = transactions.some(tr => {
17
+ if (tr.getMeta('replaceDocument')) {
18
+ return true;
19
+ }
20
+ const hasStepReplacingEntireDocument = tr.steps.some(step => {
21
+ if (!(step instanceof ReplaceStep)) {
22
+ return false;
23
+ }
24
+ const isStepReplacingFromDocStart = step.from === 0;
25
+ const isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
26
+ if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
27
+ return false;
28
+ }
29
+ return true;
30
+ });
31
+ return hasStepReplacingEntireDocument;
32
+ });
33
+ if (!isReplaceDocumentOperation) {
34
+ return null;
35
+ }
36
+ const tr = newState.tr;
37
+ const {
38
+ table
39
+ } = newState.schema.nodes;
40
+ newState.doc.forEach((node, offset, index) => {
41
+ if (node.type === table) {
42
+ const width = node.attrs.width;
43
+ const layout = node.attrs.layout;
44
+ if (!width && layout) {
45
+ let tableWidthCal;
46
+ if (fullWidthEnabled) {
47
+ tableWidthCal = akEditorFullWidthLayoutWidth;
48
+ } else {
49
+ switch (layout) {
50
+ case 'wide':
51
+ tableWidthCal = akEditorWideLayoutWidth;
52
+ break;
53
+ case 'full-width':
54
+ tableWidthCal = akEditorFullWidthLayoutWidth;
55
+ break;
56
+ // when in fix-width apprearance, no need to assign value to table width attr
57
+ // as when table is created, width attr is null by default, table rendered using layout attr
58
+ default:
59
+ break;
60
+ }
61
+ }
62
+ const {
63
+ width,
64
+ ...rest
65
+ } = node.attrs;
66
+ if (tableWidthCal) {
67
+ tr.step(new SetAttrsStep(offset, {
68
+ width: tableWidthCal,
69
+ ...rest
70
+ }));
71
+ }
72
+ }
73
+ }
74
+ });
75
+ return tr;
76
+ }
77
+ });
78
+ export { createPlugin };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "sideEffects": false
5
5
  }
@@ -11,6 +11,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
11
11
  import { IconTable } from '@atlaskit/editor-common/icons';
12
12
  import { pluginConfig } from './create-plugin-config';
13
13
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
14
+ import { createPlugin as createTableAddWidthPlugin } from './pm-plugins/table-add-width';
14
15
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
15
16
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
16
17
  import { keymapPlugin } from './pm-plugins/keymap';
@@ -168,6 +169,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
168
169
  var dispatch = _ref7.dispatch;
169
170
  return createTableLocalIdPlugin(dispatch);
170
171
  }
172
+ }, {
173
+ name: 'tableAddWidth',
174
+ plugin: function plugin(_ref8) {
175
+ var dispatch = _ref8.dispatch;
176
+ return getBooleanFF('platform.editor.custom-table-width') && options ? createTableAddWidthPlugin(dispatch, options.fullWidthEnabled || false) : undefined;
177
+ }
171
178
  }, {
172
179
  name: 'tableGetEditorViewReferencePlugin',
173
180
  plugin: function plugin() {
@@ -196,12 +203,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
196
203
  }
197
204
  return plugins;
198
205
  },
199
- contentComponent: function contentComponent(_ref8) {
200
- var editorView = _ref8.editorView,
201
- popupsMountPoint = _ref8.popupsMountPoint,
202
- popupsBoundariesElement = _ref8.popupsBoundariesElement,
203
- popupsScrollableElement = _ref8.popupsScrollableElement,
204
- dispatchAnalyticsEvent = _ref8.dispatchAnalyticsEvent;
206
+ contentComponent: function contentComponent(_ref9) {
207
+ var editorView = _ref9.editorView,
208
+ popupsMountPoint = _ref9.popupsMountPoint,
209
+ popupsBoundariesElement = _ref9.popupsBoundariesElement,
210
+ popupsScrollableElement = _ref9.popupsScrollableElement,
211
+ dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
205
212
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
206
213
  component: ACTION_SUBJECT.TABLES_PLUGIN,
207
214
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -212,25 +219,25 @@ var tablesPlugin = function tablesPlugin(options, api) {
212
219
  tableResizingPluginState: tableResizingPluginKey,
213
220
  stickyHeadersState: stickyHeadersPluginKey
214
221
  },
215
- render: function render(_ref9) {
216
- var resizingPluginState = _ref9.tableResizingPluginState,
217
- stickyHeadersState = _ref9.stickyHeadersState,
218
- tablePluginState = _ref9.tablePluginState;
222
+ render: function render(_ref10) {
223
+ var resizingPluginState = _ref10.tableResizingPluginState,
224
+ stickyHeadersState = _ref10.stickyHeadersState,
225
+ tablePluginState = _ref10.tablePluginState;
219
226
  var state = editorView.state;
220
227
  var isDragging = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
221
- var _ref10 = tablePluginState,
222
- tableNode = _ref10.tableNode,
223
- tablePos = _ref10.tablePos,
224
- targetCellPosition = _ref10.targetCellPosition,
225
- isContextualMenuOpen = _ref10.isContextualMenuOpen,
226
- layout = _ref10.layout,
227
- tableRef = _ref10.tableRef,
228
- pluginConfig = _ref10.pluginConfig,
229
- insertColumnButtonIndex = _ref10.insertColumnButtonIndex,
230
- insertRowButtonIndex = _ref10.insertRowButtonIndex,
231
- isHeaderColumnEnabled = _ref10.isHeaderColumnEnabled,
232
- isHeaderRowEnabled = _ref10.isHeaderRowEnabled,
233
- tableWrapperTarget = _ref10.tableWrapperTarget;
228
+ var _ref11 = tablePluginState,
229
+ tableNode = _ref11.tableNode,
230
+ tablePos = _ref11.tablePos,
231
+ targetCellPosition = _ref11.targetCellPosition,
232
+ isContextualMenuOpen = _ref11.isContextualMenuOpen,
233
+ layout = _ref11.layout,
234
+ tableRef = _ref11.tableRef,
235
+ pluginConfig = _ref11.pluginConfig,
236
+ insertColumnButtonIndex = _ref11.insertColumnButtonIndex,
237
+ insertRowButtonIndex = _ref11.insertRowButtonIndex,
238
+ isHeaderColumnEnabled = _ref11.isHeaderColumnEnabled,
239
+ isHeaderRowEnabled = _ref11.isHeaderRowEnabled,
240
+ tableWrapperTarget = _ref11.tableWrapperTarget;
234
241
  var allowControls = pluginConfig.allowControls;
235
242
  var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
236
243
  var LayoutContent = getBooleanFF('platform.editor.custom-table-width') ? null : isLayoutSupported(state) && options && options.breakoutEnabled ? /*#__PURE__*/React.createElement(LayoutButton, {
@@ -296,8 +303,8 @@ var tablesPlugin = function tablesPlugin(options, api) {
296
303
  }));
297
304
  },
298
305
  pluginsOptions: {
299
- quickInsert: function quickInsert(_ref11) {
300
- var formatMessage = _ref11.formatMessage;
306
+ quickInsert: function quickInsert(_ref12) {
307
+ var formatMessage = _ref12.formatMessage;
301
308
  return [{
302
309
  id: 'table',
303
310
  title: formatMessage(messages.table),
@@ -0,0 +1,81 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["width"];
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+ /**
7
+ * A plugin for scan the document, add width value to table's width attribute when necessary
8
+ *
9
+ */
10
+
11
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
12
+ import { akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
13
+ import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
14
+ import { ReplaceStep } from 'prosemirror-transform';
15
+ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
16
+ return new SafePlugin({
17
+ appendTransaction: function appendTransaction(transactions, _oldState, newState) {
18
+ // When document first load in Confluence, initially it is an empty document
19
+ // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
20
+ // what we need to do is to add width attr to all tables in the real document
21
+ // isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
22
+ var isReplaceDocumentOperation = transactions.some(function (tr) {
23
+ if (tr.getMeta('replaceDocument')) {
24
+ return true;
25
+ }
26
+ var hasStepReplacingEntireDocument = tr.steps.some(function (step) {
27
+ if (!(step instanceof ReplaceStep)) {
28
+ return false;
29
+ }
30
+ var isStepReplacingFromDocStart = step.from === 0;
31
+ var isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
32
+ if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
33
+ return false;
34
+ }
35
+ return true;
36
+ });
37
+ return hasStepReplacingEntireDocument;
38
+ });
39
+ if (!isReplaceDocumentOperation) {
40
+ return null;
41
+ }
42
+ var tr = newState.tr;
43
+ var table = newState.schema.nodes.table;
44
+ newState.doc.forEach(function (node, offset, index) {
45
+ if (node.type === table) {
46
+ var width = node.attrs.width;
47
+ var layout = node.attrs.layout;
48
+ if (!width && layout) {
49
+ var tableWidthCal;
50
+ if (fullWidthEnabled) {
51
+ tableWidthCal = akEditorFullWidthLayoutWidth;
52
+ } else {
53
+ switch (layout) {
54
+ case 'wide':
55
+ tableWidthCal = akEditorWideLayoutWidth;
56
+ break;
57
+ case 'full-width':
58
+ tableWidthCal = akEditorFullWidthLayoutWidth;
59
+ break;
60
+ // when in fix-width apprearance, no need to assign value to table width attr
61
+ // as when table is created, width attr is null by default, table rendered using layout attr
62
+ default:
63
+ break;
64
+ }
65
+ }
66
+ var _node$attrs = node.attrs,
67
+ _width = _node$attrs.width,
68
+ rest = _objectWithoutProperties(_node$attrs, _excluded);
69
+ if (tableWidthCal) {
70
+ tr.step(new SetAttrsStep(offset, _objectSpread({
71
+ width: tableWidthCal
72
+ }, rest)));
73
+ }
74
+ }
75
+ }
76
+ });
77
+ return tr;
78
+ }
79
+ });
80
+ };
81
+ export { createPlugin };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A plugin for scan the document, add width value to table's width attribute when necessary
3
+ *
4
+ */
5
+ import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
6
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<any, any>;
8
+ export { createPlugin };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A plugin for scan the document, add width value to table's width attribute when necessary
3
+ *
4
+ */
5
+ import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
6
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<any, any>;
8
+ export { createPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^25.10.0",
31
- "@atlaskit/editor-common": "^74.10.0",
31
+ "@atlaskit/editor-common": "^74.11.0",
32
32
  "@atlaskit/editor-palette": "1.5.1",
33
33
  "@atlaskit/editor-plugin-analytics": "^0.0.3",
34
34
  "@atlaskit/editor-plugin-content-insertion": "^0.0.3",
@@ -37,7 +37,7 @@
37
37
  "@atlaskit/icon": "^21.12.0",
38
38
  "@atlaskit/platform-feature-flags": "^0.2.1",
39
39
  "@atlaskit/theme": "^12.5.0",
40
- "@atlaskit/tokens": "^1.9.0",
40
+ "@atlaskit/tokens": "^1.10.0",
41
41
  "@atlaskit/tooltip": "^17.8.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@emotion/react": "^11.7.1",
@@ -65,7 +65,7 @@
65
65
  "@af/editor-libra": "*",
66
66
  "@atlaskit/analytics-next": "^9.1.0",
67
67
  "@atlaskit/button": "^16.8.0",
68
- "@atlaskit/editor-core": "^185.4.0",
68
+ "@atlaskit/editor-core": "^185.5.0",
69
69
  "@atlaskit/editor-plugin-decorations": "^0.1.0",
70
70
  "@atlaskit/editor-plugin-feature-flags": "^0.1.0",
71
71
  "@atlaskit/editor-plugin-grid": "^0.1.0",
@@ -37,6 +37,7 @@ import type { EditorSelectionAPI } from '@atlaskit/editor-common/selection';
37
37
 
38
38
  import { pluginConfig } from './create-plugin-config';
39
39
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
40
+ import { createPlugin as createTableAddWidthPlugin } from './pm-plugins/table-add-width';
40
41
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
41
42
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
42
43
  import { keymapPlugin } from './pm-plugins/keymap';
@@ -268,6 +269,16 @@ const tablesPlugin: NextEditorPlugin<
268
269
  name: 'tableLocalId',
269
270
  plugin: ({ dispatch }) => createTableLocalIdPlugin(dispatch),
270
271
  },
272
+ {
273
+ name: 'tableAddWidth',
274
+ plugin: ({ dispatch }) =>
275
+ getBooleanFF('platform.editor.custom-table-width') && options
276
+ ? createTableAddWidthPlugin(
277
+ dispatch,
278
+ options.fullWidthEnabled || false,
279
+ )
280
+ : undefined,
281
+ },
271
282
 
272
283
  {
273
284
  name: 'tableGetEditorViewReferencePlugin',
@@ -0,0 +1,103 @@
1
+ /**
2
+ * A plugin for scan the document, add width value to table's width attribute when necessary
3
+ *
4
+ */
5
+ import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
6
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ import {
8
+ akEditorFullWidthLayoutWidth,
9
+ akEditorWideLayoutWidth,
10
+ } from '@atlaskit/editor-shared-styles';
11
+ import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
12
+ import { ReplaceStep } from 'prosemirror-transform';
13
+
14
+ type __ReplaceStep = ReplaceStep & {
15
+ // Properties `to` and `from` are private attributes of ReplaceStep.
16
+ to: number;
17
+ from: number;
18
+ };
19
+
20
+ const createPlugin = (dispatch: Dispatch, fullWidthEnabled: boolean) =>
21
+ new SafePlugin({
22
+ appendTransaction: (transactions, _oldState, newState) => {
23
+ // When document first load in Confluence, initially it is an empty document
24
+ // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
25
+ // what we need to do is to add width attr to all tables in the real document
26
+ // isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
27
+ const isReplaceDocumentOperation = transactions.some((tr) => {
28
+ if (tr.getMeta('replaceDocument')) {
29
+ return true;
30
+ }
31
+
32
+ const hasStepReplacingEntireDocument = tr.steps.some((step) => {
33
+ if (!(step instanceof ReplaceStep)) {
34
+ return false;
35
+ }
36
+
37
+ const isStepReplacingFromDocStart =
38
+ (step as __ReplaceStep).from === 0;
39
+ const isStepReplacingUntilTheEndOfDocument =
40
+ (step as __ReplaceStep).to === _oldState.doc.content.size;
41
+
42
+ if (
43
+ !isStepReplacingFromDocStart ||
44
+ !isStepReplacingUntilTheEndOfDocument
45
+ ) {
46
+ return false;
47
+ }
48
+ return true;
49
+ });
50
+
51
+ return hasStepReplacingEntireDocument;
52
+ });
53
+
54
+ if (!isReplaceDocumentOperation) {
55
+ return null;
56
+ }
57
+
58
+ const tr = newState.tr;
59
+ const { table } = newState.schema.nodes;
60
+
61
+ newState.doc.forEach((node, offset, index) => {
62
+ if (node.type === table) {
63
+ const width = node.attrs.width;
64
+ const layout = node.attrs.layout;
65
+
66
+ if (!width && layout) {
67
+ let tableWidthCal;
68
+
69
+ if (fullWidthEnabled) {
70
+ tableWidthCal = akEditorFullWidthLayoutWidth;
71
+ } else {
72
+ switch (layout) {
73
+ case 'wide':
74
+ tableWidthCal = akEditorWideLayoutWidth;
75
+ break;
76
+ case 'full-width':
77
+ tableWidthCal = akEditorFullWidthLayoutWidth;
78
+ break;
79
+ // when in fix-width apprearance, no need to assign value to table width attr
80
+ // as when table is created, width attr is null by default, table rendered using layout attr
81
+ default:
82
+ break;
83
+ }
84
+ }
85
+
86
+ const { width, ...rest } = node.attrs;
87
+
88
+ if (tableWidthCal) {
89
+ tr.step(
90
+ new SetAttrsStep(offset, {
91
+ width: tableWidthCal,
92
+ ...rest,
93
+ }),
94
+ );
95
+ }
96
+ }
97
+ }
98
+ });
99
+ return tr;
100
+ },
101
+ });
102
+
103
+ export { createPlugin };