@univerjs/data-validation 0.16.1 → 0.17.0-insiders.20260318-d69dc16

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/es/index.js CHANGED
@@ -1,700 +1 @@
1
- var z = Object.defineProperty;
2
- var Y = (t, e, r) => e in t ? z(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var c = (t, e, r) => Y(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { Disposable as $, Tools as K, ILogService as f, CommandType as g, IResourceManagerService as X, IUniverInstanceService as Z, Inject as V, UniverInstanceType as q, toDisposable as ee, ICommandService as T, IUndoRedoService as A, Plugin as te, merge as ae, Injector as H, IConfigService as re, DataValidationOperator as s, LocaleService as oe } from "@univerjs/core";
5
- import { Subject as ne, debounceTime as ie, BehaviorSubject as se } from "rxjs";
6
- function Q(t) {
7
- return {
8
- type: t.type,
9
- operator: t.operator,
10
- formula1: t.formula1,
11
- formula2: t.formula2,
12
- allowBlank: t.allowBlank
13
- };
14
- }
15
- function j(t) {
16
- return {
17
- error: t.error,
18
- errorStyle: t.errorStyle,
19
- errorTitle: t.errorTitle,
20
- imeMode: t.imeMode,
21
- prompt: t.prompt,
22
- promptTitle: t.promptTitle,
23
- showDropDown: t.showDropDown,
24
- showErrorMessage: t.showErrorMessage,
25
- showInputMessage: t.showInputMessage,
26
- renderMode: t.renderMode,
27
- bizInfo: t.bizInfo
28
- };
29
- }
30
- var p = /* @__PURE__ */ ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(p || {}), de = Object.getOwnPropertyDescriptor, le = (t, e, r, a) => {
31
- for (var o = a > 1 ? void 0 : a ? de(e, r) : e, n = t.length - 1, i; n >= 0; n--)
32
- (i = t[n]) && (o = i(o) || o);
33
- return o;
34
- }, ue = (t, e) => (r, a) => e(r, a, t);
35
- let h = class extends $ {
36
- constructor(e) {
37
- super();
38
- c(this, "_model", /* @__PURE__ */ new Map());
39
- c(this, "_ruleChange$", new ne());
40
- c(this, "ruleChange$", this._ruleChange$.asObservable());
41
- c(this, "ruleChangeDebounce$", this.ruleChange$.pipe(ie(20)));
42
- this._logService = e, this.disposeWithMe({
43
- dispose: () => {
44
- this._ruleChange$.complete();
45
- }
46
- });
47
- }
48
- _ensureMap(e, r) {
49
- this._model.has(e) || this._model.set(e, /* @__PURE__ */ new Map());
50
- const a = this._model.get(e);
51
- if (a.has(r))
52
- return a.get(r);
53
- const o = { map: /* @__PURE__ */ new Map(), list: [] };
54
- return a.set(r, o), o;
55
- }
56
- _addSubUnitRule(e, r, a) {
57
- const { map: o, list: n } = e, l = (Array.isArray(r) ? r : [r]).filter((d) => !o.has(d.uid));
58
- typeof a == "number" && a < n.length ? n.splice(a, 0, ...l) : n.push(...l), l.forEach((d) => {
59
- o.set(d.uid, d);
60
- });
61
- }
62
- _removeSubUnitRule(e, r) {
63
- const { map: a, list: o } = e, n = o.findIndex((i) => i.uid === r);
64
- n > -1 && (o.splice(n, 1), a.delete(r));
65
- }
66
- _updateSubUnitRule(e, r, a) {
67
- const { map: o, list: n } = e, i = o.get(r), l = n.findIndex((u) => r === u.uid);
68
- if (!i)
69
- throw new Error(`Data validation rule is not found, ruleId: ${r}.`);
70
- const d = { ...i };
71
- switch (a.type) {
72
- case p.RANGE: {
73
- d.ranges = a.payload;
74
- break;
75
- }
76
- case p.SETTING: {
77
- Object.assign(d, Q(a.payload));
78
- break;
79
- }
80
- case p.OPTIONS: {
81
- Object.assign(d, j(a.payload));
82
- break;
83
- }
84
- case p.ALL: {
85
- Object.assign(d, a.payload);
86
- break;
87
- }
88
- }
89
- return n[l] = d, o.set(r, d), d;
90
- }
91
- _addRuleSideEffect(e, r, a, o) {
92
- if (!this._ensureMap(e, r).map.get(a.uid))
93
- return {
94
- rule: a,
95
- type: "add",
96
- unitId: e,
97
- subUnitId: r,
98
- source: o
99
- };
100
- }
101
- addRule(e, r, a, o, n) {
102
- try {
103
- const i = this._ensureMap(e, r), d = (Array.isArray(a) ? a : [a]).map((u) => this._addRuleSideEffect(e, r, u, o));
104
- this._addSubUnitRule(i, a, n), d.forEach((u) => {
105
- u && this._ruleChange$.next(u);
106
- });
107
- } catch (i) {
108
- this._logService.error(i);
109
- }
110
- }
111
- updateRule(e, r, a, o, n) {
112
- try {
113
- const i = this._ensureMap(e, r), l = K.deepClone(i.map.get(a));
114
- if (!l)
115
- throw new Error(`Data validation rule is not found, ruleId: ${a}.`);
116
- const d = this._updateSubUnitRule(i, a, o);
117
- this._ruleChange$.next({
118
- rule: d,
119
- type: "update",
120
- unitId: e,
121
- subUnitId: r,
122
- source: n,
123
- updatePayload: o,
124
- oldRule: l
125
- });
126
- } catch (i) {
127
- this._logService.error(i);
128
- }
129
- }
130
- removeRule(e, r, a, o) {
131
- try {
132
- const n = this._ensureMap(e, r), i = n.map.get(a);
133
- i && (this._removeSubUnitRule(n, a), this._ruleChange$.next({
134
- rule: i,
135
- type: "remove",
136
- unitId: e,
137
- subUnitId: r,
138
- source: o
139
- }));
140
- } catch (n) {
141
- this._logService.error(n);
142
- }
143
- }
144
- getRuleById(e, r, a) {
145
- return this._ensureMap(e, r).map.get(a);
146
- }
147
- getRuleIndex(e, r, a) {
148
- return this._ensureMap(e, r).list.findIndex((n) => n.uid === a);
149
- }
150
- getRules(e, r) {
151
- return [...this._ensureMap(e, r).list];
152
- }
153
- getUnitRules(e) {
154
- const r = this._model.get(e);
155
- if (!r)
156
- return [];
157
- const a = [];
158
- return r.forEach((o, n) => {
159
- a.push([n, o.list]);
160
- }), a;
161
- }
162
- deleteUnitRules(e) {
163
- this._model.delete(e);
164
- }
165
- getSubUnitIds(e) {
166
- var r, a;
167
- return Array.from((a = (r = this._model.get(e)) == null ? void 0 : r.keys()) != null ? a : []);
168
- }
169
- getAll() {
170
- return Array.from(this._model.keys()).map((e) => [e, this.getUnitRules(e)]);
171
- }
172
- };
173
- h = le([
174
- ue(0, f)
175
- ], h);
176
- const S = {
177
- type: g.MUTATION,
178
- id: "data-validation.mutation.addRule",
179
- handler(t, e) {
180
- if (!e)
181
- return !1;
182
- const { unitId: r, subUnitId: a, rule: o, index: n, source: i = "command" } = e;
183
- return t.get(h).addRule(r, a, o, i, n), !0;
184
- }
185
- }, N = {
186
- type: g.MUTATION,
187
- id: "data-validation.mutation.removeRule",
188
- handler(t, e) {
189
- if (!e)
190
- return !1;
191
- const { unitId: r, subUnitId: a, ruleId: o, source: n = "command" } = e, i = t.get(h);
192
- return Array.isArray(o) ? o.forEach((l) => {
193
- i.removeRule(r, a, l, n);
194
- }) : i.removeRule(r, a, o, n), !0;
195
- }
196
- }, v = {
197
- type: g.MUTATION,
198
- id: "data-validation.mutation.updateRule",
199
- handler(t, e) {
200
- if (!e)
201
- return !1;
202
- const { unitId: r, subUnitId: a, ruleId: o, payload: n, source: i = "command" } = e;
203
- return t.get(h).updateRule(r, a, o, n, i), !0;
204
- }
205
- };
206
- var ce = Object.getOwnPropertyDescriptor, me = (t, e, r, a) => {
207
- for (var o = a > 1 ? void 0 : a ? ce(e, r) : e, n = t.length - 1, i; n >= 0; n--)
208
- (i = t[n]) && (o = i(o) || o);
209
- return o;
210
- }, L = (t, e) => (r, a) => e(r, a, t);
211
- const he = "SHEET_DATA_VALIDATION_PLUGIN";
212
- let I = class extends $ {
213
- constructor(t, e, r) {
214
- super(), this._resourceManagerService = t, this._univerInstanceService = e, this._dataValidationModel = r, this._initSnapshot();
215
- }
216
- _initSnapshot() {
217
- const t = (r) => {
218
- const a = this._dataValidationModel.getUnitRules(r), o = {};
219
- return a ? (a.forEach(([n, i]) => {
220
- o[n] = i;
221
- }), JSON.stringify(o)) : "";
222
- }, e = (r) => {
223
- if (!r)
224
- return {};
225
- try {
226
- return JSON.parse(r);
227
- } catch {
228
- return {};
229
- }
230
- };
231
- this.disposeWithMe(
232
- this._resourceManagerService.registerPluginResource({
233
- pluginName: he,
234
- businesses: [q.UNIVER_SHEET],
235
- toJson: (r) => t(r),
236
- parseJson: (r) => e(r),
237
- onUnLoad: (r) => {
238
- this._dataValidationModel.deleteUnitRules(r);
239
- },
240
- onLoad: (r, a) => {
241
- Object.keys(a).forEach((o) => {
242
- a[o].forEach((i) => {
243
- this._dataValidationModel.addRule(r, o, i, "patched");
244
- });
245
- });
246
- }
247
- })
248
- );
249
- }
250
- };
251
- I = me([
252
- L(0, X),
253
- L(1, Z),
254
- L(2, V(h))
255
- ], I);
256
- var pe = /* @__PURE__ */ ((t) => (t.SHEET = "sheet", t))(pe || {});
257
- class F {
258
- constructor() {
259
- c(this, "_validatorByScopes", /* @__PURE__ */ new Map());
260
- c(this, "_validatorMap", /* @__PURE__ */ new Map());
261
- c(this, "_validatorsChange$", new se(void 0));
262
- c(this, "validatorsChange$", this._validatorsChange$.asObservable());
263
- }
264
- _addValidatorToScope(e, r) {
265
- this._validatorByScopes.has(r) || this._validatorByScopes.set(r, []);
266
- const a = this._validatorByScopes.get(r);
267
- if (a.findIndex((o) => o.id === e.id) > -1)
268
- throw new Error(`Validator item with the same id ${e.id} has already been added!`);
269
- a.push(e);
270
- }
271
- _removeValidatorFromScope(e, r) {
272
- const a = this._validatorByScopes.get(r);
273
- if (!a)
274
- return;
275
- const o = a.findIndex((n) => n.id === e.id);
276
- o > -1 && a.splice(o, 1);
277
- }
278
- register(e) {
279
- return this._validatorMap.set(e.id, e), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
280
- this._addValidatorToScope(e, r);
281
- }) : this._addValidatorToScope(e, e.scopes), this._validatorsChange$.next(), ee(() => {
282
- this._validatorMap.delete(e.id), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
283
- this._removeValidatorFromScope(e, r);
284
- }) : this._removeValidatorFromScope(e, e.scopes), this._validatorsChange$.next();
285
- });
286
- }
287
- getValidatorItem(e) {
288
- return this._validatorMap.get(e);
289
- }
290
- getValidatorsByScope(e) {
291
- return this._validatorByScopes.get(e);
292
- }
293
- }
294
- const Ee = {
295
- type: g.COMMAND,
296
- id: "data-validation.command.addRule",
297
- async handler(t, e) {
298
- if (t.get(f).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
299
- return !1;
300
- const { rule: a, unitId: o, subUnitId: n } = e, i = t.get(T), l = t.get(A), d = {
301
- ...e,
302
- rule: {
303
- ...e.rule,
304
- ranges: [e.rule.range]
305
- }
306
- }, u = [{
307
- id: S.id,
308
- params: d
309
- }], m = [{
310
- id: N.id,
311
- params: {
312
- unitId: o,
313
- subUnitId: n,
314
- ruleId: a.uid
315
- }
316
- }];
317
- return l.pushUndoRedo({
318
- unitID: o,
319
- redoMutations: u,
320
- undoMutations: m
321
- }), await i.executeCommand(S.id, d), !0;
322
- }
323
- }, ge = {
324
- type: g.COMMAND,
325
- id: "data-validation.command.removeRule",
326
- handler(t, e) {
327
- if (t.get(f).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
328
- return !1;
329
- const { unitId: a, subUnitId: o, ruleId: n } = e, i = t.get(T), l = t.get(A), d = t.get(h), u = [{
330
- id: N.id,
331
- params: e
332
- }], m = [{
333
- id: S.id,
334
- params: {
335
- unitId: a,
336
- subUnitId: o,
337
- rule: {
338
- ...d.getRuleById(a, o, n)
339
- },
340
- index: d.getRuleIndex(a, o, n)
341
- }
342
- }];
343
- return l.pushUndoRedo({
344
- undoMutations: m,
345
- redoMutations: u,
346
- unitID: e.unitId
347
- }), i.executeCommand(N.id, e), !0;
348
- }
349
- }, _e = {
350
- type: g.COMMAND,
351
- id: "data-validation.command.updateDataValidationSetting",
352
- handler(t, e) {
353
- if (t.get(f).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
354
- return !1;
355
- const a = t.get(T), o = t.get(A), n = t.get(h), { unitId: i, subUnitId: l, ruleId: d, options: u } = e, m = n.getRuleById(i, l, d);
356
- if (!m)
357
- return !1;
358
- const E = {
359
- unitId: i,
360
- subUnitId: l,
361
- ruleId: d,
362
- payload: {
363
- type: p.OPTIONS,
364
- payload: u
365
- }
366
- }, _ = [{
367
- id: v.id,
368
- params: E
369
- }], M = {
370
- unitId: i,
371
- subUnitId: l,
372
- ruleId: d,
373
- payload: {
374
- type: p.OPTIONS,
375
- payload: j(m)
376
- }
377
- }, R = [{
378
- id: v.id,
379
- params: M
380
- }];
381
- return o.pushUndoRedo({
382
- unitID: i,
383
- redoMutations: _,
384
- undoMutations: R
385
- }), a.executeCommand(v.id, E), !0;
386
- }
387
- }, ve = {
388
- type: g.COMMAND,
389
- id: "data-validation.command.updateDataValidationOptions",
390
- handler(t, e) {
391
- if (t.get(f).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
392
- return !1;
393
- const a = t.get(T), o = t.get(A), n = t.get(h), i = t.get(F), { unitId: l, subUnitId: d, ruleId: u, setting: m } = e, E = i.getValidatorItem(m.type);
394
- if (!E)
395
- return !1;
396
- const _ = n.getRuleById(l, d, u);
397
- if (!_)
398
- return !1;
399
- const M = { ..._, ...m };
400
- if (!E.validatorFormula(M, l, d).success)
401
- return !1;
402
- const R = {
403
- unitId: l,
404
- subUnitId: d,
405
- ruleId: u,
406
- payload: {
407
- type: p.SETTING,
408
- payload: {
409
- ...m,
410
- ...E.normalizeFormula(M, l, d)
411
- }
412
- }
413
- }, W = [{
414
- id: v.id,
415
- params: R
416
- }], k = {
417
- unitId: l,
418
- subUnitId: d,
419
- ruleId: u,
420
- payload: {
421
- type: p.SETTING,
422
- payload: Q(_)
423
- }
424
- }, J = [{
425
- id: v.id,
426
- params: k
427
- }];
428
- return o.pushUndoRedo({
429
- unitID: l,
430
- redoMutations: W,
431
- undoMutations: J
432
- }), a.executeCommand(v.id, R), !0;
433
- }
434
- }, Ne = {
435
- type: g.COMMAND,
436
- id: "data-validation.command.removeAll",
437
- handler(t, e) {
438
- if (t.get(f).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
439
- return !1;
440
- const { unitId: a, subUnitId: o } = e, n = t.get(T), i = t.get(h), l = t.get(A), d = [...i.getRules(a, o)], u = {
441
- unitId: a,
442
- subUnitId: o,
443
- ruleId: d.map((_) => _.uid)
444
- }, m = [{
445
- id: N.id,
446
- params: u
447
- }], E = [{
448
- id: S.id,
449
- params: {
450
- unitId: a,
451
- subUnitId: o,
452
- rule: d
453
- }
454
- }];
455
- return l.pushUndoRedo({
456
- redoMutations: m,
457
- undoMutations: E,
458
- unitID: a
459
- }), n.executeCommand(N.id, u), !0;
460
- }
461
- }, fe = "data-validation.config", U = {};
462
- var Te = Object.getOwnPropertyDescriptor, Se = (t, e, r, a) => {
463
- for (var o = a > 1 ? void 0 : a ? Te(e, r) : e, n = t.length - 1, i; n >= 0; n--)
464
- (i = t[n]) && (o = i(o) || o);
465
- return o;
466
- }, y = (t, e) => (r, a) => e(r, a, t);
467
- const Ae = "UNIVER_DATA_VALIDATION_PLUGIN";
468
- var O;
469
- let C = (O = class extends te {
470
- constructor(t = U, e, r, a) {
471
- super(), this._config = t, this._injector = e, this._commandService = r, this._configService = a;
472
- const { ...o } = ae(
473
- {},
474
- U,
475
- this._config
476
- );
477
- this._configService.setConfig(fe, o);
478
- }
479
- onStarting() {
480
- [
481
- [h],
482
- [F],
483
- [I]
484
- ].forEach((t) => this._injector.add(t)), [
485
- // command
486
- Ee,
487
- Ne,
488
- _e,
489
- ve,
490
- ge,
491
- // mutation
492
- S,
493
- v,
494
- N
495
- ].forEach((t) => {
496
- this._commandService.registerCommand(t);
497
- });
498
- }
499
- onReady() {
500
- this._injector.get(I);
501
- }
502
- }, c(O, "pluginName", Ae), c(O, "type", q.UNIVER_SHEET), O);
503
- C = Se([
504
- y(1, V(H)),
505
- y(2, T),
506
- y(3, re)
507
- ], C);
508
- s.BETWEEN + "", s.EQUAL + "", s.GREATER_THAN + "", s.GREATER_THAN_OR_EQUAL + "", s.LESS_THAN + "", s.LESS_THAN_OR_EQUAL + "", s.NOT_BETWEEN + "", s.NOT_EQUAL + "";
509
- const D = {
510
- [s.BETWEEN]: "dataValidation.ruleName.between",
511
- [s.EQUAL]: "dataValidation.ruleName.equal",
512
- [s.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
513
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
514
- [s.LESS_THAN]: "dataValidation.ruleName.lessThan",
515
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
516
- [s.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
517
- [s.NOT_EQUAL]: "dataValidation.ruleName.notEqual",
518
- NONE: "dataValidation.ruleName.legal"
519
- }, b = {
520
- [s.BETWEEN]: "dataValidation.errorMsg.between",
521
- [s.EQUAL]: "dataValidation.errorMsg.equal",
522
- [s.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
523
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
524
- [s.LESS_THAN]: "dataValidation.errorMsg.lessThan",
525
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
526
- [s.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
527
- [s.NOT_EQUAL]: "dataValidation.errorMsg.notEqual",
528
- NONE: "dataValidation.errorMsg.legal"
529
- }, Ue = {
530
- [s.BETWEEN]: "dataValidation.textLength.errorMsg.between",
531
- [s.EQUAL]: "dataValidation.textLength.errorMsg.equal",
532
- [s.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan",
533
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.greaterThanOrEqual",
534
- [s.LESS_THAN]: "dataValidation.textLength.errorMsg.lessThan",
535
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
536
- [s.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
537
- [s.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
538
- }, Ce = [
539
- s.BETWEEN,
540
- s.NOT_BETWEEN
541
- ];
542
- var Me = Object.getOwnPropertyDescriptor, Re = (t, e, r, a) => {
543
- for (var o = a > 1 ? void 0 : a ? Me(e, r) : e, n = t.length - 1, i; n >= 0; n--)
544
- (i = t[n]) && (o = i(o) || o);
545
- return o;
546
- }, w = (t, e) => (r, a) => e(r, a, t);
547
- const B = "{FORMULA1}", x = "{FORMULA2}", P = "{TYPE}", Oe = {
548
- [s.BETWEEN]: "dataValidation.operators.between",
549
- [s.EQUAL]: "dataValidation.operators.equal",
550
- [s.GREATER_THAN]: "dataValidation.operators.greaterThan",
551
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
552
- [s.LESS_THAN]: "dataValidation.operators.lessThan",
553
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
554
- [s.NOT_BETWEEN]: "dataValidation.operators.notBetween",
555
- [s.NOT_EQUAL]: "dataValidation.operators.notEqual"
556
- };
557
- var Ve = /* @__PURE__ */ ((t) => (t.DATE = "date", t.TIME = "time", t.DATETIME = "datetime", t.LIST = "list", t.MULTIPLE_LIST = "multipleList", t.COLOR = "color", t.CASCADE = "cascade", t))(Ve || {});
558
- let G = class {
559
- // #endregion
560
- constructor(t, e) {
561
- c(this, "offsetFormulaByRange", !0);
562
- // #region UI related
563
- c(this, "formulaInput");
564
- c(this, "canvasRender", null);
565
- c(this, "dropdownType");
566
- c(this, "optionsInput");
567
- c(this, "skipDefaultFontRender");
568
- this.localeService = t, this.injector = e;
569
- }
570
- get operatorNames() {
571
- return this.operators.map((t) => this.localeService.t(Oe[t]));
572
- }
573
- get titleStr() {
574
- return this.localeService.t(this.title);
575
- }
576
- generateRuleName(t) {
577
- var r, a;
578
- if (!t.operator)
579
- return this.localeService.t(D.NONE).replace(P, this.titleStr);
580
- const e = this.localeService.t(D[t.operator]).replace(B, (r = t.formula1) != null ? r : "").replace(x, (a = t.formula2) != null ? a : "");
581
- return `${this.titleStr} ${e}`;
582
- }
583
- generateRuleErrorMessage(t, e) {
584
- var a, o;
585
- return t.operator ? `${this.localeService.t(b[t.operator]).replace(B, (a = t.formula1) != null ? a : "").replace(x, (o = t.formula2) != null ? o : "")}` : this.localeService.t(b.NONE).replace(P, this.titleStr);
586
- }
587
- getExtraStyle(t, e, r, a, o) {
588
- }
589
- getRuleFinalError(t, e) {
590
- return t.showErrorMessage && t.error ? t.error : this.generateRuleErrorMessage(t, e);
591
- }
592
- isEmptyCellValue(t) {
593
- return t === "" || t === void 0 || t === null;
594
- }
595
- normalizeFormula(t, e, r) {
596
- return {
597
- formula1: t.formula1,
598
- formula2: t.formula2
599
- };
600
- }
601
- async isValidType(t, e, r) {
602
- return !0;
603
- }
604
- transform(t, e, r) {
605
- return t;
606
- }
607
- async validatorIsEqual(t, e, r) {
608
- const { formula1: a } = e, { value: o } = t;
609
- return Number.isNaN(a) ? !0 : o === a;
610
- }
611
- async validatorIsNotEqual(t, e, r) {
612
- const { formula1: a } = e;
613
- return Number.isNaN(a) ? !0 : t.value !== a;
614
- }
615
- async validatorIsBetween(t, e, r) {
616
- const { formula1: a, formula2: o } = e;
617
- if (Number.isNaN(a) || Number.isNaN(o))
618
- return !0;
619
- const n = Math.min(a, o), i = Math.max(a, o);
620
- return t.value >= n && t.value <= i;
621
- }
622
- async validatorIsNotBetween(t, e, r) {
623
- const { formula1: a, formula2: o } = e;
624
- if (Number.isNaN(a) || Number.isNaN(o))
625
- return !0;
626
- const n = Math.min(a, o), i = Math.max(a, o);
627
- return t.value < n || t.value > i;
628
- }
629
- async validatorIsGreaterThan(t, e, r) {
630
- const { formula1: a } = e;
631
- return Number.isNaN(a) ? !0 : t.value > a;
632
- }
633
- async validatorIsGreaterThanOrEqual(t, e, r) {
634
- const { formula1: a } = e;
635
- return Number.isNaN(a) ? !0 : t.value >= a;
636
- }
637
- async validatorIsLessThan(t, e, r) {
638
- const { formula1: a } = e;
639
- return Number.isNaN(a) ? !0 : t.value < a;
640
- }
641
- async validatorIsLessThanOrEqual(t, e, r) {
642
- const { formula1: a } = e;
643
- return Number.isNaN(a) ? !0 : t.value <= a;
644
- }
645
- async validator(t, e) {
646
- const { value: r, unitId: a, subUnitId: o } = t, n = this.isEmptyCellValue(r), { allowBlank: i = !0, operator: l } = e;
647
- if (n)
648
- return i;
649
- const d = await this.parseFormula(e, a, o, t.row, t.column);
650
- if (!d.isFormulaValid || !await this.isValidType(t, d, e))
651
- return !1;
652
- if (!l)
653
- return !0;
654
- const u = this.transform(t, d, e);
655
- switch (l) {
656
- case s.BETWEEN:
657
- return this.validatorIsBetween(u, d, e);
658
- case s.EQUAL:
659
- return this.validatorIsEqual(u, d, e);
660
- case s.GREATER_THAN:
661
- return this.validatorIsGreaterThan(u, d, e);
662
- case s.GREATER_THAN_OR_EQUAL:
663
- return this.validatorIsGreaterThanOrEqual(u, d, e);
664
- case s.LESS_THAN:
665
- return this.validatorIsLessThan(u, d, e);
666
- case s.LESS_THAN_OR_EQUAL:
667
- return this.validatorIsLessThanOrEqual(u, d, e);
668
- case s.NOT_BETWEEN:
669
- return this.validatorIsNotBetween(u, d, e);
670
- case s.NOT_EQUAL:
671
- return this.validatorIsNotEqual(u, d, e);
672
- default:
673
- throw new Error("Unknown operator.");
674
- }
675
- }
676
- };
677
- G = Re([
678
- w(0, V(oe)),
679
- w(1, V(H))
680
- ], G);
681
- export {
682
- S as AddDataValidationMutation,
683
- G as BaseDataValidator,
684
- h as DataValidationModel,
685
- I as DataValidationResourceController,
686
- Ve as DataValidatorDropdownType,
687
- pe as DataValidatorRegistryScope,
688
- F as DataValidatorRegistryService,
689
- B as FORMULA1,
690
- x as FORMULA2,
691
- N as RemoveDataValidationMutation,
692
- Ce as TWO_FORMULA_OPERATOR_COUNT,
693
- P as TYPE,
694
- Ue as TextLengthErrorTitleMap,
695
- C as UniverDataValidationPlugin,
696
- v as UpdateDataValidationMutation,
697
- p as UpdateRuleType,
698
- j as getRuleOptions,
699
- Q as getRuleSetting
700
- };
1
+ import{CommandType as e,DataValidationOperator as t,Disposable as n,ICommandService as r,IConfigService as i,ILogService as a,IResourceManagerService as o,IUndoRedoService as s,IUniverInstanceService as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,Tools as p,UniverInstanceType as m,merge as h,toDisposable as g}from"@univerjs/core";import{BehaviorSubject as _,Subject as v,debounceTime as y}from"rxjs";function b(e){return{type:e.type,operator:e.operator,formula1:e.formula1,formula2:e.formula2,allowBlank:e.allowBlank}}function x(e){return{error:e.error,errorStyle:e.errorStyle,errorTitle:e.errorTitle,imeMode:e.imeMode,prompt:e.prompt,promptTitle:e.promptTitle,showDropDown:e.showDropDown,showErrorMessage:e.showErrorMessage,showInputMessage:e.showInputMessage,renderMode:e.renderMode,bizInfo:e.bizInfo}}let S=function(e){return e[e.SETTING=0]=`SETTING`,e[e.RANGE=1]=`RANGE`,e[e.OPTIONS=2]=`OPTIONS`,e[e.ALL=3]=`ALL`,e}({});function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){return function(n,r){t(n,r,e)}}function O(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let k=class extends n{constructor(e){super(),this._logService=e,E(this,`_model`,new Map),E(this,`_ruleChange$`,new v),E(this,`ruleChange$`,this._ruleChange$.asObservable()),E(this,`ruleChangeDebounce$`,this.ruleChange$.pipe(y(20))),this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,t){this._model.has(e)||this._model.set(e,new Map);let n=this._model.get(e);if(n.has(t))return n.get(t);let r={map:new Map,list:[]};return n.set(t,r),r}_addSubUnitRule(e,t,n){let{map:r,list:i}=e,a=(Array.isArray(t)?t:[t]).filter(e=>!r.has(e.uid));typeof n==`number`&&n<i.length?i.splice(n,0,...a):i.push(...a),a.forEach(e=>{r.set(e.uid,e)})}_removeSubUnitRule(e,t){let{map:n,list:r}=e,i=r.findIndex(e=>e.uid===t);i>-1&&(r.splice(i,1),n.delete(t))}_updateSubUnitRule(e,t,n){let{map:r,list:i}=e,a=r.get(t),o=i.findIndex(e=>t===e.uid);if(!a)throw Error(`Data validation rule is not found, ruleId: ${t}.`);let s={...a};switch(n.type){case S.RANGE:s.ranges=n.payload;break;case S.SETTING:Object.assign(s,b(n.payload));break;case S.OPTIONS:Object.assign(s,x(n.payload));break;case S.ALL:Object.assign(s,n.payload);break;default:break}return i[o]=s,r.set(t,s),s}_addRuleSideEffect(e,t,n,r){if(!this._ensureMap(e,t).map.get(n.uid))return{rule:n,type:`add`,unitId:e,subUnitId:t,source:r}}addRule(e,t,n,r,i){try{let a=this._ensureMap(e,t),o=(Array.isArray(n)?n:[n]).map(n=>this._addRuleSideEffect(e,t,n,r));this._addSubUnitRule(a,n,i),o.forEach(e=>{e&&this._ruleChange$.next(e)})}catch(e){this._logService.error(e)}}updateRule(e,t,n,r,i){try{let a=this._ensureMap(e,t),o=p.deepClone(a.map.get(n));if(!o)throw Error(`Data validation rule is not found, ruleId: ${n}.`);let s=this._updateSubUnitRule(a,n,r);this._ruleChange$.next({rule:s,type:`update`,unitId:e,subUnitId:t,source:i,updatePayload:r,oldRule:o})}catch(e){this._logService.error(e)}}removeRule(e,t,n,r){try{let i=this._ensureMap(e,t),a=i.map.get(n);a&&(this._removeSubUnitRule(i,n),this._ruleChange$.next({rule:a,type:`remove`,unitId:e,subUnitId:t,source:r}))}catch(e){this._logService.error(e)}}getRuleById(e,t,n){return this._ensureMap(e,t).map.get(n)}getRuleIndex(e,t,n){return this._ensureMap(e,t).list.findIndex(e=>e.uid===n)}getRules(e,t){return[...this._ensureMap(e,t).list]}getUnitRules(e){let t=this._model.get(e);if(!t)return[];let n=[];return t.forEach((e,t)=>{n.push([t,e.list])}),n}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var t,n;return Array.from((t=(n=this._model.get(e))==null?void 0:n.keys())==null?[]:t)}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};k=O([D(0,a)],k);const A={type:e.MUTATION,id:`data-validation.mutation.addRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,rule:i,index:a,source:o=`command`}=t;return e.get(k).addRule(n,r,i,o,a),!0}},j={type:e.MUTATION,id:`data-validation.mutation.removeRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,source:a=`command`}=t,o=e.get(k);return Array.isArray(i)?i.forEach(e=>{o.removeRule(n,r,e,a)}):o.removeRule(n,r,i,a),!0}},M={type:e.MUTATION,id:`data-validation.mutation.updateRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,payload:a,source:o=`command`}=t;return e.get(k).updateRule(n,r,i,a,o),!0}};let N=class extends n{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._dataValidationModel=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._dataValidationModel.getUnitRules(e),n={};return t?(t.forEach(([e,t])=>{n[e]=t}),JSON.stringify(n)):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_DATA_VALIDATION_PLUGIN`,businesses:[m.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>t(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(t=>{this._dataValidationModel.addRule(e,n,t,`patched`)})})}}))}};N=O([D(0,o),D(1,c),D(2,l(k))],N);var P=`@univerjs/data-validation`,F=`0.17.0-insiders.20260318-d69dc16`;let I=function(e){return e.SHEET=`sheet`,e}({});var L=class{constructor(){E(this,`_validatorByScopes`,new Map),E(this,`_validatorMap`,new Map),E(this,`_validatorsChange$`,new _(void 0)),E(this,`validatorsChange$`,this._validatorsChange$.asObservable())}_addValidatorToScope(e,t){this._validatorByScopes.has(t)||this._validatorByScopes.set(t,[]);let n=this._validatorByScopes.get(t);if(n.findIndex(t=>t.id===e.id)>-1)throw Error(`Validator item with the same id ${e.id} has already been added!`);n.push(e)}_removeValidatorFromScope(e,t){let n=this._validatorByScopes.get(t);if(!n)return;let r=n.findIndex(t=>t.id===e.id);r>-1&&n.splice(r,1)}register(e){return this._validatorMap.set(e.id,e),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._addValidatorToScope(e,t)}):this._addValidatorToScope(e,e.scopes),this._validatorsChange$.next(),g(()=>{this._validatorMap.delete(e.id),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._removeValidatorFromScope(e,t)}):this._removeValidatorFromScope(e,e.scopes),this._validatorsChange$.next()})}getValidatorItem(e){return this._validatorMap.get(e)}getValidatorsByScope(e){return this._validatorByScopes.get(e)}};const R={type:e.COMMAND,id:`data-validation.command.addRule`,async handler(e,t){if(e.get(a).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!t)return!1;let{rule:n,unitId:i,subUnitId:o}=t,c=e.get(r),l=e.get(s),u={...t,rule:{...t.rule,ranges:[t.rule.range]}},d=[{id:A.id,params:u}],f=[{id:j.id,params:{unitId:i,subUnitId:o,ruleId:n.uid}}];return l.pushUndoRedo({unitID:i,redoMutations:d,undoMutations:f}),await c.executeCommand(A.id,u),!0}},z={type:e.COMMAND,id:`data-validation.command.removeRule`,handler(e,t){if(e.get(a).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!t)return!1;let{unitId:n,subUnitId:i,ruleId:o}=t,c=e.get(r),l=e.get(s),u=e.get(k),d=[{id:j.id,params:t}],f=[{id:A.id,params:{unitId:n,subUnitId:i,rule:{...u.getRuleById(n,i,o)},index:u.getRuleIndex(n,i,o)}}];return l.pushUndoRedo({undoMutations:f,redoMutations:d,unitID:t.unitId}),c.executeCommand(j.id,t),!0}},B={type:e.COMMAND,id:`data-validation.command.updateDataValidationSetting`,handler(e,t){if(e.get(a).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!t)return!1;let n=e.get(r),i=e.get(s),o=e.get(k),{unitId:c,subUnitId:l,ruleId:u,options:d}=t,f=o.getRuleById(c,l,u);if(!f)return!1;let p={unitId:c,subUnitId:l,ruleId:u,payload:{type:S.OPTIONS,payload:d}},m=[{id:M.id,params:p}],h={unitId:c,subUnitId:l,ruleId:u,payload:{type:S.OPTIONS,payload:x(f)}},g=[{id:M.id,params:h}];return i.pushUndoRedo({unitID:c,redoMutations:m,undoMutations:g}),n.executeCommand(M.id,p),!0}},V={type:e.COMMAND,id:`data-validation.command.updateDataValidationOptions`,handler(e,t){if(e.get(a).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!t)return!1;let n=e.get(r),i=e.get(s),o=e.get(k),c=e.get(L),{unitId:l,subUnitId:u,ruleId:d,setting:f}=t,p=c.getValidatorItem(f.type);if(!p)return!1;let m=o.getRuleById(l,u,d);if(!m)return!1;let h={...m,...f};if(!p.validatorFormula(h,l,u).success)return!1;let g={unitId:l,subUnitId:u,ruleId:d,payload:{type:S.SETTING,payload:{...f,...p.normalizeFormula(h,l,u)}}},_=[{id:M.id,params:g}],v={unitId:l,subUnitId:u,ruleId:d,payload:{type:S.SETTING,payload:b(m)}},y=[{id:M.id,params:v}];return i.pushUndoRedo({unitID:l,redoMutations:_,undoMutations:y}),n.executeCommand(M.id,g),!0}},H={type:e.COMMAND,id:`data-validation.command.removeAll`,handler(e,t){if(e.get(a).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!t)return!1;let{unitId:n,subUnitId:i}=t,o=e.get(r),c=e.get(k),l=e.get(s),u=[...c.getRules(n,i)],d={unitId:n,subUnitId:i,ruleId:u.map(e=>e.uid)},f=[{id:j.id,params:d}],p=[{id:A.id,params:{unitId:n,subUnitId:i,rule:u}}];return l.pushUndoRedo({redoMutations:f,undoMutations:p,unitID:n}),o.executeCommand(j.id,d),!0}},U=`data-validation.config`;Symbol(U);const W={};let G=class extends f{constructor(e=W,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{...i}=h({},W,this._config);this._configService.setConfig(U,i)}onStarting(){[[k],[L],[N]].forEach(e=>this._injector.add(e)),[R,H,B,V,z,A,M,j].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(N)}};E(G,`pluginName`,`UNIVER_DATA_VALIDATION_PLUGIN`),E(G,`packageName`,P),E(G,`version`,F),E(G,`type`,m.UNIVER_SHEET),G=O([D(1,l(u)),D(2,r),D(3,i)],G),t.BETWEEN,t.EQUAL,t.GREATER_THAN,t.GREATER_THAN_OR_EQUAL,t.LESS_THAN,t.LESS_THAN_OR_EQUAL,t.NOT_BETWEEN,t.NOT_EQUAL;const K={[t.BETWEEN]:`dataValidation.ruleName.between`,[t.EQUAL]:`dataValidation.ruleName.equal`,[t.GREATER_THAN]:`dataValidation.ruleName.greaterThan`,[t.GREATER_THAN_OR_EQUAL]:`dataValidation.ruleName.greaterThanOrEqual`,[t.LESS_THAN]:`dataValidation.ruleName.lessThan`,[t.LESS_THAN_OR_EQUAL]:`dataValidation.ruleName.lessThanOrEqual`,[t.NOT_BETWEEN]:`dataValidation.ruleName.notBetween`,[t.NOT_EQUAL]:`dataValidation.ruleName.notEqual`,NONE:`dataValidation.ruleName.legal`},q={[t.BETWEEN]:`dataValidation.errorMsg.between`,[t.EQUAL]:`dataValidation.errorMsg.equal`,[t.GREATER_THAN]:`dataValidation.errorMsg.greaterThan`,[t.GREATER_THAN_OR_EQUAL]:`dataValidation.errorMsg.greaterThanOrEqual`,[t.LESS_THAN]:`dataValidation.errorMsg.lessThan`,[t.LESS_THAN_OR_EQUAL]:`dataValidation.errorMsg.lessThanOrEqual`,[t.NOT_BETWEEN]:`dataValidation.errorMsg.notBetween`,[t.NOT_EQUAL]:`dataValidation.errorMsg.notEqual`,NONE:`dataValidation.errorMsg.legal`},J={[t.BETWEEN]:`dataValidation.textLength.errorMsg.between`,[t.EQUAL]:`dataValidation.textLength.errorMsg.equal`,[t.GREATER_THAN]:`dataValidation.textLength.errorMsg.greaterThan`,[t.GREATER_THAN_OR_EQUAL]:`dataValidation.textLength.errorMsg.greaterThanOrEqual`,[t.LESS_THAN]:`dataValidation.textLength.errorMsg.lessThan`,[t.LESS_THAN_OR_EQUAL]:`dataValidation.textLength.errorMsg.lessThanOrEqual`,[t.NOT_BETWEEN]:`dataValidation.textLength.errorMsg.notBetween`,[t.NOT_EQUAL]:`dataValidation.textLength.errorMsg.notEqual`},Y=[t.BETWEEN,t.NOT_BETWEEN],X=`{FORMULA1}`,Z=`{FORMULA2}`,Q=`{TYPE}`,ee={[t.BETWEEN]:`dataValidation.operators.between`,[t.EQUAL]:`dataValidation.operators.equal`,[t.GREATER_THAN]:`dataValidation.operators.greaterThan`,[t.GREATER_THAN_OR_EQUAL]:`dataValidation.operators.greaterThanOrEqual`,[t.LESS_THAN]:`dataValidation.operators.lessThan`,[t.LESS_THAN_OR_EQUAL]:`dataValidation.operators.lessThanOrEqual`,[t.NOT_BETWEEN]:`dataValidation.operators.notBetween`,[t.NOT_EQUAL]:`dataValidation.operators.notEqual`};let te=function(e){return e.DATE=`date`,e.TIME=`time`,e.DATETIME=`datetime`,e.LIST=`list`,e.MULTIPLE_LIST=`multipleList`,e.COLOR=`color`,e.CASCADE=`cascade`,e}({}),$=class{constructor(e,t){this.localeService=e,this.injector=t,E(this,`offsetFormulaByRange`,!0),E(this,`formulaInput`,void 0),E(this,`canvasRender`,null),E(this,`dropdownType`,void 0),E(this,`optionsInput`,void 0),E(this,`skipDefaultFontRender`,void 0)}get operatorNames(){return this.operators.map(e=>this.localeService.t(ee[e]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(K.NONE).replace(Q,this.titleStr);let r=this.localeService.t(K[e.operator]).replace(X,(t=e.formula1)==null?``:t).replace(Z,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){var n,r;return e.operator?`${this.localeService.t(q[e.operator]).replace(X,(n=e.formula1)==null?``:n).replace(Z,(r=e.formula2)==null?``:r)}`:this.localeService.t(q.NONE).replace(Q,this.titleStr)}getExtraStyle(e,t,n,r,i){}getRuleFinalError(e,t){return e.showErrorMessage&&e.error?e.error:this.generateRuleErrorMessage(e,t)}isEmptyCellValue(e){return e===``||e==null}normalizeFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2}}async isValidType(e,t,n){return!0}transform(e,t,n){return e}async validatorIsEqual(e,t,n){let{formula1:r}=t,{value:i}=e;return Number.isNaN(r)?!0:i===r}async validatorIsNotEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value>=a&&e.value<=o}async validatorIsNotBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value<a||e.value>o}async validatorIsGreaterThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}async validator(e,n){let{value:r,unitId:i,subUnitId:a}=e,o=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:c}=n;if(o)return s;let l=await this.parseFormula(n,i,a,e.row,e.column);if(!l.isFormulaValid||!await this.isValidType(e,l,n))return!1;if(!c)return!0;let u=this.transform(e,l,n);switch(c){case t.BETWEEN:return this.validatorIsBetween(u,l,n);case t.EQUAL:return this.validatorIsEqual(u,l,n);case t.GREATER_THAN:return this.validatorIsGreaterThan(u,l,n);case t.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(u,l,n);case t.LESS_THAN:return this.validatorIsLessThan(u,l,n);case t.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(u,l,n);case t.NOT_BETWEEN:return this.validatorIsNotBetween(u,l,n);case t.NOT_EQUAL:return this.validatorIsNotEqual(u,l,n);default:throw Error(`Unknown operator.`)}}};$=O([D(0,l(d)),D(1,l(u))],$);export{A as AddDataValidationMutation,$ as BaseDataValidator,k as DataValidationModel,N as DataValidationResourceController,te as DataValidatorDropdownType,I as DataValidatorRegistryScope,L as DataValidatorRegistryService,X as FORMULA1,Z as FORMULA2,j as RemoveDataValidationMutation,Y as TWO_FORMULA_OPERATOR_COUNT,Q as TYPE,J as TextLengthErrorTitleMap,G as UniverDataValidationPlugin,M as UpdateDataValidationMutation,S as UpdateRuleType,x as getRuleOptions,b as getRuleSetting};