@rxap/forms 12.7.3 → 13.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/esm2020/index.mjs +53 -0
  2. package/esm2020/lib/control-actions.mjs +77 -0
  3. package/esm2020/lib/control-value-accessor.mjs +14 -0
  4. package/esm2020/lib/decorators/control-async-validator.mjs +10 -0
  5. package/esm2020/lib/decorators/control-change.mjs +10 -0
  6. package/esm2020/lib/decorators/control-set-value.mjs +11 -0
  7. package/esm2020/lib/decorators/control-validator.mjs +10 -0
  8. package/esm2020/lib/decorators/form.mjs +7 -0
  9. package/esm2020/lib/decorators/metadata-keys.mjs +12 -0
  10. package/esm2020/lib/decorators/use-form-array.mjs +13 -0
  11. package/esm2020/lib/decorators/use-form-control.mjs +8 -0
  12. package/esm2020/lib/decorators/use-form-group.mjs +8 -0
  13. package/esm2020/lib/directives/form-control-error.directive.mjs +59 -0
  14. package/esm2020/lib/directives/form-control-mark-dirty.directive.mjs +31 -0
  15. package/esm2020/lib/directives/form-control-mark-pristine.directive.mjs +31 -0
  16. package/esm2020/lib/directives/form-control-mark-touched.directive.mjs +24 -0
  17. package/esm2020/lib/directives/form-control-mark-untouched.directive.mjs +31 -0
  18. package/esm2020/lib/directives/form-control-name.directive.mjs +64 -0
  19. package/esm2020/lib/directives/form-group-name.directive.mjs +61 -0
  20. package/esm2020/lib/directives/form-loaded.directive.mjs +41 -0
  21. package/esm2020/lib/directives/form-loading-error.directive.mjs +41 -0
  22. package/esm2020/lib/directives/form-loading.directive.mjs +41 -0
  23. package/esm2020/lib/directives/form-submit-failed.directive.mjs +41 -0
  24. package/esm2020/lib/directives/form-submit-invalid.directive.mjs +39 -0
  25. package/esm2020/lib/directives/form-submit-successful.directive.mjs +39 -0
  26. package/esm2020/lib/directives/form-submit.directive.mjs +74 -0
  27. package/esm2020/lib/directives/form-submitting.directive.mjs +41 -0
  28. package/esm2020/lib/directives/form.directive.mjs +541 -0
  29. package/esm2020/lib/directives/forms.module.mjs +100 -0
  30. package/esm2020/lib/directives/models.mjs +12 -0
  31. package/esm2020/lib/directives/parent-control-container.directive.mjs +25 -0
  32. package/esm2020/lib/directives/tokens.mjs +10 -0
  33. package/esm2020/lib/form-array.mjs +225 -0
  34. package/esm2020/lib/form-builder.mjs +374 -0
  35. package/esm2020/lib/form-control.mjs +169 -0
  36. package/esm2020/lib/form-group.mjs +181 -0
  37. package/esm2020/lib/model.mjs +2 -0
  38. package/esm2020/lib/tokens.mjs +4 -0
  39. package/esm2020/lib/types.mjs +2 -0
  40. package/esm2020/lib/validators/index.mjs +29 -0
  41. package/esm2020/lib/validators/is-array.mjs +18 -0
  42. package/esm2020/lib/validators/is-boolean.mjs +18 -0
  43. package/esm2020/lib/validators/is-complex.mjs +87 -0
  44. package/esm2020/lib/validators/is-date.mjs +18 -0
  45. package/esm2020/lib/validators/is-email.mjs +19 -0
  46. package/esm2020/lib/validators/is-enum.mjs +18 -0
  47. package/esm2020/lib/validators/is-int.mjs +19 -0
  48. package/esm2020/lib/validators/is-ip.mjs +19 -0
  49. package/esm2020/lib/validators/is-number.mjs +56 -0
  50. package/esm2020/lib/validators/is-object.mjs +18 -0
  51. package/esm2020/lib/validators/is-phone-number.mjs +19 -0
  52. package/esm2020/lib/validators/is-string.mjs +18 -0
  53. package/esm2020/lib/validators/is-url.mjs +19 -0
  54. package/esm2020/rxap-forms.mjs +5 -0
  55. package/fesm2015/rxap-forms.mjs +2721 -0
  56. package/fesm2015/rxap-forms.mjs.map +1 -0
  57. package/{fesm2015/rxap-forms.js → fesm2020/rxap-forms.mjs} +161 -147
  58. package/fesm2020/rxap-forms.mjs.map +1 -0
  59. package/package.json +35 -21
  60. package/src/schematics/ng-add/index.js +1 -1
  61. package/src/schematics/ng-add/index.js.map +1 -1
  62. package/bundles/rxap-forms.umd.js +0 -3521
  63. package/bundles/rxap-forms.umd.js.map +0 -1
  64. package/esm2015/index.js +0 -53
  65. package/esm2015/index.js.map +0 -1
  66. package/esm2015/lib/control-actions.js +0 -80
  67. package/esm2015/lib/control-actions.js.map +0 -1
  68. package/esm2015/lib/control-value-accessor.js +0 -14
  69. package/esm2015/lib/control-value-accessor.js.map +0 -1
  70. package/esm2015/lib/decorators/control-async-validator.js +0 -10
  71. package/esm2015/lib/decorators/control-async-validator.js.map +0 -1
  72. package/esm2015/lib/decorators/control-change.js +0 -10
  73. package/esm2015/lib/decorators/control-change.js.map +0 -1
  74. package/esm2015/lib/decorators/control-set-value.js +0 -8
  75. package/esm2015/lib/decorators/control-set-value.js.map +0 -1
  76. package/esm2015/lib/decorators/control-validator.js +0 -10
  77. package/esm2015/lib/decorators/control-validator.js.map +0 -1
  78. package/esm2015/lib/decorators/form.js +0 -7
  79. package/esm2015/lib/decorators/form.js.map +0 -1
  80. package/esm2015/lib/decorators/metadata-keys.js +0 -12
  81. package/esm2015/lib/decorators/metadata-keys.js.map +0 -1
  82. package/esm2015/lib/decorators/use-form-array.js +0 -13
  83. package/esm2015/lib/decorators/use-form-array.js.map +0 -1
  84. package/esm2015/lib/decorators/use-form-control.js +0 -8
  85. package/esm2015/lib/decorators/use-form-control.js.map +0 -1
  86. package/esm2015/lib/decorators/use-form-group.js +0 -8
  87. package/esm2015/lib/decorators/use-form-group.js.map +0 -1
  88. package/esm2015/lib/directives/form-control-error.directive.js +0 -61
  89. package/esm2015/lib/directives/form-control-error.directive.js.map +0 -1
  90. package/esm2015/lib/directives/form-control-mark-dirty.directive.js +0 -31
  91. package/esm2015/lib/directives/form-control-mark-dirty.directive.js.map +0 -1
  92. package/esm2015/lib/directives/form-control-mark-pristine.directive.js +0 -31
  93. package/esm2015/lib/directives/form-control-mark-pristine.directive.js.map +0 -1
  94. package/esm2015/lib/directives/form-control-mark-touched.directive.js +0 -25
  95. package/esm2015/lib/directives/form-control-mark-touched.directive.js.map +0 -1
  96. package/esm2015/lib/directives/form-control-mark-untouched.directive.js +0 -31
  97. package/esm2015/lib/directives/form-control-mark-untouched.directive.js.map +0 -1
  98. package/esm2015/lib/directives/form-control-name.directive.js +0 -64
  99. package/esm2015/lib/directives/form-control-name.directive.js.map +0 -1
  100. package/esm2015/lib/directives/form-group-name.directive.js +0 -61
  101. package/esm2015/lib/directives/form-group-name.directive.js.map +0 -1
  102. package/esm2015/lib/directives/form-loaded.directive.js +0 -42
  103. package/esm2015/lib/directives/form-loaded.directive.js.map +0 -1
  104. package/esm2015/lib/directives/form-loading-error.directive.js +0 -42
  105. package/esm2015/lib/directives/form-loading-error.directive.js.map +0 -1
  106. package/esm2015/lib/directives/form-loading.directive.js +0 -42
  107. package/esm2015/lib/directives/form-loading.directive.js.map +0 -1
  108. package/esm2015/lib/directives/form-submit-failed.directive.js +0 -42
  109. package/esm2015/lib/directives/form-submit-failed.directive.js.map +0 -1
  110. package/esm2015/lib/directives/form-submit-invalid.directive.js +0 -40
  111. package/esm2015/lib/directives/form-submit-invalid.directive.js.map +0 -1
  112. package/esm2015/lib/directives/form-submit-successful.directive.js +0 -40
  113. package/esm2015/lib/directives/form-submit-successful.directive.js.map +0 -1
  114. package/esm2015/lib/directives/form-submit.directive.js +0 -75
  115. package/esm2015/lib/directives/form-submit.directive.js.map +0 -1
  116. package/esm2015/lib/directives/form-submitting.directive.js +0 -42
  117. package/esm2015/lib/directives/form-submitting.directive.js.map +0 -1
  118. package/esm2015/lib/directives/form.directive.js +0 -544
  119. package/esm2015/lib/directives/form.directive.js.map +0 -1
  120. package/esm2015/lib/directives/forms.module.js +0 -100
  121. package/esm2015/lib/directives/forms.module.js.map +0 -1
  122. package/esm2015/lib/directives/models.js +0 -12
  123. package/esm2015/lib/directives/models.js.map +0 -1
  124. package/esm2015/lib/directives/parent-control-container.directive.js +0 -25
  125. package/esm2015/lib/directives/parent-control-container.directive.js.map +0 -1
  126. package/esm2015/lib/directives/tokens.js +0 -10
  127. package/esm2015/lib/directives/tokens.js.map +0 -1
  128. package/esm2015/lib/form-array.js +0 -217
  129. package/esm2015/lib/form-array.js.map +0 -1
  130. package/esm2015/lib/form-builder.js +0 -349
  131. package/esm2015/lib/form-builder.js.map +0 -1
  132. package/esm2015/lib/form-control.js +0 -170
  133. package/esm2015/lib/form-control.js.map +0 -1
  134. package/esm2015/lib/form-group.js +0 -183
  135. package/esm2015/lib/form-group.js.map +0 -1
  136. package/esm2015/lib/model.js +0 -2
  137. package/esm2015/lib/model.js.map +0 -1
  138. package/esm2015/lib/tokens.js +0 -4
  139. package/esm2015/lib/tokens.js.map +0 -1
  140. package/esm2015/lib/types.js +0 -2
  141. package/esm2015/lib/types.js.map +0 -1
  142. package/esm2015/lib/validators/index.js +0 -29
  143. package/esm2015/lib/validators/index.js.map +0 -1
  144. package/esm2015/lib/validators/is-array.js +0 -18
  145. package/esm2015/lib/validators/is-array.js.map +0 -1
  146. package/esm2015/lib/validators/is-boolean.js +0 -18
  147. package/esm2015/lib/validators/is-boolean.js.map +0 -1
  148. package/esm2015/lib/validators/is-complex.js +0 -87
  149. package/esm2015/lib/validators/is-complex.js.map +0 -1
  150. package/esm2015/lib/validators/is-date.js +0 -18
  151. package/esm2015/lib/validators/is-date.js.map +0 -1
  152. package/esm2015/lib/validators/is-email.js +0 -19
  153. package/esm2015/lib/validators/is-email.js.map +0 -1
  154. package/esm2015/lib/validators/is-enum.js +0 -18
  155. package/esm2015/lib/validators/is-enum.js.map +0 -1
  156. package/esm2015/lib/validators/is-int.js +0 -19
  157. package/esm2015/lib/validators/is-int.js.map +0 -1
  158. package/esm2015/lib/validators/is-ip.js +0 -19
  159. package/esm2015/lib/validators/is-ip.js.map +0 -1
  160. package/esm2015/lib/validators/is-number.js +0 -57
  161. package/esm2015/lib/validators/is-number.js.map +0 -1
  162. package/esm2015/lib/validators/is-object.js +0 -18
  163. package/esm2015/lib/validators/is-object.js.map +0 -1
  164. package/esm2015/lib/validators/is-phone-number.js +0 -19
  165. package/esm2015/lib/validators/is-phone-number.js.map +0 -1
  166. package/esm2015/lib/validators/is-string.js +0 -18
  167. package/esm2015/lib/validators/is-string.js.map +0 -1
  168. package/esm2015/lib/validators/is-url.js +0 -19
  169. package/esm2015/lib/validators/is-url.js.map +0 -1
  170. package/esm2015/rxap-forms.js +0 -5
  171. package/esm2015/rxap-forms.js.map +0 -1
  172. package/fesm2015/rxap-forms.js.map +0 -1
