@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
@@ -20,7 +20,7 @@ function addColumnAtCustomStep(column) {
20
20
  return tr;
21
21
  };
22
22
  }
23
- export function addColumnAt(getEditorContainerWidth) {
23
+ export function addColumnAt(getEditorContainerWidth, tablePreserveWidth = false) {
24
24
  return (column, allowAddColumnCustomStep = false, view) => {
25
25
  return tr => {
26
26
  let updatedTr = tr;
@@ -32,7 +32,7 @@ export function addColumnAt(getEditorContainerWidth) {
32
32
  const table = findTable(updatedTr.selection);
33
33
  if (table) {
34
34
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
35
- updatedTr = rescaleColumns()(table, view)(updatedTr);
35
+ updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
36
36
  }
37
37
  if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event') && view) {
38
38
  updatedTr = updateRowOrColumnMovedTransform({
@@ -49,14 +49,14 @@ export function addColumnAt(getEditorContainerWidth) {
49
49
 
50
50
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
51
51
  // Command to add a column before the column with the selection.
52
- export const addColumnBefore = getEditorContainerWidth => (state, dispatch, view) => {
52
+ export const addColumnBefore = (getEditorContainerWidth, tablePreserveWidth = false) => (state, dispatch, view) => {
53
53
  const table = findTable(state.selection);
54
54
  if (!table) {
55
55
  return false;
56
56
  }
57
57
  if (dispatch) {
58
58
  let rect = selectedRect(state);
59
- dispatch(addColumnAt(getEditorContainerWidth)(rect.left, getAllowAddColumnCustomStep(state), view)(state.tr));
59
+ dispatch(addColumnAt(getEditorContainerWidth, tablePreserveWidth)(rect.left, getAllowAddColumnCustomStep(state), view)(state.tr));
60
60
  }
61
61
  return true;
62
62
  };
@@ -74,8 +74,8 @@ export const addColumnAfter = getEditorContainerWidth => (state, dispatch, view)
74
74
  }
75
75
  return true;
76
76
  };
77
- export const insertColumn = getEditorContainerWidth => column => (state, dispatch, view) => {
78
- let tr = addColumnAt(getEditorContainerWidth)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
77
+ export const insertColumn = (getEditorContainerWidth, tablePreserveWidth = false) => column => (state, dispatch, view) => {
78
+ let tr = addColumnAt(getEditorContainerWidth, tablePreserveWidth)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
79
79
  const table = findTable(tr.selection);
80
80
  if (!table) {
81
81
  return false;
@@ -167,7 +167,7 @@ export const insertRowWithAnalytics = editorAnalyticsAPI => (inputMethod, option
167
167
  eventType: EVENT_TYPE.TRACK
168
168
  };
169
169
  })(editorAnalyticsAPI)(insertRow(options.index, options.moveCursorToInsertedRow));
170
- export const insertColumnWithAnalytics = (getEditorContainerWidth, editorAnalyticsAPI) => (inputMethod, position) => withEditorAnalyticsAPI(state => {
170
+ export const insertColumnWithAnalytics = (getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => (inputMethod, position) => withEditorAnalyticsAPI(state => {
171
171
  const {
172
172
  totalRowCount,
173
173
  totalColumnCount
@@ -184,7 +184,7 @@ export const insertColumnWithAnalytics = (getEditorContainerWidth, editorAnalyti
184
184
  },
185
185
  eventType: EVENT_TYPE.TRACK
186
186
  };
187
- })(editorAnalyticsAPI)(insertColumn(getEditorContainerWidth)(position));
187
+ })(editorAnalyticsAPI)(insertColumn(getEditorContainerWidth, tablePreserveWidth)(position));
188
188
  export const deleteRowsWithAnalytics = editorAnalyticsAPI => (inputMethod, rect, isHeaderRowRequired) => withEditorAnalyticsAPI(({
189
189
  selection
190
190
  }) => {
@@ -211,7 +211,7 @@ export const deleteRowsWithAnalytics = editorAnalyticsAPI => (inputMethod, rect,
211
211
  }
212
212
  return true;
213
213
  });
214
- export const deleteColumnsWithAnalytics = editorAnalyticsAPI => (inputMethod, rect) => withEditorAnalyticsAPI(({
214
+ export const deleteColumnsWithAnalytics = (editorAnalyticsAPI, tablePreserveWidth = false) => (inputMethod, rect) => withEditorAnalyticsAPI(({
215
215
  selection
216
216
  }) => {
217
217
  const {
@@ -231,7 +231,7 @@ export const deleteColumnsWithAnalytics = editorAnalyticsAPI => (inputMethod, re
231
231
  },
232
232
  eventType: EVENT_TYPE.TRACK
233
233
  };
234
- })(editorAnalyticsAPI)(deleteColumnsCommand(rect));
234
+ })(editorAnalyticsAPI)(deleteColumnsCommand(rect, tablePreserveWidth));
235
235
  export const deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = editorAnalyticsAPI => (state, dispatch) => {
236
236
  const {
237
237
  selection
@@ -345,7 +345,7 @@ export function handleTripleClick(view, pos) {
345
345
  }
346
346
  return false;
347
347
  }
348
- export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI, editorView) => {
348
+ export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI, editorView, tablePreserveWidth = false) => {
349
349
  const oldSelection = oldState.tr.selection;
350
350
  let {
351
351
  tr
@@ -394,7 +394,7 @@ export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI, editorV
394
394
  } = getPluginState(newState);
395
395
  tr = deleteRows(rect, isHeaderRowRequired)(tr);
396
396
  } else if (tr.selection.isColSelection()) {
397
- tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView)(tr);
397
+ tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView, tablePreserveWidth)(tr);
398
398
  }
399
399
  }
400
400
  }
@@ -6,7 +6,7 @@ import rafSchedule from 'raf-schd';
6
6
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
7
7
  import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
8
8
  import { tableMarginSides } from '@atlaskit/editor-common/styles';
9
- import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
9
+ import { browser, calcTableColumnWidths, isValidPosition } from '@atlaskit/editor-common/utils';
10
10
  import { MAX_BROWSER_SCROLLBAR_HEIGHT, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
11
11
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
12
12
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -16,7 +16,7 @@ import { autoScrollerFactory } from '../pm-plugins/drag-and-drop/utils';
16
16
  import { getPluginState } from '../pm-plugins/plugin-factory';
17
17
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
18
18
  import { META_KEYS } from '../pm-plugins/table-analytics';
19
- import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scaleTable } from '../pm-plugins/table-resizing/utils';
19
+ import { COLUMN_MIN_WIDTH, getLayoutSize, getResizeState, insertColgroupFromNode, scaleTable, updateColgroup } from '../pm-plugins/table-resizing/utils';
20
20
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
21
21
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
22
22
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
@@ -160,7 +160,8 @@ class TableComponent extends React.Component {
160
160
  getNode,
161
161
  getPos,
162
162
  containerWidth,
163
- options
163
+ options,
164
+ getEditorFeatureFlags
164
165
  } = this.props;
165
166
  const node = getNode();
166
167
  const {
@@ -176,6 +177,9 @@ class TableComponent extends React.Component {
176
177
  width
177
178
  } = containerWidth;
178
179
  this.scaleTableDebounced.cancel();
180
+ const {
181
+ tablePreserveWidth = false
182
+ } = getEditorFeatureFlags();
179
183
  const tr = scaleTable(this.table, {
180
184
  ...scaleOptions,
181
185
  node,
@@ -184,7 +188,7 @@ class TableComponent extends React.Component {
184
188
  containerWidth: width,
185
189
  previousContainerWidth: this.containerWidth.width || width,
186
190
  ...options
187
- }, domAtPos)(state.tr);
191
+ }, domAtPos, tablePreserveWidth)(state.tr);
188
192
  dispatch(tr);
189
193
  });
190
194
  _defineProperty(this, "setTimerToSendInitialOverflowCaptured", isOverflowing => {
@@ -388,6 +392,62 @@ class TableComponent extends React.Component {
388
392
  clearTimeout(this.initialOverflowCaptureTimerId);
389
393
  }
390
394
  }
395
+ handleColgroupUpdates() {
396
+ var _this$containerWidth;
397
+ const {
398
+ getNode,
399
+ containerWidth,
400
+ isResizing,
401
+ view,
402
+ getPos,
403
+ tableRef
404
+ } = this.props;
405
+ if (!tableRef) {
406
+ return;
407
+ }
408
+ const TABLE_MARGIN = 76;
409
+
410
+ // Remove any widths styles after resizing preview is completed
411
+ tableRef.style.width = '';
412
+ const tableRenderWidth = containerWidth.width - TABLE_MARGIN;
413
+ const tableNode = getNode();
414
+ const start = getPos() || 0;
415
+ const depth = view.state.doc.resolve(start).depth;
416
+
417
+ // TODO - remove this when support is added for nested tables
418
+ if (depth !== 0) {
419
+ return;
420
+ }
421
+ const {
422
+ width: tableNodeWidth
423
+ } = tableNode.attrs;
424
+ const tableColumnWidths = calcTableColumnWidths(tableNode);
425
+ const shouldTableScale = tableRenderWidth < tableNodeWidth;
426
+ let isTableColumnWidthsSame = false;
427
+ if (this.tableColumnWidths) {
428
+ isTableColumnWidthsSame = tableColumnWidths === null || tableColumnWidths === void 0 ? void 0 : tableColumnWidths.every((width, index) => width === this.tableColumnWidths[index]);
429
+ }
430
+ const {
431
+ width: containerWidthValue
432
+ } = containerWidth;
433
+ const isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
434
+ if (shouldTableScale && !isResizing && (!isTableColumnWidthsSame || isWidthChanged)) {
435
+ const resizeState = getResizeState({
436
+ minWidth: COLUMN_MIN_WIDTH,
437
+ maxSize: tableRenderWidth,
438
+ table: tableNode,
439
+ tableRef: this.table,
440
+ start,
441
+ domAtPos: view.domAtPos,
442
+ tablePreserveWidth: true
443
+ });
444
+ requestAnimationFrame(() => {
445
+ updateColgroup(resizeState, this.table, true);
446
+ });
447
+ this.tableColumnWidths = tableColumnWidths;
448
+ this.containerWidth = containerWidth;
449
+ }
450
+ }
391
451
  componentDidUpdate(_, prevState) {
392
452
  var _this$wrapper;
393
453
  const {
@@ -396,12 +456,19 @@ class TableComponent extends React.Component {
396
456
  isMediaFullscreen,
397
457
  allowColumnResizing,
398
458
  isResizing,
399
- options
459
+ options,
460
+ getEditorFeatureFlags
400
461
  } = this.props;
401
462
  const {
402
463
  isInDanger
403
464
  } = getPluginState(view.state);
465
+ const {
466
+ tablePreserveWidth = false
467
+ } = getEditorFeatureFlags();
404
468
  const table = findTable(view.state.selection);
469
+ if (tablePreserveWidth) {
470
+ this.handleColgroupUpdates();
471
+ }
405
472
  if (isInDanger && !table) {
406
473
  clearHoverSelection()(view.state, view.dispatch);
407
474
  }
@@ -438,7 +505,7 @@ class TableComponent extends React.Component {
438
505
  } = this.props;
439
506
  const shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || tablesHaveDifferentNoOfColumns(currentTable, previousTable) && isResizing;
440
507
  if (shouldRecreateResizeCols) {
441
- recreateResizeColsByNode(this.table, currentTable);
508
+ insertColgroupFromNode(this.table, currentTable, tablePreserveWidth);
442
509
  }
443
510
  updateControls()(view.state);
444
511
  }
@@ -568,7 +635,8 @@ class TableComponent extends React.Component {
568
635
  const isNested = isTableNested(view.state, tablePos);
569
636
  const 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;
570
637
  const {
571
- stickyScrollbar
638
+ stickyScrollbar,
639
+ tablePreserveWidth
572
640
  } = getEditorFeatureFlags();
573
641
  return /*#__PURE__*/React.createElement(TableContainer, {
574
642
  className: classnames(ClassName.TABLE_CONTAINER, {
@@ -586,7 +654,8 @@ class TableComponent extends React.Component {
586
654
  isNested: isNested,
587
655
  pluginInjectionApi: pluginInjectionApi,
588
656
  isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
589
- isResizing: isResizing
657
+ isResizing: isResizing,
658
+ tablePreserveWidth: tablePreserveWidth
590
659
  }, /*#__PURE__*/React.createElement("div", {
591
660
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
592
661
  "data-testid": "sticky-sentinel-top"
@@ -41,7 +41,8 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
41
41
  getPos,
42
42
  tableRef,
43
43
  isResizing,
44
- pluginInjectionApi
44
+ pluginInjectionApi,
45
+ tablePreserveWidth
45
46
  }) => {
46
47
  const containerRef = useRef(null);
47
48
  const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
@@ -123,7 +124,8 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
123
124
  tableRef,
124
125
  displayGuideline,
125
126
  attachAnalyticsEvent,
126
- displayGapCursor
127
+ displayGapCursor,
128
+ tablePreserveWidth
127
129
  };
128
130
  if (getBooleanFF('platform.editor.resizing-table-height-improvement')) {
129
131
  tableResizerProps = {
@@ -163,7 +165,8 @@ export const TableContainer = ({
163
165
  tableRef,
164
166
  isNested,
165
167
  isResizing,
166
- pluginInjectionApi
168
+ pluginInjectionApi,
169
+ tablePreserveWidth
167
170
  }) => {
168
171
  if (isTableResizingEnabled && !isNested) {
169
172
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
@@ -174,7 +177,8 @@ export const TableContainer = ({
174
177
  getPos: getPos,
175
178
  tableRef: tableRef,
176
179
  isResizing: isResizing,
177
- pluginInjectionApi: pluginInjectionApi
180
+ pluginInjectionApi: pluginInjectionApi,
181
+ tablePreserveWidth: tablePreserveWidth
178
182
  }, children);
179
183
  }
180
184
  const tableWidth = isBreakoutEnabled ? calcTableWidth(node.attrs.layout, editorWidth) : 'inherit';
@@ -82,7 +82,8 @@ export const TableResizer = ({
82
82
  tableRef,
83
83
  displayGuideline,
84
84
  attachAnalyticsEvent,
85
- displayGapCursor
85
+ displayGapCursor,
86
+ tablePreserveWidth
86
87
  }) => {
87
88
  var _findTable, _editorView$state;
88
89
  const currentGap = useRef(0);
@@ -196,11 +197,11 @@ export const TableResizer = ({
196
197
  prevNode: node,
197
198
  start: pos + 1,
198
199
  parentWidth: newWidth
199
- }, editorView.domAtPos.bind(editorView));
200
+ }, editorView.domAtPos.bind(editorView), tablePreserveWidth);
200
201
  updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
201
202
  updateWidth(newWidth);
202
203
  return newWidth;
203
- }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
204
+ }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames, tablePreserveWidth]);
204
205
  const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
205
206
  const handleResizeStop = useCallback((originalState, delta) => {
206
207
  isResizing.current = false;
@@ -237,7 +238,7 @@ export const TableResizer = ({
237
238
  prevNode: node,
238
239
  start: pos + 1,
239
240
  parentWidth: newWidth
240
- }, editorView.domAtPos.bind(editorView))(tr);
241
+ }, editorView.domAtPos.bind(editorView), tablePreserveWidth)(tr);
241
242
  const scaledNode = tr.doc.nodeAt(pos);
242
243
  (_attachAnalyticsEvent2 = attachAnalyticsEvent(generateResizedPayload({
243
244
  originalNode: node,
@@ -255,7 +256,7 @@ export const TableResizer = ({
255
256
  onResizeStop();
256
257
  }
257
258
  return newWidth;
258
- }, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
259
+ }, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop, tablePreserveWidth]);
259
260
  const handleTableSizeChangeOnKeypress = useCallback(step => {
260
261
  const newWidth = width + step;
261
262
  if (newWidth > maxWidth || newWidth < resizerMinWidth) {
@@ -57,14 +57,21 @@ export default class TableView extends ReactNodeView {
57
57
  _defineProperty(this, "hasHoveredRows", false);
58
58
  this.getPos = props.getPos;
59
59
  this.eventDispatcher = props.eventDispatcher;
60
+ this.getEditorFeatureFlags = props.getEditorFeatureFlags;
60
61
  }
61
62
  getContentDOM() {
62
63
  const rendered = DOMSerializer.renderSpec(document, toDOM(this.node, this.reactComponentProps));
63
- const tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
64
64
  if (rendered.dom) {
65
65
  this.table = rendered.dom;
66
- if (tableInlineWidth) {
67
- handleInlineTableWidth(this.table, tableInlineWidth);
66
+ const {
67
+ tablePreserveWidth = false
68
+ } = this.getEditorFeatureFlags();
69
+ // Preserve Table Width cannot have inline width set on the table
70
+ if (!tablePreserveWidth) {
71
+ const tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
72
+ if (tableInlineWidth) {
73
+ handleInlineTableWidth(this.table, tableInlineWidth);
74
+ }
68
75
  }
69
76
  }
70
77
  return rendered;
@@ -158,7 +165,8 @@ export default class TableView extends ReactNodeView {
158
165
  contentDOM: forwardRef,
159
166
  getEditorFeatureFlags: props.getEditorFeatureFlags,
160
167
  dispatchAnalyticsEvent: props.dispatchAnalyticsEvent,
161
- pluginInjectionApi: props.pluginInjectionApi
168
+ pluginInjectionApi: props.pluginInjectionApi,
169
+ tableRef: this.table
162
170
  });
163
171
  }
164
172
  });
@@ -147,9 +147,10 @@ const tablesPlugin = ({
147
147
  name: 'tableKeymap',
148
148
  plugin: () => {
149
149
  const {
150
- dragAndDropEnabled
150
+ dragAndDropEnabled,
151
+ getEditorFeatureFlags
151
152
  } = options || {};
152
- return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled);
153
+ return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, dragAndDropEnabled);
153
154
  }
154
155
  }, {
155
156
  name: 'tableSelectionKeymap',
@@ -187,10 +188,13 @@ const tablesPlugin = ({
187
188
  }, {
188
189
  name: 'tableDragAndDrop',
189
190
  plugin: ({
190
- dispatch,
191
- eventDispatcher,
192
- dispatchAnalyticsEvent
193
- }) => options !== null && options !== void 0 && options.dragAndDropEnabled ? createDragAndDropPlugin(dispatch, eventDispatcher, editorAnalyticsAPI) : undefined
191
+ dispatch
192
+ }) => {
193
+ const {
194
+ getEditorFeatureFlags
195
+ } = options || {};
196
+ return options !== null && options !== void 0 && options.dragAndDropEnabled ? createDragAndDropPlugin(dispatch, getEditorFeatureFlags, editorAnalyticsAPI) : undefined;
197
+ }
194
198
  }, {
195
199
  name: 'tableLocalId',
196
200
  plugin: ({
@@ -340,7 +344,8 @@ const tablesPlugin = ({
340
344
  hasStickyHeaders: stickyHeader && stickyHeader.sticky,
341
345
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
342
346
  editorAnalyticsAPI: editorAnalyticsAPI,
343
- getEditorContainerWidth: defaultGetEditorContainerWidth
347
+ getEditorContainerWidth: defaultGetEditorContainerWidth,
348
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
344
349
  }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
345
350
  editorView: editorView,
346
351
  mountPoint: popupsMountPoint,
@@ -364,7 +369,8 @@ const tablesPlugin = ({
364
369
  getEditorContainerWidth: defaultGetEditorContainerWidth,
365
370
  editorAnalyticsAPI: editorAnalyticsAPI,
366
371
  stickyHeaders: stickyHeader,
367
- pluginConfig: pluginConfig
372
+ pluginConfig: pluginConfig,
373
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
368
374
  }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
369
375
  editorView: editorView,
370
376
  selection: editorView.state.selection,
@@ -17,7 +17,7 @@ import { DropTargetType } from './consts';
17
17
  import { createPluginState, getPluginState } from './plugin-factory';
18
18
  import { pluginKey } from './plugin-key';
19
19
  import { getDraggableDataFromEvent } from './utils/monitor';
20
- const destroyFn = (editorView, editorAnalyticsAPI) => {
20
+ const destroyFn = (editorView, editorAnalyticsAPI, getEditorFeatureFlags) => {
21
21
  const editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
22
22
  const rowAutoScrollers = editorPageScrollContainer ? [monitorForElements({
23
23
  canMonitor({
@@ -161,7 +161,10 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
161
161
  tableNode
162
162
  } = getTablePluginState(editorView.state);
163
163
  if (tableRef && tableNode) {
164
- insertColgroupFromNode(tableRef, tableNode);
164
+ const {
165
+ tablePreserveWidth = false
166
+ } = (getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) || {};
167
+ insertColgroupFromNode(tableRef, tableNode, tablePreserveWidth);
165
168
  }
166
169
  }
167
170
  editorView.focus();
@@ -169,7 +172,7 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
169
172
  }
170
173
  }));
171
174
  };
172
- export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
175
+ export const createPlugin = (dispatch, getEditorFeatureFlags, editorAnalyticsAPI) => {
173
176
  return new SafePlugin({
174
177
  state: createPluginState(dispatch, state => ({
175
178
  decorationSet: DecorationSet.empty,
@@ -238,7 +241,7 @@ export const createPlugin = (dispatch, eventDispatcher, editorAnalyticsAPI) => {
238
241
  },
239
242
  view: editorView => {
240
243
  return {
241
- destroy: destroyFn(editorView, editorAnalyticsAPI)
244
+ destroy: destroyFn(editorView, editorAnalyticsAPI, getEditorFeatureFlags)
242
245
  };
243
246
  },
244
247
  props: {
@@ -18,7 +18,7 @@ const createTableWithAnalytics = editorAnalyticsAPI => withEditorAnalyticsAPI({
18
18
  },
19
19
  eventType: EVENT_TYPE.TRACK
20
20
  })(editorAnalyticsAPI)(createTable());
21
- export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
21
+ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, dragAndDropEnabled) {
22
22
  const list = {};
23
23
  bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
24
24
  bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
@@ -50,11 +50,14 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
50
50
  bindKeymapWithCommand(deleteRow.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
51
51
  }
52
52
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
53
+ const {
54
+ tablePreserveWidth = false
55
+ } = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
53
56
  bindKeymapWithCommand(startColumnResizing.common, initiateKeyboardColumnResizing, list);
54
57
  bindKeymapWithCommand(moveRight.common, activateNextResizeArea(1), list);
55
58
  bindKeymapWithCommand(moveLeft.common, activateNextResizeArea(-1), list);
56
- bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth), list);
57
- bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth), list);
59
+ bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth, tablePreserveWidth), list);
60
+ bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth, tablePreserveWidth), list);
58
61
  bindKeymapWithCommand(escape.common, stopKeyboardColumnResizing(), list);
59
62
  }
60
63
  return keymap(list);
@@ -82,9 +82,12 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
82
82
  }
83
83
  });
84
84
  }
85
+ const {
86
+ tablePreserveWidth = false
87
+ } = getEditorFeatureFlags();
85
88
  if (tr) {
86
89
  // "fixTables" removes empty rows as we don't allow that in schema
87
- const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
90
+ const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined, tablePreserveWidth);
88
91
  return fixTables(updatedTr) || updatedTr;
89
92
  }
90
93
  if (transactions.find(tr => tr.docChanged)) {
@@ -21,6 +21,9 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
21
21
  } = view;
22
22
  const editorDisabled = !view.editable;
23
23
  const domAtPos = view.domAtPos.bind(view);
24
+ const {
25
+ tablePreserveWidth = false
26
+ } = getEditorFeatureFlags();
24
27
  if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
25
28
  return false;
26
29
  }
@@ -67,7 +70,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
67
70
  table: originalTable,
68
71
  tableRef: dom,
69
72
  start,
70
- domAtPos
73
+ domAtPos,
74
+ tablePreserveWidth
71
75
  });
72
76
  if (evenColumns({
73
77
  resizeState,
@@ -149,7 +153,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
149
153
  const selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
150
154
  // only selected (or selected - 1) columns should be distributed
151
155
  const resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
152
- const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined);
156
+ const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined, tablePreserveWidth);
153
157
  tr = updateColumnWidths(newResizeState, table, start)(tr);
154
158
  if (colIndex === map.width - 1) {
155
159
  const mouseUpTime = event.timeStamp;
@@ -203,7 +207,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
203
207
  const table = $cell.node(-1);
204
208
  const map = TableMap.get(table);
205
209
  const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
206
- resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom);
210
+ resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, undefined, tablePreserveWidth);
207
211
  updateControls()(state);
208
212
  }
209
213
  window.addEventListener('mouseup', finish);
@@ -3,6 +3,7 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
3
3
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
+ import { MAX_SCALING_PERCENT } from './consts';
6
7
  /**
7
8
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
8
9
  * than the table and table wrapper elements. This is necessary as there is no longer
@@ -10,7 +11,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
11
  * overflow.
11
12
  */
12
13
  export const getColWidthFix = (colwidth, tableColumnCount) => colwidth - 1 / tableColumnCount;
13
- export const generateColgroup = table => {
14
+ export const generateColgroup = (table, tableRef) => {
14
15
  const cols = [];
15
16
  if (getBooleanFF('platform.editor.custom-table-width')) {
16
17
  const map = TableMap.get(table);
@@ -19,11 +20,27 @@ export const generateColgroup = table => {
19
20
  if (Array.isArray(cell.attrs.colwidth)) {
20
21
  // We slice here to guard against our colwidth array having more entries
21
22
  // Than the we actually span. We'll patch the document at a later point.
22
- cell.attrs.colwidth.slice(0, colspan).forEach(width => {
23
- cols.push(['col', {
24
- style: `width: ${getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width)}px;`
25
- }]);
26
- });
23
+ if (tableRef) {
24
+ var _tableRef$parentEleme;
25
+ const tableWidth = table.attrs && table.attrs.width;
26
+ let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
27
+ let scalePercent = renderWidth / tableWidth;
28
+ scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
29
+ cell.attrs.colwidth.slice(0, colspan).forEach(width => {
30
+ const fixedColWidth = getColWidthFix(width, map.width);
31
+ const scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
32
+ const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
33
+ cols.push(['col', {
34
+ style: `width: ${finalWidth}px;`
35
+ }]);
36
+ });
37
+ } else {
38
+ cell.attrs.colwidth.slice(0, colspan).forEach(width => {
39
+ cols.push(['col', {
40
+ style: `width: ${getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width)}px;`
41
+ }]);
42
+ });
43
+ }
27
44
  } else {
28
45
  // When we have merged cells on the first row (firstChild),
29
46
  // We want to ensure we're creating the appropriate amount of
@@ -58,13 +75,15 @@ export const generateColgroup = table => {
58
75
  }
59
76
  return cols;
60
77
  };
61
- export const insertColgroupFromNode = (tableRef, table) => {
78
+ export const insertColgroupFromNode = (tableRef, table, tablePreserveWidth = false, shouldRemove = true) => {
62
79
  let colgroup = tableRef.querySelector('colgroup');
63
- if (colgroup) {
80
+ if (colgroup && shouldRemove) {
64
81
  tableRef.removeChild(colgroup);
65
82
  }
66
- colgroup = renderColgroupFromNode(table);
67
- tableRef.insertBefore(colgroup, tableRef.firstChild);
83
+ colgroup = renderColgroupFromNode(table, tablePreserveWidth ? tableRef : undefined);
84
+ if (shouldRemove) {
85
+ tableRef.insertBefore(colgroup, tableRef.firstChild);
86
+ }
68
87
  return colgroup.children;
69
88
  };
70
89
  export const hasTableBeenResized = table => {
@@ -84,8 +103,8 @@ export const isMinCellWidthTable = table => {
84
103
  });
85
104
  return isTableMinCellWidth;
86
105
  };
87
- function renderColgroupFromNode(table) {
88
- const rendered = DOMSerializer.renderSpec(document, ['colgroup', {}, ...generateColgroup(table)]);
106
+ function renderColgroupFromNode(table, maybeTableRef) {
107
+ const rendered = DOMSerializer.renderSpec(document, ['colgroup', {}, ...generateColgroup(table, maybeTableRef)]);
89
108
  return rendered.dom;
90
109
  }
91
110
  export const getColgroupChildrenLength = table => {
@@ -1,2 +1,4 @@
1
1
  export const COLUMN_MIN_WIDTH = 48;
2
- export const TABLE_MAX_WIDTH = 1800;
2
+ export const TABLE_DEFAULT_WIDTH = 760;
3
+ export const TABLE_MAX_WIDTH = 1800;
4
+ export const MAX_SCALING_PERCENT = 0.3;
@@ -3,8 +3,8 @@ export { contentWidth } from './content-width';
3
3
  export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateColumnWidth, addContainerLeftRightPadding } from './column-state';
4
4
  export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
5
5
  export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths } from './resize-state';
6
- export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth } from './misc';
6
+ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElement } from './misc';
7
7
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
8
8
  export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
9
9
  export { resizeColumn } from './resize-column';
10
- export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH } from './consts';
10
+ export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT } from './consts';