@rxap/form-system 16.0.0-dev.8 → 16.0.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 (35) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/LICENSE +621 -0
  3. package/LICENSE.md +621 -0
  4. package/README.md +1 -1
  5. package/esm2022/index.mjs +28 -19
  6. package/esm2022/lib/control-with-data-source.mjs +1 -1
  7. package/esm2022/lib/directives/array/for-form-array-items.directive.mjs +64 -0
  8. package/esm2022/lib/directives/array/form-array-add-item-button.directive.mjs +61 -0
  9. package/esm2022/lib/directives/array/form-array-item-button.mjs +71 -0
  10. package/esm2022/lib/directives/array/form-array-item-remove-button.directive.mjs +30 -0
  11. package/esm2022/lib/directives/array/form-array-item-restore-button.directive.mjs +30 -0
  12. package/esm2022/lib/directives/array/form-array-removable.directive.mjs +62 -0
  13. package/esm2022/lib/directives/input-select-options.directive.mjs +4 -13
  14. package/esm2022/lib/form-system-control.directive.mjs +5 -17
  15. package/esm2022/lib/mixins/extract-control.mixin.mjs +1 -1
  16. package/esm2022/lib/mixins/extract-options-data-source.mixin.mjs +7 -7
  17. package/esm2022/lib/submit-context-form-adapter.factory.mjs +3 -6
  18. package/esm2022/lib/validators/is-equal-to.mjs +5 -9
  19. package/fesm2022/rxap-form-system.mjs +781 -519
  20. package/fesm2022/rxap-form-system.mjs.map +1 -1
  21. package/index.d.ts +20 -13
  22. package/lib/control-with-data-source.d.ts +2 -2
  23. package/lib/directives/array/for-form-array-items.directive.d.ts +26 -0
  24. package/lib/directives/array/form-array-add-item-button.directive.d.ts +20 -0
  25. package/lib/directives/array/form-array-item-button.d.ts +29 -0
  26. package/lib/directives/array/form-array-item-remove-button.directive.d.ts +9 -0
  27. package/lib/directives/array/form-array-item-restore-button.directive.d.ts +9 -0
  28. package/lib/directives/array/form-array-removable.directive.d.ts +19 -0
  29. package/lib/form-system-control.directive.d.ts +1 -1
  30. package/lib/mixins/extract-control.mixin.d.ts +1 -1
  31. package/lib/mixins/extract-options-data-source.mixin.d.ts +7 -7
  32. package/lib/submit-context-form-adapter.factory.d.ts +1 -1
  33. package/lib/validators/is-equal-to.d.ts +1 -1
  34. package/package.json +47 -42
  35. package/theme.css +1 -1
@@ -1,96 +1,134 @@
1
- import { RxapError, equals, Required } 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, ComponentRef, Renderer2, ElementRef, Self, NgModule, forwardRef } from '@angular/core';
6
- import { startWith, distinctUntilChanged, shareReplay, map, tap, catchError, throttleTime, switchMap } from 'rxjs/operators';
7
- import * as i2 from '@rxap/remote-method';
8
- import { ProxyRemoteMethod, RemoteMethodLoader } from '@rxap/remote-method';
9
- import { RXAP_FORM_CONTEXT, RxapFormControl, RxapFormGroup, RxapFormArray } from '@rxap/forms';
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);
21
+ class IsEqualToDirective {
22
+ set equalTo(value) {
23
+ this._equalTo = value;
24
+ if (this._onChange) {
25
+ this._onChange();
26
+ }
27
+ }
28
+ validate(control) {
29
+ if (this._equalTo === null || this._equalTo === control.value) {
30
+ return null;
31
+ }
32
+ return {
33
+ isEqualTo: {
34
+ value: this._equalTo,
35
+ actualValue: control.value,
36
+ },
37
+ };
38
+ }
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;
23
47
  }
48
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsEqualToDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
49
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.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 }); }
24
56
  }
