@ricsam/formula-engine 0.2.11 → 0.2.12

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 (31) hide show
  1. package/dist/cjs/core/autofill-utils.cjs +68 -2
  2. package/dist/cjs/core/autofill-utils.cjs.map +3 -3
  3. package/dist/cjs/core/engine-snapshot.cjs +2 -2
  4. package/dist/cjs/core/engine-snapshot.cjs.map +3 -3
  5. package/dist/cjs/core/engine.cjs +47 -3
  6. package/dist/cjs/core/engine.cjs.map +3 -3
  7. package/dist/cjs/core/managers/copy-manager.cjs +163 -14
  8. package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
  9. package/dist/cjs/core/managers/range-metadata-manager.cjs +135 -0
  10. package/dist/cjs/core/managers/range-metadata-manager.cjs.map +10 -0
  11. package/dist/cjs/core/types.cjs.map +1 -1
  12. package/dist/cjs/package.json +1 -1
  13. package/dist/mjs/core/autofill-utils.mjs +68 -2
  14. package/dist/mjs/core/autofill-utils.mjs.map +3 -3
  15. package/dist/mjs/core/engine-snapshot.mjs +2 -2
  16. package/dist/mjs/core/engine-snapshot.mjs.map +3 -3
  17. package/dist/mjs/core/engine.mjs +47 -3
  18. package/dist/mjs/core/engine.mjs.map +3 -3
  19. package/dist/mjs/core/managers/copy-manager.mjs +163 -14
  20. package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
  21. package/dist/mjs/core/managers/range-metadata-manager.mjs +95 -0
  22. package/dist/mjs/core/managers/range-metadata-manager.mjs.map +10 -0
  23. package/dist/mjs/core/types.mjs.map +1 -1
  24. package/dist/mjs/package.json +1 -1
  25. package/dist/types/core/autofill-utils.d.ts +7 -1
  26. package/dist/types/core/engine-snapshot.d.ts +4 -2
  27. package/dist/types/core/engine.d.ts +32 -1
  28. package/dist/types/core/managers/copy-manager.d.ts +11 -1
  29. package/dist/types/core/managers/range-metadata-manager.d.ts +22 -0
  30. package/dist/types/core/types.d.ts +19 -6
  31. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ // src/core/managers/range-metadata-manager.ts
