cross-state 0.56.4 → 1.0.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.
- package/dist/{diff-CElc7pJI.d.ts → diff-CAQaunfv.d.cts} +3 -3
- package/dist/{diff-BslUrJZE.d.cts → diff-DFvRd-Gf.d.ts} +3 -3
- package/dist/{extendedJson-BZkQBXEv.js → extendedJson-Dv9q6rps.js} +2 -2
- package/dist/{extendedJson-BZkQBXEv.js.map → extendedJson-Dv9q6rps.js.map} +1 -1
- package/dist/{extendedJson-Dn2F7Edo.cjs → extendedJson-ursQ8DbQ.cjs} +1 -1
- package/dist/{extendedJson-Dn2F7Edo.cjs.map → extendedJson-ursQ8DbQ.cjs.map} +1 -1
- package/dist/index.cjs +9 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/dist/mutative/index.cjs +2 -1
- package/dist/mutative/index.d.cts +2 -2
- package/dist/mutative/index.d.ts +2 -2
- package/dist/mutative/index.js +2 -1
- package/dist/mutative/register.cjs +4 -3
- package/dist/mutative/register.cjs.map +1 -1
- package/dist/mutative/register.d.cts +2 -4
- package/dist/mutative/register.d.ts +2 -2
- package/dist/mutative/register.js +4 -3
- package/dist/mutative/register.js.map +1 -1
- package/dist/{mutativeMethods-Bhd1Yi22.d.ts → mutativeMethods-BT1Cim3p.d.ts} +3 -3
- package/dist/{mutativeMethods-DWhwZRzv.d.cts → mutativeMethods-C8VcZWED.d.cts} +3 -3
- package/dist/{mutativeMethods-CgXk_bMt.cjs → mutativeMethods-CkNycpO9.cjs} +6 -7
- package/dist/{mutativeMethods-CgXk_bMt.cjs.map → mutativeMethods-CkNycpO9.cjs.map} +1 -1
- package/dist/{mutativeMethods-CZKeRIDL.js → mutativeMethods-Jowr0Znn.js} +4 -6
- package/dist/{mutativeMethods-CZKeRIDL.js.map → mutativeMethods-Jowr0Znn.js.map} +1 -1
- package/dist/{patchMethods-hhlLwtqE.cjs → patchMethods-B7Hm5-Qh.cjs} +4 -6
- package/dist/{patchMethods-hhlLwtqE.cjs.map → patchMethods-B7Hm5-Qh.cjs.map} +1 -1
- package/dist/{patchMethods-DXWygPZ6.d.ts → patchMethods-BmyvvHnP.d.cts} +4 -4
- package/dist/{patchMethods-BT4Tg5aG.d.cts → patchMethods-CixmHmNt.d.ts} +4 -4
- package/dist/{patchMethods-C_f3PORQ.js → patchMethods-iK2F87G0.js} +5 -7
- package/dist/{patchMethods-C_f3PORQ.js.map → patchMethods-iK2F87G0.js.map} +1 -1
- package/dist/patches/index.cjs +3 -3
- package/dist/patches/index.d.cts +3 -3
- package/dist/patches/index.d.ts +3 -3
- package/dist/patches/index.js +3 -3
- package/dist/patches/register.cjs +4 -4
- package/dist/patches/register.cjs.map +1 -1
- package/dist/patches/register.d.cts +3 -5
- package/dist/patches/register.d.ts +3 -3
- package/dist/patches/register.js +4 -4
- package/dist/patches/register.js.map +1 -1
- package/dist/{chunk-CUT6urMc.cjs → path-B-Rq5q6m.cjs} +14 -1
- package/dist/path-B-Rq5q6m.cjs.map +1 -0
- package/dist/path-CyYq74W8.js +8 -0
- package/dist/path-CyYq74W8.js.map +1 -0
- package/dist/persist/register.cjs +5 -5
- package/dist/persist/register.cjs.map +1 -1
- package/dist/persist/register.d.cts +2 -4
- package/dist/persist/register.d.ts +2 -2
- package/dist/persist/register.js +5 -5
- package/dist/persist/register.js.map +1 -1
- package/dist/{persist-CLgS5Cqw.js → persist-Bunx8xfQ.js} +12 -15
- package/dist/persist-Bunx8xfQ.js.map +1 -0
- package/dist/{persist-olbNkcdZ.d.ts → persist-CHRYYolx.d.cts} +3 -3
- package/dist/{persist-DboMIMOK.cjs → persist-DMbVdqS_.cjs} +11 -14
- package/dist/persist-DMbVdqS_.cjs.map +1 -0
- package/dist/{persist-DVKRq8RQ.d.cts → persist-DyI_JLxZ.d.ts} +3 -3
- package/dist/{propAccess-BdLsqViO.cjs → propAccess-C2AIn9RC.cjs} +4 -6
- package/dist/{propAccess-BdLsqViO.cjs.map → propAccess-C2AIn9RC.cjs.map} +1 -1
- package/dist/{propAccess-B260LXN1.js → propAccess-DvWFpYoj.js} +5 -7
- package/dist/{propAccess-B260LXN1.js.map → propAccess-DvWFpYoj.js.map} +1 -1
- package/dist/react/index.cjs +66 -80
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +70 -70
- package/dist/react/index.d.ts +70 -70
- package/dist/react/index.js +62 -77
- package/dist/react/index.js.map +1 -1
- package/dist/react/register.cjs +5 -5
- package/dist/react/register.cjs.map +1 -1
- package/dist/react/register.d.cts +3 -5
- package/dist/react/register.d.ts +3 -3
- package/dist/react/register.js +5 -5
- package/dist/react/register.js.map +1 -1
- package/dist/{scope-CfLlLxo9.cjs → scope-C1bcfK8e.cjs} +32 -7
- package/dist/scope-C1bcfK8e.cjs.map +1 -0
- package/dist/{scope-D3jkIPgn.d.ts → scope-CESkVNvI.d.cts} +3 -3
- package/dist/{scope-7LeON9bZ.js → scope-CKGsCVn3.js} +20 -7
- package/dist/scope-CKGsCVn3.js.map +1 -0
- package/dist/{scope-CcBxgcrs.d.cts → scope-DJXSRsGy.d.ts} +3 -3
- package/dist/{store-MBrcOgtz.d.cts → store-BRHFhRPm.d.ts} +21 -21
- package/dist/{store-CdST5wJZ.cjs → store-C1NYHLgR.cjs} +12 -13
- package/dist/store-C1NYHLgR.cjs.map +1 -0
- package/dist/{store-DnZ6fsiJ.d.ts → store-XcnTdeiJ.d.cts} +21 -21
- package/dist/{store-Dx8w7yT-.js → store-v3RYWzVg.js} +13 -14
- package/dist/store-v3RYWzVg.js.map +1 -0
- package/dist/{storeMethods-B_RzvMaV.cjs → storeMethods-CNu7VD6w.cjs} +135 -60
- package/dist/storeMethods-CNu7VD6w.cjs.map +1 -0
- package/dist/{storeMethods-BrKuusQ2.js → storeMethods-CQhXlHpl.js} +115 -59
- package/dist/storeMethods-CQhXlHpl.js.map +1 -0
- package/dist/{storeMethods-CmWv1YMe.d.cts → storeMethods-Dsz0-Cda.d.ts} +4 -4
- package/dist/{storeMethods-Cb1ur5K3.d.ts → storeMethods-y3PlfTHV.d.cts} +4 -4
- package/package.json +26 -37
- package/dist/hash-DNFM5y_h.js +0 -19
- package/dist/hash-DNFM5y_h.js.map +0 -1
- package/dist/hash-Dv3XlmHn.cjs +0 -30
- package/dist/hash-Dv3XlmHn.cjs.map +0 -1
- package/dist/persist-CLgS5Cqw.js.map +0 -1
- package/dist/persist-DboMIMOK.cjs.map +0 -1
- package/dist/scope-7LeON9bZ.js.map +0 -1
- package/dist/scope-CfLlLxo9.cjs.map +0 -1
- package/dist/store-CdST5wJZ.cjs.map +0 -1
- package/dist/store-Dx8w7yT-.js.map +0 -1
- package/dist/storeMethods-B_RzvMaV.cjs.map +0 -1
- package/dist/storeMethods-BrKuusQ2.js.map +0 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../scope-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import "../scope-DJXSRsGy.js";
|
|
2
|
+
import { A as GetKeys, B as Value, C as Selector, F as PathAsString, G as MaybePromise, H as WildcardPathAsString, I as SettablePath, K as Constrain, N as Path$1, T as Update, U as WildcardValue, W as Object_, b as Duration, j as Join, r as Store } from "../store-BRHFhRPm.js";
|
|
3
|
+
import { a as useScope, c as UseCacheValue, d as useStore, i as ScopeProvider, l as useCache, n as scopeMethods, o as cacheMethods, r as ScopeProps, s as UseCacheArray, t as storeMethods, u as UseStoreOptions } from "../storeMethods-Dsz0-Cda.js";
|
|
4
4
|
import { Component, ComponentPropsWithoutRef, Context, FormEvent, FunctionComponent, HTMLProps, ReactNode } from "react";
|
|
5
5
|
|
|
6
6
|
//#region src/react/form/customInput.d.ts
|
|
@@ -15,8 +15,8 @@ declare function CustomInput({
|
|
|
15
15
|
}: CustomInputProps): React.JSX.Element;
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/react/form/formField.d.ts
|
|
18
|
-
interface FormFieldComponentProps<TValue, TPath> {
|
|
19
|
-
name: TPath;
|
|
18
|
+
interface FormFieldComponentProps<TValue, TPath$1> {
|
|
19
|
+
name: TPath$1;
|
|
20
20
|
value: TValue;
|
|
21
21
|
onChange: (event: {
|
|
22
22
|
target: {
|
|
@@ -25,29 +25,29 @@ interface FormFieldComponentProps<TValue, TPath> {
|
|
|
25
25
|
} | TValue | undefined, ...args: any[]) => void;
|
|
26
26
|
onBlur: (...args: any[]) => void;
|
|
27
27
|
}
|
|
28
|
-
type FormFieldInfos<TDraft, TOriginal, TPath extends string> = Field<TDraft, TOriginal, TPath> & {
|
|
28
|
+
type FormFieldInfos<TDraft, TOriginal, TPath$1 extends string> = Field<TDraft, TOriginal, TPath$1> & {
|
|
29
29
|
hasTriggeredValidations: boolean;
|
|
30
30
|
};
|
|
31
31
|
type NativeInputType = "input" | "select" | "textarea";
|
|
32
32
|
type PartialComponentType<P> = (new (props: P, context?: any) => Component<P, any>) | ((props: P, context?: any) => ReactNode);
|
|
33
33
|
type FormFieldComponent = NativeInputType | PartialComponentType<any>;
|
|
34
|
-
type FieldValue<T extends FormFieldComponent> = ComponentPropsWithoutRef<T>["value"];
|
|
35
|
-
type FieldChangeValue<T extends FormFieldComponent> = ComponentPropsWithoutRef<T> extends {
|
|
34
|
+
type FieldValue<T$1 extends FormFieldComponent> = ComponentPropsWithoutRef<T$1>["value"];
|
|
35
|
+
type FieldChangeValue<T$1 extends FormFieldComponent> = ComponentPropsWithoutRef<T$1> extends {
|
|
36
36
|
onChange?: (update: infer U) => void;
|
|
37
37
|
} ? U extends {
|
|
38
38
|
target: {
|
|
39
39
|
value: infer V;
|
|
40
40
|
};
|
|
41
41
|
} ? V : U : never;
|
|
42
|
-
type MakeOptional<T, Keys extends string> = Omit<T, Keys> & Partial<Pick<T, Keys & keyof T>>;
|
|
43
|
-
type FormFieldProps<TPath, TDraft> = {
|
|
44
|
-
name: TPath & PathAsString<TDraft>;
|
|
42
|
+
type MakeOptional<T$1, Keys extends string> = Omit<T$1, Keys> & Partial<Pick<T$1, Keys & keyof T$1>>;
|
|
43
|
+
type FormFieldProps<TPath$1, TDraft> = {
|
|
44
|
+
name: TPath$1 & PathAsString<TDraft>;
|
|
45
45
|
commitOnBlur?: boolean;
|
|
46
46
|
commitDebounce?: number;
|
|
47
47
|
};
|
|
48
|
-
type FormFieldPropsWithRender<TDraft, TOriginal, TPath extends string> = FormFieldProps<TPath, TDraft> & NoInfer<{
|
|
48
|
+
type FormFieldPropsWithRender<TDraft, TOriginal, TPath$1 extends string> = FormFieldProps<TPath$1, TDraft> & NoInfer<{
|
|
49
49
|
component?: undefined;
|
|
50
|
-
render: (props: FormFieldComponentProps<Value<TDraft, TPath>, TPath>, info: FormFieldInfos<TDraft, TOriginal, TPath>, form: FormContext<TDraft, TOriginal>) => ReactNode;
|
|
50
|
+
render: (props: FormFieldComponentProps<Value<TDraft, TPath$1>, TPath$1>, info: FormFieldInfos<TDraft, TOriginal, TPath$1>, form: FormContext<TDraft, TOriginal>) => ReactNode;
|
|
51
51
|
inputFilter?: undefined;
|
|
52
52
|
defaultValue?: undefined;
|
|
53
53
|
serialize?: undefined;
|
|
@@ -55,43 +55,43 @@ type FormFieldPropsWithRender<TDraft, TOriginal, TPath extends string> = FormFie
|
|
|
55
55
|
onChange?: undefined;
|
|
56
56
|
onBlur?: undefined;
|
|
57
57
|
}>;
|
|
58
|
-
type Serialize<TDraft, TOriginal, TPath, TComponent extends FormFieldComponent> = (value: Value<TDraft, TPath>, formState: FormInstance<TDraft, TOriginal>) => FieldValue<TComponent>;
|
|
59
|
-
type Deserialize<TDraft, TOriginal, TPath, TComponent extends FormFieldComponent> = (value: FieldChangeValue<TComponent>, formState: FormInstance<TDraft, TOriginal>) => Value<TDraft, TPath>;
|
|
60
|
-
type FormFieldPropsWithComponent<TDraft, TOriginal, TPath extends string, TComponent extends FormFieldComponent> = FormFieldProps<TPath, TDraft> & {
|
|
58
|
+
type Serialize<TDraft, TOriginal, TPath$1, TComponent extends FormFieldComponent> = (value: Value<TDraft, TPath$1>, formState: FormInstance<TDraft, TOriginal>) => FieldValue<TComponent>;
|
|
59
|
+
type Deserialize<TDraft, TOriginal, TPath$1, TComponent extends FormFieldComponent> = (value: FieldChangeValue<TComponent>, formState: FormInstance<TDraft, TOriginal>) => Value<TDraft, TPath$1>;
|
|
60
|
+
type FormFieldPropsWithComponent<TDraft, TOriginal, TPath$1 extends string, TComponent extends FormFieldComponent> = FormFieldProps<TPath$1, TDraft> & {
|
|
61
61
|
component?: TComponent;
|
|
62
62
|
render?: undefined;
|
|
63
63
|
} & NoInfer<{
|
|
64
64
|
inputFilter?: (value: FieldChangeValue<TComponent>) => boolean;
|
|
65
|
-
} & MakeOptional<Omit<ComponentPropsWithoutRef<TComponent>, "id" | "name" | "value" | "defaultValue">, "onChange" | "onBlur"> & (Value<TDraft, TPath> extends Exclude<FieldValue<TComponent>, undefined> ? {
|
|
65
|
+
} & MakeOptional<Omit<ComponentPropsWithoutRef<TComponent>, "id" | "name" | "value" | "defaultValue">, "onChange" | "onBlur"> & (Value<TDraft, TPath$1> extends Exclude<FieldValue<TComponent>, undefined> ? {
|
|
66
66
|
defaultValue?: FieldValue<TComponent>;
|
|
67
|
-
serialize?: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
68
|
-
} : Value<TDraft, TPath> extends FieldValue<TComponent> ? {
|
|
67
|
+
serialize?: Serialize<TDraft, TOriginal, TPath$1, TComponent>;
|
|
68
|
+
} : Value<TDraft, TPath$1> extends FieldValue<TComponent> ? {
|
|
69
69
|
defaultValue: FieldValue<TComponent>;
|
|
70
|
-
serialize?: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
70
|
+
serialize?: Serialize<TDraft, TOriginal, TPath$1, TComponent>;
|
|
71
71
|
} | {
|
|
72
72
|
defaultValue?: FieldValue<TComponent>;
|
|
73
|
-
serialize: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
73
|
+
serialize: Serialize<TDraft, TOriginal, TPath$1, TComponent>;
|
|
74
74
|
} : {
|
|
75
|
-
serialize: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
76
|
-
}) & (FieldChangeValue<TComponent> extends Value<TDraft, TPath> ? {
|
|
77
|
-
deserialize?: Deserialize<TDraft, TOriginal, TPath, TComponent>;
|
|
75
|
+
serialize: Serialize<TDraft, TOriginal, TPath$1, TComponent>;
|
|
76
|
+
}) & (FieldChangeValue<TComponent> extends Value<TDraft, TPath$1> ? {
|
|
77
|
+
deserialize?: Deserialize<TDraft, TOriginal, TPath$1, TComponent>;
|
|
78
78
|
} : {
|
|
79
|
-
deserialize: Deserialize<TDraft, TOriginal, TPath, TComponent>;
|
|
79
|
+
deserialize: Deserialize<TDraft, TOriginal, TPath$1, TComponent>;
|
|
80
80
|
})>;
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region src/react/form/formForEach.d.ts
|
|
83
|
-
type ElementName<TDraft, TPath extends string> = keyof { [Path in TPath as Join<Path, GetKeys<NonNullable<Value<TDraft, Path>>> & (string | number)>]: 1 };
|
|
84
|
-
interface FormForEachProps<TDraft, TPath extends string> {
|
|
85
|
-
name: TPath & PathAsString<TDraft>;
|
|
83
|
+
type ElementName<TDraft, TPath$1 extends string> = keyof { [Path in TPath$1 as Join<Path, GetKeys<NonNullable<Value<TDraft, Path>>> & (string | number)>]: 1 };
|
|
84
|
+
interface FormForEachProps<TDraft, TPath$1 extends string> {
|
|
85
|
+
name: TPath$1 & PathAsString<TDraft>;
|
|
86
86
|
renderElement?: (props: {
|
|
87
|
-
name: ElementName<TDraft, TPath>;
|
|
88
|
-
key: `${GetKeys<NonNullable<Value<TDraft, TPath>>> & (string | number)}`;
|
|
87
|
+
name: ElementName<TDraft, TPath$1>;
|
|
88
|
+
key: `${GetKeys<NonNullable<Value<TDraft, TPath$1>>> & (string | number)}`;
|
|
89
89
|
index: number;
|
|
90
90
|
remove: () => void;
|
|
91
91
|
}) => ReactNode;
|
|
92
92
|
children?: (props: {
|
|
93
|
-
setValue: (value: Value<TDraft, TPath> | ((value: Value<TDraft, TPath>) => Value<TDraft, TPath>)) => void;
|
|
94
|
-
} & FieldHelperMethods<TDraft, TPath>) => ReactNode;
|
|
93
|
+
setValue: (value: Value<TDraft, TPath$1> | ((value: Value<TDraft, TPath$1>) => Value<TDraft, TPath$1>)) => void;
|
|
94
|
+
} & FieldHelperMethods<TDraft, TPath$1>) => ReactNode;
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
97
|
//#region src/react/form/useFormAutosave.d.ts
|
|
@@ -114,23 +114,23 @@ interface FormOptions<TDraft, TOriginal> {
|
|
|
114
114
|
validatedClass?: string;
|
|
115
115
|
}
|
|
116
116
|
type Validations<TDraft, TOriginal> = { [TPath in WildcardPathAsString<TDraft>]?: Record<string, Validation<TDraft, TOriginal, TPath>> } & Record<string, Record<string, Validation<TDraft, TOriginal, any>>>;
|
|
117
|
-
type Validation<TDraft, TOriginal, TPath> = (value: WildcardValue<TDraft, TPath>, context: {
|
|
117
|
+
type Validation<TDraft, TOriginal, TPath$1> = (value: WildcardValue<TDraft, TPath$1>, context: {
|
|
118
118
|
draft: TDraft;
|
|
119
119
|
original: TOriginal;
|
|
120
120
|
field: PathAsString<TDraft> | "";
|
|
121
121
|
}) => boolean;
|
|
122
|
-
type Field<TDraft, TOriginal, TPath extends string> = {
|
|
123
|
-
originalValue: Value<TOriginal, TPath> | undefined;
|
|
124
|
-
value: Value<TDraft, TPath>;
|
|
125
|
-
setValue: (value: Update<Value<TDraft, TPath>>) => void;
|
|
122
|
+
type Field<TDraft, TOriginal, TPath$1 extends string> = {
|
|
123
|
+
originalValue: Value<TOriginal, TPath$1> | undefined;
|
|
124
|
+
value: Value<TDraft, TPath$1>;
|
|
125
|
+
setValue: (value: Update<Value<TDraft, TPath$1>>) => void;
|
|
126
126
|
removeValue: () => void;
|
|
127
127
|
hasChange: boolean;
|
|
128
128
|
errors: string[];
|
|
129
|
-
} & (Value<TDraft, TPath> extends Object_ ? FieldHelperMethods<TDraft, TPath> : {});
|
|
130
|
-
type FieldHelperMethods<TDraft, TPath extends string> = {
|
|
131
|
-
names: ElementName<TDraft, TPath>[];
|
|
132
|
-
add: NonNullable<Value<TDraft, TPath>> extends readonly (infer T)[] ? (element: T) => void : NonNullable<Value<TDraft, TPath>> extends Record<infer K, infer V> ? (key: K, value: V) => void : never;
|
|
133
|
-
remove: Value<TDraft, TPath> extends readonly any[] ? (index: number) => void : (key: string) => void;
|
|
129
|
+
} & (Value<TDraft, TPath$1> extends Object_ ? FieldHelperMethods<TDraft, TPath$1> : {});
|
|
130
|
+
type FieldHelperMethods<TDraft, TPath$1 extends string> = {
|
|
131
|
+
names: ElementName<TDraft, TPath$1>[];
|
|
132
|
+
add: NonNullable<Value<TDraft, TPath$1>> extends readonly (infer T)[] ? (element: T) => void : NonNullable<Value<TDraft, TPath$1>> extends Record<infer K, infer V> ? (key: K, value: V) => void : never;
|
|
133
|
+
remove: Value<TDraft, TPath$1> extends readonly any[] ? (index: number) => void : (key: string) => void;
|
|
134
134
|
};
|
|
135
135
|
interface FormState<TDraft> {
|
|
136
136
|
draft: TDraft | undefined;
|
|
@@ -151,7 +151,7 @@ interface FormContext<TDraft, TOriginal> {
|
|
|
151
151
|
formState: Store<FormState<TDraft>>;
|
|
152
152
|
options: FormOptions<TDraft, TOriginal>;
|
|
153
153
|
original: TOriginal | undefined;
|
|
154
|
-
getField: <TPath extends string>(path: TPath) => Field<TDraft, TOriginal, TPath>;
|
|
154
|
+
getField: <TPath$1 extends string>(path: TPath$1) => Field<TDraft, TOriginal, TPath$1>;
|
|
155
155
|
getDraft: () => TDraft;
|
|
156
156
|
hasTriggeredValidations: () => boolean;
|
|
157
157
|
saveScheduled: () => boolean;
|
|
@@ -169,7 +169,7 @@ declare class Form<TDraft, TOriginal extends TDraft = TDraft> {
|
|
|
169
169
|
constructor(options: FormOptions<TDraft, TOriginal>);
|
|
170
170
|
useForm(): FormContext<TDraft, TOriginal>;
|
|
171
171
|
useFormState<S>(selector: (state: FormInstance<TDraft, TOriginal>) => S, useStoreOptions?: UseStoreOptions<S>): S;
|
|
172
|
-
useField<TPath extends string>(path: TPath, useStoreOptions?: UseStoreOptions<any>): Field<TDraft, TOriginal, TPath>;
|
|
172
|
+
useField<TPath$1 extends string>(path: TPath$1, useStoreOptions?: UseStoreOptions<any>): Field<TDraft, TOriginal, TPath$1>;
|
|
173
173
|
Form({
|
|
174
174
|
original,
|
|
175
175
|
defaultValue,
|
|
@@ -190,9 +190,9 @@ declare class Form<TDraft, TOriginal extends TDraft = TDraft> {
|
|
|
190
190
|
selector: (form: FormInstance<TDraft, TOriginal>) => S;
|
|
191
191
|
children: (selectedState: S) => ReactNode;
|
|
192
192
|
}): React.JSX.Element;
|
|
193
|
-
Field<const TPath extends string>(props: FormFieldPropsWithRender<TDraft, TOriginal, TPath>): React.JSX.Element;
|
|
194
|
-
Field<const TPath extends string, const TComponent extends FormFieldComponent = "input">(props: FormFieldPropsWithComponent<TDraft, TOriginal, TPath, TComponent>): React.JSX.Element;
|
|
195
|
-
ForEach<const TPath extends string>(props: FormForEachProps<TDraft, TPath>): React.JSX.Element;
|
|
193
|
+
Field<const TPath$1 extends string>(props: FormFieldPropsWithRender<TDraft, TOriginal, TPath$1>): React.JSX.Element;
|
|
194
|
+
Field<const TPath$1 extends string, const TComponent extends FormFieldComponent = "input">(props: FormFieldPropsWithComponent<TDraft, TOriginal, TPath$1, TComponent>): React.JSX.Element;
|
|
195
|
+
ForEach<const TPath$1 extends string>(props: FormForEachProps<TDraft, TPath$1>): React.JSX.Element;
|
|
196
196
|
withForm<TProps extends Record<string, unknown>>(Component: React.ComponentType<TProps>, formProps?: Parameters<this["Form"]>[0]): FunctionComponent<TProps>;
|
|
197
197
|
}
|
|
198
198
|
declare function createForm<TDraft, TOriginal extends TDraft = TDraft>(options: FormOptions<TDraft, TOriginal>): Form<TDraft, TOriginal>;
|
|
@@ -224,34 +224,34 @@ declare function LoadingBoundary({
|
|
|
224
224
|
declare function useLoadingBoundary(isLoading: boolean | undefined, label?: ReactNode): void;
|
|
225
225
|
//#endregion
|
|
226
226
|
//#region src/react/url/urlOptions.d.ts
|
|
227
|
-
interface UrlOptions<T> {
|
|
227
|
+
interface UrlOptions<T$1> {
|
|
228
228
|
key: string;
|
|
229
229
|
type?: "search" | "hash";
|
|
230
|
-
serialize?: (value: T) => string;
|
|
231
|
-
deserialize?: (value: string) => T;
|
|
232
|
-
defaultValue: T;
|
|
230
|
+
serialize?: (value: T$1) => string;
|
|
231
|
+
deserialize?: (value: string) => T$1;
|
|
232
|
+
defaultValue: T$1;
|
|
233
233
|
writeDefaultValue?: boolean;
|
|
234
|
-
onCommit?: (value: T) => void;
|
|
234
|
+
onCommit?: (value: T$1) => void;
|
|
235
235
|
persist?: {
|
|
236
236
|
id: string;
|
|
237
237
|
} | null;
|
|
238
238
|
path?: string | RegExp | (string | RegExp)[] | null;
|
|
239
239
|
}
|
|
240
|
-
interface UrlOptionsWithoutDefaults<T> extends Omit<UrlOptions<T | undefined>, "defaultValue"> {
|
|
241
|
-
defaultValue?: T | undefined;
|
|
240
|
+
interface UrlOptionsWithoutDefaults<T$1> extends Omit<UrlOptions<T$1 | undefined>, "defaultValue"> {
|
|
241
|
+
defaultValue?: T$1 | undefined;
|
|
242
242
|
}
|
|
243
|
-
declare function createUrlOptions<T>(options: UrlOptions<T>): Required<UrlOptions<T>>;
|
|
244
|
-
declare function createUrlOptions<T>(options: UrlOptionsWithoutDefaults<T>): Required<UrlOptions<T | undefined>>;
|
|
243
|
+
declare function createUrlOptions<T$1>(options: UrlOptions<T$1>): Required<UrlOptions<T$1>>;
|
|
244
|
+
declare function createUrlOptions<T$1>(options: UrlOptionsWithoutDefaults<T$1>): Required<UrlOptions<T$1 | undefined>>;
|
|
245
245
|
//#endregion
|
|
246
246
|
//#region src/react/url/urlParamStore.d.ts
|
|
247
247
|
declare const urlStore: Store<string>;
|
|
248
|
-
declare class UrlParamStore<T> extends Store<T> {
|
|
249
|
-
readonly urlOptions: Required<UrlOptions<T>>;
|
|
248
|
+
declare class UrlParamStore<T$1> extends Store<T$1> {
|
|
249
|
+
readonly urlOptions: Required<UrlOptions<T$1>>;
|
|
250
250
|
readonly storageKey: string | null;
|
|
251
251
|
private lastHref?;
|
|
252
252
|
private lastStorageValue?;
|
|
253
253
|
private lastValue?;
|
|
254
|
-
constructor(urlOptions: Required<UrlOptions<T>>);
|
|
254
|
+
constructor(urlOptions: Required<UrlOptions<T$1>>);
|
|
255
255
|
private watch;
|
|
256
256
|
private getUrlValue;
|
|
257
257
|
private getStorageValue;
|
|
@@ -259,25 +259,25 @@ declare class UrlParamStore<T> extends Store<T> {
|
|
|
259
259
|
private calc;
|
|
260
260
|
private updateUrl;
|
|
261
261
|
private updateStorage;
|
|
262
|
-
set(update: Update<T>): void;
|
|
263
|
-
set<const P>(path: Constrain<P, Path$1<T>>, update: Update<Value<T, P>>): void;
|
|
264
|
-
parse(path: string): T;
|
|
262
|
+
set(update: Update<T$1>): void;
|
|
263
|
+
set<const P>(path: Constrain<P, Path$1<T$1>>, update: Update<Value<T$1, P>>): void;
|
|
264
|
+
parse(path: string): T$1;
|
|
265
265
|
}
|
|
266
|
-
declare function createUrlParam<T>(options: UrlOptions<T>): UrlParamStore<T>;
|
|
267
|
-
declare function createUrlParam<T>(options: UrlOptionsWithoutDefaults<T>): UrlParamStore<T | undefined>;
|
|
266
|
+
declare function createUrlParam<T$1>(options: UrlOptions<T$1>): UrlParamStore<T$1>;
|
|
267
|
+
declare function createUrlParam<T$1>(options: UrlOptionsWithoutDefaults<T$1>): UrlParamStore<T$1 | undefined>;
|
|
268
268
|
//#endregion
|
|
269
269
|
//#region src/react/useDecoupledState.d.ts
|
|
270
|
-
interface UseDecoupledStateOptions<T> {
|
|
270
|
+
interface UseDecoupledStateOptions<T$1> {
|
|
271
271
|
debounce?: Duration;
|
|
272
272
|
throttle?: Duration;
|
|
273
|
-
onCommit?: (value: T) => void;
|
|
273
|
+
onCommit?: (value: T$1) => void;
|
|
274
274
|
}
|
|
275
|
-
declare function useDecoupledState<T>(value: T, onChange: (value: T) => void, options?: UseDecoupledStateOptions<T>): [state: T, setState: (value: T) => void];
|
|
275
|
+
declare function useDecoupledState<T$1>(value: T$1, onChange: (value: T$1) => void, options?: UseDecoupledStateOptions<T$1>): [state: T$1, setState: (value: T$1) => void];
|
|
276
276
|
//#endregion
|
|
277
277
|
//#region src/react/useProp.d.ts
|
|
278
|
-
declare function useProp<T, S>(store: Store<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>["set"]];
|
|
279
|
-
declare function useProp<T, const P>(store: Store<T>, selector: Constrain<P,
|
|
280
|
-
declare function useProp<T>(store: Store<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>["set"]];
|
|
278
|
+
declare function useProp<T$1, S>(store: Store<T$1>, selector: Selector<T$1, S>, updater: (value: S) => Update<T$1>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>["set"]];
|
|
279
|
+
declare function useProp<T$1, const P>(store: Store<T$1>, selector: Constrain<P, SettablePath<T$1>>, options?: UseStoreOptions<Value<T$1, P>>): [value: Value<T$1, P>, setValue: Store<Value<T$1, P>>["set"]];
|
|
280
|
+
declare function useProp<T$1>(store: Store<T$1>, options?: UseStoreOptions<T$1>): [value: T$1, setValue: Store<T$1>["set"]];
|
|
281
281
|
//#endregion
|
|
282
282
|
export { CustomInput, CustomInputProps, Field, Form, FormContext, FormDerivedState, FormFieldComponent, FormFieldComponentProps, FormFieldInfos, FormFieldProps, FormFieldPropsWithComponent, FormFieldPropsWithRender, FormInstance, FormOptions, FormState, LoadingBoundary, type LoadingBoundaryEntry, type LoadingBoundaryProps, type ScopeProps, ScopeProvider, Transform, type UrlOptions, type UrlOptionsWithoutDefaults, type UrlParamStore, type UseCacheArray, type UseCacheValue, type UseDecoupledStateOptions, type UseStoreOptions, Validation, Validations, cacheMethods, createForm, createUrlOptions, createUrlParam, scopeMethods, storeMethods, urlStore, useCache, useDecoupledState, useLoadingBoundary, useProp, useScope, useStore };
|
|
283
283
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/react/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { c as debounce, d as queue, h as autobind, m as calcDuration, n as createStore, r as throttle, t as Store } from "../store-v3RYWzVg.js";
|
|
2
|
+
import { a as set, c as deepEqual, n as get, o as isObject, r as join, t as castArrayPath } from "../propAccess-DvWFpYoj.js";
|
|
3
|
+
import { i as toExtendedJsonString, n as fromExtendedJsonString } from "../extendedJson-Dv9q6rps.js";
|
|
4
|
+
import "../path-CyYq74W8.js";
|
|
5
|
+
import { a as useProp, c as cacheMethods, d as useLoadingBoundary, f as useStore, i as useScope, l as useCache, n as scopeMethods, o as useLatestFunction, p as useMemoEquals, r as ScopeProvider, s as useLatestRef, t as storeMethods, u as LoadingBoundary } from "../storeMethods-CQhXlHpl.js";
|
|
6
6
|
import { Fragment, createContext, createElement, startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
|
|
@@ -106,21 +106,17 @@ function FormField({ name = "", component, commitOnBlur, commitDebounce, render,
|
|
|
106
106
|
function FormForEach({ name, renderElement, children }) {
|
|
107
107
|
const form = this.useForm();
|
|
108
108
|
const names = this.useFormState(() => {
|
|
109
|
-
|
|
110
|
-
return field.names;
|
|
109
|
+
return form.getField(name).names;
|
|
111
110
|
});
|
|
112
111
|
const add = useCallback((...args) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}, [form]);
|
|
112
|
+
form.getField(name).add(...args);
|
|
113
|
+
}, [form, name]);
|
|
116
114
|
const remove = useCallback((key) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}, [form]);
|
|
115
|
+
form.getField(name).remove(key);
|
|
116
|
+
}, [form, name]);
|
|
120
117
|
const setValue = useCallback((value) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}, [form]);
|
|
118
|
+
form.getField(name).setValue(value);
|
|
119
|
+
}, [form, name]);
|
|
124
120
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [renderElement && names.map((name$1, index) => {
|
|
125
121
|
const key = name$1.split(".").pop();
|
|
126
122
|
return /* @__PURE__ */ jsx(Fragment, { children: renderElement({
|
|
@@ -140,39 +136,38 @@ function FormForEach({ name, renderElement, children }) {
|
|
|
140
136
|
//#endregion
|
|
141
137
|
//#region src/react/form/useFormAutosave.ts
|
|
142
138
|
function useFormAutosave(form) {
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const latestRef = useRef({ options });
|
|
139
|
+
const debounceTime = calcDuration(form.options.autoSave?.debounce ?? 2e3);
|
|
140
|
+
const latestRef = useLatestRef(form);
|
|
146
141
|
const lastValue = useRef(void 0);
|
|
147
142
|
const q = useMemo(() => queue(), []);
|
|
148
143
|
const run = useMemo(() => debounce(async () => {
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const draft = getDraft();
|
|
144
|
+
const save = latestRef.current.options.autoSave?.save;
|
|
145
|
+
const draft = latestRef.current.getDraft();
|
|
152
146
|
lastValue.current = draft;
|
|
153
147
|
q.clear();
|
|
154
148
|
q(async () => {
|
|
155
149
|
try {
|
|
156
|
-
formState.set("saveInProgress", true);
|
|
157
|
-
await save?.(draft,
|
|
158
|
-
if (q.size === 0 && options
|
|
150
|
+
latestRef.current.formState.set("saveInProgress", true);
|
|
151
|
+
await save?.(draft, latestRef.current);
|
|
152
|
+
if (q.size === 0 && latestRef.current.options.autoSave?.resetAfterSave) latestRef.current.reset();
|
|
159
153
|
} finally {
|
|
160
|
-
formState.set("saveInProgress", false);
|
|
161
|
-
if (q.size === 0) formState.set("saveScheduled", false);
|
|
154
|
+
latestRef.current.formState.set("saveInProgress", false);
|
|
155
|
+
if (q.size === 0) latestRef.current.formState.set("saveScheduled", false);
|
|
162
156
|
}
|
|
163
157
|
});
|
|
164
|
-
}, debounceTime), [
|
|
158
|
+
}, debounceTime), [
|
|
159
|
+
latestRef,
|
|
160
|
+
debounceTime,
|
|
161
|
+
q
|
|
162
|
+
]);
|
|
165
163
|
useEffect(() => {
|
|
166
|
-
if (!options.autoSave?.save) return;
|
|
167
|
-
return formState.map((state) => state.draft).subscribe(() => {
|
|
168
|
-
if (deepEqual(getDraft(), lastValue.current)) return;
|
|
164
|
+
if (!latestRef.current.options.autoSave?.save) return;
|
|
165
|
+
return latestRef.current.formState.map((state) => state.draft).subscribe(() => {
|
|
166
|
+
if (deepEqual(latestRef.current.getDraft(), lastValue.current)) return;
|
|
169
167
|
run();
|
|
170
|
-
formState.set("saveScheduled", true);
|
|
168
|
+
latestRef.current.formState.set("saveScheduled", true);
|
|
171
169
|
}, { runNow: false });
|
|
172
|
-
}, [
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
latestRef.current = { options };
|
|
175
|
-
});
|
|
170
|
+
}, [latestRef, run]);
|
|
176
171
|
}
|
|
177
172
|
|
|
178
173
|
//#endregion
|
|
@@ -181,7 +176,7 @@ function FormContainer({ form,...formProps }) {
|
|
|
181
176
|
const formInstance = form.useForm();
|
|
182
177
|
const hasTriggeredValidations = form.useFormState((state) => state.hasTriggeredValidations);
|
|
183
178
|
const formRef = useRef(null);
|
|
184
|
-
|
|
179
|
+
const updateValidity = useLatestFunction((errors, buttonElement) => {
|
|
185
180
|
const formElement = formRef.current;
|
|
186
181
|
if (!formElement) return;
|
|
187
182
|
const localizedErrors = new Map([...errors.entries()].map(([field, errors$1]) => [field, errors$1.map((error) => formInstance.options.localizeError?.(error, field) ?? error)]));
|
|
@@ -190,10 +185,10 @@ function FormContainer({ form,...formProps }) {
|
|
|
190
185
|
const errorString = [...errors.values()].flat().join("\n");
|
|
191
186
|
buttonElement.setCustomValidity(errorString);
|
|
192
187
|
}
|
|
193
|
-
}
|
|
188
|
+
});
|
|
194
189
|
useEffect(() => {
|
|
195
190
|
return formInstance.formState.map(() => formInstance.getErrors()).subscribe((errors) => updateValidity(errors));
|
|
196
|
-
}, []);
|
|
191
|
+
}, [formInstance, updateValidity]);
|
|
197
192
|
return /* @__PURE__ */ jsx("form", {
|
|
198
193
|
ref: formRef,
|
|
199
194
|
noValidate: true,
|
|
@@ -208,8 +203,7 @@ function FormContainer({ form,...formProps }) {
|
|
|
208
203
|
const buttonElement = event.nativeEvent instanceof SubmitEvent && event.nativeEvent.submitter instanceof HTMLButtonElement ? event.nativeEvent.submitter : void 0;
|
|
209
204
|
updateValidity(formInstance.getErrors(), buttonElement);
|
|
210
205
|
formElement.reportValidity();
|
|
211
|
-
|
|
212
|
-
if (isValid) await formProps.onSubmit?.(event, {
|
|
206
|
+
if (formInstance.validate()) await formProps.onSubmit?.(event, {
|
|
213
207
|
...formInstance,
|
|
214
208
|
...getDerivedState(formInstance)
|
|
215
209
|
});
|
|
@@ -220,13 +214,12 @@ function FormContainer({ form,...formProps }) {
|
|
|
220
214
|
});
|
|
221
215
|
}
|
|
222
216
|
function getField(form, path) {
|
|
223
|
-
|
|
217
|
+
return {
|
|
224
218
|
get originalValue() {
|
|
225
219
|
return form.original !== void 0 ? get(form.original, path) : void 0;
|
|
226
220
|
},
|
|
227
221
|
get value() {
|
|
228
|
-
|
|
229
|
-
return get(draft ?? form.original ?? form.options.defaultValue, path);
|
|
222
|
+
return get(form.getDraft() ?? form.original ?? form.options.defaultValue, path);
|
|
230
223
|
},
|
|
231
224
|
setValue(update) {
|
|
232
225
|
form.formState.set("draft", (draft = form.original ?? form.options.defaultValue) => {
|
|
@@ -238,8 +231,7 @@ function getField(form, path) {
|
|
|
238
231
|
return !deepEqual(this.originalValue, this.value, { undefinedEqualsAbsent: true });
|
|
239
232
|
},
|
|
240
233
|
get errors() {
|
|
241
|
-
|
|
242
|
-
return errors.get(path) ?? [];
|
|
234
|
+
return form.getErrors().get(path) ?? [];
|
|
243
235
|
},
|
|
244
236
|
get names() {
|
|
245
237
|
const { value } = this;
|
|
@@ -270,7 +262,6 @@ function getField(form, path) {
|
|
|
270
262
|
});
|
|
271
263
|
}
|
|
272
264
|
};
|
|
273
|
-
return field;
|
|
274
265
|
}
|
|
275
266
|
function getErrors(draft, original, validations) {
|
|
276
267
|
const errors = /* @__PURE__ */ new Map();
|
|
@@ -424,8 +415,9 @@ var Form = class Form {
|
|
|
424
415
|
});
|
|
425
416
|
}, [
|
|
426
417
|
original,
|
|
427
|
-
defaultValue,
|
|
428
|
-
options.transform
|
|
418
|
+
options.defaultValue,
|
|
419
|
+
options.transform,
|
|
420
|
+
formState
|
|
429
421
|
]);
|
|
430
422
|
useFormAutosave(context);
|
|
431
423
|
return /* @__PURE__ */ jsx(this.context.Provider, {
|
|
@@ -437,8 +429,7 @@ var Form = class Form {
|
|
|
437
429
|
});
|
|
438
430
|
}
|
|
439
431
|
FormState({ selector, children }) {
|
|
440
|
-
|
|
441
|
-
return /* @__PURE__ */ jsx(Fragment$1, { children: children(selectedState) });
|
|
432
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: children(this.useFormState(selector)) });
|
|
442
433
|
}
|
|
443
434
|
Field(props) {
|
|
444
435
|
return Reflect.apply(FormField, this, [{
|
|
@@ -472,11 +463,11 @@ function castArray(value) {
|
|
|
472
463
|
//#endregion
|
|
473
464
|
//#region src/react/url/urlHelpers.ts
|
|
474
465
|
function defaultDeserializer(value) {
|
|
475
|
-
if (value === void 0) return
|
|
466
|
+
if (value === void 0) return;
|
|
476
467
|
try {
|
|
477
468
|
return fromExtendedJsonString(value);
|
|
478
469
|
} catch {
|
|
479
|
-
return
|
|
470
|
+
return;
|
|
480
471
|
}
|
|
481
472
|
}
|
|
482
473
|
function defaultSerializer(value) {
|
|
@@ -560,8 +551,7 @@ var UrlParamStore = class UrlParamStore extends Store {
|
|
|
560
551
|
getUrlValue() {
|
|
561
552
|
const href = urlStore.get();
|
|
562
553
|
const url = new URL(href);
|
|
563
|
-
|
|
564
|
-
return params.get(this.urlOptions.key);
|
|
554
|
+
return new URLSearchParams(url[this.urlOptions.type].slice(1) || "").get(this.urlOptions.key);
|
|
565
555
|
}
|
|
566
556
|
getStorageValue() {
|
|
567
557
|
return this.storageKey !== null ? localStorage.getItem(this.storageKey) : null;
|
|
@@ -580,8 +570,7 @@ var UrlParamStore = class UrlParamStore extends Store {
|
|
|
580
570
|
if (!this.isPathActive() && this.lastHref !== void 0) href = this.lastHref;
|
|
581
571
|
if (this.lastHref === href && this.lastStorageValue === storageValue) return this.lastValue;
|
|
582
572
|
const url = new URL(href);
|
|
583
|
-
const
|
|
584
|
-
const urlValue = params.get(this.urlOptions.key);
|
|
573
|
+
const urlValue = new URLSearchParams(url[this.urlOptions.type].slice(1)).get(this.urlOptions.key);
|
|
585
574
|
const value = urlValue !== null ? this.urlOptions.deserialize(urlValue) : this.storageKey !== null && storageValue !== null ? this.urlOptions.deserialize(storageValue) : this.urlOptions.defaultValue;
|
|
586
575
|
this.lastHref = href;
|
|
587
576
|
this.lastStorageValue = storageValue;
|
|
@@ -609,16 +598,14 @@ var UrlParamStore = class UrlParamStore extends Store {
|
|
|
609
598
|
if (update instanceof Function) {
|
|
610
599
|
const before = this.get();
|
|
611
600
|
const valueBefore = get(before, path);
|
|
612
|
-
|
|
613
|
-
update = set(before, path, valueAfter);
|
|
601
|
+
update = set(before, path, update(valueBefore));
|
|
614
602
|
} else if (path.length > 0) update = set(this.get(), path, update);
|
|
615
603
|
if (this.isPathActive()) this.updateUrl(update);
|
|
616
604
|
else this.updateStorage(update);
|
|
617
605
|
}
|
|
618
606
|
parse(path) {
|
|
619
607
|
const url = new URL(path, window.location.href);
|
|
620
|
-
const
|
|
621
|
-
const urlValue = params.get(this.urlOptions.key);
|
|
608
|
+
const urlValue = new URLSearchParams(url[this.urlOptions.type].slice(1) || "").get(this.urlOptions.key);
|
|
622
609
|
return urlValue !== null ? this.urlOptions.deserialize(urlValue) : this.urlOptions.defaultValue;
|
|
623
610
|
}
|
|
624
611
|
};
|
|
@@ -630,32 +617,30 @@ function createUrlParam(options) {
|
|
|
630
617
|
//#region src/react/useDecoupledState.ts
|
|
631
618
|
function useDecoupledState(value, onChange, options = {}) {
|
|
632
619
|
const [dirty, setDirty] = useState();
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
useEffect(() => {
|
|
638
|
-
ref.current = {
|
|
639
|
-
onChange,
|
|
640
|
-
onCommit: options.onCommit
|
|
641
|
-
};
|
|
642
|
-
}, [onChange]);
|
|
620
|
+
const latestOnChange = useLatestFunction(onChange);
|
|
621
|
+
const latestOnCommit = useLatestFunction(options.onCommit ?? (() => {}));
|
|
622
|
+
const debounceOptions = useMemoEquals(options.debounce);
|
|
623
|
+
const throttleOptions = useMemoEquals(options.throttle);
|
|
643
624
|
const update = useMemo(() => {
|
|
644
|
-
const { onChange: onChange$1, onCommit } = ref.current;
|
|
645
625
|
const update$1 = (value$1) => {
|
|
646
|
-
|
|
626
|
+
latestOnChange(value$1);
|
|
647
627
|
setDirty(void 0);
|
|
648
|
-
|
|
628
|
+
latestOnCommit(value$1);
|
|
649
629
|
};
|
|
650
630
|
let delayedUpdate;
|
|
651
|
-
if (
|
|
652
|
-
else if (
|
|
631
|
+
if (debounceOptions) delayedUpdate = debounce(update$1, debounceOptions);
|
|
632
|
+
else if (throttleOptions) delayedUpdate = throttle(update$1, throttleOptions);
|
|
653
633
|
else delayedUpdate = (value$1) => startTransition(() => update$1(value$1));
|
|
654
634
|
return (value$1) => {
|
|
655
635
|
setDirty({ v: value$1 });
|
|
656
636
|
delayedUpdate(value$1);
|
|
657
637
|
};
|
|
658
|
-
}, [
|
|
638
|
+
}, [
|
|
639
|
+
latestOnChange,
|
|
640
|
+
latestOnCommit,
|
|
641
|
+
debounceOptions,
|
|
642
|
+
throttleOptions
|
|
643
|
+
]);
|
|
659
644
|
return [dirty ? dirty.v : value, update];
|
|
660
645
|
}
|
|
661
646
|
|