@rxap/form-system 16.0.0-dev.12 → 16.0.0-dev.14

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 (28) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -1
  3. package/esm2022/index.mjs +28 -19
  4. package/esm2022/lib/control-data-source.mjs +3 -3
  5. package/esm2022/lib/directives/array/for-form-array-items.directive.mjs +64 -0
  6. package/esm2022/lib/directives/array/form-array-add-item-button.directive.mjs +61 -0
  7. package/esm2022/lib/directives/array/form-array-item-button.mjs +71 -0
  8. package/esm2022/lib/directives/array/form-array-item-remove-button.directive.mjs +30 -0
  9. package/esm2022/lib/directives/array/form-array-item-restore-button.directive.mjs +30 -0
  10. package/esm2022/lib/directives/array/form-array-removable.directive.mjs +62 -0
  11. package/esm2022/lib/directives/control-hide-show.directive.mjs +3 -3
  12. package/esm2022/lib/directives/form-directives.module.mjs +4 -4
  13. package/esm2022/lib/directives/input-select-options.directive.mjs +3 -3
  14. package/esm2022/lib/directives/options-from-remote-method.directive.mjs +3 -3
  15. package/esm2022/lib/form-system-control.directive.mjs +3 -3
  16. package/esm2022/lib/submit-context-form-adapter.factory.mjs +3 -3
  17. package/esm2022/lib/validators/is-equal-to.mjs +3 -3
  18. package/esm2022/lib/validators/is-selectable-value.directive.mjs +3 -3
  19. package/fesm2022/rxap-form-system.mjs +760 -474
  20. package/fesm2022/rxap-form-system.mjs.map +1 -1
  21. package/index.d.ts +20 -13
  22. package/lib/directives/array/for-form-array-items.directive.d.ts +26 -0
  23. package/lib/directives/array/form-array-add-item-button.directive.d.ts +20 -0
  24. package/lib/directives/array/form-array-item-button.d.ts +29 -0
  25. package/lib/directives/array/form-array-item-remove-button.directive.d.ts +9 -0
  26. package/lib/directives/array/form-array-item-restore-button.directive.d.ts +9 -0
  27. package/lib/directives/array/form-array-removable.directive.d.ts +19 -0
  28. package/package.json +19 -19
@@ -1,223 +1,78 @@
1
- import { RxapError, equals } from '@rxap/utilities';
2
- import * as i1$1 from '@rxap/data-source';
3
- import { BaseDataSource, RXAP_DATA_SOURCE_METADATA, PipeDataSource, DataSourceLoader } from '@rxap/data-source';
4
1
  import * as i0 from '@angular/core';
5
- import { InjectionToken, isDevMode, Injectable, Inject, Optional, TemplateRef, ViewContainerRef, INJECTOR, ChangeDetectorRef, Injector, Directive, Input, ComponentFactoryResolver, Renderer2, ElementRef, Self, NgModule, forwardRef } from '@angular/core';
6
- import { startWith, distinctUntilChanged, shareReplay, map, tap, catchError, throttleTime, switchMap } from 'rxjs/operators';
7
- import { RXAP_FORM_CONTEXT, RxapFormControl, RxapFormGroup, RxapFormArray } from '@rxap/forms';
8
- import * as i2 from '@rxap/remote-method';
9
- import { ProxyRemoteMethod, RemoteMethodLoader } from '@rxap/remote-method';
2
+ import { forwardRef, Directive, Input, isDevMode, INJECTOR, Injector, Inject, SkipSelf, Optional, HostBinding, HostListener, Renderer2, ElementRef, Self, TemplateRef, ViewContainerRef, ChangeDetectorRef, NgModule, InjectionToken, Injectable, ComponentFactoryResolver } from '@angular/core';
3
+ import * as i1$1 from '@angular/forms';
4
+ import { NG_VALIDATORS, NgControl, UntypedFormGroup, UntypedFormArray, ControlContainer } from '@angular/forms';
10
5
  import { __decorate, __metadata } from 'tslib';
11
- import * as i1 from '@angular/forms';
12
- import { NgControl, ControlContainer, NG_VALIDATORS } from '@angular/forms';
6
+ import * as i1 from '@rxap/data-source';
7
+ import { PipeDataSource, DataSourceLoader, BaseDataSource, RXAP_DATA_SOURCE_METADATA } from '@rxap/data-source';
13
8
  import { Mixin } from '@rxap/mixin';
9
+ import { RxapFormControl, RxapFormGroup, RxapFormArray, RXAP_FORM_CONTEXT } from '@rxap/forms';
10
+ import { map, tap, startWith as startWith$1, catchError, throttleTime, distinctUntilChanged as distinctUntilChanged$1, switchMap, shareReplay } from 'rxjs/operators';
14
11
  import { setMetadataMapMap, getMetadata, setMetadataMap, setMetadata } from '@rxap/reflect-metadata';
15
- import { Subscription, of, EMPTY } from 'rxjs';
12
+ import { RxapError, equals } from '@rxap/utilities';
13
+ import { debounceTime, map as map$1, distinctUntilChanged, startWith, pairwise, tap as tap$1, Subscription, of, EMPTY } from 'rxjs';
14
+ import * as i2 from '@angular/material/button';
16
15
  import * as i3 from '@angular/material/form-field';
17
16
  import { MAT_FORM_FIELD } from '@angular/material/form-field';
18
17
  import '@angular/material/autocomplete';
18
+ import * as i2$1 from '@rxap/remote-method';
19
+ import { RemoteMethodLoader, ProxyRemoteMethod } from '@rxap/remote-method';
19
20
 
20
- class RxapFormSystemError extends RxapError {
21
- constructor(message, code, className) {
22
- super('@rxap/form-system', message, code, className);
23
- }
24
- }
25
-
26
- const RXAP_FORM_CONTROL_SOURCE = new InjectionToken('rxap/forms/data-source');
27
- class ControlDataSource extends BaseDataSource {
28
- constructor(control, metadata = null) {
29
- super(metadata);
30
- this.control = control;
31
- }
32
- init() {
33
- if (this._initialised) {
34
- return;
35
- }
36
- super.init();
37
- if (isDevMode()) {
38
- console.log(this.control);
21
+ class IsEqualToDirective {
22
+ set equalTo(value) {
23
+ this._equalTo = value;
24
+ if (this._onChange) {
25
+ this._onChange();
39
26
  }
40
- this._data$ = this.control.valueChanges.pipe(startWith(this.control.value), distinctUntilChanged((a, b) => equals(a, b)), shareReplay(1));
41
- }
42
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlDataSource, deps: [{ token: RXAP_FORM_CONTROL_SOURCE }, { token: RXAP_DATA_SOURCE_METADATA, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
43
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlDataSource }); }
44
- }
45
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlDataSource, decorators: [{
46
- type: Injectable
47
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
48
- type: Inject,
49
- args: [RXAP_FORM_CONTROL_SOURCE]
50
- }] }, { type: undefined, decorators: [{
51
- type: Optional
52
- }, {
53
- type: Inject,
54
- args: [RXAP_DATA_SOURCE_METADATA]
55
- }] }]; } });
56
- function controlDataSource(control) {
57
- // TODO : remove as any (wait for @rxap/forms update)
58
- return new ControlDataSource(control, { id: control.controlId });
59
- }
60
-
61
- function FormContextFromActivatedRouteFactory(route) {
62
- return route.snapshot.params;
63
- }
64
-
65
- const SUBMIT_CONTEXT_FORM_ADAPTER_METHOD = new InjectionToken('submit-context-form-adapter-method');
66
- class SubmitContextFormAdapter extends ProxyRemoteMethod {
67
- constructor(remoteMethod, context) {
68
- super(remoteMethod);
69
- this.context = context;
70
27
  }
71
- transformParameters(value) {
28
+ validate(control) {
29
+ if (this._equalTo === null || this._equalTo === control.value) {
30
+ return null;
31
+ }
72
32
  return {
73
- parameters: this.context ?? {},
74
- requestBody: value,
33
+ isEqualTo: {
34
+ value: this._equalTo,
35
+ actualValue: control.value,
36
+ },
75
37
  };
76
38
  }
77
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter, deps: [{ token: SUBMIT_CONTEXT_FORM_ADAPTER_METHOD }, { token: RXAP_FORM_CONTEXT }], target: i0.ɵɵFactoryTarget.Injectable }); }
78
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter }); }
79
- }
80
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter, decorators: [{
81
- type: Injectable
82
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
83
- type: Inject,
84
- args: [SUBMIT_CONTEXT_FORM_ADAPTER_METHOD]
85
- }] }, { type: undefined, decorators: [{
86
- type: Inject,
87
- args: [RXAP_FORM_CONTEXT]
88
- }] }]; } });
89
- function SubmitContextFormAdapterFactory(remoteMethod, context) {
90
- return new SubmitContextFormAdapter(remoteMethod, context);
91
- }
92
-
93
- class ExtractFormDefinitionMixin {
94
- // TODO : change to AbstractControl from @rxap/forms
95
- extractFormDefinition(control) {
96
- const formDefinition = control.rxapFormDefinition;
97
- if (!formDefinition) {
98
- throw new RxapFormSystemError('Could not find the form definition instance', '');
99
- }
100
- return formDefinition;
101
- }
102
- }
103
-
104
- const REMOTE_METHOD_NAME = 'options';
105
- const RXAP_USE_REMOTE_METHOD = 'rxap/form-system/remote-method/use';
106
- function UseRemoteMethod(remoteMethod, name) {
107
- return function (target, propertyKey) {
108
- setMetadataMapMap(propertyKey, name, remoteMethod, RXAP_USE_REMOTE_METHOD, target);
109
- };
110
- }
111
- function UseOptionsRemoteMethod(dataSource) {
112
- return function (target, propertyKey) {
113
- UseRemoteMethod(dataSource, REMOTE_METHOD_NAME)(target, propertyKey);
114
- };
115
- }
116
- class ExtractRemoteMethodsMixin {
117
- extractRemoteMethods(formDefinition, controlId) {
118
- const map = getMetadata(RXAP_USE_REMOTE_METHOD, Object.getPrototypeOf(formDefinition));
119
- if (!map) {
120
- throw new RxapFormSystemError('Could not extract the use remote method map from the form definition instance', '');
121
- }
122
- if (!map.has(controlId)) {
123
- throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
124
- }
125
- return map.get(controlId);
39
+ /**
40
+ * @description
41
+ * Registers a callback function to call when the validator inputs change.
42
+ *
43
+ * @param fn The callback function
44
+ */
45
+ registerOnValidatorChange(fn) {
46
+ this._onChange = fn;
126
47
  }
48
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: IsEqualToDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
49
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: IsEqualToDirective, isStandalone: true, selector: "[rxapIsEqualTo]", inputs: { equalTo: ["rxapIsEqualTo", "equalTo"] }, providers: [
50
+ {
51
+ provide: NG_VALIDATORS,
52
+ multi: true,
53
+ useExisting: forwardRef(() => IsEqualToDirective),
54
+ },
55
+ ], ngImport: i0 }); }
127
56
  }
