import { $e, Fi, Gb, Ji, X, Xi, Yb, _f, ca, fn as fn2, g, mr, pr, sa } from "./chunk-QRYBFJ3R.js"; import { $R, AC, BehaviorSubject, Bi, Ct, DC, De, Eu, Fe, Go, Gs, J0, K0, Ke, Ko, L0, LC, Mf, Mi, Mt, NE, OR, Ot, P0, Pt, Q_, Qo, Qr, Ra, SE, Subject, U0, UC, UE, Vn, Vo, Vr, Vs, WC, Xe, Xt, Ze, _C, _n, _s, ar, bE, bR, cn, cs, distinctUntilChanged, dn, en, fC, filter, first, fl, fn, fs, jt, kE, kt, map, merge, mu, nR, nf, nt, nu, of, ot, qt, rR, re, rr, shareReplay, skip, st, switchMap, takeUntil, tr, we, wo, wu, x_, yu, zn } from "./chunk-23V3HWTR.js"; // node_modules/.pnpm/@univerjs+engine-numfmt@0.5.5/node_modules/@univerjs/engine-numfmt/lib/es/index.js var T = "@@@"; // node_modules/.pnpm/@univerjs+sheets@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets/lib/es/index.js var ri = Object.defineProperty; var ii = (n, e, t) => e in n ? ri(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t; var R = (n, e, t) => ii(n, typeof e != "symbol" ? e + "" : e, t); var Ji2 = ((n) => (n.OthersCanView = "othersCanView", n.NoOneElseCanView = "noOneElseCanView", n))(Ji2 || {}); var Yi = ((n) => (n.DesignedUserCanEdit = "designedUserCanEdit", n.OnlyMe = "onlyMe", n))(Yi || {}); var de = class { constructor() { R(this, "_model", /* @__PURE__ */ new Map()); R(this, "_ruleChange", new Subject()); R(this, "ruleChange$", this._ruleChange.asObservable()); R(this, "_ruleRefresh", new Subject()); R(this, "ruleRefresh$", this._ruleRefresh.asObservable()); R(this, "_rangeRuleInitStateChange", new BehaviorSubject(false)); 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 = re.generateRandomId(4); const s = this._ensureRuleMap(e, t); for (; s.has(o); ) o = re.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; } }; var 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 } }; }; var ze = { id: "sheet.mutation.delete-range-protection", type: ar.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); }), true; } }; var Fd = (n) => { const e = { ...n, ruleIds: n.rules.map((t) => t.id) }; return { id: ze.id, params: e }; }; var Ne = { id: "sheet.mutation.add-range-protection", type: ar.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); }), true; } }; var Xi2 = { type: ar.COMMAND, id: "sheet.command.add-range-protection", async handler(n, e) { if (!e) return false; const t = n.get(Pt), o = n.get(cn), 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 true; } }; var Ye = class { constructor() { R(this, "_model", /* @__PURE__ */ new Map()); R(this, "_ruleChange", new Subject()); R(this, "_ruleRefresh", new Subject()); R(this, "_resetOrder", new Subject()); R(this, "ruleChange$", this._ruleChange.asObservable()); R(this, "ruleRefresh$", this._ruleRefresh.asObservable()); R(this, "resetOrder$", this._resetOrder.asObservable()); R(this, "_worksheetRuleInitStateChange", new BehaviorSubject(false)); 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]; } }; var ct = { id: "sheet.mutation.add-worksheet-protection", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, rule: o } = e; return n.get(Ye).addRule(t, o), true; } }; var St = { id: "sheet.mutation.delete-worksheet-protection", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o } = e; return n.get(Ye).deleteRule(t, o), true; } }; var qi = { type: ar.COMMAND, id: "sheet.command.add-worksheet-protection", async handler(n, e) { if (!e) return false; const t = n.get(Pt), o = n.get(cn), { 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 true; } }; var Zi = nR("CELL_CONTENT"); var Qi = nR("ROW_FILTERED"); var et = { CELL_CONTENT: Zi, ROW_FILTERED: Qi }; var ea = ((n) => (n[n.DATA_VALIDATION = 9] = "DATA_VALIDATION", n[n.NUMFMT = 10] = "NUMFMT", n[n.CELL_IMAGE = 11] = "CELL_IMAGE", n))(ea || {}); var Ns = "sheet.interceptor.range-theme-id"; var jo = "sheet.interceptor.ignore-range-theme"; var ta = Object.defineProperty; var na = Object.getOwnPropertyDescriptor; var 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; }; var sa2 = (n, e) => (t, o) => e(t, o, n); var Go2 = nR("BEFORE_CELL_EDIT"); var qn = nR("AFTER_CELL_EDIT"); var Zn = nR("AFTER_CELL_EDIT_ASYNC"); var V = class extends nt { /** @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", false); R(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map()); R(this, "writeCellInterceptor", new rR({ BEFORE_CELL_EDIT: Go2, AFTER_CELL_EDIT: qn, AFTER_CELL_EDIT_ASYNC: Zn })); this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((t) => { this._interceptWorkbook(t); })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).subscribe( (t) => this._disposeWorkbookInterceptor(t) )), this.intercept(et.CELL_CONTENT, { priority: -1, effect: Vn.Style | Vn.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(Go2, { 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(Ze(() => cs(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(Ze(() => cs(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(Ze(() => cs(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(Ze(() => cs(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: re.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}-${Vn.Style | Vn.Value}`, r ); const i = Vn.Style | Vn.Value; this._interceptorsByName.set( `${o}-${Vn.Style}`, r.filter((a) => ((a.effect || i) & Vn.Style) > 0) ), this._interceptorsByName.set( `${o}-${Vn.Value}`, r.filter((a) => ((a.effect || i) & Vn.Value) > 0) ); } else this._interceptorsByName.set( o, r ); return this._interceptorsDirty = true, this.disposeWithMe(Ze(() => cs(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 = x_(u || []), this._composedInterceptorByKey.set(i, a); } return a; } _interceptWorkbook(e) { const t = new Mi(), o = e.getUnitId(), s = this, r = (i) => { const a = i.getSheetId(); i.__interceptViewModel((u) => { const l = new Mi(); s._worksheetDisposables.set(zo(o, i), l), l.add(u.registerCellContentInterceptor({ getCell(c, d, h, m, g2) { const f = i.getCellRaw(c, d); return s.fetchThroughInterceptors(et.CELL_CONTENT, h, m, g2)( 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)( false, { 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(Ze(() => 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([ sa2(0, _n) ], V); function zo(n, e) { return `${n}|${e.getSheetId()}`; } var 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; } var ce = { wholeStyle: 1, headerRowStyle: 2, headerColumnStyle: 4, firstRowStyle: 8, secondRowStyle: 16, lastRowStyle: 32, firstColumnStyle: 128, secondColumnStyle: 256, lastColumnStyle: 512 }; var yt = class { /** * @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"); R(this, "wholeStyle", null); R(this, "headerRowStyle", null); R(this, "headerColumnStyle", null); R(this, "firstRowStyle", null); R(this, "secondRowStyle", null); R(this, "lastRowStyle", null); R(this, "firstColumnStyle", null); R(this, "secondColumnStyle", null); R(this, "lastColumnStyle", null); 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(); } }; var 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 } } }); var 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 } } }); var ua = (n, e, t, o) => new yt(`dark-${n}`, { headerRowStyle: { bg: { rgb: e }, cl: { rgb: "rgb(255, 255, 255)" }, ht: Xt.CENTER, bl: we.TRUE }, firstRowStyle: { bg: { rgb: t } }, secondRowStyle: { bg: { rgb: o } }, lastRowStyle: { bg: { rgb: e } } }); var 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)" } ]; var ca2 = [ { 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)" } ]; var 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)" } ]; var ha = la.map(({ baseName: n, header: e, color: t }) => ia(n, e, t)); var ma = ca2.map(({ baseName: n, rowHeader: e, colHeader: t }) => aa(n, e, t)); var ga = da.map(({ baseName: n, rowHeader: e, firstRow: t, secondRow: o }) => ua(n, e, t, o)); var fa = [ ...ha, ...ma, ...ga ]; var Ra2 = { headerRowStyle: { bg: { rgb: "rgb(68,114,196)" }, cl: { rgb: "rgb(255,255,255)" }, ht: Xt.CENTER, bl: we.TRUE }, firstRowStyle: { bg: { rgb: "rgb(217,225,242)" } }, lastRowStyle: { bd: { t: { s: Xe.THIN, cl: { rgb: "rgb(68,114,196)" } } }, ht: Xt.CENTER, bl: we.TRUE } }; var pa = new yt("default", Ra2); var Ca = Object.defineProperty; var Sa = Object.getOwnPropertyDescriptor; var 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; }; var Ko2 = (n, e) => (t, o) => e(t, o, n); var Ia = "SHEET_RANGE_THEME_MODEL_PLUGIN"; var He = class extends nt { 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 $R()), 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 = qt(), 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: Vn.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: [Fe.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([ Ko2(0, ot(V)), Ko2(1, ot(Bi)) ], He); function va(n, e) { const { unitId: t } = e, o = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(Fe.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(Fe.UNIVER_SHEET); if (!s) return null; const r = o ? s.getSheetBySheetId(o) : s.getActiveSheet(true); 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; } var zt = { id: "sheet.mutation.set-worksheet-range-theme-style", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(_n), a = N(i), u = n.get(He); return a ? (u.registerRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), true) : false; } }; var Ma = (n, e) => { const t = Et(n.get(_n), 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 }; }; var Kt = { id: "sheet.mutation.remove-worksheet-range-theme-style", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(_n), a = N(i), u = n.get(He); return a ? (u.removeRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), true) : false; } }; var _a = (n, e) => { const t = Et(n.get(_n), 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 }; }; var ba = { type: ar.COMMAND, id: "sheet.command.set-worksheet-range-theme-style", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), { 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 }] }), true) : false; } }; var 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); }, {} ); var Ea = (n = 0) => { let e = n; return function() { return e++; }; }; function Os(n) { const e = new kt(); 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 kt(); 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 kt(); 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 = ((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 || {}); var Ta = class extends nt { constructor(t) { super(); R(this, "_worksheetSelections", /* @__PURE__ */ new Map()); R(this, "_selectionMoveStart$", new Subject()); R(this, "selectionMoveStart$", this._selectionMoveStart$.asObservable()); R(this, "_selectionMoving$", new Subject()); R(this, "selectionMoving$", this._selectionMoving$.asObservable()); R(this, "_selectionMoveEnd$", new BehaviorSubject([])); R(this, "selectionMoveEnd$", this._selectionMoveEnd$.asObservable()); R(this, "_selectionSet$", new BehaviorSubject([])); R(this, "selectionSet$", this._selectionSet$.asObservable()); R(this, "selectionChanged$"); R(this, "_beforeSelectionMoveEnd$", new BehaviorSubject([])); R(this, "beforeSelectionMoveEnd$", this._beforeSelectionMoveEnd$.asObservable()); this._workbook = t, this.selectionChanged$ = merge(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; var Na = Object.getOwnPropertyDescriptor; var 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; }; var Da = (n, e) => (t, o) => e(t, o, n); var F = class extends J0 { constructor(e) { super(); R(this, "selectionMoveStart$"); R(this, "selectionMoving$"); R(this, "selectionMoveEnd$"); R(this, "selectionSet$"); R(this, "selectionChanged$"); R(this, "_workbookSelections", /* @__PURE__ */ new Map()); this._instanceSrv = e, this._init(); } get _currentSelectionPos() { const e = this._instanceSrv.getCurrentUnitForType(Fe.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$(Fe.UNIVER_SHEET).pipe(shareReplay(1), takeUntil(this.dispose$)); this.selectionMoveStart$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveStart$ : of())), this.selectionMoving$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoving$ : of())), this.selectionMoveEnd$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveEnd$ : of([]))), this.selectionSet$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionSet$ : of([]))), this.selectionChanged$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionChanged$ : of([]))).pipe( distinctUntilChanged((t, o) => t.length !== o.length ? false : t.length === 0 && o.length === 0 ? true : t.every((s, r) => JSON.stringify(s) === JSON.stringify(o[r]))), skip(1) ), this._instanceSrv.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).pipe(takeUntil(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 ? false : e.some( ({ range: t }, o) => e.some(({ range: s }, r) => o === r ? false : 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, _n) ], F); var jd = "DISABLE_NORMAL_SELECTIONS"; var Gd = "SELECTIONS_ENABLED"; var 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 && (re.removeNull(s), Object.entries(s).forEach(([a, u]) => { typeof u == "object" && u !== null && Object.keys(u).length === 0 && delete s[a]; })), re.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 = false) { if (e === null) return e; if (e === void 0) return n; const o = re.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, true); m && re.removeNull(m), re.isEmptyObject(m) || (h.ts = m), o.push(h); } const d = gn(c, e, true); d && re.removeNull(d), re.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, true); u && re.removeNull(u), re.isEmptyObject(u) || (a.ts = u), o.push(a); } n.body.textRuns = _s(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 === dn.FORCE_STRING) { if (!Qn(s) && e.v !== void 0) { if (DC(e.v)) return dn.NUMBER; if (L0(`${e.v}`)) return dn.BOOLEAN; } return dn.FORCE_STRING; } return Ha(o) ? Qn(o) ? dn.STRING : Jo(e, t) : Qn(s) ? dn.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) === T; } function Yo(n, e) { return n === null ? null : typeof n == "string" ? DC(n) ? (+n == 0 || +n == 1) && e === dn.BOOLEAN ? dn.BOOLEAN : dn.NUMBER : L0(n) ? dn.BOOLEAN : dn.STRING : typeof n == "number" ? (n === 0 || n === 1) && e === dn.BOOLEAN ? dn.BOOLEAN : dn.NUMBER : typeof n == "boolean" ? dn.BOOLEAN : dn.FORCE_STRING; } function Xo(n, e) { return n === dn.NUMBER ? Number(e.v) : n === dn.BOOLEAN ? Ba(e.v) ? 1 : 0 : n === dn.STRING || n === dn.FORCE_STRING ? `${e.v}` : e.v; } function Ba(n) { if (typeof n == "string") { if (n.toUpperCase() === "TRUE") return true; if (n.toUpperCase() === "FALSE") return false; if (bR(n)) { if (Number(n) === 0) return false; if (Number(n) === 1) return true; } } if (typeof n == "number") { if (n === 0) return false; if (n === 1) return true; } 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); } var Ae = (n, e) => { const { unitId: t, subUnitId: o, cellValue: s } = e, i = n.get(_n).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 kt(); return new kt(s).forValue((h, m, g2) => { const f = re.deepClone(u == null ? void 0 : u.getValue(h, m)) || {}, p = l.getStyleByCell(f), C = l.getStyleByCell(g2); f.s = $a(p, C), c.setValue(h, m, Fa(f)); }), { ...e, options: {}, cellValue: c.getMatrix() }; }; var Q = { id: "sheet.mutation.set-range-values", type: ar.MUTATION, handler: (n, e) => { const { cellValue: t, subUnitId: o, unitId: s } = e, i = n.get(_n).getUnit(s); if (!i) return false; const a = i.getSheetBySheetId(o); if (!a) return false; const u = a.getCellMatrix(), l = i.getStyles(); return new kt(t).forValue((d, h, m) => { if (!m) u == null || u.setValue(d, h, {}); else { const g2 = u.getValue(d, h) || {}, f = Va(l, m, g2); m.f !== void 0 && (g2.f = m.f), m.si !== void 0 && (g2.si = m.si), m.p !== void 0 && (g2.p = m.p), m.v !== void 0 && (g2.v = Xo(f, m)), g2.v !== void 0 && (g2.t = f, g2.v = Xo(f, g2)), m.s !== void 0 && xa(l, g2, m), m.custom !== void 0 && (g2.custom = m.custom), u.setValue(d, h, re.removeNull(g2)); } }), true; } }; var po = { id: "sheet.command.clear-selection-all", type: ar.COMMAND, handler: (n, e) => { var S; const t = n.get(_n), o = n.get(Pt), s = n.get(F), r = n.get(cn), i = n.get(V), a = t.getCurrentUnitForType(Fe.UNIVER_SHEET); if (!a) return false; const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet(); if (!l) return false; 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 false; const h = [], m = [], g2 = { subUnitId: c, unitId: u, cellValue: Os(d) }, f = Ae( n, g2 ); h.push({ id: Q.id, params: g2 }), m.push({ id: Q.id, params: f }); const p = i.onCommandExecute({ id: po.id }); return h.push(...p.redos), m.unshift(...p.undos), mu(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 }), true) : false; } }; var Co = { id: "sheet.command.clear-selection-content", type: ar.COMMAND, handler: (n, e) => { var S; const t = n.get(_n), o = n.get(Pt), s = n.get(F), r = n.get(cn), i = n.get(V), a = t.getCurrentUnitForType(Fe.UNIVER_SHEET); if (!a) return false; const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet(); if (!l) return false; 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 false; const h = { subUnitId: c, unitId: u, cellValue: Ua(d) }, m = Ae( n, h ), g2 = i.onCommandExecute({ id: Co.id }), f = [{ id: Q.id, params: h }, ...g2.redos], p = [...g2.undos, { id: Q.id, params: m }]; return mu(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 }), true) : false; } }; var So = { id: "sheet.command.clear-selection-format", type: ar.COMMAND, handler: (n, e) => { var S; const t = n.get(_n), o = n.get(Pt), s = n.get(F), r = n.get(cn), i = n.get(V), a = t.getCurrentUnitForType(Fe.UNIVER_SHEET); if (!a) return false; const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet(); if (!l) return false; 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 false; const h = [], m = [], g2 = { subUnitId: c, unitId: u, cellValue: Pa(d) }, f = Ae( n, g2 ); h.push({ id: Q.id, params: g2 }), m.push({ id: Q.id, params: f }); const p = i.onCommandExecute({ id: So.id }); return h.push(...p.redos), m.unshift(...p.undos), mu(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 }), true) : false; } }; var As = (n, e) => ({ subUnitId: e.sheet.id, unitId: e.unitId, subUnitName: e.sheet.name }); var Jt = { id: "sheet.mutation.insert-sheet", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n), { sheet: o, index: s, unitId: r } = e, i = t.getUniverSheetInstance(r); return i ? i.addWorksheet(o.id, s, o) : false; } }; var ja = (n, e) => { const t = n.get(_n), { 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 }; }; var Ut = { id: "sheet.mutation.remove-sheet", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n), { subUnitId: o, unitId: s } = e, r = t.getUniverSheetInstance(s); return r ? r.removeSheet(o) : false; } }; var xs = { type: ar.COMMAND, id: "sheet.command.copy-sheet", handler: (n, e) => { var w, b; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), i = n.get(Vr), a = N(s, e); if (!a) return false; const { workbook: u, worksheet: l, unitId: c, subUnitId: d } = a, h = re.deepClone(l.getConfig()); h.name = Ga(u, i, h.name), h.id = re.generateRandomId(); const g2 = { index: u.getSheetIndex(l) + 1, sheet: h, unitId: c }, f = As( n, g2 ), p = r.onCommandExecute({ id: xs.id, params: { unitId: c, subUnitId: d, targetSubUnitId: h.id } }), C = [ ...(w = p.preRedos) != null ? w : [], { id: Jt.id, params: g2 }, ...p.redos ], S = [ ...(b = p.preUndos) != null ? b : [], { id: Ut.id, params: f }, ...p.undos ]; return mu(C, t).result ? (o.pushUndoRedo({ unitID: c, undoMutations: S, redoMutations: C }), true) : false; } }; 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; } var dt = { id: "sheet.mutation.move-range", type: ar.MUTATION, handler: (n, e) => { const { from: t, to: o } = e; if (!t || !o) return false; const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET); if (!r) return false; const i = r.getSheetBySheetId(e.from.subUnitId), a = r.getSheetBySheetId(e.to.subUnitId); if (!i || !a) return false; const u = i.getCellMatrix(), l = a.getCellMatrix(); return new kt(t.value).forValue((c, d, h) => { u.setValue(c, d, h); }), new kt(o.value).forValue((c, d, h) => { l.setValue(c, d, h); }), true; } }; var za = Object.defineProperty; var Ka = Object.getOwnPropertyDescriptor; var 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; }; var Ya = (n, e) => (t, o) => e(t, o, n); var Xa = Ct("sheets-formula.ref-selections.service"); var qo = class extends F { constructor(n) { super(n); } _init() { const n = this._getAliveWorkbooks$().pipe(takeUntil(this.dispose$)); this.selectionMoveStart$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionMoveStart$)))), this.selectionMoving$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionMoving$)))), this.selectionMoveEnd$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionMoveEnd$)))), this.selectionSet$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionSet$)))); } _getAliveWorkbooks$() { const n = this._instanceSrv.getAllUnitsForType(Fe.UNIVER_SHEET); n.forEach((t) => this._ensureWorkbookSelection(t.getUnitId())); const e = new BehaviorSubject(n); return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((t) => { this._ensureWorkbookSelection(t.getUnitId()), e.next([...e.getValue(), t]); })), this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).subscribe((t) => { this._removeWorkbookSelection(t.getUnitId()), e.next(e.getValue().filter((o) => o !== t)); })), e.pipe(map((t) => t.map((o) => this._ensureWorkbookSelection(o.getUnitId())))); } }; qo = Ja([ Ya(0, _n) ], qo); function qa(n, e) { const o = n.get(fs).getContextValue(Aa); return n.get(o && !e ? Xa : F); } var re2 = { id: "sheet.operation.set-selections", type: ar.OPERATION, handler: (n, e) => { if (!e) return false; const { selections: t, type: o, unitId: s, subUnitId: r } = e; return qa(n).setSelections(s, r, [...t], o), true; } }; function Ln(n, e, t = true) { const o = e.getMatrixWithMergedCells(..._C(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 }; en.contains(n, l) || s.push(l); } }), s.length === 0) return n; const r = en.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: De.NORMAL }, false)), o || { actualColumn: e, actualRow: n, startRow: n, startColumn: e, endRow: n, endColumn: e, isMerged: false, isMergedMainCell: false, rangeType: De.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: De.NORMAL, isMerged: true, isMergedMainCell: true } : { startRow: t, startColumn: o, endRow: n.startRow, endColumn: n.startColumn, actualRow: t, actualColumn: o, rangeType: De.NORMAL, isMerged: false, isMergedMainCell: false }; } var Xe2 = (n, e, t) => ({ id: re2.id, params: { unitId: e.getUnitId(), subUnitId: t.getSheetId(), reveal: true, selections: [{ range: n, primary: ve(n, t) }] } }); function Jd(n) { if (!n) return false; const { range: e, primary: t } = n; return en.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 }; } var Zo = (n) => n.id !== Ns; function Vn2(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; } var $s = "sheet.command.move-range"; var pt = { type: ar.COMMAND, id: $s, handler: async (n, e) => { var I, w; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(NE), i = n.get(Vr), a = n.get(V), u = N(s); if (!u || !await a.beforeCommandExecute({ id: pt.id, params: e })) return false; const { worksheet: c, subUnitId: d, unitId: h } = u, m = wo2( 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")), false; const g2 = a.onCommandExecute({ id: pt.id, params: { ...e } }), f = [ ...(I = g2.preRedos) != null ? I : [], ...m.redos, ...g2.redos, { id: re2.id, params: { unitId: h, subUnitId: d, selections: [{ range: e.toRange, primary: Qa(e.fromRange, e.toRange, c) }], type: Ce.MOVE_END } } ], p = [ ...(w = g2.preUndos) != null ? w : [], ...m.undos, ...g2.undos, { id: re2.id, params: { unitId: h, subUnitId: d, selections: [{ range: e.fromRange, primary: ve(e.fromRange, c) }], type: Ce.MOVE_END } } ], C = mu(f, t).result, S = a.afterCommandExecute({ id: pt.id, params: { ...e } }); return C ? (mu(S.redos, t), o.pushUndoRedo({ unitID: h, undoMutations: [...p, ...S.undos], redoMutations: [...f, ...S.redos] }), true) : false; } }; function wo2(n, e, t, o = false) { const s = [], r = [], { range: i, subUnitId: a, unitId: u } = e, { range: l, subUnitId: c } = t, h = n.get(_n).getUniverSheetInstance(u), m = h == null ? void 0 : h.getSheetBySheetId(c), g2 = h == null ? void 0 : h.getSheetBySheetId(a), f = m == null ? void 0 : m.getCellMatrix(), p = g2 == null ? void 0 : g2.getCellMatrix(); if (m && g2 && f && p) { const C = Ln(l, m, false); if (!en.equals(l, C) && !o) return null; const S = new kt(), I = new kt(), w = new kt(); tr.foreach(i, (U, P) => { const A = p.getValue(U, P); if (S.setValue(U, P, re.deepClone(A)), A) { const j = h == null ? void 0 : h.getStyles().get(A.s); w.setValue(U, P, re.deepClone(j)); } I.setValue(U, P, null); }); const b = new kt(), y = new kt(); tr.foreach(l, (U, P) => { b.setValue(U, P, re.deepClone(f.getValue(U, P))); }), tr.foreach(i, (U, P) => { const A = AC(U, P), j = en.getRelativeRange(A, i), Z = en.getPositionRange(j, l), Y = re.deepClone(w.getValue(U, P)), ee = re.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 }, T2 = { 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: T2 }); } 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 = false, i.isMergedMainCell = true; } return i; } var Sn = ((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 || {}); var _ = ((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))(_ || {}); var D = ((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 || {}); var Pe = class { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.Edit); R(this, "status", fl.INIT); R(this, "value", true); 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}`; } }; var Io = class { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.View); R(this, "status", fl.INIT); R(this, "value", true); 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}`; } }; var Ws = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Comment); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Comment}_${e}`; } }; var Ls = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Copy); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Copy}_${e}`; } }; var eu = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "subType", _.CopySheet); R(this, "status", fl.INIT); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CopySheet}_${e}`; } }; var Vs2 = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.CreatePermissionObject); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreatePermissionObject}_${e}`; } }; var Hs = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.CreateSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreateSheet}_${e}`; } }; var Bs = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.DeleteSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.DeleteSheet}_${e}`; } }; var Fs = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Duplicate); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Duplicate}_${e}`; } }; var Me = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Edit); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Edit}_${e}`; } }; var js = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Export); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Export}_${e}`; } }; var vo = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.HideSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.HideSheet}_${e}`; } }; var tu = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.History); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.History}_${e}`; } }; var Mo = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.ManageCollaborator); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ManageCollaborator}_${e}`; } }; var _o = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.MoveSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.MoveSheet}_${e}`; } }; var Gs2 = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Print); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Print}_${e}`; } }; var zs = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.RecoverHistory); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RecoverHistory}_${e}`; } }; var bo = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.RenameSheet); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RenameSheet}_${e}`; } }; var Ks = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.Share); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Share}_${e}`; } }; var Js = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.View); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.View}_${e}`; } }; var Ys = class { constructor(e) { R(this, "id"); R(this, "value", true); R(this, "type", D.Workbook); R(this, "status", fl.INIT); R(this, "subType", _.ViewHistory); this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ViewHistory}_${e}`; } }; var Xs = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.Copy); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Copy}_${e}_${t}`; } }; var qs = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.DeleteColumn); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteColumn}_${e}_${t}`; } }; var Zs = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.Delete); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Delete}_${e}_${t}`; } }; var Qs = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.DeleteRow); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteRow}_${e}_${t}`; } }; var Te = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.Edit); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Edit}_${e}_${t}`; } }; var er = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.EditExtraObject); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.EditExtraObject}_${e}_${t}`; } }; var tr2 = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.Filter); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Filter}_${e}_${t}`; } }; var nr = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.InsertColumn); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertColumn}_${e}_${t}`; } }; var or = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.InsertHyperlink); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertHyperlink}_${e}_${t}`; } }; var sr = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.InsertRow); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertRow}_${e}_${t}`; } }; var rr2 = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.ManageCollaborator); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.ManageCollaborator}_${e}_${t}`; } }; var ir = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.PivotTable); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.PivotTable}_${e}_${t}`; } }; var nu2 = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.SelectProtectedCells); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectProtectedCells}_${e}_${t}`; } }; var ou = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.SelectUnProtectedCells); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`; } }; var ar2 = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.SetCellStyle); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellStyle}_${e}_${t}`; } }; var wn = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.SetCellValue); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellValue}_${e}_${t}`; } }; var $t = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.SetColumnStyle); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetColumnStyle}_${e}_${t}`; } }; var Wt = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.SetRowStyle); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetRowStyle}_${e}_${t}`; } }; var ur = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.Sort); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Sort}_${e}_${t}`; } }; var Hn = class { constructor(e, t) { R(this, "value", true); R(this, "type", D.Worksheet); R(this, "status", fl.INIT); R(this, "id"); R(this, "subType", _.View); this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.View}_${e}_${t}`; } }; var on = { id: "sheet.command.set-range-values", type: ar.COMMAND, handler: (n, e) => { var T2; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = n.get(UE), u = N(s, e); if (!u) return false; const { subUnitId: l, unitId: c, workbook: d, worksheet: h } = u, { value: m, range: g2 } = e, f = g2 ? [g2] : (T2 = r.getCurrentSelections()) == null ? void 0 : T2.map((U) => U.range); if (!f || !f.length || !a.getPermissionPoint(new Te(c, l).id)) return false; const p = new kt(); let C; if (re.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 (fC(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 false; const { undos: b, redos: y } = i.onCommandExecute({ id: on.id, params: { ...S, range: f } }); if (mu([...y], t).result) { const U = Xe2(g2 != null ? g2 : p.getRange(), d, h); return o.pushUndoRedo({ unitID: c, undoMutations: [ { id: Q.id, params: I }, ...b, U ], redoMutations: [ { id: Q.id, params: S }, ...y, re.deepClone(U) ] }), true; } return false; } }; function lr(n, e) { const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a, cellValue: u = {} } = e, l = n.get(_n), c = n.get(V), d = l.getUniverSheetInstance(s), h = d == null ? void 0 : d.getSheetBySheetId(r); if (h) { const m = h.getCellMatrix(), g2 = m.getDataRange(); if (i.startColumn <= g2.endColumn || i.startRow <= g2.endRow) { let I, w; if (a === yu.COLUMNS) { const y = Math.min(i.endRow, g2.endRow); let x = 0; for (let U = i.startRow; U <= y; U++) { const P = m.getRow(U), A = P ? fn(P) - 1 : 0; x = Math.max(x, A); } I = { startRow: i.startRow, startColumn: i.startColumn, endRow: y, endColumn: x }; const T2 = i.endColumn - i.startColumn + 1; w = { startRow: i.startRow, startColumn: I.startColumn + T2, endRow: y, endColumn: I.endColumn + T2 }; } else { const y = Math.min(i.endColumn, g2.endColumn), x = g2.endRow; I = { startRow: i.startRow, startColumn: i.startColumn, endRow: x, endColumn: y }; const T2 = i.endRow - i.startRow + 1; w = { startRow: I.startRow + T2, startColumn: i.startColumn, endRow: I.endRow + T2, endColumn: y }; } const b = wo2( n, { unitId: s, subUnitId: r, range: I }, { unitId: s, subUnitId: r, range: w }, true ); 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(_n), 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(), g2 = { subUnitId: r, unitId: s, cellValue: Os([i]) }, f = Ae( n, g2 ), p = l.onCommandExecute({ id: on.id, params: g2 }); if (t.push({ id: Q.id, params: g2 }, ...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 === yu.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), T2 = x ? fn(x) - 1 : 0; w = Math.max(w, T2); } 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 === yu.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 = wo2( n, { unitId: s, subUnitId: r, range: C }, { unitId: s, subUnitId: r, range: S }, true ); 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 === yu.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 === yu.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 === yu.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 === yu.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); } } var dr = "sheet.command.delete-range-move-left"; var Pt2 = { type: ar.COMMAND, id: dr, handler: async (n, e) => { var w, b, y; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = N(s); if (!a) return false; 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 false; const m = { range: h, subUnitId: c, unitId: d, shiftDimension: yu.COLUMNS }, g2 = i.onCommandExecute({ id: Pt2.id, params: { range: h } }), { redo: f, undo: p } = cr( n, m ), C = [...(b = g2.preRedos) != null ? b : [], ...f], S = [...g2.undos, ...p]; return C.push(...g2.redos), C.push(Xe2(h, l, u)), S.push(...(y = g2.preUndos) != null ? y : []), mu(C, t).result ? (o.pushUndoRedo({ unitID: d, undoMutations: S.reverse(), redoMutations: C }), true) : false; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }; var hr = "sheet.command.delete-range-move-up"; var Tt = { type: ar.COMMAND, id: hr, handler: async (n, e) => { var w, b, y; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = N(s); if (!a) return false; 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 false; const m = { range: h, subUnitId: l, unitId: u, shiftDimension: yu.ROWS }, g2 = i.onCommandExecute({ id: Tt.id, params: { range: h } }), { redo: f, undo: p } = cr( n, m ), C = [...(b = g2.preRedos) != null ? b : [], ...f], S = [...g2.undos, ...p]; return C.push(...g2.redos), C.push(Xe2(h, c, d)), S.push(...(y = g2.preUndos) != null ? y : []), mu(C, t).result ? (o.pushUndoRedo({ unitID: u, undoMutations: S.reverse(), redoMutations: C }), true) : false; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }; var su = { type: ar.COMMAND, id: "sheet.command.delete-range-protection", async handler(n, e) { if (!e) return false; const t = n.get(Pt), o = n.get(cn), { 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] } }] }), true; } }; var ru = { type: ar.COMMAND, id: "sheet.command.delete-worksheet-protection", handler(n, e) { if (!e) return false; const t = n.get(Pt), o = n.get(cn), { 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 }), true; } }; var iu = { type: ar.COMMAND, id: "sheet.command.remove-worksheet-range-theme-style", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), { 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 }] }), true) : false; } }; var au = { id: "sheet.command.insert-defined-name", type: ar.COMMAND, handler: (n, e) => { const t = n.get(Pt), o = n.get(cn); if (!e) return false; const s = { ...e }; return t.syncExecuteCommand(sa.id, s) ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: [{ id: Xi.id, params: s }], redoMutations: [{ id: sa.id, params: s }] }), true) : false; } }; var mr2 = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range }; }; var qe = { id: "sheet.mutation.insert-row", type: ar.MUTATION, handler: (n, e) => { var g2; const { unitId: t, subUnitId: o, range: s, rowInfo: r } = e, a = n.get(_n).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 ? Vo(f, (g2 = r[f - s.startRow]) != null ? g2 : c, l) : Vo(f, c, l); return u.setRowCount(u.getRowCount() + s.endRow - s.startRow + 1), u.getCellMatrix().insertRows(s.startRow, h), true; } }; var yo = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range }; }; var je = { id: "sheet.mutation.insert-col", type: ar.MUTATION, handler: (n, e) => { var g2; const o = n.get(_n).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return false; 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 ? Vo(f, (g2 = a[f - i.startColumn]) != null ? g2 : p, l) : Vo(f, p, l); } return s.setColumnCount(s.getColumnCount() + i.endColumn - i.startColumn + 1), s.getCellMatrix().insertColumns(i.startColumn, d), true; } }; var uu = (n, e) => { const s = e.getRowManager().getRowData(), r = {}, i = n.range, a = UC(i.startRow, i.endRow, s), u = LC(r, a); return { unitId: n.unitId, subUnitId: n.subUnitId, range: n.range, rowInfo: u }; }; var Be = { id: "sheet.mutation.remove-rows", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return false; 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 Go(r.startRow, u, a), s.getCellMatrix().removeRows(r.startRow, u), s.setRowCount(s.getRowCount() - u), true; } }; var lu = (n, e) => { const o = n.get(_n).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 = UC(l.startColumn, l.endColumn, a), d = LC(u, c); return { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, colInfo: d }; }; var De2 = { id: "sheet.mutation.remove-col", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return false; const r = e.range, a = s.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1; return Go(r.startColumn, u, a), s.setColumnCount(s.getColumnCount() - u), s.getCellMatrix().removeColumns(r.startColumn, u), true; } }; var cu = "sheet.command.insert-range-move-down"; var sn = { type: ar.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(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = n.get(NE), u = n.get(Vr); if (r.isOverlapping()) return a.emit(u.t("sheets.info.overlappingSelections")), false; const l = N(s); if (!l) return false; const { unitId: c, subUnitId: d, worksheet: h, workbook: m } = l; let g2 = e == null ? void 0 : e.range; if (g2 || (g2 = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g2) return false; const f = [], p = [], C = h.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(S.startRow, S.endRow, g2.startColumn, g2.endColumn).getDataRange().endRow, b = Math.max(w + (g2.endRow - g2.startRow + 1) - S.endRow, 0); if (b > 0) { const ee = g2.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: we.FALSE })) }; f.push({ id: qe.id, params: ie }); const xe = mr2( n, ie ); p.push({ id: Be.id, params: xe }); } const y = {}; tr.foreach(g2, (ee, Re) => { const ie = h.getCell(ee, Re); ie && (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s }); }); const x = { range: g2, subUnitId: d, unitId: c, shiftDimension: yu.ROWS, cellValue: y }, { redo: T2, undo: U } = lr( n, x ); f.push(...T2), p.push(...U); const P = i.onCommandExecute({ id: sn.id, params: { range: g2 } }); return f.push(...P.redos), f.push(Xe2(g2, m, h)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), mu(f, t) ? (o.pushUndoRedo({ unitID: c, undoMutations: p.reverse(), redoMutations: f }), true) : false; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }; var Eo = "sheet.command.insert-range-move-right"; var Bn = { type: ar.COMMAND, id: Eo, // eslint-disable-next-line max-lines-per-function handler: async (n, e) => { var j, Z, Y; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = n.get(NE), u = n.get(Vr); if (r.isOverlapping()) return a.emit(u.t("sheets.info.overlappingSelections")), false; const l = N(s); if (!l) return false; const { workbook: c, worksheet: d, unitId: h, subUnitId: m } = l; let g2 = e == null ? void 0 : e.range; if (g2 || (g2 = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g2) return false; const f = [], p = [], C = d.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(g2.startRow, g2.endRow, S.startColumn, S.endColumn).getDataRange().endColumn, b = Math.max( w + (g2.endColumn - g2.startColumn + 1) - S.endColumn, 0 ); if (b > 0) { const ee = g2.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: we.FALSE })) }; f.push({ id: je.id, params: ie }); const xe = yo( n, ie ); p.push({ id: De2.id, params: xe }); } const y = {}; tr.foreach(g2, (ee, Re) => { const ie = d.getCell(ee, Re); !ie || !ie.s || (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s }); }); const x = { range: g2, subUnitId: m, unitId: h, shiftDimension: yu.COLUMNS, cellValue: y }, { redo: T2, undo: U } = lr( n, x ); f.push(...T2), p.push(...U); const P = i.onCommandExecute({ id: Bn.id, params: { range: g2 } }); return f.push(...P.redos), f.push(Xe2(g2, c, d)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), mu(f, t).result ? (o.pushUndoRedo({ unitID: h, undoMutations: p.reverse(), redoMutations: f }), true) : false; } // all subsequent mutations should succeed inorder to make the whole process succeed // Promise.all([]).then(() => true), }; var gr = "sheet.command.insert-row"; var mt = { type: ar.COMMAND, id: gr, handler: async (n, e) => { const t = n.get(Pt), 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 }) : false; } }; var fr = { type: ar.COMMAND, id: "sheet.command.insert-row-by-range", handler: (n, e) => { var T2, U, P, A; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), i = N(s, e); if (!i) return false; const { workbook: a, worksheet: u } = i, { range: l, direction: c, unitId: d, subUnitId: h, cellValue: m } = e, { startRow: g2, endRow: f } = l; l.rangeType = De.ROW; const p = c === wu.UP ? g2 : g2 - 1, C = u.getRowHeight(p), S = { unitId: d, subUnitId: h, range: l, rowInfo: new Array(f - g2 + 1).fill(void 0).map(() => ({ h: C, hd: we.FALSE })) // row height should inherit from the anchor row }, I = mr2( 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(...(T2 = y.preRedos) != null ? T2 : []), w.push(...(U = y.redos) != null ? U : []), w.push(Xe2(l, a, u)), b.unshift(...(P = y.preUndos) != null ? P : []), b.push(...(A = y.undos) != null ? A : []), mu(w, t).result ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: b, redoMutations: w }), true) : false; } }; var du = { type: ar.COMMAND, id: "sheet.command.insert-row-before", handler: async (n) => { var g2; const t = (g2 = n.get(F).getCurrentSelections()) == null ? void 0 : g2.map((f) => f.range); let o; if ((t == null ? void 0 : t.length) === 1) o = t[0]; else return false; const s = n.get(_n), r = N(s); if (!r) return false; 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: wu.UP, range: { startRow: l, endRow: c, startColumn: d, endColumn: h }, // copy styles from the row above cellValue: Vn2(i, l, c, d, h, true, l - 1) }; return n.get(Pt).executeCommand(mt.id, m); } }; var hu = { type: ar.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 false; const s = n.get(_n), r = N(s); if (!r) return false; 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, g2 = { unitId: a, subUnitId: u, direction: wu.DOWN, range: { startRow: c, endRow: d, startColumn: h, endColumn: m, rangeType: De.ROW }, // copy styles from the row below cellValue: Vn2(i, c, d, h, m, true, o.endRow) }; return n.get(Pt).executeCommand(mt.id, g2); } }; var Rr = "sheet.command.insert-col"; var gt = { type: ar.COMMAND, id: Rr, handler: async (n, e) => { const t = n.get(Pt), 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(pr2.id, { range: s, direction: r, unitId: a, subUnitId: i, cellValue: u }) : false; } }; var pr2 = { type: ar.COMMAND, id: "sheet.command.insert-col-by-range", handler: (n, e) => { var x, T2, U, P; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), { range: i, direction: a, subUnitId: u, unitId: l, cellValue: c } = e, { startColumn: d, endColumn: h } = e.range; i.rangeType = De.COLUMN; const m = s.getUniverSheetInstance(e.unitId), g2 = m.getSheetBySheetId(e.subUnitId), f = a === wu.LEFT ? d : d - 1, p = g2.getColumnWidth(f), C = { unitId: l, subUnitId: u, range: i, colInfo: new Array(h - d + 1).fill(void 0).map(() => ({ w: p, hd: we.FALSE })) }, S = yo( n, C ), I = [{ id: je.id, params: C }], w = [{ id: De2.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(...(T2 = b.redos) != null ? T2 : []), I.push(Xe2(i, m, g2)), w.unshift(...(U = b.preUndos) != null ? U : []), w.push(...(P = b.undos) != null ? P : []), mu(I, t).result ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: w.filter(Boolean), redoMutations: I.filter(Boolean) }), true) : false; } }; var mu2 = { type: ar.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 false; const s = n.get(_n), r = N(s); if (!r) return false; 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: wu.LEFT, range: { startColumn: l, endColumn: c, startRow: d, endRow: h, rangeType: De.COLUMN }, // copy styles from the column before cellValue: Vn2(i, d, h, l, c, false, l - 1) }; return n.get(Pt).executeCommand(gt.id, m); } }; var gu = { type: ar.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 false; const s = n.get(_n), r = N(s); if (!r) return false; 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, g2 = { unitId: a, subUnitId: u, direction: wu.RIGHT, range: { startColumn: c, endColumn: d, startRow: h, endRow: m }, // copy styles from the column after cellValue: Vn2(i, h, m, c, d, false, o.endColumn) }; return n.get(Pt).executeCommand(gt.id, g2); } }; var fu = { id: "sheet.command.insert-sheet", type: ar.COMMAND, handler: (n, e) => { var p; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(Vr), i = va(s, { unitId: e == null ? void 0 : e.unitId }); if (!i) return false; 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 = Q_(c || {}); e ? (l = (p = e.index) != null ? p : l, h.id = d || re.generateRandomId(), h.name = (c == null ? void 0 : c.name) || u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)) : (h.id = re.generateRandomId(), h.name = u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)); const m = { index: l, sheet: h, unitId: a }, g2 = As( n, m ); return t.syncExecuteCommand(Jt.id, m) ? (o.pushUndoRedo({ unitID: a, undoMutations: [{ id: Ut.id, params: g2 }], redoMutations: [{ id: Jt.id, params: m }] }), true) : false; } }; 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: en.clone(r), targetRange: { ...s, endRow: s.endRow + a, startRow: s.startRow + a } } : { unitId: t, subUnitId: o, targetRange: en.clone(s), sourceRange: { ...r, endRow: r.endRow - a, startRow: r.startRow - a } }; } var ot2 = { id: "sheet.mutation.move-rows", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(_n).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 Ko(l, c, d, h), u.getCellMatrix().moveRows(l, c, d), true; } }; 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: en.clone(r), targetRange: { ...s, endColumn: s.endColumn + a, startColumn: s.startColumn + a } } : { unitId: t, subUnitId: o, targetRange: en.clone(s), sourceRange: { ...r, startColumn: r.startColumn - a, endColumn: r.endColumn - a } }; } var st2 = { id: "sheet.mutation.move-columns", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(_n).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 Ko(l, c, d, h), u.getCellMatrix().moveColumns(l, c, d), true; } }; 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); } var Cr = "sheet.command.move-rows"; var Fn = { id: Cr, type: ar.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 === De.ROW && Y.range.startRow <= o && o <= Y.range.endRow ); if ((a == null ? void 0 : a.length) !== 1) return false; const u = n.get(V), l = n.get(_n), c = N(l, e); if (!c) return false; const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g2 = h.getSheetId(), f = n.get(NE), p = n.get(Vr), C = a[0].range, S = a[0].primary, I = Ln(C, h, false); if (!en.equals(C, I)) return f.emit(p.t("sheets.info.partOfCell")), false; if (Cu(s, h)) return f.emit(p.t("sheets.info.acrossMergedCell")), false; const w = { ...C, startRow: s, endRow: s + C.endRow - C.startRow }, b = { unitId: m, subUnitId: g2, sourceRange: C, targetRange: w }, y = Ru(n, b), x = n.get(Pt), T2 = u.onCommandExecute({ id: Fn.id, params: e }), U = [ ...(j = T2.preRedos) != null ? j : [], { id: ot2.id, params: b } ], P = [ ...(Z = T2.preUndos) != null ? Z : [], { id: ot2.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: g2, type: Ce.MOVE_END, selections: [{ range: ie, primary: ve(ie, h), style: null }] }, ft = { unitId: m, subUnitId: g2, type: Ce.MOVE_END, selections: [{ range: C, primary: S, style: null }] }; U.push({ id: re2.id, params: xe }), P.push({ id: re2.id, params: ft }); } return U.push(...T2.redos), P.push(...T2.undos), mu(U, x).result ? (n.get(cn).pushUndoRedo({ unitID: m, undoMutations: P, redoMutations: U }), true) : false; } }; var Sr = "sheet.command.move-cols"; var jn = { id: Sr, type: ar.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 === De.COLUMN && Y.range.startColumn <= o && o <= Y.range.endColumn ); if ((a == null ? void 0 : a.length) !== 1) return false; const u = n.get(V), l = n.get(_n), c = N(l, e); if (!c) return false; const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g2 = h.getSheetId(), f = n.get(NE), p = n.get(Vr), C = a[0].range, S = a[0].primary, I = Ln(C, h, false); if (!en.equals(C, I)) return f.emit(p.t("sheets.info.partOfCell")), false; if (Su(s, h)) return f.emit(p.t("sheets.info.acrossMergedCell")), false; const w = { ...C, startColumn: s, endColumn: s + C.endColumn - C.startColumn }, b = { unitId: m, subUnitId: g2, sourceRange: C, targetRange: w }, y = pu(n, b), x = n.get(Pt), T2 = u.onCommandExecute({ id: jn.id, params: e }), U = [ ...(j = T2.preRedos) != null ? j : [], { id: st2.id, params: b } ], P = [ ...(Z = T2.preUndos) != null ? Z : [], { id: st2.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: g2, type: Ce.MOVE_END, selections: [{ range: ie, primary: ve(ie, h), style: null }] }, ft = { unitId: m, subUnitId: g2, type: Ce.MOVE_END, selections: [{ range: C, primary: S, style: null }] }; U.push({ id: re2.id, params: xe }), P.push({ id: re2.id, params: ft }); } return U.push(...T2.redos), P.push(...T2.undos), mu(U, x).result && n.get(cn).pushUndoRedo({ unitID: m, undoMutations: P, redoMutations: U }), true; } }; function wr(n) { return { range: n, primary: null, style: null }; } var Yt = { id: "sheet.mutation.register-worksheet-range-theme-style", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, rangeThemeStyleJson: o, themeName: s } = e, r = n.get(_n), i = N(r), a = n.get(He); if (!i) return false; const u = new yt(s, o); return a.registerRangeThemeStyle(t, u), true; } }; var Uo = { id: "sheet.mutation.unregister-worksheet-range-theme-style", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, themeName: o } = e, s = n.get(_n), r = N(s), i = n.get(He); return r ? (i.unregisterRangeThemeStyle(t, o), true) : false; } }; var wu2 = { id: "sheet.command.register-worksheet-range-theme-style", type: ar.COMMAND, handler: (n, e) => { if (!e) return false; const { unitId: t, rangeThemeStyle: o } = e, s = n.get(_n), r = n.get(Pt), i = n.get(cn); if (!N(s)) return false; 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 }] }), true; } }; var Ir = { id: "sheet.command.remove-defined-name", type: ar.COMMAND, handler: (n, e) => { var c, d; const t = n.get(Pt), o = n.get(cn), s = n.get(V); if (!e) return false; const r = { ...e }, i = s.onCommandExecute({ id: Ir.id, params: e }), a = [ ...(c = i.preRedos) != null ? c : [], { id: Xi.id, params: r }, ...i.redos ], u = [ ...(d = i.preUndos) != null ? d : [], { id: sa.id, params: r }, ...i.undos ]; return mu(a, t) ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: u.filter(Boolean), redoMutations: a.filter(Boolean) }), true) : false; } }; var Po = "sheet.command.remove-row"; var vr = { type: ar.COMMAND, id: "sheet.command.remove-row-by-range", handler: (n, e) => { var C, S, I; if (!e) return false; const t = n.get(_n), o = N(t, e); if (!o) return false; 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() }, g2 = i.onCommandExecute({ id: Po, params: { range: a } }), f = n.get(Pt); return mu( [ ...(C = g2.preRedos) != null ? C : [], { id: Be.id, params: c }, ...g2.redos, Xe2(a, s, r) ], f ).result ? (n.get(cn).pushUndoRedo({ unitID: u, undoMutations: [ ...(S = g2.preUndos) != null ? S : [], { id: qe.id, params: d }, { id: Q.id, params: m }, ...g2.undos ], redoMutations: [ ...(I = g2.preRedos) != null ? I : [], { id: Be.id, params: c }, ...g2.redos ] }), true) : false; } }; var Gn = { type: ar.COMMAND, id: Po, handler: async (n, e) => { var h; const t = n.get(F), o = n.get(V), s = n.get(Pt); let r = e == null ? void 0 : e.range; if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return false; const i = n.get(_n), a = N(i); if (!a) return false; 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 }) : false; } }; var To = "sheet.command.remove-col"; var Mr = { type: ar.COMMAND, id: "sheet.command.remove-col-by-range", handler: (n, e) => { var C, S, I; if (!e) return false; const t = n.get(_n), o = N(t, e); if (!o) return false; 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() }, g2 = i.onCommandExecute({ id: To, params: { range: a } }), f = n.get(Pt); return mu( [ ...(C = g2.preRedos) != null ? C : [], { id: De2.id, params: c }, ...g2.redos, Xe2(a, s, r) ], f ).result ? (n.get(cn).pushUndoRedo({ unitID: u, undoMutations: [ ...(S = g2.preUndos) != null ? S : [], { id: je.id, params: d }, { id: Q.id, params: m }, ...g2.undos ], redoMutations: [ ...(I = g2.preRedos) != null ? I : [], { id: De2.id, params: c }, ...g2.redos ] }), true) : false; } }; var zn2 = { type: ar.COMMAND, id: To, handler: async (n, e) => { var h; const t = n.get(F), o = n.get(V), s = n.get(Pt); let r = e == null ? void 0 : e.range; if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return false; const i = n.get(_n), a = N(i); if (!a) return false; const { worksheet: u, subUnitId: l, unitId: c } = a; return r = { ...r, startRow: 0, endRow: Math.max(u.getMaxRows() - 1, 0) }, await o.beforeCommandExecute({ id: zn2.id, params: { range: r } }) ? s.syncExecuteCommand(Mr.id, { range: r, unitId: c, subUnitId: l }) : false; } }; var ko = { id: "sheet.command.remove-sheet", type: ar.COMMAND, handler: (n, e) => { var C, S; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), i = N(s, e); if (!i) return false; const { unitId: a, subUnitId: u, workbook: l, worksheet: c } = i; if (l.getSheets().length <= 1) return false; const d = { subUnitId: u, unitId: a, subUnitName: c.getName() }, h = ja( n, d ), m = r.onCommandExecute({ id: ko.id, params: { unitId: a, subUnitId: u } }), g2 = [...(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 mu(g2, t).result ? (o.pushUndoRedo({ unitID: a, undoMutations: f, redoMutations: g2 }), true) : false; } }; var Ue = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: re.deepClone(e.ranges) }; }; var ne = { id: "sheet.mutation.add-worksheet-merge", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return false; 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), true; } }; var Se = (n, e) => { const o = n.get(_n).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]; en.intersects(d, h) && u.push(i[c]); } return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: u }; }; var oe = { id: "sheet.mutation.remove-worksheet-merge", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return false; 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]; en.intersects(c, d) && i.splice(l, 1); } return s.getSpanModel().rebuild(i), true; } }; var Iu = { type: ar.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(Pt), s = n.get(cn), r = n.get(_n), i = (e == null ? void 0 : e.ranges) || ((A = t.getCurrentSelections()) == null ? void 0 : A.map((j) => j.range)); if (!(i != null && i.length)) return false; const a = N(r); if (!a) return false; const { subUnitId: u, unitId: l, worksheet: c } = a, d = { unitId: l, subUnitId: u, ranges: i }, m = c.getConfig().mergeData.filter((j) => i.some((Z) => en.intersects(Z, j))); if (!m.length) return false; const g2 = Se( n, d ), f = t.getCurrentSelections(); if (!(f != null && f.length)) return false; const p = re.deepClone(f), C = re.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: false, isMergedMainCell: false }; const b = vu(c, m), y = { unitId: l, subUnitId: u, cellValue: b.redoParams.getMatrix() }, x = { unitId: l, subUnitId: u, cellValue: b.undoParams.getMatrix() }, T2 = [ { id: oe.id, params: g2 }, { id: Q.id, params: y }, { id: re2.id, params: { selections: C } } ], U = [ { id: ne.id, params: g2 }, { id: Q.id, params: x }, { id: re2.id, params: { selections: p } } ]; return mu(T2, o) ? (s.pushUndoRedo({ unitID: l, undoMutations: U, redoMutations: T2 }), true) : false; } }; function vu(n, e) { const t = new kt(), o = new kt(); 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 }; } var Mu = (n) => { const { order: e } = n, t = {}; return Object.keys(e).forEach((o) => { t[e[Number(o)]] = Number(o); }), { ...n, order: t }; }; var In = { id: "sheet.mutation.reorder-range", type: ar.MUTATION, handler: (n, e) => { const { subUnitId: t, unitId: o, range: s, order: r } = e, u = n.get(_n).getUnit(o).getSheetBySheetId(t); if (!u) return false; const l = new kt(); tr.foreach(s, (d, h) => { if (r.hasOwnProperty(d)) { const m = r[d], g2 = re.deepClone(u.getCellRaw(m, h)); l.setValue(d, h, g2); } }); const c = u.getCellMatrix(); return l.forValue((d, h, m) => { c.setValue(d, h, m); }), true; } }; var _r = "sheet.command.reorder-range"; var uo = { id: _r, type: ar.COMMAND, handler: (n, e) => { var f, p; const { subUnitId: t, unitId: o, range: s, order: r } = e, i = n.get(Pt), 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 = mu(d, i), g2 = l.afterCommandExecute({ id: uo.id, params: e }); return m.result ? (mu(g2.redos, i), n.get(cn).pushUndoRedo({ unitID: o, undoMutations: [...h, ...g2.undos], redoMutations: [...d, ...g2.redos] }), true) : false; } }; var kt2 = class { constructor() { R(this, "_borderInfo", { type: Eu.ALL, color: "#000000", style: Xe.THIN, activeBorderType: false }); R(this, "_borderInfo$", new BehaviorSubject(this._borderInfo)); R(this, "borderInfo$", this._borderInfo$.asObservable()); } dispose() { this._borderInfo$.complete(); } setType(e) { this._borderInfo.type = e, this.setActiveBorderType(true), 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); } var 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 = re.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 = re.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 } }); } }); }; var _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 === Eu.TOP || r === Eu.ALL || r === Eu.OUTSIDE, a = r === Eu.LEFT || r === Eu.ALL || r === Eu.OUTSIDE, u = r === Eu.BOTTOM || r === Eu.ALL || r === Eu.OUTSIDE, l = r === Eu.RIGHT || r === Eu.ALL || r === Eu.OUTSIDE, c = r === Eu.VERTICAL || r === Eu.ALL || r === Eu.INSIDE, d = r === Eu.HORIZONTAL || r === Eu.ALL || r === Eu.INSIDE, h = r.indexOf("tlbr") > -1, m = r.indexOf("tlbc") > -1, g2 = 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: T2, bottomRange: U, rightRange: P } = _u(S), A = new kt(), { 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: g2, bl_tr: f, ml_tr: p, bc_tr: C, topRangeOut: I, leftRangeOut: w, bottomRangeOut: b, rightRangeOut: y, topRange: x, leftRange: T2, bottomRange: U, rightRange: P, range: S, mr: A, borderStyle: { s: o, cl: { rgb: s } } }; } var yu2 = (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: re.deepClone(o) }) : { l: re.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: re.deepClone(o) }) : { r: re.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: re.deepClone(o) }) : { l: re.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: re.deepClone(o) }) : { t: re.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: re.deepClone(o) }) : { b: re.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: re.deepClone(o) }) : { t: re.deepClone(o) } } }); } } }); }; function Eu2(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: re.deepClone(e) }, true), o && u(n.range, { tl_bc: re.deepClone(e) }, true), s && u(n.range, { tl_mr: re.deepClone(e) }, true), r && u(n.range, { bl_tr: re.deepClone(e) }, true), i && u(n.range, { ml_tr: re.deepClone(e) }, true), a && u(n.range, { bc_tr: re.deepClone(e) }, true); } var 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, g2 = (f, p, C) => { No(n, f, p, C); }; e && (g2(d, { b: null }), g2(a, { t: re.deepClone(r) }, true)), s && (g2(c, { t: null }), g2(i, { b: re.deepClone(r) }, true)), t && (g2(h, { r: null }), g2(u, { l: re.deepClone(r) }, true)), o && (g2(m, { l: null }), g2(l, { r: re.deepClone(r) }, true)); }; var 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: g2, bc_tr: f, topRange: p, bottomRange: C, leftRange: S, rightRange: I, topRangeOut: w, bottomRangeOut: b, leftRangeOut: y, rightRangeOut: x } = n, T2 = (U, P, A) => { No(n, U, P, A); }; !s && !r && !i && !a && !u && !l && !c && !d && !h && !m && !g2 && !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 X2 = (j = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : j.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { r: null }) : { r: null } } }); } if (A.startColumn !== e.startColumn) { const X2 = (Z = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Z.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { l: null }) : { l: null } } }); } if (A.endRow !== e.endRow) { const X2 = (Y = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Y.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { b: null }) : { b: null } } }); } if (A.startRow !== e.startRow) { const X2 = (ee = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : ee.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { t: null }) : { t: null } } }); } } else { if (P !== e.endColumn) { const X2 = (Re = o.getValue(U, P)) == null ? void 0 : Re.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { r: null }) : { r: null } } }); } if (P !== e.startColumn) { const X2 = (ie = o.getValue(U, P)) == null ? void 0 : ie.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { l: null }) : { l: null } } }); } if (U !== e.endRow) { const X2 = (xe = o.getValue(U, P)) == null ? void 0 : xe.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { b: null }) : { b: null } } }); } if (U !== e.startRow) { const X2 = (ft = o.getValue(U, P)) == null ? void 0 : ft.s; o.setValue(U, P, { s: { bd: X2 != null && X2.bd ? Object.assign(X2.bd, { t: null }) : { t: null } } }); } } }), T2(w, { b: null }), T2(p, { t: null }, true), T2(b, { t: null }), T2(C, { b: null }, true), T2(y, { r: null }), T2(S, { l: null }, true), T2(x, { l: null }), T2(I, { r: null }, true), T2(e, { tl_br: null }, true), T2(e, { tl_bc: null }, true), T2(e, { tl_mr: null }, true), T2(e, { bl_tr: null }, true), T2(e, { ml_tr: null }, true), T2(e, { bc_tr: null }, true)); }; var rn = { id: "sheet.command.set-border", type: ar.COMMAND, handler: (n, e) => { var C; const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(kt2), a = N(s, e); if (!a) return false; const u = (C = r.getCurrentSelections()) == null ? void 0 : C.map((S) => S.range); if (!(u != null && u.length)) return false; const { activeBorderType: l } = i.getBorderInfo(); if (!l) return false; const c = bu(i, a, u); yu2(c), Uu(c), Eu2(c), Pu(c); const { unitId: d, subUnitId: h, mr: m } = c, g2 = { unitId: d, subUnitId: h, cellValue: m.getData() }, f = Ae( n, g2 ); return t.syncExecuteCommand(Q.id, g2) ? (o.pushUndoRedo({ unitID: d, undoMutations: [{ id: Q.id, params: f }], redoMutations: [{ id: Q.id, params: g2 }] }), true) : false; } }; var Tu = { id: "sheet.command.set-border-position", type: ar.COMMAND, handler: (n, e) => { if (!e.value) return false; const t = n.get(Pt); return n.get(kt2).setType(e.value), t.syncExecuteCommand(rn.id); } }; var ku = { id: "sheet.command.set-border-style", type: ar.COMMAND, handler: (n, e) => { const t = n.get(Pt); return n.get(kt2).setStyle(e.value), t.syncExecuteCommand(rn.id); } }; var Nu = { id: "sheet.command.set-border-color", type: ar.COMMAND, handler: (n, e) => { const t = n.get(Pt); return n.get(kt2).setColor(e.value), t.syncExecuteCommand(rn.id); } }; var Ou = { id: "sheet.command.set-border-basic", type: ar.COMMAND, handler: (n, e) => { const { unitId: t, subUnitId: o, value: s } = e, { type: r, color: i, style: a } = s, u = n.get(Pt), l = n.get(kt2); 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 = re.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 = re.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; } var 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 }; }; var Lt = { id: "sheet.mutation.set-col-data", type: ar.MUTATION, handler: (n, e) => { const { columnData: t } = e, o = n.get(_n), s = N(o, e); if (!s) return false; 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 true; } }; var $u = { type: ar.COMMAND, id: "sheet.command.set-col-data", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s, e); if (!r) return false; 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 }] }), true) : false; } }; var Wu = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }; var Xt2 = { id: "sheet.mutation.set-col-hidden", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (!o) return false; 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 = we.TRUE); } } return true; } }; var Lu = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }; var qt2 = { id: "sheet.mutation.set-col-visible", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (!o) return false; 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 = we.FALSE); } } return true; } }; var Kn = { type: ar.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(Pt), a = n.get(_n), u = N(a, { unitId: t, subUnitId: o }); if (!u) return false; const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = { unitId: t, subUnitId: o, reveal: true, 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 })) }, g2 = mu([ { id: qt2.id, params: c }, { id: re2.id, params: d } ], i), f = r.onCommandExecute({ id: Kn.id, params: e }), p = mu([...f.redos], i); return g2.result && p.result && n.get(cn).pushUndoRedo({ unitID: t, undoMutations: [ { id: Xt2.id, params: h }, { id: re2.id, params: m }, ...(C = f.undos) != null ? C : [] ], redoMutations: [ ...(S = f.preRedos) != null ? S : [], { id: qt2.id, params: c }, { id: re2.id, params: d }, ...f.redos ] }), true; } }; var br = { type: ar.COMMAND, id: "sheet.command.set-selected-cols-visible", handler: (n) => { var l; const e = n.get(F), t = n.get(Pt), o = (l = e.getCurrentSelections()) == null ? void 0 : l.map((c) => c.range).filter((c) => c.rangeType === De.COLUMN); if (!(o != null && o.length)) return false; const s = N(n.get(_n)); if (!s) return false; 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 }); } }; var yr = { type: ar.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(_n), r = n.get(Pt); 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 === De.COLUMN); if (!(i != null && i.length)) return false; const a = N(s, e); if (!a) return false; 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), g2 = { unitId: l, subUnitId: c, reveal: true, selections: i.map((y) => ({ range: y, primary: ve(y, u), style: null })) }, f = mu([ { id: Xt2.id, params: d }, { id: re2.id, params: h } ], r), p = o.onCommandExecute({ id: yr.id, params: d }), C = mu([...p.redos], r); return f.result && C.result ? (n.get(cn).pushUndoRedo({ unitID: l, undoMutations: [ { id: qt2.id, params: m }, { id: re2.id, params: g2 }, ...(w = p.undos) != null ? w : [] ], redoMutations: [ ...(b = p.preRedos) != null ? b : [], { id: Xt2.id, params: d }, { id: re2.id, params: h }, ...p.redos ] }), true) : false; } }; 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; } var Ur = { id: "sheet.command.set-defined-name", type: ar.COMMAND, handler: (n, e) => { var d, h; const t = n.get(Pt), o = n.get(cn), s = n.get(V); if (!e) return false; const r = { ...e }, i = Yb(n, e), a = s.onCommandExecute({ id: Ur.id, params: e }), u = [ ...(d = a.preRedos) != null ? d : [], { id: Xi.id, params: i }, { id: sa.id, params: r }, ...a.redos ], l = [ ...(h = a.preUndos) != null ? h : [], { id: Xi.id, params: r }, { id: sa.id, params: i }, ...a.undos ]; return mu(u, t) ? (o.pushUndoRedo({ unitID: e.unitId, undoMutations: l.filter(Boolean), redoMutations: u.filter(Boolean) }), true) : false; } }; var Pr = (n, e) => { const o = n.get(_n).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 }; }; var ut = { id: "sheet.mutation.set-frozen", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).getUniverSheetInstance(e.unitId); if (o == null) throw new Error("universheet is null error!"); const s = o.getSheetBySheetId(e.subUnitId); if (!s) return false; const r = s.getConfig(), { startRow: i, startColumn: a, ySplit: u, xSplit: l } = e; return r.freeze = { startRow: i, startColumn: a, ySplit: u, xSplit: l }, true; } }; var Bu = { type: ar.COMMAND, id: "sheet.command.set-frozen", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s, { unitId: e.unitId, subUnitId: e.subUnitId }); if (!r) return false; 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 false; const m = { unitId: i, subUnitId: a, ...e }, g2 = Pr(n, m); return t.syncExecuteCommand(ut.id, m) ? (o.pushUndoRedo({ unitID: i, undoMutations: [{ id: ut.id, params: g2 }], redoMutations: [{ id: ut.id, params: m }] }), true) : false; } }; var Fu = { type: ar.COMMAND, id: "sheet.command.cancel-frozen", handler: (n, e) => { const t = n.get(Pt), o = n.get(_n), s = n.get(cn), r = N(o, { unitId: e == null ? void 0 : e.unitId, subUnitId: e == null ? void 0 : e.subUnitId }); if (!r) return false; 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 }] }), true; } }; var Vt = { id: "sheet.mutation.set-gridlines-color", type: ar.MUTATION, handler: (n, e) => { const t = N(n.get(_n), e); if (!t) return false; const { worksheet: o } = t, s = o.getConfig(); return s.gridlinesColor = e.color, true; } }; var ju = { type: ar.COMMAND, id: "sheet.command.set-gridlines-color", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s); if (!r) return false; const { worksheet: i } = r, a = i.getConfig().gridlinesColor; if (a === (e == null ? void 0 : e.color)) return false; 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 }] }), true) : false; } }; var he = { id: "sheet.mutation.set-range-protection", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, rule: s, ruleId: r } = e; return n.get(de).setRule(t, o, r, s), true; } }; var 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; }; var Ct2 = { id: "sheet.mutation.set-worksheet-protection", type: ar.MUTATION, handler: (n, e) => { const { unitId: t, subUnitId: o, rule: s } = e; return n.get(Ye).setRule(t, o, s), true; } }; var Gu = { type: ar.COMMAND, id: "sheet.command.set-protection", async handler(n, e) { if (!e) return false; const t = n.get(Pt), o = n.get(cn), 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: Ct2.id, params: { unitId: a, subUnitId: u, rule: r } }), c.push({ id: Ct2.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] } }))), mu(l, t) && o.pushUndoRedo({ unitID: a, undoMutations: c, redoMutations: l }), true; } }; var 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 }; }; var Ht = { id: "sheet.mutation.set-row-data", type: ar.MUTATION, handler: (n, e) => { const { rowData: t } = e, o = n.get(_n), s = N(o, e); if (!s) return false; 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 true; } }; var Ku = { type: ar.COMMAND, id: "sheet.command.set-row-data", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s, e); if (!r) return false; 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 }] }), true) : false; } }; var Ju = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }; var Zt = { id: "sheet.mutation.set-row-visible", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).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 true; } }; var Yu = (n, e) => { if (n.get(_n).getUniverSheetInstance(e.unitId) == null) throw new Error("universheet is null error!"); return { unitId: e.unitId, subUnitId: e.subUnitId, ranges: e.ranges }; }; var Qt = { id: "sheet.mutation.set-row-hidden", type: ar.MUTATION, handler: (n, e) => { const o = n.get(_n).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 true; } }; var Jn = { type: ar.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(Pt), i = n.get(cn), a = n.get(V), u = N(n.get(_n), { unitId: t, subUnitId: o }); if (!u) return false; const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = { unitId: t, subUnitId: o, reveal: true, 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 })) }, g2 = mu( [ { id: Zt.id, params: c }, { id: re2.id, params: d } ], r ), f = a.onCommandExecute({ id: Jn.id, params: e }), p = mu([...f.redos], r); return g2.result && p.result && i.pushUndoRedo({ unitID: t, undoMutations: [ ...(C = f.preUndos) != null ? C : [], { id: Qt.id, params: h }, { id: re2.id, params: m }, ...(S = f.undos) != null ? S : [] ], redoMutations: [ ...(I = f.preRedos) != null ? I : [], { id: Zt.id, params: c }, { id: re2.id, params: d }, ...f.redos ] }), true; } }; var Tr = { type: ar.COMMAND, id: "sheet.command.set-selected-rows-visible", handler: async (n) => { var c; const e = n.get(F), t = n.get(_n), o = n.get(Pt), s = (c = e.getCurrentSelections()) == null ? void 0 : c.map((d) => d.range).filter((d) => d.rangeType === De.ROW); if (!(s != null && s.length)) return false; const r = N(t); if (!r) return false; 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 }); } }; var kr = { type: ar.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(Pt), s = n.get(cn), r = n.get(_n), 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((T2) => T2.range).filter((T2) => T2.rangeType === De.ROW); if (!(a != null && a.length)) return false; const u = N(r, e); if (!u) return false; 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((T2) => ({ range: T2, primary: ve(T2, d), style: null })) }, g2 = Yu(n, h), f = { unitId: l, subUnitId: c, reveal: true, selections: a.map((T2) => ({ range: T2, primary: ve(T2, d), style: null })) }, p = i.onCommandExecute({ id: kr.id, params: h }); return mu([ ...(w = p.preRedos) != null ? w : [], { id: Qt.id, params: h }, { id: re2.id, params: m }, ...p.redos ], o).result && s.pushUndoRedo({ unitID: l, undoMutations: [ ...(b = p.preUndos) != null ? b : [], { id: Zt.id, params: g2 }, { id: re2.id, params: f }, ...(y = p.undos) != null ? y : [] ], redoMutations: [ ...(x = p.preRedos) != null ? x : [], { id: Qt.id, params: h }, { id: re2.id, params: m }, ...p.redos ] }), true; } }; 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; } var fe = { type: ar.COMMAND, id: "sheet.command.set-style", handler: (n, e) => { var b; const t = n.get(_n), o = N(t, e); if (!o) return false; const { unitId: s, subUnitId: r, worksheet: i } = o, { range: a, style: u } = e, l = n.get(Pt), c = n.get(cn), d = n.get(F), h = a ? [a] : (b = d.getCurrentSelections()) == null ? void 0 : b.map((y) => y.range); if (!(h != null && h.length)) return false; const m = new kt(), g2 = Za(i); if (re.isArray(u.value)) for (let y = 0; y < h.length; y++) g2.forOperableEach(h[y], (x, T2, U) => { m.setValue(x, T2, { s: { [u.type]: u.value[x - U.startRow][T2 - U.startColumn] } }); }); else for (let y = 0; y < h.length; y++) { const x = { s: { [u.type]: u.value } }; g2.forOperableEach(h[y], (T2, U) => m.setValue(T2, 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 = mu([...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] }), true) : false; } }; var Zd = { type: ar.COMMAND, id: "sheet.command.set-bold", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return false; const t = N(n.get(_n)); if (!t) return false; const { worksheet: o } = t, { actualRow: s, actualColumn: r } = e.primary, a = { style: { type: "bl", value: o.getRange(s, r).getFontWeight() === Gs.BOLD ? we.FALSE : we.TRUE } }; return n.get(Pt).syncExecuteCommand(fe.id, a); } }; var Qd = { type: ar.COMMAND, id: "sheet.command.set-italic", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return false; const t = N(n.get(_n)); if (!t) return false; const { worksheet: o } = t; let s = true; if (e.primary) { const { startRow: i, startColumn: a } = e.primary; s = o.getRange(i, a).getFontStyle() === Vs.ITALIC; } const r = { style: { type: "it", value: s ? we.FALSE : we.TRUE } }; return n.get(Pt).syncExecuteCommand(fe.id, r); } }; var eh = { type: ar.COMMAND, id: "sheet.command.set-underline", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return false; const t = N(n.get(_n)); if (!t) return false; const { worksheet: o } = t; let s = true; e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getUnderline().s); const r = { style: { type: "ul", value: { s: s ? we.FALSE : we.TRUE } } }; return n.get(Pt).syncExecuteCommand(fe.id, r); } }; var th = { type: ar.COMMAND, id: "sheet.command.set-stroke", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return false; const t = N(n.get(_n)); if (!t) return false; const { worksheet: o } = t; let s = true; e.primary && (s = !!o.getRange(e.primary.actualRow, e.primary.actualColumn).getStrikeThrough().s); const r = { style: { type: "st", value: { s: s ? we.FALSE : we.TRUE } } }; return n.get(Pt).syncExecuteCommand(fe.id, r); } }; var nh = { type: ar.COMMAND, id: "sheet.command.set-overline", handler: (n) => { const e = n.get(F).getCurrentLastSelection(); if (!e) return false; const t = N(n.get(_n)); if (!t) return false; const { worksheet: o } = t; let s = true; e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getOverline().s); const r = { style: { type: "ol", value: { s: s ? we.FALSE : we.TRUE } } }; return n.get(Pt).syncExecuteCommand(fe.id, r); } }; var oh = { type: ar.COMMAND, id: "sheet.command.set-font-family", handler: (n, e) => { if (!e) return false; const t = n.get(Pt), o = { style: { type: "ff", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }; var sh = { type: ar.COMMAND, id: "sheet.command.set-font-size", handler: (n, e) => { if (!e) return false; const t = n.get(Pt), o = { style: { type: "fs", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }; var Zu = { type: ar.COMMAND, id: "sheet.command.set-text-color", handler: (n, e) => { if (!e) return false; const t = n.get(Pt), o = { style: { type: "cl", value: { rgb: e.value } } }; return t.syncExecuteCommand(fe.id, o); } }; var Qu = { type: ar.COMMAND, id: "sheet.command.reset-text-color", handler: (n) => { const e = n.get(Pt), t = { style: { type: "cl", value: { rgb: null // use null to reset text color } } }; return e.syncExecuteCommand(fe.id, t); } }; var el = { type: ar.COMMAND, id: "sheet.command.set-background-color", handler: (n, e) => { if (!e || !e.value) return false; const t = n.get(Pt), o = { style: { type: "bg", value: { rgb: e.value } } }; return t.syncExecuteCommand(fe.id, o); } }; var tl = { type: ar.COMMAND, id: "sheet.command.reset-background-color", handler: (n) => { const e = n.get(Pt), t = { style: { type: "bg", value: { rgb: null // use null to reset background color } } }; return e.syncExecuteCommand(fe.id, t); } }; var nl = { type: ar.COMMAND, id: "sheet.command.set-vertical-text-align", handler: (n, e) => { if (!e) return false; const t = n.get(Pt), o = { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, style: { type: "vt", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }; var ol = { type: ar.COMMAND, id: "sheet.command.set-horizontal-text-align", handler: (n, e) => { if (!e) return false; const t = n.get(Pt), o = { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, style: { type: "ht", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }; var sl = { type: ar.COMMAND, id: "sheet.command.set-text-wrap", handler: (n, e) => { if (!e) return false; const t = n.get(Pt), o = { unitId: e.unitId, subUnitId: e.subUnitId, range: e.range, style: { type: "tb", value: e.value } }; return t.syncExecuteCommand(fe.id, o); } }; var rl = { type: ar.COMMAND, id: "sheet.command.set-text-rotation", handler: (n, e) => { if (!e) return false; const t = typeof e.value == "number" ? { a: e.value } : { a: 0, v: we.TRUE }, o = n.get(Pt), s = { style: { type: "tr", value: t } }; return o.syncExecuteCommand(fe.id, s); } }; var il = (n, e) => { const r = n.get(_n).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor; return { ...re.deepClone(e), color: r }; }; var fn3 = { id: "sheet.mutation.set-tab-color", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n).getUniverSheetInstance(e.unitId); if (!t) return false; const o = t.getSheetBySheetId(e.subUnitId); return o ? (o.getConfig().tabColor = e.color, true) : false; } }; var al = { type: ar.COMMAND, id: "sheet.command.set-tab-color", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = N(n.get(_n)); if (!s) return false; const { unitId: r, subUnitId: i } = s, a = { color: e.value, unitId: r, subUnitId: i }, u = il(n, a); return t.syncExecuteCommand(fn3.id, a) ? (o.pushUndoRedo({ unitID: r, undoMutations: [{ id: fn3.id, params: u }], redoMutations: [{ id: fn3.id, params: a }] }), true) : false; } }; var Or = { id: "sheet.mutation.set-workbook-name", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n).getUnit(e.unitId, Fe.UNIVER_SHEET); return t ? (t.setName(e.name), true) : false; } }; var Dr = { type: ar.COMMAND, id: "sheet.command.set-workbook-name", handler: async (n, e) => { var l; if (!n.get(_n).getUnit(e.unitId, Fe.UNIVER_SHEET)) return false; 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(Pt); return mu(a, u).result; } }; var an = { id: "sheet.operation.set-worksheet-active", type: ar.OPERATION, handler: (n, e) => { const t = n.get(_n).getUniverSheetInstance(e.unitId); if (!t) return false; const o = t.getWorksheets(); for (const [, s] of o) if (s.getSheetId() === e.subUnitId) return t.setActiveSheet(s), true; return false; } }; var ul = 4; var Ar = { type: ar.COMMAND, id: "sheet.command.set-worksheet-activate", handler: (n, e, t) => { const o = n.get(Pt), s = N(n.get(_n), e); if (!s) return false; 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); }); } }; var 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 }; }; var tt = { id: "sheet.mutation.set-worksheet-col-width", type: ar.MUTATION, handler: (n, e) => { var u; const t = n.get(_n), o = N(t, e); if (!o) return false; 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 true; } }; var Oo = { type: ar.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 false; const s = n.get(Pt), r = n.get(cn), i = N(n.get(_n)); if (!i) return false; const { worksheet: a, unitId: u, subUnitId: l } = i, { anchorCol: c, deltaX: d } = e, m = a.getColumnWidth(c) + d, g2 = o.length === 1 && o[0].range.rangeType === De.ALL, f = o.filter((x) => x.range.rangeType === De.COLUMN), p = g2 ? De.ALL : f.some(({ range: x }) => { const { startColumn: T2, endColumn: U } = x; return T2 <= c && c <= U; }) ? De.COLUMN : De.NORMAL; let C; if (p === De.ALL) { const x = a.getRowCount(), T2 = 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: T2 }; } else p === De.COLUMN ? C = { subUnitId: l, unitId: u, ranges: f.map((x) => en.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 = mu([...I], s); return b && y.result && r.pushUndoRedo({ unitID: u, undoMutations: [{ id: tt.id, params: w }, ...S], redoMutations: [{ id: tt.id, params: C }, ...I] }), true; } }; var Mn = { type: ar.COMMAND, id: "sheet.command.set-worksheet-col-width", handler: (n, e) => { var S, I, w, b; const t = n.get(F), o = n.get(Pt), s = n.get(cn), 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 false; const a = N(n.get(_n), e); if (!a) return false; 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: g2, redos: f } = n.get(V).onCommandExecute({ id: Mn.id, params: d }), p = r.onCommandExecute({ id: Mn.id, params: d }), C = mu([...f, ...p.redos], o); return m && C.result ? (s.pushUndoRedo({ unitID: l, undoMutations: [...(w = p.preUndos) != null ? w : [], { id: tt.id, params: h }, ...g2], redoMutations: [...(b = p.preRedos) != null ? b : [], { id: tt.id, params: d }, ...f] }), true) : false; } }; var ll = { type: ar.COMMAND, id: "sheet.command.set-col-is-auto-width", handler: async (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(F), r = n.get(_n), i = N(r, e); if (!i) return false; const { unitId: a, subUnitId: u } = i; let l = []; if (e != null && e.ranges) l = [...e.ranges]; else { const g2 = s.getCurrentSelections(); for (let f = 0; f < g2.length; f++) l.push(g2[f].range); } if (!(l != null && l.length)) return false; const c = { unitId: a, subUnitId: u, ranges: l }, { undos: d, redos: h } = n.get(V).onCommandExecute({ id: ll.id, params: c }); return mu([...h], t).result ? (o.pushUndoRedo({ unitID: a, undoMutations: [...d], redoMutations: [...h] }), true) : false; } }; var Bt = { id: "sheet.mutation.set-worksheet-default-style", type: ar.MUTATION, handler: (n, e) => { const { defaultStyle: t } = e, o = n.get(_n), s = N(o); if (!s) return false; const { worksheet: r } = s; return r ? (r.setDefaultCellStyle(t), true) : false; } }; var cl = (n, e) => { const t = Et(n.get(_n), 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() }; }; var dl = { type: ar.COMMAND, id: "sheet.command.set-worksheet-default-style", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), { 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 }] }), true) : false; } }; var $r = (n, e) => { const t = Et(n.get(_n), 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() }; }; var lt = { id: "sheet.mutation.set-worksheet-hidden", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n).getUniverSheetInstance(e.unitId); if (t == null) return false; const o = t.getSheetBySheetId(e.subUnitId); return o ? (o.getConfig().hidden = e.hidden, true) : false; } }; var hl = { type: ar.COMMAND, id: "sheet.command.set-worksheet-hidden", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(NE), r = n.get(Vr), i = N(n.get(_n), e); if (!i) return false; const { workbook: a, worksheet: u, unitId: l, subUnitId: c } = i; if (u.getConfig().hidden === we.TRUE) return false; const h = { unitId: l, subUnitId: c, hidden: we.TRUE }, m = $r(n, h); return a.getSheets().filter((C) => C.getConfig().hidden === we.FALSE).length === 1 ? (s.emit(r.t("sheets.info.hideSheet")), false) : t.syncExecuteCommand(lt.id, h) ? (o.pushUndoRedo({ unitID: l, undoMutations: [{ id: lt.id, params: m }], redoMutations: [{ id: lt.id, params: h }] }), true) : false; } }; var ml = (n, e) => { const t = Et(n.get(_n), 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() }; }; var _n2 = { id: "sheet.mutation.set-worksheet-name", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n).getUniverSheetInstance(e.unitId); if (t == null) return false; const o = t.getSheetBySheetId(e.subUnitId); return o ? (o.getConfig().name = e.name, true) : false; } }; var Do = { type: ar.COMMAND, id: "sheet.command.set-worksheet-name", handler: (n, e) => { var g2, f; const t = n.get(Pt), o = n.get(cn), s = n.get(V), r = N(n.get(_n), e); if (!r) return false; 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 = [ ...(g2 = c.preRedos) != null ? g2 : [], { id: _n2.id, params: u }, ...c.redos ], h = [ ...(f = c.preUndos) != null ? f : [], { id: _n2.id, params: l }, ...c.undos ]; return mu(d, t).result ? (o.pushUndoRedo({ unitID: i, undoMutations: h, redoMutations: d }), true) : false; } }; var gl = (n, e) => ({ ...re.deepClone(e), toOrder: e.fromOrder, fromOrder: e.toOrder }); var Rn = { id: "sheet.mutation.set-worksheet-order", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n).getUniverSheetInstance(e.unitId); if (!t) return false; const o = t.getConfig(); return o.sheetOrder.splice(e.fromOrder, 1), o.sheetOrder.splice(e.toOrder, 0, e.subUnitId), true; } }; var Wr = { type: ar.COMMAND, id: "sheet.command.set-worksheet-order", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = N(n.get(_n), e); if (!s) return false; 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 }] }), true) : false; } }; var un = class { constructor() { R(this, "_model", /* @__PURE__ */ new Map()); R(this, "_pointChange", new Subject()); 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]; } }; var Lr = class { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.Delete); R(this, "status", fl.INIT); R(this, "value", true); 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}`; } }; var Vr2 = class { constructor(e, t, o) { R(this, "type", D.SelectRange); R(this, "subType", _.ManageCollaborator); R(this, "status", fl.INIT); R(this, "value", true); 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}`; } }; var Ie = () => [Io, Pe, Vr2, Lr]; var it = [_.Edit, _.View, _.ManageCollaborator, _.Delete]; var 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; }, {}); var en2 = () => [ Me, Gs2, Ws, Js, Ls, js, Mo, Hs, Bs, bo, vo, Fs, Ks, _o, eu, Ys, zs, Vs2 ]; var fl2 = [ _.Edit, _.Print, _.Comment, _.View, _.Copy, _.Export, _.ManageCollaborator, _.CreateSheet, _.DeleteSheet, _.RenameSheet, _.HideSheet, _.Duplicate, _.Share, _.MoveSheet, _.CopySheet, _.RecoverHistory, _.ViewHistory, _.CreatePermissionObject ]; var we2 = () => [ Te, Hn, rr2, Zs ]; var ke = () => [ Xs, qs, Qs, er, tr2, nr, sr, or, ir, ar2, wn, $t, Wt, ur ]; var eo = [ _.Copy, _.DeleteColumn, _.DeleteRow, _.EditExtraObject, _.Filter, _.InsertColumn, _.InsertRow, _.InsertHyperlink, _.PivotTable, _.SetCellStyle, _.SetCellValue, _.SetColumnStyle, _.SetRowStyle, _.Sort ]; var Rl = Object.defineProperty; var pl = Object.getOwnPropertyDescriptor; var 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; }; var Ze2 = (n, e) => (t, o) => e(t, o, n); var Sl = "SHEET_WORKSHEET_PROTECTION_PLUGIN"; var wl = "SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN"; var bn = class extends J0 { 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(); [...we2(), ...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); }); }), [...we2(), ...ke()].forEach((a) => { const u = new a(t, r); this._permissionService.deletePermissionPoint(u.id); }); }); }; this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((e) => { n(e); }), this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe(n), this._univerInstanceService.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((e) => { e.getSheets().forEach((t) => { const o = e.getUnitId(), s = t.getSheetId(); we2().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": { we2().forEach((e) => { const t = new e(n.unitId, n.subUnitId); this._permissionService.updatePermissionPoint(t.id, true); }); break; } case "set": { we2().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) => { we2().forEach((r) => { const i = new r(t, s); i.value = false, this._permissionService.addPermissionPoint(i); }); }), this._worksheetProtectionRuleModel.changeRuleInitState(true); }, onUnLoad: (t) => { const o = this._univerInstanceService.getUnit(t); o && (o.getSheets().forEach((s) => { const r = s.getSheetId(); [...we2(), ...ke()].forEach((i) => { const a = new i(t, r); this._permissionService.deletePermissionPoint(a.id); }); }), en2().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([ Ze2(0, ot(UE)), Ze2(1, ot(_n)), Ze2(2, ot(Ot)), Ze2(3, ot(Ye)), Ze2(4, ot(un)), Ze2(5, ot(Bi)), Ze2(6, ot(de)), Ze2(7, ot(Mt)) ], bn); var Ao = { id: "sheet.mutation.set-worksheet-permission-points", type: ar.MUTATION, handler: (n, e) => { const { rule: t } = e; return n.get(un).addRule(t), true; } }; var Il = { type: ar.COMMAND, id: "sheet.command.set-worksheet-permission-points", async handler(n, e) { if (!e) return false; const t = n.get(Pt), { rule: o } = e; return t.executeCommand(Ao.id, { rule: o, unitId: o.unitId, subUnitId: o.subUnitId }), true; } }; var vl = { type: ar.COMMAND, id: "sheet.command.set-worksheet-protection", async handler(n, e) { if (!e) return false; const t = n.get(Pt), o = n.get(cn), { rule: s, permissionId: r, oldRule: i } = e, { unitId: a, subUnitId: u } = s, l = { ...s, permissionId: r }; if (await t.executeCommand(Ct2.id, { unitId: a, subUnitId: u, newRule: l })) { const d = [{ id: Ct2.id, params: { unitId: a, subUnitId: u, newRule: l } }], h = [{ id: Ct2.id, params: { unitId: a, subUnitId: u, rule: i } }]; o.pushUndoRedo({ unitID: a, redoMutations: d, undoMutations: h }); } return true; } }; var Ml = 2e3; var 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 }; }; var 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 }; }; var 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 }; }; var nt2 = { id: "sheet.mutation.set-worksheet-row-height", type: ar.MUTATION, handler: (n, e) => { var l; const { ranges: t, rowHeight: o } = e, s = n.get(_n), r = N(s, e); if (!r) return false; 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 true; } }; var Oe = { id: "sheet.mutation.set-worksheet-row-is-auto-height", type: ar.MUTATION, handler: (n, e) => { var a; const { ranges: t, autoHeightInfo: o } = e, s = n.get(_n), r = N(s, e); if (!r) return false; 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 true; } }; var Br = { id: "sheet.mutation.set-worksheet-row-auto-height", type: ar.MUTATION, handler: (n, e) => { const { rowsAutoHeightInfo: t } = e, o = n.get(_n), s = N(o, e); if (!s) return false; const r = s.worksheet.getRowManager(); for (const { row: i, autoHeight: a } of t) { const u = r.getRowOrCreate(i); u.ah = a; } return true; } }; var $o = { type: ar.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 false; const r = N(n.get(_n)); if (!r) return false; 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 === De.ALL, g2 = o.filter((A) => A.range.rangeType === De.ROW), f = m ? De.ALL : g2.some(({ range: A }) => { const { startRow: j, endRow: Z } = A; return j <= l && l <= Z; }) ? De.ROW : De.NORMAL; let p; if (f === De.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 === De.ROW ? p = { subUnitId: a, unitId: u, ranges: g2.map((A) => en.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: we.FALSE }, I = xo(S, i), w = n.get(Pt), b = n.get(cn), y = s.onCommandExecute({ id: $o.id, params: p }), x = mu([ { id: nt2.id, params: p }, { id: Oe.id, params: S } ], w), T2 = mu([...y.redos], w); return x.result && T2.result ? (b.pushUndoRedo({ unitID: u, undoMutations: [ ...(U = y.preUndos) != null ? U : [], { id: nt2.id, params: C }, { id: Oe.id, params: I }, ...y.undos ], redoMutations: [ ...(P = y.preRedos) != null ? P : [], { id: nt2.id, params: p }, { id: Oe.id, params: S }, ...y.redos ] }), true) : false; } }; var Wo = { type: ar.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(Pt), s = n.get(cn), r = n.get(_n), 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 false; const u = N(r, e); if (!u) return false; const { unitId: l, subUnitId: c, worksheet: d } = u, h = { subUnitId: c, unitId: l, ranges: a, rowHeight: e.value }, m = Hr(h, d), g2 = { unitId: l, subUnitId: c, ranges: h.ranges, autoHeightInfo: we.FALSE }, f = xo(g2, d), p = mu([ { id: nt2.id, params: h }, { id: Oe.id, params: g2 } ], o), C = i.onCommandExecute({ id: Wo.id, params: h }), S = mu([...C.redos], o); return p.result && S.result ? (s.pushUndoRedo({ unitID: l, undoMutations: [ ...(b = C.preRedos) != null ? b : [], { id: nt2.id, params: m }, { id: Oe.id, params: f }, ...C.undos ], redoMutations: [ ...(y = C.preRedos) != null ? y : [], { id: nt2.id, params: h }, { id: Oe.id, params: g2 }, ...C.redos ] }), true) : false; } }; var Lo = { type: ar.COMMAND, id: "sheet.command.set-row-is-auto-height", handler: (n, e) => { var C, S; const t = n.get(Pt), o = n.get(cn), s = n.get(F), r = n.get(_n), i = N(r, e); if (!i) return false; 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 false; const d = { unitId: a, subUnitId: u, ranges: c, autoHeightInfo: we.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: g2, redos: f } = n.get(V).onCommandExecute({ id: Lo.id, params: d }), p = mu([...f], t); return m && p.result ? (o.pushUndoRedo({ unitID: a, undoMutations: [{ id: Oe.id, params: h }, ...g2], redoMutations: [{ id: Oe.id, params: d }, ...f] }), true) : false; } }; var Fr = { type: ar.COMMAND, id: "sheet.command.set-worksheet-show", handler: (n, e) => { const { unitId: t, subUnitId: o } = e, s = n.get(Pt), r = n.get(cn), i = n.get(_n); if (!N(n.get(_n))) return false; const u = i.getCurrentUnitForType(Fe.UNIVER_SHEET); if (!u) return false; const l = u.getSheetBySheetId(o); if (!l || l.getConfig().hidden === we.FALSE) return false; const d = { unitId: t, subUnitId: o, hidden: we.FALSE }, h = $r(n, d), m = s.syncExecuteCommand(lt.id, d), g2 = { unitId: t, subUnitId: o }, f = s.syncExecuteCommand( an.id, g2 ); 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 } ] }), true) : false; } }; var _l = class { 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, "\\$&"); } var 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 === dn.FORCE_STRING || n.t === dn.STRING)) return String(n.v); } } function Pl(n, e, t, o, s = false) { const r = tr.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, g2 = 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(g2); 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 }; } var Tl = { type: ar.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(Pt), l = n.get(_n), c = n.get(cn); if (!N(n.get(_n))) return false; const h = l.getCurrentUnitForType(Fe.UNIVER_SHEET); if (!h) return false; const m = h.getSheetBySheetId(o); if (!m) return false; const { lastRow: g2, rs: f, maxLength: p } = Pl(m, s, r, i, a), C = m.getColumnCount(), { startColumn: S } = tr.transformRange(s, m); if (s.startColumn !== s.endColumn) return false; 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: De2.id, params: j }); } const y = { startRow: s.startRow, endRow: g2, startColumn: S, endColumn: S + p }, x = new kt(); 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 T2 = { unitId: t, subUnitId: o, cellValue: x.clone() }, U = Ae(n, T2); return I.push({ id: Q.id, params: T2 }), w.unshift({ id: Q.id, params: U }), mu(I, u).result ? (c.pushUndoRedo({ unitID: t, undoMutations: w, redoMutations: I }), true) : false; } }; var kl = { id: "sheet.command.toggle-cell-checkbox", type: ar.COMMAND, handler: (n, e) => { if (!e) return false; const { unitId: t, subUnitId: o, row: s, col: r, paragraphIndex: i } = e, u = n.get(_n).getUnit(t, Fe.UNIVER_SHEET), l = u == null ? void 0 : u.getSheetBySheetId(o), c = n.get(cn), d = n.get(Pt); if (!l) return false; const h = l.getCell(s, r); if (!(h != null && h.p)) return false; const m = re.deepClone(h.p), g2 = new jt(m), f = st.paragraph.bullet.toggleChecklist({ document: g2, paragraphIndex: i }); if (!f) return false; Ke.apply(g2.getBody(), f.serialize()); const p = { unitId: t, subUnitId: o, cellValue: { [s]: { [r]: { p: m, t: dn.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); } }; var Ft = { id: "sheet.mutation.toggle-gridlines", type: ar.MUTATION, handler: (n, e) => { const t = N(n.get(_n), e); if (!t) return false; const { worksheet: o } = t, s = o.getConfig(); return s.showGridlines = e.showGridlines, true; } }; var Nl = { type: ar.COMMAND, id: "sheet.command.toggle-gridlines", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s); if (!r) return false; const { worksheet: i } = r, a = i.getConfig().showGridlines; if (a === (e == null ? void 0 : e.showGridlines)) return false; const { unitId: u, subUnitId: l } = r, c = { showGridlines: a === we.TRUE ? we.FALSE : we.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 }] }), true) : false; } }; var Ol = { id: "sheet.command.unregister-worksheet-range-theme-style", type: ar.COMMAND, handler: (n, e) => { var h; if (!e) return false; const { unitId: t, themeName: o } = e, s = n.get(_n), r = n.get(Pt), i = n.get(cn), a = n.get(He); if (!N(s)) return false; 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 }] }), true; } }; var Dl = { id: "sheet.mutation.empty", type: ar.MUTATION, handler: () => true }; var Al = (n) => { const e = new kt(); return n.forEach((t) => { tr.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; }; var 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; }; var Qo2 = (n) => { const e = { area: 0 }, t = (o, s) => e.area < o ? (e.area = o, e.range = s, true) : false; 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; }; var $l = (n, e) => { tr.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; }; var jr = (n) => { const e = []; let t = Qo2(n); for (; t.area > 0; ) t.range && (e.push(t.range), $l(n, t.range)), t = Qo2(n); return e; }; var Gr = (n) => { const e = Al(n); return jr(e); }; var ah = class { constructor() { R(this, "_matrix", new kt()); } add(...e) { return e.forEach((t) => { tr.foreach(t, (o, s) => { this._matrix.setValue(o, s, 1); }); }), this; } subtract(...e) { return e.forEach((t) => { tr.foreach(t, (o, s) => { this._matrix.realDeleteValue(o, s); }); }), this; } merge() { const e = xl(this._matrix); return jr(e); } }; var wt = Ct("INumfmtService"); var 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) => { tr.foreach(d, (h, m) => { const g2 = t.getValue(s, r, h, m); g2 ? i.push({ pattern: g2.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: Vo2.id, params: lo(s, r, i) }); } return a.length && u.push({ id: zr.id, params: { unitId: s, subUnitId: r, ranges: a } }), u; }; var Vo2 = { id: "sheet.mutation.set.numfmt", type: ar.MUTATION, handler: (n, e) => { if (!e) return false; 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), true; } }; var zr = { id: "sheet.mutation.remove.numfmt", type: ar.MUTATION, handler: (n, e) => { if (!e) return false; const { unitId: t, subUnitId: o, ranges: s } = e; return n.get(wt).deleteValues(t, o, s), true; } }; var lh = (n, e) => { const t = n.get(wt), { ranges: o, unitId: s, subUnitId: r } = e, i = []; if (o.forEach((u) => { tr.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: Vo2.id, params: a }]; }; var 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(AC(c.row, c.col)); }); }), { unitId: n, subUnitId: e, refMap: s, values: r }; }; var Wl = { id: "sheet.operation.scroll-to-cell", type: ar.OPERATION, handler: () => true }; var Kr = "ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY"; var Ll = "maxCellsPerSheet"; var Vl = 3e6; var Hl = Object.defineProperty; var Bl = Object.getOwnPropertyDescriptor; var 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; }; var to = (n, e) => (t, o) => e(t, o, n); var yn = class extends nt { // 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, ot2, st2, De2, Be, Ut, oe, zr, ne, Or, _n2, Vo2, In, Dl, Qt, // formula SUBTOTAL Zt, Xt2, qt2 ].forEach((r) => { var i; this._commandService.registerCommand(r), (i = this._dataSyncPrimaryController) == null || i.registerSyncingMutations(r); }), ((s = this._configService.getConfig(Kr)) != null ? s : false) || [ po, Co, So, xs, Pt2, Tt, Oo, $o, gu, mu2, pr2, gt, sn, Bn, hu, du, fr, mt, fu, jn, pt, Fn, vr, zn2, 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, fn3, Zu, rl, sl, nl, Dr, Ar, an, hl, lt, Do, Wr, Rn, Br, nt2, Lo, Oe, tt, // SetWorksheetColIsAutoWidthCommand, re2, Wl, au, Ir, Ur, Fr, Nl, Ft, ju, Vt, // permissions range protection Il, ct, Ct2, St, Ao, Xi2, Gu, su, qi, ru, vl, Ne, ze, he, kl, Bt, dl, Tl, // range theme Kt, zt, Uo, Yt, Ol, wu2, ba, iu ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r))), this._configService.setConfig(Ll, Vl); } }; yn = Fl([ to(0, Pt), to(1, SE), to(2, nf(g)) ], yn); var jl = Object.defineProperty; var Gl = Object.getOwnPropertyDescriptor; var 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; }; var es = (n, e) => (t, o) => e(t, o, n); var En = class extends nt { constructor(n, e) { super(), this._univerInstanceService = n, this._commandService = e, this._initialize(); } _initialize() { this.disposeWithMe( this._commandService.onCommandExecuted((n) => { if (n.id !== Ji.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), g2 = { subUnitId: d, unitId: a, cellValue: m }; s.push({ id: Q.id, params: g2 }); } } return s.every( (i) => this._commandService.executeCommand(i.id, i.params, { onlyLocal: true }) ); }) ); } /** * 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 kt(t); return a.forValue((u, l, c) => { const d = i == null ? void 0 : i.getValue(u, l), h = Gb(d, c, s); a.setValue(u, l, h); }), a.getMatrix(); } }; En = zl([ es(0, ot(_n)), es(1, Pt) ], En); var Kl = "sheets.config"; var ts = {}; var Jl = Object.defineProperty; var Yl = Object.getOwnPropertyDescriptor; var 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; }; var ns = (n, e) => (t, o) => e(t, o, n); var ql = "SHEET_DEFINED_NAME_PLUGIN"; var ch = "AllDefaultWorkbook"; var Un = class extends nt { 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: [Fe.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, pr), ns(1, Bi) ], Un); var $ = { 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 = ((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 || {}); var cn2 = Number.MAX_SAFE_INTEGER; var 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 === De.COLUMN || t) && (e.startRow = 0, e.endRow = cn2), (e.rangeType === De.ROW || o) && (e.startColumn = 0, e.endColumn = cn2), e.rangeType === De.ALL && (e.startColumn = 0, e.endColumn = cn2, e.startRow = 0, e.endRow = cn2), e; }; var _e = (n) => { let e = n.rangeType; return n.rangeType === De.COLUMN ? e = De.ROW : n.rangeType === De.ROW && (e = De.COLUMN), { startRow: n.startColumn, endRow: n.endColumn, startColumn: n.startRow, endColumn: n.endRow, rangeType: e }; }; var 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 g2 = r(s, o); return m || (s.start <= o.start ? (o.start += d, o.end += d) : g2 && (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) }; }; var 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 } ]; }; var 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 kt(); return tr.foreach(e, (l, c) => { a.setValue(l, c, 1); }), a.moveRows(s, r, i), WC(a, (l) => l === 1); }; var Ql = (n, e) => { const { range: t, order: o } = n.params || {}; if (!t || !o) return [e]; const s = new kt(); tr.foreach(e, (a, u) => { s.setValue(a, u, 1); }); const r = new kt(); return tr.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); }), WC(s, (a) => a === 1); }; var 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 } ]; }; var 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 kt(); return tr.foreach(e, (u, l) => { a.setValue(u, l, 1); }), a.moveColumns(s, r, i), WC(a, (u) => u === 1); }; var 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 (en.contains(t, e) && s.push({ type: q.Delete }), en.contains(o, e)) { s.push({ type: q.Delete }); const a = en.getRelativeRange(e, o), u = en.getPositionRange(a, t); return [ { type: q.Set, range: u } ]; } return s; }; var 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 (!en.intersects(o, e) && !en.intersects(t, e)) return [e]; if (en.contains(o, e)) { const m = en.getRelativeRange(e, o); return [en.getPositionRange(m, t)]; } const s = new kt(); tr.foreach(e, (m, g2) => { s.setValue(m, g2, 1); }); const r = new kt(), i = en.getIntersects(o, e); i && tr.foreach(i, (m, g2) => { s.getValue(m, g2) && (s.setValue(m, g2, void 0), r.setValue(m, g2, 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 tr.foreach(l, (m, g2) => { var C; const f = m + u, p = g2 + a; s.setValue(f, p, (C = r.getValue(m, g2)) != null ? C : 0); }), WC(s, (m) => m === 1); }; var 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 = en.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 = en.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 }; }; var 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; }; var 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; }; var sc = (n, e) => { const { range: t, order: o } = n.params || {}; if (!t || !o) return []; if (en.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 []; }; var 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 (en.contains(e, t) && o.push({ type: q.Delete }), en.contains(n, t)) { o.push({ type: q.Delete }); const s = en.getRelativeRange(t, n), r = en.getPositionRange(s, e); return [ { type: q.Set, range: r } ]; } return o; } var 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; }; var 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; }; var 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; }; var 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 = en.subtract(e, s), i = en.getIntersects(s, e); if (!i) return [e]; const a = new kt(); return r.forEach((l) => { tr.foreach(l, (c, d) => { a.setValue(c, d, 1); }); }), i && tr.foreach(i, (l, c) => { a.setValue(l + o, c, 1); }), WC(a, (l) => l === 1); }; var 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; }; var 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 = en.subtract(e, s), i = en.getIntersects(s, e); if (!i) return [e]; const a = new kt(); return r.forEach((l) => { tr.foreach(l, (c, d) => { a.setValue(c, d, 1); }); }), i && tr.foreach(i, (l, c) => { a.setValue(l, c + o, 1); }), WC(a, (l) => l === 1); }; var 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; }; var 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 = en.getIntersects(t, e), i = en.subtract(e, o), a = en.getIntersects(o, e); if (!r && !a) return [e]; const u = new kt(); return a && tr.foreach(a, (c, d) => { u.setValue(c, d - s, 1); }), r && tr.foreach(r, (c, d) => { u.setValue(c, d - s, 0); }), i.forEach((c) => { tr.foreach(c, (d, h) => { u.setValue(d, h, 1); }); }), WC(u, (c) => c === 1); }; var 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; }; var 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 = en.getIntersects(t, e), i = en.subtract(e, o), a = en.getIntersects(o, e); if (!r && !a) return [e]; const u = new kt(); return a && tr.foreach(a, (c, d) => { u.setValue(c - s, d, 1); }), r && tr.foreach(r, (c, d) => { u.setValue(c - s, d, 0); }), i.forEach((c) => { tr.foreach(c, (d, h) => { u.setValue(d, h, 1); }); }), WC(u, (c) => c === 1); }; var Rc = (n, e) => { var s; const t = (s = n.ranges) != null ? s : [n.range], o = new kt(); return tr.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); }), WC(o, (r) => r === 1); }; var pc = (n, e) => { const t = n.params, o = t.range.startRow, s = t.range.endRow - t.range.startRow + 1, r = t.direction; return r === wu.UP && o === e.startRow || r === wu.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 }]; }; var Cc = (n, e) => { const t = n.params, o = t.range.startColumn, s = t.range.endColumn - t.range.startColumn + 1, r = t.direction; return r === wu.LEFT && o === e.startColumn || r === wu.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 }]; }; var Mt2 = (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; }; var 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 Mt2(t, n); }; var dh = (n, e, t) => [Pt2.id, Tt.id].includes(e.id) || qr(e, t).some((r) => en.intersects(r, n)) ? os(n, e) : n; var 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 = Mt2(t, n); return o ? [o] : []; }; var hh = (n, e, t) => [Pt2.id, Tt.id, sn.id, Eo].includes(e.id) || qr(e, t).some((r) => en.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 ot2.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 st2.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 De2.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 kt(o.from).getRange(), i = o.toRange || new kt(o.to).getRange(); s = rc( r, i, n ); } break; } return s ? Array.isArray(s) ? Mt2(s, n) : Mt2([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 st2.id: { const e = n.params; return [ e.sourceRange, { ...e.targetRange, startColumn: e.targetRange.startColumn - 0.5, endColumn: e.targetRange.startColumn - 0.5 } ]; } case ot2.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 kt(e.from.value).getRange(), new kt(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 De2.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(_n), 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 g2 = N(t); return { unitId: g2.unitId, subUnitId: g2.subUnitId, ranges: m }; } } } var Ic = Object.defineProperty; var vc = Object.getOwnPropertyDescriptor; var 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; }; var dn2 = (n, e) => (t, o) => e(t, o, n); var _c = nR("MERGE_REDO"); var bc = nR("MERGE_UNDO"); var rs = Math.floor(Number.MAX_SAFE_INTEGER / 10); var yc = class extends nt { constructor(e, t, o, s, r = false) { 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) => en.intersects(a, this._range))) return; } const t = Sc(this._range, e); if (t && en.equals(t, this._range)) return false; const o = this._range; this._range = t, this._callback(o, t); } }; var _t = class extends nt { constructor(e, t, o, s) { super(); R(this, "interceptor", new rR({ MERGE_REDO: _c, MERGE_UNDO: bc })); R(this, "_watchRanges", /* @__PURE__ */ new Set()); R(this, "_refRangeManagerMap", /* @__PURE__ */ new Map()); R(this, "_serializer", Ec()); R(this, "_onRefRangeChange", () => { this._sheetInterceptorService.interceptCommand({ // eslint-disable-next-line max-lines-per-function getMutations: (e2) => { const t2 = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET).getActiveSheet(), o2 = is(this._univerInstanceService), s2 = as(this._univerInstanceService); if (!t2 || !o2 || !s2) return { redos: [], undos: [], preRedos: [], preUndos: [] }; const a = ((() => { switch (e2.id) { case $.MoveColsCommandId: { const h = e2.params, m = Math.min(h.fromRange.startColumn, h.toRange.startColumn); return this._checkRange( [{ ...h.fromRange, startColumn: m, endColumn: t2.getColumnCount() - 1 }], o2, s2 ); } case $.MoveRowsCommandId: { const h = e2.params, m = Math.min(h.fromRange.startRow, h.toRange.startRow); return this._checkRange( [{ ...h.fromRange, startRow: m, endRow: t2.getRowCount() - 1 }], o2, s2 ); } case $.MoveRangeCommandId: { const h = e2; return this._checkRange( [h.params.fromRange, h.params.toRange], o2, s2 ); } case $.InsertRowCommandId: { const g2 = { startRow: e2.params.range.startRow, endRow: t2.getRowCount() - 1, startColumn: 0, endColumn: t2.getColumnCount() - 1, rangeType: De.ROW }; return this._checkRange([g2], o2, s2); } case $.InsertColCommandId: { const m = e2.params.range.startColumn, g2 = { startRow: 0, endRow: t2.getRowCount() - 1, startColumn: m, endColumn: t2.getColumnCount() - 1, rangeType: De.COLUMN }; return this._checkRange([g2], o2, s2); } case $.RemoveRowCommandId: { const g2 = { startRow: e2.params.range.startRow, endRow: t2.getRowCount() - 1, startColumn: 0, endColumn: t2.getColumnCount() - 1, rangeType: De.ROW }; return this._checkRange([g2], o2, s2); } case $.RemoveColCommandId: { const m = e2.params.range.startColumn, g2 = { startRow: 0, endRow: t2.getRowCount() - 1, startColumn: m, endColumn: t2.getColumnCount() - 1, rangeType: De.COLUMN }; return this._checkRange([g2], o2, s2); } case $.DeleteRangeMoveUpCommandId: case $.InsertRangeMoveDownCommandId: { const m = e2.params.range || us(this._selectionManagerService)[0], g2 = { startRow: m.startRow, startColumn: m.startColumn, endColumn: m.endColumn, endRow: rs }; return this._checkRange([g2], o2, s2); } case $.DeleteRangeMoveLeftCommandId: case $.InsertRangeMoveRightCommandId: { const m = e2.params.range || us(this._selectionManagerService)[0], g2 = { startRow: m.startRow, startColumn: m.startColumn, endColumn: rs, endRow: m.endRow }; return this._checkRange([g2], o2, s2); } case $.ReorderRangeCommandId: { const h = e2, { range: m, order: g2 } = h.params, f = []; for (let p = m.startRow; p <= m.endRow; p++) p in g2 && f.push({ startRow: p, endRow: p, startColumn: m.startColumn, endColumn: m.endColumn }); return this._checkRange(f, o2, s2); } } })() || []).reduce( (h, m) => { const g2 = m(e2); return h.push(g2), h; }, [] ).reduce( (h, m) => { var g2, f; return h.redos.push(...m.redos), h.undos.push(...m.undos), h.preRedos.push(...(g2 = m.preRedos) != null ? g2 : []), 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", (e2, t2, o2) => { const s2 = ls(t2, o2), r = this._refRangeManagerMap.get(s2); 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 }; e2.some((h) => en.intersects(h, d)) && l && l.forEach((h) => { i.add(h); }); }), [...i]; } return []; }); R(this, "registerRefRange", (e2, t2, o2, s2) => { const r = o2 || is(this._univerInstanceService), i = s2 || as(this._univerInstanceService); if (!r || !i) return Ze(() => { }); const a = ls(r, i), u = this._serializer.serialize(e2); 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(t2) : l.set(u, /* @__PURE__ */ new Set([t2])), Ze(() => { const d = l.get(u); d && (d.delete(t2), 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 !== ar.MUTATION) return false; for (const d of this._watchRanges) d.onMutation(c); })); const a = new yc(e, t, o, s, r); this._watchRanges.add(a); const u = Ze(() => { this._watchRanges.delete(a), this._watchRanges.size === 0 && (i == null || i.dispose(), i = null); }), l = this.disposeWithMe(u); return Ze(() => { l.dispose(), u.dispose(); }); } }; _t = Mc([ dn2(0, Pt), dn2(1, ot(V)), dn2(2, ot(_n)), dn2(3, ot(F)) ], _t); function is(n) { return n.getCurrentUnitForType(Fe.UNIVER_SHEET).getUnitId(); } function as(n) { var e; return (e = n.getCurrentUnitForType(Fe.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; var Pc = Object.getOwnPropertyDescriptor; var 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; }; var Rt = (n, e) => (t, o) => e(t, o, n); var kc = [je.id, qe.id, De2.id, Be.id]; var Nc = [ot2.id, st2.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 === yu.ROWS) for (let l = r; l <= i; l++) { const c = { startRow: l, endRow: l, startColumn: a, endColumn: u }; o.push(c); } else if (e === yu.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; } var Oc = nR("mergeCellPermissionCheck"); var Tn = class extends nt { constructor(e, t, o, s, r, i) { super(); R(this, "disposableCollection", new Mi()); R(this, "interceptor", new rR({ 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(Fe.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) => en.intersects(h, d)) )) { const d = { unitId: r, subUnitId: a, ranges: l }, h = Se(e._injector, d), m = [ { id: oe.id, params: d } ], g2 = [ { id: ne.id, params: h } ]; return { redos: m, undos: g2 }; } } } 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) => en.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 zn2.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 Pt2.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$(Fe.UNIVER_SHEET).pipe(first((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((g2) => { if (c <= g2.startRow && d >= g2.endRow) { a.ranges.push(g2); const f = Jr({ id: $.MoveRowsCommandId, params: e }, g2), p = Mt2(f, g2); 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((g2) => { if (c <= g2.startColumn && d >= g2.endColumn) { a.ranges.push(g2); const f = Yr({ id: $.MoveColsCommandId, params: e }, g2), p = Mt2(f, g2); 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) => en.intersects(m, e.fromRange)), u = i.filter((m) => en.intersects(m, e.toRange)), l = a.map((m) => en.getRelativeRange(m, e.fromRange)).map((m) => en.getPositionRange(m, e.toRange)), c = Zr(l).filter( (m) => !i.some((g2) => en.equals(m, g2)) ), 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 = re.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 = re.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 }, g2 = Ue( this._injector, m ), f = [ { id: oe.id, params: d }, { id: ne.id, params: m } ], p = [ { id: oe.id, params: g2 }, { 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 = re.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 = re.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 }, g2 = Ue( this._injector, m ), f = [ { id: oe.id, params: d }, { id: ne.id, params: m } ], p = [ { id: oe.id, params: g2 }, { 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 = re.deepClone(r.getMergeData()).reduce((I, w) => (en.intersects(i, w) && I.push(w), I), []); if (l.length === 0) return this._handleNull(); const c = re.deepClone(r.getMergeData()).reduce((I, w) => { if (en.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 }, g2 = Ue( this._injector, m ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g2 }], 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 = re.deepClone(i.getMergeData()).reduce((I, w) => (en.intersects(s, w) && I.push(w), I), []); if (l.length === 0) return this._handleNull(); const c = re.deepClone(i.getMergeData()).reduce((I, w) => { if (en.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 }, g2 = Ue( this._injector, m ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g2 }], 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 (en.intersects( { startRow: p, startColumn: S, endRow: C, endColumn: a }, f ) && (l.push(f), en.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 }, g2 = Ue( this._injector, m ); return { preRedos: [ { id: oe.id, params: d } ], redos: [ { id: ne.id, params: m } ], preUndos: [ { id: oe.id, params: g2 } ], 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 (en.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), en.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 }, g2 = Ue( this._injector, m ), f = [ { id: oe.id, params: d } ], p = [ { id: ne.id, params: m } ], C = [ { id: oe.id, params: g2 } ], 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 (en.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), en.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) { const P = x - w + 1, A = en.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 }, g2 = Ue( this._injector, m ), f = [ { id: oe.id, params: d } ], p = [ { id: ne.id, params: m } ], C = [ { id: oe.id, params: g2 } ], 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 (en.intersects( { startRow: p, startColumn: S, endRow: C, endColumn: a }, f ) && (l.push(f), en.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 }, g2 = 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: g2 } ] }; } _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; en.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, g2 = (f) => this.refRangeHandle(f, h, m); d.forEach((f) => { this.disposableCollection.add(this._refRangeService.registerRefRange(f, g2, 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: g2 } = e.params, f = (p) => this.refRangeHandle(p, m, g2); h.forEach((p) => { this.disposableCollection.add(this._refRangeService.registerRefRange(p, f, m, g2)); }); } })); } }; Tn = Tc([ Rt(0, ot(Pt)), Rt(1, ot(_t)), Rt(2, ot(_n)), Rt(3, ot(Ot)), Rt(4, ot(V)), Rt(5, ot(F)) ], Tn); function be(n, e) { return e ? n.getUniverSheetInstance(e) : n.getCurrentUnitForType(Fe.UNIVER_SHEET); } function ye(n, e) { return e ? n.getSheetBySheetId(e) : n.getActiveSheet(); } var Dc = Object.defineProperty; var Ac = Object.getOwnPropertyDescriptor; var 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; }; var $c = (n, e) => (t, o) => e(t, o, n); var kn = class extends nt { constructor(n) { super(), this._sheetInterceptorService = n, this._initialize(); } _initialize() { this._initInterceptorCellContent(); } _initInterceptorCellContent() { this.disposeWithMe( this._sheetInterceptorService.intercept(et.CELL_CONTENT, { priority: 11, effect: Vn.Value | Vn.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) === dn.NUMBER && n.v !== void 0 && n.v !== null && DC(n.v) ? t({ ...n, v: _f(Number(n.v)) }) : t({ ...n }); } }) ); } }; kn = xc([ $c(0, ot(V)) ], kn); var Wc = Object.defineProperty; var Lc = Object.getOwnPropertyDescriptor; var 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; }; var $e2 = (n, e) => (t, o) => e(t, o, n); var Nn = class extends nt { constructor(e, t, o, s, r, i, a, u, l, c) { super(); R(this, "disposableCollection", new Mi()); R(this, "_triggerPermissionUIEvent$", new Subject()); 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 wo("have no permission"); } _getPermissionCheck(e, t) { let o = true, s = ""; switch (e) { case on.id: fC(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 === false && this._worksheetProtectionRuleModel.resetOrder(); break; case Do.id: o = this._permissionCheckByWorksheetCommand([Me, bo]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === false && 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 === false && 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 Pt2.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 === _n2.id) { const o = e.params, { unitId: s = (t = this._univerInstanceService.getCurrentUnitForType(Fe.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 false; const { worksheet: o, unitId: s, subUnitId: r } = t, i = re.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) => en.getIntersects(i, c)))); } _permissionCheckByWorksheetCommand(e, t, o) { var l, c; const s = N(this._univerInstanceService, { unitId: t, subUnitId: o }); if (!s) return false; 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 : false : this._permissionService.composePermission(e.map((d) => new d(r).id)).every((d) => d.value); } permissionCheckWithoutRange(e) { var h, m, g2, f; const t = N(this._univerInstanceService); if (!t) return false; const { worksheet: o, unitId: s, subUnitId: r } = t, i = this._selectionManagerService.getCurrentLastSelection(); if (!i) return true; const a = (m = (h = i == null ? void 0 : i.primary) == null ? void 0 : h.actualRow) != null ? m : 0, u = (f = (g2 = i == null ? void 0 : i.primary) == null ? void 0 : g2.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 : false) === false; }) === true || 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 : false) === false; }) === true || d && d.some((C) => { var y, x, T2, 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 false; const I = (T2 = this._rangeProtectionRuleModel.getRule(s, r, S.ruleId)) == null ? void 0 : T2.permissionId; if (!I) return false; const w = new C(s, r, I); return ((P = (U = this._permissionService.getPermissionPoint(w.id)) == null ? void 0 : U.value) != null ? P : false) === false; }) === true); } permissionCheckWithRanges(e, t, o, s) { var m; const r = N(this._univerInstanceService); if (!r) return false; 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((g2) => g2.range); if (!u) return false; const { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e, h = []; return l && h.push(...l.map((g2) => new g2(o).id)), c && h.push(...c.map((g2) => new g2(o, s).id)), d && this._rangeProtectionRuleModel.getSubunitRuleList(o, s).forEach((g2) => { u.some((p) => g2.ranges.some((C) => en.intersects(C, p))) && h.push(...d.map((p) => new p(o, s, g2.permissionId).id)); }), h.length ? this._permissionService.composePermission(h).every((g2) => g2.value) : true; } _permissionCheckByMoveCommand(e) { const t = N(this._univerInstanceService); if (!t) return false; 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) => en.intersects(u, i)); return a.length > 0 ? false : (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]) === false) return false; } }), true); } _permissionCheckByMoveRangeCommand(e) { const t = N(this._univerInstanceService); if (!t) return false; 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) => en.intersects(u, i)); return a.length > 0 ? false : (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]) === false) return false; } }), true); } _permissionCheckBySetRangeValue(e, t) { let o = []; t.range ? o = [t.range] : o = [new kt(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(Fe.UNIVER_SHEET), h = (r = e.unitId) != null ? r : d.getUnitId(), m = this._definedNamesService.getValueByName(h, c); if (m) { let g2 = m.formulaOrRefString; g2.startsWith(X.EQUALS) && (g2 = g2.slice(1)); const f = g2.split(","); for (let p = 0; p < f.length; p++) { const C = f[p], S = fn2(C); if (S.sheetName) { const I = d.getSheetBySheetName(S.sheetName); if (!I) return true; const { startRow: w, endRow: b, startColumn: y, endColumn: x } = S.range; for (let T2 = w; T2 <= b; T2++) for (let U = y; U <= x; U++) { const P = (a = (i = I.getCell(T2, U)) == null ? void 0 : i.selectionProtection) == null ? void 0 : a[0]; if ((P == null ? void 0 : P[_.View]) === false) return false; } } } return true; } else { const g2 = this._lexerTreeBuilder.sequenceNodesBuilder(s); if (!g2) return true; for (let f = 0; f < g2.length; f++) { const p = g2[f]; if (typeof p == "string" || p.nodeType !== $e.REFERENCE) continue; const { token: C } = p, S = mr(C), I = S.unitId ? this._univerInstanceService.getUnit(S.unitId) : this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET); if (!I) return true; 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 true; const P = w == null ? void 0 : w.getSheetId(); if (!this._permissionService.getPermissionPoint(new Hn(b, P).id)) return false; } if (!w) return true; const { startRow: y, endRow: x, startColumn: T2, endColumn: U } = S.range; for (let P = y; P <= x; P++) for (let A = T2; 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]) === false) return false; } } return true; } } if (o) { const c = N(this._univerInstanceService); if (!c) return false; const d = e.unitId || c.unitId, h = e.subUnitId || c.subUnitId, g2 = this._rangeProtectionRuleModel.getSubunitRuleList(d, h).filter((p) => p.ranges.some((C) => en.intersects(C, o))).map((p) => new Pe(d, h, p.permissionId).id); if (!this._permissionService.composePermission(g2).every((p) => p.value)) return false; } return true; } }; Nn = Vc([ $e2(0, Pt), $e2(1, _n), $e2(2, UE), $e2(3, ot(F)), $e2(4, ot(de)), $e2(5, ot(Ye)), $e2(6, ot(Vr)), $e2(7, ot(ca)), $e2(8, fs), $e2(9, pr) ], Nn); var Hc = Object.defineProperty; var Bc = Object.getOwnPropertyDescriptor; var 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; }; var no = (n, e) => (t, o) => e(t, o, n); var ht = class extends nt { constructor(e, t, o) { super(); R(this, "_cellRuleCache", /* @__PURE__ */ new Map()); R(this, "_permissionIdCache", /* @__PURE__ */ new Map()); R(this, "_cellInfoCache", /* @__PURE__ */ new Map()); 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(Fe.UNIVER_SHEET).forEach((e) => { e.getSheets().forEach((t) => { const o = e.getUnitId(), s = t.getSheetId(); this.reBuildCache(o, s); }); }); } _initUpdateCellInfoCache() { this._permissionService.permissionPointUpdate$.pipe( filter((e) => e.type === D.SelectRange), map((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 g2 = d; g2 <= h; g2++) a.delete(`${m}-${g2}`); }); }), this._ruleModel.ruleChange$.subscribe((e) => { var r; const { unitId: t, subUnitId: o } = e, s = this._ensureCellInfoMap(t, o); e.rule.ranges.forEach((i) => { tr.foreach(i, (a, u) => { s.delete(`${a}-${u}`); }); }), e.type === "set" && ((r = e.oldRule) == null || r.ranges.forEach((i) => { tr.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, g2, 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 : true, r = (g2 = (m = this._permissionService.getPermissionPoint((h = new Io(e, t, o.permissionId)) == null ? void 0 : h.id)) == null ? void 0 : m.value) != null ? g2 : true, i = (C = (p = this._permissionService.getPermissionPoint((f = new Vr2(e, t, o.permissionId)) == null ? void 0 : f.id)) == null ? void 0 : p.value) != null ? C : false, 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 : false; 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: g2 } = 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 <= g2; 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 true; const i = r.get(`${o}`); return i ? s.every((u) => { for (const l of i.values()) if (l[u] === false) return false; return true; }) : true; } getColPermissionInfo(e, t, o, s) { var a; const r = (a = this._colInfoCache.get(e)) == null ? void 0 : a.get(t); if (!r) return true; const i = r.get(`${o}`); return i ? s.every((u) => { for (const l of i.values()) if (l[u] === false) return false; return true; }) : true; } _initUpdateRowColInfoCache() { this._permissionService.permissionPointUpdate$.pipe( filter((e) => e.type === D.SelectRange), map((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: g2 } = 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 <= g2; 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 g2 = c; g2 <= d; g2++) { const f = i.get(`${g2}`); 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, ot(de)), no(1, ot(UE)), no(2, ot(_n)) ], ht); var jc = Object.defineProperty; var Gc = Object.getOwnPropertyDescriptor; var 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; }; var Ee = (n, e) => (t, o) => e(t, o, n); var On = class extends nt { 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(true); 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(true); }); }; await Promise.all(this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).map((e) => n(e))), this._rangeProtectionRuleModel.changeRuleInitState(true); } _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(Fe.UNIVER_SHEET)) == null ? void 0 : t.getUnitId()); e && this._authzIoService.allowed({ objectID: e, objectType: D.Workbook, unitID: e, actions: fl2 }).then((o) => { en2().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(Fe.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) => { we2().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); }) : ([...we2(), ...ke()].forEach((e) => { const t = new e(n.unitId, n.subUnitId); this._permissionService.updatePermissionPoint(t.id, true); }), 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(true); return; } this._authzIoService.batchAllowed(t).then((i) => { i.forEach((a) => { const u = r.get(a.objectID); u && [...we2(), ...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(true); }); }; await Promise.all(this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).map((e) => n(e))), this._worksheetProtectionRuleModel.changeRuleInitState(true); } _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(skip(1)).subscribe(() => { const n = this._permissionService.getAllPermissionPoint(); this._permissionService.clearPermissionMap(), this._worksheetProtectionRuleModel.changeRuleInitState(false), this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((t) => { const o = t.getUnitId(); en2().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(); [...we2(), ...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 = false; if (t) { const [i, a] = t; this._authzIoService.allowed({ objectID: e, unitID: n, objectType: D.Worksheet, actions: it }).then((u) => { let l = ""; we2().forEach((c) => { var g2; const d = new c(n, a), h = d.subType, m = u.find((f) => f.action === h); m && (((g2 = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g2.value) !== m.allowed && (o = true), 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((g2) => g2.action === d); h && (((m = this._permissionService.getPermissionPoint(c.id)) == null ? void 0 : m.value) !== h.allowed && (o = true), 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 g2; const d = new c(n, a, e), h = d.subType, m = u.find((f) => f.action === h); m && (((g2 = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g2.value) !== m.allowed && (o = true), 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, _n), Ee(1, UE), Ee(2, bE), Ee(3, ot(de)), Ee(4, ot(Ye)), Ee(5, ot(rr)), Ee(6, ot(un)), Ee(7, ot(V)), Ee(8, ot(cn)), Ee(9, ot(Pt)), Ee(10, ot(ht)) ], On); var Kc = Object.defineProperty; var Jc = Object.getOwnPropertyDescriptor; var 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; }; var hn = (n, e) => (t, o) => e(t, o, n); var Dn = class extends nt { 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: Vn.Value | Vn.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] === false, 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: Vn.Value | Vn.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 : false, [_.Edit]: (l = (u = this._permissionService.getPermissionPoint(new Te(o, s).id)) == null ? void 0 : u.value) != null ? l : false }], h = !((c = d[0]) != null && c[_.View]), m = { ...n, hasWorksheetRule: true, selectionProtection: d }; return h ? (delete m.s, delete m.v, delete m.p, m) : t(m); } return t(n); } } )); } }; Dn = Yc([ hn(0, UE), hn(1, ot(Ye)), hn(2, ot(V)), hn(3, ot(ht)) ], Dn); var Xc = Object.defineProperty; var qc = Object.getOwnPropertyDescriptor; var 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; }; var cs2 = (n, e) => (t, o) => e(t, o, n); var tn = class { constructor(n, e) { R(this, "_cache", new Qr(1e4)); this._selectionProtectionRuleModel = n, this._permissionService = e, this._init(); } _init() { this._permissionService.permissionPointUpdate$.pipe( filter((n) => n.type === D.SelectRange), filter((n) => Ie().some((e) => n instanceof e)), map((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) => { tr.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) => { tr.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) => { tr.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), g2 = this._permissionService.getPermissionPoint(m.id); return d[m.subType] = (f = g2 == null ? void 0 : g2.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([ cs2(0, ot(de)), cs2(1, ot(UE)) ], tn); var ds = Ct("univer.exclusive-range-service"); var Qc = class extends nt { constructor() { super(...arguments); R(this, "_exclusiveRanges", /* @__PURE__ */ new Map()); R(this, "_exclusiveRangesChange$", new Subject()); 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 (en.intersects(r, h.range)) { o.push(c); break; } } } }), o; } }; var ed = Object.defineProperty; var td = Object.getOwnPropertyDescriptor; var 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; }; var oo = (n, e) => (t, o) => e(t, o, n); var co = class extends nt { 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) => { tr.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) => { tr.foreach(u, (l, c) => { const d = s.getCellRaw(l, c); if (d) { const m = { ...r.getStyleByCell(d) || {}, n: { pattern: a.pattern } }, g2 = r.setValue(m); d.s = g2, a.pattern === T && (d.t = dn.STRING); } else { const h = { n: { pattern: a.pattern } }, m = r.setValue(h); m && i.setValue(l, c, { s: m }); } }); }); }); } }; co = nd([ oo(0, Bi), oo(1, _n), oo(2, Mt) ], co); var od = Object.defineProperty; var sd = Object.getOwnPropertyDescriptor; var 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; }; var Qe = (n, e) => (t, o) => e(t, o, n); var hs = [je.id, qe.id, De2.id, Be.id]; var ms = [ot2.id, st2.id]; var An = class extends nt { constructor(e, t, o, s, r, i, a, u) { super(); R(this, "disposableCollection", new Mi()); 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(Fe.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(Fe.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 zn2.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) => en.intersects(a, e.range))), r = e.range; if (s.length) { const i = [], a = []; return s.forEach((u) => { const l = re.deepClone(u), c = l.ranges.reduce((d, h) => { if (en.intersects(h, r)) { const m = re.deepClone(h), { startColumn: g2, endColumn: f } = r; if (g2 <= m.startColumn && f >= m.endColumn) return d; g2 >= m.startColumn && f <= m.endColumn ? m.endColumn -= f - g2 + 1 : g2 < m.startColumn ? (m.startColumn = g2, m.endColumn -= f - g2 + 1) : f > m.endColumn && (m.endColumn = g2 - 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) => en.intersects(a, e.range))), r = e.range; if (s.length) { const i = [], a = []; return s.forEach((u) => { const l = re.deepClone(u), c = l.ranges.reduce((d, h) => { if (en.intersects(h, r)) { const m = re.deepClone(h), { startRow: g2, endRow: f } = r; if (g2 <= m.startRow && f >= m.endRow) return d; g2 >= m.startRow && f <= m.endRow ? m.endRow -= f - g2 + 1 : g2 < m.startRow ? (m.startRow = g2, m.endRow -= f - g2 + 1) : f > m.endRow && (m.endRow = g2 - 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 = re.deepClone(l); let d = false; c.ranges.forEach((h) => { s > h.startColumn && s <= h.endColumn && (h.endColumn += r, d = true); }), 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 = re.deepClone(l); let d = false; c.ranges.forEach((h) => { s > h.startRow && s <= h.endRow && (h.endRow += r, d = true); }), 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 = re.deepClone(c), m = e.fromRange.startRow; let g2 = false; 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, g2 = true); }), g2 && (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 = re.deepClone(c), m = e.fromRange.startColumn; let g2 = false; 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, g2 = true); }), g2 && (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(Fe.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; en.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, g2 = (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, g2, 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, ot(de)), Qe(1, ot(_n)), Qe(2, Pt), Qe(3, ot(_t)), Qe(4, ot(tn)), Qe(5, ot(ht)), Qe(6, ot(V)), Qe(7, ot(de)) ], An); var id = Object.defineProperty; var ad = Object.getOwnPropertyDescriptor; var 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; }; var Dt = (n, e) => (t, o) => e(t, o, n); var ld = "SHEET_RANGE_PROTECTION_PLUGIN"; var xn = class extends nt { 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 = false, this._permissionService.addPermissionPoint(c); }); }), this._selectionProtectionCache.reBuildCache(t, i); }); }, onUnLoad: (t) => { this._selectionProtectionCache.deleteUnit(t); } }) ); } }; xn = ud([ Dt(0, ot(de)), Dt(1, ot(UE)), Dt(2, ot(Bi)), Dt(3, ot(ht)), Dt(4, ot(_n)) ], xn); var cd = Object.defineProperty; var dd = Object.getOwnPropertyDescriptor; var 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; }; var At = (n, e) => (t, o) => e(t, o, n); var $n = class extends nt { 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(); en2().forEach((o) => { const s = new o(t); this._permissionService.addPermissionPoint(s); }); }; this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((e) => { n(e); }), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((e) => { n(e); })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(Fe.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); }); }), [...we2(), ...ke()].forEach((i) => { const a = new i(t, s); this._permissionService.deletePermissionPoint(a.id); }); }), en2().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, ot(UE)), At(1, ot(_n)), At(2, ot(de)), At(3, ot(Ye)), At(4, ot(un)) ], $n); var md = Object.defineProperty; var gd = Object.getOwnPropertyDescriptor; var 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; }; var Rd = (n, e) => (t, o) => e(t, o, n); var ho = class extends nt { 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, ot(He)) ], ho); var Qr2 = Object.defineProperty; var pd = Object.getOwnPropertyDescriptor; var Cd = (n, e, t) => e in n ? Qr2(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t; var 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 && Qr2(e, t, s), s; }; var gs = (n, e) => (t, o) => e(t, o, n); var ei = (n, e, t) => Cd(n, typeof e != "symbol" ? e + "" : e, t); var wd = "SHEET_PLUGIN"; var Wn = class extends Ra { constructor(n = ts, e, t) { super(), this._config = n, this._injector = e, this._configService = t; const { ...o } = nu( {}, 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, true), (e = this._config) != null && e.isRowStylePrecedeColumnStyle && this._configService.setConfig(U0, true), (t = this._config) != null && t.autoHeightForMergedCells && this._configService.setConfig(P0, true); } _initDependencies() { var e; const n = [ // services [kt2], [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]), K0(this._injector, kE(n, this._config.override)), Mf(this._injector, [ [V], [xn], [ds] ]); } onStarting() { Mf(this._injector, [ [yn], [Tn], [$n], [bn], [Dn] ]); } onRendered() { Mf(this._injector, [ [wt], [On] ]); } onReady() { Mf(this._injector, [ [En], [Un], [He], [kn], [tn], [An], [_t], [Nn] ]); } }; ei(Wn, "pluginName", wd); ei(Wn, "type", Fe.UNIVER_SHEET); Wn = Sd([ OR(Fi), gs(1, ot(Ot)), gs(2, SE) ], Wn); var Id = ((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 || {}); var vd = ((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 || {}); var gh = [ nt2.id, Oe.id, Br.id, tt.id, an.id, ot2.id, st2.id, Xt2.id, qt2.id, Qt.id, Zt.id, je.id, qe.id, De2.id, Be.id, Ft.id, Vt.id ]; var 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 kt(e.cellValue).getDataRange() }] : []; } case "sheet.mutation.move-range": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.from.subUnitId, range: new kt(e.from.value).getRange() }, { unitId: e.unitId, subUnitId: e.to.subUnitId, range: new kt(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: De.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: De.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: De.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: De.ROW } })); } case "sheet.mutation.insert-col": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: De.COLUMN } }]; } case "sheet.mutation.insert-row": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: De.ROW } }]; } case "sheet.mutation.remove-col": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: De.COLUMN } }]; } case "sheet.mutation.remove-row": { const e = n.params; return [{ unitId: e.unitId, subUnitId: e.subUnitId, range: { ...e.range, rangeType: De.ROW } }]; } case "sheet.mutation.toggle-gridlines": case "sheet.mutation.set-gridlines-color": return []; default: return []; } } var Ch = 1.5; var 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 }; } var 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: g2, endRow: f, endColumn: p } = i[i.length - 1]; if (r === yu.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 === yu.ROWS) { const w = t.find((b) => b.startRow === h && b.endRow === h && d === b.startColumn); w && (f = w.endRow, g2 = w.startColumn, p = w.endColumn); } const C = { startRow: m, startColumn: g2, endRow: f, endColumn: p, actualRow: h, actualColumn: d, isMerged: true, isMergedMainCell: m === h && g2 === 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: re2.id, params: I }; } return null; } return null; }; var 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: re2.id, params: u }; } return null; }; function fs2(n) { return n == null ? false : n.v !== void 0 && n.v !== null && n.v !== "" || n.p !== void 0; } function Yn(n, e) { return n && n.spanAnchor ? fs2(e.getValue(n.spanAnchor.startRow, n.spanAnchor.startColumn)) : fs2(n); } function _d(n, e, t, o, s) { const r = n.getCellMatrix(), i = n.getSpanModel().getMergedCellRange(e, t, o, s), a = new kt(); 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; Qo(c, h, l, d).forEach((m, g2) => { m === c && g2 === l && a.setValue(m, g2, { ...r.getValue(m, g2), spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d } }), (m !== c || g2 !== l) && (a.realDeleteValue(m, g2), a.setValue(m, g2, { 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 = false; 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: true, range: n }) : { spanAnchor: null, hasValue: false, range: n }; } function yd(n, e, t, o) { const { startRow: s, endColumn: r, endRow: i } = n; let a = null, u = false; 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: true, range: n }) : { spanAnchor: null, hasValue: false, range: n }; } function Ed(n, e, t, o) { const { startRow: s, startColumn: r, endColumn: i } = n; let a = null, u = false; 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: true, range: n }) : { spanAnchor: null, hasValue: false, range: n }; } function Ud(n, e, t, o) { const { startColumn: s, endColumn: r, endRow: i } = n; let a = null, u = false; 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: true, range: n }) : { spanAnchor: null, hasValue: false, 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 = true, h = { ...n }; const m = []; for (; d; ) { if (d = false, l && h.startRow !== 0) { const { hasValue: g2, range: f, spanAnchor: p } = Ed(h, r, 1, i); if (p && m.push(p), g2) { h = f, d = true; continue; } } if (c && h.endRow !== o - 1) { const { hasValue: g2, range: f, spanAnchor: p } = Ud(h, r, 1, i); if (p && m.push(p), g2) { h = f, d = true; continue; } } if (a && h.startColumn !== 0) { const { hasValue: g2, range: f, spanAnchor: p } = bd(h, r, 1, i); if (p && m.push(p), g2) { h = f, d = true; continue; } } if (u && h.endColumn !== s - 1) { const { hasValue: g2, range: f, spanAnchor: p } = yd(h, r, 1, i); if (p && m.push(p), g2) { h = f, d = true; continue; } } } return m.length > 0 && (h = en.union(h, ...m)), h; } var ti = (n, e, t, o = 1, s = true, r = true) => { const i = tr.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, false); } }; var ni = (n, e, t, o = 1, s = true, r = true) => { const i = tr.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, false); } }; var oi = (n, e, t, o = 1, s = true, r = true) => { const i = tr.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, false); } }; var si = (n, e, t, o = 1, s = true, r = true) => { const i = tr.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, false); } }; 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: De.NORMAL }, false)), o || { actualColumn: e, actualRow: n, startRow: n, startColumn: e, endRow: n, endColumn: e, isMerged: false, isMergedMainCell: false, rangeType: De.NORMAL }; } var Pd = (n, e, t, o, s = 1) => { switch (o) { case wu.UP: return ti(n, e, t, s); case wu.DOWN: return ni(n, e, t, s); case wu.LEFT: return oi(n, e, t, s); case wu.RIGHT: return si(n, e, t, s); } }; var _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 === wu.LEFT || e === wu.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, g2 = i ? l.startRow === c && l.startColumn === d : l.endRow === h && l.endColumn === m, f = g2 && i; if (!en.equals(o.range, l)) { const C = g2 ? 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 }; }; var bh = { WorkbookCommentPermission: Ws, WorkbookCopyPermission: Ls, WorkbookCreateProtectPermission: Vs2, WorkbookCreateSheetPermission: Hs, WorkbookDeleteSheetPermission: Bs, WorkbookDuplicatePermission: Fs, WorkbookEditablePermission: Me, WorkbookExportPermission: js, WorkbookHideSheetPermission: vo, WorkbookHistoryPermission: tu, WorkbookManageCollaboratorPermission: Mo, WorkbookMoveSheetPermission: _o, WorkbookPrintPermission: Gs2, WorkbookRecoverHistoryPermission: zs, WorkbookRenameSheetPermission: bo, WorkbookSharePermission: Ks, WorkbookViewHistoryPermission: Ys, WorkbookViewPermission: Js, WorksheetCopyPermission: Xs, WorksheetDeleteColumnPermission: qs, WorksheetDeleteProtectionPermission: Zs, WorksheetDeleteRowPermission: Qs, WorksheetEditExtraObjectPermission: er, WorksheetEditPermission: Te, WorksheetFilterPermission: tr2, WorksheetInsertColumnPermission: nr, WorksheetInsertHyperlinkPermission: or, WorksheetInsertRowPermission: sr, WorksheetManageCollaboratorPermission: rr2, WorksheetPivotTablePermission: ir, WorksheetSelectProtectedCellsPermission: nu2, WorksheetSelectUnProtectedCellsPermission: ou, WorksheetSetCellStylePermission: ar2, WorksheetSetCellValuePermission: wn, WorksheetSetColumnStylePermission: $t, WorksheetSetRowStylePermission: Wt, WorksheetSortPermission: ur, WorksheetViewPermission: Hn, RangeProtectionPermissionEditPoint: Pe, RangeProtectionPermissionViewPoint: Io }; var yh = (n, e, t, o) => { const s = n.get(UE), r = n.get(de), i = s.getPermissionPoint(new Me(e).id); if (!(i != null && i.value)) return false; const a = s.getPermissionPoint(new Te(e, t).id); if (!(a != null && a.value)) return false; const l = r.getSubunitRuleList(e, t).filter((c) => c.ranges.some((d) => o.some((h) => en.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); }) : true; }; 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 = false; return i.forValue((u, l, c) => { if (c && (u !== t || l !== o) && n.cellHasValue(c)) return a = true, false; }), 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, zn.Intercepted), a = new kt(); return i.forValue((u, l, c) => { c && (u !== t || l !== o) && a.setValue(u, l, null); }), a; } var Xn = { type: ar.COMMAND, id: "sheet.command.add-worksheet-merge", handler: (n, e) => { const t = n.get(Pt), o = n.get(cn), s = n.get(_n), 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 }, g2 = { unitId: r, subUnitId: i, ranges: u }; c.push({ id: oe.id, params: m }), c.push({ id: ne.id, params: g2 }); const f = Se(n, m), p = Ue(n, g2); 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 mu(c, t).result ? (o.pushUndoRedo({ unitID: r, undoMutations: d, redoMutations: c }), true) : false; } }; var Eh = { type: ar.COMMAND, id: "sheet.command.add-worksheet-merge-all", handler: async (n) => { var l; const e = n.get(Pt), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range); if (!(o != null && o.length)) return false; const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET); if (!r) return false; const i = r.getActiveSheet(); if (!i) return false; const a = r.getUnitId(), u = i.getSheetId(); return e.executeCommand(Xn.id, { selections: o, unitId: a, subUnitId: u }); } }; var Uh = { type: ar.COMMAND, id: "sheet.command.add-worksheet-merge-vertical", handler: async (n) => { var l; const e = n.get(Pt), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range); if (!(o != null && o.length)) return false; const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET); if (!r) return false; const i = r.getActiveSheet(); if (!i) return false; const a = r.getUnitId(), u = i.getSheetId(); return e.executeCommand(Xn.id, { value: yu.COLUMNS, selections: o, unitId: a, subUnitId: u }); } }; var Ph = { type: ar.COMMAND, id: "sheet.command.add-worksheet-merge-horizontal", handler: async (n) => { var l; const e = n.get(Pt), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range); if (!(o != null && o.length)) return false; const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET); if (!r) return false; const i = r.getActiveSheet(); if (!i) return false; const a = r.getUnitId(), u = i.getSheetId(); return e.executeCommand(Xn.id, { value: yu.ROWS, selections: o, unitId: a, subUnitId: u }); } }; function Th(n, e, t, o, s) { const r = n.get(_n), i = N(r, { unitId: e, subUnitId: t }); if (!i) return; const { worksheet: a } = i; if (a.getMergeData().some((d) => o.some((h) => en.intersects(h, d)))) throw new Error("The ranges to be merged overlap with the existing merged cells"); n.get(Pt).executeCommand(Xn.id, { unitId: e, subUnitId: t, selections: o, defaultMerge: s }); } var Dd = (n, e) => { const r = n.get(_n).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft; return { ...re.deepClone(e), rightToLeft: r }; }; var so = { id: "sheet.mutation.set-worksheet-right-to-left", type: ar.MUTATION, handler: (n, e) => { const t = n.get(_n).getUniverSheetInstance(e.unitId); if (!t) return false; const o = t.getSheetBySheetId(e.subUnitId); if (!o) return false; const s = o.getConfig(); return s.rightToLeft = e.rightToLeft, true; } }; var kh = { type: ar.COMMAND, id: "sheet.command.set-worksheet-right-to-left", handler: async (n, e) => { var d; const t = n.get(Pt), o = n.get(cn), s = N(n.get(_n), e); if (!s) return false; const { unitId: r, subUnitId: i } = s; let a = we.FALSE; e && (a = (d = e.rightToLeft) != null ? d : we.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 } ] }), true) : false; } }; export { T, Ji2 as Ji, Yi, de, Bd, ze, Fd, Ne, Xi2 as Xi, Ye, ct, St, qi, et, ea, Go2 as Go, qn, Zn, V, yt, va, N, Et, zt, Ma, Kt, _a, ba, Os, Ua, Ce, Ta, F, jd, Gd, Aa, Ae, Q, po, Co, So, As, Jt, ja, Ut, xs, dt, Xa, qo, qa, re2 as re, Ln, zd, Kd, ve, Xe2 as Xe, Jd, Vn2 as Vn, pt, wo2 as wo, _, D, Pe, Io, Ws, Ls, eu, Vs2 as Vs, Hs, Bs, Fs, Me, js, vo, tu, Mo, _o, Gs2 as Gs, zs, bo, Ks, Js, Ys, Xs, qs, Zs, Qs, Te, er, tr2 as tr, nr, or, sr, rr2 as rr, ir, nu2 as nu, ou, ar2 as ar, wn, $t, Wt, ur, Hn, on, lr, cr, Yd, Xd, Pt2 as Pt, Tt, su, ru, iu, au, mr2 as mr, qe, yo, je, Be, De2 as De, sn, Bn, mt, fr, du, hu, gt, pr2 as pr, mu2 as mu, gu, fu, Ru, ot2 as ot, pu, st2 as st, Fn, jn, Yt, Uo, wu2 as wu, Ir, vr, Gn, Mr, zn2 as zn, ko, Ue, ne, Se, oe, Iu, Mu, In, uo, kt2 as kt, rn, Tu, ku, Nu, Ou, xu, Lt, $u, Xt2 as Xt, qt2 as qt, Kn, br, yr, Ur, Pr, ut, Bu, Fu, Vt, ju, he, qd, Ct2 as Ct, Gu, zu, Ht, Ku, Zt, Qt, Jn, Tr, kr, fe, Zd, Qd, eh, th, nh, oh, sh, Zu, Qu, el, tl, nl, ol, sl, rl, fn3 as fn, al, Or, Dr, an, Ar, xr, tt, Oo, Mn, Bt, cl, dl, lt, hl, _n2 as _n, Do, Rn, Wr, un, Lr, Vr2 as Vr, Ie, it, rh, en2 as en, fl2 as fl, we2 as we, ke, eo, bn, Ao, Il, vl, ih, nt2 as nt, Oe, Br, $o, Wo, Lo, Fr, Pl, Tl, kl, Ft, Nl, Ol, Dl, Al, xl, jr, Gr, ah, wt, uh, Vo2 as Vo, zr, lh, lo, Wl, Ll, ch, Un, $, q, _e, Pn, Jr, Yr, tc, It, Xr, oc, vt, ic, ac, uc, cc, hc, gc, Mt2 as Mt, os, dh, ss, hh, Sc, mh, _t, Zr, Oc, Tn, Nn, ht, On, tn, ds, Qc, co, An, xn, $n, ho, Wn, Id, vd, gh, fh, Rh, ph, Ch, Sh, wh, Md, Ih, vh, Mh, _h, bh, yh, Xn, Eh, Uh, Ph, Th, so, kh }; //# sourceMappingURL=chunk-BW43Z7N3.js.map