@atlaskit/editor-plugin-table 7.4.8 → 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 (192) 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 +5 -3
  28. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +15 -4
  29. package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +53 -8
  30. package/dist/cjs/ui/FloatingDragMenu/index.js +15 -6
  31. package/dist/cjs/ui/FloatingInsertButton/index.js +5 -1
  32. package/dist/cjs/ui/consts.js +2 -1
  33. package/dist/cjs/utils/create.js +1 -1
  34. package/dist/cjs/utils/drag-menu.js +4 -3
  35. package/dist/es2019/commands/column-resize.js +4 -3
  36. package/dist/es2019/commands/delete.js +2 -2
  37. package/dist/es2019/commands/insert.js +6 -6
  38. package/dist/es2019/commands-with-analytics.js +4 -4
  39. package/dist/es2019/event-handlers.js +2 -2
  40. package/dist/es2019/nodeviews/TableComponent.js +77 -8
  41. package/dist/es2019/nodeviews/TableContainer.js +8 -4
  42. package/dist/es2019/nodeviews/TableResizer.js +6 -5
  43. package/dist/es2019/nodeviews/table.js +12 -4
  44. package/dist/es2019/plugin.js +14 -8
  45. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +7 -4
  46. package/dist/es2019/pm-plugins/keymap.js +6 -3
  47. package/dist/es2019/pm-plugins/main.js +4 -1
  48. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +7 -3
  49. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +31 -12
  50. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
  51. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +2 -2
  52. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +20 -2
  53. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +2 -2
  54. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +47 -10
  55. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +19 -12
  56. package/dist/es2019/toolbar.js +15 -12
  57. package/dist/es2019/transforms/column-width.js +24 -10
  58. package/dist/es2019/transforms/delete-columns.js +2 -2
  59. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +12 -5
  60. package/dist/es2019/ui/FloatingContextualMenu/index.js +6 -4
  61. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +15 -4
  62. package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +42 -8
  63. package/dist/es2019/ui/FloatingDragMenu/index.js +16 -7
  64. package/dist/es2019/ui/FloatingInsertButton/index.js +5 -1
  65. package/dist/es2019/ui/consts.js +1 -0
  66. package/dist/es2019/utils/create.js +1 -1
  67. package/dist/es2019/utils/drag-menu.js +4 -4
  68. package/dist/esm/commands/column-resize.js +4 -2
  69. package/dist/esm/commands/delete.js +2 -1
  70. package/dist/esm/commands/insert.js +6 -3
  71. package/dist/esm/commands-with-analytics.js +4 -2
  72. package/dist/esm/event-handlers.js +2 -1
  73. package/dist/esm/nodeviews/TableComponent.js +118 -49
  74. package/dist/esm/nodeviews/TableContainer.js +8 -4
  75. package/dist/esm/nodeviews/TableResizer.js +6 -5
  76. package/dist/esm/nodeviews/table.js +12 -4
  77. package/dist/esm/plugin.js +50 -47
  78. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -6
  79. package/dist/esm/pm-plugins/keymap.js +6 -3
  80. package/dist/esm/pm-plugins/main.js +4 -1
  81. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +7 -3
  82. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +32 -11
  83. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
  84. package/dist/esm/pm-plugins/table-resizing/utils/index.js +2 -2
  85. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +22 -2
  86. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +2 -1
  87. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +52 -11
  88. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +19 -8
  89. package/dist/esm/toolbar.js +17 -10
  90. package/dist/esm/transforms/column-width.js +23 -8
  91. package/dist/esm/transforms/delete-columns.js +2 -1
  92. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
  93. package/dist/esm/ui/FloatingContextualMenu/index.js +6 -4
  94. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +15 -4
  95. package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +50 -9
  96. package/dist/esm/ui/FloatingDragMenu/index.js +16 -7
  97. package/dist/esm/ui/FloatingInsertButton/index.js +5 -1
  98. package/dist/esm/ui/consts.js +1 -0
  99. package/dist/esm/utils/create.js +1 -1
  100. package/dist/esm/utils/drag-menu.js +4 -3
  101. package/dist/types/commands/column-resize.d.ts +1 -1
  102. package/dist/types/commands/delete.d.ts +1 -1
  103. package/dist/types/commands/insert.d.ts +3 -3
  104. package/dist/types/commands-with-analytics.d.ts +2 -2
  105. package/dist/types/event-handlers.d.ts +1 -1
  106. package/dist/types/nodeviews/TableComponent.d.ts +3 -0
  107. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  108. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  109. package/dist/types/nodeviews/table.d.ts +1 -0
  110. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
  111. package/dist/types/pm-plugins/keymap.d.ts +2 -2
  112. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  113. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
  114. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  115. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
  116. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  117. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
  118. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  119. package/dist/types/toolbar.d.ts +2 -2
  120. package/dist/types/transforms/column-width.d.ts +1 -1
  121. package/dist/types/transforms/delete-columns.d.ts +1 -1
  122. package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
  123. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  124. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -1
  125. package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
  126. package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
  127. package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
  128. package/dist/types/ui/consts.d.ts +1 -0
  129. package/dist/types/utils/drag-menu.d.ts +1 -1
  130. package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
  131. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  132. package/dist/types-ts4.5/commands/insert.d.ts +3 -3
  133. package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
  134. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  135. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +3 -0
  136. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  137. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  138. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -0
  139. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
  140. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
  141. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  142. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
  143. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  144. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
  145. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  146. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
  147. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  148. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  149. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  150. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  151. package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
  152. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  153. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -1
  154. package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
  155. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
  156. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -1
  157. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  158. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  159. package/package.json +3 -3
  160. package/src/commands/column-resize.ts +3 -0
  161. package/src/commands/delete.ts +2 -1
  162. package/src/commands/insert.ts +15 -6
  163. package/src/commands-with-analytics.ts +9 -3
  164. package/src/event-handlers.ts +2 -0
  165. package/src/nodeviews/TableComponent.tsx +91 -5
  166. package/src/nodeviews/TableContainer.tsx +6 -0
  167. package/src/nodeviews/TableResizer.tsx +6 -0
  168. package/src/nodeviews/table.tsx +15 -10
  169. package/src/plugin.tsx +17 -5
  170. package/src/pm-plugins/drag-and-drop/plugin.ts +16 -8
  171. package/src/pm-plugins/keymap.ts +11 -3
  172. package/src/pm-plugins/main.ts +3 -0
  173. package/src/pm-plugins/table-resizing/event-handlers.ts +11 -1
  174. package/src/pm-plugins/table-resizing/utils/colgroup.ts +49 -17
  175. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  176. package/src/pm-plugins/table-resizing/utils/index.ts +8 -1
  177. package/src/pm-plugins/table-resizing/utils/misc.ts +25 -1
  178. package/src/pm-plugins/table-resizing/utils/resize-column.ts +2 -1
  179. package/src/pm-plugins/table-resizing/utils/resize-state.ts +56 -11
  180. package/src/pm-plugins/table-resizing/utils/scale-table.ts +24 -6
  181. package/src/toolbar.tsx +18 -5
  182. package/src/transforms/column-width.ts +33 -11
  183. package/src/transforms/delete-columns.ts +7 -2
  184. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -5
  185. package/src/ui/FloatingContextualMenu/index.tsx +4 -1
  186. package/src/ui/FloatingDragMenu/DragMenu.tsx +19 -1
  187. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +94 -50
  188. package/src/ui/FloatingDragMenu/index.tsx +17 -4
  189. package/src/ui/FloatingInsertButton/index.tsx +17 -5
  190. package/src/ui/consts.ts +1 -0
  191. package/src/utils/create.ts +1 -3
  192. package/src/utils/drag-menu.ts +4 -1
