@jcoreio/zod-forms 1.0.3 → 1.1.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/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { useFormContext } from './useFormContext';
8
8
  export { type FormStatus } from './createSelectFormStatus';
9
9
  export { useFormStatus } from './useFormStatus';
10
10
  export { useFormValues } from './useFormValues';
11
- export { useHtmlField, type TypedUseHtmlField, type UseHtmlFieldProps, type HtmlFieldInputProps, type ValidUseHtmlFieldProps, } from './useHtmlField';
11
+ export { useHtmlField, type TypedUseHtmlField, type UseHtmlFieldOptions, type UseHtmlFieldProps, type HtmlFieldInputProps, type ValidUseHtmlFieldProps, } from './useHtmlField';
12
12
  export { useInitialize } from './useInitialize';
13
13
  export { useSubmit } from './useSubmit';
14
14
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,SAAS,EACT,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAC7E,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,KAAK,UAAU,EAAE,M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mBAAmB,EACxB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_createZodForm","require","_FieldPath","_useField","_useArrayField","_useFormContext","_useFormStatus","_useFormValues","_useHtmlField","_useInitialize","_useSubmit"],"sources":["src/index.ts"],"sourcesContent":["export { createZodForm, type ZodForm } from './createZodForm'\nexport {\n type FieldMeta,\n type SubmitHandler,\n type SubmitSuccededHandler,\n type SubmitFailedHandler,\n} from './FormState'\nexport {\n FieldPath,\n type FieldPathForValue,\n type FieldPathForRawValue,\n} from './FieldPath'\nexport { useField, type UseFieldProps, type TypedUseField } from './useField'\nexport {\n useArrayField,\n type UseArrayFieldProps,\n type TypedUseArrayField,\n} from './useArrayField'\nexport { type FormContextProps } from './FormContext'\nexport { useFormContext } from './useFormContext'\nexport { type FormStatus } from './createSelectFormStatus'\nexport { useFormStatus } from './useFormStatus'\nexport { useFormValues } from './useFormValues'\nexport {\n useHtmlField,\n type TypedUseHtmlField,\n type UseHtmlFieldProps,\n type HtmlFieldInputProps,\n type ValidUseHtmlFieldProps,\n} from './useHtmlField'\nexport { useInitialize } from './useInitialize'\nexport { useSubmit } from './useSubmit'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAOA,IAAAC,UAAA,GAAAD,OAAA;AAKA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AAMA,IAAAI,eAAA,GAAAJ,OAAA;AAEA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AAOA,IAAAQ,cAAA,GAAAR,OAAA;AACA,IAAAS,UAAA,GAAAT,OAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_createZodForm","require","_FieldPath","_useField","_useArrayField","_useFormContext","_useFormStatus","_useFormValues","_useHtmlField","_useInitialize","_useSubmit"],"sources":["src/index.ts"],"sourcesContent":["export { createZodForm, type ZodForm } from './createZodForm'\nexport {\n type FieldMeta,\n type SubmitHandler,\n type SubmitSuccededHandler,\n type SubmitFailedHandler,\n} from './FormState'\nexport {\n FieldPath,\n type FieldPathForValue,\n type FieldPathForRawValue,\n} from './FieldPath'\nexport { useField, type UseFieldProps, type TypedUseField } from './useField'\nexport {\n useArrayField,\n type UseArrayFieldProps,\n type TypedUseArrayField,\n} from './useArrayField'\nexport { type FormContextProps } from './FormContext'\nexport { useFormContext } from './useFormContext'\nexport { type FormStatus } from './createSelectFormStatus'\nexport { useFormStatus } from './useFormStatus'\nexport { useFormValues } from './useFormValues'\nexport {\n useHtmlField,\n type TypedUseHtmlField,\n type UseHtmlFieldOptions,\n type UseHtmlFieldProps,\n type HtmlFieldInputProps,\n type ValidUseHtmlFieldProps,\n} from './useHtmlField'\nexport { useInitialize } from './useInitialize'\nexport { useSubmit } from './useSubmit'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAOA,IAAAC,UAAA,GAAAD,OAAA;AAKA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AAMA,IAAAI,eAAA,GAAAJ,OAAA;AAEA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AAQA,IAAAQ,cAAA,GAAAR,OAAA;AACA,IAAAS,UAAA,GAAAT,OAAA","ignoreList":[]}
package/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["createZodForm","FieldPath","useField","useArrayField","useFormContext","useFormStatus","useFormValues","useHtmlField","useInitialize","useSubmit"],"sources":["src/index.ts"],"sourcesContent":["export { createZodForm, type ZodForm } from './createZodForm'\nexport {\n type FieldMeta,\n type SubmitHandler,\n type SubmitSuccededHandler,\n type SubmitFailedHandler,\n} from './FormState'\nexport {\n FieldPath,\n type FieldPathForValue,\n type FieldPathForRawValue,\n} from './FieldPath'\nexport { useField, type UseFieldProps, type TypedUseField } from './useField'\nexport {\n useArrayField,\n type UseArrayFieldProps,\n type TypedUseArrayField,\n} from './useArrayField'\nexport { type FormContextProps } from './FormContext'\nexport { useFormContext } from './useFormContext'\nexport { type FormStatus } from './createSelectFormStatus'\nexport { useFormStatus } from './useFormStatus'\nexport { useFormValues } from './useFormValues'\nexport {\n useHtmlField,\n type TypedUseHtmlField,\n type UseHtmlFieldProps,\n type HtmlFieldInputProps,\n type ValidUseHtmlFieldProps,\n} from './useHtmlField'\nexport { useInitialize } from './useInitialize'\nexport { useSubmit } from './useSubmit'\n"],"mappings":"AAAA,SAASA,aAAa;AAOtB,SACEC,SAAS;AAIX,SAASC,QAAQ;AACjB,SACEC,aAAa;AAKf,SAASC,cAAc;AAEvB,SAASC,aAAa;AACtB,SAASC,aAAa;AACtB,SACEC,YAAY;AAMd,SAASC,aAAa;AACtB,SAASC,SAAS","ignoreList":[]}
1
+ {"version":3,"file":"index.mjs","names":["createZodForm","FieldPath","useField","useArrayField","useFormContext","useFormStatus","useFormValues","useHtmlField","useInitialize","useSubmit"],"sources":["src/index.ts"],"sourcesContent":["export { createZodForm, type ZodForm } from './createZodForm'\nexport {\n type FieldMeta,\n type SubmitHandler,\n type SubmitSuccededHandler,\n type SubmitFailedHandler,\n} from './FormState'\nexport {\n FieldPath,\n type FieldPathForValue,\n type FieldPathForRawValue,\n} from './FieldPath'\nexport { useField, type UseFieldProps, type TypedUseField } from './useField'\nexport {\n useArrayField,\n type UseArrayFieldProps,\n type TypedUseArrayField,\n} from './useArrayField'\nexport { type FormContextProps } from './FormContext'\nexport { useFormContext } from './useFormContext'\nexport { type FormStatus } from './createSelectFormStatus'\nexport { useFormStatus } from './useFormStatus'\nexport { useFormValues } from './useFormValues'\nexport {\n useHtmlField,\n type TypedUseHtmlField,\n type UseHtmlFieldOptions,\n type UseHtmlFieldProps,\n type HtmlFieldInputProps,\n type ValidUseHtmlFieldProps,\n} from './useHtmlField'\nexport { useInitialize } from './useInitialize'\nexport { useSubmit } from './useSubmit'\n"],"mappings":"AAAA,SAASA,aAAa;AAOtB,SACEC,SAAS;AAIX,SAASC,QAAQ;AACjB,SACEC,aAAa;AAKf,SAASC,cAAc;AAEvB,SAASC,aAAa;AACtB,SAASC,aAAa;AACtB,SACEC,YAAY;AAOd,SAASC,aAAa;AACtB,SAASC,SAAS","ignoreList":[]}
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "peerDependencies": {
31
31
  "react": "^18.0.0"
32
32
  },
33
- "version": "1.0.3",
33
+ "version": "1.1.0",
34
34
  "sideEffects": false,
