@univerjs/sheets-data-validation 0.5.0-alpha.0 → 0.5.0-beta.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,13 @@
1
+ import { ISheetDataValidationRule, Disposable } from '@univerjs/core';
2
+ import { FormulaRefRangeService } from '@univerjs/sheets-formula';
3
+ import { SheetDataValidationModel } from '../models/sheet-data-validation-model';
4
+ export declare class DataValidationFormulaRefRangeController extends Disposable {
5
+ private _dataValidationModel;
6
+ private _formulaRefRangeService;
7
+ private _disposableMap;
8
+ constructor(_dataValidationModel: SheetDataValidationModel, _formulaRefRangeService: FormulaRefRangeService);
9
+ private _getIdWithUnitId;
10
+ registerRule: (unitId: string, subUnitId: string, rule: ISheetDataValidationRule) => void;
11
+ register(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
12
+ private _initRefRange;
13
+ }
@@ -1,4 +1,4 @@
1
- import { ISheetDataValidationRule, DataValidationStatus, DataValidationType, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
1
+ import { DataValidationType, ISheetDataValidationRule, DataValidationStatus, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
2
  import { IRuleChange, DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
3
3
  import { ISheetLocation } from '@univerjs/sheets';
4
4
  import { DataValidationCacheService } from '../services/dv-cache.service';
@@ -38,7 +38,6 @@ export declare class SheetDataValidationModel extends Disposable {
38
38
  getRuleIdByLocation(unitId: string, subUnitId: string, row: number, col: number): string | undefined;
39
39
  getRuleByLocation(unitId: string, subUnitId: string, row: number, col: number): ISheetDataValidationRule | undefined;
40
40
  validator(rule: ISheetDataValidationRule, pos: ISheetLocation, _onCompete?: (status: DataValidationStatus, changed: boolean) => void): DataValidationStatus;
41
- getRuleErrorMsg(unitId: string, subUnitId: string, ruleId: string): string;
42
41
  getRuleObjectMatrix(unitId: string, subUnitId: string): RuleMatrix;
43
42
  getRuleById(unitId: string, subUnitId: string, ruleId: string): ISheetDataValidationRule | undefined;
44
43
  getRuleIndex(unitId: string, subUnitId: string, ruleId: string): number;
@@ -6,7 +6,6 @@ interface IFormulaData {
6
6
  formula: string;
7
7
  originRow: number;
8
8
  originCol: number;
9
- isTransformable: boolean;
10
9
  formulaId: string;
11
10
  }
12
11
  export declare class DataValidationCustomFormulaService extends Disposable {
@@ -18,6 +17,7 @@ export declare class DataValidationCustomFormulaService extends Disposable {
18
17
  * Map of origin formula of rule
19
18
  */
20
19
  private _ruleFormulaMap;
20
+ private _ruleFormulaMap2;
21
21
  constructor(_instanceSrv: IUniverInstanceService, _registerOtherFormulaService: RegisterOtherFormulaService, _dataValidationModel: DataValidationModel, _dataValidationCacheService: DataValidationCacheService);
22
22
  private _initFormulaResultHandler;
23
23
  private _ensureMaps;
@@ -26,6 +26,9 @@ export declare class DataValidationCustomFormulaService extends Disposable {
26
26
  private _addFormulaByRange;
27
27
  addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
28
28
  getCellFormulaValue(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): Promise<import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>>;
29
+ getCellFormula2Value(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): Promise<import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>>;
30
+ getCellFormulaValueSync(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>;
31
+ getCellFormula2ValueSync(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>;
29
32
  getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string): IFormulaData | undefined;
30
33
  }
31
34
  export {};
@@ -1,4 +1,4 @@
1
- import { IRange, Nullable, Disposable, IUniverInstanceService } from '@univerjs/core';
1
+ import { ISheetDataValidationRule, 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';
@@ -12,9 +12,8 @@ export declare class DataValidationFormulaService extends Disposable {
12
12
  private _initFormulaResultHandler;
13
13
  private _ensureRuleFormulaMap;
14
14
  private _registerSingleFormula;
15
- addRule(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined, ranges: IRange[]): void;
15
+ addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
16
16
  removeRule(unitId: string, subUnitId: string, ruleId: string): void;
17
- updateRuleFormulaText(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined, ranges: IRange[]): void;
18
17
  getRuleFormulaResult(unitId: string, subUnitId: string, ruleId: string): Promise<Nullable<[Nullable<IOtherFormulaResult>, Nullable<IOtherFormulaResult>]>>;
19
18
  getRuleFormulaResultSync(unitId: string, subUnitId: string, ruleId: string): Nullable<IOtherFormulaResult>[] | undefined;
20
19
  getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string): [IFormulaInfo | undefined, IFormulaInfo | undefined] | undefined;
@@ -1,4 +1,8 @@
1
- import { ICellData, Nullable } from '@univerjs/core';
1
+ import { DataValidationType, ICellData, Nullable } from '@univerjs/core';
2
2
  export declare function getFormulaResult(result: Nullable<Nullable<ICellData>[][]>): Nullable<import('@univerjs/core').CellValue>;
3
3
  export declare function getFormulaCellData(result: Nullable<Nullable<ICellData>[][]>): Nullable<ICellData>;
4
4
  export declare function isLegalFormulaResult(res: string): boolean;
5
+ /**
6
+ * Judge if the data-validation's formula need to be offseted by ranges
7
+ */
8
+ export declare function isCustomFormulaType(type: DataValidationType): type is DataValidationType.CUSTOM | DataValidationType.NONE | DataValidationType.TEXT_LENGTH | DataValidationType.DATE | DataValidationType.TIME | DataValidationType.WHOLE | DataValidationType.DECIMAL;
@@ -0,0 +1,17 @@
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
+ export declare const FORMULA1 = "{FORMULA1}";
17
+ export declare const FORMULA2 = "{FORMULA2}";
@@ -5,7 +5,7 @@ export declare class CustomFormulaValidator extends BaseDataValidator {
5
5
  title: string;
6
6
  operators: DataValidationOperator[];
7
7
  scopes: string | string[];
8
- private _customFormulaService;
8
+ private readonly _customFormulaService;
9
9
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
10
10
  parseFormula(_rule: IDataValidationRule, _unitId: string, _subUnitId: string): Promise<IFormulaResult>;
11
11
  isValidType(cellInfo: IValidatorCellInfo<CellValue>, _formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
@@ -1,16 +1,14 @@
1
1
  import { CellValue, IDataValidationRule, IDataValidationRuleBase, DataValidationOperator } from '@univerjs/core';
2
2
  import { IFormulaResult, IFormulaValidResult, IValidatorCellInfo, BaseDataValidator } from '@univerjs/data-validation';
3
+ import { ISheetLocationBase } from '@univerjs/sheets';
3
4
  export declare class DateValidator extends BaseDataValidator<number> {
4
5
  id: string;
5
6
  title: string;
6
7
  operators: DataValidationOperator[];
7
8
  scopes: string | string[];
8
- private _formulaService;
9
- parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<number | undefined>>;
10
- parseFormulaSync(rule: IDataValidationRule, unitId: string, subUnitId: string): {
11
- formula1: number | undefined;
12
- formula2: number | undefined;
13
- };
9
+ private readonly _customFormulaService;
10
+ private readonly _lexerTreeBuilder;
11
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string, row: number, column: number): Promise<IFormulaResult<number | undefined>>;
14
12
  isValidType(info: IValidatorCellInfo): Promise<boolean>;
15
13
  private _validatorSingleFormula;
16
14
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
@@ -29,5 +27,5 @@ export declare class DateValidator extends BaseDataValidator<number> {
29
27
  validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
30
28
  get operatorNames(): string[];
31
29
  generateRuleName(rule: IDataValidationRuleBase): string;
32
- generateRuleErrorMessage(rule: IDataValidationRuleBase): string;
30
+ generateRuleErrorMessage(rule: IDataValidationRuleBase, pos: ISheetLocationBase): string;
33
31
  }
@@ -1,9 +1,11 @@
1
- import { CellValue, IDataValidationRule, Nullable, DataValidationOperator } from '@univerjs/core';
1
+ import { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable, DataValidationOperator } from '@univerjs/core';
2
2
  import { IFormulaResult, IFormulaValidResult, IValidatorCellInfo, BaseDataValidator } from '@univerjs/data-validation';
3
+ import { ISheetLocationBase } from '@univerjs/sheets';
3
4
  export declare function getCellValueNumber(cellValue: CellValue): number;
4
5
  export declare class DecimalValidator extends BaseDataValidator<number> {
5
- private _formulaService;
6
+ private readonly _customFormulaService;
6
7
  id: string;
8
+ private readonly _lexerTreeBuilder;
7
9
  title: string;
8
10
  operators: DataValidationOperator[];
9
11
  scopes: string | string[];
@@ -21,7 +23,7 @@ export declare class DecimalValidator extends BaseDataValidator<number> {
21
23
  t: Nullable<import('@univerjs/protocol').CellValueType>;
22
24
  };
23
25
  private _parseNumber;
24
- parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
26
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string, row: number, column: number): Promise<IFormulaResult>;
25
27
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
26
28
  validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
27
29
  validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
@@ -31,4 +33,5 @@ export declare class DecimalValidator extends BaseDataValidator<number> {
31
33
  validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
32
34
  validatorIsLessThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
33
35
  validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
36
+ generateRuleErrorMessage(rule: IDataValidationRuleBase, position: ISheetLocationBase): string;
34
37
  }
@@ -1,16 +1,18 @@
1
1
  import { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable, DataValidationOperator } from '@univerjs/core';
2
2
  import { IFormulaResult, IFormulaValidResult, IValidatorCellInfo, BaseDataValidator } from '@univerjs/data-validation';
3
+ import { ISheetLocationBase } from '@univerjs/sheets';
3
4
  export declare class TextLengthValidator extends BaseDataValidator<number> {
4
5
  id: string;
5
6
  title: string;
7
+ private readonly _lexerTreeBuilder;
6
8
  operators: DataValidationOperator[];
7
9
  scopes: string | string[];
8
- private _formulaService;
10
+ private readonly _customFormulaService;
9
11
  private _isFormulaOrInt;
10
12
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
11
13
  private _parseNumber;
12
14
  private _isValidFormula;
13
- parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<any>>;
15
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string, row: number, column: number): Promise<IFormulaResult<any>>;
14
16
  transform(cellInfo: IValidatorCellInfo<CellValue>, _formula: IFormulaResult, _rule: IDataValidationRule): {
15
17
  value: number;
16
18
  interceptValue: Nullable<CellValue>;
@@ -31,5 +33,5 @@ export declare class TextLengthValidator extends BaseDataValidator<number> {
31
33
  validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
32
34
  validatorIsLessThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
33
35
  validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
34
- generateRuleErrorMessage(rule: IDataValidationRuleBase): string;
36
+ generateRuleErrorMessage(rule: IDataValidationRuleBase, pos: ISheetLocationBase): string;
35
37
  }
@@ -1,5 +1,11 @@
1
- import { ICellData, IUnitRangeName, IUniverInstanceService, Nullable } from '@univerjs/core';
1
+ import { ICellData, ISheetDataValidationRule, IUnitRangeName, IUniverInstanceService, Nullable } from '@univerjs/core';
2
+ import { LexerTreeBuilder } from '@univerjs/engine-formula';
3
+ import { ISheetLocationBase } from '@univerjs/sheets';
2
4
  export declare function getSheetRangeValueSet(grid: IUnitRangeName, univerInstanceService: IUniverInstanceService, currUnitId: string, currSubUnitId: string): string[];
3
5
  export declare function serializeListOptions(options: string[]): string;
4
6
  export declare function deserializeListOptions(optionsStr: string): string[];
5
7
  export declare function getDataValidationCellValue(cellData: Nullable<ICellData>): string;
8
+ export declare function getTransformedFormula(lexerTreeBuilder: LexerTreeBuilder, rule: ISheetDataValidationRule, position: ISheetLocationBase): {
9
+ transformedFormula1: string | undefined;
10
+ transformedFormula2: string | undefined;
11
+ };
@@ -1,7 +1,9 @@
1
1
  import { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable, DataValidationOperator } from '@univerjs/core';
2
2
  import { IFormulaResult, IFormulaValidResult, IValidatorCellInfo, BaseDataValidator } from '@univerjs/data-validation';
3
+ import { ISheetLocationBase } from '@univerjs/sheets';
3
4
  export declare class WholeValidator extends BaseDataValidator<number> {
4
- private _formulaService;
5
+ private readonly _customFormulaService;
6
+ private readonly _lexerTreeBuilder;
5
7
  id: string;
6
8
  title: string;
7
9
  operators: DataValidationOperator[];
@@ -20,7 +22,7 @@ export declare class WholeValidator extends BaseDataValidator<number> {
20
22
  t: Nullable<import('@univerjs/protocol').CellValueType>;
21
23
  };
22
24
  private _parseNumber;
23
- parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
25
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string, row: number, column: number): Promise<IFormulaResult>;
24
26
  validatorFormula(rule: IDataValidationRuleBase, unitId: string, subUnitId: string): IFormulaValidResult;
25
27
  validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
26
28
  validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
@@ -30,4 +32,5 @@ export declare class WholeValidator extends BaseDataValidator<number> {
30
32
  validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
31
33
  validatorIsLessThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
32
34
  validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
35
+ generateRuleErrorMessage(rule: IDataValidationRuleBase, position: ISheetLocationBase): string;
33
36
  }