@atlaskit/editor-plugin-table 2.0.0 → 2.1.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 (50) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +7 -3
  3. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +23 -19
  4. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +2 -1
  5. package/dist/cjs/plugins/table/nodeviews/table.js +5 -1
  6. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +7 -3
  9. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +22 -18
  10. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +3 -2
  11. package/dist/es2019/plugins/table/nodeviews/table.js +5 -1
  12. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/esm/plugins/table/nodeviews/TableComponent.js +7 -3
  15. package/dist/esm/plugins/table/nodeviews/TableContainer.js +23 -19
  16. package/dist/esm/plugins/table/nodeviews/TableResizer.js +3 -2
  17. package/dist/esm/plugins/table/nodeviews/table.js +5 -1
  18. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
  19. package/dist/esm/version.json +1 -1
  20. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +5 -3
  21. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +2 -1
  22. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +5 -3
  23. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +2 -1
  24. package/package.json +4 -7
  25. package/src/__tests__/integration/layout.ts +1 -6
  26. package/src/__tests__/unit/analytics.ts +0 -21
  27. package/src/__tests__/unit/commands/misc.ts +0 -2
  28. package/src/__tests__/unit/commands/sort.ts +0 -131
  29. package/src/__tests__/unit/commands.ts +2 -264
  30. package/src/__tests__/unit/copy-paste.ts +1 -36
  31. package/src/__tests__/unit/event-handlers.ts +1 -113
  32. package/src/__tests__/unit/get-toolbar-config.ts +0 -29
  33. package/src/__tests__/unit/index.ts +3 -101
  34. package/src/__tests__/unit/layout.ts +1 -64
  35. package/src/__tests__/unit/nodeviews/cell.ts +1 -48
  36. package/src/__tests__/unit/pm-plugins/main.ts +1 -3
  37. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +2 -20
  38. package/src/__tests__/unit/sort-column.ts +21 -148
  39. package/src/__tests__/unit/utils/collapse.ts +3 -39
  40. package/src/plugins/table/nodeviews/TableComponent.tsx +10 -4
  41. package/src/plugins/table/nodeviews/TableContainer.tsx +28 -19
  42. package/src/plugins/table/nodeviews/TableResizer.tsx +3 -2
  43. package/src/plugins/table/nodeviews/table.tsx +6 -0
  44. package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +10 -1
  45. package/.eslintrc.js +0 -37
  46. package/src/__tests__/unit/color-picker.ts +0 -110
  47. package/src/__tests__/unit/floating-toolbar.ts +0 -95
  48. package/src/__tests__/unit/keymap.ts +0 -609
  49. package/src/__tests__/unit/pm-plugins/main-with-allow-collapse.ts +0 -110
  50. package/src/__tests__/unit/pm-plugins/table-selection-keymap.ts +0 -574
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`48ebe1fa732`](https://bitbucket.org/atlassian/atlassian-frontend/commits/48ebe1fa732) - [ED-18895] Moved table integration tests to dedicated editor plugin test package to avoid circular dependencies
8
+
9
+ ## 2.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`802453ec412`](https://bitbucket.org/atlassian/atlassian-frontend/commits/802453ec412) - [ux] update how table respond to external width changes under `platform.editor.custom-table-width` feature flag
14
+ - Updated dependencies
15
+
3
16
  ## 2.0.0
4
17
 
5
18
  ### Major Changes
@@ -284,7 +284,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
284
284
  * We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
285
285
  * Instead we use the resize event to only trigger updates when necessary.
286
286
  */
287
- window.addEventListener('resize', this.handleWindowResizeDebounced);
287
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
288
+ window.addEventListener('resize', this.handleWindowResizeDebounced);
289
+ }
288
290
  this.handleTableResizingDebounced();
289
291
  }
290
292
  var currentStickyState = _stickyHeaders.pluginKey.getState(this.props.view.state);
@@ -303,8 +305,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
303
305
  this.scaleTableDebounced.cancel();
304
306
  this.handleTableResizingDebounced.cancel();
305
307
  this.handleAutoSizeDebounced.cancel();
