@atlaskit/editor-plugin-table 2.10.1 → 2.10.3

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 (39) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +9 -3
  3. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +28 -2
  4. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +12 -4
  5. package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
  6. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +9 -3
  7. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +29 -3
  8. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +12 -4
  9. package/dist/es2019/plugins/table/nodeviews/table.js +3 -1
  10. package/dist/esm/plugins/table/nodeviews/TableComponent.js +9 -3
  11. package/dist/esm/plugins/table/nodeviews/TableContainer.js +29 -3
  12. package/dist/esm/plugins/table/nodeviews/TableResizer.js +12 -4
  13. package/dist/esm/plugins/table/nodeviews/table.js +4 -2
  14. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +4 -2
  15. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +3 -1
  16. package/dist/types/plugins/table/nodeviews/table.d.ts +4 -4
  17. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +4 -2
  18. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +3 -1
  19. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +4 -4
  20. package/package.json +3 -3
  21. package/src/__tests__/unit/commands/go-to-next-cell.ts +5 -5
  22. package/src/__tests__/unit/commands/insert.ts +5 -5
  23. package/src/__tests__/unit/commands/misc.ts +6 -8
  24. package/src/__tests__/unit/copy-paste.ts +10 -13
  25. package/src/__tests__/unit/event-handlers/index.ts +6 -6
  26. package/src/__tests__/unit/handlers.ts +6 -5
  27. package/src/__tests__/unit/hover-selection.ts +7 -6
  28. package/src/__tests__/unit/layout.ts +6 -6
  29. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +23 -23
  30. package/src/__tests__/unit/sort-column.ts +5 -5
  31. package/src/__tests__/unit/transforms/delete-columns.ts +6 -6
  32. package/src/__tests__/unit/transforms/delete-rows.ts +6 -6
  33. package/src/__tests__/unit/transforms/merging.ts +5 -5
  34. package/src/__tests__/unit/ui/TableFloatingControls.tsx +5 -5
  35. package/src/__tests__/unit/utils.ts +5 -5
  36. package/src/plugins/table/nodeviews/TableComponent.tsx +20 -3
  37. package/src/plugins/table/nodeviews/TableContainer.tsx +48 -3
  38. package/src/plugins/table/nodeviews/TableResizer.tsx +24 -4
  39. package/src/plugins/table/nodeviews/table.tsx +14 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.10.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d6e4badd8c4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d6e4badd8c4) - Add explicit height to table when resizing width to increase performance
8
+
9
+ ## 2.10.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [`31031f52f80`](https://bitbucket.org/atlassian/atlassian-frontend/commits/31031f52f80) - Fix table shift when two users resize the same table in collab mode
14
+ - Updated dependencies
15
+
3
16
  ## 2.10.1
4
17
 
5
18
  ### Patch Changes
@@ -320,7 +320,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
320
320
  view = _this$props8.view,
321
321
  getNode = _this$props8.getNode,
322
322
  isMediaFullscreen = _this$props8.isMediaFullscreen,
323
- allowColumnResizing = _this$props8.allowColumnResizing;
323
+ allowColumnResizing = _this$props8.allowColumnResizing,
324
+ isResizing = _this$props8.isResizing,
325
+ options = _this$props8.options;
324
326
  var _getPluginState = (0, _pluginFactory.getPluginState)(view.state),
325
327
  isInDanger = _getPluginState.isInDanger;
326
328
  var table = (0, _utils2.findTable)(view.state.selection);
@@ -347,7 +349,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
347
349
  var previousTable = this.node;
348
350
  if ((0, _utils4.tablesHaveDifferentColumnWidths)(currentTable, previousTable) || (0, _utils4.tablesHaveDifferentNoOfColumns)(currentTable, previousTable)) {
349
351
  var _view = this.props.view;
350
- (0, _utils3.insertColgroupFromNode)(this.table, currentTable);
352
+ var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || (0, _utils4.tablesHaveDifferentNoOfColumns)(currentTable, previousTable) && isResizing;
353
+ if (shouldRecreateResizeCols) {
354
+ (0, _utils3.insertColgroupFromNode)(this.table, currentTable);
355
+ }
351
356
  (0, _dom.updateControls)()(_view.state);
352
357
  }
