@rxap/form-system 16.0.0-dev.11 → 16.0.0-dev.13
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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/esm2022/index.mjs +28 -19
- package/esm2022/lib/directives/array/for-form-array-items.directive.mjs +64 -0
- package/esm2022/lib/directives/array/form-array-add-item-button.directive.mjs +61 -0
- package/esm2022/lib/directives/array/form-array-item-button.mjs +71 -0
- package/esm2022/lib/directives/array/form-array-item-remove-button.directive.mjs +30 -0
- package/esm2022/lib/directives/array/form-array-item-restore-button.directive.mjs +30 -0
- package/esm2022/lib/directives/array/form-array-removable.directive.mjs +62 -0
- package/fesm2022/rxap-form-system.mjs +772 -486
- package/fesm2022/rxap-form-system.mjs.map +1 -1
- package/index.d.ts +20 -13
- package/lib/directives/array/for-form-array-items.directive.d.ts +26 -0
- package/lib/directives/array/form-array-add-item-button.directive.d.ts +20 -0
- package/lib/directives/array/form-array-item-button.d.ts +29 -0
- package/lib/directives/array/form-array-item-remove-button.directive.d.ts +9 -0
- package/lib/directives/array/form-array-item-restore-button.directive.d.ts +9 -0
- package/lib/directives/array/form-array-removable.directive.d.ts +19 -0
- package/package.json +20 -19
|
@@ -1,93 +1,134 @@
|
|
|
1
|
-
import { RxapError, equals } from '@rxap/utilities';
|
|
2
|
-
import * as i1$1 from '@rxap/data-source';
|
|
3
|
-
import { BaseDataSource, RXAP_DATA_SOURCE_METADATA, PipeDataSource, DataSourceLoader } from '@rxap/data-source';
|
|
4
1
|
import * as i0 from '@angular/core';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import * as i2 from '@rxap/remote-method';
|
|
9
|
-
import { ProxyRemoteMethod, RemoteMethodLoader } from '@rxap/remote-method';
|
|
2
|
+
import { forwardRef, Directive, Input, isDevMode, INJECTOR, Injector, Inject, SkipSelf, Optional, HostBinding, HostListener, Renderer2, ElementRef, Self, TemplateRef, ViewContainerRef, ChangeDetectorRef, NgModule, InjectionToken, Injectable, ComponentFactoryResolver } from '@angular/core';
|
|
3
|
+
import * as i1$1 from '@angular/forms';
|
|
4
|
+
import { NG_VALIDATORS, NgControl, UntypedFormGroup, UntypedFormArray, ControlContainer } from '@angular/forms';
|
|
10
5
|
import { __decorate, __metadata } from 'tslib';
|
|
11
|
-
import * as i1 from '@
|
|
12
|
-
import {
|
|
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 {
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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.
|
|
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
|
-
|
|
62
|
-
|
|
115
|
+
class RxapFormSystemError extends RxapError {
|
|
116
|
+
constructor(message, code, className) {
|
|
117
|
+
super('@rxap/form-system', message, code, className);
|
|
118
|
+
}
|
|
63
119
|
}
|
|
64
120
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
121
|
+
class ExtractDataSourcesMixin {
|
|
122
|
+
extractDataSources(formDefinition, controlId) {
|
|
123
|
+
const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
|
|
124
|
+
if (!map) {
|
|
125
|
+
throw new RxapFormSystemError('Could not extract the use data source map from the form definition instance', '');
|
|
126
|
+
}
|
|
127
|
+
if (!map.has(controlId)) {
|
|
128
|
+
throw new RxapFormSystemError('A use data source definition does not exists in the form definition metadata', '');
|
|
129
|
+
}
|
|
130
|
+
return map.get(controlId);
|
|
76
131
|
}
|
|
77
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter, deps: [{ token: SUBMIT_CONTEXT_FORM_ADAPTER_METHOD }, { token: RXAP_FORM_CONTEXT }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
78
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter }); }
|
|
79
|
-
}
|
|
80
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SubmitContextFormAdapter, decorators: [{
|
|
81
|
-
type: Injectable
|
|
82
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
83
|
-
type: Inject,
|
|
84
|
-
args: [SUBMIT_CONTEXT_FORM_ADAPTER_METHOD]
|
|
85
|
-
}] }, { type: undefined, decorators: [{
|
|
86
|
-
type: Inject,
|
|
87
|
-
args: [RXAP_FORM_CONTEXT]
|
|
88
|
-
}] }]; } });
|
|
89
|
-
function SubmitContextFormAdapterFactory(remoteMethod, context) {
|
|
90
|
-
return new SubmitContextFormAdapter(remoteMethod, context);
|
|
91
132
|
}
|
|
92
133
|
|
|
93
134
|
class ExtractFormDefinitionMixin {
|
|
@@ -101,146 +142,129 @@ class ExtractFormDefinitionMixin {
|
|
|
101
142
|
}
|
|
102
143
|
}
|
|
103
144
|
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return function (target, propertyKey) {
|
|
108
|
-
setMetadataMapMap(propertyKey, name, remoteMethod, RXAP_USE_REMOTE_METHOD, target);
|
|
109
|
-
};
|
|
145
|
+
const DATA_SOURCE_NAME = 'options';
|
|
146
|
+
function ComposeOptionsTransformers(...fnc) {
|
|
147
|
+
return base => fnc.reduce((source, transform) => transform(source), base);
|
|
110
148
|
}
|
|
111
|
-
function
|
|
149
|
+
function UseOptionsDataSource(dataSource, settings) {
|
|
112
150
|
return function (target, propertyKey) {
|
|
113
|
-
|
|
151
|
+
UseDataSource(dataSource, DATA_SOURCE_NAME, settings)(target, propertyKey);
|
|
114
152
|
};
|
|
115
153
|
}
|
|
116
|
-
class
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (!
|
|
120
|
-
throw new
|
|
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');
|
|
121
159
|
}
|
|
122
|
-
|
|
123
|
-
|
|
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`);
|
|
124
164
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.ngControl = ngControl;
|
|
131
|
-
this.template = template;
|
|
132
|
-
this.remoteMethodLoader = remoteMethodLoader;
|
|
133
|
-
this.viewContainerRef = viewContainerRef;
|
|
134
|
-
this.injector = injector;
|
|
135
|
-
this.cdr = cdr;
|
|
136
|
-
this.withoutParameters = false;
|
|
137
|
-
}
|
|
138
|
-
ngOnChanges(changes) {
|
|
139
|
-
const parametersChanges = changes['parameters'];
|
|
140
|
-
if (parametersChanges) {
|
|
141
|
-
if (!this.remoteMethodToken) {
|
|
142
|
-
this.remoteMethodToken = this.extractRemoteMethodToken();
|
|
143
|
-
}
|
|
144
|
-
this.renderTemplate(parametersChanges.currentValue);
|
|
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);
|
|
145
170
|
}
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
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);
|
|
149
177
|
}
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
extractRemoteMethodToken() {
|
|
154
|
-
const control = this.ngControl.control;
|
|
155
|
-
if (!(control instanceof RxapFormControl)) {
|
|
156
|
-
throw new Error('Control is not a RxapFormControl!');
|
|
157
|
-
}
|
|
158
|
-
const formDefinition = this.extractFormDefinition(control);
|
|
159
|
-
const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
|
|
160
|
-
if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
|
|
161
|
-
throw new Error(`The remote method with the name 'options' is not defined`);
|
|
178
|
+
throw e;
|
|
162
179
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
async renderTemplate(parameters) {
|
|
166
|
-
const options = await this.remoteMethodLoader.call$(this.remoteMethodToken, parameters, undefined, this.injector);
|
|
167
|
-
this.viewContainerRef.clear();
|
|
168
|
-
for (const option of options) {
|
|
169
|
-
this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
|
|
180
|
+
if (this.settings?.transformer) {
|
|
181
|
+
dataSource = new PipeDataSource(dataSource, map(this.settings.transformer), tap(options => useDataSourceValue.lastValue = options));
|
|
170
182
|
}
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
else {
|
|
184
|
+
dataSource = new PipeDataSource(dataSource, tap(options => useDataSourceValue.lastValue = options));
|
|
173
185
|
}
|
|
174
|
-
this.
|
|
186
|
+
return this.dataSource = dataSource;
|
|
175
187
|
}
|
|
176
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, deps: [{ token: NgControl }, { token: TemplateRef }, { token: RemoteMethodLoader }, { token: ViewContainerRef }, { token: INJECTOR }, { token: ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
177
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: OptionsFromRemoteMethodDirective, isStandalone: true, selector: "[rxapOptionsFromRemoteMethod]", inputs: { parameters: ["rxapOptionsFromRemoteMethodParameters", "parameters"], resetOnChange: ["rxapOptionsFromRemoteMethodResetOnChange", "resetOnChange"], withoutParameters: ["rxapOptionsFromRemoteMethodWithoutParameters", "withoutParameters"] }, usesOnChanges: true, ngImport: i0 }); }
|
|
178
188
|
};
|
|
179
|
-
|
|
180
|
-
Mixin(ExtractFormDefinitionMixin,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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: [{
|
|
189
246
|
type: Directive,
|
|
190
247
|
args: [{
|
|
191
|
-
selector: '[
|
|
248
|
+
selector: '[rxapIsSelectableValue]',
|
|
249
|
+
providers: [
|
|
250
|
+
{
|
|
251
|
+
provide: NG_VALIDATORS,
|
|
252
|
+
multi: true,
|
|
253
|
+
useExisting: forwardRef(() => IsSelectableValueDirective),
|
|
254
|
+
},
|
|
255
|
+
],
|
|
192
256
|
standalone: true,
|
|
193
257
|
}]
|
|
194
|
-
}], ctorParameters: function () { return [{ type: i1.
|
|
195
|
-
type: Inject,
|
|
196
|
-
args: [NgControl]
|
|
197
|
-
}] }, { type: i0.TemplateRef, decorators: [{
|
|
198
|
-
type: Inject,
|
|
199
|
-
args: [TemplateRef]
|
|
200
|
-
}] }, { type: i2.RemoteMethodLoader, decorators: [{
|
|
201
|
-
type: Inject,
|
|
202
|
-
args: [RemoteMethodLoader]
|
|
203
|
-
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
258
|
+
}], ctorParameters: function () { return [{ type: i1.DataSourceLoader, decorators: [{
|
|
204
259
|
type: Inject,
|
|
205
|
-
args: [
|
|
260
|
+
args: [DataSourceLoader]
|
|
206
261
|
}] }, { type: i0.Injector, decorators: [{
|
|
207
262
|
type: Inject,
|
|
208
263
|
args: [INJECTOR]
|
|
209
|
-
}] },
|
|
210
|
-
|
|
211
|
-
args: [ChangeDetectorRef]
|
|
212
|
-
}] }]; }, propDecorators: { parameters: [{
|
|
213
|
-
type: Input,
|
|
214
|
-
args: ['rxapOptionsFromRemoteMethodParameters']
|
|
215
|
-
}], resetOnChange: [{
|
|
216
|
-
type: Input,
|
|
217
|
-
args: ['rxapOptionsFromRemoteMethodResetOnChange']
|
|
218
|
-
}], withoutParameters: [{
|
|
219
|
-
type: Input,
|
|
220
|
-
args: ['rxapOptionsFromRemoteMethodWithoutParameters']
|
|
264
|
+
}] }]; }, propDecorators: { viewer: [{
|
|
265
|
+
type: Input
|
|
221
266
|
}] } });
|
|
222
267
|
|
|
223
|
-
var FormSystemMetadataKeys;
|
|
224
|
-
(function (FormSystemMetadataKeys) {
|
|
225
|
-
FormSystemMetadataKeys["COMPONENTS"] = "rxap/form-system/components";
|
|
226
|
-
FormSystemMetadataKeys["DATA_SOURCES"] = "rxap/form-system/data-sources";
|
|
227
|
-
FormSystemMetadataKeys["COMPONENTS_PROPERTIES"] = "rxap/form-system/components-properties";
|
|
228
|
-
FormSystemMetadataKeys["FORM_COMPONENT"] = "rxap/window-form-system/form-component";
|
|
229
|
-
})(FormSystemMetadataKeys || (FormSystemMetadataKeys = {}));
|
|
230
|
-
|
|
231
|
-
class ExtractDataSourcesMixin {
|
|
232
|
-
extractDataSources(formDefinition, controlId) {
|
|
233
|
-
const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
|
|
234
|
-
if (!map) {
|
|
235
|
-
throw new RxapFormSystemError('Could not extract the use data source map from the form definition instance', '');
|
|
236
|
-
}
|
|
237
|
-
if (!map.has(controlId)) {
|
|
238
|
-
throw new RxapFormSystemError('A use data source definition does not exists in the form definition metadata', '');
|
|
239
|
-
}
|
|
240
|
-
return map.get(controlId);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
268
|
class ExtractControlFromParentMixin {
|
|
245
269
|
extractControlFromParent(parent, controlPath) {
|
|
246
270
|
if (!controlPath) {
|
|
@@ -262,232 +286,289 @@ class ExtractControlFromParentMixin {
|
|
|
262
286
|
}
|
|
263
287
|
}
|
|
264
288
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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();
|
|
281
305
|
}
|
|
282
|
-
|
|
283
|
-
throw new Error('The
|
|
306
|
+
else {
|
|
307
|
+
throw new Error('The control container is not an instance of RxapFormArray');
|
|
284
308
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
+
}
|
|
289
331
|
}
|
|
290
|
-
|
|
332
|
+
this.cdr.detectChanges();
|
|
291
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 }); }
|
|
292
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 }]; } });
|
|
293
346
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
|
|
311
|
-
if (!useDataSourceValueMap.has('options')) {
|
|
312
|
-
throw new Error(`The data source with the name 'options' is not defined`);
|
|
313
|
-
}
|
|
314
|
-
const useDataSourceValue = this.useDataSourceValue = useDataSourceValueMap.get('options');
|
|
315
|
-
this.settings = this.useDataSourceValue.settings ?? {};
|
|
316
|
-
let dataSource;
|
|
317
|
-
try {
|
|
318
|
-
dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
|
|
319
|
-
}
|
|
320
|
-
catch (e) {
|
|
321
|
-
if (e.name && e.name === 'NullInjectorError') {
|
|
322
|
-
if (isDevMode()) {
|
|
323
|
-
console.error('Cloud not inject the options data source', this.useDataSourceValue);
|
|
324
|
-
}
|
|
325
|
-
throw new Error('Cloud not inject the options data source:\n' + e.message);
|
|
326
|
-
}
|
|
327
|
-
throw e;
|
|
328
|
-
}
|
|
329
|
-
if (this.settings?.transformer) {
|
|
330
|
-
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;
|
|
331
363
|
}
|
|
332
|
-
|
|
333
|
-
|
|
364
|
+
if (this.matButton) {
|
|
365
|
+
this._controlDisabledSubscription = this.formArray.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
|
|
334
366
|
}
|
|
335
|
-
return this.dataSource = dataSource;
|
|
336
367
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
+
}] } });
|
|
341
399
|
|
|
342
|
-
|
|
343
|
-
|
|
400
|
+
// TODO : move to rxap packages
|
|
401
|
+
class FormArrayItemButton {
|
|
402
|
+
constructor(parent, matButton, renderer, elementRef) {
|
|
344
403
|
this.parent = parent;
|
|
345
|
-
this.
|
|
346
|
-
this.
|
|
347
|
-
this.
|
|
348
|
-
this.
|
|
404
|
+
this.matButton = matButton;
|
|
405
|
+
this.renderer = renderer;
|
|
406
|
+
this.elementRef = elementRef;
|
|
407
|
+
this.type = 'button';
|
|
349
408
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const formDefinition = this.extractFormDefinition();
|
|
353
|
-
this.componentRef = this.createComponent(formDefinition);
|
|
354
|
-
this.setDataSources(formDefinition, this.componentRef.instance);
|
|
355
|
-
this.setComponentProperties(formDefinition, this.componentRef.instance);
|
|
356
|
-
this.viewContainerRef.insert(this.componentRef.hostView);
|
|
409
|
+
get disabled() {
|
|
410
|
+
return this.isDisabled;
|
|
357
411
|
}
|
|
358
|
-
|
|
359
|
-
this.
|
|
412
|
+
get isDeleted() {
|
|
413
|
+
return this.deletedControl.value;
|
|
360
414
|
}
|
|
361
|
-
|
|
362
|
-
this.
|
|
415
|
+
get index() {
|
|
416
|
+
return this.formGroup.parent.controls.findIndex(control => control === this.formGroup);
|
|
363
417
|
}
|
|
364
|
-
|
|
365
|
-
this.
|
|
418
|
+
get isDisabled() {
|
|
419
|
+
return !!this.formGroup?.parent?.disabled;
|
|
366
420
|
}
|
|
367
|
-
|
|
368
|
-
if (this.
|
|
369
|
-
this.
|
|
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
|
+
}
|
|
370
433
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (!component.setDataSource) {
|
|
374
|
-
throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
|
|
434
|
+
else {
|
|
435
|
+
throw new Error(`The parent is not a form group instance`);
|
|
375
436
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
|
|
379
|
-
const settings = useDataSourceValue.settings;
|
|
380
|
-
if (settings?.transformer) {
|
|
381
|
-
dataSource = new PipeDataSource(dataSource, map(settings.transformer));
|
|
382
|
-
}
|
|
383
|
-
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();
|
|
384
439
|
}
|
|
440
|
+
this.deletedControl.value$.pipe(tap$1(() => this.updateDisplayStyle())).subscribe();
|
|
385
441
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
Reflect.set(component, key, value);
|
|
390
|
-
}
|
|
442
|
+
ngOnDestroy() {
|
|
443
|
+
this._controlDisabledSubscription?.unsubscribe();
|
|
444
|
+
this._deletedControlValueSubscription?.unsubscribe();
|
|
391
445
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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);
|
|
396
467
|
}
|
|
397
|
-
|
|
398
|
-
if (
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
const control = this.parent.control.get(this.controlId);
|
|
402
|
-
if (!control) {
|
|
403
|
-
throw new RxapFormSystemError('Could not find the control instance', '');
|
|
404
|
-
}
|
|
405
|
-
if (!(control instanceof RxapFormControl)) {
|
|
406
|
-
throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
|
|
468
|
+
updateDisplayStyle() {
|
|
469
|
+
if (this.isDeleted) {
|
|
470
|
+
this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
|
|
407
471
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
extractFormDefinition() {
|
|
411
|
-
const formDefinition = this.control.rxapFormDefinition;
|
|
412
|
-
if (!formDefinition) {
|
|
413
|
-
throw new RxapFormSystemError('Could not find the form definition instance', '');
|
|
472
|
+
else {
|
|
473
|
+
this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
|
|
414
474
|
}
|
|
415
|
-
return formDefinition;
|
|
416
475
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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);
|
|
426
494
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
|
|
495
|
+
updateDisplayStyle() {
|
|
496
|
+
if (this.isDeleted) {
|
|
497
|
+
this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
|
|
431
498
|
}
|
|
432
|
-
|
|
433
|
-
|
|
499
|
+
else {
|
|
500
|
+
this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
|
|
434
501
|
}
|
|
435
|
-
return map.get(this.controlId);
|
|
436
502
|
}
|
|
437
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type:
|
|
438
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type:
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
Mixin(ExtractDataSourcesMixin),
|
|
442
|
-
__metadata("design:paramtypes", [ControlContainer,
|
|
443
|
-
ComponentFactoryResolver,
|
|
444
|
-
ViewContainerRef,
|
|
445
|
-
DataSourceLoader,
|
|
446
|
-
Injector])
|
|
447
|
-
], FormSystemControlDirective);
|
|
448
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
|
|
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: [{
|
|
449
507
|
type: Directive,
|
|
450
508
|
args: [{
|
|
451
|
-
selector: '[
|
|
509
|
+
selector: 'button[rxapFormArrayItemRestoreButton]',
|
|
452
510
|
standalone: true,
|
|
453
511
|
}]
|
|
454
|
-
}],
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}] }, { type: i0.ComponentFactoryResolver, decorators: [{
|
|
458
|
-
type: Inject,
|
|
459
|
-
args: [ComponentFactoryResolver]
|
|
460
|
-
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
461
|
-
type: Inject,
|
|
462
|
-
args: [ViewContainerRef]
|
|
463
|
-
}] }, { type: i1$1.DataSourceLoader, decorators: [{
|
|
464
|
-
type: Inject,
|
|
465
|
-
args: [DataSourceLoader]
|
|
466
|
-
}] }, { type: i0.Injector, decorators: [{
|
|
467
|
-
type: Inject,
|
|
468
|
-
args: [INJECTOR]
|
|
469
|
-
}] }]; }, propDecorators: { controlId: [{
|
|
470
|
-
type: Input,
|
|
471
|
-
args: [{ required: true }]
|
|
512
|
+
}], propDecorators: { onClick: [{
|
|
513
|
+
type: HostListener,
|
|
514
|
+
args: ['click']
|
|
472
515
|
}] } });
|
|
473
516
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
517
|
+
// TODO : move to rxap packages
|
|
518
|
+
class FormArrayRemovableDirective {
|
|
519
|
+
constructor(parent) {
|
|
520
|
+
this.parent = parent;
|
|
521
|
+
}
|
|
522
|
+
get isDeleted() {
|
|
523
|
+
return this.deletedControl.value;
|
|
524
|
+
}
|
|
525
|
+
get isDisabled() {
|
|
526
|
+
return !!this.control?.parent?.disabled;
|
|
527
|
+
}
|
|
528
|
+
ngAfterViewInit() {
|
|
529
|
+
if (this.parent.control instanceof RxapFormGroup) {
|
|
530
|
+
this.control = this.parent.control;
|
|
531
|
+
if (this.control.controls.deleted instanceof RxapFormControl) {
|
|
532
|
+
this.deletedControl = this.control.controls.deleted;
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
throw new Error(`The parent FormGroup instance does not have a 'deleted' control`);
|
|
536
|
+
}
|
|
537
|
+
if (!(this.control.parent instanceof UntypedFormArray)) {
|
|
538
|
+
throw new Error(`The parent of the FormGroup is not a FormArray instance`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
throw new Error(`The parent is not a form group instance`);
|
|
543
|
+
}
|
|
544
|
+
this._deletedControlValueSubscription = this.deletedControl.value$.pipe(tap$1((isDeleted) => {
|
|
545
|
+
for (const [name, control] of Object.entries(this.control.controls)) {
|
|
546
|
+
if (name !== 'deleted') {
|
|
547
|
+
if (isDeleted) {
|
|
548
|
+
control.disable({ onlySelf: true });
|
|
549
|
+
}
|
|
550
|
+
else if (!this.isDisabled) {
|
|
551
|
+
control.enable({ onlySelf: true });
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
})).subscribe();
|
|
556
|
+
}
|
|
557
|
+
ngOnDestroy() {
|
|
558
|
+
this._deletedControlValueSubscription?.unsubscribe();
|
|
559
|
+
}
|
|
560
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.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 }); }
|
|
490
562
|
}
|
|
563
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayRemovableDirective, decorators: [{
|
|
564
|
+
type: Directive,
|
|
565
|
+
args: [{
|
|
566
|
+
selector: '[rxapFormArrayRemovable]',
|
|
567
|
+
standalone: true,
|
|
568
|
+
}]
|
|
569
|
+
}], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
|
|
570
|
+
type: Optional
|
|
571
|
+
}] }]; } });
|
|
491
572
|
|
|
492
573
|
const RXAP_FORM_SYSTEM_SHOW_METADATA = 'rxap/form-system/show-function';
|
|
493
574
|
const RXAP_FORM_SYSTEM_HIDE_METADATA = 'rxap/form-system/hide-function';
|
|
@@ -536,7 +617,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
|
|
|
536
617
|
if (options.rootChange) {
|
|
537
618
|
changeTrigger = formDefinition.rxapFormGroup.root.valueChanges;
|
|
538
619
|
}
|
|
539
|
-
changeTrigger = changeTrigger.pipe(startWith(null));
|
|
620
|
+
changeTrigger = changeTrigger.pipe(startWith$1(null));
|
|
540
621
|
if (showFunction) {
|
|
541
622
|
this.subscription.add(changeTrigger.pipe(tap(() => {
|
|
542
623
|
// TODO : resubscribe if the showFunction throws an error
|
|
@@ -631,12 +712,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
|
|
|
631
712
|
}] }, { type: i0.ElementRef, decorators: [{
|
|
632
713
|
type: Inject,
|
|
633
714
|
args: [ElementRef]
|
|
634
|
-
}] }, { type: i1.ControlContainer, decorators: [{
|
|
715
|
+
}] }, { type: i1$1.ControlContainer, decorators: [{
|
|
635
716
|
type: Optional
|
|
636
717
|
}, {
|
|
637
718
|
type: Inject,
|
|
638
719
|
args: [ControlContainer]
|
|
639
|
-
}] }, { type: i1.NgControl, decorators: [{
|
|
720
|
+
}] }, { type: i1$1.NgControl, decorators: [{
|
|
640
721
|
type: Self
|
|
641
722
|
}, {
|
|
642
723
|
type: Optional
|
|
@@ -676,7 +757,7 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
|
|
|
676
757
|
this.extractOptionsDatasource();
|
|
677
758
|
this.viewer = {
|
|
678
759
|
id: '[rxapInputSelectOptions]' + this.control.controlId,
|
|
679
|
-
viewChange: this.settings?.loadOnce ? EMPTY : this.control.value$.pipe(throttleTime(1000), distinctUntilChanged((a, b) => equals(a, b)), map(value => {
|
|
760
|
+
viewChange: this.settings?.loadOnce ? EMPTY : this.control.value$.pipe(throttleTime(1000), distinctUntilChanged$1((a, b) => equals(a, b)), map(value => {
|
|
680
761
|
if (this.settings?.ignoreSelectedValue) {
|
|
681
762
|
return {};
|
|
682
763
|
}
|
|
@@ -780,7 +861,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
|
|
|
780
861
|
}], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
|
|
781
862
|
type: Inject,
|
|
782
863
|
args: [TemplateRef]
|
|
783
|
-
}] }, { type: i1
|
|
864
|
+
}] }, { type: i1.DataSourceLoader, decorators: [{
|
|
784
865
|
type: Inject,
|
|
785
866
|
args: [DataSourceLoader]
|
|
786
867
|
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
@@ -792,7 +873,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
|
|
|
792
873
|
}] }, { type: i0.ChangeDetectorRef, decorators: [{
|
|
793
874
|
type: Inject,
|
|
794
875
|
args: [ChangeDetectorRef]
|
|
795
|
-
}] }, { type: i1.NgControl, decorators: [{
|
|
876
|
+
}] }, { type: i1$1.NgControl, decorators: [{
|
|
796
877
|
type: Optional
|
|
797
878
|
}, {
|
|
798
879
|
type: Inject,
|
|
@@ -834,143 +915,348 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
|
|
|
834
915
|
}]
|
|
835
916
|
}] });
|
|
836
917
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
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', '');
|
|
935
|
+
}
|
|
936
|
+
if (!map.has(controlId)) {
|
|
937
|
+
throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
|
|
842
938
|
}
|
|
939
|
+
return map.get(controlId);
|
|
843
940
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
941
|
+
}
|
|
942
|
+
let OptionsFromRemoteMethodDirective = class OptionsFromRemoteMethodDirective {
|
|
943
|
+
constructor(ngControl, template, remoteMethodLoader, viewContainerRef, injector, cdr) {
|
|
944
|
+
this.ngControl = ngControl;
|
|
945
|
+
this.template = template;
|
|
946
|
+
this.remoteMethodLoader = remoteMethodLoader;
|
|
947
|
+
this.viewContainerRef = viewContainerRef;
|
|
948
|
+
this.injector = injector;
|
|
949
|
+
this.cdr = cdr;
|
|
950
|
+
this.withoutParameters = false;
|
|
951
|
+
}
|
|
952
|
+
ngOnChanges(changes) {
|
|
953
|
+
const parametersChanges = changes['parameters'];
|
|
954
|
+
if (parametersChanges) {
|
|
955
|
+
if (!this.remoteMethodToken) {
|
|
956
|
+
this.remoteMethodToken = this.extractRemoteMethodToken();
|
|
957
|
+
}
|
|
958
|
+
this.renderTemplate(parametersChanges.currentValue);
|
|
959
|
+
}
|
|
960
|
+
if (changes['withoutParameters']?.currentValue) {
|
|
961
|
+
if (!this.remoteMethodToken) {
|
|
962
|
+
this.remoteMethodToken = this.extractRemoteMethodToken();
|
|
963
|
+
}
|
|
964
|
+
this.renderTemplate();
|
|
847
965
|
}
|
|
848
|
-
return {
|
|
849
|
-
isEqualTo: {
|
|
850
|
-
value: this._equalTo,
|
|
851
|
-
actualValue: control.value,
|
|
852
|
-
},
|
|
853
|
-
};
|
|
854
966
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
967
|
+
extractRemoteMethodToken() {
|
|
968
|
+
const control = this.ngControl.control;
|
|
969
|
+
if (!(control instanceof RxapFormControl)) {
|
|
970
|
+
throw new Error('Control is not a RxapFormControl!');
|
|
971
|
+
}
|
|
972
|
+
const formDefinition = this.extractFormDefinition(control);
|
|
973
|
+
const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
|
|
974
|
+
if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
|
|
975
|
+
throw new Error(`The remote method with the name 'options' is not defined`);
|
|
976
|
+
}
|
|
977
|
+
return remoteMethodsTokens.get(REMOTE_METHOD_NAME);
|
|
863
978
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
}
|
|
873
|
-
|
|
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: [{
|
|
874
1003
|
type: Directive,
|
|
875
1004
|
args: [{
|
|
876
|
-
selector: '[
|
|
877
|
-
providers: [
|
|
878
|
-
{
|
|
879
|
-
provide: NG_VALIDATORS,
|
|
880
|
-
multi: true,
|
|
881
|
-
useExisting: forwardRef(() => IsEqualToDirective),
|
|
882
|
-
},
|
|
883
|
-
],
|
|
1005
|
+
selector: '[rxapOptionsFromRemoteMethod]',
|
|
884
1006
|
standalone: true,
|
|
885
1007
|
}]
|
|
886
|
-
}],
|
|
1008
|
+
}], ctorParameters: function () { return [{ type: i1$1.NgControl, decorators: [{
|
|
1009
|
+
type: Inject,
|
|
1010
|
+
args: [NgControl]
|
|
1011
|
+
}] }, { type: i0.TemplateRef, decorators: [{
|
|
1012
|
+
type: Inject,
|
|
1013
|
+
args: [TemplateRef]
|
|
1014
|
+
}] }, { type: i2$1.RemoteMethodLoader, decorators: [{
|
|
1015
|
+
type: Inject,
|
|
1016
|
+
args: [RemoteMethodLoader]
|
|
1017
|
+
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
1018
|
+
type: Inject,
|
|
1019
|
+
args: [ViewContainerRef]
|
|
1020
|
+
}] }, { type: i0.Injector, decorators: [{
|
|
1021
|
+
type: Inject,
|
|
1022
|
+
args: [INJECTOR]
|
|
1023
|
+
}] }, { type: i0.ChangeDetectorRef, decorators: [{
|
|
1024
|
+
type: Inject,
|
|
1025
|
+
args: [ChangeDetectorRef]
|
|
1026
|
+
}] }]; }, propDecorators: { parameters: [{
|
|
887
1027
|
type: Input,
|
|
888
|
-
args: [
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1028
|
+
args: ['rxapOptionsFromRemoteMethodParameters']
|
|
1029
|
+
}], resetOnChange: [{
|
|
1030
|
+
type: Input,
|
|
1031
|
+
args: ['rxapOptionsFromRemoteMethodResetOnChange']
|
|
1032
|
+
}], withoutParameters: [{
|
|
1033
|
+
type: Input,
|
|
1034
|
+
args: ['rxapOptionsFromRemoteMethodWithoutParameters']
|
|
892
1035
|
}] } });
|
|
893
1036
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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;
|
|
898
1099
|
this.dataSourceLoader = dataSourceLoader;
|
|
899
1100
|
this.injector = injector;
|
|
900
|
-
this.viewer = { id: '[rxapIsSelectableValue]' };
|
|
901
1101
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1102
|
+
ngOnInit() {
|
|
1103
|
+
this.control = this.extractControl();
|
|
1104
|
+
const formDefinition = this.extractFormDefinition();
|
|
1105
|
+
this.componentRef = this.createComponent(formDefinition);
|
|
1106
|
+
this.setDataSources(formDefinition, this.componentRef.instance);
|
|
1107
|
+
this.setComponentProperties(formDefinition, this.componentRef.instance);
|
|
1108
|
+
this.viewContainerRef.insert(this.componentRef.hostView);
|
|
1109
|
+
}
|
|
1110
|
+
registerOnChange(fn) {
|
|
1111
|
+
this.componentRef.instance.registerOnChange(fn);
|
|
1112
|
+
}
|
|
1113
|
+
registerOnTouched(fn) {
|
|
1114
|
+
this.componentRef.instance.registerOnTouched(fn);
|
|
1115
|
+
}
|
|
1116
|
+
writeValue(value) {
|
|
1117
|
+
this.componentRef.instance.writeValue(value);
|
|
1118
|
+
}
|
|
1119
|
+
setDisabledState(isDisabled) {
|
|
1120
|
+
if (this.componentRef.instance.setDisabledState) {
|
|
1121
|
+
this.componentRef.instance.setDisabledState(isDisabled);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
setDataSources(formDefinition, component) {
|
|
1125
|
+
if (!component.setDataSource) {
|
|
1126
|
+
throw new RxapFormSystemError('The ControlWithDataSource interface is not implemented for the control component, but the control has defined data sources', '');
|
|
1127
|
+
}
|
|
1128
|
+
const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
|
|
1129
|
+
for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
|
|
1130
|
+
let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
|
|
1131
|
+
const settings = useDataSourceValue.settings;
|
|
1132
|
+
if (settings?.transformer) {
|
|
1133
|
+
dataSource = new PipeDataSource(dataSource, map(settings.transformer));
|
|
928
1134
|
}
|
|
1135
|
+
component.setDataSource(name, dataSource, useDataSourceValue.settings);
|
|
929
1136
|
}
|
|
930
|
-
return null;
|
|
931
1137
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
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 }); }
|
|
940
1191
|
};
|
|
941
|
-
|
|
942
|
-
Mixin(
|
|
943
|
-
__metadata("design:paramtypes", [
|
|
1192
|
+
FormSystemControlDirective = __decorate([
|
|
1193
|
+
Mixin(ExtractDataSourcesMixin),
|
|
1194
|
+
__metadata("design:paramtypes", [ControlContainer,
|
|
1195
|
+
ComponentFactoryResolver,
|
|
1196
|
+
ViewContainerRef,
|
|
1197
|
+
DataSourceLoader,
|
|
944
1198
|
Injector])
|
|
945
|
-
],
|
|
946
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type:
|
|
1199
|
+
], FormSystemControlDirective);
|
|
1200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
|
|
947
1201
|
type: Directive,
|
|
948
1202
|
args: [{
|
|
949
|
-
selector: '[
|
|
950
|
-
providers: [
|
|
951
|
-
{
|
|
952
|
-
provide: NG_VALIDATORS,
|
|
953
|
-
multi: true,
|
|
954
|
-
useExisting: forwardRef(() => IsSelectableValueDirective),
|
|
955
|
-
},
|
|
956
|
-
],
|
|
1203
|
+
selector: '[rxapFormSystemControl]',
|
|
957
1204
|
standalone: true,
|
|
958
1205
|
}]
|
|
959
|
-
}], ctorParameters: function () { return [{ type: i1$1.
|
|
1206
|
+
}], ctorParameters: function () { return [{ type: i1$1.ControlContainer, decorators: [{
|
|
1207
|
+
type: Inject,
|
|
1208
|
+
args: [ControlContainer]
|
|
1209
|
+
}] }, { type: i0.ComponentFactoryResolver, decorators: [{
|
|
1210
|
+
type: Inject,
|
|
1211
|
+
args: [ComponentFactoryResolver]
|
|
1212
|
+
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
1213
|
+
type: Inject,
|
|
1214
|
+
args: [ViewContainerRef]
|
|
1215
|
+
}] }, { type: i1.DataSourceLoader, decorators: [{
|
|
960
1216
|
type: Inject,
|
|
961
1217
|
args: [DataSourceLoader]
|
|
962
1218
|
}] }, { type: i0.Injector, decorators: [{
|
|
963
1219
|
type: Inject,
|
|
964
1220
|
args: [INJECTOR]
|
|
965
|
-
}] }]; }, propDecorators: {
|
|
966
|
-
type: Input
|
|
1221
|
+
}] }]; }, propDecorators: { controlId: [{
|
|
1222
|
+
type: Input,
|
|
1223
|
+
args: [{ required: true }]
|
|
967
1224
|
}] } });
|
|
968
1225
|
|
|
1226
|
+
const SUBMIT_CONTEXT_FORM_ADAPTER_METHOD = new InjectionToken('submit-context-form-adapter-method');
|
|
1227
|
+
class SubmitContextFormAdapter extends ProxyRemoteMethod {
|
|
1228
|
+
constructor(remoteMethod, context) {
|
|
1229
|
+
super(remoteMethod);
|
|
1230
|
+
this.context = context;
|
|
1231
|
+
}
|
|
1232
|
+
transformParameters(value) {
|
|
1233
|
+
return {
|
|
1234
|
+
parameters: this.context ?? {},
|
|
1235
|
+
requestBody: value,
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.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
|
|
969
1255
|
// endregion
|
|
970
1256
|
|
|
971
1257
|
/**
|
|
972
1258
|
* Generated bundle index. Do not edit.
|
|
973
1259
|
*/
|
|
974
1260
|
|
|
975
|
-
export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, DATA_SOURCE_NAME, ExtractControlFromParentMixin, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, ExtractOptionsDataSourceMixin, ExtractRemoteMethodsMixin, FormContextFromActivatedRouteFactory, FormSystemControlDirective, FormSystemDirectivesModule, FormSystemMetadataKeys, InputSelectOptionsDirective, IsEqualToDirective, IsSelectableValueDirective, OptionsFromRemoteMethodDirective, REMOTE_METHOD_NAME, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RXAP_USE_REMOTE_METHOD, RxapFormSystemError, SUBMIT_CONTEXT_FORM_ADAPTER_METHOD, SubmitContextFormAdapter, SubmitContextFormAdapterFactory, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseOptionsRemoteMethod, UseRemoteMethod, UseShowFunction, controlDataSource };
|
|
1261
|
+
export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, DATA_SOURCE_NAME, ExtractControlFromParentMixin, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, ExtractOptionsDataSourceMixin, ExtractRemoteMethodsMixin, ForFormArrayItemsDirective, FormArrayAddItemButtonDirective, FormArrayItemButton, FormArrayItemRemoveButtonDirective, FormArrayItemRestoreButtonDirective, FormArrayRemovableDirective, FormContextFromActivatedRouteFactory, FormSystemControlDirective, FormSystemDirectivesModule, FormSystemMetadataKeys, InputSelectOptionsDirective, IsEqualToDirective, IsSelectableValueDirective, OptionsFromRemoteMethodDirective, REMOTE_METHOD_NAME, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RXAP_USE_REMOTE_METHOD, RxapFormSystemError, SUBMIT_CONTEXT_FORM_ADAPTER_METHOD, SubmitContextFormAdapter, SubmitContextFormAdapterFactory, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseOptionsRemoteMethod, UseRemoteMethod, UseShowFunction, controlDataSource };
|
|
976
1262
|
//# sourceMappingURL=rxap-form-system.mjs.map
|