@atlaskit/editor-plugin-table 7.4.9 → 7.5.1

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 (184) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/commands/column-resize.js +4 -2
  3. package/dist/cjs/commands/delete.js +2 -1
  4. package/dist/cjs/commands/insert.js +6 -3
  5. package/dist/cjs/commands-with-analytics.js +4 -2
  6. package/dist/cjs/event-handlers.js +2 -1
  7. package/dist/cjs/nodeviews/TableComponent.js +116 -47
  8. package/dist/cjs/nodeviews/TableContainer.js +8 -4
  9. package/dist/cjs/nodeviews/TableResizer.js +6 -5
  10. package/dist/cjs/nodeviews/table.js +12 -4
  11. package/dist/cjs/plugin.js +50 -47
  12. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +9 -6
  13. package/dist/cjs/pm-plugins/keymap.js +6 -3
  14. package/dist/cjs/pm-plugins/main.js +4 -1
  15. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +7 -3
  16. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +32 -11
  17. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
  18. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +24 -0
  19. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +20 -1
  20. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +2 -1
  21. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +52 -11
  22. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +19 -8
  23. package/dist/cjs/toolbar.js +17 -10
  24. package/dist/cjs/transforms/column-width.js +22 -7
  25. package/dist/cjs/transforms/delete-columns.js +2 -1
  26. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
  27. package/dist/cjs/ui/FloatingContextualMenu/index.js +4 -2
  28. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -2
  29. package/dist/cjs/ui/FloatingDragMenu/index.js +7 -2
  30. package/dist/cjs/ui/FloatingInsertButton/index.js +5 -1
  31. package/dist/cjs/utils/create.js +1 -1
  32. package/dist/cjs/utils/drag-menu.js +4 -3
  33. package/dist/es2019/commands/column-resize.js +4 -3
  34. package/dist/es2019/commands/delete.js +2 -2
  35. package/dist/es2019/commands/insert.js +6 -6
  36. package/dist/es2019/commands-with-analytics.js +4 -4
  37. package/dist/es2019/event-handlers.js +2 -2
  38. package/dist/es2019/nodeviews/TableComponent.js +77 -8
  39. package/dist/es2019/nodeviews/TableContainer.js +8 -4
  40. package/dist/es2019/nodeviews/TableResizer.js +6 -5
  41. package/dist/es2019/nodeviews/table.js +12 -4
  42. package/dist/es2019/plugin.js +14 -8
  43. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +7 -4
  44. package/dist/es2019/pm-plugins/keymap.js +6 -3
  45. package/dist/es2019/pm-plugins/main.js +4 -1
  46. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +7 -3
  47. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +31 -12
  48. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
  49. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +2 -2
  50. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +20 -2
  51. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +2 -2
  52. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +47 -10
  53. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +19 -12
  54. package/dist/es2019/toolbar.js +15 -12
  55. package/dist/es2019/transforms/column-width.js +24 -10
  56. package/dist/es2019/transforms/delete-columns.js +2 -2
  57. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +12 -5
  58. package/dist/es2019/ui/FloatingContextualMenu/index.js +4 -2
  59. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -2
  60. package/dist/es2019/ui/FloatingDragMenu/index.js +7 -2
  61. package/dist/es2019/ui/FloatingInsertButton/index.js +5 -1
  62. package/dist/es2019/utils/create.js +1 -1
  63. package/dist/es2019/utils/drag-menu.js +4 -4
  64. package/dist/esm/commands/column-resize.js +4 -2
  65. package/dist/esm/commands/delete.js +2 -1
  66. package/dist/esm/commands/insert.js +6 -3
  67. package/dist/esm/commands-with-analytics.js +4 -2
  68. package/dist/esm/event-handlers.js +2 -1
  69. package/dist/esm/nodeviews/TableComponent.js +118 -49
  70. package/dist/esm/nodeviews/TableContainer.js +8 -4
  71. package/dist/esm/nodeviews/TableResizer.js +6 -5
  72. package/dist/esm/nodeviews/table.js +12 -4
  73. package/dist/esm/plugin.js +50 -47
  74. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -6
  75. package/dist/esm/pm-plugins/keymap.js +6 -3
  76. package/dist/esm/pm-plugins/main.js +4 -1
  77. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +7 -3
  78. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +32 -11
  79. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
  80. package/dist/esm/pm-plugins/table-resizing/utils/index.js +2 -2
  81. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +22 -2
  82. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +2 -1
  83. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +52 -11
  84. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +19 -8
  85. package/dist/esm/toolbar.js +17 -10
  86. package/dist/esm/transforms/column-width.js +23 -8
  87. package/dist/esm/transforms/delete-columns.js +2 -1
  88. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
  89. package/dist/esm/ui/FloatingContextualMenu/index.js +4 -2
  90. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -2
  91. package/dist/esm/ui/FloatingDragMenu/index.js +7 -2
  92. package/dist/esm/ui/FloatingInsertButton/index.js +5 -1
  93. package/dist/esm/utils/create.js +1 -1
  94. package/dist/esm/utils/drag-menu.js +4 -3
  95. package/dist/types/commands/column-resize.d.ts +1 -1
  96. package/dist/types/commands/delete.d.ts +1 -1
  97. package/dist/types/commands/insert.d.ts +3 -3
  98. package/dist/types/commands-with-analytics.d.ts +2 -2
  99. package/dist/types/event-handlers.d.ts +1 -1
  100. package/dist/types/nodeviews/TableComponent.d.ts +3 -0
  101. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  102. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  103. package/dist/types/nodeviews/table.d.ts +1 -0
  104. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
  105. package/dist/types/pm-plugins/keymap.d.ts +2 -2
  106. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  107. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
  108. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  109. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
  110. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  111. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
  112. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  113. package/dist/types/toolbar.d.ts +2 -2
  114. package/dist/types/transforms/column-width.d.ts +1 -1
  115. package/dist/types/transforms/delete-columns.d.ts +1 -1
  116. package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
  117. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  118. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  119. package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
  120. package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
  121. package/dist/types/utils/drag-menu.d.ts +1 -1
  122. package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
  123. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  124. package/dist/types-ts4.5/commands/insert.d.ts +3 -3
  125. package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
  126. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  127. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +3 -0
  128. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  129. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  130. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -0
  131. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
  132. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
  133. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  134. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
  135. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  136. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
  137. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  138. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
  139. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  140. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  141. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  142. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  143. package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
  144. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  145. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  146. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
  147. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -1
  148. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  149. package/docs/0-intro.tsx +3 -2
  150. package/package.json +2 -2
  151. package/src/commands/column-resize.ts +3 -0
  152. package/src/commands/delete.ts +2 -1
  153. package/src/commands/insert.ts +15 -6
  154. package/src/commands-with-analytics.ts +9 -3
  155. package/src/event-handlers.ts +2 -0
  156. package/src/nodeviews/TableComponent.tsx +91 -5
  157. package/src/nodeviews/TableContainer.tsx +7 -1
  158. package/src/nodeviews/TableResizer.tsx +7 -1
  159. package/src/nodeviews/table.tsx +15 -10
  160. package/src/plugin.tsx +17 -5
  161. package/src/pm-plugins/drag-and-drop/plugin.ts +16 -8
  162. package/src/pm-plugins/keymap.ts +11 -3
  163. package/src/pm-plugins/main.ts +3 -0
  164. package/src/pm-plugins/table-resizing/event-handlers.ts +11 -1
  165. package/src/pm-plugins/table-resizing/utils/colgroup.ts +49 -17
  166. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  167. package/src/pm-plugins/table-resizing/utils/index.ts +8 -1
  168. package/src/pm-plugins/table-resizing/utils/misc.ts +25 -1
  169. package/src/pm-plugins/table-resizing/utils/resize-column.ts +2 -1
  170. package/src/pm-plugins/table-resizing/utils/resize-state.ts +56 -11
  171. package/src/pm-plugins/table-resizing/utils/scale-table.ts +24 -6
  172. package/src/toolbar.tsx +18 -5
  173. package/src/transforms/column-width.ts +33 -11
  174. package/src/transforms/delete-columns.ts +7 -2
  175. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -5
  176. package/src/ui/FloatingContextualMenu/index.tsx +2 -0
  177. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
  178. package/src/ui/FloatingDragMenu/index.tsx +9 -1
  179. package/src/ui/FloatingInsertButton/index.tsx +17 -5
  180. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +4 -1
  181. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +4 -1
  182. package/src/utils/create.ts +1 -3
  183. package/src/utils/drag-menu.ts +4 -1
  184. package/tsconfig.dev.json +1 -1
