logisheets 1.15.0 → 1.16.0

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 (45) hide show
  1. package/README.md +3 -2
  2. package/dist/index.js +17 -0
  3. package/dist/src/api/block_manager.d.ts +2 -0
  4. package/dist/src/api/block_manager.js +2 -0
  5. package/dist/src/api/calculator.d.ts +12 -0
  6. package/dist/src/api/calculator.js +8 -0
  7. package/dist/src/api/cell.d.ts +4 -0
  8. package/dist/src/api/cell.js +4 -0
  9. package/dist/src/api/craft-calc.d.ts +11 -2
  10. package/dist/src/api/craft-calc.js +16 -2
  11. package/dist/src/api/utils.d.ts +8 -0
  12. package/dist/src/api/utils.js +7 -0
  13. package/dist/src/api/workbook.d.ts +114 -8
  14. package/dist/src/api/workbook.js +121 -5
  15. package/dist/src/api/worksheet.d.ts +31 -0
  16. package/dist/src/api/worksheet.js +31 -0
  17. package/dist/src/bindings/block_schema.d.ts +1 -0
  18. package/dist/src/bindings/define_name.d.ts +18 -0
  19. package/dist/src/bindings/define_name.js +30 -0
  20. package/dist/src/bindings/defined_name_info.d.ts +4 -0
  21. package/dist/src/bindings/defined_name_info.js +2 -0
  22. package/dist/src/bindings/edit_payload.d.ts +12 -0
  23. package/dist/src/bindings/index.d.ts +4 -0
  24. package/dist/src/bindings/index.js +4 -0
  25. package/dist/src/bindings/remove_name.d.ts +10 -0
  26. package/dist/src/bindings/remove_name.js +16 -0
  27. package/dist/src/bindings/rename_name.d.ts +14 -0
  28. package/dist/src/bindings/rename_name.js +23 -0
  29. package/dist/src/bindings/rpc_workbook_methods.d.ts +3 -1
  30. package/dist/src/bindings/save_file_result.d.ts +0 -1
  31. package/dist/src/client.d.ts +39 -2
  32. package/dist/src/layout.d.ts +2 -0
  33. package/dist/src/types.d.ts +8 -0
  34. package/dist/src/types.js +2 -0
  35. package/dist/src/utils.d.ts +4 -0
  36. package/dist/src/utils.js +4 -0
  37. package/dist/wasm/logisheets_wasm_server.d.ts +15 -7
  38. package/dist/wasm/logisheets_wasm_server.js +32 -26
  39. package/dist/wasm/logisheets_wasm_server_bg.wasm +0 -0
  40. package/dist/wasm/package.json +1 -1
  41. package/package.json +1 -1
  42. package/wasm/logisheets_wasm_server.d.ts +15 -7
  43. package/wasm/logisheets_wasm_server.js +32 -26
  44. package/wasm/logisheets_wasm_server_bg.wasm +0 -0
  45. package/wasm/package.json +1 -1
package/README.md CHANGED
@@ -27,7 +27,8 @@ import {Workbook, isErrorMessage} from 'logisheets'
27
27
  // Load a workbook from an .xlsx file on disk.
28
28
  const wb = new Workbook()
29
29
  const buf = readFileSync('book.xlsx')
30
- const code = wb.load(new Uint8Array(buf), 'book.xlsx') // 0 === success
30
+ const loaded = wb.load(new Uint8Array(buf), 'book.xlsx')
31
+ if (isErrorMessage(loaded)) throw new Error(loaded.msg)
31
32
 
32
33
  // Read a cell.
33
34
  const ws = wb.getWorksheet(0)
@@ -49,7 +50,7 @@ wb.execTransaction({
49
50
  })
50
51
 
51
52
  // Save back to .xlsx.
52
- const saved = wb.save('') // { data: Uint8Array, code }
53
+ const saved = wb.save('') // { data: Uint8Array }, or an ErrorMessage
53
54
  writeFileSync('out.xlsx', saved.data)
