@ricsam/formula-engine 0.0.16 → 0.0.18

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 (122) hide show
  1. package/dist/cjs/core/api/api-builder.cjs +67 -0
  2. package/dist/cjs/core/api/api-builder.cjs.map +10 -0
  3. package/dist/cjs/core/api/api-helpers.cjs +191 -0
  4. package/dist/cjs/core/api/api-helpers.cjs.map +10 -0
  5. package/dist/cjs/core/api/api.cjs +65 -0
  6. package/dist/cjs/core/api/api.cjs.map +10 -0
  7. package/dist/cjs/core/api/cell-orm.cjs +80 -0
  8. package/dist/cjs/core/api/cell-orm.cjs.map +10 -0
  9. package/dist/cjs/core/api/table-orm.cjs +171 -0
  10. package/dist/cjs/core/api/table-orm.cjs.map +10 -0
  11. package/dist/cjs/core/autofill-utils.cjs +75 -39
  12. package/dist/cjs/core/autofill-utils.cjs.map +3 -3
  13. package/dist/cjs/core/cell-mover.cjs +178 -0
  14. package/dist/cjs/core/cell-mover.cjs.map +10 -0
  15. package/dist/cjs/core/commands/command-executor.cjs +140 -0
  16. package/dist/cjs/core/commands/command-executor.cjs.map +10 -0
  17. package/dist/cjs/core/commands/content-commands.cjs +574 -0
  18. package/dist/cjs/core/commands/content-commands.cjs.map +10 -0
  19. package/dist/cjs/core/commands/index.cjs +95 -0
  20. package/dist/cjs/core/commands/index.cjs.map +10 -0
  21. package/dist/cjs/core/commands/metadata-commands.cjs +150 -0
  22. package/dist/cjs/core/commands/metadata-commands.cjs.map +10 -0
  23. package/dist/cjs/core/commands/named-expression-commands.cjs +238 -0
  24. package/dist/cjs/core/commands/named-expression-commands.cjs.map +10 -0
  25. package/dist/cjs/core/commands/structure-commands.cjs +495 -0
  26. package/dist/cjs/core/commands/structure-commands.cjs.map +10 -0
  27. package/dist/cjs/core/commands/style-commands.cjs +219 -0
  28. package/dist/cjs/core/commands/style-commands.cjs.map +10 -0
  29. package/dist/cjs/core/commands/table-commands.cjs +226 -0
  30. package/dist/cjs/core/commands/table-commands.cjs.map +10 -0
  31. package/dist/cjs/core/commands/types.cjs +72 -0
  32. package/dist/cjs/core/commands/types.cjs.map +10 -0
  33. package/dist/cjs/core/engine.cjs +218 -263
  34. package/dist/cjs/core/engine.cjs.map +3 -3
  35. package/dist/cjs/core/managers/api-schema-manager.cjs +304 -0
  36. package/dist/cjs/core/managers/api-schema-manager.cjs.map +10 -0
  37. package/dist/cjs/core/managers/copy-manager.cjs +336 -82
  38. package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
  39. package/dist/cjs/core/managers/reference-manager.cjs +124 -0
  40. package/dist/cjs/core/managers/reference-manager.cjs.map +10 -0
  41. package/dist/cjs/core/managers/style-manager.cjs +115 -147
  42. package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
  43. package/dist/cjs/core/managers/workbook-manager.cjs +87 -3
  44. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  45. package/dist/cjs/core/types.cjs.map +1 -1
  46. package/dist/cjs/lib.cjs +13 -2
  47. package/dist/cjs/lib.cjs.map +3 -3
  48. package/dist/cjs/package.json +1 -1
  49. package/dist/mjs/core/api/api-builder.mjs +37 -0
  50. package/dist/mjs/core/api/api-builder.mjs.map +10 -0
  51. package/dist/mjs/core/api/api-helpers.mjs +161 -0
  52. package/dist/mjs/core/api/api-helpers.mjs.map +10 -0
  53. package/dist/mjs/core/api/api.mjs +35 -0
  54. package/dist/mjs/core/api/api.mjs.map +10 -0
  55. package/dist/mjs/core/api/cell-orm.mjs +49 -0
  56. package/dist/mjs/core/api/cell-orm.mjs.map +10 -0
  57. package/dist/mjs/core/api/table-orm.mjs +148 -0
  58. package/dist/mjs/core/api/table-orm.mjs.map +10 -0
  59. package/dist/mjs/core/autofill-utils.mjs +75 -39
  60. package/dist/mjs/core/autofill-utils.mjs.map +3 -3
  61. package/dist/mjs/core/cell-mover.mjs +148 -0
  62. package/dist/mjs/core/cell-mover.mjs.map +10 -0
  63. package/dist/mjs/core/commands/command-executor.mjs +109 -0
  64. package/dist/mjs/core/commands/command-executor.mjs.map +10 -0
  65. package/dist/mjs/core/commands/content-commands.mjs +544 -0
  66. package/dist/mjs/core/commands/content-commands.mjs.map +10 -0
  67. package/dist/mjs/core/commands/index.mjs +87 -0
  68. package/dist/mjs/core/commands/index.mjs.map +10 -0
  69. package/dist/mjs/core/commands/metadata-commands.mjs +120 -0
  70. package/dist/mjs/core/commands/metadata-commands.mjs.map +10 -0
  71. package/dist/mjs/core/commands/named-expression-commands.mjs +208 -0
  72. package/dist/mjs/core/commands/named-expression-commands.mjs.map +10 -0
  73. package/dist/mjs/core/commands/structure-commands.mjs +465 -0
  74. package/dist/mjs/core/commands/structure-commands.mjs.map +10 -0
  75. package/dist/mjs/core/commands/style-commands.mjs +189 -0
  76. package/dist/mjs/core/commands/style-commands.mjs.map +10 -0
  77. package/dist/mjs/core/commands/table-commands.mjs +196 -0
  78. package/dist/mjs/core/commands/table-commands.mjs.map +10 -0
  79. package/dist/mjs/core/commands/types.mjs +42 -0
  80. package/dist/mjs/core/commands/types.mjs.map +10 -0
  81. package/dist/mjs/core/engine.mjs +253 -263
  82. package/dist/mjs/core/engine.mjs.map +3 -3
  83. package/dist/mjs/core/managers/api-schema-manager.mjs +274 -0
  84. package/dist/mjs/core/managers/api-schema-manager.mjs.map +10 -0
  85. package/dist/mjs/core/managers/copy-manager.mjs +338 -82
  86. package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
  87. package/dist/mjs/core/managers/reference-manager.mjs +93 -0
  88. package/dist/mjs/core/managers/reference-manager.mjs.map +10 -0
  89. package/dist/mjs/core/managers/style-manager.mjs +115 -147
  90. package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
  91. package/dist/mjs/core/managers/workbook-manager.mjs +87 -3
  92. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  93. package/dist/mjs/core/types.mjs.map +1 -1
  94. package/dist/mjs/lib.mjs +13 -2
  95. package/dist/mjs/lib.mjs.map +3 -3
  96. package/dist/mjs/package.json +1 -1
  97. package/dist/types/core/api/api-builder.d.ts +16 -0
  98. package/dist/types/core/api/api-helpers.d.ts +37 -0
  99. package/dist/types/core/api/api.d.ts +83 -0
  100. package/dist/types/core/api/api.type-test.d.ts +1 -0
  101. package/dist/types/core/api/cell-orm.d.ts +29 -0
  102. package/dist/types/core/api/table-orm.d.ts +46 -0
  103. package/dist/types/core/autofill-utils.d.ts +6 -9
  104. package/dist/types/core/cell-mover.d.ts +63 -0
  105. package/dist/types/core/commands/command-executor.d.ts +83 -0
  106. package/dist/types/core/commands/content-commands.d.ts +142 -0
  107. package/dist/types/core/commands/index.d.ts +16 -0
  108. package/dist/types/core/commands/metadata-commands.d.ts +55 -0
  109. package/dist/types/core/commands/named-expression-commands.d.ts +115 -0
  110. package/dist/types/core/commands/structure-commands.d.ts +132 -0
  111. package/dist/types/core/commands/style-commands.d.ts +76 -0
  112. package/dist/types/core/commands/table-commands.d.ts +104 -0
  113. package/dist/types/core/commands/types.d.ts +114 -0
  114. package/dist/types/core/engine.d.ts +241 -23
  115. package/dist/types/core/managers/api-schema-manager.d.ts +121 -0
  116. package/dist/types/core/managers/copy-manager.d.ts +47 -2
  117. package/dist/types/core/managers/reference-manager.d.ts +54 -0
  118. package/dist/types/core/managers/style-manager.d.ts +6 -6
  119. package/dist/types/core/managers/workbook-manager.d.ts +39 -1
  120. package/dist/types/core/types.d.ts +52 -11
  121. package/dist/types/lib.d.ts +8 -0
  122. package/package.json +1 -1