@@ -21,6 +21,7 @@ function addColumnAtCustomStep(column) {
21
21
  };
22
22
  }
23
23
  export function addColumnAt(getEditorContainerWidth) {
24
+ var tablePreserveWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
24
25
  return function (column) {
25
26
  var allowAddColumnCustomStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
26
27
  var view = arguments.length > 2 ? arguments[2] : undefined;
@@ -34,7 +35,7 @@ export function addColumnAt(getEditorContainerWidth) {
34
35
  var table = findTable(updatedTr.selection);
35
36
  if (table) {
36
37
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
37
- updatedTr = rescaleColumns()(table, view)(updatedTr);
38
+ updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
38
39
  }
39
40
  if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event') && view) {
40
41
  updatedTr = updateRowOrColumnMovedTransform({
@@ -52,6 +53,7 @@ export function addColumnAt(getEditorContainerWidth) {
52
53
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
53
54
  // Command to add a column before the column with the selection.
54
55
  export var addColumnBefore = function addColumnBefore(getEditorContainerWidth) {
56
+ var tablePreserveWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
55
57
  return function (state, dispatch, view) {
56
58
  var table = findTable(state.selection);
57
59
  if (!table) {
@@ -59,7 +61,7 @@ export var addColumnBefore = function addColumnBefore(getEditorContainerWidth) {
59
61
  }
60
62
  if (dispatch) {
61
63
  var rect = selectedRect(state);
62
- dispatch(addColumnAt(getEditorContainerWidth)(rect.left, getAllowAddColumnCustomStep(state), view)(state.tr));
64
+ dispatch(addColumnAt(getEditorContainerWidth, tablePreserveWidth)(rect.left, getAllowAddColumnCustomStep(state), view)(state.tr));
63
65
  }
64
66
  return true;
65
67
  };
@@ -81,9 +83,10 @@ export var addColumnAfter = function addColumnAfter(getEditorContainerWidth) {
81
83
  };
82
84
  };
83
85
  export var insertColumn = function insertColumn(getEditorContainerWidth) {
86
+ var tablePreserveWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
84
87
  return function (column) {
85
88
  return function (state, dispatch, view) {
86
- var tr = addColumnAt(getEditorContainerWidth)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
89
+ var tr = addColumnAt(getEditorContainerWidth, tablePreserveWidth)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
87
90
  var table = findTable(tr.selection);
88
91
  if (!table) {
89
92
  return false;
@@ -183,6 +183,7 @@ export var insertRowWithAnalytics = function insertRowWithAnalytics(editorAnalyt
183
183
  };
184
184
  };
185
185
  export var insertColumnWithAnalytics = function insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI) {
186
+ var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
186
187
  return function (inputMethod, position) {
187
188
  return withEditorAnalyticsAPI(function (state) {
188
189
  var _getSelectedTableInfo2 = getSelectedTableInfo(state.selection),
@@ -200,7 +201,7 @@ export var insertColumnWithAnalytics = function insertColumnWithAnalytics(getEdi
200
201
  },
201
202
  eventType: EVENT_TYPE.TRACK
202
203
  };
203
- })(editorAnalyticsAPI)(insertColumn(getEditorContainerWidth)(position));
204
+ })(editorAnalyticsAPI)(insertColumn(getEditorContainerWidth, tablePreserveWidth)(position));
204
205
  };
205
206
  };
206
207
  export var deleteRowsWithAnalytics = function deleteRowsWithAnalytics(editorAnalyticsAPI) {
@@ -232,6 +233,7 @@ export var deleteRowsWithAnalytics = function deleteRowsWithAnalytics(editorAnal
232
233
  };
233
234
  };
234
235
  export var deleteColumnsWithAnalytics = function deleteColumnsWithAnalytics(editorAnalyticsAPI) {
236
+ var tablePreserveWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
235
237
  return function (inputMethod, rect) {
236
238
  return withEditorAnalyticsAPI(function (_ref6) {
237
239
  var selection = _ref6.selection;
@@ -251,7 +253,7 @@ export var deleteColumnsWithAnalytics = function deleteColumnsWithAnalytics(edit
251
253
  },
252
254
  eventType: EVENT_TYPE.TRACK
253
255
  };
254
- })(editorAnalyticsAPI)(deleteColumnsCommand(rect));
256
+ })(editorAnalyticsAPI)(deleteColumnsCommand(rect, tablePreserveWidth));
255
257
  };
256
258
  };
257
259
  export var deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = function deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI) {
@@ -328,6 +328,7 @@ export function handleTripleClick(view, pos) {
328
328
  return false;
329
329
  }
330
330
  export var handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI, editorView) {
331
+ var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
331
332
  var oldSelection = oldState.tr.selection;
332
333
  var tr = newState.tr;
333
334
  if (oldSelection instanceof CellSelection) {
@@ -370,7 +371,7 @@ export var handleCut = function handleCut(oldTr, oldState, newState, editorAnaly
370
371
  isHeaderRowRequired = _getPluginState9.pluginConfig.isHeaderRowRequired;
371
372
  tr = deleteRows(rect, isHeaderRowRequired)(tr);
372
373
  } else if (tr.selection.isColSelection()) {
373
- tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView)(tr);
374
+ tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView, tablePreserveWidth)(tr);
374
375
  }
375
376
  }
376
377
  }
