@carbon/ibm-products 1.12.0 → 1.15.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 +653 -21
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +6 -6
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +21 -10
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +2 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +653 -21
- 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 +653 -21
- package/css/index.css.map +1 -1
- package/css/index.min.css +6 -6
- package/css/index.min.css.map +1 -1
- package/es/components/ActionBar/ActionBar.js +3 -1
- package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/es/components/AddSelect/AddSelect.js +98 -40
- package/es/components/AddSelect/AddSelectFilter.js +129 -0
- package/es/components/AddSelect/AddSelectList.js +27 -1
- package/es/components/AddSelect/AddSelectSidebar.js +15 -5
- package/es/components/AddSelect/add-select-utils.js +30 -0
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +269 -142
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +122 -39
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +46 -17
- package/es/components/DataSpreadsheet/hooks/index.js +11 -0
- package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +139 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -0
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -6
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
- package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
- package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
- package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
- package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +42 -8
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +225 -13
- package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
- 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/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
- package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
- package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
- package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
- package/es/components/PageHeader/PageHeader.js +3 -1
- package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
- package/es/components/TagSet/TagSet.js +22 -6
- package/es/components/Tearsheet/TearsheetShell.js +34 -10
- package/es/components/UserProfileImage/UserProfileImage.js +37 -9
- package/es/components/index.js +2 -1
- package/es/global/js/package-settings.js +4 -2
- package/lib/components/ActionBar/ActionBar.js +3 -1
- package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/lib/components/AddSelect/AddSelect.js +97 -38
- package/lib/components/AddSelect/AddSelectFilter.js +147 -0
- package/lib/components/AddSelect/AddSelectList.js +28 -1
- package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
- package/lib/components/AddSelect/add-select-utils.js +35 -2
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +279 -145
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +121 -45
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +47 -17
- package/lib/components/DataSpreadsheet/hooks/index.js +45 -0
- package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +151 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +79 -0
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -5
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
- package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
- package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
- package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
- package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +44 -8
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +235 -20
- package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
- 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/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
- package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
- package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
- package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
- package/lib/components/PageHeader/PageHeader.js +3 -1
- package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
- package/lib/components/TagSet/TagSet.js +22 -6
- package/lib/components/Tearsheet/TearsheetShell.js +36 -10
- package/lib/components/UserProfileImage/UserProfileImage.js +37 -9
- package/lib/components/index.js +9 -1
- package/lib/global/js/package-settings.js +4 -2
- package/package.json +20 -16
- package/scss/components/AboutModal/_about-modal.scss +4 -0
- package/scss/components/AddSelect/_add-select.scss +51 -2
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +72 -9
- 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/ExportModal/_export-modal.scss +0 -4
- package/scss/components/HTTPErrors/_http-errors.scss +16 -16
- package/scss/components/PageHeader/_page-header.scss +4 -0
- package/scss/components/Tearsheet/_tearsheet.scss +4 -0
- package/scss/components/_index.scss +1 -0
@@ -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
|
*
|
@@ -12,6 +16,7 @@ import React, { useRef, useCallback, useEffect, forwardRef } from 'react';
|
|
12
16
|
import PropTypes from 'prop-types';
|
13
17
|
import { FixedSizeList } from 'react-window';
|
14
18
|
import cx from 'classnames';
|
19
|
+
import { px } from '@carbon/layout';
|
15
20
|
import { pkg } from '../../settings';
|
16
21
|
import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
|
17
22
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
@@ -25,8 +30,11 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
25
30
|
var columns = _ref.columns,
|
26
31
|
activeCellCoordinates = _ref.activeCellCoordinates,
|
27
32
|
defaultColumn = _ref.defaultColumn,
|
33
|
+
defaultEmptyRowCount = _ref.defaultEmptyRowCount,
|
28
34
|
getTableBodyProps = _ref.getTableBodyProps,
|
35
|
+
headerGroups = _ref.headerGroups,
|
29
36
|
id = _ref.id,
|
37
|
+
onDataUpdate = _ref.onDataUpdate,
|
30
38
|
prepareRow = _ref.prepareRow,
|
31
39
|
rows = _ref.rows,
|
32
40
|
selectionAreaData = _ref.selectionAreaData,
|
@@ -41,11 +49,16 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
41
49
|
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
42
50
|
currentMatcher = _ref.currentMatcher,
|
43
51
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
44
|
-
onSelectionAreaChange = _ref.onSelectionAreaChange
|
52
|
+
onSelectionAreaChange = _ref.onSelectionAreaChange,
|
53
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
|
45
54
|
var previousState = usePreviousValue({
|
46
55
|
selectionAreaData: selectionAreaData,
|
47
56
|
clickAndHoldActive: clickAndHoldActive
|
48
|
-
}); //
|
57
|
+
}); // Set custom css property containing the spreadsheet total width
|
58
|
+
|
59
|
+
useEffect(function () {
|
60
|
+
ref === null || ref === void 0 ? void 0 : ref.current.style.setProperty("--".concat(blockClass, "--total-width"), px(totalColumnsWidth + scrollBarSize));
|
61
|
+
}, [ref, scrollBarSize, totalColumnsWidth]); // Call the `onSelectionAreaChange` handler to send selection area data
|
49
62
|
// back to the consumer
|
50
63
|
|
51
64
|
useEffect(function () {
|
@@ -95,18 +108,20 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
95
108
|
|
96
109
|
if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
|
97
110
|
createCellSelectionArea({
|
111
|
+
ref: ref,
|
98
112
|
area: area,
|
99
113
|
blockClass: blockClass,
|
100
114
|
defaultColumn: defaultColumn,
|
101
115
|
selectionAreas: selectionAreas,
|
102
|
-
setSelectionAreas: setSelectionAreas
|
116
|
+
setSelectionAreas: setSelectionAreas,
|
117
|
+
setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
|
103
118
|
});
|
104
119
|
}
|
105
120
|
|
106
121
|
return;
|
107
122
|
});
|
108
123
|
}
|
109
|
-
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
|
124
|
+
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
|
110
125
|
|
111
126
|
var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
|
112
127
|
var rowStart = _ref2.rowStart,
|
@@ -184,6 +199,9 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
184
199
|
// meaning that selectionAreas should only have one item by default
|
185
200
|
|
186
201
|
if (isHoldingCommandKey) {
|
202
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
203
|
+
activeCellElement.setAttribute('data-selection-id', tempMatcher);
|
204
|
+
setActiveCellInsideSelectionArea(true);
|
187
205
|
setActiveCellCoordinates(activeCoordinates);
|
188
206
|
setCurrentMatcher(tempMatcher);
|
189
207
|
setSelectionAreas(function (prev) {
|
@@ -214,6 +232,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
214
232
|
setSelectionAreas(selectionAreaClone);
|
215
233
|
}
|
216
234
|
} else {
|
235
|
+
setActiveCellInsideSelectionArea(false);
|
217
236
|
setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
|
218
237
|
|
219
238
|
removeCellSelections({
|
@@ -227,7 +246,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
227
246
|
setSelectionAreaData([]);
|
228
247
|
}
|
229
248
|
};
|
230
|
-
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
|
249
|
+
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
|
231
250
|
var handleBodyCellHover = useCallback(function (cell, columnIndex) {
|
232
251
|
return function () {
|
233
252
|
if (clickAndHoldActive) {
|
@@ -260,7 +279,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
260
279
|
};
|
261
280
|
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
|
262
281
|
var handleRowHeaderClick = useCallback(function (index) {
|
263
|
-
return function () {
|
282
|
+
return function (event) {
|
283
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
264
284
|
handleHeaderCellSelection({
|
265
285
|
type: 'row',
|
266
286
|
activeCellCoordinates: activeCellCoordinates,
|
@@ -271,45 +291,88 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
271
291
|
setSelectionAreas: setSelectionAreas,
|
272
292
|
spreadsheetRef: ref,
|
273
293
|
index: index,
|
274
|
-
setSelectionAreaData: setSelectionAreaData
|
294
|
+
setSelectionAreaData: setSelectionAreaData,
|
295
|
+
isHoldingCommandKey: isHoldingCommandKey
|
275
296
|
});
|
276
297
|
};
|
277
|
-
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); //
|
298
|
+
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
|
299
|
+
// using defaultEmptyRowCount to determine how many empty rows are created.
|
300
|
+
|
301
|
+
useEffect(function () {
|
302
|
+
if (!(rows !== null && rows !== void 0 && rows.length)) {
|
303
|
+
var buildEmptyRows = function buildEmptyRows() {
|
304
|
+
var emptyRowData = [];
|
305
|
+
|
306
|
+
_toConsumableArray(Array(defaultEmptyRowCount)).map(function () {
|
307
|
+
var _headerGroups$;
|
308
|
+
|
309
|
+
var emptyCell = {};
|
310
|
+
(_headerGroups$ = headerGroups[0]) === null || _headerGroups$ === void 0 ? void 0 : _headerGroups$.headers.map(function (header) {
|
311
|
+
emptyCell[header.id] = null;
|
312
|
+
});
|
313
|
+
emptyRowData.push(emptyCell);
|
314
|
+
});
|
315
|
+
|
316
|
+
onDataUpdate(emptyRowData);
|
317
|
+
};
|
318
|
+
|
319
|
+
buildEmptyRows();
|
320
|
+
}
|
321
|
+
}, [rows, headerGroups, defaultEmptyRowCount, onDataUpdate]);
|
322
|
+
|
323
|
+
var RenderEmptyRows = function RenderEmptyRows() {
|
324
|
+
return /*#__PURE__*/React.createElement("div", null);
|
325
|
+
}; // Renders each row/cell in the spreadsheet body
|
326
|
+
|
278
327
|
|
279
328
|
var RenderRow = useCallback(function (_ref3) {
|
280
329
|
var index = _ref3.index,
|
281
330
|
style = _ref3.style;
|
282
331
|
var row = rows[index];
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
style: {
|
297
|
-
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
298
|
-
}
|
299
|
-
}, index + 1), row.cells.map(function (cell, index) {
|
300
|
-
return /*#__PURE__*/React.createElement("button", _extends({
|
332
|
+
|
333
|
+
if (rows && rows.length) {
|
334
|
+
prepareRow(row);
|
335
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
|
336
|
+
style: style
|
337
|
+
}), {
|
338
|
+
className: cx("".concat(blockClass, "__tr")),
|
339
|
+
"data-row-index": index,
|
340
|
+
"aria-rowindex": index + 1
|
341
|
+
}), /*#__PURE__*/React.createElement("div", {
|
342
|
+
role: "rowheader"
|
343
|
+
}, /*#__PURE__*/React.createElement("button", {
|
344
|
+
id: "".concat(blockClass, "__cell--").concat(index, "--header"),
|
301
345
|
tabIndex: -1,
|
302
|
-
"data-row-index":
|
303
|
-
"data-column-index":
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
346
|
+
"data-row-index": index,
|
347
|
+
"data-column-index": "header",
|
348
|
+
type: "button",
|
349
|
+
onClick: handleRowHeaderClick(index),
|
350
|
+
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'))),
|
351
|
+
style: {
|
352
|
+
width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4
|
353
|
+
}
|
354
|
+
}, index + 1)), row.cells.map(function (cell, index) {
|
355
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
356
|
+
key: "cell_".concat(index),
|
357
|
+
"aria-colindex": index + 1
|
358
|
+
}, cell.getCellProps(), {
|
359
|
+
role: "gridcell",
|
360
|
+
style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
|
361
|
+
display: 'grid'
|
362
|
+
})
|
363
|
+
}), /*#__PURE__*/React.createElement("button", {
|
364
|
+
id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
|
365
|
+
tabIndex: -1,
|
366
|
+
"data-row-index": cell.row.index,
|
367
|
+
"data-column-index": index,
|
368
|
+
className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
|
369
|
+
onMouseDown: handleBodyCellClick(cell, index),
|
370
|
+
onMouseOver: handleBodyCellHover(cell, index),
|
371
|
+
onFocus: function onFocus() {},
|
372
|
+
type: "button"
|
373
|
+
}, cell.render('Cell')));
|
374
|
+
}));
|
375
|
+
}
|
313
376
|
}, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
|
314
377
|
var spreadsheetBodyRef = useRef();
|
315
378
|
return /*#__PURE__*/React.createElement("div", _extends({
|
@@ -318,10 +381,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
318
381
|
}, getTableBodyProps()), /*#__PURE__*/React.createElement(FixedSizeList, {
|
319
382
|
className: cx("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
|
320
383
|
height: 400,
|
321
|
-
itemCount: rows.length,
|
384
|
+
itemCount: rows.length || defaultEmptyRowCount,
|
322
385
|
itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
323
386
|
width: totalColumnsWidth + scrollBarSize
|
324
|
-
}, RenderRow));
|
387
|
+
}, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
|
325
388
|
});
|
326
389
|
DataSpreadsheetBody.propTypes = {
|
327
390
|
/**
|
@@ -356,11 +419,21 @@ DataSpreadsheetBody.propTypes = {
|
|
356
419
|
width: PropTypes.number
|
357
420
|
}),
|
358
421
|
|
422
|
+
/**
|
423
|
+
* Sets the number of empty rows to be created when there is no data provided
|
424
|
+
*/
|
425
|
+
defaultEmptyRowCount: PropTypes.number,
|
426
|
+
|
359
427
|
/**
|
360
428
|
* Function to set table body prop values
|
361
429
|
*/
|
362
430
|
getTableBodyProps: PropTypes.func,
|
363
431
|
|
432
|
+
/**
|
433
|
+
* Headers provided from useTable hook
|
434
|
+
*/
|
435
|
+
headerGroups: PropTypes.arrayOf(PropTypes.object),
|
436
|
+
|
364
437
|
/**
|
365
438
|
* The spreadsheet id
|
366
439
|
*/
|
@@ -371,6 +444,11 @@ DataSpreadsheetBody.propTypes = {
|
|
371
444
|
*/
|
372
445
|
onActiveCellChange: PropTypes.func,
|
373
446
|
|
447
|
+
/**
|
448
|
+
* The event handler that is called to set the rows for the empty spreadsheet
|
449
|
+
*/
|
450
|
+
onDataUpdate: PropTypes.func,
|
451
|
+
|
374
452
|
/**
|
375
453
|
* The event handler that is called when the selection areas change
|
376
454
|
*/
|
@@ -406,6 +484,11 @@ DataSpreadsheetBody.propTypes = {
|
|
406
484
|
*/
|
407
485
|
setActiveCellCoordinates: PropTypes.func,
|
408
486
|
|
487
|
+
/**
|
488
|
+
* Setter fn for active cell inside of selection area
|
489
|
+
*/
|
490
|
+
setActiveCellInsideSelectionArea: PropTypes.func,
|
491
|
+
|
409
492
|
/**
|
410
493
|
* Setter fn for clickAndHold state value
|
411
494
|
*/
|
@@ -17,9 +17,10 @@ import PropTypes from 'prop-types';
|
|
17
17
|
import cx from 'classnames';
|
18
18
|
import { px } from '@carbon/layout';
|
19
19
|
import { pkg } from '../../settings';
|
20
|
+
import { usePreviousValue } from '../../global/js/hooks';
|
20
21
|
import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
|
21
22
|
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
22
|
-
import {
|
23
|
+
import { selectAllCells } from './utils/selectAllCells';
|
23
24
|
var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
|
24
25
|
export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
25
26
|
var activeCellCoordinates = _ref.activeCellCoordinates,
|
@@ -33,7 +34,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
33
34
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
34
35
|
setSelectionAreas = _ref.setSelectionAreas,
|
35
36
|
setSelectionAreaData = _ref.setSelectionAreaData,
|
36
|
-
rows = _ref.rows
|
37
|
+
rows = _ref.rows,
|
38
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
37
39
|
|
38
40
|
var _useState = useState(0),
|
39
41
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -55,7 +57,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
55
57
|
}, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
|
56
58
|
|
57
59
|
var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
|
58
|
-
return function () {
|
60
|
+
return function (event) {
|
61
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
59
62
|
handleHeaderCellSelection({
|
60
63
|
type: 'column',
|
61
64
|
activeCellCoordinates: activeCellCoordinates,
|
@@ -66,13 +69,27 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
66
69
|
setSelectionAreas: setSelectionAreas,
|
67
70
|
spreadsheetRef: ref,
|
68
71
|
index: index,
|
69
|
-
setSelectionAreaData: setSelectionAreaData
|
72
|
+
setSelectionAreaData: setSelectionAreaData,
|
73
|
+
isHoldingCommandKey: isHoldingCommandKey
|
70
74
|
});
|
71
75
|
};
|
72
76
|
};
|
73
77
|
|
78
|
+
var handleSelectAllClick = function handleSelectAllClick() {
|
79
|
+
selectAllCells({
|
80
|
+
ref: ref,
|
81
|
+
setCurrentMatcher: setCurrentMatcher,
|
82
|
+
setSelectionAreas: setSelectionAreas,
|
83
|
+
rows: rows,
|
84
|
+
columns: columns,
|
85
|
+
activeCellCoordinates: activeCellCoordinates,
|
86
|
+
updateActiveCellCoordinates: updateActiveCellCoordinates
|
87
|
+
});
|
88
|
+
};
|
89
|
+
|
74
90
|
return /*#__PURE__*/React.createElement("div", {
|
75
|
-
className: cx("".concat(blockClass, "__header--container"))
|
91
|
+
className: cx("".concat(blockClass, "__header--container")),
|
92
|
+
role: "rowgroup"
|
76
93
|
}, headerGroups.map(function (headerGroup, index) {
|
77
94
|
return /*#__PURE__*/React.createElement("div", _extends({
|
78
95
|
key: "header_".concat(index)
|
@@ -81,30 +98,37 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
81
98
|
width: px(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
|
82
99
|
}),
|
83
100
|
className: "".concat(blockClass, "__tr")
|
84
|
-
}), /*#__PURE__*/React.createElement("
|
101
|
+
}), /*#__PURE__*/React.createElement("div", {
|
102
|
+
role: "columnheader",
|
103
|
+
style: {
|
104
|
+
width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4,
|
105
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
106
|
+
}
|
107
|
+
}, /*#__PURE__*/React.createElement("button", {
|
108
|
+
id: "".concat(blockClass, "__cell--header--header"),
|
85
109
|
"data-row-index": "header",
|
86
110
|
"data-column-index": "header",
|
87
111
|
type: "button",
|
88
112
|
tabIndex: -1,
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
}, "\xA0"), headerGroup.headers.map(function (column, index) {
|
95
|
-
return /*#__PURE__*/React.createElement("button", _extends({
|
113
|
+
onClick: handleSelectAllClick,
|
114
|
+
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'))
|
115
|
+
}, "\xA0")), headerGroup.headers.map(function (column, index) {
|
116
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
96
117
|
key: "column_".concat(index),
|
118
|
+
role: "columnheader",
|
119
|
+
className: "".concat(blockClass, "__columnheader")
|
120
|
+
}, column.getHeaderProps()), /*#__PURE__*/React.createElement("button", {
|
121
|
+
id: "".concat(blockClass, "__cell--header--").concat(index),
|
97
122
|
"data-row-index": "header",
|
98
123
|
"data-column-index": index,
|
99
124
|
tabIndex: -1,
|
100
125
|
onClick: handleColumnHeaderClick(index),
|
101
126
|
style: {
|
102
127
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
103
|
-
}
|
104
|
-
}, column.getHeaderProps(), {
|
128
|
+
},
|
105
129
|
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
130
|
type: "button"
|
107
|
-
}
|
131
|
+
}, column.render('Header')));
|
108
132
|
}));
|
109
133
|
}));
|
110
134
|
});
|
@@ -174,5 +198,10 @@ DataSpreadsheetHeader.propTypes = {
|
|
174
198
|
/**
|
175
199
|
* Setter fn for selectionAreas value
|
176
200
|
*/
|
177
|
-
setSelectionAreas: PropTypes.func
|
201
|
+
setSelectionAreas: PropTypes.func,
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Function used to update the active cell coordinates
|
205
|
+
*/
|
206
|
+
updateActiveCellCoordinates: PropTypes.func
|
178
207
|
};
|
@@ -0,0 +1,11 @@
|
|
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';
|
11
|
+
export { useSpreadsheetEdit } from './useSpreadsheetEdit';
|
@@ -0,0 +1,139 @@
|
|
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
|
+
import { includesResourceKey } from '../utils/handleMultipleKeys';
|
13
|
+
|
14
|
+
var hasFocus = function hasFocus() {
|
15
|
+
return typeof document !== 'undefined' && document.hasFocus();
|
16
|
+
};
|
17
|
+
|
18
|
+
export var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
19
|
+
var ref = _ref.ref,
|
20
|
+
containerHasFocus = _ref.containerHasFocus,
|
21
|
+
isEditing = _ref.isEditing;
|
22
|
+
|
23
|
+
var _useState = useState(''),
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
25
|
+
usingMac = _useState2[0],
|
26
|
+
setUsingMac = _useState2[1];
|
27
|
+
|
28
|
+
var _useState3 = useState(hasFocus),
|
29
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
30
|
+
windowFocused = _useState4[0],
|
31
|
+
setWindowFocused = _useState4[1];
|
32
|
+
|
33
|
+
var _useState5 = useState([]),
|
34
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
35
|
+
keysPressedList = _useState6[0],
|
36
|
+
setKeysPressedList = _useState6[1];
|
37
|
+
|
38
|
+
var previousState = usePreviousValue({
|
39
|
+
isEditing: isEditing,
|
40
|
+
windowFocused: windowFocused
|
41
|
+
}); // useEffect to check for window focus, if window loses focus
|
42
|
+
// we need to clear out the keysPressedList
|
43
|
+
|
44
|
+
useEffect(function () {
|
45
|
+
var userAgentString = window.navigator.userAgent;
|
46
|
+
|
47
|
+
if (userAgentString.includes('Macintosh')) {
|
48
|
+
setUsingMac(true);
|
49
|
+
} else {
|
50
|
+
setUsingMac(false);
|
51
|
+
}
|
52
|
+
|
53
|
+
setWindowFocused(hasFocus());
|
54
|
+
|
55
|
+
var onWindowFocus = function onWindowFocus() {
|
56
|
+
return setWindowFocused(true);
|
57
|
+
};
|
58
|
+
|
59
|
+
var onWindowBlur = function onWindowBlur() {
|
60
|
+
return setWindowFocused(false);
|
61
|
+
};
|
62
|
+
|
63
|
+
window.addEventListener('focus', onWindowFocus);
|
64
|
+
window.addEventListener('blur', onWindowBlur);
|
65
|
+
return function () {
|
66
|
+
window.removeEventListener('focus', onWindowFocus);
|
67
|
+
window.removeEventListener('blur', onWindowBlur);
|
68
|
+
};
|
69
|
+
}, []);
|
70
|
+
useEffect(function () {
|
71
|
+
if (containerHasFocus && !isEditing) {
|
72
|
+
ref.current.onkeydown = ref.current.onkeyup = function (event) {
|
73
|
+
// If keydown, we will add the new key to the keysPressedList array
|
74
|
+
if (event.type === 'keydown') {
|
75
|
+
// Prevent multiple keys of the same type being added to our keysPressedList array
|
76
|
+
if (keysPressedList.includes(event.code)) {
|
77
|
+
return;
|
78
|
+
} // Because keyup events are lost when using the Command key
|
79
|
+
// we need to remove the previously pressed keys so that we
|
80
|
+
// do not have keys in the pressed list that should not be
|
81
|
+
|
82
|
+
|
83
|
+
if (includesResourceKey(keysPressedList, usingMac) && keysPressedList.length > 1) {
|
84
|
+
var clonedKeys = _toConsumableArray(keysPressedList);
|
85
|
+
|
86
|
+
var filteredClonedKeys = clonedKeys.filter(function (item) {
|
87
|
+
return item === 'MetaLeft' || item === 'MetaRight';
|
88
|
+
});
|
89
|
+
filteredClonedKeys.push(event.code);
|
90
|
+
return setKeysPressedList(_toConsumableArray(new Set(filteredClonedKeys)));
|
91
|
+
}
|
92
|
+
|
93
|
+
var tempKeys = _toConsumableArray(keysPressedList);
|
94
|
+
|
95
|
+
tempKeys.push(event.code);
|
96
|
+
setKeysPressedList(_toConsumableArray(new Set(tempKeys)));
|
97
|
+
} // If keyup, we will remove the key from the keysPressedList array
|
98
|
+
|
99
|
+
|
100
|
+
if (event.type === 'keyup') {
|
101
|
+
var _tempKeys = _toConsumableArray(keysPressedList);
|
102
|
+
|
103
|
+
var filteredClone = _tempKeys.filter(function (item) {
|
104
|
+
return item !== event.code;
|
105
|
+
}); // Keyup events are lost on all other keys if a Meta key is used
|
106
|
+
// so to work around this behavior, we empty out all other keys
|
107
|
+
// from the keysPressedList array if we detect a Meta keyup event
|
108
|
+
|
109
|
+
|
110
|
+
if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
|
111
|
+
return setKeysPressedList([]);
|
112
|
+
}
|
113
|
+
|
114
|
+
setKeysPressedList(_toConsumableArray(new Set(filteredClone)));
|
115
|
+
}
|
116
|
+
};
|
117
|
+
}
|
118
|
+
|
119
|
+
if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
|
120
|
+
setKeysPressedList([]);
|
121
|
+
} // Remove handlers if the spreadsheet container loses focus
|
122
|
+
// or is currently in edit mode
|
123
|
+
|
124
|
+
|
125
|
+
if (!containerHasFocus || isEditing) {
|
126
|
+
ref.current.onkeydown = undefined;
|
127
|
+
ref.current.onkeyup = undefined;
|
128
|
+
|
129
|
+
if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
|
130
|
+
setKeysPressedList([]);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
|
134
|
+
return {
|
135
|
+
keysPressedList: keysPressedList,
|
136
|
+
windowFocused: windowFocused,
|
137
|
+
usingMac: usingMac
|
138
|
+
};
|
139
|
+
};
|
@@ -7,8 +7,7 @@
|
|
7
7
|
import { useEffect } from 'react';
|
8
8
|
import { pkg } from '../../../settings';
|
9
9
|
export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
10
|
-
var
|
11
|
-
_ref$blockClass = _ref.blockClass,
|
10
|
+
var _ref$blockClass = _ref.blockClass,
|
12
11
|
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
13
12
|
focusedElement = _ref.focusedElement,
|
14
13
|
removeActiveCell = _ref.removeActiveCell,
|
@@ -18,11 +17,10 @@ export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
|
18
17
|
if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
19
18
|
setContainerHasFocus(false);
|
20
19
|
removeActiveCell();
|
21
|
-
activeKeys.current = [];
|
22
20
|
}
|
23
21
|
|
24
22
|
if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
25
23
|
setContainerHasFocus(true);
|
26
24
|
}
|
27
|
-
}, [focusedElement, removeActiveCell,
|
25
|
+
}, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
|
28
26
|
};
|
@@ -0,0 +1,68 @@
|
|
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 { px } from '@carbon/layout';
|
9
|
+
export var useSpreadsheetEdit = function useSpreadsheetEdit(_ref) {
|
10
|
+
var isEditing = _ref.isEditing,
|
11
|
+
rows = _ref.rows,
|
12
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
13
|
+
activeCellRef = _ref.activeCellRef,
|
14
|
+
cellEditorRef = _ref.cellEditorRef,
|
15
|
+
cellEditorRulerRef = _ref.cellEditorRulerRef,
|
16
|
+
columns = _ref.columns,
|
17
|
+
defaultColumn = _ref.defaultColumn,
|
18
|
+
cellEditorValue = _ref.cellEditorValue;
|
19
|
+
useEffect(function () {
|
20
|
+
if (isEditing) {
|
21
|
+
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
22
|
+
|
23
|
+
var cellProps = (_rows$activeCellCoord = rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row]) === null || _rows$activeCellCoord === void 0 ? void 0 : _rows$activeCellCoord.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column];
|
24
|
+
var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
|
25
|
+
var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
|
26
|
+
cellEditorRef.current.style.left = activeCellLeftPosition;
|
27
|
+
cellEditorRef.current.style.top = activeCellTopPosition;
|
28
|
+
cellEditorRef.current.style.display = 'block';
|
29
|
+
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
30
|
+
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
31
|
+
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2 - 1, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
32
|
+
|
33
|
+
cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
|
34
|
+
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
35
|
+
var rulerWidth = cellEditorRulerRef.current.offsetWidth;
|
36
|
+
var cellWidth = activeCellRef.current.offsetWidth;
|
37
|
+
|
38
|
+
if (rulerWidth >= cellWidth) {
|
39
|
+
var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
|
40
|
+
var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
|
41
|
+
var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
42
|
+
var totalColumns = columns.length;
|
43
|
+
var totalRows = rows.length;
|
44
|
+
var totalMultiplierPossible = totalColumns - startingColumnPosition;
|
45
|
+
var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
|
46
|
+
cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
|
47
|
+
cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
|
48
|
+
cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
|
49
|
+
// Cell editor has reached max height, we need to add the scrolling back.
|
50
|
+
// We also need to subtract 1 to account for the fact that the cell editor
|
51
|
+
// is placed one pixel below the cell being edited to account for the border
|
52
|
+
|
53
|
+
if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
|
54
|
+
cellEditorRef.current.style.overflow = 'auto';
|
55
|
+
} else {
|
56
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!isEditing) {
|
62
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
63
|
+
cellEditorRef.current.style.display = 'none';
|
64
|
+
cellEditorRef.current.blur();
|
65
|
+
activeCellRef.current.focus();
|
66
|
+
}
|
67
|
+
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn, cellEditorValue, activeCellRef, cellEditorRef, cellEditorRulerRef]);
|
68
|
+
};
|