@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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/commands/insert.js +1 -1
- package/dist/cjs/nodeviews/TableComponent.js +4 -2
- package/dist/cjs/nodeviews/TableContainer.js +10 -5
- package/dist/cjs/nodeviews/TableResizer.js +7 -3
- package/dist/cjs/transforms/column-width.js +3 -105
- package/dist/cjs/transforms/delete-columns.js +2 -5
- package/dist/cjs/ui/common-styles.js +1 -1
- package/dist/cjs/utils/analytics.js +2 -1
- package/dist/es2019/commands/insert.js +1 -1
- package/dist/es2019/nodeviews/TableComponent.js +4 -2
- package/dist/es2019/nodeviews/TableContainer.js +10 -5
- package/dist/es2019/nodeviews/TableResizer.js +7 -3
- package/dist/es2019/transforms/column-width.js +4 -102
- package/dist/es2019/transforms/delete-columns.js +2 -5
- package/dist/es2019/ui/common-styles.js +1 -0
- package/dist/es2019/utils/analytics.js +2 -1
- package/dist/esm/commands/insert.js +1 -1
- package/dist/esm/nodeviews/TableComponent.js +4 -2
- package/dist/esm/nodeviews/TableContainer.js +10 -5
- package/dist/esm/nodeviews/TableResizer.js +7 -3
- package/dist/esm/transforms/column-width.js +4 -106
- package/dist/esm/transforms/delete-columns.js +2 -5
- package/dist/esm/ui/common-styles.js +1 -1
- package/dist/esm/utils/analytics.js +2 -1
- package/dist/types/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/transforms/column-width.d.ts +1 -14
- package/dist/types/utils/analytics.d.ts +1 -0
- package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/transforms/column-width.d.ts +1 -14
- package/dist/types-ts4.5/utils/analytics.d.ts +1 -0
- package/package.json +2 -5
- package/src/__tests__/unit/commands/insert.ts +7 -0
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +7 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +147 -368
- package/src/commands/insert.ts +1 -3
- package/src/nodeviews/TableComponent.tsx +2 -1
- package/src/nodeviews/TableContainer.tsx +9 -0
- package/src/nodeviews/TableResizer.tsx +6 -0
- package/src/transforms/column-width.ts +4 -137
- package/src/transforms/delete-columns.ts +3 -9
- package/src/ui/common-styles.ts +1 -0
- 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 {
|
|
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 {
|
|
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
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
};
|
package/src/ui/common-styles.ts
CHANGED
package/src/utils/analytics.ts
CHANGED
|
@@ -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
|
};
|