@@ -17,7 +17,7 @@ import rafSchedule from 'raf-schd';
17
17
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
18
18
  import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
19
19
  import { tableMarginSides } from '@atlaskit/editor-common/styles';
20
- import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
20
+ import { browser, calcTableColumnWidths, isValidPosition } from '@atlaskit/editor-common/utils';
21
21
  import { MAX_BROWSER_SCROLLBAR_HEIGHT, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
22
22
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
23
23
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -27,7 +27,7 @@ import { autoScrollerFactory } from '../pm-plugins/drag-and-drop/utils';
27
27
  import { getPluginState } from '../pm-plugins/plugin-factory';
28
28
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
29
29
  import { META_KEYS } from '../pm-plugins/table-analytics';
30
- import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scaleTable } from '../pm-plugins/table-resizing/utils';
30
+ import { COLUMN_MIN_WIDTH, getLayoutSize, getResizeState, insertColgroupFromNode, scaleTable, updateColgroup } from '../pm-plugins/table-resizing/utils';
31
31
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
32
32
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
33
33
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
@@ -168,7 +168,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
168
168
  getNode = _this$props2.getNode,
169
169
  getPos = _this$props2.getPos,
170
170
  containerWidth = _this$props2.containerWidth,
171
- options = _this$props2.options;
171
+ options = _this$props2.options,
172
+ getEditorFeatureFlags = _this$props2.getEditorFeatureFlags;
172
173
  var node = getNode();
