formstand 0.4.1 → 0.6.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/CHANGELOG.md +118 -0
- package/dist/index.cjs +22 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/package.json +7 -1
package/dist/index.d.cts
CHANGED
|
@@ -85,7 +85,7 @@ type SubmitResult<TOutput> = Readonly<{
|
|
|
85
85
|
kind: "error";
|
|
86
86
|
error: unknown;
|
|
87
87
|
}>;
|
|
88
|
-
type ArrayItemOf<T> = T extends readonly (infer U)[] ? U : never;
|
|
88
|
+
type ArrayItemOf$1<T> = T extends readonly (infer U)[] ? U : never;
|
|
89
89
|
type ErrorPath<TValues> = FieldPath<TValues> | "";
|
|
90
90
|
type ResetOptions = Readonly<{
|
|
91
91
|
keepErrors?: boolean;
|
|
@@ -129,9 +129,9 @@ type Form<TSchema extends z.ZodType> = Readonly<{
|
|
|
129
129
|
validateFieldAsync: (path: ErrorPath<z.input<TSchema>>) => Promise<FieldValidationResult>;
|
|
130
130
|
validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>>[]) => Promise<boolean>;
|
|
131
131
|
submit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => Promise<SubmitResult<z.output<TSchema>>>;
|
|
132
|
-
arrayPush: <P extends FieldPath<z.input<TSchema>>>(path: P, item: ArrayItemOf<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
132
|
+
arrayPush: <P extends FieldPath<z.input<TSchema>>>(path: P, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
133
133
|
arrayRemove: (path: FieldPath<z.input<TSchema>>, index: number) => void;
|
|
134
|
-
arrayInsert: <P extends FieldPath<z.input<TSchema>>>(path: P, index: number, item: ArrayItemOf<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
134
|
+
arrayInsert: <P extends FieldPath<z.input<TSchema>>>(path: P, index: number, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
135
135
|
arrayMove: (path: FieldPath<z.input<TSchema>>, from: number, to: number) => void;
|
|
136
136
|
arraySwap: (path: FieldPath<z.input<TSchema>>, a: number, b: number) => void;
|
|
137
137
|
handleSubmit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => (event?: {
|
|
@@ -176,8 +176,14 @@ declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
|
176
176
|
|
|
177
177
|
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
178
178
|
|
|
179
|
-
declare
|
|
180
|
-
|
|
179
|
+
declare function useIsDirty(form: FormStateApi & {
|
|
180
|
+
readonly schema?: undefined;
|
|
181
|
+
}, path?: string): boolean;
|
|
182
|
+
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
183
|
+
declare function useIsValid(form: FormStateApi & {
|
|
184
|
+
readonly schema?: undefined;
|
|
185
|
+
}, path?: string): boolean;
|
|
186
|
+
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
181
187
|
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
182
188
|
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
183
189
|
|
|
@@ -288,7 +294,12 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
288
294
|
move: (from: number, to: number) => void;
|
|
289
295
|
swap: (a: number, b: number) => void;
|
|
290
296
|
}>;
|
|
291
|
-
|
|
297
|
+
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
298
|
+
declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
299
|
+
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
300
|
+
readonly schema?: undefined;
|
|
301
|
+
}, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
|
|
302
|
+
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
292
303
|
|
|
293
304
|
type TextInputProps = Readonly<{
|
|
294
305
|
name: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ type SubmitResult<TOutput> = Readonly<{
|
|
|
85
85
|
kind: "error";
|
|
86
86
|
error: unknown;
|
|
87
87
|
}>;
|
|
88
|
-
type ArrayItemOf<T> = T extends readonly (infer U)[] ? U : never;
|
|
88
|
+
type ArrayItemOf$1<T> = T extends readonly (infer U)[] ? U : never;
|
|
89
89
|
type ErrorPath<TValues> = FieldPath<TValues> | "";
|
|
90
90
|
type ResetOptions = Readonly<{
|
|
91
91
|
keepErrors?: boolean;
|
|
@@ -129,9 +129,9 @@ type Form<TSchema extends z.ZodType> = Readonly<{
|
|
|
129
129
|
validateFieldAsync: (path: ErrorPath<z.input<TSchema>>) => Promise<FieldValidationResult>;
|
|
130
130
|
validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>>[]) => Promise<boolean>;
|
|
131
131
|
submit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => Promise<SubmitResult<z.output<TSchema>>>;
|
|
132
|
-
arrayPush: <P extends FieldPath<z.input<TSchema>>>(path: P, item: ArrayItemOf<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
132
|
+
arrayPush: <P extends FieldPath<z.input<TSchema>>>(path: P, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
133
133
|
arrayRemove: (path: FieldPath<z.input<TSchema>>, index: number) => void;
|
|
134
|
-
arrayInsert: <P extends FieldPath<z.input<TSchema>>>(path: P, index: number, item: ArrayItemOf<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
134
|
+
arrayInsert: <P extends FieldPath<z.input<TSchema>>>(path: P, index: number, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
|
|
135
135
|
arrayMove: (path: FieldPath<z.input<TSchema>>, from: number, to: number) => void;
|
|
136
136
|
arraySwap: (path: FieldPath<z.input<TSchema>>, a: number, b: number) => void;
|
|
137
137
|
handleSubmit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => (event?: {
|
|
@@ -176,8 +176,14 @@ declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
|
176
176
|
|
|
177
177
|
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
178
178
|
|
|
179
|
-
declare
|
|
180
|
-
|
|
179
|
+
declare function useIsDirty(form: FormStateApi & {
|
|
180
|
+
readonly schema?: undefined;
|
|
181
|
+
}, path?: string): boolean;
|
|
182
|
+
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
183
|
+
declare function useIsValid(form: FormStateApi & {
|
|
184
|
+
readonly schema?: undefined;
|
|
185
|
+
}, path?: string): boolean;
|
|
186
|
+
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
181
187
|
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
182
188
|
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
183
189
|
|
|
@@ -288,7 +294,12 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
288
294
|
move: (from: number, to: number) => void;
|
|
289
295
|
swap: (a: number, b: number) => void;
|
|
290
296
|
}>;
|
|
291
|
-
|
|
297
|
+
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
298
|
+
declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
299
|
+
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
300
|
+
readonly schema?: undefined;
|
|
301
|
+
}, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
|
|
302
|
+
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
292
303
|
|
|
293
304
|
type TextInputProps = Readonly<{
|
|
294
305
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -993,17 +993,26 @@ var useFormError = (form) => useStore(
|
|
|
993
993
|
form.store,
|
|
994
994
|
useShallow((state) => state.errors[""])
|
|
995
995
|
);
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
)
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
996
|
+
function useIsDirty(form, path) {
|
|
997
|
+
return useStore(
|
|
998
|
+
form.store,
|
|
999
|
+
(state) => path === void 0 || path === "" ? isFieldDirty(state.values, state.initialValues) : isFieldDirty(
|
|
1000
|
+
getAtPath(state.values, path),
|
|
1001
|
+
getAtPath(state.initialValues, path)
|
|
1002
|
+
)
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
function useIsValid(form, path) {
|
|
1006
|
+
return useStore(form.store, (state) => {
|
|
1007
|
+
for (const k in state.errors) {
|
|
1008
|
+
const errs = state.errors[k];
|
|
1009
|
+
if (errs !== void 0 && errs.length > 0 && (path === void 0 || path === "" || isPathOrChild(k, path))) {
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return true;
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1007
1016
|
var useIsSubmitting = (form) => useStore(form.store, (state) => state.isSubmitting);
|
|
1008
1017
|
var useSubmitCount = (form) => useStore(form.store, (state) => state.submitCount);
|
|
1009
1018
|
function useField(form, pathArg, options) {
|
|
@@ -1427,7 +1436,7 @@ var reconcileIds = (prev, nextItems) => {
|
|
|
1427
1436
|
counter: prev.counter + Math.max(0, unmatched - leftover.length)
|
|
1428
1437
|
};
|
|
1429
1438
|
};
|
|
1430
|
-
|
|
1439
|
+
function useFieldArray(form, pathArg) {
|
|
1431
1440
|
const path = useStore(
|
|
1432
1441
|
form.store,
|
|
1433
1442
|
(state) => typeof pathArg === "function" ? pathArg(state) : pathArg
|
|
@@ -1492,7 +1501,7 @@ var useFieldArray = (form, pathArg) => {
|
|
|
1492
1501
|
}),
|
|
1493
1502
|
[fields, items, error, push, remove, insert, move, swap]
|
|
1494
1503
|
);
|
|
1495
|
-
}
|
|
1504
|
+
}
|
|
1496
1505
|
|
|
1497
1506
|
export { CheckboxField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, isAsyncRequiredError, numberInputProps, numberToInputText, parseNumberText, parsePath, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useSubmitCount, validateAsync, validateSync };
|
|
1498
1507
|
//# sourceMappingURL=index.js.map
|