@rxap/form-system 16.0.0-dev.9 → 16.0.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +1 -1
  3. package/esm2022/index.mjs +28 -19
  4. package/esm2022/lib/control-with-data-source.mjs +1 -1
  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 +72 -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/input-select-options.directive.mjs +4 -13
  12. package/esm2022/lib/form-system-control.directive.mjs +5 -17
  13. package/esm2022/lib/mixins/extract-control.mixin.mjs +1 -1
  14. package/esm2022/lib/mixins/extract-options-data-source.mixin.mjs +1 -1
  15. package/esm2022/lib/submit-context-form-adapter.factory.mjs +3 -6
  16. package/esm2022/lib/validators/is-equal-to.mjs +5 -9
  17. package/fesm2022/rxap-form-system.mjs +782 -519
  18. package/fesm2022/rxap-form-system.mjs.map +1 -1
  19. package/index.d.ts +20 -13
  20. package/lib/control-with-data-source.d.ts +2 -2
  21. package/lib/directives/array/for-form-array-items.directive.d.ts +26 -0
  22. package/lib/directives/array/form-array-add-item-button.directive.d.ts +20 -0
  23. package/lib/directives/array/form-array-item-button.d.ts +29 -0
  24. package/lib/directives/array/form-array-item-remove-button.directive.d.ts +9 -0
  25. package/lib/directives/array/form-array-item-restore-button.directive.d.ts +9 -0
  26. package/lib/directives/array/form-array-removable.directive.d.ts +19 -0
  27. package/lib/form-system-control.directive.d.ts +1 -1
  28. package/lib/mixins/extract-control.mixin.d.ts +1 -1
  29. package/lib/mixins/extract-options-data-source.mixin.d.ts +2 -2
  30. package/lib/submit-context-form-adapter.factory.d.ts +1 -1
  31. package/lib/validators/is-equal-to.d.ts +1 -1
  32. package/package.json +48 -42
@@ -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,290 @@ 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
+ this.deletedControl = new RxapFormControl(false, { controlId: 'deleted' });
429
+ this.formGroup.addControl('deleted', this.deletedControl);
430
+ }
431
+ if (!(this.formGroup.parent instanceof UntypedFormArray)) {
432
+ throw new Error(`The parent of the FormGroup is not a FormArray instance`);
433
+ }
373
434
  }
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', '');
435
+ else {
436
+ throw new Error(`The parent is not a form group instance`);
378
437
  }
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);
438
+ if (this.matButton) {
439
+ this._controlDisabledSubscription = this.formGroup.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
387
440
  }
441
+ this.deletedControl.value$.pipe(tap$1(() => this.updateDisplayStyle())).subscribe();
388
442
  }
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
- }
443
+ ngOnDestroy() {
444
+ this._controlDisabledSubscription?.unsubscribe();
445
+ this._deletedControlValueSubscription?.unsubscribe();
394
446
  }
