@rxap/form-system 14.0.2 → 14.1.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.
@@ -0,0 +1,90 @@
1
+ var IsSelectableValueDirective_1;
2
+ import { __decorate, __metadata } from "tslib";
3
+ import { NG_VALIDATORS } from '@angular/forms';
4
+ import { Directive, forwardRef, Inject, INJECTOR, Injector, Input, isDevMode, NgModule } from '@angular/core';
5
+ import { DataSourceLoader } from '@rxap/data-source';
6
+ import { Mixin } from '@rxap/mixin';
7
+ import { ExtractOptionsDataSourceMixin } from '../mixins/extract-options-data-source.mixin';
8
+ import * as i0 from "@angular/core";
9
+ import * as i1 from "@rxap/data-source";
10
+ let IsSelectableValueDirective = IsSelectableValueDirective_1 = class IsSelectableValueDirective {
11
+ constructor(dataSourceLoader, injector) {
12
+ this.dataSourceLoader = dataSourceLoader;
13
+ this.injector = injector;
14
+ this.viewer = { id: '[rxapIsSelectableValue]' };
15
+ }
16
+ validate(control) {
17
+ if (control.value) {
18
+ this.extractOptionsDatasource(control);
19
+ const data = this.useDataSourceValue?.lastValue;
20
+ if (data) {
21
+ let options;
22
+ if (Array.isArray(data)) {
23
+ options = data;
24
+ }
25
+ else {
26
+ options = Object.entries(data).map(([value, display]) => ({ value, display }));
27
+ }
28
+ if (!options.some(option => option.value === control.value)) {
29
+ return {
30
+ isSelectableValue: {
31
+ expected: 'Value should be from the list of provided options',
32
+ }
33
+ };
34
+ }
35
+ }
36
+ else if (isDevMode()) {
37
+ console.warn('The last value from the OptionsDataSource is empty', this);
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ };
43
+ IsSelectableValueDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirective, deps: [{ token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive });
44
+ IsSelectableValueDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", type: IsSelectableValueDirective, selector: "[rxapIsSelectableValue]", inputs: { viewer: "viewer" }, providers: [
45
+ {
46
+ provide: NG_VALIDATORS,
47
+ multi: true,
48
+ useExisting: forwardRef(() => IsSelectableValueDirective_1)
49
+ }
50
+ ], ngImport: i0 });
51
+ IsSelectableValueDirective = IsSelectableValueDirective_1 = __decorate([
52
+ Mixin(ExtractOptionsDataSourceMixin),
53
+ __metadata("design:paramtypes", [DataSourceLoader,
54
+ Injector])
55
+ ], IsSelectableValueDirective);
56
+ export { IsSelectableValueDirective };
57
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
58
+ type: Directive,
59
+ args: [{
60
+ selector: '[rxapIsSelectableValue]',
61
+ providers: [
62
+ {
63
+ provide: NG_VALIDATORS,
64
+ multi: true,
65
+ useExisting: forwardRef(() => IsSelectableValueDirective)
66
+ }
67
+ ]
68
+ }]
69
+ }], ctorParameters: function () { return [{ type: i1.DataSourceLoader, decorators: [{
70
+ type: Inject,
71
+ args: [DataSourceLoader]
72
+ }] }, { type: i0.Injector, decorators: [{
73
+ type: Inject,
74
+ args: [INJECTOR]
75
+ }] }]; }, propDecorators: { viewer: [{
76
+ type: Input
77
+ }] } });
78
+ export class IsSelectableValueDirectiveModule {
79
+ }
80
+ IsSelectableValueDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
81
+ IsSelectableValueDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, declarations: [IsSelectableValueDirective], exports: [IsSelectableValueDirective] });
82
+ IsSelectableValueDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule });
83
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, decorators: [{
84
+ type: NgModule,
85
+ args: [{
86
+ declarations: [IsSelectableValueDirective],
87
+ exports: [IsSelectableValueDirective]
88
+ }]
89
+ }] });
90
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaXMtc2VsZWN0YWJsZS12YWx1ZS5kaXJlY3RpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9saWJzL2Zvcm0tc3lzdGVtL3NyYy9saWIvdmFsaWRhdG9ycy9pcy1zZWxlY3RhYmxlLXZhbHVlLmRpcmVjdGl2ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLE9BQU8sRUFBbUIsYUFBYSxFQUErQixNQUFNLGdCQUFnQixDQUFDO0FBQzdGLE9BQU8sRUFBRSxTQUFTLEVBQUUsVUFBVSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLEtBQUssRUFBRSxTQUFTLEVBQUUsUUFBUSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBQzlHLE9BQU8sRUFBd0IsZ0JBQWdCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUMzRSxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRXBDLE9BQU8sRUFBRSw2QkFBNkIsRUFBRSxNQUFNLDZDQUE2QyxDQUFDOzs7SUFlL0UsMEJBQTBCLHdDQUExQiwwQkFBMEI7SUFLckMsWUFFcUIsZ0JBQWtDLEVBRWxDLFFBQWtCO1FBRmxCLHFCQUFnQixHQUFoQixnQkFBZ0IsQ0FBa0I7UUFFbEMsYUFBUSxHQUFSLFFBQVEsQ0FBVTtRQU5oQyxXQUFNLEdBQXlCLEVBQUUsRUFBRSxF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09PSBjb250cm9sLnZhbHVlKSkge1xuICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBpc1NlbGVjdGFibGVWYWx1ZToge1xuICAgICAgICAgICAgICBleHBlY3RlZDogJ1ZhbHVlIHNob3VsZCBiZSBmcm9tIHRoZSBsaXN0IG9mIHByb3ZpZGVkIG9wdGlvbnMnLFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChpc0Rldk1vZGUoKSkge1xuICAgICAgICBjb25zb2xlLndhcm4oJ1RoZSBsYXN0IHZhbHVlIGZyb20gdGhlIE9wdGlvbnNEYXRhU291cmNlIGlzIGVtcHR5JywgdGhpcyk7XG4gICAgICB9XG4gICAgfVxuICAgIHJldHVybiBudWxsO1xuICB9XG5cbn1cblxuQE5nTW9kdWxlKHtcbiAgZGVjbGFyYXRpb25zOiBbSXNTZWxlY3RhYmxlVmFsdWVEaXJlY3RpdmVdLFxuICBleHBvcnRzOiBbSXNTZWxlY3RhYmxlVmFsdWVEaXJlY3RpdmVdXG59KVxuZXhwb3J0IGNsYXNzIElzU2VsZWN0YWJsZVZhbHVlRGlyZWN0aXZlTW9kdWxlIHt9XG4iXX0=
@@ -5,12 +5,12 @@ import { RxapError, Required, equals } from '@rxap/utilities';
5
5
  import * as i1 from '@angular/forms';