57
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsEqualToDirective, decorators: [{
58
+ type: Directive,
59
+ args: [{
60
+ selector: '[rxapIsEqualTo]',
61
+ providers: [
62
+ {
63
+ provide: NG_VALIDATORS,
64
+ multi: true,
65
+ useExisting: forwardRef(() => IsEqualToDirective),
66
+ },
67
+ ],
68
+ standalone: true,
69
+ }]
70
+ }], propDecorators: { equalTo: [{
71
+ type: Input,
72
+ args: [{
73
+ required: true,
74
+ alias: 'rxapIsEqualTo',
75
+ }]
76
+ }] } });
25
77
 
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;
78
+ var FormSystemMetadataKeys;
79
+ (function (FormSystemMetadataKeys) {
80
+ FormSystemMetadataKeys["COMPONENTS"] = "rxap/form-system/components";
81
+ FormSystemMetadataKeys["DATA_SOURCES"] = "rxap/form-system/data-sources";
82
+ FormSystemMetadataKeys["COMPONENTS_PROPERTIES"] = "rxap/form-system/components-properties";
83
+ FormSystemMetadataKeys["FORM_COMPONENT"] = "rxap/window-form-system/form-component";
84
+ })(FormSystemMetadataKeys || (FormSystemMetadataKeys = {}));
85
+
86
+ function UseDataSource(dataSource, name, settings) {
87
+ return function (target, propertyKey) {
88
+ const value = {
89
+ dataSource,
90
+ settings,
91
+ };
92
+ setMetadataMapMap(propertyKey, name, value, FormSystemMetadataKeys.DATA_SOURCES, target);
93
+ };
94
+ }
95
+
96
+ class ExtractControlMixin {
97
+ extractControl(ngControl = this.ngControl ??
98
+ this.matFormField?._control?.ngControl ??
99
+ null) {
100
+ if (!ngControl) {
101
+ throw new Error('The ngControl is not defined!');
35
102
  }
36
- super.init();
37
- if (isDevMode()) {
38
- console.log(this.control);
103
+ if (!(ngControl instanceof NgControl)) {
104
+ throw new Error('The AbstractControlDirective is not a NgControl!');
105
+ }
106
+ this.ngControl = ngControl;
107
+ const control = this.ngControl.control;
108
+ if (!(control instanceof RxapFormControl)) {
109
+ throw new Error('Control is not a RxapFormControl!');
39
110
  }
40
- this._data$ = this.control.valueChanges.pipe(startWith(this.control.value), distinctUntilChanged((a, b) => equals(a, b)), shareReplay(1));
111
+ return this.control = control;
41
112
  }
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
113
  }
60
114
 
61
- function FormContextFromActivatedRouteFactory(route) {
62
- return route.snapshot.params;
115
+ class RxapFormSystemError extends RxapError {
116
+ constructor(message, code, className) {
117
+ super('@rxap/form-system', message, code, className);
118
+ }
63
119
  }
64
120
 
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
- }
71
- transformParameters(value) {
72
- if (!this.context) {
73
- throw new Error('The provided context is null');
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', '');
74
126
  }
75
- return {
76
- parameters: this.context,
77
- requestBody: value,
78
- };
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);
79
131
  }
80
- 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 }); }
81
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter }); }
82
- }
83
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter, decorators: [{
84
- type: Injectable
85
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
86
- type: Inject,
87
- args: [SUBMIT_CONTEXT_FORM_ADAPTER_METHOD]
88
- }] }, { type: undefined, decorators: [{
89
- type: Inject,
90
- args: [RXAP_FORM_CONTEXT]
91
- }] }]; } });
92
- function SubmitContextFormAdapterFactory(remoteMethod, context) {
93
- return new SubmitContextFormAdapter(remoteMethod, context);
94
132
  }
95
133
 
96
134
  class ExtractFormDefinitionMixin {
@@ -104,146 +142,129 @@ class ExtractFormDefinitionMixin {
104
142
  }
105
143
  }
106
144
 
