@atlaskit/editor-plugin-table 1.5.5 → 1.6.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 (61) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/table/index.js +12 -11
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +37 -78
  4. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +131 -0
  5. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +65 -0
  6. package/dist/cjs/plugins/table/pm-plugins/table-resizing/commands.js +4 -49
  7. package/dist/cjs/plugins/table/pm-plugins/table-resizing/index.js +0 -7
  8. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/index.js +12 -6
  9. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +3 -11
  10. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/plugins/table/index.js +12 -11
  13. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +17 -64
  14. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +124 -0
  15. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +56 -0
  16. package/dist/es2019/plugins/table/pm-plugins/table-resizing/commands.js +2 -48
  17. package/dist/es2019/plugins/table/pm-plugins/table-resizing/index.js +0 -1
  18. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
  19. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
  20. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/plugins/table/index.js +12 -11
  23. package/dist/esm/plugins/table/nodeviews/TableComponent.js +39 -81
  24. package/dist/esm/plugins/table/nodeviews/TableContainer.js +119 -0
  25. package/dist/esm/plugins/table/nodeviews/TableResizer.js +57 -0
  26. package/dist/esm/plugins/table/pm-plugins/table-resizing/commands.js +4 -48
  27. package/dist/esm/plugins/table/pm-plugins/table-resizing/index.js +0 -1
  28. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
  29. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
  30. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +59 -2
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +0 -3
  33. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +35 -0
  34. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +13 -0
  35. package/dist/types/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
  36. package/dist/types/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
  37. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  38. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
  39. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
  40. package/dist/types/plugins/table/types.d.ts +1 -0
  41. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -3
  42. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +35 -0
  43. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +13 -0
  44. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
  45. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
  46. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  47. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
  48. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
  49. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
  50. package/package.json +3 -3
  51. package/src/__tests__/integration/sticky-header.ts +4 -1
  52. package/src/__tests__/unit/nodeviews/TableContainer.tsx +164 -0
  53. package/src/plugins/table/index.tsx +21 -18
  54. package/src/plugins/table/nodeviews/TableComponent.tsx +21 -78
  55. package/src/plugins/table/nodeviews/TableContainer.tsx +200 -0
  56. package/src/plugins/table/nodeviews/TableResizer.tsx +88 -0
  57. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +3 -72
  58. package/src/plugins/table/pm-plugins/table-resizing/index.ts +0 -1
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/index.ts +6 -2
  60. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +7 -12
  61. package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +79 -0
@@ -232,6 +232,17 @@ var tablesPlugin = function tablesPlugin(options, api) {
232
232
  tableWrapperTarget = _ref10.tableWrapperTarget;
233
233
  var allowControls = pluginConfig.allowControls;
234
234
  var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
235
+ var LayoutContent = getBooleanFF('platform.editor.custom-table-width') ? null : isLayoutSupported(state) && options && options.breakoutEnabled ? /*#__PURE__*/React.createElement(LayoutButton, {
236
+ editorView: editorView,
237
+ mountPoint: popupsMountPoint,
238
+ boundariesElement: popupsBoundariesElement,
239
+ scrollableElement: popupsScrollableElement,
240
+ targetRef: tableWrapperTarget,
241
+ layout: layout,
242
+ isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
243
+ stickyHeader: stickyHeader,
244
+ editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
245
+ }) : null;
235
246
  return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
236
247
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
237
248
  editorView: editorView,
@@ -278,17 +289,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
278
289
  stickyHeaders: stickyHeader,
279
290
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
280
291
  editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
281
- }), isLayoutSupported(state) && options && options.breakoutEnabled && /*#__PURE__*/React.createElement(LayoutButton, {
282
- editorView: editorView,
283
- mountPoint: popupsMountPoint,
284
- boundariesElement: popupsBoundariesElement,
285
- scrollableElement: popupsScrollableElement,
286
- targetRef: tableWrapperTarget,
287
- layout: layout,
288
- isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
289
- stickyHeader: stickyHeader,
290
- editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
291
- }));
292
+ }), LayoutContent);
292
293
  }
