@atlaskit/editor-plugin-table 5.7.3 → 5.7.5

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 (45) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands/insert.js +1 -1
  3. package/dist/cjs/nodeviews/TableComponent.js +4 -2
  4. package/dist/cjs/nodeviews/TableContainer.js +10 -5
  5. package/dist/cjs/nodeviews/TableResizer.js +7 -3
  6. package/dist/cjs/transforms/column-width.js +3 -105
  7. package/dist/cjs/transforms/delete-columns.js +2 -5
  8. package/dist/cjs/ui/common-styles.js +1 -1
  9. package/dist/cjs/utils/analytics.js +2 -1
  10. package/dist/es2019/commands/insert.js +1 -1
  11. package/dist/es2019/nodeviews/TableComponent.js +4 -2
  12. package/dist/es2019/nodeviews/TableContainer.js +10 -5
  13. package/dist/es2019/nodeviews/TableResizer.js +7 -3
  14. package/dist/es2019/transforms/column-width.js +4 -102
  15. package/dist/es2019/transforms/delete-columns.js +2 -5
  16. package/dist/es2019/ui/common-styles.js +1 -0
  17. package/dist/es2019/utils/analytics.js +2 -1
  18. package/dist/esm/commands/insert.js +1 -1
  19. package/dist/esm/nodeviews/TableComponent.js +4 -2
  20. package/dist/esm/nodeviews/TableContainer.js +10 -5
  21. package/dist/esm/nodeviews/TableResizer.js +7 -3
  22. package/dist/esm/transforms/column-width.js +4 -106
  23. package/dist/esm/transforms/delete-columns.js +2 -5
  24. package/dist/esm/ui/common-styles.js +1 -1
  25. package/dist/esm/utils/analytics.js +2 -1
  26. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  27. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  28. package/dist/types/transforms/column-width.d.ts +1 -14
  29. package/dist/types/utils/analytics.d.ts +1 -0
  30. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  31. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  32. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -14
  33. package/dist/types-ts4.5/utils/analytics.d.ts +1 -0
  34. package/package.json +2 -5
  35. package/src/__tests__/unit/commands/insert.ts +7 -0
  36. package/src/__tests__/unit/nodeviews/TableContainer.tsx +7 -0
  37. package/src/__tests__/unit/transforms/delete-columns.ts +147 -368
  38. package/src/commands/insert.ts +1 -3
  39. package/src/nodeviews/TableComponent.tsx +2 -1
  40. package/src/nodeviews/TableContainer.tsx +9 -0
  41. package/src/nodeviews/TableResizer.tsx +6 -0
  42. package/src/transforms/column-width.ts +4 -137
  43. package/src/transforms/delete-columns.ts +3 -9
  44. package/src/ui/common-styles.ts +1 -0
  45. package/src/utils/analytics.ts +2 -0
@@ -1,26 +1,17 @@
1
1
  import type { CellAttributes } from '@atlaskit/adf-schema';
2
2
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
4
3
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
4
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
5
  import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
7
6
  import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
8
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
- import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
10
- import {
11
- TableMap,
12
- tableNewColumnMinWidth,
13
- } from '@atlaskit/editor-tables/table-map';
8
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
14
9
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
10
 
16
11
  import type { ResizeState } from '../pm-plugins/table-resizing/utils';
17
12
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
18
13
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
19
- import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
20
- import {
21
- getResizeState,
22
- normaliseTableLayout,
23
- } from '../pm-plugins/table-resizing/utils/resize-state';
14
+ import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
24
15
  import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
25
16
  import { insertColumnButtonOffset } from '../ui/common-styles';
26
17
 
@@ -112,7 +103,7 @@ export const updateColumnWidths =
112
103
  * @param view
113
104
  * @returns Updated transaction with rescaled columns for a given table
114
105
  */
115
- export const rescaleColumnsNew =
106
+ export const rescaleColumns =
116
107
  () =>
117
108
  (table: ContentNodeWithPos, view: EditorView | undefined) =>
118
109
  (tr: Transaction): Transaction => {
@@ -138,8 +129,7 @@ export const rescaleColumnsNew =
138
129
  possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width')
139
130
  ? tableRef?.parentElement?.clientWidth || 0
140
131
  : (tableRef?.parentElement?.clientWidth || 0) -
141
- insertColumnButtonOffset -
142
- 1,
132
+ insertColumnButtonOffset,
143
133
  isResized,
144
134
  };
145
135
 
@@ -223,126 +213,3 @@ export const rescaleColumnsNew =
223
213
 
224
214
  return updateColumnWidths(resizeState, table.node, table.start)(tr);
225
215
  };
