@octanejs/hook-form 0.1.58 → 0.1.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/hook-form",
3
- "version": "0.1.58",
3
+ "version": "0.1.59",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -32,23 +32,23 @@
32
32
  ".": "./src/index.ts"
33
33
  },
34
34
  "peerDependencies": {
35
- "octane": "^0.10.0"
35
+ "octane": "^0.11.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@octanejs/testing-library": "0.1.60",
38
+ "@octanejs/testing-library": "0.1.61",
39
39
  "@swc/core": "1.15.41",
40
40
  "@swc/jest": "0.2.39",
41
41
  "@testing-library/jest-dom": "^6.9.1",
42
42
  "@testing-library/react": "16.3.2",
43
43
  "@types/react": "^19.2.17",
44
44
  "@types/react-dom": "^19.2.3",
45
- "@tsrx/react": "^0.3.7",
45
+ "@tsrx/react": "^0.4.5",
46
46
  "esbuild": "^0.28.1",
47
47
  "jest": "30.4.2",
48
48
  "jest-environment-jsdom": "30.4.1",
49
49
  "jest-environment-node": "30.4.1",
50
50
  "jest-fixed-jsdom": "0.0.10",
51
- "octane": "0.10.2",
51
+ "octane": "0.11.0",
52
52
  "react": "19.2.7",
53
53
  "react-dom": "19.2.7",
54
54
  "react-hook-form": "7.81.0",
@@ -77,8 +77,8 @@ export function FormProvider<
77
77
  );
78
78
 
79
79
  <HookFormContext value={memoizedValue as unknown as UseFormReturn}>
80
- <HookFormControlContext
81
- value={memoizedValue.control as Control}
82
- >{children}</HookFormControlContext>
80
+ <HookFormControlContext value={memoizedValue.control as Control}>
81
+ {children}
82
+ </HookFormControlContext>
83
83
  </HookFormContext>
84
84
  }
@@ -10,6 +10,6 @@ export const Controller = <
10
10
  TFieldValues extends FieldValues = FieldValues,
11
11
  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
12
12
  TTransformedValues = TFieldValues,
13
- >(props: ControllerProps<TFieldValues, TName, TTransformedValues>) => props.render(
14
- useController<TFieldValues, TName, TTransformedValues>(props),
15
- );
13
+ >(
14
+ props: ControllerProps<TFieldValues, TName, TTransformedValues>,
15
+ ) => props.render(useController<TFieldValues, TName, TTransformedValues>(props));
package/src/form.tsrx CHANGED
@@ -29,79 +29,83 @@ export function Form<TFieldValues extends FieldValues, TTransformedValues = TFie
29
29
  ...rest
30
30
  } = props;
31
31
 