395
- createComponent(formDefinition) {
396
- const component = this.extractComponent(formDefinition);
397
- const componentFactory = this.cfr.resolveComponentFactory(component);
398
- return componentFactory.create(this.injector);
447
+ 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 }); }
448
+ 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 }); }
449
+ }
450
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemButton, decorators: [{
451
+ type: Directive
452
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
453
+ type: SkipSelf
454
+ }] }, { type: i2.MatButton, decorators: [{
455
+ type: Optional
456
+ }] }, { type: i0.Renderer2 }, { type: i0.ElementRef }]; }, propDecorators: { type: [{
457
+ type: HostBinding,
458
+ args: ['type']
459
+ }], disabled: [{
460
+ type: HostBinding,
461
+ args: ['disabled']
462
+ }] } });
463
+
464
+ // TODO : move to rxap packages
465
+ class FormArrayItemRemoveButtonDirective extends FormArrayItemButton {
466
+ onClick() {
467
+ this.deletedControl.setValue(true);
399
468
  }
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', '');
469
+ updateDisplayStyle() {
470
+ if (this.isDeleted) {
471
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
407
472
  }
408
- if (!(control instanceof RxapFormControl)) {
409
- throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
473
+ else {
474
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
410
475
  }
411
- return control;
412
476
  }
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;
477
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRemoveButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
478
+ 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 }); }
479
+ }
480
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRemoveButtonDirective, decorators: [{
481
+ type: Directive,
482
+ args: [{
483
+ selector: 'button[rxapFormArrayItemRemoveButton]',
484
+ standalone: true,
485
+ }]
486
+ }], propDecorators: { onClick: [{
487
+ type: HostListener,
488
+ args: ['click']
489
+ }] } });
490
+
491
+ // TODO : move to rxap packages
492
+ class FormArrayItemRestoreButtonDirective extends FormArrayItemButton {
493
+ onClick() {
494
+ this.formGroup.controls.deleted.setValue(false);
419
495
  }
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', '');
496
+ updateDisplayStyle() {
497
+ if (this.isDeleted) {
498
+ this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
424
499
  }
425
- if (!map.has(this.controlId)) {
426
- throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
500
+ else {
501
+ this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
427
502
  }
428
- return map.get(this.controlId);
429
503
  }
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', '');
504
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
505
+ 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 }); }
506
+ }
507
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, decorators: [{
508
+ type: Directive,
509
+ args: [{
510
+ selector: 'button[rxapFormArrayItemRestoreButton]',
511
+ standalone: true,
512
+ }]
513
+ }], propDecorators: { onClick: [{
514
+ type: HostListener,
515
+ args: ['click']
516
+ }] } });
517
+
518
+ // TODO : move to rxap packages
519
+ class FormArrayRemovableDirective {
520
+ constructor(parent) {
521
+ this.parent = parent;
522
+ }
523
+ get isDeleted() {
524
+ return this.deletedControl.value;
525
+ }
526
+ get isDisabled() {
527
+ return !!this.control?.parent?.disabled;
528
+ }
529
+ ngAfterViewInit() {
530
+ if (this.parent.control instanceof RxapFormGroup) {
531
+ this.control = this.parent.control;
532
+ if (this.control.controls.deleted instanceof RxapFormControl) {
533
+ this.deletedControl = this.control.controls.deleted;
534
+ }
535
+ else {
536
+ throw new Error(`The parent FormGroup instance does not have a 'deleted' control`);
537
+ }
538
+ if (!(this.control.parent instanceof UntypedFormArray)) {
539
+ throw new Error(`The parent of the FormGroup is not a FormArray instance`);
540
+ }
434
541
  }
435
- if (!map.has(this.controlId)) {
436
- throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
542
+ else {
543
+ throw new Error(`The parent is not a form group instance`);
437
544
  }
438
- return map.get(this.controlId);
545
+ this._deletedControlValueSubscription = this.deletedControl.value$.pipe(tap$1((isDeleted) => {
546
+ for (const [name, control] of Object.entries(this.control.controls)) {
547
+ if (name !== 'deleted') {
548
+ if (isDeleted) {
549
+ control.disable({ onlySelf: true });
550
+ }
551
+ else if (!this.isDisabled) {
552
+ control.enable({ onlySelf: true });
553
+ }
554
+ }
555
+ }
556
+ })).subscribe();
439
557
  }
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: [{
558
+ ngOnDestroy() {
559
+ this._deletedControlValueSubscription?.unsubscribe();
560
+ }
561
+ 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 }); }
562
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: FormArrayRemovableDirective, isStandalone: true, selector: "[rxapFormArrayRemovable]", ngImport: i0 }); }
563
+ }
564
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayRemovableDirective, decorators: [{
464
565
  type: Directive,
465
566
  args: [{
466
- selector: '[rxapFormSystemControl]',
567
+ selector: '[rxapFormArrayRemovable]',
467
568
  standalone: true,
468
569
  }]
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
- }
570
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
571
+ type: Optional
572
+ }] }]; } });
505
573
 
