@univerjs/sheets-formula
Version:
| Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales | | --- | --- | --- | --- | --- | :---: | :---: | | `@univerjs/sheets-formula` | `UniverSheetsFormula` | [![][npm-version-shield]][npm-version-link] | ![
2 lines (1 loc) • 3.82 kB
JavaScript
"use strict";const d=require("@univerjs/core"),x=require("@univerjs/core/facade"),F=require("@univerjs/engine-formula"),i=require("@univerjs/sheets-formula"),y=require("@univerjs/engine-formula/facade"),C=require("@univerjs/sheets/facade");class R extends x.FUniver{_initialize(){this._debouncedFormulaCalculation=d.debounce(()=>{this._commandService.executeCommand(F.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(t){let n=this._injector.get(i.IRegisterFunctionService);n||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),n=this._injector.get(i.IRegisterFunctionService));const e=n.registerFunctions(t);return this._debouncedFormulaCalculation(),e}}x.FUniver.extend(R);class j extends y.FFormula{_initialize(){this._debouncedFormulaCalculation=d.debounce(()=>{this._commandService.executeCommand(F.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(t){const e=this._injector.get(d.LifecycleService).stage,o=this._injector.get(d.ILogService),c=this._injector.get(d.IConfigService);e>d.LifecycleStages.Starting&&o.warn("[FFormula]","CalculationMode is called after the Starting lifecycle and will take effect the next time the Univer Sheet is constructed. If you want it to take effect when the Univer Sheet is initialized this time, consider calling it before the Ready lifecycle or using configuration.");const r=c.getConfig(i.PLUGIN_CONFIG_KEY_BASE);if(!r){c.setConfig(i.PLUGIN_CONFIG_KEY_BASE,{initialFormulaComputing:t});return}r.initialFormulaComputing=t}registerFunction(t,n,e){var s;let o=this._injector.get(i.IRegisterFunctionService);o||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),o=this._injector.get(i.IRegisterFunctionService));const c={name:t,func:n,description:typeof e=="string"?e:(s=e==null?void 0:e.description)!=null?s:"",locales:typeof e=="object"?e.locales:void 0},r=o.registerFunction(c);return this._debouncedFormulaCalculation(),r}registerAsyncFunction(t,n,e){var s;let o=this._injector.get(i.IRegisterFunctionService);o||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),o=this._injector.get(i.IRegisterFunctionService));const c={name:t,func:n,description:typeof e=="string"?e:(s=e==null?void 0:e.description)!=null?s:"",locales:typeof e=="object"?e.locales:void 0},r=o.registerAsyncFunction(c);return this._debouncedFormulaCalculation(),r}}y.FFormula.extend(j);class M{get CalculationMode(){return i.CalculationMode}}x.FEnum.extend(M);class E extends C.FWorkbook{getAllFormulaError(){const t=[],n=this._workbook,e=n.getUnitId(),o=n.getSheets(),c=this._injector.get(F.FormulaDataModel).getArrayFormulaCellData();return o.forEach(r=>{var S;const s=r.getName(),v=r.getSheetId(),I=r.getCellMatrix(),m=((S=c==null?void 0:c[e])==null?void 0:S[v])||{};I.forValue((_,h,u)=>{var g;if(!u)return;const l=(g=m==null?void 0:m[_])==null?void 0:g[h],a=F.extractFormulaError(u,!!l);a&&t.push({sheetName:s,row:_,column:h,formula:u.f||"",errorType:a})})}),t}}C.FWorkbook.extend(E);class w extends C.FRange{getFormulaError(){var h,u;const t=[],n=this._workbook.getUnitId(),e=this._worksheet.getSheetId(),o=this._worksheet.getName(),c=this._workbook.getSheetBySheetId(e);if(!c)return t;const r=this._injector.get(F.FormulaDataModel).getArrayFormulaCellData(),s=((h=r==null?void 0:r[n])==null?void 0:h[e])||{},v=c.getCellMatrix(),{startRow:I,endRow:m,startColumn:S,endColumn:_}=this._range;for(let l=I;l<=m;l++)for(let a=S;a<=_;a++){const g=v.getValue(l,a);if(!g)continue;const k=(u=s==null?void 0:s[l])==null?void 0:u[a],b=F.extractFormulaError(g,!!k);b&&t.push({sheetName:o,row:l,column:a,formula:g.f||"",errorType:b})}return t}}C.FRange.extend(w);