/** * @license * Copyright (c) 2024 Handsoncode. All rights reserved. */ import { AddressDependency, collectDependencies } from '../parser'; import { FormulaVertex } from './FormulaCellVertex'; import { RangeVertex } from './RangeVertex'; export const collectAddressesDependentToRange = (functionRegistry, vertex, range, lazilyTransformingAstService, dependencyGraph) => { if (vertex instanceof RangeVertex) { const intersection = vertex.range.intersectionWith(range); if (intersection !== undefined) { return Array.from(intersection.addresses(dependencyGraph)); } else { return []; } } let formula; let address; if (vertex instanceof FormulaVertex) { formula = vertex.getFormula(lazilyTransformingAstService); address = vertex.getAddress(lazilyTransformingAstService); } else { return []; } return collectDependencies(formula, functionRegistry).filter(d => d instanceof AddressDependency).map(d => d.dependency.toSimpleCellAddress(address)).filter(d => range.addressInRange(d)); };