@univerjs/sheets-data-validation 0.4.2 → 0.5.0-alpha.0

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.
@@ -0,0 +1,247 @@
1
+ import { IDataValidationRule, IDataValidationRuleOptions, DataValidationOperator, DataValidationType } from '@univerjs/core';
2
+ import { FRange } from '@univerjs/sheets/facade';
3
+ import { FDataValidation } from './f-data-validation';
4
+ /**
5
+ * Builder for data validation rules.
6
+ *
7
+ * Set the data validation for cell A1 to require a value from B1:B10.
8
+ * var rule = FUniver.newDataValidation().requireValueInRange(range).build();
9
+ * cell.setDataValidation(rule);
10
+ */
11
+ export declare class FDataValidationBuilder {
12
+ private _rule;
13
+ constructor(rule?: IDataValidationRule);
14
+ /**
15
+ * Builds an FDataValidation instance based on the _rule property of the current class
16
+ *
17
+ * @returns {FDataValidation} A new instance of the FDataValidation class
18
+ */
19
+ build(): FDataValidation;
20
+ /**
21
+ * Creates a duplicate of the current DataValidationBuilder object
22
+ *
23
+ * @return {FDataValidationBuilder} A new instance of the DataValidationBuilder class
24
+ */
25
+ copy(): FDataValidationBuilder;
26
+ /**
27
+ * Determines whether invalid data is allowed
28
+ *
29
+ * @returns {boolean} True if invalid data is allowed, False otherwise
30
+ */
31
+ getAllowInvalid(): boolean;
32
+ /**
33
+ * Gets the data validation type of the rule
34
+ *
35
+ * @returns {DataValidationType} The data validation type
36
+ */
37
+ getCriteriaType(): DataValidationType;
38
+ /**
39
+ * Gets the values used for criteria evaluation
40
+ *
41
+ * @returns {any[]} An array containing the operator, formula1, and formula2 values
42
+ */
43
+ getCriteriaValues(): any[];
44
+ /**
45
+ * Gets the help text information, which is used to provide users with guidance and support
46
+ *
47
+ * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value.
48
+ */
49
+ getHelpText(): string | undefined;
50
+ /**
51
+ * Sets the data validation type to CHECKBOX and sets the checked and unchecked values
52
+ *
53
+ * @param checkedValue The value when the checkbox is checked (Optional)
54
+ * @param uncheckedValue The value when the checkbox is unchecked (Optional)
55
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining
56
+ */
57
+ requireCheckbox(checkedValue?: string, uncheckedValue?: string): FDataValidationBuilder;
58
+ /**
59
+ * Set the data validation type to DATE and configure the validation rules to be after a specific date
60
+ *
61
+ * @param date The date to compare against. The formatted date string will be set as formula1
62
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
63
+ */
64
+ requireDateAfter(date: Date): FDataValidationBuilder;
65
+ /**
66
+ * Set the data validation type to DATE and configure the validation rules to be before a specific date
67
+ *
68
+ * @param date The date to compare against. The formatted date string will be set as formula1
69
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
70
+ */
71
+ requireDateBefore(date: Date): FDataValidationBuilder;
72
+ /**
73
+ * Set the data validation type to DATE and configure the validation rules to be within a specific date range
74
+ *
75
+ * @param start The starting date of the range. The formatted date string will be set as formula1
76
+ * @param end The ending date of the range. The formatted date string will be set as formula2
77
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
78
+ */
79
+ requireDateBetween(start: Date, end: Date): FDataValidationBuilder;
80
+ /**
81
+ * Set the data validation type to DATE and configure the validation rules to be equal to a specific date
82
+ *
83
+ * @param date The date to compare against. The formatted date string will be set as formula1
84
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
85
+ */
86
+ requireDateEqualTo(date: Date): FDataValidationBuilder;
87
+ /**
88
+ * Set the data validation type to DATE and configure the validation rules to be not within a specific date range
89
+ *
90
+ * @param start The starting date of the date range
91
+ * @param end The ending date of the date range
92
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
93
+ */
94
+ requireDateNotBetween(start: Date, end: Date): FDataValidationBuilder;
95
+ /**
96
+ * Set the data validation type to DATE and configure the validation rules to be on or after a specific date
97
+ *
98
+ * @param date The date to compare against. The formatted date string will be set as formula1
99
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
100
+ */
101
+ requireDateOnOrAfter(date: Date): FDataValidationBuilder;
102
+ /**
103
+ * Set the data validation type to DATE and configure the validation rules to be on or before a specific date
104
+ *
105
+ * @param date The date to compare against. The formatted date string will be set as formula1
106
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
107
+ */
108
+ requireDateOnOrBefore(date: Date): FDataValidationBuilder;
109
+ /**
110
+ * Requires that a custom formula be satisfied.
111
+ * Sets the data validation type to CUSTOM and configures the validation rule based on the provided formula string.
112
+ *
113
+ * @param formula The formula string that needs to be satisfied.
114
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
115
+ */
116
+ requireFormulaSatisfied(formula: string): FDataValidationBuilder;
117
+ /**
118
+ * Requires the user to enter a number within a specific range, which can be integer or decimal.
119
+ * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number range.
120
+ *
121
+ * @param start The starting value of the number range.
122
+ * @param end The ending value of the number range.
123
+ * @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or decimal.
124
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
125
+ */
126
+ requireNumberBetween(start: number, end: number, isInteger?: boolean): FDataValidationBuilder;
127
+ /**
128
+ * Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal.
129
+ * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
130
+ *
131
+ * @param num The number to which the entered number should be equal.
132
+ * @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
133
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
134
+ */
135
+ requireNumberEqualTo(num: number, isInteger?: boolean): FDataValidationBuilder;
136
+ /**
137
+ * Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal.
138
+ * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
139
+ *
140
+ * @param num The number to which the entered number should be greater.
141
+ * @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
142
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
143
+ */
144
+ requireNumberGreaterThan(num: number, isInteger?: boolean): FDataValidationBuilder;
145
+ /**
146
+ * Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal.
147
+ * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
148
+ *
149
+ * @param num The number to which the entered number should be greater than or equal.
150
+ * @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
151
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
152
+ */
153
+ requireNumberGreaterThanOrEqualTo(num: number, isInteger?: boolean): FDataValidationBuilder;
154
+ /**
155
+ * Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal.
156
+ * Sets the data validation type based on the isInteger parameter and configures the validation rules for the specified number.
157
+ *
158
+ * @param num The number to which the entered number should be less.
159
+ * @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal.
160
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
161
+ */
162
+ requireNumberLessThan(num: number, isInteger?: boolean): FDataValidationBuilder;
163
+ /**
164
+ * Sets the data validation rule to require a number less than or equal to a specified value
165
+ * The specified value can be an integer or a decimal
166
+ *
167
+ * @param num The number to which the entered number should be less than or equal
168
+ * @param isInteger Indicates whether the required number is an integer
169
+ * @return The current instance of the DataValidationBuilder class, allowing for method chaining
170
+ */
171
+ requireNumberLessThanOrEqualTo(num: number, isInteger?: boolean): FDataValidationBuilder;
172
+ /**
173
+ * Sets a data validation rule that requires the user to enter a number outside a specified range
174
+ * The specified range includes all integers and decimals
175
+ *
176
+ * @param start The starting point of the specified range
177
+ * @param end The end point of the specified range
178
+ * @param isInteger Optional parameter, indicating whether the number to be verified is an integer. Default value is false
179
+ * @return An instance of the FDataValidationBuilder class, allowing for method chaining
180
+ */
181
+ requireNumberNotBetween(start: number, end: number, isInteger?: boolean): FDataValidationBuilder;
182
+ /**
183
+ * Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
184
+ * The specific value can be an integer or a decimal
185
+ *
186
+ * @param num The number to which the entered number should not be equal
187
+ * @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or a decimal
188
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining
189
+ */
190
+ requireNumberNotEqualTo(num: number, isInteger?: boolean): FDataValidationBuilder;
191
+ /**
192
+ * Sets a data validation rule that requires the user to enter a value from a list of specific values.
193
+ * The list can be displayed in a dropdown, and the user can choose multiple values according to the settings.
194
+ *
195
+ * @param values An array containing the specific values that the user can enter.
196
+ * @param multiple Optional parameter indicating whether the user can select multiple values. Default is false, meaning only one value can be selected.
197
+ * @param showDropdown Optional parameter indicating whether to display the list in a dropdown. Default is true, meaning the list will be displayed as a dropdown.
198
+ * @return An instance of the FDataValidationBuilder class, allowing for method chaining.
199
+ */
200
+ requireValueInList(values: string[], multiple?: boolean, showDropdown?: boolean): FDataValidationBuilder;
201
+ /**
202
+ * Sets a data validation rule that requires the user to enter a value within a specific range.
203
+ * The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range.
204
+ *
205
+ * @param range An FRange object representing the range of values that the user can enter.
206
+ * @param multiple Optional parameter indicating whether the user can select multiple values. Default is false, meaning only one value can be selected.
207
+ * @param showDropdown Optional parameter indicating whether to display the list in a dropdown. Default is true, meaning the list will be displayed as a dropdown.
208
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
209
+ */
210
+ requireValueInRange(range: FRange, multiple?: boolean, showDropdown?: boolean): FDataValidationBuilder;
211
+ /**
212
+ * Sets whether to allow invalid data and configures the error style for data validation.
213
+ * If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error.
214
+ * If invalid data is allowed, the error style will be set to WARNING, indicating that a warning will be displayed when invalid data is entered, but data entry can continue.
215
+ *
216
+ * @param allowInvalidData A boolean value indicating whether to allow invalid data.
217
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
218
+ */
219
+ setAllowInvalid(allowInvalidData: boolean): FDataValidationBuilder;
220
+ /**
221
+ * Sets the help text and enables the display of error messages for data validation.
222
+ * This method allows you to set a custom help text that will be displayed when the user enters invalid data.
223
+ *
224
+ * @param helpText The text to display as help information.
225
+ * @return The current instance of the FDataValidationBuilder class to allow for method chaining.
226
+ */
227
+ setHelpText(helpText: string): FDataValidationBuilder;
228
+ /**
229
+ * Sets the criteria values for data validation.
230
+ * This method is used to configure the validation rules based on specific criteria values.
231
+ *
232
+ * @param type The type of data validation.
233
+ * @param values An array containing the criteria values.
234
+ * The array should have three elements: [operator, formula1, formula2].
235
+ * operator is a DataValidationOperator enum value, formula1 is the first formula, and formula2 is the second formula.
236
+ * @return The current instance of the FDataValidationBuilder class, allowing for method chaining.
237
+ */
238
+ withCriteriaValues(type: DataValidationType, values: [DataValidationOperator, string, string]): this;
239
+ /**
240
+ * Sets the options for the data validation rule.
241
+ * For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
242
+ *
243
+ * @param options The options to set for the data validation rule.
244
+ * @returns The current instance of the FDataValidationBuilder class to allow for method chaining.
245
+ */
246
+ setOptions(options: Partial<IDataValidationRuleOptions>): this;
247
+ }
@@ -0,0 +1,88 @@
1
+ import { DataValidationOperator, DataValidationType, IDataValidationRule, IDataValidationRuleOptions } from '@univerjs/core';
2
+ import { FWorksheet, FRange } from '@univerjs/sheets/facade';
3
+ import { FDataValidationBuilder } from './f-data-validation-builder';
4
+ export declare class FDataValidation {
5
+ rule: IDataValidationRule;
6
+ private _worksheet;
7
+ constructor(rule: IDataValidationRule, worksheet?: FWorksheet);
8
+ /**
9
+ * Gets whether invalid data is allowed based on the error style value.
10
+ *
11
+ * @return true if invalid data is allowed, false otherwise.
12
+ */
13
+ getAllowInvalid(): boolean;
14
+ /**
15
+ * Gets the data validation type of the rule
16
+ *
17
+ * @returns The data validation type
18
+ */
19
+ getCriteriaType(): DataValidationType;
20
+ /**
21
+ * Gets the values used for criteria evaluation
22
+ *
23
+ * @returns An array containing the operator, formula1, and formula2 values
24
+ */
25
+ getCriteriaValues(): (string | undefined)[];
26
+ /**
27
+ * Gets the help text information, which is used to provide users with guidance and support
28
+ *
29
+ * @returns Returns the help text information. If there is no error message, it returns an undefined value.
30
+ */
31
+ getHelpText(): string | undefined;
32
+ /**
33
+ * Creates a new instance of FDataValidationBuilder using the current rule object.
34
+ * This method is useful for copying an existing data validation rule configuration.
35
+ *
36
+ * @return A new FDataValidationBuilder instance with the same rule configuration.
37
+ */
38
+ copy(): FDataValidationBuilder;
39
+ /**
40
+ * Gets whether the data validation rule is applied to the worksheet.
41
+ *
42
+ * @returns true if the rule is applied, false otherwise.
43
+ */
44
+ getApplied(): boolean;
45
+ /**
46
+ * Gets the ranges to which the data validation rule is applied.
47
+ *
48
+ * @returns An array of IRange objects representing the ranges to which the data validation rule is applied.
49
+ */
50
+ getRanges(): FRange[];
51
+ /**
52
+ * Gets the title of the error message dialog box.
53
+ *
54
+ * @returns The title of the error message dialog box.
55
+ */
56
+ getUnitId(): string | undefined;
57
+ /**
58
+ * Gets the sheetId of the worksheet.
59
+ *
60
+ * @returns The sheetId of the worksheet.
61
+ */
62
+ getSheetId(): string | undefined;
63
+ /**
64
+ * Set Criteria for the data validation rule.
65
+ * @param type The type of data validation criteria.
66
+ * @param values An array containing the operator, formula1, and formula2 values.
67
+ * @returns true if the criteria is set successfully, false otherwise.
68
+ */
69
+ setCriteria(type: DataValidationType, values: [DataValidationOperator, string, string]): boolean;
70
+ /**
71
+ * Set the options for the data validation rule.
72
+ * For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
73
+ * @param options An object containing the options to set. `IDataValidationRuleOptions`
74
+ * @returns true if the options are set successfully, false otherwise.
75
+ */
76
+ setOptions(options: Partial<IDataValidationRuleOptions>): boolean;
77
+ /**
78
+ * Set the ranges to the data validation rule.
79
+ * @param ranges new ranges array.
80
+ * @returns true if the ranges are set successfully, false otherwise.
81
+ */
82
+ setRanges(ranges: FRange[]): boolean;
83
+ /**
84
+ * Delete the data validation rule from the worksheet.
85
+ * @returns true if the rule is deleted successfully, false otherwise.
86
+ */
87
+ delete(): boolean;
88
+ }
@@ -0,0 +1,33 @@
1
+ import { DataValidationStatus, Nullable } from '@univerjs/core';
2
+ import { FRange } from '@univerjs/sheets/facade';
3
+ import { FDataValidation } from './f-data-validation';
4
+ interface IFRangeDataValidationMixin {
5
+ /**
6
+ * set a data validation rule to current range
7
+ * @param rule data validation rule, build by `FUniver.newDataValidation`
8
+ * @returns current range
9
+ */
10
+ setDataValidation(this: FRange, rule: Nullable<FDataValidation>): Promise<FRange>;
11
+ /**
12
+ * get first data validation rule in current range
13
+ * @returns data validation rule
14
+ */
15
+ getDataValidation(this: FRange): Nullable<FDataValidation>;
16
+ /**
17
+ * get all data validation rules in current range
18
+ * @returns all data validation rules
19
+ */
20
+ getDataValidations(this: FRange): FDataValidation[];
21
+ getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]>;
22
+ }
23
+ export declare class FRangeDataValidationMixin extends FRange implements IFRangeDataValidationMixin {
24
+ setDataValidation(rule: Nullable<FDataValidation>): Promise<FRange>;
25
+ getDataValidation(): Nullable<FDataValidation>;
26
+ getDataValidations(): FDataValidation[];
27
+ getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]>;
28
+ }
29
+ declare module '@univerjs/sheets/facade' {
30
+ interface FRange extends IFRangeDataValidationMixin {
31
+ }
32
+ }
33
+ export {};
@@ -0,0 +1,6 @@
1
+ import { FDataValidationBuilder } from './f-data-validation-builder';
2
+ declare module '@univerjs/core' {
3
+ namespace FUniver {
4
+ function newDataValidation(): FDataValidationBuilder;
5
+ }
6
+ }
@@ -0,0 +1,64 @@
1
+ import { IRuleChange } from '@univerjs/data-validation';
2
+ import { IAddSheetDataValidationCommandParams, IDataValidationResCache, IRemoveSheetAllDataValidationCommandParams, IRemoveSheetDataValidationCommandParams, IUpdateSheetDataValidationOptionsCommandParams, IUpdateSheetDataValidationRangeCommandParams, IUpdateSheetDataValidationSettingCommandParams, IValidStatusChange } from '@univerjs/sheets-data-validation';
3
+ import { IDisposable, IExecutionOptions, Nullable, ObjectMatrix } from '@univerjs/core';
4
+ import { FWorkbook } from '@univerjs/sheets/facade';
5
+ interface IFWorkbookDataValidationMixin {
6
+ /**
7
+ * get data validation validator status for current workbook
8
+ * @returns matrix of validator status
9
+ */
10
+ getValidatorStatus(this: FWorkbook): Promise<Record<string, ObjectMatrix<Nullable<IDataValidationResCache>>>>;
11
+ /**
12
+ * 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
15
+ */
16
+ onDataValidationChange(callback: (ruleChange: IRuleChange) => void): IDisposable;
17
+ /**
18
+ * 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
21
+ */
22
+ onDataValidationStatusChange(callback: (statusChange: IValidStatusChange) => void): IDisposable;
23
+ /**
24
+ * 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
27
+ */
28
+ onBeforeAddDataValidation(this: FWorkbook, callback: (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
29
+ /**
30
+ * 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
32
+ * @returns A disposable object that can be used to unsubscribe from the event
33
+ */
34
+ onBeforeUpdateDataValidationCriteria(this: FWorkbook, callback: (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
35
+ /**
36
+ * 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
38
+ * @returns A disposable object that can be used to unsubscribe from the event
39
+ */
40
+ onBeforeUpdateDataValidationRange(this: FWorkbook, callback: (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
41
+ /**
42
+ * 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
44
+ * @returns A disposable object that can be used to unsubscribe from the event
45
+ */
46
+ onBeforeUpdateDataValidationOptions(this: FWorkbook, callback: (params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
47
+ /**
48
+ * 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
50
+ * @returns A disposable object that can be used to unsubscribe from the event
51
+ */
52
+ onBeforeDeleteDataValidation(this: FWorkbook, callback: (params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
53
+ /**
54
+ * 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
56
+ * @returns A disposable object that can be used to unsubscribe from the event
57
+ */
58
+ onBeforeDeleteAllDataValidation(this: FWorkbook, callback: (params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
59
+ }
60
+ declare module '@univerjs/sheets/facade' {
61
+ interface FWorkbook extends IFWorkbookDataValidationMixin {
62
+ }
63
+ }
64
+ export {};
@@ -0,0 +1,20 @@
1
+ import { Nullable, ObjectMatrix } from '@univerjs/core';
2
+ import { IDataValidationResCache } from '@univerjs/sheets-data-validation';
3
+ import { FDataValidation } from './f-data-validation';
4
+ interface IFWorksheetDataValidationMixin {
5
+ /**
6
+ * get all data validation rules in current sheet
7
+ * @returns all data validation rules
8
+ */
9
+ getDataValidations(): FDataValidation[];
10
+ /**
11
+ * get data validation validator status for current sheet
12
+ * @returns matrix of validator status
13
+ */
14
+ getValidatorStatus(): Promise<ObjectMatrix<Nullable<IDataValidationResCache>>>;
15
+ }
16
+ declare module '@univerjs/sheets/facade' {
17
+ interface FWorksheet extends IFWorksheetDataValidationMixin {
18
+ }
19
+ }
20
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import './f-range';
17
+ import './f-univer';
18
+ import './f-workbook';
19
+ import './f-worksheet';
20
+ export { FDataValidation } from './f-data-validation';
21
+ export { FDataValidationBuilder } from './f-data-validation-builder';
@@ -1,6 +1,5 @@
1
- import { IRange, ISheetDataValidationRule, Disposable, Injector, IUniverInstanceService } from '@univerjs/core';
1
+ import { ISheetDataValidationRule, Disposable, IUniverInstanceService } from '@univerjs/core';
2
2
  import { DataValidationModel } from '@univerjs/data-validation';
3
- import { LexerTreeBuilder } from '@univerjs/engine-formula';
4
3
  import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';
5
4
  import { DataValidationCacheService } from './dv-cache.service';
6
5
  interface IFormulaData {
@@ -8,34 +7,25 @@ interface IFormulaData {
8
7
  originRow: number;
9
8
  originCol: number;
10
9
  isTransformable: boolean;
11
- formulaId?: string;
10
+ formulaId: string;
12
11
  }
13
12
  export declare class DataValidationCustomFormulaService extends Disposable {
14
13
  private readonly _instanceSrv;
15
14
  private _registerOtherFormulaService;
16
- private _lexerTreeBuilder;
17
15
  private readonly _dataValidationModel;
18
16
  private readonly _dataValidationCacheService;
19
- private readonly _injector;
20
- private _formulaMap;
21
17
  /**
22
18
  * Map of origin formula of rule
23
19
  */
24
20
  private _ruleFormulaMap;
25
- /**
26
- * reflect of formulaId to cell, only store transformable formula
27
- */
28
- private _formulaCellMap;
29
- constructor(_instanceSrv: IUniverInstanceService, _registerOtherFormulaService: RegisterOtherFormulaService, _lexerTreeBuilder: LexerTreeBuilder, _dataValidationModel: DataValidationModel, _dataValidationCacheService: DataValidationCacheService, _injector: Injector);
21
+ constructor(_instanceSrv: IUniverInstanceService, _registerOtherFormulaService: RegisterOtherFormulaService, _dataValidationModel: DataValidationModel, _dataValidationCacheService: DataValidationCacheService);
30
22
  private _initFormulaResultHandler;
31
23
  private _ensureMaps;
32
24
  private _registerFormula;
33
25
  deleteByRuleId(unitId: string, subUnitId: string, ruleId: string): void;
34
26
  private _addFormulaByRange;
35
27
  addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
36
- updateRuleRanges(unitId: string, subUnitId: string, ruleId: string, oldRanges: IRange[], newRanges: IRange[]): void;
37
- updateRuleFormula(unitId: string, subUnitId: string, ruleId: string, ranges: IRange[], formula: string): void;
38
- getCellFormulaValue(unitId: string, subUnitId: string, row: number, col: number): Promise<import('@univerjs/core').Nullable<import('@univerjs/sheets-formula').IOtherFormulaResult>>;
28
+ getCellFormulaValue(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): Promise<import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>>;
39
29
  getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string): IFormulaData | undefined;
40
30
  }
41
31
  export {};
@@ -1,4 +1,4 @@
1
- import { Nullable, Disposable, IUniverInstanceService } from '@univerjs/core';
1
+ import { IRange, Nullable, Disposable, IUniverInstanceService } from '@univerjs/core';
2
2
  import { IFormulaInfo, IOtherFormulaResult, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
3
3
  import { DataValidationModel } from '@univerjs/data-validation';
4
4
  import { DataValidationCacheService } from './dv-cache.service';
@@ -11,9 +11,10 @@ export declare class DataValidationFormulaService extends Disposable {
11
11
  constructor(_instanceService: IUniverInstanceService, _registerOtherFormulaService: RegisterOtherFormulaService, _dataValidationCacheService: DataValidationCacheService, _dataValidationModel: DataValidationModel);
12
12
  private _initFormulaResultHandler;
13
13
  private _ensureRuleFormulaMap;
14
- addRule(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined): void;
14
+ private _registerSingleFormula;
15
+ addRule(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined, ranges: IRange[]): void;
15
16
  removeRule(unitId: string, subUnitId: string, ruleId: string): void;
16
- updateRuleFormulaText(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined): void;
17
+ updateRuleFormulaText(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined, ranges: IRange[]): void;
17
18
  getRuleFormulaResult(unitId: string, subUnitId: string, ruleId: string): Promise<Nullable<[Nullable<IOtherFormulaResult>, Nullable<IOtherFormulaResult>]>>;
18
19
  getRuleFormulaResultSync(unitId: string, subUnitId: string, ruleId: string): Nullable<IOtherFormulaResult>[] | undefined;
19
20
  getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string): [IFormulaInfo | undefined, IFormulaInfo | undefined] | undefined;
@@ -16,18 +16,15 @@ export declare class CheckboxValidator extends BaseDataValidator {
16
16
  skipDefaultFontRender: (rule: ISheetDataValidationRule, cellValue: Nullable<CellValue>, pos: {
17
17
  unitId: string;
18
18
  subUnitId: string;
19
+ row: number;
20
+ column: number;
19
21
  }) => boolean;
20
22
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
21
23
  parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<ICheckboxFormulaResult>;
22
24
  getExtraStyle(rule: IDataValidationRule, value: Nullable<CellValue>): {
23
25
  tb: WrapStrategy;
24
26
  };
25
- parseFormulaSync(rule: IDataValidationRule, unitId: string, subUnitId: string): {
26
- formula1: Nullable<CellValue>;
27
- formula2: Nullable<CellValue>;
28
- originFormula1: Nullable<CellValue>;
29
- originFormula2: Nullable<CellValue>;
30
- };
27
+ parseFormulaSync(rule: IDataValidationRule, unitId: string, subUnitId: string): ICheckboxFormulaResult;
31
28
  isValidType(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
32
29
  generateRuleErrorMessage(rule: IDataValidationRuleBase): string;
33
30
  }
@@ -21,11 +21,7 @@ export declare class DecimalValidator extends BaseDataValidator<number> {
21
21
  t: Nullable<import('@univerjs/protocol').CellValueType>;
22
22
  };
23
23
  private _parseNumber;
24
- parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<{
25
- formula1: number;
26
- formula2: number;
27
- isFormulaValid: boolean;
28
- }>;
24
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
29
25
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
30
26
  validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
31
27
  validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
@@ -20,11 +20,7 @@ export declare class WholeValidator extends BaseDataValidator<number> {
20
20
  t: Nullable<import('@univerjs/protocol').CellValueType>;
21
21
  };
22
22
  private _parseNumber;
23
- parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<{
24
- formula1: number;
25
- formula2: number;
26
- isFormulaValid: boolean;
27
- }>;
23
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
28
24
  validatorFormula(rule: IDataValidationRuleBase, unitId: string, subUnitId: string): IFormulaValidResult;
29
25
  validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
30
26
  validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
@@ -0,0 +1 @@
1
+ (function(n,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/sheets/facade"),require("@univerjs/sheets-data-validation"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets/facade","@univerjs/sheets-data-validation","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","rxjs"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n.UniverSheetsDataValidationFacade={},n.UniverSheetsFacade,n.UniverSheetsDataValidation,n.UniverCore,n.UniverDataValidation,n.UniverEngineFormula,n.rxjs))})(this,function(n,s,r,i,m,g,_){"use strict";var v=Object.defineProperty;var y=(n,s,r)=>s in n?v(n,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[s]=r;var h=(n,s,r)=>y(n,typeof s!="symbol"?s+"":s,r);class l{constructor(t){h(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,a){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=i.DataValidationOperator.BETWEEN,this._rule.type=a?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,a){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this._rule.type=a?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,a){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=a!=null?a:!0,this}requireValueInRange(t,e,a){return this._rule.type=e?i.DataValidationType.LIST_MULTIPLE:i.DataValidationType.LIST,this._rule.formula1=`=${g.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=a!=null?a:!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}setOptions(t){return Object.assign(this._rule,t),this}}class u{constructor(t,e){h(this,"rule");h(this,"_worksheet");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._worksheet.getInject().get(m.DataValidationModel).getRuleById(this._worksheet.getWorkbook().getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){var o;if(!this.getAllowInvalid())return[];const t=(o=this._worksheet)==null?void 0:o.getWorkbook(),e=this.getSheetId();if(!e)return[];const a=t==null?void 0:t.getSheetBySheetId(e);return!t||!a?[]:this.rule.ranges.map(I=>{var p;return(p=this._worksheet)==null?void 0:p.getInject().createInstance(s.FRange,t,a,I)})}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getWorkbook().getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e){return this.getApplied()&&!this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(r.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}})?!1:(this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,!0)}setOptions(t){return this.getApplied()&&!this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(r.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...m.getRuleOptions(this.rule),...t}})?!1:(Object.assign(this.rule,t),!0)}setRanges(t){return this.getApplied()&&!this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(r.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(o=>o.getRange())})?!1:(this.rule.ranges=t,!0)}delete(){return this.getApplied()?this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(r.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class f extends s.FRange{async setDataValidation(t){if(!t)return this._commandService.executeCommand(r.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 await this._commandService.executeCommand(r.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(r.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new u(e)}getDataValidations(){return this._injector.get(r.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new u(e))}async getValidatorStatus(){return this._injector.get(r.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}s.FRange.extend(f);class D{static newDataValidation(){return new l}}i.FUniver.extend(D);class S extends s.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(r.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(r.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return i.toDisposable(this._dataValidationModel.ruleChange$.pipe(_.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return i.toDisposable(this._dataValidationModel.validStatusChange$.pipe(_.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,a)=>{const o=e.params;if(e.id===r.AddSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,a)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,a)=>{const o=e.params;if(e.id===r.UpdateSheetDataValidationSettingCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,a)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,a)=>{const o=e.params;if(e.id===r.UpdateSheetDataValidationRangeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,a)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,a)=>{const o=e.params;if(e.id===r.UpdateSheetDataValidationOptionsCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,a)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,a)=>{const o=e.params;if(e.id===r.RemoveSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,a)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,a)=>{const o=e.params;if(e.id===r.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,a)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}s.FWorkbook.extend(S);class V extends s.FWorksheet{getDataValidations(){return this._injector.get(m.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new u(e))}getValidatorStatus(){return this._injector.get(r.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}}s.FWorksheet.extend(V),n.FDataValidation=u,n.FDataValidationBuilder=l,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});