@carbon/ibm-products 1.14.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/components/Datagrid/styles/datagrid.css +4 -0
- package/css/components/Datagrid/styles/datagrid.css.map +1 -1
- package/css/components/Datagrid/styles/index.css +5 -1
- package/css/components/Datagrid/styles/index.css.map +1 -1
- package/css/components/Datagrid/styles/useNestedRows.css +1 -1
- package/css/index-full-carbon.css +75 -16
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +6 -3
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +13 -7
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +5 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +75 -16
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +6 -3
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +75 -16
- package/css/index.css.map +1 -1
- package/css/index.min.css +6 -3
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +34 -23
- package/es/components/AddSelect/AddSelectFilter.js +52 -9
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +186 -129
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +67 -15
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +55 -11
- 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 +113 -0
- package/es/components/DataSpreadsheet/utils/checkSelectedHeaderCell.js +16 -0
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +29 -12
- package/es/components/DataSpreadsheet/utils/generateData.js +17 -9
- package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
- package/es/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +30 -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 +46 -8
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +153 -15
- package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
- package/es/components/Datagrid/Datagrid/Datagrid.js +24 -12
- package/es/components/Datagrid/Datagrid/DatagridHead.js +8 -16
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +10 -10
- package/es/components/Datagrid/Datagrid/DatagridRow.js +12 -2
- package/es/components/Datagrid/Datagrid/index.js +6 -7
- package/es/components/Datagrid/index.js +1 -1
- package/es/components/Datagrid/useNestedRows.js +3 -3
- package/es/components/Datagrid/useRowExpander.js +1 -1
- package/es/components/ExportModal/ExportModal.js +10 -5
- package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
- package/es/components/PageHeader/PageHeader.js +3 -1
- package/es/components/SidePanel/SidePanel.js +5 -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/components/WebTerminal/WebTerminal.js +36 -11
- package/es/components/WebTerminal/WebTerminalContentWrapper.js +49 -0
- package/es/components/WebTerminal/index.js +2 -1
- package/es/components/index.js +1 -1
- package/es/global/js/package-settings.js +3 -1
- package/lib/components/AddSelect/AddSelect.js +34 -23
- package/lib/components/AddSelect/AddSelectFilter.js +51 -8
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +190 -128
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +69 -15
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +58 -12
- 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 +129 -0
- package/lib/components/DataSpreadsheet/utils/checkSelectedHeaderCell.js +26 -0
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +31 -13
- package/lib/components/DataSpreadsheet/utils/generateData.js +17 -9
- package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
- package/lib/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +40 -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 +48 -8
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +161 -22
- package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
- package/lib/components/Datagrid/Datagrid/Datagrid.js +25 -8
- package/lib/components/Datagrid/Datagrid/DatagridHead.js +8 -16
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +10 -10
- package/lib/components/Datagrid/Datagrid/DatagridRow.js +14 -2
- package/lib/components/Datagrid/Datagrid/index.js +3 -5
- package/lib/components/Datagrid/index.js +2 -2
- package/lib/components/Datagrid/useNestedRows.js +3 -3
- package/lib/components/Datagrid/useRowExpander.js +1 -1
- package/lib/components/ExportModal/ExportModal.js +9 -4
- package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
- package/lib/components/PageHeader/PageHeader.js +3 -1
- package/lib/components/SidePanel/SidePanel.js +5 -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/components/WebTerminal/WebTerminal.js +36 -10
- package/lib/components/WebTerminal/WebTerminalContentWrapper.js +58 -0
- package/lib/components/WebTerminal/index.js +9 -1
- package/lib/components/index.js +6 -0
- package/lib/global/js/package-settings.js +3 -1
- package/package.json +13 -13
- package/scss/components/AboutModal/_about-modal.scss +4 -0
- package/scss/components/AddSelect/_add-select.scss +9 -2
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +39 -2
- package/scss/components/Datagrid/styles/datagrid.scss +8 -0
- package/scss/components/Datagrid/styles/useNestedRows.scss +1 -1
- package/scss/components/ExportModal/_export-modal.scss +0 -4
- package/scss/components/SidePanel/_side-panel.scss +22 -3
- package/scss/components/WebTerminal/_storybook-styles.scss +5 -0
- package/scss/components/WebTerminal/_web-terminal.scss +14 -4
@@ -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,33 +18,49 @@ 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,
|
24
|
+
columns = _ref.columns,
|
21
25
|
defaultColumn = _ref.defaultColumn,
|
22
26
|
selectionAreas = _ref.selectionAreas,
|
23
|
-
setSelectionAreas = _ref.setSelectionAreas
|
24
|
-
|
25
|
-
|
26
|
-
var
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
28
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
|
29
|
+
|
30
|
+
var _getSelectionAreaPoin = (0, _getSelectionAreaPoints.getSelectionAreaPoints)(area),
|
31
|
+
lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
|
32
|
+
lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
|
33
|
+
greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
|
34
|
+
greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex;
|
35
|
+
|
36
|
+
if (greatestRowIndex - lowestRowIndex > 0 || greatestColumnIndex - lowestColumnIndex > 0) {
|
37
|
+
setActiveCellInsideSelectionArea(true);
|
38
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
39
|
+
activeCellElement.setAttribute('data-selection-id', area.matcher);
|
40
|
+
}
|
41
|
+
|
42
|
+
var selectionAreaVariableWidth = 0;
|
43
|
+
columns.forEach(function (item, index) {
|
44
|
+
if (index >= lowestColumnIndex && index <= greatestColumnIndex) {
|
45
|
+
selectionAreaVariableWidth += (item === null || item === void 0 ? void 0 : item.width) || (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
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 of the first body cell we find
|
49
|
+
|
31
50
|
var selectionAreaCellHeight = point1Element.offsetHeight;
|
32
|
-
var
|
33
|
-
var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRow - lowestRowIndex + 1);
|
51
|
+
var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRowIndex - lowestRowIndex + 1);
|
34
52
|
var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
35
53
|
var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
|
36
54
|
var relativePosition = {
|
37
55
|
top: placementElement ? placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top : lowestRowIndex === 0 ? 0 : selectionAreaCellHeight * lowestRowIndex,
|
38
56
|
// calculate top value here if virtualized row is not in DOM
|
39
|
-
left: placementElement ? placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left : lowestColumnIndex === 0 ? 0 + (defaultColumn.rowHeaderWidth - 4) :
|
57
|
+
left: placementElement ? placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left : lowestColumnIndex === 0 ? 0 + (defaultColumn.rowHeaderWidth - 4) : defaultColumn.width * lowestColumnIndex + (defaultColumn.rowHeaderWidth - 4) // calculate left value here if virtualized row is not in DOM, accounting for row header cell width (including borders)
|
40
58
|
|
41
59
|
};
|
42
60
|
var selectionAreaElement = document.querySelector("[data-matcher-id=\"".concat(area.matcher, "\"]")) || document.createElement('div');
|
43
61
|
selectionAreaElement.classList.add("".concat(blockClass, "__selection-area--element"));
|
44
62
|
selectionAreaElement.setAttribute('data-matcher-id', area.matcher);
|
45
|
-
selectionAreaElement.style.width = (0, _layout.px)(
|
63
|
+
selectionAreaElement.style.width = (0, _layout.px)(selectionAreaVariableWidth);
|
46
64
|
selectionAreaElement.style.height = (0, _layout.px)(selectionAreaTotalHeight);
|
47
65
|
selectionAreaElement.style.left = (0, _layout.px)(relativePosition.left);
|
48
66
|
selectionAreaElement.style.top = (0, _layout.px)(relativePosition.top);
|
@@ -33,28 +33,36 @@ var range = function range(len) {
|
|
33
33
|
return arr;
|
34
34
|
};
|
35
35
|
|
36
|
-
var newPet = function newPet() {
|
37
|
-
|
36
|
+
var newPet = function newPet(extraColumns) {
|
37
|
+
var extraDataProps = extraColumns && {
|
38
|
+
ownerName: petNames[Math.floor(Math.random() * petNames.length)],
|
39
|
+
weight: Math.floor(Math.random() * 40)
|
40
|
+
};
|
41
|
+
var defaultPet = {
|
38
42
|
petType: pets[Math.floor(Math.random() * pets.length)],
|
39
43
|
firstName: petNames[Math.floor(Math.random() * petNames.length)],
|
40
44
|
age: Math.floor(Math.random() * 30),
|
41
45
|
visits: Math.floor(Math.random() * 40),
|
42
46
|
health: Math.floor(Math.random() * 100)
|
43
47
|
};
|
44
|
-
};
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
lens[_key] = arguments[_key];
|
49
|
+
if (extraColumns) {
|
50
|
+
return _objectSpread(_objectSpread({}, defaultPet), extraDataProps);
|
49
51
|
}
|
50
52
|
|
53
|
+
return defaultPet;
|
54
|
+
};
|
55
|
+
|
56
|
+
var generateData = function generateData(_ref) {
|
57
|
+
var rows = _ref.rows,
|
58
|
+
extraColumns = _ref.extraColumns;
|
59
|
+
|
51
60
|
var makeDataLevel = function makeDataLevel() {
|
52
61
|
var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
62
|
+
var lens = [rows];
|
53
63
|
var len = lens[depth];
|
54
64
|
return range(len).map(function () {
|
55
|
-
return _objectSpread(
|
56
|
-
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined
|
57
|
-
});
|
65
|
+
return _objectSpread({}, newPet(extraColumns));
|
58
66
|
});
|
59
67
|
};
|
60
68
|
|
@@ -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,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getSpreadsheetWidth = void 0;
|
7
|
+
|
8
|
+
var _layout = require("@carbon/layout");
|
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 getSpreadsheetWidth = function getSpreadsheetWidth(_ref) {
|
17
|
+
var type = _ref.type,
|
18
|
+
headerGroup = _ref.headerGroup,
|
19
|
+
scrollBarSizeValue = _ref.scrollBarSizeValue,
|
20
|
+
totalVisibleColumns = _ref.totalVisibleColumns,
|
21
|
+
defaultColumn = _ref.defaultColumn,
|
22
|
+
totalColumnsWidth = _ref.totalColumnsWidth;
|
23
|
+
var additionalWidth = scrollBarSizeValue + defaultColumn.rowHeaderWidth;
|
24
|
+
|
25
|
+
if (!totalVisibleColumns) {
|
26
|
+
if (type === 'header') {
|
27
|
+
return (0, _layout.px)(parseInt(headerGroup.getHeaderGroupProps().style.width) + additionalWidth);
|
28
|
+
}
|
29
|
+
|
30
|
+
if (type !== 'header') {
|
31
|
+
return totalColumnsWidth + additionalWidth;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
if (totalVisibleColumns) {
|
36
|
+
return totalVisibleColumns * (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width) + additionalWidth;
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
exports.getSpreadsheetWidth = getSpreadsheetWidth;
|
@@ -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;
|
@@ -0,0 +1,94 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.handleEditSubmit = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _removeCellSelections = require("./removeCellSelections");
|
13
|
+
|
14
|
+
var _uuidv = _interopRequireDefault(require("../../../global/js/utils/uuidv4"));
|
15
|
+
|
16
|
+
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; }
|
17
|
+
|
18
|
+
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; }
|
19
|
+
|
20
|
+
// Update the data
|
21
|
+
var handleEditSubmit = function handleEditSubmit(_ref) {
|
22
|
+
var activeCellCoordinates = _ref.activeCellCoordinates,
|
23
|
+
cellEditorRulerRef = _ref.cellEditorRulerRef,
|
24
|
+
columns = _ref.columns,
|
25
|
+
previousState = _ref.previousState,
|
26
|
+
removeCellEditor = _ref.removeCellEditor,
|
27
|
+
rows = _ref.rows,
|
28
|
+
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
29
|
+
setCurrentMatcher = _ref.setCurrentMatcher,
|
30
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
31
|
+
spreadsheetRef = _ref.spreadsheetRef,
|
32
|
+
updateData = _ref.updateData;
|
33
|
+
return function (event) {
|
34
|
+
var key = event.key;
|
35
|
+
|
36
|
+
var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref2) {
|
37
|
+
var type = _ref2.type;
|
38
|
+
|
39
|
+
var submitEditChanges = function submitEditChanges() {
|
40
|
+
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
|
41
|
+
var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
|
42
|
+
removeCellEditor();
|
43
|
+
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
44
|
+
};
|
45
|
+
|
46
|
+
(0, _removeCellSelections.removeCellSelections)({
|
47
|
+
spreadsheetRef: spreadsheetRef
|
48
|
+
});
|
49
|
+
submitEditChanges();
|
50
|
+
var tempMatcher = (0, _uuidv.default)();
|
51
|
+
var newSelectionArea = {
|
52
|
+
row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
|
53
|
+
column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
|
54
|
+
};
|
55
|
+
setSelectionAreas([{
|
56
|
+
point1: newSelectionArea,
|
57
|
+
point2: newSelectionArea,
|
58
|
+
matcher: tempMatcher,
|
59
|
+
areaCreated: false
|
60
|
+
}]);
|
61
|
+
setCurrentMatcher(tempMatcher);
|
62
|
+
cellEditorRulerRef.current.textContent = '';
|
63
|
+
};
|
64
|
+
|
65
|
+
if (key === 'Enter') {
|
66
|
+
updateSelectionAreaOnCellEditSubmit({
|
67
|
+
type: 'Enter'
|
68
|
+
});
|
69
|
+
setActiveCellCoordinates(function (prev) {
|
70
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
71
|
+
row: prev.row === rows.length - 1 ? prev.row : prev.row + 1 // do not move to next cell below if we're already in the last row
|
72
|
+
|
73
|
+
});
|
74
|
+
});
|
75
|
+
}
|
76
|
+
|
77
|
+
if (key === 'Tab') {
|
78
|
+
event.preventDefault();
|
79
|
+
updateSelectionAreaOnCellEditSubmit({
|
80
|
+
type: 'Tab'
|
81
|
+
});
|
82
|
+
setActiveCellCoordinates(function (prev) {
|
83
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
84
|
+
column: prev.column === columns.length - 1 ? prev.column : prev.column + 1 // do not move to next cell below if we're already in the last column
|
85
|
+
|
86
|
+
});
|
87
|
+
});
|
88
|
+
}
|
89
|
+
|
90
|
+
return;
|
91
|
+
};
|
92
|
+
};
|
93
|
+
|
94
|
+
exports.handleEditSubmit = handleEditSubmit;
|
@@ -7,10 +7,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.handleHeaderCellSelection = void 0;
|
9
9
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
11
|
+
|
12
|
+
var _deepCloneObject = require("../../../global/js/utils/deepCloneObject");
|
13
|
+
|
10
14
|
var _uuidv = _interopRequireDefault(require("../../../global/js/utils/uuidv4"));
|
11
15
|
|
12
16
|
var _removeCellSelections = require("./removeCellSelections");
|
13
17
|
|
18
|
+
var _checkActiveHeaderCell = require("./checkActiveHeaderCell");
|
19
|
+
|
14
20
|
/**
|
15
21
|
* Copyright IBM Corp. 2022, 2022
|
16
22
|
*
|
@@ -28,8 +34,16 @@ var handleHeaderCellSelection = function handleHeaderCellSelection(_ref) {
|
|
28
34
|
spreadsheetRef = _ref.spreadsheetRef,
|
29
35
|
index = _ref.index,
|
30
36
|
isKeyboard = _ref.isKeyboard,
|
31
|
-
setSelectionAreaData = _ref.setSelectionAreaData
|
32
|
-
|
37
|
+
setSelectionAreaData = _ref.setSelectionAreaData,
|
38
|
+
isHoldingCommandKey = _ref.isHoldingCommandKey;
|
39
|
+
|
40
|
+
if (!isHoldingCommandKey) {
|
41
|
+
setSelectionAreaData([]);
|
42
|
+
(0, _removeCellSelections.removeCellSelections)({
|
43
|
+
spreadsheetRef: spreadsheetRef
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
33
47
|
var rowValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row : index;
|
34
48
|
var columnValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column : index;
|
35
49
|
var point1 = {
|
@@ -47,15 +61,41 @@ var handleHeaderCellSelection = function handleHeaderCellSelection(_ref) {
|
|
47
61
|
column: type === 'column' ? columnValue : 0
|
48
62
|
});
|
49
63
|
setCurrentMatcher(tempMatcher);
|
50
|
-
|
51
|
-
spreadsheetRef: spreadsheetRef
|
52
|
-
});
|
53
|
-
setSelectionAreas([{
|
64
|
+
var newSelectionArea = {
|
54
65
|
point1: point1,
|
55
66
|
point2: point2,
|
56
67
|
areaCreated: false,
|
57
|
-
matcher: tempMatcher
|
58
|
-
|
68
|
+
matcher: tempMatcher,
|
69
|
+
header: {
|
70
|
+
type: type,
|
71
|
+
index: index
|
72
|
+
}
|
73
|
+
};
|
74
|
+
setSelectionAreas(function (prev) {
|
75
|
+
var selectionsClone = (0, _deepCloneObject.deepCloneObject)(prev);
|
76
|
+
|
77
|
+
if (isHoldingCommandKey) {
|
78
|
+
var selectionsFromHeaderCell = selectionsClone.filter(function (item) {
|
79
|
+
var _item$header;
|
80
|
+
|
81
|
+
return (_item$header = item.header) === null || _item$header === void 0 ? void 0 : _item$header.type;
|
82
|
+
});
|
83
|
+
var previouslyCreatedHeaderSelection = selectionsFromHeaderCell.filter(function (item) {
|
84
|
+
var _item$header2;
|
85
|
+
|
86
|
+
return ((_item$header2 = item.header) === null || _item$header2 === void 0 ? void 0 : _item$header2.type) === type;
|
87
|
+
});
|
88
|
+
var isHeaderPartOfPreviousSelection = (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, previouslyCreatedHeaderSelection, type); // Prevents row/column header selections from being created multiple times
|
89
|
+
|
90
|
+
if (previouslyCreatedHeaderSelection.length && isHeaderPartOfPreviousSelection) {
|
91
|
+
return prev;
|
92
|
+
}
|
93
|
+
|
94
|
+
return [].concat((0, _toConsumableArray2.default)(prev), [newSelectionArea]);
|
95
|
+
}
|
96
|
+
|
97
|
+
return [newSelectionArea];
|
98
|
+
});
|
59
99
|
};
|
60
100
|
|
61
101
|
exports.handleHeaderCellSelection = handleHeaderCellSelection;
|