@sheetxl/sdk 0.7.28-beta.3 → 0.8.0-beta.1

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.
Files changed (66) hide show
  1. package/browser/cjs/{BX6A6xGDOr_td9mw.cjs → BatsV2UUraVDCRXm.cjs} +1 -1
  2. package/browser/cjs/CUz53T65cRGQRgvv.cjs +33 -0
  3. package/browser/cjs/{CWCKcp58KidyndaL.cjs → DU0kYUtdFa3jK-im.cjs} +1 -1
  4. package/browser/cjs/{B4PKKgaDTG9aSO-f.cjs → Dv4yIPLV98M5zLHa.cjs} +1 -1
  5. package/browser/cjs/a0Z-SXs_N71CtqYb.cjs +1 -0
  6. package/browser/cjs/index.cjs +2 -2
  7. package/browser/esm/{Dv8FyXyeygJPXoHo.mjs → 6JKSOvc5czaQB2Bj.mjs} +3 -3
  8. package/browser/esm/{DZfds6s3ayTZrozO.mjs → B0HS42a7lga1k1U_.mjs} +1 -1
  9. package/browser/esm/{C78IaCXqwCcraBPe.mjs → BtuJ9AGzeURtAsGo.mjs} +6946 -5790
  10. package/browser/esm/{CX1NO_a1QPjXDvTU.mjs → DGU6sM25u0EWCKl1.mjs} +3 -3
  11. package/browser/esm/{B1gpnr-7kLU7jTy-.mjs → DlPMeIyxT9tG_WDk.mjs} +2 -2
  12. package/browser/esm/{CPgz9_iM7xyAcytg.mjs → f2G3QRgEbvFJcoa2.mjs} +2 -2
  13. package/browser/esm/index.mjs +17 -14
  14. package/browser/esm/{Rj8e7SashcMlcdZJ.mjs → uyWBMSIxMlt8n5Z3.mjs} +2 -2
  15. package/node/esm/{8VtzCFSmLPKxJjOa.mjs → -pxdn3M3tc6PLHs7.mjs} +20 -20
  16. package/node/esm/{BkY99r-c3BhlT_Kv.mjs → 0n5bslM9jhO1JnI2.mjs} +1 -1
  17. package/node/esm/{DE3eIaqkk5xzmV1c.mjs → Cku7XiUvw1xrRasi.mjs} +1 -1
  18. package/node/esm/index.mjs +9650 -8487
  19. package/package.json +6 -6
  20. package/types/scripting-enums.json +6 -0
  21. package/types/scripting.d.ts +586 -27
  22. package/types/src/anchored/IAnchored.d.ts +27 -0
  23. package/types/src/calculation/Calculation.d.ts +26 -12
  24. package/types/src/calculation/ICalculation.d.ts +178 -0
  25. package/types/src/calculation/executor/CalcExecutor.d.ts +314 -14
  26. package/types/src/calculation/executor/CalcExecutorUtils.d.ts +31 -0
  27. package/types/src/calculation/executor/CircularReference.d.ts +81 -0
  28. package/types/src/calculation/grid/CalcGrid.d.ts +3 -1
  29. package/types/src/calculation/grid/CalcGridUtils.d.ts +3 -2
  30. package/types/src/calculation/grid/ICalcGrid.d.ts +12 -1
  31. package/types/src/calculation/spatial/CircularEntry.d.ts +18 -0
  32. package/types/src/calculation/spatial/index.d.ts +1 -0
  33. package/types/src/calculation/state/CalcNode.d.ts +44 -17
  34. package/types/src/calculation/state/CalcState.d.ts +78 -15
  35. package/types/src/calculation/state/CalculationContext.d.ts +42 -1
  36. package/types/src/calculation/state/IContextContainer.d.ts +31 -0
  37. package/types/src/calculation/state/_ReadObservedGrid.d.ts +90 -0
  38. package/types/src/cell/ICell.d.ts +16 -0
  39. package/types/src/cellRange/ICellRange.d.ts +51 -21
  40. package/types/src/condition/AnchoredConditional.d.ts +26 -6
  41. package/types/src/conditionalFormat/ConditionalFormat.d.ts +8 -1
  42. package/types/src/conditionalFormat/IConditionalFormat.d.ts +4 -1
  43. package/types/src/conditionalFormat/IConditionalFormatCollection.d.ts +6 -2
  44. package/types/src/dataValidation/IDataValidationCollection.d.ts +6 -2
  45. package/types/src/hyperlink/IHyperlink.d.ts +3 -1
  46. package/types/src/hyperlink/_Hyperlink.d.ts +6 -0
  47. package/types/src/lib/utils/_Utils.d.ts +7 -0
  48. package/types/src/lib/utils/utils.browser.d.ts +5 -0
  49. package/types/src/license/LicenseDetails.d.ts +5 -0
  50. package/types/src/primitives/CalcSignal.d.ts +20 -0
  51. package/types/src/primitives/PrimitiveUtils.d.ts +4 -2
  52. package/types/src/primitives/Range.d.ts +3 -1
  53. package/types/src/protectedRange/IProtectedRangeCollection.d.ts +7 -2
  54. package/types/src/scripting/FunctionArguments.d.ts +22 -0
  55. package/types/src/scripting/TypedFunction.d.ts +60 -0
  56. package/types/src/scripting/_ScriptUtils.d.ts +13 -0
  57. package/types/src/sheet/Sheet.d.ts +41 -2
  58. package/types/src/sheet/SheetCell.d.ts +2 -0
  59. package/types/src/sheet/SheetRange.d.ts +3 -0
  60. package/types/src/sheet/_SheetAutoFitUtils.d.ts +28 -0
  61. package/types/src/sheet/_SheetStateTypes.d.ts +14 -1
  62. package/types/src/style/IStyle.d.ts +5 -0
  63. package/types/src/table/AnchoredTable.d.ts +17 -1
  64. package/types/src/text/TextUtils.d.ts +18 -0
  65. package/browser/cjs/1mH2uhx_Dmceu88H.cjs +0 -33
  66. package/browser/cjs/D6cjnwWR_iUSe1f6.cjs +0 -1
