var ri = Object.defineProperty; var ii = (n, e, t) => e in n ? ri(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var R = (n, e, t) => ii(n, typeof e != "symbol" ? e + "" : e, t); import { Tools as O, CommandType as v, ICommandService as E, IUndoRedoService as W, createInterceptorKey as rt, Disposable as ae, UniverInstanceType as B, InterceptorEffectEnum as me, InterceptorManager as mo, toDisposable as We, remove as Nt, composeInterceptors as ai, DisposableCollection as jt, IUniverInstanceService as M, HorizontalAlign as ro, BooleanNumber as te, BorderStyleTypes as Rs, Inject as L, IResourceManagerService as nn, RTree as ui, generateRandomId as li, ObjectMatrix as G, RxDisposable as ps, normalizeTextRuns as ci, CellValueType as se, isRealNum as go, isBooleanString as Cs, isSafeNumeric as di, sequenceExecute as z, LocaleService as Ke, createIdentifier as fo, IContextService as Ss, selectionToArray as hi, Rectangle as k, RANGE_TYPE as H, ErrorService as bt, Range as K, cellToRange as ws, PermissionStatus as J, IPermissionService as Fe, isICellData as Is, Dimension as ge, getArrayLength as vs, insertMatrixArray as pn, spliceArray as Ms, sliceMatrixArray as _s, concatMatrixArray as bs, Direction as pe, mergeWorksheetSnapshotWithDefault as mi, moveMatrixArray as ys, BorderType as ue, FontWeight as gi, FontItalic as fi, Injector as Ro, ILogService as Es, DocumentDataModel as Ri, BuildTextUtils as pi, TextX as Ci, Optional as Si, IConfigService as Us, queryObjectMatrix as Je, CustomCommandExecutionError as wi, UserManagerService as Ii, IAuthzIoService as vi, LRUMap as Mi, DependentOn as _i, Plugin as bi, merge as yi, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE as Ei, AUTO_HEIGHT_FOR_MERGED_CELLS as Ui, registerDependencies as Pi, mergeOverrideWithDependencies as Ti, touchDependencies as ln, createRowColIter as ki, CellModeEnum as Ni } from "@univerjs/core"; import { SetDefinedNameMutation as Gt, RemoveDefinedNameMutation as Cn, SetDefinedNameMutationFactory as Oi, SetFormulaCalculationResultMutation as Di, handleNumfmtInCell as Ai, IDefinedNamesService as Ps, stripErrorMargin as xi, LexerTreeBuilder as $i, operatorToken as Wi, deserializeRangeWithSheet as Li, sequenceNodeType as Vi, deserializeRangeWithSheetWithCache as Hi, UniverFormulaEnginePlugin as Bi } from "@univerjs/engine-formula"; import { DataSyncPrimaryController as Fi } from "@univerjs/rpc"; import { Subject as Le, BehaviorSubject as at, merge as xt, shareReplay as ji, takeUntil as io, switchMap as Ge, of as Ot, distinctUntilChanged as Gi, skip as Ts, map as ao, first as zi, filter as Ho } from "rxjs"; import { DEFAULT_TEXT_FORMAT as ks } from "@univerjs/engine-numfmt"; import { takeUntil as Bo, filter as Fo, map as Ki } from "rxjs/operators"; var Ji = /* @__PURE__ */ ((n) => (n.OthersCanView = "othersCanView", n.NoOneElseCanView = "noOneElseCanView", n))(Ji || {}), Yi = /* @__PURE__ */ ((n) => (n.DesignedUserCanEdit = "designedUserCanEdit", n.OnlyMe = "onlyMe", n))(Yi || {}); class de { constructor() { /** * * Map>> */ R(this, "_model", /* @__PURE__ */ new Map()); R(this, "_ruleChange", new Le()); R(this, "ruleChange$", this._ruleChange.asObservable()); R(this, "_ruleRefresh", new Le()); R(this, "ruleRefresh$", this._ruleRefresh.asObservable()); R(this, "_rangeRuleInitStateChange", new at(!1)); R(this, "rangeRuleInitStateChange$", this._rangeRuleInitStateChange.asObservable()); } ruleRefresh(e) { this._ruleRefresh.next(e); } getRangeRuleInitState() { return this._rangeRuleInitStateChange.value; } changeRuleInitState(e) { this._rangeRuleInitStateChange.next(e); } addRule(e, t, o) { this._ensureRuleMap(e, t).set(o.id, o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: o, type: "add" }); } deleteRule(e, t, o) { var r, i, a, u; const s = (i = (r = this._model.get(e)) == null ? void 0 : r.get(t)) == null ? void 0 : i.get(o); s && ((u = (a = this._model.get(e)) == null ? void 0 : a.get(t)) == null || u.delete(o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: s, type: "delete" })); } setRule(e, t, o, s) { var i, a; const r = this.getRule(e, t, o); r && ((a = (i = this._model.get(e)) == null ? void 0 : i.get(t)) == null || a.set(o, s), this._ruleChange.next({ unitId: e, subUnitId: t, oldRule: r, rule: s, type: "set" })); } getRule(e, t, o) { var s, r; return (r = (s = this._model.get(e)) == null ? void 0 : s.get(t)) == null ? void 0 : r.get(o); } getSubunitRuleList(e, t) { var s; return [...(((s = this._model.get(e)) == null ? void 0 : s.get(t)) || /* @__PURE__ */ new Map()).values()]; } getSubunitRuleListLength(e, t) { var s; const o = (s = this._model.get(e)) == null ? void 0 : s.get(t); return o ? o.size : 0; } _ensureRuleMap(e, t) { let o = this._model.get(e); o || (o = /* @__PURE__ */ new Map(), this._model.set(e, o)); let s = o.get(t); return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s; } toObject() { const e = {}; return [...this._model.keys()].forEach((o) => { const s = this._model.get(o), r = [...s.keys()]; e[o] = {}, r.forEach((i) => { const a = s.get(i); e[o][i] = [...a.values()]; }); }), e; } fromObject(e) { const t = /* @__PURE__ */ new Map(); Object.keys(e).forEach((o) => { const s = e[o], r = /* @__PURE__ */ new Map(); Object.keys(s).forEach((i) => { const a = s[i].reduce((u, l) => (u.set(l.id, l), u), /* @__PURE__ */ new Map()); r.set(i, a); }), t.set(o, r); }), this._model = t; } deleteUnitModel(e) { this._model.delete(e); } createRuleId(e, t) { let o = O.generateRandomId(4); const s = this._ensureRuleMap(e, t); for (; s.has(o); ) o = O.generateRandomId(4); return o; } getTargetByPermissionId(e, t) { const o = this._model.get(e); if (!o) return null; for (const [s, r] of o) for (const i of r.values()) if (i.permissionId === t) return [e, s]; return null; } } const Bd = (n, e) => { const t = n.get(de), o = e.ruleIds.map((r) => t.getRule(e.unitId, e.subUnitId, r)).filter((r) => !!r); return { id: Ne.id, params: { subUnitId: e.subUnitId, unitId: e.unitId, rules: o } }; }, ze = { id: "sheet.mutation.delete-range-protection", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, ruleIds: s } = e, r = n.get(de); return s.forEach((i) => { r.deleteRule(t, o, i); }), !0; } }, Fd = (n) => { const e = { ...n, ruleIds: n.rules.map((t) => t.id) }; return { id: ze.id, params: e }; }, Ne = { id: "sheet.mutation.add-range-protection", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, rules: s } = e, r = n.get(de); return s.forEach((i) => { r.addRule(t, o, i); }), !0; } }, Xi = { type: v.COMMAND, id: "sheet.command.add-range-protection", async handler(n, e) { if (!e) return !1; const t = n.get(E), o = n.get(W), s = n.get(de), { rule: r, permissionId: i } = e, { unitId: a, subUnitId: u, ranges: l, description: c, viewState: d, editState: h } = r, m = [{ ranges: l, permissionId: i, id: s.createRuleId(a, u), description: c, unitType: r.unitType, unitId: a, subUnitId: u, viewState: d, editState: h }]; if (await t.executeCommand(Ne.id, { unitId: a, subUnitId: u, rules: m })) { const f = [{ id: Ne.id, params: { unitId: a, subUnitId: u, rules: m } }], p = [{ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: m.map((C) => C.id) } }]; o.pushUndoRedo({ unitID: a, redoMutations: f, undoMutations: p }); } return !0; } }; class Ye { constructor() { /** * * Map>> */ R(this, "_model", /* @__PURE__ */ new Map()); R(this, "_ruleChange", new Le()); R(this, "_ruleRefresh", new Le()); R(this, "_resetOrder", new Le()); R(this, "ruleChange$", this._ruleChange.asObservable()); R(this, "ruleRefresh$", this._ruleRefresh.asObservable()); R(this, "resetOrder$", this._resetOrder.asObservable()); R(this, "_worksheetRuleInitStateChange", new at(!1)); R(this, "worksheetRuleInitStateChange$", this._worksheetRuleInitStateChange.asObservable()); } changeRuleInitState(e) { this._worksheetRuleInitStateChange.next(e); } getSheetRuleInitState() { return this._worksheetRuleInitStateChange.value; } addRule(e, t) { this._ensureSubUnitMap(e).set(t.subUnitId, t), this._ruleChange.next({ unitId: e, rule: t, type: "add", subUnitId: t.subUnitId }); } deleteRule(e, t) { var s, r, i; const o = (r = (s = this._model) == null ? void 0 : s.get(e)) == null ? void 0 : r.get(t); o && ((i = this._model.get(e)) == null || i.delete(t), this._ruleChange.next({ unitId: e, rule: o, type: "delete", subUnitId: t })); } setRule(e, t, o) { var r, i; const s = this.getRule(e, t); s && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.set(t, o), this._ruleChange.next({ unitId: e, oldRule: s, rule: o, type: "set", subUnitId: t })); } getRule(e, t) { var o, s; return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t); } toObject() { const e = {}; return [...this._model.keys()].forEach((o) => { const s = this._model.get(o); s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => { const a = s.get(i); a && e[o].push(a); })); }), e; } fromObject(e) { const t = /* @__PURE__ */ new Map(); Object.keys(e).forEach((o) => { const s = e[o]; if (s != null && s.length) { const r = /* @__PURE__ */ new Map(); s.forEach((i) => { r.set(i.subUnitId, i); }), t.set(o, r); } }), this._model = t; } deleteUnitModel(e) { this._model.delete(e); } _ensureSubUnitMap(e) { let t = this._model.get(e); return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t; } ruleRefresh(e) { this._ruleRefresh.next(e); } resetOrder() { this._resetOrder.next(Math.random()); } getTargetByPermissionId(e, t) { const o = this._model.get(e); if (!o) return null; for (const [s, r] of o) if (r.permissionId === t) return [e, s]; } } const ct = { id: "sheet.mutation.add-worksheet-protection", type: v.MUTATION, handler: (n, e) => { const { unitId: t, rule: o } = e; return n.get(Ye).addRule(t, o), !0; } }, St = { id: "sheet.mutation.delete-worksheet-protection", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o } = e; return n.get(Ye).deleteRule(t, o), !0; } }, qi = { type: v.COMMAND, id: "sheet.command.add-worksheet-protection", async handler(n, e) { if (!e) return !1; const t = n.get(E), o = n.get(W), { rule: s, unitId: r } = e, i = s.subUnitId; if (await t.executeCommand(ct.id, { unitId: r, rule: s, subUnitId: s.subUnitId })) { const u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: s.subUnitId } }], l = [{ id: St.id, params: { unitId: r, subUnitId: i } }]; o.pushUndoRedo({ unitID: r, redoMutations: u, undoMutations: l }); } return !0; } }, Zi = rt("CELL_CONTENT"), Qi = rt("ROW_FILTERED"), et = { CELL_CONTENT: Zi, ROW_FILTERED: Qi }; var ea = /* @__PURE__ */ ((n) => (n[n.DATA_VALIDATION = 9] = "DATA_VALIDATION", n[n.NUMFMT = 10] = "NUMFMT", n[n.CELL_IMAGE = 11] = "CELL_IMAGE", n))(ea || {}); const Ns = "sheet.interceptor.range-theme-id", jo = "sheet.interceptor.ignore-range-theme"; var ta = Object.defineProperty, na = Object.getOwnPropertyDescriptor, oa = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? na(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && ta(e, t, s), s; }, sa = (n, e) => (t, o) => e(t, o, n); const Go = rt("BEFORE_CELL_EDIT"), qn = rt("AFTER_CELL_EDIT"), Zn = rt("AFTER_CELL_EDIT_ASYNC"); let V = class extends ae { /** @ignore */ constructor(e) { super(); R(this, "_interceptorsByName", /* @__PURE__ */ new Map()); R(this, "_commandInterceptors", []); R(this, "_rangeInterceptors", []); R(this, "_beforeCommandInterceptor", []); R(this, "_afterCommandInterceptors", []); R(this, "_workbookDisposables", /* @__PURE__ */ new Map()); R(this, "_worksheetDisposables", /* @__PURE__ */ new Map()); R(this, "_interceptorsDirty", !1); R(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map()); R(this, "writeCellInterceptor", new mo({ BEFORE_CELL_EDIT: Go, AFTER_CELL_EDIT: qn, AFTER_CELL_EDIT_ASYNC: Zn })); this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((t) => { this._interceptWorkbook(t); })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe( (t) => this._disposeWorkbookInterceptor(t) )), this.intercept(et.CELL_CONTENT, { priority: -1, effect: me.Style | me.Value, handler(t, o) { const s = o.worksheet.getCellRaw(o.row, o.col); return t ? { ...s, ...t } : s; } }), this.disposeWithMe(this.writeCellInterceptor.intercept(qn, { priority: -1, handler: (t) => t })), this.disposeWithMe(this.writeCellInterceptor.intercept(Go, { priority: -1, handler: (t) => t })), this.disposeWithMe(this.writeCellInterceptor.intercept(Zn, { priority: -1, handler: (t) => t })); } dispose() { super.dispose(), this._workbookDisposables.forEach((e) => e.dispose()), this._workbookDisposables.clear(), this._worksheetDisposables.clear(), this._interceptorsByName.clear(); } // #region intercept command execution /** * Add a listener function to a specific command to add affiliated mutations. It should be called in controllers. * * Pairs with {@link onCommandExecute}. * * @param interceptor * @returns */ interceptCommand(e) { if (this._commandInterceptors.includes(e)) throw new Error("[SheetInterceptorService]: Interceptor already exists!"); return this._commandInterceptors.push(e), this._commandInterceptors.sort((t, o) => { var s, r; return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0); }), this.disposeWithMe(We(() => Nt(this._commandInterceptors, e))); } /** * When command is executing, call this method to gether undo redo mutations from upper features. * @param command * @returns */ onCommandExecute(e) { const t = this._commandInterceptors.map((o) => o.getMutations(e)); return { preUndos: t.map((o) => { var s; return (s = o.preUndos) != null ? s : []; }).flat(), undos: t.map((o) => o.undos).flat(), preRedos: t.map((o) => { var s; return (s = o.preRedos) != null ? s : []; }).flat(), redos: t.map((o) => o.redos).flat() }; } interceptAfterCommand(e) { if (this._afterCommandInterceptors.includes(e)) throw new Error("[SheetInterceptorService]: Interceptor already exists!"); return this._afterCommandInterceptors.push(e), this._afterCommandInterceptors.sort((t, o) => { var s, r; return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0); }), this.disposeWithMe(We(() => Nt(this._afterCommandInterceptors, e))); } afterCommandExecute(e) { const t = this._afterCommandInterceptors.map((o) => o.getMutations(e)); return { undos: t.map((o) => o.undos).flat(), redos: t.map((o) => o.redos).flat() }; } /** * Add a listener function to a specific command to determine if the command can execute mutations. It should be * called in controllers. * * Pairs with {@link beforeCommandExecute}. * * @param interceptor * @returns */ interceptBeforeCommand(e) { if (this._beforeCommandInterceptor.includes(e)) throw new Error("[SheetInterceptorService]: Interceptor already exists!"); return this._beforeCommandInterceptor.push(e), this._beforeCommandInterceptor.sort((t, o) => { var s, r; return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0); }), this.disposeWithMe(We(() => Nt(this._beforeCommandInterceptor, e))); } /** * before command execute, call this method to get the flag of whether it can be executed the command, * @param info ICommandInfo * @returns Promise */ async beforeCommandExecute(e) { return (await Promise.all(this._beforeCommandInterceptor.map((o) => o.performCheck(e)))).every((o) => o); } // #endregion // #region intercept ranges - mainly for pivot table currently (2024/10/28). /** * By adding callbacks to some Ranges can get some additional mutations, such as clearing all plugin data in a certain area. * @param interceptor IRangeInterceptors * @returns IDisposable */ interceptRanges(e) { if (this._rangeInterceptors.includes(e)) throw new Error("[SheetInterceptorService]: Interceptor already exists!"); return this._rangeInterceptors.push(e), this._rangeInterceptors.sort((t, o) => { var s, r; return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0); }), this.disposeWithMe(We(() => Nt(this._rangeInterceptors, e))); } generateMutationsByRanges(e) { const t = this._rangeInterceptors.map((o) => o.getMutations(e)); return { preUndos: t.map((o) => { var s; return (s = o.preUndos) != null ? s : []; }).flat(), undos: t.map((o) => o.undos).flat(), preRedos: t.map((o) => { var s; return (s = o.preRedos) != null ? s : []; }).flat(), redos: t.map((o) => o.redos).flat() }; } // #endregion // #region intercept on writing cell async onWriteCell(e, t, o, s, r) { const i = { subUnitId: t.getSheetId(), unitId: e.getUnitId(), workbook: e, worksheet: t, row: o, col: s, origin: O.deepClone(r) }, a = this.writeCellInterceptor.fetchThroughInterceptors(qn)(r, i); return await this.writeCellInterceptor.fetchThroughInterceptors(Zn)(Promise.resolve(a), i); } // #endregion intercept(e, t) { const o = e; this._interceptorsByName.has(o) || this._interceptorsByName.set(o, []); const s = this._interceptorsByName.get(o); s.push(t); const r = s.sort((i, a) => { var u, l; return ((u = a.priority) != null ? u : 0) - ((l = i.priority) != null ? l : 0); }); if (o === et.CELL_CONTENT) { this._interceptorsByName.set( `${o}-${me.Style | me.Value}`, r ); const i = me.Style | me.Value; this._interceptorsByName.set( `${o}-${me.Style}`, r.filter((a) => ((a.effect || i) & me.Style) > 0) ), this._interceptorsByName.set( `${o}-${me.Value}`, r.filter((a) => ((a.effect || i) & me.Value) > 0) ); } else this._interceptorsByName.set( o, r ); return this._interceptorsDirty = !0, this.disposeWithMe(We(() => Nt(this._interceptorsByName.get(o), t))); } fetchThroughInterceptors(e, t, o, s) { const r = t === void 0 ? e : `${e}-${t}`, i = o != null ? o : r; let a = this._composedInterceptorByKey.get(i); if (!a || this._interceptorsDirty) { let u = this._interceptorsByName.get(r); u && s && (u = u.filter(s)), a = ai(u || []), this._composedInterceptorByKey.set(i, a); } return a; } _interceptWorkbook(e) { const t = new jt(), o = e.getUnitId(), s = this, r = (i) => { const a = i.getSheetId(); i.__interceptViewModel((u) => { const l = new jt(); s._worksheetDisposables.set(zo(o, i), l), l.add(u.registerCellContentInterceptor({ getCell(c, d, h, m, g) { const f = i.getCellRaw(c, d); return s.fetchThroughInterceptors(et.CELL_CONTENT, h, m, g)( f, { unitId: o, subUnitId: a, row: c, col: d, worksheet: i, workbook: e, rawData: f } ); } })), l.add(u.registerRowFilteredInterceptor({ getRowFiltered(c) { return !!s.fetchThroughInterceptors(et.ROW_FILTERED)( !1, { unitId: o, subUnitId: a, row: c, workbook: e, worksheet: i } ); } })); }); }; e.getSheets().forEach((i) => r(i)), t.add(e.sheetCreated$.subscribe((i) => r(i))), t.add(We(() => e.getSheets().forEach((i) => this._disposeSheetInterceptor(o, i)))), t.add(e.sheetDisposed$.subscribe((i) => this._disposeSheetInterceptor(o, i))), this._workbookDisposables.set(o, t); } _disposeWorkbookInterceptor(e) { const t = e.getUnitId(), o = this._workbookDisposables.get(t); o && (o.dispose(), this._workbookDisposables.delete(t)); } _disposeSheetInterceptor(e, t) { const o = zo(e, t), s = this._worksheetDisposables.get(o); s && (s.dispose(), this._worksheetDisposables.delete(o)); } }; V = oa([ sa(0, M) ], V); function zo(n, e) { return `${n}|${e.getSheetId()}`; } const le = (n) => { const e = {}; return n.bg && (e.bg = { ...n.bg }), n.ol && (e.ol = { ...n.ol }), n.bd && (e.bd = { ...n.bd }), n.cl && (e.cl = { ...n.cl }), n.ht && (e.ht = n.ht), n.vt && (e.vt = n.vt), n.bl !== void 0 && (e.bl = n.bl), e; }; function ra(n) { const e = {}; if (n.length === 1) return n[0]; for (const t of n) t.bg && (e.bg = t.bg), t.ol && (e.ol = t.ol), t.bd && (e.bd = { ...e.bd, ...t.bd }), t.cl && (e.cl = t.cl), t.ht && (e.ht = t.ht), t.vt && (e.vt = t.vt), t.bl !== void 0 && (e.bl = t.bl); return e; } const ce = { wholeStyle: 1, headerRowStyle: 2, headerColumnStyle: 4, firstRowStyle: 8, secondRowStyle: 16, lastRowStyle: 32, firstColumnStyle: 128, secondColumnStyle: 256, lastColumnStyle: 512 }; class yt { /** * @constructor * @param {string} name The name of the range theme style, it used to identify the range theme style. * @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style. */ constructor(e, t) { R(this, "_name"); /** * @property {Nullable} wholeStyle effect for the whole range. */ R(this, "wholeStyle", null); /** * @property {Nullable} headerRowStyle effect for the header row. */ R(this, "headerRowStyle", null); /** * @property {Nullable} headerColumnStyle effect for the header column. */ R(this, "headerColumnStyle", null); /** * @property {Nullable} firstRowStyle effect for the first row. */ R(this, "firstRowStyle", null); /** * @property {Nullable} secondRowStyle effect for the second row. */ R(this, "secondRowStyle", null); /** * @property {Nullable} lastRowStyle effect for the last row. */ R(this, "lastRowStyle", null); /** * @property {Nullable} firstColumnStyle effect for the first column. */ R(this, "firstColumnStyle", null); /** * @property {Nullable} secondColumnStyle effect for the second column. */ R(this, "secondColumnStyle", null); /** * @property {Nullable} lastColumnStyle effect for the last column. */ R(this, "lastColumnStyle", null); /** * @property {Nullable} quickly get merge style */ R(this, "_mergeCacheMap", /* @__PURE__ */ new Map()); t && this.fromJson({ ...t, name: e }), this._name = e; } /** * Gets the name of the range theme style.The name is read only, and use to identifier the range theme style. * @returns {string} The name of the range theme style. */ getName() { return this._name; } getWholeStyle() { return this.wholeStyle; } setWholeStyle(e) { this.wholeStyle = e; } getFirstRowStyle() { return this.firstRowStyle; } setFirstRowStyle(e) { this.firstRowStyle = e; } getSecondRowStyle() { return this.secondRowStyle; } setSecondRowStyle(e) { this.secondRowStyle = e; } getLastRowStyle() { return this.lastRowStyle; } setLastRowStyle(e) { this.lastRowStyle = e; } getFirstColumnStyle() { return this.firstColumnStyle; } setFirstColumnStyle(e) { this.firstColumnStyle = e; } getSecondColumnStyle() { return this.secondColumnStyle; } setSecondColumnStyle(e) { this.secondColumnStyle = e; } getLastColumnStyle() { return this.lastColumnStyle; } setLastColumnStyle(e) { this.lastColumnStyle = e; } getHeaderRowStyle() { return this.headerRowStyle; } setHeaderRowStyle(e) { this.headerRowStyle = e; } getHeaderColumnStyle() { return this.headerColumnStyle; } setHeaderColumnStyle(e) { this.headerColumnStyle = e; } getStyle(e, t, o, s) { let r = 0; return o && (r = r | ce.lastRowStyle), s && (r = r | ce.lastColumnStyle), e >= 0 && t >= 0 && (r = r | ce.wholeStyle), e % 2 === 1 && (r = r | ce.firstRowStyle), e % 2 === 0 && (r = r | ce.secondRowStyle), e === 0 && (r = r | ce.headerRowStyle), t === 0 && (r = r | ce.headerColumnStyle), t % 2 === 1 && (r = r | ce.firstColumnStyle), t % 2 === 0 && (r = r | ce.secondColumnStyle), r === 0 ? null : this._getMergeStyle(r); } _getMergeStyle(e) { let t = this._mergeCacheMap.get(e); return t || (t = this._mergeStyle(e), this._mergeCacheMap.set(e, t)), t; } _mergeStyle(e) { const t = []; return this.wholeStyle && e & ce.wholeStyle && t.push(this.wholeStyle), this.firstColumnStyle && e & ce.firstColumnStyle && t.push(this.firstColumnStyle), this.secondColumnStyle && e & ce.secondColumnStyle && t.push(this.secondColumnStyle), this.firstRowStyle && e & ce.firstRowStyle && t.push(this.firstRowStyle), this.secondRowStyle && e & ce.secondRowStyle && t.push(this.secondRowStyle), this.headerColumnStyle && e & ce.headerColumnStyle && t.push(this.headerColumnStyle), this.lastColumnStyle && e & ce.lastColumnStyle && t.push(this.lastColumnStyle), this.headerRowStyle && e & ce.headerRowStyle && t.push(this.headerRowStyle), this.lastRowStyle && e & ce.lastRowStyle && t.push(this.lastRowStyle), ra(t); } toJson() { const e = { name: this._name }; return this.wholeStyle && (e.wholeStyle = le(this.wholeStyle)), this.headerRowStyle && (e.headerRowStyle = le(this.headerRowStyle)), this.headerColumnStyle && (e.headerColumnStyle = le(this.headerColumnStyle)), this.firstRowStyle && (e.firstRowStyle = le(this.firstRowStyle)), this.secondRowStyle && (e.secondRowStyle = le(this.secondRowStyle)), this.lastRowStyle && (e.lastRowStyle = le(this.lastRowStyle)), this.firstColumnStyle && (e.firstColumnStyle = le(this.firstColumnStyle)), this.secondColumnStyle && (e.secondColumnStyle = le(this.secondColumnStyle)), this.lastColumnStyle && (e.lastColumnStyle = le(this.lastColumnStyle)), e; } fromJson(e) { this._name = e.name, e.wholeStyle && (this.wholeStyle = le(e.wholeStyle)), e.headerRowStyle && (this.headerRowStyle = le(e.headerRowStyle)), e.headerColumnStyle && (this.headerColumnStyle = le(e.headerColumnStyle)), e.firstRowStyle && (this.firstRowStyle = le(e.firstRowStyle)), e.secondRowStyle && (this.secondRowStyle = le(e.secondRowStyle)), e.lastRowStyle && (this.lastRowStyle = le(e.lastRowStyle)), e.firstColumnStyle && (this.firstColumnStyle = le(e.firstColumnStyle)), e.secondColumnStyle && (this.secondColumnStyle = le(e.secondColumnStyle)), e.lastColumnStyle && (this.lastColumnStyle = le(e.lastColumnStyle)); } dispose() { this._mergeCacheMap.clear(); } } const ia = (n, e, t) => new yt(`light-${n}`, { headerRowStyle: { bg: { rgb: e } }, firstColumnStyle: { bg: { rgb: "rgb(255, 255, 255)" } }, secondColumnStyle: { bg: { rgb: t } }, lastRowStyle: { bg: { rgb: e } } }), aa = (n, e, t) => new yt(`middle-${n}`, { headerRowStyle: { bg: { rgb: e } }, headerColumnStyle: { bg: { rgb: t } }, secondRowStyle: { bg: { rgb: t } }, lastRowStyle: { bg: { rgb: e } }, lastColumnStyle: { bg: { rgb: t } } }), ua = (n, e, t, o) => new yt(`dark-${n}`, { headerRowStyle: { bg: { rgb: e }, cl: { rgb: "rgb(255, 255, 255)" }, ht: ro.CENTER, bl: te.TRUE }, firstRowStyle: { bg: { rgb: t } }, secondRowStyle: { bg: { rgb: o } }, lastRowStyle: { bg: { rgb: e } } }), la = [ { baseName: "blue", header: "rgb(164, 202, 254)", color: "rgb(225, 239, 254)" }, { baseName: "grey", header: "rgb(205, 208, 216)", color: "rgb(238, 239, 241)" }, { baseName: "red", header: "rgb(248, 180, 180)", color: "rgb(253, 232, 232)" }, { baseName: "orange", header: "rgb(253, 186, 140)", color: "rgb(254, 236, 220)" }, { baseName: "yellow", header: "rgb(250, 200, 21)", color: "rgb(255, 244, 185)" }, { baseName: "green", header: "rgb(132, 225, 188)", color: "rgb(222, 247, 236)" }, { baseName: "azure", header: "rgb(126, 220, 226)", color: "rgb(213, 245, 246)" }, { baseName: "indigo", header: "rgb(186, 198, 248)", color: "rgb(233, 237, 255)" }, { baseName: "purple", header: "rgb(202, 191, 253)", color: "rgb(237, 235, 254)" }, { baseName: "magenta", header: "rgb(248, 180, 217)", color: "rgb(252, 232, 243)" } ], ca = [ { baseName: "blue", rowHeader: "rgb(63, 131, 248)", colHeader: "rgb(195, 221, 253)" }, { baseName: "grey", rowHeader: "rgb(95, 101, 116)", colHeader: "rgb(227, 229, 234)" }, { baseName: "red", rowHeader: "rgb(240, 82, 82)", colHeader: "rgb(251, 213, 213)" }, { baseName: "orange", rowHeader: "rgb(255, 90, 31)", colHeader: "rgb(252, 217, 189)" }, { baseName: "yellow", rowHeader: "rgb(212, 157, 15)", colHeader: "rgb(252, 220, 106)" }, { baseName: "green", rowHeader: "rgb(13, 164, 113)", colHeader: "rgb(188, 240, 218)" }, { baseName: "azure", rowHeader: "rgb(6, 148, 162)", colHeader: "rgb(175, 236, 239)" }, { baseName: "indigo", rowHeader: "rgb(70, 106, 247)", colHeader: "rgb(210, 218, 250)" }, { baseName: "purple", rowHeader: "rgb(144, 97, 249)", colHeader: "rgb(220, 215, 254)" }, { baseName: "magenta", rowHeader: "rgb(231, 70, 148)", colHeader: "rgb(250, 209, 232)" } ], da = [ { baseName: "blue", rowHeader: "rgb(30, 66, 159)", firstRow: "rgb(195, 221, 253)", secondRow: "rgb(118, 169, 250)" }, { baseName: "grey", rowHeader: "rgb(44, 48, 64)", firstRow: "rgb(227, 229, 234)", secondRow: "rgb(151, 157, 172)" }, { baseName: "red", rowHeader: "rgb(155, 28, 28)", firstRow: "rgb(251, 213, 213)", secondRow: "rgb(249, 128, 128)" }, { baseName: "orange", rowHeader: "rgb(180, 52, 3)", firstRow: "rgb(252, 217, 189)", secondRow: "rgb(255, 138, 76)" }, { baseName: "yellow", rowHeader: "rgb(154, 109, 21)", firstRow: "rgb(252, 220, 106)", secondRow: "rgb(212, 157, 15)" }, { baseName: "green", rowHeader: "rgb(4, 108, 78)", firstRow: "rgb(188, 240, 218)", secondRow: "rgb(49, 196, 141)" }, { baseName: "azure", rowHeader: "rgb(3, 102, 114)", firstRow: "rgb(175, 236, 239)", secondRow: "rgb(22, 189, 202)" }, { baseName: "indigo", rowHeader: "rgb(16, 51, 191)", firstRow: "rgb(210, 218, 250)", secondRow: "rgb(98, 128, 249)" }, { baseName: "purple", rowHeader: "rgb(74, 29, 150)", firstRow: "rgb(220, 215, 254)", secondRow: "rgb(172, 148, 250)" }, { baseName: "magenta", rowHeader: "rgb(153, 21, 75)", firstRow: "rgb(250, 209, 232)", secondRow: "rgb(241, 126, 184)" } ], ha = la.map(({ baseName: n, header: e, color: t }) => ia(n, e, t)), ma = ca.map(({ baseName: n, rowHeader: e, colHeader: t }) => aa(n, e, t)), ga = da.map(({ baseName: n, rowHeader: e, firstRow: t, secondRow: o }) => ua(n, e, t, o)), fa = [ ...ha, ...ma, ...ga ], Ra = { headerRowStyle: { bg: { rgb: "rgb(68,114,196)" }, cl: { rgb: "rgb(255,255,255)" }, ht: ro.CENTER, bl: te.TRUE }, firstRowStyle: { bg: { rgb: "rgb(217,225,242)" } }, lastRowStyle: { bd: { t: { s: Rs.THIN, cl: { rgb: "rgb(68,114,196)" } } }, ht: ro.CENTER, bl: te.TRUE } }, pa = new yt("default", Ra); var Ca = Object.defineProperty, Sa = Object.getOwnPropertyDescriptor, wa = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Sa(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Ca(e, t, s), s; }, Ko = (n, e) => (t, o) => e(t, o, n); const Ia = "SHEET_RANGE_THEME_MODEL_PLUGIN"; let He = class extends ae { constructor(e, t) { super(); R(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map()); R(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map()); R(this, "_rTreeCollection", /* @__PURE__ */ new Map()); R(this, "_defaultRangeThemeMap", /* @__PURE__ */ new Map()); this._sheetInterceptorService = e, this._resourceManagerService = t, this._registerIntercept(), this._initSnapshot(), this._initDefaultTheme(); } _initDefaultTheme() { this.registerDefaultRangeTheme(pa); for (const e of fa) this.registerDefaultRangeTheme(e); } _ensureRangeThemeStyleMap(e) { return this._rangeThemeStyleMap.has(e) || this._rangeThemeStyleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleMap.get(e); } _ensureRangeThemeStyleRuleMap(e) { return this._rangeThemeStyleRuleMap.has(e) || this._rangeThemeStyleRuleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleRuleMap.get(e); } _ensureRTreeCollection(e) { return this._rTreeCollection.has(e) || this._rTreeCollection.set(e, new ui()), this._rTreeCollection.get(e); } getDefaultRangeThemeStyle(e) { return this._defaultRangeThemeMap.get(e); } /** * Register range theme styles * @param {string} themeName * @param {IRangeThemeRangeInfo} rangeInfo */ registerRangeThemeRule(e, t) { const { unitId: o, subUnitId: s, range: r } = t, i = li(), a = this._ensureRangeThemeStyleRuleMap(o), u = this._ensureRTreeCollection(o); a.set(i, { rangeInfo: t, themeName: e }), u.insert({ unitId: o, sheetId: s, range: r, id: i }); } getRegisteredRangeThemeStyle(e) { const { unitId: t, subUnitId: o, range: s } = e, r = this._ensureRTreeCollection(t), i = Array.from(r.bulkSearch([{ unitId: t, sheetId: o, range: s }])); if (i[0]) { const u = this._ensureRangeThemeStyleRuleMap(t).get(i[0]); if (u) return u.themeName; } } removeRangeThemeRule(e, t) { const { unitId: o, subUnitId: s, range: r } = t, i = this._ensureRTreeCollection(o), a = Array.from(i.bulkSearch([{ unitId: o, sheetId: s, range: r }])); if (a[0]) { const u = this._ensureRangeThemeStyleRuleMap(o), l = u.get(a[0]); l && l.themeName === e && (u.delete(a[0]), i.remove({ unitId: o, sheetId: s, range: r, id: a[0] })); } } registerDefaultRangeTheme(e) { this._defaultRangeThemeMap.set(e.getName(), e); } getRegisteredRangeThemes() { return Array.from(this._defaultRangeThemeMap.keys()); } /** * Register custom range theme style. * @param {string} unitId The unit id. * @param {RangeThemeStyle} rangeThemeStyle The range theme style. */ registerRangeThemeStyle(e, t) { this._ensureRangeThemeStyleMap(e).set(t.getName(), t); } /** * Unregister custom range theme style. * @param {string} unitId The unit id. * @param {string} name The name of the range theme style. */ unregisterRangeThemeStyle(e, t) { this._ensureRangeThemeStyleMap(e).delete(t); } /** * Gets all custom register themes * @return {string[]} The array of all custom registered themes. */ getALLRegisteredTheme() { return Array.from(this._rangeThemeStyleMap.keys()); } getRangeThemeStyle(e, t) { return this._defaultRangeThemeMap.has(t) ? this._defaultRangeThemeMap.get(t) : this._ensureRangeThemeStyleMap(e).get(t); } getCellStyle(e, t, o, s) { const r = { startRow: o, startColumn: s, endRow: o, endColumn: s }, i = this._ensureRTreeCollection(e), a = Array.from(i.bulkSearch([{ unitId: e, sheetId: t, range: r }])); if (a[0]) { const l = this._ensureRangeThemeStyleRuleMap(e).get(a[0]); if (l) { const { rangeInfo: c, themeName: d } = l, h = o - c.range.startRow, m = s - c.range.startColumn; return this.getRangeThemeStyle(e, d).getStyle(h, m, o === c.range.endRow, s === c.range.endColumn); } } } _registerIntercept() { this.disposeWithMe(this._sheetInterceptorService.intercept(et.CELL_CONTENT, { id: Ns, effect: me.Style, handler: (e, t, o) => { const { row: s, col: r, unitId: i, subUnitId: a } = t, u = this.getCellStyle(i, a, s, r); if (u) { const l = { ...e }; return l.themeStyle = u, o(l); } return o(e); } })); } toJson(e) { const t = this._ensureRangeThemeStyleRuleMap(e), o = this._ensureRangeThemeStyleMap(e); if (o.size === 0 && t.size === 0) return "{}"; const s = {}; t.forEach((i, a) => { s[a] = i; }); const r = {}; return o.forEach((i, a) => { r[a] = i.toJson(); }), JSON.stringify({ rangeThemeStyleRuleMap: s, rangeThemeStyleMapJson: r }); } fromJSON(e) { const { rangeThemeStyleRuleMap: t, rangeThemeStyleMapJson: o } = e; this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._rTreeCollection.clear(), !(!t || !o) && (Object.keys(t).forEach((s) => { const r = t[s], { themeName: i, rangeInfo: a } = r; this.registerRangeThemeRule(i, a), this._ensureRTreeCollection(a.unitId).insert({ unitId: s, sheetId: a.subUnitId, range: a.range, id: s }); }), Object.keys(o).forEach((s) => { const r = o[s], i = new yt(r.name); i.fromJson(r), this._ensureRangeThemeStyleMap(s).set(i.getName(), i); })); } deleteUnitId(e) { this._rangeThemeStyleMap.delete(e), this._rangeThemeStyleRuleMap.delete(e), this._rTreeCollection.delete(e); } _initSnapshot() { this.disposeWithMe(this._resourceManagerService.registerPluginResource({ toJson: (e) => this.toJson(e), parseJson: (e) => { if (!e) return {}; try { return JSON.parse(e); } catch { return {}; } }, businesses: [B.UNIVER_SHEET], pluginName: Ia, onLoad: (e, t) => { this.fromJSON(t); }, onUnLoad: (e) => { this.deleteUnitId(e); } })); } dispose() { super.dispose(), this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._defaultRangeThemeMap.clear(), this._rTreeCollection.clear(); } }; He = wa([ Ko(0, L(V)), Ko(1, L(nn)) ], He); function va(n, e) { const { unitId: t } = e, o = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(B.UNIVER_SHEET); return o ? { workbook: o, unitId: o.getUnitId() } : null; } function N(n, e = {}) { const { unitId: t, subUnitId: o } = e, s = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(B.UNIVER_SHEET); if (!s) return null; const r = o ? s.getSheetBySheetId(o) : s.getActiveSheet(!0); return r ? { worksheet: r, workbook: s, unitId: s.getUnitId(), subUnitId: r.getSheetId() } : null; } function Et(n, e) { const { unitId: t, subUnitId: o } = e, s = n.getUniverSheetInstance(t); if (!s) return null; const r = s.getSheetBySheetId(o); return r ? { worksheet: r, workbook: s } : null; } const zt = { id: "sheet.mutation.set-worksheet-range-theme-style", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = N(i), u = n.get(He); return a ? (u.registerRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1; } }, Ma = (n, e) => { const t = Et(n.get(M), e); if (!t) throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!"); const { worksheet: o } = t; return { unitId: e.unitId, subUnitId: o.getSheetId(), range: e.range, themeName: e.themeName }; }, Kt = { id: "sheet.mutation.remove-worksheet-range-theme-style", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = N(i), u = n.get(He); return a ? (u.removeRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1; } }, _a = (n, e) => { const t = Et(n.get(M), e); if (!t) throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!"); const { worksheet: o } = t; return { unitId: e.unitId, subUnitId: o.getSheetId(), range: e.range, themeName: e.themeName }; }, ba = { type: v.COMMAND, id: "sheet.command.set-worksheet-range-theme-style", handler: (n, e) => { const t = n.get(E), o = n.get(W), { unitId: s } = e, r = Ma(n, e); return t.syncExecuteCommand(zt.id, e) ? (o.pushUndoRedo({ unitID: s, undoMutations: [{ id: Kt.id, params: r }], redoMutations: [{ id: zt.id, params: e }] }), !0) : !1; } }, ya = (n, e, t = "") => n.reduce( (o, s) => { const r = s && s[e]; return typeof r != "string" ? (console.warn(s, `${e} is not string`), o) : (r ? (o[r] || (o[r] = []), o[r].push(s)) : o[t].push(s), o); }, {} ), Ea = (n = 0) => { let e = n; return function() { return e++; }; }; function Os(n) { const e = new G(); return n.forEach((t) => { const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t; for (let a = o; a <= r; a++) for (let u = s; u <= i; u++) e.setValue(a, u, null); }), e.clone(); } function Ua(n) { const e = new G(); return n.forEach((t) => { const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t; for (let a = o; a <= r; a++) for (let u = s; u <= i; u++) e.setValue(a, u, { v: null, p: null, f: null, si: null, custom: null }); }), e.clone(); } function Pa(n) { const e = new G(); return n.forEach((t) => { const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t; for (let a = o; a <= r; a++) for (let u = s; u <= i; u++) e.setValue(a, u, { s: null }); }), e.clone(); } var Ce = /* @__PURE__ */ ((n) => (n[n.MOVE_START = 0] = "MOVE_START", n[n.MOVING = 1] = "MOVING", n[n.MOVE_END = 2] = "MOVE_END", n[n.ONLY_SET = 3] = "ONLY_SET", n))(Ce || {}); class Ta extends ae { constructor(t) { super(); /** * Selection data model for each worksheet. */ R(this, "_worksheetSelections", /* @__PURE__ */ new Map()); R(this, "_selectionMoveStart$", new Le()); R(this, "selectionMoveStart$", this._selectionMoveStart$.asObservable()); R(this, "_selectionMoving$", new Le()); R(this, "selectionMoving$", this._selectionMoving$.asObservable()); R(this, "_selectionMoveEnd$", new at([])); R(this, "selectionMoveEnd$", this._selectionMoveEnd$.asObservable()); R(this, "_selectionSet$", new at([])); R(this, "selectionSet$", this._selectionSet$.asObservable()); R(this, "selectionChanged$"); R(this, "_beforeSelectionMoveEnd$", new at([])); R(this, "beforeSelectionMoveEnd$", this._beforeSelectionMoveEnd$.asObservable()); this._workbook = t, this.selectionChanged$ = xt(this._selectionMoveEnd$, this._selectionSet$); } dispose() { super.dispose(), this._beforeSelectionMoveEnd$.complete(), this._selectionMoveEnd$.complete(), this._selectionMoving$.complete(), this._selectionMoveStart$.complete(), this._selectionSet$.complete(); } addSelections(t, o) { const s = this.getSelectionsOfWorksheet(t); s.push(...o), this._selectionSet$.next(s); } /** * Set selectionDatas to _worksheetSelections, and emit selectionDatas by type. * @param sheetId * @param selectionDatas * @param type */ setSelections(t, o = [], s) { switch (this.setSelectionsOfWorksheet(t, o), s) { case Ce.MOVE_START: this._selectionMoveStart$.next(o); break; case Ce.MOVING: this._selectionMoving$.next(o); break; case Ce.MOVE_END: this._beforeSelectionMoveEnd$.next(o), this._selectionMoveEnd$.next(o); break; case Ce.ONLY_SET: { this._selectionSet$.next(o); break; } default: this._selectionSet$.next(o); break; } } getCurrentSelections() { return this._getCurrentSelections(); } /** * @deprecated use `getSelectionsOfWorksheet` instead. * @param sheetId * @returns */ getSelectionOfWorksheet(t) { return this.getSelectionsOfWorksheet(t); } getSelectionsOfWorksheet(t) { return this._worksheetSelections.has(t) || this._worksheetSelections.set(t, []), this._worksheetSelections.get(t); } setSelectionsOfWorksheet(t, o) { this._worksheetSelections.set(t, [...o]); } deleteSheetSelection(t) { this._worksheetSelections.set(t, []); } /** Clear all selections in this workbook. */ clear() { this._worksheetSelections.clear(), this._selectionSet$.next([]); } _getCurrentSelections() { return this.getSelectionsOfWorksheet(this._workbook.getActiveSheet().getSheetId()); } getCurrentLastSelection() { const t = this._getCurrentSelections(); return t[t.length - 1]; } } var ka = Object.defineProperty, Na = Object.getOwnPropertyDescriptor, Oa = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Na(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && ka(e, t, s), s; }, Da = (n, e) => (t, o) => e(t, o, n); let F = class extends ps { constructor(e) { super(); /** * Selection Events, usually triggered when pointerdown in spreadsheet by selection render service after selectionModel has updated. */ R(this, "selectionMoveStart$"); /** * Selection Events, usually triggered when pointermove in spreadsheet by selection render service after selectionModel has updated. */ R(this, "selectionMoving$"); /** * Selection Events, usually triggered when pointerup in spreadsheet by selection render service after selectionModel has updated. */ R(this, "selectionMoveEnd$"); /** * Selection Events, usually triggered when changing unit.(focus in formula editor) */ R(this, "selectionSet$"); /** * Selection Events, merge moveEnd$ and selectionSet$ */ R(this, "selectionChanged$"); R(this, "_workbookSelections", /* @__PURE__ */ new Map()); this._instanceSrv = e, this._init(); } get _currentSelectionPos() { const e = this._instanceSrv.getCurrentUnitForType(B.UNIVER_SHEET); if (!e) return null; const t = e.getActiveSheet(); return { unitId: e.getUnitId(), sheetId: t.getSheetId() }; } get currentSelectionParam() { return this._currentSelectionPos; } _init() { const e = this._instanceSrv.getCurrentTypeOfUnit$(B.UNIVER_SHEET).pipe(ji(1), io(this.dispose$)); this.selectionMoveStart$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveStart$ : Ot())), this.selectionMoving$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoving$ : Ot())), this.selectionMoveEnd$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveEnd$ : Ot([]))), this.selectionSet$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionSet$ : Ot([]))), this.selectionChanged$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionChanged$ : Ot([]))).pipe( Gi((t, o) => t.length !== o.length ? !1 : t.length === 0 && o.length === 0 ? !0 : t.every((s, r) => JSON.stringify(s) === JSON.stringify(o[r]))), Ts(1) ), this._instanceSrv.getTypeOfUnitDisposed$(B.UNIVER_SHEET).pipe(io(this.dispose$)).subscribe((t) => { this._removeWorkbookSelection(t.getUnitId()); }); } /** * Clear all selections in all workbooks. * invoked by prompt.controller */ clear() { this._workbookSelections.forEach((e) => e.clear()); } getCurrentSelections() { return this._getCurrentSelections(); } getCurrentLastSelection() { const e = this._getCurrentSelections(); return e == null ? void 0 : e[e.length - 1]; } addSelections(e, t, o) { if (typeof e == "string") { this._ensureWorkbookSelection(e).addSelections(t, o); return; } const s = this._currentSelectionPos; if (!s) throw new Error("[SheetsSelectionsService]: cannot find current selection position!"); const { unitId: r, sheetId: i } = s; this._ensureWorkbookSelection(r).addSelections(i, e); } setSelections(e, t, o, s) { if (typeof e == "string" && typeof t == "string") { const u = e; this._ensureWorkbookSelection(u).setSelections( t, o || [], s != null ? s : Ce.ONLY_SET ); return; } const r = this._currentSelectionPos; if (!r) throw new Error("[SheetsSelectionsService]: cannot find current selection position!"); const { unitId: i, sheetId: a } = r; if (typeof e == "object") { const u = e != null ? e : o, l = t != null ? t : Ce.ONLY_SET; this._ensureWorkbookSelection(i).setSelections(a, u, l); } } clearCurrentSelections() { this._getCurrentSelections().splice(0); } /** * Determine whether multiple current selections overlap * * @deprecated this should be extracted to an pure function */ isOverlapping() { const e = this.getCurrentSelections(); return e == null ? !1 : e.some( ({ range: t }, o) => e.some(({ range: s }, r) => o === r ? !1 : t.startRow <= s.endRow && t.endRow >= s.startRow && t.startColumn <= s.endColumn && t.endColumn >= s.startColumn) ); } _getCurrentSelections() { const e = this._currentSelectionPos; if (!e) return []; const { unitId: t, sheetId: o } = e; return this._ensureWorkbookSelection(t).getSelectionsOfWorksheet(o); } getWorkbookSelections(e) { return this._ensureWorkbookSelection(e); } _ensureWorkbookSelection(e) { let t = this._workbookSelections.get(e); if (!t) { const o = this._instanceSrv.getUnit(e); if (!o) throw new Error(`[SheetsSelectionsService]: cannot resolve unit with id "${e}"!`); t = new Ta(o), this._workbookSelections.set(e, t); } return t; } _removeWorkbookSelection(e) { this._workbookSelections.delete(e); } }; F = Oa([ Da(0, M) ], F); const jd = "DISABLE_NORMAL_SELECTIONS", Gd = "SELECTIONS_ENABLED", Aa = "REF_SELECTIONS_ENABLED"; function xa(n, e, t) { var i; const o = n.getStyleByCell(e); o == null && delete e.s, typeof t.s == "string" && (t.s = n.get(t.s)); const s = gn(o, t.s ? t.s : null); s && (O.removeNull(s), Object.entries(s).forEach(([a, u]) => { typeof u == "object" && u !== null && Object.keys(u).length === 0 && delete s[a]; })), O.isEmptyObject(s) ? delete e.s : e.s = n.setValue(s); const r = t.v ? `${t.v}\r ` : ""; !t.p && e.p && (r && r !== ((i = e.p.body) == null ? void 0 : i.dataStream) ? delete e.p : La(e.p, t.s ? t.s : null)); } function $a(n, e) { if (!e || !Object.keys(e).length) return n; const t = n || {}; for (const o in e) o === "bd" ? t[o] = Wa(t[o] || {}, e[o]) : o in t || (t[o] = null); return t; } function Wa(n, e) { if (!e || !Object.keys(e).length) return n; for (const t in e) t in n || (n[t] = null); return n; } function gn(n, e, t = !1) { if (e === null) return e; if (e === void 0) return n; const o = O.deepClone(n) || {}; for (const s in e) t && ["bd", "tr", "td", "ht", "vt", "tb", "pd", "bg"].includes(s) || (s in o && s === "bd" ? o[s] = Object.assign(o[s], e[s]) : o[s] = e[s]); return "cl" in o && ("ul" in o && o.ul && (o.ul.cl = o.cl), "ol" in o && o.ol && (o.ol.cl = o.cl), "st" in o && o.st && (o.st.cl = o.cl)), o; } function Ds(n, e) { return n.some((t) => t.startIndex === e) ? Ds(n, e + 1) : e; } function La(n, e) { var i; if (n.body == null) return; Array.isArray(n.body.textRuns) || (n.body.textRuns = []); let t = 0; const o = [], s = ((i = n.body) == null ? void 0 : i.paragraphs) || []; for (const a of n.body.textRuns) { const { st: u, ed: l, ts: c = {} } = a; if (t < u) { const h = { st: t, ed: u }, m = gn({}, e, !0); m && O.removeNull(m), O.isEmptyObject(m) || (h.ts = m), o.push(h); } const d = gn(c, e, !0); d && O.removeNull(d), O.isEmptyObject(d) ? delete a.ts : a.ts = d, o.push(a), t = Ds(s, l); } const r = n.body.dataStream.endsWith(`\r `) ? n.body.dataStream.length - 2 : n.body.dataStream.length; if (t < r) { const a = { st: t, ed: r }, u = gn({}, e, !0); u && O.removeNull(u), O.isEmptyObject(u) || (a.ts = u), o.push(a); } n.body.textRuns = ci(o); } function Va(n, e, t) { if (e.t) return e.t; if (e.v === null) return null; const o = n.getStyleByCell(e), s = n.getStyleByCell(t); if (t.t === se.FORCE_STRING) { if (!Qn(s) && e.v !== void 0) { if (go(e.v)) return se.NUMBER; if (Cs(`${e.v}`)) return se.BOOLEAN; } return se.FORCE_STRING; } return Ha(o) ? Qn(o) ? se.STRING : Jo(e, t) : Qn(s) ? se.STRING : Jo(e, t); } function Jo(n, e) { return n.v !== void 0 ? Yo(n.v, n.t) : Yo(e.v, e.t); } function Ha(n) { var e; return !!((e = n == null ? void 0 : n.n) != null && e.pattern); } function Qn(n) { var e; return ((e = n == null ? void 0 : n.n) == null ? void 0 : e.pattern) === ks; } function Yo(n, e) { return n === null ? null : typeof n == "string" ? go(n) ? (+n == 0 || +n == 1) && e === se.BOOLEAN ? se.BOOLEAN : se.NUMBER : Cs(n) ? se.BOOLEAN : se.STRING : typeof n == "number" ? (n === 0 || n === 1) && e === se.BOOLEAN ? se.BOOLEAN : se.NUMBER : typeof n == "boolean" ? se.BOOLEAN : se.FORCE_STRING; } function Xo(n, e) { return n === se.NUMBER ? Number(e.v) : n === se.BOOLEAN ? Ba(e.v) ? 1 : 0 : n === se.STRING || n === se.FORCE_STRING ? `${e.v}` : e.v; } function Ba(n) { if (typeof n == "string") { if (n.toUpperCase() === "TRUE") return !0; if (n.toUpperCase() === "FALSE") return !1; if (di(n)) { if (Number(n) === 0) return !1; if (Number(n) === 1) return !0; } } if (typeof n == "number") { if (n === 0) return !1; if (n === 1) return !0; } return typeof n == "boolean" ? n : null; } function Fa(n) { return n == null ? null : (n.f === void 0 && (n.f = null), n.si === void 0 && (n.si = null), n.p === void 0 && (n.p = null), n.v === void 0 && (n.v = null), n.t === void 0 && (n.t = null), n.s === void 0 && (n.s = null), n.custom === void 0 && (n.custom = null), n); } const Ae = (n, e) => { const { unitId: t, subUnitId: o, cellValue: s } = e, i = n.get(M).getUniverSheetInstance(t); if (i == null) throw new Error("workbook is null error!"); const a = i.getSheetBySheetId(o); if (a == null) throw new Error("worksheet is null error!"); const u = a.getCellMatrix(), l = i.getStyles(), c = new G(); return new G(s).forValue((h, m, g) => { const f = O.deepClone(u == null ? void 0 : u.getValue(h, m)) || {}, p = l.getStyleByCell(f), C = l.getStyleByCell(g); f.s = $a(p, C), c.setValue(h, m, Fa(f)); }), { ...e, options: {}, cellValue: c.getMatrix() }; }, Q = { id: "sheet.mutation.set-range-values", type: v.MUTATION, handler: (n, e) => { const { cellValue: t, subUnitId: o, unitId: s } = e, i = n.get(M).getUnit(s); if (!i) return !1; const a = i.getSheetBySheetId(o); if (!a) return !1; const u = a.getCellMatrix(), l = i.getStyles(); return new G(t).forValue((d, h, m) => { if (!m) u == null || u.setValue(d, h, {}); else { const g = u.getValue(d, h) || {}, f = Va(l, m, g); m.f !== void 0 && (g.f = m.f), m.si !== void 0 && (g.si = m.si), m.p !== void 0 && (g.p = m.p), m.v !== void 0 && (g.v = Xo(f, m)), g.v !== void 0 && (g.t = f, g.v = Xo(f, g)), m.s !== void 0 && xa(l, g, m), m.custom !== void 0 && (g.custom = m.custom), u.setValue(d, h, O.removeNull(g)); } }), !0; } }, po = { id: "sheet.command.clear-selection-all", type: v.COMMAND, handler: (n, e) => { var S; const t = n.get(M), o = n.get(E), s = n.get(F), r = n.get(W), i = n.get(V), a = t.getCurrentUnitForType(B.UNIVER_SHEET); if (!a) return !1; const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet(); if (!l) return !1; const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range)); if (!(d != null && d.length)) return !1; const h = [], m = [], g = { subUnitId: c, unitId: u, cellValue: Os(d) }, f = Ae( n, g ); h.push({ id: Q.id, params: g }), m.push({ id: Q.id, params: f }); const p = i.onCommandExecute({ id: po.id }); return h.push(...p.redos), m.unshift(...p.undos), z(h, o) ? (r.pushUndoRedo({ // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element. // Hooks can be used to hook the code of external controllers to add new actions. unitID: u, undoMutations: m, redoMutations: h }), !0) : !1; } }, Co = { id: "sheet.command.clear-selection-content", type: v.COMMAND, handler: (n, e) => { var S; const t = n.get(M), o = n.get(E), s = n.get(F), r = n.get(W), i = n.get(V), a = t.getCurrentUnitForType(B.UNIVER_SHEET); if (!a) return !1; const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet(); if (!l) return !1; const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range)); if (!(d != null && d.length)) return !1; const h = { subUnitId: c, unitId: u, cellValue: Ua(d) }, m = Ae( n, h ), g = i.onCommandExecute({ id: Co.id }), f = [{ id: Q.id, params: h }, ...g.redos], p = [...g.undos, { id: Q.id, params: m }]; return z(f, o).result ? (r.pushUndoRedo({ // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element. // Hooks can be used to hook the code of external controllers to add new actions. unitID: u, undoMutations: p, redoMutations: f }), !0) : !1; } }, So = { id: "sheet.command.clear-selection-format", type: v.COMMAND, handler: (n, e) => { var S; const t = n.get(M), o = n.get(E), s = n.get(F), r = n.get(W), i = n.get(V), a = t.getCurrentUnitForType(B.UNIVER_SHEET); if (!a) return !1; const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet(); if (!l) return !1; const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range)); if (!(d != null && d.length)) return !1; const h = [], m = [], g = { subUnitId: c, unitId: u, cellValue: Pa(d) }, f = Ae( n, g ); h.push({ id: Q.id, params: g }), m.push({ id: Q.id, params: f }); const p = i.onCommandExecute({ id: So.id }); return h.push(...p.redos), m.unshift(...p.undos), z(h, o) ? (r.pushUndoRedo({ // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element. // Hooks can be used to hook the code of external controllers to add new actions. unitID: u, undoMutations: m, redoMutations: h }), !0) : !1; } }, As = (n, e) => ({ subUnitId: e.sheet.id, unitId: e.unitId, subUnitName: e.sheet.name }), Jt = { id: "sheet.mutation.insert-sheet", type: v.MUTATION, handler: (n, e) => { const t = n.get(M), { sheet: o, index: s, unitId: r } = e, i = t.getUniverSheetInstance(r); return i ? i.addWorksheet(o.id, s, o) : !1; } }, ja = (n, e) => { const t = n.get(M), { subUnitId: o, unitId: s } = e, r = Et(t, e); if (!r) throw new Error("[RemoveSheetUndoMutationFactory]: Worksheet is null error!"); const { workbook: i, worksheet: a } = r, u = a.getConfig(); return { index: i.getConfig().sheetOrder.findIndex((d) => d === o), sheet: u, unitId: s }; }, Ut = { id: "sheet.mutation.remove-sheet", type: v.MUTATION, handler: (n, e) => { const t = n.get(M), { subUnitId: o, unitId: s } = e, r = t.getUniverSheetInstance(s); return r ? r.removeSheet(o) : !1; } }, xs = { type: v.COMMAND, id: "sheet.command.copy-sheet", handler: (n, e) => { var w, b; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = n.get(Ke), a = N(s, e); if (!a) return !1; const { workbook: u, worksheet: l, unitId: c, subUnitId: d } = a, h = O.deepClone(l.getConfig()); h.name = Ga(u, i, h.name), h.id = O.generateRandomId(); const g = { index: u.getSheetIndex(l) + 1, sheet: h, unitId: c }, f = As( n, g ), p = r.onCommandExecute({ id: xs.id, params: { unitId: c, subUnitId: d, targetSubUnitId: h.id } }), C = [ ...(w = p.preRedos) != null ? w : [], { id: Jt.id, params: g }, ...p.redos ], S = [ ...(b = p.preUndos) != null ? b : [], { id: Ut.id, params: f }, ...p.undos ]; return z(C, t).result ? (o.pushUndoRedo({ unitID: c, undoMutations: S, redoMutations: C }), !0) : !1; } }; function Ga(n, e, t) { let o = t + e.t("sheets.tabs.sheetCopy", ""), s = 2; for (; n.checkSheetName(o); ) o = t + e.t("sheets.tabs.sheetCopy", `${s}`), s++; return o; } const dt = { id: "sheet.mutation.move-range", type: v.MUTATION, handler: (n, e) => { const { from: t, to: o } = e; if (!t || !o) return !1; const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET); if (!r) return !1; const i = r.getSheetBySheetId(e.from.subUnitId), a = r.getSheetBySheetId(e.to.subUnitId); if (!i || !a) return !1; const u = i.getCellMatrix(), l = a.getCellMatrix(); return new G(t.value).forValue((c, d, h) => { u.setValue(c, d, h); }), new G(o.value).forValue((c, d, h) => { l.setValue(c, d, h); }), !0; } }; var za = Object.defineProperty, Ka = Object.getOwnPropertyDescriptor, Ja = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Ka(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && za(e, t, s), s; }, Ya = (n, e) => (t, o) => e(t, o, n); const Xa = fo("sheets-formula.ref-selections.service"); let qo = class extends F { constructor(n) { super(n); } _init() { const n = this._getAliveWorkbooks$().pipe(io(this.dispose$)); this.selectionMoveStart$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionMoveStart$)))), this.selectionMoving$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionMoving$)))), this.selectionMoveEnd$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionMoveEnd$)))), this.selectionSet$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionSet$)))); } _getAliveWorkbooks$() { const n = this._instanceSrv.getAllUnitsForType(B.UNIVER_SHEET); n.forEach((t) => this._ensureWorkbookSelection(t.getUnitId())); const e = new at(n); return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((t) => { this._ensureWorkbookSelection(t.getUnitId()), e.next([...e.getValue(), t]); })), this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe((t) => { this._removeWorkbookSelection(t.getUnitId()), e.next(e.getValue().filter((o) => o !== t)); })), e.pipe(ao((t) => t.map((o) => this._ensureWorkbookSelection(o.getUnitId())))); } }; qo = Ja([ Ya(0, M) ], qo); function qa(n, e) { const o = n.get(Ss).getContextValue(Aa); return n.get(o && !e ? Xa : F); } const re = { id: "sheet.operation.set-selections", type: v.OPERATION, handler: (n, e) => { if (!e) return !1; const { selections: t, type: o, unitId: s, subUnitId: r } = e; return qa(n).setSelections(s, r, [...t], o), !0; } }; function Ln(n, e, t = !0) { const o = e.getMatrixWithMergedCells(...hi(n)), s = []; if (o.forValue((i, a, u) => { if (u.colSpan !== void 0 && u.rowSpan !== void 0) { const l = { startRow: i, startColumn: a, endRow: i + u.rowSpan - 1, endColumn: a + u.colSpan - 1 }; k.contains(n, l) || s.push(l); } }), s.length === 0) return n; const r = k.union(n, ...s); return t ? Ln(r, e, t) : r; } function zd(n, e, t) { let o = null; return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = { actualRow: r, actualColumn: i, startRow: r, startColumn: i, isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0, isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0, endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0), endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0), rangeType: H.NORMAL }, !1)), o || { actualColumn: e, actualRow: n, startRow: n, startColumn: e, endRow: n, endColumn: e, isMerged: !1, isMergedMainCell: !1, rangeType: H.NORMAL }; } function Kd(n, e, t) { const { startRow: o, startColumn: s, endRow: r, endColumn: i } = n; return Number.isNaN(o) && (n.startRow = 0), Number.isNaN(r) && (n.endRow = e - 1), Number.isNaN(s) && (n.startColumn = 0), Number.isNaN(i) && (n.endColumn = t - 1), n; } function ve(n, e) { const t = Number.isNaN(n.startRow) ? 0 : n.startRow, o = Number.isNaN(n.startColumn) ? 0 : n.startColumn, s = e.getMergedCell(t, o); return s ? { ...s, actualRow: t, actualColumn: o, rangeType: H.NORMAL, isMerged: !0, isMergedMainCell: !0 } : { startRow: t, startColumn: o, endRow: n.startRow, endColumn: n.startColumn, actualRow: t, actualColumn: o, rangeType: H.NORMAL, isMerged: !1, isMergedMainCell: !1 }; } const Xe = (n, e, t) => ({ id: re.id, params: { unitId: e.getUnitId(), subUnitId: t.getSheetId(), reveal: !0, selections: [{ range: n, primary: ve(n, t) }] } }); function Jd(n) { if (!n) return !1; const { range: e, primary: t } = n; return k.equals(e, t); } function Za(n) { function e(t, o) { function s(r) { for (let i = r.startRow; i <= r.endRow; i++) if (!n.getRowFiltered(i)) for (let a = r.startColumn; a <= r.endColumn; a++) o(i, a, r); } s(t); } return { forOperableEach: e }; } const Zo = (n) => n.id !== Ns; function Vn(n, e, t, o, s, r, i) { const a = {}; for (let u = e; u <= t; u++) for (let l = o; l <= s; l++) { const c = r ? n.getCellWithFilteredInterceptors(i, l, jo, Zo) : n.getCellWithFilteredInterceptors(u, i, jo, Zo); !c || !c.s || (a[u] || (a[u] = {}), a[u][l] = { s: c.s }); } return a; } const $s = "sheet.command.move-range", pt = { type: v.COMMAND, id: $s, handler: async (n, e) => { var I, w; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(bt), i = n.get(Ke), a = n.get(V), u = N(s); if (!u || !await a.beforeCommandExecute({ id: pt.id, params: e })) return !1; const { worksheet: c, subUnitId: d, unitId: h } = u, m = wo( n, { unitId: h, subUnitId: d, range: e.fromRange }, { unitId: h, subUnitId: d, range: e.toRange } ); if (m === null) return r.emit(i.t("sheets.info.acrossMergedCell")), !1; const g = a.onCommandExecute({ id: pt.id, params: { ...e } }), f = [ ...(I = g.preRedos) != null ? I : [], ...m.redos, ...g.redos, { id: re.id, params: { unitId: h, subUnitId: d, selections: [{ range: e.toRange, primary: Qa(e.fromRange, e.toRange, c) }], type: Ce.MOVE_END } } ], p = [ ...(w = g.preUndos) != null ? w : [], ...m.undos, ...g.undos, { id: re.id, params: { unitId: h, subUnitId: d, selections: [{ range: e.fromRange, primary: ve(e.fromRange, c) }], type: Ce.MOVE_END } } ], C = z(f, t).result, S = a.afterCommandExecute({ id: pt.id, params: { ...e } }); return C ? (z(S.redos, t), o.pushUndoRedo({ unitID: h, undoMutations: [...p, ...S.undos], redoMutations: [...f, ...S.redos] }), !0) : !1; } }; function wo(n, e, t, o = !1) { const s = [], r = [], { range: i, subUnitId: a, unitId: u } = e, { range: l, subUnitId: c } = t, h = n.get(M).getUniverSheetInstance(u), m = h == null ? void 0 : h.getSheetBySheetId(c), g = h == null ? void 0 : h.getSheetBySheetId(a), f = m == null ? void 0 : m.getCellMatrix(), p = g == null ? void 0 : g.getCellMatrix(); if (m && g && f && p) { const C = Ln(l, m, !1); if (!k.equals(l, C) && !o) return null; const S = new G(), I = new G(), w = new G(); K.foreach(i, (U, P) => { const A = p.getValue(U, P); if (S.setValue(U, P, O.deepClone(A)), A) { const j = h == null ? void 0 : h.getStyles().get(A.s); w.setValue(U, P, O.deepClone(j)); } I.setValue(U, P, null); }); const b = new G(), y = new G(); K.foreach(l, (U, P) => { b.setValue(U, P, O.deepClone(f.getValue(U, P))); }), K.foreach(i, (U, P) => { const A = ws(U, P), j = k.getRelativeRange(A, i), Z = k.getPositionRange(j, l), Y = O.deepClone(w.getValue(U, P)), ee = O.deepClone(S.getValue(U, P)); ee && Y && (ee.s = Y), y.setValue(Z.startRow, Z.startColumn, ee); }); const x = { fromRange: e.range, toRange: t.range, from: { value: I.getMatrix(), subUnitId: a }, to: { value: y.getMatrix(), subUnitId: c }, unitId: u }, T = { fromRange: t.range, toRange: e.range, from: { value: S.getMatrix(), subUnitId: a }, to: { value: b.getMatrix(), subUnitId: c }, unitId: u }; s.push({ id: dt.id, params: x }), r.push({ id: dt.id, params: T }); } return { redos: s, undos: r }; } function Qa(n, e, t) { const o = n.startRow, s = n.startColumn, r = t.getMergedCell(o, s), i = ve(e, t); if (r) { const a = r.endRow - r.startRow + 1, u = r.endColumn - r.startColumn + 1; i.endRow = i.startRow + a - 1, i.endColumn = i.startColumn + u - 1, i.actualRow = i.startRow, i.actualColumn = i.startColumn, i.isMerged = !1, i.isMergedMainCell = !0; } return i; } var Sn = /* @__PURE__ */ ((n) => (n[n.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", n[n.UNIVER_DOC = 1] = "UNIVER_DOC", n[n.UNIVER_SHEET = 2] = "UNIVER_SHEET", n[n.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", n[n.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n))(Sn || {}), _ = /* @__PURE__ */ ((n) => (n[n.View = 0] = "View", n[n.Edit = 1] = "Edit", n[n.ManageCollaborator = 2] = "ManageCollaborator", n[n.Print = 3] = "Print", n[n.Duplicate = 4] = "Duplicate", n[n.Comment = 5] = "Comment", n[n.Copy = 6] = "Copy", n[n.Share = 7] = "Share", n[n.Export = 8] = "Export", n[n.MoveWorksheet = 9] = "MoveWorksheet", n[n.DeleteWorksheet = 10] = "DeleteWorksheet", n[n.HideWorksheet = 11] = "HideWorksheet", n[n.RenameWorksheet = 12] = "RenameWorksheet", n[n.CreateWorksheet = 13] = "CreateWorksheet", n[n.SetWorksheetStyle = 14] = "SetWorksheetStyle", n[n.EditWorksheetCell = 15] = "EditWorksheetCell", n[n.InsertHyperlink = 16] = "InsertHyperlink", n[n.Sort = 17] = "Sort", n[n.Filter = 18] = "Filter", n[n.PivotTable = 19] = "PivotTable", n[n.FloatImg = 20] = "FloatImg", n[n.History = 21] = "History", n[n.RwHgtClWdt = 22] = "RwHgtClWdt", n[n.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", n[n.ViewFilter = 24] = "ViewFilter", n[n.MoveSheet = 25] = "MoveSheet", n[n.DeleteSheet = 26] = "DeleteSheet", n[n.HideSheet = 27] = "HideSheet", n[n.CopySheet = 28] = "CopySheet", n[n.RenameSheet = 29] = "RenameSheet", n[n.CreateSheet = 30] = "CreateSheet", n[n.SelectProtectedCells = 31] = "SelectProtectedCells", n[n.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", n[n.SetCellStyle = 33] = "SetCellStyle", n[n.SetCellValue = 34] = "SetCellValue", n[n.SetRowStyle = 35] = "SetRowStyle", n[n.SetColumnStyle = 36] = "SetColumnStyle", n[n.InsertRow = 37] = "InsertRow", n[n.InsertColumn = 38] = "InsertColumn", n[n.DeleteRow = 39] = "DeleteRow", n[n.DeleteColumn = 40] = "DeleteColumn", n[n.EditExtraObject = 41] = "EditExtraObject", n[n.Delete = 42] = "Delete", n[n.RecoverHistory = 43] = "RecoverHistory", n[n.ViewHistory = 44] = "ViewHistory", n[n.CreatePermissionObject = 45] = "CreatePermissionObject", n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n))(_ || {}), D = /* @__PURE__ */ ((n) => (n[n.Unkonwn = 0] = "Unkonwn", n[n.Workbook = 1] = "Workbook", n[n.Worksheet = 2] = "Worksheet", n[n.SelectRange = 3] = "SelectRange", n[n.Document = 4] = "Document", n[n.Slide = 5] = "Slide", n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n))(D || {}); class Pe { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.Edit); R(this, "status", J.INIT); R(this, "value", !0); R(this, "id"); R(this, "unitId"); R(this, "subUnitId"); R(this, "permissionId"); this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Edit}.${o}`; } } class Io { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.View); R(this, "status", J.INIT); R(this, "value", !0); R(this, "id"); R(this, "unitId"); R(this, "subUnitId"); R(this, "permissionId"); this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.View}.${o}`; } } class Ws { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Comment); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Comment}_${e}`; } } class Ls { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Copy); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Copy}_${e}`; } } class eu { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "subType", _.CopySheet); R(this, "status", J.INIT); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CopySheet}_${e}`; } } class Vs { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.CreatePermissionObject); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreatePermissionObject}_${e}`; } } class Hs { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.CreateSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreateSheet}_${e}`; } } class Bs { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.DeleteSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.DeleteSheet}_${e}`; } } class Fs { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Duplicate); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Duplicate}_${e}`; } } class Me { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Edit); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Edit}_${e}`; } } class js { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Export); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Export}_${e}`; } } class vo { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.HideSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.HideSheet}_${e}`; } } class tu { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.History); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.History}_${e}`; } } class Mo { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.ManageCollaborator); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ManageCollaborator}_${e}`; } } class _o { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.MoveSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.MoveSheet}_${e}`; } } class Gs { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Print); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Print}_${e}`; } } class zs { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.RecoverHistory); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RecoverHistory}_${e}`; } } class bo { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.RenameSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RenameSheet}_${e}`; } } class Ks { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.Share); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Share}_${e}`; } } class Js { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.View); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.View}_${e}`; } } class Ys { constructor(e) { R(this, "id"); R(this, "value", !0); R(this, "type", D.Workbook); R(this, "status", J.INIT); R(this, "subType", _.ViewHistory); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ViewHistory}_${e}`; } } class Xs { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.Copy); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Copy}_${e}_${t}`; } } class qs { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.DeleteColumn); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteColumn}_${e}_${t}`; } } class Zs { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.Delete); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Delete}_${e}_${t}`; } } class Qs { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.DeleteRow); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteRow}_${e}_${t}`; } } class Te { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.Edit); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Edit}_${e}_${t}`; } } class er { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.EditExtraObject); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.EditExtraObject}_${e}_${t}`; } } class tr { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.Filter); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Filter}_${e}_${t}`; } } class nr { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.InsertColumn); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertColumn}_${e}_${t}`; } } class or { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.InsertHyperlink); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertHyperlink}_${e}_${t}`; } } class sr { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.InsertRow); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertRow}_${e}_${t}`; } } class rr { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.ManageCollaborator); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.ManageCollaborator}_${e}_${t}`; } } class ir { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.PivotTable); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.PivotTable}_${e}_${t}`; } } class nu { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.SelectProtectedCells); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectProtectedCells}_${e}_${t}`; } } class ou { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.SelectUnProtectedCells); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`; } } class ar { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.SetCellStyle); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellStyle}_${e}_${t}`; } } class wn { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.SetCellValue); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellValue}_${e}_${t}`; } } class $t { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.SetColumnStyle); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetColumnStyle}_${e}_${t}`; } } class Wt { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.SetRowStyle); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetRowStyle}_${e}_${t}`; } } class ur { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.Sort); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Sort}_${e}_${t}`; } } class Hn { constructor(e, t) { R(this, "value", !0); R(this, "type", D.Worksheet); R(this, "status", J.INIT); R(this, "id"); R(this, "subType", _.View); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.View}_${e}_${t}`; } } const on = { id: "sheet.command.set-range-values", type: v.COMMAND, handler: (n, e) => { var T; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = n.get(Fe), u = N(s, e); if (!u) return !1; const { subUnitId: l, unitId: c, workbook: d, worksheet: h } = u, { value: m, range: g } = e, f = g ? [g] : (T = r.getCurrentSelections()) == null ? void 0 : T.map((U) => U.range); if (!f || !f.length || !a.getPermissionPoint(new Te(c, l).id)) return !1; const p = new G(); let C; if (O.isArray(m)) for (let U = 0; U < f.length; U++) { const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U]; for (let Y = 0; Y <= j - P; Y++) for (let ee = 0; ee <= Z - A; ee++) p.setValue(Y + P, ee + A, m[Y][ee]); } else if (Is(m)) for (let U = 0; U < f.length; U++) { const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U]; for (let Y = P; Y <= j; Y++) for (let ee = A; ee <= Z; ee++) p.setValue(Y, ee, m); } else C = m; const S = { subUnitId: l, unitId: c, cellValue: C != null ? C : p.getMatrix() }, I = Ae(n, S); if (!t.syncExecuteCommand(Q.id, S)) return !1; const { undos: b, redos: y } = i.onCommandExecute({ id: on.id, params: { ...S, range: f } }); if (z([...y], t).result) { const U = Xe(g != null ? g : p.getRange(), d, h); return o.pushUndoRedo({ unitID: c, undoMutations: [ { id: Q.id, params: I }, ...b, U ], redoMutations: [ { id: Q.id, params: S }, ...y, O.deepClone(U) ] }), !0; } return !1; } }; function lr(n, e) { const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a, cellValue: u = {} } = e, l = n.get(M), c = n.get(V), d = l.getUniverSheetInstance(s), h = d == null ? void 0 : d.getSheetBySheetId(r); if (h) { const m = h.getCellMatrix(), g = m.getDataRange(); if (i.startColumn <= g.endColumn || i.startRow <= g.endRow) { let I, w; if (a === ge.COLUMNS) { const y = Math.min(i.endRow, g.endRow); let x = 0; for (let U = i.startRow; U <= y; U++) { const P = m.getRow(U), A = P ? vs(P) - 1 : 0; x = Math.max(x, A); } I = { startRow: i.startRow, startColumn: i.startColumn, endRow: y, endColumn: x }; const T = i.endColumn - i.startColumn + 1; w = { startRow: i.startRow, startColumn: I.startColumn + T, endRow: y, endColumn: I.endColumn + T }; } else { const y = Math.min(i.endColumn, g.endColumn), x = g.endRow; I = { startRow: i.startRow, startColumn: i.startColumn, endRow: x, endColumn: y }; const T = i.endRow - i.startRow + 1; w = { startRow: I.startRow + T, startColumn: i.startColumn, endRow: I.endRow + T, endColumn: y }; } const b = wo( n, { unitId: s, subUnitId: r, range: I }, { unitId: s, subUnitId: r, range: w }, !0 ); b && (t.push(...b.redos), o.push(...b.undos)); } if (Object.entries(u).length === 0) for (let I = i.startRow; I <= i.endRow; I++) { u[I] || (u[I] = {}); for (let w = i.startColumn; w <= i.endColumn; w++) u[I][w] = null; } const f = { subUnitId: r, unitId: s, cellValue: u }, p = Ae( n, f ), { undos: C, redos: S } = c.onCommandExecute({ id: on.id, params: { ...f, range: i } }); t.push({ id: Q.id, params: f }, ...S), o.push({ id: Q.id, params: p }, ...C); } return { redo: t, undo: o }; } function cr(n, e) { const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a } = e, u = n.get(M), l = n.get(V), c = u.getUniverSheetInstance(s), d = c == null ? void 0 : c.getSheetBySheetId(r); if (d) { const h = d.getCellMatrix(), m = h.getDataRange(), g = { subUnitId: r, unitId: s, cellValue: Os([i]) }, f = Ae( n, g ), p = l.onCommandExecute({ id: on.id, params: g }); if (t.push({ id: Q.id, params: g }, ...p.redos), o.push(...p.undos, { id: Q.id, params: f }), i.startColumn <= m.endColumn || i.startRow <= m.endRow) { let C = null, S = null; if (a === ge.COLUMNS && i.endColumn < m.endColumn) { const I = Math.min(i.endRow, m.endRow); let w = 0; for (let y = i.startRow; y <= I; y++) { const x = h.getRow(y), T = x ? vs(x) - 1 : 0; w = Math.max(w, T); } C = { startRow: i.startRow, startColumn: i.endColumn + 1, endRow: I, endColumn: w }; const b = i.endColumn - i.startColumn + 1; S = { startRow: i.startRow, startColumn: C.startColumn - b, endRow: I, endColumn: C.endColumn - b }; } if (a === ge.ROWS && i.endRow < m.endRow) { const I = Math.min(i.endColumn, m.endColumn), w = m.endRow; C = { startRow: i.endRow + 1, startColumn: i.startColumn, endRow: w, endColumn: I }; const b = i.endRow - i.startRow + 1; S = { startRow: C.startRow - b, startColumn: i.startColumn, endRow: C.endRow - b, endColumn: I }; } if (C && S) { const I = wo( n, { unitId: s, subUnitId: r, range: C }, { unitId: s, subUnitId: r, range: S }, !0 ); I && (t.push(...I.redos), o.push(...I.undos)); } } } return { redo: t, undo: o }; } function Yd(n, e, t, o, s, r) { const { startRow: i, endRow: a, startColumn: u, endColumn: l } = e; if (s === ge.ROWS) { const c = a - i + 1; for (let d = t; d >= i; d--) for (let h = u; h <= l; h++) { const m = n.getValue(d, h); m == null ? n.realDeleteValue(d + c, h) : n.setValue(d + c, h, m); } for (let d = a; d >= i; d--) for (let h = u; h <= l; h++) r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h); } else if (s === ge.COLUMNS) { const c = l - u + 1; for (let d = i; d <= a; d++) for (let h = o; h >= u; h--) { const m = n.getValue(d, h); m == null ? n.realDeleteValue(d, h + c) : n.setValue(d, h + c, m); } for (let d = i; d <= a; d++) for (let h = l; h >= u; h--) r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h); } } function Xd(n, e, t, o, s) { const { startRow: r, endRow: i, startColumn: a, endColumn: u } = e, l = i - r + 1, c = u - a + 1; if (s === ge.ROWS) for (let d = r; d <= t; d++) for (let h = a; h <= u; h++) { const m = n.getValue(d + l, h); m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m); } else if (s === ge.COLUMNS) for (let d = r; d <= i; d++) for (let h = a; h <= o; h++) { const m = n.getValue(d, h + c); m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m); } } const dr = "sheet.command.delete-range-move-left", Pt = { type: v.COMMAND, id: dr, handler: async (n, e) => { var w, b, y; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = N(s); if (!a) return !1; const { worksheet: u, workbook: l, subUnitId: c, unitId: d } = a; let h = e == null ? void 0 : e.range; if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h) return !1; const m = { range: h, subUnitId: c, unitId: d, shiftDimension: ge.COLUMNS }, g = i.onCommandExecute({ id: Pt.id, params: { range: h } }), { redo: f, undo: p } = cr( n, m ), C = [...(b = g.preRedos) != null ? b : [], ...f], S = [...g.undos, ...p]; return C.push(...g.redos), C.push(Xe(h, l, u)), S.push(...(y = g.preUndos) != null ? y : []), z(C, t).result ? (o.pushUndoRedo({ unitID: d, undoMutations: S.reverse(), redoMutations: C }), !0) : !1; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }, hr = "sheet.command.delete-range-move-up", Tt = { type: v.COMMAND, id: hr, handler: async (n, e) => { var w, b, y; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = N(s); if (!a) return !1; const { unitId: u, subUnitId: l, workbook: c, worksheet: d } = a; let h = e == null ? void 0 : e.range; if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h) return !1; const m = { range: h, subUnitId: l, unitId: u, shiftDimension: ge.ROWS }, g = i.onCommandExecute({ id: Tt.id, params: { range: h } }), { redo: f, undo: p } = cr( n, m ), C = [...(b = g.preRedos) != null ? b : [], ...f], S = [...g.undos, ...p]; return C.push(...g.redos), C.push(Xe(h, c, d)), S.push(...(y = g.preUndos) != null ? y : []), z(C, t).result ? (o.pushUndoRedo({ unitID: u, undoMutations: S.reverse(), redoMutations: C }), !0) : !1; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }, su = { type: v.COMMAND, id: "sheet.command.delete-range-protection", async handler(n, e) { if (!e) return !1; const t = n.get(E), o = n.get(W), { unitId: s, subUnitId: r, rule: i } = e, a = { unitId: s, subUnitId: r, ruleIds: [i.id] }; return await t.executeCommand(ze.id, a) && o.pushUndoRedo({ unitID: s, redoMutations: [{ id: ze.id, params: a }], undoMutations: [{ id: Ne.id, params: { unitId: s, subUnitId: r, rules: [i] } }] }), !0; } }, ru = { type: v.COMMAND, id: "sheet.command.delete-worksheet-protection", handler(n, e) { if (!e) return !1; const t = n.get(E), o = n.get(W), { rule: s, unitId: r, subUnitId: i } = e; t.executeCommand(St.id, { unitId: r, subUnitId: i }); const a = [{ id: St.id, params: { unitId: r, subUnitId: i } }], u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: i } }]; return o.pushUndoRedo({ unitID: r, redoMutations: a, undoMutations: u }), !0; } }, iu = { type: v.COMMAND, id: "sheet.command.remove-worksheet-range-theme-style", handler: (n, e) => { const t = n.get(E), o = n.get(W), { unitId: s } = e, r = _a(n, e); return t.syncExecuteCommand(Kt.id, e) ? (o.pushUndoRedo({ unitID: s, undoMutations: [{ id: zt.id, params: r }], redoMutations: [{ id: Kt.id, params: e }] }), !0) : !1; } }, au = { id: "sheet.command.insert-defined-name", type: v.COMMAND, handler: (n, e) => { const t = n.get(E), o = n.get(W); if (!e) return !1; const s = { ...e }; return t.syncExecuteCommand(Gt.id, s) ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: [{ id: Cn.id, params: s }], redoMutations: [{ id: Gt.id, params: s }] }), !0) : !1; } }, mr = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range }; }, qe = { id: "sheet.mutation.insert-row", type: v.MUTATION, handler: (n, e) => { var g; const { unitId: t, subUnitId: o, range: s, rowInfo: r } = e, a = n.get(M).getUniverSheetInstance(t); if (a == null) throw new Error("universheet is null error!"); const u = a.getSheetBySheetId(o); if (u == null) throw new Error("worksheet is null error!"); const l = u.getRowManager().getRowData(), c = { h: u.getConfig().defaultRowHeight, hd: 0 }, d = s.startRow, h = s.endRow - s.startRow + 1; for (let f = d; f < d + h; f++) r ? pn(f, (g = r[f - s.startRow]) != null ? g : c, l) : pn(f, c, l); return u.setRowCount(u.getRowCount() + s.endRow - s.startRow + 1), u.getCellMatrix().insertRows(s.startRow, h), !0; } }, yo = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range }; }, je = { id: "sheet.mutation.insert-col", type: v.MUTATION, handler: (n, e) => { var g; const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return !1; const r = s.getColumnManager(), { range: i, colInfo: a } = e, l = r.getColumnData(), c = i.startColumn, d = i.endColumn - i.startColumn + 1, h = s.getConfig().defaultColumnWidth; for (let f = c; f < c + d; f++) { const p = { w: h, hd: 0 }; a ? pn(f, (g = a[f - i.startColumn]) != null ? g : p, l) : pn(f, p, l); } return s.setColumnCount(s.getColumnCount() + i.endColumn - i.startColumn + 1), s.getCellMatrix().insertColumns(i.startColumn, d), !0; } }, uu = (n, e) => { const s = e.getRowManager().getRowData(), r = {}, i = n.range, a = _s(i.startRow, i.endRow, s), u = bs(r, a); return { unitId: n.unitId, subUnitId: n.subUnitId, range: n.range, rowInfo: u }; }, Be = { id: "sheet.mutation.remove-rows", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return !1; const r = e.range, a = s.getRowManager().getRowData(); for (let c = r.startRow; c <= r.endRow; c++) s.getRowFiltered(c); const u = r.endRow - r.startRow + 1; return Ms(r.startRow, u, a), s.getCellMatrix().removeRows(r.startRow, u), s.setRowCount(s.getRowCount() - u), !0; } }, lu = (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (s == null) throw new Error("worksheet is null error!"); const a = s.getColumnManager().getColumnData(), u = {}, l = e.range, c = _s(l.startColumn, l.endColumn, a), d = bs(u, c); return { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, colInfo: d }; }, De = { id: "sheet.mutation.remove-col", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return !1; const r = e.range, a = s.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1; return Ms(r.startColumn, u, a), s.setColumnCount(s.getColumnCount() - u), s.getCellMatrix().removeColumns(r.startColumn, u), !0; } }, cu = "sheet.command.insert-range-move-down", sn = { type: v.COMMAND, id: "sheet.command.insert-range-move-down", // eslint-disable-next-line max-lines-per-function handler: async (n, e) => { var j, Z, Y; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = n.get(bt), u = n.get(Ke); if (r.isOverlapping()) return a.emit(u.t("sheets.info.overlappingSelections")), !1; const l = N(s); if (!l) return !1; const { unitId: c, subUnitId: d, worksheet: h, workbook: m } = l; let g = e == null ? void 0 : e.range; if (g || (g = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g) return !1; const f = [], p = [], C = h.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(S.startRow, S.endRow, g.startColumn, g.endColumn).getDataRange().endRow, b = Math.max(w + (g.endRow - g.startRow + 1) - S.endRow, 0); if (b > 0) { const ee = g.startRow - 1, Re = h.getRowHeight(ee), ie = { unitId: c, subUnitId: d, range: { startRow: S.endRow + 1, endRow: S.endRow + b, startColumn: S.startColumn, endColumn: S.endColumn }, rowInfo: new Array(b).fill(void 0).map(() => ({ h: Re, hd: te.FALSE })) }; f.push({ id: qe.id, params: ie }); const xe = mr( n, ie ); p.push({ id: Be.id, params: xe }); } const y = {}; K.foreach(g, (ee, Re) => { const ie = h.getCell(ee, Re); ie && (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s }); }); const x = { range: g, subUnitId: d, unitId: c, shiftDimension: ge.ROWS, cellValue: y }, { redo: T, undo: U } = lr( n, x ); f.push(...T), p.push(...U); const P = i.onCommandExecute({ id: sn.id, params: { range: g } }); return f.push(...P.redos), f.push(Xe(g, m, h)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), z(f, t) ? (o.pushUndoRedo({ unitID: c, undoMutations: p.reverse(), redoMutations: f }), !0) : !1; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }, Eo = "sheet.command.insert-range-move-right", Bn = { type: v.COMMAND, id: Eo, // eslint-disable-next-line max-lines-per-function handler: async (n, e) => { var j, Z, Y; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = n.get(bt), u = n.get(Ke); if (r.isOverlapping()) return a.emit(u.t("sheets.info.overlappingSelections")), !1; const l = N(s); if (!l) return !1; const { workbook: c, worksheet: d, unitId: h, subUnitId: m } = l; let g = e == null ? void 0 : e.range; if (g || (g = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g) return !1; const f = [], p = [], C = d.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(g.startRow, g.endRow, S.startColumn, S.endColumn).getDataRange().endColumn, b = Math.max( w + (g.endColumn - g.startColumn + 1) - S.endColumn, 0 ); if (b > 0) { const ee = g.startColumn - 1, Re = d.getColumnWidth(ee), ie = { unitId: h, subUnitId: m, range: { startRow: S.startRow + 1, endRow: S.endRow, startColumn: S.endColumn + 1, endColumn: S.endColumn + b }, colInfo: new Array(b).fill(void 0).map(() => ({ w: Re, hd: te.FALSE })) }; f.push({ id: je.id, params: ie }); const xe = yo( n, ie ); p.push({ id: De.id, params: xe }); } const y = {}; K.foreach(g, (ee, Re) => { const ie = d.getCell(ee, Re); !ie || !ie.s || (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s }); }); const x = { range: g, subUnitId: m, unitId: h, shiftDimension: ge.COLUMNS, cellValue: y }, { redo: T, undo: U } = lr( n, x ); f.push(...T), p.push(...U); const P = i.onCommandExecute({ id: Bn.id, params: { range: g } }); return f.push(...P.redos), f.push(Xe(g, c, d)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), z(f, t).result ? (o.pushUndoRedo({ unitID: h, undoMutations: p.reverse(), redoMutations: f }), !0) : !1; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }, gr = "sheet.command.insert-row", mt = { type: v.COMMAND, id: gr, handler: async (n, e) => { const t = n.get(E), o = n.get(V), { range: s, direction: r, unitId: i, subUnitId: a, cellValue: u } = e; return await o.beforeCommandExecute({ id: mt.id, params: e }) ? t.syncExecuteCommand(fr.id, { range: s, direction: r, unitId: i, subUnitId: a, cellValue: u }) : !1; } }, fr = { type: v.COMMAND, id: "sheet.command.insert-row-by-range", handler: (n, e) => { var T, U, P, A; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = N(s, e); if (!i) return !1; const { workbook: a, worksheet: u } = i, { range: l, direction: c, unitId: d, subUnitId: h, cellValue: m } = e, { startRow: g, endRow: f } = l; l.rangeType = H.ROW; const p = c === pe.UP ? g : g - 1, C = u.getRowHeight(p), S = { unitId: d, subUnitId: h, range: l, rowInfo: new Array(f - g + 1).fill(void 0).map(() => ({ h: C, hd: te.FALSE })) // row height should inherit from the anchor row }, I = mr( n, S ), w = [{ id: qe.id, params: S }], b = [{ id: Be.id, params: I }]; m && w.push({ id: Q.id, params: { unitId: d, subUnitId: h, cellValue: m } }); const y = r.onCommandExecute({ id: mt.id, params: e }); return w.unshift(...(T = y.preRedos) != null ? T : []), w.push(...(U = y.redos) != null ? U : []), w.push(Xe(l, a, u)), b.unshift(...(P = y.preUndos) != null ? P : []), b.push(...(A = y.undos) != null ? A : []), z(w, t).result ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: b, redoMutations: w }), !0) : !1; } }, du = { type: v.COMMAND, id: "sheet.command.insert-row-before", handler: async (n) => { var g; const t = (g = n.get(F).getCurrentSelections()) == null ? void 0 : g.map((f) => f.range); let o; if ((t == null ? void 0 : t.length) === 1) o = t[0]; else return !1; const s = n.get(M), r = N(s); if (!r) return !1; const { worksheet: i, subUnitId: a, unitId: u } = r, { startRow: l, endRow: c } = o, d = 0, h = i.getColumnCount() - 1, m = { unitId: u, subUnitId: a, direction: pe.UP, range: { startRow: l, endRow: c, startColumn: d, endColumn: h }, // copy styles from the row above cellValue: Vn(i, l, c, d, h, !0, l - 1) }; return n.get(E).executeCommand(mt.id, m); } }, hu = { type: v.COMMAND, id: "sheet.command.insert-row-after", handler: async (n) => { var f; const t = (f = n.get(F).getCurrentSelections()) == null ? void 0 : f.map((p) => p.range); let o; if ((t == null ? void 0 : t.length) === 1) o = t[0]; else return !1; const s = n.get(M), r = N(s); if (!r) return !1; const { worksheet: i, unitId: a, subUnitId: u } = r, l = o.endRow - o.startRow + 1, c = o.endRow + 1, d = o.endRow + l, h = 0, m = i.getColumnCount() - 1, g = { unitId: a, subUnitId: u, direction: pe.DOWN, range: { startRow: c, endRow: d, startColumn: h, endColumn: m, rangeType: H.ROW }, // copy styles from the row below cellValue: Vn(i, c, d, h, m, !0, o.endRow) }; return n.get(E).executeCommand(mt.id, g); } }, Rr = "sheet.command.insert-col", gt = { type: v.COMMAND, id: Rr, handler: async (n, e) => { const t = n.get(E), o = n.get(V), { range: s, direction: r, subUnitId: i, unitId: a, cellValue: u } = e; return await o.beforeCommandExecute({ id: gt.id, params: e }) ? t.syncExecuteCommand(pr.id, { range: s, direction: r, unitId: a, subUnitId: i, cellValue: u }) : !1; } }, pr = { type: v.COMMAND, id: "sheet.command.insert-col-by-range", handler: (n, e) => { var x, T, U, P; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), { range: i, direction: a, subUnitId: u, unitId: l, cellValue: c } = e, { startColumn: d, endColumn: h } = e.range; i.rangeType = H.COLUMN; const m = s.getUniverSheetInstance(e.unitId), g = m.getSheetBySheetId(e.subUnitId), f = a === pe.LEFT ? d : d - 1, p = g.getColumnWidth(f), C = { unitId: l, subUnitId: u, range: i, colInfo: new Array(h - d + 1).fill(void 0).map(() => ({ w: p, hd: te.FALSE })) }, S = yo( n, C ), I = [{ id: je.id, params: C }], w = [{ id: De.id, params: S }]; c && I.push({ id: Q.id, params: { unitId: l, subUnitId: u, cellValue: c } }); const b = r.onCommandExecute({ id: gt.id, params: e }); return I.unshift(...(x = b.preRedos) != null ? x : []), I.push(...(T = b.redos) != null ? T : []), I.push(Xe(i, m, g)), w.unshift(...(U = b.preUndos) != null ? U : []), w.push(...(P = b.undos) != null ? P : []), z(I, t).result ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: w.filter(Boolean), redoMutations: I.filter(Boolean) }), !0) : !1; } }, mu = { type: v.COMMAND, id: "sheet.command.insert-col-before", handler: async (n) => { const t = n.get(F).getCurrentSelections(); let o; if ((t == null ? void 0 : t.length) === 1) o = t[0].range; else return !1; const s = n.get(M), r = N(s); if (!r) return !1; const { worksheet: i, unitId: a, subUnitId: u } = r, { startColumn: l, endColumn: c } = o, d = 0, h = i.getRowCount() - 1, m = { unitId: a, subUnitId: u, direction: pe.LEFT, range: { startColumn: l, endColumn: c, startRow: d, endRow: h, rangeType: H.COLUMN }, // copy styles from the column before cellValue: Vn(i, d, h, l, c, !1, l - 1) }; return n.get(E).executeCommand(gt.id, m); } }, gu = { type: v.COMMAND, id: "sheet.command.insert-col-after", handler: async (n) => { const t = n.get(F).getCurrentSelections(); let o; if ((t == null ? void 0 : t.length) === 1) o = t[0].range; else return !1; const s = n.get(M), r = N(s); if (!r) return !1; const { worksheet: i, unitId: a, subUnitId: u } = r, l = o.endColumn - o.startColumn + 1, c = o.endColumn + 1, d = o.endColumn + l, h = 0, m = i.getRowCount() - 1, g = { unitId: a, subUnitId: u, direction: pe.RIGHT, range: { startColumn: c, endColumn: d, startRow: h, endRow: m }, // copy styles from the column after cellValue: Vn(i, h, m, c, d, !1, o.endColumn) }; return n.get(E).executeCommand(gt.id, g); } }, fu = { id: "sheet.command.insert-sheet", type: v.COMMAND, handler: (n, e) => { var p; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(Ke), i = va(s, { unitId: e == null ? void 0 : e.unitId }); if (!i) return !1; const { unitId: a, workbook: u } = i; let l = u.getSheets().length; const c = e == null ? void 0 : e.sheet, d = c == null ? void 0 : c.id, h = mi(c || {}); e ? (l = (p = e.index) != null ? p : l, h.id = d || O.generateRandomId(), h.name = (c == null ? void 0 : c.name) || u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)) : (h.id = O.generateRandomId(), h.name = u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)); const m = { index: l, sheet: h, unitId: a }, g = As( n, m ); return t.syncExecuteCommand(Jt.id, m) ? (o.pushUndoRedo({ unitID: a, undoMutations: [{ id: Ut.id, params: g }], redoMutations: [{ id: Jt.id, params: m }] }), !0) : !1; } }; function Ru(n, e) { const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startRow > r.startRow, a = s.endRow - s.startRow + 1; return i ? { unitId: t, subUnitId: o, sourceRange: k.clone(r), targetRange: { ...s, endRow: s.endRow + a, startRow: s.startRow + a } } : { unitId: t, subUnitId: o, targetRange: k.clone(s), sourceRange: { ...r, endRow: r.endRow - a, startRow: r.startRow - a } }; } const ot = { id: "sheet.mutation.move-rows", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(M).getUniverSheetInstance(t); if (!a) throw new Error("[MoveRowMutation] univerSheet is null!"); const u = a.getSheetBySheetId(o); if (!u) throw new Error("[MoveRowMutation] worksheet is null!"); const l = s.startRow, c = s.endRow - s.startRow + 1, d = r.startRow, h = u.getRowManager().getRowData(); return ys(l, c, d, h), u.getCellMatrix().moveRows(l, c, d), !0; } }; function pu(n, e) { const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startColumn > r.startColumn, a = s.endColumn - s.startColumn + 1; return i ? { unitId: t, subUnitId: o, sourceRange: k.clone(r), targetRange: { ...s, endColumn: s.endColumn + a, startColumn: s.startColumn + a } } : { unitId: t, subUnitId: o, targetRange: k.clone(s), sourceRange: { ...r, startColumn: r.startColumn - a, endColumn: r.endColumn - a } }; } const st = { id: "sheet.mutation.move-columns", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(M).getUniverSheetInstance(t); if (!a) throw new Error("[MoveColumnMutation] univerSheet is null!"); const u = a.getSheetBySheetId(o); if (!u) throw new Error("[MoveColumnMutation] worksheet is null!"); const l = s.startColumn, c = s.endColumn - s.startColumn + 1, d = r.startColumn, h = u.getColumnManager().getColumnData(); return ys(l, c, d, h), u.getCellMatrix().moveColumns(l, c, d), !0; } }; function Cu(n, e) { return e.getMergeData().some((t) => t.startRow < n && n <= t.endRow); } function Su(n, e) { return e.getMergeData().some((t) => t.startColumn < n && n <= t.endColumn); } const Cr = "sheet.command.move-rows", Fn = { id: Cr, type: v.COMMAND, // eslint-disable-next-line max-lines-per-function handler: (n, e) => { var j, Z; const t = n.get(F), { fromRange: { startRow: o }, toRange: { startRow: s }, range: r } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter( (Y) => Y.range.rangeType === H.ROW && Y.range.startRow <= o && o <= Y.range.endRow ); if ((a == null ? void 0 : a.length) !== 1) return !1; const u = n.get(V), l = n.get(M), c = N(l, e); if (!c) return !1; const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g = h.getSheetId(), f = n.get(bt), p = n.get(Ke), C = a[0].range, S = a[0].primary, I = Ln(C, h, !1); if (!k.equals(C, I)) return f.emit(p.t("sheets.info.partOfCell")), !1; if (Cu(s, h)) return f.emit(p.t("sheets.info.acrossMergedCell")), !1; const w = { ...C, startRow: s, endRow: s + C.endRow - C.startRow }, b = { unitId: m, subUnitId: g, sourceRange: C, targetRange: w }, y = Ru(n, b), x = n.get(E), T = u.onCommandExecute({ id: Fn.id, params: e }), U = [ ...(j = T.preRedos) != null ? j : [], { id: ot.id, params: b } ], P = [ ...(Z = T.preUndos) != null ? Z : [], { id: ot.id, params: y } ]; if (S) { const ee = s - o < 0, Re = C.endRow - C.startRow + 1, ie = ee ? w : { ...w, startRow: w.startRow - Re, endRow: w.endRow - Re }, xe = { unitId: m, subUnitId: g, type: Ce.MOVE_END, selections: [{ range: ie, primary: ve(ie, h), style: null }] }, ft = { unitId: m, subUnitId: g, type: Ce.MOVE_END, selections: [{ range: C, primary: S, style: null }] }; U.push({ id: re.id, params: xe }), P.push({ id: re.id, params: ft }); } return U.push(...T.redos), P.push(...T.undos), z(U, x).result ? (n.get(W).pushUndoRedo({ unitID: m, undoMutations: P, redoMutations: U }), !0) : !1; } }, Sr = "sheet.command.move-cols", jn = { id: Sr, type: v.COMMAND, // eslint-disable-next-line max-lines-per-function handler: (n, e) => { var j, Z; const t = n.get(F), { fromRange: { startColumn: o }, toRange: { startColumn: s }, range: r } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter( (Y) => Y.range.rangeType === H.COLUMN && Y.range.startColumn <= o && o <= Y.range.endColumn ); if ((a == null ? void 0 : a.length) !== 1) return !1; const u = n.get(V), l = n.get(M), c = N(l, e); if (!c) return !1; const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g = h.getSheetId(), f = n.get(bt), p = n.get(Ke), C = a[0].range, S = a[0].primary, I = Ln(C, h, !1); if (!k.equals(C, I)) return f.emit(p.t("sheets.info.partOfCell")), !1; if (Su(s, h)) return f.emit(p.t("sheets.info.acrossMergedCell")), !1; const w = { ...C, startColumn: s, endColumn: s + C.endColumn - C.startColumn }, b = { unitId: m, subUnitId: g, sourceRange: C, targetRange: w }, y = pu(n, b), x = n.get(E), T = u.onCommandExecute({ id: jn.id, params: e }), U = [ ...(j = T.preRedos) != null ? j : [], { id: st.id, params: b } ], P = [ ...(Z = T.preUndos) != null ? Z : [], { id: st.id, params: y } ]; if (S) { const Y = C.endColumn - C.startColumn + 1, ie = s - o < 0 ? w : { ...w, startColumn: w.startColumn - Y, endColumn: w.endColumn - Y }, xe = { unitId: m, subUnitId: g, type: Ce.MOVE_END, selections: [{ range: ie, primary: ve(ie, h), style: null }] }, ft = { unitId: m, subUnitId: g, type: Ce.MOVE_END, selections: [{ range: C, primary: S, style: null }] }; U.push({ id: re.id, params: xe }), P.push({ id: re.id, params: ft }); } return U.push(...T.redos), P.push(...T.undos), z(U, x).result && n.get(W).pushUndoRedo({ unitID: m, undoMutations: P, redoMutations: U }), !0; } }; function wr(n) { return { range: n, primary: null, style: null }; } const Yt = { id: "sheet.mutation.register-worksheet-range-theme-style", type: v.MUTATION, handler: (n, e) => { const { unitId: t, rangeThemeStyleJson: o, themeName: s } = e, r = n.get(M), i = N(r), a = n.get(He); if (!i) return !1; const u = new yt(s, o); return a.registerRangeThemeStyle(t, u), !0; } }, Uo = { id: "sheet.mutation.unregister-worksheet-range-theme-style", type: v.MUTATION, handler: (n, e) => { const { unitId: t, themeName: o } = e, s = n.get(M), r = N(s), i = n.get(He); return r ? (i.unregisterRangeThemeStyle(t, o), !0) : !1; } }, wu = { id: "sheet.command.register-worksheet-range-theme-style", type: v.COMMAND, handler: (n, e) => { if (!e) return !1; const { unitId: t, rangeThemeStyle: o } = e, s = n.get(M), r = n.get(E), i = n.get(W); if (!N(s)) return !1; const u = { unitId: t, themeName: o.getName(), rangeThemeStyleJson: o.toJson() }, l = { unitId: t, themeName: o.getName() }; return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({ unitID: t, undoMutations: [{ id: Uo.id, params: l }], redoMutations: [{ id: Yt.id, params: u }] }), !0; } }, Ir = { id: "sheet.command.remove-defined-name", type: v.COMMAND, handler: (n, e) => { var c, d; const t = n.get(E), o = n.get(W), s = n.get(V); if (!e) return !1; const r = { ...e }, i = s.onCommandExecute({ id: Ir.id, params: e }), a = [ ...(c = i.preRedos) != null ? c : [], { id: Cn.id, params: r }, ...i.redos ], u = [ ...(d = i.preUndos) != null ? d : [], { id: Gt.id, params: r }, ...i.undos ]; return z(a, t) ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: u.filter(Boolean), redoMutations: a.filter(Boolean) }), !0) : !1; } }, Po = "sheet.command.remove-row", vr = { type: v.COMMAND, id: "sheet.command.remove-row-by-range", handler: (n, e) => { var C, S, I; if (!e) return !1; const t = n.get(M), o = N(t, e); if (!o) return !1; const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = { unitId: u, subUnitId: l, range: a }, d = uu( c, r ), h = r.getCellMatrix().getSlice(a.startRow, a.endRow, 0, r.getColumnCount() - 1), m = { unitId: u, subUnitId: l, cellValue: h.getMatrix() }, g = i.onCommandExecute({ id: Po, params: { range: a } }), f = n.get(E); return z( [ ...(C = g.preRedos) != null ? C : [], { id: Be.id, params: c }, ...g.redos, Xe(a, s, r) ], f ).result ? (n.get(W).pushUndoRedo({ unitID: u, undoMutations: [ ...(S = g.preUndos) != null ? S : [], { id: qe.id, params: d }, { id: Q.id, params: m }, ...g.undos ], redoMutations: [ ...(I = g.preRedos) != null ? I : [], { id: Be.id, params: c }, ...g.redos ] }), !0) : !1; } }, Gn = { type: v.COMMAND, id: Po, handler: async (n, e) => { var h; const t = n.get(F), o = n.get(V), s = n.get(E); let r = e == null ? void 0 : e.range; if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return !1; const i = n.get(M), a = N(i); if (!a) return !1; const { worksheet: u, subUnitId: l, unitId: c } = a; return r = { ...r, startColumn: 0, endColumn: Math.max(u.getMaxColumns() - 1, 0) }, await o.beforeCommandExecute({ id: Gn.id, params: { range: r } }) ? s.syncExecuteCommand(vr.id, { range: r, unitId: c, subUnitId: l }) : !1; } }, To = "sheet.command.remove-col", Mr = { type: v.COMMAND, id: "sheet.command.remove-col-by-range", handler: (n, e) => { var C, S, I; if (!e) return !1; const t = n.get(M), o = N(t, e); if (!o) return !1; const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = { unitId: u, subUnitId: l, range: a }, d = lu(n, c), h = r.getCellMatrix().getSlice(0, r.getRowCount() - 1, a.startColumn, a.endColumn), m = { unitId: u, subUnitId: l, cellValue: h.getMatrix() }, g = i.onCommandExecute({ id: To, params: { range: a } }), f = n.get(E); return z( [ ...(C = g.preRedos) != null ? C : [], { id: De.id, params: c }, ...g.redos, Xe(a, s, r) ], f ).result ? (n.get(W).pushUndoRedo({ unitID: u, undoMutations: [ ...(S = g.preUndos) != null ? S : [], { id: je.id, params: d }, { id: Q.id, params: m }, ...g.undos ], redoMutations: [ ...(I = g.preRedos) != null ? I : [], { id: De.id, params: c }, ...g.redos ] }), !0) : !1; } }, zn = { type: v.COMMAND, id: To, handler: async (n, e) => { var h; const t = n.get(F), o = n.get(V), s = n.get(E); let r = e == null ? void 0 : e.range; if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return !1; const i = n.get(M), a = N(i); if (!a) return !1; const { worksheet: u, subUnitId: l, unitId: c } = a; return r = { ...r, startRow: 0, endRow: Math.max(u.getMaxRows() - 1, 0) }, await o.beforeCommandExecute({ id: zn.id, params: { range: r } }) ? s.syncExecuteCommand(Mr.id, { range: r, unitId: c, subUnitId: l }) : !1; } }, ko = { id: "sheet.command.remove-sheet", type: v.COMMAND, handler: (n, e) => { var C, S; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = N(s, e); if (!i) return !1; const { unitId: a, subUnitId: u, workbook: l, worksheet: c } = i; if (l.getSheets().length <= 1) return !1; const d = { subUnitId: u, unitId: a, subUnitName: c.getName() }, h = ja( n, d ), m = r.onCommandExecute({ id: ko.id, params: { unitId: a, subUnitId: u } }), g = [...(C = m.preRedos) != null ? C : [], { id: Ut.id, params: d }, ...m.redos], f = [...(S = m.preUndos) != null ? S : [], { id: Jt.id, params: h }, ...m.undos]; return z(g, t).result ? (o.pushUndoRedo({ unitID: a, undoMutations: f, redoMutations: g }), !0) : !1; } }, Ue = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: O.deepClone(e.ranges) }; }, ne = { id: "sheet.mutation.add-worksheet-merge", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return !1; const i = s.getConfig().mergeData, a = e.ranges; for (let u = 0; u < a.length; u++) i.push(a[u]); return s.getSpanModel().rebuild(i), !0; } }, Se = (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (s == null) throw new Error("worksheet is null error!"); const i = s.getConfig().mergeData, a = e.ranges, u = []; for (let l = 0; l < a.length; l++) for (let c = i.length - 1; c >= 0; c--) { const d = i[c], h = a[l]; k.intersects(d, h) && u.push(i[c]); } return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: u }; }, oe = { id: "sheet.mutation.remove-worksheet-merge", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return !1; const i = s.getConfig().mergeData, a = e.ranges; for (let u = 0; u < a.length; u++) for (let l = i.length - 1; l >= 0; l--) { const c = i[l], d = a[u]; k.intersects(c, d) && i.splice(l, 1); } return s.getSpanModel().rebuild(i), !0; } }, Iu = { type: v.COMMAND, id: "sheet.command.remove-worksheet-merge", // eslint-disable-next-line max-lines-per-function handler: (n, e) => { var A; const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), i = (e == null ? void 0 : e.ranges) || ((A = t.getCurrentSelections()) == null ? void 0 : A.map((j) => j.range)); if (!(i != null && i.length)) return !1; const a = N(r); if (!a) return !1; const { subUnitId: u, unitId: l, worksheet: c } = a, d = { unitId: l, subUnitId: u, ranges: i }, m = c.getConfig().mergeData.filter((j) => i.some((Z) => k.intersects(Z, j))); if (!m.length) return !1; const g = Se( n, d ), f = t.getCurrentSelections(); if (!(f != null && f.length)) return !1; const p = O.deepClone(f), C = O.deepClone(f), S = C[C.length - 1], { startRow: I, startColumn: w } = S.range; S.primary = { startRow: I, startColumn: w, endRow: I, endColumn: w, actualRow: I, actualColumn: w, isMerged: !1, isMergedMainCell: !1 }; const b = vu(c, m), y = { unitId: l, subUnitId: u, cellValue: b.redoParams.getMatrix() }, x = { unitId: l, subUnitId: u, cellValue: b.undoParams.getMatrix() }, T = [ { id: oe.id, params: g }, { id: Q.id, params: y }, { id: re.id, params: { selections: C } } ], U = [ { id: ne.id, params: g }, { id: Q.id, params: x }, { id: re.id, params: { selections: p } } ]; return z(T, o) ? (s.pushUndoRedo({ unitID: l, undoMutations: U, redoMutations: T }), !0) : !1; } }; function vu(n, e) { const t = new G(), o = new G(); return e.forEach((s) => { const { startRow: r, startColumn: i, endColumn: a, endRow: u } = s, l = n.getCellMatrix().getValue(r, i); if (l != null && l.s) for (let c = r; c <= u; c++) for (let d = i; d <= a; d++) (c !== r || d !== i) && (t.setValue(c, d, { s: l.s }), o.setValue(c, d, null)); }), { redoParams: t, undoParams: o }; } const Mu = (n) => { const { order: e } = n, t = {}; return Object.keys(e).forEach((o) => { t[e[Number(o)]] = Number(o); }), { ...n, order: t }; }, In = { id: "sheet.mutation.reorder-range", type: v.MUTATION, handler: (n, e) => { const { subUnitId: t, unitId: o, range: s, order: r } = e, u = n.get(M).getUnit(o).getSheetBySheetId(t); if (!u) return !1; const l = new G(); K.foreach(s, (d, h) => { if (r.hasOwnProperty(d)) { const m = r[d], g = O.deepClone(u.getCellRaw(m, h)); l.setValue(d, h, g); } }); const c = u.getCellMatrix(); return l.forValue((d, h, m) => { c.setValue(d, h, m); }), !0; } }, _r = "sheet.command.reorder-range", uo = { id: _r, type: v.COMMAND, handler: (n, e) => { var f, p; const { subUnitId: t, unitId: o, range: s, order: r } = e, i = n.get(E), a = { id: In.id, params: { unitId: o, subUnitId: t, order: r, range: s } }, u = { id: In.id, params: Mu(a.params) }, l = n.get(V), c = l.onCommandExecute({ id: uo.id, params: e }), d = [ ...(f = c.preRedos) != null ? f : [], a, ...c.redos ], h = [ ...(p = c.preUndos) != null ? p : [], u, ...c.undos ], m = z(d, i), g = l.afterCommandExecute({ id: uo.id, params: e }); return m.result ? (z(g.redos, i), n.get(W).pushUndoRedo({ unitID: o, undoMutations: [...h, ...g.undos], redoMutations: [...d, ...g.redos] }), !0) : !1; } }; class kt { constructor() { R(this, "_borderInfo", { type: ue.ALL, color: "#000000", style: Rs.THIN, activeBorderType: !1 }); R(this, "_borderInfo$", new at(this._borderInfo)); R(this, "borderInfo$", this._borderInfo$.asObservable()); } dispose() { this._borderInfo$.complete(); } setType(e) { this._borderInfo.type = e, this.setActiveBorderType(!0), this._refresh(); } setColor(e) { this._borderInfo.color = e, this._refresh(); } setStyle(e) { this._borderInfo.style = e, this._refresh(); } setActiveBorderType(e) { this._borderInfo.activeBorderType = e; } getBorderInfo() { return this._borderInfo; } _refresh() { this._borderInfo$.next(this._borderInfo); } } function vn(n, e) { const { startRow: t, startColumn: o, endRow: s, endColumn: r } = n; for (let i = t; i <= s; i++) for (let a = o; a <= r; a++) e(i, a); } const No = (n, e, t, o) => { const { mr: s, worksheet: r } = n; e.startRow < 0 || e.startColumn < 0 || vn(e, (i, a) => { var c, d; const u = r.getMergedCell(i, a); let l = t; if (u && (t.bc_tr || t.ml_tr || t.bl_tr || t.tl_mr || t.tl_bc || t.tl_br)) { if (o) { const h = O.deepClone( (c = s.getValue(u.startRow, u.startColumn)) == null ? void 0 : c.s ); l = h != null && h.bd ? Object.assign(h.bd, t) : t; } s.setValue(u.startRow, u.startColumn, { s: { bd: l } }); } else { if (o) { const h = O.deepClone((d = s.getValue(i, a)) == null ? void 0 : d.s); l = h != null && h.bd ? Object.assign(h.bd, t) : t; } s.setValue(i, a, { s: { bd: l } }); } }); }, _u = (n) => { const e = { startRow: n.startRow - 1, startColumn: n.startColumn, endRow: n.startRow - 1, endColumn: n.endColumn }, t = { startRow: n.startRow, startColumn: n.startColumn - 1, endRow: n.endRow, endColumn: n.startColumn - 1 }, o = { startRow: n.endRow + 1, startColumn: n.startColumn, endRow: n.endRow + 1, endColumn: n.endColumn }, s = { startRow: n.startRow, startColumn: n.endColumn + 1, endRow: n.endRow, endColumn: n.endColumn + 1 }, r = { startRow: n.startRow, startColumn: n.startColumn, endRow: n.startRow, endColumn: n.endColumn }, i = { startRow: n.startRow, startColumn: n.startColumn, endRow: n.endRow, endColumn: n.startColumn }, a = { startRow: n.endRow, startColumn: n.startColumn, endRow: n.endRow, endColumn: n.endColumn }, u = { startRow: n.startRow, startColumn: n.endColumn, endRow: n.endRow, endColumn: n.endColumn }; return { topRangeOut: e, leftRangeOut: t, bottomRangeOut: o, rightRangeOut: s, topRange: r, leftRange: i, bottomRange: a, rightRange: u }; }; function bu(n, e, t) { const { style: o, color: s, type: r } = n.getBorderInfo(), i = r === ue.TOP || r === ue.ALL || r === ue.OUTSIDE, a = r === ue.LEFT || r === ue.ALL || r === ue.OUTSIDE, u = r === ue.BOTTOM || r === ue.ALL || r === ue.OUTSIDE, l = r === ue.RIGHT || r === ue.ALL || r === ue.OUTSIDE, c = r === ue.VERTICAL || r === ue.ALL || r === ue.INSIDE, d = r === ue.HORIZONTAL || r === ue.ALL || r === ue.INSIDE, h = r.indexOf("tlbr") > -1, m = r.indexOf("tlbc") > -1, g = r.indexOf("tlmr") > -1, f = r.indexOf("bltr") > -1, p = r.indexOf("mltr") > -1, C = r.indexOf("bctr") > -1, S = t[0], { topRangeOut: I, leftRangeOut: w, bottomRangeOut: b, rightRangeOut: y, topRange: x, leftRange: T, bottomRange: U, rightRange: P } = _u(S), A = new G(), { worksheet: j, unitId: Z, subUnitId: Y } = e; return { worksheet: j, unitId: Z, subUnitId: Y, style: o, color: s, type: r, top: i, left: a, right: l, bottom: u, vertical: c, horizontal: d, tl_br: h, tl_bc: m, tl_mr: g, bl_tr: f, ml_tr: p, bc_tr: C, topRangeOut: I, leftRangeOut: w, bottomRangeOut: b, rightRangeOut: y, topRange: x, leftRange: T, bottomRange: U, rightRange: P, range: S, mr: A, borderStyle: { s: o, cl: { rgb: s } } }; } const yu = (n) => { const { range: e, mr: t, borderStyle: o, vertical: s, horizontal: r, worksheet: i } = n; s && vn(e, (a, u) => { var c, d, h; const l = i.getMergedCell(a, u); if (l) { const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s; l.startColumn !== e.startColumn && t.setValue(a, u, { s: { bd: m != null && m.bd ? Object.assign(m.bd, { l: O.deepClone(o) }) : { l: O.deepClone(o) } } }); } else { if (u !== e.endColumn) { const m = (d = t.getValue(a, u)) == null ? void 0 : d.s; t.setValue(a, u, { s: { bd: m != null && m.bd ? Object.assign(m.bd, { r: O.deepClone(o) }) : { r: O.deepClone(o) } } }); } if (u !== e.startColumn) { const m = (h = t.getValue(a, u)) == null ? void 0 : h.s; t.setValue(a, u, { s: { bd: m != null && m.bd ? Object.assign(m.bd, { l: O.deepClone(o) }) : { l: O.deepClone(o) } } }); } } }), r && vn(e, (a, u) => { var c, d, h; const l = i.getMergedCell(a, u); if (l) { const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s; l.startRow !== e.startRow && t.setValue(a, u, { s: { bd: m != null && m.bd ? Object.assign(m.bd, { t: O.deepClone(o) }) : { t: O.deepClone(o) } } }); } else { if (a !== e.endRow) { const m = (d = t.getValue(a, u)) == null ? void 0 : d.s; t.setValue(a, u, { s: { bd: m != null && m.bd ? Object.assign(m.bd, { b: O.deepClone(o) }) : { b: O.deepClone(o) } } }); } if (a !== e.startRow) { const m = (h = t.getValue(a, u)) == null ? void 0 : h.s; t.setValue(a, u, { s: { bd: m != null && m.bd ? Object.assign(m.bd, { t: O.deepClone(o) }) : { t: O.deepClone(o) } } }); } } }); }; function Eu(n) { const { borderStyle: e, tl_br: t, tl_bc: o, tl_mr: s, bl_tr: r, ml_tr: i, bc_tr: a } = n, u = (l, c, d) => { No(n, l, c, d); }; t && u(n.range, { tl_br: O.deepClone(e) }, !0), o && u(n.range, { tl_bc: O.deepClone(e) }, !0), s && u(n.range, { tl_mr: O.deepClone(e) }, !0), r && u(n.range, { bl_tr: O.deepClone(e) }, !0), i && u(n.range, { ml_tr: O.deepClone(e) }, !0), a && u(n.range, { bc_tr: O.deepClone(e) }, !0); } const Uu = (n) => { const { top: e, left: t, right: o, bottom: s, borderStyle: r, bottomRange: i, topRange: a, leftRange: u, rightRange: l, bottomRangeOut: c, topRangeOut: d, leftRangeOut: h, rightRangeOut: m } = n, g = (f, p, C) => { No(n, f, p, C); }; e && (g(d, { b: null }), g(a, { t: O.deepClone(r) }, !0)), s && (g(c, { t: null }), g(i, { b: O.deepClone(r) }, !0)), t && (g(h, { r: null }), g(u, { l: O.deepClone(r) }, !0)), o && (g(m, { l: null }), g(l, { r: O.deepClone(r) }, !0)); }, Pu = (n) => { const { range: e, worksheet: t, mr: o, top: s, bottom: r, left: i, right: a, vertical: u, horizontal: l, tl_br: c, tl_bc: d, tl_mr: h, bl_tr: m, ml_tr: g, bc_tr: f, topRange: p, bottomRange: C, leftRange: S, rightRange: I, topRangeOut: w, bottomRangeOut: b, leftRangeOut: y, rightRangeOut: x } = n, T = (U, P, A) => { No(n, U, P, A); }; !s && !r && !i && !a && !u && !l && !c && !d && !h && !m && !g && !f && (vn(e, (U, P) => { var j, Z, Y, ee, Re, ie, xe, ft; const A = t.getMergedCell(U, P); if (A) { if (A.endColumn !== e.endColumn) { const X = (j = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : j.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { r: null }) : { r: null } } }); } if (A.startColumn !== e.startColumn) { const X = (Z = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Z.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { l: null }) : { l: null } } }); } if (A.endRow !== e.endRow) { const X = (Y = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Y.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { b: null }) : { b: null } } }); } if (A.startRow !== e.startRow) { const X = (ee = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : ee.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { t: null }) : { t: null } } }); } } else { if (P !== e.endColumn) { const X = (Re = o.getValue(U, P)) == null ? void 0 : Re.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { r: null }) : { r: null } } }); } if (P !== e.startColumn) { const X = (ie = o.getValue(U, P)) == null ? void 0 : ie.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { l: null }) : { l: null } } }); } if (U !== e.endRow) { const X = (xe = o.getValue(U, P)) == null ? void 0 : xe.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { b: null }) : { b: null } } }); } if (U !== e.startRow) { const X = (ft = o.getValue(U, P)) == null ? void 0 : ft.s; o.setValue(U, P, { s: { bd: X != null && X.bd ? Object.assign(X.bd, { t: null }) : { t: null } } }); } } }), T(w, { b: null }), T(p, { t: null }, !0), T(b, { t: null }), T(C, { b: null }, !0), T(y, { r: null }), T(S, { l: null }, !0), T(x, { l: null }), T(I, { r: null }, !0), T(e, { tl_br: null }, !0), T(e, { tl_bc: null }, !0), T(e, { tl_mr: null }, !0), T(e, { bl_tr: null }, !0), T(e, { ml_tr: null }, !0), T(e, { bc_tr: null }, !0)); }, rn = { id: "sheet.command.set-border", type: v.COMMAND, handler: (n, e) => { var C; const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(kt), a = N(s, e); if (!a) return !1; const u = (C = r.getCurrentSelections()) == null ? void 0 : C.map((S) => S.range); if (!(u != null && u.length)) return !1; const { activeBorderType: l } = i.getBorderInfo(); if (!l) return !1; const c = bu(i, a, u); yu(c), Uu(c), Eu(c), Pu(c); const { unitId: d, subUnitId: h, mr: m } = c, g = { unitId: d, subUnitId: h, cellValue: m.getData() }, f = Ae( n, g ); return t.syncExecuteCommand(Q.id, g) ? (o.pushUndoRedo({ unitID: d, undoMutations: [{ id: Q.id, params: f }], redoMutations: [{ id: Q.id, params: g }] }), !0) : !1; } }, Tu = { id: "sheet.command.set-border-position", type: v.COMMAND, handler: (n, e) => { if (!e.value) return !1; const t = n.get(E); return n.get(kt).setType(e.value), t.syncExecuteCommand(rn.id); } }, ku = { id: "sheet.command.set-border-style", type: v.COMMAND, handler: (n, e) => { const t = n.get(E); return n.get(kt).setStyle(e.value), t.syncExecuteCommand(rn.id); } }, Nu = { id: "sheet.command.set-border-color", type: v.COMMAND, handler: (n, e) => { const t = n.get(E); return n.get(kt).setColor(e.value), t.syncExecuteCommand(rn.id); } }, Ou = { id: "sheet.command.set-border-basic", type: v.COMMAND, handler: (n, e) => { const { unitId: t, subUnitId: o, value: s } = e, { type: r, color: i, style: a } = s, u = n.get(E), l = n.get(kt); return l.setType(r), i && l.setColor(i), l.setStyle(a), u.syncExecuteCommand(rn.id, { unitId: t, subUnitId: o }); } }; function Du(n, e) { if (n == null) return n; const t = O.deepClone(n); if (e == null) return t; const o = {}; return "h" in e && (o.h = t.h), "ia" in e && (o.ia = t.ia), "ah" in e && (o.ah = t.ah), "hd" in e && (o.hd = t.hd), "s" in e && (o.s = t.s), "custom" in e && (o.custom = t.custom), o; } function Au(n, e) { if (n == null) return n; const t = O.deepClone(n); if (e == null) return t; const o = {}; return "w" in e && (o.w = t.w), "hd" in e && (o.hd = t.hd), "s" in e && (o.s = t.s), "custom" in e && (o.custom = t.custom), o; } const xu = (n, e) => { const { unitId: t, subUnitId: o, columnData: s } = n, r = {}, i = e.getColumnManager(); for (const a in s) { const u = s[a], l = i.getColumn(Number(a)); r[a] = Au(l, u); } return { unitId: t, subUnitId: o, columnData: r }; }, Lt = { id: "sheet.mutation.set-col-data", type: v.MUTATION, handler: (n, e) => { const { columnData: t } = e, o = n.get(M), s = N(o, e); if (!s) return !1; const { worksheet: r } = s, i = r.getColumnManager(); for (const a in t) { const u = t[a]; if (u == null) { i.removeColumn(Number(a)); continue; } const l = i.getColumnOrCreate(Number(a)); Object.assign(l, u); } return !0; } }, $u = { type: v.COMMAND, id: "sheet.command.set-col-data", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, e); if (!r) return !1; const { columnData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = { subUnitId: u, unitId: a, columnData: i }, d = xu(c, l); return t.syncExecuteCommand(Lt.id, c) ? (o.pushUndoRedo({ unitID: a, undoMutations: [{ id: Lt.id, params: d }], redoMutations: [{ id: Lt.id, params: c }] }), !0) : !1; } }, Wu = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }, Xt = { id: "sheet.mutation.set-col-hidden", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (!o) return !1; const s = o.getSheetBySheetId(e.subUnitId).getColumnManager(); for (let r = 0; r < e.ranges.length; r++) { const i = e.ranges[r]; for (let a = i.startColumn; a < i.endColumn + 1; a++) { const u = s.getColumnOrCreate(a); u != null && (u.hd = te.TRUE); } } return !0; } }, Lu = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }, qt = { id: "sheet.mutation.set-col-visible", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (!o) return !1; const s = o.getSheetBySheetId(e.subUnitId).getColumnManager(); for (let r = 0; r < e.ranges.length; r++) { const i = e.ranges[r]; for (let a = i.startColumn; a < i.endColumn + 1; a++) { const u = s.getColumnOrCreate(a); u != null && (u.hd = te.FALSE); } } return !0; } }, Kn = { type: v.COMMAND, id: "sheet.command.set-col-visible-on-cols", handler: (n, e) => { var C, S; const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(V), i = n.get(E), a = n.get(M), u = N(a, { unitId: t, subUnitId: o }); if (!u) return !1; const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = { unitId: t, subUnitId: o, reveal: !0, selections: s.map((I) => ({ range: I, primary: ve(I, l), style: null })) }, h = Lu(n, c), m = { unitId: t, subUnitId: o, selections: Er(s).map((I) => ({ range: I, primary: ve(I, l), style: null })) }, g = z([ { id: qt.id, params: c }, { id: re.id, params: d } ], i), f = r.onCommandExecute({ id: Kn.id, params: e }), p = z([...f.redos], i); return g.result && p.result && n.get(W).pushUndoRedo({ unitID: t, undoMutations: [ { id: Xt.id, params: h }, { id: re.id, params: m }, ...(C = f.undos) != null ? C : [] ], redoMutations: [ ...(S = f.preRedos) != null ? S : [], { id: qt.id, params: c }, { id: re.id, params: d }, ...f.redos ] }), !0; } }, br = { type: v.COMMAND, id: "sheet.command.set-selected-cols-visible", handler: (n) => { var l; const e = n.get(F), t = n.get(E), o = (l = e.getCurrentSelections()) == null ? void 0 : l.map((c) => c.range).filter((c) => c.rangeType === H.COLUMN); if (!(o != null && o.length)) return !1; const s = N(n.get(M)); if (!s) return !1; const { worksheet: r, unitId: i, subUnitId: a } = s, u = o.map((c) => r.getHiddenCols(c.startColumn, c.endColumn)).flat(); return t.executeCommand(Kn.id, { unitId: i, subUnitId: a, ranges: u }); } }, yr = { type: v.COMMAND, id: "sheet.command.set-col-hidden", handler: (n, e) => { var S, I, w, b; const t = n.get(F), o = n.get(V), s = n.get(M), r = n.get(E); let i = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((y) => y.range).filter((y) => y.rangeType === H.COLUMN); if (!(i != null && i.length)) return !1; const a = N(s, e); if (!a) return !1; const { worksheet: u, unitId: l, subUnitId: c } = a; i = Vu(a.worksheet, i); const d = { unitId: l, subUnitId: c, ranges: i }, h = { unitId: l, subUnitId: c, selections: Er(i).map((y) => ({ range: y, primary: ve(y, u), style: null })) }, m = Wu(n, d), g = { unitId: l, subUnitId: c, reveal: !0, selections: i.map((y) => ({ range: y, primary: ve(y, u), style: null })) }, f = z([ { id: Xt.id, params: d }, { id: re.id, params: h } ], r), p = o.onCommandExecute({ id: yr.id, params: d }), C = z([...p.redos], r); return f.result && C.result ? (n.get(W).pushUndoRedo({ unitID: l, undoMutations: [ { id: qt.id, params: m }, { id: re.id, params: g }, ...(w = p.undos) != null ? w : [] ], redoMutations: [ ...(b = p.preRedos) != null ? b : [], { id: Xt.id, params: d }, { id: re.id, params: h }, ...p.redos ] }), !0) : !1; } }; function Vu(n, e) { const t = n.getRowCount() - 1, o = n.getHiddenCols(), s = []; return e.forEach((r) => { const i = o.filter((a) => a.startColumn >= r.startColumn && a.endColumn <= r.endColumn); if (i.length) { let a = r.startColumn; i.forEach((u) => { u.startColumn > a && (s.push({ startColumn: a, endColumn: u.startColumn - 1, startRow: 0, endRow: t }), a = u.endColumn + 1); }), a <= r.endColumn && s.push({ startColumn: a, endColumn: r.endColumn, startRow: 0, endRow: t }); } else s.push(r); }), s; } function Er(n) { return Hu(n).map((t) => { const o = t.startColumn === 0 ? t.endColumn + 1 : t.startColumn - 1; return { ...t, startColumn: o, endColumn: o }; }); } function Hu(n) { const e = []; let t; return n.sort((o, s) => o.startColumn - s.startColumn).forEach((o) => { if (!t) { t = o; return; } t.endColumn === o.startColumn - 1 ? t.endColumn = o.endColumn : (e.push(t), t = o); }), e.push(t), e; } const Ur = { id: "sheet.command.set-defined-name", type: v.COMMAND, handler: (n, e) => { var d, h; const t = n.get(E), o = n.get(W), s = n.get(V); if (!e) return !1; const r = { ...e }, i = Oi(n, e), a = s.onCommandExecute({ id: Ur.id, params: e }), u = [ ...(d = a.preRedos) != null ? d : [], { id: Cn.id, params: i }, { id: Gt.id, params: r }, ...a.redos ], l = [ ...(h = a.preUndos) != null ? h : [], { id: Cn.id, params: r }, { id: Gt.id, params: i }, ...a.undos ]; return z(u, t) ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: l.filter(Boolean), redoMutations: u.filter(Boolean) }), !0) : !1; } }, Pr = (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (s == null) throw new Error("worksheet is null error!"); const i = s.getConfig().freeze; return { unitId: e.unitId, subUnitId: e.subUnitId, ...i }; }, ut = { id: "sheet.mutation.set-frozen", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return !1; const r = s.getConfig(), { startRow: i, startColumn: a, ySplit: u, xSplit: l } = e; return r.freeze = { startRow: i, startColumn: a, ySplit: u, xSplit: l }, !0; } }, Bu = { type: v.COMMAND, id: "sheet.command.set-frozen", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, { unitId: e.unitId, subUnitId: e.subUnitId }); if (!r) return !1; const { unitId: i, subUnitId: a, worksheet: u } = r, { startColumn: l, startRow: c, xSplit: d, ySplit: h } = e; if (c >= u.getRowCount() || l >= u.getColumnCount() || d >= u.getColumnCount() || h >= u.getRowCount()) return !1; const m = { unitId: i, subUnitId: a, ...e }, g = Pr(n, m); return t.syncExecuteCommand(ut.id, m) ? (o.pushUndoRedo({ unitID: i, undoMutations: [{ id: ut.id, params: g }], redoMutations: [{ id: ut.id, params: m }] }), !0) : !1; } }, Fu = { type: v.COMMAND, id: "sheet.command.cancel-frozen", handler: (n, e) => { const t = n.get(E), o = n.get(M), s = n.get(W), r = N(o, { unitId: e == null ? void 0 : e.unitId, subUnitId: e == null ? void 0 : e.subUnitId }); if (!r) return !1; const { unitId: i, subUnitId: a } = r, u = { unitId: i, subUnitId: a, startRow: -1, startColumn: -1, xSplit: 0, ySplit: 0 }, l = Pr(n, u); return t.syncExecuteCommand(ut.id, u) && s.pushUndoRedo({ unitID: i, undoMutations: [{ id: ut.id, params: l }], redoMutations: [{ id: ut.id, params: u }] }), !0; } }, Vt = { id: "sheet.mutation.set-gridlines-color", type: v.MUTATION, handler: (n, e) => { const t = N(n.get(M), e); if (!t) return !1; const { worksheet: o } = t, s = o.getConfig(); return s.gridlinesColor = e.color, !0; } }, ju = { type: v.COMMAND, id: "sheet.command.set-gridlines-color", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s); if (!r) return !1; const { worksheet: i } = r, a = i.getConfig().gridlinesColor; if (a === (e == null ? void 0 : e.color)) return !1; const { unitId: u, subUnitId: l } = r, c = { color: e == null ? void 0 : e.color, unitId: u, subUnitId: l }, d = { color: a, unitId: u, subUnitId: l }; return t.syncExecuteCommand(Vt.id, c) ? (o.pushUndoRedo({ unitID: u, undoMutations: [{ id: Vt.id, params: d }], redoMutations: [{ id: Vt.id, params: c }] }), !0) : !1; } }, he = { id: "sheet.mutation.set-range-protection", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, rule: s, ruleId: r } = e; return n.get(de).setRule(t, o, r, s), !0; } }, qd = (n, e) => { const { unitId: t, subUnitId: o, ruleId: s } = e, i = n.get(de).getRule(t, o, s); return i ? { id: he.id, params: { ...e, rule: i } } : null; }, Ct = { id: "sheet.mutation.set-worksheet-protection", type: v.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, rule: s } = e; return n.get(Ye).setRule(t, o, s), !0; } }, Gu = { type: v.COMMAND, id: "sheet.command.set-protection", async handler(n, e) { if (!e) return !1; const t = n.get(E), o = n.get(W), s = n.get(de), { rule: r, oldRule: i } = e, { unitId: a, subUnitId: u } = r, l = [], c = []; return (i == null ? void 0 : i.unitType) === r.unitType ? r.unitType === D.Worksheet ? (l.push({ id: Ct.id, params: { unitId: a, subUnitId: u, rule: r } }), c.push({ id: Ct.id, params: { unitId: a, subUnitId: u, rule: i } })) : (l.push({ id: he.id, params: { unitId: a, subUnitId: u, rule: r, ruleId: r.id } }), c.push({ id: he.id, params: { unitId: a, subUnitId: u, ruleId: i.id, rule: i } })) : (i && (i.unitType === D.Worksheet ? (l.push({ id: St.id, params: { unitId: a, subUnitId: u } }), c.push({ id: ct.id, params: { unitId: a, rule: i, subUnitId: i.subUnitId } })) : i.unitType === D.SelectRange && (l.push({ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: [i.id] } }), c.push({ id: Ne.id, params: { unitId: a, subUnitId: u, rules: [i] } }))), r.unitType === D.Worksheet ? (l.push({ id: ct.id, params: { unitId: a, rule: r, subUnitId: r.subUnitId } }), c.unshift({ id: St.id, params: { unitId: a, subUnitId: u } })) : r.unitType === D.SelectRange && (r.id = s.createRuleId(a, u), l.push({ id: Ne.id, params: { unitId: a, subUnitId: u, rules: [r] } }), c.unshift({ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: [r.id] } }))), z(l, t) && o.pushUndoRedo({ unitID: a, undoMutations: c, redoMutations: l }), !0; } }, zu = (n, e) => { const { unitId: t, subUnitId: o, rowData: s } = n, r = {}, i = e.getRowManager(); for (const a in s) { const u = s[a], l = i.getRow(Number(a)); r[a] = Du(l, u); } return { unitId: t, subUnitId: o, rowData: r }; }, Ht = { id: "sheet.mutation.set-row-data", type: v.MUTATION, handler: (n, e) => { const { rowData: t } = e, o = n.get(M), s = N(o, e); if (!s) return !1; const { worksheet: r } = s, i = r.getRowManager(); for (const a in t) { const u = t[a]; if (u == null) { i.removeRow(Number(a)); continue; } const l = i.getRowOrCreate(Number(a)); Object.assign(l, u); } return !0; } }, Ku = { type: v.COMMAND, id: "sheet.command.set-row-data", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, e); if (!r) return !1; const { rowData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = { subUnitId: u, unitId: a, rowData: i }, d = zu(c, l); return t.syncExecuteCommand(Ht.id, c) ? (o.pushUndoRedo({ unitID: a, undoMutations: [{ id: Ht.id, params: d }], redoMutations: [{ id: Ht.id, params: c }] }), !0) : !1; } }, Ju = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }, Zt = { id: "sheet.mutation.set-row-visible", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId).getRowManager(); for (let r = 0; r < e.ranges.length; r++) { const i = e.ranges[r]; for (let a = i.startRow; a < i.endRow + 1; a++) { const u = s.getRowOrCreate(a); u != null && (u.hd = 0); } } return !0; } }, Yu = (n, e) => { if (n.get(M).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }, Qt = { id: "sheet.mutation.set-row-hidden", type: v.MUTATION, handler: (n, e) => { const o = n.get(M).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId).getRowManager(); for (let r = 0; r < e.ranges.length; r++) { const i = e.ranges[r]; for (let a = i.startRow; a < i.endRow + 1; a++) { const u = s.getRowOrCreate(a); u != null && (u.hd = 1); } } return !0; } }, Jn = { type: v.COMMAND, id: "sheet.command.set-specific-rows-visible", handler: (n, e) => { var C, S, I; const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(E), i = n.get(W), a = n.get(V), u = N(n.get(M), { unitId: t, subUnitId: o }); if (!u) return !1; const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = { unitId: t, subUnitId: o, reveal: !0, selections: s.map((w) => ({ range: w, primary: ve(w, l), style: null })) }, h = Ju(n, c), m = { unitId: t, subUnitId: o, selections: Nr(s).map((w) => ({ range: w, primary: ve(w, l), style: null })) }, g = z( [ { id: Zt.id, params: c }, { id: re.id, params: d } ], r ), f = a.onCommandExecute({ id: Jn.id, params: e }), p = z([...f.redos], r); return g.result && p.result && i.pushUndoRedo({ unitID: t, undoMutations: [ ...(C = f.preUndos) != null ? C : [], { id: Qt.id, params: h }, { id: re.id, params: m }, ...(S = f.undos) != null ? S : [] ], redoMutations: [ ...(I = f.preRedos) != null ? I : [], { id: Zt.id, params: c }, { id: re.id, params: d }, ...f.redos ] }), !0; } }, Tr = { type: v.COMMAND, id: "sheet.command.set-selected-rows-visible", handler: async (n) => { var c; const e = n.get(F), t = n.get(M), o = n.get(E), s = (c = e.getCurrentSelections()) == null ? void 0 : c.map((d) => d.range).filter((d) => d.rangeType === H.ROW); if (!(s != null && s.length)) return !1; const r = N(t); if (!r) return !1; const { worksheet: i, unitId: a, subUnitId: u } = r, l = s.map((d) => i.getHiddenRows(d.startRow, d.endRow)).flat(); return o.executeCommand(Jn.id, { unitId: a, subUnitId: u, ranges: l }); } }, kr = { type: v.COMMAND, id: "sheet.command.set-rows-hidden", handler: (n, e) => { var S, I, w, b, y, x; const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), i = n.get(V); let a = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((T) => T.range).filter((T) => T.rangeType === H.ROW); if (!(a != null && a.length)) return !1; const u = N(r, e); if (!u) return !1; a = Xu(u.worksheet, a); const { unitId: l, subUnitId: c, worksheet: d } = u, h = { unitId: l, subUnitId: c, ranges: a }, m = { unitId: l, subUnitId: c, selections: Nr(a).map((T) => ({ range: T, primary: ve(T, d), style: null })) }, g = Yu(n, h), f = { unitId: l, subUnitId: c, reveal: !0, selections: a.map((T) => ({ range: T, primary: ve(T, d), style: null })) }, p = i.onCommandExecute({ id: kr.id, params: h }); return z([ ...(w = p.preRedos) != null ? w : [], { id: Qt.id, params: h }, { id: re.id, params: m }, ...p.redos ], o).result && s.pushUndoRedo({ unitID: l, undoMutations: [ ...(b = p.preUndos) != null ? b : [], { id: Zt.id, params: g }, { id: re.id, params: f }, ...(y = p.undos) != null ? y : [] ], redoMutations: [ ...(x = p.preRedos) != null ? x : [], { id: Qt.id, params: h }, { id: re.id, params: m }, ...p.redos ] }), !0; } }; function Xu(n, e) { const t = n.getMaxColumns() - 1, o = n.getHiddenRows(), s = []; return e.forEach((r) => { const i = o.filter((a) => a.startRow >= r.startRow && a.endRow <= r.endRow); if (i.length) { let a = r.startRow; i.forEach((u) => { u.startRow > a && (s.push({ startRow: a, endRow: u.startRow - 1, startColumn: 0, endColumn: t }), a = u.endRow + 1); }), a <= r.endRow && s.push({ startRow: a, endRow: r.endRow, startColumn: 0, endColumn: t }); } else s.push(r); }), s; } function Nr(n) { return qu(n).map((t) => { const o = t.startRow === 0 ? t.endRow + 1 : t.startRow - 1; return { ...t, startRow: o, endRow: o }; }); } function qu(n) { const e = []; let t; return n.sort((o, s) => o.startRow - s.startRow).forEach((o) => { if (!t) { t = o; return; } o.startRow === t.endRow + 1 ? t.endRow = o.endRow : (e.push(t), t = o); }), e.push(t), e; } const fe = { type: v.COMMAND, id: "sheet.command.set-style", handler: (n, e) => { var b; const t = n.get(M), o = N(t, e); if (!o) return !1; const { unitId: s, subUnitId: r, worksheet: i } = o, { range: a, style: u } = e, l = n.get(E), c = n.get(W), d = n.get(F), h = a ? [a] : (b = d.getCurrentSelections()) == null ? void 0 : b.map((y) => y.range); if (!(h != null && h.length)) return !1; const m = new G(), g = Za(i); if (O.isArray(u.value)) for (let y = 0; y < h.length; y++) g.forOperableEach(h[y], (x, T, U) => { m.setValue(x, T, { s: { [u.type]: u.value[x - U.startRow][T - U.startColumn] } }); }); else for (let y = 0; y < h.length; y++) { const x = { s: { [u.type]: u.value } }; g.forOperableEach(h[y], (T, U) => m.setValue(T, U, x)); } const f = { subUnitId: r, unitId: s, cellValue: m.getMatrix() }, p = Ae( n, f ), C = l.syncExecuteCommand( Q.id, f ), { undos: S, redos: I } = n.get(V).onCommandExecute({ id: fe.id, params: e }), w = z([...I], l); return C && w.result ? (c.pushUndoRedo({ unitID: f.unitId, undoMutations: [{ id: Q.id, params: p }, ...S], redoMutations: [{ id: Q.id, params: f }, ...I] }), !0) : !1; } }, Zd = { type: v.COMMAND, id: "sheet.command.set-bold", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return !1; const t = N(n.get(M)); if (!t) return !1; const { worksheet: o } = t, { actualRow: s, actualColumn: r } = e.primary, a = { style: { type: "bl", value: o.getRange(s, r).getFontWeight() === gi.BOLD ? te.FALSE : te.TRUE } }; return n.get(E).syncExecuteCommand(fe.id, a); } }, Qd = { type: v.COMMAND, id: "sheet.command.set-italic", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return !1; const t = N(n.get(M)); if (!t) return !1; const { worksheet: o } = t; let s = !0; if (e.primary) { const { startRow: i, startColumn: a } = e.primary; s = o.getRange(i, a).getFontStyle() === fi.ITALIC; } const r = { style: { type: "it", value: s ? te.FALSE : te.TRUE } }; return n.get(E).syncExecuteCommand(fe.id, r); } }, eh = { type: v.COMMAND, id: "sheet.command.set-underline", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return !1; const t = N(n.get(M)); if (!t) return !1; const { worksheet: o } = t; let s = !0; e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getUnderline().s); const r = { style: { type: "ul", value: { s: s ? te.FALSE : te.TRUE } } }; return n.get(E).syncExecuteCommand(fe.id, r); } }, th = { type: v.COMMAND, id: "sheet.command.set-stroke", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return !1; const t = N(n.get(M)); if (!t) return !1; const { worksheet: o } = t; let s = !0; e.primary && (s = !!o.getRange(e.primary.actualRow, e.primary.actualColumn).getStrikeThrough().s); const r = { style: { type: "st", value: { s: s ? te.FALSE : te.TRUE } } }; return n.get(E).syncExecuteCommand(fe.id, r); } }, nh = { type: v.COMMAND, id: "sheet.command.set-overline", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return !1; const t = N(n.get(M)); if (!t) return !1; const { worksheet: o } = t; let s = !0; e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getOverline().s); const r = { style: { type: "ol", value: { s: s ? te.FALSE : te.TRUE } } }; return n.get(E).syncExecuteCommand(fe.id, r); } }, oh = { type: v.COMMAND, id: "sheet.command.set-font-family", handler: (n, e) => { if (!e) return !1; const t = n.get(E), o = { style: { type: "ff", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }, sh = { type: v.COMMAND, id: "sheet.command.set-font-size", handler: (n, e) => { if (!e) return !1; const t = n.get(E), o = { style: { type: "fs", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }, Zu = { type: v.COMMAND, id: "sheet.command.set-text-color", handler: (n, e) => { if (!e) return !1; const t = n.get(E), o = { style: { type: "cl", value: { rgb: e.value } } }; return t.syncExecuteCommand(fe.id, o); } }, Qu = { type: v.COMMAND, id: "sheet.command.reset-text-color", handler: (n) => { const e = n.get(E), t = { style: { type: "cl", value: { rgb: null // use null to reset text color } } }; return e.syncExecuteCommand(fe.id, t); } }, el = { type: v.COMMAND, id: "sheet.command.set-background-color", handler: (n, e) => { if (!e || !e.value) return !1; const t = n.get(E), o = { style: { type: "bg", value: { rgb: e.value } } }; return t.syncExecuteCommand(fe.id, o); } }, tl = { type: v.COMMAND, id: "sheet.command.reset-background-color", handler: (n) => { const e = n.get(E), t = { style: { type: "bg", value: { rgb: null // use null to reset background color } } }; return e.syncExecuteCommand(fe.id, t); } }, nl = { type: v.COMMAND, id: "sheet.command.set-vertical-text-align", handler: (n, e) => { if (!e) return !1; const t = n.get(E), o = { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, style: { type: "vt", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }, ol = { type: v.COMMAND, id: "sheet.command.set-horizontal-text-align", handler: (n, e) => { if (!e) return !1; const t = n.get(E), o = { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, style: { type: "ht", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }, sl = { type: v.COMMAND, id: "sheet.command.set-text-wrap", handler: (n, e) => { if (!e) return !1; const t = n.get(E), o = { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, style: { type: "tb", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }, rl = { type: v.COMMAND, id: "sheet.command.set-text-rotation", handler: (n, e) => { if (!e) return !1; const t = typeof e.value == "number" ? { a: e.value } : { a: 0, v: te.TRUE }, o = n.get(E), s = { style: { type: "tr", value: t } }; return o.syncExecuteCommand(fe.id, s); } }, il = (n, e) => { const r = n.get(M).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor; return { ...O.deepClone(e), color: r }; }, fn = { id: "sheet.mutation.set-tab-color", type: v.MUTATION, handler: (n, e) => { const t = n.get(M).getUniverSheetInstance(e.unitId); if (!t) return !1; const o = t.getSheetBySheetId(e.subUnitId); return o ? (o.getConfig().tabColor = e.color, !0) : !1; } }, al = { type: v.COMMAND, id: "sheet.command.set-tab-color", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = N(n.get(M)); if (!s) return !1; const { unitId: r, subUnitId: i } = s, a = { color: e.value, unitId: r, subUnitId: i }, u = il(n, a); return t.syncExecuteCommand(fn.id, a) ? (o.pushUndoRedo({ unitID: r, undoMutations: [{ id: fn.id, params: u }], redoMutations: [{ id: fn.id, params: a }] }), !0) : !1; } }, Or = { id: "sheet.mutation.set-workbook-name", type: v.MUTATION, handler: (n, e) => { const t = n.get(M).getUnit(e.unitId, B.UNIVER_SHEET); return t ? (t.setName(e.name), !0) : !1; } }, Dr = { type: v.COMMAND, id: "sheet.command.set-workbook-name", handler: async (n, e) => { var l; if (!n.get(M).getUnit(e.unitId, B.UNIVER_SHEET)) return !1; const r = n.get(V).onCommandExecute({ id: Dr.id, params: e }), i = { name: e.name, unitId: e.unitId }, a = [ ...(l = r.preRedos) != null ? l : [], { id: Or.id, params: i }, ...r.redos ], u = n.get(E); return z(a, u).result; } }, an = { id: "sheet.operation.set-worksheet-active", type: v.OPERATION, handler: (n, e) => { const t = n.get(M).getUniverSheetInstance(e.unitId); if (!t) return !1; const o = t.getWorksheets(); for (const [, s] of o) if (s.getSheetId() === e.subUnitId) return t.setActiveSheet(s), !0; return !1; } }, ul = 4, Ar = { type: v.COMMAND, id: "sheet.command.set-worksheet-activate", handler: (n, e, t) => { const o = n.get(E), s = N(n.get(M), e); if (!s) return !1; const { unitId: r, subUnitId: i } = s; return new Promise((a) => { setTimeout(() => { const u = o.syncExecuteCommand(an.id, { unitId: r, subUnitId: i }, t); a(u); }, ul); }); } }, xr = (n, e) => { const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getColumnManager(); for (let a = 0; a < s.length; a++) { const u = s[a]; for (let l = u.startColumn; l < u.endColumn + 1; l++) { const c = i.getColumnOrCreate(l); r[l] = c.w; } } return { unitId: t, subUnitId: o, ranges: s, colWidth: r }; }, tt = { id: "sheet.mutation.set-worksheet-col-width", type: v.MUTATION, handler: (n, e) => { var u; const t = n.get(M), o = N(t, e); if (!o) return !1; const { worksheet: s } = o, r = s.getConfig().defaultColumnWidth, i = s.getColumnManager(), a = e.ranges; for (let l = 0; l < a.length; l++) { const c = a[l]; for (let d = c.startColumn; d < c.endColumn + 1; d++) { if (!s.getColVisible(d)) continue; const m = i.getColumnOrCreate(d); typeof e.colWidth == "number" ? m.w = e.colWidth : m.w = (u = e.colWidth[d]) != null ? u : r; } } return !0; } }, Oo = { type: v.COMMAND, id: "sheet.command.delta-column-width", // eslint-disable-next-line max-lines-per-function handler: async (n, e) => { const o = n.get(F).getCurrentSelections(); if (!(o != null && o.length)) return !1; const s = n.get(E), r = n.get(W), i = N(n.get(M)); if (!i) return !1; const { worksheet: a, unitId: u, subUnitId: l } = i, { anchorCol: c, deltaX: d } = e, m = a.getColumnWidth(c) + d, g = o.length === 1 && o[0].range.rangeType === H.ALL, f = o.filter((x) => x.range.rangeType === H.COLUMN), p = g ? H.ALL : f.some(({ range: x }) => { const { startColumn: T, endColumn: U } = x; return T <= c && c <= U; }) ? H.COLUMN : H.NORMAL; let C; if (p === H.ALL) { const x = a.getRowCount(), T = new Array(a.getColumnCount()).fill(void 0).map( (U, P) => ({ startRow: 0, endRow: x - 1, startColumn: P, endColumn: P }) ); C = { subUnitId: l, unitId: u, colWidth: m, ranges: T }; } else p === H.COLUMN ? C = { subUnitId: l, unitId: u, ranges: f.map((x) => k.clone(x.range)), colWidth: m } : C = { subUnitId: l, unitId: u, colWidth: m, ranges: [ { startRow: 0, endRow: a.getMaxRows() - 1, startColumn: c, endColumn: c } ] }; const { undos: S, redos: I } = n.get(V).onCommandExecute({ id: Oo.id, params: C }), w = xr( C, a ), b = s.syncExecuteCommand( tt.id, C ), y = z([...I], s); return b && y.result && r.pushUndoRedo({ unitID: u, undoMutations: [{ id: tt.id, params: w }, ...S], redoMutations: [{ id: tt.id, params: C }, ...I] }), !0; } }, Mn = { type: v.COMMAND, id: "sheet.command.set-worksheet-col-width", handler: (n, e) => { var S, I, w, b; const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(V), i = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((y) => y.range); if (!(i != null && i.length)) return !1; const a = N(n.get(M), e); if (!a) return !1; const { subUnitId: u, unitId: l, worksheet: c } = a, d = { subUnitId: u, unitId: l, ranges: i, colWidth: e.value }, h = xr(d, c), m = o.syncExecuteCommand(tt.id, d), { undos: g, redos: f } = n.get(V).onCommandExecute({ id: Mn.id, params: d }), p = r.onCommandExecute({ id: Mn.id, params: d }), C = z([...f, ...p.redos], o); return m && C.result ? (s.pushUndoRedo({ unitID: l, undoMutations: [...(w = p.preUndos) != null ? w : [], { id: tt.id, params: h }, ...g], redoMutations: [...(b = p.preRedos) != null ? b : [], { id: tt.id, params: d }, ...f] }), !0) : !1; } }, ll = { type: v.COMMAND, id: "sheet.command.set-col-is-auto-width", handler: async (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(F), r = n.get(M), i = N(r, e); if (!i) return !1; const { unitId: a, subUnitId: u } = i; let l = []; if (e != null && e.ranges) l = [...e.ranges]; else { const g = s.getCurrentSelections(); for (let f = 0; f < g.length; f++) l.push(g[f].range); } if (!(l != null && l.length)) return !1; const c = { unitId: a, subUnitId: u, ranges: l }, { undos: d, redos: h } = n.get(V).onCommandExecute({ id: ll.id, params: c }); return z([...h], t).result ? (o.pushUndoRedo({ unitID: a, undoMutations: [...d], redoMutations: [...h] }), !0) : !1; } }, Bt = { id: "sheet.mutation.set-worksheet-default-style", type: v.MUTATION, handler: (n, e) => { const { defaultStyle: t } = e, o = n.get(M), s = N(o); if (!s) return !1; const { worksheet: r } = s; return r ? (r.setDefaultCellStyle(t), !0) : !1; } }, cl = (n, e) => { const t = Et(n.get(M), e); if (!t) throw new Error("[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!"); const { worksheet: o } = t; return { unitId: e.unitId, subUnitId: o.getSheetId(), defaultStyle: o.getDefaultCellStyle() }; }, dl = { type: v.COMMAND, id: "sheet.command.set-worksheet-default-style", handler: (n, e) => { const t = n.get(E), o = n.get(W), { unitId: s } = e, r = cl(n, e); return t.syncExecuteCommand(Bt.id, e) ? (o.pushUndoRedo({ unitID: s, undoMutations: [{ id: Bt.id, params: r }], redoMutations: [{ id: Bt.id, params: e }] }), !0) : !1; } }, $r = (n, e) => { const t = Et(n.get(M), e); if (!t) throw new Error("[SetWorksheetHideMutationFactory]: worksheet is null error!"); const { worksheet: o } = t; return { hidden: o.isSheetHidden(), unitId: e.unitId, subUnitId: o.getSheetId() }; }, lt = { id: "sheet.mutation.set-worksheet-hidden", type: v.MUTATION, handler: (n, e) => { const t = n.get(M).getUniverSheetInstance(e.unitId); if (t == null) return !1; const o = t.getSheetBySheetId(e.subUnitId); return o ? (o.getConfig().hidden = e.hidden, !0) : !1; } }, hl = { type: v.COMMAND, id: "sheet.command.set-worksheet-hidden", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(bt), r = n.get(Ke), i = N(n.get(M), e); if (!i) return !1; const { workbook: a, worksheet: u, unitId: l, subUnitId: c } = i; if (u.getConfig().hidden === te.TRUE) return !1; const h = { unitId: l, subUnitId: c, hidden: te.TRUE }, m = $r(n, h); return a.getSheets().filter((C) => C.getConfig().hidden === te.FALSE).length === 1 ? (s.emit(r.t("sheets.info.hideSheet")), !1) : t.syncExecuteCommand(lt.id, h) ? (o.pushUndoRedo({ unitID: l, undoMutations: [{ id: lt.id, params: m }], redoMutations: [{ id: lt.id, params: h }] }), !0) : !1; } }, ml = (n, e) => { const t = Et(n.get(M), e); if (!t) throw new Error("[SetWorksheetNameMutationFactory]: worksheet is null error!"); const { worksheet: o } = t; return { unitId: e.unitId, name: o.getName(), subUnitId: o.getSheetId() }; }, _n = { id: "sheet.mutation.set-worksheet-name", type: v.MUTATION, handler: (n, e) => { const t = n.get(M).getUniverSheetInstance(e.unitId); if (t == null) return !1; const o = t.getSheetBySheetId(e.subUnitId); return o ? (o.getConfig().name = e.name, !0) : !1; } }, Do = { type: v.COMMAND, id: "sheet.command.set-worksheet-name", handler: (n, e) => { var g, f; const t = n.get(E), o = n.get(W), s = n.get(V), r = N(n.get(M), e); if (!r) return !1; const { unitId: i, subUnitId: a } = r, u = { subUnitId: a, name: e.name, unitId: i }, l = ml( n, u ), c = s.onCommandExecute({ id: Do.id, params: e }), d = [ ...(g = c.preRedos) != null ? g : [], { id: _n.id, params: u }, ...c.redos ], h = [ ...(f = c.preUndos) != null ? f : [], { id: _n.id, params: l }, ...c.undos ]; return z(d, t).result ? (o.pushUndoRedo({ unitID: i, undoMutations: h, redoMutations: d }), !0) : !1; } }, gl = (n, e) => ({ ...O.deepClone(e), toOrder: e.fromOrder, fromOrder: e.toOrder }), Rn = { id: "sheet.mutation.set-worksheet-order", type: v.MUTATION, handler: (n, e) => { const t = n.get(M).getUniverSheetInstance(e.unitId); if (!t) return !1; const o = t.getConfig(); return o.sheetOrder.splice(e.fromOrder, 1), o.sheetOrder.splice(e.toOrder, 0, e.subUnitId), !0; } }, Wr = { type: v.COMMAND, id: "sheet.command.set-worksheet-order", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = N(n.get(M), e); if (!s) return !1; const { workbook: r, unitId: i, subUnitId: a } = s, l = { fromOrder: r.getConfig().sheetOrder.indexOf(a), toOrder: e.order, unitId: i, subUnitId: a }, c = gl(n, l); return t.syncExecuteCommand(Rn.id, l) ? (o.pushUndoRedo({ unitID: i, undoMutations: [{ id: Rn.id, params: c }], redoMutations: [{ id: Rn.id, params: l }] }), !0) : !1; } }; class un { constructor() { R(this, "_model", /* @__PURE__ */ new Map()); R(this, "_pointChange", new Le()); R(this, "pointChange$", this._pointChange.asObservable()); } addRule(e) { this._ensureSubUnitMap(e.unitId).set(e.subUnitId, e), this._pointChange.next(e); } deleteRule(e, t) { var s, r, i; const o = (s = this._model.get(e)) == null ? void 0 : s.get(t); o && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.delete(t), this._pointChange.next(o)); } getRule(e, t) { var o, s; return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t); } toObject() { const e = {}; return [...this._model.keys()].forEach((o) => { const s = this._model.get(o); s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => { const a = s.get(i); a && e[o].push(a); })); }), e; } fromObject(e) { const t = /* @__PURE__ */ new Map(); Object.keys(e).forEach((o) => { const s = e[o]; if (s != null && s.length) { const r = /* @__PURE__ */ new Map(); s.forEach((i) => { r.set(i.subUnitId, i); }), t.set(o, r); } }), this._model = t; } deleteUnitModel(e) { this._model.delete(e); } _ensureSubUnitMap(e) { let t = this._model.get(e); return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t; } getTargetByPermissionId(e, t) { const o = this._model.get(e); if (!o) return null; for (const [s, r] of o) if (r.permissionId === t) return [e, s]; } } class Lr { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.Delete); R(this, "status", J.INIT); R(this, "value", !0); R(this, "id"); R(this, "unitId"); R(this, "subUnitId"); R(this, "permissionId"); this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Delete}.${o}`; } } class Vr { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.ManageCollaborator); R(this, "status", J.INIT); R(this, "value", !0); R(this, "id"); R(this, "unitId"); R(this, "subUnitId"); R(this, "permissionId"); this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.ManageCollaborator}.${o}`; } } const Ie = () => [Io, Pe, Vr, Lr], it = [_.Edit, _.View, _.ManageCollaborator, _.Delete], rh = (n = "unitId", e = "subUnitId", t = "permissionId") => Ie().reduce((o, s) => { const r = new s(n, e, t); return o[r.subType] = r.value, o; }, {}), en = () => [ Me, Gs, Ws, Js, Ls, js, Mo, Hs, Bs, bo, vo, Fs, Ks, _o, eu, Ys, zs, Vs ], fl = [ _.Edit, _.Print, _.Comment, _.View, _.Copy, _.Export, _.ManageCollaborator, _.CreateSheet, _.DeleteSheet, _.RenameSheet, _.HideSheet, _.Duplicate, _.Share, _.MoveSheet, _.CopySheet, _.RecoverHistory, _.ViewHistory, _.CreatePermissionObject ], we = () => [ Te, Hn, rr, Zs ], ke = () => [ Xs, qs, Qs, er, tr, nr, sr, or, ir, ar, wn, $t, Wt, ur ], eo = [ _.Copy, _.DeleteColumn, _.DeleteRow, _.EditExtraObject, _.Filter, _.InsertColumn, _.InsertRow, _.InsertHyperlink, _.PivotTable, _.SetCellStyle, _.SetCellValue, _.SetColumnStyle, _.SetRowStyle, _.Sort ]; var Rl = Object.defineProperty, pl = Object.getOwnPropertyDescriptor, Cl = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? pl(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Rl(e, t, s), s; }, Ze = (n, e) => (t, o) => e(t, o, n); const Sl = "SHEET_WORKSHEET_PROTECTION_PLUGIN", wl = "SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN"; let bn = class extends ps { constructor(n, e, t, o, s, r, i, a) { super(), this._permissionService = n, this._univerInstanceService = e, this._injector = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointRuleModel = s, this._resourceManagerService = r, this._rangeProtectionRuleModel = i, this._logService = a, this._init(), this._initRuleChange(), this._initRuleSnapshot(), this._initPointSnapshot(); } _init() { const n = (e) => { const t = e.getUnitId(), o = (s) => { const r = s.getSheetId(); [...we(), ...ke()].forEach((i) => { const a = new i(t, r); this._permissionService.addPermissionPoint(a); }), this._logService.debug("[WorksheetPermissionService]", "Initialization completed", t, r); }; e.getSheets().forEach((s) => { o(s); }), e.sheetCreated$.subscribe((s) => { o(s); }), e.sheetDisposed$.subscribe((s) => { const r = s.getSheetId(); this._rangeProtectionRuleModel.getSubunitRuleList(t, r).forEach((a) => { [...Ie()].forEach((u) => { const l = new u(t, r, a.permissionId); this._permissionService.deletePermissionPoint(l.id); }); }), [...we(), ...ke()].forEach((a) => { const u = new a(t, r); this._permissionService.deletePermissionPoint(u.id); }); }); }; this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => { n(e); }), this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).pipe(Bo(this.dispose$)).subscribe(n), this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).pipe(Bo(this.dispose$)).subscribe((e) => { e.getSheets().forEach((t) => { const o = e.getUnitId(), s = t.getSheetId(); we().forEach((r) => { const i = new r(o, s); this._permissionService.deletePermissionPoint(i.id); }); }); }); } _initRuleChange() { this.disposeWithMe( this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => { switch (n.type) { case "add": break; case "delete": { we().forEach((e) => { const t = new e(n.unitId, n.subUnitId); this._permissionService.updatePermissionPoint(t.id, !0); }); break; } case "set": { we().forEach((e) => { const t = new e(n.unitId, n.subUnitId); this._permissionService.updatePermissionPoint(t.id, n.rule); }); break; } } }) ); } _initRuleSnapshot() { const n = () => { const t = this._worksheetProtectionRuleModel.toObject(); return JSON.stringify(t); }, e = (t) => { if (!t) return {}; try { return JSON.parse(t); } catch { return {}; } }; this.disposeWithMe( this._resourceManagerService.registerPluginResource({ toJson: n, parseJson: e, pluginName: Sl, businesses: [Sn.UNIVER_SHEET], onLoad: (t, o) => { this._worksheetProtectionRuleModel.fromObject(o), Object.keys(o).forEach((s) => { we().forEach((r) => { const i = new r(t, s); i.value = !1, this._permissionService.addPermissionPoint(i); }); }), this._worksheetProtectionRuleModel.changeRuleInitState(!0); }, onUnLoad: (t) => { const o = this._univerInstanceService.getUnit(t); o && (o.getSheets().forEach((s) => { const r = s.getSheetId(); [...we(), ...ke()].forEach((i) => { const a = new i(t, r); this._permissionService.deletePermissionPoint(a.id); }); }), en().forEach((s) => { const r = new s(t); this._permissionService.deletePermissionPoint(r.id); })), this._worksheetProtectionRuleModel.deleteUnitModel(t); } }) ); } _initPointSnapshot() { const n = () => { const t = this._worksheetProtectionPointRuleModel.toObject(); return JSON.stringify(t); }, e = (t) => { if (!t) return {}; try { return JSON.parse(t); } catch { return {}; } }; this.disposeWithMe( this._resourceManagerService.registerPluginResource({ toJson: n, parseJson: e, pluginName: wl, businesses: [Sn.UNIVER_SHEET], onLoad: (t, o) => { this._worksheetProtectionPointRuleModel.fromObject(o), Object.keys(o).forEach((s) => { ke().forEach((r) => { const i = new r(t, s); this._permissionService.addPermissionPoint(i); }); }); }, onUnLoad: (t) => { this._worksheetProtectionPointRuleModel.deleteUnitModel(t); } }) ); } }; bn = Cl([ Ze(0, L(Fe)), Ze(1, L(M)), Ze(2, L(Ro)), Ze(3, L(Ye)), Ze(4, L(un)), Ze(5, L(nn)), Ze(6, L(de)), Ze(7, L(Es)) ], bn); const Ao = { id: "sheet.mutation.set-worksheet-permission-points", type: v.MUTATION, handler: (n, e) => { const { rule: t } = e; return n.get(un).addRule(t), !0; } }, Il = { type: v.COMMAND, id: "sheet.command.set-worksheet-permission-points", async handler(n, e) { if (!e) return !1; const t = n.get(E), { rule: o } = e; return t.executeCommand(Ao.id, { rule: o, unitId: o.unitId, subUnitId: o.subUnitId }), !0; } }, vl = { type: v.COMMAND, id: "sheet.command.set-worksheet-protection", async handler(n, e) { if (!e) return !1; const t = n.get(E), o = n.get(W), { rule: s, permissionId: r, oldRule: i } = e, { unitId: a, subUnitId: u } = s, l = { ...s, permissionId: r }; if (await t.executeCommand(Ct.id, { unitId: a, subUnitId: u, newRule: l })) { const d = [{ id: Ct.id, params: { unitId: a, subUnitId: u, newRule: l } }], h = [{ id: Ct.id, params: { unitId: a, subUnitId: u, rule: i } }]; o.pushUndoRedo({ unitID: a, redoMutations: d, undoMutations: h }); } return !0; } }, Ml = 2e3, Hr = (n, e) => { const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager(); for (const { startRow: a, endRow: u } of s) for (let l = a; l < u + 1; l++) { const c = i.getRowOrCreate(l); r[l] = c.h; } return { unitId: t, subUnitId: o, ranges: s, rowHeight: r }; }, xo = (n, e) => { const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager(); for (const { startRow: a, endRow: u } of s) for (let l = a; l <= u; l++) { const c = i.getRowOrCreate(l); r[l] = c.ia; } return { unitId: t, subUnitId: o, ranges: s, autoHeightInfo: r }; }, ih = (n, e) => { const { unitId: t, subUnitId: o, rowsAutoHeightInfo: s } = n, r = [], i = e.getRowManager(); for (const a of s) { const { row: u } = a, { ah: l } = i.getRowOrCreate(u); r.push({ row: u, autoHeight: l }); } return { unitId: t, subUnitId: o, rowsAutoHeightInfo: r }; }, nt = { id: "sheet.mutation.set-worksheet-row-height", type: v.MUTATION, handler: (n, e) => { var l; const { ranges: t, rowHeight: o } = e, s = n.get(M), r = N(s, e); if (!r) return !1; const { worksheet: i } = r, a = i.getRowManager(), u = i.getConfig().defaultRowHeight; for (const { startRow: c, endRow: d } of t) for (let h = c; h <= d; h++) { const m = a.getRowOrCreate(h); typeof o == "number" ? m.h = o : m.h = (l = o[h]) != null ? l : u, m.h = Math.min(Ml, m.h); } return !0; } }, Oe = { id: "sheet.mutation.set-worksheet-row-is-auto-height", type: v.MUTATION, handler: (n, e) => { var a; const { ranges: t, autoHeightInfo: o } = e, s = n.get(M), r = N(s, e); if (!r) return !1; const i = r.worksheet.getRowManager(); for (const { startRow: u, endRow: l } of t) for (let c = u; c <= l; c++) { const d = i.getRowOrCreate(c); typeof o == "number" ? d.ia = o : d.ia = (a = o[c]) != null ? a : void 0; } return !0; } }, Br = { id: "sheet.mutation.set-worksheet-row-auto-height", type: v.MUTATION, handler: (n, e) => { const { rowsAutoHeightInfo: t } = e, o = n.get(M), s = N(o, e); if (!s) return !1; const r = s.worksheet.getRowManager(); for (const { row: i, autoHeight: a } of t) { const u = r.getRowOrCreate(i); u.ah = a; } return !0; } }, $o = { type: v.COMMAND, id: "sheet.command.delta-row-height", // eslint-disable-next-line max-lines-per-function handler: async (n, e) => { var U, P; const o = n.get(F).getCurrentSelections(), s = n.get(V); if (!(o != null && o.length)) return !1; const r = N(n.get(M)); if (!r) return !1; const { worksheet: i, subUnitId: a, unitId: u } = r, { anchorRow: l, deltaY: c } = e, h = i.getRowHeight(l) + c, m = o.length === 1 && o[0].range.rangeType === H.ALL, g = o.filter((A) => A.range.rangeType === H.ROW), f = m ? H.ALL : g.some(({ range: A }) => { const { startRow: j, endRow: Z } = A; return j <= l && l <= Z; }) ? H.ROW : H.NORMAL; let p; if (f === H.ALL) { const A = i.getRowCount(), j = new Array(i.getColumnCount()).fill(void 0).map( (Z, Y) => ({ startRow: Y, endRow: Y, startColumn: 0, endColumn: A - 1 }) ); p = { subUnitId: a, unitId: u, rowHeight: h, ranges: j }; } else f === H.ROW ? p = { subUnitId: a, unitId: u, ranges: g.map((A) => k.clone(A.range)), rowHeight: h } : p = { subUnitId: a, unitId: u, rowHeight: h, ranges: [ { startRow: l, endRow: l, startColumn: 0, endColumn: i.getMaxColumns() - 1 } ] }; const C = Hr(p, i), S = { unitId: u, subUnitId: a, ranges: p.ranges, autoHeightInfo: te.FALSE }, I = xo(S, i), w = n.get(E), b = n.get(W), y = s.onCommandExecute({ id: $o.id, params: p }), x = z([ { id: nt.id, params: p }, { id: Oe.id, params: S } ], w), T = z([...y.redos], w); return x.result && T.result ? (b.pushUndoRedo({ unitID: u, undoMutations: [ ...(U = y.preUndos) != null ? U : [], { id: nt.id, params: C }, { id: Oe.id, params: I }, ...y.undos ], redoMutations: [ ...(P = y.preRedos) != null ? P : [], { id: nt.id, params: p }, { id: Oe.id, params: S }, ...y.redos ] }), !0) : !1; } }, Wo = { type: v.COMMAND, id: "sheet.command.set-row-height", // eslint-disable-next-line max-lines-per-function handler: (n, e) => { var I, w, b, y; const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), i = n.get(V), a = (I = e == null ? void 0 : e.ranges) != null && I.length ? e.ranges : (w = t.getCurrentSelections()) == null ? void 0 : w.map((x) => x.range); if (!(a != null && a.length)) return !1; const u = N(r, e); if (!u) return !1; const { unitId: l, subUnitId: c, worksheet: d } = u, h = { subUnitId: c, unitId: l, ranges: a, rowHeight: e.value }, m = Hr(h, d), g = { unitId: l, subUnitId: c, ranges: h.ranges, autoHeightInfo: te.FALSE }, f = xo(g, d), p = z([ { id: nt.id, params: h }, { id: Oe.id, params: g } ], o), C = i.onCommandExecute({ id: Wo.id, params: h }), S = z([...C.redos], o); return p.result && S.result ? (s.pushUndoRedo({ unitID: l, undoMutations: [ ...(b = C.preRedos) != null ? b : [], { id: nt.id, params: m }, { id: Oe.id, params: f }, ...C.undos ], redoMutations: [ ...(y = C.preRedos) != null ? y : [], { id: nt.id, params: h }, { id: Oe.id, params: g }, ...C.redos ] }), !0) : !1; } }, Lo = { type: v.COMMAND, id: "sheet.command.set-row-is-auto-height", handler: (n, e) => { var C, S; const t = n.get(E), o = n.get(W), s = n.get(F), r = n.get(M), i = N(r, e); if (!i) return !1; const { unitId: a, subUnitId: u, worksheet: l } = i, c = (C = e == null ? void 0 : e.ranges) != null && C.length ? e.ranges : (S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range); if (!(c != null && c.length)) return !1; const d = { unitId: a, subUnitId: u, ranges: c, autoHeightInfo: te.TRUE // Hard code first, maybe it will change by the menu item in the future. }, h = xo(d, l), m = t.syncExecuteCommand( Oe.id, d ), { undos: g, redos: f } = n.get(V).onCommandExecute({ id: Lo.id, params: d }), p = z([...f], t); return m && p.result ? (o.pushUndoRedo({ unitID: a, undoMutations: [{ id: Oe.id, params: h }, ...g], redoMutations: [{ id: Oe.id, params: d }, ...f] }), !0) : !1; } }, Fr = { type: v.COMMAND, id: "sheet.command.set-worksheet-show", handler: (n, e) => { const { unitId: t, subUnitId: o } = e, s = n.get(E), r = n.get(W), i = n.get(M); if (!N(n.get(M))) return !1; const u = i.getCurrentUnitForType(B.UNIVER_SHEET); if (!u) return !1; const l = u.getSheetBySheetId(o); if (!l || l.getConfig().hidden === te.FALSE) return !1; const d = { unitId: t, subUnitId: o, hidden: te.FALSE }, h = $r(n, d), m = s.syncExecuteCommand(lt.id, d), g = { unitId: t, subUnitId: o }, f = s.syncExecuteCommand( an.id, g ); return m && f ? (r.pushUndoRedo({ unitID: t, undoMutations: [ { id: lt.id, params: h } // { id: SetWorksheetActiveOperation.id, params: unActiveMutationParams }, ], redoMutations: [ // { id: SetWorksheetActiveOperation.id, params: activeSheetMutationParams }, { id: lt.id, params: d } ] }), !0) : !1; } }; class _l { constructor() { R(this, "_tabCount", 0); R(this, "_commaCount", 0); R(this, "_semicolonCount", 0); R(this, "_spaceCount", 0); } add(e) { switch (e) { case " ": this._tabCount++; break; case ",": this._commaCount++; break; case ";": this._semicolonCount++; break; case " ": this._spaceCount++; break; } } update(e) { e && typeof e == "string" && (e.includes(" ") && this._tabCount++, e.includes(",") && this._commaCount++, e.includes(";") && this._semicolonCount++, e.trim().includes(" ") && this._spaceCount++); } getDelimiter() { const e = Math.max(this._tabCount, this._commaCount, this._semicolonCount, this._spaceCount); return e === 0 || e === this._tabCount ? 1 : e === this._commaCount ? 2 : e === this._semicolonCount ? 4 : e === this._spaceCount ? 8 : 1; } } function bl(n, e, t) { const o = []; t !== void 0 && (n & 16) > 0 && o.push(t), (n & 1) > 0 && o.push(" "), (n & 2) > 0 && o.push(","), (n & 4) > 0 && o.push(";"), (n & 8) > 0 && o.push(" "); let s = ""; for (const i of o) s += yl(i); let r = "[".concat(s, "]"); return e && (r += "+"), new RegExp(r); } function yl(n) { return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } const El = (n) => { var t; return ((t = n.body) == null ? void 0 : t.dataStream.replace(/\r\n$/, "")) || ""; }; function Ul(n) { if (n != null) { if (n.p) return El(n.p); if (n.v && typeof n.v == "string") return n.v; if (n.t && (n.t === se.FORCE_STRING || n.t === se.STRING)) return String(n.v); } } function Pl(n, e, t, o, s = !1) { const r = K.transformRange(e, n), { startColumn: i, startRow: a, endColumn: u, endRow: l } = r; if (i !== u) throw new Error("The range must be in the same column."); if (t && (t & 16) > 0 && (o === void 0 || o.length !== 1)) throw new Error("The custom delimiter must a character."); const c = t === void 0, d = c ? new _l() : null, h = []; for (let I = a; I <= l; I++) { const w = n.getCell(I, i), b = Ul(w); h.push(b), d && d.update(b); } const m = c ? d.getDelimiter() : t, g = bl(m, s, o); let f = -1, p = 0, C = 0; const S = []; for (const I of h) { if (I !== void 0) { const w = String(I).split(g); f < 0 ? f = w.length : f = Math.max(f, w.length), S.push(w), p = C; } else S.push(void 0); C++; } return { rs: S, maxLength: f === -1 ? 0 : f, lastRow: p }; } const Tl = { type: v.COMMAND, id: "sheet.command.split-text-to-columns", // eslint-disable-next-line max-lines-per-function handler: (n, e) => { const { unitId: t, subUnitId: o, range: s, delimiter: r, customDelimiter: i, treatMultipleDelimitersAsOne: a } = e, u = n.get(E), l = n.get(M), c = n.get(W); if (!N(n.get(M))) return !1; const h = l.getCurrentUnitForType(B.UNIVER_SHEET); if (!h) return !1; const m = h.getSheetBySheetId(o); if (!m) return !1; const { lastRow: g, rs: f, maxLength: p } = Pl(m, s, r, i, a), C = m.getColumnCount(), { startColumn: S } = K.transformRange(s, m); if (s.startColumn !== s.endColumn) return !1; const I = [], w = [], b = S + p + 1 - C; if (b > 0) { const A = { unitId: t, subUnitId: o, range: { startRow: 0, endRow: m.getRowCount() - 1, startColumn: C - 1, endColumn: C - 1 + b } }; I.push({ id: je.id, params: A }); const j = yo( n, A ); w.push({ id: De.id, params: j }); } const y = { startRow: s.startRow, endRow: g, startColumn: S, endColumn: S + p }, x = new G(); for (let A = y.startRow; A <= y.endRow; A++) for (let j = y.startColumn; j <= y.endColumn; j++) { const Z = f[A - y.startRow]; j === 0 && (Z == null ? void 0 : Z.length) === 1 ? x.setValue(A, j, m.getCell(A, j)) : x.setValue(A, j, { v: (Z == null ? void 0 : Z[j - y.startColumn]) || null, p: null, f: null, si: null, custom: null }); } const T = { unitId: t, subUnitId: o, cellValue: x.clone() }, U = Ae(n, T); return I.push({ id: Q.id, params: T }), w.unshift({ id: Q.id, params: U }), z(I, u).result ? (c.pushUndoRedo({ unitID: t, undoMutations: w, redoMutations: I }), !0) : !1; } }, kl = { id: "sheet.command.toggle-cell-checkbox", type: v.COMMAND, handler: (n, e) => { if (!e) return !1; const { unitId: t, subUnitId: o, row: s, col: r, paragraphIndex: i } = e, u = n.get(M).getUnit(t, B.UNIVER_SHEET), l = u == null ? void 0 : u.getSheetBySheetId(o), c = n.get(W), d = n.get(E); if (!l) return !1; const h = l.getCell(s, r); if (!(h != null && h.p)) return !1; const m = O.deepClone(h.p), g = new Ri(m), f = pi.paragraph.bullet.toggleChecklist({ document: g, paragraphIndex: i }); if (!f) return !1; Ci.apply(g.getBody(), f.serialize()); const p = { unitId: t, subUnitId: o, cellValue: { [s]: { [r]: { p: m, t: se.STRING } } } }, C = { id: Q.id, params: p }, S = Ae(n, p), I = { id: Q.id, params: S }, w = [C], b = [I]; return c.pushUndoRedo({ redoMutations: w, undoMutations: b, unitID: t }), d.syncExecuteCommand(C.id, C.params); } }, Ft = { id: "sheet.mutation.toggle-gridlines", type: v.MUTATION, handler: (n, e) => { const t = N(n.get(M), e); if (!t) return !1; const { worksheet: o } = t, s = o.getConfig(); return s.showGridlines = e.showGridlines, !0; } }, Nl = { type: v.COMMAND, id: "sheet.command.toggle-gridlines", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s); if (!r) return !1; const { worksheet: i } = r, a = i.getConfig().showGridlines; if (a === (e == null ? void 0 : e.showGridlines)) return !1; const { unitId: u, subUnitId: l } = r, c = { showGridlines: a === te.TRUE ? te.FALSE : te.TRUE, unitId: u, subUnitId: l }, d = { showGridlines: a, unitId: u, subUnitId: l }; return t.syncExecuteCommand(Ft.id, c) ? (o.pushUndoRedo({ unitID: u, undoMutations: [{ id: Ft.id, params: d }], redoMutations: [{ id: Ft.id, params: c }] }), !0) : !1; } }, Ol = { id: "sheet.command.unregister-worksheet-range-theme-style", type: v.COMMAND, handler: (n, e) => { var h; if (!e) return !1; const { unitId: t, themeName: o } = e, s = n.get(M), r = n.get(E), i = n.get(W), a = n.get(He); if (!N(s)) return !1; const l = { unitId: t, themeName: o }, c = { unitId: t, themeName: o, rangeThemeStyleJson: (h = a.getRangeThemeStyle(t, o)) == null ? void 0 : h.toJson() }; return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({ unitID: t, undoMutations: [{ id: Yt.id, params: c }], redoMutations: [{ id: Uo.id, params: l }] }), !0; } }, Dl = { id: "sheet.mutation.empty", type: v.MUTATION, handler: () => !0 }, Al = (n) => { const e = new G(); return n.forEach((t) => { K.foreach(t, (o, s) => { e.setValue(o, s, 1); }); }), e.forValue((t, o) => { const s = e.getValue(t - 1, o); s && e.setValue(t, o, s + 1); }), e; }, xl = (n) => { const e = n; return e.forValue((t, o) => { const s = n.getValue(t - 1, o); s && e.setValue(t, o, s + 1); }), e; }, Qo = (n) => { const e = { area: 0 }, t = (o, s) => e.area < o ? (e.area = o, e.range = s, !0) : !1; return n.forValue((o, s, r) => { let i = 1, a = r; t(i * a, { startRow: o - a + 1, endRow: o, startColumn: s, endColumn: s }); const u = { startRow: o - a + 1, endRow: o, startColumn: 0, endColumn: s }; for (let l = s - 1; l >= 0 && n.getValue(o, l); l--) { a = Math.min(n.getValue(o, l) || 0, a), i++; const c = a * i; u.startColumn = l, u.startRow = o - a + 1, t(c, u); } }), e; }, $l = (n, e) => { K.foreach(e, (t, o) => { n.realDeleteValue(t, o); }); for (let t = e.startColumn; t <= e.endColumn; t++) { const o = e.endRow + 1; if (n.getValue(o, t) > 0) { n.setValue(o, t, 1); let r = o + 1; for (; n.getValue(r, t) > 0; ) n.setValue(r, t, n.getValue(r - 1, t) + 1), r++; } } return n; }, jr = (n) => { const e = []; let t = Qo(n); for (; t.area > 0; ) t.range && (e.push(t.range), $l(n, t.range)), t = Qo(n); return e; }, Gr = (n) => { const e = Al(n); return jr(e); }; class ah { constructor() { R(this, "_matrix", new G()); } add(...e) { return e.forEach((t) => { K.foreach(t, (o, s) => { this._matrix.setValue(o, s, 1); }); }), this; } subtract(...e) { return e.forEach((t) => { K.foreach(t, (o, s) => { this._matrix.realDeleteValue(o, s); }); }), this; } merge() { const e = xl(this._matrix); return jr(e); } } const wt = fo("INumfmtService"), uh = (n, e) => { const t = n.get(wt), { values: o, unitId: s, subUnitId: r } = e, i = [], a = []; Object.keys(o).forEach((l) => { o[l].ranges.forEach((d) => { K.foreach(d, (h, m) => { const g = t.getValue(s, r, h, m); g ? i.push({ pattern: g.pattern, row: h, col: m }) : a.push({ startColumn: m, endColumn: m, startRow: h, endRow: h }); }); }); }); const u = []; if (i.length) { const l = lo(s, r, i); Object.keys(l.values).forEach((c) => { const d = l.values[c]; d.ranges = Gr(d.ranges); }), u.push({ id: Vo.id, params: lo(s, r, i) }); } return a.length && u.push({ id: zr.id, params: { unitId: s, subUnitId: r, ranges: a } }), u; }, Vo = { id: "sheet.mutation.set.numfmt", type: v.MUTATION, handler: (n, e) => { if (!e) return !1; const { values: t, refMap: o } = e, s = n.get(wt), r = e.unitId, i = e.subUnitId, a = Object.keys(t).reduce( (u, l) => { const c = o[l], d = t[l].ranges; return c && u.push({ ...c, ranges: d }), u; }, [] ); return s.setValues(r, i, a), !0; } }, zr = { id: "sheet.mutation.remove.numfmt", type: v.MUTATION, handler: (n, e) => { if (!e) return !1; const { unitId: t, subUnitId: o, ranges: s } = e; return n.get(wt).deleteValues(t, o, s), !0; } }, lh = (n, e) => { const t = n.get(wt), { ranges: o, unitId: s, subUnitId: r } = e, i = []; if (o.forEach((u) => { K.foreach(u, (l, c) => { const d = t.getValue(s, r, l, c); d && i.push({ pattern: d.pattern, row: l, col: c }); }); }), !i.length) return []; const a = lo(s, r, i); return Object.keys(a.values).forEach((u) => { const l = a.values[u]; l.ranges = Gr(l.ranges); }), [{ id: Vo.id, params: a }]; }, lo = (n, e, t) => { const o = ya(t, "pattern"), s = {}, r = {}, i = Ea(); return Object.keys(o).forEach((a) => { const u = o[a], l = i(); s[l] = { pattern: a }, u.forEach((c) => { r[l] || (r[l] = { ranges: [] }), r[l].ranges.push(ws(c.row, c.col)); }); }), { unitId: n, subUnitId: e, refMap: s, values: r }; }, Wl = { id: "sheet.operation.scroll-to-cell", type: v.OPERATION, handler: () => !0 }, Kr = "ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY", Ll = "maxCellsPerSheet", Vl = 3e6; var Hl = Object.defineProperty, Bl = Object.getOwnPropertyDescriptor, Fl = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Bl(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Hl(e, t, s), s; }, to = (n, e) => (t, o) => e(t, o, n); let yn = class extends ae { // eslint-disable-next-line max-lines-per-function constructor(n, e, t) { var s; super(), this._commandService = n, this._configService = e, this._dataSyncPrimaryController = t, [ Q, je, qe, Jt, dt, ot, st, De, Be, Ut, oe, zr, ne, Or, _n, Vo, In, Dl, Qt, // formula SUBTOTAL Zt, Xt, qt ].forEach((r) => { var i; this._commandService.registerCommand(r), (i = this._dataSyncPrimaryController) == null || i.registerSyncingMutations(r); }), ((s = this._configService.getConfig(Kr)) != null ? s : !1) || [ po, Co, So, xs, Pt, Tt, Oo, $o, gu, mu, pr, gt, sn, Bn, hu, du, fr, mt, fu, jn, pt, Fn, vr, zn, Mr, Gn, ko, uo, Iu, tl, Qu, el, Ou, Nu, rn, Tu, ku, yr, Mn, $u, Lt, Bu, ut, Fu, ol, on, Wo, kr, Ku, Ht, br, Tr, Kn, Jn, fe, al, fn, Zu, rl, sl, nl, Dr, Ar, an, hl, lt, Do, Wr, Rn, Br, nt, Lo, Oe, tt, // SetWorksheetColIsAutoWidthCommand, re, Wl, au, Ir, Ur, Fr, Nl, Ft, ju, Vt, // permissions range protection Il, ct, Ct, St, Ao, Xi, Gu, su, qi, ru, vl, Ne, ze, he, kl, Bt, dl, Tl, // range theme Kt, zt, Uo, Yt, Ol, wu, ba, iu ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r))), this._configService.setConfig(Ll, Vl); } }; yn = Fl([ to(0, E), to(1, Us), to(2, Si(Fi)) ], yn); var jl = Object.defineProperty, Gl = Object.getOwnPropertyDescriptor, zl = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Gl(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && jl(e, t, s), s; }, es = (n, e) => (t, o) => e(t, o, n); let En = class extends ae { constructor(n, e) { super(), this._univerInstanceService = n, this._commandService = e, this._initialize(); } _initialize() { this.disposeWithMe( this._commandService.onCommandExecuted((n) => { if (n.id !== Di.id) return; const e = n.params, { unitData: t } = e, o = Object.keys(t), s = []; for (let i = 0; i < o.length; i++) { const a = o[i], u = t[a]; if (u == null) continue; const l = Object.keys(u); for (let c = 0; c < l.length; c++) { const d = l[c], h = u[d]; if (h == null) continue; const m = this._getMergedCellData(a, d, h), g = { subUnitId: d, unitId: a, cellValue: m }; s.push({ id: Q.id, params: g }); } } return s.every( (i) => this._commandService.executeCommand(i.id, i.params, { onlyLocal: !0 }) ); }) ); } /** * Priority that mainly deals with number format in unitData * @param unitId * @param sheetId * @param cellData * @returns */ _getMergedCellData(n, e, t) { const o = this._univerInstanceService.getUniverSheetInstance(n), s = o == null ? void 0 : o.getStyles(), r = o == null ? void 0 : o.getSheetBySheetId(e), i = r == null ? void 0 : r.getCellMatrix(), a = new G(t); return a.forValue((u, l, c) => { const d = i == null ? void 0 : i.getValue(u, l), h = Ai(d, c, s); a.setValue(u, l, h); }), a.getMatrix(); } }; En = zl([ es(0, L(M)), es(1, E) ], En); const Kl = "sheets.config", ts = {}; var Jl = Object.defineProperty, Yl = Object.getOwnPropertyDescriptor, Xl = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Yl(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Jl(e, t, s), s; }, ns = (n, e) => (t, o) => e(t, o, n); const ql = "SHEET_DEFINED_NAME_PLUGIN", ch = "AllDefaultWorkbook"; let Un = class extends ae { constructor(n, e) { super(), this._definedNamesService = n, this._resourceManagerService = e, this._initialize(); } _initialize() { this._initSnapshot(); } _initSnapshot() { const n = (t) => { const o = this._definedNamesService.getDefinedNameMap(t); return o ? JSON.stringify(o) : ""; }, e = (t) => { if (!t) return {}; try { return JSON.parse(t); } catch { return {}; } }; this.disposeWithMe( this._resourceManagerService.registerPluginResource({ pluginName: ql, businesses: [B.UNIVER_SHEET], toJson: (t) => n(t), parseJson: (t) => e(t), onUnLoad: (t) => { this._definedNamesService.removeUnitDefinedName(t); }, onLoad: (t, o) => { this._definedNamesService.registerDefinedNames(t, o); } }) ); } }; Un = Xl([ ns(0, Ps), ns(1, nn) ], Un); const $ = { MoveRangeCommandId: $s, InsertRowCommandId: gr, InsertColCommandId: Rr, RemoveColCommandId: To, RemoveRowCommandId: Po, DeleteRangeMoveLeftCommandId: dr, DeleteRangeMoveUpCommandId: hr, InsertRangeMoveDownCommandId: cu, InsertRangeMoveRightCommandId: Eo, MoveColsCommandId: Sr, MoveRowsCommandId: Cr, ReorderRangeCommandId: _r }; var q = /* @__PURE__ */ ((n) => (n[n.Set = 0] = "Set", n[n.Delete = 1] = "Delete", n[n.HorizontalMove = 2] = "HorizontalMove", n[n.VerticalMove = 3] = "VerticalMove", n[n.Unknown = 4] = "Unknown", n))(q || {}); const cn = Number.MAX_SAFE_INTEGER, Ve = (n) => { const e = { ...n }, t = Number.isNaN(e.startRow) && Number.isNaN(e.endRow) && !Number.isNaN(e.startColumn) && !Number.isNaN(e.endColumn), o = Number.isNaN(e.startColumn) && Number.isNaN(e.endColumn) && !Number.isNaN(e.startRow) && !Number.isNaN(e.endRow); return (e.rangeType === H.COLUMN || t) && (e.startRow = 0, e.endRow = cn), (e.rangeType === H.ROW || o) && (e.startColumn = 0, e.endColumn = cn), e.rangeType === H.ALL && (e.startColumn = 0, e.endColumn = cn, e.startRow = 0, e.endRow = cn), e; }, _e = (n) => { let e = n.rangeType; return n.rangeType === H.COLUMN ? e = H.ROW : n.rangeType === H.ROW && (e = H.COLUMN), { startRow: n.startColumn, endRow: n.endColumn, startColumn: n.startRow, endColumn: n.endRow, rangeType: e }; }, Pn = (n, e, t) => { const o = { ...t }, s = { ...e }, r = (f, p) => { const C = Math.max(f.start, p.start), S = Math.min(f.end, p.end); return S < C ? null : { start: C, end: S }; }, i = (f) => f.end - f.start + 1, a = (f, p) => ({ start: f.start - p.start, end: f.start - p.start + f.end - f.start }), u = (f, p) => ({ start: p.start + f.start, end: p.start + f.start + f.end - f.start }), l = e.start > n.start; if (l) { const f = Math.min(n.end, e.start) - n.start + 1; s.start -= f, s.end -= f; } const c = i(n), d = c, h = r(n, o), m = h && i(h) >= i(o); if (n.end < o.start) o.start -= c, o.end -= c; else if (h) { const f = i(h); if (m) { const p = a(o, n), C = u(p, s); o.start = C.start, o.end = C.end; } else h.start > n.start ? l ? (o.end -= f + c, o.start -= c) : o.end -= f : l ? o.end -= f : o.start > n.start && o.end > n.end ? (o.start -= c, o.end -= c + f) : o.end -= f; } const g = r(s, o); return m || (s.start <= o.start ? (o.start += d, o.end += d) : g && (l ? s.end <= o.start || s.start <= o.start && s.end >= o.start ? (o.start += d, o.end += d) : s.start >= o.start && s.start <= o.end && (o.end += d) : o.start < s.start && o.end > s.start ? o.end += d : (o.start >= s.end || o.start >= s.start && o.start <= s.end) && (o.end += d, o.start += d))), { step: o.start - t.start, length: i(o) - i(t) }; }, Jr = (n, e) => { const { fromRange: t, toRange: o } = n.params || {}; if (!o || !t) return []; const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn( { start: s.startRow, end: s.endRow }, { start: r.startRow, end: r.endRow }, { start: i.startRow, end: i.endRow } ); return a === null ? [ { type: q.Delete } ] : [ { type: q.VerticalMove, step: a.step || 0, length: a.length || 0 } ]; }, Zl = (n, e) => { const { fromRange: t, toRange: o } = n.params || {}; if (!t || !o) return [e]; const s = t.startRow, r = t.endRow - t.startRow + 1, i = o.startRow, a = new G(); return K.foreach(e, (l, c) => { a.setValue(l, c, 1); }), a.moveRows(s, r, i), Je(a, (l) => l === 1); }, Ql = (n, e) => { const { range: t, order: o } = n.params || {}; if (!t || !o) return [e]; const s = new G(); K.foreach(e, (a, u) => { s.setValue(a, u, 1); }); const r = new G(); return K.foreach(t, (a, u) => { var l; if (o.hasOwnProperty(a)) { const c = o[a], d = (l = s.getValue(c, u)) != null ? l : 0; r.setValue(a, u, d); } }), r.forValue((a, u, l) => { s.setValue(a, u, l); }), Je(s, (a) => a === 1); }, Yr = (n, e) => { const { fromRange: t, toRange: o } = n.params || {}; if (!o || !t) return []; const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn( { start: s.startColumn, end: s.endColumn }, { start: r.startColumn, end: r.endColumn }, { start: i.startColumn, end: i.endColumn } ); return a === null ? [ { type: q.Delete } ] : [ { type: q.HorizontalMove, step: a.step || 0, length: a.length || 0 } ]; }, ec = (n, e) => { const { fromRange: t, toRange: o } = n.params || {}; if (!t || !o) return [e]; const s = t.startColumn, r = t.endColumn - t.startColumn + 1, i = o.startColumn, a = new G(); return K.foreach(e, (u, l) => { a.setValue(u, l, 1); }), a.moveColumns(s, r, i), Je(a, (u) => u === 1); }, tc = (n, e) => { var r, i; const t = (r = n.params) == null ? void 0 : r.toRange, o = (i = n.params) == null ? void 0 : i.fromRange; if (!t || !o) return []; const s = []; if (k.contains(t, e) && s.push({ type: q.Delete }), k.contains(o, e)) { s.push({ type: q.Delete }); const a = k.getRelativeRange(e, o), u = k.getPositionRange(a, t); return [ { type: q.Set, range: u } ]; } return s; }, nc = (n, e) => { var d, h; const t = (d = n.params) == null ? void 0 : d.toRange, o = (h = n.params) == null ? void 0 : h.fromRange; if (!t || !o) return [e]; if (!k.intersects(o, e) && !k.intersects(t, e)) return [e]; if (k.contains(o, e)) { const m = k.getRelativeRange(e, o); return [k.getPositionRange(m, t)]; } const s = new G(); K.foreach(e, (m, g) => { s.setValue(m, g, 1); }); const r = new G(), i = k.getIntersects(o, e); i && K.foreach(i, (m, g) => { s.getValue(m, g) && (s.setValue(m, g, void 0), r.setValue(m, g, 1)); }); const a = t.startColumn - o.startColumn, u = t.startRow - o.startRow, l = { startColumn: t.startColumn - a, endColumn: t.endColumn - a, startRow: t.startRow - u, endRow: t.endRow - u }; return K.foreach(l, (m, g) => { var C; const f = m + u, p = g + a; s.setValue(f, p, (C = r.getValue(m, g)) != null ? C : 0); }), Je(s, (m) => m === 1); }, It = (n, e) => { const t = Ve(n), o = Ve(e), s = (i) => i.endColumn - i.startColumn + 1, r = (i) => i.endRow - i.startRow + 1; if (t.startRow <= o.startRow && t.endRow >= o.endRow) { if ( // 2 o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6 o.startColumn < t.startColumn && o.endColumn >= t.endColumn ) { const i = k.getIntersects(o, t); if (i) return { step: 0, length: -s(i) }; } if (o.startColumn >= t.startColumn && o.endColumn <= t.endColumn && r(t) >= r(o)) return null; if (o.startColumn >= t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn) { const i = k.getIntersects(o, t); if (i) { const a = -s(i); return { step: -(s(t) - s(i)), length: a }; } } if (o.startColumn > t.endColumn) return { step: -s(t), length: 0 }; } return { step: 0, length: 0 }; }, Xr = (n, e) => { var r; const t = (r = n.params) == null ? void 0 : r.range; if (!t) return []; const o = [], s = It(t, e); if (!s) o.push({ type: q.Delete }); else { const { step: i, length: a } = s; o.push({ type: q.HorizontalMove, step: i, length: a }); } return o; }, oc = (n, e) => { var r; const t = (r = n.params) == null ? void 0 : r.range; if (!t) return []; const o = [], s = It(_e(t), _e(e)); if (!s) o.push({ type: q.Delete }); else { const { step: i, length: a } = s; o.push({ type: q.VerticalMove, step: i, length: a }); } return o; }, sc = (n, e) => { const { range: t, order: o } = n.params || {}; if (!t || !o) return []; if (k.contains(t, e) && e.endRow === e.startRow) { const s = [], r = e.startRow; for (const i in o) if (o[i] === r) { const a = Number(i); return s.push({ type: q.VerticalMove, step: a - r, length: 0 }), s; } return []; } return []; }, vt = (n, e) => { const t = Ve(n), o = Ve(e), s = (r) => r.endColumn - r.startColumn + 1; if (t.startRow <= o.startRow && t.endRow >= o.endRow) { if ( // 2 o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6 o.startColumn < t.startColumn && o.endColumn >= t.endColumn ) return { step: 0, length: s(t) }; if ( // 3 o.startColumn >= t.startColumn && o.endColumn <= t.endColumn || // 4 o.startColumn > t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn || //5 o.startColumn >= t.endColumn ) return { step: s(t), length: 0 }; } return { step: 0, length: 0 }; }; function rc(n, e, t) { const o = []; if (k.contains(e, t) && o.push({ type: q.Delete }), k.contains(n, t)) { o.push({ type: q.Delete }); const s = k.getRelativeRange(t, n), r = k.getPositionRange(s, e); return [ { type: q.Set, range: r } ]; } return o; } const ic = (n, e) => { var a; const t = (a = n.params) == null ? void 0 : a.range; if (!t) return []; const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s; return o.push({ type: q.VerticalMove, step: r, length: i }), o; }, ac = (n, e) => { var a; const t = (a = n.params) == null ? void 0 : a.range; if (!t) return []; const o = [], s = vt(t, e), { step: r, length: i } = s; return o.push({ type: q.HorizontalMove, step: r, length: i }), o; }, uc = (n, e) => { var a; const t = (a = n.params) == null ? void 0 : a.range; if (!t) return []; const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s; return o.push({ type: q.VerticalMove, step: r, length: i }), o; }, lc = (n, e) => { var u; const t = (u = n.params) == null ? void 0 : u.range; if (!t) return [e]; const o = t.endRow - t.startRow + 1, s = { ...t, startRow: t.startRow, endRow: Number.POSITIVE_INFINITY }, r = k.subtract(e, s), i = k.getIntersects(s, e); if (!i) return [e]; const a = new G(); return r.forEach((l) => { K.foreach(l, (c, d) => { a.setValue(c, d, 1); }); }), i && K.foreach(i, (l, c) => { a.setValue(l + o, c, 1); }), Je(a, (l) => l === 1); }, cc = (n, e) => { var a; const t = (a = n.params) == null ? void 0 : a.range; if (!t) return []; const o = [], s = vt(t, e), { step: r, length: i } = s; return o.push({ type: q.HorizontalMove, step: r, length: i }), o; }, dc = (n, e) => { var u; const t = (u = n.params) == null ? void 0 : u.range; if (!t) return [e]; const o = t.endColumn - t.startColumn + 1, s = { ...t, startColumn: t.startColumn, endColumn: Number.POSITIVE_INFINITY }, r = k.subtract(e, s), i = k.getIntersects(s, e); if (!i) return [e]; const a = new G(); return r.forEach((l) => { K.foreach(l, (c, d) => { a.setValue(c, d, 1); }); }), i && K.foreach(i, (l, c) => { a.setValue(l, c + o, 1); }), Je(a, (l) => l === 1); }, hc = (n, e) => { var r; const t = (r = n.params) == null ? void 0 : r.range; if (!t) return []; const o = [], s = It(t, e); if (!s) o.push({ type: q.Delete }); else { const { step: i, length: a } = s; o.push({ type: q.HorizontalMove, step: i, length: a }); } return o; }, mc = (n, e) => { var l; const t = (l = n.params) == null ? void 0 : l.range; if (!t) return [e]; const o = { startRow: t.startRow, endRow: t.endRow, startColumn: t.startColumn, endColumn: Number.POSITIVE_INFINITY }, s = t.endColumn - t.startColumn + 1, r = k.getIntersects(t, e), i = k.subtract(e, o), a = k.getIntersects(o, e); if (!r && !a) return [e]; const u = new G(); return a && K.foreach(a, (c, d) => { u.setValue(c, d - s, 1); }), r && K.foreach(r, (c, d) => { u.setValue(c, d - s, 0); }), i.forEach((c) => { K.foreach(c, (d, h) => { u.setValue(d, h, 1); }); }), Je(u, (c) => c === 1); }, gc = (n, e) => { var r; const t = (r = n.params) == null ? void 0 : r.range; if (!t) return []; const o = [], s = It(_e(t), _e(e)); if (!s) o.push({ type: q.Delete }); else { const { step: i, length: a } = s; o.push({ type: q.VerticalMove, step: i, length: a }); } return o; }, fc = (n, e) => { var l; const t = (l = n.params) == null ? void 0 : l.range; if (!t) return [e]; const o = { ...t, startRow: t.startRow, endRow: Number.POSITIVE_INFINITY }, s = t.endRow - t.startRow + 1, r = k.getIntersects(t, e), i = k.subtract(e, o), a = k.getIntersects(o, e); if (!r && !a) return [e]; const u = new G(); return a && K.foreach(a, (c, d) => { u.setValue(c - s, d, 1); }), r && K.foreach(r, (c, d) => { u.setValue(c - s, d, 0); }), i.forEach((c) => { K.foreach(c, (d, h) => { u.setValue(d, h, 1); }); }), Je(u, (c) => c === 1); }, Rc = (n, e) => { var s; const t = (s = n.ranges) != null ? s : [n.range], o = new G(); return K.foreach(e, (r, i) => { o.setValue(r, i, 1); }), t.forEach((r) => { const i = r.startRow, u = r.endRow - i + 1; o.removeRows(i, u); }), Je(o, (r) => r === 1); }, pc = (n, e) => { const t = n.params, o = t.range.startRow, s = t.range.endRow - t.range.startRow + 1, r = t.direction; return r === pe.UP && o === e.startRow || r === pe.DOWN && o - 1 === e.endRow ? [ { startRow: e.startRow, endRow: e.endRow + s, startColumn: e.startColumn, endColumn: e.endColumn } ] : e.startRow >= o ? [{ startRow: e.startRow + s, endRow: e.endRow + s, startColumn: e.startColumn, endColumn: e.endColumn }] : e.endRow <= o ? [e] : [{ startRow: e.startRow, endRow: e.endRow + s, startColumn: e.startColumn, endColumn: e.endColumn }]; }, Cc = (n, e) => { const t = n.params, o = t.range.startColumn, s = t.range.endColumn - t.range.startColumn + 1, r = t.direction; return r === pe.LEFT && o === e.startColumn || r === pe.RIGHT && o - 1 === e.endColumn ? [ { startRow: e.startRow, endRow: e.endRow, startColumn: e.startColumn, endColumn: e.endColumn + s } ] : e.startColumn >= o ? [{ startRow: e.startRow, endRow: e.endRow, startColumn: e.startColumn + s, endColumn: e.endColumn + s }] : e.endColumn <= o ? [e] : [{ startRow: e.startRow, endRow: e.endRow, startColumn: e.startColumn, endColumn: e.endColumn + s }]; }, Mt = (n, e) => { let t = { ...e }; return n.forEach((o) => { switch (o.type) { case q.Delete: { t = null; break; } case q.HorizontalMove: { if (!t) return; t.startColumn += o.step, t.endColumn += o.step + (o.length || 0); break; } case q.VerticalMove: { if (!t) return; t.startRow += o.step, t.endRow += o.step + (o.length || 0); break; } case q.Set: { t = o.range; break; } } }), t && (t.endColumn < t.startColumn || t.endRow < t.startRow) ? null : t; }, os = (n, e) => { let t = []; switch (e.id) { case $.DeleteRangeMoveLeftCommandId: { t = hc(e, n); break; } case $.DeleteRangeMoveUpCommandId: { t = gc(e, n); break; } case $.InsertColCommandId: { t = ac(e, n); break; } case $.InsertRangeMoveDownCommandId: { t = uc(e, n); break; } case $.InsertRangeMoveRightCommandId: { t = cc(e, n); break; } case $.InsertRowCommandId: { t = ic(e, n); break; } case $.MoveColsCommandId: { t = Yr(e, n); break; } case $.MoveRangeCommandId: { t = tc(e, n); break; } case $.MoveRowsCommandId: { t = Jr(e, n); break; } case $.RemoveColCommandId: { t = Xr(e, n); break; } case $.RemoveRowCommandId: { t = oc(e, n); break; } case $.ReorderRangeCommandId: { t = sc(e, n); break; } } return Mt(t, n); }, dh = (n, e, t) => [Pt.id, Tt.id].includes(e.id) || qr(e, t).some((r) => k.intersects(r, n)) ? os(n, e) : n, ss = (n, e) => { let t = []; switch (e.id) { case $.DeleteRangeMoveLeftCommandId: return mc(e, n); case $.DeleteRangeMoveUpCommandId: return fc(e, n); case $.InsertRangeMoveDownCommandId: return lc(e, n); case $.InsertRangeMoveRightCommandId: return dc(e, n); case $.InsertColCommandId: return Cc(e, n); case $.InsertRowCommandId: return pc(e, n); case $.MoveColsCommandId: return ec(e, n); case $.MoveRangeCommandId: return nc(e, n); case $.MoveRowsCommandId: return Zl(e, n); case $.ReorderRangeCommandId: return Ql(e, n); case $.RemoveColCommandId: { t = Xr(e, n); break; } case $.RemoveRowCommandId: return Rc(e.params, n); } const o = Mt(t, n); return o ? [o] : []; }, hh = (n, e, t) => [Pt.id, Tt.id, sn.id, Eo].includes(e.id) || qr(e, t).some((r) => k.intersects(r, n)) ? ss(n, e) : n; function Sc(n, e) { const { id: t, params: o } = e; let s = { length: 0, step: 0, type: q.Unknown }; switch (t) { case Ut.id: s.type = q.Delete; break; case ot.id: s = Pn( { start: o.sourceRange.startRow, end: o.sourceRange.endRow }, { start: o.targetRange.startRow, end: o.targetRange.endRow }, { start: n.startRow, end: n.endRow } ), s.type = q.VerticalMove; break; case st.id: s = Pn( { start: o.sourceRange.startColumn, end: o.sourceRange.endColumn }, { start: o.targetRange.startColumn, end: o.targetRange.endColumn }, { start: n.startColumn, end: n.endColumn } ), s.type = q.HorizontalMove; break; case De.id: s = It(o.range, n), s ? s.type = q.HorizontalMove : s = { step: 0, length: 0, type: q.Delete }; break; case Be.id: s = It(_e(o.range), _e(n)), s ? s.type = q.VerticalMove : s = { step: 0, length: 0, type: q.Delete }; break; case qe.id: s = vt(_e(o.range), _e(n)), s.type = q.VerticalMove; break; case je.id: s = vt(o.range, n), s.type = q.HorizontalMove; break; case dt.id: { const r = o.fromRange || new G(o.from).getRange(), i = o.toRange || new G(o.to).getRange(); s = rc( r, i, n ); } break; } return s ? Array.isArray(s) ? Mt(s, n) : Mt([s], n) : n; } function qr(n, e) { var o, s, r, i, a, u; const { selectionManagerService: t } = e; switch (n.id) { case $.MoveColsCommandId: { const l = n.params; return [ l.fromRange, { ...l.toRange, startColumn: l.toRange.startColumn - 0.5, endColumn: l.toRange.endColumn - 0.5 } ]; } case $.MoveRowsCommandId: { const l = n.params; return [ l.fromRange, { ...l.toRange, startRow: l.toRange.startRow - 0.5, endRow: l.toRange.startRow - 0.5 } ]; } case $.MoveRangeCommandId: { const l = n; return [l.params.fromRange, l.params.toRange]; } case $.InsertRowCommandId: { const c = n.params.range; return [ { ...c, startRow: c.startRow - 0.5, endRow: c.endRow - 0.5 } ]; } case $.InsertColCommandId: { const c = n.params.range; return [ { ...c, startColumn: c.startColumn - 0.5, endColumn: c.endColumn - 0.5 } ]; } case $.RemoveRowCommandId: return [n.params.range]; case $.RemoveColCommandId: return [n.params.range]; case $.DeleteRangeMoveUpCommandId: case $.InsertRangeMoveDownCommandId: { const c = ((o = n.params) == null ? void 0 : o.range) || ((r = (s = t.getCurrentSelections()) == null ? void 0 : s.map((d) => d.range)) == null ? void 0 : r[0]); return c ? [c] : []; } case $.DeleteRangeMoveLeftCommandId: case $.InsertRangeMoveRightCommandId: { const c = ((i = n.params) == null ? void 0 : i.range) || ((u = (a = t.getCurrentSelections()) == null ? void 0 : a.map((d) => d.range)) == null ? void 0 : u[0]); return c ? [c] : []; } case $.ReorderRangeCommandId: { const l = n, { range: c, order: d } = l.params, h = []; for (let m = c.startRow; m <= c.endRow; m++) m in d && h.push({ startRow: m, endRow: m, startColumn: c.startColumn, endColumn: c.endColumn }); return h; } } } function wc(n) { switch (n.id) { case st.id: { const e = n.params; return [ e.sourceRange, { ...e.targetRange, startColumn: e.targetRange.startColumn - 0.5, endColumn: e.targetRange.startColumn - 0.5 } ]; } case ot.id: { const e = n.params; return [ e.sourceRange, { ...e.targetRange, startRow: e.targetRange.startRow - 0.5, endRow: e.targetRange.startRow - 0.5 } ]; } case dt.id: { const e = n.params; return [new G(e.from.value).getRange(), new G(e.to.value).getRange()]; } case je.id: { const t = n.params.range; return [ { ...t, startColumn: t.startColumn - 0.5, endColumn: t.startColumn - 0.5 } ]; } case qe.id: { const t = n.params.range; return [ { ...t, startRow: t.startRow - 0.5, endRow: t.startRow - 0.5 } ]; } case De.id: return [n.params.range]; case Be.id: return [n.params.range]; } } function mh(n, e) { var s, r, i, a, u, l; const t = n.get(M), o = n.get(F); switch (e.id) { case $.MoveColsCommandId: { const c = e.params, d = N(t, { unitId: c.unitId, subUnitId: c.subUnitId }); return { unitId: d.unitId, subUnitId: d.subUnitId, ranges: [ c.fromRange, { ...c.toRange, startColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.fromRange.endColumn + 1 : c.toRange.startColumn, endColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.toRange.endColumn - 1 : c.fromRange.startColumn - 1 } ] }; } case $.MoveRowsCommandId: { const c = e.params, d = N(t, { unitId: c.unitId, subUnitId: c.subUnitId }); return { unitId: d.unitId, subUnitId: d.subUnitId, ranges: [ c.fromRange, { ...c.toRange, startRow: c.fromRange.startRow < c.toRange.startRow ? c.fromRange.endRow + 1 : c.toRange.startRow, endRow: c.fromRange.startRow < c.toRange.startRow ? c.toRange.endRow - 1 : c.fromRange.startRow - 1 } ] }; } case $.MoveRangeCommandId: { const c = e.params, d = N(t); return { unitId: d.unitId, subUnitId: d.subUnitId, ranges: [c.fromRange, c.toRange] }; } case $.InsertRowCommandId: { const c = e.params, d = c.range; return { unitId: c.unitId, subUnitId: c.subUnitId, ranges: [ ...d.startRow > 0 ? [{ ...d, startRow: d.startRow - 1, endRow: d.endRow - 1 }] : [], { ...d, startRow: d.startRow, endRow: Number.MAX_SAFE_INTEGER } ] }; } case $.InsertColCommandId: { const c = e.params, d = c.range; return { unitId: c.unitId, subUnitId: c.subUnitId, ranges: [ ...d.startColumn > 0 ? [{ ...d, startColumn: d.startColumn - 1, endColumn: d.endColumn - 1 }] : [], { ...d, startColumn: d.startColumn, endColumn: Number.MAX_SAFE_INTEGER } ] }; } case $.RemoveRowCommandId: { const d = e.params.range, h = N(t); return { unitId: h.unitId, subUnitId: h.subUnitId, ranges: [ d, { ...d, startRow: d.endRow + 1, endRow: Number.MAX_SAFE_INTEGER } ] }; } case $.RemoveColCommandId: { const d = e.params.range, h = N(t); return { unitId: h.unitId, subUnitId: h.subUnitId, ranges: [ d, { ...d, startColumn: d.endColumn + 1, endColumn: Number.MAX_SAFE_INTEGER } ] }; } case $.DeleteRangeMoveUpCommandId: case $.InsertRangeMoveDownCommandId: { const c = e, d = N(t), h = ((s = c.params) == null ? void 0 : s.range) || ((i = (r = o.getCurrentSelections()) == null ? void 0 : r.map((m) => m.range)) == null ? void 0 : i[0]); return h ? { unitId: d.unitId, subUnitId: d.subUnitId, ranges: [ h, { ...h, startRow: h.endRow + 1, endRow: Number.MAX_SAFE_INTEGER } ] } : { unitId: d.unitId, subUnitId: d.subUnitId, ranges: [] }; } case $.DeleteRangeMoveLeftCommandId: case $.InsertRangeMoveRightCommandId: { const d = ((a = e.params) == null ? void 0 : a.range) || ((l = (u = o.getCurrentSelections()) == null ? void 0 : u.map((m) => m.range)) == null ? void 0 : l[0]), h = N(t); return d ? { unitId: h.unitId, subUnitId: h.subUnitId, ranges: [ d, { ...d, startColumn: d.endColumn + 1, endColumn: Number.MAX_SAFE_INTEGER } ] } : { unitId: h.unitId, subUnitId: h.subUnitId, ranges: [] }; } case $.ReorderRangeCommandId: { const c = e, { range: d, order: h } = c.params, m = []; for (let f = d.startRow; f <= d.endRow; f++) f in h && m.push({ startRow: f, endRow: f, startColumn: d.startColumn, endColumn: d.endColumn }); const g = N(t); return { unitId: g.unitId, subUnitId: g.subUnitId, ranges: m }; } } } var Ic = Object.defineProperty, vc = Object.getOwnPropertyDescriptor, Mc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? vc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Ic(e, t, s), s; }, dn = (n, e) => (t, o) => e(t, o, n); const _c = rt("MERGE_REDO"), bc = rt("MERGE_UNDO"), rs = Math.floor(Number.MAX_SAFE_INTEGER / 10); class yc extends ae { constructor(e, t, o, s, r = !1) { super(), this._unitId = e, this._subUnitId = t, this._range = o, this._callback = s, this._skipIntersects = r; } onMutation(e) { var s, r; if (((s = e.params) == null ? void 0 : s.unitId) !== this._unitId) return; if (e.id === dt.id) { const i = e.params; if (i.from.subUnitId !== this._subUnitId || i.to.subUnitId !== this._subUnitId) return; } else if (((r = e.params) == null ? void 0 : r.subUnitId) !== this._subUnitId) return; if (!this._range) return; if (this._skipIntersects) { if (e.id === Ut.id) return; const i = wc(e); if (i != null && i.some((a) => k.intersects(a, this._range))) return; } const t = Sc(this._range, e); if (t && k.equals(t, this._range)) return !1; const o = this._range; this._range = t, this._callback(o, t); } } let _t = class extends ae { constructor(e, t, o, s) { super(); R(this, "interceptor", new mo({ MERGE_REDO: _c, MERGE_UNDO: bc })); R(this, "_watchRanges", /* @__PURE__ */ new Set()); R(this, "_refRangeManagerMap", /* @__PURE__ */ new Map()); R(this, "_serializer", Ec()); // eslint-disable-next-line max-lines-per-function R(this, "_onRefRangeChange", () => { this._sheetInterceptorService.interceptCommand({ // eslint-disable-next-line max-lines-per-function getMutations: (e) => { const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET).getActiveSheet(), o = is(this._univerInstanceService), s = as(this._univerInstanceService); if (!t || !o || !s) return { redos: [], undos: [], preRedos: [], preUndos: [] }; const a = ((() => { switch (e.id) { case $.MoveColsCommandId: { const h = e.params, m = Math.min(h.fromRange.startColumn, h.toRange.startColumn); return this._checkRange( [{ ...h.fromRange, startColumn: m, endColumn: t.getColumnCount() - 1 }], o, s ); } case $.MoveRowsCommandId: { const h = e.params, m = Math.min(h.fromRange.startRow, h.toRange.startRow); return this._checkRange( [{ ...h.fromRange, startRow: m, endRow: t.getRowCount() - 1 }], o, s ); } case $.MoveRangeCommandId: { const h = e; return this._checkRange( [h.params.fromRange, h.params.toRange], o, s ); } case $.InsertRowCommandId: { const g = { startRow: e.params.range.startRow, endRow: t.getRowCount() - 1, startColumn: 0, endColumn: t.getColumnCount() - 1, rangeType: H.ROW }; return this._checkRange([g], o, s); } case $.InsertColCommandId: { const m = e.params.range.startColumn, g = { startRow: 0, endRow: t.getRowCount() - 1, startColumn: m, endColumn: t.getColumnCount() - 1, rangeType: H.COLUMN }; return this._checkRange([g], o, s); } case $.RemoveRowCommandId: { const g = { startRow: e.params.range.startRow, endRow: t.getRowCount() - 1, startColumn: 0, endColumn: t.getColumnCount() - 1, rangeType: H.ROW }; return this._checkRange([g], o, s); } case $.RemoveColCommandId: { const m = e.params.range.startColumn, g = { startRow: 0, endRow: t.getRowCount() - 1, startColumn: m, endColumn: t.getColumnCount() - 1, rangeType: H.COLUMN }; return this._checkRange([g], o, s); } case $.DeleteRangeMoveUpCommandId: case $.InsertRangeMoveDownCommandId: { const m = e.params.range || us(this._selectionManagerService)[0], g = { startRow: m.startRow, startColumn: m.startColumn, endColumn: m.endColumn, endRow: rs }; return this._checkRange([g], o, s); } case $.DeleteRangeMoveLeftCommandId: case $.InsertRangeMoveRightCommandId: { const m = e.params.range || us(this._selectionManagerService)[0], g = { startRow: m.startRow, startColumn: m.startColumn, endColumn: rs, endRow: m.endRow }; return this._checkRange([g], o, s); } case $.ReorderRangeCommandId: { const h = e, { range: m, order: g } = h.params, f = []; for (let p = m.startRow; p <= m.endRow; p++) p in g && f.push({ startRow: p, endRow: p, startColumn: m.startColumn, endColumn: m.endColumn }); return this._checkRange(f, o, s); } } })() || []).reduce( (h, m) => { const g = m(e); return h.push(g), h; }, [] ).reduce( (h, m) => { var g, f; return h.redos.push(...m.redos), h.undos.push(...m.undos), h.preRedos.push(...(g = m.preRedos) != null ? g : []), h.preUndos.push(...(f = m.preUndos) != null ? f : []), h; }, { redos: [], undos: [], preUndos: [], preRedos: [] } ), u = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)( a.preRedos, null ) || [], l = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)( a.redos, null ) || [], c = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)( a.preUndos, null ) || [], d = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)( a.undos, null ) || []; return { redos: l, undos: d, preRedos: u, preUndos: c }; } }); }); R(this, "_checkRange", (e, t, o) => { const s = ls(t, o), r = this._refRangeManagerMap.get(s); if (r) { const i = /* @__PURE__ */ new Set(); return [...r.keys()].forEach((u) => { const l = r.get(u), c = this._serializer.deserialize(u), d = { ...c, startRow: +c.startRow, endRow: +c.endRow, startColumn: +c.startColumn, endColumn: +c.endColumn, rangeType: c.rangeType && +c.rangeType }; e.some((h) => k.intersects(h, d)) && l && l.forEach((h) => { i.add(h); }); }), [...i]; } return []; }); /** * Listens to an area and triggers a fall back when movement occurs * @param {IRange} range the area that needs to be monitored * @param {RefRangCallback} callback the callback function that is executed when the range changes * @param {string} [_unitId] * @param {string} [_subUnitId] * @memberof RefRangeService */ R(this, "registerRefRange", (e, t, o, s) => { const r = o || is(this._univerInstanceService), i = s || as(this._univerInstanceService); if (!r || !i) return We(() => { }); const a = ls(r, i), u = this._serializer.serialize(e); let l = this._refRangeManagerMap.get(a); l || (l = /* @__PURE__ */ new Map(), this._refRangeManagerMap.set(a, l)); const c = l.get(u); return c ? c.add(t) : l.set(u, /* @__PURE__ */ new Set([t])), We(() => { const d = l.get(u); d && (d.delete(t), d.size || (l.delete(u), l.size || this._refRangeManagerMap.delete(a))); }); }); this._commandService = e, this._sheetInterceptorService = t, this._univerInstanceService = o, this._selectionManagerService = s, this._onRefRangeChange(), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_REDO, { priority: -1, handler: (r) => r }), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_UNDO, { priority: -1, handler: (r) => r }); } watchRange(e, t, o, s, r) { let i; this._watchRanges.size === 0 && (i = this._commandService.onCommandExecuted((c) => { if (c.type !== v.MUTATION) return !1; for (const d of this._watchRanges) d.onMutation(c); })); const a = new yc(e, t, o, s, r); this._watchRanges.add(a); const u = We(() => { this._watchRanges.delete(a), this._watchRanges.size === 0 && (i == null || i.dispose(), i = null); }), l = this.disposeWithMe(u); return We(() => { l.dispose(), u.dispose(); }); } }; _t = Mc([ dn(0, E), dn(1, L(V)), dn(2, L(M)), dn(3, L(F)) ], _t); function is(n) { return n.getCurrentUnitForType(B.UNIVER_SHEET).getUnitId(); } function as(n) { var e; return (e = n.getCurrentUnitForType(B.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : e.getSheetId(); } function us(n) { var e; return ((e = n.getCurrentSelections()) == null ? void 0 : e.map((t) => t.range)) || []; } function ls(n, e) { return `${n}_${e}`; } function Ec() { const n = ["startRow", "startColumn", "endRow", "endColumn", "rangeType"], e = "_"; return { deserialize: (t) => { const o = n.reduce( (r, i, a) => (r[String(a)] = i, r), {} ); return t.split(e).reduce( (r, i, a) => { const u = String(a); return i && o[u] && (r[o[u]] = i), r; }, {} ); }, serialize: (t) => n.reduce((o, s, r) => { const i = t[s]; return i !== void 0 ? `${o}${r > 0 ? e : ""}${i}` : `${o}`; }, "") }; } var Uc = Object.defineProperty, Pc = Object.getOwnPropertyDescriptor, Tc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Pc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Uc(e, t, s), s; }, Rt = (n, e) => (t, o) => e(t, o, n); const kc = [je.id, qe.id, De.id, Be.id], Nc = [ot.id, st.id]; function Zr(n, e) { let t = n; if (e !== void 0) { const o = []; for (let s = 0; s < t.length; s++) { const { startRow: r, endRow: i, startColumn: a, endColumn: u } = t[s]; if (e === ge.ROWS) for (let l = r; l <= i; l++) { const c = { startRow: l, endRow: l, startColumn: a, endColumn: u }; o.push(c); } else if (e === ge.COLUMNS) for (let l = a; l <= u; l++) { const c = { startRow: r, endRow: i, startColumn: l, endColumn: l }; o.push(c); } } t = o; } return t; } const Oc = rt("mergeCellPermissionCheck"); let Tn = class extends ae { constructor(e, t, o, s, r, i) { super(); R(this, "disposableCollection", new jt()); R(this, "interceptor", new mo({ MERGE_CELL_INTERCEPTOR_CHECK: Oc })); this._commandService = e, this._refRangeService = t, this._univerInstanceService = o, this._injector = s, this._sheetInterceptorService = r, this._selectionManagerService = i, this._onRefRangeChange(), this._initCommandInterceptor(), this._commandExecutedListener(); } _initCommandInterceptor() { const e = this; this._sheetInterceptorService.interceptCommand({ getMutations(t) { var o; switch (t.id) { case po.id: case So.id: { const s = e._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET), r = s.getUnitId(), i = s == null ? void 0 : s.getActiveSheet(); if (!i) return { redos: [], undos: [] }; const a = i.getSheetId(), u = i.getConfig().mergeData, l = (o = e._selectionManagerService.getCurrentSelections()) == null ? void 0 : o.map((c) => c.range); if (l && l.length > 0 && l.some( (d) => u.some((h) => k.intersects(h, d)) )) { const d = { unitId: r, subUnitId: a, ranges: l }, h = Se(e._injector, d), m = [ { id: oe.id, params: d } ], g = [ { id: ne.id, params: h } ]; return { redos: m, undos: g }; } } } return { redos: [], undos: [] }; } }), this._sheetInterceptorService.interceptRanges({ getMutations: ({ unitId: t, subUnitId: o, ranges: s }) => { const r = [], i = [], a = { redos: r, undos: i }; if (!s || !s.length) return a; const u = N(this._univerInstanceService, { unitId: t, subUnitId: o }); if (!u) return a; const { worksheet: l } = u, d = l.getMergeData().filter((h) => s.some((m) => k.intersects(h, m))); return d.length ? (r.push({ id: oe.id, params: { unitId: t, subUnitId: o, ranges: d } }), i.push({ id: ne.id, params: { unitId: t, subUnitId: o, ranges: d } }), { undos: i, redos: r }) : a; } }); } refRangeHandle(e, t, o) { switch (e.id) { case $.MoveColsCommandId: { const s = e.params; return this._handleMoveColsCommand(s, t, o); } case $.MoveRowsCommandId: { const s = e.params; return this._handleMoveRowsCommand(s, t, o); } case mt.id: { const s = e.params, r = s.unitId || t, i = s.subUnitId || o; return this._handleInsertRowCommand(s, r, i); } case gt.id: { const s = e.params, r = s.unitId || t, i = s.subUnitId || o; return this._handleInsertColCommand(s, r, i); } case zn.id: { const s = e.params; return this._handleRemoveColCommand(s, t, o); } case Gn.id: { const s = e.params; return this._handleRemoveRowCommand(s, t, o); } case pt.id: { const s = e.params; return this._handleMoveRangeCommand(s, t, o); } case Bn.id: { const s = e.params; return this._handleInsertRangeMoveRightCommand(s, t, o); } case sn.id: { const s = e.params; return this._handleInsertRangeMoveDownCommand(s, t, o); } case Tt.id: { const s = e.params; return this._handleDeleteRangeMoveUpCommand(s, t, o); } case Pt.id: { const s = e.params; return this._handleDeleteRangeMoveLeftCommand(s, t, o); } } return { redos: [], undos: [] }; } _onRefRangeChange() { const e = (t, o) => { const s = this._univerInstanceService.getUniverSheetInstance(t); if (!s) return; const r = s == null ? void 0 : s.getSheetBySheetId(o); if (!r) return; this.disposableCollection.dispose(); const i = r.getMergeData(), a = (u) => this.refRangeHandle(u, t, o); i.forEach((u) => { this.disposableCollection.add(this._refRangeService.registerRefRange(u, a, t, o)); }); }; this.disposeWithMe( this._commandService.onCommandExecuted((t) => { if (t.id === an.id) { const o = t.params, s = o.subUnitId, r = o.unitId; if (!s || !r) return; e(r, s); } if (t.id === ne.id) { const o = t.params, s = o.subUnitId, r = o.unitId; if (!s || !r) return; e(o.unitId, o.subUnitId); } }) ), this._univerInstanceService.getCurrentTypeOfUnit$(B.UNIVER_SHEET).pipe(zi((t) => !!t)).subscribe((t) => { const o = t.getActiveSheet(); o && e(t.getUnitId(), o.getSheetId()); }); } _handleMoveRowsCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startRow: c, endRow: d } = l; if (i.forEach((g) => { if (c <= g.startRow && d >= g.endRow) { a.ranges.push(g); const f = Jr({ id: $.MoveRowsCommandId, params: e }, g), p = Mt(f, g); p && u.ranges.push(p); } }), a.ranges.length === 0) return this._handleNull(); const h = Se(this._injector, a), m = Ue(this._injector, u); return { preRedos: [{ id: oe.id, params: a }], redos: [{ id: ne.id, params: u }], preUndos: [{ id: oe.id, params: m }], undos: [{ id: ne.id, params: h }] }; } _handleMoveColsCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startColumn: c, endColumn: d } = l; if (i.forEach((g) => { if (c <= g.startColumn && d >= g.endColumn) { a.ranges.push(g); const f = Yr({ id: $.MoveColsCommandId, params: e }, g), p = Mt(f, g); p && u.ranges.push(p); } }), a.ranges.length === 0) return this._handleNull(); const h = Se(this._injector, a), m = Ue(this._injector, u); return { preRedos: [{ id: oe.id, params: a }], redos: [{ id: ne.id, params: u }], preUndos: [{ id: oe.id, params: m }], undos: [{ id: ne.id, params: h }] }; } _handleMoveRangeCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = r.getMergeData(), a = i.filter((m) => k.intersects(m, e.fromRange)), u = i.filter((m) => k.intersects(m, e.toRange)), l = a.map((m) => k.getRelativeRange(m, e.fromRange)).map((m) => k.getPositionRange(m, e.toRange)), c = Zr(l).filter( (m) => !i.some((g) => k.equals(m, g)) ), d = [ { id: oe.id, params: { unitId: t, subUnitId: o, ranges: a } }, { id: oe.id, params: { unitId: t, subUnitId: o, ranges: u } }, { id: ne.id, params: { unitId: t, subUnitId: o, ranges: c } } ], h = [ { id: oe.id, params: { unitId: t, subUnitId: o, ranges: c } }, { id: ne.id, params: { unitId: t, subUnitId: o, ranges: u } }, { id: ne.id, params: { unitId: t, subUnitId: o, ranges: a } } ]; return { redos: d, undos: h }; } _handleInsertRowCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const { range: i } = e, { startRow: a, endRow: u } = i, l = O.deepClone(r.getMergeData()).reduce((C, S) => (a > S.startRow && a <= S.endRow && C.push(S), C), []); if (l.length === 0) return this._handleNull(); const c = O.deepClone(r.getMergeData()).reduce((C, S) => { if (a > S.startRow && a <= S.endRow) { const I = u - a + 1; S.endRow += I, this._checkIsMergeCell(S) && C.push(S); } return C; }, []), d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ), f = [ { id: oe.id, params: d }, { id: ne.id, params: m } ], p = [ { id: oe.id, params: g }, { id: ne.id, params: h } ]; return { redos: f, undos: p }; } _handleInsertColCommand(e, t, o) { const { range: s } = e, r = be(this._univerInstanceService, t); if (!r) return this._handleNull(); const i = ye(r, o); if (!i) return this._handleNull(); const { startColumn: a, endColumn: u } = s, l = O.deepClone(i.getMergeData()).reduce((C, S) => (a > S.startColumn && a <= S.endColumn && C.push(S), C), []); if (l.length === 0) return this._handleNull(); const c = O.deepClone(i.getMergeData()).reduce((C, S) => { if (a > S.startColumn && a <= S.endColumn) { const I = u - a + 1; S.endColumn += I, this._checkIsMergeCell(S) && C.push(S); } return C; }, []), d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ), f = [ { id: oe.id, params: d }, { id: ne.id, params: m } ], p = [ { id: oe.id, params: g }, { id: ne.id, params: h } ]; return { redos: f, undos: p }; } _handleRemoveColCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const { range: i } = e, { startColumn: a, endColumn: u } = i, l = O.deepClone(r.getMergeData()).reduce((I, w) => (k.intersects(i, w) && I.push(w), I), []); if (l.length === 0) return this._handleNull(); const c = O.deepClone(r.getMergeData()).reduce((I, w) => { if (k.intersects(i, w)) { if (a <= w.startColumn && u >= w.endColumn) return I; a >= w.startColumn && u <= w.endColumn ? w.endColumn -= u - a + 1 : a < w.startColumn ? (w.startColumn = a, w.endColumn -= u - a + 1) : u > w.endColumn && (w.endColumn = a - 1), this._checkIsMergeCell(w) && I.push(w); } return I; }, []), d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g }], S = [{ id: ne.id, params: h }]; return { preUndos: C, undos: S, preRedos: f, redos: p }; } _handleRemoveRowCommand(e, t, o) { const { range: s } = e, r = be(this._univerInstanceService, t); if (!r) return this._handleNull(); const i = ye(r, o); if (!i) return this._handleNull(); const { startRow: a, endRow: u } = s, l = O.deepClone(i.getMergeData()).reduce((I, w) => (k.intersects(s, w) && I.push(w), I), []); if (l.length === 0) return this._handleNull(); const c = O.deepClone(i.getMergeData()).reduce((I, w) => { if (k.intersects(s, w)) { if (a <= w.startRow && u >= w.endRow) return I; a >= w.startRow && u <= w.endRow ? w.endRow -= u - a + 1 : a < w.startRow ? (w.startRow = a, w.endRow -= u - a + 1) : u > w.endRow && (w.endRow = a - 1), this._checkIsMergeCell(w) && I.push(w); } return I; }, []), d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g }], S = [{ id: ne.id, params: h }]; return { preUndos: C, undos: S, preRedos: f, redos: p }; } _handleInsertRangeMoveRightCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = []; u.forEach((f) => { const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i; if (k.intersects( { startRow: p, startColumn: S, endRow: C, endColumn: a }, f ) && (l.push(f), k.contains( { startRow: p, startColumn: S, endRow: C, endColumn: a }, f ))) { const y = I - S + 1; c.push({ startRow: f.startRow, startColumn: f.startColumn + y, endRow: f.endRow, endColumn: f.endColumn + y }); } }); const d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ); return { preRedos: [ { id: oe.id, params: d } ], redos: [ { id: ne.id, params: m } ], preUndos: [ { id: oe.id, params: g } ], undos: [ { id: ne.id, params: h } ] }; } _handleInsertRangeMoveDownCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = []; u.forEach((I) => { const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i; if (k.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), k.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) { const P = x - w + 1; c.push({ startRow: I.startRow + P, startColumn: I.startColumn, endRow: I.endRow + P, endColumn: I.endColumn }); } }); const d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ), f = [ { id: oe.id, params: d } ], p = [ { id: ne.id, params: m } ], C = [ { id: oe.id, params: g } ], S = [ { id: ne.id, params: h } ]; return { redos: p, undos: S, preRedos: f, preUndos: C }; } _handleDeleteRangeMoveUpCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = []; u.forEach((I) => { const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i; if (k.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), k.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) { const P = x - w + 1, A = k.moveVertical(I, -P); c.push(A); } }); const d = { unitId: t, subUnitId: o, ranges: l }, h = Se( this._injector, d ), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue( this._injector, m ), f = [ { id: oe.id, params: d } ], p = [ { id: ne.id, params: m } ], C = [ { id: oe.id, params: g } ], S = [ { id: ne.id, params: h } ]; return { redos: p, undos: S, preRedos: f, preUndos: C }; } _handleDeleteRangeMoveLeftCommand(e, t, o) { const s = be(this._univerInstanceService, t); if (!s) return this._handleNull(); const r = ye(s, o); if (!r) return this._handleNull(); const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = []; u.forEach((f) => { const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i; if (k.intersects( { startRow: p, startColumn: S, endRow: C, endColumn: a }, f ) && (l.push(f), k.contains( { startRow: p, startColumn: S, endRow: C, endColumn: a }, f ))) { const y = I - S + 1; c.push({ startRow: f.startRow, startColumn: f.startColumn - y, endRow: f.endRow, endColumn: f.endColumn - y }); } }); const d = { unitId: t, subUnitId: o, ranges: l }, h = Se(this._injector, d), m = { unitId: t, subUnitId: o, ranges: c }, g = Ue(this._injector, m); return { preRedos: [ { id: oe.id, params: d } ], redos: [ { id: ne.id, params: m } ], undos: [ { id: ne.id, params: h } ], preUndos: [ { id: oe.id, params: g } ] }; } _checkIsMergeCell(e) { return !(e.startRow === e.endRow && e.startColumn === e.endColumn); } _handleNull() { return { redos: [], undos: [] }; } _commandExecutedListener() { this.disposeWithMe(this._commandService.onCommandExecuted((e) => { if (Nc.includes(e.id)) { if (!e.params) return; const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId); if (!t) return; const o = t.getSheetBySheetId(e.params.subUnitId); if (!o) return; const { sourceRange: s, targetRange: r } = e.params, i = s.startColumn === r.startColumn && s.endColumn === r.endColumn, a = i ? s.endRow - s.startRow + 1 : s.endColumn - s.startColumn + 1, u = i ? s.startRow : s.startColumn, l = i ? r.startRow : r.startColumn, c = o.getConfig().mergeData, d = []; c.forEach((f) => { let { startRow: p, endRow: C, startColumn: S, endColumn: I, rangeType: w } = f; k.intersects(f, s) || (i ? u < p && l > C ? (p -= a, C -= a) : u > C && l <= p && (p += a, C += a) : u < S && l > I ? (S -= a, I -= a) : u > I && l <= S && (S += a, I += a)), f.startRow === f.endRow && f.startColumn === f.endColumn || d.push({ startRow: p, endRow: C, startColumn: S, endColumn: I, rangeType: w }); }), o.setMergeData(d), this.disposableCollection.dispose(); const { unitId: h, subUnitId: m } = e.params, g = (f) => this.refRangeHandle(f, h, m); d.forEach((f) => { this.disposableCollection.add(this._refRangeService.registerRefRange(f, g, h, m)); }); } if (kc.includes(e.id)) { const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId); if (!t) return; const o = t.getSheetBySheetId(e.params.subUnitId); if (!o) return; const s = o.getConfig().mergeData, r = e.params; if (!r) return; const { range: i } = r, a = e.id.includes("row"), u = e.id.includes("insert"), l = a ? i.startRow : i.startColumn, c = a ? i.endRow : i.endColumn, d = c - l + 1, h = []; s.forEach((p) => { let { startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b } = p; u ? a ? l <= C && (C += d, S += d) : l <= I && (I += d, w += d) : a ? c < C && (C -= d, S -= d) : c < I && (I -= d, w -= d), p.startRow === p.endRow && p.startColumn === p.endColumn || h.push({ startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b }); }), o.setMergeData(h), this.disposableCollection.dispose(); const { unitId: m, subUnitId: g } = e.params, f = (p) => this.refRangeHandle(p, m, g); h.forEach((p) => { this.disposableCollection.add(this._refRangeService.registerRefRange(p, f, m, g)); }); } })); } }; Tn = Tc([ Rt(0, L(E)), Rt(1, L(_t)), Rt(2, L(M)), Rt(3, L(Ro)), Rt(4, L(V)), Rt(5, L(F)) ], Tn); function be(n, e) { return e ? n.getUniverSheetInstance(e) : n.getCurrentUnitForType(B.UNIVER_SHEET); } function ye(n, e) { return e ? n.getSheetBySheetId(e) : n.getActiveSheet(); } var Dc = Object.defineProperty, Ac = Object.getOwnPropertyDescriptor, xc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Ac(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Dc(e, t, s), s; }, $c = (n, e) => (t, o) => e(t, o, n); let kn = class extends ae { constructor(n) { super(), this._sheetInterceptorService = n, this._initialize(); } _initialize() { this._initInterceptorCellContent(); } _initInterceptorCellContent() { this.disposeWithMe( this._sheetInterceptorService.intercept(et.CELL_CONTENT, { priority: 11, effect: me.Value | me.Style, handler: (n, e, t) => { var s; const o = e.workbook.getStyles().getStyleByCell(n); return (s = o == null ? void 0 : o.n) != null && s.pattern ? t({ ...n }) : (n == null ? void 0 : n.t) === se.NUMBER && n.v !== void 0 && n.v !== null && go(n.v) ? t({ ...n, v: xi(Number(n.v)) }) : t({ ...n }); } }) ); } }; kn = xc([ $c(0, L(V)) ], kn); var Wc = Object.defineProperty, Lc = Object.getOwnPropertyDescriptor, Vc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Lc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Wc(e, t, s), s; }, $e = (n, e) => (t, o) => e(t, o, n); let Nn = class extends ae { constructor(e, t, o, s, r, i, a, u, l, c) { super(); R(this, "disposableCollection", new jt()); R(this, "_triggerPermissionUIEvent$", new Le()); R(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable()); this._commandService = e, this._univerInstanceService = t, this._permissionService = o, this._selectionManagerService = s, this._rangeProtectionRuleModel = r, this._worksheetProtectionRuleModel = i, this._localeService = a, this._lexerTreeBuilder = u, this._contextService = l, this._definedNamesService = c, this._initialize(); } blockExecuteWithoutPermission(e) { throw this._triggerPermissionUIEvent$.next(e), new wi("have no permission"); } _getPermissionCheck(e, t) { let o = !0, s = ""; switch (e) { case on.id: Is(t.value) && t.value.f ? (o = this._permissionCheckWithFormula(t), s = this._localeService.t("permission.dialog.formulaErr")) : o = this._permissionCheckBySetRangeValue({ workbookTypes: [Me], rangeTypes: [Pe], worksheetTypes: [wn, Te] }, t); break; case Co.id: o = this.permissionCheckWithRanges({ workbookTypes: [Me], rangeTypes: [Pe], worksheetTypes: [wn, Te] }), s = this._localeService.t("permission.dialog.editErr"); break; case Oo.id: case Mn.id: o = this.permissionCheckWithoutRange({ worksheetTypes: [$t] }), s = this._localeService.t("permission.dialog.setRowColStyleErr"); break; case $o.id: case Wo.id: case Lo.id: o = this.permissionCheckWithoutRange({ worksheetTypes: [Wt] }), s = this._localeService.t("permission.dialog.setRowColStyleErr"); break; case jn.id: case Fn.id: o = this._permissionCheckByMoveCommand(t), s = this._localeService.t("permission.dialog.moveRowColErr"); break; case pt.id: o = this._permissionCheckByMoveRangeCommand(t), s = this._localeService.t("permission.dialog.moveRangeErr"); break; case Wr.id: o = this._permissionCheckByWorksheetCommand([Me, _o]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder(); break; case Do.id: o = this._permissionCheckByWorksheetCommand([Me, bo]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder(); break; case Fr.id: { const { unitId: r, subUnitId: i } = t; o = this._permissionCheckByWorksheetCommand([Me, vo], r, i), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder(); } break; case Kn.id: o = this.permissionCheckWithRanges({ workbookTypes: [Me], rangeTypes: [Pe], worksheetTypes: [Te, $t] }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr"); break; case Jn.id: o = this.permissionCheckWithRanges({ workbookTypes: [Me], rangeTypes: [Pe], worksheetTypes: [Te, Wt] }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr"); break; case br.id: o = this.permissionCheckWithRanges({ workbookTypes: [Me], rangeTypes: [Pe], worksheetTypes: [Te, $t] }), s = this._localeService.t("permission.dialog.setRowColStyleErr"); break; case Tr.id: o = this.permissionCheckWithRanges({ workbookTypes: [Me], rangeTypes: [Pe], worksheetTypes: [Te, Wt] }), s = this._localeService.t("permission.dialog.setRowColStyleErr"); break; case Bn.id: o = this._permissionCheckWithInsertRangeMove("right"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr"); break; case sn.id: o = this._permissionCheckWithInsertRangeMove("bottom"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr"); break; case Pt.id: o = this._permissionCheckWithInsertRangeMove("left"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr"); break; case Tt.id: o = this._permissionCheckWithInsertRangeMove("top"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr"); break; } o || this.blockExecuteWithoutPermission(s); } _initialize() { this._commandExecutedListener(); } _commandExecutedListener() { this.disposeWithMe( this._commandService.beforeCommandExecuted((e) => { this._getPermissionCheck(e.id, e == null ? void 0 : e.params); }) ), this.disposeWithMe( this._commandService.onCommandExecuted((e) => { var t; if (e.id === _n.id) { const o = e.params, { unitId: s = (t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET)) == null ? void 0 : t.getUnitId(), subUnitId: r } = o; if (!s || !r) return; const i = this._worksheetProtectionRuleModel.getRule(s, r), a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r); i && this._worksheetProtectionRuleModel.ruleRefresh(i.permissionId), a.length && this._rangeProtectionRuleModel.ruleRefresh(r); } }) ); } _permissionCheckWithInsertRangeMove(e) { var l; const t = N(this._univerInstanceService); if (!t) return !1; const { worksheet: o, unitId: s, subUnitId: r } = t, i = O.deepClone((l = this._selectionManagerService.getCurrentLastSelection()) == null ? void 0 : l.range); return !(!i || (e === "top" || e === "bottom" ? i.endRow = o.getRowCount() - 1 : (e === "left" || e === "right") && (i.endColumn = o.getColumnCount() - 1), this._rangeProtectionRuleModel.getSubunitRuleList(s, r).map((c) => c.ranges).flat().some((c) => k.getIntersects(i, c)))); } _permissionCheckByWorksheetCommand(e, t, o) { var l, c; const s = N(this._univerInstanceService, { unitId: t, subUnitId: o }); if (!s) return !1; const { unitId: r, subUnitId: i } = s, a = this._worksheetProtectionRuleModel.getRule(r, i), u = this._rangeProtectionRuleModel.getSubunitRuleList(r, i).length > 0; return a || u ? (c = (l = this._permissionService.getPermissionPoint(new Mo(r).id)) == null ? void 0 : l.value) != null ? c : !1 : this._permissionService.composePermission(e.map((d) => new d(r).id)).every((d) => d.value); } permissionCheckWithoutRange(e) { var h, m, g, f; const t = N(this._univerInstanceService); if (!t) return !1; const { worksheet: o, unitId: s, subUnitId: r } = t, i = this._selectionManagerService.getCurrentLastSelection(); if (!i) return !0; const a = (m = (h = i == null ? void 0 : i.primary) == null ? void 0 : h.actualRow) != null ? m : 0, u = (f = (g = i == null ? void 0 : i.primary) == null ? void 0 : g.actualColumn) != null ? f : 0, { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e; return !(l && l.some((C) => { var w, b; const S = new C(s); return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : !1) === !1; }) === !0 || c && c.some((C) => { var w, b; const S = new C(s, r); return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : !1) === !1; }) === !0 || d && d.some((C) => { var y, x, T, U, P; const S = (x = (y = o.getCell(a, u)) == null ? void 0 : y.selectionProtection) == null ? void 0 : x[0]; if (!(S != null && S.ruleId)) return !1; const I = (T = this._rangeProtectionRuleModel.getRule(s, r, S.ruleId)) == null ? void 0 : T.permissionId; if (!I) return !1; const w = new C(s, r, I); return ((P = (U = this._permissionService.getPermissionPoint(w.id)) == null ? void 0 : U.value) != null ? P : !1) === !1; }) === !0); } permissionCheckWithRanges(e, t, o, s) { var m; const r = N(this._univerInstanceService); if (!r) return !1; const { workbook: i, worksheet: a } = r; o || (o = i.getUnitId()), s || (s = a.getSheetId()); const u = t != null ? t : (m = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : m.map((g) => g.range); if (!u) return !1; const { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e, h = []; return l && h.push(...l.map((g) => new g(o).id)), c && h.push(...c.map((g) => new g(o, s).id)), d && this._rangeProtectionRuleModel.getSubunitRuleList(o, s).forEach((g) => { u.some((p) => g.ranges.some((C) => k.intersects(C, p))) && h.push(...d.map((p) => new p(o, s, g.permissionId).id)); }), h.length ? this._permissionService.composePermission(h).every((g) => g.value) : !0; } _permissionCheckByMoveCommand(e) { const t = N(this._univerInstanceService); if (!t) return !1; const { worksheet: o, unitId: s, subUnitId: r } = t, i = e.toRange; i.endRow === o.getRowCount() - 1 ? i.endColumn = i.startColumn : i.endRow = i.startRow; const a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r).reduce((u, l) => [...u, ...l.ranges], []).filter((u) => k.intersects(u, i)); return a.length > 0 ? !1 : (a.forEach((u) => { var l, c; for (let d = u.startRow; d <= u.endRow; d++) for (let h = u.startColumn; h <= u.endColumn; h++) { const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0]; if ((m == null ? void 0 : m[_.Edit]) === !1) return !1; } }), !0); } _permissionCheckByMoveRangeCommand(e) { const t = N(this._univerInstanceService); if (!t) return !1; const { worksheet: o, unitId: s, subUnitId: r } = t, i = e.toRange, a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r).reduce((u, l) => [...u, ...l.ranges], []).filter((u) => k.intersects(u, i)); return a.length > 0 ? !1 : (a.forEach((u) => { var l, c; for (let d = u.startRow; d <= u.endRow; d++) for (let h = u.startColumn; h <= u.endColumn; h++) { const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0]; if ((m == null ? void 0 : m[_.Edit]) === !1) return !1; } }), !0); } _permissionCheckBySetRangeValue(e, t) { let o = []; t.range ? o = [t.range] : o = [new G(t.value).getDataRange()]; const { unitId: s, subUnitId: r } = t; return this.permissionCheckWithRanges(e, o, s, r); } _permissionCheckWithFormula(e) { var r, i, a, u, l; const t = e.value, o = e.range, s = t.f; if (s) { const c = s.substring(1), d = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET), h = (r = e.unitId) != null ? r : d.getUnitId(), m = this._definedNamesService.getValueByName(h, c); if (m) { let g = m.formulaOrRefString; g.startsWith(Wi.EQUALS) && (g = g.slice(1)); const f = g.split(","); for (let p = 0; p < f.length; p++) { const C = f[p], S = Li(C); if (S.sheetName) { const I = d.getSheetBySheetName(S.sheetName); if (!I) return !0; const { startRow: w, endRow: b, startColumn: y, endColumn: x } = S.range; for (let T = w; T <= b; T++) for (let U = y; U <= x; U++) { const P = (a = (i = I.getCell(T, U)) == null ? void 0 : i.selectionProtection) == null ? void 0 : a[0]; if ((P == null ? void 0 : P[_.View]) === !1) return !1; } } } return !0; } else { const g = this._lexerTreeBuilder.sequenceNodesBuilder(s); if (!g) return !0; for (let f = 0; f < g.length; f++) { const p = g[f]; if (typeof p == "string" || p.nodeType !== Vi.REFERENCE) continue; const { token: C } = p, S = Hi(C), I = S.unitId ? this._univerInstanceService.getUnit(S.unitId) : this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET); if (!I) return !0; let w = S.sheetName ? I.getSheetBySheetName(S.sheetName) : I.getActiveSheet(); const b = I.getUnitId(); if (S.sheetName) { if (w = I.getSheetBySheetName(S.sheetName), !w) return !0; const P = w == null ? void 0 : w.getSheetId(); if (!this._permissionService.getPermissionPoint(new Hn(b, P).id)) return !1; } if (!w) return !0; const { startRow: y, endRow: x, startColumn: T, endColumn: U } = S.range; for (let P = y; P <= x; P++) for (let A = T; A <= U; A++) { const j = (l = (u = w.getCell(P, A)) == null ? void 0 : u.selectionProtection) == null ? void 0 : l[0]; if ((j == null ? void 0 : j[_.View]) === !1) return !1; } } return !0; } } if (o) { const c = N(this._univerInstanceService); if (!c) return !1; const d = e.unitId || c.unitId, h = e.subUnitId || c.subUnitId, g = this._rangeProtectionRuleModel.getSubunitRuleList(d, h).filter((p) => p.ranges.some((C) => k.intersects(C, o))).map((p) => new Pe(d, h, p.permissionId).id); if (!this._permissionService.composePermission(g).every((p) => p.value)) return !1; } return !0; } }; Nn = Vc([ $e(0, E), $e(1, M), $e(2, Fe), $e(3, L(F)), $e(4, L(de)), $e(5, L(Ye)), $e(6, L(Ke)), $e(7, L($i)), $e(8, Ss), $e(9, Ps) ], Nn); var Hc = Object.defineProperty, Bc = Object.getOwnPropertyDescriptor, Fc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Bc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Hc(e, t, s), s; }, no = (n, e) => (t, o) => e(t, o, n); let ht = class extends ae { constructor(e, t, o) { super(); R(this, "_cellRuleCache", /* @__PURE__ */ new Map()); R(this, "_permissionIdCache", /* @__PURE__ */ new Map()); R(this, "_cellInfoCache", /* @__PURE__ */ new Map()); // {unitId:{subUnitId:{[row/col]:{permissionId1:{edit:true},permissionId2:{edit:true},permissionId3:{edit:false}}}}} R(this, "_rowInfoCache", /* @__PURE__ */ new Map()); R(this, "_colInfoCache", /* @__PURE__ */ new Map()); this._ruleModel = e, this._permissionService = t, this._univerInstanceService = o, this._initUpdateCellRuleCache(), this._initUpdateCellInfoCache(), this._initUpdateRowColInfoCache(), this._initCache(); } _initCache() { this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => { e.getSheets().forEach((t) => { const o = e.getUnitId(), s = t.getSheetId(); this.reBuildCache(o, s); }); }); } _initUpdateCellInfoCache() { this._permissionService.permissionPointUpdate$.pipe( Ho((e) => e.type === D.SelectRange), ao((e) => e) ).subscribe((e) => { const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s); if (!r) return; const i = this._ruleModel.getRule(o, t, r); if (!i) return; const a = this._ensureCellInfoMap(o, t); i.ranges.forEach((u) => { const { startRow: l, endRow: c, startColumn: d, endColumn: h } = u; for (let m = l; m <= c; m++) for (let g = d; g <= h; g++) a.delete(`${m}-${g}`); }); }), this._ruleModel.ruleChange$.subscribe((e) => { var r; const { unitId: t, subUnitId: o } = e, s = this._ensureCellInfoMap(t, o); e.rule.ranges.forEach((i) => { K.foreach(i, (a, u) => { s.delete(`${a}-${u}`); }); }), e.type === "set" && ((r = e.oldRule) == null || r.ranges.forEach((i) => { K.foreach(i, (a, u) => { this._cellInfoCache.delete(`${a}-${u}`); }); })); }); } _initUpdateCellRuleCache() { this._ruleModel.ruleChange$.subscribe((e) => { const { type: t } = e; t === "add" ? this._addCellRuleCache(e) : t === "delete" ? this._deleteCellRuleCache(e) : (this._deleteCellRuleCache({ ...e, rule: e.oldRule }), this._addCellRuleCache(e)); }); } _ensureRuleMap(e, t) { let o = this._cellRuleCache.get(e); o || (o = /* @__PURE__ */ new Map(), this._cellRuleCache.set(e, o)); let s = o.get(t); return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s; } _ensureCellInfoMap(e, t) { let o = this._cellInfoCache.get(e); o || (o = /* @__PURE__ */ new Map(), this._cellInfoCache.set(e, o)); let s = o.get(t); return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s; } _ensureRowColInfoMap(e, t, o) { let s = o === "row" ? this._rowInfoCache.get(e) : this._colInfoCache.get(e); s || (s = /* @__PURE__ */ new Map(), o === "row" ? this._rowInfoCache.set(e, s) : this._colInfoCache.set(e, s)); let r = s.get(t); return r || (r = /* @__PURE__ */ new Map(), s.set(t, r)), r; } _addCellRuleCache(e) { const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t); s.ranges.forEach((i) => { const { startRow: a, endRow: u, startColumn: l, endColumn: c } = i; for (let d = a; d <= u; d++) for (let h = l; h <= c; h++) r.set(`${d}-${h}`, s.id); }), this._permissionIdCache.set(s.permissionId, s.id); } _deleteCellRuleCache(e) { const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t), i = this._ensureCellInfoMap(o, t); s.ranges.forEach((a) => { const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a; for (let h = u; h <= l; h++) for (let m = c; m <= d; m++) r.delete(`${h}-${m}`), i.delete(`${h}-${m}`); }), this._permissionIdCache.delete(s.permissionId); } _getSelectionActions(e, t, o) { var l, c, d, h, m, g, f, p, C, S, I, w; const s = (d = (c = this._permissionService.getPermissionPoint((l = new Pe(e, t, o.permissionId)) == null ? void 0 : l.id)) == null ? void 0 : c.value) != null ? d : !0, r = (g = (m = this._permissionService.getPermissionPoint((h = new Io(e, t, o.permissionId)) == null ? void 0 : h.id)) == null ? void 0 : m.value) != null ? g : !0, i = (C = (p = this._permissionService.getPermissionPoint((f = new Vr(e, t, o.permissionId)) == null ? void 0 : f.id)) == null ? void 0 : p.value) != null ? C : !1, a = (w = (I = this._permissionService.getPermissionPoint((S = new Lr(e, t, o.permissionId)) == null ? void 0 : S.id)) == null ? void 0 : I.value) != null ? w : !1; return { [_.Edit]: s, [_.View]: r, [_.ManageCollaborator]: i, [_.Delete]: a }; } reBuildCache(e, t) { const o = this._ensureRuleMap(e, t), s = this._ensureCellInfoMap(e, t); o.clear(), s.clear(); const r = this._ensureRowColInfoMap(e, t, "row"), i = this._ensureRowColInfoMap(e, t, "col"); r.clear(), i.clear(), this._ruleModel.getSubunitRuleList(e, t).forEach((a) => { const u = this._getSelectionActions(e, t, a), l = { ...u, ruleId: a.id, ranges: a.ranges }; a.ranges.forEach((c) => { const { startRow: d, endRow: h, startColumn: m, endColumn: g } = c; for (let f = d; f <= h; f++) { const p = r.get(`${f}`); p ? p.set(a.id, u) : r.set(`${f}`, /* @__PURE__ */ new Map([[a.id, u]])); for (let C = m; C <= g; C++) { o.set(`${f}-${C}`, a.id), s.set(`${f}-${C}`, l); const S = i.get(`${C}`); S ? S.set(a.id, u) : i.set(`${C}`, /* @__PURE__ */ new Map([[a.id, u]])); } } }), this._permissionIdCache.set(a.permissionId, a.id); }); } getRowPermissionInfo(e, t, o, s) { var a; const r = (a = this._rowInfoCache.get(e)) == null ? void 0 : a.get(t); if (!r) return !0; const i = r.get(`${o}`); return i ? s.every((u) => { for (const l of i.values()) if (l[u] === !1) return !1; return !0; }) : !0; } getColPermissionInfo(e, t, o, s) { var a; const r = (a = this._colInfoCache.get(e)) == null ? void 0 : a.get(t); if (!r) return !0; const i = r.get(`${o}`); return i ? s.every((u) => { for (const l of i.values()) if (l[u] === !1) return !1; return !0; }) : !0; } _initUpdateRowColInfoCache() { this._permissionService.permissionPointUpdate$.pipe( Ho((e) => e.type === D.SelectRange), ao((e) => e) ).subscribe({ next: (e) => { const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s); if (!r) return; const i = this._ruleModel.getRule(o, t, r); if (!i) return; const a = this._ensureRowColInfoMap(o, t, "row"), u = this._ensureRowColInfoMap(o, t, "col"), l = this._getSelectionActions(o, t, i); i.ranges.forEach((c) => { const { startRow: d, endRow: h, startColumn: m, endColumn: g } = c; for (let f = d; f <= h; f++) { const p = a.get(`${f}`); p ? p.set(r, l) : a.set(`${f}`, /* @__PURE__ */ new Map([[r, l]])); for (let C = m; C <= g; C++) { const S = u.get(`${C}`); S ? S.set(r, l) : u.set(`${C}`, /* @__PURE__ */ new Map([[r, l]])); } } }); } }), this._ruleModel.ruleChange$.subscribe((e) => { if (e.type === "delete") { const { unitId: t, subUnitId: o, rule: s } = e, r = this._ensureRowColInfoMap(t, o, "row"), i = this._ensureRowColInfoMap(t, o, "col"); s.ranges.forEach((a) => { const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a; for (let h = u; h <= l; h++) { const m = r.get(`${h}`); m == null || m.delete(s.id); for (let g = c; g <= d; g++) { const f = i.get(`${g}`); f == null || f.delete(s.id); } } }); } }); } getCellInfo(e, t, o, s) { var l, c; const r = this._ensureCellInfoMap(e, t), i = r.get(`${o}-${s}`); if (i) return i; const a = (c = (l = this._cellRuleCache.get(e)) == null ? void 0 : l.get(t)) == null ? void 0 : c.get(`${o}-${s}`); if (!a) return; const u = this._ruleModel.getRule(e, t, a); if (u) { const h = { ...this._getSelectionActions(e, t, u), ruleId: a, ranges: u.ranges }; return r.set(`${o}-${s}`, h), h; } } deleteUnit(e) { this._cellRuleCache.delete(e), this._cellInfoCache.delete(e), this._rowInfoCache.delete(e), this._colInfoCache.delete(e); const t = this._univerInstanceService.getUnit(e); t == null || t.getSheets().forEach((o) => { const s = o.getSheetId(); this._ruleModel.getSubunitRuleList(e, s).forEach((r) => { this._permissionIdCache.delete(r.permissionId); }); }); } }; ht = Fc([ no(0, L(de)), no(1, L(Fe)), no(2, L(M)) ], ht); var jc = Object.defineProperty, Gc = Object.getOwnPropertyDescriptor, zc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Gc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && jc(e, t, s), s; }, Ee = (n, e) => (t, o) => e(t, o, n); let On = class extends ae { constructor(n, e, t, o, s, r, i, a, u, l, c) { super(), this._univerInstanceService = n, this._permissionService = e, this._authzIoService = t, this._rangeProtectionRuleModel = o, this._worksheetProtectionRuleModel = s, this._userManagerService = r, this._worksheetProtectionPointRuleModel = i, this._sheetInterceptorService = a, this._undoRedoService = u, this._commandService = l, this._rangeProtectionCache = c, this._initRangePermissionFromSnapshot(), this._initRangePermissionChange(), this._initWorksheetPermissionFromSnapshot(), this._initWorksheetPermissionChange(), this._initWorksheetPermissionPointsChange(), this._initWorkbookPermissionFromSnapshot(), this._initUserChange(), this._refreshPermissionByCollaCreate(); } async _initRangePermissionFromSnapshot() { const n = async (e) => { const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map(); if (s.forEach((i) => { const a = i.getSheetId(); this._rangeProtectionRuleModel.getSubunitRuleList(o, a).forEach((u) => { r.set(u.permissionId, u), t.push({ objectID: u.permissionId, unitID: o, objectType: D.SelectRange, actions: it }); }); }), !t.length) { this._rangeProtectionRuleModel.changeRuleInitState(!0); return; } this._authzIoService.batchAllowed(t).then((i) => { i.forEach((a) => { const u = r.get(a.objectID); u && Ie().forEach((l) => { const c = new l(o, u.subUnitId, a.objectID), d = c.subType, h = a.actions.find((m) => m.action === d); (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed); }); }), this._rangeProtectionRuleModel.changeRuleInitState(!0); }); }; await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((e) => n(e))), this._rangeProtectionRuleModel.changeRuleInitState(!0); } _initRangePermissionChange() { this.disposeWithMe( this._rangeProtectionRuleModel.ruleChange$.subscribe((n) => { n.type !== "delete" ? this._authzIoService.allowed({ objectID: n.rule.permissionId, unitID: n.unitId, objectType: D.SelectRange, actions: it }).then((e) => { Ie().forEach((t) => { if (n.type === "set") { const { rule: a, oldRule: u } = n; if (a.permissionId === (u == null ? void 0 : u.permissionId)) return; } const o = n.rule, s = new t(o.unitId, o.subUnitId, o.permissionId), r = s.subType, i = e.find((a) => a.action === r); i && this._permissionService.updatePermissionPoint(s.id, i.allowed); }), this._rangeProtectionRuleModel.ruleRefresh(n.rule.permissionId); }) : this._rangeProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId), [...ke()].forEach((t) => { const o = new t(n.unitId, n.subUnitId); this._permissionService.updatePermissionPoint(o.id, o.value); })); }) ); } async initWorkbookPermissionChange(n) { var t; const e = n || ((t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET)) == null ? void 0 : t.getUnitId()); e && this._authzIoService.allowed({ objectID: e, objectType: D.Workbook, unitID: e, actions: fl }).then((o) => { en().forEach((s) => { const r = new s(e), i = r.subType, a = o.find((u) => u.action === i); a && this._permissionService.updatePermissionPoint(r.id, a.allowed); }); }); } async _initWorkbookPermissionFromSnapshot() { await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((n) => this.initWorkbookPermissionChange(n.getUnitId()))); } _initWorksheetPermissionChange() { this.disposeWithMe( this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => { n.type !== "delete" ? this._authzIoService.allowed({ objectID: n.rule.permissionId, unitID: n.unitId, objectType: D.Worksheet, actions: it }).then((e) => { we().forEach((t) => { const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s); r && this._permissionService.updatePermissionPoint(o.id, r.allowed); }), this._worksheetProtectionRuleModel.ruleRefresh(n.rule.permissionId); }) : ([...we(), ...ke()].forEach((e) => { const t = new e(n.unitId, n.subUnitId); this._permissionService.updatePermissionPoint(t.id, !0); }), this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId)); }) ); } _initWorksheetPermissionPointsChange() { this.disposeWithMe( this._worksheetProtectionPointRuleModel.pointChange$.subscribe((n) => { this._authzIoService.allowed({ objectID: n.permissionId, unitID: n.unitId, objectType: D.Worksheet, actions: eo }).then((e) => { ke().forEach((t) => { const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s); r && this._permissionService.updatePermissionPoint(o.id, r.allowed); }); }); }) ); } async _initWorksheetPermissionFromSnapshot() { const n = async (e) => { const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map(); if (s.forEach((i) => { const a = i.getSheetId(), u = this._worksheetProtectionRuleModel.getRule(o, a); u && (r.set(u.permissionId, u), t.push({ objectID: u.permissionId, unitID: o, objectType: D.Worksheet, actions: it })); const l = this._worksheetProtectionPointRuleModel.getRule(o, a); l && (r.set(l.permissionId, l), t.push({ objectID: l.permissionId, unitID: o, objectType: D.Worksheet, actions: eo })); }), !t.length) { this._worksheetProtectionRuleModel.changeRuleInitState(!0); return; } this._authzIoService.batchAllowed(t).then((i) => { i.forEach((a) => { const u = r.get(a.objectID); u && [...we(), ...ke()].forEach((l) => { const c = new l(o, u.subUnitId), d = c.subType, h = a.actions.find((m) => m.action === d); (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed); }); }), this._worksheetProtectionRuleModel.changeRuleInitState(!0); }); }; await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((e) => n(e))), this._worksheetProtectionRuleModel.changeRuleInitState(!0); } _initUserChange() { this.disposeWithMe( // When the user changes, the permission points are updated. The first modification needs to be filtered here because it is a Behavior type, but in fact the user information is ready when this controller is initialized. this._userManagerService.currentUser$.pipe(Ts(1)).subscribe(() => { const n = this._permissionService.getAllPermissionPoint(); this._permissionService.clearPermissionMap(), this._worksheetProtectionRuleModel.changeRuleInitState(!1), this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((t) => { const o = t.getUnitId(); en().forEach((s) => { let r = new s(o); n.has(r.id) && (r = n.get(r.id)), this._permissionService.addPermissionPoint(r); }), t.getSheets().forEach((s) => { const r = s.getSheetId(); [...we(), ...ke()].forEach((a) => { let u = new a(o, r); n.has(u.id) && (u = n.get(u.id)), this._permissionService.addPermissionPoint(u); }), this._rangeProtectionRuleModel.getSubunitRuleList(o, r).forEach((a) => { Ie().forEach((u) => { let l = new u(o, r, a.permissionId); n.has(l.id) && (l = n.get(l.id)), this._permissionService.addPermissionPoint(l); }); }); }), this._initWorkbookPermissionFromSnapshot(), this._initWorksheetPermissionFromSnapshot(), this._initRangePermissionFromSnapshot(); }); }) ); } refreshPermission(n, e) { const t = this._worksheetProtectionRuleModel.getTargetByPermissionId(n, e); let o = !1; if (t) { const [i, a] = t; this._authzIoService.allowed({ objectID: e, unitID: n, objectType: D.Worksheet, actions: it }).then((u) => { let l = ""; we().forEach((c) => { var g; const d = new c(n, a), h = d.subType, m = u.find((f) => f.action === h); m && (((g = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g.value) !== m.allowed && (o = !0), this._permissionService.updatePermissionPoint(d.id, m.allowed), l += `${m.action}_${m.allowed}`); }), this._worksheetProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n); }); } const s = this._worksheetProtectionPointRuleModel.getTargetByPermissionId(n, e); if (s) { const [i, a] = s; this._authzIoService.allowed({ objectID: e, unitID: n, objectType: D.Worksheet, actions: eo }).then((u) => { ke().forEach((l) => { var m; const c = new l(n, a), d = c.subType, h = u.find((g) => g.action === d); h && (((m = this._permissionService.getPermissionPoint(c.id)) == null ? void 0 : m.value) !== h.allowed && (o = !0), this._permissionService.updatePermissionPoint(c.id, h.allowed)); }), o && this._undoRedoService.clearUndoRedo(n); }); } const r = this._rangeProtectionRuleModel.getTargetByPermissionId(n, e); if (r) { const [i, a] = r; this._authzIoService.allowed({ objectID: e, unitID: n, objectType: D.SelectRange, actions: it }).then((u) => { let l = ""; Ie().forEach((c) => { var g; const d = new c(n, a, e), h = d.subType, m = u.find((f) => f.action === h); m && (((g = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g.value) !== m.allowed && (o = !0), this._permissionService.updatePermissionPoint(d.id, m.allowed), l += `${m.action}_${m.allowed}`); }), this._rangeProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n); }); } } _refreshPermissionByCollaCreate() { this.disposeWithMe( this._commandService.onCommandExecuted((n, e) => { if (e != null && e.fromCollab && (n.id === Ne.id || n.id === ct.id || n.id === Ao.id)) { const t = n.params; this._undoRedoService.clearUndoRedo(t.unitId); } }) ); } }; On = zc([ Ee(0, M), Ee(1, Fe), Ee(2, vi), Ee(3, L(de)), Ee(4, L(Ye)), Ee(5, L(Ii)), Ee(6, L(un)), Ee(7, L(V)), Ee(8, L(W)), Ee(9, L(E)), Ee(10, L(ht)) ], On); var Kc = Object.defineProperty, Jc = Object.getOwnPropertyDescriptor, Yc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? Jc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Kc(e, t, s), s; }, hn = (n, e) => (t, o) => e(t, o, n); let Dn = class extends ae { constructor(n, e, t, o) { super(), this._permissionService = n, this._worksheetProtectionRuleModel = e, this._sheetInterceptorService = t, this._rangeProtectionCache = o, this._initViewModelByRangeInterceptor(), this._initViewModelBySheetInterceptor(); } _initViewModelByRangeInterceptor() { this.disposeWithMe(this._sheetInterceptorService.intercept( et.CELL_CONTENT, { // permissions are placed at a high level to prioritize whether to filter subsequent renderings. priority: 999, effect: me.Value | me.Style, handler: (n = {}, e, t) => { const { unitId: o, subUnitId: s, row: r, col: i } = e, a = this._rangeProtectionCache.getCellInfo(o, s, r, i); if (a) { const u = a[_.View] === !1, l = { ...n, selectionProtection: [a] }; return u ? (delete l.s, delete l.v, delete l.p, l) : t(l); } return t(n); } } )); } _initViewModelBySheetInterceptor() { this.disposeWithMe(this._sheetInterceptorService.intercept( et.CELL_CONTENT, { // permissions are placed at a high level to prioritize whether to filter subsequent renderings. priority: 999, effect: me.Value | me.Style, handler: (n = {}, e, t) => { var i, a, u, l, c; const { unitId: o, subUnitId: s } = e, r = this._worksheetProtectionRuleModel.getRule(o, s); if (r != null && r.permissionId) { const d = [{ [_.View]: (a = (i = this._permissionService.getPermissionPoint(new Hn(o, s).id)) == null ? void 0 : i.value) != null ? a : !1, [_.Edit]: (l = (u = this._permissionService.getPermissionPoint(new Te(o, s).id)) == null ? void 0 : u.value) != null ? l : !1 }], h = !((c = d[0]) != null && c[_.View]), m = { ...n, hasWorksheetRule: !0, selectionProtection: d }; return h ? (delete m.s, delete m.v, delete m.p, m) : t(m); } return t(n); } } )); } }; Dn = Yc([ hn(0, Fe), hn(1, L(Ye)), hn(2, L(V)), hn(3, L(ht)) ], Dn); var Xc = Object.defineProperty, qc = Object.getOwnPropertyDescriptor, Zc = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? qc(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Xc(e, t, s), s; }, cs = (n, e) => (t, o) => e(t, o, n); let tn = class { constructor(n, e) { R(this, "_cache", new Mi(1e4)); this._selectionProtectionRuleModel = n, this._permissionService = e, this._init(); } _init() { this._permissionService.permissionPointUpdate$.pipe( Fo((n) => n.type === D.SelectRange), Fo((n) => Ie().some((e) => n instanceof e)), Ki((n) => n) ).subscribe((n) => { const e = this._selectionProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId); for (const t of e) t.permissionId === n.permissionId && t.ranges.forEach((o) => { K.foreach(o, (s, r) => { const i = this._createKey(n.unitId, n.subUnitId, s, r); this._cache.delete(i); }); }); }), this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => { var e; n.rule.ranges.forEach((t) => { K.foreach(t, (o, s) => { const r = this._createKey(n.unitId, n.subUnitId, o, s); this._cache.delete(r); }); }), n.type === "set" && ((e = n.oldRule) == null || e.ranges.forEach((t) => { K.foreach(t, (o, s) => { const r = this._createKey(n.unitId, n.subUnitId, o, s); this._cache.delete(r); }); })); }); } _createKey(n, e, t, o) { return `${n}_${e}_${t}_${o}`; } getCellInfo(n, e, t, o) { const s = this._selectionProtectionRuleModel.getSubunitRuleList(n, e), r = []; if (!s || !s.length) return r; const i = this._createKey(n, e, t, o), a = this._cache.get(i); if (a) return a; const u = []; for (const l of s) if (l.ranges.some((c) => c.startRow <= t && c.endRow >= t && c.startColumn <= o && c.endColumn >= o)) { const c = Ie().reduce((d, h) => { var f; const m = new h(n, e, l.permissionId), g = this._permissionService.getPermissionPoint(m.id); return d[m.subType] = (f = g == null ? void 0 : g.value) != null ? f : m.value, d; }, {}); u.push({ ...c, ruleId: l.id, ranges: l.ranges }); } return this._cache.set(i, u), u; } clear() { this._cache.clear(); } }; tn = Zc([ cs(0, L(de)), cs(1, L(Fe)) ], tn); const ds = fo("univer.exclusive-range-service"); class Qc extends ae { constructor() { super(...arguments); /** * Exclusive range data structure is as follows: unitId -> sheetId -> feature -> range */ R(this, "_exclusiveRanges", /* @__PURE__ */ new Map()); R(this, "_exclusiveRangesChange$", new Le()); R(this, "exclusiveRangesChange$", this._exclusiveRangesChange$.asObservable()); } _ensureUnitMap(t) { return this._exclusiveRanges.has(t) || this._exclusiveRanges.set(t, /* @__PURE__ */ new Map()), this._exclusiveRanges.get(t); } _ensureSubunitMap(t, o) { const s = this._ensureUnitMap(t); return s.has(o) || s.set(o, /* @__PURE__ */ new Map()), s.get(o); } _ensureFeature(t, o, s) { const r = this._ensureSubunitMap(t, o); return r.has(s) || r.set(s, []), r.get(s); } addExclusiveRange(t, o, s, r) { const i = this._ensureFeature(t, o, s); i.push(...r), this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: i.map((a) => a.range) }); } getExclusiveRanges(t, o, s) { var r, i; return (i = (r = this._exclusiveRanges.get(t)) == null ? void 0 : r.get(o)) == null ? void 0 : i.get(s); } clearExclusiveRanges(t, o, s) { const r = this.getExclusiveRanges(t, o, s); this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (r == null ? void 0 : r.map((i) => i.range)) || [] }), this._ensureFeature(t, o, s), this._exclusiveRanges.get(t).get(o).set(s, []); } clearExclusiveRangesByGroupId(t, o, s, r) { const i = this.getExclusiveRanges(t, o, s); this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (i == null ? void 0 : i.map((u) => u.range)) || [] }); const a = this.getExclusiveRanges(t, o, s); if (a) { const u = a.filter((l) => l.groupId !== r); this._exclusiveRanges.get(t).get(o).set(s, u); } } getInterestGroupId(t) { const o = []; return t.forEach((s) => { var l; const r = s.range, { unitId: i, sheetId: a } = r; if (!i || !a) return; const u = (l = this._exclusiveRanges.get(i)) == null ? void 0 : l.get(a); if (u) for (const c of u.keys()) { const d = u.get(c); if (d) { for (const h of d) if (k.intersects(r, h.range)) { o.push(c); break; } } } }), o; } } var ed = Object.defineProperty, td = Object.getOwnPropertyDescriptor, nd = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? td(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && ed(e, t, s), s; }, oo = (n, e) => (t, o) => e(t, o, n); let co = class extends ae { constructor(n, e, t) { super(), this._resourceManagerService = n, this._univerInstanceService = e, this._logService = t; } getValue(n, e, t, o) { const s = this._univerInstanceService.getUniverSheetInstance(n); if (!s) return; const r = s == null ? void 0 : s.getSheetBySheetId(e); if (!r) return; const i = s.getStyles(), a = r.getCellRaw(t, o); if (a != null && a.s) { const u = i.get(a.s); if (u != null && u.n) return u.n; } return null; } deleteValues(n, e, t) { const o = this._univerInstanceService.getUniverSheetInstance(n); if (!o) return; const s = o == null ? void 0 : o.getSheetBySheetId(e); if (!s) return; const r = o.getStyles(); t.forEach((i) => { K.foreach(i, (a, u) => { const l = s.getCellRaw(a, u); if (!l) return; const c = l == null ? void 0 : l.s, h = { ...c && r.get(c) || {} }; delete h.n; const m = r.setValue(h); l.s = m; }); }); } setValues(n, e, t) { const o = this._univerInstanceService.getUniverSheetInstance(n); if (!o) return; const s = o == null ? void 0 : o.getSheetBySheetId(e); if (!s) return; const r = o.getStyles(), i = s.getCellMatrix(); t.forEach((a) => { a.ranges.forEach((u) => { K.foreach(u, (l, c) => { const d = s.getCellRaw(l, c); if (d) { const m = { ...r.getStyleByCell(d) || {}, n: { pattern: a.pattern } }, g = r.setValue(m); d.s = g, a.pattern === ks && (d.t = se.STRING); } else { const h = { n: { pattern: a.pattern } }, m = r.setValue(h); m && i.setValue(l, c, { s: m }); } }); }); }); } }; co = nd([ oo(0, nn), oo(1, M), oo(2, Es) ], co); var od = Object.defineProperty, sd = Object.getOwnPropertyDescriptor, rd = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? sd(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && od(e, t, s), s; }, Qe = (n, e) => (t, o) => e(t, o, n); const hs = [je.id, qe.id, De.id, Be.id], ms = [ot.id, st.id]; let An = class extends ae { constructor(e, t, o, s, r, i, a, u) { super(); R(this, "disposableCollection", new jt()); this._selectionProtectionRuleModel = e, this._univerInstanceService = t, this._commandService = o, this._refRangeService = s, this._selectionProtectionRenderModel = r, this._rangeProtectionCache = i, this._sheetInterceptorService = a, this._rangeProtectionRuleModel = u, this._onRefRangeChange(), this._correctPermissionRange(), this._initReBuildCache(), this._initRemoveSheet(); } _onRefRangeChange() { const e = (o, s) => { const r = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET); if (!r || !(r == null ? void 0 : r.getSheetBySheetId(s))) return; this.disposableCollection.dispose(); const a = (l) => this.refRangeHandle(l, o, s); this._selectionProtectionRuleModel.getSubunitRuleList(o, s).reduce((l, c) => [...l, ...c.ranges], []).forEach((l) => { this.disposableCollection.add(this._refRangeService.registerRefRange(l, a, o, s)); }); }; this.disposeWithMe( this._commandService.onCommandExecuted((o) => { if (o.id === Ar.id) { const s = o.params, r = s.subUnitId, i = s.unitId; if (!r || !i) return; e(i, r); } if (o.id === he.id || o.id === Ne.id) { const s = o.params, r = s.subUnitId, i = s.unitId; if (!r || !i) return; e(i, r); } }) ); const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET); if (t) { const o = t.getActiveSheet(); if (!o) return; e(t.getUnitId(), o.getSheetId()); } } refRangeHandle(e, t, o) { switch (e.id) { case Fn.id: return this._getRefRangeMutationsByMoveRows(e.params, t, o); case jn.id: return this._getRefRangeMutationsByMoveCols(e.params, t, o); case mt.id: return this._getRefRangeMutationsByInsertRows(e.params, t, o); case gt.id: return this._getRefRangeMutationsByInsertCols(e.params, t, o); case zn.id: return this._getRefRangeMutationsByDeleteCols(e.params, t, o); case Gn.id: return this._getRefRangeMutationsByDeleteRows(e.params, t, o); } return { redos: [], undos: [] }; } _getRefRangeMutationsByDeleteCols(e, t, o) { const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => k.intersects(a, e.range))), r = e.range; if (s.length) { const i = [], a = []; return s.forEach((u) => { const l = O.deepClone(u), c = l.ranges.reduce((d, h) => { if (k.intersects(h, r)) { const m = O.deepClone(h), { startColumn: g, endColumn: f } = r; if (g <= m.startColumn && f >= m.endColumn) return d; g >= m.startColumn && f <= m.endColumn ? m.endColumn -= f - g + 1 : g < m.startColumn ? (m.startColumn = g, m.endColumn -= f - g + 1) : f > m.endColumn && (m.endColumn = g - 1), this._checkIsRightRange(m) && d.push(m); } return d; }, []); l.ranges = c, l.ranges.length ? (i.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: u.id } }), a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: u, ruleId: u.id } })) : (i.push({ id: ze.id, params: { unitId: t, subUnitId: o, ruleIds: [u.id] } }), a.push({ id: Ne.id, params: { unitId: t, subUnitId: o, name: "", rules: [u] } })); }), { redos: i, undos: a }; } return { undos: [], redos: [] }; } _getRefRangeMutationsByDeleteRows(e, t, o) { const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => k.intersects(a, e.range))), r = e.range; if (s.length) { const i = [], a = []; return s.forEach((u) => { const l = O.deepClone(u), c = l.ranges.reduce((d, h) => { if (k.intersects(h, r)) { const m = O.deepClone(h), { startRow: g, endRow: f } = r; if (g <= m.startRow && f >= m.endRow) return d; g >= m.startRow && f <= m.endRow ? m.endRow -= f - g + 1 : g < m.startRow ? (m.startRow = g, m.endRow -= f - g + 1) : f > m.endRow && (m.endRow = g - 1), this._checkIsRightRange(m) && d.push(m); } return d; }, []); l.ranges = c, i.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: u.id } }), a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: u, ruleId: u.id } }); }), { redos: i, undos: a }; } return { undos: [], redos: [] }; } _getRefRangeMutationsByInsertCols(e, t, o) { const s = e.range.startColumn, r = e.range.endColumn - e.range.startColumn + 1, i = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((a) => a.ranges.some((u) => s > u.startColumn && s <= u.endColumn)); if (i.length) { const a = [], u = []; return i.forEach((l) => { const c = O.deepClone(l); let d = !1; c.ranges.forEach((h) => { s > h.startColumn && s <= h.endColumn && (h.endColumn += r, d = !0); }), d && (a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: l.id } }), u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: l.id } })); }), { redos: a, undos: u }; } return { undos: [], redos: [] }; } _getRefRangeMutationsByInsertRows(e, t, o) { const s = e.range.startRow, r = e.range.endRow - e.range.startRow + 1, i = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((a) => a.ranges.some((u) => s > u.startRow && s <= u.endRow)); if (i.length) { const a = [], u = []; return i.forEach((l) => { const c = O.deepClone(l); let d = !1; c.ranges.forEach((h) => { s > h.startRow && s <= h.endRow && (h.endRow += r, d = !0); }), d && (a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: l.id } }), u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: l.id } })); }), { redos: a, undos: u }; } return { undos: [], redos: [] }; } _getRefRangeMutationsByMoveRows(e, t, o) { const s = e.toRange, r = s.startRow, i = s.endRow - s.startRow + 1, a = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((u) => u.ranges.some((l) => r > l.startRow && r <= l.endRow)); if (a.length) { const u = [], l = []; return a.forEach((c) => { const d = O.deepClone(c), m = e.fromRange.startRow; let g = !1; d.ranges.forEach((f) => { r > f.startRow && r <= f.endRow && (m < f.startRow && (f.startRow = f.startRow - i, f.endRow = f.endRow - i), f.endRow += i, g = !0); }), g && (u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: d, ruleId: c.id } }), l.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: c.id } })); }), { redos: u, undos: l }; } return { undos: [], redos: [] }; } _getRefRangeMutationsByMoveCols(e, t, o) { const s = e.toRange, r = s.startColumn, i = s.endColumn - s.startColumn + 1, a = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((u) => u.ranges.some((l) => r > l.startColumn && r <= l.endColumn)); if (a.length) { const u = [], l = []; return a.forEach((c) => { const d = O.deepClone(c), m = e.fromRange.startColumn; let g = !1; d.ranges.forEach((f) => { r > f.startColumn && r <= f.endColumn && (m < f.startColumn && (f.startColumn = f.startColumn - i, f.endColumn = f.endColumn - i), f.endColumn += i, g = !0); }), g && (u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: d, ruleId: c.id } }), l.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: c.id } })); }), { redos: u, undos: l }; } return { undos: [], redos: [] }; } _correctPermissionRange() { this.disposeWithMe(this._commandService.onCommandExecuted((e) => { if (ms.includes(e.id)) { if (!e.params) return; const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET); if (!t) return; const o = t.getSheetBySheetId(e.params.subUnitId); if (!o) return; const { sourceRange: s, targetRange: r } = e.params, i = s.startColumn === r.startColumn && s.endColumn === r.endColumn, a = i ? s.endRow - s.startRow + 1 : s.endColumn - s.startColumn + 1, u = i ? s.startRow : s.startColumn, l = i ? r.startRow : r.startColumn; this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((f) => { f.ranges.forEach((C) => { let { startRow: S, endRow: I, startColumn: w, endColumn: b } = C; k.intersects(C, s) || (i ? u < S && l > I ? (S -= a, I -= a) : u > I && l <= S && (S += a, I += a) : u < w && l > b ? (w -= a, b -= a) : u > b && l <= w && (w += a, b += a)), this._checkIsRightRange({ startRow: S, endRow: I, startColumn: w, endColumn: b }) && (C.startColumn = w, C.endColumn = b, C.startRow = S, C.endRow = I); }); }), this.disposableCollection.dispose(); const { unitId: d, subUnitId: h } = e.params, m = (f) => this.refRangeHandle(f, d, h); this._selectionProtectionRuleModel.getSubunitRuleList(d, h).reduce((f, p) => [...f, ...p.ranges], []).forEach((f) => { this.disposableCollection.add(this._refRangeService.registerRefRange(f, m, d, h)); }), this._selectionProtectionRenderModel.clear(); } if (hs.includes(e.id)) { const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId); if (!t) return; const o = t.getSheetBySheetId(e.params.subUnitId); if (!o) return; const s = e.params; if (!s) return; const { range: r } = s, i = e.id.includes("row"), a = e.id.includes("insert"), u = i ? r.startRow : r.startColumn, l = i ? r.endRow : r.endColumn, c = l - u + 1; this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((p) => { p.ranges.forEach((S) => { let { startRow: I, endRow: w, startColumn: b, endColumn: y } = S; a ? i ? u <= I && (I += c, w += c) : u <= b && (b += c, y += c) : i ? l < I && (I -= c, w -= c) : l < b && (b -= c, y -= c), this._checkIsRightRange({ startRow: I, endRow: w, startColumn: b, endColumn: y }) && (S.startColumn = b, S.endColumn = y, S.startRow = I, S.endRow = w); }); }), this.disposableCollection.dispose(); const { unitId: h, subUnitId: m } = e.params, g = (p) => this.refRangeHandle(p, h, m); this._selectionProtectionRuleModel.getSubunitRuleList(h, m).reduce((p, C) => [...p, ...C.ranges], []).forEach((p) => { this.disposableCollection.add(this._refRangeService.registerRefRange(p, g, h, m)); }), this._selectionProtectionRenderModel.clear(); } })); } _checkIsRightRange(e) { return e.startRow <= e.endRow && e.startColumn <= e.endColumn; } _initReBuildCache() { this.disposeWithMe(this._commandService.onCommandExecuted((e) => { if (hs.includes(e.id) || ms.includes(e.id)) { const { unitId: t, subUnitId: o } = e.params; this._rangeProtectionCache.reBuildCache(t, o); } })); } _initRemoveSheet() { this._sheetInterceptorService.interceptCommand( { getMutations: (e) => { const t = [], o = [], s = [], r = []; if (e.id === ko.id) { const i = e.params, a = [], u = []; this._rangeProtectionRuleModel.getSubunitRuleList(i.unitId, i.subUnitId).forEach((l) => { a.push(l.id), u.push(l); }), a.length && u.length && (s.push({ id: ze.id, params: { unitId: i.unitId, subUnitId: i.subUnitId, ruleIds: a } }), t.push({ id: Ne.id, params: { unitId: i.unitId, subUnitId: i.subUnitId, name: "", rules: u } })); } return { redos: o, undos: t, preRedos: s, preUndos: r }; } } ); } }; An = rd([ Qe(0, L(de)), Qe(1, L(M)), Qe(2, E), Qe(3, L(_t)), Qe(4, L(tn)), Qe(5, L(ht)), Qe(6, L(V)), Qe(7, L(de)) ], An); var id = Object.defineProperty, ad = Object.getOwnPropertyDescriptor, ud = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? ad(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && id(e, t, s), s; }, Dt = (n, e) => (t, o) => e(t, o, n); const ld = "SHEET_RANGE_PROTECTION_PLUGIN"; let xn = class extends ae { constructor(n, e, t, o, s) { super(), this._selectionProtectionRuleModel = n, this._permissionService = e, this._resourceManagerService = t, this._selectionProtectionCache = o, this._univerInstanceService = s, this._initSnapshot(), this._initRuleChange(); } _initRuleChange() { this.disposeWithMe( this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => { switch (n.type) { case "add": { Ie().forEach((e) => { const t = new e(n.unitId, n.subUnitId, n.rule.permissionId); this._permissionService.addPermissionPoint(t); }); break; } case "delete": { Ie().forEach((e) => { const t = new e(n.unitId, n.subUnitId, n.rule.permissionId); this._permissionService.deletePermissionPoint(t.id); }); break; } case "set": { n.oldRule.permissionId !== n.rule.permissionId && Ie().forEach((e) => { const t = new e(n.unitId, n.subUnitId, n.oldRule.permissionId); this._permissionService.deletePermissionPoint(t.id); const o = new e(n.unitId, n.subUnitId, n.rule.permissionId); this._permissionService.addPermissionPoint(o); }); break; } } }) ); } _initSnapshot() { const n = (t) => { const s = this._selectionProtectionRuleModel.toObject()[t]; return s ? JSON.stringify(s) : ""; }, e = (t) => { if (!t) return {}; try { return JSON.parse(t); } catch { return {}; } }; this.disposeWithMe( this._resourceManagerService.registerPluginResource({ toJson: n, parseJson: e, pluginName: ld, businesses: [Sn.UNIVER_SHEET], onLoad: (t, o) => { const s = this._selectionProtectionRuleModel.toObject(); s[t] = o, this._selectionProtectionRuleModel.fromObject(s); const r = []; Object.keys(o).forEach((i) => { const a = o[i]; this._selectionProtectionRuleModel.getSubunitRuleList(t, i).forEach((u) => { r.push({ objectID: u.permissionId, unitID: t, objectType: D.SelectRange, actions: it }); }), a.forEach((u) => { Ie().forEach((l) => { const c = new l(t, i, u.permissionId); c.value = !1, this._permissionService.addPermissionPoint(c); }); }), this._selectionProtectionCache.reBuildCache(t, i); }); }, onUnLoad: (t) => { this._selectionProtectionCache.deleteUnit(t); } }) ); } }; xn = ud([ Dt(0, L(de)), Dt(1, L(Fe)), Dt(2, L(nn)), Dt(3, L(ht)), Dt(4, L(M)) ], xn); var cd = Object.defineProperty, dd = Object.getOwnPropertyDescriptor, hd = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? dd(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && cd(e, t, s), s; }, At = (n, e) => (t, o) => e(t, o, n); let $n = class extends ae { constructor(n, e, t, o, s) { super(), this._permissionService = n, this._univerInstanceService = e, this._rangeProtectionRuleModel = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointModel = s, this._init(); } _init() { const n = (e) => { const t = e.getUnitId(); en().forEach((o) => { const s = new o(t); this._permissionService.addPermissionPoint(s); }); }; this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => { n(e); }), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((e) => { n(e); })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe((e) => { const t = e.getUnitId(); e.getSheets().forEach((o) => { const s = o.getSheetId(); this._rangeProtectionRuleModel.getSubunitRuleList(t, s).forEach((i) => { [...Ie()].forEach((a) => { const u = new a(t, s, i.permissionId); this._permissionService.deletePermissionPoint(u.id); }); }), [...we(), ...ke()].forEach((i) => { const a = new i(t, s); this._permissionService.deletePermissionPoint(a.id); }); }), en().forEach((o) => { const s = new o(t); this._permissionService.deletePermissionPoint(s.id); }), this._rangeProtectionRuleModel.deleteUnitModel(t), this._worksheetProtectionPointModel.deleteUnitModel(t), this._worksheetProtectionRuleModel.deleteUnitModel(t); })); } }; $n = hd([ At(0, L(Fe)), At(1, L(M)), At(2, L(de)), At(3, L(Ye)), At(4, L(un)) ], $n); var md = Object.defineProperty, gd = Object.getOwnPropertyDescriptor, fd = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? gd(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && md(e, t, s), s; }, Rd = (n, e) => (t, o) => e(t, o, n); let ho = class extends ae { constructor(n) { super(), this._sheetRangeThemeModel = n; } /** * Register a custom range theme style. * @param {string} unitId Which unit to register the range theme style. * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register. */ registerRangeTheme(n, e) { this._sheetRangeThemeModel.registerRangeThemeStyle(n, e); } /** * Get custom register themes name list * @returns {string[]} The list of custom register themes name. */ getALLRegisterThemes() { return this._sheetRangeThemeModel.getALLRegisteredTheme(); } /** * Register range theme style to the range. * @param {string} themeName The defined theme name. * @param {IRangeThemeRangeInfo} rangeInfo The range info to apply the theme style. */ registerRangeThemeStyle(n, e) { this._sheetRangeThemeModel.registerRangeThemeRule(n, e); } /** * Get applied range theme style name. * @param {IRangeThemeRangeInfo} rangeInfo The range info to get the applied theme style. * @returns {string | undefined} The applied theme style name or not exist. */ getAppliedRangeThemeStyle(n) { return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(n); } /** * Get registered build-in range theme style */ getRegisteredRangeThemes() { return this._sheetRangeThemeModel.getRegisteredRangeThemes(); } }; ho = fd([ Rd(0, L(He)) ], ho); var Qr = Object.defineProperty, pd = Object.getOwnPropertyDescriptor, Cd = (n, e, t) => e in n ? Qr(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Sd = (n, e, t, o) => { for (var s = o > 1 ? void 0 : o ? pd(e, t) : e, r = n.length - 1, i; r >= 0; r--) (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s); return o && s && Qr(e, t, s), s; }, gs = (n, e) => (t, o) => e(t, o, n), ei = (n, e, t) => Cd(n, typeof e != "symbol" ? e + "" : e, t); const wd = "SHEET_PLUGIN"; let Wn = class extends bi { constructor(n = ts, e, t) { super(), this._config = n, this._injector = e, this._configService = t; const { ...o } = yi( {}, ts, this._config ); this._configService.setConfig(Kl, o), this._initConfig(), this._initDependencies(); } _initConfig() { var n, e, t; (n = this._config) != null && n.onlyRegisterFormulaRelatedMutations && this._configService.setConfig(Kr, !0), (e = this._config) != null && e.isRowStylePrecedeColumnStyle && this._configService.setConfig(Ei, !0), (t = this._config) != null && t.autoHeightForMergedCells && this._configService.setConfig(Ui, !0); } _initDependencies() { var e; const n = [ // services [kt], [F], [_t], [$n], [wt, { useClass: co }], [V], [ho], // controllers [yn], [Tn], [kn], [Un], // permission [bn], [Ye], [un], [Dn], [On], [Nn], // range theme [He], // range protection [tn], [de], [ht], [An], [xn], [ds, { useClass: Qc, deps: [F] }] ]; (e = this._config) != null && e.notExecuteFormula || n.push([En]), Pi(this._injector, Ti(n, this._config.override)), ln(this._injector, [ [V], [xn], [ds] ]); } onStarting() { ln(this._injector, [ [yn], [Tn], [$n], [bn], [Dn] ]); } onRendered() { ln(this._injector, [ [wt], [On] ]); } onReady() { ln(this._injector, [ [En], [Un], [He], [kn], [tn], [An], [_t], [Nn] ]); } }; ei(Wn, "pluginName", wd); ei(Wn, "type", B.UNIVER_SHEET); Wn = Sd([ _i(Bi), gs(1, L(Ro)), gs(2, Us) ], Wn); var Id = /* @__PURE__ */ ((n) => (n.SET_WORKSHEET_ROW_HEIGHT = "sheet.mutation.set-worksheet-row-height", n.SET_WORKSHEET_ROW_IS_AUTO_HEIGHT = "sheet.mutation.set-worksheet-row-is-auto-height", n.SET_WORKSHEET_ROW_AUTO_HEIGHT = "sheet.mutation.set-worksheet-row-auto-height", n.SET_WORKSHEET_COL_WIDTH = "sheet.mutation.set-worksheet-col-width", n.SET_WORKSHEET_ACTIVE = "sheet.operation.set-worksheet-active", n.MOVE_ROWS = "sheet.mutation.move-rows", n.MOVE_COLUMNS = "sheet.mutation.move-columns", n.SET_COL_HIDDEN = "sheet.mutation.set-col-hidden", n.SET_COL_VISIBLE = "sheet.mutation.set-col-visible", n.SET_ROW_HIDDEN = "sheet.mutation.set-row-hidden", n.SET_ROW_VISIBLE = "sheet.mutation.set-row-visible", n.INSERT_COL = "sheet.mutation.insert-col", n.INSERT_ROW = "sheet.mutation.insert-row", n.REMOVE_COL = "sheet.mutation.remove-col", n.REMOVE_ROW = "sheet.mutation.remove-row", n.TOGGLE_GRIDLINES = "sheet.mutation.toggle-gridlines", n.SET_GRIDLINES_COLOR = "sheet.mutation.set-gridlines-color", n))(Id || {}), vd = /* @__PURE__ */ ((n) => (n.SET_RANGE_VALUES = "sheet.mutation.set-range-values", n.MOVE_RANGE = "sheet.mutation.move-range", n.REMOVE_WORKSHEET_MERGE = "sheet.mutation.remove-worksheet-merge", n.ADD_WORKSHEET_MERGE = "sheet.mutation.add-worksheet-merge", n.REORDER_RANGE = "sheet.mutation.reorder-range", n.SET_WORKSHEET_DEFAULT_STYLE = "sheet.mutation.set-worksheet-default-style", n.SET_ROW_DATA = "sheet.mutation.set-row-data", n.SET_COL_DATA = "sheet.mutation.set-col-data", n.SET_WORKSHEET_RANGE_THEME_STYLE = "sheet.mutation.set-worksheet-range-theme-style", n.DELETE_WORKSHEET_RANGE_THEME_STYLE = "sheet.mutation.delete-worksheet-range-theme-style", n))(vd || {}); const gh = [ nt.id, Oe.id, Br.id, tt.id, an.id, ot.id, st.id, Xt.id, qt.id, Qt.id, Zt.id, je.id, qe.id, De.id, Be.id, Ft.id, Vt.id ], fh = [ Q.id, dt.id, oe.id, ne.id, In.id, Bt.id, Ht.id, Lt.id, zt.id, Kt.id ]; function Rh(n) { switch (n.id) { case "sheet.mutation.set-range-values": { const e = n.params; return e.cellValue ? [{ unitId: e.unitId, subUnitId: e.subUnitId, range: new G(e.cellValue).getDataRange() }] : []; } case "sheet.mutation.move-range": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.from.subUnitId, range: new G(e.from.value).getRange() }, { unitId: e.unitId, subUnitId: e.to.subUnitId, range: new G(e.to.value).getRange() }]; } case "sheet.mutation.remove-worksheet-merge": { const e = n.params; return e.ranges.map((t) => ({ unitId: e.unitId, subUnitId: e.subUnitId, range: t })); } case "sheet.mutation.add-worksheet-merge": { const e = n.params; return e.ranges.map((t) => ({ unitId: e.unitId, subUnitId: e.subUnitId, range: t })); } case "sheet.mutation.reorder-range": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: e.range }]; } case "sheet.mutation.set-worksheet-default-style": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { startRow: 0, endRow: Number.MAX_SAFE_INTEGER, startColumn: 0, endColumn: Number.MAX_SAFE_INTEGER } }]; } case "sheet.mutation.set-row-data": { const e = n.params, t = Object.keys(e.rowData).map(Number); return t.length === 0 ? [] : [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { startRow: Math.min(...t), endRow: Math.max(...t), startColumn: 0, endColumn: Number.MAX_SAFE_INTEGER } }]; } case "sheet.mutation.set-col-data": { const e = n.params, t = Object.keys(e.columnData).map(Number); return t.length === 0 ? [] : [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { startRow: 0, endRow: Number.MAX_SAFE_INTEGER, startColumn: Math.min(...t), endColumn: Math.max(...t) } }]; } case "sheet.mutation.set-worksheet-range-theme-style": case "sheet.mutation.delete-worksheet-range-theme-style": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: e.range }]; } default: return []; } } function ph(n) { switch (n.id) { case "sheet.mutation.set-worksheet-row-height": case "sheet.mutation.set-worksheet-row-is-auto-height": case "sheet.mutation.set-worksheet-row-auto-height": { const e = n.params; return e.ranges.map((t) => ({ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...t, rangeType: H.ROW } })); } case "sheet.mutation.set-worksheet-col-width": { const e = n.params; return e.ranges.map((t) => ({ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...t, rangeType: H.COLUMN } })); } case "sheet.mutation.move-rows": case "sheet.mutation.move-columns": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: e.targetRange }, { unitId: e.unitId, subUnitId: e.subUnitId, range: e.sourceRange }]; } case "sheet.mutation.set-col-hidden": case "sheet.mutation.set-col-visible": { const e = n.params; return e.ranges.map((t) => ({ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...t, rangeType: H.COLUMN } })); } case "sheet.mutation.set-row-hidden": case "sheet.mutation.set-row-visible": { const e = n.params; return e.ranges.map((t) => ({ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...t, rangeType: H.ROW } })); } case "sheet.mutation.insert-col": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: H.COLUMN } }]; } case "sheet.mutation.insert-row": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: H.ROW } }]; } case "sheet.mutation.remove-col": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: H.COLUMN } }]; } case "sheet.mutation.remove-row": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: H.ROW } }]; } case "sheet.mutation.toggle-gridlines": case "sheet.mutation.set-gridlines-color": return []; default: return []; } } const Ch = 1.5, Sh = "rgba(255, 255, 255, 0.01)"; function wh(n) { const { rangeWithCoord: e, primaryWithCoord: t, style: o } = n, s = { range: { startRow: e.startRow, startColumn: e.startColumn, endRow: e.endRow, endColumn: e.endColumn, rangeType: e.rangeType, unitId: e.unitId, sheetId: e.sheetId }, primary: null, style: o }; return t != null && (s.primary = Md(t)), s; } function Md(n) { const { actualRow: e, actualColumn: t, isMerged: o, isMergedMainCell: s } = n, { startRow: r, startColumn: i, endRow: a, endColumn: u } = n.mergeInfo; return { actualRow: e, actualColumn: t, isMerged: o, isMergedMainCell: s, startRow: r, startColumn: i, endRow: a, endColumn: u }; } const Ih = (n, e, t) => { const s = n.get(F).getCurrentSelections(), { value: r, selections: i, unitId: a, subUnitId: u } = e; if (s) { const c = s[(s == null ? void 0 : s.length) - 1].primary; if (c) { const { actualColumn: d, actualRow: h } = c; let { startRow: m, startColumn: g, endRow: f, endColumn: p } = i[i.length - 1]; if (r === ge.COLUMNS) { const w = t.find((b) => b.startColumn === d && b.endColumn === d && h === b.startRow); w && (p = w.endColumn, m = w.startRow, f = w.endRow); } else if (r === ge.ROWS) { const w = t.find((b) => b.startRow === h && b.endRow === h && d === b.startColumn); w && (f = w.endRow, g = w.startColumn, p = w.endColumn); } const C = { startRow: m, startColumn: g, endRow: f, endColumn: p, actualRow: h, actualColumn: d, isMerged: !0, isMergedMainCell: m === h && g === d }, S = s.map((w, b, y) => ({ range: w.range, style: null, primary: b === y.length - 1 ? C : null })), I = { unitId: a, subUnitId: u, type: Ce.ONLY_SET, selections: S }; return { id: re.id, params: I }; } return null; } return null; }, vh = (n, e) => { const o = n.get(F).getCurrentSelections(), { unitId: s, subUnitId: r } = e; if (o && o[(o == null ? void 0 : o.length) - 1].primary) { const u = { unitId: s, subUnitId: r, type: Ce.ONLY_SET, selections: [...o] }; return { id: re.id, params: u }; } return null; }; function fs(n) { return n == null ? !1 : n.v !== void 0 && n.v !== null && n.v !== "" || n.p !== void 0; } function Yn(n, e) { return n && n.spanAnchor ? fs(e.getValue(n.spanAnchor.startRow, n.spanAnchor.startColumn)) : fs(n); } function _d(n, e, t, o, s) { const r = n.getCellMatrix(), i = n.getSpanModel().getMergedCellRange(e, t, o, s), a = new G(); return r.forValue((u, l) => { const c = r.getValue(u, l); c && a.setValue(u, l, c); }), i.forEach((u) => { const { startColumn: l, startRow: c, endColumn: d, endRow: h } = u; ki(c, h, l, d).forEach((m, g) => { m === c && g === l && a.setValue(m, g, { ...r.getValue(m, g), spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d } }), (m !== c || g !== l) && (a.realDeleteValue(m, g), a.setValue(m, g, { spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d } })); }); }), a; } function bd(n, e, t, o) { const { startRow: s, startColumn: r, endRow: i } = n; let a = null, u = !1; for (let l = s; l <= i; l++) { const c = e.getValue(l, r - t); if (u = u || Yn(c, e), !o && u) break; c && c.spanAnchor && (a ? a = { startRow: Math.min(c.spanAnchor.startRow, a.startRow), startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn), endRow: Math.max(c.spanAnchor.endRow, a.endRow), endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn) } : a = { startRow: c.spanAnchor.startRow, startColumn: c.spanAnchor.startColumn, endRow: c.spanAnchor.endRow, endColumn: c.spanAnchor.endColumn }); } return u ? (n.startColumn = n.startColumn - t, { spanAnchor: a, hasValue: !0, range: n }) : { spanAnchor: null, hasValue: !1, range: n }; } function yd(n, e, t, o) { const { startRow: s, endColumn: r, endRow: i } = n; let a = null, u = !1; for (let l = s; l <= i; l++) { const c = e.getValue(l, r + t); if (u = u || Yn(c, e), !o && u) break; c && c.spanAnchor && (a ? a = { startRow: Math.min(c.spanAnchor.startRow, a.startRow), startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn), endRow: Math.max(c.spanAnchor.endRow, a.endRow), endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn) } : a = { startRow: c.spanAnchor.startRow, startColumn: c.spanAnchor.startColumn, endRow: c.spanAnchor.endRow, endColumn: c.spanAnchor.endColumn }); } return u ? (n.endColumn = n.endColumn + t, { spanAnchor: a, hasValue: !0, range: n }) : { spanAnchor: null, hasValue: !1, range: n }; } function Ed(n, e, t, o) { const { startRow: s, startColumn: r, endColumn: i } = n; let a = null, u = !1; for (let l = r; l <= i; l++) { const c = e.getValue(s - t, l); if (u = u || Yn(c, e), !o && u) break; c && c.spanAnchor && (a ? a = { startRow: Math.min(c.spanAnchor.startRow, a.startRow), startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn), endRow: Math.max(c.spanAnchor.endRow, a.endRow), endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn) } : a = { startRow: c.spanAnchor.startRow, startColumn: c.spanAnchor.startColumn, endRow: c.spanAnchor.endRow, endColumn: c.spanAnchor.endColumn }); } return u ? (n.startRow = n.startRow - t, { spanAnchor: a, hasValue: !0, range: n }) : { spanAnchor: null, hasValue: !1, range: n }; } function Ud(n, e, t, o) { const { startColumn: s, endColumn: r, endRow: i } = n; let a = null, u = !1; for (let l = s; l <= r; l++) { const c = e.getValue(i + t, l); if (u = u || Yn(c, e), !o && u) break; c && c.spanAnchor && (a ? a = { startRow: Math.min(c.spanAnchor.startRow, a.startRow), startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn), endRow: Math.max(c.spanAnchor.endRow, a.endRow), endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn) } : a = { startRow: c.spanAnchor.startRow, startColumn: c.spanAnchor.startColumn, endRow: c.spanAnchor.endRow, endColumn: c.spanAnchor.endColumn }); } return u ? (n.endRow = n.endRow + t, { spanAnchor: a, hasValue: !0, range: n }) : { spanAnchor: null, hasValue: !1, range: n }; } function Mh(n, e, t) { const o = t.getMaxRows(), s = t.getMaxColumns(), r = _d(t, 0, 0, o - 1, s - 1), i = t.getSnapshot().mergeData.length > 0, { left: a, right: u, up: l, down: c } = e; let d = !0, h = { ...n }; const m = []; for (; d; ) { if (d = !1, l && h.startRow !== 0) { const { hasValue: g, range: f, spanAnchor: p } = Ed(h, r, 1, i); if (p && m.push(p), g) { h = f, d = !0; continue; } } if (c && h.endRow !== o - 1) { const { hasValue: g, range: f, spanAnchor: p } = Ud(h, r, 1, i); if (p && m.push(p), g) { h = f, d = !0; continue; } } if (a && h.startColumn !== 0) { const { hasValue: g, range: f, spanAnchor: p } = bd(h, r, 1, i); if (p && m.push(p), g) { h = f, d = !0; continue; } } if (u && h.endColumn !== s - 1) { const { hasValue: g, range: f, spanAnchor: p } = yd(h, r, 1, i); if (p && m.push(p), g) { h = f, d = !0; continue; } } } return m.length > 0 && (h = k.union(h, ...m)), h; } const ti = (n, e, t, o = 1, s = !0, r = !0) => { const i = K.transformRange(n, e), { startRow: a, endRow: u } = i; let l = t.startRow - o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn; for (; !e.getRowVisible(l) || !d; ) l--, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn; if (l >= a) return { ...t, startRow: l, endRow: l }; if (r) { const h = { ...t, startRow: u, endRow: u }; return oi(n, e, h, o, s, !1); } }, ni = (n, e, t, o = 1, s = !0, r = !0) => { const i = K.transformRange(n, e), { startRow: a, endRow: u } = i; let l = t.endRow + o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn; for (; !e.getRowVisible(l) || !d; ) l++, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn; if (l <= u) return { ...t, startRow: l, endRow: l }; if (r) { const h = { ...t, startRow: a, endRow: a }; return si(n, e, h, o, s, !1); } }, oi = (n, e, t, o = 1, s = !0, r = !0) => { const i = K.transformRange(n, e), { startColumn: a, endColumn: u } = i; let l = t.startColumn - o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l; for (; !e.getColVisible(l) || !d; ) l--, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l; if (l >= a) return { ...t, startColumn: l, endColumn: l }; if (r) { const h = { ...t, startColumn: u, endColumn: u }; return ti(n, e, h, o, s, !1); } }, si = (n, e, t, o = 1, s = !0, r = !0) => { const i = K.transformRange(n, e), { startColumn: a, endColumn: u } = i; let l = t.endColumn + o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l; for (; !e.getColVisible(l) || !d; ) l++, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l; if (l <= u) return { ...t, endColumn: l, startColumn: l }; if (r) { const h = { ...t, startColumn: a, endColumn: a }; return ni(n, e, h, o, s, !1); } }; function mn(n, e, t) { let o = null; return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = { actualRow: r, actualColumn: i, startRow: r, startColumn: i, isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0, isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0, endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0), endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0), rangeType: H.NORMAL }, !1)), o || { actualColumn: e, actualRow: n, startRow: n, startColumn: e, endRow: n, endColumn: e, isMerged: !1, isMergedMainCell: !1, rangeType: H.NORMAL }; } const Pd = (n, e, t, o, s = 1) => { switch (o) { case pe.UP: return ti(n, e, t, s); case pe.DOWN: return ni(n, e, t, s); case pe.LEFT: return oi(n, e, t, s); case pe.RIGHT: return si(n, e, t, s); } }, _h = (n, e, t) => { let o, s = -1, r; for (let C = 0; C < n.length; C++) if (n[C].primary) { o = n[C], s = C, r = o.primary; break; } if (s === -1) return null; const i = e === pe.LEFT || e === pe.UP, a = i ? s - 1 >= 0 ? s - 1 : n.length - 1 : s + 1 < n.length ? s + 1 : 0, u = n[a]; if (!o || !r) return null; const l = { ...r }, { startRow: c, startColumn: d, endRow: h, endColumn: m } = o.range, g = i ? l.startRow === c && l.startColumn === d : l.endRow === h && l.endColumn === m, f = g && i; if (!k.equals(o.range, l)) { const C = g ? u.range : Pd(o.range, t, l, e); if (!C) return null; const S = f ? mn(C.endRow, C.endColumn, t) : mn(C.startRow, C.startColumn, t); return { startRow: S.startRow, startColumn: S.startColumn, endRow: S.endRow, endColumn: S.endColumn }; } const p = f ? mn(u.range.endRow, u.range.endColumn, t) : mn(u.range.startRow, u.range.startColumn, t); return { startRow: p.startRow, startColumn: p.startColumn, endRow: p.endRow, endColumn: p.endColumn }; }, bh = { WorkbookCommentPermission: Ws, WorkbookCopyPermission: Ls, WorkbookCreateProtectPermission: Vs, WorkbookCreateSheetPermission: Hs, WorkbookDeleteSheetPermission: Bs, WorkbookDuplicatePermission: Fs, WorkbookEditablePermission: Me, WorkbookExportPermission: js, WorkbookHideSheetPermission: vo, WorkbookHistoryPermission: tu, WorkbookManageCollaboratorPermission: Mo, WorkbookMoveSheetPermission: _o, WorkbookPrintPermission: Gs, WorkbookRecoverHistoryPermission: zs, WorkbookRenameSheetPermission: bo, WorkbookSharePermission: Ks, WorkbookViewHistoryPermission: Ys, WorkbookViewPermission: Js, WorksheetCopyPermission: Xs, WorksheetDeleteColumnPermission: qs, WorksheetDeleteProtectionPermission: Zs, WorksheetDeleteRowPermission: Qs, WorksheetEditExtraObjectPermission: er, WorksheetEditPermission: Te, WorksheetFilterPermission: tr, WorksheetInsertColumnPermission: nr, WorksheetInsertHyperlinkPermission: or, WorksheetInsertRowPermission: sr, WorksheetManageCollaboratorPermission: rr, WorksheetPivotTablePermission: ir, WorksheetSelectProtectedCellsPermission: nu, WorksheetSelectUnProtectedCellsPermission: ou, WorksheetSetCellStylePermission: ar, WorksheetSetCellValuePermission: wn, WorksheetSetColumnStylePermission: $t, WorksheetSetRowStylePermission: Wt, WorksheetSortPermission: ur, WorksheetViewPermission: Hn, RangeProtectionPermissionEditPoint: Pe, RangeProtectionPermissionViewPoint: Io }, yh = (n, e, t, o) => { const s = n.get(Fe), r = n.get(de), i = s.getPermissionPoint(new Me(e).id); if (!(i != null && i.value)) return !1; const a = s.getPermissionPoint(new Te(e, t).id); if (!(a != null && a.value)) return !1; const l = r.getSubunitRuleList(e, t).filter((c) => c.ranges.some((d) => o.some((h) => k.intersects(d, h)))); return l.length ? l.every((c) => { const d = c.permissionId, h = s.getPermissionPoint(new Pe(e, t, d).id); return !!(h != null && h.value); }) : !0; }; function Td(n, e) { return e.some((t) => kd(n, t)); } function kd(n, e) { const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s); let a = !1; return i.forValue((u, l, c) => { if (c && (u !== t || l !== o) && n.cellHasValue(c)) return a = !0, !1; }), a; } function Nd(n, e, t, o) { const s = [], r = [], i = t.getSheetId(); return o.forEach((a) => { const u = Od(t, a), l = { unitId: e, subUnitId: i, cellValue: u.getData() }, c = Ae( n, l ); s.push({ id: Q.id, params: c }), r.push({ id: Q.id, params: l }); }), { undos: s, redos: r }; } function Od(n, e) { const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s, Ni.Intercepted), a = new G(); return i.forValue((u, l, c) => { c && (u !== t || l !== o) && a.setValue(u, l, null); }), a; } const Xn = { type: v.COMMAND, id: "sheet.command.add-worksheet-merge", handler: (n, e) => { const t = n.get(E), o = n.get(W), s = n.get(M), r = e.unitId, i = e.subUnitId, a = e.selections, u = Zr(a, e.value), l = s.getUniverSheetInstance(r).getSheetBySheetId(i), c = [], d = [], h = Td(l, u), m = { unitId: r, subUnitId: i, ranges: u }, g = { unitId: r, subUnitId: i, ranges: u }; c.push({ id: oe.id, params: m }), c.push({ id: ne.id, params: g }); const f = Se(n, m), p = Ue(n, g); if (d.push({ id: oe.id, params: p }), d.push({ id: ne.id, params: f }), h) { const S = Nd(n, r, l, u); c.unshift(...S.redos), d.push(...S.undos); } return z(c, t).result ? (o.pushUndoRedo({ unitID: r, undoMutations: d, redoMutations: c }), !0) : !1; } }, Eh = { type: v.COMMAND, id: "sheet.command.add-worksheet-merge-all", handler: async (n) => { var l; const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range); if (!(o != null && o.length)) return !1; const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET); if (!r) return !1; const i = r.getActiveSheet(); if (!i) return !1; const a = r.getUnitId(), u = i.getSheetId(); return e.executeCommand(Xn.id, { selections: o, unitId: a, subUnitId: u }); } }, Uh = { type: v.COMMAND, id: "sheet.command.add-worksheet-merge-vertical", handler: async (n) => { var l; const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range); if (!(o != null && o.length)) return !1; const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET); if (!r) return !1; const i = r.getActiveSheet(); if (!i) return !1; const a = r.getUnitId(), u = i.getSheetId(); return e.executeCommand(Xn.id, { value: ge.COLUMNS, selections: o, unitId: a, subUnitId: u }); } }, Ph = { type: v.COMMAND, id: "sheet.command.add-worksheet-merge-horizontal", handler: async (n) => { var l; const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range); if (!(o != null && o.length)) return !1; const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET); if (!r) return !1; const i = r.getActiveSheet(); if (!i) return !1; const a = r.getUnitId(), u = i.getSheetId(); return e.executeCommand(Xn.id, { value: ge.ROWS, selections: o, unitId: a, subUnitId: u }); } }; function Th(n, e, t, o, s) { const r = n.get(M), i = N(r, { unitId: e, subUnitId: t }); if (!i) return; const { worksheet: a } = i; if (a.getMergeData().some((d) => o.some((h) => k.intersects(h, d)))) throw new Error("The ranges to be merged overlap with the existing merged cells"); n.get(E).executeCommand(Xn.id, { unitId: e, subUnitId: t, selections: o, defaultMerge: s }); } const Dd = (n, e) => { const r = n.get(M).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft; return { ...O.deepClone(e), rightToLeft: r }; }, so = { id: "sheet.mutation.set-worksheet-right-to-left", type: v.MUTATION, handler: (n, e) => { const t = n.get(M).getUniverSheetInstance(e.unitId); if (!t) return !1; const o = t.getSheetBySheetId(e.subUnitId); if (!o) return !1; const s = o.getConfig(); return s.rightToLeft = e.rightToLeft, !0; } }, kh = { type: v.COMMAND, id: "sheet.command.set-worksheet-right-to-left", handler: async (n, e) => { var d; const t = n.get(E), o = n.get(W), s = N(n.get(M), e); if (!s) return !1; const { unitId: r, subUnitId: i } = s; let a = te.FALSE; e && (a = (d = e.rightToLeft) != null ? d : te.FALSE); const u = { rightToLeft: a, unitId: r, subUnitId: i }, l = Dd( n, u ); return t.syncExecuteCommand( so.id, u ) ? (o.pushUndoRedo({ unitID: r, undoMutations: [{ id: so.id, params: l }], redoMutations: [ { id: so.id, params: u } ] }), !0) : !1; } }; export { qn as AFTER_CELL_EDIT, Zn as AFTER_CELL_EDIT_ASYNC, Ih as AddMergeRedoSelectionsOperationFactory, Ue as AddMergeUndoMutationFactory, vh as AddMergeUndoSelectionsOperationFactory, Xi as AddRangeProtectionCommand, Ne as AddRangeProtectionMutation, Eh as AddWorksheetMergeAllCommand, Xn as AddWorksheetMergeCommand, Ph as AddWorksheetMergeHorizontalCommand, ne as AddWorksheetMergeMutation, Uh as AddWorksheetMergeVerticalCommand, qi as AddWorksheetProtectionCommand, ct as AddWorksheetProtectionMutation, Go as BEFORE_CELL_EDIT, kt as BorderStyleManagerService, gh as COMMAND_LISTENER_SKELETON_CHANGE, fh as COMMAND_LISTENER_VALUE_CHANGE, Fu as CancelFrozenCommand, po as ClearSelectionAllCommand, Co as ClearSelectionContentCommand, So as ClearSelectionFormatCommand, xs as CopySheetCommand, jd as DISABLE_NORMAL_SELECTIONS, Un as DefinedNameDataController, Pt as DeleteRangeMoveLeftCommand, Tt as DeleteRangeMoveUpCommand, su as DeleteRangeProtectionCommand, ze as DeleteRangeProtectionMutation, ru as DeleteWorksheetProtectionCommand, St as DeleteWorksheetProtectionMutation, iu as DeleteWorksheetRangeThemeStyleCommand, Kt as DeleteWorksheetRangeThemeStyleMutation, _a as DeleteWorksheetRangeThemeStyleMutationFactory, Oo as DeltaColumnWidthCommand, $o as DeltaRowHeightCommand, Yi as EditStateEnum, $ as EffectRefRangId, Dl as EmptyMutation, Qc as ExclusiveRangeService, Fd as FactoryAddRangeProtectionMutation, Bd as FactoryDeleteRangeProtectionMutation, qd as FactorySetRangeProtectionMutation, ds as IExclusiveRangeService, et as INTERCEPTOR_POINT, wt as INumfmtService, Xa as IRefSelectionsService, gu as InsertColAfterCommand, mu as InsertColBeforeCommand, pr as InsertColByRangeCommand, gt as InsertColCommand, je as InsertColMutation, yo as InsertColMutationUndoFactory, au as InsertDefinedNameCommand, sn as InsertRangeMoveDownCommand, Bn as InsertRangeMoveRightCommand, hu as InsertRowAfterCommand, du as InsertRowBeforeCommand, fr as InsertRowByRangeCommand, mt as InsertRowCommand, qe as InsertRowMutation, mr as InsertRowMutationUndoFactory, fu as InsertSheetCommand, Jt as InsertSheetMutation, As as InsertSheetUndoMutationFactory, ea as InterceptCellContentPriority, Ll as MAX_CELL_PER_SHEET_KEY, Oc as MERGE_CELL_INTERCEPTOR_CHECK, Tn as MergeCellController, jn as MoveColsCommand, st as MoveColsMutation, pu as MoveColsMutationUndoFactory, pt as MoveRangeCommand, dt as MoveRangeMutation, Fn as MoveRowsCommand, ot as MoveRowsMutation, Ru as MoveRowsMutationUndoFactory, co as NumfmtService, q as OperatorType, bh as PermissionPointsDefinitions, Aa as REF_SELECTIONS_ENABLED, ah as RangeMergeUtil, ht as RangeProtectionCache, Lr as RangeProtectionPermissionDeleteProtectionPoint, Pe as RangeProtectionPermissionEditPoint, Vr as RangeProtectionPermissionManageCollaPoint, Io as RangeProtectionPermissionViewPoint, An as RangeProtectionRefRangeService, tn as RangeProtectionRenderModel, de as RangeProtectionRuleModel, xn as RangeProtectionService, yt as RangeThemeStyle, _t as RefRangeService, qo as RefSelectionsService, wu as RegisterWorksheetRangeThemeStyleCommand, Yt as RegisterWorksheetRangeThemeStyleMutation, Mr as RemoveColByRangeCommand, zn as RemoveColCommand, De as RemoveColMutation, Ir as RemoveDefinedNameCommand, Se as RemoveMergeUndoMutationFactory, zr as RemoveNumfmtMutation, vr as RemoveRowByRangeCommand, Gn as RemoveRowCommand, Be as RemoveRowMutation, ko as RemoveSheetCommand, Ut as RemoveSheetMutation, ja as RemoveSheetUndoMutationFactory, Iu as RemoveWorksheetMergeCommand, oe as RemoveWorksheetMergeMutation, uo as ReorderRangeCommand, In as ReorderRangeMutation, Mu as ReorderRangeUndoMutationFactory, tl as ResetBackgroundColorCommand, Qu as ResetTextColorCommand, ch as SCOPE_WORKBOOK_VALUE_DEFINED_NAME, Gd as SELECTIONS_ENABLED, Sh as SELECTION_CONTROL_BORDER_BUFFER_COLOR, Ch as SELECTION_CONTROL_BORDER_BUFFER_WIDTH, Wl as ScrollToCellOperation, Ce as SelectionMoveType, el as SetBackgroundColorCommand, Zd as SetBoldCommand, Ou as SetBorderBasicCommand, Nu as SetBorderColorCommand, rn as SetBorderCommand, Tu as SetBorderPositionCommand, ku as SetBorderStyleCommand, $u as SetColDataCommand, Lt as SetColDataMutation, xu as SetColDataMutationFactory, yr as SetColHiddenCommand, Xt as SetColHiddenMutation, qt as SetColVisibleMutation, Mn as SetColWidthCommand, Ur as SetDefinedNameCommand, oh as SetFontFamilyCommand, sh as SetFontSizeCommand, Bu as SetFrozenCommand, ut as SetFrozenMutation, Pr as SetFrozenMutationFactory, ju as SetGridlinesColorCommand, Vt as SetGridlinesColorMutation, ol as SetHorizontalTextAlignCommand, Qd as SetItalicCommand, Vo as SetNumfmtMutation, nh as SetOverlineCommand, Gu as SetProtectionCommand, he as SetRangeProtectionMutation, on as SetRangeValuesCommand, Q as SetRangeValuesMutation, Ae as SetRangeValuesUndoMutationFactory, Ku as SetRowDataCommand, Ht as SetRowDataMutation, zu as SetRowDataMutationFactory, Wo as SetRowHeightCommand, kr as SetRowHiddenCommand, Qt as SetRowHiddenMutation, Zt as SetRowVisibleMutation, br as SetSelectedColsVisibleCommand, Tr as SetSelectedRowsVisibleCommand, re as SetSelectionsOperation, Kn as SetSpecificColsVisibleCommand, Jn as SetSpecificRowsVisibleCommand, th as SetStrikeThroughCommand, fe as SetStyleCommand, al as SetTabColorCommand, fn as SetTabColorMutation, Zu as SetTextColorCommand, rl as SetTextRotationCommand, sl as SetTextWrapCommand, eh as SetUnderlineCommand, nl as SetVerticalTextAlignCommand, Dr as SetWorkbookNameCommand, Or as SetWorkbookNameMutation, Ar as SetWorksheetActivateCommand, an as SetWorksheetActiveOperation, tt as SetWorksheetColWidthMutation, xr as SetWorksheetColWidthMutationFactory, dl as SetWorksheetDefaultStyleCommand, Bt as SetWorksheetDefaultStyleMutation, cl as SetWorksheetDefaultStyleMutationFactory, hl as SetWorksheetHideCommand, lt as SetWorksheetHideMutation, Do as SetWorksheetNameCommand, _n as SetWorksheetNameMutation, Wr as SetWorksheetOrderCommand, Rn as SetWorksheetOrderMutation, Il as SetWorksheetPermissionPointsCommand, Ao as SetWorksheetPermissionPointsMutation, vl as SetWorksheetProtectionCommand, Ct as SetWorksheetProtectionMutation, ba as SetWorksheetRangeThemeStyleCommand, zt as SetWorksheetRangeThemeStyleMutation, Ma as SetWorksheetRangeThemeStyleMutationFactory, kh as SetWorksheetRightToLeftCommand, so as SetWorksheetRightToLeftMutation, Br as SetWorksheetRowAutoHeightMutation, ih as SetWorksheetRowAutoHeightMutationFactory, nt as SetWorksheetRowHeightMutation, Lo as SetWorksheetRowIsAutoHeightCommand, Oe as SetWorksheetRowIsAutoHeightMutation, Fr as SetWorksheetShowCommand, V as SheetInterceptorService, Nn as SheetPermissionCheckController, On as SheetPermissionInitController, ho as SheetRangeThemeService, Id as SheetSkeletonChangeType, vd as SheetValueChangeType, F as SheetsSelectionsService, Tl as SplitTextToColumnsCommand, kl as ToggleCellCheckboxCommand, Nl as ToggleGridlinesCommand, Ft as ToggleGridlinesMutation, _ as UnitAction, D as UnitObject, Wn as UniverSheetsPlugin, Ol as UnregisterWorksheetRangeThemeStyleCommand, Uo as UnregisterWorksheetRangeThemeStyleMutation, Ji as ViewStateEnum, Ws as WorkbookCommentPermission, Ls as WorkbookCopyPermission, eu as WorkbookCopySheetPermission, Vs as WorkbookCreateProtectPermission, Hs as WorkbookCreateSheetPermission, Bs as WorkbookDeleteSheetPermission, Fs as WorkbookDuplicatePermission, Me as WorkbookEditablePermission, js as WorkbookExportPermission, vo as WorkbookHideSheetPermission, tu as WorkbookHistoryPermission, Mo as WorkbookManageCollaboratorPermission, _o as WorkbookMoveSheetPermission, $n as WorkbookPermissionService, Gs as WorkbookPrintPermission, zs as WorkbookRecoverHistoryPermission, bo as WorkbookRenameSheetPermission, Ta as WorkbookSelectionModel, Ks as WorkbookSharePermission, Ys as WorkbookViewHistoryPermission, Js as WorkbookViewPermission, Xs as WorksheetCopyPermission, qs as WorksheetDeleteColumnPermission, Zs as WorksheetDeleteProtectionPermission, Qs as WorksheetDeleteRowPermission, er as WorksheetEditExtraObjectPermission, Te as WorksheetEditPermission, tr as WorksheetFilterPermission, nr as WorksheetInsertColumnPermission, or as WorksheetInsertHyperlinkPermission, sr as WorksheetInsertRowPermission, rr as WorksheetManageCollaboratorPermission, bn as WorksheetPermissionService, ir as WorksheetPivotTablePermission, un as WorksheetProtectionPointModel, Ye as WorksheetProtectionRuleModel, nu as WorksheetSelectProtectedCellsPermission, ou as WorksheetSelectUnProtectedCellsPermission, ar as WorksheetSetCellStylePermission, wn as WorksheetSetCellValuePermission, $t as WorksheetSetColumnStylePermission, Wt as WorksheetSetRowStylePermission, ur as WorksheetSortPermission, Hn as WorksheetViewPermission, Th as addMergeCellsUtil, Sc as adjustRangeOnMutation, Ln as alignToMergedCellsBorders, it as baseProtectionActions, yh as checkRangesEditablePermission, Md as convertPrimaryWithCoordToPrimary, wh as convertSelectionDataToRange, Vn as copyRangeStyles, xl as createTopMatrixFromMatrix, Al as createTopMatrixFromRanges, fl as defaultWorkbookPermissionPoints, eo as defaultWorksheetPermissionPoint, Mh as expandToContinuousRange, lh as factoryRemoveNumfmtUndoMutation, uh as factorySetNumfmtUndoMutation, jr as findAllRectangle, Xe as followSelectionOperation, Os as generateNullCell, Ua as generateNullCellValue, Zr as getAddMergeMutationRangeByType, Ie as getAllRangePermissionPoint, en as getAllWorkbookPermissionPoint, we as getAllWorksheetPermissionPoint, ke as getAllWorksheetPermissionPointByPointPanel, zd as getCellAtRowCol, rh as getDefaultRangePermission, lr as getInsertRangeMutations, wo as getMoveRangeUndoRedoMutations, _h as getNextPrimaryCell, ve as getPrimaryForRange, cr as getRemoveRangeMutations, qa as getSelectionsService, mh as getSeparateEffectedRangesOnCommand, N as getSheetCommandTarget, va as getSheetCommandTargetWorkbook, Et as getSheetMutationTarget, ph as getSkeletonChangedEffectedRange, Rh as getValueChangedEffectedRange, vt as handleBaseInsertRange, Pn as handleBaseMoveRowsCols, It as handleBaseRemoveRange, ss as handleCommonDefaultRangeChangeWithEffectRefCommands, hh as handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, os as handleDefaultRangeChangeWithEffectRefCommands, dh as handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, hc as handleDeleteRangeMoveLeft, gc as handleDeleteRangeMoveUp, Xd as handleDeleteRangeMutation, Xr as handleIRemoveCol, oc as handleIRemoveRow, ac as handleInsertCol, uc as handleInsertRangeMoveDown, cc as handleInsertRangeMoveRight, Yd as handleInsertRangeMutation, ic as handleInsertRow, Yr as handleMoveCols, tc as handleMoveRange, Jr as handleMoveRows, Jd as isSingleCellSelection, Gr as rangeMerge, _e as rotateRange, Mt as runRefRangeMutations, Kd as setEndForRange, Pl as splitRangeText, lo as transformCellsToRange };