@ngx-formly/core 7.0.0-alpha.1 → 7.0.0-next.0

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.
Files changed (33) hide show
  1. package/README.md +2 -2
  2. package/esm2022/lib/components/formly.field.mjs +2 -2
  3. package/esm2022/lib/components/formly.form.mjs +2 -1
  4. package/esm2022/lib/core.mjs +3 -3
  5. package/esm2022/lib/core.module.mjs +12 -12
  6. package/esm2022/lib/extensions/core/core.mjs +1 -5
  7. package/esm2022/lib/extensions/field-expression/field-expression.mjs +1 -5
  8. package/esm2022/lib/models/fieldconfig.cache.mjs +1 -1
  9. package/esm2022/lib/services/formly.builder.mjs +4 -6
  10. package/esm2022/lib/services/formly.config.mjs +22 -15
  11. package/esm2022/lib/templates/formly.attributes.mjs +16 -2
  12. package/esm2022/lib/templates/formly.validation-message.mjs +17 -2
  13. package/esm2022/lib/utils.mjs +2 -2
  14. package/esm2022/preset/public_api.mjs +2 -1
  15. package/esm2022/select/public_api.mjs +2 -2
  16. package/esm2022/select/select-options.pipe.mjs +11 -3
  17. package/esm2022/select/select.module.mjs +5 -5
  18. package/fesm2022/ngx-formly-core-preset.mjs +1 -1
  19. package/fesm2022/ngx-formly-core-select.mjs +14 -6
  20. package/fesm2022/ngx-formly-core-select.mjs.map +1 -1
  21. package/fesm2022/ngx-formly-core.mjs +67 -41
  22. package/fesm2022/ngx-formly-core.mjs.map +1 -1
  23. package/lib/core.d.ts +2 -2
  24. package/lib/core.module.d.ts +3 -3
  25. package/lib/models/fieldconfig.cache.d.ts +0 -6
  26. package/lib/services/formly.config.d.ts +3 -0
  27. package/lib/templates/formly.attributes.d.ts +5 -1
  28. package/lib/templates/formly.validation-message.d.ts +5 -1
  29. package/package.json +1 -1
  30. package/preset/public_api.d.ts +1 -0
  31. package/select/public_api.d.ts +1 -1
  32. package/select/select-options.pipe.d.ts +5 -1
  33. package/select/select.module.d.ts +1 -1
@@ -6,7 +6,7 @@ import { AbstractControl, UntypedFormArray, UntypedFormGroup, FormControl, Untyp
6
6
  import { tap, map, distinctUntilChanged, startWith, debounceTime, filter, switchMap, take } from 'rxjs/operators';
7
7
  import * as i1 from '@angular/platform-browser';
8
8
  import * as i1$1 from '@angular/common';
9
- import { DOCUMENT, CommonModule } from '@angular/common';
9
+ import { DOCUMENT, AsyncPipe, CommonModule } from '@angular/common';
10
10
 
11
11
  function disableTreeValidityCall(form, callback) {
12
12
  const _updateTreeValidity = form._updateTreeValidity.bind(form);
@@ -314,7 +314,7 @@ function isHiddenField(field) {
314
314
  return !setDefaultValue;
315
315
  }
316
316
  function isSignalRequired() {
317
- return +VERSION.major >= 18 && +VERSION.minor >= 1;
317
+ return +VERSION.major > 18 || (+VERSION.major >= 18 && +VERSION.minor >= 1);
318
318
  }
319
319
 
320
320
  function evalStringExpression(expression, argNames) {
@@ -497,10 +497,6 @@ class FieldExpressionExtension {
497
497
  }
498
498
  checkLocked = false;
499
499
  };
500
- field.options._checkField = (f, ignoreCache) => {
501
- console.warn(`Formly: 'options._checkField' is deprecated since v6.0, use 'options.checkExpressions' instead.`);
502
- field.options.checkExpressions(f, ignoreCache);
503
- };
504
500
  }
505
501
  }
