@ricsam/formula-engine 0.0.6 → 0.0.8
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/engine.cjs +9 -1
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/copy-manager.cjs +266 -0
- package/dist/cjs/core/managers/copy-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/style-manager.cjs +2 -5
- package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
- package/dist/cjs/core/types.cjs.map +1 -1
- package/dist/cjs/lib.cjs +2 -1
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/engine.mjs +9 -1
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/copy-manager.mjs +236 -0
- package/dist/mjs/core/managers/copy-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/style-manager.mjs +2 -5
- package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
- package/dist/mjs/core/types.mjs.map +1 -1
- package/dist/mjs/lib.mjs +2 -1
- package/dist/mjs/lib.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/engine.d.ts +6 -1
- package/dist/types/core/managers/copy-manager.d.ts +50 -0
- package/dist/types/core/types.d.ts +9 -0
- package/dist/types/lib.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/managers/style-manager.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * StyleManager - Manages conditional styling for cells\n */\n\nimport type {\n CellAddress,\n CellStyle,\n ConditionalStyle,\n DirectCellStyle,\n RangeAddress,\n SerializedCellValue,\n} from \"../types.cjs\";\nimport type { WorkbookManager } from \"./workbook-manager.cjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.cjs\";\nimport { isCellInRange } from \"../utils.cjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.cjs\";\n\nexport class StyleManager {\n private conditionalStyles: ConditionalStyle[] = [];\n private cellStyles: DirectCellStyle[] = [];\n\n constructor(\n private workbookManager: WorkbookManager,\n private evaluationManager: EvaluationManager\n ) {}\n\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.conditionalStyles.push(style);\n }\n\n /**\n * Remove a conditional style rule by index for a specific workbook\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.conditionalStyles.length; i++) {\n const style = this.conditionalStyles[i];\n if (style && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.conditionalStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all conditional styles for a workbook\n */\n getConditionalStyles(workbookName: string): ConditionalStyle[] {\n return this.conditionalStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.cellStyles.push(style);\n }\n\n /**\n * Remove a direct cell style rule by index for a specific workbook\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.cellStyles.length; i++) {\n const style = this.cellStyles[i];\n if (style && style.area && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.cellStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all direct cell styles for a workbook\n */\n getCellStyles(workbookName: string): DirectCellStyle[] {\n return this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n }\n\n /**\n * Get all conditional styles across all workbooks (for serialization)\n */\n getAllConditionalStyles(): ConditionalStyle[] {\n return [...this.conditionalStyles];\n }\n\n /**\n * Get all cell styles (for serialization)\n */\n getAllCellStyles(): DirectCellStyle[] {\n return [...this.cellStyles];\n }\n\n /**\n * Reset all styles (for deserialization)\n */\n resetStyles(conditionalStyles?: ConditionalStyle[], cellStyles?: DirectCellStyle[]): void {\n this.conditionalStyles = conditionalStyles ? [...conditionalStyles] : [];\n this.cellStyles = cellStyles ? [...cellStyles] : [];\n }\n\n /**\n * Remove all styles for a workbook\n */\n removeWorkbookStyles(workbookName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n }\n\n /**\n * Update workbook name in all style references\n */\n updateWorkbookName(oldName: string, newName: string): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Update sheet name in style references\n */\n updateSheetName(\n workbookName: string,\n oldSheetName: string,\n newSheetName: string\n ): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Remove styles that reference a deleted sheet\n */\n removeSheetStyles(workbookName: string, sheetName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n }\n\n /**\n * Get the style for a specific cell\n * Returns the first matching style (first match wins)\n * Checks cellStyles first, then conditionalStyles\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n // First check direct cell styles\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n continue;\n }\n if (\n cellStyle.area.workbookName === cellAddress.workbookName &&\n cellStyle.area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, cellStyle.area.range)\n ) {\n return {\n backgroundColor: cellStyle.style.backgroundColor,\n color: cellStyle.style.color,\n };\n }\n }\n\n // Then check conditional styles\n for (const style of this.conditionalStyles) {\n if (!style || !style.area) {\n continue;\n }\n // Check if cell is in the style's area\n if (\n style.area.sheetName !== cellAddress.sheetName ||\n style.area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, style.area.range)) {\n continue;\n }\n\n // Cell is in area, evaluate condition\n if (style.condition.type === \"formula\") {\n const result = this.evaluateFormulaCondition(cellAddress, style);\n if (result) return result;\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style);\n if (result) return result;\n }\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a formula-based style condition\n */\n private evaluateFormulaCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"formula\") {\n return undefined;\n }\n\n try {\n // Evaluate formula in context of the cell\n // evaluateFormula expects a full cell value (with = prefix for formulas)\n const formula = style.condition.formula.startsWith(\"=\")\n ? style.condition.formula\n : `=${style.condition.formula}`;\n \n const result = this.evaluationManager.evaluateFormula(\n formula,\n cellAddress\n );\n\n // Check if result is truthy\n const isTruthy =\n result === true ||\n result === \"TRUE\" ||\n (typeof result === \"number\" && result !== 0);\n\n if (isTruthy) {\n return {\n backgroundColor: lchToHex(style.condition.color),\n };\n }\n } catch (error) {\n // If formula evaluation fails, don't apply style\n console.warn(\"Failed to evaluate formula condition:\", error);\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a gradient-based style condition\n */\n private evaluateGradientCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"gradient\") {\n return undefined;\n }\n\n try {\n // Get the cell's evaluation result\n const evalResult = this.evaluationManager.getCellEvaluationResult(cellAddress);\n if (!evalResult || evalResult.type !== \"value\") {\n return undefined;\n }\n if (evalResult.result.type !== \"number\") {\n return undefined;\n }\n const cellValue = evalResult.result.value;\n\n // Calculate min and max values for the gradient\n const { min: minValue, max: maxValue } = this.calculateGradientBounds(\n style,\n cellAddress\n );\n\n if (minValue === null || maxValue === null) {\n return undefined;\n }\n\n // Calculate interpolation factor\n const factor = calculateGradientFactor(cellValue, minValue, maxValue);\n\n // Interpolate between min and max colors\n const minColor = style.condition.min.color;\n const maxColor = style.condition.max.color;\n const interpolatedColor = interpolateLCH(minColor, maxColor, factor);\n\n return {\n backgroundColor: lchToHex(interpolatedColor),\n };\n } catch (error) {\n console.warn(\"Failed to evaluate gradient condition:\", error);\n return undefined;\n }\n }\n\n /**\n * Calculate min and max bounds for a gradient\n */\n private calculateGradientBounds(\n style: ConditionalStyle,\n cellAddress: CellAddress\n ): { min: number | null; max: number | null } {\n if (style.condition.type !== \"gradient\") {\n return { min: null, max: null };\n }\n\n const { min: minConfig, max: maxConfig } = style.condition;\n const topLeftCell: CellAddress = {\n workbookName: style.area.workbookName,\n sheetName: style.area.sheetName,\n colIndex: style.area.range.start.col,\n rowIndex: style.area.range.start.row,\n };\n\n // Calculate min value\n let minValue: number | null = null;\n if (minConfig.type === \"lowest_value\") {\n // Evaluate MIN(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MIN(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MIN:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = minConfig.valueFormula.startsWith(\"=\")\n ? minConfig.valueFormula\n : `=${minConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n }\n\n // Calculate max value\n let maxValue: number | null = null;\n if (maxConfig.type === \"highest_value\") {\n // Evaluate MAX(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MAX(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MAX:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = maxConfig.valueFormula.startsWith(\"=\")\n ? maxConfig.valueFormula\n : `=${maxConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n }\n\n return { min: minValue, max: maxValue };\n }\n\n /**\n * Get a range reference string from a RangeAddress\n * Follows CANONICAL_RANGES.md format:\n * - Closed: A5:D10\n * - Row-bounded (col-open): A5:10\n * - Col-bounded (row-open): A5:D\n * - Open both: A5:INFINITY\n */\n private getRangeReference(area: RangeAddress): string {\n const colToLetter = (col: number): string => {\n let result = \"\";\n let c = col;\n while (c >= 0) {\n result = String.fromCharCode(65 + (c % 26)) + result;\n c = Math.floor(c / 26) - 1;\n }\n return result;\n };\n\n const startCol = colToLetter(area.range.start.col);\n const startRow = area.range.start.row + 1; // Convert to 1-based\n\n const isColInfinity = area.range.end.col.type === \"infinity\";\n const isRowInfinity = area.range.end.row.type === \"infinity\";\n\n let rangeStr: string;\n\n if (isColInfinity && isRowInfinity) {\n // Open both: A5:INFINITY\n rangeStr = `${startCol}${startRow}:INFINITY`;\n } else if (isColInfinity) {\n // Row-bounded (col-open): A5:10\n if (area.range.end.row.type === \"number\") {\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endRow}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else if (isRowInfinity) {\n // Col-bounded (row-open): A5:D\n if (area.range.end.col.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n rangeStr = `${startCol}${startRow}:${endCol}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else {\n // Closed rectangle: A5:D10\n if (area.range.end.col.type === \"number\" && area.range.end.row.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endCol}${endRow}`;\n } else {\n // Fallback to INFINITY if types don't match\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n }\n\n // Quote sheet name if it contains spaces or special characters\n const needsQuotes = /[ '!]/.test(area.sheetName);\n const sheetRef = needsQuotes ? `'${area.sheetName.replace(/'/g, \"''\")}'` : area.sheetName;\n\n // Construct the full reference: [workbook]'sheet'!range\n return `[${area.workbookName}]${sheetRef}!${rangeStr}`;\n }\n}\n\n"
|
|
5
|
+
"/**\n * StyleManager - Manages conditional styling for cells\n */\n\nimport type {\n CellAddress,\n CellStyle,\n ConditionalStyle,\n DirectCellStyle,\n RangeAddress,\n SerializedCellValue,\n} from \"../types.cjs\";\nimport type { WorkbookManager } from \"./workbook-manager.cjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.cjs\";\nimport { isCellInRange } from \"../utils.cjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.cjs\";\n\nexport class StyleManager {\n private conditionalStyles: ConditionalStyle[] = [];\n private cellStyles: DirectCellStyle[] = [];\n\n constructor(\n private workbookManager: WorkbookManager,\n private evaluationManager: EvaluationManager\n ) {}\n\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.conditionalStyles.push(style);\n }\n\n /**\n * Remove a conditional style rule by index for a specific workbook\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.conditionalStyles.length; i++) {\n const style = this.conditionalStyles[i];\n if (style && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.conditionalStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all conditional styles for a workbook\n */\n getConditionalStyles(workbookName: string): ConditionalStyle[] {\n return this.conditionalStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.cellStyles.push(style);\n }\n\n /**\n * Remove a direct cell style rule by index for a specific workbook\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.cellStyles.length; i++) {\n const style = this.cellStyles[i];\n if (style && style.area && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.cellStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all direct cell styles for a workbook\n */\n getCellStyles(workbookName: string): DirectCellStyle[] {\n return this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n }\n\n /**\n * Get all conditional styles across all workbooks (for serialization)\n */\n getAllConditionalStyles(): ConditionalStyle[] {\n return [...this.conditionalStyles];\n }\n\n /**\n * Get all cell styles (for serialization)\n */\n getAllCellStyles(): DirectCellStyle[] {\n return [...this.cellStyles];\n }\n\n /**\n * Reset all styles (for deserialization)\n */\n resetStyles(\n conditionalStyles?: ConditionalStyle[],\n cellStyles?: DirectCellStyle[]\n ): void {\n this.conditionalStyles = conditionalStyles ? [...conditionalStyles] : [];\n this.cellStyles = cellStyles ? [...cellStyles] : [];\n }\n\n /**\n * Remove all styles for a workbook\n */\n removeWorkbookStyles(workbookName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n }\n\n /**\n * Update workbook name in all style references\n */\n updateWorkbookName(oldName: string, newName: string): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Update sheet name in style references\n */\n updateSheetName(\n workbookName: string,\n oldSheetName: string,\n newSheetName: string\n ): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Remove styles that reference a deleted sheet\n */\n removeSheetStyles(workbookName: string, sheetName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n }\n\n /**\n * Get the style for a specific cell\n * Returns the first matching style (first match wins)\n * Checks cellStyles first, then conditionalStyles\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n // First check direct cell styles\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n continue;\n }\n if (\n cellStyle.area.workbookName === cellAddress.workbookName &&\n cellStyle.area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, cellStyle.area.range)\n ) {\n return cellStyle.style;\n }\n }\n\n // Then check conditional styles\n for (const style of this.conditionalStyles) {\n if (!style || !style.area) {\n continue;\n }\n // Check if cell is in the style's area\n if (\n style.area.sheetName !== cellAddress.sheetName ||\n style.area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, style.area.range)) {\n continue;\n }\n\n // Cell is in area, evaluate condition\n if (style.condition.type === \"formula\") {\n const result = this.evaluateFormulaCondition(cellAddress, style);\n if (result) return result;\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style);\n if (result) return result;\n }\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a formula-based style condition\n */\n private evaluateFormulaCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"formula\") {\n return undefined;\n }\n\n try {\n // Evaluate formula in context of the cell\n // evaluateFormula expects a full cell value (with = prefix for formulas)\n const formula = style.condition.formula.startsWith(\"=\")\n ? style.condition.formula\n : `=${style.condition.formula}`;\n\n const result = this.evaluationManager.evaluateFormula(\n formula,\n cellAddress\n );\n\n // Check if result is truthy\n const isTruthy =\n result === true ||\n result === \"TRUE\" ||\n (typeof result === \"number\" && result !== 0);\n\n if (isTruthy) {\n return {\n backgroundColor: lchToHex(style.condition.color),\n };\n }\n } catch (error) {\n // If formula evaluation fails, don't apply style\n console.warn(\"Failed to evaluate formula condition:\", error);\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a gradient-based style condition\n */\n private evaluateGradientCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"gradient\") {\n return undefined;\n }\n\n try {\n // Get the cell's evaluation result\n const evalResult =\n this.evaluationManager.getCellEvaluationResult(cellAddress);\n if (!evalResult || evalResult.type !== \"value\") {\n return undefined;\n }\n if (evalResult.result.type !== \"number\") {\n return undefined;\n }\n const cellValue = evalResult.result.value;\n\n // Calculate min and max values for the gradient\n const { min: minValue, max: maxValue } = this.calculateGradientBounds(\n style,\n cellAddress\n );\n\n if (minValue === null || maxValue === null) {\n return undefined;\n }\n\n // Calculate interpolation factor\n const factor = calculateGradientFactor(cellValue, minValue, maxValue);\n\n // Interpolate between min and max colors\n const minColor = style.condition.min.color;\n const maxColor = style.condition.max.color;\n const interpolatedColor = interpolateLCH(minColor, maxColor, factor);\n\n return {\n backgroundColor: lchToHex(interpolatedColor),\n };\n } catch (error) {\n console.warn(\"Failed to evaluate gradient condition:\", error);\n return undefined;\n }\n }\n\n /**\n * Calculate min and max bounds for a gradient\n */\n private calculateGradientBounds(\n style: ConditionalStyle,\n cellAddress: CellAddress\n ): { min: number | null; max: number | null } {\n if (style.condition.type !== \"gradient\") {\n return { min: null, max: null };\n }\n\n const { min: minConfig, max: maxConfig } = style.condition;\n const topLeftCell: CellAddress = {\n workbookName: style.area.workbookName,\n sheetName: style.area.sheetName,\n colIndex: style.area.range.start.col,\n rowIndex: style.area.range.start.row,\n };\n\n // Calculate min value\n let minValue: number | null = null;\n if (minConfig.type === \"lowest_value\") {\n // Evaluate MIN(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MIN(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MIN:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = minConfig.valueFormula.startsWith(\"=\")\n ? minConfig.valueFormula\n : `=${minConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n }\n\n // Calculate max value\n let maxValue: number | null = null;\n if (maxConfig.type === \"highest_value\") {\n // Evaluate MAX(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MAX(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MAX:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = maxConfig.valueFormula.startsWith(\"=\")\n ? maxConfig.valueFormula\n : `=${maxConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n }\n\n return { min: minValue, max: maxValue };\n }\n\n /**\n * Get a range reference string from a RangeAddress\n * Follows CANONICAL_RANGES.md format:\n * - Closed: A5:D10\n * - Row-bounded (col-open): A5:10\n * - Col-bounded (row-open): A5:D\n * - Open both: A5:INFINITY\n */\n private getRangeReference(area: RangeAddress): string {\n const colToLetter = (col: number): string => {\n let result = \"\";\n let c = col;\n while (c >= 0) {\n result = String.fromCharCode(65 + (c % 26)) + result;\n c = Math.floor(c / 26) - 1;\n }\n return result;\n };\n\n const startCol = colToLetter(area.range.start.col);\n const startRow = area.range.start.row + 1; // Convert to 1-based\n\n const isColInfinity = area.range.end.col.type === \"infinity\";\n const isRowInfinity = area.range.end.row.type === \"infinity\";\n\n let rangeStr: string;\n\n if (isColInfinity && isRowInfinity) {\n // Open both: A5:INFINITY\n rangeStr = `${startCol}${startRow}:INFINITY`;\n } else if (isColInfinity) {\n // Row-bounded (col-open): A5:10\n if (area.range.end.row.type === \"number\") {\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endRow}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else if (isRowInfinity) {\n // Col-bounded (row-open): A5:D\n if (area.range.end.col.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n rangeStr = `${startCol}${startRow}:${endCol}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else {\n // Closed rectangle: A5:D10\n if (\n area.range.end.col.type === \"number\" &&\n area.range.end.row.type === \"number\"\n ) {\n const endCol = colToLetter(area.range.end.col.value);\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endCol}${endRow}`;\n } else {\n // Fallback to INFINITY if types don't match\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n }\n\n // Quote sheet name if it contains spaces or special characters\n const needsQuotes = /[ '!]/.test(area.sheetName);\n const sheetRef = needsQuotes\n ? `'${area.sheetName.replace(/'/g, \"''\")}'`\n : area.sheetName;\n\n // Construct the full reference: [workbook]'sheet'!range\n return `[${area.workbookName}]${sheetRef}!${rangeStr}`;\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAc8B,IAA9B;AAKO,IAJP;AAAA;AAMO,MAAM,aAAa;AAAA,EAKd;AAAA,EACA;AAAA,EALF,oBAAwC,CAAC;AAAA,EACzC,aAAgC,CAAC;AAAA,EAEzC,WAAW,CACD,iBACA,mBACR;AAAA,IAFQ;AAAA,IACA;AAAA;AAAA,EAMV,mBAAmB,CAAC,OAA+B;AAAA,IACjD,KAAK,kBAAkB,KAAK,KAAK;AAAA;AAAA,EAMnC,sBAAsB,CAAC,cAAsB,OAAwB;AAAA,IACnE,MAAM,iBAAiB,KAAK,kBAAkB,OAC5C,CAAC,UAAU,MAAM,KAAK,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AO,SAAI,eAAe;AAAA,MAExB,IAAI,KAAK,MAAM,IAAI,IAAI,SAAS,UAAU;AAAA,QACxC,MAAM,SAAS,YAAY,KAAK,MAAM,IAAI,IAAI,KAAK;AAAA,QACnD,WAAW,GAAG,WAAW,YAAY;AAAA,MACvC,EAAO;AAAA,QACL,WAAW,GAAG,WAAW;AAAA;AAAA,IAE7B,EAAO;AAAA,MAEL,IACE,KAAK,MAAM,IAAI,IAAI,SAAS,YAC5B,KAAK,MAAM,IAAI,IAAI,SAAS,UAC5B;AAAA,QACA,MAAM,SAAS,YAAY,KAAK,MAAM,IAAI,IAAI,KAAK;AAAA,QACnD,MAAM,SAAS,KAAK,MAAM,IAAI,IAAI,QAAQ;AAAA,QAC1C,WAAW,GAAG,WAAW,YAAY,SAAS;AAAA,MAChD,EAAO;AAAA,QAEL,WAAW,GAAG,WAAW;AAAA;AAAA;AAAA,IAK7B,MAAM,cAAc,QAAQ,KAAK,KAAK,SAAS;AAAA,IAC/C,MAAM,WAAW,cACb,IAAI,KAAK,UAAU,QAAQ,MAAM,IAAI,OACrC,KAAK;AAAA,IAGT,OAAO,IAAI,KAAK,gBAAgB,YAAY;AAAA;AAEhD;",
|
|
8
|
+
"debugId": "837F2D1974FB775964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
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.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\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\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 {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n}\n\nexport interface Workbook {\n name: string;\n sheets: Map<string, Sheet>;\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 area: RangeAddress;\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n area: RangeAddress;\n style: CellStyle\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\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.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\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\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 {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n}\n\nexport interface Workbook {\n name: string;\n sheets: Map<string, Sheet>;\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 area: RangeAddress;\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n area: 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 cut: boolean;\n type: \"value\" | \"formula\";\n formatting: boolean;\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HO,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": "F54C7C141D21E24164756E2164756E21",
|
package/dist/cjs/lib.cjs
CHANGED
|
@@ -52,5 +52,6 @@ module.exports = __toCommonJS(exports_lib);
|
|
|
52
52
|
var import_engine = require("./core/engine.cjs");
|
|
53
53
|
__reExport(exports_lib, require("./core/types.cjs"), module.exports);
|
|
54
54
|
__reExport(exports_lib, require("./core/utils.cjs"), module.exports);
|
|
55
|
+
__reExport(exports_lib, require("./core/utils/color-utils.cjs"), module.exports);
|
|
55
56
|
|
|
56
|
-
//# debugId=
|
|
57
|
+
//# debugId=DE8C7DD7D3ED6E6764756E2164756E21
|
package/dist/cjs/lib.cjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export { FormulaEngine } from \"./core/engine.cjs\";\nexport * from \"./core/types.cjs\";\nexport * from \"./core/utils.cjs\";\n"
|
|
5
|
+
"export { FormulaEngine } from \"./core/engine.cjs\";\nexport * from \"./core/types.cjs\";\nexport * from \"./core/utils.cjs\";\nexport * from \"./core/utils/color-utils.cjs\";\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA8B,IAA9B;AACA;AACA;",
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA8B,IAA9B;AACA;AACA;AACA;",
|
|
8
|
+
"debugId": "DE8C7DD7D3ED6E6764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/package.json
CHANGED
package/dist/mjs/core/engine.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { EventManager } from "./managers/event-manager.mjs";
|
|
|
14
14
|
import { EvaluationManager } from "./managers/evaluation-manager.mjs";
|
|
15
15
|
import { DependencyManager } from "./managers/dependency-manager.mjs";
|
|
16
16
|
import { StyleManager } from "./managers/style-manager.mjs";
|
|
17
|
+
import { CopyManager } from "./managers/copy-manager.mjs";
|
|
17
18
|
|
|
18
19
|
class FormulaEngine {
|
|
19
20
|
workbookManager;
|
|
@@ -24,6 +25,7 @@ class FormulaEngine {
|
|
|
24
25
|
autoFillManager;
|
|
25
26
|
dependencyManager;
|
|
26
27
|
styleManager;
|
|
28
|
+
copyManager;
|
|
27
29
|
_workbookManager;
|
|
28
30
|
_namedExpressionManager;
|
|
29
31
|
_tableManager;
|
|
@@ -42,6 +44,7 @@ class FormulaEngine {
|
|
|
42
44
|
const formulaEvaluator = new FormulaEvaluator(this.tableManager, this.dependencyManager, this.namedExpressionManager);
|
|
43
45
|
this.evaluationManager = new EvaluationManager(this.workbookManager, this.tableManager, formulaEvaluator, this.dependencyManager);
|
|
44
46
|
this.styleManager = new StyleManager(this.workbookManager, this.evaluationManager);
|
|
47
|
+
this.copyManager = new CopyManager(this.workbookManager, this.evaluationManager, this.styleManager);
|
|
45
48
|
this.autoFillManager = new AutoFill(this.workbookManager, this);
|
|
46
49
|
this._workbookManager = this.workbookManager;
|
|
47
50
|
this._namedExpressionManager = this.namedExpressionManager;
|
|
@@ -217,6 +220,11 @@ class FormulaEngine {
|
|
|
217
220
|
getCellStyles(workbookName) {
|
|
218
221
|
return this.styleManager.getCellStyles(workbookName);
|
|
219
222
|
}
|
|
223
|
+
copyCells(source, target, options) {
|
|
224
|
+
this.copyManager.copyCells(source, target, options);
|
|
225
|
+
this.reevaluate();
|
|
226
|
+
this.eventManager.emitUpdate();
|
|
227
|
+
}
|
|
220
228
|
addSheet(opts) {
|
|
221
229
|
const newSheet = this.workbookManager.addSheet(opts);
|
|
222
230
|
const wbLevel = this.namedExpressionManager.addSheet(opts);
|
|
@@ -421,4 +429,4 @@ export {
|
|
|
421
429
|
FormulaEngine
|
|
422
430
|
};
|
|
423
431
|
|
|
424
|
-
//# debugId=
|
|
432
|
+
//# debugId=2EB061E84BF3C43A64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/core/engine.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Main FormulaEngine class\n * Core API implementation for spreadsheet calculations\n */\n\nimport {\n type CellAddress,\n type CellStyle,\n type ConditionalStyle,\n type DirectCellStyle,\n type NamedExpression,\n type RangeAddress,\n type SerializedCellValue,\n type SingleEvaluationResult,\n type SpreadsheetRange,\n type SpreadsheetRangeEnd,\n type TableDefinition,\n} from \"./types.mjs\";\n\nimport type { FillDirection } from \"@ricsam/selection-manager\";\nimport { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport { AutoFill } from \"./autofill-utils.mjs\";\nimport { WorkbookManager } from \"./managers/workbook-manager.mjs\";\nimport { deserialize, serialize } from \"./map-serializer.mjs\";\nimport { renameNamedExpressionInFormula } from \"./named-expression-renamer.mjs\";\nimport { renameSheetInFormula } from \"./sheet-renamer.mjs\";\nimport { renameTableInFormula } from \"./table-renamer.mjs\";\nimport { renameWorkbookInFormula } from \"./workbook-renamer.mjs\";\nimport { cellAddressToKey, keyToCellAddress } from \"./utils.mjs\";\nimport { CacheManager } from \"./managers/cache-manager.mjs\";\nimport { NamedExpressionManager } from \"./managers/named-expression-manager.mjs\";\nimport { TableManager } from \"./managers/table-manager.mjs\";\nimport { EventManager } from \"./managers/event-manager.mjs\";\nimport { EvaluationManager } from \"./managers/evaluation-manager.mjs\";\nimport { DependencyManager } from \"./managers/dependency-manager.mjs\";\nimport { StyleManager } from \"./managers/style-manager.mjs\";\n\n/**\n * Main FormulaEngine class\n */\nexport class FormulaEngine {\n private workbookManager: WorkbookManager;\n private namedExpressionManager: NamedExpressionManager;\n private tableManager: TableManager;\n private eventManager: EventManager;\n private evaluationManager: EvaluationManager;\n private autoFillManager: AutoFill;\n private dependencyManager: DependencyManager;\n private styleManager: StyleManager;\n\n /**\n * Public access to the store manager for testing\n */\n public _workbookManager: WorkbookManager;\n public _namedExpressionManager: NamedExpressionManager;\n public _tableManager: TableManager;\n public _eventManager: EventManager;\n public _evaluationManager: EvaluationManager;\n public _autoFillManager: AutoFill;\n public _dependencyManager: DependencyManager;\n public _styleManager: StyleManager;\n\n constructor() {\n this.eventManager = new EventManager();\n this.workbookManager = new WorkbookManager();\n this.namedExpressionManager = new NamedExpressionManager();\n this.tableManager = new TableManager(this.workbookManager);\n const cacheManager = new CacheManager();\n this.dependencyManager = new DependencyManager(\n cacheManager,\n this.workbookManager\n );\n\n const formulaEvaluator = new FormulaEvaluator(\n this.tableManager,\n this.dependencyManager,\n this.namedExpressionManager,\n );\n\n this.evaluationManager = new EvaluationManager(\n this.workbookManager,\n this.tableManager,\n formulaEvaluator,\n this.dependencyManager\n );\n\n this.styleManager = new StyleManager(\n this.workbookManager,\n this.evaluationManager\n );\n\n this.autoFillManager = new AutoFill(this.workbookManager, this);\n\n this._workbookManager = this.workbookManager;\n this._namedExpressionManager = this.namedExpressionManager;\n this._tableManager = this.tableManager;\n this._eventManager = this.eventManager;\n this._evaluationManager = this.evaluationManager;\n this._autoFillManager = this.autoFillManager;\n this._dependencyManager = this.dependencyManager;\n this._styleManager = this.styleManager;\n }\n\n /**\n * Static factory method to build an empty engine\n */\n static buildEmpty(): FormulaEngine {\n return new FormulaEngine();\n }\n\n //#region Cell\n getCellEvaluationResult(\n cellAddress: CellAddress\n ): SingleEvaluationResult | undefined {\n return this.evaluationManager.getCellEvaluationResult(cellAddress);\n }\n\n getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue {\n const result = this.getCellEvaluationResult(cellAddress);\n if (!result) {\n return \"\";\n }\n\n return this.evaluationManager.evaluationResultToSerializedValue(\n result,\n cellAddress,\n debug\n );\n }\n\n evaluateFormula(\n /**\n * formula without the leading = sign\n */\n formula: string, cellAddress: CellAddress): SerializedCellValue {\n return this.evaluationManager.evaluateFormula(formula, cellAddress);\n }\n\n getCellDependents(\n address: CellAddress | SpreadsheetRange\n ): (SpreadsheetRange | CellAddress)[] {\n throw new Error(\"Not implemented\");\n }\n\n getCellPrecedents(\n address: CellAddress | SpreadsheetRange\n ): (SpreadsheetRange | CellAddress)[] {\n throw new Error(\"Not implemented\");\n }\n\n //#endregion\n\n //#region Named Expressions\n addNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n }: {\n expression: string;\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n }) {\n this.namedExpressionManager.addNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n });\n\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n removeNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n }: {\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n }) {\n const found = this.namedExpressionManager.removeNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n });\n\n if (found) {\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n return found;\n }\n\n updateNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n }: {\n expression: string;\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n }) {\n this.namedExpressionManager.updateNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n });\n\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n renameNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n newName,\n }: {\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n newName: string;\n }) {\n const result = this.namedExpressionManager.renameNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n newName,\n });\n\n // Update all formulas that reference this named expression in sheet cells\n this.workbookManager.updateAllFormulas((formula) =>\n renameNamedExpressionInFormula(formula, expressionName, newName)\n );\n\n // Update named expressions that reference this named expression\n this.namedExpressionManager.updateAllNamedExpressions((formula) =>\n renameNamedExpressionInFormula(formula, expressionName, newName)\n );\n\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return result;\n }\n\n setNamedExpressions(\n opts: (\n | {\n type: \"global\";\n }\n | {\n type: \"sheet\";\n sheetName: string;\n workbookName: string;\n }\n | {\n type: \"workbook\";\n workbookName: string;\n }\n ) & {\n expressions: Map<string, NamedExpression>;\n }\n ) {\n this.namedExpressionManager.setNamedExpressions(opts);\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region Tables\n addTable(props: {\n tableName: string;\n sheetName: string;\n workbookName: string;\n start: string;\n numRows: SpreadsheetRangeEnd;\n numCols: number;\n }) {\n const table = this.tableManager.addTable({\n ...props,\n getCellValue: (cellAddress: CellAddress) =>\n this.getCellValue(cellAddress),\n });\n\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return table;\n }\n\n renameTable(\n workbookName: string,\n names: { oldName: string; newName: string }\n ) {\n this.tableManager.renameTable(workbookName, names);\n\n // Update all formulas that reference this table in sheet cells\n this.workbookManager.updateAllFormulas((formula) =>\n renameTableInFormula(formula, names.oldName, names.newName)\n );\n\n // Update named expressions that reference this table\n this.namedExpressionManager.updateAllNamedExpressions((formula) =>\n renameTableInFormula(formula, names.oldName, names.newName)\n );\n\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n updateTable(opts: {\n tableName: string;\n sheetName?: string;\n start?: string;\n numRows?: SpreadsheetRangeEnd;\n numCols?: number;\n workbookName: string;\n }) {\n this.tableManager.updateTable({\n ...opts,\n getCellValue: (cellAddress: CellAddress) =>\n this.getCellValue(cellAddress),\n });\n\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n removeTable(opts: { tableName: string; workbookName: string }) {\n const found = this.tableManager.removeTable(opts);\n\n if (found) {\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n return found;\n }\n\n resetTables(tables: Map<string, Map<string, TableDefinition>>) {\n this.tableManager.resetTables(tables);\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n getTables(workbookName: string) {\n return this.tableManager.getTables(workbookName);\n }\n\n isCellInTable(cellAddress: CellAddress): TableDefinition | undefined {\n return this.tableManager.isCellInTable(cellAddress);\n }\n\n //#endregion\n\n //#region Conditional Styling\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.styleManager.addConditionalStyle(style);\n this.eventManager.emitUpdate();\n }\n\n /**\n * Remove a conditional style rule by index\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const removed = this.styleManager.removeConditionalStyle(workbookName, index);\n if (removed) {\n this.eventManager.emitUpdate();\n }\n return removed;\n }\n\n /**\n * Get all conditional styles for a workbook\n */\n getConditionalStyles(workbookName: string): ConditionalStyle[] {\n return this.styleManager.getConditionalStyles(workbookName);\n }\n\n /**\n * Get the computed style for a specific cell\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n return this.styleManager.getCellStyle(cellAddress);\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.styleManager.addCellStyle(style);\n this.eventManager.emitUpdate();\n }\n\n /**\n * Remove a direct cell style rule by index\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const removed = this.styleManager.removeCellStyle(workbookName, index);\n if (removed) {\n this.eventManager.emitUpdate();\n }\n return removed;\n }\n\n /**\n * Get all direct cell styles for a workbook\n */\n getCellStyles(workbookName: string): DirectCellStyle[] {\n return this.styleManager.getCellStyles(workbookName);\n }\n\n //#endregion\n\n //#region Sheets\n addSheet(opts: { workbookName: string; sheetName: string }) {\n const newSheet = this.workbookManager.addSheet(opts);\n const wbLevel = this.namedExpressionManager.addSheet(opts);\n this.reevaluate();\n this.eventManager.emitUpdate();\n return newSheet;\n }\n\n removeSheet(opts: { workbookName: string; sheetName: string }) {\n const sheet = this.workbookManager.removeSheet(opts);\n\n // Clean up related data\n this.namedExpressionManager.removeSheet(opts);\n this.tableManager.removeSheet(opts);\n this.styleManager.removeSheetStyles(opts.workbookName, opts.sheetName);\n\n // Add engine-specific logic: re-evaluate since references might be affected\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return sheet;\n }\n\n renameSheet(opts: {\n sheetName: string;\n newSheetName: string;\n workbookName: string;\n }) {\n const sheet = this.workbookManager.renameSheet(opts);\n\n // Update scoped named expressions\n this.namedExpressionManager.renameSheet(opts);\n\n // Update tables that belong to the renamed sheet\n this.tableManager.updateTablesForSheetRename(opts);\n\n // Update conditional styles that reference this sheet\n this.styleManager.updateSheetName(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n\n // Update all formulas that reference this sheet\n this.workbookManager.updateAllFormulas((formula) =>\n renameSheetInFormula({\n formula,\n oldSheetName: opts.sheetName,\n newSheetName: opts.newSheetName,\n })\n );\n\n // Add engine-specific logic: re-evaluate since references might be affected\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return sheet;\n }\n\n getSheets(workbookName: string) {\n return this.workbookManager.getSheets(workbookName);\n }\n\n getSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }) {\n return this.workbookManager.getSheet({ workbookName, sheetName });\n }\n\n getSheetSerialized(opts: {\n sheetName: string;\n workbookName: string;\n }): Map<string, SerializedCellValue> {\n return this.workbookManager.getSheetSerialized(opts);\n }\n\n //#endregion\n\n //#region Workbook\n addWorkbook(workbookName: string) {\n this.workbookManager.addWorkbook(workbookName);\n this.namedExpressionManager.addWorkbook(workbookName);\n this.tableManager.addWorkbook(workbookName);\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n removeWorkbook(workbookName: string) {\n this.workbookManager.removeWorkbook(workbookName);\n this.namedExpressionManager.removeWorkbook(workbookName);\n this.tableManager.removeWorkbook(workbookName);\n this.styleManager.removeWorkbookStyles(workbookName);\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n cloneWorkbook(fromWorkbookName: string, toWorkbookName: string) {\n // Check if source workbook exists\n const sourceWorkbook = this.workbookManager\n .getWorkbooks()\n .get(fromWorkbookName);\n if (!sourceWorkbook) {\n throw new Error(`Source workbook \"${fromWorkbookName}\" not found`);\n }\n\n // Check if target workbook name already exists\n if (this.workbookManager.getWorkbooks().has(toWorkbookName)) {\n throw new Error(`Target workbook \"${toWorkbookName}\" already exists`);\n }\n\n // Create new workbook\n this.addWorkbook(toWorkbookName);\n\n // Clone all sheets from source workbook\n for (const [sheetName, sheet] of sourceWorkbook.sheets) {\n // Add sheet to target workbook\n this.addSheet({\n workbookName: toWorkbookName,\n sheetName: sheetName,\n });\n\n // Copy all cell content using setSheetContent for efficiency\n this.setSheetContent(\n {\n workbookName: toWorkbookName,\n sheetName: sheetName,\n },\n new Map(sheet.content)\n );\n }\n\n // Clone workbook-scoped named expressions\n const sourceWorkbookExpressions = this.namedExpressionManager\n .getNamedExpressions()\n .workbookExpressions.get(fromWorkbookName);\n if (sourceWorkbookExpressions) {\n for (const [name, expression] of sourceWorkbookExpressions) {\n this.addNamedExpression({\n expressionName: name,\n expression: expression.expression,\n workbookName: toWorkbookName,\n });\n }\n }\n\n // Clone sheet-scoped named expressions\n const sourceSheetExpressions = this.namedExpressionManager\n .getNamedExpressions()\n .sheetExpressions.get(fromWorkbookName);\n if (sourceSheetExpressions) {\n for (const [sheetName, sheetExpressions] of sourceSheetExpressions) {\n for (const [name, expression] of sheetExpressions) {\n this.addNamedExpression({\n expressionName: name,\n expression: expression.expression,\n workbookName: toWorkbookName,\n sheetName: sheetName,\n });\n }\n }\n }\n\n // Clone tables\n const sourceTables = this.tableManager.tables.get(fromWorkbookName);\n if (sourceTables) {\n for (const [tableName, table] of sourceTables) {\n this.tableManager.copyTable(\n {\n workbookName: fromWorkbookName,\n tableName: tableName,\n },\n {\n workbookName: toWorkbookName,\n tableName: tableName,\n }\n );\n }\n }\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n renameWorkbook(opts: { workbookName: string; newWorkbookName: string }) {\n this.workbookManager.renameWorkbook(opts);\n\n // Update scoped named expressions\n this.namedExpressionManager.renameWorkbook(opts);\n\n // Update tables that belong to the renamed sheet\n this.tableManager.updateTablesForWorkbookRename(opts);\n\n // Update conditional styles that reference this workbook\n this.styleManager.updateWorkbookName(\n opts.workbookName,\n opts.newWorkbookName\n );\n\n // Update all formulas that reference this workbook\n this.workbookManager.updateAllFormulas((formula) =>\n renameWorkbookInFormula({\n formula,\n oldWorkbookName: opts.workbookName,\n newWorkbookName: opts.newWorkbookName,\n })\n );\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n getWorkbooks() {\n return this.workbookManager.getWorkbooks();\n }\n //#endregion\n\n //#region CRUD Operations\n /**\n * Overrides the content of a sheet.\n * @param sheetName - The name of the sheet to set the content of\n * @param content - A map of cell addresses to their serialized values\n * @remarks This method is used to set the content of a sheet. It will re-evaluate all sheets to ensure all dependencies are resolved correctly.\n */\n setSheetContent(\n opts: { sheetName: string; workbookName: string },\n content: Map<string, SerializedCellValue>\n ) {\n this.workbookManager.setSheetContent(opts, content);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n setCellContent(address: CellAddress, content: SerializedCellValue) {\n this.workbookManager.setCellContent(address, content);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region Evaluation\n\n /**\n * Re-evaluates all sheets to ensure all dependencies are resolved correctly\n *\n * but just clears the evaluation cache\n */\n reevaluate() {\n this.evaluationManager.clearEvaluationCache();\n }\n //#endregion\n\n //#region Auto-fill\n /**\n * Auto-fills the fillRange based on the seedRange and the direction.\n */\n autoFill(\n opts: { sheetName: string; workbookName: string },\n /**\n * The user's original selection that defines the pattern/series.\n */\n seedRange: SpreadsheetRange,\n /**\n * the new cells populated by the drag, excluding the seed\n */\n fillRange: SpreadsheetRange,\n /**\n * The direction of the fill.\n */\n direction: FillDirection\n ) {\n this.autoFillManager.fill(opts, seedRange, fillRange, direction);\n }\n\n /**\n * Removes the content in the spreadsheet that is inside the range.\n */\n clearSpreadsheetRange(address: RangeAddress) {\n this.workbookManager.clearSpreadsheetRange(address);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region State - UI library integration\n getState() {\n return {\n workbooks: this.workbookManager.getWorkbooks(),\n namedExpressions: this.namedExpressionManager.getNamedExpressions(),\n tables: this.tableManager.tables,\n conditionalStyles: this.styleManager.getAllConditionalStyles(),\n cellStyles: this.styleManager.getAllCellStyles(),\n };\n }\n\n onUpdate(listener: () => void) {\n return this.eventManager.onUpdate(listener);\n }\n\n serializeEngine(): string {\n return serialize(this.getState());\n }\n\n resetToSerializedEngine(data: string) {\n const deserialized = deserialize(data) as ReturnType<typeof this.getState>;\n\n this.workbookManager.resetWorkbooks(deserialized.workbooks);\n\n deserialized.workbooks.forEach((workbook) => {\n this.namedExpressionManager.addWorkbook(workbook.name);\n this.tableManager.addWorkbook(workbook.name);\n workbook.sheets.forEach((sheet) => {\n this.namedExpressionManager.addSheet({\n workbookName: workbook.name,\n sheetName: sheet.name,\n });\n });\n });\n\n this.namedExpressionManager.resetNamedExpressions(\n deserialized.namedExpressions\n );\n this.tableManager.resetTables(deserialized.tables);\n \n // Reset styles if present\n // Handle backward compatibility: if conditionalStyles is a Map, convert it\n let conditionalStylesArray: ConditionalStyle[] | undefined;\n let cellStylesArray: DirectCellStyle[] | undefined;\n \n if (deserialized.conditionalStyles) {\n if (deserialized.conditionalStyles instanceof Map) {\n // Old format: Map<string, ConditionalStyle[]>\n conditionalStylesArray = Array.from(deserialized.conditionalStyles.values()).flat();\n } else if (Array.isArray(deserialized.conditionalStyles)) {\n // New format: ConditionalStyle[]\n conditionalStylesArray = deserialized.conditionalStyles;\n }\n }\n \n if (deserialized.cellStyles) {\n if (Array.isArray(deserialized.cellStyles)) {\n cellStylesArray = deserialized.cellStyles;\n }\n }\n \n this.styleManager.resetStyles(conditionalStylesArray, cellStylesArray);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n}\n"
|
|
5
|
+
"/**\n * Main FormulaEngine class\n * Core API implementation for spreadsheet calculations\n */\n\nimport {\n type CellAddress,\n type CellStyle,\n type ConditionalStyle,\n type CopyCellsOptions,\n type DirectCellStyle,\n type NamedExpression,\n type RangeAddress,\n type SerializedCellValue,\n type SingleEvaluationResult,\n type SpreadsheetRange,\n type SpreadsheetRangeEnd,\n type TableDefinition,\n} from \"./types.mjs\";\n\nimport type { FillDirection } from \"@ricsam/selection-manager\";\nimport { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport { AutoFill } from \"./autofill-utils.mjs\";\nimport { WorkbookManager } from \"./managers/workbook-manager.mjs\";\nimport { deserialize, serialize } from \"./map-serializer.mjs\";\nimport { renameNamedExpressionInFormula } from \"./named-expression-renamer.mjs\";\nimport { renameSheetInFormula } from \"./sheet-renamer.mjs\";\nimport { renameTableInFormula } from \"./table-renamer.mjs\";\nimport { renameWorkbookInFormula } from \"./workbook-renamer.mjs\";\nimport { cellAddressToKey, keyToCellAddress } from \"./utils.mjs\";\nimport { CacheManager } from \"./managers/cache-manager.mjs\";\nimport { NamedExpressionManager } from \"./managers/named-expression-manager.mjs\";\nimport { TableManager } from \"./managers/table-manager.mjs\";\nimport { EventManager } from \"./managers/event-manager.mjs\";\nimport { EvaluationManager } from \"./managers/evaluation-manager.mjs\";\nimport { DependencyManager } from \"./managers/dependency-manager.mjs\";\nimport { StyleManager } from \"./managers/style-manager.mjs\";\nimport { CopyManager } from \"./managers/copy-manager.mjs\";\n\n/**\n * Main FormulaEngine class\n */\nexport class FormulaEngine {\n private workbookManager: WorkbookManager;\n private namedExpressionManager: NamedExpressionManager;\n private tableManager: TableManager;\n private eventManager: EventManager;\n private evaluationManager: EvaluationManager;\n private autoFillManager: AutoFill;\n private dependencyManager: DependencyManager;\n private styleManager: StyleManager;\n private copyManager: CopyManager;\n\n /**\n * Public access to the store manager for testing\n */\n public _workbookManager: WorkbookManager;\n public _namedExpressionManager: NamedExpressionManager;\n public _tableManager: TableManager;\n public _eventManager: EventManager;\n public _evaluationManager: EvaluationManager;\n public _autoFillManager: AutoFill;\n public _dependencyManager: DependencyManager;\n public _styleManager: StyleManager;\n\n constructor() {\n this.eventManager = new EventManager();\n this.workbookManager = new WorkbookManager();\n this.namedExpressionManager = new NamedExpressionManager();\n this.tableManager = new TableManager(this.workbookManager);\n const cacheManager = new CacheManager();\n this.dependencyManager = new DependencyManager(\n cacheManager,\n this.workbookManager\n );\n\n const formulaEvaluator = new FormulaEvaluator(\n this.tableManager,\n this.dependencyManager,\n this.namedExpressionManager,\n );\n\n this.evaluationManager = new EvaluationManager(\n this.workbookManager,\n this.tableManager,\n formulaEvaluator,\n this.dependencyManager\n );\n\n this.styleManager = new StyleManager(\n this.workbookManager,\n this.evaluationManager\n );\n this.copyManager = new CopyManager(\n this.workbookManager,\n this.evaluationManager,\n this.styleManager\n );\n\n this.autoFillManager = new AutoFill(this.workbookManager, this);\n\n this._workbookManager = this.workbookManager;\n this._namedExpressionManager = this.namedExpressionManager;\n this._tableManager = this.tableManager;\n this._eventManager = this.eventManager;\n this._evaluationManager = this.evaluationManager;\n this._autoFillManager = this.autoFillManager;\n this._dependencyManager = this.dependencyManager;\n this._styleManager = this.styleManager;\n }\n\n /**\n * Static factory method to build an empty engine\n */\n static buildEmpty(): FormulaEngine {\n return new FormulaEngine();\n }\n\n //#region Cell\n getCellEvaluationResult(\n cellAddress: CellAddress\n ): SingleEvaluationResult | undefined {\n return this.evaluationManager.getCellEvaluationResult(cellAddress);\n }\n\n getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue {\n const result = this.getCellEvaluationResult(cellAddress);\n if (!result) {\n return \"\";\n }\n\n return this.evaluationManager.evaluationResultToSerializedValue(\n result,\n cellAddress,\n debug\n );\n }\n\n evaluateFormula(\n /**\n * formula without the leading = sign\n */\n formula: string, cellAddress: CellAddress): SerializedCellValue {\n return this.evaluationManager.evaluateFormula(formula, cellAddress);\n }\n\n getCellDependents(\n address: CellAddress | SpreadsheetRange\n ): (SpreadsheetRange | CellAddress)[] {\n throw new Error(\"Not implemented\");\n }\n\n getCellPrecedents(\n address: CellAddress | SpreadsheetRange\n ): (SpreadsheetRange | CellAddress)[] {\n throw new Error(\"Not implemented\");\n }\n\n //#endregion\n\n //#region Named Expressions\n addNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n }: {\n expression: string;\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n }) {\n this.namedExpressionManager.addNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n });\n\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n removeNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n }: {\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n }) {\n const found = this.namedExpressionManager.removeNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n });\n\n if (found) {\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n return found;\n }\n\n updateNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n }: {\n expression: string;\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n }) {\n this.namedExpressionManager.updateNamedExpression({\n expression,\n expressionName,\n sheetName,\n workbookName,\n });\n\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n renameNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n newName,\n }: {\n expressionName: string;\n sheetName?: string;\n workbookName?: string;\n newName: string;\n }) {\n const result = this.namedExpressionManager.renameNamedExpression({\n expressionName,\n sheetName,\n workbookName,\n newName,\n });\n\n // Update all formulas that reference this named expression in sheet cells\n this.workbookManager.updateAllFormulas((formula) =>\n renameNamedExpressionInFormula(formula, expressionName, newName)\n );\n\n // Update named expressions that reference this named expression\n this.namedExpressionManager.updateAllNamedExpressions((formula) =>\n renameNamedExpressionInFormula(formula, expressionName, newName)\n );\n\n // Re-evaluate all sheets since named expressions can be referenced from anywhere\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return result;\n }\n\n setNamedExpressions(\n opts: (\n | {\n type: \"global\";\n }\n | {\n type: \"sheet\";\n sheetName: string;\n workbookName: string;\n }\n | {\n type: \"workbook\";\n workbookName: string;\n }\n ) & {\n expressions: Map<string, NamedExpression>;\n }\n ) {\n this.namedExpressionManager.setNamedExpressions(opts);\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region Tables\n addTable(props: {\n tableName: string;\n sheetName: string;\n workbookName: string;\n start: string;\n numRows: SpreadsheetRangeEnd;\n numCols: number;\n }) {\n const table = this.tableManager.addTable({\n ...props,\n getCellValue: (cellAddress: CellAddress) =>\n this.getCellValue(cellAddress),\n });\n\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return table;\n }\n\n renameTable(\n workbookName: string,\n names: { oldName: string; newName: string }\n ) {\n this.tableManager.renameTable(workbookName, names);\n\n // Update all formulas that reference this table in sheet cells\n this.workbookManager.updateAllFormulas((formula) =>\n renameTableInFormula(formula, names.oldName, names.newName)\n );\n\n // Update named expressions that reference this table\n this.namedExpressionManager.updateAllNamedExpressions((formula) =>\n renameTableInFormula(formula, names.oldName, names.newName)\n );\n\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n updateTable(opts: {\n tableName: string;\n sheetName?: string;\n start?: string;\n numRows?: SpreadsheetRangeEnd;\n numCols?: number;\n workbookName: string;\n }) {\n this.tableManager.updateTable({\n ...opts,\n getCellValue: (cellAddress: CellAddress) =>\n this.getCellValue(cellAddress),\n });\n\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n removeTable(opts: { tableName: string; workbookName: string }) {\n const found = this.tableManager.removeTable(opts);\n\n if (found) {\n // Re-evaluate all sheets since structured references might depend on this table\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n return found;\n }\n\n resetTables(tables: Map<string, Map<string, TableDefinition>>) {\n this.tableManager.resetTables(tables);\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n getTables(workbookName: string) {\n return this.tableManager.getTables(workbookName);\n }\n\n isCellInTable(cellAddress: CellAddress): TableDefinition | undefined {\n return this.tableManager.isCellInTable(cellAddress);\n }\n\n //#endregion\n\n //#region Conditional Styling\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.styleManager.addConditionalStyle(style);\n this.eventManager.emitUpdate();\n }\n\n /**\n * Remove a conditional style rule by index\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const removed = this.styleManager.removeConditionalStyle(workbookName, index);\n if (removed) {\n this.eventManager.emitUpdate();\n }\n return removed;\n }\n\n /**\n * Get all conditional styles for a workbook\n */\n getConditionalStyles(workbookName: string): ConditionalStyle[] {\n return this.styleManager.getConditionalStyles(workbookName);\n }\n\n /**\n * Get the computed style for a specific cell\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n return this.styleManager.getCellStyle(cellAddress);\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.styleManager.addCellStyle(style);\n this.eventManager.emitUpdate();\n }\n\n /**\n * Remove a direct cell style rule by index\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const removed = this.styleManager.removeCellStyle(workbookName, index);\n if (removed) {\n this.eventManager.emitUpdate();\n }\n return removed;\n }\n\n /**\n * Get all direct cell styles for a workbook\n */\n getCellStyles(workbookName: string): DirectCellStyle[] {\n return this.styleManager.getCellStyles(workbookName);\n }\n\n //#endregion\n\n //#region Copy/Paste\n /**\n * Copy cells from source to target\n */\n copyCells(\n source: CellAddress[],\n target: CellAddress,\n options: CopyCellsOptions\n ): void {\n this.copyManager.copyCells(source, target, options);\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region Sheets\n addSheet(opts: { workbookName: string; sheetName: string }) {\n const newSheet = this.workbookManager.addSheet(opts);\n const wbLevel = this.namedExpressionManager.addSheet(opts);\n this.reevaluate();\n this.eventManager.emitUpdate();\n return newSheet;\n }\n\n removeSheet(opts: { workbookName: string; sheetName: string }) {\n const sheet = this.workbookManager.removeSheet(opts);\n\n // Clean up related data\n this.namedExpressionManager.removeSheet(opts);\n this.tableManager.removeSheet(opts);\n this.styleManager.removeSheetStyles(opts.workbookName, opts.sheetName);\n\n // Add engine-specific logic: re-evaluate since references might be affected\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return sheet;\n }\n\n renameSheet(opts: {\n sheetName: string;\n newSheetName: string;\n workbookName: string;\n }) {\n const sheet = this.workbookManager.renameSheet(opts);\n\n // Update scoped named expressions\n this.namedExpressionManager.renameSheet(opts);\n\n // Update tables that belong to the renamed sheet\n this.tableManager.updateTablesForSheetRename(opts);\n\n // Update conditional styles that reference this sheet\n this.styleManager.updateSheetName(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n\n // Update all formulas that reference this sheet\n this.workbookManager.updateAllFormulas((formula) =>\n renameSheetInFormula({\n formula,\n oldSheetName: opts.sheetName,\n newSheetName: opts.newSheetName,\n })\n );\n\n // Add engine-specific logic: re-evaluate since references might be affected\n this.reevaluate();\n this.eventManager.emitUpdate();\n\n return sheet;\n }\n\n getSheets(workbookName: string) {\n return this.workbookManager.getSheets(workbookName);\n }\n\n getSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }) {\n return this.workbookManager.getSheet({ workbookName, sheetName });\n }\n\n getSheetSerialized(opts: {\n sheetName: string;\n workbookName: string;\n }): Map<string, SerializedCellValue> {\n return this.workbookManager.getSheetSerialized(opts);\n }\n\n //#endregion\n\n //#region Workbook\n addWorkbook(workbookName: string) {\n this.workbookManager.addWorkbook(workbookName);\n this.namedExpressionManager.addWorkbook(workbookName);\n this.tableManager.addWorkbook(workbookName);\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n removeWorkbook(workbookName: string) {\n this.workbookManager.removeWorkbook(workbookName);\n this.namedExpressionManager.removeWorkbook(workbookName);\n this.tableManager.removeWorkbook(workbookName);\n this.styleManager.removeWorkbookStyles(workbookName);\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n cloneWorkbook(fromWorkbookName: string, toWorkbookName: string) {\n // Check if source workbook exists\n const sourceWorkbook = this.workbookManager\n .getWorkbooks()\n .get(fromWorkbookName);\n if (!sourceWorkbook) {\n throw new Error(`Source workbook \"${fromWorkbookName}\" not found`);\n }\n\n // Check if target workbook name already exists\n if (this.workbookManager.getWorkbooks().has(toWorkbookName)) {\n throw new Error(`Target workbook \"${toWorkbookName}\" already exists`);\n }\n\n // Create new workbook\n this.addWorkbook(toWorkbookName);\n\n // Clone all sheets from source workbook\n for (const [sheetName, sheet] of sourceWorkbook.sheets) {\n // Add sheet to target workbook\n this.addSheet({\n workbookName: toWorkbookName,\n sheetName: sheetName,\n });\n\n // Copy all cell content using setSheetContent for efficiency\n this.setSheetContent(\n {\n workbookName: toWorkbookName,\n sheetName: sheetName,\n },\n new Map(sheet.content)\n );\n }\n\n // Clone workbook-scoped named expressions\n const sourceWorkbookExpressions = this.namedExpressionManager\n .getNamedExpressions()\n .workbookExpressions.get(fromWorkbookName);\n if (sourceWorkbookExpressions) {\n for (const [name, expression] of sourceWorkbookExpressions) {\n this.addNamedExpression({\n expressionName: name,\n expression: expression.expression,\n workbookName: toWorkbookName,\n });\n }\n }\n\n // Clone sheet-scoped named expressions\n const sourceSheetExpressions = this.namedExpressionManager\n .getNamedExpressions()\n .sheetExpressions.get(fromWorkbookName);\n if (sourceSheetExpressions) {\n for (const [sheetName, sheetExpressions] of sourceSheetExpressions) {\n for (const [name, expression] of sheetExpressions) {\n this.addNamedExpression({\n expressionName: name,\n expression: expression.expression,\n workbookName: toWorkbookName,\n sheetName: sheetName,\n });\n }\n }\n }\n\n // Clone tables\n const sourceTables = this.tableManager.tables.get(fromWorkbookName);\n if (sourceTables) {\n for (const [tableName, table] of sourceTables) {\n this.tableManager.copyTable(\n {\n workbookName: fromWorkbookName,\n tableName: tableName,\n },\n {\n workbookName: toWorkbookName,\n tableName: tableName,\n }\n );\n }\n }\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n renameWorkbook(opts: { workbookName: string; newWorkbookName: string }) {\n this.workbookManager.renameWorkbook(opts);\n\n // Update scoped named expressions\n this.namedExpressionManager.renameWorkbook(opts);\n\n // Update tables that belong to the renamed sheet\n this.tableManager.updateTablesForWorkbookRename(opts);\n\n // Update conditional styles that reference this workbook\n this.styleManager.updateWorkbookName(\n opts.workbookName,\n opts.newWorkbookName\n );\n\n // Update all formulas that reference this workbook\n this.workbookManager.updateAllFormulas((formula) =>\n renameWorkbookInFormula({\n formula,\n oldWorkbookName: opts.workbookName,\n newWorkbookName: opts.newWorkbookName,\n })\n );\n\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n getWorkbooks() {\n return this.workbookManager.getWorkbooks();\n }\n //#endregion\n\n //#region CRUD Operations\n /**\n * Overrides the content of a sheet.\n * @param sheetName - The name of the sheet to set the content of\n * @param content - A map of cell addresses to their serialized values\n * @remarks This method is used to set the content of a sheet. It will re-evaluate all sheets to ensure all dependencies are resolved correctly.\n */\n setSheetContent(\n opts: { sheetName: string; workbookName: string },\n content: Map<string, SerializedCellValue>\n ) {\n this.workbookManager.setSheetContent(opts, content);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n\n setCellContent(address: CellAddress, content: SerializedCellValue) {\n this.workbookManager.setCellContent(address, content);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region Evaluation\n\n /**\n * Re-evaluates all sheets to ensure all dependencies are resolved correctly\n *\n * but just clears the evaluation cache\n */\n reevaluate() {\n this.evaluationManager.clearEvaluationCache();\n }\n //#endregion\n\n //#region Auto-fill\n /**\n * Auto-fills the fillRange based on the seedRange and the direction.\n */\n autoFill(\n opts: { sheetName: string; workbookName: string },\n /**\n * The user's original selection that defines the pattern/series.\n */\n seedRange: SpreadsheetRange,\n /**\n * the new cells populated by the drag, excluding the seed\n */\n fillRange: SpreadsheetRange,\n /**\n * The direction of the fill.\n */\n direction: FillDirection\n ) {\n this.autoFillManager.fill(opts, seedRange, fillRange, direction);\n }\n\n /**\n * Removes the content in the spreadsheet that is inside the range.\n */\n clearSpreadsheetRange(address: RangeAddress) {\n this.workbookManager.clearSpreadsheetRange(address);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n\n //#region State - UI library integration\n getState() {\n return {\n workbooks: this.workbookManager.getWorkbooks(),\n namedExpressions: this.namedExpressionManager.getNamedExpressions(),\n tables: this.tableManager.tables,\n conditionalStyles: this.styleManager.getAllConditionalStyles(),\n cellStyles: this.styleManager.getAllCellStyles(),\n };\n }\n\n onUpdate(listener: () => void) {\n return this.eventManager.onUpdate(listener);\n }\n\n serializeEngine(): string {\n return serialize(this.getState());\n }\n\n resetToSerializedEngine(data: string) {\n const deserialized = deserialize(data) as ReturnType<typeof this.getState>;\n\n this.workbookManager.resetWorkbooks(deserialized.workbooks);\n\n deserialized.workbooks.forEach((workbook) => {\n this.namedExpressionManager.addWorkbook(workbook.name);\n this.tableManager.addWorkbook(workbook.name);\n workbook.sheets.forEach((sheet) => {\n this.namedExpressionManager.addSheet({\n workbookName: workbook.name,\n sheetName: sheet.name,\n });\n });\n });\n\n this.namedExpressionManager.resetNamedExpressions(\n deserialized.namedExpressions\n );\n this.tableManager.resetTables(deserialized.tables);\n \n // Reset styles if present\n // Handle backward compatibility: if conditionalStyles is a Map, convert it\n let conditionalStylesArray: ConditionalStyle[] | undefined;\n let cellStylesArray: DirectCellStyle[] | undefined;\n \n if (deserialized.conditionalStyles) {\n if (deserialized.conditionalStyles instanceof Map) {\n // Old format: Map<string, ConditionalStyle[]>\n conditionalStylesArray = Array.from(deserialized.conditionalStyles.values()).flat();\n } else if (Array.isArray(deserialized.conditionalStyles)) {\n // New format: ConditionalStyle[]\n conditionalStylesArray = deserialized.conditionalStyles;\n }\n }\n \n if (deserialized.cellStyles) {\n if (Array.isArray(deserialized.cellStyles)) {\n cellStylesArray = deserialized.cellStyles;\n }\n }\n \n this.styleManager.resetStyles(conditionalStylesArray, cellStylesArray);\n\n // Re-evaluate all sheets to ensure all dependencies are resolved correctly\n this.reevaluate();\n this.eventManager.emitUpdate();\n }\n //#endregion\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAKO,MAAM,cAAc;AAAA,EACjB;AAAA,EACA;AAAA,EAC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