@atlaskit/editor-plugin-table 7.5.6 → 7.5.7
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 +7 -0
- package/dist/cjs/commands/selection.js +23 -1
- package/dist/cjs/nodeviews/TableComponent.js +23 -18
- package/dist/cjs/pm-plugins/sticky-headers/types.js +1 -5
- package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +11 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +22 -23
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/cjs/pm-plugins/table-selection-keymap.js +3 -0
- package/dist/es2019/commands/selection.js +22 -0
- package/dist/es2019/nodeviews/TableComponent.js +6 -4
- package/dist/es2019/pm-plugins/sticky-headers/types.js +0 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +10 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +21 -22
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/es2019/pm-plugins/table-selection-keymap.js +5 -2
- package/dist/esm/commands/selection.js +22 -0
- package/dist/esm/nodeviews/TableComponent.js +23 -18
- package/dist/esm/pm-plugins/sticky-headers/types.js +0 -1
- package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +10 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +23 -24
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/esm/pm-plugins/table-selection-keymap.js +5 -2
- package/dist/types/commands/selection.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types-ts4.5/commands/selection.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/package.json +6 -3
- package/src/commands/selection.ts +33 -0
- package/src/nodeviews/TableComponent.tsx +5 -2
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +3 -6
- package/src/pm-plugins/table-resizing/utils/misc.ts +13 -0
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +22 -28
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +3 -10
- package/src/pm-plugins/table-selection-keymap.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.5.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#80086](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80086) [`c30ac781b469`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c30ac781b469) - Add keyboard support Cmd-A to select whole table
|
|
8
|
+
- [#81017](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81017) [`df5a993963d9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/df5a993963d9) - prevent scaled table columns being resized below min width
|
|
9
|
+
|
|
3
10
|
## 7.5.6
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.shiftArrowUpFromTable = exports.selectRows = exports.selectColumns = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
|
|
6
|
+
exports.shiftArrowUpFromTable = exports.selectRows = exports.selectColumns = exports.modASelectTable = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
|
|
7
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
@@ -419,4 +419,26 @@ var shiftArrowUpFromTable = exports.shiftArrowUpFromTable = function shiftArrowU
|
|
|
419
419
|
return false;
|
|
420
420
|
};
|
|
421
421
|
};
|
|
422
|
+
};
|
|
423
|
+
var modASelectTable = exports.modASelectTable = function modASelectTable(editorSelectionAPI) {
|
|
424
|
+
return function () {
|
|
425
|
+
return function (state, dispatch) {
|
|
426
|
+
var selection = state.selection;
|
|
427
|
+
var table = (0, _utils.findTable)(selection);
|
|
428
|
+
if (!table) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
var $from = selection.$from,
|
|
432
|
+
$to = selection.$to;
|
|
433
|
+
var tableSelected = (0, _utils.isTableSelected)(selection);
|
|
434
|
+
if (!tableSelected && $from.pos > table.start + 1 && $to.pos < table.start + table.node.nodeSize) {
|
|
435
|
+
return selectFullTable(editorSelectionAPI)({
|
|
436
|
+
node: table.node,
|
|
437
|
+
startPos: table.start,
|
|
438
|
+
dir: TableSelectionDirection.BottomToTop
|
|
439
|
+
})(state, dispatch);
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
};
|
|
443
|
+
};
|
|
422
444
|
};
|
|
@@ -436,7 +436,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
436
436
|
}, {
|
|
437
437
|
key: "handleColgroupUpdates",
|
|
438
438
|
value: function handleColgroupUpdates() {
|
|
439
|
-
var _this$containerWidth
|
|
439
|
+
var _this$containerWidth,
|
|
440
|
+
_this2 = this;
|
|
440
441
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
441
442
|
var _this$props9 = this.props,
|
|
442
443
|
getNode = _this$props9.getNode,
|
|
@@ -459,7 +460,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
459
460
|
if (depth !== 0) {
|
|
460
461
|
return;
|
|
461
462
|
}
|
|
462
|
-
var tableNodeWidth = tableNode
|
|
463
|
+
var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(tableNode);
|
|
463
464
|
var shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
464
465
|
var containerWidthValue = containerWidth.width;
|
|
465
466
|
var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
|
|
@@ -473,7 +474,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
473
474
|
domAtPos: view.domAtPos,
|
|
474
475
|
isTableScalingEnabled: true
|
|
475
476
|
});
|
|
476
|
-
|
|
477
|
+
|
|
478
|
+
// Request animation frame required for Firefox
|
|
479
|
+
requestAnimationFrame(function () {
|
|
480
|
+
(0, _utils4.updateColgroup)(resizeState, _this2.table, tableNode, true);
|
|
481
|
+
});
|
|
477
482
|
}
|
|
478
483
|
this.containerWidth = containerWidth;
|
|
479
484
|
}
|
|
@@ -481,7 +486,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
481
486
|
key: "componentDidUpdate",
|
|
482
487
|
value: function componentDidUpdate(_, prevState) {
|
|
483
488
|
var _this$wrapper,
|
|
484
|
-
|
|
489
|
+
_this3 = this;
|
|
485
490
|
var _this$props10 = this.props,
|
|
486
491
|
view = _this$props10.view,
|
|
487
492
|
getNode = _this$props10.getNode,
|
|
@@ -505,7 +510,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
505
510
|
// that happens when a table is nested in expand and expand's width is
|
|
506
511
|
// changed via breakout button
|
|
507
512
|
window.requestAnimationFrame(function () {
|
|
508
|
-
|
|
513
|
+
_this3.overflowShadowsObserver = new _OverflowShadowsObserver.OverflowShadowsObserver(_this3.updateShadowState, _this3.table, _this3.wrapper);
|
|
509
514
|
});
|
|
510
515
|
} else {
|
|
511
516
|
this.overflowShadowsObserver = new _OverflowShadowsObserver.OverflowShadowsObserver(this.updateShadowState, this.table, this.wrapper);
|
|
@@ -571,7 +576,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
571
576
|
}, {
|
|
572
577
|
key: "render",
|
|
573
578
|
value: function render() {
|
|
574
|
-
var
|
|
579
|
+
var _this4 = this,
|
|
575
580
|
_classnames;
|
|
576
581
|
var _this$props11 = this.props,
|
|
577
582
|
view = _this$props11.view,
|
|
@@ -648,8 +653,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
648
653
|
tableContainerWidth: tableContainerWidth,
|
|
649
654
|
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
650
655
|
getScrollOffset: function getScrollOffset() {
|
|
651
|
-
var
|
|
652
|
-
return ((
|
|
656
|
+
var _this4$wrapper;
|
|
657
|
+
return ((_this4$wrapper = _this4.wrapper) === null || _this4$wrapper === void 0 ? void 0 : _this4$wrapper.scrollLeft) || 0;
|
|
653
658
|
},
|
|
654
659
|
tableWrapperHeight: this.state.tableWrapperHeight
|
|
655
660
|
}) : null;
|
|
@@ -699,12 +704,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
699
704
|
editorView: view,
|
|
700
705
|
node: node,
|
|
701
706
|
getScrollOffset: function getScrollOffset() {
|
|
702
|
-
var
|
|
703
|
-
return ((
|
|
707
|
+
var _this4$wrapper2;
|
|
708
|
+
return ((_this4$wrapper2 = _this4.wrapper) === null || _this4$wrapper2 === void 0 ? void 0 : _this4$wrapper2.scrollLeft) || 0;
|
|
704
709
|
},
|
|
705
710
|
getTableWrapperWidth: function getTableWrapperWidth() {
|
|
706
|
-
var
|
|
707
|
-
return ((
|
|
711
|
+
var _this4$wrapper3;
|
|
712
|
+
return ((_this4$wrapper3 = _this4.wrapper) === null || _this4$wrapper3 === void 0 ? void 0 : _this4$wrapper3.clientWidth) || 760;
|
|
708
713
|
}
|
|
709
714
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
710
715
|
style: shadowStyle(showBeforeShadow),
|
|
@@ -719,14 +724,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
719
724
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
720
725
|
className: (0, _classnames2.default)(_types.TableCssClassName.TABLE_NODE_WRAPPER),
|
|
721
726
|
ref: function ref(elem) {
|
|
722
|
-
|
|
727
|
+
_this4.wrapper = elem;
|
|
723
728
|
if (elem) {
|
|
724
|
-
|
|
729
|
+
_this4.props.contentDOM(elem);
|
|
725
730
|
var tableElement = elem.querySelector('table');
|
|
726
|
-
if (tableElement !==
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
731
|
+
if (tableElement !== _this4.table) {
|
|
732
|
+
_this4.table = tableElement;
|
|
733
|
+
_this4.createShadowSentinels(_this4.table);
|
|
734
|
+
_this4.observeTable(_this4.table);
|
|
730
735
|
}
|
|
731
736
|
}
|
|
732
737
|
}
|
|
@@ -11,7 +11,7 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
11
11
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
12
12
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
13
13
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
-
var
|
|
14
|
+
var _misc = require("./misc");
|
|
15
15
|
/**
|
|
16
16
|
* This ensures the combined width of the columns (and tbody) of table is always smaller or equal
|
|
17
17
|
* than the table and table wrapper elements. This is necessary as there is no longer
|
|
@@ -31,14 +31,10 @@ var generateColgroup = exports.generateColgroup = function generateColgroup(tabl
|
|
|
31
31
|
// We slice here to guard against our colwidth array having more entries
|
|
32
32
|
// Than the we actually span. We'll patch the document at a later point.
|
|
33
33
|
if (tableRef) {
|
|
34
|
-
var
|
|
35
|
-
var tableWidth = table.attrs && table.attrs.width;
|
|
36
|
-
var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
|
|
37
|
-
var scalePercent = renderWidth / tableWidth;
|
|
38
|
-
scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
|
|
34
|
+
var scalePercent = (0, _misc.getTableScalingPercent)(table, tableRef);
|
|
39
35
|
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
40
36
|
var fixedColWidth = getColWidthFix(width, map.width);
|
|
41
|
-
var scaledWidth = fixedColWidth *
|
|
37
|
+
var scaledWidth = fixedColWidth * scalePercent;
|
|
42
38
|
var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
|
|
43
39
|
cols.push(['col', {
|
|
44
40
|
style: "width: ".concat(finalWidth, "px;")
|
|
@@ -7,7 +7,7 @@ exports.currentColWidth = currentColWidth;
|
|
|
7
7
|
exports.domCellAround = domCellAround;
|
|
8
8
|
exports.getDefaultLayoutMaxWidth = getDefaultLayoutMaxWidth;
|
|
9
9
|
exports.getLayoutSize = getLayoutSize;
|
|
10
|
-
exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElementWidth = void 0;
|
|
10
|
+
exports.getTableScalingPercent = exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElementWidth = void 0;
|
|
11
11
|
exports.pointsAtCell = pointsAtCell;
|
|
12
12
|
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
13
13
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
@@ -16,6 +16,7 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
16
16
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
17
17
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
18
|
var _colgroup = require("./colgroup");
|
|
19
|
+
var _consts = require("./consts");
|
|
19
20
|
// Translates named layouts in number values.
|
|
20
21
|
function getLayoutSize(tableLayout) {
|
|
21
22
|
var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -99,4 +100,13 @@ var getTableElementWidth = exports.getTableElementWidth = function getTableEleme
|
|
|
99
100
|
};
|
|
100
101
|
var getTableContainerElementWidth = exports.getTableContainerElementWidth = function getTableContainerElementWidth(table) {
|
|
101
102
|
return (0, _nodeWidth.getTableContainerWidth)(table);
|
|
103
|
+
};
|
|
104
|
+
var getTableScalingPercent = exports.getTableScalingPercent = function getTableScalingPercent(table, tableRef) {
|
|
105
|
+
var _tableRef$parentEleme;
|
|
106
|
+
var tableWidth = getTableContainerElementWidth(table);
|
|
107
|
+
var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
|
|
108
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
109
|
+
var scalePercent = (renderWidth - 1) / tableWidth;
|
|
110
|
+
scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
|
|
111
|
+
return Math.min(scalePercent, 1);
|
|
102
112
|
};
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.updateColgroup = exports.normaliseTableLayout = exports.getTotalWidth = exports.getResizeState = exports.getNewResizeStateFromSelectedColumns = exports.evenSelectedColumnsWidths = exports.evenAllColumnsWidths = exports.bulkColumnsResize = exports.areColumnsEven = exports.adjustColumnsWidths = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
9
10
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
10
11
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
12
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -14,7 +15,6 @@ var _colgroup = require("./colgroup");
|
|
|
14
15
|
var _columnState = require("./column-state");
|
|
15
16
|
var _dom = require("./dom");
|
|
16
17
|
var _misc = require("./misc");
|
|
17
|
-
var _index = require("./index");
|
|
18
18
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
19
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
20
|
var getResizeState = exports.getResizeState = function getResizeState(_ref) {
|
|
@@ -26,6 +26,10 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
|
|
|
26
26
|
domAtPos = _ref.domAtPos,
|
|
27
27
|
_ref$isTableScalingEn = _ref.isTableScalingEnabled,
|
|
28
28
|
isTableScalingEnabled = _ref$isTableScalingEn === void 0 ? false : _ref$isTableScalingEn;
|
|
29
|
+
if (isTableScalingEnabled) {
|
|
30
|
+
var scalePercent = (0, _misc.getTableScalingPercent)(table, tableRef);
|
|
31
|
+
minWidth = Math.ceil(minWidth / scalePercent);
|
|
32
|
+
}
|
|
29
33
|
// If the table has been resized, we can use the column widths from the table node
|
|
30
34
|
if ((0, _colgroup.hasTableBeenResized)(table)) {
|
|
31
35
|
var _cols = (0, _utils.calcTableColumnWidths)(table).map(function (width, index) {
|
|
@@ -58,11 +62,12 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
|
|
|
58
62
|
var cols = Array.from(colgroupChildren).map(function (_, index) {
|
|
59
63
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
60
64
|
// to calculate the widths of the columns
|
|
61
|
-
if (isTableScalingEnabled
|
|
65
|
+
if (isTableScalingEnabled) {
|
|
66
|
+
var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(table);
|
|
62
67
|
return {
|
|
63
68
|
index: index,
|
|
64
|
-
width:
|
|
65
|
-
minWidth:
|
|
69
|
+
width: tableNodeWidth / colgroupChildren.length,
|
|
70
|
+
minWidth: minWidth
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
73
|
var cellsRefs = (0, _columnState.getCellsRefsInColumn)(index, table, start, domAtPos);
|
|
@@ -90,25 +95,19 @@ var updateColgroup = exports.updateColgroup = function updateColgroup(state, tab
|
|
|
90
95
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
|
|
91
96
|
var columnsCount = cols.length;
|
|
92
97
|
if (isTableScalingEnabled && tableNode) {
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
107
|
-
if (cols[i]) {
|
|
108
|
-
cols[i].style.width = "".concat(finalWidth, "px");
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
98
|
+
var scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
|
|
99
|
+
state.cols.filter(function (column) {
|
|
100
|
+
return column && !!column.width;
|
|
101
|
+
}) // if width is 0, we dont want to apply that.
|
|
102
|
+
.forEach(function (column, i) {
|
|
103
|
+
var fixedColWidth = (0, _colgroup.getColWidthFix)(column.width, columnsCount);
|
|
104
|
+
var scaledWidth = fixedColWidth * scalePercent;
|
|
105
|
+
var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
|
|
106
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
107
|
+
if (cols[i]) {
|
|
108
|
+
cols[i].style.width = "".concat(finalWidth, "px");
|
|
109
|
+
}
|
|
110
|
+
});
|
|
112
111
|
} else {
|
|
113
112
|
state.cols.filter(function (column) {
|
|
114
113
|
return column && !!column.width;
|
|
@@ -133,9 +133,9 @@ var previewScaleTable = exports.previewScaleTable = function previewScaleTable(t
|
|
|
133
133
|
(0, _dom.syncStickyRowToTable)(tableRef);
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos,
|
|
136
|
+
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) : scale(tableRef, options, domAtPos, false);
|
|
137
137
|
if (resizeState) {
|
|
138
|
-
(0, _resizeState.updateColgroup)(resizeState, tableRef, node,
|
|
138
|
+
(0, _resizeState.updateColgroup)(resizeState, tableRef, node, false);
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
|
|
@@ -20,6 +20,9 @@ function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
|
20
20
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.shift-arrowup-fix')) {
|
|
21
21
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.shiftArrowUp.common, (0, _selection.shiftArrowUpFromTable)(editorSelectionAPI)(), list);
|
|
22
22
|
}
|
|
23
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.cmd-a-select-table')) {
|
|
24
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.selectTable.common, (0, _selection.modASelectTable)(editorSelectionAPI)(), list);
|
|
25
|
+
}
|
|
23
26
|
return (0, _keymap.keymap)(list);
|
|
24
27
|
}
|
|
25
28
|
var _default = exports.default = tableSelectionKeymapPlugin;
|
|
@@ -372,4 +372,26 @@ export const shiftArrowUpFromTable = editorSelectionAPI => () => (state, dispatc
|
|
|
372
372
|
})(state, dispatch);
|
|
373
373
|
}
|
|
374
374
|
return false;
|
|
375
|
+
};
|
|
376
|
+
export const modASelectTable = editorSelectionAPI => () => (state, dispatch) => {
|
|
377
|
+
const {
|
|
378
|
+
selection
|
|
379
|
+
} = state;
|
|
380
|
+
const table = findTable(selection);
|
|
381
|
+
if (!table) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
const {
|
|
385
|
+
$from,
|
|
386
|
+
$to
|
|
387
|
+
} = selection;
|
|
388
|
+
const tableSelected = isTableSelected(selection);
|
|
389
|
+
if (!tableSelected && $from.pos > table.start + 1 && $to.pos < table.start + table.node.nodeSize) {
|
|
390
|
+
return selectFullTable(editorSelectionAPI)({
|
|
391
|
+
node: table.node,
|
|
392
|
+
startPos: table.start,
|
|
393
|
+
dir: TableSelectionDirection.BottomToTop
|
|
394
|
+
})(state, dispatch);
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
375
397
|
};
|
|
@@ -442,9 +442,7 @@ class TableComponent extends React.Component {
|
|
|
442
442
|
if (depth !== 0) {
|
|
443
443
|
return;
|
|
444
444
|
}
|
|
445
|
-
const
|
|
446
|
-
width: tableNodeWidth
|
|
447
|
-
} = tableNode.attrs;
|
|
445
|
+
const tableNodeWidth = getTableContainerWidth(tableNode);
|
|
448
446
|
const shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
449
447
|
const {
|
|
450
448
|
width: containerWidthValue
|
|
@@ -460,7 +458,11 @@ class TableComponent extends React.Component {
|
|
|
460
458
|
domAtPos: view.domAtPos,
|
|
461
459
|
isTableScalingEnabled: true
|
|
462
460
|
});
|
|
463
|
-
|
|
461
|
+
|
|
462
|
+
// Request animation frame required for Firefox
|
|
463
|
+
requestAnimationFrame(() => {
|
|
464
|
+
updateColgroup(resizeState, this.table, tableNode, true);
|
|
465
|
+
});
|
|
464
466
|
}
|
|
465
467
|
this.containerWidth = containerWidth;
|
|
466
468
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -3,7 +3,7 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
|
3
3
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
5
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import {
|
|
6
|
+
import { getTableScalingPercent } from './misc';
|
|
7
7
|
/**
|
|
8
8
|
* This ensures the combined width of the columns (and tbody) of table is always smaller or equal
|
|
9
9
|
* than the table and table wrapper elements. This is necessary as there is no longer
|
|
@@ -21,14 +21,10 @@ export const generateColgroup = (table, tableRef) => {
|
|
|
21
21
|
// We slice here to guard against our colwidth array having more entries
|
|
22
22
|
// Than the we actually span. We'll patch the document at a later point.
|
|
23
23
|
if (tableRef) {
|
|
24
|
-
|
|
25
|
-
const tableWidth = table.attrs && table.attrs.width;
|
|
26
|
-
let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
|
|
27
|
-
let scalePercent = renderWidth / tableWidth;
|
|
28
|
-
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
24
|
+
const scalePercent = getTableScalingPercent(table, tableRef);
|
|
29
25
|
cell.attrs.colwidth.slice(0, colspan).forEach(width => {
|
|
30
26
|
const fixedColWidth = getColWidthFix(width, map.width);
|
|
31
|
-
const scaledWidth = fixedColWidth *
|
|
27
|
+
const scaledWidth = fixedColWidth * scalePercent;
|
|
32
28
|
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
33
29
|
cols.push(['col', {
|
|
34
30
|
style: `width: ${finalWidth}px;`
|
|
@@ -5,6 +5,7 @@ import { calcTableColumnWidths, containsClassName } from '@atlaskit/editor-commo
|
|
|
5
5
|
import { akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { hasTableBeenResized } from './colgroup';
|
|
8
|
+
import { MAX_SCALING_PERCENT } from './consts';
|
|
8
9
|
|
|
9
10
|
// Translates named layouts in number values.
|
|
10
11
|
export function getLayoutSize(tableLayout, containerWidth = 0, options) {
|
|
@@ -89,4 +90,13 @@ export const getTableElementWidth = table => {
|
|
|
89
90
|
};
|
|
90
91
|
export const getTableContainerElementWidth = table => {
|
|
91
92
|
return getTableContainerWidth(table);
|
|
93
|
+
};
|
|
94
|
+
export const getTableScalingPercent = (table, tableRef) => {
|
|
95
|
+
var _tableRef$parentEleme;
|
|
96
|
+
const tableWidth = getTableContainerElementWidth(table);
|
|
97
|
+
let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
|
|
98
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
99
|
+
let scalePercent = (renderWidth - 1) / tableWidth;
|
|
100
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
101
|
+
return Math.min(scalePercent, 1);
|
|
92
102
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
1
2
|
import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
3
|
import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -5,8 +6,7 @@ import { getSelectedTableInfo } from '../../../utils';
|
|
|
5
6
|
import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
6
7
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
7
8
|
import { syncStickyRowToTable } from './dom';
|
|
8
|
-
import {
|
|
9
|
-
import { COLUMN_MIN_WIDTH, MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
9
|
+
import { getTableMaxWidth, getTableScalingPercent } from './misc';
|
|
10
10
|
export const getResizeState = ({
|
|
11
11
|
minWidth,
|
|
12
12
|
maxSize,
|
|
@@ -16,6 +16,10 @@ export const getResizeState = ({
|
|
|
16
16
|
domAtPos,
|
|
17
17
|
isTableScalingEnabled = false
|
|
18
18
|
}) => {
|
|
19
|
+
if (isTableScalingEnabled) {
|
|
20
|
+
const scalePercent = getTableScalingPercent(table, tableRef);
|
|
21
|
+
minWidth = Math.ceil(minWidth / scalePercent);
|
|
22
|
+
}
|
|
19
23
|
// If the table has been resized, we can use the column widths from the table node
|
|
20
24
|
if (hasTableBeenResized(table)) {
|
|
21
25
|
const cols = calcTableColumnWidths(table).map((width, index) => ({
|
|
@@ -42,11 +46,12 @@ export const getResizeState = ({
|
|
|
42
46
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
43
47
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
44
48
|
// to calculate the widths of the columns
|
|
45
|
-
if (isTableScalingEnabled
|
|
49
|
+
if (isTableScalingEnabled) {
|
|
50
|
+
const tableNodeWidth = getTableContainerWidth(table);
|
|
46
51
|
return {
|
|
47
52
|
index,
|
|
48
|
-
width:
|
|
49
|
-
minWidth
|
|
53
|
+
width: tableNodeWidth / colgroupChildren.length,
|
|
54
|
+
minWidth
|
|
50
55
|
};
|
|
51
56
|
}
|
|
52
57
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
@@ -70,23 +75,17 @@ export const updateColgroup = (state, tableRef, tableNode, isTableScalingEnabled
|
|
|
70
75
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
71
76
|
const columnsCount = cols.length;
|
|
72
77
|
if (isTableScalingEnabled && tableNode) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
85
|
-
if (cols[i]) {
|
|
86
|
-
cols[i].style.width = `${finalWidth}px`;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
78
|
+
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
79
|
+
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
80
|
+
.forEach((column, i) => {
|
|
81
|
+
const fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
82
|
+
const scaledWidth = fixedColWidth * scalePercent;
|
|
83
|
+
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
84
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
85
|
+
if (cols[i]) {
|
|
86
|
+
cols[i].style.width = `${finalWidth}px`;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
90
89
|
} else {
|
|
91
90
|
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
92
91
|
.forEach((column, i) => {
|
|
@@ -126,9 +126,9 @@ export const previewScaleTable = (tableRef, options, domAtPos, isTableScalingEna
|
|
|
126
126
|
syncStickyRowToTable(tableRef);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos,
|
|
129
|
+
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) : scale(tableRef, options, domAtPos, false);
|
|
130
130
|
if (resizeState) {
|
|
131
|
-
updateColgroup(resizeState, tableRef, node,
|
|
131
|
+
updateColgroup(resizeState, tableRef, node, false);
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { bindKeymapArrayWithCommand, bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapArrayWithCommand, bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, selectTable, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
3
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
|
-
import { arrowLeftFromTable, arrowRightFromTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
|
|
4
|
+
import { arrowLeftFromTable, arrowRightFromTable, modASelectTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
|
|
5
5
|
export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
6
6
|
const list = {};
|
|
7
7
|
bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
|
|
@@ -13,6 +13,9 @@ export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
|
13
13
|
if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
|
|
14
14
|
bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
|
|
15
15
|
}
|
|
16
|
+
if (getBooleanFF('platform.editor.table.cmd-a-select-table')) {
|
|
17
|
+
bindKeymapWithCommand(selectTable.common, modASelectTable(editorSelectionAPI)(), list);
|
|
18
|
+
}
|
|
16
19
|
return keymap(list);
|
|
17
20
|
}
|
|
18
21
|
export default tableSelectionKeymapPlugin;
|
|
@@ -413,4 +413,26 @@ export var shiftArrowUpFromTable = function shiftArrowUpFromTable(editorSelectio
|
|
|
413
413
|
return false;
|
|
414
414
|
};
|
|
415
415
|
};
|
|
416
|
+
};
|
|
417
|
+
export var modASelectTable = function modASelectTable(editorSelectionAPI) {
|
|
418
|
+
return function () {
|
|
419
|
+
return function (state, dispatch) {
|
|
420
|
+
var selection = state.selection;
|
|
421
|
+
var table = findTable(selection);
|
|
422
|
+
if (!table) {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
var $from = selection.$from,
|
|
426
|
+
$to = selection.$to;
|
|
427
|
+
var tableSelected = isTableSelected(selection);
|
|
428
|
+
if (!tableSelected && $from.pos > table.start + 1 && $to.pos < table.start + table.node.nodeSize) {
|
|
429
|
+
return selectFullTable(editorSelectionAPI)({
|
|
430
|
+
node: table.node,
|
|
431
|
+
startPos: table.start,
|
|
432
|
+
dir: TableSelectionDirection.BottomToTop
|
|
433
|
+
})(state, dispatch);
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
};
|
|
437
|
+
};
|
|
416
438
|
};
|
|
@@ -429,7 +429,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
429
429
|
}, {
|
|
430
430
|
key: "handleColgroupUpdates",
|
|
431
431
|
value: function handleColgroupUpdates() {
|
|
432
|
-
var _this$containerWidth
|
|
432
|
+
var _this$containerWidth,
|
|
433
|
+
_this2 = this;
|
|
433
434
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
434
435
|
var _this$props9 = this.props,
|
|
435
436
|
getNode = _this$props9.getNode,
|
|
@@ -452,7 +453,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
452
453
|
if (depth !== 0) {
|
|
453
454
|
return;
|
|
454
455
|
}
|
|
455
|
-
var tableNodeWidth = tableNode
|
|
456
|
+
var tableNodeWidth = getTableContainerWidth(tableNode);
|
|
456
457
|
var shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
457
458
|
var containerWidthValue = containerWidth.width;
|
|
458
459
|
var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
|
|
@@ -466,7 +467,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
466
467
|
domAtPos: view.domAtPos,
|
|
467
468
|
isTableScalingEnabled: true
|
|
468
469
|
});
|
|
469
|
-
|
|
470
|
+
|
|
471
|
+
// Request animation frame required for Firefox
|
|
472
|
+
requestAnimationFrame(function () {
|
|
473
|
+
updateColgroup(resizeState, _this2.table, tableNode, true);
|
|
474
|
+
});
|
|
470
475
|
}
|
|
471
476
|
this.containerWidth = containerWidth;
|
|
472
477
|
}
|
|
@@ -474,7 +479,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
474
479
|
key: "componentDidUpdate",
|
|
475
480
|
value: function componentDidUpdate(_, prevState) {
|
|
476
481
|
var _this$wrapper,
|
|
477
|
-
|
|
482
|
+
_this3 = this;
|
|
478
483
|
var _this$props10 = this.props,
|
|
479
484
|
view = _this$props10.view,
|
|
480
485
|
getNode = _this$props10.getNode,
|
|
@@ -498,7 +503,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
498
503
|
// that happens when a table is nested in expand and expand's width is
|
|
499
504
|
// changed via breakout button
|
|
500
505
|
window.requestAnimationFrame(function () {
|
|
501
|
-
|
|
506
|
+
_this3.overflowShadowsObserver = new OverflowShadowsObserver(_this3.updateShadowState, _this3.table, _this3.wrapper);
|
|
502
507
|
});
|
|
503
508
|
} else {
|
|
504
509
|
this.overflowShadowsObserver = new OverflowShadowsObserver(this.updateShadowState, this.table, this.wrapper);
|
|
@@ -564,7 +569,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
564
569
|
}, {
|
|
565
570
|
key: "render",
|
|
566
571
|
value: function render() {
|
|
567
|
-
var
|
|
572
|
+
var _this4 = this,
|
|
568
573
|
_classnames;
|
|
569
574
|
var _this$props11 = this.props,
|
|
570
575
|
view = _this$props11.view,
|
|
@@ -641,8 +646,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
641
646
|
tableContainerWidth: tableContainerWidth,
|
|
642
647
|
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
643
648
|
getScrollOffset: function getScrollOffset() {
|
|
644
|
-
var
|
|
645
|
-
return ((
|
|
649
|
+
var _this4$wrapper;
|
|
650
|
+
return ((_this4$wrapper = _this4.wrapper) === null || _this4$wrapper === void 0 ? void 0 : _this4$wrapper.scrollLeft) || 0;
|
|
646
651
|
},
|
|
647
652
|
tableWrapperHeight: this.state.tableWrapperHeight
|
|
648
653
|
}) : null;
|
|
@@ -692,12 +697,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
692
697
|
editorView: view,
|
|
693
698
|
node: node,
|
|
694
699
|
getScrollOffset: function getScrollOffset() {
|
|
695
|
-
var
|
|
696
|
-
return ((
|
|
700
|
+
var _this4$wrapper2;
|
|
701
|
+
return ((_this4$wrapper2 = _this4.wrapper) === null || _this4$wrapper2 === void 0 ? void 0 : _this4$wrapper2.scrollLeft) || 0;
|
|
697
702
|
},
|
|
698
703
|
getTableWrapperWidth: function getTableWrapperWidth() {
|
|
699
|
-
var
|
|
700
|
-
return ((
|
|
704
|
+
var _this4$wrapper3;
|
|
705
|
+
return ((_this4$wrapper3 = _this4.wrapper) === null || _this4$wrapper3 === void 0 ? void 0 : _this4$wrapper3.clientWidth) || 760;
|
|
701
706
|
}
|
|
702
707
|
}), /*#__PURE__*/React.createElement("div", {
|
|
703
708
|
style: shadowStyle(showBeforeShadow),
|
|
@@ -712,14 +717,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
712
717
|
}), /*#__PURE__*/React.createElement("div", {
|
|
713
718
|
className: classnames(ClassName.TABLE_NODE_WRAPPER),
|
|
714
719
|
ref: function ref(elem) {
|
|
715
|
-
|
|
720
|
+
_this4.wrapper = elem;
|
|
716
721
|
if (elem) {
|
|
717
|
-
|
|
722
|
+
_this4.props.contentDOM(elem);
|
|
718
723
|
var tableElement = elem.querySelector('table');
|
|
719
|
-
if (tableElement !==
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
724
|
+
if (tableElement !== _this4.table) {
|
|
725
|
+
_this4.table = tableElement;
|
|
726
|
+
_this4.createShadowSentinels(_this4.table);
|
|
727
|
+
_this4.observeTable(_this4.table);
|
|
723
728
|
}
|
|
724
729
|
}
|
|
725
730
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -4,7 +4,7 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
|
4
4
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
|
-
import {
|
|
7
|
+
import { getTableScalingPercent } from './misc';
|
|
8
8
|
/**
|
|
9
9
|
* This ensures the combined width of the columns (and tbody) of table is always smaller or equal
|
|
10
10
|
* than the table and table wrapper elements. This is necessary as there is no longer
|
|
@@ -24,14 +24,10 @@ export var generateColgroup = function generateColgroup(table, tableRef) {
|
|
|
24
24
|
// We slice here to guard against our colwidth array having more entries
|
|
25
25
|
// Than the we actually span. We'll patch the document at a later point.
|
|
26
26
|
if (tableRef) {
|
|
27
|
-
var
|
|
28
|
-
var tableWidth = table.attrs && table.attrs.width;
|
|
29
|
-
var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
|
|
30
|
-
var scalePercent = renderWidth / tableWidth;
|
|
31
|
-
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
27
|
+
var scalePercent = getTableScalingPercent(table, tableRef);
|
|
32
28
|
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
33
29
|
var fixedColWidth = getColWidthFix(width, map.width);
|
|
34
|
-
var scaledWidth = fixedColWidth *
|
|
30
|
+
var scaledWidth = fixedColWidth * scalePercent;
|
|
35
31
|
var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
36
32
|
cols.push(['col', {
|
|
37
33
|
style: "width: ".concat(finalWidth, "px;")
|
|
@@ -5,6 +5,7 @@ import { calcTableColumnWidths, containsClassName } from '@atlaskit/editor-commo
|
|
|
5
5
|
import { akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { hasTableBeenResized } from './colgroup';
|
|
8
|
+
import { MAX_SCALING_PERCENT } from './consts';
|
|
8
9
|
|
|
9
10
|
// Translates named layouts in number values.
|
|
10
11
|
export function getLayoutSize(tableLayout) {
|
|
@@ -89,4 +90,13 @@ export var getTableElementWidth = function getTableElementWidth(table) {
|
|
|
89
90
|
};
|
|
90
91
|
export var getTableContainerElementWidth = function getTableContainerElementWidth(table) {
|
|
91
92
|
return getTableContainerWidth(table);
|
|
93
|
+
};
|
|
94
|
+
export var getTableScalingPercent = function getTableScalingPercent(table, tableRef) {
|
|
95
|
+
var _tableRef$parentEleme;
|
|
96
|
+
var tableWidth = getTableContainerElementWidth(table);
|
|
97
|
+
var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
|
|
98
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
99
|
+
var scalePercent = (renderWidth - 1) / tableWidth;
|
|
100
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
101
|
+
return Math.min(scalePercent, 1);
|
|
92
102
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
4
5
|
import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
5
6
|
import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
|
|
6
7
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -8,8 +9,7 @@ import { getSelectedTableInfo } from '../../../utils';
|
|
|
8
9
|
import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
9
10
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
10
11
|
import { syncStickyRowToTable } from './dom';
|
|
11
|
-
import {
|
|
12
|
-
import { COLUMN_MIN_WIDTH, MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
12
|
+
import { getTableMaxWidth, getTableScalingPercent } from './misc';
|
|
13
13
|
export var getResizeState = function getResizeState(_ref) {
|
|
14
14
|
var minWidth = _ref.minWidth,
|
|
15
15
|
maxSize = _ref.maxSize,
|
|
@@ -19,6 +19,10 @@ export var getResizeState = function getResizeState(_ref) {
|
|
|
19
19
|
domAtPos = _ref.domAtPos,
|
|
20
20
|
_ref$isTableScalingEn = _ref.isTableScalingEnabled,
|
|
21
21
|
isTableScalingEnabled = _ref$isTableScalingEn === void 0 ? false : _ref$isTableScalingEn;
|
|
22
|
+
if (isTableScalingEnabled) {
|
|
23
|
+
var scalePercent = getTableScalingPercent(table, tableRef);
|
|
24
|
+
minWidth = Math.ceil(minWidth / scalePercent);
|
|
25
|
+
}
|
|
22
26
|
// If the table has been resized, we can use the column widths from the table node
|
|
23
27
|
if (hasTableBeenResized(table)) {
|
|
24
28
|
var _cols = calcTableColumnWidths(table).map(function (width, index) {
|
|
@@ -51,11 +55,12 @@ export var getResizeState = function getResizeState(_ref) {
|
|
|
51
55
|
var cols = Array.from(colgroupChildren).map(function (_, index) {
|
|
52
56
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
53
57
|
// to calculate the widths of the columns
|
|
54
|
-
if (isTableScalingEnabled
|
|
58
|
+
if (isTableScalingEnabled) {
|
|
59
|
+
var tableNodeWidth = getTableContainerWidth(table);
|
|
55
60
|
return {
|
|
56
61
|
index: index,
|
|
57
|
-
width:
|
|
58
|
-
minWidth:
|
|
62
|
+
width: tableNodeWidth / colgroupChildren.length,
|
|
63
|
+
minWidth: minWidth
|
|
59
64
|
};
|
|
60
65
|
}
|
|
61
66
|
var cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
@@ -83,25 +88,19 @@ export var updateColgroup = function updateColgroup(state, tableRef, tableNode,
|
|
|
83
88
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
84
89
|
var columnsCount = cols.length;
|
|
85
90
|
if (isTableScalingEnabled && tableNode) {
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
100
|
-
if (cols[i]) {
|
|
101
|
-
cols[i].style.width = "".concat(finalWidth, "px");
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
91
|
+
var scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
92
|
+
state.cols.filter(function (column) {
|
|
93
|
+
return column && !!column.width;
|
|
94
|
+
}) // if width is 0, we dont want to apply that.
|
|
95
|
+
.forEach(function (column, i) {
|
|
96
|
+
var fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
97
|
+
var scaledWidth = fixedColWidth * scalePercent;
|
|
98
|
+
var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
99
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
100
|
+
if (cols[i]) {
|
|
101
|
+
cols[i].style.width = "".concat(finalWidth, "px");
|
|
102
|
+
}
|
|
103
|
+
});
|
|
105
104
|
} else {
|
|
106
105
|
state.cols.filter(function (column) {
|
|
107
106
|
return column && !!column.width;
|
|
@@ -124,9 +124,9 @@ export var previewScaleTable = function previewScaleTable(tableRef, options, dom
|
|
|
124
124
|
syncStickyRowToTable(tableRef);
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
|
-
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos,
|
|
127
|
+
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) : scale(tableRef, options, domAtPos, false);
|
|
128
128
|
if (resizeState) {
|
|
129
|
-
updateColgroup(resizeState, tableRef, node,
|
|
129
|
+
updateColgroup(resizeState, tableRef, node, false);
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
132
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { bindKeymapArrayWithCommand, bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapArrayWithCommand, bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, selectTable, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
3
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
|
-
import { arrowLeftFromTable, arrowRightFromTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
|
|
4
|
+
import { arrowLeftFromTable, arrowRightFromTable, modASelectTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
|
|
5
5
|
export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
6
6
|
var list = {};
|
|
7
7
|
bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
|
|
@@ -13,6 +13,9 @@ export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
|
13
13
|
if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
|
|
14
14
|
bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
|
|
15
15
|
}
|
|
16
|
+
if (getBooleanFF('platform.editor.table.cmd-a-select-table')) {
|
|
17
|
+
bindKeymapWithCommand(selectTable.common, modASelectTable(editorSelectionAPI)(), list);
|
|
18
|
+
}
|
|
16
19
|
return keymap(list);
|
|
17
20
|
}
|
|
18
21
|
export default tableSelectionKeymapPlugin;
|
|
@@ -9,3 +9,4 @@ export declare const arrowRightFromTable: (editorSelectionAPI: ExtractInjectionA
|
|
|
9
9
|
export declare const selectColumns: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => (triggeredByKeyboard?: boolean) => Command;
|
|
10
10
|
export declare const selectRows: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => (triggeredByKeyboard?: boolean) => Command;
|
|
11
11
|
export declare const shiftArrowUpFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
12
|
+
export declare const modASelectTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
@@ -24,4 +24,5 @@ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getE
|
|
|
24
24
|
*/
|
|
25
25
|
export declare const getTableElementWidth: (table: PMNode) => number;
|
|
26
26
|
export declare const getTableContainerElementWidth: (table: PMNode) => number;
|
|
27
|
+
export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement) => number;
|
|
27
28
|
export {};
|
|
@@ -9,3 +9,4 @@ export declare const arrowRightFromTable: (editorSelectionAPI: ExtractInjectionA
|
|
|
9
9
|
export declare const selectColumns: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => (triggeredByKeyboard?: boolean) => Command;
|
|
10
10
|
export declare const selectRows: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => (triggeredByKeyboard?: boolean) => Command;
|
|
11
11
|
export declare const shiftArrowUpFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
12
|
+
export declare const modASelectTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
@@ -24,4 +24,5 @@ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getE
|
|
|
24
24
|
*/
|
|
25
25
|
export declare const getTableElementWidth: (table: PMNode) => number;
|
|
26
26
|
export declare const getTableContainerElementWidth: (table: PMNode) => number;
|
|
27
|
+
export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement) => number;
|
|
27
28
|
export {};
|
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.7",
|
|
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.5.2",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.0.14",
|
|
33
|
-
"@atlaskit/editor-common": "^78.
|
|
33
|
+
"@atlaskit/editor-common": "^78.12.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": "^4.
|
|
49
|
+
"@atlaskit/primitives": "^4.1.0",
|
|
50
50
|
"@atlaskit/theme": "^12.6.0",
|
|
51
51
|
"@atlaskit/toggle": "^13.0.0",
|
|
52
52
|
"@atlaskit/tokens": "^1.41.0",
|
|
@@ -142,6 +142,9 @@
|
|
|
142
142
|
},
|
|
143
143
|
"platform.editor.transform-slice-for-nested-expand": {
|
|
144
144
|
"type": "boolean"
|
|
145
|
+
},
|
|
146
|
+
"platform.editor.table.cmd-a-select-table": {
|
|
147
|
+
"type": "boolean"
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
}
|
|
@@ -589,3 +589,36 @@ export const shiftArrowUpFromTable =
|
|
|
589
589
|
|
|
590
590
|
return false;
|
|
591
591
|
};
|
|
592
|
+
|
|
593
|
+
export const modASelectTable =
|
|
594
|
+
(
|
|
595
|
+
editorSelectionAPI:
|
|
596
|
+
| ExtractInjectionAPI<typeof tablePlugin>['selection']
|
|
597
|
+
| undefined,
|
|
598
|
+
) =>
|
|
599
|
+
(): Command =>
|
|
600
|
+
(state, dispatch) => {
|
|
601
|
+
const { selection } = state;
|
|
602
|
+
const table = findTable(selection);
|
|
603
|
+
|
|
604
|
+
if (!table) {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
const { $from, $to } = selection;
|
|
608
|
+
|
|
609
|
+
const tableSelected = isTableSelected(selection);
|
|
610
|
+
|
|
611
|
+
if (
|
|
612
|
+
!tableSelected &&
|
|
613
|
+
$from.pos > table.start + 1 &&
|
|
614
|
+
$to.pos < table.start + table.node.nodeSize
|
|
615
|
+
) {
|
|
616
|
+
return selectFullTable(editorSelectionAPI)({
|
|
617
|
+
node: table.node,
|
|
618
|
+
startPos: table.start,
|
|
619
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
620
|
+
})(state, dispatch);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return false;
|
|
624
|
+
};
|
|
@@ -338,7 +338,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
338
338
|
return;
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
const
|
|
341
|
+
const tableNodeWidth = getTableContainerWidth(tableNode);
|
|
342
342
|
const shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
343
343
|
|
|
344
344
|
const { width: containerWidthValue } = containerWidth;
|
|
@@ -355,7 +355,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
355
355
|
isTableScalingEnabled: true,
|
|
356
356
|
});
|
|
357
357
|
|
|
358
|
-
|
|
358
|
+
// Request animation frame required for Firefox
|
|
359
|
+
requestAnimationFrame(() => {
|
|
360
|
+
updateColgroup(resizeState, this.table!, tableNode, true);
|
|
361
|
+
});
|
|
359
362
|
}
|
|
360
363
|
this.containerWidth = containerWidth;
|
|
361
364
|
}
|
|
@@ -5,7 +5,7 @@ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { getTableScalingPercent } from './misc';
|
|
9
9
|
|
|
10
10
|
type Col = Array<string | { [name: string]: string }>;
|
|
11
11
|
|
|
@@ -29,13 +29,10 @@ export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
|
|
|
29
29
|
// We slice here to guard against our colwidth array having more entries
|
|
30
30
|
// Than the we actually span. We'll patch the document at a later point.
|
|
31
31
|
if (tableRef) {
|
|
32
|
-
const
|
|
33
|
-
let renderWidth = tableRef.parentElement?.clientWidth || 760;
|
|
34
|
-
let scalePercent = renderWidth / tableWidth;
|
|
35
|
-
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
32
|
+
const scalePercent = getTableScalingPercent(table, tableRef);
|
|
36
33
|
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
37
34
|
const fixedColWidth = getColWidthFix(width, map.width);
|
|
38
|
-
const scaledWidth = fixedColWidth *
|
|
35
|
+
const scaledWidth = fixedColWidth * scalePercent;
|
|
39
36
|
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
40
37
|
cols.push([
|
|
41
38
|
'col',
|
|
@@ -31,6 +31,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
31
31
|
import type { TableOptions } from '../../../nodeviews/types';
|
|
32
32
|
|
|
33
33
|
import { hasTableBeenResized } from './colgroup';
|
|
34
|
+
import { MAX_SCALING_PERCENT } from './consts';
|
|
34
35
|
|
|
35
36
|
// Translates named layouts in number values.
|
|
36
37
|
export function getLayoutSize(
|
|
@@ -156,3 +157,15 @@ export const getTableElementWidth = (table: PMNode) => {
|
|
|
156
157
|
export const getTableContainerElementWidth = (table: PMNode) => {
|
|
157
158
|
return getTableContainerWidth(table);
|
|
158
159
|
};
|
|
160
|
+
|
|
161
|
+
export const getTableScalingPercent = (
|
|
162
|
+
table: PMNode,
|
|
163
|
+
tableRef: HTMLElement,
|
|
164
|
+
) => {
|
|
165
|
+
const tableWidth = getTableContainerElementWidth(table);
|
|
166
|
+
let renderWidth = tableRef.parentElement?.clientWidth || tableWidth;
|
|
167
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
168
|
+
let scalePercent = (renderWidth - 1) / tableWidth;
|
|
169
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
170
|
+
return Math.min(scalePercent, 1);
|
|
171
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
2
3
|
import {
|
|
3
4
|
tableCellMinWidth,
|
|
4
5
|
tableNewColumnMinWidth,
|
|
@@ -20,15 +21,9 @@ import {
|
|
|
20
21
|
import type { ColumnState } from './column-state';
|
|
21
22
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
22
23
|
import { syncStickyRowToTable } from './dom';
|
|
23
|
-
import {
|
|
24
|
+
import { getTableMaxWidth, getTableScalingPercent } from './misc';
|
|
24
25
|
import type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
25
26
|
|
|
26
|
-
import {
|
|
27
|
-
COLUMN_MIN_WIDTH,
|
|
28
|
-
MAX_SCALING_PERCENT,
|
|
29
|
-
TABLE_DEFAULT_WIDTH,
|
|
30
|
-
} from './index';
|
|
31
|
-
|
|
32
27
|
export const getResizeState = ({
|
|
33
28
|
minWidth,
|
|
34
29
|
maxSize,
|
|
@@ -46,6 +41,10 @@ export const getResizeState = ({
|
|
|
46
41
|
domAtPos: (pos: number) => { node: Node; offset: number };
|
|
47
42
|
isTableScalingEnabled: boolean;
|
|
48
43
|
}): ResizeState => {
|
|
44
|
+
if (isTableScalingEnabled) {
|
|
45
|
+
const scalePercent = getTableScalingPercent(table, tableRef);
|
|
46
|
+
minWidth = Math.ceil(minWidth / scalePercent);
|
|
47
|
+
}
|
|
49
48
|
// If the table has been resized, we can use the column widths from the table node
|
|
50
49
|
if (hasTableBeenResized(table)) {
|
|
51
50
|
const cols = calcTableColumnWidths(table).map((width, index) => ({
|
|
@@ -79,11 +78,12 @@ export const getResizeState = ({
|
|
|
79
78
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
80
79
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
81
80
|
// to calculate the widths of the columns
|
|
82
|
-
if (isTableScalingEnabled
|
|
81
|
+
if (isTableScalingEnabled) {
|
|
82
|
+
const tableNodeWidth = getTableContainerWidth(table);
|
|
83
83
|
return {
|
|
84
84
|
index,
|
|
85
|
-
width:
|
|
86
|
-
minWidth
|
|
85
|
+
width: tableNodeWidth / colgroupChildren.length,
|
|
86
|
+
minWidth,
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
@@ -116,24 +116,18 @@ export const updateColgroup = (
|
|
|
116
116
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
117
117
|
const columnsCount = cols.length;
|
|
118
118
|
if (isTableScalingEnabled && tableNode) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
132
|
-
if (cols[i]) {
|
|
133
|
-
cols[i].style.width = `${finalWidth}px`;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
119
|
+
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
120
|
+
state.cols
|
|
121
|
+
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
122
|
+
.forEach((column, i) => {
|
|
123
|
+
const fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
124
|
+
const scaledWidth = fixedColWidth * scalePercent;
|
|
125
|
+
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
126
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
127
|
+
if (cols[i]) {
|
|
128
|
+
cols[i].style.width = `${finalWidth}px`;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
137
131
|
} else {
|
|
138
132
|
state.cols
|
|
139
133
|
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
@@ -182,18 +182,11 @@ export const previewScaleTable = (
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
const resizeState = parentWidth
|
|
185
|
-
? scaleWithParent(
|
|
186
|
-
|
|
187
|
-
parentWidth,
|
|
188
|
-
node,
|
|
189
|
-
start,
|
|
190
|
-
domAtPos,
|
|
191
|
-
isTableScalingEnabled,
|
|
192
|
-
)
|
|
193
|
-
: scale(tableRef, options, domAtPos, isTableScalingEnabled);
|
|
185
|
+
? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false)
|
|
186
|
+
: scale(tableRef, options, domAtPos, false);
|
|
194
187
|
|
|
195
188
|
if (resizeState) {
|
|
196
|
-
updateColgroup(resizeState, tableRef, node,
|
|
189
|
+
updateColgroup(resizeState, tableRef, node, false);
|
|
197
190
|
}
|
|
198
191
|
};
|
|
199
192
|
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
moveRight,
|
|
6
6
|
selectColumn,
|
|
7
7
|
selectRow,
|
|
8
|
+
selectTable,
|
|
8
9
|
shiftArrowUp,
|
|
9
10
|
} from '@atlaskit/editor-common/keymaps';
|
|
10
11
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
@@ -15,6 +16,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
15
16
|
import {
|
|
16
17
|
arrowLeftFromTable,
|
|
17
18
|
arrowRightFromTable,
|
|
19
|
+
modASelectTable,
|
|
18
20
|
selectColumns,
|
|
19
21
|
selectRows,
|
|
20
22
|
shiftArrowUpFromTable,
|
|
@@ -62,6 +64,14 @@ export function tableSelectionKeymapPlugin(
|
|
|
62
64
|
);
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
if (getBooleanFF('platform.editor.table.cmd-a-select-table')) {
|
|
68
|
+
bindKeymapWithCommand(
|
|
69
|
+
selectTable.common!,
|
|
70
|
+
modASelectTable(editorSelectionAPI)(),
|
|
71
|
+
list,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
65
75
|
return keymap(list) as SafePlugin;
|
|
66
76
|
}
|
|
67
77
|
|