@olafvv/ngx-dynamic-form 0.0.2
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/README.md +55 -0
- package/esm2022/lib/components/dynamic-form/dynamic-form.component.mjs +59 -0
- package/esm2022/lib/components/dynamic-form-field/dynamic-form-field.component.mjs +129 -0
- package/esm2022/lib/controls/button/dynamic-button.component.mjs +22 -0
- package/esm2022/lib/controls/button/dynamic-button.model.mjs +12 -0
- package/esm2022/lib/controls/checkbox/dynamic-checkbox.component.mjs +32 -0
- package/esm2022/lib/controls/checkbox/dynamic-checkbox.model.mjs +21 -0
- package/esm2022/lib/controls/index.mjs +7 -0
- package/esm2022/lib/controls/input/dynamic-input.component.mjs +51 -0
- package/esm2022/lib/controls/input/dynamic-input.model.mjs +18 -0
- package/esm2022/lib/controls/readonly/dynamic-readonly.component.mjs +18 -0
- package/esm2022/lib/controls/readonly/dynamic-readonly.model.mjs +9 -0
- package/esm2022/lib/controls/select/dynamic-select.component.mjs +42 -0
- package/esm2022/lib/controls/select/dynamic-select.model.mjs +11 -0
- package/esm2022/lib/controls/textarea/dynamic-textarea.component.mjs +45 -0
- package/esm2022/lib/controls/textarea/dynamic-textarea.model.mjs +15 -0
- package/esm2022/lib/models/classes/dynamic-form-field-base-component.mjs +34 -0
- package/esm2022/lib/models/classes/dynamic-form-field-model.mjs +24 -0
- package/esm2022/lib/models/classes/dynamic-form-field-option-model.mjs +48 -0
- package/esm2022/lib/models/classes/dynamic-form-field-value-model.mjs +24 -0
- package/esm2022/lib/models/classes/dynamic-form-validators.mjs +73 -0
- package/esm2022/lib/models/constants/dynamic-relations.const.mjs +47 -0
- package/esm2022/lib/models/index.mjs +11 -0
- package/esm2022/lib/models/interfaces/dynamic-form-field-config.interface.mjs +2 -0
- package/esm2022/lib/models/interfaces/dynamic-form-validator.interface.mjs +2 -0
- package/esm2022/lib/models/tokens/dynamic-form-field-map-fn.token.mjs +3 -0
- package/esm2022/lib/models/types/dynamic-form-config.type.mjs +2 -0
- package/esm2022/lib/models/types/dynamic-form-hook.type.mjs +2 -0
- package/esm2022/lib/models/types/related-form-controls.type.mjs +2 -0
- package/esm2022/lib/services/dynamic-form-relations.service.mjs +103 -0
- package/esm2022/lib/services/dynamic-form.service.mjs +77 -0
- package/esm2022/lib/services/dynamic-validations.service.mjs +37 -0
- package/esm2022/olafvv-ngx-dynamic-form.mjs +5 -0
- package/esm2022/public-api.mjs +8 -0
- package/fesm2022/olafvv-ngx-dynamic-form.mjs +873 -0
- package/fesm2022/olafvv-ngx-dynamic-form.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/components/dynamic-form/dynamic-form.component.d.ts +32 -0
- package/lib/components/dynamic-form-field/dynamic-form-field.component.d.ts +44 -0
- package/lib/controls/button/dynamic-button.component.d.ts +11 -0
- package/lib/controls/button/dynamic-button.model.d.ts +15 -0
- package/lib/controls/checkbox/dynamic-checkbox.component.d.ts +15 -0
- package/lib/controls/checkbox/dynamic-checkbox.model.d.ts +15 -0
- package/lib/controls/index.d.ts +6 -0
- package/lib/controls/input/dynamic-input.component.d.ts +19 -0
- package/lib/controls/input/dynamic-input.model.d.ts +27 -0
- package/lib/controls/readonly/dynamic-readonly.component.d.ts +10 -0
- package/lib/controls/readonly/dynamic-readonly.model.d.ts +9 -0
- package/lib/controls/select/dynamic-select.component.d.ts +16 -0
- package/lib/controls/select/dynamic-select.model.d.ts +12 -0
- package/lib/controls/textarea/dynamic-textarea.component.d.ts +18 -0
- package/lib/controls/textarea/dynamic-textarea.model.d.ts +21 -0
- package/lib/models/classes/dynamic-form-field-base-component.d.ts +26 -0
- package/lib/models/classes/dynamic-form-field-model.d.ts +22 -0
- package/lib/models/classes/dynamic-form-field-option-model.d.ts +41 -0
- package/lib/models/classes/dynamic-form-field-value-model.d.ts +18 -0
- package/lib/models/classes/dynamic-form-validators.d.ts +48 -0
- package/lib/models/constants/dynamic-relations.const.d.ts +30 -0
- package/lib/models/index.d.ts +10 -0
- package/lib/models/interfaces/dynamic-form-field-config.interface.d.ts +60 -0
- package/lib/models/interfaces/dynamic-form-validator.interface.d.ts +6 -0
- package/lib/models/tokens/dynamic-form-field-map-fn.token.d.ts +2 -0
- package/lib/models/types/dynamic-form-config.type.d.ts +2 -0
- package/lib/models/types/dynamic-form-hook.type.d.ts +1 -0
- package/lib/models/types/related-form-controls.type.d.ts +4 -0
- package/lib/services/dynamic-form-relations.service.d.ts +26 -0
- package/lib/services/dynamic-form.service.d.ts +42 -0
- package/lib/services/dynamic-validations.service.d.ts +20 -0
- package/package.json +28 -0
- package/public-api.d.ts +4 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { DynamicFormFieldConfig } from '../interfaces/dynamic-form-field-config.interface';
|
|
3
|
+
import { DynamicFormFieldModel } from './dynamic-form-field-model';
|
|
4
|
+
export interface DynamicFormFieldValueConfig<T> extends DynamicFormFieldConfig {
|
|
5
|
+
value?: T;
|
|
6
|
+
defaultValue?: T;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class DynamicFormFieldValueModel<T> extends DynamicFormFieldModel {
|
|
9
|
+
valueChanges: Observable<T | null>;
|
|
10
|
+
private _defaultValue;
|
|
11
|
+
private _value;
|
|
12
|
+
private _value$;
|
|
13
|
+
constructor(config: DynamicFormFieldValueConfig<T>);
|
|
14
|
+
get defaultValue(): T | null;
|
|
15
|
+
set defaultValue(val: T | null);
|
|
16
|
+
get value(): T | null;
|
|
17
|
+
set value(val: T | null);
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DynamicFormValidator } from '../interfaces/dynamic-form-validator.interface';
|
|
2
|
+
export declare class DynamicFormValidators {
|
|
3
|
+
/**
|
|
4
|
+
* Default required validator, the control must contain a value
|
|
5
|
+
* @param msg
|
|
6
|
+
*/
|
|
7
|
+
static required(msg?: string): DynamicFormValidator;
|
|
8
|
+
/**
|
|
9
|
+
* Ddefault requiredTrue validator, the value of the control has to be true
|
|
10
|
+
* @param msg
|
|
11
|
+
*/
|
|
12
|
+
static requiredTrue(msg?: string): DynamicFormValidator;
|
|
13
|
+
/**
|
|
14
|
+
* Default min validator, the value has to be greater or equal than the the provided number
|
|
15
|
+
* @param min number
|
|
16
|
+
* @param msg
|
|
17
|
+
*/
|
|
18
|
+
static min(min: number, msg?: string): DynamicFormValidator;
|
|
19
|
+
/**
|
|
20
|
+
* Default max validator, the value has to be less or equal than the the provided number
|
|
21
|
+
* @param max number
|
|
22
|
+
* @param msg
|
|
23
|
+
*/
|
|
24
|
+
static max(max: number, msg?: string): DynamicFormValidator;
|
|
25
|
+
/**
|
|
26
|
+
* Default minLength validator, the value has to contain a minimum amount of characters
|
|
27
|
+
* @param min number
|
|
28
|
+
* @param msg
|
|
29
|
+
*/
|
|
30
|
+
static minLength(min: number, msg?: string): DynamicFormValidator;
|
|
31
|
+
/**
|
|
32
|
+
* Default maxLength validator, the value has to contain a maximum amount of characters
|
|
33
|
+
* @param max number
|
|
34
|
+
* @param msg
|
|
35
|
+
*/
|
|
36
|
+
static maxLength(max: number, msg?: string): DynamicFormValidator;
|
|
37
|
+
/**
|
|
38
|
+
* Ddefault email validator, the value of the control has to be a valid email address
|
|
39
|
+
* @param msg
|
|
40
|
+
*/
|
|
41
|
+
static email(msg?: string): DynamicFormValidator;
|
|
42
|
+
/**
|
|
43
|
+
* Default pattern validator, the value of the control has to match the provided pattern
|
|
44
|
+
* @param pattern: string | RegExp
|
|
45
|
+
* @param msg
|
|
46
|
+
*/
|
|
47
|
+
static pattern(pattern: string | RegExp, msg?: string): DynamicFormValidator;
|
|
48
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Injector } from '@angular/core';
|
|
2
|
+
import { UntypedFormControl } from '@angular/forms';
|
|
3
|
+
import { DynamicFormFieldModel } from '../classes/dynamic-form-field-model';
|
|
4
|
+
export declare enum RelationActionType {
|
|
5
|
+
DISABLED = "DISABLED",
|
|
6
|
+
ENABLED = "ENABLED",
|
|
7
|
+
HIDDEN = "HIDDEN",
|
|
8
|
+
VISIBLE = "VISIBLE",
|
|
9
|
+
REQUIRED = "REQUIRED",
|
|
10
|
+
OPTIONAL = "OPTIONAL"
|
|
11
|
+
}
|
|
12
|
+
export declare enum RelationOperator {
|
|
13
|
+
AND = "AND",
|
|
14
|
+
OR = "OR"
|
|
15
|
+
}
|
|
16
|
+
export interface RelationCondition {
|
|
17
|
+
fieldName: string;
|
|
18
|
+
value: (val: any) => boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface DynamicFormFieldRelation {
|
|
21
|
+
actionType: RelationActionType;
|
|
22
|
+
operator?: RelationOperator;
|
|
23
|
+
conditions: RelationCondition[];
|
|
24
|
+
}
|
|
25
|
+
export interface DynamicRelationAction {
|
|
26
|
+
type: RelationActionType;
|
|
27
|
+
reversedType?: string;
|
|
28
|
+
change(hasMatch: boolean, model: DynamicFormFieldModel, control: UntypedFormControl, injector: Injector): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const RELATION_ACTIONS: DynamicRelationAction[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './classes/dynamic-form-field-base-component';
|
|
2
|
+
export * from './classes/dynamic-form-field-model';
|
|
3
|
+
export * from './classes/dynamic-form-field-option-model';
|
|
4
|
+
export * from './classes/dynamic-form-field-value-model';
|
|
5
|
+
export * from './classes/dynamic-form-validators';
|
|
6
|
+
export * from './constants/dynamic-relations.const';
|
|
7
|
+
export * from './interfaces/dynamic-form-field-config.interface';
|
|
8
|
+
export * from './interfaces/dynamic-form-validator.interface';
|
|
9
|
+
export * from './types/dynamic-form-config.type';
|
|
10
|
+
export * from './tokens/dynamic-form-field-map-fn.token';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DynamicFormFieldRelation } from '../constants/dynamic-relations.const';
|
|
2
|
+
import { DynamicFormHook } from '../types/dynamic-form-hook.type';
|
|
3
|
+
import { DynamicFormValidator } from './dynamic-form-validator.interface';
|
|
4
|
+
export interface DynamicFormFieldConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the control has to be disabled.
|
|
7
|
+
* Default value is false.
|
|
8
|
+
* @optional
|
|
9
|
+
*/
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the control should be hidden.
|
|
13
|
+
* Default value is false
|
|
14
|
+
* @optional
|
|
15
|
+
*/
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Adds an id attribute to the FormControl.
|
|
19
|
+
* When not provided, the required 'name' property is used as id
|
|
20
|
+
* @optional
|
|
21
|
+
*/
|
|
22
|
+
id?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the width of the field, based on percentages. Default value is 100.
|
|
25
|
+
* @optional
|
|
26
|
+
*/
|
|
27
|
+
width?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Used as mat-label when provided
|
|
30
|
+
* @optional
|
|
31
|
+
*/
|
|
32
|
+
label?: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Name used as FormControlName
|
|
35
|
+
* @required
|
|
36
|
+
*/
|
|
37
|
+
name: string;
|
|
38
|
+
/**
|
|
39
|
+
* Hint text underneath the FormControl
|
|
40
|
+
* @optional
|
|
41
|
+
*/
|
|
42
|
+
hint?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Array of Dynamic Form Validators
|
|
45
|
+
* @optional
|
|
46
|
+
*/
|
|
47
|
+
validators?: DynamicFormValidator[];
|
|
48
|
+
/**
|
|
49
|
+
* Array of Dynamic Form Relations
|
|
50
|
+
* @optional
|
|
51
|
+
*/
|
|
52
|
+
relations?: DynamicFormFieldRelation[];
|
|
53
|
+
/**
|
|
54
|
+
* Event name for the control to update on.
|
|
55
|
+
* Possible values: 'update', 'blur' or 'submit'.
|
|
56
|
+
* Default values is 'update'
|
|
57
|
+
* @optional
|
|
58
|
+
*/
|
|
59
|
+
updateOn?: DynamicFormHook;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DynamicFormHook = 'submit' | 'blur' | 'change';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FormControl, FormGroup } from '@angular/forms';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { DynamicFormFieldModel } from '../models/classes/dynamic-form-field-model';
|
|
4
|
+
import { RelatedFormControls } from '../models/types/related-form-controls.type';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
export declare class DynamicFormRelationsService {
|
|
7
|
+
private _injector;
|
|
8
|
+
/**
|
|
9
|
+
* Get an object with all FormField the provided model has a relation with
|
|
10
|
+
* @param model
|
|
11
|
+
* @param group
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
findRelatedFormField(model: DynamicFormFieldModel, group: FormGroup): RelatedFormControls;
|
|
15
|
+
getRelationSubscriptions(relatedFormControls: RelatedFormControls, model: DynamicFormFieldModel, control: FormControl): Subscription[];
|
|
16
|
+
/**
|
|
17
|
+
* Check the conditions inside the relations
|
|
18
|
+
* @param relation
|
|
19
|
+
* @param relatedControl
|
|
20
|
+
* @param action
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
private checkRelationCondition;
|
|
24
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormRelationsService, never>;
|
|
25
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormRelationsService>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Type } from '@angular/core';
|
|
2
|
+
import { FormBuilder, UntypedFormGroup } from '@angular/forms';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { DynamicFormField } from '../models/classes/dynamic-form-field-base-component';
|
|
5
|
+
import { DynamicFormFieldModel } from '../models/classes/dynamic-form-field-model';
|
|
6
|
+
import { DynamicFormFieldOption } from '../models/classes/dynamic-form-field-option-model';
|
|
7
|
+
import { DynamicFormConfig } from '../models/types/dynamic-form-config.type';
|
|
8
|
+
import { DynamicFormValidationsService } from './dynamic-validations.service';
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
export type DynamicFormFieldTypeMapFn = (field: DynamicFormFieldModel) => Type<DynamicFormField> | null;
|
|
11
|
+
export declare class DynamicFormService {
|
|
12
|
+
private DYNAMIC_FORM_FIELD_MAP_FN;
|
|
13
|
+
private fb;
|
|
14
|
+
private validatorsService;
|
|
15
|
+
constructor(DYNAMIC_FORM_FIELD_MAP_FN: DynamicFormFieldTypeMapFn, fb: FormBuilder, validatorsService: DynamicFormValidationsService);
|
|
16
|
+
/**
|
|
17
|
+
* Check if there is a function provided to use custom form controls
|
|
18
|
+
* @param model
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getCustomControlComponentType(model: DynamicFormFieldModel): Type<DynamicFormField> | null;
|
|
22
|
+
/**
|
|
23
|
+
* Create a FormGroup from the provided form configuration.
|
|
24
|
+
* Returns a FormGroup.
|
|
25
|
+
* @param config
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
createFormGroup(config: DynamicFormConfig): UntypedFormGroup;
|
|
29
|
+
/**
|
|
30
|
+
* Transform any list (Observable) to a list of DynamicFormFieldOption which is used in any Dynamic Form Field with options (e.g. DynamicSelect).
|
|
31
|
+
* Generic types:
|
|
32
|
+
* T = The type of the items in the provided list
|
|
33
|
+
* K = The type of the value inside an DynamicFormFieldOption
|
|
34
|
+
* @param listObs
|
|
35
|
+
* @param labelCb
|
|
36
|
+
* @param valueCb
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
toDynamicOptionListObs<T, K = string>(listObs: Observable<T[]>, labelCb: (item: T) => string, valueCb: (item: T) => K): Observable<DynamicFormFieldOption<K>[]>;
|
|
40
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormService, [{ optional: true; }, null, null]>;
|
|
41
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormService>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FormControl, ValidatorFn } from '@angular/forms';
|
|
2
|
+
import { DynamicFormValidator } from '../models/interfaces/dynamic-form-validator.interface';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export declare class DynamicFormValidationsService {
|
|
5
|
+
/**
|
|
6
|
+
* Get all Validator Functions from the validator configuration
|
|
7
|
+
* @param validatorConfig
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
getValidatorFns(validatorConfig: DynamicFormValidator[]): ValidatorFn[];
|
|
11
|
+
/**
|
|
12
|
+
* Update the validators on a FormControl based on the provided validator configuration.
|
|
13
|
+
* This will replace any existing validators on the control or removes all validators when none provided
|
|
14
|
+
* @param validatorConfig
|
|
15
|
+
* @param control
|
|
16
|
+
*/
|
|
17
|
+
updateValidators(validatorConfig: DynamicFormValidator[], control: FormControl): void;
|
|
18
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormValidationsService, never>;
|
|
19
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormValidationsService>;
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@olafvv/ngx-dynamic-form",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^16.2.12",
|
|
6
|
+
"@angular/core": "^16.2.12",
|
|
7
|
+
"@angular/forms": "^16.2.12",
|
|
8
|
+
"@angular/material": "^16.2.14",
|
|
9
|
+
"rxjs": "^7.5.0"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"tslib": "^2.3.0"
|
|
13
|
+
},
|
|
14
|
+
"module": "fesm2022/olafvv-ngx-dynamic-form.mjs",
|
|
15
|
+
"typings": "index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": {
|
|
18
|
+
"default": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"esm2022": "./esm2022/olafvv-ngx-dynamic-form.mjs",
|
|
23
|
+
"esm": "./esm2022/olafvv-ngx-dynamic-form.mjs",
|
|
24
|
+
"default": "./fesm2022/olafvv-ngx-dynamic-form.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"sideEffects": false
|
|
28
|
+
}
|
package/public-api.d.ts
ADDED