@carbon/ibm-products
Version:
Carbon for IBM Products
45 lines (40 loc) • 2.03 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
var deepCloneObject = require('../../../global/js/utils/deepCloneObject.js');
var rangeWithCallback = require('../../../global/js/utils/rangeWithCallback.js');
const handleCellDeletion = _ref => {
let {
activeCellCoordinates,
selectionAreas,
currentMatcher,
rows,
setActiveCellContent,
updateData
} = _ref;
// This means that the delete key has been pressed when the active cell is in a header,
// not within the spreadsheet body. To delete an entire row/column, it must first be
// selected, and then can be deleted.
if (activeCellCoordinates?.column === 'header' || activeCellCoordinates?.row === 'header') {
return;
}
const selectionAreaClone = deepCloneObject.deepCloneObject(selectionAreas);
const indexOfCurrentSelectionArea = selectionAreaClone.findIndex(item => item.matcher === currentMatcher);
const selectionAreaToEmptyContents = selectionAreaClone[indexOfCurrentSelectionArea];
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.rangeWithCallback(lowestColumnIndex, greatestColumnIndex, columnIndex => {
rangeWithCallback.rangeWithCallback(lowestRowIndex, greatestRowIndex, rowIndex => {
const cellProps = rows[rowIndex].cells[columnIndex];
updateData(rowIndex, cellProps?.column.id, '');
});
});
setActiveCellContent(null);
};
exports.handleCellDeletion = handleCellDeletion;