@atlaskit/editor-plugin-table 1.5.4 → 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 +16 -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 +5 -5
  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
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.scale = void 0;
7
+ exports.scaleTable = exports.scale = exports.previewScaleTable = void 0;
8
8
  exports.scaleTableTo = scaleTableTo;
9
9
  exports.scaleWithParent = void 0;
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -14,6 +14,8 @@ var _utils = require("../../../utils");
14
14
  var _misc = require("../utils/misc");
15
15
  var _resizeLogic = require("../utils/resize-logic");
16
16
  var _resizeState = require("../utils/resize-state");
17
+ var _colgroup = require("./colgroup");
18
+ var _transforms = require("../../../transforms");
17
19
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
21
  // Base function to trigger the actual scale on a table node.
@@ -105,4 +107,61 @@ function scaleTableTo(state, maxSize) {
105
107
  newState = (0, _resizeLogic.reduceSpace)(newState, newTotalWidth - maxSize);
106
108
  }
107
109
  return (0, _resizeState.adjustColumnsWidths)(newState, maxSize);
108
- }
110
+ }
111
+ var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos) {
112
+ var node = options.node,
113
+ start = options.start,
114
+ parentWidth = options.parentWidth;
115
+ if (!tableRef || !(0, _colgroup.hasTableBeenResized)(node)) {
116
+ return;
117
+ }
118
+ var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
119
+ if (resizeState) {
120
+ (0, _resizeState.updateColgroup)(resizeState, tableRef);
121
+ }
122
+ };
123
+
124
+ // Scale the table to meet new requirements (col, layout change etc)
125
+ exports.previewScaleTable = previewScaleTable;
126
+ var scaleTable = function scaleTable(tableRef, options, domAtPos) {
127
+ return function (tr) {
128
+ if (!tableRef) {
129
+ return tr;
130
+ }
131
+ var node = options.node,
132
+ start = options.start,
133
+ parentWidth = options.parentWidth,
134
+ layoutChanged = options.layoutChanged;
135
+
136
+ // If a table has not been resized yet, columns should be auto.
137
+ if ((0, _colgroup.hasTableBeenResized)(node) === false) {
138
+ // If its not a re-sized table, we still want to re-create cols
139
+ // To force reflow of columns upon delete.
140
+ (0, _colgroup.insertColgroupFromNode)(tableRef, node);
141
+ return tr;
142
+ }
143
+ var resizeState;
144
+ if (parentWidth) {
145
+ resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
146
+ } else {
147
+ resizeState = scale(tableRef, options, domAtPos);
148
+ }
149
+ if (resizeState) {
150
+ tr = (0, _transforms.updateColumnWidths)(resizeState, node, start)(tr);
151
+ if (tr.docChanged) {
152
+ tr.setMeta('scrollIntoView', false);
153
+ // TODO: ED-8995
154
+ // We need to do this check to reduce the number of race conditions when working with tables.
155
+ // This metadata is been used in the sendTransaction function in the Collab plugin
156
+ /* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
157
+ 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.
158
+ Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
159
+ */
160
+ !layoutChanged && tr.setMeta('scaleTable', true);
161
+ return tr;
162
+ }
163
+ }
164
+ return tr;
165
+ };
166
+ };
167
+ exports.scaleTable = scaleTable;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.5.4",
3
+ "version": "1.6.0",
4
4
  "sideEffects": false
5
5
  }
@@ -229,6 +229,17 @@ const tablesPlugin = (options, api) => {
229
229
  allowControls
230
230
  } = pluginConfig;
231
231
  const stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
232
+ const LayoutContent = getBooleanFF('platform.editor.custom-table-width') ? null : isLayoutSupported(state) && options && options.breakoutEnabled ? /*#__PURE__*/React.createElement(LayoutButton, {
233
+ editorView: editorView,
234
+ mountPoint: popupsMountPoint,
235
+ boundariesElement: popupsBoundariesElement,
236
+ scrollableElement: popupsScrollableElement,
237
+ targetRef: tableWrapperTarget,
238
+ layout: layout,
239
+ isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
240
+ stickyHeader: stickyHeader,
241
+ editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
242
+ }) : null;
232
243
  return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