@@ -1,6 +1,7 @@
1
1
  import { IRange } from '@sheetxl/primitives';
2
2
  import { IListener } from '../listener';
3
3
  import { ICellRange, ICellRanges } from '../cellRange';
4
+ import { ITransaction } from '../transaction';
4
5
  /**
5
6
  * `IAnchored` objects are anchored to one or more ranges.
6
7
  */
@@ -114,5 +115,31 @@ export declare namespace IAnchored {
114
115
  readonly TwoCell: "twoCell";
115
116
  };
116
117
  type Type = typeof Type[keyof typeof Type];
118
+ /**
119
+ * Options shared by the collections that add anchored items — conditional formats, data
120
+ * validations, protected ranges.
121
+ */
122
+ interface AddOptions extends ITransaction.OperationOptions {
123
+ /**
124
+ * Position in the collection. `0` is first — for a conditional format, the highest priority.
125
+ *
126
+ * @defaultValue 0 — a new item goes first, as in Excel.
127
+ */
128
+ index?: number;
129
+ /**
130
+ * Redefine the item already at `index` instead of inserting, when it is anchored to exactly
131
+ * the same ranges (discontiguous ranges compare area by area, in authored order).
132
+ *
133
+ * @defaultValue false
134
+ *
135
+ * @remarks
136
+ * Only the item at `index` is considered, as in Excel. What counts as the same item is per
137
+ * collection: a data validation or protected range matches on ranges alone; a conditional
138
+ * format only redefines a scale rule (data bar, color scale, icon set) of the same kind —
139
+ * a style rule always inserts, since several may apply to one cell, whereas a second scale
140
+ * of one kind on the same ranges could never render.
141
+ */
142
+ replaceExisting?: boolean;
143
+ }
117
144
  }
118
145
  //# sourceMappingURL=IAnchored.d.ts.map
@@ -38,12 +38,26 @@ export declare class Calculation extends AbstractModel<State, ICalculation.JSON,
38
38
  protected _getRanges: (address: ICellRanges.Address, options?: ICellRange.GetRangeOptions) => ICellRanges;
39
39
  protected _calcExecutor: CalcExecutor;
40
40
  protected _cycleId: number;
41
+ protected _staticEpoch: number;
42
+ protected _precedentEpoch: number;
43
+ protected _epochSeenFormulas: ISpatialMap3D<FormulaSpatialValue> | null;
44
+ protected _epochSeenPrecedents: ISpatialMap3D<PrecedentSpatialValue> | null;
45
+ protected _epochSeenDynamics: Map<FormulaSpatialValue, ISpatialMap.Entry<PrecedentSpatialValue>[]> | null;
41
46
  protected _volatiles: Set<CalcNode>;
42
47
  protected _calculatedCommitId: string | null;
43
48
  protected _pendingActions: (() => Promise<unknown>)[] | null;
44
49
  protected _pendingPriority: (() => Promise<unknown>)[] | null;
45
50
  protected _draining: boolean;
46
51
  protected _drainScheduled: boolean;
