@atlaskit/editor-plugin-table 7.5.9 → 7.5.11
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 +32 -24
- package/dist/cjs/plugin.js +4 -2
- package/dist/cjs/pm-plugins/keymap.js +4 -3
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -3
- package/dist/cjs/transforms/column-width.js +4 -3
- package/dist/cjs/ui/icons/DragHandleDisabledIcon.js +2 -1
- package/dist/cjs/ui/icons/DragHandleIcon.js +2 -1
- package/dist/es2019/nodeviews/TableComponent.js +33 -25
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/pm-plugins/keymap.js +4 -4
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +12 -3
- package/dist/es2019/transforms/column-width.js +4 -3
- package/dist/es2019/ui/icons/DragHandleDisabledIcon.js +2 -1
- package/dist/es2019/ui/icons/DragHandleIcon.js +2 -1
- package/dist/esm/nodeviews/TableComponent.js +32 -24
- package/dist/esm/plugin.js +4 -2
- package/dist/esm/pm-plugins/keymap.js +4 -3
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -3
- package/dist/esm/transforms/column-width.js +4 -3
- package/dist/esm/ui/icons/DragHandleDisabledIcon.js +2 -1
- package/dist/esm/ui/icons/DragHandleIcon.js +2 -1
- package/dist/types/pm-plugins/keymap.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
- package/package.json +3 -3
- package/src/nodeviews/TableComponent.tsx +34 -27
- package/src/plugin.tsx +6 -3
- package/src/pm-plugins/keymap.ts +11 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +13 -3
- package/src/transforms/column-width.ts +4 -3
- package/src/ui/icons/DragHandleDisabledIcon.tsx +1 -0
- package/src/ui/icons/DragHandleIcon.tsx +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.5.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#82119](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/82119) [`0358b8d41041`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0358b8d41041) - insert table at full width via shortcut in full width page
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 7.5.10
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#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
|
|
15
|
+
|
|
3
16
|
## 7.5.9
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -435,8 +435,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
435
435
|
}, {
|
|
436
436
|
key: "handleColgroupUpdates",
|
|
437
437
|
value: function handleColgroupUpdates() {
|
|
438
|
-
var
|
|
439
|
-
_this2 = this;
|
|
438
|
+
var _this2 = this;
|
|
440
439
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
441
440
|
var _this$props9 = this.props,
|
|
442
441
|
getNode = _this$props9.getNode,
|
|
@@ -454,30 +453,34 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
454
453
|
var tableNode = getNode();
|
|
455
454
|
var start = getPos() || 0;
|
|
456
455
|
var depth = view.state.doc.resolve(start).depth;
|
|
457
|
-
|
|
458
|
-
// TODO - remove this when support is added for nested tables
|
|
459
456
|
if (depth !== 0) {
|
|
460
457
|
return;
|
|
461
458
|
}
|
|
462
459
|
var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(tableNode);
|
|
463
460
|
var shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
var
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
+
});
|
|
476
478
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
// Request animation frame required for Firefox
|
|
480
|
+
requestAnimationFrame(function () {
|
|
481
|
+
(0, _utils4.updateColgroup)(resizeState, _this2.table, tableNode, true);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
481
484
|
}
|
|
482
485
|
this.containerWidth = containerWidth;
|
|
483
486
|
}
|
|
@@ -493,7 +496,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
493
496
|
allowColumnResizing = _this$props10.allowColumnResizing,
|
|
494
497
|
isResizing = _this$props10.isResizing,
|
|
495
498
|
options = _this$props10.options,
|
|
496
|
-
isTableScalingEnabled = _this$props10.isTableScalingEnabled
|
|
499
|
+
isTableScalingEnabled = _this$props10.isTableScalingEnabled,
|
|
500
|
+
getPos = _this$props10.getPos;
|
|
497
501
|
var _getPluginState = (0, _pluginFactory.getPluginState)(view.state),
|
|
498
502
|
isInDanger = _getPluginState.isInDanger;
|
|
499
503
|
var table = (0, _utils2.findTable)(view.state.selection);
|
|
@@ -530,11 +534,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
530
534
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
531
535
|
// re-draw colgroup.
|
|
532
536
|
var previousTable = this.node;
|
|
533
|
-
|
|
537
|
+
var isNoOfColumnsChanged = (0, _utils5.tablesHaveDifferentNoOfColumns)(currentTable, previousTable);
|
|
538
|
+
if ((0, _utils5.tablesHaveDifferentColumnWidths)(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
534
539
|
var _view = this.props.view;
|
|
535
|
-
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing ||
|
|
540
|
+
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || isNoOfColumnsChanged && isResizing;
|
|
536
541
|
if (shouldRecreateResizeCols) {
|
|
537
|
-
(
|
|
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);
|
|
538
546
|
}
|
|
539
547
|
(0, _dom.updateControls)()(_view.state);
|
|
540
548
|
}
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -157,8 +157,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
157
157
|
var _ref6 = options || {},
|
|
158
158
|
dragAndDropEnabled = _ref6.dragAndDropEnabled,
|
|
159
159
|
_ref6$isTableScalingE = _ref6.isTableScalingEnabled,
|
|
160
|
-
isTableScalingEnabled = _ref6$isTableScalingE === void 0 ? false : _ref6$isTableScalingE
|
|
161
|
-
|
|
160
|
+
isTableScalingEnabled = _ref6$isTableScalingE === void 0 ? false : _ref6$isTableScalingE,
|
|
161
|
+
_ref6$fullWidthEnable = _ref6.fullWidthEnabled,
|
|
162
|
+
fullWidthEnabled = _ref6$fullWidthEnable === void 0 ? false : _ref6$fullWidthEnable;
|
|
163
|
+
return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, fullWidthEnabled);
|
|
162
164
|
}
|
|
163
165
|
}, {
|
|
164
166
|
name: 'tableSelectionKeymap',
|
|
@@ -16,7 +16,7 @@ var _columnResize = require("../commands/column-resize");
|
|
|
16
16
|
var _insert = require("../commands/insert");
|
|
17
17
|
var _commandsWithAnalytics2 = require("../pm-plugins/drag-and-drop/commands-with-analytics");
|
|
18
18
|
var _analytics2 = require("../utils/analytics");
|
|
19
|
-
var createTableWithAnalytics = function createTableWithAnalytics(editorAnalyticsAPI) {
|
|
19
|
+
var createTableWithAnalytics = function createTableWithAnalytics(isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
|
|
20
20
|
return (0, _analytics2.withEditorAnalyticsAPI)({
|
|
21
21
|
action: _analytics.ACTION.INSERTED,
|
|
22
22
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
@@ -25,14 +25,15 @@ var createTableWithAnalytics = function createTableWithAnalytics(editorAnalytics
|
|
|
25
25
|
inputMethod: _analytics.INPUT_METHOD.SHORTCUT
|
|
26
26
|
},
|
|
27
27
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
28
|
-
})(editorAnalyticsAPI)((0, _commands2.createTable)());
|
|
28
|
+
})(editorAnalyticsAPI)((0, _commands2.createTable)(isTableScalingEnabled, isFullWidthModeEnabled));
|
|
29
29
|
};
|
|
30
30
|
function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
31
31
|
var isTableScalingEnabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
32
|
+
var isFullWidthEnabled = arguments.length > 4 ? arguments[4] : undefined;
|
|
32
33
|
var list = {};
|
|
33
34
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.nextCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI)(1), list);
|
|
34
35
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.previousCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI)(-1), list);
|
|
35
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleTable.common, createTableWithAnalytics(editorAnalyticsAPI), list);
|
|
36
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleTable.common, createTableWithAnalytics(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
36
37
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, (0, _commands.chainCommands)((0, _commandsWithAnalytics.deleteTableIfSelectedWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), (0, _commandsWithAnalytics.emptyMultipleCellsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD)), list);
|
|
37
38
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, _commands2.moveCursorBackward, list);
|
|
38
39
|
|
|
@@ -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);
|
|
@@ -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:
|
|
@@ -14,7 +14,8 @@ var DragHandleDisabledIcon = exports.DragHandleDisabledIcon = function DragHandl
|
|
|
14
14
|
viewBox: "0 0 24 16",
|
|
15
15
|
fill: "none",
|
|
16
16
|
xmlns: "http://www.w3.org/2000/svg",
|
|
17
|
-
style: style
|
|
17
|
+
style: style,
|
|
18
|
+
"data-testid": "drag-icon-disabled"
|
|
18
19
|
}, /*#__PURE__*/_react.default.createElement("rect", {
|
|
19
20
|
width: "24",
|
|
20
21
|
height: "16",
|
|
@@ -11,7 +11,8 @@ var DragHandleIcon = exports.DragHandleIcon = function DragHandleIcon() {
|
|
|
11
11
|
xmlns: "http://www.w3.org/2000/svg",
|
|
12
12
|
width: "24",
|
|
13
13
|
height: "16",
|
|
14
|
-
fill: "none"
|
|
14
|
+
fill: "none",
|
|
15
|
+
"data-testid": "drag-icon-enabled"
|
|
15
16
|
}, /*#__PURE__*/_react.default.createElement("rect", {
|
|
16
17
|
width: "24",
|
|
17
18
|
height: "16",
|
|
@@ -418,7 +418,6 @@ class TableComponent extends React.Component {
|
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
handleColgroupUpdates(force = false) {
|
|
421
|
-
var _this$containerWidth;
|
|
422
421
|
const {
|
|
423
422
|
getNode,
|
|
424
423
|
containerWidth,
|
|
@@ -436,32 +435,36 @@ class TableComponent extends React.Component {
|
|
|
436
435
|
const tableNode = getNode();
|
|
437
436
|
const start = getPos() || 0;
|
|
438
437
|
const depth = view.state.doc.resolve(start).depth;
|
|
439
|
-
|
|
440
|
-
// TODO - remove this when support is added for nested tables
|
|
441
438
|
if (depth !== 0) {
|
|
442
439
|
return;
|
|
443
440
|
}
|
|
444
441
|
const tableNodeWidth = getTableContainerWidth(tableNode);
|
|
445
442
|
const shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
+
});
|
|
460
462
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
463
|
+
// Request animation frame required for Firefox
|
|
464
|
+
requestAnimationFrame(() => {
|
|
465
|
+
updateColgroup(resizeState, this.table, tableNode, true);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
465
468
|
}
|
|
466
469
|
this.containerWidth = containerWidth;
|
|
467
470
|
}
|
|
@@ -474,7 +477,8 @@ class TableComponent extends React.Component {
|
|
|
474
477
|
allowColumnResizing,
|
|
475
478
|
isResizing,
|
|
476
479
|
options,
|
|
477
|
-
isTableScalingEnabled
|
|
480
|
+
isTableScalingEnabled,
|
|
481
|
+
getPos
|
|
478
482
|
} = this.props;
|
|
479
483
|
const {
|
|
480
484
|
isInDanger
|
|
@@ -513,13 +517,17 @@ class TableComponent extends React.Component {
|
|
|
513
517
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
514
518
|
// re-draw colgroup.
|
|
515
519
|
const previousTable = this.node;
|
|
516
|
-
|
|
520
|
+
const isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(currentTable, previousTable);
|
|
521
|
+
if (tablesHaveDifferentColumnWidths(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
517
522
|
const {
|
|
518
523
|
view
|
|
519
524
|
} = this.props;
|
|
520
|
-
const shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing ||
|
|
525
|
+
const shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || isNoOfColumnsChanged && isResizing;
|
|
521
526
|
if (shouldRecreateResizeCols) {
|
|
522
|
-
|
|
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);
|
|
523
531
|
}
|
|
524
532
|
updateControls()(view.state);
|
|
525
533
|
}
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -149,9 +149,10 @@ const tablesPlugin = ({
|
|
|
149
149
|
plugin: () => {
|
|
150
150
|
const {
|
|
151
151
|
dragAndDropEnabled,
|
|
152
|
-
isTableScalingEnabled = false
|
|
152
|
+
isTableScalingEnabled = false,
|
|
153
|
+
fullWidthEnabled = false
|
|
153
154
|
} = options || {};
|
|
154
|
-
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled);
|
|
155
|
+
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, fullWidthEnabled);
|
|
155
156
|
}
|
|
156
157
|
}, {
|
|
157
158
|
name: 'tableSelectionKeymap',
|
|
@@ -9,7 +9,7 @@ import { activateNextResizeArea, initiateKeyboardColumnResizing, stopKeyboardCol
|
|
|
9
9
|
import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand } from '../commands/insert';
|
|
10
10
|
import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
|
|
11
11
|
import { withEditorAnalyticsAPI } from '../utils/analytics';
|
|
12
|
-
const createTableWithAnalytics = editorAnalyticsAPI => withEditorAnalyticsAPI({
|
|
12
|
+
const createTableWithAnalytics = (isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) => withEditorAnalyticsAPI({
|
|
13
13
|
action: ACTION.INSERTED,
|
|
14
14
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
15
15
|
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
@@ -17,12 +17,12 @@ const createTableWithAnalytics = editorAnalyticsAPI => withEditorAnalyticsAPI({
|
|
|
17
17
|
inputMethod: INPUT_METHOD.SHORTCUT
|
|
18
18
|
},
|
|
19
19
|
eventType: EVENT_TYPE.TRACK
|
|
20
|
-
})(editorAnalyticsAPI)(createTable());
|
|
21
|
-
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled = false) {
|
|
20
|
+
})(editorAnalyticsAPI)(createTable(isTableScalingEnabled, isFullWidthModeEnabled));
|
|
21
|
+
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled = false, isFullWidthEnabled) {
|
|
22
22
|
const list = {};
|
|
23
23
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
|
|
24
24
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
|
|
25
|
-
bindKeymapWithCommand(toggleTable.common, createTableWithAnalytics(editorAnalyticsAPI), list);
|
|
25
|
+
bindKeymapWithCommand(toggleTable.common, createTableWithAnalytics(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
26
26
|
bindKeymapWithCommand(backspace.common, chainCommands(deleteTableIfSelectedWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)), list);
|
|
27
27
|
bindKeymapWithCommand(backspace.common, moveCursorBackward, list);
|
|
28
28
|
|
|
@@ -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);
|
|
@@ -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:
|
|
@@ -7,7 +7,8 @@ export const DragHandleDisabledIcon = ({
|
|
|
7
7
|
viewBox: "0 0 24 16",
|
|
8
8
|
fill: "none",
|
|
9
9
|
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
-
style: style
|
|
10
|
+
style: style,
|
|
11
|
+
"data-testid": "drag-icon-disabled"
|
|
11
12
|
}, /*#__PURE__*/React.createElement("rect", {
|
|
12
13
|
width: "24",
|
|
13
14
|
height: "16",
|
|
@@ -3,7 +3,8 @@ export const DragHandleIcon = () => /*#__PURE__*/React.createElement("svg", {
|
|
|
3
3
|
xmlns: "http://www.w3.org/2000/svg",
|
|
4
4
|
width: "24",
|
|
5
5
|
height: "16",
|
|
6
|
-
fill: "none"
|
|
6
|
+
fill: "none",
|
|
7
|
+
"data-testid": "drag-icon-enabled"
|
|
7
8
|
}, /*#__PURE__*/React.createElement("rect", {
|
|
8
9
|
width: "24",
|
|
9
10
|
height: "16",
|
|
@@ -428,8 +428,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
428
428
|
}, {
|
|
429
429
|
key: "handleColgroupUpdates",
|
|
430
430
|
value: function handleColgroupUpdates() {
|
|
431
|
-
var
|
|
432
|
-
_this2 = this;
|
|
431
|
+
var _this2 = this;
|
|
433
432
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
434
433
|
var _this$props9 = this.props,
|
|
435
434
|
getNode = _this$props9.getNode,
|
|
@@ -447,30 +446,34 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
447
446
|
var tableNode = getNode();
|
|
448
447
|
var start = getPos() || 0;
|
|
449
448
|
var depth = view.state.doc.resolve(start).depth;
|
|
450
|
-
|
|
451
|
-
// TODO - remove this when support is added for nested tables
|
|
452
449
|
if (depth !== 0) {
|
|
453
450
|
return;
|
|
454
451
|
}
|
|
455
452
|
var tableNodeWidth = getTableContainerWidth(tableNode);
|
|
456
453
|
var shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
var
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
+
});
|
|
469
471
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
472
|
+
// Request animation frame required for Firefox
|
|
473
|
+
requestAnimationFrame(function () {
|
|
474
|
+
updateColgroup(resizeState, _this2.table, tableNode, true);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
474
477
|
}
|
|
475
478
|
this.containerWidth = containerWidth;
|
|
476
479
|
}
|
|
@@ -486,7 +489,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
486
489
|
allowColumnResizing = _this$props10.allowColumnResizing,
|
|
487
490
|
isResizing = _this$props10.isResizing,
|
|
488
491
|
options = _this$props10.options,
|
|
489
|
-
isTableScalingEnabled = _this$props10.isTableScalingEnabled
|
|
492
|
+
isTableScalingEnabled = _this$props10.isTableScalingEnabled,
|
|
493
|
+
getPos = _this$props10.getPos;
|
|
490
494
|
var _getPluginState = getPluginState(view.state),
|
|
491
495
|
isInDanger = _getPluginState.isInDanger;
|
|
492
496
|
var table = findTable(view.state.selection);
|
|
@@ -523,11 +527,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
523
527
|
// If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
|
|
524
528
|
// re-draw colgroup.
|
|
525
529
|
var previousTable = this.node;
|
|
526
|
-
|
|
530
|
+
var isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(currentTable, previousTable);
|
|
531
|
+
if (tablesHaveDifferentColumnWidths(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
527
532
|
var _view = this.props.view;
|
|
528
|
-
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing ||
|
|
533
|
+
var shouldRecreateResizeCols = !(options !== null && options !== void 0 && options.isTableResizingEnabled) || !isResizing || isNoOfColumnsChanged && isResizing;
|
|
529
534
|
if (shouldRecreateResizeCols) {
|
|
530
|
-
|
|
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);
|
|
531
539
|
}
|
|
532
540
|
updateControls()(_view.state);
|
|
533
541
|
}
|
package/dist/esm/plugin.js
CHANGED
|
@@ -150,8 +150,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
150
150
|
var _ref6 = options || {},
|
|
151
151
|
dragAndDropEnabled = _ref6.dragAndDropEnabled,
|
|
152
152
|
_ref6$isTableScalingE = _ref6.isTableScalingEnabled,
|
|
153
|
-
isTableScalingEnabled = _ref6$isTableScalingE === void 0 ? false : _ref6$isTableScalingE
|
|
154
|
-
|
|
153
|
+
isTableScalingEnabled = _ref6$isTableScalingE === void 0 ? false : _ref6$isTableScalingE,
|
|
154
|
+
_ref6$fullWidthEnable = _ref6.fullWidthEnabled,
|
|
155
|
+
fullWidthEnabled = _ref6$fullWidthEnable === void 0 ? false : _ref6$fullWidthEnable;
|
|
156
|
+
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, fullWidthEnabled);
|
|
155
157
|
}
|
|
156
158
|
}, {
|
|
157
159
|
name: 'tableSelectionKeymap',
|
|
@@ -9,7 +9,7 @@ import { activateNextResizeArea, initiateKeyboardColumnResizing, stopKeyboardCol
|
|
|
9
9
|
import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand } from '../commands/insert';
|
|
10
10
|
import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
|
|
11
11
|
import { withEditorAnalyticsAPI } from '../utils/analytics';
|
|
12
|
-
var createTableWithAnalytics = function createTableWithAnalytics(editorAnalyticsAPI) {
|
|
12
|
+
var createTableWithAnalytics = function createTableWithAnalytics(isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
|
|
13
13
|
return withEditorAnalyticsAPI({
|
|
14
14
|
action: ACTION.INSERTED,
|
|
15
15
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -18,14 +18,15 @@ var createTableWithAnalytics = function createTableWithAnalytics(editorAnalytics
|
|
|
18
18
|
inputMethod: INPUT_METHOD.SHORTCUT
|
|
19
19
|
},
|
|
20
20
|
eventType: EVENT_TYPE.TRACK
|
|
21
|
-
})(editorAnalyticsAPI)(createTable());
|
|
21
|
+
})(editorAnalyticsAPI)(createTable(isTableScalingEnabled, isFullWidthModeEnabled));
|
|
22
22
|
};
|
|
23
23
|
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
24
24
|
var isTableScalingEnabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
25
|
+
var isFullWidthEnabled = arguments.length > 4 ? arguments[4] : undefined;
|
|
25
26
|
var list = {};
|
|
26
27
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
|
|
27
28
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
|
|
28
|
-
bindKeymapWithCommand(toggleTable.common, createTableWithAnalytics(editorAnalyticsAPI), list);
|
|
29
|
+
bindKeymapWithCommand(toggleTable.common, createTableWithAnalytics(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
29
30
|
bindKeymapWithCommand(backspace.common, chainCommands(deleteTableIfSelectedWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)), list);
|
|
30
31
|
bindKeymapWithCommand(backspace.common, moveCursorBackward, list);
|
|
31
32
|
|
|
@@ -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);
|
|
@@ -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:
|
|
@@ -7,7 +7,8 @@ export var DragHandleDisabledIcon = function DragHandleDisabledIcon(_ref) {
|
|
|
7
7
|
viewBox: "0 0 24 16",
|
|
8
8
|
fill: "none",
|
|
9
9
|
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
-
style: style
|
|
10
|
+
style: style,
|
|
11
|
+
"data-testid": "drag-icon-disabled"
|
|
11
12
|
}, /*#__PURE__*/React.createElement("rect", {
|
|
12
13
|
width: "24",
|
|
13
14
|
height: "16",
|
|
@@ -4,7 +4,8 @@ export var DragHandleIcon = function DragHandleIcon() {
|
|
|
4
4
|
xmlns: "http://www.w3.org/2000/svg",
|
|
5
5
|
width: "24",
|
|
6
6
|
height: "16",
|
|
7
|
-
fill: "none"
|
|
7
|
+
fill: "none",
|
|
8
|
+
"data-testid": "drag-icon-enabled"
|
|
8
9
|
}, /*#__PURE__*/React.createElement("rect", {
|
|
9
10
|
width: "24",
|
|
10
11
|
height: "16",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
4
|
-
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean): SafePlugin;
|
|
4
|
+
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isFullWidthEnabled?: boolean): SafePlugin;
|
|
5
5
|
export default keymapPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
4
|
-
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean): SafePlugin;
|
|
4
|
+
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isFullWidthEnabled?: boolean): SafePlugin;
|
|
5
5
|
export default keymapPlugin;
|
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.11",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop": "^1.0.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.0.0",
|
|
48
48
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
|
|
49
|
-
"@atlaskit/primitives": "^
|
|
49
|
+
"@atlaskit/primitives": "^5.0.0",
|
|
50
50
|
"@atlaskit/theme": "^12.6.0",
|
|
51
51
|
"@atlaskit/toggle": "^13.0.0",
|
|
52
52
|
"@atlaskit/tokens": "^1.41.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);
|
package/src/plugin.tsx
CHANGED
|
@@ -266,14 +266,17 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
266
266
|
{
|
|
267
267
|
name: 'tableKeymap',
|
|
268
268
|
plugin: () => {
|
|
269
|
-
const {
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
const {
|
|
270
|
+
dragAndDropEnabled,
|
|
271
|
+
isTableScalingEnabled = false,
|
|
272
|
+
fullWidthEnabled = false,
|
|
273
|
+
} = options || ({} as TablePluginOptions);
|
|
272
274
|
return keymapPlugin(
|
|
273
275
|
defaultGetEditorContainerWidth,
|
|
274
276
|
editorAnalyticsAPI,
|
|
275
277
|
dragAndDropEnabled,
|
|
276
278
|
isTableScalingEnabled,
|
|
279
|
+
fullWidthEnabled,
|
|
277
280
|
);
|
|
278
281
|
},
|
|
279
282
|
},
|
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -56,6 +56,8 @@ import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/
|
|
|
56
56
|
import { withEditorAnalyticsAPI } from '../utils/analytics';
|
|
57
57
|
|
|
58
58
|
const createTableWithAnalytics = (
|
|
59
|
+
isTableScalingEnabled: boolean,
|
|
60
|
+
isFullWidthModeEnabled: boolean,
|
|
59
61
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
60
62
|
) =>
|
|
61
63
|
withEditorAnalyticsAPI({
|
|
@@ -64,13 +66,16 @@ const createTableWithAnalytics = (
|
|
|
64
66
|
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
65
67
|
attributes: { inputMethod: INPUT_METHOD.SHORTCUT },
|
|
66
68
|
eventType: EVENT_TYPE.TRACK,
|
|
67
|
-
})(editorAnalyticsAPI)(
|
|
69
|
+
})(editorAnalyticsAPI)(
|
|
70
|
+
createTable(isTableScalingEnabled, isFullWidthModeEnabled),
|
|
71
|
+
);
|
|
68
72
|
|
|
69
73
|
export function keymapPlugin(
|
|
70
74
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
71
75
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
72
76
|
dragAndDropEnabled?: boolean,
|
|
73
77
|
isTableScalingEnabled = false,
|
|
78
|
+
isFullWidthEnabled?: boolean,
|
|
74
79
|
): SafePlugin {
|
|
75
80
|
const list = {};
|
|
76
81
|
|
|
@@ -86,7 +91,11 @@ export function keymapPlugin(
|
|
|
86
91
|
);
|
|
87
92
|
bindKeymapWithCommand(
|
|
88
93
|
toggleTable.common!,
|
|
89
|
-
createTableWithAnalytics(
|
|
94
|
+
createTableWithAnalytics(
|
|
95
|
+
isTableScalingEnabled,
|
|
96
|
+
!!isFullWidthEnabled,
|
|
97
|
+
editorAnalyticsAPI,
|
|
98
|
+
),
|
|
90
99
|
list,
|
|
91
100
|
);
|
|
92
101
|
bindKeymapWithCommand(
|
|
@@ -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);
|
|
@@ -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:
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
export const DragHandleIcon = () => (
|
|
4
|
-
<svg
|
|
4
|
+
<svg
|
|
5
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
6
|
+
width="24"
|
|
7
|
+
height="16"
|
|
8
|
+
fill="none"
|
|
9
|
+
data-testid="drag-icon-enabled"
|
|
10
|
+
>
|
|
5
11
|
<rect width="24" height="16" rx="4" />
|
|
6
12
|
<g>
|
|
7
13
|
<path d="M9 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM9 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z" />
|