@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
@@ -20,7 +20,7 @@ var createTableWithAnalytics = function createTableWithAnalytics(editorAnalytics
20
20
  eventType: EVENT_TYPE.TRACK
21
21
  })(editorAnalyticsAPI)(createTable());
22
22
  };
23
- export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
23
+ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, dragAndDropEnabled) {
24
24
  var list = {};
25
25
  bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
26
26
  bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
@@ -52,11 +52,14 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
52
52
  bindKeymapWithCommand(deleteRow.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
53
53
  }
54
54
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
55
+ var _ref = getEditorFeatureFlags ? getEditorFeatureFlags() : {},
56
+ _ref$tablePreserveWid = _ref.tablePreserveWidth,
57
+ tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
55
58
  bindKeymapWithCommand(startColumnResizing.common, initiateKeyboardColumnResizing, list);
56
59
  bindKeymapWithCommand(moveRight.common, activateNextResizeArea(1), list);
57
60
  bindKeymapWithCommand(moveLeft.common, activateNextResizeArea(-1), list);
58
- bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth), list);
59
- bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth), list);
61
+ bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth, tablePreserveWidth), list);
62
+ bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth, tablePreserveWidth), list);
60
63
  bindKeymapWithCommand(escape.common, stopKeyboardColumnResizing(), list);
61
64
  }
62
65
  return keymap(list);
@@ -88,9 +88,12 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
88
88
  }
89
89
  });
90
90
  }
91
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
92
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
93
+ tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
91
94
  if (tr) {
92
95
  // "fixTables" removes empty rows as we don't allow that in schema
93
- var updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
96
+ var updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined, tablePreserveWidth);
94
97
  return fixTables(updatedTr) || updatedTr;
95
98
  }
96
99
  if (transactions.find(function (tr) {
@@ -19,6 +19,9 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
19
19
  dispatch = view.dispatch;
20
20
  var editorDisabled = !view.editable;
21
21
  var domAtPos = view.domAtPos.bind(view);
22
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
23
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
24
+ tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
22
25
  if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
23
26
  return false;
24
27
  }
@@ -64,7 +67,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
64
67
  table: originalTable,
65
68
  tableRef: dom,
66
69
  start: start,
67
- domAtPos: domAtPos
70
+ domAtPos: domAtPos,
71
+ tablePreserveWidth: tablePreserveWidth
68
72
  });
69
73
  if (evenColumns({
70
74
  resizeState: resizeState,
@@ -136,7 +140,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
136
140
  var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
137
141
  // only selected (or selected - 1) columns should be distributed
138
142
  var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
139
- var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined);
143
+ var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined, tablePreserveWidth);
140
144
  tr = updateColumnWidths(newResizeState, table, start)(tr);
141
145
  if (colIndex === map.width - 1) {
142
146
  var mouseUpTime = event.timeStamp;
@@ -184,7 +188,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
184
188
  var table = $cell.node(-1);
185
189
  var map = TableMap.get(table);
186
190
  var colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
187
- resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom);
191
+ resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, undefined, tablePreserveWidth);
188
192
  updateControls()(state);
189
193
  }
190
194
  window.addEventListener('mouseup', finish);
