@univerjs/sheets
Version:
UniverSheet normal base-sheets
1,414 lines • 407 kB
JavaScript
var di = Object.defineProperty;
var hi = (n, e, t) => e in n ? di(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var f = (n, e, t) => hi(n, typeof e != "symbol" ? e + "" : e, t);
import { Tools as N, CommandType as v, ICommandService as E, IUndoRedoService as $, createInterceptorKey as ht, Disposable as le, UniverInstanceType as F, InterceptorEffectEnum as de, InterceptorManager as So, toDisposable as Ee, remove as He, composeInterceptors as gi, DisposableCollection as Jt, IUniverInstanceService as M, BooleanNumber as te, HorizontalAlign as wo, BorderStyleTypes as Ms, Inject as L, IResourceManagerService as un, RTree as mi, generateRandomId as Ri, insertMatrixArray as Mn, sliceMatrixArray as _s, concatMatrixArray as ys, spliceArray as bs, normalizeTextRuns as fi, CellValueType as re, isRealNum as Io, isBooleanString as Es, willLoseNumericPrecision as Ci, isSafeNumeric as pi, ObjectMatrix as z, sequenceExecute as J, RxDisposable as Us, LocaleService as Ze, RANGE_TYPE as B, selectionToArray as Si, Rectangle as O, createIdentifier as vo, IContextService as ks, ErrorService as Tt, Range as K, cellToRange as Ts, PermissionStatus as Y, IPermissionService as Ge, isICellData as Ps, mapObjectMatrix as wi, Dimension as fe, getArrayLength as Os, Direction as pe, mergeWorksheetSnapshotWithDefault as Ii, moveMatrixArray as Ns, Injector as jn, BorderType as ce, FontWeight as vi, FontItalic as Mi, ILogService as Ds, DocumentDataModel as _i, BuildTextUtils as yi, TextX as bi, IConfigService as As, Optional as Ei, queryObjectMatrix as Qe, CustomCommandExecutionError as Ui, IAuthzIoService as ki, UserManagerService as Ti, LRUMap as Pi, DependentOn as Oi, Plugin as Ni, merge as Di, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE as Ai, AUTO_HEIGHT_FOR_MERGED_CELLS as xi, registerDependencies as Wi, mergeOverrideWithDependencies as $i, touchDependencies as Rn, createRowColIter as Li, CellModeEnum as Vi } from "@univerjs/core";
import { SetDefinedNameMutation as Yt, RemoveDefinedNameMutation as _n, SetDefinedNameMutationFactory as Hi, SetFormulaCalculationResultMutation as Bi, handleNumfmtInCell as Fi, IDefinedNamesService as xs, stripErrorMargin as ji, LexerTreeBuilder as Gi, operatorToken as zi, deserializeRangeWithSheet as Ki, sequenceNodeType as Ji, deserializeRangeWithSheetWithCache as Yi, UniverFormulaEnginePlugin as qi } from "@univerjs/engine-formula";
import { DataSyncPrimaryController as Xi } from "@univerjs/rpc";
import { Subject as We, BehaviorSubject as at, merge as $t, shareReplay as Zi, takeUntil as go, switchMap as Ye, of as At, distinctUntilChanged as Qi, skip as Ws, map as mo, first as ea, filter as Jo } from "rxjs";
import { isTextFormat as so } from "@univerjs/engine-numfmt";
import { takeUntil as Yo, filter as qo, map as ta } from "rxjs/operators";
var na = /* @__PURE__ */ ((n) => (n.OthersCanView = "othersCanView", n.NoOneElseCanView = "noOneElseCanView", n))(na || {}), oa = /* @__PURE__ */ ((n) => (n.DesignedUserCanEdit = "designedUserCanEdit", n.OnlyMe = "onlyMe", n))(oa || {});
class me {
constructor() {
/**
* Map<unitId, Map<subUnitId, Map<ruleId, IRangeProtectionRule>>>
*/
f(this, "_model", /* @__PURE__ */ new Map());
f(this, "_ruleChange$", new We());
f(this, "ruleChange$", this._ruleChange$.asObservable());
f(this, "_ruleRefresh$", new We());
f(this, "ruleRefresh$", this._ruleRefresh$.asObservable());
f(this, "_rangeRuleInitStateChange", new at(!1));
f(this, "rangeRuleInitStateChange$", this._rangeRuleInitStateChange.asObservable());
}
dispose() {
this._ruleChange$.complete(), this._ruleRefresh$.complete();
}
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 = N.generateRandomId(4);
const s = this._ensureRuleMap(e, t);
for (; s.has(o); )
o = N.generateRandomId(4);
return o;
}
getTargetByPermissionId(e, t) {
const o = this._model.get(e);
if (!o) return null;
for (const [s, r] of o)
for (const i of r.values())
if (i.permissionId === t)
return [e, s];
return null;
}
}
const Zd = (n, e) => {
const t = n.get(me), o = e.ruleIds.map((r) => t.getRule(e.unitId, e.subUnitId, r)).filter((r) => !!r);
return { id: $e.id, params: { subUnitId: e.subUnitId, unitId: e.unitId, rules: o } };
}, qe = {
id: "sheet.mutation.delete-range-protection",
type: v.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: o, ruleIds: s } = e, r = n.get(me);
return s.forEach((i) => {
r.deleteRule(t, o, i);
}), !0;
}
}, Qd = (n) => {
const e = { ...n, ruleIds: n.rules.map((t) => t.id) };
return { id: qe.id, params: e };
}, $e = {
id: "sheet.mutation.add-range-protection",
type: v.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: o, rules: s } = e, r = n.get(me);
return s.forEach((i) => {
r.addRule(t, o, i);
}), !0;
}
}, sa = {
type: v.COMMAND,
id: "sheet.command.add-range-protection",
async handler(n, e) {
if (!e)
return !1;
const t = n.get(E), o = n.get($), s = n.get(me), { rule: r, permissionId: i } = e, { unitId: a, subUnitId: u, ranges: l, description: c, viewState: d, editState: h } = r, g = [{
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($e.id, {
unitId: a,
subUnitId: u,
rules: g
})) {
const R = [{ id: $e.id, params: { unitId: a, subUnitId: u, rules: g } }], C = [{ id: qe.id, params: { unitId: a, subUnitId: u, ruleIds: g.map((p) => p.id) } }];
o.pushUndoRedo({
unitID: a,
redoMutations: R,
undoMutations: C
});
}
return !0;
}
};
class et {
constructor() {
/**
*
* Map<unitId, Map<subUnitId, Map<subUnitId, IWorksheetProtectionRule>>>
*/
f(this, "_model", /* @__PURE__ */ new Map());
f(this, "_ruleChange", new We());
f(this, "_ruleRefresh", new We());
f(this, "_resetOrder", new We());
f(this, "ruleChange$", this._ruleChange.asObservable());
f(this, "ruleRefresh$", this._ruleRefresh.asObservable());
f(this, "resetOrder$", this._resetOrder.asObservable());
f(this, "_worksheetRuleInitStateChange", new at(!1));
f(this, "worksheetRuleInitStateChange$", this._worksheetRuleInitStateChange.asObservable());
}
changeRuleInitState(e) {
this._worksheetRuleInitStateChange.next(e);
}
getSheetRuleInitState() {
return this._worksheetRuleInitStateChange.value;
}
addRule(e, t) {
this._ensureSubUnitMap(e).set(t.subUnitId, t), this._ruleChange.next({ unitId: e, rule: t, type: "add", subUnitId: t.subUnitId });
}
deleteRule(e, t) {
var s, r, i;
const o = (r = (s = this._model) == null ? void 0 : s.get(e)) == null ? void 0 : r.get(t);
o && ((i = this._model.get(e)) == null || i.delete(t), this._ruleChange.next({ unitId: e, rule: o, type: "delete", subUnitId: t }));
}
setRule(e, t, o) {
var r, i;
const s = this.getRule(e, t);
s && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.set(t, o), this._ruleChange.next({ unitId: e, oldRule: s, rule: o, type: "set", subUnitId: t }));
}
getRule(e, t) {
var o, s;
return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
}
toObject() {
const e = {};
return [...this._model.keys()].forEach((o) => {
const s = this._model.get(o);
s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
const a = s.get(i);
a && e[o].push(a);
}));
}), e;
}
fromObject(e) {
const t = /* @__PURE__ */ new Map();
Object.keys(e).forEach((o) => {
const s = e[o];
if (s != null && s.length) {
const r = /* @__PURE__ */ new Map();
s.forEach((i) => {
r.set(i.subUnitId, i);
}), t.set(o, r);
}
}), this._model = t;
}
deleteUnitModel(e) {
this._model.delete(e);
}
_ensureSubUnitMap(e) {
let t = this._model.get(e);
return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
}
ruleRefresh(e) {
this._ruleRefresh.next(e);
}
resetOrder() {
this._resetOrder.next(Math.random());
}
getTargetByPermissionId(e, t) {
const o = this._model.get(e);
if (!o) return null;
for (const [s, r] of o)
if (r.permissionId === t)
return [e, s];
}
}
const pt = {
id: "sheet.mutation.add-worksheet-protection",
type: v.MUTATION,
handler: (n, e) => {
const { unitId: t, rule: o } = e;
return n.get(et).addRule(t, o), !0;
}
}, Mt = {
id: "sheet.mutation.delete-worksheet-protection",
type: v.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: o } = e;
return n.get(et).deleteRule(t, o), !0;
}
}, ra = {
type: v.COMMAND,
id: "sheet.command.add-worksheet-protection",
async handler(n, e) {
if (!e)
return !1;
const t = n.get(E), o = n.get($), { rule: s, unitId: r } = e, i = s.subUnitId;
if (await t.executeCommand(pt.id, {
unitId: r,
rule: s,
subUnitId: s.subUnitId
})) {
const u = [{ id: pt.id, params: { unitId: r, rule: s, subUnitId: s.subUnitId } }], l = [{ id: Mt.id, params: { unitId: r, subUnitId: i } }];
o.pushUndoRedo({
unitID: r,
redoMutations: u,
undoMutations: l
});
}
return !0;
}
}, ia = ht("CELL_CONTENT"), aa = ht("ROW_FILTERED"), it = {
CELL_CONTENT: ia,
ROW_FILTERED: aa
};
var ua = /* @__PURE__ */ ((n) => (n[n.DATA_VALIDATION = 9] = "DATA_VALIDATION", n[n.NUMFMT = 10] = "NUMFMT", n[n.CELL_IMAGE = 11] = "CELL_IMAGE", n))(ua || {});
const $s = "sheet.interceptor.range-theme-id", Xo = "sheet.interceptor.ignore-range-theme";
var la = Object.getOwnPropertyDescriptor, ca = (n, e, t, o) => {
for (var s = o > 1 ? void 0 : o ? la(e, t) : e, r = n.length - 1, i; r >= 0; r--)
(i = n[r]) && (s = i(s) || s);
return s;
}, da = (n, e) => (t, o) => e(t, o, n);
const Zo = ht("BEFORE_CELL_EDIT"), ro = ht("AFTER_CELL_EDIT"), io = ht("VALIDATE_CELL");
let G = class extends le {
/** @ignore */
constructor(e) {
super();
f(this, "_interceptorsByName", /* @__PURE__ */ new Map());
f(this, "_commandInterceptors", []);
f(this, "_rangeInterceptors", []);
f(this, "_autoHeightInterceptors", []);
f(this, "_beforeCommandInterceptor", []);
f(this, "_afterCommandInterceptors", []);
f(this, "_workbookDisposables", /* @__PURE__ */ new Map());
f(this, "_worksheetDisposables", /* @__PURE__ */ new Map());
f(this, "_interceptorsDirty", !1);
f(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map());
f(this, "writeCellInterceptor", new So({
BEFORE_CELL_EDIT: Zo,
AFTER_CELL_EDIT: ro,
VALIDATE_CELL: io
}));
this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(F.UNIVER_SHEET).subscribe((t) => {
this._interceptWorkbook(t);
})), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(F.UNIVER_SHEET).subscribe(
(t) => this._disposeWorkbookInterceptor(t)
)), this.intercept(it.CELL_CONTENT, {
priority: -1,
effect: de.Style | de.Value,
handler: (t) => t
}), this.disposeWithMe(this.writeCellInterceptor.intercept(ro, {
priority: -1,
handler: (t) => t
})), this.disposeWithMe(this.writeCellInterceptor.intercept(Zo, {
priority: -1,
handler: (t) => t
})), this.disposeWithMe(this.writeCellInterceptor.intercept(io, {
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(Ee(() => He(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(Ee(() => He(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()
};
}
interceptAutoHeight(e) {
if (this._autoHeightInterceptors.includes(e))
throw new Error("[SheetInterceptorService]: Interceptor already exists!");
return this._autoHeightInterceptors.push(e), this._autoHeightInterceptors.sort((t, o) => {
var s, r;
return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
}), this.disposeWithMe(Ee(() => He(this._autoHeightInterceptors, e)));
}
generateMutationsOfAutoHeight(e) {
const t = this._autoHeightInterceptors.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()
};
}
/**
* 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(Ee(() => He(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<boolean>
*/
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(Ee(() => He(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
onWriteCell(e, t, o, s, r) {
const i = {
subUnitId: t.getSheetId(),
unitId: e.getUnitId(),
workbook: e,
worksheet: t,
row: o,
col: s,
origin: N.deepClone(r)
};
return this.writeCellInterceptor.fetchThroughInterceptors(ro)(r, i);
}
// #endregion
onValidateCell(e, t, o, s) {
const r = {
subUnitId: t.getSheetId(),
unitId: e.getUnitId(),
workbook: e,
worksheet: t,
row: o,
col: s
};
return this.writeCellInterceptor.fetchThroughInterceptors(io)(Promise.resolve(!0), r);
}
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 (this._interceptorsDirty = !0, o === it.CELL_CONTENT) {
const i = de.Style | de.Value;
this._interceptorsByName.set(`${o}-${i}`, r);
const a = de.Style | de.Value;
return this._interceptorsByName.set(
`${o}-${de.Style}`,
r.filter((u) => ((u.effect || a) & de.Style) > 0)
), this._interceptorsByName.set(
`${o}-${de.Value}`,
r.filter((u) => ((u.effect || a) & de.Value) > 0)
), this.disposeWithMe(Ee(() => {
He(this._interceptorsByName.get(o), t), He(this._interceptorsByName.get(`${o}-${i}`), t), He(this._interceptorsByName.get(`${o}-${de.Style}`), t), He(this._interceptorsByName.get(`${o}-${de.Value}`), t);
}));
} else
return this._interceptorsByName.set(o, r), this.disposeWithMe(Ee(() => He(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 = gi(u || []), this._composedInterceptorByKey.set(i, a);
}
return a;
}
_interceptWorkbook(e) {
const t = new Jt(), o = e.getUnitId(), s = this, r = (i) => {
const a = i.getSheetId();
i.__interceptViewModel((u) => {
const l = new Jt();
s._worksheetDisposables.set(Qo(o, i), l), l.add(u.registerCellContentInterceptor({
getCell(c, d, h, g, m) {
const R = i.getCellRaw(c, d);
return s.fetchThroughInterceptors(it.CELL_CONTENT, h, g, m)(
R,
{
unitId: o,
subUnitId: a,
row: c,
col: d,
worksheet: i,
workbook: e,
rawData: R
}
);
}
})), l.add(u.registerRowFilteredInterceptor({
getRowFiltered(c) {
return !!s.fetchThroughInterceptors(it.ROW_FILTERED)(
!1,
{
unitId: o,
subUnitId: a,
row: c,
workbook: e,
worksheet: i
}
);
}
}));
});
};
e.getSheets().forEach((i) => r(i)), t.add(e.sheetCreated$.subscribe((i) => r(i))), t.add(Ee(() => 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 = Qo(e, t), s = this._worksheetDisposables.get(o);
s && (s.dispose(), this._worksheetDisposables.delete(o));
}
};
G = ca([
da(0, M)
], G);
function Qo(n, e) {
return `${n}|${e.getSheetId()}`;
}
const he = (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 ha(n) {
const e = {};
if (n.length === 1)
return n[0];
for (const t of n)
t.bg && (e.bg = t.bg), t.ol && (e.ol = t.ol), t.bd && (e.bd = { ...e.bd, ...t.bd }), t.cl && (e.cl = t.cl), t.ht && (e.ht = t.ht), t.vt && (e.vt = t.vt), t.bl !== void 0 && (e.bl = t.bl);
return e;
}
const ge = {
wholeStyle: 1,
headerRowStyle: 2,
headerColumnStyle: 4,
firstRowStyle: 8,
secondRowStyle: 16,
lastRowStyle: 32,
firstColumnStyle: 128,
secondColumnStyle: 256,
lastColumnStyle: 512
};
class gt {
/**
* @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) {
f(this, "_name");
/**
* @property {Nullable<IRangeThemeStyleItem>} wholeStyle effect for the whole range.
*/
f(this, "wholeStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} headerRowStyle effect for the header row.
*/
f(this, "headerRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} headerColumnStyle effect for the header column.
*/
f(this, "headerColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} firstRowStyle effect for the first row.
*/
f(this, "firstRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} secondRowStyle effect for the second row.
*/
f(this, "secondRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} lastRowStyle effect for the last row.
*/
f(this, "lastRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} firstColumnStyle effect for the first column.
*/
f(this, "firstColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} secondColumnStyle effect for the second column.
*/
f(this, "secondColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} lastColumnStyle effect for the last column.
*/
f(this, "lastColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} quickly get merge style
*/
f(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, this._resetStyleCache();
}
getFirstRowStyle() {
return this.firstRowStyle;
}
setFirstRowStyle(e) {
this.firstRowStyle = e, this._resetStyleCache();
}
getSecondRowStyle() {
return this.secondRowStyle;
}
setSecondRowStyle(e) {
this.secondRowStyle = e, this._resetStyleCache();
}
getLastRowStyle() {
return this.lastRowStyle;
}
setLastRowStyle(e) {
this.lastRowStyle = e, this._resetStyleCache();
}
getFirstColumnStyle() {
return this.firstColumnStyle;
}
setFirstColumnStyle(e) {
this.firstColumnStyle = e, this._resetStyleCache();
}
getSecondColumnStyle() {
return this.secondColumnStyle;
}
setSecondColumnStyle(e) {
this.secondColumnStyle = e, this._resetStyleCache();
}
getLastColumnStyle() {
return this.lastColumnStyle;
}
setLastColumnStyle(e) {
this.lastColumnStyle = e, this._resetStyleCache();
}
getHeaderRowStyle() {
return this.headerRowStyle;
}
setHeaderRowStyle(e) {
this.headerRowStyle = e, this._resetStyleCache();
}
getHeaderColumnStyle() {
return this.headerColumnStyle;
}
setHeaderColumnStyle(e) {
this.headerColumnStyle = e, this._resetStyleCache();
}
getStyle(e, t, o, s) {
let r = 0;
return o && (r = r | ge.lastRowStyle), s && (r = r | ge.lastColumnStyle), e >= 0 && t >= 0 && (r = r | ge.wholeStyle), e % 2 === 1 && (r = r | ge.firstRowStyle), e % 2 === 0 && (r = r | ge.secondRowStyle), e === 0 && (r = r | ge.headerRowStyle), t === 0 && (r = r | ge.headerColumnStyle), t % 2 === 1 && (r = r | ge.firstColumnStyle), t % 2 === 0 && (r = r | ge.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 & ge.wholeStyle && t.push(this.wholeStyle), this.firstColumnStyle && e & ge.firstColumnStyle && t.push(this.firstColumnStyle), this.secondColumnStyle && e & ge.secondColumnStyle && t.push(this.secondColumnStyle), this.firstRowStyle && e & ge.firstRowStyle && t.push(this.firstRowStyle), this.secondRowStyle && e & ge.secondRowStyle && t.push(this.secondRowStyle), this.headerColumnStyle && e & ge.headerColumnStyle && t.push(this.headerColumnStyle), this.lastColumnStyle && e & ge.lastColumnStyle && t.push(this.lastColumnStyle), this.headerRowStyle && e & ge.headerRowStyle && t.push(this.headerRowStyle), this.lastRowStyle && e & ge.lastRowStyle && t.push(this.lastRowStyle), ha(t);
}
_resetStyleCache() {
this._mergeCacheMap.clear();
}
toJson() {
const e = {
name: this._name
};
return this.wholeStyle && (e.wholeStyle = he(this.wholeStyle)), this.headerRowStyle && (e.headerRowStyle = he(this.headerRowStyle)), this.headerColumnStyle && (e.headerColumnStyle = he(this.headerColumnStyle)), this.firstRowStyle && (e.firstRowStyle = he(this.firstRowStyle)), this.secondRowStyle && (e.secondRowStyle = he(this.secondRowStyle)), this.lastRowStyle && (e.lastRowStyle = he(this.lastRowStyle)), this.firstColumnStyle && (e.firstColumnStyle = he(this.firstColumnStyle)), this.secondColumnStyle && (e.secondColumnStyle = he(this.secondColumnStyle)), this.lastColumnStyle && (e.lastColumnStyle = he(this.lastColumnStyle)), e;
}
fromJson(e) {
this._name = e.name, e.wholeStyle && (this.wholeStyle = he(e.wholeStyle)), e.headerRowStyle && (this.headerRowStyle = he(e.headerRowStyle)), e.headerColumnStyle && (this.headerColumnStyle = he(e.headerColumnStyle)), e.firstRowStyle && (this.firstRowStyle = he(e.firstRowStyle)), e.secondRowStyle && (this.secondRowStyle = he(e.secondRowStyle)), e.lastRowStyle && (this.lastRowStyle = he(e.lastRowStyle)), e.firstColumnStyle && (this.firstColumnStyle = he(e.firstColumnStyle)), e.secondColumnStyle && (this.secondColumnStyle = he(e.secondColumnStyle)), e.lastColumnStyle && (this.lastColumnStyle = he(e.lastColumnStyle));
}
dispose() {
this._mergeCacheMap.clear();
}
}
const ga = (n, e, t) => new gt(`light-${n}`, {
headerRowStyle: {
bg: {
rgb: e
}
},
firstColumnStyle: {
bg: {
rgb: "rgb(255, 255, 255)"
}
},
secondColumnStyle: {
bg: {
rgb: t
}
},
lastRowStyle: {
bg: {
rgb: e
}
}
}), ma = (n, e, t) => new gt(`middle-${n}`, {
headerRowStyle: {
bg: {
rgb: e
}
},
headerColumnStyle: {
bg: {
rgb: t
}
},
secondRowStyle: {
bg: {
rgb: t
}
},
lastRowStyle: {
bg: {
rgb: e
}
},
lastColumnStyle: {
bg: {
rgb: t
}
}
}), Ra = (n, e, t, o) => new gt(`dark-${n}`, {
headerRowStyle: {
bg: {
rgb: e
},
cl: {
rgb: "rgb(255, 255, 255)"
},
ht: wo.CENTER,
bl: te.TRUE
},
firstRowStyle: {
bg: {
rgb: t
}
},
secondRowStyle: {
bg: {
rgb: o
}
},
lastRowStyle: {
bg: {
rgb: e
}
}
}), fa = [
{
baseName: "blue",
header: "rgb(164, 202, 254)",
color: "rgb(225, 239, 254)"
},
{
baseName: "grey",
header: "rgb(205, 208, 216)",
color: "rgb(238, 239, 241)"
},
{
baseName: "red",
header: "rgb(248, 180, 180)",
color: "rgb(253, 232, 232)"
},
{
baseName: "orange",
header: "rgb(253, 186, 140)",
color: "rgb(254, 236, 220)"
},
{
baseName: "yellow",
header: "rgb(250, 200, 21)",
color: "rgb(255, 244, 185)"
},
{
baseName: "green",
header: "rgb(132, 225, 188)",
color: "rgb(222, 247, 236)"
},
{
baseName: "azure",
header: "rgb(126, 220, 226)",
color: "rgb(213, 245, 246)"
},
{
baseName: "indigo",
header: "rgb(186, 198, 248)",
color: "rgb(233, 237, 255)"
},
{
baseName: "purple",
header: "rgb(202, 191, 253)",
color: "rgb(237, 235, 254)"
},
{
baseName: "magenta",
header: "rgb(248, 180, 217)",
color: "rgb(252, 232, 243)"
}
], Ca = [
{
baseName: "blue",
rowHeader: "rgb(63, 131, 248)",
colHeader: "rgb(195, 221, 253)"
},
{
baseName: "grey",
rowHeader: "rgb(95, 101, 116)",
colHeader: "rgb(227, 229, 234)"
},
{
baseName: "red",
rowHeader: "rgb(240, 82, 82)",
colHeader: "rgb(251, 213, 213)"
},
{
baseName: "orange",
rowHeader: "rgb(255, 90, 31)",
colHeader: "rgb(252, 217, 189)"
},
{
baseName: "yellow",
rowHeader: "rgb(212, 157, 15)",
colHeader: "rgb(252, 220, 106)"
},
{
baseName: "green",
rowHeader: "rgb(13, 164, 113)",
colHeader: "rgb(188, 240, 218)"
},
{
baseName: "azure",
rowHeader: "rgb(6, 148, 162)",
colHeader: "rgb(175, 236, 239)"
},
{
baseName: "indigo",
rowHeader: "rgb(70, 106, 247)",
colHeader: "rgb(210, 218, 250)"
},
{
baseName: "purple",
rowHeader: "rgb(144, 97, 249)",
colHeader: "rgb(220, 215, 254)"
},
{
baseName: "magenta",
rowHeader: "rgb(231, 70, 148)",
colHeader: "rgb(250, 209, 232)"
}
], pa = [
{
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)"
}
], Sa = fa.map(({ baseName: n, header: e, color: t }) => ga(n, e, t)), wa = Ca.map(({ baseName: n, rowHeader: e, colHeader: t }) => ma(n, e, t)), Ia = pa.map(({ baseName: n, rowHeader: e, firstRow: t, secondRow: o }) => Ra(n, e, t, o)), va = [
...Sa,
...wa,
...Ia
], Ls = {
headerRowStyle: {
bg: {
rgb: "rgb(68,114,196)"
},
cl: {
rgb: "rgb(255,255,255)"
},
ht: wo.CENTER,
bl: te.TRUE
},
firstRowStyle: {
bg: {
rgb: "rgb(217,225,242)"
}
}
}, Ma = new gt("default", Ls), _a = new gt("default-last-row", {
...Ls,
lastRowStyle: {
bd: {
t: {
s: Ms.THIN,
cl: {
rgb: "rgb(68,114,196)"
}
}
},
ht: wo.CENTER,
bl: te.TRUE
}
});
var ya = Object.getOwnPropertyDescriptor, ba = (n, e, t, o) => {
for (var s = o > 1 ? void 0 : o ? ya(e, t) : e, r = n.length - 1, i; r >= 0; r--)
(i = n[r]) && (s = i(s) || s);
return s;
}, es = (n, e) => (t, o) => e(t, o, n);
const Ea = "SHEET_RANGE_THEME_MODEL_PLUGIN";
let ye = class extends le {
constructor(e, t) {
super();
f(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
f(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
f(this, "_rTreeCollection", /* @__PURE__ */ new Map());
f(this, "_defaultRangeThemeMap", /* @__PURE__ */ new Map());
f(this, "_rangeThemeMapChanged$", new We());
f(this, "rangeThemeMapChange$", this._rangeThemeMapChanged$.asObservable());
this._sheetInterceptorService = e, this._resourceManagerService = t, this._registerIntercept(), this._initSnapshot(), this._initDefaultTheme();
}
_initDefaultTheme() {
this.registerDefaultRangeTheme(Ma), this.registerDefaultRangeTheme(_a);
for (const e of va)
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 mi()), this._rTreeCollection.get(e);
}
getDefaultRangeThemeStyle(e) {
return this._defaultRangeThemeMap.get(e);
}
getCustomRangeThemeStyle(e, t) {
return this._ensureRangeThemeStyleMap(e).get(t);
}
/**
* Register range theme styles
* @param {string} themeName
* @param {IRangeThemeRangeInfo} rangeInfo
*/
registerRangeThemeRule(e, t) {
const { unitId: o, subUnitId: s, range: r } = t, i = Ri(), 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 }])), u = this._ensureRangeThemeStyleRuleMap(o);
for (let l = 0; l < a.length; l++) {
const c = u.get(a[l]);
if (c && c.themeName === e) {
u.delete(a[l]), i.remove({ unitId: o, sheetId: s, range: r, id: a[l] });
break;
}
}
}
registerDefaultRangeTheme(e) {
this._defaultRangeThemeMap.set(e.getName(), e), this._rangeThemeMapChanged$.next({ type: "add", styleName: e.getName() });
}
unRegisterDefaultRangeTheme(e) {
this._defaultRangeThemeMap.delete(e), this._rangeThemeMapChanged$.next({ type: "remove", styleName: 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), this._rangeThemeMapChanged$.next({ type: "add", styleName: t.getName() });
}
/**
* 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), this._rangeThemeMapChanged$.next({ type: "remove", styleName: t });
}
/**
* Gets all custom register themes
* @param {string} unitId Which unit to register the range theme style.
* @return {string[]} The array of all custom registered themes.
*/
getALLRegisteredTheme(e) {
return Array.from(this._ensureRangeThemeStyleMap(e).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, g = s - c.range.startColumn, m = this.getRangeThemeStyle(e, d);
if (m)
return m.getStyle(h, g, o === c.range.endRow, s === c.range.endColumn);
}
}
}
_registerIntercept() {
this.disposeWithMe(this._sheetInterceptorService.intercept(it.CELL_CONTENT, {
id: $s,
effect: de.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 || e === t.rawData ? { ...t.rawData } : 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, t) {
const { rangeThemeStyleRuleMap: o, rangeThemeStyleMapJson: s } = t;
o && Object.keys(o).forEach((r) => {
const i = o[r], { themeName: a, rangeInfo: u } = i;
a.startsWith("table") || (this.registerRangeThemeRule(a, u), this._ensureRTreeCollection(u.unitId).insert({ unitId: r, sheetId: u.subUnitId, range: u.range, id: r }));
}), s && Object.keys(s).forEach((r) => {
const i = s[r], a = new gt(i.name);
a.fromJson(i), this._ensureRangeThemeStyleMap(e).set(a.getName(), a);
});
}
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: [F.UNIVER_SHEET],
pluginName: Ea,
onLoad: (e, t) => {
this.fromJSON(e, t);
},
onUnLoad: (e) => {
this.deleteUnitId(e);
}
}));
}
dispose() {
super.dispose(), this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._defaultRangeThemeMap.clear(), this._rTreeCollection.clear();
}
};
ye = ba([
es(0, L(G)),
es(1, L(un))
], ye);
function Vs(n, e) {
const { unitId: t } = e, o = t ? n.getUnit(t, F.UNIVER_SHEET) : n.getCurrentUnitOfType(F.UNIVER_SHEET);
return o ? {
workbook: o,
unitId: o.getUnitId()
} : null;
}
function k(n, e = {}) {
const { unitId: t, subUnitId: o } = e, s = t ? n.getUnit(t, F.UNIVER_SHEET) : n.getCurrentUnitOfType(F.UNIVER_SHEET);
if (!s) return null;
const r = o ? s.getSheetBySheetId(o) : s.getActiveSheet(!0);
return r ? {
worksheet: r,
workbook: s,
unitId: s.getUnitId(),
subUnitId: r.getSheetId()
} : null;
}
function ze(n, e) {
const { unitId: t, subUnitId: o } = e, s = n.getUnit(t, F.UNIVER_SHEET);
if (!s) return null;
const r = s.getSheetBySheetId(o);
return r ? {
worksheet: r,
workbook: s
} : null;
}
const qt = {
id: "sheet.mutation.set-worksheet-range-theme-style",
type: v.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = k(i), u = n.get(ye);
return a ? (u.registerRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1;
}
}, Ua = (n, e) => {
const t = ze(n.get(M), e);
if (!t)
throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");
const { worksheet: o } = t;
return {
unitId: e.unitId,
subUnitId: o.getSheetId(),
range: e.range,
themeName: e.themeName
};
}, Xt = {
id: "sheet.mutation.remove-worksheet-range-theme-style",
type: v.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = k(i), u = n.get(ye);
return a ? (u.removeRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1;
}
}, ka = (n, e) => {
const t = ze(n.get(M), e);
if (!t)
throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");
const { worksheet: o } = t;
return {
unitId: e.unitId,
subUnitId: o.getSheetId(),
range: e.range,
themeName: e.themeName
};
}, Ta = {
type: v.COMMAND,
id: "sheet.command.set-worksheet-range-theme-style",
handler: (n, e) => {
const t = n.get(E), o = n.get($), { unitId: s } = e, r = Ua(n, e);
return t.syncExecuteCommand(qt.id, e) ? (o.pushUndoRedo({
unitID: s,
undoMutations: [{ id: Xt.id, params: r }],
redoMutations: [{ id: qt.id, params: e }]
}), !0) : !1;
}
}, Mo = (n, e) => {
if (n.get(M).getUniverSheetInstance(e.unitId) == null)
throw new Error("universheet is null error!");
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
range: e.range
};
}, Ke = {
id: "sheet.mutation.insert-row",
type: v.MUTATION,
handler: (n, e) => {
var m;
const { unitId: t, subUnitId: o, range: s, rowInfo: r } = e, a = n.get(M).getUniverSheetInstance(t);
if (a == null)
throw new Error("universheet is null error!");
const u = a.getSheetBySheetId(o);
if (u == null)
throw new Error("worksheet is null error!");
const l = u.getRowManager().getRowData(), c = {
h: u.getConfig().defaultRowHeight,
hd: 0
}, d = s.startRow, h = s.endRow - s.startRow + 1;
for (let R = d; R < d + h; R++)
r ? Mn(R, (m = r[R - s.startRow]) != null ? m : c, l) : Mn(R, c, l);
return u.setRowCount(u.getRowCount() + s.endRow - s.startRow + 1), u.getCellMatrix().insertRows(s.startRow, h), !0;
}
}, Gn = (n, e) => {
if (n.get(M).getUniverSheetInstance(e.unitId) == null)
throw new Error("universheet is null error!");
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
range: e.range
};
}, Ve = {
id: "sheet.mutation.insert-col",
type: v.MUTATION,
handler: (n, e) => {
var m;
const o = n.get(M).getUniverSheetInstance(e.unitId);
if (o == null)
throw new Error("universheet is null error!");
const s = o.getSheetBySheetId(e.subUnitId);
if (!s) return !1;
const r = s.getColumnManager(), { range: i, colInfo: a } = e, l = r.getColumnData(), c = i.startColumn, d = i.endColumn - i.startColumn + 1, h = s.getConfig().defaultColumnWidth;
for (let R = c; R < c + d; R++) {
const C = {
w: h,
hd: 0
};
a ? Mn(R, (m = a[R - i.startColumn]) != null ? m : C, l) : Mn(R, C, l);
}
return s.setColumnCount(s.getColumnCount() + i.endColumn - i.startColumn + 1), s.getCellMatrix().insertColumns(i.startColumn, d), !0;
}
}, Pa = (n, e) => {
const s = e.getRowManager().getRowData(), r = {}, i = n.range, a = _s(i.startRow, i.endRow, s), u = ys(r, a);
return {
unitId: n.unitId,
subUnitId: n.subUnitId,
range: n.range,
rowInfo: u
};
}, Je = {
id: "sheet.mutation.remove-rows",
type: v.MUTATION,
handler: (n, e) => {
const o = n.get(M).getUniverSheetInstance(e.unitId);
if (o == null)
throw new Error("universheet is null error!");
const s = o.getSheetBySheetId(e.subUnitId);
if (!s) return !1;
const r = e.range, a = s.getRowManager().getRowData();
for (let c = r.startRow; c <= r.endRow; c++)
s.getRowFiltered(c);
const u = r.endRow - r.startRow + 1;
return bs(r.startRow, u, a), s.getCellMatrix().removeRows(r.startRow, u), s.setRowCount(s.getRowCount() - u), !0;
}
}, Oa = (n, e) => {
const o = n.get(M).getUniverSheetInstance(e.unitId);
if (o == null)
throw new Error("universheet is null error!");
const s = o.getSheetBySheetId(e.subUnitId);
if (s == null)
throw new Error("worksheet is null error!");
const a = s.getColumnManager().getColumnData(), u = {}, l = e.range, c = _s(l.startColumn, l.endColumn, a), d = ys(u, c);
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
range: e.range,
colInfo: d
};
}, ke = {
id: "sheet.mutation.remove-col",
type: v.MUTATION,
handler: (n, e) => {
const o = n.get(M).getUniverSheetInstance(e.unitId);
if (o == null)
throw new Error("universheet is null error!");
const s = o.getSheetBySheetId(e.subUnitId);
if (!s) return !1;
const r = e.range, a = s.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1;
return bs(r.startColumn, u, a), s.setColumnCount(s.getColumnCount() - u), s.getCellMatrix().removeColumns(r.startColumn, u), !0;
}
};
function Na(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 = wn(o, t.s ? t.s : null);
s && (N.removeNull(s), Object.entries(s).forEach(([a, u]) => {
typeof u == "object" && u !== null && Object.keys(u).length === 0 && delete s[a];
})), N.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 : xa(e.p, t.s ? t.s : null));
}
function Da(n, e) {
if (!e || !Object.keys(e).length)
return n;
const t = N.deepClone(n != null ? n : {});
for (const o in e)
o === "bd" ? t[o] = Aa(t[o] || {}, e[o]) : o in t || (t[o] = null);
return t;
}
function Aa(n, e) {
if (!e || !Object.keys(e).length)
return n;
for (const t in e)
t in n || (n[t] = null);
return n;
}
function wn(n, e, t = !1) {
if (e === null) return e;
if (e === void 0) return n;
const o = N.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 Hs(n, e) {
return n.some((t) => t.startIndex === e) ? Hs(n, e + 1) : e;
}
function xa(n, e) {
var i;
if (n.bod