@univerjs/sheets-data-validation 0.5.1 → 0.5.2

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/facade.js CHANGED
@@ -1,17 +1,17 @@
1
- var T = Object.defineProperty;
2
- var A = (s, e, t) => e in s ? T(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var l = (s, e, t) => A(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { FRange as g, FWorkbook as S, FWorksheet as I } from "@univerjs/sheets/facade";
5
- import { UpdateSheetDataValidationSettingCommand as E, UpdateSheetDataValidationOptionsCommand as k, UpdateSheetDataValidationRangeCommand as D, RemoveSheetDataValidationCommand as b, ClearRangeDataValidationCommand as C, AddSheetDataValidationCommand as v, SheetsDataValidationValidatorService as u, SheetDataValidationModel as U, RemoveSheetAllDataValidationCommand as y } from "@univerjs/sheets-data-validation";
6
- import { generateRandomId as f, DataValidationType as r, DataValidationErrorStyle as d, DataValidationOperator as o, ICommandService as h, FUniver as L, toDisposable as n } from "@univerjs/core";
7
- import { DataValidationModel as w, getRuleOptions as O } from "@univerjs/data-validation";
8
- import { serializeRangeToRefString as R } from "@univerjs/engine-formula";
1
+ var w = Object.defineProperty;
2
+ var V = (s, e, t) => e in s ? w(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var u = (s, e, t) => V(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { UpdateSheetDataValidationSettingCommand as f, UpdateSheetDataValidationOptionsCommand as S, UpdateSheetDataValidationRangeCommand as I, RemoveSheetDataValidationCommand as E, ClearRangeDataValidationCommand as U, AddSheetDataValidationCommand as D, SheetsDataValidationValidatorService as l, SheetDataValidationModel as T, RemoveSheetAllDataValidationCommand as A } from "@univerjs/sheets-data-validation";
5
+ import { FRange as c, FWorkbook as k, FWorksheet as v } from "@univerjs/sheets/facade";
6
+ import { generateRandomId as g, DataValidationType as r, DataValidationErrorStyle as _, DataValidationOperator as o, IUniverInstanceService as C, ICommandService as d, FUniver as y, toDisposable as n } from "@univerjs/core";
7
+ import { DataValidationModel as b, getRuleOptions as L } from "@univerjs/data-validation";
8
+ import { serializeRangeToRefString as O } from "@univerjs/engine-formula";
9
9
  import { filter as p } from "rxjs";
10
- class m {
10
+ class h {
11
11
  constructor(e) {
12
- l(this, "_rule");
12
+ u(this, "_rule");
13
13
  this._rule = e != null ? e : {
14
- uid: f(),
14
+ uid: g(),
15
15
  ranges: void 0,
16
16
  type: r.CUSTOM
17
17
  };
@@ -22,7 +22,7 @@ class m {
22
22
  * @returns {FDataValidation} A new instance of the FDataValidation class
23
23
  */
24
24
  build() {
25
- return new _(this._rule);
25
+ return new m(this._rule);
26
26
  }
27
27
  /**
28
28
  * Creates a duplicate of the current DataValidationBuilder object
@@ -30,9 +30,9 @@ class m {
30
30
  * @return {FDataValidationBuilder} A new instance of the DataValidationBuilder class
31
31
  */
32
32
  copy() {
33
- return new m({
33
+ return new h({
34
34
  ...this._rule,
35
- uid: f()
35
+ uid: g()
36
36
  });
37
37
  }
38
38
  /**
@@ -41,7 +41,7 @@ class m {
41
41
  * @returns {boolean} True if invalid data is allowed, False otherwise
42
42
  */
43
43
  getAllowInvalid() {
44
- return this._rule.errorStyle !== d.STOP;
44
+ return this._rule.errorStyle !== _.STOP;
45
45
  }
46
46
  /**
47
47
  * Gets the data validation type of the rule
@@ -54,7 +54,7 @@ class m {
54
54
  /**
55
55
  * Gets the values used for criteria evaluation
56
56
  *
57
- * @returns {any[]} An array containing the operator, formula1, and formula2 values
57
+ * @returns {[string, string, string]} An array containing the operator, formula1, and formula2 values
58
58
  */
59
59
  getCriteriaValues() {
60
60
  return [this._rule.operator, this._rule.formula1, this._rule.formula2];
@@ -264,7 +264,7 @@ class m {
264
264
  * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
265
265
  */
266
266
  requireValueInRange(e, t, i) {
267
- return this._rule.type = t ? r.LIST_MULTIPLE : r.LIST, this._rule.formula1 = `=${R({
267
+ return this._rule.type = t ? r.LIST_MULTIPLE : r.LIST, this._rule.formula1 = `=${O({
268
268
  unitId: e.getUnitId(),
269
269
  sheetName: e.getSheetName(),
270
270
  range: e.getRange()
@@ -279,7 +279,7 @@ class m {
279
279
  * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
280
280
  */
281
281
  setAllowInvalid(e) {
282
- return this._rule.errorStyle = e ? d.WARNING : d.STOP, this;
282
+ return this._rule.errorStyle = e ? _.WARNING : _.STOP, this;
283
283
  }
284
284
  /**
285
285
  * Sets the help text and enables the display of error messages for data validation.
@@ -315,11 +315,12 @@ class m {
315
315
  return Object.assign(this._rule, e), this;
316
316
  }
317
317
  }
318
- class _ {
319
- constructor(e, t) {
320
- l(this, "rule");
321
- l(this, "_worksheet");
322
- this.rule = e, this._worksheet = t;
318
+ class m {
319
+ constructor(e, t, i) {
320
+ u(this, "rule");
321
+ u(this, "_worksheet");
322
+ u(this, "_injector");
323
+ this._injector = i, this.rule = e, this._worksheet = t;
323
324
  }
324
325
  /**
325
326
  * Gets whether invalid data is allowed based on the error style value.
@@ -327,7 +328,7 @@ class _ {
327
328
  * @return true if invalid data is allowed, false otherwise.
328
329
  */
329
330
  getAllowInvalid() {
330
- return this.rule.errorStyle !== d.STOP;
331
+ return this.rule.errorStyle !== _.STOP;
331
332
  }
332
333
  /**
333
334
  * Gets the data validation type of the rule
@@ -360,7 +361,7 @@ class _ {
360
361
  * @return A new FDataValidationBuilder instance with the same rule configuration.
361
362
  */
362
363
  copy() {
363
- return new m(this.rule);
364
+ return new h(this.rule);
364
365
  }
365
366
  /**
366
367
  * Gets whether the data validation rule is applied to the worksheet.
@@ -370,7 +371,7 @@ class _ {
370
371
  getApplied() {
371
372
  if (!this._worksheet)
372
373
  return !1;
373
- const t = this._worksheet.getInject().get(w).getRuleById(this._worksheet.getWorkbook().getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
374
+ const t = this._injector.get(b).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
374
375
  return !!(t && t.ranges.length);
375
376
  }
376
377
  /**
@@ -379,17 +380,10 @@ class _ {
379
380
  * @returns An array of IRange objects representing the ranges to which the data validation rule is applied.
380
381
  */
381
382
  getRanges() {
382
- var a;
383
- if (!this.getAllowInvalid())
384
- return [];
385
- const e = (a = this._worksheet) == null ? void 0 : a.getWorkbook(), t = this.getSheetId();
386
- if (!t)
383
+ if (!this.getApplied())
387
384
  return [];
388
- const i = e == null ? void 0 : e.getSheetBySheetId(t);
389
- return !e || !i ? [] : this.rule.ranges.map((V) => {
390
- var c;
391
- return (c = this._worksheet) == null ? void 0 : c.getInject().createInstance(g, e, i, V);
392
- });
385
+ const e = this._injector.get(C).getUnit(this._worksheet.getUnitId());
386
+ return this.rule.ranges.map((t) => this._injector.createInstance(c, e, this._worksheet, t));
393
387
  }
394
388
  /**
395
389
  * Gets the title of the error message dialog box.
@@ -398,7 +392,7 @@ class _ {
398
392
  */
399
393
  getUnitId() {
400
394
  var e;
401
- return (e = this._worksheet) == null ? void 0 : e.getWorkbook().getUnitId();
395
+ return (e = this._worksheet) == null ? void 0 : e.getUnitId();
402
396
  }
403
397
  /**
404
398
  * Gets the sheetId of the worksheet.
@@ -416,7 +410,7 @@ class _ {
416
410
  * @returns true if the criteria is set successfully, false otherwise.
417
411
  */
418
412
  setCriteria(e, t) {
419
- return this.getApplied() && !this._worksheet.getInject().get(h).syncExecuteCommand(E.id, {
413
+ return this.getApplied() && !this._injector.get(d).syncExecuteCommand(f.id, {
420
414
  unitId: this.getUnitId(),
421
415
  subUnitId: this.getSheetId(),
422
416
  ruleId: this.rule.uid,
@@ -435,12 +429,12 @@ class _ {
435
429
  * @returns true if the options are set successfully, false otherwise.
436
430
  */
437
431
  setOptions(e) {
438
- return this.getApplied() && !this._worksheet.getInject().get(h).syncExecuteCommand(k.id, {
432
+ return this.getApplied() && !this._injector.get(d).syncExecuteCommand(S.id, {
439
433
  unitId: this.getUnitId(),
440
434
  subUnitId: this.getSheetId(),
441
435
  ruleId: this.rule.uid,
442
436
  options: {
443
- ...O(this.rule),
437
+ ...L(this.rule),
444
438
  ...e
445
439
  }
446
440
  }) ? !1 : (Object.assign(this.rule, e), !0);
@@ -451,29 +445,29 @@ class _ {
451
445
  * @returns true if the ranges are set successfully, false otherwise.
452
446
  */
453
447
  setRanges(e) {
454
- return this.getApplied() && !this._worksheet.getInject().get(h).syncExecuteCommand(D.id, {
448
+ return this.getApplied() && !this._injector.get(d).syncExecuteCommand(I.id, {
455
449
  unitId: this.getUnitId(),
456
450
  subUnitId: this.getSheetId(),
457
451
  ruleId: this.rule.uid,
458
452
  ranges: e.map((a) => a.getRange())
459
- }) ? !1 : (this.rule.ranges = e, !0);
453
+ }) ? !1 : (this.rule.ranges = e.map((t) => t.getRange()), !0);
460
454
  }
461
455
  /**
462
456
  * Delete the data validation rule from the worksheet.
463
457
  * @returns true if the rule is deleted successfully, false otherwise.
464
458
  */
465
459
  delete() {
466
- return this.getApplied() ? this._worksheet.getInject().get(h).syncExecuteCommand(b.id, {
460
+ return this.getApplied() ? this._injector.get(d).syncExecuteCommand(E.id, {
467
461
  unitId: this.getUnitId(),
468
462
  subUnitId: this.getSheetId(),
469
463
  ruleId: this.rule.uid
470
464
  }) : !1;
471
465
  }
472
466
  }
473
- class N extends g {
467
+ class R extends c {
474
468
  async setDataValidation(e) {
475
469
  if (!e)
476
- return this._commandService.executeCommand(C.id, {
470
+ return this._commandService.executeCommand(U.id, {
477
471
  unitId: this._workbook.getUnitId(),
478
472
  subUnitId: this._worksheet.getSheetId(),
479
473
  ranges: [this._range]
@@ -486,43 +480,49 @@ class N extends g {
486
480
  ranges: [this._range]
487
481
  }
488
482
  };
489
- return await this._commandService.executeCommand(v.id, t), this;
483
+ return await this._commandService.executeCommand(D.id, t), this;
490
484
  }
491
485
  getDataValidation() {
492
- const t = this._injector.get(u).getDataValidation(
486
+ const t = this._injector.get(l).getDataValidation(
493
487
  this._workbook.getUnitId(),
494
488
  this._worksheet.getSheetId(),
495
489
  [this._range]
496
490
  );
497
- return t && new _(t);
491
+ return t && new m(t, this._worksheet, this._injector);
498
492
  }
499
493
  getDataValidations() {
500
- return this._injector.get(u).getDataValidations(
494
+ return this._injector.get(l).getDataValidations(
501
495
  this._workbook.getUnitId(),
502
496
  this._worksheet.getSheetId(),
503
497
  [this._range]
504
- ).map((t) => new _(t));
498
+ ).map((t) => new m(t, this._worksheet, this._injector));
505
499
  }
506
500
  async getValidatorStatus() {
507
- return this._injector.get(u).validatorRanges(
501
+ return this._injector.get(l).validatorRanges(
508
502
  this._workbook.getUnitId(),
509
503
  this._worksheet.getSheetId(),
510
504
  [this._range]
511
505
  );
512
506
  }
513
507
  }
514
- g.extend(N);
515
- class x {
508
+ c.extend(R);
509
+ class N {
510
+ /**
511
+ * @deparecated use `univerAPI.newDataValidation()` as instead.
512
+ */
516
513
  static newDataValidation() {
517
- return new m();
514
+ return new h();
515
+ }
516
+ newDataValidation() {
517
+ return new h();
518
518
  }
519
519
  }
520
- L.extend(x);
521
- class M extends S {
520
+ y.extend(N);
521
+ class x extends k {
522
522
  _initialize() {
523
523
  Object.defineProperty(this, "_dataValidationModel", {
524
524
  get() {
525
- return this._injector.get(U);
525
+ return this._injector.get(T);
526
526
  }
527
527
  });
528
528
  }
@@ -531,7 +531,7 @@ class M extends S {
531
531
  * @returns matrix of validator status
532
532
  */
533
533
  getValidatorStatus() {
534
- return this._injector.get(u).validatorWorkbook(this._workbook.getUnitId());
534
+ return this._injector.get(l).validatorWorkbook(this._workbook.getUnitId());
535
535
  }
536
536
  // region DataValidationHooks
537
537
  /**
@@ -558,7 +558,7 @@ class M extends S {
558
558
  onBeforeAddDataValidation(e) {
559
559
  return n(this._commandService.beforeCommandExecuted((t, i) => {
560
560
  const a = t.params;
561
- if (t.id === v.id) {
561
+ if (t.id === D.id) {
562
562
  if (a.unitId !== this._workbook.getUnitId())
563
563
  return;
564
564
  if (e(a, i) === !1)
@@ -569,7 +569,7 @@ class M extends S {
569
569
  onBeforeUpdateDataValidationCriteria(e) {
570
570
  return n(this._commandService.beforeCommandExecuted((t, i) => {
571
571
  const a = t.params;
572
- if (t.id === E.id) {
572
+ if (t.id === f.id) {
573
573
  if (a.unitId !== this._workbook.getUnitId())
574
574
  return;
575
575
  if (e(a, i) === !1)
@@ -580,7 +580,7 @@ class M extends S {
580
580
  onBeforeUpdateDataValidationRange(e) {
581
581
  return n(this._commandService.beforeCommandExecuted((t, i) => {
582
582
  const a = t.params;
583
- if (t.id === D.id) {
583
+ if (t.id === I.id) {
584
584
  if (a.unitId !== this._workbook.getUnitId())
585
585
  return;
586
586
  if (e(a, i) === !1)
@@ -591,7 +591,7 @@ class M extends S {
591
591
  onBeforeUpdateDataValidationOptions(e) {
592
592
  return n(this._commandService.beforeCommandExecuted((t, i) => {
593
593
  const a = t.params;
594
- if (t.id === k.id) {
594
+ if (t.id === S.id) {
595
595
  if (a.unitId !== this._workbook.getUnitId())
596
596
  return;
597
597
  if (e(a, i) === !1)
@@ -602,7 +602,7 @@ class M extends S {
602
602
  onBeforeDeleteDataValidation(e) {
603
603
  return n(this._commandService.beforeCommandExecuted((t, i) => {
604
604
  const a = t.params;
605
- if (t.id === b.id) {
605
+ if (t.id === E.id) {
606
606
  if (a.unitId !== this._workbook.getUnitId())
607
607
  return;
608
608
  if (e(a, i) === !1)
@@ -613,7 +613,7 @@ class M extends S {
613
613
  onBeforeDeleteAllDataValidation(e) {
614
614
  return n(this._commandService.beforeCommandExecuted((t, i) => {
615
615
  const a = t.params;
616
- if (t.id === y.id) {
616
+ if (t.id === A.id) {
617
617
  if (a.unitId !== this._workbook.getUnitId())
618
618
  return;
619
619
  if (e(a, i) === !1)
@@ -622,20 +622,20 @@ class M extends S {
622
622
  }));
623
623
  }
624
624
  }
625
- S.extend(M);
626
- class B extends I {
625
+ k.extend(x);
626
+ class M extends v {
627
627
  getDataValidations() {
628
- return this._injector.get(w).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new _(t));
628
+ return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
629
629
  }
630
630
  getValidatorStatus() {
631
- return this._injector.get(u).validatorWorksheet(
631
+ return this._injector.get(l).validatorWorksheet(
632
632
  this._workbook.getUnitId(),
633
633
  this._worksheet.getSheetId()
634
634
  );
635
635
  }
636
636
  }
637
- I.extend(B);
637
+ v.extend(M);
638
638
  export {
639
- _ as FDataValidation,
640
- m as FDataValidationBuilder
639
+ m as FDataValidation,
640
+ h as FDataValidationBuilder
641
641
  };