52
+ protected _calcOwed: boolean;
53
+ /** {@link ICalculation.getCalculationMode} — gates the reactive pass in {@link _calculate}. */
54
+ protected _calcMode: ICalculation.CalculationMode;
55
+ /** {@link ICalculation.getIterativeCalculation} — handed to the executor per pass. */
56
+ protected _iterate: boolean;
57
+ protected _maxIterations: number;
58
+ protected _maxIterateChange: number;
59
+ /** The `calcPr` the file carried, kept whole so settings this engine ignores still round-trip. */
60
+ protected _calcJSON: ICalculation.JSON | null;
47
61
  protected _removeNamedItemsListeners: (() => void) | null;
48
62
  protected _namedDependents: Map<string, IRange.Coords[]> | null;
49
63
  protected _namedDependentsOf: ISpatialMap3D<FormulaSpatialValue> | null;
@@ -218,6 +232,18 @@ export declare class Calculation extends AbstractModel<State, ICalculation.JSON,
218
232
  stop(): Promise<void>;
219
233
  /** @inheritdoc ICalculation.getStatus */
220
234
  getStatus(): ICalculation.Status;
235
+ /** @inheritdoc ICalculation.getCalculationMode */
236
+ getCalculationMode(): ICalculation.CalculationMode;
237
+ /** @inheritdoc ICalculation.setCalculationMode */
238
+ setCalculationMode(mode: ICalculation.CalculationMode): this;
239
+ /** @inheritdoc ICalculation.isCalculationRequired */
240
+ isCalculationRequired(): boolean;
241
+ /** @inheritdoc ICalculation.getIterativeCalculation */
242
+ getIterativeCalculation(): ICalculation.IterativeCalculation;
243
+ /** @inheritdoc ICalculation.setIterativeCalculation */
244
+ setIterativeCalculation(options: boolean | Partial<ICalculation.IterativeCalculation>): this;
245
+ /** @inheritdoc ICalculation.toJSON */
246
+ toJSON(): ICalculation.JSON;
221
247
  /** @inheritdoc ICalculation.ready */
222
248
  ready(options?: ICalculation.CalculateOptions): Promise<ICalculation.Status>;
223
249
  /**
@@ -421,18 +447,6 @@ interface State extends AbstractModel.State {
421
447
  * Listeners to individual named items
422
448
  */
423
449
  itemRemoveListeners: (() => void)[];
424
- /**
425
- * Indicates if calculation will do iterative calcs
426
- */
427
- iterate: boolean;
428
- /**
429
- * The maximum number of iterations to perform when calculating.
430
- */
431
- maxIterations: number;
432
- /**
433
- * The maximum change allowed between iterations when performing iterative calculations.
434
- */
435
- maxIterateChange: number;
436
450
  }
437
451
  interface CommitView extends AbstractModel.CommitView {
438
452
  }
