UNPKG

@carbon/ibm-products

Version:
77 lines (75 loc) 3.25 kB
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const require_getSelectionAreaPoints = require("./getSelectionAreaPoints.js"); //#region src/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js /** * Copyright IBM Corp. 2022, 2022 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const handleActiveCellInSelectionEnter = ({ activeCellInsideSelectionArea, activeCellCoordinates, activeCellRef, selectionAreas, updateActiveCellCoordinates }) => { if (!activeCellInsideSelectionArea) return; const activeCellSelectionId = activeCellRef.current.getAttribute("data-selection-id"); const activeCellIndexInSelectionAreas = selectionAreas.findIndex((item) => item.matcher === activeCellSelectionId); const selectionAreaToNavigate = selectionAreas[activeCellIndexInSelectionAreas]; const { lowestColumnIndex, lowestRowIndex, greatestColumnIndex, greatestRowIndex } = require_getSelectionAreaPoints.getSelectionAreaPoints(selectionAreaToNavigate); const coordinatesClone = { ...activeCellCoordinates }; if (activeCellCoordinates?.row < greatestRowIndex) updateActiveCellCoordinates({ coords: coordinatesClone, updatedValue: { row: coordinatesClone?.row + 1 }, optOutOfSelectionAreaUpdate: true }); if (activeCellCoordinates?.row === greatestRowIndex) { if (activeCellCoordinates?.column < greatestColumnIndex) updateActiveCellCoordinates({ coords: coordinatesClone, updatedValue: { column: coordinatesClone?.column + 1, row: lowestRowIndex }, optOutOfSelectionAreaUpdate: true }); if (activeCellCoordinates?.column === greatestColumnIndex) { if (selectionAreas.length > 1) if (selectionAreas[activeCellIndexInSelectionAreas + 1]) { activeCellRef.current.setAttribute("data-selection-id", selectionAreas[activeCellIndexInSelectionAreas + 1].matcher); const nextSelectionArea = selectionAreas[activeCellIndexInSelectionAreas + 1]; const { lowestColumnIndex, lowestRowIndex } = require_getSelectionAreaPoints.getSelectionAreaPoints(nextSelectionArea); updateActiveCellCoordinates({ coords: coordinatesClone, updatedValue: { column: lowestColumnIndex, row: lowestRowIndex }, optOutOfSelectionAreaUpdate: true }); return; } else { activeCellRef.current.setAttribute("data-selection-id", selectionAreas[0].matcher); const firstSelectionArea = selectionAreas[0]; const { lowestColumnIndex, lowestRowIndex } = require_getSelectionAreaPoints.getSelectionAreaPoints(firstSelectionArea); updateActiveCellCoordinates({ coords: coordinatesClone, updatedValue: { column: lowestColumnIndex, row: lowestRowIndex }, optOutOfSelectionAreaUpdate: true }); } if (selectionAreas.length === 1) return updateActiveCellCoordinates({ coords: coordinatesClone, updatedValue: { column: lowestColumnIndex, row: lowestRowIndex }, optOutOfSelectionAreaUpdate: true }); } } }; //#endregion exports.handleActiveCellInSelectionEnter = handleActiveCellInSelectionEnter;