@reactables/forms 0.7.0-alpha.8 → 0.7.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -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: <T
|
|
4
|
+
export declare const buildHub2Source: <T>(hub1State$: Observable<BaseFormState<T>>) => Observable<Action<T>>;
|
package/dist/RxForm/RxForm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Reactable, EffectsAndSources, Action, Effect, ScopedEffects } from '@reactables/core';
|
|
1
|
+
import { Reactable, EffectsAndSources, Action, Effect, ScopedEffects, ActionMap } from '@reactables/core';
|
|
2
2
|
import { UpdateValuesPayload, AddControlPayload, MarkTouchedPayload, PushControlPayload } from '../Models/Payloads';
|
|
3
3
|
import { ControlRef } from '../Models';
|
|
4
4
|
import { FormControlConfig, FormArrayConfig, FormGroupConfig, AbstractControlConfig } from '../Models/Configs';
|
|
@@ -33,12 +33,17 @@ export type CustomReducer = CustomReducerFunc | {
|
|
|
33
33
|
reducer: CustomReducerFunc;
|
|
34
34
|
effects?: ((payload?: unknown) => ScopedEffects<unknown>) | Effect<unknown, unknown>[];
|
|
35
35
|
};
|
|
36
|
-
export
|
|
37
|
-
[key
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export type CustomReducers<T> = {
|
|
37
|
+
[key in keyof (T & {
|
|
38
|
+
[key: string]: CustomReducer;
|
|
39
|
+
})]: CustomReducer;
|
|
40
|
+
};
|
|
41
|
+
export interface RxFormOptions extends EffectsAndSources {
|
|
42
|
+
reducers?: CustomReducers<unknown>;
|
|
41
43
|
providers?: RxFormProviders;
|
|
44
|
+
name?: string;
|
|
45
|
+
debug?: boolean;
|
|
46
|
+
storeValue?: boolean;
|
|
42
47
|
}
|
|
43
48
|
type NormalizerFunction<T> = (value: T) => T;
|
|
44
49
|
export interface RxFormProviders {
|
|
@@ -52,6 +57,6 @@ export interface RxFormProviders {
|
|
|
52
57
|
[key: string]: ValidatorAsyncFn;
|
|
53
58
|
};
|
|
54
59
|
}
|
|
55
|
-
export declare const build:
|
|
56
|
-
export declare const load:
|
|
60
|
+
export declare const build: (config: AbstractControlConfig, options?: RxFormOptions) => Reactable<Form<unknown>, ActionMap & RxFormActions>;
|
|
61
|
+
export declare const load: (state: Form<unknown>, options?: RxFormOptions) => Reactable<Form<unknown>, ActionMap & RxFormActions>;
|
|
57
62
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -26,17 +26,20 @@ var Controls = /*#__PURE__*/Object.freeze({
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
var required = function (value) {
|
|
29
|
-
if (Array.isArray(value)) {
|
|
30
|
-
return { required: !Boolean(value.length) };
|
|
31
|
-
}
|
|
32
29
|
if (typeof value === 'string' || typeof value === 'object') {
|
|
33
30
|
return { required: !Boolean(value) };
|
|
34
31
|
}
|
|
35
32
|
if (typeof value === 'number') {
|
|
36
33
|
return { required: !(value !== undefined && value !== null) };
|
|
37
34
|
}
|
|
35
|
+
if (typeof value === 'boolean') {
|
|
36
|
+
return { required: !value };
|
|
37
|
+
}
|
|
38
38
|
return { required: false };
|
|
39
39
|
};
|
|
40
|
+
var arrayNotEmpty = function (value) { return ({
|
|
41
|
+
arrayNotEmpty: !Boolean(value.length)
|
|
42
|
+
}); };
|
|
40
43
|
var email = function (value) {
|
|
41
44
|
return value && !/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(value) ? { email: true } : { email: false };
|
|
42
45
|
};
|
|
@@ -44,12 +47,14 @@ var email = function (value) {
|
|
|
44
47
|
var Validators = /*#__PURE__*/Object.freeze({
|
|
45
48
|
__proto__: null,
|
|
46
49
|
required: required,
|
|
50
|
+
arrayNotEmpty: arrayNotEmpty,
|
|
47
51
|
email: email
|
|
48
52
|
});
|
|
49
53
|
|
|
50
54
|
var index = /*#__PURE__*/Object.freeze({
|
|
51
55
|
__proto__: null,
|
|
52
56
|
required: required,
|
|
57
|
+
arrayNotEmpty: arrayNotEmpty,
|
|
53
58
|
email: email
|
|
54
59
|
});
|
|
55
60
|
|
|
@@ -332,34 +337,28 @@ var getAncestorControls = function (controlRef, form, excludeSelf) {
|
|
|
332
337
|
};
|
|
333
338
|
|
|
334
339
|
var UPDATE_DESCENDANT_VALUES = 'UPDATE_DESCENDANT_VALUES';
|
|
335
|
-
var
|
|
340
|
+
var updateDescendantValues = function (form, _a, providers) {
|
|
336
341
|
var _b = _a.payload, controlRef = _b.controlRef, value = _b.value;
|
|
337
|
-
var descendants = getDescendantControls(controlRef,
|
|
342
|
+
var descendants = getDescendantControls(controlRef, form, true).map(function (control) { return [getFormKey(control.controlRef), control]; });
|
|
338
343
|
var result = descendants.reduce(function (acc, _a) {
|
|
339
|
-
var _b
|
|
344
|
+
var _b;
|
|
340
345
|
var key = _a[0], control = _a[1];
|
|
341
346
|
if (isChildRef(control.controlRef, controlRef)) {
|
|
342
347
|
var childValue = value[control.controlRef.at(-1)];
|
|
343
|
-
var validatorErrors = getErrors(control,
|
|
348
|
+
var validatorErrors = getErrors(control, childValue, providers);
|
|
344
349
|
var newControl = __assign(__assign({}, control), { value: childValue, validatorErrors: validatorErrors, dirty: !isEqual__default["default"](childValue, control.pristineValue) });
|
|
345
|
-
acc = {
|
|
346
|
-
form: __assign(__assign({}, acc.form), (_b = {}, _b[key] = newControl, _b)),
|
|
347
|
-
changedControls: __assign(__assign({}, acc.changedControls), (_c = {}, _c[newControl.key] = newControl, _c))
|
|
348
|
-
};
|
|
350
|
+
acc = __assign(__assign({}, acc), (_b = {}, _b[key] = newControl, _b));
|
|
349
351
|
var configControls = control.config.controls;
|
|
350
352
|
if (configControls) {
|
|
351
|
-
acc =
|
|
353
|
+
acc = updateDescendantValues(acc, {
|
|
352
354
|
type: UPDATE_DESCENDANT_VALUES,
|
|
353
355
|
payload: { controlRef: control.controlRef, value: childValue }
|
|
354
356
|
}, providers);
|
|
355
357
|
}
|
|
356
358
|
}
|
|
357
359
|
return acc;
|
|
358
|
-
},
|
|
359
|
-
return
|
|
360
|
-
form: __assign(__assign({}, state.form), result.form),
|
|
361
|
-
changedControls: __assign({}, result.changedControls)
|
|
362
|
-
};
|
|
360
|
+
}, form);
|
|
361
|
+
return result;
|
|
363
362
|
};
|
|
364
363
|
// Will only update child controls that are present.
|
|
365
364
|
// Use AddControlPayload/RemoveControl action reducers to add/remove control
|
|
@@ -388,15 +387,20 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
388
387
|
changedControls: (_c = {}, _c[newControl.key] = newControl, _c)
|
|
389
388
|
};
|
|
390
389
|
var configControls = config.controls;
|
|
391
|
-
// Update its
|
|
390
|
+
// Update its descendants
|
|
392
391
|
if (configControls) {
|
|
393
|
-
|
|
392
|
+
var updatedDescendants = updateDescendantValues(result.form, {
|
|
394
393
|
type: UPDATE_DESCENDANT_VALUES,
|
|
395
394
|
payload: {
|
|
396
395
|
controlRef: controlRef,
|
|
397
396
|
value: newValue
|
|
398
397
|
}
|
|
399
398
|
}, providers);
|
|
399
|
+
var changedDescendantControls = getDescendantControls(controlRef, updatedDescendants).reduce(function (acc, control) {
|
|
400
|
+
var _a;
|
|
401
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
402
|
+
}, {});
|
|
403
|
+
result = __assign(__assign({}, result), { form: updatedDescendants, changedControls: __assign(__assign({}, result.changedControls), changedDescendantControls) });
|
|
400
404
|
}
|
|
401
405
|
// Update its Ancestors
|
|
402
406
|
if (controlRef.length) {
|
|
@@ -1082,7 +1086,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1082
1086
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1083
1087
|
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1084
1088
|
};
|
|
1085
|
-
var reducers = options.reducers, otherOptions = __rest(options, ["reducers"]);
|
|
1089
|
+
var reducers = options.reducers, debug = options.debug, name = options.name, storeValue = options.storeValue, otherOptions = __rest(options, ["reducers", "debug", "name", "storeValue"]);
|
|
1086
1090
|
var customReducers = Object.entries(reducers || {}).reduce(function (acc, _a) {
|
|
1087
1091
|
var _b;
|
|
1088
1092
|
var key = _a[0], _case = _a[1];
|
|
@@ -1096,7 +1100,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1096
1100
|
effects: effects
|
|
1097
1101
|
}, _b));
|
|
1098
1102
|
}, {});
|
|
1099
|
-
var _d = core.RxBuilder(__assign({ initialState: initialBaseState, reducers: __assign({ updateValues: function (state, action, mergeChanges) {
|
|
1103
|
+
var _d = core.RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, storeValue: storeValue, reducers: __assign({ updateValues: function (state, action, mergeChanges) {
|
|
1100
1104
|
return updateValues(state, action, providers, mergeChanges);
|
|
1101
1105
|
}, removeControl: function (state, action, mergeChanges) {
|
|
1102
1106
|
return removeControl(state, action, providers, mergeChanges);
|
|
@@ -1110,6 +1114,9 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1110
1114
|
var state$ = core.RxBuilder({
|
|
1111
1115
|
sources: [buildHub2Source(hub1State$).pipe(operators.skip(initialFormState ? 1 : 0))],
|
|
1112
1116
|
initialState: initialFormState || null,
|
|
1117
|
+
name: "Stage 2 ".concat(name ? name : 'rxForm'),
|
|
1118
|
+
debug: debug,
|
|
1119
|
+
storeValue: storeValue,
|
|
1113
1120
|
reducers: {
|
|
1114
1121
|
formChange: formChange,
|
|
1115
1122
|
asyncValidation: {
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"author": "David Lai",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@reactables/core": "^0.7.
|
|
17
|
+
"@reactables/core": "^0.7.1-alpha.1",
|
|
18
18
|
"lodash.isequal": "^4.5.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"lodash.clonedeep": "^4.5.0"
|
|
25
25
|
},
|
|
26
|
-
"version": "0.7.
|
|
26
|
+
"version": "0.7.1-alpha.1"
|
|
27
27
|
}
|