@atlaskit/editor-plugin-table 7.21.4 → 7.21.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/pm-plugins/keymap.js +4 -6
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +40 -12
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +99 -51
- package/dist/cjs/utils/alignment.js +1 -1
- package/dist/es2019/pm-plugins/keymap.js +4 -6
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +41 -13
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +97 -48
- package/dist/es2019/utils/alignment.js +1 -1
- package/dist/esm/pm-plugins/keymap.js +4 -6
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +40 -12
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +99 -51
- package/dist/esm/utils/alignment.js +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +23 -1
- package/dist/types/utils/alignment.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +23 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +1 -1
- package/package.json +2 -5
- package/src/pm-plugins/keymap.ts +30 -32
- package/src/pm-plugins/table-resizing/event-handlers.ts +37 -25
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +142 -70
- package/src/utils/alignment.ts +8 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
|
|
3
|
+
import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
|
|
3
4
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
4
5
|
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
5
|
-
import {
|
|
6
|
+
import { getTableScalingPercent } from './misc';
|
|
6
7
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
7
8
|
import { updateColgroup } from './resize-state';
|
|
8
9
|
export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false, shouldUseIncreasedScalingPercent = false) => {
|
|
@@ -16,64 +17,112 @@ export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode,
|
|
|
16
17
|
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled, shouldUseIncreasedScalingPercent);
|
|
17
18
|
return newState;
|
|
18
19
|
};
|
|
20
|
+
export const resizeColumnAndTable = ({
|
|
21
|
+
resizeState,
|
|
22
|
+
colIndex,
|
|
23
|
+
amount,
|
|
24
|
+
tableRef,
|
|
25
|
+
tableNode,
|
|
26
|
+
lineLength,
|
|
27
|
+
width: editorWidth,
|
|
28
|
+
isTableAlignmentEnabled
|
|
29
|
+
}) => {
|
|
30
|
+
const editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
31
|
+
const isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
|
|
32
|
+
let resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
33
|
+
const willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
34
|
+
const willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
19
35
|
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
26
|
-
const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
27
|
-
let resizeAmount = tableNode.attrs.layout === ALIGN_START && !isOverflowed ? amount : amount * 2;
|
|
28
|
-
|
|
29
|
-
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
30
|
-
// let scalePercent = 1;
|
|
31
|
-
// if (isTableScalingEnabled) {
|
|
32
|
-
// import from ./misc
|
|
33
|
-
// scalePercent = getStaticTableScalingPercent(
|
|
34
|
-
// tableNode,
|
|
35
|
-
// originalTableWidth || resizeState.maxSize,
|
|
36
|
-
// );
|
|
37
|
-
// resizeAmount = amount / scalePercent;
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// need to look at the resize amount and try to adjust the colgroups
|
|
41
|
-
if (isOverflowed) {
|
|
42
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
36
|
+
// STEP 1: Update col width
|
|
37
|
+
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
38
|
+
var _tableRef$closest;
|
|
39
|
+
const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
40
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
43
|
+
const diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
44
|
+
const rest = amount - diff;
|
|
45
|
+
const final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
46
|
+
resizeAmount = final;
|
|
47
|
+
}
|
|
48
|
+
let newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
49
49
|
|
|
50
|
-
//
|
|
50
|
+
// STEP 2: Update table container width
|
|
51
|
+
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
51
52
|
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
|
|
54
|
+
// CASE 1A: table will stay in overflow
|
|
55
|
+
// do not grow the table because resize is happening in the overflow region
|
|
56
|
+
// and the overall table container needs to be retained
|
|
57
|
+
resizeState.maxSize :
|
|
58
|
+
// CASE 1B: table will no longer be in overflow, so adjust container width
|
|
59
|
+
// ensure the table is resized without any 'big jumps' by working out
|
|
60
|
+
// the difference between the new table width and the max size and adding the resize
|
|
61
|
+
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
62
|
+
// CASE 2: table will hit editor edge
|
|
63
|
+
editorContainerWidth :
|
|
64
|
+
// CASE 3: table is being resized from a non-overflow state
|
|
65
|
+
resizeState.maxSize + delta);
|
|
66
|
+
|
|
67
|
+
// do not apply scaling logic because resize state is already scaled
|
|
68
|
+
updateColgroup(newState, tableRef, tableNode, false, false);
|
|
69
|
+
if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
|
|
70
|
+
updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
56
71
|
}
|
|
57
|
-
return
|
|
58
|
-
...newState,
|
|
59
|
-
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
60
|
-
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
61
|
-
};
|
|
72
|
+
return newState;
|
|
62
73
|
};
|
|
63
|
-
const updateTablePreview = (
|
|
64
|
-
const
|
|
65
|
-
const resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
74
|
+
const updateTablePreview = (tableRef, newTableWidth, shouldChangeAlignment) => {
|
|
75
|
+
const resizingContainer = tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
66
76
|
const resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
67
77
|
const alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
68
78
|
if (resizingItem) {
|
|
69
|
-
const newWidth = `${
|
|
70
|
-
if (tableRef) {
|
|
71
|
-
tableRef.style.width = newWidth;
|
|
72
|
-
}
|
|
79
|
+
const newWidth = `${newTableWidth}px`;
|
|
73
80
|
resizingContainer.style.width = newWidth;
|
|
74
81
|
resizingItem.style.width = newWidth;
|
|
75
|
-
if (
|
|
76
|
-
alignmentContainer.style.justifyContent =
|
|
82
|
+
if (shouldChangeAlignment && alignmentContainer) {
|
|
83
|
+
alignmentContainer.style.justifyContent = ALIGN_CENTER;
|
|
77
84
|
}
|
|
78
85
|
}
|
|
86
|
+
};
|
|
87
|
+
const getEditorContainerWidth = editorWidth => Math.min(editorWidth - akEditorGutterPaddingDynamic() * 2, akEditorFullWidthLayoutWidth);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Apply a scaling factor to resize state
|
|
91
|
+
*/
|
|
92
|
+
export const scaleResizeState = ({
|
|
93
|
+
resizeState,
|
|
94
|
+
tableRef,
|
|
95
|
+
tableNode,
|
|
96
|
+
editorWidth
|
|
97
|
+
}) => {
|
|
98
|
+
// check if table is scaled, if not then avoid applying scaling values down
|
|
99
|
+
if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
|
|
100
|
+
return resizeState;
|
|
101
|
+
}
|
|
102
|
+
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
103
|
+
let cols = resizeState.cols.map(col => ({
|
|
104
|
+
...col,
|
|
105
|
+
width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
|
|
106
|
+
}));
|
|
107
|
+
const scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
108
|
+
const calculatedTableWidth = cols.reduce((prev, curr) => prev + curr.width, 0);
|
|
109
|
+
|
|
110
|
+
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
111
|
+
// distribute the difference to the smallest column
|
|
112
|
+
if (calculatedTableWidth > scaledTableWidth) {
|
|
113
|
+
const diff = calculatedTableWidth - scaledTableWidth;
|
|
114
|
+
cols = cols.map(col => {
|
|
115
|
+
return col.width - diff >= col.minWidth ? {
|
|
116
|
+
...col,
|
|
117
|
+
width: col.width - diff
|
|
118
|
+
} : col;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
...resizeState,
|
|
123
|
+
widths: cols.map(col => col.width),
|
|
124
|
+
tableWidth: scaledTableWidth,
|
|
125
|
+
maxSize: Math.round(resizeState.maxSize * scalePercent),
|
|
126
|
+
cols
|
|
127
|
+
};
|
|
79
128
|
};
|
|
@@ -11,4 +11,4 @@ export const normaliseAlignment = layout => layout === ALIGN_CENTER || layout ==
|
|
|
11
11
|
/**
|
|
12
12
|
* We don't want to switch alignment in Full-width editor
|
|
13
13
|
*/
|
|
14
|
-
export const shouldChangeAlignmentToCenterResized = (isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) => isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
14
|
+
export const shouldChangeAlignmentToCenterResized = (isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) => Boolean(isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH);
|
|
@@ -33,12 +33,10 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
|
|
|
33
33
|
bindKeymapWithCommand(addRowAfter.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
34
34
|
bindKeymapWithCommand(addColumnBefore.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
35
35
|
bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
41
|
-
}
|
|
36
|
+
bindKeymapWithCommand(addRowBeforeVO.common, addRowAroundSelection(editorAnalyticsAPI)('TOP'), list);
|
|
37
|
+
bindKeymapWithCommand(addRowAfterVO.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
38
|
+
bindKeymapWithCommand(addColumnBeforeVO.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
39
|
+
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
42
40
|
if (dragAndDropEnabled) {
|
|
43
41
|
// Move row/column shortcuts
|
|
44
42
|
/**
|
|
@@ -16,13 +16,15 @@ import { META_KEYS } from '../table-analytics';
|
|
|
16
16
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
17
17
|
import { getPluginState } from './plugin-factory';
|
|
18
18
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
19
|
+
import { scaleResizeState } from './utils/resize-column';
|
|
19
20
|
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
20
21
|
var state = view.state,
|
|
21
22
|
dispatch = view.dispatch;
|
|
22
23
|
var editorDisabled = !view.editable;
|
|
23
24
|
var domAtPos = view.domAtPos.bind(view);
|
|
24
25
|
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
25
|
-
lineLength = _getEditorContainerWi.lineLength
|
|
26
|
+
lineLength = _getEditorContainerWi.lineLength,
|
|
27
|
+
editorWidth = _getEditorContainerWi.width;
|
|
26
28
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
27
29
|
return false;
|
|
28
30
|
}
|
|
@@ -88,6 +90,17 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
88
90
|
// When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
|
|
89
91
|
// unnecessary tooltips being displayed during drag.
|
|
90
92
|
updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
|
|
93
|
+
|
|
94
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
95
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
96
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
97
|
+
resizeState = scaleResizeState({
|
|
98
|
+
resizeState: resizeState,
|
|
99
|
+
tableRef: dom,
|
|
100
|
+
tableNode: originalTable,
|
|
101
|
+
editorWidth: editorWidth
|
|
102
|
+
});
|
|
103
|
+
}
|
|
91
104
|
function finish(event) {
|
|
92
105
|
window.removeEventListener('mouseup', finish);
|
|
93
106
|
window.removeEventListener('mousemove', move);
|
|
@@ -147,18 +160,23 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
147
160
|
var resizedDelta = clientX - startX;
|
|
148
161
|
var shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled && fg('platform.editor.table.use-increased-scaling-percent');
|
|
149
162
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
150
|
-
var newResizeState = resizeColumnAndTable(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
var newResizeState = resizeColumnAndTable({
|
|
164
|
+
resizeState: resizeState,
|
|
165
|
+
colIndex: colIndex,
|
|
166
|
+
amount: resizedDelta,
|
|
167
|
+
tableRef: dom,
|
|
168
|
+
tableNode: originalTable,
|
|
169
|
+
width: editorWidth,
|
|
170
|
+
lineLength: lineLength,
|
|
171
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
172
|
+
});
|
|
155
173
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
156
174
|
|
|
157
175
|
// If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
|
|
158
|
-
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.
|
|
176
|
+
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.maxSize);
|
|
159
177
|
if (shouldChangeAlignment) {
|
|
160
178
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
161
|
-
width: newResizeState.
|
|
179
|
+
width: newResizeState.maxSize,
|
|
162
180
|
layout: ALIGN_CENTER
|
|
163
181
|
}));
|
|
164
182
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
@@ -166,7 +184,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
166
184
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
167
185
|
actionSubjectId: null,
|
|
168
186
|
attributes: {
|
|
169
|
-
tableWidth: newResizeState.
|
|
187
|
+
tableWidth: newResizeState.maxSize,
|
|
170
188
|
newAlignment: ALIGN_CENTER,
|
|
171
189
|
previousAlignment: ALIGN_START,
|
|
172
190
|
totalRowCount: totalRowCount,
|
|
@@ -177,7 +195,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
177
195
|
eventType: EVENT_TYPE.TRACK
|
|
178
196
|
})(tr);
|
|
179
197
|
} else {
|
|
180
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
198
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
181
199
|
}
|
|
182
200
|
} else {
|
|
183
201
|
var _newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
@@ -249,10 +267,20 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
249
267
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
250
268
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
251
269
|
}
|
|
270
|
+
var resizedDelta = clientX - dragging.startX;
|
|
252
271
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
253
|
-
resizeColumnAndTable(
|
|
272
|
+
resizeColumnAndTable({
|
|
273
|
+
resizeState: resizeState,
|
|
274
|
+
colIndex: colIndex,
|
|
275
|
+
amount: resizedDelta,
|
|
276
|
+
tableRef: dom,
|
|
277
|
+
tableNode: originalTable,
|
|
278
|
+
width: editorWidth,
|
|
279
|
+
lineLength: lineLength,
|
|
280
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
281
|
+
});
|
|
254
282
|
} else {
|
|
255
|
-
resizeColumn(resizeState, colIndex,
|
|
283
|
+
resizeColumn(resizeState, colIndex, resizedDelta, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
256
284
|
}
|
|
257
285
|
updateControls()(state);
|
|
258
286
|
}
|
|
@@ -3,9 +3,10 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
// Resize a given column by an amount from the current state
|
|
5
5
|
|
|
6
|
+
import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
|
|
6
7
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
7
8
|
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
8
|
-
import {
|
|
9
|
+
import { getTableScalingPercent } from './misc';
|
|
9
10
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
10
11
|
import { updateColgroup } from './resize-state';
|
|
11
12
|
export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
@@ -21,68 +22,115 @@ export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, t
|
|
|
21
22
|
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled, shouldUseIncreasedScalingPercent);
|
|
22
23
|
return newState;
|
|
23
24
|
};
|
|
25
|
+
export var resizeColumnAndTable = function resizeColumnAndTable(_ref) {
|
|
26
|
+
var resizeState = _ref.resizeState,
|
|
27
|
+
colIndex = _ref.colIndex,
|
|
28
|
+
amount = _ref.amount,
|
|
29
|
+
tableRef = _ref.tableRef,
|
|
30
|
+
tableNode = _ref.tableNode,
|
|
31
|
+
lineLength = _ref.lineLength,
|
|
32
|
+
editorWidth = _ref.width,
|
|
33
|
+
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled;
|
|
34
|
+
var editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
35
|
+
var isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
|
|
36
|
+
var resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
37
|
+
var willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
38
|
+
var willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
24
39
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
37
|
-
var resizeAmount = tableNode.attrs.layout === ALIGN_START && !isOverflowed ? amount : amount * 2;
|
|
38
|
-
|
|
39
|
-
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
40
|
-
// let scalePercent = 1;
|
|
41
|
-
// if (isTableScalingEnabled) {
|
|
42
|
-
// import from ./misc
|
|
43
|
-
// scalePercent = getStaticTableScalingPercent(
|
|
44
|
-
// tableNode,
|
|
45
|
-
// originalTableWidth || resizeState.maxSize,
|
|
46
|
-
// );
|
|
47
|
-
// resizeAmount = amount / scalePercent;
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// need to look at the resize amount and try to adjust the colgroups
|
|
51
|
-
if (isOverflowed) {
|
|
52
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
40
|
+
// STEP 1: Update col width
|
|
41
|
+
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
42
|
+
var _tableRef$closest;
|
|
43
|
+
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
44
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
|
|
45
|
+
}
|
|
46
|
+
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
47
|
+
var diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
48
|
+
var rest = amount - diff;
|
|
49
|
+
var final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
50
|
+
resizeAmount = final;
|
|
53
51
|
}
|
|
54
52
|
var newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
55
53
|
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
updateColgroup(newState, tableRef, tableNode, false, shouldUseIncreasedScalingPercent);
|
|
59
|
-
|
|
60
|
-
// use the difference in width from affected column to update overall table width
|
|
54
|
+
// STEP 2: Update table container width
|
|
55
|
+
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
61
56
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
|
|
58
|
+
// CASE 1A: table will stay in overflow
|
|
59
|
+
// do not grow the table because resize is happening in the overflow region
|
|
60
|
+
// and the overall table container needs to be retained
|
|
61
|
+
resizeState.maxSize :
|
|
62
|
+
// CASE 1B: table will no longer be in overflow, so adjust container width
|
|
63
|
+
// ensure the table is resized without any 'big jumps' by working out
|
|
64
|
+
// the difference between the new table width and the max size and adding the resize
|
|
65
|
+
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
66
|
+
// CASE 2: table will hit editor edge
|
|
67
|
+
editorContainerWidth :
|
|
68
|
+
// CASE 3: table is being resized from a non-overflow state
|
|
69
|
+
resizeState.maxSize + delta);
|
|
70
|
+
|
|
71
|
+
// do not apply scaling logic because resize state is already scaled
|
|
72
|
+
updateColgroup(newState, tableRef, tableNode, false, false);
|
|
73
|
+
if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
|
|
74
|
+
updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
66
75
|
}
|
|
67
|
-
return
|
|
68
|
-
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
69
|
-
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
70
|
-
});
|
|
76
|
+
return newState;
|
|
71
77
|
};
|
|
72
|
-
var updateTablePreview = function updateTablePreview(
|
|
73
|
-
var
|
|
74
|
-
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
|
|
78
|
+
var updateTablePreview = function updateTablePreview(tableRef, newTableWidth, shouldChangeAlignment) {
|
|
79
|
+
var resizingContainer = tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
|
|
75
80
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
76
81
|
var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
77
82
|
if (resizingItem) {
|
|
78
|
-
var newWidth = "".concat(
|
|
79
|
-
if (tableRef) {
|
|
80
|
-
tableRef.style.width = newWidth;
|
|
81
|
-
}
|
|
83
|
+
var newWidth = "".concat(newTableWidth, "px");
|
|
82
84
|
resizingContainer.style.width = newWidth;
|
|
83
85
|
resizingItem.style.width = newWidth;
|
|
84
|
-
if (
|
|
85
|
-
alignmentContainer.style.justifyContent =
|
|
86
|
+
if (shouldChangeAlignment && alignmentContainer) {
|
|
87
|
+
alignmentContainer.style.justifyContent = ALIGN_CENTER;
|
|
86
88
|
}
|
|
87
89
|
}
|
|
90
|
+
};
|
|
91
|
+
var getEditorContainerWidth = function getEditorContainerWidth(editorWidth) {
|
|
92
|
+
return Math.min(editorWidth - akEditorGutterPaddingDynamic() * 2, akEditorFullWidthLayoutWidth);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Apply a scaling factor to resize state
|
|
97
|
+
*/
|
|
98
|
+
export var scaleResizeState = function scaleResizeState(_ref2) {
|
|
99
|
+
var resizeState = _ref2.resizeState,
|
|
100
|
+
tableRef = _ref2.tableRef,
|
|
101
|
+
tableNode = _ref2.tableNode,
|
|
102
|
+
editorWidth = _ref2.editorWidth;
|
|
103
|
+
// check if table is scaled, if not then avoid applying scaling values down
|
|
104
|
+
if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
|
|
105
|
+
return resizeState;
|
|
106
|
+
}
|
|
107
|
+
var scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
108
|
+
var cols = resizeState.cols.map(function (col) {
|
|
109
|
+
return _objectSpread(_objectSpread({}, col), {}, {
|
|
110
|
+
width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
114
|
+
var calculatedTableWidth = cols.reduce(function (prev, curr) {
|
|
115
|
+
return prev + curr.width;
|
|
116
|
+
}, 0);
|
|
117
|
+
|
|
118
|
+
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
119
|
+
// distribute the difference to the smallest column
|
|
120
|
+
if (calculatedTableWidth > scaledTableWidth) {
|
|
121
|
+
var diff = calculatedTableWidth - scaledTableWidth;
|
|
122
|
+
cols = cols.map(function (col) {
|
|
123
|
+
return col.width - diff >= col.minWidth ? _objectSpread(_objectSpread({}, col), {}, {
|
|
124
|
+
width: col.width - diff
|
|
125
|
+
}) : col;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return _objectSpread(_objectSpread({}, resizeState), {}, {
|
|
129
|
+
widths: cols.map(function (col) {
|
|
130
|
+
return col.width;
|
|
131
|
+
}),
|
|
132
|
+
tableWidth: scaledTableWidth,
|
|
133
|
+
maxSize: Math.round(resizeState.maxSize * scalePercent),
|
|
134
|
+
cols: cols
|
|
135
|
+
});
|
|
88
136
|
};
|
|
@@ -14,5 +14,5 @@ export var normaliseAlignment = function normaliseAlignment(layout) {
|
|
|
14
14
|
* We don't want to switch alignment in Full-width editor
|
|
15
15
|
*/
|
|
16
16
|
export var shouldChangeAlignmentToCenterResized = function shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) {
|
|
17
|
-
return isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
17
|
+
return Boolean(isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH);
|
|
18
18
|
};
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
1
2
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { ResizeState } from './types';
|
|
3
4
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
-
|
|
5
|
+
type ResizeInformation = {
|
|
6
|
+
resizeState: ResizeState;
|
|
7
|
+
colIndex: number;
|
|
8
|
+
amount: number;
|
|
9
|
+
};
|
|
10
|
+
type TableReferences = {
|
|
11
|
+
tableRef: HTMLElement;
|
|
12
|
+
tableNode: PmNode;
|
|
13
|
+
};
|
|
14
|
+
type TableResizingPluginOptions = {
|
|
15
|
+
isTableAlignmentEnabled?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type ResizeColumnAndTable = ResizeInformation & TableResizingPluginOptions & TableReferences & EditorContainerWidth;
|
|
18
|
+
export declare const resizeColumnAndTable: ({ resizeState, colIndex, amount, tableRef, tableNode, lineLength, width: editorWidth, isTableAlignmentEnabled, }: ResizeColumnAndTable) => ResizeState;
|
|
19
|
+
/**
|
|
20
|
+
* Apply a scaling factor to resize state
|
|
21
|
+
*/
|
|
22
|
+
export declare const scaleResizeState: ({ resizeState, tableRef, tableNode, editorWidth, }: TableReferences & {
|
|
23
|
+
resizeState: ResizeState;
|
|
24
|
+
editorWidth: number;
|
|
25
|
+
}) => ResizeState;
|
|
26
|
+
export {};
|
|
@@ -11,4 +11,4 @@ export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptio
|
|
|
11
11
|
/**
|
|
12
12
|
* We don't want to switch alignment in Full-width editor
|
|
13
13
|
*/
|
|
14
|
-
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean
|
|
14
|
+
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean;
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
1
2
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { ResizeState } from './types';
|
|
3
4
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
-
|
|
5
|
+
type ResizeInformation = {
|
|
6
|
+
resizeState: ResizeState;
|
|
7
|
+
colIndex: number;
|
|
8
|
+
amount: number;
|
|
9
|
+
};
|
|
10
|
+
type TableReferences = {
|
|
11
|
+
tableRef: HTMLElement;
|
|
12
|
+
tableNode: PmNode;
|
|
13
|
+
};
|
|
14
|
+
type TableResizingPluginOptions = {
|
|
15
|
+
isTableAlignmentEnabled?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type ResizeColumnAndTable = ResizeInformation & TableResizingPluginOptions & TableReferences & EditorContainerWidth;
|
|
18
|
+
export declare const resizeColumnAndTable: ({ resizeState, colIndex, amount, tableRef, tableNode, lineLength, width: editorWidth, isTableAlignmentEnabled, }: ResizeColumnAndTable) => ResizeState;
|
|
19
|
+
/**
|
|
20
|
+
* Apply a scaling factor to resize state
|
|
21
|
+
*/
|
|
22
|
+
export declare const scaleResizeState: ({ resizeState, tableRef, tableNode, editorWidth, }: TableReferences & {
|
|
23
|
+
resizeState: ResizeState;
|
|
24
|
+
editorWidth: number;
|
|
25
|
+
}) => ResizeState;
|
|
26
|
+
export {};
|
|
@@ -11,4 +11,4 @@ export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptio
|
|
|
11
11
|
/**
|
|
12
12
|
* We don't want to switch alignment in Full-width editor
|
|
13
13
|
*/
|
|
14
|
-
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean
|
|
14
|
+
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.21.
|
|
3
|
+
"version": "7.21.5",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@atlaskit/adf-schema": "^39.0.3",
|
|
32
32
|
"@atlaskit/button": "^19.0.0",
|
|
33
33
|
"@atlaskit/custom-steps": "^0.4.0",
|
|
34
|
-
"@atlaskit/editor-common": "^86.
|
|
34
|
+
"@atlaskit/editor-common": "^86.5.0",
|
|
35
35
|
"@atlaskit/editor-palette": "1.6.0",
|
|
36
36
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.4.0",
|
|
@@ -105,9 +105,6 @@
|
|
|
105
105
|
"platform_editor_lazy-node-views": {
|
|
106
106
|
"type": "boolean"
|
|
107
107
|
},
|
|
108
|
-
"platform.editor.a11y-help-dialog-shortcut-keys-position_aghfg": {
|
|
109
|
-
"type": "boolean"
|
|
110
|
-
},
|
|
111
108
|
"platform.editor.transform-slice-for-nested-expand": {
|
|
112
109
|
"type": "boolean"
|
|
113
110
|
},
|