506
502
  parseExpressions(field, path, expr) {
@@ -737,10 +733,6 @@ class CoreExtension {
737
733
  if (!options._hiddenFieldsForCheck) {
738
734
  options._hiddenFieldsForCheck = [];
739
735
  }
740
- options._markForCheck = (f) => {
741
- console.warn(`Formly: 'options._markForCheck' is deprecated since v6.0, use 'options.detectChanges' instead.`);
742
- options.detectChanges(f);
743
- };
744
736
  options._detectChanges = (f) => {
745
737
  if (f._componentRefs) {
746
738
  markFieldForCheck(f);
@@ -1194,6 +1186,7 @@ class FormlyConfig {
1194
1186
  this.extensions = {};
1195
1187
  this.presets = {};
1196
1188
  this.extensionsByPriority = {};
1189
+ this.componentRefs = {};
1197
1190
  }
1198
1191
  addConfig(config) {
1199
1192
  if (Array.isArray(config)) {
@@ -1292,22 +1285,28 @@ class FormlyConfig {
1292
1285
  if (!type) {
1293
1286
  return null;
1294
1287
  }
1295
- if (!type.component || type._componentRef) {
1296
- return type._componentRef;
1297
- }
1298
- const { _viewContainerRef, _injector } = field.options;
1299
- if (!_viewContainerRef || !_injector) {
1288
+ if (!type.component) {
1300
1289
  return null;
1301
1290
  }
1302
- const componentRef = _viewContainerRef.createComponent(type.component, { injector: _injector });
1303
- defineHiddenProp(type, '_componentRef', componentRef);
1304
- try {
1305
- componentRef.destroy();
1306
- }
1307
- catch (e) {
1308
- console.error(`An error occurred while destroying the Formly component type "${field.type}"`, e);
1291
+ if (!this.componentRefs[type.name]) {
1292
+ const { _viewContainerRef, _injector } = field.options;
1293
+ if (!_viewContainerRef || !_injector) {
1294
+ return null;
1295
+ }
1296
+ const componentRef = _viewContainerRef.createComponent(type.component, { injector: _injector });
1297
+ this.componentRefs[type.name] = componentRef;
1298
+ try {
1299
+ componentRef.destroy();
1300
+ }
1301
+ catch (e) {
1302
+ console.error(`An error occurred while destroying the Formly component type "${field.type}"`, e);
1303
+ }
1309
1304
  }
1310
- return type._componentRef;
1305
+ return this.componentRefs[type.name];
1306
+ }
1307
+ /** @ignore @internal */
1308
+ clearRefs() {
1309
+ this.componentRefs = {};
1311
1310
  }
1312
1311
  setWrapper(options) {
1313
1312
  this.wrappers[options.name] = options;
@@ -1661,7 +1660,7 @@ class FormlyField {
1661
1660
  }
1662
1661
  const { updateOn, debounce } = field.modelOptions;
1663
1662
  if ((!updateOn || updateOn === 'change') && debounce?.default > 0) {
1664
- valueChanges = control.valueChanges.pipe(debounceTime(debounce.default));
1663
+ valueChanges = valueChanges.pipe(debounceTime(debounce.default));
1665
1664
  }
1666
1665
  const sub = valueChanges.subscribe((value) => {
1667
1666
  // workaround for https://github.com/angular/angular/issues/13792
@@ -1765,7 +1764,9 @@ class FormlyFormBuilder {
1765
1764
  this.injector = injector;
1766
1765
  this.viewContainerRef = viewContainerRef;
1767
1766
  this.parentForm = parentForm;
1768
- configs.forEach((c) => config.addConfig(c));
1767
+ if (configs) {
1768
+ configs.forEach((c) => config.addConfig(c));
1769
+ }
1769
1770
  }
1770
1771
  buildForm(form, fieldGroup = [], model, options) {
1771
1772
  this.build({ fieldGroup, model, form, options });
@@ -1815,10 +1816,6 @@ class FormlyFormBuilder {
1815
1816
  defineHiddenProp(options, '_injector', this.injector);
1816
1817
  }
1817
1818
  if (!options.build) {
1818
- options._buildForm = () => {
1819
- console.warn(`Formly: 'options._buildForm' is deprecated since v6.0, use 'options.build' instead.`);
1820
- this.build(field);
1821
- };
1822
1819
  options.build = (f = field) => {
1823
1820
  this.build(f);
1824
1821
  return f;
@@ -1920,6 +1917,7 @@ class FormlyForm {
1920
1917
  }
1921
1918
  ngOnDestroy() {
1922
1919
  this.valueChangesUnsubscribe();
1920
+ this.config.clearRefs();
1923
1921
  }
1924
1922
  checkExpressionChange() {
1925
1923
  this.field.options.checkExpressions?.(this.field);
@@ -2166,12 +2164,13 @@ class FormlyAttributes {
2166
2164
  this.renderer.removeAttribute(this.elementRef.nativeElement, attr);
2167
2165
  }
2168
2166
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyAttributes, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Directive }); }
2169
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: FormlyAttributes, selector: "[formlyAttributes]", inputs: { field: ["formlyAttributes", "field"], id: "id" }, host: { listeners: { "change": "onHostChange($event)" } }, usesOnChanges: true, ngImport: i0 }); }
2167
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: FormlyAttributes, isStandalone: true, selector: "[formlyAttributes]", inputs: { field: ["formlyAttributes", "field"], id: "id" }, host: { listeners: { "change": "onHostChange($event)" } }, usesOnChanges: true, ngImport: i0 }); }
2170
2168
  }
2171
2169
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyAttributes, decorators: [{
2172
2170
  type: Directive,
2173
2171
  args: [{
2174
2172
  selector: '[formlyAttributes]',
2173
+ standalone: true,
2175
2174
  host: {
2176
2175
  '(change)': 'onHostChange($event)',
2177
2176
  },
@@ -2185,6 +2184,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
2185
2184
  }], id: [{
2186
2185
  type: Input
2187
2186
  }] } });
2187
+ class LegacyFormlyAttributes extends FormlyAttributes {
2188
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LegacyFormlyAttributes, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
2189
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: LegacyFormlyAttributes, selector: "[formlyAttributes]", host: { listeners: { "change": "onHostChange($event)" } }, usesInheritance: true, ngImport: i0 }); }
2190
+ }
2191
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LegacyFormlyAttributes, decorators: [{
2192
+ type: Directive,
2193
+ args: [{
2194
+ selector: '[formlyAttributes]',
2195
+ host: {
2196
+ '(change)': 'onHostChange($event)',
2197
+ },
2198
+ }]
2199
+ }] });
2188
2200
 