107
- const REMOTE_METHOD_NAME = 'options';
108
- const RXAP_USE_REMOTE_METHOD = 'rxap/form-system/remote-method/use';
109
- function UseRemoteMethod(remoteMethod, name) {
110
- return function (target, propertyKey) {
111
- setMetadataMapMap(propertyKey, name, remoteMethod, RXAP_USE_REMOTE_METHOD, target);
112
- };
145
+ const DATA_SOURCE_NAME = 'options';
146
+ function ComposeOptionsTransformers(...fnc) {
147
+ return base => fnc.reduce((source, transform) => transform(source), base);
113
148
  }
114
- function UseOptionsRemoteMethod(dataSource) {
149
+ function UseOptionsDataSource(dataSource, settings) {
115
150
  return function (target, propertyKey) {
116
- UseRemoteMethod(dataSource, REMOTE_METHOD_NAME)(target, propertyKey);
151
+ UseDataSource(dataSource, DATA_SOURCE_NAME, settings)(target, propertyKey);
117
152
  };
118
153
  }
119
- class ExtractRemoteMethodsMixin {
120
- extractRemoteMethods(formDefinition, controlId) {
121
- const map = getMetadata(RXAP_USE_REMOTE_METHOD, Object.getPrototypeOf(formDefinition));
122
- if (!map) {
123
- throw new RxapFormSystemError('Could not extract the use remote method map from the form definition instance', '');
154
+ let ExtractOptionsDataSourceMixin = class ExtractOptionsDataSourceMixin {
155
+ extractOptionsDatasource(control) {
156
+ control ??= this.extractControl();
157
+ if (!(control instanceof RxapFormControl)) {
158
+ throw new Error('Ensure to use a RxapFromControl');
124
159
  }
125
- if (!map.has(controlId)) {
126
- throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
160
+ const formDefinition = this.extractFormDefinition(control);
161
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
162
+ if (!useDataSourceValueMap.has('options')) {
163
+ throw new Error(`The data source with the name 'options' is not defined`);
127
164
  }
128
- return map.get(controlId);
129
- }
130
- }
131
- let OptionsFromRemoteMethodDirective = class OptionsFromRemoteMethodDirective {
132
- constructor(ngControl, template, remoteMethodLoader, viewContainerRef, injector, cdr) {
133
- this.ngControl = ngControl;
134
- this.template = template;
135
- this.remoteMethodLoader = remoteMethodLoader;
136
- this.viewContainerRef = viewContainerRef;
137
- this.injector = injector;
138
- this.cdr = cdr;
139
- this.withoutParameters = false;
140
- }
141
- ngOnChanges(changes) {
142
- const parametersChanges = changes['parameters'];
143
- if (parametersChanges) {
144
- if (!this.remoteMethodToken) {
145
- this.remoteMethodToken = this.extractRemoteMethodToken();
146
- }
147
- this.renderTemplate(parametersChanges.currentValue);
165
+ const useDataSourceValue = this.useDataSourceValue = useDataSourceValueMap.get('options');
166
+ this.settings = this.useDataSourceValue.settings ?? {};
167
+ let dataSource;
168
+ try {
169
+ dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
148
170
  }
149
- if (changes['withoutParameters']?.currentValue) {
150
- if (!this.remoteMethodToken) {
151
- this.remoteMethodToken = this.extractRemoteMethodToken();
171
+ catch (e) {
172
+ if (e.name && e.name === 'NullInjectorError') {
173
+ if (isDevMode()) {
174
+ console.error('Cloud not inject the options data source', this.useDataSourceValue);
175
+ }
176
+ throw new Error('Cloud not inject the options data source:\n' + e.message);
152
177
  }
153
- this.renderTemplate();
154
- }
155
- }
156
- extractRemoteMethodToken() {
157
- const control = this.ngControl.control;
158
- if (!(control instanceof RxapFormControl)) {
159
- throw new Error('Control is not a RxapFormControl!');
160
- }
161
- const formDefinition = this.extractFormDefinition(control);
162
- const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
163
- if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
164
- throw new Error(`The remote method with the name 'options' is not defined`);
178
+ throw e;
165
179
  }
166
- return remoteMethodsTokens.get(REMOTE_METHOD_NAME);
167
- }
168
- async renderTemplate(parameters) {
169
- const options = await this.remoteMethodLoader.call$(this.remoteMethodToken, parameters, undefined, this.injector);
170
- this.viewContainerRef.clear();
171
- for (const option of options) {
172
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
180
+ if (this.settings?.transformer) {
181
+ dataSource = new PipeDataSource(dataSource, map(this.settings.transformer), tap(options => useDataSourceValue.lastValue = options));
173
182
  }
174
- if (this.resetOnChange !== undefined) {
175
- this.ngControl.reset(this.resetOnChange);
183
+ else {
184
+ dataSource = new PipeDataSource(dataSource, tap(options => useDataSourceValue.lastValue = options));
176
185
  }
177
- this.cdr.detectChanges();
186
+ return this.dataSource = dataSource;
178
187
  }
179
- 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 }); }
180
- 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 }); }
181
188
  };
182
- OptionsFromRemoteMethodDirective = __decorate([
183
- Mixin(ExtractFormDefinitionMixin, ExtractRemoteMethodsMixin),
184
- __metadata("design:paramtypes", [NgControl,
185
- TemplateRef,
186
- RemoteMethodLoader,
187
- ViewContainerRef,
188
- Injector,
189
- ChangeDetectorRef])
190
- ], OptionsFromRemoteMethodDirective);
191
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, decorators: [{
189
+ ExtractOptionsDataSourceMixin = __decorate([
190
+ Mixin(ExtractControlMixin, ExtractFormDefinitionMixin, ExtractDataSourcesMixin)
191
+ ], ExtractOptionsDataSourceMixin);
192
+
193
+ var IsSelectableValueDirective_1;
194
+ let IsSelectableValueDirective = class IsSelectableValueDirective {
195
+ static { IsSelectableValueDirective_1 = this; }
196
+ constructor(dataSourceLoader, injector) {
197
+ this.dataSourceLoader = dataSourceLoader;
198
+ this.injector = injector;
199
+ this.viewer = { id: '[rxapIsSelectableValue]' };
200
+ }
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);
227
+ }
228
+ }
229
+ return null;
230
+ }
231
+ 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 }); }
232
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.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.1.4", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
192
246
  type: Directive,
193
247
  args: [{
194
- selector: '[rxapOptionsFromRemoteMethod]',
248
+ selector: '[rxapIsSelectableValue]',
249
+ providers: [
250
+ {
251
+ provide: NG_VALIDATORS,
252
+ multi: true,
253
+ useExisting: forwardRef(() => IsSelectableValueDirective),
254
+ },
255
+ ],
195
256
  standalone: true,
196
257
  }]
197
- }], ctorParameters: function () { return [{ type: i1.NgControl, decorators: [{
198
- type: Inject,
199
- args: [NgControl]
200
- }] }, { type: i0.TemplateRef, decorators: [{
201
- type: Inject,
202
- args: [TemplateRef]
203
- }] }, { type: i2.RemoteMethodLoader, decorators: [{
204
- type: Inject,
205
- args: [RemoteMethodLoader]
206
- }] }, { type: i0.ViewContainerRef, decorators: [{
258
+ }], ctorParameters: function () { return [{ type: i1.DataSourceLoader, decorators: [{
207
259
  type: Inject,
208
- args: [ViewContainerRef]
260
+ args: [DataSourceLoader]
209
261
  }] }, { type: i0.Injector, decorators: [{
210
262
  type: Inject,
211
263
  args: [INJECTOR]
212
- }] }, { type: i0.ChangeDetectorRef, decorators: [{
213
- type: Inject,
214
- args: [ChangeDetectorRef]
215
- }] }]; }, propDecorators: { parameters: [{
216
- type: Input,
217
- args: ['rxapOptionsFromRemoteMethodParameters']
218
- }], resetOnChange: [{
219
- type: Input,
220
- args: ['rxapOptionsFromRemoteMethodResetOnChange']
221
- }], withoutParameters: [{
222
- type: Input,
223
- args: ['rxapOptionsFromRemoteMethodWithoutParameters']
264
+ }] }]; }, propDecorators: { viewer: [{
265
+ type: Input
224
266
  }] } });
