@conform-to/react 1.0.2 → 1.0.3
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 +1 -1
- package/context.d.ts +3 -3
- package/helpers.d.ts +5 -5
- package/helpers.js +4 -4
- package/helpers.mjs +4 -4
- package/hooks.d.ts +1 -1
- package/hooks.js +2 -0
- package/hooks.mjs +2 -0
- package/package.json +6 -4
package/README
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Version 1.0.
|
|
11
|
+
Version 1.0.3 / License MIT / Copyright (c) 2024 Edmund Hung
|
|
12
12
|
|
|
13
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
14
|
|
package/context.d.ts
CHANGED
|
@@ -27,11 +27,11 @@ export type FormMetadata<Schema extends Record<string, unknown> = Record<string,
|
|
|
27
27
|
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
|
|
28
28
|
noValidate: boolean;
|
|
29
29
|
};
|
|
30
|
-
type SubfieldMetadata<Schema, FormSchema extends Record<string, any>, FormError
|
|
30
|
+
type SubfieldMetadata<Schema, FormSchema extends Record<string, any>, FormError> = [Schema] extends [Primitive] ? {} : [Schema] extends [Array<infer Item> | null | undefined] ? {
|
|
31
31
|
getFieldList: () => Array<FieldMetadata<Item, FormSchema, FormError>>;
|
|
32
|
-
} :
|
|
32
|
+
} : [Schema] extends [Record<string, any> | null | undefined] ? {
|
|
33
33
|
getFieldset: () => Required<{
|
|
34
|
-
[Key in keyof
|
|
34
|
+
[Key in keyof Combine<Schema>]: FieldMetadata<Combine<Schema>[Key], FormSchema, FormError>;
|
|
35
35
|
}>;
|
|
36
36
|
} : {};
|
|
37
37
|
export type FieldMetadata<Schema = unknown, FormSchema extends Record<string, any> = Record<string, unknown>, FormError = string[]> = Metadata<Schema, FormSchema, FormError> & Constraint & {
|
package/helpers.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ export declare function getFormControlProps<Schema>(metadata: FieldMetadata<Sche
|
|
|
125
125
|
* Depends on the provided options, it will also set `defaultChecked` / `checked` if it is a checkbox or radio button,
|
|
126
126
|
* or otherwise `defaultValue` / `value`.
|
|
127
127
|
*
|
|
128
|
-
* @see https://conform.guide/api/react/
|
|
128
|
+
* @see https://conform.guide/api/react/getInputProps
|
|
129
129
|
* @example
|
|
130
130
|
* ```tsx
|
|
131
131
|
* // To setup an uncontrolled input
|
|
@@ -145,7 +145,7 @@ export declare function getInputProps<Schema>(metadata: FieldMetadata<Schema, an
|
|
|
145
145
|
* and constraint attributes such as `required` or `multiple`.
|
|
146
146
|
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
147
147
|
*
|
|
148
|
-
* @see https://conform.guide/api/react/
|
|
148
|
+
* @see https://conform.guide/api/react/getSelectProps
|
|
149
149
|
* @example
|
|
150
150
|
* ```tsx
|
|
151
151
|
* // To setup an uncontrolled select
|
|
@@ -161,7 +161,7 @@ export declare function getSelectProps<Schema>(metadata: FieldMetadata<Schema, a
|
|
|
161
161
|
* and constraint attributes such as `required`, `minLength` or `maxLength`.
|
|
162
162
|
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
163
163
|
*
|
|
164
|
-
* @see https://conform.guide/api/react/
|
|
164
|
+
* @see https://conform.guide/api/react/getTextareaProps
|
|
165
165
|
* @example
|
|
166
166
|
* ```tsx
|
|
167
167
|
* // To setup an uncontrolled textarea
|
|
@@ -175,7 +175,7 @@ export declare function getTextareaProps<Schema>(metadata: FieldMetadata<Schema,
|
|
|
175
175
|
* Derives the properties of a collection of checkboxes or radio buttons based on the field metadata,
|
|
176
176
|
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby` and `required`.
|
|
177
177
|
*
|
|
178
|
-
* @see https://conform.guide/api/react/
|
|
178
|
+
* @see https://conform.guide/api/react/getTextareaProps
|
|
179
179
|
* @example
|
|
180
180
|
* ```tsx
|
|
181
181
|
* <fieldset>
|
|
@@ -201,7 +201,7 @@ export declare function getCollectionProps<Schema extends Array<string | boolean
|
|
|
201
201
|
*/
|
|
202
202
|
options: string[];
|
|
203
203
|
/**
|
|
204
|
-
* Decide whether defaultValue should be returned. Pass `false` if you want to
|
|
204
|
+
* Decide whether defaultValue should be returned. Pass `false` if you want to manage the value yourself.
|
|
205
205
|
*/
|
|
206
206
|
value?: boolean;
|
|
207
207
|
}>): Array<InputProps & Pick<Required<InputProps>, 'type' | 'value'>>;
|
package/helpers.js
CHANGED
|
@@ -85,7 +85,7 @@ function getFormControlProps(metadata, options) {
|
|
|
85
85
|
* Depends on the provided options, it will also set `defaultChecked` / `checked` if it is a checkbox or radio button,
|
|
86
86
|
* or otherwise `defaultValue` / `value`.
|
|
87
87
|
*
|
|
88
|
-
* @see https://conform.guide/api/react/
|
|
88
|
+
* @see https://conform.guide/api/react/getInputProps
|
|
89
89
|
* @example
|
|
90
90
|
* ```tsx
|
|
91
91
|
* // To setup an uncontrolled input
|
|
@@ -126,7 +126,7 @@ function getInputProps(metadata, options) {
|
|
|
126
126
|
* and constraint attributes such as `required` or `multiple`.
|
|
127
127
|
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
128
128
|
*
|
|
129
|
-
* @see https://conform.guide/api/react/
|
|
129
|
+
* @see https://conform.guide/api/react/getSelectProps
|
|
130
130
|
* @example
|
|
131
131
|
* ```tsx
|
|
132
132
|
* // To setup an uncontrolled select
|
|
@@ -153,7 +153,7 @@ function getSelectProps(metadata) {
|
|
|
153
153
|
* and constraint attributes such as `required`, `minLength` or `maxLength`.
|
|
154
154
|
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
155
155
|
*
|
|
156
|
-
* @see https://conform.guide/api/react/
|
|
156
|
+
* @see https://conform.guide/api/react/getTextareaProps
|
|
157
157
|
* @example
|
|
158
158
|
* ```tsx
|
|
159
159
|
* // To setup an uncontrolled textarea
|
|
@@ -179,7 +179,7 @@ function getTextareaProps(metadata) {
|
|
|
179
179
|
* Derives the properties of a collection of checkboxes or radio buttons based on the field metadata,
|
|
180
180
|
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby` and `required`.
|
|
181
181
|
*
|
|
182
|
-
* @see https://conform.guide/api/react/
|
|
182
|
+
* @see https://conform.guide/api/react/getTextareaProps
|
|
183
183
|
* @example
|
|
184
184
|
* ```tsx
|
|
185
185
|
* <fieldset>
|
package/helpers.mjs
CHANGED
|
@@ -81,7 +81,7 @@ function getFormControlProps(metadata, options) {
|
|
|
81
81
|
* Depends on the provided options, it will also set `defaultChecked` / `checked` if it is a checkbox or radio button,
|
|
82
82
|
* or otherwise `defaultValue` / `value`.
|
|
83
83
|
*
|
|
84
|
-
* @see https://conform.guide/api/react/
|
|
84
|
+
* @see https://conform.guide/api/react/getInputProps
|
|
85
85
|
* @example
|
|
86
86
|
* ```tsx
|
|
87
87
|
* // To setup an uncontrolled input
|
|
@@ -122,7 +122,7 @@ function getInputProps(metadata, options) {
|
|
|
122
122
|
* and constraint attributes such as `required` or `multiple`.
|
|
123
123
|
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
124
124
|
*
|
|
125
|
-
* @see https://conform.guide/api/react/
|
|
125
|
+
* @see https://conform.guide/api/react/getSelectProps
|
|
126
126
|
* @example
|
|
127
127
|
* ```tsx
|
|
128
128
|
* // To setup an uncontrolled select
|
|
@@ -149,7 +149,7 @@ function getSelectProps(metadata) {
|
|
|
149
149
|
* and constraint attributes such as `required`, `minLength` or `maxLength`.
|
|
150
150
|
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
151
151
|
*
|
|
152
|
-
* @see https://conform.guide/api/react/
|
|
152
|
+
* @see https://conform.guide/api/react/getTextareaProps
|
|
153
153
|
* @example
|
|
154
154
|
* ```tsx
|
|
155
155
|
* // To setup an uncontrolled textarea
|
|
@@ -175,7 +175,7 @@ function getTextareaProps(metadata) {
|
|
|
175
175
|
* Derives the properties of a collection of checkboxes or radio buttons based on the field metadata,
|
|
176
176
|
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby` and `required`.
|
|
177
177
|
*
|
|
178
|
-
* @see https://conform.guide/api/react/
|
|
178
|
+
* @see https://conform.guide/api/react/getTextareaProps
|
|
179
179
|
* @example
|
|
180
180
|
* ```tsx
|
|
181
181
|
* <fieldset>
|
package/hooks.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { type FormMetadata, type FieldMetadata, type Pretty, type FormOptions }
|
|
|
8
8
|
export declare const useSafeLayoutEffect: typeof useEffect;
|
|
9
9
|
export declare function useFormId<Schema extends Record<string, unknown>, FormError>(preferredId?: string): FormId<Schema, FormError>;
|
|
10
10
|
export declare function useNoValidate(defaultNoValidate?: boolean): boolean;
|
|
11
|
-
export declare function useForm<Schema extends Record<string, any>, FormValue = Schema, FormError = string[]>(options: Pretty<Omit<FormOptions<Schema, FormError, FormValue>, 'formId'> & {
|
|
11
|
+
export declare function useForm<Schema extends Record<string, any>, FormValue = Schema, FormError = string[]>(options: Pretty<Omit<FormOptions<Schema, FormError, FormValue>, 'formId' | 'onSchedule'> & {
|
|
12
12
|
/**
|
|
13
13
|
* The form id. If not provided, a random id will be generated.
|
|
14
14
|
*/
|
package/hooks.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
6
6
|
var react = require('react');
|
|
7
|
+
var reactDom = require('react-dom');
|
|
7
8
|
var context = require('./context.js');
|
|
8
9
|
|
|
9
10
|
var _excluded = ["id"];
|
|
@@ -37,6 +38,7 @@ function useForm(options) {
|
|
|
37
38
|
formConfig = _rollupPluginBabelHelpers.objectWithoutProperties(options, _excluded);
|
|
38
39
|
var formId = useFormId(id);
|
|
39
40
|
var [context$1] = react.useState(() => context.createFormContext(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, formConfig), {}, {
|
|
41
|
+
onSchedule: callback => reactDom.flushSync(callback),
|
|
40
42
|
formId
|
|
41
43
|
})));
|
|
42
44
|
useSafeLayoutEffect(() => {
|
package/hooks.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { useState, useEffect, useLayoutEffect, useId } from 'react';
|
|
3
|
+
import { flushSync } from 'react-dom';
|
|
3
4
|
import { createFormContext, useSubjectRef, useFormState, getFormMetadata, useFormContext, getFieldMetadata } from './context.mjs';
|
|
4
5
|
|
|
5
6
|
var _excluded = ["id"];
|
|
@@ -33,6 +34,7 @@ function useForm(options) {
|
|
|
33
34
|
formConfig = _objectWithoutProperties(options, _excluded);
|
|
34
35
|
var formId = useFormId(id);
|
|
35
36
|
var [context] = useState(() => createFormContext(_objectSpread2(_objectSpread2({}, formConfig), {}, {
|
|
37
|
+
onSchedule: callback => flushSync(callback),
|
|
36
38
|
formId
|
|
37
39
|
})));
|
|
38
40
|
useSafeLayoutEffect(() => {
|
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.0.
|
|
6
|
+
"version": "1.0.3",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
|
@@ -30,14 +30,16 @@
|
|
|
30
30
|
"url": "https://github.com/edmundhung/conform/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@conform-to/dom": "1.0.
|
|
33
|
+
"@conform-to/dom": "1.0.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/react": "^18.2.
|
|
36
|
+
"@types/react": "^18.2.64",
|
|
37
|
+
"@types/react-dom": "^18.2.20",
|
|
37
38
|
"react": "^18.2.0"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"react": ">=18"
|
|
41
|
+
"react": ">=18",
|
|
42
|
+
"react-dom": ">=18"
|
|
41
43
|
},
|
|
42
44
|
"keywords": [
|
|
43
45
|
"constraint-validation",
|