128
- let OptionsFromRemoteMethodDirective = class OptionsFromRemoteMethodDirective {
129
- constructor(ngControl, template, remoteMethodLoader, viewContainerRef, injector, cdr) {
130
- this.ngControl = ngControl;
131
- this.template = template;
132
- this.remoteMethodLoader = remoteMethodLoader;
133
- this.viewContainerRef = viewContainerRef;
134
- this.injector = injector;
135
- this.cdr = cdr;
136
- this.withoutParameters = false;
137
- }
138
- ngOnChanges(changes) {
139
- const parametersChanges = changes['parameters'];
140
- if (parametersChanges) {
141
- if (!this.remoteMethodToken) {
142
- this.remoteMethodToken = this.extractRemoteMethodToken();
143
- }
144
- this.renderTemplate(parametersChanges.currentValue);
145
- }
146
- if (changes['withoutParameters']?.currentValue) {
147
- if (!this.remoteMethodToken) {
148
- this.remoteMethodToken = this.extractRemoteMethodToken();
149
- }
150
- this.renderTemplate();
151
- }
152
- }
153
- extractRemoteMethodToken() {
154
- const control = this.ngControl.control;
155
- if (!(control instanceof RxapFormControl)) {
156
- throw new Error('Control is not a RxapFormControl!');
157
- }
158
- const formDefinition = this.extractFormDefinition(control);
159
- const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
160
- if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
161
- throw new Error(`The remote method with the name 'options' is not defined`);
162
- }
163
- return remoteMethodsTokens.get(REMOTE_METHOD_NAME);
164
- }
165
- async renderTemplate(parameters) {
166
- const options = await this.remoteMethodLoader.call$(this.remoteMethodToken, parameters, undefined, this.injector);
167
- this.viewContainerRef.clear();
168
- for (const option of options) {
169
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
170
- }
171
- if (this.resetOnChange !== undefined) {
172
- this.ngControl.reset(this.resetOnChange);
173
- }
174
- this.cdr.detectChanges();
175
- }
176
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, deps: [{ token: NgControl }, { token: TemplateRef }, { token: RemoteMethodLoader }, { token: ViewContainerRef }, { token: INJECTOR }, { token: ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
177
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: OptionsFromRemoteMethodDirective, isStandalone: true, selector: "[rxapOptionsFromRemoteMethod]", inputs: { parameters: ["rxapOptionsFromRemoteMethodParameters", "parameters"], resetOnChange: ["rxapOptionsFromRemoteMethodResetOnChange", "resetOnChange"], withoutParameters: ["rxapOptionsFromRemoteMethodWithoutParameters", "withoutParameters"] }, usesOnChanges: true, ngImport: i0 }); }
178
- };
179
- OptionsFromRemoteMethodDirective = __decorate([
180
- Mixin(ExtractFormDefinitionMixin, ExtractRemoteMethodsMixin),
181
- __metadata("design:paramtypes", [NgControl,
182
- TemplateRef,
183
- RemoteMethodLoader,
184
- ViewContainerRef,
185
- Injector,
186
- ChangeDetectorRef])
187
- ], OptionsFromRemoteMethodDirective);
188
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, decorators: [{
57
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: IsEqualToDirective, decorators: [{
189
58
  type: Directive,
190
59
  args: [{
191
- selector: '[rxapOptionsFromRemoteMethod]',
60
+ selector: '[rxapIsEqualTo]',
61
+ providers: [
62
+ {
63
+ provide: NG_VALIDATORS,
64
+ multi: true,
65
+ useExisting: forwardRef(() => IsEqualToDirective),
66
+ },
67
+ ],
192
68
  standalone: true,
193
69
  }]
194
- }], ctorParameters: function () { return [{ type: i1.NgControl, decorators: [{
195
- type: Inject,
196
- args: [NgControl]
197
- }] }, { type: i0.TemplateRef, decorators: [{
198
- type: Inject,
199
- args: [TemplateRef]
200
- }] }, { type: i2.RemoteMethodLoader, decorators: [{
201
- type: Inject,
202
- args: [RemoteMethodLoader]
203
- }] }, { type: i0.ViewContainerRef, decorators: [{
204
- type: Inject,
205
- args: [ViewContainerRef]
206
- }] }, { type: i0.Injector, decorators: [{
207
- type: Inject,
208
- args: [INJECTOR]
209
- }] }, { type: i0.ChangeDetectorRef, decorators: [{
210
- type: Inject,
211
- args: [ChangeDetectorRef]
212
- }] }]; }, propDecorators: { parameters: [{
213
- type: Input,
214
- args: ['rxapOptionsFromRemoteMethodParameters']
215
- }], resetOnChange: [{
216
- type: Input,
217
- args: ['rxapOptionsFromRemoteMethodResetOnChange']
218
- }], withoutParameters: [{
70
+ }], propDecorators: { equalTo: [{
219
71
  type: Input,
220
- args: ['rxapOptionsFromRemoteMethodWithoutParameters']
72
+ args: [{
73
+ required: true,
74
+ alias: 'rxapIsEqualTo',
75
+ }]
221
76
  }] } });
222
77
 
223
78
  var FormSystemMetadataKeys;
@@ -228,40 +83,6 @@ var FormSystemMetadataKeys;
228
83
  FormSystemMetadataKeys["FORM_COMPONENT"] = "rxap/window-form-system/form-component";
229
84
  })(FormSystemMetadataKeys || (FormSystemMetadataKeys = {}));
230
85
 
