@rxap/form-system 12.1.0 → 13.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 (64) hide show
  1. package/esm2020/index.mjs +26 -0
  2. package/esm2020/lib/control-data-source.mjs +38 -0
  3. package/esm2020/lib/control-with-data-source.mjs +2 -0
  4. package/esm2020/lib/decorators/metadata-keys.mjs +8 -0
  5. package/esm2020/lib/decorators/use-component.mjs +9 -0
  6. package/esm2020/lib/decorators/use-data-source.mjs +9 -0
  7. package/esm2020/lib/decorators/use-form-component.mjs +13 -0
  8. package/esm2020/lib/directives/control-hide-show.directive.mjs +183 -0
  9. package/esm2020/lib/directives/form-directives.module.mjs +21 -0
  10. package/esm2020/lib/directives/input-select-options.directive.mjs +199 -0
  11. package/esm2020/lib/error.mjs +7 -0
  12. package/esm2020/lib/form-system-control.directive.mjs +158 -0
  13. package/esm2020/lib/form-system.module.mjs +17 -0
  14. package/esm2020/lib/mixins/extract-control.mixin.mjs +21 -0
  15. package/esm2020/lib/mixins/extract-data-sources.mixin.mjs +16 -0
  16. package/esm2020/lib/mixins/extract-form-definition.mixin.mjs +12 -0
  17. package/esm2020/lib/validators/is-equal-to.mjs +70 -0
  18. package/esm2020/rxap-form-system.mjs +5 -0
  19. package/fesm2015/rxap-form-system.mjs +743 -0
  20. package/fesm2015/rxap-form-system.mjs.map +1 -0
  21. package/{fesm2015/rxap-form-system.js → fesm2020/rxap-form-system.mjs} +47 -58
  22. package/fesm2020/rxap-form-system.mjs.map +1 -0
  23. package/package.json +38 -24
  24. package/src/schematics/ng-add/index.js +1 -1
  25. package/src/schematics/ng-add/index.js.map +1 -1
  26. package/bundles/rxap-form-system.umd.js +0 -1199
  27. package/bundles/rxap-form-system.umd.js.map +0 -1
  28. package/esm2015/index.js +0 -26
  29. package/esm2015/index.js.map +0 -1
  30. package/esm2015/lib/control-data-source.js +0 -38
  31. package/esm2015/lib/control-data-source.js.map +0 -1
  32. package/esm2015/lib/control-with-data-source.js +0 -2
  33. package/esm2015/lib/control-with-data-source.js.map +0 -1
  34. package/esm2015/lib/decorators/metadata-keys.js +0 -8
  35. package/esm2015/lib/decorators/metadata-keys.js.map +0 -1
  36. package/esm2015/lib/decorators/use-component.js +0 -9
  37. package/esm2015/lib/decorators/use-component.js.map +0 -1
  38. package/esm2015/lib/decorators/use-data-source.js +0 -9
  39. package/esm2015/lib/decorators/use-data-source.js.map +0 -1
  40. package/esm2015/lib/decorators/use-form-component.js +0 -13
  41. package/esm2015/lib/decorators/use-form-component.js.map +0 -1
  42. package/esm2015/lib/directives/control-hide-show.directive.js +0 -187
  43. package/esm2015/lib/directives/control-hide-show.directive.js.map +0 -1
  44. package/esm2015/lib/directives/form-directives.module.js +0 -21
  45. package/esm2015/lib/directives/form-directives.module.js.map +0 -1
  46. package/esm2015/lib/directives/input-select-options.directive.js +0 -206
  47. package/esm2015/lib/directives/input-select-options.directive.js.map +0 -1
  48. package/esm2015/lib/error.js +0 -7
  49. package/esm2015/lib/error.js.map +0 -1
  50. package/esm2015/lib/form-system-control.directive.js +0 -158
  51. package/esm2015/lib/form-system-control.directive.js.map +0 -1
  52. package/esm2015/lib/form-system.module.js +0 -17
  53. package/esm2015/lib/form-system.module.js.map +0 -1
  54. package/esm2015/lib/mixins/extract-control.mixin.js +0 -21
  55. package/esm2015/lib/mixins/extract-control.mixin.js.map +0 -1
  56. package/esm2015/lib/mixins/extract-data-sources.mixin.js +0 -16
  57. package/esm2015/lib/mixins/extract-data-sources.mixin.js.map +0 -1
  58. package/esm2015/lib/mixins/extract-form-definition.mixin.js +0 -12
  59. package/esm2015/lib/mixins/extract-form-definition.mixin.js.map +0 -1
  60. package/esm2015/lib/validators/is-equal-to.js +0 -70
  61. package/esm2015/lib/validators/is-equal-to.js.map +0 -1
  62. package/esm2015/rxap-form-system.js +0 -5
  63. package/esm2015/rxap-form-system.js.map +0 -1
  64. package/fesm2015/rxap-form-system.js.map +0 -1
