@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
@@ -7,6 +7,7 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
7
7
  import { findCellClosestToPos, findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
8
8
  import { clearMultipleCells } from './commands/clear';
9
9
  import { wrapTableInExpand } from './commands/collapse';
10
+ import { deleteColumnsCommand } from './commands/delete';
10
11
  import { insertColumn, insertRow } from './commands/insert';
11
12
  import { deleteTable, deleteTableIfSelected, setMultipleCellAttrs } from './commands/misc';
12
13
  import { sortByColumn } from './commands/sort';
@@ -14,10 +15,9 @@ import { splitCell } from './commands/split-cell';
14
15
  import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
15
16
  import { getPluginState } from './pm-plugins/plugin-factory';
16
17
  import { distributeColumnsWidths } from './pm-plugins/table-resizing/commands';
17
- import { deleteColumns, deleteRows, mergeCells } from './transforms';
18
+ import { deleteRows, mergeCells } from './transforms';
18
19
  import { checkIfNumberColumnEnabled, getSelectedCellInfo, getSelectedTableInfo } from './utils';
19
20
  import { withEditorAnalyticsAPI } from './utils/analytics';
20
- import { getAllowAddColumnCustomStep } from './utils/get-allow-add-column-custom-step';
21
21
  var TABLE_BREAKOUT_NAME_MAPPING = {
22
22
  default: TABLE_BREAKOUT.NORMAL,
23
23
  wide: TABLE_BREAKOUT.WIDE,
@@ -251,12 +251,7 @@ export var deleteColumnsWithAnalytics = function deleteColumnsWithAnalytics(edit
251
251
  },
252
252
  eventType: EVENT_TYPE.TRACK
253
253
  };
254
- })(editorAnalyticsAPI)(function (state, dispatch) {
255
- if (dispatch) {
256
- dispatch(deleteColumns(rect, getAllowAddColumnCustomStep(state))(state.tr));
257
- }
258
- return true;
259
- });
254
+ })(editorAnalyticsAPI)(deleteColumnsCommand(rect));
260
255
  };
261
256
  };
262
257
  var getTableDeletedAnalytics = function getTableDeletedAnalytics(selection, inputMethod) {
@@ -250,7 +250,7 @@ export function handleTripleClick(view, pos) {
250
250
  }
251
251
  return false;
252
252
  }
253
- export var handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI) {
253
+ export var handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI, editorView) {
254
254
  var oldSelection = oldState.tr.selection;
255
255
  var tr = newState.tr;
256
256
  if (oldSelection instanceof CellSelection) {
@@ -293,7 +293,7 @@ export var handleCut = function handleCut(oldTr, oldState, newState, editorAnaly
293
293
  isHeaderRowRequired = _getPluginState6.pluginConfig.isHeaderRowRequired;
294
294
  tr = deleteRows(rect, isHeaderRowRequired)(tr);
295
295
  } else if (tr.selection.isColSelection()) {
296
- tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState))(tr);
296
+ tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView)(tr);
297
297
  }
298
298
  }
299
299
  }
@@ -93,7 +93,7 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
93
93
  }
94
94
  if (tr) {
95
95
  // "fixTables" removes empty rows as we don't allow that in schema
96
- var updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI);
96
+ var updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
97
97
  return fixTables(updatedTr) || updatedTr;
98
98
  }