@@ -4,6 +4,7 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
4
4
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ import { MAX_SCALING_PERCENT } from './consts';
7
8
  /**
8
9
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
9
10
  * than the table and table wrapper elements. This is necessary as there is no longer
@@ -13,7 +14,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
14
  export var getColWidthFix = function getColWidthFix(colwidth, tableColumnCount) {
14
15
  return colwidth - 1 / tableColumnCount;
15
16
  };
16
- export var generateColgroup = function generateColgroup(table) {
17
+ export var generateColgroup = function generateColgroup(table, tableRef) {
17
18
  var cols = [];
18
19
  if (getBooleanFF('platform.editor.custom-table-width')) {
19
20
  var map = TableMap.get(table);
@@ -22,11 +23,27 @@ export var generateColgroup = function generateColgroup(table) {
22
23
  if (Array.isArray(cell.attrs.colwidth)) {
23
24
  // We slice here to guard against our colwidth array having more entries
24
25
  // Than the we actually span. We'll patch the document at a later point.
25
- cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
26
- cols.push(['col', {
27
- style: "width: ".concat(getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width), "px;")
28
- }]);
29
- });
26
+ if (tableRef) {
27
+ var _tableRef$parentEleme;
28
+ var tableWidth = table.attrs && table.attrs.width;
29
+ var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
30
+ var scalePercent = renderWidth / tableWidth;
31
+ scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
32
+ cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
33
+ var fixedColWidth = getColWidthFix(width, map.width);
34
+ var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
35
+ var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
36
+ cols.push(['col', {
37
+ style: "width: ".concat(finalWidth, "px;")
38
+ }]);
39
+ });
40
+ } else {
41
+ cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
42
+ cols.push(['col', {
43
+ style: "width: ".concat(getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width), "px;")
44
+ }]);
45
+ });
46
+ }
30
47
  } else {
31
48
  // When we have merged cells on the first row (firstChild),
32
49
  // We want to ensure we're creating the appropriate amount of
@@ -66,12 +83,16 @@ export var generateColgroup = function generateColgroup(table) {
66
83
  return cols;
67
84
  };
68
85
  export var insertColgroupFromNode = function insertColgroupFromNode(tableRef, table) {
86
+ var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
87
+ var shouldRemove = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
69
88
  var colgroup = tableRef.querySelector('colgroup');
70
- if (colgroup) {
89
+ if (colgroup && shouldRemove) {
71
90
  tableRef.removeChild(colgroup);
72
91
  }
73
- colgroup = renderColgroupFromNode(table);
74
- tableRef.insertBefore(colgroup, tableRef.firstChild);
92
+ colgroup = renderColgroupFromNode(table, tablePreserveWidth ? tableRef : undefined);
93
+ if (shouldRemove) {
94
+ tableRef.insertBefore(colgroup, tableRef.firstChild);
95
+ }
75
96
  return colgroup.children;
76
97
  };
77
98
  export var hasTableBeenResized = function hasTableBeenResized(table) {
@@ -93,8 +114,8 @@ export var isMinCellWidthTable = function isMinCellWidthTable(table) {
93
114
  });
94
115
  return isTableMinCellWidth;
95
116
  };
96
- function renderColgroupFromNode(table) {
97
- var rendered = DOMSerializer.renderSpec(document, ['colgroup', {}].concat(_toConsumableArray(generateColgroup(table))));
117
+ function renderColgroupFromNode(table, maybeTableRef) {
118
+ var rendered = DOMSerializer.renderSpec(document, ['colgroup', {}].concat(_toConsumableArray(generateColgroup(table, maybeTableRef))));
98
119
  return rendered.dom;
99
120
  }
100
121
  export var getColgroupChildrenLength = function getColgroupChildrenLength(table) {
@@ -1,2 +1,4 @@
1
1
  export var COLUMN_MIN_WIDTH = 48;
2
- export var TABLE_MAX_WIDTH = 1800;
2
+ export var TABLE_DEFAULT_WIDTH = 760;
3
+ export var TABLE_MAX_WIDTH = 1800;
4
+ export var 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) {
9
11
  var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -69,4 +71,22 @@ export var getTableMaxWidth = function getTableMaxWidth(_ref2) {
69
71
  maxWidth -= akEditorTableNumberColumnWidth;
70
72
  }
71
73
  return maxWidth;
74
+ };
75
+
76
+ /**
77
+ *
78
+ * @param table
79
+ * @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
80
+ */
81
+ export var getTableElementWidth = function getTableElementWidth(table) {
82
+ if (hasTableBeenResized(table)) {
83
+ // TODO: is there a scenario where ADF columns are SMALLER than container width?
84
+ return calcTableColumnWidths(table).reduce(function (sum, width) {
85
+ return sum + width;
86
+ }, 0);
87
+ }
88
+ return getTableContainerElement(table);
89
+ };
90
+ export var getTableContainerElement = function getTableContainerElement(table) {
91
+ return getTableContainerWidth(table);
72
92
  };
@@ -2,7 +2,8 @@
2
2
  import { growColumn, shrinkColumn } from './resize-logic';
3
3
  import { updateColgroup } from './resize-state';