225
267
 
226
- var FormSystemMetadataKeys;
227
- (function (FormSystemMetadataKeys) {
228
- FormSystemMetadataKeys["COMPONENTS"] = "rxap/form-system/components";
229
- FormSystemMetadataKeys["DATA_SOURCES"] = "rxap/form-system/data-sources";
230
- FormSystemMetadataKeys["COMPONENTS_PROPERTIES"] = "rxap/form-system/components-properties";
231
- FormSystemMetadataKeys["FORM_COMPONENT"] = "rxap/window-form-system/form-component";
232
- })(FormSystemMetadataKeys || (FormSystemMetadataKeys = {}));
233
-
234
- class ExtractDataSourcesMixin {
235
- extractDataSources(formDefinition, controlId) {
236
- const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
237
- if (!map) {
238
- throw new RxapFormSystemError('Could not extract the use data source map from the form definition instance', '');
239
- }
240
- if (!map.has(controlId)) {
241
- throw new RxapFormSystemError('A use data source definition does not exists in the form definition metadata', '');
242
- }
243
- return map.get(controlId);
244
- }
245
- }
246
-
247
268
  class ExtractControlFromParentMixin {
248
269
  extractControlFromParent(parent, controlPath) {
249
270
  if (!controlPath) {
@@ -265,243 +286,289 @@ class ExtractControlFromParentMixin {
265
286
  }
266
287
  }
267
288
 
268
- function UseDataSource(dataSource, name, settings) {
269
- return function (target, propertyKey) {
270
- const value = {
271
- dataSource,
272
- settings,
273
- };
274
- setMetadataMapMap(propertyKey, name, value, FormSystemMetadataKeys.DATA_SOURCES, target);
275
- };
276
- }
277
-
278
- class ExtractControlMixin {
279
- extractControl(ngControl = this.ngControl ??
280
- this.matFormField?._control?.ngControl ??
281
- null) {
282
- if (!ngControl) {
283
- throw new Error('The ngControl is not defined!');
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;
296
+ }
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();
284
305
  }
285
- if (!(ngControl instanceof NgControl)) {
286
- throw new Error('The AbstractControlDirective is not a NgControl!');
306
+ else {
307
+ throw new Error('The control container is not an instance of RxapFormArray');
287
308
  }
288
- this.ngControl = ngControl;
289
- const control = this.ngControl.control;
290
- if (!(control instanceof RxapFormControl)) {
291
- throw new Error('Control is not a RxapFormControl!');
309
+ }
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
+ }
292
331
  }
293
- return this.control = control;
332
+ this.cdr.detectChanges();
294
333
  }
334
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.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.1.4", type: ForFormArrayItemsDirective, isStandalone: true, selector: "[rxapForFormArrayItem]", ngImport: i0 }); }
295
336
  }
337
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ForFormArrayItemsDirective, decorators: [{
338
+ type: Directive,
339
+ args: [{
340
+ selector: '[rxapForFormArrayItem]',
341
+ standalone: true,
342
+ }]
343
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
344
+ type: SkipSelf
345
+ }] }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }]; } });
296
346
 
297
- const DATA_SOURCE_NAME = 'options';
298
- function ComposeOptionsTransformers(...fnc) {
299
- return base => fnc.reduce((source, transform) => transform(source), base);
300
- }
301
- function UseOptionsDataSource(dataSource, settings) {
302
- return function (target, propertyKey) {
303
- UseDataSource(dataSource, DATA_SOURCE_NAME, settings)(target, propertyKey);
304
- };
305
- }
306
- let ExtractOptionsDataSourceMixin = class ExtractOptionsDataSourceMixin {
307
- extractOptionsDatasource(control) {
308
- control ??= this.extractControl();
309
- if (!(control instanceof RxapFormControl)) {
310
- throw new Error('Ensure to use a RxapFromControl');
311
- }
312
- const formDefinition = this.extractFormDefinition(control);
313
- const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
314
- if (!useDataSourceValueMap.has('options')) {
315
- throw new Error(`The data source with the name 'options' is not defined`);
316
- }
317
- const useDataSourceValue = this.useDataSourceValue = useDataSourceValueMap.get('options');
318
- this.settings = this.useDataSourceValue.settings ?? {};
319
- let dataSource;
320
- try {
321
- dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
322
- }
323
- catch (e) {
324
- if (e.name && e.name === 'NullInjectorError') {
325
- if (isDevMode()) {
326
- console.error('Cloud not inject the options data source', this.useDataSourceValue);
327
- }
328
- throw new Error('Cloud not inject the options data source:\n' + e.message);
329
- }
330
- throw e;
331
- }
332
- if (this.settings?.transformer) {
333
- dataSource = new PipeDataSource(dataSource, map(this.settings.transformer), tap(options => useDataSourceValue.lastValue = options));
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;
334
363
  }
335
- else {
336
- dataSource = new PipeDataSource(dataSource, tap(options => useDataSourceValue.lastValue = options));
364
+ if (this.matButton) {
365
+ this._controlDisabledSubscription = this.formArray.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
337
366
  }
338
- return this.dataSource = dataSource;
339
367
  }
340
- };
341
- ExtractOptionsDataSourceMixin = __decorate([
342
- Mixin(ExtractControlMixin, ExtractFormDefinitionMixin, ExtractDataSourcesMixin)
343
- ], ExtractOptionsDataSourceMixin);
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.1.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.1.4", type: FormArrayAddItemButtonDirective, isStandalone: true, selector: "[rxapFormArrayItemAddButton]", host: { listeners: { "click": "onClick()" }, properties: { "type": "this.type", "disabled": "this.disabled" } }, ngImport: i0 }); }
376
+ }
377
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.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
+ }] } });
344
399
 