99
99
  if (transactions.find(function (tr) {
@@ -1,10 +1,10 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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) { _defineProperty(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; }
4
- import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
5
- import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
4
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
+ import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
6
6
  import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
7
- import { TableMap } from '@atlaskit/editor-tables/table-map';
7
+ import { TableMap, tableNewColumnMinWidth } from '@atlaskit/editor-tables/table-map';
8
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
9
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
10
10
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
@@ -12,6 +12,14 @@ import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
12
12
  import { getResizeState, normaliseTableLayout } from '../pm-plugins/table-resizing/utils/resize-state';
13
13
  import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
14
14
  import { insertColumnButtonOffset } from '../ui/common-styles';
15
+
16
+ /**
17
+ * Given a new ResizeState object, create a transaction that replaces and updates the table node based on new state.
18
+ * @param resizeState
19
+ * @param table
20
+ * @param start
21
+ * @returns
22
+ */
15
23
  export var updateColumnWidths = function updateColumnWidths(resizeState, table, start) {
16
24
  return function (tr) {
17
25
  var map = TableMap.get(table);
@@ -62,7 +70,7 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
62
70
  var cell = table.nodeAt(pos);
63
71
  if (!seen[pos] && cell) {
64
72
  if (updatedCellsAttrs[pos]) {
65
- tr.step(new SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
73
+ tr.step(new AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
66
74
  }
67
75
  seen[pos] = true;
68
76
  }
@@ -114,10 +122,102 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
114
122
  * @param view
115
123
  * @returns Updated transaction with rescaled columns for a given table
116
124
  */
117
- export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
125
+ export var rescaleColumnsNew = function rescaleColumnsNew() {
118
126
  return function (table, view) {
119
127
  return function (tr) {
120
- var _tableRef$parentEleme;
128
+ var _tableRef$parentEleme, _tableRef$parentEleme2;
129
+ if (!view) {
130
+ return tr;
131
+ }
132
+ var newTable = tr.doc.nodeAt(table.pos);
133
+ var domAtPos = view.domAtPos.bind(view);
134
+ var maybeTable = domAtPos(table.start).node;
135
+ var tableRef = maybeTable.closest('table');
136
+ if (!tableRef || !newTable) {
137
+ return tr;
138
+ }
139
+ var isResized = hasTableBeenResized(table.node);
140
+ // get current table info
141
+ var previousTableInfo = {
142
+ // when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
143
+ width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
144
+ /** the is the width the table can reach before overflowing */
145
+ 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 - 1,
146
+ isResized: isResized
147
+ };
148
+
149
+ // determine the new table, based on new width
150
+ var newTableInfo = {
151
+ noOfColumns: TableMap.get(newTable).width
152
+ };
153
+ if (!newTableInfo.noOfColumns || newTableInfo.noOfColumns <= 0) {
154
+ return tr;
155
+ }
156
+ var averageColumnWidth = previousTableInfo.width / newTableInfo.noOfColumns;
157
+
158
+ // 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
159
+ // we skip updating the size of columns here.
160
+ if (!previousTableInfo.isResized && averageColumnWidth > tableCellMinWidth) {
161
+ return tr;
162
+ }
163
+ var wasTableInOverflow = previousTableInfo.width > previousTableInfo.possibleMaxWidth;
164
+
165
+ // If the table has not been resized, and each column width is smaller than the minimum column width
166
+ // Or if the table has been resized, but each column width is either 48px or null
167
+ // we update the table to have 48px for each column
168
+ if (!previousTableInfo.isResized && averageColumnWidth <= tableCellMinWidth || previousTableInfo.isResized && isMinCellWidthTable(table.node)) {
169
+ var widths = new Array(newTableInfo.noOfColumns).fill(tableCellMinWidth);
170
+ var cols = widths.map(function (_, index) {
171
+ return {
172
+ width: tableCellMinWidth,
173
+ minWidth: tableCellMinWidth,
174
+ index: index
175
+ };
176
+ });
177
+ var minWidthResizeState = {
178
+ cols: cols,
179
+ widths: widths,
180
+ maxSize: previousTableInfo.possibleMaxWidth,
181
+ tableWidth: previousTableInfo.width,
182
+ overflow: wasTableInOverflow
183
+ };
184
+ return updateColumnWidths(minWidthResizeState, table.node, table.start)(tr);
185
+ }
186
+ var resizeState = getResizeState({
187
+ minWidth: tableCellMinWidth,
188
+ table: table.node,
189
+ start: table.start,
190
+ tableRef: tableRef,
191
+ domAtPos: domAtPos,
192
+ maxSize: previousTableInfo.possibleMaxWidth
193
+ });
194
+
195
+ // Two scenarios that require scaling:
196
+ // 1. If the new table width will result in the table going into overflow
197
+ // we resize the cells to avoid it (e.g. adding a column)
198
+ // 2. If the new table width will be shorter than the parent width, scale columns to fit parent
199
+ if (!wasTableInOverflow && resizeState.overflow || resizeState.tableWidth < resizeState.maxSize) {
200
+ resizeState = scaleTableTo(resizeState, previousTableInfo.possibleMaxWidth);
201
+ }
202
+ return updateColumnWidths(resizeState, table.node, table.start)(tr);
203
+ };
204
+ };
205
+ };
206
+
207
+ /**
208
+ * This function is called when user inserts/deletes a column in a table to;
209
+ * - rescale all columns (if the table did not overflow before the insertion)
210
+ * - and update column widths.
211
+ *
212
+ * This is done manually to avoid a multi-dispatch in TableComponent. See [ED-8288].
213
+ * @param table
214
+ * @param view
215
+ * @returns Updated transaction with rescaled columns for a given table
216
+ */
217
+ export var rescaleColumnsOld = function rescaleColumnsOld(getEditorContainerWidth) {
218
+ return function (table, view) {
219
+ return function (tr) {
220
+ var _tableRef$parentEleme3;
121
221
  if (!view) {
122
222
  return tr;
123
223
  }
@@ -140,7 +240,7 @@ export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
140
240
  getEditorContainerWidth: getEditorContainerWidth
141
241
  });
142
242
  var tableWidth = tableRef.clientWidth || akEditorDefaultLayoutWidth;
143
- var tableMaxWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0;
243
+ var tableMaxWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme3 = tableRef.parentElement) === null || _tableRef$parentEleme3 === void 0 ? void 0 : _tableRef$parentEleme3.clientWidth) || 0;
144
244
  tableMaxWidth -= insertColumnButtonOffset;
145
245
  var newTableMap = TableMap.get(newTable);
146
246
  var noOfColumns = newTableMap.width;
@@ -196,4 +296,10 @@ export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
196
296
  return updateColumnWidths(resizeState, table.node, table.start)(tr);
197
297
  };
198
298
  };
299
+ };
300
+ export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
301
+ if (getBooleanFF('platform.editor.table-update-colwidths-after-column-is-deleted')) {
302
+ return rescaleColumnsNew();
303
+ }
304
+ return rescaleColumnsOld(getEditorContainerWidth);
199
305
  };
@@ -7,7 +7,9 @@ import { TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics
7
7
  import { Selection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
9
  import { findTable } from '@atlaskit/editor-tables/utils';
10
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
11
  import { META_KEYS } from '../pm-plugins/table-analytics';
12
+ import { rescaleColumns } from './column-width';
11
13
  import { splitCellsInColumns } from './split';
12
14
  var deleteColumnsCustomStep = function deleteColumnsCustomStep(rect) {
13
15
  return function (tr) {
@@ -203,15 +205,23 @@ function fixRowSpans(table) {
203
205
  }
204
206
  return table.type.createChecked(table.attrs, rows, table.marks);
205
207
  }
206
- export var deleteColumns = function deleteColumns(rect) {
207
- var allowAddColumnCustomStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
208
+ export var deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
208
209
  return function (tr) {
209
- tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
210
+ var updatedTr = tr;
211
+ updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
210
212
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN
211
213
  });
212
- if (allowAddColumnCustomStep) {
213
- return deleteColumnsCustomStep(rect)(tr);
214
+ if (allowCustomStep) {
215
+ updatedTr = deleteColumnsCustomStep(rect)(updatedTr);
216
+ } else {
217
+ updatedTr = deleteColumnsLegacy(rect)(updatedTr);
218
+ }
219
+ var table = findTable(updatedTr.selection);
220
+ if (getBooleanFF('platform.editor.table-update-colwidths-after-column-is-deleted')) {
221
+ if (table) {
222
+ updatedTr = rescaleColumns()(table, view)(updatedTr);
223
+ }
214
224
  }
215
- return deleteColumnsLegacy(rect)(tr);
225
+ return updatedTr;
216
226
  };
217
227
  };
@@ -298,7 +298,7 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
298
298
  _this.toggleOpen();
299
299
  break;
300
300
  case 'delete_column':
301
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch);
301
+ deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch, editorView);
302
302
  _this.toggleOpen();
303
303
  break;
304
304
  case 'delete_row':
@@ -114,7 +114,7 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
114
114
  switch (_this.state.selectionType) {
115
115
  case 'column':
116
116
  {
117
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.BUTTON, rect)(state, dispatch);
117
+ deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.BUTTON, rect)(state, dispatch, _this.props.editorView);
118
118
  return;
119
119
  }
120
120
  case 'row':
@@ -49,7 +49,7 @@ var tableStickyHeaderColumnControlsDecorationsStyle = function tableStickyHeader
49
49
  };
