@carbon/ibm-products 1.11.2 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +0 -3
- 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 +2019 -376
- 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 +18 -6
- 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 +679 -19
- 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 +679 -19
- 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 +133 -30
- package/es/components/AddSelect/AddSelectColumn.js +0 -1
- package/es/components/AddSelect/AddSelectFilter.js +129 -0
- package/es/components/AddSelect/AddSelectList.js +59 -13
- 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 +262 -164
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +191 -51
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +65 -13
- package/es/components/DataSpreadsheet/hooks/index.js +10 -0
- package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +111 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -6
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +80 -6
- package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
- package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
- package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
- package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
- package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
- package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
- package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
- package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
- package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
- package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
- package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
- package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
- package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
- package/es/components/Datagrid/Datagrid/index.js +8 -0
- package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
- package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
- package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
- package/es/components/Datagrid/common-column-ids.js +8 -0
- package/es/components/Datagrid/index.js +22 -0
- package/es/components/Datagrid/useActionsColumn.js +86 -0
- package/es/components/Datagrid/useColumnRightAlign.js +52 -0
- package/es/components/Datagrid/useCustomizeColumns.js +45 -0
- package/es/components/Datagrid/useDatagrid.js +44 -0
- package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
- package/es/components/Datagrid/useDisableSelectRows.js +84 -0
- package/es/components/Datagrid/useExpandedRow.js +52 -0
- package/es/components/Datagrid/useFlexResize.js +51 -0
- package/es/components/Datagrid/useFloatingScroll.js +88 -0
- package/es/components/Datagrid/useInfiniteScroll.js +54 -0
- package/es/components/Datagrid/useNestedRows.js +53 -0
- package/es/components/Datagrid/useOnRowClick.js +37 -0
- package/es/components/Datagrid/useParentDimensions.js +65 -0
- package/es/components/Datagrid/useResizeTable.js +40 -0
- package/es/components/Datagrid/useRowExpander.js +34 -0
- package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
- package/es/components/Datagrid/useRowRenderer.js +30 -0
- package/es/components/Datagrid/useRowSize.js +56 -0
- package/es/components/Datagrid/useSelectAllToggle.js +74 -0
- package/es/components/Datagrid/useSelectRows.js +107 -0
- package/es/components/Datagrid/useSkeletonRows.js +32 -0
- package/es/components/Datagrid/useSortableColumns.js +110 -0
- package/es/components/Datagrid/useStickyColumn.js +183 -0
- package/es/components/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/ImportModal/ImportModal.js +2 -2
- package/es/components/TagSet/TagSet.js +12 -3
- package/es/components/UserProfileImage/UserProfileImage.js +38 -10
- package/es/components/index.js +2 -1
- package/es/global/js/package-settings.js +2 -1
- package/lib/components/ActionBar/ActionBar.js +3 -1
- package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/lib/components/AddSelect/AddSelect.js +132 -28
- package/lib/components/AddSelect/AddSelectColumn.js +0 -1
- package/lib/components/AddSelect/AddSelectFilter.js +147 -0
- package/lib/components/AddSelect/AddSelectList.js +61 -12
- 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 +267 -168
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +191 -57
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +67 -18
- package/lib/components/DataSpreadsheet/hooks/index.js +37 -0
- package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +123 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -5
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +83 -7
- package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
- package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
- package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
- package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
- package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
- package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
- package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
- package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
- package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
- package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
- package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
- package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
- package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
- package/lib/components/Datagrid/Datagrid/index.js +15 -0
- package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
- package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
- package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
- package/lib/components/Datagrid/common-column-ids.js +16 -0
- package/lib/components/Datagrid/index.js +127 -0
- package/lib/components/Datagrid/useActionsColumn.js +94 -0
- package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
- package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
- package/lib/components/Datagrid/useDatagrid.js +58 -0
- package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
- package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
- package/lib/components/Datagrid/useExpandedRow.js +58 -0
- package/lib/components/Datagrid/useFlexResize.js +61 -0
- package/lib/components/Datagrid/useFloatingScroll.js +101 -0
- package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
- package/lib/components/Datagrid/useNestedRows.js +65 -0
- package/lib/components/Datagrid/useOnRowClick.js +45 -0
- package/lib/components/Datagrid/useParentDimensions.js +75 -0
- package/lib/components/Datagrid/useResizeTable.js +48 -0
- package/lib/components/Datagrid/useRowExpander.js +45 -0
- package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
- package/lib/components/Datagrid/useRowRenderer.js +40 -0
- package/lib/components/Datagrid/useRowSize.js +67 -0
- package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
- package/lib/components/Datagrid/useSelectRows.js +119 -0
- package/lib/components/Datagrid/useSkeletonRows.js +42 -0
- package/lib/components/Datagrid/useSortableColumns.js +117 -0
- package/lib/components/Datagrid/useStickyColumn.js +190 -0
- package/lib/components/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/ImportModal/ImportModal.js +1 -1
- package/lib/components/TagSet/TagSet.js +12 -3
- package/lib/components/UserProfileImage/UserProfileImage.js +38 -10
- package/lib/components/index.js +9 -1
- package/lib/global/js/package-settings.js +2 -1
- package/package.json +19 -15
- package/scss/components/AboutModal/_about-modal.scss +2 -2
- package/scss/components/ActionSet/_action-set.scss +3 -1
- package/scss/components/AddSelect/_add-select.scss +87 -3
- package/scss/components/CreateModal/_create-modal.scss +7 -5
- package/scss/components/CreateModal/_storybook-styles.scss +8 -7
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +70 -10
- 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 +3 -3
- package/scss/components/HTTPErrors/_http-errors.scss +16 -16
- package/scss/components/InlineEdit/_inline-edit.scss +0 -1
- package/scss/components/ModifiedTabs/_modified-tabs.scss +0 -10
- package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -3
- package/scss/components/OptionsTile/_options-tile.scss +0 -1
- package/scss/components/PageHeader/_page-header.scss +4 -0
- package/scss/components/RemoveModal/_remove-modal.scss +3 -3
- package/scss/components/TagSet/_tag-set.scss +2 -1
- package/scss/components/Tearsheet/_tearsheet.scss +5 -2
- package/scss/components/_index.scss +1 -0
@@ -1,10 +1,8 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
3
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
4
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
5
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
6
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
7
|
-
var _excluded = ["cellSize", "className", "columns", "data", "onDataUpdate", "id", "onActiveCellChange"];
|
5
|
+
var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
|
8
6
|
|
9
7
|
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; }
|
10
8
|
|
@@ -18,7 +16,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
18
16
|
*/
|
19
17
|
// Import portions of React that are needed.
|
20
18
|
import React, { useMemo, useRef, useState, useCallback, useEffect } from 'react';
|
21
|
-
import { useBlockLayout, useTable } from 'react-table';
|
19
|
+
import { useBlockLayout, useTable } from 'react-table';
|
20
|
+
import { px } from '@carbon/layout'; // Other standard imports.
|
22
21
|
|
23
22
|
import PropTypes from 'prop-types';
|
24
23
|
import cx from 'classnames';
|
@@ -28,17 +27,14 @@ import { DataSpreadsheetBody } from './DataSpreadsheetBody';
|
|
28
27
|
import { DataSpreadsheetHeader } from './DataSpreadsheetHeader';
|
29
28
|
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
30
29
|
import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
|
31
|
-
import { useActiveElement } from '../../global/js/hooks';
|
32
|
-
import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
|
33
|
-
import { usePreviousValue } from '../../global/js/hooks';
|
30
|
+
import { useActiveElement, usePreviousValue } from '../../global/js/hooks';
|
34
31
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
35
|
-
import { useResetSpreadsheetFocus } from './hooks
|
36
|
-
import { useSpreadsheetOutsideClick } from './hooks/useSpreadsheetOutsideClick';
|
37
|
-
import { useMoveActiveCell } from './hooks/useMoveActiveCell';
|
32
|
+
import { useResetSpreadsheetFocus, useSpreadsheetOutsideClick, useMoveActiveCell, useMultipleKeyTracking } from './hooks';
|
38
33
|
import { createActiveCellFn } from './utils/createActiveCellFn';
|
39
34
|
import { getCellSize } from './utils/getCellSize';
|
40
|
-
import { handleMultipleKeys } from './utils/handleMultipleKeys';
|
41
|
-
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
35
|
+
import { handleMultipleKeys, includesShift } from './utils/handleMultipleKeys';
|
36
|
+
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
37
|
+
import { removeCellSelections } from './utils/removeCellSelections'; // cspell:words rowcount colcount
|
42
38
|
// The block part of our conventional BEM class names (blockClass__E--M).
|
43
39
|
|
44
40
|
var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
|
@@ -48,7 +44,10 @@ var defaults = {
|
|
48
44
|
cellSize: 'standard',
|
49
45
|
columns: Object.freeze([]),
|
50
46
|
data: Object.freeze([]),
|
51
|
-
|
47
|
+
defaultEmptyRowCount: 16,
|
48
|
+
onDataUpdate: Object.freeze(function () {}),
|
49
|
+
onActiveCellChange: Object.freeze(function () {}),
|
50
|
+
onSelectionAreaChange: Object.freeze(function () {})
|
52
51
|
};
|
53
52
|
/**
|
54
53
|
* DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
|
@@ -62,12 +61,18 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
62
61
|
columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
|
63
62
|
_ref$data = _ref.data,
|
64
63
|
data = _ref$data === void 0 ? defaults.data : _ref$data,
|
64
|
+
_ref$defaultEmptyRowC = _ref.defaultEmptyRowCount,
|
65
|
+
defaultEmptyRowCount = _ref$defaultEmptyRowC === void 0 ? defaults.defaultEmptyRowCount : _ref$defaultEmptyRowC,
|
65
66
|
_ref$onDataUpdate = _ref.onDataUpdate,
|
66
67
|
onDataUpdate = _ref$onDataUpdate === void 0 ? defaults.onDataUpdate : _ref$onDataUpdate,
|
67
68
|
id = _ref.id,
|
68
|
-
|
69
|
+
_ref$onActiveCellChan = _ref.onActiveCellChange,
|
70
|
+
onActiveCellChange = _ref$onActiveCellChan === void 0 ? defaults.onActiveCellChange : _ref$onActiveCellChan,
|
71
|
+
_ref$onSelectionAreaC = _ref.onSelectionAreaChange,
|
72
|
+
onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
|
69
73
|
rest = _objectWithoutProperties(_ref, _excluded);
|
70
74
|
|
75
|
+
var multiKeyTrackingRef = useRef();
|
71
76
|
var localRef = useRef();
|
72
77
|
var spreadsheetRef = ref || localRef;
|
73
78
|
var focusedElement = useActiveElement();
|
@@ -87,34 +92,45 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
87
92
|
selectionAreas = _useState6[0],
|
88
93
|
setSelectionAreas = _useState6[1];
|
89
94
|
|
90
|
-
var _useState7 = useState(
|
95
|
+
var _useState7 = useState([]),
|
91
96
|
_useState8 = _slicedToArray(_useState7, 2),
|
92
|
-
|
93
|
-
|
97
|
+
selectionAreaData = _useState8[0],
|
98
|
+
setSelectionAreaData = _useState8[1];
|
94
99
|
|
95
|
-
var _useState9 = useState(
|
100
|
+
var _useState9 = useState(false),
|
96
101
|
_useState10 = _slicedToArray(_useState9, 2),
|
97
|
-
|
98
|
-
|
102
|
+
clickAndHoldActive = _useState10[0],
|
103
|
+
setClickAndHoldActive = _useState10[1];
|
99
104
|
|
100
|
-
var _useState11 = useState(
|
105
|
+
var _useState11 = useState(''),
|
101
106
|
_useState12 = _slicedToArray(_useState11, 2),
|
102
|
-
|
103
|
-
|
107
|
+
currentMatcher = _useState12[0],
|
108
|
+
setCurrentMatcher = _useState12[1];
|
104
109
|
|
105
|
-
var _useState13 = useState(
|
110
|
+
var _useState13 = useState(false),
|
106
111
|
_useState14 = _slicedToArray(_useState13, 2),
|
107
|
-
|
108
|
-
|
112
|
+
isEditing = _useState14[0],
|
113
|
+
setIsEditing = _useState14[1];
|
114
|
+
|
115
|
+
var _useState15 = useState(''),
|
116
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
117
|
+
cellEditorValue = _useState16[0],
|
118
|
+
setCellEditorValue = _useState16[1];
|
109
119
|
|
110
120
|
var previousState = usePreviousValue({
|
111
|
-
activeCellCoordinates: activeCellCoordinates
|
121
|
+
activeCellCoordinates: activeCellCoordinates,
|
122
|
+
isEditing: isEditing
|
112
123
|
});
|
113
124
|
var cellSizeValue = getCellSize(cellSize);
|
114
125
|
var cellEditorRef = useRef();
|
115
|
-
|
116
|
-
var
|
126
|
+
|
127
|
+
var _useState17 = useState(),
|
128
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
129
|
+
activeCellContent = _useState18[0],
|
130
|
+
setActiveCellContent = _useState18[1];
|
131
|
+
|
117
132
|
var activeCellRef = useRef();
|
133
|
+
var cellEditorRulerRef = useRef();
|
118
134
|
var defaultColumn = useMemo(function () {
|
119
135
|
return {
|
120
136
|
width: 150,
|
@@ -122,6 +138,14 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
122
138
|
rowHeight: cellSizeValue
|
123
139
|
};
|
124
140
|
}, [cellSizeValue]);
|
141
|
+
|
142
|
+
var _useMultipleKeyTracki = useMultipleKeyTracking({
|
143
|
+
ref: multiKeyTrackingRef,
|
144
|
+
containerHasFocus: containerHasFocus,
|
145
|
+
isEditing: isEditing
|
146
|
+
}),
|
147
|
+
keysPressedList = _useMultipleKeyTracki.keysPressedList;
|
148
|
+
|
125
149
|
var scrollBarSize = useMemo(function () {
|
126
150
|
return getScrollbarWidth();
|
127
151
|
}, []);
|
@@ -162,23 +186,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
162
186
|
setCellEditorValue('');
|
163
187
|
setIsEditing(false);
|
164
188
|
cellEditorRef.current.style.display = 'none';
|
165
|
-
}, []); //
|
166
|
-
|
167
|
-
var removeCellSelections = useCallback(function (matcher) {
|
168
|
-
if (matcher && typeof matcher === 'string') {
|
169
|
-
var selectionToRemove = spreadsheetRef.current.querySelector("[data-matcher-id=\"".concat(matcher, "\"]"));
|
170
|
-
|
171
|
-
if (selectionToRemove) {
|
172
|
-
selectionToRemove.remove();
|
173
|
-
}
|
174
|
-
} else {
|
175
|
-
var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
|
176
|
-
|
177
|
-
_toConsumableArray(cellSelections).forEach(function (element) {
|
178
|
-
return element.remove();
|
179
|
-
});
|
180
|
-
}
|
181
|
-
}, [spreadsheetRef]); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
|
189
|
+
}, []); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
|
182
190
|
// happen if you click on another cell while isEditing is true
|
183
191
|
|
184
192
|
useEffect(function () {
|
@@ -188,11 +196,20 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
188
196
|
var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
|
189
197
|
removeCellEditor();
|
190
198
|
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
199
|
+
cellEditorRulerRef.current.textContent = '';
|
191
200
|
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
201
|
+
|
202
|
+
if ((prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) || (prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column)) {
|
203
|
+
if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
|
204
|
+
var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
205
|
+
setActiveCellContent(activeCellFullData.render('Cell'));
|
206
|
+
}
|
207
|
+
|
208
|
+
if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
209
|
+
setActiveCellContent(null);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor, activeCellContent]);
|
196
213
|
var createActiveCell = useCallback(function (_ref2) {
|
197
214
|
var placementElement = _ref2.placementElement,
|
198
215
|
coords = _ref2.coords,
|
@@ -218,7 +235,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
218
235
|
}
|
219
236
|
}, [spreadsheetRef, rows, onActiveCellChange, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, defaultColumn]);
|
220
237
|
useResetSpreadsheetFocus({
|
221
|
-
activeKeys: activeKeys,
|
222
238
|
focusedElement: focusedElement,
|
223
239
|
removeActiveCell: removeActiveCell,
|
224
240
|
setContainerHasFocus: setContainerHasFocus
|
@@ -230,7 +246,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
230
246
|
removeActiveCell: removeActiveCell,
|
231
247
|
removeCellSelections: removeCellSelections,
|
232
248
|
setContainerHasFocus: setContainerHasFocus,
|
233
|
-
activeKeys: activeKeys,
|
234
249
|
removeCellEditor: removeCellEditor
|
235
250
|
});
|
236
251
|
useMoveActiveCell({
|
@@ -270,10 +285,28 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
270
285
|
setCurrentMatcher(tempMatcher);
|
271
286
|
}
|
272
287
|
}, []);
|
288
|
+
var handleHomeEndKey = useCallback(function (_ref4) {
|
289
|
+
var type = _ref4.type;
|
290
|
+
|
291
|
+
var coordinatesClone = _objectSpread({}, activeCellCoordinates);
|
292
|
+
|
293
|
+
updateActiveCellCoordinates({
|
294
|
+
coords: coordinatesClone,
|
295
|
+
updatedValue: {
|
296
|
+
column: type === 'home' ? 0 : columns.length - 1
|
297
|
+
}
|
298
|
+
});
|
299
|
+
removeCellSelections({
|
300
|
+
spreadsheetRef: spreadsheetRef
|
301
|
+
});
|
302
|
+
}, [activeCellCoordinates, updateActiveCellCoordinates, spreadsheetRef, columns.length]);
|
273
303
|
var handleKeyPress = useCallback(function (event) {
|
274
|
-
var
|
304
|
+
var key = event.key;
|
305
|
+
|
306
|
+
if (isEditing) {
|
307
|
+
return;
|
308
|
+
} // Command keys need to be returned as there is default browser behavior with these keys
|
275
309
|
|
276
|
-
var key = event.key; // Command keys need to be returned as there is default browser behavior with these keys
|
277
310
|
|
278
311
|
if (key === 'Meta' || key === 'Control') {
|
279
312
|
return;
|
@@ -290,28 +323,20 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
290
323
|
|
291
324
|
|
292
325
|
if (['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1) {
|
293
|
-
if (
|
294
|
-
return;
|
295
|
-
}
|
296
|
-
|
297
|
-
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
|
326
|
+
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && keysPressedList.length < 2 && !includesShift(keysPressedList)) {
|
298
327
|
setSelectionAreas([]);
|
328
|
+
setSelectionAreaData([]);
|
299
329
|
removeCellSelections({
|
300
330
|
spreadsheetRef: spreadsheetRef
|
301
331
|
});
|
302
332
|
}
|
303
|
-
} // Update list of activeKeys
|
304
|
-
|
305
|
-
|
306
|
-
if (!((_activeKeys$current = activeKeys.current) !== null && _activeKeys$current !== void 0 && _activeKeys$current.includes(key))) {
|
307
|
-
var activeClone = _toConsumableArray(activeKeys.current);
|
308
|
-
|
309
|
-
activeKeys.current = [].concat(_toConsumableArray(activeClone), [key]);
|
310
333
|
}
|
311
334
|
|
312
|
-
if (
|
335
|
+
if (!isEditing && (keysPressedList === null || keysPressedList === void 0 ? void 0 : keysPressedList.length) > 1) {
|
313
336
|
handleMultipleKeys({
|
314
|
-
|
337
|
+
activeCellCoordinates: activeCellCoordinates,
|
338
|
+
event: event,
|
339
|
+
keysPressedList: keysPressedList,
|
315
340
|
selectionAreas: selectionAreas,
|
316
341
|
currentMatcher: currentMatcher,
|
317
342
|
rows: rows,
|
@@ -322,9 +347,26 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
322
347
|
// if one of the activeCellCoordinates is in a header position
|
323
348
|
|
324
349
|
|
325
|
-
if (!
|
350
|
+
if (keysPressedList.length < 2 && !includesShift(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
|
326
351
|
switch (key) {
|
352
|
+
// HOME
|
353
|
+
case 'Home':
|
354
|
+
{
|
355
|
+
handleHomeEndKey({
|
356
|
+
type: 'home'
|
357
|
+
});
|
358
|
+
break;
|
359
|
+
}
|
360
|
+
|
361
|
+
case 'End':
|
362
|
+
{
|
363
|
+
handleHomeEndKey({
|
364
|
+
type: 'end'
|
365
|
+
});
|
366
|
+
break;
|
367
|
+
}
|
327
368
|
// Tab
|
369
|
+
|
328
370
|
case 'Tab':
|
329
371
|
{
|
330
372
|
setSelectionAreas([]);
|
@@ -473,13 +515,35 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
473
515
|
}
|
474
516
|
}
|
475
517
|
}
|
476
|
-
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor,
|
518
|
+
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList]);
|
477
519
|
|
478
520
|
var startEditMode = function startEditMode() {
|
479
521
|
setIsEditing(true);
|
480
522
|
var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
481
523
|
var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
482
524
|
setCellEditorValue(activeCellValue);
|
525
|
+
cellEditorRulerRef.current.textContent = activeCellValue;
|
526
|
+
}; // Sets the initial placement of the cell editor cursor at the end of the text area
|
527
|
+
// this is not done for us by default in Safari
|
528
|
+
|
529
|
+
|
530
|
+
useEffect(function () {
|
531
|
+
if (isEditing && !(previousState !== null && previousState !== void 0 && previousState.isEditing)) {
|
532
|
+
cellEditorRef.current.setSelectionRange(cellEditorRulerRef.current.textContent.length, cellEditorRulerRef.current.textContent.length);
|
533
|
+
cellEditorRef.current.focus();
|
534
|
+
}
|
535
|
+
}, [isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing]);
|
536
|
+
|
537
|
+
var handleActiveCellClick = function handleActiveCellClick() {
|
538
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
539
|
+
var indexValue = (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column : activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
540
|
+
handleRowColumnHeaderClick({
|
541
|
+
isKeyboard: false,
|
542
|
+
index: indexValue
|
543
|
+
});
|
544
|
+
}
|
545
|
+
|
546
|
+
return;
|
483
547
|
}; // Go into edit mode if 'Enter' key is pressed on activeCellRef
|
484
548
|
|
485
549
|
|
@@ -492,41 +556,51 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
492
556
|
}
|
493
557
|
|
494
558
|
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
495
|
-
|
496
|
-
activeCellCoordinates: activeCellCoordinates,
|
497
|
-
rows: rows,
|
498
|
-
columns: columns,
|
499
|
-
setActiveCellCoordinates: setActiveCellCoordinates,
|
500
|
-
setCurrentMatcher: setCurrentMatcher,
|
501
|
-
setSelectionAreas: setSelectionAreas,
|
502
|
-
spreadsheetRef: spreadsheetRef,
|
559
|
+
handleRowColumnHeaderClick({
|
503
560
|
isKeyboard: true
|
504
|
-
};
|
505
|
-
|
506
|
-
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
507
|
-
handleHeaderCellSelection(_objectSpread({
|
508
|
-
type: 'column'
|
509
|
-
}, handleHeaderCellProps));
|
510
|
-
} // Select an entire row
|
511
|
-
|
512
|
-
|
513
|
-
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
514
|
-
handleHeaderCellSelection(_objectSpread({
|
515
|
-
type: 'row'
|
516
|
-
}, handleHeaderCellProps));
|
517
|
-
}
|
561
|
+
});
|
518
562
|
}
|
519
563
|
}
|
564
|
+
};
|
565
|
+
|
566
|
+
var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref5) {
|
567
|
+
var isKeyboard = _ref5.isKeyboard,
|
568
|
+
_ref5$index = _ref5.index,
|
569
|
+
index = _ref5$index === void 0 ? null : _ref5$index;
|
570
|
+
var handleHeaderCellProps = {
|
571
|
+
activeCellCoordinates: activeCellCoordinates,
|
572
|
+
rows: rows,
|
573
|
+
columns: columns,
|
574
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
575
|
+
setCurrentMatcher: setCurrentMatcher,
|
576
|
+
setSelectionAreas: setSelectionAreas,
|
577
|
+
spreadsheetRef: spreadsheetRef,
|
578
|
+
isKeyboard: isKeyboard,
|
579
|
+
setSelectionAreaData: setSelectionAreaData,
|
580
|
+
index: index
|
581
|
+
}; // Select an entire column
|
582
|
+
|
583
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
584
|
+
handleHeaderCellSelection(_objectSpread({
|
585
|
+
type: 'column'
|
586
|
+
}, handleHeaderCellProps));
|
587
|
+
} // Select an entire row
|
588
|
+
|
589
|
+
|
590
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
591
|
+
handleHeaderCellSelection(_objectSpread({
|
592
|
+
type: 'row'
|
593
|
+
}, handleHeaderCellProps));
|
594
|
+
}
|
520
595
|
}; // Go into edit mode if double click is detected on activeCellRef
|
521
596
|
|
522
597
|
|
523
598
|
var handleActiveCellDoubleClick = function handleActiveCellDoubleClick() {
|
524
599
|
startEditMode();
|
525
|
-
};
|
526
|
-
|
600
|
+
};
|
527
601
|
|
528
|
-
var
|
529
|
-
var
|
602
|
+
var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref6) {
|
603
|
+
var type = _ref6.type;
|
530
604
|
|
531
605
|
var submitEditChanges = function submitEditChanges() {
|
532
606
|
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
|
@@ -535,8 +609,33 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
535
609
|
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
536
610
|
};
|
537
611
|
|
612
|
+
removeCellSelections({
|
613
|
+
spreadsheetRef: spreadsheetRef
|
614
|
+
});
|
615
|
+
submitEditChanges();
|
616
|
+
var tempMatcher = uuidv4();
|
617
|
+
var newSelectionArea = {
|
618
|
+
row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
|
619
|
+
column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
|
620
|
+
};
|
621
|
+
setSelectionAreas([{
|
622
|
+
point1: newSelectionArea,
|
623
|
+
point2: newSelectionArea,
|
624
|
+
matcher: tempMatcher,
|
625
|
+
areaCreated: false
|
626
|
+
}]);
|
627
|
+
setCurrentMatcher(tempMatcher);
|
628
|
+
cellEditorRulerRef.current.textContent = '';
|
629
|
+
}; // Update the data
|
630
|
+
|
631
|
+
|
632
|
+
var handleEditSubmit = function handleEditSubmit(event) {
|
633
|
+
var key = event.key;
|
634
|
+
|
538
635
|
if (key === 'Enter') {
|
539
|
-
|
636
|
+
updateSelectionAreaOnCellEditSubmit({
|
637
|
+
type: 'Enter'
|
638
|
+
});
|
540
639
|
setActiveCellCoordinates(function (prev) {
|
541
640
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
542
641
|
row: prev.row === rows.length - 1 ? prev.row : prev.row + 1 // do not move to next cell below if we're already in the last row
|
@@ -547,7 +646,9 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
547
646
|
|
548
647
|
if (key === 'Tab') {
|
549
648
|
event.preventDefault();
|
550
|
-
|
649
|
+
updateSelectionAreaOnCellEditSubmit({
|
650
|
+
type: 'Tab'
|
651
|
+
});
|
551
652
|
setActiveCellCoordinates(function (prev) {
|
552
653
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
553
654
|
column: prev.column === columns.length - 1 ? prev.column : prev.column + 1 // do not move to next cell below if we're already in the last column
|
@@ -557,44 +658,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
557
658
|
}
|
558
659
|
|
559
660
|
return;
|
560
|
-
};
|
561
|
-
// Find point object that matches currentMatcher and remove the second point
|
562
|
-
// because hovering over the active cell while clicking and holding should
|
563
|
-
// remove the previously existing selection area
|
564
|
-
|
565
|
-
|
566
|
-
var handleActiveCellMouseEnterCallback = useCallback(function (areas, clickHold) {
|
567
|
-
var freshMatcherValue = currentMatcherRef.current;
|
568
|
-
|
569
|
-
if (!freshMatcherValue) {
|
570
|
-
return;
|
571
|
-
}
|
572
|
-
|
573
|
-
if (areas && areas.length && clickHold && freshMatcherValue) {
|
574
|
-
setSelectionAreas(function (prev) {
|
575
|
-
var selectionAreaClone = deepCloneObject(prev);
|
576
|
-
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
577
|
-
return item.matcher === freshMatcherValue;
|
578
|
-
});
|
579
|
-
|
580
|
-
if (indexOfItemToUpdate === -1) {
|
581
|
-
return prev;
|
582
|
-
}
|
583
|
-
|
584
|
-
if (_typeof(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
|
585
|
-
selectionAreaClone[indexOfItemToUpdate].point2 = null;
|
586
|
-
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
587
|
-
removeCellSelections({
|
588
|
-
matcher: freshMatcherValue,
|
589
|
-
spreadsheetRef: spreadsheetRef
|
590
|
-
});
|
591
|
-
return selectionAreaClone;
|
592
|
-
}
|
661
|
+
};
|
593
662
|
|
594
|
-
return prev;
|
595
|
-
});
|
596
|
-
}
|
597
|
-
}, [spreadsheetRef, removeCellSelections]);
|
598
663
|
useEffect(function () {
|
599
664
|
if (isEditing) {
|
600
665
|
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
@@ -607,58 +672,70 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
607
672
|
cellEditorRef.current.style.display = 'block';
|
608
673
|
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
609
674
|
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
610
|
-
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
675
|
+
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
|
611
676
|
|
612
677
|
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';
|
613
678
|
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
679
|
+
var rulerWidth = cellEditorRulerRef.current.offsetWidth;
|
680
|
+
var cellWidth = activeCellRef.current.offsetWidth;
|
681
|
+
|
682
|
+
if (rulerWidth >= cellWidth) {
|
683
|
+
var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
|
684
|
+
var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
|
685
|
+
var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
686
|
+
var totalColumns = columns.length;
|
687
|
+
var totalRows = rows.length;
|
688
|
+
var totalMultiplierPossible = totalColumns - startingColumnPosition;
|
689
|
+
var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
|
690
|
+
cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
|
691
|
+
cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
|
692
|
+
cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
|
693
|
+
// Cell editor has reached max height, we need to add the scrolling back.
|
694
|
+
// We also need to subtract 1 to account for the fact that the cell editor
|
695
|
+
// is placed one pixel below the cell being edited to account for the border
|
696
|
+
|
697
|
+
if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
|
698
|
+
cellEditorRef.current.style.overflow = 'auto';
|
699
|
+
} else {
|
700
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
701
|
+
}
|
702
|
+
}
|
614
703
|
}
|
615
704
|
|
616
705
|
if (!isEditing) {
|
706
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
617
707
|
cellEditorRef.current.style.display = 'none';
|
618
708
|
cellEditorRef.current.blur();
|
619
709
|
activeCellRef.current.focus();
|
620
710
|
}
|
621
|
-
}, [isEditing, activeCellCoordinates, rows]);
|
622
|
-
|
623
|
-
var handleKeyUp = function handleKeyUp(event) {
|
624
|
-
var _activeKeys$current3;
|
625
|
-
|
626
|
-
var key = event.key; // Remove key from active keys array on key up
|
627
|
-
|
628
|
-
if ((_activeKeys$current3 = activeKeys.current) !== null && _activeKeys$current3 !== void 0 && _activeKeys$current3.includes(key)) {
|
629
|
-
var activeKeysClone = _toConsumableArray(activeKeys.current);
|
630
|
-
|
631
|
-
var filteredKeysClone = activeKeysClone.filter(function (item) {
|
632
|
-
return item !== key;
|
633
|
-
});
|
634
|
-
activeKeys.current = filteredKeysClone;
|
635
|
-
}
|
636
|
-
};
|
637
|
-
|
711
|
+
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
|
638
712
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
|
639
|
-
className: cx(blockClass, className, _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
|
713
|
+
className: cx(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
|
640
714
|
ref: spreadsheetRef,
|
641
715
|
role: "grid",
|
642
716
|
tabIndex: 0,
|
643
717
|
"aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
|
644
718
|
"aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
|
645
719
|
onKeyDown: handleKeyPress,
|
646
|
-
onKeyUp: handleKeyUp,
|
647
720
|
onFocus: function onFocus() {
|
648
721
|
return setContainerHasFocus(true);
|
649
722
|
}
|
650
|
-
}), /*#__PURE__*/React.createElement(
|
723
|
+
}), /*#__PURE__*/React.createElement("div", {
|
724
|
+
ref: multiKeyTrackingRef
|
725
|
+
}, /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
|
651
726
|
ref: spreadsheetRef,
|
652
727
|
activeCellCoordinates: activeCellCoordinates,
|
653
|
-
|
728
|
+
cellSize: cellSize,
|
654
729
|
columns: columns,
|
655
730
|
defaultColumn: defaultColumn,
|
656
731
|
headerGroups: headerGroups,
|
657
732
|
rows: rows,
|
733
|
+
scrollBarSize: scrollBarSize,
|
658
734
|
selectionAreas: selectionAreas,
|
659
735
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
660
736
|
setSelectionAreas: setSelectionAreas,
|
661
|
-
setCurrentMatcher: setCurrentMatcher
|
737
|
+
setCurrentMatcher: setCurrentMatcher,
|
738
|
+
setSelectionAreaData: setSelectionAreaData
|
662
739
|
}), /*#__PURE__*/React.createElement(DataSpreadsheetBody, {
|
663
740
|
activeCellCoordinates: activeCellCoordinates,
|
664
741
|
ref: spreadsheetRef,
|
@@ -670,34 +747,45 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
670
747
|
selectionAreas: selectionAreas,
|
671
748
|
setSelectionAreas: setSelectionAreas,
|
672
749
|
cellSize: cellSize,
|
750
|
+
headerGroups: headerGroups,
|
673
751
|
defaultColumn: defaultColumn,
|
674
752
|
getTableBodyProps: getTableBodyProps,
|
753
|
+
onDataUpdate: onDataUpdate,
|
675
754
|
onActiveCellChange: onActiveCellChange,
|
755
|
+
onSelectionAreaChange: onSelectionAreaChange,
|
676
756
|
prepareRow: prepareRow,
|
677
757
|
rows: rows,
|
758
|
+
selectionAreaData: selectionAreaData,
|
759
|
+
setSelectionAreaData: setSelectionAreaData,
|
678
760
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
679
761
|
scrollBarSize: scrollBarSize,
|
680
762
|
totalColumnsWidth: totalColumnsWidth,
|
681
763
|
id: id,
|
682
|
-
columns: columns
|
764
|
+
columns: columns,
|
765
|
+
defaultEmptyRowCount: defaultEmptyRowCount
|
683
766
|
}), /*#__PURE__*/React.createElement("button", {
|
767
|
+
onClick: handleActiveCellClick,
|
684
768
|
onKeyDown: handleActiveCellKeyDown,
|
685
|
-
onMouseEnter: handleActiveCellMouseEnter,
|
686
769
|
onDoubleClick: handleActiveCellDoubleClick,
|
687
770
|
ref: activeCellRef,
|
688
771
|
className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
|
689
772
|
type: "button"
|
690
|
-
}), /*#__PURE__*/React.createElement(TextArea, {
|
773
|
+
}, activeCellContent), /*#__PURE__*/React.createElement(TextArea, {
|
691
774
|
value: cellEditorValue,
|
692
775
|
onKeyDown: handleEditSubmit,
|
693
776
|
onChange: function onChange(event) {
|
694
|
-
|
777
|
+
setCellEditorValue(event.target.value);
|
778
|
+
cellEditorRulerRef.current.textContent = event.target.value;
|
695
779
|
},
|
696
780
|
ref: cellEditorRef,
|
697
781
|
labelText: "",
|
698
782
|
"aria-labelledby": activeCellCoordinates ? "[data-row-index=\"".concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, "\"][data-column-index=\"").concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column, "\"]") : null,
|
699
783
|
className: cx("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), _defineProperty({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
|
700
|
-
})
|
784
|
+
}), /*#__PURE__*/React.createElement("pre", {
|
785
|
+
"aria-hidden": true,
|
786
|
+
ref: cellEditorRulerRef,
|
787
|
+
className: "".concat(blockClass, "__cell-editor-ruler")
|
788
|
+
})));
|
701
789
|
}); // Return a placeholder if not released and not enabled by feature flag
|
702
790
|
|
703
791
|
DataSpreadsheet = pkg.checkComponentEnabled(DataSpreadsheet, componentName); // The display name of the component, used by React. Note that displayName
|
@@ -733,6 +821,11 @@ DataSpreadsheet.propTypes = {
|
|
733
821
|
*/
|
734
822
|
data: PropTypes.arrayOf(PropTypes.shape),
|
735
823
|
|
824
|
+
/**
|
825
|
+
* Sets the number of empty rows to be created when there is no data provided
|
826
|
+
*/
|
827
|
+
defaultEmptyRowCount: PropTypes.number,
|
828
|
+
|
736
829
|
/**
|
737
830
|
* The spreadsheet id
|
738
831
|
*/
|
@@ -746,7 +839,12 @@ DataSpreadsheet.propTypes = {
|
|
746
839
|
/**
|
747
840
|
* The setter fn for the data prop
|
748
841
|
*/
|
749
|
-
onDataUpdate: PropTypes.func
|
842
|
+
onDataUpdate: PropTypes.func,
|
843
|
+
|
844
|
+
/**
|
845
|
+
* The event handler that is called when the selection area values change
|
846
|
+
*/
|
847
|
+
onSelectionAreaChange: PropTypes.func
|
750
848
|
/* TODO: add types and DocGen for all props. */
|
751
849
|
|
752
850
|
};
|