@atlaskit/editor-plugin-table 8.4.14 → 9.0.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 (97) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +9 -84
  3. package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
  4. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +3 -144
  5. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +1 -2
  6. package/dist/cjs/pm-plugins/view-mode-sort/utils.js +3 -0
  7. package/dist/cjs/tablePlugin.js +3 -5
  8. package/dist/cjs/ui/DragPreview/index.js +1 -0
  9. package/dist/cjs/ui/FloatingContextualButton/index.js +1 -2
  10. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +2 -4
  11. package/dist/cjs/ui/toolbar.js +1 -4
  12. package/dist/es2019/nodeviews/TableContainer.js +1 -1
  13. package/dist/es2019/pm-plugins/commands/column-resize.js +1 -1
  14. package/dist/es2019/pm-plugins/commands/insert.js +3 -3
  15. package/dist/es2019/pm-plugins/commands/misc.js +1 -1
  16. package/dist/es2019/pm-plugins/drag-and-drop/commands.js +1 -1
  17. package/dist/es2019/pm-plugins/table-analytics.js +1 -1
  18. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +12 -84
  19. package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
  20. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +2 -2
  21. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +2 -139
  22. package/dist/es2019/pm-plugins/table-resizing/utils/resize-logic.js +1 -1
  23. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +1 -2
  24. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +1 -1
  25. package/dist/es2019/pm-plugins/transforms/delete-columns.js +1 -1
  26. package/dist/es2019/pm-plugins/transforms/fix-tables.js +1 -1
  27. package/dist/es2019/pm-plugins/transforms/replace-table.js +1 -1
  28. package/dist/es2019/pm-plugins/transforms/split.js +2 -2
  29. package/dist/es2019/pm-plugins/utils/analytics.js +4 -4
  30. package/dist/es2019/pm-plugins/utils/column-controls.js +1 -1
  31. package/dist/es2019/pm-plugins/utils/drag-menu.js +1 -1
  32. package/dist/es2019/pm-plugins/utils/merged-cells.js +4 -4
  33. package/dist/es2019/pm-plugins/utils/nodes.js +3 -3
  34. package/dist/es2019/pm-plugins/utils/row-controls.js +2 -2
  35. package/dist/es2019/pm-plugins/view-mode-sort/index.js +2 -2
  36. package/dist/es2019/pm-plugins/view-mode-sort/utils.js +4 -1
  37. package/dist/es2019/tablePlugin.js +3 -5
  38. package/dist/es2019/ui/DragPreview/index.js +4 -3
  39. package/dist/es2019/ui/FloatingContextualButton/index.js +1 -2
  40. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +4 -6
  41. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +4 -4
  42. package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +2 -2
  43. package/dist/es2019/ui/toolbar.js +1 -4
  44. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +11 -85
  45. package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
  46. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +2 -143
  47. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +1 -2
  48. package/dist/esm/pm-plugins/view-mode-sort/utils.js +3 -0
  49. package/dist/esm/tablePlugin.js +3 -5
  50. package/dist/esm/ui/DragPreview/index.js +1 -0
  51. package/dist/esm/ui/FloatingContextualButton/index.js +1 -2
  52. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +2 -4
  53. package/dist/esm/ui/toolbar.js +1 -4
  54. package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  55. package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
  56. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -24
  57. package/dist/types/tablePluginType.d.ts +0 -1
  58. package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  59. package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -1
  60. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -24
  61. package/dist/types-ts4.5/tablePluginType.d.ts +0 -1
  62. package/package.json +4 -4
  63. package/src/nodeviews/TableContainer.tsx +1 -1
  64. package/src/pm-plugins/commands/column-resize.ts +1 -1
  65. package/src/pm-plugins/commands/insert.ts +3 -3
  66. package/src/pm-plugins/commands/misc.ts +1 -1
  67. package/src/pm-plugins/drag-and-drop/commands.ts +1 -1
  68. package/src/pm-plugins/table-analytics.ts +1 -1
  69. package/src/pm-plugins/table-resizing/event-handlers.ts +35 -121
  70. package/src/pm-plugins/table-resizing/plugin.ts +0 -4
  71. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  72. package/src/pm-plugins/table-resizing/utils/resize-column.ts +1 -219
  73. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +1 -1
  74. package/src/pm-plugins/table-resizing/utils/resize-state.ts +1 -3
  75. package/src/pm-plugins/table-resizing/utils/scale-table.ts +1 -1
  76. package/src/pm-plugins/transforms/delete-columns.ts +1 -1
  77. package/src/pm-plugins/transforms/fix-tables.ts +1 -1
  78. package/src/pm-plugins/transforms/replace-table.ts +1 -1
  79. package/src/pm-plugins/transforms/split.ts +2 -2
  80. package/src/pm-plugins/utils/analytics.ts +4 -4
  81. package/src/pm-plugins/utils/column-controls.ts +1 -1
  82. package/src/pm-plugins/utils/drag-menu.ts +1 -1
  83. package/src/pm-plugins/utils/merged-cells.ts +4 -4
  84. package/src/pm-plugins/utils/nodes.ts +3 -3
  85. package/src/pm-plugins/utils/row-controls.ts +2 -2
  86. package/src/pm-plugins/view-mode-sort/index.ts +2 -2
  87. package/src/pm-plugins/view-mode-sort/utils.ts +3 -1
  88. package/src/tablePlugin.tsx +3 -10
  89. package/src/tablePluginType.ts +0 -1
  90. package/src/ui/DragPreview/index.tsx +4 -3
  91. package/src/ui/FloatingContextualButton/index.tsx +1 -2
  92. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +4 -6
  93. package/src/ui/FloatingDragMenu/DragMenu.tsx +4 -4
  94. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +2 -2
  95. package/src/ui/toolbar.tsx +1 -11
  96. package/tsconfig.app.json +0 -1
  97. package/tsconfig.dev.json +0 -1