50
50
  var tableWrapperStyles = function tableWrapperStyles() {
51
51
  if (getBooleanFF('platform.editor.custom-table-width')) {
52
- return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\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 "])), ClassName.TABLE_NODE_WRAPPER);
52
+ return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\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 "])), ClassName.TABLE_NODE_WRAPPER);
53
53
  } else {
54
54
  return css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\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 "])), ClassName.TABLE_NODE_WRAPPER, insertColumnButtonOffset, insertColumnButtonOffset);
55
55
  }
@@ -0,0 +1,3 @@
1
+ import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Rect } from '@atlaskit/editor-tables/table-map';
3
+ export declare const deleteColumnsCommand: (rect: Rect) => Command;
@@ -11,5 +11,5 @@ export declare const handleMouseOut: (view: EditorView, mouseEvent: Event) => bo
11
11
  export declare const handleMouseLeave: (view: EditorView, event: Event) => boolean;
12
12
  export declare const handleMouseMove: (view: EditorView, event: Event, elementContentRects?: ElementContentRects) => boolean;
13
13
  export declare function handleTripleClick(view: EditorView, pos: number): boolean;
14
- export declare const handleCut: (oldTr: Transaction, oldState: EditorState, newState: EditorState, editorAnalyticsAPI?: EditorAnalyticsAPI) => Transaction;
14
+ export declare const handleCut: (oldTr: Transaction, oldState: EditorState, newState: EditorState, editorAnalyticsAPI?: EditorAnalyticsAPI, editorView?: EditorView) => Transaction;
15
15
  export declare const whenTableInFocus: (eventHandler: (view: EditorView, mouseEvent: Event, elementContentRects?: ElementContentRects) => boolean, elementContentRects?: ElementContentRects) => (view: EditorView, mouseEvent: Event) => boolean;