@@ -0,0 +1,743 @@
1
+ import * as i0 from '@angular/core';
2
+ import { ComponentFactoryResolver, ViewContainerRef, INJECTOR, ComponentRef, Injector, Directive, Inject, Input, NgModule, InjectionToken, Injectable, Optional, Renderer2, ElementRef, Self, isDevMode, TemplateRef, ChangeDetectorRef, forwardRef } from '@angular/core';
3
+ import { __decorate, __metadata } from 'tslib';
4
+ import { RxapError, Required, equals } from '@rxap/utilities';
5
+ import * as i1 from '@angular/forms';
6
+ import { ControlContainer, NgControl, NG_VALIDATORS } from '@angular/forms';
7
+ import { RxapFormControl, RxapFormGroup, RxapFormArray } from '@rxap/forms';
8
+ import * as i2 from '@rxap/data-source';
9
+ import { PipeDataSource, DataSourceLoader, BaseDataSource, RXAP_DATA_SOURCE_METADATA } from '@rxap/data-source';
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';
14
+ import * as i3 from '@angular/material/form-field';
15
+ import { MAT_FORM_FIELD } from '@angular/material/form-field';
16
+
17
+ class RxapFormSystemError extends RxapError {
18
+ constructor(message, code, className) {
19
+ super('@rxap/form-system', message, code, className);
20
+ }
21
+ }
22
+
23
+ var FormSystemMetadataKeys;
24
+ (function (FormSystemMetadataKeys) {
25
+ FormSystemMetadataKeys["COMPONENTS"] = "rxap/form-system/components";
26
+ FormSystemMetadataKeys["DATA_SOURCES"] = "rxap/form-system/data-sources";
27
+ FormSystemMetadataKeys["COMPONENTS_PROPERTIES"] = "rxap/form-system/components-properties";
28
+ FormSystemMetadataKeys["FORM_COMPONENT"] = "rxap/window-form-system/form-component";
29
+ })(FormSystemMetadataKeys || (FormSystemMetadataKeys = {}));
30
+
31
+ class ExtractDataSourcesMixin {
32
+ extractDataSources(formDefinition, controlId) {
33
+ const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
34
+ if (!map) {
35
+ throw new RxapFormSystemError('Could not extract the use data source map from the form definition instance', '');
36
+ }
37
+ if (!map.has(controlId)) {
38
+ throw new RxapFormSystemError('A use data source definition does not exists in the form definition metadata', '');
39
+ }
40
+ return map.get(controlId);
41
+ }
42
+ }
43
+
44
+ let FormSystemControlDirective = class FormSystemControlDirective {
45
+ constructor(parent, cfr, viewContainerRef, dataSourceLoader, injector) {
46
+ this.parent = parent;
47
+ this.cfr = cfr;
48
+ this.viewContainerRef = viewContainerRef;
49
+ this.dataSourceLoader = dataSourceLoader;
50
+ this.injector = injector;
51
+ }
52
+ ngOnInit() {
53
+ this.control = this.extractControl();
54
+ const formDefinition = this.extractFormDefinition();
55
+ this.componentRef = this.createComponent(formDefinition);
56
+ this.setDataSources(formDefinition, this.componentRef.instance);
57
+ this.setComponentProperties(formDefinition, this.componentRef.instance);
58
+ this.viewContainerRef.insert(this.componentRef.hostView);
59
+ }
60
+ registerOnChange(fn) {
61
+ this.componentRef.instance.registerOnChange(fn);
62
+ }
63
+ registerOnTouched(fn) {
64
+ this.componentRef.instance.registerOnTouched(fn);
65
+ }
66
+ writeValue(value) {
67
+ this.componentRef.instance.writeValue(value);
68
+ }
69
+ setDisabledState(isDisabled) {
70
+ if (this.componentRef.instance.setDisabledState) {
71
+ this.componentRef.instance.setDisabledState(isDisabled);
72
+ }
73
+ }
74
+ setDataSources(formDefinition, component) {
75
+ if (!component.setDataSource) {
76
+ throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
77
+ }
78
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
79
+ for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
80
+ let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
81
+ const settings = useDataSourceValue.settings;
82
+ if (settings === null || settings === void 0 ? void 0 : settings.transformer) {
83
+ dataSource = new PipeDataSource(dataSource, map(settings.transformer));
84
+ }
85
+ component.setDataSource(name, dataSource, useDataSourceValue.settings);
86
+ }
87
+ }
88
+ setComponentProperties(formDefinition, component) {
89
+ const componentProperties = this.extractComponentProperties(formDefinition);
90
+ for (const [key, value] of Object.entries(componentProperties)) {
91
+ Reflect.set(component, key, value);
92
+ }
93
+ }
94
+ createComponent(formDefinition) {
95
+ const component = this.extractComponent(formDefinition);
96
+ const componentFactory = this.cfr.resolveComponentFactory(component);
97
+ return componentFactory.create(this.injector);
98
+ }
99
+ extractControl() {
100
+ if (!this.parent.control) {
101
+ throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
102
+ }
103
+ const control = this.parent.control.get(this.controlId);
104
+ if (!control) {
105
+ throw new RxapFormSystemError('Could not find the control instance', '');
106
+ }
107
+ if (!(control instanceof RxapFormControl)) {
108
+ throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
109
+ }
110
+ return control;
111
+ }
112
+ extractFormDefinition() {
113
+ const formDefinition = this.control.rxapFormDefinition;
114
+ if (!formDefinition) {
115
+ throw new RxapFormSystemError('Could not find the form definition instance', '');
116
+ }
117
+ return formDefinition;
118
+ }
119
+ extractComponent(formDefinition) {
120
+ const map = getMetadata(FormSystemMetadataKeys.COMPONENTS, Object.getPrototypeOf(formDefinition));
121
+ if (!map) {
122
+ throw new RxapFormSystemError('Could not extract the use component map from the form definition instance', '');
123
+ }
124
+ if (!map.has(this.controlId)) {
125
+ throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
126
+ }
127
+ return map.get(this.controlId);
128
+ }
129
+ extractComponentProperties(formDefinition) {
130
+ const map = getMetadata(FormSystemMetadataKeys.COMPONENTS_PROPERTIES, Object.getPrototypeOf(formDefinition));
131
+ if (!map) {
132
+ throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
133
+ }
134
+ if (!map.has(this.controlId)) {
135
+ throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
136
+ }
137
+ return map.get(this.controlId);
138
+ }
139
+ };
140
+ FormSystemControlDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemControlDirective, deps: [{ token: ControlContainer }, { token: ComponentFactoryResolver }, { token: ViewContainerRef }, { token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive });
141
+ FormSystemControlDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSystemControlDirective, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 });
142
+ __decorate([
143
+ Required,
144
+ __metadata("design:type", String)
145
+ ], FormSystemControlDirective.prototype, "controlId", void 0);
146
+ __decorate([
147
+ Required,
148
+ __metadata("design:type", RxapFormControl)
149
+ ], FormSystemControlDirective.prototype, "control", void 0);
150
+ __decorate([
151
+ Required,
152
+ __metadata("design:type", ComponentRef)
153
+ ], FormSystemControlDirective.prototype, "componentRef", void 0);
154
+ FormSystemControlDirective = __decorate([
155
+ Mixin(ExtractDataSourcesMixin),
156
+ __metadata("design:paramtypes", [ControlContainer,
157
+ ComponentFactoryResolver,
158
+ ViewContainerRef,
159
+ DataSourceLoader,
160
+ Injector])
161
+ ], FormSystemControlDirective);
162
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemControlDirective, decorators: [{
163
+ type: Directive,
164
+ args: [{
165
+ selector: '[rxapFormSystemControl]'
166
+ }]
167
+ }], ctorParameters: function () {
168
+ return [{ type: i1.ControlContainer, decorators: [{
169
+ type: Inject,
170
+ args: [ControlContainer]
171
+ }] }, { type: i0.ComponentFactoryResolver, decorators: [{
172
+ type: Inject,
173
+ args: [ComponentFactoryResolver]
174
+ }] }, { type: i0.ViewContainerRef, decorators: [{
175
+ type: Inject,
176
+ args: [ViewContainerRef]
177
+ }] }, { type: i2.DataSourceLoader, decorators: [{
178
+ type: Inject,
179
+ args: [DataSourceLoader]
180
+ }] }, { type: i0.Injector, decorators: [{
181
+ type: Inject,
182
+ args: [INJECTOR]
183
+ }] }];
184
+ }, propDecorators: { controlId: [{
185
+ type: Input
186
+ }], control: [], componentRef: [] } });
187
+
188
+ class FormSystemModule {
189
+ }
190
+ FormSystemModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
191
+ FormSystemModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemModule, declarations: [FormSystemControlDirective], exports: [FormSystemControlDirective] });
192
+ FormSystemModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemModule, imports: [[]] });
193
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemModule, decorators: [{
194
+ type: NgModule,
195
+ args: [{
196
+ declarations: [FormSystemControlDirective],
197
+ exports: [FormSystemControlDirective],
198
+ imports: []
199
+ }]
200
+ }] });
201
+
202
+ const RXAP_FORM_CONTROL_SOURCE = new InjectionToken('rxap/forms/data-source');
203
+ class ControlDataSource extends BaseDataSource {
204
+ constructor(control, metadata = null) {
205
+ super(metadata);
206
+ this.control = control;
207
+ }
208
+ init() {
209
+ if (this._initialised) {
210
+ return;
211
+ }
212
+ super.init();
213
+ console.log(this.control);
214
+ this._data$ = this.control.valueChanges.pipe(startWith(this.control.value), distinctUntilChanged((a, b) => equals(a, b)), shareReplay(1));
215
+ }
216
+ }
217
+ ControlDataSource.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlDataSource, deps: [{ token: RXAP_FORM_CONTROL_SOURCE }, { token: RXAP_DATA_SOURCE_METADATA, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
218
+ ControlDataSource.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlDataSource });
219
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlDataSource, decorators: [{
220
+ type: Injectable
221
+ }], ctorParameters: function () {
222
+ return [{ type: undefined, decorators: [{
223
+ type: Inject,
224
+ args: [RXAP_FORM_CONTROL_SOURCE]
225
+ }] }, { type: undefined, decorators: [{
226
+ type: Optional
227
+ }, {
228
+ type: Inject,
229
+ args: [RXAP_DATA_SOURCE_METADATA]
230
+ }] }];
231
+ } });
232
+ function controlDataSource(control) {
233
+ // TODO : remove as any (wait for @rxap/forms update)
234
+ return new ControlDataSource(control, { id: control.controlId });
235
+ }
236
+
237
+ class ExtractControlMixin {
238
+ extractControl(parent, controlPath) {
239
+ if (!controlPath) {
240
+ throw new RxapFormSystemError('The control path is empty', '');
241
+ }
242
+ if (!parent.control) {
243
+ throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
244
+ }
245
+ const control = parent.control.get(controlPath);
246
+ if (!control) {
247
+ throw new RxapFormSystemError('Could not find the control instance', '');
248
+ }
249
+ if (!(control instanceof RxapFormControl) && !(control instanceof RxapFormGroup) && !(control instanceof RxapFormArray)) {
250
+ throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
251
+ }
252
+ return control;
253
+ }
254
+ }
255
+
256
+ class ExtractFormDefinitionMixin {
257
+ // TODO : change to AbstractControl from @rxap/forms
258
+ extractFormDefinition(control) {
259
+ const formDefinition = control.rxapFormDefinition;
260
+ if (!formDefinition) {
261
+ throw new RxapFormSystemError('Could not find the form definition instance', '');
262
+ }
263
+ return formDefinition;
264
+ }
265
+ }
266
+
267
+ function UseComponent(component, setProperties = {}) {
268
+ return function (target, propertyKey) {
269
+ setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
270
+ setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
271
+ };
272
+ }
273
+
274
+ function UseDataSource(dataSource, name, settings) {
275
+ return function (target, propertyKey) {
276
+ const value = { dataSource, settings };
277
+ setMetadataMapMap(propertyKey, name, value, FormSystemMetadataKeys.DATA_SOURCES, target);
278
+ };
279
+ }
280
+
281
+ /**
282
+ * Links a component with a form definition
283
+ *
284
+ * @param component
285
+ */
286
+ function UseFormComponent(component) {
287
+ return function (target) {
288
+ setMetadata(FormSystemMetadataKeys.FORM_COMPONENT, component, target);
289
+ };
290
+ }
291
+
292
+ const RXAP_FORM_SYSTEM_SHOW_METADATA = 'rxap/form-system/show-function';
293
+ const RXAP_FORM_SYSTEM_HIDE_METADATA = 'rxap/form-system/hide-function';
294
+ const RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS = 'rxap/form-system/hide-show-options';
295
+ function UseHideFunction(hideFunction, options = {}) {
296
+ return function (target, propertyKey) {
297
+ setMetadataMap(propertyKey, hideFunction, RXAP_FORM_SYSTEM_HIDE_METADATA, target);
298
+ if (Object.keys(options).length) {
299
+ setMetadataMap(propertyKey, options, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, target);
300
+ }
301
+ };
302
+ }
303
+ function UseShowFunction(showFunction, options = {}) {
304
+ return function (target, propertyKey) {
305
+ setMetadataMap(propertyKey, showFunction, RXAP_FORM_SYSTEM_SHOW_METADATA, target);
306
+ if (Object.keys(options).length) {
307
+ setMetadataMap(propertyKey, options, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, target);
308
+ }
309
+ };
310
+ }
311
+ let ControlHideShowDirective = class ControlHideShowDirective {
312
+ constructor(renderer, elementRef, parent, ngControl) {
313
+ this.renderer = renderer;
314
+ this.elementRef = elementRef;
315
+ this.parent = parent;
316
+ this.ngControl = ngControl;
317
+ this.subscription = new Subscription();
318
+ }
319
+ ngOnInit() {
320
+ var _a, _b;
321
+ if (!this.ngControl && !this.parent) {
322
+ throw new Error('Easier the ControlContainer or NgControl must be injectable');
323
+ }
324
+ if (!this.ngControl && !this.controlId) {
325
+ throw new Error('If the NgControl is not injectable then the control id must be defined!');
326
+ }
327
+ 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);
328
+ if (!(control instanceof RxapFormControl)) {
329
+ throw new Error('The control is not an instance of RxapFormControl');
330
+ }
331
+ this.control = control;
332
+ const formDefinition = this.extractFormDefinition(control);
333
+ const hideFunction = this.extractHideFunction(formDefinition);
334
+ const showFunction = this.extractShowFunction(formDefinition);
335
+ const options = this.extractOptions(formDefinition);
336
+ let changeTrigger = formDefinition.rxapFormGroup.valueChanges;
337
+ if (options.rootChange) {
338
+ changeTrigger = formDefinition.rxapFormGroup.root.valueChanges;
339
+ }
340
+ changeTrigger = changeTrigger.pipe(startWith(null));
341
+ if (showFunction) {
342
+ this.subscription.add(changeTrigger.pipe(tap(() => {
343
+ // TODO : resubscribe if the showFunction throws an error
344
+ const show = showFunction.call(formDefinition, control);
345
+ switch (show) {
346
+ case true:
347
+ this.show();
348
+ break;
349
+ case false:
350
+ this.hide();
351
+ break;
352
+ case null:
353
+ this.reset();
354
+ break;
355
+ }
356
+ }), catchError(err => {
357
+ console.error(err);
358
+ return of(null);
359
+ })).subscribe());
360
+ }
361
+ if (hideFunction) {
362
+ this.subscription.add(changeTrigger.pipe(tap(() => {
363
+ // TODO : resubscribe if the hideFunction throws an error
364
+ const hide = hideFunction.call(formDefinition, control);
365
+ switch (hide) {
366
+ case true:
367
+ this.hide();
368
+ break;
369
+ case false:
370
+ this.show();
371
+ break;
372
+ case null:
373
+ this.reset();
374
+ break;
375
+ }
376
+ }), catchError(err => {
377
+ console.error(err);
378
+ return of(null);
379
+ })).subscribe());
380
+ }
381
+ }
382
+ ngOnDestroy() {
383
+ this.subscription.unsubscribe();
384
+ }
385
+ extractOptions(formDefinition) {
386
+ var _a;
387
+ const map = (_a = getMetadata(RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, Object.getPrototypeOf(formDefinition))) !== null && _a !== void 0 ? _a : null;
388
+ if (!map || !map.has(this.control.controlId)) {
389
+ return {};
390
+ }
391
+ return map.get(this.control.controlId);
392
+ }
393
+ extractHideFunction(formDefinition) {
394
+ var _a;
395
+ const map = (_a = getMetadata(RXAP_FORM_SYSTEM_HIDE_METADATA, Object.getPrototypeOf(formDefinition))) !== null && _a !== void 0 ? _a : null;
396
+ if (!map || !map.has(this.control.controlId)) {
397
+ return null;
398
+ }
399
+ return map.get(this.control.controlId);
400
+ }
401
+ extractShowFunction(formDefinition) {
402
+ var _a;
403
+ const map = (_a = getMetadata(RXAP_FORM_SYSTEM_SHOW_METADATA, Object.getPrototypeOf(formDefinition))) !== null && _a !== void 0 ? _a : null;
404
+ if (!map || !map.has(this.control.controlId)) {
405
+ return null;
406
+ }
407
+ return map.get(this.control.controlId);
408
+ }
409
+ hide() {
410
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
411
+ }
412
+ show() {
413
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'block');
414
+ }
415
+ reset() {
416
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
417
+ }
418
+ };
419
+ ControlHideShowDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlHideShowDirective, deps: [{ token: Renderer2 }, { token: ElementRef }, { token: ControlContainer, optional: true }, { token: NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
420
+ ControlHideShowDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ControlHideShowDirective, selector: "[rxapControlHideShow]", inputs: { controlId: ["rxapControlHideShow", "controlId"] }, ngImport: i0 });
421
+ ControlHideShowDirective = __decorate([
422
+ Mixin(ExtractControlMixin, ExtractFormDefinitionMixin),
423
+ __metadata("design:paramtypes", [Renderer2,
424
+ ElementRef, Object, Object])
425
+ ], ControlHideShowDirective);
426
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlHideShowDirective, decorators: [{
427
+ type: Directive,
428
+ args: [{
429
+ selector: '[rxapControlHideShow]'
430
+ }]
431
+ }], ctorParameters: function () {
432
+ return [{ type: i0.Renderer2, decorators: [{
433
+ type: Inject,
434
+ args: [Renderer2]
435
+ }] }, { type: i0.ElementRef, decorators: [{
436
+ type: Inject,
437
+ args: [ElementRef]
438
+ }] }, { type: i1.ControlContainer, decorators: [{
439
+ type: Optional
440
+ }, {
441
+ type: Inject,
442
+ args: [ControlContainer]
443
+ }] }, { type: i1.NgControl, decorators: [{
444
+ type: Self
445
+ }, {
446
+ type: Optional
447
+ }, {
448
+ type: Inject,
449
+ args: [NgControl]
450
+ }] }];
451
+ }, propDecorators: { controlId: [{
452
+ type: Input,
453
+ args: ['rxapControlHideShow']
454
+ }] } });
455
+ class ControlHideShowDirectiveModule {
456
+ }
457
+ ControlHideShowDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlHideShowDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
458
+ ControlHideShowDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlHideShowDirectiveModule, declarations: [ControlHideShowDirective], exports: [ControlHideShowDirective] });
459
+ ControlHideShowDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlHideShowDirectiveModule });
460
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ControlHideShowDirectiveModule, decorators: [{
461
+ type: NgModule,
462
+ args: [{
463
+ declarations: [ControlHideShowDirective],
464
+ exports: [ControlHideShowDirective]
465
+ }]
466
+ }] });
467
+
468
+ const DATA_SOURCE_NAME = 'options';
469
+ function ComposeOptionsTransformers(...fnc) {
470
+ return base => fnc.reduce((source, transform) => transform(source), base);
471
+ }
472
+ function UseOptionsDataSource(dataSource, settings) {
473
+ return function (target, propertyKey) {
474
+ UseDataSource(dataSource, DATA_SOURCE_NAME, settings)(target, propertyKey);
475
+ };
476
+ }
477
+ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
478
+ constructor(template, dataSourceLoader, viewContainerRef, injector, cdr,
479
+ // The ngControl could be unknown on construction
480
+ // bc it is available after the content is init
481
+ ngControl = null, matFormField = null) {
482
+ this.template = template;
483
+ this.dataSourceLoader = dataSourceLoader;
484
+ this.viewContainerRef = viewContainerRef;
485
+ this.injector = injector;
486
+ this.cdr = cdr;
487
+ this.ngControl = ngControl;
488
+ this.matFormField = matFormField;
489
+ this.viewer = { id: '[rxapInputSelectOptions]' };
490
+ this.subscription = new Subscription();
491
+ this.options = null;
492
+ }
493
+ ngAfterViewInit() {
494
+ this.extractControl();
495
+ this.extractDatasource();
496
+ this.viewer = {
497
+ id: '[rxapInputSelectOptions]' + this.control.controlId,
498
+ viewChange: this.control.value$,
499
+ control: this.control,
500
+ };
501
+ this.loadOptions();
502
+ if (this.matAutocomplete) {
503
+ this.matAutocomplete.displayWith = this.toDisplay.bind(this);
504
+ }
505
+ }
506
+ extractDatasource(control = this.control) {
507
+ const formDefinition = this.extractFormDefinition(control);
508
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
509
+ if (!useDataSourceValueMap.has(DATA_SOURCE_NAME)) {
510
+ throw new Error(`The data source with the name 'options' is not defined`);
511
+ }
512
+ const useDataSourceValue = useDataSourceValueMap.get(DATA_SOURCE_NAME);
513
+ let dataSource;
514
+ try {
515
+ dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
516
+ }
517
+ catch (e) {
518
+ if (e.name && e.name === 'NullInjectorError') {
519
+ if (isDevMode()) {
520
+ console.error('Cloud not inject the options data source', useDataSourceValue);
521
+ }
522
+ throw new Error('Cloud not inject the options data source:\n' + e.message);
523
+ }
524
+ throw e;
525
+ }
526
+ const settings = useDataSourceValue.settings;
527
+ if (settings === null || settings === void 0 ? void 0 : settings.transformer) {
528
+ dataSource = new PipeDataSource(dataSource, map(settings.transformer));
529
+ }
530
+ return this.dataSource = dataSource;
531
+ }
532
+ toDisplay(value) {
533
+ var _a, _b, _c;
534
+ if (!value) {
535
+ return '';
536
+ }
537
+ 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' : '');
538
+ }
539
+ extractControl(ngControl) {
540
+ var _a, _b, _c, _d;
541
+ 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; }
542
+ if (!ngControl) {
543
+ throw new Error('The ngControl is not defined!');
544
+ }
545
+ this.ngControl = ngControl;
546
+ const control = this.ngControl.control;
547
+ if (!(control instanceof RxapFormControl)) {
548
+ throw new Error('Control is not a RxapFormControl!');
549
+ }
550
+ return this.control = control;
551
+ }
552
+ ngOnDestroy() {
553
+ var _a;
554
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
555
+ }
556
+ loadOptions(dataSource = this.dataSource) {
557
+ this.subscription.add(dataSource.connect(this.viewer).pipe(tap(options => this.renderTemplate(this.options = options))).subscribe());
558
+ }
559
+ renderTemplate(options = this.options) {
560
+ this.viewContainerRef.clear();
561
+ if (options) {
562
+ if (!Array.isArray(options)) {
563
+ for (const [value, display] of Object.entries(options)) {
564
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: { value, display } });
565
+ }
566
+ }
567
+ else {
568
+ for (const option of options) {
569
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
570
+ }
571
+ }
572
+ }
573
+ else {
574
+ if (isDevMode()) {
575
+ console.warn(`The options for the control ${this.control.fullControlPath} is empty/null/undefined!`);
576
+ }
577
+ }
578
+ this.cdr.detectChanges();
579
+ }
580
+ };
581
+ InputSelectOptionsDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: InputSelectOptionsDirective, deps: [{ token: TemplateRef }, { token: DataSourceLoader }, { token: ViewContainerRef }, { token: INJECTOR }, { token: ChangeDetectorRef }, { token: NgControl, optional: true }, { token: MAT_FORM_FIELD, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
582
+ InputSelectOptionsDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: InputSelectOptionsDirective, selector: "[rxapInputSelectOptions]", inputs: { viewer: ["rxapInputSelectOptionsViewer", "viewer"], metadata: ["rxapInputSelectOptionsMetadata", "metadata"], matAutocomplete: ["rxapInputSelectOptionsMatAutocomplete", "matAutocomplete"] }, ngImport: i0 });
583
+ __decorate([
584
+ Required,
585
+ __metadata("design:type", RxapFormControl)
586
+ ], InputSelectOptionsDirective.prototype, "control", void 0);
587
+ __decorate([
588
+ Required,
589
+ __metadata("design:type", BaseDataSource)
590
+ ], InputSelectOptionsDirective.prototype, "dataSource", void 0);
591
+ InputSelectOptionsDirective = __decorate([
592
+ Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin),
593
+ __metadata("design:paramtypes", [TemplateRef,
594
+ DataSourceLoader,
595
+ ViewContainerRef,
596
+ Injector,
597
+ ChangeDetectorRef, Object, Object])
598
+ ], InputSelectOptionsDirective);
599
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: InputSelectOptionsDirective, decorators: [{
600
+ type: Directive,
601
+ args: [{
602
+ selector: '[rxapInputSelectOptions]'
603
+ }]
604
+ }], ctorParameters: function () {
605
+ return [{ type: i0.TemplateRef, decorators: [{
606
+ type: Inject,
607
+ args: [TemplateRef]
608
+ }] }, { type: i2.DataSourceLoader, decorators: [{
609
+ type: Inject,
610
+ args: [DataSourceLoader]
611
+ }] }, { type: i0.ViewContainerRef, decorators: [{
612
+ type: Inject,
613
+ args: [ViewContainerRef]
614
+ }] }, { type: i0.Injector, decorators: [{
615
+ type: Inject,
616
+ args: [INJECTOR]
617
+ }] }, { type: i0.ChangeDetectorRef, decorators: [{
618
+ type: Inject,
619
+ args: [ChangeDetectorRef]
620
+ }] }, { type: i1.NgControl, decorators: [{
621
+ type: Optional
622
+ }, {
623
+ type: Inject,
624
+ args: [NgControl]
625
+ }] }, { type: i3.MatFormField, decorators: [{
626
+ type: Optional
627
+ }, {
628
+ type: Inject,
629
+ args: [MAT_FORM_FIELD]
630
+ }] }];
631
+ }, propDecorators: { viewer: [{
632
+ type: Input,
633
+ args: ['rxapInputSelectOptionsViewer']
634
+ }], metadata: [{
635
+ type: Input,
636
+ args: ['rxapInputSelectOptionsMetadata']
637
+ }], matAutocomplete: [{
638
+ type: Input,
639
+ args: ['rxapInputSelectOptionsMatAutocomplete']
640
+ }], control: [], dataSource: [] } });
641
+ class InputSelectOptionsDirectiveModule {
642
+ }
643
+ InputSelectOptionsDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: InputSelectOptionsDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
644
+ InputSelectOptionsDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: InputSelectOptionsDirectiveModule, declarations: [InputSelectOptionsDirective], exports: [InputSelectOptionsDirective] });
645
+ InputSelectOptionsDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: InputSelectOptionsDirectiveModule });
646
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: InputSelectOptionsDirectiveModule, decorators: [{
647
+ type: NgModule,
648
+ args: [{
649
+ declarations: [InputSelectOptionsDirective],
650
+ exports: [InputSelectOptionsDirective]
651
+ }]
652
+ }] });
653
+
654
+ class FormSystemDirectivesModule {
655
+ }
656
+ FormSystemDirectivesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
657
+ FormSystemDirectivesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemDirectivesModule, exports: [InputSelectOptionsDirectiveModule,
658
+ ControlHideShowDirectiveModule] });
659
+ FormSystemDirectivesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemDirectivesModule, imports: [InputSelectOptionsDirectiveModule,
660
+ ControlHideShowDirectiveModule] });
661
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSystemDirectivesModule, decorators: [{
662
+ type: NgModule,
663
+ args: [{
664
+ exports: [
665
+ InputSelectOptionsDirectiveModule,
666
+ ControlHideShowDirectiveModule
667
+ ]
668
+ }]
669
+ }] });
670
+
671
+ class IsEqualToDirective {
672
+ set equalTo(value) {
673
+ this._equalTo = value;
674
+ if (this._onChange) {
675
+ this._onChange();
676
+ }
677
+ }
678
+ validate(control) {
679
+ if (this._equalTo === null || this._equalTo === control.value) {
680
+ return null;
681
+ }
682
+ return { isEqualTo: { value: this._equalTo, actualValue: control.value } };
683
+ }
684
+ /**
685
+ * @description
686
+ * Registers a callback function to call when the validator inputs change.
687
+ *
688
+ * @param fn The callback function
689
+ */
690
+ registerOnValidatorChange(fn) {
691
+ this._onChange = fn;
692
+ }
693
+ }
694
+ IsEqualToDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: IsEqualToDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
695
+ IsEqualToDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: IsEqualToDirective, selector: "[rxapIsEqualTo]", inputs: { equalTo: ["rxapIsEqualTo", "equalTo"] }, providers: [
696
+ {
697
+ provide: NG_VALIDATORS,
698
+ multi: true,
699
+ useExisting: forwardRef(() => IsEqualToDirective)
700
+ }
701
+ ], ngImport: i0 });
702
+ __decorate([
703
+ Required,
704
+ __metadata("design:type", Object),
705
+ __metadata("design:paramtypes", [Object])
706
+ ], IsEqualToDirective.prototype, "equalTo", null);
707
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: IsEqualToDirective, decorators: [{
708
+ type: Directive,
709
+ args: [{
710
+ selector: '[rxapIsEqualTo]',
711
+ providers: [
712
+ {
713
+ provide: NG_VALIDATORS,
714
+ multi: true,
715
+ useExisting: forwardRef(() => IsEqualToDirective)
716
+ }
717
+ ]
718
+ }]
719
+ }], propDecorators: { equalTo: [{
720
+ type: Input,
721
+ args: ['rxapIsEqualTo']
722
+ }] } });
723
+ class IsEqualToDirectiveModule {
724
+ }
725
+ IsEqualToDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: IsEqualToDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
726
+ IsEqualToDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: IsEqualToDirectiveModule, declarations: [IsEqualToDirective], exports: [IsEqualToDirective] });
727
+ IsEqualToDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: IsEqualToDirectiveModule });
728
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: IsEqualToDirectiveModule, decorators: [{
729
+ type: NgModule,
730
+ args: [{
731
+ declarations: [IsEqualToDirective],
732
+ exports: [IsEqualToDirective]
733
+ }]
734
+ }] });
735
+
736
+ // endregion
737
+
738
+ /**
739
+ * Generated bundle index. Do not edit.
740
+ */
741
+
742
+ 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 };
743
+ //# sourceMappingURL=rxap-form-system.mjs.map