@carbon/ibm-products 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +47 -0
- package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +1 -0
- package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +20 -0
- package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +1 -0
- package/css/components/Datagrid/styles/datagrid.css +264 -0
- package/css/components/Datagrid/styles/datagrid.css.map +1 -0
- package/css/components/Datagrid/styles/index.css +509 -0
- package/css/components/Datagrid/styles/index.css.map +1 -0
- package/css/components/Datagrid/styles/useActionsColumn.css +23 -0
- package/css/components/Datagrid/styles/useActionsColumn.css.map +1 -0
- package/css/components/Datagrid/styles/useColumnRightAlign.css +28 -0
- package/css/components/Datagrid/styles/useColumnRightAlign.css.map +1 -0
- package/css/components/Datagrid/styles/useNestedRows.css +15 -0
- package/css/components/Datagrid/styles/useNestedRows.css.map +1 -0
- package/css/components/Datagrid/styles/useNestedTable.css +25 -0
- package/css/components/Datagrid/styles/useNestedTable.css.map +1 -0
- package/css/components/Datagrid/styles/useSelectAllToggle.css +28 -0
- package/css/components/Datagrid/styles/useSelectAllToggle.css.map +1 -0
- package/css/components/Datagrid/styles/useSortableColumns.css +50 -0
- package/css/components/Datagrid/styles/useSortableColumns.css.map +1 -0
- package/css/components/Datagrid/styles/useStickyColumn.css +35 -0
- package/css/components/Datagrid/styles/useStickyColumn.css.map +1 -0
- package/css/index-full-carbon.css +570 -3
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +2 -2
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +3 -0
- 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 +570 -3
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +2 -2
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +570 -3
- package/css/index.css.map +1 -1
- package/css/index.min.css +2 -2
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +76 -24
- package/es/components/AddSelect/AddSelectFilter.js +129 -0
- package/es/components/AddSelect/add-select-utils.js +30 -0
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +77 -53
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +22 -9
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +15 -11
- package/es/components/DataSpreadsheet/hooks/index.js +10 -0
- package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +111 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +1 -3
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +80 -6
- package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
- package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
- package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
- package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
- package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
- package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
- package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
- package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
- package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
- package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
- package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
- package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
- package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
- package/es/components/Datagrid/Datagrid/index.js +8 -0
- package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
- package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
- package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
- package/es/components/Datagrid/common-column-ids.js +8 -0
- package/es/components/Datagrid/index.js +22 -0
- package/es/components/Datagrid/useActionsColumn.js +86 -0
- package/es/components/Datagrid/useColumnRightAlign.js +52 -0
- package/es/components/Datagrid/useCustomizeColumns.js +45 -0
- package/es/components/Datagrid/useDatagrid.js +44 -0
- package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
- package/es/components/Datagrid/useDisableSelectRows.js +84 -0
- package/es/components/Datagrid/useExpandedRow.js +52 -0
- package/es/components/Datagrid/useFlexResize.js +51 -0
- package/es/components/Datagrid/useFloatingScroll.js +88 -0
- package/es/components/Datagrid/useInfiniteScroll.js +54 -0
- package/es/components/Datagrid/useNestedRows.js +53 -0
- package/es/components/Datagrid/useOnRowClick.js +37 -0
- package/es/components/Datagrid/useParentDimensions.js +65 -0
- package/es/components/Datagrid/useResizeTable.js +40 -0
- package/es/components/Datagrid/useRowExpander.js +34 -0
- package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
- package/es/components/Datagrid/useRowRenderer.js +30 -0
- package/es/components/Datagrid/useRowSize.js +56 -0
- package/es/components/Datagrid/useSelectAllToggle.js +74 -0
- package/es/components/Datagrid/useSelectRows.js +107 -0
- package/es/components/Datagrid/useSkeletonRows.js +32 -0
- package/es/components/Datagrid/useSortableColumns.js +110 -0
- package/es/components/Datagrid/useStickyColumn.js +183 -0
- package/es/components/index.js +2 -1
- package/es/global/js/package-settings.js +2 -1
- package/lib/components/AddSelect/AddSelect.js +75 -22
- package/lib/components/AddSelect/AddSelectFilter.js +147 -0
- package/lib/components/AddSelect/add-select-utils.js +35 -2
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +79 -56
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +22 -15
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +15 -11
- package/lib/components/DataSpreadsheet/hooks/index.js +37 -0
- package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +123 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +1 -3
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +83 -7
- package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
- package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
- package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
- package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
- package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
- package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
- package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
- package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
- package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
- package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
- package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
- package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
- package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
- package/lib/components/Datagrid/Datagrid/index.js +15 -0
- package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
- package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
- package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
- package/lib/components/Datagrid/common-column-ids.js +16 -0
- package/lib/components/Datagrid/index.js +127 -0
- package/lib/components/Datagrid/useActionsColumn.js +94 -0
- package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
- package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
- package/lib/components/Datagrid/useDatagrid.js +58 -0
- package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
- package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
- package/lib/components/Datagrid/useExpandedRow.js +58 -0
- package/lib/components/Datagrid/useFlexResize.js +61 -0
- package/lib/components/Datagrid/useFloatingScroll.js +101 -0
- package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
- package/lib/components/Datagrid/useNestedRows.js +65 -0
- package/lib/components/Datagrid/useOnRowClick.js +45 -0
- package/lib/components/Datagrid/useParentDimensions.js +75 -0
- package/lib/components/Datagrid/useResizeTable.js +48 -0
- package/lib/components/Datagrid/useRowExpander.js +45 -0
- package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
- package/lib/components/Datagrid/useRowRenderer.js +40 -0
- package/lib/components/Datagrid/useRowSize.js +67 -0
- package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
- package/lib/components/Datagrid/useSelectRows.js +119 -0
- package/lib/components/Datagrid/useSkeletonRows.js +42 -0
- package/lib/components/Datagrid/useSortableColumns.js +117 -0
- package/lib/components/Datagrid/useStickyColumn.js +190 -0
- package/lib/components/index.js +9 -1
- package/lib/global/js/package-settings.js +2 -1
- package/package.json +6 -2
- package/scss/components/AddSelect/_add-select.scss +37 -0
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +13 -3
- package/scss/components/Datagrid/_datagrid.scss +66 -0
- package/scss/components/Datagrid/_index.scss +8 -0
- package/scss/components/Datagrid/_storybook-styles.scss +26 -0
- package/scss/components/Datagrid/styles/_variables.scss +9 -0
- package/scss/components/Datagrid/styles/addons/CustomizeColumnsModal.scss +48 -0
- package/scss/components/Datagrid/styles/addons/RowSizeDropdown.scss +23 -0
- package/scss/components/Datagrid/styles/datagrid.scss +318 -0
- package/scss/components/Datagrid/styles/index.scss +17 -0
- package/scss/components/Datagrid/styles/useActionsColumn.scss +24 -0
- package/scss/components/Datagrid/styles/useColumnRightAlign.scss +29 -0
- package/scss/components/Datagrid/styles/useNestedRows.scss +17 -0
- package/scss/components/Datagrid/styles/useNestedTable.scss +28 -0
- package/scss/components/Datagrid/styles/useSelectAllToggle.scss +28 -0
- package/scss/components/Datagrid/styles/useSortableColumns.scss +55 -0
- package/scss/components/Datagrid/styles/useStickyColumn.scss +38 -0
- package/scss/components/Tearsheet/_tearsheet.scss +4 -0
- package/scss/components/_index.scss +1 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
|
4
|
+
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; }
|
5
|
+
|
6
|
+
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; }
|
7
|
+
|
8
|
+
//
|
9
|
+
// Copyright IBM Corp. 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
|
+
import React, { useState } from 'react';
|
15
|
+
import { Button, ButtonSet, Dropdown, TextInput } from 'carbon-components-react';
|
16
|
+
import PropTypes from 'prop-types';
|
17
|
+
import { Filter16 } from '@carbon/icons-react';
|
18
|
+
import { pkg } from '../../settings';
|
19
|
+
var componentName = 'AddSelectFilter';
|
20
|
+
export var AddSelectFilter = function AddSelectFilter(_ref) {
|
21
|
+
var filterOpts = _ref.filterOpts,
|
22
|
+
handleFilter = _ref.handleFilter,
|
23
|
+
handleSearch = _ref.handleSearch,
|
24
|
+
iconDescription = _ref.iconDescription,
|
25
|
+
inputPlaceholder = _ref.inputPlaceholder,
|
26
|
+
multi = _ref.multi,
|
27
|
+
placeholder = _ref.placeholder,
|
28
|
+
primaryButtonText = _ref.primaryButtonText,
|
29
|
+
searchTerm = _ref.searchTerm,
|
30
|
+
secondaryButtonText = _ref.secondaryButtonText,
|
31
|
+
textInputLabel = _ref.textInputLabel;
|
32
|
+
|
33
|
+
var _useState = useState({}),
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
35
|
+
filters = _useState2[0],
|
36
|
+
setFilters = _useState2[1];
|
37
|
+
|
38
|
+
var _useState3 = useState(false),
|
39
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
40
|
+
open = _useState4[0],
|
41
|
+
setOpen = _useState4[1];
|
42
|
+
|
43
|
+
var blockClass = "".concat(pkg.prefix, "--add-select__global-filter");
|
44
|
+
|
45
|
+
var searchHandler = function searchHandler(e) {
|
46
|
+
handleSearch(e.target.value);
|
47
|
+
};
|
48
|
+
|
49
|
+
var onchangeHandler = function onchangeHandler(_ref2, id) {
|
50
|
+
var selectedItem = _ref2.selectedItem;
|
51
|
+
setFilters(_objectSpread(_objectSpread({}, filters), {}, _defineProperty({}, id, selectedItem)));
|
52
|
+
};
|
53
|
+
|
54
|
+
var applyFilters = function applyFilters() {
|
55
|
+
handleFilter(filters);
|
56
|
+
};
|
57
|
+
|
58
|
+
var resetFilters = function resetFilters() {
|
59
|
+
setFilters({});
|
60
|
+
};
|
61
|
+
|
62
|
+
var getSelectedItem = function getSelectedItem(id) {
|
63
|
+
return filters[id] || '';
|
64
|
+
};
|
65
|
+
|
66
|
+
var showFilter = multi && (filterOpts === null || filterOpts === void 0 ? void 0 : filterOpts.length) > 0;
|
67
|
+
return /*#__PURE__*/React.createElement("div", {
|
68
|
+
className: "".concat(blockClass, "-search")
|
69
|
+
}, /*#__PURE__*/React.createElement(TextInput, {
|
70
|
+
id: "temp-id",
|
71
|
+
labelText: textInputLabel,
|
72
|
+
placeholder: inputPlaceholder,
|
73
|
+
value: searchTerm,
|
74
|
+
onChange: searchHandler
|
75
|
+
}), showFilter && /*#__PURE__*/React.createElement(Button, {
|
76
|
+
renderIcon: Filter16,
|
77
|
+
hasIconOnly: true,
|
78
|
+
kind: "ghost",
|
79
|
+
onClick: function onClick() {
|
80
|
+
return setOpen(!open);
|
81
|
+
},
|
82
|
+
iconDescription: iconDescription,
|
83
|
+
className: "".concat(blockClass, "-toggle"),
|
84
|
+
size: "md"
|
85
|
+
}), open && /*#__PURE__*/React.createElement("div", {
|
86
|
+
className: "".concat(blockClass)
|
87
|
+
}, /*#__PURE__*/React.createElement("div", {
|
88
|
+
className: "".concat(blockClass, "-content")
|
89
|
+
}, /*#__PURE__*/React.createElement("p", null, "Filters"), /*#__PURE__*/React.createElement("div", {
|
90
|
+
className: "".concat(blockClass, "-opts")
|
91
|
+
}, filterOpts.map(function (filterOpts) {
|
92
|
+
return /*#__PURE__*/React.createElement(Dropdown, {
|
93
|
+
id: filterOpts.id,
|
94
|
+
key: filterOpts.id,
|
95
|
+
titleText: filterOpts.label,
|
96
|
+
items: filterOpts.opts,
|
97
|
+
light: true,
|
98
|
+
onChange: function onChange(value) {
|
99
|
+
return onchangeHandler(value, filterOpts.id);
|
100
|
+
},
|
101
|
+
selectedItem: getSelectedItem(filterOpts.id),
|
102
|
+
label: placeholder
|
103
|
+
});
|
104
|
+
}))), /*#__PURE__*/React.createElement(ButtonSet, {
|
105
|
+
className: "".concat(blockClass, "-button-set")
|
106
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
107
|
+
kind: "secondary",
|
108
|
+
onClick: resetFilters,
|
109
|
+
className: "".concat(blockClass, "-button")
|
110
|
+
}, secondaryButtonText), /*#__PURE__*/React.createElement(Button, {
|
111
|
+
kind: "primary",
|
112
|
+
onClick: applyFilters,
|
113
|
+
className: "".concat(blockClass, "-button")
|
114
|
+
}, primaryButtonText))));
|
115
|
+
};
|
116
|
+
AddSelectFilter.propTypes = {
|
117
|
+
filterOpts: PropTypes.array,
|
118
|
+
handleFilter: PropTypes.func,
|
119
|
+
handleSearch: PropTypes.func,
|
120
|
+
iconDescription: PropTypes.string,
|
121
|
+
inputPlaceholder: PropTypes.string,
|
122
|
+
multi: PropTypes.bool,
|
123
|
+
placeholder: PropTypes.string,
|
124
|
+
primaryButtonText: PropTypes.string,
|
125
|
+
searchTerm: PropTypes.string,
|
126
|
+
secondaryButtonText: PropTypes.string,
|
127
|
+
textInputLabel: PropTypes.string
|
128
|
+
};
|
129
|
+
AddSelectFilter.displayName = componentName;
|
@@ -61,4 +61,34 @@ export var flatten = function flatten(entries) {
|
|
61
61
|
|
62
62
|
return prev.concat(item).concat(children ? flatten(children.entries) : []);
|
63
63
|
}, []);
|
64
|
+
};
|
65
|
+
/**
|
66
|
+
* takes in a global filters array and a flat list of items
|
67
|
+
* it then searches through the items and finds any with the matching filter properties
|
68
|
+
* and adds those values to the array
|
69
|
+
* globalFilters looks like [{ id: someProperty }]
|
70
|
+
* the returned array would look like [{ id: someProperty, opts: [value, value]}]
|
71
|
+
* @param {Array} globalFilters - list of filter properties
|
72
|
+
* @param {Array} items - items to search through
|
73
|
+
* @returns an array of filter values
|
74
|
+
*/
|
75
|
+
|
76
|
+
export var getGlobalFilterValues = function getGlobalFilterValues(globalFilters, items) {
|
77
|
+
var filterOpts = globalFilters.reduce(function (prevFilter, curFilter) {
|
78
|
+
var filterId = curFilter.id;
|
79
|
+
var opts = items.reduce(function (prevItem, curItem) {
|
80
|
+
var value = curItem[filterId];
|
81
|
+
|
82
|
+
if (value && !prevItem.includes(value)) {
|
83
|
+
prevItem.push(value);
|
84
|
+
}
|
85
|
+
|
86
|
+
return prevItem;
|
87
|
+
}, []);
|
88
|
+
prevFilter.push(_objectSpread({
|
89
|
+
opts: opts
|
90
|
+
}, curFilter));
|
91
|
+
return prevFilter;
|
92
|
+
}, []);
|
93
|
+
return filterOpts;
|
64
94
|
};
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
3
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
4
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
5
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
@@ -30,12 +29,10 @@ import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
|
30
29
|
import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
|
31
30
|
import { useActiveElement, usePreviousValue } from '../../global/js/hooks';
|
32
31
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
33
|
-
import { useResetSpreadsheetFocus } from './hooks
|
34
|
-
import { useSpreadsheetOutsideClick } from './hooks/useSpreadsheetOutsideClick';
|
35
|
-
import { useMoveActiveCell } from './hooks/useMoveActiveCell';
|
32
|
+
import { useResetSpreadsheetFocus, useSpreadsheetOutsideClick, useMoveActiveCell, useMultipleKeyTracking } from './hooks';
|
36
33
|
import { createActiveCellFn } from './utils/createActiveCellFn';
|
37
34
|
import { getCellSize } from './utils/getCellSize';
|
38
|
-
import { handleMultipleKeys } from './utils/handleMultipleKeys';
|
35
|
+
import { handleMultipleKeys, includesShift } from './utils/handleMultipleKeys';
|
39
36
|
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
40
37
|
import { removeCellSelections } from './utils/removeCellSelections'; // cspell:words rowcount colcount
|
41
38
|
// The block part of our conventional BEM class names (blockClass__E--M).
|
@@ -75,6 +72,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
75
72
|
onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
|
76
73
|
rest = _objectWithoutProperties(_ref, _excluded);
|
77
74
|
|
75
|
+
var multiKeyTrackingRef = useRef();
|
78
76
|
var localRef = useRef();
|
79
77
|
var spreadsheetRef = ref || localRef;
|
80
78
|
var focusedElement = useActiveElement();
|
@@ -120,7 +118,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
120
118
|
setCellEditorValue = _useState16[1];
|
121
119
|
|
122
120
|
var previousState = usePreviousValue({
|
123
|
-
activeCellCoordinates: activeCellCoordinates
|
121
|
+
activeCellCoordinates: activeCellCoordinates,
|
122
|
+
isEditing: isEditing
|
124
123
|
});
|
125
124
|
var cellSizeValue = getCellSize(cellSize);
|
126
125
|
var cellEditorRef = useRef();
|
@@ -130,7 +129,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
130
129
|
activeCellContent = _useState18[0],
|
131
130
|
setActiveCellContent = _useState18[1];
|
132
131
|
|
133
|
-
var activeKeys = useRef([]);
|
134
132
|
var activeCellRef = useRef();
|
135
133
|
var cellEditorRulerRef = useRef();
|
136
134
|
var defaultColumn = useMemo(function () {
|
@@ -140,6 +138,14 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
140
138
|
rowHeight: cellSizeValue
|
141
139
|
};
|
142
140
|
}, [cellSizeValue]);
|
141
|
+
|
142
|
+
var _useMultipleKeyTracki = useMultipleKeyTracking({
|
143
|
+
ref: multiKeyTrackingRef,
|
144
|
+
containerHasFocus: containerHasFocus,
|
145
|
+
isEditing: isEditing
|
146
|
+
}),
|
147
|
+
keysPressedList = _useMultipleKeyTracki.keysPressedList;
|
148
|
+
|
143
149
|
var scrollBarSize = useMemo(function () {
|
144
150
|
return getScrollbarWidth();
|
145
151
|
}, []);
|
@@ -229,7 +235,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
229
235
|
}
|
230
236
|
}, [spreadsheetRef, rows, onActiveCellChange, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, defaultColumn]);
|
231
237
|
useResetSpreadsheetFocus({
|
232
|
-
activeKeys: activeKeys,
|
233
238
|
focusedElement: focusedElement,
|
234
239
|
removeActiveCell: removeActiveCell,
|
235
240
|
setContainerHasFocus: setContainerHasFocus
|
@@ -241,7 +246,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
241
246
|
removeActiveCell: removeActiveCell,
|
242
247
|
removeCellSelections: removeCellSelections,
|
243
248
|
setContainerHasFocus: setContainerHasFocus,
|
244
|
-
activeKeys: activeKeys,
|
245
249
|
removeCellEditor: removeCellEditor
|
246
250
|
});
|
247
251
|
useMoveActiveCell({
|
@@ -281,10 +285,28 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
281
285
|
setCurrentMatcher(tempMatcher);
|
282
286
|
}
|
283
287
|
}, []);
|
288
|
+
var handleHomeEndKey = useCallback(function (_ref4) {
|
289
|
+
var type = _ref4.type;
|
290
|
+
|
291
|
+
var coordinatesClone = _objectSpread({}, activeCellCoordinates);
|
292
|
+
|
293
|
+
updateActiveCellCoordinates({
|
294
|
+
coords: coordinatesClone,
|
295
|
+
updatedValue: {
|
296
|
+
column: type === 'home' ? 0 : columns.length - 1
|
297
|
+
}
|
298
|
+
});
|
299
|
+
removeCellSelections({
|
300
|
+
spreadsheetRef: spreadsheetRef
|
301
|
+
});
|
302
|
+
}, [activeCellCoordinates, updateActiveCellCoordinates, spreadsheetRef, columns.length]);
|
284
303
|
var handleKeyPress = useCallback(function (event) {
|
285
|
-
var
|
304
|
+
var key = event.key;
|
305
|
+
|
306
|
+
if (isEditing) {
|
307
|
+
return;
|
308
|
+
} // Command keys need to be returned as there is default browser behavior with these keys
|
286
309
|
|
287
|
-
var key = event.key; // Command keys need to be returned as there is default browser behavior with these keys
|
288
310
|
|
289
311
|
if (key === 'Meta' || key === 'Control') {
|
290
312
|
return;
|
@@ -301,29 +323,20 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
301
323
|
|
302
324
|
|
303
325
|
if (['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1) {
|
304
|
-
if (
|
305
|
-
return;
|
306
|
-
}
|
307
|
-
|
308
|
-
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
|
326
|
+
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && keysPressedList.length < 2 && !includesShift(keysPressedList)) {
|
309
327
|
setSelectionAreas([]);
|
310
328
|
setSelectionAreaData([]);
|
311
329
|
removeCellSelections({
|
312
330
|
spreadsheetRef: spreadsheetRef
|
313
331
|
});
|
314
332
|
}
|
315
|
-
} // Update list of activeKeys
|
316
|
-
|
317
|
-
|
318
|
-
if (!((_activeKeys$current = activeKeys.current) !== null && _activeKeys$current !== void 0 && _activeKeys$current.includes(key))) {
|
319
|
-
var activeClone = _toConsumableArray(activeKeys.current);
|
320
|
-
|
321
|
-
activeKeys.current = [].concat(_toConsumableArray(activeClone), [key]);
|
322
333
|
}
|
323
334
|
|
324
|
-
if (
|
335
|
+
if (!isEditing && (keysPressedList === null || keysPressedList === void 0 ? void 0 : keysPressedList.length) > 1) {
|
325
336
|
handleMultipleKeys({
|
326
|
-
|
337
|
+
activeCellCoordinates: activeCellCoordinates,
|
338
|
+
event: event,
|
339
|
+
keysPressedList: keysPressedList,
|
327
340
|
selectionAreas: selectionAreas,
|
328
341
|
currentMatcher: currentMatcher,
|
329
342
|
rows: rows,
|
@@ -334,9 +347,26 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
334
347
|
// if one of the activeCellCoordinates is in a header position
|
335
348
|
|
336
349
|
|
337
|
-
if (!
|
350
|
+
if (keysPressedList.length < 2 && !includesShift(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
|
338
351
|
switch (key) {
|
352
|
+
// HOME
|
353
|
+
case 'Home':
|
354
|
+
{
|
355
|
+
handleHomeEndKey({
|
356
|
+
type: 'home'
|
357
|
+
});
|
358
|
+
break;
|
359
|
+
}
|
360
|
+
|
361
|
+
case 'End':
|
362
|
+
{
|
363
|
+
handleHomeEndKey({
|
364
|
+
type: 'end'
|
365
|
+
});
|
366
|
+
break;
|
367
|
+
}
|
339
368
|
// Tab
|
369
|
+
|
340
370
|
case 'Tab':
|
341
371
|
{
|
342
372
|
setSelectionAreas([]);
|
@@ -485,7 +515,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
485
515
|
}
|
486
516
|
}
|
487
517
|
}
|
488
|
-
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas]);
|
518
|
+
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList]);
|
489
519
|
|
490
520
|
var startEditMode = function startEditMode() {
|
491
521
|
setIsEditing(true);
|
@@ -493,7 +523,16 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
493
523
|
var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
494
524
|
setCellEditorValue(activeCellValue);
|
495
525
|
cellEditorRulerRef.current.textContent = activeCellValue;
|
496
|
-
};
|
526
|
+
}; // Sets the initial placement of the cell editor cursor at the end of the text area
|
527
|
+
// this is not done for us by default in Safari
|
528
|
+
|
529
|
+
|
530
|
+
useEffect(function () {
|
531
|
+
if (isEditing && !(previousState !== null && previousState !== void 0 && previousState.isEditing)) {
|
532
|
+
cellEditorRef.current.setSelectionRange(cellEditorRulerRef.current.textContent.length, cellEditorRulerRef.current.textContent.length);
|
533
|
+
cellEditorRef.current.focus();
|
534
|
+
}
|
535
|
+
}, [isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing]);
|
497
536
|
|
498
537
|
var handleActiveCellClick = function handleActiveCellClick() {
|
499
538
|
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
@@ -524,10 +563,10 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
524
563
|
}
|
525
564
|
};
|
526
565
|
|
527
|
-
var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(
|
528
|
-
var isKeyboard =
|
529
|
-
|
530
|
-
index =
|
566
|
+
var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref5) {
|
567
|
+
var isKeyboard = _ref5.isKeyboard,
|
568
|
+
_ref5$index = _ref5.index,
|
569
|
+
index = _ref5$index === void 0 ? null : _ref5$index;
|
531
570
|
var handleHeaderCellProps = {
|
532
571
|
activeCellCoordinates: activeCellCoordinates,
|
533
572
|
rows: rows,
|
@@ -560,8 +599,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
560
599
|
startEditMode();
|
561
600
|
};
|
562
601
|
|
563
|
-
var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(
|
564
|
-
var type =
|
602
|
+
var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref6) {
|
603
|
+
var type = _ref6.type;
|
565
604
|
|
566
605
|
var submitEditChanges = function submitEditChanges() {
|
567
606
|
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
|
@@ -670,22 +709,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
670
709
|
activeCellRef.current.focus();
|
671
710
|
}
|
672
711
|
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
|
673
|
-
|
674
|
-
var handleKeyUp = function handleKeyUp(event) {
|
675
|
-
var _activeKeys$current3;
|
676
|
-
|
677
|
-
var key = event.key; // Remove key from active keys array on key up
|
678
|
-
|
679
|
-
if ((_activeKeys$current3 = activeKeys.current) !== null && _activeKeys$current3 !== void 0 && _activeKeys$current3.includes(key)) {
|
680
|
-
var activeKeysClone = _toConsumableArray(activeKeys.current);
|
681
|
-
|
682
|
-
var filteredKeysClone = activeKeysClone.filter(function (item) {
|
683
|
-
return item !== key;
|
684
|
-
});
|
685
|
-
activeKeys.current = filteredKeysClone;
|
686
|
-
}
|
687
|
-
};
|
688
|
-
|
689
712
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
|
690
713
|
className: cx(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
|
691
714
|
ref: spreadsheetRef,
|
@@ -694,11 +717,12 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
694
717
|
"aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
|
695
718
|
"aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
|
696
719
|
onKeyDown: handleKeyPress,
|
697
|
-
onKeyUp: handleKeyUp,
|
698
720
|
onFocus: function onFocus() {
|
699
721
|
return setContainerHasFocus(true);
|
700
722
|
}
|
701
|
-
}), /*#__PURE__*/React.createElement(
|
723
|
+
}), /*#__PURE__*/React.createElement("div", {
|
724
|
+
ref: multiKeyTrackingRef
|
725
|
+
}, /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
|
702
726
|
ref: spreadsheetRef,
|
703
727
|
activeCellCoordinates: activeCellCoordinates,
|
704
728
|
cellSize: cellSize,
|
@@ -761,7 +785,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
761
785
|
"aria-hidden": true,
|
762
786
|
ref: cellEditorRulerRef,
|
763
787
|
className: "".concat(blockClass, "__cell-editor-ruler")
|
764
|
-
}));
|
788
|
+
})));
|
765
789
|
}); // Return a placeholder if not released and not enabled by feature flag
|
766
790
|
|
767
791
|
DataSpreadsheet = pkg.checkComponentEnabled(DataSpreadsheet, componentName); // The display name of the component, used by React. Note that displayName
|
@@ -2,6 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
3
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
4
4
|
|
5
|
+
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; }
|
6
|
+
|
7
|
+
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; }
|
8
|
+
|
5
9
|
/**
|
6
10
|
* Copyright IBM Corp. 2022, 2022
|
7
11
|
*
|
@@ -323,8 +327,11 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
323
327
|
style: style
|
324
328
|
}), {
|
325
329
|
className: cx("".concat(blockClass, "__tr")),
|
326
|
-
"data-row-index": index
|
327
|
-
|
330
|
+
"data-row-index": index,
|
331
|
+
"aria-rowindex": index
|
332
|
+
}), /*#__PURE__*/React.createElement("div", {
|
333
|
+
role: "rowheader"
|
334
|
+
}, /*#__PURE__*/React.createElement("button", {
|
328
335
|
tabIndex: -1,
|
329
336
|
"data-row-index": index,
|
330
337
|
"data-column-index": "header",
|
@@ -332,21 +339,27 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
332
339
|
onClick: handleRowHeaderClick(index),
|
333
340
|
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'))),
|
334
341
|
style: {
|
335
|
-
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
342
|
+
width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4
|
336
343
|
}
|
337
|
-
}, index + 1), row.cells.map(function (cell, index) {
|
338
|
-
return /*#__PURE__*/React.createElement("
|
344
|
+
}, index + 1)), row.cells.map(function (cell, index) {
|
345
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
346
|
+
key: "cell_".concat(index),
|
347
|
+
"aria-colindex": index
|
348
|
+
}, cell.getCellProps(), {
|
349
|
+
role: "gridcell",
|
350
|
+
style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
|
351
|
+
display: 'grid'
|
352
|
+
})
|
353
|
+
}), /*#__PURE__*/React.createElement("button", {
|
339
354
|
tabIndex: -1,
|
340
355
|
"data-row-index": cell.row.index,
|
341
|
-
"data-column-index": index
|
342
|
-
}, cell.getCellProps(), {
|
356
|
+
"data-column-index": index,
|
343
357
|
className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
|
344
|
-
key: "cell_".concat(index),
|
345
358
|
onMouseDown: handleBodyCellClick(cell, index),
|
346
359
|
onMouseOver: handleBodyCellHover(cell, index),
|
347
360
|
onFocus: function onFocus() {},
|
348
361
|
type: "button"
|
349
|
-
}
|
362
|
+
}, cell.render('Cell')));
|
350
363
|
}));
|
351
364
|
}
|
352
365
|
}, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
|
@@ -81,30 +81,34 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
81
81
|
width: px(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
|
82
82
|
}),
|
83
83
|
className: "".concat(blockClass, "__tr")
|
84
|
-
}), /*#__PURE__*/React.createElement("
|
84
|
+
}), /*#__PURE__*/React.createElement("div", {
|
85
|
+
role: "columnheader",
|
86
|
+
style: {
|
87
|
+
width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4,
|
88
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
89
|
+
}
|
90
|
+
}, /*#__PURE__*/React.createElement("button", {
|
85
91
|
"data-row-index": "header",
|
86
92
|
"data-column-index": "header",
|
87
93
|
type: "button",
|
88
94
|
tabIndex: -1,
|
89
|
-
className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".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'))
|
90
|
-
|
91
|
-
|
92
|
-
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
93
|
-
}
|
94
|
-
}, "\xA0"), headerGroup.headers.map(function (column, index) {
|
95
|
-
return /*#__PURE__*/React.createElement("button", _extends({
|
95
|
+
className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), _defineProperty({}, "".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'))
|
96
|
+
}, "\xA0")), headerGroup.headers.map(function (column, index) {
|
97
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
96
98
|
key: "column_".concat(index),
|
99
|
+
role: "columnheader",
|
100
|
+
className: "".concat(blockClass, "__columnheader")
|
101
|
+
}, column.getHeaderProps()), /*#__PURE__*/React.createElement("button", {
|
97
102
|
"data-row-index": "header",
|
98
103
|
"data-column-index": index,
|
99
104
|
tabIndex: -1,
|
100
105
|
onClick: handleColumnHeaderClick(index),
|
101
106
|
style: {
|
102
107
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
103
|
-
}
|
104
|
-
}, column.getHeaderProps(), {
|
108
|
+
},
|
105
109
|
className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || checkActiveHeaderCell(index, selectionAreas, 'column'))),
|
106
110
|
type: "button"
|
107
|
-
}
|
111
|
+
}, column.render('Header')));
|
108
112
|
}));
|
109
113
|
}));
|
110
114
|
});
|
@@ -0,0 +1,10 @@
|
|
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
|
+
export { useMoveActiveCell } from './useMoveActiveCell';
|
8
|
+
export { useMultipleKeyTracking } from './useMultipleKeyTracking';
|
9
|
+
export { useResetSpreadsheetFocus } from './useResetSpreadsheetFocus';
|
10
|
+
export { useSpreadsheetOutsideClick } from './useSpreadsheetOutsideClick';
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2022, 2022
|
6
|
+
*
|
7
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
import { useEffect, useState } from 'react';
|
11
|
+
import { usePreviousValue } from '../../../global/js/hooks';
|
12
|
+
|
13
|
+
var hasFocus = function hasFocus() {
|
14
|
+
return typeof document !== 'undefined' && document.hasFocus();
|
15
|
+
};
|
16
|
+
|
17
|
+
export var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
18
|
+
var ref = _ref.ref,
|
19
|
+
containerHasFocus = _ref.containerHasFocus,
|
20
|
+
isEditing = _ref.isEditing;
|
21
|
+
|
22
|
+
var _useState = useState(hasFocus),
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
24
|
+
windowFocused = _useState2[0],
|
25
|
+
setWindowFocused = _useState2[1];
|
26
|
+
|
27
|
+
var _useState3 = useState([]),
|
28
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
29
|
+
keysPressedList = _useState4[0],
|
30
|
+
setKeysPressedList = _useState4[1];
|
31
|
+
|
32
|
+
var previousState = usePreviousValue({
|
33
|
+
isEditing: isEditing,
|
34
|
+
windowFocused: windowFocused
|
35
|
+
}); // useEffect to check for window focus, if window loses focus
|
36
|
+
// we need to clear out the keysPressedList
|
37
|
+
|
38
|
+
useEffect(function () {
|
39
|
+
setWindowFocused(hasFocus());
|
40
|
+
|
41
|
+
var onWindowFocus = function onWindowFocus() {
|
42
|
+
return setWindowFocused(true);
|
43
|
+
};
|
44
|
+
|
45
|
+
var onWindowBlur = function onWindowBlur() {
|
46
|
+
return setWindowFocused(false);
|
47
|
+
};
|
48
|
+
|
49
|
+
window.addEventListener('focus', onWindowFocus);
|
50
|
+
window.addEventListener('blur', onWindowBlur);
|
51
|
+
return function () {
|
52
|
+
window.removeEventListener('focus', onWindowFocus);
|
53
|
+
window.removeEventListener('blur', onWindowBlur);
|
54
|
+
};
|
55
|
+
}, []);
|
56
|
+
useEffect(function () {
|
57
|
+
if (containerHasFocus && !isEditing) {
|
58
|
+
ref.current.onkeydown = ref.current.onkeyup = function (event) {
|
59
|
+
// If keydown, we will add the new key to the keysPressedList array
|
60
|
+
if (event.type === 'keydown') {
|
61
|
+
// Prevent multiple keys of the same type being added to our keysPressedList array
|
62
|
+
if (keysPressedList.includes(event.code)) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
|
66
|
+
var tempKeys = _toConsumableArray(keysPressedList);
|
67
|
+
|
68
|
+
tempKeys.push(event.code);
|
69
|
+
setKeysPressedList(_toConsumableArray(new Set(tempKeys)));
|
70
|
+
} // If keyup, we will remove the key from the keysPressedList array
|
71
|
+
|
72
|
+
|
73
|
+
if (event.type === 'keyup') {
|
74
|
+
var _tempKeys = _toConsumableArray(keysPressedList);
|
75
|
+
|
76
|
+
var filteredClone = _tempKeys.filter(function (item) {
|
77
|
+
return item !== event.code;
|
78
|
+
}); // Keyup events are lost on all other keys if a Meta key is used
|
79
|
+
// so to work around this behavior, we empty out all other keys
|
80
|
+
// from the keysPressedList array if we detect a Meta keyup event
|
81
|
+
|
82
|
+
|
83
|
+
if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
|
84
|
+
return setKeysPressedList([]);
|
85
|
+
}
|
86
|
+
|
87
|
+
setKeysPressedList(_toConsumableArray(new Set(filteredClone)));
|
88
|
+
}
|
89
|
+
};
|
90
|
+
}
|
91
|
+
|
92
|
+
if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
|
93
|
+
setKeysPressedList([]);
|
94
|
+
} // Remove handlers if the spreadsheet container loses focus
|
95
|
+
// or is currently in edit mode
|
96
|
+
|
97
|
+
|
98
|
+
if (!containerHasFocus || isEditing) {
|
99
|
+
ref.current.onkeydown = undefined;
|
100
|
+
ref.current.onkeyup = undefined;
|
101
|
+
|
102
|
+
if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
|
103
|
+
setKeysPressedList([]);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused]);
|
107
|
+
return {
|
108
|
+
keysPressedList: keysPressedList,
|
109
|
+
windowFocused: windowFocused
|
110
|
+
};
|
111
|
+
};
|