345
- let FormSystemControlDirective = class FormSystemControlDirective {
346
- constructor(parent, cfr, viewContainerRef, dataSourceLoader, injector) {
400
+ // TODO : move to rxap packages
401
+ class FormArrayItemButton {
402
+ constructor(parent, matButton, renderer, elementRef) {
347
403
  this.parent = parent;
348
- this.cfr = cfr;
349
- this.viewContainerRef = viewContainerRef;
350
- this.dataSourceLoader = dataSourceLoader;
351
- this.injector = injector;
404
+ this.matButton = matButton;
405
+ this.renderer = renderer;
406
+ this.elementRef = elementRef;
407
+ this.type = 'button';
352
408
  }
353
- ngOnInit() {
354
- this.control = this.extractControl();
355
- const formDefinition = this.extractFormDefinition();
356
- this.componentRef = this.createComponent(formDefinition);
357
- this.setDataSources(formDefinition, this.componentRef.instance);
358
- this.setComponentProperties(formDefinition, this.componentRef.instance);
359
- this.viewContainerRef.insert(this.componentRef.hostView);
409
+ get disabled() {
410
+ return this.isDisabled;
360
411
  }
361
- registerOnChange(fn) {
362
- this.componentRef.instance.registerOnChange(fn);
412
+ get isDeleted() {
413
+ return this.deletedControl.value;
363
414
  }
364
- registerOnTouched(fn) {
365
- this.componentRef.instance.registerOnTouched(fn);
415
+ get index() {
416
+ return this.formGroup.parent.controls.findIndex(control => control === this.formGroup);
366
417
  }
367
- writeValue(value) {
368
- this.componentRef.instance.writeValue(value);
418
+ get isDisabled() {
419
+ return !!this.formGroup?.parent?.disabled;
369
420
  }
370
- setDisabledState(isDisabled) {
371
- if (this.componentRef.instance.setDisabledState) {
372
- this.componentRef.instance.setDisabledState(isDisabled);
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
+ }
373
433
  }
374
- }
375
- setDataSources(formDefinition, component) {
376
- if (!component.setDataSource) {
377
- throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
434
+ else {
435
+ throw new Error(`The parent is not a form group instance`);
378
436
  }
379
- const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
380
- for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
381
- let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
382
- const settings = useDataSourceValue.settings;
383
- if (settings?.transformer) {
384
- dataSource = new PipeDataSource(dataSource, map(settings.transformer));
385
- }
386
- component.setDataSource(name, dataSource, useDataSourceValue.settings);
437
+ if (this.matButton) {
438
+ this._controlDisabledSubscription = this.formGroup.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
387
439
  }
440
+ this.deletedControl.value$.pipe(tap$1(() => this.updateDisplayStyle())).subscribe();
388
441
  }
389
- setComponentProperties(formDefinition, component) {
390
- const componentProperties = this.extractComponentProperties(formDefinition);
391
- for (const [key, value] of Object.entries(componentProperties)) {
392
- Reflect.set(component, key, value);
393
- }
442
+ ngOnDestroy() {
443
+ this._controlDisabledSubscription?.unsubscribe();
444
+ this._deletedControlValueSubscription?.unsubscribe();
394
445
  }
395
- createComponent(formDefinition) {
396
- const component = this.extractComponent(formDefinition);
397
- const componentFactory = this.cfr.resolveComponentFactory(component);
398
- return componentFactory.create(this.injector);
446
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.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.1.4", type: FormArrayItemButton, host: { properties: { "type": "this.type", "disabled": "this.disabled" } }, ngImport: i0 }); }
448
+ }
449
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.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);
399
467
  }
400
- extractControl() {
401
- if (!this.parent.control) {
402
- throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
403
- }
404
- const control = this.parent.control.get(this.controlId);
405
- if (!control) {
406
- throw new RxapFormSystemError('Could not find the control instance', '');
468
+ updateDisplayStyle() {
469
+ if (this.isDeleted) {
470
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
407
471
  }
408
- if (!(control instanceof RxapFormControl)) {
409
- throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
472
+ else {
473
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
410
474
  }
411
- return control;
412
475
  }
413
- extractFormDefinition() {
414
- const formDefinition = this.control.rxapFormDefinition;
415
- if (!formDefinition) {
416
- throw new RxapFormSystemError('Could not find the form definition instance', '');
417
- }
418
- return formDefinition;
476
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRemoveButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
477
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.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.1.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);
419
494
  }
420
- extractComponent(formDefinition) {
421
- const map = getMetadata(FormSystemMetadataKeys.COMPONENTS, Object.getPrototypeOf(formDefinition));
422
- if (!map) {
423
- throw new RxapFormSystemError('Could not extract the use component map from the form definition instance', '');
495
+ updateDisplayStyle() {
496
+ if (this.isDeleted) {
497
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
424
498
  }
425
- if (!map.has(this.controlId)) {
426
- throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
499
+ else {
500
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
427
501
  }
428
- return map.get(this.controlId);
429
502
  }
430
- extractComponentProperties(formDefinition) {
431
- const map = getMetadata(FormSystemMetadataKeys.COMPONENTS_PROPERTIES, Object.getPrototypeOf(formDefinition));
432
- if (!map) {
433
- throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
503
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
504
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.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.1.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
+ }
434
540
  }
435
- if (!map.has(this.controlId)) {
436
- throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
541
+ else {
542
+ throw new Error(`The parent is not a form group instance`);
437
543
  }
438
- return map.get(this.controlId);
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();
439
556
  }
440
- 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 }); }
441
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: FormSystemControlDirective, isStandalone: true, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 }); }
442
- };
443
- __decorate([
444
- Required,
445
- __metadata("design:type", String)
446
- ], FormSystemControlDirective.prototype, "controlId", void 0);
447
- __decorate([
448
- Required,
449
- __metadata("design:type", RxapFormControl)
450
- ], FormSystemControlDirective.prototype, "control", void 0);
451
- __decorate([
452
- Required,
453
- __metadata("design:type", ComponentRef)
454
- ], FormSystemControlDirective.prototype, "componentRef", void 0);
455
- FormSystemControlDirective = __decorate([
456
- Mixin(ExtractDataSourcesMixin),
457
- __metadata("design:paramtypes", [ControlContainer,
458
- ComponentFactoryResolver,
459
- ViewContainerRef,
460
- DataSourceLoader,
461
- Injector])
462
- ], FormSystemControlDirective);
463
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
557
+ ngOnDestroy() {
558
+ this._deletedControlValueSubscription?.unsubscribe();
559
+ }
560
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.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.1.4", type: FormArrayRemovableDirective, isStandalone: true, selector: "[rxapFormArrayRemovable]", ngImport: i0 }); }
562
+ }
563
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayRemovableDirective, decorators: [{
464
564
  type: Directive,
465
565
  args: [{
466
- selector: '[rxapFormSystemControl]',
566
+ selector: '[rxapFormArrayRemovable]',
467
567
  standalone: true,
468
568
  }]
469
- }], ctorParameters: function () { return [{ type: i1.ControlContainer, decorators: [{
470
- type: Inject,
471
- args: [ControlContainer]
472
- }] }, { type: i0.ComponentFactoryResolver, decorators: [{
473
- type: Inject,
474
- args: [ComponentFactoryResolver]
475
- }] }, { type: i0.ViewContainerRef, decorators: [{
476
- type: Inject,
477
- args: [ViewContainerRef]
478
- }] }, { type: i1$1.DataSourceLoader, decorators: [{
479
- type: Inject,
480
- args: [DataSourceLoader]
481
- }] }, { type: i0.Injector, decorators: [{
482
- type: Inject,
483
- args: [INJECTOR]
484
- }] }]; }, propDecorators: { controlId: [{
485
- type: Input
486
- }], control: [], componentRef: [] } });
487
-
488
- function UseComponent(component, setProperties = {}) {
489
- return function (target, propertyKey) {
490
- setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
491
- setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
492
- };
493
- }
494
-
495
- /**
496
- * Links a component with a form definition
497
- *
498
- * @param component
499
- */
500
- function UseFormComponent(component) {
501
- return function (target) {
502
- setMetadata(FormSystemMetadataKeys.FORM_COMPONENT, component, target);
503
- };
504
- }
569
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
570
+ type: Optional
571
+ }] }]; } });
505
572
 