353
358
  this.handleTableResizingDebounced();
@@ -421,7 +426,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
421
426
  isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
422
427
  isNested: isNested,
423
428
  pluginInjectionApi: pluginInjectionApi,
424
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
429
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
430
+ isResizing: isResizing
425
431
  }, /*#__PURE__*/_react.default.createElement("div", {
426
432
  className: _types.TableCssClassName.TABLE_STICKY_SENTINEL_TOP,
427
433
  "data-testid": "sticky-sentinel-top"
@@ -50,9 +50,28 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
50
50
  editorView = _ref2.editorView,
51
51
  getPos = _ref2.getPos,
52
52
  tableRef = _ref2.tableRef,
53
+ isResizing = _ref2.isResizing,
53
54
  pluginInjectionApi = _ref2.pluginInjectionApi;
54
55
  var containerRef = (0, _react.useRef)(null);
55
56
  var marginLeftRef = (0, _react.useRef)(0);
57
+ var tableWidthRef = (0, _react.useRef)(_editorSharedStyles.akEditorDefaultLayoutWidth);
58
+ var updateContainerHeight = (0, _react.useCallback)(function (height) {
59
+ var _containerRef$current;
60
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.style.setProperty('height', typeof height === 'number' ? "".concat(height + 29, "px") : 'auto');
61
+ }, []);
62
+ var resizeObserverRef = (0, _react.useRef)(new ResizeObserver(function (entries) {
63
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
64
+ }));
65
+ var onResizeStart = (0, _react.useCallback)(function () {
66
+ updateContainerHeight(tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight);
67
+ if (tableRef) {
68
+ resizeObserverRef.current.observe(tableRef);
69
+ }
70
+ }, [tableRef, updateContainerHeight]);
71
+ var onResizeStop = (0, _react.useCallback)(function () {
72
+ updateContainerHeight('auto');
73
+ resizeObserverRef.current.disconnect();
74
+ }, [updateContainerHeight]);
56
75
  var updateWidth = (0, _react.useCallback)(function (width) {
57
76
  if (!containerRef.current) {
58
77
  return;
@@ -87,16 +106,21 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
87
106
  // 76 is currently an accepted padding value considering the spacing for resizer handle
88
107
  var responsiveContainerWidth = containerWidth - 76;
89
108
  var width = Math.min(tableWidth, responsiveContainerWidth);
90
- marginLeftRef.current = getMarginLeft(lineLength, width);
109
+ if (!isResizing) {
110
+ tableWidthRef.current = width;
111
+ marginLeftRef.current = getMarginLeft(lineLength, width);
112
+ }
91
113
  var maxResizerWidth = Math.min(responsiveContainerWidth, _utils.TABLE_MAX_WIDTH);
92
114
  return /*#__PURE__*/_react.default.createElement("div", {
93
115
  style: {
94
116
  marginLeft: marginLeftRef.current,
95
- width: width
117
+ width: tableWidthRef.current
96
118
  },
97
119
  className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
98
120
  ref: containerRef
99
121
  }, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, {
122
+ onResizeStart: onResizeStart,
123
+ onResizeStop: onResizeStop,
100
124
  width: width,
101
125
  maxWidth: maxResizerWidth,
102
126
  containerWidth: containerWidth,
@@ -126,6 +150,7 @@ var TableContainer = function TableContainer(_ref3) {
126
150
  getPos = _ref3.getPos,
127
151
  tableRef = _ref3.tableRef,
128
152
  isNested = _ref3.isNested,
153
+ isResizing = _ref3.isResizing,
129
154
  pluginInjectionApi = _ref3.pluginInjectionApi;
130
155
  if (isTableResizingEnabled && !isNested) {
131
156
  return /*#__PURE__*/_react.default.createElement(ResizableTableContainer, {
@@ -136,6 +161,7 @@ var TableContainer = function TableContainer(_ref3) {
136
161
  editorView: editorView,
137
162
  getPos: getPos,
138
163
  tableRef: tableRef,
164
+ isResizing: isResizing,
139
165
  pluginInjectionApi: pluginInjectionApi
140
166
  }, children);
141
167
  }
@@ -33,6 +33,10 @@ var tableHandlePosition = 14;
33
33
  var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
34
34
  var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
35
35
  var handleHeightSize = 'small';
36
+ if (!tableHeight) {
37
+ return handleHeightSize;
38
+ }
39
+
36
40
  /*
37
41
  - One row table height (minimum possible table height) ~ 45px
38
42
  - Two row table height ~ 90px
@@ -41,9 +45,9 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
41
45
  - > 46 because the height of the table can be a float number like 45.44.
42
46
  - < 96 is the height of large resize handle.
43
47
  */
44
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
48
+ if (tableHeight > 46 && tableHeight < 96) {
45
49
  handleHeightSize = 'medium';
46
- } else if (tableHeight && tableHeight >= 96) {
50
+ } else if (tableHeight >= 96) {
47
51
  handleHeightSize = 'large';
48
52
  }
49
53
  return handleHeightSize;
@@ -74,6 +78,8 @@ var TableResizer = function TableResizer(_ref) {
74
78
  maxWidth = _ref.maxWidth,
75
79
  containerWidth = _ref.containerWidth,
76
80
  updateWidth = _ref.updateWidth,
81
+ onResizeStop = _ref.onResizeStop,
82
+ onResizeStart = _ref.onResizeStart,
77
83
  editorView = _ref.editorView,
78
84
  getPos = _ref.getPos,
79
85
  node = _ref.node,
@@ -116,7 +122,8 @@ var TableResizer = function TableResizer(_ref) {
116
122
  }));
117
123
  var visibleGuidelines = getVisibleGuidelines(_guidelines.defaultGuidelines, containerWidth);
118
124
  setSnappingEnabled(displayGuideline(visibleGuidelines));
119
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
125
+ onResizeStart();
126
+ }, [displayGuideline, editorView, startMeasure, onResizeStart, containerWidth]);
120
127
  var handleResize = (0, _react.useCallback)(function (originalState, delta) {
121
128
  countFrames();
122
129
  var newWidth = originalState.width + delta.width;
@@ -181,8 +188,9 @@ var TableResizer = function TableResizer(_ref) {
181
188
  displayGuideline([]);
182
189
  updateWidth(newWidth);
183
190
  scheduleResize.cancel();
191
+ onResizeStop();
184
192
  return newWidth;
185
- }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
193
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
186
194
  var handleComponent = (0, _react.useMemo)(function () {
187
195
  return {
188
196
  left: /*#__PURE__*/_react.default.createElement("div", {
@@ -96,7 +96,8 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
96
96
  }, {
97
97
  key: "setDomAttrs",
98
98
  value: function setDomAttrs(node) {
99
- var _this2 = this;
99
+ var _this2 = this,
100
+ _tableWidthPluginKey$;
100
101
  if (!this.table) {
101
102
  return;
102
103
  }
@@ -107,7 +108,8 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
107
108
 
108
109
  // handle inline style when table been resized
109
110
  var tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
110
- if (tableInlineWidth) {
111
+ var isTableResizing = (_tableWidthPluginKey$ = _tableWidth.pluginKey.getState(this.view.state)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
112
+ if (!isTableResizing && tableInlineWidth) {
111
113
  handleInlineTableWidth(this.table, tableInlineWidth);
112
114
  }
113
115
  }
@@ -312,7 +312,9 @@ class TableComponent extends React.Component {
312
312
  view,
313
313
  getNode,
314
314
  isMediaFullscreen,
315
- allowColumnResizing
315
+ allowColumnResizing,
316
+ isResizing,
317
+ options
316
318
  } = this.props;
317
319
  const {
318
320
  isInDanger
@@ -343,7 +345,10 @@ class TableComponent extends React.Component {
343
345
  const {
344
346
  view
345
347
  } = this.props;
346
- recreateResizeColsByNode(this.table, currentTable);
348
+ const shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || tablesHaveDifferentNoOfColumns(currentTable, previousTable) && isResizing;
349
+ if (shouldRecreateResizeCols) {
350
+ recreateResizeColsByNode(this.table, currentTable);
351
+ }
347
352
  updateControls()(view.state);
348
353
  }
349
354
  this.handleTableResizingDebounced();
@@ -418,7 +423,8 @@ class TableComponent extends React.Component {
418
423
  isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
419
424
  isNested: isNested,
420
425
  pluginInjectionApi: pluginInjectionApi,
421
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
426
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
427
+ isResizing: isResizing
422
428
  }, /*#__PURE__*/React.createElement("div", {
423
429
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
424
430
  "data-testid": "sticky-sentinel-top"
@@ -2,7 +2,7 @@ import React, { forwardRef, useCallback, useRef } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
4
4
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
- import { akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
5
+ import { akEditorDefaultLayoutWidth, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
6
6
  import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
7
7
  import { TableCssClassName as ClassName } from '../types';
8
8
  import { TableResizer } from './TableResizer';
@@ -40,10 +40,29 @@ export const ResizableTableContainer = ({
40
40
  editorView,
41
41
  getPos,
42
42
  tableRef,
43
+ isResizing,
43
44
  pluginInjectionApi
44
45
  }) => {
45
46
  const containerRef = useRef(null);
46
47
  const marginLeftRef = useRef(0);
48
+ const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
49
+ const updateContainerHeight = useCallback(height => {
50
+ var _containerRef$current;
51
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.style.setProperty('height', typeof height === 'number' ? `${height + 29}px` : 'auto');
52
+ }, []);
53
+ const resizeObserverRef = useRef(new ResizeObserver(entries => {
54
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
55
+ }));
56
+ const onResizeStart = useCallback(() => {
57
+ updateContainerHeight(tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight);
58
+ if (tableRef) {
59
+ resizeObserverRef.current.observe(tableRef);
60
+ }
61
+ }, [tableRef, updateContainerHeight]);
62
+ const onResizeStop = useCallback(() => {
63
+ updateContainerHeight('auto');
64
+ resizeObserverRef.current.disconnect();
65
+ }, [updateContainerHeight]);
47
66
  const updateWidth = useCallback(width => {
48
67
  if (!containerRef.current) {
49
68
  return;
@@ -78,16 +97,21 @@ export const ResizableTableContainer = ({
78
97
  // 76 is currently an accepted padding value considering the spacing for resizer handle
79
98
  const responsiveContainerWidth = containerWidth - 76;
80
99
  const width = Math.min(tableWidth, responsiveContainerWidth);
81
- marginLeftRef.current = getMarginLeft(lineLength, width);
100
+ if (!isResizing) {
101
+ tableWidthRef.current = width;
102
+ marginLeftRef.current = getMarginLeft(lineLength, width);
103
+ }
82
104
  const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
83
105
  return /*#__PURE__*/React.createElement("div", {
84
106
  style: {
85
107
  marginLeft: marginLeftRef.current,
86
- width
108
+ width: tableWidthRef.current
87
109
  },
88
110
  className: ClassName.TABLE_RESIZER_CONTAINER,
89
111
  ref: containerRef
90
112
  }, /*#__PURE__*/React.createElement(TableResizer, {
113
+ onResizeStart: onResizeStart,
114
+ onResizeStop: onResizeStop,
91
115
  width: width,
92
116
  maxWidth: maxResizerWidth,
93
117
  containerWidth: containerWidth,
@@ -117,6 +141,7 @@ export const TableContainer = ({
117
141
  getPos,
118
142
  tableRef,
119
143
  isNested,
144
+ isResizing,
120
145
  pluginInjectionApi
121
146
  }) => {
122
147
  if (isTableResizingEnabled && !isNested) {
@@ -128,6 +153,7 @@ export const TableContainer = ({
128
153
  editorView: editorView,
129
154
  getPos: getPos,
130
155
  tableRef: tableRef,
156
+ isResizing: isResizing,
131
157
  pluginInjectionApi: pluginInjectionApi
132
158
  }, children);
133
159
  }
@@ -19,6 +19,10 @@ const tableHandlePosition = 14;
19
19
  const getResizerHandleHeight = tableRef => {
20
20
  const tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
21
21
  let handleHeightSize = 'small';
22
+ if (!tableHeight) {
23
+ return handleHeightSize;
24
+ }
25
+
22
26
  /*
23
27
  - One row table height (minimum possible table height) ~ 45px
24
28
  - Two row table height ~ 90px
@@ -27,9 +31,9 @@ const getResizerHandleHeight = tableRef => {
27
31
  - > 46 because the height of the table can be a float number like 45.44.
28
32
  - < 96 is the height of large resize handle.
29
33
  */
30
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
34
+ if (tableHeight > 46 && tableHeight < 96) {
31
35
  handleHeightSize = 'medium';
32
- } else if (tableHeight && tableHeight >= 96) {
36
+ } else if (tableHeight >= 96) {
33
37
  handleHeightSize = 'large';
34
38
  }
35
39
  return handleHeightSize;
@@ -59,6 +63,8 @@ export const TableResizer = ({
59
63
  maxWidth,
60
64
  containerWidth,
61
65
  updateWidth,
66
+ onResizeStop,
67
+ onResizeStart,
62
68
  editorView,
63
69
  getPos,
64
70
  node,
@@ -105,7 +111,8 @@ export const TableResizer = ({
105
111
  }));
106
112
  const visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
107
113
  setSnappingEnabled(displayGuideline(visibleGuidelines));
108
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
114
+ onResizeStart();
115
+ }, [displayGuideline, editorView, startMeasure, onResizeStart, containerWidth]);
109
116
  const handleResize = useCallback((originalState, delta) => {
110
117
  countFrames();
111
118
  const newWidth = originalState.width + delta.width;
@@ -171,8 +178,9 @@ export const TableResizer = ({
171
178
  displayGuideline([]);
172
179
  updateWidth(newWidth);
173
180
  scheduleResize.cancel();
181
+ onResizeStop();
174
182
  return newWidth;
175
- }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
183
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
176
184
  const handleComponent = useMemo(() => ({
177
185
  left: /*#__PURE__*/React.createElement("div", {
178
186
  className: resizerHandleShadowClassName,
@@ -69,6 +69,7 @@ export default class TableView extends ReactNodeView {
69
69
  return rendered;
70
70
  }
71
71
  setDomAttrs(node) {
72
+ var _tableWidthPluginKey$;
72
73
  if (!this.table) {
73
74
  return;
74
75
  }
@@ -79,7 +80,8 @@ export default class TableView extends ReactNodeView {
79
80
 
80
81
  // handle inline style when table been resized
81
82
  const tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
82
- if (tableInlineWidth) {
83
+ const isTableResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(this.view.state)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
84
+ if (!isTableResizing && tableInlineWidth) {
83
85
  handleInlineTableWidth(this.table, tableInlineWidth);
84
86
  }
85
87
  }
@@ -313,7 +313,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
313
313
  view = _this$props8.view,
314
314
  getNode = _this$props8.getNode,
315
315
  isMediaFullscreen = _this$props8.isMediaFullscreen,
316
- allowColumnResizing = _this$props8.allowColumnResizing;
316
+ allowColumnResizing = _this$props8.allowColumnResizing,
317
+ isResizing = _this$props8.isResizing,
318
+ options = _this$props8.options;
317
319
  var _getPluginState = getPluginState(view.state),
318
320
  isInDanger = _getPluginState.isInDanger;
319
321
  var table = findTable(view.state.selection);
@@ -340,7 +342,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
340
342
  var previousTable = this.node;
341
343
  if (tablesHaveDifferentColumnWidths(currentTable, previousTable) || tablesHaveDifferentNoOfColumns(currentTable, previousTable)) {
342
344
  var _view = this.props.view;
343
- recreateResizeColsByNode(this.table, currentTable);
345
+ var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || tablesHaveDifferentNoOfColumns(currentTable, previousTable) && isResizing;
346
+ if (shouldRecreateResizeCols) {
347
+ recreateResizeColsByNode(this.table, currentTable);
348
+ }
344
349
  updateControls()(_view.state);
345
350
  }
346
351
  this.handleTableResizingDebounced();
@@ -414,7 +419,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
414
419
  isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
415
420
  isNested: isNested,
416
421
  pluginInjectionApi: pluginInjectionApi,
417
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
422
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
423
+ isResizing: isResizing
418
424
  }, /*#__PURE__*/React.createElement("div", {
419
425
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
420
426
  "data-testid": "sticky-sentinel-top"
@@ -2,7 +2,7 @@ import React, { forwardRef, useCallback, useRef } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
4
4
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
- import { akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
5
+ import { akEditorDefaultLayoutWidth, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
6
6
  import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
7
7
  import { TableCssClassName as ClassName } from '../types';
8
8
  import { TableResizer } from './TableResizer';
@@ -39,9 +39,28 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
39
39
  editorView = _ref2.editorView,
40
40
  getPos = _ref2.getPos,
41
41
  tableRef = _ref2.tableRef,
42
+ isResizing = _ref2.isResizing,
42
43
  pluginInjectionApi = _ref2.pluginInjectionApi;
43
44
  var containerRef = useRef(null);
44
45
  var marginLeftRef = useRef(0);
46
+ var tableWidthRef = useRef(akEditorDefaultLayoutWidth);
47
+ var updateContainerHeight = useCallback(function (height) {
48
+ var _containerRef$current;
49
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.style.setProperty('height', typeof height === 'number' ? "".concat(height + 29, "px") : 'auto');
50
+ }, []);
51
+ var resizeObserverRef = useRef(new ResizeObserver(function (entries) {
52
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
53
+ }));
54
+ var onResizeStart = useCallback(function () {
55
+ updateContainerHeight(tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight);
56
+ if (tableRef) {
57
+ resizeObserverRef.current.observe(tableRef);
58
+ }
59
+ }, [tableRef, updateContainerHeight]);
60
+ var onResizeStop = useCallback(function () {
61
+ updateContainerHeight('auto');
62
+ resizeObserverRef.current.disconnect();
63
+ }, [updateContainerHeight]);
45
64
  var updateWidth = useCallback(function (width) {
46
65
  if (!containerRef.current) {
47
66
  return;
@@ -76,16 +95,21 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
76
95
  // 76 is currently an accepted padding value considering the spacing for resizer handle
77
96
  var responsiveContainerWidth = containerWidth - 76;
78
97
  var width = Math.min(tableWidth, responsiveContainerWidth);
79
- marginLeftRef.current = getMarginLeft(lineLength, width);
98
+ if (!isResizing) {
99
+ tableWidthRef.current = width;
100
+ marginLeftRef.current = getMarginLeft(lineLength, width);
101
+ }
80
102
  var maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
81
103
  return /*#__PURE__*/React.createElement("div", {
82
104
  style: {
83
105
  marginLeft: marginLeftRef.current,
84
- width: width
106
+ width: tableWidthRef.current
85
107
  },
86
108
  className: ClassName.TABLE_RESIZER_CONTAINER,
87
109
  ref: containerRef
88
110
  }, /*#__PURE__*/React.createElement(TableResizer, {
111
+ onResizeStart: onResizeStart,
112
+ onResizeStop: onResizeStop,
89
113
  width: width,
90
114
  maxWidth: maxResizerWidth,
91
115
  containerWidth: containerWidth,
@@ -114,6 +138,7 @@ export var TableContainer = function TableContainer(_ref3) {
114
138
  getPos = _ref3.getPos,
115
139
  tableRef = _ref3.tableRef,
116
140
  isNested = _ref3.isNested,
141
+ isResizing = _ref3.isResizing,
117
142
  pluginInjectionApi = _ref3.pluginInjectionApi;
118
143
  if (isTableResizingEnabled && !isNested) {
119
144
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
@@ -124,6 +149,7 @@ export var TableContainer = function TableContainer(_ref3) {
124
149
  editorView: editorView,
125
150
  getPos: getPos,
126
151
  tableRef: tableRef,
152
+ isResizing: isResizing,
127
153
  pluginInjectionApi: pluginInjectionApi
128
154
  }, children);
129
155
  }
@@ -23,6 +23,10 @@ var tableHandlePosition = 14;
23
23
  var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
24
24
  var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
25
25
  var handleHeightSize = 'small';
26
+ if (!tableHeight) {
27
+ return handleHeightSize;
28
+ }
29
+
26
30
  /*
27
31
  - One row table height (minimum possible table height) ~ 45px
28
32
  - Two row table height ~ 90px
@@ -31,9 +35,9 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
31
35
  - > 46 because the height of the table can be a float number like 45.44.
32
36
  - < 96 is the height of large resize handle.
33
37
  */
34
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
38
+ if (tableHeight > 46 && tableHeight < 96) {
35
39
  handleHeightSize = 'medium';
36
- } else if (tableHeight && tableHeight >= 96) {
40
+ } else if (tableHeight >= 96) {
37
41
  handleHeightSize = 'large';
38
42
  }
39
43
  return handleHeightSize;
@@ -64,6 +68,8 @@ export var TableResizer = function TableResizer(_ref) {
64
68
  maxWidth = _ref.maxWidth,
65
69
  containerWidth = _ref.containerWidth,
66
70
  updateWidth = _ref.updateWidth,
71
+ onResizeStop = _ref.onResizeStop,
72
+ onResizeStart = _ref.onResizeStart,
67
73
  editorView = _ref.editorView,
68
74
  getPos = _ref.getPos,
69
75
  node = _ref.node,
@@ -106,7 +112,8 @@ export var TableResizer = function TableResizer(_ref) {
106
112
  }));
107
113
  var visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
108
114
  setSnappingEnabled(displayGuideline(visibleGuidelines));
109
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
115
+ onResizeStart();
116
+ }, [displayGuideline, editorView, startMeasure, onResizeStart, containerWidth]);
110
117
  var handleResize = useCallback(function (originalState, delta) {
111
118
  countFrames();
112
119
  var newWidth = originalState.width + delta.width;
@@ -171,8 +178,9 @@ export var TableResizer = function TableResizer(_ref) {
171
178
  displayGuideline([]);
172
179
  updateWidth(newWidth);
173
180
  scheduleResize.cancel();
181
+ onResizeStop();
174
182
  return newWidth;
175
- }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
183
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
176
184
  var handleComponent = useMemo(function () {
177
185
  return {
178
186
  left: /*#__PURE__*/React.createElement("div", {
@@ -89,7 +89,8 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
89
89
  }, {
90
90
  key: "setDomAttrs",
91
91
  value: function setDomAttrs(node) {
92
- var _this2 = this;
92
+ var _this2 = this,
93
+ _tableWidthPluginKey$;
93
94
  if (!this.table) {
94
95
  return;
95
96
  }
@@ -100,7 +101,8 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
100
101
 
101
102
  // handle inline style when table been resized
102
103
  var tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
103
- if (tableInlineWidth) {
104
+ var isTableResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(this.view.state)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
105
+ if (!isTableResizing && tableInlineWidth) {
104
106
  handleInlineTableWidth(this.table, tableInlineWidth);
105
107
  }
106
108
  }
@@ -23,9 +23,10 @@ type ResizableTableContainerProps = {
23
23
  editorView: EditorView;
24
24
  getPos: () => number | undefined;
25
25
  tableRef: HTMLTableElement;
26
+ isResizing?: boolean;
26
27
  pluginInjectionApi?: PluginInjectionAPI;
27
28
  };
28
- export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
+ export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
30
  type TableContainerProps = {
30
31
  node: PMNode;
31
32
  className: string;
@@ -36,7 +37,8 @@ type TableContainerProps = {
36
37
  getPos: () => number | undefined;
37
38
  tableRef: HTMLTableElement;
38
39
  isNested: boolean;
40
+ isResizing?: boolean;
39
41
  pluginInjectionApi?: PluginInjectionAPI;
40
42
  };
41
- export declare const TableContainer: ({ children, node, className, containerWidth: { lineLength, width: editorWidth }, isTableResizingEnabled, isBreakoutEnabled, editorView, getPos, tableRef, isNested, pluginInjectionApi, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
43
+ export declare const TableContainer: ({ children, node, className, containerWidth: { lineLength, width: editorWidth }, isTableResizingEnabled, isBreakoutEnabled, editorView, getPos, tableRef, isNested, isResizing, pluginInjectionApi, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
42
44
  export {};
@@ -9,6 +9,8 @@ interface TableResizerProps {
9
9
  maxWidth: number;
10
10
  containerWidth: number;
11
11
  updateWidth: (width: number) => void;
12
+ onResizeStop: () => void;
13
+ onResizeStart: () => void;
12
14
  editorView: EditorView;
13
15
  getPos: () => number | undefined;
14
16
  node: PMNode;
@@ -16,5 +18,5 @@ interface TableResizerProps {
16
18
  displayGuideline: (guideline: GuidelineConfig[]) => boolean;
17
19
  attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
18
20
  }
19
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
21
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
20
22
  export {};
@@ -3,10 +3,10 @@ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
3
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
4
4
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
5
5
  import type { GetEditorContainerWidth, GetEditorFeatureFlags, getPosHandler, getPosHandlerNode } from '@atlaskit/editor-common/types';
6
- import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
7
- import { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
8
- import { PluginInjectionAPI } from '../types';
9
- import { Props, TableOptions } from './types';
6
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
7
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
8
+ import type { PluginInjectionAPI } from '../types';
9
+ import type { Props, TableOptions } from './types';
10
10
  type ForwardRef = (node: HTMLElement | null) => void;
11
11
  export default class TableView extends ReactNodeView<Props> {
12
12
  private table;
@@ -23,9 +23,10 @@ type ResizableTableContainerProps = {
23
23
  editorView: EditorView;
24
24
  getPos: () => number | undefined;
25
25
  tableRef: HTMLTableElement;
26
+ isResizing?: boolean;
26
27
  pluginInjectionApi?: PluginInjectionAPI;
27
28
  };
28
- export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
+ export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
30
  type TableContainerProps = {
30
31
  node: PMNode;
31
32
  className: string;
@@ -36,7 +37,8 @@ type TableContainerProps = {
36
37
  getPos: () => number | undefined;
37
38
  tableRef: HTMLTableElement;
38
39
  isNested: boolean;
40
+ isResizing?: boolean;
39
41
  pluginInjectionApi?: PluginInjectionAPI;
40
42
  };
41
- export declare const TableContainer: ({ children, node, className, containerWidth: { lineLength, width: editorWidth }, isTableResizingEnabled, isBreakoutEnabled, editorView, getPos, tableRef, isNested, pluginInjectionApi, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
43
+ export declare const TableContainer: ({ children, node, className, containerWidth: { lineLength, width: editorWidth }, isTableResizingEnabled, isBreakoutEnabled, editorView, getPos, tableRef, isNested, isResizing, pluginInjectionApi, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
42
44
  export {};
@@ -9,6 +9,8 @@ interface TableResizerProps {
9
9
  maxWidth: number;
10
10
  containerWidth: number;
11
11
  updateWidth: (width: number) => void;
12
+ onResizeStop: () => void;
13
+ onResizeStart: () => void;
12
14
  editorView: EditorView;
13
15
  getPos: () => number | undefined;
14
16
  node: PMNode;
@@ -16,5 +18,5 @@ interface TableResizerProps {
16
18
  displayGuideline: (guideline: GuidelineConfig[]) => boolean;
17
19
  attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
18
20
  }
19
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
21
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
20
22
  export {};