506
574
  const RXAP_FORM_SYSTEM_SHOW_METADATA = 'rxap/form-system/show-function';
507
575
  const RXAP_FORM_SYSTEM_HIDE_METADATA = 'rxap/form-system/hide-function';
@@ -550,7 +618,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
550
618
  if (options.rootChange) {
551
619
  changeTrigger = formDefinition.rxapFormGroup.root.valueChanges;
552
620
  }
553
- changeTrigger = changeTrigger.pipe(startWith(null));
621
+ changeTrigger = changeTrigger.pipe(startWith$1(null));
554
622
  if (showFunction) {
555
623
  this.subscription.add(changeTrigger.pipe(tap(() => {
556
624
  // TODO : resubscribe if the showFunction throws an error
@@ -645,12 +713,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
645
713
  }] }, { type: i0.ElementRef, decorators: [{
646
714
  type: Inject,
647
715
  args: [ElementRef]
648
- }] }, { type: i1.ControlContainer, decorators: [{
716
+ }] }, { type: i1$1.ControlContainer, decorators: [{
649
717
  type: Optional
650
718
  }, {
651
719
  type: Inject,
652
720
  args: [ControlContainer]
653
- }] }, { type: i1.NgControl, decorators: [{
721
+ }] }, { type: i1$1.NgControl, decorators: [{
654
722
  type: Self
655
723
  }, {
656
724
  type: Optional
@@ -690,7 +758,7 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
690
758
  this.extractOptionsDatasource();
691
759
  this.viewer = {
692
760
  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 => {
761
+ viewChange: this.settings?.loadOnce ? EMPTY : this.control.value$.pipe(throttleTime(1000), distinctUntilChanged$1((a, b) => equals(a, b)), map(value => {
694
762
  if (this.settings?.ignoreSelectedValue) {
695
763
  return {};
696
764
  }
@@ -777,14 +845,6 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
777
845
  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
846
  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
847
  };
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
848
  InputSelectOptionsDirective = __decorate([
789
849
  Mixin(ExtractOptionsDataSourceMixin),
790
850
  __metadata("design:paramtypes", [TemplateRef,
@@ -802,7 +862,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
802
862
  }], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
803
863
  type: Inject,
804
864
  args: [TemplateRef]
805
- }] }, { type: i1$1.DataSourceLoader, decorators: [{
865
+ }] }, { type: i1.DataSourceLoader, decorators: [{
806
866
  type: Inject,
807
867
  args: [DataSourceLoader]
808
868
  }] }, { type: i0.ViewContainerRef, decorators: [{
@@ -814,7 +874,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
814
874
  }] }, { type: i0.ChangeDetectorRef, decorators: [{
815
875
  type: Inject,
816
876
  args: [ChangeDetectorRef]
817
- }] }, { type: i1.NgControl, decorators: [{
877
+ }] }, { type: i1$1.NgControl, decorators: [{
818
878
  type: Optional
819
879
  }, {
820
880
  type: Inject,
@@ -833,7 +893,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
833
893
  }], matAutocomplete: [{
834
894
  type: Input,
835
895
  args: ['rxapInputSelectOptionsMatAutocomplete']
836
- }], control: [], dataSource: [] } });
896
+ }] } });
837
897
 
838
898
  class FormSystemDirectivesModule {
839
899
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
@@ -856,145 +916,348 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
856
916
  }]
857
917
  }] });
858
918
 
