@rxap/forms 12.7.4 → 13.0.0-next.2

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 (170) 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 +78 -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 +2725 -0
  56. package/fesm2015/rxap-forms.mjs.map +1 -0
  57. package/{fesm2015/rxap-forms.js → fesm2020/rxap-forms.mjs} +154 -144
  58. package/fesm2020/rxap-forms.mjs.map +1 -0
  59. package/package.json +35 -21
  60. package/bundles/rxap-forms.umd.js +0 -3527
  61. package/bundles/rxap-forms.umd.js.map +0 -1
  62. package/esm2015/index.js +0 -53
  63. package/esm2015/index.js.map +0 -1
  64. package/esm2015/lib/control-actions.js +0 -80
  65. package/esm2015/lib/control-actions.js.map +0 -1
  66. package/esm2015/lib/control-value-accessor.js +0 -14
  67. package/esm2015/lib/control-value-accessor.js.map +0 -1
  68. package/esm2015/lib/decorators/control-async-validator.js +0 -10
  69. package/esm2015/lib/decorators/control-async-validator.js.map +0 -1
  70. package/esm2015/lib/decorators/control-change.js +0 -10
  71. package/esm2015/lib/decorators/control-change.js.map +0 -1
  72. package/esm2015/lib/decorators/control-set-value.js +0 -8
  73. package/esm2015/lib/decorators/control-set-value.js.map +0 -1
  74. package/esm2015/lib/decorators/control-validator.js +0 -10
  75. package/esm2015/lib/decorators/control-validator.js.map +0 -1
  76. package/esm2015/lib/decorators/form.js +0 -7
  77. package/esm2015/lib/decorators/form.js.map +0 -1
  78. package/esm2015/lib/decorators/metadata-keys.js +0 -12
  79. package/esm2015/lib/decorators/metadata-keys.js.map +0 -1
  80. package/esm2015/lib/decorators/use-form-array.js +0 -13
  81. package/esm2015/lib/decorators/use-form-array.js.map +0 -1
  82. package/esm2015/lib/decorators/use-form-control.js +0 -8
  83. package/esm2015/lib/decorators/use-form-control.js.map +0 -1
  84. package/esm2015/lib/decorators/use-form-group.js +0 -8
  85. package/esm2015/lib/decorators/use-form-group.js.map +0 -1
  86. package/esm2015/lib/directives/form-control-error.directive.js +0 -61
  87. package/esm2015/lib/directives/form-control-error.directive.js.map +0 -1
  88. package/esm2015/lib/directives/form-control-mark-dirty.directive.js +0 -31
  89. package/esm2015/lib/directives/form-control-mark-dirty.directive.js.map +0 -1
  90. package/esm2015/lib/directives/form-control-mark-pristine.directive.js +0 -31
  91. package/esm2015/lib/directives/form-control-mark-pristine.directive.js.map +0 -1
  92. package/esm2015/lib/directives/form-control-mark-touched.directive.js +0 -25
  93. package/esm2015/lib/directives/form-control-mark-touched.directive.js.map +0 -1
  94. package/esm2015/lib/directives/form-control-mark-untouched.directive.js +0 -31
  95. package/esm2015/lib/directives/form-control-mark-untouched.directive.js.map +0 -1
  96. package/esm2015/lib/directives/form-control-name.directive.js +0 -64
  97. package/esm2015/lib/directives/form-control-name.directive.js.map +0 -1
  98. package/esm2015/lib/directives/form-group-name.directive.js +0 -61
  99. package/esm2015/lib/directives/form-group-name.directive.js.map +0 -1
  100. package/esm2015/lib/directives/form-loaded.directive.js +0 -42
  101. package/esm2015/lib/directives/form-loaded.directive.js.map +0 -1
  102. package/esm2015/lib/directives/form-loading-error.directive.js +0 -42
  103. package/esm2015/lib/directives/form-loading-error.directive.js.map +0 -1
  104. package/esm2015/lib/directives/form-loading.directive.js +0 -42
  105. package/esm2015/lib/directives/form-loading.directive.js.map +0 -1
  106. package/esm2015/lib/directives/form-submit-failed.directive.js +0 -42
  107. package/esm2015/lib/directives/form-submit-failed.directive.js.map +0 -1
  108. package/esm2015/lib/directives/form-submit-invalid.directive.js +0 -40
  109. package/esm2015/lib/directives/form-submit-invalid.directive.js.map +0 -1
  110. package/esm2015/lib/directives/form-submit-successful.directive.js +0 -40
  111. package/esm2015/lib/directives/form-submit-successful.directive.js.map +0 -1
  112. package/esm2015/lib/directives/form-submit.directive.js +0 -75
  113. package/esm2015/lib/directives/form-submit.directive.js.map +0 -1
  114. package/esm2015/lib/directives/form-submitting.directive.js +0 -42
  115. package/esm2015/lib/directives/form-submitting.directive.js.map +0 -1
  116. package/esm2015/lib/directives/form.directive.js +0 -544
  117. package/esm2015/lib/directives/form.directive.js.map +0 -1
  118. package/esm2015/lib/directives/forms.module.js +0 -100
  119. package/esm2015/lib/directives/forms.module.js.map +0 -1
  120. package/esm2015/lib/directives/models.js +0 -12
  121. package/esm2015/lib/directives/models.js.map +0 -1
  122. package/esm2015/lib/directives/parent-control-container.directive.js +0 -25
  123. package/esm2015/lib/directives/parent-control-container.directive.js.map +0 -1
  124. package/esm2015/lib/directives/tokens.js +0 -10
  125. package/esm2015/lib/directives/tokens.js.map +0 -1
  126. package/esm2015/lib/form-array.js +0 -226
  127. package/esm2015/lib/form-array.js.map +0 -1
  128. package/esm2015/lib/form-builder.js +0 -349
  129. package/esm2015/lib/form-builder.js.map +0 -1
  130. package/esm2015/lib/form-control.js +0 -170
  131. package/esm2015/lib/form-control.js.map +0 -1
  132. package/esm2015/lib/form-group.js +0 -183
  133. package/esm2015/lib/form-group.js.map +0 -1
  134. package/esm2015/lib/model.js +0 -2
  135. package/esm2015/lib/model.js.map +0 -1
  136. package/esm2015/lib/tokens.js +0 -4
  137. package/esm2015/lib/tokens.js.map +0 -1
  138. package/esm2015/lib/types.js +0 -2
  139. package/esm2015/lib/types.js.map +0 -1
  140. package/esm2015/lib/validators/index.js +0 -29
  141. package/esm2015/lib/validators/index.js.map +0 -1
  142. package/esm2015/lib/validators/is-array.js +0 -18
  143. package/esm2015/lib/validators/is-array.js.map +0 -1
  144. package/esm2015/lib/validators/is-boolean.js +0 -18
  145. package/esm2015/lib/validators/is-boolean.js.map +0 -1
  146. package/esm2015/lib/validators/is-complex.js +0 -87
  147. package/esm2015/lib/validators/is-complex.js.map +0 -1
  148. package/esm2015/lib/validators/is-date.js +0 -18
  149. package/esm2015/lib/validators/is-date.js.map +0 -1
  150. package/esm2015/lib/validators/is-email.js +0 -19
  151. package/esm2015/lib/validators/is-email.js.map +0 -1
  152. package/esm2015/lib/validators/is-enum.js +0 -18
  153. package/esm2015/lib/validators/is-enum.js.map +0 -1
  154. package/esm2015/lib/validators/is-int.js +0 -19
  155. package/esm2015/lib/validators/is-int.js.map +0 -1
  156. package/esm2015/lib/validators/is-ip.js +0 -19
  157. package/esm2015/lib/validators/is-ip.js.map +0 -1
  158. package/esm2015/lib/validators/is-number.js +0 -57
  159. package/esm2015/lib/validators/is-number.js.map +0 -1
  160. package/esm2015/lib/validators/is-object.js +0 -18
  161. package/esm2015/lib/validators/is-object.js.map +0 -1
  162. package/esm2015/lib/validators/is-phone-number.js +0 -19
  163. package/esm2015/lib/validators/is-phone-number.js.map +0 -1
  164. package/esm2015/lib/validators/is-string.js +0 -18
  165. package/esm2015/lib/validators/is-string.js.map +0 -1
  166. package/esm2015/lib/validators/is-url.js +0 -19
  167. package/esm2015/lib/validators/is-url.js.map +0 -1
  168. package/esm2015/rxap-forms.js +0 -5
  169. package/esm2015/rxap-forms.js.map +0 -1
  170. package/fesm2015/rxap-forms.js.map +0 -1
