@homebound/form-state 2.17.0 → 2.17.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.
|
@@ -3,9 +3,9 @@ import { ObjectState } from "./objectField";
|
|
|
3
3
|
import { FieldState } from "./valueField";
|
|
4
4
|
import { Rule } from "../rules";
|
|
5
5
|
/** Form state for list of children, i.e. `U` is a `Book` in a form with a `books: Book[]`. */
|
|
6
|
-
export interface ListFieldState<
|
|
6
|
+
export interface ListFieldState<U> extends Omit<FieldState<U[]>, "originalValue"> {
|
|
7
7
|
readonly rows: ReadonlyArray<ObjectState<U>>;
|
|
8
8
|
add(value: U, index?: number): void;
|
|
9
9
|
remove(indexOrValue: number | U): void;
|
|
10
10
|
}
|
|
11
|
-
export declare function newListFieldState<T, K extends keyof T, U>(parentInstance: T, parentState: () => ObjectState<T>, key: K, rules: Rule<readonly ObjectState<U>[]>[], listConfig: ListFieldConfig<T, U>, config: ObjectConfig<U>, maybeAutoSave: () => void): ListFieldState<
|
|
11
|
+
export declare function newListFieldState<T, K extends keyof T, U>(parentInstance: T, parentState: () => ObjectState<T>, key: K, rules: Rule<readonly ObjectState<U>[]>[], listConfig: ListFieldConfig<T, U>, config: ObjectConfig<U>, maybeAutoSave: () => void): ListFieldState<U>;
|
|
@@ -14,7 +14,7 @@ import { Builtin } from "../utils";
|
|
|
14
14
|
* have exactly the on-the-wire type `T` that they need to submit to the backend, without doing the
|
|
15
15
|
* manual mapping of "data that was in the form controls" into "data that the backend wants".
|
|
16
16
|
*
|
|
17
|
-
* Note that this can be hierarchical by having
|
|
17
|
+
* Note that this can be hierarchical by having a field of `ListFieldState` that
|
|
18
18
|
* themselves each wrap an `ObjectState`, i.e.:
|
|
19
19
|
*
|
|
20
20
|
* ```
|
|
@@ -28,14 +28,14 @@ import { Builtin } from "../utils";
|
|
|
28
28
|
* - title: FieldState
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export declare type ObjectState<T
|
|
31
|
+
export declare type ObjectState<T> = FieldStates<T> & FieldState<T> & {
|
|
32
32
|
/** Sets the state of fields in `state`. */
|
|
33
33
|
set(state: Partial<T>, opts?: SetOpts): void;
|
|
34
34
|
/** Returns whether the object can be saved, i.e. is valid, but also as a side-effect marks touched. */
|
|
35
35
|
canSave(): boolean;
|
|
36
36
|
};
|
|
37
|
-
export declare type ObjectStateInternal<T
|
|
38
|
-
set(value:
|
|
37
|
+
export declare type ObjectStateInternal<T> = ObjectState<T> & {
|
|
38
|
+
set(value: T, opts?: InternalSetOpts): void;
|
|
39
39
|
};
|
|
40
40
|
declare const fragmentSym: unique symbol;
|
|
41
41
|
export declare type Fragment<V> = V & {
|
|
@@ -44,7 +44,7 @@ export declare type Fragment<V> = V & {
|
|
|
44
44
|
export declare function fragment<V>(value: V): Fragment<V>;
|
|
45
45
|
/** For a given input type `T`, decorate each field into the "field state" type that holds our form-relevant state, i.e. valid/touched/etc. */
|
|
46
46
|
declare type FieldStates<T> = {
|
|
47
|
-
[K in keyof T]-?: T[K] extends Fragment<infer V> ? FragmentField<V> : T[K] extends Array<infer U> | null | undefined ? [U] extends [Builtin] ? FieldState<T[K]> : ListFieldState<
|
|
47
|
+
[K in keyof T]-?: T[K] extends Fragment<infer V> ? FragmentField<V> : T[K] extends Array<infer U> | null | undefined ? [U] extends [Builtin] ? FieldState<T[K]> : ListFieldState<U> : T[K] extends Builtin | null | undefined ? FieldState<T[K]> : ObjectState<T[K]>;
|
|
48
48
|
};
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new `ObjectState` for a given form object `T` given config rules in `config`.
|
|
@@ -56,5 +56,5 @@ declare type FieldStates<T> = {
|
|
|
56
56
|
export declare function createObjectState<T>(config: ObjectConfig<T>, instance: T, opts?: {
|
|
57
57
|
maybeAutoSave?: () => void;
|
|
58
58
|
}): ObjectState<T>;
|
|
59
|
-
export declare function newObjectState<T, P = any>(config: ObjectConfig<T>, parentState: (() => ObjectState<P>) | undefined, parentListState: FieldState<any> | undefined, instance: T, key: keyof T | undefined, maybeAutoSave: () => void): ObjectState<T
|
|
59
|
+
export declare function newObjectState<T, P = any>(config: ObjectConfig<T>, parentState: (() => ObjectState<P>) | undefined, parentListState: FieldState<any> | undefined, instance: T, key: keyof T | undefined, maybeAutoSave: () => void): ObjectState<T>;
|
|
60
60
|
export {};
|