506
573
  const RXAP_FORM_SYSTEM_SHOW_METADATA = 'rxap/form-system/show-function';
507
574
  const RXAP_FORM_SYSTEM_HIDE_METADATA = 'rxap/form-system/hide-function';
@@ -550,7 +617,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
550
617
  if (options.rootChange) {
551
618
  changeTrigger = formDefinition.rxapFormGroup.root.valueChanges;
552
619
  }
553
- changeTrigger = changeTrigger.pipe(startWith(null));
620
+ changeTrigger = changeTrigger.pipe(startWith$1(null));
554
621
  if (showFunction) {
555
622
  this.subscription.add(changeTrigger.pipe(tap(() => {
556
623
  // TODO : resubscribe if the showFunction throws an error
@@ -645,12 +712,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
645
712
  }] }, { type: i0.ElementRef, decorators: [{
646
713
  type: Inject,
647
714
  args: [ElementRef]
648
- }] }, { type: i1.ControlContainer, decorators: [{
715
+ }] }, { type: i1$1.ControlContainer, decorators: [{
649
716
  type: Optional
650
717
  }, {
651
718
  type: Inject,
652
719
  args: [ControlContainer]
653
- }] }, { type: i1.NgControl, decorators: [{
720
+ }] }, { type: i1$1.NgControl, decorators: [{
654
721
  type: Self
655
722
  }, {
656
723
  type: Optional
@@ -690,7 +757,7 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
690
757
  this.extractOptionsDatasource();
691
758
  this.viewer = {
692
759
  id: '[rxapInputSelectOptions]' + this.control.controlId,
693
- 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 => {
694
761
  if (this.settings?.ignoreSelectedValue) {
695
762
  return {};
696
763
  }
@@ -777,14 +844,6 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
777
844
  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 }); }
778
845
  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 }); }
779
846
  };
