@atlaskit/editor-plugin-table 4.1.0 → 4.2.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 (60) hide show
  1. package/CHANGELOG.md +13 -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/nodeviews/TableContainer.js +27 -9
  6. package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
  7. package/dist/cjs/plugins/table/transforms/column-width.js +110 -5
  8. package/dist/cjs/plugins/table/transforms/delete-columns.js +16 -6
  9. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  10. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  11. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  12. package/dist/es2019/plugins/table/commands/delete.js +10 -0
  13. package/dist/es2019/plugins/table/commands-with-analytics.js +3 -8
  14. package/dist/es2019/plugins/table/event-handlers.js +2 -2
  15. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +27 -9
  16. package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
  17. package/dist/es2019/plugins/table/transforms/column-width.js +105 -5
  18. package/dist/es2019/plugins/table/transforms/delete-columns.js +16 -5
  19. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  20. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  21. package/dist/es2019/plugins/table/ui/common-styles.js +0 -1
  22. package/dist/esm/plugins/table/commands/delete.js +12 -0
  23. package/dist/esm/plugins/table/commands-with-analytics.js +3 -8
  24. package/dist/esm/plugins/table/event-handlers.js +2 -2
  25. package/dist/esm/plugins/table/nodeviews/TableContainer.js +27 -9
  26. package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
  27. package/dist/esm/plugins/table/transforms/column-width.js +111 -5
  28. package/dist/esm/plugins/table/transforms/delete-columns.js +16 -6
  29. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  30. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  31. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  32. package/dist/types/plugins/table/commands/delete.d.ts +3 -0
  33. package/dist/types/plugins/table/event-handlers.d.ts +1 -1
  34. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +3 -3
  35. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  36. package/dist/types/plugins/table/transforms/column-width.d.ts +25 -6
  37. package/dist/types/plugins/table/transforms/delete-columns.d.ts +2 -1
  38. package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
  39. package/dist/types-ts4.5/plugins/table/commands/delete.d.ts +3 -0
  40. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -1
  41. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +3 -3
  42. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  43. package/dist/types-ts4.5/plugins/table/transforms/column-width.d.ts +25 -6
  44. package/dist/types-ts4.5/plugins/table/transforms/delete-columns.d.ts +2 -1
  45. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
  46. package/package.json +8 -2
  47. package/src/__tests__/unit/commands.ts +1 -0
  48. package/src/__tests__/unit/transforms/delete-columns.ts +406 -105
  49. package/src/__tests__/unit/undo-redo.ts +1 -1
  50. package/src/plugins/table/commands/delete.ts +20 -0
  51. package/src/plugins/table/commands-with-analytics.ts +3 -10
  52. package/src/plugins/table/event-handlers.ts +6 -1
  53. package/src/plugins/table/nodeviews/TableContainer.tsx +189 -159
  54. package/src/plugins/table/pm-plugins/main.ts +7 -1
  55. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +1 -1
  56. package/src/plugins/table/transforms/column-width.ts +155 -15
  57. package/src/plugins/table/transforms/delete-columns.ts +23 -6
  58. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +1 -1
  59. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +7 -6
  60. package/src/plugins/table/ui/common-styles.ts +0 -1
@@ -1,7 +1,7 @@
1
1
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
2
- import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
2
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
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 = {};
@@ -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
+ };
@@ -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
  }
@@ -34,7 +34,7 @@ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
34
34
  "data-test-id": "table-container"
35
35
  }, children);
36
36
  });
37
- export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
37
+ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
38
38
  var children = _ref2.children,
39
39
  className = _ref2.className,
40
40
  node = _ref2.node,
@@ -84,7 +84,6 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
84
84
  if (!containerRef.current) {
85
85
  return;
86
86
  }
87
- var marginLeft = getMarginLeft(lineLength, width);
88
87
 
89
88
  // make sure during resizing
90
89
  // the pm-table-resizer-container width is the same as its child div resizer-item
@@ -93,10 +92,13 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
93
92
  if (containerRef.current.style.width !== "".concat(width, "px")) {
94
93
  containerRef.current.style.width = "".concat(width, "px");
95
94
  }
96
- if (marginLeftRef.current !== marginLeft) {
97
- marginLeftRef.current = marginLeft;
98
- if (Number.isFinite(marginLeft)) {
99
- containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
95
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
96
+ var marginLeft = getMarginLeft(lineLength, width);
97
+ if (marginLeftRef.current !== marginLeft) {
98
+ marginLeftRef.current = marginLeft;
99
+ if (Number.isFinite(marginLeft)) {
100
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
101
+ }
100
102
  }
101
103
  }
102
104
  }, [lineLength]);
@@ -120,7 +122,9 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
120
122
  var width = Math.min(tableWidth, responsiveContainerWidth);
121
123
  if (!isResizing) {
122
124
  tableWidthRef.current = width;
123
- marginLeftRef.current = getMarginLeft(lineLength, width);
125
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
126
+ marginLeftRef.current = getMarginLeft(lineLength, width);
127
+ }
124
128
  }
125
129
  var maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
126
130
  var tableResizerProps = {
@@ -142,7 +146,21 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
142
146
  onResizeStop: onResizeStop
143
147
  });
144
148
  }
145
- return /*#__PURE__*/React.createElement("div", {
149
+ return getBooleanFF('platform.editor.table.update-table-resizer-styles') ? /*#__PURE__*/React.createElement("div", {
150
+ style: {
151
+ display: 'flex',
152
+ justifyContent: 'center'
153
+ }
154
+ }, /*#__PURE__*/React.createElement("div", {
155
+ style: {
156
+ width: tableWidthRef.current
157
+ },
158
+ className: ClassName.TABLE_RESIZER_CONTAINER,
159
+ ref: containerRef
160
+ }, /*#__PURE__*/React.createElement(TableResizer, tableResizerProps, /*#__PURE__*/React.createElement(InnerContainer, {
161
+ className: className,
162
+ node: node
163
+ }, children)))) : /*#__PURE__*/React.createElement("div", {
146
164
  style: {
147
165
  marginLeft: marginLeftRef.current,
148
166
  width: tableWidthRef.current
@@ -153,7 +171,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
153
171
  className: className,
154
172
  node: node
155
173
  }, children)));
156
- };
174
+ });
157
175
  export var TableContainer = function TableContainer(_ref3) {
158
176
  var children = _ref3.children,
159
177
  node = _ref3.node,
@@ -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) {
@@ -2,9 +2,9 @@ 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
4
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
5
- import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
5
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
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);
@@ -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;
@@ -8,7 +8,7 @@ type InnerContainerProps = {
8
8
  className: string;
9
9
  style?: {
10
10
  width: number | 'inherit';
11
- marginLeft: number | undefined;
11
+ marginLeft?: number;
12
12
  };
13
13
  node: PMNode;
14
14
  };
@@ -17,7 +17,7 @@ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContai
17
17
  } & React.RefAttributes<HTMLDivElement>>;
18
18
  type ResizableTableContainerProps = {
19
19
  containerWidth: number;
20
- lineLength: number;
20
+ lineLength?: number;
21
21
  node: PMNode;
22
22
  className: string;
23
23
  editorView: EditorView;
@@ -26,7 +26,7 @@ type ResizableTableContainerProps = {
26
26
  isResizing?: boolean;
27
27
  pluginInjectionApi?: PluginInjectionAPI;
28
28
  };
29
- export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
+ export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
30
30
  type TableContainerProps = {
31
31
  node: PMNode;
32
32
  className: string;
@@ -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 {};