@@ -72,6 +72,7 @@ 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;
75
76
  updateFormulasForWorkbook(workbookName: string, updateCallback: (formula: string) => string): void;
76
77
  getSheetSerialized({ workbookName, sheetName, }: {
77
78
  workbookName: string;
@@ -104,6 +105,43 @@ export declare class WorkbookManager {
104
105
  */
105
106
  buildingFromScratch?: boolean;
106
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;
107
145
  /**
108
146
  * Replace all content for a sheet (safely, without breaking references)
109
147
  * This method clears the existing Map and repopulates it rather than replacing the Map reference
@@ -124,7 +162,7 @@ export declare class WorkbookManager {
124
162
  */
125
163
  iterateCellsInRange(address: RangeAddress): Generator<CellAddress>;
126
164
  getCellsInRange(address: RangeAddress): CellAddress[];
127
- private getCellContent;
165
+ getCellContent(cellAddress: CellAddress): SerializedCellValue;
128
166
  getSerializedCellValue(cellAddress: CellAddress): SerializedCellValue;
129
167
  isCellEmpty(cellAddress: CellAddress): boolean;
130
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
- area: RangeAddress;
332
+ areas: RangeAddress[];
305
333
  condition: StyleCondition;
306
334
  }
307
335
  export interface DirectCellStyle {
308
- area: RangeAddress;
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
- * all: Copy everything from the source to the target
323
- * content: Copy only the content from the source to the target
324
- * style: Copy only the style from the source to the target
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
- target: 'all' | 'content' | 'style';
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: "value" | "formula";
375
+ type?: "value" | "formula";
335
376
  }
@@ -2,3 +2,11 @@ export { FormulaEngine } from "./core/engine";
2
2
  export * from "./core/types";
3
3
  export * from "./core/utils";
4
4
  export * from "./core/utils/color-utils";
5
+ export { defineApi, createApi } from "./core/api/api";
6
+ export type { CreateApi, Declaration, Api, TableApi, CellApi } from "./core/api/api";
7
+ export { TableOrm } from "./core/api/table-orm";
8
+ export { CellOrm } from "./core/api/cell-orm";
9
+ export { SchemaValidationError } from "./core/managers/api-schema-manager";
10
+ export type { ValidationResult } from "./core/managers/api-schema-manager";
11
+ export { SchemaIntegrityError } from "./core/commands";
12
+ export type { EngineAction, EngineCommand } from "./core/commands";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",