@carbon/ibm-products
Version:
Carbon for IBM Products
30 lines (28 loc) • 1.25 kB
JavaScript
/**
* 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");
//#region src/components/DataSpreadsheet/utils/checkActiveHeaderCell.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 checkActiveHeaderCell = (headerIndex, selectionAreas, headerType) => {
const areasCloned = require_deepCloneObject.deepCloneObject(selectionAreas);
const activeRowIndexes = [];
areasCloned.forEach((area) => {
const greatestRowIndex = Math.max(area.point1?.[headerType], area.point2?.[headerType]);
const lowestRowIndex = Math.min(area.point1?.[headerType], area.point2?.[headerType]);
for (let i = lowestRowIndex; i <= greatestRowIndex; i++) activeRowIndexes.push(i);
});
const activeRowIndexesNoDuplicates = [...new Set(activeRowIndexes)];
if (areasCloned?.length && activeRowIndexesNoDuplicates.includes(headerIndex)) return true;
return false;
};
//#endregion
exports.checkActiveHeaderCell = checkActiveHeaderCell;