231
- class ExtractDataSourcesMixin {
232
- extractDataSources(formDefinition, controlId) {
233
- const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
234
- if (!map) {
235
- throw new RxapFormSystemError('Could not extract the use data source map from the form definition instance', '');
236
- }
237
- if (!map.has(controlId)) {
238
- throw new RxapFormSystemError('A use data source definition does not exists in the form definition metadata', '');
239
- }
240
- return map.get(controlId);
241
- }
242
- }
243
-
244
- class ExtractControlFromParentMixin {
245
- extractControlFromParent(parent, controlPath) {
246
- if (!controlPath) {
247
- throw new RxapFormSystemError('The control path is empty', '');
248
- }
249
- if (!parent.control) {
250
- throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
251
- }
252
- const control = parent.control.get(controlPath);
253
- if (!control) {
254
- throw new RxapFormSystemError('Could not find the control instance', '');
255
- }
256
- if (!(control instanceof RxapFormControl) &&
257
- !(control instanceof RxapFormGroup) &&
258
- !(control instanceof RxapFormArray)) {
259
- throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
260
- }
261
- return control;
262
- }
263
- }
264
-
265
86
  function UseDataSource(dataSource, name, settings) {
266
87
  return function (target, propertyKey) {
267
88
  const value = {
@@ -291,9 +112,39 @@ class ExtractControlMixin {
291
112
  }
292
113
  }
293
114
 
294
- const DATA_SOURCE_NAME = 'options';
295
- function ComposeOptionsTransformers(...fnc) {
296
- return base => fnc.reduce((source, transform) => transform(source), base);
115
+ class RxapFormSystemError extends RxapError {
116
+ constructor(message, code, className) {
117
+ super('@rxap/form-system', message, code, className);
118
+ }
119
+ }
120
+
121
+ class ExtractDataSourcesMixin {
122
+ extractDataSources(formDefinition, controlId) {
123
+ const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
124
+ if (!map) {
125
+ throw new RxapFormSystemError('Could not extract the use data source map from the form definition instance', '');
126
+ }
127
+ if (!map.has(controlId)) {
128
+ throw new RxapFormSystemError('A use data source definition does not exists in the form definition metadata', '');
129
+ }
130
+ return map.get(controlId);
131
+ }
132
+ }
133
+
134
+ class ExtractFormDefinitionMixin {
135
+ // TODO : change to AbstractControl from @rxap/forms
136
+ extractFormDefinition(control) {
137
+ const formDefinition = control.rxapFormDefinition;
138
+ if (!formDefinition) {
139
+ throw new RxapFormSystemError('Could not find the form definition instance', '');
140
+ }
141
+ return formDefinition;
142
+ }
143
+ }
144
+
145
+ const DATA_SOURCE_NAME = 'options';
146
+ function ComposeOptionsTransformers(...fnc) {
147
+ return base => fnc.reduce((source, transform) => transform(source), base);
297
148
  }
298
149
  function UseOptionsDataSource(dataSource, settings) {
299
150
  return function (target, propertyKey) {
@@ -339,155 +190,385 @@ ExtractOptionsDataSourceMixin = __decorate([
339
190
  Mixin(ExtractControlMixin, ExtractFormDefinitionMixin, ExtractDataSourcesMixin)
340
191
  ], ExtractOptionsDataSourceMixin);
341
192
 
342
- let FormSystemControlDirective = class FormSystemControlDirective {
343
- constructor(parent, cfr, viewContainerRef, dataSourceLoader, injector) {
344
- this.parent = parent;
345
- this.cfr = cfr;
346
- this.viewContainerRef = viewContainerRef;
193
+ var IsSelectableValueDirective_1;
194
+ let IsSelectableValueDirective = class IsSelectableValueDirective {
195
+ static { IsSelectableValueDirective_1 = this; }
196
+ constructor(dataSourceLoader, injector) {
347
197
  this.dataSourceLoader = dataSourceLoader;
348
198
  this.injector = injector;
199
+ this.viewer = { id: '[rxapIsSelectableValue]' };
349
200
  }
350
- ngOnInit() {
351
- this.control = this.extractControl();
352
- const formDefinition = this.extractFormDefinition();
353
- this.componentRef = this.createComponent(formDefinition);
354
- this.setDataSources(formDefinition, this.componentRef.instance);
355
- this.setComponentProperties(formDefinition, this.componentRef.instance);
356
- this.viewContainerRef.insert(this.componentRef.hostView);
357
- }
358
- registerOnChange(fn) {
359
- this.componentRef.instance.registerOnChange(fn);
360
- }
361
- registerOnTouched(fn) {
362
- this.componentRef.instance.registerOnTouched(fn);
363
- }
364
- writeValue(value) {
365
- this.componentRef.instance.writeValue(value);
366
- }
367
- setDisabledState(isDisabled) {
368
- if (this.componentRef.instance.setDisabledState) {
369
- this.componentRef.instance.setDisabledState(isDisabled);
370
- }
371
- }
372
- setDataSources(formDefinition, component) {
373
- if (!component.setDataSource) {
374
- throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
375
- }
376
- const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
377
- for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
378
- let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
379
- const settings = useDataSourceValue.settings;
380
- if (settings?.transformer) {
381
- dataSource = new PipeDataSource(dataSource, map(settings.transformer));
201
+ validate(control) {
202
+ if (control.value) {
203
+ this.extractOptionsDatasource(control);
204
+ const data = this.useDataSourceValue?.lastValue;
205
+ if (data) {
206
+ let options;
207
+ if (Array.isArray(data)) {
208
+ options = data;
209
+ }
210
+ else {
211
+ options = Object.entries(data)
212
+ .map(([value, display]) => ({
213
+ value,
214
+ display,
215
+ }));
216
+ }
217
+ if (!options.some(option => option.value === control.value)) {
218
+ return {
219
+ isSelectableValue: {
220
+ expected: 'Value should be from the list of provided options',
221
+ },
222
+ };
223
+ }
224
+ }
225
+ else if (isDevMode()) {
226
+ console.warn('The last value from the OptionsDataSource is empty', this);
382
227
  }
383
- component.setDataSource(name, dataSource, useDataSourceValue.settings);
384
228
  }
229
+ return null;
385
230
  }
386
- setComponentProperties(formDefinition, component) {
387
- const componentProperties = this.extractComponentProperties(formDefinition);
388
- for (const [key, value] of Object.entries(componentProperties)) {
389
- Reflect.set(component, key, value);
231
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: IsSelectableValueDirective, deps: [{ token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive }); }
232
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: IsSelectableValueDirective, isStandalone: true, selector: "[rxapIsSelectableValue]", inputs: { viewer: "viewer" }, providers: [
233
+ {
234
+ provide: NG_VALIDATORS,
235
+ multi: true,
236
+ useExisting: forwardRef(() => IsSelectableValueDirective_1),
237
+ },
238
+ ], ngImport: i0 }); }
239
+ };
240
+ IsSelectableValueDirective = IsSelectableValueDirective_1 = __decorate([
241
+ Mixin(ExtractOptionsDataSourceMixin),
242
+ __metadata("design:paramtypes", [DataSourceLoader,
243
+ Injector])
244
+ ], IsSelectableValueDirective);
245
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
246
+ type: Directive,
247
+ args: [{
248
+ selector: '[rxapIsSelectableValue]',
249
+ providers: [
250
+ {
251
+ provide: NG_VALIDATORS,
252
+ multi: true,
253
+ useExisting: forwardRef(() => IsSelectableValueDirective),
254
+ },
255
+ ],
256
+ standalone: true,
257
+ }]
258
+ }], ctorParameters: function () { return [{ type: i1.DataSourceLoader, decorators: [{
259
+ type: Inject,
260
+ args: [DataSourceLoader]
261
+ }] }, { type: i0.Injector, decorators: [{
262
+ type: Inject,
263
+ args: [INJECTOR]
264
+ }] }]; }, propDecorators: { viewer: [{
265
+ type: Input
266
+ }] } });
267
+
268
+ class ExtractControlFromParentMixin {
269
+ extractControlFromParent(parent, controlPath) {
270
+ if (!controlPath) {
271
+ throw new RxapFormSystemError('The control path is empty', '');
390
272
  }
391
- }
392
- createComponent(formDefinition) {
393
- const component = this.extractComponent(formDefinition);
394
- const componentFactory = this.cfr.resolveComponentFactory(component);
395
- return componentFactory.create(this.injector);
396
- }
397
- extractControl() {
398
- if (!this.parent.control) {
273
+ if (!parent.control) {
399
274
  throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
400
275
  }
401
- const control = this.parent.control.get(this.controlId);
276
+ const control = parent.control.get(controlPath);
402
277
  if (!control) {
403
278
  throw new RxapFormSystemError('Could not find the control instance', '');
404
279
  }
405
- if (!(control instanceof RxapFormControl)) {
280
+ if (!(control instanceof RxapFormControl) &&
281
+ !(control instanceof RxapFormGroup) &&
282
+ !(control instanceof RxapFormArray)) {
406
283
  throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
407
284
  }
408
285
  return control;
409
286
  }
410
- extractFormDefinition() {
411
- const formDefinition = this.control.rxapFormDefinition;
412
- if (!formDefinition) {
413
- throw new RxapFormSystemError('Could not find the form definition instance', '');
414
- }
415
- return formDefinition;
287
+ }
288
+
289
+ // TODO : move to rxap packages
290
+ class ForFormArrayItemsDirective {
291
+ constructor(container, template, viewContainerRef, cdr) {
292
+ this.container = container;
293
+ this.template = template;
294
+ this.viewContainerRef = viewContainerRef;
295
+ this.cdr = cdr;
416
296
  }
417
- extractComponent(formDefinition) {
418
- const map = getMetadata(FormSystemMetadataKeys.COMPONENTS, Object.getPrototypeOf(formDefinition));
419
- if (!map) {
420
- throw new RxapFormSystemError('Could not extract the use component map from the form definition instance', '');
297
+ ngAfterViewInit() {
298
+ if (this.container.control instanceof RxapFormArray) {
299
+ this.formArray = this.container.control;
300
+ this.container.control.value$.pipe(debounceTime(100), map$1(value => value.length), distinctUntilChanged(), startWith(0), pairwise(), tap$1(([a, b]) => {
301
+ if (a !== b) {
302
+ this.render(b);
303
+ }
304
+ })).subscribe();
421
305
  }
422
- if (!map.has(this.controlId)) {
423
- throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
306
+ else {
307
+ throw new Error('The control container is not an instance of RxapFormArray');
424
308
  }
425
- return map.get(this.controlId);
426
309
  }
427
- extractComponentProperties(formDefinition) {
428
- const map = getMetadata(FormSystemMetadataKeys.COMPONENTS_PROPERTIES, Object.getPrototypeOf(formDefinition));
429
- if (!map) {
430
- throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
431
- }
432
- if (!map.has(this.controlId)) {
433
- throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
310
+ ngOnDestroy() {
311
+ this._formArrayValueSubscription?.unsubscribe();
312
+ }
313
+ render(length) {
314
+ this.viewContainerRef.clear();
315
+ for (let index = 0; index < length; index++) {
316
+ const group = this.formArray.at(index);
317
+ if (group instanceof UntypedFormGroup) {
318
+ this.viewContainerRef.createEmbeddedView(this.template, {
319
+ $implicit: group,
320
+ index,
321
+ first: index === 0,
322
+ last: index === length - 1,
323
+ even: index % 2 === 0,
324
+ odd: index % 2 !== 0,
325
+ array: this.formArray,
326
+ });
327
+ }
328
+ else {
329
+ throw new Error('rxapForFormArrayItem only support FormArray with FormGroup as items');
330
+ }
434
331
  }
435
- return map.get(this.controlId);
332
+ this.cdr.detectChanges();
436
333
  }
437
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, deps: [{ token: ControlContainer }, { token: ComponentFactoryResolver }, { token: ViewContainerRef }, { token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive }); }
438
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: FormSystemControlDirective, isStandalone: true, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 }); }
439
- };
440
- FormSystemControlDirective = __decorate([
441
- Mixin(ExtractDataSourcesMixin),
442
- __metadata("design:paramtypes", [ControlContainer,
443
- ComponentFactoryResolver,
444
- ViewContainerRef,
445
- DataSourceLoader,
446
- Injector])
447
- ], FormSystemControlDirective);
448
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
334
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ForFormArrayItemsDirective, deps: [{ token: i1$1.ControlContainer, skipSelf: true }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
335
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: ForFormArrayItemsDirective, isStandalone: true, selector: "[rxapForFormArrayItem]", ngImport: i0 }); }
336
+ }
337
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ForFormArrayItemsDirective, decorators: [{
449
338
  type: Directive,
450
339
  args: [{
451
- selector: '[rxapFormSystemControl]',
340
+ selector: '[rxapForFormArrayItem]',
452
341
  standalone: true,
453
342
  }]
454
- }], ctorParameters: function () { return [{ type: i1.ControlContainer, decorators: [{
455
- type: Inject,
456
- args: [ControlContainer]
457
- }] }, { type: i0.ComponentFactoryResolver, decorators: [{
458
- type: Inject,
459
- args: [ComponentFactoryResolver]
460
- }] }, { type: i0.ViewContainerRef, decorators: [{
461
- type: Inject,
462
- args: [ViewContainerRef]
463
- }] }, { type: i1$1.DataSourceLoader, decorators: [{
464
- type: Inject,
465
- args: [DataSourceLoader]
466
- }] }, { type: i0.Injector, decorators: [{
467
- type: Inject,
468
- args: [INJECTOR]
469
- }] }]; }, propDecorators: { controlId: [{
470
- type: Input,
471
- args: [{ required: true }]
472
- }] } });
343
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
344
+ type: SkipSelf
345
+ }] }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }]; } });
473
346
 