@@ -77,6 +77,63 @@ export interface ICalculation extends IModel {
77
77
  * This is similar convenience method for `getCalculation().createFormula(expression).evaluate(options)`.
78
78
  */
79
79
  evaluate(expression: string, options?: number | ICalculation.EvaluateOptions & Partial<IRange.CellCoords>): Promise<Scalar | IRange>;
80
+ /**
81
+ * When the engine recalculates on its own — Excel's Calculation Options.
82
+ *
83
+ * @remarks
84
+ * In {@link ICalculation.CalculationMode.Automatic} every commit that dirties a formula
85
+ * schedules a pass. In {@link ICalculation.CalculationMode.Manual} an edit only marks its
86
+ * dependents out of date ({@link isCalculationRequired}) and nothing is recalculated — volatile
87
+ * functions (`NOW`, `RAND`) stop re-rolling too — until {@link calculate}: Excel's F9 (every
88
+ * sheet), Shift+F9 (`scope`) and Ctrl+Alt+F9 (`full`). {@link ready} resolves at once in manual
89
+ * mode; a caller that wants current values calls {@link calculate}.
90
+ *
91
+ * @defaultValue {@link ICalculation.CalculationMode.Automatic}
92
+ */
93
+ getCalculationMode(): ICalculation.CalculationMode;
94
+ /**
95
+ * Sets the calculation mode.
96
+ *
97
+ * @remarks
98
+ * Leaving manual mode recalculates whatever is out of date, as Excel does.
99
+ * {@link ICalculation.CalculationMode.AutomaticExceptTables} is accepted for parity with the
100
+ * file format and Office Scripts; this engine has no what-if data tables, so it recalculates
101
+ * exactly as `Automatic` does.
102
+ */
103
+ setCalculationMode(mode: ICalculation.CalculationMode): this;
104
+ /**
105
+ * Whether any formula is out of date — Excel's `Calculate` indicator in the status bar.
106
+ *
107
+ * @remarks
108
+ * Meaningful in manual mode, where edits accumulate until {@link calculate}. In automatic
109
+ * mode it is `true` only between an edit and the pass it schedules.
110
+ */
111
+ isCalculationRequired(): boolean;
112
+ /**
113
+ * How a reference cycle is resolved — Excel's "Enable iterative calculation" and its limits.
114
+ *
115
+ * @see {@link ICalculation.IterativeCalculation}
116
+ */
117
+ getIterativeCalculation(): ICalculation.IterativeCalculation;
118
+ /**
119
+ * Enables, disables or configures iterative calculation.
120
+ *
121
+ * @param options `true`/`false` toggles `enabled` alone; an object updates the fields given and
122
+ * keeps the rest.
123
+ *
124
+ * @remarks
125
+ * Every cell in a cycle is recalculated when this changes: turning iteration on resolves the
126
+ * cycles the workbook shows as unresolved, turning it off writes `0` to them again.
127
+ */
128
+ setIterativeCalculation(options: boolean | Partial<ICalculation.IterativeCalculation>): this;
129
+ /**
130
+ * The calculation settings as JSON — what an xlsx carries in `calcPr`.
131
+ *
132
+ * @remarks
133
+ * Sparse: a setting at its default is omitted. Settings a file carried that this engine does
134
+ * not act on (`calcOnSave`, `fullCalcOnLoad`, `fullPrecision`, …) are kept and written back.
135
+ */
136
+ toJSON(): ICalculation.JSON;
80
137
  /**
81
138
  * Add Listeners.
82
139
  *
@@ -105,6 +162,87 @@ export declare namespace ICalculation {
105
162
  * tokenizer, the AST, a formula input — is ever handed an expression of unbounded size.
106
163
  */
107
164
  const MAX_EXPRESSION_LENGTH = 8192;
165
+ /**
166
+ * A reference cycle — the answer to "why is this cell `0`".
167
+ *
168
+ * @remarks
169
+ * A cell is in a cycle when calculating it opens its own value, directly or through other cells
170
+ * — `=A1+1` in A1, `=OFFSET(A1,0,0)` in A1, `=SUMIF(B1,C1,A1)` in A1 while B1 matches C1. With
171
+ * iterative calculation off (the default, and Excel's) every cell in a cycle, and every cell
172
+ * downstream of one, evaluates to `0`; nothing on the value says why. This does.
173
+ *
174
+ * Reached from a cell — {@link ICell.getCircularReference} answers it for members and for
175
+ * downstream cells alike — and carried by the `ICellRange.Feature.Circular` regions, so a
176
+ * range, a sheet or the workbook is asked the way any other error is asked:
177
+ * `getCounts(Feature.Circular)` for how many, `getRegions(Feature.Circular)` for which, with
178
+ * this object as each region's payload. There is no list of cycles on the calculation: nobody
179
+ * starts from the cycle; they start from a cell or a range and want to know more.
180
+ *
181
+ * Live, not a snapshot: it reads the engine's cycle table on every call and drops members whose
182
+ * formula has since been edited away, so a stale handle answers `getMemberCount() === 0`.
183
+ * Persists until the last member is edited away.
184
+ */
185
+ interface ICircularReference {
186
+ /**
187
+ * The cell named for the cycle, the way Excel's status bar names one
188
+ * (`Worksheet.CircularReference` likewise answers a single cell): the first member in
189
+ * row-major order. `scope` is the sheet name, or `null` when the member lives in a named
190
+ * formula's body rather than on a sheet.
191
+ */
192
+ getRepresentative(): IRange.CellCoords | null;
193
+ /**
194
+ * Every cell IN the cycle, in row-major order, `scope` set to the sheet name. Small — a cycle
195
+ * is the cells that read each other, not everything that reads them (that is
196
+ * {@link getDownstreamCount}).
197
+ */
198
+ getMembers(): readonly IRange.CellCoords[];
199
+ /** How many cells are IN the cycle, the representative included. */
200
+ getMemberCount(): number;
201
+ /** How many cells read the cycle (transitively) and evaluate to `0` because of it. */
202
+ getDownstreamCount(): number;
203
+ /**
204
+ * Whether `coords` is IN the cycle, as opposed to downstream of it. A cell that reads a
205
+ * member's `0` answers `false` here but still resolves this cycle from
206
+ * {@link ICell.getCircularReference} — the tooltip for it says "reads a circular reference
207
+ * at A1", not "is one".
208
+ */
209
+ isMember(coords: IRange.CellCoords): boolean;
210
+ /**
211
+ * The cycle as a walk of reads from `from` back to itself — each cell reads the next, and
212
+ * the last reads the first. A cycle has no start, so it is told from the cell that asks:
213
+ * with `A1 = B1+1` and `B1 = A1+1`, asked from A1 it is `[A1, B1]` (A1 → B1 → A1), asked
214
+ * from B1 it is `[B1, A1]`. A cycle of one is `[A1]`.
215
+ *
216
+ * @remarks
217
+ * Exact, not inferred from formula text: it is the order the engine found the cycle in,
218
+ * which is the order the reads happened — a dynamic read (`INDIRECT`, `OFFSET`) is a step
219
+ * like any other. Interlocking cycles share members; the walk follows the read that closed
220
+ * the cycle `from` was found in, so it is ONE loop through that cell, not every member
221
+ * ({@link getMembers} is every member).
222
+ *
223
+ * Empty when `from` is not a live member — a downstream cell asks from
224
+ * {@link getRepresentative}.
225
+ */
226
+ getPath(from: IRange.CellCoords): readonly IRange.CellCoords[];
227
+ /**
228
+ * Whether iterative calculation was on when the cycle was last evaluated. When `false` the
229
+ * cycle is unresolved and every member and downstream cell is `0`; the iteration answers
230
+ * below are then meaningless (`0` sweeps, no change).
231
+ */
232
+ isIterative(): boolean;
233
+ /**
234
+ * Whether iterative calculation settled it: every member moved by less than the workbook's
235
+ * `maxIterateChange` in the last sweep. Always `false` with iteration off.
236
+ */
237
+ isConverged(): boolean;
238
+ /** How many sweeps the last evaluation ran — up to the workbook's `maxIterations`. */
239
+ getIterationCount(): number;
240
+ /**
241
+ * The largest change any member made in the last sweep — what stopped the iteration when
242
+ * {@link isConverged}, what it never got under when not. `0` with iteration off.
243
+ */
244
+ getLastChange(): number;
245
+ }
108
246
  /**
109
247
  * Represents a formula that can be evaluated.
110
248
  */
@@ -783,8 +921,16 @@ export declare namespace ICalculation {
783
921
  /**
784
922
  * Called when the calculation has been updated and
785
923
  * a calculation has not been started.
924
+ *
925
+ * @remarks
926
+ * In manual mode this is every edit that leaves a formula out of date — see
927
+ * {@link ICalculation.isCalculationRequired}.
786
928
  */
787
929
  onStale?(source: ICalculation): void;
930
+ /**
931
+ * Called when the calculation mode or the iterative-calculation settings change.
932
+ */
933
+ onOptionsChange?(source: ICalculation): void;
788
934
  /**
789
935
  * Called when a calculation is starting.
790
936
  */
@@ -868,6 +1014,38 @@ export declare namespace ICalculation {
868
1014
  readonly AutomaticExceptTables: "automaticExceptTables";
869
1015
  };
870
1016
  type CalculationMode = typeof CalculationMode[keyof typeof CalculationMode];
1017
+ /**
1018
+ * Iterative calculation — Excel's "Enable iterative calculation" with its two limits.
1019
+ *
1020
+ * @remarks
1021
+ * With it off a reference cycle evaluates to `0` and is reported as unresolved. With it on the
1022
+ * cells of the cycle are re-evaluated in turn, each read seeing the latest value, until no cell
1023
+ * moved by {@link maxChange} or {@link maxIterations} sweeps ran — and the results persist into
1024
+ * the next recalculation, which re-runs every cycle the way it re-runs `NOW()`: `=A1+1` in A1 is
1025
+ * a counter that advances by `maxIterations` per recalc. A cycle that stops on the sweep cap is
1026
+ * still reported ({@link ICircularReference.isConverged}); a converged one is not.
1027
+ *
1028
+ * Office Scripts calls the count `maxIteration`; the file format `iterateCount` / `iterateDelta`.
1029
+ */
1030
+ interface IterativeCalculation {
1031
+ /**
1032
+ * @defaultValue `false`
1033
+ */
1034
+ enabled: boolean;
1035
+ /**
1036
+ * The most sweeps one recalculation runs over a cycle.
1037
+ *
1038
+ * @defaultValue `100`
1039
+ */
1040
+ maxIterations: number;
1041
+ /**
1042
+ * Sweeps stop early once every cell in the cycle moved by less than this. A non-numeric
1043
+ * change (text, error) never counts as settled.
1044
+ *
1045
+ * @defaultValue `0.001`
1046
+ */
1047
+ maxChange: number;
1048
+ }
871
1049
  /**
872
1050
  * Represents the status of a calculation result
873
1051
  */