@atlaskit/editor-plugin-table 4.1.1 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/commands/delete.js +18 -0
  3. package/dist/cjs/plugins/table/commands-with-analytics.js +2 -7
  4. package/dist/cjs/plugins/table/event-handlers.js +2 -2
  5. package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
  6. package/dist/cjs/plugins/table/transforms/column-width.js +112 -7
  7. package/dist/cjs/plugins/table/transforms/delete-columns.js +16 -6
  8. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  9. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  10. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  11. package/dist/es2019/plugins/table/commands/delete.js +10 -0
  12. package/dist/es2019/plugins/table/commands-with-analytics.js +3 -8
  13. package/dist/es2019/plugins/table/event-handlers.js +2 -2
  14. package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
  15. package/dist/es2019/plugins/table/transforms/column-width.js +107 -7
  16. package/dist/es2019/plugins/table/transforms/delete-columns.js +16 -5
  17. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  18. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  19. package/dist/es2019/plugins/table/ui/common-styles.js +0 -1
  20. package/dist/esm/plugins/table/commands/delete.js +12 -0
  21. package/dist/esm/plugins/table/commands-with-analytics.js +3 -8
  22. package/dist/esm/plugins/table/event-handlers.js +2 -2
  23. package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
  24. package/dist/esm/plugins/table/transforms/column-width.js +113 -7
  25. package/dist/esm/plugins/table/transforms/delete-columns.js +16 -6
  26. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  27. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  28. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  29. package/dist/types/plugins/table/commands/delete.d.ts +3 -0
  30. package/dist/types/plugins/table/event-handlers.d.ts +1 -1
  31. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  32. package/dist/types/plugins/table/transforms/column-width.d.ts +25 -6
  33. package/dist/types/plugins/table/transforms/delete-columns.d.ts +2 -1
  34. package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
  35. package/package.json +5 -2
  36. package/src/__tests__/unit/commands.ts +1 -0
  37. package/src/__tests__/unit/transforms/delete-columns.ts +406 -105
  38. package/src/__tests__/unit/undo-redo.ts +1 -1
  39. package/src/plugins/table/commands/delete.ts +20 -0
  40. package/src/plugins/table/commands-with-analytics.ts +3 -10
  41. package/src/plugins/table/event-handlers.ts +6 -1
  42. package/src/plugins/table/pm-plugins/main.ts +7 -1
  43. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +1 -1
  44. package/src/plugins/table/transforms/column-width.ts +163 -17
  45. package/src/plugins/table/transforms/delete-columns.ts +23 -6
  46. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +1 -1
  47. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +7 -6
  48. package/src/plugins/table/ui/common-styles.ts +0 -1
  49. package/dist/types-ts4.5/i18n/cs.d.ts +0 -37
  50. package/dist/types-ts4.5/i18n/da.d.ts +0 -35
  51. package/dist/types-ts4.5/i18n/de.d.ts +0 -35
  52. package/dist/types-ts4.5/i18n/en.d.ts +0 -37
  53. package/dist/types-ts4.5/i18n/en_GB.d.ts +0 -37
  54. package/dist/types-ts4.5/i18n/en_ZZ.d.ts +0 -37
  55. package/dist/types-ts4.5/i18n/es.d.ts +0 -35
  56. package/dist/types-ts4.5/i18n/fi.d.ts +0 -35
  57. package/dist/types-ts4.5/i18n/fr.d.ts +0 -37
  58. package/dist/types-ts4.5/i18n/hu.d.ts +0 -37
  59. package/dist/types-ts4.5/i18n/it.d.ts +0 -37
  60. package/dist/types-ts4.5/i18n/ja.d.ts +0 -37
  61. package/dist/types-ts4.5/i18n/ko.d.ts +0 -35
  62. package/dist/types-ts4.5/i18n/nb.d.ts +0 -35
  63. package/dist/types-ts4.5/i18n/nl.d.ts +0 -37
  64. package/dist/types-ts4.5/i18n/pl.d.ts +0 -37
  65. package/dist/types-ts4.5/i18n/pt_BR.d.ts +0 -37
  66. package/dist/types-ts4.5/i18n/ru.d.ts +0 -37
  67. package/dist/types-ts4.5/i18n/sv.d.ts +0 -35
  68. package/dist/types-ts4.5/i18n/th.d.ts +0 -35
  69. package/dist/types-ts4.5/i18n/tr.d.ts +0 -37
  70. package/dist/types-ts4.5/i18n/uk.d.ts +0 -37
  71. package/dist/types-ts4.5/i18n/vi.d.ts +0 -35
  72. package/dist/types-ts4.5/i18n/zh.d.ts +0 -37
  73. package/dist/types-ts4.5/i18n/zh_TW.d.ts +0 -37
  74. package/dist/types-ts4.5/index.d.ts +0 -2
  75. package/dist/types-ts4.5/plugins/table/commands/clear.d.ts +0 -3
  76. package/dist/types-ts4.5/plugins/table/commands/collapse.d.ts +0 -2
  77. package/dist/types-ts4.5/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  78. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +0 -8
  79. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +0 -8
  80. package/dist/types-ts4.5/plugins/table/commands/insert.d.ts +0 -9
  81. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +0 -29
  82. package/dist/types-ts4.5/plugins/table/commands/referentiality.d.ts +0 -2
  83. package/dist/types-ts4.5/plugins/table/commands/selection.d.ts +0 -8
  84. package/dist/types-ts4.5/plugins/table/commands/sort.d.ts +0 -3
  85. package/dist/types-ts4.5/plugins/table/commands/split-cell.d.ts +0 -6
  86. package/dist/types-ts4.5/plugins/table/commands/toggle.d.ts +0 -12
  87. package/dist/types-ts4.5/plugins/table/commands-with-analytics.d.ts +0 -25
  88. package/dist/types-ts4.5/plugins/table/create-plugin-config.d.ts +0 -2
  89. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +0 -15
  90. package/dist/types-ts4.5/plugins/table/handlers.d.ts +0 -3
  91. package/dist/types-ts4.5/plugins/table/index.d.ts +0 -45
  92. package/dist/types-ts4.5/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -24
  93. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -73
  94. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +0 -44
  95. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +0 -25
  96. package/dist/types-ts4.5/plugins/table/nodeviews/TableStickyScrollbar.d.ts +0 -24
  97. package/dist/types-ts4.5/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  98. package/dist/types-ts4.5/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  99. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +0 -33
  100. package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +0 -17
  101. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +0 -26
  102. package/dist/types-ts4.5/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -1
  103. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  104. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  105. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -4
  106. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  107. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  108. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  109. package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +0 -4
  110. package/dist/types-ts4.5/plugins/table/pm-plugins/keymap.d.ts +0 -5
  111. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +0 -8
  112. package/dist/types-ts4.5/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  113. package/dist/types-ts4.5/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  114. package/dist/types-ts4.5/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  115. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  116. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  117. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  118. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
  119. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  120. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  121. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  122. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  123. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  124. package/dist/types-ts4.5/plugins/table/pm-plugins/table-analytics.d.ts +0 -23
  125. package/dist/types-ts4.5/plugins/table/pm-plugins/table-local-id.d.ts +0 -10
  126. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -23
  127. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  128. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -3
  129. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  130. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  131. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  132. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  133. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -23
  134. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  135. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/consts.d.ts +0 -2
  136. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  137. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -12
  138. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -13
  139. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -20
  140. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  141. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  142. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  143. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -21
  144. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  145. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  146. package/dist/types-ts4.5/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  147. package/dist/types-ts4.5/plugins/table/pm-plugins/table-width.d.ts +0 -17
  148. package/dist/types-ts4.5/plugins/table/reducer.d.ts +0 -3
  149. package/dist/types-ts4.5/plugins/table/toolbar.d.ts +0 -36
  150. package/dist/types-ts4.5/plugins/table/transforms/column-width.d.ts +0 -18
  151. package/dist/types-ts4.5/plugins/table/transforms/delete-columns.d.ts +0 -3
  152. package/dist/types-ts4.5/plugins/table/transforms/delete-rows.d.ts +0 -3
  153. package/dist/types-ts4.5/plugins/table/transforms/fix-tables.d.ts +0 -9
  154. package/dist/types-ts4.5/plugins/table/transforms/index.d.ts +0 -6
  155. package/dist/types-ts4.5/plugins/table/transforms/merge.d.ts +0 -5
  156. package/dist/types-ts4.5/plugins/table/transforms/replace-table.d.ts +0 -5
  157. package/dist/types-ts4.5/plugins/table/transforms/split.d.ts +0 -9
  158. package/dist/types-ts4.5/plugins/table/types.d.ts +0 -342
  159. package/dist/types-ts4.5/plugins/table/ui/ColumnResizeWidget/index.d.ts +0 -9
  160. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/FixedButton.d.ts +0 -23
  161. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -21
  162. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -3
  163. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  164. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -23
  165. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  166. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -13
  167. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  168. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  169. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  170. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -13
  171. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  172. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  173. package/dist/types-ts4.5/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  174. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  175. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  176. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  177. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +0 -39
  178. package/dist/types-ts4.5/plugins/table/ui/common-styles.d.ts +0 -9
  179. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +0 -50
  180. package/dist/types-ts4.5/plugins/table/ui/messages.d.ts +0 -63
  181. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +0 -15
  182. package/dist/types-ts4.5/plugins/table/utils/analytics.d.ts +0 -45
  183. package/dist/types-ts4.5/plugins/table/utils/collapse.d.ts +0 -29
  184. package/dist/types-ts4.5/plugins/table/utils/column-controls.d.ts +0 -10
  185. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +0 -19
  186. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +0 -20
  187. package/dist/types-ts4.5/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  188. package/dist/types-ts4.5/plugins/table/utils/guidelines.d.ts +0 -2
  189. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +0 -11
  190. package/dist/types-ts4.5/plugins/table/utils/nodes.d.ts +0 -13
  191. package/dist/types-ts4.5/plugins/table/utils/paste.d.ts +0 -14
  192. package/dist/types-ts4.5/plugins/table/utils/row-controls.d.ts +0 -16
  193. package/dist/types-ts4.5/plugins/table/utils/selection.d.ts +0 -6
  194. package/dist/types-ts4.5/plugins/table/utils/snapping.d.ts +0 -10
  195. package/dist/types-ts4.5/plugins/table/utils/table.d.ts +0 -4
  196. package/dist/types-ts4.5/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  197. package/dist/types-ts4.5/plugins/table-plugin.d.ts +0 -2
  198. package/dist/types-ts4.5/types/i18n.d.ts +0 -5
  199. package/tmp/api-report-tmp.d.ts +0 -112
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 4.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#40795](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/40795) [`fec7aa5c761`](https://bitbucket.org/atlassian/atlassian-frontend/commits/fec7aa5c761) - [ux] Fix distribute column resize will not been override when undefined
8
+
9
+ ## 4.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#40780](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/40780) [`981ad6038e9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/981ad6038e9) - Fixes a bug when deleting a table column will cause column resizing to become unresponsive and lag. Delete columns operation will now update the table column widths to avoid this, under a new feature flag.
14
+
3
15
  ## 4.1.1
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deleteColumnsCommand = void 0;
7
+ var _deleteColumns = require("../transforms/delete-columns");
8
+ var _getAllowAddColumnCustomStep = require("../utils/get-allow-add-column-custom-step");
9
+ var deleteColumnsCommand = exports.deleteColumnsCommand = function deleteColumnsCommand(rect) {
10
+ return function (state, dispatch, view) {
11
+ var tr = (0, _deleteColumns.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(state), view)(state.tr);
12
+ if (dispatch) {
13
+ dispatch(tr);
14
+ return true;
15
+ }
16
+ return false;
17
+ };
18
+ };
@@ -12,6 +12,7 @@ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
12
12
  var _utils = require("@atlaskit/editor-tables/utils");
