@atlaskit/editor-plugin-table 7.13.1 → 7.13.2
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 +8 -0
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +10 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +8 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +51 -34
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +11 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +7 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +49 -34
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +11 -4
- package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +7 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +50 -33
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -0
- package/package.json +2 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +43 -21
- package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
- package/src/pm-plugins/table-resizing/utils/misc.ts +11 -0
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +85 -65
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.13.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#97570](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/97570)
|
|
8
|
+
[`d53d6981c3ce`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d53d6981c3ce) -
|
|
9
|
+
Clean up resizing logic and stop growing table container when overflowed
|
|
10
|
+
|
|
3
11
|
## 7.13.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -141,11 +141,14 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
141
141
|
if (isTableScalingEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.preserve-widths-with-lock-button')) {
|
|
142
142
|
_shouldScale = _shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
143
143
|
}
|
|
144
|
-
var newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
145
144
|
var resizedDelta = clientX - startX;
|
|
146
|
-
tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
|
|
147
145
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.colum-resizing-improvements')) {
|
|
146
|
+
var newResizeState = (0, _utils3.resizeColumnAndTable)(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
147
|
+
tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
|
|
148
148
|
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
149
|
+
} else {
|
|
150
|
+
var _newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
151
|
+
tr = (0, _transforms.updateColumnWidths)(_newResizeState, table, start)(tr);
|
|
149
152
|
}
|
|
150
153
|
if (colIndex === map.width - 1) {
|
|
151
154
|
var mouseUpTime = event.timeStamp;
|
|
@@ -215,7 +218,11 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
215
218
|
if (isTableScalingEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.preserve-widths-with-lock-button')) {
|
|
216
219
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
217
220
|
}
|
|
218
|
-
(0,
|
|
221
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.colum-resizing-improvements')) {
|
|
222
|
+
(0, _utils3.resizeColumnAndTable)(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
223
|
+
} else {
|
|
224
|
+
(0, _utils3.resizeColumn)(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
225
|
+
}
|
|
219
226
|
(0, _utils3.updateControls)()(state);
|
|
220
227
|
}
|
|
221
228
|
window.addEventListener('mouseup', finish);
|
|
@@ -207,6 +207,12 @@ Object.defineProperty(exports, "resizeColumn", {
|
|
|
207
207
|
return _resizeColumn.resizeColumn;
|
|
208
208
|
}
|
|
209
209
|
});
|
|
210
|
+
Object.defineProperty(exports, "resizeColumnAndTable", {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function get() {
|
|
213
|
+
return _resizeColumn.resizeColumnAndTable;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
210
216
|
Object.defineProperty(exports, "scale", {
|
|
211
217
|
enumerable: true,
|
|
212
218
|
get: function get() {
|
|
@@ -7,7 +7,7 @@ exports.currentColWidth = currentColWidth;
|
|
|
7
7
|
exports.domCellAround = domCellAround;
|
|
8
8
|
exports.getDefaultLayoutMaxWidth = getDefaultLayoutMaxWidth;
|
|
9
9
|
exports.getLayoutSize = getLayoutSize;
|
|
10
|
-
exports.getTableScalingPercent = exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElementWidth = void 0;
|
|
10
|
+
exports.getTableScalingPercent = exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElementWidth = exports.getStaticTableScalingPercent = void 0;
|
|
11
11
|
exports.pointsAtCell = pointsAtCell;
|
|
12
12
|
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
13
13
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
@@ -108,4 +108,11 @@ var getTableScalingPercent = exports.getTableScalingPercent = function getTableS
|
|
|
108
108
|
var scalePercent = (renderWidth - 1) / tableWidth;
|
|
109
109
|
scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
|
|
110
110
|
return Math.min(scalePercent, 1);
|
|
111
|
+
};
|
|
112
|
+
var getStaticTableScalingPercent = exports.getStaticTableScalingPercent = function getStaticTableScalingPercent(table, tableRenderWidth) {
|
|
113
|
+
var tableWidth = getTableContainerElementWidth(table);
|
|
114
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
115
|
+
var scalePercent = (tableRenderWidth - 1) / tableWidth;
|
|
116
|
+
scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
|
|
117
|
+
return Math.min(scalePercent, 1);
|
|
111
118
|
};
|
|
@@ -4,9 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.resizeColumn = void 0;
|
|
7
|
+
exports.resizeColumnAndTable = exports.resizeColumn = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
9
|
var _types = require("../../../types");
|
|
11
10
|
var _misc = require("./misc");
|
|
12
11
|
var _resizeLogic = require("./resize-logic");
|
|
@@ -15,47 +14,65 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
15
14
|
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) { (0, _defineProperty2.default)(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; } // Resize a given column by an amount from the current state
|
|
16
15
|
var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
17
16
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
18
|
-
// If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
|
|
19
17
|
var scalePercent = 1;
|
|
20
|
-
var resizeAmount;
|
|
21
|
-
if (
|
|
22
|
-
var _tableRef$closest;
|
|
23
|
-
// when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
|
|
24
|
-
var tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
|
|
25
|
-
var tableContainerWidth = tableRef === null || tableRef === void 0 || (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
26
|
-
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
27
|
-
resizeAmount = amount * 2;
|
|
28
|
-
if (isOverflowed) {
|
|
29
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
30
|
-
} else {
|
|
31
|
-
resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
resizeAmount = amount;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// This need to be clean up if clean up the FF, we will not need this scale logic because now full table width changed/updated in resizeColumn
|
|
38
|
-
if (isTableScalingEnabled && !(0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.colum-resizing-improvements')) {
|
|
18
|
+
var resizeAmount = amount;
|
|
19
|
+
if (isTableScalingEnabled) {
|
|
39
20
|
scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
|
|
40
21
|
resizeAmount = amount / scalePercent;
|
|
41
22
|
}
|
|
42
|
-
var newState =
|
|
43
|
-
(0,
|
|
44
|
-
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.colum-resizing-improvements')) {
|
|
45
|
-
// use the difference in width from affected column to update overall table width
|
|
46
|
-
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
47
|
-
updateTable(delta, tableRef, tableNode);
|
|
48
|
-
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
49
|
-
tableWidth: resizeState.tableWidth + delta
|
|
50
|
-
});
|
|
51
|
-
}
|
|
23
|
+
var newState = resizeAmount > 0 ? (0, _resizeLogic.growColumn)(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? (0, _resizeLogic.shrinkColumn)(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
|
|
24
|
+
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
52
25
|
return newState;
|
|
53
26
|
};
|
|
54
|
-
|
|
27
|
+
|
|
28
|
+
// try not scale table during resize
|
|
29
|
+
var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnAndTable(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
30
|
+
var _tableRef$closest;
|
|
31
|
+
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
32
|
+
var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
|
|
33
|
+
// TODO: can we use document state, and apply scaling factor?
|
|
34
|
+
var tableWidth = tableRef.clientWidth;
|
|
35
|
+
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
36
|
+
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
37
|
+
var resizeAmount = 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;
|
|
53
|
+
} else {
|
|
54
|
+
resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
|
|
55
|
+
}
|
|
56
|
+
var newState = (0, _resizeLogic.updateAffectedColumn)(resizeState, colIndex, resizeAmount);
|
|
57
|
+
|
|
58
|
+
// this function only updates the colgroup in DOM, it reverses the scalePercent
|
|
59
|
+
// todo: change isScalingEnabled to true when reimplementing scaling
|
|
60
|
+
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, false);
|
|
61
|
+
|
|
62
|
+
// use the difference in width from affected column to update overall table width
|
|
63
|
+
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
64
|
+
if (!isOverflowed) {
|
|
65
|
+
updateTablePreview(delta, tableRef, tableNode);
|
|
66
|
+
}
|
|
67
|
+
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
68
|
+
tableWidth: isOverflowed ? tableContainerWidth : resizeState.tableWidth + delta
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode) {
|
|
55
72
|
var currentWidth = (0, _misc.getTableContainerElementWidth)(tableNode);
|
|
56
73
|
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
|
|
57
74
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
58
|
-
if (
|
|
75
|
+
if (resizingItem) {
|
|
59
76
|
var newWidth = "".concat(currentWidth + resizeAmount, "px");
|
|
60
77
|
if (tableRef) {
|
|
61
78
|
tableRef.style.width = newWidth;
|
|
@@ -11,7 +11,7 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
|
11
11
|
import { META_KEYS } from '../table-analytics';
|
|
12
12
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
13
13
|
import { getPluginState } from './plugin-factory';
|
|
14
|
-
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, updateControls } from './utils';
|
|
14
|
+
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
15
15
|
export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI) => {
|
|
16
16
|
const {
|
|
17
17
|
state,
|
|
@@ -148,11 +148,14 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
148
148
|
if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
|
|
149
149
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
150
150
|
}
|
|
151
|
-
const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
|
|
152
151
|
const resizedDelta = clientX - startX;
|
|
153
|
-
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
154
152
|
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
153
|
+
const newResizeState = resizeColumnAndTable(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
|
|
154
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
155
155
|
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
156
|
+
} else {
|
|
157
|
+
const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
|
|
158
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
156
159
|
}
|
|
157
160
|
if (colIndex === map.width - 1) {
|
|
158
161
|
const mouseUpTime = event.timeStamp;
|
|
@@ -228,7 +231,11 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
228
231
|
if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
|
|
229
232
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
230
233
|
}
|
|
231
|
-
|
|
234
|
+
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
235
|
+
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
236
|
+
} else {
|
|
237
|
+
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
238
|
+
}
|
|
232
239
|
updateControls()(state);
|
|
233
240
|
}
|
|
234
241
|
window.addEventListener('mouseup', finish);
|
|
@@ -6,5 +6,5 @@ export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bu
|
|
|
6
6
|
export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElementWidth } from './misc';
|
|
7
7
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
8
8
|
export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
|
|
9
|
-
export { resizeColumn } from './resize-column';
|
|
9
|
+
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
10
10
|
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT } from './consts';
|
|
@@ -98,4 +98,11 @@ export const getTableScalingPercent = (table, tableRef) => {
|
|
|
98
98
|
let scalePercent = (renderWidth - 1) / tableWidth;
|
|
99
99
|
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
100
100
|
return Math.min(scalePercent, 1);
|
|
101
|
+
};
|
|
102
|
+
export const getStaticTableScalingPercent = (table, tableRenderWidth) => {
|
|
103
|
+
const tableWidth = getTableContainerElementWidth(table);
|
|
104
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
105
|
+
let scalePercent = (tableRenderWidth - 1) / tableWidth;
|
|
106
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
107
|
+
return Math.min(scalePercent, 1);
|
|
101
108
|
};
|
|
@@ -1,53 +1,68 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
|
|
3
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
5
4
|
import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
|
|
6
5
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
7
6
|
import { updateColgroup } from './resize-state';
|
|
8
7
|
export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false) => {
|
|
9
|
-
// If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
|
|
10
8
|
let scalePercent = 1;
|
|
11
|
-
let resizeAmount;
|
|
12
|
-
if (
|
|
13
|
-
var _tableRef$closest;
|
|
14
|
-
// when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
|
|
15
|
-
const tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
|
|
16
|
-
const tableContainerWidth = tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
17
|
-
const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
18
|
-
resizeAmount = amount * 2;
|
|
19
|
-
if (isOverflowed) {
|
|
20
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
21
|
-
} else {
|
|
22
|
-
resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
resizeAmount = amount;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// This need to be clean up if clean up the FF, we will not need this scale logic because now full table width changed/updated in resizeColumn
|
|
29
|
-
if (isTableScalingEnabled && !getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
9
|
+
let resizeAmount = amount;
|
|
10
|
+
if (isTableScalingEnabled) {
|
|
30
11
|
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
31
12
|
resizeAmount = amount / scalePercent;
|
|
32
13
|
}
|
|
33
|
-
const newState =
|
|
34
|
-
|
|
35
|
-
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
36
|
-
// use the difference in width from affected column to update overall table width
|
|
37
|
-
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
38
|
-
updateTable(delta, tableRef, tableNode);
|
|
39
|
-
return {
|
|
40
|
-
...newState,
|
|
41
|
-
tableWidth: resizeState.tableWidth + delta
|
|
42
|
-
};
|
|
43
|
-
}
|
|
14
|
+
const newState = resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
|
|
15
|
+
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
44
16
|
return newState;
|
|
45
17
|
};
|
|
46
|
-
|
|
18
|
+
|
|
19
|
+
// try not scale table during resize
|
|
20
|
+
export const resizeColumnAndTable = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false, originalTableWidth) => {
|
|
21
|
+
var _tableRef$closest;
|
|
22
|
+
// TODO: can we use document state, and apply scaling factor?
|
|
23
|
+
const tableWidth = tableRef.clientWidth;
|
|
24
|
+
const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
25
|
+
const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
26
|
+
let resizeAmount = amount * 2;
|
|
27
|
+
|
|
28
|
+
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
29
|
+
// let scalePercent = 1;
|
|
30
|
+
// if (isTableScalingEnabled) {
|
|
31
|
+
// import from ./misc
|
|
32
|
+
// scalePercent = getStaticTableScalingPercent(
|
|
33
|
+
// tableNode,
|
|
34
|
+
// originalTableWidth || resizeState.maxSize,
|
|
35
|
+
// );
|
|
36
|
+
// resizeAmount = amount / scalePercent;
|
|
37
|
+
// }
|
|
38
|
+
|
|
39
|
+
// need to look at the resize amount and try to adjust the colgroups
|
|
40
|
+
if (isOverflowed) {
|
|
41
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
42
|
+
} else {
|
|
43
|
+
resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
|
|
44
|
+
}
|
|
45
|
+
const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
46
|
+
|
|
47
|
+
// this function only updates the colgroup in DOM, it reverses the scalePercent
|
|
48
|
+
// todo: change isScalingEnabled to true when reimplementing scaling
|
|
49
|
+
updateColgroup(newState, tableRef, tableNode, false);
|
|
50
|
+
|
|
51
|
+
// use the difference in width from affected column to update overall table width
|
|
52
|
+
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
53
|
+
if (!isOverflowed) {
|
|
54
|
+
updateTablePreview(delta, tableRef, tableNode);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...newState,
|
|
58
|
+
tableWidth: isOverflowed ? tableContainerWidth : resizeState.tableWidth + delta
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const updateTablePreview = (resizeAmount, tableRef, tableNode) => {
|
|
47
62
|
const currentWidth = getTableContainerElementWidth(tableNode);
|
|
48
63
|
const resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
49
64
|
const resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
50
|
-
if (
|
|
65
|
+
if (resizingItem) {
|
|
51
66
|
const newWidth = `${currentWidth + resizeAmount}px`;
|
|
52
67
|
if (tableRef) {
|
|
53
68
|
tableRef.style.width = newWidth;
|
|
@@ -11,7 +11,7 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
|
11
11
|
import { META_KEYS } from '../table-analytics';
|
|
12
12
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
13
13
|
import { getPluginState } from './plugin-factory';
|
|
14
|
-
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, updateControls } from './utils';
|
|
14
|
+
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
15
15
|
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI) {
|
|
16
16
|
var state = view.state,
|
|
17
17
|
dispatch = view.dispatch;
|
|
@@ -135,11 +135,14 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
135
135
|
if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
|
|
136
136
|
_shouldScale = _shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
137
137
|
}
|
|
138
|
-
var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
139
138
|
var resizedDelta = clientX - startX;
|
|
140
|
-
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
141
139
|
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
140
|
+
var newResizeState = resizeColumnAndTable(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
141
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
142
142
|
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
143
|
+
} else {
|
|
144
|
+
var _newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
145
|
+
tr = updateColumnWidths(_newResizeState, table, start)(tr);
|
|
143
146
|
}
|
|
144
147
|
if (colIndex === map.width - 1) {
|
|
145
148
|
var mouseUpTime = event.timeStamp;
|
|
@@ -209,7 +212,11 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
209
212
|
if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
|
|
210
213
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
211
214
|
}
|
|
212
|
-
|
|
215
|
+
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
216
|
+
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
217
|
+
} else {
|
|
218
|
+
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
219
|
+
}
|
|
213
220
|
updateControls()(state);
|
|
214
221
|
}
|
|
215
222
|
window.addEventListener('mouseup', finish);
|
|
@@ -6,5 +6,5 @@ export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bu
|
|
|
6
6
|
export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElementWidth } from './misc';
|
|
7
7
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
8
8
|
export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
|
|
9
|
-
export { resizeColumn } from './resize-column';
|
|
9
|
+
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
10
10
|
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT } from './consts';
|
|
@@ -98,4 +98,11 @@ export var getTableScalingPercent = function getTableScalingPercent(table, table
|
|
|
98
98
|
var scalePercent = (renderWidth - 1) / tableWidth;
|
|
99
99
|
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
100
100
|
return Math.min(scalePercent, 1);
|
|
101
|
+
};
|
|
102
|
+
export var getStaticTableScalingPercent = function getStaticTableScalingPercent(table, tableRenderWidth) {
|
|
103
|
+
var tableWidth = getTableContainerElementWidth(table);
|
|
104
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
105
|
+
var scalePercent = (tableRenderWidth - 1) / tableWidth;
|
|
106
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
107
|
+
return Math.min(scalePercent, 1);
|
|
101
108
|
};
|
|
@@ -3,54 +3,71 @@ 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 { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
6
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
8
7
|
import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
|
|
9
8
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
10
9
|
import { updateColgroup } from './resize-state';
|
|
11
10
|
export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
12
11
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
13
|
-
// If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
|
|
14
12
|
var scalePercent = 1;
|
|
15
|
-
var resizeAmount;
|
|
16
|
-
if (
|
|
17
|
-
var _tableRef$closest;
|
|
18
|
-
// when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
|
|
19
|
-
var tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
|
|
20
|
-
var tableContainerWidth = tableRef === null || tableRef === void 0 || (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
21
|
-
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
22
|
-
resizeAmount = amount * 2;
|
|
23
|
-
if (isOverflowed) {
|
|
24
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
25
|
-
} else {
|
|
26
|
-
resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
resizeAmount = amount;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// This need to be clean up if clean up the FF, we will not need this scale logic because now full table width changed/updated in resizeColumn
|
|
33
|
-
if (isTableScalingEnabled && !getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
13
|
+
var resizeAmount = amount;
|
|
14
|
+
if (isTableScalingEnabled) {
|
|
34
15
|
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
35
16
|
resizeAmount = amount / scalePercent;
|
|
36
17
|
}
|
|
37
|
-
var newState =
|
|
38
|
-
|
|
39
|
-
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
40
|
-
// use the difference in width from affected column to update overall table width
|
|
41
|
-
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
42
|
-
updateTable(delta, tableRef, tableNode);
|
|
43
|
-
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
44
|
-
tableWidth: resizeState.tableWidth + delta
|
|
45
|
-
});
|
|
46
|
-
}
|
|
18
|
+
var newState = resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
|
|
19
|
+
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
47
20
|
return newState;
|
|
48
21
|
};
|
|
49
|
-
|
|
22
|
+
|
|
23
|
+
// try not scale table during resize
|
|
24
|
+
export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
25
|
+
var _tableRef$closest;
|
|
26
|
+
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
27
|
+
var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
|
|
28
|
+
// TODO: can we use document state, and apply scaling factor?
|
|
29
|
+
var tableWidth = tableRef.clientWidth;
|
|
30
|
+
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
31
|
+
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
32
|
+
var resizeAmount = amount * 2;
|
|
33
|
+
|
|
34
|
+
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
35
|
+
// let scalePercent = 1;
|
|
36
|
+
// if (isTableScalingEnabled) {
|
|
37
|
+
// import from ./misc
|
|
38
|
+
// scalePercent = getStaticTableScalingPercent(
|
|
39
|
+
// tableNode,
|
|
40
|
+
// originalTableWidth || resizeState.maxSize,
|
|
41
|
+
// );
|
|
42
|
+
// resizeAmount = amount / scalePercent;
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
// need to look at the resize amount and try to adjust the colgroups
|
|
46
|
+
if (isOverflowed) {
|
|
47
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
48
|
+
} else {
|
|
49
|
+
resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
|
|
50
|
+
}
|
|
51
|
+
var newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
52
|
+
|
|
53
|
+
// this function only updates the colgroup in DOM, it reverses the scalePercent
|
|
54
|
+
// todo: change isScalingEnabled to true when reimplementing scaling
|
|
55
|
+
updateColgroup(newState, tableRef, tableNode, false);
|
|
56
|
+
|
|
57
|
+
// use the difference in width from affected column to update overall table width
|
|
58
|
+
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
59
|
+
if (!isOverflowed) {
|
|
60
|
+
updateTablePreview(delta, tableRef, tableNode);
|
|
61
|
+
}
|
|
62
|
+
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
63
|
+
tableWidth: isOverflowed ? tableContainerWidth : resizeState.tableWidth + delta
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode) {
|
|
50
67
|
var currentWidth = getTableContainerElementWidth(tableNode);
|
|
51
68
|
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
|
|
52
69
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
53
|
-
if (
|
|
70
|
+
if (resizingItem) {
|
|
54
71
|
var newWidth = "".concat(currentWidth + resizeAmount, "px");
|
|
55
72
|
if (tableRef) {
|
|
56
73
|
tableRef.style.width = newWidth;
|
|
@@ -9,5 +9,5 @@ export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
|
9
9
|
export { scale, scaleWithParent, scaleTable, previewScaleTable, } from './scale-table';
|
|
10
10
|
export type { ScaleOptions } from './scale-table';
|
|
11
11
|
export type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
12
|
-
export { resizeColumn } from './resize-column';
|
|
12
|
+
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
13
13
|
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, } from './consts';
|
|
@@ -25,4 +25,5 @@ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getE
|
|
|
25
25
|
export declare const getTableElementWidth: (table: PMNode) => number;
|
|
26
26
|
export declare const getTableContainerElementWidth: (table: PMNode) => number;
|
|
27
27
|
export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement | null) => number;
|
|
28
|
+
export declare const getStaticTableScalingPercent: (table: PMNode, tableRenderWidth: number) => number;
|
|
28
29
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { ResizeState } from './types';
|
|
3
3
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean) => ResizeState;
|
|
4
|
+
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number) => ResizeState;
|
|
@@ -9,5 +9,5 @@ export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
|
9
9
|
export { scale, scaleWithParent, scaleTable, previewScaleTable, } from './scale-table';
|
|
10
10
|
export type { ScaleOptions } from './scale-table';
|
|
11
11
|
export type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
12
|
-
export { resizeColumn } from './resize-column';
|
|
12
|
+
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
13
13
|
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, } from './consts';
|
|
@@ -25,4 +25,5 @@ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getE
|
|
|
25
25
|
export declare const getTableElementWidth: (table: PMNode) => number;
|
|
26
26
|
export declare const getTableContainerElementWidth: (table: PMNode) => number;
|
|
27
27
|
export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement | null) => number;
|
|
28
|
+
export declare const getStaticTableScalingPercent: (table: PMNode, tableRenderWidth: number) => number;
|
|
28
29
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { ResizeState } from './types';
|
|
3
3
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean) => ResizeState;
|
|
4
|
+
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number) => ResizeState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.13.
|
|
3
|
+
"version": "7.13.2",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@atlaskit/primitives": "^6.1.0",
|
|
52
52
|
"@atlaskit/theme": "^12.8.0",
|
|
53
53
|
"@atlaskit/toggle": "^13.1.0",
|
|
54
|
-
"@atlaskit/tokens": "^1.
|
|
54
|
+
"@atlaskit/tokens": "^1.47.0",
|
|
55
55
|
"@atlaskit/tooltip": "^18.3.0",
|
|
56
56
|
"@babel/runtime": "^7.0.0",
|
|
57
57
|
"@emotion/react": "^11.7.1",
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
getTableMaxWidth,
|
|
33
33
|
pointsAtCell,
|
|
34
34
|
resizeColumn,
|
|
35
|
+
resizeColumnAndTable,
|
|
35
36
|
updateControls,
|
|
36
37
|
} from './utils';
|
|
37
38
|
|
|
@@ -197,22 +198,31 @@ export const handleMouseDown = (
|
|
|
197
198
|
shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
const newResizeState = resizeColumn(
|
|
201
|
-
resizeState,
|
|
202
|
-
colIndex,
|
|
203
|
-
clientX - startX,
|
|
204
|
-
dom,
|
|
205
|
-
originalTable,
|
|
206
|
-
resizingSelectedColumns ? selectedColumns : undefined,
|
|
207
|
-
shouldScale,
|
|
208
|
-
);
|
|
209
|
-
|
|
210
201
|
const resizedDelta = clientX - startX;
|
|
211
202
|
|
|
212
|
-
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
213
|
-
|
|
214
203
|
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
204
|
+
const newResizeState = resizeColumnAndTable(
|
|
205
|
+
resizeState,
|
|
206
|
+
colIndex,
|
|
207
|
+
clientX - startX,
|
|
208
|
+
dom,
|
|
209
|
+
originalTable,
|
|
210
|
+
resizingSelectedColumns ? selectedColumns : undefined,
|
|
211
|
+
shouldScale,
|
|
212
|
+
);
|
|
213
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
215
214
|
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
215
|
+
} else {
|
|
216
|
+
const newResizeState = resizeColumn(
|
|
217
|
+
resizeState,
|
|
218
|
+
colIndex,
|
|
219
|
+
clientX - startX,
|
|
220
|
+
dom,
|
|
221
|
+
originalTable,
|
|
222
|
+
resizingSelectedColumns ? selectedColumns : undefined,
|
|
223
|
+
shouldScale,
|
|
224
|
+
);
|
|
225
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
if (colIndex === map.width - 1) {
|
|
@@ -300,15 +310,27 @@ export const handleMouseDown = (
|
|
|
300
310
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
301
311
|
}
|
|
302
312
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
313
|
+
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
314
|
+
resizeColumnAndTable(
|
|
315
|
+
resizeState,
|
|
316
|
+
colIndex,
|
|
317
|
+
clientX - dragging.startX,
|
|
318
|
+
dom,
|
|
319
|
+
table,
|
|
320
|
+
undefined,
|
|
321
|
+
shouldScale,
|
|
322
|
+
);
|
|
323
|
+
} else {
|
|
324
|
+
resizeColumn(
|
|
325
|
+
resizeState,
|
|
326
|
+
colIndex,
|
|
327
|
+
clientX - dragging.startX,
|
|
328
|
+
dom,
|
|
329
|
+
table,
|
|
330
|
+
undefined,
|
|
331
|
+
shouldScale,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
312
334
|
|
|
313
335
|
updateControls()(state);
|
|
314
336
|
}
|
|
@@ -42,7 +42,7 @@ export {
|
|
|
42
42
|
} from './scale-table';
|
|
43
43
|
export type { ScaleOptions } from './scale-table';
|
|
44
44
|
export type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
45
|
-
export { resizeColumn } from './resize-column';
|
|
45
|
+
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
46
46
|
export {
|
|
47
47
|
COLUMN_MIN_WIDTH,
|
|
48
48
|
TABLE_MAX_WIDTH,
|
|
@@ -167,3 +167,14 @@ export const getTableScalingPercent = (
|
|
|
167
167
|
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
168
168
|
return Math.min(scalePercent, 1);
|
|
169
169
|
};
|
|
170
|
+
|
|
171
|
+
export const getStaticTableScalingPercent = (
|
|
172
|
+
table: PMNode,
|
|
173
|
+
tableRenderWidth: number,
|
|
174
|
+
) => {
|
|
175
|
+
const tableWidth = getTableContainerElementWidth(table);
|
|
176
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
177
|
+
let scalePercent = (tableRenderWidth - 1) / tableWidth;
|
|
178
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
179
|
+
return Math.min(scalePercent, 1);
|
|
180
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
|
|
5
4
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
6
5
|
|
|
@@ -18,79 +17,100 @@ export const resizeColumn = (
|
|
|
18
17
|
selectedColumns?: number[],
|
|
19
18
|
isTableScalingEnabled = false,
|
|
20
19
|
): ResizeState => {
|
|
21
|
-
// If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
|
|
22
20
|
let scalePercent = 1;
|
|
23
|
-
let resizeAmount
|
|
24
|
-
|
|
25
|
-
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
26
|
-
// when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
|
|
27
|
-
const tableWidth = tableRef?.clientWidth;
|
|
28
|
-
const tableContainerWidth = tableRef?.closest('.resizer-item')?.clientWidth;
|
|
29
|
-
|
|
30
|
-
const isOverflowed = !!(
|
|
31
|
-
tableWidth &&
|
|
32
|
-
tableContainerWidth &&
|
|
33
|
-
tableWidth > tableContainerWidth
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
resizeAmount = amount * 2;
|
|
37
|
-
|
|
38
|
-
if (isOverflowed) {
|
|
39
|
-
resizeAmount =
|
|
40
|
-
amount < 0
|
|
41
|
-
? amount
|
|
42
|
-
: resizeAmount -
|
|
43
|
-
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
44
|
-
} else {
|
|
45
|
-
resizeAmount =
|
|
46
|
-
amount > 0 && tableContainerWidth
|
|
47
|
-
? resizeAmount -
|
|
48
|
-
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2
|
|
49
|
-
: resizeAmount;
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
resizeAmount = amount;
|
|
53
|
-
}
|
|
21
|
+
let resizeAmount = amount;
|
|
54
22
|
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
isTableScalingEnabled &&
|
|
58
|
-
!getBooleanFF('platform.editor.table.colum-resizing-improvements')
|
|
59
|
-
) {
|
|
23
|
+
if (isTableScalingEnabled) {
|
|
60
24
|
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
61
25
|
resizeAmount = amount / scalePercent;
|
|
62
26
|
}
|
|
63
27
|
|
|
64
|
-
const newState =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
: resizeState;
|
|
73
|
-
|
|
74
|
-
getBooleanFF('platform.editor.table.colum-resizing-improvements')
|
|
75
|
-
? updateColgroup(newState, tableRef, tableNode, false)
|
|
76
|
-
: updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
77
|
-
|
|
78
|
-
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
79
|
-
// use the difference in width from affected column to update overall table width
|
|
80
|
-
const delta =
|
|
81
|
-
newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
82
|
-
|
|
83
|
-
updateTable(delta, tableRef, tableNode);
|
|
84
|
-
return {
|
|
85
|
-
...newState,
|
|
86
|
-
tableWidth: resizeState.tableWidth + delta,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
28
|
+
const newState =
|
|
29
|
+
resizeAmount > 0
|
|
30
|
+
? growColumn(resizeState, colIndex, resizeAmount, selectedColumns)
|
|
31
|
+
: resizeAmount < 0
|
|
32
|
+
? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns)
|
|
33
|
+
: resizeState;
|
|
34
|
+
|
|
35
|
+
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
89
36
|
|
|
90
37
|
return newState;
|
|
91
38
|
};
|
|
92
39
|
|
|
93
|
-
|
|
40
|
+
// try not scale table during resize
|
|
41
|
+
export const resizeColumnAndTable = (
|
|
42
|
+
resizeState: ResizeState,
|
|
43
|
+
colIndex: number,
|
|
44
|
+
amount: number,
|
|
45
|
+
tableRef: HTMLElement,
|
|
46
|
+
tableNode: PmNode,
|
|
47
|
+
selectedColumns?: number[],
|
|
48
|
+
isTableScalingEnabled = false,
|
|
49
|
+
originalTableWidth?: number,
|
|
50
|
+
): ResizeState => {
|
|
51
|
+
// TODO: can we use document state, and apply scaling factor?
|
|
52
|
+
const tableWidth = tableRef.clientWidth;
|
|
53
|
+
const tableContainerWidth = tableRef.closest(
|
|
54
|
+
'.pm-table-container',
|
|
55
|
+
)?.clientWidth;
|
|
56
|
+
|
|
57
|
+
const isOverflowed = !!(
|
|
58
|
+
tableWidth &&
|
|
59
|
+
tableContainerWidth &&
|
|
60
|
+
tableWidth > tableContainerWidth
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
let resizeAmount = amount * 2;
|
|
64
|
+
|
|
65
|
+
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
66
|
+
// let scalePercent = 1;
|
|
67
|
+
// if (isTableScalingEnabled) {
|
|
68
|
+
// import from ./misc
|
|
69
|
+
// scalePercent = getStaticTableScalingPercent(
|
|
70
|
+
// tableNode,
|
|
71
|
+
// originalTableWidth || resizeState.maxSize,
|
|
72
|
+
// );
|
|
73
|
+
// resizeAmount = amount / scalePercent;
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
// need to look at the resize amount and try to adjust the colgroups
|
|
77
|
+
if (isOverflowed) {
|
|
78
|
+
resizeAmount =
|
|
79
|
+
amount < 0
|
|
80
|
+
? amount
|
|
81
|
+
: resizeAmount -
|
|
82
|
+
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
83
|
+
} else {
|
|
84
|
+
resizeAmount =
|
|
85
|
+
amount > 0 && tableContainerWidth
|
|
86
|
+
? resizeAmount -
|
|
87
|
+
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2
|
|
88
|
+
: resizeAmount;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
92
|
+
|
|
93
|
+
// this function only updates the colgroup in DOM, it reverses the scalePercent
|
|
94
|
+
// todo: change isScalingEnabled to true when reimplementing scaling
|
|
95
|
+
updateColgroup(newState, tableRef, tableNode, false);
|
|
96
|
+
|
|
97
|
+
// use the difference in width from affected column to update overall table width
|
|
98
|
+
const delta =
|
|
99
|
+
newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
100
|
+
|
|
101
|
+
if (!isOverflowed) {
|
|
102
|
+
updateTablePreview(delta, tableRef, tableNode);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
...newState,
|
|
107
|
+
tableWidth: isOverflowed
|
|
108
|
+
? tableContainerWidth
|
|
109
|
+
: resizeState.tableWidth + delta,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const updateTablePreview = (
|
|
94
114
|
resizeAmount: number,
|
|
95
115
|
tableRef: HTMLElement | null,
|
|
96
116
|
tableNode: PmNode,
|
|
@@ -101,7 +121,7 @@ const updateTable = (
|
|
|
101
121
|
);
|
|
102
122
|
const resizingItem = resizingContainer?.querySelector('.resizer-item');
|
|
103
123
|
|
|
104
|
-
if (
|
|
124
|
+
if (resizingItem) {
|
|
105
125
|
const newWidth = `${currentWidth + resizeAmount}px`;
|
|
106
126
|
if (tableRef) {
|
|
107
127
|
tableRef.style.width = newWidth;
|