@rowsncolumns/spreadsheet-state 28.0.75 → 28.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/anchored-objects.d.ts +66 -0
- package/dist/cjs/api/anchored-objects.d.ts.map +1 -0
- package/dist/cjs/api/anchored-objects.js +259 -0
- package/dist/cjs/api/dependency.d.ts +13 -2
- package/dist/cjs/api/dependency.d.ts.map +1 -1
- package/dist/cjs/api/dependency.js +11 -5
- package/dist/cjs/api/formula.d.ts +61 -4
- package/dist/cjs/api/formula.d.ts.map +1 -1
- package/dist/cjs/api/formula.js +250 -61
- package/dist/cjs/api/merges.d.ts +8 -0
- package/dist/cjs/api/merges.d.ts.map +1 -1
- package/dist/cjs/api/merges.js +64 -1
- package/dist/cjs/api/named-range-structural.d.ts +62 -0
- package/dist/cjs/api/named-range-structural.d.ts.map +1 -0
- package/dist/cjs/api/named-range-structural.js +197 -0
- package/dist/cjs/api/range-rule-helpers.d.ts +45 -1
- package/dist/cjs/api/range-rule-helpers.d.ts.map +1 -1
- package/dist/cjs/api/range-rule-helpers.js +159 -6
- package/dist/cjs/api/structural-formula-update.d.ts.map +1 -1
- package/dist/cjs/api/structural-formula-update.js +24 -6
- package/dist/cjs/api/structural-guards.d.ts +78 -0
- package/dist/cjs/api/structural-guards.d.ts.map +1 -0
- package/dist/cjs/api/structural-guards.js +202 -0
- package/dist/cjs/api/structural-table-refs.d.ts +94 -0
- package/dist/cjs/api/structural-table-refs.d.ts.map +1 -0
- package/dist/cjs/api/structural-table-refs.js +313 -0
- package/dist/cjs/constants.d.ts +25 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +26 -0
- package/dist/cjs/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation-worker.js +64 -6
- package/dist/cjs/hooks/use-calculation.d.ts +7 -0
- package/dist/cjs/hooks/use-calculation.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation.js +15 -0
- package/dist/cjs/hooks/use-on-calculation-success.d.ts +7 -0
- package/dist/cjs/hooks/use-on-calculation-success.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-calculation-success.js +7 -1
- package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts +13 -3
- package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-cells-shift-left.js +27 -2
- package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts +13 -3
- package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-cells-shift-up.js +27 -2
- package/dist/cjs/hooks/use-on-delete-column.d.ts +13 -4
- package/dist/cjs/hooks/use-on-delete-column.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-column.js +14 -2
- package/dist/cjs/hooks/use-on-delete-row.d.ts +13 -4
- package/dist/cjs/hooks/use-on-delete-row.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-row.js +14 -2
- package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts +13 -3
- package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-cells-shift-down.js +27 -2
- package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts +13 -3
- package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-cells-shift-right.js +27 -2
- package/dist/cjs/hooks/use-on-insert-column.d.ts +10 -3
- package/dist/cjs/hooks/use-on-insert-column.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-column.js +33 -7
- package/dist/cjs/hooks/use-on-insert-row.d.ts +10 -3
- package/dist/cjs/hooks/use-on-insert-row.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-row.js +32 -7
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts +2 -2
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/cjs/hooks/use-spreadsheet-state.js +61 -15
- package/dist/cjs/hooks/use-structured-reference.d.ts.map +1 -1
- package/dist/cjs/hooks/use-structured-reference.js +10 -6
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/interface/calculation-interface.d.ts +9 -0
- package/dist/cjs/interface/calculation-interface.d.ts.map +1 -1
- package/dist/cjs/interface/calculation-interface.js +31 -2
- package/dist/cjs/interface/delete-cells-shift-left.d.ts +8 -1
- package/dist/cjs/interface/delete-cells-shift-left.d.ts.map +1 -1
- package/dist/cjs/interface/delete-cells-shift-left.js +158 -80
- package/dist/cjs/interface/delete-cells-shift-up.d.ts +9 -1
- package/dist/cjs/interface/delete-cells-shift-up.d.ts.map +1 -1
- package/dist/cjs/interface/delete-cells-shift-up.js +155 -73
- package/dist/cjs/interface/delete-column.d.ts +1 -1
- package/dist/cjs/interface/delete-column.d.ts.map +1 -1
- package/dist/cjs/interface/delete-column.js +90 -31
- package/dist/cjs/interface/delete-row.d.ts +1 -1
- package/dist/cjs/interface/delete-row.d.ts.map +1 -1
- package/dist/cjs/interface/delete-row.js +85 -26
- package/dist/cjs/interface/insert-cells-shift-down.d.ts +10 -1
- package/dist/cjs/interface/insert-cells-shift-down.d.ts.map +1 -1
- package/dist/cjs/interface/insert-cells-shift-down.js +147 -52
- package/dist/cjs/interface/insert-cells-shift-right.d.ts +10 -1
- package/dist/cjs/interface/insert-cells-shift-right.d.ts.map +1 -1
- package/dist/cjs/interface/insert-cells-shift-right.js +154 -58
- package/dist/cjs/interface/insert-column.d.ts +1 -1
- package/dist/cjs/interface/insert-column.d.ts.map +1 -1
- package/dist/cjs/interface/insert-column.js +46 -8
- package/dist/cjs/interface/insert-row.d.ts +1 -1
- package/dist/cjs/interface/insert-row.d.ts.map +1 -1
- package/dist/cjs/interface/insert-row.js +47 -10
- package/dist/cjs/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/cjs/interface/spreadsheet-interface.js +33 -0
- package/dist/cjs/sheet-cell.d.ts.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/api/anchored-objects.d.ts +66 -0
- package/dist/esm/api/anchored-objects.d.ts.map +1 -0
- package/dist/esm/api/anchored-objects.js +212 -0
- package/dist/esm/api/dependency.d.ts +13 -2
- package/dist/esm/api/dependency.d.ts.map +1 -1
- package/dist/esm/api/dependency.js +10 -4
- package/dist/esm/api/formula.d.ts +61 -4
- package/dist/esm/api/formula.d.ts.map +1 -1
- package/dist/esm/api/formula.js +238 -60
- package/dist/esm/api/merges.d.ts +8 -0
- package/dist/esm/api/merges.d.ts.map +1 -1
- package/dist/esm/api/merges.js +51 -0
- package/dist/esm/api/named-range-structural.d.ts +62 -0
- package/dist/esm/api/named-range-structural.d.ts.map +1 -0
- package/dist/esm/api/named-range-structural.js +176 -0
- package/dist/esm/api/range-rule-helpers.d.ts +45 -1
- package/dist/esm/api/range-rule-helpers.d.ts.map +1 -1
- package/dist/esm/api/range-rule-helpers.js +153 -1
- package/dist/esm/api/structural-formula-update.d.ts.map +1 -1
- package/dist/esm/api/structural-formula-update.js +24 -6
- package/dist/esm/api/structural-guards.d.ts +78 -0
- package/dist/esm/api/structural-guards.d.ts.map +1 -0
- package/dist/esm/api/structural-guards.js +186 -0
- package/dist/esm/api/structural-table-refs.d.ts +94 -0
- package/dist/esm/api/structural-table-refs.d.ts.map +1 -0
- package/dist/esm/api/structural-table-refs.js +219 -0
- package/dist/esm/constants.d.ts +25 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +26 -0
- package/dist/esm/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation-worker.js +45 -0
- package/dist/esm/hooks/use-calculation.d.ts +7 -0
- package/dist/esm/hooks/use-calculation.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation.js +15 -0
- package/dist/esm/hooks/use-on-calculation-success.d.ts +7 -0
- package/dist/esm/hooks/use-on-calculation-success.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-calculation-success.js +7 -1
- package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts +13 -3
- package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-cells-shift-left.js +26 -2
- package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts +13 -3
- package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-cells-shift-up.js +26 -2
- package/dist/esm/hooks/use-on-delete-column.d.ts +13 -4
- package/dist/esm/hooks/use-on-delete-column.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-column.js +14 -2
- package/dist/esm/hooks/use-on-delete-row.d.ts +13 -4
- package/dist/esm/hooks/use-on-delete-row.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-row.js +14 -2
- package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts +13 -3
- package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-cells-shift-down.js +26 -2
- package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts +13 -3
- package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-cells-shift-right.js +26 -2
- package/dist/esm/hooks/use-on-insert-column.d.ts +10 -3
- package/dist/esm/hooks/use-on-insert-column.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-column.js +33 -7
- package/dist/esm/hooks/use-on-insert-row.d.ts +10 -3
- package/dist/esm/hooks/use-on-insert-row.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-row.js +32 -7
- package/dist/esm/hooks/use-spreadsheet-state.d.ts +2 -2
- package/dist/esm/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/esm/hooks/use-spreadsheet-state.js +61 -15
- package/dist/esm/hooks/use-structured-reference.d.ts.map +1 -1
- package/dist/esm/hooks/use-structured-reference.js +10 -6
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/interface/calculation-interface.d.ts +9 -0
- package/dist/esm/interface/calculation-interface.d.ts.map +1 -1
- package/dist/esm/interface/calculation-interface.js +33 -2
- package/dist/esm/interface/delete-cells-shift-left.d.ts +8 -1
- package/dist/esm/interface/delete-cells-shift-left.d.ts.map +1 -1
- package/dist/esm/interface/delete-cells-shift-left.js +135 -59
- package/dist/esm/interface/delete-cells-shift-up.d.ts +9 -1
- package/dist/esm/interface/delete-cells-shift-up.d.ts.map +1 -1
- package/dist/esm/interface/delete-cells-shift-up.js +133 -53
- package/dist/esm/interface/delete-column.d.ts +1 -1
- package/dist/esm/interface/delete-column.d.ts.map +1 -1
- package/dist/esm/interface/delete-column.js +80 -11
- package/dist/esm/interface/delete-row.d.ts +1 -1
- package/dist/esm/interface/delete-row.d.ts.map +1 -1
- package/dist/esm/interface/delete-row.js +81 -11
- package/dist/esm/interface/insert-cells-shift-down.d.ts +10 -1
- package/dist/esm/interface/insert-cells-shift-down.d.ts.map +1 -1
- package/dist/esm/interface/insert-cells-shift-down.js +116 -47
- package/dist/esm/interface/insert-cells-shift-right.d.ts +10 -1
- package/dist/esm/interface/insert-cells-shift-right.d.ts.map +1 -1
- package/dist/esm/interface/insert-cells-shift-right.js +120 -51
- package/dist/esm/interface/insert-column.d.ts +1 -1
- package/dist/esm/interface/insert-column.d.ts.map +1 -1
- package/dist/esm/interface/insert-column.js +46 -8
- package/dist/esm/interface/insert-row.d.ts +1 -1
- package/dist/esm/interface/insert-row.d.ts.map +1 -1
- package/dist/esm/interface/insert-row.js +47 -10
- package/dist/esm/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/esm/interface/spreadsheet-interface.js +29 -0
- package/dist/esm/sheet-cell.d.ts.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +16 -16
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { CellInterface, GridRange } from "@rowsncolumns/common-types";
|
|
2
|
+
import type { EmbeddedChart, EmbeddedObject, ProtectedRange } from "@rowsncolumns/spreadsheet";
|
|
3
|
+
import type { Draft } from "immer";
|
|
4
|
+
/**
|
|
5
|
+
* Structural (whole row / whole column insert or delete) relocation of the
|
|
6
|
+
* objects Excel anchors to cells rather than storing inside them: floating
|
|
7
|
+
* objects (charts, pictures / embeds), the ranges a chart reads, and
|
|
8
|
+
* AllowEditRange (protected range) rectangles.
|
|
9
|
+
*
|
|
10
|
+
* Excel rules (Sheets agree on every one):
|
|
11
|
+
* - A floating object's anchor cell shifts like any cell: pushed down/right by
|
|
12
|
+
* an insert at or before it, pulled up/left by a delete before it. When the
|
|
13
|
+
* anchor row/column itself is deleted the object snaps to the first
|
|
14
|
+
* surviving cell at the deletion index (Move-and-size / Move-don't-size both
|
|
15
|
+
* move; only absolute anchors stay put). Size never changes.
|
|
16
|
+
* - A range (chart series, AllowEditRange) shifts like a formula reference:
|
|
17
|
+
* insert at/before the start moves it, insert strictly inside grows it,
|
|
18
|
+
* delete inside shrinks it, delete of the whole span removes it (`#REF!`).
|
|
19
|
+
*
|
|
20
|
+
* The span rule here mirrors `shift_facet_span` in `rnc-store` exactly so both
|
|
21
|
+
* engines relocate identically.
|
|
22
|
+
*/
|
|
23
|
+
export type StructuralAxis = "row" | "column";
|
|
24
|
+
export type StructuralOp = "insert" | "delete";
|
|
25
|
+
/**
|
|
26
|
+
* Shift the `[start, end]` span of a range along the edited axis. Returns the
|
|
27
|
+
* new span, or `null` when a delete consumes it entirely.
|
|
28
|
+
*/
|
|
29
|
+
export declare const shiftSpanLikeReference: (start: number, end: number, op: StructuralOp, index: number, count: number) => [number, number] | null;
|
|
30
|
+
/**
|
|
31
|
+
* Shift a single row/column index the way a cell (and everything anchored to
|
|
32
|
+
* it) moves: pushed by an insert at or before it, pulled back by a delete
|
|
33
|
+
* before it, snapped to the deletion index when its own row/column is
|
|
34
|
+
* removed.
|
|
35
|
+
*/
|
|
36
|
+
export declare const shiftAnchorIndex: (anchorIndex: number, op: StructuralOp, index: number, count: number) => number;
|
|
37
|
+
export declare const shiftAnchorCell: (anchor: CellInterface, axis: StructuralAxis, op: StructuralOp, index: number, count: number) => CellInterface;
|
|
38
|
+
/**
|
|
39
|
+
* Shift a grid rectangle with the reference rule along one axis. Returns the
|
|
40
|
+
* same object when nothing moved, a new one when it did, `null` when a delete
|
|
41
|
+
* consumed the whole span.
|
|
42
|
+
*/
|
|
43
|
+
export declare const shiftGridRangeLikeReference: <R extends GridRange>(range: R, axis: StructuralAxis, op: StructuralOp, index: number, count: number) => R | null;
|
|
44
|
+
/**
|
|
45
|
+
* Walk a chart spec and rewrite every `SheetRange` it holds on `sheetId` —
|
|
46
|
+
* `dataRange`, per-series / per-domain `sources`, error-bar `plusRange` /
|
|
47
|
+
* `minusRange`, and any future range-valued key — with the reference rule.
|
|
48
|
+
* A range the delete consumes entirely is removed: spliced out of arrays
|
|
49
|
+
* (`sources`), nulled on properties (`dataRange`) — the chart's `#REF!`.
|
|
50
|
+
* Unknown keys are left untouched. Mutates in place; returns whether anything
|
|
51
|
+
* changed.
|
|
52
|
+
*/
|
|
53
|
+
export declare const shiftChartSpecRanges: (spec: unknown, sheetId: number, axis: StructuralAxis, op: StructuralOp, index: number, count: number) => boolean;
|
|
54
|
+
/** Shift the anchor cell of every embed (picture, shape, text box…) on the edited sheet. */
|
|
55
|
+
export declare const shiftEmbedsOnStructuralChange: (draft: Draft<EmbeddedObject>[], sheetId: number, axis: StructuralAxis, op: StructuralOp, index: number, count: number) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Shift every chart on the edited sheet: its anchor cell like a floating
|
|
58
|
+
* object, and the ranges inside its spec like references.
|
|
59
|
+
*/
|
|
60
|
+
export declare const shiftChartsOnStructuralChange: (draft: Draft<EmbeddedChart>[], sheetId: number, axis: StructuralAxis, op: StructuralOp, index: number, count: number) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Shift AllowEditRange rectangles. A protected range without a rectangle
|
|
63
|
+
* (sheet-scoped protection) is untouched; one the delete consumes is removed.
|
|
64
|
+
*/
|
|
65
|
+
export declare const shiftProtectedRangesOnStructuralChange: (draft: Draft<ProtectedRange>[], sheetId: number, axis: StructuralAxis, op: StructuralOp, index: number, count: number) => void;
|
|
66
|
+
//# sourceMappingURL=anchored-objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchored-objects.d.ts","sourceRoot":"","sources":["../../../api/anchored-objects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EAEV,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,CAAC;AAC9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,KAAK,MAAM,EACX,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAerB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,MAAM,EACnB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,MASF,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,QAAQ,aAAa,EACrB,MAAM,cAAc,EACpB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,aASF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,SAAS,EAC7D,OAAO,CAAC,EACR,MAAM,cAAc,EACpB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,CAAC,GAAG,IAgBN,CAAC;AAgBF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,OAAO,EACb,SAAS,MAAM,EACf,MAAM,cAAc,EACpB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,OAoCF,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,6BAA6B,GACxC,OAAO,KAAK,CAAC,cAAc,CAAC,EAAE,EAC9B,SAAS,MAAM,EACf,MAAM,cAAc,EACpB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,SAUd,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GACxC,OAAO,KAAK,CAAC,aAAa,CAAC,EAAE,EAC7B,SAAS,MAAM,EACf,MAAM,cAAc,EACpB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,SAad,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sCAAsC,GACjD,OAAO,KAAK,CAAC,cAAc,CAAC,EAAE,EAC9B,SAAS,MAAM,EACf,MAAM,cAAc,EACpB,IAAI,YAAY,EAChB,OAAO,MAAM,EACb,OAAO,MAAM,SAyCd,CAAC"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { __assign, __read, __values } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Shift the `[start, end]` span of a range along the edited axis. Returns the
|
|
4
|
+
* new span, or `null` when a delete consumes it entirely.
|
|
5
|
+
*/
|
|
6
|
+
export var shiftSpanLikeReference = function (start, end, op, index, count) {
|
|
7
|
+
if (count <= 0)
|
|
8
|
+
return [start, end];
|
|
9
|
+
if (op === "insert") {
|
|
10
|
+
if (index <= start)
|
|
11
|
+
return [start + count, end + count];
|
|
12
|
+
if (index <= end)
|
|
13
|
+
return [start, end + count];
|
|
14
|
+
return [start, end];
|
|
15
|
+
}
|
|
16
|
+
var deleteEnd = index + count - 1;
|
|
17
|
+
if (start > deleteEnd)
|
|
18
|
+
return [start - count, end - count];
|
|
19
|
+
if (end < index)
|
|
20
|
+
return [start, end];
|
|
21
|
+
var nextStart = start < index ? start : start > deleteEnd ? start - count : index;
|
|
22
|
+
var nextEnd = end < index ? end : end > deleteEnd ? end - count : index - 1;
|
|
23
|
+
if (nextStart > nextEnd)
|
|
24
|
+
return null;
|
|
25
|
+
return [nextStart, nextEnd];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Shift a single row/column index the way a cell (and everything anchored to
|
|
29
|
+
* it) moves: pushed by an insert at or before it, pulled back by a delete
|
|
30
|
+
* before it, snapped to the deletion index when its own row/column is
|
|
31
|
+
* removed.
|
|
32
|
+
*/
|
|
33
|
+
export var shiftAnchorIndex = function (anchorIndex, op, index, count) {
|
|
34
|
+
if (count <= 0)
|
|
35
|
+
return anchorIndex;
|
|
36
|
+
if (op === "insert") {
|
|
37
|
+
return anchorIndex >= index ? anchorIndex + count : anchorIndex;
|
|
38
|
+
}
|
|
39
|
+
var deleteEnd = index + count - 1;
|
|
40
|
+
if (anchorIndex > deleteEnd)
|
|
41
|
+
return anchorIndex - count;
|
|
42
|
+
if (anchorIndex >= index)
|
|
43
|
+
return Math.max(1, index);
|
|
44
|
+
return anchorIndex;
|
|
45
|
+
};
|
|
46
|
+
export var shiftAnchorCell = function (anchor, axis, op, index, count) {
|
|
47
|
+
if (axis === "row") {
|
|
48
|
+
var rowIndex = shiftAnchorIndex(anchor.rowIndex, op, index, count);
|
|
49
|
+
return rowIndex === anchor.rowIndex ? anchor : __assign(__assign({}, anchor), { rowIndex: rowIndex });
|
|
50
|
+
}
|
|
51
|
+
var columnIndex = shiftAnchorIndex(anchor.columnIndex, op, index, count);
|
|
52
|
+
return columnIndex === anchor.columnIndex
|
|
53
|
+
? anchor
|
|
54
|
+
: __assign(__assign({}, anchor), { columnIndex: columnIndex });
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Shift a grid rectangle with the reference rule along one axis. Returns the
|
|
58
|
+
* same object when nothing moved, a new one when it did, `null` when a delete
|
|
59
|
+
* consumed the whole span.
|
|
60
|
+
*/
|
|
61
|
+
export var shiftGridRangeLikeReference = function (range, axis, op, index, count) {
|
|
62
|
+
var _a;
|
|
63
|
+
var _b = __read(axis === "row"
|
|
64
|
+
? ["startRowIndex", "endRowIndex"]
|
|
65
|
+
: ["startColumnIndex", "endColumnIndex"], 2), startKey = _b[0], endKey = _b[1];
|
|
66
|
+
var span = shiftSpanLikeReference(range[startKey], range[endKey], op, index, count);
|
|
67
|
+
if (!span)
|
|
68
|
+
return null;
|
|
69
|
+
var _c = __read(span, 2), start = _c[0], end = _c[1];
|
|
70
|
+
if (start === range[startKey] && end === range[endKey])
|
|
71
|
+
return range;
|
|
72
|
+
return __assign(__assign({}, range), (_a = {}, _a[startKey] = start, _a[endKey] = end, _a));
|
|
73
|
+
};
|
|
74
|
+
var isSheetRangeLike = function (value) {
|
|
75
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
76
|
+
return false;
|
|
77
|
+
var v = value;
|
|
78
|
+
return (typeof v.sheetId === "number" &&
|
|
79
|
+
typeof v.startRowIndex === "number" &&
|
|
80
|
+
typeof v.endRowIndex === "number" &&
|
|
81
|
+
typeof v.startColumnIndex === "number" &&
|
|
82
|
+
typeof v.endColumnIndex === "number");
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Walk a chart spec and rewrite every `SheetRange` it holds on `sheetId` —
|
|
86
|
+
* `dataRange`, per-series / per-domain `sources`, error-bar `plusRange` /
|
|
87
|
+
* `minusRange`, and any future range-valued key — with the reference rule.
|
|
88
|
+
* A range the delete consumes entirely is removed: spliced out of arrays
|
|
89
|
+
* (`sources`), nulled on properties (`dataRange`) — the chart's `#REF!`.
|
|
90
|
+
* Unknown keys are left untouched. Mutates in place; returns whether anything
|
|
91
|
+
* changed.
|
|
92
|
+
*/
|
|
93
|
+
export var shiftChartSpecRanges = function (spec, sheetId, axis, op, index, count) {
|
|
94
|
+
var changed = false;
|
|
95
|
+
var shiftRange = function (range) {
|
|
96
|
+
if (range.sheetId !== sheetId)
|
|
97
|
+
return range;
|
|
98
|
+
var next = shiftGridRangeLikeReference(range, axis, op, index, count);
|
|
99
|
+
if (next !== range)
|
|
100
|
+
changed = true;
|
|
101
|
+
return next;
|
|
102
|
+
};
|
|
103
|
+
var walk = function (node) {
|
|
104
|
+
var e_1, _a;
|
|
105
|
+
if (!node || typeof node !== "object")
|
|
106
|
+
return;
|
|
107
|
+
if (Array.isArray(node)) {
|
|
108
|
+
for (var i = node.length - 1; i >= 0; i--) {
|
|
109
|
+
var item = node[i];
|
|
110
|
+
if (isSheetRangeLike(item)) {
|
|
111
|
+
var next = shiftRange(item);
|
|
112
|
+
if (next === null)
|
|
113
|
+
node.splice(i, 1);
|
|
114
|
+
else if (next !== item)
|
|
115
|
+
node[i] = next;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
walk(item);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
var obj = node;
|
|
124
|
+
try {
|
|
125
|
+
for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
126
|
+
var key = _c.value;
|
|
127
|
+
var value = obj[key];
|
|
128
|
+
if (isSheetRangeLike(value)) {
|
|
129
|
+
var next = shiftRange(value);
|
|
130
|
+
if (next !== value)
|
|
131
|
+
obj[key] = next;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
walk(value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
139
|
+
finally {
|
|
140
|
+
try {
|
|
141
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
142
|
+
}
|
|
143
|
+
finally { if (e_1) throw e_1.error; }
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
walk(spec);
|
|
147
|
+
return changed;
|
|
148
|
+
};
|
|
149
|
+
/** Shift the anchor cell of every embed (picture, shape, text box…) on the edited sheet. */
|
|
150
|
+
export var shiftEmbedsOnStructuralChange = function (draft, sheetId, axis, op, index, count) {
|
|
151
|
+
var e_2, _a;
|
|
152
|
+
try {
|
|
153
|
+
for (var draft_1 = __values(draft), draft_1_1 = draft_1.next(); !draft_1_1.done; draft_1_1 = draft_1.next()) {
|
|
154
|
+
var embed = draft_1_1.value;
|
|
155
|
+
var position = embed.position;
|
|
156
|
+
if (!position || position.sheetId !== sheetId)
|
|
157
|
+
continue;
|
|
158
|
+
var overlay = position.overlayPosition;
|
|
159
|
+
if (!(overlay === null || overlay === void 0 ? void 0 : overlay.anchorCell))
|
|
160
|
+
continue;
|
|
161
|
+
var next = shiftAnchorCell(overlay.anchorCell, axis, op, index, count);
|
|
162
|
+
if (next !== overlay.anchorCell)
|
|
163
|
+
overlay.anchorCell = next;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
167
|
+
finally {
|
|
168
|
+
try {
|
|
169
|
+
if (draft_1_1 && !draft_1_1.done && (_a = draft_1.return)) _a.call(draft_1);
|
|
170
|
+
}
|
|
171
|
+
finally { if (e_2) throw e_2.error; }
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Shift every chart on the edited sheet: its anchor cell like a floating
|
|
176
|
+
* object, and the ranges inside its spec like references.
|
|
177
|
+
*/
|
|
178
|
+
export var shiftChartsOnStructuralChange = function (draft, sheetId, axis, op, index, count) {
|
|
179
|
+
var e_3, _a;
|
|
180
|
+
var _b;
|
|
181
|
+
try {
|
|
182
|
+
for (var draft_2 = __values(draft), draft_2_1 = draft_2.next(); !draft_2_1.done; draft_2_1 = draft_2.next()) {
|
|
183
|
+
var chart = draft_2_1.value;
|
|
184
|
+
var position = chart.position;
|
|
185
|
+
if ((position === null || position === void 0 ? void 0 : position.sheetId) === sheetId && ((_b = position.overlayPosition) === null || _b === void 0 ? void 0 : _b.anchorCell)) {
|
|
186
|
+
var overlay = position.overlayPosition;
|
|
187
|
+
var next = shiftAnchorCell(overlay.anchorCell, axis, op, index, count);
|
|
188
|
+
if (next !== overlay.anchorCell)
|
|
189
|
+
overlay.anchorCell = next;
|
|
190
|
+
}
|
|
191
|
+
// Series ranges may point at ANY sheet, so the spec walk is not gated on
|
|
192
|
+
// the chart's own sheet.
|
|
193
|
+
shiftChartSpecRanges(chart.spec, sheetId, axis, op, index, count);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
197
|
+
finally {
|
|
198
|
+
try {
|
|
199
|
+
if (draft_2_1 && !draft_2_1.done && (_a = draft_2.return)) _a.call(draft_2);
|
|
200
|
+
}
|
|
201
|
+
finally { if (e_3) throw e_3.error; }
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Shift AllowEditRange rectangles. A protected range without a rectangle
|
|
206
|
+
* (sheet-scoped protection) is untouched; one the delete consumes is removed.
|
|
207
|
+
*/
|
|
208
|
+
export var shiftProtectedRangesOnStructuralChange = function (draft, sheetId, axis, op, index, count) {
|
|
209
|
+
var e_4, _a;
|
|
210
|
+
var _b = __read(axis === "row"
|
|
211
|
+
? ["startRowIndex", "endRowIndex"]
|
|
212
|
+
: ["startColumnIndex", "endColumnIndex"], 2), startKey = _b[0], endKey = _b[1];
|
|
213
|
+
for (var i = draft.length - 1; i >= 0; i--) {
|
|
214
|
+
var protectedRange = draft[i];
|
|
215
|
+
var range = protectedRange.range;
|
|
216
|
+
if (range.sheetId !== sheetId)
|
|
217
|
+
continue;
|
|
218
|
+
var start = range[startKey];
|
|
219
|
+
var end = range[endKey];
|
|
220
|
+
if (typeof start !== "number" || typeof end !== "number")
|
|
221
|
+
continue;
|
|
222
|
+
var span = shiftSpanLikeReference(start, end, op, index, count);
|
|
223
|
+
if (!span) {
|
|
224
|
+
draft.splice(i, 1);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (span[0] !== start)
|
|
228
|
+
range[startKey] = span[0];
|
|
229
|
+
if (span[1] !== end)
|
|
230
|
+
range[endKey] = span[1];
|
|
231
|
+
if (protectedRange.unprotectedRanges) {
|
|
232
|
+
var kept = [];
|
|
233
|
+
var unprotectedChanged = false;
|
|
234
|
+
try {
|
|
235
|
+
for (var _c = (e_4 = void 0, __values(protectedRange.unprotectedRanges)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
236
|
+
var unprotected = _d.value;
|
|
237
|
+
if (unprotected.sheetId !== sheetId) {
|
|
238
|
+
kept.push(unprotected);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
var next = shiftGridRangeLikeReference(unprotected, axis, op, index, count);
|
|
242
|
+
if (next !== unprotected)
|
|
243
|
+
unprotectedChanged = true;
|
|
244
|
+
if (next)
|
|
245
|
+
kept.push(next);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
249
|
+
finally {
|
|
250
|
+
try {
|
|
251
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
252
|
+
}
|
|
253
|
+
finally { if (e_4) throw e_4.error; }
|
|
254
|
+
}
|
|
255
|
+
if (unprotectedChanged)
|
|
256
|
+
protectedRange.unprotectedRanges = kept;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
@@ -3,8 +3,8 @@ import type { CellData } from "@rowsncolumns/spreadsheet";
|
|
|
3
3
|
import type { Draft } from "immer";
|
|
4
4
|
import type { useCalculation } from "../hooks/use-calculation";
|
|
5
5
|
import type { CellXfsRegistry } from "../hooks/use-cellxfs-registry";
|
|
6
|
-
import type { SharedStringRegistry } from "../hooks/use-ss-registry";
|
|
7
6
|
import type { SheetData } from "../hooks/use-spreadsheet-state";
|
|
7
|
+
import type { SharedStringRegistry } from "../hooks/use-ss-registry";
|
|
8
8
|
import type { RecalcCellCoordinate } from "../types";
|
|
9
9
|
type ProcessDependentCellsProps<T extends CellData> = {
|
|
10
10
|
rowIndex: number;
|
|
@@ -38,7 +38,7 @@ export declare const collectUniqueDependentsForRange: <T extends CellData>(param
|
|
|
38
38
|
rowIndex: number;
|
|
39
39
|
columnIndex: number;
|
|
40
40
|
}>;
|
|
41
|
-
export declare const moveFormulaAtPosition: <T extends CellData>({ draft, position, destinationSheetId, activeSheetName, enqueueCalculation, enqueueGraphOperation, recalcCells, movedKeys, rowDelta, columnDelta, sourceRange, locale, rowCount, columnCount, cellXfsRegistry, sharedStringRegistry, }: {
|
|
41
|
+
export declare const moveFormulaAtPosition: <T extends CellData>({ draft, position, destinationSheetId, activeSheetName, enqueueCalculation, enqueueGraphOperation, recalcCells, movedKeys, rowDelta, columnDelta, sourceRange, deletedRange, destinationPosition, locale, rowCount, columnCount, cellXfsRegistry, sharedStringRegistry, }: {
|
|
42
42
|
draft: Draft<SheetData<T>>;
|
|
43
43
|
position: {
|
|
44
44
|
sheetId: number;
|
|
@@ -54,6 +54,17 @@ export declare const moveFormulaAtPosition: <T extends CellData>({ draft, positi
|
|
|
54
54
|
rowDelta?: number;
|
|
55
55
|
columnDelta?: number;
|
|
56
56
|
sourceRange?: GridRange;
|
|
57
|
+
/** Cells removed by a delete-cells shift — references into it become `#REF!` (SHF-09). */
|
|
58
|
+
deletedRange?: GridRange;
|
|
59
|
+
/**
|
|
60
|
+
* Where the formula cell itself ends up. Defaults to `position + delta` (the cell moves with the
|
|
61
|
+
* shift). A dependent OUTSIDE the shifted band keeps its place while its references into the
|
|
62
|
+
* band still move by the delta — pass its own position here so the graph is re-keyed correctly.
|
|
63
|
+
*/
|
|
64
|
+
destinationPosition?: {
|
|
65
|
+
rowIndex: number;
|
|
66
|
+
columnIndex: number;
|
|
67
|
+
};
|
|
57
68
|
locale?: string;
|
|
58
69
|
rowCount?: number;
|
|
59
70
|
columnCount?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency.d.ts","sourceRoot":"","sources":["../../../api/dependency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"dependency.d.ts","sourceRoot":"","sources":["../../../api/dependency.ts"],"names":[],"mappings":"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"}
|
|
@@ -232,8 +232,8 @@ export var collectUniqueDependentsForRange = function (params) {
|
|
|
232
232
|
};
|
|
233
233
|
// Process a single formula move at a specific position with the specified deltas.
|
|
234
234
|
export var moveFormulaAtPosition = function (_a) {
|
|
235
|
-
var _b, _c;
|
|
236
|
-
var draft = _a.draft, position = _a.position, destinationSheetId = _a.destinationSheetId, activeSheetName = _a.activeSheetName, enqueueCalculation = _a.enqueueCalculation, enqueueGraphOperation = _a.enqueueGraphOperation, recalcCells = _a.recalcCells, movedKeys = _a.movedKeys,
|
|
235
|
+
var _b, _c, _d, _e;
|
|
236
|
+
var draft = _a.draft, position = _a.position, destinationSheetId = _a.destinationSheetId, activeSheetName = _a.activeSheetName, enqueueCalculation = _a.enqueueCalculation, enqueueGraphOperation = _a.enqueueGraphOperation, recalcCells = _a.recalcCells, movedKeys = _a.movedKeys, _f = _a.rowDelta, rowDelta = _f === void 0 ? 0 : _f, _g = _a.columnDelta, columnDelta = _g === void 0 ? 0 : _g, sourceRange = _a.sourceRange, deletedRange = _a.deletedRange, destinationPosition = _a.destinationPosition, locale = _a.locale, rowCount = _a.rowCount, columnCount = _a.columnCount, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry;
|
|
237
237
|
var sheetCell = new SheetCell();
|
|
238
238
|
var currentSheet = createSheetDraft(draft, position.sheetId, position.rowIndex);
|
|
239
239
|
var cellData = (_c = (_b = currentSheet[position.rowIndex]) === null || _b === void 0 ? void 0 : _b.values) === null || _c === void 0 ? void 0 : _c[position.columnIndex];
|
|
@@ -241,11 +241,17 @@ export var moveFormulaAtPosition = function (_a) {
|
|
|
241
241
|
if (!movedKeys.has(sheetCell.key) && sheetCell.isFormula()) {
|
|
242
242
|
movedKeys.add(sheetCell.key);
|
|
243
243
|
var previousFormula = sheetCell.formula;
|
|
244
|
-
var newRowIndex = position.rowIndex + rowDelta;
|
|
245
|
-
var newColumnIndex = position.columnIndex + columnDelta;
|
|
244
|
+
var newRowIndex = (_d = destinationPosition === null || destinationPosition === void 0 ? void 0 : destinationPosition.rowIndex) !== null && _d !== void 0 ? _d : position.rowIndex + rowDelta;
|
|
245
|
+
var newColumnIndex = (_e = destinationPosition === null || destinationPosition === void 0 ? void 0 : destinationPosition.columnIndex) !== null && _e !== void 0 ? _e : position.columnIndex + columnDelta;
|
|
246
246
|
var resolvedSheetName = activeSheetName !== null && activeSheetName !== void 0 ? activeSheetName : "";
|
|
247
|
-
|
|
247
|
+
// The delta is applied to the references inside `sourceRange`; the formula cell's own
|
|
248
|
+
// destination (for the graph re-key) may differ when it does not move itself.
|
|
249
|
+
sheetCell.moveFormula({ rowIndex: position.rowIndex, columnIndex: position.columnIndex }, {
|
|
250
|
+
rowIndex: position.rowIndex + rowDelta,
|
|
251
|
+
columnIndex: position.columnIndex + columnDelta,
|
|
252
|
+
}, resolvedSheetName, {
|
|
248
253
|
exclusionRange: sourceRange,
|
|
254
|
+
deletedRange: deletedRange,
|
|
249
255
|
rowCount: rowCount,
|
|
250
256
|
columnCount: columnCount,
|
|
251
257
|
});
|
|
@@ -22,6 +22,23 @@ export declare const updateNamedRangeName: (formulaValue: string, newName: strin
|
|
|
22
22
|
* @param newName
|
|
23
23
|
*/
|
|
24
24
|
export declare const updateColumnName: (formulaValue: string, newName: string, oldName: string) => string;
|
|
25
|
+
/** The column specifier Excel writes for a deleted table column (`Table1[@#REF!]`). */
|
|
26
|
+
export declare const REF_ERROR_COLUMN = "#REF!";
|
|
27
|
+
/**
|
|
28
|
+
* Rewrite every structured reference into `tableName` to the `#REF!` token —
|
|
29
|
+
* Excel's text for a formula whose table was deleted (`=SUM(Table1[Price])`
|
|
30
|
+
* → `=SUM(#REF!)`), so the cell evaluates to `#REF!` rather than `#NAME?`.
|
|
31
|
+
* Returns the input unchanged when the formula never names the table.
|
|
32
|
+
*/
|
|
33
|
+
export declare const breakTableReferencesInFormula: (formulaValue: string, tableName: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Rewrite the column specifiers of `columnNames` inside structured references
|
|
36
|
+
* to `tableName` (or, when `tableName` is undefined, the bare this-row form
|
|
37
|
+
* `[@Col]` whose table is implied by the formula's own cell) to `#REF!` —
|
|
38
|
+
* Excel's text for a deleted table column (`=Table1[@Qty]*2` →
|
|
39
|
+
* `=Table1[@#REF!]*2`). Keeps every other character of the reference as typed.
|
|
40
|
+
*/
|
|
41
|
+
export declare const breakTableColumnsInFormula: (formulaValue: string, tableName: string | undefined, columnNames: string[]) => string;
|
|
25
42
|
/**
|
|
26
43
|
* Converts tokens to string
|
|
27
44
|
* @param tokens
|
|
@@ -46,24 +63,64 @@ export declare const isAbsoluteColumnReference: (formula: string | undefined) =>
|
|
|
46
63
|
* @param formula
|
|
47
64
|
*/
|
|
48
65
|
export declare const isAbsoluteRowReference: (formula: string | undefined) => boolean;
|
|
66
|
+
export type StructuralRangeRewriteOptions = {
|
|
67
|
+
/**
|
|
68
|
+
* Whether references WITHOUT a sheet qualifier resolve to the edited sheet.
|
|
69
|
+
* True for a formula that lives on the edited sheet; false for a formula on
|
|
70
|
+
* another sheet, whose bare `A1:A3` is its own sheet's range and must not
|
|
71
|
+
* move when the edited sheet changes shape.
|
|
72
|
+
*/
|
|
73
|
+
includeUnqualifiedReferences?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Restrict the rewrite to ranges whose PERPENDICULAR span lies inside this
|
|
76
|
+
* band — an insert/delete-cells shift of columns `B:C` only touches ranges
|
|
77
|
+
* that live entirely inside columns B..C (SHF-08); a wider range keeps its
|
|
78
|
+
* address (SHF-07). Whole-column and whole-row references span the entire
|
|
79
|
+
* sheet, so they never fall inside a band.
|
|
80
|
+
*/
|
|
81
|
+
bandSpan?: RangeBandSpan;
|
|
82
|
+
};
|
|
83
|
+
/** Alias kept for callers that import the scope options under this name. */
|
|
84
|
+
export type StructuralFormulaScopeOptions = StructuralRangeRewriteOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Restricts `expandRangesInFormula` / `contractRangesInFormula` to ranges whose PERPENDICULAR span
|
|
87
|
+
* lies within a band — an insert/delete-cells shift of columns `B:C` only expands ranges that live
|
|
88
|
+
* entirely inside columns B..C (SHF-08); a wider range keeps its address (SHF-07). Whole-column and
|
|
89
|
+
* whole-row references span the entire sheet, so they never fall inside a band.
|
|
90
|
+
*/
|
|
91
|
+
export type RangeBandSpan = {
|
|
92
|
+
startIndex: number;
|
|
93
|
+
endIndex: number;
|
|
94
|
+
};
|
|
49
95
|
/**
|
|
50
96
|
* Expands ranges in a formula when rows or columns are inserted within the range
|
|
51
97
|
* @param formula The formula to process
|
|
52
98
|
* @param insertionIndex The row or column index where insertion happens
|
|
53
99
|
* @param count Number of rows or columns being inserted
|
|
54
100
|
* @param dimension Whether inserting 'row' or 'column'
|
|
55
|
-
* @param activeSheetName
|
|
101
|
+
* @param activeSheetName Name of the EDITED sheet: only references that resolve
|
|
102
|
+
* to it are touched
|
|
103
|
+
* @param options `includeUnqualifiedReferences` — whether references without a
|
|
104
|
+
* sheet qualifier resolve to the edited sheet (true when the formula lives on
|
|
105
|
+
* it; false for a formula on another sheet, whose bare `A1:A3` is its own)
|
|
56
106
|
* @returns The formula with expanded ranges, or undefined if no changes
|
|
57
107
|
*/
|
|
58
|
-
export declare const expandRangesInFormula: (formula: string | undefined, insertionIndex: number, count: number, dimension: "row" | "column", activeSheetName: string) => string | undefined;
|
|
108
|
+
export declare const expandRangesInFormula: (formula: string | undefined, insertionIndex: number, count: number, dimension: "row" | "column", activeSheetName: string, options?: StructuralRangeRewriteOptions) => string | undefined;
|
|
59
109
|
/**
|
|
60
110
|
* Contracts ranges in a formula when rows or columns are deleted within the range
|
|
61
111
|
* @param formula The formula to process
|
|
62
112
|
* @param deletionIndex The row or column index where deletion starts
|
|
63
113
|
* @param count Number of rows or columns being deleted
|
|
64
114
|
* @param dimension Whether deleting 'row' or 'column'
|
|
65
|
-
* @param activeSheetName
|
|
115
|
+
* @param activeSheetName Name of the EDITED sheet: only references that resolve
|
|
116
|
+
* to it are touched
|
|
117
|
+
* @param options `includeUnqualifiedReferences` — see `expandRangesInFormula`
|
|
66
118
|
* @returns The formula with contracted ranges, or undefined if no changes
|
|
119
|
+
*
|
|
120
|
+
* Excel semantics for the deleted band: a range whose rows/columns are ALL
|
|
121
|
+
* deleted becomes the `#REF!` token (`=SUM(A2:A3)` → `=SUM(#REF!)`); a single
|
|
122
|
+
* cell reference into the band becomes `#REF!` (`=A3+1` → `=#REF!+1`, a spill
|
|
123
|
+
* reference `=C1#` → `=#REF!#`); a partially covered range shrinks.
|
|
67
124
|
*/
|
|
68
|
-
export declare const contractRangesInFormula: (formula: string | undefined, deletionIndex: number, count: number, dimension: "row" | "column", activeSheetName: string) => string | undefined;
|
|
125
|
+
export declare const contractRangesInFormula: (formula: string | undefined, deletionIndex: number, count: number, dimension: "row" | "column", activeSheetName: string, options?: StructuralRangeRewriteOptions) => string | undefined;
|
|
69
126
|
//# sourceMappingURL=formula.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formula.d.ts","sourceRoot":"","sources":["../../../api/formula.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formula.d.ts","sourceRoot":"","sources":["../../../api/formula.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,2BAA2B,CAAC;AAUpE,OAAO,EACL,yBAAyB,EACzB,eAAe,EACf,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAElF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,cAAc,MAAM,EACpB,SAAS,MAAM,EACf,SAAS,MAAM,WA4BhB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,MAAM,EACpB,SAAS,MAAM,EACf,SAAS,MAAM,WAehB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAC3B,cAAc,MAAM,EACpB,SAAS,MAAM,EACf,SAAS,MAAM,WAYhB,CAAC;AAEF,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAgDxC;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GACxC,cAAc,MAAM,EACpB,WAAW,MAAM,KAChB,MA4BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,cAAc,MAAM,EACpB,WAAW,MAAM,GAAG,SAAS,EAC7B,aAAa,MAAM,EAAE,KACpB,MA+BF,CAAC;AAaF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,EAAE,WAU/C,CAAC;AAiBF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GACpC,SAAS,MAAM,EACf,UAAU,MAAM,EAChB,aAAa,MAAM,WAGpB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,MAAM,GAAG,SAAS,YAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,MAAM,GAAG,SAAS,YAGjE,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;;;OAKG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF,4EAA4E;AAC5E,MAAM,MAAM,6BAA6B,GAAG,6BAA6B,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAmBrE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,GAAG,SAAS,EAC3B,gBAAgB,MAAM,EACtB,OAAO,MAAM,EACb,WAAW,KAAK,GAAG,QAAQ,EAC3B,iBAAiB,MAAM,EACvB,UAAS,6BAAkC,KAC1C,MAAM,GAAG,SAyKX,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,GAAG,SAAS,EAC3B,eAAe,MAAM,EACrB,OAAO,MAAM,EACb,WAAW,KAAK,GAAG,QAAQ,EAC3B,iBAAiB,MAAM,EACvB,UAAS,6BAAkC,KAC1C,MAAM,GAAG,SAkPX,CAAC"}
|