6
6
  import { ControlContainer, NgControl, NG_VALIDATORS } from '@angular/forms';
7
7
  import { RxapFormControl, RxapFormGroup, RxapFormArray } from '@rxap/forms';
8
- import * as i2 from '@rxap/data-source';
8
+ import * as i1$1 from '@rxap/data-source';
9
9
  import { PipeDataSource, DataSourceLoader, BaseDataSource, RXAP_DATA_SOURCE_METADATA } from '@rxap/data-source';
10
10
  import { Mixin } from '@rxap/mixin';
11
- import { getMetadata, setMetadataMap, setMetadataMapMap, setMetadata } from '@rxap/utilities/reflect-metadata';
12
- import { map, startWith, distinctUntilChanged, shareReplay, tap, catchError } from 'rxjs/operators';
13
- import { Subscription, of } from 'rxjs';
11
+ import { getMetadata, setMetadataMapMap, setMetadataMap, setMetadata } from '@rxap/utilities/reflect-metadata';
12
+ import { map, startWith, distinctUntilChanged, shareReplay, tap, catchError, throttleTime, switchMap } from 'rxjs/operators';
13
+ import { Subscription, of, EMPTY } from 'rxjs';
14
14
  import * as i3 from '@angular/material/form-field';
15
15
  import { MAT_FORM_FIELD } from '@angular/material/form-field';
