@atlaskit/editor-plugin-table 7.4.9 → 7.5.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 +12 -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/docs/0-intro.tsx +3 -2
- 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 +7 -1
- package/src/nodeviews/TableResizer.tsx +7 -1
- 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/ui/TableFloatingColumnControls/ColumnControls/index.tsx +4 -1
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +4 -1
- package/src/utils/create.ts +1 -3
- package/src/utils/drag-menu.ts +4 -1
- package/tsconfig.dev.json +1 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { getParentNodeWidth, layoutToWidth } from '@atlaskit/editor-common/node-width';
|
|
1
|
+
import { getParentNodeWidth, getTableContainerWidth, layoutToWidth } from '@atlaskit/editor-common/node-width';
|
|
2
2
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
3
3
|
import { getBreakpoint, mapBreakpointToLayoutMaxWidth } from '@atlaskit/editor-common/ui';
|
|
4
|
-
import { containsClassName } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { calcTableColumnWidths, containsClassName } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
|
+
import { hasTableBeenResized } from './colgroup';
|
|
8
|
+
|
|
7
9
|
// Translates named layouts in number values.
|
|
8
10
|
export function getLayoutSize(tableLayout, containerWidth = 0, options) {
|
|
9
11
|
const {
|
|
@@ -71,4 +73,20 @@ export const getTableMaxWidth = ({
|
|
|
71
73
|
maxWidth -= akEditorTableNumberColumnWidth;
|
|
72
74
|
}
|
|
73
75
|
return maxWidth;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param table
|
|
81
|
+
* @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
|
|
82
|
+
*/
|
|
83
|
+
export const getTableElementWidth = table => {
|
|
84
|
+
if (hasTableBeenResized(table)) {
|
|
85
|
+
// TODO: is there a scenario where ADF columns are SMALLER than container width?
|
|
86
|
+
return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
|
|
87
|
+
}
|
|
88
|
+
return getTableContainerElement(table);
|
|
89
|
+
};
|
|
90
|
+
export const getTableContainerElement = table => {
|
|
91
|
+
return getTableContainerWidth(table);
|
|
74
92
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
3
3
|
import { updateColgroup } from './resize-state';
|
|
4
|
-
export const resizeColumn = (resizeState, colIndex, amount, tableRef, selectedColumns) => {
|
|
4
|
+
export const resizeColumn = (resizeState, colIndex, amount, tableRef, selectedColumns, tablePreserveWidth = false) => {
|
|
5
5
|
const newState = amount > 0 ? growColumn(resizeState, colIndex, amount, selectedColumns) : amount < 0 ? shrinkColumn(resizeState, colIndex, amount, selectedColumns) : resizeState;
|
|
6
|
-
updateColgroup(newState, tableRef);
|
|
6
|
+
updateColgroup(newState, tableRef, tablePreserveWidth);
|
|
7
7
|
return newState;
|
|
8
8
|
};
|
|
@@ -6,14 +6,17 @@ import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './c
|
|
|
6
6
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
7
7
|
import { syncStickyRowToTable } from './dom';
|
|
8
8
|
import { getTableMaxWidth } from './misc';
|
|
9
|
+
import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
9
10
|
export const getResizeState = ({
|
|
10
11
|
minWidth,
|
|
11
12
|
maxSize,
|
|
12
13
|
table,
|
|
13
14
|
tableRef,
|
|
14
15
|
start,
|
|
15
|
-
domAtPos
|
|
16
|
+
domAtPos,
|
|
17
|
+
tablePreserveWidth = false
|
|
16
18
|
}) => {
|
|
19
|
+
// If the table has been resized, we can use the column widths from the table node
|
|
17
20
|
if (hasTableBeenResized(table)) {
|
|
18
21
|
const cols = calcTableColumnWidths(table).map((width, index) => ({
|
|
19
22
|
width: width === 0 ? tableNewColumnMinWidth : width,
|
|
@@ -31,10 +34,22 @@ export const getResizeState = ({
|
|
|
31
34
|
overflow
|
|
32
35
|
};
|
|
33
36
|
}
|
|
37
|
+
const shouldReinsertColgroup = !tablePreserveWidth;
|
|
34
38
|
|
|
35
39
|
// Getting the resize state from DOM
|
|
36
|
-
const colgroupChildren = insertColgroupFromNode(tableRef, table
|
|
40
|
+
const colgroupChildren = insertColgroupFromNode(tableRef, table, tablePreserveWidth, shouldReinsertColgroup // don't reinsert colgroup when preserving table width - this causes widths to jump
|
|
41
|
+
);
|
|
42
|
+
|
|
37
43
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
44
|
+
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
45
|
+
// to calculate the widths of the columns
|
|
46
|
+
if (tablePreserveWidth && table.attrs.width) {
|
|
47
|
+
return {
|
|
48
|
+
index,
|
|
49
|
+
width: table.attrs.width / colgroupChildren.length,
|
|
50
|
+
minWidth: 48
|
|
51
|
+
};
|
|
52
|
+
}
|
|
38
53
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
39
54
|
return getColumnStateFromDOM(cellsRefs, index, minWidth);
|
|
40
55
|
});
|
|
@@ -51,16 +66,37 @@ export const getResizeState = ({
|
|
|
51
66
|
};
|
|
52
67
|
|
|
53
68
|
// updates Colgroup DOM node with new widths
|
|
54
|
-
export const updateColgroup = (state, tableRef) => {
|
|
69
|
+
export const updateColgroup = (state, tableRef, tablePreserveWidth) => {
|
|
55
70
|
const cols = tableRef.querySelectorAll('col');
|
|
56
71
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
57
72
|
const columnsCount = cols.length;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
if (tablePreserveWidth) {
|
|
74
|
+
var _tableRef$dataset;
|
|
75
|
+
const tableWidth = parseInt(((_tableRef$dataset = tableRef.dataset) === null || _tableRef$dataset === void 0 ? void 0 : _tableRef$dataset.tableWidth) || ''); // TODO - get this value from the table node, not the dom
|
|
76
|
+
if (tableWidth) {
|
|
77
|
+
var _tableRef$parentEleme;
|
|
78
|
+
let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || TABLE_DEFAULT_WIDTH;
|
|
79
|
+
let scalePercent = renderWidth / tableWidth;
|
|
80
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
81
|
+
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
82
|
+
.forEach((column, i) => {
|
|
83
|
+
const fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
84
|
+
const scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
|
|
85
|
+
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
86
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
87
|
+
if (cols[i]) {
|
|
88
|
+
cols[i].style.width = `${finalWidth}px`;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
62
91
|
}
|
|
63
|
-
}
|
|
92
|
+
} else {
|
|
93
|
+
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
94
|
+
.forEach((column, i) => {
|
|
95
|
+
if (cols[i]) {
|
|
96
|
+
cols[i].style.width = `${getColWidthFix(column.width, columnsCount)}px`;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
64
100
|
} else {
|
|
65
101
|
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
66
102
|
.forEach((column, i) => {
|
|
@@ -240,7 +276,7 @@ export const normaliseTableLayout = input => {
|
|
|
240
276
|
return 'default';
|
|
241
277
|
}
|
|
242
278
|
};
|
|
243
|
-
export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getEditorContainerWidth) => {
|
|
279
|
+
export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getEditorContainerWidth, tablePreserveWidth = false) => {
|
|
244
280
|
// Fail early so that we don't do complex calculations for no reason
|
|
245
281
|
const numColumnsSelected = rect.right - rect.left;
|
|
246
282
|
if (numColumnsSelected <= 1) {
|
|
@@ -278,7 +314,8 @@ export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getE
|
|
|
278
314
|
table: table.node,
|
|
279
315
|
tableRef,
|
|
280
316
|
start: table.start,
|
|
281
|
-
domAtPos
|
|
317
|
+
domAtPos,
|
|
318
|
+
tablePreserveWidth
|
|
282
319
|
});
|
|
283
320
|
const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
|
|
284
321
|
const widthsBefore = resizeState.widths;
|
|
@@ -10,7 +10,7 @@ import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
|
10
10
|
import { syncStickyRowToTable } from './dom';
|
|
11
11
|
// Base function to trigger the actual scale on a table node.
|
|
12
12
|
// Will only resize/scale if a table has been previously resized.
|
|
13
|
-
export const scale = (tableRef, options, domAtPos) => {
|
|
13
|
+
export const scale = (tableRef, options, domAtPos, tablePreserveWidth = false) => {
|
|
14
14
|
/**
|
|
15
15
|
* isBreakoutEnabled === true -> default center aligned
|
|
16
16
|
* isBreakoutEnabled === false -> full width mode
|
|
@@ -57,18 +57,20 @@ export const scale = (tableRef, options, domAtPos) => {
|
|
|
57
57
|
table: node,
|
|
58
58
|
tableRef,
|
|
59
59
|
start,
|
|
60
|
-
domAtPos
|
|
60
|
+
domAtPos,
|
|
61
|
+
tablePreserveWidth
|
|
61
62
|
});
|
|
62
63
|
return scaleTableTo(resizeState, newWidth);
|
|
63
64
|
};
|
|
64
|
-
export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos) => {
|
|
65
|
+
export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, tablePreserveWidth = false) => {
|
|
65
66
|
const resizeState = getResizeState({
|
|
66
67
|
minWidth: tableCellMinWidth,
|
|
67
68
|
maxSize: parentWidth,
|
|
68
69
|
table,
|
|
69
70
|
tableRef,
|
|
70
71
|
start,
|
|
71
|
-
domAtPos
|
|
72
|
+
domAtPos,
|
|
73
|
+
tablePreserveWidth
|
|
72
74
|
});
|
|
73
75
|
if (table.attrs.isNumberColumnEnabled) {
|
|
74
76
|
parentWidth -= akEditorTableNumberColumnWidth;
|
|
@@ -103,7 +105,7 @@ export function scaleTableTo(state, maxSize) {
|
|
|
103
105
|
}
|
|
104
106
|
return adjustColumnsWidths(newState, maxSize);
|
|
105
107
|
}
|
|
106
|
-
export const previewScaleTable = (tableRef, options, domAtPos) => {
|
|
108
|
+
export const previewScaleTable = (tableRef, options, domAtPos, tablePreserveWidth = false) => {
|
|
107
109
|
const {
|
|
108
110
|
node,
|
|
109
111
|
start,
|
|
@@ -117,18 +119,21 @@ export const previewScaleTable = (tableRef, options, domAtPos) => {
|
|
|
117
119
|
const width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
|
|
118
120
|
tableRef.style.width = `${width}px`;
|
|
119
121
|
}
|
|
120
|
-
|
|
122
|
+
|
|
123
|
+
// If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
|
|
124
|
+
// If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
|
|
125
|
+
if (!hasTableBeenResized(node) && !tablePreserveWidth) {
|
|
121
126
|
syncStickyRowToTable(tableRef);
|
|
122
127
|
return;
|
|
123
128
|
}
|
|
124
|
-
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
|
|
129
|
+
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth) : scale(tableRef, options, domAtPos, tablePreserveWidth);
|
|
125
130
|
if (resizeState) {
|
|
126
|
-
updateColgroup(resizeState, tableRef);
|
|
131
|
+
updateColgroup(resizeState, tableRef, tablePreserveWidth);
|
|
127
132
|
}
|
|
128
133
|
};
|
|
129
134
|
|
|
130
135
|
// Scale the table to meet new requirements (col, layout change etc)
|
|
131
|
-
export const scaleTable = (tableRef, options, domAtPos) => tr => {
|
|
136
|
+
export const scaleTable = (tableRef, options, domAtPos, tablePreserveWidth = false) => tr => {
|
|
132
137
|
if (!tableRef) {
|
|
133
138
|
return tr;
|
|
134
139
|
}
|
|
@@ -142,15 +147,17 @@ export const scaleTable = (tableRef, options, domAtPos) => tr => {
|
|
|
142
147
|
if (hasTableBeenResized(node) === false) {
|
|
143
148
|
// If its not a re-sized table, we still want to re-create cols
|
|
144
149
|
// To force reflow of columns upon delete.
|
|
145
|
-
|
|
150
|
+
if (!tablePreserveWidth) {
|
|
151
|
+
insertColgroupFromNode(tableRef, node);
|
|
152
|
+
}
|
|
146
153
|
tr.setMeta('scrollIntoView', false);
|
|
147
154
|
return tr;
|
|
148
155
|
}
|
|
149
156
|
let resizeState;
|
|
150
157
|
if (parentWidth) {
|
|
151
|
-
resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
|
|
158
|
+
resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth);
|
|
152
159
|
} else {
|
|
153
|
-
resizeState = scale(tableRef, options, domAtPos);
|
|
160
|
+
resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
|
|
154
161
|
}
|
|
155
162
|
if (resizeState) {
|
|
156
163
|
tr = updateColumnWidths(resizeState, node, start)(tr);
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -80,7 +80,7 @@ export const getToolbarMenuConfig = (config, state, {
|
|
|
80
80
|
// with native widgets. It's enabled via a plugin config.
|
|
81
81
|
export const getToolbarCellOptionsConfig = (editorState, editorView, initialSelectionRect, {
|
|
82
82
|
formatMessage
|
|
83
|
-
}, getEditorContainerWidth, editorAnalyticsAPI) => {
|
|
83
|
+
}, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => {
|
|
84
84
|
var _pluginState$pluginCo, _pluginState$pluginCo2;
|
|
85
85
|
const {
|
|
86
86
|
top,
|
|
@@ -98,7 +98,7 @@ export const getToolbarCellOptionsConfig = (editorState, editorView, initialSele
|
|
|
98
98
|
const selectionRect = getClosestSelectionRect(state);
|
|
99
99
|
const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right;
|
|
100
100
|
if (index) {
|
|
101
|
-
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
|
|
101
|
+
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
|
|
102
102
|
}
|
|
103
103
|
return true;
|
|
104
104
|
},
|
|
@@ -177,7 +177,7 @@ export const getToolbarCellOptionsConfig = (editorState, editorView, initialSele
|
|
|
177
177
|
}];
|
|
178
178
|
if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
|
|
179
179
|
var _newResizeStateWithAn;
|
|
180
|
-
const newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth) : undefined;
|
|
180
|
+
const newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth) : undefined;
|
|
181
181
|
const wouldChange = (_newResizeStateWithAn = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn !== void 0 ? _newResizeStateWithAn : false;
|
|
182
182
|
const distributeColumnWidths = (state, dispatch) => {
|
|
183
183
|
if (newResizeStateWithAnalytics) {
|
|
@@ -296,10 +296,13 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
296
296
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
297
297
|
const nodeType = state.schema.nodes.table;
|
|
298
298
|
const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
299
|
+
const {
|
|
300
|
+
tablePreserveWidth = false
|
|
301
|
+
} = getEditorFeatureFlags();
|
|
299
302
|
let cellItems;
|
|
300
|
-
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
|
|
303
|
+
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
|
|
301
304
|
let columnSettingsItems;
|
|
302
|
-
columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
|
|
305
|
+
columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth) : [];
|
|
303
306
|
const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
|
|
304
307
|
|
|
305
308
|
// Check if we need to show confirm dialog for delete button
|
|
@@ -390,22 +393,22 @@ const separator = hidden => {
|
|
|
390
393
|
};
|
|
391
394
|
const getCellItems = (pluginConfig, state, view, {
|
|
392
395
|
formatMessage
|
|
393
|
-
}, getEditorContainerWidth, editorAnalyticsAPI) => {
|
|
396
|
+
}, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => {
|
|
394
397
|
const initialSelectionRect = getClosestSelectionRect(state);
|
|
395
398
|
if (initialSelectionRect) {
|
|
396
399
|
const cellOptions = getToolbarCellOptionsConfig(state, view, initialSelectionRect, {
|
|
397
400
|
formatMessage
|
|
398
|
-
}, getEditorContainerWidth, editorAnalyticsAPI);
|
|
401
|
+
}, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
|
|
399
402
|
return [cellOptions, separator(cellOptions.hidden)];
|
|
400
403
|
}
|
|
401
404
|
return [];
|
|
402
405
|
};
|
|
403
|
-
export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI) => (state, dispatch, editorView) => {
|
|
406
|
+
export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => (state, dispatch, editorView) => {
|
|
404
407
|
const selectionOrTableRect = getClosestSelectionOrTableRect(state);
|
|
405
408
|
if (!editorView || !selectionOrTableRect) {
|
|
406
409
|
return false;
|
|
407
410
|
}
|
|
408
|
-
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
|
|
411
|
+
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
409
412
|
if (newResizeStateWithAnalytics) {
|
|
410
413
|
distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
|
|
411
414
|
return true;
|
|
@@ -417,14 +420,14 @@ export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI)
|
|
|
417
420
|
// fixed column button should be in this function call in the future
|
|
418
421
|
const getColumnSettingItems = (editorState, editorView, {
|
|
419
422
|
formatMessage
|
|
420
|
-
}, getEditorContainerWidth, editorAnalyticsAPI) => {
|
|
423
|
+
}, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth = false) => {
|
|
421
424
|
var _newResizeStateWithAn2, _pluginState$pluginCo3;
|
|
422
425
|
const pluginState = getPluginState(editorState);
|
|
423
426
|
const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
|
|
424
427
|
if (!selectionOrTableRect || !editorView) {
|
|
425
428
|
return [];
|
|
426
429
|
}
|
|
427
|
-
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
|
|
430
|
+
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
428
431
|
const wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
|
|
429
432
|
if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
|
|
430
433
|
return [{
|
|
@@ -432,7 +435,7 @@ const getColumnSettingItems = (editorState, editorView, {
|
|
|
432
435
|
type: 'button',
|
|
433
436
|
title: formatMessage(messages.distributeColumns),
|
|
434
437
|
icon: DistributeColumnIcon,
|
|
435
|
-
onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view),
|
|
438
|
+
onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(state, dispatch, view),
|
|
436
439
|
disabled: !wouldChange
|
|
437
440
|
}, {
|
|
438
441
|
type: 'separator'
|
|
@@ -2,7 +2,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
|
2
2
|
import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
|
|
3
3
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
4
4
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
5
|
-
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
5
|
+
import { getTableContainerElement, getTableElementWidth, hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
6
6
|
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
7
7
|
import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
|
|
8
8
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
@@ -85,8 +85,7 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
|
|
|
85
85
|
* @param view
|
|
86
86
|
* @returns Updated transaction with rescaled columns for a given table
|
|
87
87
|
*/
|
|
88
|
-
export const rescaleColumns = () => (table, view) => tr => {
|
|
89
|
-
var _tableRef$parentEleme, _tableRef$parentEleme2;
|
|
88
|
+
export const rescaleColumns = (tablePreserveWidth = false) => (table, view) => tr => {
|
|
90
89
|
if (!view) {
|
|
91
90
|
return tr;
|
|
92
91
|
}
|
|
@@ -98,14 +97,28 @@ export const rescaleColumns = () => (table, view) => tr => {
|
|
|
98
97
|
return tr;
|
|
99
98
|
}
|
|
100
99
|
const isResized = hasTableBeenResized(table.node);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
|
|
105
|
-
/** the is the width the table can reach before overflowing */
|
|
106
|
-
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
|
|
100
|
+
let previousTableInfo = {
|
|
101
|
+
width: 0,
|
|
102
|
+
possibleMaxWidth: 0,
|
|
107
103
|
isResized
|
|
108
104
|
};
|
|
105
|
+
if (tablePreserveWidth) {
|
|
106
|
+
previousTableInfo = {
|
|
107
|
+
// TODO - ensure correct width is returned when table doesn't have a width value
|
|
108
|
+
width: getTableElementWidth(table.node),
|
|
109
|
+
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? getTableContainerElement(table.node) : getTableContainerElement(table.node) - insertColumnButtonOffset,
|
|
110
|
+
isResized
|
|
111
|
+
};
|
|
112
|
+
} else {
|
|
113
|
+
var _tableRef$parentEleme, _tableRef$parentEleme2;
|
|
114
|
+
previousTableInfo = {
|
|
115
|
+
// when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
|
|
116
|
+
width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
|
|
117
|
+
/** the is the width the table can reach before overflowing */
|
|
118
|
+
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
|
|
119
|
+
isResized
|
|
120
|
+
};
|
|
121
|
+
}
|
|
109
122
|
|
|
110
123
|
// determine the new table, based on new width
|
|
111
124
|
const newTableInfo = {
|
|
@@ -148,7 +161,8 @@ export const rescaleColumns = () => (table, view) => tr => {
|
|
|
148
161
|
start: table.start,
|
|
149
162
|
tableRef,
|
|
150
163
|
domAtPos,
|
|
151
|
-
maxSize: previousTableInfo.possibleMaxWidth
|
|
164
|
+
maxSize: previousTableInfo.possibleMaxWidth,
|
|
165
|
+
tablePreserveWidth
|
|
152
166
|
});
|
|
153
167
|
|
|
154
168
|
// Two scenarios that require scaling:
|
|
@@ -192,7 +192,7 @@ function fixRowSpans(table) {
|
|
|
192
192
|
}
|
|
193
193
|
return table.type.createChecked(table.attrs, rows, table.marks);
|
|
194
194
|
}
|
|
195
|
-
export const deleteColumns = (rect, allowCustomStep, view) => tr => {
|
|
195
|
+
export const deleteColumns = (rect, allowCustomStep, view, tablePreserveWidth = false) => tr => {
|
|
196
196
|
let updatedTr = tr;
|
|
197
197
|
updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
198
198
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN
|
|
@@ -204,7 +204,7 @@ export const deleteColumns = (rect, allowCustomStep, view) => tr => {
|
|
|
204
204
|
}
|
|
205
205
|
const table = findTable(updatedTr.selection);
|
|
206
206
|
if (table) {
|
|
207
|
-
updatedTr = rescaleColumns()(table, view)(updatedTr);
|
|
207
|
+
updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
|
|
208
208
|
}
|
|
209
209
|
return updatedTr;
|
|
210
210
|
};
|
|
@@ -302,8 +302,11 @@ export class ContextualMenu extends Component {
|
|
|
302
302
|
}
|
|
303
303
|
} = getPluginState(editorView.state);
|
|
304
304
|
if (allowDistributeColumns && (!isDragAndDropEnabled || !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))) {
|
|
305
|
-
var _newResizeState$chang;
|
|
306
|
-
const
|
|
305
|
+
var _this$props$getEditor, _this$props, _newResizeState$chang;
|
|
306
|
+
const {
|
|
307
|
+
tablePreserveWidth = false
|
|
308
|
+
} = ((_this$props$getEditor = (_this$props = this.props).getEditorFeatureFlags) === null || _this$props$getEditor === void 0 ? void 0 : _this$props$getEditor.call(_this$props)) || {};
|
|
309
|
+
const newResizeState = getNewResizeStateFromSelectedColumns(selectionRect, editorView.state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
307
310
|
const wouldChange = (_newResizeState$chang = newResizeState === null || newResizeState === void 0 ? void 0 : newResizeState.changed) !== null && _newResizeState$chang !== void 0 ? _newResizeState$chang : false;
|
|
308
311
|
return {
|
|
309
312
|
content: formatMessage(messages.distributeColumns),
|
|
@@ -397,7 +400,8 @@ export class ContextualMenu extends Component {
|
|
|
397
400
|
editorView,
|
|
398
401
|
selectionRect,
|
|
399
402
|
editorAnalyticsAPI,
|
|
400
|
-
getEditorContainerWidth
|
|
403
|
+
getEditorContainerWidth,
|
|
404
|
+
getEditorFeatureFlags
|
|
401
405
|
} = this.props;
|
|
402
406
|
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
403
407
|
const {
|
|
@@ -407,6 +411,9 @@ export class ContextualMenu extends Component {
|
|
|
407
411
|
const {
|
|
408
412
|
targetCellPosition
|
|
409
413
|
} = getPluginState(state);
|
|
414
|
+
const {
|
|
415
|
+
tablePreserveWidth = false
|
|
416
|
+
} = (getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) || {};
|
|
410
417
|
switch (item.value.name) {
|
|
411
418
|
case 'sort_column_desc':
|
|
412
419
|
sortColumnWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect.left, SortOrder.DESC)(state, dispatch);
|
|
@@ -425,7 +432,7 @@ export class ContextualMenu extends Component {
|
|
|
425
432
|
this.toggleOpen();
|
|
426
433
|
break;
|
|
427
434
|
case 'distribute_columns':
|
|
428
|
-
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
|
|
435
|
+
const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
429
436
|
if (newResizeStateWithAnalytics) {
|
|
430
437
|
distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, newResizeStateWithAnalytics)(state, dispatch);
|
|
431
438
|
this.toggleOpen();
|
|
@@ -436,7 +443,7 @@ export class ContextualMenu extends Component {
|
|
|
436
443
|
this.toggleOpen();
|
|
437
444
|
break;
|
|
438
445
|
case 'insert_column':
|
|
439
|
-
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(state, dispatch, editorView);
|
|
446
|
+
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(state, dispatch, editorView);
|
|
440
447
|
this.toggleOpen();
|
|
441
448
|
break;
|
|
442
449
|
case 'insert_row':
|
|
@@ -16,7 +16,8 @@ const FloatingContextualMenu = ({
|
|
|
16
16
|
isOpen,
|
|
17
17
|
pluginConfig,
|
|
18
18
|
editorAnalyticsAPI,
|
|
19
|
-
getEditorContainerWidth
|
|
19
|
+
getEditorContainerWidth,
|
|
20
|
+
getEditorFeatureFlags
|
|
20
21
|
}) => {
|
|
21
22
|
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
22
23
|
const {
|
|
@@ -68,7 +69,8 @@ const FloatingContextualMenu = ({
|
|
|
68
69
|
selectionRect: selectionRect,
|
|
69
70
|
boundariesElement: boundariesElement,
|
|
70
71
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
71
|
-
getEditorContainerWidth: getEditorContainerWidth
|
|
72
|
+
getEditorContainerWidth: getEditorContainerWidth,
|
|
73
|
+
getEditorFeatureFlags: getEditorFeatureFlags
|
|
72
74
|
})));
|
|
73
75
|
};
|
|
74
76
|
FloatingContextualMenu.displayName = 'FloatingContextualMenu';
|
|
@@ -175,7 +175,8 @@ export const DragMenu = /*#__PURE__*/React.memo(({
|
|
|
175
175
|
fitWidth,
|
|
176
176
|
mountPoint,
|
|
177
177
|
scrollableElement,
|
|
178
|
-
boundariesElement
|
|
178
|
+
boundariesElement,
|
|
179
|
+
tablePreserveWidth
|
|
179
180
|
}) => {
|
|
180
181
|
var _pluginConfig$allowBa;
|
|
181
182
|
const {
|
|
@@ -195,7 +196,7 @@ export const DragMenu = /*#__PURE__*/React.memo(({
|
|
|
195
196
|
const shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
|
|
196
197
|
const hasMergedCellsInTable = getMergedCellsPositions(state.tr).length > 0;
|
|
197
198
|
const allowBackgroundColor = (_pluginConfig$allowBa = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.allowBackgroundColor) !== null && _pluginConfig$allowBa !== void 0 ? _pluginConfig$allowBa : false;
|
|
198
|
-
const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.isHeaderRowRequired);
|
|
199
|
+
const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.isHeaderRowRequired, tablePreserveWidth);
|
|
199
200
|
const {
|
|
200
201
|
menuItems,
|
|
201
202
|
menuCallback
|
|
@@ -17,7 +17,8 @@ const FloatingDragMenu = ({
|
|
|
17
17
|
getEditorContainerWidth,
|
|
18
18
|
editorAnalyticsAPI,
|
|
19
19
|
stickyHeaders,
|
|
20
|
-
pluginConfig
|
|
20
|
+
pluginConfig,
|
|
21
|
+
getEditorFeatureFlags
|
|
21
22
|
}) => {
|
|
22
23
|
if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
|
|
23
24
|
return null;
|
|
@@ -28,6 +29,9 @@ const FloatingDragMenu = ({
|
|
|
28
29
|
if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
32
|
+
const {
|
|
33
|
+
tablePreserveWidth = false
|
|
34
|
+
} = getEditorFeatureFlags();
|
|
31
35
|
return /*#__PURE__*/React.createElement(Popup, {
|
|
32
36
|
alignX: direction === 'row' ? 'right' : undefined,
|
|
33
37
|
alignY: direction === 'row' ? 'start' : undefined,
|
|
@@ -60,7 +64,8 @@ const FloatingDragMenu = ({
|
|
|
60
64
|
fitHeight: tablePopupMenuFitHeight,
|
|
61
65
|
mountPoint: mountPoint,
|
|
62
66
|
boundariesElement: boundariesElement,
|
|
63
|
-
scrollableElement: scrollableElement
|
|
67
|
+
scrollableElement: scrollableElement,
|
|
68
|
+
tablePreserveWidth: tablePreserveWidth
|
|
64
69
|
}));
|
|
65
70
|
};
|
|
66
71
|
FloatingDragMenu.displayName = 'FloatingDragMenu';
|
|
@@ -177,12 +177,16 @@ export class FloatingInsertButton extends React.Component {
|
|
|
177
177
|
getEditorContainerWidth
|
|
178
178
|
} = this.props;
|
|
179
179
|
if (typeof insertColumnButtonIndex !== 'undefined') {
|
|
180
|
+
var _this$props$getEditor, _this$props;
|
|
180
181
|
event.preventDefault();
|
|
182
|
+
const {
|
|
183
|
+
tablePreserveWidth = false
|
|
184
|
+
} = ((_this$props$getEditor = (_this$props = this.props).getEditorFeatureFlags) === null || _this$props$getEditor === void 0 ? void 0 : _this$props$getEditor.call(_this$props)) || {};
|
|
181
185
|
const {
|
|
182
186
|
state,
|
|
183
187
|
dispatch
|
|
184
188
|
} = editorView;
|
|
185
|
-
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(state, dispatch, editorView);
|
|
189
|
+
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(state, dispatch, editorView);
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
}
|
|
@@ -3,7 +3,7 @@ import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
|
3
3
|
export const createTableWithWidth = (isFullWidthModeEnabled, getEditorFeatureFlags, createTableProps) => schema => {
|
|
4
4
|
const {
|
|
5
5
|
tablePreserveWidth = false
|
|
6
|
-
} = getEditorFeatureFlags ? getEditorFeatureFlags()
|
|
6
|
+
} = (getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) || {};
|
|
7
7
|
if (tablePreserveWidth && isFullWidthModeEnabled) {
|
|
8
8
|
return createTable({
|
|
9
9
|
schema,
|
|
@@ -58,7 +58,7 @@ const defaultSelectionRect = {
|
|
|
58
58
|
right: 0,
|
|
59
59
|
bottom: 0
|
|
60
60
|
};
|
|
61
|
-
export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, isHeaderRowRequired) => {
|
|
61
|
+
export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, isHeaderRowRequired, tablePreserveWidth = false) => {
|
|
62
62
|
var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
|
|
63
63
|
const addOptions = direction === 'row' ? [{
|
|
64
64
|
label: 'above',
|
|
@@ -138,7 +138,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
|
|
|
138
138
|
moveCursorToInsertedRow: true
|
|
139
139
|
})(state, dispatch);
|
|
140
140
|
} else {
|
|
141
|
-
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, (index !== null && index !== void 0 ? index : 0) + offset)(state, dispatch, editorView);
|
|
141
|
+
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.TABLE_CONTEXT_MENU, (index !== null && index !== void 0 ? index : 0) + offset)(state, dispatch, editorView);
|
|
142
142
|
}
|
|
143
143
|
return true;
|
|
144
144
|
},
|
|
@@ -150,7 +150,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
|
|
|
150
150
|
onClick: (state, dispatch) => {
|
|
151
151
|
const selectionRect = getClosestSelectionRect(state);
|
|
152
152
|
if (selectionRect) {
|
|
153
|
-
const newResizeState = getNewResizeStateFromSelectedColumns(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
|
|
153
|
+
const newResizeState = getNewResizeStateFromSelectedColumns(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
154
154
|
if (newResizeState) {
|
|
155
155
|
distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, newResizeState)(state, dispatch);
|
|
156
156
|
return true;
|
|
@@ -176,7 +176,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
|
|
|
176
176
|
if (direction === 'row') {
|
|
177
177
|
deleteRowsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect !== null && selectionRect !== void 0 ? selectionRect : defaultSelectionRect, !!isHeaderRowRequired)(state, dispatch);
|
|
178
178
|
} else {
|
|
179
|
-
deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect !== null && selectionRect !== void 0 ? selectionRect : defaultSelectionRect)(state, dispatch, editorView);
|
|
179
|
+
deleteColumnsWithAnalytics(editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect !== null && selectionRect !== void 0 ? selectionRect : defaultSelectionRect)(state, dispatch, editorView);
|
|
180
180
|
}
|
|
181
181
|
return true;
|
|
182
182
|
},
|
|
@@ -122,6 +122,7 @@ export var activateNextResizeArea = function activateNextResizeArea(direction) {
|
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
124
|
export var changeColumnWidthByStep = function changeColumnWidthByStep(stepSize, getEditorContainerWidth) {
|
|
125
|
+
var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
125
126
|
return function (state, dispatch, view) {
|
|
126
127
|
var customTr = state.tr;
|
|
127
128
|
var fakeDispatch = function fakeDispatch(tr) {
|
|
@@ -170,14 +171,15 @@ export var changeColumnWidthByStep = function changeColumnWidthByStep(stepSize,
|
|
|
170
171
|
table: originalTable,
|
|
171
172
|
tableRef: dom,
|
|
172
173
|
start: tableStartPosition,
|
|
173
|
-
domAtPos: domAtPos
|
|
174
|
+
domAtPos: domAtPos,
|
|
175
|
+
tablePreserveWidth: tablePreserveWidth
|
|
174
176
|
});
|
|
175
177
|
updateControls()(state);
|
|
176
178
|
var selectionRect = getSelectionRect(state.selection);
|
|
177
179
|
var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
178
180
|
// only selected (or selected - 1) columns should be distributed
|
|
179
181
|
var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
|
|
180
|
-
var newResizeState = resizeColumn(initialResizeState, colIndex, stepSize, dom, resizingSelectedColumns ? selectedColumns : undefined);
|
|
182
|
+
var newResizeState = resizeColumn(initialResizeState, colIndex, stepSize, dom, resizingSelectedColumns ? selectedColumns : undefined, tablePreserveWidth);
|
|
181
183
|
customTr = updateColumnWidths(newResizeState, originalTable, tableStartPosition)(customTr);
|
|
182
184
|
if (dispatch) {
|
|
183
185
|
dispatch(customTr);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { deleteColumns } from '../transforms/delete-columns';
|
|
2
2
|
import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
|
|
3
3
|
export var deleteColumnsCommand = function deleteColumnsCommand(rect) {
|
|
4
|
+
var tablePreserveWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
4
5
|
return function (state, dispatch, view) {
|
|
5
|
-
var tr = deleteColumns(rect, getAllowAddColumnCustomStep(state), view)(state.tr);
|
|
6
|
+
var tr = deleteColumns(rect, getAllowAddColumnCustomStep(state), view, tablePreserveWidth)(state.tr);
|
|
6
7
|
if (dispatch) {
|
|
7
8
|
dispatch(tr);
|
|
8
9
|
return true;
|