@univerjs/data-validation 0.6.7 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +692 -0
  2. package/package.json +5 -5
package/lib/index.js ADDED
@@ -0,0 +1,692 @@
1
+ var k = Object.defineProperty;
2
+ var J = (t, e, r) => e in t ? k(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var c = (t, e, r) => J(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { Disposable as x, Tools as P, ILogService as N, IResourceManagerService as z, IUniverInstanceService as K, Inject as O, UniverInstanceType as G, toDisposable as Y, CommandType as g, ICommandService as T, IUndoRedoService as A, Plugin as X, merge as Z, Injector as $, IConfigService as ee, DataValidationOperator as s, LocaleService as te } from "@univerjs/core";
5
+ import { Subject as ae, debounceTime as re, BehaviorSubject as oe } 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 H(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 h = /* @__PURE__ */ ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(h || {}), ne = Object.getOwnPropertyDescriptor, ie = (t, e, r, a) => {
31
+ for (var o = a > 1 ? void 0 : a ? ne(e, r) : e, n = t.length - 1, i; n >= 0; n--)
32
+ (i = t[n]) && (o = i(o) || o);
33
+ return o;
34
+ }, se = (t, e) => (r, a) => e(r, a, t);
35
+ let p = class extends x {
36
+ constructor(e) {
37
+ super();
38
+ c(this, "_model", /* @__PURE__ */ new Map());
39
+ c(this, "_ruleChange$", new ae());
40
+ c(this, "ruleChange$", this._ruleChange$.asObservable());
41
+ c(this, "ruleChangeDebounce$", this.ruleChange$.pipe(re(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 h.RANGE: {
73
+ d.ranges = a.payload;
74
+ break;
75
+ }
76
+ case h.SETTING: {
77
+ Object.assign(d, q(a.payload));
78
+ break;
79
+ }
80
+ case h.OPTIONS: {
81
+ Object.assign(d, H(a.payload));
82
+ break;
83
+ }
84
+ case h.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 = P.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
+ p = ie([
174
+ se(0, N)
175
+ ], p);
176
+ var de = Object.getOwnPropertyDescriptor, le = (t, e, r, a) => {
177
+ for (var o = a > 1 ? void 0 : a ? de(e, r) : e, n = t.length - 1, i; n >= 0; n--)
178
+ (i = t[n]) && (o = i(o) || o);
179
+ return o;
180
+ }, y = (t, e) => (r, a) => e(r, a, t);
181
+ const ue = "SHEET_DATA_VALIDATION_PLUGIN";
182
+ let I = class extends x {
183
+ constructor(t, e, r) {
184
+ super(), this._resourceManagerService = t, this._univerInstanceService = e, this._dataValidationModel = r, this._initSnapshot();
185
+ }
186
+ _initSnapshot() {
187
+ const t = (r) => {
188
+ const a = this._dataValidationModel.getUnitRules(r), o = {};
189
+ return a ? (a.forEach(([n, i]) => {
190
+ o[n] = i;
191
+ }), JSON.stringify(o)) : "";
192
+ }, e = (r) => {
193
+ if (!r)
194
+ return {};
195
+ try {
196
+ return JSON.parse(r);
197
+ } catch {
198
+ return {};
199
+ }
200
+ };
201
+ this.disposeWithMe(
202
+ this._resourceManagerService.registerPluginResource({
203
+ pluginName: ue,
204
+ businesses: [G.UNIVER_SHEET],
205
+ toJson: (r) => t(r),
206
+ parseJson: (r) => e(r),
207
+ onUnLoad: (r) => {
208
+ this._dataValidationModel.deleteUnitRules(r);
209
+ },
210
+ onLoad: (r, a) => {
211
+ Object.keys(a).forEach((o) => {
212
+ a[o].forEach((i) => {
213
+ this._dataValidationModel.addRule(r, o, i, "patched");
214
+ });
215
+ });
216
+ }
217
+ })
218
+ );
219
+ }
220
+ };
221
+ I = le([
222
+ y(0, z),
223
+ y(1, K),
224
+ y(2, O(p))
225
+ ], I);
226
+ var ce = /* @__PURE__ */ ((t) => (t.SHEET = "sheet", t))(ce || {});
227
+ class Q {
228
+ constructor() {
229
+ c(this, "_validatorByScopes", /* @__PURE__ */ new Map());
230
+ c(this, "_validatorMap", /* @__PURE__ */ new Map());
231
+ c(this, "_validatorsChange$", new oe(void 0));
232
+ c(this, "validatorsChange$", this._validatorsChange$.asObservable());
233
+ }
234
+ _addValidatorToScope(e, r) {
235
+ this._validatorByScopes.has(r) || this._validatorByScopes.set(r, []);
236
+ const a = this._validatorByScopes.get(r);
237
+ if (a.findIndex((o) => o.id === e.id) > -1)
238
+ throw new Error(`Validator item with the same id ${e.id} has already been added!`);
239
+ a.push(e);
240
+ }
241
+ _removeValidatorFromScope(e, r) {
242
+ const a = this._validatorByScopes.get(r);
243
+ if (!a)
244
+ return;
245
+ const o = a.findIndex((n) => n.id === e.id);
246
+ o > -1 && a.splice(o, 1);
247
+ }
248
+ register(e) {
249
+ return this._validatorMap.set(e.id, e), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
250
+ this._addValidatorToScope(e, r);
251
+ }) : this._addValidatorToScope(e, e.scopes), this._validatorsChange$.next(), Y(() => {
252
+ this._validatorMap.delete(e.id), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
253
+ this._removeValidatorFromScope(e, r);
254
+ }) : this._removeValidatorFromScope(e, e.scopes), this._validatorsChange$.next();
255
+ });
256
+ }
257
+ getValidatorItem(e) {
258
+ return this._validatorMap.get(e);
259
+ }
260
+ getValidatorsByScope(e) {
261
+ return this._validatorByScopes.get(e);
262
+ }
263
+ }
264
+ const S = {
265
+ type: g.MUTATION,
266
+ id: "data-validation.mutation.addRule",
267
+ handler(t, e) {
268
+ if (!e)
269
+ return !1;
270
+ const { unitId: r, subUnitId: a, rule: o, index: n, source: i = "command" } = e;
271
+ return t.get(p).addRule(r, a, o, i, n), !0;
272
+ }
273
+ }, f = {
274
+ type: g.MUTATION,
275
+ id: "data-validation.mutation.removeRule",
276
+ handler(t, e) {
277
+ if (!e)
278
+ return !1;
279
+ const { unitId: r, subUnitId: a, ruleId: o, source: n = "command" } = e, i = t.get(p);
280
+ return Array.isArray(o) ? o.forEach((l) => {
281
+ i.removeRule(r, a, l, n);
282
+ }) : i.removeRule(r, a, o, n), !0;
283
+ }
284
+ }, v = {
285
+ type: g.MUTATION,
286
+ id: "data-validation.mutation.updateRule",
287
+ handler(t, e) {
288
+ if (!e)
289
+ return !1;
290
+ const { unitId: r, subUnitId: a, ruleId: o, payload: n, source: i = "command" } = e;
291
+ return t.get(p).updateRule(r, a, o, n, i), !0;
292
+ }
293
+ }, me = {
294
+ type: g.COMMAND,
295
+ id: "data-validation.command.addRule",
296
+ async handler(t, e) {
297
+ if (t.get(N).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
298
+ return !1;
299
+ const { rule: a, unitId: o, subUnitId: n } = e, i = t.get(T), l = t.get(A), d = {
300
+ ...e,
301
+ rule: {
302
+ ...e.rule,
303
+ ranges: [e.rule.range]
304
+ }
305
+ }, u = [{
306
+ id: S.id,
307
+ params: d
308
+ }], m = [{
309
+ id: f.id,
310
+ params: {
311
+ unitId: o,
312
+ subUnitId: n,
313
+ ruleId: a.uid
314
+ }
315
+ }];
316
+ return l.pushUndoRedo({
317
+ unitID: o,
318
+ redoMutations: u,
319
+ undoMutations: m
320
+ }), await i.executeCommand(S.id, d), !0;
321
+ }
322
+ }, pe = {
323
+ type: g.COMMAND,
324
+ id: "data-validation.command.removeRule",
325
+ handler(t, e) {
326
+ if (t.get(N).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
327
+ return !1;
328
+ const { unitId: a, subUnitId: o, ruleId: n } = e, i = t.get(T), l = t.get(A), d = t.get(p), u = [{
329
+ id: f.id,
330
+ params: e
331
+ }], m = [{
332
+ id: S.id,
333
+ params: {
334
+ unitId: a,
335
+ subUnitId: o,
336
+ rule: {
337
+ ...d.getRuleById(a, o, n)
338
+ },
339
+ index: d.getRuleIndex(a, o, n)
340
+ }
341
+ }];
342
+ return l.pushUndoRedo({
343
+ undoMutations: m,
344
+ redoMutations: u,
345
+ unitID: e.unitId
346
+ }), i.executeCommand(f.id, e), !0;
347
+ }
348
+ }, he = {
349
+ type: g.COMMAND,
350
+ id: "data-validation.command.updateDataValidationSetting",
351
+ handler(t, e) {
352
+ if (t.get(N).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
353
+ return !1;
354
+ const a = t.get(T), o = t.get(A), n = t.get(p), { unitId: i, subUnitId: l, ruleId: d, options: u } = e, m = n.getRuleById(i, l, d);
355
+ if (!m)
356
+ return !1;
357
+ const _ = {
358
+ unitId: i,
359
+ subUnitId: l,
360
+ ruleId: d,
361
+ payload: {
362
+ type: h.OPTIONS,
363
+ payload: u
364
+ }
365
+ }, E = [{
366
+ id: v.id,
367
+ params: _
368
+ }], M = {
369
+ unitId: i,
370
+ subUnitId: l,
371
+ ruleId: d,
372
+ payload: {
373
+ type: h.OPTIONS,
374
+ payload: H(m)
375
+ }
376
+ }, R = [{
377
+ id: v.id,
378
+ params: M
379
+ }];
380
+ return o.pushUndoRedo({
381
+ unitID: i,
382
+ redoMutations: E,
383
+ undoMutations: R
384
+ }), a.executeCommand(v.id, _), !0;
385
+ }
386
+ }, _e = {
387
+ type: g.COMMAND,
388
+ id: "data-validation.command.updateDataValidationOptions",
389
+ handler(t, e) {
390
+ if (t.get(N).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
391
+ return !1;
392
+ const a = t.get(T), o = t.get(A), n = t.get(p), i = t.get(Q), { unitId: l, subUnitId: d, ruleId: u, setting: m } = e, _ = i.getValidatorItem(m.type);
393
+ if (!_)
394
+ return !1;
395
+ const E = n.getRuleById(l, d, u);
396
+ if (!E)
397
+ return !1;
398
+ const M = { ...E, ...m };
399
+ if (!_.validatorFormula(M, l, d).success)
400
+ return !1;
401
+ const R = {
402
+ unitId: l,
403
+ subUnitId: d,
404
+ ruleId: u,
405
+ payload: {
406
+ type: h.SETTING,
407
+ payload: {
408
+ ...m,
409
+ ..._.normalizeFormula(M, l, d)
410
+ }
411
+ }
412
+ }, j = [{
413
+ id: v.id,
414
+ params: R
415
+ }], F = {
416
+ unitId: l,
417
+ subUnitId: d,
418
+ ruleId: u,
419
+ payload: {
420
+ type: h.SETTING,
421
+ payload: q(E)
422
+ }
423
+ }, W = [{
424
+ id: v.id,
425
+ params: F
426
+ }];
427
+ return o.pushUndoRedo({
428
+ unitID: l,
429
+ redoMutations: j,
430
+ undoMutations: W
431
+ }), a.executeCommand(v.id, R), !0;
432
+ }
433
+ }, ge = {
434
+ type: g.COMMAND,
435
+ id: "data-validation.command.removeAll",
436
+ handler(t, e) {
437
+ if (t.get(N).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
438
+ return !1;
439
+ const { unitId: a, subUnitId: o } = e, n = t.get(T), i = t.get(p), l = t.get(A), d = [...i.getRules(a, o)], u = {
440
+ unitId: a,
441
+ subUnitId: o,
442
+ ruleId: d.map((E) => E.uid)
443
+ }, m = [{
444
+ id: f.id,
445
+ params: u
446
+ }], _ = [{
447
+ id: S.id,
448
+ params: {
449
+ unitId: a,
450
+ subUnitId: o,
451
+ rule: d
452
+ }
453
+ }];
454
+ return l.pushUndoRedo({
455
+ redoMutations: m,
456
+ undoMutations: _,
457
+ unitID: a
458
+ }), n.executeCommand(f.id, u), !0;
459
+ }
460
+ }, Ee = "data-validation.config", U = {};
461
+ var ve = Object.getOwnPropertyDescriptor, fe = (t, e, r, a) => {
462
+ for (var o = a > 1 ? void 0 : a ? ve(e, r) : e, n = t.length - 1, i; n >= 0; n--)
463
+ (i = t[n]) && (o = i(o) || o);
464
+ return o;
465
+ }, L = (t, e) => (r, a) => e(r, a, t);
466
+ const Ne = "UNIVER_DATA_VALIDATION_PLUGIN";
467
+ var V;
468
+ let D = (V = class extends X {
469
+ constructor(t = U, e, r, a) {
470
+ super(), this._config = t, this._injector = e, this._commandService = r, this._configService = a;
471
+ const { ...o } = Z(
472
+ {},
473
+ U,
474
+ this._config
475
+ );
476
+ this._configService.setConfig(Ee, o);
477
+ }
478
+ onStarting() {
479
+ [
480
+ [p],
481
+ [Q],
482
+ [I]
483
+ ].forEach((t) => this._injector.add(t)), [
484
+ // command
485
+ me,
486
+ ge,
487
+ he,
488
+ _e,
489
+ pe,
490
+ // mutation
491
+ S,
492
+ v,
493
+ f
494
+ ].forEach((t) => {
495
+ this._commandService.registerCommand(t);
496
+ });
497
+ }
498
+ onReady() {
499
+ this._injector.get(I);
500
+ }
501
+ }, c(V, "pluginName", Ne), c(V, "type", G.UNIVER_SHEET), V);
502
+ D = fe([
503
+ L(1, O($)),
504
+ L(2, T),
505
+ L(3, ee)
506
+ ], D);
507
+ 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 + "";
508
+ const Te = {
509
+ [s.BETWEEN]: "dataValidation.ruleName.between",
510
+ [s.EQUAL]: "dataValidation.ruleName.equal",
511
+ [s.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
512
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
513
+ [s.LESS_THAN]: "dataValidation.ruleName.lessThan",
514
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
515
+ [s.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
516
+ [s.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
517
+ }, Se = {
518
+ [s.BETWEEN]: "dataValidation.errorMsg.between",
519
+ [s.EQUAL]: "dataValidation.errorMsg.equal",
520
+ [s.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
521
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
522
+ [s.LESS_THAN]: "dataValidation.errorMsg.lessThan",
523
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
524
+ [s.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
525
+ [s.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
526
+ }, ye = {
527
+ [s.BETWEEN]: "dataValidation.textLength.errorMsg.between",
528
+ [s.EQUAL]: "dataValidation.textLength.errorMsg.equal",
529
+ [s.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan",
530
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.greaterThanOrEqual",
531
+ [s.LESS_THAN]: "dataValidation.textLength.errorMsg.lessThan",
532
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
533
+ [s.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
534
+ [s.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
535
+ }, Le = [
536
+ s.BETWEEN,
537
+ s.NOT_BETWEEN
538
+ ];
539
+ var Ae = Object.getOwnPropertyDescriptor, Me = (t, e, r, a) => {
540
+ for (var o = a > 1 ? void 0 : a ? Ae(e, r) : e, n = t.length - 1, i; n >= 0; n--)
541
+ (i = t[n]) && (o = i(o) || o);
542
+ return o;
543
+ }, w = (t, e) => (r, a) => e(r, a, t);
544
+ const b = "{FORMULA1}", C = "{FORMULA2}", Re = {
545
+ [s.BETWEEN]: "dataValidation.operators.between",
546
+ [s.EQUAL]: "dataValidation.operators.equal",
547
+ [s.GREATER_THAN]: "dataValidation.operators.greaterThan",
548
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
549
+ [s.LESS_THAN]: "dataValidation.operators.lessThan",
550
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
551
+ [s.NOT_BETWEEN]: "dataValidation.operators.notBetween",
552
+ [s.NOT_EQUAL]: "dataValidation.operators.notEqual"
553
+ };
554
+ let B = class {
555
+ // #endregion
556
+ constructor(t, e) {
557
+ c(this, "offsetFormulaByRange", !0);
558
+ // #region UI related
559
+ c(this, "formulaInput");
560
+ c(this, "canvasRender", null);
561
+ c(this, "dropdown");
562
+ c(this, "optionsInput");
563
+ c(this, "skipDefaultFontRender");
564
+ this.localeService = t, this.injector = e;
565
+ }
566
+ get operatorNames() {
567
+ return this.operators.map((t) => this.localeService.t(Re[t]));
568
+ }
569
+ get titleStr() {
570
+ return this.localeService.t(this.title);
571
+ }
572
+ generateRuleName(t) {
573
+ var r, a;
574
+ if (!t.operator)
575
+ return this.titleStr;
576
+ const e = this.localeService.t(Te[t.operator]).replace(b, (r = t.formula1) != null ? r : "").replace(C, (a = t.formula2) != null ? a : "");
577
+ return `${this.titleStr} ${e}`;
578
+ }
579
+ generateRuleErrorMessage(t, e) {
580
+ var a, o;
581
+ return t.operator ? `${this.localeService.t(Se[t.operator]).replace(b, (a = t.formula1) != null ? a : "").replace(C, (o = t.formula2) != null ? o : "")}` : this.titleStr;
582
+ }
583
+ getExtraStyle(t, e, r, a, o) {
584
+ }
585
+ getRuleFinalError(t, e) {
586
+ return t.showErrorMessage && t.error ? t.error : this.generateRuleErrorMessage(t, e);
587
+ }
588
+ isEmptyCellValue(t) {
589
+ return t === "" || t === void 0 || t === null;
590
+ }
591
+ normalizeFormula(t, e, r) {
592
+ return {
593
+ formula1: t.formula1,
594
+ formula2: t.formula2
595
+ };
596
+ }
597
+ async isValidType(t, e, r) {
598
+ return !0;
599
+ }
600
+ transform(t, e, r) {
601
+ return t;
602
+ }
603
+ async validatorIsEqual(t, e, r) {
604
+ const { formula1: a } = e, { value: o } = t;
605
+ return Number.isNaN(a) ? !0 : o === a;
606
+ }
607
+ async validatorIsNotEqual(t, e, r) {
608
+ const { formula1: a } = e;
609
+ return Number.isNaN(a) ? !0 : t.value !== a;
610
+ }
611
+ async validatorIsBetween(t, e, r) {
612
+ const { formula1: a, formula2: o } = e;
613
+ if (Number.isNaN(a) || Number.isNaN(o))
614
+ return !0;
615
+ const n = Math.min(a, o), i = Math.max(a, o);
616
+ return t.value >= n && t.value <= i;
617
+ }
618
+ async validatorIsNotBetween(t, e, r) {
619
+ const { formula1: a, formula2: o } = e;
620
+ if (Number.isNaN(a) || Number.isNaN(o))
621
+ return !0;
622
+ const n = Math.min(a, o), i = Math.max(a, o);
623
+ return t.value < n || t.value > i;
624
+ }
625
+ async validatorIsGreaterThan(t, e, r) {
626
+ const { formula1: a } = e;
627
+ return Number.isNaN(a) ? !0 : t.value > a;
628
+ }
629
+ async validatorIsGreaterThanOrEqual(t, e, r) {
630
+ const { formula1: a } = e;
631
+ return Number.isNaN(a) ? !0 : t.value >= a;
632
+ }
633
+ async validatorIsLessThan(t, e, r) {
634
+ const { formula1: a } = e;
635
+ return Number.isNaN(a) ? !0 : t.value < a;
636
+ }
637
+ async validatorIsLessThanOrEqual(t, e, r) {
638
+ const { formula1: a } = e;
639
+ return Number.isNaN(a) ? !0 : t.value <= a;
640
+ }
641
+ async validator(t, e) {
642
+ const { value: r, unitId: a, subUnitId: o } = t, n = this.isEmptyCellValue(r), { allowBlank: i = !0, operator: l } = e;
643
+ if (n)
644
+ return i;
645
+ const d = await this.parseFormula(e, a, o, t.row, t.column);
646
+ if (!d.isFormulaValid || !await this.isValidType(t, d, e))
647
+ return !1;
648
+ if (!P.isDefine(l))
649
+ return !0;
650
+ const u = this.transform(t, d, e);
651
+ switch (l) {
652
+ case s.BETWEEN:
653
+ return this.validatorIsBetween(u, d, e);
654
+ case s.EQUAL:
655
+ return this.validatorIsEqual(u, d, e);
656
+ case s.GREATER_THAN:
657
+ return this.validatorIsGreaterThan(u, d, e);
658
+ case s.GREATER_THAN_OR_EQUAL:
659
+ return this.validatorIsGreaterThanOrEqual(u, d, e);
660
+ case s.LESS_THAN:
661
+ return this.validatorIsLessThan(u, d, e);
662
+ case s.LESS_THAN_OR_EQUAL:
663
+ return this.validatorIsLessThanOrEqual(u, d, e);
664
+ case s.NOT_BETWEEN:
665
+ return this.validatorIsNotBetween(u, d, e);
666
+ case s.NOT_EQUAL:
667
+ return this.validatorIsNotEqual(u, d, e);
668
+ default:
669
+ throw new Error("Unknown operator.");
670
+ }
671
+ }
672
+ };
673
+ B = Me([
674
+ w(0, O(te)),
675
+ w(1, O($))
676
+ ], B);
677
+ export {
678
+ S as AddDataValidationMutation,
679
+ B as BaseDataValidator,
680
+ p as DataValidationModel,
681
+ I as DataValidationResourceController,
682
+ ce as DataValidatorRegistryScope,
683
+ Q as DataValidatorRegistryService,
684
+ f as RemoveDataValidationMutation,
685
+ Le as TWO_FORMULA_OPERATOR_COUNT,
686
+ ye as TextLengthErrorTitleMap,
687
+ D as UniverDataValidationPlugin,
688
+ v as UpdateDataValidationMutation,
689
+ h as UpdateRuleType,
690
+ H as getRuleOptions,
691
+ q as getRuleSetting
692
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/data-validation",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "private": false,
5
5
  "description": "Data validation library for Univer",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,7 +48,7 @@
48
48
  "rxjs": ">=7.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@univerjs/core": "0.6.7"
51
+ "@univerjs/core": "0.6.9"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@univerjs/protocol": "0.1.45",
@@ -56,9 +56,9 @@
56
56
  "typescript": "^5.8.2",
57
57
  "vite": "^6.2.3",
58
58
  "vitest": "^3.0.9",
59
- "@univerjs-infra/shared": "0.6.7",
60
- "@univerjs/core": "0.6.7",
61
- "@univerjs/sheets": "0.6.7"
59
+ "@univerjs-infra/shared": "0.6.9",
60
+ "@univerjs/core": "0.6.9",
61
+ "@univerjs/sheets": "0.6.9"
62
62
  },
63
63
  "scripts": {
64
64
  "dev": "vite",