@univerjs/sheets-data-validation 0.4.2 → 0.5.0-beta.0
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 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +641 -0
- package/lib/es/index.js +2070 -2290
- package/lib/types/controllers/dv-formula-ref-range.controller.d.ts +13 -0
- package/lib/types/facade/f-data-validation-builder.d.ts +247 -0
- package/lib/types/facade/f-data-validation.d.ts +88 -0
- package/lib/types/facade/f-range.d.ts +33 -0
- package/lib/types/facade/f-univer.d.ts +6 -0
- package/lib/types/facade/f-workbook.d.ts +64 -0
- package/lib/types/facade/f-worksheet.d.ts +20 -0
- package/lib/types/facade/index.d.ts +21 -0
- package/lib/types/models/sheet-data-validation-model.d.ts +1 -2
- package/lib/types/services/dv-custom-formula.service.d.ts +8 -15
- package/lib/types/services/dv-formula.service.d.ts +3 -3
- package/lib/types/utils/formula.d.ts +5 -1
- package/lib/types/validators/checkbox-validator.d.ts +3 -6
- package/lib/types/validators/const.d.ts +17 -0
- package/lib/types/validators/custom-validator.d.ts +1 -1
- package/lib/types/validators/date-validator.d.ts +5 -7
- package/lib/types/validators/decimal-validator.d.ts +6 -7
- package/lib/types/validators/text-length-validator.d.ts +5 -3
- package/lib/types/validators/util.d.ts +7 -1
- package/lib/types/validators/whole-validator.d.ts +5 -6
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +26 -17
package/lib/es/facade.js
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
var T = Object.defineProperty;
|
|
2
|
+
var A = (s, e, t) => e in s ? T(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var l = (s, e, t) => A(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { FRange as g, FWorkbook as S, FWorksheet as I } from "@univerjs/sheets/facade";
|
|
5
|
+
import { UpdateSheetDataValidationSettingCommand as E, UpdateSheetDataValidationOptionsCommand as k, UpdateSheetDataValidationRangeCommand as D, RemoveSheetDataValidationCommand as b, ClearRangeDataValidationCommand as C, AddSheetDataValidationCommand as v, SheetsDataValidationValidatorService as u, SheetDataValidationModel as U, RemoveSheetAllDataValidationCommand as y } from "@univerjs/sheets-data-validation";
|
|
6
|
+
import { generateRandomId as f, DataValidationType as r, DataValidationErrorStyle as d, DataValidationOperator as o, ICommandService as h, FUniver as L, toDisposable as n } from "@univerjs/core";
|
|
7
|
+
import { DataValidationModel as w, getRuleOptions as O } from "@univerjs/data-validation";
|
|
8
|
+
import { serializeRangeToRefString as R } from "@univerjs/engine-formula";
|
|
9
|
+
import { filter as p } from "rxjs";
|
|
10
|
+
class m {
|
|
11
|
+
constructor(e) {
|
|
12
|
+
l(this, "_rule");
|
|
13
|
+
this._rule = e != null ? e : {
|
|
14
|
+
uid: f(),
|
|
15
|
+
ranges: void 0,
|
|
16
|
+
type: r.CUSTOM
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds an FDataValidation instance based on the _rule property of the current class
|
|
21
|
+
*
|
|
22
|
+
* @returns {FDataValidation} A new instance of the FDataValidation class
|
|
23
|
+
*/
|
|
24
|
+
build() {
|
|
25
|
+
return new _(this._rule);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a duplicate of the current DataValidationBuilder object
|
|
29
|
+
*
|
|
30
|
+
* @return {FDataValidationBuilder} A new instance of the DataValidationBuilder class
|
|
31
|
+
*/
|
|
32
|
+
copy() {
|
|
33
|
+
return new m({
|
|
34
|
+
...this._rule,
|
|
35
|
+
uid: f()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Determines whether invalid data is allowed
|
|
40
|
+
*
|
|
41
|
+
* @returns {boolean} True if invalid data is allowed, False otherwise
|
|
42
|
+
*/
|
|
43
|
+
getAllowInvalid() {
|
|
44
|
+
return this._rule.errorStyle !== d.STOP;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the data validation type of the rule
|
|
48
|
+
*
|
|
49
|
+
* @returns {DataValidationType} The data validation type
|
|
50
|
+
*/
|
|
51
|
+
getCriteriaType() {
|
|
52
|
+
return this._rule.type;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets the values used for criteria evaluation
|
|
56
|
+
*
|
|
57
|
+
* @returns {any[]} An array containing the operator, formula1, and formula2 values
|
|
58
|
+
*/
|
|
59
|
+
getCriteriaValues() {
|
|
60
|
+
return [this._rule.operator, this._rule.formula1, this._rule.formula2];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the help text information, which is used to provide users with guidance and support
|
|
64
|
+
*
|
|
65
|
+
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value.
|
|
66
|
+
*/
|
|
67
|
+
getHelpText() {
|
|
68
|
+
return this._rule.error;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sets the data validation type to CHECKBOX and sets the checked and unchecked values
|
|
72
|
+
*
|
|
73
|
+
* @param checkedValue The value when the checkbox is checked (Optional)
|
|
74
|
+
* @param uncheckedValue The value when the checkbox is unchecked (Optional)
|
|
75
|
+
* @returns The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
76
|
+
*/
|
|
77
|
+
requireCheckbox(e, t) {
|
|
78
|
+
return this._rule.type = r.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
82
|
+
*
|
|
83
|
+
* @param date The date to compare against. The formatted date string will be set as formula1
|
|
84
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
85
|
+
*/
|
|
86
|
+
requireDateAfter(e) {
|
|
87
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = o.GREATER_THAN, this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
91
|
+
*
|
|
92
|
+
* @param date The date to compare against. The formatted date string will be set as formula1
|
|
93
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
94
|
+
*/
|
|
95
|
+
requireDateBefore(e) {
|
|
96
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN, this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
100
|
+
*
|
|
101
|
+
* @param start The starting date of the range. The formatted date string will be set as formula1
|
|
102
|
+
* @param end The ending date of the range. The formatted date string will be set as formula2
|
|
103
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
104
|
+
*/
|
|
105
|
+
requireDateBetween(e, t) {
|
|
106
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = o.BETWEEN, this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
110
|
+
*
|
|
111
|
+
* @param date The date to compare against. The formatted date string will be set as formula1
|
|
112
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
113
|
+
*/
|
|
114
|
+
requireDateEqualTo(e) {
|
|
115
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.EQUAL, this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set the data validation type to DATE and configure the validation rules to be not within a specific date range
|
|
119
|
+
*
|
|
120
|
+
* @param start The starting date of the date range
|
|
121
|
+
* @param end The ending date of the date range
|
|
122
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
123
|
+
*/
|
|
124
|
+
requireDateNotBetween(e, t) {
|
|
125
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = o.NOT_BETWEEN, this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
129
|
+
*
|
|
130
|
+
* @param date The date to compare against. The formatted date string will be set as formula1
|
|
131
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
132
|
+
*/
|
|
133
|
+
requireDateOnOrAfter(e) {
|
|
134
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN_OR_EQUAL, this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
138
|
+
*
|
|
139
|
+
* @param date The date to compare against. The formatted date string will be set as formula1
|
|
140
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
141
|
+
*/
|
|
142
|
+
requireDateOnOrBefore(e) {
|
|
143
|
+
return this._rule.type = r.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN_OR_EQUAL, this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Requires that a custom formula be satisfied.
|
|
147
|
+
* Sets the data validation type to CUSTOM and configures the validation rule based on the provided formula string.
|
|
148
|
+
*
|
|
149
|
+
* @param formula The formula string that needs to be satisfied.
|
|
150
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
151
|
+
*/
|
|
152
|
+
requireFormulaSatisfied(e) {
|
|
153
|
+
return this._rule.type = r.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Requires the user to enter a number within a specific range, which can be integer or decimal.
|
|
157
|
+
* Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number range.
|
|
158
|
+
*
|
|
159
|
+
* @param start The starting value of the number range.
|
|
160
|
+
* @param end The ending value of the number range.
|
|
161
|
+
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or decimal.
|
|
162
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
163
|
+
*/
|
|
164
|
+
requireNumberBetween(e, t, i) {
|
|
165
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.BETWEEN, this._rule.type = i ? r.WHOLE : r.DECIMAL, this;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal.
|
|
169
|
+
* Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
|
|
170
|
+
*
|
|
171
|
+
* @param num The number to which the entered number should be equal.
|
|
172
|
+
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
|
|
173
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
174
|
+
*/
|
|
175
|
+
requireNumberEqualTo(e, t) {
|
|
176
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.EQUAL, this._rule.type = t ? r.WHOLE : r.DECIMAL, this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal.
|
|
180
|
+
* Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
|
|
181
|
+
*
|
|
182
|
+
* @param num The number to which the entered number should be greater.
|
|
183
|
+
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
|
|
184
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
185
|
+
*/
|
|
186
|
+
requireNumberGreaterThan(e, t) {
|
|
187
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN, this._rule.type = t ? r.WHOLE : r.DECIMAL, this;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
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
|
+
* Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
|
|
192
|
+
*
|
|
193
|
+
* @param num The number to which the entered number should be greater than or equal.
|
|
194
|
+
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
|
|
195
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
196
|
+
*/
|
|
197
|
+
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
198
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN_OR_EQUAL, this._rule.type = t ? r.WHOLE : r.DECIMAL, this;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal.
|
|
202
|
+
* Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
|
|
203
|
+
*
|
|
204
|
+
* @param num The number to which the entered number should be less.
|
|
205
|
+
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
|
|
206
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
207
|
+
*/
|
|
208
|
+
requireNumberLessThan(e, t) {
|
|
209
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN, this._rule.type = t ? r.WHOLE : r.DECIMAL, this;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
213
|
+
* The specified value can be an integer or a decimal
|
|
214
|
+
*
|
|
215
|
+
* @param num The number to which the entered number should be less than or equal
|
|
216
|
+
* @param isInteger Indicates whether the required number is an integer
|
|
217
|
+
* @return The current instance of the DataValidationBuilder class, allowing for method chaining
|
|
218
|
+
*/
|
|
219
|
+
requireNumberLessThanOrEqualTo(e, t) {
|
|
220
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN_OR_EQUAL, this._rule.type = t ? r.WHOLE : r.DECIMAL, this;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
224
|
+
* The specified range includes all integers and decimals
|
|
225
|
+
*
|
|
226
|
+
* @param start The starting point of the specified range
|
|
227
|
+
* @param end The end point of the specified range
|
|
228
|
+
* @param isInteger Optional parameter, indicating whether the number to be verified is an integer. Default value is false
|
|
229
|
+
* @return An instance of the FDataValidationBuilder class, allowing for method chaining
|
|
230
|
+
*/
|
|
231
|
+
requireNumberNotBetween(e, t, i) {
|
|
232
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.NOT_BETWEEN, this._rule.type = i ? r.WHOLE : r.DECIMAL, this;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
236
|
+
* The specific value can be an integer or a decimal
|
|
237
|
+
*
|
|
238
|
+
* @param num The number to which the entered number should not be equal
|
|
239
|
+
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal
|
|
240
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
241
|
+
*/
|
|
242
|
+
requireNumberNotEqualTo(e, t) {
|
|
243
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.NOT_EQUAL, this._rule.type = t ? r.WHOLE : r.DECIMAL, this;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
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 values An array containing the specific values that the user can enter.
|
|
250
|
+
* @param multiple Optional parameter indicating whether the user can select multiple values. Default is false, meaning only one value can be selected.
|
|
251
|
+
* @param showDropdown Optional parameter indicating whether to display the list in a dropdown. Default is true, meaning the list will be displayed as a dropdown.
|
|
252
|
+
* @return An instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
253
|
+
*/
|
|
254
|
+
requireValueInList(e, t, i) {
|
|
255
|
+
return this._rule.type = t ? r.LIST_MULTIPLE : r.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = i != null ? i : !0, this;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
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 range An FRange object representing the range of values that the user can enter.
|
|
262
|
+
* @param multiple Optional parameter indicating whether the user can select multiple values. Default is false, meaning only one value can be selected.
|
|
263
|
+
* @param showDropdown Optional parameter indicating whether to display the list in a dropdown. Default is true, meaning the list will be displayed as a dropdown.
|
|
264
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
265
|
+
*/
|
|
266
|
+
requireValueInRange(e, t, i) {
|
|
267
|
+
return this._rule.type = t ? r.LIST_MULTIPLE : r.LIST, this._rule.formula1 = `=${R({
|
|
268
|
+
unitId: e.getUnitId(),
|
|
269
|
+
sheetName: e.getSheetName(),
|
|
270
|
+
range: e.getRange()
|
|
271
|
+
})}`, this._rule.formula2 = void 0, this._rule.showDropDown = i != null ? i : !0, this;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Sets whether to allow invalid data and configures the error style for data validation.
|
|
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
|
+
* @param allowInvalidData A boolean value indicating whether to allow invalid data.
|
|
279
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
280
|
+
*/
|
|
281
|
+
setAllowInvalid(e) {
|
|
282
|
+
return this._rule.errorStyle = e ? d.WARNING : d.STOP, this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Sets the help text and enables the display of error messages for data validation.
|
|
286
|
+
* This method allows you to set a custom help text that will be displayed when the user enters invalid data.
|
|
287
|
+
*
|
|
288
|
+
* @param helpText The text to display as help information.
|
|
289
|
+
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
290
|
+
*/
|
|
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
|
+
/**
|
|
308
|
+
* Sets the options for the data validation rule.
|
|
309
|
+
* For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
|
|
310
|
+
*
|
|
311
|
+
* @param options The options to set for the data validation rule.
|
|
312
|
+
* @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
313
|
+
*/
|
|
314
|
+
setOptions(e) {
|
|
315
|
+
return Object.assign(this._rule, e), this;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
class _ {
|
|
319
|
+
constructor(e, t) {
|
|
320
|
+
l(this, "rule");
|
|
321
|
+
l(this, "_worksheet");
|
|
322
|
+
this.rule = e, this._worksheet = t;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Gets whether invalid data is allowed based on the error style value.
|
|
326
|
+
*
|
|
327
|
+
* @return true if invalid data is allowed, false otherwise.
|
|
328
|
+
*/
|
|
329
|
+
getAllowInvalid() {
|
|
330
|
+
return this.rule.errorStyle !== d.STOP;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Gets the data validation type of the rule
|
|
334
|
+
*
|
|
335
|
+
* @returns The data validation type
|
|
336
|
+
*/
|
|
337
|
+
getCriteriaType() {
|
|
338
|
+
return this.rule.type;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Gets the values used for criteria evaluation
|
|
342
|
+
*
|
|
343
|
+
* @returns An array containing the operator, formula1, and formula2 values
|
|
344
|
+
*/
|
|
345
|
+
getCriteriaValues() {
|
|
346
|
+
return [this.rule.operator, this.rule.formula1, this.rule.formula2];
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Gets the help text information, which is used to provide users with guidance and support
|
|
350
|
+
*
|
|
351
|
+
* @returns Returns the help text information. If there is no error message, it returns an undefined value.
|
|
352
|
+
*/
|
|
353
|
+
getHelpText() {
|
|
354
|
+
return this.rule.error;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Creates a new instance of FDataValidationBuilder using the current rule object.
|
|
358
|
+
* This method is useful for copying an existing data validation rule configuration.
|
|
359
|
+
*
|
|
360
|
+
* @return A new FDataValidationBuilder instance with the same rule configuration.
|
|
361
|
+
*/
|
|
362
|
+
copy() {
|
|
363
|
+
return new m(this.rule);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Gets whether the data validation rule is applied to the worksheet.
|
|
367
|
+
*
|
|
368
|
+
* @returns true if the rule is applied, false otherwise.
|
|
369
|
+
*/
|
|
370
|
+
getApplied() {
|
|
371
|
+
if (!this._worksheet)
|
|
372
|
+
return !1;
|
|
373
|
+
const t = this._worksheet.getInject().get(w).getRuleById(this._worksheet.getWorkbook().getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
|
|
374
|
+
return !!(t && t.ranges.length);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Gets the ranges to which the data validation rule is applied.
|
|
378
|
+
*
|
|
379
|
+
* @returns An array of IRange objects representing the ranges to which the data validation rule is applied.
|
|
380
|
+
*/
|
|
381
|
+
getRanges() {
|
|
382
|
+
var a;
|
|
383
|
+
if (!this.getAllowInvalid())
|
|
384
|
+
return [];
|
|
385
|
+
const e = (a = this._worksheet) == null ? void 0 : a.getWorkbook(), t = this.getSheetId();
|
|
386
|
+
if (!t)
|
|
387
|
+
return [];
|
|
388
|
+
const i = e == null ? void 0 : e.getSheetBySheetId(t);
|
|
389
|
+
return !e || !i ? [] : this.rule.ranges.map((V) => {
|
|
390
|
+
var c;
|
|
391
|
+
return (c = this._worksheet) == null ? void 0 : c.getInject().createInstance(g, e, i, V);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Gets the title of the error message dialog box.
|
|
396
|
+
*
|
|
397
|
+
* @returns The title of the error message dialog box.
|
|
398
|
+
*/
|
|
399
|
+
getUnitId() {
|
|
400
|
+
var e;
|
|
401
|
+
return (e = this._worksheet) == null ? void 0 : e.getWorkbook().getUnitId();
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Gets the sheetId of the worksheet.
|
|
405
|
+
*
|
|
406
|
+
* @returns The sheetId of the worksheet.
|
|
407
|
+
*/
|
|
408
|
+
getSheetId() {
|
|
409
|
+
var e;
|
|
410
|
+
return (e = this._worksheet) == null ? void 0 : e.getSheetId();
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Set Criteria for the data validation rule.
|
|
414
|
+
* @param type The type of data validation criteria.
|
|
415
|
+
* @param values An array containing the operator, formula1, and formula2 values.
|
|
416
|
+
* @returns true if the criteria is set successfully, false otherwise.
|
|
417
|
+
*/
|
|
418
|
+
setCriteria(e, t) {
|
|
419
|
+
return this.getApplied() && !this._worksheet.getInject().get(h).syncExecuteCommand(E.id, {
|
|
420
|
+
unitId: this.getUnitId(),
|
|
421
|
+
subUnitId: this.getSheetId(),
|
|
422
|
+
ruleId: this.rule.uid,
|
|
423
|
+
setting: {
|
|
424
|
+
operator: t[0],
|
|
425
|
+
formula1: t[1],
|
|
426
|
+
formula2: t[2],
|
|
427
|
+
type: this.rule.type
|
|
428
|
+
}
|
|
429
|
+
}) ? !1 : (this.rule.operator = t[0], this.rule.formula1 = t[1], this.rule.formula2 = t[2], this.rule.type = e, !0);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Set the options for the data validation rule.
|
|
433
|
+
* For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
|
|
434
|
+
* @param options An object containing the options to set. `IDataValidationRuleOptions`
|
|
435
|
+
* @returns true if the options are set successfully, false otherwise.
|
|
436
|
+
*/
|
|
437
|
+
setOptions(e) {
|
|
438
|
+
return this.getApplied() && !this._worksheet.getInject().get(h).syncExecuteCommand(k.id, {
|
|
439
|
+
unitId: this.getUnitId(),
|
|
440
|
+
subUnitId: this.getSheetId(),
|
|
441
|
+
ruleId: this.rule.uid,
|
|
442
|
+
options: {
|
|
443
|
+
...O(this.rule),
|
|
444
|
+
...e
|
|
445
|
+
}
|
|
446
|
+
}) ? !1 : (Object.assign(this.rule, e), !0);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Set the ranges to the data validation rule.
|
|
450
|
+
* @param ranges new ranges array.
|
|
451
|
+
* @returns true if the ranges are set successfully, false otherwise.
|
|
452
|
+
*/
|
|
453
|
+
setRanges(e) {
|
|
454
|
+
return this.getApplied() && !this._worksheet.getInject().get(h).syncExecuteCommand(D.id, {
|
|
455
|
+
unitId: this.getUnitId(),
|
|
456
|
+
subUnitId: this.getSheetId(),
|
|
457
|
+
ruleId: this.rule.uid,
|
|
458
|
+
ranges: e.map((a) => a.getRange())
|
|
459
|
+
}) ? !1 : (this.rule.ranges = e, !0);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Delete the data validation rule from the worksheet.
|
|
463
|
+
* @returns true if the rule is deleted successfully, false otherwise.
|
|
464
|
+
*/
|
|
465
|
+
delete() {
|
|
466
|
+
return this.getApplied() ? this._worksheet.getInject().get(h).syncExecuteCommand(b.id, {
|
|
467
|
+
unitId: this.getUnitId(),
|
|
468
|
+
subUnitId: this.getSheetId(),
|
|
469
|
+
ruleId: this.rule.uid
|
|
470
|
+
}) : !1;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
class N extends g {
|
|
474
|
+
async setDataValidation(e) {
|
|
475
|
+
if (!e)
|
|
476
|
+
return this._commandService.executeCommand(C.id, {
|
|
477
|
+
unitId: this._workbook.getUnitId(),
|
|
478
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
479
|
+
ranges: [this._range]
|
|
480
|
+
}), this;
|
|
481
|
+
const t = {
|
|
482
|
+
unitId: this._workbook.getUnitId(),
|
|
483
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
484
|
+
rule: {
|
|
485
|
+
...e.rule,
|
|
486
|
+
ranges: [this._range]
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
return await this._commandService.executeCommand(v.id, t), this;
|
|
490
|
+
}
|
|
491
|
+
getDataValidation() {
|
|
492
|
+
const t = this._injector.get(u).getDataValidation(
|
|
493
|
+
this._workbook.getUnitId(),
|
|
494
|
+
this._worksheet.getSheetId(),
|
|
495
|
+
[this._range]
|
|
496
|
+
);
|
|
497
|
+
return t && new _(t);
|
|
498
|
+
}
|
|
499
|
+
getDataValidations() {
|
|
500
|
+
return this._injector.get(u).getDataValidations(
|
|
501
|
+
this._workbook.getUnitId(),
|
|
502
|
+
this._worksheet.getSheetId(),
|
|
503
|
+
[this._range]
|
|
504
|
+
).map((t) => new _(t));
|
|
505
|
+
}
|
|
506
|
+
async getValidatorStatus() {
|
|
507
|
+
return this._injector.get(u).validatorRanges(
|
|
508
|
+
this._workbook.getUnitId(),
|
|
509
|
+
this._worksheet.getSheetId(),
|
|
510
|
+
[this._range]
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
g.extend(N);
|
|
515
|
+
class x {
|
|
516
|
+
static newDataValidation() {
|
|
517
|
+
return new m();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
L.extend(x);
|
|
521
|
+
class M extends S {
|
|
522
|
+
_initialize() {
|
|
523
|
+
Object.defineProperty(this, "_dataValidationModel", {
|
|
524
|
+
get() {
|
|
525
|
+
return this._injector.get(U);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* get data validation validator status for current workbook
|
|
531
|
+
* @returns matrix of validator status
|
|
532
|
+
*/
|
|
533
|
+
getValidatorStatus() {
|
|
534
|
+
return this._injector.get(u).validatorWorkbook(this._workbook.getUnitId());
|
|
535
|
+
}
|
|
536
|
+
// region DataValidationHooks
|
|
537
|
+
/**
|
|
538
|
+
* The onDataValidationChange event is fired when the data validation rule of this sheet is changed.
|
|
539
|
+
* @param callback Callback function that will be called when the event is fired
|
|
540
|
+
* @returns A disposable object that can be used to unsubscribe from the event
|
|
541
|
+
*/
|
|
542
|
+
onDataValidationChange(e) {
|
|
543
|
+
return n(this._dataValidationModel.ruleChange$.pipe(p((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* The onDataValidationStatusChange event is fired when the data validation status of this sheet is changed.
|
|
547
|
+
* @param callback Callback function that will be called when the event is fired
|
|
548
|
+
* @returns A disposable object that can be used to unsubscribe from the event
|
|
549
|
+
*/
|
|
550
|
+
onDataValidationStatusChange(e) {
|
|
551
|
+
return n(this._dataValidationModel.validStatusChange$.pipe(p((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* The onBeforeAddDataValidation event is fired before the data validation rule is added.
|
|
555
|
+
* @param callback Callback function that will be called when the event is fired
|
|
556
|
+
* @returns A disposable object that can be used to unsubscribe from the event
|
|
557
|
+
*/
|
|
558
|
+
onBeforeAddDataValidation(e) {
|
|
559
|
+
return n(this._commandService.beforeCommandExecuted((t, i) => {
|
|
560
|
+
const a = t.params;
|
|
561
|
+
if (t.id === v.id) {
|
|
562
|
+
if (a.unitId !== this._workbook.getUnitId())
|
|
563
|
+
return;
|
|
564
|
+
if (e(a, i) === !1)
|
|
565
|
+
throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
|
|
566
|
+
}
|
|
567
|
+
}));
|
|
568
|
+
}
|
|
569
|
+
onBeforeUpdateDataValidationCriteria(e) {
|
|
570
|
+
return n(this._commandService.beforeCommandExecuted((t, i) => {
|
|
571
|
+
const a = t.params;
|
|
572
|
+
if (t.id === E.id) {
|
|
573
|
+
if (a.unitId !== this._workbook.getUnitId())
|
|
574
|
+
return;
|
|
575
|
+
if (e(a, i) === !1)
|
|
576
|
+
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
|
|
577
|
+
}
|
|
578
|
+
}));
|
|
579
|
+
}
|
|
580
|
+
onBeforeUpdateDataValidationRange(e) {
|
|
581
|
+
return n(this._commandService.beforeCommandExecuted((t, i) => {
|
|
582
|
+
const a = t.params;
|
|
583
|
+
if (t.id === D.id) {
|
|
584
|
+
if (a.unitId !== this._workbook.getUnitId())
|
|
585
|
+
return;
|
|
586
|
+
if (e(a, i) === !1)
|
|
587
|
+
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
|
|
588
|
+
}
|
|
589
|
+
}));
|
|
590
|
+
}
|
|
591
|
+
onBeforeUpdateDataValidationOptions(e) {
|
|
592
|
+
return n(this._commandService.beforeCommandExecuted((t, i) => {
|
|
593
|
+
const a = t.params;
|
|
594
|
+
if (t.id === k.id) {
|
|
595
|
+
if (a.unitId !== this._workbook.getUnitId())
|
|
596
|
+
return;
|
|
597
|
+
if (e(a, i) === !1)
|
|
598
|
+
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
|
|
599
|
+
}
|
|
600
|
+
}));
|
|
601
|
+
}
|
|
602
|
+
onBeforeDeleteDataValidation(e) {
|
|
603
|
+
return n(this._commandService.beforeCommandExecuted((t, i) => {
|
|
604
|
+
const a = t.params;
|
|
605
|
+
if (t.id === b.id) {
|
|
606
|
+
if (a.unitId !== this._workbook.getUnitId())
|
|
607
|
+
return;
|
|
608
|
+
if (e(a, i) === !1)
|
|
609
|
+
throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
|
|
610
|
+
}
|
|
611
|
+
}));
|
|
612
|
+
}
|
|
613
|
+
onBeforeDeleteAllDataValidation(e) {
|
|
614
|
+
return n(this._commandService.beforeCommandExecuted((t, i) => {
|
|
615
|
+
const a = t.params;
|
|
616
|
+
if (t.id === y.id) {
|
|
617
|
+
if (a.unitId !== this._workbook.getUnitId())
|
|
618
|
+
return;
|
|
619
|
+
if (e(a, i) === !1)
|
|
620
|
+
throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
|
|
621
|
+
}
|
|
622
|
+
}));
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
S.extend(M);
|
|
626
|
+
class B extends I {
|
|
627
|
+
getDataValidations() {
|
|
628
|
+
return this._injector.get(w).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new _(t));
|
|
629
|
+
}
|
|
630
|
+
getValidatorStatus() {
|
|
631
|
+
return this._injector.get(u).validatorWorksheet(
|
|
632
|
+
this._workbook.getUnitId(),
|
|
633
|
+
this._worksheet.getSheetId()
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
I.extend(B);
|
|
638
|
+
export {
|
|
639
|
+
_ as FDataValidation,
|
|
640
|
+
m as FDataValidationBuilder
|
|
641
|
+
};
|