@univerjs/sheets-data-validation 0.6.6 → 0.6.7-nightly.202503261607

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,2425 @@
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;
603
+ f === D.VALID ? _.realDeleteValue(i, r) : _.setValue(i, r, f);
604
+ const O = _.getValue(i, r);
605
+ u(f, R !== O);
606
+ }), D.VALIDATING) : (u(R != null ? R : D.VALID, !1), R != null ? R : D.VALID);
607
+ } else
608
+ return u(D.VALID, !1), D.VALID;
609
+ }
610
+ getRuleObjectMatrix(a, e) {
611
+ return this._ensureRuleMatrix(a, e);
612
+ }
613
+ getRuleById(a, e, t) {
614
+ return this._dataValidationModel.getRuleById(a, e, t);
615
+ }
616
+ getRuleIndex(a, e, t) {
617
+ return this._dataValidationModel.getRuleIndex(a, e, t);
618
+ }
619
+ getRules(a, e) {
620
+ return [...this._dataValidationModel.getRules(a, e)];
621
+ }
622
+ getUnitRules(a) {
623
+ return this._dataValidationModel.getUnitRules(a);
624
+ }
625
+ deleteUnitRules(a) {
626
+ return this._dataValidationModel.deleteUnitRules(a);
627
+ }
628
+ getSubUnitIds(a) {
629
+ return this._dataValidationModel.getSubUnitIds(a);
630
+ }
631
+ getAll() {
632
+ return this._dataValidationModel.getAll();
633
+ }
634
+ };
635
+ F = ta([
636
+ X(0, v(Ge)),
637
+ X(1, w),
638
+ X(2, v(q)),
639
+ X(3, v(Q)),
640
+ X(4, v(K)),
641
+ X(5, v(H)),
642
+ X(6, x)
643
+ ], F);
644
+ const Ve = 1, Me = 0;
645
+ function et(o, a) {
646
+ return V.isBlank(o) ? a.t("dataValidation.validFail.value") : S(o) ? a.t("dataValidation.validFail.primitive") : "";
647
+ }
648
+ const pe = (o) => V.isDefine(o) && String(o).toLowerCase() === "true" ? "1" : String(o).toLowerCase() === "false" ? "0" : o;
649
+ class aa extends G {
650
+ constructor() {
651
+ super(...arguments);
652
+ g(this, "id", T.CHECKBOX);
653
+ g(this, "title", "dataValidation.checkbox.title");
654
+ g(this, "operators", []);
655
+ g(this, "scopes", ["sheet"]);
656
+ g(this, "offsetFormulaByRange", !1);
657
+ g(this, "_formulaService", this.injector.get(K));
658
+ g(this, "skipDefaultFontRender", (e, t, r) => {
659
+ const { unitId: i, subUnitId: s } = r, { formula1: n, formula2: l } = this.parseFormulaSync(e, i, s), u = `${t != null ? t : ""}`;
660
+ return !u || u === `${n}` || u === `${l}`;
661
+ });
662
+ }
663
+ validatorFormula(e, t, r) {
664
+ const { formula1: i, formula2: s } = e, n = i === s;
665
+ if (V.isBlank(i) && V.isBlank(s))
666
+ return {
667
+ success: !0
668
+ };
669
+ if (n)
670
+ return {
671
+ success: !1,
672
+ formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
673
+ formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
674
+ };
675
+ const l = et(i, this.localeService), u = et(s, this.localeService);
676
+ return {
677
+ success: !l && !u,
678
+ formula1: l,
679
+ formula2: u
680
+ };
681
+ }
682
+ async parseFormula(e, t, r) {
683
+ var c, m, p, _;
684
+ 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));
685
+ return {
686
+ formula1: pe(l),
687
+ formula2: pe(u),
688
+ originFormula1: l,
689
+ originFormula2: u,
690
+ isFormulaValid: d
691
+ };
692
+ }
693
+ getExtraStyle(e, t) {
694
+ return {
695
+ tb: ve.CLIP
696
+ };
697
+ }
698
+ parseFormulaSync(e, t, r) {
699
+ var c, m, p, _;
700
+ 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));
701
+ return {
702
+ formula1: pe(l),
703
+ formula2: pe(u),
704
+ originFormula1: l,
705
+ originFormula2: u,
706
+ isFormulaValid: d
707
+ };
708
+ }
709
+ async isValidType(e, t, r) {
710
+ const { value: i, unitId: s, subUnitId: n } = e, { formula1: l, formula2: u, originFormula1: d, originFormula2: c } = await this.parseFormula(r, s, n);
711
+ 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 : ""));
712
+ }
713
+ generateRuleErrorMessage(e) {
714
+ return this.localeService.t("dataValidation.checkbox.error");
715
+ }
716
+ }
717
+ const ra = {
718
+ [h.BETWEEN]: "dataValidation.date.operators.between",
719
+ [h.EQUAL]: "dataValidation.date.operators.equal",
720
+ [h.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
721
+ [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
722
+ [h.LESS_THAN]: "dataValidation.date.operators.lessThan",
723
+ [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
724
+ [h.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
725
+ [h.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
726
+ };
727
+ 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 + "";
728
+ const ia = {
729
+ [h.BETWEEN]: "dataValidation.date.ruleName.between",
730
+ [h.EQUAL]: "dataValidation.date.ruleName.equal",
731
+ [h.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
732
+ [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
733
+ [h.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
734
+ [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
735
+ [h.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
736
+ [h.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
737
+ }, oa = {
738
+ [h.BETWEEN]: "dataValidation.date.errorMsg.between",
739
+ [h.EQUAL]: "dataValidation.date.errorMsg.equal",
740
+ [h.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
741
+ [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
742
+ [h.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
743
+ [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
744
+ [h.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
745
+ [h.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
746
+ }, Ae = [
747
+ h.BETWEEN,
748
+ h.NOT_BETWEEN
749
+ ], le = "{FORMULA1}", ue = "{FORMULA2}";
750
+ function Ya(o) {
751
+ return o.filter(Boolean).join(",");
752
+ }
753
+ function fe(o) {
754
+ return o.split(",").filter(Boolean);
755
+ }
756
+ function Xa(o) {
757
+ const a = ne(o);
758
+ return a == null ? "" : a.toString();
759
+ }
760
+ function De(o, a, e) {
761
+ 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;
762
+ return {
763
+ transformedFormula1: u,
764
+ transformedFormula2: d
765
+ };
766
+ }
767
+ const Ue = (o) => {
768
+ var e, t;
769
+ if (o == null || typeof o == "boolean")
770
+ return;
771
+ if (typeof o == "number" || !Number.isNaN(+o))
772
+ return +o;
773
+ const a = (e = j.parseDate(o)) == null ? void 0 : e.v;
774
+ return V.isDefine(a) ? a : (t = j.parseDate(at(o).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : t.v;
775
+ };
776
+ class sa extends G {
777
+ constructor() {
778
+ super(...arguments);
779
+ g(this, "id", T.DATE);
780
+ g(this, "title", "dataValidation.date.title");
781
+ g(this, "operators", [
782
+ h.BETWEEN,
783
+ h.EQUAL,
784
+ h.GREATER_THAN,
785
+ h.GREATER_THAN_OR_EQUAL,
786
+ h.LESS_THAN,
787
+ h.LESS_THAN_OR_EQUAL,
788
+ h.NOT_BETWEEN,
789
+ h.NOT_EQUAL
790
+ ]);
791
+ g(this, "scopes", ["sheet"]);
792
+ g(this, "_customFormulaService", this.injector.get(H));
793
+ g(this, "_lexerTreeBuilder", this.injector.get(Y));
794
+ }
795
+ async parseFormula(e, t, r, i, s) {
796
+ 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));
797
+ return {
798
+ formula1: Ue(S(u) ? n == null ? void 0 : n.v : u),
799
+ formula2: Ue(S(d) ? l == null ? void 0 : l.v : d),
800
+ isFormulaValid: c
801
+ };
802
+ }
803
+ async isValidType(e) {
804
+ const { interceptValue: t, value: r } = e;
805
+ return typeof r == "number" && typeof t == "string" ? !0 : typeof t == "string" ? !!j.parseDate(t) : !1;
806
+ }
807
+ _validatorSingleFormula(e) {
808
+ return !V.isBlank(e) && (S(e) || !Number.isNaN(+e) || !!(e && j.parseDate(e)));
809
+ }
810
+ validatorFormula(e, t, r) {
811
+ const i = e.operator;
812
+ if (!i)
813
+ return {
814
+ success: !1
815
+ };
816
+ const s = this._validatorSingleFormula(e.formula1), n = this.localeService.t("dataValidation.validFail.date");
817
+ if (Ae.includes(i)) {
818
+ const u = this._validatorSingleFormula(e.formula2);
819
+ return {
820
+ success: s && u,
821
+ formula1: s ? void 0 : n,
822
+ formula2: u ? void 0 : n
823
+ };
824
+ }
825
+ return {
826
+ success: s,
827
+ formula1: s ? void 0 : n
828
+ };
829
+ }
830
+ normalizeFormula(e, t, r) {
831
+ const { formula1: i, formula2: s, bizInfo: n } = e, l = (u) => {
832
+ var c;
833
+ if (!u)
834
+ return u;
835
+ let d;
836
+ if (!Number.isNaN(+u))
837
+ d = j.dateFromSerial(+u);
838
+ else {
839
+ const m = (c = j.parseDate(u)) == null ? void 0 : c.v;
840
+ if (m == null)
841
+ return "";
842
+ d = j.dateFromSerial(m);
843
+ }
844
+ 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");
845
+ };
846
+ return {
847
+ formula1: S(i) ? i : l(`${i}`),
848
+ formula2: S(s) ? s : l(`${s}`)
849
+ };
850
+ }
851
+ transform(e, t, r) {
852
+ const { value: i } = e;
853
+ return {
854
+ ...e,
855
+ value: Ue(i)
856
+ };
857
+ }
858
+ get operatorNames() {
859
+ return this.operators.map((e) => this.localeService.t(ra[e]));
860
+ }
861
+ generateRuleName(e) {
862
+ var r, i;
863
+ if (!e.operator)
864
+ return this.titleStr;
865
+ const t = this.localeService.t(ia[e.operator]).replace(le, (r = e.formula1) != null ? r : "").replace(ue, (i = e.formula2) != null ? i : "");
866
+ return `${this.titleStr} ${t}`;
867
+ }
868
+ generateRuleErrorMessage(e, t) {
869
+ if (!e.operator)
870
+ return this.titleStr;
871
+ const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
872
+ return `${this.localeService.t(oa[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
873
+ }
874
+ }
875
+ 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 + "";
876
+ 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 + "";
877
+ const ht = {
878
+ [h.BETWEEN]: "dataValidation.errorMsg.between",
879
+ [h.EQUAL]: "dataValidation.errorMsg.equal",
880
+ [h.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
881
+ [h.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
882
+ [h.LESS_THAN]: "dataValidation.errorMsg.lessThan",
883
+ [h.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
884
+ [h.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
885
+ [h.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
886
+ };
887
+ function ye(o) {
888
+ let a = o;
889
+ return typeof o == "string" ? ((o.startsWith("¥") || o.startsWith("$")) && (a = o.slice(1)), +a) : +o;
890
+ }
891
+ class na extends G {
892
+ constructor() {
893
+ super(...arguments);
894
+ g(this, "_customFormulaService", this.injector.get(H));
895
+ g(this, "id", T.DECIMAL);
896
+ g(this, "_lexerTreeBuilder", this.injector.get(Y));
897
+ g(this, "title", "dataValidation.decimal.title");
898
+ g(this, "operators", [
899
+ h.BETWEEN,
900
+ h.EQUAL,
901
+ h.GREATER_THAN,
902
+ h.GREATER_THAN_OR_EQUAL,
903
+ h.LESS_THAN,
904
+ h.LESS_THAN_OR_EQUAL,
905
+ h.NOT_BETWEEN,
906
+ h.NOT_EQUAL
907
+ ]);
908
+ g(this, "scopes", ["sheet"]);
909
+ }
910
+ _isFormulaOrNumber(e) {
911
+ return !V.isBlank(e) && (S(e) || !Number.isNaN(+e));
912
+ }
913
+ async isValidType(e, t, r) {
914
+ const { value: i } = e;
915
+ return !Number.isNaN(ye(i));
916
+ }
917
+ transform(e, t, r) {
918
+ const { value: i } = e;
919
+ return {
920
+ ...e,
921
+ value: ye(i)
922
+ };
923
+ }
924
+ _parseNumber(e) {
925
+ return e == null ? Number.NaN : +e;
926
+ }
927
+ async parseFormula(e, t, r, i, s) {
928
+ 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));
929
+ return {
930
+ formula1: this._parseNumber(S(u) ? n == null ? void 0 : n.v : u),
931
+ formula2: this._parseNumber(S(d) ? l == null ? void 0 : l.v : d),
932
+ isFormulaValid: c
933
+ };
934
+ }
935
+ validatorFormula(e, t, r) {
936
+ const i = e.operator;
937
+ if (!i)
938
+ return {
939
+ success: !1
940
+ };
941
+ 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");
942
+ return l ? {
943
+ success: s && n,
944
+ formula1: s ? void 0 : u,
945
+ formula2: n ? void 0 : u
946
+ } : {
947
+ success: s,
948
+ formula1: s ? "" : u
949
+ };
950
+ }
951
+ generateRuleErrorMessage(e, t) {
952
+ if (!e.operator)
953
+ return this.titleStr;
954
+ const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
955
+ return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
956
+ }
957
+ }
958
+ function He(o) {
959
+ if (!o)
960
+ return [];
961
+ const a = /* @__PURE__ */ new Set();
962
+ return o.forEach(
963
+ (e) => {
964
+ e.forEach((t) => {
965
+ var i, s;
966
+ const r = ne(t);
967
+ if (r != null) {
968
+ if (typeof r != "string" && typeof (t == null ? void 0 : t.s) == "object" && ((s = (i = t.s) == null ? void 0 : i.n) != null && s.pattern)) {
969
+ a.add(j.format(t.s.n.pattern, r, { throws: !1 }));
970
+ return;
971
+ }
972
+ C(r.toString()) && a.add(r.toString());
973
+ }
974
+ });
975
+ }
976
+ ), [...a];
977
+ }
978
+ const la = [
979
+ "if",
980
+ "indirect",
981
+ "choose",
982
+ "offset"
983
+ ];
984
+ function ua(o, a) {
985
+ if (!S(o) || dt(o.slice(1)))
986
+ return !0;
987
+ const t = a.sequenceNodesBuilder(o);
988
+ return t && t.some((r) => typeof r == "object" && r.nodeType === kt.FUNCTION && la.indexOf(r.token.toLowerCase()) > -1);
989
+ }
990
+ function da(o, a) {
991
+ const { formula1: e = "", ranges: t } = o;
992
+ if (dt(e.slice(1))) {
993
+ const i = jt(e.slice(1));
994
+ if ((!i.sheetName || i.sheetName === a) && t.some((s) => I.intersects(s, i.range)))
995
+ return !0;
996
+ }
997
+ return !1;
998
+ }
999
+ class mt extends G {
1000
+ constructor() {
1001
+ super(...arguments);
1002
+ g(this, "formulaService", this.injector.get(K));
1003
+ g(this, "_lexer", this.injector.get(Y));
1004
+ g(this, "_univerInstanceService", this.injector.get(w));
1005
+ g(this, "offsetFormulaByRange", !1);
1006
+ g(this, "id", T.LIST);
1007
+ g(this, "title", "dataValidation.list.title");
1008
+ g(this, "operators", []);
1009
+ g(this, "scopes", ["sheet"]);
1010
+ g(this, "skipDefaultFontRender", (e) => e.renderMode !== Be.TEXT);
1011
+ }
1012
+ validatorFormula(e, t, r) {
1013
+ var u, d, c;
1014
+ 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 : "");
1015
+ return {
1016
+ success: !!(i && s && !l),
1017
+ formula1: i ? s ? l ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
1018
+ };
1019
+ }
1020
+ getExtraStyle(e, t, { style: r }) {
1021
+ var s;
1022
+ const i = (s = r.tb !== ve.OVERFLOW ? r.tb : ve.CLIP) != null ? s : ve.WRAP;
1023
+ if (e.type === T.LIST && (e.renderMode === Be.ARROW || e.renderMode === Be.TEXT)) {
1024
+ const n = this.getListWithColorMap(e), l = `${t != null ? t : ""}`, u = n[l];
1025
+ if (u)
1026
+ return {
1027
+ bg: {
1028
+ rgb: u
1029
+ },
1030
+ tb: i
1031
+ };
1032
+ }
1033
+ return {
1034
+ tb: i
1035
+ };
1036
+ }
1037
+ parseCellValue(e) {
1038
+ const t = e.toString();
1039
+ return fe(t);
1040
+ }
1041
+ async parseFormula(e, t, r) {
1042
+ var l, u;
1043
+ 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]);
1044
+ return {
1045
+ formula1: void 0,
1046
+ formula2: void 0,
1047
+ isFormulaValid: C(String(s))
1048
+ };
1049
+ }
1050
+ async isValidType(e, t, r) {
1051
+ var m, p;
1052
+ 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);
1053
+ return this.parseCellValue(i).every((_) => d.includes(_));
1054
+ }
1055
+ generateRuleName() {
1056
+ return this.localeService.t("dataValidation.list.name");
1057
+ }
1058
+ generateRuleErrorMessage() {
1059
+ return this.localeService.t("dataValidation.list.error");
1060
+ }
1061
+ getList(e, t, r) {
1062
+ var m, p, _, R;
1063
+ const { formula1: i = "" } = e, s = this.injector.get(w), n = (m = t ? s.getUniverSheetInstance(t) : void 0) != null ? m : s.getCurrentUnitForType(N.UNIVER_SHEET);
1064
+ if (!n) return [];
1065
+ const l = (p = r ? n.getSheetBySheetId(r) : void 0) != null ? p : n.getActiveSheet();
1066
+ if (!l) return [];
1067
+ const u = n.getUnitId(), d = l.getSheetId(), c = this.formulaService.getRuleFormulaResultSync(u, d, e.uid);
1068
+ return S(i) ? He((R = (_ = c == null ? void 0 : c[0]) == null ? void 0 : _.result) == null ? void 0 : R[0][0]) : fe(i);
1069
+ }
1070
+ async getListAsync(e, t, r) {
1071
+ var m, p, _, R;
1072
+ const { formula1: i = "" } = e, s = this.injector.get(w), n = (m = t ? s.getUniverSheetInstance(t) : void 0) != null ? m : s.getCurrentUnitForType(N.UNIVER_SHEET);
1073
+ if (!n) return [];
1074
+ const l = (p = r ? n.getSheetBySheetId(r) : void 0) != null ? p : n.getActiveSheet();
1075
+ if (!l) return [];
1076
+ const u = n.getUnitId(), d = l.getSheetId(), c = await this.formulaService.getRuleFormulaResult(u, d, e.uid);
1077
+ return S(i) ? He((R = (_ = c == null ? void 0 : c[0]) == null ? void 0 : _.result) == null ? void 0 : R[0][0]) : fe(i);
1078
+ }
1079
+ getListWithColor(e, t, r) {
1080
+ const i = this.getList(e, t, r), s = (e.formula2 || "").split(",");
1081
+ return i.map((n, l) => ({ label: n, color: s[l] }));
1082
+ }
1083
+ getListWithColorMap(e, t, r) {
1084
+ const i = this.getListWithColor(e, t, r), s = {};
1085
+ return i.forEach((n) => {
1086
+ n.color && (s[n.label] = n.color);
1087
+ }), s;
1088
+ }
1089
+ }
1090
+ class ca extends G {
1091
+ constructor() {
1092
+ super(...arguments);
1093
+ g(this, "id", T.TEXT_LENGTH);
1094
+ g(this, "title", "dataValidation.textLength.title");
1095
+ g(this, "_lexerTreeBuilder", this.injector.get(Y));
1096
+ g(this, "operators", [
1097
+ h.BETWEEN,
1098
+ h.EQUAL,
1099
+ h.GREATER_THAN,
1100
+ h.GREATER_THAN_OR_EQUAL,
1101
+ h.LESS_THAN,
1102
+ h.LESS_THAN_OR_EQUAL,
1103
+ h.NOT_BETWEEN,
1104
+ h.NOT_EQUAL
1105
+ ]);
1106
+ g(this, "scopes", ["sheet"]);
1107
+ g(this, "_customFormulaService", this.injector.get(H));
1108
+ }
1109
+ _isFormulaOrInt(e) {
1110
+ return !V.isBlank(e) && (S(e) || !Number.isNaN(+e) && Number.isInteger(+e));
1111
+ }
1112
+ validatorFormula(e, t, r) {
1113
+ const i = e.operator;
1114
+ if (!i)
1115
+ return {
1116
+ success: !1
1117
+ };
1118
+ 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");
1119
+ return l ? {
1120
+ success: s && n,
1121
+ formula1: s ? void 0 : u,
1122
+ formula2: n ? void 0 : u
1123
+ } : {
1124
+ success: s,
1125
+ formula1: u
1126
+ };
1127
+ }
1128
+ _parseNumber(e) {
1129
+ return e == null ? Number.NaN : +e;
1130
+ }
1131
+ async parseFormula(e, t, r, i, s) {
1132
+ 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));
1133
+ return {
1134
+ formula1: this._parseNumber(S(u) ? n == null ? void 0 : n.v : u),
1135
+ formula2: this._parseNumber(S(d) ? l == null ? void 0 : l.v : d),
1136
+ isFormulaValid: c
1137
+ };
1138
+ }
1139
+ transform(e, t, r) {
1140
+ return {
1141
+ ...e,
1142
+ value: e.value.toString().length
1143
+ };
1144
+ }
1145
+ async isValidType(e, t, r) {
1146
+ const { value: i } = e;
1147
+ return typeof i == "string" || typeof i == "number";
1148
+ }
1149
+ generateRuleErrorMessage(e, t) {
1150
+ if (!e.operator)
1151
+ return this.titleStr;
1152
+ const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
1153
+ return `${this.localeService.t(At[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
1154
+ }
1155
+ }
1156
+ function gt(o) {
1157
+ var e, t;
1158
+ 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;
1159
+ }
1160
+ function be(o, a, e, t, r = "command", i = !0) {
1161
+ 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 });
1162
+ if (!m)
1163
+ return {
1164
+ redoMutations: l,
1165
+ undoMutations: u
1166
+ };
1167
+ const { worksheet: p } = m, _ = new Se();
1168
+ let R = !1;
1169
+ function M(f, O) {
1170
+ i && f.forEach((P) => {
1171
+ b.foreach(P, (B, $) => {
1172
+ const U = p.getCellRaw(B, $), J = ct(U);
1173
+ (gt(U) || J === O) && !(U != null && U.p) && (R = !0, _.setValue(B, $, {
1174
+ v: O,
1175
+ p: null
1176
+ }));
1177
+ });
1178
+ });
1179
+ }
1180
+ if (e.forEach((f) => {
1181
+ switch (f.type) {
1182
+ case "delete":
1183
+ l.push({
1184
+ id: A.id,
1185
+ params: {
1186
+ unitId: o,
1187
+ subUnitId: a,
1188
+ ruleId: f.rule.uid,
1189
+ source: r
1190
+ }
1191
+ }), u.unshift({
1192
+ id: L.id,
1193
+ params: {
1194
+ unitId: o,
1195
+ subUnitId: a,
1196
+ rule: f.rule,
1197
+ index: f.index,
1198
+ source: r
1199
+ }
1200
+ });
1201
+ break;
1202
+ case "update": {
1203
+ if (de(f.rule.type, n)) {
1204
+ 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;
1205
+ he !== f.rule.formula1 || me !== f.rule.formula2 || !rt(f.newRanges, f.oldRanges) ? (l.push({
1206
+ id: E.id,
1207
+ params: {
1208
+ unitId: o,
1209
+ subUnitId: a,
1210
+ ruleId: f.ruleId,
1211
+ payload: {
1212
+ type: y.ALL,
1213
+ payload: {
1214
+ formula1: he,
1215
+ formula2: me,
1216
+ ranges: f.newRanges
1217
+ }
1218
+ }
1219
+ }
1220
+ }), u.unshift({
1221
+ id: E.id,
1222
+ params: {
1223
+ unitId: o,
1224
+ subUnitId: a,
1225
+ ruleId: f.ruleId,
1226
+ payload: {
1227
+ type: y.ALL,
1228
+ payload: {
1229
+ formula1: f.rule.formula1,
1230
+ formula2: f.rule.formula2,
1231
+ ranges: f.oldRanges
1232
+ }
1233
+ }
1234
+ }
1235
+ })) : (l.push({
1236
+ id: E.id,
1237
+ params: {
1238
+ unitId: o,
1239
+ subUnitId: a,
1240
+ ruleId: f.ruleId,
1241
+ payload: {
1242
+ type: y.RANGE,
1243
+ payload: f.newRanges
1244
+ },
1245
+ source: r
1246
+ }
1247
+ }), u.unshift({
1248
+ id: E.id,
1249
+ params: {
1250
+ unitId: o,
1251
+ subUnitId: a,
1252
+ ruleId: f.ruleId,
1253
+ payload: {
1254
+ type: y.RANGE,
1255
+ payload: f.oldRanges
1256
+ },
1257
+ source: r
1258
+ }
1259
+ }));
1260
+ } else
1261
+ l.push({
1262
+ id: E.id,
1263
+ params: {
1264
+ unitId: o,
1265
+ subUnitId: a,
1266
+ ruleId: f.ruleId,
1267
+ payload: {
1268
+ type: y.RANGE,
1269
+ payload: f.newRanges
1270
+ },
1271
+ source: r
1272
+ }
1273
+ }), u.unshift({
1274
+ id: E.id,
1275
+ params: {
1276
+ unitId: o,
1277
+ subUnitId: a,
1278
+ ruleId: f.ruleId,
1279
+ payload: {
1280
+ type: y.RANGE,
1281
+ payload: f.oldRanges
1282
+ },
1283
+ source: r
1284
+ }
1285
+ });
1286
+ const O = d.getRuleById(o, a, f.ruleId);
1287
+ if (O && O.type === T.CHECKBOX) {
1288
+ const B = d.getValidator(T.CHECKBOX).parseFormulaSync(O, o, a);
1289
+ M(f.newRanges, B.formula2);
1290
+ }
1291
+ break;
1292
+ }
1293
+ case "add": {
1294
+ if (l.push({
1295
+ id: L.id,
1296
+ params: {
1297
+ unitId: o,
1298
+ subUnitId: a,
1299
+ rule: f.rule,
1300
+ source: r
1301
+ }
1302
+ }), u.unshift({
1303
+ id: A.id,
1304
+ params: {
1305
+ unitId: o,
1306
+ subUnitId: a,
1307
+ ruleId: f.rule.uid,
1308
+ source: r
1309
+ }
1310
+ }), f.rule.type === T.CHECKBOX) {
1311
+ const P = d.getValidator(T.CHECKBOX).parseFormulaSync(f.rule, o, a);
1312
+ M(f.rule.ranges, P.originFormula2);
1313
+ }
1314
+ break;
1315
+ }
1316
+ }
1317
+ }), R) {
1318
+ const f = {
1319
+ id: se.id,
1320
+ params: {
1321
+ unitId: o,
1322
+ subUnitId: a,
1323
+ cellValue: _.getData()
1324
+ }
1325
+ }, O = {
1326
+ id: se.id,
1327
+ params: ot(t, f.params)
1328
+ };
1329
+ l.push(f), u.push(O);
1330
+ }
1331
+ return {
1332
+ redoMutations: l,
1333
+ undoMutations: u
1334
+ };
1335
+ }
1336
+ const ha = {
1337
+ type: z.COMMAND,
1338
+ id: "sheet.command.updateDataValidationRuleRange",
1339
+ handler(o, a) {
1340
+ if (!a)
1341
+ return !1;
1342
+ const { unitId: e, subUnitId: t, ranges: r, ruleId: i } = a, s = o.get(F), n = o.get(x), l = o.get(Z);
1343
+ if (!s.getRuleById(e, t, i))
1344
+ return !1;
1345
+ const d = s.getRuleObjectMatrix(e, t).clone();
1346
+ d.updateRange(i, r);
1347
+ const c = d.diff(s.getRules(e, t)), { redoMutations: m, undoMutations: p } = be(e, t, c, o);
1348
+ return l.pushUndoRedo({
1349
+ undoMutations: p,
1350
+ redoMutations: m,
1351
+ unitID: e
1352
+ }), Ie(m, n), !0;
1353
+ }
1354
+ }, ma = {
1355
+ type: z.COMMAND,
1356
+ id: "sheet.command.addDataValidation",
1357
+ handler(o, a) {
1358
+ if (!a)
1359
+ return !1;
1360
+ 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();
1361
+ l.addRule(r);
1362
+ const u = l.diff(i.getRules(e, t)), d = i.getValidator(r.type), c = {
1363
+ unitId: e,
1364
+ subUnitId: t,
1365
+ rule: {
1366
+ ...r,
1367
+ ...d == null ? void 0 : d.normalizeFormula(r, e, t)
1368
+ }
1369
+ }, { redoMutations: m, undoMutations: p } = be(e, t, u, o);
1370
+ return m.push({
1371
+ id: L.id,
1372
+ params: c
1373
+ }), p.unshift({
1374
+ id: A.id,
1375
+ params: {
1376
+ unitId: e,
1377
+ subUnitId: t,
1378
+ ruleId: r.uid
1379
+ }
1380
+ }), n.pushUndoRedo({
1381
+ unitID: e,
1382
+ redoMutations: m,
1383
+ undoMutations: p
1384
+ }), Ie(m, s), !0;
1385
+ }
1386
+ }, ga = {
1387
+ type: z.COMMAND,
1388
+ id: "sheets.command.update-data-validation-setting",
1389
+ // eslint-disable-next-line max-lines-per-function
1390
+ handler(o, a) {
1391
+ if (!a)
1392
+ return !1;
1393
+ 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);
1394
+ if (!d)
1395
+ return !1;
1396
+ const c = r.getRuleById(s, n, l);
1397
+ if (!c)
1398
+ return !1;
1399
+ const m = { ...c, ...u };
1400
+ if (!d.validatorFormula(m, s, n).success)
1401
+ return !1;
1402
+ const p = {
1403
+ unitId: s,
1404
+ subUnitId: n,
1405
+ ruleId: l,
1406
+ payload: {
1407
+ type: y.SETTING,
1408
+ payload: {
1409
+ ...u,
1410
+ ...d.normalizeFormula(m, s, n)
1411
+ }
1412
+ }
1413
+ }, _ = [{
1414
+ id: E.id,
1415
+ params: p
1416
+ }], R = {
1417
+ unitId: s,
1418
+ subUnitId: n,
1419
+ ruleId: l,
1420
+ payload: {
1421
+ type: y.SETTING,
1422
+ payload: Dt(c)
1423
+ }
1424
+ }, M = [{
1425
+ id: E.id,
1426
+ params: R
1427
+ }];
1428
+ if (u.type === T.CHECKBOX) {
1429
+ const O = c.ranges, P = o.get(w), B = Ye(P, { unitId: s, subUnitId: n });
1430
+ if (B) {
1431
+ const $ = new Se(), { worksheet: U } = B, { formula2: J = Me, formula1: ce = Ve } = c, { formula2: he = Me, formula1: me = Ve } = u;
1432
+ let Le = !1;
1433
+ if (O.forEach((ge) => {
1434
+ b.foreach(ge, (ae, xe) => {
1435
+ const k = U.getCellRaw(ae, xe), Ke = ct(k);
1436
+ (gt(k) || Ke === String(J)) && !(k != null && k.p) ? ($.setValue(ae, xe, {
1437
+ v: he,
1438
+ p: null
1439
+ }), Le = !0) : Ke === String(ce) && !(k != null && k.p) && ($.setValue(ae, xe, {
1440
+ v: me,
1441
+ p: null
1442
+ }), Le = !0);
1443
+ });
1444
+ }), Le) {
1445
+ const ge = {
1446
+ id: se.id,
1447
+ params: {
1448
+ unitId: s,
1449
+ subUnitId: n,
1450
+ cellValue: $.getData()
1451
+ }
1452
+ }, ae = {
1453
+ id: se.id,
1454
+ params: ot(o, ge.params)
1455
+ };
1456
+ _.push(ge), M.push(ae);
1457
+ }
1458
+ }
1459
+ }
1460
+ return Ie(_, e).result ? (t.pushUndoRedo({
1461
+ unitID: s,
1462
+ redoMutations: _,
1463
+ undoMutations: M
1464
+ }), !0) : !1;
1465
+ }
1466
+ }, _a = {
1467
+ type: z.COMMAND,
1468
+ id: "sheets.command.update-data-validation-options",
1469
+ handler(o, a) {
1470
+ if (!a)
1471
+ return !1;
1472
+ 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);
1473
+ if (!u)
1474
+ return !1;
1475
+ const d = {
1476
+ unitId: i,
1477
+ subUnitId: s,
1478
+ ruleId: n,
1479
+ payload: {
1480
+ type: y.OPTIONS,
1481
+ payload: l
1482
+ }
1483
+ }, c = [{
1484
+ id: E.id,
1485
+ params: d
1486
+ }], m = {
1487
+ unitId: i,
1488
+ subUnitId: s,
1489
+ ruleId: n,
1490
+ payload: {
1491
+ type: y.OPTIONS,
1492
+ payload: bt(u)
1493
+ }
1494
+ }, p = [{
1495
+ id: E.id,
1496
+ params: m
1497
+ }];
1498
+ return t.pushUndoRedo({
1499
+ unitID: i,
1500
+ redoMutations: c,
1501
+ undoMutations: p
1502
+ }), e.executeCommand(E.id, d), !0;
1503
+ }
1504
+ }, pa = {
1505
+ type: z.COMMAND,
1506
+ id: "sheets.command.clear-range-data-validation",
1507
+ handler(o, a) {
1508
+ if (!a)
1509
+ return !1;
1510
+ 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);
1511
+ if (!n) return !1;
1512
+ const u = o.get(Z), d = l.getRuleObjectMatrix(e, t).clone();
1513
+ d.removeRange(r);
1514
+ const c = d.diff(l.getRules(e, t)), { redoMutations: m, undoMutations: p } = be(e, t, c, o);
1515
+ return u.pushUndoRedo({
1516
+ unitID: e,
1517
+ redoMutations: m,
1518
+ undoMutations: p
1519
+ }), Ie(m, i).result;
1520
+ }
1521
+ }, fa = {
1522
+ type: z.COMMAND,
1523
+ id: "sheet.command.remove-all-data-validation",
1524
+ handler(o, a) {
1525
+ if (!a)
1526
+ return !1;
1527
+ const { unitId: e, subUnitId: t } = a, r = o.get(x), i = o.get(F), s = o.get(Z), n = [...i.getRules(e, t)], l = {
1528
+ unitId: e,
1529
+ subUnitId: t,
1530
+ ruleId: n.map((c) => c.uid)
1531
+ }, u = [{
1532
+ id: A.id,
1533
+ params: l
1534
+ }], d = [{
1535
+ id: L.id,
1536
+ params: {
1537
+ unitId: e,
1538
+ subUnitId: t,
1539
+ rule: n
1540
+ }
1541
+ }];
1542
+ return s.pushUndoRedo({
1543
+ redoMutations: u,
1544
+ undoMutations: d,
1545
+ unitID: e
1546
+ }), r.executeCommand(A.id, l), !0;
1547
+ }
1548
+ }, Ra = (o, a) => {
1549
+ const e = o.get(F), { unitId: t, subUnitId: r, ruleId: i, source: s } = a;
1550
+ if (Array.isArray(i)) {
1551
+ const l = i.map((u) => e.getRuleById(t, r, u)).filter(Boolean);
1552
+ return [{
1553
+ id: L.id,
1554
+ params: {
1555
+ unitId: t,
1556
+ subUnitId: r,
1557
+ rule: l,
1558
+ source: s
1559
+ }
1560
+ }];
1561
+ }
1562
+ return [{
1563
+ id: L.id,
1564
+ params: {
1565
+ unitId: t,
1566
+ subUnitId: r,
1567
+ rule: {
1568
+ ...e.getRuleById(t, r, i)
1569
+ },
1570
+ index: e.getRuleIndex(t, r, i)
1571
+ }
1572
+ }];
1573
+ }, va = {
1574
+ type: z.COMMAND,
1575
+ id: "sheet.command.remove-data-validation-rule",
1576
+ handler(o, a) {
1577
+ if (!a)
1578
+ return !1;
1579
+ const { unitId: e, subUnitId: t, ruleId: r } = a, i = o.get(x), s = o.get(Z), n = o.get(F), l = [{
1580
+ id: A.id,
1581
+ params: a
1582
+ }], u = [{
1583
+ id: L.id,
1584
+ params: {
1585
+ unitId: e,
1586
+ subUnitId: t,
1587
+ rule: {
1588
+ ...n.getRuleById(e, t, r)
1589
+ },
1590
+ index: n.getRuleIndex(e, t, r)
1591
+ }
1592
+ }];
1593
+ return s.pushUndoRedo({
1594
+ undoMutations: u,
1595
+ redoMutations: l,
1596
+ unitID: a.unitId
1597
+ }), i.executeCommand(A.id, a), !0;
1598
+ }
1599
+ }, Sa = "sheets-data-validation.config", tt = {};
1600
+ var Va = Object.getOwnPropertyDescriptor, Ma = (o, a, e, t) => {
1601
+ for (var r = t > 1 ? void 0 : t ? Va(a, e) : a, i = o.length - 1, s; i >= 0; i--)
1602
+ (s = o[i]) && (r = s(r) || r);
1603
+ return r;
1604
+ }, We = (o, a) => (e, t) => a(e, t, o);
1605
+ let Ee = class extends W {
1606
+ constructor(a, e, t) {
1607
+ super();
1608
+ g(this, "_disposableMap", /* @__PURE__ */ new Map());
1609
+ g(this, "registerRule", (a, e, t) => {
1610
+ de(t.type, this._validatorRegistryService) && this.register(a, e, t);
1611
+ });
1612
+ this._dataValidationModel = a, this._formulaRefRangeService = e, this._validatorRegistryService = t, this._initRefRange();
1613
+ }
1614
+ _getIdWithUnitId(a, e, t) {
1615
+ return `${a}_${e}_${t}`;
1616
+ }
1617
+ // eslint-disable-next-line max-lines-per-function
1618
+ register(a, e, t) {
1619
+ const r = t.ranges, i = t.formula1, s = t.formula2, n = this._formulaRefRangeService.registerRangeFormula(a, e, r, [i != null ? i : "", s != null ? s : ""], (u) => {
1620
+ if (u.length === 0)
1621
+ return {
1622
+ undos: [{
1623
+ id: L.id,
1624
+ params: {
1625
+ unitId: a,
1626
+ subUnitId: e,
1627
+ rule: t,
1628
+ source: "patched"
1629
+ }
1630
+ }],
1631
+ redos: [{
1632
+ id: A.id,
1633
+ params: {
1634
+ unitId: a,
1635
+ subUnitId: e,
1636
+ ruleId: t.uid,
1637
+ source: "patched"
1638
+ }
1639
+ }]
1640
+ };
1641
+ const d = [], c = [], m = u[0];
1642
+ d.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: m.ranges,
1652
+ formula1: m.formulas[0],
1653
+ formula2: m.formulas[1]
1654
+ }
1655
+ },
1656
+ source: "patched"
1657
+ }
1658
+ }), c.push({
1659
+ id: E.id,
1660
+ params: {
1661
+ unitId: a,
1662
+ subUnitId: e,
1663
+ ruleId: t.uid,
1664
+ payload: {
1665
+ type: y.ALL,
1666
+ payload: {
1667
+ ranges: r,
1668
+ formula1: i,
1669
+ formula2: s
1670
+ }
1671
+ },
1672
+ source: "patched"
1673
+ }
1674
+ });
1675
+ for (let p = 1; p < u.length; p++) {
1676
+ const _ = u[p], R = Mt();
1677
+ d.push({
1678
+ id: L.id,
1679
+ params: {
1680
+ unitId: a,
1681
+ subUnitId: e,
1682
+ rule: {
1683
+ ...t,
1684
+ uid: R,
1685
+ formula1: _.formulas[0],
1686
+ formula2: _.formulas[1],
1687
+ ranges: _.ranges
1688
+ },
1689
+ source: "patched"
1690
+ }
1691
+ }), c.push({
1692
+ id: A.id,
1693
+ params: {
1694
+ unitId: a,
1695
+ subUnitId: e,
1696
+ ruleId: R,
1697
+ source: "patched"
1698
+ }
1699
+ });
1700
+ }
1701
+ return {
1702
+ undos: c,
1703
+ redos: d
1704
+ };
1705
+ }), l = this._getIdWithUnitId(a, e, t.uid);
1706
+ this._disposableMap.set(l, n);
1707
+ }
1708
+ _initRefRange() {
1709
+ const a = this._dataValidationModel.getAll();
1710
+ for (const [e, t] of a)
1711
+ for (const [r, i] of t)
1712
+ for (const s of i)
1713
+ this.registerRule(e, r, s);
1714
+ this.disposeWithMe(
1715
+ this._dataValidationModel.ruleChange$.subscribe((e) => {
1716
+ const { unitId: t, subUnitId: r, rule: i } = e;
1717
+ switch (e.type) {
1718
+ case "add": {
1719
+ const s = e.rule;
1720
+ this.registerRule(e.unitId, e.subUnitId, s);
1721
+ break;
1722
+ }
1723
+ case "remove": {
1724
+ const s = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
1725
+ s && s.dispose();
1726
+ break;
1727
+ }
1728
+ case "update": {
1729
+ const s = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, s.uid));
1730
+ n && n.dispose(), this.registerRule(e.unitId, e.subUnitId, s);
1731
+ break;
1732
+ }
1733
+ }
1734
+ })
1735
+ ), this.disposeWithMe(Qe(() => {
1736
+ this._disposableMap.forEach((e) => {
1737
+ e.dispose();
1738
+ }), this._disposableMap.clear();
1739
+ }));
1740
+ }
1741
+ };
1742
+ Ee = Ma([
1743
+ We(0, v(F)),
1744
+ We(1, v(ut)),
1745
+ We(2, v(q))
1746
+ ], Ee);
1747
+ 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) => {
1748
+ for (var r = t > 1 ? void 0 : t ? ya(a, e) : a, i = o.length - 1, s; i >= 0; i--)
1749
+ (s = o[i]) && (r = s(r) || r);
1750
+ return r;
1751
+ }, Pe = (o, a) => (e, t) => a(e, t, o);
1752
+ let Te = class extends W {
1753
+ constructor(o, a, e) {
1754
+ super(), this._univerInstanceService = o, this._permissionService = a, this._lexerTreeBuilder = e;
1755
+ }
1756
+ getFormulaRefCheck(o) {
1757
+ var e, t;
1758
+ const a = this._lexerTreeBuilder.sequenceNodesBuilder(o);
1759
+ if (!a)
1760
+ return !0;
1761
+ for (let r = 0; r < a.length; r++) {
1762
+ const i = a[r];
1763
+ if (typeof i == "string")
1764
+ continue;
1765
+ const { token: s } = i, n = Qt(s), l = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET);
1766
+ let u = l.getActiveSheet();
1767
+ const d = l.getUnitId();
1768
+ if (n.sheetName) {
1769
+ if (u = l.getSheetBySheetName(n.sheetName), !u)
1770
+ return !1;
1771
+ const R = u == null ? void 0 : u.getSheetId();
1772
+ if (!this._permissionService.getPermissionPoint(new xt(d, R).id)) return !1;
1773
+ }
1774
+ if (!u)
1775
+ return !1;
1776
+ const { startRow: c, endRow: m, startColumn: p, endColumn: _ } = n.range;
1777
+ for (let R = c; R <= m; R++)
1778
+ for (let M = p; M <= _; M++) {
1779
+ const f = (t = (e = u.getCell(R, M)) == null ? void 0 : e.selectionProtection) == null ? void 0 : t[0];
1780
+ if ((f == null ? void 0 : f[_t.View]) === !1)
1781
+ return !1;
1782
+ }
1783
+ }
1784
+ return !0;
1785
+ }
1786
+ };
1787
+ Te = Ea([
1788
+ Pe(0, w),
1789
+ Pe(1, yt),
1790
+ Pe(2, v(Y))
1791
+ ], Te);
1792
+ var Ta = Object.getOwnPropertyDescriptor, Fa = (o, a, e, t) => {
1793
+ for (var r = t > 1 ? void 0 : t ? Ta(a, e) : a, i = o.length - 1, s; i >= 0; i--)
1794
+ (s = o[i]) && (r = s(r) || r);
1795
+ return r;
1796
+ }, ee = (o, a) => (e, t) => a(e, t, o);
1797
+ let Fe = class extends W {
1798
+ constructor(a, e, t, r, i, s) {
1799
+ super();
1800
+ g(this, "_disposableMap", /* @__PURE__ */ new Map());
1801
+ g(this, "registerRule", (a, e, t) => {
1802
+ de(t.type, this._validatorRegistryService) || (this.register(a, e, t), this.registerFormula(a, e, t));
1803
+ });
1804
+ this._dataValidationModel = a, this._injector = e, this._refRangeService = t, this._dataValidationFormulaService = r, this._formulaRefRangeService = i, this._validatorRegistryService = s, this._initRefRange();
1805
+ }
1806
+ _getIdWithUnitId(a, e, t) {
1807
+ return `${a}_${e}_${t}`;
1808
+ }
1809
+ // eslint-disable-next-line max-lines-per-function
1810
+ registerFormula(a, e, t) {
1811
+ var u;
1812
+ const r = t.uid, i = this._getIdWithUnitId(a, e, r), s = (u = this._disposableMap.get(i)) != null ? u : /* @__PURE__ */ new Set(), n = (d, c) => {
1813
+ const m = this._dataValidationModel.getRuleById(a, e, r);
1814
+ if (!m)
1815
+ return { redos: [], undos: [] };
1816
+ const p = m[d];
1817
+ if (!p || p === c)
1818
+ return { redos: [], undos: [] };
1819
+ const _ = {
1820
+ unitId: a,
1821
+ subUnitId: e,
1822
+ ruleId: t.uid,
1823
+ payload: {
1824
+ type: y.SETTING,
1825
+ payload: {
1826
+ type: m.type,
1827
+ formula1: m.formula1,
1828
+ formula2: m.formula2,
1829
+ [d]: c
1830
+ }
1831
+ },
1832
+ source: "patched"
1833
+ }, R = {
1834
+ unitId: a,
1835
+ subUnitId: e,
1836
+ ruleId: t.uid,
1837
+ payload: {
1838
+ type: y.SETTING,
1839
+ payload: {
1840
+ type: m.type,
1841
+ formula1: m.formula1,
1842
+ formula2: m.formula2
1843
+ }
1844
+ },
1845
+ source: "patched"
1846
+ }, M = [
1847
+ {
1848
+ id: E.id,
1849
+ params: _
1850
+ }
1851
+ ], f = [
1852
+ {
1853
+ id: E.id,
1854
+ params: R
1855
+ }
1856
+ ];
1857
+ return { redos: M, undos: f };
1858
+ }, l = this._dataValidationFormulaService.getRuleFormulaInfo(a, e, r);
1859
+ if (l) {
1860
+ const [d, c] = l;
1861
+ if (d) {
1862
+ const m = this._formulaRefRangeService.registerFormula(
1863
+ a,
1864
+ e,
1865
+ d.text,
1866
+ (p) => n("formula1", p)
1867
+ );
1868
+ s.add(() => m.dispose());
1869
+ }
1870
+ if (c) {
1871
+ const m = this._formulaRefRangeService.registerFormula(
1872
+ a,
1873
+ e,
1874
+ c.text,
1875
+ (p) => n("formula2", p)
1876
+ );
1877
+ s.add(() => m.dispose());
1878
+ }
1879
+ }
1880
+ }
1881
+ register(a, e, t) {
1882
+ var l;
1883
+ const r = (u) => {
1884
+ const d = [...t.ranges], m = d.map((_) => Ut(_, u)).filter((_) => !!_).flat();
1885
+ if (rt(m, d))
1886
+ return { redos: [], undos: [] };
1887
+ if (m.length) {
1888
+ const _ = {
1889
+ unitId: a,
1890
+ subUnitId: e,
1891
+ ruleId: t.uid,
1892
+ payload: {
1893
+ type: y.RANGE,
1894
+ payload: m
1895
+ },
1896
+ source: "patched"
1897
+ }, R = [{ id: E.id, params: _ }], M = [{
1898
+ id: E.id,
1899
+ params: {
1900
+ unitId: a,
1901
+ subUnitId: e,
1902
+ ruleId: t.uid,
1903
+ payload: {
1904
+ type: y.RANGE,
1905
+ payload: d
1906
+ },
1907
+ source: "patched"
1908
+ }
1909
+ }];
1910
+ return { redos: R, undos: M };
1911
+ } else {
1912
+ const _ = { unitId: a, subUnitId: e, ruleId: t.uid }, R = [{ id: A.id, params: _ }], M = Ra(this._injector, _);
1913
+ return { redos: R, undos: M };
1914
+ }
1915
+ }, i = [];
1916
+ t.ranges.forEach((u) => {
1917
+ const d = this._refRangeService.registerRefRange(u, r, a, e);
1918
+ i.push(() => d.dispose());
1919
+ });
1920
+ const s = this._getIdWithUnitId(a, e, t.uid), n = (l = this._disposableMap.get(s)) != null ? l : /* @__PURE__ */ new Set();
1921
+ n.add(() => i.forEach((u) => u())), this._disposableMap.set(s, n);
1922
+ }
1923
+ _initRefRange() {
1924
+ const a = this._dataValidationModel.getAll();
1925
+ for (const [e, t] of a)
1926
+ for (const [r, i] of t)
1927
+ for (const s of i)
1928
+ this.registerRule(e, r, s);
1929
+ this.disposeWithMe(
1930
+ this._dataValidationModel.ruleChange$.subscribe((e) => {
1931
+ const { unitId: t, subUnitId: r, rule: i } = e;
1932
+ switch (e.type) {
1933
+ case "add": {
1934
+ const s = e.rule;
1935
+ this.registerRule(e.unitId, e.subUnitId, s);
1936
+ break;
1937
+ }
1938
+ case "remove": {
1939
+ const s = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
1940
+ s && s.forEach((n) => n());
1941
+ break;
1942
+ }
1943
+ case "update": {
1944
+ const s = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, s.uid));
1945
+ n && n.forEach((l) => l()), this.registerRule(e.unitId, e.subUnitId, s);
1946
+ break;
1947
+ }
1948
+ }
1949
+ })
1950
+ ), this.disposeWithMe(Qe(() => {
1951
+ this._disposableMap.forEach((e) => {
1952
+ e.forEach((t) => t());
1953
+ }), this._disposableMap.clear();
1954
+ }));
1955
+ }
1956
+ };
1957
+ Fe = Fa([
1958
+ ee(0, v(F)),
1959
+ ee(1, v(qe)),
1960
+ ee(2, v(Bt)),
1961
+ ee(3, v(K)),
1962
+ ee(4, v(ut)),
1963
+ ee(5, v(q))
1964
+ ], Fe);
1965
+ var Na = Object.getOwnPropertyDescriptor, Ca = (o, a, e, t) => {
1966
+ for (var r = t > 1 ? void 0 : t ? Na(a, e) : a, i = o.length - 1, s; i >= 0; i--)
1967
+ (s = o[i]) && (r = s(r) || r);
1968
+ return r;
1969
+ }, $e = (o, a) => (e, t) => a(e, t, o);
1970
+ let Ne = class extends W {
1971
+ constructor(o, a, e) {
1972
+ super(), this._sheetInterceptorService = o, this._univerInstanceService = a, this._sheetDataValidationModel = e, this._initSheetChange();
1973
+ }
1974
+ _initSheetChange() {
1975
+ this.disposeWithMe(
1976
+ this._sheetInterceptorService.interceptCommand({
1977
+ getMutations: (o) => {
1978
+ var a;
1979
+ if (o.id === Ht.id) {
1980
+ const e = o.params, t = e.unitId || this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET).getUnitId(), r = this._univerInstanceService.getUniverSheetInstance(t);
1981
+ if (!r)
1982
+ return { redos: [], undos: [] };
1983
+ const i = e.subUnitId || ((a = r.getActiveSheet()) == null ? void 0 : a.getSheetId());
1984
+ if (!i)
1985
+ return { redos: [], undos: [] };
1986
+ const s = this._sheetDataValidationModel.getRules(t, i);
1987
+ if (s.length === 0)
1988
+ return { redos: [], undos: [] };
1989
+ const n = s.map((d) => d.uid), l = {
1990
+ unitId: t,
1991
+ subUnitId: i,
1992
+ ruleId: n,
1993
+ source: "patched"
1994
+ }, u = {
1995
+ unitId: t,
1996
+ subUnitId: i,
1997
+ rule: [...s],
1998
+ source: "patched"
1999
+ };
2000
+ return {
2001
+ redos: [{
2002
+ id: A.id,
2003
+ params: l
2004
+ }],
2005
+ undos: [{
2006
+ id: L.id,
2007
+ params: u
2008
+ }]
2009
+ };
2010
+ }
2011
+ return { redos: [], undos: [] };
2012
+ }
2013
+ })
2014
+ );
2015
+ }
2016
+ };
2017
+ Ne = Ca([
2018
+ $e(0, v(st)),
2019
+ $e(1, v(w)),
2020
+ $e(2, v(F))
2021
+ ], Ne);
2022
+ class wa extends G {
2023
+ constructor() {
2024
+ super(...arguments);
2025
+ g(this, "id", T.ANY);
2026
+ g(this, "title", "dataValidation.any.title");
2027
+ g(this, "operators", []);
2028
+ g(this, "scopes", ["sheet"]);
2029
+ g(this, "offsetFormulaByRange", !1);
2030
+ }
2031
+ async parseFormula(e, t, r) {
2032
+ return {
2033
+ formula1: e.formula1,
2034
+ formula2: e.formula2,
2035
+ isFormulaValid: !0
2036
+ };
2037
+ }
2038
+ validatorFormula(e, t, r) {
2039
+ return {
2040
+ success: !0
2041
+ };
2042
+ }
2043
+ async isValidType(e, t, r) {
2044
+ return !0;
2045
+ }
2046
+ generateRuleErrorMessage(e) {
2047
+ return this.localeService.t("dataValidation.any.error");
2048
+ }
2049
+ }
2050
+ class Oa extends G {
2051
+ constructor() {
2052
+ super(...arguments);
2053
+ g(this, "id", T.CUSTOM);
2054
+ g(this, "title", "dataValidation.custom.title");
2055
+ g(this, "operators", []);
2056
+ g(this, "scopes", ["sheet"]);
2057
+ g(this, "_customFormulaService", this.injector.get(H));
2058
+ g(this, "_lexerTreeBuilder", this.injector.get(Y));
2059
+ }
2060
+ validatorFormula(e, t, r) {
2061
+ var u;
2062
+ const i = S(e.formula1), s = (u = e.formula1) != null ? u : "", l = this._lexerTreeBuilder.checkIfAddBracket(s) === 0 && s.startsWith(qt.EQUALS);
2063
+ return {
2064
+ success: i && l,
2065
+ formula1: i && l ? "" : this.localeService.t("dataValidation.validFail.formula")
2066
+ };
2067
+ }
2068
+ async parseFormula(e, t, r) {
2069
+ return {
2070
+ formula1: void 0,
2071
+ formula2: void 0,
2072
+ isFormulaValid: !0
2073
+ };
2074
+ }
2075
+ async isValidType(e, t, r) {
2076
+ 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;
2077
+ 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;
2078
+ }
2079
+ generateRuleErrorMessage(e) {
2080
+ return this.localeService.t("dataValidation.custom.error");
2081
+ }
2082
+ generateRuleName(e) {
2083
+ var t;
2084
+ return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (t = e.formula1) != null ? t : "");
2085
+ }
2086
+ }
2087
+ class Ia extends mt {
2088
+ constructor() {
2089
+ super(...arguments);
2090
+ g(this, "id", T.LIST_MULTIPLE);
2091
+ g(this, "title", "dataValidation.listMultiple.title");
2092
+ g(this, "offsetFormulaByRange", !1);
2093
+ g(this, "skipDefaultFontRender", () => !0);
2094
+ }
2095
+ }
2096
+ class Aa extends G {
2097
+ constructor() {
2098
+ super(...arguments);
2099
+ g(this, "_customFormulaService", this.injector.get(H));
2100
+ g(this, "_lexerTreeBuilder", this.injector.get(Y));
2101
+ g(this, "id", T.WHOLE);
2102
+ g(this, "title", "dataValidation.whole.title");
2103
+ g(this, "operators", [
2104
+ h.BETWEEN,
2105
+ h.EQUAL,
2106
+ h.GREATER_THAN,
2107
+ h.GREATER_THAN_OR_EQUAL,
2108
+ h.LESS_THAN,
2109
+ h.LESS_THAN_OR_EQUAL,
2110
+ h.NOT_BETWEEN,
2111
+ h.NOT_EQUAL
2112
+ ]);
2113
+ g(this, "scopes", ["sheet"]);
2114
+ }
2115
+ _isFormulaOrInt(e) {
2116
+ return !V.isBlank(e) && (S(e) || !Number.isNaN(+e) && Number.isInteger(+e));
2117
+ }
2118
+ async isValidType(e, t, r) {
2119
+ const { value: i } = e, s = ye(i);
2120
+ return !Number.isNaN(s) && Number.isInteger(s);
2121
+ }
2122
+ transform(e, t, r) {
2123
+ const { value: i } = e;
2124
+ return {
2125
+ ...e,
2126
+ value: ye(i)
2127
+ };
2128
+ }
2129
+ _parseNumber(e) {
2130
+ return e == null ? Number.NaN : +e;
2131
+ }
2132
+ async parseFormula(e, t, r, i, s) {
2133
+ 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}`);
2134
+ return {
2135
+ formula1: this._parseNumber(c),
2136
+ formula2: this._parseNumber(m),
2137
+ isFormulaValid: p
2138
+ };
2139
+ }
2140
+ validatorFormula(e, t, r) {
2141
+ const i = e.operator;
2142
+ if (!i)
2143
+ return {
2144
+ success: !1
2145
+ };
2146
+ 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");
2147
+ return l ? {
2148
+ success: s && n,
2149
+ formula1: s ? void 0 : u,
2150
+ formula2: n ? void 0 : u
2151
+ } : {
2152
+ success: s,
2153
+ formula1: u
2154
+ };
2155
+ }
2156
+ generateRuleErrorMessage(e, t) {
2157
+ if (!e.operator)
2158
+ return this.titleStr;
2159
+ const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
2160
+ return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
2161
+ }
2162
+ }
2163
+ var Da = Object.getOwnPropertyDescriptor, ba = (o, a, e, t) => {
2164
+ for (var r = t > 1 ? void 0 : t ? Da(a, e) : a, i = o.length - 1, s; i >= 0; i--)
2165
+ (s = o[i]) && (r = s(r) || r);
2166
+ return r;
2167
+ }, te = (o, a) => (e, t) => a(e, t, o);
2168
+ let Ce = class extends Tt {
2169
+ constructor(o, a, e, t, r, i) {
2170
+ super(), this._univerInstanceService = o, this._dataValidatorRegistryService = a, this._injector = e, this._selectionManagerService = t, this._sheetInterceptorService = r, this._sheetDataValidationModel = i, this._init();
2171
+ }
2172
+ _init() {
2173
+ this._registerValidators(), this._initCommandInterceptor();
2174
+ }
2175
+ _registerValidators() {
2176
+ [
2177
+ wa,
2178
+ na,
2179
+ Aa,
2180
+ ca,
2181
+ sa,
2182
+ aa,
2183
+ mt,
2184
+ Ia,
2185
+ Oa
2186
+ ].forEach((o) => {
2187
+ const a = this._injector.createInstance(o);
2188
+ this.disposeWithMe(this._dataValidatorRegistryService.register(a)), this.disposeWithMe(Qe(() => this._injector.delete(o)));
2189
+ });
2190
+ }
2191
+ _initCommandInterceptor() {
2192
+ this._sheetInterceptorService.interceptCommand({
2193
+ getMutations: (o) => {
2194
+ var a;
2195
+ if (o.id === Wt.id) {
2196
+ const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e.getUnitId(), r = e.getActiveSheet();
2197
+ if (!r)
2198
+ throw new Error("No active sheet found");
2199
+ const i = r.getSheetId(), s = (a = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : a.map((c) => c.range), n = this._sheetDataValidationModel.getRuleObjectMatrix(t, i).clone();
2200
+ s && n.removeRange(s);
2201
+ const l = n.diff(this._sheetDataValidationModel.getRules(t, i)), { redoMutations: u, undoMutations: d } = be(t, i, l, this._injector, "patched");
2202
+ return {
2203
+ undos: d,
2204
+ redos: u
2205
+ };
2206
+ }
2207
+ return {
2208
+ undos: [],
2209
+ redos: []
2210
+ };
2211
+ }
2212
+ });
2213
+ }
2214
+ };
2215
+ Ce = ba([
2216
+ te(0, w),
2217
+ te(1, v(q)),
2218
+ te(2, v(qe)),
2219
+ te(3, v(nt)),
2220
+ te(4, v(st)),
2221
+ te(5, v(F))
2222
+ ], Ce);
2223
+ var La = Object.getOwnPropertyDescriptor, xa = (o, a, e, t) => {
2224
+ for (var r = t > 1 ? void 0 : t ? La(a, e) : a, i = o.length - 1, s; i >= 0; i--)
2225
+ (s = o[i]) && (r = s(r) || r);
2226
+ return r;
2227
+ }, Re = (o, a) => (e, t) => a(e, t, o);
2228
+ let we = class extends W {
2229
+ constructor(o, a, e, t) {
2230
+ super(), this._univerInstanceService = o, this._sheetDataValidationModel = a, this._dataValidationCacheService = e, this._lifecycleService = t, this._initRecalculate();
2231
+ }
2232
+ _initRecalculate() {
2233
+ const o = (a) => {
2234
+ if (a.length === 0)
2235
+ return;
2236
+ const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e == null ? void 0 : e.getActiveSheet(), r = {};
2237
+ a.flat().forEach((i) => {
2238
+ r[i.unitId] || (r[i.unitId] = {}), r[i.unitId][i.subUnitId] || (r[i.unitId][i.subUnitId] = []);
2239
+ const s = this._univerInstanceService.getUnit(i.unitId, N.UNIVER_SHEET), n = s == null ? void 0 : s.getSheetBySheetId(i.subUnitId);
2240
+ n && r[i.unitId][i.subUnitId].push(...i.ranges.map((l) => b.transformRange(l, n)));
2241
+ }), Object.entries(r).forEach(([i, s]) => {
2242
+ Object.entries(s).forEach(([n, l]) => {
2243
+ (e == null ? void 0 : e.getUnitId()) === i && (t == null ? void 0 : t.getSheetId()) === n ? this.validatorRanges(i, n, l) : requestIdleCallback(() => {
2244
+ this.validatorRanges(i, n, l);
2245
+ });
2246
+ });
2247
+ });
2248
+ };
2249
+ 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));
2250
+ }
2251
+ async _validatorByCell(o, a, e, t) {
2252
+ const r = o.getUnitId(), i = a.getSheetId();
2253
+ if (!V.isDefine(e) || !V.isDefine(t))
2254
+ throw new Error(`row or col is not defined, row: ${e}, col: ${t}`);
2255
+ const s = this._sheetDataValidationModel.getRuleByLocation(r, i, e, t);
2256
+ return s ? new Promise((n) => {
2257
+ this._sheetDataValidationModel.validator(s, { unitId: r, subUnitId: i, row: e, col: t, worksheet: a, workbook: o }, (l) => {
2258
+ n(l);
2259
+ });
2260
+ }) : D.VALID;
2261
+ }
2262
+ async validatorCell(o, a, e, t) {
2263
+ const r = this._univerInstanceService.getUnit(o, N.UNIVER_SHEET);
2264
+ if (!r)
2265
+ throw new Error(`cannot find current workbook, unitId: ${o}`);
2266
+ const i = r.getSheetBySheetId(a);
2267
+ if (!i)
2268
+ throw new Error(`cannot find current worksheet, sheetId: ${a}`);
2269
+ return this._validatorByCell(r, i, e, t);
2270
+ }
2271
+ validatorRanges(o, a, e) {
2272
+ if (!e.length)
2273
+ return Promise.resolve([]);
2274
+ const t = this._univerInstanceService.getUnit(o, N.UNIVER_SHEET);
2275
+ if (!t)
2276
+ throw new Error(`cannot find current workbook, unitId: ${o}`);
2277
+ const r = t.getSheetBySheetId(a);
2278
+ if (!r)
2279
+ throw new Error(`cannot find current worksheet, sheetId: ${a}`);
2280
+ return Promise.all(e.map((i) => {
2281
+ const s = [];
2282
+ return b.foreach(i, (n, l) => {
2283
+ s.push(this._validatorByCell(t, r, n, l));
2284
+ }), Promise.all(s);
2285
+ }));
2286
+ }
2287
+ async validatorWorksheet(o, a) {
2288
+ const e = this._univerInstanceService.getUnit(o, N.UNIVER_SHEET);
2289
+ if (!e)
2290
+ throw new Error(`cannot find current workbook, unitId: ${o}`);
2291
+ const t = e.getSheetBySheetId(a);
2292
+ if (!t)
2293
+ throw new Error(`cannot find current worksheet, sheetId: ${a}`);
2294
+ const r = this._sheetDataValidationModel.getRules(o, a);
2295
+ return await Promise.all(r.map((i) => Promise.all(i.ranges.map((s) => {
2296
+ const n = [];
2297
+ return b.foreach(s, (l, u) => {
2298
+ n.push(this._validatorByCell(e, t, l, u));
2299
+ }), n;
2300
+ })))), this._dataValidationCacheService.ensureCache(o, a);
2301
+ }
2302
+ async validatorWorkbook(o) {
2303
+ const a = this._sheetDataValidationModel.getSubUnitIds(o), e = await Promise.all(a.map((r) => this.validatorWorksheet(o, r))), t = {};
2304
+ return e.forEach((r, i) => {
2305
+ t[a[i]] = r;
2306
+ }), t;
2307
+ }
2308
+ getDataValidations(o, a, e) {
2309
+ const t = this._sheetDataValidationModel.getRuleObjectMatrix(o, a), r = /* @__PURE__ */ new Set();
2310
+ return e.forEach((s) => {
2311
+ b.foreach(s, (n, l) => {
2312
+ const u = t.getValue(n, l);
2313
+ u && r.add(u);
2314
+ });
2315
+ }), Array.from(r).map((s) => this._sheetDataValidationModel.getRuleById(o, a, s)).filter(Boolean);
2316
+ }
2317
+ getDataValidation(o, a, e) {
2318
+ return this.getDataValidations(o, a, e)[0];
2319
+ }
2320
+ };
2321
+ we = xa([
2322
+ Re(0, w),
2323
+ Re(1, v(F)),
2324
+ Re(2, v(Q)),
2325
+ Re(3, v(Ft))
2326
+ ], we);
2327
+ 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) => {
2328
+ for (var r = t > 1 ? void 0 : t ? Ua(a, e) : a, i = o.length - 1, s; i >= 0; i--)
2329
+ (s = o[i]) && (r = s(r) || r);
2330
+ return r;
2331
+ }, ke = (o, a) => (e, t) => a(e, t, o), pt = (o, a, e) => Ha(o, typeof a != "symbol" ? a + "" : a, e);
2332
+ let Oe = class extends Ot {
2333
+ constructor(o = tt, a, e, t) {
2334
+ super(), this._config = o, this._injector = a, this._commandService = e, this._configService = t;
2335
+ const { ...r } = It(
2336
+ {},
2337
+ tt,
2338
+ this._config
2339
+ );
2340
+ this._configService.setConfig(Sa, r);
2341
+ }
2342
+ onStarting() {
2343
+ [
2344
+ [Q],
2345
+ [K],
2346
+ [H],
2347
+ [we],
2348
+ [F],
2349
+ [Ce],
2350
+ [Te],
2351
+ [Ne],
2352
+ [Fe],
2353
+ [Ee]
2354
+ ].forEach((o) => {
2355
+ this._injector.add(o);
2356
+ }), [
2357
+ ma,
2358
+ ha,
2359
+ ga,
2360
+ _a,
2361
+ va,
2362
+ fa,
2363
+ pa
2364
+ ].forEach((o) => {
2365
+ this._commandService.registerCommand(o);
2366
+ }), this._injector.get(Q), this._injector.get(we), this._injector.get(Ce), this._injector.get(Ee), this._injector.get(Fe);
2367
+ }
2368
+ onReady() {
2369
+ this._injector.get(Ne);
2370
+ }
2371
+ onRendered() {
2372
+ this._injector.get(Te);
2373
+ }
2374
+ };
2375
+ pt(Oe, "pluginName", Gt);
2376
+ pt(Oe, "type", N.UNIVER_SHEET);
2377
+ Oe = Wa([
2378
+ Ct(Lt),
2379
+ ke(1, v(qe)),
2380
+ ke(2, x),
2381
+ ke(3, wt)
2382
+ ], Oe);
2383
+ function Ka(o) {
2384
+ const e = o.get(nt).getCurrentSelections().map((i) => i.range);
2385
+ return {
2386
+ uid: V.generateRandomId(6),
2387
+ type: T.DECIMAL,
2388
+ operator: h.EQUAL,
2389
+ formula1: "100",
2390
+ ranges: e != null ? e : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
2391
+ };
2392
+ }
2393
+ export {
2394
+ ma as AddSheetDataValidationCommand,
2395
+ Ve as CHECKBOX_FORMULA_1,
2396
+ Me as CHECKBOX_FORMULA_2,
2397
+ aa as CheckboxValidator,
2398
+ pa as ClearRangeDataValidationCommand,
2399
+ Gt as DATA_VALIDATION_PLUGIN_NAME,
2400
+ Q as DataValidationCacheService,
2401
+ H as DataValidationCustomFormulaService,
2402
+ Te as DataValidationFormulaController,
2403
+ K as DataValidationFormulaService,
2404
+ sa as DateValidator,
2405
+ Ia as ListMultipleValidator,
2406
+ mt as ListValidator,
2407
+ fa as RemoveSheetAllDataValidationCommand,
2408
+ va as RemoveSheetDataValidationCommand,
2409
+ F as SheetDataValidationModel,
2410
+ we as SheetsDataValidationValidatorService,
2411
+ Oe as UniverSheetsDataValidationPlugin,
2412
+ _a as UpdateSheetDataValidationOptionsCommand,
2413
+ ha as UpdateSheetDataValidationRangeCommand,
2414
+ ga as UpdateSheetDataValidationSettingCommand,
2415
+ Ka as createDefaultNewRule,
2416
+ fe as deserializeListOptions,
2417
+ ne as getCellValueOrigin,
2418
+ Xa as getDataValidationCellValue,
2419
+ be as getDataValidationDiffMutations,
2420
+ _e as getFormulaCellData,
2421
+ oe as getFormulaResult,
2422
+ C as isLegalFormulaResult,
2423
+ Ya as serializeListOptions,
2424
+ pe as transformCheckboxValue
2425
+ };