@@ -1,27 +1,3 @@
1
- import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
2
1
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
2
  import type { ResizeState } from './types';
4
3
  export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, scalePercent?: number) => ResizeState;
5
- type ResizeInformation = {
6
- resizeState: ResizeState;
7
- colIndex: number;
8
- amount: number;
9
- };
10
- type TableReferences = {
11
- tableRef: HTMLElement;
12
- tableNode: PmNode;
13
- };
14
- type TableResizingPluginOptions = {
15
- isTableAlignmentEnabled?: boolean;
16
- };
17
- type ResizeColumnAndTable = ResizeInformation & TableResizingPluginOptions & TableReferences & EditorContainerWidth;
18
- export declare const resizeColumnAndTable: ({ resizeState, colIndex, amount, tableRef, tableNode, lineLength, width: editorWidth, isTableAlignmentEnabled, }: ResizeColumnAndTable) => ResizeState;
19
- /**
20
- * Apply a scaling factor to resize state
21
- */
22
- export declare const scaleResizeState: ({ resizeState, tableRef, tableNode, editorWidth, shouldUseIncreasedScalingPercent, }: TableReferences & {
23
- resizeState: ResizeState;
24
- editorWidth: number;
25
- shouldUseIncreasedScalingPercent: boolean;
26
- }) => ResizeState;
27
- export {};
@@ -18,7 +18,6 @@ export interface TablePluginOptions {
18
18
  fullWidthEnabled?: boolean;
19
19
  wasFullWidthEnabled?: boolean;
20
20
  getEditorFeatureFlags?: GetEditorFeatureFlags;
21
- isNewColumnResizingEnabled?: boolean;
22
21
  isCommentEditor?: boolean;
23
22
  isChromelessEditor?: boolean;
24
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "8.4.14",
3
+ "version": "9.0.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,11 +30,11 @@
30
30
  "@atlaskit/adf-schema": "^46.1.0",
31
31
  "@atlaskit/button": "^20.3.0",
32
32
  "@atlaskit/custom-steps": "^0.9.0",
33
- "@atlaskit/editor-common": "^97.2.0",
33
+ "@atlaskit/editor-common": "^98.0.0",
34
34
  "@atlaskit/editor-palette": "1.6.3",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
- "@atlaskit/editor-plugin-batch-attribute-updates": "1.1.9",
37
+ "@atlaskit/editor-plugin-batch-attribute-updates": "1.1.10",
38
38
  "@atlaskit/editor-plugin-content-insertion": "^1.11.0",
39
39
  "@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
40
40
  "@atlaskit/editor-plugin-guideline": "^1.2.0",
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
52
52
  "@atlaskit/primitives": "^13.3.0",
53
53
  "@atlaskit/theme": "^14.0.0",
54
- "@atlaskit/tmp-editor-statsig": "^2.30.0",
54
+ "@atlaskit/tmp-editor-statsig": "^2.31.0",
55
55
  "@atlaskit/toggle": "^14.0.0",
56
56
  "@atlaskit/tokens": "^2.5.0",
57
57
  "@atlaskit/tooltip": "^19.0.0",
@@ -303,7 +303,7 @@ export const ResizableTableContainer = React.memo(
303
303
  ? containerWidth - akEditorGutterPaddingDynamic() * 2
304
304
  : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
305
305
  }
306
- let width =
306
+ const width =
307
307
  !node.attrs.width && isCommentEditor
308
308
  ? responsiveContainerWidth
309
309
  : Math.min(tableWidth, responsiveContainerWidth);
@@ -382,7 +382,7 @@ export const changeColumnWidthByStep =
382
382
  isTableScalingEnabled && isCommentEditor && !originalTable.attrs?.width
383
383
  ? getScalingPercentForTableWithoutWidth(originalTable, dom)
384
384
  : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
385
- let newResizeState = resizeColumn(
385
+ const newResizeState = resizeColumn(
386
386
  initialResizeState,
387
387
  colIndex,
388
388
  stepSize,
@@ -134,7 +134,7 @@ export const addColumnBefore =
134
134
  return false;
135
135
  }
136
136
  if (dispatch) {
137
- let rect = selectedRect(state);
137
+ const rect = selectedRect(state);
138
138
  dispatch(
139
139
  addColumnAt(
140
140
  api,
@@ -171,7 +171,7 @@ export const addColumnAfter =
171
171
  }
172
172
 
173
173
  if (dispatch) {
174
- let rect = selectedRect(state);
174
+ const rect = selectedRect(state);
175
175
  dispatch(
176
176
  addColumnAt(
177
177
  api,
@@ -201,7 +201,7 @@ export const insertColumn =
201
201
  ) =>
202
202
  (column: number): Command =>
203
203
  (state, dispatch, view) => {
204
- let tr = addColumnAt(
204
+ const tr = addColumnAt(
205
205
  api,
206
206
  isTableScalingEnabled,
207
207
  isTableFixedColumnWidthsOptionEnabled,
@@ -737,7 +737,7 @@ export const addBoldInEmptyHeaderCells =
737
737
 
738
738
  export const updateWidthToWidest = (widthToWidest: WidthToWidest) =>
739
739
  createCommand((state) => {
740
- let { widthToWidest: prevWidthToWidest } = getPluginState(state);
740
+ const { widthToWidest: prevWidthToWidest } = getPluginState(state);
741
741
 
742
742
  if (isEqual(widthToWidest, prevWidthToWidest)) {
743
743
  return false;
@@ -122,7 +122,7 @@ export const toggleDragMenu = (
122
122
  ) =>
123
123
  createCommand(
124
124
  (state) => {
125
- let {
125
+ const {
126
126
  isDragMenuOpen: previousOpenState,
127
127
  dragMenuDirection: previousDragMenuDirection,
128
128
  dragMenuIndex: previousDragMenuIndex,
@@ -55,7 +55,7 @@ const createPlugin = (
55
55
  appendTransaction: (transactions, oldState, newState) => {
56
56
  const newPluginState = pluginKey.getState(newState);
57
57
  let hasAnalyticsBeenDispatched = false;
58
- let lastTriggerName =
58
+ const lastTriggerName =
59
59
  newPluginState?.lastTrigger?.name ||
60
60
  // NOTE: We assume that we know and can correctly differentiate
61
61
  // between all triggers of table overflow state change.
@@ -1,7 +1,6 @@
1
1
  import type { CellAttributes } from '@atlaskit/adf-schema';
2
2
  import {
3
3
  ACTION_SUBJECT,
4
- CHANGE_ALIGNMENT_REASON,
5
4
  EVENT_TYPE,
6
5
  INPUT_METHOD,
7
6
  TABLE_ACTION,
@@ -21,12 +20,6 @@ import { updateResizeHandleDecorations } from '../commands/misc';
21
20
  import { getPluginState as getTablePluginState } from '../plugin-factory';
22
21
  import { META_KEYS } from '../table-analytics';
23
22
  import { updateColumnWidths } from '../transforms/column-width';
24
- import {
25
- ALIGN_CENTER,
26
- ALIGN_START,
27
- shouldChangeAlignmentToCenterResized,
28
- } from '../utils/alignment';
29
- import { isTableNested } from '../utils/nodes';
30
23
  import { getSelectedColumnIndexes } from '../utils/selection';
31
24
 
32
25
  import { evenColumns, setDragging, stopResizing } from './commands';
@@ -40,7 +33,7 @@ import {
40
33
  getScalingPercentForTableWithoutWidth,
41
34
  getTableScalingPercent,
42
35
  } from './utils/misc';
43
- import { resizeColumn, resizeColumnAndTable, scaleResizeState } from './utils/resize-column';
36
+ import { resizeColumn } from './utils/resize-column';
44
37
  import { getResizeState } from './utils/resize-state';
45
38
 
46
39
  export const handleMouseDown = (
@@ -53,8 +46,6 @@ export const handleMouseDown = (
53
46
  api: PluginInjectionAPI | undefined | null,
54
47
  nodeViewPortalProviderAPI: PortalProviderAPI,
55
48
  editorAnalyticsAPI?: EditorAnalyticsAPI,
56
- isNewColumnResizingEnabled?: boolean,
57
- isTableAlignmentEnabled?: boolean,
58
49
  isCommentEditor?: boolean,
59
50
  // Ignored via go/ees005
60
51
  // eslint-disable-next-line @typescript-eslint/max-params
@@ -62,7 +53,7 @@ export const handleMouseDown = (
62
53
  const { state, dispatch } = view;
63
54
  const editorDisabled = !view.editable;
64
55
  const domAtPos = view.domAtPos.bind(view);
65
- const { lineLength, width: editorWidth } = getEditorContainerWidth();
56
+ const { width: editorWidth } = getEditorContainerWidth();
66
57
 
67
58
  if (
68
59
  editorDisabled ||
@@ -123,7 +114,7 @@ export const handleMouseDown = (
123
114
  shouldUseIncreasedScalingPercent = true;
124
115
  }
125
116
 
126
- let resizeState = getResizeState({
117
+ const resizeState = getResizeState({
127
118
  minWidth: tableCellMinWidth,
128
119
  maxSize,
129
120
  table: originalTable,
@@ -163,18 +154,6 @@ export const handleMouseDown = (
163
154
  false,
164
155
  )(state, dispatch);
165
156
 
166
- // for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
167
- // implication: the scaled version of the table becomes the source of truth
168
- if (isNewColumnResizingEnabled && shouldScale) {
169
- resizeState = scaleResizeState({
170
- resizeState,
171
- tableRef: dom,
172
- tableNode: originalTable,
173
- editorWidth,
174
- shouldUseIncreasedScalingPercent,
175
- });
176
- }
177
-
178
157
  function finish(event: MouseEvent) {
179
158
  // Ignored via go/ees005
180
159
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -223,8 +202,6 @@ export const handleMouseDown = (
223
202
  // There may be a more elegant solution to this, to avoid a jarring experience.
224
203
  if (table.eq(originalTable)) {
225
204
  const map = TableMap.get(table);
226
- const totalRowCount = map.height;
227
- const totalColumnCount = map.width;
228
205
  const colIndex =
229
206
  map.colCount($cell.pos - start) +
230
207
  ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) -
@@ -246,71 +223,22 @@ export const handleMouseDown = (
246
223
  isTableScalingWithFixedColumnWidthsOptionEnabled ||
247
224
  (isTableScalingEnabled && !!isCommentEditor);
248
225
 
249
- if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
250
- const newResizeState = resizeColumnAndTable({
251
- resizeState,
252
- colIndex,
253
- amount: resizedDelta,
254
- tableRef: dom,
255
- tableNode: originalTable,
256
- width: editorWidth,
257
- lineLength,
258
- isTableAlignmentEnabled,
259
- });
260
-
261
- tr = updateColumnWidths(newResizeState, table, start, api)(tr);
262
-
263
- // If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
264
- const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(
265
- isTableAlignmentEnabled,
266
- originalTable,
267
- lineLength,
268
- newResizeState.maxSize,
269
- );
270
-
271
- if (shouldChangeAlignment) {
272
- tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
273
- ...table.attrs,
274
- width: newResizeState.maxSize,
275
- layout: ALIGN_CENTER,
276
- });
277
-
278
- editorAnalyticsAPI?.attachAnalyticsEvent({
279
- action: TABLE_ACTION.CHANGED_ALIGNMENT,
280
- actionSubject: ACTION_SUBJECT.TABLE,
281
- actionSubjectId: null,
282
- attributes: {
283
- tableWidth: newResizeState.maxSize,
284
- newAlignment: ALIGN_CENTER,
285
- previousAlignment: ALIGN_START,
286
- totalRowCount: totalRowCount,
287
- totalColumnCount: totalColumnCount,
288
- inputMethod: INPUT_METHOD.AUTO,
289
- reason: CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED,
290
- },
291
- eventType: EVENT_TYPE.TRACK,
292
- })(tr);
293
- } else {
294
- tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
295
- }
296
- } else {
297
- const scalePercent =
298
- isTableScalingEnabled && isCommentEditor && !table.attrs?.width
299
- ? getScalingPercentForTableWithoutWidth(originalTable, dom)
300
- : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
301
-
302
- const newResizeState = resizeColumn(
303
- resizeState,
304
- colIndex,
305
- resizedDelta,
306
- dom,
307
- originalTable,
308
- resizingSelectedColumns ? selectedColumns : undefined,
309
- shouldScale,
310
- scalePercent,
311
- );
312
- tr = updateColumnWidths(newResizeState, table, start, api)(tr);
313
- }
226
+ const scalePercent =
227
+ isTableScalingEnabled && isCommentEditor && !table.attrs?.width
228
+ ? getScalingPercentForTableWithoutWidth(originalTable, dom)
229
+ : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
230
+
231
+ const newResizeState = resizeColumn(
232
+ resizeState,
233
+ colIndex,
234
+ resizedDelta,
235
+ dom,
236
+ originalTable,
237
+ resizingSelectedColumns ? selectedColumns : undefined,
238
+ shouldScale,
239
+ scalePercent,
240
+ );
241
+ tr = updateColumnWidths(newResizeState, table, start, api)(tr);
314
242
 
315
243
  if (colIndex === map.width - 1) {
316
244
  const mouseUpTime = event.timeStamp;
@@ -367,14 +295,13 @@ export const handleMouseDown = (
367
295
  !dragging ||
368
296
  resizeHandlePos === null ||
369
297
  !pointsAtCell(state.doc.resolve(resizeHandlePos)) ||
370
- ((!isNewColumnResizingEnabled || isTableNested(state, tablePos)) && !isTableHovered)
298
+ !isTableHovered
371
299
  ) {
372
300
  return finish(event);
373
301
  }
374
302
 
375
303
  const $cell = state.doc.resolve(resizeHandlePos);
376
304
  const table = $cell.node(-1);
377
- // const tablePos = state.doc.resolve(start).start(-1);
378
305
  const tableDepth = state.doc.resolve(tablePos).depth;
379
306
  const map = TableMap.get(table);
380
307
  // Ignored via go/ees005
@@ -393,34 +320,21 @@ export const handleMouseDown = (
393
320
 
394
321
  const resizedDelta = clientX - dragging.startX;
395
322
 
396
- if (isNewColumnResizingEnabled && !isTableNested(state, tablePos) && !isCommentEditor) {
397
- resizeColumnAndTable({
398
- resizeState,
399
- colIndex,
400
- amount: resizedDelta,
401
- tableRef: dom,
402
- tableNode: originalTable,
403
- width: editorWidth,
404
- lineLength,
405
- isTableAlignmentEnabled,
406
- });
407
- } else {
408
- const scalePercent =
409
- isTableScalingEnabled && isCommentEditor && !table.attrs?.width
410
- ? getScalingPercentForTableWithoutWidth(table, dom)
411
- : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
412
-
413
- resizeColumn(
414
- resizeState,
415
- colIndex,
416
- resizedDelta,
417
- dom,
418
- table,
419
- undefined,
420
- shouldScale,
421
- scalePercent,
422
- );
423
- }
323
+ const scalePercent =
324
+ isTableScalingEnabled && isCommentEditor && !table.attrs?.width
325
+ ? getScalingPercentForTableWithoutWidth(table, dom)
326
+ : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
327
+
328
+ resizeColumn(
329
+ resizeState,
330
+ colIndex,
331
+ resizedDelta,
332
+ dom,
333
+ table,
334
+ undefined,
335
+ shouldScale,
336
+ scalePercent,
337
+ );
424
338
 
425
339
  updateControls()(state);
426
340
  }
@@ -27,8 +27,6 @@ export function createPlugin(
27
27
  nodeViewPortalProviderAPI: PortalProviderAPI,
28
28
  editorAnalyticsAPI?: EditorAnalyticsAPI,
29
29
  isTableScalingEnabled?: boolean,
30
- isNewColumnResizingEnabled?: boolean,
31
- isTableAlignmentEnabled?: boolean,
32
30
  isCommentEditor?: boolean,
33
31
  ) {
34
32
  return new SafePlugin({
@@ -82,8 +80,6 @@ export function createPlugin(
82
80
  api,
83
81
  nodeViewPortalProviderAPI,
84
82
  editorAnalyticsAPI,
85
- isNewColumnResizingEnabled,
86
- isTableAlignmentEnabled,
87
83
  isCommentEditor,
88
84
  )
89
85
  ) {
@@ -60,7 +60,7 @@ export function currentColWidth(
60
60
  cellPos: number,
61
61
  { colspan, colwidth }: CellAttributes,
62
62
  ): number {
63
- let width = colwidth && colwidth[colwidth.length - 1];
63
+ const width = colwidth && colwidth[colwidth.length - 1];
64
64
  if (width) {
65
65
  return width;
66
66
  }
@@ -156,7 +156,7 @@ export const getScalingPercentForTableWithoutWidth = (
156
156
  // are table columns resized
157
157
  if (hasTableColumnBeenResized(table)) {
158
158
  const tableWidth = calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
159
- let renderWidth = tableRef?.parentElement?.clientWidth || tableWidth;
159
+ const renderWidth = tableRef?.parentElement?.clientWidth || tableWidth;
160
160
 
161
161
  // minus 1 here to avoid any 1px scroll in Firefox
162
162
  return (renderWidth - 1) / tableWidth;
@@ -1,22 +1,7 @@
1
1
  // Resize a given column by an amount from the current state
2
- import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
- import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
4
2
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
5
- import {
6
- akEditorFullWidthLayoutWidth,
7
- akEditorGutterPaddingDynamic,
8
- akEditorTableNumberColumnWidth,
9
- } from '@atlaskit/editor-shared-styles';
10
3
 
11
- import { TableCssClassName as ClassName } from '../../../types';
12
- import {
13
- ALIGN_CENTER,
14
- ALIGN_START,
15
- shouldChangeAlignmentToCenterResized,
16
- } from '../../utils/alignment';
17
-
18
- import { getTableScalingPercent } from './misc';
19
- import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
4
+ import { growColumn, shrinkColumn } from './resize-logic';
20
5
  import { updateColgroup } from './resize-state';
21
6
  import type { ResizeState } from './types';
22
7
 
@@ -49,206 +34,3 @@ export const resizeColumn = (
49
34
 
50
35
  return newState;
51
36
  };
52
-
53
- type ResizeInformation = {
54
- resizeState: ResizeState;
55
- colIndex: number;
56
- amount: number;
57
- };
58
-
59
- type TableReferences = {
60
- tableRef: HTMLElement;
61
- tableNode: PmNode;
62
- };
63
-
64
- type TableResizingPluginOptions = {
65
- isTableAlignmentEnabled?: boolean;
66
- };
67
-
68
- type ResizeColumnAndTable = ResizeInformation &
69
- TableResizingPluginOptions &
70
- TableReferences &
71
- EditorContainerWidth;
72
-
73
- export const resizeColumnAndTable = ({
74
- resizeState,
75
- colIndex,
76
- amount,
77
- tableRef,
78
- tableNode,
79
- lineLength,
80
- width: editorWidth,
81
- isTableAlignmentEnabled,
82
- }: ResizeColumnAndTable): ResizeState => {
83
- const editorContainerWidth = getEditorContainerWidth(editorWidth);
84
- const isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
85
- const isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
86
- const isOverflow = resizeState.tableWidth > resizeState.maxSize;
87
- let resizeAmount = isTableLeftAligned ? amount : amount * 2;
88
- const willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
89
-
90
- const willResizedTableStayInOverflow =
91
- isOverflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
92
-
93
- // STEP 1: Update col width
94
- if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
95
- const tableContainerWidth = tableRef.closest('.pm-table-container')?.clientWidth;
96
- resizeAmount =
97
- amount < 0
98
- ? amount
99
- : // Ignored via go/ees005
100
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
101
- resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth!) / 2;
102
- } else {
103
- const diff = -(resizeState.tableWidth - resizeState.maxSize);
104
- const rest = amount - diff;
105
- const final = isTableLeftAligned ? diff + rest : diff + rest * 2;
106
- resizeAmount = final;
107
- }
108
-
109
- const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
110
-
111
- // STEP 2: Update table container width
112
- // columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
113
- const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
114
-
115
- newState.maxSize = Math.round(
116
- isOverflow
117
- ? willResizedTableStayInOverflow
118
- ? // CASE 1A: table will stay in overflow
119
- // do not grow the table because resize is happening in the overflow region
120
- // and the overall table container needs to be retained
121
- isNumberColumnEnabled
122
- ? resizeState.maxSize + akEditorTableNumberColumnWidth
123
- : resizeState.maxSize
124
- : // CASE 1B: table will no longer be in overflow, so adjust container width
125
- // ensure the table is resized without any 'big jumps' by working out
126
- // the difference between the new table width and the max size and adding the resize
127
- isNumberColumnEnabled
128
- ? resizeState.maxSize +
129
- akEditorTableNumberColumnWidth +
130
- (resizeState.tableWidth - resizeState.maxSize + akEditorTableNumberColumnWidth + delta)
131
- : resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta)
132
- : willTableHitEditorEdge
133
- ? // CASE 2: table will hit editor edge
134
- editorContainerWidth
135
- : // CASE 3: table is being resized from a non-overflow state
136
- isNumberColumnEnabled
137
- ? resizeState.maxSize + akEditorTableNumberColumnWidth + delta
138
- : resizeState.maxSize + delta,
139
- );
140
-
141
- // do not apply scaling logic because resize state is already scaled
142
- updateColgroup(newState, tableRef, tableNode, false, 1);
143
-
144
- updateTablePreview(
145
- tableRef,
146
- newState.maxSize,
147
- shouldChangeAlignmentToCenterResized(
148
- isTableAlignmentEnabled,
149
- tableNode,
150
- lineLength,
151
- newState.maxSize,
152
- ),
153
- );
154
-
155
- return newState;
156
- };
157
-
158
- const updateTablePreview = (
159
- tableRef: HTMLElement,
160
- newTableWidth: number,
161
- shouldChangeAlignment?: boolean,
162
- ) => {
163
- const resizingContainer = tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
164
- const resizingItem = resizingContainer?.querySelector('.resizer-item');
165
- const alignmentContainer = resizingContainer?.parentElement;
166
-
167
- if (resizingItem) {
168
- const newWidth = `${newTableWidth}px`;
169
- // Ignored via go/ees005
170
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
171
- (resizingContainer as HTMLElement).style.width = newWidth;
172
- // Ignored via go/ees005
173
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
174
- (resizingItem as HTMLElement).style.width = newWidth;
175
-
176
- if (shouldChangeAlignment && alignmentContainer) {
177
- alignmentContainer.style.justifyContent = ALIGN_CENTER;
178
- }
179
- }
180
- };
181
-
182
- const getEditorContainerWidth = (editorWidth: number) =>
183
- Math.min(editorWidth - akEditorGutterPaddingDynamic() * 2, akEditorFullWidthLayoutWidth);
184
-
185
- /**
186
- * Apply a scaling factor to resize state
187
- */
188
- export const scaleResizeState = ({
189
- resizeState,
190
- tableRef,
191
- tableNode,
192
- editorWidth,
193
- shouldUseIncreasedScalingPercent,
194
- }: TableReferences & {
195
- resizeState: ResizeState;
196
- editorWidth: number;
197
- shouldUseIncreasedScalingPercent: boolean;
198
- }): ResizeState => {
199
- const isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
200
- const isTableScaled =
201
- isNumberColumnEnabled || resizeState.maxSize > getEditorContainerWidth(editorWidth);
202
-
203
- // Tables with number column can cause the table to be in two different states:
204
- // 1. The table sum of col widths will be smaller than the max size, which is incorrect. For this
205
- // avoid scaling and take the document width
206
- // 2. The table sum of col widths will be the same size as max width, which happens when the table
207
- // is scaled using preserve table width logic, for this apply a scaled width
208
- // return early if table isn't scaled
209
- if (!isTableScaled || (isNumberColumnEnabled && resizeState.maxSize > resizeState.tableWidth)) {
210
- return resizeState;
211
- }
212
-
213
- const scalePercent = getTableScalingPercent(
214
- tableNode,
215
- tableRef,
216
- shouldUseIncreasedScalingPercent,
217
- );
218
- const scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
219
- let cols = resizeState.cols.map((col) => {
220
- return {
221
- ...col,
222
- minWidth: tableCellMinWidth,
223
- width: Math.max(Math.round(col.width * scalePercent), tableCellMinWidth),
224
- };
225
- });
226
-
227
- const calculatedTableWidth = cols.reduce((prev, curr) => prev + curr.width, 0);
228
-
229
- // using Math.round can cause the sum of col widths to be larger than the table width
230
- // distribute the difference to the first column
231
- if (calculatedTableWidth > scaledTableWidth) {
232
- const diff = calculatedTableWidth - scaledTableWidth;
233
- let hasDiffBeenDistributed = false;
234
- cols = cols.map((col) => {
235
- if (!hasDiffBeenDistributed && col.width - diff >= col.minWidth) {
236
- hasDiffBeenDistributed = true;
237
- return { ...col, width: col.width - diff };
238
- }
239
- return col;
240
- });
241
- }
242
-
243
- const maxSize = isNumberColumnEnabled
244
- ? Math.round((resizeState.maxSize + akEditorTableNumberColumnWidth) * scalePercent)
245
- : Math.round(resizeState.maxSize * scalePercent);
246
-
247
- return {
248
- ...resizeState,
249
- widths: cols.map((col) => col.width),
250
- tableWidth: scaledTableWidth,
251
- maxSize,
252
- cols,
253
- };
254
- };
@@ -183,7 +183,7 @@ function stackSpace(
183
183
 
184
184
  while (candidates.length && amount) {
185
185
  // search for most (or least) free space in candidates
186
- let candidateIdx = findNextFreeColumn(candidates, amount);
186
+ const candidateIdx = findNextFreeColumn(candidates, amount);
187
187
  if (candidateIdx === -1) {
188
188
  // stack to the right -> growing the dragging column and go overflow
189
189
  if (amount > 0) {
@@ -367,8 +367,6 @@ export const getNewResizeStateFromSelectedColumns = (
367
367
  getEditorContainerWidth,
368
368
  });
369
369
 
370
- let resizeState;
371
-
372
370
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
373
371
  const isTableScalingWithFixedColumnWidthsOptionEnabled =
374
372
  isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled;
@@ -383,7 +381,7 @@ export const getNewResizeStateFromSelectedColumns = (
383
381
  shouldUseIncreasedScalingPercent = true;
384
382
  }
385
383
 
386
- resizeState = getResizeState({
384
+ const resizeState = getResizeState({
387
385
  minWidth: tableCellMinWidth,
388
386
  maxSize,
389
387
  table: table.node,