@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/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +71 -71
- package/lib/es/index.js +415 -400
- package/lib/types/facade/f-data-validation-builder.d.ts +2 -2
- package/lib/types/facade/f-data-validation.d.ts +5 -4
- package/lib/types/facade/f-univer.d.ts +4 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/es/facade.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { generateRandomId as
|
|
7
|
-
import { DataValidationModel as
|
|
8
|
-
import { serializeRangeToRefString as
|
|
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
|
|
10
|
+
class h {
|
|
11
11
|
constructor(e) {
|
|
12
|
-
|
|
12
|
+
u(this, "_rule");
|
|
13
13
|
this._rule = e != null ? e : {
|
|
14
|
-
uid:
|
|
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
|
|
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
|
|
33
|
+
return new h({
|
|
34
34
|
...this._rule,
|
|
35
|
-
uid:
|
|
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 !==
|
|
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 {
|
|
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 = `=${
|
|
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 ?
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
this
|
|
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 !==
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
389
|
-
return
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
...
|
|
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.
|
|
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.
|
|
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
|
|
467
|
+
class R extends c {
|
|
474
468
|
async setDataValidation(e) {
|
|
475
469
|
if (!e)
|
|
476
|
-
return this._commandService.executeCommand(
|
|
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(
|
|
483
|
+
return await this._commandService.executeCommand(D.id, t), this;
|
|
490
484
|
}
|
|
491
485
|
getDataValidation() {
|
|
492
|
-
const t = this._injector.get(
|
|
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
|
|
491
|
+
return t && new m(t, this._worksheet, this._injector);
|
|
498
492
|
}
|
|
499
493
|
getDataValidations() {
|
|
500
|
-
return this._injector.get(
|
|
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
|
|
498
|
+
).map((t) => new m(t, this._worksheet, this._injector));
|
|
505
499
|
}
|
|
506
500
|
async getValidatorStatus() {
|
|
507
|
-
return this._injector.get(
|
|
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
|
-
|
|
515
|
-
class
|
|
508
|
+
c.extend(R);
|
|
509
|
+
class N {
|
|
510
|
+
/**
|
|
511
|
+
* @deparecated use `univerAPI.newDataValidation()` as instead.
|
|
512
|
+
*/
|
|
516
513
|
static newDataValidation() {
|
|
517
|
-
return new
|
|
514
|
+
return new h();
|
|
515
|
+
}
|
|
516
|
+
newDataValidation() {
|
|
517
|
+
return new h();
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
|
-
|
|
521
|
-
class
|
|
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(
|
|
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(
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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
|
-
|
|
626
|
-
class
|
|
625
|
+
k.extend(x);
|
|
626
|
+
class M extends v {
|
|
627
627
|
getDataValidations() {
|
|
628
|
-
return this._injector.get(
|
|
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(
|
|
631
|
+
return this._injector.get(l).validatorWorksheet(
|
|
632
632
|
this._workbook.getUnitId(),
|
|
633
633
|
this._worksheet.getSheetId()
|
|
634
634
|
);
|
|
635
635
|
}
|
|
636
636
|
}
|
|
637
|
-
|
|
637
|
+
v.extend(M);
|
|
638
638
|
export {
|
|
639
|
-
|
|
640
|
-
|
|
639
|
+
m as FDataValidation,
|
|
640
|
+
h as FDataValidationBuilder
|
|
641
641
|
};
|