@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) • 4.26 kB
JavaScript
(function(t,l){typeof exports=="object"&&typeof module<"u"?l(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula/facade"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/core/facade","@univerjs/engine-formula","@univerjs/sheets-formula","@univerjs/engine-formula/facade","@univerjs/sheets/facade"],l):(t=typeof globalThis<"u"?globalThis:t||self,l(t.UniverCore,t.UniverCoreFacade,t.UniverEngineFormula,t.UniverSheetsFormula,t.UniverEngineFormulaFacade,t.UniverSheetsFacade))})(this,(function(t,l,g,i,x,m){"use strict";class k extends l.FUniver{_initialize(){this._debouncedFormulaCalculation=t.debounce(()=>{this._commandService.executeCommand(g.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(n){let c=this._injector.get(i.IRegisterFunctionService);c||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),c=this._injector.get(i.IRegisterFunctionService));const e=c.registerFunctions(n);return this._debouncedFormulaCalculation(),e}}l.FUniver.extend(k);class R extends x.FFormula{_initialize(){this._debouncedFormulaCalculation=t.debounce(()=>{this._commandService.executeCommand(g.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(n){const e=this._injector.get(t.LifecycleService).stage,o=this._injector.get(t.ILogService),s=this._injector.get(t.IConfigService);e>t.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=s.getConfig(i.PLUGIN_CONFIG_KEY_BASE);if(!r){s.setConfig(i.PLUGIN_CONFIG_KEY_BASE,{initialFormulaComputing:n});return}r.initialFormulaComputing=n}registerFunction(n,c,e){var a;let o=this._injector.get(i.IRegisterFunctionService);o||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),o=this._injector.get(i.IRegisterFunctionService));const s={name:n,func:c,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},r=o.registerFunction(s);return this._debouncedFormulaCalculation(),r}registerAsyncFunction(n,c,e){var a;let o=this._injector.get(i.IRegisterFunctionService);o||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),o=this._injector.get(i.IRegisterFunctionService));const s={name:n,func:c,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},r=o.registerAsyncFunction(s);return this._debouncedFormulaCalculation(),r}}x.FFormula.extend(R);class b{get CalculationMode(){return i.CalculationMode}}l.FEnum.extend(b);class E extends m.FWorkbook{getAllFormulaError(){const n=[],c=this._workbook,e=c.getUnitId(),o=c.getSheets(),s=this._injector.get(g.FormulaDataModel).getArrayFormulaCellData();return o.forEach(r=>{var C;const a=r.getName(),j=r.getSheetId(),I=r.getCellMatrix(),F=((C=s==null?void 0:s[e])==null?void 0:C[j])||{};I.forValue((_,h,f)=>{var v;if(!f)return;const d=(v=F==null?void 0:F[_])==null?void 0:v[h],u=g.extractFormulaError(f,!!d);u&&n.push({sheetName:a,row:_,column:h,formula:f.f||"",errorType:u})})}),n}}m.FWorkbook.extend(E);class U extends m.FRange{getFormulaError(){var h,f;const n=[],c=this._workbook.getUnitId(),e=this._worksheet.getSheetId(),o=this._worksheet.getName(),s=this._workbook.getSheetBySheetId(e);if(!s)return n;const r=this._injector.get(g.FormulaDataModel).getArrayFormulaCellData(),a=((h=r==null?void 0:r[c])==null?void 0:h[e])||{},j=s.getCellMatrix(),{startRow:I,endRow:F,startColumn:C,endColumn:_}=this._range;for(let d=I;d<=F;d++)for(let u=C;u<=_;u++){const v=j.getValue(d,u);if(!v)continue;const M=(f=a==null?void 0:a[d])==null?void 0:f[u],y=g.extractFormulaError(v,!!M);y&&n.push({sheetName:o,row:d,column:u,formula:v.f||"",errorType:y})}return n}}m.FRange.extend(U)}));