Skip to content

Commit 12e52c5

Browse files
committed
feat: merge FeControl and FeControlDirective, remove Directive from filenames, add exportAs to all directives
1 parent 2f6beba commit 12e52c5

33 files changed

+243
-498
lines changed

README.md

Lines changed: 3 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ $ npm i ngfe
7979

8080
### Requirements
8181

82-
* Angular 12.0+
83-
* RxJs 6.6+
82+
* Angular 12+
83+
* RxJs 7+
8484

8585

8686

@@ -355,7 +355,7 @@ Also emits event only if form has `valid` state.
355355

356356
For dynamic forms we need to setup values when some fields became visible, and remove such values on field hiding.
357357

358-
Structural directive [`feIf`](./projects/ngfe/src/lib/core/fe-if.directive.ts) works similar to `ngIf` (except `else` part) and could set a model to some default / `undefined`.
358+
Structural directive [`feIf`](./projects/ngfe/src/lib/core/fe-if.ts) works similar to `ngIf` (except `else` part) and could set a model to some default / `undefined`.
359359

360360
When Angular change detection runs, `feIf` directive checks that the condition is true/false, wait until template updates, then update bound model and renders conditional template. This allows us to keep this logic in template and not collide with rendering process.
361361

@@ -452,172 +452,6 @@ Also, with this package, `feControl` provides `NgControl` and allows you to use
452452
453453

454454

