import type {QuantityInputs} from './model'; import type {QuantitySnapshot} from './project-inputs'; import {projectRecords} from './project-inputs'; export type ExportScope='selected'|'all'; export function exportRecords(snapshot:QuantitySnapshot,scope:ExportScope){ return projectRecords(snapshot).filter(r=>scope==='all'||r.pier.input.name===snapshot.selected); } /** Preserve edits made while PNG/Excel generation awaited IO, even across project replacement. */ export function finishQuantityExport(start:QuantitySnapshot,scope:ExportScope,live:QuantitySnapshot,save:(name:string,data:QuantityInputs)=>void):string[]{ const current=projectRecords(live),changed:string[]=[]; for(const before of exportRecords(start,scope)){ const after=current.find(r=>r.pier.input.name===before.pier.input.name); if(!after||JSON.stringify(start.project)!==JSON.stringify(live.project)||after.pier.dirty||!after.result||after.pier.model!==before.pier.model||after.result.signature!==before.result?.signature||JSON.stringify(after.stored)!==JSON.stringify(before.stored)){ changed.push(before.pier.input.name);continue; } save(after.pier.input.name,{...after.stored,lastSignature:after.result.signature}); } return changed; }