@ng-flexy/form
Version:
Flexy components and tools to build Angular 8+ applications
426 lines (400 loc) • 19.5 kB
TypeScript
import * as i0 from '@angular/core';
import { OnInit, OnDestroy, Renderer2, ElementRef, ViewContainerRef, ComponentFactoryResolver, EventEmitter, ChangeDetectorRef, TemplateRef, PipeTransform, InjectionToken, ModuleWithProviders } from '@angular/core';
import * as i9 from '@angular/forms';
import { AbstractControl, FormGroup, FormControl, ValidatorFn, FormBuilder, FormArray } from '@angular/forms';
import * as i11 from '@ng-flexy/layout';
import { FlexyLayoutComponentJsonSchema, FlexyLayoutGridJsonSchema, FlexyLayoutJson, FlexyLayoutComponentSchema, FlexyLayoutGridSchema, FlexyLayout, FlexyLayoutJsonMapperService } from '@ng-flexy/layout';
import { Observable, Subscription } from 'rxjs';
import { FlexyLoggerService, FlexyModel } from '@ng-flexy/core';
import { HttpClient } from '@angular/common/http';
import * as i10 from '@ngx-translate/core';
import { TranslateService } from '@ngx-translate/core';
import * as i8 from '@angular/common';
declare const COMPLEX_TYPE_INDEX_MARKER = "{%}";
declare enum FlexyFormFieldType {
String = "string",
Number = "number",
Boolean = "boolean",
Array = "array",
Group = "group"
}
interface FlexyFormLayoutJson extends FlexyLayoutJson {
schema: FlexyFormLayoutJsonSchema[];
}
type FlexyFormLayoutJsonSchema = FlexyFormFieldLayoutJsonSchema | FlexyFormComplexFieldLayoutJsonSchema | FlexyFormIfJsonSchema | FlexyFormCalcJsonSchema | FlexyFormGridJsonSchema | FlexyFormComponentJsonSchema;
interface FlexyFormGridJsonSchema extends FlexyLayoutGridJsonSchema {
children?: FlexyFormLayoutJsonSchema[];
}
interface FlexyFormComponentJsonSchema extends FlexyLayoutComponentJsonSchema {
children?: FlexyFormLayoutJsonSchema[];
}
interface FlexyFormIfJsonSchema extends FlexyFormGridJsonSchema {
if: string;
}
interface FlexyFormCalcJsonSchema extends FlexyFormComponentJsonSchema {
calc: string;
name?: string;
}
interface FlexyFormFieldLayoutJsonSchema extends FlexyFormComponentJsonSchema {
name: string;
type?: FlexyFormFieldType;
validators?: FlexyFormFieldLayoutValidators;
}
interface FlexyFormComplexFieldLayoutJsonSchema extends FlexyFormFieldLayoutJsonSchema {
items: FlexyFormLayoutJsonSchema;
indexDef?: string;
indexPattern?: string;
indexGenPattern?: string;
groupKey?: string;
}
interface FlexyFormFieldLayoutValidators {
[validatorName: string]: any;
}
type FlexyFormLayoutSchema = FlexyFormFieldLayoutSchema | FlexyFormLayoutGridSchema | FlexyLayoutComponentSchema | FlexyFormLayoutGridSchema;
interface FlexyFormFieldLayoutSchema extends FlexyLayoutComponentSchema {
formControl: AbstractControl;
formName: string;
calc?: string;
if?: string;
items?: FlexyFormFieldLayoutSchema[];
groupKey?: string;
children?: FlexyFormLayoutSchema[];
parent?: FlexyFormLayoutSchema;
jsonSchema?: FlexyFormLayoutJsonSchema;
}
interface FlexyFormLayoutGridSchema extends FlexyLayoutGridSchema {
children?: FlexyFormLayoutSchema[];
parent?: FlexyFormLayoutSchema;
jsonSchema?: FlexyFormLayoutJsonSchema;
}
type FlexyFormData = FlexyFormDataKV | FlexyFormDataKV[];
interface FlexyFormDataKV {
[paramKey: string]: any;
}
interface CalcRefs {
[name: string]: {
calc: string;
control: FormControl;
ifControl?: FormGroup;
};
}
declare class FlexyForm extends FlexyLayout {
currentData: FlexyFormData;
currentDataHash: string;
readonly currentData$: Observable<FlexyFormData>;
get valid(): boolean;
isStarted: boolean;
readonly schema: FlexyFormLayoutSchema[];
readonly formGroup: FormGroup;
private readonly _originalData;
private readonly _currentDataSubject;
_calculatedRefs: CalcRefs;
_lastErrors: {
[key: string]: any;
};
private _changesSubscription;
constructor(formGroup: FormGroup, schema: FlexyFormLayoutSchema[], data: FlexyFormData);
getAllData(): FlexyFormData;
getDirtyData(): FlexyFormData;
getAllErrors(): {
[key: string]: any;
};
containsFieldSchema(fieldName: string): boolean;
getFieldSchema(fieldName: string): FlexyFormFieldLayoutSchema;
getFieldInstance<T>(fieldName: string): T;
private _subscribeChangesAndCalculate;
private _setCurrentData;
private _initCalculatedRefs;
private _calculate;
private _clearHiddenData;
}
declare class FlexyFormAttributesDirective implements OnInit, OnDestroy {
private renderer;
private el;
flexyForm: FlexyForm;
componentSchema: FlexyFormFieldLayoutSchema;
private _changesSubscription;
constructor(renderer: Renderer2, el: ElementRef);
ngOnInit(): void;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormAttributesDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<FlexyFormAttributesDirective, "[flexyFormAttributes]", never, { "flexyForm": { "alias": "flexyForm"; "required": false; }; "componentSchema": { "alias": "componentSchema"; "required": false; }; }, {}, never, never, false, never>;
}
declare class FlexyFormContainerDirective implements OnInit, OnDestroy {
private vc;
private resolver;
private renderer;
flexyForm: FlexyForm;
set componentSchema(schema: FlexyFormFieldLayoutSchema);
get componentSchema(): FlexyFormFieldLayoutSchema;
private _schema;
private _changesSubscription;
private _componentRef;
constructor(vc: ViewContainerRef, resolver: ComponentFactoryResolver, renderer: Renderer2);
ngOnInit(): void;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormContainerDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<FlexyFormContainerDirective, "[flexyFormContainer]", never, { "flexyForm": { "alias": "flexyForm"; "required": false; }; "componentSchema": { "alias": "componentSchema"; "required": false; }; }, {}, never, never, false, never>;
}
interface FlexyFormValidatorsMap {
[name: string]: (data?: any) => ValidatorFn;
}
declare class FlexyFormJsonMapperService {
private jsonLayoutMapper;
private formBuilder;
private logger;
static controlCounter: number;
get supportedValidators(): string[];
private _validatorsMap;
constructor(validatorsMap: FlexyFormValidatorsMap, jsonLayoutMapper: FlexyLayoutJsonMapperService, formBuilder: FormBuilder, logger: FlexyLoggerService);
createForm(json: FlexyFormLayoutJson, readonlyMode: boolean, formData: FlexyFormData): FlexyForm;
createItemControl(itemsSchema: FlexyFormLayoutJsonSchema, readonlyMode: boolean, value: FlexyFormData): AbstractControl;
createArrayItemSchema(control: AbstractControl, items: FlexyFormLayoutJsonSchema, itemKeyDef: string, parentName: string, readonlyMode: boolean, formData: FlexyFormData, value: FlexyFormData, index: number, parentSchema?: FlexyFormLayoutSchema): FlexyFormFieldLayoutSchema;
createGroupItemSchema(control: AbstractControl, items: FlexyFormFieldLayoutJsonSchema, itemKeyDef: string, parentName: string, readonlyMode: boolean, formData: FlexyFormData, value: FlexyFormData, key: string, parentSchema?: FlexyFormLayoutSchema): FlexyFormFieldLayoutSchema;
createSchema(json: FlexyFormLayoutJsonSchema[], readonlyMode: boolean, formData: FlexyFormData, parentFormGroup: FormGroup, parentControlGroupName: string, parentSchema?: FlexyFormLayoutSchema): FlexyFormLayoutSchema[];
private map;
private createControl;
private controlComplexName;
private mapItem;
private _jsonLayoutItemMap;
private mapItemSetArrayControl;
private mapItemSetGroupControl;
private mapItemSetFieldControl;
private createArrayItems;
private populateComplexTypeIndexMarker;
private createControlConfig;
private createArrayControl;
private unifyName;
private mapValidators;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormJsonMapperService, [{ optional: true; }, null, null, null]>;
static ɵprov: i0.ɵɵInjectableDeclaration<FlexyFormJsonMapperService>;
}
interface FlexyFormChanges {
valid: boolean;
data: FlexyFormData;
}
declare class FlexyFormComponent implements OnInit, OnDestroy {
private jsonMapper;
private cdr;
json: FlexyFormLayoutJson;
data: FlexyFormData;
readonly: boolean;
changesDebounceTime: number;
created: EventEmitter<FlexyForm>;
changed: EventEmitter<FlexyFormChanges>;
form: FlexyForm;
private _changesSubscription;
constructor(jsonMapper: FlexyFormJsonMapperService, cdr: ChangeDetectorRef);
ngOnInit(): void;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<FlexyFormComponent, "flexy-form", never, { "json": { "alias": "json"; "required": false; }; "data": { "alias": "data"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "changesDebounceTime": { "alias": "changesDebounceTime"; "required": false; }; }, { "created": "created"; "changed": "changed"; }, never, never, false, never>;
}
declare class FlexyFormContainerComponent {
form: FlexyForm;
schema: FlexyFormLayoutSchema[];
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormContainerComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<FlexyFormContainerComponent, "flexy-form-container", never, { "form": { "alias": "form"; "required": false; }; "schema": { "alias": "schema"; "required": false; }; }, {}, never, ["*"], false, never>;
}
declare class FlexyFlexyFormIfDirective implements OnInit {
private templateRef;
private viewContainer;
flexyFormIf: {
schema: FlexyFormLayoutSchema;
form: FlexyForm;
};
constructor(templateRef: TemplateRef<any>, viewContainer: ViewContainerRef);
private _visibility;
private _changesSubscription;
private _ifCompiled;
private _viewRef;
ngOnInit(): void;
private _render;
private _isEnabled;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFlexyFormIfDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<FlexyFlexyFormIfDirective, "[flexyFormIf]", never, { "flexyFormIf": { "alias": "flexyFormIf"; "required": false; }; }, {}, never, never, false, never>;
}
type SelectOption = SelectOptionData;
interface SelectOptionMapper {
value: string;
text: string;
prefixHtml?: string;
}
interface SelectOptionData {
value: any;
text: string;
prefixHtml?: string;
_raw?: any;
}
declare class FlexyFormControlOptionsService {
private httpClient;
private logger;
constructor(httpClient: HttpClient, logger: FlexyLoggerService);
loadOptions(optionsUrl: string, optionsMapper?: SelectOptionMapper | string, optionsPath?: string): Observable<SelectOption[]>;
private _jsonataMapperOptions;
private _optionsMapper;
private _mapperTemplate;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormControlOptionsService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<FlexyFormControlOptionsService>;
}
interface FlexyFormOptionsFilter {
observableFields: string[];
filter: string;
}
declare abstract class FlexyFormAbstractOptionsComponent {
protected optionsService: FlexyFormControlOptionsService;
protected logger: FlexyLoggerService;
form: FlexyForm;
options: SelectOption[];
optionsUrl: string;
optionsPath: string;
optionsMapper: SelectOptionMapper | string;
optionsRawId: string;
optionsFilter: FlexyFormOptionsFilter;
loading: boolean;
protected changesSubscription: Subscription;
protected filterData: {};
private _optionsCache;
protected constructor(optionsService: FlexyFormControlOptionsService, logger: FlexyLoggerService);
initOptions(): Promise<void>;
private _setOptionsFiltering;
}
declare enum FlexyFormDataMode {
All = "all",
Dirty = "dirty",
Touched = "toched"
}
declare function findErrors(schema: FlexyFormLayoutSchema[], currentData: FlexyFormData): {
[key: string]: any;
};
declare function findSchema(fieldName: string, schema: FlexyFormLayoutSchema[]): FlexyFormFieldLayoutSchema;
declare function calculate(calcExp: string, data: any): any;
declare function getSchemaData(schemas: FlexyFormLayoutSchema[], currentData: FlexyFormData, mode?: FlexyFormDataMode): FlexyFormData;
declare function findRemoved(allData: any, originalData: any): {};
declare function clearEmptyArrayAndObjects(data: {
[key: string]: any;
}): void;
interface FlexyValidatorsData {
[paramKey: string]: any;
}
declare class FlexyFormFirstErrorPipe implements PipeTransform {
private translateService;
private logger;
constructor(translateService: TranslateService, logger: FlexyLoggerService);
transform(errors: any): string;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormFirstErrorPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<FlexyFormFirstErrorPipe, "firstError", false>;
}
declare class FlexyOptionsMapperPipe implements PipeTransform {
constructor();
transform(value: FlexyModel<any>[], mapper: {
value: string;
text: string;
}): SelectOptionData[];
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyOptionsMapperPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<FlexyOptionsMapperPipe, "flexyOptions", false>;
}
declare const HIDDEN_IF_GROUP_NAME = "__if__";
declare const HIDDEN_CALC_GROUP_NAME = "__calc__";
declare function parseFormJson(json: FlexyFormLayoutJson): FlexyFormLayoutJsonSchema[];
declare function checkSchema(schema: FlexyFormLayoutJsonSchema[]): void;
declare function assignHiddenNames(schema: FlexyFormLayoutJsonSchema[]): void;
declare function parseFormVersion1(json: any[]): FlexyFormLayoutJsonSchema[];
declare function parseFormVersion1Item(item: any): FlexyFormLayoutJsonSchema;
declare function replaceMarker(s: string, marker: string, key: string | number): string;
declare class FlexyFormSchemaService {
private jsonMapperService;
constructor(jsonMapperService: FlexyFormJsonMapperService);
addGroupItemToSchema(parentSchemaRef: FlexyFormFieldLayoutSchema, itemKey: string, groupSchema: FlexyFormComplexFieldLayoutJsonSchema, controlGroupName: string, readonly: boolean): FlexyFormFieldLayoutSchema;
validateGroupKey(key: any, groupSchema: FlexyFormComplexFieldLayoutJsonSchema): string;
removeGroupItemToSchema(layoutSchemaRef: FlexyFormFieldLayoutSchema, index: any): string;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormSchemaService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<FlexyFormSchemaService>;
}
declare function findRawValue(rawIdKey: string, controlValue: any | any[], options: SelectOption[]): any | any[];
declare function prepareControlValue(optionsRawId: string, data: SelectOptionData | SelectOptionData[]): any;
declare function isRequired(control: AbstractControl): boolean;
declare function markAsDirtyDeep(control: AbstractControl): void;
type ControlPath = (string | number)[] | string;
interface CrossFieldsOptions {
lower: {
name: string;
path: ControlPath;
};
greater: {
name: string;
path: ControlPath;
};
}
declare namespace FlexyFormsValidators {
function notEmptyValidator(control: FormControl): {
'not-empty': boolean;
};
function noWhitespaceValidator(control: FormControl): {
whitespace: boolean;
};
function emailValidator(control: FormControl): {
'invalid-email': {
currentValue: any;
};
};
function booleanValidator(control: FormControl): {
'invalid-boolean': {
currentValue: any;
};
};
function integerValidator(control: FormControl): {
'invalid-integer': {
currentValue: any;
};
};
function minValidator(min: number): ValidatorFn;
function maxValidator(max: number): ValidatorFn;
function numberValidator(control: FormControl): {
'invalid-number': {
currentValue: any;
};
};
function minLengthArray(min: number): (control: FormControl) => {
[key: string]: any;
};
function maxLengthArray(max: number): (control: FormControl) => {
[key: string]: any;
};
function isEmpty(control: FormControl): boolean;
function urlValidator(control: FormControl): {
'invalid-url': {
currentValue: any;
};
};
function crossFieldValidator(fields: CrossFieldsOptions): (control: FormControl) => {
[key: string]: any;
};
function crossFieldMinValidator(minPath: ControlPath): (control: FormControl) => {
[key: string]: any;
};
function crossFieldMaxValidator(maxPath: ControlPath): (control: FormControl) => {
[key: string]: any;
};
function crossFieldAbsoluteMinValidator(minPath: ControlPath): (control: FormControl) => {
[key: string]: any;
};
function forbiddenValuesValidator(forbiddenValues: (string | number)[]): (control: FormControl) => {
[key: string]: any;
};
function arrayUniqueFieldsValidator(data: {
path: ControlPath;
fieldName: string;
}): (control: FormArray) => {
[key: string]: any;
};
}
declare const FLEXY_FORM_VALIDATORS: InjectionToken<FlexyFormValidatorsMap>;
declare class FlexyFormsModule {
static forRoot(validators?: FlexyFormValidatorsMap): ModuleWithProviders<FlexyFormsModule>;
static ɵfac: i0.ɵɵFactoryDeclaration<FlexyFormsModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<FlexyFormsModule, [typeof FlexyFormFirstErrorPipe, typeof FlexyOptionsMapperPipe, typeof FlexyFormContainerComponent, typeof FlexyFormAttributesDirective, typeof FlexyFormContainerDirective, typeof FlexyFlexyFormIfDirective, typeof FlexyFormComponent], [typeof i8.CommonModule, typeof i9.FormsModule, typeof i9.ReactiveFormsModule, typeof i10.TranslateModule, typeof i11.FlexyLayoutModule], [typeof FlexyFormFirstErrorPipe, typeof FlexyOptionsMapperPipe, typeof FlexyFormContainerComponent, typeof FlexyFormAttributesDirective, typeof FlexyFormContainerDirective, typeof FlexyFlexyFormIfDirective, typeof FlexyFormComponent]>;
static ɵinj: i0.ɵɵInjectorDeclaration<FlexyFormsModule>;
}
export { COMPLEX_TYPE_INDEX_MARKER, FLEXY_FORM_VALIDATORS, FlexyFlexyFormIfDirective, FlexyForm, FlexyFormAbstractOptionsComponent, FlexyFormAttributesDirective, FlexyFormComponent, FlexyFormContainerComponent, FlexyFormContainerDirective, FlexyFormControlOptionsService, FlexyFormDataMode, FlexyFormFieldType, FlexyFormFirstErrorPipe, FlexyFormJsonMapperService, FlexyFormSchemaService, FlexyFormsModule, FlexyFormsValidators, FlexyOptionsMapperPipe, HIDDEN_CALC_GROUP_NAME, HIDDEN_IF_GROUP_NAME, assignHiddenNames, calculate, checkSchema, clearEmptyArrayAndObjects, findErrors, findRawValue, findRemoved, findSchema, getSchemaData, isRequired, markAsDirtyDeep, parseFormJson, parseFormVersion1, parseFormVersion1Item, prepareControlValue, replaceMarker };
export type { CrossFieldsOptions, FlexyFormCalcJsonSchema, FlexyFormChanges, FlexyFormComplexFieldLayoutJsonSchema, FlexyFormComponentJsonSchema, FlexyFormData, FlexyFormFieldLayoutJsonSchema, FlexyFormFieldLayoutSchema, FlexyFormFieldLayoutValidators, FlexyFormGridJsonSchema, FlexyFormIfJsonSchema, FlexyFormLayoutGridSchema, FlexyFormLayoutJson, FlexyFormLayoutJsonSchema, FlexyFormLayoutSchema, FlexyFormOptionsFilter, FlexyFormValidatorsMap, FlexyValidatorsData, SelectOption, SelectOptionData, SelectOptionMapper };