@atlaskit/editor-plugin-table 7.4.9 → 7.5.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 (180) hide show
  1. package/CHANGELOG.md +6 -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/package.json +2 -2
  150. package/src/commands/column-resize.ts +3 -0
  151. package/src/commands/delete.ts +2 -1
  152. package/src/commands/insert.ts +15 -6
  153. package/src/commands-with-analytics.ts +9 -3
  154. package/src/event-handlers.ts +2 -0
  155. package/src/nodeviews/TableComponent.tsx +91 -5
  156. package/src/nodeviews/TableContainer.tsx +6 -0
  157. package/src/nodeviews/TableResizer.tsx +6 -0
  158. package/src/nodeviews/table.tsx +15 -10
  159. package/src/plugin.tsx +17 -5
  160. package/src/pm-plugins/drag-and-drop/plugin.ts +16 -8
  161. package/src/pm-plugins/keymap.ts +11 -3
  162. package/src/pm-plugins/main.ts +3 -0
  163. package/src/pm-plugins/table-resizing/event-handlers.ts +11 -1
  164. package/src/pm-plugins/table-resizing/utils/colgroup.ts +49 -17
  165. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  166. package/src/pm-plugins/table-resizing/utils/index.ts +8 -1
  167. package/src/pm-plugins/table-resizing/utils/misc.ts +25 -1
  168. package/src/pm-plugins/table-resizing/utils/resize-column.ts +2 -1
  169. package/src/pm-plugins/table-resizing/utils/resize-state.ts +56 -11
  170. package/src/pm-plugins/table-resizing/utils/scale-table.ts +24 -6
  171. package/src/toolbar.tsx +18 -5
  172. package/src/transforms/column-width.ts +33 -11
  173. package/src/transforms/delete-columns.ts +7 -2
  174. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -5
  175. package/src/ui/FloatingContextualMenu/index.tsx +2 -0
  176. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
  177. package/src/ui/FloatingDragMenu/index.tsx +9 -1
  178. package/src/ui/FloatingInsertButton/index.tsx +17 -5
  179. package/src/utils/create.ts +1 -3
  180. package/src/utils/drag-menu.ts +4 -1
@@ -154,8 +154,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
154
154
  name: 'tableKeymap',
155
155
  plugin: function plugin() {
156
156
  var _ref6 = options || {},
157
- dragAndDropEnabled = _ref6.dragAndDropEnabled;
158
- return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled);
157
+ dragAndDropEnabled = _ref6.dragAndDropEnabled,
158
+ getEditorFeatureFlags = _ref6.getEditorFeatureFlags;
159
+ return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, dragAndDropEnabled);
159
160
  }
