Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
Features:
- Added a Type Parameter for the FormModel to improve autocomplete.
- Added Angular 10 and 11 version constraints to the package.json
  • Loading branch information
devtronic committed Jun 8, 2021
1 parent a5be2e5 commit f4a39fa
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Changelog

## 2.1.0

Features:
- Added a Type Parameter for the FormModel to improve autocomplete.
- Added Angular 10 and 11 version constraints to the package.json

## 2.0.1

Fix
Fix:
- Fixed ExpressionChangedAfterItHasBeenCheckedError.

Change:
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"type": "git"
},
"license": "MIT",
"version": "2.0.1",
"version": "2.1.0",
"peerDependencies": {
"@angular/common": "^7.2.0 || ^8.0.0 || ^9.0.0",
"@angular/core": "^7.2.0 || ^8.0.0 || ^9.0.0",
"@angular/forms": "^7.2.0 || ^8.0.0 || ^9.0.0"
"@angular/common": "^7.2.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
"@angular/core": "^7.2.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
"@angular/forms": "^7.2.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0"
}
}
6 changes: 3 additions & 3 deletions src/lib/form-builder/form-builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import {FormModel} from '../form-type/abstract-type';
})
export class FormBuilderComponent<T extends { [key: string]: any } = {}> implements OnInit, OnChanges {

public fieldType: AbstractGroupType<IGroupTypeOptions>;
public fieldType: AbstractGroupType<IGroupTypeOptions<T>, T>;

@Input()
public mwFormModel: FormModel;
public mwFormModel: FormModel<T>;

@Input()
public mwFormData: T;
Expand Down Expand Up @@ -60,7 +60,7 @@ export class FormBuilderComponent<T extends { [key: string]: any } = {}> impleme
public ngOnChanges(changes: SimpleChanges): void {
if ('mwFormModel' in changes && changes.mwFormModel.currentValue) {
this.rebuildForm();
this.fieldType = new FormGroupType({
this.fieldType = new FormGroupType<T>({
model: this.mwFormModel,
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/form-group/form-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {AbstractFormGroupComponent} from '../abstract-form-group/abstract-form-g
import {AbstractGroupType, IGroupTypeOptions} from '../form-type/abstract-group-type';
import {Constructor} from '../types';

export class FormGroupType extends AbstractGroupType<IGroupTypeOptions> {
export class FormGroupType<T = any> extends AbstractGroupType<IGroupTypeOptions<T>, T> {
public readonly component: Constructor = FormGroupComponent;
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib/form-type/abstract-group-type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {AbstractType, FormModel} from './abstract-type';
import {FormGroup} from '../abstraction';

export interface IGroupTypeOptions {
model: FormModel;
export interface IGroupTypeOptions<T = any> {
model: FormModel<T>;
}

export abstract class AbstractGroupType<T extends IGroupTypeOptions> extends AbstractType<T> {
export abstract class AbstractGroupType<T extends IGroupTypeOptions<TModel>, TModel = any> extends AbstractType<T> {
public control: FormGroup;
}
2 changes: 1 addition & 1 deletion src/lib/form-type/abstract-layout-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AbstractGroupType, IGroupTypeOptions} from './abstract-group-type';

export abstract class AbstractLayoutType<T extends IGroupTypeOptions> extends AbstractGroupType<T> {
export abstract class AbstractLayoutType<T extends IGroupTypeOptions<TModel>, TModel = any> extends AbstractGroupType<T, TModel> {
}
10 changes: 7 additions & 3 deletions src/lib/form-type/abstract-type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {AbstractControlOptions, AsyncValidatorFn, ValidatorFn} from '@angular/forms';
import {FormBuilderComponent} from '../form-builder/form-builder.component';
import {AbstractFormControl, Constructor} from '../types';
import {AbstractGroupType, IGroupTypeOptions} from './abstract-group-type';
import {AbstractLayoutType} from './abstract-layout-type';

export interface FormModel {
[key: string]: AbstractType<any>;
}

export type FormModel<T = any> =
{ [p in keyof T]?: AbstractGroupType<IGroupTypeOptions<p>, p> | AbstractType<any> } |
{ [p in Exclude<string, keyof T>]: AbstractLayoutType<IGroupTypeOptions<T>, T> }
;

export abstract class AbstractType<T> {
public abstract readonly component: Constructor;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/model-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ModelHandler {

private static handleModel(model: FormModel, group: FormGroup, builderInstance: FormBuilderComponent): void {
Object.keys(model).forEach((name) => {
const field = model[name];
const field: AbstractType<any> = model[name];
if (!field) {
return;
}
Expand Down

0 comments on commit f4a39fa

Please sign in to comment.