@univerjs/sheets-data-validation 0.6.0-nightly.202502181606 → 0.6.0-nightly.202502201606
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 +502 -178
- package/lib/es/index.js +751 -751
- package/lib/types/facade/f-data-validation-builder.d.ts +365 -64
- package/lib/types/facade/f-data-validation.d.ts +121 -83
- package/lib/types/facade/f-event.d.ts +58 -24
- package/lib/types/facade/f-range.d.ts +68 -11
- package/lib/types/facade/f-workbook.d.ts +5 -3
- package/lib/types/facade/f-worksheet.d.ts +13 -10
- 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,16 +1,16 @@
|
|
|
1
1
|
var H = Object.defineProperty;
|
|
2
2
|
var j = (g, e, t) => e in g ? H(g, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : g[e] = t;
|
|
3
|
-
var
|
|
4
|
-
import { UpdateSheetDataValidationSettingCommand as b, UpdateSheetDataValidationOptionsCommand as U, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as A, ClearRangeDataValidationCommand as q, AddSheetDataValidationCommand as T, SheetsDataValidationValidatorService as S, SheetDataValidationModel as
|
|
3
|
+
var f = (g, e, t) => j(g, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { UpdateSheetDataValidationSettingCommand as b, UpdateSheetDataValidationOptionsCommand as U, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as A, ClearRangeDataValidationCommand as q, AddSheetDataValidationCommand as T, SheetsDataValidationValidatorService as S, SheetDataValidationModel as k, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
|
|
5
5
|
import { FRange as y, FWorkbook as x, FWorksheet as N } from "@univerjs/sheets/facade";
|
|
6
|
-
import {
|
|
7
|
-
import { DataValidationModel as
|
|
6
|
+
import { DataValidationType as o, generateRandomId as L, DataValidationErrorStyle as V, DataValidationOperator as h, IUniverInstanceService as W, ICommandService as p, CanceledError as m, toDisposable as c } from "@univerjs/core";
|
|
7
|
+
import { DataValidationModel as w, getRuleOptions as $ } from "@univerjs/data-validation";
|
|
8
8
|
import { serializeRangeToRefString as F } from "@univerjs/engine-formula";
|
|
9
9
|
import { FUniver as M, FEventName as P } from "@univerjs/core/facade";
|
|
10
10
|
import { filter as R } from "rxjs";
|
|
11
11
|
class E {
|
|
12
12
|
constructor(e) {
|
|
13
|
-
|
|
13
|
+
f(this, "_rule");
|
|
14
14
|
this._rule = e != null ? e : {
|
|
15
15
|
uid: L(),
|
|
16
16
|
ranges: void 0,
|
|
@@ -22,20 +22,31 @@ class E {
|
|
|
22
22
|
* @returns {FDataValidation} A new instance of the FDataValidation class
|
|
23
23
|
* @example
|
|
24
24
|
* ```typescript
|
|
25
|
-
* const
|
|
26
|
-
* const
|
|
25
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
26
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
27
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
28
|
+
* const rule = univerAPI.newDataValidation()
|
|
29
|
+
* .requireNumberBetween(1, 10)
|
|
30
|
+
* .setOptions({
|
|
31
|
+
* allowBlank: true,
|
|
32
|
+
* showErrorMessage: true,
|
|
33
|
+
* error: 'Please enter a number between 1 and 10'
|
|
34
|
+
* })
|
|
35
|
+
* .build();
|
|
36
|
+
* fRange.setDataValidation(rule);
|
|
27
37
|
* ```
|
|
28
38
|
*/
|
|
29
39
|
build() {
|
|
30
|
-
return new
|
|
40
|
+
return new _(this._rule);
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
33
43
|
* Creates a duplicate of the current DataValidationBuilder object
|
|
34
44
|
* @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
|
|
35
45
|
* @example
|
|
36
46
|
* ```typescript
|
|
37
|
-
* const builder = univerAPI.newDataValidation();
|
|
38
|
-
* const
|
|
47
|
+
* const builder = univerAPI.newDataValidation().requireNumberBetween(1, 10);
|
|
48
|
+
* const copyBuilder = builder.copy();
|
|
49
|
+
* console.log(copyBuilder);
|
|
39
50
|
* ```
|
|
40
51
|
*/
|
|
41
52
|
copy() {
|
|
@@ -49,12 +60,12 @@ class E {
|
|
|
49
60
|
* @returns {boolean} True if invalid data is allowed, False otherwise
|
|
50
61
|
* @example
|
|
51
62
|
* ```typescript
|
|
52
|
-
* const builder = univerAPI.newDataValidation();
|
|
53
|
-
*
|
|
63
|
+
* const builder = univerAPI.newDataValidation().requireNumberBetween(1, 10);
|
|
64
|
+
* console.log(builder.getAllowInvalid());
|
|
54
65
|
* ```
|
|
55
66
|
*/
|
|
56
67
|
getAllowInvalid() {
|
|
57
|
-
return this._rule.errorStyle !==
|
|
68
|
+
return this._rule.errorStyle !== V.STOP;
|
|
58
69
|
}
|
|
59
70
|
/**
|
|
60
71
|
* Gets the data validation type of the rule
|
|
@@ -62,7 +73,13 @@ class E {
|
|
|
62
73
|
* @example
|
|
63
74
|
* ```typescript
|
|
64
75
|
* const builder = univerAPI.newDataValidation();
|
|
65
|
-
*
|
|
76
|
+
* console.log(builder.getCriteriaType());
|
|
77
|
+
*
|
|
78
|
+
* builder.requireNumberBetween(1, 10);
|
|
79
|
+
* console.log(builder.getCriteriaType());
|
|
80
|
+
*
|
|
81
|
+
* builder.requireValueInList(['Yes', 'No']);
|
|
82
|
+
* console.log(builder.getCriteriaType());
|
|
66
83
|
* ```
|
|
67
84
|
*/
|
|
68
85
|
getCriteriaType() {
|
|
@@ -73,8 +90,12 @@ class E {
|
|
|
73
90
|
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
74
91
|
* @example
|
|
75
92
|
* ```typescript
|
|
76
|
-
* const builder = univerAPI.newDataValidation();
|
|
93
|
+
* const builder = univerAPI.newDataValidation().requireNumberBetween(1, 10);
|
|
77
94
|
* const [operator, formula1, formula2] = builder.getCriteriaValues();
|
|
95
|
+
* console.log(operator, formula1, formula2);
|
|
96
|
+
*
|
|
97
|
+
* builder.requireValueInList(['Yes', 'No']);
|
|
98
|
+
* console.log(builder.getCriteriaValues());
|
|
78
99
|
* ```
|
|
79
100
|
*/
|
|
80
101
|
getCriteriaValues() {
|
|
@@ -85,8 +106,11 @@ class E {
|
|
|
85
106
|
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
86
107
|
* @example
|
|
87
108
|
* ```typescript
|
|
88
|
-
* const builder = univerAPI.newDataValidation()
|
|
89
|
-
*
|
|
109
|
+
* const builder = univerAPI.newDataValidation().setOptions({
|
|
110
|
+
* showErrorMessage: true,
|
|
111
|
+
* error: 'Please enter a valid value'
|
|
112
|
+
* });
|
|
113
|
+
* console.log(builder.getHelpText()); // 'Please enter a valid value'
|
|
90
114
|
* ```
|
|
91
115
|
*/
|
|
92
116
|
getHelpText() {
|
|
@@ -99,8 +123,22 @@ class E {
|
|
|
99
123
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
100
124
|
* @example
|
|
101
125
|
* ```typescript
|
|
102
|
-
* const
|
|
103
|
-
* const
|
|
126
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
127
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
128
|
+
*
|
|
129
|
+
* // Set the data validation for cell A1:A10 to require a checkbox with default 1 and 0 values
|
|
130
|
+
* const fRange = fWorksheet.getRange('A1:A10');
|
|
131
|
+
* const rule = univerAPI.newDataValidation()
|
|
132
|
+
* .requireCheckbox()
|
|
133
|
+
* .build();
|
|
134
|
+
* fRange.setDataValidation(rule);
|
|
135
|
+
*
|
|
136
|
+
* // Set the data validation for cell B1:B10 to require a checkbox with 'Yes' and 'No' values
|
|
137
|
+
* const fRange2 = fWorksheet.getRange('B1:B10');
|
|
138
|
+
* const rule2 = univerAPI.newDataValidation()
|
|
139
|
+
* .requireCheckbox('Yes', 'No')
|
|
140
|
+
* .build();
|
|
141
|
+
* fRange2.setDataValidation(rule2);
|
|
104
142
|
* ```
|
|
105
143
|
*/
|
|
106
144
|
requireCheckbox(e, t) {
|
|
@@ -112,8 +150,20 @@ class E {
|
|
|
112
150
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
113
151
|
* @example
|
|
114
152
|
* ```typescript
|
|
115
|
-
* const
|
|
116
|
-
* const
|
|
153
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
154
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
155
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
156
|
+
* fRange.setValues([
|
|
157
|
+
* ['2024-01-01', '2024-12-31'],
|
|
158
|
+
* ['2025-01-01', '2025-12-31']
|
|
159
|
+
* ]);
|
|
160
|
+
* const rule = univerAPI.newDataValidation()
|
|
161
|
+
* .requireDateAfter(new Date('2025-01-01'))
|
|
162
|
+
* .build();
|
|
163
|
+
* fRange.setDataValidation(rule);
|
|
164
|
+
*
|
|
165
|
+
* const status = await fRange.getValidatorStatus();
|
|
166
|
+
* console.log(status); // [['invalid', 'invalid', 'invalid', 'valid']]
|
|
117
167
|
* ```
|
|
118
168
|
*/
|
|
119
169
|
requireDateAfter(e) {
|
|
@@ -125,8 +175,20 @@ class E {
|
|
|
125
175
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
126
176
|
* @example
|
|
127
177
|
* ```typescript
|
|
128
|
-
* const
|
|
129
|
-
* const
|
|
178
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
179
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
180
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
181
|
+
* fRange.setValues([
|
|
182
|
+
* ['2024-01-01', '2024-12-31'],
|
|
183
|
+
* ['2025-01-01', '2025-12-31']
|
|
184
|
+
* ]);
|
|
185
|
+
* const rule = univerAPI.newDataValidation()
|
|
186
|
+
* .requireDateBefore(new Date('2025-01-01'))
|
|
187
|
+
* .build();
|
|
188
|
+
* fRange.setDataValidation(rule);
|
|
189
|
+
*
|
|
190
|
+
* const status = await fRange.getValidatorStatus();
|
|
191
|
+
* console.log(status); // [['valid', 'valid', 'invalid', 'invalid']]
|
|
130
192
|
* ```
|
|
131
193
|
*/
|
|
132
194
|
requireDateBefore(e) {
|
|
@@ -139,10 +201,20 @@ class E {
|
|
|
139
201
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
140
202
|
* @example
|
|
141
203
|
* ```typescript
|
|
142
|
-
* const
|
|
143
|
-
* const
|
|
144
|
-
*
|
|
204
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
205
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
206
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
207
|
+
* fRange.setValues([
|
|
208
|
+
* ['2024-01-01', '2024-12-31'],
|
|
209
|
+
* ['2025-01-01', '2025-12-31']
|
|
210
|
+
* ]);
|
|
211
|
+
* const rule = univerAPI.newDataValidation()
|
|
212
|
+
* .requireDateBetween(new Date('2024-06-01'), new Date('2025-06-01'))
|
|
145
213
|
* .build();
|
|
214
|
+
* fRange.setDataValidation(rule);
|
|
215
|
+
*
|
|
216
|
+
* const status = await fRange.getValidatorStatus();
|
|
217
|
+
* console.log(status); // [['invalid', 'valid', 'valid', 'invalid']]
|
|
146
218
|
* ```
|
|
147
219
|
*/
|
|
148
220
|
requireDateBetween(e, t) {
|
|
@@ -154,8 +226,23 @@ class E {
|
|
|
154
226
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
155
227
|
* @example
|
|
156
228
|
* ```typescript
|
|
157
|
-
* const
|
|
158
|
-
* const
|
|
229
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
230
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
231
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
232
|
+
* fRange.setValues([
|
|
233
|
+
* ['2024-01-01', '2024-12-31'],
|
|
234
|
+
* ['2025-01-01', '2025-12-31']
|
|
235
|
+
* ]);
|
|
236
|
+
* const rule = univerAPI.newDataValidation()
|
|
237
|
+
* .requireDateEqualTo(new Date('2025-01-01'))
|
|
238
|
+
* .build();
|
|
239
|
+
* fRange.setDataValidation(rule);
|
|
240
|
+
*
|
|
241
|
+
* const status = await fWorksheet.getRange('A2').getValidatorStatus();
|
|
242
|
+
* console.log(status?.[0]?.[0]); // 'valid'
|
|
243
|
+
*
|
|
244
|
+
* const status2 = await fWorksheet.getRange('B2').getValidatorStatus();
|
|
245
|
+
* console.log(status2?.[0]?.[0]); // 'invalid'
|
|
159
246
|
* ```
|
|
160
247
|
*/
|
|
161
248
|
requireDateEqualTo(e) {
|
|
@@ -168,10 +255,20 @@ class E {
|
|
|
168
255
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
169
256
|
* @example
|
|
170
257
|
* ```typescript
|
|
171
|
-
* const
|
|
172
|
-
* const
|
|
173
|
-
*
|
|
258
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
259
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
260
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
261
|
+
* fRange.setValues([
|
|
262
|
+
* ['2024-01-01', '2024-12-31'],
|
|
263
|
+
* ['2025-01-01', '2025-12-31']
|
|
264
|
+
* ]);
|
|
265
|
+
* const rule = univerAPI.newDataValidation()
|
|
266
|
+
* .requireDateNotBetween(new Date('2024-06-01'), new Date('2025-06-01'))
|
|
174
267
|
* .build();
|
|
268
|
+
* fRange.setDataValidation(rule);
|
|
269
|
+
*
|
|
270
|
+
* const status = await fRange.getValidatorStatus();
|
|
271
|
+
* console.log(status); // [['valid', 'invalid', 'invalid', 'valid']]
|
|
175
272
|
* ```
|
|
176
273
|
*/
|
|
177
274
|
requireDateNotBetween(e, t) {
|
|
@@ -183,8 +280,20 @@ class E {
|
|
|
183
280
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
184
281
|
* @example
|
|
185
282
|
* ```typescript
|
|
186
|
-
* const
|
|
187
|
-
* const
|
|
283
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
284
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
285
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
286
|
+
* fRange.setValues([
|
|
287
|
+
* ['2024-01-01', '2024-12-31'],
|
|
288
|
+
* ['2025-01-01', '2025-12-31']
|
|
289
|
+
* ]);
|
|
290
|
+
* const rule = univerAPI.newDataValidation()
|
|
291
|
+
* .requireDateOnOrAfter(new Date('2025-01-01'))
|
|
292
|
+
* .build();
|
|
293
|
+
* fRange.setDataValidation(rule);
|
|
294
|
+
*
|
|
295
|
+
* const status = await fRange.getValidatorStatus();
|
|
296
|
+
* console.log(status); // [['invalid', 'invalid', 'valid', 'valid']]
|
|
188
297
|
* ```
|
|
189
298
|
*/
|
|
190
299
|
requireDateOnOrAfter(e) {
|
|
@@ -196,8 +305,20 @@ class E {
|
|
|
196
305
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
197
306
|
* @example
|
|
198
307
|
* ```typescript
|
|
199
|
-
* const
|
|
200
|
-
* const
|
|
308
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
309
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
310
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
311
|
+
* fRange.setValues([
|
|
312
|
+
* ['2024-01-01', '2024-12-31'],
|
|
313
|
+
* ['2025-01-01', '2025-12-31']
|
|
314
|
+
* ]);
|
|
315
|
+
* const rule = univerAPI.newDataValidation()
|
|
316
|
+
* .requireDateOnOrBefore(new Date('2025-01-01'))
|
|
317
|
+
* .build();
|
|
318
|
+
* fRange.setDataValidation(rule);
|
|
319
|
+
*
|
|
320
|
+
* const status = await fRange.getValidatorStatus();
|
|
321
|
+
* console.log(status); // [['valid', 'valid', 'valid', 'invalid']]
|
|
201
322
|
* ```
|
|
202
323
|
*/
|
|
203
324
|
requireDateOnOrBefore(e) {
|
|
@@ -205,12 +326,33 @@ class E {
|
|
|
205
326
|
}
|
|
206
327
|
/**
|
|
207
328
|
* Requires that a custom formula be satisfied
|
|
208
|
-
* @param {string} formula - The formula string that needs to be satisfied
|
|
329
|
+
* @param {string} formula - The formula string that needs to be satisfied, formula result should be TRUE or FALSE, and references range will relative offset
|
|
209
330
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
210
331
|
* @example
|
|
211
332
|
* ```typescript
|
|
212
|
-
* const
|
|
213
|
-
* const
|
|
333
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
334
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
335
|
+
* const cell = fWorksheet.getRange('A1:B2');
|
|
336
|
+
* cell.setValues([
|
|
337
|
+
* [4, 3],
|
|
338
|
+
* [2, 1]
|
|
339
|
+
* ]);
|
|
340
|
+
* const fRange = fWorksheet.getRange('C1:D2');
|
|
341
|
+
* fRange.setValues([
|
|
342
|
+
* [1, 2],
|
|
343
|
+
* [3, 4]
|
|
344
|
+
* ]);
|
|
345
|
+
* const rule = univerAPI.newDataValidation()
|
|
346
|
+
* .requireFormulaSatisfied('=A1>2')
|
|
347
|
+
* .setOptions({
|
|
348
|
+
* showErrorMessage: true,
|
|
349
|
+
* error: 'Please enter a value equal to A1'
|
|
350
|
+
* })
|
|
351
|
+
* .build();
|
|
352
|
+
* fRange.setDataValidation(rule);
|
|
353
|
+
*
|
|
354
|
+
* const status = await fRange.getValidatorStatus();
|
|
355
|
+
* console.log(status); // [['valid', 'valid', 'invalid', 'invalid']]
|
|
214
356
|
* ```
|
|
215
357
|
*/
|
|
216
358
|
requireFormulaSatisfied(e) {
|
|
@@ -224,8 +366,18 @@ class E {
|
|
|
224
366
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
225
367
|
* @example
|
|
226
368
|
* ```typescript
|
|
227
|
-
* const
|
|
228
|
-
* const
|
|
369
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
370
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
371
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
372
|
+
* const rule = univerAPI.newDataValidation()
|
|
373
|
+
* .requireNumberBetween(1, 10)
|
|
374
|
+
* .setOptions({
|
|
375
|
+
* allowBlank: false,
|
|
376
|
+
* showErrorMessage: true,
|
|
377
|
+
* error: 'Please enter a number between 1 and 10'
|
|
378
|
+
* })
|
|
379
|
+
* .build();
|
|
380
|
+
* fRange.setDataValidation(rule);
|
|
229
381
|
* ```
|
|
230
382
|
*/
|
|
231
383
|
requireNumberBetween(e, t, i) {
|
|
@@ -238,8 +390,18 @@ class E {
|
|
|
238
390
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
239
391
|
* @example
|
|
240
392
|
* ```typescript
|
|
241
|
-
* const
|
|
242
|
-
* const
|
|
393
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
394
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
395
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
396
|
+
* const rule = univerAPI.newDataValidation()
|
|
397
|
+
* .requireNumberEqualTo(10)
|
|
398
|
+
* .setOptions({
|
|
399
|
+
* allowBlank: false,
|
|
400
|
+
* showErrorMessage: true,
|
|
401
|
+
* error: 'Please enter a number equal to 10'
|
|
402
|
+
* })
|
|
403
|
+
* .build();
|
|
404
|
+
* fRange.setDataValidation(rule);
|
|
243
405
|
* ```
|
|
244
406
|
*/
|
|
245
407
|
requireNumberEqualTo(e, t) {
|
|
@@ -252,8 +414,18 @@ class E {
|
|
|
252
414
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
253
415
|
* @example
|
|
254
416
|
* ```typescript
|
|
255
|
-
* const
|
|
256
|
-
* const
|
|
417
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
418
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
419
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
420
|
+
* const rule = univerAPI.newDataValidation()
|
|
421
|
+
* .requireNumberGreaterThan(10)
|
|
422
|
+
* .setOptions({
|
|
423
|
+
* allowBlank: false,
|
|
424
|
+
* showErrorMessage: true,
|
|
425
|
+
* error: 'Please enter a number greater than 10'
|
|
426
|
+
* })
|
|
427
|
+
* .build();
|
|
428
|
+
* fRange.setDataValidation(rule);
|
|
257
429
|
* ```
|
|
258
430
|
*/
|
|
259
431
|
requireNumberGreaterThan(e, t) {
|
|
@@ -266,8 +438,18 @@ class E {
|
|
|
266
438
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
267
439
|
* @example
|
|
268
440
|
* ```typescript
|
|
269
|
-
* const
|
|
270
|
-
* const
|
|
441
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
442
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
443
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
444
|
+
* const rule = univerAPI.newDataValidation()
|
|
445
|
+
* .requireNumberGreaterThanOrEqualTo(10)
|
|
446
|
+
* .setOptions({
|
|
447
|
+
* allowBlank: false,
|
|
448
|
+
* showErrorMessage: true,
|
|
449
|
+
* error: 'Please enter a number greater than 10 or equal to 10'
|
|
450
|
+
* })
|
|
451
|
+
* .build();
|
|
452
|
+
* fRange.setDataValidation(rule);
|
|
271
453
|
* ```
|
|
272
454
|
*/
|
|
273
455
|
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
@@ -280,8 +462,18 @@ class E {
|
|
|
280
462
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
281
463
|
* @example
|
|
282
464
|
* ```typescript
|
|
283
|
-
* const
|
|
284
|
-
* const
|
|
465
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
466
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
467
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
468
|
+
* const rule = univerAPI.newDataValidation()
|
|
469
|
+
* .requireNumberLessThan(10)
|
|
470
|
+
* .setOptions({
|
|
471
|
+
* allowBlank: false,
|
|
472
|
+
* showErrorMessage: true,
|
|
473
|
+
* error: 'Please enter a number less than 10'
|
|
474
|
+
* })
|
|
475
|
+
* .build();
|
|
476
|
+
* fRange.setDataValidation(rule);
|
|
285
477
|
* ```
|
|
286
478
|
*/
|
|
287
479
|
requireNumberLessThan(e, t) {
|
|
@@ -295,8 +487,18 @@ class E {
|
|
|
295
487
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
296
488
|
* @example
|
|
297
489
|
* ```typescript
|
|
298
|
-
* const
|
|
299
|
-
* const
|
|
490
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
491
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
492
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
493
|
+
* const rule = univerAPI.newDataValidation()
|
|
494
|
+
* .requireNumberLessThanOrEqualTo(10)
|
|
495
|
+
* .setOptions({
|
|
496
|
+
* allowBlank: false,
|
|
497
|
+
* showErrorMessage: true,
|
|
498
|
+
* error: 'Please enter a number less than 10 or equal to 10'
|
|
499
|
+
* })
|
|
500
|
+
* .build();
|
|
501
|
+
* fRange.setDataValidation(rule);
|
|
300
502
|
* ```
|
|
301
503
|
*/
|
|
302
504
|
requireNumberLessThanOrEqualTo(e, t) {
|
|
@@ -311,8 +513,18 @@ class E {
|
|
|
311
513
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
312
514
|
* @example
|
|
313
515
|
* ```typescript
|
|
314
|
-
* const
|
|
315
|
-
* const
|
|
516
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
517
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
518
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
519
|
+
* const rule = univerAPI.newDataValidation()
|
|
520
|
+
* .requireNumberNotBetween(1, 10)
|
|
521
|
+
* .setOptions({
|
|
522
|
+
* allowBlank: false,
|
|
523
|
+
* showErrorMessage: true,
|
|
524
|
+
* error: 'Please enter a number not between 1 and 10'
|
|
525
|
+
* })
|
|
526
|
+
* .build();
|
|
527
|
+
* fRange.setDataValidation(rule);
|
|
316
528
|
* ```
|
|
317
529
|
*/
|
|
318
530
|
requireNumberNotBetween(e, t, i) {
|
|
@@ -326,8 +538,18 @@ class E {
|
|
|
326
538
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
327
539
|
* @example
|
|
328
540
|
* ```typescript
|
|
329
|
-
* const
|
|
330
|
-
* const
|
|
541
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
542
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
543
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
544
|
+
* const rule = univerAPI.newDataValidation()
|
|
545
|
+
* .requireNumberNotEqualTo(10)
|
|
546
|
+
* .setOptions({
|
|
547
|
+
* allowBlank: false,
|
|
548
|
+
* showErrorMessage: true,
|
|
549
|
+
* error: 'Please enter a number not equal to 10'
|
|
550
|
+
* })
|
|
551
|
+
* .build();
|
|
552
|
+
* fRange.setDataValidation(rule);
|
|
331
553
|
* ```
|
|
332
554
|
*/
|
|
333
555
|
requireNumberNotEqualTo(e, t) {
|
|
@@ -342,8 +564,18 @@ class E {
|
|
|
342
564
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
343
565
|
* @example
|
|
344
566
|
* ```typescript
|
|
345
|
-
* const
|
|
346
|
-
* const
|
|
567
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
568
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
569
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
570
|
+
* const rule = univerAPI.newDataValidation()
|
|
571
|
+
* .requireValueInList(['Yes', 'No'])
|
|
572
|
+
* .setOptions({
|
|
573
|
+
* allowBlank: true,
|
|
574
|
+
* showErrorMessage: true,
|
|
575
|
+
* error: 'Please enter a value from the list'
|
|
576
|
+
* })
|
|
577
|
+
* .build();
|
|
578
|
+
* fRange.setDataValidation(rule);
|
|
347
579
|
* ```
|
|
348
580
|
*/
|
|
349
581
|
requireValueInList(e, t, i) {
|
|
@@ -358,9 +590,24 @@ class E {
|
|
|
358
590
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
359
591
|
* @example
|
|
360
592
|
* ```typescript
|
|
361
|
-
* const
|
|
362
|
-
* const
|
|
363
|
-
* const
|
|
593
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
594
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
595
|
+
* const fRange = fWorksheet.getRange('B1:B2');
|
|
596
|
+
* fRange.setValues([
|
|
597
|
+
* ['Yes'],
|
|
598
|
+
* ['No']
|
|
599
|
+
* ]);
|
|
600
|
+
*
|
|
601
|
+
* const rule = univerAPI.newDataValidation()
|
|
602
|
+
* .requireValueInRange(fRange)
|
|
603
|
+
* .setOptions({
|
|
604
|
+
* allowBlank: false,
|
|
605
|
+
* showErrorMessage: true,
|
|
606
|
+
* error: 'Please enter a value from the list'
|
|
607
|
+
* })
|
|
608
|
+
* .build();
|
|
609
|
+
* const cell = fWorksheet.getRange('A1');
|
|
610
|
+
* cell.setDataValidation(rule);
|
|
364
611
|
* ```
|
|
365
612
|
*/
|
|
366
613
|
requireValueInRange(e, t, i) {
|
|
@@ -378,12 +625,28 @@ class E {
|
|
|
378
625
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
379
626
|
* @example
|
|
380
627
|
* ```typescript
|
|
381
|
-
* const
|
|
382
|
-
* const
|
|
628
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
629
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
630
|
+
*
|
|
631
|
+
* // Set the data validation for cell A1:B2 to allow invalid data, so A1:B2 will display a warning when invalid data is entered
|
|
632
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
633
|
+
* const rule = univerAPI.newDataValidation()
|
|
634
|
+
* .requireValueInList(['Yes', 'No'])
|
|
635
|
+
* .setAllowInvalid(true)
|
|
636
|
+
* .build();
|
|
637
|
+
* fRange.setDataValidation(rule);
|
|
638
|
+
*
|
|
639
|
+
* // Set the data validation for cell C1:D2 to not allow invalid data, so C1:D2 will stop data entry when invalid data is entered
|
|
640
|
+
* const fRange2 = fWorksheet.getRange('C1:D2');
|
|
641
|
+
* const rule2 = univerAPI.newDataValidation()
|
|
642
|
+
* .requireValueInList(['Yes', 'No'])
|
|
643
|
+
* .setAllowInvalid(false)
|
|
644
|
+
* .build();
|
|
645
|
+
* fRange2.setDataValidation(rule2);
|
|
383
646
|
* ```
|
|
384
647
|
*/
|
|
385
648
|
setAllowInvalid(e) {
|
|
386
|
-
return this._rule.errorStyle = e ?
|
|
649
|
+
return this._rule.errorStyle = e ? V.WARNING : V.STOP, this;
|
|
387
650
|
}
|
|
388
651
|
/**
|
|
389
652
|
* Sets whether to allow blank values
|
|
@@ -391,8 +654,25 @@ class E {
|
|
|
391
654
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
392
655
|
* @example
|
|
393
656
|
* ```typescript
|
|
394
|
-
*
|
|
395
|
-
* const
|
|
657
|
+
* // Assume current sheet is empty data
|
|
658
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
659
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
660
|
+
*
|
|
661
|
+
* // Set the data validation for cell A1:B2 to allow blank values
|
|
662
|
+
* const fRange = fWorksheet.getRange('A1:B2');
|
|
663
|
+
* const rule = univerAPI.newDataValidation()
|
|
664
|
+
* .requireValueInList(['Yes', 'No'])
|
|
665
|
+
* .setAllowBlank(true)
|
|
666
|
+
* .build();
|
|
667
|
+
* fRange.setDataValidation(rule);
|
|
668
|
+
*
|
|
669
|
+
* // Set the data validation for cell C1:D2 to not allow blank values
|
|
670
|
+
* const fRange2 = fWorksheet.getRange('C1:D2');
|
|
671
|
+
* const rule2 = univerAPI.newDataValidation()
|
|
672
|
+
* .requireValueInList(['Yes', 'No'])
|
|
673
|
+
* .setAllowBlank(false)
|
|
674
|
+
* .build();
|
|
675
|
+
* fRange2.setDataValidation(rule2);
|
|
396
676
|
* ```
|
|
397
677
|
*/
|
|
398
678
|
setAllowBlank(e) {
|
|
@@ -404,23 +684,29 @@ class E {
|
|
|
404
684
|
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
405
685
|
* @example
|
|
406
686
|
* ```typescript
|
|
407
|
-
* const
|
|
408
|
-
* const
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
687
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
688
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
689
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
690
|
+
* const rule = univerAPI.newDataValidation()
|
|
691
|
+
* .requireValueInList(['Yes', 'No'])
|
|
692
|
+
* .setOptions({
|
|
693
|
+
* allowBlank: true,
|
|
694
|
+
* showErrorMessage: true,
|
|
695
|
+
* error: 'Please enter a value from the list'
|
|
696
|
+
* })
|
|
697
|
+
* .build();
|
|
698
|
+
* fRange.setDataValidation(rule);
|
|
413
699
|
* ```
|
|
414
700
|
*/
|
|
415
701
|
setOptions(e) {
|
|
416
702
|
return Object.assign(this._rule, e), this;
|
|
417
703
|
}
|
|
418
704
|
}
|
|
419
|
-
class
|
|
705
|
+
class _ {
|
|
420
706
|
constructor(e, t, i) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
707
|
+
f(this, "rule");
|
|
708
|
+
f(this, "_worksheet");
|
|
709
|
+
f(this, "_injector");
|
|
424
710
|
this._injector = i, this.rule = e, this._worksheet = t;
|
|
425
711
|
}
|
|
426
712
|
/**
|
|
@@ -428,28 +714,28 @@ class m {
|
|
|
428
714
|
* @returns {boolean} true if invalid data is allowed, false otherwise
|
|
429
715
|
* @example
|
|
430
716
|
* ```typescript
|
|
431
|
-
* const
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* .
|
|
436
|
-
*
|
|
717
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
718
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
719
|
+
* const rules = fWorksheet.getDataValidations();
|
|
720
|
+
* rules.forEach((rule) => {
|
|
721
|
+
* console.log(rule, rule.getAllowInvalid());
|
|
722
|
+
* });
|
|
437
723
|
* ```
|
|
438
724
|
*/
|
|
439
725
|
getAllowInvalid() {
|
|
440
|
-
return this.rule.errorStyle !==
|
|
726
|
+
return this.rule.errorStyle !== V.STOP;
|
|
441
727
|
}
|
|
442
728
|
/**
|
|
443
729
|
* Gets the data validation type of the rule
|
|
444
730
|
* @returns {DataValidationType | string} The data validation type
|
|
445
731
|
* @example
|
|
446
732
|
* ```typescript
|
|
447
|
-
* const
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* .
|
|
452
|
-
*
|
|
733
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
734
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
735
|
+
* const rules = fWorksheet.getDataValidations();
|
|
736
|
+
* rules.forEach((rule) => {
|
|
737
|
+
* console.log(rule, rule.getCriteriaType());
|
|
738
|
+
* });
|
|
453
739
|
* ```
|
|
454
740
|
*/
|
|
455
741
|
getCriteriaType() {
|
|
@@ -460,12 +746,15 @@ class m {
|
|
|
460
746
|
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
461
747
|
* @example
|
|
462
748
|
* ```typescript
|
|
463
|
-
* const
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
* .
|
|
468
|
-
*
|
|
749
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
750
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
751
|
+
* const rules = fWorksheet.getDataValidations();
|
|
752
|
+
* rules.forEach((rule) => {
|
|
753
|
+
* console.log(rule);
|
|
754
|
+
* const criteriaValues = rule.getCriteriaValues();
|
|
755
|
+
* const [operator, formula1, formula2] = criteriaValues;
|
|
756
|
+
* console.log(operator, formula1, formula2);
|
|
757
|
+
* });
|
|
469
758
|
* ```
|
|
470
759
|
*/
|
|
471
760
|
getCriteriaValues() {
|
|
@@ -476,12 +765,19 @@ class m {
|
|
|
476
765
|
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
477
766
|
* @example
|
|
478
767
|
* ```typescript
|
|
479
|
-
* const
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* .
|
|
484
|
-
*
|
|
768
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
769
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
770
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
771
|
+
* const rule = univerAPI.newDataValidation()
|
|
772
|
+
* .requireNumberBetween(1, 10)
|
|
773
|
+
* .setOptions({
|
|
774
|
+
* allowBlank: true,
|
|
775
|
+
* showErrorMessage: true,
|
|
776
|
+
* error: 'Please enter a number between 1 and 10'
|
|
777
|
+
* })
|
|
778
|
+
* .build();
|
|
779
|
+
* fRange.setDataValidation(rule);
|
|
780
|
+
* console.log(fRange.getDataValidation().getHelpText()); // 'Please enter a number between 1 and 10'
|
|
485
781
|
* ```
|
|
486
782
|
*/
|
|
487
783
|
getHelpText() {
|
|
@@ -492,13 +788,27 @@ class m {
|
|
|
492
788
|
* @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
|
|
493
789
|
* @example
|
|
494
790
|
* ```typescript
|
|
495
|
-
* const
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
* .
|
|
500
|
-
*
|
|
501
|
-
*
|
|
791
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
792
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
793
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
794
|
+
* const rule = univerAPI.newDataValidation()
|
|
795
|
+
* .requireNumberBetween(1, 10)
|
|
796
|
+
* .setOptions({
|
|
797
|
+
* allowBlank: true,
|
|
798
|
+
* showErrorMessage: true,
|
|
799
|
+
* error: 'Please enter a number between 1 and 10'
|
|
800
|
+
* })
|
|
801
|
+
* .build();
|
|
802
|
+
* fRange.setDataValidation(rule);
|
|
803
|
+
*
|
|
804
|
+
* const builder = fRange.getDataValidation().copy();
|
|
805
|
+
* const newRule = builder
|
|
806
|
+
* .requireNumberBetween(1, 5)
|
|
807
|
+
* .setOptions({
|
|
808
|
+
* error: 'Please enter a number between 1 and 5'
|
|
809
|
+
* })
|
|
810
|
+
* .build();
|
|
811
|
+
* fRange.setDataValidation(newRule);
|
|
502
812
|
* ```
|
|
503
813
|
*/
|
|
504
814
|
copy() {
|
|
@@ -509,18 +819,21 @@ class m {
|
|
|
509
819
|
* @returns {boolean} true if the rule is applied, false otherwise
|
|
510
820
|
* @example
|
|
511
821
|
* ```typescript
|
|
512
|
-
* const
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
* .
|
|
517
|
-
*
|
|
822
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
823
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
824
|
+
* const rules = fWorksheet.getDataValidations();
|
|
825
|
+
* rules.forEach((rule) => {
|
|
826
|
+
* console.log(rule, rule.getApplied());
|
|
827
|
+
* });
|
|
828
|
+
*
|
|
829
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
830
|
+
* console.log(fRange.getDataValidation()?.getApplied());
|
|
518
831
|
* ```
|
|
519
832
|
*/
|
|
520
833
|
getApplied() {
|
|
521
834
|
if (!this._worksheet)
|
|
522
835
|
return !1;
|
|
523
|
-
const t = this._injector.get(
|
|
836
|
+
const t = this._injector.get(w).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
|
|
524
837
|
return !!(t && t.ranges.length);
|
|
525
838
|
}
|
|
526
839
|
/**
|
|
@@ -528,12 +841,16 @@ class m {
|
|
|
528
841
|
* @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
|
|
529
842
|
* @example
|
|
530
843
|
* ```typescript
|
|
531
|
-
* const
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
* .
|
|
536
|
-
*
|
|
844
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
845
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
846
|
+
* const rules = fWorksheet.getDataValidations();
|
|
847
|
+
* rules.forEach((rule) => {
|
|
848
|
+
* console.log(rule);
|
|
849
|
+
* const ranges = rule.getRanges();
|
|
850
|
+
* ranges.forEach((range) => {
|
|
851
|
+
* console.log(range.getA1Notation());
|
|
852
|
+
* });
|
|
853
|
+
* });
|
|
537
854
|
* ```
|
|
538
855
|
*/
|
|
539
856
|
getRanges() {
|
|
@@ -547,12 +864,10 @@ class m {
|
|
|
547
864
|
* @returns {string | undefined} The unit ID of the worksheet
|
|
548
865
|
* @example
|
|
549
866
|
* ```typescript
|
|
550
|
-
* const
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* .getDataValidation();
|
|
555
|
-
* const unitId = dataValidation.getUnitId();
|
|
867
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
868
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
869
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
870
|
+
* console.log(fRange.getDataValidation().getUnitId());
|
|
556
871
|
* ```
|
|
557
872
|
*/
|
|
558
873
|
getUnitId() {
|
|
@@ -564,12 +879,10 @@ class m {
|
|
|
564
879
|
* @returns {string | undefined} The sheet ID of the worksheet
|
|
565
880
|
* @example
|
|
566
881
|
* ```typescript
|
|
567
|
-
* const
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
* .getDataValidation();
|
|
572
|
-
* const sheetId = dataValidation.getSheetId();
|
|
882
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
883
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
884
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
885
|
+
* console.log(fRange.getDataValidation().getSheetId());
|
|
573
886
|
* ```
|
|
574
887
|
*/
|
|
575
888
|
getSheetId() {
|
|
@@ -584,15 +897,17 @@ class m {
|
|
|
584
897
|
* @returns {FDataValidation} The current instance for method chaining
|
|
585
898
|
* @example
|
|
586
899
|
* ```typescript
|
|
587
|
-
* const
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* .
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
900
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
901
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
902
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
903
|
+
* const rule = univerAPI.newDataValidation()
|
|
904
|
+
* .requireNumberEqualTo(20)
|
|
905
|
+
* .build();
|
|
906
|
+
* fRange.setDataValidation(rule);
|
|
907
|
+
*
|
|
908
|
+
* fRange.getDataValidation().setCriteria(
|
|
909
|
+
* univerAPI.Enum.DataValidationType.DECIMAL,
|
|
910
|
+
* [univerAPI.Enum.DataValidationOperator.BETWEEN, '1', '10']
|
|
596
911
|
* );
|
|
597
912
|
* ```
|
|
598
913
|
*/
|
|
@@ -618,12 +933,15 @@ class m {
|
|
|
618
933
|
* @returns {FDataValidation} The current instance for method chaining
|
|
619
934
|
* @example
|
|
620
935
|
* ```typescript
|
|
621
|
-
* const
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
* .
|
|
626
|
-
*
|
|
936
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
937
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
938
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
939
|
+
* const rule = univerAPI.newDataValidation()
|
|
940
|
+
* .requireNumberEqualTo(20)
|
|
941
|
+
* .build();
|
|
942
|
+
* fRange.setDataValidation(rule);
|
|
943
|
+
*
|
|
944
|
+
* fRange.getDataValidation().setOptions({
|
|
627
945
|
* allowBlank: true,
|
|
628
946
|
* showErrorMessage: true,
|
|
629
947
|
* error: 'Please enter a valid value'
|
|
@@ -649,13 +967,16 @@ class m {
|
|
|
649
967
|
* @returns {FDataValidation} The current instance for method chaining
|
|
650
968
|
* @example
|
|
651
969
|
* ```typescript
|
|
652
|
-
* const
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
* .
|
|
657
|
-
*
|
|
658
|
-
*
|
|
970
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
971
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
972
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
973
|
+
* const rule = univerAPI.newDataValidation()
|
|
974
|
+
* .requireNumberEqualTo(20)
|
|
975
|
+
* .build();
|
|
976
|
+
* fRange.setDataValidation(rule);
|
|
977
|
+
*
|
|
978
|
+
* const newRuleRange = fWorksheet.getRange('C1:D10');
|
|
979
|
+
* fRange.getDataValidation().setRanges([newRuleRange]);
|
|
659
980
|
* ```
|
|
660
981
|
*/
|
|
661
982
|
setRanges(e) {
|
|
@@ -673,12 +994,15 @@ class m {
|
|
|
673
994
|
* @returns {boolean} true if the rule is deleted successfully, false otherwise
|
|
674
995
|
* @example
|
|
675
996
|
* ```typescript
|
|
676
|
-
* const
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
* .
|
|
681
|
-
*
|
|
997
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
998
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
999
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
1000
|
+
* const rule = univerAPI.newDataValidation()
|
|
1001
|
+
* .requireNumberEqualTo(20)
|
|
1002
|
+
* .build();
|
|
1003
|
+
* fRange.setDataValidation(rule);
|
|
1004
|
+
*
|
|
1005
|
+
* fRange.getDataValidation().delete();
|
|
682
1006
|
* ```
|
|
683
1007
|
*/
|
|
684
1008
|
delete() {
|
|
@@ -713,14 +1037,14 @@ class G extends y {
|
|
|
713
1037
|
this._worksheet.getSheetId(),
|
|
714
1038
|
[this._range]
|
|
715
1039
|
);
|
|
716
|
-
return t && new
|
|
1040
|
+
return t && new _(t, this._worksheet, this._injector);
|
|
717
1041
|
}
|
|
718
1042
|
getDataValidations() {
|
|
719
1043
|
return this._injector.get(S).getDataValidations(
|
|
720
1044
|
this._workbook.getUnitId(),
|
|
721
1045
|
this._worksheet.getSheetId(),
|
|
722
1046
|
[this._range]
|
|
723
|
-
).map((t) => new
|
|
1047
|
+
).map((t) => new _(t, this._worksheet, this._injector));
|
|
724
1048
|
}
|
|
725
1049
|
async getValidatorStatus() {
|
|
726
1050
|
return this._injector.get(S).validatorRanges(
|
|
@@ -747,22 +1071,22 @@ class Q extends M {
|
|
|
747
1071
|
*/
|
|
748
1072
|
// eslint-disable-next-line max-lines-per-function
|
|
749
1073
|
_initialize(e) {
|
|
750
|
-
if (!e.has(
|
|
751
|
-
const t = e.get(
|
|
1074
|
+
if (!e.has(k)) return;
|
|
1075
|
+
const t = e.get(k), i = e.get(p);
|
|
752
1076
|
this.registerEventHandler(
|
|
753
1077
|
this.Event.SheetDataValidationChanged,
|
|
754
1078
|
() => t.ruleChange$.subscribe((r) => {
|
|
755
1079
|
const { unitId: a, subUnitId: n, rule: u, oldRule: l, type: s } = r, d = this.getSheetTarget(a, n);
|
|
756
1080
|
if (!d)
|
|
757
1081
|
return;
|
|
758
|
-
const { workbook: D, worksheet: I } = d,
|
|
1082
|
+
const { workbook: D, worksheet: I } = d, v = new _(u, I.getSheet(), this._injector);
|
|
759
1083
|
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
760
1084
|
origin: r,
|
|
761
1085
|
worksheet: I,
|
|
762
1086
|
workbook: D,
|
|
763
1087
|
changeType: s,
|
|
764
1088
|
oldRule: l,
|
|
765
|
-
rule:
|
|
1089
|
+
rule: v
|
|
766
1090
|
});
|
|
767
1091
|
})
|
|
768
1092
|
), this.registerEventHandler(
|
|
@@ -771,10 +1095,10 @@ class Q extends M {
|
|
|
771
1095
|
const { unitId: a, subUnitId: n, ruleId: u, status: l, row: s, col: d } = r, D = this.getSheetTarget(a, n);
|
|
772
1096
|
if (!D)
|
|
773
1097
|
return;
|
|
774
|
-
const { workbook: I, worksheet:
|
|
1098
|
+
const { workbook: I, worksheet: v } = D, B = v.getDataValidation(u);
|
|
775
1099
|
B && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
|
|
776
1100
|
workbook: I,
|
|
777
|
-
worksheet:
|
|
1101
|
+
worksheet: v,
|
|
778
1102
|
row: s,
|
|
779
1103
|
column: d,
|
|
780
1104
|
rule: B,
|
|
@@ -794,7 +1118,7 @@ class Q extends M {
|
|
|
794
1118
|
rule: a.rule
|
|
795
1119
|
};
|
|
796
1120
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
|
|
797
|
-
throw new
|
|
1121
|
+
throw new m();
|
|
798
1122
|
}
|
|
799
1123
|
})
|
|
800
1124
|
), this.registerEventHandler(
|
|
@@ -815,7 +1139,7 @@ class Q extends M {
|
|
|
815
1139
|
newCriteria: a.setting
|
|
816
1140
|
};
|
|
817
1141
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, d), d.cancel)
|
|
818
|
-
throw new
|
|
1142
|
+
throw new m();
|
|
819
1143
|
}
|
|
820
1144
|
})
|
|
821
1145
|
), this.registerEventHandler(
|
|
@@ -836,7 +1160,7 @@ class Q extends M {
|
|
|
836
1160
|
newRanges: a.ranges
|
|
837
1161
|
};
|
|
838
1162
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, d), d.cancel)
|
|
839
|
-
throw new
|
|
1163
|
+
throw new m();
|
|
840
1164
|
}
|
|
841
1165
|
})
|
|
842
1166
|
), this.registerEventHandler(
|
|
@@ -857,7 +1181,7 @@ class Q extends M {
|
|
|
857
1181
|
newOptions: a.options
|
|
858
1182
|
};
|
|
859
1183
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, d), d.cancel)
|
|
860
|
-
throw new
|
|
1184
|
+
throw new m();
|
|
861
1185
|
}
|
|
862
1186
|
})
|
|
863
1187
|
), this.registerEventHandler(
|
|
@@ -877,7 +1201,7 @@ class Q extends M {
|
|
|
877
1201
|
ruleId: a.ruleId
|
|
878
1202
|
};
|
|
879
1203
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, d), d.cancel)
|
|
880
|
-
throw new
|
|
1204
|
+
throw new m();
|
|
881
1205
|
}
|
|
882
1206
|
})
|
|
883
1207
|
), this.registerEventHandler(
|
|
@@ -893,7 +1217,7 @@ class Q extends M {
|
|
|
893
1217
|
rules: l.getDataValidations()
|
|
894
1218
|
};
|
|
895
1219
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
|
|
896
|
-
throw new
|
|
1220
|
+
throw new m();
|
|
897
1221
|
}
|
|
898
1222
|
})
|
|
899
1223
|
);
|
|
@@ -904,7 +1228,7 @@ class z extends x {
|
|
|
904
1228
|
_initialize() {
|
|
905
1229
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
906
1230
|
get() {
|
|
907
|
-
return this._injector.get(
|
|
1231
|
+
return this._injector.get(k);
|
|
908
1232
|
}
|
|
909
1233
|
});
|
|
910
1234
|
}
|
|
@@ -988,7 +1312,7 @@ class z extends x {
|
|
|
988
1312
|
x.extend(z);
|
|
989
1313
|
class K extends N {
|
|
990
1314
|
getDataValidations() {
|
|
991
|
-
return this._injector.get(
|
|
1315
|
+
return this._injector.get(w).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new _(t, this._worksheet, this._injector));
|
|
992
1316
|
}
|
|
993
1317
|
getValidatorStatus() {
|
|
994
1318
|
return this._injector.get(S).validatorWorksheet(
|
|
@@ -1000,8 +1324,8 @@ class K extends N {
|
|
|
1000
1324
|
return this.getValidatorStatus();
|
|
1001
1325
|
}
|
|
1002
1326
|
getDataValidation(e) {
|
|
1003
|
-
const i = this._injector.get(
|
|
1004
|
-
return i ? new
|
|
1327
|
+
const i = this._injector.get(w).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
|
|
1328
|
+
return i ? new _(i, this._worksheet, this._injector) : null;
|
|
1005
1329
|
}
|
|
1006
1330
|
}
|
|
1007
1331
|
N.extend(K);
|
|
@@ -1033,6 +1357,6 @@ class X {
|
|
|
1033
1357
|
}
|
|
1034
1358
|
P.extend(X);
|
|
1035
1359
|
export {
|
|
1036
|
-
|
|
1360
|
+
_ as FDataValidation,
|
|
1037
1361
|
E as FDataValidationBuilder
|
|
1038
1362
|
};
|