293
294
  }));
294
295
  },
@@ -14,17 +14,14 @@ import classnames from 'classnames';
14
14
  import { isTableSelected } from '@atlaskit/editor-tables/utils';
15
15
  import rafSchedule from 'raf-schd';
16
16
  import { findTable } from '@atlaskit/editor-tables/utils';
17
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
18
- import { calcTableWidth, tableMarginSides } from '@atlaskit/editor-common/styles';
17
+ import { tableMarginSides } from '@atlaskit/editor-common/styles';
19
18
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
20
19
  import { akEditorMobileBreakoutPoint, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
21
20
  import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
22
- import { parsePx } from '@atlaskit/editor-common/utils';
23
21
  import { autoSizeTable, clearHoverSelection } from '../commands';
24
22
  import { getPluginState } from '../pm-plugins/plugin-factory';
25
23
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
26
- import { scaleTable } from '../pm-plugins/table-resizing';
27
- import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode } from '../pm-plugins/table-resizing/utils';
24
+ import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scaleTable } from '../pm-plugins/table-resizing/utils';
28
25
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
29
26
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
30
27
  import TableFloatingControls from '../ui/TableFloatingControls';
@@ -32,6 +29,7 @@ import { containsHeaderRow, tablesHaveDifferentColumnWidths, tablesHaveDifferent
32
29
  import { updateOverflowShadows } from './update-overflow-shadows';
33
30
  import memoizeOne from 'memoize-one';
34
31
  import { OverflowShadowsObserver } from './OverflowShadowsObserver';
32
+ import { TableContainer } from './TableContainer';
35
33
  var isIE11 = browser.ie_version === 11;
36
34
  var NOOP = function NOOP() {
37
35
  return undefined;
@@ -46,7 +44,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
46
44
  _this = _super.call(this, props);
47
45
  _defineProperty(_assertThisInitialized(_this), "state", (_defineProperty2 = {
48
46
  scroll: 0,
49
- tableContainerWidth: 'inherit',
50
47
  parentWidth: undefined,
51
48
  isLoading: true
52
49
  }, _defineProperty(_defineProperty2, ShadowEvent.SHOW_BEFORE_SHADOW, false), _defineProperty(_defineProperty2, ShadowEvent.SHOW_AFTER_SHADOW, false), _defineProperty2));
@@ -84,18 +81,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
84
81
  }
85
82
  });
86
83
  _defineProperty(_assertThisInitialized(_this), "prevTableState", null);
87
- _defineProperty(_assertThisInitialized(_this), "getMarginLeft", function (tableContainerCssWidth) {
88
- var containerWidth = _this.props.containerWidth;
89
- var lineLength = containerWidth.lineLength;
90
- var marginLeft;
91
- if (tableContainerCssWidth !== 'inherit' && lineLength) {
92
- var _containerWidth2 = parsePx(tableContainerCssWidth);
93
- if (_containerWidth2) {
94
- marginLeft = (lineLength - _containerWidth2) / 2;
95
- }
96
- }
97
- return marginLeft;
98
- });
99
84
  _defineProperty(_assertThisInitialized(_this), "handleScroll", function (event) {
100
85
  if (!_this.wrapper || event.target !== _this.wrapper) {
101
86
  return;
@@ -152,7 +137,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
152
137
  }
153
138
  _this.updateParentWidth(parentWidth);
154
139
  }
155
- _this.updateTableContainerWidth();
156
140
  _this.node = node;
157
141
  _this.containerWidth = containerWidth;
158
142
  _this.layoutSize = layoutSize;
@@ -174,13 +158,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
174
158
  var domAtPos = view.domAtPos.bind(view);
175
159
  var width = containerWidth.width;
176
160
  _this.scaleTableDebounced.cancel();
177
- scaleTable(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
161
+ var tr = scaleTable(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
178
162
  node: node,
179
163
  prevNode: _this.node || node,
180
164
  start: pos + 1,
181
165
  containerWidth: width,
182
166
  previousContainerWidth: _this.containerWidth.width || width
183
- }, options), domAtPos)(state, dispatch);
167
+ }, options), domAtPos)(state.tr);
168
+ dispatch(tr);
184
169
  });