226
-
227
- /**
228
- * This function is called when user inserts/deletes a column in a table to;
229
- * - rescale all columns (if the table did not overflow before the insertion)
230
- * - and update column widths.
231
- *
232
- * This is done manually to avoid a multi-dispatch in TableComponent. See [ED-8288].
233
- * @param table
234
- * @param view
235
- * @returns Updated transaction with rescaled columns for a given table
236
- */
237
- export const rescaleColumnsOld =
238
- (getEditorContainerWidth: GetEditorContainerWidth) =>
239
- (table: ContentNodeWithPos, view: EditorView | undefined) =>
240
- (tr: Transaction): Transaction => {
241
- if (!view) {
242
- return tr;
243
- }
244
-
245
- const pos = table.pos;
246
- const newTable = tr.doc.nodeAt(pos);
247
- const { state } = view;
248
- const domAtPos = view.domAtPos.bind(view);
249
- const maybeTable = domAtPos(table.start).node as HTMLElement;
250
- const tableRef = maybeTable.closest('table');
251
-
252
- if (!tableRef || !newTable) {
253
- return tr;
254
- }
255
-
256
- const layout = normaliseTableLayout(tableRef?.dataset.layout);
257
- // The is the width the table can reach before overflowing
258
- const maxSize = getTableMaxWidth({
259
- table: table.node,
260
- tableStart: table.start,
261
- state,
262
- layout,
263
- getEditorContainerWidth,
264
- });
265
-
266
- const tableWidth = tableRef.clientWidth || akEditorDefaultLayoutWidth;
267
- let tableMaxWidth = tableRef?.parentElement?.clientWidth || 0;
268
- tableMaxWidth -= insertColumnButtonOffset;
269
- const newTableMap = TableMap.get(newTable);
270
- const noOfColumns = newTableMap.width;
271
- if (!noOfColumns || noOfColumns <= 0) {
272
- return tr;
273
- }
274
- const columnWidthUnresized = tableWidth / noOfColumns;
275
-
276
- // If the table has not been resized, and the column width is bigger than the minimum column width
277
- // we skip updating the size of columns here.
278
- if (
279
- !hasTableBeenResized(table.node) &&
280
- columnWidthUnresized > tableCellMinWidth
281
- ) {
282
- return tr;
283
- }
284
-
285
- // If the table has not been resized, and the column width is smaller than the minimum column width
286
- // Or if the table has been resized, but each column width is either 48px or null
287
- // we update the table to have 48px for each column
288
- if (
289
- (!hasTableBeenResized(table.node) &&
290
- columnWidthUnresized <= tableCellMinWidth) ||
291
- (hasTableBeenResized(table.node) && isMinCellWidthTable(table.node))
292
- ) {
293
- const widths: Array<number> = new Array(noOfColumns).fill(
294
- tableCellMinWidth,
295
- );
296
- const cols = widths.map((_, index) => ({
297
- width: tableCellMinWidth,
298
- minWidth: tableCellMinWidth,
299
- index,
300
- }));
301
- const overflow = tableWidth > maxSize;
302
- const minWidthResizeState = {
303
- cols,
304
- widths,
305
- maxSize,
306
- tableWidth,
307
- overflow,
308
- };
309
- return updateColumnWidths(
310
- minWidthResizeState,
311
- table.node,
312
- table.start,
313
- )(tr);
314
- }
315
-
316
- let resizeState = getResizeState({
317
- minWidth: tableCellMinWidth,
318
- table: table.node,
319
- start: table.start,
320
- tableRef,
321
- domAtPos,
322
- maxSize,
323
- });
324
- const previousTableWidth = resizeState.tableWidth - tableNewColumnMinWidth;
325
- const tableDidntPreviouslyOverflow =
326
- previousTableWidth <= Math.max(maxSize, tableMaxWidth);
327
-
328
- // If the new table width will result in the table going into an overflow state
329
- // we resize the cells to avoid the overflow occuring
330
- if (tableDidntPreviouslyOverflow && resizeState.overflow) {
331
- resizeState = scaleTableTo(resizeState, maxSize);
332
- }
333
-
334
- return updateColumnWidths(resizeState, table.node, table.start)(tr);
335
- };
336
-
337
- export const rescaleColumns = (
338
- getEditorContainerWidth?: GetEditorContainerWidth,
339
- ) => {
340
- if (
341
- getBooleanFF(
342
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
343
- )
344
- ) {
345
- return rescaleColumnsNew();
346
- }
347
- return rescaleColumnsOld(getEditorContainerWidth!);
348
- };
@@ -8,7 +8,6 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import type { Rect } from '@atlaskit/editor-tables/table-map';
9
9
  import { TableMap } from '@atlaskit/editor-tables/table-map';
10
10
  import { findTable } from '@atlaskit/editor-tables/utils';
11
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
11
 
13
12
  import { META_KEYS } from '../pm-plugins/table-analytics';
14
13
 
@@ -263,14 +262,9 @@ export const deleteColumns =
263
262
  updatedTr = deleteColumnsLegacy(rect)(updatedTr);
264
263
  }
265
264
  const table = findTable(updatedTr.selection);
266
- if (
267
- getBooleanFF(
268
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
269
- )
270
- ) {
271
- if (table) {
272
- updatedTr = rescaleColumns()(table, view)(updatedTr);
273
- }
265
+
266
+ if (table) {
267
+ updatedTr = rescaleColumns()(table, view)(updatedTr);
274
268
  }
275
269
  return updatedTr;
276
270
  };
@@ -150,6 +150,7 @@ const stickyScrollbarContainerStyles = `.${ClassName.TABLE_CONTAINER} {
150
150
  overflow-x: auto;
151
151
  position: sticky;
152
152
  bottom: 0;
153
+ z-index: 1;
153
154
  }
154
155
  }`;
155
156
 
@@ -144,6 +144,7 @@ export const generateResizeFrameRatePayloads = (props: {
144
144
  docSize: number;
145
145
  frameRateSamples: number[];
146
146
  originalNode: PMNode;
147
+ experiments?: Record<string, boolean | undefined>;
147
148
  }): TableEventPayload[] => {
148
149
  const reducedResizeFrameRateSamples = reduceResizeFrameRateSamples(
149
150
  props.frameRateSamples,
@@ -157,6 +158,7 @@ export const generateResizeFrameRatePayloads = (props: {
157
158
  nodeSize: props.originalNode.nodeSize,
158
159
  docSize: props.docSize,
159
160
  isInitialSample: index === 0,
161
+ experiments: props.experiments,
160
162
  },
161
163
  }));
162
164
  };