2189
2201
  /**
2190
2202
  * The `<formly-validation-message>` component renders the error message of a given `field`.
@@ -2234,7 +2246,7 @@ class FormlyValidationMessage {
2234
2246
  return undefined;
2235
2247
  }
2236
2248
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyValidationMessage, deps: [{ token: FormlyConfig }], target: i0.ɵɵFactoryTarget.Component }); }
2237
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: FormlyValidationMessage, selector: "formly-validation-message", inputs: { field: "field" }, usesOnChanges: true, ngImport: i0, template: '{{ errorMessage$ | async }}', isInline: true, dependencies: [{ kind: "pipe", type: i1$1.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2249
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: FormlyValidationMessage, isStandalone: true, selector: "formly-validation-message", inputs: { field: "field" }, usesOnChanges: true, ngImport: i0, template: '{{ errorMessage$ | async }}', isInline: true, dependencies: [{ kind: "pipe", type: AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2238
2250
  }
2239
2251
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyValidationMessage, decorators: [{
2240
2252
  type: Component,
@@ -2242,10 +2254,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
2242
2254
  selector: 'formly-validation-message',
2243
2255
  template: '{{ errorMessage$ | async }}',
2244
2256
  changeDetection: ChangeDetectionStrategy.OnPush,
2257
+ standalone: true,
2258
+ imports: [AsyncPipe],
2245
2259
  }]
2246
2260
  }], ctorParameters: () => [{ type: FormlyConfig }], propDecorators: { field: [{
2247
2261
  type: Input
2248
2262
  }] } });
2263
+ class LegacyFormlyValidationMessage extends FormlyValidationMessage {
2264
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LegacyFormlyValidationMessage, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
2265
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: LegacyFormlyValidationMessage, selector: "formly-validation-message", usesInheritance: true, ngImport: i0, template: '{{ errorMessage$ | async }}', isInline: true, dependencies: [{ kind: "pipe", type: i1$1.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2266
+ }
2267
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LegacyFormlyValidationMessage, decorators: [{
2268
+ type: Component,
2269
+ args: [{
2270
+ selector: 'formly-validation-message',
2271
+ template: '{{ errorMessage$ | async }}',
2272
+ changeDetection: ChangeDetectionStrategy.OnPush,
2273
+ }]
2274
+ }] });
2249
2275
 
2250
2276
  class FieldArrayType extends FieldType {
2251
2277
  onPopulate(field) {
@@ -2369,15 +2395,15 @@ class FormlyModule {
2369
2395
  static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: FormlyModule, declarations: [FormlyTemplate,
2370
2396
  LegacyFormlyForm,
2371
2397
  LegacyFormlyField,
2372
- FormlyAttributes,
2398
+ LegacyFormlyAttributes,
2399
+ LegacyFormlyValidationMessage,
2373
2400
  FormlyGroup,
2374
- FormlyValidationMessage,
2375
2401
  FormlyTemplateType], imports: [CommonModule], exports: [FormlyTemplate,
2376
2402
  LegacyFormlyForm,
2377
2403
  LegacyFormlyField,
2378
- FormlyAttributes,
2379
- FormlyGroup,
2380
- FormlyValidationMessage] }); }
2404
+ LegacyFormlyAttributes,
2405
+ LegacyFormlyValidationMessage,
2406
+ FormlyGroup] }); }
2381
2407
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyModule, imports: [CommonModule] }); }
2382
2408
  }
2383
2409
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyModule, decorators: [{
@@ -2387,18 +2413,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
2387
2413
  FormlyTemplate,
2388
2414
  LegacyFormlyForm,
2389
2415
  LegacyFormlyField,
2390
- FormlyAttributes,
2416
+ LegacyFormlyAttributes,
2417
+ LegacyFormlyValidationMessage,
2391
2418
  FormlyGroup,
2392
- FormlyValidationMessage,
2393
2419
  FormlyTemplateType,
2394
2420
  ],
2395
2421
  exports: [
2396
2422
  FormlyTemplate,
2397
2423
  LegacyFormlyForm,
2398
2424
  LegacyFormlyField,
2399
- FormlyAttributes,
2425
+ LegacyFormlyAttributes,
2426
+ LegacyFormlyValidationMessage,
2400
2427
  FormlyGroup,
2401
- FormlyValidationMessage,
2402
2428
  ],
2403
2429
  imports: [CommonModule],
2404
2430
  }]
@@ -2412,5 +2438,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
2412
2438
  * Generated bundle index. Do not edit.
2413
2439
  */