455-
## Reference
456-
457-
### [`FeControl<MODEL, INPUT>`](./projects/ngfe/src/lib/core/fe-control.ts)
458-
459-
```
460-
readonly modelValue: MODEL | undefined;
461-
readonly modelValue$: Observable<MODEL | undefined>;
462-
readonly inputValue: INPUT | undefined;
463-
readonly inputValue$: Observable<INPUT | undefined>;
464-
readonly toInputValue$: Observable<INPUT | undefined>;
465-
disabled: boolean;
466-
readonly disabled$: Observable<boolean>;
467-
standalone: boolean;
468-
readonly standalone$: Observable<boolean>;
469-
touched: boolean;
470-
readonly touched$: Observable<boolean>;
471-
dirty: boolean;
472-
readonly dirty$: Observable<boolean>;
473-
readonly validators: FeValidator<MODEL, INPUT>[];
474-
readonly validators$: Observable<FeValidator<MODEL, INPUT>[]>;
475-
readonly validity: boolean;
476-
readonly validity$: Observable<FeValidity>[]>;
477-
readonly valid: boolean;
478-
readonly valid$: Observable<boolean>;
479-
readonly invalid: boolean;
480-
readonly invalid$: Observable<boolean>;
481-
readonly pending: boolean;
482-
readonly pending$: Observable<boolean>;
483-
readonly errors: FeErrors | undefined;
484-
readonly errors$: Observable<FeErrors | undefined>;
485-
readonly visibleErrors: FeErrors | undefined;
486-
readonly visibleErrors$: Observable<FeErrors | undefined>;
487-
readonly destroy$: Observable<undefined>;
488-
adapter: FeAdapter<MODEL, INPUT> | undefined;
489-
debounce: debounce: number | undefined;
490-
update(modelValue: MODEL | undefined, source: VcSource = 'manual');
491-
input(inputValue: INPUT | undefined);
492-
touch();
493-
updateValidators({add = [], remove = []}: {
494-
add?: FeValidator<MODEL, INPUT>[];
495-
remove?: FeValidator<MODEL, INPUT>[];
496-
});
497-
addValidator(validator: FeValidator<MODEL, INPUT>);
498-
updateValidity();
499-
setAdapter(adapter: FeAdapter<MODEL, INPUT> | undefined);
500-
reset();
501-
```
502-
503-
### [`FeControlDirective<MODEL, INPUT>`](./projects/ngfe/src/lib/core/fe-control.directive.ts)
504-
505-
`exportAs: "feControl"`
506-
507-
```
508-
[(feControl)]: MODEL | undefined;
509-
[(disabled)]: boolean;
510-
[(standalone)]: boolean;
511-
[(touched)]: boolean;
512-
[(dirty)]: boolean;
513-
[extraValidators]: FeValidator<MODEL>[] | undefined;
514-
[debounce]: number | undefined;
515-
[adapter]: 'noop' | 'numberToString' | 'dateToDateString' | 'dateToDateLocalString' | 'deepCopy'
516-
| FeAdapter<MODEL, INPUT> | undefined;
517-
(destroy): undefined;
518-
readonly modelValue: MODEL | undefined;
519-
readonly modelValue$: Observable<MODEL | undefined>;
520-
readonly inputValue: INPUT | undefined;
521-
readonly inputValue$: Observable<INPUT | undefined>;
522-
disabled: boolean;
523-
readonly disabled$: Observable<boolean>;
524-
standalone: boolean;
525-
readonly standalone$: Observable<boolean>;
526-
touched: boolean;
527-
readonly touched$: Observable<boolean>;
528-
dirty: boolean;
529-
readonly dirty$: Observable<boolean>;
530-
readonly validity: boolean;
531-
readonly validity$: Observable<FeValidity>[]>;
532-
readonly valid: boolean;
533-
readonly valid$: Observable<boolean>;
534-
readonly invalid: boolean;
535-
readonly invalid$: Observable<boolean>;
536-
readonly pending: boolean;
537-
readonly pending$: Observable<boolean>;
538-
readonly errors: FeErrors | undefined;
539-
readonly errors$: Observable<FeErrors | undefined>;
540-
readonly visibleErrors: FeErrors | undefined;
541-
readonly visibleErrors$: Observable<FeErrors | undefined>;
542-
```
543-
544-
### [`FeFormDirective`](./projects/ngfe/src/lib/core/fe-form.directive.ts)
545-
546-
`exportAs: "feForm"`
547-
548-
```
549-
[disabled]: boolean;
550-
readonly change$: Observable<undefined>;
551-
readonly validity: FeValidity;
552-
readonly validity$: Observable<FeValidity>;
553-
readonly valid: boolean;
554-
readonly valid$: Observable<boolean>;
555-
readonly invalid: boolean;
556-
readonly invalid$: Observable<boolean>;
557-
readonly pending: boolean;
558-
readonly pending$: Observable<boolean>;
559-
readonly controls: FeControl[];
560-
readonly enabledControls: FeControl[];
561-
readonly touched: boolean;
562-
readonly dirty: boolean;
563-
touchAll();
564-
reset();
565-
```
566-
567-
### [`FeSubmitDirective`](./projects/ngfe/src/lib/core/fe-submit.directive.ts)
568-
569-
`exportAs: "feSubmit"`
570-
571-
```
572-
(feSubmit): void;
573-
```
574-
575-
### [`FeIfDirective<T>`](./projects/ngfe/src/lib/core/fe-if.directive.ts)
576-
577-
```
578-
[feIf]: any;
579-
[(ensure)]: T | undefined;
580-
[default]: T | undefined;
581-
[force]: boolean;
582-
```
583-
584-
### [`FeInputDirective`](./projects/ngfe/src/lib/value-accessors/fe-input.directive.ts)
585-
586-
```
587-
[type]: 'text' | 'color' | 'email' | 'password' | 'range' | 'search' | 'tel' | 'url' |
588-
'number' |
589-
'checkbox' |'radio' |
590-
'date' | 'datetime-local' | 'time' | 'month' | 'week' |
591-
'file' |
592-
'hidden' | 'button' | 'image' | 'reset' = 'text';
593-
[name]: string;
594-
[value]: any;
595-
[updateOn]: 'change' | 'blur' = 'change'
596-
[touchOnBlur]: boolean | string = true;
597-
[touchOnChange]: boolean | string = false;
598-
[readFileAs]: 'DataURL' | 'Text' | 'ArrayBuffer' | 'BinaryString' = 'DataURL'
599-
(fileError): string;
600-
connected: boolean = true;
601-
```
602-
603-
### [`FeSelectDirective`](./projects/ngfe/src/lib/value-accessors/fe-select.directive.ts)
604-
605-
```
606-
[multiple]: boolean = false;
607-
[updateOn]: 'change' | 'blur' = 'change';
608-
[touchOnBlur]: boolean | string = true;
609-
[touchOnChange]: boolean | string = false;
610-
readonly options: Set<FeSelectOptionDirective>;
611-
connected: boolean = true;
612-
```
613-
614-
### [`FeSelectOptionDirective`](./projects/ngfe/src/lib/value-accessors/fe-select.directive.ts)
615-
616-
```
617-
[value]: any;
618-
```
619-
620-
621455
## LICENSE
622456

623457
MIT