@@ -0,0 +1,2725 @@
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.formDirective.form.markAllAsDirty();
1994
+ this.formDirective.form.markAllAsTouched();
1995
+ this.formDirective.cdr.markForCheck();
1996
+ this.subscription = this.formDirective.rxapSubmit.pipe(take(1), tap(value => {
1997
+ const clonedValue = clone(value);
1998
+ this.afterSubmit.emit(clonedValue);
1999
+ if (this._resetAfterSubmit) {
2000
+ this.formDirective.reset();
2001
+ }
2002
+ if (this.navigateAfterSubmit) {
2003
+ if (!this.router) {
2004
+ throw new Error('Could not resolve the router!');
2005
+ }
2006
+ return this.router.navigate(this.navigateAfterSubmit);
2007
+ }
2008
+ return Promise.resolve();
2009
+ })).subscribe();
2010
+ this.formDirective.onSubmit(new Event('submit'));
2011
+ }
2012
+ ngOnDestroy() {
2013
+ var _a;
2014
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2015
+ }
2016
+ }
2017
+ 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 });
2018
+ 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 });
2019
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitDirective, decorators: [{
2020
+ type: Directive,
2021
+ args: [{
2022
+ selector: '[rxapFormSubmit]',
2023
+ host: {
2024
+ '(click)': 'onClick()',
2025
+ '(confirmed)': 'onConfirm()',
2026
+ }
2027
+ }]
2028
+ }], ctorParameters: function () {
2029
+ return [{ type: FormDirective, decorators: [{
2030
+ type: Inject,
2031
+ args: [FormDirective]
2032
+ }] }, { type: i2$1.Router, decorators: [{
2033
+ type: Optional
2034
+ }, {
2035
+ type: Inject,
2036
+ args: [Router]
2037
+ }] }];
2038
+ }, propDecorators: { type: [{
2039
+ type: HostBinding,
2040
+ args: ['type']
2041
+ }, {
2042
+ type: Input
2043
+ }], resetAfterSubmit: [{
2044
+ type: Input,
2045
+ args: ['resetAfterSubmit']
2046
+ }], navigateAfterSubmit: [{
2047
+ type: Input
2048
+ }], afterSubmit: [{
2049
+ type: Output
2050
+ }] } });
2051
+
2052
+ /**
2053
+ * A full exertion of FormGroupName from @angular/forms. The only change is the
2054
+ * ability to access the control container outside of the current component
2055
+ *
2056
+ * @deprecated use the ParentControlContainerDirective
2057
+ */
2058
+ class FormGroupNameDirective extends FormGroupName {
2059
+ constructor(parent, validators, asyncValidators) {
2060
+ super(parent, validators, asyncValidators);
2061
+ }
2062
+ get control() {
2063
+ // TODO : add type check
2064
+ return this.formDirective.getFormGroup(this);
2065
+ }
2066
+ }
2067
+ 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 });
2068
+ FormGroupNameDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormGroupNameDirective, selector: "[rxapFormGroupName]", inputs: { name: ["rxapFormGroupName", "name"] }, providers: [
2069
+ {
2070
+ provide: ControlContainer,
2071
+ useExisting: forwardRef(() => FormGroupNameDirective)
2072
+ }
2073
+ ], exportAs: ["rxapFormGroup"], usesInheritance: true, ngImport: i0 });
2074
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormGroupNameDirective, decorators: [{
2075
+ type: Directive,
2076
+ args: [{
2077
+ selector: '[rxapFormGroupName]',
2078
+ providers: [
2079
+ {
2080
+ provide: ControlContainer,
2081
+ useExisting: forwardRef(() => FormGroupNameDirective)
2082
+ }
2083
+ ],
2084
+ exportAs: 'rxapFormGroup'
2085
+ }]
2086
+ }], ctorParameters: function () {
2087
+ return [{ type: i1.ControlContainer, decorators: [{
2088
+ type: Optional
2089
+ }, {
2090
+ type: SkipSelf
2091
+ }] }, { type: undefined, decorators: [{
2092
+ type: Optional
2093
+ }, {
2094
+ type: Self
2095
+ }, {
2096
+ type: Inject,
2097
+ args: [NG_VALIDATORS]
2098
+ }] }, { type: undefined, decorators: [{
2099
+ type: Optional
2100
+ }, {
2101
+ type: Self
2102
+ }, {
2103
+ type: Inject,
2104
+ args: [NG_ASYNC_VALIDATORS]
2105
+ }] }];
2106
+ }, propDecorators: { name: [{
2107
+ type: Input,
2108
+ args: ['rxapFormGroupName']
2109
+ }] } });
2110
+
2111
+ /**
2112
+ * A full exertion of FormControlName from @angular/forms. The only change is the
2113
+ * ability to access the control container outside of the current component
2114
+ *
2115
+ * @deprecated use the ParentControlContainerDirective
2116
+ */
2117
+ class FormControlNameDirective extends FormControlName {
2118
+ constructor(parent, validators, asyncValidators, valueAccessors) {
2119
+ super(parent, validators, asyncValidators, valueAccessors, null);
2120
+ }
2121
+ }
2122
+ 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 });
2123
+ FormControlNameDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormControlNameDirective, selector: "[rxapFormControlName]", inputs: { name: ["rxapFormControlName", "name"] }, providers: [
2124
+ {
2125
+ provide: NgControl,
2126
+ useExisting: forwardRef(() => FormControlNameDirective)
2127
+ }
2128
+ ], exportAs: ["rxapFormControl"], usesInheritance: true, ngImport: i0 });
2129
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormControlNameDirective, decorators: [{
2130
+ type: Directive,
2131
+ args: [{
2132
+ selector: '[rxapFormControlName]',
2133
+ providers: [
2134
+ {
2135
+ provide: NgControl,
2136
+ useExisting: forwardRef(() => FormControlNameDirective)
2137
+ }
2138
+ ],
2139
+ exportAs: 'rxapFormControl'
2140
+ }]
2141
+ }], ctorParameters: function () {
2142
+ return [{ type: i1.ControlContainer, decorators: [{
2143
+ type: Optional
2144
+ }, {
2145
+ type: SkipSelf
2146
+ }] }, { type: Array, decorators: [{
2147
+ type: Optional
2148
+ }, {
2149
+ type: Self
2150
+ }, {
2151
+ type: Inject,
2152
+ args: [NG_VALIDATORS]
2153
+ }] }, { type: Array, decorators: [{
2154
+ type: Optional
2155
+ }, {
2156
+ type: Self
2157
+ }, {
2158
+ type: Inject,
2159
+ args: [NG_ASYNC_VALIDATORS]
2160
+ }] }, { type: undefined, decorators: [{
2161
+ type: Optional
2162
+ }, {
2163
+ type: Self
2164
+ }, {
2165
+ type: Inject,
2166
+ args: [NG_VALUE_ACCESSOR]
2167
+ }] }];
2168
+ }, propDecorators: { name: [{
2169
+ type: Input,
2170
+ args: ['rxapFormControlName']
2171
+ }] } });
2172
+
2173
+ class ParentControlContainerDirective {
2174
+ }
2175
+ ParentControlContainerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ParentControlContainerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2176
+ ParentControlContainerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ParentControlContainerDirective, selector: "[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]", providers: [
2177
+ {
2178
+ provide: ControlContainer,
2179
+ useExisting: ControlContainer
2180
+ }
2181
+ ], ngImport: i0 });
2182
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ParentControlContainerDirective, decorators: [{
2183
+ type: Directive,
2184
+ args: [{
2185
+ selector: '[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]',
2186
+ providers: [
2187
+ {
2188
+ provide: ControlContainer,
2189
+ useExisting: ControlContainer
2190
+ }
2191
+ ]
2192
+ }]
2193
+ }] });
2194
+
2195
+ class FormSubmitSuccessfulDirective {
2196
+ constructor(formDirective, template, viewContainerRef) {
2197
+ this.formDirective = formDirective;
2198
+ this.template = template;
2199
+ this.viewContainerRef = viewContainerRef;
2200
+ }
2201
+ ngAfterViewInit() {
2202
+ this.subscription = this.formDirective.submitSuccessful$.pipe(tap(result => {
2203
+ this.viewContainerRef.clear();
2204
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
2205
+ })).subscribe();
2206
+ }
2207
+ ngOnDestroy() {
2208
+ var _a;
2209
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2210
+ }
2211
+ }
2212
+ 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 });
2213
+ FormSubmitSuccessfulDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmitSuccessfulDirective, selector: "[rxapFormSubmitSuccessful]", ngImport: i0 });
2214
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitSuccessfulDirective, decorators: [{
2215
+ type: Directive,
2216
+ args: [{
2217
+ selector: '[rxapFormSubmitSuccessful]'
2218
+ }]
2219
+ }], ctorParameters: function () {
2220
+ return [{ type: FormDirective, decorators: [{
2221
+ type: Inject,
2222
+ args: [FormDirective]
2223
+ }] }, { type: i0.TemplateRef, decorators: [{
2224
+ type: Inject,
2225
+ args: [TemplateRef]
2226
+ }] }, { type: i0.ViewContainerRef, decorators: [{
2227
+ type: Inject,
2228
+ args: [ViewContainerRef]
2229
+ }] }];
2230
+ } });
2231
+
2232
+ class FormSubmitInvalidDirective {
2233
+ constructor(formDirective, template, viewContainerRef) {
2234
+ this.formDirective = formDirective;
2235
+ this.template = template;
2236
+ this.viewContainerRef = viewContainerRef;
2237
+ }
2238
+ ngAfterViewInit() {
2239
+ this.subscription = this.formDirective.invalidSubmit.pipe(tap(result => {
2240
+ this.viewContainerRef.clear();
2241
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
2242
+ })).subscribe();
2243
+ }
2244
+ ngOnDestroy() {
2245
+ var _a;
2246
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2247
+ }
2248
+ }
2249
+ 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 });
2250
+ FormSubmitInvalidDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: FormSubmitInvalidDirective, selector: "[rxapFormSubmitInvalid]", ngImport: i0 });
2251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: FormSubmitInvalidDirective, decorators: [{
2252
+ type: Directive,
2253
+ args: [{
2254
+ selector: '[rxapFormSubmitInvalid]'
2255
+ }]
2256
+ }], ctorParameters: function () {
2257
+ return [{ type: FormDirective, decorators: [{
2258
+ type: Inject,
2259
+ args: [FormDirective]
2260
+ }] }, { type: i0.TemplateRef, decorators: [{
2261
+ type: Inject,
2262
+ args: [TemplateRef]
2263
+ }] }, { type: i0.ViewContainerRef, decorators: [{
2264
+ type: Inject,
2265
+ args: [ViewContainerRef]
2266
+ }] }];
2267
+ } });
2268
+
2269
+ class RxapFormsModule {
2270
+ }
2271
+ RxapFormsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2272
+ RxapFormsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule, declarations: [FormDirective,
2273
+ FormSubmitFailedDirective,
2274
+ FormLoadingDirective,
2275
+ FormSubmittingDirective,
2276
+ FormLoadingErrorDirective,
2277
+ FormLoadedDirective,
2278
+ FormControlErrorDirective,
2279
+ FormControlMarkDirtyDirective,
2280
+ FormControlMarkTouchedDirective,
2281
+ FormControlMarkUntouchedDirective,
2282
+ FormControlMarkPristineDirective,
2283
+ FormSubmitDirective,
2284
+ FormGroupNameDirective,
2285
+ FormControlNameDirective,
2286
+ ParentControlContainerDirective,
2287
+ FormSubmitSuccessfulDirective,
2288
+ FormSubmitInvalidDirective], exports: [FormDirective,
2289
+ FormSubmitFailedDirective,
2290
+ FormLoadingDirective,
2291
+ FormSubmittingDirective,
2292
+ FormLoadingErrorDirective,
2293
+ FormLoadedDirective,
2294
+ FormControlErrorDirective,
2295
+ FormControlMarkDirtyDirective,
2296
+ FormControlMarkTouchedDirective,
2297
+ FormControlMarkUntouchedDirective,
2298
+ FormControlMarkPristineDirective,
2299
+ FormSubmitDirective,
2300
+ FormGroupNameDirective,
2301
+ FormControlNameDirective,
2302
+ ParentControlContainerDirective,
2303
+ FormSubmitSuccessfulDirective,
2304
+ FormSubmitInvalidDirective] });
2305
+ RxapFormsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule });
2306
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: RxapFormsModule, decorators: [{
2307
+ type: NgModule,
2308
+ args: [{
2309
+ declarations: [
2310
+ FormDirective,
2311
+ FormSubmitFailedDirective,
2312
+ FormLoadingDirective,
2313
+ FormSubmittingDirective,
2314
+ FormLoadingErrorDirective,
2315
+ FormLoadedDirective,
2316
+ FormControlErrorDirective,
2317
+ FormControlMarkDirtyDirective,
2318
+ FormControlMarkTouchedDirective,
2319
+ FormControlMarkUntouchedDirective,
2320
+ FormControlMarkPristineDirective,
2321
+ FormSubmitDirective,
2322
+ FormGroupNameDirective,
2323
+ FormControlNameDirective,
2324
+ ParentControlContainerDirective,
2325
+ FormSubmitSuccessfulDirective,
2326
+ FormSubmitInvalidDirective,
2327
+ ],
2328
+ exports: [
2329
+ FormDirective,
2330
+ FormSubmitFailedDirective,
2331
+ FormLoadingDirective,
2332
+ FormSubmittingDirective,
2333
+ FormLoadingErrorDirective,
2334
+ FormLoadedDirective,
2335
+ FormControlErrorDirective,
2336
+ FormControlMarkDirtyDirective,
2337
+ FormControlMarkTouchedDirective,
2338
+ FormControlMarkUntouchedDirective,
2339
+ FormControlMarkPristineDirective,
2340
+ FormSubmitDirective,
2341
+ FormGroupNameDirective,
2342
+ FormControlNameDirective,
2343
+ ParentControlContainerDirective,
2344
+ FormSubmitSuccessfulDirective,
2345
+ FormSubmitInvalidDirective,
2346
+ ]
2347
+ }]
2348
+ }] });
2349
+
2350
+ function ToFormMethod(call) {
2351
+ return { call };
2352
+ }
2353
+ /**
2354
+ * @deprecated use ToFormMethod instead
2355
+ *
2356
+ * @param call the call method implementation
2357
+ */
2358
+ function ToFormSubmitMethod(call) {
2359
+ return ToFormMethod(call);
2360
+ }
2361
+
2362
+ /**
2363
+ * Checks if a given value is a number.
2364
+ */
2365
+ function isNumber(value, options = {}) {
2366
+ var _a, _b;
2367
+ if (typeof value !== 'number') {
2368
+ return false;
2369
+ }
2370
+ if (value === Infinity || value === -Infinity) {
2371
+ return (_a = options.allowInfinity) !== null && _a !== void 0 ? _a : false;
2372
+ }
2373
+ if (Number.isNaN(value)) {
2374
+ return (_b = options.allowNaN) !== null && _b !== void 0 ? _b : false;
2375
+ }
2376
+ if (options.maxDecimalPlaces !== undefined) {
2377
+ let decimalPlaces = 0;
2378
+ if (value % 1 !== 0) {
2379
+ decimalPlaces = value.toString().split('.')[1].length;
2380
+ }
2381
+ if (decimalPlaces > options.maxDecimalPlaces) {
2382
+ return false;
2383
+ }
2384
+ }
2385
+ return Number.isFinite(value);
2386
+ }
2387
+ /**
2388
+ * @deprecated use RxapValidators.isNumber() instead
2389
+ * @param control
2390
+ * @constructor
2391
+ */
2392
+ function IsNumber(control) {
2393
+ if (control.value === null) {
2394
+ return null;
2395
+ }
2396
+ if (isNaN(Number(control.value))) {
2397
+ return { isNumber: { expected: 'A number or a string representing a number', actual: control.value } };
2398
+ }
2399
+ return null;
2400
+ }
2401
+ function _IsNumber({ message, options } = {}) {
2402
+ return (control) => {
2403
+ if (control.value === null) {
2404
+ return null;
2405
+ }
2406
+ if (!isNumber(!(options === null || options === void 0 ? void 0 : options.strict) && typeof control.value === 'string' ? Number(control.value) : control.value, options)) {
2407
+ return {
2408
+ isNumber: {
2409
+ expected: 'A number value',
2410
+ actual: control.value,
2411
+ message
2412
+ }
2413
+ };
2414
+ }
2415
+ return null;
2416
+ };
2417
+ }
2418
+
2419
+ function IsBoolean({ message } = {}) {
2420
+ return (control) => {
2421
+ if (control.value === null) {
2422
+ return null;
2423
+ }
2424
+ if (!(control.value instanceof Boolean || typeof control.value === 'boolean')) {
2425
+ return {
2426
+ isBoolean: {
2427
+ expected: 'A boolean value',
2428
+ actual: control.value,
2429
+ message
2430
+ }
2431
+ };
2432
+ }
2433
+ return null;
2434
+ };
2435
+ }
2436
+
2437
+ function IsObject({ message } = {}) {
2438
+ return (control) => {
2439
+ if (control.value === null) {
2440
+ return null;
2441
+ }
2442
+ if (!(control.value !== undefined && (typeof control.value === 'object' || typeof control.value === 'function') && !Array.isArray(control.value))) {
2443
+ return {
2444
+ isObject: {
2445
+ expected: 'A object value',
2446
+ actual: control.value,
2447
+ message
2448
+ }
2449
+ };
2450
+ }
2451
+ return null;
2452
+ };
2453
+ }
2454
+
2455
+ function IsString({ message } = {}) {
2456
+ return (control) => {
2457
+ if (control.value === null) {
2458
+ return null;
2459
+ }
2460
+ if (!(control.value instanceof String || typeof control.value === 'string')) {
2461
+ return {
2462
+ isString: {
2463
+ expected: 'A string value',
2464
+ actual: control.value,
2465
+ message
2466
+ }
2467
+ };
2468
+ }
2469
+ return null;
2470
+ };
2471
+ }
2472
+
2473
+ function IsInt({ message, options } = {}) {
2474
+ return (control) => {
2475
+ if (control.value === null) {
2476
+ return null;
2477
+ }
2478
+ if (!isNumber(control.value, options) || Number.isInteger(control.value)) {
2479
+ return {
2480
+ isInt: {
2481
+ expected: 'A int value',
2482
+ actual: control.value,
2483
+ message
2484
+ }
2485
+ };
2486
+ }
2487
+ return null;
2488
+ };
2489
+ }
2490
+
2491
+ function IsEnum({ message, entity }) {
2492
+ return (control) => {
2493
+ if (control.value === null) {
2494
+ return null;
2495
+ }
2496
+ if (Object.keys(entity).map(k => entity[k]).indexOf(control.value) === -1) {
2497
+ return {
2498
+ isEnum: {
2499
+ expected: 'A enum value',
2500
+ actual: control.value,
2501
+ message
2502
+ }
2503
+ };
2504
+ }
2505
+ return null;
2506
+ };
2507
+ }
2508
+
2509
+ function IsDate({ message } = {}) {
2510
+ return (control) => {
2511
+ if (control.value === null) {
2512
+ return null;
2513
+ }
2514
+ if (!(control.value instanceof Date && !isNaN(control.value.getTime()))) {
2515
+ return {
2516
+ isDate: {
2517
+ expected: 'A date value',
2518
+ actual: control.value,
2519
+ message
2520
+ }
2521
+ };
2522
+ }
2523
+ return null;
2524
+ };
2525
+ }
2526
+
2527
+ function IsArray({ message } = {}) {
2528
+ return (control) => {
2529
+ if (control.value === null) {
2530
+ return null;
2531
+ }
2532
+ if (!Array.isArray(control.value)) {
2533
+ return {
2534
+ isArray: {
2535
+ expected: 'A array value',
2536
+ actual: control.value,
2537
+ message
2538
+ }
2539
+ };
2540
+ }
2541
+ return null;
2542
+ };
2543
+ }
2544
+
2545
+ const regexOptions = {
2546
+ uppercase: '.*[A-Z]',
2547
+ special: '.*[^A-Za-z0-9]',
2548
+ digit: '.*[0-9]',
2549
+ lowercase: '.*[a-z]',
2550
+ upperLower: '.*[a-zA-Z]',
2551
+ alphaNumeric: '.*[a-zA-Z0-9]'
2552
+ };
2553
+ const lengthOptions = {
2554
+ min: '.{n,}',
2555
+ max: '.{0,n}',
2556
+ range: '.{min,max}',
2557
+ exact: '.{n}',
2558
+ no_limit: '.*'
2559
+ };
2560
+ function inOperator(k, o) {
2561
+ return k in o;
2562
+ }
2563
+ function create(options) {
2564
+ let regex = '^';
2565
+ for (const [key, value] of Object.entries(regexOptions)) {
2566
+ if (inOperator(key, options) && isNumber(options[key])) {
2567
+ regex += '(?=' + value.repeat(options[key]) + ')';
2568
+ }
2569
+ }
2570
+ if (isNumber(options.min) && isNumber(options.max)) {
2571
+ regex += lengthOptions.range.replace('min', options.min.toFixed(0)).replace('max', options.max.toFixed(0));
2572
+ }
2573
+ else if (isNumber(options.max)) {
2574
+ regex += lengthOptions.max.replace('n', options.max.toFixed(0));
2575
+ }
2576
+ else if (isNumber(options.min)) {
2577
+ regex += lengthOptions.min.replace('n', options.min.toFixed(0));
2578
+ }
2579
+ else if (isNumber(options.exact)) {
2580
+ regex += lengthOptions.exact.replace('n', options.exact.toFixed(0));
2581
+ }
2582
+ else {
2583
+ regex += lengthOptions.no_limit;
2584
+ }
2585
+ regex += '$';
2586
+ return regex;
2587
+ }
2588
+ function check(str, regexStringOrOptions) {
2589
+ let regex;
2590
+ let regexString;
2591
+ if (typeof regexStringOrOptions === 'object') {
2592
+ regexString = create(regexStringOrOptions);
2593
+ }
2594
+ else {
2595
+ regexString = regexStringOrOptions;
2596
+ }
2597
+ regex = new RegExp(regexString);
2598
+ return regex.test(str);
2599
+ }
2600
+ function checkError(str, options) {
2601
+ const returnObject = {};
2602
+ for (const [key, value] of Object.entries(options)) {
2603
+ returnObject[key] = check(str, { [key]: value });
2604
+ }
2605
+ return returnObject;
2606
+ }
2607
+ function IsComplex({ message, options }) {
2608
+ return (control) => {
2609
+ if (control.value === null) {
2610
+ return null;
2611
+ }
2612
+ const isNotString = IsString({ message })(control);
2613
+ if (isNotString !== null) {
2614
+ return isNotString;
2615
+ }
2616
+ const errors = checkError(control.value, options);
2617
+ if (Object.keys(errors).length && Object.values(errors).some(item => !item)) {
2618
+ return {
2619
+ isComplex: {
2620
+ expected: options,
2621
+ actual: errors,
2622
+ message
2623
+ }
2624
+ };
2625
+ }
2626
+ return null;
2627
+ };
2628
+ }
2629
+
2630
+ function IsPhoneNumber({ message, locale, options } = {}) {
2631
+ return (control) => {
2632
+ if (control.value === null) {
2633
+ return null;
2634
+ }
2635
+ if (!isMobilePhone(control.value, locale, options)) {
2636
+ return {
2637
+ isPhoneNumber: {
2638
+ expected: 'A phone number value',
2639
+ actual: control.value,
2640
+ message
2641
+ }
2642
+ };
2643
+ }
2644
+ return null;
2645
+ };
2646
+ }
2647
+
2648
+ function IsEmail({ message, options } = {}) {
2649
+ return (control) => {
2650
+ if (control.value === null) {
2651
+ return null;
2652
+ }
2653
+ if (!(typeof control.value === 'string' && isEmail(control.value, options))) {
2654
+ return {
2655
+ isEmail: {
2656
+ expected: 'A email value',
2657
+ actual: control.value,
2658
+ message
2659
+ }
2660
+ };
2661
+ }
2662
+ return null;
2663
+ };
2664
+ }
2665
+
2666
+ function IsUrl({ message, options } = {}) {
2667
+ return (control) => {
2668
+ if (control.value === null) {
2669
+ return null;
2670
+ }
2671
+ if (!(typeof control.value === 'string' && isURL(control.value, options))) {
2672
+ return {
2673
+ isURL: {
2674
+ expected: 'A url value',
2675
+ actual: control.value,
2676
+ message
2677
+ }
2678
+ };
2679
+ }
2680
+ return null;
2681
+ };
2682
+ }
2683
+
2684
+ function IsIP({ message, version } = {}) {
2685
+ return (control) => {
2686
+ if (control.value === null) {
2687
+ return null;
2688
+ }
2689
+ if (!(typeof control.value === 'string' && isIP(control.value, version))) {
2690
+ return {
2691
+ isIp: {
2692
+ expected: `A valid IPv${version !== null && version !== void 0 ? version : '4'} value`,
2693
+ actual: control.value,
2694
+ message
2695
+ }
2696
+ };
2697
+ }
2698
+ return null;
2699
+ };
2700
+ }
2701
+
2702
+ const RxapValidators = {
2703
+ IsNumber: _IsNumber,
2704
+ IsBoolean,
2705
+ IsArray,
2706
+ IsDate,
2707
+ IsEnum,
2708
+ IsInt,
2709
+ IsObject,
2710
+ IsString,
2711
+ IsComplex,
2712
+ IsPhoneNumber,
2713
+ IsEmail,
2714
+ IsUrl,
2715
+ IsIP
2716
+ };
2717
+
2718
+ // endregion
2719
+
2720
+ /**
2721
+ * Generated bundle index. Do not edit.
2722
+ */
2723
+
2724
+ 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 };
2725
+ //# sourceMappingURL=rxap-forms.mjs.map