@univerjs/sheets-data-validation 0.5.3 → 0.5.4-nightly.202501131606

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/es/facade.js CHANGED
@@ -1,24 +1,23 @@
1
- var b = Object.defineProperty;
2
- var V = (s, e, t) => e in s ? b(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var u = (s, e, t) => V(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { UpdateSheetDataValidationSettingCommand as f, UpdateSheetDataValidationOptionsCommand as S, UpdateSheetDataValidationRangeCommand as E, RemoveSheetDataValidationCommand as I, ClearRangeDataValidationCommand as U, AddSheetDataValidationCommand as D, SheetsDataValidationValidatorService as l, SheetDataValidationModel as A, RemoveSheetAllDataValidationCommand as C } from "@univerjs/sheets-data-validation";
5
- import { FRange as c, FWorkbook as k, FWorksheet as w } from "@univerjs/sheets/facade";
6
- import { generateRandomId as g, DataValidationType as i, DataValidationErrorStyle as _, DataValidationOperator as o, IUniverInstanceService as T, ICommandService as d, FUniver as y, toDisposable as n } from "@univerjs/core";
7
- import { DataValidationModel as v, getRuleOptions as L } from "@univerjs/data-validation";
8
- import { serializeRangeToRefString as O } from "@univerjs/engine-formula";
9
- import { filter as p } from "rxjs";
10
- class h {
1
+ var j = Object.defineProperty;
2
+ var q = (c, e, t) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
3
+ var f = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
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 x } from "@univerjs/sheets/facade";
6
+ import { generateRandomId as B, DataValidationType as o, DataValidationErrorStyle as w, DataValidationOperator as d, IUniverInstanceService as H, ICommandService as p, FUniver as N, CanceledError as _, toDisposable as g, FEventName as $ } from "@univerjs/core";
7
+ import { DataValidationModel as b, getRuleOptions as F } from "@univerjs/data-validation";
8
+ import { serializeRangeToRefString as P } from "@univerjs/engine-formula";
9
+ import { filter as R } from "rxjs";
10
+ class D {
11
11
  constructor(e) {
12
- u(this, "_rule");
12
+ f(this, "_rule");
13
13
  this._rule = e != null ? e : {
14
- uid: g(),
14
+ uid: B(),
15
15
  ranges: void 0,
16
- type: i.CUSTOM
16
+ type: o.CUSTOM
17
17
  };
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
23
22
  */
24
23
  build() {
@@ -26,26 +25,23 @@ class h {
26
25
  }
27
26
  /**
28
27
  * Creates a duplicate of the current DataValidationBuilder object
29
- *
30
- * @return {FDataValidationBuilder} A new instance of the DataValidationBuilder class
28
+ * @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
31
29
  */
32
30
  copy() {
33
- return new h({
31
+ return new D({
34
32
  ...this._rule,
35
- uid: g()
33
+ uid: B()
36
34
  });
37
35
  }
38
36
  /**
39
37
  * Determines whether invalid data is allowed
40
- *
41
38
  * @returns {boolean} True if invalid data is allowed, False otherwise
42
39
  */
43
40
  getAllowInvalid() {
44
- return this._rule.errorStyle !== _.STOP;
41
+ return this._rule.errorStyle !== w.STOP;
45
42
  }
46
43
  /**
47
44
  * Gets the data validation type of the rule
48
- *
49
45
  * @returns {DataValidationType} The data validation type
50
46
  */
51
47
  getCriteriaType() {
@@ -53,7 +49,6 @@ class h {
53
49
  }
54
50
  /**
55
51
  * Gets the values used for criteria evaluation
56
- *
57
52
  * @returns {[string, string, string]} An array containing the operator, formula1, and formula2 values
58
53
  */
59
54
  getCriteriaValues() {
@@ -61,7 +56,6 @@ class h {
61
56
  }
62
57
  /**
63
58
  * Gets the help text information, which is used to provide users with guidance and support
64
- *
65
59
  * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value.
66
60
  */
67
61
  getHelpText() {
@@ -69,202 +63,183 @@ class h {
69
63
  }
70
64
  /**
71
65
  * Sets the data validation type to CHECKBOX and sets the checked and unchecked values
72
- *
73
66
  * @param checkedValue The value when the checkbox is checked (Optional)
74
67
  * @param uncheckedValue The value when the checkbox is unchecked (Optional)
75
68
  * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
76
69
  */
77
70
  requireCheckbox(e, t) {
78
- return this._rule.type = i.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
71
+ return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
79
72
  }
80
73
  /**
81
74
  * Set the data validation type to DATE and configure the validation rules to be after a specific date
82
- *
83
75
  * @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
76
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
85
77
  */
86
78
  requireDateAfter(e) {
87
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = o.GREATER_THAN, this;
79
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = d.GREATER_THAN, this;
88
80
  }
89
81
  /**
90
82
  * Set the data validation type to DATE and configure the validation rules to be before a specific date
91
- *
92
83
  * @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
84
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
94
85
  */
95
86
  requireDateBefore(e) {
96
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN, this;
87
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN, this;
97
88
  }
98
89
  /**
99
90
  * Set the data validation type to DATE and configure the validation rules to be within a specific date range
100
- *
101
91
  * @param start The starting date of the range. The formatted date string will be set as formula1
102
92
  * @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
93
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
104
94
  */
105
95
  requireDateBetween(e, t) {
106
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = o.BETWEEN, this;
96
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = d.BETWEEN, this;
107
97
  }
108
98
  /**
109
99
  * Set the data validation type to DATE and configure the validation rules to be equal to a specific date
110
- *
111
100
  * @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
101
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
113
102
  */
114
103
  requireDateEqualTo(e) {
115
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.EQUAL, this;
104
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.EQUAL, this;
116
105
  }
117
106
  /**
118
107
  * Set the data validation type to DATE and configure the validation rules to be not within a specific date range
119
- *
120
108
  * @param start The starting date of the date range
121
109
  * @param end The ending date of the date range
122
- * @return The current instance of the FDataValidationBuilder class to allow for method chaining
110
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
123
111
  */
124
112
  requireDateNotBetween(e, t) {
125
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = o.NOT_BETWEEN, this;
113
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = d.NOT_BETWEEN, this;
126
114
  }
127
115
  /**
128
116
  * Set the data validation type to DATE and configure the validation rules to be on or after a specific date
129
- *
130
117
  * @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
118
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
132
119
  */
133
120
  requireDateOnOrAfter(e) {
134
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN_OR_EQUAL, this;
121
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN_OR_EQUAL, this;
135
122
  }
136
123
  /**
137
124
  * Set the data validation type to DATE and configure the validation rules to be on or before a specific date
138
- *
139
125
  * @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
126
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
141
127
  */
142
128
  requireDateOnOrBefore(e) {
143
- return this._rule.type = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN_OR_EQUAL, this;
129
+ return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN_OR_EQUAL, this;
144
130
  }
145
131
  /**
146
132
  * Requires that a custom formula be satisfied.
147
133
  * Sets the data validation type to CUSTOM and configures the validation rule based on the provided formula string.
148
- *
149
134
  * @param formula The formula string that needs to be satisfied.
150
- * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
135
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
151
136
  */
152
137
  requireFormulaSatisfied(e) {
153
- return this._rule.type = i.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
138
+ return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
154
139
  }
155
140
  /**
156
141
  * Requires the user to enter a number within a specific range, which can be integer or decimal.
157
142
  * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number range.
158
- *
159
143
  * @param start The starting value of the number range.
160
144
  * @param end The ending value of the number range.
161
145
  * @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.
146
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
163
147
  */
164
148
  requireNumberBetween(e, t, r) {
165
- return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.BETWEEN, this._rule.type = r ? i.WHOLE : i.DECIMAL, this;
149
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = d.BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
166
150
  }
167
151
  /**
168
152
  * Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal.
169
153
  * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
170
- *
171
154
  * @param num The number to which the entered number should be equal.
172
155
  * @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.
156
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
174
157
  */
175
158
  requireNumberEqualTo(e, t) {
176
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.EQUAL, this._rule.type = t ? i.WHOLE : i.DECIMAL, this;
159
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
177
160
  }
178
161
  /**
179
162
  * Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal.
180
163
  * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
181
- *
182
164
  * @param num The number to which the entered number should be greater.
183
165
  * @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.
166
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
185
167
  */
186
168
  requireNumberGreaterThan(e, t) {
187
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN, this._rule.type = t ? i.WHOLE : i.DECIMAL, this;
169
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
188
170
  }
189
171
  /**
190
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.
191
173
  * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
192
- *
193
174
  * @param num The number to which the entered number should be greater than or equal.
194
175
  * @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.
176
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
196
177
  */
197
178
  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 ? i.WHOLE : i.DECIMAL, this;
179
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
199
180
  }
200
181
  /**
201
182
  * Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal.
202
183
  * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
203
- *
204
184
  * @param num The number to which the entered number should be less.
205
185
  * @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.
186
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
207
187
  */
208
188
  requireNumberLessThan(e, t) {
209
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN, this._rule.type = t ? i.WHOLE : i.DECIMAL, this;
189
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
210
190
  }
211
191
  /**
212
192
  * Sets the data validation rule to require a number less than or equal to a specified value
213
193
  * The specified value can be an integer or a decimal
214
- *
215
194
  * @param num The number to which the entered number should be less than or equal
216
195
  * @param isInteger Indicates whether the required number is an integer
217
- * @return The current instance of the DataValidationBuilder class, allowing for method chaining
196
+ * @returns The current instance of the DataValidationBuilder class, allowing for method chaining
218
197
  */
219
198
  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 ? i.WHOLE : i.DECIMAL, this;
199
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
221
200
  }
222
201
  /**
223
202
  * Sets a data validation rule that requires the user to enter a number outside a specified range
224
203
  * The specified range includes all integers and decimals
225
- *
226
204
  * @param start The starting point of the specified range
227
205
  * @param end The end point of the specified range
228
206
  * @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
207
+ * @returns An instance of the FDataValidationBuilder class, allowing for method chaining
230
208
  */
231
209
  requireNumberNotBetween(e, t, r) {
232
- return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.NOT_BETWEEN, this._rule.type = r ? i.WHOLE : i.DECIMAL, this;
210
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = d.NOT_BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
233
211
  }
234
212
  /**
235
213
  * Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
236
214
  * The specific value can be an integer or a decimal
237
- *
238
215
  * @param num The number to which the entered number should not be equal
239
216
  * @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
217
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
241
218
  */
242
219
  requireNumberNotEqualTo(e, t) {
243
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.NOT_EQUAL, this._rule.type = t ? i.WHOLE : i.DECIMAL, this;
220
+ return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.NOT_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
244
221
  }
245
222
  /**
246
223
  * Sets a data validation rule that requires the user to enter a value from a list of specific values.
247
224
  * The list can be displayed in a dropdown, and the user can choose multiple values according to the settings.
248
- *
249
225
  * @param values An array containing the specific values that the user can enter.
250
226
  * @param multiple Optional parameter indicating whether the user can select multiple values. Default is false, meaning only one value can be selected.
251
227
  * @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.
228
+ * @returns An instance of the FDataValidationBuilder class, allowing for method chaining.
253
229
  */
254
230
  requireValueInList(e, t, r) {
255
- return this._rule.type = t ? i.LIST_MULTIPLE : i.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
231
+ 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
232
  }
257
233
  /**
258
234
  * Sets a data validation rule that requires the user to enter a value within a specific range.
259
235
  * The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range.
260
- *
261
236
  * @param range An FRange object representing the range of values that the user can enter.
262
237
  * @param multiple Optional parameter indicating whether the user can select multiple values. Default is false, meaning only one value can be selected.
263
238
  * @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.
239
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
265
240
  */
266
241
  requireValueInRange(e, t, r) {
267
- return this._rule.type = t ? i.LIST_MULTIPLE : i.LIST, this._rule.formula1 = `=${O({
242
+ return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${P({
268
243
  unitId: e.getUnitId(),
269
244
  sheetName: e.getSheetName(),
270
245
  range: e.getRange()
@@ -274,19 +249,17 @@ class h {
274
249
  * Sets whether to allow invalid data and configures the error style for data validation.
275
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.
276
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.
277
- *
278
252
  * @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.
253
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
280
254
  */
281
255
  setAllowInvalid(e) {
282
- return this._rule.errorStyle = e ? _.WARNING : _.STOP, this;
256
+ return this._rule.errorStyle = e ? w.WARNING : w.STOP, this;
283
257
  }
284
258
  /**
285
259
  * Sets the help text and enables the display of error messages for data validation.
286
260
  * This method allows you to set a custom help text that will be displayed when the user enters invalid data.
287
- *
288
261
  * @param helpText The text to display as help information.
289
- * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
262
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
290
263
  */
291
264
  setHelpText(e) {
292
265
  return this._rule.error = e, this._rule.showErrorMessage = !0, this;
@@ -294,12 +267,11 @@ class h {
294
267
  /**
295
268
  * Sets the criteria values for data validation.
296
269
  * This method is used to configure the validation rules based on specific criteria values.
297
- *
298
270
  * @param type The type of data validation.
299
271
  * @param values An array containing the criteria values.
300
272
  * The array should have three elements: [operator, formula1, formula2].
301
273
  * 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.
274
+ * @returns The current instance of the FDataValidationBuilder class, allowing for method chaining.
303
275
  */
304
276
  withCriteriaValues(e, t) {
305
277
  return this._rule.type = e, this._rule.operator = t[0], this._rule.formula1 = t[1], this._rule.formula2 = t[2], this;
@@ -310,7 +282,6 @@ class h {
310
282
  /**
311
283
  * Sets the options for the data validation rule.
312
284
  * For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
313
- *
314
285
  * @param options The options to set for the data validation rule.
315
286
  * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
316
287
  */
@@ -320,22 +291,20 @@ class h {
320
291
  }
321
292
  class m {
322
293
  constructor(e, t, r) {
323
- u(this, "rule");
324
- u(this, "_worksheet");
325
- u(this, "_injector");
294
+ f(this, "rule");
295
+ f(this, "_worksheet");
296
+ f(this, "_injector");
326
297
  this._injector = r, this.rule = e, this._worksheet = t;
327
298
  }
328
299
  /**
329
300
  * Gets whether invalid data is allowed based on the error style value.
330
- *
331
- * @return true if invalid data is allowed, false otherwise.
301
+ * @returns true if invalid data is allowed, false otherwise.
332
302
  */
333
303
  getAllowInvalid() {
334
- return this.rule.errorStyle !== _.STOP;
304
+ return this.rule.errorStyle !== w.STOP;
335
305
  }
336
306
  /**
337
307
  * Gets the data validation type of the rule
338
- *
339
308
  * @returns The data validation type
340
309
  */
341
310
  getCriteriaType() {
@@ -343,7 +312,6 @@ class m {
343
312
  }
344
313
  /**
345
314
  * Gets the values used for criteria evaluation
346
- *
347
315
  * @returns An array containing the operator, formula1, and formula2 values
348
316
  */
349
317
  getCriteriaValues() {
@@ -351,7 +319,6 @@ class m {
351
319
  }
352
320
  /**
353
321
  * Gets the help text information, which is used to provide users with guidance and support
354
- *
355
322
  * @returns Returns the help text information. If there is no error message, it returns an undefined value.
356
323
  */
357
324
  getHelpText() {
@@ -360,37 +327,33 @@ class m {
360
327
  /**
361
328
  * Creates a new instance of FDataValidationBuilder using the current rule object.
362
329
  * This method is useful for copying an existing data validation rule configuration.
363
- *
364
- * @return A new FDataValidationBuilder instance with the same rule configuration.
330
+ * @returns A new FDataValidationBuilder instance with the same rule configuration.
365
331
  */
366
332
  copy() {
367
- return new h(this.rule);
333
+ return new D(this.rule);
368
334
  }
369
335
  /**
370
336
  * Gets whether the data validation rule is applied to the worksheet.
371
- *
372
337
  * @returns true if the rule is applied, false otherwise.
373
338
  */
374
339
  getApplied() {
375
340
  if (!this._worksheet)
376
341
  return !1;
377
- const t = this._injector.get(v).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
342
+ const t = this._injector.get(b).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
378
343
  return !!(t && t.ranges.length);
379
344
  }
380
345
  /**
381
346
  * Gets the ranges to which the data validation rule is applied.
382
- *
383
347
  * @returns An array of IRange objects representing the ranges to which the data validation rule is applied.
384
348
  */
385
349
  getRanges() {
386
350
  if (!this.getApplied())
387
351
  return [];
388
- const e = this._injector.get(T).getUnit(this._worksheet.getUnitId());
389
- return this.rule.ranges.map((t) => this._injector.createInstance(c, e, this._worksheet, t));
352
+ const e = this._injector.get(H).getUnit(this._worksheet.getUnitId());
353
+ return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
390
354
  }
391
355
  /**
392
356
  * Gets the title of the error message dialog box.
393
- *
394
357
  * @returns The title of the error message dialog box.
395
358
  */
396
359
  getUnitId() {
@@ -399,7 +362,6 @@ class m {
399
362
  }
400
363
  /**
401
364
  * Gets the sheetId of the worksheet.
402
- *
403
365
  * @returns The sheetId of the worksheet.
404
366
  */
405
367
  getSheetId() {
@@ -410,10 +372,11 @@ class m {
410
372
  * Set Criteria for the data validation rule.
411
373
  * @param type The type of data validation criteria.
412
374
  * @param values An array containing the operator, formula1, and formula2 values.
375
+ * @param allowBlank
413
376
  * @returns true if the criteria is set successfully, false otherwise.
414
377
  */
415
378
  setCriteria(e, t, r = !0) {
416
- if (this.getApplied() && !this._injector.get(d).syncExecuteCommand(f.id, {
379
+ if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
417
380
  unitId: this.getUnitId(),
418
381
  subUnitId: this.getSheetId(),
419
382
  ruleId: this.rule.uid,
@@ -435,12 +398,12 @@ class m {
435
398
  * @returns true if the options are set successfully, false otherwise.
436
399
  */
437
400
  setOptions(e) {
438
- if (this.getApplied() && !this._injector.get(d).syncExecuteCommand(S.id, {
401
+ if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(v.id, {
439
402
  unitId: this.getUnitId(),
440
403
  subUnitId: this.getSheetId(),
441
404
  ruleId: this.rule.uid,
442
405
  options: {
443
- ...L(this.rule),
406
+ ...F(this.rule),
444
407
  ...e
445
408
  }
446
409
  }))
@@ -453,7 +416,7 @@ class m {
453
416
  * @returns true if the ranges are set successfully, false otherwise.
454
417
  */
455
418
  setRanges(e) {
456
- if (this.getApplied() && !this._injector.get(d).syncExecuteCommand(E.id, {
419
+ if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
457
420
  unitId: this.getUnitId(),
458
421
  subUnitId: this.getSheetId(),
459
422
  ruleId: this.rule.uid,
@@ -467,17 +430,17 @@ class m {
467
430
  * @returns true if the rule is deleted successfully, false otherwise.
468
431
  */
469
432
  delete() {
470
- return this.getApplied() ? this._injector.get(d).syncExecuteCommand(I.id, {
433
+ return this.getApplied() ? this._injector.get(p).syncExecuteCommand(T.id, {
471
434
  unitId: this.getUnitId(),
472
435
  subUnitId: this.getSheetId(),
473
436
  ruleId: this.rule.uid
474
437
  }) : !1;
475
438
  }
476
439
  }
477
- class R extends c {
440
+ class G extends y {
478
441
  setDataValidation(e) {
479
442
  if (!e)
480
- return this._commandService.syncExecuteCommand(U.id, {
443
+ return this._commandService.syncExecuteCommand(W.id, {
481
444
  unitId: this._workbook.getUnitId(),
482
445
  subUnitId: this._worksheet.getSheetId(),
483
446
  ranges: [this._range]
@@ -490,10 +453,10 @@ class R extends c {
490
453
  ranges: [this._range]
491
454
  }
492
455
  };
493
- return this._commandService.syncExecuteCommand(D.id, t), this;
456
+ return this._commandService.syncExecuteCommand(A.id, t), this;
494
457
  }
495
458
  getDataValidation() {
496
- const t = this._injector.get(l).getDataValidation(
459
+ const t = this._injector.get(S).getDataValidation(
497
460
  this._workbook.getUnitId(),
498
461
  this._worksheet.getSheetId(),
499
462
  [this._range]
@@ -501,74 +464,188 @@ class R extends c {
501
464
  return t && new m(t, this._worksheet, this._injector);
502
465
  }
503
466
  getDataValidations() {
504
- return this._injector.get(l).getDataValidations(
467
+ return this._injector.get(S).getDataValidations(
505
468
  this._workbook.getUnitId(),
506
469
  this._worksheet.getSheetId(),
507
470
  [this._range]
508
471
  ).map((t) => new m(t, this._worksheet, this._injector));
509
472
  }
510
473
  async getValidatorStatus() {
511
- return this._injector.get(l).validatorRanges(
474
+ return this._injector.get(S).validatorRanges(
512
475
  this._workbook.getUnitId(),
513
476
  this._worksheet.getSheetId(),
514
477
  [this._range]
515
478
  );
516
479
  }
517
480
  }
518
- c.extend(R);
519
- class N {
481
+ y.extend(G);
482
+ class Q extends N {
483
+ /**
520
484
  /**
521
485
  * @deparecated use `univerAPI.newDataValidation()` as instead.
522
486
  */
523
487
  static newDataValidation() {
524
- return new h();
488
+ return new D();
525
489
  }
526
490
  newDataValidation() {
527
- return new h();
491
+ return new D();
492
+ }
493
+ // eslint-disable-next-line max-lines-per-function
494
+ _initialize(e) {
495
+ if (!e.has(V)) return;
496
+ const t = e.get(V), r = e.get(p);
497
+ this.disposeWithMe(t.ruleChange$.subscribe((a) => {
498
+ const { unitId: i, subUnitId: n, rule: h, oldRule: u, type: s } = a, l = this.getSheetTarget(i, n);
499
+ if (!l)
500
+ return;
501
+ const { workbook: I, worksheet: k } = l, E = new m(h, k.getSheet(), this._injector);
502
+ this.fireEvent(this.Event.SheetDataValidationChanged, {
503
+ origin: a,
504
+ worksheet: k,
505
+ workbook: I,
506
+ changeType: s,
507
+ oldRule: u,
508
+ rule: E
509
+ });
510
+ })), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
511
+ const { unitId: i, subUnitId: n, ruleId: h, status: u, row: s, col: l } = a, I = this.getSheetTarget(i, n);
512
+ if (!I)
513
+ return;
514
+ const { workbook: k, worksheet: E } = I, L = E.getDataValidation(h);
515
+ L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
516
+ workbook: k,
517
+ worksheet: E,
518
+ row: s,
519
+ column: l,
520
+ rule: L,
521
+ status: u
522
+ });
523
+ })), this.disposeWithMe(r.beforeCommandExecuted((a) => {
524
+ switch (a.id) {
525
+ case A.id: {
526
+ const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
527
+ if (!n)
528
+ return;
529
+ const { workbook: h, worksheet: u } = n, s = {
530
+ worksheet: u,
531
+ workbook: h,
532
+ rule: i.rule
533
+ };
534
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
535
+ throw new _();
536
+ break;
537
+ }
538
+ case U.id: {
539
+ const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
540
+ if (!n)
541
+ return;
542
+ const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
543
+ if (!s)
544
+ return;
545
+ const l = {
546
+ worksheet: u,
547
+ workbook: h,
548
+ rule: s,
549
+ ruleId: i.ruleId,
550
+ newCriteria: i.setting
551
+ };
552
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, l), l.cancel)
553
+ throw new _();
554
+ break;
555
+ }
556
+ case C.id: {
557
+ const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
558
+ if (!n)
559
+ return;
560
+ const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
561
+ if (!s)
562
+ return;
563
+ const l = {
564
+ worksheet: u,
565
+ workbook: h,
566
+ rule: s,
567
+ ruleId: i.ruleId,
568
+ newRanges: i.ranges
569
+ };
570
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, l), l.cancel)
571
+ throw new _();
572
+ break;
573
+ }
574
+ case v.id: {
575
+ const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
576
+ if (!n)
577
+ return;
578
+ const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
579
+ if (!s)
580
+ return;
581
+ const l = {
582
+ worksheet: u,
583
+ workbook: h,
584
+ rule: s,
585
+ ruleId: i.ruleId,
586
+ newOptions: i.options
587
+ };
588
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, l), l.cancel)
589
+ throw new _();
590
+ break;
591
+ }
592
+ case T.id: {
593
+ const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
594
+ if (!n)
595
+ return;
596
+ const { workbook: h, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
597
+ if (!s)
598
+ return;
599
+ const l = {
600
+ worksheet: u,
601
+ workbook: h,
602
+ rule: s,
603
+ ruleId: i.ruleId
604
+ };
605
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, l), l.cancel)
606
+ throw new _();
607
+ break;
608
+ }
609
+ case O.id: {
610
+ const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
611
+ if (!n)
612
+ return;
613
+ const { workbook: h, worksheet: u } = n, s = {
614
+ worksheet: u,
615
+ workbook: h,
616
+ rules: u.getDataValidations()
617
+ };
618
+ if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
619
+ throw new _();
620
+ break;
621
+ }
622
+ }
623
+ }));
528
624
  }
529
625
  }
530
- y.extend(N);
531
- class x extends k {
626
+ N.extend(Q);
627
+ class z extends M {
532
628
  _initialize() {
533
629
  Object.defineProperty(this, "_dataValidationModel", {
534
630
  get() {
535
- return this._injector.get(A);
631
+ return this._injector.get(V);
536
632
  }
537
633
  });
538
634
  }
539
- /**
540
- * get data validation validator status for current workbook
541
- * @returns matrix of validator status
542
- */
543
635
  getValidatorStatus() {
544
- return this._injector.get(l).validatorWorkbook(this._workbook.getUnitId());
636
+ return this._injector.get(S).validatorWorkbook(this._workbook.getUnitId());
545
637
  }
546
638
  // region DataValidationHooks
547
- /**
548
- * The onDataValidationChange event is fired when the data validation rule of this sheet is changed.
549
- * @param callback Callback function that will be called when the event is fired
550
- * @returns A disposable object that can be used to unsubscribe from the event
551
- */
552
639
  onDataValidationChange(e) {
553
- return n(this._dataValidationModel.ruleChange$.pipe(p((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
640
+ return g(this._dataValidationModel.ruleChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
554
641
  }
555
- /**
556
- * The onDataValidationStatusChange event is fired when the data validation status of this sheet is changed.
557
- * @param callback Callback function that will be called when the event is fired
558
- * @returns A disposable object that can be used to unsubscribe from the event
559
- */
560
642
  onDataValidationStatusChange(e) {
561
- return n(this._dataValidationModel.validStatusChange$.pipe(p((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
643
+ return g(this._dataValidationModel.validStatusChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
562
644
  }
563
- /**
564
- * The onBeforeAddDataValidation event is fired before the data validation rule is added.
565
- * @param callback Callback function that will be called when the event is fired
566
- * @returns A disposable object that can be used to unsubscribe from the event
567
- */
568
645
  onBeforeAddDataValidation(e) {
569
- return n(this._commandService.beforeCommandExecuted((t, r) => {
646
+ return g(this._commandService.beforeCommandExecuted((t, r) => {
570
647
  const a = t.params;
571
- if (t.id === D.id) {
648
+ if (t.id === A.id) {
572
649
  if (a.unitId !== this._workbook.getUnitId())
573
650
  return;
574
651
  if (e(a, r) === !1)
@@ -577,9 +654,9 @@ class x extends k {
577
654
  }));
578
655
  }
579
656
  onBeforeUpdateDataValidationCriteria(e) {
580
- return n(this._commandService.beforeCommandExecuted((t, r) => {
657
+ return g(this._commandService.beforeCommandExecuted((t, r) => {
581
658
  const a = t.params;
582
- if (t.id === f.id) {
659
+ if (t.id === U.id) {
583
660
  if (a.unitId !== this._workbook.getUnitId())
584
661
  return;
585
662
  if (e(a, r) === !1)
@@ -588,9 +665,9 @@ class x extends k {
588
665
  }));
589
666
  }
590
667
  onBeforeUpdateDataValidationRange(e) {
591
- return n(this._commandService.beforeCommandExecuted((t, r) => {
668
+ return g(this._commandService.beforeCommandExecuted((t, r) => {
592
669
  const a = t.params;
593
- if (t.id === E.id) {
670
+ if (t.id === C.id) {
594
671
  if (a.unitId !== this._workbook.getUnitId())
595
672
  return;
596
673
  if (e(a, r) === !1)
@@ -599,9 +676,9 @@ class x extends k {
599
676
  }));
600
677
  }
601
678
  onBeforeUpdateDataValidationOptions(e) {
602
- return n(this._commandService.beforeCommandExecuted((t, r) => {
679
+ return g(this._commandService.beforeCommandExecuted((t, r) => {
603
680
  const a = t.params;
604
- if (t.id === S.id) {
681
+ if (t.id === v.id) {
605
682
  if (a.unitId !== this._workbook.getUnitId())
606
683
  return;
607
684
  if (e(a, r) === !1)
@@ -610,9 +687,9 @@ class x extends k {
610
687
  }));
611
688
  }
612
689
  onBeforeDeleteDataValidation(e) {
613
- return n(this._commandService.beforeCommandExecuted((t, r) => {
690
+ return g(this._commandService.beforeCommandExecuted((t, r) => {
614
691
  const a = t.params;
615
- if (t.id === I.id) {
692
+ if (t.id === T.id) {
616
693
  if (a.unitId !== this._workbook.getUnitId())
617
694
  return;
618
695
  if (e(a, r) === !1)
@@ -621,9 +698,9 @@ class x extends k {
621
698
  }));
622
699
  }
623
700
  onBeforeDeleteAllDataValidation(e) {
624
- return n(this._commandService.beforeCommandExecuted((t, r) => {
701
+ return g(this._commandService.beforeCommandExecuted((t, r) => {
625
702
  const a = t.params;
626
- if (t.id === C.id) {
703
+ if (t.id === O.id) {
627
704
  if (a.unitId !== this._workbook.getUnitId())
628
705
  return;
629
706
  if (e(a, r) === !1)
@@ -632,20 +709,51 @@ class x extends k {
632
709
  }));
633
710
  }
634
711
  }
635
- k.extend(x);
636
- class B extends w {
712
+ M.extend(z);
713
+ class K extends x {
637
714
  getDataValidations() {
638
- return this._injector.get(v).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
715
+ return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
639
716
  }
640
717
  getValidatorStatus() {
641
- return this._injector.get(l).validatorWorksheet(
718
+ return this._injector.get(S).validatorWorksheet(
642
719
  this._workbook.getUnitId(),
643
720
  this._worksheet.getSheetId()
644
721
  );
645
722
  }
723
+ getDataValidation(e) {
724
+ const r = this._injector.get(b).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
725
+ return r ? new m(r, this._worksheet, this._injector) : null;
726
+ }
727
+ }
728
+ x.extend(K);
729
+ class X {
730
+ get SheetDataValidationChanged() {
731
+ return "SheetDataValidationChanged";
732
+ }
733
+ get SheetDataValidatorStatusChanged() {
734
+ return "SheetDataValidatorStatusChanged";
735
+ }
736
+ get BeforeSheetDataValidationAdd() {
737
+ return "BeforeSheetDataValidationAdd";
738
+ }
739
+ get BeforeSheetDataValidationDelete() {
740
+ return "BeforeSheetDataValidationDelete";
741
+ }
742
+ get BeforeSheetDataValidationDeleteAll() {
743
+ return "BeforeSheetDataValidationDeleteAll";
744
+ }
745
+ get BeforeSheetDataValidationCriteriaUpdate() {
746
+ return "BeforeSheetDataValidationCriteriaUpdate";
747
+ }
748
+ get BeforeSheetDataValidationRangeUpdate() {
749
+ return "BeforeSheetDataValidationRangeUpdate";
750
+ }
751
+ get BeforeSheetDataValidationOptionsUpdate() {
752
+ return "BeforeSheetDataValidationOptionsUpdate";
753
+ }
646
754
  }
647
- w.extend(B);
755
+ $.extend(X);
648
756
  export {
649
757
  m as FDataValidation,
650
- h as FDataValidationBuilder
758
+ D as FDataValidationBuilder
651
759
  };