306
- this.handleWindowResizeDebounced.cancel();
307
- if (this.props.allowColumnResizing) {
308
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
309
+ this.handleWindowResizeDebounced.cancel();
310
+ }
311
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && this.props.allowColumnResizing) {
308
312
  window.removeEventListener('resize', this.handleWindowResizeDebounced);
309
313
  }
310
314
  if (this.overflowShadowsObserver) {
@@ -11,6 +11,7 @@ var _nodeWidth = require("@atlaskit/editor-common/node-width");
11
11
  var _styles = require("@atlaskit/editor-common/styles");
12
12
  var _types = require("../types");
13
13
  var _TableResizer = require("./TableResizer");
14
+ var _utils = require("../pm-plugins/table-resizing/utils");
14
15
  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
16
  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
17
  var getMarginLeft = function getMarginLeft(_ref) {
@@ -26,17 +27,13 @@ var getMarginLeft = function getMarginLeft(_ref) {
26
27
  return marginLeft;
27
28
  };
28
29
  var InnerContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
29
- var marginLeft = _ref2.marginLeft,
30
- className = _ref2.className,
31
- width = _ref2.width,
30
+ var className = _ref2.className,
31
+ style = _ref2.style,
32
32
  node = _ref2.node,
33
33
  children = _ref2.children;
34
34
  return /*#__PURE__*/_react.default.createElement("div", {
35
35
  ref: ref,
36
- style: {
37
- width: width,
38
- marginLeft: marginLeft
39
- },
36
+ style: style,
40
37
  className: className,
41
38
  "data-number-column": node.attrs.isNumberColumnEnabled,
42
39
  "data-layout": node.attrs.layout,
@@ -49,6 +46,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
49
46
  className = _ref3.className,
50
47
  node = _ref3.node,
51
48
  lineLength = _ref3.lineLength,
49
+ containerWidth = _ref3.containerWidth,
52
50
  editorView = _ref3.editorView,
53
51
  getPos = _ref3.getPos,
54
52
  tableRef = _ref3.tableRef;
@@ -58,19 +56,24 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
58
56
  if (!containerRef.current || !innerContainerRef.current) {
59
57
  return;
60
58
  }
61
- innerContainerRef.current.style.width = "".concat(width, "px");
62
59
  var marginLeft = getMarginLeft({
63
60
  lineLength: lineLength,
64
61
  tableWidth: width
65
62
  });
66
- containerRef.current.style.width = "".concat(width, "px");
67
- containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
63
+ if (marginLeft) {
64
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
65
+ }
68
66
  }, [lineLength]);
69
- var width = (0, _nodeWidth.getTableContainerWidth)(node);
67
+ var tableWidth = (0, _nodeWidth.getTableContainerWidth)(node);
68
+
69
+ // 76 is currently an accepted padding value considering the spacing for resizer handle
70
+ var responsiveContainerWidth = containerWidth - 76;
71
+ var width = Math.min(tableWidth, responsiveContainerWidth);
70
72
  var marginLeft = getMarginLeft({
71
73
  lineLength: lineLength,
72
74
  tableWidth: width
73
75
  });
76
+ var maxResizerWidth = Math.min(responsiveContainerWidth, _utils.TABLE_MAX_WIDTH);
74
77
  return /*#__PURE__*/_react.default.createElement("div", {
75
78
  style: {
76
79
  marginLeft: marginLeft,
@@ -80,6 +83,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
80
83
  ref: containerRef
81
84
  }, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, {
82
85
  width: width,
86
+ maxWidth: maxResizerWidth,
83
87
  updateWidth: updateWidth,
84
88
  editorView: editorView,
85
89
  getPos: getPos,
@@ -88,9 +92,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
88
92
  }, /*#__PURE__*/_react.default.createElement(InnerContainer, {
89
93
  ref: innerContainerRef,
90
94
  className: className,
91
- node: node,
92
- width: width,
93
- marginLeft: 0
95
+ node: node
94
96
  }, children)));
95
97
  };
96
98
  exports.ResizableTableContainer = ResizableTableContainer;
@@ -121,11 +123,13 @@ var TableContainer = function TableContainer(_ref4) {
121
123
  return /*#__PURE__*/_react.default.createElement(InnerContainer, {
122
124
  node: node,
123
125
  className: className,
124
- width: tableWidth,
125
- marginLeft: getMarginLeft({
126
- lineLength: lineLength,
127
- tableWidth: tableWidth
128
- })
126
+ style: {
127
+ width: tableWidth,
128
+ marginLeft: getMarginLeft({
129
+ lineLength: lineLength,
130
+ tableWidth: tableWidth
131
+ })
132
+ }
129
133
  }, children);
130
134
  };
131
135
  exports.TableContainer = TableContainer;
@@ -18,6 +18,7 @@ var handles = {
18
18
  var TableResizer = function TableResizer(_ref) {
19
19
  var children = _ref.children,
20
20
  width = _ref.width,
21
+ maxWidth = _ref.maxWidth,
21
22
  updateWidth = _ref.updateWidth,
22
23
  editorView = _ref.editorView,
23
24
  getPos = _ref.getPos,
@@ -70,7 +71,7 @@ var TableResizer = function TableResizer(_ref) {
70
71
  },
71
72
  resizeRatio: 2,
72
73
  minWidth: minColumnWidth,
73
- maxWidth: _utils.TABLE_MAX_WIDTH
74
+ maxWidth: maxWidth
74
75
  }, children);
75
76
  };