160
161
  }, {
161
162
  name: 'tableSelectionKeymap',
@@ -196,40 +197,40 @@ var tablesPlugin = function tablesPlugin(_ref) {
196
197
  }, {
197
198
  name: 'tableDragAndDrop',
198
199
  plugin: function plugin(_ref10) {
199
- var dispatch = _ref10.dispatch,
200
- eventDispatcher = _ref10.eventDispatcher,
201
- dispatchAnalyticsEvent = _ref10.dispatchAnalyticsEvent;
202
- return options !== null && options !== void 0 && options.dragAndDropEnabled ? (0, _dragAndDrop.createPlugin)(dispatch, eventDispatcher, editorAnalyticsAPI) : undefined;
200
+ var dispatch = _ref10.dispatch;
201
+ var _ref11 = options || {},
202
+ getEditorFeatureFlags = _ref11.getEditorFeatureFlags;
203
+ return options !== null && options !== void 0 && options.dragAndDropEnabled ? (0, _dragAndDrop.createPlugin)(dispatch, getEditorFeatureFlags, editorAnalyticsAPI) : undefined;
203
204
  }
204
205
  }, {
205
206
  name: 'tableLocalId',
206
- plugin: function plugin(_ref11) {
207
- var dispatch = _ref11.dispatch;
207
+ plugin: function plugin(_ref12) {
208
+ var dispatch = _ref12.dispatch;
208
209
  return (0, _tableLocalId.createPlugin)(dispatch);
209
210
  }
210
211
  }, {
211
212
  name: 'tableWidth',
212
- plugin: function plugin(_ref12) {
213
+ plugin: function plugin(_ref13) {
213
214
  var _options$fullWidthEna;
214
- var dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent,
215
- dispatch = _ref12.dispatch;
215
+ var dispatchAnalyticsEvent = _ref13.dispatchAnalyticsEvent,
216
+ dispatch = _ref13.dispatch;
216
217
  return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) : undefined;
217
218
  }
218
219
  },
219
220
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
220
221
  {
221
222
  name: 'tableOverflowAnalyticsPlugin',
222
- plugin: function plugin(_ref13) {
223
+ plugin: function plugin(_ref14) {
223
224
  var _options$tableResizin;
224
- var dispatch = _ref13.dispatch,
225
- dispatchAnalyticsEvent = _ref13.dispatchAnalyticsEvent;
225
+ var dispatch = _ref14.dispatch,
226
+ dispatchAnalyticsEvent = _ref14.dispatchAnalyticsEvent;
226
227
  return (0, _tableAnalytics.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
227
228
  }
228
229
  }, {
229
230
  name: 'tableAnalyticsPlugin',
230
- plugin: function plugin(_ref14) {
231
- var dispatch = _ref14.dispatch,
232
- dispatchAnalyticsEvent = _ref14.dispatchAnalyticsEvent;
231
+ plugin: function plugin(_ref15) {
232
+ var dispatch = _ref15.dispatch,
233
+ dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
233
234
  return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event') ? (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent) : undefined;
234
235
  }
235
236
  }, {
@@ -260,12 +261,12 @@ var tablesPlugin = function tablesPlugin(_ref) {
260
261
  }
261
262
  return plugins;
262
263
  },
263
- contentComponent: function contentComponent(_ref15) {
264
- var editorView = _ref15.editorView,
265
- popupsMountPoint = _ref15.popupsMountPoint,
266
- popupsBoundariesElement = _ref15.popupsBoundariesElement,
267
- popupsScrollableElement = _ref15.popupsScrollableElement,
268
- dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
264
+ contentComponent: function contentComponent(_ref16) {
265
+ var editorView = _ref16.editorView,
266
+ popupsMountPoint = _ref16.popupsMountPoint,
267
+ popupsBoundariesElement = _ref16.popupsBoundariesElement,
268
+ popupsScrollableElement = _ref16.popupsScrollableElement,
269
+ dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
269
270
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
270
271
  component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
271
272
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -279,30 +280,30 @@ var tablesPlugin = function tablesPlugin(_ref) {
279
280
  stickyHeadersState: _stickyHeaders.pluginKey,
280
281
  dragAndDropState: _dragAndDrop.pluginKey
281
282
  },
282
- render: function render(_ref16) {
283
- var resizingPluginState = _ref16.tableResizingPluginState,
284
- stickyHeadersState = _ref16.stickyHeadersState,
285
- tablePluginState = _ref16.tablePluginState,
286
- tableWidthPluginState = _ref16.tableWidthPluginState,
287
- dragAndDropState = _ref16.dragAndDropState;
283
+ render: function render(_ref17) {
284
+ var resizingPluginState = _ref17.tableResizingPluginState,
285
+ stickyHeadersState = _ref17.stickyHeadersState,
286
+ tablePluginState = _ref17.tablePluginState,
287
+ tableWidthPluginState = _ref17.tableWidthPluginState,
288
+ dragAndDropState = _ref17.dragAndDropState;
288
289
  var state = editorView.state;
289
290
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
290
291
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
291
292
  var isResizing = isColumnResizing || isTableResizing;
292
- var _ref17 = tablePluginState,
293
- tableNode = _ref17.tableNode,
294
- tablePos = _ref17.tablePos,
295
- targetCellPosition = _ref17.targetCellPosition,
296
- isContextualMenuOpen = _ref17.isContextualMenuOpen,
297
- layout = _ref17.layout,
298
- tableRef = _ref17.tableRef,
299
- pluginConfig = _ref17.pluginConfig,
300
- insertColumnButtonIndex = _ref17.insertColumnButtonIndex,
301
- insertRowButtonIndex = _ref17.insertRowButtonIndex,
302
- isHeaderColumnEnabled = _ref17.isHeaderColumnEnabled,
303
- isHeaderRowEnabled = _ref17.isHeaderRowEnabled,
304
- isDragAndDropEnabled = _ref17.isDragAndDropEnabled,
305
- tableWrapperTarget = _ref17.tableWrapperTarget;
293
+ var _ref18 = tablePluginState,
294
+ tableNode = _ref18.tableNode,
295
+ tablePos = _ref18.tablePos,
296
+ targetCellPosition = _ref18.targetCellPosition,
297
+ isContextualMenuOpen = _ref18.isContextualMenuOpen,
298
+ layout = _ref18.layout,
299
+ tableRef = _ref18.tableRef,
300
+ pluginConfig = _ref18.pluginConfig,
301
+ insertColumnButtonIndex = _ref18.insertColumnButtonIndex,
302
+ insertRowButtonIndex = _ref18.insertRowButtonIndex,
303
+ isHeaderColumnEnabled = _ref18.isHeaderColumnEnabled,
304
+ isHeaderRowEnabled = _ref18.isHeaderRowEnabled,
305
+ isDragAndDropEnabled = _ref18.isDragAndDropEnabled,
306
+ tableWrapperTarget = _ref18.tableWrapperTarget;
306
307
  var allowControls = pluginConfig.allowControls;
307
308
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
308
309
  var LayoutContent = options && !options.tableResizingEnabled && (0, _utils2.isLayoutSupported)(state) && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
@@ -343,7 +344,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
343
344
  hasStickyHeaders: stickyHeader && stickyHeader.sticky,
344
345
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
345
346
  editorAnalyticsAPI: editorAnalyticsAPI,
346
- getEditorContainerWidth: defaultGetEditorContainerWidth
347
+ getEditorContainerWidth: defaultGetEditorContainerWidth,
348
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
347
349
  }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/_react.default.createElement(_FloatingContextualMenu.default, {
348
350
  editorView: editorView,
349
351
  mountPoint: popupsMountPoint,
@@ -367,7 +369,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
367
369
  getEditorContainerWidth: defaultGetEditorContainerWidth,
368
370
  editorAnalyticsAPI: editorAnalyticsAPI,
369
371
  stickyHeaders: stickyHeader,
370
- pluginConfig: pluginConfig
372
+ pluginConfig: pluginConfig,
373
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
371
374
  }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/_react.default.createElement(_FloatingDeleteButton.default, {
372
375
  editorView: editorView,
373
376
  selection: editorView.state.selection,
@@ -383,8 +386,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
383
386
  }));
384
387
  },
385
388
  pluginsOptions: {
386
- quickInsert: function quickInsert(_ref18) {
387
- var formatMessage = _ref18.formatMessage;
389
+ quickInsert: function quickInsert(_ref19) {
390
+ var formatMessage = _ref19.formatMessage;
388
391
  return [{
389
392
  id: 'table',
390
393
  title: formatMessage(_messages.toolbarInsertBlockMessages.table),
@@ -23,7 +23,7 @@ var _consts = require("./consts");
23
23
  var _pluginFactory2 = require("./plugin-factory");
24
24
  var _pluginKey2 = require("./plugin-key");
25
25
  var _monitor = require("./utils/monitor");
26
- var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
26
+ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI, getEditorFeatureFlags) {
27
27
  var editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
28
28
  var rowAutoScrollers = editorPageScrollContainer ? [(0, _adapter.monitorForElements)({
29
29
  canMonitor: function canMonitor(_ref) {
@@ -153,7 +153,10 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
153
153
  tableRef = _getTablePluginState3.tableRef,
154
154
  tableNode = _getTablePluginState3.tableNode;
155
155
  if (tableRef && tableNode) {
156
- (0, _utils3.insertColgroupFromNode)(tableRef, tableNode);
156
+ var _ref8 = (getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) || {},
157
+ _ref8$tablePreserveWi = _ref8.tablePreserveWidth,
158
+ tablePreserveWidth = _ref8$tablePreserveWi === void 0 ? false : _ref8$tablePreserveWi;
159
+ (0, _utils3.insertColgroupFromNode)(tableRef, tableNode, tablePreserveWidth);
157
160
  }
158
161
  }
159
162
  editorView.focus();
@@ -161,7 +164,7 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
161
164
  }
162
165
  })]));
163
166
  };
164
- var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventDispatcher, editorAnalyticsAPI) {
167
+ var createPlugin = exports.createPlugin = function createPlugin(dispatch, getEditorFeatureFlags, editorAnalyticsAPI) {
165
168
  return new _safePlugin.SafePlugin({
166
169
  state: (0, _pluginFactory2.createPluginState)(dispatch, function (state) {
167
170
  return {
@@ -229,7 +232,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
229
232
  },
230
233
  view: function view(editorView) {
231
234
  return {
232
- destroy: destroyFn(editorView, editorAnalyticsAPI)
235
+ destroy: destroyFn(editorView, editorAnalyticsAPI, getEditorFeatureFlags)
233
236
  };
234
237
  },
235
238
  props: {
@@ -239,7 +242,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
239
242
  return decorationSet;
240
243
  },
241
244
  handleKeyDown: function handleKeyDown(view, event) {
242
- var _ref8;
245
+ var _ref9;
243
246
  var tr = view.state.tr;
244
247
  var keysToTrapWhen = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
245
248
 
@@ -260,7 +263,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
260
263
  return true;
261
264
  }
262
265
  }
263
- var isDragHandleFocused = ['drag-handle-button-row', 'drag-handle-button-column'].includes((_ref8 = event.target || null) === null || _ref8 === void 0 ? void 0 : _ref8.id);
266
+ var isDragHandleFocused = ['drag-handle-button-row', 'drag-handle-button-column'].includes((_ref9 = event.target || null) === null || _ref9 === void 0 ? void 0 : _ref9.id);
264
267
  var keysToTrap = ['Enter', ' '];
265
268
  var _getPluginState3 = (0, _pluginFactory2.getPluginState)(view.state),
266
269
  isDragMenuOpen = _getPluginState3.isDragMenuOpen;
@@ -27,7 +27,7 @@ var createTableWithAnalytics = function createTableWithAnalytics(editorAnalytics
27
27
  eventType: _analytics.EVENT_TYPE.TRACK
28
28
  })(editorAnalyticsAPI)((0, _commands2.createTable)());
29
29
  };
30
- function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
30
+ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, dragAndDropEnabled) {
31
31
  var list = {};
32
32
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.nextCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI)(1), list);
33
33
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.previousCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI)(-1), list);
@@ -59,11 +59,14 @@ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEn
59
59
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteRow.common, (0, _commandsWithAnalytics.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut)(editorAnalyticsAPI), list);
60
60
  }
61
61
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-column-resizing_emcvz')) {
62
+ var _ref = getEditorFeatureFlags ? getEditorFeatureFlags() : {},
63
+ _ref$tablePreserveWid = _ref.tablePreserveWidth,
64
+ tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
62
65
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.startColumnResizing.common, _columnResize.initiateKeyboardColumnResizing, list);
63
66
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, (0, _columnResize.activateNextResizeArea)(1), list);
64
67
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, (0, _columnResize.activateNextResizeArea)(-1), list);
65
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.decreaseMediaSize.common, (0, _columnResize.changeColumnWidthByStep)(-10, getEditorContainerWidth), list);
66
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.increaseMediaSize.common, (0, _columnResize.changeColumnWidthByStep)(10, getEditorContainerWidth), list);
68
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.decreaseMediaSize.common, (0, _columnResize.changeColumnWidthByStep)(-10, getEditorContainerWidth, tablePreserveWidth), list);
69
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.increaseMediaSize.common, (0, _columnResize.changeColumnWidthByStep)(10, getEditorContainerWidth, tablePreserveWidth), list);
67
70
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.escape.common, (0, _columnResize.stopKeyboardColumnResizing)(), list);
68
71
  }