2414
2440
 
2415
- export { FORMLY_CONFIG, FieldArrayType, FieldType, FieldWrapper, FormlyConfig, FormlyField, FormlyForm, FormlyFormBuilder, FormlyModule, LegacyFormlyField, LegacyFormlyForm, provideFormlyConfig, provideFormlyCore, FormlyAttributes as ɵFormlyAttributes, FormlyGroup as ɵFormlyGroup, FormlyTemplate as ɵFormlyTemplate, FormlyValidationMessage as ɵFormlyValidationMessage, clone as ɵclone, defineHiddenProp as ɵdefineHiddenProp, getFieldValue as ɵgetFieldValue, hasKey as ɵhasKey, observe as ɵobserve, reverseDeepMerge as ɵreverseDeepMerge };
2441
+ export { FORMLY_CONFIG, FieldArrayType, FieldType, FieldWrapper, FormlyAttributes, FormlyConfig, FormlyField, FormlyForm, FormlyFormBuilder, FormlyModule, FormlyValidationMessage, LegacyFormlyAttributes, LegacyFormlyField, LegacyFormlyForm, LegacyFormlyValidationMessage, provideFormlyConfig, provideFormlyCore, FormlyGroup as ɵFormlyGroup, FormlyTemplate as ɵFormlyTemplate, clone as ɵclone, defineHiddenProp as ɵdefineHiddenProp, getFieldValue as ɵgetFieldValue, hasKey as ɵhasKey, observe as ɵobserve, reverseDeepMerge as ɵreverseDeepMerge };
2416
2442
  //# sourceMappingURL=ngx-formly-core.mjs.map