76
77
  exports.TableResizer = TableResizer;
@@ -26,15 +26,19 @@ var _tableResizing = require("../pm-plugins/table-resizing");
26
26
  var _utils = require("../pm-plugins/table-resizing/utils");
27
27
  var _tableMap = require("@atlaskit/editor-tables/table-map");
28
28
  var _TableComponent = _interopRequireDefault(require("./TableComponent"));
29
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
30
+ var _nodeWidth = require("@atlaskit/editor-common/node-width");
29
31
  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); }; }
30
32
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
31
33
  var tableAttributes = function tableAttributes(node) {
34
+ var style = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? "width: ".concat((0, _nodeWidth.getTableContainerWidth)(node), "px") : undefined;
32
35
  return {
33
36
  'data-number-column': node.attrs.isNumberColumnEnabled,
34
37
  'data-layout': node.attrs.layout,
35
38
  'data-autosize': node.attrs.__autoSize,
36
39
  'data-table-local-id': node.attrs.localId || '',
37
- 'data-table-width': node.attrs.width
40
+ 'data-table-width': node.attrs.width,
41
+ style: style
38
42
  };
39
43
  };
40
44
  var toDOM = function toDOM(node, props) {
@@ -10,6 +10,7 @@ exports.scaleWithParent = void 0;
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
  var _styles = require("@atlaskit/editor-common/styles");
12
12
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
14
  var _utils = require("../../../utils");
14
15
  var _misc = require("../utils/misc");
15
16
  var _resizeLogic = require("../utils/resize-logic");
@@ -112,7 +113,13 @@ var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos)
112
113
  var node = options.node,
113
114
  start = options.start,
114
115
  parentWidth = options.parentWidth;
115
- if (!tableRef || !(0, _colgroup.hasTableBeenResized)(node)) {
116
+ if (!tableRef) {
117
+ return;
118
+ }
119
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && parentWidth) {
120
+ tableRef.style.width = "".concat(parentWidth, "px");
121
+ }
122
+ if (!(0, _colgroup.hasTableBeenResized)(node)) {
116
123
  return;
117
124
  }
118
125
  var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -281,7 +281,9 @@ class TableComponent extends React.Component {
281
281
  * We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
282
282
  * Instead we use the resize event to only trigger updates when necessary.
283
283
  */
284
- window.addEventListener('resize', this.handleWindowResizeDebounced);
284
+ if (!getBooleanFF('platform.editor.custom-table-width')) {
285
+ window.addEventListener('resize', this.handleWindowResizeDebounced);
286
+ }
285
287
  this.handleTableResizingDebounced();
286
288
  }
287
289
  const currentStickyState = stickyHeadersPluginKey.getState(this.props.view.state);