185
170
  _defineProperty(_assertThisInitialized(_this), "handleAutoSize", function () {
186
171
  if (_this.table) {
@@ -218,36 +203,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
218
203
  parentWidth: parentWidth
219
204
  });
220
205
  });
221
- _defineProperty(_assertThisInitialized(_this), "updateTableContainerWidth", function () {
206
+ _defineProperty(_assertThisInitialized(_this), "getParentNodeWidth", function () {
222
207
  var _this$props5 = _this.props,
223
- getNode = _this$props5.getNode,
208
+ getPos = _this$props5.getPos,
224
209
  containerWidth = _this$props5.containerWidth,
225
- options = _this$props5.options;
226
- var node = getNode();
227
- if (options && options.isBreakoutEnabled === false) {
228
- return;
229
- }
230
- var tableContainerWidth = calcTableWidth(node.attrs.layout, containerWidth.width);
231
- if (_this.state.tableContainerWidth === tableContainerWidth) {
232
- return null;
233
- }
234
- _this.setState(function (prevState) {
235
- if (options && options.isBreakoutEnabled === false && prevState.tableContainerWidth !== 'inherit') {
236
- return {
237
- tableContainerWidth: 'inherit'
238
- };
239
- }
240
- return {
241
- tableContainerWidth: tableContainerWidth
242
- };
243
- });
244
- });
245
- _defineProperty(_assertThisInitialized(_this), "getParentNodeWidth", function () {
246
- var _this$props6 = _this.props,
247
- getPos = _this$props6.getPos,
248
- containerWidth = _this$props6.containerWidth,
249
- options = _this$props6.options,
250
- state = _this$props6.view.state;
210
+ options = _this$props5.options,
211
+ state = _this$props5.view.state;
251
212
  var pos = getPos();
252
213
  if (!isValidPosition(pos, state)) {
253
214
  return;
@@ -305,9 +266,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
305
266
  _createClass(TableComponent, [{
306
267
  key: "componentDidMount",
307
268
  value: function componentDidMount() {
308
- var _this$props7 = this.props,
309
- allowColumnResizing = _this$props7.allowColumnResizing,
310
- eventDispatcher = _this$props7.eventDispatcher;
269
+ var _this$props6 = this.props,
270
+ allowColumnResizing = _this$props6.allowColumnResizing,
271
+ eventDispatcher = _this$props6.eventDispatcher;
311
272
  if (allowColumnResizing && this.wrapper && !isIE11) {
312
273
  this.wrapper.addEventListener('scroll', this.handleScrollDebounced);
313
274
  }
@@ -317,7 +278,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
317
278
  * Instead we use the resize event to only trigger updates when necessary.
318
279
  */
319
280
  window.addEventListener('resize', this.handleWindowResizeDebounced);
320
- this.updateTableContainerWidth();
321
281
  this.handleTableResizingDebounced();
322
282
  }
323
283
  var currentStickyState = stickyHeadersPluginKey.getState(this.props.view.state);
@@ -348,11 +308,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
348
308
  }, {
349
309
  key: "componentDidUpdate",
350
310
  value: function componentDidUpdate(prevProps) {
351
- var _this$props8 = this.props,
352
- view = _this$props8.view,
353
- getNode = _this$props8.getNode,
354
- isMediaFullscreen = _this$props8.isMediaFullscreen,
355
- allowColumnResizing = _this$props8.allowColumnResizing;
311
+ var _this$props7 = this.props,
312
+ view = _this$props7.view,
313
+ getNode = _this$props7.getNode,
314
+ isMediaFullscreen = _this$props7.isMediaFullscreen,
315
+ allowColumnResizing = _this$props7.allowColumnResizing;
356
316
  var _getPluginState = getPluginState(view.state),
357
317
  isInDanger = _getPluginState.isInDanger;
358
318
  var table = findTable(view.state.selection);
@@ -408,20 +368,21 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
408
368
  value: function render() {
409
369
  var _classnames,
410
370
  _this2 = this;
411
- var _this$props9 = this.props,
412
- view = _this$props9.view,
413
- getNode = _this$props9.getNode,
414
- tableResizingPluginState = _this$props9.tableResizingPluginState,
415
- _this$props9$allowCon = _this$props9.allowControls,
416
- allowControls = _this$props9$allowCon === void 0 ? true : _this$props9$allowCon,
417
- isHeaderRowEnabled = _this$props9.isHeaderRowEnabled,
418
- ordering = _this$props9.ordering,
419
- isHeaderColumnEnabled = _this$props9.isHeaderColumnEnabled,
420
- tableActive = _this$props9.tableActive,
421
- containerWidth = _this$props9.containerWidth;
371
+ var _this$props8 = this.props,
372
+ view = _this$props8.view,
373
+ getNode = _this$props8.getNode,
374
+ tableResizingPluginState = _this$props8.tableResizingPluginState,
375
+ _this$props8$allowCon = _this$props8.allowControls,
376
+ allowControls = _this$props8$allowCon === void 0 ? true : _this$props8$allowCon,
377
+ isHeaderRowEnabled = _this$props8.isHeaderRowEnabled,
378
+ ordering = _this$props8.ordering,
379
+ isHeaderColumnEnabled = _this$props8.isHeaderColumnEnabled,
380
+ tableActive = _this$props8.tableActive,
381
+ containerWidth = _this$props8.containerWidth,
382
+ options = _this$props8.options,
383
+ getPos = _this$props8.getPos;
422
384
  var _this$state = this.state,
423
385
  isLoading = _this$state.isLoading,
424
- tableContainerWidth = _this$state.tableContainerWidth,
425
386
  showBeforeShadow = _this$state.showBeforeShadow,
426
387
  showAfterShadow = _this$state.showAfterShadow;
427
388
  var node = getNode();
@@ -469,18 +430,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
469
430
  visibility: visible ? 'visible' : 'hidden'
470
431
  };
471
432
  }) : NOOP;
472
- if (getBooleanFF('platform.editor.custom-table-width')) {
473
- // new table experience code goes here
474
- // return <Resizer>...
475
- }
476
- return /*#__PURE__*/React.createElement("div", {
477
- style: {
478
- width: tableContainerWidth,
479
- marginLeft: this.getMarginLeft(tableContainerWidth)
480
- },
433
+ return /*#__PURE__*/React.createElement(TableContainer, {
481
434
  className: classnames(ClassName.TABLE_CONTAINER, (_classnames = {}, _defineProperty(_classnames, ClassName.WITH_CONTROLS, allowControls && tableActive), _defineProperty(_classnames, ClassName.TABLE_STICKY, this.state.stickyHeader && hasHeaderRow), _defineProperty(_classnames, ClassName.HOVERED_DELETE_BUTTON, isInDanger), _defineProperty(_classnames, ClassName.TABLE_SELECTED, isTableSelected(view.state.selection)), _defineProperty(_classnames, 'less-padding', containerWidth.width < akEditorMobileBreakoutPoint), _classnames)),
482
- "data-number-column": node.attrs.isNumberColumnEnabled,
483
- "data-layout": node.attrs.layout
435
+ editorView: view,
436
+ getPos: getPos,
437
+ node: node,
438
+ tableRef: tableRef,
439
+ containerWidth: containerWidth,
440
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.isFullWidthModeEnabled,
441
+ isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled
484
442
  }, stickyHeadersOptimization && /*#__PURE__*/React.createElement("div", {
485
443
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
486
444
  "data-testid": "sticky-sentinel-top"
@@ -0,0 +1,119 @@
1
+ import React, { useCallback, useRef, forwardRef } from 'react';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
4
+ import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
+ import { TableCssClassName as ClassName } from '../types';
6
+ import { TableResizer } from './TableResizer';
7
+ var getMarginLeft = function getMarginLeft(_ref) {
8
+ var lineLength = _ref.lineLength,
9
+ tableWidth = _ref.tableWidth;
10
+ var marginLeft;
11
+ if (tableWidth !== 'inherit' && lineLength) {
12
+ var containerWidth = tableWidth;
13
+ if (containerWidth) {
14
+ marginLeft = (lineLength - containerWidth) / 2;
15
+ }
16
+ }
17
+ return marginLeft;
18
+ };
19
+ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
20
+ var marginLeft = _ref2.marginLeft,
21
+ className = _ref2.className,
22
+ width = _ref2.width,
23
+ node = _ref2.node,
24
+ children = _ref2.children;
25
+ return /*#__PURE__*/React.createElement("div", {
26
+ ref: ref,
27
+ style: {
28
+ width: width,
29
+ marginLeft: marginLeft
30
+ },
31
+ className: className,
32
+ "data-number-column": node.attrs.isNumberColumnEnabled,
33
+ "data-layout": node.attrs.layout,
34
+ "data-test-id": "table-container"
35
+ }, children);
36
+ });
37
+ export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
38
+ var children = _ref3.children,
39
+ className = _ref3.className,
40
+ node = _ref3.node,
41
+ lineLength = _ref3.lineLength,
42
+ editorView = _ref3.editorView,
43
+ getPos = _ref3.getPos,
44
+ tableRef = _ref3.tableRef;
45
+ var containerRef = useRef(null);
46
+ var innerContainerRef = useRef(null);
47
+ var updateWidth = useCallback(function (width) {
48
+ if (!containerRef.current || !innerContainerRef.current) {
49
+ return;
50
+ }
51
+ innerContainerRef.current.style.width = "".concat(width, "px");
52
+ var marginLeft = getMarginLeft({
53
+ lineLength: lineLength,
54
+ tableWidth: width
55
+ });
56
+ containerRef.current.style.width = "".concat(width, "px");
57
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
58
+ }, [lineLength]);
59
+ var width = getTableContainerWidth(node);
60
+ var marginLeft = getMarginLeft({
61
+ lineLength: lineLength,
62
+ tableWidth: width
63
+ });
64
+ return /*#__PURE__*/React.createElement("div", {
65
+ style: {
66
+ marginLeft: marginLeft,
67
+ width: width
68
+ },
69
+ className: ClassName.TABLE_RESIZER_CONTAINER,
70
+ ref: containerRef
71
+ }, /*#__PURE__*/React.createElement(TableResizer, {
72
+ width: width,
73
+ updateWidth: updateWidth,
74
+ editorView: editorView,
75
+ getPos: getPos,
76
+ node: node,
77
+ tableRef: tableRef
78
+ }, /*#__PURE__*/React.createElement(InnerContainer, {
79
+ ref: innerContainerRef,
80
+ className: className,
81
+ node: node,
82
+ width: width,
83
+ marginLeft: 0
84
+ }, children)));
85
+ };
86
+ export var TableContainer = function TableContainer(_ref4) {
87
+ var children = _ref4.children,
88
+ node = _ref4.node,
89
+ className = _ref4.className,
90
+ _ref4$containerWidth = _ref4.containerWidth,
91
+ lineLength = _ref4$containerWidth.lineLength,
92
+ editorWidth = _ref4$containerWidth.width,
93
+ isFullWidthModeEnabled = _ref4.isFullWidthModeEnabled,
94
+ isBreakoutEnabled = _ref4.isBreakoutEnabled,
95
+ editorView = _ref4.editorView,
96
+ getPos = _ref4.getPos,
97
+ tableRef = _ref4.tableRef;
98
+ if ((isFullWidthModeEnabled || isBreakoutEnabled) && getBooleanFF('platform.editor.custom-table-width')) {
99
+ return /*#__PURE__*/React.createElement(ResizableTableContainer, {
100
+ className: className,
101
+ node: node,
102
+ lineLength: lineLength,
103
+ containerWidth: editorWidth,
104
+ editorView: editorView,
105
+ getPos: getPos,
106
+ tableRef: tableRef
107
+ }, children);
108
+ }
109
+ var tableWidth = isBreakoutEnabled ? calcTableWidth(node.attrs.layout, editorWidth) : 'inherit';
110
+ return /*#__PURE__*/React.createElement(InnerContainer, {
111
+ node: node,
112
+ className: className,
113
+ width: tableWidth,
114
+ marginLeft: getMarginLeft({
115
+ lineLength: lineLength,
116
+ tableWidth: tableWidth
117
+ })
118
+ }, children);
119
+ };
@@ -0,0 +1,57 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
4
+ import React from 'react';
5
+ import rafSchd from 'raf-schd';
6
+ import { ResizerNext } from '@atlaskit/editor-common/resizer';
7
+ import { scaleTable, previewScaleTable } from '../pm-plugins/table-resizing/utils';
8
+ var handles = {
9
+ right: true
10
+ };
11
+ export var TableResizer = function TableResizer(_ref) {
12
+ var children = _ref.children,
13
+ width = _ref.width,
14
+ updateWidth = _ref.updateWidth,
15
+ editorView = _ref.editorView,
16
+ getPos = _ref.getPos,
17
+ node = _ref.node,
18
+ tableRef = _ref.tableRef;
19
+ return /*#__PURE__*/React.createElement(ResizerNext, {
20
+ enable: handles,
21
+ width: width,
22
+ handleResizeStart: function handleResizeStart() {
23
+ return width;
24
+ },
25
+ handleResize: rafSchd(function (originalState, delta) {
26
+ var newWidth = originalState.width + delta.width;
27
+ previewScaleTable(tableRef, {
28
+ node: node,
29
+ prevNode: node,
30
+ start: getPos() + 1,
31
+ parentWidth: newWidth
32
+ }, editorView.domAtPos.bind(editorView));
33
+ updateWidth(newWidth);
34
+ return newWidth;
35
+ }),
36
+ handleResizeStop: function handleResizeStop(originalState, delta) {
37
+ var newWidth = originalState.width + delta.width;
38
+ var state = editorView.state,
39
+ dispatch = editorView.dispatch;
40
+ var pos = getPos();
41
+ var tr = state.tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
42
+ width: newWidth
43
+ }));
44
+ var newNode = tr.doc.nodeAt(pos);
45
+ tr = scaleTable(tableRef, {
46
+ node: newNode,
47
+ prevNode: node,
48
+ start: getPos() + 1,
49
+ parentWidth: newWidth
50
+ }, editorView.domAtPos.bind(editorView))(tr);
51
+ dispatch(tr);
52
+ updateWidth(newWidth);
53
+ return newWidth;
54
+ },
55
+ resizeRatio: 2
56
+ }, children);
57
+ };
@@ -1,51 +1,7 @@
1
1
  import { isTableSelected } from '@atlaskit/editor-tables/utils';
2
- import { updateColumnWidths } from '../../transforms';
3
2
  import { createCommand, getPluginState } from './plugin-factory';
4
- import { evenAllColumnsWidths, hasTableBeenResized, isClickNear, insertColgroupFromNode as recreateResizeColsByNode, scale, scaleWithParent } from './utils';
5
- // Scale the table to meet new requirements (col, layout change etc)
6
- export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
7
- return function (state, dispatch) {
8
- if (!tableRef) {
9
- return false;
10
- }
11
- var node = options.node,
12
- start = options.start,
13
- parentWidth = options.parentWidth,
14
- layoutChanged = options.layoutChanged;
15
-
16
- // If a table has not been resized yet, columns should be auto.
17
- if (hasTableBeenResized(node) === false) {
18
- // If its not a re-sized table, we still want to re-create cols
19
- // To force reflow of columns upon delete.
20
- recreateResizeColsByNode(tableRef, node);
21
- return false;
22
- }
23
- var resizeState;
24
- if (parentWidth) {
25
- resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
26
- } else {
27
- resizeState = scale(tableRef, options, domAtPos);
28
- }
29
- if (resizeState) {
30
- var _tr = state.tr;
31
- _tr = updateColumnWidths(resizeState, node, start)(_tr);
32
- if (_tr.docChanged && dispatch) {
33
- _tr.setMeta('scrollIntoView', false);
34
- // TODO: ED-8995
35
- // We need to do this check to reduce the number of race conditions when working with tables.
36
- // This metadata is been used in the sendTransaction function in the Collab plugin
37
- /* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
38
- scaleTable is only called once every time a breakout button is clicked, so it is safe not to add the meta 'scaleTable' to the tr.
39
- Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
40
- */
41
- !layoutChanged && _tr.setMeta('scaleTable', true);
42
- dispatch(_tr);
43
- return true;
44
- }
45
- }
46
- return false;
47
- };
48
- };
3
+ import { evenAllColumnsWidths, isClickNear } from './utils';
4
+ import { updateColumnWidths } from '../../transforms';
49
5
  export var evenColumns = function evenColumns(_ref) {
50
6
  var resizeState = _ref.resizeState,
51
7
  table = _ref.table,
@@ -79,8 +35,8 @@ export var evenColumns = function evenColumns(_ref) {
79
35
  export var distributeColumnsWidths = function distributeColumnsWidths(newResizeState, table) {
80
36
  return function (state, dispatch) {
81
37
  if (dispatch) {
82
- var _tr2 = updateColumnWidths(newResizeState, table.node, table.start)(state.tr);
83
- stopResizing(_tr2)(state, dispatch);
38
+ var _tr = updateColumnWidths(newResizeState, table.node, table.start)(state.tr);
39
+ stopResizing(_tr)(state, dispatch);
84
40
  }
85
41
  return true;
86
42
  };
@@ -1,4 +1,3 @@
1
1
  export { createPlugin } from './plugin';
2
- export { scaleTable } from './commands';
3
2
  export { pluginKey } from './plugin-key';
4
3
  export { getPluginState } from './plugin-factory';
@@ -3,7 +3,7 @@ export { contentWidth } from './content-width';
3
3
  export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateColumnWidth, addContainerLeftRightPadding } from './column-state';
4
4
  export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
5
5
  export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths } from './resize-state';
6
- export { tableLayoutToSize, getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround } from './misc';
6
+ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround } from './misc';
7
7
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
8
- export { scale, scaleWithParent } from './scale-table';
8
+ export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
9
9
  export { resizeColumn } from './resize-column';
@@ -1,13 +1,8 @@
1
1
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
2
2
  import { getBreakpoint, mapBreakpointToLayoutMaxWidth } from '@atlaskit/editor-common/ui';
3
- import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorWideLayoutWidth, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
3
+ import { akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
4
4
  import { containsClassName } from '@atlaskit/editor-common/utils';
5
- import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
6
- export var tableLayoutToSize = {
7
- default: akEditorDefaultLayoutWidth,
8
- wide: akEditorWideLayoutWidth,
9
- 'full-width': akEditorFullWidthLayoutWidth
10
- };
5
+ import { getParentNodeWidth, layoutToWidth } from '@atlaskit/editor-common/node-width';
11
6
 
12
7
  // Translates named layouts in number values.
13
8
  export function getLayoutSize(tableLayout) {
@@ -18,10 +13,10 @@ export function getLayoutSize(tableLayout) {
18
13
  return containerWidth ? Math.min(containerWidth - akEditorGutterPadding * 2, akEditorFullWidthLayoutWidth) : akEditorFullWidthLayoutWidth;
19
14
  }
20
15
  var calculatedTableWidth = calcTableWidth(tableLayout, containerWidth, true);
21
- if (calculatedTableWidth.endsWith('px')) {
22
- return parseInt(calculatedTableWidth, 10);
16
+ if (calculatedTableWidth !== 'inherit') {
17
+ return calculatedTableWidth;
23
18
  }
24
- return tableLayoutToSize[tableLayout] || containerWidth;
19
+ return layoutToWidth[tableLayout] || containerWidth;
25
20
  }
26
21
  export function getDefaultLayoutMaxWidth(containerWidth) {
27
22
  return mapBreakpointToLayoutMaxWidth(getBreakpoint(containerWidth));
@@ -6,7 +6,9 @@ import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
6
6
  import { getTableWidth } from '../../../utils';
7
7
  import { getLayoutSize } from '../utils/misc';
8
8
  import { reduceSpace } from '../utils/resize-logic';
9
- import { adjustColumnsWidths, getResizeState, getTotalWidth } from '../utils/resize-state';
9
+ import { adjustColumnsWidths, getResizeState, getTotalWidth, updateColgroup } from '../utils/resize-state';
10
+ import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
11
+ import { updateColumnWidths } from '../../../transforms';
10
12
  // Base function to trigger the actual scale on a table node.
11
13
  // Will only resize/scale if a table has been previously resized.
12
14
  export var scale = function scale(tableRef, options, domAtPos) {
@@ -94,4 +96,59 @@ export function scaleTableTo(state, maxSize) {
94
96
  newState = reduceSpace(newState, newTotalWidth - maxSize);
95
97
  }
96
98
  return adjustColumnsWidths(newState, maxSize);
97
- }
99
+ }
100
+ export var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos) {
101
+ var node = options.node,
102
+ start = options.start,
103
+ parentWidth = options.parentWidth;
104
+ if (!tableRef || !hasTableBeenResized(node)) {
105
+ return;
106
+ }
107
+ var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
108
+ if (resizeState) {
109
+ updateColgroup(resizeState, tableRef);
110
+ }
111
+ };
112
+
113
+ // Scale the table to meet new requirements (col, layout change etc)
114
+ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
115
+ return function (tr) {
116
+ if (!tableRef) {
117
+ return tr;
118
+ }
119
+ var node = options.node,
120
+ start = options.start,
121
+ parentWidth = options.parentWidth,
122
+ layoutChanged = options.layoutChanged;
123
+
124
+ // If a table has not been resized yet, columns should be auto.
125
+ if (hasTableBeenResized(node) === false) {
126
+ // If its not a re-sized table, we still want to re-create cols
127
+ // To force reflow of columns upon delete.
128
+ insertColgroupFromNode(tableRef, node);
129
+ return tr;
130
+ }
131
+ var resizeState;
132
+ if (parentWidth) {
133
+ resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
134
+ } else {
135
+ resizeState = scale(tableRef, options, domAtPos);
136
+ }
137
+ if (resizeState) {
138
+ tr = updateColumnWidths(resizeState, node, start)(tr);
139
+ if (tr.docChanged) {
140
+ tr.setMeta('scrollIntoView', false);
141
+ // TODO: ED-8995
142
+ // We need to do this check to reduce the number of race conditions when working with tables.
143
+ // This metadata is been used in the sendTransaction function in the Collab plugin
144
+ /* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
145
+ scaleTable is only called once every time a breakout button is clicked, so it is safe not to add the meta 'scaleTable' to the tr.
146
+ Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
147
+ */
148
+ !layoutChanged && tr.setMeta('scaleTable', true);
149
+ return tr;
150
+ }
151
+ }
152
+ return tr;
153
+ };
154
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.5.5",
3
+ "version": "1.6.0",
4
4
  "sideEffects": false
5
5
  }
@@ -28,7 +28,6 @@ export interface ComponentProps {
28
28
  }
29
29
  interface TableState {
30
30
  scroll: number;
31
- tableContainerWidth: string;
32
31
  parentWidth?: number;
33
32
  isLoading: boolean;
34
33
  stickyHeader?: RowStickyState;
@@ -54,13 +53,11 @@ declare class TableComponent extends React.Component<ComponentProps, TableState>
54
53
  onStickyState: (state: StickyPluginState) => void;
55
54
  prevTableState: any;
56
55
  render(): JSX.Element;
57
- private getMarginLeft;
58
56
  private handleScroll;
59
57
  private handleTableResizing;
60
58
  private scaleTable;
61
59
  private handleAutoSize;
62
60
  private handleWindowResize;
63
- private updateTableContainerWidth;
64
61
  private getParentNodeWidth;
65
62
  private updateParentWidth;
66
63
  private tableNodeLayoutSize;