| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409 |
- var Rt = Object.defineProperty;
- var St = (s, a, e) => a in s ? Rt(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e;
- var f = (s, a, e) => St(s, typeof a != "symbol" ? a + "" : a, e);
- import { Inject as S, ICommandService as x, IUniverInstanceService as O, Disposable as $, ObjectMatrix as ve, UniverInstanceType as N, Range as b, isFormulaString as v, DataValidationType as T, getOriginCellValue as vt, RBush as Vt, debounce as Mt, Rectangle as I, Tools as V, DataValidationStatus as D, WrapStrategy as Se, DataValidationOperator as h, numfmt as Q, dayjs as at, DataValidationRenderMode as Be, CommandType as z, IUndoRedoService as Z, sequenceExecute as Ie, isRangesEqual as rt, generateRandomId as yt, toDisposable as qe, IPermissionService as Et, Injector as Ge, CellValueType as Tt, RxDisposable as Ft, LifecycleService as Nt, LifecycleStages as ze, bufferDebounceTime as Ct, DependentOn as Ot, Plugin as wt, merge as It, IConfigService as At } from "@univerjs/core";
- import { DataValidationModel as ke, DataValidatorRegistryService as G, UpdateRuleType as y, BaseDataValidator as k, TextLengthErrorTitleMap as Dt, AddDataValidationMutation as L, RemoveDataValidationMutation as A, UpdateDataValidationMutation as E, getRuleSetting as bt, getRuleOptions as Lt, UniverDataValidationPlugin as xt } from "@univerjs/data-validation";
- import { SetRangeValuesMutation as oe, RemoveSheetMutation as it, getSheetCommandTarget as Ye, SetRangeValuesUndoMutationFactory as st, WorksheetViewPermission as Bt, RefRangeService as Ut, handleCommonDefaultRangeChangeWithEffectRefCommands as Pt, SheetInterceptorService as ot, RemoveSheetCommand as $t, SheetsSelectionsService as nt, ClearSelectionAllCommand as Ht } from "@univerjs/sheets";
- import { Subject as Qe, bufferWhen as Wt, filter as Ze } from "rxjs";
- import { RegisterOtherFormulaService as lt, FormulaRefRangeService as ut } from "@univerjs/sheets-formula";
- import { ERROR_TYPE_SET as jt, LexerTreeBuilder as Y, isReferenceString as dt, sequenceNodeType as Qt, deserializeRangeWithSheet as qt, deserializeRangeWithSheetWithCache as Gt, operatorToken as kt } from "@univerjs/engine-formula";
- const Yt = "SHEET_DATA_VALIDATION_PLUGIN";
- var Xt = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, zt = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? Kt(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && Xt(a, e, r), r;
- }, Je = (s, a) => (e, t) => a(e, t, s);
- let q = class extends $ {
- constructor(a, e) {
- super();
- f(this, "_cacheMatrix", /* @__PURE__ */ new Map());
- f(this, "_dirtyRanges$", new Qe());
- f(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
- this._commandService = a, this._univerInstanceService = e, this._initDirtyRanges(), this._initSheetRemove();
- }
- _initDirtyRanges() {
- this.disposeWithMe(this._commandService.onCommandExecuted((a) => {
- if (a.id === oe.id) {
- const { cellValue: e, unitId: t, subUnitId: r } = a.params;
- if (e) {
- const i = new ve(e).getDataRange();
- if (i.endRow === -1) return;
- this.markRangeDirty(t, r, [i]);
- }
- }
- }));
- }
- _initSheetRemove() {
- this.disposeWithMe(this._commandService.onCommandExecuted((a) => {
- var e;
- if (a.id === it.id) {
- const { unitId: t, subUnitId: r } = a.params;
- (e = this._cacheMatrix.get(t)) == null || e.delete(r);
- }
- })), this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((a) => {
- a.type === N.UNIVER_SHEET && this._cacheMatrix.delete(a.getUnitId());
- }));
- }
- _ensureCache(a, e) {
- let t = this._cacheMatrix.get(a);
- t || (t = /* @__PURE__ */ new Map(), this._cacheMatrix.set(a, t));
- let r = t.get(e);
- return r || (r = new ve(), t.set(e, r)), r;
- }
- ensureCache(a, e) {
- return this._ensureCache(a, e);
- }
- addRule(a, e, t) {
- this.markRangeDirty(a, e, t.ranges);
- }
- removeRule(a, e, t) {
- this._deleteRange(a, e, t.ranges);
- }
- markRangeDirty(a, e, t) {
- const r = this._ensureCache(a, e);
- t.forEach((i) => {
- b.foreach(i, (o, n) => {
- r.setValue(o, n, void 0);
- });
- }), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
- }
- _deleteRange(a, e, t) {
- const r = this._ensureCache(a, e);
- t.forEach((i) => {
- b.foreach(i, (o, n) => {
- r.realDeleteValue(o, n);
- });
- }), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
- }
- getValue(a, e, t, r) {
- return this._ensureCache(a, e).getValue(t, r);
- }
- };
- q = zt([
- Je(0, S(x)),
- Je(1, S(O))
- ], q);
- function se(s) {
- var a, e;
- return (e = (a = s == null ? void 0 : s[0]) == null ? void 0 : a[0]) == null ? void 0 : e.v;
- }
- function ge(s) {
- var a;
- return (a = s == null ? void 0 : s[0]) == null ? void 0 : a[0];
- }
- function C(s) {
- return !jt.has(s);
- }
- function de(s, a) {
- var t;
- const e = a.getValidatorItem(s);
- return (t = e == null ? void 0 : e.offsetFormulaByRange) != null ? t : !1;
- }
- var Zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, ea = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? Jt(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && Zt(a, e, r), r;
- }, re = (s, a) => (e, t) => a(e, t, s);
- let P = class extends $ {
- constructor(a, e, t, r, i) {
- super();
- /**
- * Map of origin formula of rule
- */
- f(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
- f(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
- this._instanceSrv = a, this._registerOtherFormulaService = e, this._dataValidationModel = t, this._dataValidationCacheService = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
- }
- _initFormulaResultHandler() {
- this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
- for (const e in a) {
- const t = a[e];
- if (this._instanceSrv.getUnitType(e) === N.UNIVER_SHEET)
- for (const i in t) {
- const o = t[i], { ruleFormulaMap: n } = this._ensureMaps(e, i);
- o.forEach((l) => {
- var c, m;
- const u = n.get((c = l.extra) == null ? void 0 : c.ruleId), d = this._dataValidationModel.getRuleById(e, i, (m = l.extra) == null ? void 0 : m.ruleId);
- d && u && this._dataValidationCacheService.markRangeDirty(e, i, d.ranges);
- });
- }
- }
- }));
- }
- _ensureMaps(a, e) {
- let t = this._ruleFormulaMap.get(a), r = this._ruleFormulaMap2.get(a);
- t || (t = /* @__PURE__ */ new Map(), this._ruleFormulaMap.set(a, t)), r || (r = /* @__PURE__ */ new Map(), this._ruleFormulaMap2.set(a, r));
- let i = t.get(e);
- i || (i = /* @__PURE__ */ new Map(), t.set(e, i));
- let o = r.get(e);
- return o || (o = /* @__PURE__ */ new Map(), r.set(e, o)), { ruleFormulaMap: i, ruleFormulaMap2: o };
- }
- _registerFormula(a, e, t, r, i) {
- return this._registerOtherFormulaService.registerFormulaWithRange(a, e, r, i, { ruleId: t });
- }
- deleteByRuleId(a, e, t) {
- const { ruleFormulaMap: r, ruleFormulaMap2: i } = this._ensureMaps(a, e), o = this._dataValidationModel.getRuleById(a, e, t), n = r.get(t);
- if (!o || !n)
- return;
- const l = r.get(t);
- l && (r.delete(t), this._registerOtherFormulaService.deleteFormula(a, e, [l.formulaId]));
- const u = i.get(t);
- u && (i.delete(t), this._registerOtherFormulaService.deleteFormula(a, e, [u.formulaId]));
- }
- _addFormulaByRange(a, e, t, r, i, o) {
- const { ruleFormulaMap: n, ruleFormulaMap2: l } = this._ensureMaps(a, e), u = o[0].startRow, d = o[0].startColumn;
- if (r && v(r)) {
- const c = this._registerFormula(a, e, t, r, o);
- n.set(t, {
- formula: r,
- originCol: d,
- originRow: u,
- formulaId: c
- });
- }
- if (i && v(i)) {
- const c = this._registerFormula(a, e, t, i, o);
- l.set(t, {
- formula: i,
- originCol: d,
- originRow: u,
- formulaId: c
- });
- }
- }
- addRule(a, e, t) {
- if (de(t.type, this._validatorRegistryService)) {
- const { ranges: r, formula1: i, formula2: o, uid: n } = t;
- this._addFormulaByRange(a, e, n, i, o, r);
- }
- }
- async getCellFormulaValue(a, e, t, r, i) {
- var _, g;
- const { ruleFormulaMap: o } = this._ensureMaps(a, e), n = o.get(t);
- if (!n)
- return Promise.resolve(void 0);
- const l = await this._registerOtherFormulaService.getFormulaValue(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
- }
- async getCellFormula2Value(a, e, t, r, i) {
- var _, g;
- const { ruleFormulaMap2: o } = this._ensureMaps(a, e), n = o.get(t);
- if (!n)
- return Promise.resolve(void 0);
- const l = await this._registerOtherFormulaService.getFormulaValue(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
- }
- getCellFormulaValueSync(a, e, t, r, i) {
- var _, g;
- const { ruleFormulaMap: o } = this._ensureMaps(a, e), n = o.get(t);
- if (!n)
- return;
- const l = this._registerOtherFormulaService.getFormulaValueSync(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
- }
- getCellFormula2ValueSync(a, e, t, r, i) {
- var _, g;
- const { ruleFormulaMap2: o } = this._ensureMaps(a, e), n = o.get(t);
- if (!n)
- return;
- const l = this._registerOtherFormulaService.getFormulaValueSync(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
- }
- getRuleFormulaInfo(a, e, t) {
- const { ruleFormulaMap: r } = this._ensureMaps(a, e);
- return r.get(t);
- }
- };
- P = ea([
- re(0, O),
- re(1, S(lt)),
- re(2, S(ke)),
- re(3, S(q)),
- re(4, S(G))
- ], P);
- var ta = Object.defineProperty, aa = Object.getOwnPropertyDescriptor, ra = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? aa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && ta(a, e, r), r;
- }, ie = (s, a) => (e, t) => a(e, t, s);
- let K = class extends $ {
- constructor(a, e, t, r, i) {
- super();
- f(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
- this._instanceService = a, this._registerOtherFormulaService = e, this._dataValidationCacheService = t, this._dataValidationModel = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
- }
- _initFormulaResultHandler() {
- this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
- for (const e in a) {
- const t = a[e];
- if (this._instanceService.getUnitType(e) === N.UNIVER_SHEET)
- for (const i in t) {
- const o = t[i], n = this._ensureRuleFormulaMap(e, i);
- o.forEach((l) => {
- var u, d;
- if (n.get((u = l.extra) == null ? void 0 : u.ruleId)) {
- const c = this._dataValidationModel.getRuleById(e, i, (d = l.extra) == null ? void 0 : d.ruleId);
- c && this._dataValidationCacheService.markRangeDirty(e, i, c.ranges);
- }
- });
- }
- }
- }));
- }
- _ensureRuleFormulaMap(a, e) {
- let t = this._formulaRuleMap.get(a);
- t || (t = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(a, t));
- let r = t.get(e);
- return r || (r = /* @__PURE__ */ new Map(), t.set(e, r)), r;
- }
- _registerSingleFormula(a, e, t, r) {
- const i = [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }];
- return this._registerOtherFormulaService.registerFormulaWithRange(a, e, t, i, { ruleId: r });
- }
- addRule(a, e, t) {
- if (!de(t.type, this._validatorRegistryService) && t.type !== T.CHECKBOX) {
- const { formula1: r, formula2: i, uid: o } = t, n = v(r), l = v(i);
- if (!n && !l)
- return;
- const u = this._ensureRuleFormulaMap(a, e), d = [void 0, void 0];
- if (n) {
- const c = this._registerSingleFormula(a, e, r, o);
- d[0] = { id: c, text: r };
- }
- if (l) {
- const c = this._registerSingleFormula(a, e, i, o);
- d[1] = { id: c, text: i };
- }
- u.set(o, d);
- }
- }
- removeRule(a, e, t) {
- const i = this._ensureRuleFormulaMap(a, e).get(t);
- if (!i)
- return;
- const [o, n] = i, l = [o == null ? void 0 : o.id, n == null ? void 0 : n.id].filter(Boolean);
- l.length && this._registerOtherFormulaService.deleteFormula(a, e, l);
- }
- getRuleFormulaResult(a, e, t) {
- const i = this._ensureRuleFormulaMap(a, e).get(t);
- if (!i)
- return Promise.resolve(null);
- const o = async (n) => n && this._registerOtherFormulaService.getFormulaValue(a, e, n.id);
- return Promise.all([
- o(i[0]),
- o(i[1])
- ]);
- }
- getRuleFormulaResultSync(a, e, t) {
- const i = this._ensureRuleFormulaMap(a, e).get(t);
- if (i)
- return i.map((o) => {
- if (o)
- return this._registerOtherFormulaService.getFormulaValueSync(a, e, o.id);
- });
- }
- getRuleFormulaInfo(a, e, t) {
- return this._ensureRuleFormulaMap(a, e).get(t);
- }
- };
- K = ra([
- ie(0, O),
- ie(1, S(lt)),
- ie(2, S(q)),
- ie(3, S(ke)),
- ie(4, S(G))
- ], K);
- function ne(s) {
- return vt(s);
- }
- function ct(s) {
- var a;
- return String((a = ne(s)) != null ? a : "");
- }
- class Xe {
- constructor(a, e, t, r, i = !1) {
- f(this, "_map");
- f(this, "_tree", new Vt());
- f(this, "_dirty", !0);
- f(this, "_buildTree", () => {
- if (!this._dirty || this._disableTree)
- return;
- this._tree.clear();
- const a = [];
- this._map.forEach((e, t) => {
- e.forEach((r) => {
- a.push({
- minX: r.startRow,
- maxX: r.endRow,
- minY: r.startColumn,
- maxY: r.endColumn,
- ruleId: t
- });
- });
- }), this._tree.load(a), this._dirty = !1;
- });
- f(this, "_debonceBuildTree", Mt(this._buildTree, 0));
- this._unitId = e, this._subUnitId = t, this._univerInstanceService = r, this._disableTree = i, this._map = a, this._buildTree();
- }
- get _worksheet() {
- var a;
- return (a = this._univerInstanceService.getUnit(this._unitId, N.UNIVER_SHEET)) == null ? void 0 : a.getSheetBySheetId(this._subUnitId);
- }
- _addRule(a, e) {
- if (!this._worksheet)
- return;
- const t = I.mergeRanges(e.map((r) => b.transformRange(r, this._worksheet)));
- this._map.forEach((r, i) => {
- const o = I.subtractMulti(r, t);
- o.length === 0 ? this._map.delete(i) : this._map.set(i, o);
- }), this._dirty = !0, this._map.set(a, t), this._debonceBuildTree();
- }
- addRule(a) {
- this._addRule(a.uid, a.ranges);
- }
- removeRange(a) {
- if (!this._worksheet)
- return;
- const e = a.map((t) => b.transformRange(t, this._worksheet));
- this._map.forEach((t, r) => {
- const i = I.subtractMulti(t, e);
- i.length === 0 ? this._map.delete(r) : this._map.set(r, i);
- }), this._dirty = !0, this._debonceBuildTree();
- }
- _removeRule(a) {
- this._map.delete(a), this._dirty = !0, this._debonceBuildTree();
- }
- removeRule(a) {
- this._removeRule(a.uid);
- }
- updateRange(a, e) {
- this._removeRule(a), this._addRule(a, e);
- }
- addRangeRules(a) {
- a.forEach(({ id: e, ranges: t }) => {
- if (!t.length)
- return;
- let r = this._map.get(e);
- r ? (this._map.set(e, I.mergeRanges([...r, ...t])), r = this._map.get(e)) : (r = t, this._map.set(e, r)), this._map.forEach((i, o) => {
- if (o === e)
- return;
- const n = I.subtractMulti(i, t);
- n.length === 0 ? this._map.delete(o) : this._map.set(o, n);
- });
- }), this._dirty = !0, this._debonceBuildTree();
- }
- diff(a) {
- const e = [];
- let t = 0;
- return a.forEach((r, i) => {
- var l;
- const o = (l = this._map.get(r.uid)) != null ? l : [], n = r.ranges;
- o.length !== 0 && (o.length !== n.length || o.some((u, d) => !I.equals(u, n[d]))) && e.push({
- type: "update",
- ruleId: r.uid,
- oldRanges: n,
- newRanges: I.sort(o),
- rule: r
- }), o.length === 0 && (e.push({
- type: "delete",
- rule: r,
- index: i - t
- }), t++);
- }), e;
- }
- diffWithAddition(a, e) {
- const t = [];
- let r = 0;
- return a.forEach((i, o) => {
- var u;
- const n = (u = this._map.get(i.uid)) != null ? u : [], l = i.ranges;
- n.length !== 0 && (n.length !== l.length || n.some((d, c) => !I.equals(d, l[c]))) && t.push({
- type: "update",
- ruleId: i.uid,
- oldRanges: l,
- newRanges: I.sort(n),
- rule: i
- }), n.length === 0 && (t.push({
- type: "delete",
- rule: i,
- index: o - r
- }), r++);
- }), Array.from(e).forEach((i) => {
- var n;
- const o = (n = this._map.get(i.uid)) != null ? n : [];
- t.push({
- type: "add",
- rule: {
- ...i,
- ranges: I.sort(o)
- }
- });
- }), t;
- }
- clone() {
- return new Xe(
- new Map(V.deepClone(Array.from(this._map.entries()))),
- this._unitId,
- this._subUnitId,
- this._univerInstanceService,
- // disable tree on cloned matrix, cause there is no need to search
- !0
- );
- }
- getValue(a, e) {
- this._dirty && this._buildTree();
- const t = this._tree.search({
- minX: a,
- maxX: a,
- minY: e,
- maxY: e
- });
- return t.length > 0 ? t[0].ruleId : void 0;
- }
- }
- var ia = Object.defineProperty, sa = Object.getOwnPropertyDescriptor, oa = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? sa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && ia(a, e, r), r;
- }, X = (s, a) => (e, t) => a(e, t, s);
- let F = class extends $ {
- constructor(a, e, t, r, i, o, n) {
- super();
- f(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
- f(this, "_validStatusChange$", new Qe());
- f(this, "_ruleChange$", new Qe());
- f(this, "ruleChange$", this._ruleChange$.asObservable());
- f(this, "validStatusChange$", this._validStatusChange$.asObservable());
- this._dataValidationModel = a, this._univerInstanceService = e, this._dataValidatorRegistryService = t, this._dataValidationCacheService = r, this._dataValidationFormulaService = i, this._dataValidationCustomFormulaService = o, this._commandService = n, this._initRuleUpdateListener(), this.disposeWithMe(() => {
- this._ruleChange$.complete(), this._validStatusChange$.complete();
- }), this._initUniverInstanceListener();
- }
- _initUniverInstanceListener() {
- this.disposeWithMe(
- this._univerInstanceService.unitDisposed$.subscribe((a) => {
- this._ruleMatrixMap.delete(a.getUnitId());
- })
- ), this.disposeWithMe(
- this._commandService.onCommandExecuted((a) => {
- if (a.id === it.id) {
- const { unitId: e, subUnitId: t } = a.params, r = this._ruleMatrixMap.get(e);
- r && r.delete(t);
- }
- })
- );
- }
- _initRuleUpdateListener() {
- const a = this._dataValidationModel.getAll();
- for (const [e, t] of a)
- for (const [r, i] of t)
- for (const o of i)
- this._addRule(e, r, o), this._ruleChange$.next({
- type: "add",
- unitId: e,
- subUnitId: r,
- rule: o,
- source: "patched"
- });
- this.disposeWithMe(
- this._dataValidationModel.ruleChange$.subscribe((e) => {
- switch (e.type) {
- case "add":
- this._addRule(e.unitId, e.subUnitId, e.rule);
- break;
- case "update":
- this._updateRule(e.unitId, e.subUnitId, e.rule.uid, e.oldRule, e.updatePayload);
- break;
- case "remove":
- this._removeRule(e.unitId, e.subUnitId, e.rule);
- break;
- }
- this._ruleChange$.next(e);
- })
- );
- }
- _ensureRuleMatrix(a, e) {
- let t = this._ruleMatrixMap.get(a);
- t || (t = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(a, t));
- let r = t.get(e);
- return r || (r = new Xe(/* @__PURE__ */ new Map(), a, e, this._univerInstanceService), t.set(e, r)), r;
- }
- _addRuleSideEffect(a, e, t) {
- this._ensureRuleMatrix(a, e).addRule(t), this._dataValidationCacheService.addRule(a, e, t), this._dataValidationFormulaService.addRule(a, e, t), this._dataValidationCustomFormulaService.addRule(a, e, t);
- }
- _addRule(a, e, t) {
- (Array.isArray(t) ? t : [t]).forEach((i) => {
- this._addRuleSideEffect(a, e, i);
- });
- }
- _updateRule(a, e, t, r, i) {
- const o = this._ensureRuleMatrix(a, e), n = {
- ...r,
- ...i.payload
- };
- i.type === y.RANGE ? o.updateRange(t, i.payload) : i.type === y.ALL && o.updateRange(t, i.payload.ranges), this._dataValidationCacheService.removeRule(a, e, r), this._dataValidationCacheService.addRule(a, e, n), this._dataValidationFormulaService.removeRule(a, e, r.uid), this._dataValidationFormulaService.addRule(a, e, n), this._dataValidationCustomFormulaService.deleteByRuleId(a, e, t), this._dataValidationCustomFormulaService.addRule(a, e, n);
- }
- _removeRule(a, e, t) {
- this._ensureRuleMatrix(a, e).removeRule(t), this._dataValidationCacheService.removeRule(a, e, t), this._dataValidationCustomFormulaService.deleteByRuleId(a, e, t.uid);
- }
- getValidator(a) {
- return this._dataValidatorRegistryService.getValidatorItem(a);
- }
- getRuleIdByLocation(a, e, t, r) {
- return this._ensureRuleMatrix(a, e).getValue(t, r);
- }
- getRuleByLocation(a, e, t, r) {
- const i = this.getRuleIdByLocation(a, e, t, r);
- if (i)
- return this._dataValidationModel.getRuleById(a, e, i);
- }
- validator(a, e, t) {
- const { col: r, row: i, unitId: o, subUnitId: n, worksheet: l } = e, u = (g, R) => {
- t && t(g, R), R && this._validStatusChange$.next({
- unitId: o,
- subUnitId: n,
- ruleId: a.uid,
- status: g,
- row: i,
- col: r
- });
- }, d = l.getCellValueOnly(i, r), c = this.getValidator(a.type), m = l.getCellRaw(i, r), _ = ne(m);
- if (c) {
- const g = this._dataValidationCacheService.ensureCache(o, n), R = g.getValue(i, r);
- return R == null ? (g.setValue(i, r, D.VALIDATING), c.validator(
- {
- value: _,
- unitId: o,
- subUnitId: n,
- row: i,
- column: r,
- worksheet: e.worksheet,
- workbook: e.workbook,
- interceptValue: ne(d),
- t: m == null ? void 0 : m.t
- },
- a
- ).then((M) => {
- const p = M ? D.VALID : D.INVALID;
- p === D.VALID ? g.realDeleteValue(i, r) : g.setValue(i, r, p);
- const w = g.getValue(i, r);
- u(p, R !== w);
- }), D.VALIDATING) : (u(R != null ? R : D.VALID, !1), R != null ? R : D.VALID);
- } else
- return u(D.VALID, !1), D.VALID;
- }
- getRuleObjectMatrix(a, e) {
- return this._ensureRuleMatrix(a, e);
- }
- getRuleById(a, e, t) {
- return this._dataValidationModel.getRuleById(a, e, t);
- }
- getRuleIndex(a, e, t) {
- return this._dataValidationModel.getRuleIndex(a, e, t);
- }
- getRules(a, e) {
- return [...this._dataValidationModel.getRules(a, e)];
- }
- getUnitRules(a) {
- return this._dataValidationModel.getUnitRules(a);
- }
- deleteUnitRules(a) {
- return this._dataValidationModel.deleteUnitRules(a);
- }
- getSubUnitIds(a) {
- return this._dataValidationModel.getSubUnitIds(a);
- }
- getAll() {
- return this._dataValidationModel.getAll();
- }
- };
- F = oa([
- X(0, S(ke)),
- X(1, O),
- X(2, S(G)),
- X(3, S(q)),
- X(4, S(K)),
- X(5, S(P)),
- X(6, x)
- ], F);
- const Ve = 1, Me = 0;
- function et(s, a) {
- return V.isBlank(s) ? a.t("dataValidation.validFail.value") : v(s) ? a.t("dataValidation.validFail.primitive") : "";
- }
- const _e = (s) => V.isDefine(s) && String(s).toLowerCase() === "true" ? "1" : String(s).toLowerCase() === "false" ? "0" : s;
- class na extends k {
- constructor() {
- super(...arguments);
- f(this, "id", T.CHECKBOX);
- f(this, "title", "dataValidation.checkbox.title");
- f(this, "operators", []);
- f(this, "scopes", ["sheet"]);
- f(this, "offsetFormulaByRange", !1);
- f(this, "_formulaService", this.injector.get(K));
- f(this, "skipDefaultFontRender", (e, t, r) => {
- const { unitId: i, subUnitId: o } = r, { formula1: n, formula2: l } = this.parseFormulaSync(e, i, o), u = `${t != null ? t : ""}`;
- return !u || u === `${n}` || u === `${l}`;
- });
- }
- validatorFormula(e, t, r) {
- const { formula1: i, formula2: o } = e, n = i === o;
- if (V.isBlank(i) && V.isBlank(o))
- return {
- success: !0
- };
- if (n)
- return {
- success: !1,
- formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
- formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
- };
- const l = et(i, this.localeService), u = et(o, this.localeService);
- return {
- success: !l && !u,
- formula1: l,
- formula2: u
- };
- }
- async parseFormula(e, t, r) {
- var c, m, _, g;
- const { formula1: i = Ve, formula2: o = Me } = e, n = await this._formulaService.getRuleFormulaResult(t, r, e.uid), l = v(i) ? se((m = (c = n == null ? void 0 : n[0]) == null ? void 0 : c.result) == null ? void 0 : m[0][0]) : i, u = v(o) ? se((g = (_ = n == null ? void 0 : n[1]) == null ? void 0 : _.result) == null ? void 0 : g[0][0]) : o, d = C(String(l)) && C(String(u));
- return {
- formula1: _e(l),
- formula2: _e(u),
- originFormula1: l,
- originFormula2: u,
- isFormulaValid: d
- };
- }
- getExtraStyle(e, t) {
- return {
- tb: Se.CLIP
- };
- }
- parseFormulaSync(e, t, r) {
- var c, m, _, g;
- const { formula1: i = Ve, formula2: o = Me } = e, n = this._formulaService.getRuleFormulaResultSync(t, r, e.uid), l = v(i) ? se((m = (c = n == null ? void 0 : n[0]) == null ? void 0 : c.result) == null ? void 0 : m[0][0]) : i, u = v(o) ? se((g = (_ = n == null ? void 0 : n[1]) == null ? void 0 : _.result) == null ? void 0 : g[0][0]) : o, d = C(String(l)) && C(String(u));
- return {
- formula1: _e(l),
- formula2: _e(u),
- originFormula1: l,
- originFormula2: u,
- isFormulaValid: d
- };
- }
- async isValidType(e, t, r) {
- const { value: i, unitId: o, subUnitId: n } = e, { formula1: l, formula2: u, originFormula1: d, originFormula2: c } = await this.parseFormula(r, o, n);
- return !V.isDefine(l) || !V.isDefine(u) ? !0 : V.isDefine(i) && (String(i) === String(l) || String(i) === String(u) || String(i) === String(d != null ? d : "") || String(i) === String(c != null ? c : ""));
- }
- generateRuleErrorMessage(e) {
- return this.localeService.t("dataValidation.checkbox.error");
- }
- }
- const la = {
- [h.BETWEEN]: "dataValidation.date.operators.between",
- [h.EQUAL]: "dataValidation.date.operators.equal",
- [h.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
- [h.LESS_THAN]: "dataValidation.date.operators.lessThan",
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
- [h.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
- [h.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
- };
- h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
- const ua = {
- [h.BETWEEN]: "dataValidation.date.ruleName.between",
- [h.EQUAL]: "dataValidation.date.ruleName.equal",
- [h.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
- [h.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
- [h.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
- [h.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
- }, da = {
- [h.BETWEEN]: "dataValidation.date.errorMsg.between",
- [h.EQUAL]: "dataValidation.date.errorMsg.equal",
- [h.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
- [h.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
- [h.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
- [h.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
- }, Ae = [
- h.BETWEEN,
- h.NOT_BETWEEN
- ], le = "{FORMULA1}", ue = "{FORMULA2}";
- function ir(s) {
- return s.filter(Boolean).join(",");
- }
- function pe(s) {
- return s.split(",").filter(Boolean);
- }
- function sr(s) {
- const a = ne(s);
- return a == null ? "" : a.toString();
- }
- function De(s, a, e) {
- const { formula1: t, formula2: r } = a, i = a.ranges[0].startRow, o = a.ranges[0].startColumn, n = e.row - i, l = e.col - o, u = v(t) ? s.moveFormulaRefOffset(t, l, n, !0) : t, d = v(r) ? s.moveFormulaRefOffset(r, l, n, !0) : r;
- return {
- transformedFormula1: u,
- transformedFormula2: d
- };
- }
- const Ue = (s) => {
- var e, t;
- if (s == null || typeof s == "boolean")
- return;
- if (typeof s == "number" || !Number.isNaN(+s))
- return +s;
- const a = (e = Q.parseDate(s)) == null ? void 0 : e.v;
- return V.isDefine(a) ? a : (t = Q.parseDate(at(s).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : t.v;
- };
- class ca extends k {
- constructor() {
- super(...arguments);
- f(this, "id", T.DATE);
- f(this, "title", "dataValidation.date.title");
- f(this, "operators", [
- h.BETWEEN,
- h.EQUAL,
- h.GREATER_THAN,
- h.GREATER_THAN_OR_EQUAL,
- h.LESS_THAN,
- h.LESS_THAN_OR_EQUAL,
- h.NOT_BETWEEN,
- h.NOT_EQUAL
- ]);
- f(this, "scopes", ["sheet"]);
- f(this, "_customFormulaService", this.injector.get(P));
- f(this, "_lexerTreeBuilder", this.injector.get(Y));
- }
- async parseFormula(e, t, r, i, o) {
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = C(String(n == null ? void 0 : n.v)) && C(String(l == null ? void 0 : l.v));
- return {
- formula1: Ue(v(u) ? n == null ? void 0 : n.v : u),
- formula2: Ue(v(d) ? l == null ? void 0 : l.v : d),
- isFormulaValid: c
- };
- }
- async isValidType(e) {
- const { interceptValue: t, value: r } = e;
- return typeof r == "number" && typeof t == "string" ? !0 : typeof t == "string" ? !!Q.parseDate(t) : !1;
- }
- _validatorSingleFormula(e) {
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) || !!(e && Q.parseDate(e)));
- }
- validatorFormula(e, t, r) {
- const i = e.operator;
- if (!i)
- return {
- success: !1
- };
- const o = this._validatorSingleFormula(e.formula1), n = this.localeService.t("dataValidation.validFail.date");
- if (Ae.includes(i)) {
- const u = this._validatorSingleFormula(e.formula2);
- return {
- success: o && u,
- formula1: o ? void 0 : n,
- formula2: u ? void 0 : n
- };
- }
- return {
- success: o,
- formula1: o ? void 0 : n
- };
- }
- normalizeFormula(e, t, r) {
- const { formula1: i, formula2: o, bizInfo: n } = e, l = (u) => {
- var c;
- if (!u)
- return u;
- let d;
- if (!Number.isNaN(+u))
- d = Q.dateFromSerial(+u);
- else {
- const m = (c = Q.parseDate(u)) == null ? void 0 : c.v;
- if (m == null)
- return "";
- d = Q.dateFromSerial(m);
- }
- return at(`${d[0]}/${d[1]}/${d[2]} ${d[3]}:${d[4]}:${d[5]}`).format(n != null && n.showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD");
- };
- return {
- formula1: v(i) ? i : l(`${i}`),
- formula2: v(o) ? o : l(`${o}`)
- };
- }
- transform(e, t, r) {
- const { value: i } = e;
- return {
- ...e,
- value: Ue(i)
- };
- }
- get operatorNames() {
- return this.operators.map((e) => this.localeService.t(la[e]));
- }
- generateRuleName(e) {
- var r, i;
- if (!e.operator)
- return this.titleStr;
- const t = this.localeService.t(ua[e.operator]).replace(le, (r = e.formula1) != null ? r : "").replace(ue, (i = e.formula2) != null ? i : "");
- return `${this.titleStr} ${t}`;
- }
- generateRuleErrorMessage(e, t) {
- if (!e.operator)
- return this.titleStr;
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
- return `${this.localeService.t(da[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
- }
- }
- h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
- h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
- const ht = {
- [h.BETWEEN]: "dataValidation.errorMsg.between",
- [h.EQUAL]: "dataValidation.errorMsg.equal",
- [h.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
- [h.LESS_THAN]: "dataValidation.errorMsg.lessThan",
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
- [h.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
- [h.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
- };
- function ye(s) {
- let a = s;
- return typeof s == "string" ? ((s.startsWith("¥") || s.startsWith("$")) && (a = s.slice(1)), +a) : +s;
- }
- class ha extends k {
- constructor() {
- super(...arguments);
- f(this, "_customFormulaService", this.injector.get(P));
- f(this, "id", T.DECIMAL);
- f(this, "_lexerTreeBuilder", this.injector.get(Y));
- f(this, "title", "dataValidation.decimal.title");
- f(this, "operators", [
- h.BETWEEN,
- h.EQUAL,
- h.GREATER_THAN,
- h.GREATER_THAN_OR_EQUAL,
- h.LESS_THAN,
- h.LESS_THAN_OR_EQUAL,
- h.NOT_BETWEEN,
- h.NOT_EQUAL
- ]);
- f(this, "scopes", ["sheet"]);
- }
- _isFormulaOrNumber(e) {
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e));
- }
- async isValidType(e, t, r) {
- const { value: i } = e;
- return !Number.isNaN(ye(i));
- }
- transform(e, t, r) {
- const { value: i } = e;
- return {
- ...e,
- value: ye(i)
- };
- }
- _parseNumber(e) {
- return e == null ? Number.NaN : +e;
- }
- async parseFormula(e, t, r, i, o) {
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = C(String(n == null ? void 0 : n.v)) && C(String(l == null ? void 0 : l.v));
- return {
- formula1: this._parseNumber(v(u) ? n == null ? void 0 : n.v : u),
- formula2: this._parseNumber(v(d) ? l == null ? void 0 : l.v : d),
- isFormulaValid: c
- };
- }
- validatorFormula(e, t, r) {
- const i = e.operator;
- if (!i)
- return {
- success: !1
- };
- const o = V.isDefine(e.formula1) && this._isFormulaOrNumber(e.formula1), n = V.isDefine(e.formula2) && this._isFormulaOrNumber(e.formula2), l = Ae.includes(i), u = this.localeService.t("dataValidation.validFail.number");
- return l ? {
- success: o && n,
- formula1: o ? void 0 : u,
- formula2: n ? void 0 : u
- } : {
- success: o,
- formula1: o ? "" : u
- };
- }
- generateRuleErrorMessage(e, t) {
- if (!e.operator)
- return this.titleStr;
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
- return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
- }
- }
- function Pe(s) {
- if (!s)
- return [];
- const a = /* @__PURE__ */ new Set();
- return s.forEach(
- (e) => {
- e.forEach((t) => {
- var i, o;
- const r = ne(t);
- if (r != null) {
- if (typeof r != "string" && typeof (t == null ? void 0 : t.s) == "object" && ((o = (i = t.s) == null ? void 0 : i.n) != null && o.pattern)) {
- a.add(Q.format(t.s.n.pattern, r, { throws: !1 }));
- return;
- }
- C(r.toString()) && a.add(r.toString());
- }
- });
- }
- ), [...a];
- }
- const ma = [
- "if",
- "indirect",
- "choose",
- "offset"
- ];
- function fa(s, a) {
- if (!v(s) || dt(s.slice(1)))
- return !0;
- const t = a.sequenceNodesBuilder(s);
- return t && t.some((r) => typeof r == "object" && r.nodeType === Qt.FUNCTION && ma.indexOf(r.token.toLowerCase()) > -1);
- }
- function ga(s, a) {
- const { formula1: e = "", ranges: t } = s;
- if (dt(e.slice(1))) {
- const i = qt(e.slice(1));
- if ((!i.sheetName || i.sheetName === a) && t.some((o) => I.intersects(o, i.range)))
- return !0;
- }
- return !1;
- }
- class mt extends k {
- constructor() {
- super(...arguments);
- f(this, "formulaService", this.injector.get(K));
- f(this, "_lexer", this.injector.get(Y));
- f(this, "_univerInstanceService", this.injector.get(O));
- f(this, "offsetFormulaByRange", !1);
- f(this, "id", T.LIST);
- f(this, "title", "dataValidation.list.title");
- f(this, "operators", []);
- f(this, "scopes", ["sheet"]);
- f(this, "skipDefaultFontRender", (e) => e.renderMode !== Be.TEXT);
- }
- validatorFormula(e, t, r) {
- var u, d, c;
- const i = !V.isBlank(e.formula1), o = fa((u = e.formula1) != null ? u : "", this._lexer), n = (c = (d = this._univerInstanceService.getUnit(t, N.UNIVER_SHEET)) == null ? void 0 : d.getSheetBySheetId(r)) == null ? void 0 : c.getName(), l = ga(e, n != null ? n : "");
- return {
- success: !!(i && o && !l),
- formula1: i ? o ? l ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
- };
- }
- getExtraStyle(e, t, { style: r }) {
- var o;
- const i = (o = r.tb !== Se.OVERFLOW ? r.tb : Se.CLIP) != null ? o : Se.WRAP;
- if (e.type === T.LIST && (e.renderMode === Be.ARROW || e.renderMode === Be.TEXT)) {
- const n = this.getListWithColorMap(e), l = `${t != null ? t : ""}`, u = n[l];
- if (u)
- return {
- bg: {
- rgb: u
- },
- tb: i
- };
- }
- return {
- tb: i
- };
- }
- parseCellValue(e) {
- const t = e.toString();
- return pe(t);
- }
- async parseFormula(e, t, r) {
- var l, u;
- const i = await this.formulaService.getRuleFormulaResult(t, r, e.uid), o = se((u = (l = i == null ? void 0 : i[0]) == null ? void 0 : l.result) == null ? void 0 : u[0][0]);
- return {
- formula1: void 0,
- formula2: void 0,
- isFormulaValid: C(String(o))
- };
- }
- async isValidType(e, t, r) {
- var m, _;
- const { value: i, unitId: o, subUnitId: n } = e, { formula1: l = "" } = r, u = await this.formulaService.getRuleFormulaResult(o, n, r.uid), d = v(l) ? Pe((_ = (m = u == null ? void 0 : u[0]) == null ? void 0 : m.result) == null ? void 0 : _[0][0]) : pe(l);
- return this.parseCellValue(i).every((g) => d.includes(g));
- }
- generateRuleName() {
- return this.localeService.t("dataValidation.list.name");
- }
- generateRuleErrorMessage() {
- return this.localeService.t("dataValidation.list.error");
- }
- getList(e, t, r) {
- var m, _, g, R;
- const { formula1: i = "" } = e, o = this.injector.get(O), n = (m = t ? o.getUniverSheetInstance(t) : void 0) != null ? m : o.getCurrentUnitForType(N.UNIVER_SHEET);
- if (!n) return [];
- const l = (_ = r ? n.getSheetBySheetId(r) : void 0) != null ? _ : n.getActiveSheet();
- if (!l) return [];
- const u = n.getUnitId(), d = l.getSheetId(), c = this.formulaService.getRuleFormulaResultSync(u, d, e.uid);
- return v(i) ? Pe((R = (g = c == null ? void 0 : c[0]) == null ? void 0 : g.result) == null ? void 0 : R[0][0]) : pe(i);
- }
- async getListAsync(e, t, r) {
- var m, _, g, R;
- const { formula1: i = "" } = e, o = this.injector.get(O), n = (m = t ? o.getUniverSheetInstance(t) : void 0) != null ? m : o.getCurrentUnitForType(N.UNIVER_SHEET);
- if (!n) return [];
- const l = (_ = r ? n.getSheetBySheetId(r) : void 0) != null ? _ : n.getActiveSheet();
- if (!l) return [];
- const u = n.getUnitId(), d = l.getSheetId(), c = await this.formulaService.getRuleFormulaResult(u, d, e.uid);
- return v(i) ? Pe((R = (g = c == null ? void 0 : c[0]) == null ? void 0 : g.result) == null ? void 0 : R[0][0]) : pe(i);
- }
- getListWithColor(e, t, r) {
- const i = this.getList(e, t, r), o = (e.formula2 || "").split(",");
- return i.map((n, l) => ({ label: n, color: o[l] }));
- }
- getListWithColorMap(e, t, r) {
- const i = this.getListWithColor(e, t, r), o = {};
- return i.forEach((n) => {
- n.color && (o[n.label] = n.color);
- }), o;
- }
- }
- class _a extends k {
- constructor() {
- super(...arguments);
- f(this, "id", T.TEXT_LENGTH);
- f(this, "title", "dataValidation.textLength.title");
- f(this, "_lexerTreeBuilder", this.injector.get(Y));
- f(this, "operators", [
- h.BETWEEN,
- h.EQUAL,
- h.GREATER_THAN,
- h.GREATER_THAN_OR_EQUAL,
- h.LESS_THAN,
- h.LESS_THAN_OR_EQUAL,
- h.NOT_BETWEEN,
- h.NOT_EQUAL
- ]);
- f(this, "scopes", ["sheet"]);
- f(this, "_customFormulaService", this.injector.get(P));
- }
- _isFormulaOrInt(e) {
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) && Number.isInteger(+e));
- }
- validatorFormula(e, t, r) {
- const i = e.operator;
- if (!i)
- return {
- success: !1
- };
- const o = V.isDefine(e.formula1) && this._isFormulaOrInt(e.formula1), n = V.isDefine(e.formula2) && this._isFormulaOrInt(e.formula2), l = Ae.includes(i), u = this.localeService.t("dataValidation.validFail.number");
- return l ? {
- success: o && n,
- formula1: o ? void 0 : u,
- formula2: n ? void 0 : u
- } : {
- success: o,
- formula1: u
- };
- }
- _parseNumber(e) {
- return e == null ? Number.NaN : +e;
- }
- async parseFormula(e, t, r, i, o) {
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = C(String(n == null ? void 0 : n.v)) && C(String(l == null ? void 0 : l.v));
- return {
- formula1: this._parseNumber(v(u) ? n == null ? void 0 : n.v : u),
- formula2: this._parseNumber(v(d) ? l == null ? void 0 : l.v : d),
- isFormulaValid: c
- };
- }
- transform(e, t, r) {
- return {
- ...e,
- value: e.value.toString().length
- };
- }
- async isValidType(e, t, r) {
- const { value: i } = e;
- return typeof i == "string" || typeof i == "number";
- }
- generateRuleErrorMessage(e, t) {
- if (!e.operator)
- return this.titleStr;
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
- return `${this.localeService.t(Dt[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
- }
- }
- function ft(s) {
- var e, t;
- return s ? s.p ? !((t = (e = s.p.body) == null ? void 0 : e.dataStream) != null ? t : "").slice(0, -2).trim() : V.isBlank(s.v) : !0;
- }
- function be(s, a, e, t, r = "command", i = !0) {
- const o = t.get(Y), n = t.get(G), l = [], u = [], d = t.get(F), c = t.get(O), m = Ye(c, { unitId: s, subUnitId: a });
- if (!m)
- return {
- redoMutations: l,
- undoMutations: u
- };
- const { worksheet: _ } = m, g = new ve();
- let R = !1;
- function M(p, w) {
- i && p.forEach((H) => {
- b.foreach(H, (B, W) => {
- const U = _.getCellRaw(B, W), J = ct(U);
- (ft(U) || J === w) && !(U != null && U.p) && (R = !0, g.setValue(B, W, {
- v: w,
- p: null
- }));
- });
- });
- }
- if (e.forEach((p) => {
- switch (p.type) {
- case "delete":
- l.push({
- id: A.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.rule.uid,
- source: r
- }
- }), u.unshift({
- id: L.id,
- params: {
- unitId: s,
- subUnitId: a,
- rule: p.rule,
- index: p.index,
- source: r
- }
- });
- break;
- case "update": {
- if (de(p.rule.type, n)) {
- const H = p.oldRanges[0].startRow, B = p.oldRanges[0].startColumn, W = p.newRanges[0].startRow, U = p.newRanges[0].startColumn, J = W - H, ce = U - B, he = v(p.rule.formula1) ? o.moveFormulaRefOffset(p.rule.formula1, ce, J) : p.rule.formula1, me = v(p.rule.formula2) ? o.moveFormulaRefOffset(p.rule.formula2, ce, J) : p.rule.formula2;
- he !== p.rule.formula1 || me !== p.rule.formula2 || !rt(p.newRanges, p.oldRanges) ? (l.push({
- id: E.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.ruleId,
- payload: {
- type: y.ALL,
- payload: {
- formula1: he,
- formula2: me,
- ranges: p.newRanges
- }
- }
- }
- }), u.unshift({
- id: E.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.ruleId,
- payload: {
- type: y.ALL,
- payload: {
- formula1: p.rule.formula1,
- formula2: p.rule.formula2,
- ranges: p.oldRanges
- }
- }
- }
- })) : (l.push({
- id: E.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.ruleId,
- payload: {
- type: y.RANGE,
- payload: p.newRanges
- },
- source: r
- }
- }), u.unshift({
- id: E.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.ruleId,
- payload: {
- type: y.RANGE,
- payload: p.oldRanges
- },
- source: r
- }
- }));
- } else
- l.push({
- id: E.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.ruleId,
- payload: {
- type: y.RANGE,
- payload: p.newRanges
- },
- source: r
- }
- }), u.unshift({
- id: E.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.ruleId,
- payload: {
- type: y.RANGE,
- payload: p.oldRanges
- },
- source: r
- }
- });
- const w = d.getRuleById(s, a, p.ruleId);
- if (w && w.type === T.CHECKBOX) {
- const B = d.getValidator(T.CHECKBOX).parseFormulaSync(w, s, a);
- M(p.newRanges, B.formula2);
- }
- break;
- }
- case "add": {
- if (l.push({
- id: L.id,
- params: {
- unitId: s,
- subUnitId: a,
- rule: p.rule,
- source: r
- }
- }), u.unshift({
- id: A.id,
- params: {
- unitId: s,
- subUnitId: a,
- ruleId: p.rule.uid,
- source: r
- }
- }), p.rule.type === T.CHECKBOX) {
- const H = d.getValidator(T.CHECKBOX).parseFormulaSync(p.rule, s, a);
- M(p.rule.ranges, H.originFormula2);
- }
- break;
- }
- }
- }), R) {
- const p = {
- id: oe.id,
- params: {
- unitId: s,
- subUnitId: a,
- cellValue: g.getData()
- }
- }, w = {
- id: oe.id,
- params: st(t, p.params)
- };
- l.push(p), u.push(w);
- }
- return {
- redoMutations: l,
- undoMutations: u
- };
- }
- const pa = {
- type: z.COMMAND,
- id: "sheet.command.updateDataValidationRuleRange",
- handler(s, a) {
- if (!a)
- return !1;
- const { unitId: e, subUnitId: t, ranges: r, ruleId: i } = a, o = s.get(F), n = s.get(x), l = s.get(Z);
- if (!o.getRuleById(e, t, i))
- return !1;
- const d = o.getRuleObjectMatrix(e, t).clone();
- d.updateRange(i, r);
- const c = d.diff(o.getRules(e, t)), { redoMutations: m, undoMutations: _ } = be(e, t, c, s);
- return l.pushUndoRedo({
- undoMutations: _,
- redoMutations: m,
- unitID: e
- }), Ie(m, n), !0;
- }
- }, Ra = {
- type: z.COMMAND,
- id: "sheet.command.addDataValidation",
- handler(s, a) {
- if (!a)
- return !1;
- const { unitId: e, subUnitId: t, rule: r } = a, i = s.get(F), o = s.get(x), n = s.get(Z), l = i.getRuleObjectMatrix(e, t).clone();
- l.addRule(r);
- const u = l.diff(i.getRules(e, t)), d = i.getValidator(r.type), c = {
- unitId: e,
- subUnitId: t,
- rule: {
- ...r,
- ...d == null ? void 0 : d.normalizeFormula(r, e, t)
- }
- }, { redoMutations: m, undoMutations: _ } = be(e, t, u, s);
- return m.push({
- id: L.id,
- params: c
- }), _.unshift({
- id: A.id,
- params: {
- unitId: e,
- subUnitId: t,
- ruleId: r.uid
- }
- }), n.pushUndoRedo({
- unitID: e,
- redoMutations: m,
- undoMutations: _
- }), Ie(m, o), !0;
- }
- }, Sa = {
- type: z.COMMAND,
- id: "sheets.command.update-data-validation-setting",
- // eslint-disable-next-line max-lines-per-function
- handler(s, a) {
- if (!a)
- return !1;
- const e = s.get(x), t = s.get(Z), r = s.get(F), i = s.get(G), { unitId: o, subUnitId: n, ruleId: l, setting: u } = a, d = i.getValidatorItem(u.type);
- if (!d)
- return !1;
- const c = r.getRuleById(o, n, l);
- if (!c)
- return !1;
- const m = { ...c, ...u };
- if (!d.validatorFormula(m, o, n).success)
- return !1;
- const _ = {
- unitId: o,
- subUnitId: n,
- ruleId: l,
- payload: {
- type: y.SETTING,
- payload: {
- ...u,
- ...d.normalizeFormula(m, o, n)
- }
- }
- }, g = [{
- id: E.id,
- params: _
- }], R = {
- unitId: o,
- subUnitId: n,
- ruleId: l,
- payload: {
- type: y.SETTING,
- payload: bt(c)
- }
- }, M = [{
- id: E.id,
- params: R
- }];
- if (u.type === T.CHECKBOX) {
- const w = c.ranges, H = s.get(O), B = Ye(H, { unitId: o, subUnitId: n });
- if (B) {
- const W = new ve(), { worksheet: U } = B, { formula2: J = Me, formula1: ce = Ve } = c, { formula2: he = Me, formula1: me = Ve } = u;
- let Le = !1;
- if (w.forEach((fe) => {
- b.foreach(fe, (ae, xe) => {
- const j = U.getCellRaw(ae, xe), Ke = ct(j);
- (ft(j) || Ke === String(J)) && !(j != null && j.p) ? (W.setValue(ae, xe, {
- v: he,
- p: null
- }), Le = !0) : Ke === String(ce) && !(j != null && j.p) && (W.setValue(ae, xe, {
- v: me,
- p: null
- }), Le = !0);
- });
- }), Le) {
- const fe = {
- id: oe.id,
- params: {
- unitId: o,
- subUnitId: n,
- cellValue: W.getData()
- }
- }, ae = {
- id: oe.id,
- params: st(s, fe.params)
- };
- g.push(fe), M.push(ae);
- }
- }
- }
- return Ie(g, e).result ? (t.pushUndoRedo({
- unitID: o,
- redoMutations: g,
- undoMutations: M
- }), !0) : !1;
- }
- }, va = {
- type: z.COMMAND,
- id: "sheets.command.update-data-validation-options",
- handler(s, a) {
- if (!a)
- return !1;
- const e = s.get(x), t = s.get(Z), r = s.get(F), { unitId: i, subUnitId: o, ruleId: n, options: l } = a, u = r.getRuleById(i, o, n);
- if (!u)
- return !1;
- const d = {
- unitId: i,
- subUnitId: o,
- ruleId: n,
- payload: {
- type: y.OPTIONS,
- payload: l
- }
- }, c = [{
- id: E.id,
- params: d
- }], m = {
- unitId: i,
- subUnitId: o,
- ruleId: n,
- payload: {
- type: y.OPTIONS,
- payload: Lt(u)
- }
- }, _ = [{
- id: E.id,
- params: m
- }];
- return t.pushUndoRedo({
- unitID: i,
- redoMutations: c,
- undoMutations: _
- }), e.executeCommand(E.id, d), !0;
- }
- }, Va = {
- type: z.COMMAND,
- id: "sheets.command.clear-range-data-validation",
- handler(s, a) {
- if (!a)
- return !1;
- const { unitId: e, subUnitId: t, ranges: r } = a, i = s.get(x), o = s.get(O), n = Ye(o, { unitId: e, subUnitId: t }), l = s.get(F);
- if (!n) return !1;
- const u = s.get(Z), d = l.getRuleObjectMatrix(e, t).clone();
- d.removeRange(r);
- const c = d.diff(l.getRules(e, t)), { redoMutations: m, undoMutations: _ } = be(e, t, c, s);
- return u.pushUndoRedo({
- unitID: e,
- redoMutations: m,
- undoMutations: _
- }), Ie(m, i).result;
- }
- }, Ma = {
- type: z.COMMAND,
- id: "sheet.command.remove-all-data-validation",
- handler(s, a) {
- if (!a)
- return !1;
- const { unitId: e, subUnitId: t } = a, r = s.get(x), i = s.get(F), o = s.get(Z), n = [...i.getRules(e, t)], l = {
- unitId: e,
- subUnitId: t,
- ruleId: n.map((c) => c.uid)
- }, u = [{
- id: A.id,
- params: l
- }], d = [{
- id: L.id,
- params: {
- unitId: e,
- subUnitId: t,
- rule: n
- }
- }];
- return o.pushUndoRedo({
- redoMutations: u,
- undoMutations: d,
- unitID: e
- }), r.executeCommand(A.id, l), !0;
- }
- }, ya = (s, a) => {
- const e = s.get(F), { unitId: t, subUnitId: r, ruleId: i, source: o } = a;
- if (Array.isArray(i)) {
- const l = i.map((u) => e.getRuleById(t, r, u)).filter(Boolean);
- return [{
- id: L.id,
- params: {
- unitId: t,
- subUnitId: r,
- rule: l,
- source: o
- }
- }];
- }
- return [{
- id: L.id,
- params: {
- unitId: t,
- subUnitId: r,
- rule: {
- ...e.getRuleById(t, r, i)
- },
- index: e.getRuleIndex(t, r, i)
- }
- }];
- }, Ea = {
- type: z.COMMAND,
- id: "sheet.command.remove-data-validation-rule",
- handler(s, a) {
- if (!a)
- return !1;
- const { unitId: e, subUnitId: t, ruleId: r } = a, i = s.get(x), o = s.get(Z), n = s.get(F), l = [{
- id: A.id,
- params: a
- }], u = [{
- id: L.id,
- params: {
- unitId: e,
- subUnitId: t,
- rule: {
- ...n.getRuleById(e, t, r)
- },
- index: n.getRuleIndex(e, t, r)
- }
- }];
- return o.pushUndoRedo({
- undoMutations: u,
- redoMutations: l,
- unitID: a.unitId
- }), i.executeCommand(A.id, a), !0;
- }
- }, Ta = "sheets-data-validation.config", tt = {};
- var Fa = Object.defineProperty, Na = Object.getOwnPropertyDescriptor, Ca = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? Na(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && Fa(a, e, r), r;
- }, $e = (s, a) => (e, t) => a(e, t, s);
- let Ee = class extends $ {
- constructor(a, e, t) {
- super();
- f(this, "_disposableMap", /* @__PURE__ */ new Map());
- f(this, "registerRule", (a, e, t) => {
- de(t.type, this._validatorRegistryService) && this.register(a, e, t);
- });
- this._dataValidationModel = a, this._formulaRefRangeService = e, this._validatorRegistryService = t, this._initRefRange();
- }
- _getIdWithUnitId(a, e, t) {
- return `${a}_${e}_${t}`;
- }
- // eslint-disable-next-line max-lines-per-function
- register(a, e, t) {
- const r = t.ranges, i = t.formula1, o = t.formula2, n = this._formulaRefRangeService.registerRangeFormula(a, e, r, [i != null ? i : "", o != null ? o : ""], (u) => {
- if (u.length === 0)
- return {
- undos: [{
- id: L.id,
- params: {
- unitId: a,
- subUnitId: e,
- rule: t,
- source: "patched"
- }
- }],
- redos: [{
- id: A.id,
- params: {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- source: "patched"
- }
- }]
- };
- const d = [], c = [], m = u[0];
- d.push({
- id: E.id,
- params: {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- payload: {
- type: y.ALL,
- payload: {
- ranges: m.ranges,
- formula1: m.formulas[0],
- formula2: m.formulas[1]
- }
- },
- source: "patched"
- }
- }), c.push({
- id: E.id,
- params: {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- payload: {
- type: y.ALL,
- payload: {
- ranges: r,
- formula1: i,
- formula2: o
- }
- },
- source: "patched"
- }
- });
- for (let _ = 1; _ < u.length; _++) {
- const g = u[_], R = yt();
- d.push({
- id: L.id,
- params: {
- unitId: a,
- subUnitId: e,
- rule: {
- ...t,
- uid: R,
- formula1: g.formulas[0],
- formula2: g.formulas[1],
- ranges: g.ranges
- },
- source: "patched"
- }
- }), c.push({
- id: A.id,
- params: {
- unitId: a,
- subUnitId: e,
- ruleId: R,
- source: "patched"
- }
- });
- }
- return {
- undos: c,
- redos: d
- };
- }), l = this._getIdWithUnitId(a, e, t.uid);
- this._disposableMap.set(l, n);
- }
- _initRefRange() {
- const a = this._dataValidationModel.getAll();
- for (const [e, t] of a)
- for (const [r, i] of t)
- for (const o of i)
- this.registerRule(e, r, o);
- this.disposeWithMe(
- this._dataValidationModel.ruleChange$.subscribe((e) => {
- const { unitId: t, subUnitId: r, rule: i } = e;
- switch (e.type) {
- case "add": {
- const o = e.rule;
- this.registerRule(e.unitId, e.subUnitId, o);
- break;
- }
- case "remove": {
- const o = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
- o && o.dispose();
- break;
- }
- case "update": {
- const o = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, o.uid));
- n && n.dispose(), this.registerRule(e.unitId, e.subUnitId, o);
- break;
- }
- }
- })
- ), this.disposeWithMe(qe(() => {
- this._disposableMap.forEach((e) => {
- e.dispose();
- }), this._disposableMap.clear();
- }));
- }
- };
- Ee = Ca([
- $e(0, S(F)),
- $e(1, S(ut)),
- $e(2, S(G))
- ], Ee);
- var gt = /* @__PURE__ */ ((s) => (s[s.View = 0] = "View", s[s.Edit = 1] = "Edit", s[s.ManageCollaborator = 2] = "ManageCollaborator", s[s.Print = 3] = "Print", s[s.Duplicate = 4] = "Duplicate", s[s.Comment = 5] = "Comment", s[s.Copy = 6] = "Copy", s[s.Share = 7] = "Share", s[s.Export = 8] = "Export", s[s.MoveWorksheet = 9] = "MoveWorksheet", s[s.DeleteWorksheet = 10] = "DeleteWorksheet", s[s.HideWorksheet = 11] = "HideWorksheet", s[s.RenameWorksheet = 12] = "RenameWorksheet", s[s.CreateWorksheet = 13] = "CreateWorksheet", s[s.SetWorksheetStyle = 14] = "SetWorksheetStyle", s[s.EditWorksheetCell = 15] = "EditWorksheetCell", s[s.InsertHyperlink = 16] = "InsertHyperlink", s[s.Sort = 17] = "Sort", s[s.Filter = 18] = "Filter", s[s.PivotTable = 19] = "PivotTable", s[s.FloatImg = 20] = "FloatImg", s[s.History = 21] = "History", s[s.RwHgtClWdt = 22] = "RwHgtClWdt", s[s.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", s[s.ViewFilter = 24] = "ViewFilter", s[s.MoveSheet = 25] = "MoveSheet", s[s.DeleteSheet = 26] = "DeleteSheet", s[s.HideSheet = 27] = "HideSheet", s[s.CopySheet = 28] = "CopySheet", s[s.RenameSheet = 29] = "RenameSheet", s[s.CreateSheet = 30] = "CreateSheet", s[s.SelectProtectedCells = 31] = "SelectProtectedCells", s[s.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", s[s.SetCellStyle = 33] = "SetCellStyle", s[s.SetCellValue = 34] = "SetCellValue", s[s.SetRowStyle = 35] = "SetRowStyle", s[s.SetColumnStyle = 36] = "SetColumnStyle", s[s.InsertRow = 37] = "InsertRow", s[s.InsertColumn = 38] = "InsertColumn", s[s.DeleteRow = 39] = "DeleteRow", s[s.DeleteColumn = 40] = "DeleteColumn", s[s.EditExtraObject = 41] = "EditExtraObject", s[s.Delete = 42] = "Delete", s[s.RecoverHistory = 43] = "RecoverHistory", s[s.ViewHistory = 44] = "ViewHistory", s[s.CreatePermissionObject = 45] = "CreatePermissionObject", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(gt || {}), Oa = Object.defineProperty, wa = Object.getOwnPropertyDescriptor, Ia = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? wa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && Oa(a, e, r), r;
- }, He = (s, a) => (e, t) => a(e, t, s);
- let Te = class extends $ {
- constructor(s, a, e) {
- super(), this._univerInstanceService = s, this._permissionService = a, this._lexerTreeBuilder = e;
- }
- getFormulaRefCheck(s) {
- var e, t;
- const a = this._lexerTreeBuilder.sequenceNodesBuilder(s);
- if (!a)
- return !0;
- for (let r = 0; r < a.length; r++) {
- const i = a[r];
- if (typeof i == "string")
- continue;
- const { token: o } = i, n = Gt(o), l = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET);
- let u = l.getActiveSheet();
- const d = l.getUnitId();
- if (n.sheetName) {
- if (u = l.getSheetBySheetName(n.sheetName), !u)
- return !1;
- const R = u == null ? void 0 : u.getSheetId();
- if (!this._permissionService.getPermissionPoint(new Bt(d, R).id)) return !1;
- }
- if (!u)
- return !1;
- const { startRow: c, endRow: m, startColumn: _, endColumn: g } = n.range;
- for (let R = c; R <= m; R++)
- for (let M = _; M <= g; M++) {
- const p = (t = (e = u.getCell(R, M)) == null ? void 0 : e.selectionProtection) == null ? void 0 : t[0];
- if ((p == null ? void 0 : p[gt.View]) === !1)
- return !1;
- }
- }
- return !0;
- }
- };
- Te = Ia([
- He(0, O),
- He(1, Et),
- He(2, S(Y))
- ], Te);
- var Aa = Object.defineProperty, Da = Object.getOwnPropertyDescriptor, ba = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? Da(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && Aa(a, e, r), r;
- }, ee = (s, a) => (e, t) => a(e, t, s);
- let Fe = class extends $ {
- constructor(a, e, t, r, i, o) {
- super();
- f(this, "_disposableMap", /* @__PURE__ */ new Map());
- f(this, "registerRule", (a, e, t) => {
- de(t.type, this._validatorRegistryService) || (this.register(a, e, t), this.registerFormula(a, e, t));
- });
- this._dataValidationModel = a, this._injector = e, this._refRangeService = t, this._dataValidationFormulaService = r, this._formulaRefRangeService = i, this._validatorRegistryService = o, this._initRefRange();
- }
- _getIdWithUnitId(a, e, t) {
- return `${a}_${e}_${t}`;
- }
- // eslint-disable-next-line max-lines-per-function
- registerFormula(a, e, t) {
- var u;
- const r = t.uid, i = this._getIdWithUnitId(a, e, r), o = (u = this._disposableMap.get(i)) != null ? u : /* @__PURE__ */ new Set(), n = (d, c) => {
- const m = this._dataValidationModel.getRuleById(a, e, r);
- if (!m)
- return { redos: [], undos: [] };
- const _ = m[d];
- if (!_ || _ === c)
- return { redos: [], undos: [] };
- const g = {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- payload: {
- type: y.SETTING,
- payload: {
- type: m.type,
- formula1: m.formula1,
- formula2: m.formula2,
- [d]: c
- }
- },
- source: "patched"
- }, R = {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- payload: {
- type: y.SETTING,
- payload: {
- type: m.type,
- formula1: m.formula1,
- formula2: m.formula2
- }
- },
- source: "patched"
- }, M = [
- {
- id: E.id,
- params: g
- }
- ], p = [
- {
- id: E.id,
- params: R
- }
- ];
- return { redos: M, undos: p };
- }, l = this._dataValidationFormulaService.getRuleFormulaInfo(a, e, r);
- if (l) {
- const [d, c] = l;
- if (d) {
- const m = this._formulaRefRangeService.registerFormula(
- a,
- e,
- d.text,
- (_) => n("formula1", _)
- );
- o.add(() => m.dispose());
- }
- if (c) {
- const m = this._formulaRefRangeService.registerFormula(
- a,
- e,
- c.text,
- (_) => n("formula2", _)
- );
- o.add(() => m.dispose());
- }
- }
- }
- register(a, e, t) {
- var l;
- const r = (u) => {
- const d = [...t.ranges], m = d.map((g) => Pt(g, u)).filter((g) => !!g).flat();
- if (rt(m, d))
- return { redos: [], undos: [] };
- if (m.length) {
- const g = {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- payload: {
- type: y.RANGE,
- payload: m
- },
- source: "patched"
- }, R = [{ id: E.id, params: g }], M = [{
- id: E.id,
- params: {
- unitId: a,
- subUnitId: e,
- ruleId: t.uid,
- payload: {
- type: y.RANGE,
- payload: d
- },
- source: "patched"
- }
- }];
- return { redos: R, undos: M };
- } else {
- const g = { unitId: a, subUnitId: e, ruleId: t.uid }, R = [{ id: A.id, params: g }], M = ya(this._injector, g);
- return { redos: R, undos: M };
- }
- }, i = [];
- t.ranges.forEach((u) => {
- const d = this._refRangeService.registerRefRange(u, r, a, e);
- i.push(() => d.dispose());
- });
- const o = this._getIdWithUnitId(a, e, t.uid), n = (l = this._disposableMap.get(o)) != null ? l : /* @__PURE__ */ new Set();
- n.add(() => i.forEach((u) => u())), this._disposableMap.set(o, n);
- }
- _initRefRange() {
- const a = this._dataValidationModel.getAll();
- for (const [e, t] of a)
- for (const [r, i] of t)
- for (const o of i)
- this.registerRule(e, r, o);
- this.disposeWithMe(
- this._dataValidationModel.ruleChange$.subscribe((e) => {
- const { unitId: t, subUnitId: r, rule: i } = e;
- switch (e.type) {
- case "add": {
- const o = e.rule;
- this.registerRule(e.unitId, e.subUnitId, o);
- break;
- }
- case "remove": {
- const o = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
- o && o.forEach((n) => n());
- break;
- }
- case "update": {
- const o = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, o.uid));
- n && n.forEach((l) => l()), this.registerRule(e.unitId, e.subUnitId, o);
- break;
- }
- }
- })
- ), this.disposeWithMe(qe(() => {
- this._disposableMap.forEach((e) => {
- e.forEach((t) => t());
- }), this._disposableMap.clear();
- }));
- }
- };
- Fe = ba([
- ee(0, S(F)),
- ee(1, S(Ge)),
- ee(2, S(Ut)),
- ee(3, S(K)),
- ee(4, S(ut)),
- ee(5, S(G))
- ], Fe);
- var La = Object.defineProperty, xa = Object.getOwnPropertyDescriptor, Ba = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? xa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && La(a, e, r), r;
- }, We = (s, a) => (e, t) => a(e, t, s);
- let Ne = class extends $ {
- constructor(s, a, e) {
- super(), this._sheetInterceptorService = s, this._univerInstanceService = a, this._sheetDataValidationModel = e, this._initSheetChange();
- }
- _initSheetChange() {
- this.disposeWithMe(
- this._sheetInterceptorService.interceptCommand({
- getMutations: (s) => {
- var a;
- if (s.id === $t.id) {
- const e = s.params, t = e.unitId || this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET).getUnitId(), r = this._univerInstanceService.getUniverSheetInstance(t);
- if (!r)
- return { redos: [], undos: [] };
- const i = e.subUnitId || ((a = r.getActiveSheet()) == null ? void 0 : a.getSheetId());
- if (!i)
- return { redos: [], undos: [] };
- const o = this._sheetDataValidationModel.getRules(t, i);
- if (o.length === 0)
- return { redos: [], undos: [] };
- const n = o.map((d) => d.uid), l = {
- unitId: t,
- subUnitId: i,
- ruleId: n,
- source: "patched"
- }, u = {
- unitId: t,
- subUnitId: i,
- rule: [...o],
- source: "patched"
- };
- return {
- redos: [{
- id: A.id,
- params: l
- }],
- undos: [{
- id: L.id,
- params: u
- }]
- };
- }
- return { redos: [], undos: [] };
- }
- })
- );
- }
- };
- Ne = Ba([
- We(0, S(ot)),
- We(1, S(O)),
- We(2, S(F))
- ], Ne);
- class Ua extends k {
- constructor() {
- super(...arguments);
- f(this, "id", T.ANY);
- f(this, "title", "dataValidation.any.title");
- f(this, "operators", []);
- f(this, "scopes", ["sheet"]);
- f(this, "offsetFormulaByRange", !1);
- }
- async parseFormula(e, t, r) {
- return {
- formula1: e.formula1,
- formula2: e.formula2,
- isFormulaValid: !0
- };
- }
- validatorFormula(e, t, r) {
- return {
- success: !0
- };
- }
- async isValidType(e, t, r) {
- return !0;
- }
- generateRuleErrorMessage(e) {
- return this.localeService.t("dataValidation.any.error");
- }
- }
- class Pa extends k {
- constructor() {
- super(...arguments);
- f(this, "id", T.CUSTOM);
- f(this, "title", "dataValidation.custom.title");
- f(this, "operators", []);
- f(this, "scopes", ["sheet"]);
- f(this, "_customFormulaService", this.injector.get(P));
- f(this, "_lexerTreeBuilder", this.injector.get(Y));
- }
- validatorFormula(e, t, r) {
- var u;
- const i = v(e.formula1), o = (u = e.formula1) != null ? u : "", l = this._lexerTreeBuilder.checkIfAddBracket(o) === 0 && o.startsWith(kt.EQUALS);
- return {
- success: i && l,
- formula1: i && l ? "" : this.localeService.t("dataValidation.validFail.formula")
- };
- }
- async parseFormula(e, t, r) {
- return {
- formula1: void 0,
- formula2: void 0,
- isFormulaValid: !0
- };
- }
- async isValidType(e, t, r) {
- const { column: i, row: o, unitId: n, subUnitId: l } = e, u = await this._customFormulaService.getCellFormulaValue(n, l, r.uid, o, i), d = u == null ? void 0 : u.v;
- return C(String(d)) && V.isDefine(d) && d !== "" ? u.t === Tt.BOOLEAN ? !!d : typeof d == "boolean" ? d : typeof d == "number" ? !!d : typeof d == "string" ? C(d) : !!d : !1;
- }
- generateRuleErrorMessage(e) {
- return this.localeService.t("dataValidation.custom.error");
- }
- generateRuleName(e) {
- var t;
- return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (t = e.formula1) != null ? t : "");
- }
- }
- class $a extends mt {
- constructor() {
- super(...arguments);
- f(this, "id", T.LIST_MULTIPLE);
- f(this, "title", "dataValidation.listMultiple.title");
- f(this, "offsetFormulaByRange", !1);
- f(this, "skipDefaultFontRender", () => !0);
- }
- }
- class Ha extends k {
- constructor() {
- super(...arguments);
- f(this, "_customFormulaService", this.injector.get(P));
- f(this, "_lexerTreeBuilder", this.injector.get(Y));
- f(this, "id", T.WHOLE);
- f(this, "title", "dataValidation.whole.title");
- f(this, "operators", [
- h.BETWEEN,
- h.EQUAL,
- h.GREATER_THAN,
- h.GREATER_THAN_OR_EQUAL,
- h.LESS_THAN,
- h.LESS_THAN_OR_EQUAL,
- h.NOT_BETWEEN,
- h.NOT_EQUAL
- ]);
- f(this, "scopes", ["sheet"]);
- }
- _isFormulaOrInt(e) {
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) && Number.isInteger(+e));
- }
- async isValidType(e, t, r) {
- const { value: i } = e, o = ye(i);
- return !Number.isNaN(o) && Number.isInteger(o);
- }
- transform(e, t, r) {
- const { value: i } = e;
- return {
- ...e,
- value: ye(i)
- };
- }
- _parseNumber(e) {
- return e == null ? Number.NaN : +e;
- }
- async parseFormula(e, t, r, i, o) {
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = v(u) ? n == null ? void 0 : n.v : u, m = v(d) ? l == null ? void 0 : l.v : d, _ = C(`${c}`) && C(`${m}`);
- return {
- formula1: this._parseNumber(c),
- formula2: this._parseNumber(m),
- isFormulaValid: _
- };
- }
- validatorFormula(e, t, r) {
- const i = e.operator;
- if (!i)
- return {
- success: !1
- };
- const o = V.isDefine(e.formula1) && this._isFormulaOrInt(e.formula1), n = V.isDefine(e.formula2) && this._isFormulaOrInt(e.formula2), l = Ae.includes(i), u = this.localeService.t("dataValidation.validFail.number");
- return l ? {
- success: o && n,
- formula1: o ? void 0 : u,
- formula2: n ? void 0 : u
- } : {
- success: o,
- formula1: u
- };
- }
- generateRuleErrorMessage(e, t) {
- if (!e.operator)
- return this.titleStr;
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
- return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
- }
- }
- var Wa = Object.defineProperty, ja = Object.getOwnPropertyDescriptor, Qa = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? ja(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && Wa(a, e, r), r;
- }, te = (s, a) => (e, t) => a(e, t, s);
- let Ce = class extends Ft {
- constructor(s, a, e, t, r, i) {
- super(), this._univerInstanceService = s, this._dataValidatorRegistryService = a, this._injector = e, this._selectionManagerService = t, this._sheetInterceptorService = r, this._sheetDataValidationModel = i, this._init();
- }
- _init() {
- this._registerValidators(), this._initCommandInterceptor();
- }
- _registerValidators() {
- [
- Ua,
- ha,
- Ha,
- _a,
- ca,
- na,
- mt,
- $a,
- Pa
- ].forEach((s) => {
- const a = this._injector.createInstance(s);
- this.disposeWithMe(this._dataValidatorRegistryService.register(a)), this.disposeWithMe(qe(() => this._injector.delete(s)));
- });
- }
- _initCommandInterceptor() {
- this._sheetInterceptorService.interceptCommand({
- getMutations: (s) => {
- var a;
- if (s.id === Ht.id) {
- const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e.getUnitId(), r = e.getActiveSheet();
- if (!r)
- throw new Error("No active sheet found");
- const i = r.getSheetId(), o = (a = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : a.map((c) => c.range), n = this._sheetDataValidationModel.getRuleObjectMatrix(t, i).clone();
- o && n.removeRange(o);
- const l = n.diff(this._sheetDataValidationModel.getRules(t, i)), { redoMutations: u, undoMutations: d } = be(t, i, l, this._injector, "patched");
- return {
- undos: d,
- redos: u
- };
- }
- return {
- undos: [],
- redos: []
- };
- }
- });
- }
- };
- Ce = Qa([
- te(0, O),
- te(1, S(G)),
- te(2, S(Ge)),
- te(3, S(nt)),
- te(4, S(ot)),
- te(5, S(F))
- ], Ce);
- var qa = Object.defineProperty, Ga = Object.getOwnPropertyDescriptor, ka = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? Ga(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && qa(a, e, r), r;
- }, Re = (s, a) => (e, t) => a(e, t, s);
- let Oe = class extends $ {
- constructor(s, a, e, t) {
- super(), this._univerInstanceService = s, this._sheetDataValidationModel = a, this._dataValidationCacheService = e, this._lifecycleService = t, this._initRecalculate();
- }
- _initRecalculate() {
- const s = (a) => {
- if (a.length === 0)
- return;
- const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e == null ? void 0 : e.getActiveSheet(), r = {};
- a.flat().forEach((i) => {
- r[i.unitId] || (r[i.unitId] = {}), r[i.unitId][i.subUnitId] || (r[i.unitId][i.subUnitId] = []);
- const o = this._univerInstanceService.getUnit(i.unitId, N.UNIVER_SHEET), n = o == null ? void 0 : o.getSheetBySheetId(i.subUnitId);
- n && r[i.unitId][i.subUnitId].push(...i.ranges.map((l) => b.transformRange(l, n)));
- }), Object.entries(r).forEach(([i, o]) => {
- Object.entries(o).forEach(([n, l]) => {
- (e == null ? void 0 : e.getUnitId()) === i && (t == null ? void 0 : t.getSheetId()) === n ? this.validatorRanges(i, n, l) : requestIdleCallback(() => {
- this.validatorRanges(i, n, l);
- });
- });
- });
- };
- this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(Wt(() => this._lifecycleService.lifecycle$.pipe(Ze((a) => a === ze.Rendered)))).subscribe(s)), this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(Ze(() => this._lifecycleService.stage >= ze.Rendered), Ct(20)).subscribe(s));
- }
- async _validatorByCell(s, a, e, t) {
- const r = s.getUnitId(), i = a.getSheetId();
- if (!V.isDefine(e) || !V.isDefine(t))
- throw new Error(`row or col is not defined, row: ${e}, col: ${t}`);
- const o = this._sheetDataValidationModel.getRuleByLocation(r, i, e, t);
- return o ? new Promise((n) => {
- this._sheetDataValidationModel.validator(o, { unitId: r, subUnitId: i, row: e, col: t, worksheet: a, workbook: s }, (l) => {
- n(l);
- });
- }) : D.VALID;
- }
- async validatorCell(s, a, e, t) {
- const r = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
- if (!r)
- throw new Error(`cannot find current workbook, unitId: ${s}`);
- const i = r.getSheetBySheetId(a);
- if (!i)
- throw new Error(`cannot find current worksheet, sheetId: ${a}`);
- return this._validatorByCell(r, i, e, t);
- }
- validatorRanges(s, a, e) {
- if (!e.length)
- return Promise.resolve([]);
- const t = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
- if (!t)
- throw new Error(`cannot find current workbook, unitId: ${s}`);
- const r = t.getSheetBySheetId(a);
- if (!r)
- throw new Error(`cannot find current worksheet, sheetId: ${a}`);
- return Promise.all(e.map((i) => {
- const o = [];
- return b.foreach(i, (n, l) => {
- o.push(this._validatorByCell(t, r, n, l));
- }), Promise.all(o);
- }));
- }
- async validatorWorksheet(s, a) {
- const e = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
- if (!e)
- throw new Error(`cannot find current workbook, unitId: ${s}`);
- const t = e.getSheetBySheetId(a);
- if (!t)
- throw new Error(`cannot find current worksheet, sheetId: ${a}`);
- const r = this._sheetDataValidationModel.getRules(s, a);
- return await Promise.all(r.map((i) => Promise.all(i.ranges.map((o) => {
- const n = [];
- return b.foreach(o, (l, u) => {
- n.push(this._validatorByCell(e, t, l, u));
- }), n;
- })))), this._dataValidationCacheService.ensureCache(s, a);
- }
- async validatorWorkbook(s) {
- const a = this._sheetDataValidationModel.getSubUnitIds(s), e = await Promise.all(a.map((r) => this.validatorWorksheet(s, r))), t = {};
- return e.forEach((r, i) => {
- t[a[i]] = r;
- }), t;
- }
- getDataValidations(s, a, e) {
- const t = this._sheetDataValidationModel.getRuleObjectMatrix(s, a), r = /* @__PURE__ */ new Set();
- return e.forEach((o) => {
- b.foreach(o, (n, l) => {
- const u = t.getValue(n, l);
- u && r.add(u);
- });
- }), Array.from(r).map((o) => this._sheetDataValidationModel.getRuleById(s, a, o)).filter(Boolean);
- }
- getDataValidation(s, a, e) {
- return this.getDataValidations(s, a, e)[0];
- }
- };
- Oe = ka([
- Re(0, O),
- Re(1, S(F)),
- Re(2, S(q)),
- Re(3, S(Nt))
- ], Oe);
- var _t = Object.defineProperty, Ya = Object.getOwnPropertyDescriptor, Xa = (s, a, e) => a in s ? _t(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e, Ka = (s, a, e, t) => {
- for (var r = t > 1 ? void 0 : t ? Ya(a, e) : a, i = s.length - 1, o; i >= 0; i--)
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
- return t && r && _t(a, e, r), r;
- }, je = (s, a) => (e, t) => a(e, t, s), pt = (s, a, e) => Xa(s, typeof a != "symbol" ? a + "" : a, e);
- let we = class extends wt {
- constructor(s = tt, a, e, t) {
- super(), this._config = s, this._injector = a, this._commandService = e, this._configService = t;
- const { ...r } = It(
- {},
- tt,
- this._config
- );
- this._configService.setConfig(Ta, r);
- }
- onStarting() {
- [
- [q],
- [K],
- [P],
- [Oe],
- [F],
- [Ce],
- [Te],
- [Ne],
- [Fe],
- [Ee]
- ].forEach((s) => {
- this._injector.add(s);
- }), [
- Ra,
- pa,
- Sa,
- va,
- Ea,
- Ma,
- Va
- ].forEach((s) => {
- this._commandService.registerCommand(s);
- }), this._injector.get(q), this._injector.get(Oe), this._injector.get(Ee), this._injector.get(Fe);
- }
- onReady() {
- this._injector.get(Ne);
- }
- onRendered() {
- this._injector.get(Ce), this._injector.get(Te);
- }
- };
- pt(we, "pluginName", Yt);
- pt(we, "type", N.UNIVER_SHEET);
- we = Ka([
- Ot(xt),
- je(1, S(Ge)),
- je(2, x),
- je(3, At)
- ], we);
- function or(s) {
- const e = s.get(nt).getCurrentSelections().map((i) => i.range);
- return {
- uid: V.generateRandomId(6),
- type: T.DECIMAL,
- operator: h.EQUAL,
- formula1: "100",
- ranges: e != null ? e : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
- };
- }
- export {
- Ra as AddSheetDataValidationCommand,
- Ve as CHECKBOX_FORMULA_1,
- Me as CHECKBOX_FORMULA_2,
- na as CheckboxValidator,
- Va as ClearRangeDataValidationCommand,
- Yt as DATA_VALIDATION_PLUGIN_NAME,
- q as DataValidationCacheService,
- P as DataValidationCustomFormulaService,
- Te as DataValidationFormulaController,
- K as DataValidationFormulaService,
- ca as DateValidator,
- $a as ListMultipleValidator,
- mt as ListValidator,
- Ma as RemoveSheetAllDataValidationCommand,
- Ea as RemoveSheetDataValidationCommand,
- F as SheetDataValidationModel,
- Oe as SheetsDataValidationValidatorService,
- we as UniverSheetsDataValidationPlugin,
- va as UpdateSheetDataValidationOptionsCommand,
- pa as UpdateSheetDataValidationRangeCommand,
- Sa as UpdateSheetDataValidationSettingCommand,
- or as createDefaultNewRule,
- pe as deserializeListOptions,
- ne as getCellValueOrigin,
- sr as getDataValidationCellValue,
- be as getDataValidationDiffMutations,
- ge as getFormulaCellData,
- se as getFormulaResult,
- C as isLegalFormulaResult,
- ir as serializeListOptions,
- _e as transformCheckboxValue
- };
|