780
- __decorate([
781
- Required,
782
- __metadata("design:type", RxapFormControl)
783
- ], InputSelectOptionsDirective.prototype, "control", void 0);
784
- __decorate([
785
- Required,
786
- __metadata("design:type", BaseDataSource)
787
- ], InputSelectOptionsDirective.prototype, "dataSource", void 0);
788
847
  InputSelectOptionsDirective = __decorate([
789
848
  Mixin(ExtractOptionsDataSourceMixin),
790
849
  __metadata("design:paramtypes", [TemplateRef,
@@ -802,7 +861,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
802
861
  }], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
803
862
  type: Inject,
804
863
  args: [TemplateRef]
805
- }] }, { type: i1$1.DataSourceLoader, decorators: [{
864
+ }] }, { type: i1.DataSourceLoader, decorators: [{
806
865
  type: Inject,
807
866
  args: [DataSourceLoader]
808
867
  }] }, { type: i0.ViewContainerRef, decorators: [{
@@ -814,7 +873,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
814
873
  }] }, { type: i0.ChangeDetectorRef, decorators: [{
815
874
  type: Inject,
816
875
  args: [ChangeDetectorRef]
817
- }] }, { type: i1.NgControl, decorators: [{
876
+ }] }, { type: i1$1.NgControl, decorators: [{
818
877
  type: Optional
819
878
  }, {
820
879
  type: Inject,
@@ -833,7 +892,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
833
892
  }], matAutocomplete: [{
834
893
  type: Input,
835
894
  args: ['rxapInputSelectOptionsMatAutocomplete']
836
- }], control: [], dataSource: [] } });
895
+ }] } });
837
896
 
838
897
  class FormSystemDirectivesModule {
839
898
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
@@ -856,145 +915,348 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
856
915
  }]
857
916
  }] });
858
917
 
859
- class IsEqualToDirective {
860
- set equalTo(value) {
861
- this._equalTo = value;
862
- if (this._onChange) {
863
- 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', '');
864
935
  }
865
- }
866
- validate(control) {
867
- if (this._equalTo === null || this._equalTo === control.value) {
868
- return null;
936
+ if (!map.has(controlId)) {
937
+ throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
869
938
  }
870
- return {
871
- isEqualTo: {
872
- value: this._equalTo,
873
- actualValue: control.value,
874
- },
875
- };
876
- }
877
- /**
878
- * @description
879
- * Registers a callback function to call when the validator inputs change.
880
- *
881
- * @param fn The callback function
882
- */
883
- registerOnValidatorChange(fn) {
884
- this._onChange = fn;
939
+ return map.get(controlId);
885
940
  }
886
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsEqualToDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
887
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: IsEqualToDirective, isStandalone: true, selector: "[rxapIsEqualTo]", inputs: { equalTo: ["rxapIsEqualTo", "equalTo"] }, providers: [
888
- {
889
- provide: NG_VALIDATORS,
890
- multi: true,
891
- useExisting: forwardRef(() => IsEqualToDirective),
892
- },
893
- ], ngImport: i0 }); }
894
941
  }
