@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.
- package/README.md +7 -0
- package/dist/cjs/core/engine-snapshot.cjs.map +2 -2
- package/dist/cjs/core/engine.cjs +690 -513
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/undo-redo-manager.cjs +109 -0
- package/dist/cjs/core/managers/undo-redo-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/workbook-manager.cjs +89 -55
- package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
- package/dist/cjs/core/types.cjs +4 -2
- package/dist/cjs/core/types.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/engine-snapshot.mjs.map +2 -2
- package/dist/mjs/core/engine.mjs +690 -513
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/undo-redo-manager.mjs +69 -0
- package/dist/mjs/core/managers/undo-redo-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/workbook-manager.mjs +91 -55
- package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
- package/dist/mjs/core/types.mjs +4 -2
- package/dist/mjs/core/types.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/engine-snapshot.d.ts +13 -7
- package/dist/types/core/engine.d.ts +18 -3
- package/dist/types/core/managers/undo-redo-manager.d.ts +16 -0
- package/dist/types/core/managers/workbook-manager.d.ts +2 -0
- package/dist/types/core/types.d.ts +29 -0
- package/package.json +1 -1
|
@@ -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;
|