@rxap/form-system 14.0.1 → 14.1.0-dev.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaXMtc2VsZWN0YWJsZS12YWx1ZS5kaXJlY3RpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9saWJzL2Zvcm0tc3lzdGVtL3NyYy9saWIvdmFsaWRhdG9ycy9pcy1zZWxlY3RhYmxlLXZhbHVlLmRpcmVjdGl2ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLE9BQU8sRUFBbUIsYUFBYSxFQUErQixNQUFNLGdCQUFnQixDQUFDO0FBQzdGLE9BQU8sRUFBRSxTQUFTLEVBQUUsVUFBVSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLEtBQUssRUFBRSxTQUFTLEVBQUUsUUFBUSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBQzlHLE9BQU8sRUFBd0IsZ0JBQWdCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUMzRSxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRXBDLE9BQU8sRUFBRSw2QkFBNkIsRUFBRSxNQUFNLDZDQUE2QyxDQUFDOzs7SUFlL0UsMEJBQTBCLHdDQUExQiwwQkFBMEI7SUFLckMsWUFFcUIsZ0JBQWtDLEVBRWxDLFFBQWtCO1FBRmxCLHFCQUFnQixHQUFoQixnQkFBZ0IsQ0FBa0I7UUFFbEMsYUFBUSxHQUFSLFFBQVEsQ0FBVTtRQU5oQyxXQUFNLEdBQXlCLEVBQUUsRUF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bHVlID09PSBjb250cm9sLnZhbHVlKSkge1xuICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBpc1NlbGVjdGFibGVWYWx1ZToge1xuICAgICAgICAgICAgICBleHBlY3RlZDogJ1ZhbHVlIHNob3VsZCBiZSBmcm9tIHRoZSBsaXN0IG9mIHByb3ZpZGVkIG9wdGlvbnMnLFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChpc0Rldk1vZGUoKSkge1xuICAgICAgICBjb25zb2xlLndhcm4oJ1RoZSBsYXN0IHZhbHVlIGZyb20gdGhlIE9wdGlvbnNEYXRhU291cmNlIGlzIGVtcHR5JywgdGhpcyk7XG4gICAgICB9XG4gICAgfVxuICAgIHJldHVybiBudWxsO1xuICB9XG5cbn1cblxuQE5nTW9kdWxlKHtcbiAgZGVjbGFyYXRpb25zOiBbSXNTZWxlY3RhYmxlVmFsdWVEaXJlY3RpdmVdLFxuICBleHBvcnRzOiBbSXNTZWxlY3RhYmxlVmFsdWVEaXJlY3RpdmVdXG59KVxuZXhwb3J0IGNsYXNzIElzU2VsZWN0YWJsZVZhbHVlRGlyZWN0aXZlTW9kdWxlIHt9XG4iXX0=
@@ -5,11 +5,11 @@ 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';
11
+ import { getMetadata, setMetadataMapMap, setMetadataMap, setMetadata } from '@rxap/utilities/reflect-metadata';
12
+ import { map, startWith, distinctUntilChanged, shareReplay, tap, catchError, switchMap } from 'rxjs/operators';
13
13
  import { Subscription, of } from 'rxjs';
14
14
  import * as i3 from '@angular/material/form-field';
15
15
  import { MAT_FORM_FIELD } from '@angular/material/form-field';
@@ -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
@@ -493,80 +552,62 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
493
552
  this.options = null;
494
553
  }
495
554
  ngAfterViewInit() {
496
- this.extractControl();
497
- this.extractDatasource();
555
+ var _b, _c;
556
+ var _a;
557
+ this.extractOptionsDatasource();
498
558
  this.viewer = {
499
559
  id: '[rxapInputSelectOptions]' + this.control.controlId,
500
560
  viewChange: this.control.value$.pipe(map(value => {
501
- var _a;
502
- if ((_a = this.settings) === null || _a === void 0 ? void 0 : _a.ignoreSelectedValue) {
561
+ var _b;
562
+ if ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.ignoreSelectedValue) {
503
563
  return {};
504
564
  }
505
565
  return value;
506
566
  })),
507
567
  control: this.control,
508
568
  };
509
- this.loadOptions();
510
569
  if (this.matAutocomplete) {
511
570
  this.matAutocomplete.displayWith = this.toDisplay.bind(this);
571
+ (_b = this.settings) !== null && _b !== void 0 ? _b : (this.settings = {});
572
+ (_c = (_a = this.settings).filteredOptions) !== null && _c !== void 0 ? _c : (_a.filteredOptions = true);
512
573
  }
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;
574
+ this.loadOptions();
540
575
  }
541
576
  toDisplay(value) {
542
- var _a, _b, _c;
577
+ var _b, _c, _d;
543
578
  if (!value) {
544
579
  return '';
545
580
  }
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;
581
+ 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
582
  }
