@conform-to/react 1.2.0 → 1.2.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/context.d.ts CHANGED
@@ -1,200 +1,72 @@
1
- import {
2
- type Constraint,
3
- type Combine,
4
- type FormId,
5
- type FieldName,
6
- type FormContext as BaseFormContext,
7
- type FormValue,
8
- type FormState,
9
- type Intent,
10
- type SubscriptionScope,
11
- type SubscriptionSubject,
12
- type FormOptions as BaseFormOptions,
13
- } from '@conform-to/dom';
14
- import {
15
- type FormEvent,
16
- type ReactElement,
17
- type ReactNode,
18
- type MutableRefObject,
19
- } from 'react';
1
+ import { type Constraint, type Combine, type FormId, type FieldName, type FormContext as BaseFormContext, type FormValue, type FormState, type Intent, type SubscriptionScope, type SubscriptionSubject, type FormOptions as BaseFormOptions } from '@conform-to/dom';
2
+ import { type FormEvent, type ReactElement, type ReactNode, type MutableRefObject } from 'react';
20
3
  export type Pretty<T> = {
21
- [K in keyof T]: T[K];
4
+ [K in keyof T]: T[K];
22
5
  } & {};
23
- export type Primitive =
24
- | string
25
- | number
26
- | bigint
27
- | boolean
28
- | Date
29
- | File
30
- | null
31
- | undefined;
32
- export type Metadata<
33
- Schema,
34
- FormSchema extends Record<string, unknown>,
35
- FormError = string[],
36
- > = {
37
- key: string | undefined;
38
- id: string;
39
- errorId: string;
40
- descriptionId: string;
41
- name: FieldName<Schema, FormSchema, FormError>;
42
- initialValue: FormValue<Schema>;
43
- value: FormValue<Schema>;
44
- errors: FormError | undefined;
45
- allErrors: Record<string, FormError>;
46
- valid: boolean;
47
- dirty: boolean;
6
+ export type Primitive = string | number | bigint | boolean | Date | File | null | undefined;
7
+ export type Metadata<Schema, FormSchema extends Record<string, unknown>, FormError = string[]> = {
8
+ key: string | undefined;
9
+ id: string;
10
+ errorId: string;
11
+ descriptionId: string;
12
+ name: FieldName<Schema, FormSchema, FormError>;
13
+ initialValue: FormValue<Schema>;
14
+ value: FormValue<Schema>;
15
+ errors: FormError | undefined;
16
+ allErrors: Record<string, FormError>;
17
+ valid: boolean;
18
+ dirty: boolean;
48
19
  };
49
- export type FormMetadata<
50
- Schema extends Record<string, unknown> = Record<string, unknown>,
51
- FormError = string[],
52
- > = Omit<Metadata<Schema, Schema, FormError>, 'id'> &
53
- Pick<FormContext<Schema, FormError>, Intent['type']> & {
54
- id: FormId<Schema, FormError>;
55
- context: Wrapped<FormContext<Schema, FormError>>;
56
- status?: 'success' | 'error';
57
- getFieldset: () => Required<{
58
- [Key in keyof Combine<Schema>]: FieldMetadata<
59
- Combine<Schema>[Key],
60
- Schema,
61
- FormError
62
- >;
63
- }>;
64
- onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
65
- noValidate: boolean;
66
- };
67
- type SubfieldMetadata<
68
- Schema,
69
- FormSchema extends Record<string, any>,
70
- FormError,
71
- > = [Schema] extends [Primitive]
72
- ? {}
73
- : [Schema] extends [Array<infer Item> | null | undefined]
74
- ? {
75
- getFieldList: () => Array<FieldMetadata<Item, FormSchema, FormError>>;
76
- }
77
- : [Schema] extends [Record<string, any> | null | undefined]
78
- ? {
79
- getFieldset: () => Required<{
80
- [Key in keyof Combine<Schema>]: FieldMetadata<
81
- Combine<Schema>[Key],
82
- FormSchema,
83
- FormError
84
- >;
85
- }>;
86
- }
87
- : {};
88
- export type FieldMetadata<
89
- Schema = unknown,
90
- FormSchema extends Record<string, any> = Record<string, unknown>,
91
- FormError = string[],
92
- > = Metadata<Schema, FormSchema, FormError> &
93
- Constraint & {
94
- formId: FormId<FormSchema, FormError>;
95
- } & SubfieldMetadata<Schema, FormSchema, FormError>;
96
- export declare const Form: import('react').Context<
97
- FormContext<any, string[], any>[]
98
- >;
20
+ export type FormMetadata<Schema extends Record<string, unknown> = Record<string, unknown>, FormError = string[]> = Omit<Metadata<Schema, Schema, FormError>, 'id'> & Pick<FormContext<Schema, FormError>, Intent['type']> & {
21
+ id: FormId<Schema, FormError>;
22
+ context: Wrapped<FormContext<Schema, FormError>>;
23
+ status?: 'success' | 'error';
24
+ getFieldset: () => Required<{
25
+ [Key in keyof Combine<Schema>]: FieldMetadata<Combine<Schema>[Key], Schema, FormError>;
26
+ }>;
27
+ onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
28
+ noValidate: boolean;
29
+ };
30
+ type SubfieldMetadata<Schema, FormSchema extends Record<string, any>, FormError> = [Schema] extends [Primitive] ? {} : [Schema] extends [Array<infer Item> | null | undefined] ? {
31
+ getFieldList: () => Array<FieldMetadata<Item, FormSchema, FormError>>;
32
+ } : [Schema] extends [Record<string, any> | null | undefined] ? {
33
+ getFieldset: () => Required<{
34
+ [Key in keyof Combine<Schema>]: FieldMetadata<Combine<Schema>[Key], FormSchema, FormError>;
35
+ }>;
36
+ } : {};
37
+ export type FieldMetadata<Schema = unknown, FormSchema extends Record<string, any> = Record<string, unknown>, FormError = string[]> = Metadata<Schema, FormSchema, FormError> & Constraint & {
38
+ formId: FormId<FormSchema, FormError>;
39
+ } & SubfieldMetadata<Schema, FormSchema, FormError>;
40
+ export declare const Form: import("react").Context<FormContext<any, string[], any>[]>;
99
41
  declare const wrappedSymbol: unique symbol;
100
42
  export type Wrapped<Type> = {
101
- [wrappedSymbol]: Type;
43
+ [wrappedSymbol]: Type;
102
44
  };
103
- export declare function getWrappedFormContext(
104
- context: Wrapped<FormContext>,
105
- ): FormContext;
106
- export declare function useFormContext<
107
- Schema extends Record<string, any>,
108
- FormError,
109
- >(formId?: FormId<Schema, FormError>): FormContext<Schema, FormError, unknown>;
110
- export declare function useFormState<FormError>(
111
- form: FormContext<any, FormError>,
112
- subjectRef?: MutableRefObject<SubscriptionSubject>,
113
- ): FormState<FormError>;
45
+ export declare function getWrappedFormContext(context: Wrapped<FormContext>): FormContext;
46
+ export declare function useFormContext<Schema extends Record<string, any>, FormError>(formId?: FormId<Schema, FormError>): FormContext<Schema, FormError, unknown>;
47
+ export declare function useFormState<FormError>(form: FormContext<any, FormError>, subjectRef?: MutableRefObject<SubscriptionSubject>): FormState<FormError>;
114
48
  export declare function FormProvider(props: {
115
- context: Wrapped<FormContext<any, any>>;
116
- children: ReactNode;
49
+ context: Wrapped<FormContext<any, any>>;
50
+ children: ReactNode;
117
51
  }): ReactElement;
118
52
  export declare function FormStateInput(props: {
119
- formId?: string;
53
+ formId?: string;
120
54
  }): React.ReactElement;
121
- export declare function useSubjectRef(
122
- initialSubject?: SubscriptionSubject,
123
- ): MutableRefObject<SubscriptionSubject>;
124
- export declare function updateSubjectRef(
125
- ref: MutableRefObject<SubscriptionSubject>,
126
- subject: 'status' | 'formId',
127
- ): void;
128
- export declare function updateSubjectRef(
129
- ref: MutableRefObject<SubscriptionSubject>,
130
- subject: Exclude<keyof SubscriptionSubject, 'status' | 'formId'>,
131
- scope: keyof SubscriptionScope,
132
- name: string,
133
- ): void;
134
- export declare function getMetadata<
135
- Schema,
136
- FormError,
137
- FormSchema extends Record<string, any>,
138
- >(
139
- context: FormContext<FormSchema, FormError, any>,
140
- subjectRef: MutableRefObject<SubscriptionSubject>,
141
- stateSnapshot: FormState<FormError>,
142
- name?: FieldName<Schema, FormSchema, FormError>,
143
- ): Metadata<Schema, FormSchema, FormError>;
144
- export declare function getFieldMetadata<
145
- Schema,
146
- FormSchema extends Record<string, any>,
147
- FormError,
148
- >(
149
- context: FormContext<FormSchema, FormError, any>,
150
- subjectRef: MutableRefObject<SubscriptionSubject>,
151
- stateSnapshot: FormState<FormError>,
152
- prefix?: string,
153
- key?: string | number,
154
- ): FieldMetadata<Schema, FormSchema, FormError>;
155
- export declare function getFormMetadata<
156
- Schema extends Record<string, any>,
157
- FormError = string[],
158
- FormValue = Schema,
159
- >(
160
- context: FormContext<Schema, FormError, FormValue>,
161
- subjectRef: MutableRefObject<SubscriptionSubject>,
162
- stateSnapshot: FormState<FormError>,
163
- noValidate: boolean,
164
- ): FormMetadata<Schema, FormError>;
165
- export type FormOptions<
166
- Schema extends Record<string, any> = any,
167
- FormError = string[],
168
- FormValue = Schema,
169
- > = BaseFormOptions<Schema, FormError, FormValue> & {
170
- /**
171
- * A function to be called before the form is submitted.
172
- */
173
- onSubmit?: (
174
- event: FormEvent<HTMLFormElement>,
175
- context: ReturnType<
176
- BaseFormContext<Schema, FormError, FormValue>['submit']
177
- >,
178
- ) => void;
55
+ export declare function useSubjectRef(initialSubject?: SubscriptionSubject): MutableRefObject<SubscriptionSubject>;
56
+ export declare function updateSubjectRef(ref: MutableRefObject<SubscriptionSubject>, subject: 'status' | 'formId'): void;
57
+ export declare function updateSubjectRef(ref: MutableRefObject<SubscriptionSubject>, subject: Exclude<keyof SubscriptionSubject, 'status' | 'formId'>, scope: keyof SubscriptionScope, name: string): void;
58
+ export declare function getMetadata<Schema, FormError, FormSchema extends Record<string, any>>(context: FormContext<FormSchema, FormError, any>, subjectRef: MutableRefObject<SubscriptionSubject>, stateSnapshot: FormState<FormError>, name?: FieldName<Schema, FormSchema, FormError>): Metadata<Schema, FormSchema, FormError>;
59
+ export declare function getFieldMetadata<Schema, FormSchema extends Record<string, any>, FormError>(context: FormContext<FormSchema, FormError, any>, subjectRef: MutableRefObject<SubscriptionSubject>, stateSnapshot: FormState<FormError>, prefix?: string, key?: string | number): FieldMetadata<Schema, FormSchema, FormError>;
60
+ export declare function getFormMetadata<Schema extends Record<string, any>, FormError = string[], FormValue = Schema>(context: FormContext<Schema, FormError, FormValue>, subjectRef: MutableRefObject<SubscriptionSubject>, stateSnapshot: FormState<FormError>, noValidate: boolean): FormMetadata<Schema, FormError>;
61
+ export type FormOptions<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema> = BaseFormOptions<Schema, FormError, FormValue> & {
62
+ /**
63
+ * A function to be called before the form is submitted.
64
+ */
65
+ onSubmit?: (event: FormEvent<HTMLFormElement>, context: ReturnType<BaseFormContext<Schema, FormError, FormValue>['submit']>) => void;
179
66
  };
180
- export type FormContext<
181
- Schema extends Record<string, any> = any,
182
- FormError = string[],
183
- FormValue = Schema,
184
- > = Omit<
185
- BaseFormContext<Schema, FormError, FormValue>,
186
- 'submit' | 'onUpdate'
187
- > & {
188
- submit: (event: FormEvent<HTMLFormElement>) => void;
189
- onUpdate: (
190
- options: Partial<FormOptions<Schema, FormError, FormValue>>,
191
- ) => void;
67
+ export type FormContext<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema> = Omit<BaseFormContext<Schema, FormError, FormValue>, 'submit' | 'onUpdate'> & {
68
+ submit: (event: FormEvent<HTMLFormElement>) => void;
69
+ onUpdate: (options: Partial<FormOptions<Schema, FormError, FormValue>>) => void;
192
70
  };
193
- export declare function createFormContext<
194
- Schema extends Record<string, any> = any,
195
- FormError = string[],
196
- FormValue = Schema,
197
- >(
198
- options: FormOptions<Schema, FormError, FormValue>,
199
- ): FormContext<Schema, FormError, FormValue>;
71
+ export declare function createFormContext<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema>(options: FormOptions<Schema, FormError, FormValue>): FormContext<Schema, FormError, FormValue>;
200
72
  export {};
package/hooks.d.ts CHANGED
@@ -1,63 +1,34 @@
1
1
  import { type FormId, type FieldName } from '@conform-to/dom';
2
2
  import { useEffect } from 'react';
3
- import {
4
- type FormMetadata,
5
- type FieldMetadata,
6
- type Pretty,
7
- type FormOptions,
8
- } from './context';
3
+ import { type FormMetadata, type FieldMetadata, type Pretty, type FormOptions } from './context';
9
4
  /**
10
5
  * useLayoutEffect is client-only.
11
6
  * This basically makes it a no-op on server
12
7
  */
13
8
  export declare const useSafeLayoutEffect: typeof useEffect;
14
- export declare function useFormId<
15
- Schema extends Record<string, unknown>,
16
- FormError,
17
- >(preferredId?: string): FormId<Schema, FormError>;
9
+ export declare function useFormId<Schema extends Record<string, unknown>, FormError>(preferredId?: string): FormId<Schema, FormError>;
18
10
  export declare function useNoValidate(defaultNoValidate?: boolean): boolean;
19
- export declare function useForm<
20
- Schema extends Record<string, any>,
21
- FormValue = Schema,
22
- FormError = string[],
23
- >(
24
- options: Pretty<
25
- Omit<FormOptions<Schema, FormError, FormValue>, 'formId'> & {
26
- /**
27
- * The form id. If not provided, a random id will be generated.
28
- */
29
- id?: string;
30
- /**
31
- * Enable constraint validation before the dom is hydated.
32
- *
33
- * Default to `true`.
34
- */
35
- defaultNoValidate?: boolean;
36
- }
37
- >,
38
- ): [
39
- FormMetadata<Schema, FormError>,
40
- ReturnType<FormMetadata<Schema, FormError>['getFieldset']>,
11
+ export declare function useForm<Schema extends Record<string, any>, FormValue = Schema, FormError = string[]>(options: Pretty<Omit<FormOptions<Schema, FormError, FormValue>, 'formId'> & {
12
+ /**
13
+ * The form id. If not provided, a random id will be generated.
14
+ */
15
+ id?: string;
16
+ /**
17
+ * Enable constraint validation before the dom is hydated.
18
+ *
19
+ * Default to `true`.
20
+ */
21
+ defaultNoValidate?: boolean;
22
+ }>): [
23
+ FormMetadata<Schema, FormError>,
24
+ ReturnType<FormMetadata<Schema, FormError>['getFieldset']>
41
25
  ];
42
- export declare function useFormMetadata<
43
- Schema extends Record<string, any>,
44
- FormError = string[],
45
- >(
46
- formId?: FormId<Schema, FormError>,
47
- options?: {
48
- defaultNoValidate?: boolean;
49
- },
50
- ): FormMetadata<Schema, FormError>;
51
- export declare function useField<
52
- FieldSchema,
53
- FormSchema extends Record<string, unknown> = Record<string, unknown>,
54
- FormError = string[],
55
- >(
56
- name: FieldName<FieldSchema, FormSchema, FormError>,
57
- options?: {
58
- formId?: FormId<FormSchema, FormError>;
59
- },
60
- ): [
61
- FieldMetadata<FieldSchema, FormSchema, FormError>,
62
- FormMetadata<FormSchema, FormError>,
26
+ export declare function useFormMetadata<Schema extends Record<string, any>, FormError = string[]>(formId?: FormId<Schema, FormError>, options?: {
27
+ defaultNoValidate?: boolean;
28
+ }): FormMetadata<Schema, FormError>;
29
+ export declare function useField<FieldSchema, FormSchema extends Record<string, unknown> = Record<string, unknown>, FormError = string[]>(name: FieldName<FieldSchema, FormSchema, FormError>, options?: {
30
+ formId?: FormId<FormSchema, FormError>;
31
+ }): [
32
+ FieldMetadata<FieldSchema, FormSchema, FormError>,
33
+ FormMetadata<FormSchema, FormError>
63
34
  ];
package/hooks.js CHANGED
@@ -89,8 +89,8 @@ function useForm(options) {
89
89
  var prev = element.dataset.conform;
90
90
  var next = stateSnapshot.key[element.name];
91
91
  var defaultValue = stateSnapshot.initialValue[element.name];
92
- if (prev === 'managed') {
93
- // Skip fields managed by useInputControl()
92
+ if (prev === 'managed' || element.type === 'submit' || element.type === 'reset' || element.type === 'button') {
93
+ // Skip buttons and fields managed by useInputControl()
94
94
  continue;
95
95
  }
96
96
  if (typeof prev === 'undefined' || prev !== next) {
package/hooks.mjs CHANGED
@@ -85,8 +85,8 @@ function useForm(options) {
85
85
  var prev = element.dataset.conform;
86
86
  var next = stateSnapshot.key[element.name];
87
87
  var defaultValue = stateSnapshot.initialValue[element.name];
88
- if (prev === 'managed') {
89
- // Skip fields managed by useInputControl()
88
+ if (prev === 'managed' || element.type === 'submit' || element.type === 'reset' || element.type === 'button') {
89
+ // Skip buttons and fields managed by useInputControl()
90
90
  continue;
91
91
  }
92
92
  if (typeof prev === 'undefined' || prev !== next) {
package/index.d.ts CHANGED
@@ -1,29 +1,5 @@
1
- export {
2
- type Submission,
3
- type SubmissionResult,
4
- type DefaultValue,
5
- type Intent,
6
- type FormId,
7
- type FieldName,
8
- parse,
9
- } from '@conform-to/dom';
10
- export {
11
- type FieldMetadata,
12
- type FormMetadata,
13
- FormProvider,
14
- FormStateInput,
15
- } from './context';
1
+ export { type Submission, type SubmissionResult, type DefaultValue, type Intent, type FormId, type FieldName, parse, } from '@conform-to/dom';
2
+ export { type FieldMetadata, type FormMetadata, FormProvider, FormStateInput, } from './context';
16
3
  export { useForm, useFormMetadata, useField } from './hooks';
17
- export {
18
- Control as unstable_Control,
19
- useControl as unstable_useControl,
20
- useInputControl,
21
- } from './integrations';
22
- export {
23
- getFormProps,
24
- getFieldsetProps,
25
- getInputProps,
26
- getSelectProps,
27
- getTextareaProps,
28
- getCollectionProps,
29
- } from './helpers';
4
+ export { Control as unstable_Control, useControl as unstable_useControl, useInputControl, } from './integrations';
5
+ export { getFormProps, getFieldsetProps, getInputProps, getSelectProps, getTextareaProps, getCollectionProps, } from './helpers';
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Conform view adapter for react",
4
4
  "homepage": "https://conform.guide",
5
5
  "license": "MIT",
6
- "version": "1.2.0",
6
+ "version": "1.2.1",
7
7
  "main": "index.js",
8
8
  "module": "index.mjs",
9
9
  "types": "index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "url": "https://github.com/edmundhung/conform/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@conform-to/dom": "1.2.0"
33
+ "@conform-to/dom": "1.2.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.17.8",
package/README DELETED
@@ -1,37 +0,0 @@
1
-
2
-
3
- ███████╗ ██████╗ ███╗ ██╗ ████████╗ ██████╗ ███████╗ ███╗ ███╗
4
- ██╔═════╝ ██╔═══██╗ ████╗ ██║ ██╔═════╝ ██╔═══██╗ ██╔═══██╗ ████████║
5
- ██║ ██║ ██║ ██╔██╗██║ ███████╗ ██║ ██║ ███████╔╝ ██╔██╔██║
6
- ██║ ██║ ██║ ██║╚████║ ██╔════╝ ██║ ██║ ██╔═══██╗ ██║╚═╝██║
7
- ╚███████╗ ╚██████╔╝ ██║ ╚███║ ██║ ╚██████╔╝ ██║ ██║ ██║ ██║
8
- ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
9
-
10
-
11
- Version 1.1.3 / License MIT / Copyright (c) 2024 Edmund Hung
12
-
13
- A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js.
14
-
15
- # Getting Started
16
-
17
- Check out the overview and tutorial at our website https://conform.guide
18
-
19
- # Features
20
-
21
- - Progressive enhancement first APIs
22
- - Type-safe field inference
23
- - Fine-grained subscription
24
- - Built-in accessibility helpers
25
- - Automatic type coercion with Zod
26
-
27
- # Documentation
28
-
29
- - Validation: https://conform.guide/validation
30
- - Nested object and Array: https://conform.guide/complex-structures
31
- - UI Integrations: https://conform.guide/integration/ui-libraries
32
- - Intent button: https://conform.guide/intent-button
33
- - Accessibility Guide: https://conform.guide/accessibility
34
-
35
- # Support
36
-
37
- To report a bug, please open an issue on the repository at https://github.com/edmundhung/conform. For feature requests and questions, you can post them in the Discussions section.
package/experimental.d.ts DELETED
File without changes