UNPKG

@carbon/ibm-products

Version:
35 lines (33 loc) 1.85 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. */ import { deepCloneObject } from "../../../global/js/utils/deepCloneObject.js"; import { rangeWithCallback } from "../../../global/js/utils/rangeWithCallback.js"; //#region src/components/DataSpreadsheet/utils/handleCellDeletion.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 handleCellDeletion = ({ activeCellCoordinates, selectionAreas, currentMatcher, rows, setActiveCellContent, updateData }) => { if (activeCellCoordinates?.column === "header" || activeCellCoordinates?.row === "header") return; const selectionAreaClone = deepCloneObject(selectionAreas); const selectionAreaToEmptyContents = selectionAreaClone[selectionAreaClone.findIndex((item) => item.matcher === currentMatcher)]; const lowestColumnIndex = Math.min(selectionAreaToEmptyContents?.point1?.column, selectionAreaToEmptyContents?.point2?.column); const greatestColumnIndex = Math.max(selectionAreaToEmptyContents?.point1?.column, selectionAreaToEmptyContents?.point2?.column); const lowestRowIndex = Math.min(selectionAreaToEmptyContents?.point1?.row, selectionAreaToEmptyContents?.point2?.row); const greatestRowIndex = Math.max(selectionAreaToEmptyContents?.point1?.row, selectionAreaToEmptyContents?.point2?.row); rangeWithCallback(lowestColumnIndex, greatestColumnIndex, (columnIndex) => { rangeWithCallback(lowestRowIndex, greatestRowIndex, (rowIndex) => { const cellProps = rows[rowIndex].cells[columnIndex]; updateData(rowIndex, cellProps?.column.id, ""); }); }); setActiveCellContent(null); }; //#endregion export { handleCellDeletion };