2
+ import { isCellInRange } from "../utils.mjs";
3
+ import { rangesIntersect, subtractRange } from "../utils/range-utils.mjs";
4
+ var cloneArea = (area) => ({
5
+ workbookName: area.workbookName,
6
+ sheetName: area.sheetName,
7
+ range: {
8
+ start: { ...area.range.start },
9
+ end: {
10
+ col: { ...area.range.end.col },
11
+ row: { ...area.range.end.row }
12
+ }
13
+ }
14
+ });
15
+ var cloneEntry = (entry) => ({
16
+ id: entry.id,
17
+ areas: entry.areas.map(cloneArea),
18
+ metadata: entry.metadata
19
+ });
20
+
21
+ class RangeMetadataManager {
22
+ rangeMetadata = [];
23
+ addRangeMetadata(entry) {
24
+ const id = entry.id ?? crypto.randomUUID();
25
+ if (this.rangeMetadata.some((existing) => existing.id === id)) {
26
+ throw new Error(`Range metadata with id "${id}" already exists`);
27
+ }
28
+ this.rangeMetadata.push({
29
+ id,
30
+ areas: entry.areas.map(cloneArea),
31
+ metadata: entry.metadata
32
+ });
33
+ return id;
34
+ }
35
+ removeRangeMetadata(id) {
36
+ const beforeLength = this.rangeMetadata.length;
37
+ this.rangeMetadata = this.rangeMetadata.filter((entry) => entry.id !== id);
38
+ return this.rangeMetadata.length !== beforeLength;
39
+ }
40
+ getAllRangeMetadata() {
41
+ return this.rangeMetadata.map(cloneEntry);
42
+ }
43
+ getRangeMetadataForCell(cellAddress) {
44
+ return this.rangeMetadata.filter((entry) => entry.areas.some((area) => area.workbookName === cellAddress.workbookName && area.sheetName === cellAddress.sheetName && isCellInRange(cellAddress, area.range))).map(cloneEntry);
45
+ }
46
+ getRangeMetadataIntersectingWithRange(range) {
47
+ return this.rangeMetadata.filter((entry) => entry.areas.some((area) => area.workbookName === range.workbookName && area.sheetName === range.sheetName && rangesIntersect(area.range, range.range))).map(cloneEntry);
48
+ }
49
+ clearRangeMetadataInRange(range) {
50
+ this.rangeMetadata = this.rangeMetadata.map((entry) => ({
51
+ ...entry,
52
+ areas: entry.areas.flatMap((area) => {
53
+ if (area.workbookName !== range.workbookName || area.sheetName !== range.sheetName) {
54
+ return [area];
55
+ }
56
+ return subtractRange(area.range, range.range).map((remainingRange) => ({
57
+ ...area,
58
+ range: remainingRange
59
+ }));
60
+ })
61
+ })).filter((entry) => entry.areas.length > 0);
62
+ }
63
+ removeWorkbookRangeMetadata(workbookName) {
64
+ this.rangeMetadata = this.rangeMetadata.filter((entry) => !entry.areas.some((area) => area.workbookName === workbookName));
65
+ }
66
+ removeSheetRangeMetadata(workbookName, sheetName) {
67
+ this.rangeMetadata = this.rangeMetadata.filter((entry) => !entry.areas.some((area) => area.workbookName === workbookName && area.sheetName === sheetName));
68
+ }
69
+ updateWorkbookName(oldName, newName) {
70
+ this.rangeMetadata = this.rangeMetadata.map((entry) => ({
71
+ ...entry,
72
+ areas: entry.areas.map((area) => area.workbookName === oldName ? { ...area, workbookName: newName } : area)
73
+ }));
74
+ }
75
+ updateSheetName(workbookName, oldSheetName, newSheetName) {
76
+ this.rangeMetadata = this.rangeMetadata.map((entry) => ({
77
+ ...entry,
78
+ areas: entry.areas.map((area) => area.workbookName === workbookName && area.sheetName === oldSheetName ? { ...area, sheetName: newSheetName } : area)
79
+ }));
80
+ }
81
+ resetRangeMetadata(rangeMetadata) {
82
+ this.rangeMetadata = rangeMetadata ? rangeMetadata.map(cloneEntry) : [];
83
+ }
84
+ toSnapshot() {
85
+ return this.getAllRangeMetadata();
86
+ }
87
+ restoreFromSnapshot(snapshot) {
88
+ this.resetRangeMetadata(snapshot);
89
+ }
90
+ }
91
+ export {
92
+ RangeMetadataManager
93
+ };
94
+
95
+ //# debugId=7530C074EFE9F64464756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/core/managers/range-metadata-manager.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * RangeMetadataManager - Manages arbitrary consumer-defined metadata attached\n * to ranges rather than individual cells.\n */\n\nimport type {\n CellAddress,\n RangeAddress,\n RangeMetadata,\n RangeMetadataInput,\n} from \"../types.mjs\";\nimport type { RangeMetadataManagerSnapshot } from \"../engine-snapshot.mjs\";\nimport { isCellInRange } from \"../utils.mjs\";\nimport { rangesIntersect, subtractRange } from \"../utils/range-utils.mjs\";\n\nconst cloneArea = (area: RangeAddress): RangeAddress => ({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: {\n start: { ...area.range.start },\n end: {\n col: { ...area.range.end.col },\n row: { ...area.range.end.row },\n },\n },\n});\n\nconst cloneEntry = <TMetadata>(\n entry: RangeMetadata<TMetadata>\n): RangeMetadata<TMetadata> => ({\n id: entry.id,\n areas: entry.areas.map(cloneArea),\n metadata: entry.metadata,\n});\n\nexport class RangeMetadataManager<TMetadata = unknown> {\n private rangeMetadata: RangeMetadata<TMetadata>[] = [];\n\n addRangeMetadata(entry: RangeMetadataInput<TMetadata>): string {\n const id = entry.id ?? crypto.randomUUID();\n if (this.rangeMetadata.some((existing) => existing.id === id)) {\n throw new Error(`Range metadata with id \"${id}\" already exists`);\n }\n\n this.rangeMetadata.push({\n id,\n areas: entry.areas.map(cloneArea),\n metadata: entry.metadata,\n });\n\n return id;\n }\n\n removeRangeMetadata(id: string): boolean {\n const beforeLength = this.rangeMetadata.length;\n this.rangeMetadata = this.rangeMetadata.filter((entry) => entry.id !== id);\n return this.rangeMetadata.length !== beforeLength;\n }\n\n getAllRangeMetadata(): RangeMetadata<TMetadata>[] {\n return this.rangeMetadata.map(cloneEntry);\n }\n\n getRangeMetadataForCell(cellAddress: CellAddress): RangeMetadata<TMetadata>[] {\n return this.rangeMetadata\n .filter((entry) =>\n entry.areas.some(\n (area) =>\n area.workbookName === cellAddress.workbookName &&\n area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, area.range)\n )\n )\n .map(cloneEntry);\n }\n\n getRangeMetadataIntersectingWithRange(\n range: RangeAddress\n ): RangeMetadata<TMetadata>[] {\n return this.rangeMetadata\n .filter((entry) =>\n entry.areas.some(\n (area) =>\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n )\n )\n .map(cloneEntry);\n }\n\n clearRangeMetadataInRange(range: RangeAddress): void {\n this.rangeMetadata = this.rangeMetadata\n .map((entry) => ({\n ...entry,\n areas: entry.areas.flatMap((area) => {\n if (\n area.workbookName !== range.workbookName ||\n area.sheetName !== range.sheetName\n ) {\n return [area];\n }\n\n return subtractRange(area.range, range.range).map((remainingRange) => ({\n ...area,\n range: remainingRange,\n }));\n }),\n }))\n .filter((entry) => entry.areas.length > 0);\n }\n\n removeWorkbookRangeMetadata(workbookName: string): void {\n this.rangeMetadata = this.rangeMetadata.filter(\n (entry) => !entry.areas.some((area) => area.workbookName === workbookName)\n );\n }\n\n removeSheetRangeMetadata(workbookName: string, sheetName: string): void {\n this.rangeMetadata = this.rangeMetadata.filter(\n (entry) =>\n !entry.areas.some(\n (area) =>\n area.workbookName === workbookName && area.sheetName === sheetName\n )\n );\n }\n\n updateWorkbookName(oldName: string, newName: string): void {\n this.rangeMetadata = this.rangeMetadata.map((entry) => ({\n ...entry,\n areas: entry.areas.map((area) =>\n area.workbookName === oldName ? { ...area, workbookName: newName } : area\n ),\n }));\n }\n\n updateSheetName(\n workbookName: string,\n oldSheetName: string,\n newSheetName: string\n ): void {\n this.rangeMetadata = this.rangeMetadata.map((entry) => ({\n ...entry,\n areas: entry.areas.map((area) =>\n area.workbookName === workbookName && area.sheetName === oldSheetName\n ? { ...area, sheetName: newSheetName }\n : area\n ),\n }));\n }\n\n resetRangeMetadata(rangeMetadata?: RangeMetadata<TMetadata>[]): void {\n this.rangeMetadata = rangeMetadata ? rangeMetadata.map(cloneEntry) : [];\n }\n\n toSnapshot(): RangeMetadataManagerSnapshot {\n return this.getAllRangeMetadata();\n }\n\n restoreFromSnapshot(snapshot: RangeMetadataManagerSnapshot): void {\n this.resetRangeMetadata(snapshot as RangeMetadata<TMetadata>[]);\n }\n}\n"
6
+ ],
7
+ "mappings": "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",
8
+ "debugId": "7530C074EFE9F64464756E2164756E21",
9
+ "names": []
10
+ }
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/types.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.mjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport type { FunctionNode } from \"../parser/ast.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.mjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\nexport interface SearchOptions {\n workbookName?: string;\n sheetName?: string;\n caseSensitive?: boolean;\n}\n\nexport interface SearchMatch {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n cellContent: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n}\n\nexport interface ReplaceTarget {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n occurrenceIndex: number;\n}\n\nexport interface ReplaceChange {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n replacementText: string;\n beforeContent: string;\n afterContent: string;\n}\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'metadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['metadata'] - copy only metadata (rich text, links, etc.)\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'metadata'] - copy content and metadata\n * - ['style', 'metadata'] - copy formatting and metadata\n * - ['content', 'style', 'metadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | (\"content\" | \"style\" | \"metadata\")[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
5
+ "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.mjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport type { FunctionNode } from \"../parser/ast.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.mjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\nexport interface SearchOptions {\n workbookName?: string;\n sheetName?: string;\n caseSensitive?: boolean;\n}\n\nexport interface SearchMatch {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n cellContent: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n}\n\nexport interface ReplaceTarget {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n occurrenceIndex: number;\n}\n\nexport interface ReplaceChange {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n replacementText: string;\n beforeContent: string;\n afterContent: string;\n}\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface RangeMetadata<TMetadata = unknown> {\n id: string;\n areas: RangeAddress[];\n metadata: TMetadata;\n}\n\nexport interface RangeMetadataInput<TMetadata = unknown> {\n id?: string;\n areas: RangeAddress[];\n metadata: TMetadata;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n wrapText?: boolean;\n}\n\nexport type CopyCellsIncludePart =\n | \"content\"\n | \"style\"\n | \"cellMetadata\"\n | \"rangeMetadata\";\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'cellMetadata', 'rangeMetadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['cellMetadata'] - copy only cell metadata (rich text, links, etc.)\n * - ['rangeMetadata'] - copy only range metadata\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'cellMetadata'] - copy content and cell metadata\n * - ['style', 'rangeMetadata'] - copy formatting and range metadata\n * - ['content', 'style', 'cellMetadata', 'rangeMetadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | CopyCellsIncludePart[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
6
6
  ],