e2e/tests/playground/input-control.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test.describe.serial('FeInputDirective', () => {
1010

1111
test('open', async ({page}) => {
1212
await kit.goto('/input-control');
13-
await expect(kit.subTitle).toHaveText('FeInputDirective');
13+
await expect(kit.subTitle).toHaveText('FeInput');
1414
});
1515

1616
test('input 1 - base input', async () => {

e2e/tests/playground/select-control.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test.describe.serial('FeSelectDirective', () => {
1111

1212
test('open', async ({page}) => {
1313
await kit.goto('/select-control');
14-
await expect(kit.subTitle).toHaveText('FeSelectDirective');
14+
await expect(kit.subTitle).toHaveText('FeSelect');
1515
});
1616

1717
test('select 1 - base select', async () => {

projects/ngfe-ng-adapter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngfe-ng-adapter",
3-
"version": "13.0.0",
3+
"version": "13.1.0",
44
"keywords": ["angular", "forms"],
55
"author": {
66
"name": "Oleksa Novyk",

projects/ngfe-ng-adapter/src/lib/fe-ng-adapter.module.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { NgModule } from '@angular/core';
2-
import { FeNgAdapterDirective } from './fe-ng-adapter.directive';
3-
import { FeNgControlDirective } from './fe-ng-control.directive';
2+
import { FeNgAdapter } from './fe-ng-adapter';
3+
import { FeNgControl } from './fe-ng-control';
44

55
@NgModule({
66
declarations: [
7-
FeNgAdapterDirective,
8-
FeNgControlDirective,
7+
FeNgAdapter,
8+
FeNgControl,
99
],
1010
exports: [
11-
FeNgAdapterDirective,
12-
FeNgControlDirective,
11+
FeNgAdapter,
12+
FeNgControl,
1313
],
1414
})
1515
export class FeNgAdapterModule {

projects/ngfe-ng-adapter/src/lib/fe-ng-adapter.directive.ts renamed to projects/ngfe-ng-adapter/src/lib/fe-ng-adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Directive, Inject, Optional, Self } from '@angular/core';
22
import { ControlValueAccessor, NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validator } from '@angular/forms';
3-
import { FeControl, FeInputDirective, FeSelectDirective } from 'ngfe';
3+
import { FeControl, FeInput, FeSelect } from 'ngfe';
44

55
@Directive({
66
selector: '[feControl]',
77
})
8-
export class FeNgAdapterDirective {
8+
export class FeNgAdapter {
99
constructor(
1010
@Self() private control: FeControl,
1111
@Self() @Optional() @Inject(NG_VALUE_ACCESSOR) private ngValueAccessors: ControlValueAccessor[],
1212
@Self() @Optional() @Inject(NG_VALIDATORS) private ngValidators: Validator[],
1313
@Self() @Optional() @Inject(NG_ASYNC_VALIDATORS) private ngAsyncValidators: Validator[],
14-
@Self() @Optional() @Inject(FeInputDirective) private feInputDirective: FeInputDirective | undefined,
15-
@Self() @Optional() @Inject(FeSelectDirective) private feSelectDirective: FeSelectDirective | undefined,
14+
@Self() @Optional() @Inject(FeInput) private feInputDirective: FeInput | undefined,
15+
@Self() @Optional() @Inject(FeSelect) private feSelectDirective: FeSelect | undefined,
1616
) {
1717
// @todo use selectValueAccessor
1818
// https://github.com/angular/angular/blob/3a60063a54d850c50ce962a8a39ce01cfee71398/packages/forms/src/directives/shared.ts#L326

projects/ngfe-ng-adapter/src/lib/fe-ng-control.directive.ts renamed to projects/ngfe-ng-adapter/src/lib/fe-ng-control.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ class LocalControl {
127127
providers: [
128128
{
129129
provide: NgControl,
130-
useExisting: FeNgControlDirective,
130+
useExisting: FeNgControl,
131131
},
132132
{
133133
provide: ControlContainer,
134-
useExisting: FeNgControlDirective,
134+
useExisting: FeNgControl,
135135
},
136136
],
137137
})
138-
export class FeNgControlDirective extends NgControl {
138+
export class FeNgControl extends NgControl {
139139
@Input() name!: string | null;
140140

141141
private _control?: LocalControl;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './fe-ng-adapter.directive';
1+
export * from './fe-ng-adapter';
22
export * from './fe-ng-adapter.module';
3-
export * from './fe-ng-control.directive';
3+
export * from './fe-ng-control';

projects/ngfe/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngfe",
3-
"version": "13.0.0",
3+
"version": "13.1.0",
44
"keywords": ["angular", "forms"],
55
"author": {
66
"name": "Oleksa Novyk",

0 commit comments

Comments
 (0)