@univerjs/sheets-data-validation 0.6.7 → 0.6.9

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