@weser/forms 0.0.14 → 0.0.16

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/README.md CHANGED
@@ -1,22 +1,3 @@
1
- # @weser/hooks
1
+ # @weser/forms
2
2
 
3
- <img alt="npm version" src="https://badge.fury.io/js/@weser%2Fhooks.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/@weser/hooks.svg"> <a href="https://bundlephobia.com/result?p=@weser/hooks@latest"><img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@weser/hooks.svg"></a>
4
-
5
- ## Installation
6
-
7
- ```sh
8
- # npm
9
- npm i --save @weser/hooks
10
- # yarn
11
- yarn add @weser/hooks
12
- # pnpm
13
- pnpm add @weser/hooks
14
- ```
15
-
16
- ## Documentation
17
-
18
- ## License
19
-
20
- @weser/hooks is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
21
- Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br>
22
- Created with ♥ by [@robinweser](http://weser.io).
3
+ [Documentation](https://packages.weser.io/forms)
@@ -1,2 +1,2 @@
1
- import { $ZodIssue } from '@zod/core';
1
+ import { $ZodIssue } from 'zod/v4/core';
2
2
  export default function defaultFormatErrorMessage(error: $ZodIssue): string;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ZodIssue } from '@zod/core';
1
+ import { $ZodIssue } from 'zod/v4/core';
2
2
  export type Field<T> = {
3
3
  value: T;
4
4
  disabled: boolean;
@@ -1,6 +1,6 @@
1
1
  import { ChangeEvent } from 'react';
2
2
  import { ZodType } from 'zod';
3
- import { $ZodIssue } from '@zod/core';
3
+ import { $ZodIssue } from 'zod/v4/core';
4
4
  import { Field, Options } from './types.js';
5
5
  export default function useField<T = string, C = ChangeEvent<HTMLInputElement>>(schema: ZodType, { name, value, disabled, touched, showValidationOn, parseValue, formatErrorMessage, _onInit, _onUpdate, _storedField, }?: Options<T>): {
6
6
  valid: boolean;
package/dist/useField.js CHANGED
@@ -4,7 +4,7 @@ import defaultParseValue from './defaultParseValue.js';
4
4
  export default function useField(schema, { name, value = '', disabled = false, touched = false, showValidationOn = 'submit', parseValue = (defaultParseValue), formatErrorMessage = defaultFormatErrorMessage, _onInit, _onUpdate, _storedField, } = {}) {
5
5
  function _validate(value) {
6
6
  const { success, error } = schema.safeParse(value);
7
- if (!success) {
7
+ if (!success && error.issues.length > 0) {
8
8
  return formatErrorMessage(error.issues[0], value, name);
9
9
  }
10
10
  }
package/dist/useForm.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FormEvent, ChangeEvent } from 'react';
2
2
  import { z, ZodObject, ZodError, ZodRawShape } from 'zod';
3
- import { $ZodIssue } from '@zod/core';
3
+ import { $ZodIssue } from 'zod/v4/core';
4
4
  import { Options } from './types.js';
5
5
  export default function useForm<S extends ZodRawShape>(schema: ZodObject<S>, formatErrorMessage?: (error: $ZodIssue, value: any, name?: string) => string): {
6
6
  useFormField: <T = string, C = ChangeEvent<HTMLInputElement>>(_name: keyof S, options?: Omit<Options<T>, 'formatErrorMessage' | 'name' | '_onUpdateValue'>) => {
package/dist/useForm.js CHANGED
@@ -68,10 +68,10 @@ export default function useForm(schema, formatErrorMessage = defaultFormatErrorM
68
68
  onSubmit(parsed.data);
69
69
  }
70
70
  else {
71
+ if (parsed.error.issues.length > 0) {
72
+ _applyErrors(parsed.error.issues);
73
+ }
71
74
  if (onError) {
72
- if (parsed.error.issues.length > 0) {
73
- _applyErrors(parsed.error.issues);
74
- }
75
75
  onError(parsed.error);
76
76
  }
77
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weser/forms",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "React hooks for forms with zod schemas",
5
5
  "author": "Robin Weser <robin@weser.io>",
6
6
  "license": "MIT",
@@ -43,9 +43,6 @@
43
43
  "forms",
44
44
  "zod"
45
45
  ],
46
- "dependencies": {
47
- "@zod/core": "^0.11.6"
48
- },
49
46
  "peerDependencies": {
50
47
  "react": ">16.3.0",
51
48
  "zod": ">=4"
@@ -58,5 +55,5 @@
58
55
  "typescript": "^5.4.5",
59
56
  "zod": "^4.1.11"
60
57
  },
61
- "gitHead": "2844a44c54a0ada9f675baf40226f87fe894c29f"
58
+ "gitHead": "7b2bc4fa318330eb2031b0d1835554a8a9f0f6bd"
62
59
  }