474
- function UseComponent(component, setProperties = {}) {
475
- return function (target, propertyKey) {
476
- setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
477
- setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
478
- };
347
+ // TODO : move to rxap packages
348
+ class FormArrayAddItemButtonDirective {
349
+ constructor(parent, matButton) {
350
+ this.parent = parent;
351
+ this.matButton = matButton;
352
+ this.type = 'button';
353
+ }
354
+ get disabled() {
355
+ return this.isDisabled;
356
+ }
357
+ get isDisabled() {
358
+ return !!this.formArray?.disabled;
359
+ }
360
+ ngAfterViewInit() {
361
+ if (this.parent.control instanceof RxapFormArray) {
362
+ this.formArray = this.parent.control;
363
+ }
364
+ if (this.matButton) {
365
+ this._controlDisabledSubscription = this.formArray.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
366
+ }
367
+ }
368
+ ngOnDestroy() {
369
+ this._controlDisabledSubscription?.unsubscribe();
370
+ }
371
+ onClick() {
372
+ this.formArray.insertAt();
373
+ }
374
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayAddItemButtonDirective, deps: [{ token: i1$1.ControlContainer, optional: true, skipSelf: true }, { token: i2.MatButton, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
375
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: FormArrayAddItemButtonDirective, isStandalone: true, selector: "[rxapFormArrayItemAddButton]", host: { listeners: { "click": "onClick()" }, properties: { "type": "this.type", "disabled": "this.disabled" } }, ngImport: i0 }); }
479
376
  }
377
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayAddItemButtonDirective, decorators: [{
378
+ type: Directive,
379
+ args: [{
380
+ selector: '[rxapFormArrayItemAddButton]',
381
+ standalone: true,
382
+ }]
383
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
384
+ type: Optional
385
+ }, {
386
+ type: SkipSelf
387
+ }] }, { type: i2.MatButton, decorators: [{
388
+ type: Optional
389
+ }] }]; }, propDecorators: { type: [{
390
+ type: HostBinding,
391
+ args: ['type']
392
+ }], disabled: [{
393
+ type: HostBinding,
394
+ args: ['disabled']
395
+ }], onClick: [{
396
+ type: HostListener,
397
+ args: ['click']
398
+ }] } });
480
399
 
