@rxap/form-system 16.0.0-dev.2 → 16.0.0-dev.20
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 +406 -0
- package/LICENSE +621 -21
- package/LICENSE.md +621 -0
- package/README.md +7 -22
- package/esm2022/index.mjs +28 -15
- package/esm2022/lib/control-data-source.mjs +7 -8
- package/esm2022/lib/control-with-data-source.mjs +1 -1
- package/esm2022/lib/decorators/metadata-keys.mjs +1 -1
- package/esm2022/lib/decorators/use-component.mjs +2 -2
- package/esm2022/lib/decorators/use-data-source.mjs +6 -3
- package/esm2022/lib/decorators/use-form-component.mjs +2 -2
- 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/esm2022/lib/directives/control-hide-show.directive.mjs +12 -13
- package/esm2022/lib/directives/form-directives.module.mjs +25 -0
- package/esm2022/lib/directives/input-select-options.directive.mjs +29 -28
- package/esm2022/lib/directives/options-from-remote-method.directive.mjs +131 -0
- package/esm2022/lib/error.mjs +1 -1
- package/esm2022/lib/form-context-from-activated-route.factory.mjs +4 -0
- package/esm2022/lib/form-system-control.directive.mjs +14 -27
- package/esm2022/lib/mixins/extract-control-from-parent.mixin.mjs +5 -3
- package/esm2022/lib/mixins/extract-control.mixin.mjs +5 -3
- package/esm2022/lib/mixins/extract-data-sources.mixin.mjs +2 -2
- package/esm2022/lib/mixins/extract-form-definition.mixin.mjs +1 -1
- package/esm2022/lib/mixins/extract-options-data-source.mixin.mjs +9 -10
- package/esm2022/lib/submit-context-form-adapter.factory.mjs +32 -0
- package/esm2022/lib/validators/is-equal-to.mjs +22 -22
- package/esm2022/lib/validators/is-selectable-value.directive.mjs +20 -16
- package/esm2022/rxap-form-system.mjs +1 -1
- package/fesm2022/rxap-form-system.mjs +810 -343
- package/fesm2022/rxap-form-system.mjs.map +1 -1
- package/index.d.ts +20 -9
- package/lib/control-with-data-source.d.ts +2 -2
- 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/lib/directives/control-hide-show.directive.d.ts +1 -1
- package/lib/directives/form-directives.module.d.ts +8 -0
- package/lib/directives/input-select-options.directive.d.ts +3 -3
- package/lib/directives/options-from-remote-method.directive.d.ts +38 -0
- package/lib/form-context-from-activated-route.factory.d.ts +2 -0
- package/lib/form-system-control.directive.d.ts +2 -2
- package/lib/mixins/extract-control.mixin.d.ts +1 -1
- package/lib/mixins/extract-form-definition.mixin.d.ts +1 -1
- package/lib/mixins/extract-options-data-source.mixin.d.ts +6 -7
- package/lib/submit-context-form-adapter.factory.d.ts +13 -0
- package/lib/validators/is-equal-to.d.ts +1 -1
- package/package.json +83 -56
- package/theme.css +1 -0
- package/collection.json +0 -10
- package/migration.json +0 -4
- package/src/schematics/ng-add/index.d.ts +0 -2
- package/src/schematics/ng-add/index.js +0 -8
- package/src/schematics/ng-add/index.js.map +0 -1
- package/src/schematics/ng-add/schema.json +0 -7
|
@@ -1,60 +1,79 @@
|
|
|
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 {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { 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';
|
|
9
5
|
import { __decorate, __metadata } from 'tslib';
|
|
6
|
+
import * as i1 from '@rxap/data-source';
|
|
7
|
+
import { PipeDataSource, DataSourceLoader, BaseDataSource, RXAP_DATA_SOURCE_METADATA } from '@rxap/data-source';
|
|
10
8
|
import { Mixin } from '@rxap/mixin';
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
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';
|
|
11
|
+
import { setMetadataMapMap, getMetadata, setMetadataMap, setMetadata } from '@rxap/reflect-metadata';
|
|
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';
|
|
14
15
|
import * as i3 from '@angular/material/form-field';
|
|
15
16
|
import { MAT_FORM_FIELD } from '@angular/material/form-field';
|
|
16
17
|
import '@angular/material/autocomplete';
|
|
18
|
+
import * as i2$1 from '@rxap/remote-method';
|
|
19
|
+
import { RemoteMethodLoader, ProxyRemoteMethod } from '@rxap/remote-method';
|
|
17
20
|
|
|
18
|
-
class
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const RXAP_FORM_CONTROL_SOURCE = new InjectionToken('rxap/forms/data-source');
|
|
25
|
-
class ControlDataSource extends BaseDataSource {
|
|
26
|
-
constructor(control, metadata = null) {
|
|
27
|
-
super(metadata);
|
|
28
|
-
this.control = control;
|
|
29
|
-
}
|
|
30
|
-
init() {
|
|
31
|
-
if (this._initialised) {
|
|
32
|
-
return;
|
|
21
|
+
class IsEqualToDirective {
|
|
22
|
+
set equalTo(value) {
|
|
23
|
+
this._equalTo = value;
|
|
24
|
+
if (this._onChange) {
|
|
25
|
+
this._onChange();
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
}
|
|
28
|
+
validate(control) {
|
|
29
|
+
if (this._equalTo === null || this._equalTo === control.value) {
|
|
30
|
+
return null;
|
|
37
31
|
}
|
|
38
|
-
|
|
32
|
+
return {
|
|
33
|
+
isEqualTo: {
|
|
34
|
+
value: this._equalTo,
|
|
35
|
+
actualValue: control.value,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
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 }); }
|
|
57
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
|
+
}] } });
|
|
58
77
|
|
|
59
78
|
var FormSystemMetadataKeys;
|
|
60
79
|
(function (FormSystemMetadataKeys) {
|
|
@@ -64,6 +83,41 @@ var FormSystemMetadataKeys;
|
|
|
64
83
|
FormSystemMetadataKeys["FORM_COMPONENT"] = "rxap/window-form-system/form-component";
|
|
65
84
|
})(FormSystemMetadataKeys || (FormSystemMetadataKeys = {}));
|
|
66
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!');
|
|
102
|
+
}
|
|
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!');
|
|
110
|
+
}
|
|
111
|
+
return this.control = control;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class RxapFormSystemError extends RxapError {
|
|
116
|
+
constructor(message, code, className) {
|
|
117
|
+
super('@rxap/form-system', message, code, className);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
67
121
|
class ExtractDataSourcesMixin {
|
|
68
122
|
extractDataSources(formDefinition, controlId) {
|
|
69
123
|
const map = getMetadata(FormSystemMetadataKeys.DATA_SOURCES, Object.getPrototypeOf(formDefinition));
|
|
@@ -77,25 +131,6 @@ class ExtractDataSourcesMixin {
|
|
|
77
131
|
}
|
|
78
132
|
}
|
|
79
133
|
|
|
80
|
-
class ExtractControlFromParentMixin {
|
|
81
|
-
extractControlFromParent(parent, controlPath) {
|
|
82
|
-
if (!controlPath) {
|
|
83
|
-
throw new RxapFormSystemError('The control path is empty', '');
|
|
84
|
-
}
|
|
85
|
-
if (!parent.control) {
|
|
86
|
-
throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
|
|
87
|
-
}
|
|
88
|
-
const control = parent.control.get(controlPath);
|
|
89
|
-
if (!control) {
|
|
90
|
-
throw new RxapFormSystemError('Could not find the control instance', '');
|
|
91
|
-
}
|
|
92
|
-
if (!(control instanceof RxapFormControl) && !(control instanceof RxapFormGroup) && !(control instanceof RxapFormArray)) {
|
|
93
|
-
throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
|
|
94
|
-
}
|
|
95
|
-
return control;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
134
|
class ExtractFormDefinitionMixin {
|
|
100
135
|
// TODO : change to AbstractControl from @rxap/forms
|
|
101
136
|
extractFormDefinition(control) {
|
|
@@ -107,30 +142,6 @@ class ExtractFormDefinitionMixin {
|
|
|
107
142
|
}
|
|
108
143
|
}
|
|
109
144
|
|
|
110
|
-
function UseDataSource(dataSource, name, settings) {
|
|
111
|
-
return function (target, propertyKey) {
|
|
112
|
-
const value = { dataSource, settings };
|
|
113
|
-
setMetadataMapMap(propertyKey, name, value, FormSystemMetadataKeys.DATA_SOURCES, target);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
class ExtractControlMixin {
|
|
118
|
-
extractControl(ngControl = this.ngControl ?? this.matFormField?._control?.ngControl ?? null) {
|
|
119
|
-
if (!ngControl) {
|
|
120
|
-
throw new Error('The ngControl is not defined!');
|
|
121
|
-
}
|
|
122
|
-
if (!(ngControl instanceof NgControl)) {
|
|
123
|
-
throw new Error('The AbstractControlDirective is not a NgControl!');
|
|
124
|
-
}
|
|
125
|
-
this.ngControl = ngControl;
|
|
126
|
-
const control = this.ngControl.control;
|
|
127
|
-
if (!(control instanceof RxapFormControl)) {
|
|
128
|
-
throw new Error('Control is not a RxapFormControl!');
|
|
129
|
-
}
|
|
130
|
-
return this.control = control;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
145
|
const DATA_SOURCE_NAME = 'options';
|
|
135
146
|
function ComposeOptionsTransformers(...fnc) {
|
|
136
147
|
return base => fnc.reduce((source, transform) => transform(source), base);
|
|
@@ -179,166 +190,385 @@ ExtractOptionsDataSourceMixin = __decorate([
|
|
|
179
190
|
Mixin(ExtractControlMixin, ExtractFormDefinitionMixin, ExtractDataSourcesMixin)
|
|
180
191
|
], ExtractOptionsDataSourceMixin);
|
|
181
192
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.viewContainerRef = viewContainerRef;
|
|
193
|
+
var IsSelectableValueDirective_1;
|
|
194
|
+
let IsSelectableValueDirective = class IsSelectableValueDirective {
|
|
195
|
+
static { IsSelectableValueDirective_1 = this; }
|
|
196
|
+
constructor(dataSourceLoader, injector) {
|
|
187
197
|
this.dataSourceLoader = dataSourceLoader;
|
|
188
198
|
this.injector = injector;
|
|
199
|
+
this.viewer = { id: '[rxapIsSelectableValue]' };
|
|
189
200
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const useDataSourceValueMap = this.extractDataSources(formDefinition, this.controlId);
|
|
217
|
-
for (const [name, useDataSourceValue] of useDataSourceValueMap.entries()) {
|
|
218
|
-
let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource);
|
|
219
|
-
const settings = useDataSourceValue.settings;
|
|
220
|
-
if (settings?.transformer) {
|
|
221
|
-
dataSource = new PipeDataSource(dataSource, map(settings.transformer));
|
|
201
|
+
validate(control) {
|
|
202
|
+
if (control.value) {
|
|
203
|
+
this.extractOptionsDatasource(control);
|
|
204
|
+
const data = this.useDataSourceValue?.lastValue;
|
|
205
|
+
if (data) {
|
|
206
|
+
let options;
|
|
207
|
+
if (Array.isArray(data)) {
|
|
208
|
+
options = data;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
options = Object.entries(data)
|
|
212
|
+
.map(([value, display]) => ({
|
|
213
|
+
value,
|
|
214
|
+
display,
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
if (!options.some(option => option.value === control.value)) {
|
|
218
|
+
return {
|
|
219
|
+
isSelectableValue: {
|
|
220
|
+
expected: 'Value should be from the list of provided options',
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else if (isDevMode()) {
|
|
226
|
+
console.warn('The last value from the OptionsDataSource is empty', this);
|
|
222
227
|
}
|
|
223
|
-
component.setDataSource(name, dataSource, useDataSourceValue.settings);
|
|
224
228
|
}
|
|
229
|
+
return null;
|
|
225
230
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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: [{
|
|
246
|
+
type: Directive,
|
|
247
|
+
args: [{
|
|
248
|
+
selector: '[rxapIsSelectableValue]',
|
|
249
|
+
providers: [
|
|
250
|
+
{
|
|
251
|
+
provide: NG_VALIDATORS,
|
|
252
|
+
multi: true,
|
|
253
|
+
useExisting: forwardRef(() => IsSelectableValueDirective),
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
standalone: true,
|
|
257
|
+
}]
|
|
258
|
+
}], ctorParameters: function () { return [{ type: i1.DataSourceLoader, decorators: [{
|
|
259
|
+
type: Inject,
|
|
260
|
+
args: [DataSourceLoader]
|
|
261
|
+
}] }, { type: i0.Injector, decorators: [{
|
|
262
|
+
type: Inject,
|
|
263
|
+
args: [INJECTOR]
|
|
264
|
+
}] }]; }, propDecorators: { viewer: [{
|
|
265
|
+
type: Input
|
|
266
|
+
}] } });
|
|
267
|
+
|
|
268
|
+
class ExtractControlFromParentMixin {
|
|
269
|
+
extractControlFromParent(parent, controlPath) {
|
|
270
|
+
if (!controlPath) {
|
|
271
|
+
throw new RxapFormSystemError('The control path is empty', '');
|
|
230
272
|
}
|
|
231
|
-
|
|
232
|
-
createComponent(formDefinition) {
|
|
233
|
-
const component = this.extractComponent(formDefinition);
|
|
234
|
-
const componentFactory = this.cfr.resolveComponentFactory(component);
|
|
235
|
-
return componentFactory.create(this.injector);
|
|
236
|
-
}
|
|
237
|
-
extractControl() {
|
|
238
|
-
if (!this.parent.control) {
|
|
273
|
+
if (!parent.control) {
|
|
239
274
|
throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
|
|
240
275
|
}
|
|
241
|
-
const control =
|
|
276
|
+
const control = parent.control.get(controlPath);
|
|
242
277
|
if (!control) {
|
|
243
278
|
throw new RxapFormSystemError('Could not find the control instance', '');
|
|
244
279
|
}
|
|
245
|
-
if (!(control instanceof RxapFormControl)
|
|
280
|
+
if (!(control instanceof RxapFormControl) &&
|
|
281
|
+
!(control instanceof RxapFormGroup) &&
|
|
282
|
+
!(control instanceof RxapFormArray)) {
|
|
246
283
|
throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
|
|
247
284
|
}
|
|
248
285
|
return control;
|
|
249
286
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// TODO : move to rxap packages
|
|
290
|
+
class ForFormArrayItemsDirective {
|
|
291
|
+
constructor(container, template, viewContainerRef, cdr) {
|
|
292
|
+
this.container = container;
|
|
293
|
+
this.template = template;
|
|
294
|
+
this.viewContainerRef = viewContainerRef;
|
|
295
|
+
this.cdr = cdr;
|
|
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();
|
|
261
305
|
}
|
|
262
|
-
|
|
263
|
-
throw new
|
|
306
|
+
else {
|
|
307
|
+
throw new Error('The control container is not an instance of RxapFormArray');
|
|
264
308
|
}
|
|
265
|
-
return map.get(this.controlId);
|
|
266
309
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
+
}
|
|
271
331
|
}
|
|
272
|
-
|
|
273
|
-
|
|
332
|
+
this.cdr.detectChanges();
|
|
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 }); }
|
|
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 }]; } });
|
|
346
|
+
|
|
347
|
+
// TODO : move to rxap packages
|
|
348
|
+
class FormArrayAddItemButtonDirective {
|
|
349
|
+
constructor(parent, matButton) {
|
|
350
|
+
this.parent = parent;
|
|
351
|
+
this.matButton = matButton;
|
|
352
|
+
this.type = 'button';
|
|
353
|
+
}
|
|
354
|
+
get disabled() {
|
|
355
|
+
return this.isDisabled;
|
|
356
|
+
}
|
|
357
|
+
get isDisabled() {
|
|
358
|
+
return !!this.formArray?.disabled;
|
|
359
|
+
}
|
|
360
|
+
ngAfterViewInit() {
|
|
361
|
+
if (this.parent.control instanceof RxapFormArray) {
|
|
362
|
+
this.formArray = this.parent.control;
|
|
363
|
+
}
|
|
364
|
+
if (this.matButton) {
|
|
365
|
+
this._controlDisabledSubscription = this.formArray.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
|
|
274
366
|
}
|
|
275
|
-
return map.get(this.controlId);
|
|
276
367
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
], FormSystemControlDirective.prototype, "control", void 0);
|
|
288
|
-
__decorate([
|
|
289
|
-
Required,
|
|
290
|
-
__metadata("design:type", ComponentRef)
|
|
291
|
-
], FormSystemControlDirective.prototype, "componentRef", void 0);
|
|
292
|
-
FormSystemControlDirective = __decorate([
|
|
293
|
-
Mixin(ExtractDataSourcesMixin),
|
|
294
|
-
__metadata("design:paramtypes", [ControlContainer,
|
|
295
|
-
ComponentFactoryResolver,
|
|
296
|
-
ViewContainerRef,
|
|
297
|
-
DataSourceLoader,
|
|
298
|
-
Injector])
|
|
299
|
-
], FormSystemControlDirective);
|
|
300
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.2", ngImport: i0, type: FormSystemControlDirective, decorators: [{
|
|
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: [{
|
|
301
378
|
type: Directive,
|
|
302
379
|
args: [{
|
|
303
|
-
selector: '[
|
|
304
|
-
standalone: true
|
|
380
|
+
selector: '[rxapFormArrayItemAddButton]',
|
|
381
|
+
standalone: true,
|
|
305
382
|
}]
|
|
306
|
-
}], ctorParameters: function () { return [{ type: i1.ControlContainer, decorators: [{
|
|
307
|
-
type:
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}] }, { type:
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
type: Input
|
|
323
|
-
}], control: [], componentRef: [] } });
|
|
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
|
+
}] } });
|
|
324
399
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
400
|
+
// TODO : move to rxap packages
|
|
401
|
+
class FormArrayItemButton {
|
|
402
|
+
constructor(parent, matButton, renderer, elementRef) {
|
|
403
|
+
this.parent = parent;
|
|
404
|
+
this.matButton = matButton;
|
|
405
|
+
this.renderer = renderer;
|
|
406
|
+
this.elementRef = elementRef;
|
|
407
|
+
this.type = 'button';
|
|
408
|
+
}
|
|
409
|
+
get disabled() {
|
|
410
|
+
return this.isDisabled;
|
|
411
|
+
}
|
|
412
|
+
get isDeleted() {
|
|
413
|
+
return this.deletedControl.value;
|
|
414
|
+
}
|
|
415
|
+
get index() {
|
|
416
|
+
return this.formGroup.parent.controls.findIndex(control => control === this.formGroup);
|
|
417
|
+
}
|
|
418
|
+
get isDisabled() {
|
|
419
|
+
return !!this.formGroup?.parent?.disabled;
|
|
420
|
+
}
|
|
421
|
+
ngAfterViewInit() {
|
|
422
|
+
if (this.parent.control instanceof RxapFormGroup) {
|
|
423
|
+
this.formGroup = this.parent.control;
|
|
424
|
+
if (this.formGroup.controls.deleted instanceof RxapFormControl) {
|
|
425
|
+
this.deletedControl = this.formGroup.controls.deleted;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
throw new Error(`The parent FormGroup instance does not have a 'deleted' control`);
|
|
429
|
+
}
|
|
430
|
+
if (!(this.formGroup.parent instanceof UntypedFormArray)) {
|
|
431
|
+
throw new Error(`The parent of the FormGroup is not a FormArray instance`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
throw new Error(`The parent is not a form group instance`);
|
|
436
|
+
}
|
|
437
|
+
if (this.matButton) {
|
|
438
|
+
this._controlDisabledSubscription = this.formGroup.disabled$.pipe(tap$1(isDisabled => this.matButton.disabled = isDisabled)).subscribe();
|
|
439
|
+
}
|
|
440
|
+
this.deletedControl.value$.pipe(tap$1(() => this.updateDisplayStyle())).subscribe();
|
|
441
|
+
}
|
|
442
|
+
ngOnDestroy() {
|
|
443
|
+
this._controlDisabledSubscription?.unsubscribe();
|
|
444
|
+
this._deletedControlValueSubscription?.unsubscribe();
|
|
445
|
+
}
|
|
446
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.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 }); }
|
|
330
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
|
+
}] } });
|
|
331
462
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
463
|
+
// TODO : move to rxap packages
|
|
464
|
+
class FormArrayItemRemoveButtonDirective extends FormArrayItemButton {
|
|
465
|
+
onClick() {
|
|
466
|
+
this.deletedControl.setValue(true);
|
|
467
|
+
}
|
|
468
|
+
updateDisplayStyle() {
|
|
469
|
+
if (this.isDeleted) {
|
|
470
|
+
this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.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 }); }
|
|
341
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);
|
|
494
|
+
}
|
|
495
|
+
updateDisplayStyle() {
|
|
496
|
+
if (this.isDeleted) {
|
|
497
|
+
this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
504
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: FormArrayItemRestoreButtonDirective, isStandalone: true, selector: "button[rxapFormArrayItemRestoreButton]", host: { listeners: { "click": "onClick()" } }, usesInheritance: true, ngImport: i0 }); }
|
|
505
|
+
}
|
|
506
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormArrayItemRestoreButtonDirective, decorators: [{
|
|
507
|
+
type: Directive,
|
|
508
|
+
args: [{
|
|
509
|
+
selector: 'button[rxapFormArrayItemRestoreButton]',
|
|
510
|
+
standalone: true,
|
|
511
|
+
}]
|
|
512
|
+
}], propDecorators: { onClick: [{
|
|
513
|
+
type: HostListener,
|
|
514
|
+
args: ['click']
|
|
515
|
+
}] } });
|
|
516
|
+
|
|
517
|
+
// TODO : move to rxap packages
|
|
518
|
+
class FormArrayRemovableDirective {
|
|
519
|
+
constructor(parent) {
|
|
520
|
+
this.parent = parent;
|
|
521
|
+
}
|
|
522
|
+
get isDeleted() {
|
|
523
|
+
return this.deletedControl.value;
|
|
524
|
+
}
|
|
525
|
+
get isDisabled() {
|
|
526
|
+
return !!this.control?.parent?.disabled;
|
|
527
|
+
}
|
|
528
|
+
ngAfterViewInit() {
|
|
529
|
+
if (this.parent.control instanceof RxapFormGroup) {
|
|
530
|
+
this.control = this.parent.control;
|
|
531
|
+
if (this.control.controls.deleted instanceof RxapFormControl) {
|
|
532
|
+
this.deletedControl = this.control.controls.deleted;
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
throw new Error(`The parent FormGroup instance does not have a 'deleted' control`);
|
|
536
|
+
}
|
|
537
|
+
if (!(this.control.parent instanceof UntypedFormArray)) {
|
|
538
|
+
throw new Error(`The parent of the FormGroup is not a FormArray instance`);
|
|
539
|
+
}
|
|
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 }); }
|
|
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
|
+
}] }]; } });
|
|
342
572
|
|
|
343
573
|
const RXAP_FORM_SYSTEM_SHOW_METADATA = 'rxap/form-system/show-function';
|
|
344
574
|
const RXAP_FORM_SYSTEM_HIDE_METADATA = 'rxap/form-system/hide-function';
|
|
@@ -387,7 +617,7 @@ let ControlHideShowDirective = class ControlHideShowDirective {
|
|
|
387
617
|
if (options.rootChange) {
|
|
388
618
|
changeTrigger = formDefinition.rxapFormGroup.root.valueChanges;
|
|
389
619
|
}
|
|
390
|
-
changeTrigger = changeTrigger.pipe(startWith(null));
|
|
620
|
+
changeTrigger = changeTrigger.pipe(startWith$1(null));
|
|
391
621
|
if (showFunction) {
|
|
392
622
|
this.subscription.add(changeTrigger.pipe(tap(() => {
|
|
393
623
|
// TODO : resubscribe if the showFunction throws an error
|
|
@@ -462,19 +692,19 @@ let ControlHideShowDirective = class ControlHideShowDirective {
|
|
|
462
692
|
reset() {
|
|
463
693
|
this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
|
|
464
694
|
}
|
|
465
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
466
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.
|
|
695
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlHideShowDirective, deps: [{ token: Renderer2 }, { token: ElementRef }, { token: ControlContainer, optional: true }, { token: NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
696
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: ControlHideShowDirective, isStandalone: true, selector: "[rxapControlHideShow]", inputs: { controlId: ["rxapControlHideShow", "controlId"] }, ngImport: i0 }); }
|
|
467
697
|
};
|
|
468
698
|
ControlHideShowDirective = __decorate([
|
|
469
699
|
Mixin(ExtractControlFromParentMixin, ExtractFormDefinitionMixin),
|
|
470
700
|
__metadata("design:paramtypes", [Renderer2,
|
|
471
701
|
ElementRef, Object, Object])
|
|
472
702
|
], ControlHideShowDirective);
|
|
473
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
703
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ControlHideShowDirective, decorators: [{
|
|
474
704
|
type: Directive,
|
|
475
705
|
args: [{
|
|
476
706
|
selector: '[rxapControlHideShow]',
|
|
477
|
-
standalone: true
|
|
707
|
+
standalone: true,
|
|
478
708
|
}]
|
|
479
709
|
}], ctorParameters: function () { return [{ type: i0.Renderer2, decorators: [{
|
|
480
710
|
type: Inject,
|
|
@@ -482,12 +712,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.2", ngImpor
|
|
|
482
712
|
}] }, { type: i0.ElementRef, decorators: [{
|
|
483
713
|
type: Inject,
|
|
484
714
|
args: [ElementRef]
|
|
485
|
-
}] }, { type: i1.ControlContainer, decorators: [{
|
|
715
|
+
}] }, { type: i1$1.ControlContainer, decorators: [{
|
|
486
716
|
type: Optional
|
|
487
717
|
}, {
|
|
488
718
|
type: Inject,
|
|
489
719
|
args: [ControlContainer]
|
|
490
|
-
}] }, { type: i1.NgControl, decorators: [{
|
|
720
|
+
}] }, { type: i1$1.NgControl, decorators: [{
|
|
491
721
|
type: Self
|
|
492
722
|
}, {
|
|
493
723
|
type: Optional
|
|
@@ -527,7 +757,7 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
|
|
|
527
757
|
this.extractOptionsDatasource();
|
|
528
758
|
this.viewer = {
|
|
529
759
|
id: '[rxapInputSelectOptions]' + this.control.controlId,
|
|
530
|
-
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 => {
|
|
531
761
|
if (this.settings?.ignoreSelectedValue) {
|
|
532
762
|
return {};
|
|
533
763
|
}
|
|
@@ -546,7 +776,8 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
|
|
|
546
776
|
if (!value) {
|
|
547
777
|
return '';
|
|
548
778
|
}
|
|
549
|
-
return this.options?.find((option) => option.value === value)?.display ??
|
|
779
|
+
return this.options?.find((option) => option.value === value)?.display ??
|
|
780
|
+
(isDevMode() ? 'to display error' : '');
|
|
550
781
|
}
|
|
551
782
|
ngOnDestroy() {
|
|
552
783
|
this.subscription?.unsubscribe();
|
|
@@ -562,8 +793,13 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
|
|
|
562
793
|
}
|
|
563
794
|
else {
|
|
564
795
|
return Object.entries(options)
|
|
565
|
-
.filter(([value, display]) => typeof display ===
|
|
566
|
-
|
|
796
|
+
.filter(([value, display]) => typeof display ===
|
|
797
|
+
'string' &&
|
|
798
|
+
display.toLowerCase().includes(controlValue))
|
|
799
|
+
.map(([value, display]) => ({
|
|
800
|
+
value,
|
|
801
|
+
display,
|
|
802
|
+
}));
|
|
567
803
|
}
|
|
568
804
|
}
|
|
569
805
|
return options;
|
|
@@ -584,7 +820,12 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
|
|
|
584
820
|
if (options) {
|
|
585
821
|
if (!Array.isArray(options)) {
|
|
586
822
|
for (const [value, display] of Object.entries(options)) {
|
|
587
|
-
this.viewContainerRef.createEmbeddedView(this.template, {
|
|
823
|
+
this.viewContainerRef.createEmbeddedView(this.template, {
|
|
824
|
+
$implicit: {
|
|
825
|
+
value,
|
|
826
|
+
display,
|
|
827
|
+
},
|
|
828
|
+
});
|
|
588
829
|
}
|
|
589
830
|
}
|
|
590
831
|
else {
|
|
@@ -600,17 +841,9 @@ let InputSelectOptionsDirective = class InputSelectOptionsDirective {
|
|
|
600
841
|
}
|
|
601
842
|
this.cdr.detectChanges();
|
|
602
843
|
}
|
|
603
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
604
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.
|
|
844
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: InputSelectOptionsDirective, deps: [{ token: TemplateRef }, { token: DataSourceLoader }, { token: ViewContainerRef }, { token: INJECTOR }, { token: ChangeDetectorRef }, { token: NgControl, optional: true }, { token: MAT_FORM_FIELD, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
845
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: InputSelectOptionsDirective, isStandalone: true, selector: "[rxapInputSelectOptions]", inputs: { viewer: ["rxapInputSelectOptionsViewer", "viewer"], metadata: ["rxapInputSelectOptionsMetadata", "metadata"], matAutocomplete: ["rxapInputSelectOptionsMatAutocomplete", "matAutocomplete"] }, ngImport: i0 }); }
|
|
605
846
|
};
|
|
606
|
-
__decorate([
|
|
607
|
-
Required,
|
|
608
|
-
__metadata("design:type", RxapFormControl)
|
|
609
|
-
], InputSelectOptionsDirective.prototype, "control", void 0);
|
|
610
|
-
__decorate([
|
|
611
|
-
Required,
|
|
612
|
-
__metadata("design:type", BaseDataSource)
|
|
613
|
-
], InputSelectOptionsDirective.prototype, "dataSource", void 0);
|
|
614
847
|
InputSelectOptionsDirective = __decorate([
|
|
615
848
|
Mixin(ExtractOptionsDataSourceMixin),
|
|
616
849
|
__metadata("design:paramtypes", [TemplateRef,
|
|
@@ -619,16 +852,16 @@ InputSelectOptionsDirective = __decorate([
|
|
|
619
852
|
Injector,
|
|
620
853
|
ChangeDetectorRef, Object, Object])
|
|
621
854
|
], InputSelectOptionsDirective);
|
|
622
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
855
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: InputSelectOptionsDirective, decorators: [{
|
|
623
856
|
type: Directive,
|
|
624
857
|
args: [{
|
|
625
858
|
selector: '[rxapInputSelectOptions]',
|
|
626
|
-
standalone: true
|
|
859
|
+
standalone: true,
|
|
627
860
|
}]
|
|
628
861
|
}], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
|
|
629
862
|
type: Inject,
|
|
630
863
|
args: [TemplateRef]
|
|
631
|
-
}] }, { type: i1
|
|
864
|
+
}] }, { type: i1.DataSourceLoader, decorators: [{
|
|
632
865
|
type: Inject,
|
|
633
866
|
args: [DataSourceLoader]
|
|
634
867
|
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
@@ -640,7 +873,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.2", ngImpor
|
|
|
640
873
|
}] }, { type: i0.ChangeDetectorRef, decorators: [{
|
|
641
874
|
type: Inject,
|
|
642
875
|
args: [ChangeDetectorRef]
|
|
643
|
-
}] }, { type: i1.NgControl, decorators: [{
|
|
876
|
+
}] }, { type: i1$1.NgControl, decorators: [{
|
|
644
877
|
type: Optional
|
|
645
878
|
}, {
|
|
646
879
|
type: Inject,
|
|
@@ -659,137 +892,371 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.2", ngImpor
|
|
|
659
892
|
}], matAutocomplete: [{
|
|
660
893
|
type: Input,
|
|
661
894
|
args: ['rxapInputSelectOptionsMatAutocomplete']
|
|
662
|
-
}]
|
|
895
|
+
}] } });
|
|
663
896
|
|
|
664
|
-
class
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
897
|
+
class FormSystemDirectivesModule {
|
|
898
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
899
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, imports: [InputSelectOptionsDirective,
|
|
900
|
+
ControlHideShowDirective], exports: [InputSelectOptionsDirective,
|
|
901
|
+
ControlHideShowDirective] }); }
|
|
902
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule }); }
|
|
903
|
+
}
|
|
904
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemDirectivesModule, decorators: [{
|
|
905
|
+
type: NgModule,
|
|
906
|
+
args: [{
|
|
907
|
+
exports: [
|
|
908
|
+
InputSelectOptionsDirective,
|
|
909
|
+
ControlHideShowDirective,
|
|
910
|
+
],
|
|
911
|
+
imports: [
|
|
912
|
+
InputSelectOptionsDirective,
|
|
913
|
+
ControlHideShowDirective,
|
|
914
|
+
],
|
|
915
|
+
}]
|
|
916
|
+
}] });
|
|
917
|
+
|
|
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', '');
|
|
669
935
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
if (this._equalTo === null || this._equalTo === control.value) {
|
|
673
|
-
return null;
|
|
936
|
+
if (!map.has(controlId)) {
|
|
937
|
+
throw new RxapFormSystemError('A use remote method definition does not exists in the form definition metadata', '');
|
|
674
938
|
}
|
|
675
|
-
return
|
|
939
|
+
return map.get(controlId);
|
|
676
940
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
this.
|
|
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;
|
|
685
951
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
useExisting: forwardRef(() => IsEqualToDirective)
|
|
952
|
+
ngOnChanges(changes) {
|
|
953
|
+
const parametersChanges = changes['parameters'];
|
|
954
|
+
if (parametersChanges) {
|
|
955
|
+
if (!this.remoteMethodToken) {
|
|
956
|
+
this.remoteMethodToken = this.extractRemoteMethodToken();
|
|
692
957
|
}
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
958
|
+
this.renderTemplate(parametersChanges.currentValue);
|
|
959
|
+
}
|
|
960
|
+
if (changes['withoutParameters']?.currentValue) {
|
|
961
|
+
if (!this.remoteMethodToken) {
|
|
962
|
+
this.remoteMethodToken = this.extractRemoteMethodToken();
|
|
963
|
+
}
|
|
964
|
+
this.renderTemplate();
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
extractRemoteMethodToken() {
|
|
968
|
+
const control = this.ngControl.control;
|
|
969
|
+
if (!(control instanceof RxapFormControl)) {
|
|
970
|
+
throw new Error('Control is not a RxapFormControl!');
|
|
971
|
+
}
|
|
972
|
+
const formDefinition = this.extractFormDefinition(control);
|
|
973
|
+
const remoteMethodsTokens = this.extractRemoteMethods(formDefinition, control.controlId);
|
|
974
|
+
if (!remoteMethodsTokens.has(REMOTE_METHOD_NAME)) {
|
|
975
|
+
throw new Error(`The remote method with the name 'options' is not defined`);
|
|
976
|
+
}
|
|
977
|
+
return remoteMethodsTokens.get(REMOTE_METHOD_NAME);
|
|
978
|
+
}
|
|
979
|
+
async renderTemplate(parameters) {
|
|
980
|
+
const options = await this.remoteMethodLoader.call$(this.remoteMethodToken, parameters, undefined, this.injector);
|
|
981
|
+
this.viewContainerRef.clear();
|
|
982
|
+
for (const option of options) {
|
|
983
|
+
this.viewContainerRef.createEmbeddedView(this.template, { $implicit: option });
|
|
984
|
+
}
|
|
985
|
+
if (this.resetOnChange !== undefined) {
|
|
986
|
+
this.ngControl.reset(this.resetOnChange);
|
|
987
|
+
}
|
|
988
|
+
this.cdr.detectChanges();
|
|
989
|
+
}
|
|
990
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, deps: [{ token: NgControl }, { token: TemplateRef }, { token: RemoteMethodLoader }, { token: ViewContainerRef }, { token: INJECTOR }, { token: ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
991
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: OptionsFromRemoteMethodDirective, isStandalone: true, selector: "[rxapOptionsFromRemoteMethod]", inputs: { parameters: ["rxapOptionsFromRemoteMethodParameters", "parameters"], resetOnChange: ["rxapOptionsFromRemoteMethodResetOnChange", "resetOnChange"], withoutParameters: ["rxapOptionsFromRemoteMethodWithoutParameters", "withoutParameters"] }, usesOnChanges: true, ngImport: i0 }); }
|
|
992
|
+
};
|
|
993
|
+
OptionsFromRemoteMethodDirective = __decorate([
|
|
994
|
+
Mixin(ExtractFormDefinitionMixin, ExtractRemoteMethodsMixin),
|
|
995
|
+
__metadata("design:paramtypes", [NgControl,
|
|
996
|
+
TemplateRef,
|
|
997
|
+
RemoteMethodLoader,
|
|
998
|
+
ViewContainerRef,
|
|
999
|
+
Injector,
|
|
1000
|
+
ChangeDetectorRef])
|
|
1001
|
+
], OptionsFromRemoteMethodDirective);
|
|
1002
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OptionsFromRemoteMethodDirective, decorators: [{
|
|
701
1003
|
type: Directive,
|
|
702
1004
|
args: [{
|
|
703
|
-
selector: '[
|
|
704
|
-
|
|
705
|
-
{
|
|
706
|
-
provide: NG_VALIDATORS,
|
|
707
|
-
multi: true,
|
|
708
|
-
useExisting: forwardRef(() => IsEqualToDirective)
|
|
709
|
-
}
|
|
710
|
-
],
|
|
711
|
-
standalone: true
|
|
1005
|
+
selector: '[rxapOptionsFromRemoteMethod]',
|
|
1006
|
+
standalone: true,
|
|
712
1007
|
}]
|
|
713
|
-
}],
|
|
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: [{
|
|
714
1027
|
type: Input,
|
|
715
|
-
args: ['
|
|
1028
|
+
args: ['rxapOptionsFromRemoteMethodParameters']
|
|
1029
|
+
}], resetOnChange: [{
|
|
1030
|
+
type: Input,
|
|
1031
|
+
args: ['rxapOptionsFromRemoteMethodResetOnChange']
|
|
1032
|
+
}], withoutParameters: [{
|
|
1033
|
+
type: Input,
|
|
1034
|
+
args: ['rxapOptionsFromRemoteMethodWithoutParameters']
|
|
716
1035
|
}] } });
|
|
717
1036
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
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;
|
|
721
1099
|
this.dataSourceLoader = dataSourceLoader;
|
|
722
1100
|
this.injector = injector;
|
|
723
|
-
this.viewer = { id: '[rxapIsSelectableValue]' };
|
|
724
1101
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
else if (isDevMode()) {
|
|
746
|
-
console.warn('The last value from the OptionsDataSource is empty', this);
|
|
747
|
-
}
|
|
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);
|
|
748
1122
|
}
|
|
749
|
-
return null;
|
|
750
1123
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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));
|
|
757
1134
|
}
|
|
758
|
-
|
|
1135
|
+
component.setDataSource(name, dataSource, useDataSourceValue.settings);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
setComponentProperties(formDefinition, component) {
|
|
1139
|
+
const componentProperties = this.extractComponentProperties(formDefinition);
|
|
1140
|
+
for (const [key, value] of Object.entries(componentProperties)) {
|
|
1141
|
+
Reflect.set(component, key, value);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
createComponent(formDefinition) {
|
|
1145
|
+
const component = this.extractComponent(formDefinition);
|
|
1146
|
+
const componentFactory = this.cfr.resolveComponentFactory(component);
|
|
1147
|
+
return componentFactory.create(this.injector);
|
|
1148
|
+
}
|
|
1149
|
+
extractControl() {
|
|
1150
|
+
if (!this.parent.control) {
|
|
1151
|
+
throw new RxapFormSystemError('The control property of ControlContainer is not defined', '');
|
|
1152
|
+
}
|
|
1153
|
+
const control = this.parent.control.get(this.controlId);
|
|
1154
|
+
if (!control) {
|
|
1155
|
+
throw new RxapFormSystemError('Could not find the control instance', '');
|
|
1156
|
+
}
|
|
1157
|
+
if (!(control instanceof RxapFormControl)) {
|
|
1158
|
+
throw new RxapFormSystemError('The extracted control is not a RxapFormControl', '');
|
|
1159
|
+
}
|
|
1160
|
+
return control;
|
|
1161
|
+
}
|
|
1162
|
+
extractFormDefinition() {
|
|
1163
|
+
const formDefinition = this.control.rxapFormDefinition;
|
|
1164
|
+
if (!formDefinition) {
|
|
1165
|
+
throw new RxapFormSystemError('Could not find the form definition instance', '');
|
|
1166
|
+
}
|
|
1167
|
+
return formDefinition;
|
|
1168
|
+
}
|
|
1169
|
+
extractComponent(formDefinition) {
|
|
1170
|
+
const map = getMetadata(FormSystemMetadataKeys.COMPONENTS, Object.getPrototypeOf(formDefinition));
|
|
1171
|
+
if (!map) {
|
|
1172
|
+
throw new RxapFormSystemError('Could not extract the use component map from the form definition instance', '');
|
|
1173
|
+
}
|
|
1174
|
+
if (!map.has(this.controlId)) {
|
|
1175
|
+
throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
|
|
1176
|
+
}
|
|
1177
|
+
return map.get(this.controlId);
|
|
1178
|
+
}
|
|
1179
|
+
extractComponentProperties(formDefinition) {
|
|
1180
|
+
const map = getMetadata(FormSystemMetadataKeys.COMPONENTS_PROPERTIES, Object.getPrototypeOf(formDefinition));
|
|
1181
|
+
if (!map) {
|
|
1182
|
+
throw new RxapFormSystemError('Could not extract the use component properties map from the form definition instance', '');
|
|
1183
|
+
}
|
|
1184
|
+
if (!map.has(this.controlId)) {
|
|
1185
|
+
throw new RxapFormSystemError('A use component definition does not exists in the form definition metadata', '');
|
|
1186
|
+
}
|
|
1187
|
+
return map.get(this.controlId);
|
|
1188
|
+
}
|
|
1189
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, deps: [{ token: ControlContainer }, { token: ComponentFactoryResolver }, { token: ViewContainerRef }, { token: DataSourceLoader }, { token: INJECTOR }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1190
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.4", type: FormSystemControlDirective, isStandalone: true, selector: "[rxapFormSystemControl]", inputs: { controlId: "controlId" }, ngImport: i0 }); }
|
|
759
1191
|
};
|
|
760
|
-
|
|
761
|
-
Mixin(
|
|
762
|
-
__metadata("design:paramtypes", [
|
|
1192
|
+
FormSystemControlDirective = __decorate([
|
|
1193
|
+
Mixin(ExtractDataSourcesMixin),
|
|
1194
|
+
__metadata("design:paramtypes", [ControlContainer,
|
|
1195
|
+
ComponentFactoryResolver,
|
|
1196
|
+
ViewContainerRef,
|
|
1197
|
+
DataSourceLoader,
|
|
763
1198
|
Injector])
|
|
764
|
-
],
|
|
765
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
1199
|
+
], FormSystemControlDirective);
|
|
1200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: FormSystemControlDirective, decorators: [{
|
|
766
1201
|
type: Directive,
|
|
767
1202
|
args: [{
|
|
768
|
-
selector: '[
|
|
769
|
-
|
|
770
|
-
{
|
|
771
|
-
provide: NG_VALIDATORS,
|
|
772
|
-
multi: true,
|
|
773
|
-
useExisting: forwardRef(() => IsSelectableValueDirective)
|
|
774
|
-
}
|
|
775
|
-
],
|
|
776
|
-
standalone: true
|
|
1203
|
+
selector: '[rxapFormSystemControl]',
|
|
1204
|
+
standalone: true,
|
|
777
1205
|
}]
|
|
778
|
-
}], 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: [{
|
|
779
1216
|
type: Inject,
|
|
780
1217
|
args: [DataSourceLoader]
|
|
781
1218
|
}] }, { type: i0.Injector, decorators: [{
|
|
782
1219
|
type: Inject,
|
|
783
1220
|
args: [INJECTOR]
|
|
784
|
-
}] }]; }, propDecorators: {
|
|
785
|
-
type: Input
|
|
1221
|
+
}] }]; }, propDecorators: { controlId: [{
|
|
1222
|
+
type: Input,
|
|
1223
|
+
args: [{ required: true }]
|
|
786
1224
|
}] } });
|
|
787
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
|
|
788
1255
|
// endregion
|
|
789
1256
|
|
|
790
1257
|
/**
|
|
791
1258
|
* Generated bundle index. Do not edit.
|
|
792
1259
|
*/
|
|
793
1260
|
|
|
794
|
-
export { ComposeOptionsTransformers, ControlDataSource, ControlHideShowDirective, DATA_SOURCE_NAME, ExtractControlFromParentMixin, ExtractControlMixin, ExtractDataSourcesMixin, ExtractFormDefinitionMixin, ExtractOptionsDataSourceMixin, FormSystemControlDirective, FormSystemMetadataKeys, InputSelectOptionsDirective, IsEqualToDirective, IsSelectableValueDirective, RXAP_FORM_CONTROL_SOURCE, RXAP_FORM_SYSTEM_HIDE_METADATA, RXAP_FORM_SYSTEM_HIDE_SHOW_OPTIONS, RXAP_FORM_SYSTEM_SHOW_METADATA, RxapFormSystemError, UseComponent, UseDataSource, UseFormComponent, UseHideFunction, UseOptionsDataSource, UseShowFunction, controlDataSource };
|
|
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 };
|
|
795
1262
|
//# sourceMappingURL=rxap-form-system.mjs.map
|