54
55
  ```
55
56
 
package/dist/index.js CHANGED
@@ -1,4 +1,21 @@
1
1
  "use strict";
2
+ // logisheets — the LogiSheets engine for Node.
3
+ //
4
+ // Same API as logisheets-web (`Workbook`, `Worksheet`, the generated bindings,
5
+ // `isErrorMessage`, ...), from the same source: `./src` is NOT tracked here.
6
+ // `yarn link` (run by `prepare` / `prepublishOnly`) copies packages/web/src
7
+ // over it, so edit and document the code in packages/web, never here.
8
+ //
9
+ // Differences from logisheets-web:
10
+ // - built against the nodejs-target WASM, which loads the .wasm from disk
11
+ // and initializes itself on require. There is no `initWasm` to await; a
12
+ // `new Workbook()` works straight after import.
13
+ // - the web package's root-only extras (`initWasm`, `formatNumber`,
14
+ // `formatText`) are not exported.
15
+ // - CommonJS output.
16
+ //
17
+ // For a managed multi-workbook host with RPC, crafts and file watching on top
18
+ // of this engine, use logisheets-runtime.
2
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
20
  if (k2 === undefined) k2 = k;
4
21
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,3 +1,5 @@
1
+ /** Hands out block ids for `Workbook.createBlockForNewCraft` and checks that a
2
+ * created block can be bound. Internal to `Workbook`. */
1
3
  export declare class BlockManager {
2
4
  constructor(checkBindBlock: (sheetIdx: number, blockId: number, rowCount: number, colCount: number) => boolean, getAvailableBlockId: (sheetIdx: number) => number);
3
5
  /**
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BlockManager = void 0;
4
+ /** Hands out block ids for `Workbook.createBlockForNewCraft` and checks that a
5
+ * created block can be bound. Internal to `Workbook`. */
4
6
  class BlockManager {
5
7
  constructor(checkBindBlock, getAvailableBlockId) {
6
8
  this._checkBindBlock = checkBindBlock;
@@ -1,16 +1,28 @@
1
1
  import { AsyncFuncResult, Task } from '../bindings';
2
+ /** Why a custom function failed. Each becomes an error string in the cell:
3
+ * `#ARGERR!`, `#TIMEOUT!`, `#NOTFOUND!`, anything else `#UNKNOWN!`. */
2
4
  export declare const enum CalcException {
3
5
  Unspecified = 0,
4
6
  ArgErr = 1,
5
7
  TimeOut = 2,
6
8
  NotFound = 3
7
9
  }
10
+ /** Implements a custom function: receives its arguments as strings and
11
+ * resolves the cell's result as a string, or a {@link CalcException}. */
8
12
  export type Executor = (args: readonly string[]) => Promise<string | CalcException>;
13
+ /** A formula function implemented in JS. Register it with
14
+ * `Workbook.registryCustomFunc`; `funcName` is what formulas call. */
9
15
  export declare class CustomFunc {
10
16
  readonly funcName: string;
11
17
  executor: Executor;
12
18
  constructor(funcName: string, executor: Executor);
13
19
  }
