@univerjs/sheets-data-validation 0.5.4-nightly.202501151606 → 0.5.4-nightly.202501160647
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/es/facade.js +434 -170
- package/lib/types/facade/f-data-validation-builder.d.ts +236 -103
- package/lib/types/facade/f-data-validation.d.ts +155 -30
- package/lib/types/facade/f-range.d.ts +34 -7
- package/lib/types/facade/f-univer.d.ts +10 -1
- package/lib/types/facade/f-workbook.d.ts +8 -24
- package/lib/types/facade/f-worksheet.d.ts +9 -4
- package/lib/umd/facade.js +1 -1
- package/package.json +6 -6
|
@@ -7,75 +7,200 @@ export declare class FDataValidation {
|
|
|
7
7
|
private _injector;
|
|
8
8
|
constructor(rule: IDataValidationRule, worksheet?: Worksheet, _injector?: Injector);
|
|
9
9
|
/**
|
|
10
|
-
* Gets whether invalid data is allowed based on the error style value
|
|
11
|
-
* @returns true if invalid data is allowed, false otherwise
|
|
10
|
+
* Gets whether invalid data is allowed based on the error style value
|
|
11
|
+
* @returns {boolean} true if invalid data is allowed, false otherwise
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const dataValidation = univerAPI
|
|
15
|
+
* .getActiveWorkbook()
|
|
16
|
+
* .getActiveWorksheet()
|
|
17
|
+
* .getActiveRange()
|
|
18
|
+
* .getDataValidation();
|
|
19
|
+
* const allowsInvalid = dataValidation.getAllowInvalid();
|
|
20
|
+
* ```
|
|
12
21
|
*/
|
|
13
22
|
getAllowInvalid(): boolean;
|
|
14
23
|
/**
|
|
15
24
|
* Gets the data validation type of the rule
|
|
16
|
-
* @returns The data validation type
|
|
25
|
+
* @returns {DataValidationType | string} The data validation type
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const dataValidation = univerAPI
|
|
29
|
+
* .getActiveWorkbook()
|
|
30
|
+
* .getActiveWorksheet()
|
|
31
|
+
* .getActiveRange()
|
|
32
|
+
* .getDataValidation();
|
|
33
|
+
* const type = dataValidation.getCriteriaType();
|
|
34
|
+
* ```
|
|
17
35
|
*/
|
|
18
36
|
getCriteriaType(): DataValidationType | string;
|
|
19
37
|
/**
|
|
20
38
|
* Gets the values used for criteria evaluation
|
|
21
|
-
* @returns An array containing the operator, formula1, and formula2 values
|
|
39
|
+
* @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const dataValidation = univerAPI
|
|
43
|
+
* .getActiveWorkbook()
|
|
44
|
+
* .getActiveWorksheet()
|
|
45
|
+
* .getActiveRange()
|
|
46
|
+
* .getDataValidation();
|
|
47
|
+
* const [operator, formula1, formula2] = dataValidation.getCriteriaValues();
|
|
48
|
+
* ```
|
|
22
49
|
*/
|
|
23
50
|
getCriteriaValues(): [string | undefined, string | undefined, string | undefined];
|
|
24
51
|
/**
|
|
25
52
|
* Gets the help text information, which is used to provide users with guidance and support
|
|
26
|
-
* @returns Returns the help text information. If there is no error message, it returns an undefined value
|
|
53
|
+
* @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const dataValidation = univerAPI
|
|
57
|
+
* .getActiveWorkbook()
|
|
58
|
+
* .getActiveWorksheet()
|
|
59
|
+
* .getActiveRange()
|
|
60
|
+
* .getDataValidation();
|
|
61
|
+
* const helpText = dataValidation.getHelpText();
|
|
62
|
+
* ```
|
|
27
63
|
*/
|
|
28
64
|
getHelpText(): string | undefined;
|
|
29
65
|
/**
|
|
30
|
-
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
66
|
+
* Creates a new instance of FDataValidationBuilder using the current rule object
|
|
67
|
+
* @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const dataValidation = univerAPI
|
|
71
|
+
* .getActiveWorkbook()
|
|
72
|
+
* .getActiveWorksheet()
|
|
73
|
+
* .getActiveRange()
|
|
74
|
+
* .getDataValidation();
|
|
75
|
+
* const builder = dataValidation.copy();
|
|
76
|
+
* const newRule = builder.setAllowInvalid(true).build();
|
|
77
|
+
* ```
|
|
33
78
|
*/
|
|
34
79
|
copy(): FDataValidationBuilder;
|
|
35
80
|
/**
|
|
36
|
-
* Gets whether the data validation rule is applied to the worksheet
|
|
37
|
-
* @returns true if the rule is applied, false otherwise
|
|
81
|
+
* Gets whether the data validation rule is applied to the worksheet
|
|
82
|
+
* @returns {boolean} true if the rule is applied, false otherwise
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const dataValidation = univerAPI
|
|
86
|
+
* .getActiveWorkbook()
|
|
87
|
+
* .getActiveWorksheet()
|
|
88
|
+
* .getActiveRange()
|
|
89
|
+
* .getDataValidation();
|
|
90
|
+
* const isApplied = dataValidation.getApplied();
|
|
91
|
+
* ```
|
|
38
92
|
*/
|
|
39
93
|
getApplied(): boolean;
|
|
40
94
|
/**
|
|
41
|
-
* Gets the ranges to which the data validation rule is applied
|
|
42
|
-
* @returns An array of
|
|
95
|
+
* Gets the ranges to which the data validation rule is applied
|
|
96
|
+
* @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const dataValidation = univerAPI
|
|
100
|
+
* .getActiveWorkbook()
|
|
101
|
+
* .getActiveWorksheet()
|
|
102
|
+
* .getActiveRange()
|
|
103
|
+
* .getDataValidation();
|
|
104
|
+
* const ranges = dataValidation.getRanges();
|
|
105
|
+
* ```
|
|
43
106
|
*/
|
|
44
107
|
getRanges(): FRange[];
|
|
45
108
|
/**
|
|
46
|
-
* Gets the
|
|
47
|
-
* @returns The
|
|
109
|
+
* Gets the unit ID of the worksheet
|
|
110
|
+
* @returns {string | undefined} The unit ID of the worksheet
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const dataValidation = univerAPI
|
|
114
|
+
* .getActiveWorkbook()
|
|
115
|
+
* .getActiveWorksheet()
|
|
116
|
+
* .getActiveRange()
|
|
117
|
+
* .getDataValidation();
|
|
118
|
+
* const unitId = dataValidation.getUnitId();
|
|
119
|
+
* ```
|
|
48
120
|
*/
|
|
49
121
|
getUnitId(): string | undefined;
|
|
50
122
|
/**
|
|
51
|
-
* Gets the
|
|
52
|
-
* @returns The
|
|
123
|
+
* Gets the sheet ID of the worksheet
|
|
124
|
+
* @returns {string | undefined} The sheet ID of the worksheet
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const dataValidation = univerAPI
|
|
128
|
+
* .getActiveWorkbook()
|
|
129
|
+
* .getActiveWorksheet()
|
|
130
|
+
* .getActiveRange()
|
|
131
|
+
* .getDataValidation();
|
|
132
|
+
* const sheetId = dataValidation.getSheetId();
|
|
133
|
+
* ```
|
|
53
134
|
*/
|
|
54
135
|
getSheetId(): string | undefined;
|
|
55
136
|
/**
|
|
56
|
-
* Set Criteria for the data validation rule
|
|
57
|
-
* @param type The type of data validation criteria
|
|
58
|
-
* @param values An array containing the operator, formula1, and formula2 values
|
|
59
|
-
* @param allowBlank
|
|
60
|
-
* @returns
|
|
137
|
+
* Set Criteria for the data validation rule
|
|
138
|
+
* @param {DataValidationType} type - The type of data validation criteria
|
|
139
|
+
* @param {[DataValidationOperator, string, string]} values - An array containing the operator, formula1, and formula2 values
|
|
140
|
+
* @param {boolean} [allowBlank] - Whether to allow blank values
|
|
141
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const dataValidation = univerAPI
|
|
145
|
+
* .getActiveWorkbook()
|
|
146
|
+
* .getActiveWorksheet()
|
|
147
|
+
* .getActiveRange()
|
|
148
|
+
* .getDataValidation();
|
|
149
|
+
* dataValidation.setCriteria(
|
|
150
|
+
* DataValidationType.DECIMAL,
|
|
151
|
+
* [DataValidationOperator.BETWEEN, '1', '10'],
|
|
152
|
+
* true
|
|
153
|
+
* );
|
|
154
|
+
* ```
|
|
61
155
|
*/
|
|
62
156
|
setCriteria(type: DataValidationType, values: [DataValidationOperator, string, string], allowBlank?: boolean): FDataValidation;
|
|
63
157
|
/**
|
|
64
|
-
* Set the options for the data validation rule
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
* @
|
|
158
|
+
* Set the options for the data validation rule
|
|
159
|
+
* @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
|
|
160
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const dataValidation = univerAPI
|
|
164
|
+
* .getActiveWorkbook()
|
|
165
|
+
* .getActiveWorksheet()
|
|
166
|
+
* .getActiveRange()
|
|
167
|
+
* .getDataValidation();
|
|
168
|
+
* dataValidation.setOptions({
|
|
169
|
+
* allowBlank: true,
|
|
170
|
+
* showErrorMessage: true,
|
|
171
|
+
* error: 'Please enter a valid value'
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
68
174
|
*/
|
|
69
175
|
setOptions(options: Partial<IDataValidationRuleOptions>): FDataValidation;
|
|
70
176
|
/**
|
|
71
|
-
* Set the ranges to the data validation rule
|
|
72
|
-
* @param ranges
|
|
73
|
-
* @returns
|
|
177
|
+
* Set the ranges to the data validation rule
|
|
178
|
+
* @param {FRange[]} ranges - New ranges array
|
|
179
|
+
* @returns {FDataValidation} The current instance for method chaining
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const dataValidation = univerAPI
|
|
183
|
+
* .getActiveWorkbook()
|
|
184
|
+
* .getActiveWorksheet()
|
|
185
|
+
* .getActiveRange()
|
|
186
|
+
* .getDataValidation();
|
|
187
|
+
* const range = FRange.create('Sheet1', 'A1:B10');
|
|
188
|
+
* dataValidation.setRanges([range]);
|
|
189
|
+
* ```
|
|
74
190
|
*/
|
|
75
191
|
setRanges(ranges: FRange[]): FDataValidation;
|
|
76
192
|
/**
|
|
77
|
-
* Delete the data validation rule from the worksheet
|
|
78
|
-
* @returns true if the rule is deleted successfully, false otherwise
|
|
193
|
+
* Delete the data validation rule from the worksheet
|
|
194
|
+
* @returns {boolean} true if the rule is deleted successfully, false otherwise
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const dataValidation = univerAPI
|
|
198
|
+
* .getActiveWorkbook()
|
|
199
|
+
* .getActiveWorksheet()
|
|
200
|
+
* .getActiveRange()
|
|
201
|
+
* .getDataValidation();
|
|
202
|
+
* const isDeleted = dataValidation.delete();
|
|
203
|
+
* ```
|
|
79
204
|
*/
|
|
80
205
|
delete(): boolean;
|
|
81
206
|
}
|
|
@@ -3,21 +3,48 @@ import { FRange } from '@univerjs/sheets/facade';
|
|
|
3
3
|
import { FDataValidation } from './f-data-validation';
|
|
4
4
|
export interface IFRangeDataValidationMixin {
|
|
5
5
|
/**
|
|
6
|
-
* Set a data validation rule to current range.
|
|
7
|
-
* @param rule data validation rule, build by `FUniver.newDataValidation`
|
|
6
|
+
* Set a data validation rule to current range. if rule is null, clear data validation rule.
|
|
7
|
+
* @param {Nullable<FDataValidation>} rule data validation rule, build by `FUniver.newDataValidation`
|
|
8
8
|
* @returns current range
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const rule = FUniver.newDataValidation().requireValueInRange(range).build();
|
|
12
|
+
* cell.setDataValidation(rule);
|
|
13
|
+
* ```
|
|
9
14
|
*/
|
|
10
|
-
setDataValidation(
|
|
15
|
+
setDataValidation(rule: Nullable<FDataValidation>): FRange;
|
|
11
16
|
/**
|
|
12
17
|
* Get first data validation rule in current range.
|
|
13
|
-
* @returns data validation rule
|
|
18
|
+
* @returns {Nullable<FDataValidation>} data validation rule
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
22
|
+
* const worksheet = workbook.getActiveSheet();
|
|
23
|
+
* const dataValidation = worksheet.getActiveRange().getDataValidation();
|
|
24
|
+
* ```
|
|
14
25
|
*/
|
|
15
|
-
getDataValidation(
|
|
26
|
+
getDataValidation(): Nullable<FDataValidation>;
|
|
16
27
|
/**
|
|
17
28
|
* Get all data validation rules in current range.
|
|
18
|
-
* @returns all data validation rules
|
|
29
|
+
* @returns {FDataValidation[]} all data validation rules
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
33
|
+
* const worksheet = workbook.getActiveSheet();
|
|
34
|
+
* const dataValidations = worksheet.getActiveRange().getDataValidations();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
getDataValidations(): FDataValidation[];
|
|
38
|
+
/**
|
|
39
|
+
* Get data validation validator status for current range.
|
|
40
|
+
* @returns {Promise<DataValidationStatus[][]>} matrix of validator status
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
44
|
+
* const worksheet = workbook.getActiveSheet();
|
|
45
|
+
* const validatorStatus = worksheet.getActiveRange().getValidatorStatus();
|
|
46
|
+
* ```
|
|
19
47
|
*/
|
|
20
|
-
getDataValidations(this: FRange): FDataValidation[];
|
|
21
48
|
getValidatorStatus(): Promise<DataValidationStatus[][]>;
|
|
22
49
|
}
|
|
23
50
|
export declare class FRangeDataValidationMixin extends FRange implements IFRangeDataValidationMixin {
|
|
@@ -3,9 +3,18 @@ import { FDataValidationBuilder } from './f-data-validation-builder';
|
|
|
3
3
|
export declare class FUnvierDataValidationMixin extends FUniver {
|
|
4
4
|
/**
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
6
|
+
* @deprecated use `univerAPI.newDataValidation()` as instead.
|
|
7
7
|
*/
|
|
8
8
|
static newDataValidation(): FDataValidationBuilder;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new instance of FDataValidationBuilder
|
|
11
|
+
* @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const rule = FUnvier.newDataValidation();
|
|
15
|
+
* cell.setDataValidation(rule.requireValueInRange(range));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
9
18
|
newDataValidation(): FDataValidationBuilder;
|
|
10
19
|
_initialize(injector: Injector): void;
|
|
11
20
|
}
|
|
@@ -13,51 +13,35 @@ export interface IFWorkbookDataValidationMixin {
|
|
|
13
13
|
*/
|
|
14
14
|
getValidatorStatus(this: FWorkbook): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {function(IRuleChange): void} callback - Callback function that will be called when the event is fired
|
|
18
|
-
* @returns {IDisposable} A disposable object that can be used to unsubscribe from the event
|
|
16
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.SheetDataValidationChanged, (event) => { ... })` instead
|
|
19
17
|
*/
|
|
20
18
|
onDataValidationChange(callback: (ruleChange: IRuleChange) => void): IDisposable;
|
|
21
19
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param {function(IValidStatusChange): void} callback - Callback function that will be called when the event is fired
|
|
24
|
-
* @returns {IDisposable} A disposable object that can be used to unsubscribe from the event
|
|
20
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => { ... })` instead
|
|
25
21
|
*/
|
|
26
22
|
onDataValidationStatusChange(callback: (statusChange: IValidStatusChange) => void): IDisposable;
|
|
27
23
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param {function(IAddSheetDataValidationCommandParams, IExecutionOptions | undefined): void | false} callback - Callback function that will be called when the event is fired
|
|
30
|
-
* @returns {IDisposable} A disposable object that can be used to unsubscribe from the event
|
|
24
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => { ... })` instead
|
|
31
25
|
*/
|
|
32
26
|
onBeforeAddDataValidation(this: FWorkbook, callback: (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
33
27
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param callback - Callback function that will be called when the event is fired
|
|
36
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
28
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => { ... })` instead
|
|
37
29
|
*/
|
|
38
30
|
onBeforeUpdateDataValidationCriteria(this: FWorkbook, callback: (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
39
31
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param callback - Callback function that will be called when the event is fired
|
|
42
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
32
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => { ... })` instead
|
|
43
33
|
*/
|
|
44
34
|
onBeforeUpdateDataValidationRange(this: FWorkbook, callback: (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
45
35
|
/**
|
|
46
|
-
*
|
|
47
|
-
* @param callback - Callback function that will be called when the event is fired
|
|
48
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
36
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => { ... })` instead
|
|
49
37
|
*/
|
|
50
38
|
onBeforeUpdateDataValidationOptions(this: FWorkbook, callback: (params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
51
39
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param callback - Callback function that will be called when the event is fired
|
|
54
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
40
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => { ... })` instead
|
|
55
41
|
*/
|
|
56
42
|
onBeforeDeleteDataValidation(this: FWorkbook, callback: (params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
57
43
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @param callback - Callback function that will be called when the event is fired
|
|
60
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
44
|
+
* @deprecated Use `univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => { ... })` instead
|
|
61
45
|
*/
|
|
62
46
|
onBeforeDeleteAllDataValidation(this: FWorkbook, callback: (params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
63
47
|
}
|
|
@@ -4,7 +4,7 @@ import { FDataValidation } from './f-data-validation';
|
|
|
4
4
|
export interface IFWorksheetDataValidationMixin {
|
|
5
5
|
/**
|
|
6
6
|
* Get all data validation rules in current sheet.
|
|
7
|
-
* @returns all data validation rules
|
|
7
|
+
* @returns {FDataValidation[]} all data validation rules
|
|
8
8
|
* ```ts
|
|
9
9
|
* const workbook = univerAPI.getActiveWorkbook();
|
|
10
10
|
* const worksheet = workbook.getWorksheet('sheet1');
|
|
@@ -12,20 +12,24 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
getDataValidations(): FDataValidation[];
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use `getValidatorStatusAsync` instead
|
|
17
|
+
*/
|
|
18
|
+
getValidatorStatus(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
15
19
|
/**
|
|
16
20
|
* Get data validation validator status for current sheet.
|
|
17
|
-
* @returns matrix of validator status
|
|
21
|
+
* @returns {Promise<ObjectMatrix<Nullable<DataValidationStatus>>>} matrix of validator status
|
|
18
22
|
* ```ts
|
|
19
23
|
* const workbook = univerAPI.getActiveWorkbook();
|
|
20
24
|
* const worksheet = workbook.getWorksheet('sheet1');
|
|
21
25
|
* const validatorStatus = worksheet.getValidatorStatus();
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
|
-
|
|
28
|
+
getValidatorStatusAsync(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
25
29
|
/**
|
|
26
30
|
* get data validation rule by rule id
|
|
27
31
|
* @param ruleId - the rule id
|
|
28
|
-
* @returns data validation rule
|
|
32
|
+
* @returns {Nullable<FDataValidation>} data validation rule
|
|
29
33
|
* ```ts
|
|
30
34
|
* const workbook = univerAPI.getActiveWorkbook();
|
|
31
35
|
* const worksheet = workbook.getWorksheet('sheet1');
|
|
@@ -37,6 +41,7 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
37
41
|
export declare class FWorksheetDataValidationMixin extends FWorksheet implements IFWorksheetDataValidationMixin {
|
|
38
42
|
getDataValidations(): FDataValidation[];
|
|
39
43
|
getValidatorStatus(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
44
|
+
getValidatorStatusAsync(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
40
45
|
getDataValidation(ruleId: string): Nullable<FDataValidation>;
|
|
41
46
|
}
|
|
42
47
|
declare module '@univerjs/sheets/facade' {
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","rxjs"],i):(u=typeof globalThis<"u"?globalThis:u||self,i(u.UniverSheetsDataValidationFacade={},u.UniverSheetsDataValidation,u.UniverSheetsFacade,u.UniverCore,u.UniverDataValidation,u.UniverEngineFormula,u.rxjs))})(this,function(u,i,m,a,D,v,E){"use strict";var U=Object.defineProperty;var A=(u,i,m)=>i in u?U(u,i,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[i]=m;var S=(u,i,m)=>A(u,typeof i!="symbol"?i+"":i,m);class _{constructor(t){S(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new g(this._rule)}copy(){return new _({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${v.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setHelpText(t){return this._rule.error=t,this._rule.showErrorMessage=!0,this}withCriteriaValues(t,e){return this._rule.type=t,this._rule.operator=e[0],this._rule.formula1=e[1],this._rule.formula2=e[2],this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class g{constructor(t,e,r){S(this,"rule");S(this,"_worksheet");S(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new _(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(D.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(m.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...D.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(o=>o.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(i.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class w extends m.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(i.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(i.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(i.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new g(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(i.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new g(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}m.FRange.extend(w);class T extends a.FUniver{static newDataValidation(){return new _}newDataValidation(){return new _}_initialize(t){if(!t.has(i.SheetDataValidationModel))return;const e=t.get(i.SheetDataValidationModel),r=t.get(a.ICommandService);this.disposeWithMe(e.ruleChange$.subscribe(o=>{const{unitId:n,subUnitId:s,rule:p,oldRule:d,type:l}=o,h=this.getSheetTarget(n,s);if(!h)return;const{workbook:c,worksheet:V}=h,I=new g(p,V.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:o,worksheet:V,workbook:c,changeType:l,oldRule:d,rule:I})})),this.disposeWithMe(e.validStatusChange$.subscribe(o=>{const{unitId:n,subUnitId:s,ruleId:p,status:d,row:l,col:h}=o,c=this.getSheetTarget(n,s);if(!c)return;const{workbook:V,worksheet:I}=c,k=I.getDataValidation(p);k&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:V,worksheet:I,row:l,column:h,rule:k,status:d})})),this.disposeWithMe(r.beforeCommandExecuted(o=>{switch(o.id){case i.AddSheetDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l={worksheet:d,workbook:p,rule:n.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,l),l.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationSettingCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId,newCriteria:n.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationRangeCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId,newRanges:n.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationOptionsCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId,newOptions:n.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError;break}case i.RemoveSheetDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError;break}case i.RemoveSheetAllDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l={worksheet:d,workbook:p,rules:d.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,l),l.cancel)throw new a.CanceledError;break}}}))}}a.FUniver.extend(T);class b extends m.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(i.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(E.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(E.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.AddSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationSettingCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationRangeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationOptionsCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.RemoveSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}m.FWorkbook.extend(b);class y extends m.FWorksheet{getDataValidations(){return this._injector.get(D.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new g(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(t){const r=this._injector.get(D.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new g(r,this._worksheet,this._injector):null}}m.FWorksheet.extend(y);class C{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}a.FEventName.extend(C),u.FDataValidation=g,u.FDataValidationBuilder=_,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(u,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","rxjs"],i):(u=typeof globalThis<"u"?globalThis:u||self,i(u.UniverSheetsDataValidationFacade={},u.UniverSheetsDataValidation,u.UniverSheetsFacade,u.UniverCore,u.UniverDataValidation,u.UniverEngineFormula,u.rxjs))})(this,function(u,i,m,a,D,v,E){"use strict";var U=Object.defineProperty;var A=(u,i,m)=>i in u?U(u,i,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[i]=m;var S=(u,i,m)=>A(u,typeof i!="symbol"?i+"":i,m);class _{constructor(t){S(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new g(this._rule)}copy(){return new _({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${v.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class g{constructor(t,e,r){S(this,"rule");S(this,"_worksheet");S(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new _(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(D.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(m.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...D.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(o=>o.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(i.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class w extends m.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(i.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(i.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(i.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new g(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(i.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new g(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}m.FRange.extend(w);class T extends a.FUniver{static newDataValidation(){return new _}newDataValidation(){return new _}_initialize(t){if(!t.has(i.SheetDataValidationModel))return;const e=t.get(i.SheetDataValidationModel),r=t.get(a.ICommandService);this.disposeWithMe(e.ruleChange$.subscribe(o=>{const{unitId:n,subUnitId:s,rule:p,oldRule:l,type:d}=o,h=this.getSheetTarget(n,s);if(!h)return;const{workbook:c,worksheet:V}=h,I=new g(p,V.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:o,worksheet:V,workbook:c,changeType:d,oldRule:l,rule:I})})),this.disposeWithMe(e.validStatusChange$.subscribe(o=>{const{unitId:n,subUnitId:s,ruleId:p,status:l,row:d,col:h}=o,c=this.getSheetTarget(n,s);if(!c)return;const{workbook:V,worksheet:I}=c,k=I.getDataValidation(p);k&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:V,worksheet:I,row:d,column:h,rule:k,status:l})})),this.disposeWithMe(r.beforeCommandExecuted(o=>{switch(o.id){case i.AddSheetDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:l}=s,d={worksheet:l,workbook:p,rule:n.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,d),d.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationSettingCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:l}=s,d=l.getDataValidation(n.ruleId);if(!d)return;const h={worksheet:l,workbook:p,rule:d,ruleId:n.ruleId,newCriteria:n.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationRangeCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:l}=s,d=l.getDataValidation(n.ruleId);if(!d)return;const h={worksheet:l,workbook:p,rule:d,ruleId:n.ruleId,newRanges:n.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationOptionsCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:l}=s,d=l.getDataValidation(n.ruleId);if(!d)return;const h={worksheet:l,workbook:p,rule:d,ruleId:n.ruleId,newOptions:n.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError;break}case i.RemoveSheetDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:l}=s,d=l.getDataValidation(n.ruleId);if(!d)return;const h={worksheet:l,workbook:p,rule:d,ruleId:n.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError;break}case i.RemoveSheetAllDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:l}=s,d={worksheet:l,workbook:p,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,d),d.cancel)throw new a.CanceledError;break}}}))}}a.FUniver.extend(T);class b extends m.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(i.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(E.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(E.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.AddSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationSettingCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationRangeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationOptionsCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.RemoveSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}m.FWorkbook.extend(b);class y extends m.FWorksheet{getDataValidations(){return this._injector.get(D.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new g(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(t){const r=this._injector.get(D.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new g(r,this._worksheet,this._injector):null}}m.FWorksheet.extend(y);class C{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}a.FEventName.extend(C),u.FDataValidation=g,u.FDataValidationBuilder=_,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.5.4-nightly.
|
|
3
|
+
"version": "0.5.4-nightly.202501160647",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@univerjs/protocol": "0.1.40",
|
|
57
|
-
"@univerjs/core": "0.5.4-nightly.
|
|
58
|
-
"@univerjs/engine-formula": "0.5.4-nightly.
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/sheets-formula": "0.5.4-nightly.
|
|
57
|
+
"@univerjs/core": "0.5.4-nightly.202501160647",
|
|
58
|
+
"@univerjs/engine-formula": "0.5.4-nightly.202501160647",
|
|
59
|
+
"@univerjs/sheets": "0.5.4-nightly.202501160647",
|
|
60
|
+
"@univerjs/data-validation": "0.5.4-nightly.202501160647",
|
|
61
|
+
"@univerjs/sheets-formula": "0.5.4-nightly.202501160647"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"less": "^4.2.1",
|