@rxap/forms 12.7.0 → 13.0.0-next.0

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