@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
|
@@ -41,16 +41,16 @@ var _checkActiveHeaderCell = require("./utils/checkActiveHeaderCell");
|
|
|
41
41
|
|
|
42
42
|
var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
|
|
43
43
|
|
|
44
|
+
var _getSpreadsheetWidth = require("./utils/getSpreadsheetWidth");
|
|
45
|
+
|
|
44
46
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
45
47
|
|
|
46
48
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* LICENSE file in the root directory of this source tree.
|
|
53
|
-
*/
|
|
50
|
+
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; }
|
|
51
|
+
|
|
52
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
53
|
+
|
|
54
54
|
var blockClass = "".concat(_settings.pkg.prefix, "--data-spreadsheet");
|
|
55
55
|
var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
56
56
|
var columns = _ref.columns,
|
|
@@ -75,7 +75,10 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
75
75
|
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
|
76
76
|
currentMatcher = _ref.currentMatcher,
|
|
77
77
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
|
78
|
-
onSelectionAreaChange = _ref.onSelectionAreaChange
|
|
78
|
+
onSelectionAreaChange = _ref.onSelectionAreaChange,
|
|
79
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea,
|
|
80
|
+
totalVisibleColumns = _ref.totalVisibleColumns;
|
|
81
|
+
var contentScrollRef = (0, _react.useRef)();
|
|
79
82
|
var previousState = (0, _hooks.usePreviousValue)({
|
|
80
83
|
selectionAreaData: selectionAreaData,
|
|
81
84
|
clickAndHoldActive: clickAndHoldActive
|
|
@@ -133,18 +136,20 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
133
136
|
|
|
134
137
|
if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
|
|
135
138
|
(0, _createCellSelectionArea.createCellSelectionArea)({
|
|
139
|
+
ref: ref,
|
|
136
140
|
area: area,
|
|
137
141
|
blockClass: blockClass,
|
|
138
142
|
defaultColumn: defaultColumn,
|
|
139
143
|
selectionAreas: selectionAreas,
|
|
140
|
-
setSelectionAreas: setSelectionAreas
|
|
144
|
+
setSelectionAreas: setSelectionAreas,
|
|
145
|
+
setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
|
|
141
146
|
});
|
|
142
147
|
}
|
|
143
148
|
|
|
144
149
|
return;
|
|
145
150
|
});
|
|
146
151
|
}
|
|
147
|
-
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
|
|
152
|
+
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
|
|
148
153
|
|
|
149
154
|
var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
|
|
150
155
|
var rowStart = _ref2.rowStart,
|
|
@@ -222,6 +227,9 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
222
227
|
// meaning that selectionAreas should only have one item by default
|
|
223
228
|
|
|
224
229
|
if (isHoldingCommandKey) {
|
|
230
|
+
var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
|
231
|
+
activeCellElement.setAttribute('data-selection-id', tempMatcher);
|
|
232
|
+
setActiveCellInsideSelectionArea(true);
|
|
225
233
|
setActiveCellCoordinates(activeCoordinates);
|
|
226
234
|
setCurrentMatcher(tempMatcher);
|
|
227
235
|
setSelectionAreas(function (prev) {
|
|
@@ -252,6 +260,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
252
260
|
setSelectionAreas(selectionAreaClone);
|
|
253
261
|
}
|
|
254
262
|
} else {
|
|
263
|
+
setActiveCellInsideSelectionArea(false);
|
|
255
264
|
setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
|
|
256
265
|
|
|
257
266
|
(0, _removeCellSelections.removeCellSelections)({
|
|
@@ -265,7 +274,22 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
265
274
|
setSelectionAreaData([]);
|
|
266
275
|
}
|
|
267
276
|
};
|
|
268
|
-
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
|
|
277
|
+
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
|
|
278
|
+
|
|
279
|
+
var handleBodyScroll = function handleBodyScroll() {
|
|
280
|
+
var headerRowElement = ref.current.querySelector("\n .".concat(blockClass, "__header--container .").concat(blockClass, "__tr"));
|
|
281
|
+
headerRowElement.scrollLeft = contentScrollRef.current.scrollLeft;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
(0, _react.useEffect)(function () {
|
|
285
|
+
contentScrollRef.current.addEventListener('scroll', function (event) {
|
|
286
|
+
return handleBodyScroll(event);
|
|
287
|
+
});
|
|
288
|
+
var contentScrollElementRef = contentScrollRef.current;
|
|
289
|
+
return function () {
|
|
290
|
+
contentScrollElementRef.removeEventListener('scroll', handleBodyScroll);
|
|
291
|
+
};
|
|
292
|
+
});
|
|
269
293
|
var handleBodyCellHover = (0, _react.useCallback)(function (cell, columnIndex) {
|
|
270
294
|
return function () {
|
|
271
295
|
if (clickAndHoldActive) {
|
|
@@ -298,7 +322,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
298
322
|
};
|
|
299
323
|
}, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
|
|
300
324
|
var handleRowHeaderClick = (0, _react.useCallback)(function (index) {
|
|
301
|
-
return function () {
|
|
325
|
+
return function (event) {
|
|
326
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
|
302
327
|
(0, _handleHeaderCellSelection.handleHeaderCellSelection)({
|
|
303
328
|
type: 'row',
|
|
304
329
|
activeCellCoordinates: activeCellCoordinates,
|
|
@@ -309,7 +334,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
309
334
|
setSelectionAreas: setSelectionAreas,
|
|
310
335
|
spreadsheetRef: ref,
|
|
311
336
|
index: index,
|
|
312
|
-
setSelectionAreaData: setSelectionAreaData
|
|
337
|
+
setSelectionAreaData: setSelectionAreaData,
|
|
338
|
+
isHoldingCommandKey: isHoldingCommandKey
|
|
313
339
|
});
|
|
314
340
|
};
|
|
315
341
|
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
|
|
@@ -351,8 +377,13 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
351
377
|
style: style
|
|
352
378
|
}), {
|
|
353
379
|
className: (0, _classnames.default)("".concat(blockClass, "__tr")),
|
|
354
|
-
"data-row-index": index
|
|
355
|
-
|
|
380
|
+
"data-row-index": index,
|
|
381
|
+
"aria-rowindex": index + 1
|
|
382
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
383
|
+
role: "rowheader",
|
|
384
|
+
className: "".concat(blockClass, "__td-th--cell-container")
|
|
385
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
386
|
+
id: "".concat(blockClass, "__cell--").concat(index, "--header"),
|
|
356
387
|
tabIndex: -1,
|
|
357
388
|
"data-row-index": index,
|
|
358
389
|
"data-column-index": "header",
|
|
@@ -362,22 +393,30 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
362
393
|
style: {
|
|
363
394
|
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
|
|
364
395
|
}
|
|
365
|
-
}, index + 1), row.cells.map(function (cell, index) {
|
|
366
|
-
return /*#__PURE__*/_react.default.createElement("
|
|
396
|
+
}, index + 1)), row.cells.map(function (cell, index) {
|
|
397
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
398
|
+
key: "cell_".concat(index),
|
|
399
|
+
"aria-colindex": index + 1
|
|
400
|
+
}, cell.getCellProps(), {
|
|
401
|
+
role: "gridcell",
|
|
402
|
+
style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
|
|
403
|
+
display: 'grid',
|
|
404
|
+
minWidth: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width
|
|
405
|
+
})
|
|
406
|
+
}), /*#__PURE__*/_react.default.createElement("button", {
|
|
407
|
+
id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
|
|
367
408
|
tabIndex: -1,
|
|
368
409
|
"data-row-index": cell.row.index,
|
|
369
|
-
"data-column-index": index
|
|
370
|
-
}, cell.getCellProps(), {
|
|
410
|
+
"data-column-index": index,
|
|
371
411
|
className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
|
|
372
|
-
key: "cell_".concat(index),
|
|
373
412
|
onMouseDown: handleBodyCellClick(cell, index),
|
|
374
413
|
onMouseOver: handleBodyCellHover(cell, index),
|
|
375
414
|
onFocus: function onFocus() {},
|
|
376
415
|
type: "button"
|
|
377
|
-
}
|
|
416
|
+
}, cell.render('Cell')));
|
|
378
417
|
}));
|
|
379
418
|
}
|
|
380
|
-
}, [prepareRow, rows,
|
|
419
|
+
}, [prepareRow, rows, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover, defaultColumn]);
|
|
381
420
|
var spreadsheetBodyRef = (0, _react.useRef)();
|
|
382
421
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
383
422
|
ref: spreadsheetBodyRef,
|
|
@@ -387,7 +426,13 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
|
|
|
387
426
|
height: 400,
|
|
388
427
|
itemCount: rows.length || defaultEmptyRowCount,
|
|
389
428
|
itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
|
390
|
-
width:
|
|
429
|
+
width: (0, _getSpreadsheetWidth.getSpreadsheetWidth)({
|
|
430
|
+
scrollBarSizeValue: scrollBarSize,
|
|
431
|
+
totalVisibleColumns: totalVisibleColumns,
|
|
432
|
+
defaultColumn: defaultColumn,
|
|
433
|
+
totalColumnsWidth: totalColumnsWidth
|
|
434
|
+
}),
|
|
435
|
+
outerRef: contentScrollRef
|
|
391
436
|
}, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
|
|
392
437
|
});
|
|
393
438
|
exports.DataSpreadsheetBody = DataSpreadsheetBody;
|
|
@@ -489,6 +534,11 @@ DataSpreadsheetBody.propTypes = {
|
|
|
489
534
|
*/
|
|
490
535
|
setActiveCellCoordinates: _propTypes.default.func,
|
|
491
536
|
|
|
537
|
+
/**
|
|
538
|
+
* Setter fn for active cell inside of selection area
|
|
539
|
+
*/
|
|
540
|
+
setActiveCellInsideSelectionArea: _propTypes.default.func,
|
|
541
|
+
|
|
492
542
|
/**
|
|
493
543
|
* Setter fn for clickAndHold state value
|
|
494
544
|
*/
|
|
@@ -517,5 +567,11 @@ DataSpreadsheetBody.propTypes = {
|
|
|
517
567
|
/**
|
|
518
568
|
* The total columns width
|
|
519
569
|
*/
|
|
520
|
-
totalColumnsWidth: _propTypes.default.number
|
|
570
|
+
totalColumnsWidth: _propTypes.default.number,
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* The total number of columns to be initially visible, additional columns will be rendered and
|
|
574
|
+
* visible via horizontal scrollbar
|
|
575
|
+
*/
|
|
576
|
+
totalVisibleColumns: _propTypes.default.number
|
|
521
577
|
};
|
|
@@ -21,15 +21,17 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
21
21
|
|
|
22
22
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
23
23
|
|
|
24
|
-
var _layout = require("@carbon/layout");
|
|
25
|
-
|
|
26
24
|
var _settings = require("../../settings");
|
|
27
25
|
|
|
26
|
+
var _hooks = require("../../global/js/hooks");
|
|
27
|
+
|
|
28
28
|
var _checkActiveHeaderCell = require("./utils/checkActiveHeaderCell");
|
|
29
29
|
|
|
30
30
|
var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _selectAllCells = require("./utils/selectAllCells");
|
|
33
|
+
|
|
34
|
+
var _getSpreadsheetWidth = require("./utils/getSpreadsheetWidth");
|
|
33
35
|
|
|
34
36
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
37
|
|
|
@@ -52,7 +54,9 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
|
52
54
|
setCurrentMatcher = _ref.setCurrentMatcher,
|
|
53
55
|
setSelectionAreas = _ref.setSelectionAreas,
|
|
54
56
|
setSelectionAreaData = _ref.setSelectionAreaData,
|
|
55
|
-
rows = _ref.rows
|
|
57
|
+
rows = _ref.rows,
|
|
58
|
+
totalVisibleColumns = _ref.totalVisibleColumns,
|
|
59
|
+
updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
|
|
56
60
|
|
|
57
61
|
var _useState = (0, _react.useState)(0),
|
|
58
62
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
@@ -74,7 +78,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
|
74
78
|
}, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
|
|
75
79
|
|
|
76
80
|
var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
|
|
77
|
-
return function () {
|
|
81
|
+
return function (event) {
|
|
82
|
+
var isHoldingCommandKey = event.metaKey || event.ctrlKey;
|
|
78
83
|
(0, _handleHeaderCellSelection.handleHeaderCellSelection)({
|
|
79
84
|
type: 'column',
|
|
80
85
|
activeCellCoordinates: activeCellCoordinates,
|
|
@@ -85,45 +90,75 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
|
85
90
|
setSelectionAreas: setSelectionAreas,
|
|
86
91
|
spreadsheetRef: ref,
|
|
87
92
|
index: index,
|
|
88
|
-
setSelectionAreaData: setSelectionAreaData
|
|
93
|
+
setSelectionAreaData: setSelectionAreaData,
|
|
94
|
+
isHoldingCommandKey: isHoldingCommandKey
|
|
89
95
|
});
|
|
90
96
|
};
|
|
91
97
|
};
|
|
92
98
|
|
|
99
|
+
var handleSelectAllClick = function handleSelectAllClick() {
|
|
100
|
+
(0, _selectAllCells.selectAllCells)({
|
|
101
|
+
ref: ref,
|
|
102
|
+
setCurrentMatcher: setCurrentMatcher,
|
|
103
|
+
setSelectionAreas: setSelectionAreas,
|
|
104
|
+
rows: rows,
|
|
105
|
+
columns: columns,
|
|
106
|
+
activeCellCoordinates: activeCellCoordinates,
|
|
107
|
+
updateActiveCellCoordinates: updateActiveCellCoordinates
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
93
111
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
94
|
-
className: (0, _classnames.default)("".concat(blockClass, "__header--container"))
|
|
112
|
+
className: (0, _classnames.default)("".concat(blockClass, "__header--container")),
|
|
113
|
+
role: "rowgroup"
|
|
95
114
|
}, headerGroups.map(function (headerGroup, index) {
|
|
96
115
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
97
116
|
key: "header_".concat(index)
|
|
98
117
|
}, headerGroup.getHeaderGroupProps(), {
|
|
99
118
|
style: _objectSpread(_objectSpread({}, headerGroup.getHeaderGroupProps().style), {}, {
|
|
100
|
-
width: (0,
|
|
119
|
+
width: (0, _getSpreadsheetWidth.getSpreadsheetWidth)({
|
|
120
|
+
type: 'header',
|
|
121
|
+
headerGroup: headerGroup,
|
|
122
|
+
scrollBarSizeValue: scrollBarSizeValue,
|
|
123
|
+
totalVisibleColumns: totalVisibleColumns,
|
|
124
|
+
defaultColumn: defaultColumn
|
|
125
|
+
}),
|
|
126
|
+
overflow: 'hidden'
|
|
101
127
|
}),
|
|
102
128
|
className: "".concat(blockClass, "__tr")
|
|
103
|
-
}), /*#__PURE__*/_react.default.createElement("
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
type: "button",
|
|
107
|
-
tabIndex: -1,
|
|
108
|
-
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header')),
|
|
129
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
130
|
+
role: "columnheader",
|
|
131
|
+
className: "".concat(blockClass, "__select-all-cell-container"),
|
|
109
132
|
style: {
|
|
110
133
|
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
|
|
111
134
|
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
|
112
135
|
}
|
|
113
|
-
},
|
|
114
|
-
|
|
136
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
137
|
+
id: "".concat(blockClass, "__cell--header--header"),
|
|
138
|
+
"data-row-index": "header",
|
|
139
|
+
"data-column-index": "header",
|
|
140
|
+
type: "button",
|
|
141
|
+
tabIndex: -1,
|
|
142
|
+
onClick: handleSelectAllClick,
|
|
143
|
+
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header'))
|
|
144
|
+
}, "\xA0")), headerGroup.headers.map(function (column, index) {
|
|
145
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
115
146
|
key: "column_".concat(index),
|
|
147
|
+
role: "columnheader",
|
|
148
|
+
className: "".concat(blockClass, "__columnheader")
|
|
149
|
+
}, column.getHeaderProps()), /*#__PURE__*/_react.default.createElement("button", {
|
|
150
|
+
id: "".concat(blockClass, "__cell--header--").concat(index),
|
|
116
151
|
"data-row-index": "header",
|
|
117
152
|
"data-column-index": index,
|
|
118
153
|
tabIndex: -1,
|
|
119
154
|
onClick: handleColumnHeaderClick(index),
|
|
120
155
|
style: {
|
|
121
|
-
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
|
|
122
|
-
|
|
123
|
-
|
|
156
|
+
height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
|
|
157
|
+
width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width
|
|
158
|
+
},
|
|
124
159
|
className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'column'))),
|
|
125
160
|
type: "button"
|
|
126
|
-
}
|
|
161
|
+
}, column.render('Header')));
|
|
127
162
|
}));
|
|
128
163
|
}));
|
|
129
164
|
});
|
|
@@ -194,5 +229,16 @@ DataSpreadsheetHeader.propTypes = {
|
|
|
194
229
|
/**
|
|
195
230
|
* Setter fn for selectionAreas value
|
|
196
231
|
*/
|
|
197
|
-
setSelectionAreas: _propTypes.default.func
|
|
232
|
+
setSelectionAreas: _propTypes.default.func,
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The total number of columns to be initially visible, additional columns will be rendered and
|
|
236
|
+
* visible via horizontal scrollbar
|
|
237
|
+
*/
|
|
238
|
+
totalVisibleColumns: _propTypes.default.number,
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Function used to update the active cell coordinates
|
|
242
|
+
*/
|
|
243
|
+
updateActiveCellCoordinates: _propTypes.default.func
|
|
198
244
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useMoveActiveCell", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _useMoveActiveCell.useMoveActiveCell;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useMultipleKeyTracking", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _useMultipleKeyTracking.useMultipleKeyTracking;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "useResetSpreadsheetFocus", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _useResetSpreadsheetFocus.useResetSpreadsheetFocus;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "useSpreadsheetEdit", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _useSpreadsheetEdit.useSpreadsheetEdit;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "useSpreadsheetOutsideClick", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _useSpreadsheetOutsideClick.useSpreadsheetOutsideClick;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
var _useMoveActiveCell = require("./useMoveActiveCell");
|
|
38
|
+
|
|
39
|
+
var _useMultipleKeyTracking = require("./useMultipleKeyTracking");
|
|
40
|
+
|
|
41
|
+
var _useResetSpreadsheetFocus = require("./useResetSpreadsheetFocus");
|
|
42
|
+
|
|
43
|
+
var _useSpreadsheetOutsideClick = require("./useSpreadsheetOutsideClick");
|
|
44
|
+
|
|
45
|
+
var _useSpreadsheetEdit = require("./useSpreadsheetEdit");
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useMultipleKeyTracking = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
var _react = require("react");
|
|
15
|
+
|
|
16
|
+
var _hooks = require("../../../global/js/hooks");
|
|
17
|
+
|
|
18
|
+
var _handleMultipleKeys = require("../utils/handleMultipleKeys");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Copyright IBM Corp. 2022, 2022
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/
|
|
26
|
+
var hasFocus = function hasFocus() {
|
|
27
|
+
return typeof document !== 'undefined' && document.hasFocus();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
|
|
31
|
+
var ref = _ref.ref,
|
|
32
|
+
containerHasFocus = _ref.containerHasFocus,
|
|
33
|
+
isEditing = _ref.isEditing;
|
|
34
|
+
|
|
35
|
+
var _useState = (0, _react.useState)(''),
|
|
36
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
37
|
+
usingMac = _useState2[0],
|
|
38
|
+
setUsingMac = _useState2[1];
|
|
39
|
+
|
|
40
|
+
var _useState3 = (0, _react.useState)(hasFocus),
|
|
41
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
42
|
+
windowFocused = _useState4[0],
|
|
43
|
+
setWindowFocused = _useState4[1];
|
|
44
|
+
|
|
45
|
+
var _useState5 = (0, _react.useState)([]),
|
|
46
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
47
|
+
keysPressedList = _useState6[0],
|
|
48
|
+
setKeysPressedList = _useState6[1];
|
|
49
|
+
|
|
50
|
+
var previousState = (0, _hooks.usePreviousValue)({
|
|
51
|
+
isEditing: isEditing,
|
|
52
|
+
windowFocused: windowFocused
|
|
53
|
+
}); // useEffect to check for window focus, if window loses focus
|
|
54
|
+
// we need to clear out the keysPressedList
|
|
55
|
+
|
|
56
|
+
(0, _react.useEffect)(function () {
|
|
57
|
+
var userAgentString = window.navigator.userAgent;
|
|
58
|
+
|
|
59
|
+
if (userAgentString.includes('Macintosh')) {
|
|
60
|
+
setUsingMac(true);
|
|
61
|
+
} else {
|
|
62
|
+
setUsingMac(false);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setWindowFocused(hasFocus());
|
|
66
|
+
|
|
67
|
+
var onWindowFocus = function onWindowFocus() {
|
|
68
|
+
return setWindowFocused(true);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var onWindowBlur = function onWindowBlur() {
|
|
72
|
+
return setWindowFocused(false);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
window.addEventListener('focus', onWindowFocus);
|
|
76
|
+
window.addEventListener('blur', onWindowBlur);
|
|
77
|
+
return function () {
|
|
78
|
+
window.removeEventListener('focus', onWindowFocus);
|
|
79
|
+
window.removeEventListener('blur', onWindowBlur);
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
82
|
+
(0, _react.useEffect)(function () {
|
|
83
|
+
if (containerHasFocus && !isEditing) {
|
|
84
|
+
ref.current.onkeydown = ref.current.onkeyup = function (event) {
|
|
85
|
+
// If keydown, we will add the new key to the keysPressedList array
|
|
86
|
+
if (event.type === 'keydown') {
|
|
87
|
+
// Prevent multiple keys of the same type being added to our keysPressedList array
|
|
88
|
+
if (keysPressedList.includes(event.code)) {
|
|
89
|
+
return;
|
|
90
|
+
} // Because keyup events are lost when using the Command key
|
|
91
|
+
// we need to remove the previously pressed keys so that we
|
|
92
|
+
// do not have keys in the pressed list that should not be
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac) && keysPressedList.length > 1) {
|
|
96
|
+
var clonedKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
|
97
|
+
var filteredClonedKeys = clonedKeys.filter(function (item) {
|
|
98
|
+
return item === 'MetaLeft' || item === 'MetaRight';
|
|
99
|
+
});
|
|
100
|
+
filteredClonedKeys.push(event.code);
|
|
101
|
+
return setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClonedKeys)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
|
105
|
+
tempKeys.push(event.code);
|
|
106
|
+
setKeysPressedList((0, _toConsumableArray2.default)(new Set(tempKeys)));
|
|
107
|
+
} // If keyup, we will remove the key from the keysPressedList array
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (event.type === 'keyup') {
|
|
111
|
+
var _tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
|
|
112
|
+
|
|
113
|
+
var filteredClone = _tempKeys.filter(function (item) {
|
|
114
|
+
return item !== event.code;
|
|
115
|
+
}); // Keyup events are lost on all other keys if a Meta key is used
|
|
116
|
+
// so to work around this behavior, we empty out all other keys
|
|
117
|
+
// from the keysPressedList array if we detect a Meta keyup event
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
|
|
121
|
+
return setKeysPressedList([]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClone)));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
|
|
130
|
+
setKeysPressedList([]);
|
|
131
|
+
} // Remove handlers if the spreadsheet container loses focus
|
|
132
|
+
// or is currently in edit mode
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
if (!containerHasFocus || isEditing) {
|
|
136
|
+
ref.current.onkeydown = undefined;
|
|
137
|
+
ref.current.onkeyup = undefined;
|
|
138
|
+
|
|
139
|
+
if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
|
|
140
|
+
setKeysPressedList([]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
|
|
144
|
+
return {
|
|
145
|
+
keysPressedList: keysPressedList,
|
|
146
|
+
windowFocused: windowFocused,
|
|
147
|
+
usingMac: usingMac
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
exports.useMultipleKeyTracking = useMultipleKeyTracking;
|
|
@@ -16,8 +16,7 @@ var _settings = require("../../../settings");
|
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*/
|
|
18
18
|
var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
|
19
|
-
var
|
|
20
|
-
_ref$blockClass = _ref.blockClass,
|
|
19
|
+
var _ref$blockClass = _ref.blockClass,
|
|
21
20
|
blockClass = _ref$blockClass === void 0 ? "".concat(_settings.pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
|
22
21
|
focusedElement = _ref.focusedElement,
|
|
23
22
|
removeActiveCell = _ref.removeActiveCell,
|
|
@@ -27,13 +26,12 @@ var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
|
|
|
27
26
|
if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
|
28
27
|
setContainerHasFocus(false);
|
|
29
28
|
removeActiveCell();
|
|
30
|
-
activeKeys.current = [];
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
|
|
34
32
|
setContainerHasFocus(true);
|
|
35
33
|
}
|
|
36
|
-
}, [focusedElement, removeActiveCell,
|
|
34
|
+
}, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
|
|
37
35
|
};
|
|
38
36
|
|
|
39
37
|
exports.useResetSpreadsheetFocus = useResetSpreadsheetFocus;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSpreadsheetEdit = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _layout = require("@carbon/layout");
|
|
11
|
+
|
|
12
|
+
// /**
|
|
13
|
+
// * Copyright IBM Corp. 2022, 2022
|
|
14
|
+
// *
|
|
15
|
+
// * This source code is licensed under the Apache-2.0 license found in the
|
|
16
|
+
// * LICENSE file in the root directory of this source tree.
|
|
17
|
+
// */
|
|
18
|
+
var useSpreadsheetEdit = function useSpreadsheetEdit(_ref) {
|
|
19
|
+
var isEditing = _ref.isEditing,
|
|
20
|
+
rows = _ref.rows,
|
|
21
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
|
22
|
+
activeCellRef = _ref.activeCellRef,
|
|
23
|
+
cellEditorRef = _ref.cellEditorRef,
|
|
24
|
+
cellEditorRulerRef = _ref.cellEditorRulerRef,
|
|
25
|
+
columns = _ref.columns,
|
|
26
|
+
defaultColumn = _ref.defaultColumn,
|
|
27
|
+
cellEditorValue = _ref.cellEditorValue;
|
|
28
|
+
(0, _react.useEffect)(function () {
|
|
29
|
+
if (isEditing) {
|
|
30
|
+
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
|
31
|
+
|
|
32
|
+
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];
|
|
33
|
+
var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
|
|
34
|
+
var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
|
|
35
|
+
cellEditorRef.current.style.left = activeCellLeftPosition;
|
|
36
|
+
cellEditorRef.current.style.top = activeCellTopPosition;
|
|
37
|
+
cellEditorRef.current.style.display = 'block';
|
|
38
|
+
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
|
39
|
+
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
|
40
|
+
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
|
|
41
|
+
|
|
42
|
+
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';
|
|
43
|
+
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
|
44
|
+
var rulerWidth = cellEditorRulerRef.current.offsetWidth;
|
|
45
|
+
var cellWidth = activeCellRef.current.offsetWidth;
|
|
46
|
+
|
|
47
|
+
if (rulerWidth >= cellWidth) {
|
|
48
|
+
var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
|
|
49
|
+
var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
|
|
50
|
+
var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
|
51
|
+
var totalColumns = columns.length;
|
|
52
|
+
var totalRows = rows.length;
|
|
53
|
+
var totalMultiplierPossible = totalColumns - startingColumnPosition;
|
|
54
|
+
var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
|
|
55
|
+
cellEditorRef.current.style.maxHeight = (0, _layout.px)(totalCellEditorMaxHeight);
|
|
56
|
+
cellEditorRef.current.style.width = (0, _layout.px)(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
|
|
57
|
+
cellEditorRef.current.style.height = (0, _layout.px)(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
|
|
58
|
+
// Cell editor has reached max height, we need to add the scrolling back.
|
|
59
|
+
// We also need to subtract 1 to account for the fact that the cell editor
|
|
60
|
+
// is placed one pixel below the cell being edited to account for the border
|
|
61
|
+
|
|
62
|
+
if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
|
|
63
|
+
cellEditorRef.current.style.overflow = 'auto';
|
|
64
|
+
} else {
|
|
65
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!isEditing) {
|
|
71
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
|
72
|
+
cellEditorRef.current.style.display = 'none';
|
|
73
|
+
cellEditorRef.current.blur();
|
|
74
|
+
activeCellRef.current.focus();
|
|
75
|
+
}
|
|
76
|
+
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn, cellEditorValue, activeCellRef, cellEditorRef, cellEditorRulerRef]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.useSpreadsheetEdit = useSpreadsheetEdit;
|