@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.21.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#122514](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122514)
|
|
8
|
+
[`91276c81ef8a8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/91276c81ef8a8) -
|
|
9
|
+
[ED-24019] This change is cleaning up the feature flag
|
|
10
|
+
'platform.editor.a11y-help-dialog-shortcut-keys-position_aghfg' which was introduced for new
|
|
11
|
+
keyboard shortcuts for inserting columns and rows to a table.
|
|
12
|
+
- [#122054](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122054)
|
|
13
|
+
[`2ead5fa12242d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2ead5fa12242d) -
|
|
14
|
+
Use scaled amounts for new column resizing, and update logic to cater for more scenarios
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 7.21.4
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -40,12 +40,10 @@ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEn
|
|
|
40
40
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowAfter.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list);
|
|
41
41
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnBefore.common, (0, _insert.addColumnBefore)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
42
42
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfter.common, (0, _insert.addColumnAfter)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfterVO.common, (0, _insert.addColumnAfter)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
48
|
-
}
|
|
43
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowBeforeVO.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('TOP'), list);
|
|
44
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowAfterVO.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list);
|
|
45
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnBeforeVO.common, (0, _insert.addColumnBefore)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
46
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfterVO.common, (0, _insert.addColumnAfter)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
49
47
|
if (dragAndDropEnabled) {
|
|
50
48
|
// Move row/column shortcuts
|
|
51
49
|
/**
|
|
@@ -21,6 +21,7 @@ var _tableAnalytics = require("../table-analytics");
|
|
|
21
21
|
var _commands = require("./commands");
|
|
22
22
|
var _pluginFactory2 = require("./plugin-factory");
|
|
23
23
|
var _utils3 = require("./utils");
|
|
24
|
+
var _resizeColumn = require("./utils/resize-column");
|
|
24
25
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
26
|
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; }
|
|
26
27
|
var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
@@ -29,7 +30,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
29
30
|
var editorDisabled = !view.editable;
|
|
30
31
|
var domAtPos = view.domAtPos.bind(view);
|
|
31
32
|
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
32
|
-
lineLength = _getEditorContainerWi.lineLength
|
|
33
|
+
lineLength = _getEditorContainerWi.lineLength,
|
|
34
|
+
editorWidth = _getEditorContainerWi.width;
|
|
33
35
|
if (editorDisabled || localResizeHandlePos === null || !(0, _utils3.pointsAtCell)(state.doc.resolve(localResizeHandlePos))) {
|
|
34
36
|
return false;
|
|
35
37
|
}
|
|
@@ -95,6 +97,17 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
95
97
|
// When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
|
|
96
98
|
// unnecessary tooltips being displayed during drag.
|
|
97
99
|
(0, _misc.updateResizeHandleDecorations)(undefined, undefined, false)(state, dispatch);
|
|
100
|
+
|
|
101
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
102
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
103
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
104
|
+
resizeState = (0, _resizeColumn.scaleResizeState)({
|
|
105
|
+
resizeState: resizeState,
|
|
106
|
+
tableRef: dom,
|
|
107
|
+
tableNode: originalTable,
|
|
108
|
+
editorWidth: editorWidth
|
|
109
|
+
});
|
|
110
|
+
}
|
|
98
111
|
function finish(event) {
|
|
99
112
|
window.removeEventListener('mouseup', finish);
|
|
100
113
|
window.removeEventListener('mousemove', move);
|
|
@@ -154,18 +167,23 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
154
167
|
var resizedDelta = clientX - startX;
|
|
155
168
|
var shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled && (0, _platformFeatureFlags.fg)('platform.editor.table.use-increased-scaling-percent');
|
|
156
169
|
if (isNewColumnResizingEnabled && !(0, _utils2.isTableNested)(state, tablePos)) {
|
|
157
|
-
var newResizeState = (0, _utils3.resizeColumnAndTable)(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
var newResizeState = (0, _utils3.resizeColumnAndTable)({
|
|
171
|
+
resizeState: resizeState,
|
|
172
|
+
colIndex: colIndex,
|
|
173
|
+
amount: resizedDelta,
|
|
174
|
+
tableRef: dom,
|
|
175
|
+
tableNode: originalTable,
|
|
176
|
+
width: editorWidth,
|
|
177
|
+
lineLength: lineLength,
|
|
178
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
179
|
+
});
|
|
162
180
|
tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
|
|
163
181
|
|
|
164
182
|
// 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
|
|
165
|
-
var shouldChangeAlignment = (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.
|
|
183
|
+
var shouldChangeAlignment = (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.maxSize);
|
|
166
184
|
if (shouldChangeAlignment) {
|
|
167
185
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
168
|
-
width: newResizeState.
|
|
186
|
+
width: newResizeState.maxSize,
|
|
169
187
|
layout: _alignment.ALIGN_CENTER
|
|
170
188
|
}));
|
|
171
189
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
@@ -173,7 +191,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
173
191
|
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
|
|
174
192
|
actionSubjectId: null,
|
|
175
193
|
attributes: {
|
|
176
|
-
tableWidth: newResizeState.
|
|
194
|
+
tableWidth: newResizeState.maxSize,
|
|
177
195
|
newAlignment: _alignment.ALIGN_CENTER,
|
|
178
196
|
previousAlignment: _alignment.ALIGN_START,
|
|
179
197
|
totalRowCount: totalRowCount,
|
|
@@ -184,7 +202,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
184
202
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
185
203
|
})(tr);
|
|
186
204
|
} else {
|
|
187
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
205
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
188
206
|
}
|
|
189
207
|
} else {
|
|
190
208
|
var _newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
@@ -256,10 +274,20 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
256
274
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
257
275
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
258
276
|
}
|
|
277
|
+
var resizedDelta = clientX - dragging.startX;
|
|
259
278
|
if (isNewColumnResizingEnabled && !(0, _utils2.isTableNested)(state, tablePos)) {
|
|
260
|
-
(0, _utils3.resizeColumnAndTable)(
|
|
279
|
+
(0, _utils3.resizeColumnAndTable)({
|
|
280
|
+
resizeState: resizeState,
|
|
281
|
+
colIndex: colIndex,
|
|
282
|
+
amount: resizedDelta,
|
|
283
|
+
tableRef: dom,
|
|
284
|
+
tableNode: originalTable,
|
|
285
|
+
width: editorWidth,
|
|
286
|
+
lineLength: lineLength,
|
|
287
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
288
|
+
});
|
|
261
289
|
} else {
|
|
262
|
-
(0, _utils3.resizeColumn)(resizeState, colIndex,
|
|
290
|
+
(0, _utils3.resizeColumn)(resizeState, colIndex, resizedDelta, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
263
291
|
}
|
|
264
292
|
(0, _utils3.updateControls)()(state);
|
|
265
293
|
}
|
|
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.resizeColumnAndTable = exports.resizeColumn = void 0;
|
|
7
|
+
exports.scaleResizeState = exports.resizeColumnAndTable = exports.resizeColumn = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
9
10
|
var _types = require("../../../types");
|
|
10
11
|
var _alignment = require("../../../utils/alignment");
|
|
11
12
|
var _misc = require("./misc");
|
|
@@ -26,68 +27,115 @@ var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, col
|
|
|
26
27
|
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, isTableScalingEnabled, shouldUseIncreasedScalingPercent);
|
|
27
28
|
return newState;
|
|
28
29
|
};
|
|
30
|
+
var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnAndTable(_ref) {
|
|
31
|
+
var resizeState = _ref.resizeState,
|
|
32
|
+
colIndex = _ref.colIndex,
|
|
33
|
+
amount = _ref.amount,
|
|
34
|
+
tableRef = _ref.tableRef,
|
|
35
|
+
tableNode = _ref.tableNode,
|
|
36
|
+
lineLength = _ref.lineLength,
|
|
37
|
+
editorWidth = _ref.width,
|
|
38
|
+
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled;
|
|
39
|
+
var editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
40
|
+
var isTableLeftAligned = tableNode.attrs.layout === _alignment.ALIGN_START;
|
|
41
|
+
var resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
42
|
+
var willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
43
|
+
var willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
29
44
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
42
|
-
var resizeAmount = tableNode.attrs.layout === _alignment.ALIGN_START && !isOverflowed ? amount : amount * 2;
|
|
43
|
-
|
|
44
|
-
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
45
|
-
// let scalePercent = 1;
|
|
46
|
-
// if (isTableScalingEnabled) {
|
|
47
|
-
// import from ./misc
|
|
48
|
-
// scalePercent = getStaticTableScalingPercent(
|
|
49
|
-
// tableNode,
|
|
50
|
-
// originalTableWidth || resizeState.maxSize,
|
|
51
|
-
// );
|
|
52
|
-
// resizeAmount = amount / scalePercent;
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
// need to look at the resize amount and try to adjust the colgroups
|
|
56
|
-
if (isOverflowed) {
|
|
57
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
45
|
+
// STEP 1: Update col width
|
|
46
|
+
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
47
|
+
var _tableRef$closest;
|
|
48
|
+
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
49
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
|
|
50
|
+
}
|
|
51
|
+
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
52
|
+
var diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
53
|
+
var rest = amount - diff;
|
|
54
|
+
var final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
55
|
+
resizeAmount = final;
|
|
58
56
|
}
|
|
59
57
|
var newState = (0, _resizeLogic.updateAffectedColumn)(resizeState, colIndex, resizeAmount);
|
|
60
58
|
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, false, shouldUseIncreasedScalingPercent);
|
|
64
|
-
|
|
65
|
-
// use the difference in width from affected column to update overall table width
|
|
59
|
+
// STEP 2: Update table container width
|
|
60
|
+
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
66
61
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
|
|
63
|
+
// CASE 1A: table will stay in overflow
|
|
64
|
+
// do not grow the table because resize is happening in the overflow region
|
|
65
|
+
// and the overall table container needs to be retained
|
|
66
|
+
resizeState.maxSize :
|
|
67
|
+
// CASE 1B: table will no longer be in overflow, so adjust container width
|
|
68
|
+
// ensure the table is resized without any 'big jumps' by working out
|
|
69
|
+
// the difference between the new table width and the max size and adding the resize
|
|
70
|
+
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
71
|
+
// CASE 2: table will hit editor edge
|
|
72
|
+
editorContainerWidth :
|
|
73
|
+
// CASE 3: table is being resized from a non-overflow state
|
|
74
|
+
resizeState.maxSize + delta);
|
|
75
|
+
|
|
76
|
+
// do not apply scaling logic because resize state is already scaled
|
|
77
|
+
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, false, false);
|
|
78
|
+
if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
|
|
79
|
+
updateTablePreview(tableRef, newState.maxSize, (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
71
80
|
}
|
|
72
|
-
return
|
|
73
|
-
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
74
|
-
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
75
|
-
});
|
|
81
|
+
return newState;
|
|
76
82
|
};
|
|
77
|
-
var updateTablePreview = function updateTablePreview(
|
|
78
|
-
var
|
|
79
|
-
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
|
|
83
|
+
var updateTablePreview = function updateTablePreview(tableRef, newTableWidth, shouldChangeAlignment) {
|
|
84
|
+
var resizingContainer = tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
|
|
80
85
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
81
86
|
var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
82
87
|
if (resizingItem) {
|
|
83
|
-
var newWidth = "".concat(
|
|
84
|
-
if (tableRef) {
|
|
85
|
-
tableRef.style.width = newWidth;
|
|
86
|
-
}
|
|
88
|
+
var newWidth = "".concat(newTableWidth, "px");
|
|
87
89
|
resizingContainer.style.width = newWidth;
|
|
88
90
|
resizingItem.style.width = newWidth;
|
|
89
|
-
if (
|
|
90
|
-
alignmentContainer.style.justifyContent =
|
|
91
|
+
if (shouldChangeAlignment && alignmentContainer) {
|
|
92
|
+
alignmentContainer.style.justifyContent = _alignment.ALIGN_CENTER;
|
|
91
93
|
}
|
|
92
94
|
}
|
|
95
|
+
};
|
|
96
|
+
var getEditorContainerWidth = function getEditorContainerWidth(editorWidth) {
|
|
97
|
+
return Math.min(editorWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Apply a scaling factor to resize state
|
|
102
|
+
*/
|
|
103
|
+
var scaleResizeState = exports.scaleResizeState = function scaleResizeState(_ref2) {
|
|
104
|
+
var resizeState = _ref2.resizeState,
|
|
105
|
+
tableRef = _ref2.tableRef,
|
|
106
|
+
tableNode = _ref2.tableNode,
|
|
107
|
+
editorWidth = _ref2.editorWidth;
|
|
108
|
+
// check if table is scaled, if not then avoid applying scaling values down
|
|
109
|
+
if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
|
|
110
|
+
return resizeState;
|
|
111
|
+
}
|
|
112
|
+
var scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
|
|
113
|
+
var cols = resizeState.cols.map(function (col) {
|
|
114
|
+
return _objectSpread(_objectSpread({}, col), {}, {
|
|
115
|
+
width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
119
|
+
var calculatedTableWidth = cols.reduce(function (prev, curr) {
|
|
120
|
+
return prev + curr.width;
|
|
121
|
+
}, 0);
|
|
122
|
+
|
|
123
|
+
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
124
|
+
// distribute the difference to the smallest column
|
|
125
|
+
if (calculatedTableWidth > scaledTableWidth) {
|
|
126
|
+
var diff = calculatedTableWidth - scaledTableWidth;
|
|
127
|
+
cols = cols.map(function (col) {
|
|
128
|
+
return col.width - diff >= col.minWidth ? _objectSpread(_objectSpread({}, col), {}, {
|
|
129
|
+
width: col.width - diff
|
|
130
|
+
}) : col;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return _objectSpread(_objectSpread({}, resizeState), {}, {
|
|
134
|
+
widths: cols.map(function (col) {
|
|
135
|
+
return col.width;
|
|
136
|
+
}),
|
|
137
|
+
tableWidth: scaledTableWidth,
|
|
138
|
+
maxSize: Math.round(resizeState.maxSize * scalePercent),
|
|
139
|
+
cols: cols
|
|
140
|
+
});
|
|
93
141
|
};
|
|
@@ -20,5 +20,5 @@ var normaliseAlignment = exports.normaliseAlignment = function normaliseAlignmen
|
|
|
20
20
|
* We don't want to switch alignment in Full-width editor
|
|
21
21
|
*/
|
|
22
22
|
var shouldChangeAlignmentToCenterResized = exports.shouldChangeAlignmentToCenterResized = function shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) {
|
|
23
|
-
return isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < _consts.FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
23
|
+
return Boolean(isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < _consts.FULL_WIDTH_EDITOR_CONTENT_WIDTH);
|
|
24
24
|
};
|
|
@@ -23,12 +23,10 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
|
|
|
23
23
|
bindKeymapWithCommand(addRowAfter.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
24
24
|
bindKeymapWithCommand(addColumnBefore.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
25
25
|
bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
31
|
-
}
|
|
26
|
+
bindKeymapWithCommand(addRowBeforeVO.common, addRowAroundSelection(editorAnalyticsAPI)('TOP'), list);
|
|
27
|
+
bindKeymapWithCommand(addRowAfterVO.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
28
|
+
bindKeymapWithCommand(addColumnBeforeVO.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
29
|
+
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
32
30
|
if (dragAndDropEnabled) {
|
|
33
31
|
// Move row/column shortcuts
|
|
34
32
|
/**
|
|
@@ -13,6 +13,7 @@ import { META_KEYS } from '../table-analytics';
|
|
|
13
13
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
14
14
|
import { getPluginState } from './plugin-factory';
|
|
15
15
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
16
|
+
import { scaleResizeState } from './utils/resize-column';
|
|
16
17
|
export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) => {
|
|
17
18
|
const {
|
|
18
19
|
state,
|
|
@@ -21,7 +22,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
21
22
|
const editorDisabled = !view.editable;
|
|
22
23
|
const domAtPos = view.domAtPos.bind(view);
|
|
23
24
|
const {
|
|
24
|
-
lineLength
|
|
25
|
+
lineLength,
|
|
26
|
+
width: editorWidth
|
|
25
27
|
} = getEditorContainerWidth();
|
|
26
28
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
27
29
|
return false;
|
|
@@ -61,7 +63,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
61
63
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
62
64
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
63
65
|
}
|
|
64
|
-
|
|
66
|
+
let resizeState = getResizeState({
|
|
65
67
|
minWidth: tableCellMinWidth,
|
|
66
68
|
maxSize,
|
|
67
69
|
table: originalTable,
|
|
@@ -89,6 +91,17 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
89
91
|
// When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
|
|
90
92
|
// unnecessary tooltips being displayed during drag.
|
|
91
93
|
updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
|
|
94
|
+
|
|
95
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
96
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
97
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
98
|
+
resizeState = scaleResizeState({
|
|
99
|
+
resizeState,
|
|
100
|
+
tableRef: dom,
|
|
101
|
+
tableNode: originalTable,
|
|
102
|
+
editorWidth
|
|
103
|
+
});
|
|
104
|
+
}
|
|
92
105
|
function finish(event) {
|
|
93
106
|
window.removeEventListener('mouseup', finish);
|
|
94
107
|
window.removeEventListener('mousemove', move);
|
|
@@ -158,19 +171,24 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
158
171
|
const resizedDelta = clientX - startX;
|
|
159
172
|
const shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled && fg('platform.editor.table.use-increased-scaling-percent');
|
|
160
173
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
161
|
-
const newResizeState = resizeColumnAndTable(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
const newResizeState = resizeColumnAndTable({
|
|
175
|
+
resizeState,
|
|
176
|
+
colIndex,
|
|
177
|
+
amount: resizedDelta,
|
|
178
|
+
tableRef: dom,
|
|
179
|
+
tableNode: originalTable,
|
|
180
|
+
width: editorWidth,
|
|
181
|
+
lineLength,
|
|
182
|
+
isTableAlignmentEnabled
|
|
183
|
+
});
|
|
166
184
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
167
185
|
|
|
168
186
|
// 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
|
|
169
|
-
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.
|
|
187
|
+
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.maxSize);
|
|
170
188
|
if (shouldChangeAlignment) {
|
|
171
189
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
|
|
172
190
|
...table.attrs,
|
|
173
|
-
width: newResizeState.
|
|
191
|
+
width: newResizeState.maxSize,
|
|
174
192
|
layout: ALIGN_CENTER
|
|
175
193
|
});
|
|
176
194
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
@@ -178,7 +196,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
178
196
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
179
197
|
actionSubjectId: null,
|
|
180
198
|
attributes: {
|
|
181
|
-
tableWidth: newResizeState.
|
|
199
|
+
tableWidth: newResizeState.maxSize,
|
|
182
200
|
newAlignment: ALIGN_CENTER,
|
|
183
201
|
previousAlignment: ALIGN_START,
|
|
184
202
|
totalRowCount: totalRowCount,
|
|
@@ -189,7 +207,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
189
207
|
eventType: EVENT_TYPE.TRACK
|
|
190
208
|
})(tr);
|
|
191
209
|
} else {
|
|
192
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
210
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
193
211
|
}
|
|
194
212
|
} else {
|
|
195
213
|
const newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
@@ -267,10 +285,20 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
267
285
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
268
286
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
269
287
|
}
|
|
288
|
+
const resizedDelta = clientX - dragging.startX;
|
|
270
289
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
271
|
-
resizeColumnAndTable(
|
|
290
|
+
resizeColumnAndTable({
|
|
291
|
+
resizeState,
|
|
292
|
+
colIndex,
|
|
293
|
+
amount: resizedDelta,
|
|
294
|
+
tableRef: dom,
|
|
295
|
+
tableNode: originalTable,
|
|
296
|
+
width: editorWidth,
|
|
297
|
+
lineLength,
|
|
298
|
+
isTableAlignmentEnabled
|
|
299
|
+
});
|
|
272
300
|
} else {
|
|
273
|
-
resizeColumn(resizeState, colIndex,
|
|
301
|
+
resizeColumn(resizeState, colIndex, resizedDelta, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
274
302
|
}
|
|
275
303
|
updateControls()(state);
|
|
276
304
|
}
|