@univerjs/sheets-data-validation 0.5.3 → 0.5.4
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 +247 -102
- package/lib/es/index.js +632 -632
- package/lib/types/facade/f-event.d.ts +269 -0
- package/lib/types/facade/f-range.d.ts +3 -3
- package/lib/types/facade/f-univer.d.ts +4 -1
- package/lib/types/facade/f-workbook.d.ts +17 -32
- package/lib/types/facade/f-worksheet.d.ts +24 -2
- package/lib/types/facade/index.d.ts +2 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
package/lib/es/facade.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { UpdateSheetDataValidationSettingCommand as
|
|
5
|
-
import { FRange as
|
|
6
|
-
import { generateRandomId as
|
|
7
|
-
import { DataValidationModel as
|
|
8
|
-
import { serializeRangeToRefString as
|
|
9
|
-
import { filter as
|
|
10
|
-
class
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var q = (c, e, t) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
+
var f = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { UpdateSheetDataValidationSettingCommand as U, UpdateSheetDataValidationOptionsCommand as v, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as T, ClearRangeDataValidationCommand as W, AddSheetDataValidationCommand as A, SheetsDataValidationValidatorService as S, SheetDataValidationModel as V, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
|
|
5
|
+
import { FRange as y, FWorkbook as M, FWorksheet as x } from "@univerjs/sheets/facade";
|
|
6
|
+
import { generateRandomId as B, DataValidationType as o, DataValidationErrorStyle as w, DataValidationOperator as d, IUniverInstanceService as H, ICommandService as p, FUniver as N, CanceledError as _, toDisposable as g, FEventName as $ } from "@univerjs/core";
|
|
7
|
+
import { DataValidationModel as b, getRuleOptions as F } from "@univerjs/data-validation";
|
|
8
|
+
import { serializeRangeToRefString as P } from "@univerjs/engine-formula";
|
|
9
|
+
import { filter as R } from "rxjs";
|
|
10
|
+
class D {
|
|
11
11
|
constructor(e) {
|
|
12
|
-
|
|
12
|
+
f(this, "_rule");
|
|
13
13
|
this._rule = e != null ? e : {
|
|
14
|
-
uid:
|
|
14
|
+
uid: B(),
|
|
15
15
|
ranges: void 0,
|
|
16
|
-
type:
|
|
16
|
+
type: o.CUSTOM
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -30,9 +30,9 @@ class h {
|
|
|
30
30
|
* @return {FDataValidationBuilder} A new instance of the DataValidationBuilder class
|
|
31
31
|
*/
|
|
32
32
|
copy() {
|
|
33
|
-
return new
|
|
33
|
+
return new D({
|
|
34
34
|
...this._rule,
|
|
35
|
-
uid:
|
|
35
|
+
uid: B()
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -41,7 +41,7 @@ class h {
|
|
|
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 !== w.STOP;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Gets the data validation type of the rule
|
|
@@ -75,7 +75,7 @@ class h {
|
|
|
75
75
|
* @returns The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
76
76
|
*/
|
|
77
77
|
requireCheckbox(e, t) {
|
|
78
|
-
return this._rule.type =
|
|
78
|
+
return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
@@ -84,7 +84,7 @@ class h {
|
|
|
84
84
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
85
85
|
*/
|
|
86
86
|
requireDateAfter(e) {
|
|
87
|
-
return this._rule.type =
|
|
87
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = d.GREATER_THAN, this;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
@@ -93,7 +93,7 @@ class h {
|
|
|
93
93
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
94
94
|
*/
|
|
95
95
|
requireDateBefore(e) {
|
|
96
|
-
return this._rule.type =
|
|
96
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN, this;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
@@ -103,7 +103,7 @@ class h {
|
|
|
103
103
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
104
104
|
*/
|
|
105
105
|
requireDateBetween(e, t) {
|
|
106
|
-
return this._rule.type =
|
|
106
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = d.BETWEEN, this;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
@@ -112,7 +112,7 @@ class h {
|
|
|
112
112
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
113
113
|
*/
|
|
114
114
|
requireDateEqualTo(e) {
|
|
115
|
-
return this._rule.type =
|
|
115
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.EQUAL, this;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Set the data validation type to DATE and configure the validation rules to be not within a specific date range
|
|
@@ -122,7 +122,7 @@ class h {
|
|
|
122
122
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
123
123
|
*/
|
|
124
124
|
requireDateNotBetween(e, t) {
|
|
125
|
-
return this._rule.type =
|
|
125
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = d.NOT_BETWEEN, this;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
@@ -131,7 +131,7 @@ class h {
|
|
|
131
131
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
132
132
|
*/
|
|
133
133
|
requireDateOnOrAfter(e) {
|
|
134
|
-
return this._rule.type =
|
|
134
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN_OR_EQUAL, this;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
@@ -140,7 +140,7 @@ class h {
|
|
|
140
140
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
141
141
|
*/
|
|
142
142
|
requireDateOnOrBefore(e) {
|
|
143
|
-
return this._rule.type =
|
|
143
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN_OR_EQUAL, this;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Requires that a custom formula be satisfied.
|
|
@@ -150,7 +150,7 @@ class h {
|
|
|
150
150
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
151
151
|
*/
|
|
152
152
|
requireFormulaSatisfied(e) {
|
|
153
|
-
return this._rule.type =
|
|
153
|
+
return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Requires the user to enter a number within a specific range, which can be integer or decimal.
|
|
@@ -162,7 +162,7 @@ class h {
|
|
|
162
162
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
163
163
|
*/
|
|
164
164
|
requireNumberBetween(e, t, r) {
|
|
165
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator =
|
|
165
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = d.BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal.
|
|
@@ -173,7 +173,7 @@ class h {
|
|
|
173
173
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
174
174
|
*/
|
|
175
175
|
requireNumberEqualTo(e, t) {
|
|
176
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
176
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal.
|
|
@@ -184,7 +184,7 @@ class h {
|
|
|
184
184
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
185
185
|
*/
|
|
186
186
|
requireNumberGreaterThan(e, t) {
|
|
187
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
187
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal.
|
|
@@ -195,7 +195,7 @@ class h {
|
|
|
195
195
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
196
196
|
*/
|
|
197
197
|
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
198
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
198
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal.
|
|
@@ -206,7 +206,7 @@ class h {
|
|
|
206
206
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
207
207
|
*/
|
|
208
208
|
requireNumberLessThan(e, t) {
|
|
209
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
209
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
210
210
|
}
|
|
211
211
|
/**
|
|
212
212
|
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
@@ -217,7 +217,7 @@ class h {
|
|
|
217
217
|
* @return The current instance of the DataValidationBuilder class, allowing for method chaining
|
|
218
218
|
*/
|
|
219
219
|
requireNumberLessThanOrEqualTo(e, t) {
|
|
220
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
220
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
223
|
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
@@ -229,7 +229,7 @@ class h {
|
|
|
229
229
|
* @return An instance of the FDataValidationBuilder class, allowing for method chaining
|
|
230
230
|
*/
|
|
231
231
|
requireNumberNotBetween(e, t, r) {
|
|
232
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator =
|
|
232
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = d.NOT_BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
@@ -240,7 +240,7 @@ class h {
|
|
|
240
240
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
241
241
|
*/
|
|
242
242
|
requireNumberNotEqualTo(e, t) {
|
|
243
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
243
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.NOT_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
246
246
|
* Sets a data validation rule that requires the user to enter a value from a list of specific values.
|
|
@@ -252,7 +252,7 @@ class h {
|
|
|
252
252
|
* @return An instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
253
253
|
*/
|
|
254
254
|
requireValueInList(e, t, r) {
|
|
255
|
-
return this._rule.type = t ?
|
|
255
|
+
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* Sets a data validation rule that requires the user to enter a value within a specific range.
|
|
@@ -264,7 +264,7 @@ class h {
|
|
|
264
264
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
265
265
|
*/
|
|
266
266
|
requireValueInRange(e, t, r) {
|
|
267
|
-
return this._rule.type = t ?
|
|
267
|
+
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${P({
|
|
268
268
|
unitId: e.getUnitId(),
|
|
269
269
|
sheetName: e.getSheetName(),
|
|
270
270
|
range: e.getRange()
|
|
@@ -279,7 +279,7 @@ class h {
|
|
|
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 ? w.WARNING : w.STOP, this;
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
285
|
* Sets the help text and enables the display of error messages for data validation.
|
|
@@ -320,9 +320,9 @@ class h {
|
|
|
320
320
|
}
|
|
321
321
|
class m {
|
|
322
322
|
constructor(e, t, r) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
f(this, "rule");
|
|
324
|
+
f(this, "_worksheet");
|
|
325
|
+
f(this, "_injector");
|
|
326
326
|
this._injector = r, this.rule = e, this._worksheet = t;
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
@@ -331,7 +331,7 @@ class m {
|
|
|
331
331
|
* @return true if invalid data is allowed, false otherwise.
|
|
332
332
|
*/
|
|
333
333
|
getAllowInvalid() {
|
|
334
|
-
return this.rule.errorStyle !==
|
|
334
|
+
return this.rule.errorStyle !== w.STOP;
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
337
337
|
* Gets the data validation type of the rule
|
|
@@ -364,7 +364,7 @@ class m {
|
|
|
364
364
|
* @return A new FDataValidationBuilder instance with the same rule configuration.
|
|
365
365
|
*/
|
|
366
366
|
copy() {
|
|
367
|
-
return new
|
|
367
|
+
return new D(this.rule);
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Gets whether the data validation rule is applied to the worksheet.
|
|
@@ -374,7 +374,7 @@ class m {
|
|
|
374
374
|
getApplied() {
|
|
375
375
|
if (!this._worksheet)
|
|
376
376
|
return !1;
|
|
377
|
-
const t = this._injector.get(
|
|
377
|
+
const t = this._injector.get(b).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
|
|
378
378
|
return !!(t && t.ranges.length);
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
@@ -385,8 +385,8 @@ class m {
|
|
|
385
385
|
getRanges() {
|
|
386
386
|
if (!this.getApplied())
|
|
387
387
|
return [];
|
|
388
|
-
const e = this._injector.get(
|
|
389
|
-
return this.rule.ranges.map((t) => this._injector.createInstance(
|
|
388
|
+
const e = this._injector.get(H).getUnit(this._worksheet.getUnitId());
|
|
389
|
+
return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
|
|
390
390
|
}
|
|
391
391
|
/**
|
|
392
392
|
* Gets the title of the error message dialog box.
|
|
@@ -413,7 +413,7 @@ class m {
|
|
|
413
413
|
* @returns true if the criteria is set successfully, false otherwise.
|
|
414
414
|
*/
|
|
415
415
|
setCriteria(e, t, r = !0) {
|
|
416
|
-
if (this.getApplied() && !this._injector.get(
|
|
416
|
+
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
|
|
417
417
|
unitId: this.getUnitId(),
|
|
418
418
|
subUnitId: this.getSheetId(),
|
|
419
419
|
ruleId: this.rule.uid,
|
|
@@ -435,12 +435,12 @@ class m {
|
|
|
435
435
|
* @returns true if the options are set successfully, false otherwise.
|
|
436
436
|
*/
|
|
437
437
|
setOptions(e) {
|
|
438
|
-
if (this.getApplied() && !this._injector.get(
|
|
438
|
+
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(v.id, {
|
|
439
439
|
unitId: this.getUnitId(),
|
|
440
440
|
subUnitId: this.getSheetId(),
|
|
441
441
|
ruleId: this.rule.uid,
|
|
442
442
|
options: {
|
|
443
|
-
...
|
|
443
|
+
...F(this.rule),
|
|
444
444
|
...e
|
|
445
445
|
}
|
|
446
446
|
}))
|
|
@@ -453,7 +453,7 @@ class m {
|
|
|
453
453
|
* @returns true if the ranges are set successfully, false otherwise.
|
|
454
454
|
*/
|
|
455
455
|
setRanges(e) {
|
|
456
|
-
if (this.getApplied() && !this._injector.get(
|
|
456
|
+
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
|
|
457
457
|
unitId: this.getUnitId(),
|
|
458
458
|
subUnitId: this.getSheetId(),
|
|
459
459
|
ruleId: this.rule.uid,
|
|
@@ -467,17 +467,17 @@ class m {
|
|
|
467
467
|
* @returns true if the rule is deleted successfully, false otherwise.
|
|
468
468
|
*/
|
|
469
469
|
delete() {
|
|
470
|
-
return this.getApplied() ? this._injector.get(
|
|
470
|
+
return this.getApplied() ? this._injector.get(p).syncExecuteCommand(T.id, {
|
|
471
471
|
unitId: this.getUnitId(),
|
|
472
472
|
subUnitId: this.getSheetId(),
|
|
473
473
|
ruleId: this.rule.uid
|
|
474
474
|
}) : !1;
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
class
|
|
477
|
+
class G extends y {
|
|
478
478
|
setDataValidation(e) {
|
|
479
479
|
if (!e)
|
|
480
|
-
return this._commandService.syncExecuteCommand(
|
|
480
|
+
return this._commandService.syncExecuteCommand(W.id, {
|
|
481
481
|
unitId: this._workbook.getUnitId(),
|
|
482
482
|
subUnitId: this._worksheet.getSheetId(),
|
|
483
483
|
ranges: [this._range]
|
|
@@ -490,10 +490,10 @@ class R extends c {
|
|
|
490
490
|
ranges: [this._range]
|
|
491
491
|
}
|
|
492
492
|
};
|
|
493
|
-
return this._commandService.syncExecuteCommand(
|
|
493
|
+
return this._commandService.syncExecuteCommand(A.id, t), this;
|
|
494
494
|
}
|
|
495
495
|
getDataValidation() {
|
|
496
|
-
const t = this._injector.get(
|
|
496
|
+
const t = this._injector.get(S).getDataValidation(
|
|
497
497
|
this._workbook.getUnitId(),
|
|
498
498
|
this._worksheet.getSheetId(),
|
|
499
499
|
[this._range]
|
|
@@ -501,74 +501,188 @@ class R extends c {
|
|
|
501
501
|
return t && new m(t, this._worksheet, this._injector);
|
|
502
502
|
}
|
|
503
503
|
getDataValidations() {
|
|
504
|
-
return this._injector.get(
|
|
504
|
+
return this._injector.get(S).getDataValidations(
|
|
505
505
|
this._workbook.getUnitId(),
|
|
506
506
|
this._worksheet.getSheetId(),
|
|
507
507
|
[this._range]
|
|
508
508
|
).map((t) => new m(t, this._worksheet, this._injector));
|
|
509
509
|
}
|
|
510
510
|
async getValidatorStatus() {
|
|
511
|
-
return this._injector.get(
|
|
511
|
+
return this._injector.get(S).validatorRanges(
|
|
512
512
|
this._workbook.getUnitId(),
|
|
513
513
|
this._worksheet.getSheetId(),
|
|
514
514
|
[this._range]
|
|
515
515
|
);
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
|
-
|
|
519
|
-
class N {
|
|
518
|
+
y.extend(G);
|
|
519
|
+
class Q extends N {
|
|
520
|
+
/**
|
|
520
521
|
/**
|
|
521
522
|
* @deparecated use `univerAPI.newDataValidation()` as instead.
|
|
522
523
|
*/
|
|
523
524
|
static newDataValidation() {
|
|
524
|
-
return new
|
|
525
|
+
return new D();
|
|
525
526
|
}
|
|
526
527
|
newDataValidation() {
|
|
527
|
-
return new
|
|
528
|
+
return new D();
|
|
529
|
+
}
|
|
530
|
+
// eslint-disable-next-line max-lines-per-function
|
|
531
|
+
_initialize(e) {
|
|
532
|
+
if (!e.has(V)) return;
|
|
533
|
+
const t = e.get(V), r = e.get(p);
|
|
534
|
+
this.disposeWithMe(t.ruleChange$.subscribe((a) => {
|
|
535
|
+
const { unitId: i, subUnitId: n, rule: h, oldRule: u, type: s } = a, l = this.getSheetTarget(i, n);
|
|
536
|
+
if (!l)
|
|
537
|
+
return;
|
|
538
|
+
const { workbook: I, worksheet: k } = l, E = new m(h, k.getSheet(), this._injector);
|
|
539
|
+
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
540
|
+
origin: a,
|
|
541
|
+
worksheet: k,
|
|
542
|
+
workbook: I,
|
|
543
|
+
changeType: s,
|
|
544
|
+
oldRule: u,
|
|
545
|
+
rule: E
|
|
546
|
+
});
|
|
547
|
+
})), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
|
|
548
|
+
const { unitId: i, subUnitId: n, ruleId: h, status: u, row: s, col: l } = a, I = this.getSheetTarget(i, n);
|
|
549
|
+
if (!I)
|
|
550
|
+
return;
|
|
551
|
+
const { workbook: k, worksheet: E } = I, L = E.getDataValidation(h);
|
|
552
|
+
L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
|
|
553
|
+
workbook: k,
|
|
554
|
+
worksheet: E,
|
|
555
|
+
row: s,
|
|
556
|
+
column: l,
|
|
557
|
+
rule: L,
|
|
558
|
+
status: u
|
|
559
|
+
});
|
|
560
|
+
})), this.disposeWithMe(r.beforeCommandExecuted((a) => {
|
|
561
|
+
switch (a.id) {
|
|
562
|
+
case A.id: {
|
|
563
|
+
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
564
|
+
if (!n)
|
|
565
|
+
return;
|
|
566
|
+
const { workbook: h, worksheet: u } = n, s = {
|
|
567
|
+
worksheet: u,
|
|
568
|
+
workbook: h,
|
|
569
|
+
rule: i.rule
|
|
570
|
+
};
|
|
571
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
|
|
572
|
+
throw new _();
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
case U.id: {
|
|
576
|
+
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
577
|
+
if (!n)
|
|
578
|
+
return;
|
|
579
|
+
const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
580
|
+
if (!s)
|
|
581
|
+
return;
|
|
582
|
+
const l = {
|
|
583
|
+
worksheet: u,
|
|
584
|
+
workbook: h,
|
|
585
|
+
rule: s,
|
|
586
|
+
ruleId: i.ruleId,
|
|
587
|
+
newCriteria: i.setting
|
|
588
|
+
};
|
|
589
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, l), l.cancel)
|
|
590
|
+
throw new _();
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
case C.id: {
|
|
594
|
+
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
595
|
+
if (!n)
|
|
596
|
+
return;
|
|
597
|
+
const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
598
|
+
if (!s)
|
|
599
|
+
return;
|
|
600
|
+
const l = {
|
|
601
|
+
worksheet: u,
|
|
602
|
+
workbook: h,
|
|
603
|
+
rule: s,
|
|
604
|
+
ruleId: i.ruleId,
|
|
605
|
+
newRanges: i.ranges
|
|
606
|
+
};
|
|
607
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, l), l.cancel)
|
|
608
|
+
throw new _();
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
case v.id: {
|
|
612
|
+
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
613
|
+
if (!n)
|
|
614
|
+
return;
|
|
615
|
+
const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
616
|
+
if (!s)
|
|
617
|
+
return;
|
|
618
|
+
const l = {
|
|
619
|
+
worksheet: u,
|
|
620
|
+
workbook: h,
|
|
621
|
+
rule: s,
|
|
622
|
+
ruleId: i.ruleId,
|
|
623
|
+
newOptions: i.options
|
|
624
|
+
};
|
|
625
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, l), l.cancel)
|
|
626
|
+
throw new _();
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
case T.id: {
|
|
630
|
+
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
631
|
+
if (!n)
|
|
632
|
+
return;
|
|
633
|
+
const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
634
|
+
if (!s)
|
|
635
|
+
return;
|
|
636
|
+
const l = {
|
|
637
|
+
worksheet: u,
|
|
638
|
+
workbook: h,
|
|
639
|
+
rule: s,
|
|
640
|
+
ruleId: i.ruleId
|
|
641
|
+
};
|
|
642
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, l), l.cancel)
|
|
643
|
+
throw new _();
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
case O.id: {
|
|
647
|
+
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
648
|
+
if (!n)
|
|
649
|
+
return;
|
|
650
|
+
const { workbook: h, worksheet: u } = n, s = {
|
|
651
|
+
worksheet: u,
|
|
652
|
+
workbook: h,
|
|
653
|
+
rules: u.getDataValidations()
|
|
654
|
+
};
|
|
655
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
|
|
656
|
+
throw new _();
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}));
|
|
528
661
|
}
|
|
529
662
|
}
|
|
530
|
-
|
|
531
|
-
class
|
|
663
|
+
N.extend(Q);
|
|
664
|
+
class z extends M {
|
|
532
665
|
_initialize() {
|
|
533
666
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
534
667
|
get() {
|
|
535
|
-
return this._injector.get(
|
|
668
|
+
return this._injector.get(V);
|
|
536
669
|
}
|
|
537
670
|
});
|
|
538
671
|
}
|
|
539
|
-
/**
|
|
540
|
-
* get data validation validator status for current workbook
|
|
541
|
-
* @returns matrix of validator status
|
|
542
|
-
*/
|
|
543
672
|
getValidatorStatus() {
|
|
544
|
-
return this._injector.get(
|
|
673
|
+
return this._injector.get(S).validatorWorkbook(this._workbook.getUnitId());
|
|
545
674
|
}
|
|
546
675
|
// region DataValidationHooks
|
|
547
|
-
/**
|
|
548
|
-
* The onDataValidationChange event is fired when the data validation rule of this sheet is changed.
|
|
549
|
-
* @param callback Callback function that will be called when the event is fired
|
|
550
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
551
|
-
*/
|
|
552
676
|
onDataValidationChange(e) {
|
|
553
|
-
return
|
|
677
|
+
return g(this._dataValidationModel.ruleChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
|
|
554
678
|
}
|
|
555
|
-
/**
|
|
556
|
-
* The onDataValidationStatusChange event is fired when the data validation status of this sheet is changed.
|
|
557
|
-
* @param callback Callback function that will be called when the event is fired
|
|
558
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
559
|
-
*/
|
|
560
679
|
onDataValidationStatusChange(e) {
|
|
561
|
-
return
|
|
680
|
+
return g(this._dataValidationModel.validStatusChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
|
|
562
681
|
}
|
|
563
|
-
/**
|
|
564
|
-
* The onBeforeAddDataValidation event is fired before the data validation rule is added.
|
|
565
|
-
* @param callback Callback function that will be called when the event is fired
|
|
566
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
567
|
-
*/
|
|
568
682
|
onBeforeAddDataValidation(e) {
|
|
569
|
-
return
|
|
683
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
570
684
|
const a = t.params;
|
|
571
|
-
if (t.id ===
|
|
685
|
+
if (t.id === A.id) {
|
|
572
686
|
if (a.unitId !== this._workbook.getUnitId())
|
|
573
687
|
return;
|
|
574
688
|
if (e(a, r) === !1)
|
|
@@ -577,9 +691,9 @@ class x extends k {
|
|
|
577
691
|
}));
|
|
578
692
|
}
|
|
579
693
|
onBeforeUpdateDataValidationCriteria(e) {
|
|
580
|
-
return
|
|
694
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
581
695
|
const a = t.params;
|
|
582
|
-
if (t.id ===
|
|
696
|
+
if (t.id === U.id) {
|
|
583
697
|
if (a.unitId !== this._workbook.getUnitId())
|
|
584
698
|
return;
|
|
585
699
|
if (e(a, r) === !1)
|
|
@@ -588,9 +702,9 @@ class x extends k {
|
|
|
588
702
|
}));
|
|
589
703
|
}
|
|
590
704
|
onBeforeUpdateDataValidationRange(e) {
|
|
591
|
-
return
|
|
705
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
592
706
|
const a = t.params;
|
|
593
|
-
if (t.id ===
|
|
707
|
+
if (t.id === C.id) {
|
|
594
708
|
if (a.unitId !== this._workbook.getUnitId())
|
|
595
709
|
return;
|
|
596
710
|
if (e(a, r) === !1)
|
|
@@ -599,9 +713,9 @@ class x extends k {
|
|
|
599
713
|
}));
|
|
600
714
|
}
|
|
601
715
|
onBeforeUpdateDataValidationOptions(e) {
|
|
602
|
-
return
|
|
716
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
603
717
|
const a = t.params;
|
|
604
|
-
if (t.id ===
|
|
718
|
+
if (t.id === v.id) {
|
|
605
719
|
if (a.unitId !== this._workbook.getUnitId())
|
|
606
720
|
return;
|
|
607
721
|
if (e(a, r) === !1)
|
|
@@ -610,9 +724,9 @@ class x extends k {
|
|
|
610
724
|
}));
|
|
611
725
|
}
|
|
612
726
|
onBeforeDeleteDataValidation(e) {
|
|
613
|
-
return
|
|
727
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
614
728
|
const a = t.params;
|
|
615
|
-
if (t.id ===
|
|
729
|
+
if (t.id === T.id) {
|
|
616
730
|
if (a.unitId !== this._workbook.getUnitId())
|
|
617
731
|
return;
|
|
618
732
|
if (e(a, r) === !1)
|
|
@@ -621,9 +735,9 @@ class x extends k {
|
|
|
621
735
|
}));
|
|
622
736
|
}
|
|
623
737
|
onBeforeDeleteAllDataValidation(e) {
|
|
624
|
-
return
|
|
738
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
625
739
|
const a = t.params;
|
|
626
|
-
if (t.id ===
|
|
740
|
+
if (t.id === O.id) {
|
|
627
741
|
if (a.unitId !== this._workbook.getUnitId())
|
|
628
742
|
return;
|
|
629
743
|
if (e(a, r) === !1)
|
|
@@ -632,20 +746,51 @@ class x extends k {
|
|
|
632
746
|
}));
|
|
633
747
|
}
|
|
634
748
|
}
|
|
635
|
-
|
|
636
|
-
class
|
|
749
|
+
M.extend(z);
|
|
750
|
+
class K extends x {
|
|
637
751
|
getDataValidations() {
|
|
638
|
-
return this._injector.get(
|
|
752
|
+
return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
|
|
639
753
|
}
|
|
640
754
|
getValidatorStatus() {
|
|
641
|
-
return this._injector.get(
|
|
755
|
+
return this._injector.get(S).validatorWorksheet(
|
|
642
756
|
this._workbook.getUnitId(),
|
|
643
757
|
this._worksheet.getSheetId()
|
|
644
758
|
);
|
|
645
759
|
}
|
|
760
|
+
getDataValidation(e) {
|
|
761
|
+
const r = this._injector.get(b).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
|
|
762
|
+
return r ? new m(r, this._worksheet, this._injector) : null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
x.extend(K);
|
|
766
|
+
class X {
|
|
767
|
+
get SheetDataValidationChanged() {
|
|
768
|
+
return "SheetDataValidationChanged";
|
|
769
|
+
}
|
|
770
|
+
get SheetDataValidatorStatusChanged() {
|
|
771
|
+
return "SheetDataValidatorStatusChanged";
|
|
772
|
+
}
|
|
773
|
+
get BeforeSheetDataValidationAdd() {
|
|
774
|
+
return "BeforeSheetDataValidationAdd";
|
|
775
|
+
}
|
|
776
|
+
get BeforeSheetDataValidationDelete() {
|
|
777
|
+
return "BeforeSheetDataValidationDelete";
|
|
778
|
+
}
|
|
779
|
+
get BeforeSheetDataValidationDeleteAll() {
|
|
780
|
+
return "BeforeSheetDataValidationDeleteAll";
|
|
781
|
+
}
|
|
782
|
+
get BeforeSheetDataValidationCriteriaUpdate() {
|
|
783
|
+
return "BeforeSheetDataValidationCriteriaUpdate";
|
|
784
|
+
}
|
|
785
|
+
get BeforeSheetDataValidationRangeUpdate() {
|
|
786
|
+
return "BeforeSheetDataValidationRangeUpdate";
|
|
787
|
+
}
|
|
788
|
+
get BeforeSheetDataValidationOptionsUpdate() {
|
|
789
|
+
return "BeforeSheetDataValidationOptionsUpdate";
|
|
790
|
+
}
|
|
646
791
|
}
|
|
647
|
-
|
|
792
|
+
$.extend(X);
|
|
648
793
|
export {
|
|
649
794
|
m as FDataValidation,
|
|
650
|
-
|
|
795
|
+
D as FDataValidationBuilder
|
|
651
796
|
};
|