@ricsam/formula-engine 0.0.15 → 0.0.17
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/core/autofill-utils.cjs +73 -35
- package/dist/cjs/core/autofill-utils.cjs.map +3 -3
- package/dist/cjs/core/cell-mover.cjs +178 -0
- package/dist/cjs/core/cell-mover.cjs.map +10 -0
- package/dist/cjs/core/engine.cjs +126 -3
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/copy-manager.cjs +337 -82
- package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/reference-manager.cjs +124 -0
- package/dist/cjs/core/managers/reference-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/style-manager.cjs +115 -147
- package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/workbook-manager.cjs +104 -3
- package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
- package/dist/cjs/core/types.cjs.map +2 -2
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/autofill-utils.mjs +73 -35
- package/dist/mjs/core/autofill-utils.mjs.map +3 -3
- package/dist/mjs/core/cell-mover.mjs +148 -0
- package/dist/mjs/core/cell-mover.mjs.map +10 -0
- package/dist/mjs/core/engine.mjs +126 -3
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/copy-manager.mjs +339 -82
- package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/reference-manager.mjs +93 -0
- package/dist/mjs/core/managers/reference-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/style-manager.mjs +115 -147
- package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/workbook-manager.mjs +104 -3
- package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
- package/dist/mjs/core/types.mjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/autofill-utils.d.ts +4 -0
- package/dist/types/core/cell-mover.d.ts +63 -0
- package/dist/types/core/engine.d.ts +123 -9
- package/dist/types/core/managers/copy-manager.d.ts +47 -2
- package/dist/types/core/managers/reference-manager.d.ts +54 -0
- package/dist/types/core/managers/style-manager.d.ts +6 -6
- package/dist/types/core/managers/workbook-manager.d.ts +40 -1
- package/dist/types/core/types.d.ts +52 -11
- package/package.json +1 -1
|
@@ -14,8 +14,11 @@ import { DependencyManager } from "./managers/dependency-manager";
|
|
|
14
14
|
import { StyleManager } from "./managers/style-manager";
|
|
15
15
|
/**
|
|
16
16
|
* Main FormulaEngine class
|
|
17
|
+
* @template TCellMetadata - Consumer-defined type for cell metadata (rich text, links, custom data, etc.)
|
|
18
|
+
* @template TSheetMetadata - Consumer-defined type for sheet metadata (text boxes, frozen panes, etc.)
|
|
19
|
+
* @template TWorkbookMetadata - Consumer-defined type for workbook metadata (themes, document properties, etc.)
|
|
17
20
|
*/
|
|
18
|
-
export declare class FormulaEngine {
|
|
21
|
+
export declare class FormulaEngine<TCellMetadata = unknown, TSheetMetadata = unknown, TWorkbookMetadata = unknown> {
|
|
19
22
|
private workbookManager;
|
|
20
23
|
private namedExpressionManager;
|
|
21
24
|
private tableManager;
|
|
@@ -25,6 +28,7 @@ export declare class FormulaEngine {
|
|
|
25
28
|
private dependencyManager;
|
|
26
29
|
private styleManager;
|
|
27
30
|
private copyManager;
|
|
31
|
+
private referenceManager;
|
|
28
32
|
/**
|
|
29
33
|
* Public access to the store manager for testing
|
|
30
34
|
*/
|
|
@@ -39,10 +43,74 @@ export declare class FormulaEngine {
|
|
|
39
43
|
constructor();
|
|
40
44
|
/**
|
|
41
45
|
* Static factory method to build an empty engine
|
|
46
|
+
* @template TC - Consumer-defined cell metadata type
|
|
47
|
+
* @template TS - Consumer-defined sheet metadata type
|
|
48
|
+
* @template TW - Consumer-defined workbook metadata type
|
|
42
49
|
*/
|
|
43
|
-
static buildEmpty(): FormulaEngine
|
|
50
|
+
static buildEmpty<TC = unknown, TS = unknown, TW = unknown>(): FormulaEngine<TC, TS, TW>;
|
|
44
51
|
getCellEvaluationResult(cellAddress: CellAddress): SingleEvaluationResult | undefined;
|
|
45
52
|
getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue;
|
|
53
|
+
/**
|
|
54
|
+
* Set metadata for a cell
|
|
55
|
+
* Metadata can contain rich text, links, comments, or any consumer-defined data
|
|
56
|
+
*/
|
|
57
|
+
setCellMetadata(address: CellAddress, metadata: TCellMetadata | undefined): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get metadata for a cell
|
|
60
|
+
*/
|
|
61
|
+
getCellMetadata(address: CellAddress): TCellMetadata | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get all cell metadata for a sheet (serialized as Map)
|
|
64
|
+
*/
|
|
65
|
+
getSheetMetadataSerialized(opts: {
|
|
66
|
+
sheetName: string;
|
|
67
|
+
workbookName: string;
|
|
68
|
+
}): Map<string, TCellMetadata>;
|
|
69
|
+
/**
|
|
70
|
+
* Set metadata for a sheet
|
|
71
|
+
* Sheet metadata can contain text boxes, frozen panes, print settings, or any consumer-defined data
|
|
72
|
+
*/
|
|
73
|
+
setSheetMetadata(opts: {
|
|
74
|
+
workbookName: string;
|
|
75
|
+
sheetName: string;
|
|
76
|
+
}, metadata: TSheetMetadata): void;
|
|
77
|
+
/**
|
|
78
|
+
* Get metadata for a sheet
|
|
79
|
+
*/
|
|
80
|
+
getSheetMetadata(opts: {
|
|
81
|
+
workbookName: string;
|
|
82
|
+
sheetName: string;
|
|
83
|
+
}): TSheetMetadata | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Set metadata for a workbook
|
|
86
|
+
* Workbook metadata can contain themes, document properties, settings, or any consumer-defined data
|
|
87
|
+
*/
|
|
88
|
+
setWorkbookMetadata(workbookName: string, metadata: TWorkbookMetadata): void;
|
|
89
|
+
/**
|
|
90
|
+
* Get metadata for a workbook
|
|
91
|
+
*/
|
|
92
|
+
getWorkbookMetadata(workbookName: string): TWorkbookMetadata | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Create a tracked reference to a range
|
|
95
|
+
* Returns a stable UUID that can be used to retrieve the address later
|
|
96
|
+
* The reference automatically updates when sheets/workbooks are renamed
|
|
97
|
+
*/
|
|
98
|
+
createRef(address: RangeAddress): string;
|
|
99
|
+
/**
|
|
100
|
+
* Get the current address for a tracked reference
|
|
101
|
+
* Returns undefined if reference doesn't exist or has been invalidated
|
|
102
|
+
*/
|
|
103
|
+
getRefAddress(refId: string): RangeAddress | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Delete a tracked reference
|
|
106
|
+
* Returns true if the reference was deleted, false if it didn't exist
|
|
107
|
+
*/
|
|
108
|
+
deleteRef(refId: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get all invalid reference IDs
|
|
111
|
+
* Useful for cleanup after sheet/workbook deletions
|
|
112
|
+
*/
|
|
113
|
+
getInvalidRefs(): string[];
|
|
46
114
|
evaluateFormula(
|
|
47
115
|
/**
|
|
48
116
|
* formula without the leading = sign
|
|
@@ -128,6 +196,14 @@ export declare class FormulaEngine {
|
|
|
128
196
|
* Get the computed style for a specific cell
|
|
129
197
|
*/
|
|
130
198
|
getCellStyle(cellAddress: CellAddress): CellStyle | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* Get all cell styles (for testing and serialization)
|
|
201
|
+
*/
|
|
202
|
+
getAllCellStyles(): DirectCellStyle[];
|
|
203
|
+
/**
|
|
204
|
+
* Get all conditional styles (for testing and serialization)
|
|
205
|
+
*/
|
|
206
|
+
getAllConditionalStyles(): ConditionalStyle[];
|
|
131
207
|
/**
|
|
132
208
|
* Add a direct cell style rule
|
|
133
209
|
*/
|
|
@@ -221,24 +297,61 @@ export declare class FormulaEngine {
|
|
|
221
297
|
* Get bounds (min/max row/col) from an array of cell addresses
|
|
222
298
|
*/
|
|
223
299
|
private getBoundsFromCells;
|
|
300
|
+
/**
|
|
301
|
+
* Move a single cell to a new location
|
|
302
|
+
* Updates all formula references that point to the moved cell
|
|
303
|
+
*
|
|
304
|
+
* @param source - The cell to move
|
|
305
|
+
* @param target - The destination cell address
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* // Move A1 to D5. If B1 contains =A1, it will be updated to =D5
|
|
309
|
+
* engine.moveCell(
|
|
310
|
+
* { workbookName, sheetName, colIndex: 0, rowIndex: 0 },
|
|
311
|
+
* { workbookName, sheetName, colIndex: 3, rowIndex: 4 }
|
|
312
|
+
* );
|
|
313
|
+
*/
|
|
314
|
+
moveCell(source: CellAddress, target: CellAddress): void;
|
|
315
|
+
/**
|
|
316
|
+
* Move a range of cells to a new location
|
|
317
|
+
* Updates all formula references that point to the moved cells
|
|
318
|
+
*
|
|
319
|
+
* @param sourceRange - The range to move
|
|
320
|
+
* @param target - The top-left destination cell address
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* // Move A1:D5 to F10. If E1 contains =SUM(A1:D5), it will be updated to =SUM(F10:I14)
|
|
324
|
+
* engine.moveRange(
|
|
325
|
+
* {
|
|
326
|
+
* workbookName,
|
|
327
|
+
* sheetName,
|
|
328
|
+
* range: {
|
|
329
|
+
* start: { col: 0, row: 0 },
|
|
330
|
+
* end: { col: { type: "number", value: 3 }, row: { type: "number", value: 4 } }
|
|
331
|
+
* }
|
|
332
|
+
* },
|
|
333
|
+
* { workbookName, sheetName, colIndex: 5, rowIndex: 9 }
|
|
334
|
+
* );
|
|
335
|
+
*/
|
|
336
|
+
moveRange(sourceRange: RangeAddress, target: CellAddress): void;
|
|
224
337
|
addSheet(opts: {
|
|
225
338
|
workbookName: string;
|
|
226
339
|
sheetName: string;
|
|
227
|
-
}): import("./types").Sheet
|
|
340
|
+
}): import("./types").Sheet<unknown, unknown>;
|
|
228
341
|
removeSheet(opts: {
|
|
229
342
|
workbookName: string;
|
|
230
343
|
sheetName: string;
|
|
231
|
-
}): import("./types").Sheet
|
|
344
|
+
}): import("./types").Sheet<unknown, unknown>;
|
|
232
345
|
renameSheet(opts: {
|
|
233
346
|
sheetName: string;
|
|
234
347
|
newSheetName: string;
|
|
235
348
|
workbookName: string;
|
|
236
|
-
}): import("./types").Sheet
|
|
237
|
-
getSheets(workbookName: string): Map<string, import("./types").Sheet
|
|
349
|
+
}): import("./types").Sheet<unknown, unknown>;
|
|
350
|
+
getSheets(workbookName: string): Map<string, import("./types").Sheet<unknown, unknown>>;
|
|
238
351
|
getSheet({ workbookName, sheetName, }: {
|
|
239
352
|
workbookName: string;
|
|
240
353
|
sheetName: string;
|
|
241
|
-
}): import("./types").Sheet | undefined;
|
|
354
|
+
}): import("./types").Sheet<unknown, unknown> | undefined;
|
|
242
355
|
getSheetSerialized(opts: {
|
|
243
356
|
sheetName: string;
|
|
244
357
|
workbookName: string;
|
|
@@ -250,7 +363,7 @@ export declare class FormulaEngine {
|
|
|
250
363
|
workbookName: string;
|
|
251
364
|
newWorkbookName: string;
|
|
252
365
|
}): void;
|
|
253
|
-
getWorkbooks(): Map<string, import("./types").Workbook
|
|
366
|
+
getWorkbooks(): Map<string, import("./types").Workbook<unknown, unknown, unknown>>;
|
|
254
367
|
/**
|
|
255
368
|
* Overrides the content of a sheet.
|
|
256
369
|
* @param sheetName - The name of the sheet to set the content of
|
|
@@ -293,7 +406,7 @@ export declare class FormulaEngine {
|
|
|
293
406
|
*/
|
|
294
407
|
clearSpreadsheetRange(address: RangeAddress): void;
|
|
295
408
|
getState(): {
|
|
296
|
-
workbooks: Map<string, import("./types").Workbook
|
|
409
|
+
workbooks: Map<string, import("./types").Workbook<unknown, unknown, unknown>>;
|
|
297
410
|
namedExpressions: {
|
|
298
411
|
sheetExpressions: Map<string, Map<string, Map<string, NamedExpression>>>;
|
|
299
412
|
workbookExpressions: Map<string, Map<string, NamedExpression>>;
|
|
@@ -302,6 +415,7 @@ export declare class FormulaEngine {
|
|
|
302
415
|
tables: Map<string, Map<string, TableDefinition>>;
|
|
303
416
|
conditionalStyles: ConditionalStyle[];
|
|
304
417
|
cellStyles: DirectCellStyle[];
|
|
418
|
+
references: Map<string, import("./types").TrackedReference>;
|
|
305
419
|
};
|
|
306
420
|
onUpdate(listener: () => void): () => void;
|
|
307
421
|
serializeEngine(): string;
|
|
@@ -10,14 +10,59 @@ export declare class CopyManager {
|
|
|
10
10
|
private evaluationManager;
|
|
11
11
|
private styleManager;
|
|
12
12
|
constructor(workbookManager: WorkbookManager, evaluationManager: EvaluationManager, styleManager: StyleManager);
|
|
13
|
+
/**
|
|
14
|
+
* Normalize the include option to an array of parts to copy
|
|
15
|
+
*/
|
|
16
|
+
private normalizeInclude;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a specific part should be included in the copy operation
|
|
19
|
+
*/
|
|
20
|
+
private shouldInclude;
|
|
13
21
|
/**
|
|
14
22
|
* Paste cells from source to target
|
|
23
|
+
* Delegates to cutCells for move operations or copyOnlyCells for copy operations
|
|
15
24
|
*/
|
|
16
|
-
|
|
25
|
+
pasteCells(source: CellAddress[], target: CellAddress, options: CopyCellsOptions): void;
|
|
26
|
+
/**
|
|
27
|
+
* Cut cells: Proper snapshot flow for move operations
|
|
28
|
+
* 1. Snapshot source cells (with styles)
|
|
29
|
+
* 2. Remove source cells and punch holes in style areas
|
|
30
|
+
* 3. Update references in OTHER cells (not in moved set)
|
|
31
|
+
* 4. Update formulas in snapshot and apply to target
|
|
32
|
+
*/
|
|
33
|
+
private cutCells;
|
|
34
|
+
/**
|
|
35
|
+
* Copy cells: Standard copy operation (not cut/move)
|
|
36
|
+
* Snapshot → Copy with adjustment → Copy formatting
|
|
37
|
+
*/
|
|
38
|
+
private copyOnlyCells;
|
|
17
39
|
/**
|
|
18
40
|
* Find the top-left cell (minimum row/col indices)
|
|
19
41
|
*/
|
|
20
42
|
private findTopLeft;
|
|
43
|
+
/**
|
|
44
|
+
* Create a snapshot of cells' content and metadata
|
|
45
|
+
* This prevents issues with overlapping ranges where source and target overlap
|
|
46
|
+
* Used for copy operations (not cut)
|
|
47
|
+
*/
|
|
48
|
+
private snapshotCells;
|
|
49
|
+
/**
|
|
50
|
+
* Create a snapshot of cells with content, metadata, AND styles
|
|
51
|
+
* Used for cut operations to preserve all cell information
|
|
52
|
+
*/
|
|
53
|
+
private snapshotCellsWithStyles;
|
|
54
|
+
/**
|
|
55
|
+
* Apply styles from a snapshot to a target cell
|
|
56
|
+
* Creates new style areas at the target location
|
|
57
|
+
*/
|
|
58
|
+
private applyStylesFromSnapshot;
|
|
59
|
+
/**
|
|
60
|
+
* Copy content from a cell snapshot to a target cell
|
|
61
|
+
*/
|
|
62
|
+
private copyCellContentFromSnapshot;
|
|
63
|
+
/**
|
|
64
|
+
* Update all formula references when cells are cut (moved)
|
|
65
|
+
*/
|
|
21
66
|
/**
|
|
22
67
|
* Copy content from one cell to another
|
|
23
68
|
*/
|
|
@@ -69,7 +114,7 @@ export declare class CopyManager {
|
|
|
69
114
|
* Expand a RangeAddress into an array of CellAddress
|
|
70
115
|
* Handles finite ranges, row-bounded, and column-bounded ranges
|
|
71
116
|
*/
|
|
72
|
-
|
|
117
|
+
expandRangeToCells(rangeAddress: RangeAddress): CellAddress[];
|
|
73
118
|
/**
|
|
74
119
|
* Copy cell content with explicit row/column offset for fill operations
|
|
75
120
|
*/
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ReferenceManager - Manages tracked references for external elements
|
|
3
|
+
*
|
|
4
|
+
* Allows consumers to create stable references to ranges that automatically
|
|
5
|
+
* update when sheets/workbooks are renamed and become invalid when deleted.
|
|
6
|
+
*/
|
|
7
|
+
import type { RangeAddress, TrackedReference } from "../types";
|
|
8
|
+
export declare class ReferenceManager {
|
|
9
|
+
private references;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Create a new tracked reference
|
|
13
|
+
* Returns UUID for the reference
|
|
14
|
+
*/
|
|
15
|
+
createRef(address: RangeAddress): string;
|
|
16
|
+
/**
|
|
17
|
+
* Get the current address for a reference
|
|
18
|
+
* Returns undefined if reference doesn't exist or is invalid
|
|
19
|
+
*/
|
|
20
|
+
getRefAddress(refId: string): RangeAddress | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Delete a reference
|
|
23
|
+
* Returns true if reference was deleted, false if it didn't exist
|
|
24
|
+
*/
|
|
25
|
+
deleteRef(refId: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Get all invalid reference IDs
|
|
28
|
+
*/
|
|
29
|
+
getInvalidRefs(): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Update references when sheet is renamed
|
|
32
|
+
*/
|
|
33
|
+
updateSheetName(workbookName: string, oldSheetName: string, newSheetName: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Update references when workbook is renamed
|
|
36
|
+
*/
|
|
37
|
+
updateWorkbookName(oldWorkbookName: string, newWorkbookName: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Mark references as invalid when sheet is removed
|
|
40
|
+
*/
|
|
41
|
+
invalidateSheet(workbookName: string, sheetName: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Mark references as invalid when workbook is removed
|
|
44
|
+
*/
|
|
45
|
+
invalidateWorkbook(workbookName: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get all references for serialization
|
|
48
|
+
*/
|
|
49
|
+
getAllReferences(): Map<string, TrackedReference>;
|
|
50
|
+
/**
|
|
51
|
+
* Restore references from serialization
|
|
52
|
+
*/
|
|
53
|
+
resetReferences(refs: Map<string, TrackedReference>): void;
|
|
54
|
+
}
|
|
@@ -34,7 +34,7 @@ export declare class StyleManager {
|
|
|
34
34
|
getStylesIntersectingWithRange(range: RangeAddress): DirectCellStyle[];
|
|
35
35
|
/**
|
|
36
36
|
* Get the style for a range if all cells in the range have the same style
|
|
37
|
-
* Returns the DirectCellStyle if the range is completely contained within a single style's
|
|
37
|
+
* Returns the DirectCellStyle if the range is completely contained within a single style's areas
|
|
38
38
|
* Returns undefined if multiple styles, partial coverage, or no styles apply
|
|
39
39
|
*/
|
|
40
40
|
getStyleForRange(range: RangeAddress): DirectCellStyle | undefined;
|
|
@@ -100,12 +100,12 @@ export declare class StyleManager {
|
|
|
100
100
|
clearCellStyles(range: RangeAddress): void;
|
|
101
101
|
/**
|
|
102
102
|
* Clear cell styles in a range using subtraction
|
|
103
|
-
* For each intersecting style, subtract the cleared range:
|
|
104
|
-
* - If
|
|
105
|
-
* - If
|
|
106
|
-
* - If no intersection: keep unchanged
|
|
103
|
+
* For each intersecting style, subtract the cleared range from its areas:
|
|
104
|
+
* - If an area is completely contained: remove that area
|
|
105
|
+
* - If an area partially overlaps: split into remaining rectangles (hole punching)
|
|
106
|
+
* - If no intersection: keep area unchanged
|
|
107
107
|
*
|
|
108
|
-
* This matches Excel's behavior where pasting
|
|
108
|
+
* This matches Excel's behavior where cutting/pasting creates multi-area styles
|
|
109
109
|
*/
|
|
110
110
|
clearCellStylesInRange(range: RangeAddress): void;
|
|
111
111
|
}
|
|
@@ -72,6 +72,8 @@ export declare class WorkbookManager {
|
|
|
72
72
|
newSheetName: string;
|
|
73
73
|
}): Sheet;
|
|
74
74
|
updateAllFormulas(updateCallback: (formula: string) => string): void;
|
|
75
|
+
updateFormulasExcluding(excludeCellsSet: Set<string>, updateCallback: (formula: string) => string): void;
|
|
76
|
+
updateFormulasForWorkbook(workbookName: string, updateCallback: (formula: string) => string): void;
|
|
75
77
|
getSheetSerialized({ workbookName, sheetName, }: {
|
|
76
78
|
workbookName: string;
|
|
77
79
|
sheetName: string;
|
|
@@ -103,6 +105,43 @@ export declare class WorkbookManager {
|
|
|
103
105
|
*/
|
|
104
106
|
buildingFromScratch?: boolean;
|
|
105
107
|
}): void;
|
|
108
|
+
/**
|
|
109
|
+
* Set metadata for a cell
|
|
110
|
+
*/
|
|
111
|
+
setCellMetadata<TMetadata = unknown>(address: CellAddress, metadata: TMetadata | undefined): void;
|
|
112
|
+
/**
|
|
113
|
+
* Get metadata for a cell
|
|
114
|
+
*/
|
|
115
|
+
getCellMetadata<TMetadata = unknown>(address: CellAddress): TMetadata | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Get all metadata for a sheet
|
|
118
|
+
*/
|
|
119
|
+
getSheetMetadataSerialized<TMetadata = unknown>(opts: {
|
|
120
|
+
sheetName: string;
|
|
121
|
+
workbookName: string;
|
|
122
|
+
}): Map<string, TMetadata>;
|
|
123
|
+
/**
|
|
124
|
+
* Set metadata for a sheet
|
|
125
|
+
*/
|
|
126
|
+
setSheetMetadata<TSheetMetadata = unknown>(opts: {
|
|
127
|
+
workbookName: string;
|
|
128
|
+
sheetName: string;
|
|
129
|
+
}, metadata: TSheetMetadata): void;
|
|
130
|
+
/**
|
|
131
|
+
* Get metadata for a sheet
|
|
132
|
+
*/
|
|
133
|
+
getSheetMetadata<TSheetMetadata = unknown>(opts: {
|
|
134
|
+
workbookName: string;
|
|
135
|
+
sheetName: string;
|
|
136
|
+
}): TSheetMetadata | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Set metadata for a workbook
|
|
139
|
+
*/
|
|
140
|
+
setWorkbookMetadata<TWorkbookMetadata = unknown>(workbookName: string, metadata: TWorkbookMetadata): void;
|
|
141
|
+
/**
|
|
142
|
+
* Get metadata for a workbook
|
|
143
|
+
*/
|
|
144
|
+
getWorkbookMetadata<TWorkbookMetadata = unknown>(workbookName: string): TWorkbookMetadata | undefined;
|
|
106
145
|
/**
|
|
107
146
|
* Replace all content for a sheet (safely, without breaking references)
|
|
108
147
|
* This method clears the existing Map and repopulates it rather than replacing the Map reference
|
|
@@ -123,7 +162,7 @@ export declare class WorkbookManager {
|
|
|
123
162
|
*/
|
|
124
163
|
iterateCellsInRange(address: RangeAddress): Generator<CellAddress>;
|
|
125
164
|
getCellsInRange(address: RangeAddress): CellAddress[];
|
|
126
|
-
|
|
165
|
+
getCellContent(cellAddress: CellAddress): SerializedCellValue;
|
|
127
166
|
getSerializedCellValue(cellAddress: CellAddress): SerializedCellValue;
|
|
128
167
|
isCellEmpty(cellAddress: CellAddress): boolean;
|
|
129
168
|
isFormulaCell(cellAddress: CellAddress): boolean;
|
|
@@ -109,14 +109,42 @@ export declare enum FormulaError {
|
|
|
109
109
|
ERROR = "#ERROR!",
|
|
110
110
|
SPILL = "#SPILL!"
|
|
111
111
|
}
|
|
112
|
-
export interface Sheet {
|
|
112
|
+
export interface Sheet<TCellMetadata = unknown, TSheetMetadata = unknown> {
|
|
113
113
|
name: string;
|
|
114
114
|
index: number;
|
|
115
115
|
content: Map<string, SerializedCellValue>;
|
|
116
|
+
/**
|
|
117
|
+
* Cell metadata - arbitrary consumer-defined data per cell
|
|
118
|
+
* Examples: rich text content, links, comments, custom app data
|
|
119
|
+
* The engine stores and copies this data but doesn't interpret it
|
|
120
|
+
* Keyed by cell reference (e.g., "A1")
|
|
121
|
+
*/
|
|
122
|
+
metadata: Map<string, TCellMetadata>;
|
|
123
|
+
/**
|
|
124
|
+
* Sheet-level metadata - arbitrary consumer-defined data for the entire sheet
|
|
125
|
+
* Examples: text boxes, drawings, frozen panes, print settings
|
|
126
|
+
* The engine stores and copies this data but doesn't interpret it
|
|
127
|
+
*/
|
|
128
|
+
sheetMetadata: TSheetMetadata;
|
|
116
129
|
}
|
|
117
|
-
export interface Workbook {
|
|
130
|
+
export interface Workbook<TCellMetadata = unknown, TSheetMetadata = unknown, TWorkbookMetadata = unknown> {
|
|
118
131
|
name: string;
|
|
119
|
-
sheets: Map<string, Sheet
|
|
132
|
+
sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;
|
|
133
|
+
/**
|
|
134
|
+
* Workbook-level metadata - arbitrary consumer-defined data for the entire workbook
|
|
135
|
+
* Examples: themes, custom ribbons, document properties, workbook settings
|
|
136
|
+
* The engine stores and copies this data but doesn't interpret it
|
|
137
|
+
*/
|
|
138
|
+
workbookMetadata: TWorkbookMetadata;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Tracked reference - a stable reference to a range that updates automatically
|
|
142
|
+
* when workbooks/sheets are renamed and becomes invalid when they're deleted
|
|
143
|
+
*/
|
|
144
|
+
export interface TrackedReference {
|
|
145
|
+
id: string;
|
|
146
|
+
address: RangeAddress;
|
|
147
|
+
isValid: boolean;
|
|
120
148
|
}
|
|
121
149
|
export type ValueEvaluationResult = {
|
|
122
150
|
type: "value";
|
|
@@ -301,11 +329,11 @@ export interface GradientStyleCondition {
|
|
|
301
329
|
}
|
|
302
330
|
export type StyleCondition = FormulaStyleCondition | GradientStyleCondition;
|
|
303
331
|
export interface ConditionalStyle {
|
|
304
|
-
|
|
332
|
+
areas: RangeAddress[];
|
|
305
333
|
condition: StyleCondition;
|
|
306
334
|
}
|
|
307
335
|
export interface DirectCellStyle {
|
|
308
|
-
|
|
336
|
+
areas: RangeAddress[];
|
|
309
337
|
style: CellStyle;
|
|
310
338
|
}
|
|
311
339
|
export interface CellStyle {
|
|
@@ -317,19 +345,32 @@ export interface CellStyle {
|
|
|
317
345
|
underline?: boolean;
|
|
318
346
|
}
|
|
319
347
|
export interface CopyCellsOptions {
|
|
320
|
-
cut: boolean;
|
|
321
348
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
|
|
349
|
+
* Whether this is a cut operation (clears source cells after copying)
|
|
350
|
+
* @default false
|
|
351
|
+
*/
|
|
352
|
+
cut?: boolean;
|
|
353
|
+
/**
|
|
354
|
+
* What to include in the copy operation.
|
|
355
|
+
* - Use 'all' as shorthand for ['content', 'style', 'metadata']
|
|
356
|
+
* - Use array for fine-grained control over what to copy:
|
|
357
|
+
* - ['content'] - copy only values/formulas
|
|
358
|
+
* - ['style'] - copy only formatting
|
|
359
|
+
* - ['metadata'] - copy only metadata (rich text, links, etc.)
|
|
360
|
+
* - ['content', 'style'] - copy content and formatting
|
|
361
|
+
* - ['content', 'metadata'] - copy content and metadata
|
|
362
|
+
* - ['style', 'metadata'] - copy formatting and metadata
|
|
363
|
+
* - ['content', 'style', 'metadata'] - same as 'all'
|
|
364
|
+
* @default 'all'
|
|
325
365
|
*/
|
|
326
|
-
|
|
366
|
+
include?: 'all' | ('content' | 'style' | 'metadata')[];
|
|
327
367
|
/**
|
|
328
368
|
* The type of the content to copy
|
|
329
369
|
* value: Copy the value from the source to the target,
|
|
330
370
|
* e.g. if the cell has the formula =123 + 123 then the value is 246
|
|
331
371
|
* formula: Copy the formula from the source to the target,
|
|
332
372
|
* e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied
|
|
373
|
+
* @default 'formula'
|
|
333
374
|
*/
|
|
334
|
-
type
|
|
375
|
+
type?: "value" | "formula";
|
|
335
376
|
}
|