13
13
  var _clear = require("./commands/clear");
14
14
  var _collapse = require("./commands/collapse");
15
+ var _delete = require("./commands/delete");
15
16
  var _insert = require("./commands/insert");
16
17
  var _misc = require("./commands/misc");
17
18
  var _sort = require("./commands/sort");
@@ -22,7 +23,6 @@ var _commands = require("./pm-plugins/table-resizing/commands");
22
23
  var _transforms = require("./transforms");
23
24
  var _utils2 = require("./utils");
24
25
  var _analytics2 = require("./utils/analytics");
25
- var _getAllowAddColumnCustomStep = require("./utils/get-allow-add-column-custom-step");
26
26
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
27
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
28
  var TABLE_BREAKOUT_NAME_MAPPING = {
@@ -258,12 +258,7 @@ var deleteColumnsWithAnalytics = exports.deleteColumnsWithAnalytics = function d
258
258
  },
259
259
  eventType: _analytics.EVENT_TYPE.TRACK
260
260
  };
261
- })(editorAnalyticsAPI)(function (state, dispatch) {
262
- if (dispatch) {
263
- dispatch((0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(state))(state.tr));
264
- }
265
- return true;
266
- });
261
+ })(editorAnalyticsAPI)((0, _delete.deleteColumnsCommand)(rect));
267
262
  };
