@atlaskit/editor-plugin-table 7.2.1 → 7.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/nodeviews/TableComponent.js +11 -7
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +11 -25
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +13 -3
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +7 -3
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/nodeviews/TableComponent.js +9 -5
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +7 -3
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/nodeviews/TableComponent.js +11 -7
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
- package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
- package/dist/esm/ui/TableFloatingColumnControls/index.js +7 -3
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -0
- package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
- package/dist/types/ui/TableFloatingColumnControls/index.d.ts +1 -0
- package/dist/types/utils/drag-menu.d.ts +4 -1
- package/dist/types/utils/merged-cells.d.ts +2 -0
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +1 -0
- package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
- package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
- package/package.json +9 -16
- package/src/nodeviews/TableComponent.tsx +1 -0
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +6 -27
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -1
- package/src/ui/TableFloatingColumnControls/index.tsx +5 -0
- package/src/utils/drag-menu.ts +94 -20
- package/src/utils/merged-cells.ts +78 -0
- package/tsconfig.dev.json +0 -69
- package/tsconfig.json +2 -871
- package/examples/99-testing.tsx +0 -140
- package/examples/config.jsonc +0 -14
- package/src/__tests__/unit/analytics.ts +0 -888
- package/src/__tests__/unit/collab.ts +0 -93
- package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
- package/src/__tests__/unit/commands/insert.ts +0 -137
- package/src/__tests__/unit/commands/misc.ts +0 -185
- package/src/__tests__/unit/commands/sort.ts +0 -128
- package/src/__tests__/unit/commands.ts +0 -745
- package/src/__tests__/unit/copy-button.ts +0 -22
- package/src/__tests__/unit/copy-paste.ts +0 -677
- package/src/__tests__/unit/event-handlers/index.ts +0 -125
- package/src/__tests__/unit/event-handlers.ts +0 -296
- package/src/__tests__/unit/fix-tables.ts +0 -164
- package/src/__tests__/unit/get-toolbar-config.ts +0 -127
- package/src/__tests__/unit/handlers.ts +0 -98
- package/src/__tests__/unit/hover-selection.ts +0 -230
- package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
- package/src/__tests__/unit/index.ts +0 -912
- package/src/__tests__/unit/layout.ts +0 -146
- package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
- package/src/__tests__/unit/nodeviews/cell.ts +0 -132
- package/src/__tests__/unit/nodeviews/table.ts +0 -129
- package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
- package/src/__tests__/unit/pm-plugins/main.ts +0 -214
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
- package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
- package/src/__tests__/unit/sort-column.ts +0 -399
- package/src/__tests__/unit/toolbar.ts +0 -512
- package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
- package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
- package/src/__tests__/unit/transforms/merging.ts +0 -392
- package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
- package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
- package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
- package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
- package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
- package/src/__tests__/unit/ui/RowControls.tsx +0 -294
- package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
- package/src/__tests__/unit/undo-redo.ts +0 -220
- package/src/__tests__/unit/utils/analytics.ts +0 -98
- package/src/__tests__/unit/utils/collapse.ts +0 -57
- package/src/__tests__/unit/utils/column-controls.ts +0 -205
- package/src/__tests__/unit/utils/dom.ts +0 -180
- package/src/__tests__/unit/utils/merged-cells.ts +0 -156
- package/src/__tests__/unit/utils/nodes.ts +0 -79
- package/src/__tests__/unit/utils/row-controls.ts +0 -195
- package/src/__tests__/unit/utils/table.ts +0 -96
- package/src/__tests__/unit/utils.ts +0 -670
- package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
- package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-should-remove-the-table-column-on-click-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/copy-button-ts-floating-toolbar-copy-button-table-target-node-displays-blue-border-when-copy-button-is-hovered-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-2-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-3-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +0 -3
- package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
- package/src/__tests__/visual-regression/copy-button.ts +0 -181
- package/src/__tests__/visual-regression/index.ts +0 -62
- package/src/__tests__/visual-regression/sticky-header.ts +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#68572](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/68572) [`15d407fe5143`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/15d407fe5143) - Upgrading @atlaskit/editor-prosemirror dependency
|
|
8
|
+
- [#70707](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70707) [`01c10b920070`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/01c10b920070) - [ux] Move options in drag menu now have disabled state when target has merged cells.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 7.2.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#70342](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70342) [`6862cba17f31`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6862cba17f31) - Fix drop functionality when dragging in overflown table
|
|
16
|
+
|
|
3
17
|
## 7.2.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -471,8 +471,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
471
471
|
}, {
|
|
472
472
|
key: "render",
|
|
473
473
|
value: function render() {
|
|
474
|
-
var
|
|
475
|
-
|
|
474
|
+
var _this3 = this,
|
|
475
|
+
_classnames;
|
|
476
476
|
var _this$props10 = this.props,
|
|
477
477
|
view = _this$props10.view,
|
|
478
478
|
getNode = _this$props10.getNode,
|
|
@@ -544,7 +544,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
544
544
|
stickyHeader: this.state.stickyHeader,
|
|
545
545
|
getEditorFeatureFlags: getEditorFeatureFlags,
|
|
546
546
|
tableContainerWidth: tableContainerWidth,
|
|
547
|
-
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled
|
|
547
|
+
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
548
|
+
getScrollOffset: function getScrollOffset() {
|
|
549
|
+
var _this3$wrapper;
|
|
550
|
+
return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
|
|
551
|
+
}
|
|
548
552
|
}) : null;
|
|
549
553
|
var shadowPadding = allowControls && tableActive ? -_editorSharedStyles.akEditorTableToolbarSize : _styles.tableMarginSides;
|
|
550
554
|
var shadowStyle = (0, _memoizeOne.default)(function (visible) {
|
|
@@ -592,12 +596,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
592
596
|
editorView: view,
|
|
593
597
|
node: node,
|
|
594
598
|
getScrollOffset: function getScrollOffset() {
|
|
595
|
-
var _this3$
|
|
596
|
-
return ((_this3$
|
|
599
|
+
var _this3$wrapper2;
|
|
600
|
+
return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.scrollLeft) || 0;
|
|
597
601
|
},
|
|
598
602
|
getTableWrapperWidth: function getTableWrapperWidth() {
|
|
599
|
-
var _this3$
|
|
600
|
-
return ((_this3$
|
|
603
|
+
var _this3$wrapper3;
|
|
604
|
+
return ((_this3$wrapper3 = _this3.wrapper) === null || _this3$wrapper3 === void 0 ? void 0 : _this3$wrapper3.clientWidth) || 760;
|
|
601
605
|
}
|
|
602
606
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
603
607
|
style: shadowStyle(showBeforeShadow),
|
|
@@ -11,6 +11,7 @@ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
|
11
11
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
12
12
|
var _utils2 = require("../../utils");
|
|
13
13
|
var _analytics2 = require("../../utils/analytics");
|
|
14
|
+
var _dragMenu = require("../../utils/drag-menu");
|
|
14
15
|
var _commands = require("./commands");
|
|
15
16
|
var clearDropTargetWithAnalytics = exports.clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
|
|
16
17
|
return function (inputMethod, sourceType, sourceIndexes, status, tr) {
|
|
@@ -91,30 +92,13 @@ var moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalyticsViaShort
|
|
|
91
92
|
if (selectedIndexes.length === 0) {
|
|
92
93
|
return false;
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
-
// const sourceIndex = selectedIndexes[0];
|
|
96
|
-
// we can move only by one row/column
|
|
97
|
-
// 'direction' can only be 1 (for right or down) or -1 (for left or up)
|
|
98
|
-
var targetIndex = Math[direction < 0 ? 'min' : 'max'].apply(Math, (0, _toConsumableArray2.default)(selectedIndexes)) + direction;
|
|
99
|
-
|
|
100
|
-
// We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
|
|
101
95
|
var _getSelectedTableInfo3 = (0, _utils2.getSelectedTableInfo)(selection),
|
|
102
96
|
totalRowCount = _getSelectedTableInfo3.totalRowCount,
|
|
103
97
|
totalColumnCount = _getSelectedTableInfo3.totalColumnCount;
|
|
104
|
-
|
|
105
|
-
if (!isValidTargetIndex) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// We can move only if there are no merged cells in the source or target row/column
|
|
110
|
-
var hasMergedCellsInSource = isRow ? (0, _utils2.hasMergedCellsInRow)(selectedIndexes)(selection) : (0, _utils2.hasMergedCellsInColumn)(selectedIndexes)(selection);
|
|
111
|
-
if (hasMergedCellsInSource) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
var hasMergedCellsInTarget = isRow ? (0, _utils2.hasMergedCellsInRow)(targetIndex)(selection) : (0, _utils2.hasMergedCellsInColumn)(targetIndex)(selection);
|
|
115
|
-
if (hasMergedCellsInTarget) {
|
|
98
|
+
if (!(0, _dragMenu.canMove)(sourceType, direction, isRow ? totalRowCount : totalColumnCount, selection, selectionRect)) {
|
|
116
99
|
return false;
|
|
117
100
|
}
|
|
101
|
+
var targetIndex = (0, _dragMenu.getTargetIndex)(selectedIndexes, direction);
|
|
118
102
|
return moveSourceWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
|
|
119
103
|
};
|
|
120
104
|
};
|
|
@@ -7,14 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.ColumnControls = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
10
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
10
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
12
11
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
13
|
-
var
|
|
12
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
14
13
|
var _commands = require("../../../commands");
|
|
15
14
|
var _commands2 = require("../../../pm-plugins/drag-and-drop/commands");
|
|
16
15
|
var _types = require("../../../types");
|
|
17
|
-
var
|
|
16
|
+
var _utils2 = require("../../../utils");
|
|
18
17
|
var _DragHandle = require("../../DragHandle");
|
|
19
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -22,11 +21,11 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
22
21
|
|
|
23
22
|
var getSelectedColumns = function getSelectedColumns(selection) {
|
|
24
23
|
if (selection instanceof _editorTables.CellSelection && selection.isColSelection()) {
|
|
25
|
-
var rect = (0,
|
|
24
|
+
var rect = (0, _utils.getSelectionRect)(selection);
|
|
26
25
|
if (!rect) {
|
|
27
26
|
return [];
|
|
28
27
|
}
|
|
29
|
-
return (0,
|
|
28
|
+
return (0, _utils2.getSelectedColumnIndexes)(rect);
|
|
30
29
|
}
|
|
31
30
|
return [];
|
|
32
31
|
};
|
|
@@ -46,7 +45,8 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
|
|
|
46
45
|
isTableHovered = _ref.isTableHovered,
|
|
47
46
|
tableContainerWidth = _ref.tableContainerWidth,
|
|
48
47
|
isNumberColumnEnabled = _ref.isNumberColumnEnabled,
|
|
49
|
-
isDragging = _ref.isDragging
|
|
48
|
+
isDragging = _ref.isDragging,
|
|
49
|
+
getScrollOffset = _ref.getScrollOffset;
|
|
50
50
|
var columnControlsRef = (0, _react.useRef)(null);
|
|
51
51
|
var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
|
|
52
52
|
return (
|
|
@@ -56,7 +56,7 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
|
|
|
56
56
|
);
|
|
57
57
|
}).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
|
|
58
58
|
// TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
|
|
59
|
-
var columnParams = (0,
|
|
59
|
+
var columnParams = (0, _utils2.getRowsParams)(colWidths !== null && colWidths !== void 0 ? colWidths : []);
|
|
60
60
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
61
61
|
var selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
62
62
|
var firstRow = tableRef.querySelector('tr');
|
|
@@ -116,24 +116,10 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
|
|
|
116
116
|
var colIndexes = (0, _react.useMemo)(function () {
|
|
117
117
|
return [colIndex];
|
|
118
118
|
}, [colIndex]);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var _tableWrapper$scrollL;
|
|
124
|
-
columnControlsRef.current.scrollLeft = (_tableWrapper$scrollL = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.scrollLeft) !== null && _tableWrapper$scrollL !== void 0 ? _tableWrapper$scrollL : 0;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, [stickyTop, tableWrapper]);
|
|
128
|
-
(0, _react.useEffect)(function () {
|
|
129
|
-
handleScroll();
|
|
130
|
-
}, [handleScroll]);
|
|
131
|
-
(0, _react.useEffect)(function () {
|
|
132
|
-
tableWrapper === null || tableWrapper === void 0 || tableWrapper.addEventListener('scroll', handleScroll);
|
|
133
|
-
return function () {
|
|
134
|
-
tableWrapper === null || tableWrapper === void 0 || tableWrapper.removeEventListener('scroll', handleScroll);
|
|
135
|
-
};
|
|
136
|
-
}, [tableWrapper, handleScroll]);
|
|
119
|
+
if (stickyTop && columnControlsRef.current) {
|
|
120
|
+
var _getScrollOffset;
|
|
121
|
+
columnControlsRef.current.scrollLeft = (_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0;
|
|
122
|
+
}
|
|
137
123
|
var generateHandleByType = function generateHandleByType(type) {
|
|
138
124
|
var _rowHeights$reduce, _colWidths$reduce;
|
|
139
125
|
if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.ColumnDropTargets = void 0;
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _types = require("../../../types");
|
|
10
10
|
var _ColumnDropTarget = require("./ColumnDropTarget");
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
13
|
var ColumnDropTargets = exports.ColumnDropTargets = function ColumnDropTargets(_ref) {
|
|
12
14
|
var tableRef = _ref.tableRef,
|
|
13
15
|
tableHeight = _ref.tableHeight,
|
|
14
16
|
localId = _ref.localId,
|
|
15
|
-
colWidths = _ref.colWidths
|
|
17
|
+
colWidths = _ref.colWidths,
|
|
18
|
+
isHeaderSticky = _ref.isHeaderSticky,
|
|
19
|
+
getScrollOffset = _ref.getScrollOffset;
|
|
20
|
+
var dropTargetRef = (0, _react.useRef)(null);
|
|
16
21
|
if (!tableRef) {
|
|
17
22
|
return null;
|
|
18
23
|
}
|
|
24
|
+
if (isHeaderSticky && dropTargetRef.current) {
|
|
25
|
+
var _getScrollOffset;
|
|
26
|
+
dropTargetRef.current.style.marginLeft = "-".concat((_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0, "px");
|
|
27
|
+
}
|
|
19
28
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
29
|
+
ref: dropTargetRef,
|
|
20
30
|
className: _types.TableCssClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS,
|
|
21
31
|
contentEditable: false
|
|
22
32
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -31,7 +31,8 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
|
|
|
31
31
|
isInDanger = _ref.isInDanger,
|
|
32
32
|
isTableHovered = _ref.isTableHovered,
|
|
33
33
|
tableContainerWidth = _ref.tableContainerWidth,
|
|
34
|
-
isNumberColumnEnabled = _ref.isNumberColumnEnabled
|
|
34
|
+
isNumberColumnEnabled = _ref.isNumberColumnEnabled,
|
|
35
|
+
getScrollOffset = _ref.getScrollOffset;
|
|
35
36
|
var _useState = (0, _react.useState)({
|
|
36
37
|
width: 0,
|
|
37
38
|
height: 0
|
|
@@ -136,12 +137,15 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
|
|
|
136
137
|
hasHeaderColumn: hasHeaderColumn,
|
|
137
138
|
tableContainerWidth: tableContainerWidth,
|
|
138
139
|
isNumberColumnEnabled: isNumberColumnEnabled,
|
|
139
|
-
isDragging: isDragging
|
|
140
|
+
isDragging: isDragging,
|
|
141
|
+
getScrollOffset: getScrollOffset
|
|
140
142
|
}), isDragging && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
|
|
141
143
|
tableRef: tableRef,
|
|
144
|
+
isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
|
|
142
145
|
tableHeight: tableRect.height,
|
|
143
146
|
localId: currentNodeLocalId,
|
|
144
|
-
colWidths: colWidths
|
|
147
|
+
colWidths: colWidths,
|
|
148
|
+
getScrollOffset: getScrollOffset
|
|
145
149
|
}));
|
|
146
150
|
};
|
|
147
151
|
var _default = exports.default = TableFloatingColumnControls;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.getDragMenuConfig = void 0;
|
|
7
|
+
exports.getTargetIndex = exports.getDragMenuConfig = exports.canMove = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _customSteps = require("@atlaskit/custom-steps");
|
|
10
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -26,14 +26,36 @@ var _resizeState = require("../pm-plugins/table-resizing/utils/resize-state");
|
|
|
26
26
|
var _toolbar = require("../toolbar");
|
|
27
27
|
var _transforms = require("../transforms");
|
|
28
28
|
var _icons = require("../ui/icons");
|
|
29
|
+
var _mergedCells = require("./merged-cells");
|
|
29
30
|
var _selection = require("./selection");
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
return index !== undefined && index > min;
|
|
31
|
+
var getTargetIndex = exports.getTargetIndex = function getTargetIndex(selectedIndexes, direction) {
|
|
32
|
+
return Math[direction < 0 ? 'min' : 'max'].apply(Math, (0, _toConsumableArray2.default)(selectedIndexes)) + direction;
|
|
33
33
|
};
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
var canMove = exports.canMove = function canMove(sourceType, direction, totalItemsOfSourceTypeCount, selection, selectionRect) {
|
|
35
|
+
if (!selectionRect) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
var isRow = sourceType === 'table-row';
|
|
39
|
+
var selectedIndexes = isRow ? (0, _selection.getSelectedRowIndexes)(selectionRect) : (0, _selection.getSelectedColumnIndexes)(selectionRect);
|
|
40
|
+
var targetIndex = getTargetIndex(selectedIndexes, direction);
|
|
41
|
+
var isValidTargetIndex = targetIndex >= 0 && targetIndex < totalItemsOfSourceTypeCount;
|
|
42
|
+
if (!isValidTargetIndex) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// We can't move column when target has merges with other columns
|
|
47
|
+
// We can't move row when target has merges with other rows
|
|
48
|
+
var hasMergedCellsInTarget = isRow ? (0, _mergedCells.hasMergedCellsWithRowNextToRowIndex)(targetIndex, selection) : (0, _mergedCells.hasMergedCellsWithColumnNextToColumnIndex)(targetIndex, selection);
|
|
49
|
+
if (hasMergedCellsInTarget) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Currently we can't move in any direction if there are merged cells in the source
|
|
54
|
+
var hasMergedCellsInSource = isRow ? (0, _mergedCells.hasMergedCellsInRow)(selectedIndexes)(selection) : (0, _mergedCells.hasMergedCellsInColumn)(selectedIndexes)(selection);
|
|
55
|
+
if (hasMergedCellsInSource) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
37
59
|
};
|
|
38
60
|
var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
|
|
39
61
|
var rect = (0, _toolbar.getClosestSelectionRect)(state);
|
|
@@ -44,6 +66,7 @@ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
|
|
|
44
66
|
return false;
|
|
45
67
|
};
|
|
46
68
|
var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI) {
|
|
69
|
+
var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
|
|
47
70
|
var addOptions = direction === 'row' ? [{
|
|
48
71
|
label: 'above',
|
|
49
72
|
offset: 0,
|
|
@@ -65,13 +88,12 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
65
88
|
icon: _icons.AddColRightIcon,
|
|
66
89
|
keymap: _keymaps.addColumnAfter
|
|
67
90
|
}];
|
|
91
|
+
var selection = editorView.state.selection;
|
|
68
92
|
var moveOptions = direction === 'row' ? [{
|
|
69
93
|
label: 'up',
|
|
70
94
|
icon: _arrowUp.default,
|
|
71
95
|
keymap: _keymaps.moveRowUp,
|
|
72
|
-
canMove:
|
|
73
|
-
return canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top);
|
|
74
|
-
},
|
|
96
|
+
canMove: canDrag && canMove('table-row', -1, (_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0, selection, selectionRect),
|
|
75
97
|
getOriginIndexes: _selection.getSelectedRowIndexes,
|
|
76
98
|
getTargetIndex: function getTargetIndex(selectionRect) {
|
|
77
99
|
return selectionRect.top - 1;
|
|
@@ -80,10 +102,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
80
102
|
label: 'down',
|
|
81
103
|
icon: _arrowDown.default,
|
|
82
104
|
keymap: _keymaps.moveRowDown,
|
|
83
|
-
canMove:
|
|
84
|
-
var _selectionRect$bottom, _tableMap$height;
|
|
85
|
-
return canDrag && canIncrease(((_selectionRect$bottom = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom) !== null && _selectionRect$bottom !== void 0 ? _selectionRect$bottom : 0) - 1, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
|
|
86
|
-
},
|
|
105
|
+
canMove: canDrag && canMove('table-row', 1, (_tableMap$height2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height2 !== void 0 ? _tableMap$height2 : 0, selection, selectionRect),
|
|
87
106
|
getOriginIndexes: _selection.getSelectedRowIndexes,
|
|
88
107
|
getTargetIndex: function getTargetIndex(selectionRect) {
|
|
89
108
|
return selectionRect.bottom;
|
|
@@ -92,9 +111,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
92
111
|
label: 'left',
|
|
93
112
|
icon: _arrowLeft.default,
|
|
94
113
|
keymap: _keymaps.moveColumnLeft,
|
|
95
|
-
canMove:
|
|
96
|
-
return canDrag && canDecrease(selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left);
|
|
97
|
-
},
|
|
114
|
+
canMove: canDrag && canMove('table-column', -1, (_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0, selection, selectionRect),
|
|
98
115
|
getOriginIndexes: _selection.getSelectedColumnIndexes,
|
|
99
116
|
getTargetIndex: function getTargetIndex(selectionRect) {
|
|
100
117
|
return selectionRect.left - 1;
|
|
@@ -103,10 +120,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
103
120
|
label: 'right',
|
|
104
121
|
icon: _arrowRight.default,
|
|
105
122
|
keymap: _keymaps.moveColumnRight,
|
|
106
|
-
canMove:
|
|
107
|
-
var _selectionRect$right, _tableMap$width;
|
|
108
|
-
return canDrag && canIncrease(((_selectionRect$right = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right) !== null && _selectionRect$right !== void 0 ? _selectionRect$right : 0) - 1, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
|
|
109
|
-
},
|
|
123
|
+
canMove: canDrag && canMove('table-column', 1, (_tableMap$width2 = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width2 !== void 0 ? _tableMap$width2 : 0, selection, selectionRect),
|
|
110
124
|
getOriginIndexes: _selection.getSelectedColumnIndexes,
|
|
111
125
|
getTargetIndex: function getTargetIndex(selectionRect) {
|
|
112
126
|
return selectionRect.right;
|
|
@@ -191,10 +205,10 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
191
205
|
return {
|
|
192
206
|
id: "move_".concat(direction, "_").concat(label),
|
|
193
207
|
title: "Move ".concat(direction, " ").concat(label),
|
|
194
|
-
disabled: !canMove
|
|
208
|
+
disabled: !canMove,
|
|
195
209
|
icon: icon,
|
|
196
210
|
onClick: function onClick(state, dispatch) {
|
|
197
|
-
if (canMove
|
|
211
|
+
if (canMove) {
|
|
198
212
|
requestAnimationFrame(function () {
|
|
199
213
|
(0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), getOriginIndexes(selectionRect), getTargetIndex(selectionRect))(editorView.state, editorView.dispatch);
|
|
200
214
|
});
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.hasMergedCellsInRow = exports.hasMergedCellsInColumn = exports.hasMergedCellsInBetween = void 0;
|
|
7
|
+
exports.hasMergedCellsWithRowNextToRowIndex = exports.hasMergedCellsWithColumnNextToColumnIndex = exports.hasMergedCellsInRow = exports.hasMergedCellsInColumn = exports.hasMergedCellsInBetween = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
10
10
|
var hasMergedCells = function hasMergedCells(indexes, normalizeRect) {
|
|
@@ -137,4 +137,69 @@ var hasMergedCellsInBetween = exports.hasMergedCellsInBetween = function hasMerg
|
|
|
137
137
|
return mergedCellsInRectArr[1].includes(cell);
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Checks if any cell in the column with colIndex is merged with a cell in a column to the left or to the right of it.
|
|
143
|
+
// colIndex is a logical index of the column. It starts at 0 and goes up to tableMap.width - 1.
|
|
144
|
+
var hasMergedCellsWithColumnNextToColumnIndex = exports.hasMergedCellsWithColumnNextToColumnIndex = function hasMergedCellsWithColumnNextToColumnIndex(colIndex, selection) {
|
|
145
|
+
var table = (0, _editorTables.findTable)(selection);
|
|
146
|
+
if (!table) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
var tableMap = _editorTables.TableMap.get(table.node);
|
|
150
|
+
var width = tableMap.width;
|
|
151
|
+
if (width <= 1) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (colIndex < 0 || colIndex > width - 1) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
var map = tableMap.map;
|
|
158
|
+
// j is an index in the tableMap.map array. tableMap.map is a flat array.
|
|
159
|
+
// Each item of this array contains a number.
|
|
160
|
+
// The number represents the position of the corresponding cell in the tableMap. It exists for each cell.
|
|
161
|
+
// If there are merged cells, their positions will be represented by the same number.
|
|
162
|
+
var isFirstColumn = colIndex === 0;
|
|
163
|
+
var isLastColumn = colIndex === width - 1;
|
|
164
|
+
for (var j = colIndex; j < map.length; j += width) {
|
|
165
|
+
if (!isFirstColumn && map[j] === map[j - 1] ||
|
|
166
|
+
// compare with a cell in the column on the left
|
|
167
|
+
!isLastColumn && map[j] === map[j + 1] // compare with a cell in the column on the right
|
|
168
|
+
) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// Checks if any cell in the row with rowIndex is merged with a cell in a row above or below it.
|
|
176
|
+
var hasMergedCellsWithRowNextToRowIndex = exports.hasMergedCellsWithRowNextToRowIndex = function hasMergedCellsWithRowNextToRowIndex(rowIndex, selection) {
|
|
177
|
+
var table = (0, _editorTables.findTable)(selection);
|
|
178
|
+
if (!table) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
var tableMap = _editorTables.TableMap.get(table.node);
|
|
182
|
+
var height = tableMap.height;
|
|
183
|
+
if (height <= 1) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if (rowIndex < 0 || rowIndex > height - 1) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
var map = tableMap.map,
|
|
190
|
+
width = tableMap.width; // map is a flat array representing position of each cell in the table.
|
|
191
|
+
var indexOfFirstCellInTheRow = rowIndex * width;
|
|
192
|
+
var indexOfLastCellInTheRow = indexOfFirstCellInTheRow + width - 1;
|
|
193
|
+
var isFirstRow = rowIndex === 0;
|
|
194
|
+
var isLastRow = rowIndex === height - 1;
|
|
195
|
+
// j is an index of a cell in a row
|
|
196
|
+
for (var j = indexOfFirstCellInTheRow; j <= indexOfLastCellInTheRow; j++) {
|
|
197
|
+
if (!isFirstRow && map[j] === map[j - width] ||
|
|
198
|
+
// compare with a cell in the row above
|
|
199
|
+
!isLastRow && map[j] === map[j + width] // compare with a cell in the row below
|
|
200
|
+
) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
140
205
|
};
|
|
@@ -543,7 +543,11 @@ class TableComponent extends React.Component {
|
|
|
543
543
|
stickyHeader: this.state.stickyHeader,
|
|
544
544
|
getEditorFeatureFlags: getEditorFeatureFlags,
|
|
545
545
|
tableContainerWidth: tableContainerWidth,
|
|
546
|
-
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled
|
|
546
|
+
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
547
|
+
getScrollOffset: () => {
|
|
548
|
+
var _this$wrapper2;
|
|
549
|
+
return ((_this$wrapper2 = this.wrapper) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.scrollLeft) || 0;
|
|
550
|
+
}
|
|
547
551
|
}) : null;
|
|
548
552
|
const shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
|
|
549
553
|
const shadowStyle = memoizeOne(visible => ({
|
|
@@ -595,12 +599,12 @@ class TableComponent extends React.Component {
|
|
|
595
599
|
editorView: view,
|
|
596
600
|
node: node,
|
|
597
601
|
getScrollOffset: () => {
|
|
598
|
-
var _this$
|
|
599
|
-
return ((_this$
|
|
602
|
+
var _this$wrapper3;
|
|
603
|
+
return ((_this$wrapper3 = this.wrapper) === null || _this$wrapper3 === void 0 ? void 0 : _this$wrapper3.scrollLeft) || 0;
|
|
600
604
|
},
|
|
601
605
|
getTableWrapperWidth: () => {
|
|
602
|
-
var _this$
|
|
603
|
-
return ((_this$
|
|
606
|
+
var _this$wrapper4;
|
|
607
|
+
return ((_this$wrapper4 = this.wrapper) === null || _this$wrapper4 === void 0 ? void 0 : _this$wrapper4.clientWidth) || 760;
|
|
604
608
|
}
|
|
605
609
|
}), /*#__PURE__*/React.createElement("div", {
|
|
606
610
|
style: shadowStyle(showBeforeShadow),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
3
3
|
import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
|
-
import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo
|
|
4
|
+
import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo } from '../../utils';
|
|
5
5
|
import { withEditorAnalyticsAPI } from '../../utils/analytics';
|
|
6
|
+
import { canMove, getTargetIndex } from '../../utils/drag-menu';
|
|
6
7
|
import { clearDropTarget, moveSource } from './commands';
|
|
7
8
|
export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, sourceIndexes, status, tr) => {
|
|
8
9
|
return withEditorAnalyticsAPI(({
|
|
@@ -81,30 +82,13 @@ export const moveSourceWithAnalyticsViaShortcut = editorAnalyticsAPI => (sourceT
|
|
|
81
82
|
if (selectedIndexes.length === 0) {
|
|
82
83
|
return false;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
// const sourceIndex = selectedIndexes[0];
|
|
86
|
-
// we can move only by one row/column
|
|
87
|
-
// 'direction' can only be 1 (for right or down) or -1 (for left or up)
|
|
88
|
-
const targetIndex = Math[direction < 0 ? 'min' : 'max'](...selectedIndexes) + direction;
|
|
89
|
-
|
|
90
|
-
// We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
|
|
91
85
|
const {
|
|
92
86
|
totalRowCount,
|
|
93
87
|
totalColumnCount
|
|
94
88
|
} = getSelectedTableInfo(selection);
|
|
95
|
-
|
|
96
|
-
if (!isValidTargetIndex) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// We can move only if there are no merged cells in the source or target row/column
|
|
101
|
-
const hasMergedCellsInSource = isRow ? hasMergedCellsInRow(selectedIndexes)(selection) : hasMergedCellsInColumn(selectedIndexes)(selection);
|
|
102
|
-
if (hasMergedCellsInSource) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
const hasMergedCellsInTarget = isRow ? hasMergedCellsInRow(targetIndex)(selection) : hasMergedCellsInColumn(targetIndex)(selection);
|
|
106
|
-
if (hasMergedCellsInTarget) {
|
|
89
|
+
if (!canMove(sourceType, direction, isRow ? totalRowCount : totalColumnCount, selection, selectionRect)) {
|
|
107
90
|
return false;
|
|
108
91
|
}
|
|
92
|
+
const targetIndex = getTargetIndex(selectedIndexes, direction);
|
|
109
93
|
return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, selectedIndexes, targetIndex)(state, dispatch);
|
|
110
94
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
2
|
|
|
3
|
-
import React, { useCallback,
|
|
3
|
+
import React, { useCallback, useMemo, useRef } from 'react';
|
|
4
4
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
5
|
-
import { closestElement } from '@atlaskit/editor-common/utils';
|
|
6
5
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
7
6
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
8
7
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
@@ -36,7 +35,8 @@ export const ColumnControls = ({
|
|
|
36
35
|
isTableHovered,
|
|
37
36
|
tableContainerWidth,
|
|
38
37
|
isNumberColumnEnabled,
|
|
39
|
-
isDragging
|
|
38
|
+
isDragging,
|
|
39
|
+
getScrollOffset
|
|
40
40
|
}) => {
|
|
41
41
|
var _colWidths$map$join, _rowHeights$;
|
|
42
42
|
const columnControlsRef = useRef(null);
|
|
@@ -115,24 +115,10 @@ export const ColumnControls = ({
|
|
|
115
115
|
const colIndexes = useMemo(() => {
|
|
116
116
|
return [colIndex];
|
|
117
117
|
}, [colIndex]);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
var _tableWrapper$scrollL;
|
|
123
|
-
columnControlsRef.current.scrollLeft = (_tableWrapper$scrollL = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.scrollLeft) !== null && _tableWrapper$scrollL !== void 0 ? _tableWrapper$scrollL : 0;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}, [stickyTop, tableWrapper]);
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
handleScroll();
|
|
129
|
-
}, [handleScroll]);
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.addEventListener('scroll', handleScroll);
|
|
132
|
-
return () => {
|
|
133
|
-
tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.removeEventListener('scroll', handleScroll);
|
|
134
|
-
};
|
|
135
|
-
}, [tableWrapper, handleScroll]);
|
|
118
|
+
if (stickyTop && columnControlsRef.current) {
|
|
119
|
+
var _getScrollOffset;
|
|
120
|
+
columnControlsRef.current.scrollLeft = (_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0;
|
|
121
|
+
}
|
|
136
122
|
const generateHandleByType = type => {
|
|
137
123
|
var _rowHeights$reduce, _colWidths$reduce;
|
|
138
124
|
if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
2
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
3
3
|
import { ColumnDropTarget } from './ColumnDropTarget';
|
|
4
4
|
export const ColumnDropTargets = ({
|
|
5
5
|
tableRef,
|
|
6
6
|
tableHeight,
|
|
7
7
|
localId,
|
|
8
|
-
colWidths
|
|
8
|
+
colWidths,
|
|
9
|
+
isHeaderSticky,
|
|
10
|
+
getScrollOffset
|
|
9
11
|
}) => {
|
|
12
|
+
const dropTargetRef = useRef(null);
|
|
10
13
|
if (!tableRef) {
|
|
11
14
|
return null;
|
|
12
15
|
}
|
|
16
|
+
if (isHeaderSticky && dropTargetRef.current) {
|
|
17
|
+
var _getScrollOffset;
|
|
18
|
+
dropTargetRef.current.style.marginLeft = `-${(_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0}px`;
|
|
19
|
+
}
|
|
13
20
|
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
ref: dropTargetRef,
|
|
14
22
|
className: ClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS,
|
|
15
23
|
contentEditable: false
|
|
16
24
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -17,7 +17,8 @@ export const TableFloatingColumnControls = ({
|
|
|
17
17
|
isInDanger,
|
|
18
18
|
isTableHovered,
|
|
19
19
|
tableContainerWidth,
|
|
20
|
-
isNumberColumnEnabled
|
|
20
|
+
isNumberColumnEnabled,
|
|
21
|
+
getScrollOffset
|
|
21
22
|
}) => {
|
|
22
23
|
const [tableRect, setTableRect] = useState({
|
|
23
24
|
width: 0,
|
|
@@ -107,12 +108,15 @@ export const TableFloatingColumnControls = ({
|
|
|
107
108
|
hasHeaderColumn: hasHeaderColumn,
|
|
108
109
|
tableContainerWidth: tableContainerWidth,
|
|
109
110
|
isNumberColumnEnabled: isNumberColumnEnabled,
|
|
110
|
-
isDragging: isDragging
|
|
111
|
+
isDragging: isDragging,
|
|
112
|
+
getScrollOffset: getScrollOffset
|
|
111
113
|
}), isDragging && /*#__PURE__*/React.createElement(ColumnDropTargets, {
|
|
112
114
|
tableRef: tableRef,
|
|
115
|
+
isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
|
|
113
116
|
tableHeight: tableRect.height,
|
|
114
117
|
localId: currentNodeLocalId,
|
|
115
|
-
colWidths: colWidths
|
|
118
|
+
colWidths: colWidths,
|
|
119
|
+
getScrollOffset: getScrollOffset
|
|
116
120
|
}));
|
|
117
121
|
};
|
|
118
122
|
export default TableFloatingColumnControls;
|