@carbon/ibm-products 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +76 -30
- 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 +10 -4
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +1 -1
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +76 -30
- 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 +76 -30
- 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 +88 -87
- package/es/components/AddSelect/AddSelectColumn.js +143 -6
- package/es/components/AddSelect/AddSelectSidebar.js +1 -14
- package/es/components/AddSelect/add-select-utils.js +64 -0
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +255 -140
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +37 -38
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +55 -6
- package/es/components/DataSpreadsheet/hooks/useMoveActiveCell.js +27 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +28 -0
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +41 -0
- package/es/components/DataSpreadsheet/{checkActiveHeaderCell.js → utils/checkActiveHeaderCell.js} +1 -1
- package/es/components/DataSpreadsheet/{createActiveCellFn.js → utils/createActiveCellFn.js} +20 -9
- package/es/components/DataSpreadsheet/{createCellSelectionArea.js → utils/createCellSelectionArea.js} +8 -4
- package/es/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
- package/es/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +46 -0
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +82 -0
- package/es/components/DataSpreadsheet/utils/removeCellSelections.js +30 -0
- package/es/components/InlineEdit/InlineEdit.js +49 -8
- package/es/components/OptionsTile/OptionsTile.js +20 -20
- package/es/components/OptionsTile/index.js +1 -1
- package/es/components/PageHeader/PageHeader.js +35 -32
- package/es/components/PageHeader/PageHeaderTitle.js +2 -1
- package/es/components/PageHeader/PageHeaderUtils.js +21 -22
- package/lib/components/AddSelect/AddSelect.js +91 -87
- package/lib/components/AddSelect/AddSelectColumn.js +144 -4
- package/lib/components/AddSelect/AddSelectSidebar.js +7 -14
- package/lib/components/AddSelect/add-select-utils.js +78 -0
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +263 -142
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +39 -36
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +62 -8
- package/lib/components/DataSpreadsheet/hooks/useMoveActiveCell.js +37 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +39 -0
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +52 -0
- package/lib/components/DataSpreadsheet/{checkActiveHeaderCell.js → utils/checkActiveHeaderCell.js} +1 -1
- package/lib/components/DataSpreadsheet/{createActiveCellFn.js → utils/createActiveCellFn.js} +20 -9
- package/lib/components/DataSpreadsheet/{createCellSelectionArea.js → utils/createCellSelectionArea.js} +8 -4
- package/lib/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
- package/lib/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +59 -0
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +92 -0
- package/lib/components/DataSpreadsheet/utils/removeCellSelections.js +41 -0
- package/lib/components/InlineEdit/InlineEdit.js +52 -10
- package/lib/components/OptionsTile/OptionsTile.js +19 -19
- package/lib/components/PageHeader/PageHeader.js +35 -32
- package/lib/components/PageHeader/PageHeaderTitle.js +2 -1
- package/lib/components/PageHeader/PageHeaderUtils.js +21 -22
- package/package.json +2 -2
- package/scss/components/AddSelect/_add-select.scss +16 -0
- package/scss/components/BreadcrumbWithOverflow/_breadcrumb-with-overflow.scss +7 -3
- package/scss/components/CreateSidePanel/_create-side-panel.scss +1 -1
- package/scss/components/CreateSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +14 -1
- package/scss/components/EditSidePanel/_edit-side-panel.scss +9 -0
- package/scss/components/EditSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/InlineEdit/_inline-edit.scss +31 -37
- package/scss/components/OptionsTile/_index.scss +1 -1
- package/scss/components/OptionsTile/_options-tile.scss +17 -17
- package/scss/components/OptionsTile/_storybook-styles.scss +4 -4
- package/scss/components/PageHeader/_page-header.scss +3 -2
- package/scss/components/SidePanel/_side-panel.scss +8 -8
@@ -15,11 +15,14 @@ import cx from 'classnames';
|
|
15
15
|
import { pkg } from '../../settings';
|
16
16
|
import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
|
17
17
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
18
|
-
import {
|
19
|
-
import {
|
18
|
+
import { removeCellSelections } from './utils/removeCellSelections';
|
19
|
+
import { createCellSelectionArea } from './utils/createCellSelectionArea';
|
20
|
+
import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
|
21
|
+
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
20
22
|
var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
|
21
23
|
export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
22
|
-
var
|
24
|
+
var columns = _ref.columns,
|
25
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
23
26
|
defaultColumn = _ref.defaultColumn,
|
24
27
|
getTableBodyProps = _ref.getTableBodyProps,
|
25
28
|
id = _ref.id,
|
@@ -35,8 +38,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
35
38
|
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
36
39
|
currentMatcher = _ref.currentMatcher,
|
37
40
|
setCurrentMatcher = _ref.setCurrentMatcher;
|
38
|
-
|
39
|
-
|
41
|
+
// Create cell selection areas based on selectionAreas array
|
40
42
|
useEffect(function () {
|
41
43
|
if (selectionAreas && selectionAreas.length) {
|
42
44
|
selectionAreas.map(function (area) {
|
@@ -56,6 +58,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
56
58
|
createCellSelectionArea({
|
57
59
|
area: area,
|
58
60
|
blockClass: blockClass,
|
61
|
+
defaultColumn: defaultColumn,
|
59
62
|
selectionAreas: selectionAreas,
|
60
63
|
setSelectionAreas: setSelectionAreas
|
61
64
|
});
|
@@ -64,7 +67,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
64
67
|
return;
|
65
68
|
});
|
66
69
|
}
|
67
|
-
}, [selectionAreas, setSelectionAreas]); // Mouse up
|
70
|
+
}, [selectionAreas, setSelectionAreas, defaultColumn]); // Mouse up
|
68
71
|
|
69
72
|
useEffect(function () {
|
70
73
|
var handleMouseUp = function handleMouseUp(event) {
|
@@ -90,26 +93,6 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
90
93
|
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
91
94
|
return selectionAreaClone;
|
92
95
|
});
|
93
|
-
} else {
|
94
|
-
var selectionAreaClone = deepCloneObject(selectionAreas);
|
95
|
-
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
96
|
-
return item.matcher === currentMatcher;
|
97
|
-
});
|
98
|
-
|
99
|
-
if (indexOfItemToUpdate === -1) {
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
|
103
|
-
var notYetCreatedSelections = selectionAreaClone.filter(function (item) {
|
104
|
-
return !item.areaCreated && item.matcher === currentMatcher;
|
105
|
-
});
|
106
|
-
var previouslyCreatedSelectionAreas = selectionAreaClone.filter(function (item) {
|
107
|
-
return item.point2 && item.areaCreated;
|
108
|
-
}); // We want to ensure that there is only ever one item in selectionAreas
|
109
|
-
// that has not been created yet. This item's point1 values will always
|
110
|
-
// be equal to the activeCellCoordinates
|
111
|
-
|
112
|
-
setSelectionAreas([].concat(_toConsumableArray(notYetCreatedSelections), _toConsumableArray(previouslyCreatedSelectionAreas)));
|
113
96
|
}
|
114
97
|
};
|
115
98
|
|
@@ -140,7 +123,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
140
123
|
row: cell.row.index,
|
141
124
|
column: columnIndex
|
142
125
|
};
|
143
|
-
var tempMatcher = uuidv4();
|
126
|
+
var tempMatcher = uuidv4();
|
127
|
+
setClickAndHoldActive(true); // prevent multiple selections unless cmd key is held
|
144
128
|
// meaning that selectionAreas should only have one item by default
|
145
129
|
|
146
130
|
if (isHoldingCommandKey) {
|
@@ -176,23 +160,17 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
176
160
|
} else {
|
177
161
|
setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
|
178
162
|
|
179
|
-
|
180
|
-
|
181
|
-
_toConsumableArray(cellSelections).forEach(function (element) {
|
182
|
-
return element.remove();
|
163
|
+
removeCellSelections({
|
164
|
+
spreadsheetRef: ref
|
183
165
|
});
|
184
|
-
|
185
166
|
setSelectionAreas([{
|
186
167
|
point1: activeCoordinates,
|
187
168
|
matcher: tempMatcher
|
188
169
|
}]);
|
189
170
|
setCurrentMatcher(tempMatcher);
|
190
171
|
}
|
191
|
-
|
192
|
-
currentMatcherRef.current = tempMatcher;
|
193
|
-
setClickAndHoldActive(true);
|
194
172
|
};
|
195
|
-
}, [
|
173
|
+
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref]);
|
196
174
|
var handleBodyCellHover = useCallback(function (cell, columnIndex) {
|
197
175
|
return function () {
|
198
176
|
if (clickAndHoldActive) {
|
@@ -223,7 +201,22 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
223
201
|
});
|
224
202
|
}
|
225
203
|
};
|
226
|
-
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
|
204
|
+
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
|
205
|
+
var handleRowHeaderClick = useCallback(function (index) {
|
206
|
+
return function () {
|
207
|
+
handleHeaderCellSelection({
|
208
|
+
type: 'row',
|
209
|
+
activeCellCoordinates: activeCellCoordinates,
|
210
|
+
rows: rows,
|
211
|
+
columns: columns,
|
212
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
213
|
+
setCurrentMatcher: setCurrentMatcher,
|
214
|
+
setSelectionAreas: setSelectionAreas,
|
215
|
+
spreadsheetRef: ref,
|
216
|
+
index: index
|
217
|
+
});
|
218
|
+
};
|
219
|
+
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows]); // Renders each row/cell in the spreadsheet body
|
227
220
|
|
228
221
|
var RenderRow = useCallback(function (_ref2) {
|
229
222
|
var index = _ref2.index,
|
@@ -240,6 +233,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
240
233
|
"data-row-index": index,
|
241
234
|
"data-column-index": "header",
|
242
235
|
type: "button",
|
236
|
+
onClick: handleRowHeaderClick(index),
|
243
237
|
className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || checkActiveHeaderCell(index, selectionAreas, 'row'))),
|
244
238
|
style: {
|
245
239
|
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
@@ -258,7 +252,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
258
252
|
type: "button"
|
259
253
|
}), cell.render('Cell'));
|
260
254
|
}));
|
261
|
-
}, [prepareRow, rows, defaultColumn.rowHeaderWidth,
|
255
|
+
}, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
|
262
256
|
var spreadsheetBodyRef = useRef();
|
263
257
|
return /*#__PURE__*/React.createElement("div", _extends({
|
264
258
|
ref: spreadsheetBodyRef,
|
@@ -285,6 +279,11 @@ DataSpreadsheetBody.propTypes = {
|
|
285
279
|
*/
|
286
280
|
clickAndHoldActive: PropTypes.bool,
|
287
281
|
|
282
|
+
/**
|
283
|
+
* All of the spreadsheet columns
|
284
|
+
*/
|
285
|
+
columns: PropTypes.array,
|
286
|
+
|
288
287
|
/**
|
289
288
|
* This represents the id of the current cell selection area
|
290
289
|
*/
|
@@ -7,17 +7,40 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
7
|
* This source code is licensed under the Apache-2.0 license found in the
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
|
-
import React from 'react';
|
10
|
+
import React, { forwardRef } from 'react';
|
11
11
|
import PropTypes from 'prop-types';
|
12
12
|
import cx from 'classnames';
|
13
13
|
import { pkg } from '../../settings';
|
14
|
-
import { checkActiveHeaderCell } from './checkActiveHeaderCell';
|
14
|
+
import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
|
15
|
+
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
15
16
|
var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
|
16
|
-
export var DataSpreadsheetHeader = function
|
17
|
+
export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
17
18
|
var activeCellCoordinates = _ref.activeCellCoordinates,
|
19
|
+
columns = _ref.columns,
|
18
20
|
defaultColumn = _ref.defaultColumn,
|
19
21
|
headerGroups = _ref.headerGroups,
|
20
|
-
selectionAreas = _ref.selectionAreas
|
22
|
+
selectionAreas = _ref.selectionAreas,
|
23
|
+
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
24
|
+
setCurrentMatcher = _ref.setCurrentMatcher,
|
25
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
26
|
+
rows = _ref.rows;
|
27
|
+
|
28
|
+
var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
|
29
|
+
return function () {
|
30
|
+
handleHeaderCellSelection({
|
31
|
+
type: 'column',
|
32
|
+
activeCellCoordinates: activeCellCoordinates,
|
33
|
+
rows: rows,
|
34
|
+
columns: columns,
|
35
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
36
|
+
setCurrentMatcher: setCurrentMatcher,
|
37
|
+
setSelectionAreas: setSelectionAreas,
|
38
|
+
spreadsheetRef: ref,
|
39
|
+
index: index
|
40
|
+
});
|
41
|
+
};
|
42
|
+
};
|
43
|
+
|
21
44
|
return /*#__PURE__*/React.createElement("div", {
|
22
45
|
className: cx("".concat(blockClass, "__header--container"))
|
23
46
|
}, headerGroups.map(function (headerGroup, index) {
|
@@ -41,6 +64,7 @@ export var DataSpreadsheetHeader = function DataSpreadsheetHeader(_ref) {
|
|
41
64
|
"data-row-index": "header",
|
42
65
|
"data-column-index": index,
|
43
66
|
tabIndex: -1,
|
67
|
+
onClick: handleColumnHeaderClick(index),
|
44
68
|
style: {
|
45
69
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
46
70
|
}
|
@@ -50,7 +74,7 @@ export var DataSpreadsheetHeader = function DataSpreadsheetHeader(_ref) {
|
|
50
74
|
}), column.render('Header'));
|
51
75
|
}));
|
52
76
|
}));
|
53
|
-
};
|
77
|
+
});
|
54
78
|
DataSpreadsheetHeader.propTypes = {
|
55
79
|
/**
|
56
80
|
* Object containing the active cell coordinates
|
@@ -60,6 +84,11 @@ DataSpreadsheetHeader.propTypes = {
|
|
60
84
|
column: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
61
85
|
}),
|
62
86
|
|
87
|
+
/**
|
88
|
+
* All of the spreadsheet columns
|
89
|
+
*/
|
90
|
+
columns: PropTypes.array,
|
91
|
+
|
63
92
|
/**
|
64
93
|
* Default spreadsheet sizing values
|
65
94
|
*/
|
@@ -74,8 +103,28 @@ DataSpreadsheetHeader.propTypes = {
|
|
74
103
|
*/
|
75
104
|
headerGroups: PropTypes.arrayOf(PropTypes.object),
|
76
105
|
|
106
|
+
/**
|
107
|
+
* All of the spreadsheet row data
|
108
|
+
*/
|
109
|
+
rows: PropTypes.arrayOf(PropTypes.object),
|
110
|
+
|
77
111
|
/**
|
78
112
|
* All of the cell selection area items
|
79
113
|
*/
|
80
|
-
selectionAreas: PropTypes.arrayOf(PropTypes.object)
|
114
|
+
selectionAreas: PropTypes.arrayOf(PropTypes.object),
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Setter fn for activeCellCoordinates value
|
118
|
+
*/
|
119
|
+
setActiveCellCoordinates: PropTypes.func,
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Setter fn for currentMatcher value
|
123
|
+
*/
|
124
|
+
setCurrentMatcher: PropTypes.func,
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Setter fn for selectionAreas value
|
128
|
+
*/
|
129
|
+
setSelectionAreas: PropTypes.func
|
81
130
|
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2022, 2022
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import { useEffect } from 'react'; // Moves the placement of the active cell
|
8
|
+
|
9
|
+
export var useMoveActiveCell = function useMoveActiveCell(_ref) {
|
10
|
+
var spreadsheetRef = _ref.spreadsheetRef,
|
11
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
12
|
+
containerHasFocus = _ref.containerHasFocus,
|
13
|
+
createActiveCell = _ref.createActiveCell;
|
14
|
+
useEffect(function () {
|
15
|
+
var activeCellPlacementElement = spreadsheetRef === null || spreadsheetRef === void 0 ? void 0 : spreadsheetRef.current.querySelector("[data-row-index=\"".concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, "\"][data-column-index=\"").concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column, "\"]"));
|
16
|
+
var shouldPlaceActiveCellInHeader = (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && true;
|
17
|
+
var selectAllElement = spreadsheetRef === null || spreadsheetRef === void 0 ? void 0 : spreadsheetRef.current.querySelector("[data-row-index=\"header\"][data-column-index=\"header\"]");
|
18
|
+
|
19
|
+
if (containerHasFocus) {
|
20
|
+
createActiveCell({
|
21
|
+
placementElement: activeCellCoordinates ? activeCellPlacementElement : selectAllElement,
|
22
|
+
coords: activeCellCoordinates,
|
23
|
+
addToHeader: shouldPlaceActiveCellInHeader
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}, [activeCellCoordinates, spreadsheetRef, createActiveCell, containerHasFocus]);
|
27
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2022, 2022
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import { useEffect } from 'react';
|
8
|
+
import { pkg } from '../../../settings';
|
9
|
+
export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
10
|
+
var activeKeys = _ref.activeKeys,
|
11
|
+
_ref$blockClass = _ref.blockClass,
|
12
|
+
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
13
|
+
focusedElement = _ref.focusedElement,
|
14
|
+
removeActiveCell = _ref.removeActiveCell,
|
15
|
+
setContainerHasFocus = _ref.setContainerHasFocus;
|
16
|
+
// Reset everything when spreadsheet loses focus
|
17
|
+
useEffect(function () {
|
18
|
+
if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
19
|
+
setContainerHasFocus(false);
|
20
|
+
removeActiveCell();
|
21
|
+
activeKeys.current = [];
|
22
|
+
}
|
23
|
+
|
24
|
+
if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
25
|
+
setContainerHasFocus(true);
|
26
|
+
}
|
27
|
+
}, [focusedElement, removeActiveCell, activeKeys, blockClass, setContainerHasFocus]);
|
28
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2022, 2022
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import { useEffect } from 'react';
|
8
|
+
import { pkg } from '../../../settings'; // Click outside useEffect for spreadsheet
|
9
|
+
|
10
|
+
export var useSpreadsheetOutsideClick = function useSpreadsheetOutsideClick(_ref) {
|
11
|
+
var spreadsheetRef = _ref.spreadsheetRef,
|
12
|
+
_ref$blockClass = _ref.blockClass,
|
13
|
+
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
14
|
+
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
15
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
16
|
+
removeActiveCell = _ref.removeActiveCell,
|
17
|
+
removeCellSelections = _ref.removeCellSelections,
|
18
|
+
setContainerHasFocus = _ref.setContainerHasFocus,
|
19
|
+
activeKeys = _ref.activeKeys,
|
20
|
+
removeCellEditor = _ref.removeCellEditor;
|
21
|
+
useEffect(function () {
|
22
|
+
var handleOutsideClick = function handleOutsideClick(event) {
|
23
|
+
if (!spreadsheetRef.current || spreadsheetRef.current.contains(event.target) || event.target.classList.contains("".concat(blockClass, "__active-cell--highlight")) || event.target.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
|
27
|
+
setActiveCellCoordinates(null);
|
28
|
+
setSelectionAreas([]);
|
29
|
+
removeActiveCell();
|
30
|
+
removeCellSelections();
|
31
|
+
setContainerHasFocus(false);
|
32
|
+
removeCellEditor();
|
33
|
+
activeKeys.current = [];
|
34
|
+
};
|
35
|
+
|
36
|
+
document.addEventListener('click', handleOutsideClick);
|
37
|
+
return function () {
|
38
|
+
document.removeEventListener('click', handleOutsideClick);
|
39
|
+
};
|
40
|
+
}, [spreadsheetRef, removeActiveCell, removeCellSelections, activeKeys, blockClass, setActiveCellCoordinates, setContainerHasFocus, setSelectionAreas, removeCellEditor]);
|
41
|
+
};
|
package/es/components/DataSpreadsheet/{checkActiveHeaderCell.js → utils/checkActiveHeaderCell.js}
RENAMED
@@ -6,7 +6,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
6
6
|
* This source code is licensed under the Apache-2.0 license found in the
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
8
8
|
*/
|
9
|
-
import { deepCloneObject } from '
|
9
|
+
import { deepCloneObject } from '../../../global/js/utils/deepCloneObject'; // Determines if a row or column header cell should receive a highlight/active background color
|
10
10
|
// Check each object in selectionAreas and see if the headerIndex is between
|
11
11
|
// point1.row and point2.row, inclusive
|
12
12
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
import { px } from '@carbon/layout';
|
8
|
-
import { pkg } from '
|
8
|
+
import { pkg } from '../../../settings';
|
9
9
|
export var createActiveCellFn = function createActiveCellFn(_ref) {
|
10
10
|
var placementElement = _ref.placementElement,
|
11
11
|
coords = _ref.coords,
|
@@ -16,7 +16,9 @@ export var createActiveCellFn = function createActiveCellFn(_ref) {
|
|
16
16
|
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
17
17
|
onActiveCellChange = _ref.onActiveCellChange,
|
18
18
|
activeCellValue = _ref.activeCellValue,
|
19
|
-
|
19
|
+
activeCellRef = _ref.activeCellRef,
|
20
|
+
cellEditorRef = _ref.cellEditorRef,
|
21
|
+
defaultColumn = _ref.defaultColumn;
|
20
22
|
|
21
23
|
if (!coords) {
|
22
24
|
return;
|
@@ -24,23 +26,32 @@ export var createActiveCellFn = function createActiveCellFn(_ref) {
|
|
24
26
|
// to `.${blockClass}__header--container`, otherwise it should be appended to `.${blockClass}__listContainer` firstElementChild
|
25
27
|
|
26
28
|
|
29
|
+
var point1Element = document.querySelector("[data-row-index=\"".concat(coords.row, "\"][data-column-index=\"").concat(coords.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
|
30
|
+
|
31
|
+
var selectionAreaCellWidth = point1Element.offsetWidth;
|
32
|
+
var selectionAreaCellHeight = point1Element.offsetHeight;
|
27
33
|
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;
|
28
34
|
var relativePosition = {
|
29
|
-
top: placementElement.getBoundingClientRect().top - activeElementContainer.getBoundingClientRect().top,
|
30
|
-
|
35
|
+
top: placementElement ? placementElement.getBoundingClientRect().top - activeElementContainer.getBoundingClientRect().top : coords.row === 0 ? 0 : selectionAreaCellHeight * coords.row,
|
36
|
+
// calculate top value here if virtualized row is not in DOM
|
37
|
+
left: placementElement ? placementElement.getBoundingClientRect().left - activeElementContainer.getBoundingClientRect().left : coords.column === 0 ? 0 + (defaultColumn.rowHeaderWidth - 4) : selectionAreaCellWidth * coords.column + (defaultColumn.rowHeaderWidth - 4) // calculate left value here if virtualized row is not in DOM, accounting for row header cell width (including borders)
|
38
|
+
|
31
39
|
};
|
32
|
-
var activeCellButton =
|
33
|
-
activeCellButton.
|
34
|
-
activeCellButton.
|
35
|
-
activeCellButton.style.width = px(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetWidth);
|
36
|
-
activeCellButton.style.height = px(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetHeight);
|
40
|
+
var activeCellButton = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current;
|
41
|
+
activeCellButton.style.width = px(placementElement ? placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetWidth : selectionAreaCellWidth);
|
42
|
+
activeCellButton.style.height = px(placementElement ? placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetHeight : selectionAreaCellHeight);
|
37
43
|
activeCellButton.style.left = px(relativePosition.left);
|
38
44
|
activeCellButton.style.top = px(relativePosition.top);
|
45
|
+
activeCellButton.style.display = 'block';
|
39
46
|
activeCellButton.setAttribute('data-active-row-index', typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number' ? coords.row : 'header');
|
40
47
|
activeCellButton.setAttribute('data-active-column-index', typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' ? coords.column : 'header');
|
41
48
|
activeElementContainer.appendChild(activeCellButton);
|
42
49
|
activeCellButton.focus();
|
43
50
|
|
51
|
+
if (!addToHeader) {
|
52
|
+
activeElementContainer.appendChild(cellEditorRef.current);
|
53
|
+
}
|
54
|
+
|
44
55
|
if (typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' && typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number') {
|
45
56
|
onActiveCellChange === null || onActiveCellChange === void 0 ? void 0 : onActiveCellChange(activeCellValue);
|
46
57
|
}
|
@@ -5,17 +5,19 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
import { px } from '@carbon/layout';
|
8
|
-
import { deepCloneObject } from '
|
8
|
+
import { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
|
9
9
|
export var createCellSelectionArea = function createCellSelectionArea(_ref) {
|
10
10
|
var area = _ref.area,
|
11
11
|
blockClass = _ref.blockClass,
|
12
|
+
defaultColumn = _ref.defaultColumn,
|
12
13
|
selectionAreas = _ref.selectionAreas,
|
13
14
|
setSelectionAreas = _ref.setSelectionAreas;
|
14
15
|
var greatestRow = Math.max(area.point1.row, area.point2.row);
|
15
16
|
var greatestColumn = Math.max(area.point1.column, area.point2.column);
|
16
17
|
var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
|
17
18
|
var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
|
18
|
-
var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]"));
|
19
|
+
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
|
20
|
+
|
19
21
|
var selectionAreaCellWidth = point1Element.offsetWidth;
|
20
22
|
var selectionAreaCellHeight = point1Element.offsetHeight;
|
21
23
|
var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumn - lowestColumnIndex + 1);
|
@@ -23,8 +25,10 @@ export var createCellSelectionArea = function createCellSelectionArea(_ref) {
|
|
23
25
|
var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
24
26
|
var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
|
25
27
|
var relativePosition = {
|
26
|
-
top: placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top,
|
27
|
-
|
28
|
+
top: placementElement ? placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top : lowestRowIndex === 0 ? 0 : selectionAreaCellHeight * lowestRowIndex,
|
29
|
+
// calculate top value here if virtualized row is not in DOM
|
30
|
+
left: placementElement ? placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left : lowestColumnIndex === 0 ? 0 + (defaultColumn.rowHeaderWidth - 4) : selectionAreaCellWidth * lowestColumnIndex + (defaultColumn.rowHeaderWidth - 4) // calculate left value here if virtualized row is not in DOM, accounting for row header cell width (including borders)
|
31
|
+
|
28
32
|
};
|
29
33
|
var selectionAreaElement = document.querySelector("[data-matcher-id=\"".concat(area.matcher, "\"]")) || document.createElement('div');
|
30
34
|
selectionAreaElement.classList.add("".concat(blockClass, "__selection-area--element"));
|
@@ -4,6 +4,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
4
4
|
|
5
5
|
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) { _defineProperty(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; }
|
6
6
|
|
7
|
+
/**
|
8
|
+
* Copyright IBM Corp. 2022, 2022
|
9
|
+
*
|
10
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
12
|
+
*/
|
7
13
|
// cspell:disable
|
8
14
|
var pets = ['dog', 'cat', 'bird', 'lizard', 'frog', 'hamster', 'fish', 'rabbit', 'snake'];
|
9
15
|
var petNames = ['Bruno', 'Willow', 'Kona', 'Heidi', 'Rusty', 'Bonnie', 'Cash', 'Gucci', 'Brody', 'Emma', 'Loki', 'Angel', 'Astro', 'Sherman', 'Layla', 'Peanut', 'Grace', 'Mickey', 'Sasha', 'Finn', 'Tucker', 'Bear', 'Mocha', 'Roscoe']; // cspell:enable
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2022, 2022
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import uuidv4 from '../../../global/js/utils/uuidv4';
|
8
|
+
import { removeCellSelections } from './removeCellSelections';
|
9
|
+
export var handleHeaderCellSelection = function handleHeaderCellSelection(_ref) {
|
10
|
+
var type = _ref.type,
|
11
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
12
|
+
rows = _ref.rows,
|
13
|
+
columns = _ref.columns,
|
14
|
+
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
15
|
+
setCurrentMatcher = _ref.setCurrentMatcher,
|
16
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
17
|
+
spreadsheetRef = _ref.spreadsheetRef,
|
18
|
+
index = _ref.index,
|
19
|
+
isKeyboard = _ref.isKeyboard;
|
20
|
+
var rowValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row : index;
|
21
|
+
var columnValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column : index;
|
22
|
+
var point1 = {
|
23
|
+
row: type === 'column' ? 0 : rowValue,
|
24
|
+
column: type === 'column' ? columnValue : 0
|
25
|
+
};
|
26
|
+
var point2 = {
|
27
|
+
row: type === 'column' ? rows.length - 1 : rowValue,
|
28
|
+
// going to always be the last row
|
29
|
+
column: type === 'column' ? columnValue : columns.length - 1
|
30
|
+
};
|
31
|
+
var tempMatcher = uuidv4();
|
32
|
+
setActiveCellCoordinates({
|
33
|
+
row: type === 'column' ? 0 : rowValue,
|
34
|
+
column: type === 'column' ? columnValue : 0
|
35
|
+
});
|
36
|
+
setCurrentMatcher(tempMatcher);
|
37
|
+
removeCellSelections({
|
38
|
+
spreadsheetRef: spreadsheetRef
|
39
|
+
});
|
40
|
+
setSelectionAreas([{
|
41
|
+
point1: point1,
|
42
|
+
point2: point2,
|
43
|
+
areaCreated: false,
|
44
|
+
matcher: tempMatcher
|
45
|
+
}]);
|
46
|
+
};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2022, 2022
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
|
8
|
+
export var handleMultipleKeys = function handleMultipleKeys(_ref) {
|
9
|
+
var _selectionAreasClone$;
|
10
|
+
|
11
|
+
var activeKeys = _ref.activeKeys,
|
12
|
+
selectionAreas = _ref.selectionAreas,
|
13
|
+
currentMatcher = _ref.currentMatcher,
|
14
|
+
rows = _ref.rows,
|
15
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
16
|
+
columns = _ref.columns;
|
17
|
+
var activeKeyValues = activeKeys.current;
|
18
|
+
var selectionAreasClone = deepCloneObject(selectionAreas);
|
19
|
+
var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
|
20
|
+
return item.matcher === currentMatcher;
|
21
|
+
});
|
22
|
+
var pointToUpdate = (_selectionAreasClone$ = selectionAreasClone[indexOfCurrentArea]) !== null && _selectionAreasClone$ !== void 0 && _selectionAreasClone$.point2 ? selectionAreasClone[indexOfCurrentArea].point2 : selectionAreasClone[indexOfCurrentArea].point1; // Down + Shift
|
23
|
+
|
24
|
+
if (activeKeyValues.includes('Shift') && activeKeyValues.includes('ArrowDown')) {
|
25
|
+
if (rows.length - 1 === pointToUpdate.row) {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
|
29
|
+
var newPoint = {
|
30
|
+
row: pointToUpdate.row + 1,
|
31
|
+
column: pointToUpdate.column
|
32
|
+
};
|
33
|
+
selectionAreasClone[indexOfCurrentArea].point2 = newPoint;
|
34
|
+
selectionAreasClone[indexOfCurrentArea].areaCreated = false;
|
35
|
+
setSelectionAreas(selectionAreasClone);
|
36
|
+
} // Right + Shift
|
37
|
+
|
38
|
+
|
39
|
+
if (activeKeyValues.includes('Shift') && activeKeyValues.includes('ArrowRight')) {
|
40
|
+
if (columns.length - 1 === pointToUpdate.column) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
|
44
|
+
var _newPoint = {
|
45
|
+
row: pointToUpdate.row,
|
46
|
+
column: pointToUpdate.column + 1
|
47
|
+
};
|
48
|
+
selectionAreasClone[indexOfCurrentArea].point2 = _newPoint;
|
49
|
+
selectionAreasClone[indexOfCurrentArea].areaCreated = false;
|
50
|
+
setSelectionAreas(selectionAreasClone);
|
51
|
+
} // Up + Shift
|
52
|
+
|
53
|
+
|
54
|
+
if (activeKeyValues.includes('Shift') && activeKeyValues.includes('ArrowUp')) {
|
55
|
+
if (pointToUpdate.row === 0) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
var _newPoint2 = {
|
60
|
+
row: pointToUpdate.row - 1,
|
61
|
+
column: pointToUpdate.column
|
62
|
+
};
|
63
|
+
selectionAreasClone[indexOfCurrentArea].point2 = _newPoint2;
|
64
|
+
selectionAreasClone[indexOfCurrentArea].areaCreated = false;
|
65
|
+
setSelectionAreas(selectionAreasClone);
|
66
|
+
} // Left + Shift
|
67
|
+
|
68
|
+
|
69
|
+
if (activeKeyValues.includes('Shift') && activeKeyValues.includes('ArrowLeft')) {
|
70
|
+
if (pointToUpdate.column === 0) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
|
74
|
+
var _newPoint3 = {
|
75
|
+
row: pointToUpdate.row,
|
76
|
+
column: pointToUpdate.column - 1
|
77
|
+
};
|
78
|
+
selectionAreasClone[indexOfCurrentArea].point2 = _newPoint3;
|
79
|
+
selectionAreasClone[indexOfCurrentArea].areaCreated = false;
|
80
|
+
setSelectionAreas(selectionAreasClone);
|
81
|
+
}
|
82
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Copyright IBM Corp. 2022, 2022
|
5
|
+
*
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
8
|
+
*/
|
9
|
+
import { pkg } from '../../../settings'; // Removes the cell selection elements
|
10
|
+
|
11
|
+
export var removeCellSelections = function removeCellSelections(_ref) {
|
12
|
+
var matcher = _ref.matcher,
|
13
|
+
spreadsheetRef = _ref.spreadsheetRef,
|
14
|
+
_ref$blockClass = _ref.blockClass,
|
15
|
+
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass;
|
16
|
+
|
17
|
+
if (matcher && typeof matcher === 'string') {
|
18
|
+
var selectionToRemove = spreadsheetRef.current.querySelector("[data-matcher-id=\"".concat(matcher, "\"]"));
|
19
|
+
|
20
|
+
if (selectionToRemove) {
|
21
|
+
selectionToRemove.remove();
|
22
|
+
}
|
23
|
+
} else {
|
24
|
+
var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
|
25
|
+
|
26
|
+
_toConsumableArray(cellSelections).forEach(function (element) {
|
27
|
+
return element.remove();
|
28
|
+
});
|
29
|
+
}
|
30
|
+
};
|