@ricsam/formula-engine 0.2.13 → 0.2.15

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.
@@ -16,6 +16,18 @@ export type StyleManagerSnapshot = {
16
16
  };
17
17
  export type RangeMetadataManagerSnapshot = RangeMetadata[];
18
18
  export type ReferenceManagerSnapshot = Map<string, TrackedReference>;
19
+ export type EngineHistorySnapshotManagers = {
20
+ workbook: WorkbookManagerSnapshot;
21
+ namedExpression: NamedExpressionManagerSnapshot;
22
+ table: TableManagerSnapshot;
23
+ style: StyleManagerSnapshot;
24
+ rangeMetadata: RangeMetadataManagerSnapshot;
25
+ reference: ReferenceManagerSnapshot;
26
+ };
27
+ export type EngineHistorySnapshot = {
28
+ version: typeof ENGINE_SNAPSHOT_VERSION;
29
+ managers: EngineHistorySnapshotManagers;
30
+ };
19
31
  export type SerializedValueEvaluationResultSnapshot = {
20
32
  type: "value";
21
33
  result: CellValue;
@@ -120,13 +132,7 @@ export type CacheManagerSnapshot = {
120
132
  scc: SerializedSCCSnapshot;
121
133
  }>;
122
134
  };
123
- type EngineSnapshotManagers = {
124
- workbook: WorkbookManagerSnapshot;
125
- namedExpression: NamedExpressionManagerSnapshot;
126
- table: TableManagerSnapshot;
127
- style: StyleManagerSnapshot;
128
- rangeMetadata: RangeMetadataManagerSnapshot;
129
- reference: ReferenceManagerSnapshot;
135
+ type EngineSnapshotManagers = EngineHistorySnapshotManagers & {
130
136
  dependency: DependencyManagerSnapshot;
131
137
  cache: CacheManagerSnapshot;
132
138
  };
@@ -2,7 +2,7 @@
2
2
  * Main FormulaEngine class
3
3
  * Core API implementation for spreadsheet calculations
4
4
  */
5
- import { type CellAddress, type CellStyle, type ConditionalStyle, type CopyCellsOptions, type DirectCellStyle, type NamedExpression, type RangeAddress, type RangeMetadata, type RangeMetadataInput, type ReplaceChange, type ReplaceTarget, type SearchMatch, type SearchOptions, type SerializedCellValue, type Sheet, type SingleEvaluationResult, type SpreadsheetRange, type SpreadsheetRangeEnd, type TableDefinition } from "./types";
5
+ import { type CellAddress, type CellStyle, type ConditionalStyle, type CopyCellsOptions, type DirectCellStyle, type FormulaEngineOptions, type NamedExpression, type RangeAddress, type RangeMetadata, type RangeMetadataInput, type ReplaceChange, type ReplaceTarget, type SearchMatch, type SearchOptions, type SerializedCellValue, type Sheet, type SingleEvaluationResult, type SpreadsheetRange, type SpreadsheetRangeEnd, type TableDefinition, type UndoRedoState } from "./types";
6
6
  import type { FillDirection } from "@ricsam/selection-manager";
7
7
  import { AutoFill } from "./autofill-utils";
8
8
  import { WorkbookManager } from "./managers/workbook-manager";
@@ -36,6 +36,8 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
36
36
  private rangeMetadataManager;
37
37
  private copyManager;
38
38
  private referenceManager;
39
+ private undoRedoManager;
40
+ private historyCheckpointDepth;
39
41
  /**
40
42
  * Public access to the store manager for testing
41
43
  */
@@ -48,14 +50,22 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
48
50
  _dependencyManager: DependencyManager;
49
51
  _styleManager: StyleManager;
50
52
  _rangeMetadataManager: RangeMetadataManager<MetadataType<TMetadata, "range">>;
51
- constructor();
53
+ constructor(options?: FormulaEngineOptions);
52
54
  /**
53
55
  * Static factory method to build an empty engine
54
56
  * @template TMetadata - Consumer-defined metadata shape with optional cell, sheet, and workbook entries.
55
57
  */
56
- static buildEmpty<TMetadata extends Metadata = Metadata>(): FormulaEngine<TMetadata>;
58
+ static buildEmpty<TMetadata extends Metadata = Metadata>(options?: FormulaEngineOptions): FormulaEngine<TMetadata>;
59
+ undo(): boolean;
60
+ redo(): boolean;
61
+ canUndo(): boolean;
62
+ canRedo(): boolean;
63
+ getUndoRedoState(): UndoRedoState;
64
+ clearUndoRedoHistory(): void;
65
+ transact<T>(callback: () => T): T;
57
66
  private emitMutation;
58
67
  private emitUpdate;
68
+ private withUndoRedoCheckpoint;
59
69
  private getExistingSheetContent;
60
70
  private getWorkbookResourceKeys;
61
71
  private getSheetResourceKeys;
@@ -522,8 +532,13 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
522
532
  };