895
- __decorate([
896
- Required,
897
- __metadata("design:type", Object),
898
- __metadata("design:paramtypes", [Object])
899
- ], IsEqualToDirective.prototype, "equalTo", null);
900
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsEqualToDirective, decorators: [{
901
- type: Directive,
902
- args: [{
903
- selector: '[rxapIsEqualTo]',
904
- providers: [
905
- {
906
- provide: NG_VALIDATORS,
907
- multi: true,
908
- useExisting: forwardRef(() => IsEqualToDirective),
909
- },
910
- ],
911
- standalone: true,
912
- }]
913
- }], propDecorators: { equalTo: [{
914
- type: Input,
915
- args: ['rxapIsEqualTo']
916
- }] } });
917
-
918
- var IsSelectableValueDirective_1;
919
- let IsSelectableValueDirective = class IsSelectableValueDirective {
920
- static { IsSelectableValueDirective_1 = this; }
921
- constructor(dataSourceLoader, injector) {
922
- this.dataSourceLoader = dataSourceLoader;
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;
923
948
  this.injector = injector;
924
- this.viewer = { id: '[rxapIsSelectableValue]' };
949
+ this.cdr = cdr;
950
+ this.withoutParameters = false;
925
951
  }
926
- validate(control) {
927
- if (control.value) {
928
- this.extractOptionsDatasource(control);
929
- const data = this.useDataSourceValue?.lastValue;
930
- if (data) {
931
- let options;
932
- if (Array.isArray(data)) {
933
- options = data;
934
- }
935
- else {
936
- options = Object.entries(data)
937
- .map(([value, display]) => ({
938
- value,
939
- display,
940
- }));
941
- }
942
- if (!options.some(option => option.value === control.value)) {
943
- return {
944
- isSelectableValue: {
945
- expected: 'Value should be from the list of provided options',
946
- },
947
- };
948
- }
952
+ ngOnChanges(changes) {
953
+ const parametersChanges = changes['parameters'];
954
+ if (parametersChanges) {
955
+ if (!this.remoteMethodToken) {
956
+ this.remoteMethodToken = this.extractRemoteMethodToken();
949
957
  }
950
- else if (isDevMode()) {
951
- console.warn('The last value from the OptionsDataSource is empty', this);
958
+ this.renderTemplate(parametersChanges.currentValue);
959
+ }
960
+ if (changes['withoutParameters']?.currentValue) {
961
+ if (!this.remoteMethodToken) {
962
+ this.remoteMethodToken = this.extractRemoteMethodToken();
952
963
  }
964
+ this.renderTemplate();
953
965
  }
954
- return null;
955
966
  }
956
- 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 }); }
957
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: IsSelectableValueDirective, isStandalone: true, selector: "[rxapIsSelectableValue]", inputs: { viewer: "viewer" }, providers: [
958
- {
959
- provide: NG_VALIDATORS,
960
- multi: true,
961
- useExisting: forwardRef(() => IsSelectableValueDirective_1),
962
- },
963
- ], ngImport: i0 }); }
964
- };
965
- IsSelectableValueDirective = IsSelectableValueDirective_1 = __decorate([
966
- Mixin(ExtractOptionsDataSourceMixin),
967
- __metadata("design:paramtypes", [DataSourceLoader,
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);
978
+ }
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.1.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.1.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.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, decorators: [{
1003
+ type: Directive,
1004
+ args: [{
1005
+ selector: '[rxapOptionsFromRemoteMethod]',
1006
+ standalone: true,
1007
+ }]
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: [{
1027
+ type: Input,
1028
+ args: ['rxapOptionsFromRemoteMethodParameters']
1029
+ }], resetOnChange: [{
1030
+ type: Input,
1031
+ args: ['rxapOptionsFromRemoteMethodResetOnChange']
1032
+ }], withoutParameters: [{
1033
+ type: Input,
1034
+ args: ['rxapOptionsFromRemoteMethodWithoutParameters']
1035
+ }] } });
1036
+
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.1.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.1.4", ngImport: i0, type: ControlDataSource }); }
1073
+ }
1074
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.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;
1099
+ this.dataSourceLoader = dataSourceLoader;
1100
+ this.injector = injector;
1101
+ }
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));
1134
+ }
1135
+ component.setDataSource(name, dataSource, useDataSourceValue.settings);
1136
+ }
1137
+ }
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.1.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.1.4", type: FormSystemControlDirective, isStandalone: true, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 }); }
1191
+ };
1192
+ FormSystemControlDirective = __decorate([
1193
+ Mixin(ExtractDataSourcesMixin),
1194
+ __metadata("design:paramtypes", [ControlContainer,
1195
+ ComponentFactoryResolver,
1196
+ ViewContainerRef,
1197
+ DataSourceLoader,
968
1198
  Injector])
969
- ], IsSelectableValueDirective);
970
- 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.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
971
1201
  type: Directive,
972
1202
  args: [{
973
- selector: '[rxapIsSelectableValue]',
974
- providers: [
975
- {
976
- provide: NG_VALIDATORS,
977
- multi: true,
978
- useExisting: forwardRef(() => IsSelectableValueDirective),
979
- },
980
- ],
1203
+ selector: '[rxapFormSystemControl]',
981
1204
  standalone: true,
982
1205
  }]
983
- }], 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: [{
984
1216
  type: Inject,
985
1217
  args: [DataSourceLoader]
986
1218
  }] }, { type: i0.Injector, decorators: [{
987
1219
  type: Inject,
988
1220
  args: [INJECTOR]
989
- }] }]; }, propDecorators: { viewer: [{
990
- type: Input
1221
+ }] }]; }, propDecorators: { controlId: [{
1222
+ type: Input,
1223
+ args: [{ required: true }]
991
1224
  }] } });
992
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.1.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.1.4", ngImport: i0, type: SubmitContextFormAdapter }); }
1240
+ }
1241
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.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
993
1255
  // endregion
994
1256
 
995
1257
  /**
996
1258
  * Generated bundle index. Do not edit.
997
1259
  */
998
1260
 
999
- 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 };
1000
1262
  //# sourceMappingURL=rxap-form-system.mjs.map