268
263
  };
269
264
  var getTableDeletedAnalytics = function getTableDeletedAnalytics(selection, inputMethod) {
@@ -259,7 +259,7 @@ function handleTripleClick(view, pos) {
259
259
  }
260
260
  return false;
261
261
  }
262
- var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI) {
262
+ var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI, editorView) {
263
263
  var oldSelection = oldState.tr.selection;
264
264
  var tr = newState.tr;
265
265
  if (oldSelection instanceof _cellSelection.CellSelection) {
@@ -302,7 +302,7 @@ var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState
302
302
  isHeaderRowRequired = _getPluginState6.pluginConfig.isHeaderRowRequired;
303
303
  tr = (0, _transforms.deleteRows)(rect, isHeaderRowRequired)(tr);
304
304
  } else if (tr.selection.isColSelection()) {
305
- tr = (0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(oldState))(tr);
305
+ tr = (0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(oldState), editorView)(tr);
306
306
  }
307
307
  }
308
308
  }
@@ -100,7 +100,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
100
100
  }
101
101
  if (tr) {
102
102
  // "fixTables" removes empty rows as we don't allow that in schema
103
- var updatedTr = (0, _eventHandlers.handleCut)(tr, oldState, newState, editorAnalyticsAPI);
103
+ var updatedTr = (0, _eventHandlers.handleCut)(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
104
104
  return (0, _transforms2.fixTables)(updatedTr) || updatedTr;
105
105
  }
106
106
  if (transactions.find(function (tr) {
@@ -4,10 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateColumnWidths = exports.rescaleColumns = void 0;
7
+ exports.updateColumnWidths = exports.rescaleColumnsOld = exports.rescaleColumnsNew = exports.rescaleColumns = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _steps = require("@atlaskit/adf-schema/steps");
10
9
  var _styles = require("@atlaskit/editor-common/styles");
10
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
11
11
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
12
  var _tableMap = require("@atlaskit/editor-tables/table-map");
13
13
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -19,6 +19,13 @@ var _scaleTable = require("../pm-plugins/table-resizing/utils/scale-table");
19
19
  var _commonStyles = require("../ui/common-styles");
20
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
+ /**
23
+ * Given a new ResizeState object, create a transaction that replaces and updates the table node based on new state.
24
+ * @param resizeState
25
+ * @param table
26
+ * @param start
27
+ * @returns
28
+ */
22
29
  var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidths(resizeState, table, start) {
23
30
  return function (tr) {
24
31
  var map = _tableMap.TableMap.get(table);
@@ -69,7 +76,7 @@ var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidth
69
76
  var cell = table.nodeAt(pos);
70
77
  if (!seen[pos] && cell) {
71
78
  if (updatedCellsAttrs[pos]) {
72
- tr.step(new _steps.SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
79
+ tr.step(new _transform.AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
73
80
  }
74
81
  seen[pos] = true;
75
82
  }
@@ -121,10 +128,102 @@ var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidth
121
128
  * @param view
122
129
  * @returns Updated transaction with rescaled columns for a given table
123
130
  */
124
- var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
131
+ var rescaleColumnsNew = exports.rescaleColumnsNew = function rescaleColumnsNew() {
132
+ return function (table, view) {
133
+ return function (tr) {
134
+ var _tableRef$parentEleme, _tableRef$parentEleme2;
135
+ if (!view) {
136
+ return tr;
137
+ }
138
+ var newTable = tr.doc.nodeAt(table.pos);
139
+ var domAtPos = view.domAtPos.bind(view);
140
+ var maybeTable = domAtPos(table.start).node;
141
+ var tableRef = maybeTable.closest('table');
142
+ if (!tableRef || !newTable) {
143
+ return tr;
144
+ }
145
+ var isResized = (0, _utils.hasTableBeenResized)(table.node);
146
+ // get current table info
147
+ var previousTableInfo = {
148
+ // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
149
+ width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
150
+ /** the is the width the table can reach before overflowing */
151
+ possibleMaxWidth: (0, _platformFeatureFlags.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) - _commonStyles.insertColumnButtonOffset - 1,
152
+ isResized: isResized
153
+ };
154
+
155
+ // determine the new table, based on new width
156
+ var newTableInfo = {
157
+ noOfColumns: _tableMap.TableMap.get(newTable).width
158
+ };
159
+ if (!newTableInfo.noOfColumns || newTableInfo.noOfColumns <= 0) {
160
+ return tr;
161
+ }
162
+ var averageColumnWidth = previousTableInfo.width / newTableInfo.noOfColumns;
163
+
164
+ // If the table has not been resized (i.e. all columns will have the same width) and every column width is bigger than the minimum column width
165
+ // we skip updating the size of columns here.
166
+ if (!previousTableInfo.isResized && averageColumnWidth > _styles.tableCellMinWidth) {
167
+ return tr;
168
+ }
169
+ var wasTableInOverflow = previousTableInfo.width > previousTableInfo.possibleMaxWidth;
170
+
171
+ // If the table has not been resized, and each column width is smaller than the minimum column width
172
+ // Or if the table has been resized, but each column width is either 48px or null
173
+ // we update the table to have 48px for each column
174
+ if (!previousTableInfo.isResized && averageColumnWidth <= _styles.tableCellMinWidth || previousTableInfo.isResized && (0, _colgroup.isMinCellWidthTable)(table.node)) {
175
+ var widths = new Array(newTableInfo.noOfColumns).fill(_styles.tableCellMinWidth);
176
+ var cols = widths.map(function (_, index) {
177
+ return {
178
+ width: _styles.tableCellMinWidth,
179
+ minWidth: _styles.tableCellMinWidth,
180
+ index: index
181
+ };
182
+ });
183
+ var minWidthResizeState = {
184
+ cols: cols,
185
+ widths: widths,
186
+ maxSize: previousTableInfo.possibleMaxWidth,
187
+ tableWidth: previousTableInfo.width,
188
+ overflow: wasTableInOverflow
189
+ };
190
+ return updateColumnWidths(minWidthResizeState, table.node, table.start)(tr);
191
+ }
192
+ var resizeState = (0, _resizeState.getResizeState)({
193
+ minWidth: _styles.tableCellMinWidth,
194
+ table: table.node,
195
+ start: table.start,
196
+ tableRef: tableRef,
197
+ domAtPos: domAtPos,
198
+ maxSize: previousTableInfo.possibleMaxWidth
199
+ });
200
+
201
+ // Two scenarios that require scaling:
202
+ // 1. If the new table width will result in the table going into overflow
203
+ // we resize the cells to avoid it (e.g. adding a column)
204
+ // 2. If the new table width will be shorter than the parent width, scale columns to fit parent
205
+ if (!wasTableInOverflow && resizeState.overflow || resizeState.tableWidth < resizeState.maxSize) {
206
+ resizeState = (0, _scaleTable.scaleTableTo)(resizeState, previousTableInfo.possibleMaxWidth);
207
+ }
208
+ return updateColumnWidths(resizeState, table.node, table.start)(tr);
209
+ };
210
+ };
211
+ };
212
+
213
+ /**
214
+ * This function is called when user inserts/deletes a column in a table to;
215
+ * - rescale all columns (if the table did not overflow before the insertion)
216
+ * - and update column widths.
217
+ *
218
+ * This is done manually to avoid a multi-dispatch in TableComponent. See [ED-8288].
219
+ * @param table
220
+ * @param view
221
+ * @returns Updated transaction with rescaled columns for a given table
222
+ */
223
+ var rescaleColumnsOld = exports.rescaleColumnsOld = function rescaleColumnsOld(getEditorContainerWidth) {
125
224
  return function (table, view) {
126
225
  return function (tr) {
127
- var _tableRef$parentEleme;
226
+ var _tableRef$parentEleme3;
128
227
  if (!view) {
129
228
  return tr;
130
229
  }
@@ -147,7 +246,7 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorC
147
246
  getEditorContainerWidth: getEditorContainerWidth
148
247
  });
149
248
  var tableWidth = tableRef.clientWidth || _editorSharedStyles.akEditorDefaultLayoutWidth;
150
- var tableMaxWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0;
249
+ var tableMaxWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme3 = tableRef.parentElement) === null || _tableRef$parentEleme3 === void 0 ? void 0 : _tableRef$parentEleme3.clientWidth) || 0;
151
250
  tableMaxWidth -= _commonStyles.insertColumnButtonOffset;
152
251
  var newTableMap = _tableMap.TableMap.get(newTable);
153
252
  var noOfColumns = newTableMap.width;
@@ -192,7 +291,7 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorC
192
291
  domAtPos: domAtPos,
193
292
  maxSize: maxSize
194
293
  });
195
- var previousTableWidth = resizeState.tableWidth - _styles.tableNewColumnMinWidth;
294
+ var previousTableWidth = resizeState.tableWidth - _tableMap.tableNewColumnMinWidth;
196
295
  var tableDidntPreviouslyOverflow = previousTableWidth <= Math.max(maxSize, tableMaxWidth);
197
296
 
198
297
  // If the new table width will result in the table going into an overflow state
@@ -203,4 +302,10 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorC
203
302
  return updateColumnWidths(resizeState, table.node, table.start)(tr);
204
303
  };
205
304
  };
305
+ };
306
+ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
307
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-update-colwidths-after-column-is-deleted')) {
308
+ return rescaleColumnsNew();
309
+ }
310
+ return rescaleColumnsOld(getEditorContainerWidth);
206
311
  };