@@ -298,8 +300,10 @@ class TableComponent extends React.Component {
298
300
  this.scaleTableDebounced.cancel();
299
301
  this.handleTableResizingDebounced.cancel();
300
302
  this.handleAutoSizeDebounced.cancel();
301
- this.handleWindowResizeDebounced.cancel();
302
- if (this.props.allowColumnResizing) {
303
+ if (!getBooleanFF('platform.editor.custom-table-width')) {
304
+ this.handleWindowResizeDebounced.cancel();
305
+ }
306
+ if (!getBooleanFF('platform.editor.custom-table-width') && this.props.allowColumnResizing) {
303
307
  window.removeEventListener('resize', this.handleWindowResizeDebounced);
304
308
  }
305
309
  if (this.overflowShadowsObserver) {
@@ -4,6 +4,7 @@ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
4
4
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
5
  import { TableCssClassName as ClassName } from '../types';
6
6
  import { TableResizer } from './TableResizer';
7
+ import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
7
8
  const getMarginLeft = ({
8
9
  lineLength,
9
10
  tableWidth
@@ -18,18 +19,14 @@ const getMarginLeft = ({
18
19
  return marginLeft;
19
20
  };
20
21
  export const InnerContainer = /*#__PURE__*/forwardRef(({
21
- marginLeft,
22
22
  className,
23
- width,
23
+ style,
24
24
  node,
25
25
  children
26
26
  }, ref) => {
27
27
  return /*#__PURE__*/React.createElement("div", {
28
28
  ref: ref,
29
- style: {
30
- width,
31
- marginLeft
32
- },
29
+ style: style,
33
30
  className: className,
34
31
  "data-number-column": node.attrs.isNumberColumnEnabled,
35
32
  "data-layout": node.attrs.layout,
@@ -41,6 +38,7 @@ export const ResizableTableContainer = ({
41
38
  className,
42
39
  node,
43
40
  lineLength,
41
+ containerWidth,
44
42
  editorView,
45
43
  getPos,
46
44
  tableRef
@@ -51,19 +49,24 @@ export const ResizableTableContainer = ({
51
49
  if (!containerRef.current || !innerContainerRef.current) {
52
50
  return;
53
51
  }
54
- innerContainerRef.current.style.width = `${width}px`;
55
52
  const marginLeft = getMarginLeft({
56
53
  lineLength,
57
54
  tableWidth: width
58
55
  });
59
- containerRef.current.style.width = `${width}px`;
60
- containerRef.current.style.marginLeft = `${marginLeft}px`;
56
+ if (marginLeft) {
57
+ containerRef.current.style.marginLeft = `${marginLeft}px`;
58
+ }
61
59
  }, [lineLength]);
62
- const width = getTableContainerWidth(node);
60
+ const tableWidth = getTableContainerWidth(node);
61
+
62
+ // 76 is currently an accepted padding value considering the spacing for resizer handle
63
+ const responsiveContainerWidth = containerWidth - 76;
64
+ const width = Math.min(tableWidth, responsiveContainerWidth);
63
65
  const marginLeft = getMarginLeft({
64
66
  lineLength,
65
67
  tableWidth: width
66
68
  });
69
+ const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
67
70
  return /*#__PURE__*/React.createElement("div", {
68
71
  style: {
69
72
  marginLeft,
@@ -73,6 +76,7 @@ export const ResizableTableContainer = ({
73
76
  ref: containerRef
74
77
  }, /*#__PURE__*/React.createElement(TableResizer, {
75
78
  width: width,
79
+ maxWidth: maxResizerWidth,
76
80
  updateWidth: updateWidth,
77
81
  editorView: editorView,
78
82
  getPos: getPos,
@@ -81,9 +85,7 @@ export const ResizableTableContainer = ({
81
85
  }, /*#__PURE__*/React.createElement(InnerContainer, {
82
86
  ref: innerContainerRef,
83
87
  className: className,
84
- node: node,
85
- width: width,
86
- marginLeft: 0
88
+ node: node
87
89
  }, children)));
88
90
  };
89
91
  export const TableContainer = ({
@@ -115,10 +117,12 @@ export const TableContainer = ({
115
117
  return /*#__PURE__*/React.createElement(InnerContainer, {
116
118
  node: node,
117
119
  className: className,
118
- width: tableWidth,
119
- marginLeft: getMarginLeft({
120
- lineLength: lineLength,
121
- tableWidth
122
- })
120
+ style: {
121
+ width: tableWidth,
122
+ marginLeft: getMarginLeft({
123
+ lineLength: lineLength,
124
+ tableWidth
125
+ })
126
+ }
123
127
  }, children);
124
128
  };
@@ -1,13 +1,14 @@
1
1
  import React from 'react';
2
2
  import rafSchd from 'raf-schd';
3
3
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
4
- import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
4
+ import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH } from '../pm-plugins/table-resizing/utils';
5
5
  const handles = {
6
6
  right: true
7
7
  };
8
8
  export const TableResizer = ({
9
9
  children,
10
10
  width,
11
+ maxWidth,
11
12
  updateWidth,
12
13
  editorView,
13
14
  getPos,
@@ -62,6 +63,6 @@ export const TableResizer = ({
62
63
  },
63
64
  resizeRatio: 2,
64
65
  minWidth: minColumnWidth,
65
- maxWidth: TABLE_MAX_WIDTH
66
+ maxWidth: maxWidth
66
67
  }, children);
67
68
  };
@@ -10,13 +10,17 @@ import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizin
10
10
  import { generateColgroup } from '../pm-plugins/table-resizing/utils';
11
11
  import { TableMap } from '@atlaskit/editor-tables/table-map';
12
12
  import TableComponent from './TableComponent';
13
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
13
15
  const tableAttributes = node => {
16
+ const style = getBooleanFF('platform.editor.custom-table-width') ? `width: ${getTableContainerWidth(node)}px` : undefined;
14
17
  return {
15
18
  'data-number-column': node.attrs.isNumberColumnEnabled,
16
19
  'data-layout': node.attrs.layout,
17
20
  'data-autosize': node.attrs.__autoSize,
18
21
  'data-table-local-id': node.attrs.localId || '',
19
- 'data-table-width': node.attrs.width
22
+ 'data-table-width': node.attrs.width,
23
+ style
20
24
  };
21
25
  };
22
26
  const toDOM = (node, props) => {
@@ -1,5 +1,6 @@
1
1
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
2
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { getTableWidth } from '../../../utils';
4
5
  import { getLayoutSize } from '../utils/misc';
5
6
  import { reduceSpace } from '../utils/resize-logic';
@@ -106,7 +107,13 @@ export const previewScaleTable = (tableRef, options, domAtPos) => {
106
107
  start,
107
108
  parentWidth
108
109
  } = options;
109
- if (!tableRef || !hasTableBeenResized(node)) {
110
+ if (!tableRef) {
111
+ return;
112
+ }
113
+ if (getBooleanFF('platform.editor.custom-table-width') && parentWidth) {
114
+ tableRef.style.width = `${parentWidth}px`;
115
+ }
116
+ if (!hasTableBeenResized(node)) {
110
117
  return;
111
118
  }
112
119
  const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -278,7 +278,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
278
278
  * We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
279
279
  * Instead we use the resize event to only trigger updates when necessary.
280
280
  */
281
- window.addEventListener('resize', this.handleWindowResizeDebounced);
281
+ if (!getBooleanFF('platform.editor.custom-table-width')) {
282
+ window.addEventListener('resize', this.handleWindowResizeDebounced);
283
+ }
282
284
  this.handleTableResizingDebounced();
283
285
  }
284
286
  var currentStickyState = stickyHeadersPluginKey.getState(this.props.view.state);
@@ -297,8 +299,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
297
299
  this.scaleTableDebounced.cancel();
298
300
  this.handleTableResizingDebounced.cancel();
299
301
  this.handleAutoSizeDebounced.cancel();
300
- this.handleWindowResizeDebounced.cancel();
301
- if (this.props.allowColumnResizing) {
302
+ if (!getBooleanFF('platform.editor.custom-table-width')) {
303
+ this.handleWindowResizeDebounced.cancel();
304
+ }
305
+ if (!getBooleanFF('platform.editor.custom-table-width') && this.props.allowColumnResizing) {
302
306
  window.removeEventListener('resize', this.handleWindowResizeDebounced);
303
307
  }
304
308
  if (this.overflowShadowsObserver) {
@@ -4,6 +4,7 @@ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
4
4
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
5
  import { TableCssClassName as ClassName } from '../types';
6
6
  import { TableResizer } from './TableResizer';
7
+ import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
7
8
  var getMarginLeft = function getMarginLeft(_ref) {
8
9
  var lineLength = _ref.lineLength,
9
10
  tableWidth = _ref.tableWidth;
@@ -17,17 +18,13 @@ var getMarginLeft = function getMarginLeft(_ref) {
17
18
  return marginLeft;
18
19
  };
19
20
  export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
20
- var marginLeft = _ref2.marginLeft,
21
- className = _ref2.className,
22
- width = _ref2.width,
21
+ var className = _ref2.className,
22
+ style = _ref2.style,
23
23
  node = _ref2.node,
24
24
  children = _ref2.children;
25
25
  return /*#__PURE__*/React.createElement("div", {
26
26
  ref: ref,
27
- style: {
28
- width: width,
29
- marginLeft: marginLeft
30
- },
27
+ style: style,
31
28
  className: className,
32
29
  "data-number-column": node.attrs.isNumberColumnEnabled,
33
30
  "data-layout": node.attrs.layout,
@@ -39,6 +36,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
39
36
  className = _ref3.className,
40
37
  node = _ref3.node,
41
38
  lineLength = _ref3.lineLength,
39
+ containerWidth = _ref3.containerWidth,
42
40
  editorView = _ref3.editorView,
43
41
  getPos = _ref3.getPos,
44
42
  tableRef = _ref3.tableRef;
@@ -48,19 +46,24 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
48
46
  if (!containerRef.current || !innerContainerRef.current) {
49
47
  return;
50
48
  }
51
- innerContainerRef.current.style.width = "".concat(width, "px");
52
49
  var marginLeft = getMarginLeft({
53
50
  lineLength: lineLength,
54
51
  tableWidth: width
55
52
  });
56
- containerRef.current.style.width = "".concat(width, "px");
57
- containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
53
+ if (marginLeft) {
54
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
55
+ }
58
56
  }, [lineLength]);
59
- var width = getTableContainerWidth(node);
57
+ var tableWidth = getTableContainerWidth(node);
58
+
59
+ // 76 is currently an accepted padding value considering the spacing for resizer handle
60
+ var responsiveContainerWidth = containerWidth - 76;
61
+ var width = Math.min(tableWidth, responsiveContainerWidth);
60
62
  var marginLeft = getMarginLeft({
61
63
  lineLength: lineLength,
62
64
  tableWidth: width
63
65
  });
66
+ var maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
64
67
  return /*#__PURE__*/React.createElement("div", {
65
68
  style: {
66
69
  marginLeft: marginLeft,
@@ -70,6 +73,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
70
73
  ref: containerRef
71
74
  }, /*#__PURE__*/React.createElement(TableResizer, {
72
75
  width: width,
76
+ maxWidth: maxResizerWidth,
73
77
  updateWidth: updateWidth,
74
78
  editorView: editorView,
75
79
  getPos: getPos,
@@ -78,9 +82,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
78
82
  }, /*#__PURE__*/React.createElement(InnerContainer, {
79
83
  ref: innerContainerRef,
80
84
  className: className,
81
- node: node,
82
- width: width,
83
- marginLeft: 0
85
+ node: node
84
86
  }, children)));
85
87
  };
86
88
  export var TableContainer = function TableContainer(_ref4) {
@@ -110,10 +112,12 @@ export var TableContainer = function TableContainer(_ref4) {
110
112
  return /*#__PURE__*/React.createElement(InnerContainer, {
111
113
  node: node,
112
114
  className: className,
113
- width: tableWidth,
114
- marginLeft: getMarginLeft({
115
- lineLength: lineLength,
116
- tableWidth: tableWidth
117
- })
115
+ style: {
116
+ width: tableWidth,
117
+ marginLeft: getMarginLeft({
118
+ lineLength: lineLength,
119
+ tableWidth: tableWidth
120
+ })
121
+ }
118
122
  }, children);
119
123
  };
@@ -4,13 +4,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
  import React from 'react';
5
5
  import rafSchd from 'raf-schd';
6
6
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
7
- import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
7
+ import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH } from '../pm-plugins/table-resizing/utils';
8
8
  var handles = {
9
9
  right: true
10
10
  };
11
11
  export var TableResizer = function TableResizer(_ref) {
12
12
  var children = _ref.children,
13
13
  width = _ref.width,
14
+ maxWidth = _ref.maxWidth,
14
15
  updateWidth = _ref.updateWidth,
15
16
  editorView = _ref.editorView,
16
17
  getPos = _ref.getPos,
@@ -63,6 +64,6 @@ export var TableResizer = function TableResizer(_ref) {
63
64
  },
64
65
  resizeRatio: 2,
65
66
  minWidth: minColumnWidth,
66
- maxWidth: TABLE_MAX_WIDTH
67
+ maxWidth: maxWidth
67
68
  }, children);
68
69
  };
@@ -21,13 +21,17 @@ import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizin
21
21
  import { generateColgroup } from '../pm-plugins/table-resizing/utils';
22
22
  import { TableMap } from '@atlaskit/editor-tables/table-map';
23
23
  import TableComponent from './TableComponent';
24
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
25
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
24
26
  var tableAttributes = function tableAttributes(node) {
27
+ var style = getBooleanFF('platform.editor.custom-table-width') ? "width: ".concat(getTableContainerWidth(node), "px") : undefined;
25
28
  return {
26
29
  'data-number-column': node.attrs.isNumberColumnEnabled,
27
30
  'data-layout': node.attrs.layout,
28
31
  'data-autosize': node.attrs.__autoSize,
29
32
  'data-table-local-id': node.attrs.localId || '',
30
- 'data-table-width': node.attrs.width
33
+ 'data-table-width': node.attrs.width,
34
+ style: style
31
35
  };
32
36
  };
33
37
  var toDOM = function toDOM(node, props) {
@@ -3,6 +3,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
3
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
4
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
5
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
7
  import { getTableWidth } from '../../../utils';
7
8
  import { getLayoutSize } from '../utils/misc';
8
9
  import { reduceSpace } from '../utils/resize-logic';
@@ -101,7 +102,13 @@ export var previewScaleTable = function previewScaleTable(tableRef, options, dom
101
102
  var node = options.node,
102
103
  start = options.start,
103
104
  parentWidth = options.parentWidth;
104
- if (!tableRef || !hasTableBeenResized(node)) {
105
+ if (!tableRef) {
106
+ return;
107
+ }
108
+ if (getBooleanFF('platform.editor.custom-table-width') && parentWidth) {
109
+ tableRef.style.width = "".concat(parentWidth, "px");
110
+ }
111
+ if (!hasTableBeenResized(node)) {
105
112
  return;
106
113
  }
107
114
  var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -4,8 +4,10 @@ import { EditorView } from 'prosemirror-view';
4
4
  import { EditorContainerWidth } from '@atlaskit/editor-common/types';
5
5
  type InnerContainerProps = {
6
6
  className: string;
7
- marginLeft: number | undefined;
8
- width: number | 'inherit';
7
+ style?: {
8
+ width: number | 'inherit';
9
+ marginLeft: number | undefined;
10
+ };
9
11
  node: PMNode;
10
12
  };
11
13
  export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContainerProps & {
@@ -20,7 +22,7 @@ type ResizableTableContainerProps = {
20
22
  getPos: () => number | undefined;
21
23
  tableRef: HTMLTableElement;
22
24
  };
23
- export declare const ResizableTableContainer: ({ children, className, node, lineLength, editorView, getPos, tableRef, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
25
+ export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
24
26
  type TableContainerProps = {
25
27
  node: PMNode;
26
28
  className: string;