32
- const submit = useCallback(async (event) => {
33
- let hasError = false;
34
- let type = '';
32
+ const submit = useCallback(
33
+ async (event) => {
34
+ let hasError = false;
35
+ let type = '';
35
36
 
36
- await control.handleSubmit(async (data) => {
37
- const formData = new FormData();
38
- let formDataJson = '';
37
+ await control.handleSubmit(async (data) => {
38
+ const formData = new FormData();
39
+ let formDataJson = '';
39
40
 
40
- try {
41
- formDataJson = JSON.stringify(data);
42
- } catch {
43
- }
44
-
45
- const flattenFormValues = flatten(data as FieldValues);
46
-
47
- for (const key in flattenFormValues) {
48
- formData.append(key, flattenFormValues[key]);
49
- }
41
+ try {
42
+ formDataJson = JSON.stringify(data);
43
+ } catch {}
50
44
 
51
- if (onSubmit) {
52
- await onSubmit({
53
- data: data as TTransformedValues,
54
- event,
55
- method,
56
- formData,
57
- formDataJson,
58
- });
59
- }
45
+ const flattenFormValues = flatten(data as FieldValues);
60
46
 
61
- if (action) {
62
- try {
63
- const shouldStringifySubmissionData = [
64
- headers && headers['Content-Type'],
65
- encType,
66
- ].some((value) => value && value.includes('json'));
47
+ for (const key in flattenFormValues) {
48
+ formData.append(key, flattenFormValues[key]);
49
+ }
67
50
 
68
- const response = await fetch(String(action), {
51
+ if (onSubmit) {
52
+ await onSubmit({
53
+ data: data as TTransformedValues,
54
+ event,
69
55
  method,
70
- headers: {
71
- ...headers,
72
- ...(encType && encType !== 'multipart/form-data' ? { 'Content-Type': encType } : {}),
73
- },
74
- body: shouldStringifySubmissionData ? formDataJson : formData,
56
+ formData,
57
+ formDataJson,
75
58
  });
59
+ }
60
+
61
+ if (action) {
62
+ try {
63
+ const shouldStringifySubmissionData = [
64
+ headers && headers['Content-Type'],
65
+ encType,
66
+ ].some((value) => value && value.includes('json'));
67
+
68
+ const response = await fetch(String(action), {
69
+ method,
70
+ headers: {
71
+ ...headers,
72
+ ...(encType && encType !== 'multipart/form-data'
73
+ ? { 'Content-Type': encType }
74
+ : {}),
75
+ },
76
+ body: shouldStringifySubmissionData ? formDataJson : formData,
77
+ });
76
78
 
77
- if (
78
- response &&
79
+ if (
80
+ response &&
79
81
  (validateStatus
80
82
  ? !validateStatus(response.status)
81
83
  : response.status < 200 || response.status >= 300)
82
- ) {
84
+ ) {
85
+ hasError = true;
86
+ onError && onError({ response });
87
+ type = String(response.status);
88
+ } else {
89
+ onSuccess && onSuccess({ response });
90
+ }
91
+ } catch (error) {
83
92
  hasError = true;
84
- onError && onError({ response });
85
- type = String(response.status);
86
- } else {
87
- onSuccess && onSuccess({ response });
93
+ onError && onError({ error });
88
94
  }
89
- } catch (error) {
90
- hasError = true;
91
- onError && onError({ error });
92
95
  }
93
- }
94
- })(event);
96
+ })(event);
95
97
 
96
- if (hasError && control) {
97
- control._subjects.state.next({
98
- isSubmitSuccessful: false,
99
- });
100
- control.setError('root.server', {
101
- type,
102
- });
103
- }
104
- }, [control, onSubmit, method, action, headers, encType, validateStatus, onError, onSuccess]);
98
+ if (hasError && control) {
99
+ control._subjects.state.next({
100
+ isSubmitSuccessful: false,
101
+ });
102
+ control.setError('root.server', {
103
+ type,
104
+ });
105
+ }
106
+ },
107
+ [control, onSubmit, method, action, headers, encType, validateStatus, onError, onSuccess],
108
+ );
105
109
 
106
110
  useEffect(() => {
107
111
  setMounted(true);
@@ -111,12 +115,16 @@ export function Form<TFieldValues extends FieldValues, TTransformedValues = TFie
111
115
  return render({ submit });
112
116
  }
113
117
 
114
- return <form
115
- noValidate={mounted}
116
- action={action as string | undefined}
117
- method={method}
118
- encType={encType}
119
- onSubmit={submit}
120
- {...rest}
121
- >{children}</form>;
118
+ return (
119
+ <form
120
+ noValidate={mounted}
121
+ action={action as string | undefined}
122
+ method={method}
123
+ encType={encType}
124
+ onSubmit={submit}
125
+ {...rest}
126
+ >
127
+ {children}
128
+ </form>
129
+ );
122
130
  }
@@ -9,15 +9,16 @@ import type { FieldValues, UseFormStateProps, UseFormStateReturn } from './types
9
9
  export type FormStateSubscribeProps<
10
10
  TFieldValues extends FieldValues,
11
11
  TTransformedValues = TFieldValues,
12
- > =
13
- UseFormStateProps<TFieldValues, TTransformedValues> & {
14
- render: (values: UseFormStateReturn<TFieldValues>) => OctaneNode;
15
- };
12
+ > = UseFormStateProps<TFieldValues, TTransformedValues> & {
13
+ render: (values: UseFormStateReturn<TFieldValues>) => OctaneNode;
14
+ };
16
15
 
17
16
  export const FormStateSubscribe = <
18
17
  TFieldValues extends FieldValues,
19
18
  TTransformedValues = TFieldValues,
20
- >(props: FormStateSubscribeProps<TFieldValues, TTransformedValues>) => {
19
+ >(
20
+ props: FormStateSubscribeProps<TFieldValues, TTransformedValues>,
21
+ ) => {
21
22
  const { control, disabled, exact, name, render } = props;
22
23
  return render(useFormState({ control, name, disabled, exact }));
23
24
  };
package/src/watch.tsrx CHANGED
@@ -7,17 +7,20 @@ import type { FieldPath, FieldValues, WatchProps, WatchRenderValue } from './typ
7
7
 
8
8
  export const Watch = <
9
9
  TFieldValues extends FieldValues = FieldValues,
10
- TFieldName extends | FieldPath<TFieldValues>
11
- | readonly [FieldPath<TFieldValues>, ...FieldPath<TFieldValues>[]]
12
- | FieldPath<TFieldValues>[]
13
- | readonly FieldPath<TFieldValues>[]
14
- | undefined = undefined,
10
+ TFieldName extends
11
+ | FieldPath<TFieldValues>
12
+ | readonly [FieldPath<TFieldValues>, ...FieldPath<TFieldValues>[]]
13
+ | FieldPath<TFieldValues>[]
14
+ | readonly FieldPath<TFieldValues>[]
15
+ | undefined = undefined,
15
16
  TContext = any,
16
17
  TTransformedValues = TFieldValues,
17
18
  TComputeValue = undefined,
18
- >(props: WatchProps<TFieldName, TFieldValues, TContext, TTransformedValues, TComputeValue>) =>
19
+ >(
20
+ props: WatchProps<TFieldName, TFieldValues, TContext, TTransformedValues, TComputeValue>,
21
+ ) =>
19
22
  props.render(
20
- useWatch({ name: props.names, ...props as any }) as WatchRenderValue<
23
+ useWatch({ name: props.names, ...(props as any) }) as WatchRenderValue<
21
24
  TFieldName,
22
25
  TFieldValues,
23
26
  TComputeValue