859
- class IsEqualToDirective {
860
- set equalTo(value) {
861
- this._equalTo = value;
862
- if (this._onChange) {
863
- this._onChange();
919
+ const REMOTE_METHOD_NAME = 'options';
920
+ const RXAP_USE_REMOTE_METHOD = 'rxap/form-system/remote-method/use';
921
+ function UseRemoteMethod(remoteMethod, name) {
922
+ return function (target, propertyKey) {
923
+ setMetadataMapMap(propertyKey, name, remoteMethod, RXAP_USE_REMOTE_METHOD, target);
924
+ };
925
+ }
926
+ function UseOptionsRemoteMethod(dataSource) {
927
+ return function (target, propertyKey) {
928
+ UseRemoteMethod(dataSource, REMOTE_METHOD_NAME)(target, propertyKey);
929
+ };
930
+ }
931
+ class ExtractRemoteMethodsMixin {
932
+ extractRemoteMethods(formDefinition, controlId) {
933
+ const map = getMetadata(RXAP_USE_REMOTE_METHOD, Object.getPrototypeOf(formDefinition));
934
+ if (!map) {
935
+ throw new RxapFormSystemError('Could not extract the use remote method map from the form definition instance', '');
864
936
  }
865
- }
866
- validate(control) {
867
- if (this._equalTo === null || this._equalTo === control.value) {
868
- return null;
937
+ if (!map.has(controlId)) {
938
+ throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
869
939
  }
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;
940
+ return map.get(controlId);
885
941
  }
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
942
  }
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;
943
+ let OptionsFromRemoteMethodDirective = class OptionsFromRemoteMethodDirective {
944
+ constructor(ngControl, template, remoteMethodLoader, viewContainerRef, injector, cdr) {
945
+ this.ngControl = ngControl;
946
+ this.template = template;
947
+ this.remoteMethodLoader = remoteMethodLoader;
948
+ this.viewContainerRef = viewContainerRef;
923
949
  this.injector = injector;
924
- this.viewer = { id: '[rxapIsSelectableValue]' };
950
+ this.cdr = cdr;
951
+ this.withoutParameters = false;
925
952
  }
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
- }
953
+ ngOnChanges(changes) {
954
+ const parametersChanges = changes['parameters'];
955
+ if (parametersChanges) {
956
+ if (!this.remoteMethodToken) {
957
+ this.remoteMethodToken = this.extractRemoteMethodToken();
949
958
  }
950
- else if (isDevMode()) {
951
- console.warn('The last value from the OptionsDataSource is empty', this);
959
+ this.renderTemplate(parametersChanges.currentValue);
960
+ }
961
+ if (changes['withoutParameters']?.currentValue) {
962
+ if (!this.remoteMethodToken) {
963
+ this.remoteMethodToken = this.extractRemoteMethodToken();
952
964
  }
965
+ this.renderTemplate();
953
966
  }
954
- return null;
955
967
  }
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,
968
+ extractRemoteMethodToken() {
969
+ const control = this.ngControl.control;
970
+ if (!(control instanceof RxapFormControl)) {
971
+ throw new Error('Control is not a RxapFormControl!');
972
+ }
973
+ const formDefinition = this.extractFormDefinition(control);
974
+ const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
975
+ if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
976
+ throw new Error(`The remote method with the name 'options' is not defined`);
977
+ }
978
+ return remoteMethodsTokens.get(REMOTE_METHOD_NAME);
979
+ }
980
+ async renderTemplate(parameters) {
981
+ const options = await this.remoteMethodLoader.call$(this.remoteMethodToken, parameters, undefined, this.injector);
982
+ this.viewContainerRef.clear();
983
+ for (const option of options) {
984
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
985
+ }
986
+ if (this.resetOnChange !== undefined) {
987
+ this.ngControl.reset(this.resetOnChange);
988
+ }
989
+ this.cdr.detectChanges();
990
+ }
991
+ 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 }); }
992
+ 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 }); }
993
+ };
994
+ OptionsFromRemoteMethodDirective = __decorate([
995
+ Mixin(ExtractFormDefinitionMixin, ExtractRemoteMethodsMixin),
996
+ __metadata("design:paramtypes", [NgControl,
997
+ TemplateRef,
998
+ RemoteMethodLoader,
999
+ ViewContainerRef,
1000
+ Injector,
1001
+ ChangeDetectorRef])
1002
+ ], OptionsFromRemoteMethodDirective);
1003
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, decorators: [{
1004
+ type: Directive,
1005
+ args: [{
1006
+ selector: '[rxapOptionsFromRemoteMethod]',
1007
+ standalone: true,
1008
+ }]
1009
+ }], ctorParameters: function () { return [{ type: i1$1.NgControl, decorators: [{
1010
+ type: Inject,
1011
+ args: [NgControl]
1012
+ }] }, { type: i0.TemplateRef, decorators: [{
1013
+ type: Inject,
1014
+ args: [TemplateRef]
1015
+ }] }, { type: i2$1.RemoteMethodLoader, decorators: [{
1016
+ type: Inject,
1017
+ args: [RemoteMethodLoader]
1018
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1019
+ type: Inject,
1020
+ args: [ViewContainerRef]
1021
+ }] }, { type: i0.Injector, decorators: [{
1022
+ type: Inject,
1023
+ args: [INJECTOR]
1024
+ }] }, { type: i0.ChangeDetectorRef, decorators: [{
1025
+ type: Inject,
1026
+ args: [ChangeDetectorRef]
1027
+ }] }]; }, propDecorators: { parameters: [{
1028
+ type: Input,
1029
+ args: ['rxapOptionsFromRemoteMethodParameters']
1030
+ }], resetOnChange: [{
1031
+ type: Input,
1032
+ args: ['rxapOptionsFromRemoteMethodResetOnChange']
1033
+ }], withoutParameters: [{
1034
+ type: Input,
1035
+ args: ['rxapOptionsFromRemoteMethodWithoutParameters']
1036
+ }] } });
1037
+
1038
+ function UseComponent(component, setProperties = {}) {
1039
+ return function (target, propertyKey) {
1040
+ setMetadataMap(propertyKey, component, FormSystemMetadataKeys.COMPONENTS, target);
1041
+ setMetadataMap(propertyKey, setProperties, FormSystemMetadataKeys.COMPONENTS_PROPERTIES, target);
1042
+ };
1043
+ }
1044
+
1045
+ /**
1046
+ * Links a component with a form definition
1047
+ *
1048
+ * @param component
1049
+ */
1050
+ function UseFormComponent(component) {
1051
+ return function (target) {
1052
+ setMetadata(FormSystemMetadataKeys.FORM_COMPONENT, component, target);
1053
+ };
1054
+ }
1055
+
1056
+ const RXAP_FORM_CONTROL_SOURCE = new InjectionToken('rxap/forms/data-source');
1057
+ class ControlDataSource extends BaseDataSource {
1058
+ constructor(control, metadata = null) {
1059
+ super(metadata);
1060
+ this.control = control;
1061
+ }
1062
+ init() {
1063
+ if (this._initialised) {
1064
+ return;
1065
+ }
1066
+ super.init();
1067
+ if (isDevMode()) {
1068
+ console.log(this.control);
1069
+ }
1070
+ this._data$ = this.control.valueChanges.pipe(startWith$1(this.control.value), distinctUntilChanged$1((a, b) => equals(a, b)), shareReplay(1));
1071
+ }
1072
+ 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 }); }
1073
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlDataSource }); }
1074
+ }
1075
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlDataSource, decorators: [{
1076
+ type: Injectable
1077
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1078
+ type: Inject,
1079
+ args: [RXAP_FORM_CONTROL_SOURCE]
1080
+ }] }, { type: undefined, decorators: [{
1081
+ type: Optional
1082
+ }, {
1083
+ type: Inject,
1084
+ args: [RXAP_DATA_SOURCE_METADATA]
1085
+ }] }]; } });
1086
+ function controlDataSource(control) {
1087
+ // TODO : remove as any (wait for @rxap/forms update)
1088
+ return new ControlDataSource(control, { id: control.controlId });
1089
+ }
1090
+
1091
+ function FormContextFromActivatedRouteFactory(route) {
1092
+ return route.snapshot.params;
1093
+ }
1094
+
1095
+ let FormSystemControlDirective = class FormSystemControlDirective {
1096
+ constructor(parent, cfr, viewContainerRef, dataSourceLoader, injector) {
1097
+ this.parent = parent;
1098
+ this.cfr = cfr;
1099
+ this.viewContainerRef = viewContainerRef;
1100
+ this.dataSourceLoader = dataSourceLoader;
1101
+ this.injector = injector;
1102
+ }
1103
+ ngOnInit() {
1104
+ this.control = this.extractControl();
1105
+ const formDefinition = this.extractFormDefinition();
1106
+ this.componentRef = this.createComponent(formDefinition);
1107
+ this.setDataSources(formDefinition, this.componentRef.instance);
1108
+ this.setComponentProperties(formDefinition, this.componentRef.instance);
1109
+ this.viewContainerRef.insert(this.componentRef.hostView);
1110
+ }
1111
+ registerOnChange(fn) {
1112
+ this.componentRef.instance.registerOnChange(fn);
1113
+ }
1114
+ registerOnTouched(fn) {
1115
+ this.componentRef.instance.registerOnTouched(fn);
1116
+ }
1117
+ writeValue(value) {
1118
+ this.componentRef.instance.writeValue(value);
1119
+ }
1120
+ setDisabledState(isDisabled) {
1121
+ if (this.componentRef.instance.setDisabledState) {
1122
+ this.componentRef.instance.setDisabledState(isDisabled);
1123
+ }
1124
+ }
1125
+ setDataSources(formDefinition, component) {
1126
+ if (!component.setDataSource) {
1127
+ throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
1128
+ }
1129
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
1130
+ for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
1131
+ let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
1132
+ const settings = useDataSourceValue.settings;
1133
+ if (settings?.transformer) {
1134
+ dataSource = new PipeDataSource(dataSource, map(settings.transformer));
1135
+ }
1136
+ component.setDataSource(name, dataSource, useDataSourceValue.settings);
1137
+ }
1138
+ }
1139
+ setComponentProperties(formDefinition, component) {
1140
+ const componentProperties = this.extractComponentProperties(formDefinition);
1141
+ for (const [key, value] of Object.entries(componentProperties)) {
1142
+ Reflect.set(component, key, value);
1143
+ }
1144
+ }
1145
+ createComponent(formDefinition) {
1146
+ const component = this.extractComponent(formDefinition);
1147
+ const componentFactory = this.cfr.resolveComponentFactory(component);
1148
+ return componentFactory.create(this.injector);
1149
+ }
1150
+ extractControl() {
1151
+ if (!this.parent.control) {
1152
+ throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
1153
+ }
1154
+ const control = this.parent.control.get(this.controlId);
1155
+ if (!control) {
1156
+ throw new RxapFormSystemError('Could not find the control instance', '');
1157
+ }
1158
+ if (!(control instanceof RxapFormControl)) {
1159
+ throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
1160
+ }
1161
+ return control;
1162
+ }
1163
+ extractFormDefinition() {
1164
+ const formDefinition = this.control.rxapFormDefinition;
1165
+ if (!formDefinition) {
1166
+ throw new RxapFormSystemError('Could not find the form definition instance', '');
1167
+ }
1168
+ return formDefinition;
1169
+ }
1170
+ extractComponent(formDefinition) {
1171
+ const map = getMetadata(FormSystemMetadataKeys.COMPONENTS, Object.getPrototypeOf(formDefinition));
1172
+ if (!map) {
1173
+ throw new RxapFormSystemError('Could not extract the use component map from the form definition instance', '');
1174
+ }
1175
+ if (!map.has(this.controlId)) {
1176
+ throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
1177
+ }
1178
+ return map.get(this.controlId);
1179
+ }
1180
+ extractComponentProperties(formDefinition) {
1181
+ const map = getMetadata(FormSystemMetadataKeys.COMPONENTS_PROPERTIES, Object.getPrototypeOf(formDefinition));
1182
+ if (!map) {
1183
+ throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
1184
+ }
1185
+ if (!map.has(this.controlId)) {
1186
+ throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
1187
+ }
1188
+ return map.get(this.controlId);
1189
+ }
1190
+ 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 }); }
1191
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: FormSystemControlDirective, isStandalone: true, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 }); }
1192
+ };
1193
+ FormSystemControlDirective = __decorate([
1194
+ Mixin(ExtractDataSourcesMixin),
1195
+ __metadata("design:paramtypes", [ControlContainer,
1196
+ ComponentFactoryResolver,
1197
+ ViewContainerRef,
1198
+ DataSourceLoader,
968
1199
  Injector])
969
- ], IsSelectableValueDirective);
970
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: IsSelectableValueDirective, decorators: [{
1200
+ ], FormSystemControlDirective);
1201
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
971
1202
  type: Directive,