523
533
  onUpdate(listener: () => void): () => void;
524
534
  private buildSerializedSnapshot;
535
+ private buildHistorySnapshot;
536
+ private serializeHistorySnapshot;
525
537
  private buildNamedExpressionSnapshot;
526
538
  serializeEngine(): string;
539
+ private assertSupportedSnapshot;
540
+ private restoreDataManagersFromSnapshot;
541
+ private restoreHistorySnapshot;
527
542
  resetToSerializedEngine(data: string): void;
528
543
  }
529
544
  export {};
@@ -0,0 +1,16 @@
1
+ import type { UndoRedoOptions, UndoRedoState } from "../types";
2
+ export declare class UndoRedoManager {
3
+ private undoStack;
4
+ private redoStack;
5
+ readonly maxDepth: number;
6
+ constructor(options: UndoRedoOptions | undefined);
7
+ canUndo(): boolean;
8
+ canRedo(): boolean;
9
+ recordMutation(before: string, after: string): void;
10
+ popUndo(): string | undefined;
11
+ popRedo(): string | undefined;
12
+ pushUndo(snapshot: string): void;
13
+ pushRedo(snapshot: string): void;
14
+ clear(): void;
15
+ getState(): UndoRedoState;
16
+ }
@@ -99,6 +99,8 @@ export declare class WorkbookManager {
99
99
  private resolveSearchScope;
100
100
  private getStringContentKind;
101
101
  private findMatchesInString;
102
+ private normalizeSearchMaxResults;
103
+ private iterateStringCellsInSearchOrder;
102
104
  private buildSearchMatchesInScope;
103
105
  search(query: string, options?: SearchOptions): SearchMatch[];
104
106
  private buildReplacedContent;
@@ -7,6 +7,27 @@ import type { FormulaEvaluator } from "../evaluator/formula-evaluator";
7
7
  import type { FunctionNode } from "../parser/ast";
8
8
  import type { DependencyNode } from "./managers/dependency-node";
9
9
  import type { LookupOrder } from "./managers/range-eval-order-builder";
10
+ export interface UndoRedoOptions {
11
+ /**
12
+ * Maximum number of undo entries retained by the engine.
13
+ * @default 100
14
+ */
15
+ maxDepth?: number;
16
+ }
17
+ export interface FormulaEngineOptions {
18
+ /**
19
+ * Configure engine-level undo/redo history. History is always enabled.
20
+ */
21
+ undoRedo?: UndoRedoOptions;
22
+ }
23
+ export interface UndoRedoState {
24
+ enabled: boolean;
25
+ canUndo: boolean;
26
+ canRedo: boolean;
27
+ undoDepth: number;
28
+ redoDepth: number;
29
+ maxDepth: number;
30
+ }
10
31
  export interface CellAddress {
11
32
  sheetName: string;
12
33
  workbookName: string;
@@ -80,10 +101,18 @@ export type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;
80
101
  * any empty values are deleted from the sheet content
81
102
  */
82
103
  export type SerializedCellValue = string | number | boolean | undefined;
104
+ export declare const DEFAULT_SEARCH_MAX_RESULTS = 1000;
83
105
  export interface SearchOptions {
84
106
  workbookName?: string;
85
107
  sheetName?: string;
86
108
  caseSensitive?: boolean;
109
+ /**
110
+ * Maximum number of matches returned by search(). Defaults to
111
+ * DEFAULT_SEARCH_MAX_RESULTS to keep interactive UIs from materializing
112
+ * enormous result sets. Pass Number.POSITIVE_INFINITY for an unbounded search.
113
+ * replaceAll() ignores this option and always replaces all matches in scope.
114
+ */
115
+ maxResults?: number;
87
116
  }
88
117
  export interface SearchMatch {
89
118
  workbookName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",