UNPKG

@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] | ![

1,598 lines • 518 kB
var Xa = Object.defineProperty; var Wa = (a, e, n) => e in a ? Xa(a, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[e] = n; var W = (a, e, n) => Wa(a, typeof e != "symbol" ? e + "" : e, n); import { CommandType as xt, ICommandService as ce, ObjectMatrix as G, generateRandomId as la, IUniverInstanceService as Ae, Rectangle as fe, sequenceExecuteAsync as Ka, Inject as X, LifecycleService as ka, Disposable as ae, ILogService as Qa, IConfigService as Ce, LocaleService as _t, isFormulaString as Me, isFormulaId as sa, cellToRange as da, Direction as Xe, getIntersectRange as Ye, RANGE_TYPE as Y, UniverInstanceType as te, Injector as rt, Tools as ft, InterceptorEffectEnum as $a, CellValueType as Gt, isRealNum as ja, createIdentifier as yt, toDisposable as ie, moveRangeByOffset as Nt, DisposableCollection as We, AbsoluteRefType as Ke, Optional as za, DependentOn as pa, Plugin as La, merge as Pa, touchDependencies as Ue, isNodeEnv as Ht } from "@univerjs/core"; import { SetRangeValuesCommand as Ta, SheetsSelectionsService as Za, getSheetCommandTarget as Ja, findFirstNonEmptyCell as en, alignToMergedCellsBorders as ct, expandToContinuousRange as tn, SetSelectionsOperation as an, SetRangeValuesMutation as Z, SetStyleCommand as qt, SetBorderCommand as Ea, ClearSelectionFormatCommand as Ia, handleMoveCols as Na, EffectRefRangId as H, runRefRangeMutations as w, handleMoveRows as Ra, handleMoveRange as Sa, handleInsertRangeMoveRight as Aa, handleInsertRangeMoveDown as Ca, handleDeleteRangeMoveUp as Da, handleDeleteRangeMoveLeft as ba, handleIRemoveCol as Oa, handleIRemoveRow as Ma, handleInsertCol as xa, handleInsertRow as _a, RemoveDefinedNameCommand as ya, SetDefinedNameCommand as qa, RemoveSheetCommand as nn, SetWorksheetNameCommand as rn, DeleteRangeMoveLeftCommand as on, DeleteRangeMoveUpCommand as un, RemoveColCommand as mn, RemoveRowCommand as fn, InsertRangeMoveDownCommand as cn, InsertRangeMoveRightCommand as ln, InsertColCommand as sn, InsertRowCommand as dn, MoveColsCommand as pn, MoveRowsCommand as Ln, MoveRangeCommand as Pn, SheetInterceptorService as gt, RemoveSheetMutation as Rt, InsertSheetMutation as St, MoveRangeMutation as wt, MoveRowsMutation as Yt, MoveColsMutation as Xt, ReorderRangeMutation as Wt, RemoveRowMutation as Kt, RemoveColMutation as kt, InsertColMutation as Qt, InsertRowMutation as $t, SetRowHiddenMutation as jt, SetRowVisibleMutation as zt, INTERCEPTOR_POINT as Tn, SetWorksheetActiveOperation as En, SCOPE_WORKBOOK_VALUE_DEFINED_NAME as lt, RefRangeService as In, handleDefaultRangeChangeWithEffectRefCommands as Zt, getSeparateEffectedRangesOnCommand as Nn, handleCommonDefaultRangeChangeWithEffectRefCommands as Rn, UniverSheetsPlugin as Sn } from "@univerjs/sheets"; import { serializeRange as _e, IActiveDirtyManagerService as ht, SetFormulaCalculationResultMutation as An, RemoveOtherFormulaMutation as Cn, SetOtherFormulaMutation as Dn, FormulaDataModel as ot, SetFormulaCalculationStartMutation as Ie, SetFormulaCalculationStopMutation as Jt, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as ea, SetFormulaCalculationNotificationMutation as bn, FormulaExecuteStageType as Fe, FormulaExecutedStateType as De, sequenceNodeType as ee, deserializeRangeWithSheetWithCache as pe, serializeRangeToRefString as ut, ErrorType as j, IDefinedNamesService as Ut, LexerTreeBuilder as Ft, generateStringWithSequence as ke, SetDefinedNameMutation as ye, SetFormulaDataMutation as Be, SetArrayFormulaDataMutation as At, initSheetFormulaData as ta, RemoveDefinedNameMutation as Ct, stripErrorMargin as On, FunctionType as t, FUNCTION_NAMES_ARRAY as aa, FUNCTION_NAMES_COMPATIBILITY as x, FUNCTION_NAMES_CUBE as se, FUNCTION_NAMES_DATABASE as $, FUNCTION_NAMES_DATE as F, FUNCTION_NAMES_ENGINEERING as A, FUNCTION_NAMES_FINANCIAL as C, FUNCTION_NAMES_INFORMATION as v, FUNCTION_NAMES_LOGICAL as K, FUNCTION_NAMES_LOOKUP as _, FUNCTION_NAMES_MATH as L, FUNCTION_NAMES_STATISTICAL as l, FUNCTION_NAMES_TEXT as b, FUNCTION_NAMES_WEB as st, IFunctionService as Bt, isReferenceStrings as Mn, functionArray as xn, functionCompatibility as _n, functionCube as yn, functionDatabase as qn, functionDate as gn, functionEngineering as hn, functionFinancial as Un, functionInformation as Fn, functionLogical as Bn, functionLookup as vn, functionMath as Vn, functionMeta as Gn, functionStatistical as Hn, functionText as wn, functionUniver as Yn, functionWeb as Xn, serializeRangeWithSpreadsheet as na, serializeRangeWithSheet as ia, CustomFunction as Dt, AsyncCustomFunction as ga, UniverFormulaEnginePlugin as ha, IFormulaCurrentConfigService as Wn, Lexer as Kn, AstTreeBuilder as kn, Interpreter as Qn, generateExecuteAstNodeData as $n, getObjectValue as jn } from "@univerjs/engine-formula"; import { Subject as ra, BehaviorSubject as Ua, bufferWhen as zn, filter as oa, map as Zn } from "rxjs"; import { IRPCChannelService as Fa, fromModule as Jn, toModule as ei } from "@univerjs/rpc"; const ti = { id: "formula.command.insert-function", type: xt.COMMAND, handler: async (a, e) => { const { list: n, listOfRangeHasNumber: i } = e, r = a.get(ce), o = new G(); n.forEach((f) => { const { range: m, primary: c, formula: s } = f, { row: P, column: E } = c, p = la(6); o.setValue(P, E, { f: s, si: p }); const { startRow: R, startColumn: S, endRow: N, endColumn: d } = m; for (let D = R; D <= N; D++) for (let I = S; I <= d; I++) (D !== P || I !== E) && o.setValue(D, I, { si: p }); }), i && i.length > 0 && i.forEach((f) => { const { primary: m, formula: c } = f; o.setValue(m.row, m.column, { f: c }); }); const u = { value: o.getData() }; return r.executeCommand(Ta.id, u); } }, ai = { id: "sheets-formula.command.quick-sum", type: xt.COMMAND, handler: async (a) => { const n = a.get(Za).getCurrentLastSelection(); if (!n) return !1; const i = a.get(Ae), r = Ja(i); if (!r) return !1; const o = n.range, { worksheet: u } = r; let f = en(o, u); if (!f) return !1; f = ct(f, u); const m = tn({ startRow: f.startRow, startColumn: f.startColumn, endRow: o.endRow, endColumn: o.endColumn }, { left: !0, right: !0, up: !0, down: !0 }, u), c = new G(), s = ct({ startRow: m.endRow, endRow: m.endRow, startColumn: m.startColumn, endColumn: m.endColumn }, u); if (!fe.equals(s, m)) for (const p of u.iterateByColumn(s)) (!p.value || !u.cellHasValue(p.value)) && c.setValue(p.row, p.col, { f: `=SUM(${_e({ startColumn: p.col, endColumn: p.col, startRow: m.startRow, endRow: p.row - 1 })})` }); const P = ct({ startRow: m.startRow, startColumn: m.endColumn, endRow: m.endRow, endColumn: m.endColumn }, u); if (!fe.equals(P, m)) for (const p of u.iterateByRow(P)) (!p.value || !u.cellHasValue(p.value)) && c.setValue(p.row, p.col, { f: `=SUM(${_e({ startColumn: m.startColumn, endColumn: p.col - 1, startRow: p.row, endRow: p.row })})` }); const E = a.get(ce); return (await Ka([ { id: Ta.id, params: { range: m, value: c.getMatrix() } }, { id: an.id, params: { unitId: r.unitId, subUnitId: r.subUnitId, selections: [{ range: m, primary: fe.contains(m, n.primary) ? n.primary : { ...f, actualRow: f.startRow, actualColumn: f.startColumn }, style: null }] } } ], E)).result; } }, Oe = { type: xt.MUTATION, id: "sheet.mutation.data-validation-formula-mark-dirty", handler() { return !0; } }, ge = "sheets-formula.base.config"; var Le = /* @__PURE__ */ ((a) => (a[a.FORCED = 0] = "FORCED", a[a.WHEN_EMPTY = 1] = "WHEN_EMPTY", a[a.NO_CALCULATION = 2] = "NO_CALCULATION", a))(Le || {}); const ua = {}, ni = "sheets-formula.remote.config", ma = {}; var Ne = /* @__PURE__ */ ((a) => (a[a.NOT_REGISTER = 1] = "NOT_REGISTER", a[a.SUCCESS = 2] = "SUCCESS", a[a.WAIT = 3] = "WAIT", a[a.ERROR = 4] = "ERROR", a))(Ne || {}), ii = Object.getOwnPropertyDescriptor, ri = (a, e, n, i) => { for (var r = i > 1 ? void 0 : i ? ii(e, n) : e, o = a.length - 1, u; o >= 0; o--) (u = a[o]) && (r = u(r) || r); return r; }, dt = (a, e) => (n, i) => e(n, i, a); let Qe = class extends ae { constructor(e, n, i) { super(); W(this, "_formulaCacheMap", /* @__PURE__ */ new Map()); W(this, "_formulaChangeWithRange$", new ra()); W(this, "formulaChangeWithRange$", this._formulaChangeWithRange$.asObservable()); // FIXME: this design could be improved. W(this, "_formulaResult$", new ra()); W(this, "formulaResult$", this._formulaResult$.asObservable()); W(this, "calculateStarted$", new Ua(!1)); this._commandService = e, this._activeDirtyManagerService = n, this._lifecycleService = i, this._initFormulaRegister(), this._initFormulaCalculationResultChange(); } dispose() { super.dispose(), this._formulaChangeWithRange$.complete(), this._formulaResult$.complete(), this.calculateStarted$.complete(); } _ensureCacheMap(e, n) { let i = this._formulaCacheMap.get(e); i || (i = /* @__PURE__ */ new Map(), this._formulaCacheMap.set(e, i)); let r = i.get(n); return r || (r = /* @__PURE__ */ new Map(), i.set(n, r)), r; } _createFormulaId(e, n) { return `formula.${e}_${n}_${la(8)}`; } _initFormulaRegister() { this._activeDirtyManagerService.register( Oe.id, { commandId: Oe.id, getDirtyData(n) { return { dirtyUnitOtherFormulaMap: n.params }; } } ); const e = (n) => { const { unitId: i, subUnitId: r, formulaText: o, formulaId: u, ranges: f } = n; if (!this._ensureCacheMap(i, r).has(u)) return; const c = { unitId: i, subUnitId: r, formulaMap: { [u]: { f: o, ranges: f } } }; this._commandService.executeCommand(Dn.id, c).then(() => { this._commandService.executeCommand( Oe.id, { [i]: { [r]: { [u]: !0 } } } ); }); }; this.disposeWithMe( this._formulaChangeWithRange$.pipe(zn(() => this.calculateStarted$.pipe(oa((n) => n)))).subscribe((n) => n.forEach(e)) ), this.disposeWithMe( this._formulaChangeWithRange$.pipe(oa(() => this.calculateStarted$.getValue())).subscribe(e) ); } _initFormulaCalculationResultChange() { this.disposeWithMe(this._commandService.onCommandExecuted((e) => { if (e.id === An.id) { const n = e.params, { unitOtherData: i } = n, r = {}; for (const o in i) { const u = i[o], f = {}; r[o] = f; for (const m in u) { const c = this._ensureCacheMap(o, m), s = u[m], P = []; f[m] = P; for (const E in s) { const p = s[E]; if (c.has(E)) { const R = c.get(E); if (!R) continue; R.result || (R.result = {}); const S = new G(p), N = new G(R.result); S.forValue((d, D, I) => { N.setValue(d, D, I); }), R.status = Ne.SUCCESS, R.callbacks.forEach((d) => { d(p); }), R.callbacks.clear(), P.push(R); } } } } this._formulaResult$.next(r); } })); } registerFormulaWithRange(e, n, i, r = [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }], o) { const u = this._createFormulaId(e, n); return this._ensureCacheMap(e, n).set(u, { result: void 0, status: Ne.WAIT, formulaId: u, callbacks: /* @__PURE__ */ new Set(), extra: o }), this._formulaChangeWithRange$.next({ unitId: e, subUnitId: n, formulaText: i, formulaId: u, ranges: r }), u; } deleteFormula(e, n, i) { const r = { unitId: e, subUnitId: n, formulaIdList: i }; this._commandService.executeCommand(Cn.id, r); const o = this._ensureCacheMap(e, n); i.forEach((u) => o.delete(u)); } getFormulaValue(e, n, i) { const r = this._ensureCacheMap(e, n), o = r.get(i); return o ? o.status === Ne.SUCCESS || o.status === Ne.ERROR ? Promise.resolve(o) : new Promise((u) => { o.callbacks.add(() => { u(r.get(i)); }); }) : Promise.resolve(null); } getFormulaValueSync(e, n, i) { return this._ensureCacheMap(e, n).get(i); } markFormulaDirty(e, n, i) { const r = this.getFormulaValueSync(e, n, i); r && (r.status = Ne.WAIT, this._commandService.executeCommand( Oe.id, { [e]: { [n]: { [i]: !0 } } } )); } }; Qe = ri([ dt(0, ce), dt(1, ht), dt(2, X(ka)) ], Qe); var oi = Object.getOwnPropertyDescriptor, ui = (a, e, n, i) => { for (var r = i > 1 ? void 0 : i ? oi(e, n) : e, o = a.length - 1, u; o >= 0; o--) (u = a[o]) && (r = u(r) || r); return r; }, de = (a, e) => (n, i) => e(n, i, a); const fa = { done: 0, count: 0 }, pt = { onlyLocal: !0 }; let xe = class extends ae { constructor(e, n, i, r, o, u, f) { super(); W(this, "_waitingCommandQueue", []); W(this, "_executingDirtyData", { forceCalculation: !1, dirtyRanges: [], dirtyNameMap: {}, dirtyDefinedNameMap: {}, dirtyUnitFeatureMap: {}, dirtyUnitOtherFormulaMap: {}, clearDependencyTreeCache: {} }); W(this, "_setTimeoutKey", -1); W(this, "_startExecutionTime", 0); W(this, "_totalCalculationTaskCount", 0); W(this, "_doneCalculationTaskCount", 0); W(this, "_executionInProgressParams", null); W(this, "_restartCalculation", !1); /** * The mark of forced calculation. If a new mutation triggers dirty area calculation during the forced calculation process, forced calculation is still required. */ W(this, "_forceCalculating", !1); W(this, "_progress$", new Ua(fa)); W(this, "progress$", this._progress$.asObservable()); this._commandService = e, this._activeDirtyManagerService = n, this._logService = i, this._configService = r, this._formulaDataModel = o, this._localeService = u, this._registerOtherFormulaService = f, this._commandExecutedListener(), this._initialExecuteFormulaProcessListener(), this._initialExecuteFormula(); } _emitProgress(e) { this._progress$.next({ done: this._doneCalculationTaskCount, count: this._totalCalculationTaskCount, label: e }); } _startProgress() { this._doneCalculationTaskCount = 0, this._totalCalculationTaskCount = 1; const e = this._localeService.t("formula.progress.analyzing"); this._emitProgress(e); } _calculateProgress(e) { if (this._executionInProgressParams) { const { totalFormulasToCalculate: n, completedFormulasCount: i, totalArrayFormulasToCalculate: r, completedArrayFormulasCount: o } = this._executionInProgressParams; if (this._doneCalculationTaskCount = i + o, this._totalCalculationTaskCount = n + r, this._totalCalculationTaskCount === 0) return; this._emitProgress(e); } } _completeProgress() { this._doneCalculationTaskCount = this._totalCalculationTaskCount = 1; const e = this._localeService.t("formula.progress.done"); this._emitProgress(e); } clearProgress() { this._doneCalculationTaskCount = 0, this._totalCalculationTaskCount = 0, this._emitProgress(); } dispose() { super.dispose(), this._progress$.next(fa), this._progress$.complete(), clearTimeout(this._setTimeoutKey); } _getCalculationMode() { var n; const e = this._configService.getConfig(ge); return (n = e == null ? void 0 : e.initialFormulaComputing) != null ? n : Le.WHEN_EMPTY; } _commandExecutedListener() { this.disposeWithMe( this._commandService.beforeCommandExecuted((e) => { if (e.id === Ie.id) { const n = e.params; n.rowData = this._formulaDataModel.getHiddenRowsFiltered(); } }) ), this.disposeWithMe( this._commandService.onCommandExecuted((e, n) => { if (this._activeDirtyManagerService.get(e.id)) { if (e.id === Z.id) { const i = e.params; if (n && n.onlyLocal === !0 || i.trigger === qt.id || i.trigger === Ea.id || i.trigger === Ia.id) return; } this._waitingCommandQueue.push(e), clearTimeout(this._setTimeoutKey), this._setTimeoutKey = setTimeout(() => { const i = this._generateDirty(this._waitingCommandQueue); this._executingDirtyData = this._mergeDirty(this._executingDirtyData, i), this._executionInProgressParams == null ? this._commandService.executeCommand(Ie.id, { ...this._executingDirtyData }, pt) : (this._restartCalculation = !0, this._commandService.executeCommand(Jt.id, {})), this._waitingCommandQueue = []; }, 100); } }) ); } _generateDirty(e) { const n = [], i = {}, r = {}, o = {}, u = {}, f = {}; for (const m of e) { const c = this._activeDirtyManagerService.get(m.id); if (c == null) continue; const s = c.getDirtyData(m), { dirtyRanges: P, dirtyNameMap: E, dirtyDefinedNameMap: p, dirtyUnitFeatureMap: R, dirtyUnitOtherFormulaMap: S, clearDependencyTreeCache: N } = s; P != null && this._mergeDirtyRanges(n, P), E != null && this._mergeDirtyNameMap(i, E), p != null && this._mergeDirtyNameMap(r, p), R != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(o, R), S != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(u, S), N != null && this._mergeDirtyNameMap(f, N); } return { dirtyRanges: n, dirtyNameMap: i, dirtyDefinedNameMap: r, dirtyUnitFeatureMap: o, dirtyUnitOtherFormulaMap: u, forceCalculation: !1, clearDependencyTreeCache: f, maxIteration: this._configService.getConfig(ea) // numfmtItemMap, }; } _mergeDirty(e, n) { const i = [...e.dirtyRanges, ...n.dirtyRanges], r = { ...e.dirtyNameMap }, o = { ...e.dirtyDefinedNameMap }, u = { ...e.dirtyUnitFeatureMap }, f = { ...e.dirtyUnitOtherFormulaMap }, m = { ...e.clearDependencyTreeCache }; this._mergeDirtyNameMap(r, n.dirtyNameMap), this._mergeDirtyNameMap(o, n.dirtyDefinedNameMap), this._mergeDirtyUnitFeatureOrOtherFormulaMap(u, n.dirtyUnitFeatureMap), this._mergeDirtyUnitFeatureOrOtherFormulaMap(f, n.dirtyUnitOtherFormulaMap), this._mergeDirtyNameMap(m, n.clearDependencyTreeCache); const c = e.maxIteration || n.maxIteration; return { dirtyRanges: i, dirtyNameMap: r, dirtyDefinedNameMap: o, dirtyUnitFeatureMap: u, dirtyUnitOtherFormulaMap: f, forceCalculation: !!this._forceCalculating, clearDependencyTreeCache: m, maxIteration: c }; } /** * dirtyRanges may overlap with the ranges in allDirtyRanges and need to be deduplicated * @param allDirtyRanges * @param dirtyRanges */ _mergeDirtyRanges(e, n) { for (const i of n) { let r = !1; for (const o of e) if (i.unitId === o.unitId && i.sheetId === o.sheetId) { const { startRow: u, startColumn: f, endRow: m, endColumn: c } = i.range, { startRow: s, startColumn: P, endRow: E, endColumn: p } = o.range; if (u === s && f === P && m === E && c === p) { r = !0; break; } } r || e.push(i); } } _mergeDirtyNameMap(e, n) { Object.keys(n).forEach((i) => { e[i] == null && (e[i] = {}), Object.keys(n[i]).forEach((r) => { var o; (o = n[i]) != null && o[r] && (e[i][r] = n[i][r]); }); }); } _mergeDirtyUnitFeatureOrOtherFormulaMap(e, n) { Object.keys(n).forEach((i) => { e[i] == null && (e[i] = {}), Object.keys(n[i]).forEach((r) => { e[i][r] == null && (e[i][r] = {}), Object.keys(n[i][r]).forEach((o) => { e[i][r][o] = n[i][r][o] || !1; }); }); }); } // eslint-disable-next-line max-lines-per-function _initialExecuteFormulaProcessListener() { let e = null, n = 0; this.disposeWithMe( // eslint-disable-next-line max-lines-per-function, complexity this._commandService.onCommandExecuted((i) => { if (i.id === Ie.id) { const { forceCalculation: o = !1 } = i.params; o && (this._forceCalculating = !0); } else i.id === Jt.id && this.clearProgress(); if (i.id !== bn.id) return; const r = i.params; if (r.stageInfo != null) { const { stage: o } = r.stageInfo; if (o === Fe.START) n === 0 && (this._startExecutionTime = performance.now()), n++, e !== null && (clearTimeout(e), e = null), e = setTimeout(() => { e = null, this._startProgress(); }, 1e3); else if (o === Fe.CURRENTLY_CALCULATING) { if (this._executionInProgressParams = r.stageInfo, e === null) { const u = this._localeService.t("formula.progress.calculating"); this._calculateProgress(u); } } else if (o === Fe.START_DEPENDENCY_ARRAY_FORMULA) { if (this._executionInProgressParams = r.stageInfo, e === null) { const u = this._localeService.t("formula.progress.array-analysis"); this._calculateProgress(u); } } else if (o === Fe.CURRENTLY_CALCULATING_ARRAY_FORMULA && (this._executionInProgressParams = r.stageInfo, e === null)) { const u = this._localeService.t("formula.progress.array-calculation"); this._calculateProgress(u); } } else { const o = r.functionsExecutedState; let u = ""; switch (n--, o) { case De.NOT_EXECUTED: u = "No tasks are being executed anymore", this._resetExecutingDirtyData(); break; case De.STOP_EXECUTION: u = "The execution of the formula has been stopped", n = 0; break; case De.SUCCESS: u = "Formula calculation succeeded", (n === 0 || n === -1) && (u += `. Total time consumed: ${performance.now() - this._startExecutionTime} ms`), this._resetExecutingDirtyData(); break; case De.INITIAL: u = "Waiting for calculation", this._resetExecutingDirtyData(); break; } (n === 0 || n === -1) && (e ? (clearTimeout(e), e = null, this.clearProgress()) : this._completeProgress(), n = 0, this._doneCalculationTaskCount = 0, this._totalCalculationTaskCount = 0, this._forceCalculating = !1), o === De.STOP_EXECUTION && this._restartCalculation ? (this._restartCalculation = !1, this._commandService.executeCommand( Ie.id, { ...this._executingDirtyData }, pt )) : this._executionInProgressParams = null, this._logService.debug("[TriggerCalculationController]", u); } }) ); } _resetExecutingDirtyData() { this._executingDirtyData = { dirtyRanges: [], dirtyNameMap: {}, dirtyDefinedNameMap: {}, dirtyUnitFeatureMap: {}, dirtyUnitOtherFormulaMap: {}, forceCalculation: !1, clearDependencyTreeCache: {} }; } _initialExecuteFormula() { const e = this._getCalculationMode(), n = this._getDirtyDataByCalculationMode(e); this._commandService.executeCommand(Ie.id, n, pt), this._registerOtherFormulaService.calculateStarted$.next(!0); } _getDirtyDataByCalculationMode(e) { const n = e === Le.FORCED, i = e === Le.WHEN_EMPTY ? this._formulaDataModel.getFormulaDirtyRanges() : []; return { forceCalculation: n, dirtyRanges: i, dirtyNameMap: {}, dirtyDefinedNameMap: {}, dirtyUnitFeatureMap: {}, dirtyUnitOtherFormulaMap: {}, clearDependencyTreeCache: {}, maxIteration: this._configService.getConfig(ea) }; } }; xe = ui([ de(0, ce), de(1, ht), de(2, Qa), de(3, Ce), de(4, X(ot)), de(5, X(_t)), de(6, X(Qe)) ], xe); function mi(a, e, n) { var i; return a == null || a[e] == null || ((i = a[e]) == null ? void 0 : i[n]) == null; } function Lt(a, e, n) { var i; if (n) { if (a && a[e] && ((i = a[e]) != null && i[n])) return delete a[e][n], { [e]: { [n]: null } }; } else if (a && a[e]) return delete a[e], { [e]: null }; } var y = /* @__PURE__ */ ((a) => (a[a.MoveRange = 0] = "MoveRange", a[a.MoveRows = 1] = "MoveRows", a[a.MoveCols = 2] = "MoveCols", a[a.InsertRow = 3] = "InsertRow", a[a.InsertColumn = 4] = "InsertColumn", a[a.RemoveRow = 5] = "RemoveRow", a[a.RemoveColumn = 6] = "RemoveColumn", a[a.DeleteMoveLeft = 7] = "DeleteMoveLeft", a[a.DeleteMoveUp = 8] = "DeleteMoveUp", a[a.InsertMoveDown = 9] = "InsertMoveDown", a[a.InsertMoveRight = 10] = "InsertMoveRight", a[a.SetName = 11] = "SetName", a[a.RemoveSheet = 12] = "RemoveSheet", a[a.SetDefinedName = 13] = "SetDefinedName", a[a.RemoveDefinedName = 14] = "RemoveDefinedName", a))(y || {}); const fi = [ 11, 12, 13, 14 /* RemoveDefinedName */ ]; function ci(a, e, n) { const { type: i } = n; return fi.includes(i) ? li(a, e) : si(a, e, n); } function li(a, e) { const n = [], i = []; return Object.keys(e).forEach((r) => { const o = e[r], u = a[r]; if (o == null || u == null) return !0; Object.keys(o).forEach((f) => { const m = new G(o[f] || {}), c = new G(u[f] || {}), s = new G(), P = new G(); if (m.forValue((N, d, D) => { if (D == null) return !0; const I = qe(D); I !== null && (s.setValue(N, d, I), P.setValue(N, d, c.getValue(N, d))); }), s.getSizeOf() === 0) return; const E = { subUnitId: f, unitId: r, cellValue: s.getMatrix() }, p = { id: Z.id, params: E }; i.push(p); const R = { subUnitId: f, unitId: r, cellValue: P.getMatrix() }, S = { id: Z.id, params: R }; n.push(S); }); }), { undos: n, redos: i }; } function si(a, e, n) { const { redoFormulaData: i, undoFormulaData: r } = di(a, e, n), o = [], u = []; return Object.keys(i).forEach((f) => { Object.keys(i[f]).forEach((m) => { if (Object.keys(i[f][m]).length !== 0) { const c = { subUnitId: m, unitId: f, cellValue: i[f][m] }, s = { id: Z.id, params: c }; o.push(s); } }); }), Object.keys(r).forEach((f) => { Object.keys(r[f]).forEach((m) => { if (Object.keys(r[f][m]).length !== 0) { const c = { subUnitId: m, unitId: f, cellValue: r[f][m] }, s = { id: Z.id, params: c }; u.push(s); } }); }), { undos: u, redos: o }; } function di(a, e, n) { const i = {}, r = {}, { unitId: o, sheetId: u } = n; return (/* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(e)])).forEach((m) => { if (mi(a, m, u)) return; (/* @__PURE__ */ new Set([ ...Object.keys(a[m] || {}), ...Object.keys(e[m] || {}) ])).forEach((s) => { var D, I; const P = (D = a[m]) == null ? void 0 : D[s], E = (I = e[m]) == null ? void 0 : I[s], p = new G(P || {}), R = new G(E || {}); let S = []; m !== o || s !== u ? S = Li(R) : S = pi(p, n); const N = xi(S, p, R), d = _i(S, p); i[m] || (i[m] = {}), r[m] || (r[m] = {}), i[m][s] = { ...i[m][s], ...N }, r[m][s] = { ...r[m][s], ...d }; }); }), { redoFormulaData: i, undoFormulaData: r }; } function pi(a, e) { const { type: n, from: i, to: r, range: o } = e, u = []; return a.forValue((f, m, c) => { if (c == null || !Ba(c)) return !0; const s = da(f, m); let P = null, E = !1; if ([ 0, 1, 2 /* MoveCols */ ].includes(n)) P = Pi(n, i, r, s); else if (o != null) { const p = Ti(s, e); P = p.newCell, E = p.isReverse; } E ? u.unshift({ oldCell: s, newCell: P }) : u.push({ oldCell: s, newCell: P }); }), u; } function Li(a) { const e = []; return a.forValue((n, i, r) => { if (r == null || !Ba(r)) return !0; const o = da(n, i); e.push({ oldCell: o, newCell: o }); }), e; } function Pi(a, e, n, i) { if (e == null || n == null) return null; switch (a) { case 0: return Ei(e, n, i); case 1: return Ii(e, n, i); case 2: return Ni(e, n, i); default: return null; } } function Ti(a, e) { const { type: n, rangeFilteredRows: i } = e, r = e.range; let o = null, u = !1; switch (n) { case 3: o = Ri(r, a), u = !0; break; case 4: o = Si(r, a), u = !0; break; case 5: o = Ai(r, a, i); break; case 6: o = Ci(r, a); break; case 7: o = Di(r, a); break; case 8: o = bi(r, a); break; case 9: o = Oi(r, a), u = !0; break; case 10: o = Mi(r, a), u = !0; break; } return { newCell: o, isReverse: u }; } function Ei(a, e, n) { const i = Sa( { id: H.MoveRangeCommandId, params: { toRange: e, fromRange: a } }, n ); return w(i, n); } function Ii(a, e, n) { const i = Ra( { id: H.MoveRowsCommandId, params: { toRange: e, fromRange: a } }, n ); return w(i, n); } function Ni(a, e, n) { const i = Na( { id: H.MoveColsCommandId, params: { toRange: e, fromRange: a } }, n ); return w(i, n); } function Ri(a, e) { const n = _a( { id: H.InsertRowCommandId, params: { range: a, unitId: "", subUnitId: "", direction: Xe.DOWN } }, e ); return w(n, e); } function Si(a, e) { const n = xa( { id: H.InsertColCommandId, params: { range: a, unitId: "", subUnitId: "", direction: Xe.RIGHT } }, e ); return w(n, e); } function Ai(a, e, n) { const i = Ma( { id: H.RemoveRowCommandId, params: { range: a } }, e, n ); return w(i, e); } function Ci(a, e) { const n = Oa( { id: H.RemoveColCommandId, params: { range: a } }, e ); return w(n, e); } function Di(a, e) { const n = ba( { id: H.DeleteRangeMoveLeftCommandId, params: { range: a } }, e ); return w(n, e); } function bi(a, e) { const n = Da( { id: H.DeleteRangeMoveUpCommandId, params: { range: a } }, e ); return w(n, e); } function Oi(a, e) { const n = Ca( { id: H.InsertRangeMoveDownCommandId, params: { range: a } }, e ); return w(n, e); } function Mi(a, e) { const n = Aa( { id: H.InsertRangeMoveRightCommandId, params: { range: a } }, e ); return w(n, e); } function xi(a, e, n) { var r, o, u; const i = new G({}); for (let f = 0; f < a.length; f++) { const { oldCell: m, newCell: c } = a[f]; if ((r = i.getValue(m.startRow, m.startColumn)) != null && r.f || (o = i.getValue(m.startRow, m.startColumn)) != null && o.si || i.setValue(m.startRow, m.startColumn, { f: null, si: null }), c) { const s = (u = n.getValue(m.startRow, m.startColumn)) != null ? u : e.getValue(m.startRow, m.startColumn), P = qe(s); i.setValue(c.startRow, c.startColumn, P); } } return i.getMatrix(); } function _i(a, e) { const n = new G({}); for (let i = a.length - 1; i >= 0; i--) { const { oldCell: r, newCell: o } = a[i], u = e.getValue(r.startRow, r.startColumn), f = qe(u); if (n.setValue(r.startRow, r.startColumn, f), o) { const m = e.getValue(o.startRow, o.startColumn), c = qe(m); n.setValue(o.startRow, o.startColumn, c != null ? c : { f: null, si: null }); } } return n.getMatrix(); } function qe(a) { if (a == null) return; const { f: e, si: n, x: i = 0, y: r = 0 } = a, o = Me(e), u = sa(n); if (!o && !u) return { f: null, si: null }; const f = {}; return u && (f.si = n), o && i === 0 && r === 0 && (f.f = e), f.f === void 0 && (f.f = null), f.si === void 0 && (f.si = null), f; } function yi(a) { const e = new G({}); return new G(a).forValue((i, r, o) => { const u = qe(o); u && e.setValue(i, r, u); }), e.getMatrix(); } function Ba(a) { const e = (a == null ? void 0 : a.f) || "", n = (a == null ? void 0 : a.si) || "", i = Me(e), r = sa(n); return !!(i || r); } function va(a, e, n, i, r, o) { if ((r == null || r.length === 0) && (o == null || o.length === 0)) { if (a === n && e === i) return !0; } else if ((a === r || r == null || r.length === 0) && e === o) return !0; return !1; } function Va(a, e, n = 0, i = 0) { const r = []; for (let o = 0, u = a.length; o < u; o++) { const f = a[o]; if (typeof f == "string" || f.nodeType !== ee.REFERENCE || e.includes(o)) { r.push(f); continue; } const { token: m } = f, c = pe(m), { range: s, sheetName: P, unitId: E } = c, p = fe.moveOffset(s, n, i); r.push({ ...f, token: ut({ range: p, unitId: E, sheetName: P }) }); } return r; } function Ga(a, e, n, i) { const { type: r, unitId: o, sheetId: u, range: f, from: m, to: c, rangeFilteredRows: s } = e, { range: P, sheetId: E, unitId: p, sheetName: R, refOffsetX: S, refOffsetY: N } = a; if (!va( o, u, n, i, p, E )) return; const d = fe.moveOffset(P, S, N); let D = null; if (r === y.MoveRange) { if (m == null || c == null) return; const I = Tt(d, m), T = Ye(d, m); if (T == null || I !== 4) return; const g = Sa( { id: H.MoveRangeCommandId, params: { toRange: c, fromRange: m } }, T ), h = w(g, T); if (h == null) return j.REF; D = Pt(I, h, m, c, d, T); } else if (r === y.MoveRows) { if (m == null || c == null) return; const I = Tt(d, m); let T = Ye(d, m); if (T == null && (m.endRow < d.startRow && c.endRow <= d.startRow || m.startRow > d.endRow && c.startRow > d.endRow)) return; T == null && (T = { startRow: d.startRow, endRow: d.endRow, startColumn: d.startColumn, endColumn: d.endColumn, rangeType: Y.NORMAL }); const g = Ra( { id: H.MoveRowsCommandId, params: { toRange: c, fromRange: m } }, T ), h = w(g, T); if (h == null) return j.REF; D = Pt(I, h, m, c, d, T); } else if (r === y.MoveCols) { if (m == null || c == null) return; const I = Tt(d, m); let T = Ye(d, m); if (T == null && (m.endColumn < d.startColumn && c.endColumn <= d.startColumn || m.startColumn > d.endColumn && c.startColumn > d.endColumn)) return; T == null && (T = { startRow: d.startRow, endRow: d.endRow, startColumn: d.startColumn, endColumn: d.endColumn, rangeType: Y.NORMAL }); const g = Na( { id: H.MoveColsCommandId, params: { toRange: c, fromRange: m } }, T ), h = w(g, T); if (h == null) return j.REF; D = Pt(I, h, m, c, d, T); } if (f != null) { if (r === y.InsertRow) { const I = _a( { id: H.InsertRowCommandId, params: { range: f, unitId: "", subUnitId: "", direction: Xe.DOWN } }, d ), T = w(I, d); if (T == null) return; D = { ...d, ...T }; } else if (r === y.InsertColumn) { const I = xa( { id: H.InsertColCommandId, params: { range: f, unitId: "", subUnitId: "", direction: Xe.RIGHT } }, d ), T = w(I, d); if (T == null) return; D = { ...d, ...T }; } else if (r === y.RemoveRow) { const I = Ma( { id: H.RemoveRowCommandId, params: { range: f } }, d, s ), T = w(I, d); if (T == null) return j.REF; D = { ...d, ...T }; } else if (r === y.RemoveColumn) { const I = Oa( { id: H.RemoveColCommandId, params: { range: f } }, d ), T = w(I, d); if (T == null) return j.REF; D = { ...d, ...T }; } else if (r === y.DeleteMoveLeft) { const I = ba( { id: H.DeleteRangeMoveLeftCommandId, params: { range: f } }, d ), T = w(I, d); if (T == null) return j.REF; D = { ...d, ...T }; } else if (r === y.DeleteMoveUp) { const I = Da( { id: H.DeleteRangeMoveUpCommandId, params: { range: f } }, d ), T = w(I, d); if (T == null) return j.REF; D = { ...d, ...T }; } else if (r === y.InsertMoveDown) { const I = Ca( { id: H.InsertRangeMoveDownCommandId, params: { range: f } }, d ), T = w(I, d); if (T == null) return; D = { ...d, ...T }; } else if (r === y.InsertMoveRight) { const I = Aa( { id: H.InsertRangeMoveRightCommandId, params: { range: f } }, d ), T = w(I, d); if (T == null) return; D = { ...d, ...T }; } } if (D != null) return ut({ range: D, sheetName: R, unitId: p }); } function Pt(a, e, n, i, r, o) { const { startRow: u, endRow: f, startColumn: m, endColumn: c, rangeType: s } = be(e), { startRow: P, startColumn: E, endRow: p, endColumn: R, rangeType: S = Y.NORMAL } = be(n), { startRow: N, startColumn: d, endRow: D, endColumn: I } = be(i), { startRow: T, endRow: g, startColumn: h, endColumn: B } = be(o), { startRow: q, endRow: M, startColumn: U, endColumn: V, rangeType: Q = Y.NORMAL } = be(r), O = { ...r }; function Pe() { return s === Y.COLUMN && Q === Y.COLUMN ? !0 : m >= U && c <= V; } function ne() { return s === Y.ROW && Q === Y.ROW ? !0 : u >= q && f <= M; } if (a === 0) if (Pe()) if (u < q) O.startRow = u; else if (u >= M) O.endRow -= p + 1 - q; else return; else return; else if (a === 1) if (Pe()) if (f > M) O.endRow = f; else if (f <= q) O.startRow += M - P + 1; else return; else return; else if (a === 2) if (ne()) if (m < U) O.startColumn = m; else if (m >= V) O.endColumn -= R + 1 - U; else return; else return; else if (a === 3) if (ne()) if (c > V) O.endColumn = c; else if (c <= U) O.startColumn += V - E + 1; else return; else return; else a === 4 ? (O.startRow = u, O.startColumn = m, O.endRow = f, O.endColumn = c) : E <= U && R >= V || S === Y.ROW && Q === Y.ROW ? n.endRow < q ? (N >= q && (O.startRow -= p - P + 1), N >= M && (O.endRow -= p - P + 1)) : n.startRow > M ? (D <= M && (O.endRow += p - P + 1), D <= q && (O.startRow += p - P + 1)) : n.startRow >= q && n.endRow <= M && (N <= q ? O.startRow += p - P + 1 : N >= M && (O.endRow -= p - P + 1)) : P <= q && p >= M || S === Y.COLUMN && Q === Y.COLUMN ? n.endColumn < U ? (d >= U && (O.startColumn -= R - E + 1), d >= V && (O.endColumn -= R - E + 1)) : n.startColumn > V ? (I <= V && (O.endColumn += R - E + 1), I <= U && (O.startColumn += R - E + 1)) : n.startColumn >= U && n.endColumn <= V && (d <= U ? O.startColumn += R - E + 1 : d >= V && (O.endColumn -= R - E + 1)) : ((d <= B + 1 && I >= V || d <= U && I >= h - 1) && N <= q && D >= M || (N <= g + 1 && D >= M || N <= q && D >= T - 1) && d <= U && I >= V, O.startRow = u, O.startColumn = m, O.endRow = f, O.endColumn = c); return O; } function Tt(a, e) { const n = Re(a.startRow), i = Se(a.endRow), r = Re(a.startColumn), o = Se(a.endColumn), u = Re(e.startRow), f = Se(e.endRow), m = Re(e.startColumn), c = Se(e.endColumn); function s() { return a.rangeType === Y.COLUMN && e.rangeType === Y.COLUMN ? !0 : n >= u && i <= f; } function P() { return a.rangeType === Y.ROW && e.rangeType === Y.ROW ? !0 : r >= m && o <= c; } function E() { return a.rangeType === Y.ALL && e.rangeType === Y.ALL; } return s() && P() || E() ? 4 : P() && n >= u && n <= f && i > f ? 0 : P() && i >= u && i <= f && n < u ? 1 : s() && r >= m && r <= c && o > c ? 2 : s() && o >= m && o <= c && r < m ? 3 : null; } function Re(a) { return isNaN(a) ? -1 / 0 : a; } function Se(a) { return isNaN(a) ? 1 / 0 : a; } function be(a) { const { startRow: e, endRow: n, startColumn: i, endColumn: r } = a; return { ...a, startRow: Re(e), endRow: Se(n), startColumn: Re(i), endColumn: Se(r) }; } function Ha(a, e) { const { id: n } = e; let i = null; switch (n) { case Pn.id: i = qi(e, a); break; case Ln.id: i = gi(e, a); break; case pn.id: i = hi(e, a); break; case dn.id: i = Ui(e); break; case sn.id: i = Fi(e); break; case ln.id: i = Bi(e, a); break; case cn.id: i = vi(e, a); break; case fn.id: i = Vi(e, a); break; case mn.id: i = Gi(e, a); break; case un.id: i = Hi(e, a); break; case on.id: i = wi(e, a); break; case rn.id: i = Yi(e, a); break; case nn.id: i = Xi(e, a); break; case qa.id: i = Wi(e, a); break; case ya.id: i = Ki(e, a); break; } return i; } function J(a) { var i; const e = a.getUnitId(), n = ((i = a.getActiveSheet()) == null ? void 0 : i.getSheetId()) || ""; return { unitId: e, sheetId: n }; } function qi(a, e) { const { params: n } = a; if (!n) return null; const { fromRange: i, toRange: r } = n; if (!i || !r) return null; const { unitId: o, sheetId: u } = J(e); return { type: y.MoveRange, from: i, to: r, unitId: o, sheetId: u }; } function gi(a, e) { const { params: n } = a; if (!n) return null; const { fromRange: { startRow: i, endRow: r }, toRange: { startRow: o, endRow: u } } = n, f = e.getUnitId(), m = e.getActiveSheet(); if (!m) return null; const c = m.getSheetId(), s = { startRow: i, startColumn: 0, endRow: r, endColumn: m.getColumnCount() - 1, rangeType: Y.ROW }, P = { startRow: o, startColumn: 0, endRow: u, endColumn: m.getColumnCount() - 1, rangeType: Y.ROW }; return { type: y.MoveRows, from: s, to: P, unitId: f, sheetId: c }; } function hi(a, e) { const { params: n } = a; if (!n) return null; const { fromRange: { startColumn: i, endColumn: r }, toRange: { startColumn: o, endColumn: u } } = n, f = e.getUnitId(), m = e.getActiveSheet(); if (!m) return null; const c = m.getSheetId(), s = { startRow: 0, startColumn: i, endRow: m.getRowCount() - 1, endColumn: r, rangeType: Y.COLUMN }, P = { startRow: 0, startColumn: o, endRow: m.getRowCount() - 1, endColumn: u, rangeType: Y.COLUMN }; return { type: y.MoveCols, from: s, to: P, unitId: f, sheetId: c }; } function Ui(a) { const { params: e } = a; if (!e) return null; const { range: n, unitId: i, subUnitId: r } = e; return { type: y.InsertRow, range: n, unitId: i, sheetId: r }; } function Fi(a) { const { params: e } = a; if (!e) return null; const { range: n, unitId: i, subUnitId: r } = e; return { type: y.InsertColumn, range: n, unitId: i, sheetId: r }; } function Bi(a, e) { const { params: n } = a; if (!n) return null; const { range: i } = n, { unitId: r, sheetId: o } = J(e); return { type: y.InsertMoveRight, range: i, unitId: r, sheetId: o }; } function vi(a, e) { const { params: n } = a; if (!n) return null; const { range: i } = n, { unitId: r, sheetId: o } = J(e); return { type: y.InsertMoveDown, range: i, unitId: r, sheetId: o }; } function Vi(a, e) { var u, f; const { params: n } = a; if (!n) return null; const { range: i } = n, { unitId: r, sheetId: o } = J(e); return { type: y.RemoveRow, range: i, unitId: r, sheetId: o, rangeFilteredRows: (f = (u = e.getSheetBySheetId(o)) == null ? void 0 : u.getRangeFilterRows(i)) != null ? f : [] }; } function Gi(a, e) { const { params: n } = a; if (!n) return null; const { range: i } = n, { unitId: r, sheetId: o } = J(e); return { type: y.RemoveColumn, range: i, unitId: r, sheetId: o }; } function Hi(a, e) { const { params: n } = a; if (!n) return null; const { range: i } = n, { unitId: r, sheetId: o } = J(e); return { type: y.DeleteMoveUp, range: i, unitId: r, sheetId: o }; } function wi(a, e) { const { params: n } = a; if (!n) return null; const { range: i } = n, { unitId: r, sheetId: o } = J(e); return { type: y.DeleteMoveLeft, range: i, unitId: r, sheetId: o }; } function Yi(a, e) { const { params: n } = a; if (!n) return null; const { unitId: i, subUnitId: r, name: o } = n, { unitId: u, sheetId: f } = J(e); return { type: y.SetName, unitId: i || u, sheetId: r || f, sheetName: o }; } function Xi(a, e) { const { params: n } = a; if (!n) return null; const { unitId: i, subUnitId: r } = n, { unitId: o, sheetId: u } = J(e); return { type: y.RemoveSheet, unitId: i || o, sheetId: r || u }; } function Wi(a, e) { const { params: n } = a; if (!n) return null; const { unitId: i, name: r, id: o } = n, { sheetId: u } = J(e); return { type: y.SetDefinedName, unitId: i, sheetId: u, definedName: r, definedNameId: o }; } function Ki(a, e) { const { params: n } = a; if (!n) return null; const { unitId: i, name: r, id: o } = n, { sheetId: u } = J(e); return { type: y.RemoveDefinedName, unitId: i, sheetId: u, definedName: r, definedNameId: o }; } var ki = Object.getOwnPropertyDescriptor, Qi = (a, e, n, i) => { for (var r = i > 1 ? void 0 : i ? ki(e, n) : e, o = a.length - 1, u; o >= 0; o--) (u = a[o]) && (r = u(r) || r); return r; }, ve = (a, e) => (n, i) => e(n, i, a); let $e = class extends ae { constructor(a, e, n, i) { super(), this._definedNamesService = a, this._univerInstanceService = e, this._sheetInterceptorService = n, this._lexerTreeBuilder = i, this._initialize(); } _initialize() { this._commandExecutedListener(); } _commandExecutedListener() { this.disposeWithMe( this._sheetInterceptorService.interceptCommand({ getMutations: (a) => { if (a.id === qa.id || a.id === ya.id) return { redos: [], undos: [] }; const e = this._univerInstanceService.getCurrentUnitForType(te.UNIVER_SHEET); if (e == null) return { redos: [], undos: [] }; const n = Ha(e, a); return n ? this._getUpdateDefinedNameMutations(e, n) : { redos: [], undos: [] }; } }) ); } // eslint-disable-next-line max-lines-per-function _getUpdateDefinedNameMutations(a, e) { const { type: n, unitId: i, sheetId: r } = e, o = this._definedNamesService.getDefinedNameMap(i); if (!o) return { redos: [], undos: [] }; const u = [], f = []; return Object.values(o).forEach((m) => { var N; const { formulaOrRefString: c } = m, s = this._lexerTreeBuilder.sequenceNodesBuilder(c); if (s == null) return !0; let P = !1; const E = []; for (let d = 0, D = s.length; d < D; d++) { const I = s[d]; if (typeof I == "string" || I.nodeType !== ee.REFERENCE) continue; const { token: T } = I, g = pe(T), { range: h, sheetName: B, unitId: q } = g, M = ((N = a.getSheetBySheetName(B)) == null ? void 0 : N.getSheetId()) || "", U = { range: h, sheetId: M, unitId: q, sheetName: B, refOffsetX: 0, refOffsetY: 0 }; let V = null; if (n === y.RemoveSheet) V = this._removeSheet(m, i, r); else if (n === y.SetName) { const { sheetId: Q, sheetName: O } = e; if (O == null || M == null || M.length === 0 || Q !== M) continue; V = ut({ range: h, sheetName: O, unitId: q }); } else V = Ga( U, e, i, r ); V != null && (s[d] = { ...I, token: V }, P = !0, E.push(d)); } if (!P) return !0; const p = ke(Va(s, E)), R = { id: ye.id, params: { unitId: i, ...m, formulaOrRefString: p } }; u.push(R); const S = { id: ye.id, params: { unitId: i, ...m } }; f.push(S); }), { redos: u, undos: f }; } _removeSheet(a, e, n) { var o; const { formulaOrRefString: i