@@ -0,0 +1,2721 @@
1
+ import * as i1 from '@angular/forms';
2
+ import { FormArray, AbstractControl, FormGroup, FormControl, Validators, FormGroupDirective, ControlContainer, FormGroupName, NG_VALIDATORS, NG_ASYNC_VALIDATORS, FormControlName, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
3
+ import { map, distinctUntilChanged, debounceTime, filter, tap, startWith, take } from 'rxjs/operators';
4
+ import { merge, defer, of, EMPTY, Subject, isObservable, BehaviorSubject, Subscription } from 'rxjs';
5
+ import { equals, coerceArray, HasRxapOnInitMethod, assertIsArray, assertIsObject, assertIsFunction, isPromise, isObject, clone, Required, hasIndexSignature, coerceBoolean } from '@rxap/utilities';
6
+ import * as i0 from '@angular/core';
7
+ import { isDevMode, Injector, InjectionToken, EventEmitter, ChangeDetectorRef, forwardRef, Directive, Inject, Optional, SkipSelf, Input, Output, HostBinding, TemplateRef, ViewContainerRef, Host, HostListener, Self, NgModule } from '@angular/core';
8
+ import { GetDefinitionMetadata, DefinitionMetadata } from '@rxap/definition';
9
+ import { getMetadata, setMetadataMapSet, setMetadataMap } from '@rxap/utilities/reflect-metadata';
10
+ import { __decorate, __metadata } from 'tslib';
11
+ import * as i2 from '@rxap/services';
12
+ import { LoadingIndicatorService } from '@rxap/services';
13
+ import { ToggleSubject } from '@rxap/utilities/rxjs';
14
+ import * as i2$1 from '@angular/router';
15
+ import { Router } from '@angular/router';
16
+ import { ConfirmClick } from '@rxap/directives';
17
+ import { isMobilePhone, isEmail, isURL, isIP } from '@rxap/validator';
18
+
19
+ function getControlValue(control) {
20
+ if (control.getRawValue) {
21
+ return control.getRawValue();
22
+ }
23
+ return control.value;
24
+ }
25
+ function controlValueChanges$(control) {
26
+ return merge(defer(() => of(getControlValue(control))), control.valueChanges.pipe(map(() => getControlValue(control))));
27
+ }
28
+ function controlDisabled$(control) {
29
+ var _a;
30
+ return merge(defer(() => of(control.disabled)), merge(control.statusChanges, (_a = control.stateChanges) !== null && _a !== void 0 ? _a : EMPTY).pipe(map(() => control.disabled), distinctUntilChanged()));
31
+ }
32
+ function controlEnabled$(control) {
33
+ var _a;
34
+ return merge(defer(() => of(control.enabled)), merge(control.statusChanges, (_a = control.stateChanges) !== null && _a !== void 0 ? _a : EMPTY).pipe(map(() => control.enabled), distinctUntilChanged()));
35
+ }
36
+ function controlReadonly$(control) {
37
+ var _a;
38
+ return merge(defer(() => { var _a; return of((_a = control.readonly) !== null && _a !== void 0 ? _a : false); }), merge(control.statusChanges, (_a = control.stateChanges) !== null && _a !== void 0 ? _a : EMPTY).pipe(map(() => { var _a; return (_a = control.readonly) !== null && _a !== void 0 ? _a : false; }), distinctUntilChanged()));
39
+ }
40
+ function controlStatusChanges$(control) {
41
+ return merge(defer(() => of(control.status)), control.statusChanges.pipe(map(() => control.status), distinctUntilChanged()));
42
+ }
43
+ function controlErrorChanges$(control) {
44
+ return merge(defer(() => of(control.errors)), control.valueChanges.pipe(map(() => control.errors)), control.statusChanges.pipe(map(() => control.errors))).pipe(distinctUntilChanged((a, b) => equals(a, b)));
45
+ }
46
+ function enableControl(control, enabled, opts) {
47
+ if (enabled) {
48
+ control.enable(opts);
49
+ }
50
+ else {
51
+ control.disable(opts);
52
+ }
53
+ }
54
+ function disableControl(control, disabled, opts) {
55
+ enableControl(control, !disabled, opts);
56
+ }
57
+ function controlDisabledWhile(control, observable, opts) {
58
+ return observable.subscribe(isDisabled => disableControl(control, isDisabled, opts));
59
+ }
60
+ function controlEnabledWhile(control, observable, opts) {
61
+ return observable.subscribe(isEnabled => enableControl(control, isEnabled, opts));
62
+ }
63
+ function mergeControlValidators(control, validators) {
64
+ control.setValidators([...coerceArray(control.validator), ...coerceArray(validators)]);
65
+ control.updateValueAndValidity();
66
+ }
67
+ function validateControlOn(control, validation) {
68
+ return validation.subscribe(maybeError => {
69
+ control.setErrors(maybeError);
70
+ });
71
+ }
72
+ function hasErrorAndTouched(control, error, path) {
73
+ const hasError = control.hasError(error, !path || path.length === 0 ? undefined : path);
74
+ return hasError && control.touched;
75
+ }
76
+ function hasErrorAndDirty(control, error, path) {
77
+ const hasError = control.hasError(error, !path || path.length === 0 ? undefined : path);
78
+ return hasError && control.dirty;
79
+ }
80
+ function markAllDirty(control) {
81
+ control.markAsDirty({ onlySelf: true });
82
+ control._forEachChild((_control) => _control.markAllAsDirty());
83
+ }
84
+ function markAllPristine(control) {
85
+ control.markAsPristine({ onlySelf: true });
86
+ control._forEachChild((_control) => _control.markAllAsPristine());
87
+ }
88
+ function markAllUntouched(control) {
89
+ control.markAsUntouched({ onlySelf: true });
90
+ control._forEachChild((_control) => _control.markAllAsUntouched());
91
+ }
92
+ function selectControlValue$(control, mapFn) {
93
+ return control.value$.pipe(map(mapFn), distinctUntilChanged());
94
+ }
95
+
96
+ class RxapFormArray extends FormArray {
97
+ constructor(controls, options) {
98
+ super(controls, options);
99
+ this.controls = controls;
100
+ this._readonly = false;
101
+ this.value$ = controlValueChanges$(this);
102
+ this.disabled$ = controlDisabled$(this);
103
+ this.enabled$ = controlEnabled$(this);
104
+ this.status$ = controlStatusChanges$(this);
105
+ this.errors$ = controlErrorChanges$(this);
106
+ this.touchChanges = new Subject();
107
+ this.touch$ = this.touchChanges
108
+ .asObservable()
109
+ .pipe(distinctUntilChanged());
110
+ this.dirtyChanges = new Subject();
111
+ this.dirty$ = this.dirtyChanges
112
+ .asObservable()
113
+ .pipe(distinctUntilChanged());
114
+ this.controlId = options.controlId;
115
+ this._builder = options.builder;
116
+ this._controlInsertedFn = options.controlInsertedFn;
117
+ this._controlRemovedFn = options.controlRemovedFn;
118
+ }
119
+ get readonly() {
120
+ var _a, _b;
121
+ return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.readonly) !== null && _b !== void 0 ? _b : this._readonly;
122
+ }
123
+ set readonly(value) {
124
+ this._readonly = value;
125
+ this.controls.forEach(control => { var _a; return (_a = control.stateChanges) === null || _a === void 0 ? void 0 : _a.next(); });
126
+ }
127
+ /**
128
+ * @internal
129
+ */
130
+ get rxapFormDefinition() {
131
+ return this.parent.rxapFormDefinition;
132
+ }
133
+ get controlPath() {
134
+ const parent = this.parent;
135
+ if (parent) {
136
+ if (parent.controlPath) {
137
+ if (parent === this.root) {
138
+ return this.controlId;
139
+ }
140
+ else {
141
+ return [parent.controlPath, this.controlId].join('.');
142
+ }
143
+ }
144
+ }
145
+ return this.controlId;
146
+ }
147
+ get fullControlPath() {
148
+ const parent = this.parent;
149
+ if (parent) {
150
+ if (parent.fullControlPath) {
151
+ return [parent.fullControlPath, this.controlId].join('.');
152
+ }
153
+ }
154
+ return this.controlId;
155
+ }
156
+ select(mapFn) {
157
+ return this.value$.pipe(map(mapFn), distinctUntilChanged());
158
+ }
159
+ at(index) {
160
+ return super.at(index);
161
+ }
162
+ getRawValue() {
163
+ return super.getRawValue();
164
+ }
165
+ insert(index, control) {
166
+ if (isDevMode()) {
167
+ console.warn('It is not recommend to use the FormArray.insert method');
168
+ }
169
+ return super.insert(index, control);
170
+ }
171
+ /**
172
+ * inserts a new control at the specified index. If the index is undefined
173
+ * the new control will be added to the end.
174
+ *
175
+ * @param index (optional) the index where the control should be created
176
+ * @param state (optional) the initial state of the new control
177
+ */
178
+ insertAt(index, state) {
179
+ const insertIndex = index !== null && index !== void 0 ? index : this.controls.length;
180
+ const controlOrDefinition = this._builder(state, {
181
+ controlId: insertIndex.toFixed(0),
182
+ });
183
+ this._controlInsertedFn(insertIndex, controlOrDefinition);
184
+ if (insertIndex < this.controls.length) {
185
+ // update the control ids for all controls, that are moved.
186
+ for (let i = insertIndex; i < this.controls.length; i++) {
187
+ Reflect.set(this.controls[i], 'controlId', (i + 1).toFixed(0));
188
+ }
189
+ }
190
+ // call the super insert after the update, bc the insert method will
191
+ // trigger a change detection
192
+ if (controlOrDefinition instanceof AbstractControl) {
193
+ super.insert(insertIndex, controlOrDefinition);
194
+ }
195
+ else {
196
+ super.insert(insertIndex, controlOrDefinition.rxapFormGroup);
197
+ }
198
+ }
199
+ disabledWhile(observable, options) {
200
+ return controlDisabledWhile(this, observable, options);
201
+ }
202
+ enabledWhile(observable, options) {
203
+ return controlEnabledWhile(this, observable, options);
204
+ }
205
+ mergeValidators(validators) {
206
+ mergeControlValidators(this, validators);
207
+ }
208
+ mergeAsyncValidators(validators) {
209
+ this.setAsyncValidators([
210
+ ...coerceArray(this.asyncValidator),
211
+ ...coerceArray(validators),
212
+ ]);
213
+ this.updateValueAndValidity();
214
+ }
215
+ markAllAsDirty() {
216
+ markAllDirty(this);
217
+ }
218
+ markAllAsPristine() {
219
+ markAllPristine(this);
220
+ }
221
+ setValue(valueOrObservable, options) {
222
+ if (isObservable(valueOrObservable)) {
223
+ return valueOrObservable.subscribe((value) => super.setValue(value, options));
224
+ }
225
+ super.setValue(valueOrObservable, options);
226
+ }
227
+ markAllAsUntouched() {
228
+ markAllUntouched(this);
229
+ }
230
+ validateOn(observableValidation) {
231
+ return observableValidation.subscribe((maybeError) => {
232
+ this.setErrors(maybeError);
233
+ });
234
+ }
235
+ hasErrorAndTouched(errorCode, path) {
236
+ return hasErrorAndTouched(this, errorCode, path);
237
+ }
238
+ patchValue(valueOrObservable, options) {
239
+ if (isObservable(valueOrObservable)) {
240
+ return valueOrObservable.subscribe((value) => {
241
+ super.patchValue(value, options);
242
+ });
243
+ }
244
+ super.patchValue(valueOrObservable, options);
245
+ }
246
+ hasErrorAndDirty(errorCode, path) {
247
+ return hasErrorAndDirty(this, errorCode, path);
248
+ }
249
+ removeAt(index) {
250
+ if (isDevMode()) {
251
+ console.warn('It is not recommend to use the FormArray.removeAt method');
252
+ }
253
+ super.removeAt(index);
254
+ this._controlRemovedFn(index);
255
+ }
256
+ setEnable(enable = true, opts) {
257
+ enableControl(this, enable, opts);
258
+ }
259
+ push(control) {
260
+ if (isDevMode()) {
261
+ console.warn('It is not recommend to use the FormArray.push method');
262
+ }
263
+ return super.push(control);
264
+ }
265
+ setDisable(disable = true, opts) {
266
+ disableControl(this, disable, opts);
267
+ }
268
+ setControl(index, control) {
269
+ if (isDevMode()) {
270
+ console.warn('It is not recommend to use the FormArray.setControl method');
271
+ }
272
+ return super.setControl(index, control);
273
+ }
274
+ markAsTouched(opts) {
275
+ super.markAsTouched(opts);
276
+ this.touchChanges.next(true);
277
+ }
278
+ markAsUntouched(opts) {
279
+ super.markAsUntouched(opts);
280
+ this.touchChanges.next(false);
281
+ }
282
+ markAsPristine(opts) {
283
+ super.markAsPristine(opts);
284
+ this.dirtyChanges.next(false);
285
+ }
286
+ markAsDirty(opts) {
287
+ super.markAsDirty(opts);
288
+ this.dirtyChanges.next(true);
289
+ }
290
+ reset(value, options) {
291
+ super.reset(value, options);
292
+ }
293
+ setValidators(newValidator, updateValueAndValidity = true) {
294
+ super.setValidators(newValidator);
295
+ if (updateValueAndValidity) {
296
+ super.updateValueAndValidity();
297
+ }
298
+ }
299
+ setAsyncValidators(newValidator, updateValueAndValidity = true) {
300
+ super.setAsyncValidators(newValidator);
301
+ if (updateValueAndValidity) {
302
+ super.updateValueAndValidity();
303
+ }
304
+ }
305
+ hasError(errorCode, path) {
306
+ return super.hasError(errorCode, path);
307
+ }
308
+ setErrors(errors, opts = {}) {
309
+ return super.setErrors(errors, opts);
310
+ }
311
+ getError(errorCode, path) {
312
+ return super.getError(errorCode, path);
313
+ }
314
+ }
315
+
316
+ var MetadataKeys;
317
+ (function (MetadataKeys) {
318
+ MetadataKeys["CONTROL_VALIDATORS"] = "rxap/forms/control-validators";
319
+ MetadataKeys["CONTROL_ASYNC_VALIDATORS"] = "rxap/forms/control-async-validators";
320
+ MetadataKeys["CONTROL_CHANGES"] = "rxap/forms/control-changes";
321
+ MetadataKeys["CONTROL_SET_VALUE"] = "rxap/forms/control-set-value";
322
+ MetadataKeys["FORM_ARRAY_GROUPS"] = "rxap/forms/form-array-groups";
323
+ MetadataKeys["FORM_ARRAY_CONTROLS"] = "rxap/forms/form-array-controls";
324
+ MetadataKeys["FORM_GROUPS"] = "rxap/forms/form-groups";
325
+ MetadataKeys["FORM_CONTROLS"] = "rxap/forms/form-controls";
326
+ })(MetadataKeys || (MetadataKeys = {}));
327
+
328
+ class RxapFormGroup extends FormGroup {
329
+ constructor(controls, options) {
330
+ super(controls, options);
331
+ this.controls = controls;
332
+ this._readonly = false;
333
+ this.touchChanges = new Subject();
334
+ this.dirtyChanges = new Subject();
335
+ this.touch$ = this.touchChanges.asObservable().pipe(distinctUntilChanged());
336
+ this.dirty$ = this.dirtyChanges.asObservable().pipe(distinctUntilChanged());
337
+ this.value$ = controlValueChanges$(this);
338
+ this.disabled$ = controlDisabled$(this);
339
+ this.enabled$ = controlEnabled$(this);
340
+ this.status$ = controlStatusChanges$(this);
341
+ this.errors$ = controlErrorChanges$(this);
342
+ this.controlId = options.controlId;
343
+ }
344
+ /**
345
+ * @internal
346
+ */
347
+ get rxapFormDefinition() {
348
+ if (!this.parent) {
349
+ return this._rxapFormDefinition;
350
+ }
351
+ if (this._rxapFormDefinition) {
352
+ return this._rxapFormDefinition;
353
+ }
354
+ return this.parent.rxapFormDefinition;
355
+ }
356
+ get readonly() {
357
+ var _a, _b;
358
+ return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.readonly) !== null && _b !== void 0 ? _b : this._readonly;
359
+ }
360
+ set readonly(value) {
361
+ var _a;
362
+ this._readonly = value;
363
+ Object.values((_a = this.controls) !== null && _a !== void 0 ? _a : {}).forEach(control => { var _a; return (_a = control.stateChanges) === null || _a === void 0 ? void 0 : _a.next(); });
364
+ }
365
+ get controlPath() {
366
+ const parent = this.parent;
367
+ if (parent) {
368
+ if (parent.controlPath) {
369
+ if (parent === this.root) {
370
+ return this.controlId;
371
+ }
372
+ else {
373
+ return [parent.controlPath, this.controlId].join('.');
374
+ }
375
+ }
376
+ }
377
+ return '';
378
+ }
379
+ get fullControlPath() {
380
+ const parent = this.parent;
381
+ if (parent) {
382
+ if (parent.fullControlPath) {
383
+ return [parent.fullControlPath, this.controlId].join('.');
384
+ }
385
+ }
386
+ return this.controlId;
387
+ }
388
+ select(mapFn) {
389
+ return selectControlValue$(this, mapFn);
390
+ }
391
+ getRawValue() {
392
+ return super.getRawValue();
393
+ }
394
+ get(path) {
395
+ return super.get(path);
396
+ }
397
+ getControl(...names) {
398
+ return this.get(names.join('.'));
399
+ }
400
+ addControl(name, control) {
401
+ super.addControl(name, control);
402
+ }
403
+ removeControl(name) {
404
+ super.removeControl(name);
405
+ }
406
+ contains(controlName) {
407
+ return super.contains(controlName);
408
+ }
409
+ setControl(name, control) {
410
+ super.setControl(name, control);
411
+ }
412
+ setValue(valueOrObservable, options) {
413
+ if (isObservable(valueOrObservable)) {
414
+ return valueOrObservable.subscribe((value) => super.setValue(value, options));
415
+ }
416
+ super.setValue(valueOrObservable, options);
417
+ }
418
+ patchValue(valueOrObservable, options) {
419
+ if (isObservable(valueOrObservable)) {
420
+ return valueOrObservable.subscribe((value) => super.patchValue(value, options));
421
+ }
422
+ super.patchValue(valueOrObservable, options);
423
+ }
424
+ disabledWhile(observable, options) {
425
+ return controlDisabledWhile(this, observable, options);
426
+ }
427
+ enabledWhile(observable, options) {
428
+ return controlEnabledWhile(this, observable, options);
429
+ }
430
+ mergeValidators(validators) {
431
+ mergeControlValidators(this, validators);
432
+ }
433
+ mergeAsyncValidators(validators) {
434
+ this.setAsyncValidators([
435
+ ...coerceArray(this.asyncValidator),
436
+ ...coerceArray(validators),
437
+ ]);
438
+ this.updateValueAndValidity();
439
+ }
440
+ markAsTouched(opts) {
441
+ super.markAsTouched(opts);
442
+ this.touchChanges.next(true);
443
+ }
444
+ markAsUntouched(opts) {
445
+ super.markAsUntouched(opts);
446
+ this.touchChanges.next(false);
447
+ }
448
+ markAsPristine(opts) {
449
+ super.markAsPristine(opts);
450
+ this.dirtyChanges.next(false);
451
+ }
452
+ markAsDirty(opts) {
453
+ super.markAsDirty(opts);
454
+ this.dirtyChanges.next(true);
455
+ }
456
+ markAllAsDirty() {
457
+ markAllDirty(this);
458
+ }
459
+ markAllAsPristine() {
460
+ markAllPristine(this);
461
+ }
462
+ markAllAsUntouched() {
463
+ markAllUntouched(this);
464
+ }
465
+ reset(formState, options) {
466
+ super.reset(formState, options);
467
+ }
468
+ setValidators(newValidator, updateValueAndValidity = true) {
469
+ super.setValidators(newValidator);
470
+ if (updateValueAndValidity) {
471
+ super.updateValueAndValidity();
472
+ }
473
+ }
474
+ setAsyncValidators(newValidator, updateValueAndValidity = true) {
475
+ super.setAsyncValidators(newValidator);
476
+ if (updateValueAndValidity) {
477
+ super.updateValueAndValidity();
478
+ }
479
+ }
480
+ validateOn(observableValidation) {
481
+ return validateControlOn(this, observableValidation);
482
+ }
483
+ hasError(errorCode, path) {
484
+ return super.hasError(errorCode, path);
485
+ }
486
+ setErrors(errors, opts = {}) {
487
+ return super.setErrors(errors, opts);
488
+ }
489
+ getError(errorCode, path) {
490
+ return super.getError(errorCode, path);
491
+ }
492
+ hasErrorAndTouched(error, ...path) {
493
+ return hasErrorAndTouched(this, error, ...path);
494
+ }
495
+ hasErrorAndDirty(error, ...path) {
496
+ return hasErrorAndDirty(this, error, ...path);
497
+ }
498
+ setEnable(enable = true, opts) {
499
+ enableControl(this, enable, opts);
500
+ }
501
+ setDisable(disable = true, opts) {
502
+ disableControl(this, disable, opts);
503
+ }
504
+ }
505
+
506
+ class RxapFormControl extends FormControl {
507
+ constructor(formState, options) {
508
+ super(formState, options);
509
+ this._readonly = false;
510
+ this.touchChanges = new Subject();
511
+ this.dirtyChanges = new Subject();
512
+ this.touch$ = this.touchChanges
513
+ .asObservable()
514
+ .pipe(distinctUntilChanged());
515
+ this.dirty$ = this.dirtyChanges
516
+ .asObservable()
517
+ .pipe(distinctUntilChanged());
518
+ this.value$ = controlValueChanges$(this);
519
+ this.disabled$ = controlDisabled$(this);
520
+ this.enabled$ = controlEnabled$(this);
521
+ this.status$ = controlStatusChanges$(this);
522
+ this.errors$ = controlErrorChanges$(this);
523
+ this._onSetValue = [];
524
+ this.stateChanges = new Subject();
525
+ this.readonly$ = controlReadonly$(this);
526
+ this.controlId = options.controlId;
527
+ this.initialState = formState;
528
+ }
529
+ /**
530
+ * @internal
531
+ */
532
+ get rxapFormDefinition() {
533
+ return this.parent.rxapFormDefinition;
534
+ }
535
+ get readonly() {
536
+ var _a, _b;
537
+ return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.readonly) !== null && _b !== void 0 ? _b : this._readonly;
538
+ }
539
+ set readonly(value) {
540
+ this._readonly = value;
541
+ this.stateChanges.next();
542
+ }
543
+ get controlPath() {
544
+ const parent = this.parent;
545
+ if (parent) {
546
+ if (parent.controlPath) {
547
+ if (parent === this.root) {
548
+ return this.controlId;
549
+ }
550
+ else {
551
+ return [parent.controlPath, this.controlId].join('.');
552
+ }
553
+ }
554
+ }
555
+ return this.controlId;
556
+ }
557
+ get fullControlPath() {
558
+ const parent = this.parent;
559
+ if (parent) {
560
+ if (parent.fullControlPath) {
561
+ return [parent.fullControlPath, this.controlId].join('.');
562
+ }
563
+ }
564
+ return this.controlId;
565
+ }
566
+ setValue(valueOrObservable, options) {
567
+ if (isObservable(valueOrObservable)) {
568
+ return valueOrObservable.subscribe((value) => {
569
+ super.setValue(value, options);
570
+ this._onSetValue.forEach((setValueFn) => setValueFn(value, options));
571
+ });
572
+ }
573
+ super.setValue(valueOrObservable, options);
574
+ this._onSetValue.forEach((setValueFn) => setValueFn(valueOrObservable, options));
575
+ }
576
+ patchValue(valueOrObservable, options) {
577
+ if (isObservable(valueOrObservable)) {
578
+ return valueOrObservable.subscribe((value) => super.patchValue(value, options));
579
+ }
580
+ super.patchValue(valueOrObservable, options);
581
+ }
582
+ disabledWhile(observable, options) {
583
+ return controlDisabledWhile(this, observable, options);
584
+ }
585
+ enabledWhile(observable, options) {
586
+ return controlEnabledWhile(this, observable, options);
587
+ }
588
+ mergeValidators(validators) {
589
+ mergeControlValidators(this, validators);
590
+ }
591
+ mergeAsyncValidators(validators) {
592
+ this.setAsyncValidators([
593
+ // TODO : remove 'as any' if solution for the type overwrite issue is found (above)
594
+ this.asyncValidator,
595
+ ...coerceArray(validators),
596
+ ]);
597
+ this.updateValueAndValidity();
598
+ }
599
+ markAsTouched(opts) {
600
+ super.markAsTouched(opts);
601
+ this.touchChanges.next(true);
602
+ }
603
+ markAsUntouched(opts) {
604
+ super.markAsUntouched(opts);
605
+ this.touchChanges.next(false);
606
+ }
607
+ markAsPristine(opts) {
608
+ super.markAsPristine(opts);
609
+ this.dirtyChanges.next(false);
610
+ }
611
+ markAsDirty(opts) {
612
+ super.markAsDirty(opts);
613
+ this.dirtyChanges.next(true);
614
+ }
615
+ markAllAsDirty() {
616
+ this.markAsDirty({ onlySelf: true });
617
+ }
618
+ reset(formState, options) {
619
+ const newState = formState !== null && formState !== void 0 ? formState : this.initialState;
620
+ if (typeof newState === 'function') {
621
+ super.reset(newState(), options);
622
+ }
623
+ else {
624
+ super.reset(newState, options);
625
+ }
626
+ }
627
+ setValidators(newValidator, updateValueAndValidity = true) {
628
+ super.setValidators(newValidator);
629
+ if (updateValueAndValidity) {
630
+ super.updateValueAndValidity();
631
+ }
632
+ }
633
+ setAsyncValidators(newValidator, updateValueAndValidity = true) {
634
+ super.setAsyncValidators(newValidator);
635
+ if (updateValueAndValidity) {
636
+ super.updateValueAndValidity();
637
+ }
638
+ }
639
+ validateOn(observableValidation) {
640
+ return validateControlOn(this, observableValidation);
641
+ }
642
+ getError(errorCode) {
643
+ return super.getError(errorCode);
644
+ }
645
+ hasError(errorCode) {
646
+ return super.hasError(errorCode);
647
+ }
648
+ setErrors(errors, opts = {}) {
649
+ return super.setErrors(errors, opts);
650
+ }
651
+ setError(key, value, opts = {}) {
652
+ super.setErrors({ [key]: value }, opts);
653
+ }
654
+ hasErrorAndTouched(error) {
655
+ return hasErrorAndTouched(this, error);
656
+ }
657
+ hasErrorAndDirty(error) {
658
+ return hasErrorAndDirty(this, error);
659
+ }
660
+ setEnable(enable = true, opts) {
661
+ enableControl(this, enable, opts);
662
+ }
663
+ setDisable(disable = true, opts) {
664
+ disableControl(this, disable, opts);
665
+ }
666
+ registerOnSetValue(setValueFn) {
667
+ this._onSetValue.push(setValueFn);
668
+ }
669
+ }
670
+
671
+ class FormArrayControlManager {
672
+ constructor(form, controlId) {
673
+ this.form = form;
674
+ this.controlId = controlId;
675
+ }
676
+ inserted(index, controlOrDefinition) {
677
+ const controlContainer = this.form[this.controlId];
678
+ if (Array.isArray(controlContainer)) {
679
+ controlContainer.splice(index, 0, controlOrDefinition);
680
+ }
681
+ else {
682
+ throw new Error('Could not register inserted control or definition. The control id does not points to an array of control or definition instance!');
683
+ }
684
+ }
685
+ removed(index) {
686
+ const controlContainer = this.form[this.controlId];
687
+ if (Array.isArray(controlContainer)) {
688
+ controlContainer.splice(index, 1);
689
+ }
690
+ else {
691
+ throw new Error('Could not register inserted control or definition. The control id does not points to an array of control or definition instance!');
692
+ }
693
+ }
694
+ }
695
+ class RxapFormBuilder {
696
+ constructor(definition, injector = Injector.NULL, providers = []) {
697
+ var _a;
698
+ this.definition = definition;
699
+ this.injector = injector;
700
+ this.formArrayGroups = this.extractArrayGroups();
701
+ this.formArrayControls = this.extractArrayControls();
702
+ this.formControls = this.extractControls();
703
+ this.formGroups = this.extractGroups();
704
+ this.validators = this.extractValidators();
705
+ this.asyncValidators = this.extractAsyncValidators();
706
+ this.controlChanges = this.extractControlChanges();
707
+ this.controlSetValue = this.extractControlSetValue();
708
+ const formOptions = (this.formOptions = this.extractFormOptions());
709
+ // merge the providers from the from options with the providers from the
710
+ // constructor. If the provider is defined in the form options and constructor
711
+ // then the provider from the constructor will be used.
712
+ this.providers = [...providers, ...((_a = formOptions.providers) !== null && _a !== void 0 ? _a : [])].filter((provider, index, self) => provider.hasOwnProperty('provide') &&
713
+ self.findIndex((selfProvider) => selfProvider.hasOwnProperty('provide') &&
714
+ selfProvider.provide === provider.provide) === index);
715
+ }
716
+ build(state = {}, options = {}) {
717
+ var _a, _b;
718
+ const injector = Injector.create({
719
+ name: `rxap/form-builder/${this.formOptions.id}`,
720
+ parent: this.injector,
721
+ providers: this.providers
722
+ });
723
+ let form;
724
+ // don't use the notFoundValue feature of the injector.
725
+ // if used for each call of the get method an "empty" or "fallback"
726
+ // instance is created
727
+ try {
728
+ form = injector.get(this.definition);
729
+ }
730
+ catch (e) {
731
+ if (isDevMode()) {
732
+ console.error(`Could not inject the definition instance. Fallback and call the constructor of the definition class: ${e.message}`);
733
+ }
734
+ form = new this.definition();
735
+ }
736
+ const controls = {};
737
+ this.buildControls(state, form, controls);
738
+ this.buildGroups(state, form, controls);
739
+ this.buildArrayGroups(state, form, controls);
740
+ this.buildArrayControls(state, form, controls);
741
+ const formOptions = Object.assign(Object.assign(Object.assign({}, this.formOptions), { controlId: (_a = options.controlId) !== null && _a !== void 0 ? _a : (options.id ? options.id : this.formOptions.id) }), options);
742
+ form.rxapFormGroup = new RxapFormGroup(controls, formOptions);
743
+ Reflect.set(form.rxapFormGroup, '_rxapFormDefinition', form);
744
+ form.rxapMetadata = this.formOptions;
745
+ if (HasRxapOnInitMethod(form)) {
746
+ form.rxapOnInit();
747
+ }
748
+ for (const control of Object.values(form.rxapFormGroup.controls)) {
749
+ if (control.controlId) {
750
+ const controlSetValueOnInit = Array.from((_b = this.controlSetValue.get(control.controlId)) !== null && _b !== void 0 ? _b : []).filter((controlSetValueOptions) => controlSetValueOptions.initial);
751
+ for (const onSetValue of this.coerceToFnArray(form, controlSetValueOnInit)) {
752
+ onSetValue(control.value, { initial: true });
753
+ }
754
+ }
755
+ }
756
+ return form;
757
+ }
758
+ buildArrayControls(builderFormState, form, controls) {
759
+ for (const [controlId, options] of this.formArrayControls.entries()) {
760
+ const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
761
+ assertIsArray(formState);
762
+ const formControls = formState.map((fs, index) => new RxapFormControl(fs, { controlId: index.toFixed(0) }));
763
+ const manager = new FormArrayControlManager(form, controlId);
764
+ const formArray = (formControls.rxapFormArray =
765
+ controls[controlId] =
766
+ new RxapFormArray(
767
+ // TODO : add the formControlOptions property. To definition the form control options
768
+ formControls, Object.assign(Object.assign({}, options), { controlId, validators: [], asyncValidators: [], controlInsertedFn: manager.inserted.bind(manager), controlRemovedFn: manager.removed.bind(manager), builder: (state, controlOptions) => new RxapFormControl(state, controlOptions) })));
769
+ // TODO : add support for injectable validators
770
+ formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
771
+ formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
772
+ Reflect.set(form, controlId, formControls);
773
+ }
774
+ }
775
+ buildArrayGroups(builderFormState, form, controls) {
776
+ for (const [controlId, options] of this.formArrayGroups.entries()) {
777
+ const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
778
+ assertIsArray(formState);
779
+ const formGroupBuilder = new RxapFormBuilder(options.definition, this.injector, this.providers);
780
+ // TODO : add the formGroupOptions property. To definition of the form group options
781
+ const formGroupDefinitions = formState.map((fs, index) => formGroupBuilder.build(fs, { id: index.toFixed(0) }));
782
+ const manager = new FormArrayControlManager(form, controlId);
783
+ const formArray = (formGroupDefinitions.rxapFormArray =
784
+ controls[controlId] =
785
+ new RxapFormArray(formGroupDefinitions.map((fgd) => fgd.rxapFormGroup), Object.assign(Object.assign({}, options), { builder: formGroupBuilder.build.bind(formGroupBuilder), controlId, validators: [], asyncValidators: [], controlInsertedFn: manager.inserted.bind(manager), controlRemovedFn: manager.removed.bind(manager) })));
786
+ // TODO : add support for injectable validators
787
+ formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
788
+ formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
789
+ Reflect.set(form, controlId, formGroupDefinitions);
790
+ }
791
+ }
792
+ buildGroups(builderFormState, form, controls) {
793
+ for (const [controlId, options] of this.formGroups.entries()) {
794
+ const formState = this.coerceToGroupFormState(controlId, {}, builderFormState, options.state);
795
+ assertIsObject(formState);
796
+ const formGroupDefinition = new RxapFormBuilder(options.definition, this.injector, this.providers).build(formState, Object.assign(Object.assign({}, options), { validators: [], asyncValidators: [] }));
797
+ controls[controlId] = formGroupDefinition.rxapFormGroup;
798
+ const formGroup = formGroupDefinition.rxapFormGroup;
799
+ // TODO : add support for injectable validators
800
+ formGroup.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
801
+ formGroup.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
802
+ // set the form group definition instance to the form definition instance
803
+ Reflect.set(form, controlId, formGroupDefinition);
804
+ }
805
+ }
806
+ buildControls(builderFormState, form, controls) {
807
+ var _a, _b;
808
+ for (const [controlId, options] of this.formControls.entries()) {
809
+ const control = (controls[controlId] = new ((_a = options.controlType) !== null && _a !== void 0 ? _a : RxapFormControl)(this.coerceToControlFormState(controlId, null, builderFormState, options.state), Object.assign(Object.assign({}, options), { controlId, validators: [], asyncValidators: [] })));
810
+ const injectValidators = [];
811
+ const injectAsyncValidators = [];
812
+ for (const injectValidator of (_b = options.injectValidators) !== null && _b !== void 0 ? _b : []) {
813
+ const injectableValidator = this.injector.get(injectValidator);
814
+ if (injectableValidator.validate) {
815
+ injectValidators.push(injectableValidator.validate.bind(injectableValidator));
816
+ }
817
+ if (injectableValidator.asyncValidate) {
818
+ injectAsyncValidators.push(injectableValidator.asyncValidate.bind(injectableValidator));
819
+ }
820
+ }
821
+ control.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId), injectValidators), false);
822
+ control.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId), injectAsyncValidators), false);
823
+ // register all control on change function with the form control
824
+ this.coerceToFnArray(form, this.controlChanges.get(controlId)).forEach((changeFn) => control.registerOnChange(changeFn));
825
+ // register all control on set value function with the form control
826
+ this.coerceToFnArray(form, this.controlSetValue.get(controlId)).forEach((setValueFn) => control.registerOnSetValue(setValueFn));
827
+ if (Array.isArray(options.validators)) {
828
+ if (options.validators.includes(Validators.required) ||
829
+ options.validators.includes(Validators.requiredTrue)) {
830
+ Reflect.set(control, 'hasRequiredValidator', true);
831
+ }
832
+ }
833
+ // set the form control instance to the form definition instance
834
+ Reflect.set(form, controlId, control);
835
+ }
836
+ }
837
+ /**
838
+ * Coerce to a function array.
839
+ *
840
+ * @param form the current form definition instance
841
+ * @param methodKeys A set of propertyKeys that points to form
842
+ * definition instance methods
843
+ */
844
+ coerceToFnArray(form, methodKeys) {
845
+ const changes = [];
846
+ if (methodKeys) {
847
+ for (const propertyKeyOrOptions of methodKeys) {
848
+ const propertyKey = typeof propertyKeyOrOptions === 'string'
849
+ ? propertyKeyOrOptions
850
+ : propertyKeyOrOptions.propertyKey;
851
+ assertIsFunction(form[propertyKey]);
852
+ changes.push(form[propertyKey].bind(form));
853
+ }
854
+ }
855
+ return changes;
856
+ }
857
+ /**
858
+ * Coerce to a validator function array.
859
+ *
860
+ * @param form the current form definition instance
861
+ * @param optionsValidators The options validator functions
862
+ * @param validatorMethodKeys A set of propertyKeys that points to form
863
+ * definition instance methods
864
+ * @param injectValidators Injected validator functions
865
+ */
866
+ coerceToValidatorArray(form, optionsValidators, validatorMethodKeys, injectValidators) {
867
+ const validators = optionsValidators
868
+ ? Array.isArray(optionsValidators)
869
+ ? optionsValidators
870
+ : [optionsValidators]
871
+ : [];
872
+ if (validatorMethodKeys) {
873
+ validatorMethodKeys.forEach((propertyKey) => {
874
+ assertIsFunction(form[propertyKey]);
875
+ validators.push(form[propertyKey].bind(form));
876
+ });
877
+ }
878
+ if (injectValidators) {
879
+ validators.push(...injectValidators);
880
+ }
881
+ return validators;
882
+ }
883
+ /**
884
+ * Coerce to the form state for the specified controlId. If none form state is
885
+ * found the default form state will be returned.
886
+ *
887
+ * @param controlId A control id
888
+ * @param defaultFormState The default form state
889
+ * @param builderFormState The form state provides as build state parameter
890
+ * @param optionsFormState The form state set by the decorator in the form definition
891
+ */
892
+ coerceToControlFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
893
+ let formState = defaultFormState;
894
+ if (builderFormState && builderFormState[controlId] !== undefined) {
895
+ formState = builderFormState[controlId];
896
+ }
897
+ else if (optionsFormState !== undefined) {
898
+ formState = optionsFormState !== null && optionsFormState !== void 0 ? optionsFormState : null;
899
+ }
900
+ if (typeof formState === 'function') {
901
+ formState = formState();
902
+ }
903
+ return formState;
904
+ }
905
+ /**
906
+ * Coerce to the form state for the specified controlId. If none form state is
907
+ * found the default form state will be returned.
908
+ *
909
+ * The difference to the method coerceToControlFormState is that null will be
910
+ * handled as undefined and the defaultFormState is used
911
+ *
912
+ * @param controlId A control id
913
+ * @param defaultFormState The default form state
914
+ * @param builderFormState The form state provides as build state parameter
915
+ * @param optionsFormState The form state set by the decorator in the form definition
916
+ */
917
+ coerceToGroupFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
918
+ let formState = defaultFormState;
919
+ if (builderFormState && builderFormState[controlId]) {
920
+ formState = builderFormState[controlId];
921
+ }
922
+ else if (optionsFormState) {
923
+ formState = optionsFormState;
924
+ }
925
+ if (typeof formState === 'function') {
926
+ formState = formState();
927
+ if (!formState) {
928
+ throw new Error(`The form state function for the form group '${controlId}' returns a empty value (null/undefined)`);
929
+ }
930
+ if (typeof formState !== 'object') {
931
+ throw new Error(`The form state function for the form group '${controlId}' returns a non object like value instead '${typeof formState}'`);
932
+ }
933
+ }
934
+ return formState;
935
+ }
936
+ /**
937
+ * Coerce to the form state for the specified controlId. If none form state is
938
+ * found the default form state will be returned.
939
+ *
940
+ * The difference to the method coerceToControlFormState is that null will be
941
+ * handled as undefined and the defaultFormState is used
942
+ *
943
+ * @param controlId A control id
944
+ * @param defaultFormState The default form state
945
+ * @param builderFormState The form state provides as build state parameter
946
+ * @param optionsFormState The form state set by the decorator in the form definition
947
+ */
948
+ coerceToArrayFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
949
+ let formState = defaultFormState;
950
+ if (builderFormState && builderFormState[controlId] && Array.isArray(builderFormState[controlId])) {
951
+ formState = builderFormState[controlId];
952
+ }
953
+ else if (optionsFormState && Array.isArray(optionsFormState)) {
954
+ formState = optionsFormState;
955
+ }
956
+ if (typeof formState === 'function') {
957
+ formState = formState();
958
+ if (!formState) {
959
+ throw new Error(`The form state function for the form array '${controlId}' returns a empty value (null/undefined)`);
960
+ }
961
+ if (!Array.isArray(formState)) {
962
+ throw new Error(`The form state function for the form array '${controlId}' returns a non array like value instead '${typeof formState}'`);
963
+ }
964
+ }
965
+ return formState;
966
+ }
967
+ extractControlChanges() {
968
+ var _a;
969
+ return ((_a = getMetadata(MetadataKeys.CONTROL_CHANGES, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
970
+ }
971
+ extractControlSetValue() {
972
+ var _a;
973
+ return ((_a = getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
974
+ }
975
+ extractValidators() {
976
+ var _a;
977
+ return ((_a = getMetadata(MetadataKeys.CONTROL_VALIDATORS, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
978
+ }
979
+ extractAsyncValidators() {
980
+ var _a;
981
+ return ((_a = getMetadata(MetadataKeys.CONTROL_ASYNC_VALIDATORS, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
982
+ }
983
+ extractArrayGroups() {
984
+ var _a;
985
+ return ((_a = getMetadata(MetadataKeys.FORM_ARRAY_GROUPS, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
986
+ }
987
+ extractArrayControls() {
988
+ var _a;
989
+ return ((_a = getMetadata(MetadataKeys.FORM_ARRAY_CONTROLS, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
990
+ }
991
+ extractGroups() {
992
+ var _a;
993
+ return ((_a = getMetadata(MetadataKeys.FORM_GROUPS, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
994
+ }
995
+ extractControls() {
996
+ var _a;
997
+ return ((_a = getMetadata(MetadataKeys.FORM_CONTROLS, this.definition.prototype)) !== null && _a !== void 0 ? _a : new Map());
998
+ }
999
+ extractFormOptions() {
1000
+ const options = GetDefinitionMetadata(this.definition);
1001
+ if (!options || !options.hasOwnProperty('id')) {
1002
+ throw new Error('Ensure that the @UseForm decorator is used.');
1003
+ }
1004
+ if (!options.providers) {
1005
+ options.providers = [];
1006
+ }
1007
+ return options;
1008
+ }
1009
+ }
1010
+
1011
+ class ControlValueAccessor {
1012
+ constructor() {
1013
+ this.onChange = (value) => { };
1014
+ this.onTouched = () => { };
1015
+ this.setDisabledState = (isDisabled) => { };
1016
+ }
1017
+ registerOnChange(fn) {
1018
+ this.onChange = fn;
1019
+ }
1020
+ registerOnTouched(fn) {
1021
+ this.onTouched = fn;
1022
+ }
1023
+ }
1024
+
1025
+ const RXAP_FORM_INITIAL_STATE = new InjectionToken('rxap/forms/initial-state');
1026
+ const RXAP_FORM_CONTEXT = new InjectionToken('rxap/forms/context');
1027
+
1028
+ function ControlAsyncValidator(...controlIds) {
1029
+ return function (target, propertyKey) {
1030
+ for (const controlId of controlIds) {
1031
+ setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_ASYNC_VALIDATORS, target);
1032
+ }
1033
+ };
1034
+ }
1035
+
1036
+ function ControlChange(...controlIds) {
1037
+ return function (target, propertyKey) {
1038
+ for (const controlId of controlIds) {
1039
+ setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_CHANGES, target);
1040
+ }
1041
+ };
1042
+ }
1043
+
1044
+ function ControlSetValue(controlId, options = {}) {
1045
+ return function (target, propertyKey) {
1046
+ setMetadataMapSet(controlId, Object.assign(Object.assign({}, options), { propertyKey }), MetadataKeys.CONTROL_SET_VALUE, target);
1047
+ };
1048
+ }
1049
+
1050
+ function ControlValidator(...controlIds) {
1051
+ return function (target, propertyKey) {
1052
+ for (const controlId of controlIds) {
1053
+ setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_VALIDATORS, target);
1054
+ }
1055
+ };
1056
+ }
1057
+
1058
+ function UseFormArrayGroup(definition, options = {}) {
1059
+ return function (target, propertyKey) {
1060
+ setMetadataMap(propertyKey, Object.assign(Object.assign({}, options), { definition }), MetadataKeys.FORM_ARRAY_GROUPS, target);
1061
+ };
1062
+ }
1063
+ function UseFormArrayControl(options = {}) {
1064
+ return function (target, propertyKey) {
1065
+ setMetadataMap(propertyKey, options, MetadataKeys.FORM_ARRAY_CONTROLS, target);
1066
+ };
1067
+ }
1068
+
1069
+ function UseFormControl(options = {}) {
1070
+ return function (target, propertyKey) {
1071
+ setMetadataMap(propertyKey, options, MetadataKeys.FORM_CONTROLS, target);
1072
+ };
1073
+ }
1074
+
1075
+ function UseFormGroup(definition, options = {}) {
1076
+ return function (target, propertyKey) {
1077
+ setMetadataMap(propertyKey, Object.assign(Object.assign({}, options), { definition }), MetadataKeys.FORM_GROUPS, target);
1078
+ };
1079
+ }
1080
+
1081
+ function RxapForm(optionsOrId, className = 'FormDefinition', packageName = '@rxap/forms') {
1082
+ return function (target) {
1083
+ DefinitionMetadata(optionsOrId, className, packageName)(target);
1084
+ };
1085
+ }
1086
+
1087
+ const RXAP_FORM_DEFINITION = new InjectionToken('rxap/forms/definition');
1088
+ const RXAP_FORM_DEFINITION_BUILDER = new InjectionToken('rxap/forms/definition-builder');
1089
+ const RXAP_FORM_SUBMIT_METHOD = new InjectionToken('rxap/form/submit-method');
1090
+ const RXAP_FORM_SUBMIT_FAILED_METHOD = new InjectionToken('rxap/form/submit-failed-method');
1091
+ const RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD = new InjectionToken('rxap/form/submit-successful-method');
1092
+ const RXAP_FORM_LOAD_METHOD = new InjectionToken('rxap/form/load-method');
1093
+ const RXAP_FORM_LOAD_FAILED_METHOD = new InjectionToken('rxap/form/load-failed-method');
1094
+ const RXAP_FORM_LOAD_SUCCESSFUL_METHOD = new InjectionToken('rxap/form/load-successful-method');
1095
+
1096
+ class FormDirective extends FormGroupDirective {
1097
+ constructor(cdr, formDefinition = null,
1098
+ // skip self, bc the token is set to null
1099
+ submitMethod = null,
1100
+ // skip self, bc the token is set to null
1101
+ loadMethod = null,
1102
+ // skip self, bc the token is set to null
1103
+ loadFailedMethod = null,
1104
+ // skip self, bc the token is set to null
1105
+ loadSuccessfulMethod = null,
1106
+ // skip self, bc the token is set to null
1107
+ submitFailedMethod = null,
1108
+ // skip self, bc the token is set to null
1109
+ submitSuccessfulMethod = null,
1110
+ // skip self, bc the token is set to null
1111
+ formDefinitionBuilder = null, loadingIndicatorService = null) {
1112
+ var _a, _b;
1113
+ super([], []);
1114
+ this.cdr = cdr;
1115
+ this.loadMethod = loadMethod;
1116
+ this.loadFailedMethod = loadFailedMethod;
1117
+ this.loadSuccessfulMethod = loadSuccessfulMethod;
1118
+ this.submitFailedMethod = submitFailedMethod;
1119
+ this.submitSuccessfulMethod = submitSuccessfulMethod;
1120
+ this.formDefinitionBuilder = formDefinitionBuilder;
1121
+ this.loadingIndicatorService = loadingIndicatorService;
1122
+ /**
1123
+ * Emits when the submit method is executed without errors. The result of the
1124
+ * submit method is passed as event object.
1125
+ *
1126
+ * If no submit method is defined then emit after the submit button
1127
+ * is clicked.
1128
+ */
1129
+ this.rxapSubmit = new EventEmitter();
1130
+ this.invalidSubmit = new EventEmitter();
1131
+ this.submitSuccessful$ = new EventEmitter();
1132
+ this.submitting$ = new ToggleSubject();
1133
+ this.submitError$ = new BehaviorSubject(null);
1134
+ this.loading$ = new ToggleSubject();
1135
+ this.loaded$ = new ToggleSubject();
1136
+ this.loadingError$ = new BehaviorSubject(null);
1137
+ this.submitMethod = null;
1138
+ this._autoSubmitSubscription = new Subscription();
1139
+ if (submitMethod) {
1140
+ this.submitMethod = submitMethod;
1141
+ }
1142
+ if (!formDefinition && formDefinitionBuilder) {
1143
+ formDefinition = formDefinitionBuilder.build();
1144
+ }
1145
+ if (formDefinition) {
1146
+ this._formDefinition = formDefinition;
1147
+ this.form = formDefinition.rxapFormGroup;
1148
+ }
1149
+ (_a = this.loadingIndicatorService) === null || _a === void 0 ? void 0 : _a.attachLoading(this.loading$);
1150
+ (_b = this.loadingIndicatorService) === null || _b === void 0 ? void 0 : _b.attachLoading(this.submitting$);
1151
+ }
1152
+ get submitting() {
1153
+ return this.submitting$.value;
1154
+ }
1155
+ get submitError() {
1156
+ return this.submitError$.value;
1157
+ }
1158
+ get loading() {
1159
+ return this.loading$.value;
1160
+ }
1161
+ get loaded() {
1162
+ return this.loaded$.value;
1163
+ }
1164
+ get loadingError() {
1165
+ return this.loadingError$.value;
1166
+ }
1167
+ set useFormDefinition(value) {
1168
+ if (value) {
1169
+ this._formDefinition = value;
1170
+ this.form = value.rxapFormGroup;
1171
+ }
1172
+ }
1173
+ get formDefinition() {
1174
+ return this._formDefinition;
1175
+ }
1176
+ ngOnChanges(changes) {
1177
+ super.ngOnChanges(changes);
1178
+ const formChange = changes.form;
1179
+ if (formChange && !formChange.firstChange) {
1180
+ this.loadInitialState(formChange.currentValue);
1181
+ }
1182
+ }
1183
+ ngOnInit() {
1184
+ if (!this.form) {
1185
+ // TODO : replace with rxap error
1186
+ throw new Error('The form definition instance is not defined');
1187
+ }
1188
+ this.loadInitialState(this.form);
1189
+ function HasNgOnInitMethod(obj) {
1190
+ return obj && typeof obj.ngOnInit === 'function';
1191
+ }
1192
+ if (HasNgOnInitMethod(this._formDefinition)) {
1193
+ this._formDefinition.ngOnInit();
1194
+ }
1195
+ if (this._formDefinition.rxapMetadata.autoSubmit) {
1196
+ const debounce = typeof this._formDefinition.rxapMetadata.autoSubmit === 'number'
1197
+ ? this._formDefinition.rxapMetadata.autoSubmit
1198
+ : 5000;
1199
+ this._autoSubmitSubscription = this.form.valueChanges
1200
+ .pipe(debounceTime(debounce), filter(() => this.form.valid), tap((value) => console.debug(`Auto submit form '${this._formDefinition.rxapMetadata.id}'`, value)), tap(() => this.submit()))
1201
+ .subscribe();
1202
+ }
1203
+ }
1204
+ onSubmit($event) {
1205
+ $event.preventDefault();
1206
+ super.onSubmit($event);
1207
+ if (this.form.valid) {
1208
+ this.submit();
1209
+ }
1210
+ else {
1211
+ function reduceErrors(control, errors = {}) {
1212
+ if (control.invalid) {
1213
+ if (control.controls) {
1214
+ if (Array.isArray(control.controls)) {
1215
+ const errorList = [];
1216
+ for (const item of control.controls) {
1217
+ errorList.push(reduceErrors(item));
1218
+ }
1219
+ errors[control.controlId] = errorList;
1220
+ }
1221
+ else {
1222
+ const innerErrors = {};
1223
+ for (const child of Object.values(control.controls)) {
1224
+ reduceErrors(child, innerErrors);
1225
+ }
1226
+ errors[control.controlId] = innerErrors;
1227
+ }
1228
+ }
1229
+ else {
1230
+ if (control.errors) {
1231
+ errors[control.controlId] = control.errors;
1232
+ }
1233
+ }
1234
+ }
1235
+ return errors;
1236
+ }
1237
+ if (isDevMode()) {
1238
+ console.log('Form submit is not valid for: ' + this.form.controlId, this.form.errors);
1239
+ function printErrorControls(control) {
1240
+ if (!control.valid) {
1241
+ console.group(control.controlId);
1242
+ if (control.controls) {
1243
+ if (Array.isArray(control.controls)) {
1244
+ for (let i = 0; i < control.controls.length; i++) {
1245
+ const child = control.controls[i];
1246
+ if (!child.valid) {
1247
+ console.group(`index: ${i}`);
1248
+ printErrorControls(child);
1249
+ console.groupEnd();
1250
+ }
1251
+ }
1252
+ }
1253
+ else {
1254
+ for (const child of Object.values(control.controls)) {
1255
+ printErrorControls(child);
1256
+ }
1257
+ }
1258
+ }
1259
+ else {
1260
+ if (control.errors) {
1261
+ for (const [key, value] of Object.entries(control.errors)) {
1262
+ console.group(key);
1263
+ console.log(value);
1264
+ console.groupEnd();
1265
+ }
1266
+ }
1267
+ console.log('value: ', control.value);
1268
+ }
1269
+ console.groupEnd();
1270
+ }
1271
+ }
1272
+ printErrorControls(this.form);
1273
+ }
1274
+ this.invalidSubmit.emit(reduceErrors(this.form));
1275
+ }
1276
+ return false;
1277
+ }
1278
+ loadInitialState(form) {
1279
+ if (this.initial) {
1280
+ if (isDevMode()) {
1281
+ console.log('use the value from input initial');
1282
+ }
1283
+ form.patchValue(this.initial);
1284
+ }
1285
+ else {
1286
+ if (this.loadMethod) {
1287
+ this.loading$.enable();
1288
+ try {
1289
+ const resultOrPromise = this.loadMethod.call();
1290
+ if (isPromise(resultOrPromise)) {
1291
+ resultOrPromise
1292
+ .then((value) => {
1293
+ form.patchValue(value);
1294
+ this.loaded$.enable();
1295
+ this.loadSuccessful(value);
1296
+ })
1297
+ .catch((error) => {
1298
+ this.loadingError$.next(error);
1299
+ this.loadFailed(error);
1300
+ })
1301
+ .finally(() => {
1302
+ this.loading$.disable();
1303
+ this.cdr.detectChanges();
1304
+ });
1305
+ }
1306
+ else if (isObject(resultOrPromise)) {
1307
+ form.patchValue(resultOrPromise);
1308
+ this.loaded$.enable();
1309
+ this.loadSuccessful(resultOrPromise);
1310
+ this.loading$.disable();
1311
+ }
1312
+ }
1313
+ catch (error) {
1314
+ this.loaded$.disable();
1315
+ this.loadingError$.next(error);
1316
+ this.loadFailed(error);
1317
+ this.loading$.disable();
1318
+ }
1319
+ }
1320
+ else {
1321
+ if (isDevMode()) {
1322
+ console.warn('The form loading method is not defined for: ' + this.form.controlId);
1323
+ }
1324
+ this.loaded$.enable();
1325
+ }
1326
+ }
1327
+ }
1328
+ loadSuccessful(value) {
1329
+ if (this.loadSuccessfulMethod) {
1330
+ this.loadSuccessfulMethod.call(value);
1331
+ }
1332
+ else if (isDevMode()) {
1333
+ console.warn('The load successful is not defined for: ' + this.form.controlId);
1334
+ }
1335
+ }
1336
+ loadFailed(error) {
1337
+ var _a;
1338
+ console.debug('Load Error:', error);
1339
+ console.error('Load Error:', error.message);
1340
+ if (this.loadFailedMethod) {
1341
+ (_a = this.loadFailedMethod) === null || _a === void 0 ? void 0 : _a.call(error);
1342
+ }
1343
+ else if (isDevMode()) {
1344
+ console.warn('The form loading failed for: ' + this.form.controlId);
1345
+ }
1346
+ }
1347
+ getSubmitValue() {
1348
+ let value = undefined;
1349
+ if (typeof this._formDefinition['getSubmitValue'] === 'function') {
1350
+ value = this._formDefinition.getSubmitValue();
1351
+ }
1352
+ else if (typeof this._formDefinition['toJSON'] === 'function') {
1353
+ value = this._formDefinition.toJSON();
1354
+ }
1355
+ value = value !== null && value !== void 0 ? value : this.form.value;
1356
+ return clone(value);
1357
+ }
1358
+ submit() {
1359
+ const value = this.getSubmitValue();
1360
+ if (this.submitMethod) {
1361
+ Reflect.set(this, 'submitted', false);
1362
+ this.submitting$.enable();
1363
+ this.submitError$.next(null);
1364
+ try {
1365
+ const resultOrPromise = this.submitMethod.call(value);
1366
+ if (isPromise(resultOrPromise)) {
1367
+ resultOrPromise
1368
+ .then((result) => {
1369
+ Reflect.set(this, 'submitted', true);
1370
+ this.rxapSubmit.emit(result);
1371
+ this.submitSuccessful(result);
1372
+ })
1373
+ .catch((error) => {
1374
+ this.submitError$.next(error);
1375
+ this.submitFailed(error);
1376
+ })
1377
+ .finally(() => {
1378
+ this.submitting$.disable();
1379
+ this.cdr.detectChanges();
1380
+ });
1381
+ }
1382
+ else {
1383
+ Reflect.set(this, 'submitted', true);
1384
+ this.rxapSubmit.emit(resultOrPromise);
1385
+ this.submitSuccessful(resultOrPromise);
1386
+ this.submitting$.disable();
1387
+ }
1388
+ }
1389
+ catch (error) {
1390
+ this.submitting$.disable();
1391
+ this.submitError$.next(error);
1392
+ this.submitFailed(error);
1393
+ }
1394
+ }
1395
+ else {
1396
+ if (isDevMode()) {
1397
+ console.warn('The form submit method is not defined for: ' + this.form.controlId);
1398
+ }
1399
+ this.rxapSubmit.emit(value);
1400
+ this.submitSuccessful(value);
1401
+ }
1402
+ }
1403
+ submitFailed(error) {
1404
+ console.debug('Submit Error:', error);
1405
+ console.error('Submit Error:', error.message);
1406
+ if (this.submitFailedMethod) {
1407
+ this.submitFailedMethod.call(error);
1408
+ }
1409
+ else if (isDevMode()) {
1410
+ console.warn('The form submit failed method is not defined for: ' +
1411
+ this.form.controlId);
1412
+ }
1413
+ }
1414
+ submitSuccessful(value) {
1415
+ this.submitSuccessful$.next(value);
1416
+ if (this.submitSuccessfulMethod) {
1417
+ this.submitSuccessfulMethod.call(value);
1418
+ }
1419
+ else if (isDevMode()) {
1420
+ console.warn('The form submit successful method is not defined for: ' +
1421
+ this.form.controlId);
1422
+ }
1423
+ }
1424
+ ngOnDestroy() {
1425
+ var _a;
1426
+ super.ngOnDestroy();
1427
+ (_a = this._autoSubmitSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1428
+ function HasNgOnDestroyMethod(obj) {
1429
+ return obj && typeof obj.ngOnDestroy === 'function';
1430
+ }
1431
+ if (HasNgOnDestroyMethod(this._formDefinition)) {
1432
+ this._formDefinition.ngOnDestroy();
1433
+ }
1434
+ }
1435
+ }
1436
+ FormDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormDirective, deps: [{ token: ChangeDetectorRef }, { token: RXAP_FORM_DEFINITION, optional: true }, { token: RXAP_FORM_SUBMIT_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_LOAD_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_LOAD_FAILED_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_LOAD_SUCCESSFUL_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_SUBMIT_FAILED_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_DEFINITION_BUILDER, optional: true, skipSelf: true }, { token: LoadingIndicatorService, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
1437
+ FormDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormDirective, selector: "form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]", inputs: { initial: "initial", useFormDefinition: ["rxapForm", "useFormDefinition"], submitMethod: "submitMethod" }, outputs: { ngSubmit: "ngSubmit", rxapSubmit: "rxapSubmit", invalidSubmit: "invalidSubmit", submitSuccessful$: "submitSuccessful" }, host: { listeners: { "reset": "onReset()" }, properties: { "class.rxap-submitting": "this.submitting", "class.rxap-submit-error": "this.submitError", "class.rxap-loading": "this.loading", "class.rxap-loaded": "this.loaded", "class.rxap-loading-error": "this.loadingError" } }, providers: [
1438
+ {
1439
+ provide: ControlContainer,
1440
+ // ignore coverage
1441
+ useExisting: forwardRef(() => FormDirective)
1442
+ },
1443
+ // region form provider clear
1444
+ // form provider that are directly associated with the current form
1445
+ // are cleared to prevent that inner forms can access this providers
1446
+ // Example: The parent form has a submit method provider and the inner should
1447
+ // not have a submit method provider. If the parent submit method provider is
1448
+ // not cleared then the inner form uses the parent submit method provider on
1449
+ // submit
1450
+ {
1451
+ provide: RXAP_FORM_SUBMIT_METHOD,
1452
+ useValue: null,
1453
+ },
1454
+ {
1455
+ provide: RXAP_FORM_LOAD_METHOD,
1456
+ useValue: null,
1457
+ },
1458
+ {
1459
+ provide: RXAP_FORM_LOAD_FAILED_METHOD,
1460
+ useValue: null,
1461
+ },
1462
+ {
1463
+ provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
1464
+ useValue: null,
1465
+ },
1466
+ {
1467
+ provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
1468
+ useValue: null,
1469
+ },
1470
+ {
1471
+ provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
1472
+ useValue: null,
1473
+ },
1474
+ {
1475
+ provide: RXAP_FORM_DEFINITION_BUILDER,
1476
+ useValue: null,
1477
+ },
1478
+ // endregion
1479
+ ], exportAs: ["rxapForm"], usesInheritance: true, usesOnChanges: true, ngImport: i0 });
1480
+ __decorate([
1481
+ Required,
1482
+ __metadata("design:type", Object)
1483
+ ], FormDirective.prototype, "_formDefinition", void 0);
1484
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormDirective, decorators: [{
1485
+ type: Directive,
1486
+ args: [{
1487
+ selector: 'form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]',
1488
+ providers: [
1489
+ {
1490
+ provide: ControlContainer,
1491
+ // ignore coverage
1492
+ useExisting: forwardRef(() => FormDirective)
1493
+ },
1494
+ // region form provider clear
1495
+ // form provider that are directly associated with the current form
1496
+ // are cleared to prevent that inner forms can access this providers
1497
+ // Example: The parent form has a submit method provider and the inner should
1498
+ // not have a submit method provider. If the parent submit method provider is
1499
+ // not cleared then the inner form uses the parent submit method provider on
1500
+ // submit
1501
+ {
1502
+ provide: RXAP_FORM_SUBMIT_METHOD,
1503
+ useValue: null,
1504
+ },
1505
+ {
1506
+ provide: RXAP_FORM_LOAD_METHOD,
1507
+ useValue: null,
1508
+ },
1509
+ {
1510
+ provide: RXAP_FORM_LOAD_FAILED_METHOD,
1511
+ useValue: null,
1512
+ },
1513
+ {
1514
+ provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
1515
+ useValue: null,
1516
+ },
1517
+ {
1518
+ provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
1519
+ useValue: null,
1520
+ },
1521
+ {
1522
+ provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
1523
+ useValue: null,
1524
+ },
1525
+ {
1526
+ provide: RXAP_FORM_DEFINITION_BUILDER,
1527
+ useValue: null,
1528
+ },
1529
+ // endregion
1530
+ ],
1531
+ host: { '(reset)': 'onReset()' },
1532
+ outputs: ['ngSubmit'],
1533
+ exportAs: 'rxapForm',
1534
+ }]
1535
+ }], ctorParameters: function () {
1536
+ return [{ type: i0.ChangeDetectorRef, decorators: [{
1537
+ type: Inject,
1538
+ args: [ChangeDetectorRef]
1539
+ }] }, { type: undefined, decorators: [{
1540
+ type: Optional
1541
+ }, {
1542
+ type: Inject,
1543
+ args: [RXAP_FORM_DEFINITION]
1544
+ }] }, { type: undefined, decorators: [{
1545
+ type: SkipSelf
1546
+ }, {
1547
+ type: Optional
1548
+ }, {
1549
+ type: Inject,
1550
+ args: [RXAP_FORM_SUBMIT_METHOD]
1551
+ }] }, { type: undefined, decorators: [{
1552
+ type: SkipSelf
1553
+ }, {
1554
+ type: Optional
1555
+ }, {
1556
+ type: Inject,
1557
+ args: [RXAP_FORM_LOAD_METHOD]
1558
+ }] }, { type: undefined, decorators: [{
1559
+ type: SkipSelf
1560
+ }, {
1561
+ type: Optional
1562
+ }, {
1563
+ type: Inject,
1564
+ args: [RXAP_FORM_LOAD_FAILED_METHOD]
1565
+ }] }, { type: undefined, decorators: [{
1566
+ type: SkipSelf
1567
+ }, {
1568
+ type: Optional
1569
+ }, {
1570
+ type: Inject,
1571
+ args: [RXAP_FORM_LOAD_SUCCESSFUL_METHOD]
1572
+ }] }, { type: undefined, decorators: [{
1573
+ type: SkipSelf
1574
+ }, {
1575
+ type: Optional
1576
+ }, {
1577
+ type: Inject,
1578
+ args: [RXAP_FORM_SUBMIT_FAILED_METHOD]
1579
+ }] }, { type: undefined, decorators: [{
1580
+ type: SkipSelf
1581
+ }, {
1582
+ type: Optional
1583
+ }, {
1584
+ type: Inject,
1585
+ args: [RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD]
1586
+ }] }, { type: RxapFormBuilder, decorators: [{
1587
+ type: SkipSelf
1588
+ }, {
1589
+ type: Optional
1590
+ }, {
1591
+ type: Inject,
1592
+ args: [RXAP_FORM_DEFINITION_BUILDER]
1593
+ }] }, { type: i2.LoadingIndicatorService, decorators: [{
1594
+ type: Optional
1595
+ }, {
1596
+ type: Inject,
1597
+ args: [LoadingIndicatorService]
1598
+ }] }];
1599
+ }, propDecorators: { initial: [{
1600
+ type: Input
1601
+ }], rxapSubmit: [{
1602
+ type: Output
1603
+ }], invalidSubmit: [{
1604
+ type: Output
1605
+ }], submitSuccessful$: [{
1606
+ type: Output,
1607
+ args: ['submitSuccessful']
1608
+ }], submitting: [{
1609
+ type: HostBinding,
1610
+ args: ['class.rxap-submitting']
1611
+ }], submitError: [{
1612
+ type: HostBinding,
1613
+ args: ['class.rxap-submit-error']
1614
+ }], loading: [{
1615
+ type: HostBinding,
1616
+ args: ['class.rxap-loading']
1617
+ }], loaded: [{
1618
+ type: HostBinding,
1619
+ args: ['class.rxap-loaded']
1620
+ }], loadingError: [{
1621
+ type: HostBinding,
1622
+ args: ['class.rxap-loading-error']
1623
+ }], useFormDefinition: [{
1624
+ type: Input,
1625
+ args: ['rxapForm']
1626
+ }], _formDefinition: [], submitMethod: [{
1627
+ type: Input
1628
+ }] } });
1629
+
1630
+ class FormSubmitFailedDirective {
1631
+ constructor(formDirective, template, viewContainerRef) {
1632
+ this.formDirective = formDirective;
1633
+ this.template = template;
1634
+ this.viewContainerRef = viewContainerRef;
1635
+ }
1636
+ ngAfterViewInit() {
1637
+ this.subscription = this.formDirective.submitError$.pipe(tap(error => {
1638
+ this.viewContainerRef.clear();
1639
+ if (error !== null) {
1640
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
1641
+ }
1642
+ })).subscribe();
1643
+ }
1644
+ ngOnDestroy() {
1645
+ var _a;
1646
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1647
+ }
1648
+ }
1649
+ FormSubmitFailedDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitFailedDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
1650
+ FormSubmitFailedDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmitFailedDirective, selector: "[rxapFormSubmitFailed]", ngImport: i0 });
1651
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitFailedDirective, decorators: [{
1652
+ type: Directive,
1653
+ args: [{
1654
+ selector: '[rxapFormSubmitFailed]'
1655
+ }]
1656
+ }], ctorParameters: function () {
1657
+ return [{ type: FormDirective, decorators: [{
1658
+ type: Inject,
1659
+ args: [FormDirective]
1660
+ }] }, { type: i0.TemplateRef, decorators: [{
1661
+ type: Inject,
1662
+ args: [TemplateRef]
1663
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1664
+ type: Inject,
1665
+ args: [ViewContainerRef]
1666
+ }] }];
1667
+ } });
1668
+
1669
+ class FormLoadingDirective {
1670
+ constructor(formDirective, template, viewContainerRef) {
1671
+ this.formDirective = formDirective;
1672
+ this.template = template;
1673
+ this.viewContainerRef = viewContainerRef;
1674
+ }
1675
+ ngAfterViewInit() {
1676
+ this.subscription = this.formDirective.loading$.pipe(distinctUntilChanged(), tap(loading => {
1677
+ this.viewContainerRef.clear();
1678
+ if (loading) {
1679
+ this.viewContainerRef.createEmbeddedView(this.template);
1680
+ }
1681
+ })).subscribe();
1682
+ }
1683
+ ngOnDestroy() {
1684
+ var _a;
1685
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1686
+ }
1687
+ }
1688
+ FormLoadingDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormLoadingDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
1689
+ FormLoadingDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormLoadingDirective, selector: "[rxapFormLoading]", ngImport: i0 });
1690
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormLoadingDirective, decorators: [{
1691
+ type: Directive,
1692
+ args: [{
1693
+ selector: '[rxapFormLoading]'
1694
+ }]
1695
+ }], ctorParameters: function () {
1696
+ return [{ type: FormDirective, decorators: [{
1697
+ type: Inject,
1698
+ args: [FormDirective]
1699
+ }] }, { type: i0.TemplateRef, decorators: [{
1700
+ type: Inject,
1701
+ args: [TemplateRef]
1702
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1703
+ type: Inject,
1704
+ args: [ViewContainerRef]
1705
+ }] }];
1706
+ } });
1707
+
1708
+ class FormSubmittingDirective {
1709
+ constructor(formDirective, template, viewContainerRef) {
1710
+ this.formDirective = formDirective;
1711
+ this.template = template;
1712
+ this.viewContainerRef = viewContainerRef;
1713
+ }
1714
+ ngAfterViewInit() {
1715
+ this.subscription = this.formDirective.submitting$.pipe(distinctUntilChanged(), tap(loading => {
1716
+ this.viewContainerRef.clear();
1717
+ if (loading) {
1718
+ this.viewContainerRef.createEmbeddedView(this.template);
1719
+ }
1720
+ })).subscribe();
1721
+ }
1722
+ ngOnDestroy() {
1723
+ var _a;
1724
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1725
+ }
1726
+ }
1727
+ FormSubmittingDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmittingDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
1728
+ FormSubmittingDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmittingDirective, selector: "[rxapFormSubmitting]", ngImport: i0 });
1729
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmittingDirective, decorators: [{
1730
+ type: Directive,
1731
+ args: [{
1732
+ selector: '[rxapFormSubmitting]'
1733
+ }]
1734
+ }], ctorParameters: function () {
1735
+ return [{ type: FormDirective, decorators: [{
1736
+ type: Inject,
1737
+ args: [FormDirective]
1738
+ }] }, { type: i0.TemplateRef, decorators: [{
1739
+ type: Inject,
1740
+ args: [TemplateRef]
1741
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1742
+ type: Inject,
1743
+ args: [ViewContainerRef]
1744
+ }] }];
1745
+ } });
1746
+
1747
+ class FormLoadedDirective {
1748
+ constructor(formDirective, template, viewContainerRef) {
1749
+ this.formDirective = formDirective;
1750
+ this.template = template;
1751
+ this.viewContainerRef = viewContainerRef;
1752
+ }
1753
+ ngAfterViewInit() {
1754
+ this.subscription = this.formDirective.loaded$.pipe(distinctUntilChanged(), tap(loading => {
1755
+ this.viewContainerRef.clear();
1756
+ if (loading) {
1757
+ this.viewContainerRef.createEmbeddedView(this.template);
1758
+ }
1759
+ })).subscribe();
1760
+ }
1761
+ ngOnDestroy() {
1762
+ var _a;
1763
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1764
+ }
1765
+ }
1766
+ FormLoadedDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormLoadedDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
1767
+ FormLoadedDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormLoadedDirective, selector: "[rxapFormLoaded]", ngImport: i0 });
1768
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormLoadedDirective, decorators: [{
1769
+ type: Directive,
1770
+ args: [{
1771
+ selector: '[rxapFormLoaded]'
1772
+ }]
1773
+ }], ctorParameters: function () {
1774
+ return [{ type: FormDirective, decorators: [{
1775
+ type: Inject,
1776
+ args: [FormDirective]
1777
+ }] }, { type: i0.TemplateRef, decorators: [{
1778
+ type: Inject,
1779
+ args: [TemplateRef]
1780
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1781
+ type: Inject,
1782
+ args: [ViewContainerRef]
1783
+ }] }];
1784
+ } });
1785
+
1786
+ class FormLoadingErrorDirective {
1787
+ constructor(formDirective, template, viewContainerRef) {
1788
+ this.formDirective = formDirective;
1789
+ this.template = template;
1790
+ this.viewContainerRef = viewContainerRef;
1791
+ }
1792
+ ngAfterViewInit() {
1793
+ this.subscription = this.formDirective.loadingError$.pipe(tap(error => {
1794
+ this.viewContainerRef.clear();
1795
+ if (error !== null) {
1796
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
1797
+ }
1798
+ })).subscribe();
1799
+ }
1800
+ ngOnDestroy() {
1801
+ var _a;
1802
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1803
+ }
1804
+ }
1805
+ FormLoadingErrorDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormLoadingErrorDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
1806
+ FormLoadingErrorDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormLoadingErrorDirective, selector: "[rxapFormLoadingError]", ngImport: i0 });
1807
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormLoadingErrorDirective, decorators: [{
1808
+ type: Directive,
1809
+ args: [{
1810
+ selector: '[rxapFormLoadingError]'
1811
+ }]
1812
+ }], ctorParameters: function () {
1813
+ return [{ type: FormDirective, decorators: [{
1814
+ type: Inject,
1815
+ args: [FormDirective]
1816
+ }] }, { type: i0.TemplateRef, decorators: [{
1817
+ type: Inject,
1818
+ args: [TemplateRef]
1819
+ }] }, { type: i0.ViewContainerRef, decorators: [{
1820
+ type: Inject,
1821
+ args: [ViewContainerRef]
1822
+ }] }];
1823
+ } });
1824
+
1825
+ /**
1826
+ * @deprecated removed
1827
+ */
1828
+ class FormControlErrorDirective {
1829
+ constructor(template, parent, viewContainerRef) {
1830
+ this.template = template;
1831
+ this.parent = parent;
1832
+ this.viewContainerRef = viewContainerRef;
1833
+ }
1834
+ ngOnInit() {
1835
+ var _a;
1836
+ const control = (_a = this.parent.control) === null || _a === void 0 ? void 0 : _a.get(this.name);
1837
+ if (!control) {
1838
+ throw new Error('Could not extract form control instance');
1839
+ }
1840
+ this.subscription = control.statusChanges.pipe(startWith(control.status), filter(status => status === 'INVALID'), tap(() => {
1841
+ this.viewContainerRef.clear();
1842
+ if (control.hasError(this.errorKey)) {
1843
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: control.getError(this.errorKey) });
1844
+ }
1845
+ })).subscribe();
1846
+ }
1847
+ ngOnDestroy() {
1848
+ var _a;
1849
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1850
+ }
1851
+ }
1852
+ FormControlErrorDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlErrorDirective, deps: [{ token: i0.TemplateRef }, { token: i1.ControlContainer, host: true, skipSelf: true }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
1853
+ FormControlErrorDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlErrorDirective, selector: "[rxapFormControlError]", inputs: { name: ["rxapFormControlErrorFrom", "name"], errorKey: ["rxapFormControlErrorIf", "errorKey"] }, ngImport: i0 });
1854
+ __decorate([
1855
+ Required,
1856
+ __metadata("design:type", String)
1857
+ ], FormControlErrorDirective.prototype, "name", void 0);
1858
+ __decorate([
1859
+ Required,
1860
+ __metadata("design:type", String)
1861
+ ], FormControlErrorDirective.prototype, "errorKey", void 0);
1862
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlErrorDirective, decorators: [{
1863
+ type: Directive,
1864
+ args: [{
1865
+ selector: '[rxapFormControlError]'
1866
+ }]
1867
+ }], ctorParameters: function () {
1868
+ return [{ type: i0.TemplateRef }, { type: i1.ControlContainer, decorators: [{
1869
+ type: Host
1870
+ }, {
1871
+ type: SkipSelf
1872
+ }] }, { type: i0.ViewContainerRef }];
1873
+ }, propDecorators: { name: [{
1874
+ type: Input,
1875
+ args: ['rxapFormControlErrorFrom']
1876
+ }], errorKey: [{
1877
+ type: Input,
1878
+ args: ['rxapFormControlErrorIf']
1879
+ }] } });
1880
+
1881
+ class FormControlMarkDirtyDirective {
1882
+ constructor(parent) {
1883
+ this.parent = parent;
1884
+ }
1885
+ onClick() {
1886
+ const control = this.parent.control;
1887
+ if (control && hasIndexSignature(control) && typeof control['markAllAsDirty'] === 'function') {
1888
+ control.markAllAsDirty();
1889
+ }
1890
+ else {
1891
+ control === null || control === void 0 ? void 0 : control.markAsDirty();
1892
+ }
1893
+ }
1894
+ }
1895
+ FormControlMarkDirtyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkDirtyDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive });
1896
+ FormControlMarkDirtyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlMarkDirtyDirective, selector: "[rxapFormControlMarkDirty]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 });
1897
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkDirtyDirective, decorators: [{
1898
+ type: Directive,
1899
+ args: [{
1900
+ selector: '[rxapFormControlMarkDirty]'
1901
+ }]
1902
+ }], ctorParameters: function () { return [{ type: i1.ControlContainer }]; }, propDecorators: { onClick: [{
1903
+ type: HostListener,
1904
+ args: ['click']
1905
+ }] } });
1906
+
1907
+ class FormControlMarkTouchedDirective {
1908
+ constructor(parent) {
1909
+ this.parent = parent;
1910
+ }
1911
+ onClick() {
1912
+ var _a;
1913
+ (_a = this.parent.control) === null || _a === void 0 ? void 0 : _a.markAllAsTouched();
1914
+ }
1915
+ }
1916
+ FormControlMarkTouchedDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkTouchedDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive });
1917
+ FormControlMarkTouchedDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlMarkTouchedDirective, selector: "[rxapFormControlMarkTouched]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 });
1918
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkTouchedDirective, decorators: [{
1919
+ type: Directive,
1920
+ args: [{
1921
+ selector: '[rxapFormControlMarkTouched]'
1922
+ }]
1923
+ }], ctorParameters: function () { return [{ type: i1.ControlContainer }]; }, propDecorators: { onClick: [{
1924
+ type: HostListener,
1925
+ args: ['click']
1926
+ }] } });
1927
+
1928
+ class FormControlMarkUntouchedDirective {
1929
+ constructor(parent) {
1930
+ this.parent = parent;
1931
+ }
1932
+ onClick() {
1933
+ const control = this.parent.control;
1934
+ if (control && hasIndexSignature(control) && typeof control['markAllAsUntouched'] === 'function') {
1935
+ control.markAllAsUntouched();
1936
+ }
1937
+ else {
1938
+ control === null || control === void 0 ? void 0 : control.markAsUntouched();
1939
+ }
1940
+ }
1941
+ }
1942
+ FormControlMarkUntouchedDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkUntouchedDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive });
1943
+ FormControlMarkUntouchedDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlMarkUntouchedDirective, selector: "[rxapFormControlMarkUntouched]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 });
1944
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkUntouchedDirective, decorators: [{
1945
+ type: Directive,
1946
+ args: [{
1947
+ selector: '[rxapFormControlMarkUntouched]'
1948
+ }]
1949
+ }], ctorParameters: function () { return [{ type: i1.ControlContainer }]; }, propDecorators: { onClick: [{
1950
+ type: HostListener,
1951
+ args: ['click']
1952
+ }] } });
1953
+
1954
+ class FormControlMarkPristineDirective {
1955
+ constructor(parent) {
1956
+ this.parent = parent;
1957
+ }
1958
+ onClick() {
1959
+ const control = this.parent.control;
1960
+ if (control && hasIndexSignature(control) && typeof control['markAllAsPristine'] === 'function') {
1961
+ control.markAllAsPristine();
1962
+ }
1963
+ else {
1964
+ control === null || control === void 0 ? void 0 : control.markAsPristine();
1965
+ }
1966
+ }
1967
+ }
1968
+ FormControlMarkPristineDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkPristineDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive });
1969
+ FormControlMarkPristineDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlMarkPristineDirective, selector: "[rxapFormControlMarkPristine]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 });
1970
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlMarkPristineDirective, decorators: [{
1971
+ type: Directive,
1972
+ args: [{
1973
+ selector: '[rxapFormControlMarkPristine]'
1974
+ }]
1975
+ }], ctorParameters: function () { return [{ type: i1.ControlContainer }]; }, propDecorators: { onClick: [{
1976
+ type: HostListener,
1977
+ args: ['click']
1978
+ }] } });
1979
+
1980
+ class FormSubmitDirective extends ConfirmClick {
1981
+ constructor(formDirective, router = null) {
1982
+ super();
1983
+ this.formDirective = formDirective;
1984
+ this.router = router;
1985
+ this.type = 'button';
1986
+ this.afterSubmit = new EventEmitter();
1987
+ this._resetAfterSubmit = false;
1988
+ }
1989
+ set resetAfterSubmit(value) {
1990
+ this._resetAfterSubmit = coerceBoolean(value);
1991
+ }
1992
+ execute() {
1993
+ this.subscription = this.formDirective.rxapSubmit.pipe(take(1), tap(event => {
1994
+ this.afterSubmit.emit(event);
1995
+ if (this._resetAfterSubmit) {
1996
+ this.formDirective.reset();
1997
+ }
1998
+ if (this.navigateAfterSubmit) {
1999
+ if (!this.router) {
2000
+ throw new Error('Could not resolve the router!');
2001
+ }
2002
+ return this.router.navigate(this.navigateAfterSubmit);
2003
+ }
2004
+ return Promise.resolve();
2005
+ })).subscribe();
2006
+ this.formDirective.onSubmit(new Event('submit'));
2007
+ }
2008
+ ngOnDestroy() {
2009
+ var _a;
2010
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2011
+ }
2012
+ }
2013
+ FormSubmitDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitDirective, deps: [{ token: FormDirective }, { token: Router, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
2014
+ FormSubmitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmitDirective, selector: "[rxapFormSubmit]", inputs: { type: "type", resetAfterSubmit: "resetAfterSubmit", navigateAfterSubmit: "navigateAfterSubmit" }, outputs: { afterSubmit: "afterSubmit" }, host: { listeners: { "click": "onClick()", "confirmed": "onConfirm()" }, properties: { "type": "this.type" } }, usesInheritance: true, ngImport: i0 });
2015
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitDirective, decorators: [{
2016
+ type: Directive,
2017
+ args: [{
2018
+ selector: '[rxapFormSubmit]',
2019
+ host: {
2020
+ '(click)': 'onClick()',
2021
+ '(confirmed)': 'onConfirm()',
2022
+ }
2023
+ }]
2024
+ }], ctorParameters: function () {
2025
+ return [{ type: FormDirective, decorators: [{
2026
+ type: Inject,
2027
+ args: [FormDirective]
2028
+ }] }, { type: i2$1.Router, decorators: [{
2029
+ type: Optional
2030
+ }, {
2031
+ type: Inject,
2032
+ args: [Router]
2033
+ }] }];
2034
+ }, propDecorators: { type: [{
2035
+ type: HostBinding,
2036
+ args: ['type']
2037
+ }, {
2038
+ type: Input
2039
+ }], resetAfterSubmit: [{
2040
+ type: Input,
2041
+ args: ['resetAfterSubmit']
2042
+ }], navigateAfterSubmit: [{
2043
+ type: Input
2044
+ }], afterSubmit: [{
2045
+ type: Output
2046
+ }] } });
2047
+
2048
+ /**
2049
+ * A full exertion of FormGroupName from @angular/forms. The only change is the
2050
+ * ability to access the control container outside of the current component
2051
+ *
2052
+ * @deprecated use the ParentControlContainerDirective
2053
+ */
2054
+ class FormGroupNameDirective extends FormGroupName {
2055
+ constructor(parent, validators, asyncValidators) {
2056
+ super(parent, validators, asyncValidators);
2057
+ }
2058
+ get control() {
2059
+ // TODO : add type check
2060
+ return this.formDirective.getFormGroup(this);
2061
+ }
2062
+ }
2063
+ FormGroupNameDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormGroupNameDirective, deps: [{ token: i1.ControlContainer, optional: true, skipSelf: true }, { token: NG_VALIDATORS, optional: true, self: true }, { token: NG_ASYNC_VALIDATORS, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
2064
+ FormGroupNameDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormGroupNameDirective, selector: "[rxapFormGroupName]", inputs: { name: ["rxapFormGroupName", "name"] }, providers: [
2065
+ {
2066
+ provide: ControlContainer,
2067
+ useExisting: forwardRef(() => FormGroupNameDirective)
2068
+ }
2069
+ ], exportAs: ["rxapFormGroup"], usesInheritance: true, ngImport: i0 });
2070
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormGroupNameDirective, decorators: [{
2071
+ type: Directive,
2072
+ args: [{
2073
+ selector: '[rxapFormGroupName]',
2074
+ providers: [
2075
+ {
2076
+ provide: ControlContainer,
2077
+ useExisting: forwardRef(() => FormGroupNameDirective)
2078
+ }
2079
+ ],
2080
+ exportAs: 'rxapFormGroup'
2081
+ }]
2082
+ }], ctorParameters: function () {
2083
+ return [{ type: i1.ControlContainer, decorators: [{
2084
+ type: Optional
2085
+ }, {
2086
+ type: SkipSelf
2087
+ }] }, { type: undefined, decorators: [{
2088
+ type: Optional
2089
+ }, {
2090
+ type: Self
2091
+ }, {
2092
+ type: Inject,
2093
+ args: [NG_VALIDATORS]
2094
+ }] }, { type: undefined, decorators: [{
2095
+ type: Optional
2096
+ }, {
2097
+ type: Self
2098
+ }, {
2099
+ type: Inject,
2100
+ args: [NG_ASYNC_VALIDATORS]
2101
+ }] }];
2102
+ }, propDecorators: { name: [{
2103
+ type: Input,
2104
+ args: ['rxapFormGroupName']
2105
+ }] } });
2106
+
2107
+ /**
2108
+ * A full exertion of FormControlName from @angular/forms. The only change is the
2109
+ * ability to access the control container outside of the current component
2110
+ *
2111
+ * @deprecated use the ParentControlContainerDirective
2112
+ */
2113
+ class FormControlNameDirective extends FormControlName {
2114
+ constructor(parent, validators, asyncValidators, valueAccessors) {
2115
+ super(parent, validators, asyncValidators, valueAccessors, null);
2116
+ }
2117
+ }
2118
+ FormControlNameDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlNameDirective, deps: [{ token: i1.ControlContainer, optional: true, skipSelf: true }, { token: NG_VALIDATORS, optional: true, self: true }, { token: NG_ASYNC_VALIDATORS, optional: true, self: true }, { token: NG_VALUE_ACCESSOR, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
2119
+ FormControlNameDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlNameDirective, selector: "[rxapFormControlName]", inputs: { name: ["rxapFormControlName", "name"] }, providers: [
2120
+ {
2121
+ provide: NgControl,
2122
+ useExisting: forwardRef(() => FormControlNameDirective)
2123
+ }
2124
+ ], exportAs: ["rxapFormControl"], usesInheritance: true, ngImport: i0 });
2125
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlNameDirective, decorators: [{
2126
+ type: Directive,
2127
+ args: [{
2128
+ selector: '[rxapFormControlName]',
2129
+ providers: [
2130
+ {
2131
+ provide: NgControl,
2132
+ useExisting: forwardRef(() => FormControlNameDirective)
2133
+ }
2134
+ ],
2135
+ exportAs: 'rxapFormControl'
2136
+ }]
2137
+ }], ctorParameters: function () {
2138
+ return [{ type: i1.ControlContainer, decorators: [{
2139
+ type: Optional
2140
+ }, {
2141
+ type: SkipSelf
2142
+ }] }, { type: Array, decorators: [{
2143
+ type: Optional
2144
+ }, {
2145
+ type: Self
2146
+ }, {
2147
+ type: Inject,
2148
+ args: [NG_VALIDATORS]
2149
+ }] }, { type: Array, decorators: [{
2150
+ type: Optional
2151
+ }, {
2152
+ type: Self
2153
+ }, {
2154
+ type: Inject,
2155
+ args: [NG_ASYNC_VALIDATORS]
2156
+ }] }, { type: undefined, decorators: [{
2157
+ type: Optional
2158
+ }, {
2159
+ type: Self
2160
+ }, {
2161
+ type: Inject,
2162
+ args: [NG_VALUE_ACCESSOR]
2163
+ }] }];
2164
+ }, propDecorators: { name: [{
2165
+ type: Input,
2166
+ args: ['rxapFormControlName']
2167
+ }] } });
2168
+
2169
+ class ParentControlContainerDirective {
2170
+ }
2171
+ ParentControlContainerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ParentControlContainerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2172
+ ParentControlContainerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ParentControlContainerDirective, selector: "[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]", providers: [
2173
+ {
2174
+ provide: ControlContainer,
2175
+ useExisting: ControlContainer
2176
+ }
2177
+ ], ngImport: i0 });
2178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ParentControlContainerDirective, decorators: [{
2179
+ type: Directive,
2180
+ args: [{
2181
+ selector: '[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]',
2182
+ providers: [
2183
+ {
2184
+ provide: ControlContainer,
2185
+ useExisting: ControlContainer
2186
+ }
2187
+ ]
2188
+ }]
2189
+ }] });
2190
+
2191
+ class FormSubmitSuccessfulDirective {
2192
+ constructor(formDirective, template, viewContainerRef) {
2193
+ this.formDirective = formDirective;
2194
+ this.template = template;
2195
+ this.viewContainerRef = viewContainerRef;
2196
+ }
2197
+ ngAfterViewInit() {
2198
+ this.subscription = this.formDirective.submitSuccessful$.pipe(tap(result => {
2199
+ this.viewContainerRef.clear();
2200
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
2201
+ })).subscribe();
2202
+ }
2203
+ ngOnDestroy() {
2204
+ var _a;
2205
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2206
+ }
2207
+ }
2208
+ FormSubmitSuccessfulDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitSuccessfulDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
2209
+ FormSubmitSuccessfulDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmitSuccessfulDirective, selector: "[rxapFormSubmitSuccessful]", ngImport: i0 });
2210
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitSuccessfulDirective, decorators: [{
2211
+ type: Directive,
2212
+ args: [{
2213
+ selector: '[rxapFormSubmitSuccessful]'
2214
+ }]
2215
+ }], ctorParameters: function () {
2216
+ return [{ type: FormDirective, decorators: [{
2217
+ type: Inject,
2218
+ args: [FormDirective]
2219
+ }] }, { type: i0.TemplateRef, decorators: [{
2220
+ type: Inject,
2221
+ args: [TemplateRef]
2222
+ }] }, { type: i0.ViewContainerRef, decorators: [{
2223
+ type: Inject,
2224
+ args: [ViewContainerRef]
2225
+ }] }];
2226
+ } });
2227
+
2228
+ class FormSubmitInvalidDirective {
2229
+ constructor(formDirective, template, viewContainerRef) {
2230
+ this.formDirective = formDirective;
2231
+ this.template = template;
2232
+ this.viewContainerRef = viewContainerRef;
2233
+ }
2234
+ ngAfterViewInit() {
2235
+ this.subscription = this.formDirective.invalidSubmit.pipe(tap(result => {
2236
+ this.viewContainerRef.clear();
2237
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
2238
+ })).subscribe();
2239
+ }
2240
+ ngOnDestroy() {
2241
+ var _a;
2242
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2243
+ }
2244
+ }
2245
+ FormSubmitInvalidDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitInvalidDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
2246
+ FormSubmitInvalidDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmitInvalidDirective, selector: "[rxapFormSubmitInvalid]", ngImport: i0 });
2247
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitInvalidDirective, decorators: [{
2248
+ type: Directive,
2249
+ args: [{
2250
+ selector: '[rxapFormSubmitInvalid]'
2251
+ }]
2252
+ }], ctorParameters: function () {
2253
+ return [{ type: FormDirective, decorators: [{
2254
+ type: Inject,
2255
+ args: [FormDirective]
2256
+ }] }, { type: i0.TemplateRef, decorators: [{
2257
+ type: Inject,
2258
+ args: [TemplateRef]
2259
+ }] }, { type: i0.ViewContainerRef, decorators: [{
2260
+ type: Inject,
2261
+ args: [ViewContainerRef]
2262
+ }] }];
2263
+ } });
2264
+
2265
+ class RxapFormsModule {
2266
+ }
2267
+ RxapFormsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2268
+ RxapFormsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule, declarations: [FormDirective,
2269
+ FormSubmitFailedDirective,
2270
+ FormLoadingDirective,
2271
+ FormSubmittingDirective,
2272
+ FormLoadingErrorDirective,
2273
+ FormLoadedDirective,
2274
+ FormControlErrorDirective,
2275
+ FormControlMarkDirtyDirective,
2276
+ FormControlMarkTouchedDirective,
2277
+ FormControlMarkUntouchedDirective,
2278
+ FormControlMarkPristineDirective,
2279
+ FormSubmitDirective,
2280
+ FormGroupNameDirective,
2281
+ FormControlNameDirective,
2282
+ ParentControlContainerDirective,
2283
+ FormSubmitSuccessfulDirective,
2284
+ FormSubmitInvalidDirective], exports: [FormDirective,
2285
+ FormSubmitFailedDirective,
2286
+ FormLoadingDirective,
2287
+ FormSubmittingDirective,
2288
+ FormLoadingErrorDirective,
2289
+ FormLoadedDirective,
2290
+ FormControlErrorDirective,
2291
+ FormControlMarkDirtyDirective,
2292
+ FormControlMarkTouchedDirective,
2293
+ FormControlMarkUntouchedDirective,
2294
+ FormControlMarkPristineDirective,
2295
+ FormSubmitDirective,
2296
+ FormGroupNameDirective,
2297
+ FormControlNameDirective,
2298
+ ParentControlContainerDirective,
2299
+ FormSubmitSuccessfulDirective,
2300
+ FormSubmitInvalidDirective] });
2301
+ RxapFormsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule });
2302
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule, decorators: [{
2303
+ type: NgModule,
2304
+ args: [{
2305
+ declarations: [
2306
+ FormDirective,
2307
+ FormSubmitFailedDirective,
2308
+ FormLoadingDirective,
2309
+ FormSubmittingDirective,
2310
+ FormLoadingErrorDirective,
2311
+ FormLoadedDirective,
2312
+ FormControlErrorDirective,
2313
+ FormControlMarkDirtyDirective,
2314
+ FormControlMarkTouchedDirective,
2315
+ FormControlMarkUntouchedDirective,
2316
+ FormControlMarkPristineDirective,
2317
+ FormSubmitDirective,
2318
+ FormGroupNameDirective,
2319
+ FormControlNameDirective,
2320
+ ParentControlContainerDirective,
2321
+ FormSubmitSuccessfulDirective,
2322
+ FormSubmitInvalidDirective,
2323
+ ],
2324
+ exports: [
2325
+ FormDirective,
2326
+ FormSubmitFailedDirective,
2327
+ FormLoadingDirective,
2328
+ FormSubmittingDirective,
2329
+ FormLoadingErrorDirective,
2330
+ FormLoadedDirective,
2331
+ FormControlErrorDirective,
2332
+ FormControlMarkDirtyDirective,
2333
+ FormControlMarkTouchedDirective,
2334
+ FormControlMarkUntouchedDirective,
2335
+ FormControlMarkPristineDirective,
2336
+ FormSubmitDirective,
2337
+ FormGroupNameDirective,
2338
+ FormControlNameDirective,
2339
+ ParentControlContainerDirective,
2340
+ FormSubmitSuccessfulDirective,
2341
+ FormSubmitInvalidDirective,
2342
+ ]
2343
+ }]
2344
+ }] });
2345
+
2346
+ function ToFormMethod(call) {
2347
+ return { call };
2348
+ }
2349
+ /**
2350
+ * @deprecated use ToFormMethod instead
2351
+ *
2352
+ * @param call the call method implementation
2353
+ */
2354
+ function ToFormSubmitMethod(call) {
2355
+ return ToFormMethod(call);
2356
+ }
2357
+
2358
+ /**
2359
+ * Checks if a given value is a number.
2360
+ */
2361
+ function isNumber(value, options = {}) {
2362
+ var _a, _b;
2363
+ if (typeof value !== 'number') {
2364
+ return false;
2365
+ }
2366
+ if (value === Infinity || value === -Infinity) {
2367
+ return (_a = options.allowInfinity) !== null && _a !== void 0 ? _a : false;
2368
+ }
2369
+ if (Number.isNaN(value)) {
2370
+ return (_b = options.allowNaN) !== null && _b !== void 0 ? _b : false;
2371
+ }
2372
+ if (options.maxDecimalPlaces !== undefined) {
2373
+ let decimalPlaces = 0;
2374
+ if (value % 1 !== 0) {
2375
+ decimalPlaces = value.toString().split('.')[1].length;
2376
+ }
2377
+ if (decimalPlaces > options.maxDecimalPlaces) {
2378
+ return false;
2379
+ }
2380
+ }
2381
+ return Number.isFinite(value);
2382
+ }
2383
+ /**
2384
+ * @deprecated use RxapValidators.isNumber() instead
2385
+ * @param control
2386
+ * @constructor
2387
+ */
2388
+ function IsNumber(control) {
2389
+ if (control.value === null) {
2390
+ return null;
2391
+ }
2392
+ if (isNaN(Number(control.value))) {
2393
+ return { isNumber: { expected: 'A number or a string representing a number', actual: control.value } };
2394
+ }
2395
+ return null;
2396
+ }
2397
+ function _IsNumber({ message, options } = {}) {
2398
+ return (control) => {
2399
+ if (control.value === null) {
2400
+ return null;
2401
+ }
2402
+ if (!isNumber(!(options === null || options === void 0 ? void 0 : options.strict) && typeof control.value === 'string' ? Number(control.value) : control.value, options)) {
2403
+ return {
2404
+ isNumber: {
2405
+ expected: 'A number value',
2406
+ actual: control.value,
2407
+ message
2408
+ }
2409
+ };
2410
+ }
2411
+ return null;
2412
+ };
2413
+ }
2414
+
2415
+ function IsBoolean({ message } = {}) {
2416
+ return (control) => {
2417
+ if (control.value === null) {
2418
+ return null;
2419
+ }
2420
+ if (!(control.value instanceof Boolean || typeof control.value === 'boolean')) {
2421
+ return {
2422
+ isBoolean: {
2423
+ expected: 'A boolean value',
2424
+ actual: control.value,
2425
+ message
2426
+ }
2427
+ };
2428
+ }
2429
+ return null;
2430
+ };
2431
+ }
2432
+
2433
+ function IsObject({ message } = {}) {
2434
+ return (control) => {
2435
+ if (control.value === null) {
2436
+ return null;
2437
+ }
2438
+ if (!(control.value !== undefined && (typeof control.value === 'object' || typeof control.value === 'function') && !Array.isArray(control.value))) {
2439
+ return {
2440
+ isObject: {
2441
+ expected: 'A object value',
2442
+ actual: control.value,
2443
+ message
2444
+ }
2445
+ };
2446
+ }
2447
+ return null;
2448
+ };
2449
+ }
2450
+
2451
+ function IsString({ message } = {}) {
2452
+ return (control) => {
2453
+ if (control.value === null) {
2454
+ return null;
2455
+ }
2456
+ if (!(control.value instanceof String || typeof control.value === 'string')) {
2457
+ return {
2458
+ isString: {
2459
+ expected: 'A string value',
2460
+ actual: control.value,
2461
+ message
2462
+ }
2463
+ };
2464
+ }
2465
+ return null;
2466
+ };
2467
+ }
2468
+
2469
+ function IsInt({ message, options } = {}) {
2470
+ return (control) => {
2471
+ if (control.value === null) {
2472
+ return null;
2473
+ }
2474
+ if (!isNumber(control.value, options) || Number.isInteger(control.value)) {
2475
+ return {
2476
+ isInt: {
2477
+ expected: 'A int value',
2478
+ actual: control.value,
2479
+ message
2480
+ }
2481
+ };
2482
+ }
2483
+ return null;
2484
+ };
2485
+ }
2486
+
2487
+ function IsEnum({ message, entity }) {
2488
+ return (control) => {
2489
+ if (control.value === null) {
2490
+ return null;
2491
+ }
2492
+ if (Object.keys(entity).map(k => entity[k]).indexOf(control.value) === -1) {
2493
+ return {
2494
+ isEnum: {
2495
+ expected: 'A enum value',
2496
+ actual: control.value,
2497
+ message
2498
+ }
2499
+ };
2500
+ }
2501
+ return null;
2502
+ };
2503
+ }
2504
+
2505
+ function IsDate({ message } = {}) {
2506
+ return (control) => {
2507
+ if (control.value === null) {
2508
+ return null;
2509
+ }
2510
+ if (!(control.value instanceof Date && !isNaN(control.value.getTime()))) {
2511
+ return {
2512
+ isDate: {
2513
+ expected: 'A date value',
2514
+ actual: control.value,
2515
+ message
2516
+ }
2517
+ };
2518
+ }
2519
+ return null;
2520
+ };
2521
+ }
2522
+
2523
+ function IsArray({ message } = {}) {
2524
+ return (control) => {
2525
+ if (control.value === null) {
2526
+ return null;
2527
+ }
2528
+ if (!Array.isArray(control.value)) {
2529
+ return {
2530
+ isArray: {
2531
+ expected: 'A array value',
2532
+ actual: control.value,
2533
+ message
2534
+ }
2535
+ };
2536
+ }
2537
+ return null;
2538
+ };
2539
+ }
2540
+
2541
+ const regexOptions = {
2542
+ uppercase: '.*[A-Z]',
2543
+ special: '.*[^A-Za-z0-9]',
2544
+ digit: '.*[0-9]',
2545
+ lowercase: '.*[a-z]',
2546
+ upperLower: '.*[a-zA-Z]',
2547
+ alphaNumeric: '.*[a-zA-Z0-9]'
2548
+ };
2549
+ const lengthOptions = {
2550
+ min: '.{n,}',
2551
+ max: '.{0,n}',
2552
+ range: '.{min,max}',
2553
+ exact: '.{n}',
2554
+ no_limit: '.*'
2555
+ };
2556
+ function inOperator(k, o) {
2557
+ return k in o;
2558
+ }
2559
+ function create(options) {
2560
+ let regex = '^';
2561
+ for (const [key, value] of Object.entries(regexOptions)) {
2562
+ if (inOperator(key, options) && isNumber(options[key])) {
2563
+ regex += '(?=' + value.repeat(options[key]) + ')';
2564
+ }
2565
+ }
2566
+ if (isNumber(options.min) && isNumber(options.max)) {
2567
+ regex += lengthOptions.range.replace('min', options.min.toFixed(0)).replace('max', options.max.toFixed(0));
2568
+ }
2569
+ else if (isNumber(options.max)) {
2570
+ regex += lengthOptions.max.replace('n', options.max.toFixed(0));
2571
+ }
2572
+ else if (isNumber(options.min)) {
2573
+ regex += lengthOptions.min.replace('n', options.min.toFixed(0));
2574
+ }
2575
+ else if (isNumber(options.exact)) {
2576
+ regex += lengthOptions.exact.replace('n', options.exact.toFixed(0));
2577
+ }
2578
+ else {
2579
+ regex += lengthOptions.no_limit;
2580
+ }
2581
+ regex += '$';
2582
+ return regex;
2583
+ }
2584
+ function check(str, regexStringOrOptions) {
2585
+ let regex;
2586
+ let regexString;
2587
+ if (typeof regexStringOrOptions === 'object') {
2588
+ regexString = create(regexStringOrOptions);
2589
+ }
2590
+ else {
2591
+ regexString = regexStringOrOptions;
2592
+ }
2593
+ regex = new RegExp(regexString);
2594
+ return regex.test(str);
2595
+ }
2596
+ function checkError(str, options) {
2597
+ const returnObject = {};
2598
+ for (const [key, value] of Object.entries(options)) {
2599
+ returnObject[key] = check(str, { [key]: value });
2600
+ }
2601
+ return returnObject;
2602
+ }
2603
+ function IsComplex({ message, options }) {
2604
+ return (control) => {
2605
+ if (control.value === null) {
2606
+ return null;
2607
+ }
2608
+ const isNotString = IsString({ message })(control);
2609
+ if (isNotString !== null) {
2610
+ return isNotString;
2611
+ }
2612
+ const errors = checkError(control.value, options);
2613
+ if (Object.keys(errors).length && Object.values(errors).some(item => !item)) {
2614
+ return {
2615
+ isComplex: {
2616
+ expected: options,
2617
+ actual: errors,
2618
+ message
2619
+ }
2620
+ };
2621
+ }
2622
+ return null;
2623
+ };
2624
+ }
2625
+
2626
+ function IsPhoneNumber({ message, locale, options } = {}) {
2627
+ return (control) => {
2628
+ if (control.value === null) {
2629
+ return null;
2630
+ }
2631
+ if (!isMobilePhone(control.value, locale, options)) {
2632
+ return {
2633
+ isPhoneNumber: {
2634
+ expected: 'A phone number value',
2635
+ actual: control.value,
2636
+ message
2637
+ }
2638
+ };
2639
+ }
2640
+ return null;
2641
+ };
2642
+ }
2643
+
2644
+ function IsEmail({ message, options } = {}) {
2645
+ return (control) => {
2646
+ if (control.value === null) {
2647
+ return null;
2648
+ }
2649
+ if (!(typeof control.value === 'string' && isEmail(control.value, options))) {
2650
+ return {
2651
+ isEmail: {
2652
+ expected: 'A email value',
2653
+ actual: control.value,
2654
+ message
2655
+ }
2656
+ };
2657
+ }
2658
+ return null;
2659
+ };
2660
+ }
2661
+
2662
+ function IsUrl({ message, options } = {}) {
2663
+ return (control) => {
2664
+ if (control.value === null) {
2665
+ return null;
2666
+ }
2667
+ if (!(typeof control.value === 'string' && isURL(control.value, options))) {
2668
+ return {
2669
+ isURL: {
2670
+ expected: 'A url value',
2671
+ actual: control.value,
2672
+ message
2673
+ }
2674
+ };
2675
+ }
2676
+ return null;
2677
+ };
2678
+ }
2679
+
2680
+ function IsIP({ message, version } = {}) {
2681
+ return (control) => {
2682
+ if (control.value === null) {
2683
+ return null;
2684
+ }
2685
+ if (!(typeof control.value === 'string' && isIP(control.value, version))) {
2686
+ return {
2687
+ isIp: {
2688
+ expected: `A valid IPv${version !== null && version !== void 0 ? version : '4'} value`,
2689
+ actual: control.value,
2690
+ message
2691
+ }
2692
+ };
2693
+ }
2694
+ return null;
2695
+ };
2696
+ }
2697
+
2698
+ const RxapValidators = {
2699
+ IsNumber: _IsNumber,
2700
+ IsBoolean,
2701
+ IsArray,
2702
+ IsDate,
2703
+ IsEnum,
2704
+ IsInt,
2705
+ IsObject,
2706
+ IsString,
2707
+ IsComplex,
2708
+ IsPhoneNumber,
2709
+ IsEmail,
2710
+ IsUrl,
2711
+ IsIP
2712
+ };
2713
+
2714
+ // endregion
2715
+
2716
+ /**
2717
+ * Generated bundle index. Do not edit.
2718
+ */
2719
+
2720
+ export { ControlAsyncValidator, ControlChange, ControlSetValue, ControlValidator, ControlValueAccessor, FormArrayControlManager, FormControlErrorDirective, FormControlMarkDirtyDirective, FormControlMarkPristineDirective, FormControlMarkTouchedDirective, FormControlMarkUntouchedDirective, FormControlNameDirective, FormDirective, FormGroupNameDirective, FormLoadedDirective, FormLoadingDirective, FormLoadingErrorDirective, FormSubmitDirective, FormSubmitFailedDirective, FormSubmitInvalidDirective, FormSubmitSuccessfulDirective, FormSubmittingDirective, IsArray, IsBoolean, IsDate, IsEnum, IsInt, IsNumber, IsObject, IsString, ParentControlContainerDirective, RXAP_FORM_CONTEXT, RXAP_FORM_DEFINITION, RXAP_FORM_DEFINITION_BUILDER, RXAP_FORM_INITIAL_STATE, RXAP_FORM_LOAD_FAILED_METHOD, RXAP_FORM_LOAD_METHOD, RXAP_FORM_LOAD_SUCCESSFUL_METHOD, RXAP_FORM_SUBMIT_FAILED_METHOD, RXAP_FORM_SUBMIT_METHOD, RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD, RxapForm, RxapFormArray, RxapFormBuilder, RxapFormControl, RxapFormGroup, RxapFormsModule, RxapValidators, ToFormMethod, ToFormSubmitMethod, UseFormArrayControl, UseFormArrayGroup, UseFormControl, UseFormGroup, _IsNumber, controlDisabled$, controlDisabledWhile, controlEnabled$, controlEnabledWhile, controlErrorChanges$, controlReadonly$, controlStatusChanges$, controlValueChanges$, disableControl, enableControl, hasErrorAndDirty, hasErrorAndTouched, isNumber, markAllDirty, markAllPristine, markAllUntouched, mergeControlValidators, selectControlValue$, validateControlOn };
2721
+ //# sourceMappingURL=rxap-forms.mjs.map