@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`89989e06f43`](https://bitbucket.org/atlassian/atlassian-frontend/commits/89989e06f43) - [ux] Adding initial Resizer to table plugin behind a platform feature flag, allowing tables to resize to a custom width. This change also includes the following refactors:- change calcTableWidth function to return number instead of px- allowing tables to use breakout values when allowColumnResize is disabled
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 1.5.5
4
14
 
5
15
  ### Patch Changes
@@ -239,6 +239,17 @@ var tablesPlugin = function tablesPlugin(options, api) {
239
239
  tableWrapperTarget = _ref10.tableWrapperTarget;
240
240
  var allowControls = pluginConfig.allowControls;
241
241
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
242
+ var LayoutContent = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? null : (0, _utils3.isLayoutSupported)(state) && options && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
243
+ editorView: editorView,
244
+ mountPoint: popupsMountPoint,
245
+ boundariesElement: popupsBoundariesElement,
246
+ scrollableElement: popupsScrollableElement,
247
+ targetRef: tableWrapperTarget,
248
+ layout: layout,
249
+ isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
250
+ stickyHeader: stickyHeader,
251
+ editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
252
+ }) : null;
242
253
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/_react.default.createElement(_FloatingContextualButton.default, {
243
254
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
244
255
  editorView: editorView,
@@ -285,17 +296,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
285
296
  stickyHeaders: stickyHeader,
286
297
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
287
298
  editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
288
- }), (0, _utils3.isLayoutSupported)(state) && options && options.breakoutEnabled && /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
289
- editorView: editorView,
290
- mountPoint: popupsMountPoint,
291
- boundariesElement: popupsBoundariesElement,
292
- scrollableElement: popupsScrollableElement,
293
- targetRef: tableWrapperTarget,
294
- layout: layout,
295
- isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
296
- stickyHeader: stickyHeader,
297
- editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
298
- }));
299
+ }), LayoutContent);
299
300
  }
300
301
  }));
301
302
  },
@@ -16,7 +16,6 @@ var _react = _interopRequireDefault(require("react"));
16
16
  var _classnames2 = _interopRequireDefault(require("classnames"));
17
17
  var _utils = require("@atlaskit/editor-tables/utils");
18
18
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
19
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
19
  var _styles = require("@atlaskit/editor-common/styles");
21
20
  var _utils2 = require("@atlaskit/editor-common/utils");
22
21
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
@@ -24,7 +23,6 @@ var _nodeWidth = require("@atlaskit/editor-common/node-width");
24
23
  var _commands = require("../commands");
25
24
  var _pluginFactory = require("../pm-plugins/plugin-factory");
26
25
  var _stickyHeaders = require("../pm-plugins/sticky-headers");
27
- var _tableResizing = require("../pm-plugins/table-resizing");
28
26
  var _utils3 = require("../pm-plugins/table-resizing/utils");
29
27
  var _dom = require("../pm-plugins/table-resizing/utils/dom");
30
28
  var _types = require("../types");
@@ -33,6 +31,7 @@ var _utils4 = require("../utils");
33
31
  var _updateOverflowShadows = require("./update-overflow-shadows");
34
32
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
35
33
  var _OverflowShadowsObserver = require("./OverflowShadowsObserver");
34
+ var _TableContainer = require("./TableContainer");
36
35
  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; }
37
36
  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, _defineProperty3.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; }
38
37
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
@@ -51,7 +50,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
51
50
  _this = _super.call(this, props);
52
51
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "state", (_defineProperty2 = {
53
52
  scroll: 0,
54
- tableContainerWidth: 'inherit',
55
53
  parentWidth: undefined,
56
54
  isLoading: true
57
55
  }, (0, _defineProperty3.default)(_defineProperty2, _types.ShadowEvent.SHOW_BEFORE_SHADOW, false), (0, _defineProperty3.default)(_defineProperty2, _types.ShadowEvent.SHOW_AFTER_SHADOW, false), _defineProperty2));
@@ -89,18 +87,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
89
87
  }
90
88
  });