4
4
  export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, selectedColumns) {
5
+ var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
5
6
  var newState = amount > 0 ? growColumn(resizeState, colIndex, amount, selectedColumns) : amount < 0 ? shrinkColumn(resizeState, colIndex, amount, selectedColumns) : resizeState;
6
- updateColgroup(newState, tableRef);
7
+ updateColgroup(newState, tableRef, tablePreserveWidth);
7
8
  return newState;
8
9
  };
@@ -9,13 +9,17 @@ import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './c
9
9
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
10
10
  import { syncStickyRowToTable } from './dom';
11
11
  import { getTableMaxWidth } from './misc';
12
+ import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
12
13
  export var getResizeState = function getResizeState(_ref) {
13
14
  var minWidth = _ref.minWidth,
14
15
  maxSize = _ref.maxSize,
15
16
  table = _ref.table,
16
17
  tableRef = _ref.tableRef,
17
18
  start = _ref.start,
18
- domAtPos = _ref.domAtPos;
19
+ domAtPos = _ref.domAtPos,
20
+ _ref$tablePreserveWid = _ref.tablePreserveWidth,
21
+ tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
22
+ // If the table has been resized, we can use the column widths from the table node
19
23
  if (hasTableBeenResized(table)) {
20
24
  var _cols = calcTableColumnWidths(table).map(function (width, index) {
21
25
  return {
@@ -39,10 +43,22 @@ export var getResizeState = function getResizeState(_ref) {
39
43
  overflow: _overflow
40
44
  };
41
45
  }
46
+ var shouldReinsertColgroup = !tablePreserveWidth;
42
47
 
43
48
  // Getting the resize state from DOM
44
- var colgroupChildren = insertColgroupFromNode(tableRef, table);
49
+ var colgroupChildren = insertColgroupFromNode(tableRef, table, tablePreserveWidth, shouldReinsertColgroup // don't reinsert colgroup when preserving table width - this causes widths to jump
50
+ );
51
+
45
52
  var cols = Array.from(colgroupChildren).map(function (_, index) {
53
+ // If the table hasn't been resized and we have a table width attribute, we can use it
54
+ // to calculate the widths of the columns
55
+ if (tablePreserveWidth && table.attrs.width) {
56
+ return {
57
+ index: index,
58
+ width: table.attrs.width / colgroupChildren.length,
59
+ minWidth: 48
60
+ };
61
+ }
46
62
  var cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
47
63
  return getColumnStateFromDOM(cellsRefs, index, minWidth);
48
64
  });
@@ -63,18 +79,41 @@ export var getResizeState = function getResizeState(_ref) {
63
79
  };
64
80
 
65
81
  // updates Colgroup DOM node with new widths
66
- export var updateColgroup = function updateColgroup(state, tableRef) {
82
+ export var updateColgroup = function updateColgroup(state, tableRef, tablePreserveWidth) {
67
83
  var cols = tableRef.querySelectorAll('col');
68
84
  if (getBooleanFF('platform.editor.custom-table-width')) {
69
85
  var columnsCount = cols.length;
70
- state.cols.filter(function (column) {
71
- return column && !!column.width;
72
- }) // if width is 0, we dont want to apply that.
73
- .forEach(function (column, i) {
74
- if (cols[i]) {
75
- cols[i].style.width = "".concat(getColWidthFix(column.width, columnsCount), "px");
86
+ if (tablePreserveWidth) {
87
+ var _tableRef$dataset;
88
+ 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
89
+ if (tableWidth) {
90
+ var _tableRef$parentEleme;
91
+ var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || TABLE_DEFAULT_WIDTH;
92
+ var scalePercent = renderWidth / tableWidth;
93
+ scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
94
+ state.cols.filter(function (column) {
95
+ return column && !!column.width;
96
+ }) // if width is 0, we dont want to apply that.
97
+ .forEach(function (column, i) {
98
+ var fixedColWidth = getColWidthFix(column.width, columnsCount);
99
+ var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
100
+ var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
101
+ // we aren't handling the remaining pixels here when the 48px min width is reached
102
+ if (cols[i]) {
103
+ cols[i].style.width = "".concat(finalWidth, "px");
104
+ }
105
+ });
76
106
  }
77
- });
107
+ } else {
108
+ state.cols.filter(function (column) {
109
+ return column && !!column.width;
110
+ }) // if width is 0, we dont want to apply that.
111
+ .forEach(function (column, i) {
112
+ if (cols[i]) {
113
+ cols[i].style.width = "".concat(getColWidthFix(column.width, columnsCount), "px");
114
+ }
115
+ });
116
+ }
78
117
  } else {
79
118
  state.cols.filter(function (column) {
80
119
  return column && !!column.width;
@@ -262,6 +301,7 @@ export var normaliseTableLayout = function normaliseTableLayout(input) {
262
301
  }
263
302
  };
264
303
  export var getNewResizeStateFromSelectedColumns = function getNewResizeStateFromSelectedColumns(rect, state, domAtPos, getEditorContainerWidth) {
304
+ var tablePreserveWidth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
265
305
  // Fail early so that we don't do complex calculations for no reason
266
306
  var numColumnsSelected = rect.right - rect.left;
267
307
  if (numColumnsSelected <= 1) {
@@ -298,7 +338,8 @@ export var getNewResizeStateFromSelectedColumns = function getNewResizeStateFrom
298
338
  table: table.node,
299
339
  tableRef: tableRef,
300
340
  start: table.start,
301
- domAtPos: domAtPos
341
+ domAtPos: domAtPos,
342
+ tablePreserveWidth: tablePreserveWidth
302
343
  });
303
344
  var newResizeState = evenSelectedColumnsWidths(resizeState, rect);
304
345
  var widthsBefore = resizeState.widths;
@@ -14,6 +14,7 @@ import { syncStickyRowToTable } from './dom';
14
14
  // Base function to trigger the actual scale on a table node.
15
15
  // Will only resize/scale if a table has been previously resized.
16
16
  export var scale = function scale(tableRef, options, domAtPos) {
17
+ var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
17
18
  /**
18
19
  * isBreakoutEnabled === true -> default center aligned
19
20
  * isBreakoutEnabled === false -> full width mode
@@ -58,18 +59,21 @@ export var scale = function scale(tableRef, options, domAtPos) {
58
59
  table: node,
59
60
  tableRef: tableRef,
60
61
  start: start,
61
- domAtPos: domAtPos
62
+ domAtPos: domAtPos,
63
+ tablePreserveWidth: tablePreserveWidth
62
64
  });
63
65
  return scaleTableTo(resizeState, newWidth);
64
66
  };
65
67
  export var scaleWithParent = function scaleWithParent(tableRef, parentWidth, table, start, domAtPos) {
68
+ var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
66
69
  var resizeState = getResizeState({
67
70
  minWidth: tableCellMinWidth,
68
71
  maxSize: parentWidth,
69
72
  table: table,
70
73
  tableRef: tableRef,
71
74
  start: start,
72
- domAtPos: domAtPos
75
+ domAtPos: domAtPos,
76
+ tablePreserveWidth: tablePreserveWidth
73
77
  });
74
78
  if (table.attrs.isNumberColumnEnabled) {
75
79
  parentWidth -= akEditorTableNumberColumnWidth;
@@ -101,6 +105,7 @@ export function scaleTableTo(state, maxSize) {
101
105
  return adjustColumnsWidths(newState, maxSize);
102
106
  }
103
107
  export var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos) {
108
+ var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
104
109
  var node = options.node,
105
110
  start = options.start,
106
111
  parentWidth = options.parentWidth;
@@ -112,18 +117,22 @@ export var previewScaleTable = function previewScaleTable(tableRef, options, dom
112
117
  var width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
113
118
  tableRef.style.width = "".concat(width, "px");
114
119
  }
115
- if (!hasTableBeenResized(node)) {
120
+
121
+ // If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
122
+ // If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
123
+ if (!hasTableBeenResized(node) && !tablePreserveWidth) {
116
124
  syncStickyRowToTable(tableRef);
117
125
  return;
118
126
  }
119
- var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
127
+ var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth) : scale(tableRef, options, domAtPos, tablePreserveWidth);
120
128
  if (resizeState) {
121
- updateColgroup(resizeState, tableRef);
129
+ updateColgroup(resizeState, tableRef, tablePreserveWidth);
122
130
  }
123
131
  };
124
132
 
125
133
  // Scale the table to meet new requirements (col, layout change etc)
126
134
  export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
135
+ var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
127
136
  return function (tr) {
128
137
  if (!tableRef) {
129
138
  return tr;
@@ -136,15 +145,17 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
136
145
  if (hasTableBeenResized(node) === false) {
137
146
  // If its not a re-sized table, we still want to re-create cols
138
147
  // To force reflow of columns upon delete.
139
- insertColgroupFromNode(tableRef, node);
148
+ if (!tablePreserveWidth) {
149
+ insertColgroupFromNode(tableRef, node);
150
+ }
140
151
  tr.setMeta('scrollIntoView', false);
141
152
  return tr;
142
153
  }
143
154
  var resizeState;
144
155
  if (parentWidth) {
145
- resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
156
+ resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth);
146
157
  } else {
147
- resizeState = scale(tableRef, options, domAtPos);
158
+ resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
148
159
  }
149
160
  if (resizeState) {
150
161
  tr = updateColumnWidths(resizeState, node, start)(tr);
@@ -85,6 +85,7 @@ export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _
85
85
  export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(editorState, editorView, initialSelectionRect, _ref2, getEditorContainerWidth, editorAnalyticsAPI) {
86
86
  var _pluginState$pluginCo, _pluginState$pluginCo2;
87
87
  var formatMessage = _ref2.formatMessage;
88
+ var tablePreserveWidth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
88
89
  var top = initialSelectionRect.top,
89
90
  bottom = initialSelectionRect.bottom,
90
91
  right = initialSelectionRect.right,
@@ -99,7 +100,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
99
100
  var selectionRect = getClosestSelectionRect(state);
100
101
  var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right;
101
102
  if (index) {
102
- insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
103
+ insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
103
104
  }
104
105
  return true;
105
106
  },
@@ -178,7 +179,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
178
179
  }];
179
180
  if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
180
181
  var _newResizeStateWithAn;
181
- var newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth) : undefined;
182
+ var newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth) : undefined;
182
183
  var wouldChange = (_newResizeStateWithAn = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn !== void 0 ? _newResizeStateWithAn : false;
183
184
  var distributeColumnWidths = function distributeColumnWidths(state, dispatch) {
184
185
  if (newResizeStateWithAnalytics) {
@@ -298,10 +299,13 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
298
299
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
299
300
  var nodeType = state.schema.nodes.table;
300
301
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
302
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
303
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
304
+ tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
301
305
  var cellItems;
302
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
306
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
303
307
  var columnSettingsItems;
304
- columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
308
+ columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth) : [];
305
309
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
306
310
 
307
311
  // Check if we need to show confirm dialog for delete button
@@ -340,8 +344,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
340
344
  }
341
345
  return element;
342
346
  };
343
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
344
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
347
+ var _getEditorFeatureFlag3 = getEditorFeatureFlags(),
348
+ stickyScrollbar = _getEditorFeatureFlag3.stickyScrollbar;
345
349
  return {
346
350
  title: 'Table floating controls',
347
351
  getDomRef: getDomRef,
@@ -400,22 +404,24 @@ var separator = function separator(hidden) {
400
404
  };
401
405
  var getCellItems = function getCellItems(pluginConfig, state, view, _ref3, getEditorContainerWidth, editorAnalyticsAPI) {
402
406
  var formatMessage = _ref3.formatMessage;
407
+ var tablePreserveWidth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
403
408
  var initialSelectionRect = getClosestSelectionRect(state);
404
409
  if (initialSelectionRect) {
405
410
  var cellOptions = getToolbarCellOptionsConfig(state, view, initialSelectionRect, {
406
411
  formatMessage: formatMessage
407
- }, getEditorContainerWidth, editorAnalyticsAPI);
412
+ }, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
408
413
  return [cellOptions, separator(cellOptions.hidden)];
409
414
  }
410
415
  return [];
411
416
  };
412
417
  export var getDistributeConfig = function getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI) {
418
+ var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
413
419
  return function (state, dispatch, editorView) {
414
420
  var selectionOrTableRect = getClosestSelectionOrTableRect(state);
415
421
  if (!editorView || !selectionOrTableRect) {
416
422
  return false;
417
423
  }
418
- var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
424
+ var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
419
425
  if (newResizeStateWithAnalytics) {
420
426
  distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
421
427
  return true;
@@ -429,12 +435,13 @@ export var getDistributeConfig = function getDistributeConfig(getEditorContainer
429
435
  var getColumnSettingItems = function getColumnSettingItems(editorState, editorView, _ref4, getEditorContainerWidth, editorAnalyticsAPI) {
430
436
  var _newResizeStateWithAn2, _pluginState$pluginCo3;
431
437
  var formatMessage = _ref4.formatMessage;
438
+ var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
432
439
  var pluginState = getPluginState(editorState);
433
440
  var selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
434
441
  if (!selectionOrTableRect || !editorView) {
435
442
  return [];
436
443
  }
437
- var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
444
+ var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
438
445
  var wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
439
446
  if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
440
447
  return [{
@@ -443,7 +450,7 @@ var getColumnSettingItems = function getColumnSettingItems(editorState, editorVi
443
450
  title: formatMessage(messages.distributeColumns),
444
451
  icon: DistributeColumnIcon,
445
452
  onClick: function onClick(state, dispatch, view) {
446
- return getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view);
453
+ return getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(state, dispatch, view);
447
454
  },
448
455
  disabled: !wouldChange
449
456
  }, {
@@ -5,7 +5,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
5
  import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
- import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
8
+ import { getTableContainerElement, getTableElementWidth, hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
9
9
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
10
10
  import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
11
11
  import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
@@ -88,9 +88,9 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
88
88
  * @returns Updated transaction with rescaled columns for a given table
89
89
  */
90
90
  export var rescaleColumns = function rescaleColumns() {
91
+ var tablePreserveWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
91
92
  return function (table, view) {
92
93
  return function (tr) {
93
- var _tableRef$parentEleme, _tableRef$parentEleme2;
94
94
  if (!view) {
95
95
  return tr;
96
96
  }
@@ -102,14 +102,28 @@ export var rescaleColumns = function rescaleColumns() {
102
102
  return tr;
103
103
  }
104
104
  var isResized = hasTableBeenResized(table.node);
105
- // get current table info
106
105
  var previousTableInfo = {
107
- // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
108
- width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
109
- /** the is the width the table can reach before overflowing */
110
- possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 || (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
106
+ width: 0,
107
+ possibleMaxWidth: 0,
111
108
  isResized: isResized
112
109
  };
110
+ if (tablePreserveWidth) {
111
+ previousTableInfo = {
112
+ // TODO - ensure correct width is returned when table doesn't have a width value
113
+ width: getTableElementWidth(table.node),
114
+ possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? getTableContainerElement(table.node) : getTableContainerElement(table.node) - insertColumnButtonOffset,
115
+ isResized: isResized
116
+ };
117
+ } else {
118
+ var _tableRef$parentEleme, _tableRef$parentEleme2;
119
+ previousTableInfo = {
120
+ // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
121
+ width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
122
+ /** the is the width the table can reach before overflowing */
123
+ possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 || (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
124
+ isResized: isResized
125
+ };
126
+ }
113
127
 
114
128
  // determine the new table, based on new width
115
129
  var newTableInfo = {
@@ -154,7 +168,8 @@ export var rescaleColumns = function rescaleColumns() {
154
168
  start: table.start,
155
169
  tableRef: tableRef,
156
170
  domAtPos: domAtPos,
157
- maxSize: previousTableInfo.possibleMaxWidth
171
+ maxSize: previousTableInfo.possibleMaxWidth,
172
+ tablePreserveWidth: tablePreserveWidth
158
173
  });
159
174
 
160
175
  // Two scenarios that require scaling:
@@ -205,6 +205,7 @@ function fixRowSpans(table) {
205
205
  return table.type.createChecked(table.attrs, rows, table.marks);
206
206
  }
207
207
  export var deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
208
+ var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
208
209
  return function (tr) {
209
210
  var updatedTr = tr;
210
211
  updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
@@ -217,7 +218,7 @@ export var deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
217
218
  }
218
219
  var table = findTable(updatedTr.selection);
219
220
  if (table) {
220
- updatedTr = rescaleColumns()(table, view)(updatedTr);
221
+ updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
221
222
  }
222
223
  return updatedTr;
223
224
  };