7
7
  "mappings": ";AAkKO,IAAK;AAAA,CAAL,CAAK,kBAAL;AAAA,EACL,wBAAO;AAAA,EACP,sBAAK;AAAA,EACL,wBAAO;AAAA,EACP,uBAAM;AAAA,EACN,uBAAM;AAAA,EACN,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,GATE;",
8
8
  "debugId": "0E7C5AF634572D3964756E2164756E21",
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "type": "module"
5
5
  }
@@ -5,10 +5,12 @@ import type { SpreadsheetRange } from "./types";
5
5
  import type { FillDirection } from "@ricsam/selection-manager";
6
6
  import type { WorkbookManager } from "./managers/workbook-manager";
7
7
  import type { StyleManager } from "./managers/style-manager";
8
+ import type { RangeMetadataManager } from "./managers/range-metadata-manager";
8
9
  export declare class AutoFill {
9
10
  private workbookManager;
10
11
  private styleManager;
11
- constructor(workbookManager: WorkbookManager, styleManager: StyleManager);
12
+ private rangeMetadataManager;
13
+ constructor(workbookManager: WorkbookManager, styleManager: StyleManager, rangeMetadataManager: RangeMetadataManager);
12
14
  /**
13
15
  * Converts a SpreadsheetRange to FiniteSpreadsheetRange, throwing an error if infinite
14
16
  */
@@ -37,4 +39,8 @@ export declare class AutoFill {
37
39
  * Copy metadata from seed range to fill range with pattern repetition
38
40
  */
39
41
  private fillMetadata;
42
+ /**
43
+ * Copy range metadata from seed range to fill range with pattern repetition.
44
+ */
45
+ private fillRangeMetadata;
40
46
  }
@@ -1,7 +1,7 @@
1
1
  import type { ContextDependency } from "../evaluator/evaluation-context";
2
2
  import type { DependencyNode } from "./managers/dependency-node";
3
- import type { CellAddress, CellInRangeResult, CellValue, ConditionalStyle, DirectCellStyle, FormulaError, NamedExpression, RangeAddress, RelativeRange, SpreadsheetRange, TableDefinition, TrackedReference, Workbook } from "./types";
4
- export declare const ENGINE_SNAPSHOT_VERSION: 4;
3
+ import type { CellAddress, CellInRangeResult, CellValue, ConditionalStyle, DirectCellStyle, FormulaError, NamedExpression, RangeAddress, RangeMetadata, RelativeRange, SpreadsheetRange, TableDefinition, TrackedReference, Workbook } from "./types";
4
+ export declare const ENGINE_SNAPSHOT_VERSION: 5;
5
5
  export type NodeSnapshotId = string;
6
6
  export type NamedExpressionManagerSnapshot = {
7
7
  sheetExpressions: Map<string, Map<string, Map<string, NamedExpression>>>;
@@ -14,6 +14,7 @@ export type StyleManagerSnapshot = {
14
14
  conditionalStyles: ConditionalStyle[];
15
15
  cellStyles: DirectCellStyle[];
16
16
  };
17
+ export type RangeMetadataManagerSnapshot = RangeMetadata[];
17
18
  export type ReferenceManagerSnapshot = Map<string, TrackedReference>;
18
19
  export type SerializedValueEvaluationResultSnapshot = {
19
20
  type: "value";
@@ -124,6 +125,7 @@ type EngineSnapshotManagers = {
124
125
  namedExpression: NamedExpressionManagerSnapshot;
125
126
  table: TableManagerSnapshot;
126
127
  style: StyleManagerSnapshot;
128
+ rangeMetadata: RangeMetadataManagerSnapshot;
127
129
  reference: ReferenceManagerSnapshot;
128
130
  dependency: DependencyManagerSnapshot;
129
131
  cache: CacheManagerSnapshot;
@@ -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 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 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";
6
6
  import type { FillDirection } from "@ricsam/selection-manager";
7
7
  import { AutoFill } from "./autofill-utils";
8
8
  import { WorkbookManager } from "./managers/workbook-manager";
@@ -12,8 +12,10 @@ import { EventManager } from "./managers/event-manager";
12
12
  import { EvaluationManager } from "./managers/evaluation-manager";
13
13
  import { DependencyManager } from "./managers/dependency-manager";
14
14
  import { StyleManager } from "./managers/style-manager";
15
+ import { RangeMetadataManager } from "./managers/range-metadata-manager";
15
16
  type Metadata = {
16
17
  cell?: unknown;
18
+ range?: unknown;
17
19
  sheet?: unknown;
18
20
  workbook?: unknown;
19
21
  };
@@ -31,6 +33,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
31
33
  private autoFillManager;
32
34
  private dependencyManager;
33
35
  private styleManager;
36
+ private rangeMetadataManager;
34
37
  private copyManager;
35
38
  private referenceManager;
36
39
  /**
@@ -44,6 +47,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
44
47
  _autoFillManager: AutoFill;
45
48
  _dependencyManager: DependencyManager;
46
49
  _styleManager: StyleManager;
50
+ _rangeMetadataManager: RangeMetadataManager<MetadataType<TMetadata, "range">>;
47
51
  constructor();
48
52
  /**
49
53
  * Static factory method to build an empty engine
@@ -98,6 +102,32 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
98
102
  * Get metadata for a workbook
99
103
  */
100
104
  getWorkbookMetadata(workbookName: string): MetadataType<TMetadata, "workbook"> | undefined;
105
+ /**
106
+ * Add metadata attached to one or more ranges.
107
+ * Range metadata is arbitrary consumer-defined data that follows range
108
+ * copy/paste, autofill, workbook/sheet rename, and serialization flows.
109
+ */
110
+ addRangeMetadata(metadata: RangeMetadataInput<MetadataType<TMetadata, "range">>): string;
111
+ /**
112
+ * Remove a range metadata entry by id.
113
+ */
114
+ removeRangeMetadata(id: string): void;
115
+ /**
116
+ * Get all range metadata entries.
117
+ */
118
+ getAllRangeMetadata(): RangeMetadata<MetadataType<TMetadata, "range">>[];
119
+ /**
120
+ * Get range metadata entries that apply to a specific cell.
121
+ */
122
+ getRangeMetadataForCell(address: CellAddress): RangeMetadata<MetadataType<TMetadata, "range">>[];
123
+ /**
124
+ * Get range metadata entries intersecting with a range.
125
+ */
126
+ getRangeMetadataIntersectingWithRange(range: RangeAddress): RangeMetadata<MetadataType<TMetadata, "range">>[];
127
+ /**
128
+ * Clear range metadata from a range, preserving non-overlapping portions.
129
+ */
130
+ clearRangeMetadata(range: RangeAddress): void;
101
131
  /**
102
132
  * Create a tracked reference to a range
103
133
  * Returns a stable UUID that can be used to retrieve the address later
@@ -487,6 +517,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
487
517
  tables: Map<string, Map<string, TableDefinition>>;
488
518
  conditionalStyles: ConditionalStyle[];
489
519
  cellStyles: DirectCellStyle[];
520
+ rangeMetadata: RangeMetadata<MetadataType<TMetadata, "range">>[];
490
521
  references: Map<string, import("./types").TrackedReference>;
491
522
  };
492
523
  onUpdate(listener: () => void): () => void;
@@ -5,11 +5,13 @@ import type { CellAddress, CopyCellsOptions, RangeAddress } from "../types";
5
5
  import type { WorkbookManager } from "./workbook-manager";
6
6
  import type { EvaluationManager } from "./evaluation-manager";
7
7
  import type { StyleManager } from "./style-manager";
8
+ import type { RangeMetadataManager } from "./range-metadata-manager";
8
9
  export declare class CopyManager {
9
10
  private workbookManager;
10
11
  private evaluationManager;
11
12
  private styleManager;
12
- constructor(workbookManager: WorkbookManager, evaluationManager: EvaluationManager, styleManager: StyleManager);
13
+ private rangeMetadataManager;
14
+ constructor(workbookManager: WorkbookManager, evaluationManager: EvaluationManager, styleManager: StyleManager, rangeMetadataManager: RangeMetadataManager);
13
15
  /**
14
16
  * Normalize the include option to an array of parts to copy
15
17
  */
@@ -60,6 +62,7 @@ export declare class CopyManager {
60
62
  * Copy content from a cell snapshot to a target cell
61
63
  */
62
64
  private copyCellContentFromSnapshot;
65
+ private copyCellMetadataFromSnapshot;
63
66
  /**
64
67
  * Update all formula references when cells are cut (moved)
65
68
  */
@@ -77,6 +80,11 @@ export declare class CopyManager {
77
80
  * Clears existing cell styles in target range first (Excel behavior)
78
81
  */
79
82
  private copyFormatting;
83
+ private cloneMetadataValue;
84
+ private getRangeAddressFromBoundingBox;
85
+ private collectRangeMetadataCopies;
86
+ private applyRangeMetadataCopies;
87
+ private copyRangeMetadata;
80
88
  /**
81
89
  * Get bounding box for a set of cells
82
90
  */
@@ -123,6 +131,8 @@ export declare class CopyManager {
123
131
  * Adjust formula references by a specific row/column offset
124
132
  */
125
133
  private adjustFormulaWithOffset;
134
+ private copyCellMetadata;
135
+ private copyCellRangeMetadata;
126
136
  /**
127
137
  * Copy formatting from one cell to another
128
138
  * Clears existing cell styles at target (Excel behavior) before copying new ones
@@ -0,0 +1,22 @@
1
+ /**
2
+ * RangeMetadataManager - Manages arbitrary consumer-defined metadata attached
3
+ * to ranges rather than individual cells.
4
+ */
5
+ import type { CellAddress, RangeAddress, RangeMetadata, RangeMetadataInput } from "../types";
6
+ import type { RangeMetadataManagerSnapshot } from "../engine-snapshot";
7
+ export declare class RangeMetadataManager<TMetadata = unknown> {
8
+ private rangeMetadata;
9
+ addRangeMetadata(entry: RangeMetadataInput<TMetadata>): string;
10
+ removeRangeMetadata(id: string): boolean;
11
+ getAllRangeMetadata(): RangeMetadata<TMetadata>[];
12
+ getRangeMetadataForCell(cellAddress: CellAddress): RangeMetadata<TMetadata>[];
13
+ getRangeMetadataIntersectingWithRange(range: RangeAddress): RangeMetadata<TMetadata>[];
14
+ clearRangeMetadataInRange(range: RangeAddress): void;
15
+ removeWorkbookRangeMetadata(workbookName: string): void;
16
+ removeSheetRangeMetadata(workbookName: string, sheetName: string): void;
17
+ updateWorkbookName(oldName: string, newName: string): void;
18
+ updateSheetName(workbookName: string, oldSheetName: string, newSheetName: string): void;
19
+ resetRangeMetadata(rangeMetadata?: RangeMetadata<TMetadata>[]): void;
20
+ toSnapshot(): RangeMetadataManagerSnapshot;
21
+ restoreFromSnapshot(snapshot: RangeMetadataManagerSnapshot): void;
22
+ }
@@ -371,6 +371,16 @@ export interface DirectCellStyle {
371
371
  areas: RangeAddress[];
372
372
  style: CellStyle;
373
373
  }
374
+ export interface RangeMetadata<TMetadata = unknown> {
375
+ id: string;
376
+ areas: RangeAddress[];
377
+ metadata: TMetadata;
378
+ }
379
+ export interface RangeMetadataInput<TMetadata = unknown> {
380
+ id?: string;
381
+ areas: RangeAddress[];
382
+ metadata: TMetadata;
383
+ }
374
384
  export interface CellStyle {
375
385
  backgroundColor?: string;
376
386
  color?: string;
@@ -378,7 +388,9 @@ export interface CellStyle {
378
388
  bold?: boolean;
379
389
  italic?: boolean;
380
390
  underline?: boolean;
391
+ wrapText?: boolean;
381
392
  }
393
+ export type CopyCellsIncludePart = "content" | "style" | "cellMetadata" | "rangeMetadata";
382
394
  export interface CopyCellsOptions {
383
395
  /**
384
396
  * Whether this is a cut operation (clears source cells after copying)
@@ -387,18 +399,19 @@ export interface CopyCellsOptions {
387
399
  cut?: boolean;
388
400
  /**
389
401
  * What to include in the copy operation.
390
- * - Use 'all' as shorthand for ['content', 'style', 'metadata']
402
+ * - Use 'all' as shorthand for ['content', 'style', 'cellMetadata', 'rangeMetadata']
391
403
  * - Use array for fine-grained control over what to copy:
392
404
  * - ['content'] - copy only values/formulas
393
405
  * - ['style'] - copy only formatting
394
- * - ['metadata'] - copy only metadata (rich text, links, etc.)
406
+ * - ['cellMetadata'] - copy only cell metadata (rich text, links, etc.)
407
+ * - ['rangeMetadata'] - copy only range metadata
395
408
  * - ['content', 'style'] - copy content and formatting
396
- * - ['content', 'metadata'] - copy content and metadata
397
- * - ['style', 'metadata'] - copy formatting and metadata
398
- * - ['content', 'style', 'metadata'] - same as 'all'
409
+ * - ['content', 'cellMetadata'] - copy content and cell metadata
410
+ * - ['style', 'rangeMetadata'] - copy formatting and range metadata
411
+ * - ['content', 'style', 'cellMetadata', 'rangeMetadata'] - same as 'all'
399
412
  * @default 'all'
400
413
  */
401
- include?: "all" | ("content" | "style" | "metadata")[];
414
+ include?: "all" | CopyCellsIncludePart[];
402
415
  /**
403
416
  * The type of the content to copy
404
417
  * value: Copy the value from the source to the target,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",