481
- /**
482
- * Links a component with a form definition
483
- *
484
- * @param component
485
- */
486
- function UseFormComponent(component) {
487
- return function (target) {
488
- setMetadata(FormSystemMetadataKeys.FORM_COMPONENT, component, target);
489
- };
400
+ // TODO : move to rxap packages
401
+ class FormArrayItemButton {
402
+ constructor(parent, matButton, renderer, elementRef) {
403
+ this.parent = parent;
404
+ this.matButton = matButton;
405
+ this.renderer = renderer;
406
+ this.elementRef = elementRef;
407
+ this.type = 'button';
408
+ }
409
+ get disabled() {
410
+ return this.isDisabled;
411
+ }
412
+ get isDeleted() {
413
+ return this.deletedControl.value;
414
+ }
415
+ get index() {
416
+ return this.formGroup.parent.controls.findIndex(control => control === this.formGroup);
417
+ }
418
+ get isDisabled() {
419
+ return !!this.formGroup?.parent?.disabled;
420
+ }
421
+ ngAfterViewInit() {
422
+ if (this.parent.control instanceof RxapFormGroup) {
423
+ this.formGroup = this.parent.control;
424
+ if (this.formGroup.controls.deleted instanceof RxapFormControl) {
425
+ this.deletedControl = this.formGroup.controls.deleted;
426
+ }
427
+ else {
428
+ throw new Error(`The parent FormGroup instance does not have a 'deleted' control`);
429
+ }
430
+ if (!(this.formGroup.parent instanceof UntypedFormArray)) {
431
+ throw new Error(`The parent of the FormGroup is not a FormArray instance`);
432
+ }
433
+ }
434
+ else {
435
+ throw new Error(`The parent is not a form group instance`);
436
+ }
437
+ if (this.matButton) {
438
+ this._controlDisabledSubscription = this.formGroup.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
439
+ }
440
+ this.deletedControl.value$.pipe(tap$1(() => this.updateDisplayStyle())).subscribe();
441
+ }
442
+ ngOnDestroy() {
443
+ this._controlDisabledSubscription?.unsubscribe();
444
+ this._deletedControlValueSubscription?.unsubscribe();
445
+ }
446
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayItemButton, deps: [{ token: i1$1.ControlContainer, skipSelf: true }, { token: i2.MatButton, optional: true }, { token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
447
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: FormArrayItemButton, host: { properties: { "type": "this.type", "disabled": "this.disabled" } }, ngImport: i0 }); }
448
+ }
449
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayItemButton, decorators: [{
450
+ type: Directive
451
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
452
+ type: SkipSelf
453
+ }] }, { type: i2.MatButton, decorators: [{
454
+ type: Optional
455
+ }] }, { type: i0.Renderer2 }, { type: i0.ElementRef }]; }, propDecorators: { type: [{
456
+ type: HostBinding,
457
+ args: ['type']
458
+ }], disabled: [{
459
+ type: HostBinding,
460
+ args: ['disabled']
461
+ }] } });
462
+
463
+ // TODO : move to rxap packages
464
+ class FormArrayItemRemoveButtonDirective extends FormArrayItemButton {
465
+ onClick() {
466
+ this.deletedControl.setValue(true);
467
+ }
468
+ updateDisplayStyle() {
469
+ if (this.isDeleted) {
470
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
471
+ }
472
+ else {
473
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
474
+ }
475
+ }
476
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayItemRemoveButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
477
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: FormArrayItemRemoveButtonDirective, isStandalone: true, selector: "button[rxapFormArrayItemRemoveButton]", host: { listeners: { "click": "onClick()" } }, usesInheritance: true, ngImport: i0 }); }
478
+ }
479
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayItemRemoveButtonDirective, decorators: [{
480
+ type: Directive,
481
+ args: [{
482
+ selector: 'button[rxapFormArrayItemRemoveButton]',
483
+ standalone: true,
484
+ }]
485
+ }], propDecorators: { onClick: [{
486
+ type: HostListener,
487
+ args: ['click']
488
+ }] } });
489
+
490
+ // TODO : move to rxap packages
491
+ class FormArrayItemRestoreButtonDirective extends FormArrayItemButton {
492
+ onClick() {
493
+ this.formGroup.controls.deleted.setValue(false);
494
+ }
495
+ updateDisplayStyle() {
496
+ if (this.isDeleted) {
497
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
498
+ }
499
+ else {
500
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
501
+ }
502
+ }
503
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
504
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: FormArrayItemRestoreButtonDirective, isStandalone: true, selector: "button[rxapFormArrayItemRestoreButton]", host: { listeners: { "click": "onClick()" } }, usesInheritance: true, ngImport: i0 }); }
505
+ }
506
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, decorators: [{
507
+ type: Directive,
508
+ args: [{
509
+ selector: 'button[rxapFormArrayItemRestoreButton]',
510
+ standalone: true,
511
+ }]
512
+ }], propDecorators: { onClick: [{
513
+ type: HostListener,
514
+ args: ['click']
515
+ }] } });
516
+
517
+ // TODO : move to rxap packages
518
+ class FormArrayRemovableDirective {
519
+ constructor(parent) {
520
+ this.parent = parent;
521
+ }
522
+ get isDeleted() {
523
+ return this.deletedControl.value;
524
+ }
525
+ get isDisabled() {
526
+ return !!this.control?.parent?.disabled;
527
+ }
528
+ ngAfterViewInit() {
529
+ if (this.parent.control instanceof RxapFormGroup) {
530
+ this.control = this.parent.control;
531
+ if (this.control.controls.deleted instanceof RxapFormControl) {
532
+ this.deletedControl = this.control.controls.deleted;
533
+ }
534
+ else {
535
+ throw new Error(`The parent FormGroup instance does not have a 'deleted' control`);
536
+ }
537
+ if (!(this.control.parent instanceof UntypedFormArray)) {
538
+ throw new Error(`The parent of the FormGroup is not a FormArray instance`);
539
+ }
540
+ }
541
+ else {
542
+ throw new Error(`The parent is not a form group instance`);
543
+ }
544
+ this._deletedControlValueSubscription = this.deletedControl.value$.pipe(tap$1((isDeleted) => {
545
+ for (const [name, control] of Object.entries(this.control.controls)) {
546
+ if (name !== 'deleted') {
547
+ if (isDeleted) {
548
+ control.disable({ onlySelf: true });
549
+ }
550
+ else if (!this.isDisabled) {
551
+ control.enable({ onlySelf: true });
552
+ }
553
+ }
554
+ }
555
+ })).subscribe();
556
+ }
557
+ ngOnDestroy() {
558
+ this._deletedControlValueSubscription?.unsubscribe();
559
+ }
560
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayRemovableDirective, deps: [{ token: i1$1.ControlContainer, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
561
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: FormArrayRemovableDirective, isStandalone: true, selector: "[rxapFormArrayRemovable]", ngImport: i0 }); }
490
562
  }
563
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormArrayRemovableDirective, decorators: [{
564
+ type: Directive,
565
+ args: [{
566
+ selector: '[rxapFormArrayRemovable]',
567
+ standalone: true,
568
+ }]
569
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
570
+ type: Optional
571
+ }] }]; } });
491
572
 
492
573
  const RXAP_FORM_SYSTEM_SHOW_METADATA = 'rxap/form-system/show-function';
493
574
  const RXAP_FORM_SYSTEM_HIDE_METADATA = 'rxap/form-system/hide-function';
@@ -536,7 +617,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
536
617
  if (options.rootChange) {
537
618
  changeTrigger = formDefinition.rxapFormGroup.root.valueChanges;
538
619
  }
539
- changeTrigger = changeTrigger.pipe(startWith(null));
620
+ changeTrigger = changeTrigger.pipe(startWith$1(null));
540
621
  if (showFunction) {
541
622
  this.subscription.add(changeTrigger.pipe(tap(() => {
542
623
  // TODO : resubscribe if the showFunction throws an error
@@ -611,15 +692,15 @@ let ControlHideShowDirective = class ControlHideShowDirective {
611
692
  reset() {
612
693
  this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
613
694
  }
614
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlHideShowDirective, deps: [{ token: Renderer2 }, { token: ElementRef }, { token: ControlContainer, optional: true }, { token: NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive }); }
615
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: ControlHideShowDirective, isStandalone: true, selector: "[rxapControlHideShow]", inputs: { controlId: ["rxapControlHideShow", "controlId"] }, ngImport: i0 }); }
695
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ControlHideShowDirective, deps: [{ token: Renderer2 }, { token: ElementRef }, { token: ControlContainer, optional: true }, { token: NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive }); }
696
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: ControlHideShowDirective, isStandalone: true, selector: "[rxapControlHideShow]", inputs: { controlId: ["rxapControlHideShow", "controlId"] }, ngImport: i0 }); }
616
697
  };
617
698
  ControlHideShowDirective = __decorate([
618
699
  Mixin(ExtractControlFromParentMixin, ExtractFormDefinitionMixin),
619
700
  __metadata("design:paramtypes", [Renderer2,
620
701
  ElementRef, Object, Object])
621
702
  ], ControlHideShowDirective);
