@ngx-formly/core 6.0.0 → 6.0.1
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 +20 -13
- package/esm2020/json-schema/formly-json-schema.service.mjs +3 -3
- package/esm2020/select/select-options.pipe.mjs +36 -4
- package/fesm2015/ngx-formly-core-json-schema.mjs +2 -2
- package/fesm2015/ngx-formly-core-json-schema.mjs.map +1 -1
- package/fesm2015/ngx-formly-core-select.mjs +35 -3
- package/fesm2015/ngx-formly-core-select.mjs.map +1 -1
- package/fesm2020/ngx-formly-core-json-schema.mjs +2 -2
- package/fesm2020/ngx-formly-core-json-schema.mjs.map +1 -1
- package/fesm2020/ngx-formly-core-select.mjs +35 -3
- package/fesm2020/ngx-formly-core-select.mjs.map +1 -1
- package/package.json +1 -1
- package/select/select-options.pipe.d.ts +7 -2
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Pipe, NgModule } from '@angular/core';
|
|
3
|
-
import { Observable,
|
|
4
|
-
import { map } from 'rxjs/operators';
|
|
3
|
+
import { Observable, BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { map, filter, tap } from 'rxjs/operators';
|
|
5
5
|
|
|
6
6
|
class FormlySelectOptionsPipe {
|
|
7
7
|
transform(options, field) {
|
|
8
8
|
if (!(options instanceof Observable)) {
|
|
9
|
-
options =
|
|
9
|
+
options = this.observableOf(options, field);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this.dispose();
|
|
10
13
|
}
|
|
11
14
|
return options.pipe(map((value) => this.transformOptions(value, field)));
|
|
12
15
|
}
|
|
16
|
+
ngOnDestroy() {
|
|
17
|
+
this.dispose();
|
|
18
|
+
}
|
|
13
19
|
transformOptions(options, field) {
|
|
14
20
|
const to = this.transformSelectProps(field);
|
|
15
21
|
const opts = [];
|
|
@@ -59,6 +65,32 @@ class FormlySelectOptionsPipe {
|
|
|
59
65
|
disabledProp: selectPropFn(props.disabledProp || 'disabled'),
|
|
60
66
|
};
|
|
61
67
|
}
|
|
68
|
+
dispose() {
|
|
69
|
+
if (this._options) {
|
|
70
|
+
this._options.complete();
|
|
71
|
+
this._options = null;
|
|
72
|
+
}
|
|
73
|
+
if (this._subscription) {
|
|
74
|
+
this._subscription.unsubscribe();
|
|
75
|
+
this._subscription = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
observableOf(options, f) {
|
|
79
|
+
this.dispose();
|
|
80
|
+
if (f && f.options && f.options.fieldChanges) {
|
|
81
|
+
this._subscription = f.options.fieldChanges
|
|
82
|
+
.pipe(filter(({ property, type, field }) => {
|
|
83
|
+
return (type === 'expressionChanges' &&
|
|
84
|
+
(property.indexOf('templateOptions.options') === 0 || property.indexOf('props.options') === 0) &&
|
|
85
|
+
field === f &&
|
|
86
|
+
Array.isArray(field.props.options) &&
|
|
87
|
+
!!this._options);
|
|
88
|
+
}), tap(() => this._options.next(f.props.options)))
|
|
89
|
+
.subscribe();
|
|
90
|
+
}
|
|
91
|
+
this._options = new BehaviorSubject(options);
|
|
92
|
+
return this._options.asObservable();
|
|
93
|
+
}
|
|
62
94
|
}
|
|
63
95
|
FormlySelectOptionsPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: FormlySelectOptionsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
64
96
|
FormlySelectOptionsPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: FormlySelectOptionsPipe, name: "formlySelectOptions" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-formly-core-select.mjs","sources":["../../../../src/core/select/src/select-options.pipe.ts","../../../../src/core/select/src/select.module.ts","../../../../src/core/select/src/ngx-formly-core-select.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\nimport { Observable,
|
|
1
|
+
{"version":3,"file":"ngx-formly-core-select.mjs","sources":["../../../../src/core/select/src/select-options.pipe.ts","../../../../src/core/select/src/select.module.ts","../../../../src/core/select/src/ngx-formly-core-select.ts"],"sourcesContent":["import { OnDestroy, Pipe, PipeTransform } from '@angular/core';\nimport { BehaviorSubject, Observable, Subscription } from 'rxjs';\nimport { filter, map, tap } from 'rxjs/operators';\nimport { FormlyFieldConfig, FormlyFieldProps } from '@ngx-formly/core';\n\nexport interface FormlySelectOption {\n label: string;\n disabled?: boolean;\n value?: any;\n group?: FormlySelectOption[];\n}\n\nexport interface FormlyFieldSelectProps extends FormlyFieldProps {\n groupProp?: string | ((option: any) => string);\n labelProp?: string | ((option: any) => any);\n valueProp?: string | ((option: any) => boolean);\n disabledProp?: string | ((option: any) => string);\n}\n\ntype ITransformOption = {\n labelProp: (option: any) => string;\n valueProp: (option: any) => any;\n disabledProp: (option: any) => boolean;\n groupProp: (option: any) => string;\n};\n\n@Pipe({ name: 'formlySelectOptions' })\nexport class FormlySelectOptionsPipe implements PipeTransform, OnDestroy {\n private _subscription: Subscription;\n private _options: BehaviorSubject<any[]>;\n\n transform(options: any, field?: FormlyFieldConfig): Observable<FormlySelectOption[]> {\n if (!(options instanceof Observable)) {\n options = this.observableOf(options, field);\n } else {\n this.dispose();\n }\n\n return (options as Observable<any>).pipe(map((value) => this.transformOptions(value, field)));\n }\n\n ngOnDestroy(): void {\n this.dispose();\n }\n\n private transformOptions(options: any[], field?: FormlyFieldConfig): FormlySelectOption[] {\n const to = this.transformSelectProps(field);\n\n const opts: FormlySelectOption[] = [];\n const groups: { [id: string]: number } = {};\n\n options?.forEach((option) => {\n const o = this.transformOption(option, to);\n if (o.group) {\n const id = groups[o.label];\n if (id === undefined) {\n groups[o.label] = opts.push(o) - 1;\n } else {\n o.group.forEach((o) => opts[id].group.push(o));\n }\n } else {\n opts.push(o);\n }\n });\n\n return opts;\n }\n\n private transformOption(option: any, props: ITransformOption): FormlySelectOption {\n const group = props.groupProp(option);\n if (Array.isArray(group)) {\n return {\n label: props.labelProp(option),\n group: group.map((opt) => this.transformOption(opt, props)),\n };\n }\n\n option = {\n label: props.labelProp(option),\n value: props.valueProp(option),\n disabled: !!props.disabledProp(option),\n };\n\n if (group) {\n return { label: group, group: [option] };\n }\n\n return option;\n }\n\n private transformSelectProps(field?: FormlyFieldConfig): ITransformOption {\n const props = field?.props || field?.templateOptions || {};\n const selectPropFn = (prop: any) => (typeof prop === 'function' ? prop : (o: any) => o[prop]);\n\n return {\n groupProp: selectPropFn(props.groupProp || 'group'),\n labelProp: selectPropFn(props.labelProp || 'label'),\n valueProp: selectPropFn(props.valueProp || 'value'),\n disabledProp: selectPropFn(props.disabledProp || 'disabled'),\n };\n }\n\n private dispose() {\n if (this._options) {\n this._options.complete();\n this._options = null;\n }\n\n if (this._subscription) {\n this._subscription.unsubscribe();\n this._subscription = null;\n }\n }\n\n private observableOf(options: any, f?: FormlyFieldConfig) {\n this.dispose();\n if (f && f.options && f.options.fieldChanges) {\n this._subscription = f.options.fieldChanges\n .pipe(\n filter(({ property, type, field }) => {\n return (\n type === 'expressionChanges' &&\n (property.indexOf('templateOptions.options') === 0 || property.indexOf('props.options') === 0) &&\n field === f &&\n Array.isArray(field.props.options) &&\n !!this._options\n );\n }),\n tap(() => this._options.next(f.props.options as any)),\n )\n .subscribe();\n }\n\n this._options = new BehaviorSubject(options);\n return this._options.asObservable();\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FormlySelectOptionsPipe } from './select-options.pipe';\n\n@NgModule({\n declarations: [FormlySelectOptionsPipe],\n exports: [FormlySelectOptionsPipe],\n})\nexport class FormlySelectModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;MA2Ba,uBAAuB,CAAA;IAIlC,SAAS,CAAC,OAAY,EAAE,KAAyB,EAAA;AAC/C,QAAA,IAAI,EAAE,OAAO,YAAY,UAAU,CAAC,EAAE;YACpC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,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eAAe,CAAC,OAAO,CAAC,CAAC;AAC7C,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;KACrC;;qHA5GU,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CAAA;mHAAvB,uBAAuB,EAAA,IAAA,EAAA,qBAAA,EAAA,CAAA,CAAA;4FAAvB,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBADnC,IAAI;mBAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAA;;;MCnBxB,kBAAkB,CAAA;;gHAAlB,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;iHAAlB,kBAAkB,EAAA,YAAA,EAAA,CAHd,uBAAuB,CAAA,EAAA,OAAA,EAAA,CAC5B,uBAAuB,CAAA,EAAA,CAAA,CAAA;iHAEtB,kBAAkB,EAAA,CAAA,CAAA;4FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAJ9B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;oBACR,YAAY,EAAE,CAAC,uBAAuB,CAAC;oBACvC,OAAO,EAAE,CAAC,uBAAuB,CAAC;AACnC,iBAAA,CAAA;;;ACND;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PipeTransform } from '@angular/core';
|
|
1
|
+
import { OnDestroy, PipeTransform } from '@angular/core';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { FormlyFieldConfig, FormlyFieldProps } from '@ngx-formly/core';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
@@ -14,11 +14,16 @@ export interface FormlyFieldSelectProps extends FormlyFieldProps {
|
|
|
14
14
|
valueProp?: string | ((option: any) => boolean);
|
|
15
15
|
disabledProp?: string | ((option: any) => string);
|
|
16
16
|
}
|
|
17
|
-
export declare class FormlySelectOptionsPipe implements PipeTransform {
|
|
17
|
+
export declare class FormlySelectOptionsPipe implements PipeTransform, OnDestroy {
|
|
18
|
+
private _subscription;
|
|
19
|
+
private _options;
|
|
18
20
|
transform(options: any, field?: FormlyFieldConfig): Observable<FormlySelectOption[]>;
|
|
21
|
+
ngOnDestroy(): void;
|
|
19
22
|
private transformOptions;
|
|
20
23
|
private transformOption;
|
|
21
24
|
private transformSelectProps;
|
|
25
|
+
private dispose;
|
|
26
|
+
private observableOf;
|
|
22
27
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormlySelectOptionsPipe, never>;
|
|
23
28
|
static ɵpipe: i0.ɵɵPipeDeclaration<FormlySelectOptionsPipe, "formlySelectOptions">;
|
|
24
29
|
}
|