@visactor/vtable-sheet 1.22.7 → 1.22.8-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/cjs/components/sheet-tab-event-handler.js +3 -2
  2. package/cjs/components/sheet-tab-event-handler.js.map +1 -1
  3. package/cjs/components/vtable-sheet.d.ts +2 -1
  4. package/cjs/components/vtable-sheet.js +9 -1
  5. package/cjs/components/vtable-sheet.js.map +1 -1
  6. package/cjs/core/WorkSheet.d.ts +1 -1
  7. package/cjs/core/WorkSheet.js.map +1 -1
  8. package/cjs/core/table-plugins.js +7 -5
  9. package/cjs/core/table-plugins.js.map +1 -1
  10. package/cjs/formula/cell-highlight-manager.d.ts +1 -0
  11. package/cjs/formula/cell-highlight-manager.js +27 -22
  12. package/cjs/formula/cell-highlight-manager.js.map +1 -1
  13. package/cjs/formula/cross-sheet-data-synchronizer.d.ts +48 -0
  14. package/cjs/formula/cross-sheet-data-synchronizer.js +159 -0
  15. package/cjs/formula/cross-sheet-data-synchronizer.js.map +1 -0
  16. package/cjs/formula/cross-sheet-formula-handler.d.ts +58 -0
  17. package/cjs/formula/cross-sheet-formula-handler.js +240 -0
  18. package/cjs/formula/cross-sheet-formula-handler.js.map +1 -0
  19. package/cjs/formula/cross-sheet-formula-manager.d.ts +52 -0
  20. package/cjs/formula/cross-sheet-formula-manager.js +235 -0
  21. package/cjs/formula/cross-sheet-formula-manager.js.map +1 -0
  22. package/cjs/formula/cross-sheet-formula-validator.d.ts +56 -0
  23. package/cjs/formula/cross-sheet-formula-validator.js +271 -0
  24. package/cjs/formula/cross-sheet-formula-validator.js.map +1 -0
  25. package/cjs/formula/formula-engine.d.ts +4 -1
  26. package/cjs/formula/formula-engine.js +132 -25
  27. package/cjs/formula/formula-engine.js.map +1 -1
  28. package/cjs/formula/formula-paste-processor.d.ts +3 -3
  29. package/cjs/formula/formula-paste-processor.js.map +1 -1
  30. package/cjs/formula/formula-reference-adjustor.d.ts +1 -1
  31. package/cjs/formula/formula-reference-adjustor.js.map +1 -1
  32. package/cjs/formula/index.d.ts +8 -0
  33. package/cjs/formula/index.js +40 -3
  34. package/cjs/formula/index.js.map +1 -1
  35. package/cjs/index.d.ts +1 -1
  36. package/cjs/index.js +1 -1
  37. package/cjs/index.js.map +1 -1
  38. package/cjs/managers/formula-manager.d.ts +17 -2
  39. package/cjs/managers/formula-manager.js +150 -12
  40. package/cjs/managers/formula-manager.js.map +1 -1
  41. package/cjs/styles/menu.js +2 -1
  42. package/cjs/styles/sheet-tab.js +1 -2
  43. package/cjs/tools/index.js +2 -1
  44. package/dist/vtable-sheet.js +11322 -331
  45. package/dist/vtable-sheet.min.js +1 -1
  46. package/es/components/sheet-tab-event-handler.js +3 -2
  47. package/es/components/sheet-tab-event-handler.js.map +1 -1
  48. package/es/components/vtable-sheet.d.ts +2 -1
  49. package/es/components/vtable-sheet.js +9 -1
  50. package/es/components/vtable-sheet.js.map +1 -1
  51. package/es/core/WorkSheet.d.ts +1 -1
  52. package/es/core/WorkSheet.js.map +1 -1
  53. package/es/core/table-plugins.js +7 -5
  54. package/es/core/table-plugins.js.map +1 -1
  55. package/es/formula/cell-highlight-manager.d.ts +1 -0
  56. package/es/formula/cell-highlight-manager.js +27 -22
  57. package/es/formula/cell-highlight-manager.js.map +1 -1
  58. package/es/formula/cross-sheet-data-synchronizer.d.ts +48 -0
  59. package/es/formula/cross-sheet-data-synchronizer.js +151 -0
  60. package/es/formula/cross-sheet-data-synchronizer.js.map +1 -0
  61. package/es/formula/cross-sheet-formula-handler.d.ts +58 -0
  62. package/es/formula/cross-sheet-formula-handler.js +236 -0
  63. package/es/formula/cross-sheet-formula-handler.js.map +1 -0
  64. package/es/formula/cross-sheet-formula-manager.d.ts +52 -0
  65. package/es/formula/cross-sheet-formula-manager.js +227 -0
  66. package/es/formula/cross-sheet-formula-manager.js.map +1 -0
  67. package/es/formula/cross-sheet-formula-validator.d.ts +56 -0
  68. package/es/formula/cross-sheet-formula-validator.js +263 -0
  69. package/es/formula/cross-sheet-formula-validator.js.map +1 -0
  70. package/es/formula/formula-engine.d.ts +4 -1
  71. package/es/formula/formula-engine.js +132 -25
  72. package/es/formula/formula-engine.js.map +1 -1
  73. package/es/formula/formula-paste-processor.d.ts +3 -3
  74. package/es/formula/formula-paste-processor.js.map +1 -1
  75. package/es/formula/formula-reference-adjustor.d.ts +1 -1
  76. package/es/formula/formula-reference-adjustor.js.map +1 -1
  77. package/es/formula/index.d.ts +8 -0
  78. package/es/formula/index.js +8 -0
  79. package/es/formula/index.js.map +1 -1
  80. package/es/index.d.ts +1 -1
  81. package/es/index.js +1 -1
  82. package/es/index.js.map +1 -1
  83. package/es/managers/formula-manager.d.ts +17 -2
  84. package/es/managers/formula-manager.js +152 -11
  85. package/es/managers/formula-manager.js.map +1 -1
  86. package/es/styles/menu.js +2 -1
  87. package/es/styles/sheet-tab.js +1 -2
  88. package/es/tools/index.js +2 -1
  89. package/package.json +5 -5
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/formula/cross-sheet-formula-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,+EAAyE;AACzE,mFAA6E;AAC7E,mFAAoG;AAgBpG,MAAa,wBAAwB;IAmBnC,YACE,aAA4B,EAC5B,YAAsF,EACtF,cAAoB;QAfd,YAAO,GAA6B;YAC1C,aAAa,EAAE,IAAI;YACnB,gBAAgB,EAAE,IAAI;YACtB,WAAW,EAAE,EAAE;YACf,iBAAiB,EAAE,GAAG;SACvB,CAAC;QAGM,kBAAa,GAAG,KAAK,CAAC;QACtB,qBAAgB,GAAkB,EAAE,CAAC;QACrC,uBAAkB,GAA0C,IAAI,GAAG,EAAE,CAAC;QAO5E,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,iBAAiB,GAAG,IAAI,sDAAwB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;QAC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;SAC7B,CAAC;IACJ,CAAC;IAKD,UAAU;QACR,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;IAC9B,CAAC;IAKD,qBAAqB,CAAC,KAAa,EAAE,QAA8B;QACjE,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAKD,wBAAwB,CAAC,KAAa,EAAE,QAA8B;QACpE,IAAI,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;IAKK,SAAS;;YACb,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC;QAC1C,CAAC;KAAA;IAKD,OAAO;QACL,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAzXD,4DAyXC","file":"cross-sheet-formula-handler.js","sourcesContent":["/**\n * 跨sheet公式处理器\n * 处理跨sheet公式的计算、更新和同步\n */\n\nimport type { FormulaCell } from '../ts-types/formula';\nimport type { FormulaEngine } from './formula-engine';\nimport { CrossSheetFormulaManager } from './cross-sheet-formula-manager';\nimport { CrossSheetDataSynchronizer } from './cross-sheet-data-synchronizer';\nimport { CrossSheetFormulaValidator, type ValidationResult } from './cross-sheet-formula-validator';\n\nexport interface CrossSheetFormulaOptions {\n enableCaching: boolean;\n enableValidation: boolean;\n syncTimeout: number;\n maxRecursionDepth: number;\n}\n\nexport interface FormulaCalculationResult {\n value: any;\n error?: string;\n dependencies: FormulaCell[];\n calculationTime: number;\n}\n\nexport class CrossSheetFormulaHandler {\n private formulaEngine: FormulaEngine;\n private crossSheetManager: CrossSheetFormulaManager;\n private dataSynchronizer: CrossSheetDataSynchronizer;\n private validator: CrossSheetFormulaValidator;\n private formulaManager?: any; // FormulaManager reference for proper sheet registration\n\n private options: CrossSheetFormulaOptions = {\n enableCaching: true,\n enableValidation: true,\n syncTimeout: 50,\n maxRecursionDepth: 100\n };\n\n // 计算状态\n private isCalculating = false;\n private calculationQueue: FormulaCell[] = [];\n private calculationResults: Map<string, FormulaCalculationResult> = new Map();\n\n constructor(\n formulaEngine: FormulaEngine,\n sheetManager?: { getAllSheets: () => Array<{ sheetKey: string; sheetTitle: string }> },\n formulaManager?: any\n ) {\n this.formulaEngine = formulaEngine;\n this.formulaManager = formulaManager;\n this.crossSheetManager = new CrossSheetFormulaManager(formulaEngine, sheetManager);\n this.dataSynchronizer = new CrossSheetDataSynchronizer(formulaEngine, this.crossSheetManager);\n this.validator = new CrossSheetFormulaValidator(formulaEngine, this.crossSheetManager, sheetManager);\n }\n\n /**\n * 设置跨sheet公式\n */\n async setCrossSheetFormula(cell: FormulaCell, formula: string): Promise<FormulaCalculationResult> {\n const startTime = performance.now();\n\n try {\n // 验证公式(如果启用)\n if (this.options.enableValidation) {\n const validation = this.validator.validateFormulaSyntax(formula);\n if (!validation.valid) {\n return {\n value: null,\n error: validation.error,\n dependencies: [],\n calculationTime: performance.now() - startTime\n };\n }\n }\n\n // 注册跨sheet引用\n this.crossSheetManager.registerCrossSheetReference(formula, cell);\n\n // 设置公式到引擎\n this.formulaEngine.setCellContent(cell, formula);\n\n // 计算结果\n let result: { value: any; error?: string };\n if (this.formulaManager) {\n // 使用FormulaManager获取单元格值(支持未激活的sheet)\n result = this.formulaManager.getCellValue(cell);\n } else {\n // 回退到直接使用FormulaEngine\n result = this.formulaEngine.getCellValue(cell);\n }\n\n // 获取依赖关系\n const dependencies = this.formulaEngine.getCellPrecedents(cell);\n\n const calculationResult: FormulaCalculationResult = {\n value: result.value,\n error: result.error,\n dependencies,\n calculationTime: performance.now() - startTime\n };\n\n // 缓存结果\n if (this.options.enableCaching) {\n this.cacheCalculationResult(cell, calculationResult);\n }\n\n return calculationResult;\n } catch (error) {\n return {\n value: null,\n error: error instanceof Error ? error.message : 'Unknown error',\n dependencies: [],\n calculationTime: performance.now() - startTime\n };\n }\n }\n\n /**\n * 获取跨sheet公式的值\n */\n async getCrossSheetValue(cell: FormulaCell): Promise<FormulaCalculationResult> {\n const startTime = performance.now();\n\n try {\n // 检查缓存\n if (this.options.enableCaching) {\n const cached = this.getCachedResult(cell);\n if (cached) {\n return {\n ...cached,\n calculationTime: performance.now() - startTime\n };\n }\n }\n\n // 获取公式\n const formula = this.formulaEngine.getCellFormula(cell);\n if (!formula) {\n return {\n value: null,\n error: 'No formula found',\n dependencies: [],\n calculationTime: performance.now() - startTime\n };\n }\n\n // 计算结果\n let result: { value: any; error?: string };\n if (this.formulaManager) {\n // 使用FormulaManager获取单元格值(支持未激活的sheet)\n result = this.formulaManager.getCellValue(cell);\n } else {\n // 回退到直接使用FormulaEngine\n result = this.formulaEngine.getCellValue(cell);\n }\n const dependencies = this.formulaEngine.getCellPrecedents(cell);\n\n const calculationResult: FormulaCalculationResult = {\n value: result.value,\n error: result.error,\n dependencies,\n calculationTime: performance.now() - startTime\n };\n\n // 缓存结果\n if (this.options.enableCaching) {\n this.cacheCalculationResult(cell, calculationResult);\n }\n\n return calculationResult;\n } catch (error) {\n return {\n value: null,\n error: error instanceof Error ? error.message : 'Unknown error',\n dependencies: [],\n calculationTime: performance.now() - startTime\n };\n }\n }\n\n /**\n * 更新跨sheet引用\n */\n async updateCrossSheetReferences(targetSheet: string, changedCells: FormulaCell[]): Promise<void> {\n await this.crossSheetManager.updateCrossSheetReferences(targetSheet, changedCells);\n }\n\n /**\n * 验证跨sheet公式\n */\n validateCrossSheetFormula(cell: FormulaCell): ValidationResult {\n const formula = this.formulaEngine.getCellFormula(cell);\n if (!formula) {\n return {\n valid: false,\n errors: [\n {\n type: 'MISSING_REFERENCE',\n message: 'No formula found',\n sheet: cell.sheet,\n cell\n }\n ],\n warnings: []\n };\n }\n\n const syntaxValidation = this.validator.validateFormulaSyntax(formula);\n return {\n valid: syntaxValidation.valid,\n errors: syntaxValidation.error\n ? [\n {\n type: 'MISSING_REFERENCE',\n message: syntaxValidation.error,\n sheet: cell.sheet,\n cell\n }\n ]\n : [],\n warnings: []\n };\n }\n\n /**\n * 验证所有跨sheet公式\n */\n validateAllCrossSheetFormulas(): Map<string, ValidationResult> {\n return this.validator.validateAllSheets();\n }\n\n /**\n * 获取跨sheet依赖关系\n */\n getCrossSheetDependencies(): Map<string, string[]> {\n return this.dataSynchronizer.getCrossSheetDependencies();\n }\n\n /**\n * 强制重新计算所有跨sheet公式\n */\n async recalculateAllCrossSheetFormulas(): Promise<void> {\n const allSheets = this.formulaEngine.getAllSheets();\n\n for (const sheetInfo of allSheets) {\n const formulas = this.formulaEngine.exportFormulas(sheetInfo.key);\n\n for (const [cellRef, formula] of Object.entries(formulas)) {\n if (this.hasCrossSheetReference(formula)) {\n const cell = this.parseA1Notation(cellRef);\n const cellWithSheet: FormulaCell = { sheet: sheetInfo.key, row: cell.row, col: cell.col };\n\n await this.recalculateFormula(cellWithSheet);\n }\n }\n }\n }\n\n /**\n * 重新计算公式\n */\n async recalculateFormula(cell: FormulaCell): Promise<FormulaCalculationResult> {\n return await this.getCrossSheetValue(cell);\n }\n\n /**\n * 检查公式是否包含跨sheet引用\n */\n private hasCrossSheetReference(formula: string): boolean {\n return formula.includes('!');\n }\n\n /**\n * 缓存计算结果\n */\n private cacheCalculationResult(cell: FormulaCell, result: FormulaCalculationResult): void {\n const cacheKey = this.getCacheKey(cell);\n this.calculationResults.set(cacheKey, result);\n }\n\n /**\n * 获取缓存的计算结果\n */\n private getCachedResult(cell: FormulaCell): FormulaCalculationResult | null {\n const cacheKey = this.getCacheKey(cell);\n return this.calculationResults.get(cacheKey) || null;\n }\n\n /**\n * 获取缓存键\n */\n private getCacheKey(cell: FormulaCell): string {\n return `${cell.sheet}!${this.getA1Notation(cell.row, cell.col)}`;\n }\n\n /**\n * A1表示法解析\n */\n private parseA1Notation(a1Notation: string): { row: number; col: number } {\n const match = a1Notation.match(/^([A-Z]+)([0-9]+)$/);\n if (!match) {\n throw new Error(`Invalid cell reference: ${a1Notation}`);\n }\n\n const colLetters = match[1];\n const rowNumber = parseInt(match[2], 10);\n\n let col = 0;\n for (let i = 0; i < colLetters.length; i++) {\n col = col * 26 + (colLetters.charCodeAt(i) - 65);\n }\n\n return { row: rowNumber - 1, col };\n }\n\n /**\n * A1表示法生成\n */\n private getA1Notation(row: number, col: number): string {\n let colStr = '';\n let tempCol = col;\n\n do {\n colStr = String.fromCharCode(65 + (tempCol % 26)) + colStr;\n tempCol = Math.floor(tempCol / 26) - 1;\n } while (tempCol >= 0);\n\n return `${colStr}${row + 1}`;\n }\n\n /**\n * 更新处理选项\n */\n updateOptions(options: Partial<CrossSheetFormulaOptions>): void {\n this.options = { ...this.options, ...options };\n\n // 更新依赖组件的选项\n this.dataSynchronizer.updateSyncOptions({\n immediate: this.options.enableCaching,\n timeout: this.options.syncTimeout\n });\n }\n\n /**\n * 获取处理状态\n */\n getHandlerStatus(): {\n isCalculating: boolean;\n pendingCalculations: number;\n cacheSize: number;\n options: CrossSheetFormulaOptions;\n } {\n return {\n isCalculating: this.isCalculating,\n pendingCalculations: this.calculationQueue.length,\n cacheSize: this.calculationResults.size,\n options: { ...this.options }\n };\n }\n\n /**\n * 清除缓存\n */\n clearCache(): void {\n this.calculationResults.clear();\n this.crossSheetManager.clearCache();\n this.validator.clearCache();\n }\n\n /**\n * 添加数据变更监听器\n */\n addDataChangeListener(sheet: string, listener: (event: any) => void): void {\n this.dataSynchronizer.addDataChangeListener(sheet, listener);\n }\n\n /**\n * 移除数据变更监听器\n */\n removeDataChangeListener(sheet: string, listener: (event: any) => void): void {\n this.dataSynchronizer.removeDataChangeListener(sheet, listener);\n }\n\n /**\n * 强制同步\n */\n async forceSync(): Promise<void> {\n await this.dataSynchronizer.forceSync();\n }\n\n /**\n * 销毁处理器\n */\n destroy(): void {\n this.clearCache();\n this.calculationResults.clear();\n this.calculationQueue = [];\n this.crossSheetManager.destroy();\n this.dataSynchronizer.destroy();\n this.validator.destroy();\n }\n}\n"]}
@@ -0,0 +1,52 @@
1
+ import type { FormulaCell } from '../ts-types/formula';
2
+ import type { FormulaEngine } from './formula-engine';
3
+ export interface CrossSheetReference {
4
+ sourceSheet: string;
5
+ targetSheet: string;
6
+ sourceCell: FormulaCell;
7
+ targetCells: FormulaCell[];
8
+ formula: string;
9
+ }
10
+ export interface CrossSheetDependency {
11
+ dependentSheet: string;
12
+ precedentSheet: string;
13
+ dependentCells: FormulaCell[];
14
+ precedentCells: FormulaCell[];
15
+ }
16
+ export declare class CrossSheetFormulaManager {
17
+ private formulaEngine;
18
+ private sheetManager;
19
+ private crossSheetDependencies;
20
+ private reverseCrossSheetDependencies;
21
+ private calculationCache;
22
+ private readonly CACHE_TTL;
23
+ constructor(formulaEngine: FormulaEngine, sheetManager?: {
24
+ getAllSheets: () => Array<{
25
+ sheetKey: string;
26
+ sheetTitle: string;
27
+ }>;
28
+ });
29
+ registerCrossSheetReference(formula: string, sourceCell: FormulaCell): CrossSheetReference[];
30
+ private isValidSheet;
31
+ private extractTargetSheets;
32
+ private extractTargetCells;
33
+ private updateCrossSheetDependency;
34
+ getCrossSheetDependencies(sheet: string): CrossSheetDependency[];
35
+ private getDependentCells;
36
+ private getPrecedentCells;
37
+ updateCrossSheetReferences(targetSheet: string, changedCells: FormulaCell[]): Promise<void>;
38
+ private formulaReferencesCells;
39
+ private recalculateFormula;
40
+ private recalculateDependents;
41
+ validateCrossSheetReferences(sheet: string): {
42
+ valid: boolean;
43
+ errors: string[];
44
+ };
45
+ getCachedValue(cell: FormulaCell): any;
46
+ clearCache(): void;
47
+ clearSheetDependencies(sheet: string): void;
48
+ private parseA1Notation;
49
+ private getA1Notation;
50
+ private getCacheKey;
51
+ destroy(): void;
52
+ }
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+
3
+ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
4
+ return new (P || (P = Promise))((function(resolve, reject) {
5
+ function fulfilled(value) {
6
+ try {
7
+ step(generator.next(value));
8
+ } catch (e) {
9
+ reject(e);
10
+ }
11
+ }
12
+ function rejected(value) {
13
+ try {
14
+ step(generator.throw(value));
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ }
19
+ function step(result) {
20
+ var value;
21
+ result.done ? resolve(result.value) : (value = result.value, value instanceof P ? value : new P((function(resolve) {
22
+ resolve(value);
23
+ }))).then(fulfilled, rejected);
24
+ }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ }));
27
+ };
28
+
29
+ Object.defineProperty(exports, "__esModule", {
30
+ value: !0
31
+ }), exports.CrossSheetFormulaManager = void 0;
32
+
33
+ class CrossSheetFormulaManager {
34
+ constructor(formulaEngine, sheetManager) {
35
+ this.crossSheetDependencies = new Map, this.reverseCrossSheetDependencies = new Map,
36
+ this.calculationCache = new Map, this.CACHE_TTL = 1e3, this.formulaEngine = formulaEngine,
37
+ this.sheetManager = sheetManager;
38
+ }
39
+ registerCrossSheetReference(formula, sourceCell) {
40
+ const references = [], targetSheets = this.extractTargetSheets(formula);
41
+ for (const targetSheet of targetSheets) {
42
+ const targetCells = this.extractTargetCells(formula, targetSheet);
43
+ targetCells.length > 0 && (references.push({
44
+ sourceSheet: sourceCell.sheet,
45
+ targetSheet: targetSheet,
46
+ sourceCell: sourceCell,
47
+ targetCells: targetCells,
48
+ formula: formula
49
+ }), this.updateCrossSheetDependency(sourceCell.sheet, targetSheet, sourceCell, targetCells));
50
+ }
51
+ return references;
52
+ }
53
+ isValidSheet(sheetName) {
54
+ if (this.sheetManager) {
55
+ return this.sheetManager.getAllSheets().some((sheet => sheet.sheetTitle.toLowerCase() === sheetName.toLowerCase()));
56
+ }
57
+ return this.formulaEngine.getAllSheets().some((sheet => sheet.title.toLowerCase() === sheetName.toLowerCase()));
58
+ }
59
+ extractTargetSheets(formula) {
60
+ const sheets = new Set, quotedSheetPattern = /'([^']+)'[!!]/g, unquotedSheetPattern = /([A-Za-z0-9_\s一-龥]+)[!!]/g;
61
+ let match;
62
+ for (;null !== (match = quotedSheetPattern.exec(formula)); ) {
63
+ const sheetName = match[1];
64
+ sheetName && this.isValidSheet(sheetName) && sheets.add(sheetName);
65
+ }
66
+ for (;null !== (match = unquotedSheetPattern.exec(formula)); ) {
67
+ const sheetName = match[1];
68
+ sheetName && this.isValidSheet(sheetName) && sheets.add(sheetName);
69
+ }
70
+ return Array.from(sheets);
71
+ }
72
+ extractTargetCells(formula, targetSheet) {
73
+ const cells = [], escapedSheetName = targetSheet.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), cellPattern = new RegExp(`'?${escapedSheetName}'?[!!]([A-Z]+[0-9]+)(?:\\s*:\\s*(?:'?${escapedSheetName}'?[!!])?([A-Z]+[0-9]+))?`, "g");
74
+ let match;
75
+ for (;null !== (match = cellPattern.exec(formula)); ) if (match[2]) {
76
+ const startCell = this.parseA1Notation(match[1]), endCell = this.parseA1Notation(match[2]);
77
+ for (let row = Math.min(startCell.row, endCell.row); row <= Math.max(startCell.row, endCell.row); row++) for (let col = Math.min(startCell.col, endCell.col); col <= Math.max(startCell.col, endCell.col); col++) cells.push({
78
+ sheet: targetSheet,
79
+ row: row,
80
+ col: col
81
+ });
82
+ } else {
83
+ const cell = this.parseA1Notation(match[1]);
84
+ cells.push({
85
+ sheet: targetSheet,
86
+ row: cell.row,
87
+ col: cell.col
88
+ });
89
+ }
90
+ return cells;
91
+ }
92
+ updateCrossSheetDependency(sourceSheet, targetSheet, _sourceCell, _targetCells) {
93
+ this.crossSheetDependencies.has(sourceSheet) || this.crossSheetDependencies.set(sourceSheet, new Set);
94
+ const sourceDeps = this.crossSheetDependencies.get(sourceSheet);
95
+ sourceDeps && sourceDeps.add(targetSheet), this.reverseCrossSheetDependencies.has(targetSheet) || this.reverseCrossSheetDependencies.set(targetSheet, new Set);
96
+ const targetDeps = this.reverseCrossSheetDependencies.get(targetSheet);
97
+ targetDeps && targetDeps.add(sourceSheet);
98
+ }
99
+ getCrossSheetDependencies(sheet) {
100
+ const dependencies = [], targetSheets = this.crossSheetDependencies.get(sheet);
101
+ if (targetSheets) for (const targetSheet of targetSheets) {
102
+ const dependentCells = this.getDependentCells(sheet, targetSheet), precedentCells = this.getPrecedentCells(targetSheet, sheet);
103
+ dependencies.push({
104
+ dependentSheet: sheet,
105
+ precedentSheet: targetSheet,
106
+ dependentCells: dependentCells,
107
+ precedentCells: precedentCells
108
+ });
109
+ }
110
+ return dependencies;
111
+ }
112
+ getDependentCells(dependentSheet, precedentSheet) {
113
+ const cells = [], allSheets = this.formulaEngine.getAllSheets();
114
+ for (const sheetInfo of allSheets) if (sheetInfo.key === dependentSheet) {
115
+ const formulas = this.formulaEngine.exportFormulas(sheetInfo.key);
116
+ for (const [cellRef, formula] of Object.entries(formulas)) if (formula.includes(`${precedentSheet}!`)) {
117
+ const cell = this.parseA1Notation(cellRef);
118
+ cells.push({
119
+ sheet: dependentSheet,
120
+ row: cell.row,
121
+ col: cell.col
122
+ });
123
+ }
124
+ }
125
+ return cells;
126
+ }
127
+ getPrecedentCells(precedentSheet, dependentSheet) {
128
+ const cells = [], formulas = this.formulaEngine.exportFormulas(dependentSheet);
129
+ for (const formula of Object.values(formulas)) if (formula.includes(`${precedentSheet}!`)) {
130
+ const targetCells = this.extractTargetCells(formula, precedentSheet);
131
+ cells.push(...targetCells);
132
+ }
133
+ return cells;
134
+ }
135
+ updateCrossSheetReferences(targetSheet, changedCells) {
136
+ return __awaiter(this, void 0, void 0, (function*() {
137
+ const dependentSheets = this.reverseCrossSheetDependencies.get(targetSheet);
138
+ if (!dependentSheets || 0 === dependentSheets.size) return;
139
+ const cellsToRecalculate = [];
140
+ for (const dependentSheet of dependentSheets) {
141
+ const formulas = this.formulaEngine.exportFormulas(dependentSheet);
142
+ for (const [cellRef, formula] of Object.entries(formulas)) if (this.formulaReferencesCells(formula, targetSheet, changedCells)) {
143
+ const cell = this.parseA1Notation(cellRef);
144
+ cellsToRecalculate.push({
145
+ sheet: dependentSheet,
146
+ row: cell.row,
147
+ col: cell.col
148
+ });
149
+ }
150
+ }
151
+ for (const cell of cellsToRecalculate) yield this.recalculateFormula(cell);
152
+ }));
153
+ }
154
+ formulaReferencesCells(formula, targetSheet, targetCells) {
155
+ return this.extractTargetCells(formula, targetSheet).some((refCell => targetCells.some((targetCell => refCell.sheet === targetCell.sheet && refCell.row === targetCell.row && refCell.col === targetCell.col))));
156
+ }
157
+ recalculateFormula(cell) {
158
+ return __awaiter(this, void 0, void 0, (function*() {
159
+ try {
160
+ const formula = this.formulaEngine.getCellFormula(cell);
161
+ if (formula) {
162
+ const result = this.formulaEngine.calculateFormula(formula), cacheKey = this.getCacheKey(cell);
163
+ this.calculationCache.set(cacheKey, {
164
+ value: result.value,
165
+ timestamp: Date.now()
166
+ }), this.recalculateDependents(cell);
167
+ }
168
+ } catch (error) {}
169
+ }));
170
+ }
171
+ recalculateDependents(cell) {
172
+ const dependents = this.formulaEngine.getCellDependents(cell);
173
+ for (const dependent of dependents) this.recalculateFormula(dependent);
174
+ }
175
+ validateCrossSheetReferences(sheet) {
176
+ const errors = [], formulas = this.formulaEngine.exportFormulas(sheet);
177
+ for (const [cellRef, formula] of Object.entries(formulas)) {
178
+ const targetSheets = this.extractTargetSheets(formula);
179
+ for (const targetSheet of targetSheets) {
180
+ if (!this.formulaEngine.getAllSheets().some((s => s.key === targetSheet))) {
181
+ errors.push(`Invalid sheet reference in ${cellRef}: ${targetSheet}`);
182
+ continue;
183
+ }
184
+ const targetCells = this.extractTargetCells(formula, targetSheet);
185
+ for (const targetCell of targetCells) {
186
+ this.formulaEngine.getCellValue(targetCell).error && errors.push(`Invalid cell reference in ${cellRef}: ${targetSheet}!${this.getA1Notation(targetCell.row, targetCell.col)}`);
187
+ }
188
+ }
189
+ }
190
+ return {
191
+ valid: 0 === errors.length,
192
+ errors: errors
193
+ };
194
+ }
195
+ getCachedValue(cell) {
196
+ const cacheKey = this.getCacheKey(cell), cached = this.calculationCache.get(cacheKey);
197
+ return cached && Date.now() - cached.timestamp < this.CACHE_TTL ? cached.value : null;
198
+ }
199
+ clearCache() {
200
+ this.calculationCache.clear();
201
+ }
202
+ clearSheetDependencies(sheet) {
203
+ this.crossSheetDependencies.delete(sheet);
204
+ for (const [targetSheet, sourceSheets] of this.reverseCrossSheetDependencies.entries()) sourceSheets.delete(sheet),
205
+ 0 === sourceSheets.size && this.reverseCrossSheetDependencies.delete(targetSheet);
206
+ for (const [cacheKey] of this.calculationCache.entries()) cacheKey.startsWith(`${sheet}!`) && this.calculationCache.delete(cacheKey);
207
+ }
208
+ parseA1Notation(a1Notation) {
209
+ const match = a1Notation.match(/^([A-Z]+)([0-9]+)$/);
210
+ if (!match) throw new Error(`Invalid cell reference: ${a1Notation}`);
211
+ const colLetters = match[1], rowNumber = parseInt(match[2], 10);
212
+ let col = 0;
213
+ for (let i = 0; i < colLetters.length; i++) col = 26 * col + (colLetters.charCodeAt(i) - 65);
214
+ return {
215
+ row: rowNumber - 1,
216
+ col: col
217
+ };
218
+ }
219
+ getA1Notation(row, col) {
220
+ let colStr = "", tempCol = col;
221
+ do {
222
+ colStr = String.fromCharCode(65 + tempCol % 26) + colStr, tempCol = Math.floor(tempCol / 26) - 1;
223
+ } while (tempCol >= 0);
224
+ return `${colStr}${row + 1}`;
225
+ }
226
+ getCacheKey(cell) {
227
+ return `${cell.sheet}!${this.getA1Notation(cell.row, cell.col)}`;
228
+ }
229
+ destroy() {
230
+ this.clearCache(), this.crossSheetDependencies.clear(), this.reverseCrossSheetDependencies.clear();
231
+ }
232
+ }
233
+
234
+ exports.CrossSheetFormulaManager = CrossSheetFormulaManager;
235
+ //#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CAAC,EAAE,EAAE,CAAC,CAAC;QAEzC,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,GAAG,GAAG,GAAG,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;SAClD;QAED,OAAO,EAAE,GAAG,EAAE,SAAS,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC;IACrC,CAAC;IAKO,aAAa,CAAC,GAAW,EAAE,GAAW;QAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,OAAO,GAAG,GAAG,CAAC;QAElB,GAAG;YACD,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;YAC3D,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;SACxC,QAAQ,OAAO,IAAI,CAAC,EAAE;QAEvB,OAAO,GAAG,MAAM,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;IAC/B,CAAC;IAKO,WAAW,CAAC,IAAiB;QACnC,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnE,CAAC;IAKD,OAAO;QACL,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,CAAC,6BAA6B,CAAC,KAAK,EAAE,CAAC;IAC7C,CAAC;CACF;AA7bD,4DA6bC","file":"cross-sheet-formula-manager.js","sourcesContent":["/**\n * 跨sheet公式管理器\n * 专门处理跨sheet tab的公式引用和计算\n */\n\nimport type { FormulaCell } from '../ts-types/formula';\nimport type { FormulaEngine } from './formula-engine';\n\nexport interface CrossSheetReference {\n sourceSheet: string;\n targetSheet: string;\n sourceCell: FormulaCell;\n targetCells: FormulaCell[];\n formula: string;\n}\n\nexport interface CrossSheetDependency {\n dependentSheet: string;\n precedentSheet: string;\n dependentCells: FormulaCell[];\n precedentCells: FormulaCell[];\n}\n\nexport class CrossSheetFormulaManager {\n private formulaEngine: FormulaEngine;\n private sheetManager: { getAllSheets: () => Array<{ sheetKey: string; sheetTitle: string }> } | undefined;\n\n // 跨sheet依赖关系映射\n private crossSheetDependencies: Map<string, Set<string>> = new Map();\n\n // 反向依赖映射(用于快速查找)\n private reverseCrossSheetDependencies: Map<string, Set<string>> = new Map();\n\n // 缓存机制\n private calculationCache: Map<string, { value: any; timestamp: number }> = new Map();\n private readonly CACHE_TTL = 1000; // 1秒缓存\n\n constructor(\n formulaEngine: FormulaEngine,\n sheetManager?: { getAllSheets: () => Array<{ sheetKey: string; sheetTitle: string }> }\n ) {\n this.formulaEngine = formulaEngine;\n this.sheetManager = sheetManager;\n }\n\n /**\n * 注册跨sheet公式引用\n */\n registerCrossSheetReference(formula: string, sourceCell: FormulaCell): CrossSheetReference[] {\n const references: CrossSheetReference[] = [];\n const targetSheets = this.extractTargetSheets(formula);\n\n for (const targetSheet of targetSheets) {\n const targetCells = this.extractTargetCells(formula, targetSheet);\n if (targetCells.length > 0) {\n references.push({\n sourceSheet: sourceCell.sheet,\n targetSheet,\n sourceCell,\n targetCells,\n formula\n });\n\n // 更新依赖关系\n this.updateCrossSheetDependency(sourceCell.sheet, targetSheet, sourceCell, targetCells);\n }\n }\n\n return references;\n }\n\n /**\n * 验证sheet是否存在(使用sheetTitle而不是sheetKey)\n * 检查所有存在的sheet,包括未激活的sheet\n */\n private isValidSheet(sheetName: string): boolean {\n // 优先使用sheetManager检查所有存在的sheet(包括未激活的)\n if (this.sheetManager) {\n const allSheets = this.sheetManager.getAllSheets();\n return allSheets.some(sheet => sheet.sheetTitle.toLowerCase() === sheetName.toLowerCase());\n }\n\n // 回退到formulaEngine中已注册的sheet\n const allSheets = this.formulaEngine.getAllSheets();\n return allSheets.some(sheet => sheet.title.toLowerCase() === sheetName.toLowerCase());\n }\n\n /**\n * 提取公式中引用的目标sheet\n * 检查所有存在的sheet,包括未激活的sheet\n */\n private extractTargetSheets(formula: string): string[] {\n const sheets = new Set<string>();\n // 支持:\n // - Sheet1!A1\n // - Sheet1!A1\n // - 'My Sheet'!A1\n // - 'My Sheet'!A1\n const quotedSheetPattern = /'([^']+)'[!!]/g;\n const unquotedSheetPattern = /([A-Za-z0-9_\\s一-龥]+)[!!]/g;\n\n let match: RegExpExecArray | null;\n while ((match = quotedSheetPattern.exec(formula)) !== null) {\n const sheetName = match[1];\n if (sheetName && this.isValidSheet(sheetName)) {\n sheets.add(sheetName);\n }\n }\n while ((match = unquotedSheetPattern.exec(formula)) !== null) {\n const sheetName = match[1];\n if (sheetName && this.isValidSheet(sheetName)) {\n sheets.add(sheetName);\n }\n }\n\n return Array.from(sheets);\n }\n\n /**\n * 提取公式中引用的目标单元格\n */\n private extractTargetCells(formula: string, targetSheet: string): FormulaCell[] {\n const cells: FormulaCell[] = [];\n\n // 匹配带sheet前缀的单元格引用,如 Sheet1!A1 或 Sheet1!A1:B2 - 支持中英文sheet名称\n const escapedSheetName = targetSheet.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const sepPattern = '[!!]';\n // 支持:\n // - Sheet1!A1\n // - Sheet1!A1:B2\n // - Sheet1!A1:Sheet1!B2\n // - 'My Sheet'!A1:'My Sheet'!B2\n const cellPattern = new RegExp(\n `'?${escapedSheetName}'?${sepPattern}([A-Z]+[0-9]+)` +\n `(?:\\\\s*:\\\\s*(?:'?${escapedSheetName}'?${sepPattern})?([A-Z]+[0-9]+))?`,\n 'g'\n );\n let match;\n\n while ((match = cellPattern.exec(formula)) !== null) {\n if (match[2]) {\n // 范围引用,如 A1:B2\n const startCell = this.parseA1Notation(match[1]);\n const endCell = this.parseA1Notation(match[2]);\n\n // 展开范围到所有单元格\n for (let row = Math.min(startCell.row, endCell.row); row <= Math.max(startCell.row, endCell.row); row++) {\n for (let col = Math.min(startCell.col, endCell.col); col <= Math.max(startCell.col, endCell.col); col++) {\n cells.push({ sheet: targetSheet, row, col });\n }\n }\n } else {\n // 单个单元格引用,如 A1\n const cell = this.parseA1Notation(match[1]);\n cells.push({ sheet: targetSheet, row: cell.row, col: cell.col });\n }\n }\n\n return cells;\n }\n\n /**\n * 更新跨sheet依赖关系\n */\n private updateCrossSheetDependency(\n sourceSheet: string,\n targetSheet: string,\n _sourceCell: FormulaCell,\n _targetCells: FormulaCell[]\n ): void {\n // 正向依赖\n if (!this.crossSheetDependencies.has(sourceSheet)) {\n this.crossSheetDependencies.set(sourceSheet, new Set());\n }\n const sourceDeps = this.crossSheetDependencies.get(sourceSheet);\n if (sourceDeps) {\n sourceDeps.add(targetSheet);\n }\n\n // 反向依赖\n if (!this.reverseCrossSheetDependencies.has(targetSheet)) {\n this.reverseCrossSheetDependencies.set(targetSheet, new Set());\n }\n const targetDeps = this.reverseCrossSheetDependencies.get(targetSheet);\n if (targetDeps) {\n targetDeps.add(sourceSheet);\n }\n }\n\n /**\n * 获取跨sheet依赖关系\n */\n getCrossSheetDependencies(sheet: string): CrossSheetDependency[] {\n const dependencies: CrossSheetDependency[] = [];\n const targetSheets = this.crossSheetDependencies.get(sheet);\n\n if (targetSheets) {\n for (const targetSheet of targetSheets) {\n const dependentCells = this.getDependentCells(sheet, targetSheet);\n const precedentCells = this.getPrecedentCells(targetSheet, sheet);\n\n dependencies.push({\n dependentSheet: sheet,\n precedentSheet: targetSheet,\n dependentCells,\n precedentCells\n });\n }\n }\n\n return dependencies;\n }\n\n /**\n * 获取依赖于指定sheet的单元格\n */\n private getDependentCells(dependentSheet: string, precedentSheet: string): FormulaCell[] {\n const cells: FormulaCell[] = [];\n\n // 遍历所有公式,找到引用precedentSheet的单元格\n const allSheets = this.formulaEngine.getAllSheets();\n for (const sheetInfo of allSheets) {\n if (sheetInfo.key === dependentSheet) {\n const formulas = this.formulaEngine.exportFormulas(sheetInfo.key);\n\n for (const [cellRef, formula] of Object.entries(formulas)) {\n if (formula.includes(`${precedentSheet}!`)) {\n const cell = this.parseA1Notation(cellRef);\n cells.push({ sheet: dependentSheet, row: cell.row, col: cell.col });\n }\n }\n }\n }\n\n return cells;\n }\n\n /**\n * 获取被指定sheet依赖的单元格\n */\n private getPrecedentCells(precedentSheet: string, dependentSheet: string): FormulaCell[] {\n const cells: FormulaCell[] = [];\n\n // 从dependentSheet的公式中提取引用precedentSheet的单元格\n const formulas = this.formulaEngine.exportFormulas(dependentSheet);\n\n for (const formula of Object.values(formulas)) {\n if (formula.includes(`${precedentSheet}!`)) {\n const targetCells = this.extractTargetCells(formula, precedentSheet);\n cells.push(...targetCells);\n }\n }\n\n return cells;\n }\n\n /**\n * 当目标sheet数据变化时,更新依赖的公式\n */\n async updateCrossSheetReferences(targetSheet: string, changedCells: FormulaCell[]): Promise<void> {\n const dependentSheets = this.reverseCrossSheetDependencies.get(targetSheet);\n\n if (!dependentSheets || dependentSheets.size === 0) {\n return;\n }\n\n // 收集所有需要重新计算的公式单元格\n const cellsToRecalculate: FormulaCell[] = [];\n\n for (const dependentSheet of dependentSheets) {\n const formulas = this.formulaEngine.exportFormulas(dependentSheet);\n\n for (const [cellRef, formula] of Object.entries(formulas)) {\n // 检查公式是否引用了任何变化的单元格\n if (this.formulaReferencesCells(formula, targetSheet, changedCells)) {\n const cell = this.parseA1Notation(cellRef);\n cellsToRecalculate.push({ sheet: dependentSheet, row: cell.row, col: cell.col });\n }\n }\n }\n\n // 重新计算所有受影响的公式\n for (const cell of cellsToRecalculate) {\n await this.recalculateFormula(cell);\n }\n }\n\n /**\n * 检查公式是否引用了指定的单元格\n */\n private formulaReferencesCells(formula: string, targetSheet: string, targetCells: FormulaCell[]): boolean {\n const referencedCells = this.extractTargetCells(formula, targetSheet);\n\n return referencedCells.some(refCell =>\n targetCells.some(\n targetCell =>\n refCell.sheet === targetCell.sheet && refCell.row === targetCell.row && refCell.col === targetCell.col\n )\n );\n }\n\n /**\n * 重新计算公式单元格\n */\n private async recalculateFormula(cell: FormulaCell): Promise<void> {\n try {\n const formula = this.formulaEngine.getCellFormula(cell);\n if (formula) {\n const result = this.formulaEngine.calculateFormula(formula);\n\n // 更新缓存\n const cacheKey = this.getCacheKey(cell);\n this.calculationCache.set(cacheKey, {\n value: result.value,\n timestamp: Date.now()\n });\n\n // 触发重新计算依赖\n this.recalculateDependents(cell);\n }\n } catch (error) {\n console.error(`Failed to recalculate formula at ${cell.sheet}!${this.getA1Notation(cell.row, cell.col)}:`, error);\n }\n }\n\n /**\n * 重新计算依赖的公式\n */\n private recalculateDependents(cell: FormulaCell): void {\n const dependents = this.formulaEngine.getCellDependents(cell);\n\n for (const dependent of dependents) {\n // 递归重新计算\n this.recalculateFormula(dependent);\n }\n }\n\n /**\n * 验证跨sheet引用的有效性\n */\n validateCrossSheetReferences(sheet: string): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n const formulas = this.formulaEngine.exportFormulas(sheet);\n\n for (const [cellRef, formula] of Object.entries(formulas)) {\n const targetSheets = this.extractTargetSheets(formula);\n\n for (const targetSheet of targetSheets) {\n if (!this.formulaEngine.getAllSheets().some(s => s.key === targetSheet)) {\n errors.push(`Invalid sheet reference in ${cellRef}: ${targetSheet}`);\n continue;\n }\n\n const targetCells = this.extractTargetCells(formula, targetSheet);\n for (const targetCell of targetCells) {\n const cellValue = this.formulaEngine.getCellValue(targetCell);\n if (cellValue.error) {\n errors.push(\n `Invalid cell reference in ${cellRef}: ${targetSheet}!${this.getA1Notation(\n targetCell.row,\n targetCell.col\n )}`\n );\n }\n }\n }\n }\n\n return {\n valid: errors.length === 0,\n errors\n };\n }\n\n /**\n * 获取缓存的计算结果\n */\n getCachedValue(cell: FormulaCell): any {\n const cacheKey = this.getCacheKey(cell);\n const cached = this.calculationCache.get(cacheKey);\n\n if (cached && Date.now() - cached.timestamp < this.CACHE_TTL) {\n return cached.value;\n }\n\n return null;\n }\n\n /**\n * 清除缓存\n */\n clearCache(): void {\n this.calculationCache.clear();\n }\n\n /**\n * 清除指定sheet的依赖关系\n */\n clearSheetDependencies(sheet: string): void {\n // 清除正向依赖\n this.crossSheetDependencies.delete(sheet);\n\n // 清除反向依赖\n for (const [targetSheet, sourceSheets] of this.reverseCrossSheetDependencies.entries()) {\n sourceSheets.delete(sheet);\n if (sourceSheets.size === 0) {\n this.reverseCrossSheetDependencies.delete(targetSheet);\n }\n }\n\n // 清除相关缓存\n for (const [cacheKey] of this.calculationCache.entries()) {\n if (cacheKey.startsWith(`${sheet}!`)) {\n this.calculationCache.delete(cacheKey);\n }\n }\n }\n\n /**\n * 工具方法:A1表示法解析\n */\n private parseA1Notation(a1Notation: string): { row: number; col: number } {\n const match = a1Notation.match(/^([A-Z]+)([0-9]+)$/);\n if (!match) {\n throw new Error(`Invalid cell reference: ${a1Notation}`);\n }\n\n const colLetters = match[1];\n const rowNumber = parseInt(match[2], 10);\n\n let col = 0;\n for (let i = 0; i < colLetters.length; i++) {\n col = col * 26 + (colLetters.charCodeAt(i) - 65);\n }\n\n return { row: rowNumber - 1, col };\n }\n\n /**\n * 工具方法:A1表示法生成\n */\n private getA1Notation(row: number, col: number): string {\n let colStr = '';\n let tempCol = col;\n\n do {\n colStr = String.fromCharCode(65 + (tempCol % 26)) + colStr;\n tempCol = Math.floor(tempCol / 26) - 1;\n } while (tempCol >= 0);\n\n return `${colStr}${row + 1}`;\n }\n\n /**\n * 工具方法:缓存键生成\n */\n private getCacheKey(cell: FormulaCell): string {\n return `${cell.sheet}!${this.getA1Notation(cell.row, cell.col)}`;\n }\n\n /**\n * 销毁管理器\n */\n destroy(): void {\n this.clearCache();\n this.crossSheetDependencies.clear();\n this.reverseCrossSheetDependencies.clear();\n }\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import type { FormulaCell } from '../ts-types/formula';
2
+ import type { FormulaEngine } from './formula-engine';
3
+ import type { CrossSheetFormulaManager } from './cross-sheet-formula-manager';
4
+ export interface ValidationError {
5
+ type: 'INVALID_SHEET' | 'INVALID_CELL' | 'CIRCULAR_REFERENCE' | 'MISSING_REFERENCE';
6
+ message: string;
7
+ sheet: string;
8
+ cell: FormulaCell;
9
+ target?: string;
10
+ }
11
+ export interface ValidationResult {
12
+ valid: boolean;
13
+ errors: ValidationError[];
14
+ warnings: string[];
15
+ }
16
+ export interface ValidationOptions {
17
+ checkCircularReferences: boolean;
18
+ checkMissingReferences: boolean;
19
+ checkCellBounds: boolean;
20
+ maxRecursionDepth: number;
21
+ }
22
+ export declare class CrossSheetFormulaValidator {
23
+ private formulaEngine;
24
+ private crossSheetManager;
25
+ private sheetManager;
26
+ private validationCache;
27
+ private readonly CACHE_TTL;
28
+ private defaultOptions;
29
+ constructor(formulaEngine: FormulaEngine, crossSheetManager: CrossSheetFormulaManager, sheetManager?: {
30
+ getAllSheets: () => Array<{
31
+ sheetKey: string;
32
+ sheetTitle: string;
33
+ }>;
34
+ });
35
+ validateSheet(sheet: string, options?: Partial<ValidationOptions>): ValidationResult;
36
+ private validateFormula;
37
+ private extractCrossSheetReferences;
38
+ private validateCellReferences;
39
+ private checkCircularReferences;
40
+ private checkMissingReferences;
41
+ validateAllSheets(options?: Partial<ValidationOptions>): Map<string, ValidationResult>;
42
+ validateFormulaSyntax(formula: string): {
43
+ valid: boolean;
44
+ error?: string;
45
+ };
46
+ private validateExpressionStructure;
47
+ private isValidSheetName;
48
+ private isValidCellReference;
49
+ private isValidSheet;
50
+ private parseA1Notation;
51
+ private getA1Notation;
52
+ private getCacheKey;
53
+ private getCacheTimestamp;
54
+ clearCache(): void;
55
+ destroy(): void;
56
+ }