622
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlHideShowDirective, decorators: [{
703
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ControlHideShowDirective, decorators: [{
623
704
  type: Directive,
624
705
  args: [{
625
706
  selector: '[rxapControlHideShow]',
@@ -631,12 +712,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
631
712
  }] }, { type: i0.ElementRef, decorators: [{
632
713
  type: Inject,
633
714
  args: [ElementRef]
634
- }] }, { type: i1.ControlContainer, decorators: [{
715
+ }] }, { type: i1$1.ControlContainer, decorators: [{
635
716
  type: Optional
636
717
  }, {
637
718
  type: Inject,
638
719
  args: [ControlContainer]
639
- }] }, { type: i1.NgControl, decorators: [{
720
+ }] }, { type: i1$1.NgControl, decorators: [{
640
721
  type: Self
641
722
  }, {
642
723
  type: Optional
@@ -676,7 +757,7 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
676
757
  this.extractOptionsDatasource();
677
758
  this.viewer = {
678
759
  id: '[rxapInputSelectOptions]' + this.control.controlId,
679
- viewChange: this.settings?.loadOnce ? EMPTY : this.control.value$.pipe(throttleTime(1000), distinctUntilChanged((a, b) => equals(a, b)), map(value => {
760
+ viewChange: this.settings?.loadOnce ? EMPTY : this.control.value$.pipe(throttleTime(1000), distinctUntilChanged$1((a, b) => equals(a, b)), map(value => {
680
761
  if (this.settings?.ignoreSelectedValue) {
681
762
  return {};
682
763
  }
@@ -760,8 +841,8 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
760
841
  }
761
842
  this.cdr.detectChanges();
762
843
  }
763
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", 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 }); }
764
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: InputSelectOptionsDirective, isStandalone: true, selector: "[rxapInputSelectOptions]", inputs: { viewer: ["rxapInputSelectOptionsViewer", "viewer"], metadata: ["rxapInputSelectOptionsMetadata", "metadata"], matAutocomplete: ["rxapInputSelectOptionsMatAutocomplete", "matAutocomplete"] }, ngImport: i0 }); }
844
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", 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 }); }
845
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: InputSelectOptionsDirective, isStandalone: true, selector: "[rxapInputSelectOptions]", inputs: { viewer: ["rxapInputSelectOptionsViewer", "viewer"], metadata: ["rxapInputSelectOptionsMetadata", "metadata"], matAutocomplete: ["rxapInputSelectOptionsMatAutocomplete", "matAutocomplete"] }, ngImport: i0 }); }
765
846
  };
766
847
  InputSelectOptionsDirective = __decorate([
767
848
  Mixin(ExtractOptionsDataSourceMixin),
@@ -771,7 +852,7 @@ InputSelectOptionsDirective = __decorate([
771
852
  Injector,
772
853
  ChangeDetectorRef, Object, Object])
773
854
  ], InputSelectOptionsDirective);
774
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: InputSelectOptionsDirective, decorators: [{
855
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: InputSelectOptionsDirective, decorators: [{
775
856
  type: Directive,
776
857
  args: [{
777
858
  selector: '[rxapInputSelectOptions]',
@@ -780,7 +861,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
780
861
  }], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
781
862
  type: Inject,
782
863
  args: [TemplateRef]
783
- }] }, { type: i1$1.DataSourceLoader, decorators: [{
864
+ }] }, { type: i1.DataSourceLoader, decorators: [{
784
865
  type: Inject,
785
866
  args: [DataSourceLoader]
786
867
  }] }, { type: i0.ViewContainerRef, decorators: [{
@@ -792,7 +873,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
792
873
  }] }, { type: i0.ChangeDetectorRef, decorators: [{
793
874
  type: Inject,
794
875
  args: [ChangeDetectorRef]
795
- }] }, { type: i1.NgControl, decorators: [{
876
+ }] }, { type: i1$1.NgControl, decorators: [{
796
877
  type: Optional
797
878
  }, {
798
879
  type: Inject,
@@ -814,13 +895,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
814
895
  }] } });
815
896
 
816
897
  class FormSystemDirectivesModule {
817
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
818
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, imports: [InputSelectOptionsDirective,
898
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormSystemDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
899
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.4", ngImport: i0, type: FormSystemDirectivesModule, imports: [InputSelectOptionsDirective,
819
900
  ControlHideShowDirective], exports: [InputSelectOptionsDirective,
820
901
  ControlHideShowDirective] }); }
821
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule }); }
902
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormSystemDirectivesModule }); }
822
903
  }
