@atlaskit/editor-plugin-table 7.5.8 → 7.5.10
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 +13 -0
- package/dist/cjs/nodeviews/TableComponent.js +34 -27
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +8 -1
- package/dist/cjs/transforms/column-width.js +4 -3
- package/dist/es2019/nodeviews/TableComponent.js +35 -28
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +12 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +8 -1
- package/dist/es2019/transforms/column-width.js +4 -3
- package/dist/esm/nodeviews/TableComponent.js +34 -27
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +8 -1
- package/dist/esm/transforms/column-width.js +4 -3
- package/package.json +2 -2
- package/src/nodeviews/TableComponent.tsx +36 -36
- package/src/pm-plugins/table-resizing/event-handlers.ts +13 -3
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +12 -4
- package/src/transforms/column-width.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.5.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#81527](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81527) [`f54438c79095`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f54438c79095) - prevent nested tables from scaling
|
|
8
|
+
|
|
9
|
+
## 7.5.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#81302](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81302) [`969e899b8844`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/969e899b8844) - Update column resize logic to match mouse movement
|
|
14
|
+
- [#81427](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81427) [`8adea3fa8973`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8adea3fa8973) - [ux] When number column toggled and preserve table widths ff enabled, the table oveflow state should align with current behaviour.
|
|
15
|
+
|
|
3
16
|
## 7.5.8
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -185,8 +185,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
185
185
|
getNode = _this$props2.getNode,
|
|
186
186
|
getPos = _this$props2.getPos,
|
|
187
187
|
containerWidth = _this$props2.containerWidth,
|
|
188
|
-
options = _this$props2.options
|
|
189
|
-
isTableScalingEnabled = _this$props2.isTableScalingEnabled;
|
|
188
|
+
options = _this$props2.options;
|
|
190
189
|
var node = getNode();
|
|
191
190
|
var state = view.state,
|
|
192
191
|
dispatch = view.dispatch;
|
|
@@ -203,7 +202,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
203
202
|
start: pos + 1,
|
|
204
203
|
containerWidth: width,
|
|
205
204
|
previousContainerWidth: _this.containerWidth.width || width
|
|
206
|
-
}, options), domAtPos,
|
|
205
|
+
}, options), domAtPos, false)(state.tr);
|
|
207
206
|
dispatch(tr);
|
|
208
207
|
});
|
|
209
208
|
(0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "setTimerToSendInitialOverflowCaptured", function (isOverflowing) {
|
|
@@ -436,8 +435,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
436
435
|
}, {
|
|
437
436
|
key: "handleColgroupUpdates",
|
|
438
437
|
value: function handleColgroupUpdates() {
|
|
439
|
-
var
|
|
440
|
-
_this2 = this;
|
|
438
|
+
var _this2 = this;
|
|
441
439
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
442
440
|
var _this$props9 = this.props,
|
|
443
441
|
getNode = _this$props9.getNode,
|
|
@@ -455,30 +453,34 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
455
453
|
var tableNode = getNode();
|
|
456
454
|
var start = getPos() || 0;
|
|
457
455
|
var depth = view.state.doc.resolve(start).depth;
|
|
458
|
-
|
|
459
|
-
// TODO - remove this when support is added for nested tables
|
|
460
456
|
if (depth !== 0) {
|
|
461
457
|
return;
|
|
462
458
|
}
|
|
463
459
|
var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(tableNode);
|
|
464
460
|
var shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
461
|
+
if (force || shouldTableScale) {
|
|
462
|
+
var _this$containerWidth;
|
|
463
|
+
var containerWidthValue = containerWidth.width;
|
|
464
|
+
var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
|
|
465
|
+
var wasTableResized = (0, _colgroup.hasTableBeenResized)(this.node);
|
|
466
|
+
var isTableResied = (0, _colgroup.hasTableBeenResized)(tableNode);
|
|
467
|
+
var isColumnsDistributed = wasTableResized && !isTableResied;
|
|
468
|
+
if (force || !isResizing && (isWidthChanged || isColumnsDistributed)) {
|
|
469
|
+
var resizeState = (0, _utils4.getResizeState)({
|
|
470
|
+
minWidth: _utils4.COLUMN_MIN_WIDTH,
|
|
471
|
+
maxSize: tableRenderWidth,
|
|
472
|
+
table: tableNode,
|
|
473
|
+
tableRef: this.table,
|
|
474
|
+
start: start,
|
|
475
|
+
domAtPos: view.domAtPos,
|
|
476
|
+
isTableScalingEnabled: true
|
|
477
|
+
});
|
|
477
478
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
479
|
+
// Request animation frame required for Firefox
|
|
480
|
+
requestAnimationFrame(function () {
|
|
481
|
+
(0, _utils4.updateColgroup)(resizeState, _this2.table, tableNode, true);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
482
484
|
}
|
|
483
485
|
this.containerWidth = containerWidth;
|
|
484
486
|
}
|
|
@@ -494,7 +496,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
494
496
|
allowColumnResizing = _this$props10.allowColumnResizing,
|
|
495
497
|
isResizing = _this$props10.isResizing,
|
|
496
498
|
options = _this$props10.options,
|
|
497
|
-
isTableScalingEnabled = _this$props10.isTableScalingEnabled
|
|
499
|
+
isTableScalingEnabled = _this$props10.isTableScalingEnabled,
|
|
500
|
+
getPos = _this$props10.getPos;
|
|
498
501
|
var _getPluginState = (0, _pluginFactory.getPluginState)(view.state),
|
|
499
502
|
isInDanger = _getPluginState.isInDanger;
|
|
500
503
|
var table = (0, _utils2.findTable)(view.state.selection);
|
|
@@ -531,11 +534,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
531
534
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
532
535
|
// re-draw colgroup.
|
|
533
536
|
var previousTable = this.node;
|
|
534
|
-
|
|
537
|
+
var isNoOfColumnsChanged = (0, _utils5.tablesHaveDifferentNoOfColumns)(currentTable, previousTable);
|
|
538
|
+
if ((0, _utils5.tablesHaveDifferentColumnWidths)(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
535
539
|
var _view = this.props.view;
|
|
536
|
-
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing ||
|
|
540
|
+
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || isNoOfColumnsChanged && isResizing;
|
|
537
541
|
if (shouldRecreateResizeCols) {
|
|
538
|
-
(
|
|
542
|
+
var start = getPos() || 0;
|
|
543
|
+
var depth = _view.state.doc.resolve(start).depth;
|
|
544
|
+
var shouldScale = depth === 0 && isTableScalingEnabled;
|
|
545
|
+
(0, _utils4.insertColgroupFromNode)(this.table, currentTable, shouldScale);
|
|
539
546
|
}
|
|
540
547
|
(0, _dom.updateControls)()(_view.state);
|
|
541
548
|
}
|
|
@@ -44,6 +44,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
44
44
|
var $cell = state.doc.resolve(localResizeHandlePos);
|
|
45
45
|
var originalTable = $cell.node(-1);
|
|
46
46
|
var start = $cell.start(-1);
|
|
47
|
+
var tablePos = state.doc.resolve(start).start(-1);
|
|
48
|
+
var tableDepth = state.doc.resolve(tablePos).depth;
|
|
47
49
|
var dom = domAtPos(start).node;
|
|
48
50
|
if (dom && dom.nodeName !== 'TABLE') {
|
|
49
51
|
dom = dom.closest('table');
|
|
@@ -67,6 +69,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
67
69
|
getEditorContainerWidth: getEditorContainerWidth
|
|
68
70
|
});
|
|
69
71
|
}
|
|
72
|
+
var shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
70
73
|
var resizeState = (0, _utils3.getResizeState)({
|
|
71
74
|
minWidth: _styles.tableCellMinWidth,
|
|
72
75
|
maxSize: maxSize,
|
|
@@ -74,7 +77,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
74
77
|
tableRef: dom,
|
|
75
78
|
start: start,
|
|
76
79
|
domAtPos: domAtPos,
|
|
77
|
-
isTableScalingEnabled:
|
|
80
|
+
isTableScalingEnabled: shouldScale
|
|
78
81
|
});
|
|
79
82
|
if ((0, _commands.evenColumns)({
|
|
80
83
|
resizeState: resizeState,
|
|
@@ -116,6 +119,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
116
119
|
var $cell = state.doc.resolve(resizeHandlePos);
|
|
117
120
|
var start = $cell.start(-1);
|
|
118
121
|
var table = $cell.node(-1);
|
|
122
|
+
var tablePos = state.doc.resolve(start).start(-1);
|
|
123
|
+
var tableDepth = state.doc.resolve(tablePos).depth;
|
|
119
124
|
|
|
120
125
|
// If we let go in the same place we started, don't need to do anything.
|
|
121
126
|
if (dragging && clientX === dragging.startX) {
|
|
@@ -146,7 +151,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
146
151
|
var selectedColumns = selectionRect ? (0, _utils2.getSelectedColumnIndexes)(selectionRect) : [];
|
|
147
152
|
// only selected (or selected - 1) columns should be distributed
|
|
148
153
|
var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
|
|
149
|
-
var
|
|
154
|
+
var _shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
155
|
+
var newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
150
156
|
var resizedDelta = clientX - startX;
|
|
151
157
|
tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
|
|
152
158
|
if (colIndex === map.width - 1) {
|
|
@@ -207,9 +213,12 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
207
213
|
}
|
|
208
214
|
var $cell = state.doc.resolve(resizeHandlePos);
|
|
209
215
|
var table = $cell.node(-1);
|
|
216
|
+
var tablePos = state.doc.resolve(start).start(-1);
|
|
217
|
+
var tableDepth = state.doc.resolve(tablePos).depth;
|
|
210
218
|
var map = _tableMap.TableMap.get(table);
|
|
211
219
|
var colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
|
|
212
|
-
|
|
220
|
+
var shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
221
|
+
(0, _utils3.resizeColumn)(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
213
222
|
(0, _utils3.updateControls)()(state);
|
|
214
223
|
}
|
|
215
224
|
window.addEventListener('mouseup', finish);
|
|
@@ -4,13 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resizeColumn = void 0;
|
|
7
|
+
var _misc = require("./misc");
|
|
7
8
|
var _resizeLogic = require("./resize-logic");
|
|
8
9
|
var _resizeState = require("./resize-state");
|
|
9
10
|
// Resize a given column by an amount from the current state
|
|
10
11
|
|
|
11
12
|
var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
12
13
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
13
|
-
var
|
|
14
|
+
var scalePercent = 1;
|
|
15
|
+
var resizeAmount = amount;
|
|
16
|
+
if (isTableScalingEnabled) {
|
|
17
|
+
scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
|
|
18
|
+
resizeAmount = amount / scalePercent;
|
|
19
|
+
}
|
|
20
|
+
var newState = resizeAmount > 0 ? (0, _resizeLogic.growColumn)(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? (0, _resizeLogic.shrinkColumn)(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
|
|
14
21
|
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
15
22
|
return newState;
|
|
16
23
|
};
|
|
@@ -113,9 +113,10 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns() {
|
|
|
113
113
|
possibleMaxWidth: 0,
|
|
114
114
|
isResized: isResized
|
|
115
115
|
};
|
|
116
|
-
|
|
116
|
+
var tableDepth = view.state.doc.resolve(table.pos).depth;
|
|
117
|
+
var shouldScale = isTableScalingEnabled && tableDepth === 0;
|
|
118
|
+
if (shouldScale) {
|
|
117
119
|
previousTableInfo = {
|
|
118
|
-
// TODO - ensure correct width is returned when table doesn't have a width value
|
|
119
120
|
width: (0, _utils.getTableElementWidth)(table.node),
|
|
120
121
|
possibleMaxWidth: (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? (0, _utils.getTableContainerElementWidth)(table.node) : (0, _utils.getTableContainerElementWidth)(table.node) - _commonStyles.insertColumnButtonOffset,
|
|
121
122
|
isResized: isResized
|
|
@@ -175,7 +176,7 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns() {
|
|
|
175
176
|
tableRef: tableRef,
|
|
176
177
|
domAtPos: domAtPos,
|
|
177
178
|
maxSize: previousTableInfo.possibleMaxWidth,
|
|
178
|
-
isTableScalingEnabled:
|
|
179
|
+
isTableScalingEnabled: shouldScale
|
|
179
180
|
});
|
|
180
181
|
|
|
181
182
|
// Two scenarios that require scaling:
|
|
@@ -169,8 +169,7 @@ class TableComponent extends React.Component {
|
|
|
169
169
|
getNode,
|
|
170
170
|
getPos,
|
|
171
171
|
containerWidth,
|
|
172
|
-
options
|
|
173
|
-
isTableScalingEnabled
|
|
172
|
+
options
|
|
174
173
|
} = this.props;
|
|
175
174
|
const node = getNode();
|
|
176
175
|
const {
|
|
@@ -194,7 +193,7 @@ class TableComponent extends React.Component {
|
|
|
194
193
|
containerWidth: width,
|
|
195
194
|
previousContainerWidth: this.containerWidth.width || width,
|
|
196
195
|
...options
|
|
197
|
-
}, domAtPos,
|
|
196
|
+
}, domAtPos, false)(state.tr);
|
|
198
197
|
dispatch(tr);
|
|
199
198
|
});
|
|
200
199
|
_defineProperty(this, "setTimerToSendInitialOverflowCaptured", isOverflowing => {
|
|
@@ -419,7 +418,6 @@ class TableComponent extends React.Component {
|
|
|
419
418
|
}
|
|
420
419
|
}
|
|
421
420
|
handleColgroupUpdates(force = false) {
|
|
422
|
-
var _this$containerWidth;
|
|
423
421
|
const {
|
|
424
422
|
getNode,
|
|
425
423
|
containerWidth,
|
|
@@ -437,32 +435,36 @@ class TableComponent extends React.Component {
|
|
|
437
435
|
const tableNode = getNode();
|
|
438
436
|
const start = getPos() || 0;
|
|
439
437
|
const depth = view.state.doc.resolve(start).depth;
|
|
440
|
-
|
|
441
|
-
// TODO - remove this when support is added for nested tables
|
|
442
438
|
if (depth !== 0) {
|
|
443
439
|
return;
|
|
444
440
|
}
|
|
445
441
|
const tableNodeWidth = getTableContainerWidth(tableNode);
|
|
446
442
|
const shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
443
|
+
if (force || shouldTableScale) {
|
|
444
|
+
var _this$containerWidth;
|
|
445
|
+
const {
|
|
446
|
+
width: containerWidthValue
|
|
447
|
+
} = containerWidth;
|
|
448
|
+
const isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
|
|
449
|
+
const wasTableResized = hasTableBeenResized(this.node);
|
|
450
|
+
const isTableResied = hasTableBeenResized(tableNode);
|
|
451
|
+
const isColumnsDistributed = wasTableResized && !isTableResied;
|
|
452
|
+
if (force || !isResizing && (isWidthChanged || isColumnsDistributed)) {
|
|
453
|
+
const resizeState = getResizeState({
|
|
454
|
+
minWidth: COLUMN_MIN_WIDTH,
|
|
455
|
+
maxSize: tableRenderWidth,
|
|
456
|
+
table: tableNode,
|
|
457
|
+
tableRef: this.table,
|
|
458
|
+
start,
|
|
459
|
+
domAtPos: view.domAtPos,
|
|
460
|
+
isTableScalingEnabled: true
|
|
461
|
+
});
|
|
461
462
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
// Request animation frame required for Firefox
|
|
464
|
+
requestAnimationFrame(() => {
|
|
465
|
+
updateColgroup(resizeState, this.table, tableNode, true);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
466
468
|
}
|
|
467
469
|
this.containerWidth = containerWidth;
|
|
468
470
|
}
|
|
@@ -475,7 +477,8 @@ class TableComponent extends React.Component {
|
|
|
475
477
|
allowColumnResizing,
|
|
476
478
|
isResizing,
|
|
477
479
|
options,
|
|
478
|
-
isTableScalingEnabled
|
|
480
|
+
isTableScalingEnabled,
|
|
481
|
+
getPos
|
|
479
482
|
} = this.props;
|
|
480
483
|
const {
|
|
481
484
|
isInDanger
|
|
@@ -514,13 +517,17 @@ class TableComponent extends React.Component {
|
|
|
514
517
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
515
518
|
// re-draw colgroup.
|
|
516
519
|
const previousTable = this.node;
|
|
517
|
-
|
|
520
|
+
const isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(currentTable, previousTable);
|
|
521
|
+
if (tablesHaveDifferentColumnWidths(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
518
522
|
const {
|
|
519
523
|
view
|
|
520
524
|
} = this.props;
|
|
521
|
-
const shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing ||
|
|
525
|
+
const shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || isNoOfColumnsChanged && isResizing;
|
|
522
526
|
if (shouldRecreateResizeCols) {
|
|
523
|
-
|
|
527
|
+
const start = getPos() || 0;
|
|
528
|
+
const depth = view.state.doc.resolve(start).depth;
|
|
529
|
+
const shouldScale = depth === 0 && isTableScalingEnabled;
|
|
530
|
+
insertColgroupFromNode(this.table, currentTable, shouldScale);
|
|
524
531
|
}
|
|
525
532
|
updateControls()(view.state);
|
|
526
533
|
}
|
|
@@ -41,6 +41,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
41
41
|
const $cell = state.doc.resolve(localResizeHandlePos);
|
|
42
42
|
const originalTable = $cell.node(-1);
|
|
43
43
|
const start = $cell.start(-1);
|
|
44
|
+
const tablePos = state.doc.resolve(start).start(-1);
|
|
45
|
+
const tableDepth = state.doc.resolve(tablePos).depth;
|
|
44
46
|
let dom = domAtPos(start).node;
|
|
45
47
|
if (dom && dom.nodeName !== 'TABLE') {
|
|
46
48
|
dom = dom.closest('table');
|
|
@@ -64,6 +66,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
64
66
|
getEditorContainerWidth
|
|
65
67
|
});
|
|
66
68
|
}
|
|
69
|
+
const shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
67
70
|
const resizeState = getResizeState({
|
|
68
71
|
minWidth: tableCellMinWidth,
|
|
69
72
|
maxSize,
|
|
@@ -71,7 +74,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
71
74
|
tableRef: dom,
|
|
72
75
|
start,
|
|
73
76
|
domAtPos,
|
|
74
|
-
isTableScalingEnabled:
|
|
77
|
+
isTableScalingEnabled: shouldScale
|
|
75
78
|
});
|
|
76
79
|
if (evenColumns({
|
|
77
80
|
resizeState,
|
|
@@ -119,6 +122,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
119
122
|
const $cell = state.doc.resolve(resizeHandlePos);
|
|
120
123
|
const start = $cell.start(-1);
|
|
121
124
|
const table = $cell.node(-1);
|
|
125
|
+
const tablePos = state.doc.resolve(start).start(-1);
|
|
126
|
+
const tableDepth = state.doc.resolve(tablePos).depth;
|
|
122
127
|
|
|
123
128
|
// If we let go in the same place we started, don't need to do anything.
|
|
124
129
|
if (dragging && clientX === dragging.startX) {
|
|
@@ -153,7 +158,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
153
158
|
const selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
154
159
|
// only selected (or selected - 1) columns should be distributed
|
|
155
160
|
const resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
|
|
156
|
-
const
|
|
161
|
+
const shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
162
|
+
const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
|
|
157
163
|
const resizedDelta = clientX - startX;
|
|
158
164
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
159
165
|
if (colIndex === map.width - 1) {
|
|
@@ -220,9 +226,12 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
220
226
|
}
|
|
221
227
|
const $cell = state.doc.resolve(resizeHandlePos);
|
|
222
228
|
const table = $cell.node(-1);
|
|
229
|
+
const tablePos = state.doc.resolve(start).start(-1);
|
|
230
|
+
const tableDepth = state.doc.resolve(tablePos).depth;
|
|
223
231
|
const map = TableMap.get(table);
|
|
224
232
|
const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
|
|
225
|
-
|
|
233
|
+
const shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
234
|
+
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
226
235
|
updateControls()(state);
|
|
227
236
|
}
|
|
228
237
|
window.addEventListener('mouseup', finish);
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
|
|
3
|
+
import { getTableScalingPercent } from './misc';
|
|
3
4
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
4
5
|
import { updateColgroup } from './resize-state';
|
|
5
6
|
export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false) => {
|
|
6
|
-
|
|
7
|
+
let scalePercent = 1;
|
|
8
|
+
let resizeAmount = amount;
|
|
9
|
+
if (isTableScalingEnabled) {
|
|
10
|
+
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
11
|
+
resizeAmount = amount / scalePercent;
|
|
12
|
+
}
|
|
13
|
+
const newState = resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
|
|
7
14
|
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
8
15
|
return newState;
|
|
9
16
|
};
|
|
@@ -102,9 +102,10 @@ export const rescaleColumns = (isTableScalingEnabled = false) => (table, view) =
|
|
|
102
102
|
possibleMaxWidth: 0,
|
|
103
103
|
isResized
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
const tableDepth = view.state.doc.resolve(table.pos).depth;
|
|
106
|
+
const shouldScale = isTableScalingEnabled && tableDepth === 0;
|
|
107
|
+
if (shouldScale) {
|
|
106
108
|
previousTableInfo = {
|
|
107
|
-
// TODO - ensure correct width is returned when table doesn't have a width value
|
|
108
109
|
width: getTableElementWidth(table.node),
|
|
109
110
|
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? getTableContainerElementWidth(table.node) : getTableContainerElementWidth(table.node) - insertColumnButtonOffset,
|
|
110
111
|
isResized
|
|
@@ -162,7 +163,7 @@ export const rescaleColumns = (isTableScalingEnabled = false) => (table, view) =
|
|
|
162
163
|
tableRef,
|
|
163
164
|
domAtPos,
|
|
164
165
|
maxSize: previousTableInfo.possibleMaxWidth,
|
|
165
|
-
isTableScalingEnabled
|
|
166
|
+
isTableScalingEnabled: shouldScale
|
|
166
167
|
});
|
|
167
168
|
|
|
168
169
|
// Two scenarios that require scaling:
|
|
@@ -178,8 +178,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
178
178
|
getNode = _this$props2.getNode,
|
|
179
179
|
getPos = _this$props2.getPos,
|
|
180
180
|
containerWidth = _this$props2.containerWidth,
|
|
181
|
-
options = _this$props2.options
|
|
182
|
-
isTableScalingEnabled = _this$props2.isTableScalingEnabled;
|
|
181
|
+
options = _this$props2.options;
|
|
183
182
|
var node = getNode();
|
|
184
183
|
var state = view.state,
|
|
185
184
|
dispatch = view.dispatch;
|
|
@@ -196,7 +195,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
196
195
|
start: pos + 1,
|
|
197
196
|
containerWidth: width,
|
|
198
197
|
previousContainerWidth: _this.containerWidth.width || width
|
|
199
|
-
}, options), domAtPos,
|
|
198
|
+
}, options), domAtPos, false)(state.tr);
|
|
200
199
|
dispatch(tr);
|
|
201
200
|
});
|
|
202
201
|
_defineProperty(_assertThisInitialized(_this), "setTimerToSendInitialOverflowCaptured", function (isOverflowing) {
|
|
@@ -429,8 +428,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
429
428
|
}, {
|
|
430
429
|
key: "handleColgroupUpdates",
|
|
431
430
|
value: function handleColgroupUpdates() {
|
|
432
|
-
var
|
|
433
|
-
_this2 = this;
|
|
431
|
+
var _this2 = this;
|
|
434
432
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
435
433
|
var _this$props9 = this.props,
|
|
436
434
|
getNode = _this$props9.getNode,
|
|
@@ -448,30 +446,34 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
448
446
|
var tableNode = getNode();
|
|
449
447
|
var start = getPos() || 0;
|
|
450
448
|
var depth = view.state.doc.resolve(start).depth;
|
|
451
|
-
|
|
452
|
-
// TODO - remove this when support is added for nested tables
|
|
453
449
|
if (depth !== 0) {
|
|
454
450
|
return;
|
|
455
451
|
}
|
|
456
452
|
var tableNodeWidth = getTableContainerWidth(tableNode);
|
|
457
453
|
var shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
var
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
454
|
+
if (force || shouldTableScale) {
|
|
455
|
+
var _this$containerWidth;
|
|
456
|
+
var containerWidthValue = containerWidth.width;
|
|
457
|
+
var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
|
|
458
|
+
var wasTableResized = hasTableBeenResized(this.node);
|
|
459
|
+
var isTableResied = hasTableBeenResized(tableNode);
|
|
460
|
+
var isColumnsDistributed = wasTableResized && !isTableResied;
|
|
461
|
+
if (force || !isResizing && (isWidthChanged || isColumnsDistributed)) {
|
|
462
|
+
var resizeState = getResizeState({
|
|
463
|
+
minWidth: COLUMN_MIN_WIDTH,
|
|
464
|
+
maxSize: tableRenderWidth,
|
|
465
|
+
table: tableNode,
|
|
466
|
+
tableRef: this.table,
|
|
467
|
+
start: start,
|
|
468
|
+
domAtPos: view.domAtPos,
|
|
469
|
+
isTableScalingEnabled: true
|
|
470
|
+
});
|
|
470
471
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
472
|
+
// Request animation frame required for Firefox
|
|
473
|
+
requestAnimationFrame(function () {
|
|
474
|
+
updateColgroup(resizeState, _this2.table, tableNode, true);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
475
477
|
}
|
|
476
478
|
this.containerWidth = containerWidth;
|
|
477
479
|
}
|
|
@@ -487,7 +489,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
487
489
|
allowColumnResizing = _this$props10.allowColumnResizing,
|
|
488
490
|
isResizing = _this$props10.isResizing,
|
|
489
491
|
options = _this$props10.options,
|
|
490
|
-
isTableScalingEnabled = _this$props10.isTableScalingEnabled
|
|
492
|
+
isTableScalingEnabled = _this$props10.isTableScalingEnabled,
|
|
493
|
+
getPos = _this$props10.getPos;
|
|
491
494
|
var _getPluginState = getPluginState(view.state),
|
|
492
495
|
isInDanger = _getPluginState.isInDanger;
|
|
493
496
|
var table = findTable(view.state.selection);
|
|
@@ -524,11 +527,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
524
527
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
525
528
|
// re-draw colgroup.
|
|
526
529
|
var previousTable = this.node;
|
|
527
|
-
|
|
530
|
+
var isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(currentTable, previousTable);
|
|
531
|
+
if (tablesHaveDifferentColumnWidths(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
528
532
|
var _view = this.props.view;
|
|
529
|
-
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing ||
|
|
533
|
+
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || isNoOfColumnsChanged && isResizing;
|
|
530
534
|
if (shouldRecreateResizeCols) {
|
|
531
|
-
|
|
535
|
+
var start = getPos() || 0;
|
|
536
|
+
var depth = _view.state.doc.resolve(start).depth;
|
|
537
|
+
var shouldScale = depth === 0 && isTableScalingEnabled;
|
|
538
|
+
insertColgroupFromNode(this.table, currentTable, shouldScale);
|
|
532
539
|
}
|
|
533
540
|
updateControls()(_view.state);
|
|
534
541
|
}
|
|
@@ -38,6 +38,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
38
38
|
var $cell = state.doc.resolve(localResizeHandlePos);
|
|
39
39
|
var originalTable = $cell.node(-1);
|
|
40
40
|
var start = $cell.start(-1);
|
|
41
|
+
var tablePos = state.doc.resolve(start).start(-1);
|
|
42
|
+
var tableDepth = state.doc.resolve(tablePos).depth;
|
|
41
43
|
var dom = domAtPos(start).node;
|
|
42
44
|
if (dom && dom.nodeName !== 'TABLE') {
|
|
43
45
|
dom = dom.closest('table');
|
|
@@ -61,6 +63,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
61
63
|
getEditorContainerWidth: getEditorContainerWidth
|
|
62
64
|
});
|
|
63
65
|
}
|
|
66
|
+
var shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
64
67
|
var resizeState = getResizeState({
|
|
65
68
|
minWidth: tableCellMinWidth,
|
|
66
69
|
maxSize: maxSize,
|
|
@@ -68,7 +71,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
68
71
|
tableRef: dom,
|
|
69
72
|
start: start,
|
|
70
73
|
domAtPos: domAtPos,
|
|
71
|
-
isTableScalingEnabled:
|
|
74
|
+
isTableScalingEnabled: shouldScale
|
|
72
75
|
});
|
|
73
76
|
if (evenColumns({
|
|
74
77
|
resizeState: resizeState,
|
|
@@ -110,6 +113,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
110
113
|
var $cell = state.doc.resolve(resizeHandlePos);
|
|
111
114
|
var start = $cell.start(-1);
|
|
112
115
|
var table = $cell.node(-1);
|
|
116
|
+
var tablePos = state.doc.resolve(start).start(-1);
|
|
117
|
+
var tableDepth = state.doc.resolve(tablePos).depth;
|
|
113
118
|
|
|
114
119
|
// If we let go in the same place we started, don't need to do anything.
|
|
115
120
|
if (dragging && clientX === dragging.startX) {
|
|
@@ -140,7 +145,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
140
145
|
var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
141
146
|
// only selected (or selected - 1) columns should be distributed
|
|
142
147
|
var resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
|
|
143
|
-
var
|
|
148
|
+
var _shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
149
|
+
var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
|
|
144
150
|
var resizedDelta = clientX - startX;
|
|
145
151
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
146
152
|
if (colIndex === map.width - 1) {
|
|
@@ -201,9 +207,12 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
201
207
|
}
|
|
202
208
|
var $cell = state.doc.resolve(resizeHandlePos);
|
|
203
209
|
var table = $cell.node(-1);
|
|
210
|
+
var tablePos = state.doc.resolve(start).start(-1);
|
|
211
|
+
var tableDepth = state.doc.resolve(tablePos).depth;
|
|
204
212
|
var map = TableMap.get(table);
|
|
205
213
|
var colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
|
|
206
|
-
|
|
214
|
+
var shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
215
|
+
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
|
|
207
216
|
updateControls()(state);
|
|
208
217
|
}
|
|
209
218
|
window.addEventListener('mouseup', finish);
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
|
|
3
|
+
import { getTableScalingPercent } from './misc';
|
|
3
4
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
4
5
|
import { updateColgroup } from './resize-state';
|
|
5
6
|
export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
|
|
6
7
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
7
|
-
var
|
|
8
|
+
var scalePercent = 1;
|
|
9
|
+
var resizeAmount = amount;
|
|
10
|
+
if (isTableScalingEnabled) {
|
|
11
|
+
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
12
|
+
resizeAmount = amount / scalePercent;
|
|
13
|
+
}
|
|
14
|
+
var newState = resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
|
|
8
15
|
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
9
16
|
return newState;
|
|
10
17
|
};
|
|
@@ -107,9 +107,10 @@ export var rescaleColumns = function rescaleColumns() {
|
|
|
107
107
|
possibleMaxWidth: 0,
|
|
108
108
|
isResized: isResized
|
|
109
109
|
};
|
|
110
|
-
|
|
110
|
+
var tableDepth = view.state.doc.resolve(table.pos).depth;
|
|
111
|
+
var shouldScale = isTableScalingEnabled && tableDepth === 0;
|
|
112
|
+
if (shouldScale) {
|
|
111
113
|
previousTableInfo = {
|
|
112
|
-
// TODO - ensure correct width is returned when table doesn't have a width value
|
|
113
114
|
width: getTableElementWidth(table.node),
|
|
114
115
|
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width') ? getTableContainerElementWidth(table.node) : getTableContainerElementWidth(table.node) - insertColumnButtonOffset,
|
|
115
116
|
isResized: isResized
|
|
@@ -169,7 +170,7 @@ export var rescaleColumns = function rescaleColumns() {
|
|
|
169
170
|
tableRef: tableRef,
|
|
170
171
|
domAtPos: domAtPos,
|
|
171
172
|
maxSize: previousTableInfo.possibleMaxWidth,
|
|
172
|
-
isTableScalingEnabled:
|
|
173
|
+
isTableScalingEnabled: shouldScale
|
|
173
174
|
});
|
|
174
175
|
|
|
175
176
|
// Two scenarios that require scaling:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.10",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^35.6.0",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.0.15",
|
|
33
|
-
"@atlaskit/editor-common": "^78.
|
|
33
|
+
"@atlaskit/editor-common": "^78.14.0",
|
|
34
34
|
"@atlaskit/editor-palette": "1.5.2",
|
|
35
35
|
"@atlaskit/editor-plugin-analytics": "^1.0.0",
|
|
36
36
|
"@atlaskit/editor-plugin-content-insertion": "^1.0.0",
|
|
@@ -333,32 +333,36 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
333
333
|
const start = getPos() || 0;
|
|
334
334
|
const depth = view.state.doc.resolve(start).depth;
|
|
335
335
|
|
|
336
|
-
// TODO - remove this when support is added for nested tables
|
|
337
336
|
if (depth !== 0) {
|
|
338
337
|
return;
|
|
339
338
|
}
|
|
340
339
|
|
|
341
340
|
const tableNodeWidth = getTableContainerWidth(tableNode);
|
|
342
341
|
const shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
342
|
+
if (force || shouldTableScale) {
|
|
343
|
+
const { width: containerWidthValue } = containerWidth;
|
|
344
|
+
const isWidthChanged = this.containerWidth?.width !== containerWidthValue;
|
|
345
|
+
|
|
346
|
+
const wasTableResized = hasTableBeenResized(this.node);
|
|
347
|
+
const isTableResied = hasTableBeenResized(tableNode);
|
|
348
|
+
const isColumnsDistributed = wasTableResized && !isTableResied;
|
|
349
|
+
|
|
350
|
+
if (force || (!isResizing && (isWidthChanged || isColumnsDistributed))) {
|
|
351
|
+
const resizeState = getResizeState({
|
|
352
|
+
minWidth: COLUMN_MIN_WIDTH,
|
|
353
|
+
maxSize: tableRenderWidth,
|
|
354
|
+
table: tableNode,
|
|
355
|
+
tableRef: this.table,
|
|
356
|
+
start,
|
|
357
|
+
domAtPos: view.domAtPos,
|
|
358
|
+
isTableScalingEnabled: true,
|
|
359
|
+
});
|
|
343
360
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
minWidth: COLUMN_MIN_WIDTH,
|
|
350
|
-
maxSize: tableRenderWidth,
|
|
351
|
-
table: tableNode,
|
|
352
|
-
tableRef: this.table,
|
|
353
|
-
start,
|
|
354
|
-
domAtPos: view.domAtPos,
|
|
355
|
-
isTableScalingEnabled: true,
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// Request animation frame required for Firefox
|
|
359
|
-
requestAnimationFrame(() => {
|
|
360
|
-
updateColgroup(resizeState, this.table!, tableNode, true);
|
|
361
|
-
});
|
|
361
|
+
// Request animation frame required for Firefox
|
|
362
|
+
requestAnimationFrame(() => {
|
|
363
|
+
updateColgroup(resizeState, this.table!, tableNode, true);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
362
366
|
}
|
|
363
367
|
this.containerWidth = containerWidth;
|
|
364
368
|
}
|
|
@@ -372,6 +376,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
372
376
|
isResizing,
|
|
373
377
|
options,
|
|
374
378
|
isTableScalingEnabled,
|
|
379
|
+
getPos,
|
|
375
380
|
} = this.props;
|
|
376
381
|
const { isInDanger } = getPluginState(view.state);
|
|
377
382
|
const table = findTable(view.state.selection);
|
|
@@ -426,24 +431,26 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
426
431
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
427
432
|
// re-draw colgroup.
|
|
428
433
|
const previousTable = this.node;
|
|
434
|
+
const isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(
|
|
435
|
+
currentTable,
|
|
436
|
+
previousTable,
|
|
437
|
+
);
|
|
429
438
|
if (
|
|
430
439
|
tablesHaveDifferentColumnWidths(currentTable, previousTable) ||
|
|
431
|
-
|
|
440
|
+
isNoOfColumnsChanged
|
|
432
441
|
) {
|
|
433
442
|
const { view } = this.props;
|
|
434
443
|
|
|
435
444
|
const shouldRecreateResizeCols =
|
|
436
445
|
!options?.isTableResizingEnabled ||
|
|
437
446
|
!isResizing ||
|
|
438
|
-
(
|
|
439
|
-
isResizing);
|
|
447
|
+
(isNoOfColumnsChanged && isResizing);
|
|
440
448
|
|
|
441
449
|
if (shouldRecreateResizeCols) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
);
|
|
450
|
+
const start = getPos() || 0;
|
|
451
|
+
const depth = view.state.doc.resolve(start).depth;
|
|
452
|
+
const shouldScale = depth === 0 && isTableScalingEnabled;
|
|
453
|
+
insertColgroupFromNode(this.table, currentTable, shouldScale);
|
|
447
454
|
}
|
|
448
455
|
|
|
449
456
|
updateControls()(view.state);
|
|
@@ -888,14 +895,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
888
895
|
layoutChanged: boolean;
|
|
889
896
|
parentWidth?: number;
|
|
890
897
|
}) => {
|
|
891
|
-
const {
|
|
892
|
-
view,
|
|
893
|
-
getNode,
|
|
894
|
-
getPos,
|
|
895
|
-
containerWidth,
|
|
896
|
-
options,
|
|
897
|
-
isTableScalingEnabled,
|
|
898
|
-
} = this.props;
|
|
898
|
+
const { view, getNode, getPos, containerWidth, options } = this.props;
|
|
899
899
|
const node = getNode();
|
|
900
900
|
const { state, dispatch } = view;
|
|
901
901
|
const pos = getPos();
|
|
@@ -920,7 +920,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
920
920
|
...options,
|
|
921
921
|
},
|
|
922
922
|
domAtPos,
|
|
923
|
-
|
|
923
|
+
false,
|
|
924
924
|
)(state.tr);
|
|
925
925
|
|
|
926
926
|
dispatch(tr);
|
|
@@ -72,6 +72,8 @@ export const handleMouseDown = (
|
|
|
72
72
|
const $cell = state.doc.resolve(localResizeHandlePos);
|
|
73
73
|
const originalTable = $cell.node(-1);
|
|
74
74
|
const start = $cell.start(-1);
|
|
75
|
+
const tablePos = state.doc.resolve(start).start(-1);
|
|
76
|
+
const tableDepth = state.doc.resolve(tablePos).depth;
|
|
75
77
|
|
|
76
78
|
let dom: HTMLTableElement = domAtPos(start).node as HTMLTableElement;
|
|
77
79
|
if (dom && dom.nodeName !== 'TABLE') {
|
|
@@ -112,6 +114,7 @@ export const handleMouseDown = (
|
|
|
112
114
|
});
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
const shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
115
118
|
const resizeState = getResizeState({
|
|
116
119
|
minWidth: tableCellMinWidth,
|
|
117
120
|
maxSize,
|
|
@@ -119,7 +122,7 @@ export const handleMouseDown = (
|
|
|
119
122
|
tableRef: dom,
|
|
120
123
|
start,
|
|
121
124
|
domAtPos,
|
|
122
|
-
isTableScalingEnabled:
|
|
125
|
+
isTableScalingEnabled: shouldScale,
|
|
123
126
|
});
|
|
124
127
|
|
|
125
128
|
if (
|
|
@@ -166,6 +169,8 @@ export const handleMouseDown = (
|
|
|
166
169
|
const $cell = state.doc.resolve(resizeHandlePos);
|
|
167
170
|
const start = $cell.start(-1);
|
|
168
171
|
const table = $cell.node(-1);
|
|
172
|
+
const tablePos = state.doc.resolve(start).start(-1);
|
|
173
|
+
const tableDepth = state.doc.resolve(tablePos).depth;
|
|
169
174
|
|
|
170
175
|
// If we let go in the same place we started, don't need to do anything.
|
|
171
176
|
if (dragging && clientX === dragging.startX) {
|
|
@@ -204,6 +209,8 @@ export const handleMouseDown = (
|
|
|
204
209
|
const resizingSelectedColumns =
|
|
205
210
|
selectedColumns.indexOf(colIndex) > -1 ||
|
|
206
211
|
selectedColumns.indexOf(colIndex + 1) > -1;
|
|
212
|
+
|
|
213
|
+
const shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
207
214
|
const newResizeState = resizeColumn(
|
|
208
215
|
resizeState,
|
|
209
216
|
colIndex,
|
|
@@ -211,7 +218,7 @@ export const handleMouseDown = (
|
|
|
211
218
|
dom,
|
|
212
219
|
originalTable,
|
|
213
220
|
resizingSelectedColumns ? selectedColumns : undefined,
|
|
214
|
-
|
|
221
|
+
shouldScale,
|
|
215
222
|
);
|
|
216
223
|
|
|
217
224
|
const resizedDelta = clientX - startX;
|
|
@@ -282,12 +289,15 @@ export const handleMouseDown = (
|
|
|
282
289
|
|
|
283
290
|
const $cell = state.doc.resolve(resizeHandlePos);
|
|
284
291
|
const table = $cell.node(-1);
|
|
292
|
+
const tablePos = state.doc.resolve(start).start(-1);
|
|
293
|
+
const tableDepth = state.doc.resolve(tablePos).depth;
|
|
285
294
|
const map = TableMap.get(table);
|
|
286
295
|
const colIndex =
|
|
287
296
|
map.colCount($cell.pos - $cell.start(-1)) +
|
|
288
297
|
$cell.nodeAfter!.attrs.colspan -
|
|
289
298
|
1;
|
|
290
299
|
|
|
300
|
+
const shouldScale = tableDepth === 0 && isTableScalingEnabled;
|
|
291
301
|
resizeColumn(
|
|
292
302
|
resizeState,
|
|
293
303
|
colIndex,
|
|
@@ -295,7 +305,7 @@ export const handleMouseDown = (
|
|
|
295
305
|
dom,
|
|
296
306
|
table,
|
|
297
307
|
undefined,
|
|
298
|
-
|
|
308
|
+
shouldScale,
|
|
299
309
|
);
|
|
300
310
|
|
|
301
311
|
updateControls()(state);
|
|
@@ -1,6 +1,7 @@
|
|
|
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
3
|
|
|
4
|
+
import { getTableScalingPercent } from './misc';
|
|
4
5
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
5
6
|
import { updateColgroup } from './resize-state';
|
|
6
7
|
import type { ResizeState } from './types';
|
|
@@ -14,11 +15,18 @@ export const resizeColumn = (
|
|
|
14
15
|
selectedColumns?: number[],
|
|
15
16
|
isTableScalingEnabled = false,
|
|
16
17
|
): ResizeState => {
|
|
18
|
+
let scalePercent = 1;
|
|
19
|
+
let resizeAmount = amount;
|
|
20
|
+
|
|
21
|
+
if (isTableScalingEnabled) {
|
|
22
|
+
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
23
|
+
resizeAmount = amount / scalePercent;
|
|
24
|
+
}
|
|
17
25
|
const newState =
|
|
18
|
-
|
|
19
|
-
? growColumn(resizeState, colIndex,
|
|
20
|
-
:
|
|
21
|
-
? shrinkColumn(resizeState, colIndex,
|
|
26
|
+
resizeAmount > 0
|
|
27
|
+
? growColumn(resizeState, colIndex, resizeAmount, selectedColumns)
|
|
28
|
+
: resizeAmount < 0
|
|
29
|
+
? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns)
|
|
22
30
|
: resizeState;
|
|
23
31
|
|
|
24
32
|
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
@@ -132,9 +132,10 @@ export const rescaleColumns =
|
|
|
132
132
|
isResized,
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
const tableDepth = view.state.doc.resolve(table.pos).depth;
|
|
136
|
+
const shouldScale = isTableScalingEnabled && tableDepth === 0;
|
|
137
|
+
if (shouldScale) {
|
|
136
138
|
previousTableInfo = {
|
|
137
|
-
// TODO - ensure correct width is returned when table doesn't have a width value
|
|
138
139
|
width: getTableElementWidth(table.node),
|
|
139
140
|
possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width')
|
|
140
141
|
? getTableContainerElementWidth(table.node)
|
|
@@ -217,7 +218,7 @@ export const rescaleColumns =
|
|
|
217
218
|
tableRef,
|
|
218
219
|
domAtPos,
|
|
219
220
|
maxSize: previousTableInfo.possibleMaxWidth,
|
|
220
|
-
isTableScalingEnabled,
|
|
221
|
+
isTableScalingEnabled: shouldScale,
|
|
221
222
|
});
|
|
222
223
|
|
|
223
224
|
// Two scenarios that require scaling:
|