@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,605 lines • 527 kB
JavaScript
var Wa = Object.defineProperty;
var Ka = (a, e, n) => e in a ? Wa(a, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[e] = n;
var K = (a, e, n) => Ka(a, typeof e != "symbol" ? e + "" : e, n);
import { CommandType as ca, ICommandService as ue, ObjectMatrix as V, generateRandomId as la, IUniverInstanceService as Ee, Rectangle as fe, sequenceExecuteAsync as ka, Inject as H, Disposable as ee, CellValueType as xt, createDocumentModelWithStyle as Qa, WrapTextType as ja, PositionedObjectLayoutType as $a, BooleanNumber as za, ObjectRelativeFromV as Za, ObjectRelativeFromH as Ja, ImageSourceType as en, DrawingTypeEnum as tn, BuildTextUtils as an, InterceptorEffectEnum as _t, ILogService as nn, IConfigService as Ce, LocaleService as Gt, isFormulaString as Me, isFormulaId as sa, cellToRange as da, Tools as Xe, Direction as Ke, getIntersectRange as We, RANGE_TYPE as X, UniverInstanceType as $, Injector as ct, isRealNum as rn, createIdentifier as Ht, toDisposable as J, moveRangeByOffset as yt, DisposableCollection as ke, AbsoluteRefType as Qe, Optional as on, DependentOn as pa, Plugin as La, merge as Pa, touchDependencies as Ue, isNodeEnv as Xt } from "@univerjs/core";
import { SetRangeValuesCommand as Ta, SheetsSelectionsService as un, getSheetCommandTarget as mn, findFirstNonEmptyCell as fn, alignToMergedCellsBorders as It, expandToContinuousRange as cn, SetSelectionsOperation as ln, SheetInterceptorService as lt, INTERCEPTOR_POINT as Ea, InterceptCellContentPriority as sn, SetRangeValuesMutation as Q, SetStyleCommand as wt, SetBorderCommand as Ia, ClearSelectionFormatCommand as Na, handleMoveCols as Ra, EffectRefRangId as w, runRefRangeMutations as Y, handleMoveRows as Sa, handleMoveRange as Aa, handleInsertRangeMoveRight as Ca, handleInsertRangeMoveDown as Da, handleDeleteRangeMoveUp as ba, handleDeleteRangeMoveLeft as Oa, handleIRemoveCol as Ma, handleIRemoveRow as xa, handleInsertCol as _a, handleInsertRow as ya, RemoveDefinedNameCommand as ga, SetDefinedNameCommand as qa, RemoveSheetCommand as dn, SetWorksheetNameCommand as pn, DeleteRangeMoveLeftCommand as Ln, DeleteRangeMoveUpCommand as Pn, RemoveColCommand as Tn, RemoveRowCommand as En, InsertRangeMoveDownCommand as In, InsertRangeMoveRightCommand as Nn, InsertColCommand as Rn, InsertRowCommand as Sn, MoveColsCommand as An, MoveRowsCommand as Cn, MoveRangeCommand as Dn, RemoveSheetMutation as gt, InsertSheetMutation as qt, MoveRangeMutation as Wt, MoveRowsMutation as Kt, MoveColsMutation as kt, ReorderRangeMutation as Qt, RemoveRowMutation as jt, RemoveColMutation as $t, InsertColMutation as zt, InsertRowMutation as Zt, SetRowHiddenMutation as Jt, SetRowVisibleMutation as ea, SetWorksheetActiveOperation as ha, SCOPE_WORKBOOK_VALUE_DEFINED_NAME as Nt, RefRangeService as bn, handleDefaultRangeChangeWithEffectRefCommands as ta, getSeparateEffectedRangesOnCommand as On, handleCommonDefaultRangeChangeWithEffectRefCommands as Mn, UniverSheetsPlugin as xn } from "@univerjs/sheets";
import { serializeRange as Se, FormulaDataModel as ye, ErrorType as k, SetImageFormulaDataMutation as _n, IActiveDirtyManagerService as Ua, RegisterOtherFormulaService as yn, SetFormulaCalculationStartMutation as Fe, SetFormulaStringBatchCalculationMutation as gn, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE as qn, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as hn, SetFormulaCalculationStopMutation as aa, SetFormulaCalculationNotificationMutation as Un, FormulaExecuteStageType as Be, FormulaExecutedStateType as be, SetTriggerFormulaCalculationStartMutation as je, sequenceNodeType as ie, deserializeRangeWithSheetWithCache as Pe, serializeRangeToRefString as st, IDefinedNamesService as dt, LexerTreeBuilder as pt, generateStringWithSequence as $e, SetDefinedNameMutation as Ae, SetFormulaDataMutation as ve, SetArrayFormulaDataMutation as ht, initSheetFormulaData as na, RemoveDefinedNameMutation as Ut, IFunctionService as Lt, SetFormulaCalculationResultMutation as Fn, stripErrorMargin as Bn, FunctionType as t, FUNCTION_NAMES_ARRAY as ia, FUNCTION_NAMES_COMPATIBILITY as _, FUNCTION_NAMES_CUBE as de, FUNCTION_NAMES_DATABASE as j, FUNCTION_NAMES_DATE as v, FUNCTION_NAMES_ENGINEERING as C, FUNCTION_NAMES_FINANCIAL as D, FUNCTION_NAMES_INFORMATION as G, FUNCTION_NAMES_LOGICAL as W, FUNCTION_NAMES_LOOKUP as g, FUNCTION_NAMES_MATH as T, FUNCTION_NAMES_STATISTICAL as s, FUNCTION_NAMES_TEXT as b, FUNCTION_NAMES_WEB as Rt, isReferenceStrings as vn, functionArray as Vn, functionCompatibility as Gn, functionCube as Hn, functionDatabase as wn, functionDate as Yn, functionEngineering as Xn, functionFinancial as Wn, functionInformation as Kn, functionLogical as kn, functionLookup as Qn, functionMath as jn, functionMeta as $n, functionStatistical as zn, functionText as Zn, functionUniver as Jn, functionWeb as ei, OtherFormulaMarkDirty as ti, SetSuperTableMutation as ai, RemoveSuperTableMutation as ni, serializeRangeWithSheet as ze, ISuperTableService as ii, serializeRangeWithSpreadsheet as ra, CustomFunction as Ft, AsyncCustomFunction as Fa, UniverFormulaEnginePlugin as ri, IFormulaCurrentConfigService as oi, Lexer as ui, AstTreeBuilder as mi, Interpreter as fi, generateExecuteAstNodeData as ci, getObjectValue as li } from "@univerjs/engine-formula";
import { BehaviorSubject as si, map as di } from "rxjs";
import { IRPCChannelService as Ba, fromModule as pi, toModule as Li } from "@univerjs/rpc";
const Pi = {
id: "formula.command.insert-function",
type: ca.COMMAND,
handler: async (a, e) => {
const { list: n, listOfRangeHasNumber: i } = e, r = a.get(ue), o = new V();
n.forEach((f) => {
const { range: m, primary: c, formula: l } = f, { row: L, column: E } = c, p = la(6);
o.setValue(L, E, {
f: l,
si: p
});
const { startRow: S, startColumn: A, endRow: I, endColumn: d } = m;
for (let R = S; R <= I; R++)
for (let N = A; N <= d; N++)
(R !== L || N !== E) && o.setValue(R, N, {
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);
}
}, Ti = {
id: "sheets-formula.command.quick-sum",
type: ca.COMMAND,
handler: async (a) => {
const n = a.get(un).getCurrentLastSelection();
if (!n) return !1;
const i = a.get(Ee), r = mn(i);
if (!r) return !1;
const o = n.range, { worksheet: u } = r;
let f = fn(o, u);
if (!f) return !1;
f = It(f, u);
const m = cn({
startRow: f.startRow,
startColumn: f.startColumn,
endRow: o.endRow,
endColumn: o.endColumn
}, { left: !0, right: !0, up: !0, down: !0 }, u), c = new V(), l = It({
startRow: m.endRow,
endRow: m.endRow,
startColumn: m.startColumn,
endColumn: m.endColumn
}, u);
if (!fe.equals(l, m))
for (const p of u.iterateByColumn(l))
(!p.value || !u.cellHasValue(p.value)) && c.setValue(p.row, p.col, {
f: `=SUM(${Se({
startColumn: p.col,
endColumn: p.col,
startRow: m.startRow,
endRow: p.row - 1
})})`
});
const L = It({
startRow: m.startRow,
startColumn: m.endColumn,
endRow: m.endRow,
endColumn: m.endColumn
}, u);
if (!fe.equals(L, m))
for (const p of u.iterateByRow(L))
(!p.value || !u.cellHasValue(p.value)) && c.setValue(p.row, p.col, {
f: `=SUM(${Se({
startColumn: m.startColumn,
endColumn: p.col - 1,
startRow: p.row,
endRow: p.row
})})`
});
const E = a.get(ue);
return (await ka([
{
id: Ta.id,
params: {
range: m,
value: c.getMatrix()
}
},
{
id: ln.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;
}
}, ge = "sheets-formula.base.config";
var Te = /* @__PURE__ */ ((a) => (a[a.FORCED = 0] = "FORCED", a[a.WHEN_EMPTY = 1] = "WHEN_EMPTY", a[a.NO_CALCULATION = 2] = "NO_CALCULATION", a))(Te || {});
const oa = {}, Ei = "sheets-formula.remote.config", ua = {};
var Ii = Object.getOwnPropertyDescriptor, Ni = (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;
}, St = (a, e) => (n, i) => e(n, i, a);
let Ze = class extends ee {
constructor(e, n, i) {
super();
K(this, "_errorValueCell", {
v: k.VALUE,
t: xt.STRING
});
K(this, "_refreshRender");
this._commandService = e, this._sheetInterceptorService = n, this._formulaDataModel = i, this._initialize();
}
_initialize() {
this._commandExecutedListener(), this._initInterceptorCellContent();
}
_commandExecutedListener() {
this.disposeWithMe(
this._commandService.onCommandExecuted(async (e) => {
if (e.id === _n.id) {
const n = e.params;
if (!n) return;
const { imageFormulaData: i } = n;
if (!i || i.length === 0) return;
const r = await Promise.all(
i.map((u) => this._getImageNatureSize(u))
), o = {};
r.forEach((u) => {
const { unitId: f, sheetId: m, row: c, column: l, ...L } = u;
o[f] || (o[f] = {}), o[f][m] || (o[f][m] = new V()), o[f][m].setValue(c, l, L);
}), this._formulaDataModel.mergeUnitImageFormulaData(o), this._refreshRender();
}
})
);
}
// eslint-disable-next-line max-lines-per-function
_initInterceptorCellContent() {
this.disposeWithMe(
this._sheetInterceptorService.intercept(Ea.CELL_CONTENT, {
priority: sn.CELL_IMAGE,
effect: _t.Value | _t.Style,
// eslint-disable-next-line max-lines-per-function
handler: (e, n, i) => {
var q, M;
const { unitId: r, subUnitId: o, row: u, col: f } = n, m = this._formulaDataModel.getUnitImageFormulaData(), c = (M = (q = m == null ? void 0 : m[r]) == null ? void 0 : q[o]) == null ? void 0 : M.getValue(u, f);
if (!c)
return i(e);
const {
source: l,
// altText,
// sizing,
height: L,
width: E,
isErrorImage: p,
imageNaturalWidth: S,
imageNaturalHeight: A
} = c;
if (p)
return i(this._errorValueCell);
const I = E || S, d = L || A, R = Qa("", {}), N = {
unitId: r,
subUnitId: o,
drawingId: la(),
drawingType: tn.DRAWING_IMAGE,
imageSourceType: en.URL,
source: l,
transform: {
left: 0,
top: 0,
width: I,
height: d
},
docTransform: {
size: {
width: I,
height: d
},
positionH: {
relativeFrom: Ja.PAGE,
posOffset: 0
},
positionV: {
relativeFrom: Za.PARAGRAPH,
posOffset: 0
},
angle: 0
},
behindDoc: za.FALSE,
title: "",
description: "",
layoutType: $a.INLINE,
// Insert inline drawing by default.
wrapText: ja.BOTH_SIDES,
distB: 0,
distL: 0,
distR: 0,
distT: 0
}, P = an.drawing.add({
documentDataModel: R,
drawings: [N],
selection: {
collapsed: !0,
startOffset: 0,
endOffset: 0
}
});
return P ? (R.apply(P), i({
...e,
p: R.getSnapshot()
})) : i(this._errorValueCell);
}
})
);
}
async _getImageNatureSize(e) {
const n = await this._getImageSize(e.source);
return n.image ? {
...e,
isErrorImage: !1,
imageNaturalHeight: n.height,
imageNaturalWidth: n.width
} : { ...e, isErrorImage: !0 };
}
async _getImageSize(e) {
return new Promise((n) => {
const i = new Image();
i.src = e, i.onload = () => {
n({
width: i.width,
height: i.height,
image: i
});
}, i.onerror = () => {
n({
width: 0,
height: 0,
image: null
});
};
});
}
registerRefreshRenderFunction(e) {
this._refreshRender = e;
}
};
Ze = Ni([
St(0, ue),
St(1, H(lt)),
St(2, H(ye))
], Ze);
var Ri = Object.getOwnPropertyDescriptor, Si = (a, e, n, i) => {
for (var r = i > 1 ? void 0 : i ? Ri(e, n) : e, o = a.length - 1, u; o >= 0; o--)
(u = a[o]) && (r = u(r) || r);
return r;
}, pe = (a, e) => (n, i) => e(n, i, a);
const ma = { done: 0, count: 0 }, At = { onlyLocal: !0 };
let xe = class extends ee {
constructor(e, n, i, r, o, u, f) {
super();
K(this, "_waitingCommandQueue", []);
K(this, "_executingDirtyData", {
forceCalculation: !1,
dirtyRanges: [],
dirtyNameMap: {},
dirtyDefinedNameMap: {},
dirtyUnitFeatureMap: {},
dirtyUnitOtherFormulaMap: {},
clearDependencyTreeCache: {}
});
K(this, "_setTimeoutKey", -1);
K(this, "_startExecutionTime", 0);
K(this, "_totalCalculationTaskCount", 0);
K(this, "_doneCalculationTaskCount", 0);
K(this, "_executionInProgressParams", null);
K(this, "_restartCalculation", !1);
K(this, "_progress$", new si(ma));
K(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(ma), 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 : Te.WHEN_EMPTY;
}
_commandExecutedListener() {
this.disposeWithMe(
this._commandService.beforeCommandExecuted((e) => {
if (e.id === Fe.id || e.id === gn.id) {
const n = e.params;
if (e.id === Fe.id) {
const i = this._configService.getConfig(qn) || !1;
n.isCalculateTreeModel = i;
}
n.maxIteration = this._configService.getConfig(hn), n.rowData = this._formulaDataModel.getHiddenRowsFiltered();
}
})
), this.disposeWithMe(
this._commandService.onCommandExecuted((e, n) => {
if (this._activeDirtyManagerService.get(e.id)) {
if (e.id === Q.id) {
const i = e.params;
if (n && n.onlyLocal === !0 || i.trigger === wt.id || i.trigger === Ia.id || i.trigger === Na.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(Fe.id, { ...this._executingDirtyData }, At) : (this._restartCalculation = !0, this._commandService.executeCommand(aa.id, {})), this._waitingCommandQueue = [];
}, 100);
}
})
);
}
_generateDirty(e) {
const n = [], i = {}, r = {}, o = {}, u = {}, f = {};
let m = !1;
for (const c of e) {
const l = this._activeDirtyManagerService.get(c.id);
if (l == null)
continue;
const L = l.getDirtyData(c), { dirtyRanges: E, dirtyNameMap: p, dirtyDefinedNameMap: S, dirtyUnitFeatureMap: A, dirtyUnitOtherFormulaMap: I, clearDependencyTreeCache: d, forceCalculation: R = !1 } = L;
E != null && this._mergeDirtyRanges(n, E), p != null && this._mergeDirtyNameMap(i, p), S != null && this._mergeDirtyNameMap(r, S), A != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(o, A), I != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(u, I), d != null && this._mergeDirtyNameMap(f, d), m = m || R;
}
return {
dirtyRanges: n,
dirtyNameMap: i,
dirtyDefinedNameMap: r,
dirtyUnitFeatureMap: o,
dirtyUnitOtherFormulaMap: u,
forceCalculation: m,
clearDependencyTreeCache: f
// 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.forceCalculation || n.forceCalculation;
return {
dirtyRanges: i,
dirtyNameMap: r,
dirtyDefinedNameMap: o,
dirtyUnitFeatureMap: u,
dirtyUnitOtherFormulaMap: f,
forceCalculation: c,
clearDependencyTreeCache: m
};
}
/**
* 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: l, startColumn: L, endRow: E, endColumn: p } = o.range;
if (u === l && f === L && 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 === aa.id && this.clearProgress(), i.id !== Un.id)
return;
const r = i.params;
if (r.stageInfo != null) {
const {
stage: o
} = r.stageInfo;
if (o === Be.START)
n === 0 && (this._startExecutionTime = performance.now()), n++, e !== null && (clearTimeout(e), e = null), e = setTimeout(() => {
e = null, this._startProgress();
}, 1e3);
else if (o === Be.CURRENTLY_CALCULATING) {
if (this._executionInProgressParams = r.stageInfo, e === null) {
const u = this._localeService.t("formula.progress.calculating");
this._calculateProgress(u);
}
} else if (o === Be.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 === Be.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 be.NOT_EXECUTED:
u = "No tasks are being executed anymore", this._resetExecutingDirtyData();
break;
case be.STOP_EXECUTION:
u = "The execution of the formula has been stopped", n = 0;
break;
case be.SUCCESS:
u = "Formula calculation succeeded", (n === 0 || n === -1) && (u += `. Total time consumed: ${performance.now() - this._startExecutionTime} ms`), this._resetExecutingDirtyData();
break;
case be.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), o === be.STOP_EXECUTION && this._restartCalculation ? (this._restartCalculation = !1, this._commandService.executeCommand(
Fe.id,
{
...this._executingDirtyData
},
At
)) : 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(je.id, n, At), this._registerOtherFormulaService.calculateStarted$.next(!0);
}
_getDirtyDataByCalculationMode(e) {
const n = e === Te.FORCED, i = e === Te.WHEN_EMPTY ? this._formulaDataModel.getFormulaDirtyRanges() : [];
return {
forceCalculation: n,
dirtyRanges: i,
dirtyNameMap: {},
dirtyDefinedNameMap: {},
dirtyUnitFeatureMap: {},
dirtyUnitOtherFormulaMap: {},
clearDependencyTreeCache: {}
};
}
};
xe = Si([
pe(0, ue),
pe(1, Ua),
pe(2, nn),
pe(3, Ce),
pe(4, H(ye)),
pe(5, H(Gt)),
pe(6, H(yn))
], xe);
function Ai(a, e, n) {
var i;
return a == null || a[e] == null || ((i = a[e]) == null ? void 0 : i[n]) == null;
}
function Ct(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 Ci = [
11,
12,
13,
14
/* RemoveDefinedName */
];
function Di(a, e, n) {
const { type: i } = n;
return Ci.includes(i) ? bi(a, e) : Oi(a, e, n);
}
function bi(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 V(o[f] || {}), c = new V(u[f] || {}), l = new V(), L = new V();
if (m.forValue((I, d, R) => {
if (R == null)
return !0;
const N = _e(R);
N !== null && (l.setValue(I, d, N), L.setValue(I, d, c.getValue(I, d)));
}), l.getSizeOf() === 0)
return;
const E = {
subUnitId: f,
unitId: r,
cellValue: l.getMatrix()
}, p = {
id: Q.id,
params: E
};
i.push(p);
const S = {
subUnitId: f,
unitId: r,
cellValue: L.getMatrix()
}, A = {
id: Q.id,
params: S
};
n.push(A);
});
}), {
undos: n,
redos: i
};
}
function Oi(a, e, n) {
const { redoFormulaData: i, undoFormulaData: r } = Mi(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]
}, l = {
id: Q.id,
params: c
};
o.push(l);
}
});
}), 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]
}, l = {
id: Q.id,
params: c
};
u.push(l);
}
});
}), {
undos: u,
redos: o
};
}
function Mi(a, e, n) {
const i = {}, r = {}, { unitId: o, sheetId: u } = n;
return (/* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(e)])).forEach((m) => {
if (Ai(a, m, u))
return;
(/* @__PURE__ */ new Set([
...Object.keys(a[m] || {}),
...Object.keys(e[m] || {})
])).forEach((l) => {
var R, N;
const L = (R = a[m]) == null ? void 0 : R[l], E = (N = e[m]) == null ? void 0 : N[l], p = new V(L || {}), S = new V(E || {});
let A = [];
m !== o || l !== u ? A = _i(S) : A = xi(p, S, n);
const I = Xi(A, p, S), d = Wi(A, p);
i[m] || (i[m] = {}), r[m] || (r[m] = {}), i[m][l] = {
...i[m][l],
...I
}, r[m][l] = {
...r[m][l],
...d
};
});
}), {
redoFormulaData: i,
undoFormulaData: r
};
}
function xi(a, e, n) {
const { type: i, from: r, to: o, range: u } = n, f = [];
return a.forValue((m, c, l) => {
if (l == null || !va(l)) return !0;
const L = da(m, c);
let E = null, p = !1;
if ([
0,
1,
2
/* MoveCols */
].includes(i))
E = yi(i, r, o, L);
else if (u != null) {
const S = gi(L, n);
E = S.newCell, p = S.isReverse;
}
if (Xe.diffValue(L, E) && !e.getValue(m, c))
return !0;
p ? f.unshift({ oldCell: L, newCell: E }) : f.push({ oldCell: L, newCell: E });
}), f;
}
function _i(a) {
const e = [];
return a.forValue((n, i, r) => {
if (r == null || !va(r)) return !0;
const o = da(n, i);
e.push({ oldCell: o, newCell: o });
}), e;
}
function yi(a, e, n, i) {
if (e == null || n == null)
return null;
switch (a) {
case 0:
return qi(e, n, i);
case 1:
return hi(e, n, i);
case 2:
return Ui(e, n, i);
default:
return null;
}
}
function gi(a, e) {
const { type: n, rangeFilteredRows: i } = e, r = e.range;
let o = null, u = !1;
switch (n) {
case 3:
o = Fi(r, a), u = !0;
break;
case 4:
o = Bi(r, a), u = !0;
break;
case 5:
o = vi(r, a, i);
break;
case 6:
o = Vi(r, a);
break;
case 7:
o = Gi(r, a);
break;
case 8:
o = Hi(r, a);
break;
case 9:
o = wi(r, a), u = !0;
break;
case 10:
o = Yi(r, a), u = !0;
break;
}
return { newCell: o, isReverse: u };
}
function qi(a, e, n) {
const i = Aa(
{
id: w.MoveRangeCommandId,
params: { toRange: e, fromRange: a }
},
n
);
return Y(i, n);
}
function hi(a, e, n) {
const i = Sa(
{
id: w.MoveRowsCommandId,
params: { toRange: e, fromRange: a }
},
n
);
return Y(i, n);
}
function Ui(a, e, n) {
const i = Ra(
{
id: w.MoveColsCommandId,
params: { toRange: e, fromRange: a }
},
n
);
return Y(i, n);
}
function Fi(a, e) {
const n = ya(
{
id: w.InsertRowCommandId,
params: { range: a, unitId: "", subUnitId: "", direction: Ke.DOWN }
},
e
);
return Y(n, e);
}
function Bi(a, e) {
const n = _a(
{
id: w.InsertColCommandId,
params: { range: a, unitId: "", subUnitId: "", direction: Ke.RIGHT }
},
e
);
return Y(n, e);
}
function vi(a, e, n) {
const i = xa(
{
id: w.RemoveRowCommandId,
params: { range: a }
},
e,
n
);
return Y(i, e);
}
function Vi(a, e) {
const n = Ma(
{
id: w.RemoveColCommandId,
params: { range: a }
},
e
);
return Y(n, e);
}
function Gi(a, e) {
const n = Oa(
{
id: w.DeleteRangeMoveLeftCommandId,
params: { range: a }
},
e
);
return Y(n, e);
}
function Hi(a, e) {
const n = ba(
{
id: w.DeleteRangeMoveUpCommandId,
params: { range: a }
},
e
);
return Y(n, e);
}
function wi(a, e) {
const n = Da(
{
id: w.InsertRangeMoveDownCommandId,
params: { range: a }
},
e
);
return Y(n, e);
}
function Yi(a, e) {
const n = Ca(
{
id: w.InsertRangeMoveRightCommandId,
params: { range: a }
},
e
);
return Y(n, e);
}
function Xi(a, e, n) {
var r, o, u;
const i = new V({});
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 l = (u = n.getValue(m.startRow, m.startColumn)) != null ? u : e.getValue(m.startRow, m.startColumn), L = _e(l);
i.setValue(c.startRow, c.startColumn, L);
}
}
return i.getMatrix();
}
function Wi(a, e) {
const n = new V({});
for (let i = a.length - 1; i >= 0; i--) {
const { oldCell: r, newCell: o } = a[i], u = e.getValue(r.startRow, r.startColumn), f = _e(u);
if (n.setValue(r.startRow, r.startColumn, f), o) {
const m = e.getValue(o.startRow, o.startColumn), c = _e(m);
n.setValue(o.startRow, o.startColumn, c != null ? c : { f: null, si: null });
}
}
return n.getMatrix();
}
function _e(a) {
if (a == null)
return {
f: null,
si: null
};
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 Ki(a) {
const e = new V({});
return new V(a).forValue((i, r, o) => {
const u = _e(o);
u !== void 0 && e.setValue(i, r, u);
}), e.getMatrix();
}
function va(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 Ga(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 !== ie.REFERENCE || e.includes(o)) {
r.push(f);
continue;
}
const { token: m } = f, c = Pe(m), { range: l, sheetName: L, unitId: E } = c, p = fe.moveOffset(l, n, i);
r.push({
...f,
token: st({
range: p,
unitId: E,
sheetName: L
})
});
}
return r;
}
function Ha(a, e, n, i) {
const { type: r, unitId: o, sheetId: u, range: f, from: m, to: c, rangeFilteredRows: l } = e, {
range: L,
sheetId: E,
unitId: p,
sheetName: S,
refOffsetX: A,
refOffsetY: I
} = a;
if (!Va(
o,
u,
n,
i,
p,
E
))
return;
const d = fe.moveOffset(L, A, I);
let R = null;
if (r === y.MoveRange) {
if (m == null || c == null)
return;
const N = bt(d, m), P = We(d, m);
if (P == null || N !== 4)
return;
const q = Aa(
{ id: w.MoveRangeCommandId, params: { toRange: c, fromRange: m } },
P
), M = Y(q, P);
if (M == null)
return k.REF;
R = Dt(N, M, m, c, d, P);
} else if (r === y.MoveRows) {
if (m == null || c == null)
return;
const N = bt(d, m);
let P = We(d, m);
if (P == null && (m.endRow < d.startRow && c.endRow <= d.startRow || m.startRow > d.endRow && c.startRow > d.endRow))
return;
P == null && (P = {
startRow: d.startRow,
endRow: d.endRow,
startColumn: d.startColumn,
endColumn: d.endColumn,
rangeType: X.NORMAL
});
const q = Sa(
{ id: w.MoveRowsCommandId, params: { toRange: c, fromRange: m } },
P
), M = Y(q, P);
if (M == null)
return k.REF;
R = Dt(N, M, m, c, d, P);
} else if (r === y.MoveCols) {
if (m == null || c == null)
return;
const N = bt(d, m);
let P = We(d, m);
if (P == null && (m.endColumn < d.startColumn && c.endColumn <= d.startColumn || m.startColumn > d.endColumn && c.startColumn > d.endColumn))
return;
P == null && (P = {
startRow: d.startRow,
endRow: d.endRow,
startColumn: d.startColumn,
endColumn: d.endColumn,
rangeType: X.NORMAL
});
const q = Ra(
{ id: w.MoveColsCommandId, params: { toRange: c, fromRange: m } },
P
), M = Y(q, P);
if (M == null)
return k.REF;
R = Dt(N, M, m, c, d, P);
}
if (f != null) {
if (r === y.InsertRow) {
const N = ya(
{
id: w.InsertRowCommandId,
params: { range: f, unitId: "", subUnitId: "", direction: Ke.DOWN }
},
d
), P = Y(N, d);
if (P == null)
return;
R = {
...d,
...P
};
} else if (r === y.InsertColumn) {
const N = _a(
{
id: w.InsertColCommandId,
params: { range: f, unitId: "", subUnitId: "", direction: Ke.RIGHT }
},
d
), P = Y(N, d);
if (P == null)
return;
R = {
...d,
...P
};
} else if (r === y.RemoveRow) {
const N = xa(
{
id: w.RemoveRowCommandId,
params: { range: f }
},
d,
l
), P = Y(N, d);
if (P == null)
return k.REF;
R = {
...d,
...P
};
} else if (r === y.RemoveColumn) {
const N = Ma(
{
id: w.RemoveColCommandId,
params: { range: f }
},
d
), P = Y(N, d);
if (P == null)
return k.REF;
R = {
...d,
...P
};
} else if (r === y.DeleteMoveLeft) {
const N = Oa(
{
id: w.DeleteRangeMoveLeftCommandId,
params: { range: f }
},
d
), P = Y(N, d);
if (P == null)
return k.REF;
R = {
...d,
...P
};
} else if (r === y.DeleteMoveUp) {
const N = ba(
{
id: w.DeleteRangeMoveUpCommandId,
params: { range: f }
},
d
), P = Y(N, d);
if (P == null)
return k.REF;
R = {
...d,
...P
};
} else if (r === y.InsertMoveDown) {
const N = Da(
{
id: w.InsertRangeMoveDownCommandId,
params: { range: f }
},
d
), P = Y(N, d);
if (P == null)
return;
R = {
...d,
...P
};
} else if (r === y.InsertMoveRight) {
const N = Ca(
{
id: w.InsertRangeMoveRightCommandId,
params: { range: f }
},
d
), P = Y(N, d);
if (P == null)
return;
R = {
...d,
...P
};
}
}
if (R != null)
return st({
range: R,
sheetName: S,
unitId: p
});
}
function Dt(a, e, n, i, r, o) {
const { startRow: u, endRow: f, startColumn: m, endColumn: c, rangeType: l } = Oe(e), {
startRow: L,
startColumn: E,
endRow: p,
endColumn: S,
rangeType: A = X.NORMAL
} = Oe(n), { startRow: I, startColumn: d, endRow: R, endColumn: N } = Oe(i), {
startRow: P,
endRow: q,
startColumn: M,
endColumn: U
} = Oe(o), {
startRow: h,
endRow: x,
startColumn: F,
endColumn: B,
rangeType: ae = X.NORMAL
} = Oe(r), O = { ...r };
function ce() {
return l === X.COLUMN && ae === X.COLUMN ? !0 : m >= F && c <= B;
}
function ne() {
return l === X.ROW && ae === X.ROW ? !0 : u >= h && f <= x;
}
if (a === 0)
if (ce())
if (u < h)
O.startRow = u;
else if (u >= x)
O.endRow -= p + 1 - h;
else
return;
else
return;
else if (a === 1)
if (ce())
if (f > x)
O.endRow = f;
else if (f <= h)
O.startRow += x - L + 1;
else
return;
else
return;
else if (a === 2)
if (ne())
if (m < F)
O.startColumn = m;
else if (m >= B)
O.endColumn -= S + 1 - F;
else
return;
else
return;
else if (a === 3)
if (ne())
if (c > B)
O.endColumn = c;
else if (c <= F)
O.startColumn += B - E + 1;
else
return;
else
return;
else a === 4 ? (O.startRow = u, O.startColumn = m, O.endRow = f, O.endColumn = c) : E <= F && S >= B || A === X.ROW && ae === X.ROW ? n.endRow < h ? (I >= h && (O.startRow -= p - L + 1), I >= x && (O.endRow -= p - L + 1)) : n.startRow > x ? (R <= x && (O.endRow += p - L + 1), R <= h && (O.startRow += p - L + 1)) : n.startRow >= h && n.endRow <= x && (I <= h ? O.startRow += p - L + 1 : I >= x && (O.endRow -= p - L + 1)) : L <= h && p >= x || A === X.COLUMN && ae === X.COLUMN ? n.endColumn < F ? (d >= F && (O.startColumn -= S - E + 1), d >= B && (O.endColumn -= S - E + 1)) : n.startColumn > B ? (N <= B && (O.endColumn += S - E + 1), N <= F && (O.startColumn += S - E + 1)) : n.startColumn >= F && n.endColumn <= B && (d <= F ? O.startColumn += S - E + 1 : d >= B && (O.endColumn -= S - E + 1)) : ((d <= U + 1 && N >= B || d <= F && N >= M - 1) && I <= h && R >= x || (I <= q + 1 && R >= x || I <= h && R >= P - 1) && d <= F && N >= B, O.startRow = u, O.startColumn = m, O.endRow = f, O.endColumn = c);
return O;
}
function bt(a, e) {
const n = Ne(a.startRow), i = Re(a.endRow), r = Ne(a.startColumn), o = Re(a.endColumn), u = Ne(e.startRow), f = Re(e.endRow), m = Ne(e.startColumn), c = Re(e.endColumn);
function l() {
return a.rangeType === X.COLUMN && e.rangeType === X.COLUMN ? !0 : n >= u && i <= f;
}
function L() {
return a.rangeType === X.ROW && e.rangeType === X.ROW ? !0 : r >= m && o <= c;
}
function E() {
return a.rangeType === X.ALL && e.rangeType === X.ALL;
}
return l() && L() || E() ? 4 : L() && n >= u && n <= f && i > f ? 0 : L() && i >= u && i <= f && n < u ? 1 : l() && r >= m && r <= c && o > c ? 2 : l() && o >= m && o <= c && r < m ? 3 : null;
}
function Ne(a) {
return isNaN(a) ? -1 / 0 : a;
}
function Re(a) {
return isNaN(a) ? 1 / 0 : a;
}
function Oe(a) {
const { startRow: e, endRow: n, startColumn: i, endColumn: r } = a;
return {
...a,
startRow: Ne(e),
endRow: Re(n),
startColumn: Ne(i),
endColumn: Re(r)
};
}
function wa(a, e) {
const { id: n } = e;
let i = null;
switch (n) {
case Dn.id:
i = ki(e, a);
break;
case Cn.id:
i = Qi(e, a);
break;
case An.id:
i = ji(e, a);
break;
case Sn.id:
i = $i(e);
break;
case Rn.id:
i = zi(e);
break;
case Nn.id:
i = Zi(e, a);
break;
case In.id:
i = Ji(e, a);
break;
case En.id:
i = er(e, a);
break;
case Tn.id:
i = tr(e, a);
break;
case Pn.id:
i = ar(e, a);
break;
case Ln.id:
i = nr(e, a);
break;
case pn.id:
i = ir(e, a);
break;
case dn.id:
i = rr(e, a);
break;
case qa.id:
i = or(e, a);
break;
case ga.id:
i = ur(e, a);
break;
}
return i;
}
function te(a) {
var i;
const e = a.getUnitId(), n = ((i = a.getActiveSheet()) == null ? void 0 : i.getSheetId()) || "";
return {
unitId: e,
sheetId: n
};
}
function ki(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 } = te(e);
return {
type: y.MoveRange,
from: i,
to: r,
unitId: o,
sheetId: u
};
}
function Qi(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(), l = {
startRow: i,
startColumn: 0,
endRow: r,
endColumn: m.getColumnCount() - 1,
rangeType: X.ROW
}, L = {
startRow: o,
startColumn: 0,
endRow: u,
endColumn: m.getColumnCount() - 1,
rangeType: X.ROW
};
return {
type: y.MoveRows,
from: l,
to: L,
unitId: f,
sheetId: c
};
}
function ji(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(), l = {
startRow: 0,
startColumn: i,
endRow: m.getRowCount() - 1,
endColumn: r,
rangeType: X.COLUMN
}, L = {
startRow: 0,
startColumn: o,
endRow: m.getRowCount() - 1,
endColumn: u,
rangeType: X.COLUMN
};
return {
type: y.MoveCols,
from: l,
to: L,
unitId: f,
sheetId: c
};
}
function $i(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 zi(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 Zi(a, e) {
const { params: n } = a;
if (!n) return null;
const { range: i } = n, { unitId: r, sheetId: o } = te(e);
return {
type: y.InsertMoveRight,
range: i,
unitId: r,
sheetId: o
};
}
function Ji(a, e) {
const { params: n } = a;
if (!n) return null;
const { range: i } = n, { unitId: r, sheetId: o } = te(e);
return {
type: y.InsertMoveDown,
range: i,
unitId: r,
sheetId: o
};
}
function er(a, e) {
var u, f;
const { params: n } = a;
if (!n) return null;
const { range: i } = n, { unitId: r, sheetId: o } = te(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 tr(a, e) {
const { params: n } = a;
if (!n) return null;
const { range: i } = n, { unitId: r, sheetId: o } = te(e);
return {
type: y.RemoveColumn,
range: i,
unitId: r,
sheetId: o
};
}
function ar(a, e) {
const { params: n } = a;
if (!n) return null;
const { range: i } = n, { unitId: r, sheetId: o } = te(e);
return {
type: y.DeleteMoveUp,
range: i,
unitId: r,
sheetId: o
};
}
function nr(a, e) {
const { params: n } = a;
if (!n) return null;
const { range: i } = n, { unitId: r, sheetId: o } = te(e);
return {
type: y.DeleteMoveLeft,
range: i,
unitId: r,
sheetId: o
};
}
function ir(a, e) {
const { params: n } = a;
if (!n) return null;
const { unitId: i, subUnitId: r, name: o } = n, { unitId: u, sheetId: f } = te(e);
return {
type: y.SetName,
unitId: i || u,
sheetId: r || f,
sheetName: o
};
}
function rr(a, e) {
const { params: n } = a;
if (!n) return null;
const { unitId: i, subUnitId: r } = n, { unitId: o, sheetId: u } = te(e);
return {
type: y.RemoveSheet,
unitId: i || o,
sheetId: r || u
};
}
function or(a, e) {
const { params: n } = a;
if (!n) return null;
const { unitId: i, name: r, id: o } = n, { sheetId: u } = te(e);
return {
type: y.SetDefinedName,
unitId: i,
sheetId: u,
definedName: r,
definedNameId: o
};
}
function ur(a, e) {
const { params: n } = a;
if (!n) return null;
const { unitId: i, name: r, id: o } = n, { sheetId: u } = te(e);
return {
type: y.RemoveDefinedName,
unitId: i,
sheetId: u,
definedName: r,
definedNameId: o
};
}
var mr = Object.getOwnPropertyDescriptor, fr = (a, e, n, i) => {
for (var r = i > 1 ? void 0 : i ? mr(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 Je = class extends ee {
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 === ga.id)
return {
redos: [],
undos: []
};
const e = this._univerInstanceService.getCurrentUnitForType($.UNIVER_SHEET);
if (e == null)
return {
redos: [],
undos: []
};
const n = wa(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 I;
const { formulaOrRefString: c } = m, l = this._lexerTreeBuilder.sequenceNodesBuilder(c);
if (l == null)
return !0;
let L = !1;
const E = [];
for (let d = 0, R = l.length; d < R; d++) {
const N = l[d];
if (typeof N == "string" || N.nodeType !== ie.REFERENCE)
continue;
const { token: P } = N, q = Pe(P), { range: M, sheetName: U, unitId: h } = q, x = ((I = a.getSheetBySheetName(U)) == null ? void 0 : I.getSheetId()) || "", F = {
range: M,
sheetId: x,
unitId: h,
sheetName: U,
refOffsetX: 0,
refOffsetY: 0
};
let B = null;
if (n === y.RemoveSheet)
B = this._removeSheet(m, i, r);
else if (n === y.SetName) {
const {
sheetId: ae,
sheetName: O
} = e;
if (O == null || x == null || x.length === 0 || ae !== x)
continue;
B = st({
range: M,
sheetName: O,
unitId: h
});
} else
B = Ha(
F,
e,
i,
r
);
B != null && (l[d] = {
...N,
token: B
}, L = !0, E.push(d));
}
if (!L)
return !0;
const p = $e(Ga(l, E)), S = {
id: Ae.id,
params: {
unitId: i,
...m,
formulaOrRefString: p
}
};
u.push(S);
const A = {
id: Ae.id,
params: {
unitId: i,
...m
}
};
f.push(A);
}), {
redos: u,
undos: f
};
}
_removeSheet(a, e, n) {
var o;
const { formulaOrRefString: i } = a;
return ((o = this._definedNamesService.getWorksheetByRef(e, i)) == null ? void 0 : o.getSheetId()) === n ? k.REF : null;
}
};
Je = fr([
Ve(0, dt),
Ve(1, Ee),
Ve(2, H(lt)),
Ve(3, H(pt))
], Je);
var cr = Object.getOwnPropertyDescriptor, lr = (a, e, n, i) => {
for (va