@univerjs/sheets-data-validation 0.5.3 → 0.5.4
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 +247 -102
- package/lib/es/index.js +632 -632
- package/lib/types/facade/f-event.d.ts +269 -0
- package/lib/types/facade/f-range.d.ts +3 -3
- package/lib/types/facade/f-univer.d.ts +4 -1
- package/lib/types/facade/f-workbook.d.ts +17 -32
- package/lib/types/facade/f-worksheet.d.ts +24 -2
- package/lib/types/facade/index.d.ts +2 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { DataValidationStatus, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IEventBase, IRange, ISheetDataValidationRule } from '@univerjs/core';
|
|
2
|
+
import { DataValidationChangeType, IRuleChange } from '@univerjs/data-validation';
|
|
3
|
+
import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
|
|
4
|
+
import { FDataValidation } from './f-data-validation';
|
|
5
|
+
/**
|
|
6
|
+
* Event interface triggered when a data validation rule is changed
|
|
7
|
+
* @interface ISheetDataValidationChangedEvent
|
|
8
|
+
* @augments {IEventBase}
|
|
9
|
+
*/
|
|
10
|
+
export interface ISheetDataValidationChangedEvent extends IEventBase {
|
|
11
|
+
/** The source of the rule change */
|
|
12
|
+
origin: IRuleChange;
|
|
13
|
+
/** The worksheet containing the validation rule */
|
|
14
|
+
worksheet: FWorksheet;
|
|
15
|
+
/** The workbook instance */
|
|
16
|
+
workbook: FWorkbook;
|
|
17
|
+
/** Type of change made to the validation rule */
|
|
18
|
+
changeType: DataValidationChangeType;
|
|
19
|
+
/** The previous validation rule, if it exists */
|
|
20
|
+
oldRule?: IDataValidationRule;
|
|
21
|
+
/** The new or modified validation rule */
|
|
22
|
+
rule: FDataValidation;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Event interface triggered when a data validation status changes
|
|
26
|
+
* @interface ISheetDataValidatorStatusChangedEvent
|
|
27
|
+
* @augments {IEventBase}
|
|
28
|
+
*/
|
|
29
|
+
export interface ISheetDataValidatorStatusChangedEvent extends IEventBase {
|
|
30
|
+
/** The worksheet containing the validation */
|
|
31
|
+
worksheet: FWorksheet;
|
|
32
|
+
/** The workbook instance */
|
|
33
|
+
workbook: FWorkbook;
|
|
34
|
+
/** Row index of the validated cell */
|
|
35
|
+
row: number;
|
|
36
|
+
/** Column index of the validated cell */
|
|
37
|
+
column: number;
|
|
38
|
+
/** Current validation status */
|
|
39
|
+
status: DataValidationStatus;
|
|
40
|
+
/** The validation rule that was checked */
|
|
41
|
+
rule: FDataValidation;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Event interface triggered before adding a new data validation rule
|
|
45
|
+
* @interface IBeforeSheetDataValidationAddEvent
|
|
46
|
+
* @augments {IEventBase}
|
|
47
|
+
*/
|
|
48
|
+
export interface IBeforeSheetDataValidationAddEvent extends IEventBase {
|
|
49
|
+
/** The worksheet to add the validation to */
|
|
50
|
+
worksheet: FWorksheet;
|
|
51
|
+
/** The workbook instance */
|
|
52
|
+
workbook: FWorkbook;
|
|
53
|
+
/** The validation rule to be added */
|
|
54
|
+
rule: ISheetDataValidationRule;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Event interface triggered before deleting a data validation rule
|
|
58
|
+
* @interface IBeforeSheetDataValidationDeleteEvent
|
|
59
|
+
* @augments {IEventBase}
|
|
60
|
+
*/
|
|
61
|
+
export interface IBeforeSheetDataValidationDeleteEvent extends IEventBase {
|
|
62
|
+
/** The worksheet containing the validation */
|
|
63
|
+
worksheet: FWorksheet;
|
|
64
|
+
/** The workbook instance */
|
|
65
|
+
workbook: FWorkbook;
|
|
66
|
+
/** Unique identifier of the rule to be deleted */
|
|
67
|
+
ruleId: string;
|
|
68
|
+
/** The validation rule to be deleted */
|
|
69
|
+
rule: FDataValidation;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Event interface triggered before updating a data validation rule's criteria
|
|
73
|
+
* @interface IBeforeSheetDataValidationCriteriaUpdateEvent
|
|
74
|
+
* @augments {IEventBase}
|
|
75
|
+
*/
|
|
76
|
+
export interface IBeforeSheetDataValidationCriteriaUpdateEvent extends IEventBase {
|
|
77
|
+
/** The worksheet containing the validation */
|
|
78
|
+
worksheet: FWorksheet;
|
|
79
|
+
/** The workbook instance */
|
|
80
|
+
workbook: FWorkbook;
|
|
81
|
+
/** Unique identifier of the rule to be updated */
|
|
82
|
+
ruleId: string;
|
|
83
|
+
/** The current validation rule */
|
|
84
|
+
rule: FDataValidation;
|
|
85
|
+
/** The new criteria to be applied */
|
|
86
|
+
newCriteria: IDataValidationRuleBase;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Event interface triggered before updating a data validation rule's ranges
|
|
90
|
+
* @interface IBeforeSheetDataValidationRangeUpdateEvent
|
|
91
|
+
* @augments {IEventBase}
|
|
92
|
+
*/
|
|
93
|
+
export interface IBeforeSheetDataValidationRangeUpdateEvent extends IEventBase {
|
|
94
|
+
/** The worksheet containing the validation */
|
|
95
|
+
worksheet: FWorksheet;
|
|
96
|
+
/** The workbook instance */
|
|
97
|
+
workbook: FWorkbook;
|
|
98
|
+
/** Unique identifier of the rule to be updated */
|
|
99
|
+
ruleId: string;
|
|
100
|
+
/** The current validation rule */
|
|
101
|
+
rule: FDataValidation;
|
|
102
|
+
/** The new ranges to be applied */
|
|
103
|
+
newRanges: IRange[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Event interface triggered before updating a data validation rule's options
|
|
107
|
+
* @interface IBeforeSheetDataValidationOptionsUpdateEvent
|
|
108
|
+
* @augments {IEventBase}
|
|
109
|
+
*/
|
|
110
|
+
export interface IBeforeSheetDataValidationOptionsUpdateEvent extends IEventBase {
|
|
111
|
+
/** The worksheet containing the validation */
|
|
112
|
+
worksheet: FWorksheet;
|
|
113
|
+
/** The workbook instance */
|
|
114
|
+
workbook: FWorkbook;
|
|
115
|
+
/** Unique identifier of the rule to be updated */
|
|
116
|
+
ruleId: string;
|
|
117
|
+
/** The current validation rule */
|
|
118
|
+
rule: FDataValidation;
|
|
119
|
+
/** The new options to be applied */
|
|
120
|
+
newOptions: IDataValidationRuleOptions;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Event interface triggered before deleting all data validation rules
|
|
124
|
+
* @interface IBeforeSheetDataValidationDeleteAllEvent
|
|
125
|
+
* @augments {IEventBase}
|
|
126
|
+
*/
|
|
127
|
+
export interface IBeforeSheetDataValidationDeleteAllEvent extends IEventBase {
|
|
128
|
+
/** The worksheet containing the validations */
|
|
129
|
+
worksheet: FWorksheet;
|
|
130
|
+
/** The workbook instance */
|
|
131
|
+
workbook: FWorkbook;
|
|
132
|
+
/** Array of all validation rules to be deleted */
|
|
133
|
+
rules: FDataValidation[];
|
|
134
|
+
}
|
|
135
|
+
export interface IDataValidationEventParamConfig {
|
|
136
|
+
SheetDataValidationChanged: ISheetDataValidationChangedEvent;
|
|
137
|
+
SheetDataValidatorStatusChanged: ISheetDataValidatorStatusChangedEvent;
|
|
138
|
+
BeforeSheetDataValidationAdd: IBeforeSheetDataValidationAddEvent;
|
|
139
|
+
BeforeSheetDataValidationDelete: IBeforeSheetDataValidationDeleteEvent;
|
|
140
|
+
BeforeSheetDataValidationDeleteAll: IBeforeSheetDataValidationDeleteAllEvent;
|
|
141
|
+
BeforeSheetDataValidationCriteriaUpdate: IBeforeSheetDataValidationCriteriaUpdateEvent;
|
|
142
|
+
BeforeSheetDataValidationRangeUpdate: IBeforeSheetDataValidationRangeUpdateEvent;
|
|
143
|
+
BeforeSheetDataValidationOptionsUpdate: IBeforeSheetDataValidationOptionsUpdateEvent;
|
|
144
|
+
}
|
|
145
|
+
interface IDataValidationEvent {
|
|
146
|
+
/**
|
|
147
|
+
* Event fired when a rule is added, deleted, or modified
|
|
148
|
+
* @see {@link ISheetDataValidationChangedEvent}
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* univerAPI.on(univerAPI.Event.SheetDataValidationChanged, (event) => {
|
|
152
|
+
* const { worksheet, workbook, changeType, oldRule, rule } = event;
|
|
153
|
+
* console.log(event);
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
readonly SheetDataValidationChanged: 'SheetDataValidationChanged';
|
|
158
|
+
/**
|
|
159
|
+
* Event fired when a cell validator status is changed
|
|
160
|
+
* @see {@link ISheetDataValidatorStatusChangedEvent}
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* univerAPI.on(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => {
|
|
164
|
+
* const { worksheet, workbook, row, column, status, rule } = event;
|
|
165
|
+
* console.log(event);
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
readonly SheetDataValidatorStatusChanged: 'SheetDataValidatorStatusChanged';
|
|
170
|
+
/**
|
|
171
|
+
* Event fired before a rule is added
|
|
172
|
+
* @see {@link IBeforeSheetDataValidationAddEvent}
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => {
|
|
176
|
+
* const { worksheet, workbook, rule } = event;
|
|
177
|
+
* console.log(event);
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
readonly BeforeSheetDataValidationAdd: 'BeforeSheetDataValidationAdd';
|
|
182
|
+
/**
|
|
183
|
+
* Event fired before a rule is deleted
|
|
184
|
+
* @see {@link IBeforeSheetDataValidationDeleteEvent}
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => {
|
|
188
|
+
* const { worksheet, workbook, rule } = event;
|
|
189
|
+
* console.log(event);
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
readonly BeforeSheetDataValidationDelete: 'BeforeSheetDataValidationDelete';
|
|
194
|
+
/**
|
|
195
|
+
* Event fired before all rules are deleted
|
|
196
|
+
* @see {@link IBeforeSheetDataValidationDeleteAllEvent}
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => {
|
|
200
|
+
* const { worksheet, workbook, rules } = event;
|
|
201
|
+
* console.log(event);
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
readonly BeforeSheetDataValidationDeleteAll: 'BeforeSheetDataValidationDeleteAll';
|
|
206
|
+
/**
|
|
207
|
+
* Event fired before the criteria of a rule are updated
|
|
208
|
+
* @see {@link IBeforeSheetDataValidationCriteriaUpdateEvent}
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => {
|
|
212
|
+
* const { worksheet, workbook, rule, newCriteria } = event;
|
|
213
|
+
* console.log(event);
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
readonly BeforeSheetDataValidationCriteriaUpdate: 'BeforeSheetDataValidationCriteriaUpdate';
|
|
218
|
+
/**
|
|
219
|
+
* Event fired before the range of a rule is updated
|
|
220
|
+
* @see {@link IBeforeSheetDataValidationRangeUpdateEvent}
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => {
|
|
224
|
+
* const { worksheet, workbook, rule, newRanges } = event;
|
|
225
|
+
* console.log(event);
|
|
226
|
+
* });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
readonly BeforeSheetDataValidationRangeUpdate: 'BeforeSheetDataValidationRangeUpdate';
|
|
230
|
+
/**
|
|
231
|
+
* Event fired before the options of a rule are updated
|
|
232
|
+
* @see {@link IBeforeSheetDataValidationOptionsUpdateEvent}
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => {
|
|
236
|
+
* const { worksheet, workbook, rule, newOptions } = event;
|
|
237
|
+
* console.log(event);
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
readonly BeforeSheetDataValidationOptionsUpdate: 'BeforeSheetDataValidationOptionsUpdate';
|
|
242
|
+
}
|
|
243
|
+
export declare class FDataValidationEvent implements IDataValidationEvent {
|
|
244
|
+
get SheetDataValidationChanged(): 'SheetDataValidationChanged';
|
|
245
|
+
get SheetDataValidatorStatusChanged(): 'SheetDataValidatorStatusChanged';
|
|
246
|
+
get BeforeSheetDataValidationAdd(): 'BeforeSheetDataValidationAdd';
|
|
247
|
+
get BeforeSheetDataValidationDelete(): 'BeforeSheetDataValidationDelete';
|
|
248
|
+
get BeforeSheetDataValidationDeleteAll(): 'BeforeSheetDataValidationDeleteAll';
|
|
249
|
+
get BeforeSheetDataValidationCriteriaUpdate(): 'BeforeSheetDataValidationCriteriaUpdate';
|
|
250
|
+
get BeforeSheetDataValidationRangeUpdate(): 'BeforeSheetDataValidationRangeUpdate';
|
|
251
|
+
get BeforeSheetDataValidationOptionsUpdate(): 'BeforeSheetDataValidationOptionsUpdate';
|
|
252
|
+
}
|
|
253
|
+
export interface IDataValidationEventConfig {
|
|
254
|
+
SheetDataValidationChanged: ISheetDataValidationChangedEvent;
|
|
255
|
+
SheetDataValidatorStatusChanged: ISheetDataValidatorStatusChangedEvent;
|
|
256
|
+
BeforeSheetDataValidationAdd: IBeforeSheetDataValidationAddEvent;
|
|
257
|
+
BeforeSheetDataValidationDelete: IBeforeSheetDataValidationDeleteEvent;
|
|
258
|
+
BeforeSheetDataValidationDeleteAll: IBeforeSheetDataValidationDeleteAllEvent;
|
|
259
|
+
BeforeSheetDataValidationCriteriaUpdate: IBeforeSheetDataValidationCriteriaUpdateEvent;
|
|
260
|
+
BeforeSheetDataValidationRangeUpdate: IBeforeSheetDataValidationRangeUpdateEvent;
|
|
261
|
+
BeforeSheetDataValidationOptionsUpdate: IBeforeSheetDataValidationOptionsUpdateEvent;
|
|
262
|
+
}
|
|
263
|
+
declare module '@univerjs/core' {
|
|
264
|
+
interface FEventName extends IDataValidationEvent {
|
|
265
|
+
}
|
|
266
|
+
interface IEventParamConfig extends IDataValidationEventParamConfig {
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export {};
|
|
@@ -3,18 +3,18 @@ import { FRange } from '@univerjs/sheets/facade';
|
|
|
3
3
|
import { FDataValidation } from './f-data-validation';
|
|
4
4
|
export interface IFRangeDataValidationMixin {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Set a data validation rule to current range.
|
|
7
7
|
* @param rule data validation rule, build by `FUniver.newDataValidation`
|
|
8
8
|
* @returns current range
|
|
9
9
|
*/
|
|
10
10
|
setDataValidation(this: FRange, rule: Nullable<FDataValidation>): FRange;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Get first data validation rule in current range.
|
|
13
13
|
* @returns data validation rule
|
|
14
14
|
*/
|
|
15
15
|
getDataValidation(this: FRange): Nullable<FDataValidation>;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Get all data validation rules in current range.
|
|
18
18
|
* @returns all data validation rules
|
|
19
19
|
*/
|
|
20
20
|
getDataValidations(this: FRange): FDataValidation[];
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { Injector, FUniver } from '@univerjs/core';
|
|
1
2
|
import { FDataValidationBuilder } from './f-data-validation-builder';
|
|
2
|
-
export declare class FUnvierDataValidationMixin {
|
|
3
|
+
export declare class FUnvierDataValidationMixin extends FUniver {
|
|
4
|
+
/**
|
|
3
5
|
/**
|
|
4
6
|
* @deparecated use `univerAPI.newDataValidation()` as instead.
|
|
5
7
|
*/
|
|
6
8
|
static newDataValidation(): FDataValidationBuilder;
|
|
7
9
|
newDataValidation(): FDataValidationBuilder;
|
|
10
|
+
_initialize(injector: Injector): void;
|
|
8
11
|
}
|
|
9
12
|
declare module '@univerjs/core' {
|
|
10
13
|
namespace FUniver {
|
|
@@ -4,55 +4,59 @@ import { DataValidationStatus, IDisposable, IExecutionOptions, Nullable, ObjectM
|
|
|
4
4
|
import { FWorkbook } from '@univerjs/sheets/facade';
|
|
5
5
|
export interface IFWorkbookDataValidationMixin {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @returns matrix of validator status
|
|
7
|
+
* Get data validation validator status for current workbook.
|
|
8
|
+
* @returns A promise that resolves to a matrix of validator status.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* univerAPI.getActiveWorkbook().getValidatorStatus().then((status) => { console.log(status) })
|
|
12
|
+
* ```
|
|
9
13
|
*/
|
|
10
14
|
getValidatorStatus(this: FWorkbook): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>;
|
|
11
15
|
/**
|
|
12
16
|
* The onDataValidationChange event is fired when the data validation rule of this sheet is changed.
|
|
13
|
-
* @param callback Callback function that will be called when the event is fired
|
|
14
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
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
|
|
15
19
|
*/
|
|
16
20
|
onDataValidationChange(callback: (ruleChange: IRuleChange) => void): IDisposable;
|
|
17
21
|
/**
|
|
18
22
|
* The onDataValidationStatusChange event is fired when the data validation status of this sheet is changed.
|
|
19
|
-
* @param callback Callback function that will be called when the event is fired
|
|
20
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
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
|
|
21
25
|
*/
|
|
22
26
|
onDataValidationStatusChange(callback: (statusChange: IValidStatusChange) => void): IDisposable;
|
|
23
27
|
/**
|
|
24
28
|
* The onBeforeAddDataValidation event is fired before the data validation rule is added.
|
|
25
|
-
* @param callback Callback function that will be called when the event is fired
|
|
26
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
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
|
|
27
31
|
*/
|
|
28
32
|
onBeforeAddDataValidation(this: FWorkbook, callback: (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
29
33
|
/**
|
|
30
34
|
* The onBeforeUpdateDataValidationCriteria event is fired before the data validation rule is updated.
|
|
31
|
-
* @param callback Callback function that will be called when the event is fired
|
|
35
|
+
* @param callback - Callback function that will be called when the event is fired
|
|
32
36
|
* @returns A disposable object that can be used to unsubscribe from the event
|
|
33
37
|
*/
|
|
34
38
|
onBeforeUpdateDataValidationCriteria(this: FWorkbook, callback: (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
35
39
|
/**
|
|
36
40
|
* The onBeforeUpdateDataValidationRange event is fired before the data validation rule is updated.
|
|
37
|
-
* @param callback Callback function that will be called when the event is fired
|
|
41
|
+
* @param callback - Callback function that will be called when the event is fired
|
|
38
42
|
* @returns A disposable object that can be used to unsubscribe from the event
|
|
39
43
|
*/
|
|
40
44
|
onBeforeUpdateDataValidationRange(this: FWorkbook, callback: (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
41
45
|
/**
|
|
42
46
|
* The onBeforeUpdateDataValidationOptions event is fired before the data validation rule is updated.
|
|
43
|
-
* @param callback Callback function that will be called when the event is fired
|
|
47
|
+
* @param callback - Callback function that will be called when the event is fired
|
|
44
48
|
* @returns A disposable object that can be used to unsubscribe from the event
|
|
45
49
|
*/
|
|
46
50
|
onBeforeUpdateDataValidationOptions(this: FWorkbook, callback: (params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
47
51
|
/**
|
|
48
52
|
* The onBeforeDeleteDataValidation event is fired before the data validation rule is deleted.
|
|
49
|
-
* @param callback Callback function that will be called when the event is fired
|
|
53
|
+
* @param callback - Callback function that will be called when the event is fired
|
|
50
54
|
* @returns A disposable object that can be used to unsubscribe from the event
|
|
51
55
|
*/
|
|
52
56
|
onBeforeDeleteDataValidation(this: FWorkbook, callback: (params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
53
57
|
/**
|
|
54
58
|
* The onBeforeDeleteAllDataValidation event is fired before delete all data validation rules.
|
|
55
|
-
* @param callback Callback function that will be called when the event is fired
|
|
59
|
+
* @param callback - Callback function that will be called when the event is fired
|
|
56
60
|
* @returns A disposable object that can be used to unsubscribe from the event
|
|
57
61
|
*/
|
|
58
62
|
onBeforeDeleteAllDataValidation(this: FWorkbook, callback: (params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
@@ -60,28 +64,9 @@ export interface IFWorkbookDataValidationMixin {
|
|
|
60
64
|
export declare class FWorkbookDataValidationMixin extends FWorkbook implements IFWorkbookDataValidationMixin {
|
|
61
65
|
_dataValidationModel: SheetDataValidationModel;
|
|
62
66
|
_initialize(): void;
|
|
63
|
-
/**
|
|
64
|
-
* get data validation validator status for current workbook
|
|
65
|
-
* @returns matrix of validator status
|
|
66
|
-
*/
|
|
67
67
|
getValidatorStatus(): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>;
|
|
68
|
-
/**
|
|
69
|
-
* The onDataValidationChange event is fired when the data validation rule of this sheet is changed.
|
|
70
|
-
* @param callback Callback function that will be called when the event is fired
|
|
71
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
72
|
-
*/
|
|
73
68
|
onDataValidationChange(callback: (ruleChange: IRuleChange) => void): IDisposable;
|
|
74
|
-
/**
|
|
75
|
-
* The onDataValidationStatusChange event is fired when the data validation status of this sheet is changed.
|
|
76
|
-
* @param callback Callback function that will be called when the event is fired
|
|
77
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
78
|
-
*/
|
|
79
69
|
onDataValidationStatusChange(callback: (statusChange: IValidStatusChange) => void): IDisposable;
|
|
80
|
-
/**
|
|
81
|
-
* The onBeforeAddDataValidation event is fired before the data validation rule is added.
|
|
82
|
-
* @param callback Callback function that will be called when the event is fired
|
|
83
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
84
|
-
*/
|
|
85
70
|
onBeforeAddDataValidation(callback: (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
86
71
|
onBeforeUpdateDataValidationCriteria(callback: (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
87
72
|
onBeforeUpdateDataValidationRange(callback: (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
@@ -3,19 +3,41 @@ import { FWorksheet } from '@univerjs/sheets/facade';
|
|
|
3
3
|
import { FDataValidation } from './f-data-validation';
|
|
4
4
|
export interface IFWorksheetDataValidationMixin {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Get all data validation rules in current sheet.
|
|
7
7
|
* @returns all data validation rules
|
|
8
|
+
* ```ts
|
|
9
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
10
|
+
* const worksheet = workbook.getWorksheet('sheet1');
|
|
11
|
+
* const dataValidations = worksheet.getDataValidations();
|
|
12
|
+
* ```
|
|
8
13
|
*/
|
|
9
14
|
getDataValidations(): FDataValidation[];
|
|
10
15
|
/**
|
|
11
|
-
*
|
|
16
|
+
* Get data validation validator status for current sheet.
|
|
12
17
|
* @returns matrix of validator status
|
|
18
|
+
* ```ts
|
|
19
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
20
|
+
* const worksheet = workbook.getWorksheet('sheet1');
|
|
21
|
+
* const validatorStatus = worksheet.getValidatorStatus();
|
|
22
|
+
* ```
|
|
13
23
|
*/
|
|
14
24
|
getValidatorStatus(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
25
|
+
/**
|
|
26
|
+
* get data validation rule by rule id
|
|
27
|
+
* @param ruleId - the rule id
|
|
28
|
+
* @returns data validation rule
|
|
29
|
+
* ```ts
|
|
30
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
31
|
+
* const worksheet = workbook.getWorksheet('sheet1');
|
|
32
|
+
* const dataValidation = worksheet.getDataValidation('ruleId');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
getDataValidation(ruleId: string): Nullable<FDataValidation>;
|
|
15
36
|
}
|
|
16
37
|
export declare class FWorksheetDataValidationMixin extends FWorksheet implements IFWorksheetDataValidationMixin {
|
|
17
38
|
getDataValidations(): FDataValidation[];
|
|
18
39
|
getValidatorStatus(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
40
|
+
getDataValidation(ruleId: string): Nullable<FDataValidation>;
|
|
19
41
|
}
|
|
20
42
|
declare module '@univerjs/sheets/facade' {
|
|
21
43
|
interface FWorksheet extends IFWorksheetDataValidationMixin {
|
|
@@ -17,8 +17,10 @@ import './f-range';
|
|
|
17
17
|
import './f-univer';
|
|
18
18
|
import './f-workbook';
|
|
19
19
|
import './f-worksheet';
|
|
20
|
+
import './f-event';
|
|
20
21
|
export { FDataValidation } from './f-data-validation';
|
|
21
22
|
export { FDataValidationBuilder } from './f-data-validation-builder';
|
|
23
|
+
export type * from './f-event';
|
|
22
24
|
export type * from './f-range';
|
|
23
25
|
export type * from './f-univer';
|
|
24
26
|
export type * from './f-workbook';
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n.UniverSheetsDataValidationFacade={},n.UniverSheetsDataValidation,n.UniverSheetsFacade,n.UniverCore,n.UniverDataValidation,n.UniverEngineFormula,n.rxjs))})(this,function(n,a,s,i,_,p,m){"use strict";var V=Object.defineProperty;var E=(n,a,s)=>a in n?V(n,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[a]=s;var d=(n,a,s)=>E(n,typeof a!="symbol"?a+"":a,s);class l{constructor(t){d(this,"_rule");this._rule=t!=null?t:{uid:i.generateRandomId(),ranges:void 0,type:i.DataValidationType.CUSTOM}}build(){return new u(this._rule)}copy(){return new l({...this._rule,uid:i.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==i.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=i.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=i.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=i.DataValidationOperator.BETWEEN,this._rule.type=r?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.NOT_EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?i.DataValidationType.LIST_MULTIPLE:i.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?i.DataValidationType.LIST_MULTIPLE:i.DataValidationType.LIST,this._rule.formula1=`=${p.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?i.DataValidationErrorStyle.WARNING:i.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 u{constructor(t,e,r){d(this,"rule");d(this,"_worksheet");d(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==i.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 l(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(_.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(i.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(s.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(i.ICommandService).syncExecuteCommand(a.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(i.ICommandService).syncExecuteCommand(a.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{..._.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(i.ICommandService).syncExecuteCommand(a.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(i.ICommandService).syncExecuteCommand(a.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class g extends s.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(a.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(a.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(a.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new u(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(a.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new u(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(a.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}s.FRange.extend(g);class D{static newDataValidation(){return new l}newDataValidation(){return new l}}i.FUniver.extend(D);class f extends s.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(a.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(a.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return i.toDisposable(this._dataValidationModel.ruleChange$.pipe(m.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return i.toDisposable(this._dataValidationModel.validStatusChange$.pipe(m.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.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 i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.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 i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.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 i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.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 i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.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 i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}s.FWorkbook.extend(f);class S extends s.FWorksheet{getDataValidations(){return this._injector.get(_.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new u(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(a.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}}s.FWorksheet.extend(S),n.FDataValidation=u,n.FDataValidationBuilder=l,Object.defineProperty(n,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}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"})});
|