@carbon/ibm-products 1.14.0 → 1.15.0
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/css/index-full-carbon.css +23 -5
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +3 -3
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +4 -4
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +2 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +23 -5
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +3 -3
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +23 -5
- package/css/index.css.map +1 -1
- package/css/index.min.css +3 -3
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +25 -19
- package/es/components/AddSelect/AddSelectFilter.js +5 -5
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +174 -127
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +24 -8
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +31 -6
- package/es/components/DataSpreadsheet/hooks/index.js +2 -1
- package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +36 -8
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -0
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
- package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
- package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
- package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
- package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +42 -8
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +153 -15
- package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
- package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
- package/es/components/PageHeader/PageHeader.js +3 -1
- package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
- package/es/components/TagSet/TagSet.js +13 -6
- package/es/components/Tearsheet/TearsheetShell.js +34 -10
- package/es/global/js/package-settings.js +2 -1
- package/lib/components/AddSelect/AddSelect.js +25 -19
- package/lib/components/AddSelect/AddSelectFilter.js +5 -5
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +178 -126
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +24 -8
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +32 -6
- package/lib/components/DataSpreadsheet/hooks/index.js +9 -1
- package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +36 -8
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +79 -0
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
- package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
- package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
- package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
- package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +44 -8
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +161 -22
- package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
- package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
- package/lib/components/PageHeader/PageHeader.js +3 -1
- package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
- package/lib/components/TagSet/TagSet.js +13 -6
- package/lib/components/Tearsheet/TearsheetShell.js +36 -10
- package/lib/global/js/package-settings.js +2 -1
- package/package.json +11 -11
- package/scss/components/AboutModal/_about-modal.scss +4 -0
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +22 -1
- package/scss/components/ExportModal/_export-modal.scss +0 -4
@@ -25,11 +25,13 @@ var _layout = require("@carbon/layout");
|
|
25
25
|
|
26
26
|
var _settings = require("../../settings");
|
27
27
|
|
28
|
+
var _hooks = require("../../global/js/hooks");
|
29
|
+
|
28
30
|
var _checkActiveHeaderCell = require("./utils/checkActiveHeaderCell");
|
29
31
|
|
30
32
|
var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
|
31
33
|
|
32
|
-
var
|
34
|
+
var _selectAllCells = require("./utils/selectAllCells");
|
33
35
|
|
34
36
|
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); }
|
35
37
|
|
@@ -52,7 +54,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
52
54
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
53
55
|
setSelectionAreas = _ref.setSelectionAreas,
|
54
56
|
setSelectionAreaData = _ref.setSelectionAreaData,
|
55
|
-
rows = _ref.rows
|
57
|
+
rows = _ref.rows,
|
58
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
56
59
|
|
57
60
|
var _useState = (0, _react.useState)(0),
|
58
61
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
@@ -74,7 +77,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
74
77
|
}, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
|
75
78
|
|
76
79
|
var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
|
77
|
-
return function () {
|
80
|
+
return function (event) {
|
81
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
78
82
|
(0, _handleHeaderCellSelection.handleHeaderCellSelection)({
|
79
83
|
type: 'column',
|
80
84
|
activeCellCoordinates: activeCellCoordinates,
|
@@ -85,13 +89,27 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
85
89
|
setSelectionAreas: setSelectionAreas,
|
86
90
|
spreadsheetRef: ref,
|
87
91
|
index: index,
|
88
|
-
setSelectionAreaData: setSelectionAreaData
|
92
|
+
setSelectionAreaData: setSelectionAreaData,
|
93
|
+
isHoldingCommandKey: isHoldingCommandKey
|
89
94
|
});
|
90
95
|
};
|
91
96
|
};
|
92
97
|
|
98
|
+
var handleSelectAllClick = function handleSelectAllClick() {
|
99
|
+
(0, _selectAllCells.selectAllCells)({
|
100
|
+
ref: ref,
|
101
|
+
setCurrentMatcher: setCurrentMatcher,
|
102
|
+
setSelectionAreas: setSelectionAreas,
|
103
|
+
rows: rows,
|
104
|
+
columns: columns,
|
105
|
+
activeCellCoordinates: activeCellCoordinates,
|
106
|
+
updateActiveCellCoordinates: updateActiveCellCoordinates
|
107
|
+
});
|
108
|
+
};
|
109
|
+
|
93
110
|
return /*#__PURE__*/_react.default.createElement("div", {
|
94
|
-
className: (0, _classnames.default)("".concat(blockClass, "__header--container"))
|
111
|
+
className: (0, _classnames.default)("".concat(blockClass, "__header--container")),
|
112
|
+
role: "rowgroup"
|
95
113
|
}, headerGroups.map(function (headerGroup, index) {
|
96
114
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
97
115
|
key: "header_".concat(index)
|
@@ -107,10 +125,12 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
107
125
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
108
126
|
}
|
109
127
|
}, /*#__PURE__*/_react.default.createElement("button", {
|
128
|
+
id: "".concat(blockClass, "__cell--header--header"),
|
110
129
|
"data-row-index": "header",
|
111
130
|
"data-column-index": "header",
|
112
131
|
type: "button",
|
113
132
|
tabIndex: -1,
|
133
|
+
onClick: handleSelectAllClick,
|
114
134
|
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header'))
|
115
135
|
}, "\xA0")), headerGroup.headers.map(function (column, index) {
|
116
136
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
@@ -118,6 +138,7 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
118
138
|
role: "columnheader",
|
119
139
|
className: "".concat(blockClass, "__columnheader")
|
120
140
|
}, column.getHeaderProps()), /*#__PURE__*/_react.default.createElement("button", {
|
141
|
+
id: "".concat(blockClass, "__cell--header--").concat(index),
|
121
142
|
"data-row-index": "header",
|
122
143
|
"data-column-index": index,
|
123
144
|
tabIndex: -1,
|
@@ -198,5 +219,10 @@ DataSpreadsheetHeader.propTypes = {
|
|
198
219
|
/**
|
199
220
|
* Setter fn for selectionAreas value
|
200
221
|
*/
|
201
|
-
setSelectionAreas: _propTypes.default.func
|
222
|
+
setSelectionAreas: _propTypes.default.func,
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Function used to update the active cell coordinates
|
226
|
+
*/
|
227
|
+
updateActiveCellCoordinates: _propTypes.default.func
|
202
228
|
};
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "useResetSpreadsheetFocus", {
|
|
21
21
|
return _useResetSpreadsheetFocus.useResetSpreadsheetFocus;
|
22
22
|
}
|
23
23
|
});
|
24
|
+
Object.defineProperty(exports, "useSpreadsheetEdit", {
|
25
|
+
enumerable: true,
|
26
|
+
get: function get() {
|
27
|
+
return _useSpreadsheetEdit.useSpreadsheetEdit;
|
28
|
+
}
|
29
|
+
});
|
24
30
|
Object.defineProperty(exports, "useSpreadsheetOutsideClick", {
|
25
31
|
enumerable: true,
|
26
32
|
get: function get() {
|
@@ -34,4 +40,6 @@ var _useMultipleKeyTracking = require("./useMultipleKeyTracking");
|
|
34
40
|
|
35
41
|
var _useResetSpreadsheetFocus = require("./useResetSpreadsheetFocus");
|
36
42
|
|
37
|
-
var _useSpreadsheetOutsideClick = require("./useSpreadsheetOutsideClick");
|
43
|
+
var _useSpreadsheetOutsideClick = require("./useSpreadsheetOutsideClick");
|
44
|
+
|
45
|
+
var _useSpreadsheetEdit = require("./useSpreadsheetEdit");
|
@@ -15,6 +15,8 @@ var _react = require("react");
|
|
15
15
|
|
16
16
|
var _hooks = require("../../../global/js/hooks");
|
17
17
|
|
18
|
+
var _handleMultipleKeys = require("../utils/handleMultipleKeys");
|
19
|
+
|
18
20
|
/**
|
19
21
|
* Copyright IBM Corp. 2022, 2022
|
20
22
|
*
|
@@ -30,15 +32,20 @@ var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
|
30
32
|
containerHasFocus = _ref.containerHasFocus,
|
31
33
|
isEditing = _ref.isEditing;
|
32
34
|
|
33
|
-
var _useState = (0, _react.useState)(
|
35
|
+
var _useState = (0, _react.useState)(''),
|
34
36
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
35
|
-
|
36
|
-
|
37
|
+
usingMac = _useState2[0],
|
38
|
+
setUsingMac = _useState2[1];
|
37
39
|
|
38
|
-
var _useState3 = (0, _react.useState)(
|
40
|
+
var _useState3 = (0, _react.useState)(hasFocus),
|
39
41
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
40
|
-
|
41
|
-
|
42
|
+
windowFocused = _useState4[0],
|
43
|
+
setWindowFocused = _useState4[1];
|
44
|
+
|
45
|
+
var _useState5 = (0, _react.useState)([]),
|
46
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
47
|
+
keysPressedList = _useState6[0],
|
48
|
+
setKeysPressedList = _useState6[1];
|
42
49
|
|
43
50
|
var previousState = (0, _hooks.usePreviousValue)({
|
44
51
|
isEditing: isEditing,
|
@@ -47,6 +54,14 @@ var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
|
47
54
|
// we need to clear out the keysPressedList
|
48
55
|
|
49
56
|
(0, _react.useEffect)(function () {
|
57
|
+
var userAgentString = window.navigator.userAgent;
|
58
|
+
|
59
|
+
if (userAgentString.includes('Macintosh')) {
|
60
|
+
setUsingMac(true);
|
61
|
+
} else {
|
62
|
+
setUsingMac(false);
|
63
|
+
}
|
64
|
+
|
50
65
|
setWindowFocused(hasFocus());
|
51
66
|
|
52
67
|
var onWindowFocus = function onWindowFocus() {
|
@@ -72,6 +87,18 @@ var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
|
72
87
|
// Prevent multiple keys of the same type being added to our keysPressedList array
|
73
88
|
if (keysPressedList.includes(event.code)) {
|
74
89
|
return;
|
90
|
+
} // Because keyup events are lost when using the Command key
|
91
|
+
// we need to remove the previously pressed keys so that we
|
92
|
+
// do not have keys in the pressed list that should not be
|
93
|
+
|
94
|
+
|
95
|
+
if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac) && keysPressedList.length > 1) {
|
96
|
+
var clonedKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
97
|
+
var filteredClonedKeys = clonedKeys.filter(function (item) {
|
98
|
+
return item === 'MetaLeft' || item === 'MetaRight';
|
99
|
+
});
|
100
|
+
filteredClonedKeys.push(event.code);
|
101
|
+
return setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClonedKeys)));
|
75
102
|
}
|
76
103
|
|
77
104
|
var tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
@@ -113,10 +140,11 @@ var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
|
113
140
|
setKeysPressedList([]);
|
114
141
|
}
|
115
142
|
}
|
116
|
-
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused]);
|
143
|
+
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
|
117
144
|
return {
|
118
145
|
keysPressedList: keysPressedList,
|
119
|
-
windowFocused: windowFocused
|
146
|
+
windowFocused: windowFocused,
|
147
|
+
usingMac: usingMac
|
120
148
|
};
|
121
149
|
};
|
122
150
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useSpreadsheetEdit = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
var _layout = require("@carbon/layout");
|
11
|
+
|
12
|
+
// /**
|
13
|
+
// * Copyright IBM Corp. 2022, 2022
|
14
|
+
// *
|
15
|
+
// * This source code is licensed under the Apache-2.0 license found in the
|
16
|
+
// * LICENSE file in the root directory of this source tree.
|
17
|
+
// */
|
18
|
+
var useSpreadsheetEdit = function useSpreadsheetEdit(_ref) {
|
19
|
+
var isEditing = _ref.isEditing,
|
20
|
+
rows = _ref.rows,
|
21
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
22
|
+
activeCellRef = _ref.activeCellRef,
|
23
|
+
cellEditorRef = _ref.cellEditorRef,
|
24
|
+
cellEditorRulerRef = _ref.cellEditorRulerRef,
|
25
|
+
columns = _ref.columns,
|
26
|
+
defaultColumn = _ref.defaultColumn,
|
27
|
+
cellEditorValue = _ref.cellEditorValue;
|
28
|
+
(0, _react.useEffect)(function () {
|
29
|
+
if (isEditing) {
|
30
|
+
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
31
|
+
|
32
|
+
var cellProps = (_rows$activeCellCoord = rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row]) === null || _rows$activeCellCoord === void 0 ? void 0 : _rows$activeCellCoord.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column];
|
33
|
+
var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
|
34
|
+
var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
|
35
|
+
cellEditorRef.current.style.left = activeCellLeftPosition;
|
36
|
+
cellEditorRef.current.style.top = activeCellTopPosition;
|
37
|
+
cellEditorRef.current.style.display = 'block';
|
38
|
+
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
39
|
+
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
40
|
+
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2 - 1, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
41
|
+
|
42
|
+
cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
|
43
|
+
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
44
|
+
var rulerWidth = cellEditorRulerRef.current.offsetWidth;
|
45
|
+
var cellWidth = activeCellRef.current.offsetWidth;
|
46
|
+
|
47
|
+
if (rulerWidth >= cellWidth) {
|
48
|
+
var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
|
49
|
+
var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
|
50
|
+
var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
51
|
+
var totalColumns = columns.length;
|
52
|
+
var totalRows = rows.length;
|
53
|
+
var totalMultiplierPossible = totalColumns - startingColumnPosition;
|
54
|
+
var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
|
55
|
+
cellEditorRef.current.style.maxHeight = (0, _layout.px)(totalCellEditorMaxHeight);
|
56
|
+
cellEditorRef.current.style.width = (0, _layout.px)(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
|
57
|
+
cellEditorRef.current.style.height = (0, _layout.px)(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
|
58
|
+
// Cell editor has reached max height, we need to add the scrolling back.
|
59
|
+
// We also need to subtract 1 to account for the fact that the cell editor
|
60
|
+
// is placed one pixel below the cell being edited to account for the border
|
61
|
+
|
62
|
+
if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
|
63
|
+
cellEditorRef.current.style.overflow = 'auto';
|
64
|
+
} else {
|
65
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
if (!isEditing) {
|
71
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
72
|
+
cellEditorRef.current.style.display = 'none';
|
73
|
+
cellEditorRef.current.blur();
|
74
|
+
activeCellRef.current.focus();
|
75
|
+
}
|
76
|
+
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn, cellEditorValue, activeCellRef, cellEditorRef, cellEditorRulerRef]);
|
77
|
+
};
|
78
|
+
|
79
|
+
exports.useSpreadsheetEdit = useSpreadsheetEdit;
|
@@ -9,6 +9,8 @@ var _layout = require("@carbon/layout");
|
|
9
9
|
|
10
10
|
var _deepCloneObject = require("../../../global/js/utils/deepCloneObject");
|
11
11
|
|
12
|
+
var _getSelectionAreaPoints = require("./getSelectionAreaPoints");
|
13
|
+
|
12
14
|
/**
|
13
15
|
* Copyright IBM Corp. 2022, 2022
|
14
16
|
*
|
@@ -16,21 +18,32 @@ var _deepCloneObject = require("../../../global/js/utils/deepCloneObject");
|
|
16
18
|
* LICENSE file in the root directory of this source tree.
|
17
19
|
*/
|
18
20
|
var createCellSelectionArea = function createCellSelectionArea(_ref) {
|
19
|
-
var
|
21
|
+
var ref = _ref.ref,
|
22
|
+
area = _ref.area,
|
20
23
|
blockClass = _ref.blockClass,
|
21
24
|
defaultColumn = _ref.defaultColumn,
|
22
25
|
selectionAreas = _ref.selectionAreas,
|
23
|
-
setSelectionAreas = _ref.setSelectionAreas
|
24
|
-
|
25
|
-
|
26
|
-
var
|
27
|
-
|
26
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
27
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
|
28
|
+
|
29
|
+
var _getSelectionAreaPoin = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(area),
|
30
|
+
lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
|
31
|
+
lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
|
32
|
+
greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
|
33
|
+
greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex;
|
34
|
+
|
35
|
+
if (greatestRowIndex - lowestRowIndex > 0 || greatestColumnIndex - lowestColumnIndex > 0) {
|
36
|
+
setActiveCellInsideSelectionArea(true);
|
37
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
38
|
+
activeCellElement.setAttribute('data-selection-id', area.matcher);
|
39
|
+
}
|
40
|
+
|
28
41
|
var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]")) || document.querySelector(".".concat(blockClass, "__body--td")); // if we can't find the point1 element (this can happen in the case where a virtualized row is not present anymore in the DOM), we get the default height/width of the first body cell we find
|
29
42
|
|
30
43
|
var selectionAreaCellWidth = point1Element.offsetWidth;
|
31
44
|
var selectionAreaCellHeight = point1Element.offsetHeight;
|
32
|
-
var selectionAreaTotalWidth = selectionAreaCellWidth * (
|
33
|
-
var selectionAreaTotalHeight = selectionAreaCellHeight * (
|
45
|
+
var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumnIndex - lowestColumnIndex + 1);
|
46
|
+
var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRowIndex - lowestRowIndex + 1);
|
34
47
|
var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
35
48
|
var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
|
36
49
|
var relativePosition = {
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getSelectionAreaPoints = void 0;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Copyright IBM Corp. 2022, 2022
|
10
|
+
*
|
11
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
13
|
+
*/
|
14
|
+
var getSelectionAreaPoints = function getSelectionAreaPoints(area) {
|
15
|
+
var greatestRowIndex = Math.max(area.point1.row, area.point2.row);
|
16
|
+
var greatestColumnIndex = Math.max(area.point1.column, area.point2.column);
|
17
|
+
var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
|
18
|
+
var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
|
19
|
+
return {
|
20
|
+
greatestRowIndex: greatestRowIndex,
|
21
|
+
greatestColumnIndex: greatestColumnIndex,
|
22
|
+
lowestColumnIndex: lowestColumnIndex,
|
23
|
+
lowestRowIndex: lowestRowIndex
|
24
|
+
};
|
25
|
+
};
|
26
|
+
|
27
|
+
exports.getSelectionAreaPoints = getSelectionAreaPoints;
|
@@ -0,0 +1,127 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.handleActiveCellInSelectionEnter = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _getSelectionAreaPoints = require("./getSelectionAreaPoints");
|
13
|
+
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
15
|
+
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
17
|
+
|
18
|
+
var handleActiveCellInSelectionEnter = function handleActiveCellInSelectionEnter(_ref) {
|
19
|
+
var activeCellInsideSelectionArea = _ref.activeCellInsideSelectionArea,
|
20
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
21
|
+
activeCellRef = _ref.activeCellRef,
|
22
|
+
selectionAreas = _ref.selectionAreas,
|
23
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
24
|
+
|
25
|
+
if (!activeCellInsideSelectionArea) {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
|
29
|
+
var activeCellSelectionId = activeCellRef.current.getAttribute('data-selection-id');
|
30
|
+
var activeCellIndexInSelectionAreas = selectionAreas.findIndex(function (item) {
|
31
|
+
return item.matcher === activeCellSelectionId;
|
32
|
+
});
|
33
|
+
var selectionAreaToNavigate = selectionAreas[activeCellIndexInSelectionAreas];
|
34
|
+
|
35
|
+
var _getSelectionAreaPoin = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(selectionAreaToNavigate),
|
36
|
+
lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
|
37
|
+
lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
|
38
|
+
greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
|
39
|
+
greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex; // Move active cell down one row if possible
|
40
|
+
|
41
|
+
|
42
|
+
var coordinatesClone = _objectSpread({}, activeCellCoordinates);
|
43
|
+
|
44
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) < greatestRowIndex) {
|
45
|
+
updateActiveCellCoordinates({
|
46
|
+
coords: coordinatesClone,
|
47
|
+
updatedValue: {
|
48
|
+
row: (coordinatesClone === null || coordinatesClone === void 0 ? void 0 : coordinatesClone.row) + 1
|
49
|
+
},
|
50
|
+
optOutOfSelectionAreaUpdate: true
|
51
|
+
});
|
52
|
+
} // Move active cell to next column of selection area if it exists
|
53
|
+
// If not, find the next selection area and update active cell to
|
54
|
+
// be the first cell in that selection
|
55
|
+
|
56
|
+
|
57
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === greatestRowIndex) {
|
58
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) < greatestColumnIndex) {
|
59
|
+
updateActiveCellCoordinates({
|
60
|
+
coords: coordinatesClone,
|
61
|
+
updatedValue: {
|
62
|
+
column: (coordinatesClone === null || coordinatesClone === void 0 ? void 0 : coordinatesClone.column) + 1,
|
63
|
+
row: lowestRowIndex
|
64
|
+
},
|
65
|
+
optOutOfSelectionAreaUpdate: true
|
66
|
+
});
|
67
|
+
} // Move to next selection area if there is one, or back to
|
68
|
+
// the beginning of the current selection
|
69
|
+
|
70
|
+
|
71
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === greatestColumnIndex) {
|
72
|
+
if (selectionAreas.length > 1) {
|
73
|
+
if (selectionAreas[activeCellIndexInSelectionAreas + 1]) {
|
74
|
+
// Update activeCellRef data-selection-id attribute to the matcher of the next selection area
|
75
|
+
activeCellRef.current.setAttribute('data-selection-id', selectionAreas[activeCellIndexInSelectionAreas + 1].matcher);
|
76
|
+
var nextSelectionArea = selectionAreas[activeCellIndexInSelectionAreas + 1];
|
77
|
+
|
78
|
+
var _getSelectionAreaPoin2 = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(nextSelectionArea),
|
79
|
+
_lowestColumnIndex = _getSelectionAreaPoin2.lowestColumnIndex,
|
80
|
+
_lowestRowIndex = _getSelectionAreaPoin2.lowestRowIndex;
|
81
|
+
|
82
|
+
updateActiveCellCoordinates({
|
83
|
+
coords: coordinatesClone,
|
84
|
+
updatedValue: {
|
85
|
+
column: _lowestColumnIndex,
|
86
|
+
row: _lowestRowIndex
|
87
|
+
},
|
88
|
+
optOutOfSelectionAreaUpdate: true
|
89
|
+
});
|
90
|
+
return;
|
91
|
+
} else {
|
92
|
+
// There are multiple selection areas and the active cell is in the last one
|
93
|
+
// So we need to move the active cell to the first cell in the first selection area
|
94
|
+
activeCellRef.current.setAttribute('data-selection-id', selectionAreas[0].matcher);
|
95
|
+
var firstSelectionArea = selectionAreas[0];
|
96
|
+
|
97
|
+
var _getSelectionAreaPoin3 = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(firstSelectionArea),
|
98
|
+
_lowestColumnIndex2 = _getSelectionAreaPoin3.lowestColumnIndex,
|
99
|
+
_lowestRowIndex2 = _getSelectionAreaPoin3.lowestRowIndex;
|
100
|
+
|
101
|
+
updateActiveCellCoordinates({
|
102
|
+
coords: coordinatesClone,
|
103
|
+
updatedValue: {
|
104
|
+
column: _lowestColumnIndex2,
|
105
|
+
row: _lowestRowIndex2
|
106
|
+
},
|
107
|
+
optOutOfSelectionAreaUpdate: true
|
108
|
+
});
|
109
|
+
}
|
110
|
+
} // Only one selection area, go back to first cell in the selection
|
111
|
+
|
112
|
+
|
113
|
+
if (selectionAreas.length === 1) {
|
114
|
+
return updateActiveCellCoordinates({
|
115
|
+
coords: coordinatesClone,
|
116
|
+
updatedValue: {
|
117
|
+
column: lowestColumnIndex,
|
118
|
+
row: lowestRowIndex
|
119
|
+
},
|
120
|
+
optOutOfSelectionAreaUpdate: true
|
121
|
+
});
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
};
|
126
|
+
|
127
|
+
exports.handleActiveCellInSelectionEnter = handleActiveCellInSelectionEnter;
|
@@ -0,0 +1,118 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.handleActiveCellInSelectionTab = void 0;
|
7
|
+
|
8
|
+
var _getSelectionAreaPoints = require("./getSelectionAreaPoints");
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Copyright IBM Corp. 2022, 2022
|
12
|
+
*
|
13
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
15
|
+
*/
|
16
|
+
var handleActiveCellInSelectionTab = function handleActiveCellInSelectionTab(_ref) {
|
17
|
+
var activeCellInsideSelectionArea = _ref.activeCellInsideSelectionArea,
|
18
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
19
|
+
activeCellRef = _ref.activeCellRef,
|
20
|
+
selectionAreas = _ref.selectionAreas,
|
21
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
22
|
+
|
23
|
+
if (!activeCellInsideSelectionArea) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
|
27
|
+
var activeCellSelectionId = activeCellRef.current.getAttribute('data-selection-id');
|
28
|
+
var activeCellIndexInSelectionAreas = selectionAreas.findIndex(function (item) {
|
29
|
+
return item.matcher === activeCellSelectionId;
|
30
|
+
});
|
31
|
+
var selectionAreaToNavigate = selectionAreas[activeCellIndexInSelectionAreas];
|
32
|
+
|
33
|
+
var _getSelectionAreaPoin = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(selectionAreaToNavigate),
|
34
|
+
lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
|
35
|
+
lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
|
36
|
+
greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
|
37
|
+
greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex; // Move active cell to next column in selection area
|
38
|
+
|
39
|
+
|
40
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) < greatestColumnIndex) {
|
41
|
+
updateActiveCellCoordinates({
|
42
|
+
updatedValue: {
|
43
|
+
column: (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) + 1
|
44
|
+
},
|
45
|
+
optOutOfSelectionAreaUpdate: true
|
46
|
+
});
|
47
|
+
} // Move active cell to next row of selection area if it exists
|
48
|
+
// If not, find the next selection area and update active cell to
|
49
|
+
// be the first cell in that selection
|
50
|
+
|
51
|
+
|
52
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === greatestColumnIndex) {
|
53
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) < greatestRowIndex) {
|
54
|
+
updateActiveCellCoordinates({
|
55
|
+
updatedValue: {
|
56
|
+
column: lowestColumnIndex,
|
57
|
+
row: (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) + 1
|
58
|
+
},
|
59
|
+
optOutOfSelectionAreaUpdate: true
|
60
|
+
});
|
61
|
+
} // Move to next selection area if there is on, or back to
|
62
|
+
// the beginning of the current selection
|
63
|
+
|
64
|
+
|
65
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === greatestRowIndex) {
|
66
|
+
if (selectionAreas.length > 1) {
|
67
|
+
if (selectionAreas[activeCellIndexInSelectionAreas + 1]) {
|
68
|
+
// Update activeCellRef data-selection-id attribute to the matcher of the next selection area
|
69
|
+
activeCellRef.current.setAttribute('data-selection-id', selectionAreas[activeCellIndexInSelectionAreas + 1].matcher);
|
70
|
+
var nextSelectionArea = selectionAreas[activeCellIndexInSelectionAreas + 1];
|
71
|
+
|
72
|
+
var _getSelectionAreaPoin2 = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(nextSelectionArea),
|
73
|
+
_lowestColumnIndex = _getSelectionAreaPoin2.lowestColumnIndex,
|
74
|
+
_lowestRowIndex = _getSelectionAreaPoin2.lowestRowIndex;
|
75
|
+
|
76
|
+
updateActiveCellCoordinates({
|
77
|
+
updatedValue: {
|
78
|
+
column: _lowestColumnIndex,
|
79
|
+
row: _lowestRowIndex
|
80
|
+
},
|
81
|
+
optOutOfSelectionAreaUpdate: true
|
82
|
+
});
|
83
|
+
return;
|
84
|
+
} else {
|
85
|
+
// There are multiple selection areas and the active cell is in the last one
|
86
|
+
// So we need to move the active cell to the first cell in the first selection area
|
87
|
+
activeCellRef.current.setAttribute('data-selection-id', selectionAreas[0].matcher);
|
88
|
+
var firstSelectionArea = selectionAreas[0];
|
89
|
+
|
90
|
+
var _getSelectionAreaPoin3 = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(firstSelectionArea),
|
91
|
+
_lowestColumnIndex2 = _getSelectionAreaPoin3.lowestColumnIndex,
|
92
|
+
_lowestRowIndex2 = _getSelectionAreaPoin3.lowestRowIndex;
|
93
|
+
|
94
|
+
updateActiveCellCoordinates({
|
95
|
+
updatedValue: {
|
96
|
+
column: _lowestColumnIndex2,
|
97
|
+
row: _lowestRowIndex2
|
98
|
+
},
|
99
|
+
optOutOfSelectionAreaUpdate: true
|
100
|
+
});
|
101
|
+
}
|
102
|
+
} // Only one selection area, go back to first cell in the selection
|
103
|
+
|
104
|
+
|
105
|
+
if (selectionAreas.length === 1) {
|
106
|
+
return updateActiveCellCoordinates({
|
107
|
+
updatedValue: {
|
108
|
+
column: lowestColumnIndex,
|
109
|
+
row: lowestRowIndex
|
110
|
+
},
|
111
|
+
optOutOfSelectionAreaUpdate: true
|
112
|
+
});
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
};
|
117
|
+
|
118
|
+
exports.handleActiveCellInSelectionTab = handleActiveCellInSelectionTab;
|