69
72
  return (0, _keymap.keymap)(list);
@@ -95,9 +95,12 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
95
95
  }
96
96
  });
97
97
  }
98
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
99
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
100
+ tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
98
101
  if (tr) {
99
102
  // "fixTables" removes empty rows as we don't allow that in schema
100
- var updatedTr = (0, _eventHandlers.handleCut)(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
103
+ var updatedTr = (0, _eventHandlers.handleCut)(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined, tablePreserveWidth);
101
104
  return (0, _transforms2.fixTables)(updatedTr) || updatedTr;
102
105
  }
103
106
  if (transactions.find(function (tr) {
@@ -25,6 +25,9 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
25
25
  dispatch = view.dispatch;
26
26
  var editorDisabled = !view.editable;
27
27
  var domAtPos = view.domAtPos.bind(view);
28
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
29
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
30
+ tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
28
31
  if (editorDisabled || localResizeHandlePos === null || !(0, _utils3.pointsAtCell)(state.doc.resolve(localResizeHandlePos))) {
29
32
  return false;
30
33
  }
@@ -70,7 +73,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
70
73
  table: originalTable,
71
74
  tableRef: dom,
72
75
  start: start,
73
- domAtPos: domAtPos
76
+ domAtPos: domAtPos,
77
+ tablePreserveWidth: tablePreserveWidth
74
78
  });
75
79
  if ((0, _commands.evenColumns)({
76
80
  resizeState: resizeState,
@@ -142,7 +146,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
142
146
  var selectedColumns = selectionRect ? (0, _utils2.getSelectedColumnIndexes)(selectionRect) : [];
143
147
  // only selected (or selected - 1) columns should be distributed
144
148
  var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
145
- var newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined);
149
+ var newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined, tablePreserveWidth);
146
150
  tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
147
151
  if (colIndex === map.width - 1) {
148
152
  var mouseUpTime = event.timeStamp;
@@ -190,7 +194,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
190
194
  var table = $cell.node(-1);
191
195
  var map = _tableMap.TableMap.get(table);
192
196
  var colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
193
- (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - dragging.startX, dom);
197
+ (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - dragging.startX, dom, undefined, tablePreserveWidth);
194
198
  (0, _utils3.updateControls)()(state);
195
199
  }
196
200
  window.addEventListener('mouseup', finish);
@@ -11,6 +11,7 @@ var _utils = require("@atlaskit/editor-common/utils");
11
11
  var _model = require("@atlaskit/editor-prosemirror/model");
12
12
  var _tableMap = require("@atlaskit/editor-tables/table-map");
13
13
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
+ var _consts = require("./consts");
14
15
  /**
15
16
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
16
17
  * than the table and table wrapper elements. This is necessary as there is no longer
@@ -20,7 +21,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var getColWidthFix = exports.getColWidthFix = function getColWidthFix(colwidth, tableColumnCount) {
21
22
  return colwidth - 1 / tableColumnCount;
22
23
  };
23
- var generateColgroup = exports.generateColgroup = function generateColgroup(table) {
24
+ var generateColgroup = exports.generateColgroup = function generateColgroup(table, tableRef) {
24
25
  var cols = [];
25
26
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
26
27
  var map = _tableMap.TableMap.get(table);
@@ -29,11 +30,27 @@ var generateColgroup = exports.generateColgroup = function generateColgroup(tabl
29
30
  if (Array.isArray(cell.attrs.colwidth)) {
30
31
  // We slice here to guard against our colwidth array having more entries
31
32
  // Than the we actually span. We'll patch the document at a later point.
32
- cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
33
- cols.push(['col', {
34
- style: "width: ".concat(getColWidthFix(width ? Math.max(width, _styles.tableCellMinWidth) : _styles.tableCellMinWidth, map.width), "px;")
35
- }]);
36
- });
33
+ if (tableRef) {
34
+ var _tableRef$parentEleme;
35
+ var tableWidth = table.attrs && table.attrs.width;
36
+ var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
37
+ var scalePercent = renderWidth / tableWidth;
38
+ scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
39
+ cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
40
+ var fixedColWidth = getColWidthFix(width, map.width);
41
+ var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
42
+ var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
43
+ cols.push(['col', {
44
+ style: "width: ".concat(finalWidth, "px;")
45
+ }]);
46
+ });
47
+ } else {
48
+ cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
49
+ cols.push(['col', {
50
+ style: "width: ".concat(getColWidthFix(width ? Math.max(width, _styles.tableCellMinWidth) : _styles.tableCellMinWidth, map.width), "px;")
51
+ }]);
52
+ });
53
+ }
37
54
  } else {
38
55
  // When we have merged cells on the first row (firstChild),
39
56
  // We want to ensure we're creating the appropriate amount of
@@ -73,12 +90,16 @@ var generateColgroup = exports.generateColgroup = function generateColgroup(tabl
73
90
  return cols;
74
91
  };
75
92
  var insertColgroupFromNode = exports.insertColgroupFromNode = function insertColgroupFromNode(tableRef, table) {
93
+ var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
94
+ var shouldRemove = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
76
95
  var colgroup = tableRef.querySelector('colgroup');
77
- if (colgroup) {
96
+ if (colgroup && shouldRemove) {
78
97
  tableRef.removeChild(colgroup);
79
98
  }
80
- colgroup = renderColgroupFromNode(table);
81
- tableRef.insertBefore(colgroup, tableRef.firstChild);
99
+ colgroup = renderColgroupFromNode(table, tablePreserveWidth ? tableRef : undefined);
100
+ if (shouldRemove) {
101
+ tableRef.insertBefore(colgroup, tableRef.firstChild);
102
+ }
82
103
  return colgroup.children;
83
104
  };
84
105
  var hasTableBeenResized = exports.hasTableBeenResized = function hasTableBeenResized(table) {
@@ -100,8 +121,8 @@ var isMinCellWidthTable = exports.isMinCellWidthTable = function isMinCellWidthT
100
121
  });
101
122
  return isTableMinCellWidth;
102
123
  };
103
- function renderColgroupFromNode(table) {
104
- var rendered = _model.DOMSerializer.renderSpec(document, ['colgroup', {}].concat((0, _toConsumableArray2.default)(generateColgroup(table))));
124
+ function renderColgroupFromNode(table, maybeTableRef) {
125
+ var rendered = _model.DOMSerializer.renderSpec(document, ['colgroup', {}].concat((0, _toConsumableArray2.default)(generateColgroup(table, maybeTableRef))));
105
126
  return rendered.dom;
106
127
  }
107
128
  var getColgroupChildrenLength = exports.getColgroupChildrenLength = function getColgroupChildrenLength(table) {
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TABLE_MAX_WIDTH = exports.COLUMN_MIN_WIDTH = void 0;
6
+ exports.TABLE_MAX_WIDTH = exports.TABLE_DEFAULT_WIDTH = exports.MAX_SCALING_PERCENT = exports.COLUMN_MIN_WIDTH = void 0;
7
7
  var COLUMN_MIN_WIDTH = exports.COLUMN_MIN_WIDTH = 48;
8
- var TABLE_MAX_WIDTH = exports.TABLE_MAX_WIDTH = 1800;
8
+ var TABLE_DEFAULT_WIDTH = exports.TABLE_DEFAULT_WIDTH = 760;
9
+ var TABLE_MAX_WIDTH = exports.TABLE_MAX_WIDTH = 1800;
10
+ var MAX_SCALING_PERCENT = exports.MAX_SCALING_PERCENT = 0.3;
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "COLUMN_MIN_WIDTH", {
9
9
  return _consts.COLUMN_MIN_WIDTH;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "MAX_SCALING_PERCENT", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _consts.MAX_SCALING_PERCENT;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "TABLE_DEFAULT_WIDTH", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _consts.TABLE_DEFAULT_WIDTH;
22
+ }
23
+ });
12
24
  Object.defineProperty(exports, "TABLE_MAX_WIDTH", {
13
25
  enumerable: true,
14
26
  get: function get() {
@@ -123,6 +135,18 @@ Object.defineProperty(exports, "getResizeState", {
123
135
  return _resizeState.getResizeState;
124
136
  }
125
137
  });
138
+ Object.defineProperty(exports, "getTableContainerElement", {
139
+ enumerable: true,
140
+ get: function get() {
141
+ return _misc.getTableContainerElement;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "getTableElementWidth", {
145
+ enumerable: true,
146
+ get: function get() {
147
+ return _misc.getTableElementWidth;
148
+ }
149
+ });
126
150
  Object.defineProperty(exports, "getTableMaxWidth", {
127
151
  enumerable: true,
128
152
  get: function get() {
@@ -7,7 +7,7 @@ exports.currentColWidth = currentColWidth;
7
7
  exports.domCellAround = domCellAround;
8
8
  exports.getDefaultLayoutMaxWidth = getDefaultLayoutMaxWidth;
9
9
  exports.getLayoutSize = getLayoutSize;
10
- exports.getTableMaxWidth = void 0;
10
+ exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElement = void 0;
11
11
  exports.pointsAtCell = pointsAtCell;
12
12
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
13
13
  var _styles = require("@atlaskit/editor-common/styles");
@@ -15,6 +15,7 @@ var _ui = require("@atlaskit/editor-common/ui");
15
15
  var _utils = require("@atlaskit/editor-common/utils");
16
16
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
17
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
+ var _colgroup = require("./colgroup");
18
19
  // Translates named layouts in number values.
19
20
  function getLayoutSize(tableLayout) {
20
21
  var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -80,4 +81,22 @@ var getTableMaxWidth = exports.getTableMaxWidth = function getTableMaxWidth(_ref
80
81
  maxWidth -= _editorSharedStyles.akEditorTableNumberColumnWidth;
81
82
  }
82
83
  return maxWidth;
84
+ };
85
+
86
+ /**
87
+ *
88
+ * @param table
89
+ * @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
90
+ */
91
+ var getTableElementWidth = exports.getTableElementWidth = function getTableElementWidth(table) {
92
+ if ((0, _colgroup.hasTableBeenResized)(table)) {
93
+ // TODO: is there a scenario where ADF columns are SMALLER than container width?
94
+ return (0, _utils.calcTableColumnWidths)(table).reduce(function (sum, width) {
95
+ return sum + width;
96
+ }, 0);
97
+ }
98
+ return getTableContainerElement(table);
99
+ };
100
+ var getTableContainerElement = exports.getTableContainerElement = function getTableContainerElement(table) {
101
+ return (0, _nodeWidth.getTableContainerWidth)(table);
83
102
  };
@@ -9,7 +9,8 @@ var _resizeState = require("./resize-state");
9
9
  // Resize a given column by an amount from the current state
10
10
 
11
11
  var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, selectedColumns) {
12
+ var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
12
13
  var newState = amount > 0 ? (0, _resizeLogic.growColumn)(resizeState, colIndex, amount, selectedColumns) : amount < 0 ? (0, _resizeLogic.shrinkColumn)(resizeState, colIndex, amount, selectedColumns) : resizeState;
13
- (0, _resizeState.updateColgroup)(newState, tableRef);
14
+ (0, _resizeState.updateColgroup)(newState, tableRef, tablePreserveWidth);
14
15
  return newState;
15
16
  };
@@ -14,6 +14,7 @@ var _colgroup = require("./colgroup");
14
14
  var _columnState = require("./column-state");
15
15
  var _dom = require("./dom");
16
16
  var _misc = require("./misc");
17
+ var _index = require("./index");
17
18
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
19
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
20
  var getResizeState = exports.getResizeState = function getResizeState(_ref) {
@@ -22,7 +23,10 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
22
23
  table = _ref.table,
23
24
  tableRef = _ref.tableRef,
24
25
  start = _ref.start,
25
- domAtPos = _ref.domAtPos;
26
+ domAtPos = _ref.domAtPos,
27
+ _ref$tablePreserveWid = _ref.tablePreserveWidth,
28
+ tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
29
+ // If the table has been resized, we can use the column widths from the table node
26
30
  if ((0, _colgroup.hasTableBeenResized)(table)) {
27
31
  var _cols = (0, _utils.calcTableColumnWidths)(table).map(function (width, index) {
28
32
  return {
@@ -46,10 +50,22 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
46
50
  overflow: _overflow
47
51
  };
48
52
  }
53
+ var shouldReinsertColgroup = !tablePreserveWidth;
49
54
 
50
55
  // Getting the resize state from DOM
51
- var colgroupChildren = (0, _colgroup.insertColgroupFromNode)(tableRef, table);
56
+ var colgroupChildren = (0, _colgroup.insertColgroupFromNode)(tableRef, table, tablePreserveWidth, shouldReinsertColgroup // don't reinsert colgroup when preserving table width - this causes widths to jump
57
+ );
58
+
52
59
  var cols = Array.from(colgroupChildren).map(function (_, index) {
60
+ // If the table hasn't been resized and we have a table width attribute, we can use it
61
+ // to calculate the widths of the columns
62
+ if (tablePreserveWidth && table.attrs.width) {
63
+ return {
64
+ index: index,
65
+ width: table.attrs.width / colgroupChildren.length,
66
+ minWidth: 48
67
+ };
68
+ }
53
69
  var cellsRefs = (0, _columnState.getCellsRefsInColumn)(index, table, start, domAtPos);
54
70
  return (0, _columnState.getColumnStateFromDOM)(cellsRefs, index, minWidth);
55
71
  });
@@ -70,18 +86,41 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
70
86
  };
71
87
 
72
88
  // updates Colgroup DOM node with new widths
73
- var updateColgroup = exports.updateColgroup = function updateColgroup(state, tableRef) {
89
+ var updateColgroup = exports.updateColgroup = function updateColgroup(state, tableRef, tablePreserveWidth) {
74
90
  var cols = tableRef.querySelectorAll('col');
75
91
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
76
92
  var columnsCount = cols.length;
77
- state.cols.filter(function (column) {
78
- return column && !!column.width;
79
- }) // if width is 0, we dont want to apply that.
80
- .forEach(function (column, i) {
81
- if (cols[i]) {
82
- cols[i].style.width = "".concat((0, _colgroup.getColWidthFix)(column.width, columnsCount), "px");
93
+ if (tablePreserveWidth) {
94
+ var _tableRef$dataset;
95
+ var tableWidth = parseInt(((_tableRef$dataset = tableRef.dataset) === null || _tableRef$dataset === void 0 ? void 0 : _tableRef$dataset.tableWidth) || ''); // TODO - get this value from the table node, not the dom
96
+ if (tableWidth) {
97
+ var _tableRef$parentEleme;
98
+ var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || _index.TABLE_DEFAULT_WIDTH;
99
+ var scalePercent = renderWidth / tableWidth;
100
+ scalePercent = Math.max(scalePercent, 1 - _index.MAX_SCALING_PERCENT);
101
+ state.cols.filter(function (column) {
102
+ return column && !!column.width;
103
+ }) // if width is 0, we dont want to apply that.
104
+ .forEach(function (column, i) {
105
+ var fixedColWidth = (0, _colgroup.getColWidthFix)(column.width, columnsCount);
106
+ var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
107
+ var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
108
+ // we aren't handling the remaining pixels here when the 48px min width is reached
109
+ if (cols[i]) {
110
+ cols[i].style.width = "".concat(finalWidth, "px");
111
+ }
112
+ });
83
113
  }
84
- });
114
+ } else {
115
+ state.cols.filter(function (column) {
116
+ return column && !!column.width;
117
+ }) // if width is 0, we dont want to apply that.
118
+ .forEach(function (column, i) {
119
+ if (cols[i]) {
120
+ cols[i].style.width = "".concat((0, _colgroup.getColWidthFix)(column.width, columnsCount), "px");
121
+ }
122
+ });
123
+ }
85
124
  } else {
86
125
  state.cols.filter(function (column) {
87
126
  return column && !!column.width;
@@ -269,6 +308,7 @@ var normaliseTableLayout = exports.normaliseTableLayout = function normaliseTabl
269
308
  }
270
309
  };
271
310
  var getNewResizeStateFromSelectedColumns = exports.getNewResizeStateFromSelectedColumns = function getNewResizeStateFromSelectedColumns(rect, state, domAtPos, getEditorContainerWidth) {
311
+ var tablePreserveWidth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
272
312
  // Fail early so that we don't do complex calculations for no reason
273
313
  var numColumnsSelected = rect.right - rect.left;
274
314
  if (numColumnsSelected <= 1) {
@@ -305,7 +345,8 @@ var getNewResizeStateFromSelectedColumns = exports.getNewResizeStateFromSelected
305
345
  table: table.node,
306
346
  tableRef: tableRef,
307
347
  start: table.start,
308
- domAtPos: domAtPos
348
+ domAtPos: domAtPos,
349
+ tablePreserveWidth: tablePreserveWidth
309
350
  });
310
351
  var newResizeState = evenSelectedColumnsWidths(resizeState, rect);
311
352
  var widthsBefore = resizeState.widths;