233
244
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
234
245
  editorView: editorView,
@@ -275,17 +286,7 @@ const tablesPlugin = (options, api) => {
275
286
  stickyHeaders: stickyHeader,
276
287
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
277
288
  editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
278
- }), isLayoutSupported(state) && options && options.breakoutEnabled && /*#__PURE__*/React.createElement(LayoutButton, {
279
- editorView: editorView,
280
- mountPoint: popupsMountPoint,
281
- boundariesElement: popupsBoundariesElement,
282
- scrollableElement: popupsScrollableElement,
283
- targetRef: tableWrapperTarget,
284
- layout: layout,
285
- isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
286
- stickyHeader: stickyHeader,
287
- editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI
288
- }));
289
+ }), LayoutContent);
289
290
  }
290
291
  }));
291
292
  },
@@ -4,17 +4,14 @@ import classnames from 'classnames';
4
4
  import { isTableSelected } from '@atlaskit/editor-tables/utils';
5
5
  import rafSchedule from 'raf-schd';
6
6
  import { findTable } from '@atlaskit/editor-tables/utils';
7
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
- import { calcTableWidth, tableMarginSides } from '@atlaskit/editor-common/styles';
7
+ import { tableMarginSides } from '@atlaskit/editor-common/styles';
9
8
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
10
9
  import { akEditorMobileBreakoutPoint, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
11
10
  import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
12
- import { parsePx } from '@atlaskit/editor-common/utils';
13
11
  import { autoSizeTable, clearHoverSelection } from '../commands';
14
12
  import { getPluginState } from '../pm-plugins/plugin-factory';
15
13
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
16
- import { scaleTable } from '../pm-plugins/table-resizing';
17
- import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode } from '../pm-plugins/table-resizing/utils';
14
+ import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scaleTable } from '../pm-plugins/table-resizing/utils';
18
15
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
19
16
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
20
17
  import TableFloatingControls from '../ui/TableFloatingControls';
