@univerjs/sheets-data-validation 0.5.4 → 0.5.5-experimental.20250122-3362a4a
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 +690 -445
- package/lib/es/index.js +1741 -1702
- package/lib/types/facade/f-data-validation-builder.d.ts +238 -133
- package/lib/types/facade/f-data-validation.d.ts +158 -38
- package/lib/types/facade/f-range.d.ts +36 -9
- package/lib/types/facade/f-univer.d.ts +13 -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
|
@@ -1,769 +1,1012 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this
|
|
14
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { UpdateSheetDataValidationSettingCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, RemoveSheetDataValidationCommand, ClearRangeDataValidationCommand, AddSheetDataValidationCommand, SheetsDataValidationValidatorService, SheetDataValidationModel, RemoveSheetAllDataValidationCommand } from "@univerjs/sheets-data-validation";
|
|
6
|
+
import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
|
|
7
|
+
import { generateRandomId, DataValidationType, DataValidationErrorStyle, DataValidationOperator, IUniverInstanceService, ICommandService, FUniver, CanceledError, toDisposable, FEventName } from "@univerjs/core";
|
|
8
|
+
import { DataValidationModel, getRuleOptions } from "@univerjs/data-validation";
|
|
9
|
+
import { serializeRangeToRefString } from "@univerjs/engine-formula";
|
|
10
|
+
import { filter } from "rxjs";
|
|
11
|
+
const _FDataValidationBuilder = class _FDataValidationBuilder {
|
|
12
|
+
constructor(rule) {
|
|
13
|
+
__publicField(this, "_rule");
|
|
14
|
+
this._rule = rule != null ? rule : {
|
|
15
|
+
uid: generateRandomId(),
|
|
15
16
|
ranges: void 0,
|
|
16
|
-
type:
|
|
17
|
+
type: DataValidationType.CUSTOM
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Builds an FDataValidation instance based on the _rule property of the current class
|
|
21
|
-
*
|
|
22
22
|
* @returns {FDataValidation} A new instance of the FDataValidation class
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const builder = univerAPI.newDataValidation();
|
|
26
|
+
* const validation = builder.requireNumberBetween(1, 10).build();
|
|
27
|
+
* ```
|
|
23
28
|
*/
|
|
24
29
|
build() {
|
|
25
|
-
return new
|
|
30
|
+
return new FDataValidation(this._rule);
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* Creates a duplicate of the current DataValidationBuilder object
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
34
|
+
* @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const builder = univerAPI.newDataValidation();
|
|
38
|
+
* const copy = builder.requireNumberBetween(1, 10).copy();
|
|
39
|
+
* ```
|
|
31
40
|
*/
|
|
32
41
|
copy() {
|
|
33
|
-
return new
|
|
42
|
+
return new _FDataValidationBuilder({
|
|
34
43
|
...this._rule,
|
|
35
|
-
uid:
|
|
44
|
+
uid: generateRandomId()
|
|
36
45
|
});
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* Determines whether invalid data is allowed
|
|
40
|
-
*
|
|
41
49
|
* @returns {boolean} True if invalid data is allowed, False otherwise
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const builder = univerAPI.newDataValidation();
|
|
53
|
+
* const allowsInvalid = builder.getAllowInvalid();
|
|
54
|
+
* ```
|
|
42
55
|
*/
|
|
43
56
|
getAllowInvalid() {
|
|
44
|
-
return this._rule.errorStyle !==
|
|
57
|
+
return this._rule.errorStyle !== DataValidationErrorStyle.STOP;
|
|
45
58
|
}
|
|
46
59
|
/**
|
|
47
60
|
* Gets the data validation type of the rule
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
61
|
+
* @returns {DataValidationType | string} The data validation type
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const builder = univerAPI.newDataValidation();
|
|
65
|
+
* const type = builder.getCriteriaType();
|
|
66
|
+
* ```
|
|
50
67
|
*/
|
|
51
68
|
getCriteriaType() {
|
|
52
69
|
return this._rule.type;
|
|
53
70
|
}
|
|
54
71
|
/**
|
|
55
72
|
* Gets the values used for criteria evaluation
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
73
|
+
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const builder = univerAPI.newDataValidation();
|
|
77
|
+
* const [operator, formula1, formula2] = builder.getCriteriaValues();
|
|
78
|
+
* ```
|
|
58
79
|
*/
|
|
59
80
|
getCriteriaValues() {
|
|
60
81
|
return [this._rule.operator, this._rule.formula1, this._rule.formula2];
|
|
61
82
|
}
|
|
62
83
|
/**
|
|
63
84
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
85
|
+
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const builder = univerAPI.newDataValidation();
|
|
89
|
+
* const helpText = builder.getHelpText();
|
|
90
|
+
* ```
|
|
66
91
|
*/
|
|
67
92
|
getHelpText() {
|
|
68
93
|
return this._rule.error;
|
|
69
94
|
}
|
|
70
95
|
/**
|
|
71
96
|
* Sets the data validation type to CHECKBOX and sets the checked and unchecked values
|
|
72
|
-
*
|
|
73
|
-
* @param
|
|
74
|
-
* @
|
|
75
|
-
* @
|
|
97
|
+
* @param {string} [checkedValue] - The value when the checkbox is checked
|
|
98
|
+
* @param {string} [uncheckedValue] - The value when the checkbox is unchecked
|
|
99
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const builder = univerAPI.newDataValidation();
|
|
103
|
+
* const rule = builder.requireCheckbox('Yes', 'No').build();
|
|
104
|
+
* ```
|
|
76
105
|
*/
|
|
77
|
-
requireCheckbox(
|
|
78
|
-
return this._rule.type =
|
|
106
|
+
requireCheckbox(checkedValue, uncheckedValue) {
|
|
107
|
+
return this._rule.type = DataValidationType.CHECKBOX, this._rule.formula1 = checkedValue, this._rule.formula2 = uncheckedValue, this;
|
|
79
108
|
}
|
|
80
109
|
/**
|
|
81
110
|
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
84
|
-
* @
|
|
111
|
+
* @param {Date} date - The date to compare against
|
|
112
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const builder = univerAPI.newDataValidation();
|
|
116
|
+
* const rule = builder.requireDateAfter(new Date('2024-01-01')).build();
|
|
117
|
+
* ```
|
|
85
118
|
*/
|
|
86
|
-
requireDateAfter(
|
|
87
|
-
return this._rule.type =
|
|
119
|
+
requireDateAfter(date) {
|
|
120
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = date.toLocaleDateString(), this._rule.operator = DataValidationOperator.GREATER_THAN, this;
|
|
88
121
|
}
|
|
89
122
|
/**
|
|
90
123
|
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
91
|
-
*
|
|
92
|
-
* @
|
|
93
|
-
* @
|
|
124
|
+
* @param {Date} date - The date to compare against
|
|
125
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const builder = univerAPI.newDataValidation();
|
|
129
|
+
* const rule = builder.requireDateBefore(new Date('2024-12-31')).build();
|
|
130
|
+
* ```
|
|
94
131
|
*/
|
|
95
|
-
requireDateBefore(
|
|
96
|
-
return this._rule.type =
|
|
132
|
+
requireDateBefore(date) {
|
|
133
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = date.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.LESS_THAN, this;
|
|
97
134
|
}
|
|
98
135
|
/**
|
|
99
136
|
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
100
|
-
*
|
|
101
|
-
* @param
|
|
102
|
-
* @
|
|
103
|
-
* @
|
|
137
|
+
* @param {Date} start - The starting date of the range
|
|
138
|
+
* @param {Date} end - The ending date of the range
|
|
139
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const builder = univerAPI.newDataValidation();
|
|
143
|
+
* const rule = builder
|
|
144
|
+
* .requireDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
|
|
145
|
+
* .build();
|
|
146
|
+
* ```
|
|
104
147
|
*/
|
|
105
|
-
requireDateBetween(
|
|
106
|
-
return this._rule.type =
|
|
148
|
+
requireDateBetween(start, end) {
|
|
149
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = start.toLocaleDateString(), this._rule.formula2 = end.toLocaleDateString(), this._rule.operator = DataValidationOperator.BETWEEN, this;
|
|
107
150
|
}
|
|
108
151
|
/**
|
|
109
152
|
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
110
|
-
*
|
|
111
|
-
* @
|
|
112
|
-
* @
|
|
153
|
+
* @param {Date} date - The date to compare against
|
|
154
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const builder = univerAPI.newDataValidation();
|
|
158
|
+
* const rule = builder.requireDateEqualTo(new Date('2024-01-01')).build();
|
|
159
|
+
* ```
|
|
113
160
|
*/
|
|
114
|
-
requireDateEqualTo(
|
|
115
|
-
return this._rule.type =
|
|
161
|
+
requireDateEqualTo(date) {
|
|
162
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = date.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.EQUAL, this;
|
|
116
163
|
}
|
|
117
164
|
/**
|
|
118
165
|
* 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
|
-
* @
|
|
166
|
+
* @param {Date} start - The starting date of the date range
|
|
167
|
+
* @param {Date} end - The ending date of the date range
|
|
168
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const builder = univerAPI.newDataValidation();
|
|
172
|
+
* const rule = builder
|
|
173
|
+
* .requireDateNotBetween(new Date('2024-01-01'), new Date('2024-12-31'))
|
|
174
|
+
* .build();
|
|
175
|
+
* ```
|
|
123
176
|
*/
|
|
124
|
-
requireDateNotBetween(
|
|
125
|
-
return this._rule.type =
|
|
177
|
+
requireDateNotBetween(start, end) {
|
|
178
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = start.toLocaleDateString(), this._rule.formula2 = end.toLocaleDateString(), this._rule.operator = DataValidationOperator.NOT_BETWEEN, this;
|
|
126
179
|
}
|
|
127
180
|
/**
|
|
128
181
|
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
129
|
-
*
|
|
130
|
-
* @
|
|
131
|
-
* @
|
|
182
|
+
* @param {Date} date - The date to compare against
|
|
183
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const builder = univerAPI.newDataValidation();
|
|
187
|
+
* const rule = builder.requireDateOnOrAfter(new Date('2024-01-01')).build();
|
|
188
|
+
* ```
|
|
132
189
|
*/
|
|
133
|
-
requireDateOnOrAfter(
|
|
134
|
-
return this._rule.type =
|
|
190
|
+
requireDateOnOrAfter(date) {
|
|
191
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = date.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.GREATER_THAN_OR_EQUAL, this;
|
|
135
192
|
}
|
|
136
193
|
/**
|
|
137
194
|
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
138
|
-
*
|
|
139
|
-
* @
|
|
140
|
-
* @
|
|
195
|
+
* @param {Date} date - The date to compare against
|
|
196
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const builder = univerAPI.newDataValidation();
|
|
200
|
+
* const rule = builder.requireDateOnOrBefore(new Date('2024-12-31')).build();
|
|
201
|
+
* ```
|
|
141
202
|
*/
|
|
142
|
-
requireDateOnOrBefore(
|
|
143
|
-
return this._rule.type =
|
|
203
|
+
requireDateOnOrBefore(date) {
|
|
204
|
+
return this._rule.type = DataValidationType.DATE, this._rule.formula1 = date.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.LESS_THAN_OR_EQUAL, this;
|
|
144
205
|
}
|
|
145
206
|
/**
|
|
146
|
-
* Requires that a custom formula be satisfied
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
150
|
-
*
|
|
207
|
+
* Requires that a custom formula be satisfied
|
|
208
|
+
* @param {string} formula - The formula string that needs to be satisfied
|
|
209
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const builder = univerAPI.newDataValidation();
|
|
213
|
+
* const rule = builder.requireFormulaSatisfied('=A1>0').build();
|
|
214
|
+
* ```
|
|
151
215
|
*/
|
|
152
|
-
requireFormulaSatisfied(
|
|
153
|
-
return this._rule.type =
|
|
216
|
+
requireFormulaSatisfied(formula) {
|
|
217
|
+
return this._rule.type = DataValidationType.CUSTOM, this._rule.formula1 = formula, this._rule.formula2 = void 0, this;
|
|
154
218
|
}
|
|
155
219
|
/**
|
|
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
|
-
*
|
|
220
|
+
* Requires the user to enter a number within a specific range, which can be integer or decimal
|
|
221
|
+
* @param {number} start - The starting value of the number range
|
|
222
|
+
* @param {number} end - The ending value of the number range
|
|
223
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
224
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const builder = univerAPI.newDataValidation();
|
|
228
|
+
* const rule = builder.requireNumberBetween(1, 10).build();
|
|
229
|
+
* ```
|
|
163
230
|
*/
|
|
164
|
-
requireNumberBetween(
|
|
165
|
-
return this._rule.formula1 = `${
|
|
231
|
+
requireNumberBetween(start, end, isInteger) {
|
|
232
|
+
return this._rule.formula1 = `${start}`, this._rule.formula2 = `${end}`, this._rule.operator = DataValidationOperator.BETWEEN, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
166
233
|
}
|
|
167
234
|
/**
|
|
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
|
-
*
|
|
235
|
+
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
|
|
236
|
+
* @param {number} num - The number to which the entered number should be equal
|
|
237
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
238
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const builder = univerAPI.newDataValidation();
|
|
242
|
+
* const rule = builder.requireNumberEqualTo(10).build();
|
|
243
|
+
* ```
|
|
174
244
|
*/
|
|
175
|
-
requireNumberEqualTo(
|
|
176
|
-
return this._rule.formula1 = `${
|
|
245
|
+
requireNumberEqualTo(num, isInteger) {
|
|
246
|
+
return this._rule.formula1 = `${num}`, this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.EQUAL, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
177
247
|
}
|
|
178
248
|
/**
|
|
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
|
-
*
|
|
249
|
+
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
|
|
250
|
+
* @param {number} num - The number to which the entered number should be greater
|
|
251
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
252
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const builder = univerAPI.newDataValidation();
|
|
256
|
+
* const rule = builder.requireNumberGreaterThan(10).build();
|
|
257
|
+
* ```
|
|
185
258
|
*/
|
|
186
|
-
requireNumberGreaterThan(
|
|
187
|
-
return this._rule.formula1 = `${
|
|
259
|
+
requireNumberGreaterThan(num, isInteger) {
|
|
260
|
+
return this._rule.formula1 = `${num}`, this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.GREATER_THAN, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
188
261
|
}
|
|
189
262
|
/**
|
|
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
|
-
*
|
|
263
|
+
* 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
|
|
264
|
+
* @param {number} num - The number to which the entered number should be greater than or equal
|
|
265
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
266
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const builder = univerAPI.newDataValidation();
|
|
270
|
+
* const rule = builder.requireNumberGreaterThanOrEqualTo(10).build();
|
|
271
|
+
* ```
|
|
196
272
|
*/
|
|
197
|
-
requireNumberGreaterThanOrEqualTo(
|
|
198
|
-
return this._rule.formula1 = `${
|
|
273
|
+
requireNumberGreaterThanOrEqualTo(num, isInteger) {
|
|
274
|
+
return this._rule.formula1 = `${num}`, this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.GREATER_THAN_OR_EQUAL, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
199
275
|
}
|
|
200
276
|
/**
|
|
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
|
-
*
|
|
277
|
+
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
|
|
278
|
+
* @param {number} num - The number to which the entered number should be less
|
|
279
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
280
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const builder = univerAPI.newDataValidation();
|
|
284
|
+
* const rule = builder.requireNumberLessThan(10).build();
|
|
285
|
+
* ```
|
|
207
286
|
*/
|
|
208
|
-
requireNumberLessThan(
|
|
209
|
-
return this._rule.formula1 = `${
|
|
287
|
+
requireNumberLessThan(num, isInteger) {
|
|
288
|
+
return this._rule.formula1 = `${num}`, this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.LESS_THAN, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
210
289
|
}
|
|
211
290
|
/**
|
|
212
291
|
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
213
292
|
* The specified value can be an integer or a decimal
|
|
214
|
-
*
|
|
215
|
-
* @param
|
|
216
|
-
* @
|
|
217
|
-
* @
|
|
293
|
+
* @param {number} num - The number to which the entered number should be less than or equal
|
|
294
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
295
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const builder = univerAPI.newDataValidation();
|
|
299
|
+
* const rule = builder.requireNumberLessThanOrEqualTo(10).build();
|
|
300
|
+
* ```
|
|
218
301
|
*/
|
|
219
|
-
requireNumberLessThanOrEqualTo(
|
|
220
|
-
return this._rule.formula1 = `${
|
|
302
|
+
requireNumberLessThanOrEqualTo(num, isInteger) {
|
|
303
|
+
return this._rule.formula1 = `${num}`, this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.LESS_THAN_OR_EQUAL, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
221
304
|
}
|
|
222
305
|
/**
|
|
223
306
|
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
224
307
|
* The specified range includes all integers and decimals
|
|
225
|
-
*
|
|
226
|
-
* @param
|
|
227
|
-
* @param
|
|
228
|
-
* @
|
|
229
|
-
* @
|
|
308
|
+
* @param {number} start - The starting point of the specified range
|
|
309
|
+
* @param {number} end - The end point of the specified range
|
|
310
|
+
* @param {boolean} [isInteger] - Optional parameter, indicating whether the number to be verified is an integer
|
|
311
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* const builder = univerAPI.newDataValidation();
|
|
315
|
+
* const rule = builder.requireNumberNotBetween(1, 10).build();
|
|
316
|
+
* ```
|
|
230
317
|
*/
|
|
231
|
-
requireNumberNotBetween(
|
|
232
|
-
return this._rule.formula1 = `${
|
|
318
|
+
requireNumberNotBetween(start, end, isInteger) {
|
|
319
|
+
return this._rule.formula1 = `${start}`, this._rule.formula2 = `${end}`, this._rule.operator = DataValidationOperator.NOT_BETWEEN, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
233
320
|
}
|
|
234
321
|
/**
|
|
235
322
|
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
236
323
|
* The specific value can be an integer or a decimal
|
|
237
|
-
*
|
|
238
|
-
* @param
|
|
239
|
-
* @
|
|
240
|
-
* @
|
|
324
|
+
* @param {number} num - The number to which the entered number should not be equal
|
|
325
|
+
* @param {boolean} [isInteger] - Indicates whether the required number is an integer
|
|
326
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const builder = univerAPI.newDataValidation();
|
|
330
|
+
* const rule = builder.requireNumberNotEqualTo(10).build();
|
|
331
|
+
* ```
|
|
241
332
|
*/
|
|
242
|
-
requireNumberNotEqualTo(
|
|
243
|
-
return this._rule.formula1 = `${
|
|
333
|
+
requireNumberNotEqualTo(num, isInteger) {
|
|
334
|
+
return this._rule.formula1 = `${num}`, this._rule.formula2 = void 0, this._rule.operator = DataValidationOperator.NOT_EQUAL, this._rule.type = isInteger ? DataValidationType.WHOLE : DataValidationType.DECIMAL, this;
|
|
244
335
|
}
|
|
245
336
|
/**
|
|
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
|
-
* @
|
|
337
|
+
* Sets a data validation rule that requires the user to enter a value from a list of specific values
|
|
338
|
+
* The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
|
|
339
|
+
* @param {string[]} values - An array containing the specific values that the user can enter
|
|
340
|
+
* @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
|
|
341
|
+
* @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
|
|
342
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* const builder = univerAPI.newDataValidation();
|
|
346
|
+
* const rule = builder.requireValueInList(['Yes', 'No']).build();
|
|
347
|
+
* ```
|
|
253
348
|
*/
|
|
254
|
-
requireValueInList(
|
|
255
|
-
return this._rule.type =
|
|
349
|
+
requireValueInList(values, multiple, showDropdown) {
|
|
350
|
+
return this._rule.type = multiple ? DataValidationType.LIST_MULTIPLE : DataValidationType.LIST, this._rule.formula1 = values.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = showDropdown != null ? showDropdown : !0, this;
|
|
256
351
|
}
|
|
257
352
|
/**
|
|
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
|
-
* @
|
|
353
|
+
* Sets a data validation rule that requires the user to enter a value within a specific range
|
|
354
|
+
* The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
|
|
355
|
+
* @param {FRange} range - An FRange object representing the range of values that the user can enter
|
|
356
|
+
* @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
|
|
357
|
+
* @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
|
|
358
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const builder = univerAPI.newDataValidation();
|
|
362
|
+
* const range = FRange.create('Sheet1', 'B1:B10');
|
|
363
|
+
* const rule = builder.requireValueInRange(range).build();
|
|
364
|
+
* ```
|
|
265
365
|
*/
|
|
266
|
-
requireValueInRange(
|
|
267
|
-
return this._rule.type =
|
|
268
|
-
unitId:
|
|
269
|
-
sheetName:
|
|
270
|
-
range:
|
|
271
|
-
})}`, this._rule.formula2 = void 0, this._rule.showDropDown =
|
|
366
|
+
requireValueInRange(range, multiple, showDropdown) {
|
|
367
|
+
return this._rule.type = multiple ? DataValidationType.LIST_MULTIPLE : DataValidationType.LIST, this._rule.formula1 = `=${serializeRangeToRefString({
|
|
368
|
+
unitId: range.getUnitId(),
|
|
369
|
+
sheetName: range.getSheetName(),
|
|
370
|
+
range: range.getRange()
|
|
371
|
+
})}`, this._rule.formula2 = void 0, this._rule.showDropDown = showDropdown != null ? showDropdown : !0, this;
|
|
272
372
|
}
|
|
273
373
|
/**
|
|
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
|
-
* @
|
|
374
|
+
* Sets whether to allow invalid data and configures the error style
|
|
375
|
+
* If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error
|
|
376
|
+
* 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
|
|
377
|
+
* @param {boolean} allowInvalidData - Whether to allow invalid data
|
|
378
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const builder = univerAPI.newDataValidation();
|
|
382
|
+
* const rule = builder.setAllowInvalid(true).build();
|
|
383
|
+
* ```
|
|
280
384
|
*/
|
|
281
|
-
setAllowInvalid(
|
|
282
|
-
return this._rule.errorStyle =
|
|
385
|
+
setAllowInvalid(allowInvalidData) {
|
|
386
|
+
return this._rule.errorStyle = allowInvalidData ? DataValidationErrorStyle.WARNING : DataValidationErrorStyle.STOP, this;
|
|
283
387
|
}
|
|
284
388
|
/**
|
|
285
|
-
* Sets
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @
|
|
289
|
-
*
|
|
389
|
+
* Sets whether to allow blank values
|
|
390
|
+
* @param {boolean} allowBlank - Whether to allow blank values
|
|
391
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* const builder = univerAPI.newDataValidation();
|
|
395
|
+
* const rule = builder.setAllowBlank(true).build();
|
|
396
|
+
* ```
|
|
290
397
|
*/
|
|
291
|
-
|
|
292
|
-
return this._rule.
|
|
398
|
+
setAllowBlank(allowBlank) {
|
|
399
|
+
return this._rule.allowBlank = allowBlank, this;
|
|
293
400
|
}
|
|
294
401
|
/**
|
|
295
|
-
* Sets the
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* @
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
402
|
+
* Sets the options for the data validation rule
|
|
403
|
+
* @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
|
|
404
|
+
* @returns {FDataValidationBuilder} The current instance for method chaining
|
|
405
|
+
* @example
|
|
406
|
+
* ```typescript
|
|
407
|
+
* const builder = univerAPI.newDataValidation();
|
|
408
|
+
* const rule = builder.setOptions({
|
|
409
|
+
* allowBlank: true,
|
|
410
|
+
* showErrorMessage: true,
|
|
411
|
+
* error: 'Please enter a valid value'
|
|
412
|
+
* }).build();
|
|
413
|
+
* ```
|
|
303
414
|
*/
|
|
304
|
-
|
|
305
|
-
return
|
|
415
|
+
setOptions(options) {
|
|
416
|
+
return Object.assign(this._rule, options), this;
|
|
306
417
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
*/
|
|
317
|
-
setOptions(e) {
|
|
318
|
-
return Object.assign(this._rule, e), this;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
class m {
|
|
322
|
-
constructor(e, t, r) {
|
|
323
|
-
f(this, "rule");
|
|
324
|
-
f(this, "_worksheet");
|
|
325
|
-
f(this, "_injector");
|
|
326
|
-
this._injector = r, this.rule = e, this._worksheet = t;
|
|
418
|
+
};
|
|
419
|
+
__name(_FDataValidationBuilder, "FDataValidationBuilder");
|
|
420
|
+
let FDataValidationBuilder = _FDataValidationBuilder;
|
|
421
|
+
const _FDataValidation = class _FDataValidation {
|
|
422
|
+
constructor(rule, worksheet, _injector) {
|
|
423
|
+
__publicField(this, "rule");
|
|
424
|
+
__publicField(this, "_worksheet");
|
|
425
|
+
__publicField(this, "_injector");
|
|
426
|
+
this._injector = _injector, this.rule = rule, this._worksheet = worksheet;
|
|
327
427
|
}
|
|
328
428
|
/**
|
|
329
|
-
* Gets whether invalid data is allowed based on the error style value
|
|
330
|
-
*
|
|
331
|
-
* @
|
|
429
|
+
* Gets whether invalid data is allowed based on the error style value
|
|
430
|
+
* @returns {boolean} true if invalid data is allowed, false otherwise
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* const dataValidation = univerAPI
|
|
434
|
+
* .getActiveWorkbook()
|
|
435
|
+
* .getActiveWorksheet()
|
|
436
|
+
* .getActiveRange()
|
|
437
|
+
* .getDataValidation();
|
|
438
|
+
* const allowsInvalid = dataValidation.getAllowInvalid();
|
|
439
|
+
* ```
|
|
332
440
|
*/
|
|
333
441
|
getAllowInvalid() {
|
|
334
|
-
return this.rule.errorStyle !==
|
|
442
|
+
return this.rule.errorStyle !== DataValidationErrorStyle.STOP;
|
|
335
443
|
}
|
|
336
444
|
/**
|
|
337
445
|
* Gets the data validation type of the rule
|
|
338
|
-
*
|
|
339
|
-
* @
|
|
446
|
+
* @returns {DataValidationType | string} The data validation type
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* const dataValidation = univerAPI
|
|
450
|
+
* .getActiveWorkbook()
|
|
451
|
+
* .getActiveWorksheet()
|
|
452
|
+
* .getActiveRange()
|
|
453
|
+
* .getDataValidation();
|
|
454
|
+
* const type = dataValidation.getCriteriaType();
|
|
455
|
+
* ```
|
|
340
456
|
*/
|
|
341
457
|
getCriteriaType() {
|
|
342
458
|
return this.rule.type;
|
|
343
459
|
}
|
|
344
460
|
/**
|
|
345
461
|
* Gets the values used for criteria evaluation
|
|
346
|
-
*
|
|
347
|
-
* @
|
|
462
|
+
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
463
|
+
* @example
|
|
464
|
+
* ```typescript
|
|
465
|
+
* const dataValidation = univerAPI
|
|
466
|
+
* .getActiveWorkbook()
|
|
467
|
+
* .getActiveWorksheet()
|
|
468
|
+
* .getActiveRange()
|
|
469
|
+
* .getDataValidation();
|
|
470
|
+
* const [operator, formula1, formula2] = dataValidation.getCriteriaValues();
|
|
471
|
+
* ```
|
|
348
472
|
*/
|
|
349
473
|
getCriteriaValues() {
|
|
350
474
|
return [this.rule.operator, this.rule.formula1, this.rule.formula2];
|
|
351
475
|
}
|
|
352
476
|
/**
|
|
353
477
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
354
|
-
*
|
|
355
|
-
* @
|
|
478
|
+
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* const dataValidation = univerAPI
|
|
482
|
+
* .getActiveWorkbook()
|
|
483
|
+
* .getActiveWorksheet()
|
|
484
|
+
* .getActiveRange()
|
|
485
|
+
* .getDataValidation();
|
|
486
|
+
* const helpText = dataValidation.getHelpText();
|
|
487
|
+
* ```
|
|
356
488
|
*/
|
|
357
489
|
getHelpText() {
|
|
358
490
|
return this.rule.error;
|
|
359
491
|
}
|
|
360
492
|
/**
|
|
361
|
-
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
493
|
+
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
494
|
+
* @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* const dataValidation = univerAPI
|
|
498
|
+
* .getActiveWorkbook()
|
|
499
|
+
* .getActiveWorksheet()
|
|
500
|
+
* .getActiveRange()
|
|
501
|
+
* .getDataValidation();
|
|
502
|
+
* const builder = dataValidation.copy();
|
|
503
|
+
* const newRule = builder.setAllowInvalid(true).build();
|
|
504
|
+
* ```
|
|
365
505
|
*/
|
|
366
506
|
copy() {
|
|
367
|
-
return new
|
|
507
|
+
return new FDataValidationBuilder(this.rule);
|
|
368
508
|
}
|
|
369
509
|
/**
|
|
370
|
-
* Gets whether the data validation rule is applied to the worksheet
|
|
371
|
-
*
|
|
372
|
-
* @
|
|
510
|
+
* Gets whether the data validation rule is applied to the worksheet
|
|
511
|
+
* @returns {boolean} true if the rule is applied, false otherwise
|
|
512
|
+
* @example
|
|
513
|
+
* ```typescript
|
|
514
|
+
* const dataValidation = univerAPI
|
|
515
|
+
* .getActiveWorkbook()
|
|
516
|
+
* .getActiveWorksheet()
|
|
517
|
+
* .getActiveRange()
|
|
518
|
+
* .getDataValidation();
|
|
519
|
+
* const isApplied = dataValidation.getApplied();
|
|
520
|
+
* ```
|
|
373
521
|
*/
|
|
374
522
|
getApplied() {
|
|
375
523
|
if (!this._worksheet)
|
|
376
524
|
return !1;
|
|
377
|
-
const
|
|
378
|
-
return !!(
|
|
525
|
+
const currentRule = this._injector.get(DataValidationModel).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
|
|
526
|
+
return !!(currentRule && currentRule.ranges.length);
|
|
379
527
|
}
|
|
380
528
|
/**
|
|
381
|
-
* Gets the ranges to which the data validation rule is applied
|
|
382
|
-
*
|
|
383
|
-
* @
|
|
529
|
+
* Gets the ranges to which the data validation rule is applied
|
|
530
|
+
* @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
|
|
531
|
+
* @example
|
|
532
|
+
* ```typescript
|
|
533
|
+
* const dataValidation = univerAPI
|
|
534
|
+
* .getActiveWorkbook()
|
|
535
|
+
* .getActiveWorksheet()
|
|
536
|
+
* .getActiveRange()
|
|
537
|
+
* .getDataValidation();
|
|
538
|
+
* const ranges = dataValidation.getRanges();
|
|
539
|
+
* ```
|
|
384
540
|
*/
|
|
385
541
|
getRanges() {
|
|
386
542
|
if (!this.getApplied())
|
|
387
543
|
return [];
|
|
388
|
-
const
|
|
389
|
-
return this.rule.ranges.map((
|
|
544
|
+
const workbook = this._injector.get(IUniverInstanceService).getUnit(this._worksheet.getUnitId());
|
|
545
|
+
return this.rule.ranges.map((range) => this._injector.createInstance(FRange, workbook, this._worksheet, range));
|
|
390
546
|
}
|
|
391
547
|
/**
|
|
392
|
-
* Gets the
|
|
393
|
-
*
|
|
394
|
-
* @
|
|
548
|
+
* Gets the unit ID of the worksheet
|
|
549
|
+
* @returns {string | undefined} The unit ID of the worksheet
|
|
550
|
+
* @example
|
|
551
|
+
* ```typescript
|
|
552
|
+
* const dataValidation = univerAPI
|
|
553
|
+
* .getActiveWorkbook()
|
|
554
|
+
* .getActiveWorksheet()
|
|
555
|
+
* .getActiveRange()
|
|
556
|
+
* .getDataValidation();
|
|
557
|
+
* const unitId = dataValidation.getUnitId();
|
|
558
|
+
* ```
|
|
395
559
|
*/
|
|
396
560
|
getUnitId() {
|
|
397
|
-
var
|
|
398
|
-
return (
|
|
561
|
+
var _a;
|
|
562
|
+
return (_a = this._worksheet) == null ? void 0 : _a.getUnitId();
|
|
399
563
|
}
|
|
400
564
|
/**
|
|
401
|
-
* Gets the
|
|
402
|
-
*
|
|
403
|
-
* @
|
|
565
|
+
* Gets the sheet ID of the worksheet
|
|
566
|
+
* @returns {string | undefined} The sheet ID of the worksheet
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* const dataValidation = univerAPI
|
|
570
|
+
* .getActiveWorkbook()
|
|
571
|
+
* .getActiveWorksheet()
|
|
572
|
+
* .getActiveRange()
|
|
573
|
+
* .getDataValidation();
|
|
574
|
+
* const sheetId = dataValidation.getSheetId();
|
|
575
|
+
* ```
|
|
404
576
|
*/
|
|
405
577
|
getSheetId() {
|
|
406
|
-
var
|
|
407
|
-
return (
|
|
578
|
+
var _a;
|
|
579
|
+
return (_a = this._worksheet) == null ? void 0 : _a.getSheetId();
|
|
408
580
|
}
|
|
409
581
|
/**
|
|
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
|
-
* @
|
|
582
|
+
* Set Criteria for the data validation rule
|
|
583
|
+
* @param {DataValidationType} type - The type of data validation criteria
|
|
584
|
+
* @param {[DataValidationOperator, string, string]} values - An array containing the operator, formula1, and formula2 values
|
|
585
|
+
* @param {boolean} [allowBlank] - Whether to allow blank values
|
|
586
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
587
|
+
* @example
|
|
588
|
+
* ```typescript
|
|
589
|
+
* const dataValidation = univerAPI
|
|
590
|
+
* .getActiveWorkbook()
|
|
591
|
+
* .getActiveWorksheet()
|
|
592
|
+
* .getActiveRange()
|
|
593
|
+
* .getDataValidation();
|
|
594
|
+
* dataValidation.setCriteria(
|
|
595
|
+
* DataValidationType.DECIMAL,
|
|
596
|
+
* [DataValidationOperator.BETWEEN, '1', '10'],
|
|
597
|
+
* true
|
|
598
|
+
* );
|
|
599
|
+
* ```
|
|
414
600
|
*/
|
|
415
|
-
setCriteria(
|
|
416
|
-
if (this.getApplied() && !this._injector.get(
|
|
601
|
+
setCriteria(type, values, allowBlank = !0) {
|
|
602
|
+
if (this.getApplied() && !this._injector.get(ICommandService).syncExecuteCommand(UpdateSheetDataValidationSettingCommand.id, {
|
|
417
603
|
unitId: this.getUnitId(),
|
|
418
604
|
subUnitId: this.getSheetId(),
|
|
419
605
|
ruleId: this.rule.uid,
|
|
420
606
|
setting: {
|
|
421
|
-
operator:
|
|
422
|
-
formula1:
|
|
423
|
-
formula2:
|
|
607
|
+
operator: values[0],
|
|
608
|
+
formula1: values[1],
|
|
609
|
+
formula2: values[2],
|
|
424
610
|
type: this.rule.type,
|
|
425
|
-
allowBlank
|
|
611
|
+
allowBlank
|
|
426
612
|
}
|
|
427
613
|
}))
|
|
428
614
|
throw new Error("setCriteria failed");
|
|
429
|
-
return this.rule.operator =
|
|
615
|
+
return this.rule.operator = values[0], this.rule.formula1 = values[1], this.rule.formula2 = values[2], this.rule.type = type, this.rule.allowBlank = allowBlank, this;
|
|
430
616
|
}
|
|
431
617
|
/**
|
|
432
|
-
* Set the options for the data validation rule
|
|
433
|
-
*
|
|
434
|
-
* @
|
|
435
|
-
* @
|
|
618
|
+
* Set the options for the data validation rule
|
|
619
|
+
* @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
|
|
620
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* const dataValidation = univerAPI
|
|
624
|
+
* .getActiveWorkbook()
|
|
625
|
+
* .getActiveWorksheet()
|
|
626
|
+
* .getActiveRange()
|
|
627
|
+
* .getDataValidation();
|
|
628
|
+
* dataValidation.setOptions({
|
|
629
|
+
* allowBlank: true,
|
|
630
|
+
* showErrorMessage: true,
|
|
631
|
+
* error: 'Please enter a valid value'
|
|
632
|
+
* });
|
|
633
|
+
* ```
|
|
436
634
|
*/
|
|
437
|
-
setOptions(
|
|
438
|
-
if (this.getApplied() && !this._injector.get(
|
|
635
|
+
setOptions(options) {
|
|
636
|
+
if (this.getApplied() && !this._injector.get(ICommandService).syncExecuteCommand(UpdateSheetDataValidationOptionsCommand.id, {
|
|
439
637
|
unitId: this.getUnitId(),
|
|
440
638
|
subUnitId: this.getSheetId(),
|
|
441
639
|
ruleId: this.rule.uid,
|
|
442
640
|
options: {
|
|
443
|
-
...
|
|
444
|
-
...
|
|
641
|
+
...getRuleOptions(this.rule),
|
|
642
|
+
...options
|
|
445
643
|
}
|
|
446
644
|
}))
|
|
447
645
|
throw new Error("setOptions failed");
|
|
448
|
-
return Object.assign(this.rule,
|
|
646
|
+
return Object.assign(this.rule, options), this;
|
|
449
647
|
}
|
|
450
648
|
/**
|
|
451
|
-
* Set the ranges to the data validation rule
|
|
452
|
-
* @param ranges
|
|
453
|
-
* @returns
|
|
649
|
+
* Set the ranges to the data validation rule
|
|
650
|
+
* @param {FRange[]} ranges - New ranges array
|
|
651
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
652
|
+
* @example
|
|
653
|
+
* ```typescript
|
|
654
|
+
* const dataValidation = univerAPI
|
|
655
|
+
* .getActiveWorkbook()
|
|
656
|
+
* .getActiveWorksheet()
|
|
657
|
+
* .getActiveRange()
|
|
658
|
+
* .getDataValidation();
|
|
659
|
+
* const range = FRange.create('Sheet1', 'A1:B10');
|
|
660
|
+
* dataValidation.setRanges([range]);
|
|
661
|
+
* ```
|
|
454
662
|
*/
|
|
455
|
-
setRanges(
|
|
456
|
-
if (this.getApplied() && !this._injector.get(
|
|
663
|
+
setRanges(ranges) {
|
|
664
|
+
if (this.getApplied() && !this._injector.get(ICommandService).syncExecuteCommand(UpdateSheetDataValidationRangeCommand.id, {
|
|
457
665
|
unitId: this.getUnitId(),
|
|
458
666
|
subUnitId: this.getSheetId(),
|
|
459
667
|
ruleId: this.rule.uid,
|
|
460
|
-
ranges:
|
|
668
|
+
ranges: ranges.map((range) => range.getRange())
|
|
461
669
|
}))
|
|
462
670
|
throw new Error("setRanges failed");
|
|
463
|
-
return this.rule.ranges =
|
|
671
|
+
return this.rule.ranges = ranges.map((range) => range.getRange()), this;
|
|
464
672
|
}
|
|
465
673
|
/**
|
|
466
|
-
* Delete the data validation rule from the worksheet
|
|
467
|
-
* @returns true if the rule is deleted successfully, false otherwise
|
|
674
|
+
* Delete the data validation rule from the worksheet
|
|
675
|
+
* @returns {boolean} true if the rule is deleted successfully, false otherwise
|
|
676
|
+
* @example
|
|
677
|
+
* ```typescript
|
|
678
|
+
* const dataValidation = univerAPI
|
|
679
|
+
* .getActiveWorkbook()
|
|
680
|
+
* .getActiveWorksheet()
|
|
681
|
+
* .getActiveRange()
|
|
682
|
+
* .getDataValidation();
|
|
683
|
+
* const isDeleted = dataValidation.delete();
|
|
684
|
+
* ```
|
|
468
685
|
*/
|
|
469
686
|
delete() {
|
|
470
|
-
return this.getApplied() ? this._injector.get(
|
|
687
|
+
return this.getApplied() ? this._injector.get(ICommandService).syncExecuteCommand(RemoveSheetDataValidationCommand.id, {
|
|
471
688
|
unitId: this.getUnitId(),
|
|
472
689
|
subUnitId: this.getSheetId(),
|
|
473
690
|
ruleId: this.rule.uid
|
|
474
691
|
}) : !1;
|
|
475
692
|
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
693
|
+
};
|
|
694
|
+
__name(_FDataValidation, "FDataValidation");
|
|
695
|
+
let FDataValidation = _FDataValidation;
|
|
696
|
+
const _FRangeDataValidationMixin = class _FRangeDataValidationMixin extends FRange {
|
|
697
|
+
setDataValidation(rule) {
|
|
698
|
+
if (!rule)
|
|
699
|
+
return this._commandService.syncExecuteCommand(ClearRangeDataValidationCommand.id, {
|
|
481
700
|
unitId: this._workbook.getUnitId(),
|
|
482
701
|
subUnitId: this._worksheet.getSheetId(),
|
|
483
702
|
ranges: [this._range]
|
|
484
703
|
}), this;
|
|
485
|
-
const
|
|
704
|
+
const params = {
|
|
486
705
|
unitId: this._workbook.getUnitId(),
|
|
487
706
|
subUnitId: this._worksheet.getSheetId(),
|
|
488
707
|
rule: {
|
|
489
|
-
...
|
|
708
|
+
...rule.rule,
|
|
490
709
|
ranges: [this._range]
|
|
491
710
|
}
|
|
492
711
|
};
|
|
493
|
-
return this._commandService.syncExecuteCommand(
|
|
712
|
+
return this._commandService.syncExecuteCommand(AddSheetDataValidationCommand.id, params), this;
|
|
494
713
|
}
|
|
495
714
|
getDataValidation() {
|
|
496
|
-
const
|
|
715
|
+
const rule = this._injector.get(SheetsDataValidationValidatorService).getDataValidation(
|
|
497
716
|
this._workbook.getUnitId(),
|
|
498
717
|
this._worksheet.getSheetId(),
|
|
499
718
|
[this._range]
|
|
500
719
|
);
|
|
501
|
-
return
|
|
720
|
+
return rule && new FDataValidation(rule, this._worksheet, this._injector);
|
|
502
721
|
}
|
|
503
722
|
getDataValidations() {
|
|
504
|
-
return this._injector.get(
|
|
723
|
+
return this._injector.get(SheetsDataValidationValidatorService).getDataValidations(
|
|
505
724
|
this._workbook.getUnitId(),
|
|
506
725
|
this._worksheet.getSheetId(),
|
|
507
726
|
[this._range]
|
|
508
|
-
).map((
|
|
727
|
+
).map((rule) => new FDataValidation(rule, this._worksheet, this._injector));
|
|
509
728
|
}
|
|
510
729
|
async getValidatorStatus() {
|
|
511
|
-
return this._injector.get(
|
|
730
|
+
return this._injector.get(SheetsDataValidationValidatorService).validatorRanges(
|
|
512
731
|
this._workbook.getUnitId(),
|
|
513
732
|
this._worksheet.getSheetId(),
|
|
514
733
|
[this._range]
|
|
515
734
|
);
|
|
516
735
|
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
736
|
+
};
|
|
737
|
+
__name(_FRangeDataValidationMixin, "FRangeDataValidationMixin");
|
|
738
|
+
let FRangeDataValidationMixin = _FRangeDataValidationMixin;
|
|
739
|
+
FRange.extend(FRangeDataValidationMixin);
|
|
740
|
+
const _FUnvierDataValidationMixin = class _FUnvierDataValidationMixin extends FUniver {
|
|
741
|
+
// eslint-disable-next-line jsdoc/require-returns
|
|
520
742
|
/**
|
|
521
743
|
/**
|
|
522
|
-
* @
|
|
744
|
+
* @deprecated use `univerAPI.newDataValidation()` as instead.
|
|
523
745
|
*/
|
|
524
746
|
static newDataValidation() {
|
|
525
|
-
return new
|
|
747
|
+
return new FDataValidationBuilder();
|
|
526
748
|
}
|
|
749
|
+
/**
|
|
750
|
+
* Creates a new instance of FDataValidationBuilder
|
|
751
|
+
* @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
|
|
752
|
+
* @example
|
|
753
|
+
* ```ts
|
|
754
|
+
* const rule = FUnvier.newDataValidation();
|
|
755
|
+
* cell.setDataValidation(rule.requireValueInRange(range));
|
|
756
|
+
* ```
|
|
757
|
+
*/
|
|
527
758
|
newDataValidation() {
|
|
528
|
-
return new
|
|
759
|
+
return new FDataValidationBuilder();
|
|
529
760
|
}
|
|
761
|
+
/**
|
|
762
|
+
* @ignore
|
|
763
|
+
*/
|
|
530
764
|
// eslint-disable-next-line max-lines-per-function
|
|
531
|
-
_initialize(
|
|
532
|
-
if (!
|
|
533
|
-
const
|
|
534
|
-
this.disposeWithMe(
|
|
535
|
-
const { unitId
|
|
536
|
-
if (!
|
|
765
|
+
_initialize(injector) {
|
|
766
|
+
if (!injector.has(SheetDataValidationModel)) return;
|
|
767
|
+
const sheetDataValidationModel = injector.get(SheetDataValidationModel), commadnService = injector.get(ICommandService);
|
|
768
|
+
this.disposeWithMe(sheetDataValidationModel.ruleChange$.subscribe((ruleChange) => {
|
|
769
|
+
const { unitId, subUnitId, rule, oldRule, type } = ruleChange, target = this.getSheetTarget(unitId, subUnitId);
|
|
770
|
+
if (!target)
|
|
537
771
|
return;
|
|
538
|
-
const { workbook
|
|
772
|
+
const { workbook, worksheet } = target, fRule = new FDataValidation(rule, worksheet.getSheet(), this._injector);
|
|
539
773
|
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
540
|
-
origin:
|
|
541
|
-
worksheet
|
|
542
|
-
workbook
|
|
543
|
-
changeType:
|
|
544
|
-
oldRule
|
|
545
|
-
rule:
|
|
774
|
+
origin: ruleChange,
|
|
775
|
+
worksheet,
|
|
776
|
+
workbook,
|
|
777
|
+
changeType: type,
|
|
778
|
+
oldRule,
|
|
779
|
+
rule: fRule
|
|
546
780
|
});
|
|
547
|
-
})), this.disposeWithMe(
|
|
548
|
-
const { unitId
|
|
549
|
-
if (!
|
|
781
|
+
})), this.disposeWithMe(sheetDataValidationModel.validStatusChange$.subscribe((statusChange) => {
|
|
782
|
+
const { unitId, subUnitId, ruleId, status, row, col } = statusChange, target = this.getSheetTarget(unitId, subUnitId);
|
|
783
|
+
if (!target)
|
|
550
784
|
return;
|
|
551
|
-
const { workbook
|
|
552
|
-
|
|
553
|
-
workbook
|
|
554
|
-
worksheet
|
|
555
|
-
row
|
|
556
|
-
column:
|
|
557
|
-
rule
|
|
558
|
-
status
|
|
785
|
+
const { workbook, worksheet } = target, rule = worksheet.getDataValidation(ruleId);
|
|
786
|
+
rule && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
|
|
787
|
+
workbook,
|
|
788
|
+
worksheet,
|
|
789
|
+
row,
|
|
790
|
+
column: col,
|
|
791
|
+
rule,
|
|
792
|
+
status
|
|
559
793
|
});
|
|
560
|
-
})), this.disposeWithMe(
|
|
561
|
-
switch (
|
|
562
|
-
case
|
|
563
|
-
const
|
|
564
|
-
if (!
|
|
794
|
+
})), this.disposeWithMe(commadnService.beforeCommandExecuted((commandInfo) => {
|
|
795
|
+
switch (commandInfo.id) {
|
|
796
|
+
case AddSheetDataValidationCommand.id: {
|
|
797
|
+
const params = commandInfo.params, target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
798
|
+
if (!target)
|
|
565
799
|
return;
|
|
566
|
-
const { workbook
|
|
567
|
-
worksheet
|
|
568
|
-
workbook
|
|
569
|
-
rule:
|
|
800
|
+
const { workbook, worksheet } = target, eventParams = {
|
|
801
|
+
worksheet,
|
|
802
|
+
workbook,
|
|
803
|
+
rule: params.rule
|
|
570
804
|
};
|
|
571
|
-
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd,
|
|
572
|
-
throw new
|
|
805
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, eventParams), eventParams.cancel)
|
|
806
|
+
throw new CanceledError();
|
|
573
807
|
break;
|
|
574
808
|
}
|
|
575
|
-
case
|
|
576
|
-
const
|
|
577
|
-
if (!
|
|
809
|
+
case UpdateSheetDataValidationSettingCommand.id: {
|
|
810
|
+
const params = commandInfo.params, target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
811
|
+
if (!target)
|
|
578
812
|
return;
|
|
579
|
-
const { workbook
|
|
580
|
-
if (!
|
|
813
|
+
const { workbook, worksheet } = target, rule = worksheet.getDataValidation(params.ruleId);
|
|
814
|
+
if (!rule)
|
|
581
815
|
return;
|
|
582
|
-
const
|
|
583
|
-
worksheet
|
|
584
|
-
workbook
|
|
585
|
-
rule
|
|
586
|
-
ruleId:
|
|
587
|
-
newCriteria:
|
|
816
|
+
const eventParams = {
|
|
817
|
+
worksheet,
|
|
818
|
+
workbook,
|
|
819
|
+
rule,
|
|
820
|
+
ruleId: params.ruleId,
|
|
821
|
+
newCriteria: params.setting
|
|
588
822
|
};
|
|
589
|
-
if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,
|
|
590
|
-
throw new
|
|
823
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, eventParams), eventParams.cancel)
|
|
824
|
+
throw new CanceledError();
|
|
591
825
|
break;
|
|
592
826
|
}
|
|
593
|
-
case
|
|
594
|
-
const
|
|
595
|
-
if (!
|
|
827
|
+
case UpdateSheetDataValidationRangeCommand.id: {
|
|
828
|
+
const params = commandInfo.params, target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
829
|
+
if (!target)
|
|
596
830
|
return;
|
|
597
|
-
const { workbook
|
|
598
|
-
if (!
|
|
831
|
+
const { workbook, worksheet } = target, rule = worksheet.getDataValidation(params.ruleId);
|
|
832
|
+
if (!rule)
|
|
599
833
|
return;
|
|
600
|
-
const
|
|
601
|
-
worksheet
|
|
602
|
-
workbook
|
|
603
|
-
rule
|
|
604
|
-
ruleId:
|
|
605
|
-
newRanges:
|
|
834
|
+
const eventParams = {
|
|
835
|
+
worksheet,
|
|
836
|
+
workbook,
|
|
837
|
+
rule,
|
|
838
|
+
ruleId: params.ruleId,
|
|
839
|
+
newRanges: params.ranges
|
|
606
840
|
};
|
|
607
|
-
if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,
|
|
608
|
-
throw new
|
|
841
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, eventParams), eventParams.cancel)
|
|
842
|
+
throw new CanceledError();
|
|
609
843
|
break;
|
|
610
844
|
}
|
|
611
|
-
case
|
|
612
|
-
const
|
|
613
|
-
if (!
|
|
845
|
+
case UpdateSheetDataValidationOptionsCommand.id: {
|
|
846
|
+
const params = commandInfo.params, target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
847
|
+
if (!target)
|
|
614
848
|
return;
|
|
615
|
-
const { workbook
|
|
616
|
-
if (!
|
|
849
|
+
const { workbook, worksheet } = target, rule = worksheet.getDataValidation(params.ruleId);
|
|
850
|
+
if (!rule)
|
|
617
851
|
return;
|
|
618
|
-
const
|
|
619
|
-
worksheet
|
|
620
|
-
workbook
|
|
621
|
-
rule
|
|
622
|
-
ruleId:
|
|
623
|
-
newOptions:
|
|
852
|
+
const eventParams = {
|
|
853
|
+
worksheet,
|
|
854
|
+
workbook,
|
|
855
|
+
rule,
|
|
856
|
+
ruleId: params.ruleId,
|
|
857
|
+
newOptions: params.options
|
|
624
858
|
};
|
|
625
|
-
if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,
|
|
626
|
-
throw new
|
|
859
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, eventParams), eventParams.cancel)
|
|
860
|
+
throw new CanceledError();
|
|
627
861
|
break;
|
|
628
862
|
}
|
|
629
|
-
case
|
|
630
|
-
const
|
|
631
|
-
if (!
|
|
863
|
+
case RemoveSheetDataValidationCommand.id: {
|
|
864
|
+
const params = commandInfo.params, target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
865
|
+
if (!target)
|
|
632
866
|
return;
|
|
633
|
-
const { workbook
|
|
634
|
-
if (!
|
|
867
|
+
const { workbook, worksheet } = target, rule = worksheet.getDataValidation(params.ruleId);
|
|
868
|
+
if (!rule)
|
|
635
869
|
return;
|
|
636
|
-
const
|
|
637
|
-
worksheet
|
|
638
|
-
workbook
|
|
639
|
-
rule
|
|
640
|
-
ruleId:
|
|
870
|
+
const eventParams = {
|
|
871
|
+
worksheet,
|
|
872
|
+
workbook,
|
|
873
|
+
rule,
|
|
874
|
+
ruleId: params.ruleId
|
|
641
875
|
};
|
|
642
|
-
if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete,
|
|
643
|
-
throw new
|
|
876
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, eventParams), eventParams.cancel)
|
|
877
|
+
throw new CanceledError();
|
|
644
878
|
break;
|
|
645
879
|
}
|
|
646
|
-
case
|
|
647
|
-
const
|
|
648
|
-
if (!
|
|
880
|
+
case RemoveSheetAllDataValidationCommand.id: {
|
|
881
|
+
const params = commandInfo.params, target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
882
|
+
if (!target)
|
|
649
883
|
return;
|
|
650
|
-
const { workbook
|
|
651
|
-
worksheet
|
|
652
|
-
workbook
|
|
653
|
-
rules:
|
|
884
|
+
const { workbook, worksheet } = target, eventParams = {
|
|
885
|
+
worksheet,
|
|
886
|
+
workbook,
|
|
887
|
+
rules: worksheet.getDataValidations()
|
|
654
888
|
};
|
|
655
|
-
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,
|
|
656
|
-
throw new
|
|
889
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, eventParams), eventParams.cancel)
|
|
890
|
+
throw new CanceledError();
|
|
657
891
|
break;
|
|
658
892
|
}
|
|
659
893
|
}
|
|
660
894
|
}));
|
|
661
895
|
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
|
|
896
|
+
};
|
|
897
|
+
__name(_FUnvierDataValidationMixin, "FUnvierDataValidationMixin");
|
|
898
|
+
let FUnvierDataValidationMixin = _FUnvierDataValidationMixin;
|
|
899
|
+
FUniver.extend(FUnvierDataValidationMixin);
|
|
900
|
+
const _FWorkbookDataValidationMixin = class _FWorkbookDataValidationMixin extends FWorkbook {
|
|
665
901
|
_initialize() {
|
|
666
902
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
667
903
|
get() {
|
|
668
|
-
return this._injector.get(
|
|
904
|
+
return this._injector.get(SheetDataValidationModel);
|
|
669
905
|
}
|
|
670
906
|
});
|
|
671
907
|
}
|
|
672
908
|
getValidatorStatus() {
|
|
673
|
-
return this._injector.get(
|
|
909
|
+
return this._injector.get(SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId());
|
|
674
910
|
}
|
|
675
911
|
// region DataValidationHooks
|
|
676
|
-
onDataValidationChange(
|
|
677
|
-
return
|
|
912
|
+
onDataValidationChange(callback) {
|
|
913
|
+
return toDisposable(this._dataValidationModel.ruleChange$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
|
|
678
914
|
}
|
|
679
|
-
onDataValidationStatusChange(
|
|
680
|
-
return
|
|
915
|
+
onDataValidationStatusChange(callback) {
|
|
916
|
+
return toDisposable(this._dataValidationModel.validStatusChange$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
|
|
681
917
|
}
|
|
682
|
-
onBeforeAddDataValidation(
|
|
683
|
-
return
|
|
684
|
-
const
|
|
685
|
-
if (
|
|
686
|
-
if (
|
|
918
|
+
onBeforeAddDataValidation(callback) {
|
|
919
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
920
|
+
const params = commandInfo.params;
|
|
921
|
+
if (commandInfo.id === AddSheetDataValidationCommand.id) {
|
|
922
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
687
923
|
return;
|
|
688
|
-
if (
|
|
924
|
+
if (callback(params, options) === !1)
|
|
689
925
|
throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
|
|
690
926
|
}
|
|
691
927
|
}));
|
|
692
928
|
}
|
|
693
|
-
onBeforeUpdateDataValidationCriteria(
|
|
694
|
-
return
|
|
695
|
-
const
|
|
696
|
-
if (
|
|
697
|
-
if (
|
|
929
|
+
onBeforeUpdateDataValidationCriteria(callback) {
|
|
930
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
931
|
+
const params = commandInfo.params;
|
|
932
|
+
if (commandInfo.id === UpdateSheetDataValidationSettingCommand.id) {
|
|
933
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
698
934
|
return;
|
|
699
|
-
if (
|
|
935
|
+
if (callback(params, options) === !1)
|
|
700
936
|
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
|
|
701
937
|
}
|
|
702
938
|
}));
|
|
703
939
|
}
|
|
704
|
-
onBeforeUpdateDataValidationRange(
|
|
705
|
-
return
|
|
706
|
-
const
|
|
707
|
-
if (
|
|
708
|
-
if (
|
|
940
|
+
onBeforeUpdateDataValidationRange(callback) {
|
|
941
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
942
|
+
const params = commandInfo.params;
|
|
943
|
+
if (commandInfo.id === UpdateSheetDataValidationRangeCommand.id) {
|
|
944
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
709
945
|
return;
|
|
710
|
-
if (
|
|
946
|
+
if (callback(params, options) === !1)
|
|
711
947
|
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
|
|
712
948
|
}
|
|
713
949
|
}));
|
|
714
950
|
}
|
|
715
|
-
onBeforeUpdateDataValidationOptions(
|
|
716
|
-
return
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
719
|
-
if (
|
|
951
|
+
onBeforeUpdateDataValidationOptions(callback) {
|
|
952
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
953
|
+
const params = commandInfo.params;
|
|
954
|
+
if (commandInfo.id === UpdateSheetDataValidationOptionsCommand.id) {
|
|
955
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
720
956
|
return;
|
|
721
|
-
if (
|
|
957
|
+
if (callback(params, options) === !1)
|
|
722
958
|
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
|
|
723
959
|
}
|
|
724
960
|
}));
|
|
725
961
|
}
|
|
726
|
-
onBeforeDeleteDataValidation(
|
|
727
|
-
return
|
|
728
|
-
const
|
|
729
|
-
if (
|
|
730
|
-
if (
|
|
962
|
+
onBeforeDeleteDataValidation(callback) {
|
|
963
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
964
|
+
const params = commandInfo.params;
|
|
965
|
+
if (commandInfo.id === RemoveSheetDataValidationCommand.id) {
|
|
966
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
731
967
|
return;
|
|
732
|
-
if (
|
|
968
|
+
if (callback(params, options) === !1)
|
|
733
969
|
throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
|
|
734
970
|
}
|
|
735
971
|
}));
|
|
736
972
|
}
|
|
737
|
-
onBeforeDeleteAllDataValidation(
|
|
738
|
-
return
|
|
739
|
-
const
|
|
740
|
-
if (
|
|
741
|
-
if (
|
|
973
|
+
onBeforeDeleteAllDataValidation(callback) {
|
|
974
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
975
|
+
const params = commandInfo.params;
|
|
976
|
+
if (commandInfo.id === RemoveSheetAllDataValidationCommand.id) {
|
|
977
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
742
978
|
return;
|
|
743
|
-
if (
|
|
979
|
+
if (callback(params, options) === !1)
|
|
744
980
|
throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
|
|
745
981
|
}
|
|
746
982
|
}));
|
|
747
983
|
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
984
|
+
};
|
|
985
|
+
__name(_FWorkbookDataValidationMixin, "FWorkbookDataValidationMixin");
|
|
986
|
+
let FWorkbookDataValidationMixin = _FWorkbookDataValidationMixin;
|
|
987
|
+
FWorkbook.extend(FWorkbookDataValidationMixin);
|
|
988
|
+
const _FWorksheetDataValidationMixin = class _FWorksheetDataValidationMixin extends FWorksheet {
|
|
751
989
|
getDataValidations() {
|
|
752
|
-
return this._injector.get(
|
|
990
|
+
return this._injector.get(DataValidationModel).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((rule) => new FDataValidation(rule, this._worksheet, this._injector));
|
|
753
991
|
}
|
|
754
992
|
getValidatorStatus() {
|
|
755
|
-
return this._injector.get(
|
|
993
|
+
return this._injector.get(SheetsDataValidationValidatorService).validatorWorksheet(
|
|
756
994
|
this._workbook.getUnitId(),
|
|
757
995
|
this._worksheet.getSheetId()
|
|
758
996
|
);
|
|
759
997
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
998
|
+
getValidatorStatusAsync() {
|
|
999
|
+
return this.getValidatorStatus();
|
|
1000
|
+
}
|
|
1001
|
+
getDataValidation(ruleId) {
|
|
1002
|
+
const rule = this._injector.get(DataValidationModel).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), ruleId);
|
|
1003
|
+
return rule ? new FDataValidation(rule, this._worksheet, this._injector) : null;
|
|
763
1004
|
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
|
|
1005
|
+
};
|
|
1006
|
+
__name(_FWorksheetDataValidationMixin, "FWorksheetDataValidationMixin");
|
|
1007
|
+
let FWorksheetDataValidationMixin = _FWorksheetDataValidationMixin;
|
|
1008
|
+
FWorksheet.extend(FWorksheetDataValidationMixin);
|
|
1009
|
+
const _FDataValidationEvent = class _FDataValidationEvent {
|
|
767
1010
|
get SheetDataValidationChanged() {
|
|
768
1011
|
return "SheetDataValidationChanged";
|
|
769
1012
|
}
|
|
@@ -788,9 +1031,11 @@ class X {
|
|
|
788
1031
|
get BeforeSheetDataValidationOptionsUpdate() {
|
|
789
1032
|
return "BeforeSheetDataValidationOptionsUpdate";
|
|
790
1033
|
}
|
|
791
|
-
}
|
|
792
|
-
|
|
1034
|
+
};
|
|
1035
|
+
__name(_FDataValidationEvent, "FDataValidationEvent");
|
|
1036
|
+
let FDataValidationEvent = _FDataValidationEvent;
|
|
1037
|
+
FEventName.extend(FDataValidationEvent);
|
|
793
1038
|
export {
|
|
794
|
-
|
|
795
|
-
|
|
1039
|
+
FDataValidation,
|
|
1040
|
+
FDataValidationBuilder
|
|
796
1041
|
};
|