@@ -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';
@@ -1,9 +1,11 @@
1
- import { getParentNodeWidth, layoutToWidth } from '@atlaskit/editor-common/node-width';
1
+ import { getParentNodeWidth, getTableContainerWidth, layoutToWidth } from '@atlaskit/editor-common/node-width';
2
2
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
3
3
  import { getBreakpoint, mapBreakpointToLayoutMaxWidth } from '@atlaskit/editor-common/ui';
4
- import { containsClassName } from '@atlaskit/editor-common/utils';
4
+ import { calcTableColumnWidths, containsClassName } from '@atlaskit/editor-common/utils';
5
5
  import { akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
6
6
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ import { hasTableBeenResized } from './colgroup';
8
+
7
9
  // Translates named layouts in number values.
8
10
  export function getLayoutSize(tableLayout, containerWidth = 0, options) {
9
11
  const {
@@ -71,4 +73,20 @@ export const getTableMaxWidth = ({
71
73
  maxWidth -= akEditorTableNumberColumnWidth;
72
74
  }
73
75
  return maxWidth;
76
+ };
77
+
78
+ /**
79
+ *
80
+ * @param table
81
+ * @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
82
+ */
83
+ export const getTableElementWidth = table => {
84
+ if (hasTableBeenResized(table)) {
85
+ // TODO: is there a scenario where ADF columns are SMALLER than container width?
86
+ return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
87
+ }
88
+ return getTableContainerElement(table);
89
+ };
90
+ export const getTableContainerElement = table => {
91
+ return getTableContainerWidth(table);
74
92
  };
@@ -1,8 +1,8 @@
1
1
  // Resize a given column by an amount from the current state
2
2
  import { growColumn, shrinkColumn } from './resize-logic';
3
3
  import { updateColgroup } from './resize-state';
4
- export const resizeColumn = (resizeState, colIndex, amount, tableRef, selectedColumns) => {
4
+ export const resizeColumn = (resizeState, colIndex, amount, tableRef, selectedColumns, tablePreserveWidth = false) => {
5
5
  const newState = amount > 0 ? growColumn(resizeState, colIndex, amount, selectedColumns) : amount < 0 ? shrinkColumn(resizeState, colIndex, amount, selectedColumns) : resizeState;
6
- updateColgroup(newState, tableRef);
6
+ updateColgroup(newState, tableRef, tablePreserveWidth);
7
7
  return newState;
8
8
  };
@@ -6,14 +6,17 @@ import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './c
6
6
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
7
7
  import { syncStickyRowToTable } from './dom';
8
8
  import { getTableMaxWidth } from './misc';
9
+ import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
9
10
  export const getResizeState = ({
10
11
  minWidth,
11
12
  maxSize,
12
13
  table,
13
14
  tableRef,
14
15
  start,
15
- domAtPos
16
+ domAtPos,
17
+ tablePreserveWidth = false
16
18
  }) => {
19
+ // If the table has been resized, we can use the column widths from the table node
17
20
  if (hasTableBeenResized(table)) {
18
21
  const cols = calcTableColumnWidths(table).map((width, index) => ({
19
22
  width: width === 0 ? tableNewColumnMinWidth : width,
@@ -31,10 +34,22 @@ export const getResizeState = ({
31
34
  overflow
32
35
  };
33
36
  }
37
+ const shouldReinsertColgroup = !tablePreserveWidth;
34
38
 
35
39
  // Getting the resize state from DOM
36
- const colgroupChildren = insertColgroupFromNode(tableRef, table);
40
+ const colgroupChildren = insertColgroupFromNode(tableRef, table, tablePreserveWidth, shouldReinsertColgroup // don't reinsert colgroup when preserving table width - this causes widths to jump
41
+ );
42
+
37
43
  const cols = Array.from(colgroupChildren).map((_, index) => {
44
+ // If the table hasn't been resized and we have a table width attribute, we can use it
45
+ // to calculate the widths of the columns
46
+ if (tablePreserveWidth && table.attrs.width) {
47
+ return {
48
+ index,
49
+ width: table.attrs.width / colgroupChildren.length,
50
+ minWidth: 48
51
+ };
52
+ }
38
53
  const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
39
54
  return getColumnStateFromDOM(cellsRefs, index, minWidth);
40
55
  });
@@ -51,16 +66,37 @@ export const getResizeState = ({
51
66
  };
52
67
 
53
68
  // updates Colgroup DOM node with new widths
54
- export const updateColgroup = (state, tableRef) => {
69
+ export const updateColgroup = (state, tableRef, tablePreserveWidth) => {
55
70
  const cols = tableRef.querySelectorAll('col');
56
71
  if (getBooleanFF('platform.editor.custom-table-width')) {
57
72
  const columnsCount = cols.length;
58
- state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
59
- .forEach((column, i) => {
60
- if (cols[i]) {
61
- cols[i].style.width = `${getColWidthFix(column.width, columnsCount)}px`;
73
+ if (tablePreserveWidth) {
74
+ var _tableRef$dataset;
75
+ const 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
76
+ if (tableWidth) {
77
+ var _tableRef$parentEleme;
78
+ let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || TABLE_DEFAULT_WIDTH;
79
+ let scalePercent = renderWidth / tableWidth;
80
+ scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
81
+ state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
82
+ .forEach((column, i) => {
83
+ const fixedColWidth = getColWidthFix(column.width, columnsCount);
84
+ const scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
85
+ const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
86
+ // we aren't handling the remaining pixels here when the 48px min width is reached
87
+ if (cols[i]) {
88
+ cols[i].style.width = `${finalWidth}px`;
89
+ }
90
+ });
62
91
  }
63
- });
92
+ } else {
93
+ state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
94
+ .forEach((column, i) => {
95
+ if (cols[i]) {
96
+ cols[i].style.width = `${getColWidthFix(column.width, columnsCount)}px`;
97
+ }
98
+ });
99
+ }
64
100
  } else {
65
101
  state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
66
102
  .forEach((column, i) => {
@@ -240,7 +276,7 @@ export const normaliseTableLayout = input => {
240
276
  return 'default';
241
277
  }
242
278
  };
243
- export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getEditorContainerWidth) => {
279
+ export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getEditorContainerWidth, tablePreserveWidth = false) => {
244
280
  // Fail early so that we don't do complex calculations for no reason
245
281
  const numColumnsSelected = rect.right - rect.left;
246
282
  if (numColumnsSelected <= 1) {
@@ -278,7 +314,8 @@ export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getE
278
314
  table: table.node,
279
315
  tableRef,
280
316
  start: table.start,
281
- domAtPos
317
+ domAtPos,
318
+ tablePreserveWidth
282
319
  });
283
320
  const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
284
321
  const widthsBefore = resizeState.widths;
@@ -10,7 +10,7 @@ import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
10
10
  import { syncStickyRowToTable } from './dom';
11
11
  // Base function to trigger the actual scale on a table node.
12
12
  // Will only resize/scale if a table has been previously resized.
13
- export const scale = (tableRef, options, domAtPos) => {
13
+ export const scale = (tableRef, options, domAtPos, tablePreserveWidth = false) => {
14
14
  /**
15
15
  * isBreakoutEnabled === true -> default center aligned
16
16
  * isBreakoutEnabled === false -> full width mode
@@ -57,18 +57,20 @@ export const scale = (tableRef, options, domAtPos) => {
57
57
  table: node,
58
58
  tableRef,
59
59
  start,
60
- domAtPos
60
+ domAtPos,
61
+ tablePreserveWidth
61
62
  });
62
63
  return scaleTableTo(resizeState, newWidth);
63
64
  };
64
- export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos) => {
65
+ export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, tablePreserveWidth = false) => {
65
66
  const resizeState = getResizeState({
66
67
  minWidth: tableCellMinWidth,
67
68
  maxSize: parentWidth,
68
69
  table,
69
70
  tableRef,
70
71
  start,
71
- domAtPos
72
+ domAtPos,
73
+ tablePreserveWidth
72
74
  });
73
75
  if (table.attrs.isNumberColumnEnabled) {
74
76
  parentWidth -= akEditorTableNumberColumnWidth;
@@ -103,7 +105,7 @@ export function scaleTableTo(state, maxSize) {
103
105
  }
104
106
  return adjustColumnsWidths(newState, maxSize);
105
107
  }
106
- export const previewScaleTable = (tableRef, options, domAtPos) => {
108
+ export const previewScaleTable = (tableRef, options, domAtPos, tablePreserveWidth = false) => {
107
109
  const {
108
110
  node,
109
111
  start,
@@ -117,18 +119,21 @@ export const previewScaleTable = (tableRef, options, domAtPos) => {
117
119
  const width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
118
120
  tableRef.style.width = `${width}px`;
119
121
  }
120
- if (!hasTableBeenResized(node)) {
122
+
123
+ // If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
124
+ // If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
125
+ if (!hasTableBeenResized(node) && !tablePreserveWidth) {
121
126
  syncStickyRowToTable(tableRef);
122
127
  return;
123
128
  }
124
- const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
129
+ const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth) : scale(tableRef, options, domAtPos, tablePreserveWidth);
125
130
  if (resizeState) {
126
- updateColgroup(resizeState, tableRef);
131
+ updateColgroup(resizeState, tableRef, tablePreserveWidth);
127
132
  }
128
133
  };
129
134
 
130
135
  // Scale the table to meet new requirements (col, layout change etc)
131
- export const scaleTable = (tableRef, options, domAtPos) => tr => {
136
+ export const scaleTable = (tableRef, options, domAtPos, tablePreserveWidth = false) => tr => {
132
137
  if (!tableRef) {
133
138
  return tr;
134
139
  }
@@ -142,15 +147,17 @@ export const scaleTable = (tableRef, options, domAtPos) => tr => {
142
147
  if (hasTableBeenResized(node) === false) {
143
148
  // If its not a re-sized table, we still want to re-create cols
144
149
  // To force reflow of columns upon delete.
145
- insertColgroupFromNode(tableRef, node);
150
+ if (!tablePreserveWidth) {
151
+ insertColgroupFromNode(tableRef, node);
152
+ }
146
153
  tr.setMeta('scrollIntoView', false);
147
154
  return tr;
148
155
  }
149
156
  let resizeState;
150
157
  if (parentWidth) {
151
- resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
158
+ resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth);
152
159
  } else {
153
- resizeState = scale(tableRef, options, domAtPos);
160
+ resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
154
161
  }
155
162
  if (resizeState) {
156
163
  tr = updateColumnWidths(resizeState, node, start)(tr);
@@ -80,7 +80,7 @@ export const getToolbarMenuConfig = (config, state, {
80
80
  // with native widgets. It's enabled via a plugin config.
81
81
  export const getToolbarCellOptionsConfig = (editorState, editorView, initialSelectionRect, {
82
82
  formatMessage
83
- }, getEditorContainerWidth, editorAnalyticsAPI) => {
83
+ }, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => {
84
84
  var _pluginState$pluginCo, _pluginState$pluginCo2;
85
85
  const {
86
86
  top,
@@ -98,7 +98,7 @@ export const getToolbarCellOptionsConfig = (editorState, editorView, initialSele
98
98
  const selectionRect = getClosestSelectionRect(state);
99
99
  const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right;
100
100
  if (index) {
101
- insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
101
+ insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
102
102
  }
103
103
  return true;
104
104
  },
@@ -177,7 +177,7 @@ export const getToolbarCellOptionsConfig = (editorState, editorView, initialSele
177
177
  }];
178
178
  if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
179
179
  var _newResizeStateWithAn;
180
- const newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth) : undefined;
180
+ const newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth) : undefined;
181
181
  const wouldChange = (_newResizeStateWithAn = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn !== void 0 ? _newResizeStateWithAn : false;
182
182
  const distributeColumnWidths = (state, dispatch) => {
183
183
  if (newResizeStateWithAnalytics) {
@@ -296,10 +296,13 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
296
296
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
297
297
  const nodeType = state.schema.nodes.table;
298
298
  const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
299
+ const {
300
+ tablePreserveWidth = false
301
+ } = getEditorFeatureFlags();
299
302
  let cellItems;
300
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
303
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
301
304
  let columnSettingsItems;
302
- columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
305
+ columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth) : [];
303
306
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
304
307
 
305
308
  // Check if we need to show confirm dialog for delete button
@@ -390,22 +393,22 @@ const separator = hidden => {
390
393
  };
391
394
  const getCellItems = (pluginConfig, state, view, {
392
395
  formatMessage
393
- }, getEditorContainerWidth, editorAnalyticsAPI) => {
396
+ }, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => {
394
397
  const initialSelectionRect = getClosestSelectionRect(state);
395
398
  if (initialSelectionRect) {
396
399
  const cellOptions = getToolbarCellOptionsConfig(state, view, initialSelectionRect, {
397
400
  formatMessage
398
- }, getEditorContainerWidth, editorAnalyticsAPI);
401
+ }, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
399
402
  return [cellOptions, separator(cellOptions.hidden)];
400
403
  }
401
404
  return [];
402
405
  };
403
- export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI) => (state, dispatch, editorView) => {
406
+ export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => (state, dispatch, editorView) => {
404
407
  const selectionOrTableRect = getClosestSelectionOrTableRect(state);
405
408
  if (!editorView || !selectionOrTableRect) {
406
409
  return false;
407
410
  }
408
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
411
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
409
412
  if (newResizeStateWithAnalytics) {
410
413
  distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
411
414
  return true;
@@ -417,14 +420,14 @@ export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI)
417
420
  // fixed column button should be in this function call in the future
418
421
  const getColumnSettingItems = (editorState, editorView, {
419
422
  formatMessage
420
- }, getEditorContainerWidth, editorAnalyticsAPI) => {
423
+ }, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => {
421
424
  var _newResizeStateWithAn2, _pluginState$pluginCo3;
422
425
  const pluginState = getPluginState(editorState);
423
426
  const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
424
427
  if (!selectionOrTableRect || !editorView) {
425
428
  return [];
426
429
  }
427
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
430
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
428
431
  const wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
429
432
  if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
430
433
  return [{
@@ -432,7 +435,7 @@ const getColumnSettingItems = (editorState, editorView, {
432
435
  type: 'button',
433
436
  title: formatMessage(messages.distributeColumns),
434
437
  icon: DistributeColumnIcon,
435
- onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view),
438
+ onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(state, dispatch, view),
436
439
  disabled: !wouldChange
437
440
  }, {
438
441
  type: 'separator'
@@ -2,7 +2,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
2
  import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import { TableMap } from '@atlaskit/editor-tables/table-map';
4
4
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
- import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
5
+ import { getTableContainerElement, getTableElementWidth, hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
6
6
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
7
7
  import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
8
8
  import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
@@ -85,8 +85,7 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
85
85
  * @param view
86
86
  * @returns Updated transaction with rescaled columns for a given table
87
87
  */
88
- export const rescaleColumns = () => (table, view) => tr => {
89
- var _tableRef$parentEleme, _tableRef$parentEleme2;
88
+ export const rescaleColumns = (tablePreserveWidth = false) => (table, view) => tr => {
90
89
  if (!view) {
91
90
  return tr;
92
91
  }
@@ -98,14 +97,28 @@ export const rescaleColumns = () => (table, view) => tr => {
98
97
  return tr;
99
98
  }
100
99
  const isResized = hasTableBeenResized(table.node);
101
- // get current table info
102
- const previousTableInfo = {
103
- // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
104
- width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
105
- /** the is the width the table can reach before overflowing */
106
- possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
100
+ let previousTableInfo = {
101
+ width: 0,
102
+ possibleMaxWidth: 0,
107
103
  isResized
108
104
  };
105
+ if (tablePreserveWidth) {
106
+ previousTableInfo = {
107
+ // TODO - ensure correct width is returned when table doesn't have a width value
108
+ width: getTableElementWidth(table.node),
109
+ possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? getTableContainerElement(table.node) : getTableContainerElement(table.node) - insertColumnButtonOffset,
110
+ isResized
111
+ };
112
+ } else {
113
+ var _tableRef$parentEleme, _tableRef$parentEleme2;
114
+ previousTableInfo = {
115
+ // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
116
+ width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
117
+ /** the is the width the table can reach before overflowing */
118
+ possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
119
+ isResized
120
+ };
121
+ }
109
122
 
110
123
  // determine the new table, based on new width
111
124
  const newTableInfo = {
@@ -148,7 +161,8 @@ export const rescaleColumns = () => (table, view) => tr => {
148
161
  start: table.start,
149
162
  tableRef,
150
163
  domAtPos,
151
- maxSize: previousTableInfo.possibleMaxWidth
164
+ maxSize: previousTableInfo.possibleMaxWidth,
165
+ tablePreserveWidth
152
166
  });
153
167
 
154
168
  // Two scenarios that require scaling:
@@ -192,7 +192,7 @@ function fixRowSpans(table) {
192
192
  }
193
193
  return table.type.createChecked(table.attrs, rows, table.marks);
194
194
  }
195
- export const deleteColumns = (rect, allowCustomStep, view) => tr => {
195
+ export const deleteColumns = (rect, allowCustomStep, view, tablePreserveWidth = false) => tr => {
196
196
  let updatedTr = tr;
197
197
  updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
198
198
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN
@@ -204,7 +204,7 @@ export const deleteColumns = (rect, allowCustomStep, view) => tr => {
204
204
  }
205
205
  const table = findTable(updatedTr.selection);
206
206
  if (table) {
207
- updatedTr = rescaleColumns()(table, view)(updatedTr);
207
+ updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
208
208
  }
209
209
  return updatedTr;
210
210
  };