91
89
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "prevTableState", null);
92
- (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "getMarginLeft", function (tableContainerCssWidth) {
93
- var containerWidth = _this.props.containerWidth;
94
- var lineLength = containerWidth.lineLength;
95
- var marginLeft;
96
- if (tableContainerCssWidth !== 'inherit' && lineLength) {
97
- var _containerWidth2 = (0, _utils2.parsePx)(tableContainerCssWidth);
98
- if (_containerWidth2) {
99
- marginLeft = (lineLength - _containerWidth2) / 2;
100
- }
101
- }
102
- return marginLeft;
103
- });
104
90
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "handleScroll", function (event) {
105
91
  if (!_this.wrapper || event.target !== _this.wrapper) {
106
92
  return;
@@ -157,7 +143,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
157
143
  }
158
144
  _this.updateParentWidth(parentWidth);
159
145
  }
160
- _this.updateTableContainerWidth();
161
146
  _this.node = node;
162
147
  _this.containerWidth = containerWidth;
163
148
  _this.layoutSize = layoutSize;
@@ -179,13 +164,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
179
164
  var domAtPos = view.domAtPos.bind(view);
180
165
  var width = containerWidth.width;
181
166
  _this.scaleTableDebounced.cancel();
182
- (0, _tableResizing.scaleTable)(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
167
+ var tr = (0, _utils3.scaleTable)(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
183
168
  node: node,
184
169
  prevNode: _this.node || node,
185
170
  start: pos + 1,
186
171
  containerWidth: width,
187
172
  previousContainerWidth: _this.containerWidth.width || width
188
- }, options), domAtPos)(state, dispatch);
173
+ }, options), domAtPos)(state.tr);
174
+ dispatch(tr);
189
175
  });
190
176
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "handleAutoSize", function () {
191
177
  if (_this.table) {
@@ -223,36 +209,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
223
209
  parentWidth: parentWidth
224
210
  });
225
211
  });