823
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, decorators: [{
904
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormSystemDirectivesModule, decorators: [{
824
905
  type: NgModule,
825
906
  args: [{
826
907
  exports: [
@@ -834,143 +915,348 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
834
915
  }]
835
916
  }] });
836
917
 
837
- class IsEqualToDirective {
838
- set equalTo(value) {
839
- this._equalTo = value;
840
- if (this._onChange) {
841
- this._onChange();
918
+ const REMOTE_METHOD_NAME = 'options';
919
+ const RXAP_USE_REMOTE_METHOD = 'rxap/form-system/remote-method/use';
920
+ function UseRemoteMethod(remoteMethod, name) {
921
+ return function (target, propertyKey) {
922
+ setMetadataMapMap(propertyKey, name, remoteMethod, RXAP_USE_REMOTE_METHOD, target);
923
+ };
924
+ }
925
+ function UseOptionsRemoteMethod(dataSource) {
926
+ return function (target, propertyKey) {
927
+ UseRemoteMethod(dataSource, REMOTE_METHOD_NAME)(target, propertyKey);
928
+ };
929
+ }
930
+ class ExtractRemoteMethodsMixin {
931
+ extractRemoteMethods(formDefinition, controlId) {
932
+ const map = getMetadata(RXAP_USE_REMOTE_METHOD, Object.getPrototypeOf(formDefinition));
933
+ if (!map) {
934
+ throw new RxapFormSystemError('Could not extract the use remote method map from the form definition instance', '');
842
935
  }
936
+ if (!map.has(controlId)) {
937
+ throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
938
+ }
939
+ return map.get(controlId);
843
940
  }
844
- validate(control) {
845
- if (this._equalTo === null || this._equalTo === control.value) {
846
- return null;
941
+ }
942
+ let OptionsFromRemoteMethodDirective = class OptionsFromRemoteMethodDirective {
943
+ constructor(ngControl, template, remoteMethodLoader, viewContainerRef, injector, cdr) {
944
+ this.ngControl = ngControl;
945
+ this.template = template;
946
+ this.remoteMethodLoader = remoteMethodLoader;
947
+ this.viewContainerRef = viewContainerRef;
948
+ this.injector = injector;
949
+ this.cdr = cdr;
950
+ this.withoutParameters = false;
951
+ }
952
+ ngOnChanges(changes) {
953
+ const parametersChanges = changes['parameters'];
954
+ if (parametersChanges) {
955
+ if (!this.remoteMethodToken) {
956
+ this.remoteMethodToken = this.extractRemoteMethodToken();
957
+ }
958
+ this.renderTemplate(parametersChanges.currentValue);
959
+ }
960
+ if (changes['withoutParameters']?.currentValue) {
961
+ if (!this.remoteMethodToken) {
962
+ this.remoteMethodToken = this.extractRemoteMethodToken();
963
+ }
964
+ this.renderTemplate();
847
965
  }
848
- return {
849
- isEqualTo: {
850
- value: this._equalTo,
851
- actualValue: control.value,
852
- },
853
- };
854
966
  }
855
- /**
856
- * @description
857
- * Registers a callback function to call when the validator inputs change.
858
- *
859
- * @param fn The callback function
860
- */
861
- registerOnValidatorChange(fn) {
862
- this._onChange = fn;
967
+ extractRemoteMethodToken() {
968
+ const control = this.ngControl.control;
969
+ if (!(control instanceof RxapFormControl)) {
970
+ throw new Error('Control is not a RxapFormControl!');
971
+ }
972
+ const formDefinition = this.extractFormDefinition(control);
973
+ const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
974
+ if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
975
+ throw new Error(`The remote method with the name 'options' is not defined`);
976
+ }
977
+ return remoteMethodsTokens.get(REMOTE_METHOD_NAME);
863
978
  }
864
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsEqualToDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
865
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: IsEqualToDirective, isStandalone: true, selector: "[rxapIsEqualTo]", inputs: { equalTo: ["rxapIsEqualTo", "equalTo"] }, providers: [
866
- {
867
- provide: NG_VALIDATORS,
868
- multi: true,
869
- useExisting: forwardRef(() => IsEqualToDirective),
870
- },
871
- ], ngImport: i0 }); }
872
- }
873
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsEqualToDirective, decorators: [{
979
+ async renderTemplate(parameters) {
980
+ const options = await this.remoteMethodLoader.call$(this.remoteMethodToken, parameters, undefined, this.injector);
981
+ this.viewContainerRef.clear();
982
+ for (const option of options) {
983
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
984
+ }
985
+ if (this.resetOnChange !== undefined) {
986
+ this.ngControl.reset(this.resetOnChange);
987
+ }
988
+ this.cdr.detectChanges();
989
+ }
990
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, deps: [{ token: NgControl }, { token: TemplateRef }, { token: RemoteMethodLoader }, { token: ViewContainerRef }, { token: INJECTOR }, { token: ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
991
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: OptionsFromRemoteMethodDirective, isStandalone: true, selector: "[rxapOptionsFromRemoteMethod]", inputs: { parameters: ["rxapOptionsFromRemoteMethodParameters", "parameters"], resetOnChange: ["rxapOptionsFromRemoteMethodResetOnChange", "resetOnChange"], withoutParameters: ["rxapOptionsFromRemoteMethodWithoutParameters", "withoutParameters"] }, usesOnChanges: true, ngImport: i0 }); }
992
+ };
993
+ OptionsFromRemoteMethodDirective = __decorate([
994
+ Mixin(ExtractFormDefinitionMixin, ExtractRemoteMethodsMixin),
995
+ __metadata("design:paramtypes", [NgControl,
996
+ TemplateRef,
997
+ RemoteMethodLoader,
998
+ ViewContainerRef,
999
+ Injector,
1000
+ ChangeDetectorRef])
1001
+ ], OptionsFromRemoteMethodDirective);
1002
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, decorators: [{
874
1003
  type: Directive,
875
1004
  args: [{
876
- selector: '[rxapIsEqualTo]',
877
- providers: [
878
- {
879
- provide: NG_VALIDATORS,
880
- multi: true,
881
- useExisting: forwardRef(() => IsEqualToDirective),
882
- },
883
- ],
1005
+ selector: '[rxapOptionsFromRemoteMethod]',
884
1006
  standalone: true,
885
1007
  }]
886
- }], propDecorators: { equalTo: [{
1008
+ }], ctorParameters: function () { return [{ type: i1$1.NgControl, decorators: [{
1009
+ type: Inject,
1010
+ args: [NgControl]
1011
+ }] }, { type: i0.TemplateRef, decorators: [{
1012
+ type: Inject,
1013
+ args: [TemplateRef]
1014
+ }] }, { type: i2$1.RemoteMethodLoader, decorators: [{
1015
+ type: Inject,
1016
+ args: [RemoteMethodLoader]
1017
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1018
+ type: Inject,
1019
+ args: [ViewContainerRef]
1020
+ }] }, { type: i0.Injector, decorators: [{
1021
+ type: Inject,
1022
+ args: [INJECTOR]
1023
+ }] }, { type: i0.ChangeDetectorRef, decorators: [{
1024
+ type: Inject,
1025
+ args: [ChangeDetectorRef]
1026
+ }] }]; }, propDecorators: { parameters: [{
887
1027
  type: Input,
888
- args: [{
889
- required: true,
890
- alias: 'rxapIsEqualTo',
891
- }]
1028
+ args: ['rxapOptionsFromRemoteMethodParameters']
1029
+ }], resetOnChange: [{
1030
+ type: Input,
1031
+ args: ['rxapOptionsFromRemoteMethodResetOnChange']
1032
+ }], withoutParameters: [{
1033
+ type: Input,
1034
+ args: ['rxapOptionsFromRemoteMethodWithoutParameters']
892
1035
  }] } });
893
1036
 
894
- var IsSelectableValueDirective_1;
895
- let IsSelectableValueDirective = class IsSelectableValueDirective {
896
- static { IsSelectableValueDirective_1 = this; }
897
- constructor(dataSourceLoader, injector) {
1037
+ function UseComponent(component, setProperties = {}) {
1038
+ return function (target, propertyKey) {
1039
+ setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
1040
+ setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
1041
+ };
1042
+ }
1043
+
1044
+ /**
1045
+ * Links a component with a form definition
1046
+ *
1047
+ * @param component
1048
+ */
1049
+ function UseFormComponent(component) {
1050
+ return function (target) {
1051
+ setMetadata(FormSystemMetadataKeys.FORM_COMPONENT, component, target);
1052
+ };
1053
+ }
1054
+
1055
+ const RXAP_FORM_CONTROL_SOURCE = new InjectionToken('rxap/forms/data-source');
1056
+ class ControlDataSource extends BaseDataSource {
1057
+ constructor(control, metadata = null) {
1058
+ super(metadata);
1059
+ this.control = control;
1060
+ }
1061
+ init() {
1062
+ if (this._initialised) {
1063
+ return;
1064
+ }
1065
+ super.init();
1066
+ if (isDevMode()) {
1067
+ console.log(this.control);
1068
+ }
1069
+ this._data$ = this.control.valueChanges.pipe(startWith$1(this.control.value), distinctUntilChanged$1((a, b) => equals(a, b)), shareReplay(1));
1070
+ }
1071
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ControlDataSource, deps: [{ token: RXAP_FORM_CONTROL_SOURCE }, { token: RXAP_DATA_SOURCE_METADATA, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
1072
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ControlDataSource }); }
1073
+ }
1074
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: ControlDataSource, decorators: [{
1075
+ type: Injectable
1076
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1077
+ type: Inject,
1078
+ args: [RXAP_FORM_CONTROL_SOURCE]
1079
+ }] }, { type: undefined, decorators: [{
1080
+ type: Optional
1081
+ }, {
1082
+ type: Inject,
1083
+ args: [RXAP_DATA_SOURCE_METADATA]
1084
+ }] }]; } });
1085
+ function controlDataSource(control) {
1086
+ // TODO : remove as any (wait for @rxap/forms update)
1087
+ return new ControlDataSource(control, { id: control.controlId });
1088
+ }
1089
+
1090
+ function FormContextFromActivatedRouteFactory(route) {
1091
+ return route.snapshot.params;
1092
+ }
1093
+
1094
+ let FormSystemControlDirective = class FormSystemControlDirective {
1095
+ constructor(parent, cfr, viewContainerRef, dataSourceLoader, injector) {
1096
+ this.parent = parent;
1097
+ this.cfr = cfr;
1098
+ this.viewContainerRef = viewContainerRef;
898
1099
  this.dataSourceLoader = dataSourceLoader;
899
1100
  this.injector = injector;
900
- this.viewer = { id: '[rxapIsSelectableValue]' };
901
1101
  }
902
- validate(control) {
903
- if (control.value) {
904
- this.extractOptionsDatasource(control);
905
- const data = this.useDataSourceValue?.lastValue;
906
- if (data) {
907
- let options;
908
- if (Array.isArray(data)) {
909
- options = data;
910
- }
911
- else {
912
- options = Object.entries(data)
913
- .map(([value, display]) => ({
914
- value,
915
- display,
916
- }));
917
- }
918
- if (!options.some(option => option.value === control.value)) {
919
- return {
920
- isSelectableValue: {
921
- expected: 'Value should be from the list of provided options',
922
- },
923
- };
924
- }
925
- }
926
- else if (isDevMode()) {
927
- console.warn('The last value from the OptionsDataSource is empty', this);
1102
+ ngOnInit() {
1103
+ this.control = this.extractControl();
1104
+ const formDefinition = this.extractFormDefinition();
1105
+ this.componentRef = this.createComponent(formDefinition);
1106
+ this.setDataSources(formDefinition, this.componentRef.instance);
1107
+ this.setComponentProperties(formDefinition, this.componentRef.instance);
1108
+ this.viewContainerRef.insert(this.componentRef.hostView);
1109
+ }
1110
+ registerOnChange(fn) {
1111
+ this.componentRef.instance.registerOnChange(fn);
1112
+ }
1113
+ registerOnTouched(fn) {
1114
+ this.componentRef.instance.registerOnTouched(fn);
1115
+ }
1116
+ writeValue(value) {
1117
+ this.componentRef.instance.writeValue(value);
1118
+ }
1119
+ setDisabledState(isDisabled) {
1120
+ if (this.componentRef.instance.setDisabledState) {
1121
+ this.componentRef.instance.setDisabledState(isDisabled);
1122
+ }
1123
+ }
1124
+ setDataSources(formDefinition, component) {
1125
+ if (!component.setDataSource) {
1126
+ throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
1127
+ }
1128
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
1129
+ for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
1130
+ let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
1131
+ const settings = useDataSourceValue.settings;
1132
+ if (settings?.transformer) {
1133
+ dataSource = new PipeDataSource(dataSource, map(settings.transformer));
928
1134
  }
1135
+ component.setDataSource(name, dataSource, useDataSourceValue.settings);
929
1136
  }
930
- return null;
931
1137
  }
932
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsSelectableValueDirective, deps: [{ token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive }); }
933
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: IsSelectableValueDirective, isStandalone: true, selector: "[rxapIsSelectableValue]", inputs: { viewer: "viewer" }, providers: [
934
- {
935
- provide: NG_VALIDATORS,
936
- multi: true,
937
- useExisting: forwardRef(() => IsSelectableValueDirective_1),
938
- },
939
- ], ngImport: i0 }); }
1138
+ setComponentProperties(formDefinition, component) {
1139
+ const componentProperties = this.extractComponentProperties(formDefinition);
1140
+ for (const [key, value] of Object.entries(componentProperties)) {
1141
+ Reflect.set(component, key, value);
1142
+ }
1143
+ }
1144
+ createComponent(formDefinition) {
1145
+ const component = this.extractComponent(formDefinition);
1146
+ const componentFactory = this.cfr.resolveComponentFactory(component);
1147
+ return componentFactory.create(this.injector);
1148
+ }
1149
+ extractControl() {
1150
+ if (!this.parent.control) {
1151
+ throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
1152
+ }
1153
+ const control = this.parent.control.get(this.controlId);
1154
+ if (!control) {
1155
+ throw new RxapFormSystemError('Could not find the control instance', '');
1156
+ }
1157
+ if (!(control instanceof RxapFormControl)) {
1158
+ throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
1159
+ }
1160
+ return control;
1161
+ }
1162
+ extractFormDefinition() {
1163
+ const formDefinition = this.control.rxapFormDefinition;
1164
+ if (!formDefinition) {
1165
+ throw new RxapFormSystemError('Could not find the form definition instance', '');
1166
+ }
1167
+ return formDefinition;
1168
+ }
1169
+ extractComponent(formDefinition) {
1170
+ const map = getMetadata(FormSystemMetadataKeys.COMPONENTS, Object.getPrototypeOf(formDefinition));
1171
+ if (!map) {
1172
+ throw new RxapFormSystemError('Could not extract the use component map from the form definition instance', '');
1173
+ }
1174
+ if (!map.has(this.controlId)) {
1175
+ throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
1176
+ }
1177
+ return map.get(this.controlId);
1178
+ }
1179
+ extractComponentProperties(formDefinition) {
1180
+ const map = getMetadata(FormSystemMetadataKeys.COMPONENTS_PROPERTIES, Object.getPrototypeOf(formDefinition));
1181
+ if (!map) {
1182
+ throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
1183
+ }
1184
+ if (!map.has(this.controlId)) {
1185
+ throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
1186
+ }
1187
+ return map.get(this.controlId);
1188
+ }
1189
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormSystemControlDirective, deps: [{ token: ControlContainer }, { token: ComponentFactoryResolver }, { token: ViewContainerRef }, { token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive }); }
1190
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.4", type: FormSystemControlDirective, isStandalone: true, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 }); }
940
1191
  };
