@alauda-fe/common
Version:
Alauda frontend team common codes.
46 lines (45 loc) • 1.98 kB
TypeScript
import { IterableDiffers, OnDestroy } from '@angular/core';
import { AbstractControl, FormArray, ValidatorFn } from '@angular/forms';
import * as i0 from "@angular/core";
export declare const DUPLICATE_ERROR_KEY = "duplicateError";
type RowKeys = Array<string | Record<string, string[]>>;
type FormatKeys = Record<string, string[]>;
export type FormatValue = Record<string, any>;
export type MatchValueFn = (props: string[], value1: FormatValue, value2: FormatValue) => boolean;
export type StrategyFn = (keys: FormatKeys, controls: AbstractControl[], staleValue: FormatValue, mapFn: ValueMapFn, matchesFn: MatchValueFn, initData: any[]) => Array<{
key: string;
control: AbstractControl;
}>;
export declare enum DUPLICATION_JUSTIFY_STRATEGY {
IDENTICAL = "identical",
FULL = "full"
}
export declare const STRATEGY_JUDGE_MAPPER: Record<DUPLICATION_JUSTIFY_STRATEGY, StrategyFn>;
export declare class ValidateRowDuplicateService implements OnDestroy {
private readonly arrayDiffers;
private rowsDiffer;
/**
* @param differFactory: used to create support differ, which can be provided by user
*/
constructor(arrayDiffers: IterableDiffers);
private readonly controlValueMap;
private readonly errorMap;
private formArraySizeSub;
createFormArrayValidator({ rowKeys, formArray, valueMapFn, initData, matchesFn, strategy, }: {
rowKeys: RowKeys;
formArray: FormArray;
valueMapFn?: any;
initData?: any[];
matchesFn?: MatchValueFn;
strategy?: DUPLICATION_JUSTIFY_STRATEGY;
}): ValidatorFn;
private handleRemoveRowValue;
private initFormArraySizeChange;
private addDuplicateError;
private removeDuplicateError;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ValidateRowDuplicateService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ValidateRowDuplicateService>;
}
type ValueMapFn = (data: any, prop?: string) => any;
export {};