564
583
  ngOnDestroy() {
565
- var _a;
566
- (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
584
+ var _b;
585
+ (_b = this.subscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
567
586
  }
568
587
  loadOptions(dataSource = this.dataSource) {
569
- this.subscription.add(dataSource.connect(this.viewer).pipe(tap(options => this.renderTemplate(this.options = options))).subscribe());
588
+ this.subscription.add(dataSource.connect(this.viewer).pipe(switchMap(options => {
589
+ var _b;
590
+ if ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.filteredOptions) {
591
+ return this.control.value$.pipe(map(controlValue => {
592
+ if (typeof controlValue === 'string' && controlValue) {
593
+ controlValue = controlValue.toLowerCase();
594
+ if (Array.isArray(options)) {
595
+ return options.filter(option => option.display.toLowerCase().includes(controlValue));
596
+ }
597
+ else {
598
+ return Object.entries(options)
599
+ .filter(([value, display]) => typeof display === 'string' && display.toLowerCase().includes(controlValue))
600
+ .map(([value, display]) => ({ value, display }));
601
+ }
602
+ }
603
+ return options;
604
+ }));
605
+ }
606
+ return of(options);
607
+ }), tap(options => this.renderTemplate(this.options = options)),
608
+ // trigger a change detection after the options are rendered
609
+ // this is needed to trigger the mat-autocomplete options to display function
610
+ tap(() => { var _b, _c, _d, _e; return (_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); })).subscribe());
570
611
  }
571
612
  renderTemplate(options = this.options) {
572
613
  this.viewContainerRef.clear();
@@ -601,7 +642,7 @@ __decorate([
601
642
  __metadata("design:type", BaseDataSource)
602
643
  ], InputSelectOptionsDirective.prototype, "dataSource", void 0);
603
644
  InputSelectOptionsDirective = __decorate([
604
- Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin),
645
+ Mixin(ExtractOptionsDataSourceMixin),
605
646
  __metadata("design:paramtypes", [TemplateRef,
606
647
  DataSourceLoader,
607
648
  ViewContainerRef,
@@ -617,7 +658,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
617
658
  return [{ type: i0.TemplateRef, decorators: [{
618
659
  type: Inject,
619
660
  args: [TemplateRef]
620
- }] }, { type: i2.DataSourceLoader, decorators: [{
661
+ }] }, { type: i1$1.DataSourceLoader, decorators: [{
621
662
  type: Inject,
622
663
  args: [DataSourceLoader]
623
664
  }] }, { type: i0.ViewContainerRef, decorators: [{
@@ -745,11 +786,95 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
745
786
  }]
746
787
  }] });
747
788
 
789
+ var IsSelectableValueDirective_1;
790
+ let IsSelectableValueDirective = IsSelectableValueDirective_1 = class IsSelectableValueDirective {
791
+ constructor(dataSourceLoader, injector) {
792
+ this.dataSourceLoader = dataSourceLoader;
793
+ this.injector = injector;
794
+ this.viewer = { id: '[rxapIsSelectableValue]' };
795
+ }
796
+ validate(control) {
797
+ var _a;
798
+ if (control.value) {
799
+ this.extractOptionsDatasource(control);
800
+ const data = (_a = this.useDataSourceValue) === null || _a === void 0 ? void 0 : _a.lastValue;
801
+ if (data) {
802
+ let options;
803
+ if (Array.isArray(data)) {
804
+ options = data;
805
+ }
806
+ else {
807
+ options = Object.entries(data).map(([value, display]) => ({ value, display }));
808
+ }
809
+ if (!options.some(option => option.value === control.value)) {
810
+ return {
811
+ isSelectableValue: {
812
+ expected: 'Value should be from the list of provided options',
813
+ }
814
+ };
815
+ }
816
+ }
817
+ else if (isDevMode()) {
818
+ console.warn('The last value from the OptionsDataSource is empty', this);
819
+ }
820
+ }
821
+ return null;
822
+ }
823
+ };
824
+ 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 });
825
+ IsSelectableValueDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", type: IsSelectableValueDirective, selector: "[rxapIsSelectableValue]", inputs: { viewer: "viewer" }, providers: [
826
+ {
827
+ provide: NG_VALIDATORS,
828
+ multi: true,
829
+ useExisting: forwardRef(() => IsSelectableValueDirective_1)
830
+ }
831
+ ], ngImport: i0 });
832
+ IsSelectableValueDirective = IsSelectableValueDirective_1 = __decorate([
833
+ Mixin(ExtractOptionsDataSourceMixin),
834
+ __metadata("design:paramtypes", [DataSourceLoader,
835
+ Injector])
836
+ ], IsSelectableValueDirective);
837
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
838
+ type: Directive,
839
+ args: [{
840
+ selector: '[rxapIsSelectableValue]',
841
+ providers: [
842
+ {
843
+ provide: NG_VALIDATORS,
844
+ multi: true,
845
+ useExisting: forwardRef(() => IsSelectableValueDirective)
846
+ }
847
+ ]
848
+ }]
849
+ }], ctorParameters: function () {
850
+ return [{ type: i1$1.DataSourceLoader, decorators: [{
851
+ type: Inject,
852
+ args: [DataSourceLoader]
853
+ }] }, { type: i0.Injector, decorators: [{
854
+ type: Inject,
855
+ args: [INJECTOR]
856
+ }] }];
857
+ }, propDecorators: { viewer: [{
858
+ type: Input
859
+ }] } });
860
+ class IsSelectableValueDirectiveModule {
861
+ }
862
+ IsSelectableValueDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
863
+ IsSelectableValueDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, declarations: [IsSelectableValueDirective], exports: [IsSelectableValueDirective] });
864
+ IsSelectableValueDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule });
865
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: IsSelectableValueDirectiveModule, decorators: [{
866
+ type: NgModule,
867
+ args: [{
868
+ declarations: [IsSelectableValueDirective],
869
+ exports: [IsSelectableValueDirective]
870
+ }]
871
+ }] });
872
+
748
873
  // endregion
749
874
 
750
875
  /**
751
876
  * Generated bundle index. Do not edit.
752
877
  */
753
878
 
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 };
879
+ 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
880
  //# sourceMappingURL=rxap-form-system.mjs.map