173
174
  var state = view.state,
174
175
  dispatch = view.dispatch;
@@ -179,13 +180,16 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
179
180
  var domAtPos = view.domAtPos.bind(view);
180
181
  var width = containerWidth.width;
181
182
  _this.scaleTableDebounced.cancel();
183
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
184
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
185
+ tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
182
186
  var tr = scaleTable(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
183
187
  node: node,
184
188
  prevNode: _this.node || node,
185
189
  start: pos + 1,
186
190
  containerWidth: width,
187
191
  previousContainerWidth: _this.containerWidth.width || width
188
- }, options), domAtPos)(state.tr);
192
+ }, options), domAtPos, tablePreserveWidth)(state.tr);
189
193
  dispatch(tr);
190
194
  });
191
195
  _defineProperty(_assertThisInitialized(_this), "setTimerToSendInitialOverflowCaptured", function (isOverflowing) {
@@ -312,8 +316,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
312
316
  this.wrapper.addEventListener('scroll', this.handleScrollDebounced, {
313
317
  passive: true
314
318
  });
315
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
316
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
319
+ var _getEditorFeatureFlag3 = getEditorFeatureFlags(),
320
+ stickyScrollbar = _getEditorFeatureFlag3.stickyScrollbar;
317
321
  if (stickyScrollbar) {
318
322
  if (this.table) {
319
323
  this.stickyScrollbar = new TableStickyScrollbar(this.wrapper, this.props.view);
@@ -359,8 +363,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
359
363
  if (isDragAndDropEnabled && this.dragAndDropCleanupFn) {
360
364
  this.dragAndDropCleanupFn();
361
365
  }
362
- var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
363
- stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
366
+ var _getEditorFeatureFlag4 = getEditorFeatureFlags(),
367
+ stickyScrollbar = _getEditorFeatureFlag4.stickyScrollbar;
364
368
  if (stickyScrollbar) {
365
369
  if (this.stickyScrollbar) {
366
370
  this.stickyScrollbar.dispose();
@@ -385,20 +389,83 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
385
389
  }
386
390
  }
387
391
  }, {
388
- key: "componentDidUpdate",
389
- value: function componentDidUpdate(_, prevState) {
390
- var _this$wrapper,
391
- _this2 = this;
392
+ key: "handleColgroupUpdates",
393
+ value: function handleColgroupUpdates() {
394
+ var _this2 = this,
395
+ _this$containerWidth;
392
396
  var _this$props9 = this.props,
393
- view = _this$props9.view,
394
397
  getNode = _this$props9.getNode,
395
- isMediaFullscreen = _this$props9.isMediaFullscreen,
396
- allowColumnResizing = _this$props9.allowColumnResizing,
398
+ containerWidth = _this$props9.containerWidth,
397
399
  isResizing = _this$props9.isResizing,
398
- options = _this$props9.options;
400
+ view = _this$props9.view,
401
+ getPos = _this$props9.getPos,
402
+ tableRef = _this$props9.tableRef;
403
+ if (!tableRef) {
404
+ return;
405
+ }
406
+ var TABLE_MARGIN = 76;
407
+
408
+ // Remove any widths styles after resizing preview is completed
409
+ tableRef.style.width = '';
410
+ var tableRenderWidth = containerWidth.width - TABLE_MARGIN;
411
+ var tableNode = getNode();
412
+ var start = getPos() || 0;
413
+ var depth = view.state.doc.resolve(start).depth;
414
+
415
+ // TODO - remove this when support is added for nested tables
416
+ if (depth !== 0) {
417
+ return;
418
+ }
419
+ var tableNodeWidth = tableNode.attrs.width;
420
+ var tableColumnWidths = calcTableColumnWidths(tableNode);
421
+ var shouldTableScale = tableRenderWidth < tableNodeWidth;
422
+ var isTableColumnWidthsSame = false;
423
+ if (this.tableColumnWidths) {
424
+ isTableColumnWidthsSame = tableColumnWidths === null || tableColumnWidths === void 0 ? void 0 : tableColumnWidths.every(function (width, index) {
425
+ return width === _this2.tableColumnWidths[index];
426
+ });
427
+ }
428
+ var containerWidthValue = containerWidth.width;
429
+ var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
430
+ if (shouldTableScale && !isResizing && (!isTableColumnWidthsSame || isWidthChanged)) {
431
+ var resizeState = getResizeState({
432
+ minWidth: COLUMN_MIN_WIDTH,
433
+ maxSize: tableRenderWidth,
434
+ table: tableNode,
435
+ tableRef: this.table,
436
+ start: start,
437
+ domAtPos: view.domAtPos,
438
+ tablePreserveWidth: true
439
+ });
440
+ requestAnimationFrame(function () {
441
+ updateColgroup(resizeState, _this2.table, true);
442
+ });
443
+ this.tableColumnWidths = tableColumnWidths;
444
+ this.containerWidth = containerWidth;
445
+ }
446
+ }
447
+ }, {
448
+ key: "componentDidUpdate",
449
+ value: function componentDidUpdate(_, prevState) {
450
+ var _this$wrapper,
451
+ _this3 = this;
452
+ var _this$props10 = this.props,
453
+ view = _this$props10.view,
454
+ getNode = _this$props10.getNode,
455
+ isMediaFullscreen = _this$props10.isMediaFullscreen,
456
+ allowColumnResizing = _this$props10.allowColumnResizing,
457
+ isResizing = _this$props10.isResizing,
458
+ options = _this$props10.options,
459
+ getEditorFeatureFlags = _this$props10.getEditorFeatureFlags;
399
460
  var _getPluginState = getPluginState(view.state),
400
461
  isInDanger = _getPluginState.isInDanger;
462
+ var _getEditorFeatureFlag5 = getEditorFeatureFlags(),
463
+ _getEditorFeatureFlag6 = _getEditorFeatureFlag5.tablePreserveWidth,
464
+ tablePreserveWidth = _getEditorFeatureFlag6 === void 0 ? false : _getEditorFeatureFlag6;
401
465
  var table = findTable(view.state.selection);
466
+ if (tablePreserveWidth) {
467
+ this.handleColgroupUpdates();
468
+ }
402
469
  if (isInDanger && !table) {
403
470
  clearHoverSelection()(view.state, view.dispatch);
404
471
  }
@@ -408,7 +475,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
408
475
  // that happens when a table is nested in expand and expand's width is
409
476
  // changed via breakout button
410
477
  window.requestAnimationFrame(function () {
411
- _this2.overflowShadowsObserver = new OverflowShadowsObserver(_this2.updateShadowState, _this2.table, _this2.wrapper);
478
+ _this3.overflowShadowsObserver = new OverflowShadowsObserver(_this3.updateShadowState, _this3.table, _this3.wrapper);
412
479
  });
413
480
  } else {
414
481
  this.overflowShadowsObserver = new OverflowShadowsObserver(this.updateShadowState, this.table, this.wrapper);
@@ -433,7 +500,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
433
500
  var _view = this.props.view;
434
501
  var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || tablesHaveDifferentNoOfColumns(currentTable, previousTable) && isResizing;
435
502
  if (shouldRecreateResizeCols) {
436
- recreateResizeColsByNode(this.table, currentTable);
503
+ insertColgroupFromNode(this.table, currentTable, tablePreserveWidth);
437
504
  }
438
505
  updateControls()(_view.state);
439
506
  }
@@ -464,24 +531,24 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
464
531
  }, {
465
532
  key: "render",
466
533
  value: function render() {
467
- var _this3 = this,
534
+ var _this4 = this,
468
535
  _classnames;
469
- var _this$props10 = this.props,
470
- view = _this$props10.view,
471
- getNode = _this$props10.getNode,
472
- isResizing = _this$props10.isResizing,
473
- _this$props10$allowCo = _this$props10.allowControls,
474
- allowControls = _this$props10$allowCo === void 0 ? true : _this$props10$allowCo,
475
- isHeaderRowEnabled = _this$props10.isHeaderRowEnabled,
476
- ordering = _this$props10.ordering,
477
- isHeaderColumnEnabled = _this$props10.isHeaderColumnEnabled,
478
- tableActive = _this$props10.tableActive,
479
- containerWidth = _this$props10.containerWidth,
480
- options = _this$props10.options,
481
- getPos = _this$props10.getPos,
482
- pluginInjectionApi = _this$props10.pluginInjectionApi,
483
- isDragAndDropEnabled = _this$props10.isDragAndDropEnabled,
484
- getEditorFeatureFlags = _this$props10.getEditorFeatureFlags;
536
+ var _this$props11 = this.props,
537
+ view = _this$props11.view,
538
+ getNode = _this$props11.getNode,
539
+ isResizing = _this$props11.isResizing,
540
+ _this$props11$allowCo = _this$props11.allowControls,
541
+ allowControls = _this$props11$allowCo === void 0 ? true : _this$props11$allowCo,
542
+ isHeaderRowEnabled = _this$props11.isHeaderRowEnabled,
543
+ ordering = _this$props11.ordering,
544
+ isHeaderColumnEnabled = _this$props11.isHeaderColumnEnabled,
545
+ tableActive = _this$props11.tableActive,
546
+ containerWidth = _this$props11.containerWidth,
547
+ options = _this$props11.options,
548
+ getPos = _this$props11.getPos,
549
+ pluginInjectionApi = _this$props11.pluginInjectionApi,
550
+ isDragAndDropEnabled = _this$props11.isDragAndDropEnabled,
551
+ getEditorFeatureFlags = _this$props11.getEditorFeatureFlags;
485
552
  var _this$state3 = this.state,
486
553
  showBeforeShadow = _this$state3.showBeforeShadow,
487
554
  showAfterShadow = _this$state3.showAfterShadow;
@@ -539,8 +606,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
539
606
  tableContainerWidth: tableContainerWidth,
540
607
  isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
541
608
  getScrollOffset: function getScrollOffset() {
542
- var _this3$wrapper;
543
- return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
609
+ var _this4$wrapper;
610
+ return ((_this4$wrapper = _this4.wrapper) === null || _this4$wrapper === void 0 ? void 0 : _this4$wrapper.scrollLeft) || 0;
544
611
  }
545
612
  }) : null;
546
613
  var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
@@ -563,8 +630,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
563
630
  }
564
631
  var isNested = isTableNested(view.state, tablePos);
565
632
  var topStickyShadowPosition = isDragAndDropEnabled ? this.state.stickyHeader && this.state.stickyHeader.top + this.state.stickyHeader.padding + 2 : this.state.stickyHeader && this.state.stickyHeader.top + this.state.stickyHeader.padding + shadowPadding + 2;
566
- var _getEditorFeatureFlag3 = getEditorFeatureFlags(),
567
- stickyScrollbar = _getEditorFeatureFlag3.stickyScrollbar;
633
+ var _getEditorFeatureFlag7 = getEditorFeatureFlags(),
634
+ stickyScrollbar = _getEditorFeatureFlag7.stickyScrollbar,
635
+ tablePreserveWidth = _getEditorFeatureFlag7.tablePreserveWidth;
568
636
  return /*#__PURE__*/React.createElement(TableContainer, {
569
637
  className: classnames(ClassName.TABLE_CONTAINER, (_classnames = {}, _defineProperty(_classnames, ClassName.WITH_CONTROLS, allowControls && tableActive), _defineProperty(_classnames, ClassName.TABLE_STICKY, this.state.stickyHeader && hasHeaderRow), _defineProperty(_classnames, ClassName.HOVERED_DELETE_BUTTON, isInDanger), _defineProperty(_classnames, ClassName.TABLE_SELECTED, isTableSelected(view.state.selection)), _classnames)),
570
638
  editorView: view,
@@ -576,7 +644,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
576
644
  isNested: isNested,
577
645
  pluginInjectionApi: pluginInjectionApi,
578
646
  isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
579
- isResizing: isResizing
647
+ isResizing: isResizing,
648
+ tablePreserveWidth: tablePreserveWidth
580
649
  }, /*#__PURE__*/React.createElement("div", {
581
650
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
582
651
  "data-testid": "sticky-sentinel-top"
@@ -587,12 +656,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
587
656
  editorView: view,
588
657
  node: node,
589
658
  getScrollOffset: function getScrollOffset() {
590
- var _this3$wrapper2;
591
- return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.scrollLeft) || 0;
659
+ var _this4$wrapper2;
660
+ return ((_this4$wrapper2 = _this4.wrapper) === null || _this4$wrapper2 === void 0 ? void 0 : _this4$wrapper2.scrollLeft) || 0;
592
661
  },
593
662
  getTableWrapperWidth: function getTableWrapperWidth() {
594
- var _this3$wrapper3;
595
- return ((_this3$wrapper3 = _this3.wrapper) === null || _this3$wrapper3 === void 0 ? void 0 : _this3$wrapper3.clientWidth) || 760;
663
+ var _this4$wrapper3;
664
+ return ((_this4$wrapper3 = _this4.wrapper) === null || _this4$wrapper3 === void 0 ? void 0 : _this4$wrapper3.clientWidth) || 760;
596
665
  }
597
666
  }), /*#__PURE__*/React.createElement("div", {
598
667
  style: shadowStyle(showBeforeShadow),
@@ -607,13 +676,13 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
607
676
  }), /*#__PURE__*/React.createElement("div", {
608
677
  className: classnames(ClassName.TABLE_NODE_WRAPPER),
609
678
  ref: function ref(elem) {
610
- _this3.wrapper = elem;
679
+ _this4.wrapper = elem;
611
680
  if (elem) {
612
- _this3.props.contentDOM(elem);
681
+ _this4.props.contentDOM(elem);
613
682
  var tableElement = elem.querySelector('table');
614
- if (tableElement !== _this3.table) {
615
- _this3.table = tableElement;
616
- _this3.createShadowSentinels(_this3.table);
683
+ if (tableElement !== _this4.table) {
684
+ _this4.table = tableElement;
685
+ _this4.createShadowSentinels(_this4.table);
617
686
  }
618
687
  }
619
688
  }
@@ -43,7 +43,8 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
43
43
  getPos = _ref2.getPos,
44
44
  tableRef = _ref2.tableRef,
45
45
  isResizing = _ref2.isResizing,
46
- pluginInjectionApi = _ref2.pluginInjectionApi;
46
+ pluginInjectionApi = _ref2.pluginInjectionApi,
47
+ tablePreserveWidth = _ref2.tablePreserveWidth;
47
48
  var containerRef = useRef(null);
48
49
  var tableWidthRef = useRef(akEditorDefaultLayoutWidth);
49
50
  var updateContainerHeight = useCallback(function (height) {
@@ -124,7 +125,8 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
124
125
  tableRef: tableRef,
125
126
  displayGuideline: displayGuideline,
126
127
  attachAnalyticsEvent: attachAnalyticsEvent,
127
- displayGapCursor: displayGapCursor
128
+ displayGapCursor: displayGapCursor,
129
+ tablePreserveWidth: tablePreserveWidth
128
130
  };
129
131
  if (getBooleanFF('platform.editor.resizing-table-height-improvement')) {
130
132
  tableResizerProps = _objectSpread(_objectSpread({}, tableResizerProps), {}, {
@@ -162,7 +164,8 @@ export var TableContainer = function TableContainer(_ref3) {
162
164
  tableRef = _ref3.tableRef,
163
165
  isNested = _ref3.isNested,
164
166
  isResizing = _ref3.isResizing,
165
- pluginInjectionApi = _ref3.pluginInjectionApi;
167
+ pluginInjectionApi = _ref3.pluginInjectionApi,
168
+ tablePreserveWidth = _ref3.tablePreserveWidth;
166
169
  if (isTableResizingEnabled && !isNested) {
167
170
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
168
171
  className: className,
@@ -172,7 +175,8 @@ export var TableContainer = function TableContainer(_ref3) {
172
175
  getPos: getPos,
173
176
  tableRef: tableRef,
174
177
  isResizing: isResizing,
175
- pluginInjectionApi: pluginInjectionApi
178
+ pluginInjectionApi: pluginInjectionApi,
179
+ tablePreserveWidth: tablePreserveWidth
176
180
  }, children);
177
181
  }
178
182
  var tableWidth = isBreakoutEnabled ? calcTableWidth(node.attrs.layout, editorWidth) : 'inherit';
@@ -87,7 +87,8 @@ export var TableResizer = function TableResizer(_ref) {
87
87
  tableRef = _ref.tableRef,
88
88
  displayGuideline = _ref.displayGuideline,
89
89
  attachAnalyticsEvent = _ref.attachAnalyticsEvent,
90
- displayGapCursor = _ref.displayGapCursor;
90
+ displayGapCursor = _ref.displayGapCursor,
91
+ tablePreserveWidth = _ref.tablePreserveWidth;
91
92
  var currentGap = useRef(0);
92
93
  // track resizing state - use ref over state to avoid re-render
93
94
  var isResizing = useRef(false);
@@ -195,11 +196,11 @@ export var TableResizer = function TableResizer(_ref) {
195
196
  prevNode: node,
196
197
  start: pos + 1,
197
198
  parentWidth: newWidth
198
- }, editorView.domAtPos.bind(editorView));
199
+ }, editorView.domAtPos.bind(editorView), tablePreserveWidth);
199
200
  updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
200
201
  updateWidth(newWidth);
201
202
  return newWidth;
202
- }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
203
+ }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames, tablePreserveWidth]);
203
204
  var scheduleResize = useMemo(function () {
204
205
  return rafSchd(handleResize);
205
206
  }, [handleResize]);
@@ -235,7 +236,7 @@ export var TableResizer = function TableResizer(_ref) {
235
236
  prevNode: node,
236
237
  start: pos + 1,
237
238
  parentWidth: newWidth
238
- }, editorView.domAtPos.bind(editorView))(tr);
239
+ }, editorView.domAtPos.bind(editorView), tablePreserveWidth)(tr);
239
240
  var scaledNode = tr.doc.nodeAt(pos);
240
241
  (_attachAnalyticsEvent2 = attachAnalyticsEvent(generateResizedPayload({
241
242
  originalNode: node,
@@ -253,7 +254,7 @@ export var TableResizer = function TableResizer(_ref) {
253
254
  onResizeStop();
254
255
  }
255
256
  return newWidth;
256
- }, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
257
+ }, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop, tablePreserveWidth]);
257
258
  var handleTableSizeChangeOnKeypress = useCallback(function (step) {
258
259
  var newWidth = width + step;
259
260
  if (newWidth > maxWidth || newWidth < resizerMinWidth) {
@@ -72,17 +72,24 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
72
72
  _defineProperty(_assertThisInitialized(_this), "hasHoveredRows", false);
73
73
  _this.getPos = props.getPos;
74
74
  _this.eventDispatcher = props.eventDispatcher;
75
+ _this.getEditorFeatureFlags = props.getEditorFeatureFlags;
75
76
  return _this;
76
77
  }
77
78
  _createClass(TableView, [{
78
79
  key: "getContentDOM",
79
80
  value: function getContentDOM() {
80
81
  var rendered = DOMSerializer.renderSpec(document, toDOM(this.node, this.reactComponentProps));
81
- var tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
82
82
  if (rendered.dom) {
83
83
  this.table = rendered.dom;
84
- if (tableInlineWidth) {
85
- handleInlineTableWidth(this.table, tableInlineWidth);
84
+ var _this$getEditorFeatur = this.getEditorFeatureFlags(),
85
+ _this$getEditorFeatur2 = _this$getEditorFeatur.tablePreserveWidth,
86
+ tablePreserveWidth = _this$getEditorFeatur2 === void 0 ? false : _this$getEditorFeatur2;
87
+ // Preserve Table Width cannot have inline width set on the table
88
+ if (!tablePreserveWidth) {
89
+ var tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
90
+ if (tableInlineWidth) {
91
+ handleInlineTableWidth(this.table, tableInlineWidth);
92
+ }
86
93
  }
87
94
  }
88
95
  return rendered;
@@ -180,7 +187,8 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
180
187
  contentDOM: forwardRef,
181
188
  getEditorFeatureFlags: props.getEditorFeatureFlags,
182
189
  dispatchAnalyticsEvent: props.dispatchAnalyticsEvent,
183
- pluginInjectionApi: props.pluginInjectionApi
190
+ pluginInjectionApi: props.pluginInjectionApi,
191
+ tableRef: _this3.table
184
192
  });
185
193
  }
186
194
  });