20
+ /**
21
+ * Runs the async tasks an `ActionEffect` hands back for custom functions.
22
+ * All tasks run concurrently; the result keeps the task order, which is what
23
+ * the engine uses to match values to cells. An unregistered function yields
24
+ * `#NOTFOUND!` rather than rejecting.
25
+ */
14
26
  export declare class Calculator {
15
27
  calc(tasks: readonly Task[]): Promise<AsyncFuncResult>;
16
28
  registry(f: CustomFunc): void;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Calculator = exports.CustomFunc = void 0;
4
+ /** A formula function implemented in JS. Register it with
5
+ * `Workbook.registryCustomFunc`; `funcName` is what formulas call. */
4
6
  class CustomFunc {
5
7
  funcName;
6
8
  executor;
@@ -10,6 +12,12 @@ class CustomFunc {
10
12
  }
11
13
  }
12
14
  exports.CustomFunc = CustomFunc;
15
+ /**
16
+ * Runs the async tasks an `ActionEffect` hands back for custom functions.
17
+ * All tasks run concurrently; the result keeps the task order, which is what
18
+ * the engine uses to match values to cells. An unregistered function yields
19
+ * `#NOTFOUND!` rather than rejecting.
20
+ */
13
21
  class Calculator {
14
22
  async calc(tasks) {
15
23
  const promises = tasks.map((t) => this._exec(t.asyncFunc, t.args));
@@ -1,6 +1,10 @@
1
1
  import { CellInfo, Value, Style } from '../bindings';
2
+ /** Convenience wrapper over one {@link CellInfo} snapshot; it does not track
3
+ * later edits. */
2
4
  export declare class Cell {
3
5
  constructor(cellInfo: CellInfo);
6
+ /** The value as a plain string (`''` when empty, `true`/`false` for
7
+ * booleans, the error text for errors). Not number-formatted. */
4
8
  getText(): string;
5
9
  getStyle(): Style;
6
10
  getFormula(): string;
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CellValue = exports.Cell = void 0;
4
+ /** Convenience wrapper over one {@link CellInfo} snapshot; it does not track
5
+ * later edits. */
4
6
  class Cell {
5
7
  constructor(cellInfo) {
6
8
  this._value = CellValue.from(cellInfo.value);
7
9
  this._info = cellInfo;
8
10
  }
11
+ /** The value as a plain string (`''` when empty, `true`/`false` for
12
+ * booleans, the error text for errors). Not number-formatted. */
9
13
  getText() {
10
14
  return this._value.valueStr ?? '';
11
15
  }
@@ -18,6 +18,13 @@ import type { Client } from '../client';
18
18
  * Slot 0 inside each craft range is reserved for `calcOnce`; user
19
19
  * `localId`s are transparently offset by 1 so they cannot collide.
20
20
  *
21
+ * Failure: every method throws an `Error` when an engine call resolves an
22
+ * `ErrorMessage`. A write the engine REJECTS resolves an `ActionEffect` with
23
+ * `status.type === 'err'` instead, which these methods do not inspect, so a
24
+ * rejected formula surfaces only as whatever the slot then reads back.
25
+ *
26
+ * All slots live on sheet index 0, which must exist.
27
+ *
21
28
  * Lifetime notes:
22
29
  * - Ephemeral cells are wiped on file save/load (that's what "ephemeral"
23
30
  * means). No reload-survival design is needed.
@@ -55,7 +62,8 @@ export declare class CraftCalc {
55
62
  * for normal cells), so repeated `getCalc` calls reflect the latest
56
63
  * state without re-issuing the formula.
57
64
  *
58
- * Throws if `localId` was never `setCalc`-ed (or has been dropped).
65
+ * A slot that was never `setCalc`-ed (or has been dropped) reads as
66
+ * `'empty'`; the engine does not distinguish it from an empty result.
59
67
  */
60
68
  getCalc(localId: number): Promise<Value>;
61
69
  /**
@@ -78,6 +86,7 @@ export declare class CraftCalc {
78
86
  }
79
87
  /**
80
88
  * Allocate a fresh ephemeral-id range and return a {@link CraftCalc}
81
- * handle scoped to it. Call once per craft (or per host-UI context).
89
+ * handle scoped to it. Call once per craft (or per host-UI context): every
90
+ * call burns a new range for the rest of the JS session.
82
91
  */
83
92
  export declare function acquireCraftCalc(workbook: Client): CraftCalc;
@@ -15,6 +15,11 @@ const utils_1 = require("./utils");
15
15
  // keep both base and offset in plain Number. With 2^32 reserved for the
16
16
  // engine and 2^20 per craft, we can hand out ~2^21 craft ranges before
17
17
  // running into precision concerns — plenty.
18
+ //
19
+ // NOTE: the engine does not honour this split. Its shadow-cell allocator
20
+ // (crates/controller/src/sid_assigner) starts at u32::MAX and counts UP, into
21
+ // the first craft range, and `WorkbookOps.evalFormula` (logisheets-core) uses
22
+ // ids from 1, so ids from different owners can collide.
18
23
  const ENGINE_RESERVED_END = 0x1_0000_0000; // 2^32
19
24
  const CRAFT_RANGE_SIZE = 1 << 20; // 2^20 ids per craft
20
25
  // Bumped on every acquire. Lives for the JS session only; on reload
@@ -40,6 +45,13 @@ let nextCraftBase = ENGINE_RESERVED_END;
40
45
  * Slot 0 inside each craft range is reserved for `calcOnce`; user
41
46
  * `localId`s are transparently offset by 1 so they cannot collide.
42
47
  *
48
+ * Failure: every method throws an `Error` when an engine call resolves an
49
+ * `ErrorMessage`. A write the engine REJECTS resolves an `ActionEffect` with
50
+ * `status.type === 'err'` instead, which these methods do not inspect, so a
51
+ * rejected formula surfaces only as whatever the slot then reads back.
52
+ *
53
+ * All slots live on sheet index 0, which must exist.
54
+ *
43
55
  * Lifetime notes:
44
56
  * - Ephemeral cells are wiped on file save/load (that's what "ephemeral"
45
57
  * means). No reload-survival design is needed.
@@ -91,7 +103,8 @@ class CraftCalc {
91
103
  * for normal cells), so repeated `getCalc` calls reflect the latest
92
104
  * state without re-issuing the formula.
93
105
  *
94
- * Throws if `localId` was never `setCalc`-ed (or has been dropped).
106
+ * A slot that was never `setCalc`-ed (or has been dropped) reads as
107
+ * `'empty'`; the engine does not distinguish it from an empty result.
95
108
  */
96
109
  async getCalc(localId) {
97
110
  const sheetId = await this._resolveSheetId();
@@ -219,7 +232,8 @@ class CraftCalc {
219
232
  exports.CraftCalc = CraftCalc;
220
233
  /**
221
234
  * Allocate a fresh ephemeral-id range and return a {@link CraftCalc}
222
- * handle scoped to it. Call once per craft (or per host-UI context).
235
+ * handle scoped to it. Call once per craft (or per host-UI context): every
236
+ * call burns a new range for the rest of the JS session.
223
237
  */
224
238
  function acquireCraftCalc(workbook) {
225
239
  const base = nextCraftBase;
@@ -1,5 +1,13 @@
1
1
  import { Fill, PatternFill } from '../bindings';
2
2
  import { ErrorMessage } from '../bindings/error_message';
3
+ /**
4
+ * Whether an engine reply is an {@link ErrorMessage}. Structural: any object
5
+ * carrying both `msg` and `ty` matches. Use it on every `Result<T>` before
6
+ * reading the value; an engine refusal to APPLY a transaction is not an
7
+ * `ErrorMessage` but an `ActionEffect` with `status.type === 'err'`.
8
+ */
3
9
  export declare function isErrorMessage(v: any): v is ErrorMessage;
10
+ /** A synchronous engine reply: the value, or an {@link ErrorMessage}. */
4
11
  export type Result<V> = V | ErrorMessage;
12
+ /** The pattern fill of a cell `Fill`, or null for a gradient fill. */
5
13
  export declare function getPatternFill(v: Fill): PatternFill | null;
@@ -2,12 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isErrorMessage = isErrorMessage;
4
4
  exports.getPatternFill = getPatternFill;
5
+ /**
6
+ * Whether an engine reply is an {@link ErrorMessage}. Structural: any object
7
+ * carrying both `msg` and `ty` matches. Use it on every `Result<T>` before
8
+ * reading the value; an engine refusal to APPLY a transaction is not an
9
+ * `ErrorMessage` but an `ActionEffect` with `status.type === 'err'`.
10
+ */
5
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
12
  function isErrorMessage(v) {
7
13
  if (typeof v !== 'object' || v === null)
8
14
  return false;
9
15
  return 'msg' in v && 'ty' in v;
10
16
  }
17
+ /** The pattern fill of a cell `Fill`, or null for a gradient fill. */
11
18
  function getPatternFill(v) {
12
19
  if (v.type === 'patternFill')
13
20
  return v.value;
@@ -1,21 +1,49 @@
1
- import { ActionEffect, BlockField, BlockInfo, BlockSortOrder, GetBlockSortOrderParams, PivotPlan, PivotPlanParams, PivotExcelNote, PivotPlanForParams, MayModifyBlockParams, CheckFieldValidationParams, FieldValidationVerdict, DuplicateBlockKey, EnumSetInfo, BlockOpForPayload, BlockOpPolicy, GetBlockModifyInfoParams, BlockModifyInfo, FormulaDisplayInfo, ShadowCellInfo, SheetCellId, SheetInfo, SaveFileResult, AppData, CellInfo, CellCoordinateWithSheet, Transaction, GetBlockValuesParams, GetCellIdParams, GetShadowCellIdParams, GetShadowCellIdsParams, GetAvailableBlockIdParams, TempStatusDiff, BlockDataRow, CommentMention } from '../bindings';
1
+ import { ActionEffect, BlockField, BlockInfo, BlockSortOrder, GetBlockSortOrderParams, PivotPlan, PivotPlanParams, PivotExcelNote, PivotPlanForParams, MayModifyBlockParams, CheckFieldValidationParams, FieldValidationVerdict, DuplicateBlockKey, EnumSetInfo, DefinedNameInfo, BlockOpForPayload, BlockOpPolicy, GetBlockModifyInfoParams, BlockModifyInfo, FormulaDisplayInfo, ShadowCellInfo, SheetCellId, SheetInfo, SaveFileResult, AppData, CellInfo, CellCoordinateWithSheet, Transaction, GetBlockValuesParams, GetCellIdParams, GetShadowCellIdParams, GetShadowCellIdsParams, GetAvailableBlockIdParams, TempStatusDiff, BlockDataRow, CommentMention } from '../bindings';
2
2
  import { ColId, RowId } from '../types';
3
3
  import { Worksheet } from './worksheet';
4
4
  import { CustomFunc } from './calculator';
5
5
  import { Result } from './utils';
6
6
  import { Author } from './author';
7
- export type ReturnCode = number;
8
7
  export type Callback = () => void;
9
8
  export type CellIdCallback = (cellId: SheetCellId) => void;
9
+ /**
10
+ * A synchronous handle on one engine workbook, living in the calling thread.
11
+ *
12
+ * In the browser, `initWasm()` must have resolved before the constructor runs;
13
+ * the Node build needs no init. The app does not use this directly on the main
14
+ * thread: logisheets-engine runs one inside its web worker and exposes it as
15
+ * the async {@link Client}. Shared code should target `Client`.
16
+ *
17
+ * Conventions for every method:
18
+ * - Sheet, row and column indexes are 0-based. `sheetIdx` is the tab
19
+ * position (changes when sheets move); `sheetId` is stable. Convert with
20
+ * {@link getSheetId} / {@link getSheetIdx}.
21
+ * - Reads return `Result<T>`: an `ErrorMessage` on failure, never a throw.
22
+ * - Writes go through {@link execTransaction}, which reports a rejection in
23
+ * the returned `ActionEffect` rather than throwing.
24
+ *
25
+ * Call {@link release} when done; the engine keeps the workbook alive until
26
+ * then.
27
+ */
10
28
  export declare class Workbook {
29
+ /** Allocates a new, empty workbook in the engine. */
11
30
  constructor();
31
+ /** Current tab position of the sheet with stable id `sheetId`. */
12
32
  getSheetIdx(sheetId: number): Result<number>;
13
33
  getBlockValues(params: GetBlockValuesParams): Result<readonly string[]>;
34
+ /**
35
+ * An unused block id on the sheet, asked of the engine every call and not
36
+ * reserved: two calls before a `createBlock` return the same id.
37
+ * {@link createBlockForNewCraft} instead hands out ids from a local
38
+ * counter.
39
+ */
14
40
  getAvailableBlockId(params: GetAvailableBlockIdParams): Result<number>;
15
41
  /**
16
- * @returns the block id if success, otherwise the error message
42
+ * Create a `rowCnt` x `colCnt` block whose master (top-left) cell is at
43
+ * (`masterRow`, `masterCol`), as a non-undoable transaction.
17
44
  *
18
- * It is caller's responsibility to store the block id.
45
+ * @returns the new block id, or an `ErrorMessage` if the engine rejected
46
+ * the block. The caller must store the id; nothing else records it.
19
47
  */
20
48
  createBlockForNewCraft(sheetIdx: number, masterRow: number, masterCol: number, rowCnt: number, colCnt: number): Result<number>;
21
49
  /**
@@ -68,9 +96,16 @@ export declare class Workbook {
68
96
  * {@link AuthorService.searchUsers} result.
69
97
  */
70
98
  upsertPerson(author: Author): ActionEffect;
99
+ /** Undo the last undoable transaction. `false` when there was nothing to
100
+ * undo; on `true` the cell and sheet update callbacks fire. */
71
101
  undo(): boolean;
102
+ /** Redo the last undone transaction. Same contract as {@link undo}. */
72
103
  redo(): boolean;
104
+ /** Called after a transaction reporting cell changes, after undo/redo,
105
+ * and when async custom-function results land. No unsubscribe. */
73
106
  registerCellUpdatedCallback(callback: Callback): void;
107
+ /** Called after a transaction reporting sheet-level changes, and after
108
+ * undo/redo. No unsubscribe. */
74
109
  registerSheetInfoUpdateCallback(callback: Callback): void;
75
110
  /**
76
111
  * Fires after a transaction with sheet indices whose row/column headers
@@ -79,6 +114,7 @@ export declare class Workbook {
79
114
  */
80
115
  registerHeaderUpdatedCallback(callback: (sheetIdxes: readonly number[]) => void): void;
81
116
  getSheetNameByIdx(idx: number): Result<string>;
117
+ /** Every sheet, in tab order. */
82
118
  getAllSheetInfo(): Array<SheetInfo>;
83
119
  /**
84
120
  * Every distinct formula function name used across the workbook (cell
@@ -86,7 +122,15 @@ export declare class Workbook {
86
122
  * stored at parse time, sorted + deduped.
87
123
  */
88
124
  getFormulaFunctionNames(): Result<string[]>;
125
+ /** Whether `f` looks like a formula: it must start with `=` and the rest
126
+ * must lex. A cheap syntax screen, not a full parse; nothing is evaluated. */
89
127
  checkFormula(f: string): boolean;
128
+ /**
129
+ * Evaluate a boolean formula on sheet `sheetIdx`. `f` is written as cell
130
+ * content into one engine-owned scratch ephemeral cell, so a formula needs
131
+ * its leading `=`. An `ErrorMessage` when the result is an error value or
132
+ * the write is rejected.
133
+ */
90
134
  calcCondition(sheetIdx: number, f: string): Result<boolean>;
91
135
  /**
92
136
  * Resolve a (refName, key, field) triple to a concrete cell, the same
@@ -117,23 +161,57 @@ export declare class Workbook {
117
161
  * rather than assume the slot is free.
118
162
  */
119
163
  isInTempMode(): Result<boolean>;
164
+ /** Stable id of the sheet at tab position `sheetIdx`. */
120
165
  getSheetId(sheetIdx: number): Result<number>;
121
166
  getBlockRowId(sheetId: number, blockId: number, rowIdx: number): Result<RowId>;
122
167
  getBlockColId(sheetId: number, blockId: number, colIdx: number): Result<ColId>;
123
168
  getDisplayUnitsOfFormula(f: string): Result<FormulaDisplayInfo>;
169
+ /**
170
+ * Subscribe to value changes of the cell now at (sheetIdx, rowIdx,
171
+ * colIdx). The coordinate is resolved to a cell id once, up front.
172
+ * Returns an `ErrorMessage` if it cannot be resolved.
173
+ */
124
174
  onCellValueChanged(sheetIdx: number, rowIdx: number, colIdx: number, callback: Callback): Result<void>;
125
175
  onCellRemoved(sheetIdx: number, rowIdx: number, colIdx: number, callback: Callback): Result<void>;
126
176
  onShadowCellValueChanged(sheetIdx: number, rowIdx: number, colIdx: number, callback: Callback): Result<void>;
127
177
  private _registerCellRemovedCallback;
128
178
  private _registerCellValueChangedCallback;
129
179
  registerCellValueChangedByCellId(cellId: SheetCellId, callback: Callback): void;
130
- commitTempStatus(): void;
131
- cleanupTempStatus(): void;
132
- toggleStatus(useTemp: boolean): void;
180
+ /**
181
+ * Temp branch (speculative edits). Transactions sent with `temp: true`
182
+ * land on ONE workbook-wide branch; {@link commitTempStatus} folds it into
183
+ * the real state, {@link cleanupTempStatus} discards all of it, and
184
+ * {@link toggleStatus} picks which state reads are served from. Any
185
+ * non-temp write discards the branch. Check {@link isInTempMode} before
186
+ * assuming the slot is free.
187
+ */
188
+ commitTempStatus(): Result<void>;
189
+ cleanupTempStatus(): Result<void>;
190
+ /** Serve reads from the temp branch (`true`) or the committed state. */
191
+ toggleStatus(useTemp: boolean): Result<void>;
192
+ /** Cell infos for stable cell ids, in input order. Works for ephemeral and
193
+ * shadow cells, which have no coordinate. */
133
194
  batchGetCellInfoById(ids: readonly SheetCellId[]): Result<readonly CellInfo[]>;
134
195
  batchGetCellCoordinateWithSheetById(ids: readonly SheetCellId[]): Result<readonly CellCoordinateWithSheet[]>;
196
+ /**
197
+ * Apply a transaction: all payloads, in order, as one unit and (when
198
+ * `tx.undoable`) one undo step.
199
+ *
200
+ * Never throws for an engine refusal. A rejected transaction applies
201
+ * nothing and returns an `ActionEffect` with `status.type === 'err'` and
202
+ * the reason (naming the offending payload) in `errorMessage`; check it
203
+ * whenever the write must land. Callbacks fire only on success.
204
+ *
205
+ * Custom-function calls in the new formulas come back as `asyncTasks`;
206
+ * they are run here through the registered {@link CustomFunc}s and their
207
+ * results fed back later, so those cells update after this returns.
208
+ */
135
209
  execTransaction(tx: Transaction): ActionEffect;
136
- load(buf: Uint8Array, bookName: string): ReturnCode;
210
+ /**
211
+ * Replace this workbook's contents with a parsed .xlsx. An unreadable file
212
+ * comes back as an {@link ErrorMessage} and leaves this workbook as it was.
213
+ */
214
+ load(buf: Uint8Array, bookName: string): Result<void>;
137
215
  /**
138
216
  * Serialize to .xlsx bytes.
139
217
  *
@@ -143,14 +221,24 @@ export declare class Workbook {
143
221
  * so a file Excel must recalculate needs the coordinates. One-way — a
144
222
  * resolved `BLOCKREFS` becomes a plain range, which LogiSheets does not
145
223
  * parse back when it straddles a block.
224
+ *
225
+ * `data` is the opaque AppData string stored in the file (craft state and
226
+ * friends); read it back with {@link getAppData} after a load. Despite the
227
+ * return type, a failed save returns an `ErrorMessage`: check with
228
+ * `isErrorMessage`.
146
229
  */
147
230
  save(data: string, resolveBlockRefs?: boolean): SaveFileResult;
231
+ /** The AppData entries carried by the loaded file (see {@link save}). */
148
232
  getAppData(): readonly AppData[];
149
233
  /** Monotonic counter bumped on every committed write — snapshot it to
150
234
  * detect concurrent modification (optimistic concurrency). */
151
235
  getVersion(): number;
236
+ /** Free the engine workbook. Every later call on this handle, or on a
237
+ * `Worksheet` taken from it, is invalid. */
152
238
  release(): void;
153
239
  getSheetCount(): number;
240
+ /** The sheet at tab position `idx`. THROWS when `idx` is out of range,
241
+ * unlike the `Result`-returning reads. */
154
242
  getWorksheet(idx: number): Worksheet;
155
243
  /**
156
244
  * Fill-handle drag: predict the contents for `dst` from the source
@@ -252,13 +340,24 @@ export declare class Workbook {
252
340
  * this just dispatches the resulting `reorderBlockLines` payload.
253
341
  */
254
342
  sortBlock(sheetIdx: number, blockId: number, field: string, asc: boolean): Result<ActionEffect>;
343
+ /** The sheet with stable id `id`. Not validated: an unknown id yields a
344
+ * `Worksheet` whose calls fail. */
255
345
  getWorksheetById(id: number): Worksheet;
346
+ /** Make `customFunc.funcName` callable from formulas. The engine hands
347
+ * such calls back as async tasks, see {@link execTransaction}. */
256
348
  registryCustomFunc(customFunc: CustomFunc): void;
349
+ /**
350
+ * The id of a cell's shadow: an ephemeral companion cell the engine keeps
351
+ * per (cell, kind) for validation-style formulas. Allocated on first ask
352
+ * and stable afterwards.
353
+ */
257
354
  getShadowCellId(params: GetShadowCellIdParams): Result<number>;
258
355
  getShadowCellIds(params: GetShadowCellIdsParams): Result<readonly number[]>;
259
356
  getShadowInfoById(params: {
260
357
  shadowId: number;
261
358
  }): Result<ShadowCellInfo>;
359
+ /** The stable id of the cell at a coordinate. It survives row/column
360
+ * insertion and deletion, unlike the coordinate. */
262
361
  getCellId(params: GetCellIdParams): Result<SheetCellId>;
263
362
  getAllBlockFields(): Result<readonly BlockField[]>;
264
363
  /**
@@ -298,6 +397,13 @@ export declare class Workbook {
298
397
  * host, keyed by variant id.
299
398
  */
300
399
  getEnumSets(): Result<readonly EnumSetInfo[]>;
400
+ /**
401
+ * The workbook's defined names, ordered by name. Each definition is
402
+ * sheet-qualified (`Sheet1!$B$2:$B$9`) so it reads the same from any sheet.
403
+ * Define, rename and remove them with the `defineName` / `renameName` /
404
+ * `removeName` payloads.
405
+ */
406
+ getDefinedNames(): Result<readonly DefinedNameInfo[]>;
301
407
  /**
302
408
  * Every duplicated block row key in the workbook.
303
409
  *