35
35
  "engines": {
36
36
  "node": ">=16"
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ export { useFormValues } from './useFormValues'
24
24
  export {
25
25
  useHtmlField,
26
26
  type TypedUseHtmlField,
27
+ type UseHtmlFieldOptions,
27
28
  type UseHtmlFieldProps,
28
29
  type HtmlFieldInputProps,
29
30
  type ValidUseHtmlFieldProps,
@@ -3,7 +3,10 @@ import React from 'react'
3
3
  import { FormContext, FormContextProps } from './FormContext'
4
4
 
5
5
  export function useFormContext<
6
- T extends z.ZodTypeAny = z.ZodUnknown
6
+ T extends z.ZodTypeAny = z.ZodBranded<
7
+ z.ZodNever,
8
+ 'you must pass a schema type'
9
+ >
7
10
  >(): FormContextProps<T> {
8
11
  const props: FormContextProps<T> = React.useContext(FormContext) as any
9
12
  if (!props) {
@@ -9,5 +9,8 @@ export const useFormDispatch = createDispatchHook(
9
9
  ) as typeof useFormDispatchType
10
10
 
11
11
  declare function useFormDispatchType<
12
- T extends z.ZodTypeAny = z.ZodNever
12
+ T extends z.ZodTypeAny = z.ZodBranded<
13
+ z.ZodNever,
14
+ 'you must pass a schema type'
15
+ >
13
16
  >(): Dispatch<FormAction<T>>
@@ -36,7 +36,12 @@ export type UseHtmlFieldProps<Field extends FieldPath> = z.input<
36
36
  ERROR: 'field schema input must be a nullish string, number, boolean or bigint'
37
37
  }
38
38
 
39
- type UseHtmlFieldOptions<Field, Schema extends z.ZodTypeAny> = {
39
+ export type UseHtmlFieldOptions<
40
+ Field,
41
+ Schema extends z.ZodTypeAny = Field extends FieldPath<infer S>
42
+ ? S
43
+ : z.ZodTypeAny
44
+ > = {
40
45
  field: Field
41
46
  type: z.input<Schema> extends boolean | null | undefined
42
47
  ? 'checkbox'
@@ -3,7 +3,12 @@ import React, { DependencyList } from 'react'
3
3
  import { useFormContext } from './useFormContext'
4
4
  import { InitializeAction } from './actions/initialize'
5
5
 
6
- export function useInitialize<T extends z.ZodTypeAny = z.ZodNever>(
6
+ export function useInitialize<
7
+ T extends z.ZodTypeAny = z.ZodBranded<
8
+ z.ZodNever,
9
+ 'you must pass a schema type'
10
+ >
11
+ >(
7
12
  options: Omit<InitializeAction<T>, 'type'>,
8
13
  deps: DependencyList = [options.values, options.rawValues]
9
14
  ) {
@@ -1,4 +1,4 @@
1
1
  import z from 'zod';
2
2
  import { FormContextProps } from './FormContext';
3
- export declare function useFormContext<T extends z.ZodTypeAny = z.ZodUnknown>(): FormContextProps<T>;
3
+ export declare function useFormContext<T extends z.ZodTypeAny = z.ZodBranded<z.ZodNever, 'you must pass a schema type'>>(): FormContextProps<T>;
4
4
  //# sourceMappingURL=useFormContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormContext.d.ts","sourceRoot":"","sources":["src/useFormContext.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAE7D,wBAAgB,cAAc,CAC5B,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,KAClC,gBAAgB,CAAC,CAAC,CAAC,CAMvB"}
1
+ {"version":3,"file":"useFormContext.d.ts","sourceRoot":"","sources":["src/useFormContext.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAE7D,wBAAgB,cAAc,CAC5B,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CACnC,CAAC,CAAC,QAAQ,EACV,6BAA6B,CAC9B,KACE,gBAAgB,CAAC,CAAC,CAAC,CAMvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useFormContext.js","names":["_react","_interopRequireDefault","require","_FormContext","useFormContext","props","React","useContext","FormContext","Error"],"sources":["src/useFormContext.ts"],"sourcesContent":["import z from 'zod'\nimport React from 'react'\nimport { FormContext, FormContextProps } from './FormContext'\n\nexport function useFormContext<\n T extends z.ZodTypeAny = z.ZodUnknown\n>(): FormContextProps<T> {\n const props: FormContextProps<T> = React.useContext(FormContext) as any\n if (!props) {\n throw new Error(`must be used inside a <FormProvider>`)\n }\n return props\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEO,SAASE,cAAcA,CAAA,EAEL;EACvB,IAAMC,KAA0B,GAAGC,iBAAK,CAACC,UAAU,CAACC,wBAAW,CAAQ;EACvE,IAAI,CAACH,KAAK,EAAE;IACV,MAAM,IAAII,KAAK,uCAAuC,CAAC;EACzD;EACA,OAAOJ,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"file":"useFormContext.js","names":["_react","_interopRequireDefault","require","_FormContext","useFormContext","props","React","useContext","FormContext","Error"],"sources":["src/useFormContext.ts"],"sourcesContent":["import z from 'zod'\nimport React from 'react'\nimport { FormContext, FormContextProps } from './FormContext'\n\nexport function useFormContext<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'you must pass a schema type'\n >\n>(): FormContextProps<T> {\n const props: FormContextProps<T> = React.useContext(FormContext) as any\n if (!props) {\n throw new Error(`must be used inside a <FormProvider>`)\n }\n return props\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEO,SAASE,cAAcA,CAAA,EAKL;EACvB,IAAMC,KAA0B,GAAGC,iBAAK,CAACC,UAAU,CAACC,wBAAW,CAAQ;EACvE,IAAI,CAACH,KAAK,EAAE;IACV,MAAM,IAAII,KAAK,uCAAuC,CAAC;EACzD;EACA,OAAOJ,KAAK;AACd","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useFormContext.mjs","names":["React","FormContext","useFormContext","props","useContext","Error"],"sources":["src/useFormContext.ts"],"sourcesContent":["import z from 'zod'\nimport React from 'react'\nimport { FormContext, FormContextProps } from './FormContext'\n\nexport function useFormContext<\n T extends z.ZodTypeAny = z.ZodUnknown\n>(): FormContextProps<T> {\n const props: FormContextProps<T> = React.useContext(FormContext) as any\n if (!props) {\n throw new Error(`must be used inside a <FormProvider>`)\n }\n return props\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW;AAEpB,OAAO,SAASC,cAAcA,CAAA,EAEL;EACvB,MAAMC,KAA0B,GAAGH,KAAK,CAACI,UAAU,CAACH,WAAW,CAAQ;EACvE,IAAI,CAACE,KAAK,EAAE;IACV,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;EACzD;EACA,OAAOF,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"file":"useFormContext.mjs","names":["React","FormContext","useFormContext","props","useContext","Error"],"sources":["src/useFormContext.ts"],"sourcesContent":["import z from 'zod'\nimport React from 'react'\nimport { FormContext, FormContextProps } from './FormContext'\n\nexport function useFormContext<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'you must pass a schema type'\n >\n>(): FormContextProps<T> {\n const props: FormContextProps<T> = React.useContext(FormContext) as any\n if (!props) {\n throw new Error(`must be used inside a <FormProvider>`)\n }\n return props\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW;AAEpB,OAAO,SAASC,cAAcA,CAAA,EAKL;EACvB,MAAMC,KAA0B,GAAGH,KAAK,CAACI,UAAU,CAACH,WAAW,CAAQ;EACvE,IAAI,CAACE,KAAK,EAAE;IACV,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;EACzD;EACA,OAAOF,KAAK;AACd","ignoreList":[]}
@@ -2,6 +2,6 @@ import z from 'zod';
2
2
  import { FormAction } from './FormAction';
3
3
  import { Dispatch } from 'redux';
4
4
  export declare const useFormDispatch: typeof useFormDispatchType;
5
- declare function useFormDispatchType<T extends z.ZodTypeAny = z.ZodNever>(): Dispatch<FormAction<T>>;
5
+ declare function useFormDispatchType<T extends z.ZodTypeAny = z.ZodBranded<z.ZodNever, 'you must pass a schema type'>>(): Dispatch<FormAction<T>>;
6
6
  export {};
7
7
  //# sourceMappingURL=useFormDispatch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormDispatch.d.ts","sourceRoot":"","sources":["src/useFormDispatch.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,eAAO,MAAM,eAAe,EAEvB,OAAO,mBAAmB,CAAA;AAE/B,OAAO,UAAU,mBAAmB,CAClC,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,QAAQ,KAChC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"useFormDispatch.d.ts","sourceRoot":"","sources":["src/useFormDispatch.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,eAAO,MAAM,eAAe,EAEvB,OAAO,mBAAmB,CAAA;AAE/B,OAAO,UAAU,mBAAmB,CAClC,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CACnC,CAAC,CAAC,QAAQ,EACV,6BAA6B,CAC9B,KACE,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useFormDispatch.js","names":["_reactRedux","require","_FormStateContext","useFormDispatch","exports","createDispatchHook","FormStateContext"],"sources":["src/useFormDispatch.ts"],"sourcesContent":["import { createDispatchHook } from 'react-redux'\nimport { FormStateContext } from './FormStateContext'\nimport z from 'zod'\nimport { FormAction } from './FormAction'\nimport { Dispatch } from 'redux'\n\nexport const useFormDispatch = createDispatchHook(\n FormStateContext\n) as typeof useFormDispatchType\n\ndeclare function useFormDispatchType<\n T extends z.ZodTypeAny = z.ZodNever\n>(): Dispatch<FormAction<T>>\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAKO,IAAME,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,IAAAE,8BAAkB,EAC/CC,kCACF,CAA+B","ignoreList":[]}
1
+ {"version":3,"file":"useFormDispatch.js","names":["_reactRedux","require","_FormStateContext","useFormDispatch","exports","createDispatchHook","FormStateContext"],"sources":["src/useFormDispatch.ts"],"sourcesContent":["import { createDispatchHook } from 'react-redux'\nimport { FormStateContext } from './FormStateContext'\nimport z from 'zod'\nimport { FormAction } from './FormAction'\nimport { Dispatch } from 'redux'\n\nexport const useFormDispatch = createDispatchHook(\n FormStateContext\n) as typeof useFormDispatchType\n\ndeclare function useFormDispatchType<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'you must pass a schema type'\n >\n>(): Dispatch<FormAction<T>>\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAKO,IAAME,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,IAAAE,8BAAkB,EAC/CC,kCACF,CAA+B","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useFormDispatch.mjs","names":["createDispatchHook","FormStateContext","useFormDispatch"],"sources":["src/useFormDispatch.ts"],"sourcesContent":["import { createDispatchHook } from 'react-redux'\nimport { FormStateContext } from './FormStateContext'\nimport z from 'zod'\nimport { FormAction } from './FormAction'\nimport { Dispatch } from 'redux'\n\nexport const useFormDispatch = createDispatchHook(\n FormStateContext\n) as typeof useFormDispatchType\n\ndeclare function useFormDispatchType<\n T extends z.ZodTypeAny = z.ZodNever\n>(): Dispatch<FormAction<T>>\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,aAAa;AAChD,SAASC,gBAAgB;AAKzB,OAAO,MAAMC,eAAe,GAAGF,kBAAkB,CAC/CC,gBACF,CAA+B","ignoreList":[]}
1
+ {"version":3,"file":"useFormDispatch.mjs","names":["createDispatchHook","FormStateContext","useFormDispatch"],"sources":["src/useFormDispatch.ts"],"sourcesContent":["import { createDispatchHook } from 'react-redux'\nimport { FormStateContext } from './FormStateContext'\nimport z from 'zod'\nimport { FormAction } from './FormAction'\nimport { Dispatch } from 'redux'\n\nexport const useFormDispatch = createDispatchHook(\n FormStateContext\n) as typeof useFormDispatchType\n\ndeclare function useFormDispatchType<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'you must pass a schema type'\n >\n>(): Dispatch<FormAction<T>>\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,aAAa;AAChD,SAASC,gBAAgB;AAKzB,OAAO,MAAMC,eAAe,GAAGF,kBAAkB,CAC/CC,gBACF,CAA+B","ignoreList":[]}
package/useHtmlField.d.ts CHANGED
@@ -24,7 +24,7 @@ export type UseHtmlFieldProps<Field extends FieldPath> = z.input<Field['schema']
24
24
  } : {
25
25
  ERROR: 'field schema input must be a nullish string, number, boolean or bigint';
26
26
  };
27
- type UseHtmlFieldOptions<Field, Schema extends z.ZodTypeAny> = {
27
+ export type UseHtmlFieldOptions<Field, Schema extends z.ZodTypeAny = Field extends FieldPath<infer S> ? S : z.ZodTypeAny> = {
28
28
  field: Field;
29
29
  type: z.input<Schema> extends boolean | null | undefined ? 'checkbox' : Exclude<HTMLInputTypeAttribute, 'checkbox'>;
30
30
  normalizeOnBlur?: boolean;
@@ -37,5 +37,4 @@ export interface TypedUseHtmlField<T extends z.ZodTypeAny> {
37
37
  export declare function useHtmlField<Field extends FieldPath>(options: UseHtmlFieldOptions<Field, Field['schema']>): UseHtmlFieldProps<Field>;
38
38
  export declare function useHtmlField<T extends z.ZodTypeAny = z.ZodBranded<z.ZodNever, 'cast to TypedUseHtmlField<T> to pass a path array'>, Path extends PathInSchema<T> = any>(options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>;
39
39
  export declare function useHtmlField<T extends z.ZodTypeAny = z.ZodBranded<z.ZodNever, 'cast to TypedUseHtmlField<T> to pass a pathstring'>, Path extends PathstringInSchema<T> = any>(options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>;
40
- export {};
41
40
  //# sourceMappingURL=useHtmlField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHtmlField.d.ts","sourceRoot":"","sources":["src/useHtmlField.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAA;AACpD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CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useHtmlField.js","names":["_FieldPath","require","_useField","_react","_interopRequireDefault","_zodInvertible","_useFormContext2","_acceptsNumber","_acceptsBigint","_excluded","_excluded2","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useHtmlFieldBase","options","field","type","_options$normalizeOnB","normalizeOnBlur","props","useField","value","rawValue","initialValue","rawInitialValue","setValue","setRawValue","setMeta","meta","_objectWithoutProperties2","schema","_React$useState","React","useState","_React$useState2","_slicedToArray2","tempRawValue","setTempRawValue","tryNumber","useMemo","acceptsNumber","tryBigint","acceptsBigint","onChange","useCallback","getRawValue","normalized","normalizeRawValue","onFocus","visited","onBlur","parsed","safeParse","formatted","success","invert","data","undefined","touched","input","name","pathstring","String","checked","Boolean","target","HTMLInputElement","normalizeBlank","safeBigInt","BigInt","error","_ref","test","num","Number","isNaN","bigint","useHtmlField","_ref2","rest","_useFormContext","useFormContext","root","FieldPath","get"],"sources":["src/useHtmlField.ts"],"sourcesContent":["import z from 'zod'\nimport { BasePath, FieldPath } from './FieldPath'\nimport { useField, UseFieldProps } from './useField'\nimport React, { ChangeEvent, HTMLInputTypeAttribute } from 'react'\nimport { invert } from 'zod-invertible'\nimport { useFormContext } from './useFormContext'\nimport { acceptsNumber } from './util/acceptsNumber'\nimport { acceptsBigint } from './util/acceptsBigint'\nimport { PathInSchema, PathstringInSchema } from './util/PathInSchema'\nimport { parsePathstring } from './util/parsePathstring'\nimport { SchemaAt } from './util/SchemaAt'\n\nexport type HtmlFieldInputProps = {\n name: string\n type: HTMLInputTypeAttribute\n value: string\n checked?: boolean\n onChange: React.ChangeEventHandler\n onFocus: React.FocusEventHandler\n onBlur: React.FocusEventHandler\n}\n\nexport type ValidUseHtmlFieldProps<Field extends FieldPath> = {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n}\n\nexport type UseHtmlFieldProps<Field extends FieldPath> = z.input<\n Field['schema']\n> extends string | number | bigint | boolean | null | undefined\n ? {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n }\n : {\n ERROR: 'field schema input must be a nullish string, number, boolean or bigint'\n }\n\ntype UseHtmlFieldOptions<Field, Schema extends z.ZodTypeAny> = {\n field: Field\n type: z.input<Schema> extends boolean | null | undefined\n ? 'checkbox'\n : Exclude<HTMLInputTypeAttribute, 'checkbox'>\n normalizeOnBlur?: boolean\n}\n\nexport interface TypedUseHtmlField<T extends z.ZodTypeAny> {\n <Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n ): UseHtmlFieldProps<Field>\n <Path extends PathInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\n <Path extends PathstringInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\n}\n\nfunction useHtmlFieldBase<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field> {\n const { field, type, normalizeOnBlur = true } = options\n const props = useField(field)\n const {\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n ...meta\n } = props\n\n const { schema } = field\n\n // tempRawValue is used for storing blank text when we've coerced the\n // raw value to null or undefined, or storing numeric text when we've\n // coerced the raw value to a number or bigint.\n // This way we can set a raw value that will parse better in the form\n // state without interfering with the text the user is typing.\n const [tempRawValue, setTempRawValue] = React.useState(\n rawValue as string | null | undefined\n )\n\n const tryNumber = React.useMemo(() => acceptsNumber(schema), [schema])\n const tryBigint = React.useMemo(() => acceptsBigint(schema), [schema])\n\n const onChange = React.useCallback(\n (e: React.ChangeEvent) => {\n const rawValue = getRawValue(e)\n const normalized = normalizeRawValue(rawValue, {\n schema,\n tryNumber,\n tryBigint,\n })\n if (typeof rawValue === 'string' && typeof normalized !== 'string') {\n setTempRawValue(rawValue)\n }\n setRawValue(normalized)\n },\n [getRawValue, setRawValue, schema]\n )\n\n const onFocus = React.useCallback(() => {\n setMeta({ visited: true })\n }, [])\n\n const onBlur = React.useCallback(\n (e: React.FocusEvent) => {\n let rawValue = normalizeRawValue(getRawValue(e), {\n schema,\n tryNumber,\n tryBigint,\n })\n if (normalizeOnBlur) {\n const parsed = field.schema.safeParse(rawValue)\n const formatted = parsed.success\n ? invert(field.schema).safeParse(parsed.data)\n : undefined\n if (formatted?.success) rawValue = formatted.data\n setRawValue(rawValue)\n }\n setTempRawValue(undefined)\n setMeta({ visited: true, touched: true })\n },\n [getRawValue, setRawValue, schema]\n )\n\n return React.useMemo(\n (): ValidUseHtmlFieldProps<Field> => ({\n input: {\n name: field.pathstring,\n type,\n value:\n typeof rawValue === 'boolean'\n ? String(rawValue)\n : typeof rawValue === 'string'\n ? rawValue || tempRawValue || ''\n : tempRawValue || (rawValue == null ? '' : String(rawValue) || ''),\n ...(type === 'checkbox' && { checked: Boolean(rawValue) }),\n onChange,\n onFocus,\n onBlur,\n },\n meta: {\n ...meta,\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n },\n }),\n [props, tempRawValue, onChange]\n ) as any\n}\n\nfunction getRawValue(e: ChangeEvent) {\n const { target } = e\n if (target instanceof HTMLInputElement) {\n return target.type === 'checkbox' ? target.checked : target.value\n }\n return (target as any).value\n}\n\nfunction normalizeBlank(schema: z.ZodTypeAny): any {\n if (schema.safeParse(undefined).success) return undefined\n if (schema.safeParse(null).success) return null\n return undefined\n}\n\nfunction safeBigInt(rawValue: string): bigint | undefined {\n try {\n return BigInt(rawValue)\n } catch (error) {\n return undefined\n }\n}\n\nfunction normalizeRawValue(\n rawValue: string | boolean,\n {\n schema,\n tryNumber,\n tryBigint,\n }: { schema: z.ZodTypeAny; tryNumber: boolean; tryBigint: boolean }\n): string | boolean | number | bigint | null | undefined {\n if (typeof rawValue === 'boolean') return rawValue\n if (typeof rawValue === 'string' && !/\\S/.test(rawValue)) {\n return normalizeBlank(schema)\n }\n if (typeof rawValue === 'string' && !schema.safeParse(rawValue).success) {\n if (tryNumber) {\n const num = Number(rawValue)\n if (!isNaN(num)) return num\n }\n if (tryBigint) {\n const bigint = safeBigInt(rawValue)\n if (bigint != null) return bigint\n }\n }\n return rawValue\n}\n\nexport function useHtmlField<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a path array'\n >,\n Path extends PathInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a pathstring'\n >,\n Path extends PathstringInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\nexport function useHtmlField<T extends z.ZodTypeAny>({\n field,\n ...rest\n}: UseHtmlFieldOptions<FieldPath | BasePath, T>): UseHtmlFieldProps<any> {\n const { root } = useFormContext<T>()\n return useHtmlFieldBase({\n field: field instanceof FieldPath ? field : root.get(field as any),\n ...rest,\n })\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,c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AI,OAAAlD,yBAAA,aAAAiD,KAAA,EAAAvF,UAAA;EAEP,IAAAyF,eAAA,GAAiB,IAAAC,+BAAc,EAAI,CAAC;IAA5BC,IAAI,GAAAF,eAAA,CAAJE,IAAI;EACZ,OAAOrE,gBAAgB,CAAAR,aAAA;IACrBU,KAAK,EAAEA,KAAK,YAAYoE,oBAAS,GAAGpE,KAAK,GAAGmE,IAAI,CAACE,GAAG,CAACrE,KAAY;EAAC,GAC/DgE,IAAI,CACR,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"useHtmlField.js","names":["_FieldPath","require","_useField","_react","_interopRequireDefault","_zodInvertible","_useFormContext2","_acceptsNumber","_acceptsBigint","_excluded","_excluded2","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useHtmlFieldBase","options","field","type","_options$normalizeOnB","normalizeOnBlur","props","useField","value","rawValue","initialValue","rawInitialValue","setValue","setRawValue","setMeta","meta","_objectWithoutProperties2","schema","_React$useState","React","useState","_React$useState2","_slicedToArray2","tempRawValue","setTempRawValue","tryNumber","useMemo","acceptsNumber","tryBigint","acceptsBigint","onChange","useCallback","getRawValue","normalized","normalizeRawValue","onFocus","visited","onBlur","parsed","safeParse","formatted","success","invert","data","undefined","touched","input","name","pathstring","String","checked","Boolean","target","HTMLInputElement","normalizeBlank","safeBigInt","BigInt","error","_ref","test","num","Number","isNaN","bigint","useHtmlField","_ref2","rest","_useFormContext","useFormContext","root","FieldPath","get"],"sources":["src/useHtmlField.ts"],"sourcesContent":["import z from 'zod'\nimport { BasePath, FieldPath } from './FieldPath'\nimport { useField, UseFieldProps } from './useField'\nimport React, { ChangeEvent, HTMLInputTypeAttribute } from 'react'\nimport { invert } from 'zod-invertible'\nimport { useFormContext } from './useFormContext'\nimport { acceptsNumber } from './util/acceptsNumber'\nimport { acceptsBigint } from './util/acceptsBigint'\nimport { PathInSchema, PathstringInSchema } from './util/PathInSchema'\nimport { parsePathstring } from './util/parsePathstring'\nimport { SchemaAt } from './util/SchemaAt'\n\nexport type HtmlFieldInputProps = {\n name: string\n type: HTMLInputTypeAttribute\n value: string\n checked?: boolean\n onChange: React.ChangeEventHandler\n onFocus: React.FocusEventHandler\n onBlur: React.FocusEventHandler\n}\n\nexport type ValidUseHtmlFieldProps<Field extends FieldPath> = {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n}\n\nexport type UseHtmlFieldProps<Field extends FieldPath> = z.input<\n Field['schema']\n> extends string | number | bigint | boolean | null | undefined\n ? {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n }\n : {\n ERROR: 'field schema input must be a nullish string, number, boolean or bigint'\n }\n\nexport type UseHtmlFieldOptions<\n Field,\n Schema extends z.ZodTypeAny = Field extends FieldPath<infer S>\n ? S\n : z.ZodTypeAny\n> = {\n field: Field\n type: z.input<Schema> extends boolean | null | undefined\n ? 'checkbox'\n : Exclude<HTMLInputTypeAttribute, 'checkbox'>\n normalizeOnBlur?: boolean\n}\n\nexport interface TypedUseHtmlField<T extends z.ZodTypeAny> {\n <Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n ): UseHtmlFieldProps<Field>\n <Path extends PathInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\n <Path extends PathstringInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\n}\n\nfunction useHtmlFieldBase<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field> {\n const { field, type, normalizeOnBlur = true } = options\n const props = useField(field)\n const {\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n ...meta\n } = props\n\n const { schema } = field\n\n // tempRawValue is used for storing blank text when we've coerced the\n // raw value to null or undefined, or storing numeric text when we've\n // coerced the raw value to a number or bigint.\n // This way we can set a raw value that will parse better in the form\n // state without interfering with the text the user is typing.\n const [tempRawValue, setTempRawValue] = React.useState(\n rawValue as string | null | undefined\n )\n\n const tryNumber = React.useMemo(() => acceptsNumber(schema), [schema])\n const tryBigint = React.useMemo(() => acceptsBigint(schema), [schema])\n\n const onChange = React.useCallback(\n (e: React.ChangeEvent) => {\n const rawValue = getRawValue(e)\n const normalized = normalizeRawValue(rawValue, {\n schema,\n tryNumber,\n tryBigint,\n })\n if (typeof rawValue === 'string' && typeof normalized !== 'string') {\n setTempRawValue(rawValue)\n }\n setRawValue(normalized)\n },\n [getRawValue, setRawValue, schema]\n )\n\n const onFocus = React.useCallback(() => {\n setMeta({ visited: true })\n }, [])\n\n const onBlur = React.useCallback(\n (e: React.FocusEvent) => {\n let rawValue = normalizeRawValue(getRawValue(e), {\n schema,\n tryNumber,\n tryBigint,\n })\n if (normalizeOnBlur) {\n const parsed = field.schema.safeParse(rawValue)\n const formatted = parsed.success\n ? invert(field.schema).safeParse(parsed.data)\n : undefined\n if (formatted?.success) rawValue = formatted.data\n setRawValue(rawValue)\n }\n setTempRawValue(undefined)\n setMeta({ visited: true, touched: true })\n },\n [getRawValue, setRawValue, schema]\n )\n\n return React.useMemo(\n (): ValidUseHtmlFieldProps<Field> => ({\n input: {\n name: field.pathstring,\n type,\n value:\n typeof rawValue === 'boolean'\n ? String(rawValue)\n : typeof rawValue === 'string'\n ? rawValue || tempRawValue || ''\n : tempRawValue || (rawValue == null ? '' : String(rawValue) || ''),\n ...(type === 'checkbox' && { checked: Boolean(rawValue) }),\n onChange,\n onFocus,\n onBlur,\n },\n meta: {\n ...meta,\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n },\n }),\n [props, tempRawValue, onChange]\n ) as any\n}\n\nfunction getRawValue(e: ChangeEvent) {\n const { target } = e\n if (target instanceof HTMLInputElement) {\n return target.type === 'checkbox' ? target.checked : target.value\n }\n return (target as any).value\n}\n\nfunction normalizeBlank(schema: z.ZodTypeAny): any {\n if (schema.safeParse(undefined).success) return undefined\n if (schema.safeParse(null).success) return null\n return undefined\n}\n\nfunction safeBigInt(rawValue: string): bigint | undefined {\n try {\n return BigInt(rawValue)\n } catch (error) {\n return undefined\n }\n}\n\nfunction normalizeRawValue(\n rawValue: string | boolean,\n {\n schema,\n tryNumber,\n tryBigint,\n }: { schema: z.ZodTypeAny; tryNumber: boolean; tryBigint: boolean }\n): string | boolean | number | bigint | null | undefined {\n if (typeof rawValue === 'boolean') return rawValue\n if (typeof rawValue === 'string' && !/\\S/.test(rawValue)) {\n return normalizeBlank(schema)\n }\n if (typeof rawValue === 'string' && !schema.safeParse(rawValue).success) {\n if (tryNumber) {\n const num = Number(rawValue)\n if (!isNaN(num)) return num\n }\n if (tryBigint) {\n const bigint = safeBigInt(rawValue)\n if (bigint != null) return bigint\n }\n }\n return rawValue\n}\n\nexport function useHtmlField<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a path array'\n >,\n Path extends PathInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a pathstring'\n >,\n Path extends PathstringInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\nexport function useHtmlField<T extends z.ZodTypeAny>({\n field,\n ...rest\n}: UseHtmlFieldOptions<FieldPath | BasePath, T>): UseHtmlFieldProps<any> {\n const { root } = useFormContext<T>()\n return useHtmlFieldBase({\n field: field instanceof FieldPath ? field : root.get(field as any),\n ...rest,\n })\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AAAoD,IAAAQ,SAAA;EAAAC,UAAA;AAAA,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,yBAAA,CAAAf,CAAA,KAAAH,OAAA,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AQ,CAAC;MAC5B,IAAI,CAACqD,KAAK,CAACF,GAAG,CAAC,EAAE,OAAOA,GAAG;IAC7B;IACA,IAAIhC,SAAS,EAAE;MACb,IAAMmC,MAAM,GAAGR,UAAU,CAAC9C,QAAQ,CAAC;MACnC,IAAIsD,MAAM,IAAI,IAAI,EAAE,OAAOA,MAAM;IACnC;EACF;EACA,OAAOtD,QAAQ;AACjB;AAuBO,SAASuD,YAAYA,CAAAC,KAAA,EAG6C;EAAA,IAFvE/D,KAAK,GAAA+D,KAAA,CAAL/D,KAAK;IACFgE,IAAI,OAAAlD,yBAAA,aAAAiD,KAAA,EAAAvF,UAAA;EAEP,IAAAyF,eAAA,GAAiB,IAAAC,+BAAc,EAAI,CAAC;IAA5BC,IAAI,GAAAF,eAAA,CAAJE,IAAI;EACZ,OAAOrE,gBAAgB,CAAAR,aAAA;IACrBU,KAAK,EAAEA,KAAK,YAAYoE,oBAAS,GAAGpE,KAAK,GAAGmE,IAAI,CAACE,GAAG,CAACrE,KAAY;EAAC,GAC/DgE,IAAI,CACR,CAAC;AACJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useHtmlField.mjs","names":["FieldPath","useField","React","invert","useFormContext","acceptsNumber","acceptsBigint","useHtmlFieldBase","options","field","type","normalizeOnBlur","props","value","rawValue","initialValue","rawInitialValue","setValue","setRawValue","setMeta","meta","schema","tempRawValue","setTempRawValue","useState","tryNumber","useMemo","tryBigint","onChange","useCallback","e","getRawValue","normalized","normalizeRawValue","onFocus","visited","onBlur","parsed","safeParse","formatted","success","data","undefined","touched","input","name","pathstring","String","checked","Boolean","target","HTMLInputElement","normalizeBlank","safeBigInt","BigInt","error","test","num","Number","isNaN","bigint","useHtmlField","rest","root","get"],"sources":["src/useHtmlField.ts"],"sourcesContent":["import z from 'zod'\nimport { BasePath, FieldPath } from './FieldPath'\nimport { useField, UseFieldProps } from './useField'\nimport React, { ChangeEvent, HTMLInputTypeAttribute } from 'react'\nimport { invert } from 'zod-invertible'\nimport { useFormContext } from './useFormContext'\nimport { acceptsNumber } from './util/acceptsNumber'\nimport { acceptsBigint } from './util/acceptsBigint'\nimport { PathInSchema, PathstringInSchema } from './util/PathInSchema'\nimport { parsePathstring } from './util/parsePathstring'\nimport { SchemaAt } from './util/SchemaAt'\n\nexport type HtmlFieldInputProps = {\n name: string\n type: HTMLInputTypeAttribute\n value: string\n checked?: boolean\n onChange: React.ChangeEventHandler\n onFocus: React.FocusEventHandler\n onBlur: React.FocusEventHandler\n}\n\nexport type ValidUseHtmlFieldProps<Field extends FieldPath> = {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n}\n\nexport type UseHtmlFieldProps<Field extends FieldPath> = z.input<\n Field['schema']\n> extends string | number | bigint | boolean | null | undefined\n ? {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n }\n : {\n ERROR: 'field schema input must be a nullish string, number, boolean or bigint'\n }\n\ntype UseHtmlFieldOptions<Field, Schema extends z.ZodTypeAny> = {\n field: Field\n type: z.input<Schema> extends boolean | null | undefined\n ? 'checkbox'\n : Exclude<HTMLInputTypeAttribute, 'checkbox'>\n normalizeOnBlur?: boolean\n}\n\nexport interface TypedUseHtmlField<T extends z.ZodTypeAny> {\n <Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n ): UseHtmlFieldProps<Field>\n <Path extends PathInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\n <Path extends PathstringInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\n}\n\nfunction useHtmlFieldBase<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field> {\n const { field, type, normalizeOnBlur = true } = options\n const props = useField(field)\n const {\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n ...meta\n } = props\n\n const { schema } = field\n\n // tempRawValue is used for storing blank text when we've coerced the\n // raw value to null or undefined, or storing numeric text when we've\n // coerced the raw value to a number or bigint.\n // This way we can set a raw value that will parse better in the form\n // state without interfering with the text the user is typing.\n const [tempRawValue, setTempRawValue] = React.useState(\n rawValue as string | null | undefined\n )\n\n const tryNumber = React.useMemo(() => acceptsNumber(schema), [schema])\n const tryBigint = React.useMemo(() => acceptsBigint(schema), [schema])\n\n const onChange = React.useCallback(\n (e: React.ChangeEvent) => {\n const rawValue = getRawValue(e)\n const normalized = normalizeRawValue(rawValue, {\n schema,\n tryNumber,\n tryBigint,\n })\n if (typeof rawValue === 'string' && typeof normalized !== 'string') {\n setTempRawValue(rawValue)\n }\n setRawValue(normalized)\n },\n [getRawValue, setRawValue, schema]\n )\n\n const onFocus = React.useCallback(() => {\n setMeta({ visited: true })\n }, [])\n\n const onBlur = React.useCallback(\n (e: React.FocusEvent) => {\n let rawValue = normalizeRawValue(getRawValue(e), {\n schema,\n tryNumber,\n tryBigint,\n })\n if (normalizeOnBlur) {\n const parsed = field.schema.safeParse(rawValue)\n const formatted = parsed.success\n ? invert(field.schema).safeParse(parsed.data)\n : undefined\n if (formatted?.success) rawValue = formatted.data\n setRawValue(rawValue)\n }\n setTempRawValue(undefined)\n setMeta({ visited: true, touched: true })\n },\n [getRawValue, setRawValue, schema]\n )\n\n return React.useMemo(\n (): ValidUseHtmlFieldProps<Field> => ({\n input: {\n name: field.pathstring,\n type,\n value:\n typeof rawValue === 'boolean'\n ? String(rawValue)\n : typeof rawValue === 'string'\n ? rawValue || tempRawValue || ''\n : tempRawValue || (rawValue == null ? '' : String(rawValue) || ''),\n ...(type === 'checkbox' && { checked: Boolean(rawValue) }),\n onChange,\n onFocus,\n onBlur,\n },\n meta: {\n ...meta,\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n },\n }),\n [props, tempRawValue, onChange]\n ) as any\n}\n\nfunction getRawValue(e: ChangeEvent) {\n const { target } = e\n if (target instanceof HTMLInputElement) {\n return target.type === 'checkbox' ? target.checked : target.value\n }\n return (target as any).value\n}\n\nfunction normalizeBlank(schema: z.ZodTypeAny): any {\n if (schema.safeParse(undefined).success) return undefined\n if (schema.safeParse(null).success) return null\n return undefined\n}\n\nfunction safeBigInt(rawValue: string): bigint | undefined {\n try {\n return BigInt(rawValue)\n } catch (error) {\n return undefined\n }\n}\n\nfunction normalizeRawValue(\n rawValue: string | boolean,\n {\n schema,\n tryNumber,\n tryBigint,\n }: { schema: z.ZodTypeAny; tryNumber: boolean; tryBigint: boolean }\n): string | boolean | number | bigint | null | undefined {\n if (typeof rawValue === 'boolean') return rawValue\n if (typeof rawValue === 'string' && !/\\S/.test(rawValue)) {\n return normalizeBlank(schema)\n }\n if (typeof rawValue === 'string' && !schema.safeParse(rawValue).success) {\n if (tryNumber) {\n const num = Number(rawValue)\n if (!isNaN(num)) return num\n }\n if (tryBigint) {\n const bigint = safeBigInt(rawValue)\n if (bigint != null) return bigint\n }\n }\n return rawValue\n}\n\nexport function useHtmlField<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a path array'\n >,\n Path extends PathInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a pathstring'\n >,\n Path extends PathstringInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\nexport function useHtmlField<T extends z.ZodTypeAny>({\n field,\n ...rest\n}: UseHtmlFieldOptions<FieldPath | BasePath, T>): UseHtmlFieldProps<any> {\n const { root } = useFormContext<T>()\n return useHtmlFieldBase({\n field: field instanceof FieldPath ? field : root.get(field as any),\n ...rest,\n })\n}\n"],"mappings":"AACA,SAAmBA,SAAS;AAC5B,SAASC,QAAQ;AACjB,OAAOC,KAAK,MAA+C,OAAO;AAClE,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,cAAc;AACvB,SAASC,aAAa;AACtB,SAASC,aAAa;AAmDtB,SAASC,gBAAgBA,CACvBC,OAAoD,EAC1B;EAC1B,MAAM;IAAEC,KAAK;IAAEC,IAAI;IAAEC,eAAe,GAAG;EAAK,CAAC,GAAGH,OAAO;EACvD,MAAMI,KAAK,GAAGX,QAAQ,CAACQ,KAAK,CAAC;EAC7B,MAAM;IACJI,KAAK;IACLC,QAAQ;IACRC,YAAY;IACZC,eAAe;IACfC,QAAQ;IACRC,WAAW;IACXC,OAAO;IACP,GAAGC;EACL,CAAC,GAAGR,KAAK;EAET,MAAM;IAAES;EAAO,CAAC,GAAGZ,KAAK;;EAExB;EACA;EACA;EACA;EACA;EACA,MAAM,CAACa,YAAY,EAAEC,eAAe,CAAC,GAAGrB,KAAK,CAACsB,QAAQ,CACpDV,QACF,CAAC;EAED,MAAMW,SAAS,GAAGvB,KAAK,CAACwB,OAAO,CAAC,MAAMrB,aAAa,CAACgB,MAAM,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EACtE,MAAMM,SAAS,GAAGzB,KAAK,CAACwB,OAAO,CAAC,MAAMpB,aAAa,CAACe,MAAM,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEtE,MAAMO,QAAQ,GAAG1B,KAAK,CAAC2B,WAAW,CAC/BC,CAAoB,IAAK;IACxB,MAAMhB,QAAQ,GAAGiB,WAAW,CAACD,CAAC,CAAC;IAC/B,MAAME,UAAU,GAAGC,iBAAiB,CAACnB,QAAQ,EAAE;MAC7CO,MAAM;MACNI,SAAS;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ACxC,QAAQ,CAAC;EACzB,CAAC,CAAC,OAAOyC,KAAK,EAAE;IACd,OAAOb,SAAS;EAClB;AACF;AAEA,SAAST,iBAAiBA,CACxBnB,QAA0B,EAC1B;EACEO,MAAM;EACNI,SAAS;EACTE;AACgE,CAAC,EACZ;EACvD,IAAI,OAAOb,QAAQ,KAAK,SAAS,EAAE,OAAOA,QAAQ;EAClD,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC0C,IAAI,CAAC1C,QAAQ,CAAC,EAAE;IACxD,OAAOsC,cAAc,CAAC/B,MAAM,CAAC;EAC/B;EACA,IAAI,OAAOP,QAAQ,KAAK,QAAQ,IAAI,CAACO,MAAM,CAACiB,SAAS,CAACxB,QAAQ,CAAC,CAAC0B,OAAO,EAAE;IACvE,IAAIf,SAAS,EAAE;MACb,MAAMgC,GAAG,GAAGC,MAAM,CAAC5C,QAAQ,CAAC;MAC5B,IAAI,CAAC6C,KAAK,CAACF,GAAG,CAAC,EAAE,OAAOA,GAAG;IAC7B;IACA,IAAI9B,SAAS,EAAE;MACb,MAAMiC,MAAM,GAAGP,UAAU,CAACvC,QAAQ,CAAC;MACnC,IAAI8C,MAAM,IAAI,IAAI,EAAE,OAAOA,MAAM;IACnC;EACF;EACA,OAAO9C,QAAQ;AACjB;AAuBA,OAAO,SAAS+C,YAAYA,CAAyB;EACnDpD,KAAK;EACL,GAAGqD;AACyC,CAAC,EAA0B;EACvE,MAAM;IAAEC;EAAK,CAAC,GAAG3D,cAAc,CAAI,CAAC;EACpC,OAAOG,gBAAgB,CAAC;IACtBE,KAAK,EAAEA,KAAK,YAAYT,SAAS,GAAGS,KAAK,GAAGsD,IAAI,CAACC,GAAG,CAACvD,KAAY,CAAC;IAClE,GAAGqD;EACL,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"useHtmlField.mjs","names":["FieldPath","useField","React","invert","useFormContext","acceptsNumber","acceptsBigint","useHtmlFieldBase","options","field","type","normalizeOnBlur","props","value","rawValue","initialValue","rawInitialValue","setValue","setRawValue","setMeta","meta","schema","tempRawValue","setTempRawValue","useState","tryNumber","useMemo","tryBigint","onChange","useCallback","e","getRawValue","normalized","normalizeRawValue","onFocus","visited","onBlur","parsed","safeParse","formatted","success","data","undefined","touched","input","name","pathstring","String","checked","Boolean","target","HTMLInputElement","normalizeBlank","safeBigInt","BigInt","error","test","num","Number","isNaN","bigint","useHtmlField","rest","root","get"],"sources":["src/useHtmlField.ts"],"sourcesContent":["import z from 'zod'\nimport { BasePath, FieldPath } from './FieldPath'\nimport { useField, UseFieldProps } from './useField'\nimport React, { ChangeEvent, HTMLInputTypeAttribute } from 'react'\nimport { invert } from 'zod-invertible'\nimport { useFormContext } from './useFormContext'\nimport { acceptsNumber } from './util/acceptsNumber'\nimport { acceptsBigint } from './util/acceptsBigint'\nimport { PathInSchema, PathstringInSchema } from './util/PathInSchema'\nimport { parsePathstring } from './util/parsePathstring'\nimport { SchemaAt } from './util/SchemaAt'\n\nexport type HtmlFieldInputProps = {\n name: string\n type: HTMLInputTypeAttribute\n value: string\n checked?: boolean\n onChange: React.ChangeEventHandler\n onFocus: React.FocusEventHandler\n onBlur: React.FocusEventHandler\n}\n\nexport type ValidUseHtmlFieldProps<Field extends FieldPath> = {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n}\n\nexport type UseHtmlFieldProps<Field extends FieldPath> = z.input<\n Field['schema']\n> extends string | number | bigint | boolean | null | undefined\n ? {\n input: HtmlFieldInputProps\n meta: UseFieldProps<Field>\n }\n : {\n ERROR: 'field schema input must be a nullish string, number, boolean or bigint'\n }\n\nexport type UseHtmlFieldOptions<\n Field,\n Schema extends z.ZodTypeAny = Field extends FieldPath<infer S>\n ? S\n : z.ZodTypeAny\n> = {\n field: Field\n type: z.input<Schema> extends boolean | null | undefined\n ? 'checkbox'\n : Exclude<HTMLInputTypeAttribute, 'checkbox'>\n normalizeOnBlur?: boolean\n}\n\nexport interface TypedUseHtmlField<T extends z.ZodTypeAny> {\n <Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n ): UseHtmlFieldProps<Field>\n <Path extends PathInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\n <Path extends PathstringInSchema<T>>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n ): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\n}\n\nfunction useHtmlFieldBase<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field> {\n const { field, type, normalizeOnBlur = true } = options\n const props = useField(field)\n const {\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n ...meta\n } = props\n\n const { schema } = field\n\n // tempRawValue is used for storing blank text when we've coerced the\n // raw value to null or undefined, or storing numeric text when we've\n // coerced the raw value to a number or bigint.\n // This way we can set a raw value that will parse better in the form\n // state without interfering with the text the user is typing.\n const [tempRawValue, setTempRawValue] = React.useState(\n rawValue as string | null | undefined\n )\n\n const tryNumber = React.useMemo(() => acceptsNumber(schema), [schema])\n const tryBigint = React.useMemo(() => acceptsBigint(schema), [schema])\n\n const onChange = React.useCallback(\n (e: React.ChangeEvent) => {\n const rawValue = getRawValue(e)\n const normalized = normalizeRawValue(rawValue, {\n schema,\n tryNumber,\n tryBigint,\n })\n if (typeof rawValue === 'string' && typeof normalized !== 'string') {\n setTempRawValue(rawValue)\n }\n setRawValue(normalized)\n },\n [getRawValue, setRawValue, schema]\n )\n\n const onFocus = React.useCallback(() => {\n setMeta({ visited: true })\n }, [])\n\n const onBlur = React.useCallback(\n (e: React.FocusEvent) => {\n let rawValue = normalizeRawValue(getRawValue(e), {\n schema,\n tryNumber,\n tryBigint,\n })\n if (normalizeOnBlur) {\n const parsed = field.schema.safeParse(rawValue)\n const formatted = parsed.success\n ? invert(field.schema).safeParse(parsed.data)\n : undefined\n if (formatted?.success) rawValue = formatted.data\n setRawValue(rawValue)\n }\n setTempRawValue(undefined)\n setMeta({ visited: true, touched: true })\n },\n [getRawValue, setRawValue, schema]\n )\n\n return React.useMemo(\n (): ValidUseHtmlFieldProps<Field> => ({\n input: {\n name: field.pathstring,\n type,\n value:\n typeof rawValue === 'boolean'\n ? String(rawValue)\n : typeof rawValue === 'string'\n ? rawValue || tempRawValue || ''\n : tempRawValue || (rawValue == null ? '' : String(rawValue) || ''),\n ...(type === 'checkbox' && { checked: Boolean(rawValue) }),\n onChange,\n onFocus,\n onBlur,\n },\n meta: {\n ...meta,\n value,\n rawValue,\n initialValue,\n rawInitialValue,\n setValue,\n setRawValue,\n setMeta,\n },\n }),\n [props, tempRawValue, onChange]\n ) as any\n}\n\nfunction getRawValue(e: ChangeEvent) {\n const { target } = e\n if (target instanceof HTMLInputElement) {\n return target.type === 'checkbox' ? target.checked : target.value\n }\n return (target as any).value\n}\n\nfunction normalizeBlank(schema: z.ZodTypeAny): any {\n if (schema.safeParse(undefined).success) return undefined\n if (schema.safeParse(null).success) return null\n return undefined\n}\n\nfunction safeBigInt(rawValue: string): bigint | undefined {\n try {\n return BigInt(rawValue)\n } catch (error) {\n return undefined\n }\n}\n\nfunction normalizeRawValue(\n rawValue: string | boolean,\n {\n schema,\n tryNumber,\n tryBigint,\n }: { schema: z.ZodTypeAny; tryNumber: boolean; tryBigint: boolean }\n): string | boolean | number | bigint | null | undefined {\n if (typeof rawValue === 'boolean') return rawValue\n if (typeof rawValue === 'string' && !/\\S/.test(rawValue)) {\n return normalizeBlank(schema)\n }\n if (typeof rawValue === 'string' && !schema.safeParse(rawValue).success) {\n if (tryNumber) {\n const num = Number(rawValue)\n if (!isNaN(num)) return num\n }\n if (tryBigint) {\n const bigint = safeBigInt(rawValue)\n if (bigint != null) return bigint\n }\n }\n return rawValue\n}\n\nexport function useHtmlField<Field extends FieldPath>(\n options: UseHtmlFieldOptions<Field, Field['schema']>\n): UseHtmlFieldProps<Field>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a path array'\n >,\n Path extends PathInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, Path>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, Path>>>\nexport function useHtmlField<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'cast to TypedUseHtmlField<T> to pass a pathstring'\n >,\n Path extends PathstringInSchema<T> = any\n>(\n options: UseHtmlFieldOptions<Path, SchemaAt<T, parsePathstring<Path>>>\n): UseHtmlFieldProps<FieldPath<SchemaAt<T, parsePathstring<Path>>>>\nexport function useHtmlField<T extends z.ZodTypeAny>({\n field,\n ...rest\n}: UseHtmlFieldOptions<FieldPath | BasePath, T>): UseHtmlFieldProps<any> {\n const { root } = useFormContext<T>()\n return useHtmlFieldBase({\n field: field instanceof FieldPath ? field : root.get(field as any),\n ...rest,\n })\n}\n"],"mappings":"AACA,SAAmBA,SAAS;AAC5B,SAASC,QAAQ;AACjB,OAAOC,KAAK,MAA+C,OAAO;AAClE,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,cAAc;AACvB,SAASC,aAAa;AACtB,SAASC,aAAa;AAwDtB,SAASC,gBAAgBA,CACvBC,OAAoD,EAC1B;EAC1B,MAAM;IAAEC,KAAK;IAAEC,IAAI;IAAEC,eAAe,GAAG;EAAK,CAAC,GAAGH,OAAO;EACvD,MAAMI,KAAK,GAAGX,QAAQ,CAACQ,KAAK,CAAC;EAC7B,MAAM;IACJI,KAAK;IACLC,QAAQ;IACRC,YAAY;IACZC,eAAe;IACfC,QAAQ;IACRC,WAAW;IACXC,OAAO;IACP,GAAGC;EACL,CAAC,GAAGR,KAAK;EAET,MAAM;IAAES;EAAO,CAAC,GAAGZ,KAAK;;EAExB;EACA;EACA;EACA;EACA;EACA,MAAM,CAACa,YAAY,EAAEC,eAAe,CAAC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,IAAI,IAAI,EAAE,OAAOA,MAAM;IACnC;EACF;EACA,OAAO9C,QAAQ;AACjB;AAuBA,OAAO,SAAS+C,YAAYA,CAAyB;EACnDpD,KAAK;EACL,GAAGqD;AACyC,CAAC,EAA0B;EACvE,MAAM;IAAEC;EAAK,CAAC,GAAG3D,cAAc,CAAI,CAAC;EACpC,OAAOG,gBAAgB,CAAC;IACtBE,KAAK,EAAEA,KAAK,YAAYT,SAAS,GAAGS,KAAK,GAAGsD,IAAI,CAACC,GAAG,CAACvD,KAAY,CAAC;IAClE,GAAGqD;EACL,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import z from 'zod';
2
2
  import { DependencyList } from 'react';
3
3
  import { InitializeAction } from './actions/initialize';
4
- export declare function useInitialize<T extends z.ZodTypeAny = z.ZodNever>(options: Omit<InitializeAction<T>, 'type'>, deps?: DependencyList): void;
4
+ export declare function useInitialize<T extends z.ZodTypeAny = z.ZodBranded<z.ZodNever, 'you must pass a schema type'>>(options: Omit<InitializeAction<T>, 'type'>, deps?: DependencyList): void;
5
5
  //# sourceMappingURL=useInitialize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInitialize.d.ts","sourceRoot":"","sources":["src/useInitialize.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAc,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,wBAAgB,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,QAAQ,EAC/D,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAC1C,IAAI,GAAE,cAAoD,QAM3D"}
1
+ {"version":3,"file":"useInitialize.d.ts","sourceRoot":"","sources":["src/useInitialize.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAc,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,wBAAgB,aAAa,CAC3B,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CACnC,CAAC,CAAC,QAAQ,EACV,6BAA6B,CAC9B,EAED,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAC1C,IAAI,GAAE,cAAoD,QAM3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"useInitialize.js","names":["_react","_interopRequireDefault","require","_useFormContext2","useInitialize","options","deps","arguments","length","undefined","values","rawValues","_useFormContext","useFormContext","initialize","React","useEffect"],"sources":["src/useInitialize.ts"],"sourcesContent":["import z from 'zod'\nimport React, { DependencyList } from 'react'\nimport { useFormContext } from './useFormContext'\nimport { InitializeAction } from './actions/initialize'\n\nexport function useInitialize<T extends z.ZodTypeAny = z.ZodNever>(\n options: Omit<InitializeAction<T>, 'type'>,\n deps: DependencyList = [options.values, options.rawValues]\n) {\n const { initialize } = useFormContext<T>()\n React.useEffect(() => {\n initialize(options)\n }, deps)\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAGO,SAASE,aAAaA,CAC3BC,OAA0C,EAE1C;EAAA,IADAC,IAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAACF,OAAO,CAACK,MAAM,EAAEL,OAAO,CAACM,SAAS,CAAC;EAE1D,IAAAC,eAAA,GAAuB,IAAAC,+BAAc,EAAI,CAAC;IAAlCC,UAAU,GAAAF,eAAA,CAAVE,UAAU;EAClBC,iBAAK,CAACC,SAAS,CAAC,YAAM;IACpBF,UAAU,CAACT,OAAO,CAAC;EACrB,CAAC,EAAEC,IAAI,CAAC;AACV","ignoreList":[]}
1
+ {"version":3,"file":"useInitialize.js","names":["_react","_interopRequireDefault","require","_useFormContext2","useInitialize","options","deps","arguments","length","undefined","values","rawValues","_useFormContext","useFormContext","initialize","React","useEffect"],"sources":["src/useInitialize.ts"],"sourcesContent":["import z from 'zod'\nimport React, { DependencyList } from 'react'\nimport { useFormContext } from './useFormContext'\nimport { InitializeAction } from './actions/initialize'\n\nexport function useInitialize<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'you must pass a schema type'\n >\n>(\n options: Omit<InitializeAction<T>, 'type'>,\n deps: DependencyList = [options.values, options.rawValues]\n) {\n const { initialize } = useFormContext<T>()\n React.useEffect(() => {\n initialize(options)\n }, deps)\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAGO,SAASE,aAAaA,CAM3BC,OAA0C,EAE1C;EAAA,IADAC,IAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAACF,OAAO,CAACK,MAAM,EAAEL,OAAO,CAACM,SAAS,CAAC;EAE1D,IAAAC,eAAA,GAAuB,IAAAC,+BAAc,EAAI,CAAC;IAAlCC,UAAU,GAAAF,eAAA,CAAVE,UAAU;EAClBC,iBAAK,CAACC,SAAS,CAAC,YAAM;IACpBF,UAAU,CAACT,OAAO,CAAC;EACrB,CAAC,EAAEC,IAAI,CAAC;AACV","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useInitialize.mjs","names":["React","useFormContext","useInitialize","options","deps","values","rawValues","initialize","useEffect"],"sources":["src/useInitialize.ts"],"sourcesContent":["import z from 'zod'\nimport React, { DependencyList } from 'react'\nimport { useFormContext } from './useFormContext'\nimport { InitializeAction } from './actions/initialize'\n\nexport function useInitialize<T extends z.ZodTypeAny = z.ZodNever>(\n options: Omit<InitializeAction<T>, 'type'>,\n deps: DependencyList = [options.values, options.rawValues]\n) {\n const { initialize } = useFormContext<T>()\n React.useEffect(() => {\n initialize(options)\n }, deps)\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAA0B,OAAO;AAC7C,SAASC,cAAc;AAGvB,OAAO,SAASC,aAAaA,CAC3BC,OAA0C,EAC1CC,IAAoB,GAAG,CAACD,OAAO,CAACE,MAAM,EAAEF,OAAO,CAACG,SAAS,CAAC,EAC1D;EACA,MAAM;IAAEC;EAAW,CAAC,GAAGN,cAAc,CAAI,CAAC;EAC1CD,KAAK,CAACQ,SAAS,CAAC,MAAM;IACpBD,UAAU,CAACJ,OAAO,CAAC;EACrB,CAAC,EAAEC,IAAI,CAAC;AACV","ignoreList":[]}
1
+ {"version":3,"file":"useInitialize.mjs","names":["React","useFormContext","useInitialize","options","deps","values","rawValues","initialize","useEffect"],"sources":["src/useInitialize.ts"],"sourcesContent":["import z from 'zod'\nimport React, { DependencyList } from 'react'\nimport { useFormContext } from './useFormContext'\nimport { InitializeAction } from './actions/initialize'\n\nexport function useInitialize<\n T extends z.ZodTypeAny = z.ZodBranded<\n z.ZodNever,\n 'you must pass a schema type'\n >\n>(\n options: Omit<InitializeAction<T>, 'type'>,\n deps: DependencyList = [options.values, options.rawValues]\n) {\n const { initialize } = useFormContext<T>()\n React.useEffect(() => {\n initialize(options)\n }, deps)\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAA0B,OAAO;AAC7C,SAASC,cAAc;AAGvB,OAAO,SAASC,aAAaA,CAM3BC,OAA0C,EAC1CC,IAAoB,GAAG,CAACD,OAAO,CAACE,MAAM,EAAEF,OAAO,CAACG,SAAS,CAAC,EAC1D;EACA,MAAM;IAAEC;EAAW,CAAC,GAAGN,cAAc,CAAI,CAAC;EAC1CD,KAAK,CAACQ,SAAS,CAAC,MAAM;IACpBD,UAAU,CAACJ,OAAO,CAAC;EACrB,CAAC,EAAEC,IAAI,CAAC;AACV","ignoreList":[]}