@univerjs/sheets-data-validation 0.5.4-nightly.202501151606 → 0.5.4-nightly.202501160647
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/es/facade.js +434 -170
- package/lib/types/facade/f-data-validation-builder.d.ts +236 -103
- package/lib/types/facade/f-data-validation.d.ts +155 -30
- package/lib/types/facade/f-range.d.ts +34 -7
- package/lib/types/facade/f-univer.d.ts +10 -1
- package/lib/types/facade/f-workbook.d.ts +8 -24
- package/lib/types/facade/f-worksheet.d.ts +9 -4
- package/lib/umd/facade.js +1 -1
- package/package.json +6 -6
package/lib/es/facade.js
CHANGED
|
@@ -2,8 +2,8 @@ var j = Object.defineProperty;
|
|
|
2
2
|
var q = (c, e, t) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
3
|
var f = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { UpdateSheetDataValidationSettingCommand as U, UpdateSheetDataValidationOptionsCommand as v, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as T, ClearRangeDataValidationCommand as W, AddSheetDataValidationCommand as A, SheetsDataValidationValidatorService as S, SheetDataValidationModel as V, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
|
|
5
|
-
import { FRange as y, FWorkbook as M, FWorksheet as
|
|
6
|
-
import { generateRandomId as B, DataValidationType as o, DataValidationErrorStyle as w, DataValidationOperator as
|
|
5
|
+
import { FRange as y, FWorkbook as M, FWorksheet as N } from "@univerjs/sheets/facade";
|
|
6
|
+
import { generateRandomId as B, DataValidationType as o, DataValidationErrorStyle as w, DataValidationOperator as h, IUniverInstanceService as H, ICommandService as p, FUniver as x, CanceledError as _, toDisposable as g, FEventName as $ } from "@univerjs/core";
|
|
7
7
|
import { DataValidationModel as b, getRuleOptions as F } from "@univerjs/data-validation";
|
|
8
8
|
import { serializeRangeToRefString as P } from "@univerjs/engine-formula";
|
|
9
9
|
import { filter as R } from "rxjs";
|
|
@@ -19,6 +19,11 @@ class D {
|
|
|
19
19
|
/**
|
|
20
20
|
* Builds an FDataValidation instance based on the _rule property of the current class
|
|
21
21
|
* @returns {FDataValidation} A new instance of the FDataValidation class
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const builder = univerAPI.newDataValidation();
|
|
25
|
+
* const validation = builder.requireNumberBetween(1, 10).build();
|
|
26
|
+
* ```
|
|
22
27
|
*/
|
|
23
28
|
build() {
|
|
24
29
|
return new m(this._rule);
|
|
@@ -26,6 +31,11 @@ class D {
|
|
|
26
31
|
/**
|
|
27
32
|
* Creates a duplicate of the current DataValidationBuilder object
|
|
28
33
|
* @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const builder = univerAPI.newDataValidation();
|
|
37
|
+
* const copy = builder.requireNumberBetween(1, 10).copy();
|
|
38
|
+
* ```
|
|
29
39
|
*/
|
|
30
40
|
copy() {
|
|
31
41
|
return new D({
|
|
@@ -36,207 +46,321 @@ class D {
|
|
|
36
46
|
/**
|
|
37
47
|
* Determines whether invalid data is allowed
|
|
38
48
|
* @returns {boolean} True if invalid data is allowed, False otherwise
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const builder = univerAPI.newDataValidation();
|
|
52
|
+
* const allowsInvalid = builder.getAllowInvalid();
|
|
53
|
+
* ```
|
|
39
54
|
*/
|
|
40
55
|
getAllowInvalid() {
|
|
41
56
|
return this._rule.errorStyle !== w.STOP;
|
|
42
57
|
}
|
|
43
58
|
/**
|
|
44
59
|
* Gets the data validation type of the rule
|
|
45
|
-
* @returns {DataValidationType} The data validation type
|
|
60
|
+
* @returns {DataValidationType | string} The data validation type
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const builder = univerAPI.newDataValidation();
|
|
64
|
+
* const type = builder.getCriteriaType();
|
|
65
|
+
* ```
|
|
46
66
|
*/
|
|
47
67
|
getCriteriaType() {
|
|
48
68
|
return this._rule.type;
|
|
49
69
|
}
|
|
50
70
|
/**
|
|
51
71
|
* Gets the values used for criteria evaluation
|
|
52
|
-
* @returns {[string, string, string]} An array containing the operator, formula1, and formula2 values
|
|
72
|
+
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const builder = univerAPI.newDataValidation();
|
|
76
|
+
* const [operator, formula1, formula2] = builder.getCriteriaValues();
|
|
77
|
+
* ```
|
|
53
78
|
*/
|
|
54
79
|
getCriteriaValues() {
|
|
55
80
|
return [this._rule.operator, this._rule.formula1, this._rule.formula2];
|
|
56
81
|
}
|
|
57
82
|
/**
|
|
58
83
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
59
|
-
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
84
|
+
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const builder = univerAPI.newDataValidation();
|
|
88
|
+
* const helpText = builder.getHelpText();
|
|
89
|
+
* ```
|
|
60
90
|
*/
|
|
61
91
|
getHelpText() {
|
|
62
92
|
return this._rule.error;
|
|
63
93
|
}
|
|
64
94
|
/**
|
|
65
95
|
* Sets the data validation type to CHECKBOX and sets the checked and unchecked values
|
|
66
|
-
* @param checkedValue The value when the checkbox is checked
|
|
67
|
-
* @param uncheckedValue The value when the checkbox is unchecked
|
|
68
|
-
* @returns The current instance
|
|
96
|
+
* @param {string} [checkedValue] - The value when the checkbox is checked
|
|
97
|
+
* @param {string} [uncheckedValue] - The value when the checkbox is unchecked
|
|
98
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const builder = univerAPI.newDataValidation();
|
|
102
|
+
* const rule = builder.requireCheckbox('Yes', 'No').build();
|
|
103
|
+
* ```
|
|
69
104
|
*/
|
|
70
105
|
requireCheckbox(e, t) {
|
|
71
106
|
return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
|
|
72
107
|
}
|
|
73
108
|
/**
|
|
74
109
|
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
75
|
-
* @param date The date to compare against
|
|
76
|
-
* @returns The current instance
|
|
110
|
+
* @param {Date} date - The date to compare against
|
|
111
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const builder = univerAPI.newDataValidation();
|
|
115
|
+
* const rule = builder.requireDateAfter(new Date('2024-01-01')).build();
|
|
116
|
+
* ```
|
|
77
117
|
*/
|
|
78
118
|
requireDateAfter(e) {
|
|
79
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator =
|
|
119
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = h.GREATER_THAN, this;
|
|
80
120
|
}
|
|
81
121
|
/**
|
|
82
122
|
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
83
|
-
* @param date The date to compare against
|
|
84
|
-
* @returns The current instance
|
|
123
|
+
* @param {Date} date - The date to compare against
|
|
124
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const builder = univerAPI.newDataValidation();
|
|
128
|
+
* const rule = builder.requireDateBefore(new Date('2024-12-31')).build();
|
|
129
|
+
* ```
|
|
85
130
|
*/
|
|
86
131
|
requireDateBefore(e) {
|
|
87
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator =
|
|
132
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this;
|
|
88
133
|
}
|
|
89
134
|
/**
|
|
90
135
|
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
91
|
-
* @param start The starting date of the range
|
|
92
|
-
* @param end The ending date of the range
|
|
93
|
-
* @returns The current instance
|
|
136
|
+
* @param {Date} start - The starting date of the range
|
|
137
|
+
* @param {Date} end - The ending date of the range
|
|
138
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const builder = univerAPI.newDataValidation();
|
|
142
|
+
* const rule = builder
|
|
143
|
+
* .requireDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
|
|
144
|
+
* .build();
|
|
145
|
+
* ```
|
|
94
146
|
*/
|
|
95
147
|
requireDateBetween(e, t) {
|
|
96
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator =
|
|
148
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = h.BETWEEN, this;
|
|
97
149
|
}
|
|
98
150
|
/**
|
|
99
151
|
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
100
|
-
* @param date The date to compare against
|
|
101
|
-
* @returns The current instance
|
|
152
|
+
* @param {Date} date - The date to compare against
|
|
153
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const builder = univerAPI.newDataValidation();
|
|
157
|
+
* const rule = builder.requireDateEqualTo(new Date('2024-01-01')).build();
|
|
158
|
+
* ```
|
|
102
159
|
*/
|
|
103
160
|
requireDateEqualTo(e) {
|
|
104
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator =
|
|
161
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this;
|
|
105
162
|
}
|
|
106
163
|
/**
|
|
107
164
|
* Set the data validation type to DATE and configure the validation rules to be not within a specific date range
|
|
108
|
-
* @param start The starting date of the date range
|
|
109
|
-
* @param end The ending date of the date range
|
|
110
|
-
* @returns The current instance
|
|
165
|
+
* @param {Date} start - The starting date of the date range
|
|
166
|
+
* @param {Date} end - The ending date of the date range
|
|
167
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const builder = univerAPI.newDataValidation();
|
|
171
|
+
* const rule = builder
|
|
172
|
+
* .requireDateNotBetween(new Date('2024-01-01'), new Date('2024-12-31'))
|
|
173
|
+
* .build();
|
|
174
|
+
* ```
|
|
111
175
|
*/
|
|
112
176
|
requireDateNotBetween(e, t) {
|
|
113
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator =
|
|
177
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = h.NOT_BETWEEN, this;
|
|
114
178
|
}
|
|
115
179
|
/**
|
|
116
180
|
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
117
|
-
* @param date The date to compare against
|
|
118
|
-
* @returns The current instance
|
|
181
|
+
* @param {Date} date - The date to compare against
|
|
182
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const builder = univerAPI.newDataValidation();
|
|
186
|
+
* const rule = builder.requireDateOnOrAfter(new Date('2024-01-01')).build();
|
|
187
|
+
* ```
|
|
119
188
|
*/
|
|
120
189
|
requireDateOnOrAfter(e) {
|
|
121
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator =
|
|
190
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this;
|
|
122
191
|
}
|
|
123
192
|
/**
|
|
124
193
|
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
125
|
-
* @param date The date to compare against
|
|
126
|
-
* @returns The current instance
|
|
194
|
+
* @param {Date} date - The date to compare against
|
|
195
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const builder = univerAPI.newDataValidation();
|
|
199
|
+
* const rule = builder.requireDateOnOrBefore(new Date('2024-12-31')).build();
|
|
200
|
+
* ```
|
|
127
201
|
*/
|
|
128
202
|
requireDateOnOrBefore(e) {
|
|
129
|
-
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator =
|
|
203
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this;
|
|
130
204
|
}
|
|
131
205
|
/**
|
|
132
|
-
* Requires that a custom formula be satisfied
|
|
133
|
-
*
|
|
134
|
-
* @
|
|
135
|
-
* @
|
|
206
|
+
* Requires that a custom formula be satisfied
|
|
207
|
+
* @param {string} formula - The formula string that needs to be satisfied
|
|
208
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const builder = univerAPI.newDataValidation();
|
|
212
|
+
* const rule = builder.requireFormulaSatisfied('=A1>0').build();
|
|
213
|
+
* ```
|
|
136
214
|
*/
|
|
137
215
|
requireFormulaSatisfied(e) {
|
|
138
216
|
return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
|
|
139
217
|
}
|
|
140
218
|
/**
|
|
141
|
-
* Requires the user to enter a number within a specific range, which can be integer or decimal
|
|
142
|
-
*
|
|
143
|
-
* @param
|
|
144
|
-
* @param
|
|
145
|
-
* @
|
|
146
|
-
* @
|
|
219
|
+
* Requires the user to enter a number within a specific range, which can be integer or decimal
|
|
220
|
+
* @param {number} start - The starting value of the number range
|
|
221
|
+
* @param {number} end - The ending value of the number range
|
|
222
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
223
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const builder = univerAPI.newDataValidation();
|
|
227
|
+
* const rule = builder.requireNumberBetween(1, 10).build();
|
|
228
|
+
* ```
|
|
147
229
|
*/
|
|
148
230
|
requireNumberBetween(e, t, r) {
|
|
149
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator =
|
|
231
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
|
|
150
232
|
}
|
|
151
233
|
/**
|
|
152
|
-
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
|
|
153
|
-
*
|
|
154
|
-
* @param
|
|
155
|
-
* @
|
|
156
|
-
* @
|
|
234
|
+
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
|
|
235
|
+
* @param {number} num - The number to which the entered number should be equal
|
|
236
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
237
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const builder = univerAPI.newDataValidation();
|
|
241
|
+
* const rule = builder.requireNumberEqualTo(10).build();
|
|
242
|
+
* ```
|
|
157
243
|
*/
|
|
158
244
|
requireNumberEqualTo(e, t) {
|
|
159
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
245
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
160
246
|
}
|
|
161
247
|
/**
|
|
162
|
-
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
|
|
163
|
-
*
|
|
164
|
-
* @param
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
248
|
+
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
|
|
249
|
+
* @param {number} num - The number to which the entered number should be greater
|
|
250
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
251
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const builder = univerAPI.newDataValidation();
|
|
255
|
+
* const rule = builder.requireNumberGreaterThan(10).build();
|
|
256
|
+
* ```
|
|
167
257
|
*/
|
|
168
258
|
requireNumberGreaterThan(e, t) {
|
|
169
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
259
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
170
260
|
}
|
|
171
261
|
/**
|
|
172
|
-
* Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal
|
|
173
|
-
*
|
|
174
|
-
* @param
|
|
175
|
-
* @
|
|
176
|
-
* @
|
|
262
|
+
* Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal
|
|
263
|
+
* @param {number} num - The number to which the entered number should be greater than or equal
|
|
264
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
265
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const builder = univerAPI.newDataValidation();
|
|
269
|
+
* const rule = builder.requireNumberGreaterThanOrEqualTo(10).build();
|
|
270
|
+
* ```
|
|
177
271
|
*/
|
|
178
272
|
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
179
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
273
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
180
274
|
}
|
|
181
275
|
/**
|
|
182
|
-
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
|
|
183
|
-
*
|
|
184
|
-
* @param
|
|
185
|
-
* @
|
|
186
|
-
* @
|
|
276
|
+
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
|
|
277
|
+
* @param {number} num - The number to which the entered number should be less
|
|
278
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
279
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const builder = univerAPI.newDataValidation();
|
|
283
|
+
* const rule = builder.requireNumberLessThan(10).build();
|
|
284
|
+
* ```
|
|
187
285
|
*/
|
|
188
286
|
requireNumberLessThan(e, t) {
|
|
189
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
287
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
190
288
|
}
|
|
191
289
|
/**
|
|
192
290
|
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
193
291
|
* The specified value can be an integer or a decimal
|
|
194
|
-
* @param num The number to which the entered number should be less than or equal
|
|
195
|
-
* @param isInteger Indicates whether the required number is an integer
|
|
196
|
-
* @returns The current instance
|
|
292
|
+
* @param {number} num - The number to which the entered number should be less than or equal
|
|
293
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
294
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const builder = univerAPI.newDataValidation();
|
|
298
|
+
* const rule = builder.requireNumberLessThanOrEqualTo(10).build();
|
|
299
|
+
* ```
|
|
197
300
|
*/
|
|
198
301
|
requireNumberLessThanOrEqualTo(e, t) {
|
|
199
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
302
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
200
303
|
}
|
|
201
304
|
/**
|
|
202
305
|
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
203
306
|
* The specified range includes all integers and decimals
|
|
204
|
-
* @param start The starting point of the specified range
|
|
205
|
-
* @param end The end point of the specified range
|
|
206
|
-
* @param isInteger Optional parameter, indicating whether the number to be verified is an integer
|
|
207
|
-
* @returns
|
|
307
|
+
* @param {number} start - The starting point of the specified range
|
|
308
|
+
* @param {number} end - The end point of the specified range
|
|
309
|
+
* @param {boolean} [isInteger] - Optional parameter, indicating whether the number to be verified is an integer
|
|
310
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* const builder = univerAPI.newDataValidation();
|
|
314
|
+
* const rule = builder.requireNumberNotBetween(1, 10).build();
|
|
315
|
+
* ```
|
|
208
316
|
*/
|
|
209
317
|
requireNumberNotBetween(e, t, r) {
|
|
210
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator =
|
|
318
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.NOT_BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
|
|
211
319
|
}
|
|
212
320
|
/**
|
|
213
321
|
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
214
322
|
* The specific value can be an integer or a decimal
|
|
215
|
-
* @param num The number to which the entered number should not be equal
|
|
216
|
-
* @param isInteger Indicates whether the required number is an integer
|
|
217
|
-
* @returns The current instance
|
|
323
|
+
* @param {number} num - The number to which the entered number should not be equal
|
|
324
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
325
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const builder = univerAPI.newDataValidation();
|
|
329
|
+
* const rule = builder.requireNumberNotEqualTo(10).build();
|
|
330
|
+
* ```
|
|
218
331
|
*/
|
|
219
332
|
requireNumberNotEqualTo(e, t) {
|
|
220
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
333
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.NOT_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
221
334
|
}
|
|
222
335
|
/**
|
|
223
|
-
* Sets a data validation rule that requires the user to enter a value from a list of specific values
|
|
224
|
-
* The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
|
|
225
|
-
* @param values An array containing the specific values that the user can enter
|
|
226
|
-
* @param multiple Optional parameter indicating whether the user can select multiple values
|
|
227
|
-
* @param showDropdown Optional parameter indicating whether to display the list in a dropdown
|
|
228
|
-
* @returns
|
|
336
|
+
* Sets a data validation rule that requires the user to enter a value from a list of specific values
|
|
337
|
+
* The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
|
|
338
|
+
* @param {string[]} values - An array containing the specific values that the user can enter
|
|
339
|
+
* @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
|
|
340
|
+
* @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
|
|
341
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const builder = univerAPI.newDataValidation();
|
|
345
|
+
* const rule = builder.requireValueInList(['Yes', 'No']).build();
|
|
346
|
+
* ```
|
|
229
347
|
*/
|
|
230
348
|
requireValueInList(e, t, r) {
|
|
231
349
|
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
|
|
232
350
|
}
|
|
233
351
|
/**
|
|
234
|
-
* Sets a data validation rule that requires the user to enter a value within a specific range
|
|
235
|
-
* The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
|
|
236
|
-
* @param range An FRange object representing the range of values that the user can enter
|
|
237
|
-
* @param multiple Optional parameter indicating whether the user can select multiple values
|
|
238
|
-
* @param showDropdown Optional parameter indicating whether to display the list in a dropdown
|
|
239
|
-
* @returns The current instance
|
|
352
|
+
* Sets a data validation rule that requires the user to enter a value within a specific range
|
|
353
|
+
* The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
|
|
354
|
+
* @param {FRange} range - An FRange object representing the range of values that the user can enter
|
|
355
|
+
* @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
|
|
356
|
+
* @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
|
|
357
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const builder = univerAPI.newDataValidation();
|
|
361
|
+
* const range = FRange.create('Sheet1', 'B1:B10');
|
|
362
|
+
* const rule = builder.requireValueInRange(range).build();
|
|
363
|
+
* ```
|
|
240
364
|
*/
|
|
241
365
|
requireValueInRange(e, t, r) {
|
|
242
366
|
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${P({
|
|
@@ -246,44 +370,46 @@ class D {
|
|
|
246
370
|
})}`, this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
|
|
247
371
|
}
|
|
248
372
|
/**
|
|
249
|
-
* Sets whether to allow invalid data and configures the error style
|
|
250
|
-
* If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error
|
|
251
|
-
* 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
|
|
252
|
-
* @param
|
|
253
|
-
* @returns The current instance
|
|
373
|
+
* Sets whether to allow invalid data and configures the error style
|
|
374
|
+
* If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error
|
|
375
|
+
* 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
|
|
376
|
+
* @param {boolean} allowInvalidData - Whether to allow invalid data
|
|
377
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* const builder = univerAPI.newDataValidation();
|
|
381
|
+
* const rule = builder.setAllowInvalid(true).build();
|
|
382
|
+
* ```
|
|
254
383
|
*/
|
|
255
384
|
setAllowInvalid(e) {
|
|
256
385
|
return this._rule.errorStyle = e ? w.WARNING : w.STOP, this;
|
|
257
386
|
}
|
|
258
387
|
/**
|
|
259
|
-
* Sets
|
|
260
|
-
*
|
|
261
|
-
* @
|
|
262
|
-
* @
|
|
388
|
+
* Sets whether to allow blank values
|
|
389
|
+
* @param {boolean} allowBlank - Whether to allow blank values
|
|
390
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* const builder = univerAPI.newDataValidation();
|
|
394
|
+
* const rule = builder.setAllowBlank(true).build();
|
|
395
|
+
* ```
|
|
263
396
|
*/
|
|
264
|
-
setHelpText(e) {
|
|
265
|
-
return this._rule.error = e, this._rule.showErrorMessage = !0, this;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Sets the criteria values for data validation.
|
|
269
|
-
* This method is used to configure the validation rules based on specific criteria values.
|
|
270
|
-
* @param type The type of data validation.
|
|
271
|
-
* @param values An array containing the criteria values.
|
|
272
|
-
* The array should have three elements: [operator, formula1, formula2].
|
|
273
|
-
* operator is a DataValidationOperator enum value, formula1 is the first formula, and formula2 is the second formula.
|
|
274
|
-
* @returns The current instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
275
|
-
*/
|
|
276
|
-
withCriteriaValues(e, t) {
|
|
277
|
-
return this._rule.type = e, this._rule.operator = t[0], this._rule.formula1 = t[1], this._rule.formula2 = t[2], this;
|
|
278
|
-
}
|
|
279
397
|
setAllowBlank(e) {
|
|
280
398
|
return this._rule.allowBlank = e, this;
|
|
281
399
|
}
|
|
282
400
|
/**
|
|
283
|
-
* Sets the options for the data validation rule
|
|
284
|
-
*
|
|
285
|
-
* @
|
|
286
|
-
* @
|
|
401
|
+
* Sets the options for the data validation rule
|
|
402
|
+
* @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
|
|
403
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const builder = univerAPI.newDataValidation();
|
|
407
|
+
* const rule = builder.setOptions({
|
|
408
|
+
* allowBlank: true,
|
|
409
|
+
* showErrorMessage: true,
|
|
410
|
+
* error: 'Please enter a valid value'
|
|
411
|
+
* }).build();
|
|
412
|
+
* ```
|
|
287
413
|
*/
|
|
288
414
|
setOptions(e) {
|
|
289
415
|
return Object.assign(this._rule, e), this;
|
|
@@ -297,44 +423,98 @@ class m {
|
|
|
297
423
|
this._injector = r, this.rule = e, this._worksheet = t;
|
|
298
424
|
}
|
|
299
425
|
/**
|
|
300
|
-
* Gets whether invalid data is allowed based on the error style value
|
|
301
|
-
* @returns true if invalid data is allowed, false otherwise
|
|
426
|
+
* Gets whether invalid data is allowed based on the error style value
|
|
427
|
+
* @returns {boolean} true if invalid data is allowed, false otherwise
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* const dataValidation = univerAPI
|
|
431
|
+
* .getActiveWorkbook()
|
|
432
|
+
* .getActiveWorksheet()
|
|
433
|
+
* .getActiveRange()
|
|
434
|
+
* .getDataValidation();
|
|
435
|
+
* const allowsInvalid = dataValidation.getAllowInvalid();
|
|
436
|
+
* ```
|
|
302
437
|
*/
|
|
303
438
|
getAllowInvalid() {
|
|
304
439
|
return this.rule.errorStyle !== w.STOP;
|
|
305
440
|
}
|
|
306
441
|
/**
|
|
307
442
|
* Gets the data validation type of the rule
|
|
308
|
-
* @returns The data validation type
|
|
443
|
+
* @returns {DataValidationType | string} The data validation type
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const dataValidation = univerAPI
|
|
447
|
+
* .getActiveWorkbook()
|
|
448
|
+
* .getActiveWorksheet()
|
|
449
|
+
* .getActiveRange()
|
|
450
|
+
* .getDataValidation();
|
|
451
|
+
* const type = dataValidation.getCriteriaType();
|
|
452
|
+
* ```
|
|
309
453
|
*/
|
|
310
454
|
getCriteriaType() {
|
|
311
455
|
return this.rule.type;
|
|
312
456
|
}
|
|
313
457
|
/**
|
|
314
458
|
* Gets the values used for criteria evaluation
|
|
315
|
-
* @returns An array containing the operator, formula1, and formula2 values
|
|
459
|
+
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
460
|
+
* @example
|
|
461
|
+
* ```typescript
|
|
462
|
+
* const dataValidation = univerAPI
|
|
463
|
+
* .getActiveWorkbook()
|
|
464
|
+
* .getActiveWorksheet()
|
|
465
|
+
* .getActiveRange()
|
|
466
|
+
* .getDataValidation();
|
|
467
|
+
* const [operator, formula1, formula2] = dataValidation.getCriteriaValues();
|
|
468
|
+
* ```
|
|
316
469
|
*/
|
|
317
470
|
getCriteriaValues() {
|
|
318
471
|
return [this.rule.operator, this.rule.formula1, this.rule.formula2];
|
|
319
472
|
}
|
|
320
473
|
/**
|
|
321
474
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
322
|
-
* @returns Returns the help text information. If there is no error message, it returns an undefined value
|
|
475
|
+
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
476
|
+
* @example
|
|
477
|
+
* ```typescript
|
|
478
|
+
* const dataValidation = univerAPI
|
|
479
|
+
* .getActiveWorkbook()
|
|
480
|
+
* .getActiveWorksheet()
|
|
481
|
+
* .getActiveRange()
|
|
482
|
+
* .getDataValidation();
|
|
483
|
+
* const helpText = dataValidation.getHelpText();
|
|
484
|
+
* ```
|
|
323
485
|
*/
|
|
324
486
|
getHelpText() {
|
|
325
487
|
return this.rule.error;
|
|
326
488
|
}
|
|
327
489
|
/**
|
|
328
|
-
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
329
|
-
*
|
|
330
|
-
* @
|
|
490
|
+
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
491
|
+
* @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* const dataValidation = univerAPI
|
|
495
|
+
* .getActiveWorkbook()
|
|
496
|
+
* .getActiveWorksheet()
|
|
497
|
+
* .getActiveRange()
|
|
498
|
+
* .getDataValidation();
|
|
499
|
+
* const builder = dataValidation.copy();
|
|
500
|
+
* const newRule = builder.setAllowInvalid(true).build();
|
|
501
|
+
* ```
|
|
331
502
|
*/
|
|
332
503
|
copy() {
|
|
333
504
|
return new D(this.rule);
|
|
334
505
|
}
|
|
335
506
|
/**
|
|
336
|
-
* Gets whether the data validation rule is applied to the worksheet
|
|
337
|
-
* @returns true if the rule is applied, false otherwise
|
|
507
|
+
* Gets whether the data validation rule is applied to the worksheet
|
|
508
|
+
* @returns {boolean} true if the rule is applied, false otherwise
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const dataValidation = univerAPI
|
|
512
|
+
* .getActiveWorkbook()
|
|
513
|
+
* .getActiveWorksheet()
|
|
514
|
+
* .getActiveRange()
|
|
515
|
+
* .getDataValidation();
|
|
516
|
+
* const isApplied = dataValidation.getApplied();
|
|
517
|
+
* ```
|
|
338
518
|
*/
|
|
339
519
|
getApplied() {
|
|
340
520
|
if (!this._worksheet)
|
|
@@ -343,8 +523,17 @@ class m {
|
|
|
343
523
|
return !!(t && t.ranges.length);
|
|
344
524
|
}
|
|
345
525
|
/**
|
|
346
|
-
* Gets the ranges to which the data validation rule is applied
|
|
347
|
-
* @returns An array of
|
|
526
|
+
* Gets the ranges to which the data validation rule is applied
|
|
527
|
+
* @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* const dataValidation = univerAPI
|
|
531
|
+
* .getActiveWorkbook()
|
|
532
|
+
* .getActiveWorksheet()
|
|
533
|
+
* .getActiveRange()
|
|
534
|
+
* .getDataValidation();
|
|
535
|
+
* const ranges = dataValidation.getRanges();
|
|
536
|
+
* ```
|
|
348
537
|
*/
|
|
349
538
|
getRanges() {
|
|
350
539
|
if (!this.getApplied())
|
|
@@ -353,27 +542,58 @@ class m {
|
|
|
353
542
|
return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
|
|
354
543
|
}
|
|
355
544
|
/**
|
|
356
|
-
* Gets the
|
|
357
|
-
* @returns The
|
|
545
|
+
* Gets the unit ID of the worksheet
|
|
546
|
+
* @returns {string | undefined} The unit ID of the worksheet
|
|
547
|
+
* @example
|
|
548
|
+
* ```typescript
|
|
549
|
+
* const dataValidation = univerAPI
|
|
550
|
+
* .getActiveWorkbook()
|
|
551
|
+
* .getActiveWorksheet()
|
|
552
|
+
* .getActiveRange()
|
|
553
|
+
* .getDataValidation();
|
|
554
|
+
* const unitId = dataValidation.getUnitId();
|
|
555
|
+
* ```
|
|
358
556
|
*/
|
|
359
557
|
getUnitId() {
|
|
360
558
|
var e;
|
|
361
559
|
return (e = this._worksheet) == null ? void 0 : e.getUnitId();
|
|
362
560
|
}
|
|
363
561
|
/**
|
|
364
|
-
* Gets the
|
|
365
|
-
* @returns The
|
|
562
|
+
* Gets the sheet ID of the worksheet
|
|
563
|
+
* @returns {string | undefined} The sheet ID of the worksheet
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* const dataValidation = univerAPI
|
|
567
|
+
* .getActiveWorkbook()
|
|
568
|
+
* .getActiveWorksheet()
|
|
569
|
+
* .getActiveRange()
|
|
570
|
+
* .getDataValidation();
|
|
571
|
+
* const sheetId = dataValidation.getSheetId();
|
|
572
|
+
* ```
|
|
366
573
|
*/
|
|
367
574
|
getSheetId() {
|
|
368
575
|
var e;
|
|
369
576
|
return (e = this._worksheet) == null ? void 0 : e.getSheetId();
|
|
370
577
|
}
|
|
371
578
|
/**
|
|
372
|
-
* Set Criteria for the data validation rule
|
|
373
|
-
* @param type The type of data validation criteria
|
|
374
|
-
* @param values An array containing the operator, formula1, and formula2 values
|
|
375
|
-
* @param allowBlank
|
|
376
|
-
* @returns
|
|
579
|
+
* Set Criteria for the data validation rule
|
|
580
|
+
* @param {DataValidationType} type - The type of data validation criteria
|
|
581
|
+
* @param {[DataValidationOperator, string, string]} values - An array containing the operator, formula1, and formula2 values
|
|
582
|
+
* @param {boolean} [allowBlank] - Whether to allow blank values
|
|
583
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* const dataValidation = univerAPI
|
|
587
|
+
* .getActiveWorkbook()
|
|
588
|
+
* .getActiveWorksheet()
|
|
589
|
+
* .getActiveRange()
|
|
590
|
+
* .getDataValidation();
|
|
591
|
+
* dataValidation.setCriteria(
|
|
592
|
+
* DataValidationType.DECIMAL,
|
|
593
|
+
* [DataValidationOperator.BETWEEN, '1', '10'],
|
|
594
|
+
* true
|
|
595
|
+
* );
|
|
596
|
+
* ```
|
|
377
597
|
*/
|
|
378
598
|
setCriteria(e, t, r = !0) {
|
|
379
599
|
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
|
|
@@ -392,10 +612,22 @@ class m {
|
|
|
392
612
|
return this.rule.operator = t[0], this.rule.formula1 = t[1], this.rule.formula2 = t[2], this.rule.type = e, this.rule.allowBlank = r, this;
|
|
393
613
|
}
|
|
394
614
|
/**
|
|
395
|
-
* Set the options for the data validation rule
|
|
396
|
-
*
|
|
397
|
-
* @
|
|
398
|
-
* @
|
|
615
|
+
* Set the options for the data validation rule
|
|
616
|
+
* @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
|
|
617
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* const dataValidation = univerAPI
|
|
621
|
+
* .getActiveWorkbook()
|
|
622
|
+
* .getActiveWorksheet()
|
|
623
|
+
* .getActiveRange()
|
|
624
|
+
* .getDataValidation();
|
|
625
|
+
* dataValidation.setOptions({
|
|
626
|
+
* allowBlank: true,
|
|
627
|
+
* showErrorMessage: true,
|
|
628
|
+
* error: 'Please enter a valid value'
|
|
629
|
+
* });
|
|
630
|
+
* ```
|
|
399
631
|
*/
|
|
400
632
|
setOptions(e) {
|
|
401
633
|
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(v.id, {
|
|
@@ -411,9 +643,19 @@ class m {
|
|
|
411
643
|
return Object.assign(this.rule, e), this;
|
|
412
644
|
}
|
|
413
645
|
/**
|
|
414
|
-
* Set the ranges to the data validation rule
|
|
415
|
-
* @param ranges
|
|
416
|
-
* @returns
|
|
646
|
+
* Set the ranges to the data validation rule
|
|
647
|
+
* @param {FRange[]} ranges - New ranges array
|
|
648
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
649
|
+
* @example
|
|
650
|
+
* ```typescript
|
|
651
|
+
* const dataValidation = univerAPI
|
|
652
|
+
* .getActiveWorkbook()
|
|
653
|
+
* .getActiveWorksheet()
|
|
654
|
+
* .getActiveRange()
|
|
655
|
+
* .getDataValidation();
|
|
656
|
+
* const range = FRange.create('Sheet1', 'A1:B10');
|
|
657
|
+
* dataValidation.setRanges([range]);
|
|
658
|
+
* ```
|
|
417
659
|
*/
|
|
418
660
|
setRanges(e) {
|
|
419
661
|
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
|
|
@@ -426,8 +668,17 @@ class m {
|
|
|
426
668
|
return this.rule.ranges = e.map((t) => t.getRange()), this;
|
|
427
669
|
}
|
|
428
670
|
/**
|
|
429
|
-
* Delete the data validation rule from the worksheet
|
|
430
|
-
* @returns true if the rule is deleted successfully, false otherwise
|
|
671
|
+
* Delete the data validation rule from the worksheet
|
|
672
|
+
* @returns {boolean} true if the rule is deleted successfully, false otherwise
|
|
673
|
+
* @example
|
|
674
|
+
* ```typescript
|
|
675
|
+
* const dataValidation = univerAPI
|
|
676
|
+
* .getActiveWorkbook()
|
|
677
|
+
* .getActiveWorksheet()
|
|
678
|
+
* .getActiveRange()
|
|
679
|
+
* .getDataValidation();
|
|
680
|
+
* const isDeleted = dataValidation.delete();
|
|
681
|
+
* ```
|
|
431
682
|
*/
|
|
432
683
|
delete() {
|
|
433
684
|
return this.getApplied() ? this._injector.get(p).syncExecuteCommand(T.id, {
|
|
@@ -479,14 +730,24 @@ class G extends y {
|
|
|
479
730
|
}
|
|
480
731
|
}
|
|
481
732
|
y.extend(G);
|
|
482
|
-
class Q extends
|
|
733
|
+
class Q extends x {
|
|
734
|
+
// eslint-disable-next-line jsdoc/require-returns
|
|
483
735
|
/**
|
|
484
736
|
/**
|
|
485
|
-
* @
|
|
737
|
+
* @deprecated use `univerAPI.newDataValidation()` as instead.
|
|
486
738
|
*/
|
|
487
739
|
static newDataValidation() {
|
|
488
740
|
return new D();
|
|
489
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* Creates a new instance of FDataValidationBuilder
|
|
744
|
+
* @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
|
|
745
|
+
* @example
|
|
746
|
+
* ```ts
|
|
747
|
+
* const rule = FUnvier.newDataValidation();
|
|
748
|
+
* cell.setDataValidation(rule.requireValueInRange(range));
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
490
751
|
newDataValidation() {
|
|
491
752
|
return new D();
|
|
492
753
|
}
|
|
@@ -495,10 +756,10 @@ class Q extends N {
|
|
|
495
756
|
if (!e.has(V)) return;
|
|
496
757
|
const t = e.get(V), r = e.get(p);
|
|
497
758
|
this.disposeWithMe(t.ruleChange$.subscribe((a) => {
|
|
498
|
-
const { unitId: i, subUnitId: n, rule:
|
|
759
|
+
const { unitId: i, subUnitId: n, rule: d, oldRule: u, type: s } = a, l = this.getSheetTarget(i, n);
|
|
499
760
|
if (!l)
|
|
500
761
|
return;
|
|
501
|
-
const { workbook: I, worksheet: k } = l, E = new m(
|
|
762
|
+
const { workbook: I, worksheet: k } = l, E = new m(d, k.getSheet(), this._injector);
|
|
502
763
|
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
503
764
|
origin: a,
|
|
504
765
|
worksheet: k,
|
|
@@ -508,10 +769,10 @@ class Q extends N {
|
|
|
508
769
|
rule: E
|
|
509
770
|
});
|
|
510
771
|
})), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
|
|
511
|
-
const { unitId: i, subUnitId: n, ruleId:
|
|
772
|
+
const { unitId: i, subUnitId: n, ruleId: d, status: u, row: s, col: l } = a, I = this.getSheetTarget(i, n);
|
|
512
773
|
if (!I)
|
|
513
774
|
return;
|
|
514
|
-
const { workbook: k, worksheet: E } = I, L = E.getDataValidation(
|
|
775
|
+
const { workbook: k, worksheet: E } = I, L = E.getDataValidation(d);
|
|
515
776
|
L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
|
|
516
777
|
workbook: k,
|
|
517
778
|
worksheet: E,
|
|
@@ -526,9 +787,9 @@ class Q extends N {
|
|
|
526
787
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
527
788
|
if (!n)
|
|
528
789
|
return;
|
|
529
|
-
const { workbook:
|
|
790
|
+
const { workbook: d, worksheet: u } = n, s = {
|
|
530
791
|
worksheet: u,
|
|
531
|
-
workbook:
|
|
792
|
+
workbook: d,
|
|
532
793
|
rule: i.rule
|
|
533
794
|
};
|
|
534
795
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
|
|
@@ -539,12 +800,12 @@ class Q extends N {
|
|
|
539
800
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
540
801
|
if (!n)
|
|
541
802
|
return;
|
|
542
|
-
const { workbook:
|
|
803
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
543
804
|
if (!s)
|
|
544
805
|
return;
|
|
545
806
|
const l = {
|
|
546
807
|
worksheet: u,
|
|
547
|
-
workbook:
|
|
808
|
+
workbook: d,
|
|
548
809
|
rule: s,
|
|
549
810
|
ruleId: i.ruleId,
|
|
550
811
|
newCriteria: i.setting
|
|
@@ -557,12 +818,12 @@ class Q extends N {
|
|
|
557
818
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
558
819
|
if (!n)
|
|
559
820
|
return;
|
|
560
|
-
const { workbook:
|
|
821
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
561
822
|
if (!s)
|
|
562
823
|
return;
|
|
563
824
|
const l = {
|
|
564
825
|
worksheet: u,
|
|
565
|
-
workbook:
|
|
826
|
+
workbook: d,
|
|
566
827
|
rule: s,
|
|
567
828
|
ruleId: i.ruleId,
|
|
568
829
|
newRanges: i.ranges
|
|
@@ -575,12 +836,12 @@ class Q extends N {
|
|
|
575
836
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
576
837
|
if (!n)
|
|
577
838
|
return;
|
|
578
|
-
const { workbook:
|
|
839
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
579
840
|
if (!s)
|
|
580
841
|
return;
|
|
581
842
|
const l = {
|
|
582
843
|
worksheet: u,
|
|
583
|
-
workbook:
|
|
844
|
+
workbook: d,
|
|
584
845
|
rule: s,
|
|
585
846
|
ruleId: i.ruleId,
|
|
586
847
|
newOptions: i.options
|
|
@@ -593,12 +854,12 @@ class Q extends N {
|
|
|
593
854
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
594
855
|
if (!n)
|
|
595
856
|
return;
|
|
596
|
-
const { workbook:
|
|
857
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
597
858
|
if (!s)
|
|
598
859
|
return;
|
|
599
860
|
const l = {
|
|
600
861
|
worksheet: u,
|
|
601
|
-
workbook:
|
|
862
|
+
workbook: d,
|
|
602
863
|
rule: s,
|
|
603
864
|
ruleId: i.ruleId
|
|
604
865
|
};
|
|
@@ -610,9 +871,9 @@ class Q extends N {
|
|
|
610
871
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
611
872
|
if (!n)
|
|
612
873
|
return;
|
|
613
|
-
const { workbook:
|
|
874
|
+
const { workbook: d, worksheet: u } = n, s = {
|
|
614
875
|
worksheet: u,
|
|
615
|
-
workbook:
|
|
876
|
+
workbook: d,
|
|
616
877
|
rules: u.getDataValidations()
|
|
617
878
|
};
|
|
618
879
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
|
|
@@ -623,7 +884,7 @@ class Q extends N {
|
|
|
623
884
|
}));
|
|
624
885
|
}
|
|
625
886
|
}
|
|
626
|
-
|
|
887
|
+
x.extend(Q);
|
|
627
888
|
class z extends M {
|
|
628
889
|
_initialize() {
|
|
629
890
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
@@ -710,7 +971,7 @@ class z extends M {
|
|
|
710
971
|
}
|
|
711
972
|
}
|
|
712
973
|
M.extend(z);
|
|
713
|
-
class K extends
|
|
974
|
+
class K extends N {
|
|
714
975
|
getDataValidations() {
|
|
715
976
|
return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
|
|
716
977
|
}
|
|
@@ -720,12 +981,15 @@ class K extends x {
|
|
|
720
981
|
this._worksheet.getSheetId()
|
|
721
982
|
);
|
|
722
983
|
}
|
|
984
|
+
getValidatorStatusAsync() {
|
|
985
|
+
return this.getValidatorStatus();
|
|
986
|
+
}
|
|
723
987
|
getDataValidation(e) {
|
|
724
988
|
const r = this._injector.get(b).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
|
|
725
989
|
return r ? new m(r, this._worksheet, this._injector) : null;
|
|
726
990
|
}
|
|
727
991
|
}
|
|
728
|
-
|
|
992
|
+
N.extend(K);
|
|
729
993
|
class X {
|
|
730
994
|
get SheetDataValidationChanged() {
|
|
731
995
|
return "SheetDataValidationChanged";
|