226
- (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "updateTableContainerWidth", function () {
212
+ (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "getParentNodeWidth", function () {
227
213
  var _this$props5 = _this.props,
228
- getNode = _this$props5.getNode,
214
+ getPos = _this$props5.getPos,
229
215
  containerWidth = _this$props5.containerWidth,
230
- options = _this$props5.options;
231
- var node = getNode();
232
- if (options && options.isBreakoutEnabled === false) {
233
- return;
234
- }
235
- var tableContainerWidth = (0, _styles.calcTableWidth)(node.attrs.layout, containerWidth.width);
236
- if (_this.state.tableContainerWidth === tableContainerWidth) {
237
- return null;
238
- }
239
- _this.setState(function (prevState) {
240
- if (options && options.isBreakoutEnabled === false && prevState.tableContainerWidth !== 'inherit') {
241
- return {
242
- tableContainerWidth: 'inherit'
243
- };
244
- }
245
- return {
246
- tableContainerWidth: tableContainerWidth
247
- };
248
- });
249
- });
250
- (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "getParentNodeWidth", function () {
251
- var _this$props6 = _this.props,
252
- getPos = _this$props6.getPos,
253
- containerWidth = _this$props6.containerWidth,
254
- options = _this$props6.options,
255
- state = _this$props6.view.state;
216
+ options = _this$props5.options,
217
+ state = _this$props5.view.state;
256
218
  var pos = getPos();
257
219
  if (!(0, _utils2.isValidPosition)(pos, state)) {
258
220
  return;
@@ -310,9 +272,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
310
272
  (0, _createClass2.default)(TableComponent, [{
311
273
  key: "componentDidMount",
312
274
  value: function componentDidMount() {
313
- var _this$props7 = this.props,
314
- allowColumnResizing = _this$props7.allowColumnResizing,
315
- eventDispatcher = _this$props7.eventDispatcher;
275
+ var _this$props6 = this.props,
276
+ allowColumnResizing = _this$props6.allowColumnResizing,
277
+ eventDispatcher = _this$props6.eventDispatcher;
316
278
  if (allowColumnResizing && this.wrapper && !isIE11) {
317
279
  this.wrapper.addEventListener('scroll', this.handleScrollDebounced);
318
280
  }
@@ -322,7 +284,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
322
284
  * Instead we use the resize event to only trigger updates when necessary.
323
285
  */
324
286
  window.addEventListener('resize', this.handleWindowResizeDebounced);
325
- this.updateTableContainerWidth();
326
287
  this.handleTableResizingDebounced();
327
288
  }
328
289
  var currentStickyState = _stickyHeaders.pluginKey.getState(this.props.view.state);
@@ -353,11 +314,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
353
314
  }, {
354
315
  key: "componentDidUpdate",
355
316
  value: function componentDidUpdate(prevProps) {
356
- var _this$props8 = this.props,
357
- view = _this$props8.view,
358
- getNode = _this$props8.getNode,
359
- isMediaFullscreen = _this$props8.isMediaFullscreen,
360
- allowColumnResizing = _this$props8.allowColumnResizing;
317
+ var _this$props7 = this.props,
318
+ view = _this$props7.view,
319
+ getNode = _this$props7.getNode,
320
+ isMediaFullscreen = _this$props7.isMediaFullscreen,
321
+ allowColumnResizing = _this$props7.allowColumnResizing;
361
322
  var _getPluginState = (0, _pluginFactory.getPluginState)(view.state),
362
323
  isInDanger = _getPluginState.isInDanger;
363
324
  var table = (0, _utils.findTable)(view.state.selection);
@@ -413,20 +374,21 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
413
374
  value: function render() {
414
375
  var _classnames,
415
376
  _this2 = this;
416
- var _this$props9 = this.props,
417
- view = _this$props9.view,
418
- getNode = _this$props9.getNode,
419
- tableResizingPluginState = _this$props9.tableResizingPluginState,
420
- _this$props9$allowCon = _this$props9.allowControls,
421
- allowControls = _this$props9$allowCon === void 0 ? true : _this$props9$allowCon,
422
- isHeaderRowEnabled = _this$props9.isHeaderRowEnabled,
423
- ordering = _this$props9.ordering,
424
- isHeaderColumnEnabled = _this$props9.isHeaderColumnEnabled,
425
- tableActive = _this$props9.tableActive,
426
- containerWidth = _this$props9.containerWidth;
377
+ var _this$props8 = this.props,
378
+ view = _this$props8.view,
379
+ getNode = _this$props8.getNode,
380
+ tableResizingPluginState = _this$props8.tableResizingPluginState,
381
+ _this$props8$allowCon = _this$props8.allowControls,
382
+ allowControls = _this$props8$allowCon === void 0 ? true : _this$props8$allowCon,
383
+ isHeaderRowEnabled = _this$props8.isHeaderRowEnabled,
384
+ ordering = _this$props8.ordering,
385
+ isHeaderColumnEnabled = _this$props8.isHeaderColumnEnabled,
386
+ tableActive = _this$props8.tableActive,
387
+ containerWidth = _this$props8.containerWidth,
388
+ options = _this$props8.options,
389
+ getPos = _this$props8.getPos;
427
390
  var _this$state = this.state,
428
391
  isLoading = _this$state.isLoading,
429
- tableContainerWidth = _this$state.tableContainerWidth,
430
392
  showBeforeShadow = _this$state.showBeforeShadow,
431
393
  showAfterShadow = _this$state.showAfterShadow;
432
394
  var node = getNode();
@@ -474,18 +436,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
474
436
  visibility: visible ? 'visible' : 'hidden'
475
437
  };
476
438
  }) : NOOP;
477
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
478
- // new table experience code goes here
479
- // return <Resizer>...
480
- }
481
- return /*#__PURE__*/_react.default.createElement("div", {
482
- style: {
483
- width: tableContainerWidth,
484
- marginLeft: this.getMarginLeft(tableContainerWidth)
485
- },
439
+ return /*#__PURE__*/_react.default.createElement(_TableContainer.TableContainer, {
486
440
  className: (0, _classnames2.default)(_types.TableCssClassName.TABLE_CONTAINER, (_classnames = {}, (0, _defineProperty3.default)(_classnames, _types.TableCssClassName.WITH_CONTROLS, allowControls && tableActive), (0, _defineProperty3.default)(_classnames, _types.TableCssClassName.TABLE_STICKY, this.state.stickyHeader && hasHeaderRow), (0, _defineProperty3.default)(_classnames, _types.TableCssClassName.HOVERED_DELETE_BUTTON, isInDanger), (0, _defineProperty3.default)(_classnames, _types.TableCssClassName.TABLE_SELECTED, (0, _utils.isTableSelected)(view.state.selection)), (0, _defineProperty3.default)(_classnames, 'less-padding', containerWidth.width < _editorSharedStyles.akEditorMobileBreakoutPoint), _classnames)),
487
- "data-number-column": node.attrs.isNumberColumnEnabled,
488
- "data-layout": node.attrs.layout
441
+ editorView: view,
442
+ getPos: getPos,
443
+ node: node,
444
+ tableRef: tableRef,
445
+ containerWidth: containerWidth,
446
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.isFullWidthModeEnabled,
447
+ isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled
489
448
  }, stickyHeadersOptimization && /*#__PURE__*/_react.default.createElement("div", {
490
449
  className: _types.TableCssClassName.TABLE_STICKY_SENTINEL_TOP,
491
450
  "data-testid": "sticky-sentinel-top"
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TableContainer = exports.ResizableTableContainer = exports.InnerContainer = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _nodeWidth = require("@atlaskit/editor-common/node-width");
11
+ var _styles = require("@atlaskit/editor-common/styles");
12
+ var _types = require("../types");
13
+ var _TableResizer = require("./TableResizer");
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
+ var getMarginLeft = function getMarginLeft(_ref) {
17
+ var lineLength = _ref.lineLength,
18
+ tableWidth = _ref.tableWidth;
19
+ var marginLeft;
20
+ if (tableWidth !== 'inherit' && lineLength) {
21
+ var containerWidth = tableWidth;
22
+ if (containerWidth) {
23
+ marginLeft = (lineLength - containerWidth) / 2;
24
+ }
25
+ }
26
+ return marginLeft;
27
+ };
28
+ var InnerContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
29
+ var marginLeft = _ref2.marginLeft,
30
+ className = _ref2.className,
31
+ width = _ref2.width,
32
+ node = _ref2.node,
33
+ children = _ref2.children;
34
+ return /*#__PURE__*/_react.default.createElement("div", {
35
+ ref: ref,
36
+ style: {
37
+ width: width,
38
+ marginLeft: marginLeft
39
+ },
40
+ className: className,
41
+ "data-number-column": node.attrs.isNumberColumnEnabled,
42
+ "data-layout": node.attrs.layout,
43
+ "data-test-id": "table-container"
44
+ }, children);
45
+ });
46
+ exports.InnerContainer = InnerContainer;
47
+ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
48
+ var children = _ref3.children,
49
+ className = _ref3.className,
50
+ node = _ref3.node,
51
+ lineLength = _ref3.lineLength,
52
+ editorView = _ref3.editorView,
53
+ getPos = _ref3.getPos,
54
+ tableRef = _ref3.tableRef;
55
+ var containerRef = (0, _react.useRef)(null);
56
+ var innerContainerRef = (0, _react.useRef)(null);
57
+ var updateWidth = (0, _react.useCallback)(function (width) {
58
+ if (!containerRef.current || !innerContainerRef.current) {
59
+ return;
60
+ }
61
+ innerContainerRef.current.style.width = "".concat(width, "px");
62
+ var marginLeft = getMarginLeft({
63
+ lineLength: lineLength,
64
+ tableWidth: width
65
+ });
66
+ containerRef.current.style.width = "".concat(width, "px");
67
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
68
+ }, [lineLength]);
69
+ var width = (0, _nodeWidth.getTableContainerWidth)(node);
70
+ var marginLeft = getMarginLeft({
71
+ lineLength: lineLength,
72
+ tableWidth: width
73
+ });
74
+ return /*#__PURE__*/_react.default.createElement("div", {
75
+ style: {
76
+ marginLeft: marginLeft,
77
+ width: width
78
+ },
79
+ className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
80
+ ref: containerRef
81
+ }, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, {
82
+ width: width,
83
+ updateWidth: updateWidth,
84
+ editorView: editorView,
85
+ getPos: getPos,
86
+ node: node,
87
+ tableRef: tableRef
88
+ }, /*#__PURE__*/_react.default.createElement(InnerContainer, {
89
+ ref: innerContainerRef,
90
+ className: className,
91
+ node: node,
92
+ width: width,
93
+ marginLeft: 0
94
+ }, children)));
95
+ };
96
+ exports.ResizableTableContainer = ResizableTableContainer;
97
+ var TableContainer = function TableContainer(_ref4) {
98
+ var children = _ref4.children,
99
+ node = _ref4.node,
100
+ className = _ref4.className,
101
+ _ref4$containerWidth = _ref4.containerWidth,
102
+ lineLength = _ref4$containerWidth.lineLength,
103
+ editorWidth = _ref4$containerWidth.width,
104
+ isFullWidthModeEnabled = _ref4.isFullWidthModeEnabled,
105
+ isBreakoutEnabled = _ref4.isBreakoutEnabled,
106
+ editorView = _ref4.editorView,
107
+ getPos = _ref4.getPos,
108
+ tableRef = _ref4.tableRef;
109
+ if ((isFullWidthModeEnabled || isBreakoutEnabled) && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
110
+ return /*#__PURE__*/_react.default.createElement(ResizableTableContainer, {
111
+ className: className,
112
+ node: node,
113
+ lineLength: lineLength,
114
+ containerWidth: editorWidth,
115
+ editorView: editorView,
116
+ getPos: getPos,
117
+ tableRef: tableRef
118
+ }, children);
119
+ }
120
+ var tableWidth = isBreakoutEnabled ? (0, _styles.calcTableWidth)(node.attrs.layout, editorWidth) : 'inherit';
121
+ return /*#__PURE__*/_react.default.createElement(InnerContainer, {
122
+ node: node,
123
+ className: className,
124
+ width: tableWidth,
125
+ marginLeft: getMarginLeft({
126
+ lineLength: lineLength,
127
+ tableWidth: tableWidth
128
+ })
129
+ }, children);
130
+ };
131
+ exports.TableContainer = TableContainer;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TableResizer = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
11
+ var _resizer = require("@atlaskit/editor-common/resizer");
12
+ var _utils = require("../pm-plugins/table-resizing/utils");
13
+ 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; }
14
+ 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; }
15
+ var handles = {
16
+ right: true
17
+ };
18
+ var TableResizer = function TableResizer(_ref) {
19
+ var children = _ref.children,
20
+ width = _ref.width,
21
+ updateWidth = _ref.updateWidth,
22
+ editorView = _ref.editorView,
23
+ getPos = _ref.getPos,
24
+ node = _ref.node,
25
+ tableRef = _ref.tableRef;
26
+ return /*#__PURE__*/_react.default.createElement(_resizer.ResizerNext, {
27
+ enable: handles,
28
+ width: width,
29
+ handleResizeStart: function handleResizeStart() {
30
+ return width;
31
+ },
32
+ handleResize: (0, _rafSchd.default)(function (originalState, delta) {
33
+ var newWidth = originalState.width + delta.width;
34
+ (0, _utils.previewScaleTable)(tableRef, {
35
+ node: node,
36
+ prevNode: node,
37
+ start: getPos() + 1,
38
+ parentWidth: newWidth
39
+ }, editorView.domAtPos.bind(editorView));
40
+ updateWidth(newWidth);
41
+ return newWidth;
42
+ }),
43
+ handleResizeStop: function handleResizeStop(originalState, delta) {
44
+ var newWidth = originalState.width + delta.width;
45
+ var state = editorView.state,
46
+ dispatch = editorView.dispatch;
47
+ var pos = getPos();
48
+ var tr = state.tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
49
+ width: newWidth
50
+ }));
51
+ var newNode = tr.doc.nodeAt(pos);
52
+ tr = (0, _utils.scaleTable)(tableRef, {
53
+ node: newNode,
54
+ prevNode: node,
55
+ start: getPos() + 1,
56
+ parentWidth: newWidth
57
+ }, editorView.domAtPos.bind(editorView))(tr);
58
+ dispatch(tr);
59
+ updateWidth(newWidth);
60
+ return newWidth;
61
+ },
62
+ resizeRatio: 2
63
+ }, children);
64
+ };
65
+ exports.TableResizer = TableResizer;
@@ -3,56 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stopResizing = exports.setResizeHandlePos = exports.setLastClick = exports.setDragging = exports.scaleTable = exports.evenColumns = exports.distributeColumnsWidths = void 0;
6
+ exports.stopResizing = exports.setResizeHandlePos = exports.setLastClick = exports.setDragging = exports.evenColumns = exports.distributeColumnsWidths = void 0;
7
7
  var _utils = require("@atlaskit/editor-tables/utils");
8
- var _transforms = require("../../transforms");
9
8
  var _pluginFactory = require("./plugin-factory");
10
9
  var _utils2 = require("./utils");
11
- // Scale the table to meet new requirements (col, layout change etc)
12
- var scaleTable = function scaleTable(tableRef, options, domAtPos) {
13
- return function (state, dispatch) {
14
- if (!tableRef) {
15
- return false;
16
- }
17
- var node = options.node,
18
- start = options.start,
19
- parentWidth = options.parentWidth,
20
- layoutChanged = options.layoutChanged;
21
-
22
- // If a table has not been resized yet, columns should be auto.
23
- if ((0, _utils2.hasTableBeenResized)(node) === false) {
24
- // If its not a re-sized table, we still want to re-create cols
25
- // To force reflow of columns upon delete.
26
- (0, _utils2.insertColgroupFromNode)(tableRef, node);
27
- return false;
28
- }
29
- var resizeState;
30
- if (parentWidth) {
31
- resizeState = (0, _utils2.scaleWithParent)(tableRef, parentWidth, node, start, domAtPos);
32
- } else {
33
- resizeState = (0, _utils2.scale)(tableRef, options, domAtPos);
34
- }
35
- if (resizeState) {
36
- var _tr = state.tr;
37
- _tr = (0, _transforms.updateColumnWidths)(resizeState, node, start)(_tr);
38
- if (_tr.docChanged && dispatch) {
39
- _tr.setMeta('scrollIntoView', false);
40
- // TODO: ED-8995
41
- // We need to do this check to reduce the number of race conditions when working with tables.
42
- // This metadata is been used in the sendTransaction function in the Collab plugin
43
- /* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
44
- 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.
45
- Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
46
- */
47
- !layoutChanged && _tr.setMeta('scaleTable', true);
48
- dispatch(_tr);
49
- return true;
50
- }
51
- }
52
- return false;
53
- };
54
- };
55
- exports.scaleTable = scaleTable;
10
+ var _transforms = require("../../transforms");
56
11
  var evenColumns = function evenColumns(_ref) {
57
12
  var resizeState = _ref.resizeState,
58
13
  table = _ref.table,
@@ -87,8 +42,8 @@ exports.evenColumns = evenColumns;
87
42
  var distributeColumnsWidths = function distributeColumnsWidths(newResizeState, table) {
88
43
  return function (state, dispatch) {
89
44
  if (dispatch) {
90
- var _tr2 = (0, _transforms.updateColumnWidths)(newResizeState, table.node, table.start)(state.tr);
91
- stopResizing(_tr2)(state, dispatch);
45
+ var _tr = (0, _transforms.updateColumnWidths)(newResizeState, table.node, table.start)(state.tr);
46
+ stopResizing(_tr)(state, dispatch);
92
47
  }
93
48
  return true;
94
49
  };
@@ -21,13 +21,6 @@ Object.defineProperty(exports, "pluginKey", {
21
21
  return _pluginKey.pluginKey;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "scaleTable", {
25
- enumerable: true,
26
- get: function get() {
27
- return _commands.scaleTable;
28
- }
29
- });
30
24
  var _plugin = require("./plugin");
31
- var _commands = require("./commands");
32
25
  var _pluginKey = require("./plugin-key");
33
26
  var _pluginFactory = require("./plugin-factory");
@@ -141,6 +141,12 @@ Object.defineProperty(exports, "pointsAtCell", {
141
141
  return _misc.pointsAtCell;
142
142
  }
143
143
  });
144
+ Object.defineProperty(exports, "previewScaleTable", {
145
+ enumerable: true,
146
+ get: function get() {
147
+ return _scaleTable.previewScaleTable;
148
+ }
149
+ });
144
150
  Object.defineProperty(exports, "reduceSpace", {
145
151
  enumerable: true,
146
152
  get: function get() {
@@ -159,22 +165,22 @@ Object.defineProperty(exports, "scale", {
159
165
  return _scaleTable.scale;
160
166
  }
161
167
  });
162
- Object.defineProperty(exports, "scaleWithParent", {
168
+ Object.defineProperty(exports, "scaleTable", {
163
169
  enumerable: true,
164
170
  get: function get() {
165
- return _scaleTable.scaleWithParent;
171
+ return _scaleTable.scaleTable;
166
172
  }
167
173
  });
168
- Object.defineProperty(exports, "shrinkColumn", {
174
+ Object.defineProperty(exports, "scaleWithParent", {
169
175
  enumerable: true,
170
176
  get: function get() {
171
- return _resizeLogic.shrinkColumn;
177
+ return _scaleTable.scaleWithParent;
172
178
  }
173
179
  });
174
- Object.defineProperty(exports, "tableLayoutToSize", {
180
+ Object.defineProperty(exports, "shrinkColumn", {
175
181
  enumerable: true,
176
182
  get: function get() {
177
- return _misc.tableLayoutToSize;
183
+ return _resizeLogic.shrinkColumn;
178
184
  }
179
185
  });
180
186
  Object.defineProperty(exports, "updateColgroup", {
@@ -9,20 +9,12 @@ exports.getDefaultLayoutMaxWidth = getDefaultLayoutMaxWidth;
9
9
  exports.getLayoutSize = getLayoutSize;
10
10
  exports.getTableMaxWidth = void 0;
11
11
  exports.pointsAtCell = pointsAtCell;
12
- exports.tableLayoutToSize = void 0;
13
12
  var _styles = require("@atlaskit/editor-common/styles");
14
13
  var _ui = require("@atlaskit/editor-common/ui");
15
14
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
15
  var _utils = require("@atlaskit/editor-common/utils");
17
16
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
18
- var tableLayoutToSize = {
19
- default: _editorSharedStyles.akEditorDefaultLayoutWidth,
20
- wide: _editorSharedStyles.akEditorWideLayoutWidth,
21
- 'full-width': _editorSharedStyles.akEditorFullWidthLayoutWidth
22
- };
23
-
24
17
  // Translates named layouts in number values.
25
- exports.tableLayoutToSize = tableLayoutToSize;
26
18
  function getLayoutSize(tableLayout) {
27
19
  var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
28
20
  var options = arguments.length > 2 ? arguments[2] : undefined;
@@ -31,10 +23,10 @@ function getLayoutSize(tableLayout) {
31
23
  return containerWidth ? Math.min(containerWidth - _editorSharedStyles.akEditorGutterPadding * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth) : _editorSharedStyles.akEditorFullWidthLayoutWidth;
32
24
  }
33
25
  var calculatedTableWidth = (0, _styles.calcTableWidth)(tableLayout, containerWidth, true);
34
- if (calculatedTableWidth.endsWith('px')) {
35
- return parseInt(calculatedTableWidth, 10);
26
+ if (calculatedTableWidth !== 'inherit') {
27
+ return calculatedTableWidth;
36
28
  }
37
- return tableLayoutToSize[tableLayout] || containerWidth;
29
+ return _nodeWidth.layoutToWidth[tableLayout] || containerWidth;
38
30
  }
39
31
  function getDefaultLayoutMaxWidth(containerWidth) {
40
32
  return (0, _ui.mapBreakpointToLayoutMaxWidth)((0, _ui.getBreakpoint)(containerWidth));