@atlaskit/editor-plugin-table 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/table/index.js +40 -34
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +1 -2
  4. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +21 -13
  5. package/dist/cjs/plugins/table/nodeviews/table.js +7 -2
  6. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +14 -5
  7. package/dist/cjs/plugins/table/pm-plugins/{table-add-width.js → table-width.js} +27 -4
  8. package/dist/cjs/plugins/table/toolbar.js +6 -1
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/plugins/table/index.js +18 -9
  11. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +1 -2
  12. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +26 -14
  13. package/dist/es2019/plugins/table/nodeviews/table.js +7 -2
  14. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +14 -5
  15. package/dist/es2019/plugins/table/pm-plugins/{table-add-width.js → table-width.js} +25 -3
  16. package/dist/es2019/plugins/table/toolbar.js +6 -1
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/plugins/table/index.js +40 -34
  19. package/dist/esm/plugins/table/nodeviews/TableComponent.js +1 -2
  20. package/dist/esm/plugins/table/nodeviews/TableResizer.js +21 -13
  21. package/dist/esm/plugins/table/nodeviews/table.js +7 -2
  22. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +14 -5
  23. package/dist/esm/plugins/table/pm-plugins/{table-add-width.js → table-width.js} +25 -3
  24. package/dist/esm/plugins/table/toolbar.js +6 -1
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -2
  27. package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +1 -1
  28. package/dist/types/plugins/table/pm-plugins/table-width.d.ts +16 -0
  29. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -2
  30. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +1 -1
  31. package/dist/types-ts4.5/plugins/table/pm-plugins/table-width.d.ts +16 -0
  32. package/package.json +3 -3
  33. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +66 -0
  34. package/src/plugins/table/index.tsx +35 -22
  35. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -6
  36. package/src/plugins/table/nodeviews/TableResizer.tsx +27 -20
  37. package/src/plugins/table/nodeviews/table.tsx +12 -2
  38. package/src/plugins/table/pm-plugins/decorations/plugin.ts +26 -4
  39. package/src/plugins/table/pm-plugins/{table-add-width.ts → table-width.ts} +33 -3
  40. package/src/plugins/table/toolbar.tsx +7 -1
  41. package/dist/types/plugins/table/pm-plugins/table-add-width.d.ts +0 -7
  42. package/dist/types-ts4.5/plugins/table/pm-plugins/table-add-width.d.ts +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`464c9736dff`](https://bitbucket.org/atlassian/atlassian-frontend/commits/464c9736dff) - [ux] [ED-17626] Remove table controls during table width resizing
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 2.2.0
4
14
 
5
15
  ### Minor Changes
@@ -18,7 +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
+ var _tableWidth = require("./pm-plugins/table-width");
22
22
  var _safariDeleteCompositionTextIssueWorkaround = require("./pm-plugins/safari-delete-composition-text-issue-workaround");
23
23
  var _plugin = require("./pm-plugins/decorations/plugin");
24
24
  var _keymap = require("./pm-plugins/keymap");
@@ -172,9 +172,11 @@ var tablesPlugin = function tablesPlugin(options, api) {
172
172
  return (0, _tableLocalId.createPlugin)(dispatch);
173
173
  }
174
174
  }, {
175
- name: 'tableAddWidth',
176
- plugin: function plugin() {
177
- return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && options ? (0, _tableAddWidth.createPlugin)(options.fullWidthEnabled || false) : undefined;
175
+ name: 'tableWidth',
176
+ plugin: function plugin(_ref8) {
177
+ var _options$fullWidthEna;
178
+ var dispatch = _ref8.dispatch;
179
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? (0, _tableWidth.createPlugin)(dispatch, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
178
180
  }
179
181
  }, {
180
182
  name: 'tableGetEditorViewReferencePlugin',
@@ -204,12 +206,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
204
206
  }
205
207
  return plugins;
206
208
  },
207
- contentComponent: function contentComponent(_ref8) {
208
- var editorView = _ref8.editorView,
209
- popupsMountPoint = _ref8.popupsMountPoint,
210
- popupsBoundariesElement = _ref8.popupsBoundariesElement,
211
- popupsScrollableElement = _ref8.popupsScrollableElement,
212
- dispatchAnalyticsEvent = _ref8.dispatchAnalyticsEvent;
209
+ contentComponent: function contentComponent(_ref9) {
210
+ var editorView = _ref9.editorView,
211
+ popupsMountPoint = _ref9.popupsMountPoint,
212
+ popupsBoundariesElement = _ref9.popupsBoundariesElement,
213
+ popupsScrollableElement = _ref9.popupsScrollableElement,
214
+ dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
213
215
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
214
216
  component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
215
217
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -217,28 +219,32 @@ var tablesPlugin = function tablesPlugin(options, api) {
217
219
  }, /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
218
220
  plugins: {
219
221
  tablePluginState: _pluginKey.pluginKey,
222
+ tableWidthPluginState: _tableWidth.pluginKey,
220
223
  tableResizingPluginState: _tableResizing.pluginKey,
221
224
  stickyHeadersState: _stickyHeaders.pluginKey
222
225
  },
223
- render: function render(_ref9) {
224
- var resizingPluginState = _ref9.tableResizingPluginState,
225
- stickyHeadersState = _ref9.stickyHeadersState,
226
- tablePluginState = _ref9.tablePluginState;
226
+ render: function render(_ref10) {
227
+ var resizingPluginState = _ref10.tableResizingPluginState,
228
+ stickyHeadersState = _ref10.stickyHeadersState,
229
+ tablePluginState = _ref10.tablePluginState,
230
+ tableWidthPluginState = _ref10.tableWidthPluginState;
227
231
  var state = editorView.state;
228
- var isDragging = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
229
- var _ref10 = tablePluginState,
230
- tableNode = _ref10.tableNode,
231
- tablePos = _ref10.tablePos,
232
- targetCellPosition = _ref10.targetCellPosition,
233
- isContextualMenuOpen = _ref10.isContextualMenuOpen,
234
- layout = _ref10.layout,
235
- tableRef = _ref10.tableRef,
236
- pluginConfig = _ref10.pluginConfig,
237
- insertColumnButtonIndex = _ref10.insertColumnButtonIndex,
238
- insertRowButtonIndex = _ref10.insertRowButtonIndex,
239
- isHeaderColumnEnabled = _ref10.isHeaderColumnEnabled,
240
- isHeaderRowEnabled = _ref10.isHeaderRowEnabled,
241
- tableWrapperTarget = _ref10.tableWrapperTarget;
232
+ var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
233
+ var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
234
+ var isResizing = isColumnResizing || isTableResizing;
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;
242
248
  var allowControls = pluginConfig.allowControls;
243
249
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
244
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, {
@@ -252,7 +258,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
252
258
  stickyHeader: stickyHeader,
253
259
  editorAnalyticsAPI: editorAnalyticsAPI
254
260
  }) : null;
255
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/_react.default.createElement(_FloatingContextualButton.default, {
261
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, targetCellPosition && tableRef && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/_react.default.createElement(_FloatingContextualButton.default, {
256
262
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
257
263
  editorView: editorView,
258
264
  tableNode: tableNode,
@@ -279,17 +285,17 @@ var tablesPlugin = function tablesPlugin(options, api) {
279
285
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
280
286
  editorAnalyticsAPI: editorAnalyticsAPI,
281
287
  getEditorContainerWidth: defaultGetEditorContainerWidth
282
- }), /*#__PURE__*/_react.default.createElement(_FloatingContextualMenu.default, {
288
+ }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/_react.default.createElement(_FloatingContextualMenu.default, {
283
289
  editorView: editorView,
284
290
  mountPoint: popupsMountPoint,
285
291
  boundariesElement: popupsBoundariesElement,
286
292
  targetCellPosition: targetCellPosition,
287
- isOpen: Boolean(isContextualMenuOpen),
293
+ isOpen: Boolean(isContextualMenuOpen) && !isResizing,
288
294
  pluginConfig: pluginConfig,
289
295
  editorAnalyticsAPI: editorAnalyticsAPI,
290
296
  getEditorContainerWidth: defaultGetEditorContainerWidth,
291
297
  getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
292
- }), allowControls && /*#__PURE__*/_react.default.createElement(_FloatingDeleteButton.default, {
298
+ }), allowControls && !isResizing && /*#__PURE__*/_react.default.createElement(_FloatingDeleteButton.default, {
293
299
  editorView: editorView,
294
300
  selection: editorView.state.selection,
295
301
  tableRef: tableRef,
@@ -304,8 +310,8 @@ var tablesPlugin = function tablesPlugin(options, api) {
304
310
  }));
305
311
  },
306
312
  pluginsOptions: {
307
- quickInsert: function quickInsert(_ref11) {
308
- var formatMessage = _ref11.formatMessage;
313
+ quickInsert: function quickInsert(_ref12) {
314
+ var formatMessage = _ref12.formatMessage;
309
315
  return [{
310
316
  id: 'table',
311
317
  title: formatMessage(_messages.toolbarInsertBlockMessages.table),
@@ -384,7 +384,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
384
384
  var _this$props8 = this.props,
385
385
  view = _this$props8.view,
386
386
  getNode = _this$props8.getNode,
387
- tableResizingPluginState = _this$props8.tableResizingPluginState,
387
+ isResizing = _this$props8.isResizing,
388
388
  _this$props8$allowCon = _this$props8.allowControls,
389
389
  allowControls = _this$props8$allowCon === void 0 ? true : _this$props8$allowCon,
390
390
  isHeaderRowEnabled = _this$props8.isHeaderRowEnabled,
@@ -410,7 +410,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
410
410
  tableRenderOptimization = _this$props$getEditor4.tableRenderOptimization,
411
411
  tableOverflowShadowsOptimization = _this$props$getEditor4.tableOverflowShadowsOptimization;
412
412
  var tableRef = this.table || undefined;
413
- var isResizing = !!tableResizingPluginState && !!tableResizingPluginState.dragging;
414
413
  var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
415
414
 
416
415
  //dont need to change tableHeight with tableRenderOptimization because it will be observed inside floating components
@@ -13,6 +13,7 @@ var _rafSchd = _interopRequireDefault(require("raf-schd"));
13
13
  var _resizer = require("@atlaskit/editor-common/resizer");
14
14
  var _guideline = require("@atlaskit/editor-common/guideline");
15
15
  var _utils = require("../pm-plugins/table-resizing/utils");
16
+ var _tableWidth = require("../pm-plugins/table-width");
16
17
  var _guidelines = require("../utils/guidelines");
17
18
  var _snapping = require("../utils/snapping");
18
19
  var _consts = require("../ui/consts");
@@ -70,27 +71,34 @@ var TableResizer = function TableResizer(_ref) {
70
71
  } : undefined;
71
72
  }, [snappingEnabled]);
72
73
  var handleResizeStart = (0, _react.useCallback)(function () {
74
+ var dispatch = editorView.dispatch,
75
+ tr = editorView.state.tr;
76
+ dispatch(tr.setMeta(_tableWidth.pluginKey, {
77
+ resizing: true
78
+ }));
73
79
  setSnappingEnabled(displayGuideline(_guidelines.defaultGuidelines));
74
80
  return width;
75
- }, [width, displayGuideline]);
81
+ }, [width, displayGuideline, editorView]);
76
82
  var handleResizeStop = (0, _react.useCallback)(function (originalState, delta) {
77
83
  var newWidth = originalState.width + delta.width;
78
84
  var state = editorView.state,
79
85
  dispatch = editorView.dispatch;
80
86
  var pos = getPos();
81
- if (typeof pos !== 'number') {
82
- return;
87
+ var tr = state.tr.setMeta(_tableWidth.pluginKey, {
88
+ resizing: false
89
+ });
90
+ if (typeof pos === 'number') {
91
+ tr = tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
92
+ width: newWidth
93
+ }));
94
+ var newNode = tr.doc.nodeAt(pos);
95
+ tr = (0, _utils.scaleTable)(tableRef, {
96
+ node: newNode,
97
+ prevNode: node,
98
+ start: pos + 1,
99
+ parentWidth: newWidth
100
+ }, editorView.domAtPos.bind(editorView))(tr);
83
101
  }
84
- var tr = state.tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
85
- width: newWidth
86
- }));
87
- var newNode = tr.doc.nodeAt(pos);
88
- tr = (0, _utils.scaleTable)(tableRef, {
89
- node: newNode,
90
- prevNode: node,
91
- start: pos + 1,
92
- parentWidth: newWidth
93
- }, editorView.domAtPos.bind(editorView))(tr);
94
102
  dispatch(tr);
95
103
 
96
104
  // Hide guidelines when resizing stops
@@ -23,6 +23,7 @@ var _createPluginConfig = require("../create-plugin-config");
23
23
  var _pluginFactory = require("../pm-plugins/plugin-factory");
24
24
  var _pluginKey = require("../pm-plugins/plugin-key");
25
25
  var _tableResizing = require("../pm-plugins/table-resizing");
26
+ var _tableWidth = require("../pm-plugins/table-width");
26
27
  var _utils = require("../pm-plugins/table-resizing/utils");
27
28
  var _tableMap = require("@atlaskit/editor-tables/table-map");
28
29
  var _TableComponent = _interopRequireDefault(require("./TableComponent"));
@@ -114,16 +115,20 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
114
115
  plugins: {
115
116
  pluginState: _pluginKey.pluginKey,
116
117
  tableResizingPluginState: _tableResizing.pluginKey,
118
+ tableWidthPluginState: _tableWidth.pluginKey,
117
119
  widthPlugin: fakePluginKey,
118
120
  mediaState: fakeMediaPluginKey
119
121
  },
120
122
  editorView: props.view,
121
123
  render: function render(pluginStates) {
122
124
  var tableResizingPluginState = pluginStates.tableResizingPluginState,
125
+ tableWidthPluginState = pluginStates.tableWidthPluginState,
123
126
  pluginState = pluginStates.pluginState,
124
127
  mediaState = pluginStates.mediaState;
125
- var tableActive = props.getPos() === pluginState.tablePos;
126
128
  var containerWidth = props.getEditorContainerWidth();
129
+ var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
130
+ var isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
131
+ var tableActive = props.getPos() === pluginState.tablePos && !isTableResizing;
127
132
  return /*#__PURE__*/_react.default.createElement(_TableComponent.default, {
128
133
  view: props.view,
129
134
  allowColumnResizing: props.allowColumnResizing,
@@ -136,7 +141,7 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
136
141
  isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
137
142
  tableActive: tableActive,
138
143
  ordering: pluginState.ordering,
139
- tableResizingPluginState: tableResizingPluginState,
144
+ isResizing: isResizing,
140
145
  getNode: _this3.getNode,
141
146
  containerWidth: containerWidth,
142
147
  contentDOM: forwardRef,
@@ -9,6 +9,7 @@ var _prosemirrorState = require("prosemirror-state");
9
9
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
10
10
  var _prosemirrorView = require("prosemirror-view");
11
11
  var _pluginKey = require("../plugin-key");
12
+ var _tableWidth = require("../table-width");
12
13
  var _utils = require("./utils");
13
14
  var pluginKey = new _prosemirrorState.PluginKey('tableDecorationsPlugin');
14
15
  exports.pluginKey = pluginKey;
@@ -16,8 +17,16 @@ var getDecorations = function getDecorations(state) {
16
17
  return pluginKey.getState(state);
17
18
  };
18
19
  exports.getDecorations = getDecorations;
19
- var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, decorationSet, oldState) {
20
- if (tr.docChanged || tr.selection instanceof _cellSelection.CellSelection) {
20
+ var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, decorationSet, oldState, newState) {
21
+ var _tableWidthPluginKey$, _tableWidthPluginKey$2;
22
+ var isResizing = (_tableWidthPluginKey$ = _tableWidth.pluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
23
+ var wasResizing = (_tableWidthPluginKey$2 = _tableWidth.pluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
24
+ var changedResizing = isResizing !== wasResizing;
25
+
26
+ // Remove column controls when resizing
27
+ if (isResizing) {
28
+ return _prosemirrorView.DecorationSet.empty;
29
+ } else if (tr.docChanged || tr.selection instanceof _cellSelection.CellSelection || changedResizing) {
21
30
  return (0, _utils.buildColumnControlsDecorations)({
22
31
  decorationSet: decorationSet,
23
32
  tr: tr
@@ -40,15 +49,15 @@ var createPlugin = function createPlugin() {
40
49
  init: function init() {
41
50
  return _prosemirrorView.DecorationSet.empty;
42
51
  },
43
- apply: function apply(tr, decorationSet, oldState) {
52
+ apply: function apply(tr, decorationSet, oldState, newState) {
44
53
  var pluginState = decorationSet;
45
54
  var meta = tr.getMeta(_pluginKey.pluginKey);
46
55
  if (meta && meta.data && meta.data.decorationSet) {
47
56
  pluginState = meta.data.decorationSet;
48
57
  }
49
- if (tr.docChanged || tr.selectionSet) {
58
+ if (tr.docChanged || tr.selectionSet || tr.getMeta(_tableWidth.pluginKey)) {
50
59
  pluginState = pluginState.map(tr.mapping, tr.doc);
51
- return handleDocOrSelectionChanged(tr, pluginState, oldState);
60
+ return handleDocOrSelectionChanged(tr, pluginState, oldState, newState);
52
61
  }
53
62
  return pluginState;
54
63
  }
@@ -4,22 +4,45 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.createPlugin = void 0;
7
+ exports.pluginKey = exports.createPlugin = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
11
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
12
  var _steps = require("@atlaskit/adf-schema/steps");
13
13
  var _prosemirrorTransform = require("prosemirror-transform");
14
+ var _prosemirrorState = require("prosemirror-state");
14
15
  var _excluded = ["width"];
15
16
  /**
16
- * A plugin for scan the document, add width value to table's width attribute when necessary
17
- *
17
+ * A plugin for handle table custom widths
18
+ * Has login to scan the document, add width value to table's width attribute when necessary
19
+ * Also holds resizing state to hide / show table controls
18
20
  */
19
21
  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
22
  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(fullWidthEnabled) {
23
+ var pluginKey = new _prosemirrorState.PluginKey('tableWidthPlugin');
24
+ exports.pluginKey = pluginKey;
25
+ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
22
26
  return new _safePlugin.SafePlugin({
27
+ key: pluginKey,
28
+ state: {
29
+ init: function init() {
30
+ return {
31
+ resizing: false
32
+ };
33
+ },
34
+ apply: function apply(tr, pluginState) {
35
+ var meta = tr.getMeta(pluginKey);
36
+ if (meta && meta.resizing !== pluginState.resizing) {
37
+ var newState = {
38
+ resizing: meta.resizing
39
+ };
40
+ dispatch(pluginKey, newState);
41
+ return newState;
42
+ }
43
+ return pluginState;
44
+ }
45
+ },
23
46
  appendTransaction: function appendTransaction(transactions, _oldState, newState) {
24
47
  // When document first load in Confluence, initially it is an empty document
25
48
  // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
@@ -13,6 +13,7 @@ var _commands = require("./commands");
13
13
  var _commandsWithAnalytics = require("./commands-with-analytics");
14
14
  var _pluginFactory = require("./pm-plugins/plugin-factory");
15
15
  var _tableResizing = require("./pm-plugins/table-resizing");
16
+ var _tableWidth = require("./pm-plugins/table-width");
16
17
  var _types = require("./types");
17
18
  var _utils = require("./utils");
18
19
  var _utils2 = require("@atlaskit/editor-common/utils");
@@ -302,7 +303,11 @@ var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth, editor
302
303
  var tableObject = (0, _utils3.findTable)(state.selection);
303
304
  var pluginState = (0, _pluginFactory.getPluginState)(state);
304
305
  var resizeState = _tableResizing.pluginKey.getState(state);
305
- if (tableObject && pluginState.editorHasFocus) {
306
+ var tableWidthState = _tableWidth.pluginKey.getState(state);
307
+
308
+ // We don't want to show floating toolbar while resizing the table
309
+ var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
310
+ if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
306
311
  var nodeType = state.schema.nodes.table;
307
312
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
308
313
  var _ref3 = getEditorFeatureFlags() || {},
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -11,7 +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
+ import { pluginKey as tableWidthPluginKey, createPlugin as createTableWidthPlugin } from './pm-plugins/table-width';
15
15
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
16
16
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
17
17
  import { keymapPlugin } from './pm-plugins/keymap';
@@ -155,8 +155,13 @@ const tablesPlugin = (options, api) => {
155
155
  dispatch
156
156
  }) => createTableLocalIdPlugin(dispatch)
157
157
  }, {
158
- name: 'tableAddWidth',
159
- plugin: () => getBooleanFF('platform.editor.custom-table-width') && options ? createTableAddWidthPlugin(options.fullWidthEnabled || false) : undefined
158
+ name: 'tableWidth',
159
+ plugin: ({
160
+ dispatch
161
+ }) => {
162
+ var _options$fullWidthEna;
163
+ return getBooleanFF('platform.editor.custom-table-width') ? createTableWidthPlugin(dispatch, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
164
+ }
160
165
  }, {
161
166
  name: 'tableGetEditorViewReferencePlugin',
162
167
  plugin: () => {
@@ -199,18 +204,22 @@ const tablesPlugin = (options, api) => {
199
204
  }, /*#__PURE__*/React.createElement(WithPluginState, {
200
205
  plugins: {
201
206
  tablePluginState: pluginKey,
207
+ tableWidthPluginState: tableWidthPluginKey,
202
208
  tableResizingPluginState: tableResizingPluginKey,
203
209
  stickyHeadersState: stickyHeadersPluginKey
204
210
  },
205
211
  render: ({
206
212
  tableResizingPluginState: resizingPluginState,
207
213
  stickyHeadersState,
208
- tablePluginState
214
+ tablePluginState,
215
+ tableWidthPluginState
209
216
  }) => {
210
217
  const {
211
218
  state
212
219
  } = editorView;
213
- const isDragging = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
220
+ const isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
221
+ const isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
222
+ const isResizing = isColumnResizing || isTableResizing;
214
223
  const {
215
224
  tableNode,
216
225
  tablePos,
@@ -240,7 +249,7 @@ const tablesPlugin = (options, api) => {
240
249
  stickyHeader: stickyHeader,
241
250
  editorAnalyticsAPI: editorAnalyticsAPI
242
251
  }) : null;
243
- return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
252
+ return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
244
253
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
245
254
  editorView: editorView,
246
255
  tableNode: tableNode,
@@ -267,17 +276,17 @@ const tablesPlugin = (options, api) => {
267
276
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
268
277
  editorAnalyticsAPI: editorAnalyticsAPI,
269
278
  getEditorContainerWidth: defaultGetEditorContainerWidth
270
- }), /*#__PURE__*/React.createElement(FloatingContextualMenu, {
279
+ }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
271
280
  editorView: editorView,
272
281
  mountPoint: popupsMountPoint,
273
282
  boundariesElement: popupsBoundariesElement,
274
283
  targetCellPosition: targetCellPosition,
275
- isOpen: Boolean(isContextualMenuOpen),
284
+ isOpen: Boolean(isContextualMenuOpen) && !isResizing,
276
285
  pluginConfig: pluginConfig,
277
286
  editorAnalyticsAPI: editorAnalyticsAPI,
278
287
  getEditorContainerWidth: defaultGetEditorContainerWidth,
279
288
  getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
280
- }), allowControls && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
289
+ }), allowControls && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
281
290
  editorView: editorView,
282
291
  selection: editorView.state.selection,
283
292
  tableRef: tableRef,
@@ -376,7 +376,7 @@ class TableComponent extends React.Component {
376
376
  const {
377
377
  view,
378
378
  getNode,
379
- tableResizingPluginState,
379
+ isResizing,
380
380
  allowControls = true,
381
381
  isHeaderRowEnabled,
382
382
  ordering,
@@ -405,7 +405,6 @@ class TableComponent extends React.Component {
405
405
  tableOverflowShadowsOptimization
406
406
  } = this.props.getEditorFeatureFlags();
407
407
  const tableRef = this.table || undefined;
408
- const isResizing = !!tableResizingPluginState && !!tableResizingPluginState.dragging;
409
408
  const headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
410
409
 
411
410
  //dont need to change tableHeight with tableRenderOptimization because it will be observed inside floating components
@@ -3,6 +3,7 @@ import rafSchd from 'raf-schd';
3
3
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
4
4
  import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
5
5
  import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH } from '../pm-plugins/table-resizing/utils';
6
+ import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
6
7
  import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
7
8
  import { findClosestSnap } from '../utils/snapping';
8
9
  import { TABLE_SNAP_GAP, TABLE_HIGHLIGHT_GAP } from '../ui/consts';
@@ -53,9 +54,18 @@ export const TableResizer = ({
53
54
  x: defaultGuidelineWidths
54
55
  } : undefined, [snappingEnabled]);
55
56
  const handleResizeStart = useCallback(() => {
57
+ const {
58
+ dispatch,
59
+ state: {
60
+ tr
61
+ }
62
+ } = editorView;
63
+ dispatch(tr.setMeta(tableWidthPluginKey, {
64
+ resizing: true
65
+ }));
56
66
  setSnappingEnabled(displayGuideline(defaultGuidelines));
57
67
  return width;
58
- }, [width, displayGuideline]);
68
+ }, [width, displayGuideline, editorView]);
59
69
  const handleResizeStop = useCallback((originalState, delta) => {
60
70
  const newWidth = originalState.width + delta.width;
61
71
  const {
@@ -63,20 +73,22 @@ export const TableResizer = ({
63
73
  dispatch
64
74
  } = editorView;
65
75
  const pos = getPos();
66
- if (typeof pos !== 'number') {
67
- return;
68
- }
69
- let tr = state.tr.setNodeMarkup(pos, undefined, {
70
- ...node.attrs,
71
- width: newWidth
76
+ let tr = state.tr.setMeta(tableWidthPluginKey, {
77
+ resizing: false
72
78
  });
73
- const newNode = tr.doc.nodeAt(pos);
74
- tr = scaleTable(tableRef, {
75
- node: newNode,
76
- prevNode: node,
77
- start: pos + 1,
78
- parentWidth: newWidth
79
- }, editorView.domAtPos.bind(editorView))(tr);
79
+ if (typeof pos === 'number') {
80
+ tr = tr.setNodeMarkup(pos, undefined, {
81
+ ...node.attrs,
82
+ width: newWidth
83
+ });
84
+ const newNode = tr.doc.nodeAt(pos);
85
+ tr = scaleTable(tableRef, {
86
+ node: newNode,
87
+ prevNode: node,
88
+ start: pos + 1,
89
+ parentWidth: newWidth
90
+ }, editorView.domAtPos.bind(editorView))(tr);
91
+ }
80
92
  dispatch(tr);
81
93
 
82
94
  // Hide guidelines when resizing stops
@@ -7,6 +7,7 @@ import { pluginConfig as getPluginConfig } from '../create-plugin-config';
7
7
  import { getPluginState } from '../pm-plugins/plugin-factory';
8
8
  import { pluginKey } from '../pm-plugins/plugin-key';
9
9
  import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizing';
10
+ import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
10
11
  import { generateColgroup } from '../pm-plugins/table-resizing/utils';
11
12
  import { TableMap } from '@atlaskit/editor-tables/table-map';
12
13
  import TableComponent from './TableComponent';
@@ -83,6 +84,7 @@ export default class TableView extends ReactNodeView {
83
84
  plugins: {
84
85
  pluginState: pluginKey,
85
86
  tableResizingPluginState: tableResizingPluginKey,
87
+ tableWidthPluginState: tableWidthPluginKey,
86
88
  widthPlugin: fakePluginKey,
87
89
  mediaState: fakeMediaPluginKey
88
90
  },
@@ -90,12 +92,15 @@ export default class TableView extends ReactNodeView {
90
92
  render: pluginStates => {
91
93
  const {
92
94
  tableResizingPluginState,
95
+ tableWidthPluginState,
93
96
  pluginState,
94
97
  // containerWidth,
95
98
  mediaState
96
99
  } = pluginStates;
97
- const tableActive = props.getPos() === pluginState.tablePos;
98
100
  const containerWidth = props.getEditorContainerWidth();
101
+ const isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
102
+ const isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
103
+ const tableActive = props.getPos() === pluginState.tablePos && !isTableResizing;
99
104
  return /*#__PURE__*/React.createElement(TableComponent, {
100
105
  view: props.view,
101
106
  allowColumnResizing: props.allowColumnResizing,
@@ -108,7 +113,7 @@ export default class TableView extends ReactNodeView {
108
113
  isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
109
114
  tableActive: tableActive,
110
115
  ordering: pluginState.ordering,
111
- tableResizingPluginState: tableResizingPluginState,
116
+ isResizing: isResizing,
112
117
  getNode: this.getNode,
113
118
  containerWidth: containerWidth,
114
119
  contentDOM: forwardRef,
@@ -6,11 +6,20 @@ import { PluginKey
6
6
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
7
7
  import { DecorationSet } from 'prosemirror-view';
8
8
  import { pluginKey as tablePluginKey } from '../plugin-key';
9
+ import { pluginKey as tableWidthPluginKey } from '../table-width';
9
10
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
10
11
  export const pluginKey = new PluginKey('tableDecorationsPlugin');
11
12
  export const getDecorations = state => pluginKey.getState(state);
12
- export const handleDocOrSelectionChanged = (tr, decorationSet, oldState) => {
13
- if (tr.docChanged || tr.selection instanceof CellSelection) {
13
+ export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newState) => {
14
+ var _tableWidthPluginKey$, _tableWidthPluginKey$2;
15
+ const isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
16
+ const wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
17
+ const changedResizing = isResizing !== wasResizing;
18
+
19
+ // Remove column controls when resizing
20
+ if (isResizing) {
21
+ return DecorationSet.empty;
22
+ } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
14
23
  return buildColumnControlsDecorations({
15
24
  decorationSet,
16
25
  tr
@@ -30,15 +39,15 @@ export const createPlugin = () => {
30
39
  return new SafePlugin({
31
40
  state: {
32
41
  init: () => DecorationSet.empty,
33
- apply: (tr, decorationSet, oldState) => {
42
+ apply: (tr, decorationSet, oldState, newState) => {
34
43
  let pluginState = decorationSet;
35
44
  const meta = tr.getMeta(tablePluginKey);
36
45
  if (meta && meta.data && meta.data.decorationSet) {
37
46
  pluginState = meta.data.decorationSet;
38
47
  }
39
- if (tr.docChanged || tr.selectionSet) {
48
+ if (tr.docChanged || tr.selectionSet || tr.getMeta(tableWidthPluginKey)) {
40
49
  pluginState = pluginState.map(tr.mapping, tr.doc);
41
- return handleDocOrSelectionChanged(tr, pluginState, oldState);
50
+ return handleDocOrSelectionChanged(tr, pluginState, oldState, newState);
42
51
  }
43
52
  return pluginState;
44
53
  }