@carbon/ibm-products 1.13.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +268 -0
- package/css/components/Datagrid/styles/datagrid.css.map +1 -0
- package/css/components/Datagrid/styles/index.css +513 -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 +611 -10
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +3 -3
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +7 -4
- 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 +611 -10
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +3 -3
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +611 -10
- package/css/index.css.map +1 -1
- package/css/index.min.css +3 -3
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +106 -43
- package/es/components/AddSelect/AddSelectFilter.js +172 -0
- package/es/components/AddSelect/add-select-utils.js +30 -0
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +255 -175
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +78 -17
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +65 -20
- 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 +1 -3
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
- package/es/components/DataSpreadsheet/utils/generateData.js +17 -9
- package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
- package/es/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +30 -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 +60 -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/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 +13 -6
- package/es/components/Tearsheet/TearsheetShell.js +34 -10
- package/es/components/index.js +2 -1
- package/es/global/js/package-settings.js +4 -2
- package/lib/components/AddSelect/AddSelect.js +105 -41
- package/lib/components/AddSelect/AddSelectFilter.js +190 -0
- package/lib/components/AddSelect/add-select-utils.js +35 -2
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +261 -177
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +79 -23
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +67 -21
- 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 +1 -3
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
- package/lib/components/DataSpreadsheet/utils/generateData.js +17 -9
- package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
- package/lib/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +40 -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 +68 -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/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 +13 -6
- package/lib/components/Tearsheet/TearsheetShell.js +36 -10
- package/lib/components/index.js +9 -1
- package/lib/global/js/package-settings.js +4 -2
- package/package.json +16 -12
- package/scss/components/AboutModal/_about-modal.scss +4 -0
- package/scss/components/AddSelect/_add-select.scss +46 -2
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +41 -4
- 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 +326 -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/Tearsheet/_tearsheet.scss +4 -0
- package/scss/components/_index.scss +1 -0
|
@@ -2,6 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
4
|
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
* Copyright IBM Corp. 2022, 2022
|
|
7
11
|
*
|
|
@@ -21,6 +25,7 @@ import { removeCellSelections } from './utils/removeCellSelections';
|
|
|
21
25
|
import { createCellSelectionArea } from './utils/createCellSelectionArea';
|
|
22
26
|
import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
|
|
23
27
|
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
|
28
|
+
import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth';
|
|
24
29
|
var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
|
|
25
30
|
export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
26
31
|
var columns = _ref.columns,
|
|
@@ -45,7 +50,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
45
50
|
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
|
46
51
|
currentMatcher = _ref.currentMatcher,
|
|
47
52
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
|
48
|
-
onSelectionAreaChange = _ref.onSelectionAreaChange
|
|
53
|
+
onSelectionAreaChange = _ref.onSelectionAreaChange,
|
|
54
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea,
|
|
55
|
+
totalVisibleColumns = _ref.totalVisibleColumns;
|
|
56
|
+
var contentScrollRef = useRef();
|
|
49
57
|
var previousState = usePreviousValue({
|
|
50
58
|
selectionAreaData: selectionAreaData,
|
|
51
59
|
clickAndHoldActive: clickAndHoldActive
|
|
@@ -103,18 +111,20 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
103
111
|
|
|
104
112
|
if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
|
|
105
113
|
createCellSelectionArea({
|
|
114
|
+
ref: ref,
|
|
106
115
|
area: area,
|
|
107
116
|
blockClass: blockClass,
|
|
108
117
|
defaultColumn: defaultColumn,
|
|
109
118
|
selectionAreas: selectionAreas,
|
|
110
|
-
setSelectionAreas: setSelectionAreas
|
|
119
|
+
setSelectionAreas: setSelectionAreas,
|
|
120
|
+
setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
|
|
111
121
|
});
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
return;
|
|
115
125
|
});
|
|
116
126
|
}
|
|
117
|
-
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
|
|
127
|
+
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
|
|
118
128
|
|
|
119
129
|
var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
|
|
120
130
|
var rowStart = _ref2.rowStart,
|
|
@@ -192,6 +202,9 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
192
202
|
// meaning that selectionAreas should only have one item by default
|
|
193
203
|
|
|
194
204
|
if (isHoldingCommandKey) {
|
|
205
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
|
206
|
+
activeCellElement.setAttribute('data-selection-id', tempMatcher);
|
|
207
|
+
setActiveCellInsideSelectionArea(true);
|
|
195
208
|
setActiveCellCoordinates(activeCoordinates);
|
|
196
209
|
setCurrentMatcher(tempMatcher);
|
|
197
210
|
setSelectionAreas(function (prev) {
|
|
@@ -222,6 +235,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
222
235
|
setSelectionAreas(selectionAreaClone);
|
|
223
236
|
}
|
|
224
237
|
} else {
|
|
238
|
+
setActiveCellInsideSelectionArea(false);
|
|
225
239
|
setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
|
|
226
240
|
|
|
227
241
|
removeCellSelections({
|
|
@@ -235,7 +249,22 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
235
249
|
setSelectionAreaData([]);
|
|
236
250
|
}
|
|
237
251
|
};
|
|
238
|
-
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
|
|
252
|
+
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
|
|
253
|
+
|
|
254
|
+
var handleBodyScroll = function handleBodyScroll() {
|
|
255
|
+
var headerRowElement = ref.current.querySelector("\n .".concat(blockClass, "__header--container .").concat(blockClass, "__tr"));
|
|
256
|
+
headerRowElement.scrollLeft = contentScrollRef.current.scrollLeft;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
useEffect(function () {
|
|
260
|
+
contentScrollRef.current.addEventListener('scroll', function (event) {
|
|
261
|
+
return handleBodyScroll(event);
|
|
262
|
+
});
|
|
263
|
+
var contentScrollElementRef = contentScrollRef.current;
|
|
264
|
+
return function () {
|
|
265
|
+
contentScrollElementRef.removeEventListener('scroll', handleBodyScroll);
|
|
266
|
+
};
|
|
267
|
+
});
|
|
239
268
|
var handleBodyCellHover = useCallback(function (cell, columnIndex) {
|
|
240
269
|
return function () {
|
|
241
270
|
if (clickAndHoldActive) {
|
|
@@ -268,7 +297,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
268
297
|
};
|
|
269
298
|
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
|
|
270
299
|
var handleRowHeaderClick = useCallback(function (index) {
|
|
271
|
-
return function () {
|
|
300
|
+
return function (event) {
|
|
301
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
|
272
302
|
handleHeaderCellSelection({
|
|
273
303
|
type: 'row',
|
|
274
304
|
activeCellCoordinates: activeCellCoordinates,
|
|
@@ -279,7 +309,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
279
309
|
setSelectionAreas: setSelectionAreas,
|
|
280
310
|
spreadsheetRef: ref,
|
|
281
311
|
index: index,
|
|
282
|
-
setSelectionAreaData: setSelectionAreaData
|
|
312
|
+
setSelectionAreaData: setSelectionAreaData,
|
|
313
|
+
isHoldingCommandKey: isHoldingCommandKey
|
|
283
314
|
});
|
|
284
315
|
};
|
|
285
316
|
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
|
|
@@ -323,8 +354,13 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
323
354
|
style: style
|
|
324
355
|
}), {
|
|
325
356
|
className: cx("".concat(blockClass, "__tr")),
|
|
326
|
-
"data-row-index": index
|
|
327
|
-
|
|
357
|
+
"data-row-index": index,
|
|
358
|
+
"aria-rowindex": index + 1
|
|
359
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
360
|
+
role: "rowheader",
|
|
361
|
+
className: "".concat(blockClass, "__td-th--cell-container")
|
|
362
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
363
|
+
id: "".concat(blockClass, "__cell--").concat(index, "--header"),
|
|
328
364
|
tabIndex: -1,
|
|
329
365
|
"data-row-index": index,
|
|
330
366
|
"data-column-index": "header",
|
|
@@ -334,22 +370,30 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
334
370
|
style: {
|
|
335
371
|
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
|
336
372
|
}
|
|
337
|
-
}, index + 1), row.cells.map(function (cell, index) {
|
|
338
|
-
return /*#__PURE__*/React.createElement("
|
|
373
|
+
}, index + 1)), row.cells.map(function (cell, index) {
|
|
374
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
375
|
+
key: "cell_".concat(index),
|
|
376
|
+
"aria-colindex": index + 1
|
|
377
|
+
}, cell.getCellProps(), {
|
|
378
|
+
role: "gridcell",
|
|
379
|
+
style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
|
|
380
|
+
display: 'grid',
|
|
381
|
+
minWidth: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width
|
|
382
|
+
})
|
|
383
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
384
|
+
id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
|
|
339
385
|
tabIndex: -1,
|
|
340
386
|
"data-row-index": cell.row.index,
|
|
341
|
-
"data-column-index": index
|
|
342
|
-
}, cell.getCellProps(), {
|
|
387
|
+
"data-column-index": index,
|
|
343
388
|
className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
|
|
344
|
-
key: "cell_".concat(index),
|
|
345
389
|
onMouseDown: handleBodyCellClick(cell, index),
|
|
346
390
|
onMouseOver: handleBodyCellHover(cell, index),
|
|
347
391
|
onFocus: function onFocus() {},
|
|
348
392
|
type: "button"
|
|
349
|
-
}
|
|
393
|
+
}, cell.render('Cell')));
|
|
350
394
|
}));
|
|
351
395
|
}
|
|
352
|
-
}, [prepareRow, rows,
|
|
396
|
+
}, [prepareRow, rows, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover, defaultColumn]);
|
|
353
397
|
var spreadsheetBodyRef = useRef();
|
|
354
398
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
355
399
|
ref: spreadsheetBodyRef,
|
|
@@ -359,7 +403,13 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
359
403
|
height: 400,
|
|
360
404
|
itemCount: rows.length || defaultEmptyRowCount,
|
|
361
405
|
itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
|
362
|
-
width:
|
|
406
|
+
width: getSpreadsheetWidth({
|
|
407
|
+
scrollBarSizeValue: scrollBarSize,
|
|
408
|
+
totalVisibleColumns: totalVisibleColumns,
|
|
409
|
+
defaultColumn: defaultColumn,
|
|
410
|
+
totalColumnsWidth: totalColumnsWidth
|
|
411
|
+
}),
|
|
412
|
+
outerRef: contentScrollRef
|
|
363
413
|
}, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
|
|
364
414
|
});
|
|
365
415
|
DataSpreadsheetBody.propTypes = {
|
|
@@ -460,6 +510,11 @@ DataSpreadsheetBody.propTypes = {
|
|
|
460
510
|
*/
|
|
461
511
|
setActiveCellCoordinates: PropTypes.func,
|
|
462
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Setter fn for active cell inside of selection area
|
|
515
|
+
*/
|
|
516
|
+
setActiveCellInsideSelectionArea: PropTypes.func,
|
|
517
|
+
|
|
463
518
|
/**
|
|
464
519
|
* Setter fn for clickAndHold state value
|
|
465
520
|
*/
|
|
@@ -488,5 +543,11 @@ DataSpreadsheetBody.propTypes = {
|
|
|
488
543
|
/**
|
|
489
544
|
* The total columns width
|
|
490
545
|
*/
|
|
491
|
-
totalColumnsWidth: PropTypes.number
|
|
546
|
+
totalColumnsWidth: PropTypes.number,
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* The total number of columns to be initially visible, additional columns will be rendered and
|
|
550
|
+
* visible via horizontal scrollbar
|
|
551
|
+
*/
|
|
552
|
+
totalVisibleColumns: PropTypes.number
|
|
492
553
|
};
|
|
@@ -15,11 +15,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
15
15
|
import React, { forwardRef, useEffect, useState } from 'react';
|
|
16
16
|
import PropTypes from 'prop-types';
|
|
17
17
|
import cx from 'classnames';
|
|
18
|
-
import { px } from '@carbon/layout';
|
|
19
18
|
import { pkg } from '../../settings';
|
|
19
|
+
import { usePreviousValue } from '../../global/js/hooks';
|
|
20
20
|
import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
|
|
21
21
|
import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
|
|
22
|
-
import {
|
|
22
|
+
import { selectAllCells } from './utils/selectAllCells';
|
|
23
|
+
import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth';
|
|
23
24
|
var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
|
|
24
25
|
export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
25
26
|
var activeCellCoordinates = _ref.activeCellCoordinates,
|
|
@@ -33,7 +34,9 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
|
33
34
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
|
34
35
|
setSelectionAreas = _ref.setSelectionAreas,
|
|
35
36
|
setSelectionAreaData = _ref.setSelectionAreaData,
|
|
36
|
-
rows = _ref.rows
|
|
37
|
+
rows = _ref.rows,
|
|
38
|
+
totalVisibleColumns = _ref.totalVisibleColumns,
|
|
39
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
|
37
40
|
|
|
38
41
|
var _useState = useState(0),
|
|
39
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -55,7 +58,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
|
55
58
|
}, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
|
|
56
59
|
|
|
57
60
|
var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
|
|
58
|
-
return function () {
|
|
61
|
+
return function (event) {
|
|
62
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
|
59
63
|
handleHeaderCellSelection({
|
|
60
64
|
type: 'column',
|
|
61
65
|
activeCellCoordinates: activeCellCoordinates,
|
|
@@ -66,45 +70,75 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
|
66
70
|
setSelectionAreas: setSelectionAreas,
|
|
67
71
|
spreadsheetRef: ref,
|
|
68
72
|
index: index,
|
|
69
|
-
setSelectionAreaData: setSelectionAreaData
|
|
73
|
+
setSelectionAreaData: setSelectionAreaData,
|
|
74
|
+
isHoldingCommandKey: isHoldingCommandKey
|
|
70
75
|
});
|
|
71
76
|
};
|
|
72
77
|
};
|
|
73
78
|
|
|
79
|
+
var handleSelectAllClick = function handleSelectAllClick() {
|
|
80
|
+
selectAllCells({
|
|
81
|
+
ref: ref,
|
|
82
|
+
setCurrentMatcher: setCurrentMatcher,
|
|
83
|
+
setSelectionAreas: setSelectionAreas,
|
|
84
|
+
rows: rows,
|
|
85
|
+
columns: columns,
|
|
86
|
+
activeCellCoordinates: activeCellCoordinates,
|
|
87
|
+
updateActiveCellCoordinates: updateActiveCellCoordinates
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
74
91
|
return /*#__PURE__*/React.createElement("div", {
|
|
75
|
-
className: cx("".concat(blockClass, "__header--container"))
|
|
92
|
+
className: cx("".concat(blockClass, "__header--container")),
|
|
93
|
+
role: "rowgroup"
|
|
76
94
|
}, headerGroups.map(function (headerGroup, index) {
|
|
77
95
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
78
96
|
key: "header_".concat(index)
|
|
79
97
|
}, headerGroup.getHeaderGroupProps(), {
|
|
80
98
|
style: _objectSpread(_objectSpread({}, headerGroup.getHeaderGroupProps().style), {}, {
|
|
81
|
-
width:
|
|
99
|
+
width: getSpreadsheetWidth({
|
|
100
|
+
type: 'header',
|
|
101
|
+
headerGroup: headerGroup,
|
|
102
|
+
scrollBarSizeValue: scrollBarSizeValue,
|
|
103
|
+
totalVisibleColumns: totalVisibleColumns,
|
|
104
|
+
defaultColumn: defaultColumn
|
|
105
|
+
}),
|
|
106
|
+
overflow: 'hidden'
|
|
82
107
|
}),
|
|
83
108
|
className: "".concat(blockClass, "__tr")
|
|
84
|
-
}), /*#__PURE__*/React.createElement("
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
type: "button",
|
|
88
|
-
tabIndex: -1,
|
|
89
|
-
className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header')),
|
|
109
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
110
|
+
role: "columnheader",
|
|
111
|
+
className: "".concat(blockClass, "__select-all-cell-container"),
|
|
90
112
|
style: {
|
|
91
113
|
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
|
|
92
114
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
|
93
115
|
}
|
|
94
|
-
}, "
|
|
95
|
-
|
|
116
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
117
|
+
id: "".concat(blockClass, "__cell--header--header"),
|
|
118
|
+
"data-row-index": "header",
|
|
119
|
+
"data-column-index": "header",
|
|
120
|
+
type: "button",
|
|
121
|
+
tabIndex: -1,
|
|
122
|
+
onClick: handleSelectAllClick,
|
|
123
|
+
className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header'))
|
|
124
|
+
}, "\xA0")), headerGroup.headers.map(function (column, index) {
|
|
125
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
96
126
|
key: "column_".concat(index),
|
|
127
|
+
role: "columnheader",
|
|
128
|
+
className: "".concat(blockClass, "__columnheader")
|
|
129
|
+
}, column.getHeaderProps()), /*#__PURE__*/React.createElement("button", {
|
|
130
|
+
id: "".concat(blockClass, "__cell--header--").concat(index),
|
|
97
131
|
"data-row-index": "header",
|
|
98
132
|
"data-column-index": index,
|
|
99
133
|
tabIndex: -1,
|
|
100
134
|
onClick: handleColumnHeaderClick(index),
|
|
101
135
|
style: {
|
|
102
|
-
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
|
103
|
-
|
|
104
|
-
|
|
136
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
|
137
|
+
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width
|
|
138
|
+
},
|
|
105
139
|
className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || checkActiveHeaderCell(index, selectionAreas, 'column'))),
|
|
106
140
|
type: "button"
|
|
107
|
-
}
|
|
141
|
+
}, column.render('Header')));
|
|
108
142
|
}));
|
|
109
143
|
}));
|
|
110
144
|
});
|
|
@@ -174,5 +208,16 @@ DataSpreadsheetHeader.propTypes = {
|
|
|
174
208
|
/**
|
|
175
209
|
* Setter fn for selectionAreas value
|
|
176
210
|
*/
|
|
177
|
-
setSelectionAreas: PropTypes.func
|
|
211
|
+
setSelectionAreas: PropTypes.func,
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The total number of columns to be initially visible, additional columns will be rendered and
|
|
215
|
+
* visible via horizontal scrollbar
|
|
216
|
+
*/
|
|
217
|
+
totalVisibleColumns: PropTypes.number,
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Function used to update the active cell coordinates
|
|
221
|
+
*/
|
|
222
|
+
updateActiveCellCoordinates: PropTypes.func
|
|
178
223
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2022, 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export { useMoveActiveCell } from './useMoveActiveCell';
|
|
8
|
+
export { useMultipleKeyTracking } from './useMultipleKeyTracking';
|
|
9
|
+
export { useResetSpreadsheetFocus } from './useResetSpreadsheetFocus';
|
|
10
|
+
export { useSpreadsheetOutsideClick } from './useSpreadsheetOutsideClick';
|
|
11
|
+
export { useSpreadsheetEdit } from './useSpreadsheetEdit';
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright IBM Corp. 2022, 2022
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useState } from 'react';
|
|
11
|
+
import { usePreviousValue } from '../../../global/js/hooks';
|
|
12
|
+
import { includesResourceKey } from '../utils/handleMultipleKeys';
|
|
13
|
+
|
|
14
|
+
var hasFocus = function hasFocus() {
|
|
15
|
+
return typeof document !== 'undefined' && document.hasFocus();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
|
19
|
+
var ref = _ref.ref,
|
|
20
|
+
containerHasFocus = _ref.containerHasFocus,
|
|
21
|
+
isEditing = _ref.isEditing;
|
|
22
|
+
|
|
23
|
+
var _useState = useState(''),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
usingMac = _useState2[0],
|
|
26
|
+
setUsingMac = _useState2[1];
|
|
27
|
+
|
|
28
|
+
var _useState3 = useState(hasFocus),
|
|
29
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
30
|
+
windowFocused = _useState4[0],
|
|
31
|
+
setWindowFocused = _useState4[1];
|
|
32
|
+
|
|
33
|
+
var _useState5 = useState([]),
|
|
34
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
35
|
+
keysPressedList = _useState6[0],
|
|
36
|
+
setKeysPressedList = _useState6[1];
|
|
37
|
+
|
|
38
|
+
var previousState = usePreviousValue({
|
|
39
|
+
isEditing: isEditing,
|
|
40
|
+
windowFocused: windowFocused
|
|
41
|
+
}); // useEffect to check for window focus, if window loses focus
|
|
42
|
+
// we need to clear out the keysPressedList
|
|
43
|
+
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
var userAgentString = window.navigator.userAgent;
|
|
46
|
+
|
|
47
|
+
if (userAgentString.includes('Macintosh')) {
|
|
48
|
+
setUsingMac(true);
|
|
49
|
+
} else {
|
|
50
|
+
setUsingMac(false);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setWindowFocused(hasFocus());
|
|
54
|
+
|
|
55
|
+
var onWindowFocus = function onWindowFocus() {
|
|
56
|
+
return setWindowFocused(true);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var onWindowBlur = function onWindowBlur() {
|
|
60
|
+
return setWindowFocused(false);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
window.addEventListener('focus', onWindowFocus);
|
|
64
|
+
window.addEventListener('blur', onWindowBlur);
|
|
65
|
+
return function () {
|
|
66
|
+
window.removeEventListener('focus', onWindowFocus);
|
|
67
|
+
window.removeEventListener('blur', onWindowBlur);
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
if (containerHasFocus && !isEditing) {
|
|
72
|
+
ref.current.onkeydown = ref.current.onkeyup = function (event) {
|
|
73
|
+
// If keydown, we will add the new key to the keysPressedList array
|
|
74
|
+
if (event.type === 'keydown') {
|
|
75
|
+
// Prevent multiple keys of the same type being added to our keysPressedList array
|
|
76
|
+
if (keysPressedList.includes(event.code)) {
|
|
77
|
+
return;
|
|
78
|
+
} // Because keyup events are lost when using the Command key
|
|
79
|
+
// we need to remove the previously pressed keys so that we
|
|
80
|
+
// do not have keys in the pressed list that should not be
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if (includesResourceKey(keysPressedList, usingMac) && keysPressedList.length > 1) {
|
|
84
|
+
var clonedKeys = _toConsumableArray(keysPressedList);
|
|
85
|
+
|
|
86
|
+
var filteredClonedKeys = clonedKeys.filter(function (item) {
|
|
87
|
+
return item === 'MetaLeft' || item === 'MetaRight';
|
|
88
|
+
});
|
|
89
|
+
filteredClonedKeys.push(event.code);
|
|
90
|
+
return setKeysPressedList(_toConsumableArray(new Set(filteredClonedKeys)));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var tempKeys = _toConsumableArray(keysPressedList);
|
|
94
|
+
|
|
95
|
+
tempKeys.push(event.code);
|
|
96
|
+
setKeysPressedList(_toConsumableArray(new Set(tempKeys)));
|
|
97
|
+
} // If keyup, we will remove the key from the keysPressedList array
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if (event.type === 'keyup') {
|
|
101
|
+
var _tempKeys = _toConsumableArray(keysPressedList);
|
|
102
|
+
|
|
103
|
+
var filteredClone = _tempKeys.filter(function (item) {
|
|
104
|
+
return item !== event.code;
|
|
105
|
+
}); // Keyup events are lost on all other keys if a Meta key is used
|
|
106
|
+
// so to work around this behavior, we empty out all other keys
|
|
107
|
+
// from the keysPressedList array if we detect a Meta keyup event
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
|
|
111
|
+
return setKeysPressedList([]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setKeysPressedList(_toConsumableArray(new Set(filteredClone)));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
|
|
120
|
+
setKeysPressedList([]);
|
|
121
|
+
} // Remove handlers if the spreadsheet container loses focus
|
|
122
|
+
// or is currently in edit mode
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if (!containerHasFocus || isEditing) {
|
|
126
|
+
ref.current.onkeydown = undefined;
|
|
127
|
+
ref.current.onkeyup = undefined;
|
|
128
|
+
|
|
129
|
+
if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
|
|
130
|
+
setKeysPressedList([]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
|
|
134
|
+
return {
|
|
135
|
+
keysPressedList: keysPressedList,
|
|
136
|
+
windowFocused: windowFocused,
|
|
137
|
+
usingMac: usingMac
|
|
138
|
+
};
|
|
139
|
+
};
|
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
import { useEffect } from 'react';
|
|
8
8
|
import { pkg } from '../../../settings';
|
|
9
9
|
export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
|
10
|
-
var
|
|
11
|
-
_ref$blockClass = _ref.blockClass,
|
|
10
|
+
var _ref$blockClass = _ref.blockClass,
|
|
12
11
|
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
|
13
12
|
focusedElement = _ref.focusedElement,
|
|
14
13
|
removeActiveCell = _ref.removeActiveCell,
|
|
@@ -18,11 +17,10 @@ export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
|
|
18
17
|
if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
|
19
18
|
setContainerHasFocus(false);
|
|
20
19
|
removeActiveCell();
|
|
21
|
-
activeKeys.current = [];
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
|
25
23
|
setContainerHasFocus(true);
|
|
26
24
|
}
|
|
27
|
-
}, [focusedElement, removeActiveCell,
|
|
25
|
+
}, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
|
|
28
26
|
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// /**
|
|
2
|
+
// * Copyright IBM Corp. 2022, 2022
|
|
3
|
+
// *
|
|
4
|
+
// * This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
// * LICENSE file in the root directory of this source tree.
|
|
6
|
+
// */
|
|
7
|
+
import { useEffect } from 'react';
|
|
8
|
+
import { px } from '@carbon/layout';
|
|
9
|
+
export var useSpreadsheetEdit = function useSpreadsheetEdit(_ref) {
|
|
10
|
+
var isEditing = _ref.isEditing,
|
|
11
|
+
rows = _ref.rows,
|
|
12
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
|
13
|
+
activeCellRef = _ref.activeCellRef,
|
|
14
|
+
cellEditorRef = _ref.cellEditorRef,
|
|
15
|
+
cellEditorRulerRef = _ref.cellEditorRulerRef,
|
|
16
|
+
columns = _ref.columns,
|
|
17
|
+
defaultColumn = _ref.defaultColumn,
|
|
18
|
+
cellEditorValue = _ref.cellEditorValue;
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (isEditing) {
|
|
21
|
+
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
|
22
|
+
|
|
23
|
+
var cellProps = (_rows$activeCellCoord = rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row]) === null || _rows$activeCellCoord === void 0 ? void 0 : _rows$activeCellCoord.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column];
|
|
24
|
+
var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
|
|
25
|
+
var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
|
|
26
|
+
cellEditorRef.current.style.left = activeCellLeftPosition;
|
|
27
|
+
cellEditorRef.current.style.top = activeCellTopPosition;
|
|
28
|
+
cellEditorRef.current.style.display = 'block';
|
|
29
|
+
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
|
30
|
+
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
|
31
|
+
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2 - 1, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
|
32
|
+
|
|
33
|
+
cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
|
|
34
|
+
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
|
35
|
+
var rulerWidth = cellEditorRulerRef.current.offsetWidth;
|
|
36
|
+
var cellWidth = activeCellRef.current.offsetWidth;
|
|
37
|
+
|
|
38
|
+
if (rulerWidth >= cellWidth) {
|
|
39
|
+
var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
|
|
40
|
+
var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
|
|
41
|
+
var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
|
42
|
+
var totalColumns = columns.length;
|
|
43
|
+
var totalRows = rows.length;
|
|
44
|
+
var totalMultiplierPossible = totalColumns - startingColumnPosition;
|
|
45
|
+
var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
|
|
46
|
+
cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
|
|
47
|
+
cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
|
|
48
|
+
cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
|
|
49
|
+
// Cell editor has reached max height, we need to add the scrolling back.
|
|
50
|
+
// We also need to subtract 1 to account for the fact that the cell editor
|
|
51
|
+
// is placed one pixel below the cell being edited to account for the border
|
|
52
|
+
|
|
53
|
+
if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
|
|
54
|
+
cellEditorRef.current.style.overflow = 'auto';
|
|
55
|
+
} else {
|
|
56
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!isEditing) {
|
|
62
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
|
63
|
+
cellEditorRef.current.style.display = 'none';
|
|
64
|
+
cellEditorRef.current.blur();
|
|
65
|
+
activeCellRef.current.focus();
|
|
66
|
+
}
|
|
67
|
+
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn, cellEditorValue, activeCellRef, cellEditorRef, cellEditorRulerRef]);
|
|
68
|
+
};
|
|
@@ -16,7 +16,6 @@ export var useSpreadsheetOutsideClick = function useSpreadsheetOutsideClick(_ref
|
|
|
16
16
|
setSelectionAreas = _ref.setSelectionAreas,
|
|
17
17
|
removeActiveCell = _ref.removeActiveCell,
|
|
18
18
|
setContainerHasFocus = _ref.setContainerHasFocus,
|
|
19
|
-
activeKeys = _ref.activeKeys,
|
|
20
19
|
removeCellEditor = _ref.removeCellEditor;
|
|
21
20
|
useEffect(function () {
|
|
22
21
|
var handleOutsideClick = function handleOutsideClick(event) {
|
|
@@ -32,12 +31,11 @@ export var useSpreadsheetOutsideClick = function useSpreadsheetOutsideClick(_ref
|
|
|
32
31
|
});
|
|
33
32
|
setContainerHasFocus(false);
|
|
34
33
|
removeCellEditor();
|
|
35
|
-
activeKeys.current = [];
|
|
36
34
|
};
|
|
37
35
|
|
|
38
36
|
document.addEventListener('click', handleOutsideClick);
|
|
39
37
|
return function () {
|
|
40
38
|
document.removeEventListener('click', handleOutsideClick);
|
|
41
39
|
};
|
|
42
|
-
}, [spreadsheetRef, removeActiveCell,
|
|
40
|
+
}, [spreadsheetRef, removeActiveCell, blockClass, setActiveCellCoordinates, setContainerHasFocus, setSelectionAreas, removeCellEditor]);
|
|
43
41
|
};
|
|
@@ -6,22 +6,34 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { px } from '@carbon/layout';
|
|
8
8
|
import { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
|
|
9
|
+
import { getSelectionAreaPoints } from './getSelectionAreaPoints';
|
|
9
10
|
export var createCellSelectionArea = function createCellSelectionArea(_ref) {
|
|
10
|
-
var
|
|
11
|
+
var ref = _ref.ref,
|
|
12
|
+
area = _ref.area,
|
|
11
13
|
blockClass = _ref.blockClass,
|
|
12
14
|
defaultColumn = _ref.defaultColumn,
|
|
13
15
|
selectionAreas = _ref.selectionAreas,
|
|
14
|
-
setSelectionAreas = _ref.setSelectionAreas
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
|
|
16
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
|
17
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
|
|
18
|
+
|
|
19
|
+
var _getSelectionAreaPoin = getSelectionAreaPoints(area),
|
|
20
|
+
lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
|
|
21
|
+
lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
|
|
22
|
+
greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
|
|
23
|
+
greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex;
|
|
24
|
+
|
|
25
|
+
if (greatestRowIndex - lowestRowIndex > 0 || greatestColumnIndex - lowestColumnIndex > 0) {
|
|
26
|
+
setActiveCellInsideSelectionArea(true);
|
|
27
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
|
28
|
+
activeCellElement.setAttribute('data-selection-id', area.matcher);
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]")) || document.querySelector(".".concat(blockClass, "__body--td")); // if we can't find the point1 element (this can happen in the case where a virtualized row is not present anymore in the DOM), we get the default height/width of the first body cell we find
|
|
20
32
|
|
|
21
33
|
var selectionAreaCellWidth = point1Element.offsetWidth;
|
|
22
34
|
var selectionAreaCellHeight = point1Element.offsetHeight;
|
|
23
|
-
var selectionAreaTotalWidth = selectionAreaCellWidth * (
|
|
24
|
-
var selectionAreaTotalHeight = selectionAreaCellHeight * (
|
|
35
|
+
var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumnIndex - lowestColumnIndex + 1);
|
|
36
|
+
var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRowIndex - lowestRowIndex + 1);
|
|
25
37
|
var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
|
26
38
|
var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
|
|
27
39
|
var relativePosition = {
|