@univerjs/sheets-data-validation 0.6.7 → 0.6.9-nightly.202504021607

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/facade.js ADDED
@@ -0,0 +1,1453 @@
1
+ var H = Object.defineProperty;
2
+ var q = (h, e, t) => e in h ? H(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
+ var _ = (h, e, t) => q(h, typeof e != "symbol" ? e + "" : e, t);
4
+ import { UpdateSheetDataValidationSettingCommand as b, UpdateSheetDataValidationOptionsCommand as U, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as A, ClearRangeDataValidationCommand as j, AddSheetDataValidationCommand as T, SheetsDataValidationValidatorService as S, SheetDataValidationModel as f, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
5
+ import { FRange as y, FWorkbook as x, FWorksheet as M } from "@univerjs/sheets/facade";
6
+ import { DataValidationType as a, generateRandomId as L, DataValidationErrorStyle as k, DataValidationOperator as u, IUniverInstanceService as W, ICommandService as p, CanceledError as c, toDisposable as g } from "@univerjs/core";
7
+ import { DataValidationModel as w, getRuleOptions as $ } from "@univerjs/data-validation";
8
+ import { serializeRangeToRefString as F } from "@univerjs/engine-formula";
9
+ import { FUniver as N, FEventName as P } from "@univerjs/core/facade";
10
+ import { filter as R } from "rxjs";
11
+ class E {
12
+ constructor(e) {
13
+ _(this, "_rule");
14
+ this._rule = e != null ? e : {
15
+ uid: L(),
16
+ ranges: void 0,
17
+ type: a.CUSTOM
18
+ };
19
+ }
20
+ /**
21
+ * Builds an FDataValidation instance based on the _rule property of the current class
22
+ * @returns {FDataValidation} A new instance of the FDataValidation class
23
+ * @example
24
+ * ```typescript
25
+ * const fWorkbook = univerAPI.getActiveWorkbook();
26
+ * const fWorksheet = fWorkbook.getActiveSheet();
27
+ *
28
+ * // Create a new data validation rule that requires a number between 1 and 10 for the range A1:B10
29
+ * const fRange = fWorksheet.getRange('A1:B10');
30
+ * const rule = univerAPI.newDataValidation()
31
+ * .requireNumberBetween(1, 10)
32
+ * .setOptions({
33
+ * allowBlank: true,
34
+ * showErrorMessage: true,
35
+ * error: 'Please enter a number between 1 and 10'
36
+ * })
37
+ * .build();
38
+ * fRange.setDataValidation(rule);
39
+ * ```
40
+ */
41
+ build() {
42
+ return new m(this._rule);
43
+ }
44
+ /**
45
+ * Creates a duplicate of the current DataValidationBuilder object
46
+ * @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
47
+ * @example
48
+ * ```typescript
49
+ * const fWorkbook = univerAPI.getActiveWorkbook();
50
+ * const fWorksheet = fWorkbook.getActiveSheet();
51
+ *
52
+ * // Create a new data validation rule that requires a number between 1 and 10 for the range A1:B10
53
+ * const fRange = fWorksheet.getRange('A1:B10');
54
+ * const builder = univerAPI.newDataValidation()
55
+ * .requireNumberBetween(1, 10)
56
+ * .setOptions({
57
+ * allowBlank: true,
58
+ * showErrorMessage: true,
59
+ * error: 'Please enter a number between 1 and 10'
60
+ * });
61
+ * fRange.setDataValidation(builder.build());
62
+ *
63
+ * // Copy the builder applied to the new range F1:G10
64
+ * const newRange = fWorksheet.getRange('F1:G10');
65
+ * const copyBuilder = builder.copy();
66
+ * newRange.setDataValidation(copyBuilder.build());
67
+ * ```
68
+ */
69
+ copy() {
70
+ return new E({
71
+ ...this._rule,
72
+ uid: L()
73
+ });
74
+ }
75
+ /**
76
+ * Determines whether invalid data is allowed
77
+ * @returns {boolean} True if invalid data is allowed, False otherwise
78
+ * @example
79
+ * ```typescript
80
+ * const builder = univerAPI.newDataValidation().requireNumberBetween(1, 10);
81
+ * console.log(builder.getAllowInvalid());
82
+ * ```
83
+ */
84
+ getAllowInvalid() {
85
+ return this._rule.errorStyle !== k.STOP;
86
+ }
87
+ /**
88
+ * Gets the data validation type of the rule
89
+ * @returns {DataValidationType | string} The data validation type
90
+ * @example
91
+ * ```typescript
92
+ * const builder = univerAPI.newDataValidation();
93
+ * console.log(builder.getCriteriaType()); // custom
94
+ *
95
+ * builder.requireNumberBetween(1, 10);
96
+ * console.log(builder.getCriteriaType()); // decimal
97
+ *
98
+ * builder.requireValueInList(['Yes', 'No']);
99
+ * console.log(builder.getCriteriaType()); // list
100
+ * ```
101
+ */
102
+ getCriteriaType() {
103
+ return this._rule.type;
104
+ }
105
+ /**
106
+ * Gets the values used for criteria evaluation
107
+ * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
108
+ * @example
109
+ * ```typescript
110
+ * const builder = univerAPI.newDataValidation().requireNumberBetween(1, 10);
111
+ * const [operator, formula1, formula2] = builder.getCriteriaValues();
112
+ * console.log(operator, formula1, formula2); // between 1 10
113
+ *
114
+ * builder.requireValueInList(['Yes', 'No']);
115
+ * console.log(builder.getCriteriaValues()); // undefined Yes,No undefined
116
+ * ```
117
+ */
118
+ getCriteriaValues() {
119
+ return [this._rule.operator, this._rule.formula1, this._rule.formula2];
120
+ }
121
+ /**
122
+ * Gets the help text information, which is used to provide users with guidance and support
123
+ * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
124
+ * @example
125
+ * ```typescript
126
+ * const builder = univerAPI.newDataValidation().setOptions({
127
+ * showErrorMessage: true,
128
+ * error: 'Please enter a valid value'
129
+ * });
130
+ * console.log(builder.getHelpText()); // 'Please enter a valid value'
131
+ * ```
132
+ */
133
+ getHelpText() {
134
+ return this._rule.error;
135
+ }
136
+ /**
137
+ * Sets the data validation rule to require that the input is a boolean value; this value is rendered as a checkbox.
138
+ * @param {string} [checkedValue] - The value assigned to a checked box.
139
+ * @param {string} [uncheckedValue] - The value assigned to an unchecked box.
140
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
141
+ * @example
142
+ * ```typescript
143
+ * const fWorkbook = univerAPI.getActiveWorkbook();
144
+ * const fWorksheet = fWorkbook.getActiveSheet();
145
+ *
146
+ * // Set the data validation for cell A1:A10 to require a checkbox with default 1 and 0 values
147
+ * const fRange = fWorksheet.getRange('A1:A10');
148
+ * const rule = univerAPI.newDataValidation()
149
+ * .requireCheckbox()
150
+ * .build();
151
+ * fRange.setDataValidation(rule);
152
+ *
153
+ * // Set the data validation for cell B1:B10 to require a checkbox with 'Yes' and 'No' values
154
+ * const fRange2 = fWorksheet.getRange('B1:B10');
155
+ * const rule2 = univerAPI.newDataValidation()
156
+ * .requireCheckbox('Yes', 'No')
157
+ * .build();
158
+ * fRange2.setDataValidation(rule2);
159
+ * ```
160
+ */
161
+ requireCheckbox(e, t) {
162
+ return this._rule.type = a.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
163
+ }
164
+ /**
165
+ * Set the data validation type to DATE and configure the validation rules to be after a specific date.
166
+ * @param {Date} date - The latest unacceptable date.
167
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
168
+ * @example
169
+ * ```typescript
170
+ * const fWorkbook = univerAPI.getActiveWorkbook();
171
+ * const fWorksheet = fWorkbook.getActiveSheet();
172
+ *
173
+ * // Set some date values in the range A1:B2
174
+ * const fRange = fWorksheet.getRange('A1:B2');
175
+ * fRange.setValues([
176
+ * ['2024-01-01', '2024-12-31'],
177
+ * ['2025-01-01', '2025-12-31']
178
+ * ]);
179
+ *
180
+ * // Create a data validation rule that requires a date after 2025-01-01
181
+ * const rule = univerAPI.newDataValidation()
182
+ * .requireDateAfter(new Date('2025-01-01'))
183
+ * .build();
184
+ * fRange.setDataValidation(rule);
185
+ *
186
+ * // Get the validation status of the range
187
+ * const status = await fRange.getValidatorStatus();
188
+ * console.log(status); // [['invalid', 'invalid', 'invalid', 'valid']]
189
+ * ```
190
+ */
191
+ requireDateAfter(e) {
192
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = u.GREATER_THAN, this;
193
+ }
194
+ /**
195
+ * Set the data validation type to DATE and configure the validation rules to be before a specific date.
196
+ * @param {Date} date - The earliest unacceptable date.
197
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
198
+ * @example
199
+ * ```typescript
200
+ * const fWorkbook = univerAPI.getActiveWorkbook();
201
+ * const fWorksheet = fWorkbook.getActiveSheet();
202
+ *
203
+ * // Set some date values in the range A1:B2
204
+ * const fRange = fWorksheet.getRange('A1:B2');
205
+ * fRange.setValues([
206
+ * ['2024-01-01', '2024-12-31'],
207
+ * ['2025-01-01', '2025-12-31']
208
+ * ]);
209
+ *
210
+ * // Create a data validation rule that requires a date before 2025-01-01
211
+ * const rule = univerAPI.newDataValidation()
212
+ * .requireDateBefore(new Date('2025-01-01'))
213
+ * .build();
214
+ * fRange.setDataValidation(rule);
215
+ *
216
+ * // Get the validation status of the range
217
+ * const status = await fRange.getValidatorStatus();
218
+ * console.log(status); // [['valid', 'valid', 'invalid', 'invalid']]
219
+ * ```
220
+ */
221
+ requireDateBefore(e) {
222
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = u.LESS_THAN, this;
223
+ }
224
+ /**
225
+ * Set the data validation type to DATE and configure the validation rules to be within a specific date range.
226
+ * @param {Date} start - The earliest acceptable date.
227
+ * @param {Date} end - The latest acceptable date.
228
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
229
+ * @example
230
+ * ```typescript
231
+ * const fWorkbook = univerAPI.getActiveWorkbook();
232
+ * const fWorksheet = fWorkbook.getActiveSheet();
233
+ *
234
+ * // Set some date values in the range A1:B2
235
+ * const fRange = fWorksheet.getRange('A1:B2');
236
+ * fRange.setValues([
237
+ * ['2024-01-01', '2024-12-31'],
238
+ * ['2025-01-01', '2025-12-31']
239
+ * ]);
240
+ *
241
+ * // Create a data validation rule that requires a date between 2024-06-01 and 2025-06-01
242
+ * const rule = univerAPI.newDataValidation()
243
+ * .requireDateBetween(new Date('2024-06-01'), new Date('2025-06-01'))
244
+ * .build();
245
+ * fRange.setDataValidation(rule);
246
+ *
247
+ * // Get the validation status of the range
248
+ * const status = await fRange.getValidatorStatus();
249
+ * console.log(status); // [['invalid', 'valid', 'valid', 'invalid']]
250
+ * ```
251
+ */
252
+ requireDateBetween(e, t) {
253
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = u.BETWEEN, this;
254
+ }
255
+ /**
256
+ * Set the data validation type to DATE and configure the validation rules to be equal to a specific date.
257
+ * @param {Date} date - The sole acceptable date.
258
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
259
+ * @example
260
+ * ```typescript
261
+ * const fWorkbook = univerAPI.getActiveWorkbook();
262
+ * const fWorksheet = fWorkbook.getActiveSheet();
263
+ *
264
+ * // Set some date values in the range A1:B2
265
+ * const fRange = fWorksheet.getRange('A1:B2');
266
+ * fRange.setValues([
267
+ * ['2024-01-01', '2024-12-31'],
268
+ * ['2025-01-01', '2025-12-31']
269
+ * ]);
270
+ *
271
+ * // Create a data validation rule that requires a date equal to 2025-01-01
272
+ * const rule = univerAPI.newDataValidation()
273
+ * .requireDateEqualTo(new Date('2025-01-01'))
274
+ * .build();
275
+ * fRange.setDataValidation(rule);
276
+ *
277
+ * // Get the validation status of the cell A2
278
+ * const status = await fWorksheet.getRange('A2').getValidatorStatus();
279
+ * console.log(status?.[0]?.[0]); // 'valid'
280
+ *
281
+ * // Get the validation status of the cell B2
282
+ * const status2 = await fWorksheet.getRange('B2').getValidatorStatus();
283
+ * console.log(status2?.[0]?.[0]); // 'invalid'
284
+ * ```
285
+ */
286
+ requireDateEqualTo(e) {
287
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = u.EQUAL, this;
288
+ }
289
+ /**
290
+ * Set the data validation type to DATE and configure the validation rules to be not within a specific date range.
291
+ * @param {Date} start - The earliest unacceptable date.
292
+ * @param {Date} end - The latest unacceptable date.
293
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
294
+ * @example
295
+ * ```typescript
296
+ * const fWorkbook = univerAPI.getActiveWorkbook();
297
+ * const fWorksheet = fWorkbook.getActiveSheet();
298
+ *
299
+ * // Set some date values in the range A1:B2
300
+ * const fRange = fWorksheet.getRange('A1:B2');
301
+ * fRange.setValues([
302
+ * ['2024-01-01', '2024-12-31'],
303
+ * ['2025-01-01', '2025-12-31']
304
+ * ]);
305
+ *
306
+ * // Create a data validation rule that requires a date not between 2024-06-01 and 2025-06-01
307
+ * const rule = univerAPI.newDataValidation()
308
+ * .requireDateNotBetween(new Date('2024-06-01'), new Date('2025-06-01'))
309
+ * .build();
310
+ * fRange.setDataValidation(rule);
311
+ *
312
+ * // Get the validation status of the range
313
+ * const status = await fRange.getValidatorStatus();
314
+ * console.log(status); // [['valid', 'invalid', 'invalid', 'valid']]
315
+ * ```
316
+ */
317
+ requireDateNotBetween(e, t) {
318
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = u.NOT_BETWEEN, this;
319
+ }
320
+ /**
321
+ * Set the data validation type to DATE and configure the validation rules to be on or after a specific date.
322
+ * @param {Date} date - The earliest acceptable date.
323
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
324
+ * @example
325
+ * ```typescript
326
+ * const fWorkbook = univerAPI.getActiveWorkbook();
327
+ * const fWorksheet = fWorkbook.getActiveSheet();
328
+ *
329
+ * // Set some date values in the range A1:B2
330
+ * const fRange = fWorksheet.getRange('A1:B2');
331
+ * fRange.setValues([
332
+ * ['2024-01-01', '2024-12-31'],
333
+ * ['2025-01-01', '2025-12-31']
334
+ * ]);
335
+ *
336
+ * // Create a data validation rule that requires a date on or after 2025-01-01
337
+ * const rule = univerAPI.newDataValidation()
338
+ * .requireDateOnOrAfter(new Date('2025-01-01'))
339
+ * .build();
340
+ * fRange.setDataValidation(rule);
341
+ *
342
+ * // Get the validation status of the range
343
+ * const status = await fRange.getValidatorStatus();
344
+ * console.log(status); // [['invalid', 'invalid', 'valid', 'valid']]
345
+ * ```
346
+ */
347
+ requireDateOnOrAfter(e) {
348
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = u.GREATER_THAN_OR_EQUAL, this;
349
+ }
350
+ /**
351
+ * Set the data validation type to DATE and configure the validation rules to be on or before a specific date.
352
+ * @param {Date} date - The latest acceptable date.
353
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
354
+ * @example
355
+ * ```typescript
356
+ * const fWorkbook = univerAPI.getActiveWorkbook();
357
+ * const fWorksheet = fWorkbook.getActiveSheet();
358
+ *
359
+ * // Set some date values in the range A1:B2
360
+ * const fRange = fWorksheet.getRange('A1:B2');
361
+ * fRange.setValues([
362
+ * ['2024-01-01', '2024-12-31'],
363
+ * ['2025-01-01', '2025-12-31']
364
+ * ]);
365
+ *
366
+ * // Create a data validation rule that requires a date on or before 2025-01-01
367
+ * const rule = univerAPI.newDataValidation()
368
+ * .requireDateOnOrBefore(new Date('2025-01-01'))
369
+ * .build();
370
+ * fRange.setDataValidation(rule);
371
+ *
372
+ * // Get the validation status of the range
373
+ * const status = await fRange.getValidatorStatus();
374
+ * console.log(status); // [['valid', 'valid', 'valid', 'invalid']]
375
+ * ```
376
+ */
377
+ requireDateOnOrBefore(e) {
378
+ return this._rule.type = a.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = u.LESS_THAN_OR_EQUAL, this;
379
+ }
380
+ /**
381
+ * Sets the data validation rule to require that the given formula evaluates to `true`.
382
+ * @param {string} formula - The formula string that needs to be satisfied, formula result should be TRUE or FALSE, and references range will relative offset.
383
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
384
+ * @example
385
+ * ```typescript
386
+ * const fWorkbook = univerAPI.getActiveWorkbook();
387
+ * const fWorksheet = fWorkbook.getActiveSheet();
388
+ *
389
+ * // Set some values in the range A1:B2 and C1:D2
390
+ * const cell = fWorksheet.getRange('A1:B2');
391
+ * cell.setValues([
392
+ * [4, 3],
393
+ * [2, 1]
394
+ * ]);
395
+ * const fRange = fWorksheet.getRange('C1:D2');
396
+ * fRange.setValues([
397
+ * [1, 2],
398
+ * [3, 4]
399
+ * ]);
400
+ *
401
+ * // Create a data validation rule that requires the formula '=A1>2' to be satisfied
402
+ * const rule = univerAPI.newDataValidation()
403
+ * .requireFormulaSatisfied('=A1>2')
404
+ * .setOptions({
405
+ * showErrorMessage: true,
406
+ * error: 'Please enter a value equal to A1'
407
+ * })
408
+ * .build();
409
+ * fRange.setDataValidation(rule);
410
+ *
411
+ * // Get the validation status of the range
412
+ * const status = await fRange.getValidatorStatus();
413
+ * console.log(status); // [['valid', 'valid', 'invalid', 'invalid']]
414
+ * ```
415
+ */
416
+ requireFormulaSatisfied(e) {
417
+ return this._rule.type = a.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
418
+ }
419
+ /**
420
+ * Sets the data validation rule to require a number that falls between, or is either of, two specified numbers.
421
+ * @param {number} start - The lowest acceptable value.
422
+ * @param {number} end - The highest acceptable value.
423
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
424
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
425
+ * @example
426
+ * ```typescript
427
+ * const fWorkbook = univerAPI.getActiveWorkbook();
428
+ * const fWorksheet = fWorkbook.getActiveSheet();
429
+ *
430
+ * // Create a new data validation rule that requires a number between 1 and 10 for the range A1:B10
431
+ * const fRange = fWorksheet.getRange('A1:B10');
432
+ * const rule = univerAPI.newDataValidation()
433
+ * .requireNumberBetween(1, 10)
434
+ * .setOptions({
435
+ * allowBlank: false,
436
+ * showErrorMessage: true,
437
+ * error: 'Please enter a number between 1 and 10'
438
+ * })
439
+ * .build();
440
+ * fRange.setDataValidation(rule);
441
+ * ```
442
+ */
443
+ requireNumberBetween(e, t, i) {
444
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = u.BETWEEN, this._rule.type = i ? a.WHOLE : a.DECIMAL, this;
445
+ }
446
+ /**
447
+ * Sets the data validation rule to require a number equal to the given value.
448
+ * @param {number} num - The sole acceptable value.
449
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
450
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
451
+ * @example
452
+ * ```typescript
453
+ * const fWorkbook = univerAPI.getActiveWorkbook();
454
+ * const fWorksheet = fWorkbook.getActiveSheet();
455
+ *
456
+ * // Create a new data validation rule that requires a number equal to 10 for the range A1:B10
457
+ * const fRange = fWorksheet.getRange('A1:B10');
458
+ * const rule = univerAPI.newDataValidation()
459
+ * .requireNumberEqualTo(10)
460
+ * .setOptions({
461
+ * allowBlank: false,
462
+ * showErrorMessage: true,
463
+ * error: 'Please enter a number equal to 10'
464
+ * })
465
+ * .build();
466
+ * fRange.setDataValidation(rule);
467
+ * ```
468
+ */
469
+ requireNumberEqualTo(e, t) {
470
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = u.EQUAL, this._rule.type = t ? a.WHOLE : a.DECIMAL, this;
471
+ }
472
+ /**
473
+ * Sets the data validation rule to require a number greater than the given value.
474
+ * @param {number} num - The highest unacceptable value.
475
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
476
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
477
+ * @example
478
+ * ```typescript
479
+ * const fWorkbook = univerAPI.getActiveWorkbook();
480
+ * const fWorksheet = fWorkbook.getActiveSheet();
481
+ *
482
+ * // Create a new data validation rule that requires a number greater than 10 for the range A1:B10
483
+ * const fRange = fWorksheet.getRange('A1:B10');
484
+ * const rule = univerAPI.newDataValidation()
485
+ * .requireNumberGreaterThan(10)
486
+ * .setOptions({
487
+ * allowBlank: false,
488
+ * showErrorMessage: true,
489
+ * error: 'Please enter a number greater than 10'
490
+ * })
491
+ * .build();
492
+ * fRange.setDataValidation(rule);
493
+ * ```
494
+ */
495
+ requireNumberGreaterThan(e, t) {
496
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = u.GREATER_THAN, this._rule.type = t ? a.WHOLE : a.DECIMAL, this;
497
+ }
498
+ /**
499
+ * Sets the data validation rule to require a number greater than or equal to the given value.
500
+ * @param {number} num - The lowest acceptable value.
501
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
502
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
503
+ * @example
504
+ * ```typescript
505
+ * const fWorkbook = univerAPI.getActiveWorkbook();
506
+ * const fWorksheet = fWorkbook.getActiveSheet();
507
+ *
508
+ * // Create a new data validation rule that requires a number greater than 10 or equal to 10 for the range A1:B10
509
+ * const fRange = fWorksheet.getRange('A1:B10');
510
+ * const rule = univerAPI.newDataValidation()
511
+ * .requireNumberGreaterThanOrEqualTo(10)
512
+ * .setOptions({
513
+ * allowBlank: false,
514
+ * showErrorMessage: true,
515
+ * error: 'Please enter a number greater than 10 or equal to 10'
516
+ * })
517
+ * .build();
518
+ * fRange.setDataValidation(rule);
519
+ * ```
520
+ */
521
+ requireNumberGreaterThanOrEqualTo(e, t) {
522
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = u.GREATER_THAN_OR_EQUAL, this._rule.type = t ? a.WHOLE : a.DECIMAL, this;
523
+ }
524
+ /**
525
+ * Sets the data validation rule to require a number less than the given value.
526
+ * @param {number} num - The lowest unacceptable value.
527
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
528
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
529
+ * @example
530
+ * ```typescript
531
+ * const fWorkbook = univerAPI.getActiveWorkbook();
532
+ * const fWorksheet = fWorkbook.getActiveSheet();
533
+ *
534
+ * // Create a new data validation rule that requires a number less than 10 for the range A1:B10
535
+ * const fRange = fWorksheet.getRange('A1:B10');
536
+ * const rule = univerAPI.newDataValidation()
537
+ * .requireNumberLessThan(10)
538
+ * .setOptions({
539
+ * allowBlank: false,
540
+ * showErrorMessage: true,
541
+ * error: 'Please enter a number less than 10'
542
+ * })
543
+ * .build();
544
+ * fRange.setDataValidation(rule);
545
+ * ```
546
+ */
547
+ requireNumberLessThan(e, t) {
548
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = u.LESS_THAN, this._rule.type = t ? a.WHOLE : a.DECIMAL, this;
549
+ }
550
+ /**
551
+ * Sets the data validation rule to require a number less than or equal to the given value.
552
+ * @param {number} num - The highest acceptable value.
553
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
554
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
555
+ * @example
556
+ * ```typescript
557
+ * const fWorkbook = univerAPI.getActiveWorkbook();
558
+ * const fWorksheet = fWorkbook.getActiveSheet();
559
+ *
560
+ * // Create a new data validation rule that requires a number less than 10 or equal to 10 for the range A1:B10
561
+ * const fRange = fWorksheet.getRange('A1:B10');
562
+ * const rule = univerAPI.newDataValidation()
563
+ * .requireNumberLessThanOrEqualTo(10)
564
+ * .setOptions({
565
+ * allowBlank: false,
566
+ * showErrorMessage: true,
567
+ * error: 'Please enter a number less than 10 or equal to 10'
568
+ * })
569
+ * .build();
570
+ * fRange.setDataValidation(rule);
571
+ * ```
572
+ */
573
+ requireNumberLessThanOrEqualTo(e, t) {
574
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = u.LESS_THAN_OR_EQUAL, this._rule.type = t ? a.WHOLE : a.DECIMAL, this;
575
+ }
576
+ /**
577
+ * Sets the data validation rule to require a number that does not fall between, and is neither of, two specified numbers.
578
+ * @param {number} start - The lowest unacceptable value.
579
+ * @param {number} end - The highest unacceptable value.
580
+ * @param {boolean} [isInteger] - Optional parameter, indicating whether the number to be verified is an integer.
581
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
582
+ * @example
583
+ * ```typescript
584
+ * const fWorkbook = univerAPI.getActiveWorkbook();
585
+ * const fWorksheet = fWorkbook.getActiveSheet();
586
+ *
587
+ * // Create a new data validation rule that requires a number not between 1 and 10 for the range A1:B10
588
+ * const fRange = fWorksheet.getRange('A1:B10');
589
+ * const rule = univerAPI.newDataValidation()
590
+ * .requireNumberNotBetween(1, 10)
591
+ * .setOptions({
592
+ * allowBlank: false,
593
+ * showErrorMessage: true,
594
+ * error: 'Please enter a number not between 1 and 10'
595
+ * })
596
+ * .build();
597
+ * fRange.setDataValidation(rule);
598
+ * ```
599
+ */
600
+ requireNumberNotBetween(e, t, i) {
601
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = u.NOT_BETWEEN, this._rule.type = i ? a.WHOLE : a.DECIMAL, this;
602
+ }
603
+ /**
604
+ * Sets the data validation rule to require a number not equal to the given value.
605
+ * @param {number} num - The sole unacceptable value.
606
+ * @param {boolean} [isInteger] - Indicates whether the required number is an integer.
607
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
608
+ * @example
609
+ * ```typescript
610
+ * const fWorkbook = univerAPI.getActiveWorkbook();
611
+ * const fWorksheet = fWorkbook.getActiveSheet();
612
+ *
613
+ * // Create a new data validation rule that requires a number not equal to 10 for the range A1:B10
614
+ * const fRange = fWorksheet.getRange('A1:B10');
615
+ * const rule = univerAPI.newDataValidation()
616
+ * .requireNumberNotEqualTo(10)
617
+ * .setOptions({
618
+ * allowBlank: false,
619
+ * showErrorMessage: true,
620
+ * error: 'Please enter a number not equal to 10'
621
+ * })
622
+ * .build();
623
+ * fRange.setDataValidation(rule);
624
+ * ```
625
+ */
626
+ requireNumberNotEqualTo(e, t) {
627
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = u.NOT_EQUAL, this._rule.type = t ? a.WHOLE : a.DECIMAL, this;
628
+ }
629
+ /**
630
+ * Sets a data validation rule that requires the user to enter a value from a list of specific values.
631
+ * The list can be displayed in a dropdown, and the user can choose multiple values according to the settings.
632
+ * @param {string[]} values - An array of acceptable values.
633
+ * @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values.
634
+ * @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown.
635
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
636
+ * @example
637
+ * ```typescript
638
+ * const fWorkbook = univerAPI.getActiveWorkbook();
639
+ * const fWorksheet = fWorkbook.getActiveSheet();
640
+ *
641
+ * // Create a new data validation rule that requires the user to enter a value from the list ['Yes', 'No'] for the range A1:B10
642
+ * const fRange = fWorksheet.getRange('A1:B10');
643
+ * const rule = univerAPI.newDataValidation()
644
+ * .requireValueInList(['Yes', 'No'])
645
+ * .setOptions({
646
+ * allowBlank: true,
647
+ * showErrorMessage: true,
648
+ * error: 'Please enter a value from the list'
649
+ * })
650
+ * .build();
651
+ * fRange.setDataValidation(rule);
652
+ * ```
653
+ */
654
+ requireValueInList(e, t, i) {
655
+ return this._rule.type = t ? a.LIST_MULTIPLE : a.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = i != null ? i : !0, this;
656
+ }
657
+ /**
658
+ * Sets a data validation rule that requires the user to enter a value within a specific range.
659
+ * The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range.
660
+ * @param {FRange} range - An FRange object representing the range of values that the user can enter.
661
+ * @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values.
662
+ * @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown.
663
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
664
+ * @example
665
+ * ```typescript
666
+ * const fWorkbook = univerAPI.getActiveWorkbook();
667
+ * const fWorksheet = fWorkbook.getActiveSheet();
668
+ *
669
+ * // Set the values in the range B1:B2
670
+ * const fRange = fWorksheet.getRange('B1:B2');
671
+ * fRange.setValues([
672
+ * ['Yes'],
673
+ * ['No']
674
+ * ]);
675
+ *
676
+ * // Create a new data validation rule that requires the user to enter a value from the range B1:B2 for the range A1:A10
677
+ * const rule = univerAPI.newDataValidation()
678
+ * .requireValueInRange(fRange)
679
+ * .setOptions({
680
+ * allowBlank: false,
681
+ * showErrorMessage: true,
682
+ * error: 'Please enter a value from the list'
683
+ * })
684
+ * .build();
685
+ * const cell = fWorksheet.getRange('A1');
686
+ * cell.setDataValidation(rule);
687
+ * ```
688
+ */
689
+ requireValueInRange(e, t, i) {
690
+ return this._rule.type = t ? a.LIST_MULTIPLE : a.LIST, this._rule.formula1 = `=${F({
691
+ unitId: e.getUnitId(),
692
+ sheetName: e.getSheetName(),
693
+ range: e.getRange()
694
+ })}`, this._rule.formula2 = void 0, this._rule.showDropDown = i != null ? i : !0, this;
695
+ }
696
+ /**
697
+ * Sets whether to allow invalid data and configures the error style.
698
+ * If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error.
699
+ * If invalid data is allowed, the error style will be set to WARNING, indicating that a warning will be displayed when invalid data is entered, but data entry can continue.
700
+ * @param {boolean} allowInvalidData - Whether to allow invalid data.
701
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
702
+ * @example
703
+ * ```typescript
704
+ * const fWorkbook = univerAPI.getActiveWorkbook();
705
+ * const fWorksheet = fWorkbook.getActiveSheet();
706
+ *
707
+ * // Set the data validation for cell A1:B2 to allow invalid data, so A1:B2 will display a warning when invalid data is entered
708
+ * const fRange = fWorksheet.getRange('A1:B2');
709
+ * const rule = univerAPI.newDataValidation()
710
+ * .requireValueInList(['Yes', 'No'])
711
+ * .setAllowInvalid(true)
712
+ * .build();
713
+ * fRange.setDataValidation(rule);
714
+ *
715
+ * // 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
716
+ * const fRange2 = fWorksheet.getRange('C1:D2');
717
+ * const rule2 = univerAPI.newDataValidation()
718
+ * .requireValueInList(['Yes', 'No'])
719
+ * .setAllowInvalid(false)
720
+ * .build();
721
+ * fRange2.setDataValidation(rule2);
722
+ * ```
723
+ */
724
+ setAllowInvalid(e) {
725
+ return this._rule.errorStyle = e ? k.WARNING : k.STOP, this;
726
+ }
727
+ /**
728
+ * Sets whether to allow blank values.
729
+ * @param {boolean} allowBlank - Whether to allow blank values.
730
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
731
+ * @example
732
+ * ```typescript
733
+ * // Assume current sheet is empty data
734
+ * const fWorkbook = univerAPI.getActiveWorkbook();
735
+ * const fWorksheet = fWorkbook.getActiveSheet();
736
+ *
737
+ * // Set the data validation for cell A1:B2 to allow blank values
738
+ * const fRange = fWorksheet.getRange('A1:B2');
739
+ * const rule = univerAPI.newDataValidation()
740
+ * .requireValueInList(['Yes', 'No'])
741
+ * .setAllowBlank(true)
742
+ * .build();
743
+ * fRange.setDataValidation(rule);
744
+ *
745
+ * // Set the data validation for cell C1:D2 to not allow blank values
746
+ * const fRange2 = fWorksheet.getRange('C1:D2');
747
+ * const rule2 = univerAPI.newDataValidation()
748
+ * .requireValueInList(['Yes', 'No'])
749
+ * .setAllowBlank(false)
750
+ * .build();
751
+ * fRange2.setDataValidation(rule2);
752
+ * ```
753
+ */
754
+ setAllowBlank(e) {
755
+ return this._rule.allowBlank = e, this;
756
+ }
757
+ /**
758
+ * Sets the options for the data validation rule.
759
+ * @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule.
760
+ * @returns {FDataValidationBuilder} The current instance for method chaining.
761
+ * @example
762
+ * ```typescript
763
+ * const fWorkbook = univerAPI.getActiveWorkbook();
764
+ * const fWorksheet = fWorkbook.getActiveSheet();
765
+ *
766
+ * // Create a new data validation rule that requires the user to enter a value from the list ['Yes', 'No'] for the range A1:B10
767
+ * const fRange = fWorksheet.getRange('A1:B10');
768
+ * const rule = univerAPI.newDataValidation()
769
+ * .requireValueInList(['Yes', 'No'])
770
+ * .setOptions({
771
+ * allowBlank: true,
772
+ * showErrorMessage: true,
773
+ * error: 'Please enter a value from the list'
774
+ * })
775
+ * .build();
776
+ * fRange.setDataValidation(rule);
777
+ * ```
778
+ */
779
+ setOptions(e) {
780
+ return Object.assign(this._rule, e), this;
781
+ }
782
+ }
783
+ class m {
784
+ constructor(e, t, i) {
785
+ _(this, "rule");
786
+ _(this, "_worksheet");
787
+ _(this, "_injector");
788
+ this._injector = i, this.rule = e, this._worksheet = t;
789
+ }
790
+ /**
791
+ * Gets whether invalid data is allowed based on the error style value
792
+ * @returns {boolean} true if invalid data is allowed, false otherwise
793
+ * @example
794
+ * ```typescript
795
+ * const fWorkbook = univerAPI.getActiveWorkbook();
796
+ * const fWorksheet = fWorkbook.getActiveSheet();
797
+ * const rules = fWorksheet.getDataValidations();
798
+ * rules.forEach((rule) => {
799
+ * console.log(rule, rule.getAllowInvalid());
800
+ * });
801
+ * ```
802
+ */
803
+ getAllowInvalid() {
804
+ return this.rule.errorStyle !== k.STOP;
805
+ }
806
+ /**
807
+ * Gets the data validation type of the rule
808
+ * @returns {DataValidationType | string} The data validation type
809
+ * @example
810
+ * ```typescript
811
+ * const fWorkbook = univerAPI.getActiveWorkbook();
812
+ * const fWorksheet = fWorkbook.getActiveSheet();
813
+ * const rules = fWorksheet.getDataValidations();
814
+ * rules.forEach((rule) => {
815
+ * console.log(rule, rule.getCriteriaType());
816
+ * });
817
+ * ```
818
+ */
819
+ getCriteriaType() {
820
+ return this.rule.type;
821
+ }
822
+ /**
823
+ * Gets the values used for criteria evaluation
824
+ * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
825
+ * @example
826
+ * ```typescript
827
+ * const fWorkbook = univerAPI.getActiveWorkbook();
828
+ * const fWorksheet = fWorkbook.getActiveSheet();
829
+ * const rules = fWorksheet.getDataValidations();
830
+ * rules.forEach((rule) => {
831
+ * console.log(rule);
832
+ * const criteriaValues = rule.getCriteriaValues();
833
+ * const [operator, formula1, formula2] = criteriaValues;
834
+ * console.log(operator, formula1, formula2);
835
+ * });
836
+ * ```
837
+ */
838
+ getCriteriaValues() {
839
+ return [this.rule.operator, this.rule.formula1, this.rule.formula2];
840
+ }
841
+ /**
842
+ * Gets the help text information, which is used to provide users with guidance and support
843
+ * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
844
+ * @example
845
+ * ```typescript
846
+ * const fWorkbook = univerAPI.getActiveWorkbook();
847
+ * const fWorksheet = fWorkbook.getActiveSheet();
848
+ * const fRange = fWorksheet.getRange('A1:B10');
849
+ * const rule = univerAPI.newDataValidation()
850
+ * .requireNumberBetween(1, 10)
851
+ * .setOptions({
852
+ * allowBlank: true,
853
+ * showErrorMessage: true,
854
+ * error: 'Please enter a number between 1 and 10'
855
+ * })
856
+ * .build();
857
+ * fRange.setDataValidation(rule);
858
+ * console.log(fRange.getDataValidation().getHelpText()); // 'Please enter a number between 1 and 10'
859
+ * ```
860
+ */
861
+ getHelpText() {
862
+ return this.rule.error;
863
+ }
864
+ /**
865
+ * Creates a new instance of FDataValidationBuilder using the current rule object
866
+ * @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
867
+ * @example
868
+ * ```typescript
869
+ * const fWorkbook = univerAPI.getActiveWorkbook();
870
+ * const fWorksheet = fWorkbook.getActiveSheet();
871
+ * const fRange = fWorksheet.getRange('A1:B10');
872
+ * const rule = univerAPI.newDataValidation()
873
+ * .requireNumberBetween(1, 10)
874
+ * .setOptions({
875
+ * allowBlank: true,
876
+ * showErrorMessage: true,
877
+ * error: 'Please enter a number between 1 and 10'
878
+ * })
879
+ * .build();
880
+ * fRange.setDataValidation(rule);
881
+ *
882
+ * const builder = fRange.getDataValidation().copy();
883
+ * const newRule = builder
884
+ * .requireNumberBetween(1, 5)
885
+ * .setOptions({
886
+ * error: 'Please enter a number between 1 and 5'
887
+ * })
888
+ * .build();
889
+ * fRange.setDataValidation(newRule);
890
+ * ```
891
+ */
892
+ copy() {
893
+ return new E(this.rule);
894
+ }
895
+ /**
896
+ * Gets whether the data validation rule is applied to the worksheet
897
+ * @returns {boolean} true if the rule is applied, false otherwise
898
+ * @example
899
+ * ```typescript
900
+ * const fWorkbook = univerAPI.getActiveWorkbook();
901
+ * const fWorksheet = fWorkbook.getActiveSheet();
902
+ * const rules = fWorksheet.getDataValidations();
903
+ * rules.forEach((rule) => {
904
+ * console.log(rule, rule.getApplied());
905
+ * });
906
+ *
907
+ * const fRange = fWorksheet.getRange('A1:B10');
908
+ * console.log(fRange.getDataValidation()?.getApplied());
909
+ * ```
910
+ */
911
+ getApplied() {
912
+ if (!this._worksheet)
913
+ return !1;
914
+ const t = this._injector.get(w).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
915
+ return !!(t && t.ranges.length);
916
+ }
917
+ /**
918
+ * Gets the ranges to which the data validation rule is applied
919
+ * @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
920
+ * @example
921
+ * ```typescript
922
+ * const fWorkbook = univerAPI.getActiveWorkbook();
923
+ * const fWorksheet = fWorkbook.getActiveSheet();
924
+ * const rules = fWorksheet.getDataValidations();
925
+ * rules.forEach((rule) => {
926
+ * console.log(rule);
927
+ * const ranges = rule.getRanges();
928
+ * ranges.forEach((range) => {
929
+ * console.log(range.getA1Notation());
930
+ * });
931
+ * });
932
+ * ```
933
+ */
934
+ getRanges() {
935
+ if (!this.getApplied())
936
+ return [];
937
+ const e = this._injector.get(W).getUnit(this._worksheet.getUnitId());
938
+ return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
939
+ }
940
+ /**
941
+ * Gets the unit ID of the worksheet
942
+ * @returns {string | undefined} The unit ID of the worksheet
943
+ * @example
944
+ * ```typescript
945
+ * const fWorkbook = univerAPI.getActiveWorkbook();
946
+ * const fWorksheet = fWorkbook.getActiveSheet();
947
+ * const fRange = fWorksheet.getRange('A1:B10');
948
+ * console.log(fRange.getDataValidation().getUnitId());
949
+ * ```
950
+ */
951
+ getUnitId() {
952
+ var e;
953
+ return (e = this._worksheet) == null ? void 0 : e.getUnitId();
954
+ }
955
+ /**
956
+ * Gets the sheet ID of the worksheet
957
+ * @returns {string | undefined} The sheet ID of the worksheet
958
+ * @example
959
+ * ```typescript
960
+ * const fWorkbook = univerAPI.getActiveWorkbook();
961
+ * const fWorksheet = fWorkbook.getActiveSheet();
962
+ * const fRange = fWorksheet.getRange('A1:B10');
963
+ * console.log(fRange.getDataValidation().getSheetId());
964
+ * ```
965
+ */
966
+ getSheetId() {
967
+ var e;
968
+ return (e = this._worksheet) == null ? void 0 : e.getSheetId();
969
+ }
970
+ /**
971
+ * Set Criteria for the data validation rule
972
+ * @param {DataValidationType} type - The type of data validation criteria
973
+ * @param {[DataValidationOperator, string, string]} values - An array containing the operator, formula1, and formula2 values
974
+ * @param {boolean} [allowBlank] - Whether to allow blank values
975
+ * @returns {FDataValidation} The current instance for method chaining
976
+ * @example
977
+ * ```typescript
978
+ * const fWorkbook = univerAPI.getActiveWorkbook();
979
+ * const fWorksheet = fWorkbook.getActiveSheet();
980
+ *
981
+ * // Create a new data validation rule that requires a number equal to 20 for the range A1:B10
982
+ * const fRange = fWorksheet.getRange('A1:B10');
983
+ * const rule = univerAPI.newDataValidation()
984
+ * .requireNumberEqualTo(20)
985
+ * .build();
986
+ * fRange.setDataValidation(rule);
987
+ *
988
+ * // Change the rule criteria to require a number between 1 and 10
989
+ * fRange.getDataValidation().setCriteria(
990
+ * univerAPI.Enum.DataValidationType.DECIMAL,
991
+ * [univerAPI.Enum.DataValidationOperator.BETWEEN, '1', '10']
992
+ * );
993
+ * ```
994
+ */
995
+ setCriteria(e, t, i = !0) {
996
+ if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(b.id, {
997
+ unitId: this.getUnitId(),
998
+ subUnitId: this.getSheetId(),
999
+ ruleId: this.rule.uid,
1000
+ setting: {
1001
+ operator: t[0],
1002
+ formula1: t[1],
1003
+ formula2: t[2],
1004
+ type: this.rule.type,
1005
+ allowBlank: i
1006
+ }
1007
+ }))
1008
+ throw new Error("setCriteria failed");
1009
+ return this.rule.operator = t[0], this.rule.formula1 = t[1], this.rule.formula2 = t[2], this.rule.type = e, this.rule.allowBlank = i, this;
1010
+ }
1011
+ /**
1012
+ * Set the options for the data validation rule
1013
+ * @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
1014
+ * @returns {FDataValidation} The current instance for method chaining
1015
+ * @example
1016
+ * ```typescript
1017
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1018
+ * const fWorksheet = fWorkbook.getActiveSheet();
1019
+ *
1020
+ * // Create a new data validation rule that requires a number equal to 20 for the range A1:B10
1021
+ * const fRange = fWorksheet.getRange('A1:B10');
1022
+ * const rule = univerAPI.newDataValidation()
1023
+ * .requireNumberEqualTo(20)
1024
+ * .build();
1025
+ * fRange.setDataValidation(rule);
1026
+ *
1027
+ * // Supplement the rule with additional options
1028
+ * fRange.getDataValidation().setOptions({
1029
+ * allowBlank: true,
1030
+ * showErrorMessage: true,
1031
+ * error: 'Please enter a valid value'
1032
+ * });
1033
+ * ```
1034
+ */
1035
+ setOptions(e) {
1036
+ if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
1037
+ unitId: this.getUnitId(),
1038
+ subUnitId: this.getSheetId(),
1039
+ ruleId: this.rule.uid,
1040
+ options: {
1041
+ ...$(this.rule),
1042
+ ...e
1043
+ }
1044
+ }))
1045
+ throw new Error("setOptions failed");
1046
+ return Object.assign(this.rule, e), this;
1047
+ }
1048
+ /**
1049
+ * Set the ranges to the data validation rule
1050
+ * @param {FRange[]} ranges - New ranges array
1051
+ * @returns {FDataValidation} The current instance for method chaining
1052
+ * @example
1053
+ * ```typescript
1054
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1055
+ * const fWorksheet = fWorkbook.getActiveSheet();
1056
+ *
1057
+ * // Create a new data validation rule that requires a number equal to 20 for the range A1:B10
1058
+ * const fRange = fWorksheet.getRange('A1:B10');
1059
+ * const rule = univerAPI.newDataValidation()
1060
+ * .requireNumberEqualTo(20)
1061
+ * .build();
1062
+ * fRange.setDataValidation(rule);
1063
+ *
1064
+ * // Change the range to C1:D10
1065
+ * const newRuleRange = fWorksheet.getRange('C1:D10');
1066
+ * fRange.getDataValidation().setRanges([newRuleRange]);
1067
+ * ```
1068
+ */
1069
+ setRanges(e) {
1070
+ if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
1071
+ unitId: this.getUnitId(),
1072
+ subUnitId: this.getSheetId(),
1073
+ ruleId: this.rule.uid,
1074
+ ranges: e.map((r) => r.getRange())
1075
+ }))
1076
+ throw new Error("setRanges failed");
1077
+ return this.rule.ranges = e.map((t) => t.getRange()), this;
1078
+ }
1079
+ /**
1080
+ * Delete the data validation rule from the worksheet
1081
+ * @returns {boolean} true if the rule is deleted successfully, false otherwise
1082
+ * @example
1083
+ * ```typescript
1084
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1085
+ * const fWorksheet = fWorkbook.getActiveSheet();
1086
+ *
1087
+ * // Create a new data validation rule that requires a number equal to 20 for the range A1:B10
1088
+ * const fRange = fWorksheet.getRange('A1:B10');
1089
+ * const rule = univerAPI.newDataValidation()
1090
+ * .requireNumberEqualTo(20)
1091
+ * .build();
1092
+ * fRange.setDataValidation(rule);
1093
+ *
1094
+ * // Delete the data validation rule
1095
+ * fRange.getDataValidation().delete();
1096
+ * ```
1097
+ */
1098
+ delete() {
1099
+ return this.getApplied() ? this._injector.get(p).syncExecuteCommand(A.id, {
1100
+ unitId: this.getUnitId(),
1101
+ subUnitId: this.getSheetId(),
1102
+ ruleId: this.rule.uid
1103
+ }) : !1;
1104
+ }
1105
+ }
1106
+ class G extends y {
1107
+ setDataValidation(e) {
1108
+ if (!e)
1109
+ return this._commandService.syncExecuteCommand(j.id, {
1110
+ unitId: this._workbook.getUnitId(),
1111
+ subUnitId: this._worksheet.getSheetId(),
1112
+ ranges: [this._range]
1113
+ }), this;
1114
+ const t = {
1115
+ unitId: this._workbook.getUnitId(),
1116
+ subUnitId: this._worksheet.getSheetId(),
1117
+ rule: {
1118
+ ...e.rule,
1119
+ ranges: [this._range]
1120
+ }
1121
+ };
1122
+ return this._commandService.syncExecuteCommand(T.id, t), this;
1123
+ }
1124
+ getDataValidation() {
1125
+ const t = this._injector.get(S).getDataValidation(
1126
+ this._workbook.getUnitId(),
1127
+ this._worksheet.getSheetId(),
1128
+ [this._range]
1129
+ );
1130
+ return t && new m(t, this._worksheet, this._injector);
1131
+ }
1132
+ getDataValidations() {
1133
+ return this._injector.get(S).getDataValidations(
1134
+ this._workbook.getUnitId(),
1135
+ this._worksheet.getSheetId(),
1136
+ [this._range]
1137
+ ).map((t) => new m(t, this._worksheet, this._injector));
1138
+ }
1139
+ async getValidatorStatus() {
1140
+ return this._injector.get(S).validatorRanges(
1141
+ this._workbook.getUnitId(),
1142
+ this._worksheet.getSheetId(),
1143
+ [this._range]
1144
+ );
1145
+ }
1146
+ }
1147
+ y.extend(G);
1148
+ class Q extends N {
1149
+ /**
1150
+ * @deprecated use `univerAPI.newDataValidation()` as instead.
1151
+ * @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
1152
+ */
1153
+ static newDataValidation() {
1154
+ return new E();
1155
+ }
1156
+ newDataValidation() {
1157
+ return new E();
1158
+ }
1159
+ /**
1160
+ * @ignore
1161
+ */
1162
+ // eslint-disable-next-line max-lines-per-function
1163
+ _initialize(e) {
1164
+ const t = e.get(p);
1165
+ this.registerEventHandler(
1166
+ this.Event.SheetDataValidationChanged,
1167
+ () => e.has(f) ? e.get(f).ruleChange$.subscribe((r) => {
1168
+ const { unitId: o, subUnitId: l, rule: s, oldRule: n, type: d } = r, D = this.getSheetTarget(o, l);
1169
+ if (!D)
1170
+ return;
1171
+ const { workbook: I, worksheet: V } = D, v = new m(s, V.getSheet(), this._injector);
1172
+ this.fireEvent(this.Event.SheetDataValidationChanged, {
1173
+ origin: r,
1174
+ worksheet: V,
1175
+ workbook: I,
1176
+ changeType: d,
1177
+ oldRule: n,
1178
+ rule: v
1179
+ });
1180
+ }) : { dispose: () => {
1181
+ } }
1182
+ ), this.registerEventHandler(
1183
+ this.Event.SheetDataValidatorStatusChanged,
1184
+ () => e.has(f) ? e.get(f).validStatusChange$.subscribe((r) => {
1185
+ const { unitId: o, subUnitId: l, ruleId: s, status: n, row: d, col: D } = r, I = this.getSheetTarget(o, l);
1186
+ if (!I)
1187
+ return;
1188
+ const { workbook: V, worksheet: v } = I, B = v.getDataValidation(s);
1189
+ B && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
1190
+ workbook: V,
1191
+ worksheet: v,
1192
+ row: d,
1193
+ column: D,
1194
+ rule: B,
1195
+ status: n
1196
+ });
1197
+ }) : { dispose: () => {
1198
+ } }
1199
+ ), this.registerEventHandler(
1200
+ this.Event.BeforeSheetDataValidationAdd,
1201
+ () => t.beforeCommandExecuted((i) => {
1202
+ if (i.id === T.id) {
1203
+ const r = i.params, o = this.getSheetTarget(r.unitId, r.subUnitId);
1204
+ if (!o)
1205
+ return;
1206
+ const { workbook: l, worksheet: s } = o, n = {
1207
+ worksheet: s,
1208
+ workbook: l,
1209
+ rule: r.rule
1210
+ };
1211
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, n), n.cancel)
1212
+ throw new c();
1213
+ }
1214
+ })
1215
+ ), this.registerEventHandler(
1216
+ this.Event.BeforeSheetDataValidationCriteriaUpdate,
1217
+ () => t.beforeCommandExecuted((i) => {
1218
+ if (i.id === b.id) {
1219
+ const r = i.params, o = this.getSheetTarget(r.unitId, r.subUnitId);
1220
+ if (!o)
1221
+ return;
1222
+ const { workbook: l, worksheet: s } = o, n = s.getDataValidation(r.ruleId);
1223
+ if (!n)
1224
+ return;
1225
+ const d = {
1226
+ worksheet: s,
1227
+ workbook: l,
1228
+ rule: n,
1229
+ ruleId: r.ruleId,
1230
+ newCriteria: r.setting
1231
+ };
1232
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, d), d.cancel)
1233
+ throw new c();
1234
+ }
1235
+ })
1236
+ ), this.registerEventHandler(
1237
+ this.Event.BeforeSheetDataValidationRangeUpdate,
1238
+ () => t.beforeCommandExecuted((i) => {
1239
+ if (i.id === C.id) {
1240
+ const r = i.params, o = this.getSheetTarget(r.unitId, r.subUnitId);
1241
+ if (!o)
1242
+ return;
1243
+ const { workbook: l, worksheet: s } = o, n = s.getDataValidation(r.ruleId);
1244
+ if (!n)
1245
+ return;
1246
+ const d = {
1247
+ worksheet: s,
1248
+ workbook: l,
1249
+ rule: n,
1250
+ ruleId: r.ruleId,
1251
+ newRanges: r.ranges
1252
+ };
1253
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, d), d.cancel)
1254
+ throw new c();
1255
+ }
1256
+ })
1257
+ ), this.registerEventHandler(
1258
+ this.Event.BeforeSheetDataValidationOptionsUpdate,
1259
+ () => t.beforeCommandExecuted((i) => {
1260
+ if (i.id === U.id) {
1261
+ const r = i.params, o = this.getSheetTarget(r.unitId, r.subUnitId);
1262
+ if (!o)
1263
+ return;
1264
+ const { workbook: l, worksheet: s } = o, n = s.getDataValidation(r.ruleId);
1265
+ if (!n)
1266
+ return;
1267
+ const d = {
1268
+ worksheet: s,
1269
+ workbook: l,
1270
+ rule: n,
1271
+ ruleId: r.ruleId,
1272
+ newOptions: r.options
1273
+ };
1274
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, d), d.cancel)
1275
+ throw new c();
1276
+ }
1277
+ })
1278
+ ), this.registerEventHandler(
1279
+ this.Event.BeforeSheetDataValidationDelete,
1280
+ () => t.beforeCommandExecuted((i) => {
1281
+ if (i.id === A.id) {
1282
+ const r = i.params, o = this.getSheetTarget(r.unitId, r.subUnitId);
1283
+ if (!o)
1284
+ return;
1285
+ const { workbook: l, worksheet: s } = o, n = s.getDataValidation(r.ruleId);
1286
+ if (!n)
1287
+ return;
1288
+ const d = {
1289
+ worksheet: s,
1290
+ workbook: l,
1291
+ rule: n,
1292
+ ruleId: r.ruleId
1293
+ };
1294
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, d), d.cancel)
1295
+ throw new c();
1296
+ }
1297
+ })
1298
+ ), this.registerEventHandler(
1299
+ this.Event.BeforeSheetDataValidationDeleteAll,
1300
+ () => t.beforeCommandExecuted((i) => {
1301
+ if (i.id === O.id) {
1302
+ const r = i.params, o = this.getSheetTarget(r.unitId, r.subUnitId);
1303
+ if (!o)
1304
+ return;
1305
+ const { workbook: l, worksheet: s } = o, n = {
1306
+ worksheet: s,
1307
+ workbook: l,
1308
+ rules: s.getDataValidations()
1309
+ };
1310
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, n), n.cancel)
1311
+ throw new c();
1312
+ }
1313
+ })
1314
+ );
1315
+ }
1316
+ }
1317
+ N.extend(Q);
1318
+ class z extends x {
1319
+ _initialize() {
1320
+ Object.defineProperty(this, "_dataValidationModel", {
1321
+ get() {
1322
+ return this._injector.get(f);
1323
+ }
1324
+ });
1325
+ }
1326
+ getValidatorStatus() {
1327
+ return this._injector.get(S).validatorWorkbook(this._workbook.getUnitId());
1328
+ }
1329
+ // region DataValidationHooks
1330
+ onDataValidationChange(e) {
1331
+ return g(this._dataValidationModel.ruleChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
1332
+ }
1333
+ onDataValidationStatusChange(e) {
1334
+ return g(this._dataValidationModel.validStatusChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
1335
+ }
1336
+ onBeforeAddDataValidation(e) {
1337
+ return g(this._commandService.beforeCommandExecuted((t, i) => {
1338
+ const r = t.params;
1339
+ if (t.id === T.id) {
1340
+ if (r.unitId !== this._workbook.getUnitId())
1341
+ return;
1342
+ if (e(r, i) === !1)
1343
+ throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
1344
+ }
1345
+ }));
1346
+ }
1347
+ onBeforeUpdateDataValidationCriteria(e) {
1348
+ return g(this._commandService.beforeCommandExecuted((t, i) => {
1349
+ const r = t.params;
1350
+ if (t.id === b.id) {
1351
+ if (r.unitId !== this._workbook.getUnitId())
1352
+ return;
1353
+ if (e(r, i) === !1)
1354
+ throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
1355
+ }
1356
+ }));
1357
+ }
1358
+ onBeforeUpdateDataValidationRange(e) {
1359
+ return g(this._commandService.beforeCommandExecuted((t, i) => {
1360
+ const r = t.params;
1361
+ if (t.id === C.id) {
1362
+ if (r.unitId !== this._workbook.getUnitId())
1363
+ return;
1364
+ if (e(r, i) === !1)
1365
+ throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
1366
+ }
1367
+ }));
1368
+ }
1369
+ onBeforeUpdateDataValidationOptions(e) {
1370
+ return g(this._commandService.beforeCommandExecuted((t, i) => {
1371
+ const r = t.params;
1372
+ if (t.id === U.id) {
1373
+ if (r.unitId !== this._workbook.getUnitId())
1374
+ return;
1375
+ if (e(r, i) === !1)
1376
+ throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
1377
+ }
1378
+ }));
1379
+ }
1380
+ onBeforeDeleteDataValidation(e) {
1381
+ return g(this._commandService.beforeCommandExecuted((t, i) => {
1382
+ const r = t.params;
1383
+ if (t.id === A.id) {
1384
+ if (r.unitId !== this._workbook.getUnitId())
1385
+ return;
1386
+ if (e(r, i) === !1)
1387
+ throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
1388
+ }
1389
+ }));
1390
+ }
1391
+ onBeforeDeleteAllDataValidation(e) {
1392
+ return g(this._commandService.beforeCommandExecuted((t, i) => {
1393
+ const r = t.params;
1394
+ if (t.id === O.id) {
1395
+ if (r.unitId !== this._workbook.getUnitId())
1396
+ return;
1397
+ if (e(r, i) === !1)
1398
+ throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
1399
+ }
1400
+ }));
1401
+ }
1402
+ }
1403
+ x.extend(z);
1404
+ class K extends M {
1405
+ getDataValidations() {
1406
+ return this._injector.get(w).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
1407
+ }
1408
+ getValidatorStatus() {
1409
+ return this._injector.get(S).validatorWorksheet(
1410
+ this._workbook.getUnitId(),
1411
+ this._worksheet.getSheetId()
1412
+ );
1413
+ }
1414
+ getValidatorStatusAsync() {
1415
+ return this.getValidatorStatus();
1416
+ }
1417
+ getDataValidation(e) {
1418
+ const i = this._injector.get(w).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
1419
+ return i ? new m(i, this._worksheet, this._injector) : null;
1420
+ }
1421
+ }
1422
+ M.extend(K);
1423
+ class X {
1424
+ get SheetDataValidationChanged() {
1425
+ return "SheetDataValidationChanged";
1426
+ }
1427
+ get SheetDataValidatorStatusChanged() {
1428
+ return "SheetDataValidatorStatusChanged";
1429
+ }
1430
+ get BeforeSheetDataValidationAdd() {
1431
+ return "BeforeSheetDataValidationAdd";
1432
+ }
1433
+ get BeforeSheetDataValidationDelete() {
1434
+ return "BeforeSheetDataValidationDelete";
1435
+ }
1436
+ get BeforeSheetDataValidationDeleteAll() {
1437
+ return "BeforeSheetDataValidationDeleteAll";
1438
+ }
1439
+ get BeforeSheetDataValidationCriteriaUpdate() {
1440
+ return "BeforeSheetDataValidationCriteriaUpdate";
1441
+ }
1442
+ get BeforeSheetDataValidationRangeUpdate() {
1443
+ return "BeforeSheetDataValidationRangeUpdate";
1444
+ }
1445
+ get BeforeSheetDataValidationOptionsUpdate() {
1446
+ return "BeforeSheetDataValidationOptionsUpdate";
1447
+ }
1448
+ }
1449
+ P.extend(X);
1450
+ export {
1451
+ m as FDataValidation,
1452
+ E as FDataValidationBuilder
1453
+ };