941
- IsSelectableValueDirective = IsSelectableValueDirective_1 = __decorate([
942
- Mixin(ExtractOptionsDataSourceMixin),
943
- __metadata("design:paramtypes", [DataSourceLoader,
1192
+ FormSystemControlDirective = __decorate([
1193
+ Mixin(ExtractDataSourcesMixin),
1194
+ __metadata("design:paramtypes", [ControlContainer,
1195
+ ComponentFactoryResolver,
1196
+ ViewContainerRef,
1197
+ DataSourceLoader,
944
1198
  Injector])
945
- ], IsSelectableValueDirective);
946
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
1199
+ ], FormSystemControlDirective);
1200
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
947
1201
  type: Directive,
948
1202
  args: [{
949
- selector: '[rxapIsSelectableValue]',
950
- providers: [
951
- {
952
- provide: NG_VALIDATORS,
953
- multi: true,
954
- useExisting: forwardRef(() => IsSelectableValueDirective),
955
- },
956
- ],
1203
+ selector: '[rxapFormSystemControl]',
957
1204
  standalone: true,
958
1205
  }]
959
- }], ctorParameters: function () { return [{ type: i1$1.DataSourceLoader, decorators: [{
1206
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
1207
+ type: Inject,
1208
+ args: [ControlContainer]
1209
+ }] }, { type: i0.ComponentFactoryResolver, decorators: [{
1210
+ type: Inject,
1211
+ args: [ComponentFactoryResolver]
1212
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1213
+ type: Inject,
1214
+ args: [ViewContainerRef]
1215
+ }] }, { type: i1.DataSourceLoader, decorators: [{
960
1216
  type: Inject,
961
1217
  args: [DataSourceLoader]
962
1218
  }] }, { type: i0.Injector, decorators: [{
963
1219
  type: Inject,
964
1220
  args: [INJECTOR]
965
- }] }]; }, propDecorators: { viewer: [{
966
- type: Input
1221
+ }] }]; }, propDecorators: { controlId: [{
1222
+ type: Input,
1223
+ args: [{ required: true }]
967
1224
  }] } });
968
1225
 
1226
+ const SUBMIT_CONTEXT_FORM_ADAPTER_METHOD = new InjectionToken('submit-context-form-adapter-method');
1227
+ class SubmitContextFormAdapter extends ProxyRemoteMethod {
1228
+ constructor(remoteMethod, context) {
1229
+ super(remoteMethod);
1230
+ this.context = context;
1231
+ }
1232
+ transformParameters(value) {
1233
+ return {
1234
+ parameters: this.context ?? {},
1235
+ requestBody: value,
1236
+ };
1237
+ }
1238
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: SubmitContextFormAdapter, deps: [{ token: SUBMIT_CONTEXT_FORM_ADAPTER_METHOD }, { token: RXAP_FORM_CONTEXT }], target: i0.ɵɵFactoryTarget.Injectable }); }
1239
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: SubmitContextFormAdapter }); }
1240
+ }
1241
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImport: i0, type: SubmitContextFormAdapter, decorators: [{
1242
+ type: Injectable
1243
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1244
+ type: Inject,
1245
+ args: [SUBMIT_CONTEXT_FORM_ADAPTER_METHOD]
1246
+ }] }, { type: undefined, decorators: [{
1247
+ type: Inject,
1248
+ args: [RXAP_FORM_CONTEXT]
1249
+ }] }]; } });
1250
+ function SubmitContextFormAdapterFactory(remoteMethod, context) {
1251
+ return new SubmitContextFormAdapter(remoteMethod, context);
1252
+ }
1253
+
1254
+ // region validators
969
1255
  // endregion
970
1256
 
971
1257
  /**
972
1258
  * Generated bundle index. Do not edit.
973
1259
  */
974
1260
 
975
- export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, DATA_SOURCE_NAME, ExtractControlFromParentMixin, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, ExtractOptionsDataSourceMixin, ExtractRemoteMethodsMixin, FormContextFromActivatedRouteFactory, FormSystemControlDirective, FormSystemDirectivesModule, FormSystemMetadataKeys, InputSelectOptionsDirective, IsEqualToDirective, IsSelectableValueDirective, OptionsFromRemoteMethodDirective, REMOTE_METHOD_NAME, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RXAP_USE_REMOTE_METHOD, RxapFormSystemError, SUBMIT_CONTEXT_FORM_ADAPTER_METHOD, SubmitContextFormAdapter, SubmitContextFormAdapterFactory, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseOptionsRemoteMethod, UseRemoteMethod, UseShowFunction, controlDataSource };
1261
+ export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, DATA_SOURCE_NAME, ExtractControlFromParentMixin, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, ExtractOptionsDataSourceMixin, ExtractRemoteMethodsMixin, ForFormArrayItemsDirective, FormArrayAddItemButtonDirective, FormArrayItemButton, FormArrayItemRemoveButtonDirective, FormArrayItemRestoreButtonDirective, FormArrayRemovableDirective, FormContextFromActivatedRouteFactory, FormSystemControlDirective, FormSystemDirectivesModule, FormSystemMetadataKeys, InputSelectOptionsDirective, IsEqualToDirective, IsSelectableValueDirective, OptionsFromRemoteMethodDirective, REMOTE_METHOD_NAME, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RXAP_USE_REMOTE_METHOD, RxapFormSystemError, SUBMIT_CONTEXT_FORM_ADAPTER_METHOD, SubmitContextFormAdapter, SubmitContextFormAdapterFactory, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseOptionsRemoteMethod, UseRemoteMethod, UseShowFunction, controlDataSource };
976
1262
  //# sourceMappingURL=rxap-form-system.mjs.map