@@ -22,6 +19,7 @@ import { containsHeaderRow, tablesHaveDifferentColumnWidths, tablesHaveDifferent
22
19
  import { updateOverflowShadows } from './update-overflow-shadows';
23
20
  import memoizeOne from 'memoize-one';
24
21
  import { OverflowShadowsObserver } from './OverflowShadowsObserver';
22
+ import { TableContainer } from './TableContainer';
25
23
  const isIE11 = browser.ie_version === 11;
26
24
  const NOOP = () => undefined;
27
25
  class TableComponent extends React.Component {
@@ -29,7 +27,6 @@ class TableComponent extends React.Component {
29
27
  super(props);
30
28
  _defineProperty(this, "state", {
31
29
  scroll: 0,
32
- tableContainerWidth: 'inherit',
33
30
  parentWidth: undefined,
34
31
  isLoading: true,
35
32
  [ShadowEvent.SHOW_BEFORE_SHADOW]: false,
@@ -72,22 +69,6 @@ class TableComponent extends React.Component {
72
69
  }
73
70
  });
74
71
  _defineProperty(this, "prevTableState", null);
75
- _defineProperty(this, "getMarginLeft", tableContainerCssWidth => {
76
- const {
77
- containerWidth
78
- } = this.props;
79
- const {
80
- lineLength
81
- } = containerWidth;
82
- let marginLeft;
83
- if (tableContainerCssWidth !== 'inherit' && lineLength) {
84
- const containerWidth = parsePx(tableContainerCssWidth);
85
- if (containerWidth) {
86
- marginLeft = (lineLength - containerWidth) / 2;
87
- }
88
- }
89
- return marginLeft;
90
- });
91
72
  _defineProperty(this, "handleScroll", event => {
92
73
  if (!this.wrapper || event.target !== this.wrapper) {
93
74
  return;
@@ -148,7 +129,6 @@ class TableComponent extends React.Component {
148
129
  }
149
130
  this.updateParentWidth(parentWidth);
150
131
  }
151
- this.updateTableContainerWidth();
152
132
  this.node = node;
153
133
  this.containerWidth = containerWidth;
154
134
  this.layoutSize = layoutSize;
@@ -175,7 +155,7 @@ class TableComponent extends React.Component {
175
155
  width
176
156
  } = containerWidth;
177
157
  this.scaleTableDebounced.cancel();
178
- scaleTable(this.table, {
158
+ const tr = scaleTable(this.table, {
179
159
  ...scaleOptions,
180
160
  node,
181
161
  prevNode: this.node || node,
@@ -183,7 +163,8 @@ class TableComponent extends React.Component {
183
163
  containerWidth: width,
184
164
  previousContainerWidth: this.containerWidth.width || width,
185
165
  ...options
186
- }, domAtPos)(state, dispatch);
166
+ }, domAtPos)(state.tr);
167
+ dispatch(tr);
187
168
  });
188
169
  _defineProperty(this, "handleAutoSize", () => {
189
170
  if (this.table) {
@@ -223,31 +204,6 @@ class TableComponent extends React.Component {
223
204
  parentWidth: parentWidth
224
205
  });
225
206
  });
226
- _defineProperty(this, "updateTableContainerWidth", () => {
227
- const {
228
- getNode,
229
- containerWidth,
230
- options
231
- } = this.props;
232
- const node = getNode();
233
- if (options && options.isBreakoutEnabled === false) {
234
- return;
235
- }
236
- const tableContainerWidth = calcTableWidth(node.attrs.layout, containerWidth.width);
237
- if (this.state.tableContainerWidth === tableContainerWidth) {
238
- return null;
239
- }
240
- this.setState(prevState => {
241
- if (options && options.isBreakoutEnabled === false && prevState.tableContainerWidth !== 'inherit') {
242
- return {
243
- tableContainerWidth: 'inherit'
244
- };
245
- }
246
- return {
247
- tableContainerWidth
248
- };
249
- });
250
- });
251
207
  _defineProperty(this, "getParentNodeWidth", () => {
252
208
  const {
253
209
  getPos,
@@ -325,7 +281,6 @@ class TableComponent extends React.Component {
325
281
  * Instead we use the resize event to only trigger updates when necessary.
326
282
  */
327
283
  window.addEventListener('resize', this.handleWindowResizeDebounced);
328
- this.updateTableContainerWidth();
329
284
  this.handleTableResizingDebounced();
330
285
  }
331
286
  const currentStickyState = stickyHeadersPluginKey.getState(this.props.view.state);
@@ -420,11 +375,12 @@ class TableComponent extends React.Component {
420
375
  ordering,
421
376
  isHeaderColumnEnabled,
422
377
  tableActive,
423
- containerWidth
378
+ containerWidth,
379
+ options,
380
+ getPos
424
381
  } = this.props;
425
382
  const {
426
383
  isLoading,
427
- tableContainerWidth,
428
384
  showBeforeShadow,
429
385
  showAfterShadow
430
386
  } = this.state;
@@ -473,15 +429,7 @@ class TableComponent extends React.Component {
473
429
  const shadowStyle = tableOverflowShadowsOptimization ? memoizeOne(visible => ({
474
430
  visibility: visible ? 'visible' : 'hidden'
475
431
  })) : NOOP;
476
- if (getBooleanFF('platform.editor.custom-table-width')) {
477
- // new table experience code goes here
478
- // return <Resizer>...
479
- }
480
- return /*#__PURE__*/React.createElement("div", {
481
- style: {
482
- width: tableContainerWidth,
483
- marginLeft: this.getMarginLeft(tableContainerWidth)
484
- },
432
+ return /*#__PURE__*/React.createElement(TableContainer, {
485
433
  className: classnames(ClassName.TABLE_CONTAINER, {
486
434
  [ClassName.WITH_CONTROLS]: allowControls && tableActive,
487
435
  [ClassName.TABLE_STICKY]: this.state.stickyHeader && hasHeaderRow,
@@ -489,8 +437,13 @@ class TableComponent extends React.Component {
489
437
  [ClassName.TABLE_SELECTED]: isTableSelected(view.state.selection),
490
438
  'less-padding': containerWidth.width < akEditorMobileBreakoutPoint
491
439
  }),
492
- "data-number-column": node.attrs.isNumberColumnEnabled,
493
- "data-layout": node.attrs.layout
440
+ editorView: view,
441
+ getPos: getPos,
442
+ node: node,
443
+ tableRef: tableRef,
444
+ containerWidth: containerWidth,
445
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.isFullWidthModeEnabled,
446
+ isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled
494
447
  }, stickyHeadersOptimization && /*#__PURE__*/React.createElement("div", {
495
448
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
496
449
  "data-testid": "sticky-sentinel-top"
@@ -0,0 +1,124 @@
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
+ const getMarginLeft = ({
8
+ lineLength,
9
+ tableWidth
10
+ }) => {
11
+ let marginLeft;
12
+ if (tableWidth !== 'inherit' && lineLength) {
13
+ const containerWidth = tableWidth;
14
+ if (containerWidth) {
15
+ marginLeft = (lineLength - containerWidth) / 2;
16
+ }
17
+ }
18
+ return marginLeft;
19
+ };
20
+ export const InnerContainer = /*#__PURE__*/forwardRef(({
21
+ marginLeft,
22
+ className,
23
+ width,
24
+ node,
25
+ children
26
+ }, ref) => {
27
+ return /*#__PURE__*/React.createElement("div", {
28
+ ref: ref,
29
+ style: {
30
+ width,
31
+ marginLeft
32
+ },
33
+ className: className,
34
+ "data-number-column": node.attrs.isNumberColumnEnabled,
35
+ "data-layout": node.attrs.layout,
36
+ "data-test-id": "table-container"
37
+ }, children);
38
+ });
39
+ export const ResizableTableContainer = ({
40
+ children,
41
+ className,
42
+ node,
43
+ lineLength,
44
+ editorView,
45
+ getPos,
46
+ tableRef
47
+ }) => {
48
+ const containerRef = useRef(null);
49
+ const innerContainerRef = useRef(null);
50
+ const updateWidth = useCallback(width => {
51
+ if (!containerRef.current || !innerContainerRef.current) {
52
+ return;
53
+ }
54
+ innerContainerRef.current.style.width = `${width}px`;
55
+ const marginLeft = getMarginLeft({
56
+ lineLength,
57
+ tableWidth: width
58
+ });
59
+ containerRef.current.style.width = `${width}px`;
60
+ containerRef.current.style.marginLeft = `${marginLeft}px`;
61
+ }, [lineLength]);
62
+ const width = getTableContainerWidth(node);
63
+ const marginLeft = getMarginLeft({
64
+ lineLength,
65
+ tableWidth: width
66
+ });
67
+ return /*#__PURE__*/React.createElement("div", {
68
+ style: {
69
+ marginLeft,
70
+ width
71
+ },
72
+ className: ClassName.TABLE_RESIZER_CONTAINER,
73
+ ref: containerRef
74
+ }, /*#__PURE__*/React.createElement(TableResizer, {
75
+ width: width,
76
+ updateWidth: updateWidth,
77
+ editorView: editorView,
78
+ getPos: getPos,
79
+ node: node,
80
+ tableRef: tableRef
81
+ }, /*#__PURE__*/React.createElement(InnerContainer, {
82
+ ref: innerContainerRef,
83
+ className: className,
84
+ node: node,
85
+ width: width,
86
+ marginLeft: 0
87
+ }, children)));
88
+ };
89
+ export const TableContainer = ({
90
+ children,
91
+ node,
92
+ className,
93
+ containerWidth: {
94
+ lineLength,
95
+ width: editorWidth
96
+ },
97
+ isFullWidthModeEnabled,
98
+ isBreakoutEnabled,
99
+ editorView,
100
+ getPos,
101
+ tableRef
102
+ }) => {
103
+ if ((isFullWidthModeEnabled || isBreakoutEnabled) && getBooleanFF('platform.editor.custom-table-width')) {
104
+ return /*#__PURE__*/React.createElement(ResizableTableContainer, {
105
+ className: className,
106
+ node: node,
107
+ lineLength: lineLength,
108
+ containerWidth: editorWidth,
109
+ editorView: editorView,
110
+ getPos: getPos,
111
+ tableRef: tableRef
112
+ }, children);
113
+ }
114
+ const tableWidth = isBreakoutEnabled ? calcTableWidth(node.attrs.layout, editorWidth) : 'inherit';
115
+ return /*#__PURE__*/React.createElement(InnerContainer, {
116
+ node: node,
117
+ className: className,
118
+ width: tableWidth,
119
+ marginLeft: getMarginLeft({
120
+ lineLength: lineLength,
121
+ tableWidth
122
+ })
123
+ }, children);
124
+ };
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import rafSchd from 'raf-schd';
3
+ import { ResizerNext } from '@atlaskit/editor-common/resizer';
4
+ import { scaleTable, previewScaleTable } from '../pm-plugins/table-resizing/utils';
5
+ const handles = {
6
+ right: true
7
+ };
8
+ export const TableResizer = ({
9
+ children,
10
+ width,
11
+ updateWidth,
12
+ editorView,
13
+ getPos,
14
+ node,
15
+ tableRef
16
+ }) => {
17
+ return /*#__PURE__*/React.createElement(ResizerNext, {
18
+ enable: handles,
19
+ width: width,
20
+ handleResizeStart: () => width,
21
+ handleResize: rafSchd((originalState, delta) => {
22
+ const newWidth = originalState.width + delta.width;
23
+ previewScaleTable(tableRef, {
24
+ node,
25
+ prevNode: node,
26
+ start: getPos() + 1,
27
+ parentWidth: newWidth
28
+ }, editorView.domAtPos.bind(editorView));
29
+ updateWidth(newWidth);
30
+ return newWidth;
31
+ }),
32
+ handleResizeStop: (originalState, delta) => {
33
+ const newWidth = originalState.width + delta.width;
34
+ const {
35
+ state,
36
+ dispatch
37
+ } = editorView;
38
+ const pos = getPos();
39
+ let tr = state.tr.setNodeMarkup(pos, undefined, {
40
+ ...node.attrs,
41
+ width: newWidth
42
+ });
43
+ const newNode = tr.doc.nodeAt(pos);
44
+ tr = scaleTable(tableRef, {
45
+ node: newNode,
46
+ prevNode: node,
47
+ start: getPos() + 1,
48
+ parentWidth: newWidth
49
+ }, editorView.domAtPos.bind(editorView))(tr);
50
+ dispatch(tr);
51
+ updateWidth(newWidth);
52
+ return newWidth;
53
+ },
54
+ resizeRatio: 2
55
+ }, children);
56
+ };
@@ -1,53 +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 const scaleTable = (tableRef, options, domAtPos) => (state, dispatch) => {
7
- if (!tableRef) {
8
- return false;
9
- }
10
- const {
11
- node,
12
- start,
13
- parentWidth,
14
- layoutChanged
15
- } = options;
16
-
17
- // If a table has not been resized yet, columns should be auto.
18
- if (hasTableBeenResized(node) === false) {
19
- // If its not a re-sized table, we still want to re-create cols
20
- // To force reflow of columns upon delete.
21
- recreateResizeColsByNode(tableRef, node);
22
- return false;
23
- }
24
- let resizeState;
25
- if (parentWidth) {
26
- resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
27
- } else {
28
- resizeState = scale(tableRef, options, domAtPos);
29
- }
30
- if (resizeState) {
31
- let {
32
- tr
33
- } = state;
34
- tr = updateColumnWidths(resizeState, node, start)(tr);
35
- if (tr.docChanged && dispatch) {
36
- tr.setMeta('scrollIntoView', false);
37
- // TODO: ED-8995
38
- // We need to do this check to reduce the number of race conditions when working with tables.
39
- // This metadata is been used in the sendTransaction function in the Collab plugin
40
- /* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
41
- 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.
42
- Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
43
- */
44
- !layoutChanged && tr.setMeta('scaleTable', true);
45
- dispatch(tr);
46
- return true;
47
- }
48
- }
49
- return false;
50
- };
3
+ import { evenAllColumnsWidths, isClickNear } from './utils';
4
+ import { updateColumnWidths } from '../../transforms';
51
5
  export const evenColumns = ({
52
6
  resizeState,
53
7
  table,
@@ -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 const 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, containerWidth = 0, options) {
@@ -18,10 +13,10 @@ export function getLayoutSize(tableLayout, containerWidth = 0, options) {
18
13
  return containerWidth ? Math.min(containerWidth - akEditorGutterPadding * 2, akEditorFullWidthLayoutWidth) : akEditorFullWidthLayoutWidth;
19
14
  }
20
15
  const 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));
@@ -3,7 +3,9 @@ import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
3
3
  import { getTableWidth } from '../../../utils';
4
4
  import { getLayoutSize } from '../utils/misc';
5
5
  import { reduceSpace } from '../utils/resize-logic';
6
- import { adjustColumnsWidths, getResizeState, getTotalWidth } from '../utils/resize-state';
6
+ import { adjustColumnsWidths, getResizeState, getTotalWidth, updateColgroup } from '../utils/resize-state';
7
+ import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
8
+ import { updateColumnWidths } from '../../../transforms';
7
9
  // Base function to trigger the actual scale on a table node.
8
10
  // Will only resize/scale if a table has been previously resized.
9
11
  export const scale = (tableRef, options, domAtPos) => {
@@ -97,4 +99,61 @@ export function scaleTableTo(state, maxSize) {
97
99
  newState = reduceSpace(newState, newTotalWidth - maxSize);
98
100
  }
99
101
  return adjustColumnsWidths(newState, maxSize);
100
- }
102
+ }
103
+ export const previewScaleTable = (tableRef, options, domAtPos) => {
104
+ const {
105
+ node,
106
+ start,
107
+ parentWidth
108
+ } = options;
109
+ if (!tableRef || !hasTableBeenResized(node)) {
110
+ return;
111
+ }
112
+ const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
113
+ if (resizeState) {
114
+ updateColgroup(resizeState, tableRef);
115
+ }
116
+ };
117
+
118
+ // Scale the table to meet new requirements (col, layout change etc)
119
+ export const scaleTable = (tableRef, options, domAtPos) => tr => {
120
+ if (!tableRef) {
121
+ return tr;
122
+ }
123
+ const {
124
+ node,
125
+ start,
126
+ parentWidth,
127
+ layoutChanged
128
+ } = options;
129
+
130
+ // If a table has not been resized yet, columns should be auto.
131
+ if (hasTableBeenResized(node) === false) {
132
+ // If its not a re-sized table, we still want to re-create cols
133
+ // To force reflow of columns upon delete.
134
+ insertColgroupFromNode(tableRef, node);
135
+ return tr;
136
+ }
137
+ let resizeState;
138
+ if (parentWidth) {
139
+ resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
140
+ } else {
141
+ resizeState = scale(tableRef, options, domAtPos);
142
+ }
143
+ if (resizeState) {
144
+ tr = updateColumnWidths(resizeState, node, start)(tr);
145
+ if (tr.docChanged) {
146
+ tr.setMeta('scrollIntoView', false);
147
+ // TODO: ED-8995
148
+ // We need to do this check to reduce the number of race conditions when working with tables.
149
+ // This metadata is been used in the sendTransaction function in the Collab plugin
150
+ /* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
151
+ 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.
152
+ Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
153
+ */
154
+ !layoutChanged && tr.setMeta('scaleTable', true);
155
+ return tr;
156
+ }
157
+ }
158
+ return tr;
159
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.5.4",
3
+ "version": "1.6.0",
4
4
  "sideEffects": false
5
5
  }