@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
@@ -23,6 +23,8 @@ var _reactWindow = require("react-window");
|
|
23
23
|
|
24
24
|
var _classnames = _interopRequireDefault(require("classnames"));
|
25
25
|
|
26
|
+
var _layout = require("@carbon/layout");
|
27
|
+
|
26
28
|
var _settings = require("../../settings");
|
27
29
|
|
28
30
|
var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
|
@@ -43,19 +45,20 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
43
45
|
|
44
46
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
* LICENSE file in the root directory of this source tree.
|
51
|
-
*/
|
48
|
+
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; }
|
49
|
+
|
50
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
51
|
+
|
52
52
|
var blockClass = "".concat(_settings.pkg.prefix, "--data-spreadsheet");
|
53
53
|
var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
54
54
|
var columns = _ref.columns,
|
55
55
|
activeCellCoordinates = _ref.activeCellCoordinates,
|
56
56
|
defaultColumn = _ref.defaultColumn,
|
57
|
+
defaultEmptyRowCount = _ref.defaultEmptyRowCount,
|
57
58
|
getTableBodyProps = _ref.getTableBodyProps,
|
59
|
+
headerGroups = _ref.headerGroups,
|
58
60
|
id = _ref.id,
|
61
|
+
onDataUpdate = _ref.onDataUpdate,
|
59
62
|
prepareRow = _ref.prepareRow,
|
60
63
|
rows = _ref.rows,
|
61
64
|
selectionAreaData = _ref.selectionAreaData,
|
@@ -70,11 +73,16 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
70
73
|
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
71
74
|
currentMatcher = _ref.currentMatcher,
|
72
75
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
73
|
-
onSelectionAreaChange = _ref.onSelectionAreaChange
|
76
|
+
onSelectionAreaChange = _ref.onSelectionAreaChange,
|
77
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
|
74
78
|
var previousState = (0, _hooks.usePreviousValue)({
|
75
79
|
selectionAreaData: selectionAreaData,
|
76
80
|
clickAndHoldActive: clickAndHoldActive
|
77
|
-
}); //
|
81
|
+
}); // Set custom css property containing the spreadsheet total width
|
82
|
+
|
83
|
+
(0, _react.useEffect)(function () {
|
84
|
+
ref === null || ref === void 0 ? void 0 : ref.current.style.setProperty("--".concat(blockClass, "--total-width"), (0, _layout.px)(totalColumnsWidth + scrollBarSize));
|
85
|
+
}, [ref, scrollBarSize, totalColumnsWidth]); // Call the `onSelectionAreaChange` handler to send selection area data
|
78
86
|
// back to the consumer
|
79
87
|
|
80
88
|
(0, _react.useEffect)(function () {
|
@@ -124,18 +132,20 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
124
132
|
|
125
133
|
if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
|
126
134
|
(0, _createCellSelectionArea.createCellSelectionArea)({
|
135
|
+
ref: ref,
|
127
136
|
area: area,
|
128
137
|
blockClass: blockClass,
|
129
138
|
defaultColumn: defaultColumn,
|
130
139
|
selectionAreas: selectionAreas,
|
131
|
-
setSelectionAreas: setSelectionAreas
|
140
|
+
setSelectionAreas: setSelectionAreas,
|
141
|
+
setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
|
132
142
|
});
|
133
143
|
}
|
134
144
|
|
135
145
|
return;
|
136
146
|
});
|
137
147
|
}
|
138
|
-
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
|
148
|
+
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
|
139
149
|
|
140
150
|
var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
|
141
151
|
var rowStart = _ref2.rowStart,
|
@@ -213,6 +223,9 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
213
223
|
// meaning that selectionAreas should only have one item by default
|
214
224
|
|
215
225
|
if (isHoldingCommandKey) {
|
226
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
227
|
+
activeCellElement.setAttribute('data-selection-id', tempMatcher);
|
228
|
+
setActiveCellInsideSelectionArea(true);
|
216
229
|
setActiveCellCoordinates(activeCoordinates);
|
217
230
|
setCurrentMatcher(tempMatcher);
|
218
231
|
setSelectionAreas(function (prev) {
|
@@ -243,6 +256,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
243
256
|
setSelectionAreas(selectionAreaClone);
|
244
257
|
}
|
245
258
|
} else {
|
259
|
+
setActiveCellInsideSelectionArea(false);
|
246
260
|
setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
|
247
261
|
|
248
262
|
(0, _removeCellSelections.removeCellSelections)({
|
@@ -256,7 +270,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
256
270
|
setSelectionAreaData([]);
|
257
271
|
}
|
258
272
|
};
|
259
|
-
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
|
273
|
+
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
|
260
274
|
var handleBodyCellHover = (0, _react.useCallback)(function (cell, columnIndex) {
|
261
275
|
return function () {
|
262
276
|
if (clickAndHoldActive) {
|
@@ -289,7 +303,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
289
303
|
};
|
290
304
|
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
|
291
305
|
var handleRowHeaderClick = (0, _react.useCallback)(function (index) {
|
292
|
-
return function () {
|
306
|
+
return function (event) {
|
307
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
293
308
|
(0, _handleHeaderCellSelection.handleHeaderCellSelection)({
|
294
309
|
type: 'row',
|
295
310
|
activeCellCoordinates: activeCellCoordinates,
|
@@ -300,45 +315,86 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
300
315
|
setSelectionAreas: setSelectionAreas,
|
301
316
|
spreadsheetRef: ref,
|
302
317
|
index: index,
|
303
|
-
setSelectionAreaData: setSelectionAreaData
|
318
|
+
setSelectionAreaData: setSelectionAreaData,
|
319
|
+
isHoldingCommandKey: isHoldingCommandKey
|
304
320
|
});
|
305
321
|
};
|
306
|
-
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); //
|
322
|
+
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
|
323
|
+
// using defaultEmptyRowCount to determine how many empty rows are created.
|
324
|
+
|
325
|
+
(0, _react.useEffect)(function () {
|
326
|
+
if (!(rows !== null && rows !== void 0 && rows.length)) {
|
327
|
+
var buildEmptyRows = function buildEmptyRows() {
|
328
|
+
var emptyRowData = [];
|
329
|
+
(0, _toConsumableArray2.default)(Array(defaultEmptyRowCount)).map(function () {
|
330
|
+
var _headerGroups$;
|
331
|
+
|
332
|
+
var emptyCell = {};
|
333
|
+
(_headerGroups$ = headerGroups[0]) === null || _headerGroups$ === void 0 ? void 0 : _headerGroups$.headers.map(function (header) {
|
334
|
+
emptyCell[header.id] = null;
|
335
|
+
});
|
336
|
+
emptyRowData.push(emptyCell);
|
337
|
+
});
|
338
|
+
onDataUpdate(emptyRowData);
|
339
|
+
};
|
340
|
+
|
341
|
+
buildEmptyRows();
|
342
|
+
}
|
343
|
+
}, [rows, headerGroups, defaultEmptyRowCount, onDataUpdate]);
|
344
|
+
|
345
|
+
var RenderEmptyRows = function RenderEmptyRows() {
|
346
|
+
return /*#__PURE__*/_react.default.createElement("div", null);
|
347
|
+
}; // Renders each row/cell in the spreadsheet body
|
348
|
+
|
307
349
|
|
308
350
|
var RenderRow = (0, _react.useCallback)(function (_ref3) {
|
309
351
|
var index = _ref3.index,
|
310
352
|
style = _ref3.style;
|
311
353
|
var row = rows[index];
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
style: {
|
326
|
-
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
327
|
-
}
|
328
|
-
}, index + 1), row.cells.map(function (cell, index) {
|
329
|
-
return /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
|
354
|
+
|
355
|
+
if (rows && rows.length) {
|
356
|
+
prepareRow(row);
|
357
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, row.getRowProps({
|
358
|
+
style: style
|
359
|
+
}), {
|
360
|
+
className: (0, _classnames.default)("".concat(blockClass, "__tr")),
|
361
|
+
"data-row-index": index,
|
362
|
+
"aria-rowindex": index + 1
|
363
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
364
|
+
role: "rowheader"
|
365
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
366
|
+
id: "".concat(blockClass, "__cell--").concat(index, "--header"),
|
330
367
|
tabIndex: -1,
|
331
|
-
"data-row-index":
|
332
|
-
"data-column-index":
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
368
|
+
"data-row-index": index,
|
369
|
+
"data-column-index": "header",
|
370
|
+
type: "button",
|
371
|
+
onClick: handleRowHeaderClick(index),
|
372
|
+
className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'row'))),
|
373
|
+
style: {
|
374
|
+
width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4
|
375
|
+
}
|
376
|
+
}, index + 1)), row.cells.map(function (cell, index) {
|
377
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
378
|
+
key: "cell_".concat(index),
|
379
|
+
"aria-colindex": index + 1
|
380
|
+
}, cell.getCellProps(), {
|
381
|
+
role: "gridcell",
|
382
|
+
style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
|
383
|
+
display: 'grid'
|
384
|
+
})
|
385
|
+
}), /*#__PURE__*/_react.default.createElement("button", {
|
386
|
+
id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
|
387
|
+
tabIndex: -1,
|
388
|
+
"data-row-index": cell.row.index,
|
389
|
+
"data-column-index": index,
|
390
|
+
className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
|
391
|
+
onMouseDown: handleBodyCellClick(cell, index),
|
392
|
+
onMouseOver: handleBodyCellHover(cell, index),
|
393
|
+
onFocus: function onFocus() {},
|
394
|
+
type: "button"
|
395
|
+
}, cell.render('Cell')));
|
396
|
+
}));
|
397
|
+
}
|
342
398
|
}, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
|
343
399
|
var spreadsheetBodyRef = (0, _react.useRef)();
|
344
400
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
@@ -347,10 +403,10 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
347
403
|
}, getTableBodyProps()), /*#__PURE__*/_react.default.createElement(_reactWindow.FixedSizeList, {
|
348
404
|
className: (0, _classnames.default)("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
|
349
405
|
height: 400,
|
350
|
-
itemCount: rows.length,
|
406
|
+
itemCount: rows.length || defaultEmptyRowCount,
|
351
407
|
itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
352
408
|
width: totalColumnsWidth + scrollBarSize
|
353
|
-
}, RenderRow));
|
409
|
+
}, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
|
354
410
|
});
|
355
411
|
exports.DataSpreadsheetBody = DataSpreadsheetBody;
|
356
412
|
DataSpreadsheetBody.propTypes = {
|
@@ -386,11 +442,21 @@ DataSpreadsheetBody.propTypes = {
|
|
386
442
|
width: _propTypes.default.number
|
387
443
|
}),
|
388
444
|
|
445
|
+
/**
|
446
|
+
* Sets the number of empty rows to be created when there is no data provided
|
447
|
+
*/
|
448
|
+
defaultEmptyRowCount: _propTypes.default.number,
|
449
|
+
|
389
450
|
/**
|
390
451
|
* Function to set table body prop values
|
391
452
|
*/
|
392
453
|
getTableBodyProps: _propTypes.default.func,
|
393
454
|
|
455
|
+
/**
|
456
|
+
* Headers provided from useTable hook
|
457
|
+
*/
|
458
|
+
headerGroups: _propTypes.default.arrayOf(_propTypes.default.object),
|
459
|
+
|
394
460
|
/**
|
395
461
|
* The spreadsheet id
|
396
462
|
*/
|
@@ -401,6 +467,11 @@ DataSpreadsheetBody.propTypes = {
|
|
401
467
|
*/
|
402
468
|
onActiveCellChange: _propTypes.default.func,
|
403
469
|
|
470
|
+
/**
|
471
|
+
* The event handler that is called to set the rows for the empty spreadsheet
|
472
|
+
*/
|
473
|
+
onDataUpdate: _propTypes.default.func,
|
474
|
+
|
404
475
|
/**
|
405
476
|
* The event handler that is called when the selection areas change
|
406
477
|
*/
|
@@ -436,6 +507,11 @@ DataSpreadsheetBody.propTypes = {
|
|
436
507
|
*/
|
437
508
|
setActiveCellCoordinates: _propTypes.default.func,
|
438
509
|
|
510
|
+
/**
|
511
|
+
* Setter fn for active cell inside of selection area
|
512
|
+
*/
|
513
|
+
setActiveCellInsideSelectionArea: _propTypes.default.func,
|
514
|
+
|
439
515
|
/**
|
440
516
|
* Setter fn for clickAndHold state value
|
441
517
|
*/
|
@@ -25,11 +25,13 @@ var _layout = require("@carbon/layout");
|
|
25
25
|
|
26
26
|
var _settings = require("../../settings");
|
27
27
|
|
28
|
+
var _hooks = require("../../global/js/hooks");
|
29
|
+
|
28
30
|
var _checkActiveHeaderCell = require("./utils/checkActiveHeaderCell");
|
29
31
|
|
30
32
|
var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
|
31
33
|
|
32
|
-
var
|
34
|
+
var _selectAllCells = require("./utils/selectAllCells");
|
33
35
|
|
34
36
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
35
37
|
|
@@ -52,7 +54,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
52
54
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
53
55
|
setSelectionAreas = _ref.setSelectionAreas,
|
54
56
|
setSelectionAreaData = _ref.setSelectionAreaData,
|
55
|
-
rows = _ref.rows
|
57
|
+
rows = _ref.rows,
|
58
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
56
59
|
|
57
60
|
var _useState = (0, _react.useState)(0),
|
58
61
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
@@ -74,7 +77,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
74
77
|
}, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
|
75
78
|
|
76
79
|
var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
|
77
|
-
return function () {
|
80
|
+
return function (event) {
|
81
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
78
82
|
(0, _handleHeaderCellSelection.handleHeaderCellSelection)({
|
79
83
|
type: 'column',
|
80
84
|
activeCellCoordinates: activeCellCoordinates,
|
@@ -85,13 +89,27 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
85
89
|
setSelectionAreas: setSelectionAreas,
|
86
90
|
spreadsheetRef: ref,
|
87
91
|
index: index,
|
88
|
-
setSelectionAreaData: setSelectionAreaData
|
92
|
+
setSelectionAreaData: setSelectionAreaData,
|
93
|
+
isHoldingCommandKey: isHoldingCommandKey
|
89
94
|
});
|
90
95
|
};
|
91
96
|
};
|
92
97
|
|
98
|
+
var handleSelectAllClick = function handleSelectAllClick() {
|
99
|
+
(0, _selectAllCells.selectAllCells)({
|
100
|
+
ref: ref,
|
101
|
+
setCurrentMatcher: setCurrentMatcher,
|
102
|
+
setSelectionAreas: setSelectionAreas,
|
103
|
+
rows: rows,
|
104
|
+
columns: columns,
|
105
|
+
activeCellCoordinates: activeCellCoordinates,
|
106
|
+
updateActiveCellCoordinates: updateActiveCellCoordinates
|
107
|
+
});
|
108
|
+
};
|
109
|
+
|
93
110
|
return /*#__PURE__*/_react.default.createElement("div", {
|
94
|
-
className: (0, _classnames.default)("".concat(blockClass, "__header--container"))
|
111
|
+
className: (0, _classnames.default)("".concat(blockClass, "__header--container")),
|
112
|
+
role: "rowgroup"
|
95
113
|
}, headerGroups.map(function (headerGroup, index) {
|
96
114
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
97
115
|
key: "header_".concat(index)
|
@@ -100,30 +118,37 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
100
118
|
width: (0, _layout.px)(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
|
101
119
|
}),
|
102
120
|
className: "".concat(blockClass, "__tr")
|
103
|
-
}), /*#__PURE__*/_react.default.createElement("
|
121
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
122
|
+
role: "columnheader",
|
123
|
+
style: {
|
124
|
+
width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4,
|
125
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
126
|
+
}
|
127
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
128
|
+
id: "".concat(blockClass, "__cell--header--header"),
|
104
129
|
"data-row-index": "header",
|
105
130
|
"data-column-index": "header",
|
106
131
|
type: "button",
|
107
132
|
tabIndex: -1,
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
113
|
-
}, "\xA0"), headerGroup.headers.map(function (column, index) {
|
114
|
-
return /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
|
133
|
+
onClick: handleSelectAllClick,
|
134
|
+
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header'))
|
135
|
+
}, "\xA0")), headerGroup.headers.map(function (column, index) {
|
136
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
115
137
|
key: "column_".concat(index),
|
138
|
+
role: "columnheader",
|
139
|
+
className: "".concat(blockClass, "__columnheader")
|
140
|
+
}, column.getHeaderProps()), /*#__PURE__*/_react.default.createElement("button", {
|
141
|
+
id: "".concat(blockClass, "__cell--header--").concat(index),
|
116
142
|
"data-row-index": "header",
|
117
143
|
"data-column-index": index,
|
118
144
|
tabIndex: -1,
|
119
145
|
onClick: handleColumnHeaderClick(index),
|
120
146
|
style: {
|
121
147
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
122
|
-
}
|
123
|
-
}, column.getHeaderProps(), {
|
148
|
+
},
|
124
149
|
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'column'))),
|
125
150
|
type: "button"
|
126
|
-
}
|
151
|
+
}, column.render('Header')));
|
127
152
|
}));
|
128
153
|
}));
|
129
154
|
});
|
@@ -194,5 +219,10 @@ DataSpreadsheetHeader.propTypes = {
|
|
194
219
|
/**
|
195
220
|
* Setter fn for selectionAreas value
|
196
221
|
*/
|
197
|
-
setSelectionAreas: _propTypes.default.func
|
222
|
+
setSelectionAreas: _propTypes.default.func,
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Function used to update the active cell coordinates
|
226
|
+
*/
|
227
|
+
updateActiveCellCoordinates: _propTypes.default.func
|
198
228
|
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "useMoveActiveCell", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function get() {
|
9
|
+
return _useMoveActiveCell.useMoveActiveCell;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "useMultipleKeyTracking", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _useMultipleKeyTracking.useMultipleKeyTracking;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
Object.defineProperty(exports, "useResetSpreadsheetFocus", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function get() {
|
21
|
+
return _useResetSpreadsheetFocus.useResetSpreadsheetFocus;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
Object.defineProperty(exports, "useSpreadsheetEdit", {
|
25
|
+
enumerable: true,
|
26
|
+
get: function get() {
|
27
|
+
return _useSpreadsheetEdit.useSpreadsheetEdit;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
Object.defineProperty(exports, "useSpreadsheetOutsideClick", {
|
31
|
+
enumerable: true,
|
32
|
+
get: function get() {
|
33
|
+
return _useSpreadsheetOutsideClick.useSpreadsheetOutsideClick;
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
37
|
+
var _useMoveActiveCell = require("./useMoveActiveCell");
|
38
|
+
|
39
|
+
var _useMultipleKeyTracking = require("./useMultipleKeyTracking");
|
40
|
+
|
41
|
+
var _useResetSpreadsheetFocus = require("./useResetSpreadsheetFocus");
|
42
|
+
|
43
|
+
var _useSpreadsheetOutsideClick = require("./useSpreadsheetOutsideClick");
|
44
|
+
|
45
|
+
var _useSpreadsheetEdit = require("./useSpreadsheetEdit");
|
@@ -0,0 +1,151 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.useMultipleKeyTracking = void 0;
|
9
|
+
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
11
|
+
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
13
|
+
|
14
|
+
var _react = require("react");
|
15
|
+
|
16
|
+
var _hooks = require("../../../global/js/hooks");
|
17
|
+
|
18
|
+
var _handleMultipleKeys = require("../utils/handleMultipleKeys");
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Copyright IBM Corp. 2022, 2022
|
22
|
+
*
|
23
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
25
|
+
*/
|
26
|
+
var hasFocus = function hasFocus() {
|
27
|
+
return typeof document !== 'undefined' && document.hasFocus();
|
28
|
+
};
|
29
|
+
|
30
|
+
var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
31
|
+
var ref = _ref.ref,
|
32
|
+
containerHasFocus = _ref.containerHasFocus,
|
33
|
+
isEditing = _ref.isEditing;
|
34
|
+
|
35
|
+
var _useState = (0, _react.useState)(''),
|
36
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
37
|
+
usingMac = _useState2[0],
|
38
|
+
setUsingMac = _useState2[1];
|
39
|
+
|
40
|
+
var _useState3 = (0, _react.useState)(hasFocus),
|
41
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
42
|
+
windowFocused = _useState4[0],
|
43
|
+
setWindowFocused = _useState4[1];
|
44
|
+
|
45
|
+
var _useState5 = (0, _react.useState)([]),
|
46
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
47
|
+
keysPressedList = _useState6[0],
|
48
|
+
setKeysPressedList = _useState6[1];
|
49
|
+
|
50
|
+
var previousState = (0, _hooks.usePreviousValue)({
|
51
|
+
isEditing: isEditing,
|
52
|
+
windowFocused: windowFocused
|
53
|
+
}); // useEffect to check for window focus, if window loses focus
|
54
|
+
// we need to clear out the keysPressedList
|
55
|
+
|
56
|
+
(0, _react.useEffect)(function () {
|
57
|
+
var userAgentString = window.navigator.userAgent;
|
58
|
+
|
59
|
+
if (userAgentString.includes('Macintosh')) {
|
60
|
+
setUsingMac(true);
|
61
|
+
} else {
|
62
|
+
setUsingMac(false);
|
63
|
+
}
|
64
|
+
|
65
|
+
setWindowFocused(hasFocus());
|
66
|
+
|
67
|
+
var onWindowFocus = function onWindowFocus() {
|
68
|
+
return setWindowFocused(true);
|
69
|
+
};
|
70
|
+
|
71
|
+
var onWindowBlur = function onWindowBlur() {
|
72
|
+
return setWindowFocused(false);
|
73
|
+
};
|
74
|
+
|
75
|
+
window.addEventListener('focus', onWindowFocus);
|
76
|
+
window.addEventListener('blur', onWindowBlur);
|
77
|
+
return function () {
|
78
|
+
window.removeEventListener('focus', onWindowFocus);
|
79
|
+
window.removeEventListener('blur', onWindowBlur);
|
80
|
+
};
|
81
|
+
}, []);
|
82
|
+
(0, _react.useEffect)(function () {
|
83
|
+
if (containerHasFocus && !isEditing) {
|
84
|
+
ref.current.onkeydown = ref.current.onkeyup = function (event) {
|
85
|
+
// If keydown, we will add the new key to the keysPressedList array
|
86
|
+
if (event.type === 'keydown') {
|
87
|
+
// Prevent multiple keys of the same type being added to our keysPressedList array
|
88
|
+
if (keysPressedList.includes(event.code)) {
|
89
|
+
return;
|
90
|
+
} // Because keyup events are lost when using the Command key
|
91
|
+
// we need to remove the previously pressed keys so that we
|
92
|
+
// do not have keys in the pressed list that should not be
|
93
|
+
|
94
|
+
|
95
|
+
if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac) && keysPressedList.length > 1) {
|
96
|
+
var clonedKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
97
|
+
var filteredClonedKeys = clonedKeys.filter(function (item) {
|
98
|
+
return item === 'MetaLeft' || item === 'MetaRight';
|
99
|
+
});
|
100
|
+
filteredClonedKeys.push(event.code);
|
101
|
+
return setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClonedKeys)));
|
102
|
+
}
|
103
|
+
|
104
|
+
var tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
105
|
+
tempKeys.push(event.code);
|
106
|
+
setKeysPressedList((0, _toConsumableArray2.default)(new Set(tempKeys)));
|
107
|
+
} // If keyup, we will remove the key from the keysPressedList array
|
108
|
+
|
109
|
+
|
110
|
+
if (event.type === 'keyup') {
|
111
|
+
var _tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
112
|
+
|
113
|
+
var filteredClone = _tempKeys.filter(function (item) {
|
114
|
+
return item !== event.code;
|
115
|
+
}); // Keyup events are lost on all other keys if a Meta key is used
|
116
|
+
// so to work around this behavior, we empty out all other keys
|
117
|
+
// from the keysPressedList array if we detect a Meta keyup event
|
118
|
+
|
119
|
+
|
120
|
+
if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
|
121
|
+
return setKeysPressedList([]);
|
122
|
+
}
|
123
|
+
|
124
|
+
setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClone)));
|
125
|
+
}
|
126
|
+
};
|
127
|
+
}
|
128
|
+
|
129
|
+
if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
|
130
|
+
setKeysPressedList([]);
|
131
|
+
} // Remove handlers if the spreadsheet container loses focus
|
132
|
+
// or is currently in edit mode
|
133
|
+
|
134
|
+
|
135
|
+
if (!containerHasFocus || isEditing) {
|
136
|
+
ref.current.onkeydown = undefined;
|
137
|
+
ref.current.onkeyup = undefined;
|
138
|
+
|
139
|
+
if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
|
140
|
+
setKeysPressedList([]);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
|
144
|
+
return {
|
145
|
+
keysPressedList: keysPressedList,
|
146
|
+
windowFocused: windowFocused,
|
147
|
+
usingMac: usingMac
|
148
|
+
};
|
149
|
+
};
|
150
|
+
|
151
|
+
exports.useMultipleKeyTracking = useMultipleKeyTracking;
|
@@ -16,8 +16,7 @@ var _settings = require("../../../settings");
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
17
17
|
*/
|
18
18
|
var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
19
|
-
var
|
20
|
-
_ref$blockClass = _ref.blockClass,
|
19
|
+
var _ref$blockClass = _ref.blockClass,
|
21
20
|
blockClass = _ref$blockClass === void 0 ? "".concat(_settings.pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
22
21
|
focusedElement = _ref.focusedElement,
|
23
22
|
removeActiveCell = _ref.removeActiveCell,
|
@@ -27,13 +26,12 @@ var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
|
27
26
|
if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
28
27
|
setContainerHasFocus(false);
|
29
28
|
removeActiveCell();
|
30
|
-
activeKeys.current = [];
|
31
29
|
}
|
32
30
|
|
33
31
|
if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
34
32
|
setContainerHasFocus(true);
|
35
33
|
}
|
36
|
-
}, [focusedElement, removeActiveCell,
|
34
|
+
}, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
|
37
35
|
};
|
38
36
|
|
39
37
|
exports.useResetSpreadsheetFocus = useResetSpreadsheetFocus;
|