@univerjs/sheets-data-validation 0.5.4 → 0.5.5-nightly.202501201336
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +435 -208
- package/lib/es/index.js +149 -147
- package/lib/types/facade/f-data-validation-builder.d.ts +237 -133
- package/lib/types/facade/f-data-validation.d.ts +155 -38
- package/lib/types/facade/f-range.d.ts +36 -9
- 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/types/services/dv-validator-service.d.ts +1 -1
- package/lib/types/validators/custom-validator.d.ts +1 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -176
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";
|
|
@@ -18,16 +18,24 @@ class D {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Builds an FDataValidation instance based on the _rule property of the current class
|
|
21
|
-
*
|
|
22
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
|
+
* ```
|
|
23
27
|
*/
|
|
24
28
|
build() {
|
|
25
29
|
return new m(this._rule);
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* Creates a duplicate of the current DataValidationBuilder object
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
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
|
+
* ```
|
|
31
39
|
*/
|
|
32
40
|
copy() {
|
|
33
41
|
return new D({
|
|
@@ -37,231 +45,322 @@ class D {
|
|
|
37
45
|
}
|
|
38
46
|
/**
|
|
39
47
|
* Determines whether invalid data is allowed
|
|
40
|
-
*
|
|
41
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
|
+
* ```
|
|
42
54
|
*/
|
|
43
55
|
getAllowInvalid() {
|
|
44
56
|
return this._rule.errorStyle !== w.STOP;
|
|
45
57
|
}
|
|
46
58
|
/**
|
|
47
59
|
* Gets the data validation type of the rule
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
60
|
+
* @returns {DataValidationType | string} The data validation type
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const builder = univerAPI.newDataValidation();
|
|
64
|
+
* const type = builder.getCriteriaType();
|
|
65
|
+
* ```
|
|
50
66
|
*/
|
|
51
67
|
getCriteriaType() {
|
|
52
68
|
return this._rule.type;
|
|
53
69
|
}
|
|
54
70
|
/**
|
|
55
71
|
* Gets the values used for criteria evaluation
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
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
|
+
* ```
|
|
58
78
|
*/
|
|
59
79
|
getCriteriaValues() {
|
|
60
80
|
return [this._rule.operator, this._rule.formula1, this._rule.formula2];
|
|
61
81
|
}
|
|
62
82
|
/**
|
|
63
83
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
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
|
+
* ```
|
|
66
90
|
*/
|
|
67
91
|
getHelpText() {
|
|
68
92
|
return this._rule.error;
|
|
69
93
|
}
|
|
70
94
|
/**
|
|
71
95
|
* Sets the data validation type to CHECKBOX and sets the checked and unchecked values
|
|
72
|
-
*
|
|
73
|
-
* @param
|
|
74
|
-
* @
|
|
75
|
-
* @
|
|
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
|
+
* ```
|
|
76
104
|
*/
|
|
77
105
|
requireCheckbox(e, t) {
|
|
78
106
|
return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
|
|
79
107
|
}
|
|
80
108
|
/**
|
|
81
109
|
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
84
|
-
* @
|
|
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
|
+
* ```
|
|
85
117
|
*/
|
|
86
118
|
requireDateAfter(e) {
|
|
87
|
-
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;
|
|
88
120
|
}
|
|
89
121
|
/**
|
|
90
122
|
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
91
|
-
*
|
|
92
|
-
* @
|
|
93
|
-
* @
|
|
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
|
+
* ```
|
|
94
130
|
*/
|
|
95
131
|
requireDateBefore(e) {
|
|
96
|
-
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;
|
|
97
133
|
}
|
|
98
134
|
/**
|
|
99
135
|
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
100
|
-
*
|
|
101
|
-
* @param
|
|
102
|
-
* @
|
|
103
|
-
* @
|
|
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
|
+
* ```
|
|
104
146
|
*/
|
|
105
147
|
requireDateBetween(e, t) {
|
|
106
|
-
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;
|
|
107
149
|
}
|
|
108
150
|
/**
|
|
109
151
|
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
110
|
-
*
|
|
111
|
-
* @
|
|
112
|
-
* @
|
|
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
|
+
* ```
|
|
113
159
|
*/
|
|
114
160
|
requireDateEqualTo(e) {
|
|
115
|
-
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;
|
|
116
162
|
}
|
|
117
163
|
/**
|
|
118
164
|
* Set the data validation type to DATE and configure the validation rules to be not within a specific date range
|
|
119
|
-
*
|
|
120
|
-
* @param
|
|
121
|
-
* @
|
|
122
|
-
* @
|
|
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
|
+
* ```
|
|
123
175
|
*/
|
|
124
176
|
requireDateNotBetween(e, t) {
|
|
125
|
-
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;
|
|
126
178
|
}
|
|
127
179
|
/**
|
|
128
180
|
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
129
|
-
*
|
|
130
|
-
* @
|
|
131
|
-
* @
|
|
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
|
+
* ```
|
|
132
188
|
*/
|
|
133
189
|
requireDateOnOrAfter(e) {
|
|
134
|
-
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;
|
|
135
191
|
}
|
|
136
192
|
/**
|
|
137
193
|
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
138
|
-
*
|
|
139
|
-
* @
|
|
140
|
-
* @
|
|
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
|
+
* ```
|
|
141
201
|
*/
|
|
142
202
|
requireDateOnOrBefore(e) {
|
|
143
|
-
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;
|
|
144
204
|
}
|
|
145
205
|
/**
|
|
146
|
-
* Requires that a custom formula be satisfied
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
150
|
-
*
|
|
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
|
+
* ```
|
|
151
214
|
*/
|
|
152
215
|
requireFormulaSatisfied(e) {
|
|
153
216
|
return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
|
|
154
217
|
}
|
|
155
218
|
/**
|
|
156
|
-
* Requires the user to enter a number within a specific range, which can be integer or decimal
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @param
|
|
160
|
-
* @
|
|
161
|
-
* @
|
|
162
|
-
*
|
|
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
|
+
* ```
|
|
163
229
|
*/
|
|
164
230
|
requireNumberBetween(e, t, r) {
|
|
165
|
-
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;
|
|
166
232
|
}
|
|
167
233
|
/**
|
|
168
|
-
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* @
|
|
172
|
-
* @
|
|
173
|
-
*
|
|
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
|
+
* ```
|
|
174
243
|
*/
|
|
175
244
|
requireNumberEqualTo(e, t) {
|
|
176
|
-
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;
|
|
177
246
|
}
|
|
178
247
|
/**
|
|
179
|
-
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @
|
|
183
|
-
* @
|
|
184
|
-
*
|
|
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
|
+
* ```
|
|
185
257
|
*/
|
|
186
258
|
requireNumberGreaterThan(e, t) {
|
|
187
|
-
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;
|
|
188
260
|
}
|
|
189
261
|
/**
|
|
190
|
-
* Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* @
|
|
194
|
-
* @
|
|
195
|
-
*
|
|
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
|
+
* ```
|
|
196
271
|
*/
|
|
197
272
|
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
198
|
-
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;
|
|
199
274
|
}
|
|
200
275
|
/**
|
|
201
|
-
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* @
|
|
205
|
-
* @
|
|
206
|
-
*
|
|
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
|
+
* ```
|
|
207
285
|
*/
|
|
208
286
|
requireNumberLessThan(e, t) {
|
|
209
|
-
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;
|
|
210
288
|
}
|
|
211
289
|
/**
|
|
212
290
|
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
213
291
|
* The specified value can be an integer or a decimal
|
|
214
|
-
*
|
|
215
|
-
* @param
|
|
216
|
-
* @
|
|
217
|
-
* @
|
|
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
|
+
* ```
|
|
218
300
|
*/
|
|
219
301
|
requireNumberLessThanOrEqualTo(e, t) {
|
|
220
|
-
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;
|
|
221
303
|
}
|
|
222
304
|
/**
|
|
223
305
|
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
224
306
|
* The specified range includes all integers and decimals
|
|
225
|
-
*
|
|
226
|
-
* @param
|
|
227
|
-
* @param
|
|
228
|
-
* @
|
|
229
|
-
* @
|
|
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
|
+
* ```
|
|
230
316
|
*/
|
|
231
317
|
requireNumberNotBetween(e, t, r) {
|
|
232
|
-
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;
|
|
233
319
|
}
|
|
234
320
|
/**
|
|
235
321
|
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
236
322
|
* The specific value can be an integer or a decimal
|
|
237
|
-
*
|
|
238
|
-
* @param
|
|
239
|
-
* @
|
|
240
|
-
* @
|
|
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
|
+
* ```
|
|
241
331
|
*/
|
|
242
332
|
requireNumberNotEqualTo(e, t) {
|
|
243
|
-
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;
|
|
244
334
|
}
|
|
245
335
|
/**
|
|
246
|
-
* Sets a data validation rule that requires the user to enter a value from a list of specific values
|
|
247
|
-
* The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
|
|
248
|
-
*
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* @
|
|
252
|
-
* @
|
|
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
|
+
* ```
|
|
253
347
|
*/
|
|
254
348
|
requireValueInList(e, t, r) {
|
|
255
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;
|
|
256
350
|
}
|
|
257
351
|
/**
|
|
258
|
-
* Sets a data validation rule that requires the user to enter a value within a specific range
|
|
259
|
-
* The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
|
|
260
|
-
*
|
|
261
|
-
* @param
|
|
262
|
-
* @param
|
|
263
|
-
* @
|
|
264
|
-
* @
|
|
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
|
+
* ```
|
|
265
364
|
*/
|
|
266
365
|
requireValueInRange(e, t, r) {
|
|
267
366
|
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${P({
|
|
@@ -271,48 +370,46 @@ class D {
|
|
|
271
370
|
})}`, this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
|
|
272
371
|
}
|
|
273
372
|
/**
|
|
274
|
-
* Sets whether to allow invalid data and configures the error style
|
|
275
|
-
* If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error
|
|
276
|
-
* 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
|
|
277
|
-
*
|
|
278
|
-
* @
|
|
279
|
-
* @
|
|
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
|
+
* ```
|
|
280
383
|
*/
|
|
281
384
|
setAllowInvalid(e) {
|
|
282
385
|
return this._rule.errorStyle = e ? w.WARNING : w.STOP, this;
|
|
283
386
|
}
|
|
284
387
|
/**
|
|
285
|
-
* Sets
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @
|
|
289
|
-
*
|
|
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
|
+
* ```
|
|
290
396
|
*/
|
|
291
|
-
setHelpText(e) {
|
|
292
|
-
return this._rule.error = e, this._rule.showErrorMessage = !0, this;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Sets the criteria values for data validation.
|
|
296
|
-
* This method is used to configure the validation rules based on specific criteria values.
|
|
297
|
-
*
|
|
298
|
-
* @param type The type of data validation.
|
|
299
|
-
* @param values An array containing the criteria values.
|
|
300
|
-
* The array should have three elements: [operator, formula1, formula2].
|
|
301
|
-
* operator is a DataValidationOperator enum value, formula1 is the first formula, and formula2 is the second formula.
|
|
302
|
-
* @return The current instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
303
|
-
*/
|
|
304
|
-
withCriteriaValues(e, t) {
|
|
305
|
-
return this._rule.type = e, this._rule.operator = t[0], this._rule.formula1 = t[1], this._rule.formula2 = t[2], this;
|
|
306
|
-
}
|
|
307
397
|
setAllowBlank(e) {
|
|
308
398
|
return this._rule.allowBlank = e, this;
|
|
309
399
|
}
|
|
310
400
|
/**
|
|
311
|
-
* Sets the options for the data validation rule
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
* @
|
|
315
|
-
*
|
|
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
|
+
* ```
|
|
316
413
|
*/
|
|
317
414
|
setOptions(e) {
|
|
318
415
|
return Object.assign(this._rule, e), this;
|
|
@@ -326,50 +423,98 @@ class m {
|
|
|
326
423
|
this._injector = r, this.rule = e, this._worksheet = t;
|
|
327
424
|
}
|
|
328
425
|
/**
|
|
329
|
-
* Gets whether invalid data is allowed based on the error style value
|
|
330
|
-
*
|
|
331
|
-
* @
|
|
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
|
+
* ```
|
|
332
437
|
*/
|
|
333
438
|
getAllowInvalid() {
|
|
334
439
|
return this.rule.errorStyle !== w.STOP;
|
|
335
440
|
}
|
|
336
441
|
/**
|
|
337
442
|
* Gets the data validation type of the rule
|
|
338
|
-
*
|
|
339
|
-
* @
|
|
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
|
+
* ```
|
|
340
453
|
*/
|
|
341
454
|
getCriteriaType() {
|
|
342
455
|
return this.rule.type;
|
|
343
456
|
}
|
|
344
457
|
/**
|
|
345
458
|
* Gets the values used for criteria evaluation
|
|
346
|
-
*
|
|
347
|
-
* @
|
|
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
|
+
* ```
|
|
348
469
|
*/
|
|
349
470
|
getCriteriaValues() {
|
|
350
471
|
return [this.rule.operator, this.rule.formula1, this.rule.formula2];
|
|
351
472
|
}
|
|
352
473
|
/**
|
|
353
474
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
354
|
-
*
|
|
355
|
-
* @
|
|
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
|
+
* ```
|
|
356
485
|
*/
|
|
357
486
|
getHelpText() {
|
|
358
487
|
return this.rule.error;
|
|
359
488
|
}
|
|
360
489
|
/**
|
|
361
|
-
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
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
|
+
* ```
|
|
365
502
|
*/
|
|
366
503
|
copy() {
|
|
367
504
|
return new D(this.rule);
|
|
368
505
|
}
|
|
369
506
|
/**
|
|
370
|
-
* Gets whether the data validation rule is applied to the worksheet
|
|
371
|
-
*
|
|
372
|
-
* @
|
|
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
|
+
* ```
|
|
373
518
|
*/
|
|
374
519
|
getApplied() {
|
|
375
520
|
if (!this._worksheet)
|
|
@@ -378,9 +523,17 @@ class m {
|
|
|
378
523
|
return !!(t && t.ranges.length);
|
|
379
524
|
}
|
|
380
525
|
/**
|
|
381
|
-
* Gets the ranges to which the data validation rule is applied
|
|
382
|
-
*
|
|
383
|
-
* @
|
|
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
|
+
* ```
|
|
384
537
|
*/
|
|
385
538
|
getRanges() {
|
|
386
539
|
if (!this.getApplied())
|
|
@@ -389,28 +542,58 @@ class m {
|
|
|
389
542
|
return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
|
|
390
543
|
}
|
|
391
544
|
/**
|
|
392
|
-
* Gets the
|
|
393
|
-
*
|
|
394
|
-
* @
|
|
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
|
+
* ```
|
|
395
556
|
*/
|
|
396
557
|
getUnitId() {
|
|
397
558
|
var e;
|
|
398
559
|
return (e = this._worksheet) == null ? void 0 : e.getUnitId();
|
|
399
560
|
}
|
|
400
561
|
/**
|
|
401
|
-
* Gets the
|
|
402
|
-
*
|
|
403
|
-
* @
|
|
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
|
+
* ```
|
|
404
573
|
*/
|
|
405
574
|
getSheetId() {
|
|
406
575
|
var e;
|
|
407
576
|
return (e = this._worksheet) == null ? void 0 : e.getSheetId();
|
|
408
577
|
}
|
|
409
578
|
/**
|
|
410
|
-
* Set Criteria for the data validation rule
|
|
411
|
-
* @param type The type of data validation criteria
|
|
412
|
-
* @param values An array containing the operator, formula1, and formula2 values
|
|
413
|
-
* @
|
|
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
|
+
* ```
|
|
414
597
|
*/
|
|
415
598
|
setCriteria(e, t, r = !0) {
|
|
416
599
|
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
|
|
@@ -429,10 +612,22 @@ class m {
|
|
|
429
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;
|
|
430
613
|
}
|
|
431
614
|
/**
|
|
432
|
-
* Set the options for the data validation rule
|
|
433
|
-
*
|
|
434
|
-
* @
|
|
435
|
-
* @
|
|
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
|
+
* ```
|
|
436
631
|
*/
|
|
437
632
|
setOptions(e) {
|
|
438
633
|
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(v.id, {
|
|
@@ -448,9 +643,19 @@ class m {
|
|
|
448
643
|
return Object.assign(this.rule, e), this;
|
|
449
644
|
}
|
|
450
645
|
/**
|
|
451
|
-
* Set the ranges to the data validation rule
|
|
452
|
-
* @param ranges
|
|
453
|
-
* @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
|
+
* ```
|
|
454
659
|
*/
|
|
455
660
|
setRanges(e) {
|
|
456
661
|
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
|
|
@@ -463,8 +668,17 @@ class m {
|
|
|
463
668
|
return this.rule.ranges = e.map((t) => t.getRange()), this;
|
|
464
669
|
}
|
|
465
670
|
/**
|
|
466
|
-
* Delete the data validation rule from the worksheet
|
|
467
|
-
* @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
|
+
* ```
|
|
468
682
|
*/
|
|
469
683
|
delete() {
|
|
470
684
|
return this.getApplied() ? this._injector.get(p).syncExecuteCommand(T.id, {
|
|
@@ -516,14 +730,24 @@ class G extends y {
|
|
|
516
730
|
}
|
|
517
731
|
}
|
|
518
732
|
y.extend(G);
|
|
519
|
-
class Q extends
|
|
733
|
+
class Q extends x {
|
|
734
|
+
// eslint-disable-next-line jsdoc/require-returns
|
|
520
735
|
/**
|
|
521
736
|
/**
|
|
522
|
-
* @
|
|
737
|
+
* @deprecated use `univerAPI.newDataValidation()` as instead.
|
|
523
738
|
*/
|
|
524
739
|
static newDataValidation() {
|
|
525
740
|
return new D();
|
|
526
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
|
+
*/
|
|
527
751
|
newDataValidation() {
|
|
528
752
|
return new D();
|
|
529
753
|
}
|
|
@@ -532,10 +756,10 @@ class Q extends N {
|
|
|
532
756
|
if (!e.has(V)) return;
|
|
533
757
|
const t = e.get(V), r = e.get(p);
|
|
534
758
|
this.disposeWithMe(t.ruleChange$.subscribe((a) => {
|
|
535
|
-
const { unitId: i, subUnitId: n, rule:
|
|
759
|
+
const { unitId: i, subUnitId: n, rule: d, oldRule: u, type: s } = a, l = this.getSheetTarget(i, n);
|
|
536
760
|
if (!l)
|
|
537
761
|
return;
|
|
538
|
-
const { workbook: I, worksheet: k } = l, E = new m(
|
|
762
|
+
const { workbook: I, worksheet: k } = l, E = new m(d, k.getSheet(), this._injector);
|
|
539
763
|
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
540
764
|
origin: a,
|
|
541
765
|
worksheet: k,
|
|
@@ -545,10 +769,10 @@ class Q extends N {
|
|
|
545
769
|
rule: E
|
|
546
770
|
});
|
|
547
771
|
})), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
|
|
548
|
-
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);
|
|
549
773
|
if (!I)
|
|
550
774
|
return;
|
|
551
|
-
const { workbook: k, worksheet: E } = I, L = E.getDataValidation(
|
|
775
|
+
const { workbook: k, worksheet: E } = I, L = E.getDataValidation(d);
|
|
552
776
|
L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
|
|
553
777
|
workbook: k,
|
|
554
778
|
worksheet: E,
|
|
@@ -563,9 +787,9 @@ class Q extends N {
|
|
|
563
787
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
564
788
|
if (!n)
|
|
565
789
|
return;
|
|
566
|
-
const { workbook:
|
|
790
|
+
const { workbook: d, worksheet: u } = n, s = {
|
|
567
791
|
worksheet: u,
|
|
568
|
-
workbook:
|
|
792
|
+
workbook: d,
|
|
569
793
|
rule: i.rule
|
|
570
794
|
};
|
|
571
795
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
|
|
@@ -576,12 +800,12 @@ class Q extends N {
|
|
|
576
800
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
577
801
|
if (!n)
|
|
578
802
|
return;
|
|
579
|
-
const { workbook:
|
|
803
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
580
804
|
if (!s)
|
|
581
805
|
return;
|
|
582
806
|
const l = {
|
|
583
807
|
worksheet: u,
|
|
584
|
-
workbook:
|
|
808
|
+
workbook: d,
|
|
585
809
|
rule: s,
|
|
586
810
|
ruleId: i.ruleId,
|
|
587
811
|
newCriteria: i.setting
|
|
@@ -594,12 +818,12 @@ class Q extends N {
|
|
|
594
818
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
595
819
|
if (!n)
|
|
596
820
|
return;
|
|
597
|
-
const { workbook:
|
|
821
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
598
822
|
if (!s)
|
|
599
823
|
return;
|
|
600
824
|
const l = {
|
|
601
825
|
worksheet: u,
|
|
602
|
-
workbook:
|
|
826
|
+
workbook: d,
|
|
603
827
|
rule: s,
|
|
604
828
|
ruleId: i.ruleId,
|
|
605
829
|
newRanges: i.ranges
|
|
@@ -612,12 +836,12 @@ class Q extends N {
|
|
|
612
836
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
613
837
|
if (!n)
|
|
614
838
|
return;
|
|
615
|
-
const { workbook:
|
|
839
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
616
840
|
if (!s)
|
|
617
841
|
return;
|
|
618
842
|
const l = {
|
|
619
843
|
worksheet: u,
|
|
620
|
-
workbook:
|
|
844
|
+
workbook: d,
|
|
621
845
|
rule: s,
|
|
622
846
|
ruleId: i.ruleId,
|
|
623
847
|
newOptions: i.options
|
|
@@ -630,12 +854,12 @@ class Q extends N {
|
|
|
630
854
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
631
855
|
if (!n)
|
|
632
856
|
return;
|
|
633
|
-
const { workbook:
|
|
857
|
+
const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
|
|
634
858
|
if (!s)
|
|
635
859
|
return;
|
|
636
860
|
const l = {
|
|
637
861
|
worksheet: u,
|
|
638
|
-
workbook:
|
|
862
|
+
workbook: d,
|
|
639
863
|
rule: s,
|
|
640
864
|
ruleId: i.ruleId
|
|
641
865
|
};
|
|
@@ -647,9 +871,9 @@ class Q extends N {
|
|
|
647
871
|
const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
648
872
|
if (!n)
|
|
649
873
|
return;
|
|
650
|
-
const { workbook:
|
|
874
|
+
const { workbook: d, worksheet: u } = n, s = {
|
|
651
875
|
worksheet: u,
|
|
652
|
-
workbook:
|
|
876
|
+
workbook: d,
|
|
653
877
|
rules: u.getDataValidations()
|
|
654
878
|
};
|
|
655
879
|
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
|
|
@@ -660,7 +884,7 @@ class Q extends N {
|
|
|
660
884
|
}));
|
|
661
885
|
}
|
|
662
886
|
}
|
|
663
|
-
|
|
887
|
+
x.extend(Q);
|
|
664
888
|
class z extends M {
|
|
665
889
|
_initialize() {
|
|
666
890
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
@@ -747,7 +971,7 @@ class z extends M {
|
|
|
747
971
|
}
|
|
748
972
|
}
|
|
749
973
|
M.extend(z);
|
|
750
|
-
class K extends
|
|
974
|
+
class K extends N {
|
|
751
975
|
getDataValidations() {
|
|
752
976
|
return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
|
|
753
977
|
}
|
|
@@ -757,12 +981,15 @@ class K extends x {
|
|
|
757
981
|
this._worksheet.getSheetId()
|
|
758
982
|
);
|
|
759
983
|
}
|
|
984
|
+
getValidatorStatusAsync() {
|
|
985
|
+
return this.getValidatorStatus();
|
|
986
|
+
}
|
|
760
987
|
getDataValidation(e) {
|
|
761
988
|
const r = this._injector.get(b).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
|
|
762
989
|
return r ? new m(r, this._worksheet, this._injector) : null;
|
|
763
990
|
}
|
|
764
991
|
}
|
|
765
|
-
|
|
992
|
+
N.extend(K);
|
|
766
993
|
class X {
|
|
767
994
|
get SheetDataValidationChanged() {
|
|
768
995
|
return "SheetDataValidationChanged";
|