index.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409
  1. var Rt = Object.defineProperty;
  2. var St = (s, a, e) => a in s ? Rt(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e;
  3. var f = (s, a, e) => St(s, typeof a != "symbol" ? a + "" : a, e);
  4. 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";
  5. 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";
  6. 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";
  7. import { Subject as Qe, bufferWhen as Wt, filter as Ze } from "rxjs";
  8. import { RegisterOtherFormulaService as lt, FormulaRefRangeService as ut } from "@univerjs/sheets-formula";
  9. 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";
  10. const Yt = "SHEET_DATA_VALIDATION_PLUGIN";
  11. var Xt = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, zt = (s, a, e, t) => {
  12. for (var r = t > 1 ? void 0 : t ? Kt(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  13. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  14. return t && r && Xt(a, e, r), r;
  15. }, Je = (s, a) => (e, t) => a(e, t, s);
  16. let q = class extends $ {
  17. constructor(a, e) {
  18. super();
  19. f(this, "_cacheMatrix", /* @__PURE__ */ new Map());
  20. f(this, "_dirtyRanges$", new Qe());
  21. f(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
  22. this._commandService = a, this._univerInstanceService = e, this._initDirtyRanges(), this._initSheetRemove();
  23. }
  24. _initDirtyRanges() {
  25. this.disposeWithMe(this._commandService.onCommandExecuted((a) => {
  26. if (a.id === oe.id) {
  27. const { cellValue: e, unitId: t, subUnitId: r } = a.params;
  28. if (e) {
  29. const i = new ve(e).getDataRange();
  30. if (i.endRow === -1) return;
  31. this.markRangeDirty(t, r, [i]);
  32. }
  33. }
  34. }));
  35. }
  36. _initSheetRemove() {
  37. this.disposeWithMe(this._commandService.onCommandExecuted((a) => {
  38. var e;
  39. if (a.id === it.id) {
  40. const { unitId: t, subUnitId: r } = a.params;
  41. (e = this._cacheMatrix.get(t)) == null || e.delete(r);
  42. }
  43. })), this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((a) => {
  44. a.type === N.UNIVER_SHEET && this._cacheMatrix.delete(a.getUnitId());
  45. }));
  46. }
  47. _ensureCache(a, e) {
  48. let t = this._cacheMatrix.get(a);
  49. t || (t = /* @__PURE__ */ new Map(), this._cacheMatrix.set(a, t));
  50. let r = t.get(e);
  51. return r || (r = new ve(), t.set(e, r)), r;
  52. }
  53. ensureCache(a, e) {
  54. return this._ensureCache(a, e);
  55. }
  56. addRule(a, e, t) {
  57. this.markRangeDirty(a, e, t.ranges);
  58. }
  59. removeRule(a, e, t) {
  60. this._deleteRange(a, e, t.ranges);
  61. }
  62. markRangeDirty(a, e, t) {
  63. const r = this._ensureCache(a, e);
  64. t.forEach((i) => {
  65. b.foreach(i, (o, n) => {
  66. r.setValue(o, n, void 0);
  67. });
  68. }), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
  69. }
  70. _deleteRange(a, e, t) {
  71. const r = this._ensureCache(a, e);
  72. t.forEach((i) => {
  73. b.foreach(i, (o, n) => {
  74. r.realDeleteValue(o, n);
  75. });
  76. }), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
  77. }
  78. getValue(a, e, t, r) {
  79. return this._ensureCache(a, e).getValue(t, r);
  80. }
  81. };
  82. q = zt([
  83. Je(0, S(x)),
  84. Je(1, S(O))
  85. ], q);
  86. function se(s) {
  87. var a, e;
  88. return (e = (a = s == null ? void 0 : s[0]) == null ? void 0 : a[0]) == null ? void 0 : e.v;
  89. }
  90. function ge(s) {
  91. var a;
  92. return (a = s == null ? void 0 : s[0]) == null ? void 0 : a[0];
  93. }
  94. function C(s) {
  95. return !jt.has(s);
  96. }
  97. function de(s, a) {
  98. var t;
  99. const e = a.getValidatorItem(s);
  100. return (t = e == null ? void 0 : e.offsetFormulaByRange) != null ? t : !1;
  101. }
  102. var Zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, ea = (s, a, e, t) => {
  103. for (var r = t > 1 ? void 0 : t ? Jt(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  104. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  105. return t && r && Zt(a, e, r), r;
  106. }, re = (s, a) => (e, t) => a(e, t, s);
  107. let P = class extends $ {
  108. constructor(a, e, t, r, i) {
  109. super();
  110. /**
  111. * Map of origin formula of rule
  112. */
  113. f(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
  114. f(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
  115. this._instanceSrv = a, this._registerOtherFormulaService = e, this._dataValidationModel = t, this._dataValidationCacheService = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
  116. }
  117. _initFormulaResultHandler() {
  118. this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
  119. for (const e in a) {
  120. const t = a[e];
  121. if (this._instanceSrv.getUnitType(e) === N.UNIVER_SHEET)
  122. for (const i in t) {
  123. const o = t[i], { ruleFormulaMap: n } = this._ensureMaps(e, i);
  124. o.forEach((l) => {
  125. var c, m;
  126. 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);
  127. d && u && this._dataValidationCacheService.markRangeDirty(e, i, d.ranges);
  128. });
  129. }
  130. }
  131. }));
  132. }
  133. _ensureMaps(a, e) {
  134. let t = this._ruleFormulaMap.get(a), r = this._ruleFormulaMap2.get(a);
  135. t || (t = /* @__PURE__ */ new Map(), this._ruleFormulaMap.set(a, t)), r || (r = /* @__PURE__ */ new Map(), this._ruleFormulaMap2.set(a, r));
  136. let i = t.get(e);
  137. i || (i = /* @__PURE__ */ new Map(), t.set(e, i));
  138. let o = r.get(e);
  139. return o || (o = /* @__PURE__ */ new Map(), r.set(e, o)), { ruleFormulaMap: i, ruleFormulaMap2: o };
  140. }
  141. _registerFormula(a, e, t, r, i) {
  142. return this._registerOtherFormulaService.registerFormulaWithRange(a, e, r, i, { ruleId: t });
  143. }
  144. deleteByRuleId(a, e, t) {
  145. const { ruleFormulaMap: r, ruleFormulaMap2: i } = this._ensureMaps(a, e), o = this._dataValidationModel.getRuleById(a, e, t), n = r.get(t);
  146. if (!o || !n)
  147. return;
  148. const l = r.get(t);
  149. l && (r.delete(t), this._registerOtherFormulaService.deleteFormula(a, e, [l.formulaId]));
  150. const u = i.get(t);
  151. u && (i.delete(t), this._registerOtherFormulaService.deleteFormula(a, e, [u.formulaId]));
  152. }
  153. _addFormulaByRange(a, e, t, r, i, o) {
  154. const { ruleFormulaMap: n, ruleFormulaMap2: l } = this._ensureMaps(a, e), u = o[0].startRow, d = o[0].startColumn;
  155. if (r && v(r)) {
  156. const c = this._registerFormula(a, e, t, r, o);
  157. n.set(t, {
  158. formula: r,
  159. originCol: d,
  160. originRow: u,
  161. formulaId: c
  162. });
  163. }
  164. if (i && v(i)) {
  165. const c = this._registerFormula(a, e, t, i, o);
  166. l.set(t, {
  167. formula: i,
  168. originCol: d,
  169. originRow: u,
  170. formulaId: c
  171. });
  172. }
  173. }
  174. addRule(a, e, t) {
  175. if (de(t.type, this._validatorRegistryService)) {
  176. const { ranges: r, formula1: i, formula2: o, uid: n } = t;
  177. this._addFormulaByRange(a, e, n, i, o, r);
  178. }
  179. }
  180. async getCellFormulaValue(a, e, t, r, i) {
  181. var _, g;
  182. const { ruleFormulaMap: o } = this._ensureMaps(a, e), n = o.get(t);
  183. if (!n)
  184. return Promise.resolve(void 0);
  185. const l = await this._registerOtherFormulaService.getFormulaValue(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
  186. return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
  187. }
  188. async getCellFormula2Value(a, e, t, r, i) {
  189. var _, g;
  190. const { ruleFormulaMap2: o } = this._ensureMaps(a, e), n = o.get(t);
  191. if (!n)
  192. return Promise.resolve(void 0);
  193. const l = await this._registerOtherFormulaService.getFormulaValue(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
  194. return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
  195. }
  196. getCellFormulaValueSync(a, e, t, r, i) {
  197. var _, g;
  198. const { ruleFormulaMap: o } = this._ensureMaps(a, e), n = o.get(t);
  199. if (!n)
  200. return;
  201. const l = this._registerOtherFormulaService.getFormulaValueSync(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
  202. return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
  203. }
  204. getCellFormula2ValueSync(a, e, t, r, i) {
  205. var _, g;
  206. const { ruleFormulaMap2: o } = this._ensureMaps(a, e), n = o.get(t);
  207. if (!n)
  208. return;
  209. const l = this._registerOtherFormulaService.getFormulaValueSync(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
  210. return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
  211. }
  212. getRuleFormulaInfo(a, e, t) {
  213. const { ruleFormulaMap: r } = this._ensureMaps(a, e);
  214. return r.get(t);
  215. }
  216. };
  217. P = ea([
  218. re(0, O),
  219. re(1, S(lt)),
  220. re(2, S(ke)),
  221. re(3, S(q)),
  222. re(4, S(G))
  223. ], P);
  224. var ta = Object.defineProperty, aa = Object.getOwnPropertyDescriptor, ra = (s, a, e, t) => {
  225. for (var r = t > 1 ? void 0 : t ? aa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  226. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  227. return t && r && ta(a, e, r), r;
  228. }, ie = (s, a) => (e, t) => a(e, t, s);
  229. let K = class extends $ {
  230. constructor(a, e, t, r, i) {
  231. super();
  232. f(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
  233. this._instanceService = a, this._registerOtherFormulaService = e, this._dataValidationCacheService = t, this._dataValidationModel = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
  234. }
  235. _initFormulaResultHandler() {
  236. this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
  237. for (const e in a) {
  238. const t = a[e];
  239. if (this._instanceService.getUnitType(e) === N.UNIVER_SHEET)
  240. for (const i in t) {
  241. const o = t[i], n = this._ensureRuleFormulaMap(e, i);
  242. o.forEach((l) => {
  243. var u, d;
  244. if (n.get((u = l.extra) == null ? void 0 : u.ruleId)) {
  245. const c = this._dataValidationModel.getRuleById(e, i, (d = l.extra) == null ? void 0 : d.ruleId);
  246. c && this._dataValidationCacheService.markRangeDirty(e, i, c.ranges);
  247. }
  248. });
  249. }
  250. }
  251. }));
  252. }
  253. _ensureRuleFormulaMap(a, e) {
  254. let t = this._formulaRuleMap.get(a);
  255. t || (t = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(a, t));
  256. let r = t.get(e);
  257. return r || (r = /* @__PURE__ */ new Map(), t.set(e, r)), r;
  258. }
  259. _registerSingleFormula(a, e, t, r) {
  260. const i = [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }];
  261. return this._registerOtherFormulaService.registerFormulaWithRange(a, e, t, i, { ruleId: r });
  262. }
  263. addRule(a, e, t) {
  264. if (!de(t.type, this._validatorRegistryService) && t.type !== T.CHECKBOX) {
  265. const { formula1: r, formula2: i, uid: o } = t, n = v(r), l = v(i);
  266. if (!n && !l)
  267. return;
  268. const u = this._ensureRuleFormulaMap(a, e), d = [void 0, void 0];
  269. if (n) {
  270. const c = this._registerSingleFormula(a, e, r, o);
  271. d[0] = { id: c, text: r };
  272. }
  273. if (l) {
  274. const c = this._registerSingleFormula(a, e, i, o);
  275. d[1] = { id: c, text: i };
  276. }
  277. u.set(o, d);
  278. }
  279. }
  280. removeRule(a, e, t) {
  281. const i = this._ensureRuleFormulaMap(a, e).get(t);
  282. if (!i)
  283. return;
  284. const [o, n] = i, l = [o == null ? void 0 : o.id, n == null ? void 0 : n.id].filter(Boolean);
  285. l.length && this._registerOtherFormulaService.deleteFormula(a, e, l);
  286. }
  287. getRuleFormulaResult(a, e, t) {
  288. const i = this._ensureRuleFormulaMap(a, e).get(t);
  289. if (!i)
  290. return Promise.resolve(null);
  291. const o = async (n) => n && this._registerOtherFormulaService.getFormulaValue(a, e, n.id);
  292. return Promise.all([
  293. o(i[0]),
  294. o(i[1])
  295. ]);
  296. }
  297. getRuleFormulaResultSync(a, e, t) {
  298. const i = this._ensureRuleFormulaMap(a, e).get(t);
  299. if (i)
  300. return i.map((o) => {
  301. if (o)
  302. return this._registerOtherFormulaService.getFormulaValueSync(a, e, o.id);
  303. });
  304. }
  305. getRuleFormulaInfo(a, e, t) {
  306. return this._ensureRuleFormulaMap(a, e).get(t);
  307. }
  308. };
  309. K = ra([
  310. ie(0, O),
  311. ie(1, S(lt)),
  312. ie(2, S(q)),
  313. ie(3, S(ke)),
  314. ie(4, S(G))
  315. ], K);
  316. function ne(s) {
  317. return vt(s);
  318. }
  319. function ct(s) {
  320. var a;
  321. return String((a = ne(s)) != null ? a : "");
  322. }
  323. class Xe {
  324. constructor(a, e, t, r, i = !1) {
  325. f(this, "_map");
  326. f(this, "_tree", new Vt());
  327. f(this, "_dirty", !0);
  328. f(this, "_buildTree", () => {
  329. if (!this._dirty || this._disableTree)
  330. return;
  331. this._tree.clear();
  332. const a = [];
  333. this._map.forEach((e, t) => {
  334. e.forEach((r) => {
  335. a.push({
  336. minX: r.startRow,
  337. maxX: r.endRow,
  338. minY: r.startColumn,
  339. maxY: r.endColumn,
  340. ruleId: t
  341. });
  342. });
  343. }), this._tree.load(a), this._dirty = !1;
  344. });
  345. f(this, "_debonceBuildTree", Mt(this._buildTree, 0));
  346. this._unitId = e, this._subUnitId = t, this._univerInstanceService = r, this._disableTree = i, this._map = a, this._buildTree();
  347. }
  348. get _worksheet() {
  349. var a;
  350. return (a = this._univerInstanceService.getUnit(this._unitId, N.UNIVER_SHEET)) == null ? void 0 : a.getSheetBySheetId(this._subUnitId);
  351. }
  352. _addRule(a, e) {
  353. if (!this._worksheet)
  354. return;
  355. const t = I.mergeRanges(e.map((r) => b.transformRange(r, this._worksheet)));
  356. this._map.forEach((r, i) => {
  357. const o = I.subtractMulti(r, t);
  358. o.length === 0 ? this._map.delete(i) : this._map.set(i, o);
  359. }), this._dirty = !0, this._map.set(a, t), this._debonceBuildTree();
  360. }
  361. addRule(a) {
  362. this._addRule(a.uid, a.ranges);
  363. }
  364. removeRange(a) {
  365. if (!this._worksheet)
  366. return;
  367. const e = a.map((t) => b.transformRange(t, this._worksheet));
  368. this._map.forEach((t, r) => {
  369. const i = I.subtractMulti(t, e);
  370. i.length === 0 ? this._map.delete(r) : this._map.set(r, i);
  371. }), this._dirty = !0, this._debonceBuildTree();
  372. }
  373. _removeRule(a) {
  374. this._map.delete(a), this._dirty = !0, this._debonceBuildTree();
  375. }
  376. removeRule(a) {
  377. this._removeRule(a.uid);
  378. }
  379. updateRange(a, e) {
  380. this._removeRule(a), this._addRule(a, e);
  381. }
  382. addRangeRules(a) {
  383. a.forEach(({ id: e, ranges: t }) => {
  384. if (!t.length)
  385. return;
  386. let r = this._map.get(e);
  387. 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) => {
  388. if (o === e)
  389. return;
  390. const n = I.subtractMulti(i, t);
  391. n.length === 0 ? this._map.delete(o) : this._map.set(o, n);
  392. });
  393. }), this._dirty = !0, this._debonceBuildTree();
  394. }
  395. diff(a) {
  396. const e = [];
  397. let t = 0;
  398. return a.forEach((r, i) => {
  399. var l;
  400. const o = (l = this._map.get(r.uid)) != null ? l : [], n = r.ranges;
  401. o.length !== 0 && (o.length !== n.length || o.some((u, d) => !I.equals(u, n[d]))) && e.push({
  402. type: "update",
  403. ruleId: r.uid,
  404. oldRanges: n,
  405. newRanges: I.sort(o),
  406. rule: r
  407. }), o.length === 0 && (e.push({
  408. type: "delete",
  409. rule: r,
  410. index: i - t
  411. }), t++);
  412. }), e;
  413. }
  414. diffWithAddition(a, e) {
  415. const t = [];
  416. let r = 0;
  417. return a.forEach((i, o) => {
  418. var u;
  419. const n = (u = this._map.get(i.uid)) != null ? u : [], l = i.ranges;
  420. n.length !== 0 && (n.length !== l.length || n.some((d, c) => !I.equals(d, l[c]))) && t.push({
  421. type: "update",
  422. ruleId: i.uid,
  423. oldRanges: l,
  424. newRanges: I.sort(n),
  425. rule: i
  426. }), n.length === 0 && (t.push({
  427. type: "delete",
  428. rule: i,
  429. index: o - r
  430. }), r++);
  431. }), Array.from(e).forEach((i) => {
  432. var n;
  433. const o = (n = this._map.get(i.uid)) != null ? n : [];
  434. t.push({
  435. type: "add",
  436. rule: {
  437. ...i,
  438. ranges: I.sort(o)
  439. }
  440. });
  441. }), t;
  442. }
  443. clone() {
  444. return new Xe(
  445. new Map(V.deepClone(Array.from(this._map.entries()))),
  446. this._unitId,
  447. this._subUnitId,
  448. this._univerInstanceService,
  449. // disable tree on cloned matrix, cause there is no need to search
  450. !0
  451. );
  452. }
  453. getValue(a, e) {
  454. this._dirty && this._buildTree();
  455. const t = this._tree.search({
  456. minX: a,
  457. maxX: a,
  458. minY: e,
  459. maxY: e
  460. });
  461. return t.length > 0 ? t[0].ruleId : void 0;
  462. }
  463. }
  464. var ia = Object.defineProperty, sa = Object.getOwnPropertyDescriptor, oa = (s, a, e, t) => {
  465. for (var r = t > 1 ? void 0 : t ? sa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  466. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  467. return t && r && ia(a, e, r), r;
  468. }, X = (s, a) => (e, t) => a(e, t, s);
  469. let F = class extends $ {
  470. constructor(a, e, t, r, i, o, n) {
  471. super();
  472. f(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
  473. f(this, "_validStatusChange$", new Qe());
  474. f(this, "_ruleChange$", new Qe());
  475. f(this, "ruleChange$", this._ruleChange$.asObservable());
  476. f(this, "validStatusChange$", this._validStatusChange$.asObservable());
  477. 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(() => {
  478. this._ruleChange$.complete(), this._validStatusChange$.complete();
  479. }), this._initUniverInstanceListener();
  480. }
  481. _initUniverInstanceListener() {
  482. this.disposeWithMe(
  483. this._univerInstanceService.unitDisposed$.subscribe((a) => {
  484. this._ruleMatrixMap.delete(a.getUnitId());
  485. })
  486. ), this.disposeWithMe(
  487. this._commandService.onCommandExecuted((a) => {
  488. if (a.id === it.id) {
  489. const { unitId: e, subUnitId: t } = a.params, r = this._ruleMatrixMap.get(e);
  490. r && r.delete(t);
  491. }
  492. })
  493. );
  494. }
  495. _initRuleUpdateListener() {
  496. const a = this._dataValidationModel.getAll();
  497. for (const [e, t] of a)
  498. for (const [r, i] of t)
  499. for (const o of i)
  500. this._addRule(e, r, o), this._ruleChange$.next({
  501. type: "add",
  502. unitId: e,
  503. subUnitId: r,
  504. rule: o,
  505. source: "patched"
  506. });
  507. this.disposeWithMe(
  508. this._dataValidationModel.ruleChange$.subscribe((e) => {
  509. switch (e.type) {
  510. case "add":
  511. this._addRule(e.unitId, e.subUnitId, e.rule);
  512. break;
  513. case "update":
  514. this._updateRule(e.unitId, e.subUnitId, e.rule.uid, e.oldRule, e.updatePayload);
  515. break;
  516. case "remove":
  517. this._removeRule(e.unitId, e.subUnitId, e.rule);
  518. break;
  519. }
  520. this._ruleChange$.next(e);
  521. })
  522. );
  523. }
  524. _ensureRuleMatrix(a, e) {
  525. let t = this._ruleMatrixMap.get(a);
  526. t || (t = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(a, t));
  527. let r = t.get(e);
  528. return r || (r = new Xe(/* @__PURE__ */ new Map(), a, e, this._univerInstanceService), t.set(e, r)), r;
  529. }
  530. _addRuleSideEffect(a, e, t) {
  531. this._ensureRuleMatrix(a, e).addRule(t), this._dataValidationCacheService.addRule(a, e, t), this._dataValidationFormulaService.addRule(a, e, t), this._dataValidationCustomFormulaService.addRule(a, e, t);
  532. }
  533. _addRule(a, e, t) {
  534. (Array.isArray(t) ? t : [t]).forEach((i) => {
  535. this._addRuleSideEffect(a, e, i);
  536. });
  537. }
  538. _updateRule(a, e, t, r, i) {
  539. const o = this._ensureRuleMatrix(a, e), n = {
  540. ...r,
  541. ...i.payload
  542. };
  543. 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);
  544. }
  545. _removeRule(a, e, t) {
  546. this._ensureRuleMatrix(a, e).removeRule(t), this._dataValidationCacheService.removeRule(a, e, t), this._dataValidationCustomFormulaService.deleteByRuleId(a, e, t.uid);
  547. }
  548. getValidator(a) {
  549. return this._dataValidatorRegistryService.getValidatorItem(a);
  550. }
  551. getRuleIdByLocation(a, e, t, r) {
  552. return this._ensureRuleMatrix(a, e).getValue(t, r);
  553. }
  554. getRuleByLocation(a, e, t, r) {
  555. const i = this.getRuleIdByLocation(a, e, t, r);
  556. if (i)
  557. return this._dataValidationModel.getRuleById(a, e, i);
  558. }
  559. validator(a, e, t) {
  560. const { col: r, row: i, unitId: o, subUnitId: n, worksheet: l } = e, u = (g, R) => {
  561. t && t(g, R), R && this._validStatusChange$.next({
  562. unitId: o,
  563. subUnitId: n,
  564. ruleId: a.uid,
  565. status: g,
  566. row: i,
  567. col: r
  568. });
  569. }, d = l.getCellValueOnly(i, r), c = this.getValidator(a.type), m = l.getCellRaw(i, r), _ = ne(m);
  570. if (c) {
  571. const g = this._dataValidationCacheService.ensureCache(o, n), R = g.getValue(i, r);
  572. return R == null ? (g.setValue(i, r, D.VALIDATING), c.validator(
  573. {
  574. value: _,
  575. unitId: o,
  576. subUnitId: n,
  577. row: i,
  578. column: r,
  579. worksheet: e.worksheet,
  580. workbook: e.workbook,
  581. interceptValue: ne(d),
  582. t: m == null ? void 0 : m.t
  583. },
  584. a
  585. ).then((M) => {
  586. const p = M ? D.VALID : D.INVALID;
  587. p === D.VALID ? g.realDeleteValue(i, r) : g.setValue(i, r, p);
  588. const w = g.getValue(i, r);
  589. u(p, R !== w);
  590. }), D.VALIDATING) : (u(R != null ? R : D.VALID, !1), R != null ? R : D.VALID);
  591. } else
  592. return u(D.VALID, !1), D.VALID;
  593. }
  594. getRuleObjectMatrix(a, e) {
  595. return this._ensureRuleMatrix(a, e);
  596. }
  597. getRuleById(a, e, t) {
  598. return this._dataValidationModel.getRuleById(a, e, t);
  599. }
  600. getRuleIndex(a, e, t) {
  601. return this._dataValidationModel.getRuleIndex(a, e, t);
  602. }
  603. getRules(a, e) {
  604. return [...this._dataValidationModel.getRules(a, e)];
  605. }
  606. getUnitRules(a) {
  607. return this._dataValidationModel.getUnitRules(a);
  608. }
  609. deleteUnitRules(a) {
  610. return this._dataValidationModel.deleteUnitRules(a);
  611. }
  612. getSubUnitIds(a) {
  613. return this._dataValidationModel.getSubUnitIds(a);
  614. }
  615. getAll() {
  616. return this._dataValidationModel.getAll();
  617. }
  618. };
  619. F = oa([
  620. X(0, S(ke)),
  621. X(1, O),
  622. X(2, S(G)),
  623. X(3, S(q)),
  624. X(4, S(K)),
  625. X(5, S(P)),
  626. X(6, x)
  627. ], F);
  628. const Ve = 1, Me = 0;
  629. function et(s, a) {
  630. return V.isBlank(s) ? a.t("dataValidation.validFail.value") : v(s) ? a.t("dataValidation.validFail.primitive") : "";
  631. }
  632. const _e = (s) => V.isDefine(s) && String(s).toLowerCase() === "true" ? "1" : String(s).toLowerCase() === "false" ? "0" : s;
  633. class na extends k {
  634. constructor() {
  635. super(...arguments);
  636. f(this, "id", T.CHECKBOX);
  637. f(this, "title", "dataValidation.checkbox.title");
  638. f(this, "operators", []);
  639. f(this, "scopes", ["sheet"]);
  640. f(this, "offsetFormulaByRange", !1);
  641. f(this, "_formulaService", this.injector.get(K));
  642. f(this, "skipDefaultFontRender", (e, t, r) => {
  643. const { unitId: i, subUnitId: o } = r, { formula1: n, formula2: l } = this.parseFormulaSync(e, i, o), u = `${t != null ? t : ""}`;
  644. return !u || u === `${n}` || u === `${l}`;
  645. });
  646. }
  647. validatorFormula(e, t, r) {
  648. const { formula1: i, formula2: o } = e, n = i === o;
  649. if (V.isBlank(i) && V.isBlank(o))
  650. return {
  651. success: !0
  652. };
  653. if (n)
  654. return {
  655. success: !1,
  656. formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
  657. formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
  658. };
  659. const l = et(i, this.localeService), u = et(o, this.localeService);
  660. return {
  661. success: !l && !u,
  662. formula1: l,
  663. formula2: u
  664. };
  665. }
  666. async parseFormula(e, t, r) {
  667. var c, m, _, g;
  668. 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));
  669. return {
  670. formula1: _e(l),
  671. formula2: _e(u),
  672. originFormula1: l,
  673. originFormula2: u,
  674. isFormulaValid: d
  675. };
  676. }
  677. getExtraStyle(e, t) {
  678. return {
  679. tb: Se.CLIP
  680. };
  681. }
  682. parseFormulaSync(e, t, r) {
  683. var c, m, _, g;
  684. 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));
  685. return {
  686. formula1: _e(l),
  687. formula2: _e(u),
  688. originFormula1: l,
  689. originFormula2: u,
  690. isFormulaValid: d
  691. };
  692. }
  693. async isValidType(e, t, r) {
  694. const { value: i, unitId: o, subUnitId: n } = e, { formula1: l, formula2: u, originFormula1: d, originFormula2: c } = await this.parseFormula(r, o, n);
  695. 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 : ""));
  696. }
  697. generateRuleErrorMessage(e) {
  698. return this.localeService.t("dataValidation.checkbox.error");
  699. }
  700. }
  701. const la = {
  702. [h.BETWEEN]: "dataValidation.date.operators.between",
  703. [h.EQUAL]: "dataValidation.date.operators.equal",
  704. [h.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
  705. [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
  706. [h.LESS_THAN]: "dataValidation.date.operators.lessThan",
  707. [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
  708. [h.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
  709. [h.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
  710. };
  711. 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 + "";
  712. const ua = {
  713. [h.BETWEEN]: "dataValidation.date.ruleName.between",
  714. [h.EQUAL]: "dataValidation.date.ruleName.equal",
  715. [h.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
  716. [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
  717. [h.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
  718. [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
  719. [h.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
  720. [h.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
  721. }, da = {
  722. [h.BETWEEN]: "dataValidation.date.errorMsg.between",
  723. [h.EQUAL]: "dataValidation.date.errorMsg.equal",
  724. [h.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
  725. [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
  726. [h.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
  727. [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
  728. [h.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
  729. [h.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
  730. }, Ae = [
  731. h.BETWEEN,
  732. h.NOT_BETWEEN
  733. ], le = "{FORMULA1}", ue = "{FORMULA2}";
  734. function ir(s) {
  735. return s.filter(Boolean).join(",");
  736. }
  737. function pe(s) {
  738. return s.split(",").filter(Boolean);
  739. }
  740. function sr(s) {
  741. const a = ne(s);
  742. return a == null ? "" : a.toString();
  743. }
  744. function De(s, a, e) {
  745. 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;
  746. return {
  747. transformedFormula1: u,
  748. transformedFormula2: d
  749. };
  750. }
  751. const Ue = (s) => {
  752. var e, t;
  753. if (s == null || typeof s == "boolean")
  754. return;
  755. if (typeof s == "number" || !Number.isNaN(+s))
  756. return +s;
  757. const a = (e = Q.parseDate(s)) == null ? void 0 : e.v;
  758. return V.isDefine(a) ? a : (t = Q.parseDate(at(s).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : t.v;
  759. };
  760. class ca extends k {
  761. constructor() {
  762. super(...arguments);
  763. f(this, "id", T.DATE);
  764. f(this, "title", "dataValidation.date.title");
  765. f(this, "operators", [
  766. h.BETWEEN,
  767. h.EQUAL,
  768. h.GREATER_THAN,
  769. h.GREATER_THAN_OR_EQUAL,
  770. h.LESS_THAN,
  771. h.LESS_THAN_OR_EQUAL,
  772. h.NOT_BETWEEN,
  773. h.NOT_EQUAL
  774. ]);
  775. f(this, "scopes", ["sheet"]);
  776. f(this, "_customFormulaService", this.injector.get(P));
  777. f(this, "_lexerTreeBuilder", this.injector.get(Y));
  778. }
  779. async parseFormula(e, t, r, i, o) {
  780. 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));
  781. return {
  782. formula1: Ue(v(u) ? n == null ? void 0 : n.v : u),
  783. formula2: Ue(v(d) ? l == null ? void 0 : l.v : d),
  784. isFormulaValid: c
  785. };
  786. }
  787. async isValidType(e) {
  788. const { interceptValue: t, value: r } = e;
  789. return typeof r == "number" && typeof t == "string" ? !0 : typeof t == "string" ? !!Q.parseDate(t) : !1;
  790. }
  791. _validatorSingleFormula(e) {
  792. return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) || !!(e && Q.parseDate(e)));
  793. }
  794. validatorFormula(e, t, r) {
  795. const i = e.operator;
  796. if (!i)
  797. return {
  798. success: !1
  799. };
  800. const o = this._validatorSingleFormula(e.formula1), n = this.localeService.t("dataValidation.validFail.date");
  801. if (Ae.includes(i)) {
  802. const u = this._validatorSingleFormula(e.formula2);
  803. return {
  804. success: o && u,
  805. formula1: o ? void 0 : n,
  806. formula2: u ? void 0 : n
  807. };
  808. }
  809. return {
  810. success: o,
  811. formula1: o ? void 0 : n
  812. };
  813. }
  814. normalizeFormula(e, t, r) {
  815. const { formula1: i, formula2: o, bizInfo: n } = e, l = (u) => {
  816. var c;
  817. if (!u)
  818. return u;
  819. let d;
  820. if (!Number.isNaN(+u))
  821. d = Q.dateFromSerial(+u);
  822. else {
  823. const m = (c = Q.parseDate(u)) == null ? void 0 : c.v;
  824. if (m == null)
  825. return "";
  826. d = Q.dateFromSerial(m);
  827. }
  828. 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");
  829. };
  830. return {
  831. formula1: v(i) ? i : l(`${i}`),
  832. formula2: v(o) ? o : l(`${o}`)
  833. };
  834. }
  835. transform(e, t, r) {
  836. const { value: i } = e;
  837. return {
  838. ...e,
  839. value: Ue(i)
  840. };
  841. }
  842. get operatorNames() {
  843. return this.operators.map((e) => this.localeService.t(la[e]));
  844. }
  845. generateRuleName(e) {
  846. var r, i;
  847. if (!e.operator)
  848. return this.titleStr;
  849. const t = this.localeService.t(ua[e.operator]).replace(le, (r = e.formula1) != null ? r : "").replace(ue, (i = e.formula2) != null ? i : "");
  850. return `${this.titleStr} ${t}`;
  851. }
  852. generateRuleErrorMessage(e, t) {
  853. if (!e.operator)
  854. return this.titleStr;
  855. const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
  856. return `${this.localeService.t(da[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
  857. }
  858. }
  859. 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 + "";
  860. 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 + "";
  861. const ht = {
  862. [h.BETWEEN]: "dataValidation.errorMsg.between",
  863. [h.EQUAL]: "dataValidation.errorMsg.equal",
  864. [h.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
  865. [h.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
  866. [h.LESS_THAN]: "dataValidation.errorMsg.lessThan",
  867. [h.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
  868. [h.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
  869. [h.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
  870. };
  871. function ye(s) {
  872. let a = s;
  873. return typeof s == "string" ? ((s.startsWith("¥") || s.startsWith("$")) && (a = s.slice(1)), +a) : +s;
  874. }
  875. class ha extends k {
  876. constructor() {
  877. super(...arguments);
  878. f(this, "_customFormulaService", this.injector.get(P));
  879. f(this, "id", T.DECIMAL);
  880. f(this, "_lexerTreeBuilder", this.injector.get(Y));
  881. f(this, "title", "dataValidation.decimal.title");
  882. f(this, "operators", [
  883. h.BETWEEN,
  884. h.EQUAL,
  885. h.GREATER_THAN,
  886. h.GREATER_THAN_OR_EQUAL,
  887. h.LESS_THAN,
  888. h.LESS_THAN_OR_EQUAL,
  889. h.NOT_BETWEEN,
  890. h.NOT_EQUAL
  891. ]);
  892. f(this, "scopes", ["sheet"]);
  893. }
  894. _isFormulaOrNumber(e) {
  895. return !V.isBlank(e) && (v(e) || !Number.isNaN(+e));
  896. }
  897. async isValidType(e, t, r) {
  898. const { value: i } = e;
  899. return !Number.isNaN(ye(i));
  900. }
  901. transform(e, t, r) {
  902. const { value: i } = e;
  903. return {
  904. ...e,
  905. value: ye(i)
  906. };
  907. }
  908. _parseNumber(e) {
  909. return e == null ? Number.NaN : +e;
  910. }
  911. async parseFormula(e, t, r, i, o) {
  912. 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));
  913. return {
  914. formula1: this._parseNumber(v(u) ? n == null ? void 0 : n.v : u),
  915. formula2: this._parseNumber(v(d) ? l == null ? void 0 : l.v : d),
  916. isFormulaValid: c
  917. };
  918. }
  919. validatorFormula(e, t, r) {
  920. const i = e.operator;
  921. if (!i)
  922. return {
  923. success: !1
  924. };
  925. 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");
  926. return l ? {
  927. success: o && n,
  928. formula1: o ? void 0 : u,
  929. formula2: n ? void 0 : u
  930. } : {
  931. success: o,
  932. formula1: o ? "" : u
  933. };
  934. }
  935. generateRuleErrorMessage(e, t) {
  936. if (!e.operator)
  937. return this.titleStr;
  938. const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
  939. return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
  940. }
  941. }
  942. function Pe(s) {
  943. if (!s)
  944. return [];
  945. const a = /* @__PURE__ */ new Set();
  946. return s.forEach(
  947. (e) => {
  948. e.forEach((t) => {
  949. var i, o;
  950. const r = ne(t);
  951. if (r != null) {
  952. if (typeof r != "string" && typeof (t == null ? void 0 : t.s) == "object" && ((o = (i = t.s) == null ? void 0 : i.n) != null && o.pattern)) {
  953. a.add(Q.format(t.s.n.pattern, r, { throws: !1 }));
  954. return;
  955. }
  956. C(r.toString()) && a.add(r.toString());
  957. }
  958. });
  959. }
  960. ), [...a];
  961. }
  962. const ma = [
  963. "if",
  964. "indirect",
  965. "choose",
  966. "offset"
  967. ];
  968. function fa(s, a) {
  969. if (!v(s) || dt(s.slice(1)))
  970. return !0;
  971. const t = a.sequenceNodesBuilder(s);
  972. return t && t.some((r) => typeof r == "object" && r.nodeType === Qt.FUNCTION && ma.indexOf(r.token.toLowerCase()) > -1);
  973. }
  974. function ga(s, a) {
  975. const { formula1: e = "", ranges: t } = s;
  976. if (dt(e.slice(1))) {
  977. const i = qt(e.slice(1));
  978. if ((!i.sheetName || i.sheetName === a) && t.some((o) => I.intersects(o, i.range)))
  979. return !0;
  980. }
  981. return !1;
  982. }
  983. class mt extends k {
  984. constructor() {
  985. super(...arguments);
  986. f(this, "formulaService", this.injector.get(K));
  987. f(this, "_lexer", this.injector.get(Y));
  988. f(this, "_univerInstanceService", this.injector.get(O));
  989. f(this, "offsetFormulaByRange", !1);
  990. f(this, "id", T.LIST);
  991. f(this, "title", "dataValidation.list.title");
  992. f(this, "operators", []);
  993. f(this, "scopes", ["sheet"]);
  994. f(this, "skipDefaultFontRender", (e) => e.renderMode !== Be.TEXT);
  995. }
  996. validatorFormula(e, t, r) {
  997. var u, d, c;
  998. 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 : "");
  999. return {
  1000. success: !!(i && o && !l),
  1001. formula1: i ? o ? l ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
  1002. };
  1003. }
  1004. getExtraStyle(e, t, { style: r }) {
  1005. var o;
  1006. const i = (o = r.tb !== Se.OVERFLOW ? r.tb : Se.CLIP) != null ? o : Se.WRAP;
  1007. if (e.type === T.LIST && (e.renderMode === Be.ARROW || e.renderMode === Be.TEXT)) {
  1008. const n = this.getListWithColorMap(e), l = `${t != null ? t : ""}`, u = n[l];
  1009. if (u)
  1010. return {
  1011. bg: {
  1012. rgb: u
  1013. },
  1014. tb: i
  1015. };
  1016. }
  1017. return {
  1018. tb: i
  1019. };
  1020. }
  1021. parseCellValue(e) {
  1022. const t = e.toString();
  1023. return pe(t);
  1024. }
  1025. async parseFormula(e, t, r) {
  1026. var l, u;
  1027. 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]);
  1028. return {
  1029. formula1: void 0,
  1030. formula2: void 0,
  1031. isFormulaValid: C(String(o))
  1032. };
  1033. }
  1034. async isValidType(e, t, r) {
  1035. var m, _;
  1036. 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);
  1037. return this.parseCellValue(i).every((g) => d.includes(g));
  1038. }
  1039. generateRuleName() {
  1040. return this.localeService.t("dataValidation.list.name");
  1041. }
  1042. generateRuleErrorMessage() {
  1043. return this.localeService.t("dataValidation.list.error");
  1044. }
  1045. getList(e, t, r) {
  1046. var m, _, g, R;
  1047. const { formula1: i = "" } = e, o = this.injector.get(O), n = (m = t ? o.getUniverSheetInstance(t) : void 0) != null ? m : o.getCurrentUnitForType(N.UNIVER_SHEET);
  1048. if (!n) return [];
  1049. const l = (_ = r ? n.getSheetBySheetId(r) : void 0) != null ? _ : n.getActiveSheet();
  1050. if (!l) return [];
  1051. const u = n.getUnitId(), d = l.getSheetId(), c = this.formulaService.getRuleFormulaResultSync(u, d, e.uid);
  1052. 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);
  1053. }
  1054. async getListAsync(e, t, r) {
  1055. var m, _, g, R;
  1056. const { formula1: i = "" } = e, o = this.injector.get(O), n = (m = t ? o.getUniverSheetInstance(t) : void 0) != null ? m : o.getCurrentUnitForType(N.UNIVER_SHEET);
  1057. if (!n) return [];
  1058. const l = (_ = r ? n.getSheetBySheetId(r) : void 0) != null ? _ : n.getActiveSheet();
  1059. if (!l) return [];
  1060. const u = n.getUnitId(), d = l.getSheetId(), c = await this.formulaService.getRuleFormulaResult(u, d, e.uid);
  1061. 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);
  1062. }
  1063. getListWithColor(e, t, r) {
  1064. const i = this.getList(e, t, r), o = (e.formula2 || "").split(",");
  1065. return i.map((n, l) => ({ label: n, color: o[l] }));
  1066. }
  1067. getListWithColorMap(e, t, r) {
  1068. const i = this.getListWithColor(e, t, r), o = {};
  1069. return i.forEach((n) => {
  1070. n.color && (o[n.label] = n.color);
  1071. }), o;
  1072. }
  1073. }
  1074. class _a extends k {
  1075. constructor() {
  1076. super(...arguments);
  1077. f(this, "id", T.TEXT_LENGTH);
  1078. f(this, "title", "dataValidation.textLength.title");
  1079. f(this, "_lexerTreeBuilder", this.injector.get(Y));
  1080. f(this, "operators", [
  1081. h.BETWEEN,
  1082. h.EQUAL,
  1083. h.GREATER_THAN,
  1084. h.GREATER_THAN_OR_EQUAL,
  1085. h.LESS_THAN,
  1086. h.LESS_THAN_OR_EQUAL,
  1087. h.NOT_BETWEEN,
  1088. h.NOT_EQUAL
  1089. ]);
  1090. f(this, "scopes", ["sheet"]);
  1091. f(this, "_customFormulaService", this.injector.get(P));
  1092. }
  1093. _isFormulaOrInt(e) {
  1094. return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) && Number.isInteger(+e));
  1095. }
  1096. validatorFormula(e, t, r) {
  1097. const i = e.operator;
  1098. if (!i)
  1099. return {
  1100. success: !1
  1101. };
  1102. 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");
  1103. return l ? {
  1104. success: o && n,
  1105. formula1: o ? void 0 : u,
  1106. formula2: n ? void 0 : u
  1107. } : {
  1108. success: o,
  1109. formula1: u
  1110. };
  1111. }
  1112. _parseNumber(e) {
  1113. return e == null ? Number.NaN : +e;
  1114. }
  1115. async parseFormula(e, t, r, i, o) {
  1116. 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));
  1117. return {
  1118. formula1: this._parseNumber(v(u) ? n == null ? void 0 : n.v : u),
  1119. formula2: this._parseNumber(v(d) ? l == null ? void 0 : l.v : d),
  1120. isFormulaValid: c
  1121. };
  1122. }
  1123. transform(e, t, r) {
  1124. return {
  1125. ...e,
  1126. value: e.value.toString().length
  1127. };
  1128. }
  1129. async isValidType(e, t, r) {
  1130. const { value: i } = e;
  1131. return typeof i == "string" || typeof i == "number";
  1132. }
  1133. generateRuleErrorMessage(e, t) {
  1134. if (!e.operator)
  1135. return this.titleStr;
  1136. const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
  1137. return `${this.localeService.t(Dt[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
  1138. }
  1139. }
  1140. function ft(s) {
  1141. var e, t;
  1142. 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;
  1143. }
  1144. function be(s, a, e, t, r = "command", i = !0) {
  1145. 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 });
  1146. if (!m)
  1147. return {
  1148. redoMutations: l,
  1149. undoMutations: u
  1150. };
  1151. const { worksheet: _ } = m, g = new ve();
  1152. let R = !1;
  1153. function M(p, w) {
  1154. i && p.forEach((H) => {
  1155. b.foreach(H, (B, W) => {
  1156. const U = _.getCellRaw(B, W), J = ct(U);
  1157. (ft(U) || J === w) && !(U != null && U.p) && (R = !0, g.setValue(B, W, {
  1158. v: w,
  1159. p: null
  1160. }));
  1161. });
  1162. });
  1163. }
  1164. if (e.forEach((p) => {
  1165. switch (p.type) {
  1166. case "delete":
  1167. l.push({
  1168. id: A.id,
  1169. params: {
  1170. unitId: s,
  1171. subUnitId: a,
  1172. ruleId: p.rule.uid,
  1173. source: r
  1174. }
  1175. }), u.unshift({
  1176. id: L.id,
  1177. params: {
  1178. unitId: s,
  1179. subUnitId: a,
  1180. rule: p.rule,
  1181. index: p.index,
  1182. source: r
  1183. }
  1184. });
  1185. break;
  1186. case "update": {
  1187. if (de(p.rule.type, n)) {
  1188. 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;
  1189. he !== p.rule.formula1 || me !== p.rule.formula2 || !rt(p.newRanges, p.oldRanges) ? (l.push({
  1190. id: E.id,
  1191. params: {
  1192. unitId: s,
  1193. subUnitId: a,
  1194. ruleId: p.ruleId,
  1195. payload: {
  1196. type: y.ALL,
  1197. payload: {
  1198. formula1: he,
  1199. formula2: me,
  1200. ranges: p.newRanges
  1201. }
  1202. }
  1203. }
  1204. }), u.unshift({
  1205. id: E.id,
  1206. params: {
  1207. unitId: s,
  1208. subUnitId: a,
  1209. ruleId: p.ruleId,
  1210. payload: {
  1211. type: y.ALL,
  1212. payload: {
  1213. formula1: p.rule.formula1,
  1214. formula2: p.rule.formula2,
  1215. ranges: p.oldRanges
  1216. }
  1217. }
  1218. }
  1219. })) : (l.push({
  1220. id: E.id,
  1221. params: {
  1222. unitId: s,
  1223. subUnitId: a,
  1224. ruleId: p.ruleId,
  1225. payload: {
  1226. type: y.RANGE,
  1227. payload: p.newRanges
  1228. },
  1229. source: r
  1230. }
  1231. }), u.unshift({
  1232. id: E.id,
  1233. params: {
  1234. unitId: s,
  1235. subUnitId: a,
  1236. ruleId: p.ruleId,
  1237. payload: {
  1238. type: y.RANGE,
  1239. payload: p.oldRanges
  1240. },
  1241. source: r
  1242. }
  1243. }));
  1244. } else
  1245. l.push({
  1246. id: E.id,
  1247. params: {
  1248. unitId: s,
  1249. subUnitId: a,
  1250. ruleId: p.ruleId,
  1251. payload: {
  1252. type: y.RANGE,
  1253. payload: p.newRanges
  1254. },
  1255. source: r
  1256. }
  1257. }), u.unshift({
  1258. id: E.id,
  1259. params: {
  1260. unitId: s,
  1261. subUnitId: a,
  1262. ruleId: p.ruleId,
  1263. payload: {
  1264. type: y.RANGE,
  1265. payload: p.oldRanges
  1266. },
  1267. source: r
  1268. }
  1269. });
  1270. const w = d.getRuleById(s, a, p.ruleId);
  1271. if (w && w.type === T.CHECKBOX) {
  1272. const B = d.getValidator(T.CHECKBOX).parseFormulaSync(w, s, a);
  1273. M(p.newRanges, B.formula2);
  1274. }
  1275. break;
  1276. }
  1277. case "add": {
  1278. if (l.push({
  1279. id: L.id,
  1280. params: {
  1281. unitId: s,
  1282. subUnitId: a,
  1283. rule: p.rule,
  1284. source: r
  1285. }
  1286. }), u.unshift({
  1287. id: A.id,
  1288. params: {
  1289. unitId: s,
  1290. subUnitId: a,
  1291. ruleId: p.rule.uid,
  1292. source: r
  1293. }
  1294. }), p.rule.type === T.CHECKBOX) {
  1295. const H = d.getValidator(T.CHECKBOX).parseFormulaSync(p.rule, s, a);
  1296. M(p.rule.ranges, H.originFormula2);
  1297. }
  1298. break;
  1299. }
  1300. }
  1301. }), R) {
  1302. const p = {
  1303. id: oe.id,
  1304. params: {
  1305. unitId: s,
  1306. subUnitId: a,
  1307. cellValue: g.getData()
  1308. }
  1309. }, w = {
  1310. id: oe.id,
  1311. params: st(t, p.params)
  1312. };
  1313. l.push(p), u.push(w);
  1314. }
  1315. return {
  1316. redoMutations: l,
  1317. undoMutations: u
  1318. };
  1319. }
  1320. const pa = {
  1321. type: z.COMMAND,
  1322. id: "sheet.command.updateDataValidationRuleRange",
  1323. handler(s, a) {
  1324. if (!a)
  1325. return !1;
  1326. const { unitId: e, subUnitId: t, ranges: r, ruleId: i } = a, o = s.get(F), n = s.get(x), l = s.get(Z);
  1327. if (!o.getRuleById(e, t, i))
  1328. return !1;
  1329. const d = o.getRuleObjectMatrix(e, t).clone();
  1330. d.updateRange(i, r);
  1331. const c = d.diff(o.getRules(e, t)), { redoMutations: m, undoMutations: _ } = be(e, t, c, s);
  1332. return l.pushUndoRedo({
  1333. undoMutations: _,
  1334. redoMutations: m,
  1335. unitID: e
  1336. }), Ie(m, n), !0;
  1337. }
  1338. }, Ra = {
  1339. type: z.COMMAND,
  1340. id: "sheet.command.addDataValidation",
  1341. handler(s, a) {
  1342. if (!a)
  1343. return !1;
  1344. 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();
  1345. l.addRule(r);
  1346. const u = l.diff(i.getRules(e, t)), d = i.getValidator(r.type), c = {
  1347. unitId: e,
  1348. subUnitId: t,
  1349. rule: {
  1350. ...r,
  1351. ...d == null ? void 0 : d.normalizeFormula(r, e, t)
  1352. }
  1353. }, { redoMutations: m, undoMutations: _ } = be(e, t, u, s);
  1354. return m.push({
  1355. id: L.id,
  1356. params: c
  1357. }), _.unshift({
  1358. id: A.id,
  1359. params: {
  1360. unitId: e,
  1361. subUnitId: t,
  1362. ruleId: r.uid
  1363. }
  1364. }), n.pushUndoRedo({
  1365. unitID: e,
  1366. redoMutations: m,
  1367. undoMutations: _
  1368. }), Ie(m, o), !0;
  1369. }
  1370. }, Sa = {
  1371. type: z.COMMAND,
  1372. id: "sheets.command.update-data-validation-setting",
  1373. // eslint-disable-next-line max-lines-per-function
  1374. handler(s, a) {
  1375. if (!a)
  1376. return !1;
  1377. 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);
  1378. if (!d)
  1379. return !1;
  1380. const c = r.getRuleById(o, n, l);
  1381. if (!c)
  1382. return !1;
  1383. const m = { ...c, ...u };
  1384. if (!d.validatorFormula(m, o, n).success)
  1385. return !1;
  1386. const _ = {
  1387. unitId: o,
  1388. subUnitId: n,
  1389. ruleId: l,
  1390. payload: {
  1391. type: y.SETTING,
  1392. payload: {
  1393. ...u,
  1394. ...d.normalizeFormula(m, o, n)
  1395. }
  1396. }
  1397. }, g = [{
  1398. id: E.id,
  1399. params: _
  1400. }], R = {
  1401. unitId: o,
  1402. subUnitId: n,
  1403. ruleId: l,
  1404. payload: {
  1405. type: y.SETTING,
  1406. payload: bt(c)
  1407. }
  1408. }, M = [{
  1409. id: E.id,
  1410. params: R
  1411. }];
  1412. if (u.type === T.CHECKBOX) {
  1413. const w = c.ranges, H = s.get(O), B = Ye(H, { unitId: o, subUnitId: n });
  1414. if (B) {
  1415. const W = new ve(), { worksheet: U } = B, { formula2: J = Me, formula1: ce = Ve } = c, { formula2: he = Me, formula1: me = Ve } = u;
  1416. let Le = !1;
  1417. if (w.forEach((fe) => {
  1418. b.foreach(fe, (ae, xe) => {
  1419. const j = U.getCellRaw(ae, xe), Ke = ct(j);
  1420. (ft(j) || Ke === String(J)) && !(j != null && j.p) ? (W.setValue(ae, xe, {
  1421. v: he,
  1422. p: null
  1423. }), Le = !0) : Ke === String(ce) && !(j != null && j.p) && (W.setValue(ae, xe, {
  1424. v: me,
  1425. p: null
  1426. }), Le = !0);
  1427. });
  1428. }), Le) {
  1429. const fe = {
  1430. id: oe.id,
  1431. params: {
  1432. unitId: o,
  1433. subUnitId: n,
  1434. cellValue: W.getData()
  1435. }
  1436. }, ae = {
  1437. id: oe.id,
  1438. params: st(s, fe.params)
  1439. };
  1440. g.push(fe), M.push(ae);
  1441. }
  1442. }
  1443. }
  1444. return Ie(g, e).result ? (t.pushUndoRedo({
  1445. unitID: o,
  1446. redoMutations: g,
  1447. undoMutations: M
  1448. }), !0) : !1;
  1449. }
  1450. }, va = {
  1451. type: z.COMMAND,
  1452. id: "sheets.command.update-data-validation-options",
  1453. handler(s, a) {
  1454. if (!a)
  1455. return !1;
  1456. 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);
  1457. if (!u)
  1458. return !1;
  1459. const d = {
  1460. unitId: i,
  1461. subUnitId: o,
  1462. ruleId: n,
  1463. payload: {
  1464. type: y.OPTIONS,
  1465. payload: l
  1466. }
  1467. }, c = [{
  1468. id: E.id,
  1469. params: d
  1470. }], m = {
  1471. unitId: i,
  1472. subUnitId: o,
  1473. ruleId: n,
  1474. payload: {
  1475. type: y.OPTIONS,
  1476. payload: Lt(u)
  1477. }
  1478. }, _ = [{
  1479. id: E.id,
  1480. params: m
  1481. }];
  1482. return t.pushUndoRedo({
  1483. unitID: i,
  1484. redoMutations: c,
  1485. undoMutations: _
  1486. }), e.executeCommand(E.id, d), !0;
  1487. }
  1488. }, Va = {
  1489. type: z.COMMAND,
  1490. id: "sheets.command.clear-range-data-validation",
  1491. handler(s, a) {
  1492. if (!a)
  1493. return !1;
  1494. 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);
  1495. if (!n) return !1;
  1496. const u = s.get(Z), d = l.getRuleObjectMatrix(e, t).clone();
  1497. d.removeRange(r);
  1498. const c = d.diff(l.getRules(e, t)), { redoMutations: m, undoMutations: _ } = be(e, t, c, s);
  1499. return u.pushUndoRedo({
  1500. unitID: e,
  1501. redoMutations: m,
  1502. undoMutations: _
  1503. }), Ie(m, i).result;
  1504. }
  1505. }, Ma = {
  1506. type: z.COMMAND,
  1507. id: "sheet.command.remove-all-data-validation",
  1508. handler(s, a) {
  1509. if (!a)
  1510. return !1;
  1511. const { unitId: e, subUnitId: t } = a, r = s.get(x), i = s.get(F), o = s.get(Z), n = [...i.getRules(e, t)], l = {
  1512. unitId: e,
  1513. subUnitId: t,
  1514. ruleId: n.map((c) => c.uid)
  1515. }, u = [{
  1516. id: A.id,
  1517. params: l
  1518. }], d = [{
  1519. id: L.id,
  1520. params: {
  1521. unitId: e,
  1522. subUnitId: t,
  1523. rule: n
  1524. }
  1525. }];
  1526. return o.pushUndoRedo({
  1527. redoMutations: u,
  1528. undoMutations: d,
  1529. unitID: e
  1530. }), r.executeCommand(A.id, l), !0;
  1531. }
  1532. }, ya = (s, a) => {
  1533. const e = s.get(F), { unitId: t, subUnitId: r, ruleId: i, source: o } = a;
  1534. if (Array.isArray(i)) {
  1535. const l = i.map((u) => e.getRuleById(t, r, u)).filter(Boolean);
  1536. return [{
  1537. id: L.id,
  1538. params: {
  1539. unitId: t,
  1540. subUnitId: r,
  1541. rule: l,
  1542. source: o
  1543. }
  1544. }];
  1545. }
  1546. return [{
  1547. id: L.id,
  1548. params: {
  1549. unitId: t,
  1550. subUnitId: r,
  1551. rule: {
  1552. ...e.getRuleById(t, r, i)
  1553. },
  1554. index: e.getRuleIndex(t, r, i)
  1555. }
  1556. }];
  1557. }, Ea = {
  1558. type: z.COMMAND,
  1559. id: "sheet.command.remove-data-validation-rule",
  1560. handler(s, a) {
  1561. if (!a)
  1562. return !1;
  1563. const { unitId: e, subUnitId: t, ruleId: r } = a, i = s.get(x), o = s.get(Z), n = s.get(F), l = [{
  1564. id: A.id,
  1565. params: a
  1566. }], u = [{
  1567. id: L.id,
  1568. params: {
  1569. unitId: e,
  1570. subUnitId: t,
  1571. rule: {
  1572. ...n.getRuleById(e, t, r)
  1573. },
  1574. index: n.getRuleIndex(e, t, r)
  1575. }
  1576. }];
  1577. return o.pushUndoRedo({
  1578. undoMutations: u,
  1579. redoMutations: l,
  1580. unitID: a.unitId
  1581. }), i.executeCommand(A.id, a), !0;
  1582. }
  1583. }, Ta = "sheets-data-validation.config", tt = {};
  1584. var Fa = Object.defineProperty, Na = Object.getOwnPropertyDescriptor, Ca = (s, a, e, t) => {
  1585. for (var r = t > 1 ? void 0 : t ? Na(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  1586. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  1587. return t && r && Fa(a, e, r), r;
  1588. }, $e = (s, a) => (e, t) => a(e, t, s);
  1589. let Ee = class extends $ {
  1590. constructor(a, e, t) {
  1591. super();
  1592. f(this, "_disposableMap", /* @__PURE__ */ new Map());
  1593. f(this, "registerRule", (a, e, t) => {
  1594. de(t.type, this._validatorRegistryService) && this.register(a, e, t);
  1595. });
  1596. this._dataValidationModel = a, this._formulaRefRangeService = e, this._validatorRegistryService = t, this._initRefRange();
  1597. }
  1598. _getIdWithUnitId(a, e, t) {
  1599. return `${a}_${e}_${t}`;
  1600. }
  1601. // eslint-disable-next-line max-lines-per-function
  1602. register(a, e, t) {
  1603. const r = t.ranges, i = t.formula1, o = t.formula2, n = this._formulaRefRangeService.registerRangeFormula(a, e, r, [i != null ? i : "", o != null ? o : ""], (u) => {
  1604. if (u.length === 0)
  1605. return {
  1606. undos: [{
  1607. id: L.id,
  1608. params: {
  1609. unitId: a,
  1610. subUnitId: e,
  1611. rule: t,
  1612. source: "patched"
  1613. }
  1614. }],
  1615. redos: [{
  1616. id: A.id,
  1617. params: {
  1618. unitId: a,
  1619. subUnitId: e,
  1620. ruleId: t.uid,
  1621. source: "patched"
  1622. }
  1623. }]
  1624. };
  1625. const d = [], c = [], m = u[0];
  1626. d.push({
  1627. id: E.id,
  1628. params: {
  1629. unitId: a,
  1630. subUnitId: e,
  1631. ruleId: t.uid,
  1632. payload: {
  1633. type: y.ALL,
  1634. payload: {
  1635. ranges: m.ranges,
  1636. formula1: m.formulas[0],
  1637. formula2: m.formulas[1]
  1638. }
  1639. },
  1640. source: "patched"
  1641. }
  1642. }), c.push({
  1643. id: E.id,
  1644. params: {
  1645. unitId: a,
  1646. subUnitId: e,
  1647. ruleId: t.uid,
  1648. payload: {
  1649. type: y.ALL,
  1650. payload: {
  1651. ranges: r,
  1652. formula1: i,
  1653. formula2: o
  1654. }
  1655. },
  1656. source: "patched"
  1657. }
  1658. });
  1659. for (let _ = 1; _ < u.length; _++) {
  1660. const g = u[_], R = yt();
  1661. d.push({
  1662. id: L.id,
  1663. params: {
  1664. unitId: a,
  1665. subUnitId: e,
  1666. rule: {
  1667. ...t,
  1668. uid: R,
  1669. formula1: g.formulas[0],
  1670. formula2: g.formulas[1],
  1671. ranges: g.ranges
  1672. },
  1673. source: "patched"
  1674. }
  1675. }), c.push({
  1676. id: A.id,
  1677. params: {
  1678. unitId: a,
  1679. subUnitId: e,
  1680. ruleId: R,
  1681. source: "patched"
  1682. }
  1683. });
  1684. }
  1685. return {
  1686. undos: c,
  1687. redos: d
  1688. };
  1689. }), l = this._getIdWithUnitId(a, e, t.uid);
  1690. this._disposableMap.set(l, n);
  1691. }
  1692. _initRefRange() {
  1693. const a = this._dataValidationModel.getAll();
  1694. for (const [e, t] of a)
  1695. for (const [r, i] of t)
  1696. for (const o of i)
  1697. this.registerRule(e, r, o);
  1698. this.disposeWithMe(
  1699. this._dataValidationModel.ruleChange$.subscribe((e) => {
  1700. const { unitId: t, subUnitId: r, rule: i } = e;
  1701. switch (e.type) {
  1702. case "add": {
  1703. const o = e.rule;
  1704. this.registerRule(e.unitId, e.subUnitId, o);
  1705. break;
  1706. }
  1707. case "remove": {
  1708. const o = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
  1709. o && o.dispose();
  1710. break;
  1711. }
  1712. case "update": {
  1713. const o = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, o.uid));
  1714. n && n.dispose(), this.registerRule(e.unitId, e.subUnitId, o);
  1715. break;
  1716. }
  1717. }
  1718. })
  1719. ), this.disposeWithMe(qe(() => {
  1720. this._disposableMap.forEach((e) => {
  1721. e.dispose();
  1722. }), this._disposableMap.clear();
  1723. }));
  1724. }
  1725. };
  1726. Ee = Ca([
  1727. $e(0, S(F)),
  1728. $e(1, S(ut)),
  1729. $e(2, S(G))
  1730. ], Ee);
  1731. 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) => {
  1732. for (var r = t > 1 ? void 0 : t ? wa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  1733. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  1734. return t && r && Oa(a, e, r), r;
  1735. }, He = (s, a) => (e, t) => a(e, t, s);
  1736. let Te = class extends $ {
  1737. constructor(s, a, e) {
  1738. super(), this._univerInstanceService = s, this._permissionService = a, this._lexerTreeBuilder = e;
  1739. }
  1740. getFormulaRefCheck(s) {
  1741. var e, t;
  1742. const a = this._lexerTreeBuilder.sequenceNodesBuilder(s);
  1743. if (!a)
  1744. return !0;
  1745. for (let r = 0; r < a.length; r++) {
  1746. const i = a[r];
  1747. if (typeof i == "string")
  1748. continue;
  1749. const { token: o } = i, n = Gt(o), l = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET);
  1750. let u = l.getActiveSheet();
  1751. const d = l.getUnitId();
  1752. if (n.sheetName) {
  1753. if (u = l.getSheetBySheetName(n.sheetName), !u)
  1754. return !1;
  1755. const R = u == null ? void 0 : u.getSheetId();
  1756. if (!this._permissionService.getPermissionPoint(new Bt(d, R).id)) return !1;
  1757. }
  1758. if (!u)
  1759. return !1;
  1760. const { startRow: c, endRow: m, startColumn: _, endColumn: g } = n.range;
  1761. for (let R = c; R <= m; R++)
  1762. for (let M = _; M <= g; M++) {
  1763. const p = (t = (e = u.getCell(R, M)) == null ? void 0 : e.selectionProtection) == null ? void 0 : t[0];
  1764. if ((p == null ? void 0 : p[gt.View]) === !1)
  1765. return !1;
  1766. }
  1767. }
  1768. return !0;
  1769. }
  1770. };
  1771. Te = Ia([
  1772. He(0, O),
  1773. He(1, Et),
  1774. He(2, S(Y))
  1775. ], Te);
  1776. var Aa = Object.defineProperty, Da = Object.getOwnPropertyDescriptor, ba = (s, a, e, t) => {
  1777. for (var r = t > 1 ? void 0 : t ? Da(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  1778. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  1779. return t && r && Aa(a, e, r), r;
  1780. }, ee = (s, a) => (e, t) => a(e, t, s);
  1781. let Fe = class extends $ {
  1782. constructor(a, e, t, r, i, o) {
  1783. super();
  1784. f(this, "_disposableMap", /* @__PURE__ */ new Map());
  1785. f(this, "registerRule", (a, e, t) => {
  1786. de(t.type, this._validatorRegistryService) || (this.register(a, e, t), this.registerFormula(a, e, t));
  1787. });
  1788. this._dataValidationModel = a, this._injector = e, this._refRangeService = t, this._dataValidationFormulaService = r, this._formulaRefRangeService = i, this._validatorRegistryService = o, this._initRefRange();
  1789. }
  1790. _getIdWithUnitId(a, e, t) {
  1791. return `${a}_${e}_${t}`;
  1792. }
  1793. // eslint-disable-next-line max-lines-per-function
  1794. registerFormula(a, e, t) {
  1795. var u;
  1796. const r = t.uid, i = this._getIdWithUnitId(a, e, r), o = (u = this._disposableMap.get(i)) != null ? u : /* @__PURE__ */ new Set(), n = (d, c) => {
  1797. const m = this._dataValidationModel.getRuleById(a, e, r);
  1798. if (!m)
  1799. return { redos: [], undos: [] };
  1800. const _ = m[d];
  1801. if (!_ || _ === c)
  1802. return { redos: [], undos: [] };
  1803. const g = {
  1804. unitId: a,
  1805. subUnitId: e,
  1806. ruleId: t.uid,
  1807. payload: {
  1808. type: y.SETTING,
  1809. payload: {
  1810. type: m.type,
  1811. formula1: m.formula1,
  1812. formula2: m.formula2,
  1813. [d]: c
  1814. }
  1815. },
  1816. source: "patched"
  1817. }, R = {
  1818. unitId: a,
  1819. subUnitId: e,
  1820. ruleId: t.uid,
  1821. payload: {
  1822. type: y.SETTING,
  1823. payload: {
  1824. type: m.type,
  1825. formula1: m.formula1,
  1826. formula2: m.formula2
  1827. }
  1828. },
  1829. source: "patched"
  1830. }, M = [
  1831. {
  1832. id: E.id,
  1833. params: g
  1834. }
  1835. ], p = [
  1836. {
  1837. id: E.id,
  1838. params: R
  1839. }
  1840. ];
  1841. return { redos: M, undos: p };
  1842. }, l = this._dataValidationFormulaService.getRuleFormulaInfo(a, e, r);
  1843. if (l) {
  1844. const [d, c] = l;
  1845. if (d) {
  1846. const m = this._formulaRefRangeService.registerFormula(
  1847. a,
  1848. e,
  1849. d.text,
  1850. (_) => n("formula1", _)
  1851. );
  1852. o.add(() => m.dispose());
  1853. }
  1854. if (c) {
  1855. const m = this._formulaRefRangeService.registerFormula(
  1856. a,
  1857. e,
  1858. c.text,
  1859. (_) => n("formula2", _)
  1860. );
  1861. o.add(() => m.dispose());
  1862. }
  1863. }
  1864. }
  1865. register(a, e, t) {
  1866. var l;
  1867. const r = (u) => {
  1868. const d = [...t.ranges], m = d.map((g) => Pt(g, u)).filter((g) => !!g).flat();
  1869. if (rt(m, d))
  1870. return { redos: [], undos: [] };
  1871. if (m.length) {
  1872. const g = {
  1873. unitId: a,
  1874. subUnitId: e,
  1875. ruleId: t.uid,
  1876. payload: {
  1877. type: y.RANGE,
  1878. payload: m
  1879. },
  1880. source: "patched"
  1881. }, R = [{ id: E.id, params: g }], M = [{
  1882. id: E.id,
  1883. params: {
  1884. unitId: a,
  1885. subUnitId: e,
  1886. ruleId: t.uid,
  1887. payload: {
  1888. type: y.RANGE,
  1889. payload: d
  1890. },
  1891. source: "patched"
  1892. }
  1893. }];
  1894. return { redos: R, undos: M };
  1895. } else {
  1896. const g = { unitId: a, subUnitId: e, ruleId: t.uid }, R = [{ id: A.id, params: g }], M = ya(this._injector, g);
  1897. return { redos: R, undos: M };
  1898. }
  1899. }, i = [];
  1900. t.ranges.forEach((u) => {
  1901. const d = this._refRangeService.registerRefRange(u, r, a, e);
  1902. i.push(() => d.dispose());
  1903. });
  1904. const o = this._getIdWithUnitId(a, e, t.uid), n = (l = this._disposableMap.get(o)) != null ? l : /* @__PURE__ */ new Set();
  1905. n.add(() => i.forEach((u) => u())), this._disposableMap.set(o, n);
  1906. }
  1907. _initRefRange() {
  1908. const a = this._dataValidationModel.getAll();
  1909. for (const [e, t] of a)
  1910. for (const [r, i] of t)
  1911. for (const o of i)
  1912. this.registerRule(e, r, o);
  1913. this.disposeWithMe(
  1914. this._dataValidationModel.ruleChange$.subscribe((e) => {
  1915. const { unitId: t, subUnitId: r, rule: i } = e;
  1916. switch (e.type) {
  1917. case "add": {
  1918. const o = e.rule;
  1919. this.registerRule(e.unitId, e.subUnitId, o);
  1920. break;
  1921. }
  1922. case "remove": {
  1923. const o = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
  1924. o && o.forEach((n) => n());
  1925. break;
  1926. }
  1927. case "update": {
  1928. const o = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, o.uid));
  1929. n && n.forEach((l) => l()), this.registerRule(e.unitId, e.subUnitId, o);
  1930. break;
  1931. }
  1932. }
  1933. })
  1934. ), this.disposeWithMe(qe(() => {
  1935. this._disposableMap.forEach((e) => {
  1936. e.forEach((t) => t());
  1937. }), this._disposableMap.clear();
  1938. }));
  1939. }
  1940. };
  1941. Fe = ba([
  1942. ee(0, S(F)),
  1943. ee(1, S(Ge)),
  1944. ee(2, S(Ut)),
  1945. ee(3, S(K)),
  1946. ee(4, S(ut)),
  1947. ee(5, S(G))
  1948. ], Fe);
  1949. var La = Object.defineProperty, xa = Object.getOwnPropertyDescriptor, Ba = (s, a, e, t) => {
  1950. for (var r = t > 1 ? void 0 : t ? xa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  1951. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  1952. return t && r && La(a, e, r), r;
  1953. }, We = (s, a) => (e, t) => a(e, t, s);
  1954. let Ne = class extends $ {
  1955. constructor(s, a, e) {
  1956. super(), this._sheetInterceptorService = s, this._univerInstanceService = a, this._sheetDataValidationModel = e, this._initSheetChange();
  1957. }
  1958. _initSheetChange() {
  1959. this.disposeWithMe(
  1960. this._sheetInterceptorService.interceptCommand({
  1961. getMutations: (s) => {
  1962. var a;
  1963. if (s.id === $t.id) {
  1964. const e = s.params, t = e.unitId || this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET).getUnitId(), r = this._univerInstanceService.getUniverSheetInstance(t);
  1965. if (!r)
  1966. return { redos: [], undos: [] };
  1967. const i = e.subUnitId || ((a = r.getActiveSheet()) == null ? void 0 : a.getSheetId());
  1968. if (!i)
  1969. return { redos: [], undos: [] };
  1970. const o = this._sheetDataValidationModel.getRules(t, i);
  1971. if (o.length === 0)
  1972. return { redos: [], undos: [] };
  1973. const n = o.map((d) => d.uid), l = {
  1974. unitId: t,
  1975. subUnitId: i,
  1976. ruleId: n,
  1977. source: "patched"
  1978. }, u = {
  1979. unitId: t,
  1980. subUnitId: i,
  1981. rule: [...o],
  1982. source: "patched"
  1983. };
  1984. return {
  1985. redos: [{
  1986. id: A.id,
  1987. params: l
  1988. }],
  1989. undos: [{
  1990. id: L.id,
  1991. params: u
  1992. }]
  1993. };
  1994. }
  1995. return { redos: [], undos: [] };
  1996. }
  1997. })
  1998. );
  1999. }
  2000. };
  2001. Ne = Ba([
  2002. We(0, S(ot)),
  2003. We(1, S(O)),
  2004. We(2, S(F))
  2005. ], Ne);
  2006. class Ua extends k {
  2007. constructor() {
  2008. super(...arguments);
  2009. f(this, "id", T.ANY);
  2010. f(this, "title", "dataValidation.any.title");
  2011. f(this, "operators", []);
  2012. f(this, "scopes", ["sheet"]);
  2013. f(this, "offsetFormulaByRange", !1);
  2014. }
  2015. async parseFormula(e, t, r) {
  2016. return {
  2017. formula1: e.formula1,
  2018. formula2: e.formula2,
  2019. isFormulaValid: !0
  2020. };
  2021. }
  2022. validatorFormula(e, t, r) {
  2023. return {
  2024. success: !0
  2025. };
  2026. }
  2027. async isValidType(e, t, r) {
  2028. return !0;
  2029. }
  2030. generateRuleErrorMessage(e) {
  2031. return this.localeService.t("dataValidation.any.error");
  2032. }
  2033. }
  2034. class Pa extends k {
  2035. constructor() {
  2036. super(...arguments);
  2037. f(this, "id", T.CUSTOM);
  2038. f(this, "title", "dataValidation.custom.title");
  2039. f(this, "operators", []);
  2040. f(this, "scopes", ["sheet"]);
  2041. f(this, "_customFormulaService", this.injector.get(P));
  2042. f(this, "_lexerTreeBuilder", this.injector.get(Y));
  2043. }
  2044. validatorFormula(e, t, r) {
  2045. var u;
  2046. const i = v(e.formula1), o = (u = e.formula1) != null ? u : "", l = this._lexerTreeBuilder.checkIfAddBracket(o) === 0 && o.startsWith(kt.EQUALS);
  2047. return {
  2048. success: i && l,
  2049. formula1: i && l ? "" : this.localeService.t("dataValidation.validFail.formula")
  2050. };
  2051. }
  2052. async parseFormula(e, t, r) {
  2053. return {
  2054. formula1: void 0,
  2055. formula2: void 0,
  2056. isFormulaValid: !0
  2057. };
  2058. }
  2059. async isValidType(e, t, r) {
  2060. 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;
  2061. 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;
  2062. }
  2063. generateRuleErrorMessage(e) {
  2064. return this.localeService.t("dataValidation.custom.error");
  2065. }
  2066. generateRuleName(e) {
  2067. var t;
  2068. return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (t = e.formula1) != null ? t : "");
  2069. }
  2070. }
  2071. class $a extends mt {
  2072. constructor() {
  2073. super(...arguments);
  2074. f(this, "id", T.LIST_MULTIPLE);
  2075. f(this, "title", "dataValidation.listMultiple.title");
  2076. f(this, "offsetFormulaByRange", !1);
  2077. f(this, "skipDefaultFontRender", () => !0);
  2078. }
  2079. }
  2080. class Ha extends k {
  2081. constructor() {
  2082. super(...arguments);
  2083. f(this, "_customFormulaService", this.injector.get(P));
  2084. f(this, "_lexerTreeBuilder", this.injector.get(Y));
  2085. f(this, "id", T.WHOLE);
  2086. f(this, "title", "dataValidation.whole.title");
  2087. f(this, "operators", [
  2088. h.BETWEEN,
  2089. h.EQUAL,
  2090. h.GREATER_THAN,
  2091. h.GREATER_THAN_OR_EQUAL,
  2092. h.LESS_THAN,
  2093. h.LESS_THAN_OR_EQUAL,
  2094. h.NOT_BETWEEN,
  2095. h.NOT_EQUAL
  2096. ]);
  2097. f(this, "scopes", ["sheet"]);
  2098. }
  2099. _isFormulaOrInt(e) {
  2100. return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) && Number.isInteger(+e));
  2101. }
  2102. async isValidType(e, t, r) {
  2103. const { value: i } = e, o = ye(i);
  2104. return !Number.isNaN(o) && Number.isInteger(o);
  2105. }
  2106. transform(e, t, r) {
  2107. const { value: i } = e;
  2108. return {
  2109. ...e,
  2110. value: ye(i)
  2111. };
  2112. }
  2113. _parseNumber(e) {
  2114. return e == null ? Number.NaN : +e;
  2115. }
  2116. async parseFormula(e, t, r, i, o) {
  2117. 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}`);
  2118. return {
  2119. formula1: this._parseNumber(c),
  2120. formula2: this._parseNumber(m),
  2121. isFormulaValid: _
  2122. };
  2123. }
  2124. validatorFormula(e, t, r) {
  2125. const i = e.operator;
  2126. if (!i)
  2127. return {
  2128. success: !1
  2129. };
  2130. 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");
  2131. return l ? {
  2132. success: o && n,
  2133. formula1: o ? void 0 : u,
  2134. formula2: n ? void 0 : u
  2135. } : {
  2136. success: o,
  2137. formula1: u
  2138. };
  2139. }
  2140. generateRuleErrorMessage(e, t) {
  2141. if (!e.operator)
  2142. return this.titleStr;
  2143. const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
  2144. return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
  2145. }
  2146. }
  2147. var Wa = Object.defineProperty, ja = Object.getOwnPropertyDescriptor, Qa = (s, a, e, t) => {
  2148. for (var r = t > 1 ? void 0 : t ? ja(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  2149. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  2150. return t && r && Wa(a, e, r), r;
  2151. }, te = (s, a) => (e, t) => a(e, t, s);
  2152. let Ce = class extends Ft {
  2153. constructor(s, a, e, t, r, i) {
  2154. super(), this._univerInstanceService = s, this._dataValidatorRegistryService = a, this._injector = e, this._selectionManagerService = t, this._sheetInterceptorService = r, this._sheetDataValidationModel = i, this._init();
  2155. }
  2156. _init() {
  2157. this._registerValidators(), this._initCommandInterceptor();
  2158. }
  2159. _registerValidators() {
  2160. [
  2161. Ua,
  2162. ha,
  2163. Ha,
  2164. _a,
  2165. ca,
  2166. na,
  2167. mt,
  2168. $a,
  2169. Pa
  2170. ].forEach((s) => {
  2171. const a = this._injector.createInstance(s);
  2172. this.disposeWithMe(this._dataValidatorRegistryService.register(a)), this.disposeWithMe(qe(() => this._injector.delete(s)));
  2173. });
  2174. }
  2175. _initCommandInterceptor() {
  2176. this._sheetInterceptorService.interceptCommand({
  2177. getMutations: (s) => {
  2178. var a;
  2179. if (s.id === Ht.id) {
  2180. const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e.getUnitId(), r = e.getActiveSheet();
  2181. if (!r)
  2182. throw new Error("No active sheet found");
  2183. const i = r.getSheetId(), o = (a = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : a.map((c) => c.range), n = this._sheetDataValidationModel.getRuleObjectMatrix(t, i).clone();
  2184. o && n.removeRange(o);
  2185. const l = n.diff(this._sheetDataValidationModel.getRules(t, i)), { redoMutations: u, undoMutations: d } = be(t, i, l, this._injector, "patched");
  2186. return {
  2187. undos: d,
  2188. redos: u
  2189. };
  2190. }
  2191. return {
  2192. undos: [],
  2193. redos: []
  2194. };
  2195. }
  2196. });
  2197. }
  2198. };
  2199. Ce = Qa([
  2200. te(0, O),
  2201. te(1, S(G)),
  2202. te(2, S(Ge)),
  2203. te(3, S(nt)),
  2204. te(4, S(ot)),
  2205. te(5, S(F))
  2206. ], Ce);
  2207. var qa = Object.defineProperty, Ga = Object.getOwnPropertyDescriptor, ka = (s, a, e, t) => {
  2208. for (var r = t > 1 ? void 0 : t ? Ga(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  2209. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  2210. return t && r && qa(a, e, r), r;
  2211. }, Re = (s, a) => (e, t) => a(e, t, s);
  2212. let Oe = class extends $ {
  2213. constructor(s, a, e, t) {
  2214. super(), this._univerInstanceService = s, this._sheetDataValidationModel = a, this._dataValidationCacheService = e, this._lifecycleService = t, this._initRecalculate();
  2215. }
  2216. _initRecalculate() {
  2217. const s = (a) => {
  2218. if (a.length === 0)
  2219. return;
  2220. const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e == null ? void 0 : e.getActiveSheet(), r = {};
  2221. a.flat().forEach((i) => {
  2222. r[i.unitId] || (r[i.unitId] = {}), r[i.unitId][i.subUnitId] || (r[i.unitId][i.subUnitId] = []);
  2223. const o = this._univerInstanceService.getUnit(i.unitId, N.UNIVER_SHEET), n = o == null ? void 0 : o.getSheetBySheetId(i.subUnitId);
  2224. n && r[i.unitId][i.subUnitId].push(...i.ranges.map((l) => b.transformRange(l, n)));
  2225. }), Object.entries(r).forEach(([i, o]) => {
  2226. Object.entries(o).forEach(([n, l]) => {
  2227. (e == null ? void 0 : e.getUnitId()) === i && (t == null ? void 0 : t.getSheetId()) === n ? this.validatorRanges(i, n, l) : requestIdleCallback(() => {
  2228. this.validatorRanges(i, n, l);
  2229. });
  2230. });
  2231. });
  2232. };
  2233. 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));
  2234. }
  2235. async _validatorByCell(s, a, e, t) {
  2236. const r = s.getUnitId(), i = a.getSheetId();
  2237. if (!V.isDefine(e) || !V.isDefine(t))
  2238. throw new Error(`row or col is not defined, row: ${e}, col: ${t}`);
  2239. const o = this._sheetDataValidationModel.getRuleByLocation(r, i, e, t);
  2240. return o ? new Promise((n) => {
  2241. this._sheetDataValidationModel.validator(o, { unitId: r, subUnitId: i, row: e, col: t, worksheet: a, workbook: s }, (l) => {
  2242. n(l);
  2243. });
  2244. }) : D.VALID;
  2245. }
  2246. async validatorCell(s, a, e, t) {
  2247. const r = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
  2248. if (!r)
  2249. throw new Error(`cannot find current workbook, unitId: ${s}`);
  2250. const i = r.getSheetBySheetId(a);
  2251. if (!i)
  2252. throw new Error(`cannot find current worksheet, sheetId: ${a}`);
  2253. return this._validatorByCell(r, i, e, t);
  2254. }
  2255. validatorRanges(s, a, e) {
  2256. if (!e.length)
  2257. return Promise.resolve([]);
  2258. const t = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
  2259. if (!t)
  2260. throw new Error(`cannot find current workbook, unitId: ${s}`);
  2261. const r = t.getSheetBySheetId(a);
  2262. if (!r)
  2263. throw new Error(`cannot find current worksheet, sheetId: ${a}`);
  2264. return Promise.all(e.map((i) => {
  2265. const o = [];
  2266. return b.foreach(i, (n, l) => {
  2267. o.push(this._validatorByCell(t, r, n, l));
  2268. }), Promise.all(o);
  2269. }));
  2270. }
  2271. async validatorWorksheet(s, a) {
  2272. const e = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
  2273. if (!e)
  2274. throw new Error(`cannot find current workbook, unitId: ${s}`);
  2275. const t = e.getSheetBySheetId(a);
  2276. if (!t)
  2277. throw new Error(`cannot find current worksheet, sheetId: ${a}`);
  2278. const r = this._sheetDataValidationModel.getRules(s, a);
  2279. return await Promise.all(r.map((i) => Promise.all(i.ranges.map((o) => {
  2280. const n = [];
  2281. return b.foreach(o, (l, u) => {
  2282. n.push(this._validatorByCell(e, t, l, u));
  2283. }), n;
  2284. })))), this._dataValidationCacheService.ensureCache(s, a);
  2285. }
  2286. async validatorWorkbook(s) {
  2287. const a = this._sheetDataValidationModel.getSubUnitIds(s), e = await Promise.all(a.map((r) => this.validatorWorksheet(s, r))), t = {};
  2288. return e.forEach((r, i) => {
  2289. t[a[i]] = r;
  2290. }), t;
  2291. }
  2292. getDataValidations(s, a, e) {
  2293. const t = this._sheetDataValidationModel.getRuleObjectMatrix(s, a), r = /* @__PURE__ */ new Set();
  2294. return e.forEach((o) => {
  2295. b.foreach(o, (n, l) => {
  2296. const u = t.getValue(n, l);
  2297. u && r.add(u);
  2298. });
  2299. }), Array.from(r).map((o) => this._sheetDataValidationModel.getRuleById(s, a, o)).filter(Boolean);
  2300. }
  2301. getDataValidation(s, a, e) {
  2302. return this.getDataValidations(s, a, e)[0];
  2303. }
  2304. };
  2305. Oe = ka([
  2306. Re(0, O),
  2307. Re(1, S(F)),
  2308. Re(2, S(q)),
  2309. Re(3, S(Nt))
  2310. ], Oe);
  2311. 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) => {
  2312. for (var r = t > 1 ? void 0 : t ? Ya(a, e) : a, i = s.length - 1, o; i >= 0; i--)
  2313. (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
  2314. return t && r && _t(a, e, r), r;
  2315. }, je = (s, a) => (e, t) => a(e, t, s), pt = (s, a, e) => Xa(s, typeof a != "symbol" ? a + "" : a, e);
  2316. let we = class extends wt {
  2317. constructor(s = tt, a, e, t) {
  2318. super(), this._config = s, this._injector = a, this._commandService = e, this._configService = t;
  2319. const { ...r } = It(
  2320. {},
  2321. tt,
  2322. this._config
  2323. );
  2324. this._configService.setConfig(Ta, r);
  2325. }
  2326. onStarting() {
  2327. [
  2328. [q],
  2329. [K],
  2330. [P],
  2331. [Oe],
  2332. [F],
  2333. [Ce],
  2334. [Te],
  2335. [Ne],
  2336. [Fe],
  2337. [Ee]
  2338. ].forEach((s) => {
  2339. this._injector.add(s);
  2340. }), [
  2341. Ra,
  2342. pa,
  2343. Sa,
  2344. va,
  2345. Ea,
  2346. Ma,
  2347. Va
  2348. ].forEach((s) => {
  2349. this._commandService.registerCommand(s);
  2350. }), this._injector.get(q), this._injector.get(Oe), this._injector.get(Ee), this._injector.get(Fe);
  2351. }
  2352. onReady() {
  2353. this._injector.get(Ne);
  2354. }
  2355. onRendered() {
  2356. this._injector.get(Ce), this._injector.get(Te);
  2357. }
  2358. };
  2359. pt(we, "pluginName", Yt);
  2360. pt(we, "type", N.UNIVER_SHEET);
  2361. we = Ka([
  2362. Ot(xt),
  2363. je(1, S(Ge)),
  2364. je(2, x),
  2365. je(3, At)
  2366. ], we);
  2367. function or(s) {
  2368. const e = s.get(nt).getCurrentSelections().map((i) => i.range);
  2369. return {
  2370. uid: V.generateRandomId(6),
  2371. type: T.DECIMAL,
  2372. operator: h.EQUAL,
  2373. formula1: "100",
  2374. ranges: e != null ? e : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
  2375. };
  2376. }
  2377. export {
  2378. Ra as AddSheetDataValidationCommand,
  2379. Ve as CHECKBOX_FORMULA_1,
  2380. Me as CHECKBOX_FORMULA_2,
  2381. na as CheckboxValidator,
  2382. Va as ClearRangeDataValidationCommand,
  2383. Yt as DATA_VALIDATION_PLUGIN_NAME,
  2384. q as DataValidationCacheService,
  2385. P as DataValidationCustomFormulaService,
  2386. Te as DataValidationFormulaController,
  2387. K as DataValidationFormulaService,
  2388. ca as DateValidator,
  2389. $a as ListMultipleValidator,
  2390. mt as ListValidator,
  2391. Ma as RemoveSheetAllDataValidationCommand,
  2392. Ea as RemoveSheetDataValidationCommand,
  2393. F as SheetDataValidationModel,
  2394. Oe as SheetsDataValidationValidatorService,
  2395. we as UniverSheetsDataValidationPlugin,
  2396. va as UpdateSheetDataValidationOptionsCommand,
  2397. pa as UpdateSheetDataValidationRangeCommand,
  2398. Sa as UpdateSheetDataValidationSettingCommand,
  2399. or as createDefaultNewRule,
  2400. pe as deserializeListOptions,
  2401. ne as getCellValueOrigin,
  2402. sr as getDataValidationCellValue,
  2403. be as getDataValidationDiffMutations,
  2404. ge as getFormulaCellData,
  2405. se as getFormulaResult,
  2406. C as isLegalFormulaResult,
  2407. ir as serializeListOptions,
  2408. _e as transformCheckboxValue
  2409. };