@reactables/forms 2.0.0-beta.9 → 2.0.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.
- package/dist/Helpers/addAsyncValidationEffects.d.ts +7 -5
- package/dist/Helpers/buildFormState.d.ts +2 -2
- package/dist/Helpers/buildHub2Source.d.ts +1 -1
- package/dist/Models/Controls.d.ts +9 -8
- package/dist/Models/Validators.d.ts +1 -1
- package/dist/Reducers/Hub2/asyncValidation.d.ts +1 -1
- package/dist/Reducers/Hub2/asyncValidationResponse.d.ts +1 -1
- package/dist/Reducers/Hub2/formChange.d.ts +3 -3
- package/dist/Reducers/Hub2/mergeControls.d.ts +1 -1
- package/dist/Reducers/Hub2/mergeRemoveControl.d.ts +1 -1
- package/dist/RxForm/RxForm.d.ts +14 -14
- package/dist/Testing/Models/initialState.d.ts +1 -1
- package/dist/index.cjs +64 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -61
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/Reducers/Hub1/index.d.ts +0 -6
- package/dist/Reducers/Hub2/index.d.ts +0 -3
- package/dist/Reducers/index.d.ts +0 -2
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from '@reactables/core';
|
|
2
2
|
import { BaseControl } from '../Models/Controls';
|
|
3
|
-
import { ControlAsyncValidationResponse } from '../Models/Payloads';
|
|
4
3
|
import { RxFormProviders } from '../RxForm/RxForm';
|
|
5
|
-
|
|
6
|
-
type ControlScopedEffect<T> = Effect<BaseControl<T>, ControlAsyncValidationResponse | ControlRef>;
|
|
4
|
+
type ControlScopedEffect<T> = Effect;
|
|
7
5
|
export declare const getScopedEffectsForControl: <T>(formControl: BaseControl<T>, providers: RxFormProviders) => ControlScopedEffect<T>[];
|
|
8
|
-
export declare const getAsyncValidationEffects: (formControls: BaseControl<unknown>[]) =>
|
|
6
|
+
export declare const getAsyncValidationEffects: (formControls: BaseControl<unknown>[]) => {
|
|
7
|
+
type: string;
|
|
8
|
+
scopedEffects?: import("@reactables/core").ScopedEffects;
|
|
9
|
+
payload: BaseControl<unknown>;
|
|
10
|
+
}[];
|
|
9
11
|
export {};
|
|
@@ -2,5 +2,5 @@ import { AbstractControlConfig } from '../Models/Configs';
|
|
|
2
2
|
import { BaseForm, BaseFormState } from '../Models/Controls';
|
|
3
3
|
import { ControlRef } from '../Models/ControlRef';
|
|
4
4
|
import { RxFormProviders } from '../RxForm/RxForm';
|
|
5
|
-
export declare const buildState: <T>(config: AbstractControlConfig,
|
|
6
|
-
export declare const buildFormState: <T>(config: AbstractControlConfig,
|
|
5
|
+
export declare const buildState: <T>(config: AbstractControlConfig, controlRef: ControlRef | undefined, providers: RxFormProviders, form?: BaseForm<T>) => BaseForm<T>;
|
|
6
|
+
export declare const buildFormState: <T>(config: AbstractControlConfig, controlRef: ControlRef | undefined, providers: RxFormProviders, form?: BaseForm<T>) => BaseFormState<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Action } from '@reactables/core';
|
|
3
3
|
import { BaseFormState } from '../Models/Controls';
|
|
4
|
-
export declare const buildHub2Source:
|
|
4
|
+
export declare const buildHub2Source: (hub1State$: Observable<BaseFormState<any>>, initialBaseState: BaseFormState<any>) => Observable<Action<any>>;
|
|
@@ -19,9 +19,9 @@ interface AsyncFields {
|
|
|
19
19
|
pending?: boolean;
|
|
20
20
|
}
|
|
21
21
|
interface ValidatedFields {
|
|
22
|
-
valid: boolean;
|
|
22
|
+
valid: boolean | null;
|
|
23
23
|
errors: FormErrors;
|
|
24
|
-
childrenValid: boolean;
|
|
24
|
+
childrenValid: boolean | null;
|
|
25
25
|
}
|
|
26
26
|
export interface Hub2Fields extends AsyncFields, ValidatedFields {
|
|
27
27
|
}
|
|
@@ -36,13 +36,14 @@ export interface BaseFormState<T> {
|
|
|
36
36
|
[key: string]: BaseControl<unknown>;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
export
|
|
40
|
-
root
|
|
39
|
+
export type BaseForm<T> = {
|
|
40
|
+
root: BaseControl<T>;
|
|
41
41
|
[key: string]: BaseControl<unknown>;
|
|
42
|
-
}
|
|
43
|
-
export
|
|
44
|
-
root
|
|
42
|
+
};
|
|
43
|
+
export type Form<T> = {
|
|
44
|
+
root: FormControl<T>;
|
|
45
|
+
} & {
|
|
45
46
|
[key: string]: FormControl<unknown>;
|
|
46
|
-
}
|
|
47
|
+
};
|
|
47
48
|
export declare const DEFAULT_HUB2_FIELDS: Hub2Fields;
|
|
48
49
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { BaseControl } from './Controls';
|
|
3
3
|
import { FormErrors } from './FormErrors';
|
|
4
|
-
export type ValidatorFn = (value:
|
|
4
|
+
export type ValidatorFn = (value: any) => FormErrors;
|
|
5
5
|
export type ValidatorAsyncFn = <T>(control$: Observable<BaseControl<T>>) => Observable<Observable<FormErrors>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Action } from '@reactables/core';
|
|
2
2
|
import { Form } from '../../Models/Controls';
|
|
3
3
|
import { ControlRef } from '../../Models';
|
|
4
|
-
export declare const asyncValidation:
|
|
4
|
+
export declare const asyncValidation: (form: Form<any> | null, { payload: controlRef }: Action<ControlRef>) => Form<any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Action } from '@reactables/core';
|
|
2
2
|
import { Form } from '../../Models/Controls';
|
|
3
3
|
import { ControlAsyncValidationResponse } from '../../Models/Payloads';
|
|
4
|
-
export declare const asyncValidationResponse:
|
|
4
|
+
export declare const asyncValidationResponse: (form: Form<any> | null, { payload: { key, validatorIndex, errors } }: Action<ControlAsyncValidationResponse>) => Form<any>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Form } from '../../Models/Controls';
|
|
3
|
-
export declare const formChange:
|
|
1
|
+
import { Action } from '@reactables/core';
|
|
2
|
+
import { BaseFormState, Form } from '../../Models/Controls';
|
|
3
|
+
export declare const formChange: (state: (Form<any> | null) | undefined, { payload }: Action<BaseFormState<any>>) => Form<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Form, FormControl, BaseFormState } from '../../Models/Controls';
|
|
2
2
|
export declare const mergeControls: <T>(state: Form<T>, { form, _changedControls, _removedControls }: BaseFormState<unknown>) => {
|
|
3
3
|
[x: string]: FormControl<unknown>;
|
|
4
|
-
root
|
|
4
|
+
root: FormControl<unknown>;
|
|
5
5
|
};
|
|
@@ -2,5 +2,5 @@ import { Form, BaseForm, FormControl } from '../../Models/Controls';
|
|
|
2
2
|
import { ControlRef } from '../../Models/ControlRef';
|
|
3
3
|
export declare const mergeRemoveControl: <T>(state: Form<T>, form: BaseForm<T>, controlRef: ControlRef) => {
|
|
4
4
|
[x: string]: FormControl<unknown>;
|
|
5
|
-
root
|
|
5
|
+
root: FormControl<unknown>;
|
|
6
6
|
};
|
package/dist/RxForm/RxForm.d.ts
CHANGED
|
@@ -29,27 +29,27 @@ export interface FormReducers {
|
|
|
29
29
|
markControlAsUntouched: <T>(state: BaseFormState<T>, payload: ControlRef) => BaseFormState<T>;
|
|
30
30
|
resetControl: <T>(state: BaseFormState<T>, payload: ControlRef) => BaseFormState<T>;
|
|
31
31
|
}
|
|
32
|
-
export type CustomReducerFunc<FormValue = unknown
|
|
33
|
-
export type CustomReducer<FormValue = unknown
|
|
34
|
-
reducer: CustomReducerFunc<FormValue
|
|
35
|
-
effects?: Effect
|
|
32
|
+
export type CustomReducerFunc<FormValue = unknown> = (reducers: FormReducers, state: BaseFormState<FormValue>, action: any) => BaseFormState<unknown>;
|
|
33
|
+
export type CustomReducer<FormValue = unknown> = CustomReducerFunc<FormValue> | {
|
|
34
|
+
reducer: CustomReducerFunc<FormValue>;
|
|
35
|
+
effects?: Effect[] | ((payload?: unknown) => ScopedEffects);
|
|
36
36
|
};
|
|
37
|
-
export type ActionCreatorTypeFromCustomReducer<T> = T extends (
|
|
38
|
-
reducer: (
|
|
37
|
+
export type ActionCreatorTypeFromCustomReducer<T> = T extends (formReducers: FormReducers, state: any) => unknown ? () => void : T extends (formReducers: FormReducers, state: any, action: Action<infer P>) => unknown ? (payload: P) => void : T extends {
|
|
38
|
+
reducer: (formReducers: FormReducers, state: any) => unknown;
|
|
39
39
|
} ? () => void : T extends {
|
|
40
|
-
reducer:
|
|
40
|
+
reducer: (formReducers: FormReducers, state: any, action: Action<infer P>) => unknown;
|
|
41
41
|
} ? (payload: P) => void : never;
|
|
42
|
-
export interface RxFormOptions<T extends Record<string, CustomReducer
|
|
42
|
+
export interface RxFormOptions<T extends Record<string, CustomReducer<any>> = Record<string, CustomReducer<any>>> {
|
|
43
43
|
reducers?: T;
|
|
44
44
|
providers?: RxFormProviders;
|
|
45
45
|
name?: string;
|
|
46
46
|
debug?: boolean;
|
|
47
|
-
sources?: Observable<Action<
|
|
47
|
+
sources?: Observable<Action<any>>[];
|
|
48
48
|
}
|
|
49
49
|
type NormalizerFunction<T> = (value: T) => T;
|
|
50
50
|
export interface RxFormProviders {
|
|
51
51
|
normalizers?: {
|
|
52
|
-
[key: string]: NormalizerFunction<
|
|
52
|
+
[key: string]: NormalizerFunction<any>;
|
|
53
53
|
};
|
|
54
54
|
validators?: {
|
|
55
55
|
[key: string]: ValidatorFn;
|
|
@@ -58,7 +58,7 @@ export interface RxFormProviders {
|
|
|
58
58
|
[key: string]: ValidatorAsyncFn;
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
export declare const build: <FormValue, CustomReducers extends Record<string, CustomReducer<FormValue
|
|
61
|
+
export declare const build: <FormValue, CustomReducers extends Record<string, CustomReducer<FormValue>> = Record<string, CustomReducer<FormValue>>>(config: AbstractControlConfig, options?: RxFormOptions<CustomReducers>) => Reactable<Form<FormValue>, { [K in keyof CustomReducers]: ActionCreatorTypeFromCustomReducer<CustomReducers[K]>; } & {
|
|
62
62
|
updateValues: <T>(payload: UpdateValuesPayload<T>) => void;
|
|
63
63
|
addControl: (payload: AddControlPayload) => void;
|
|
64
64
|
pushControl: (payload: PushControlPayload) => void;
|
|
@@ -68,9 +68,9 @@ export declare const build: <FormValue, CustomReducers extends Record<string, Cu
|
|
|
68
68
|
markControlAsUntouched: (payload: ControlRef) => void;
|
|
69
69
|
resetControl: (payload: ControlRef) => void;
|
|
70
70
|
} & ActionMap & DestroyAction, CustomReducerActionTypes<CustomReducers> & FormActionTypes & {
|
|
71
|
-
destroy:
|
|
71
|
+
destroy: "destroy";
|
|
72
72
|
}>;
|
|
73
|
-
export declare const load: <FormValue, CustomReducers extends Record<string, CustomReducer<FormValue
|
|
73
|
+
export declare const load: <FormValue, CustomReducers extends Record<string, CustomReducer<FormValue>> = Record<string, CustomReducer<FormValue>>>(state: Form<FormValue>, options?: RxFormOptions<CustomReducers>) => Reactable<Form<FormValue>, { [K in keyof CustomReducers]: ActionCreatorTypeFromCustomReducer<CustomReducers[K]>; } & {
|
|
74
74
|
updateValues: <T>(payload: UpdateValuesPayload<T>) => void;
|
|
75
75
|
addControl: (payload: AddControlPayload) => void;
|
|
76
76
|
pushControl: (payload: PushControlPayload) => void;
|
|
@@ -80,7 +80,7 @@ export declare const load: <FormValue, CustomReducers extends Record<string, Cus
|
|
|
80
80
|
markControlAsUntouched: (payload: ControlRef) => void;
|
|
81
81
|
resetControl: (payload: ControlRef) => void;
|
|
82
82
|
} & ActionMap & DestroyAction, CustomReducerActionTypes<CustomReducers> & FormActionTypes & {
|
|
83
|
-
destroy:
|
|
83
|
+
destroy: "destroy";
|
|
84
84
|
}>;
|
|
85
85
|
type CustomReducerActionTypes<T extends Record<string, CustomReducer>> = {
|
|
86
86
|
[K in keyof T as `${K & string}`]: `${K & string}`;
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@ var DEFAULT_HUB2_FIELDS = {
|
|
|
11
11
|
pending: false,
|
|
12
12
|
valid: null,
|
|
13
13
|
childrenValid: null,
|
|
14
|
-
errors:
|
|
14
|
+
errors: {},
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
var Controls = /*#__PURE__*/Object.freeze({
|
|
@@ -32,7 +32,7 @@ var required = function (value) {
|
|
|
32
32
|
return { required: false };
|
|
33
33
|
};
|
|
34
34
|
var arrayNotEmpty = function (value) { return ({
|
|
35
|
-
arrayNotEmpty: !Boolean(value.length)
|
|
35
|
+
arrayNotEmpty: !Boolean(value.length),
|
|
36
36
|
}); };
|
|
37
37
|
var email = function (value) {
|
|
38
38
|
return value && !/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(value) ? { email: true } : { email: false };
|
|
@@ -149,16 +149,15 @@ var getErrors = function (control, value, _a) {
|
|
|
149
149
|
var _b;
|
|
150
150
|
var validators = _a.validators;
|
|
151
151
|
return ((_b = control.config.validators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, validator) {
|
|
152
|
-
if (!validators[validator]) {
|
|
152
|
+
if (!(validators === null || validators === void 0 ? void 0 : validators[validator])) {
|
|
153
153
|
throw "You have not provided a validator for \"".concat(validator, "\"");
|
|
154
154
|
}
|
|
155
155
|
return __assign(__assign({}, acc), validators[validator](value));
|
|
156
156
|
}, {})) || {};
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
-
var buildState = function (config,
|
|
159
|
+
var buildState = function (config, controlRef, providers, form) {
|
|
160
160
|
var _a;
|
|
161
|
-
if (form === void 0) { form = { root: null }; }
|
|
162
161
|
if (controlRef === void 0) { controlRef = []; }
|
|
163
162
|
var value = getValueFromControlConfig(config);
|
|
164
163
|
var control = {
|
|
@@ -169,7 +168,7 @@ var buildState = function (config, form, controlRef, providers) {
|
|
|
169
168
|
controlRef: controlRef,
|
|
170
169
|
validatorErrors: {},
|
|
171
170
|
config: config,
|
|
172
|
-
key: generateKey(5)
|
|
171
|
+
key: generateKey(5),
|
|
173
172
|
};
|
|
174
173
|
var newForm = __assign(__assign({}, form), (_a = {}, _a[getFormKey(controlRef)] = __assign(__assign({}, control), { validatorErrors: getErrors(control, value, providers) }), _a));
|
|
175
174
|
var controls = config.controls;
|
|
@@ -177,22 +176,21 @@ var buildState = function (config, form, controlRef, providers) {
|
|
|
177
176
|
if (controls && !(controls instanceof Array)) {
|
|
178
177
|
newForm = Object.entries(config.controls).reduce(function (acc, _a) {
|
|
179
178
|
var key = _a[0], controlConfig = _a[1];
|
|
180
|
-
return buildState(controlConfig,
|
|
179
|
+
return buildState(controlConfig, controlRef.concat(key), providers, acc);
|
|
181
180
|
}, newForm);
|
|
182
181
|
}
|
|
183
182
|
else if (controls && controls instanceof Array) {
|
|
184
183
|
// Adding controls for Form Array
|
|
185
184
|
newForm = config.controls.reduce(function (acc, controlConfig, index) {
|
|
186
|
-
return buildState(controlConfig,
|
|
185
|
+
return buildState(controlConfig, controlRef.concat(index), providers, acc);
|
|
187
186
|
}, newForm);
|
|
188
187
|
}
|
|
189
188
|
return newForm;
|
|
190
189
|
};
|
|
191
|
-
var buildFormState = function (config,
|
|
192
|
-
if (form === void 0) { form = { root: null }; }
|
|
190
|
+
var buildFormState = function (config, controlRef, providers, form) {
|
|
193
191
|
if (controlRef === void 0) { controlRef = []; }
|
|
194
192
|
return {
|
|
195
|
-
form: buildState(config,
|
|
193
|
+
form: buildState(config, controlRef, providers, form),
|
|
196
194
|
};
|
|
197
195
|
};
|
|
198
196
|
|
|
@@ -203,7 +201,8 @@ var getScopedEffectsForControl = function (formControl, providers) {
|
|
|
203
201
|
if (asyncValidators && asyncValidators.length) {
|
|
204
202
|
scopedEffects = asyncValidators.reduce(function (acc, asyncValidator, validatorIndex) {
|
|
205
203
|
var effect = function (actions$) {
|
|
206
|
-
|
|
204
|
+
var _a;
|
|
205
|
+
if (!((_a = providers.asyncValidators) === null || _a === void 0 ? void 0 : _a[asyncValidator])) {
|
|
207
206
|
throw "You have not provided an asyncValidator for \"".concat(asyncValidator, "\"");
|
|
208
207
|
}
|
|
209
208
|
return actions$.pipe(operators.map(function (_a) {
|
|
@@ -215,16 +214,16 @@ var getScopedEffectsForControl = function (formControl, providers) {
|
|
|
215
214
|
payload: {
|
|
216
215
|
key: key,
|
|
217
216
|
errors: errors,
|
|
218
|
-
validatorIndex: validatorIndex
|
|
219
|
-
}
|
|
217
|
+
validatorIndex: validatorIndex,
|
|
218
|
+
},
|
|
220
219
|
}); }), operators.catchError(function () {
|
|
221
220
|
return rxjs.of({
|
|
222
221
|
type: 'asyncValidationResponse',
|
|
223
222
|
payload: {
|
|
224
223
|
key: key,
|
|
225
224
|
errors: { asyncValidationApiError: true },
|
|
226
|
-
validatorIndex: validatorIndex
|
|
227
|
-
}
|
|
225
|
+
validatorIndex: validatorIndex,
|
|
226
|
+
},
|
|
228
227
|
});
|
|
229
228
|
})));
|
|
230
229
|
}));
|
|
@@ -283,7 +282,7 @@ var updateAncestorValues = function (form, _a, providers) {
|
|
|
283
282
|
}
|
|
284
283
|
var newParentControl = __assign(__assign({}, parentControl), { validatorErrors: getErrors(parentControl, newValue, providers), value: newValue, dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
285
284
|
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
286
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
285
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
287
286
|
}, providers);
|
|
288
287
|
}
|
|
289
288
|
return form;
|
|
@@ -305,7 +304,7 @@ var getDescendantControls = function (controlRef, form, excludeSelf) {
|
|
|
305
304
|
}
|
|
306
305
|
var control = getControl(controlRef, form);
|
|
307
306
|
var value = control.value, config = control.config;
|
|
308
|
-
var descendants;
|
|
307
|
+
var descendants = [];
|
|
309
308
|
if (Array.isArray(config.controls)) {
|
|
310
309
|
// If control is a Form Array
|
|
311
310
|
descendants = value.reduce(function (acc, item, index) {
|
|
@@ -331,11 +330,11 @@ var getAncestorControls = function (controlRef, form, excludeSelf) {
|
|
|
331
330
|
var formControls = acc.formControls.concat(getControl(currentRef, form));
|
|
332
331
|
return {
|
|
333
332
|
currentRef: currentRef,
|
|
334
|
-
formControls: formControls
|
|
333
|
+
formControls: formControls,
|
|
335
334
|
};
|
|
336
335
|
}, {
|
|
337
336
|
currentRef: [],
|
|
338
|
-
formControls: []
|
|
337
|
+
formControls: [],
|
|
339
338
|
}).formControls;
|
|
340
339
|
var root = form['root'];
|
|
341
340
|
var result = [root].concat(formControls);
|
|
@@ -407,7 +406,7 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
407
406
|
if (configControls) {
|
|
408
407
|
checkKeys(oldChildValue, newChildValue);
|
|
409
408
|
acc = updateDescendantValues(acc, {
|
|
410
|
-
payload: { controlRef: control.controlRef, value: newChildValue }
|
|
409
|
+
payload: { controlRef: control.controlRef, value: newChildValue },
|
|
411
410
|
}, providers);
|
|
412
411
|
}
|
|
413
412
|
}
|
|
@@ -419,10 +418,11 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
419
418
|
// Use AddControlPayload/RemoveControl action reducers to add/remove control
|
|
420
419
|
var updateValues = function (_a, action, providers, mergeChanges) {
|
|
421
420
|
var _b, _c;
|
|
422
|
-
var
|
|
421
|
+
var _d;
|
|
422
|
+
var form = _a.form, _e = _a._changedControls, _changedControls = _e === void 0 ? {} : _e, _f = _a._removedControls, _removedControls = _f === void 0 ? {} : _f;
|
|
423
423
|
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
424
424
|
var normalizers = providers.normalizers;
|
|
425
|
-
var
|
|
425
|
+
var _g = action.payload, controlRef = _g.controlRef, value = _g.value;
|
|
426
426
|
controlRefCheck(controlRef);
|
|
427
427
|
// Update its own value
|
|
428
428
|
var ctrlKey = getFormKey(controlRef);
|
|
@@ -430,8 +430,8 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
430
430
|
var oldValue = form[ctrlKey].value;
|
|
431
431
|
var config = form[ctrlKey].config;
|
|
432
432
|
if (config.normalizers) {
|
|
433
|
-
newValue = config.normalizers.reduce(function (acc, normalizer) {
|
|
434
|
-
if (!normalizers[normalizer]) {
|
|
433
|
+
newValue = (_d = config.normalizers) === null || _d === void 0 ? void 0 : _d.reduce(function (acc, normalizer) {
|
|
434
|
+
if (!(normalizers === null || normalizers === void 0 ? void 0 : normalizers[normalizer])) {
|
|
435
435
|
throw "You have not provided a normalizer for \"".concat(normalizer, "\"");
|
|
436
436
|
}
|
|
437
437
|
return normalizers[normalizer](acc);
|
|
@@ -441,7 +441,7 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
441
441
|
var newControl = __assign(__assign({}, form[ctrlKey]), { validatorErrors: validatorErrors, dirty: !isEqual(value, form[ctrlKey].pristineValue), value: newValue });
|
|
442
442
|
var result = {
|
|
443
443
|
form: __assign(__assign({}, form), (_b = {}, _b[ctrlKey] = newControl, _b)),
|
|
444
|
-
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c)
|
|
444
|
+
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c),
|
|
445
445
|
};
|
|
446
446
|
var configControls = config.controls;
|
|
447
447
|
// Update its descendants
|
|
@@ -450,8 +450,8 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
450
450
|
var updatedDescendants = updateDescendantValues(result.form, {
|
|
451
451
|
payload: {
|
|
452
452
|
controlRef: controlRef,
|
|
453
|
-
value: newValue
|
|
454
|
-
}
|
|
453
|
+
value: newValue,
|
|
454
|
+
},
|
|
455
455
|
}, providers);
|
|
456
456
|
var changedDescendantControls = getDescendantControls(controlRef, updatedDescendants).reduce(function (acc, control) {
|
|
457
457
|
var _a;
|
|
@@ -462,7 +462,7 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
462
462
|
// Update its Ancestors
|
|
463
463
|
if (controlRef.length) {
|
|
464
464
|
result = __assign(__assign({}, result), { form: updateAncestorValues(result.form, {
|
|
465
|
-
payload: { controlRef: controlRef, value: newValue }
|
|
465
|
+
payload: { controlRef: controlRef, value: newValue },
|
|
466
466
|
}, providers) });
|
|
467
467
|
}
|
|
468
468
|
var changedAncestorControls = getAncestorControls(controlRef, result.form).reduce(function (acc, control) {
|
|
@@ -493,7 +493,7 @@ var updateAncestorValuesRemoveControl = function (form, _a, providers) {
|
|
|
493
493
|
}
|
|
494
494
|
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
495
495
|
return updateAncestorValues(__assign(__assign({}, form), (_b = {}, _b[parentFormKey] = newParentControl, _b)), {
|
|
496
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
496
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
497
497
|
}, providers);
|
|
498
498
|
}
|
|
499
499
|
return form;
|
|
@@ -547,7 +547,7 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
547
547
|
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
548
548
|
}, {});
|
|
549
549
|
var result = updateAncestorValuesRemoveControl(controlRemoved, {
|
|
550
|
-
payload: controlRef
|
|
550
|
+
payload: controlRef,
|
|
551
551
|
}, providers);
|
|
552
552
|
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getAncestorControls(controlRef.slice(0, -1), result).reduce(function (acc, control) {
|
|
553
553
|
var _a;
|
|
@@ -588,7 +588,7 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
588
588
|
return {
|
|
589
589
|
form: result,
|
|
590
590
|
_changedControls: _changedControls,
|
|
591
|
-
_removedControls: _removedControls
|
|
591
|
+
_removedControls: _removedControls,
|
|
592
592
|
};
|
|
593
593
|
};
|
|
594
594
|
|
|
@@ -611,7 +611,7 @@ var updateAncestorValuesAddControl = function (form, _a, providers) {
|
|
|
611
611
|
}
|
|
612
612
|
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
613
613
|
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
614
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
614
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
615
615
|
}, providers);
|
|
616
616
|
}
|
|
617
617
|
return form;
|
|
@@ -631,10 +631,10 @@ var addControl = function (state, action, providers, mergeChanges) {
|
|
|
631
631
|
if (!getControl(controlRef.slice(0, -1), state.form)) {
|
|
632
632
|
throw 'You are attempting to add a control to a non-existent form group';
|
|
633
633
|
}
|
|
634
|
-
var newForm = buildState(config,
|
|
634
|
+
var newForm = buildState(config, controlRef, providers, state.form);
|
|
635
635
|
var newValue = getControl(controlRef, newForm).value;
|
|
636
636
|
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
637
|
-
payload: { controlRef: controlRef, value: newValue }
|
|
637
|
+
payload: { controlRef: controlRef, value: newValue },
|
|
638
638
|
}, providers);
|
|
639
639
|
var _changedControls = getControlBranch(controlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
640
640
|
var _a;
|
|
@@ -643,7 +643,7 @@ var addControl = function (state, action, providers, mergeChanges) {
|
|
|
643
643
|
return {
|
|
644
644
|
form: ancestorsUpdated,
|
|
645
645
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
646
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
646
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
647
647
|
};
|
|
648
648
|
};
|
|
649
649
|
|
|
@@ -662,10 +662,10 @@ var pushControl = function (state, action, providers, mergeChanges) {
|
|
|
662
662
|
else {
|
|
663
663
|
throw 'You are attempting to push to a control that is not a Form Array';
|
|
664
664
|
}
|
|
665
|
-
var newForm = buildState(config,
|
|
665
|
+
var newForm = buildState(config, newControlRef, providers, state.form);
|
|
666
666
|
var newValue = getControl(newControlRef, newForm).value;
|
|
667
667
|
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
668
|
-
payload: { controlRef: newControlRef, value: newValue }
|
|
668
|
+
payload: { controlRef: newControlRef, value: newValue },
|
|
669
669
|
}, providers);
|
|
670
670
|
var _changedControls = getControlBranch(newControlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
671
671
|
var _a;
|
|
@@ -674,7 +674,7 @@ var pushControl = function (state, action, providers, mergeChanges) {
|
|
|
674
674
|
return {
|
|
675
675
|
form: ancestorsUpdated,
|
|
676
676
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
677
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
677
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
678
678
|
};
|
|
679
679
|
};
|
|
680
680
|
|
|
@@ -705,7 +705,7 @@ var updateAncestorPristineValues = function (form, _a) {
|
|
|
705
705
|
}
|
|
706
706
|
var newParentControl = __assign(__assign({}, form[parentKey]), { pristineValue: newValue, dirty: isEqual(form[parentKey].value, newValue) });
|
|
707
707
|
return updateAncestorPristineValues(__assign(__assign({}, form), (_b = {}, _b[parentKey] = newParentControl, _b)), {
|
|
708
|
-
payload: parentRef
|
|
708
|
+
payload: parentRef,
|
|
709
709
|
});
|
|
710
710
|
}
|
|
711
711
|
return form;
|
|
@@ -723,7 +723,7 @@ var markControlAsPristine = function (state, action, mergeChanges) {
|
|
|
723
723
|
var result = __assign(__assign({}, form), descendants);
|
|
724
724
|
if (controlRef.length) {
|
|
725
725
|
result = updateAncestorPristineValues(result, {
|
|
726
|
-
payload: controlRef
|
|
726
|
+
payload: controlRef,
|
|
727
727
|
});
|
|
728
728
|
}
|
|
729
729
|
var _changedControls = getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
@@ -733,7 +733,7 @@ var markControlAsPristine = function (state, action, mergeChanges) {
|
|
|
733
733
|
return {
|
|
734
734
|
form: result,
|
|
735
735
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
736
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
736
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
737
737
|
};
|
|
738
738
|
};
|
|
739
739
|
|
|
@@ -755,7 +755,7 @@ var markControlAsTouched = function (state, action, mergeChanges) {
|
|
|
755
755
|
return {
|
|
756
756
|
form: __assign(__assign({}, form), controls),
|
|
757
757
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
758
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
758
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
759
759
|
};
|
|
760
760
|
};
|
|
761
761
|
|
|
@@ -785,7 +785,7 @@ var markControlAsUntouched = function (state, action, mergeChanges) {
|
|
|
785
785
|
return {
|
|
786
786
|
form: result,
|
|
787
787
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
788
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
788
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
789
789
|
};
|
|
790
790
|
};
|
|
791
791
|
|
|
@@ -806,10 +806,10 @@ var resetControl = function (state, action, providers, mergeChanges) {
|
|
|
806
806
|
delete descendantsRemoved[key];
|
|
807
807
|
});
|
|
808
808
|
// Remove all descendants
|
|
809
|
-
var restoredControls = buildState(controlToReset.config,
|
|
809
|
+
var restoredControls = buildState(controlToReset.config, controlToReset.controlRef, providers, descendantsRemoved);
|
|
810
810
|
var restoredControlValue = getControl(controlRef, restoredControls).value;
|
|
811
811
|
var result = updateAncestorValues(restoredControls, {
|
|
812
|
-
payload: { controlRef: controlRef, value: restoredControlValue }
|
|
812
|
+
payload: { controlRef: controlRef, value: restoredControlValue },
|
|
813
813
|
}, providers);
|
|
814
814
|
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
815
815
|
var _a;
|
|
@@ -828,7 +828,7 @@ var resetControl = function (state, action, providers, mergeChanges) {
|
|
|
828
828
|
return {
|
|
829
829
|
form: result,
|
|
830
830
|
_changedControls: _changedControls,
|
|
831
|
-
_removedControls: _removedControls
|
|
831
|
+
_removedControls: _removedControls,
|
|
832
832
|
};
|
|
833
833
|
};
|
|
834
834
|
|
|
@@ -836,12 +836,14 @@ var asyncValidation = function (form, _a) {
|
|
|
836
836
|
var controlRef = _a.payload;
|
|
837
837
|
var updatedSelfAndAncestors = getAncestorControls(controlRef, form).reduce(function (acc, control) {
|
|
838
838
|
var _a;
|
|
839
|
+
var _b;
|
|
839
840
|
var isChangedControl = getFormKey(control.controlRef) === getFormKey(controlRef);
|
|
840
841
|
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { pending: true, asyncValidateInProgress: isChangedControl
|
|
841
|
-
? __assign({}, control.config.asyncValidators.reduce(function (acc, _, index) {
|
|
842
|
+
? __assign({}, (_b = control.config.asyncValidators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, _, index) {
|
|
842
843
|
var _a;
|
|
843
844
|
return (__assign(__assign({}, acc), (_a = {}, _a[index] = true, _a)));
|
|
844
|
-
}, {}))
|
|
845
|
+
}, {}))
|
|
846
|
+
: control.asyncValidateInProgress }), _a));
|
|
845
847
|
}, {});
|
|
846
848
|
return __assign(__assign({}, form), updatedSelfAndAncestors);
|
|
847
849
|
};
|
|
@@ -1062,7 +1064,7 @@ var control = function (config) {
|
|
|
1062
1064
|
var indexMap = {
|
|
1063
1065
|
0: 'initialValue',
|
|
1064
1066
|
1: 'validators',
|
|
1065
|
-
2: 'asyncValidators'
|
|
1067
|
+
2: 'asyncValidators',
|
|
1066
1068
|
};
|
|
1067
1069
|
return __assign(__assign({}, acc), (_a = {}, _a[indexMap[index]] = index < 1 ? item : [].concat(item || []), _a));
|
|
1068
1070
|
}, {});
|
|
@@ -1095,7 +1097,7 @@ var reducerTools = function (providers) { return ({
|
|
|
1095
1097
|
},
|
|
1096
1098
|
markControlAsUntouched: function (state, payload) {
|
|
1097
1099
|
return markControlAsUntouched(state, { payload: payload }, true);
|
|
1098
|
-
}
|
|
1100
|
+
},
|
|
1099
1101
|
}); };
|
|
1100
1102
|
var build = function (config, options) {
|
|
1101
1103
|
var _a, _b, _c;
|
|
@@ -1103,9 +1105,9 @@ var build = function (config, options) {
|
|
|
1103
1105
|
var providers = {
|
|
1104
1106
|
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1105
1107
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1106
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1108
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators),
|
|
1107
1109
|
};
|
|
1108
|
-
var initialState = buildFormState(config, undefined,
|
|
1110
|
+
var initialState = buildFormState(config, undefined, providers);
|
|
1109
1111
|
return createReactable(initialState, options);
|
|
1110
1112
|
};
|
|
1111
1113
|
var load = function (state, options) {
|
|
@@ -1124,7 +1126,7 @@ var load = function (state, options) {
|
|
|
1124
1126
|
var key = _a[0], value = _a[1];
|
|
1125
1127
|
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
|
|
1126
1128
|
}, {}), _b));
|
|
1127
|
-
}, {})
|
|
1129
|
+
}, {}),
|
|
1128
1130
|
};
|
|
1129
1131
|
return createReactable(baseFormState, options);
|
|
1130
1132
|
};
|
|
@@ -1134,7 +1136,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1134
1136
|
var providers = {
|
|
1135
1137
|
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1136
1138
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1137
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1139
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators),
|
|
1138
1140
|
};
|
|
1139
1141
|
var reducers = options.reducers, debug = options.debug, name = options.name, otherOptions = __rest(options, ["reducers", "debug", "name"]);
|
|
1140
1142
|
var customReducers = Object.entries(reducers || {}).reduce(function (acc, _a) {
|
|
@@ -1147,7 +1149,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1147
1149
|
var form = _a.form;
|
|
1148
1150
|
return _reducer(reducerTools(providers), { form: form }, action);
|
|
1149
1151
|
},
|
|
1150
|
-
effects: effects
|
|
1152
|
+
effects: effects,
|
|
1151
1153
|
}, _b));
|
|
1152
1154
|
}, {});
|
|
1153
1155
|
var _d = core.RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, reducers: __assign({ updateValues: function (state, action) {
|
|
@@ -1174,20 +1176,21 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1174
1176
|
reducer: function (state) { return state; },
|
|
1175
1177
|
effects: function (control) { return ({
|
|
1176
1178
|
key: control.key,
|
|
1177
|
-
effects: getScopedEffectsForControl(control, providers)
|
|
1178
|
-
}); }
|
|
1179
|
+
effects: getScopedEffectsForControl(control, providers),
|
|
1180
|
+
}); },
|
|
1179
1181
|
},
|
|
1180
1182
|
asyncValidation: asyncValidation,
|
|
1181
|
-
asyncValidationResponse: asyncValidationResponse
|
|
1182
|
-
}
|
|
1183
|
+
asyncValidationResponse: asyncValidationResponse,
|
|
1184
|
+
},
|
|
1183
1185
|
}), state$ = _e[0], hub2Actions = _e[1];
|
|
1184
1186
|
var destroy = function () {
|
|
1185
1187
|
hub1Actions.destroy();
|
|
1186
1188
|
hub2Actions.destroy();
|
|
1187
1189
|
};
|
|
1190
|
+
var actions = __assign(__assign({}, hub1Actions), { destroy: destroy });
|
|
1188
1191
|
return [
|
|
1189
1192
|
state$.pipe(operators.filter(function (form) { return form !== null; })),
|
|
1190
|
-
|
|
1193
|
+
actions,
|
|
1191
1194
|
hub1Actions$,
|
|
1192
1195
|
];
|
|
1193
1196
|
};
|