972
1203
  args: [{
973
- selector: '[rxapIsSelectableValue]',
974
- providers: [
975
- {
976
- provide: NG_VALIDATORS,
977
- multi: true,
978
- useExisting: forwardRef(() => IsSelectableValueDirective),
979
- },
980
- ],
1204
+ selector: '[rxapFormSystemControl]',
981
1205
  standalone: true,
982
1206
  }]
983
- }], ctorParameters: function () { return [{ type: i1$1.DataSourceLoader, decorators: [{
1207
+ }], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
1208
+ type: Inject,
1209
+ args: [ControlContainer]
1210
+ }] }, { type: i0.ComponentFactoryResolver, decorators: [{
1211
+ type: Inject,
1212
+ args: [ComponentFactoryResolver]
1213
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1214
+ type: Inject,
1215
+ args: [ViewContainerRef]
1216
+ }] }, { type: i1.DataSourceLoader, decorators: [{
984
1217
  type: Inject,
985
1218
  args: [DataSourceLoader]
986
1219
  }] }, { type: i0.Injector, decorators: [{
987
1220
  type: Inject,
988
1221
  args: [INJECTOR]
989
- }] }]; }, propDecorators: { viewer: [{
990
- type: Input
1222
+ }] }]; }, propDecorators: { controlId: [{
1223
+ type: Input,
1224
+ args: [{ required: true }]
991
1225
  }] } });
