UNPKG

@carbon/ibm-products

Version:
35 lines (33 loc) 1.96 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_deepCloneObject = require("../../../global/js/utils/deepCloneObject.js"); const require_rangeWithCallback = require("../../../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 = require_deepCloneObject.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); require_rangeWithCallback.rangeWithCallback(lowestColumnIndex, greatestColumnIndex, (columnIndex) => { require_rangeWithCallback.rangeWithCallback(lowestRowIndex, greatestRowIndex, (rowIndex) => { const cellProps = rows[rowIndex].cells[columnIndex]; updateData(rowIndex, cellProps?.column.id, ""); }); }); setActiveCellContent(null); }; //#endregion exports.handleCellDeletion = handleCellDeletion;