@@ -16,5 +16,5 @@ interface getTableMaxWidthProps {
16
16
  layout: TableLayout;
17
17
  getEditorContainerWidth: GetEditorContainerWidth;
18
18
  }
19
- export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getEditorContainerWidth, }: getTableMaxWidthProps) => any;
19
+ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getEditorContainerWidth, }: getTableMaxWidthProps) => number;
20
20
  export {};
@@ -1,9 +1,16 @@
1
1
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
2
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
6
- import { ResizeState } from '../pm-plugins/table-resizing/utils';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { ResizeState } from '../pm-plugins/table-resizing/utils';
7
+ /**
8
+ * Given a new ResizeState object, create a transaction that replaces and updates the table node based on new state.
9
+ * @param resizeState
10
+ * @param table
11
+ * @param start
12
+ * @returns
13
+ */
7
14
  export declare const updateColumnWidths: (resizeState: ResizeState, table: PMNode, start: number) => (tr: Transaction) => Transaction;
8
15
  /**
9
16
  * This function is called when user inserts/deletes a column in a table to;
@@ -15,4 +22,16 @@ export declare const updateColumnWidths: (resizeState: ResizeState, table: PMNod
15
22
  * @param view
16
23
  * @returns Updated transaction with rescaled columns for a given table
17
24
  */
18
- export declare const rescaleColumns: (getEditorContainerWidth: GetEditorContainerWidth) => (table: ContentNodeWithPos, view: EditorView | undefined) => (tr: Transaction) => Transaction;
25
+ export declare const rescaleColumnsNew: () => (table: ContentNodeWithPos, view: EditorView | undefined) => (tr: Transaction) => Transaction;
26
+ /**
27
+ * This function is called when user inserts/deletes a column in a table to;
28
+ * - rescale all columns (if the table did not overflow before the insertion)
29
+ * - and update column widths.
30
+ *
31
+ * This is done manually to avoid a multi-dispatch in TableComponent. See [ED-8288].
32
+ * @param table
33
+ * @param view
34
+ * @returns Updated transaction with rescaled columns for a given table
35
+ */
36
+ export declare const rescaleColumnsOld: (getEditorContainerWidth: GetEditorContainerWidth) => (table: ContentNodeWithPos, view: EditorView | undefined) => (tr: Transaction) => Transaction;
37
+ export declare const rescaleColumns: (getEditorContainerWidth?: GetEditorContainerWidth) => (table: ContentNodeWithPos, view: EditorView | undefined) => (tr: Transaction) => Transaction;
@@ -1,3 +1,4 @@
1
1
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
3
  import type { Rect } from '@atlaskit/editor-tables/table-map';
3
- export declare const deleteColumns: (rect: Rect, allowAddColumnCustomStep?: boolean) => (tr: Transaction) => Transaction;
4
+ export declare const deleteColumns: (rect: Rect, allowCustomStep: boolean, view?: EditorView) => (tr: Transaction) => Transaction;
@@ -1,9 +1,9 @@
1
1
  import { Component } from 'react';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import { Selection } from '@atlaskit/editor-prosemirror/state';
4
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import { RowStickyState } from '../../pm-plugins/sticky-headers';
6
- import { CellSelectionType } from './types';
3
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ import type { RowStickyState } from '../../pm-plugins/sticky-headers';
6
+ import type { CellSelectionType } from './types';
7
7
  export interface Props {
8
8
  editorView: EditorView;
9
9
  selection: Selection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "4.1.1",
3
+ "version": "4.2.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^32.0.0",
31
31
  "@atlaskit/custom-steps": "^0.0.2",
32
- "@atlaskit/editor-common": "^76.6.0",
32
+ "@atlaskit/editor-common": "^76.7.0",
33
33
  "@atlaskit/editor-palette": "1.5.1",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.2.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -126,6 +126,9 @@
126
126
  },
127
127
  "platform.editor.table.update-table-resizer-styles": {
128
128
  "type": "boolean"
129
+ },
130
+ "platform.editor.table-update-colwidths-after-column-is-deleted": {
131
+ "type": "boolean"
129
132
  }
130
133
  }
131
134
  }
@@ -327,6 +327,7 @@ describe('table plugin: actions', () => {
327
327
  const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
328
328
  attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
329
329
  };
330
+
330
331
  describe('when the entire table is selected', () => {
331
332
  it('should remove the table', () => {
332
333
  const { editorView, refs } = editor(