992
1226
 
1227
+ const SUBMIT_CONTEXT_FORM_ADAPTER_METHOD = new InjectionToken('submit-context-form-adapter-method');
1228
+ class SubmitContextFormAdapter extends ProxyRemoteMethod {
1229
+ constructor(remoteMethod, context) {
1230
+ super(remoteMethod);
1231
+ this.context = context;
1232
+ }
1233
+ transformParameters(value) {
1234
+ return {
1235
+ parameters: this.context ?? {},
1236
+ requestBody: value,
1237
+ };
1238
+ }
1239
+ 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 }); }
1240
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter }); }
1241
+ }
1242
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter, decorators: [{
1243
+ type: Injectable
1244
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1245
+ type: Inject,
1246
+ args: [SUBMIT_CONTEXT_FORM_ADAPTER_METHOD]
1247
+ }] }, { type: undefined, decorators: [{
1248
+ type: Inject,
1249
+ args: [RXAP_FORM_CONTEXT]
1250
+ }] }]; } });
1251
+ function SubmitContextFormAdapterFactory(remoteMethod, context) {
1252
+ return new SubmitContextFormAdapter(remoteMethod, context);
1253
+ }
1254
+
1255
+ // region validators
993
1256
  // endregion
994
1257
 
995
1258
  /**
996
1259
  * Generated bundle index. Do not edit.
997
1260
  */
998
1261
 
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 };
1262
+ 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
1263
  //# sourceMappingURL=rxap-form-system.mjs.map