@atlaskit/editor-plugin-table 7.4.9 → 7.5.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/commands/column-resize.js +4 -2
- package/dist/cjs/commands/delete.js +2 -1
- package/dist/cjs/commands/insert.js +6 -3
- package/dist/cjs/commands-with-analytics.js +4 -2
- package/dist/cjs/event-handlers.js +2 -1
- package/dist/cjs/nodeviews/TableComponent.js +116 -47
- package/dist/cjs/nodeviews/TableContainer.js +8 -4
- package/dist/cjs/nodeviews/TableResizer.js +6 -5
- package/dist/cjs/nodeviews/table.js +12 -4
- package/dist/cjs/plugin.js +50 -47
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +9 -6
- package/dist/cjs/pm-plugins/keymap.js +6 -3
- package/dist/cjs/pm-plugins/main.js +4 -1
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +7 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +32 -11
- package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/index.js +24 -0
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +20 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +2 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +52 -11
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +19 -8
- package/dist/cjs/toolbar.js +17 -10
- package/dist/cjs/transforms/column-width.js +22 -7
- package/dist/cjs/transforms/delete-columns.js +2 -1
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
- package/dist/cjs/ui/FloatingContextualMenu/index.js +4 -2
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/cjs/ui/FloatingDragMenu/index.js +7 -2
- package/dist/cjs/ui/FloatingInsertButton/index.js +5 -1
- package/dist/cjs/utils/create.js +1 -1
- package/dist/cjs/utils/drag-menu.js +4 -3
- package/dist/es2019/commands/column-resize.js +4 -3
- package/dist/es2019/commands/delete.js +2 -2
- package/dist/es2019/commands/insert.js +6 -6
- package/dist/es2019/commands-with-analytics.js +4 -4
- package/dist/es2019/event-handlers.js +2 -2
- package/dist/es2019/nodeviews/TableComponent.js +77 -8
- package/dist/es2019/nodeviews/TableContainer.js +8 -4
- package/dist/es2019/nodeviews/TableResizer.js +6 -5
- package/dist/es2019/nodeviews/table.js +12 -4
- package/dist/es2019/plugin.js +14 -8
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +7 -4
- package/dist/es2019/pm-plugins/keymap.js +6 -3
- package/dist/es2019/pm-plugins/main.js +4 -1
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +7 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +31 -12
- package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +20 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +47 -10
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +19 -12
- package/dist/es2019/toolbar.js +15 -12
- package/dist/es2019/transforms/column-width.js +24 -10
- package/dist/es2019/transforms/delete-columns.js +2 -2
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +12 -5
- package/dist/es2019/ui/FloatingContextualMenu/index.js +4 -2
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/es2019/ui/FloatingDragMenu/index.js +7 -2
- package/dist/es2019/ui/FloatingInsertButton/index.js +5 -1
- package/dist/es2019/utils/create.js +1 -1
- package/dist/es2019/utils/drag-menu.js +4 -4
- package/dist/esm/commands/column-resize.js +4 -2
- package/dist/esm/commands/delete.js +2 -1
- package/dist/esm/commands/insert.js +6 -3
- package/dist/esm/commands-with-analytics.js +4 -2
- package/dist/esm/event-handlers.js +2 -1
- package/dist/esm/nodeviews/TableComponent.js +118 -49
- package/dist/esm/nodeviews/TableContainer.js +8 -4
- package/dist/esm/nodeviews/TableResizer.js +6 -5
- package/dist/esm/nodeviews/table.js +12 -4
- package/dist/esm/plugin.js +50 -47
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +9 -6
- package/dist/esm/pm-plugins/keymap.js +6 -3
- package/dist/esm/pm-plugins/main.js +4 -1
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +7 -3
- package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +32 -11
- package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
- package/dist/esm/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +22 -2
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +2 -1
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +52 -11
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +19 -8
- package/dist/esm/toolbar.js +17 -10
- package/dist/esm/transforms/column-width.js +23 -8
- package/dist/esm/transforms/delete-columns.js +2 -1
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +45 -38
- package/dist/esm/ui/FloatingContextualMenu/index.js +4 -2
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/esm/ui/FloatingDragMenu/index.js +7 -2
- package/dist/esm/ui/FloatingInsertButton/index.js +5 -1
- package/dist/esm/utils/create.js +1 -1
- package/dist/esm/utils/drag-menu.js +4 -3
- package/dist/types/commands/column-resize.d.ts +1 -1
- package/dist/types/commands/delete.d.ts +1 -1
- package/dist/types/commands/insert.d.ts +3 -3
- package/dist/types/commands-with-analytics.d.ts +2 -2
- package/dist/types/event-handlers.d.ts +1 -1
- package/dist/types/nodeviews/TableComponent.d.ts +3 -0
- package/dist/types/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/nodeviews/table.d.ts +1 -0
- package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
- package/dist/types/pm-plugins/keymap.d.ts +2 -2
- package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
- package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +2 -2
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
- package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
- package/dist/types/toolbar.d.ts +2 -2
- package/dist/types/transforms/column-width.d.ts +1 -1
- package/dist/types/transforms/delete-columns.d.ts +1 -1
- package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
- package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
- package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
- package/dist/types/utils/drag-menu.d.ts +1 -1
- package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
- package/dist/types-ts4.5/commands/delete.d.ts +1 -1
- package/dist/types-ts4.5/commands/insert.d.ts +3 -3
- package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
- package/dist/types-ts4.5/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +3 -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/nodeviews/table.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +3 -2
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -3
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
- package/dist/types-ts4.5/toolbar.d.ts +2 -2
- package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
- package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -1
- package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -1
- package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
- package/package.json +2 -2
- package/src/commands/column-resize.ts +3 -0
- package/src/commands/delete.ts +2 -1
- package/src/commands/insert.ts +15 -6
- package/src/commands-with-analytics.ts +9 -3
- package/src/event-handlers.ts +2 -0
- package/src/nodeviews/TableComponent.tsx +91 -5
- package/src/nodeviews/TableContainer.tsx +6 -0
- package/src/nodeviews/TableResizer.tsx +6 -0
- package/src/nodeviews/table.tsx +15 -10
- package/src/plugin.tsx +17 -5
- package/src/pm-plugins/drag-and-drop/plugin.ts +16 -8
- package/src/pm-plugins/keymap.ts +11 -3
- package/src/pm-plugins/main.ts +3 -0
- package/src/pm-plugins/table-resizing/event-handlers.ts +11 -1
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +49 -17
- package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
- package/src/pm-plugins/table-resizing/utils/index.ts +8 -1
- package/src/pm-plugins/table-resizing/utils/misc.ts +25 -1
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +2 -1
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +56 -11
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +24 -6
- package/src/toolbar.tsx +18 -5
- package/src/transforms/column-width.ts +33 -11
- package/src/transforms/delete-columns.ts +7 -2
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -5
- package/src/ui/FloatingContextualMenu/index.tsx +2 -0
- package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
- package/src/ui/FloatingDragMenu/index.tsx +9 -1
- package/src/ui/FloatingInsertButton/index.tsx +17 -5
- package/src/utils/create.ts +1 -3
- package/src/utils/drag-menu.ts +4 -1
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -30,7 +30,10 @@ import {
|
|
|
30
30
|
toggleTable,
|
|
31
31
|
} from '@atlaskit/editor-common/keymaps';
|
|
32
32
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
33
|
-
import type {
|
|
33
|
+
import type {
|
|
34
|
+
GetEditorContainerWidth,
|
|
35
|
+
GetEditorFeatureFlags,
|
|
36
|
+
} from '@atlaskit/editor-common/types';
|
|
34
37
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
35
38
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
36
39
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -69,6 +72,7 @@ const createTableWithAnalytics = (
|
|
|
69
72
|
export function keymapPlugin(
|
|
70
73
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
71
74
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
75
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
72
76
|
dragAndDropEnabled?: boolean,
|
|
73
77
|
): SafePlugin {
|
|
74
78
|
const list = {};
|
|
@@ -178,6 +182,10 @@ export function keymapPlugin(
|
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
185
|
+
const { tablePreserveWidth = false } = getEditorFeatureFlags
|
|
186
|
+
? getEditorFeatureFlags()
|
|
187
|
+
: {};
|
|
188
|
+
|
|
181
189
|
bindKeymapWithCommand(
|
|
182
190
|
startColumnResizing.common!,
|
|
183
191
|
initiateKeyboardColumnResizing,
|
|
@@ -190,13 +198,13 @@ export function keymapPlugin(
|
|
|
190
198
|
|
|
191
199
|
bindKeymapWithCommand(
|
|
192
200
|
decreaseMediaSize.common!,
|
|
193
|
-
changeColumnWidthByStep(-10, getEditorContainerWidth),
|
|
201
|
+
changeColumnWidthByStep(-10, getEditorContainerWidth, tablePreserveWidth),
|
|
194
202
|
list,
|
|
195
203
|
);
|
|
196
204
|
|
|
197
205
|
bindKeymapWithCommand(
|
|
198
206
|
increaseMediaSize.common!,
|
|
199
|
-
changeColumnWidthByStep(10, getEditorContainerWidth),
|
|
207
|
+
changeColumnWidthByStep(10, getEditorContainerWidth, tablePreserveWidth),
|
|
200
208
|
list,
|
|
201
209
|
);
|
|
202
210
|
bindKeymapWithCommand(escape.common!, stopKeyboardColumnResizing(), list);
|
package/src/pm-plugins/main.ts
CHANGED
|
@@ -188,6 +188,8 @@ export const createPlugin = (
|
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
const { tablePreserveWidth = false } = getEditorFeatureFlags();
|
|
192
|
+
|
|
191
193
|
if (tr) {
|
|
192
194
|
// "fixTables" removes empty rows as we don't allow that in schema
|
|
193
195
|
const updatedTr = handleCut(
|
|
@@ -196,6 +198,7 @@ export const createPlugin = (
|
|
|
196
198
|
newState,
|
|
197
199
|
editorAnalyticsAPI,
|
|
198
200
|
editorViewRef || undefined,
|
|
201
|
+
tablePreserveWidth,
|
|
199
202
|
);
|
|
200
203
|
return fixTables(updatedTr) || updatedTr;
|
|
201
204
|
}
|
|
@@ -48,6 +48,7 @@ export const handleMouseDown = (
|
|
|
48
48
|
const { state, dispatch } = view;
|
|
49
49
|
const editorDisabled = !view.editable;
|
|
50
50
|
const domAtPos = view.domAtPos.bind(view);
|
|
51
|
+
const { tablePreserveWidth = false } = getEditorFeatureFlags();
|
|
51
52
|
|
|
52
53
|
if (
|
|
53
54
|
editorDisabled ||
|
|
@@ -117,6 +118,7 @@ export const handleMouseDown = (
|
|
|
117
118
|
tableRef: dom,
|
|
118
119
|
start,
|
|
119
120
|
domAtPos,
|
|
121
|
+
tablePreserveWidth,
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
if (
|
|
@@ -207,6 +209,7 @@ export const handleMouseDown = (
|
|
|
207
209
|
clientX - startX,
|
|
208
210
|
dom,
|
|
209
211
|
resizingSelectedColumns ? selectedColumns : undefined,
|
|
212
|
+
tablePreserveWidth,
|
|
210
213
|
);
|
|
211
214
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
212
215
|
if (colIndex === map.width - 1) {
|
|
@@ -265,7 +268,14 @@ export const handleMouseDown = (
|
|
|
265
268
|
$cell.nodeAfter!.attrs.colspan -
|
|
266
269
|
1;
|
|
267
270
|
|
|
268
|
-
resizeColumn(
|
|
271
|
+
resizeColumn(
|
|
272
|
+
resizeState,
|
|
273
|
+
colIndex,
|
|
274
|
+
clientX - dragging.startX,
|
|
275
|
+
dom,
|
|
276
|
+
undefined,
|
|
277
|
+
tablePreserveWidth,
|
|
278
|
+
);
|
|
269
279
|
|
|
270
280
|
updateControls()(state);
|
|
271
281
|
}
|
|
@@ -5,6 +5,8 @@ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
|
|
8
|
+
import { MAX_SCALING_PERCENT } from './consts';
|
|
9
|
+
|
|
8
10
|
type Col = Array<string | { [name: string]: string }>;
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -16,7 +18,7 @@ type Col = Array<string | { [name: string]: string }>;
|
|
|
16
18
|
export const getColWidthFix = (colwidth: number, tableColumnCount: number) =>
|
|
17
19
|
colwidth - 1 / tableColumnCount;
|
|
18
20
|
|
|
19
|
-
export const generateColgroup = (table: PmNode) => {
|
|
21
|
+
export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
|
|
20
22
|
const cols: Col[] = [];
|
|
21
23
|
|
|
22
24
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
@@ -26,17 +28,37 @@ export const generateColgroup = (table: PmNode) => {
|
|
|
26
28
|
if (Array.isArray(cell.attrs.colwidth)) {
|
|
27
29
|
// We slice here to guard against our colwidth array having more entries
|
|
28
30
|
// Than the we actually span. We'll patch the document at a later point.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
if (tableRef) {
|
|
32
|
+
const tableWidth = table.attrs && table.attrs.width;
|
|
33
|
+
let renderWidth = tableRef.parentElement?.clientWidth || 760;
|
|
34
|
+
let scalePercent = renderWidth / tableWidth;
|
|
35
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
36
|
+
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
37
|
+
const fixedColWidth = getColWidthFix(width, map.width);
|
|
38
|
+
const scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
|
|
39
|
+
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
40
|
+
cols.push([
|
|
41
|
+
'col',
|
|
42
|
+
{
|
|
43
|
+
style: `width: ${finalWidth}px;`,
|
|
44
|
+
},
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
49
|
+
cols.push([
|
|
50
|
+
'col',
|
|
51
|
+
{
|
|
52
|
+
style: `width: ${getColWidthFix(
|
|
53
|
+
width
|
|
54
|
+
? Math.max(width, tableCellMinWidth)
|
|
55
|
+
: tableCellMinWidth,
|
|
56
|
+
map.width,
|
|
57
|
+
)}px;`,
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
40
62
|
} else {
|
|
41
63
|
// When we have merged cells on the first row (firstChild),
|
|
42
64
|
// We want to ensure we're creating the appropriate amount of
|
|
@@ -73,14 +95,21 @@ export const generateColgroup = (table: PmNode) => {
|
|
|
73
95
|
export const insertColgroupFromNode = (
|
|
74
96
|
tableRef: HTMLTableElement,
|
|
75
97
|
table: PmNode,
|
|
98
|
+
tablePreserveWidth = false,
|
|
99
|
+
shouldRemove = true,
|
|
76
100
|
): HTMLCollection => {
|
|
77
101
|
let colgroup = tableRef.querySelector('colgroup') as HTMLElement;
|
|
78
|
-
if (colgroup) {
|
|
102
|
+
if (colgroup && shouldRemove) {
|
|
79
103
|
tableRef.removeChild(colgroup);
|
|
80
104
|
}
|
|
81
105
|
|
|
82
|
-
colgroup = renderColgroupFromNode(
|
|
83
|
-
|
|
106
|
+
colgroup = renderColgroupFromNode(
|
|
107
|
+
table,
|
|
108
|
+
tablePreserveWidth ? tableRef : undefined,
|
|
109
|
+
);
|
|
110
|
+
if (shouldRemove) {
|
|
111
|
+
tableRef.insertBefore(colgroup, tableRef.firstChild);
|
|
112
|
+
}
|
|
84
113
|
|
|
85
114
|
return colgroup.children;
|
|
86
115
|
};
|
|
@@ -109,11 +138,14 @@ export const isMinCellWidthTable = (table: PmNode) => {
|
|
|
109
138
|
return isTableMinCellWidth;
|
|
110
139
|
};
|
|
111
140
|
|
|
112
|
-
function renderColgroupFromNode(
|
|
141
|
+
function renderColgroupFromNode(
|
|
142
|
+
table: PmNode,
|
|
143
|
+
maybeTableRef: HTMLElement | undefined,
|
|
144
|
+
): HTMLElement {
|
|
113
145
|
const rendered = DOMSerializer.renderSpec(document, [
|
|
114
146
|
'colgroup',
|
|
115
147
|
{},
|
|
116
|
-
...generateColgroup(table),
|
|
148
|
+
...generateColgroup(table, maybeTableRef),
|
|
117
149
|
]);
|
|
118
150
|
|
|
119
151
|
return rendered.dom as HTMLElement;
|
|
@@ -30,6 +30,8 @@ export {
|
|
|
30
30
|
currentColWidth,
|
|
31
31
|
domCellAround,
|
|
32
32
|
getTableMaxWidth,
|
|
33
|
+
getTableElementWidth,
|
|
34
|
+
getTableContainerElement,
|
|
33
35
|
} from './misc';
|
|
34
36
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
35
37
|
export {
|
|
@@ -41,4 +43,9 @@ export {
|
|
|
41
43
|
export type { ScaleOptions } from './scale-table';
|
|
42
44
|
export type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
43
45
|
export { resizeColumn } from './resize-column';
|
|
44
|
-
export {
|
|
46
|
+
export {
|
|
47
|
+
COLUMN_MIN_WIDTH,
|
|
48
|
+
TABLE_MAX_WIDTH,
|
|
49
|
+
TABLE_DEFAULT_WIDTH,
|
|
50
|
+
MAX_SCALING_PERCENT,
|
|
51
|
+
} from './consts';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CellAttributes, TableLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import {
|
|
3
3
|
getParentNodeWidth,
|
|
4
|
+
getTableContainerWidth,
|
|
4
5
|
layoutToWidth,
|
|
5
6
|
} from '@atlaskit/editor-common/node-width';
|
|
6
7
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
@@ -9,7 +10,10 @@ import {
|
|
|
9
10
|
getBreakpoint,
|
|
10
11
|
mapBreakpointToLayoutMaxWidth,
|
|
11
12
|
} from '@atlaskit/editor-common/ui';
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
calcTableColumnWidths,
|
|
15
|
+
containsClassName,
|
|
16
|
+
} from '@atlaskit/editor-common/utils';
|
|
13
17
|
import type {
|
|
14
18
|
NodeSpec,
|
|
15
19
|
Node as PMNode,
|
|
@@ -26,6 +30,8 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
26
30
|
|
|
27
31
|
import type { TableOptions } from '../../../nodeviews/types';
|
|
28
32
|
|
|
33
|
+
import { hasTableBeenResized } from './colgroup';
|
|
34
|
+
|
|
29
35
|
// Translates named layouts in number values.
|
|
30
36
|
export function getLayoutSize(
|
|
31
37
|
tableLayout: TableLayout,
|
|
@@ -132,3 +138,21 @@ export const getTableMaxWidth = ({
|
|
|
132
138
|
|
|
133
139
|
return maxWidth as number;
|
|
134
140
|
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @param table
|
|
145
|
+
* @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
|
|
146
|
+
*/
|
|
147
|
+
export const getTableElementWidth = (table: PMNode) => {
|
|
148
|
+
if (hasTableBeenResized(table)) {
|
|
149
|
+
// TODO: is there a scenario where ADF columns are SMALLER than container width?
|
|
150
|
+
return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return getTableContainerElement(table);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const getTableContainerElement = (table: PMNode) => {
|
|
157
|
+
return getTableContainerWidth(table);
|
|
158
|
+
};
|
|
@@ -9,6 +9,7 @@ export const resizeColumn = (
|
|
|
9
9
|
amount: number,
|
|
10
10
|
tableRef: HTMLElement,
|
|
11
11
|
selectedColumns?: number[],
|
|
12
|
+
tablePreserveWidth = false,
|
|
12
13
|
): ResizeState => {
|
|
13
14
|
const newState =
|
|
14
15
|
amount > 0
|
|
@@ -17,7 +18,7 @@ export const resizeColumn = (
|
|
|
17
18
|
? shrinkColumn(resizeState, colIndex, amount, selectedColumns)
|
|
18
19
|
: resizeState;
|
|
19
20
|
|
|
20
|
-
updateColgroup(newState, tableRef);
|
|
21
|
+
updateColgroup(newState, tableRef, tablePreserveWidth);
|
|
21
22
|
|
|
22
23
|
return newState;
|
|
23
24
|
};
|
|
@@ -23,6 +23,8 @@ import { syncStickyRowToTable } from './dom';
|
|
|
23
23
|
import { getTableMaxWidth } from './misc';
|
|
24
24
|
import type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
25
25
|
|
|
26
|
+
import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
27
|
+
|
|
26
28
|
export const getResizeState = ({
|
|
27
29
|
minWidth,
|
|
28
30
|
maxSize,
|
|
@@ -30,6 +32,7 @@ export const getResizeState = ({
|
|
|
30
32
|
tableRef,
|
|
31
33
|
start,
|
|
32
34
|
domAtPos,
|
|
35
|
+
tablePreserveWidth = false,
|
|
33
36
|
}: {
|
|
34
37
|
minWidth: number;
|
|
35
38
|
maxSize: number;
|
|
@@ -37,7 +40,9 @@ export const getResizeState = ({
|
|
|
37
40
|
tableRef: HTMLTableElement;
|
|
38
41
|
start: number;
|
|
39
42
|
domAtPos: (pos: number) => { node: Node; offset: number };
|
|
43
|
+
tablePreserveWidth: boolean;
|
|
40
44
|
}): ResizeState => {
|
|
45
|
+
// If the table has been resized, we can use the column widths from the table node
|
|
41
46
|
if (hasTableBeenResized(table)) {
|
|
42
47
|
const cols = calcTableColumnWidths(table).map((width, index) => ({
|
|
43
48
|
width: width === 0 ? tableNewColumnMinWidth : width,
|
|
@@ -58,9 +63,25 @@ export const getResizeState = ({
|
|
|
58
63
|
};
|
|
59
64
|
}
|
|
60
65
|
|
|
66
|
+
const shouldReinsertColgroup = !tablePreserveWidth;
|
|
67
|
+
|
|
61
68
|
// Getting the resize state from DOM
|
|
62
|
-
const colgroupChildren = insertColgroupFromNode(
|
|
69
|
+
const colgroupChildren = insertColgroupFromNode(
|
|
70
|
+
tableRef,
|
|
71
|
+
table,
|
|
72
|
+
tablePreserveWidth,
|
|
73
|
+
shouldReinsertColgroup, // don't reinsert colgroup when preserving table width - this causes widths to jump
|
|
74
|
+
);
|
|
63
75
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
76
|
+
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
77
|
+
// to calculate the widths of the columns
|
|
78
|
+
if (tablePreserveWidth && table.attrs.width) {
|
|
79
|
+
return {
|
|
80
|
+
index,
|
|
81
|
+
width: table.attrs.width / colgroupChildren.length,
|
|
82
|
+
minWidth: 48,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
64
85
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
65
86
|
return getColumnStateFromDOM(cellsRefs, index, minWidth);
|
|
66
87
|
});
|
|
@@ -83,21 +104,43 @@ export const getResizeState = ({
|
|
|
83
104
|
export const updateColgroup = (
|
|
84
105
|
state: ResizeState,
|
|
85
106
|
tableRef: HTMLElement,
|
|
107
|
+
tablePreserveWidth?: boolean,
|
|
86
108
|
): void => {
|
|
87
109
|
const cols = tableRef.querySelectorAll('col');
|
|
88
110
|
|
|
89
111
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
90
112
|
const columnsCount = cols.length;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
if (tablePreserveWidth) {
|
|
114
|
+
const tableWidth = parseInt(tableRef.dataset?.tableWidth || ''); // TODO - get this value from the table node, not the dom
|
|
115
|
+
if (tableWidth) {
|
|
116
|
+
let renderWidth =
|
|
117
|
+
tableRef.parentElement?.clientWidth || TABLE_DEFAULT_WIDTH;
|
|
118
|
+
let scalePercent = renderWidth / tableWidth;
|
|
119
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
120
|
+
state.cols
|
|
121
|
+
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
122
|
+
.forEach((column, i) => {
|
|
123
|
+
const fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
124
|
+
const scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
|
|
125
|
+
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
126
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
127
|
+
if (cols[i]) {
|
|
128
|
+
cols[i].style.width = `${finalWidth}px`;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
state.cols
|
|
134
|
+
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
135
|
+
.forEach((column, i) => {
|
|
136
|
+
if (cols[i]) {
|
|
137
|
+
cols[i].style.width = `${getColWidthFix(
|
|
138
|
+
column.width,
|
|
139
|
+
columnsCount,
|
|
140
|
+
)}px`;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
101
144
|
} else {
|
|
102
145
|
state.cols
|
|
103
146
|
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
@@ -306,6 +349,7 @@ export const getNewResizeStateFromSelectedColumns = (
|
|
|
306
349
|
state: EditorState,
|
|
307
350
|
domAtPos: (pos: number) => { node: Node; offset: number },
|
|
308
351
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
352
|
+
tablePreserveWidth = false,
|
|
309
353
|
): ResizeStateWithAnalytics | undefined => {
|
|
310
354
|
// Fail early so that we don't do complex calculations for no reason
|
|
311
355
|
const numColumnsSelected = rect.right - rect.left;
|
|
@@ -350,6 +394,7 @@ export const getNewResizeStateFromSelectedColumns = (
|
|
|
350
394
|
tableRef,
|
|
351
395
|
start: table.start,
|
|
352
396
|
domAtPos,
|
|
397
|
+
tablePreserveWidth,
|
|
353
398
|
});
|
|
354
399
|
|
|
355
400
|
const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
|
|
@@ -39,6 +39,7 @@ export const scale = (
|
|
|
39
39
|
tableRef: HTMLTableElement,
|
|
40
40
|
options: ScaleOptions,
|
|
41
41
|
domAtPos: DomAtPos,
|
|
42
|
+
tablePreserveWidth = false,
|
|
42
43
|
): ResizeState | undefined => {
|
|
43
44
|
/**
|
|
44
45
|
* isBreakoutEnabled === true -> default center aligned
|
|
@@ -97,6 +98,7 @@ export const scale = (
|
|
|
97
98
|
tableRef,
|
|
98
99
|
start,
|
|
99
100
|
domAtPos,
|
|
101
|
+
tablePreserveWidth,
|
|
100
102
|
});
|
|
101
103
|
|
|
102
104
|
return scaleTableTo(resizeState, newWidth);
|
|
@@ -108,6 +110,7 @@ export const scaleWithParent = (
|
|
|
108
110
|
table: PMNode,
|
|
109
111
|
start: number,
|
|
110
112
|
domAtPos: DomAtPos,
|
|
113
|
+
tablePreserveWidth = false,
|
|
111
114
|
) => {
|
|
112
115
|
const resizeState = getResizeState({
|
|
113
116
|
minWidth: tableCellMinWidth,
|
|
@@ -116,6 +119,7 @@ export const scaleWithParent = (
|
|
|
116
119
|
tableRef,
|
|
117
120
|
start,
|
|
118
121
|
domAtPos,
|
|
122
|
+
tablePreserveWidth,
|
|
119
123
|
});
|
|
120
124
|
|
|
121
125
|
if (table.attrs.isNumberColumnEnabled) {
|
|
@@ -154,6 +158,7 @@ export const previewScaleTable = (
|
|
|
154
158
|
tableRef: HTMLTableElement | null | undefined,
|
|
155
159
|
options: ScaleOptions,
|
|
156
160
|
domAtPos: DomAtPos,
|
|
161
|
+
tablePreserveWidth: boolean = false,
|
|
157
162
|
) => {
|
|
158
163
|
const { node, start, parentWidth } = options;
|
|
159
164
|
|
|
@@ -169,17 +174,26 @@ export const previewScaleTable = (
|
|
|
169
174
|
tableRef.style.width = `${width}px`;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
|
|
177
|
+
// If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
|
|
178
|
+
// If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
|
|
179
|
+
if (!hasTableBeenResized(node) && !tablePreserveWidth) {
|
|
173
180
|
syncStickyRowToTable(tableRef);
|
|
174
181
|
return;
|
|
175
182
|
}
|
|
176
183
|
|
|
177
184
|
const resizeState = parentWidth
|
|
178
|
-
? scaleWithParent(
|
|
179
|
-
|
|
185
|
+
? scaleWithParent(
|
|
186
|
+
tableRef,
|
|
187
|
+
parentWidth,
|
|
188
|
+
node,
|
|
189
|
+
start,
|
|
190
|
+
domAtPos,
|
|
191
|
+
tablePreserveWidth,
|
|
192
|
+
)
|
|
193
|
+
: scale(tableRef, options, domAtPos, tablePreserveWidth);
|
|
180
194
|
|
|
181
195
|
if (resizeState) {
|
|
182
|
-
updateColgroup(resizeState, tableRef);
|
|
196
|
+
updateColgroup(resizeState, tableRef, tablePreserveWidth);
|
|
183
197
|
}
|
|
184
198
|
};
|
|
185
199
|
|
|
@@ -189,6 +203,7 @@ export const scaleTable =
|
|
|
189
203
|
tableRef: HTMLTableElement | null | undefined,
|
|
190
204
|
options: ScaleOptions,
|
|
191
205
|
domAtPos: DomAtPos,
|
|
206
|
+
tablePreserveWidth = false,
|
|
192
207
|
) =>
|
|
193
208
|
(tr: Transaction) => {
|
|
194
209
|
if (!tableRef) {
|
|
@@ -200,7 +215,9 @@ export const scaleTable =
|
|
|
200
215
|
if (hasTableBeenResized(node) === false) {
|
|
201
216
|
// If its not a re-sized table, we still want to re-create cols
|
|
202
217
|
// To force reflow of columns upon delete.
|
|
203
|
-
|
|
218
|
+
if (!tablePreserveWidth) {
|
|
219
|
+
insertColgroupFromNode(tableRef, node);
|
|
220
|
+
}
|
|
204
221
|
tr.setMeta('scrollIntoView', false);
|
|
205
222
|
return tr;
|
|
206
223
|
}
|
|
@@ -213,9 +230,10 @@ export const scaleTable =
|
|
|
213
230
|
node,
|
|
214
231
|
start,
|
|
215
232
|
domAtPos,
|
|
233
|
+
tablePreserveWidth,
|
|
216
234
|
);
|
|
217
235
|
} else {
|
|
218
|
-
resizeState = scale(tableRef, options, domAtPos);
|
|
236
|
+
resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
|
|
219
237
|
}
|
|
220
238
|
|
|
221
239
|
if (resizeState) {
|
package/src/toolbar.tsx
CHANGED
|
@@ -169,6 +169,7 @@ export const getToolbarCellOptionsConfig = (
|
|
|
169
169
|
{ formatMessage }: ToolbarMenuContext,
|
|
170
170
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
171
171
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
172
|
+
tablePreserveWidth = false,
|
|
172
173
|
): FloatingToolbarDropdown<Command> => {
|
|
173
174
|
const { top, bottom, right, left } = initialSelectionRect;
|
|
174
175
|
const numberOfColumns = right - left;
|
|
@@ -190,6 +191,7 @@ export const getToolbarCellOptionsConfig = (
|
|
|
190
191
|
insertColumnWithAnalytics(
|
|
191
192
|
getEditorContainerWidth,
|
|
192
193
|
editorAnalyticsAPI,
|
|
194
|
+
tablePreserveWidth,
|
|
193
195
|
)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
|
|
194
196
|
}
|
|
195
197
|
return true;
|
|
@@ -292,6 +294,7 @@ export const getToolbarCellOptionsConfig = (
|
|
|
292
294
|
editorState,
|
|
293
295
|
editorView.domAtPos.bind(editorView),
|
|
294
296
|
getEditorContainerWidth,
|
|
297
|
+
tablePreserveWidth,
|
|
295
298
|
)
|
|
296
299
|
: undefined;
|
|
297
300
|
const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
|
|
@@ -459,6 +462,8 @@ export const getToolbarConfig =
|
|
|
459
462
|
editorAnalyticsAPI,
|
|
460
463
|
);
|
|
461
464
|
|
|
465
|
+
const { tablePreserveWidth = false } = getEditorFeatureFlags();
|
|
466
|
+
|
|
462
467
|
let cellItems: Array<FloatingToolbarItem<Command>>;
|
|
463
468
|
cellItems = pluginState.isDragAndDropEnabled
|
|
464
469
|
? []
|
|
@@ -469,6 +474,7 @@ export const getToolbarConfig =
|
|
|
469
474
|
intl,
|
|
470
475
|
getEditorContainerWidth,
|
|
471
476
|
editorAnalyticsAPI,
|
|
477
|
+
tablePreserveWidth,
|
|
472
478
|
);
|
|
473
479
|
|
|
474
480
|
let columnSettingsItems;
|
|
@@ -481,6 +487,7 @@ export const getToolbarConfig =
|
|
|
481
487
|
intl,
|
|
482
488
|
getEditorContainerWidth,
|
|
483
489
|
editorAnalyticsAPI,
|
|
490
|
+
tablePreserveWidth,
|
|
484
491
|
)
|
|
485
492
|
: [];
|
|
486
493
|
const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
|
|
@@ -606,6 +613,7 @@ const getCellItems = (
|
|
|
606
613
|
{ formatMessage }: ToolbarMenuContext,
|
|
607
614
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
608
615
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
616
|
+
tablePreserveWidth = false,
|
|
609
617
|
): Array<FloatingToolbarItem<Command>> => {
|
|
610
618
|
const initialSelectionRect = getClosestSelectionRect(state);
|
|
611
619
|
if (initialSelectionRect) {
|
|
@@ -616,6 +624,7 @@ const getCellItems = (
|
|
|
616
624
|
{ formatMessage },
|
|
617
625
|
getEditorContainerWidth,
|
|
618
626
|
editorAnalyticsAPI,
|
|
627
|
+
tablePreserveWidth,
|
|
619
628
|
);
|
|
620
629
|
return [cellOptions, separator(cellOptions.hidden!)];
|
|
621
630
|
}
|
|
@@ -626,6 +635,7 @@ export const getDistributeConfig =
|
|
|
626
635
|
(
|
|
627
636
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
628
637
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
638
|
+
tablePreserveWidth = false,
|
|
629
639
|
): Command =>
|
|
630
640
|
(state, dispatch, editorView) => {
|
|
631
641
|
const selectionOrTableRect = getClosestSelectionOrTableRect(state);
|
|
@@ -637,6 +647,7 @@ export const getDistributeConfig =
|
|
|
637
647
|
state,
|
|
638
648
|
editorView.domAtPos.bind(editorView),
|
|
639
649
|
getEditorContainerWidth,
|
|
650
|
+
tablePreserveWidth,
|
|
640
651
|
);
|
|
641
652
|
|
|
642
653
|
if (newResizeStateWithAnalytics) {
|
|
@@ -657,6 +668,7 @@ const getColumnSettingItems = (
|
|
|
657
668
|
{ formatMessage }: ToolbarMenuContext,
|
|
658
669
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
659
670
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
671
|
+
tablePreserveWidth = false,
|
|
660
672
|
): Array<FloatingToolbarItem<Command>> => {
|
|
661
673
|
const pluginState = getPluginState(editorState);
|
|
662
674
|
const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
|
|
@@ -670,6 +682,7 @@ const getColumnSettingItems = (
|
|
|
670
682
|
editorState,
|
|
671
683
|
editorView.domAtPos.bind(editorView),
|
|
672
684
|
getEditorContainerWidth,
|
|
685
|
+
tablePreserveWidth,
|
|
673
686
|
);
|
|
674
687
|
|
|
675
688
|
const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
|
|
@@ -685,11 +698,11 @@ const getColumnSettingItems = (
|
|
|
685
698
|
title: formatMessage(messages.distributeColumns),
|
|
686
699
|
icon: DistributeColumnIcon,
|
|
687
700
|
onClick: (state, dispatch, view) =>
|
|
688
|
-
getDistributeConfig(
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
),
|
|
701
|
+
getDistributeConfig(
|
|
702
|
+
getEditorContainerWidth,
|
|
703
|
+
editorAnalyticsAPI,
|
|
704
|
+
tablePreserveWidth,
|
|
705
|
+
)(state, dispatch, view),
|
|
693
706
|
disabled: !wouldChange,
|
|
694
707
|
},
|
|
695
708
|
{
|