@atlaskit/editor-plugin-table 8.4.14 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/nodeviews/TableRow.js +24 -14
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +9 -84
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +3 -144
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +1 -2
- package/dist/cjs/pm-plugins/view-mode-sort/utils.js +3 -0
- package/dist/cjs/tablePlugin.js +3 -5
- package/dist/cjs/ui/DragPreview/index.js +1 -0
- package/dist/cjs/ui/FloatingContextualButton/index.js +1 -2
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +2 -4
- package/dist/cjs/ui/TableFullWidthLabel/index.js +1 -0
- package/dist/cjs/ui/event-handlers.js +18 -7
- package/dist/cjs/ui/toolbar.js +1 -4
- package/dist/es2019/nodeviews/TableContainer.js +1 -1
- package/dist/es2019/nodeviews/TableRow.js +24 -14
- package/dist/es2019/pm-plugins/commands/column-resize.js +1 -1
- package/dist/es2019/pm-plugins/commands/insert.js +3 -3
- package/dist/es2019/pm-plugins/commands/misc.js +1 -1
- package/dist/es2019/pm-plugins/drag-and-drop/commands.js +1 -1
- package/dist/es2019/pm-plugins/table-analytics.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +12 -84
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +2 -139
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-logic.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +1 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +1 -1
- package/dist/es2019/pm-plugins/transforms/delete-columns.js +1 -1
- package/dist/es2019/pm-plugins/transforms/fix-tables.js +1 -1
- package/dist/es2019/pm-plugins/transforms/replace-table.js +1 -1
- package/dist/es2019/pm-plugins/transforms/split.js +2 -2
- package/dist/es2019/pm-plugins/utils/analytics.js +4 -4
- package/dist/es2019/pm-plugins/utils/column-controls.js +1 -1
- package/dist/es2019/pm-plugins/utils/drag-menu.js +1 -1
- package/dist/es2019/pm-plugins/utils/merged-cells.js +4 -4
- package/dist/es2019/pm-plugins/utils/nodes.js +3 -3
- package/dist/es2019/pm-plugins/utils/row-controls.js +2 -2
- package/dist/es2019/pm-plugins/view-mode-sort/index.js +2 -2
- package/dist/es2019/pm-plugins/view-mode-sort/utils.js +4 -1
- package/dist/es2019/tablePlugin.js +3 -5
- package/dist/es2019/ui/DragPreview/index.js +4 -3
- package/dist/es2019/ui/FloatingContextualButton/index.js +1 -2
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +4 -6
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +4 -4
- package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +2 -2
- package/dist/es2019/ui/TableFullWidthLabel/index.js +1 -0
- package/dist/es2019/ui/event-handlers.js +12 -1
- package/dist/es2019/ui/toolbar.js +1 -4
- package/dist/esm/nodeviews/TableRow.js +24 -14
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +11 -85
- package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +2 -143
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +1 -2
- package/dist/esm/pm-plugins/view-mode-sort/utils.js +3 -0
- package/dist/esm/tablePlugin.js +3 -5
- package/dist/esm/ui/DragPreview/index.js +1 -0
- package/dist/esm/ui/FloatingContextualButton/index.js +1 -2
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +2 -4
- package/dist/esm/ui/TableFullWidthLabel/index.js +1 -0
- package/dist/esm/ui/event-handlers.js +12 -1
- package/dist/esm/ui/toolbar.js +1 -4
- package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -24
- package/dist/types/tablePluginType.d.ts +0 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -24
- package/dist/types-ts4.5/tablePluginType.d.ts +0 -1
- package/package.json +5 -5
- package/src/nodeviews/TableComponent.tsx +1 -1
- package/src/nodeviews/TableContainer.tsx +1 -1
- package/src/nodeviews/TableRow.ts +34 -14
- package/src/pm-plugins/commands/column-resize.ts +1 -1
- package/src/pm-plugins/commands/hover.ts +2 -2
- package/src/pm-plugins/commands/insert.ts +3 -3
- package/src/pm-plugins/commands/misc.ts +1 -1
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +1 -1
- package/src/pm-plugins/drag-and-drop/commands.ts +6 -2
- package/src/pm-plugins/table-analytics.ts +1 -1
- package/src/pm-plugins/table-resizing/event-handlers.ts +35 -121
- package/src/pm-plugins/table-resizing/plugin.ts +0 -4
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +1 -1
- package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +1 -219
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +1 -1
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +1 -3
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +1 -1
- package/src/pm-plugins/transforms/column-width.ts +1 -1
- package/src/pm-plugins/transforms/delete-columns.ts +1 -1
- package/src/pm-plugins/transforms/fix-tables.ts +1 -1
- package/src/pm-plugins/transforms/replace-table.ts +1 -1
- package/src/pm-plugins/transforms/split.ts +2 -2
- package/src/pm-plugins/utils/analytics.ts +4 -4
- package/src/pm-plugins/utils/column-controls.ts +1 -1
- package/src/pm-plugins/utils/drag-menu.ts +1 -1
- package/src/pm-plugins/utils/merged-cells.ts +4 -4
- package/src/pm-plugins/utils/nodes.ts +3 -3
- package/src/pm-plugins/utils/row-controls.ts +2 -2
- package/src/pm-plugins/view-mode-sort/index.ts +2 -2
- package/src/pm-plugins/view-mode-sort/utils.ts +3 -1
- package/src/tablePlugin.tsx +3 -10
- package/src/tablePluginType.ts +0 -1
- package/src/ui/DragPreview/index.tsx +4 -3
- package/src/ui/FloatingContextualButton/index.tsx +1 -2
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +4 -6
- package/src/ui/FloatingDragMenu/DragMenu.tsx +4 -4
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +2 -2
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +1 -1
- package/src/ui/TableFloatingColumnControls/index.tsx +1 -1
- package/src/ui/TableFullWidthLabel/index.tsx +1 -0
- package/src/ui/event-handlers.ts +19 -1
- package/src/ui/toolbar.tsx +1 -11
- package/tsconfig.app.json +0 -1
- package/tsconfig.dev.json +0 -1
|
@@ -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
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
) {
|
|
@@ -105,7 +105,7 @@ export const insertColgroupFromNode = (
|
|
|
105
105
|
|
|
106
106
|
colgroup = renderColgroupFromNode(
|
|
107
107
|
table,
|
|
108
|
-
isTableScalingEnabled ?
|
|
108
|
+
isTableScalingEnabled ? tableRef ?? undefined : undefined,
|
|
109
109
|
shouldUseIncreasedScalingPercent,
|
|
110
110
|
isCommentEditor,
|
|
111
111
|
);
|
|
@@ -60,7 +60,7 @@ export function currentColWidth(
|
|
|
60
60
|
cellPos: number,
|
|
61
61
|
{ colspan, colwidth }: CellAttributes,
|
|
62
62
|
): number {
|
|
63
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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,
|
|
@@ -148,7 +148,7 @@ export function scaleTableTo(state: ResizeState, maxSize: number): ResizeState {
|
|
|
148
148
|
}),
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
const newTotalWidth = getTotalWidth(newState);
|
|
152
152
|
if (newTotalWidth > maxSize) {
|
|
153
153
|
newState = reduceSpace(newState, newTotalWidth - maxSize);
|
|
154
154
|
}
|
|
@@ -9,7 +9,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
|
|
11
11
|
import type { PluginInjectionAPI } from '../../types';
|
|
12
|
-
import { isMinCellWidthTable
|
|
12
|
+
import { isMinCellWidthTable, hasTableBeenResized } from '../table-resizing/utils/colgroup';
|
|
13
13
|
import { getTableContainerElementWidth, getTableElementWidth } from '../table-resizing/utils/misc';
|
|
14
14
|
import { getResizeState } from '../table-resizing/utils/resize-state';
|
|
15
15
|
import { scaleTableTo } from '../table-resizing/utils/scale-table';
|
|
@@ -29,7 +29,7 @@ const deleteColumnsCustomStep =
|
|
|
29
29
|
splitCellsInColumns(tr, table.pos, rect.left, rect.right);
|
|
30
30
|
|
|
31
31
|
// Delete the columns
|
|
32
|
-
|
|
32
|
+
const mapStart = tr.mapping.maps.length;
|
|
33
33
|
const originalDoc = tr.doc;
|
|
34
34
|
const deletedColumns: number[] = [];
|
|
35
35
|
for (let i = rect.left; i < rect.right; i++) {
|
|
@@ -22,7 +22,7 @@ export const replaceSelectedTable = (
|
|
|
22
22
|
typeof content === 'string'
|
|
23
23
|
? new Slice(Fragment.from(state.schema.text(content)), 0, 0)
|
|
24
24
|
: content;
|
|
25
|
-
|
|
25
|
+
const tr = state.tr.replace(table.pos, table.pos + table.node.nodeSize, slice);
|
|
26
26
|
tr.setSelection(TextSelection.create(tr.doc, table.pos + slice.size + 1));
|
|
27
27
|
|
|
28
28
|
const { totalRowCount, totalColumnCount } = getSelectedTableInfo(state.selection);
|
|
@@ -18,7 +18,7 @@ export function splitCellsInColumns(
|
|
|
18
18
|
columnStart: number,
|
|
19
19
|
columnEnd: number,
|
|
20
20
|
): Transaction {
|
|
21
|
-
|
|
21
|
+
const mapStart = tr.mapping.maps.length;
|
|
22
22
|
const table = tr.doc.nodeAt(tablePos);
|
|
23
23
|
if (!table) {
|
|
24
24
|
return tr;
|
|
@@ -59,7 +59,7 @@ export function splitCellsInColumns(
|
|
|
59
59
|
// Add the new cells
|
|
60
60
|
for (let cellRowIndex = rowIndex; cellRowIndex < rowIndex + rowspan; cellRowIndex++) {
|
|
61
61
|
for (let i = 0; i < colspan; i++) {
|
|
62
|
-
|
|
62
|
+
const mapping = tr.mapping.slice(mapStart);
|
|
63
63
|
const cellPos = map.positionAt(cellRowIndex, column + i, table);
|
|
64
64
|
tr.insert(
|
|
65
65
|
mapping.map(cellPos + tableStart),
|
|
@@ -167,10 +167,10 @@ export const useMeasureFramerate = (config: UseMeasureFramerateConfig = {}) => {
|
|
|
167
167
|
timeoutMs = 200,
|
|
168
168
|
} = config;
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
const frameCount = useRef(0);
|
|
171
|
+
const lastTime = useRef(0);
|
|
172
|
+
const timeoutId = useRef<NodeJS.Timeout | undefined>();
|
|
173
|
+
const frameRateSamples = useRef<number[]>([]);
|
|
174
174
|
|
|
175
175
|
useEffect(() => {
|
|
176
176
|
return () => {
|
|
@@ -148,7 +148,7 @@ export const colWidthsForRow = (tr: HTMLTableRowElement) => {
|
|
|
148
148
|
}));
|
|
149
149
|
|
|
150
150
|
// reverse engineer cell widths from table widths
|
|
151
|
-
|
|
151
|
+
const domBasedCellWidths: number[] = [];
|
|
152
152
|
cellInfos.map((cell) => {
|
|
153
153
|
domBasedCellWidths.push(...getRelativeDomCellWidths(cell));
|
|
154
154
|
});
|
|
@@ -188,8 +188,8 @@ export const checkEdgeHasMergedCells = (
|
|
|
188
188
|
const { mapByRow, mapByColumn } = tableMap;
|
|
189
189
|
const map = 'row' === direction ? mapByRow : mapByColumn;
|
|
190
190
|
const lengthLimiter = direction === 'row' ? tableMap.width : tableMap.height;
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const minIndex = Math.min(...indexes);
|
|
192
|
+
const maxIndex = Math.max(...indexes);
|
|
193
193
|
let isTopSideHaveMergedCells = false;
|
|
194
194
|
let isBottomSideHaveMergedCells = false;
|
|
195
195
|
|
|
@@ -197,8 +197,8 @@ export const checkEdgeHasMergedCells = (
|
|
|
197
197
|
* this is to check if the cell position from last focused table is overflow. since if you selection from a cell in 6th row and 7th column cell in a 7x8 table to 3x3 table, the cell position will be overflow because new table dont have this cell at all.
|
|
198
198
|
TODO: ED-22335 this should better called only when hover over the drag handle.
|
|
199
199
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
const isOldMinIndex = !map[minIndex - 1] || !map[minIndex];
|
|
201
|
+
const isOldMaxIndex = !map[maxIndex + 1] || !map[maxIndex];
|
|
202
202
|
|
|
203
203
|
if (minIndex > 0 && !isOldMinIndex) {
|
|
204
204
|
const prevSelectionSet = map[minIndex - 1];
|