@@ -12,7 +12,9 @@ var _analytics = require("@atlaskit/editor-common/analytics");
12
12
  var _state = require("@atlaskit/editor-prosemirror/state");
13
13
  var _tableMap = require("@atlaskit/editor-tables/table-map");
14
14
  var _utils = require("@atlaskit/editor-tables/utils");
15
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
16
  var _tableAnalytics = require("../pm-plugins/table-analytics");
17
+ var _columnWidth = require("./column-width");
16
18
  var _split = require("./split");
17
19
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
20
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -210,15 +212,23 @@ function fixRowSpans(table) {
210
212
  }
211
213
  return table.type.createChecked(table.attrs, rows, table.marks);
212
214
  }
213
- var deleteColumns = exports.deleteColumns = function deleteColumns(rect) {
214
- var allowAddColumnCustomStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
215
+ var deleteColumns = exports.deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
215
216
  return function (tr) {
216
- tr.setMeta(_tableAnalytics.META_KEYS.OVERFLOW_TRIGGER, {
217
+ var updatedTr = tr;
218
+ updatedTr.setMeta(_tableAnalytics.META_KEYS.OVERFLOW_TRIGGER, {
217
219
  name: _analytics.TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN
218
220
  });
219
- if (allowAddColumnCustomStep) {
220
- return deleteColumnsCustomStep(rect)(tr);
221
+ if (allowCustomStep) {
222
+ updatedTr = deleteColumnsCustomStep(rect)(updatedTr);
223
+ } else {
224
+ updatedTr = deleteColumnsLegacy(rect)(updatedTr);
225
+ }
226
+ var table = (0, _utils.findTable)(updatedTr.selection);
227
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-update-colwidths-after-column-is-deleted')) {
228
+ if (table) {
229
+ updatedTr = (0, _columnWidth.rescaleColumns)()(table, view)(updatedTr);
230
+ }
221
231
  }
222
- return deleteColumnsLegacy(rect)(tr);
232
+ return updatedTr;
223
233
  };
224
234
  };
@@ -304,7 +304,7 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
304
304
  _this.toggleOpen();
305
305
  break;
306
306
  case 'delete_column':
307
- (0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch);
307
+ (0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch, editorView);
308
308
  _this.toggleOpen();
309
309
  break;
310
310
  case 'delete_row':
@@ -125,7 +125,7 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
125
125
  switch (_this.state.selectionType) {
126
126
  case 'column':
127
127
  {
128
- (0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.BUTTON, rect)(state, dispatch);
128
+ (0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.BUTTON, rect)(state, dispatch, _this.props.editorView);
129
129
  return;
130
130
  }
131
131
  case 'row':
@@ -56,7 +56,7 @@ var tableStickyHeaderColumnControlsDecorationsStyle = function tableStickyHeader
56
56
  };
57
57
  var tableWrapperStyles = function tableWrapperStyles() {
58
58
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
59
- return (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n padding-bottom: 0px;\n /* fixes gap cursor height */\n overflow: auto;\n overflow-y: hidden;\n position: relative;\n\n > table[data-number-column='true'] {\n margin-left: 1px;\n width: calc(100% - 1px);\n }\n }\n "])), _types.TableCssClassName.TABLE_NODE_WRAPPER);
59
+ return (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n padding-bottom: 0px;\n /* fixes gap cursor height */\n overflow: auto;\n overflow-y: hidden;\n position: relative;\n\n > table[data-number-column='true'] {\n width: calc(100% - 1px);\n }\n }\n "])), _types.TableCssClassName.TABLE_NODE_WRAPPER);
60
60
  } else {
61
61
  return (0, _react.css)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n padding-right: ", "px;\n margin-right: -", "px;\n padding-bottom: 0px;\n /* fixes gap cursor height */\n overflow: auto;\n overflow-y: hidden;\n position: relative;\n }\n "])), _types.TableCssClassName.TABLE_NODE_WRAPPER, insertColumnButtonOffset, insertColumnButtonOffset);
62
62
  }
@@ -0,0 +1,10 @@
1
+ import { deleteColumns } from '../transforms/delete-columns';
2
+ import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
3
+ export const deleteColumnsCommand = rect => (state, dispatch, view) => {
4
+ const tr = deleteColumns(rect, getAllowAddColumnCustomStep(state), view)(state.tr);
5
+ if (dispatch) {
6
+ dispatch(tr);
7
+ return true;
8
+ }
9
+ return false;
10
+ };
@@ -4,6 +4,7 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { findCellClosestToPos, findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
5
5
  import { clearMultipleCells } from './commands/clear';
6
6
  import { wrapTableInExpand } from './commands/collapse';
7
+ import { deleteColumnsCommand } from './commands/delete';
7
8
  import { insertColumn, insertRow } from './commands/insert';
8
9
  import { deleteTable, deleteTableIfSelected, setMultipleCellAttrs } from './commands/misc';
9
10
  import { sortByColumn } from './commands/sort';
@@ -11,10 +12,9 @@ import { splitCell } from './commands/split-cell';
11
12
  import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
12
13
  import { getPluginState } from './pm-plugins/plugin-factory';
13
14
  import { distributeColumnsWidths } from './pm-plugins/table-resizing/commands';
14
- import { deleteColumns, deleteRows, mergeCells } from './transforms';
15
+ import { deleteRows, mergeCells } from './transforms';
15
16
  import { checkIfNumberColumnEnabled, getSelectedCellInfo, getSelectedTableInfo } from './utils';
16
17
  import { withEditorAnalyticsAPI } from './utils/analytics';
17
- import { getAllowAddColumnCustomStep } from './utils/get-allow-add-column-custom-step';
18
18
  const TABLE_BREAKOUT_NAME_MAPPING = {
19
19
  default: TABLE_BREAKOUT.NORMAL,
20
20
  wide: TABLE_BREAKOUT.WIDE,
@@ -231,12 +231,7 @@ export const deleteColumnsWithAnalytics = editorAnalyticsAPI => (inputMethod, re
231
231
  },
232
232
  eventType: EVENT_TYPE.TRACK
233
233
  };
234
- })(editorAnalyticsAPI)((state, dispatch) => {
235
- if (dispatch) {
236
- dispatch(deleteColumns(rect, getAllowAddColumnCustomStep(state))(state.tr));
237
- }
238
- return true;
239
- });
234
+ })(editorAnalyticsAPI)(deleteColumnsCommand(rect));
240
235
  const getTableDeletedAnalytics = (selection, inputMethod) => {
241
236
  const {
242
237
  totalRowCount,
@@ -263,7 +263,7 @@ export function handleTripleClick(view, pos) {
263
263
  }
264
264
  return false;
265
265
  }
266
- export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI) => {
266
+ export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI, editorView) => {
267
267
  const oldSelection = oldState.tr.selection;
268
268
  let {
269
269
  tr
@@ -312,7 +312,7 @@ export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI) => {
312
312
  } = getPluginState(newState);
313
313
  tr = deleteRows(rect, isHeaderRowRequired)(tr);
314
314
  } else if (tr.selection.isColSelection()) {
315
- tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState))(tr);
315
+ tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView)(tr);
316
316
  }