16
16
 
@@ -174,7 +174,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
174
174
  }] }, { type: i0.ViewContainerRef, decorators: [{
175
175
  type: Inject,
176
176
  args: [ViewContainerRef]
177
- }] }, { type: i2.DataSourceLoader, decorators: [{
177
+ }] }, { type: i1$1.DataSourceLoader, decorators: [{
178
178
  type: Inject,
179
179
  args: [DataSourceLoader]
180
180
  }] }, { type: i0.Injector, decorators: [{
@@ -236,8 +236,8 @@ function controlDataSource(control) {
236
236
  return new ControlDataSource(control, { id: control.controlId });
237
237
  }
238
238
 
239
- class ExtractControlMixin {
240
- extractControl(parent, controlPath) {
239
+ class ExtractControlFromParentMixin {
240
+ extractControlFromParent(parent, controlPath) {
241
241
  if (!controlPath) {
242
242
  throw new RxapFormSystemError('The control path is empty', '');
243
243
  }
@@ -266,17 +266,85 @@ class ExtractFormDefinitionMixin {
266
266
  }
267
267
  }
268
268
 
269
- function UseComponent(component, setProperties = {}) {
269
+ function UseDataSource(dataSource, name, settings) {
270
270
  return function (target, propertyKey) {
271
- setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
272
- setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
271
+ const value = { dataSource, settings };
272
+ setMetadataMapMap(propertyKey, name, value, FormSystemMetadataKeys.DATA_SOURCES, target);
273
273
  };
274
274
  }
275
275
 
276
- function UseDataSource(dataSource, name, settings) {
276
+ class ExtractControlMixin {
277
+ extractControl(ngControl) {
278
+ var _a, _b, _c, _d;
279
+ if (ngControl === void 0) { ngControl = (_d = (_a = this.ngControl) !== null && _a !== void 0 ? _a : (_c = (_b = this.matFormField) === null || _b === void 0 ? void 0 : _b._control) === null || _c === void 0 ? void 0 : _c.ngControl) !== null && _d !== void 0 ? _d : null; }
280
+ if (!ngControl) {
281
+ throw new Error('The ngControl is not defined!');
282
+ }
283
+ if (!(ngControl instanceof NgControl)) {
284
+ throw new Error('The AbstractControlDirective is not a NgControl!');
285
+ }
286
+ this.ngControl = ngControl;
287
+ const control = this.ngControl.control;
288
+ if (!(control instanceof RxapFormControl)) {
289
+ throw new Error('Control is not a RxapFormControl!');
290
+ }
291
+ return this.control = control;
292
+ }
293
+ }
294
+
295
+ const DATA_SOURCE_NAME = 'options';
296
+ function ComposeOptionsTransformers(...fnc) {
297
+ return base => fnc.reduce((source, transform) => transform(source), base);
298
+ }
299
+ function UseOptionsDataSource(dataSource, settings) {
277
300
  return function (target, propertyKey) {
278
- const value = { dataSource, settings };
279
- setMetadataMapMap(propertyKey, name, value, FormSystemMetadataKeys.DATA_SOURCES, target);
301
+ UseDataSource(dataSource, DATA_SOURCE_NAME, settings)(target, propertyKey);
302
+ };
303
+ }
304
+ let ExtractOptionsDataSourceMixin = class ExtractOptionsDataSourceMixin {
305
+ extractOptionsDatasource(control) {
306
+ var _a, _b;
307
+ control !== null && control !== void 0 ? control : (control = this.extractControl());
308
+ if (!(control instanceof RxapFormControl)) {
309
+ throw new Error('Ensure to use a RxapFromControl');
310
+ }
311
+ const formDefinition = this.extractFormDefinition(control);
312
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
313
+ if (!useDataSourceValueMap.has('options')) {
314
+ throw new Error(`The data source with the name 'options' is not defined`);
315
+ }
316
+ const useDataSourceValue = this.useDataSourceValue = useDataSourceValueMap.get('options');
317
+ this.settings = (_a = this.useDataSourceValue.settings) !== null && _a !== void 0 ? _a : {};
318
+ let dataSource;
319
+ try {
320
+ dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
321
+ }
322
+ catch (e) {
323
+ if (e.name && e.name === 'NullInjectorError') {
324
+ if (isDevMode()) {
325
+ console.error('Cloud not inject the options data source', this.useDataSourceValue);
326
+ }
327
+ throw new Error('Cloud not inject the options data source:\n' + e.message);
328
+ }
329
+ throw e;
330
+ }
331
+ if ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.transformer) {
332
+ dataSource = new PipeDataSource(dataSource, map(this.settings.transformer), tap(options => useDataSourceValue.lastValue = options));
333
+ }
334
+ else {
335
+ dataSource = new PipeDataSource(dataSource, tap(options => useDataSourceValue.lastValue = options));
336
+ }
337
+ return this.dataSource = dataSource;
338
+ }
339
+ };
340
+ ExtractOptionsDataSourceMixin = __decorate([
341
+ Mixin(ExtractControlMixin, ExtractFormDefinitionMixin, ExtractDataSourcesMixin)
342
+ ], ExtractOptionsDataSourceMixin);
343
+
344
+ function UseComponent(component, setProperties = {}) {
345
+ return function (target, propertyKey) {
346
+ setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
347
+ setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
280
348
  };
281
349
  }
282
350
 
@@ -326,7 +394,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
326
394
  if (!this.ngControl && !this.controlId) {
327
395
  throw new Error('If the NgControl is not injectable then the control id must be defined!');
328
396
  }
329
- const control = (_b = (_a = this.ngControl) === null || _a === void 0 ? void 0 : _a.control) !== null && _b !== void 0 ? _b : this.extractControl(this.parent, this.controlId);
397
+ const control = (_b = (_a = this.ngControl) === null || _a === void 0 ? void 0 : _a.control) !== null && _b !== void 0 ? _b : this.extractControlFromParent(this.parent, this.controlId);
330
398
  if (!(control instanceof RxapFormControl)) {
331
399
  throw new Error('The control is not an instance of RxapFormControl');
332
400
  }
@@ -421,7 +489,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
421
489
  ControlHideShowDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: ControlHideShowDirective, deps: [{ token: Renderer2 }, { token: ElementRef }, { token: ControlContainer, optional: true }, { token: NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
422
490
  ControlHideShowDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", type: ControlHideShowDirective, selector: "[rxapControlHideShow]", inputs: { controlId: ["rxapControlHideShow", "controlId"] }, ngImport: i0 });
423
491
  ControlHideShowDirective = __decorate([
424
- Mixin(ExtractControlMixin, ExtractFormDefinitionMixin),
492
+ Mixin(ExtractControlFromParentMixin, ExtractFormDefinitionMixin),
425
493
  __metadata("design:paramtypes", [Renderer2,
426
494
  ElementRef, Object, Object])
427
495
  ], ControlHideShowDirective);
@@ -467,15 +535,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
467
535
  }]
468
536
  }] });
469
537
 
470
- const DATA_SOURCE_NAME = 'options';
471
- function ComposeOptionsTransformers(...fnc) {
472
- return base => fnc.reduce((source, transform) => transform(source), base);
473
- }
474
- function UseOptionsDataSource(dataSource, settings) {
475
- return function (target, propertyKey) {
476
- UseDataSource(dataSource, DATA_SOURCE_NAME, settings)(target, propertyKey);
477
- };
478
- }
479
538
  let InputSelectOptionsDirective = class InputSelectOptionsDirective {
480
539
  constructor(template, dataSourceLoader, viewContainerRef, injector, cdr,
481
540
  // The ngControl could be unknown on construction
@@ -491,82 +550,77 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
491
550
  this.viewer = { id: '[rxapInputSelectOptions]' };
492
551
  this.subscription = new Subscription();
493
552
  this.options = null;
553
+ /**
554
+ * This flag is used to prevent the setValue is called for each refresh
555
+ * of the options list. This is needed because the setValue method will
556
+ * trigger a new refresh of the options list. This results in an endless
557
+ * call stack. This flag is set to true if the setValue method is called
558
+ * once.
559
+ */
560
+ this.isAutocompleteToDisplayTriggered = false;
494
561
  }
495
562
  ngAfterViewInit() {
496
- this.extractControl();
497
- this.extractDatasource();
563
+ var _b, _c, _d;
564
+ var _a;
565
+ this.extractOptionsDatasource();
498
566
  this.viewer = {
499
567
  id: '[rxapInputSelectOptions]' + this.control.controlId,
500
- viewChange: this.control.value$.pipe(map(value => {
501
- var _a;
502
- if ((_a = this.settings) === null || _a === void 0 ? void 0 : _a.ignoreSelectedValue) {
568
+ viewChange: ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.loadOnce) ? EMPTY : this.control.value$.pipe(throttleTime(1000), distinctUntilChanged((a, b) => equals(a, b)), map(value => {
569
+ var _b;
570
+ if ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.ignoreSelectedValue) {
503
571
  return {};
504
572
  }
505
573
  return value;
506
574
  })),
507
575
  control: this.control,
508
576
  };
509
- this.loadOptions();
510
577
  if (this.matAutocomplete) {
511
578
  this.matAutocomplete.displayWith = this.toDisplay.bind(this);
579
+ (_c = this.settings) !== null && _c !== void 0 ? _c : (this.settings = {});
580
+ (_d = (_a = this.settings).filteredOptions) !== null && _d !== void 0 ? _d : (_a.filteredOptions = true);
512
581
  }
513
- }
514
- extractDatasource(control = this.control) {
515
- const formDefinition = this.extractFormDefinition(control);
516
- const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
517
- if (!useDataSourceValueMap.has(DATA_SOURCE_NAME)) {
518
- throw new Error(`The data source with the name 'options' is not defined`);
519
- }
520
- const useDataSourceValue = useDataSourceValueMap.get(DATA_SOURCE_NAME);
521
- this.settings = useDataSourceValue.settings;
522
- let dataSource;
523
- try {
524
- dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
525
- }
526
- catch (e) {
527
- if (e.name && e.name === 'NullInjectorError') {
528
- if (isDevMode()) {
529
- console.error('Cloud not inject the options data source', useDataSourceValue);
530
- }
531
- throw new Error('Cloud not inject the options data source:\n' + e.message);
532
- }
533
- throw e;
534
- }
535
- const settings = useDataSourceValue.settings;
536
- if (settings === null || settings === void 0 ? void 0 : settings.transformer) {
537
- dataSource = new PipeDataSource(dataSource, map(settings.transformer));
538
- }
539
- return this.dataSource = dataSource;
582
+ this.loadOptions();
540
583
  }
541
584
  toDisplay(value) {
542
- var _a, _b, _c;
585
+ var _b, _c, _d;
543
586
  if (!value) {
544
587
  return '';
545
588
  }
546
- return (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.find((option) => option.value === value)) === null || _b === void 0 ? void 0 : _b.display) !== null && _c !== void 0 ? _c : (isDevMode() ? 'to display error' : '');
547
- }
548
- extractControl(ngControl) {
549
- var _a, _b, _c, _d;
550
- if (ngControl === void 0) { ngControl = (_d = (_a = this.ngControl) !== null && _a !== void 0 ? _a : (_c = (_b = this.matFormField) === null || _b === void 0 ? void 0 : _b._control) === null || _c === void 0 ? void 0 : _c.ngControl) !== null && _d !== void 0 ? _d : null; }
551
- if (!ngControl) {
552
- throw new Error('The ngControl is not defined!');
553
- }
554
- if (!(ngControl instanceof NgControl)) {
555
- throw new Error(`The control is not an instance of ngControl`);
556
- }
557
- this.ngControl = ngControl;
558
- const control = this.ngControl.control;
559
- if (!(control instanceof RxapFormControl)) {
560
- throw new Error('Control is not a RxapFormControl!');
561
- }
562
- return this.control = control;
589
+ return (_d = (_c = (_b = this.options) === null || _b === void 0 ? void 0 : _b.find((option) => option.value === value)) === null || _c === void 0 ? void 0 : _c.display) !== null && _d !== void 0 ? _d : (isDevMode() ? 'to display error' : '');
563
590
  }
564
591
  ngOnDestroy() {
565
- var _a;
566
- (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
592
+ var _b;
593
+ (_b = this.subscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
567
594
  }
568
595
  loadOptions(dataSource = this.dataSource) {
569
- this.subscription.add(dataSource.connect(this.viewer).pipe(tap(options => this.renderTemplate(this.options = options))).subscribe());
596
+ this.subscription.add(dataSource.connect(this.viewer).pipe(switchMap(options => {
597
+ var _b;
598
+ if ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.filteredOptions) {
599
+ return this.control.value$.pipe(map(controlValue => {
600
+ if (typeof controlValue === 'string' && controlValue) {
601
+ controlValue = controlValue.toLowerCase();
602
+ if (Array.isArray(options)) {
603
+ return options.filter(option => option.display.toLowerCase().includes(controlValue));
604
+ }
605
+ else {
606
+ return Object.entries(options)
607
+ .filter(([value, display]) => typeof display === 'string' && display.toLowerCase().includes(controlValue))
608
+ .map(([value, display]) => ({ value, display }));
609
+ }
610
+ }
611
+ return options;
612
+ }));
613
+ }
614
+ return of(options);
615
+ }), tap(options => this.renderTemplate(this.options = options)), tap(() => {
616
+ var _b, _c, _d, _e;
617
+ if (this.matAutocomplete && !this.isAutocompleteToDisplayTriggered) {
618
+ this.isAutocompleteToDisplayTriggered = true;
619
+ // trigger a change detection after the options are rendered
620
+ // this is needed to trigger the mat-autocomplete options to display function
621
+ (_c = (_b = this.ngControl) === null || _b === void 0 ? void 0 : _b.control) === null || _c === void 0 ? void 0 : _c.setValue((_e = (_d = this.ngControl) === null || _d === void 0 ? void 0 : _d.control) === null || _e === void 0 ? void 0 : _e.value);
622
+ }
623
+ })).subscribe());
570
624
  }
571
625
  renderTemplate(options = this.options) {
572
626
  this.viewContainerRef.clear();
@@ -601,7 +655,7 @@ __decorate([
601
655
  __metadata("design:type", BaseDataSource)
602
656
  ], InputSelectOptionsDirective.prototype, "dataSource", void 0);
603
657
  InputSelectOptionsDirective = __decorate([
604
- Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin),
658
+ Mixin(ExtractOptionsDataSourceMixin),
605
659
  __metadata("design:paramtypes", [TemplateRef,
606
660
  DataSourceLoader,
607
661
  ViewContainerRef,
@@ -617,7 +671,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
617
671
  return [{ type: i0.TemplateRef, decorators: [{
618
672
  type: Inject,
619
673
  args: [TemplateRef]
620
- }] }, { type: i2.DataSourceLoader, decorators: [{
674
+ }] }, { type: i1$1.DataSourceLoader, decorators: [{
621
675
  type: Inject,
622
676
  args: [DataSourceLoader]
623
677
  }] }, { type: i0.ViewContainerRef, decorators: [{
@@ -745,11 +799,95 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
745
799
  }]
746
800
  }] });
747
801
 
802
+ var IsSelectableValueDirective_1;
803
+ let IsSelectableValueDirective = IsSelectableValueDirective_1 = class IsSelectableValueDirective {
804
+ constructor(dataSourceLoader, injector) {
805
+ this.dataSourceLoader = dataSourceLoader;
806
+ this.injector = injector;
807
+ this.viewer = { id: '[rxapIsSelectableValue]' };
808
+ }
809
+ validate(control) {
810
+ var _a;
811
+ if (control.value) {
812
+ this.extractOptionsDatasource(control);
813
+ const data = (_a = this.useDataSourceValue) === null || _a === void 0 ? void 0 : _a.lastValue;
814
+ if (data) {
815
+ let options;
816
+ if (Array.isArray(data)) {
817
+ options = data;
818
+ }
819
+ else {
820
+ options = Object.entries(data).map(([value, display]) => ({ value, display }));
821
+ }
822
+ if (!options.some(option => option.value === control.value)) {
823
+ return {
824
+ isSelectableValue: {
825
+ expected: 'Value should be from the list of provided options',
826
+ }
827
+ };
828
+ }
829
+ }
830
+ else if (isDevMode()) {
831
+ console.warn('The last value from the OptionsDataSource is empty', this);
832
+ }
833
+ }
834
+ return null;
835
+ }
836
+ };
837
+ IsSelectableValueDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirective, deps: [{ token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive });
838
+ IsSelectableValueDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", type: IsSelectableValueDirective, selector: "[rxapIsSelectableValue]", inputs: { viewer: "viewer" }, providers: [
839
+ {
840
+ provide: NG_VALIDATORS,
841
+ multi: true,
842
+ useExisting: forwardRef(() => IsSelectableValueDirective_1)
843
+ }
844
+ ], ngImport: i0 });
845
+ IsSelectableValueDirective = IsSelectableValueDirective_1 = __decorate([
846
+ Mixin(ExtractOptionsDataSourceMixin),
847
+ __metadata("design:paramtypes", [DataSourceLoader,
848
+ Injector])
849
+ ], IsSelectableValueDirective);
850
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
851
+ type: Directive,
852
+ args: [{
853
+ selector: '[rxapIsSelectableValue]',
854
+ providers: [
855
+ {
856
+ provide: NG_VALIDATORS,
857
+ multi: true,
858
+ useExisting: forwardRef(() => IsSelectableValueDirective)
859
+ }
860
+ ]
861
+ }]
862
+ }], ctorParameters: function () {
863
+ return [{ type: i1$1.DataSourceLoader, decorators: [{
864
+ type: Inject,
865
+ args: [DataSourceLoader]
866
+ }] }, { type: i0.Injector, decorators: [{
867
+ type: Inject,
868
+ args: [INJECTOR]
869
+ }] }];
870
+ }, propDecorators: { viewer: [{
871
+ type: Input
872
+ }] } });
873
+ class IsSelectableValueDirectiveModule {
874
+ }
875
+ IsSelectableValueDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
876
+ IsSelectableValueDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, declarations: [IsSelectableValueDirective], exports: [IsSelectableValueDirective] });
877
+ IsSelectableValueDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule });
878
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, decorators: [{
879
+ type: NgModule,
880
+ args: [{
881
+ declarations: [IsSelectableValueDirective],
882
+ exports: [IsSelectableValueDirective]
883
+ }]
884
+ }] });
885
+
748
886
  // endregion
749
887
 
750
888
  /**
751
889
  * Generated bundle index. Do not edit.
752
890
  */
753
891
 
754
- export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, ControlHideShowDirectiveModule, DATA_SOURCE_NAME, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, FormSystemControlDirective, FormSystemDirectivesModule, FormSystemMetadataKeys, FormSystemModule, InputSelectOptionsDirective, InputSelectOptionsDirectiveModule, IsEqualToDirective, IsEqualToDirectiveModule, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RxapFormSystemError, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseShowFunction, controlDataSource };
892
+ export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, ControlHideShowDirectiveModule, DATA_SOURCE_NAME, ExtractControlFromParentMixin, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, ExtractOptionsDataSourceMixin, FormSystemControlDirective, FormSystemDirectivesModule, FormSystemMetadataKeys, FormSystemModule, InputSelectOptionsDirective, InputSelectOptionsDirectiveModule, IsEqualToDirective, IsEqualToDirectiveModule, IsSelectableValueDirective, IsSelectableValueDirectiveModule, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RxapFormSystemError, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseShowFunction, controlDataSource };
755
893
  //# sourceMappingURL=rxap-form-system.mjs.map