@univerjs/sheets-data-validation 0.6.0 → 0.6.1

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.
@@ -14,12 +14,12 @@ export declare class FDataValidation {
14
14
  * @returns {boolean} true if invalid data is allowed, false otherwise
15
15
  * @example
16
16
  * ```typescript
17
- * const dataValidation = univerAPI
18
- * .getActiveWorkbook()
19
- * .getActiveWorksheet()
20
- * .getActiveRange()
21
- * .getDataValidation();
22
- * const allowsInvalid = dataValidation.getAllowInvalid();
17
+ * const fWorkbook = univerAPI.getActiveWorkbook();
18
+ * const fWorksheet = fWorkbook.getActiveSheet();
19
+ * const rules = fWorksheet.getDataValidations();
20
+ * rules.forEach((rule) => {
21
+ * console.log(rule, rule.getAllowInvalid());
22
+ * });
23
23
  * ```
24
24
  */
25
25
  getAllowInvalid(): boolean;
@@ -28,12 +28,12 @@ export declare class FDataValidation {
28
28
  * @returns {DataValidationType | string} The data validation type
29
29
  * @example
30
30
  * ```typescript
31
- * const dataValidation = univerAPI
32
- * .getActiveWorkbook()
33
- * .getActiveWorksheet()
34
- * .getActiveRange()
35
- * .getDataValidation();
36
- * const type = dataValidation.getCriteriaType();
31
+ * const fWorkbook = univerAPI.getActiveWorkbook();
32
+ * const fWorksheet = fWorkbook.getActiveSheet();
33
+ * const rules = fWorksheet.getDataValidations();
34
+ * rules.forEach((rule) => {
35
+ * console.log(rule, rule.getCriteriaType());
36
+ * });
37
37
  * ```
38
38
  */
39
39
  getCriteriaType(): DataValidationType | string;
@@ -42,12 +42,15 @@ export declare class FDataValidation {
42
42
  * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
43
43
  * @example
44
44
  * ```typescript
45
- * const dataValidation = univerAPI
46
- * .getActiveWorkbook()
47
- * .getActiveWorksheet()
48
- * .getActiveRange()
49
- * .getDataValidation();
50
- * const [operator, formula1, formula2] = dataValidation.getCriteriaValues();
45
+ * const fWorkbook = univerAPI.getActiveWorkbook();
46
+ * const fWorksheet = fWorkbook.getActiveSheet();
47
+ * const rules = fWorksheet.getDataValidations();
48
+ * rules.forEach((rule) => {
49
+ * console.log(rule);
50
+ * const criteriaValues = rule.getCriteriaValues();
51
+ * const [operator, formula1, formula2] = criteriaValues;
52
+ * console.log(operator, formula1, formula2);
53
+ * });
51
54
  * ```
52
55
  */
53
56
  getCriteriaValues(): [string | undefined, string | undefined, string | undefined];
@@ -56,12 +59,19 @@ export declare class FDataValidation {
56
59
  * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
57
60
  * @example
58
61
  * ```typescript
59
- * const dataValidation = univerAPI
60
- * .getActiveWorkbook()
61
- * .getActiveWorksheet()
62
- * .getActiveRange()
63
- * .getDataValidation();
64
- * const helpText = dataValidation.getHelpText();
62
+ * const fWorkbook = univerAPI.getActiveWorkbook();
63
+ * const fWorksheet = fWorkbook.getActiveSheet();
64
+ * const fRange = fWorksheet.getRange('A1:B10');
65
+ * const rule = univerAPI.newDataValidation()
66
+ * .requireNumberBetween(1, 10)
67
+ * .setOptions({
68
+ * allowBlank: true,
69
+ * showErrorMessage: true,
70
+ * error: 'Please enter a number between 1 and 10'
71
+ * })
72
+ * .build();
73
+ * fRange.setDataValidation(rule);
74
+ * console.log(fRange.getDataValidation().getHelpText()); // 'Please enter a number between 1 and 10'
65
75
  * ```
66
76
  */
67
77
  getHelpText(): string | undefined;
@@ -70,13 +80,27 @@ export declare class FDataValidation {
70
80
  * @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
71
81
  * @example
72
82
  * ```typescript
73
- * const dataValidation = univerAPI
74
- * .getActiveWorkbook()
75
- * .getActiveWorksheet()
76
- * .getActiveRange()
77
- * .getDataValidation();
78
- * const builder = dataValidation.copy();
79
- * const newRule = builder.setAllowInvalid(true).build();
83
+ * const fWorkbook = univerAPI.getActiveWorkbook();
84
+ * const fWorksheet = fWorkbook.getActiveSheet();
85
+ * const fRange = fWorksheet.getRange('A1:B10');
86
+ * const rule = univerAPI.newDataValidation()
87
+ * .requireNumberBetween(1, 10)
88
+ * .setOptions({
89
+ * allowBlank: true,
90
+ * showErrorMessage: true,
91
+ * error: 'Please enter a number between 1 and 10'
92
+ * })
93
+ * .build();
94
+ * fRange.setDataValidation(rule);
95
+ *
96
+ * const builder = fRange.getDataValidation().copy();
97
+ * const newRule = builder
98
+ * .requireNumberBetween(1, 5)
99
+ * .setOptions({
100
+ * error: 'Please enter a number between 1 and 5'
101
+ * })
102
+ * .build();
103
+ * fRange.setDataValidation(newRule);
80
104
  * ```
81
105
  */
82
106
  copy(): FDataValidationBuilder;
@@ -85,12 +109,15 @@ export declare class FDataValidation {
85
109
  * @returns {boolean} true if the rule is applied, false otherwise
86
110
  * @example
87
111
  * ```typescript
88
- * const dataValidation = univerAPI
89
- * .getActiveWorkbook()
90
- * .getActiveWorksheet()
91
- * .getActiveRange()
92
- * .getDataValidation();
93
- * const isApplied = dataValidation.getApplied();
112
+ * const fWorkbook = univerAPI.getActiveWorkbook();
113
+ * const fWorksheet = fWorkbook.getActiveSheet();
114
+ * const rules = fWorksheet.getDataValidations();
115
+ * rules.forEach((rule) => {
116
+ * console.log(rule, rule.getApplied());
117
+ * });
118
+ *
119
+ * const fRange = fWorksheet.getRange('A1:B10');
120
+ * console.log(fRange.getDataValidation()?.getApplied());
94
121
  * ```
95
122
  */
96
123
  getApplied(): boolean;
@@ -99,12 +126,16 @@ export declare class FDataValidation {
99
126
  * @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
100
127
  * @example
101
128
  * ```typescript
102
- * const dataValidation = univerAPI
103
- * .getActiveWorkbook()
104
- * .getActiveWorksheet()
105
- * .getActiveRange()
106
- * .getDataValidation();
107
- * const ranges = dataValidation.getRanges();
129
+ * const fWorkbook = univerAPI.getActiveWorkbook();
130
+ * const fWorksheet = fWorkbook.getActiveSheet();
131
+ * const rules = fWorksheet.getDataValidations();
132
+ * rules.forEach((rule) => {
133
+ * console.log(rule);
134
+ * const ranges = rule.getRanges();
135
+ * ranges.forEach((range) => {
136
+ * console.log(range.getA1Notation());
137
+ * });
138
+ * });
108
139
  * ```
109
140
  */
110
141
  getRanges(): FRange[];
@@ -113,12 +144,10 @@ export declare class FDataValidation {
113
144
  * @returns {string | undefined} The unit ID of the worksheet
114
145
  * @example
115
146
  * ```typescript
116
- * const dataValidation = univerAPI
117
- * .getActiveWorkbook()
118
- * .getActiveWorksheet()
119
- * .getActiveRange()
120
- * .getDataValidation();
121
- * const unitId = dataValidation.getUnitId();
147
+ * const fWorkbook = univerAPI.getActiveWorkbook();
148
+ * const fWorksheet = fWorkbook.getActiveSheet();
149
+ * const fRange = fWorksheet.getRange('A1:B10');
150
+ * console.log(fRange.getDataValidation().getUnitId());
122
151
  * ```
123
152
  */
124
153
  getUnitId(): string | undefined;
@@ -127,12 +156,10 @@ export declare class FDataValidation {
127
156
  * @returns {string | undefined} The sheet ID of the worksheet
128
157
  * @example
129
158
  * ```typescript
130
- * const dataValidation = univerAPI
131
- * .getActiveWorkbook()
132
- * .getActiveWorksheet()
133
- * .getActiveRange()
134
- * .getDataValidation();
135
- * const sheetId = dataValidation.getSheetId();
159
+ * const fWorkbook = univerAPI.getActiveWorkbook();
160
+ * const fWorksheet = fWorkbook.getActiveSheet();
161
+ * const fRange = fWorksheet.getRange('A1:B10');
162
+ * console.log(fRange.getDataValidation().getSheetId());
136
163
  * ```
137
164
  */
138
165
  getSheetId(): string | undefined;
@@ -144,15 +171,17 @@ export declare class FDataValidation {
144
171
  * @returns {FDataValidation} The current instance for method chaining
145
172
  * @example
146
173
  * ```typescript
147
- * const dataValidation = univerAPI
148
- * .getActiveWorkbook()
149
- * .getActiveWorksheet()
150
- * .getActiveRange()
151
- * .getDataValidation();
152
- * dataValidation.setCriteria(
153
- * DataValidationType.DECIMAL,
154
- * [DataValidationOperator.BETWEEN, '1', '10'],
155
- * true
174
+ * const fWorkbook = univerAPI.getActiveWorkbook();
175
+ * const fWorksheet = fWorkbook.getActiveSheet();
176
+ * const fRange = fWorksheet.getRange('A1:B10');
177
+ * const rule = univerAPI.newDataValidation()
178
+ * .requireNumberEqualTo(20)
179
+ * .build();
180
+ * fRange.setDataValidation(rule);
181
+ *
182
+ * fRange.getDataValidation().setCriteria(
183
+ * univerAPI.Enum.DataValidationType.DECIMAL,
184
+ * [univerAPI.Enum.DataValidationOperator.BETWEEN, '1', '10']
156
185
  * );
157
186
  * ```
158
187
  */
@@ -163,12 +192,15 @@ export declare class FDataValidation {
163
192
  * @returns {FDataValidation} The current instance for method chaining
164
193
  * @example
165
194
  * ```typescript
166
- * const dataValidation = univerAPI
167
- * .getActiveWorkbook()
168
- * .getActiveWorksheet()
169
- * .getActiveRange()
170
- * .getDataValidation();
171
- * dataValidation.setOptions({
195
+ * const fWorkbook = univerAPI.getActiveWorkbook();
196
+ * const fWorksheet = fWorkbook.getActiveSheet();
197
+ * const fRange = fWorksheet.getRange('A1:B10');
198
+ * const rule = univerAPI.newDataValidation()
199
+ * .requireNumberEqualTo(20)
200
+ * .build();
201
+ * fRange.setDataValidation(rule);
202
+ *
203
+ * fRange.getDataValidation().setOptions({
172
204
  * allowBlank: true,
173
205
  * showErrorMessage: true,
174
206
  * error: 'Please enter a valid value'
@@ -182,13 +214,16 @@ export declare class FDataValidation {
182
214
  * @returns {FDataValidation} The current instance for method chaining
183
215
  * @example
184
216
  * ```typescript
185
- * const dataValidation = univerAPI
186
- * .getActiveWorkbook()
187
- * .getActiveWorksheet()
188
- * .getActiveRange()
189
- * .getDataValidation();
190
- * const range = FRange.create('Sheet1', 'A1:B10');
191
- * dataValidation.setRanges([range]);
217
+ * const fWorkbook = univerAPI.getActiveWorkbook();
218
+ * const fWorksheet = fWorkbook.getActiveSheet();
219
+ * const fRange = fWorksheet.getRange('A1:B10');
220
+ * const rule = univerAPI.newDataValidation()
221
+ * .requireNumberEqualTo(20)
222
+ * .build();
223
+ * fRange.setDataValidation(rule);
224
+ *
225
+ * const newRuleRange = fWorksheet.getRange('C1:D10');
226
+ * fRange.getDataValidation().setRanges([newRuleRange]);
192
227
  * ```
193
228
  */
194
229
  setRanges(ranges: FRange[]): FDataValidation;
@@ -197,12 +232,15 @@ export declare class FDataValidation {
197
232
  * @returns {boolean} true if the rule is deleted successfully, false otherwise
198
233
  * @example
199
234
  * ```typescript
200
- * const dataValidation = univerAPI
201
- * .getActiveWorkbook()
202
- * .getActiveWorksheet()
203
- * .getActiveRange()
204
- * .getDataValidation();
205
- * const isDeleted = dataValidation.delete();
235
+ * const fWorkbook = univerAPI.getActiveWorkbook();
236
+ * const fWorksheet = fWorkbook.getActiveSheet();
237
+ * const fRange = fWorksheet.getRange('A1:B10');
238
+ * const rule = univerAPI.newDataValidation()
239
+ * .requireNumberEqualTo(20)
240
+ * .build();
241
+ * fRange.setDataValidation(rule);
242
+ *
243
+ * fRange.getDataValidation().delete();
206
244
  * ```
207
245
  */
208
246
  delete(): boolean;
@@ -155,10 +155,12 @@ interface IDataValidationEvent {
155
155
  * @see {@link ISheetDataValidationChangedEvent}
156
156
  * @example
157
157
  * ```ts
158
- * univerAPI.on(univerAPI.Event.SheetDataValidationChanged, (event) => {
159
- * const { worksheet, workbook, changeType, oldRule, rule } = event;
160
- * console.log(event);
158
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetDataValidationChanged, (event) => {
159
+ * const { origin, worksheet, workbook, changeType, oldRule, rule } = event;
160
+ * console.log(event);
161
161
  * });
162
+ *
163
+ * // Remove the event listener, use `disposable.dispose()`
162
164
  * ```
163
165
  */
164
166
  readonly SheetDataValidationChanged: 'SheetDataValidationChanged';
@@ -167,10 +169,12 @@ interface IDataValidationEvent {
167
169
  * @see {@link ISheetDataValidatorStatusChangedEvent}
168
170
  * @example
169
171
  * ```ts
170
- * univerAPI.on(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => {
171
- * const { worksheet, workbook, row, column, status, rule } = event;
172
- * console.log(event);
172
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => {
173
+ * const { worksheet, workbook, row, column, status, rule } = event;
174
+ * console.log(event);
173
175
  * });
176
+ *
177
+ * // Remove the event listener, use `disposable.dispose()`
174
178
  * ```
175
179
  */
176
180
  readonly SheetDataValidatorStatusChanged: 'SheetDataValidatorStatusChanged';
@@ -179,10 +183,15 @@ interface IDataValidationEvent {
179
183
  * @see {@link IBeforeSheetDataValidationAddEvent}
180
184
  * @example
181
185
  * ```ts
182
- * univerAPI.on(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => {
183
- * const { worksheet, workbook, rule } = event;
184
- * console.log(event);
186
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => {
187
+ * const { worksheet, workbook, rule } = event;
188
+ * console.log(event);
189
+ *
190
+ * // Cancel the data validation rule addition operation
191
+ * event.cancel = true;
185
192
  * });
193
+ *
194
+ * // Remove the event listener, use `disposable.dispose()`
186
195
  * ```
187
196
  */
188
197
  readonly BeforeSheetDataValidationAdd: 'BeforeSheetDataValidationAdd';
@@ -191,10 +200,15 @@ interface IDataValidationEvent {
191
200
  * @see {@link IBeforeSheetDataValidationDeleteEvent}
192
201
  * @example
193
202
  * ```ts
194
- * univerAPI.on(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => {
195
- * const { worksheet, workbook, rule } = event;
196
- * console.log(event);
203
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => {
204
+ * const { worksheet, workbook, ruleId, rule } = event;
205
+ * console.log(event);
206
+ *
207
+ * // Cancel the data validation rule deletion operation
208
+ * event.cancel = true;
197
209
  * });
210
+ *
211
+ * // Remove the event listener, use `disposable.dispose()`
198
212
  * ```
199
213
  */
200
214
  readonly BeforeSheetDataValidationDelete: 'BeforeSheetDataValidationDelete';
@@ -203,10 +217,15 @@ interface IDataValidationEvent {
203
217
  * @see {@link IBeforeSheetDataValidationDeleteAllEvent}
204
218
  * @example
205
219
  * ```ts
206
- * univerAPI.on(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => {
207
- * const { worksheet, workbook, rules } = event;
208
- * console.log(event);
220
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => {
221
+ * const { worksheet, workbook, rules } = event;
222
+ * console.log(event);
223
+ *
224
+ * // Cancel the data validation rule deletion operation
225
+ * event.cancel = true;
209
226
  * });
227
+ *
228
+ * // Remove the event listener, use `disposable.dispose()`
210
229
  * ```
211
230
  */
212
231
  readonly BeforeSheetDataValidationDeleteAll: 'BeforeSheetDataValidationDeleteAll';
@@ -215,10 +234,15 @@ interface IDataValidationEvent {
215
234
  * @see {@link IBeforeSheetDataValidationCriteriaUpdateEvent}
216
235
  * @example
217
236
  * ```ts
218
- * univerAPI.on(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => {
219
- * const { worksheet, workbook, rule, newCriteria } = event;
220
- * console.log(event);
237
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => {
238
+ * const { worksheet, workbook, ruleId, rule, newCriteria } = event;
239
+ * console.log(event);
240
+ *
241
+ * // Cancel the data validation rule criteria update operation
242
+ * event.cancel = true;
221
243
  * });
244
+ *
245
+ * // Remove the event listener, use `disposable.dispose()`
222
246
  * ```
223
247
  */
224
248
  readonly BeforeSheetDataValidationCriteriaUpdate: 'BeforeSheetDataValidationCriteriaUpdate';
@@ -227,10 +251,15 @@ interface IDataValidationEvent {
227
251
  * @see {@link IBeforeSheetDataValidationRangeUpdateEvent}
228
252
  * @example
229
253
  * ```ts
230
- * univerAPI.on(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => {
231
- * const { worksheet, workbook, rule, newRanges } = event;
232
- * console.log(event);
254
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => {
255
+ * const { worksheet, workbook, ruleId, rule, newRanges } = event;
256
+ * console.log(event);
257
+ *
258
+ * // Cancel the data validation rule range update operation
259
+ * event.cancel = true;
233
260
  * });
261
+ *
262
+ * // Remove the event listener, use `disposable.dispose()`
234
263
  * ```
235
264
  */
236
265
  readonly BeforeSheetDataValidationRangeUpdate: 'BeforeSheetDataValidationRangeUpdate';
@@ -239,10 +268,15 @@ interface IDataValidationEvent {
239
268
  * @see {@link IBeforeSheetDataValidationOptionsUpdateEvent}
240
269
  * @example
241
270
  * ```ts
242
- * univerAPI.on(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => {
243
- * const { worksheet, workbook, rule, newOptions } = event;
244
- * console.log(event);
271
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => {
272
+ * const { worksheet, workbook, ruleId, rule, newOptions } = event;
273
+ * console.log(event);
274
+ *
275
+ * // Cancel the data validation rule options update operation
276
+ * event.cancel = true;
245
277
  * });
278
+ *
279
+ * // Remove the event listener, use `disposable.dispose()`
246
280
  * ```
247
281
  */
248
282
  readonly BeforeSheetDataValidationOptionsUpdate: 'BeforeSheetDataValidationOptionsUpdate';
@@ -11,8 +11,18 @@ export interface IFRangeDataValidationMixin {
11
11
  * @returns current range
12
12
  * @example
13
13
  * ```ts
14
- * const rule = FUniver.newDataValidation().requireValueInRange(range).build();
15
- * cell.setDataValidation(rule);
14
+ * const fWorkbook = univerAPI.getActiveWorkbook();
15
+ * const fWorksheet = fWorkbook.getActiveSheet();
16
+ * const fRange = fWorksheet.getRange('A1:B10');
17
+ * const rule = univerAPI.newDataValidation()
18
+ * .requireNumberBetween(1, 10)
19
+ * .setOptions({
20
+ * allowBlank: true,
21
+ * showErrorMessage: true,
22
+ * error: 'Please enter a number between 1 and 10'
23
+ * })
24
+ * .build();
25
+ * fRange.setDataValidation(rule);
16
26
  * ```
17
27
  */
18
28
  setDataValidation(rule: Nullable<FDataValidation>): FRange;
@@ -21,9 +31,20 @@ export interface IFRangeDataValidationMixin {
21
31
  * @returns {Nullable<FDataValidation>} data validation rule
22
32
  * @example
23
33
  * ```ts
24
- * const workbook = univerAPI.getActiveWorkbook();
25
- * const worksheet = workbook.getActiveSheet();
26
- * const dataValidation = worksheet.getActiveRange().getDataValidation();
34
+ * const fWorkbook = univerAPI.getActiveWorkbook();
35
+ * const fWorksheet = fWorkbook.getActiveSheet();
36
+ * const fRange = fWorksheet.getRange('A1:B10');
37
+ * const rule = univerAPI.newDataValidation()
38
+ * .requireNumberEqualTo(20)
39
+ * .build();
40
+ * fRange.setDataValidation(rule);
41
+ * console.log(fRange.getDataValidation().getCriteriaValues());
42
+ *
43
+ * fRange.getDataValidation().setCriteria(
44
+ * univerAPI.Enum.DataValidationType.DECIMAL,
45
+ * [univerAPI.Enum.DataValidationOperator.BETWEEN, '1', '10']
46
+ * );
47
+ * console.log(fRange.getDataValidation().getCriteriaValues());
27
48
  * ```
28
49
  */
29
50
  getDataValidation(): Nullable<FDataValidation>;
@@ -32,9 +53,23 @@ export interface IFRangeDataValidationMixin {
32
53
  * @returns {FDataValidation[]} all data validation rules
33
54
  * @example
34
55
  * ```ts
35
- * const workbook = univerAPI.getActiveWorkbook();
36
- * const worksheet = workbook.getActiveSheet();
37
- * const dataValidations = worksheet.getActiveRange().getDataValidations();
56
+ * const fWorkbook = univerAPI.getActiveWorkbook();
57
+ * const fWorksheet = fWorkbook.getActiveSheet();
58
+ * const fRange1 = fWorksheet.getRange('A1:B10');
59
+ * const rule1 = univerAPI.newDataValidation()
60
+ * .requireNumberEqualTo(20)
61
+ * .build();
62
+ * fRange1.setDataValidation(rule1);
63
+ *
64
+ * const fRange2 = fWorksheet.getRange('C1:D10');
65
+ * const rule2 = univerAPI.newDataValidation()
66
+ * .requireNumberBetween(1, 10)
67
+ * .build();
68
+ * fRange2.setDataValidation(rule2);
69
+ *
70
+ * const range = fWorksheet.getRange('A1:D10');
71
+ * const rules = range.getDataValidations();
72
+ * console.log(rules.length); // 2
38
73
  * ```
39
74
  */
40
75
  getDataValidations(): FDataValidation[];
@@ -43,9 +78,31 @@ export interface IFRangeDataValidationMixin {
43
78
  * @returns {Promise<DataValidationStatus[][]>} matrix of validator status
44
79
  * @example
45
80
  * ```ts
46
- * const workbook = univerAPI.getActiveWorkbook();
47
- * const worksheet = workbook.getActiveSheet();
48
- * const validatorStatus = worksheet.getActiveRange().getValidatorStatus();
81
+ * const fWorkbook = univerAPI.getActiveWorkbook();
82
+ * const fWorksheet = fWorkbook.getActiveSheet();
83
+ * const fRange = fWorksheet.getRange('A1:B10');
84
+ * fRange.setValues([
85
+ * [1, 2],
86
+ * [3, 4],
87
+ * [5, 6],
88
+ * [7, 8],
89
+ * [9, 10],
90
+ * [11, 12],
91
+ * [13, 14],
92
+ * [15, 16],
93
+ * [17, 18],
94
+ * [19, 20]
95
+ * ]);
96
+ * const rule = univerAPI.newDataValidation()
97
+ * .requireNumberBetween(1, 10)
98
+ * .build();
99
+ * fRange.setDataValidation(rule);
100
+ *
101
+ * const status = await fWorksheet.getRange('B2').getValidatorStatus();
102
+ * console.log(status?.[0]?.[0]); // 'valid'
103
+ *
104
+ * const status2 = await fWorksheet.getRange('B10').getValidatorStatus();
105
+ * console.log(status2?.[0]?.[0]); // 'invalid'
49
106
  * ```
50
107
  */
51
108
  getValidatorStatus(): Promise<DataValidationStatus[][]>;
@@ -1,6 +1,6 @@
1
+ import { DataValidationStatus, IDisposable, IExecutionOptions, Nullable, ObjectMatrix } from '@univerjs/core';
1
2
  import { IRuleChange } from '@univerjs/data-validation';
2
3
  import { IAddSheetDataValidationCommandParams, IRemoveSheetAllDataValidationCommandParams, IRemoveSheetDataValidationCommandParams, IUpdateSheetDataValidationOptionsCommandParams, IUpdateSheetDataValidationRangeCommandParams, IUpdateSheetDataValidationSettingCommandParams, IValidStatusChange, SheetDataValidationModel } from '@univerjs/sheets-data-validation';
3
- import { DataValidationStatus, IDisposable, IExecutionOptions, Nullable, ObjectMatrix } from '@univerjs/core';
4
4
  import { FWorkbook } from '@univerjs/sheets/facade';
5
5
  /**
6
6
  * @ignore
@@ -11,10 +11,12 @@ export interface IFWorkbookDataValidationMixin {
11
11
  * @returns A promise that resolves to a matrix of validator status.
12
12
  * @example
13
13
  * ```ts
14
- * univerAPI.getActiveWorkbook().getValidatorStatus().then((status) => { console.log(status) })
14
+ * const fWorkbook = univerAPI.getActiveWorkbook();
15
+ * const status = await fWorkbook.getValidatorStatus();
16
+ * console.log(status);
15
17
  * ```
16
18
  */
17
- getValidatorStatus(this: FWorkbook): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>;
19
+ getValidatorStatus(): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>;
18
20
  /**
19
21
  * @deprecated Use `univerAPI.addEvent(univerAPI.Event.SheetDataValidationChanged, (event) => { ... })` instead
20
22
  */
@@ -7,11 +7,12 @@ import { FDataValidation } from './f-data-validation';
7
7
  export interface IFWorksheetDataValidationMixin {
8
8
  /**
9
9
  * Get all data validation rules in current sheet.
10
- * @returns {FDataValidation[]} all data validation rules
10
+ * @returns {FDataValidation[]} All data validation rules
11
11
  * ```ts
12
- * const workbook = univerAPI.getActiveWorkbook();
13
- * const worksheet = workbook.getWorksheet('sheet1');
14
- * const dataValidations = worksheet.getDataValidations();
12
+ * const fWorkbook = univerAPI.getActiveWorkbook();
13
+ * const fWorksheet = fWorkbook.getActiveSheet();
14
+ * const rules = fWorksheet.getDataValidations();
15
+ * console.log(rules);
15
16
  * ```
16
17
  */
17
18
  getDataValidations(): FDataValidation[];
@@ -23,9 +24,10 @@ export interface IFWorksheetDataValidationMixin {
23
24
  * Get data validation validator status for current sheet.
24
25
  * @returns {Promise<ObjectMatrix<Nullable<DataValidationStatus>>>} matrix of validator status
25
26
  * ```ts
26
- * const workbook = univerAPI.getActiveWorkbook();
27
- * const worksheet = workbook.getWorksheet('sheet1');
28
- * const validatorStatus = worksheet.getValidatorStatus();
27
+ * const fWorkbook = univerAPI.getActiveWorkbook();
28
+ * const fWorksheet = fWorkbook.getActiveSheet();
29
+ * const status = await fWorksheet.getValidatorStatusAsync();
30
+ * console.log(status);
29
31
  * ```
30
32
  */
31
33
  getValidatorStatusAsync(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
@@ -34,9 +36,10 @@ export interface IFWorksheetDataValidationMixin {
34
36
  * @param ruleId - the rule id
35
37
  * @returns {Nullable<FDataValidation>} data validation rule
36
38
  * ```ts
37
- * const workbook = univerAPI.getActiveWorkbook();
38
- * const worksheet = workbook.getWorksheet('sheet1');
39
- * const dataValidation = worksheet.getDataValidation('ruleId');
39
+ * const fWorkbook = univerAPI.getActiveWorkbook();
40
+ * const fWorksheet = fWorkbook.getActiveSheet();
41
+ * const rules = fWorksheet.getDataValidations();
42
+ * console.log(fWorksheet.getDataValidation(rules[0]?.rule.uid));
40
43
  * ```
41
44
  */
42
45
  getDataValidation(ruleId: string): Nullable<FDataValidation>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-data-validation",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "description": "Data validation for Univer Sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -54,19 +54,19 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@univerjs/protocol": "0.1.43",
57
- "@univerjs/core": "0.6.0",
58
- "@univerjs/data-validation": "0.6.0",
59
- "@univerjs/engine-formula": "0.6.0",
60
- "@univerjs/sheets": "0.6.0",
61
- "@univerjs/sheets-formula": "0.6.0"
57
+ "@univerjs/core": "0.6.1",
58
+ "@univerjs/data-validation": "0.6.1",
59
+ "@univerjs/engine-formula": "0.6.1",
60
+ "@univerjs/sheets-formula": "0.6.1",
61
+ "@univerjs/sheets": "0.6.1"
62
62
  },
63
63
  "devDependencies": {
64
64
  "less": "^4.2.2",
65
65
  "rxjs": "^7.8.1",
66
66
  "typescript": "^5.7.3",
67
- "vite": "^6.1.0",
68
- "vitest": "^3.0.5",
69
- "@univerjs-infra/shared": "0.6.0"
67
+ "vite": "^6.1.1",
68
+ "vitest": "^3.0.6",
69
+ "@univerjs-infra/shared": "0.6.1"
70
70
  },
71
71
  "scripts": {
72
72
  "dev": "vite",