317
317
  }
318
318
  }
@@ -82,7 +82,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
82
82
  }
83
83
  if (tr) {
84
84
  // "fixTables" removes empty rows as we don't allow that in schema
85
- const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI);
85
+ const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
86
86
  return fixTables(updatedTr) || updatedTr;
87
87
  }
88
88
  if (transactions.find(tr => tr.docChanged)) {
@@ -1,7 +1,7 @@
1
- import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
2
- import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
1
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
+ import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
4
- import { TableMap } from '@atlaskit/editor-tables/table-map';
4
+ import { TableMap, tableNewColumnMinWidth } from '@atlaskit/editor-tables/table-map';
5
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
6
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
7
7
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
@@ -9,6 +9,14 @@ import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
9
9
  import { getResizeState, normaliseTableLayout } from '../pm-plugins/table-resizing/utils/resize-state';
10
10
  import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
11
11
  import { insertColumnButtonOffset } from '../ui/common-styles';
12
+
13
+ /**
14
+ * Given a new ResizeState object, create a transaction that replaces and updates the table node based on new state.
15
+ * @param resizeState
16
+ * @param table
17
+ * @param start
18
+ * @returns
19
+ */
12
20
  export const updateColumnWidths = (resizeState, table, start) => tr => {
13
21
  const map = TableMap.get(table);
14
22
  const updatedCellsAttrs = {};
@@ -61,7 +69,7 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
61
69
  const cell = table.nodeAt(pos);
62
70
  if (!seen[pos] && cell) {
63
71
  if (updatedCellsAttrs[pos]) {
64
- tr.step(new SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
72
+ tr.step(new AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
65
73
  }
66
74
  seen[pos] = true;
67
75
  }
@@ -112,8 +120,94 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
112
120
  * @param view
113
121
  * @returns Updated transaction with rescaled columns for a given table
114
122
  */
115
- export const rescaleColumns = getEditorContainerWidth => (table, view) => tr => {
116
- var _tableRef$parentEleme;
123
+ export const rescaleColumnsNew = () => (table, view) => tr => {
124
+ var _tableRef$parentEleme, _tableRef$parentEleme2;
125
+ if (!view) {
126
+ return tr;
127
+ }
128
+ const newTable = tr.doc.nodeAt(table.pos);
129
+ const domAtPos = view.domAtPos.bind(view);
130
+ const maybeTable = domAtPos(table.start).node;
131
+ const tableRef = maybeTable.closest('table');
132
+ if (!tableRef || !newTable) {
133
+ return tr;
134
+ }
135
+ const isResized = hasTableBeenResized(table.node);
136
+ // get current table info
137
+ const previousTableInfo = {
138
+ // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
139
+ width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
140
+ /** the is the width the table can reach before overflowing */
141
+ 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 - 1,
142
+ isResized
143
+ };
144
+
145
+ // determine the new table, based on new width
146
+ const newTableInfo = {
147
+ noOfColumns: TableMap.get(newTable).width
148
+ };
149
+ if (!newTableInfo.noOfColumns || newTableInfo.noOfColumns <= 0) {
150
+ return tr;
151
+ }
152
+ const averageColumnWidth = previousTableInfo.width / newTableInfo.noOfColumns;
153
+
154
+ // If the table has not been resized (i.e. all columns will have the same width) and every column width is bigger than the minimum column width
155
+ // we skip updating the size of columns here.
156
+ if (!previousTableInfo.isResized && averageColumnWidth > tableCellMinWidth) {
157
+ return tr;
158
+ }
159
+ const wasTableInOverflow = previousTableInfo.width > previousTableInfo.possibleMaxWidth;
160
+
161
+ // If the table has not been resized, and each column width is smaller than the minimum column width
162
+ // Or if the table has been resized, but each column width is either 48px or null
163
+ // we update the table to have 48px for each column
164
+ if (!previousTableInfo.isResized && averageColumnWidth <= tableCellMinWidth || previousTableInfo.isResized && isMinCellWidthTable(table.node)) {
165
+ const widths = new Array(newTableInfo.noOfColumns).fill(tableCellMinWidth);
166
+ const cols = widths.map((_, index) => ({
167
+ width: tableCellMinWidth,
168
+ minWidth: tableCellMinWidth,
169
+ index
170
+ }));
171
+ const minWidthResizeState = {
172
+ cols,
173
+ widths,
174
+ maxSize: previousTableInfo.possibleMaxWidth,
175
+ tableWidth: previousTableInfo.width,
176
+ overflow: wasTableInOverflow
177
+ };
178
+ return updateColumnWidths(minWidthResizeState, table.node, table.start)(tr);
179
+ }
180
+ let resizeState = getResizeState({
181
+ minWidth: tableCellMinWidth,
182
+ table: table.node,
183
+ start: table.start,
184
+ tableRef,
185
+ domAtPos,
186
+ maxSize: previousTableInfo.possibleMaxWidth
187
+ });
188
+
189
+ // Two scenarios that require scaling:
190
+ // 1. If the new table width will result in the table going into overflow
191
+ // we resize the cells to avoid it (e.g. adding a column)
192
+ // 2. If the new table width will be shorter than the parent width, scale columns to fit parent
193
+ if (!wasTableInOverflow && resizeState.overflow || resizeState.tableWidth < resizeState.maxSize) {
194
+ resizeState = scaleTableTo(resizeState, previousTableInfo.possibleMaxWidth);
195
+ }
196
+ return updateColumnWidths(resizeState, table.node, table.start)(tr);
197
+ };
198
+
199
+ /**
200
+ * This function is called when user inserts/deletes a column in a table to;
201
+ * - rescale all columns (if the table did not overflow before the insertion)
202
+ * - and update column widths.
203
+ *
204
+ * This is done manually to avoid a multi-dispatch in TableComponent. See [ED-8288].
205
+ * @param table
206
+ * @param view
207
+ * @returns Updated transaction with rescaled columns for a given table
208
+ */
209
+ export const rescaleColumnsOld = getEditorContainerWidth => (table, view) => tr => {
210
+ var _tableRef$parentEleme3;
117
211
  if (!view) {
118
212
  return tr;
119
213
  }
@@ -138,7 +232,7 @@ export const rescaleColumns = getEditorContainerWidth => (table, view) => tr =>
138
232
  getEditorContainerWidth
139
233
  });
140
234
  const tableWidth = tableRef.clientWidth || akEditorDefaultLayoutWidth;
141
- let tableMaxWidth = (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0;
235
+ let tableMaxWidth = (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme3 = tableRef.parentElement) === null || _tableRef$parentEleme3 === void 0 ? void 0 : _tableRef$parentEleme3.clientWidth) || 0;
142
236
  tableMaxWidth -= insertColumnButtonOffset;
143
237
  const newTableMap = TableMap.get(newTable);
144
238
  const noOfColumns = newTableMap.width;
@@ -190,4 +284,10 @@ export const rescaleColumns = getEditorContainerWidth => (table, view) => tr =>
190
284
  resizeState = scaleTableTo(resizeState, maxSize);
191
285
  }
192
286
  return updateColumnWidths(resizeState, table.node, table.start)(tr);
287
+ };
288
+ export const rescaleColumns = getEditorContainerWidth => {
289
+ if (getBooleanFF('platform.editor.table-update-colwidths-after-column-is-deleted')) {
290
+ return rescaleColumnsNew();
291
+ }
292
+ return rescaleColumnsOld(getEditorContainerWidth);
193
293
  };
@@ -3,7 +3,9 @@ import { TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics
3
3
  import { Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { findTable } from '@atlaskit/editor-tables/utils';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
7
  import { META_KEYS } from '../pm-plugins/table-analytics';
8
+ import { rescaleColumns } from './column-width';
7
9
  import { splitCellsInColumns } from './split';
8
10
  const deleteColumnsCustomStep = rect => tr => {
9
11
  const table = findTable(tr.selection);
@@ -191,12 +193,21 @@ function fixRowSpans(table) {
191
193
  }
192
194
  return table.type.createChecked(table.attrs, rows, table.marks);
193
195
  }
194
- export const deleteColumns = (rect, allowAddColumnCustomStep = false) => tr => {
195
- tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
196
+ export const deleteColumns = (rect, allowCustomStep, view) => tr => {
197
+ let updatedTr = tr;
198
+ updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
196
199
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN
197
200
  });
198
- if (allowAddColumnCustomStep) {
199
- return deleteColumnsCustomStep(rect)(tr);
201
+ if (allowCustomStep) {
202
+ updatedTr = deleteColumnsCustomStep(rect)(updatedTr);
203
+ } else {
204
+ updatedTr = deleteColumnsLegacy(rect)(updatedTr);
205
+ }
206
+ const table = findTable(updatedTr.selection);
207
+ if (getBooleanFF('platform.editor.table-update-colwidths-after-column-is-deleted')) {
208
+ if (table) {
209
+ updatedTr = rescaleColumns()(table, view)(updatedTr);
210
+ }
200
211
  }
201
- return deleteColumnsLegacy(rect)(tr);
212
+ return updatedTr;
202
213
  };
@@ -300,7 +300,7 @@ export class ContextualMenu extends Component {
300
300
  this.toggleOpen();
301
301
  break;
302
302
  case 'delete_column':
303
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch);
303
+ deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch, editorView);
304
304
  this.toggleOpen();
305
305
  break;
306
306
  case 'delete_row':
@@ -108,7 +108,7 @@ class FloatingDeleteButton extends Component {
108
108
  switch (this.state.selectionType) {
109
109
  case 'column':
110
110
  {
111
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.BUTTON, rect)(state, dispatch);
111
+ deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.BUTTON, rect)(state, dispatch, this.props.editorView);
112
112
  return;
113
113
  }
114
114
  case 'row':
@@ -169,7 +169,6 @@ const tableWrapperStyles = () => {
169
169
  position: relative;
170
170
 
171
171
  > table[data-number-column='true'] {
172
- margin-left: 1px;
173
172
  width: calc(100% - 1px);
174
173
  }
175
174
  }
@@ -0,0 +1,12 @@
1
+ import { deleteColumns } from '../transforms/delete-columns';
2
+ import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
3
+ export var deleteColumnsCommand = function deleteColumnsCommand(rect) {
4
+ return function (state, dispatch, view) {
5
+ var tr = deleteColumns(rect, getAllowAddColumnCustomStep(state), view)(state.tr);
6
+ if (dispatch) {
7
+ dispatch(tr);
8
+ return true;
9
+ }
10
+ return false;
11
+ };
12
+ };