@carbon/ibm-products 1.7.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +227 -5762
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +5 -5
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +46 -3426
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +3 -3
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +195 -4028
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +5 -5
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +195 -4029
- package/css/index.css.map +1 -1
- package/css/index.min.css +5 -5
- package/css/index.min.css.map +1 -1
- package/es/components/APIKeyModal/APIKeyModal.js +10 -13
- package/es/components/ActionBar/ActionBar.js +0 -3
- package/es/components/ActionBar/ActionBarItem.js +2 -6
- package/es/components/ActionSet/ActionSet.js +10 -12
- package/es/components/AddSelect/AddSelect.js +120 -25
- package/es/components/AddSelect/AddSelectBreadcrumbs.js +4 -4
- package/es/components/AddSelect/AddSelectColumn.js +58 -0
- package/es/components/AddSelect/AddSelectList.js +67 -8
- package/es/components/AddSelect/AddSelectSidebar.js +7 -1
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
- package/es/components/ButtonMenu/ButtonMenu.js +7 -5
- package/es/components/ButtonMenu/ButtonMenuItem.js +1 -2
- package/es/components/Card/Card.js +31 -21
- package/es/components/Card/CardFooter.js +14 -10
- package/es/components/Card/CardHeader.js +8 -6
- package/es/components/Cascade/Cascade.js +5 -4
- package/es/components/ComboButton/ComboButton.js +0 -4
- package/es/components/ComboButton/ComboButtonItem/index.js +0 -5
- package/es/components/CreateFullPage/CreateFullPageStep.js +15 -8
- package/es/components/CreateModal/CreateModal.js +1 -4
- package/es/components/CreateTearsheet/CreateTearsheet.js +10 -11
- package/es/components/CreateTearsheet/CreateTearsheetStep.js +18 -14
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +563 -80
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +366 -0
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +81 -0
- package/es/components/DataSpreadsheet/checkActiveHeaderCell.js +34 -0
- package/es/components/DataSpreadsheet/createActiveCellFn.js +47 -0
- package/es/components/DataSpreadsheet/createCellSelectionArea.js +45 -0
- package/es/components/DataSpreadsheet/getCellSize.js +30 -0
- package/es/components/EditSidePanel/EditSidePanel.js +9 -10
- package/es/components/EmptyStates/EmptyState.js +7 -6
- package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +4 -8
- package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +4 -8
- package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +4 -8
- package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +4 -8
- package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +4 -8
- package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +4 -8
- package/es/components/ExampleComponent/ExampleComponent.js +12 -13
- package/es/components/ExportModal/ExportModal.js +13 -9
- package/es/components/ExpressiveCard/ExpressiveCard.js +0 -8
- package/es/components/ImportModal/ImportModal.js +7 -5
- package/es/components/InlineEdit/InlineEdit.js +44 -46
- package/es/components/LoadingBar/LoadingBar.js +13 -17
- package/es/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
- package/es/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
- package/es/components/ModifiedTabs/ModifiedTabs.js +24 -18
- package/es/components/NotificationsPanel/NotificationsPanel.js +109 -86
- package/es/components/OptionsTile/OptionsTile.js +17 -10
- package/es/components/PageHeader/PageHeader.js +58 -47
- package/es/components/PageHeader/PageHeaderUtils.js +3 -7
- package/es/components/ProductiveCard/ProductiveCard.js +23 -12
- package/es/components/RemoveModal/RemoveModal.js +0 -3
- package/es/components/SidePanel/SidePanel.js +22 -17
- package/es/components/TagSet/TagSet.js +25 -12
- package/es/components/TagSet/TagSetModal.js +16 -12
- package/es/components/TagSet/TagSetOverflow.js +21 -13
- package/es/components/Tearsheet/Tearsheet.js +27 -18
- package/es/components/Tearsheet/TearsheetNarrow.js +18 -15
- package/es/components/Toolbar/ToolbarButton.js +0 -3
- package/es/components/UserProfileImage/UserProfileImage.js +2 -1
- package/es/components/WebTerminal/WebTerminal.js +17 -18
- package/es/components/index.js +0 -1
- package/es/global/js/hooks/index.js +1 -0
- package/es/global/js/hooks/useActiveElement.js +27 -0
- package/es/global/js/utils/DisplayBox.js +31 -0
- package/es/global/js/utils/Wrap.js +7 -5
- package/es/global/js/utils/deepCloneObject.js +26 -0
- package/lib/components/APIKeyModal/APIKeyModal.js +10 -13
- package/lib/components/ActionBar/ActionBar.js +0 -3
- package/lib/components/ActionBar/ActionBarItem.js +2 -6
- package/lib/components/ActionSet/ActionSet.js +10 -12
- package/lib/components/AddSelect/AddSelect.js +118 -24
- package/lib/components/AddSelect/AddSelectBreadcrumbs.js +2 -3
- package/lib/components/AddSelect/AddSelectColumn.js +79 -0
- package/lib/components/AddSelect/AddSelectList.js +65 -8
- package/lib/components/AddSelect/AddSelectSidebar.js +7 -1
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
- package/lib/components/ButtonMenu/ButtonMenu.js +7 -5
- package/lib/components/ButtonMenu/ButtonMenuItem.js +1 -2
- package/lib/components/Card/Card.js +31 -21
- package/lib/components/Card/CardFooter.js +14 -10
- package/lib/components/Card/CardHeader.js +8 -6
- package/lib/components/Cascade/Cascade.js +5 -4
- package/lib/components/ComboButton/ComboButton.js +0 -4
- package/lib/components/ComboButton/ComboButtonItem/index.js +0 -5
- package/lib/components/CreateFullPage/CreateFullPageStep.js +17 -14
- package/lib/components/CreateModal/CreateModal.js +1 -4
- package/lib/components/CreateTearsheet/CreateTearsheet.js +10 -11
- package/lib/components/CreateTearsheet/CreateTearsheetStep.js +20 -20
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +567 -77
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +391 -0
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +99 -0
- package/lib/components/DataSpreadsheet/checkActiveHeaderCell.js +45 -0
- package/lib/components/DataSpreadsheet/createActiveCellFn.js +58 -0
- package/lib/components/DataSpreadsheet/createCellSelectionArea.js +56 -0
- package/lib/components/DataSpreadsheet/getCellSize.js +39 -0
- package/lib/components/EditSidePanel/EditSidePanel.js +9 -10
- package/lib/components/EmptyStates/EmptyState.js +9 -8
- package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +3 -7
- package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +3 -7
- package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +3 -7
- package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +3 -7
- package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +3 -7
- package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +3 -7
- package/lib/components/ExampleComponent/ExampleComponent.js +12 -13
- package/lib/components/ExportModal/ExportModal.js +13 -9
- package/lib/components/ExpressiveCard/ExpressiveCard.js +0 -8
- package/lib/components/ImportModal/ImportModal.js +7 -5
- package/lib/components/InlineEdit/InlineEdit.js +43 -45
- package/lib/components/LoadingBar/LoadingBar.js +13 -17
- package/lib/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
- package/lib/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
- package/lib/components/ModifiedTabs/ModifiedTabs.js +24 -18
- package/lib/components/NotificationsPanel/NotificationsPanel.js +109 -86
- package/lib/components/OptionsTile/OptionsTile.js +17 -10
- package/lib/components/PageHeader/PageHeader.js +56 -46
- package/lib/components/PageHeader/PageHeaderUtils.js +3 -7
- package/lib/components/ProductiveCard/ProductiveCard.js +24 -18
- package/lib/components/RemoveModal/RemoveModal.js +0 -3
- package/lib/components/SidePanel/SidePanel.js +22 -17
- package/lib/components/TagSet/TagSet.js +26 -12
- package/lib/components/TagSet/TagSetModal.js +17 -13
- package/lib/components/TagSet/TagSetOverflow.js +24 -19
- package/lib/components/Tearsheet/Tearsheet.js +26 -17
- package/lib/components/Tearsheet/TearsheetNarrow.js +18 -15
- package/lib/components/Toolbar/ToolbarButton.js +0 -3
- package/lib/components/UserProfileImage/UserProfileImage.js +2 -1
- package/lib/components/WebTerminal/WebTerminal.js +17 -18
- package/lib/components/index.js +0 -8
- package/lib/global/js/hooks/index.js +8 -0
- package/lib/global/js/hooks/useActiveElement.js +39 -0
- package/lib/global/js/utils/DisplayBox.js +46 -0
- package/lib/global/js/utils/Wrap.js +7 -5
- package/lib/global/js/utils/deepCloneObject.js +37 -0
- package/package.json +18 -18
- package/scss/components/{CancelableTextEdit/_index.scss → ActionBar/_storybook-styles.scss} +2 -2
- package/scss/components/ActionSet/_storybook-styles.scss +1 -3
- package/scss/components/AddSelect/_add-select.scss +83 -14
- package/scss/components/{CancelableTextEdit → BreadcrumbWithOverflow}/_storybook-styles.scss +2 -2
- package/scss/components/ButtonSetWithOverflow/_storybook-styles.scss +8 -0
- package/scss/components/CreateInfluencer/_create-influencer.scss +2 -0
- package/scss/components/CreateModal/_create-modal.scss +1 -0
- package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
- package/scss/components/CreateTearsheetNarrow/_create-tearsheet-narrow.scss +1 -0
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +53 -7
- package/scss/components/InlineEdit/_inline-edit.scss +36 -15
- package/scss/components/InlineEdit/_storybook-styles.scss +2 -0
- package/scss/components/LoadingBar/_loading-bar.scss +13 -0
- package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -0
- package/scss/components/PageHeader/_page-header.scss +2 -0
- package/scss/components/SidePanel/_side-panel.scss +11 -4
- package/scss/components/StatusIcon/_status-icon.scss +1 -0
- package/scss/components/TagSet/_storybook-styles.scss +8 -0
- package/scss/components/Tearsheet/_tearsheet.scss +1 -2
- package/scss/components/UserProfileImage/_user-profile-image.scss +9 -0
- package/scss/components/WebTerminal/_web-terminal.scss +2 -0
- package/scss/components/_index.scss +0 -1
- package/scss/global/styles/_display-box.scss +62 -0
- package/es/components/CancelableTextEdit/CancelableTextEdit.js +0 -245
- package/es/components/CancelableTextEdit/index.js +0 -7
- package/lib/components/CancelableTextEdit/CancelableTextEdit.js +0 -265
- package/lib/components/CancelableTextEdit/index.js +0 -13
- package/scss/components/CancelableTextEdit/_cancelable-text-edit.scss +0 -212
@@ -0,0 +1,391 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
6
|
+
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
8
|
+
value: true
|
9
|
+
});
|
10
|
+
exports.DataSpreadsheetBody = void 0;
|
11
|
+
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13
|
+
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
+
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
17
|
+
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
19
|
+
|
20
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
21
|
+
|
22
|
+
var _reactWindow = require("react-window");
|
23
|
+
|
24
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
25
|
+
|
26
|
+
var _settings = require("../../settings");
|
27
|
+
|
28
|
+
var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
|
29
|
+
|
30
|
+
var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
|
31
|
+
|
32
|
+
var _createCellSelectionArea = require("./createCellSelectionArea");
|
33
|
+
|
34
|
+
var _checkActiveHeaderCell = require("./checkActiveHeaderCell");
|
35
|
+
|
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); }
|
37
|
+
|
38
|
+
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; }
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Copyright IBM Corp. 2022, 2022
|
42
|
+
*
|
43
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
44
|
+
* LICENSE file in the root directory of this source tree.
|
45
|
+
*/
|
46
|
+
var blockClass = "".concat(_settings.pkg.prefix, "--data-spreadsheet");
|
47
|
+
var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
48
|
+
var activeCellCoordinates = _ref.activeCellCoordinates,
|
49
|
+
defaultColumn = _ref.defaultColumn,
|
50
|
+
getTableBodyProps = _ref.getTableBodyProps,
|
51
|
+
id = _ref.id,
|
52
|
+
prepareRow = _ref.prepareRow,
|
53
|
+
rows = _ref.rows,
|
54
|
+
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
55
|
+
selectionAreas = _ref.selectionAreas,
|
56
|
+
setContainerHasFocus = _ref.setContainerHasFocus,
|
57
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
58
|
+
scrollBarSize = _ref.scrollBarSize,
|
59
|
+
totalColumnsWidth = _ref.totalColumnsWidth,
|
60
|
+
clickAndHoldActive = _ref.clickAndHoldActive,
|
61
|
+
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
62
|
+
currentMatcher = _ref.currentMatcher,
|
63
|
+
setCurrentMatcher = _ref.setCurrentMatcher;
|
64
|
+
var currentMatcherRef = ref; // Create cell selection areas based on selectionAreas array
|
65
|
+
|
66
|
+
(0, _react.useEffect)(function () {
|
67
|
+
if (selectionAreas && selectionAreas.length) {
|
68
|
+
selectionAreas.map(function (area) {
|
69
|
+
if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
|
70
|
+
// Do not create a cell selection area if point1 and point2 have the same values
|
71
|
+
// Cell selections must have two distinctly different points for an area to be created
|
72
|
+
if (area.point1.row === area.point2.row && area.point1.column === area.point2.column) {
|
73
|
+
var selectionAreasClone = (0, _deepCloneObject.deepCloneObject)(selectionAreas);
|
74
|
+
var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
|
75
|
+
return item.matcher === area.matcher;
|
76
|
+
});
|
77
|
+
selectionAreasClone[indexOfCurrentArea].areaCreated = false;
|
78
|
+
selectionAreasClone[indexOfCurrentArea].point2 = null;
|
79
|
+
return setSelectionAreas(selectionAreasClone);
|
80
|
+
}
|
81
|
+
|
82
|
+
(0, _createCellSelectionArea.createCellSelectionArea)({
|
83
|
+
area: area,
|
84
|
+
blockClass: blockClass,
|
85
|
+
selectionAreas: selectionAreas,
|
86
|
+
setSelectionAreas: setSelectionAreas
|
87
|
+
});
|
88
|
+
}
|
89
|
+
|
90
|
+
return;
|
91
|
+
});
|
92
|
+
}
|
93
|
+
}, [selectionAreas, setSelectionAreas]); // Mouse up
|
94
|
+
|
95
|
+
(0, _react.useEffect)(function () {
|
96
|
+
var handleMouseUp = function handleMouseUp(event) {
|
97
|
+
setClickAndHoldActive(false);
|
98
|
+
var cellButton = event.target.closest(".".concat(blockClass, "__body--td"));
|
99
|
+
|
100
|
+
if (cellButton) {
|
101
|
+
var endCellCoordinates = {
|
102
|
+
row: Number(cellButton.getAttribute('data-row-index')),
|
103
|
+
column: Number(cellButton.getAttribute('data-column-index'))
|
104
|
+
};
|
105
|
+
setSelectionAreas(function (prev) {
|
106
|
+
var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(prev);
|
107
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
108
|
+
return item.matcher === currentMatcher;
|
109
|
+
}); // No items in the array have an object that matches the value of currentMatcher
|
110
|
+
|
111
|
+
if (indexOfItemToUpdate === -1) {
|
112
|
+
return prev;
|
113
|
+
}
|
114
|
+
|
115
|
+
selectionAreaClone[indexOfItemToUpdate].point2 = endCellCoordinates;
|
116
|
+
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
117
|
+
return selectionAreaClone;
|
118
|
+
});
|
119
|
+
} else {
|
120
|
+
var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(selectionAreas);
|
121
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
122
|
+
return item.matcher === currentMatcher;
|
123
|
+
});
|
124
|
+
|
125
|
+
if (indexOfItemToUpdate === -1) {
|
126
|
+
return;
|
127
|
+
}
|
128
|
+
|
129
|
+
var notYetCreatedSelections = selectionAreaClone.filter(function (item) {
|
130
|
+
return !item.areaCreated && item.matcher === currentMatcher;
|
131
|
+
});
|
132
|
+
var previouslyCreatedSelectionAreas = selectionAreaClone.filter(function (item) {
|
133
|
+
return item.point2 && item.areaCreated;
|
134
|
+
}); // We want to ensure that there is only ever one item in selectionAreas
|
135
|
+
// that has not been created yet. This item's point1 values will always
|
136
|
+
// be equal to the activeCellCoordinates
|
137
|
+
|
138
|
+
setSelectionAreas([].concat((0, _toConsumableArray2.default)(notYetCreatedSelections), (0, _toConsumableArray2.default)(previouslyCreatedSelectionAreas)));
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
document.addEventListener('mouseup', handleMouseUp);
|
143
|
+
return function () {
|
144
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
145
|
+
};
|
146
|
+
}, [selectionAreas, currentMatcher, setSelectionAreas, setClickAndHoldActive, setCurrentMatcher, ref]); // Make sure that if the cellSize prop changes, the active
|
147
|
+
// cell also gets updated with the new size
|
148
|
+
|
149
|
+
(0, _react.useEffect)(function () {
|
150
|
+
var listContainer = spreadsheetBodyRef === null || spreadsheetBodyRef === void 0 ? void 0 : spreadsheetBodyRef.current;
|
151
|
+
var activeCellButton = listContainer.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
152
|
+
|
153
|
+
if (activeCellButton) {
|
154
|
+
activeCellButton.style.height = "".concat(defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight, "px");
|
155
|
+
}
|
156
|
+
}, [defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight]); // onClick fn for each cell in the data spreadsheet body,
|
157
|
+
// adds the active cell highlight
|
158
|
+
|
159
|
+
var handleBodyCellClick = (0, _react.useCallback)(function (cell, columnIndex) {
|
160
|
+
return function (event) {
|
161
|
+
event.preventDefault();
|
162
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
163
|
+
var isHoldingShiftKey = event.shiftKey;
|
164
|
+
setContainerHasFocus(true);
|
165
|
+
var activeCoordinates = {
|
166
|
+
row: cell.row.index,
|
167
|
+
column: columnIndex
|
168
|
+
};
|
169
|
+
var tempMatcher = (0, _uuidv.default)(); // prevent multiple selections unless cmd key is held
|
170
|
+
// meaning that selectionAreas should only have one item by default
|
171
|
+
|
172
|
+
if (isHoldingCommandKey) {
|
173
|
+
setActiveCellCoordinates(activeCoordinates);
|
174
|
+
setCurrentMatcher(tempMatcher);
|
175
|
+
setSelectionAreas(function (prev) {
|
176
|
+
return [].concat((0, _toConsumableArray2.default)(prev), [{
|
177
|
+
point1: activeCoordinates,
|
178
|
+
matcher: tempMatcher
|
179
|
+
}]);
|
180
|
+
});
|
181
|
+
} else if (isHoldingShiftKey) {
|
182
|
+
setContainerHasFocus(true);
|
183
|
+
var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(selectionAreas);
|
184
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
185
|
+
return item.matcher === currentMatcher;
|
186
|
+
});
|
187
|
+
|
188
|
+
if (indexOfItemToUpdate === -1) {
|
189
|
+
// There is always a selectionArea with a point1 object that updates
|
190
|
+
// whenever the activeCellCoordinates update, we should always be able
|
191
|
+
// to find an index, but if we do not for some reason we should return
|
192
|
+
// at this point.
|
193
|
+
return;
|
194
|
+
} else {
|
195
|
+
// Update the selectionArea that was found, do not update currentMatcher
|
196
|
+
selectionAreaClone[indexOfItemToUpdate].point1 = activeCellCoordinates;
|
197
|
+
selectionAreaClone[indexOfItemToUpdate].point2 = activeCoordinates;
|
198
|
+
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
199
|
+
selectionAreaClone[indexOfItemToUpdate].matcher = currentMatcher;
|
200
|
+
setSelectionAreas(selectionAreaClone);
|
201
|
+
}
|
202
|
+
} else {
|
203
|
+
setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
|
204
|
+
|
205
|
+
var cellSelections = spreadsheetBodyRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
|
206
|
+
(0, _toConsumableArray2.default)(cellSelections).forEach(function (element) {
|
207
|
+
return element.remove();
|
208
|
+
});
|
209
|
+
setSelectionAreas([{
|
210
|
+
point1: activeCoordinates,
|
211
|
+
matcher: tempMatcher
|
212
|
+
}]);
|
213
|
+
setCurrentMatcher(tempMatcher);
|
214
|
+
}
|
215
|
+
|
216
|
+
currentMatcherRef.current = tempMatcher;
|
217
|
+
setClickAndHoldActive(true);
|
218
|
+
};
|
219
|
+
}, [currentMatcherRef, currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher]);
|
220
|
+
var handleBodyCellHover = (0, _react.useCallback)(function (cell, columnIndex) {
|
221
|
+
return function () {
|
222
|
+
if (clickAndHoldActive) {
|
223
|
+
var cellCoordinates = {
|
224
|
+
row: cell.row.index,
|
225
|
+
column: columnIndex
|
226
|
+
};
|
227
|
+
setSelectionAreas(function (prev) {
|
228
|
+
var _selectionAreaClone$i, _selectionAreaClone$i2;
|
229
|
+
|
230
|
+
var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(prev);
|
231
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
232
|
+
return item.matcher === currentMatcher;
|
233
|
+
}); // No items in the array match up with the currentMatcher value
|
234
|
+
|
235
|
+
if (indexOfItemToUpdate === -1) {
|
236
|
+
return prev;
|
237
|
+
} // Do not update state if you're still hovering on the same cell
|
238
|
+
|
239
|
+
|
240
|
+
if (((_selectionAreaClone$i = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i === void 0 ? void 0 : _selectionAreaClone$i.row) === cellCoordinates.row && ((_selectionAreaClone$i2 = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i2 === void 0 ? void 0 : _selectionAreaClone$i2.column) === cellCoordinates.column) {
|
241
|
+
return prev;
|
242
|
+
}
|
243
|
+
|
244
|
+
selectionAreaClone[indexOfItemToUpdate].point2 = cellCoordinates;
|
245
|
+
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
246
|
+
return selectionAreaClone;
|
247
|
+
});
|
248
|
+
}
|
249
|
+
};
|
250
|
+
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]); // Renders each cell in the spreadsheet body
|
251
|
+
|
252
|
+
var RenderRow = (0, _react.useCallback)(function (_ref2) {
|
253
|
+
var index = _ref2.index,
|
254
|
+
style = _ref2.style;
|
255
|
+
var row = rows[index];
|
256
|
+
prepareRow(row);
|
257
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, row.getRowProps({
|
258
|
+
style: style
|
259
|
+
}), {
|
260
|
+
className: (0, _classnames.default)("".concat(blockClass, "__tr")),
|
261
|
+
"data-row-index": index
|
262
|
+
}), /*#__PURE__*/_react.default.createElement("button", {
|
263
|
+
tabIndex: -1,
|
264
|
+
"data-row-index": index,
|
265
|
+
"data-column-index": "header",
|
266
|
+
type: "button",
|
267
|
+
className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'row'))),
|
268
|
+
style: {
|
269
|
+
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
270
|
+
}
|
271
|
+
}, index + 1), row.cells.map(function (cell, index) {
|
272
|
+
return /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
|
273
|
+
tabIndex: -1,
|
274
|
+
"data-row-index": cell.row.index,
|
275
|
+
"data-column-index": index
|
276
|
+
}, cell.getCellProps(), {
|
277
|
+
className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
|
278
|
+
key: "cell_".concat(index),
|
279
|
+
onMouseDown: handleBodyCellClick(cell, index),
|
280
|
+
onMouseOver: handleBodyCellHover(cell, index),
|
281
|
+
onFocus: function onFocus() {},
|
282
|
+
type: "button"
|
283
|
+
}), cell.render('Cell'));
|
284
|
+
}));
|
285
|
+
}, [prepareRow, rows, defaultColumn.rowHeaderWidth, handleBodyCellClick, handleBodyCellHover, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas]);
|
286
|
+
var spreadsheetBodyRef = (0, _react.useRef)();
|
287
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
288
|
+
ref: spreadsheetBodyRef,
|
289
|
+
className: (0, _classnames.default)("".concat(blockClass, "__body--container"))
|
290
|
+
}, getTableBodyProps()), /*#__PURE__*/_react.default.createElement(_reactWindow.FixedSizeList, {
|
291
|
+
className: (0, _classnames.default)("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
|
292
|
+
height: 400,
|
293
|
+
itemCount: rows.length,
|
294
|
+
itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
295
|
+
width: totalColumnsWidth + scrollBarSize
|
296
|
+
}, RenderRow));
|
297
|
+
});
|
298
|
+
exports.DataSpreadsheetBody = DataSpreadsheetBody;
|
299
|
+
DataSpreadsheetBody.propTypes = {
|
300
|
+
/**
|
301
|
+
* Object containing the active cell coordinates
|
302
|
+
*/
|
303
|
+
activeCellCoordinates: _propTypes.default.shape({
|
304
|
+
row: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
305
|
+
column: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
306
|
+
}),
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Is the user clicking and holding in the data spreadsheet body
|
310
|
+
*/
|
311
|
+
clickAndHoldActive: _propTypes.default.bool,
|
312
|
+
|
313
|
+
/**
|
314
|
+
* This represents the id of the current cell selection area
|
315
|
+
*/
|
316
|
+
currentMatcher: _propTypes.default.string,
|
317
|
+
|
318
|
+
/**
|
319
|
+
* Default spreadsheet sizing values
|
320
|
+
*/
|
321
|
+
defaultColumn: _propTypes.default.shape({
|
322
|
+
rowHeight: _propTypes.default.number,
|
323
|
+
rowHeaderWidth: _propTypes.default.number,
|
324
|
+
width: _propTypes.default.number
|
325
|
+
}),
|
326
|
+
|
327
|
+
/**
|
328
|
+
* Function to set table body prop values
|
329
|
+
*/
|
330
|
+
getTableBodyProps: _propTypes.default.func,
|
331
|
+
|
332
|
+
/**
|
333
|
+
* The spreadsheet id
|
334
|
+
*/
|
335
|
+
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
336
|
+
|
337
|
+
/**
|
338
|
+
* The event handler that is called when the active cell changes
|
339
|
+
*/
|
340
|
+
onActiveCellChange: _propTypes.default.func,
|
341
|
+
|
342
|
+
/**
|
343
|
+
* Prepare row function from react-table
|
344
|
+
*/
|
345
|
+
prepareRow: _propTypes.default.func,
|
346
|
+
|
347
|
+
/**
|
348
|
+
* All of the spreadsheet row data
|
349
|
+
*/
|
350
|
+
rows: _propTypes.default.arrayOf(_propTypes.default.object),
|
351
|
+
|
352
|
+
/**
|
353
|
+
* The scrollbar width
|
354
|
+
*/
|
355
|
+
scrollBarSize: _propTypes.default.number,
|
356
|
+
|
357
|
+
/**
|
358
|
+
* Array of selection areas
|
359
|
+
*/
|
360
|
+
selectionAreas: _propTypes.default.array,
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Setter fn for activeCellCoordinates state value
|
364
|
+
*/
|
365
|
+
setActiveCellCoordinates: _propTypes.default.func,
|
366
|
+
|
367
|
+
/**
|
368
|
+
* Setter fn for clickAndHold state value
|
369
|
+
*/
|
370
|
+
setClickAndHoldActive: _propTypes.default.func,
|
371
|
+
|
372
|
+
/**
|
373
|
+
* Setter fn for containerHasFocus state value
|
374
|
+
*/
|
375
|
+
setContainerHasFocus: _propTypes.default.func,
|
376
|
+
|
377
|
+
/**
|
378
|
+
* Setter fn for currentMatcher state value
|
379
|
+
*/
|
380
|
+
setCurrentMatcher: _propTypes.default.func,
|
381
|
+
|
382
|
+
/**
|
383
|
+
* Setter fn for selectionAreas state value
|
384
|
+
*/
|
385
|
+
setSelectionAreas: _propTypes.default.func,
|
386
|
+
|
387
|
+
/**
|
388
|
+
* The total columns width
|
389
|
+
*/
|
390
|
+
totalColumnsWidth: _propTypes.default.number
|
391
|
+
};
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.DataSpreadsheetHeader = void 0;
|
9
|
+
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11
|
+
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
+
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
15
|
+
|
16
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
17
|
+
|
18
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
19
|
+
|
20
|
+
var _settings = require("../../settings");
|
21
|
+
|
22
|
+
var _checkActiveHeaderCell = require("./checkActiveHeaderCell");
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Copyright IBM Corp. 2022, 2022
|
26
|
+
*
|
27
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
28
|
+
* LICENSE file in the root directory of this source tree.
|
29
|
+
*/
|
30
|
+
var blockClass = "".concat(_settings.pkg.prefix, "--data-spreadsheet");
|
31
|
+
|
32
|
+
var DataSpreadsheetHeader = function DataSpreadsheetHeader(_ref) {
|
33
|
+
var activeCellCoordinates = _ref.activeCellCoordinates,
|
34
|
+
defaultColumn = _ref.defaultColumn,
|
35
|
+
headerGroups = _ref.headerGroups,
|
36
|
+
selectionAreas = _ref.selectionAreas;
|
37
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
38
|
+
className: (0, _classnames.default)("".concat(blockClass, "__header--container"))
|
39
|
+
}, headerGroups.map(function (headerGroup, index) {
|
40
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
41
|
+
key: "header_".concat(index)
|
42
|
+
}, headerGroup.getHeaderGroupProps(), {
|
43
|
+
className: "".concat(blockClass, "__tr")
|
44
|
+
}), /*#__PURE__*/_react.default.createElement("button", {
|
45
|
+
"data-row-index": "header",
|
46
|
+
"data-column-index": "header",
|
47
|
+
type: "button",
|
48
|
+
tabIndex: -1,
|
49
|
+
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (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')),
|
50
|
+
style: {
|
51
|
+
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
|
52
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
53
|
+
}
|
54
|
+
}, "\xA0"), headerGroup.headers.map(function (column, index) {
|
55
|
+
return /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
|
56
|
+
key: "column_".concat(index),
|
57
|
+
"data-row-index": "header",
|
58
|
+
"data-column-index": index,
|
59
|
+
tabIndex: -1,
|
60
|
+
style: {
|
61
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
62
|
+
}
|
63
|
+
}, column.getHeaderProps(), {
|
64
|
+
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'column'))),
|
65
|
+
type: "button"
|
66
|
+
}), column.render('Header'));
|
67
|
+
}));
|
68
|
+
}));
|
69
|
+
};
|
70
|
+
|
71
|
+
exports.DataSpreadsheetHeader = DataSpreadsheetHeader;
|
72
|
+
DataSpreadsheetHeader.propTypes = {
|
73
|
+
/**
|
74
|
+
* Object containing the active cell coordinates
|
75
|
+
*/
|
76
|
+
activeCellCoordinates: _propTypes.default.shape({
|
77
|
+
row: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
78
|
+
column: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
79
|
+
}),
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Default spreadsheet sizing values
|
83
|
+
*/
|
84
|
+
defaultColumn: _propTypes.default.shape({
|
85
|
+
rowHeight: _propTypes.default.number,
|
86
|
+
rowHeaderWidth: _propTypes.default.number,
|
87
|
+
width: _propTypes.default.number
|
88
|
+
}),
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Headers provided from useTable hook
|
92
|
+
*/
|
93
|
+
headerGroups: _propTypes.default.arrayOf(_propTypes.default.object),
|
94
|
+
|
95
|
+
/**
|
96
|
+
* All of the cell selection area items
|
97
|
+
*/
|
98
|
+
selectionAreas: _propTypes.default.arrayOf(_propTypes.default.object)
|
99
|
+
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.checkActiveHeaderCell = void 0;
|
9
|
+
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
11
|
+
|
12
|
+
var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Copyright IBM Corp. 2022, 2022
|
16
|
+
*
|
17
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
19
|
+
*/
|
20
|
+
// Determines if a row or column header cell should receive a highlight/active background color
|
21
|
+
// Check each object in selectionAreas and see if the headerIndex is between
|
22
|
+
// point1.row and point2.row, inclusive
|
23
|
+
var checkActiveHeaderCell = function checkActiveHeaderCell(headerIndex, selectionAreas, headerType) {
|
24
|
+
var areasCloned = (0, _deepCloneObject.deepCloneObject)(selectionAreas);
|
25
|
+
var activeRowIndexes = [];
|
26
|
+
areasCloned.forEach(function (area) {
|
27
|
+
var _area$point, _area$point2, _area$point3, _area$point4;
|
28
|
+
|
29
|
+
var greatestRowIndex = Math.max((_area$point = area.point1) === null || _area$point === void 0 ? void 0 : _area$point[headerType], (_area$point2 = area.point2) === null || _area$point2 === void 0 ? void 0 : _area$point2[headerType]);
|
30
|
+
var lowestRowIndex = Math.min((_area$point3 = area.point1) === null || _area$point3 === void 0 ? void 0 : _area$point3[headerType], (_area$point4 = area.point2) === null || _area$point4 === void 0 ? void 0 : _area$point4[headerType]);
|
31
|
+
|
32
|
+
for (var i = lowestRowIndex; i <= greatestRowIndex; i++) {
|
33
|
+
activeRowIndexes.push(i);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
var activeRowIndexesNoDuplicates = (0, _toConsumableArray2.default)(new Set(activeRowIndexes));
|
37
|
+
|
38
|
+
if (areasCloned !== null && areasCloned !== void 0 && areasCloned.length && activeRowIndexesNoDuplicates.includes(headerIndex)) {
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
|
42
|
+
return false;
|
43
|
+
};
|
44
|
+
|
45
|
+
exports.checkActiveHeaderCell = checkActiveHeaderCell;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createActiveCellFn = void 0;
|
7
|
+
|
8
|
+
var _layout = require("@carbon/layout");
|
9
|
+
|
10
|
+
var _settings = require("../../settings");
|
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 createActiveCellFn = function createActiveCellFn(_ref) {
|
19
|
+
var placementElement = _ref.placementElement,
|
20
|
+
coords = _ref.coords,
|
21
|
+
_ref$addToHeader = _ref.addToHeader,
|
22
|
+
addToHeader = _ref$addToHeader === void 0 ? false : _ref$addToHeader,
|
23
|
+
contextRef = _ref.contextRef,
|
24
|
+
_ref$blockClass = _ref.blockClass,
|
25
|
+
blockClass = _ref$blockClass === void 0 ? "".concat(_settings.pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
26
|
+
onActiveCellChange = _ref.onActiveCellChange,
|
27
|
+
activeCellValue = _ref.activeCellValue,
|
28
|
+
handleActiveCellMouseEnter = _ref.handleActiveCellMouseEnter;
|
29
|
+
|
30
|
+
if (!coords) {
|
31
|
+
return;
|
32
|
+
} // If the active cell is in the column header row (very first), we need to append this element
|
33
|
+
// to `.${blockClass}__header--container`, otherwise it should be appended to `.${blockClass}__listContainer` firstElementChild
|
34
|
+
|
35
|
+
|
36
|
+
var activeElementContainer = addToHeader ? contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__header--container")) : contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
37
|
+
var relativePosition = {
|
38
|
+
top: placementElement.getBoundingClientRect().top - activeElementContainer.getBoundingClientRect().top,
|
39
|
+
left: placementElement.getBoundingClientRect().left - activeElementContainer.getBoundingClientRect().left
|
40
|
+
};
|
41
|
+
var activeCellButton = (contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"))) || document.createElement('button');
|
42
|
+
activeCellButton.classList.add("".concat(blockClass, "__active-cell--highlight"), "".concat(blockClass, "--interactive-cell-element"));
|
43
|
+
activeCellButton.addEventListener('mouseenter', handleActiveCellMouseEnter);
|
44
|
+
activeCellButton.style.width = (0, _layout.px)(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetWidth);
|
45
|
+
activeCellButton.style.height = (0, _layout.px)(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetHeight);
|
46
|
+
activeCellButton.style.left = (0, _layout.px)(relativePosition.left);
|
47
|
+
activeCellButton.style.top = (0, _layout.px)(relativePosition.top);
|
48
|
+
activeCellButton.setAttribute('data-active-row-index', typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number' ? coords.row : 'header');
|
49
|
+
activeCellButton.setAttribute('data-active-column-index', typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' ? coords.column : 'header');
|
50
|
+
activeElementContainer.appendChild(activeCellButton);
|
51
|
+
activeCellButton.focus();
|
52
|
+
|
53
|
+
if (typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' && typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number') {
|
54
|
+
onActiveCellChange === null || onActiveCellChange === void 0 ? void 0 : onActiveCellChange(activeCellValue);
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
exports.createActiveCellFn = createActiveCellFn;
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createCellSelectionArea = void 0;
|
7
|
+
|
8
|
+
var _layout = require("@carbon/layout");
|
9
|
+
|
10
|
+
var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
|
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 createCellSelectionArea = function createCellSelectionArea(_ref) {
|
19
|
+
var area = _ref.area,
|
20
|
+
blockClass = _ref.blockClass,
|
21
|
+
selectionAreas = _ref.selectionAreas,
|
22
|
+
setSelectionAreas = _ref.setSelectionAreas;
|
23
|
+
var greatestRow = Math.max(area.point1.row, area.point2.row);
|
24
|
+
var greatestColumn = Math.max(area.point1.column, area.point2.column);
|
25
|
+
var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
|
26
|
+
var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
|
27
|
+
var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]"));
|
28
|
+
var selectionAreaCellWidth = point1Element.offsetWidth;
|
29
|
+
var selectionAreaCellHeight = point1Element.offsetHeight;
|
30
|
+
var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumn - lowestColumnIndex + 1);
|
31
|
+
var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRow - lowestRowIndex + 1);
|
32
|
+
var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
33
|
+
var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
|
34
|
+
var relativePosition = {
|
35
|
+
top: placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top,
|
36
|
+
left: placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left
|
37
|
+
};
|
38
|
+
var selectionAreaElement = document.querySelector("[data-matcher-id=\"".concat(area.matcher, "\"]")) || document.createElement('div');
|
39
|
+
selectionAreaElement.classList.add("".concat(blockClass, "__selection-area--element"));
|
40
|
+
selectionAreaElement.setAttribute('data-matcher-id', area.matcher);
|
41
|
+
selectionAreaElement.style.width = (0, _layout.px)(selectionAreaTotalWidth);
|
42
|
+
selectionAreaElement.style.height = (0, _layout.px)(selectionAreaTotalHeight);
|
43
|
+
selectionAreaElement.style.left = (0, _layout.px)(relativePosition.left);
|
44
|
+
selectionAreaElement.style.top = (0, _layout.px)(relativePosition.top);
|
45
|
+
bodyContainer.appendChild(selectionAreaElement);
|
46
|
+
var selectionAreasClone = (0, _deepCloneObject.deepCloneObject)(selectionAreas);
|
47
|
+
var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
|
48
|
+
return item.matcher === area.matcher;
|
49
|
+
}); // We need to add another property to the selectionAreas object array to
|
50
|
+
// let us know if an area has been created for each item already, ie createdArea: true
|
51
|
+
|
52
|
+
selectionAreasClone[indexOfCurrentArea].areaCreated = true;
|
53
|
+
setSelectionAreas(selectionAreasClone);
|
54
|
+
};
|
55
|
+
|
56
|
+
exports.createCellSelectionArea = createCellSelectionArea;
|