@atlaskit/editor-plugin-table 7.4.8 → 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 +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 +5 -3
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +15 -4
- package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +53 -8
- package/dist/cjs/ui/FloatingDragMenu/index.js +15 -6
- package/dist/cjs/ui/FloatingInsertButton/index.js +5 -1
- package/dist/cjs/ui/consts.js +2 -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 +6 -4
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +15 -4
- package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +42 -8
- package/dist/es2019/ui/FloatingDragMenu/index.js +16 -7
- package/dist/es2019/ui/FloatingInsertButton/index.js +5 -1
- package/dist/es2019/ui/consts.js +1 -0
- 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 +6 -4
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +15 -4
- package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +50 -9
- package/dist/esm/ui/FloatingDragMenu/index.js +16 -7
- package/dist/esm/ui/FloatingInsertButton/index.js +5 -1
- package/dist/esm/ui/consts.js +1 -0
- 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 +7 -1
- package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
- package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
- package/dist/types/ui/consts.d.ts +1 -0
- 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 +7 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
- 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/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
- package/package.json +3 -3
- 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 +4 -1
- package/src/ui/FloatingDragMenu/DragMenu.tsx +19 -1
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +94 -50
- package/src/ui/FloatingDragMenu/index.tsx +17 -4
- package/src/ui/FloatingInsertButton/index.tsx +17 -5
- package/src/ui/consts.ts +1 -0
- package/src/utils/create.ts +1 -3
- package/src/utils/drag-menu.ts +4 -1
|
@@ -20,7 +20,7 @@ var createTableWithAnalytics = function createTableWithAnalytics(editorAnalytics
|
|
|
20
20
|
eventType: EVENT_TYPE.TRACK
|
|
21
21
|
})(editorAnalyticsAPI)(createTable());
|
|
22
22
|
};
|
|
23
|
-
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
23
|
+
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, dragAndDropEnabled) {
|
|
24
24
|
var list = {};
|
|
25
25
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
|
|
26
26
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
|
|
@@ -52,11 +52,14 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
|
|
|
52
52
|
bindKeymapWithCommand(deleteRow.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
|
|
53
53
|
}
|
|
54
54
|
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
55
|
+
var _ref = getEditorFeatureFlags ? getEditorFeatureFlags() : {},
|
|
56
|
+
_ref$tablePreserveWid = _ref.tablePreserveWidth,
|
|
57
|
+
tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
|
|
55
58
|
bindKeymapWithCommand(startColumnResizing.common, initiateKeyboardColumnResizing, list);
|
|
56
59
|
bindKeymapWithCommand(moveRight.common, activateNextResizeArea(1), list);
|
|
57
60
|
bindKeymapWithCommand(moveLeft.common, activateNextResizeArea(-1), list);
|
|
58
|
-
bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth), list);
|
|
59
|
-
bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth), list);
|
|
61
|
+
bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStep(-10, getEditorContainerWidth, tablePreserveWidth), list);
|
|
62
|
+
bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStep(10, getEditorContainerWidth, tablePreserveWidth), list);
|
|
60
63
|
bindKeymapWithCommand(escape.common, stopKeyboardColumnResizing(), list);
|
|
61
64
|
}
|
|
62
65
|
return keymap(list);
|
|
@@ -88,9 +88,12 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
+
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
92
|
+
_getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
|
|
93
|
+
tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
|
|
91
94
|
if (tr) {
|
|
92
95
|
// "fixTables" removes empty rows as we don't allow that in schema
|
|
93
|
-
var updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
|
|
96
|
+
var updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined, tablePreserveWidth);
|
|
94
97
|
return fixTables(updatedTr) || updatedTr;
|
|
95
98
|
}
|
|
96
99
|
if (transactions.find(function (tr) {
|
|
@@ -19,6 +19,9 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
19
19
|
dispatch = view.dispatch;
|
|
20
20
|
var editorDisabled = !view.editable;
|
|
21
21
|
var domAtPos = view.domAtPos.bind(view);
|
|
22
|
+
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
23
|
+
_getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
|
|
24
|
+
tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
|
|
22
25
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
23
26
|
return false;
|
|
24
27
|
}
|
|
@@ -64,7 +67,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
64
67
|
table: originalTable,
|
|
65
68
|
tableRef: dom,
|
|
66
69
|
start: start,
|
|
67
|
-
domAtPos: domAtPos
|
|
70
|
+
domAtPos: domAtPos,
|
|
71
|
+
tablePreserveWidth: tablePreserveWidth
|
|
68
72
|
});
|
|
69
73
|
if (evenColumns({
|
|
70
74
|
resizeState: resizeState,
|
|
@@ -136,7 +140,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
136
140
|
var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
137
141
|
// only selected (or selected - 1) columns should be distributed
|
|
138
142
|
var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
|
|
139
|
-
var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined);
|
|
143
|
+
var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined, tablePreserveWidth);
|
|
140
144
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
141
145
|
if (colIndex === map.width - 1) {
|
|
142
146
|
var mouseUpTime = event.timeStamp;
|
|
@@ -184,7 +188,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
184
188
|
var table = $cell.node(-1);
|
|
185
189
|
var map = TableMap.get(table);
|
|
186
190
|
var colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
|
|
187
|
-
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom);
|
|
191
|
+
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, undefined, tablePreserveWidth);
|
|
188
192
|
updateControls()(state);
|
|
189
193
|
}
|
|
190
194
|
window.addEventListener('mouseup', finish);
|
|
@@ -4,6 +4,7 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
|
4
4
|
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
|
+
import { MAX_SCALING_PERCENT } from './consts';
|
|
7
8
|
/**
|
|
8
9
|
* This ensures the combined width of the columns (and tbody) of table is always smaller or equal
|
|
9
10
|
* than the table and table wrapper elements. This is necessary as there is no longer
|
|
@@ -13,7 +14,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
13
14
|
export var getColWidthFix = function getColWidthFix(colwidth, tableColumnCount) {
|
|
14
15
|
return colwidth - 1 / tableColumnCount;
|
|
15
16
|
};
|
|
16
|
-
export var generateColgroup = function generateColgroup(table) {
|
|
17
|
+
export var generateColgroup = function generateColgroup(table, tableRef) {
|
|
17
18
|
var cols = [];
|
|
18
19
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
19
20
|
var map = TableMap.get(table);
|
|
@@ -22,11 +23,27 @@ export var generateColgroup = function generateColgroup(table) {
|
|
|
22
23
|
if (Array.isArray(cell.attrs.colwidth)) {
|
|
23
24
|
// We slice here to guard against our colwidth array having more entries
|
|
24
25
|
// Than the we actually span. We'll patch the document at a later point.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (tableRef) {
|
|
27
|
+
var _tableRef$parentEleme;
|
|
28
|
+
var tableWidth = table.attrs && table.attrs.width;
|
|
29
|
+
var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
|
|
30
|
+
var scalePercent = renderWidth / tableWidth;
|
|
31
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
32
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
33
|
+
var fixedColWidth = getColWidthFix(width, map.width);
|
|
34
|
+
var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
|
|
35
|
+
var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
36
|
+
cols.push(['col', {
|
|
37
|
+
style: "width: ".concat(finalWidth, "px;")
|
|
38
|
+
}]);
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
42
|
+
cols.push(['col', {
|
|
43
|
+
style: "width: ".concat(getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width), "px;")
|
|
44
|
+
}]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
30
47
|
} else {
|
|
31
48
|
// When we have merged cells on the first row (firstChild),
|
|
32
49
|
// We want to ensure we're creating the appropriate amount of
|
|
@@ -66,12 +83,16 @@ export var generateColgroup = function generateColgroup(table) {
|
|
|
66
83
|
return cols;
|
|
67
84
|
};
|
|
68
85
|
export var insertColgroupFromNode = function insertColgroupFromNode(tableRef, table) {
|
|
86
|
+
var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
87
|
+
var shouldRemove = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
69
88
|
var colgroup = tableRef.querySelector('colgroup');
|
|
70
|
-
if (colgroup) {
|
|
89
|
+
if (colgroup && shouldRemove) {
|
|
71
90
|
tableRef.removeChild(colgroup);
|
|
72
91
|
}
|
|
73
|
-
colgroup = renderColgroupFromNode(table);
|
|
74
|
-
|
|
92
|
+
colgroup = renderColgroupFromNode(table, tablePreserveWidth ? tableRef : undefined);
|
|
93
|
+
if (shouldRemove) {
|
|
94
|
+
tableRef.insertBefore(colgroup, tableRef.firstChild);
|
|
95
|
+
}
|
|
75
96
|
return colgroup.children;
|
|
76
97
|
};
|
|
77
98
|
export var hasTableBeenResized = function hasTableBeenResized(table) {
|
|
@@ -93,8 +114,8 @@ export var isMinCellWidthTable = function isMinCellWidthTable(table) {
|
|
|
93
114
|
});
|
|
94
115
|
return isTableMinCellWidth;
|
|
95
116
|
};
|
|
96
|
-
function renderColgroupFromNode(table) {
|
|
97
|
-
var rendered = DOMSerializer.renderSpec(document, ['colgroup', {}].concat(_toConsumableArray(generateColgroup(table))));
|
|
117
|
+
function renderColgroupFromNode(table, maybeTableRef) {
|
|
118
|
+
var rendered = DOMSerializer.renderSpec(document, ['colgroup', {}].concat(_toConsumableArray(generateColgroup(table, maybeTableRef))));
|
|
98
119
|
return rendered.dom;
|
|
99
120
|
}
|
|
100
121
|
export var getColgroupChildrenLength = function getColgroupChildrenLength(table) {
|
|
@@ -3,8 +3,8 @@ export { contentWidth } from './content-width';
|
|
|
3
3
|
export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateColumnWidth, addContainerLeftRightPadding } from './column-state';
|
|
4
4
|
export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
|
|
5
5
|
export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths } from './resize-state';
|
|
6
|
-
export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth } from './misc';
|
|
6
|
+
export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElement } from './misc';
|
|
7
7
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
8
8
|
export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
|
|
9
9
|
export { resizeColumn } from './resize-column';
|
|
10
|
-
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH } from './consts';
|
|
10
|
+
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT } from './consts';
|
|
@@ -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) {
|
|
9
11
|
var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -69,4 +71,22 @@ export var getTableMaxWidth = function getTableMaxWidth(_ref2) {
|
|
|
69
71
|
maxWidth -= akEditorTableNumberColumnWidth;
|
|
70
72
|
}
|
|
71
73
|
return maxWidth;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param table
|
|
79
|
+
* @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
|
|
80
|
+
*/
|
|
81
|
+
export var getTableElementWidth = function getTableElementWidth(table) {
|
|
82
|
+
if (hasTableBeenResized(table)) {
|
|
83
|
+
// TODO: is there a scenario where ADF columns are SMALLER than container width?
|
|
84
|
+
return calcTableColumnWidths(table).reduce(function (sum, width) {
|
|
85
|
+
return sum + width;
|
|
86
|
+
}, 0);
|
|
87
|
+
}
|
|
88
|
+
return getTableContainerElement(table);
|
|
89
|
+
};
|
|
90
|
+
export var getTableContainerElement = function getTableContainerElement(table) {
|
|
91
|
+
return getTableContainerWidth(table);
|
|
72
92
|
};
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
3
3
|
import { updateColgroup } from './resize-state';
|
|
4
4
|
export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, selectedColumns) {
|
|
5
|
+
var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
5
6
|
var newState = amount > 0 ? growColumn(resizeState, colIndex, amount, selectedColumns) : amount < 0 ? shrinkColumn(resizeState, colIndex, amount, selectedColumns) : resizeState;
|
|
6
|
-
updateColgroup(newState, tableRef);
|
|
7
|
+
updateColgroup(newState, tableRef, tablePreserveWidth);
|
|
7
8
|
return newState;
|
|
8
9
|
};
|
|
@@ -9,13 +9,17 @@ import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './c
|
|
|
9
9
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
10
10
|
import { syncStickyRowToTable } from './dom';
|
|
11
11
|
import { getTableMaxWidth } from './misc';
|
|
12
|
+
import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
12
13
|
export var getResizeState = function getResizeState(_ref) {
|
|
13
14
|
var minWidth = _ref.minWidth,
|
|
14
15
|
maxSize = _ref.maxSize,
|
|
15
16
|
table = _ref.table,
|
|
16
17
|
tableRef = _ref.tableRef,
|
|
17
18
|
start = _ref.start,
|
|
18
|
-
domAtPos = _ref.domAtPos
|
|
19
|
+
domAtPos = _ref.domAtPos,
|
|
20
|
+
_ref$tablePreserveWid = _ref.tablePreserveWidth,
|
|
21
|
+
tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
|
|
22
|
+
// If the table has been resized, we can use the column widths from the table node
|
|
19
23
|
if (hasTableBeenResized(table)) {
|
|
20
24
|
var _cols = calcTableColumnWidths(table).map(function (width, index) {
|
|
21
25
|
return {
|
|
@@ -39,10 +43,22 @@ export var getResizeState = function getResizeState(_ref) {
|
|
|
39
43
|
overflow: _overflow
|
|
40
44
|
};
|
|
41
45
|
}
|
|
46
|
+
var shouldReinsertColgroup = !tablePreserveWidth;
|
|
42
47
|
|
|
43
48
|
// Getting the resize state from DOM
|
|
44
|
-
var colgroupChildren = insertColgroupFromNode(tableRef, table
|
|
49
|
+
var colgroupChildren = insertColgroupFromNode(tableRef, table, tablePreserveWidth, shouldReinsertColgroup // don't reinsert colgroup when preserving table width - this causes widths to jump
|
|
50
|
+
);
|
|
51
|
+
|
|
45
52
|
var cols = Array.from(colgroupChildren).map(function (_, index) {
|
|
53
|
+
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
54
|
+
// to calculate the widths of the columns
|
|
55
|
+
if (tablePreserveWidth && table.attrs.width) {
|
|
56
|
+
return {
|
|
57
|
+
index: index,
|
|
58
|
+
width: table.attrs.width / colgroupChildren.length,
|
|
59
|
+
minWidth: 48
|
|
60
|
+
};
|
|
61
|
+
}
|
|
46
62
|
var cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
47
63
|
return getColumnStateFromDOM(cellsRefs, index, minWidth);
|
|
48
64
|
});
|
|
@@ -63,18 +79,41 @@ export var getResizeState = function getResizeState(_ref) {
|
|
|
63
79
|
};
|
|
64
80
|
|
|
65
81
|
// updates Colgroup DOM node with new widths
|
|
66
|
-
export var updateColgroup = function updateColgroup(state, tableRef) {
|
|
82
|
+
export var updateColgroup = function updateColgroup(state, tableRef, tablePreserveWidth) {
|
|
67
83
|
var cols = tableRef.querySelectorAll('col');
|
|
68
84
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
69
85
|
var columnsCount = cols.length;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
if (tablePreserveWidth) {
|
|
87
|
+
var _tableRef$dataset;
|
|
88
|
+
var 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
|
|
89
|
+
if (tableWidth) {
|
|
90
|
+
var _tableRef$parentEleme;
|
|
91
|
+
var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || TABLE_DEFAULT_WIDTH;
|
|
92
|
+
var scalePercent = renderWidth / tableWidth;
|
|
93
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
94
|
+
state.cols.filter(function (column) {
|
|
95
|
+
return column && !!column.width;
|
|
96
|
+
}) // if width is 0, we dont want to apply that.
|
|
97
|
+
.forEach(function (column, i) {
|
|
98
|
+
var fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
99
|
+
var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
|
|
100
|
+
var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
101
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
102
|
+
if (cols[i]) {
|
|
103
|
+
cols[i].style.width = "".concat(finalWidth, "px");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
76
106
|
}
|
|
77
|
-
}
|
|
107
|
+
} else {
|
|
108
|
+
state.cols.filter(function (column) {
|
|
109
|
+
return column && !!column.width;
|
|
110
|
+
}) // if width is 0, we dont want to apply that.
|
|
111
|
+
.forEach(function (column, i) {
|
|
112
|
+
if (cols[i]) {
|
|
113
|
+
cols[i].style.width = "".concat(getColWidthFix(column.width, columnsCount), "px");
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
78
117
|
} else {
|
|
79
118
|
state.cols.filter(function (column) {
|
|
80
119
|
return column && !!column.width;
|
|
@@ -262,6 +301,7 @@ export var normaliseTableLayout = function normaliseTableLayout(input) {
|
|
|
262
301
|
}
|
|
263
302
|
};
|
|
264
303
|
export var getNewResizeStateFromSelectedColumns = function getNewResizeStateFromSelectedColumns(rect, state, domAtPos, getEditorContainerWidth) {
|
|
304
|
+
var tablePreserveWidth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
265
305
|
// Fail early so that we don't do complex calculations for no reason
|
|
266
306
|
var numColumnsSelected = rect.right - rect.left;
|
|
267
307
|
if (numColumnsSelected <= 1) {
|
|
@@ -298,7 +338,8 @@ export var getNewResizeStateFromSelectedColumns = function getNewResizeStateFrom
|
|
|
298
338
|
table: table.node,
|
|
299
339
|
tableRef: tableRef,
|
|
300
340
|
start: table.start,
|
|
301
|
-
domAtPos: domAtPos
|
|
341
|
+
domAtPos: domAtPos,
|
|
342
|
+
tablePreserveWidth: tablePreserveWidth
|
|
302
343
|
});
|
|
303
344
|
var newResizeState = evenSelectedColumnsWidths(resizeState, rect);
|
|
304
345
|
var widthsBefore = resizeState.widths;
|
|
@@ -14,6 +14,7 @@ import { syncStickyRowToTable } from './dom';
|
|
|
14
14
|
// Base function to trigger the actual scale on a table node.
|
|
15
15
|
// Will only resize/scale if a table has been previously resized.
|
|
16
16
|
export var scale = function scale(tableRef, options, domAtPos) {
|
|
17
|
+
var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
17
18
|
/**
|
|
18
19
|
* isBreakoutEnabled === true -> default center aligned
|
|
19
20
|
* isBreakoutEnabled === false -> full width mode
|
|
@@ -58,18 +59,21 @@ export var scale = function scale(tableRef, options, domAtPos) {
|
|
|
58
59
|
table: node,
|
|
59
60
|
tableRef: tableRef,
|
|
60
61
|
start: start,
|
|
61
|
-
domAtPos: domAtPos
|
|
62
|
+
domAtPos: domAtPos,
|
|
63
|
+
tablePreserveWidth: tablePreserveWidth
|
|
62
64
|
});
|
|
63
65
|
return scaleTableTo(resizeState, newWidth);
|
|
64
66
|
};
|
|
65
67
|
export var scaleWithParent = function scaleWithParent(tableRef, parentWidth, table, start, domAtPos) {
|
|
68
|
+
var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
66
69
|
var resizeState = getResizeState({
|
|
67
70
|
minWidth: tableCellMinWidth,
|
|
68
71
|
maxSize: parentWidth,
|
|
69
72
|
table: table,
|
|
70
73
|
tableRef: tableRef,
|
|
71
74
|
start: start,
|
|
72
|
-
domAtPos: domAtPos
|
|
75
|
+
domAtPos: domAtPos,
|
|
76
|
+
tablePreserveWidth: tablePreserveWidth
|
|
73
77
|
});
|
|
74
78
|
if (table.attrs.isNumberColumnEnabled) {
|
|
75
79
|
parentWidth -= akEditorTableNumberColumnWidth;
|
|
@@ -101,6 +105,7 @@ export function scaleTableTo(state, maxSize) {
|
|
|
101
105
|
return adjustColumnsWidths(newState, maxSize);
|
|
102
106
|
}
|
|
103
107
|
export var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos) {
|
|
108
|
+
var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
104
109
|
var node = options.node,
|
|
105
110
|
start = options.start,
|
|
106
111
|
parentWidth = options.parentWidth;
|
|
@@ -112,18 +117,22 @@ export var previewScaleTable = function previewScaleTable(tableRef, options, dom
|
|
|
112
117
|
var width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
|
|
113
118
|
tableRef.style.width = "".concat(width, "px");
|
|
114
119
|
}
|
|
115
|
-
|
|
120
|
+
|
|
121
|
+
// If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
|
|
122
|
+
// If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
|
|
123
|
+
if (!hasTableBeenResized(node) && !tablePreserveWidth) {
|
|
116
124
|
syncStickyRowToTable(tableRef);
|
|
117
125
|
return;
|
|
118
126
|
}
|
|
119
|
-
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
|
|
127
|
+
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth) : scale(tableRef, options, domAtPos, tablePreserveWidth);
|
|
120
128
|
if (resizeState) {
|
|
121
|
-
updateColgroup(resizeState, tableRef);
|
|
129
|
+
updateColgroup(resizeState, tableRef, tablePreserveWidth);
|
|
122
130
|
}
|
|
123
131
|
};
|
|
124
132
|
|
|
125
133
|
// Scale the table to meet new requirements (col, layout change etc)
|
|
126
134
|
export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
135
|
+
var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
127
136
|
return function (tr) {
|
|
128
137
|
if (!tableRef) {
|
|
129
138
|
return tr;
|
|
@@ -136,15 +145,17 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
|
136
145
|
if (hasTableBeenResized(node) === false) {
|
|
137
146
|
// If its not a re-sized table, we still want to re-create cols
|
|
138
147
|
// To force reflow of columns upon delete.
|
|
139
|
-
|
|
148
|
+
if (!tablePreserveWidth) {
|
|
149
|
+
insertColgroupFromNode(tableRef, node);
|
|
150
|
+
}
|
|
140
151
|
tr.setMeta('scrollIntoView', false);
|
|
141
152
|
return tr;
|
|
142
153
|
}
|
|
143
154
|
var resizeState;
|
|
144
155
|
if (parentWidth) {
|
|
145
|
-
resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos);
|
|
156
|
+
resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, tablePreserveWidth);
|
|
146
157
|
} else {
|
|
147
|
-
resizeState = scale(tableRef, options, domAtPos);
|
|
158
|
+
resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
|
|
148
159
|
}
|
|
149
160
|
if (resizeState) {
|
|
150
161
|
tr = updateColumnWidths(resizeState, node, start)(tr);
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -85,6 +85,7 @@ export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _
|
|
|
85
85
|
export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(editorState, editorView, initialSelectionRect, _ref2, getEditorContainerWidth, editorAnalyticsAPI) {
|
|
86
86
|
var _pluginState$pluginCo, _pluginState$pluginCo2;
|
|
87
87
|
var formatMessage = _ref2.formatMessage;
|
|
88
|
+
var tablePreserveWidth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
88
89
|
var top = initialSelectionRect.top,
|
|
89
90
|
bottom = initialSelectionRect.bottom,
|
|
90
91
|
right = initialSelectionRect.right,
|
|
@@ -99,7 +100,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
|
|
|
99
100
|
var selectionRect = getClosestSelectionRect(state);
|
|
100
101
|
var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right;
|
|
101
102
|
if (index) {
|
|
102
|
-
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
|
|
103
|
+
insertColumnWithAnalytics(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
|
|
103
104
|
}
|
|
104
105
|
return true;
|
|
105
106
|
},
|
|
@@ -178,7 +179,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
|
|
|
178
179
|
}];
|
|
179
180
|
if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
|
|
180
181
|
var _newResizeStateWithAn;
|
|
181
|
-
var newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth) : undefined;
|
|
182
|
+
var newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth) : undefined;
|
|
182
183
|
var wouldChange = (_newResizeStateWithAn = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn !== void 0 ? _newResizeStateWithAn : false;
|
|
183
184
|
var distributeColumnWidths = function distributeColumnWidths(state, dispatch) {
|
|
184
185
|
if (newResizeStateWithAnalytics) {
|
|
@@ -298,10 +299,13 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
298
299
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
299
300
|
var nodeType = state.schema.nodes.table;
|
|
300
301
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
302
|
+
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
303
|
+
_getEditorFeatureFlag2 = _getEditorFeatureFlag.tablePreserveWidth,
|
|
304
|
+
tablePreserveWidth = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
|
|
301
305
|
var cellItems;
|
|
302
|
-
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
|
|
306
|
+
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
|
|
303
307
|
var columnSettingsItems;
|
|
304
|
-
columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
|
|
308
|
+
columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth) : [];
|
|
305
309
|
var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
|
|
306
310
|
|
|
307
311
|
// Check if we need to show confirm dialog for delete button
|
|
@@ -340,8 +344,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
340
344
|
}
|
|
341
345
|
return element;
|
|
342
346
|
};
|
|
343
|
-
var
|
|
344
|
-
stickyScrollbar =
|
|
347
|
+
var _getEditorFeatureFlag3 = getEditorFeatureFlags(),
|
|
348
|
+
stickyScrollbar = _getEditorFeatureFlag3.stickyScrollbar;
|
|
345
349
|
return {
|
|
346
350
|
title: 'Table floating controls',
|
|
347
351
|
getDomRef: getDomRef,
|
|
@@ -400,22 +404,24 @@ var separator = function separator(hidden) {
|
|
|
400
404
|
};
|
|
401
405
|
var getCellItems = function getCellItems(pluginConfig, state, view, _ref3, getEditorContainerWidth, editorAnalyticsAPI) {
|
|
402
406
|
var formatMessage = _ref3.formatMessage;
|
|
407
|
+
var tablePreserveWidth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
403
408
|
var initialSelectionRect = getClosestSelectionRect(state);
|
|
404
409
|
if (initialSelectionRect) {
|
|
405
410
|
var cellOptions = getToolbarCellOptionsConfig(state, view, initialSelectionRect, {
|
|
406
411
|
formatMessage: formatMessage
|
|
407
|
-
}, getEditorContainerWidth, editorAnalyticsAPI);
|
|
412
|
+
}, getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth);
|
|
408
413
|
return [cellOptions, separator(cellOptions.hidden)];
|
|
409
414
|
}
|
|
410
415
|
return [];
|
|
411
416
|
};
|
|
412
417
|
export var getDistributeConfig = function getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI) {
|
|
418
|
+
var tablePreserveWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
413
419
|
return function (state, dispatch, editorView) {
|
|
414
420
|
var selectionOrTableRect = getClosestSelectionOrTableRect(state);
|
|
415
421
|
if (!editorView || !selectionOrTableRect) {
|
|
416
422
|
return false;
|
|
417
423
|
}
|
|
418
|
-
var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
|
|
424
|
+
var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
419
425
|
if (newResizeStateWithAnalytics) {
|
|
420
426
|
distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
|
|
421
427
|
return true;
|
|
@@ -429,12 +435,13 @@ export var getDistributeConfig = function getDistributeConfig(getEditorContainer
|
|
|
429
435
|
var getColumnSettingItems = function getColumnSettingItems(editorState, editorView, _ref4, getEditorContainerWidth, editorAnalyticsAPI) {
|
|
430
436
|
var _newResizeStateWithAn2, _pluginState$pluginCo3;
|
|
431
437
|
var formatMessage = _ref4.formatMessage;
|
|
438
|
+
var tablePreserveWidth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
432
439
|
var pluginState = getPluginState(editorState);
|
|
433
440
|
var selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
|
|
434
441
|
if (!selectionOrTableRect || !editorView) {
|
|
435
442
|
return [];
|
|
436
443
|
}
|
|
437
|
-
var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
|
|
444
|
+
var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, tablePreserveWidth);
|
|
438
445
|
var wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
|
|
439
446
|
if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
|
|
440
447
|
return [{
|
|
@@ -443,7 +450,7 @@ var getColumnSettingItems = function getColumnSettingItems(editorState, editorVi
|
|
|
443
450
|
title: formatMessage(messages.distributeColumns),
|
|
444
451
|
icon: DistributeColumnIcon,
|
|
445
452
|
onClick: function onClick(state, dispatch, view) {
|
|
446
|
-
return getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view);
|
|
453
|
+
return getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, tablePreserveWidth)(state, dispatch, view);
|
|
447
454
|
},
|
|
448
455
|
disabled: !wouldChange
|
|
449
456
|
}, {
|
|
@@ -5,7 +5,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
|
5
5
|
import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
|
|
6
6
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
7
7
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
|
-
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
8
|
+
import { getTableContainerElement, getTableElementWidth, hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
9
9
|
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
10
10
|
import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
|
|
11
11
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
@@ -88,9 +88,9 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
|
|
|
88
88
|
* @returns Updated transaction with rescaled columns for a given table
|
|
89
89
|
*/
|
|
90
90
|
export var rescaleColumns = function rescaleColumns() {
|
|
91
|
+
var tablePreserveWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
91
92
|
return function (table, view) {
|
|
92
93
|
return function (tr) {
|
|
93
|
-
var _tableRef$parentEleme, _tableRef$parentEleme2;
|
|
94
94
|
if (!view) {
|
|
95
95
|
return tr;
|
|
96
96
|
}
|
|
@@ -102,14 +102,28 @@ export var rescaleColumns = function rescaleColumns() {
|
|
|
102
102
|
return tr;
|
|
103
103
|
}
|
|
104
104
|
var isResized = hasTableBeenResized(table.node);
|
|
105
|
-
// get current table info
|
|
106
105
|
var previousTableInfo = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/** the is the width the table can reach before overflowing */
|
|
110
|
-
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 || (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
|
|
106
|
+
width: 0,
|
|
107
|
+
possibleMaxWidth: 0,
|
|
111
108
|
isResized: isResized
|
|
112
109
|
};
|
|
110
|
+
if (tablePreserveWidth) {
|
|
111
|
+
previousTableInfo = {
|
|
112
|
+
// TODO - ensure correct width is returned when table doesn't have a width value
|
|
113
|
+
width: getTableElementWidth(table.node),
|
|
114
|
+
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? getTableContainerElement(table.node) : getTableContainerElement(table.node) - insertColumnButtonOffset,
|
|
115
|
+
isResized: isResized
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
var _tableRef$parentEleme, _tableRef$parentEleme2;
|
|
119
|
+
previousTableInfo = {
|
|
120
|
+
// when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
|
|
121
|
+
width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
|
|
122
|
+
/** the is the width the table can reach before overflowing */
|
|
123
|
+
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 || (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - insertColumnButtonOffset,
|
|
124
|
+
isResized: isResized
|
|
125
|
+
};
|
|
126
|
+
}
|
|
113
127
|
|
|
114
128
|
// determine the new table, based on new width
|
|
115
129
|
var newTableInfo = {
|
|
@@ -154,7 +168,8 @@ export var rescaleColumns = function rescaleColumns() {
|
|
|
154
168
|
start: table.start,
|
|
155
169
|
tableRef: tableRef,
|
|
156
170
|
domAtPos: domAtPos,
|
|
157
|
-
maxSize: previousTableInfo.possibleMaxWidth
|
|
171
|
+
maxSize: previousTableInfo.possibleMaxWidth,
|
|
172
|
+
tablePreserveWidth: tablePreserveWidth
|
|
158
173
|
});
|
|
159
174
|
|
|
160
175
|
// Two scenarios that require scaling:
|
|
@@ -205,6 +205,7 @@ function fixRowSpans(table) {
|
|
|
205
205
|
return table.type.createChecked(table.attrs, rows, table.marks);
|
|
206
206
|
}
|
|
207
207
|
export var deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
|
|
208
|
+
var tablePreserveWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
208
209
|
return function (tr) {
|
|
209
210
|
var updatedTr = tr;
|
|
210
211
|
updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
@@ -217,7 +218,7 @@ export var deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
|
|
|
217
218
|
}
|
|
218
219
|
var table = findTable(updatedTr.selection);
|
|
219
220
|
if (table) {
|
|
220
|
-
updatedTr = rescaleColumns()(table, view)(updatedTr);
|
|
221
|
+
updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
|
|
221
222
|
}
|
|
222
223
|
return updatedTr;
|
|
223
224
|
};
|