Skip to content

Commit

Permalink
Version 3.0.0
Browse files Browse the repository at this point in the history
Feature:
- Updated the peerDependencies for Angular 12

Change:
- Extracted an interface of the FormBuilderComponent to remove a cyclic dependency.

BREAKING CHANGE:
- Dropped support for Angular <10.0.0
  • Loading branch information
devtronic committed Jul 22, 2021
1 parent 3c46bdc commit 0f5c974
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Feature:
- Updated the peerDependencies for Angular 12

Change:
- Extracted an interface of the FormBuilderComponent to remove a cyclic dependency.

BREAKING CHANGE:
- Dropped support for Angular <10.0.0

Expand Down
24 changes: 24 additions & 0 deletions src/lib/abstraction/form-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {AbstractGroupType, IGroupTypeOptions} from '../form-type/abstract-group-type';
import {FormModel} from '../form-type/abstract-type';
import {EventEmitter, QueryList} from '@angular/core';
import {FormSlotDirective} from '../form-slot/form-slot.directive';
import {FormGroup} from './form-group';
import {FormArray} from './form-array';
import {ValidationErrors} from '@angular/forms';

export interface IFormBuilder<T extends { [key: string]: any } = {}> {
fieldType: AbstractGroupType<IGroupTypeOptions<T>, T>;
mwFormModel: FormModel<T>;
mwFormData: T;
mwFormSubmit: EventEmitter<T>;
mwSlots: QueryList<FormSlotDirective>;
group: FormGroup;
readonly valid: boolean;
readonly invalid: boolean;

rebuildForm(): void;

submit(): T;

getErrors(group?: FormGroup | FormArray): { [key: string]: ValidationErrors } | ValidationErrors[] | null;
}
1 change: 1 addition & 0 deletions src/lib/abstraction/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './form-array';
export * from './form-builder';
export * from './form-control';
export * from './form-group';
export * from './init-handler';
7 changes: 3 additions & 4 deletions src/lib/form-builder/form-builder.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {Component, ContentChildren, EventEmitter, Input, OnInit, Output, QueryList} from '@angular/core';
import {OnChanges, SimpleChanges} from '@angular/core';
import {Component, ContentChildren, EventEmitter, Input, OnChanges, OnInit, Output, QueryList, SimpleChanges} from '@angular/core';
import {ValidationErrors} from '@angular/forms';
import {FormSlotDirective} from '../form-slot/form-slot.directive';
import {ModelHandler} from '../model-handler';
import {AbstractGroupType, IGroupTypeOptions} from '../form-type/abstract-group-type';
import {AbstractCollectionType} from '../form-type/abstract-collection-type';
import {FormArray, FormControl, FormGroup} from '../abstraction';
import {FormArray, FormControl, FormGroup, IFormBuilder} from '../abstraction';
import {AbstractFormControl} from '../types';
import {FormGroupComponent, FormGroupType} from '../form-group/form-group.component';
import {AbstractLayoutType} from '../form-type/abstract-layout-type';
Expand All @@ -25,7 +24,7 @@ import {FormModel} from '../form-type/abstract-type';
`,
styles: []
})
export class FormBuilderComponent<T extends { [key: string]: any } = {}> implements OnInit, OnChanges {
export class FormBuilderComponent<T extends { [key: string]: any } = {}> implements OnInit, OnChanges, IFormBuilder {

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

Expand Down
4 changes: 2 additions & 2 deletions src/lib/form-type/abstract-type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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';
import {IFormBuilder} from '../abstraction';


export type FormModel<T = any> =
Expand All @@ -13,7 +13,7 @@ export type FormModel<T = any> =
export abstract class AbstractType<T> {
public abstract readonly component: Constructor;

public builderInstance: FormBuilderComponent;
public builderInstance: IFormBuilder;

public control: AbstractFormControl;

Expand Down
11 changes: 5 additions & 6 deletions src/lib/model-handler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {FormBuilderComponent} from './form-builder/form-builder.component';
import {AbstractCollectionType} from './form-type/abstract-collection-type';
import {AbstractGroupType} from './form-type/abstract-group-type';
import {AbstractType, FormModel} from './form-type/abstract-type';
import {FormArray, FormControl, FormGroup} from './abstraction';
import {FormArray, FormControl, FormGroup, IFormBuilder} from './abstraction';
import {AbstractLayoutType} from './form-type/abstract-layout-type';

export class ModelHandler {
public static build(model: FormModel, builderInstance: FormBuilderComponent): FormGroup {
public static build(model: FormModel, builderInstance: IFormBuilder): FormGroup {
const group = new FormGroup({});
this.handleModel(model, group, builderInstance);
return group;
}

private static handleModel(model: FormModel, group: FormGroup, builderInstance: FormBuilderComponent): void {
private static handleModel(model: FormModel, group: FormGroup, builderInstance: IFormBuilder): void {
Object.keys(model).forEach((name) => {
const field: AbstractType<any> = model[name];
if (!field) {
Expand Down Expand Up @@ -40,7 +39,7 @@ export class ModelHandler {
}

public static buildSingleField(field: AbstractType<any>,
builderInstance: FormBuilderComponent
builderInstance: IFormBuilder
): FormArray | FormGroup | FormControl | null {
let component: FormArray | FormGroup | FormControl;

Expand All @@ -58,7 +57,7 @@ export class ModelHandler {
return component;
}

private static handleArray(field: AbstractCollectionType<any, any>, array: FormArray, builderInstance: FormBuilderComponent): void {
private static handleArray(field: AbstractCollectionType<any, any>, array: FormArray, builderInstance: IFormBuilder): void {
const control = ModelHandler.buildSingleField(field.fieldInstance, builderInstance);
if (!control) {
return;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
"enableResourceInlining": true,
"compilationMode": "partial"
},
"exclude": [
"src/test.ts",
Expand Down

0 comments on commit 0f5c974

Please sign in to comment.