@conform-to/react 0.9.1 → 1.0.0-pre.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 +64 -0
- package/context.js +196 -0
- package/context.mjs +183 -0
- package/helpers.d.ts +206 -50
- package/helpers.js +206 -101
- package/helpers.mjs +199 -85
- package/hooks.d.ts +33 -199
- package/hooks.js +83 -715
- package/hooks.mjs +81 -710
- package/index.d.ts +6 -3
- package/index.js +22 -15
- package/index.mjs +6 -4
- package/integrations.d.ts +18 -0
- package/integrations.js +161 -0
- package/integrations.mjs +155 -0
- package/package.json +3 -3
- package/validitystate.d.ts +12 -0
- package/validitystate.js +38 -0
- package/validitystate.mjs +34 -0
package/helpers.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
|
|
2
|
+
import { INTENT, serializeIntents } from '@conform-to/dom';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Cleanup `undefined` from the
|
|
5
|
+
* Cleanup `undefined` from the result.
|
|
6
6
|
* To minimize conflicts when merging with user defined props
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
8
|
+
function simplify(props) {
|
|
9
9
|
for (var key in props) {
|
|
10
10
|
if (props[key] === undefined) {
|
|
11
11
|
delete props[key];
|
|
@@ -13,99 +13,213 @@ function cleanup(props) {
|
|
|
13
13
|
}
|
|
14
14
|
return props;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Derives aria attributes of a form control based on the field metadata.
|
|
19
|
+
*/
|
|
20
|
+
function getAriaAttributes(metadata) {
|
|
18
21
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'aria-
|
|
26
|
-
|
|
27
|
-
return id;
|
|
28
|
-
}
|
|
29
|
-
if (!id) {
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
return "".concat(result, " ").concat(id);
|
|
33
|
-
}) : undefined
|
|
22
|
+
if (typeof options.ariaAttributes !== 'undefined' && !options.ariaAttributes) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
var invalid = options.ariaInvalid === 'all' ? !metadata.allValid : !metadata.valid;
|
|
26
|
+
var ariaDescribedBy = typeof options.ariaDescribedBy === 'string' ? options.ariaDescribedBy : options.ariaDescribedBy ? metadata.descriptionId : undefined;
|
|
27
|
+
return simplify({
|
|
28
|
+
'aria-invalid': invalid || undefined,
|
|
29
|
+
'aria-describedby': invalid ? "".concat(metadata.errorId, " ").concat(ariaDescribedBy !== null && ariaDescribedBy !== void 0 ? ariaDescribedBy : '').trim() : ariaDescribedBy
|
|
34
30
|
});
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Derives the properties of a form element based on the form metadata,
|
|
35
|
+
* including `id`, `onSubmit`, `noValidate`, `aria-invalid` and `aria-describedby`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* <form {...getFormProps(metadata)} />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function getFormProps(metadata, options) {
|
|
43
|
+
return simplify(_objectSpread2({
|
|
44
|
+
id: metadata.id,
|
|
45
|
+
onSubmit: metadata.onSubmit,
|
|
46
|
+
noValidate: metadata.noValidate
|
|
47
|
+
}, getAriaAttributes(metadata, options)));
|
|
41
48
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Derives the properties of a fieldset element based on the field metadata,
|
|
52
|
+
* including `id`, `name`, `form`, `aria-invalid` and `aria-describedby`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* <fieldset {...getFieldsetProps(metadata)} />
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
function getFieldsetProps(metadata, options) {
|
|
60
|
+
return simplify(_objectSpread2({
|
|
61
|
+
id: metadata.id,
|
|
62
|
+
name: metadata.name,
|
|
63
|
+
form: metadata.formId
|
|
64
|
+
}, getAriaAttributes(metadata, options)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Derives common properties of a form control based on the field metadata,
|
|
69
|
+
* including `key`, `id`, `name`, `form`, `required`, `autoFocus`, `aria-invalid` and `aria-describedby`.
|
|
70
|
+
*/
|
|
71
|
+
function getFormControlProps(metadata, options) {
|
|
72
|
+
var _metadata$constraint;
|
|
73
|
+
return simplify(_objectSpread2({
|
|
74
|
+
key: metadata.key,
|
|
75
|
+
required: ((_metadata$constraint = metadata.constraint) === null || _metadata$constraint === void 0 ? void 0 : _metadata$constraint.required) || undefined,
|
|
76
|
+
autoFocus: !metadata.valid || undefined
|
|
77
|
+
}, getFieldsetProps(metadata, options)));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Derives the properties of an input element based on the field metadata,
|
|
82
|
+
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
|
|
83
|
+
* and constraint attributes such as `type`, `required`, `minLength`, `maxLength`, `min`, `max`, `step`, `pattern`, `multiple`.
|
|
84
|
+
* Depends on the provided options, it will also set `defaultChecked` / `checked` if it is a checkbox or radio button,
|
|
85
|
+
* or otherwise `defaultValue` / `value`.
|
|
86
|
+
*
|
|
87
|
+
* @see https://conform.guide/api/react/get-input-props
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* // To setup an uncontrolled input
|
|
91
|
+
* <input {...getInputProps(metadata)} />
|
|
92
|
+
* // To setup an uncontrolled checkbox
|
|
93
|
+
* <input {...getInputProps(metadata, { type: 'checkbox' })} />
|
|
94
|
+
* // To setup an input without defaultValue
|
|
95
|
+
* <input {...getInputProps(metadata, { value: false })} />
|
|
96
|
+
* // To setup a radio button without defaultChecked state
|
|
97
|
+
* <input {...getInputProps(metadata, { type: 'radio', value: false })} />
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
function getInputProps(metadata) {
|
|
102
|
+
var _metadata$constraint2, _metadata$constraint3, _metadata$constraint4, _metadata$constraint5, _metadata$constraint6, _metadata$constraint7, _metadata$constraint8;
|
|
62
103
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
63
|
-
var props = _objectSpread2(_objectSpread2({}, getFormControlProps(
|
|
104
|
+
var props = _objectSpread2(_objectSpread2({}, getFormControlProps(metadata, options)), {}, {
|
|
64
105
|
type: options.type,
|
|
65
|
-
minLength:
|
|
66
|
-
maxLength:
|
|
67
|
-
min:
|
|
68
|
-
max:
|
|
69
|
-
step:
|
|
70
|
-
pattern:
|
|
71
|
-
multiple:
|
|
106
|
+
minLength: (_metadata$constraint2 = metadata.constraint) === null || _metadata$constraint2 === void 0 ? void 0 : _metadata$constraint2.minLength,
|
|
107
|
+
maxLength: (_metadata$constraint3 = metadata.constraint) === null || _metadata$constraint3 === void 0 ? void 0 : _metadata$constraint3.maxLength,
|
|
108
|
+
min: (_metadata$constraint4 = metadata.constraint) === null || _metadata$constraint4 === void 0 ? void 0 : _metadata$constraint4.min,
|
|
109
|
+
max: (_metadata$constraint5 = metadata.constraint) === null || _metadata$constraint5 === void 0 ? void 0 : _metadata$constraint5.max,
|
|
110
|
+
step: (_metadata$constraint6 = metadata.constraint) === null || _metadata$constraint6 === void 0 ? void 0 : _metadata$constraint6.step,
|
|
111
|
+
pattern: (_metadata$constraint7 = metadata.constraint) === null || _metadata$constraint7 === void 0 ? void 0 : _metadata$constraint7.pattern,
|
|
112
|
+
multiple: (_metadata$constraint8 = metadata.constraint) === null || _metadata$constraint8 === void 0 ? void 0 : _metadata$constraint8.multiple
|
|
72
113
|
});
|
|
73
|
-
if (options.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
114
|
+
if (typeof options.value === 'undefined' || options.value) {
|
|
115
|
+
if (options.type === 'checkbox' || options.type === 'radio') {
|
|
116
|
+
props.value = typeof options.value === 'string' ? options.value : 'on';
|
|
117
|
+
props.defaultChecked = typeof metadata.initialValue === 'boolean' ? metadata.initialValue : metadata.initialValue === props.value;
|
|
118
|
+
} else if (typeof metadata.initialValue === 'string') {
|
|
119
|
+
props.defaultValue = metadata.initialValue;
|
|
120
|
+
}
|
|
79
121
|
}
|
|
80
|
-
return
|
|
122
|
+
return simplify(props);
|
|
81
123
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Derives the properties of a select element based on the field metadata,
|
|
127
|
+
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
|
|
128
|
+
* and constraint attributes such as `required` or `multiple`.
|
|
129
|
+
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
130
|
+
*
|
|
131
|
+
* @see https://conform.guide/api/react/get-select-props
|
|
132
|
+
* @example
|
|
133
|
+
* ```tsx
|
|
134
|
+
* // To setup an uncontrolled select
|
|
135
|
+
* <select {...getSelectProps(metadata)} />
|
|
136
|
+
* // To setup a select without defaultValue
|
|
137
|
+
* <select {...getSelectProps(metadata, { value: false })} />
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
function getSelectProps(metadata) {
|
|
141
|
+
var _metadata$constraint9;
|
|
142
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
143
|
+
var props = _objectSpread2(_objectSpread2({}, getFormControlProps(metadata, options)), {}, {
|
|
144
|
+
multiple: (_metadata$constraint9 = metadata.constraint) === null || _metadata$constraint9 === void 0 ? void 0 : _metadata$constraint9.multiple
|
|
145
|
+
});
|
|
146
|
+
if (typeof options.value === 'undefined' || options.value) {
|
|
147
|
+
props.defaultValue = Array.isArray(metadata.initialValue) ? metadata.initialValue.map(item => "".concat(item !== null && item !== void 0 ? item : '')) : metadata.initialValue;
|
|
148
|
+
}
|
|
149
|
+
return simplify(props);
|
|
87
150
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Derives the properties of a textarea element based on the field metadata,
|
|
154
|
+
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
|
|
155
|
+
* and constraint attributes such as `required`, `minLength` or `maxLength`.
|
|
156
|
+
* Depends on the provided options, it will also set `defaultValue` / `value`.
|
|
157
|
+
*
|
|
158
|
+
* @see https://conform.guide/api/react/get-textarea-props
|
|
159
|
+
* @example
|
|
160
|
+
* ```tsx
|
|
161
|
+
* // To setup an uncontrolled textarea
|
|
162
|
+
* <textarea {...getTextareaProps(metadata)} />
|
|
163
|
+
* // To setup a textarea without defaultValue
|
|
164
|
+
* <textarea {...getTextareaProps(metadata, { value: false })} />
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
function getTextareaProps(metadata) {
|
|
168
|
+
var _metadata$constraint10, _metadata$constraint11;
|
|
169
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
170
|
+
var props = _objectSpread2(_objectSpread2({}, getFormControlProps(metadata, options)), {}, {
|
|
171
|
+
minLength: (_metadata$constraint10 = metadata.constraint) === null || _metadata$constraint10 === void 0 ? void 0 : _metadata$constraint10.minLength,
|
|
172
|
+
maxLength: (_metadata$constraint11 = metadata.constraint) === null || _metadata$constraint11 === void 0 ? void 0 : _metadata$constraint11.maxLength
|
|
173
|
+
});
|
|
174
|
+
if (typeof options.value === 'undefined' || options.value) {
|
|
175
|
+
props.defaultValue = metadata.initialValue;
|
|
176
|
+
}
|
|
177
|
+
return simplify(props);
|
|
94
178
|
}
|
|
95
|
-
|
|
96
|
-
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Derives the properties of a collection of checkboxes or radio buttons based on the field metadata,
|
|
182
|
+
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby` and `required`.
|
|
183
|
+
*
|
|
184
|
+
* @see https://conform.guide/api/react/get-textarea-props
|
|
185
|
+
* @example
|
|
186
|
+
* ```tsx
|
|
187
|
+
* <fieldset>
|
|
188
|
+
* {getCollectionProps(metadata, {
|
|
189
|
+
* type: 'checkbox',
|
|
190
|
+
* options: ['a', 'b', 'c']
|
|
191
|
+
* }).map((props) => (
|
|
192
|
+
* <div key={props.key}>
|
|
193
|
+
* <label htmlFor={props.id}>{props.value}</label>
|
|
194
|
+
* <input {...props} />
|
|
195
|
+
* </div>
|
|
196
|
+
* ))}
|
|
197
|
+
* </fieldset>
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
function getCollectionProps(metadata, options) {
|
|
201
|
+
return options.options.map(value => {
|
|
202
|
+
var _metadata$key, _metadata$constraint12;
|
|
203
|
+
return simplify(_objectSpread2(_objectSpread2({}, getFormControlProps(metadata, options)), {}, {
|
|
204
|
+
key: "".concat((_metadata$key = metadata.key) !== null && _metadata$key !== void 0 ? _metadata$key : '').concat(value),
|
|
205
|
+
id: "".concat(metadata.id, "-").concat(value),
|
|
206
|
+
type: options.type,
|
|
207
|
+
value,
|
|
208
|
+
defaultChecked: typeof options.value === 'undefined' || options.value ? options.type === 'checkbox' && Array.isArray(metadata.initialValue) ? metadata.initialValue.includes(value) : metadata.initialValue === value : undefined,
|
|
209
|
+
// The required attribute doesn't make sense for checkbox group
|
|
210
|
+
// As it would require all checkboxes to be checked instead of at least one
|
|
211
|
+
// It is overriden with `undefiend` so it could be cleaned up properly
|
|
212
|
+
required: options.type === 'checkbox' ? undefined : (_metadata$constraint12 = metadata.constraint) === null || _metadata$constraint12 === void 0 ? void 0 : _metadata$constraint12.required
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
97
215
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// As it would require all checkboxes to be checked instead of at least one
|
|
106
|
-
// overriden with `undefiend` so it gets cleaned up
|
|
107
|
-
required: options.type === 'checkbox' ? undefined : config.required
|
|
108
|
-
})));
|
|
216
|
+
function getControlButtonProps(formId, intents) {
|
|
217
|
+
return {
|
|
218
|
+
name: INTENT,
|
|
219
|
+
value: serializeIntents(intents),
|
|
220
|
+
form: formId,
|
|
221
|
+
formNoValidate: true
|
|
222
|
+
};
|
|
109
223
|
}
|
|
110
224
|
|
|
111
|
-
export {
|
|
225
|
+
export { getAriaAttributes, getCollectionProps, getControlButtonProps, getFieldsetProps, getFormControlProps, getFormProps, getInputProps, getSelectProps, getTextareaProps };
|
package/hooks.d.ts
CHANGED
|
@@ -1,208 +1,42 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The frist error of the field
|
|
14
|
-
*/
|
|
15
|
-
error?: string;
|
|
16
|
-
/**
|
|
17
|
-
* All of the field errors
|
|
18
|
-
*/
|
|
19
|
-
errors?: string[];
|
|
20
|
-
}
|
|
21
|
-
export type FieldValue<Schema> = Schema extends Primitive ? string : Schema extends File ? File : Schema extends Array<infer InnerType> ? Array<FieldValue<InnerType>> : unknown extends Schema ? any : Record<string, any> extends Schema ? {
|
|
22
|
-
[Key in KeysOf<Schema>]?: FieldValue<ResolveType<Schema, Key>>;
|
|
23
|
-
} : any;
|
|
24
|
-
type SubmissionResult = {
|
|
25
|
-
intent: Submission['intent'];
|
|
26
|
-
payload: Submission['payload'] | null;
|
|
27
|
-
error: Submission['error'];
|
|
28
|
-
};
|
|
29
|
-
export interface FormConfig<Output extends Record<string, any>, Input extends Record<string, any> = Output> {
|
|
1
|
+
import { type FormId, type FieldName, type FormOptions } from '@conform-to/dom';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { type FormMetadata, type FieldMetadata, type Pretty } from './context';
|
|
4
|
+
/**
|
|
5
|
+
* useLayoutEffect is client-only.
|
|
6
|
+
* This basically makes it a no-op on server
|
|
7
|
+
*/
|
|
8
|
+
export declare const useSafeLayoutEffect: typeof useEffect;
|
|
9
|
+
export declare function useFormId<Schema extends Record<string, unknown>, Error>(preferredId?: string): FormId<Schema, Error>;
|
|
10
|
+
export declare function useNoValidate(defaultNoValidate?: boolean): boolean;
|
|
11
|
+
export declare function useForm<Schema extends Record<string, any>, Error = string[], Value = Schema>(options: Pretty<FormOptions<Schema, Error, Value> & {
|
|
30
12
|
/**
|
|
31
13
|
* If the form id is provided, Id for label,
|
|
32
14
|
* input and error elements will be derived.
|
|
33
15
|
*/
|
|
34
16
|
id?: string;
|
|
35
17
|
/**
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
ref?: RefObject<HTMLFormElement>;
|
|
39
|
-
/**
|
|
40
|
-
* Define when conform should start validation.
|
|
41
|
-
* Support "onSubmit", "onInput", "onBlur".
|
|
42
|
-
*
|
|
43
|
-
* @default "onSubmit"
|
|
44
|
-
*/
|
|
45
|
-
shouldValidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
46
|
-
/**
|
|
47
|
-
* Define when conform should revalidate again.
|
|
48
|
-
* Support "onSubmit", "onInput", "onBlur".
|
|
49
|
-
*
|
|
50
|
-
* @default shouldValidate, or "onSubmit" if shouldValidate is not provided.
|
|
51
|
-
*/
|
|
52
|
-
shouldRevalidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
53
|
-
/**
|
|
54
|
-
* An object representing the initial value of the form.
|
|
55
|
-
*/
|
|
56
|
-
defaultValue?: FieldValue<Input>;
|
|
57
|
-
/**
|
|
58
|
-
* An object describing the result of the last submission
|
|
59
|
-
*/
|
|
60
|
-
lastSubmission?: SubmissionResult | null;
|
|
61
|
-
/**
|
|
62
|
-
* An object describing the constraint of each field
|
|
63
|
-
*/
|
|
64
|
-
constraint?: FieldsetConstraint<Input>;
|
|
65
|
-
/**
|
|
66
|
-
* Enable native validation before hydation.
|
|
67
|
-
*
|
|
68
|
-
* Default to `false`.
|
|
69
|
-
*/
|
|
70
|
-
fallbackNative?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Accept form submission regardless of the form validity.
|
|
18
|
+
* Enable constraint validation before the dom is hydated.
|
|
73
19
|
*
|
|
74
|
-
* Default to `
|
|
75
|
-
*/
|
|
76
|
-
noValidate?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* A function to be called when the form should be (re)validated.
|
|
79
|
-
*/
|
|
80
|
-
onValidate?: ({ form, formData, }: {
|
|
81
|
-
form: HTMLFormElement;
|
|
82
|
-
formData: FormData;
|
|
83
|
-
}) => Submission | Submission<Output>;
|
|
84
|
-
/**
|
|
85
|
-
* The submit event handler of the form. It will be called
|
|
86
|
-
* only when the form is considered valid.
|
|
20
|
+
* Default to `true`.
|
|
87
21
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
id?: string;
|
|
109
|
-
errorId?: string;
|
|
110
|
-
error: string | undefined;
|
|
111
|
-
errors: string[];
|
|
112
|
-
ref: RefObject<HTMLFormElement>;
|
|
113
|
-
props: FormProps;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Returns properties required to hook into form events.
|
|
117
|
-
* Applied custom validation and define when error should be reported.
|
|
118
|
-
*
|
|
119
|
-
* @see https://conform.guide/api/react#useform
|
|
120
|
-
*/
|
|
121
|
-
export declare function useForm<Output extends Record<string, any>, Input extends Record<string, any> = Output>(config?: FormConfig<Output, Input>): [Form, Fieldset<Input>];
|
|
122
|
-
/**
|
|
123
|
-
* A set of field configuration
|
|
124
|
-
*/
|
|
125
|
-
export type Fieldset<Schema extends Record<string, any> | undefined> = {
|
|
126
|
-
[Key in KeysOf<Schema>]-?: FieldConfig<ResolveType<Schema, Key>>;
|
|
22
|
+
defaultNoValidate?: boolean;
|
|
23
|
+
}>): {
|
|
24
|
+
meta: FormMetadata<Schema, Error>;
|
|
25
|
+
fields: ReturnType<FormMetadata<Schema, Error>['getFieldset']>;
|
|
26
|
+
};
|
|
27
|
+
export declare function useFormMetadata<Schema extends Record<string, any>, Error>(options: {
|
|
28
|
+
formId: FormId<Schema, Error>;
|
|
29
|
+
defaultNoValidate?: boolean;
|
|
30
|
+
}): FormMetadata<Schema, Error>;
|
|
31
|
+
export declare function useField<FormSchema extends Record<string, unknown>, FieldSchema = FormSchema, Error = unknown>(options: {
|
|
32
|
+
formId: FormId<FormSchema, Error>;
|
|
33
|
+
name: FieldName<FieldSchema>;
|
|
34
|
+
} | {
|
|
35
|
+
formId: FormId<FormSchema, Error>;
|
|
36
|
+
name?: undefined;
|
|
37
|
+
}): {
|
|
38
|
+
meta: FieldMetadata<FieldSchema, Error, FormSchema>;
|
|
39
|
+
fields: FieldMetadata<FieldSchema, Error, FormSchema>['getFieldset'] extends Function ? ReturnType<FieldMetadata<FieldSchema, Error, FormSchema>['getFieldset']> : never;
|
|
40
|
+
list: FieldMetadata<FieldSchema, Error, FormSchema>['getFieldList'] extends Function ? ReturnType<FieldMetadata<FieldSchema, Error, FormSchema>['getFieldList']> : never;
|
|
41
|
+
form: FormMetadata<FormSchema, Error>;
|
|
127
42
|
};
|
|
128
|
-
export interface FieldsetConfig<Schema extends Record<string, any> | undefined> {
|
|
129
|
-
/**
|
|
130
|
-
* The prefix used to generate the name of nested fields.
|
|
131
|
-
*/
|
|
132
|
-
name?: string;
|
|
133
|
-
/**
|
|
134
|
-
* An object representing the initial value of the fieldset.
|
|
135
|
-
*/
|
|
136
|
-
defaultValue?: FieldValue<Schema>;
|
|
137
|
-
/**
|
|
138
|
-
* An object describing the initial error of each field
|
|
139
|
-
*/
|
|
140
|
-
initialError?: Record<string, string[]>;
|
|
141
|
-
/**
|
|
142
|
-
* An object describing the constraint of each field
|
|
143
|
-
*/
|
|
144
|
-
constraint?: FieldsetConstraint<Schema>;
|
|
145
|
-
/**
|
|
146
|
-
* The id of the form, connecting each field to a form remotely
|
|
147
|
-
*/
|
|
148
|
-
form?: string;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Returns all the information about the fieldset.
|
|
152
|
-
*
|
|
153
|
-
* @see https://conform.guide/api/react#usefieldset
|
|
154
|
-
*/
|
|
155
|
-
export declare function useFieldset<Schema extends Record<string, any> | undefined>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldsetConfig<Schema>): Fieldset<Schema>;
|
|
156
|
-
export declare function useFieldset<Schema extends Record<string, any> | undefined>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Schema>): Fieldset<Schema>;
|
|
157
|
-
/**
|
|
158
|
-
* Returns a list of key and field config.
|
|
159
|
-
*
|
|
160
|
-
* @see https://conform.guide/api/react#usefieldlist
|
|
161
|
-
*/
|
|
162
|
-
export declare function useFieldList<Schema extends Array<any> | undefined>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Schema>): Array<{
|
|
163
|
-
key: string;
|
|
164
|
-
} & FieldConfig<Schema extends Array<infer Item> ? Item : never>>;
|
|
165
|
-
interface InputControl {
|
|
166
|
-
change: (eventOrValue: {
|
|
167
|
-
target: {
|
|
168
|
-
value: string;
|
|
169
|
-
};
|
|
170
|
-
} | string | boolean) => void;
|
|
171
|
-
focus: () => void;
|
|
172
|
-
blur: () => void;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Returns a ref object and a set of helpers that dispatch corresponding dom event.
|
|
176
|
-
*
|
|
177
|
-
* @see https://conform.guide/api/react#useinputevent
|
|
178
|
-
*/
|
|
179
|
-
export declare function useInputEvent(options: {
|
|
180
|
-
ref: RefObject<FieldElement> | (() => Element | RadioNodeList | FieldElement | null | undefined);
|
|
181
|
-
onInput?: (event: Event) => void;
|
|
182
|
-
onFocus?: (event: FocusEvent) => void;
|
|
183
|
-
onBlur?: (event: FocusEvent) => void;
|
|
184
|
-
onReset?: (event: Event) => void;
|
|
185
|
-
}): InputControl;
|
|
186
|
-
export declare const FORM_ERROR_ELEMENT_NAME = "__form__";
|
|
187
|
-
/**
|
|
188
|
-
* Validate the form with the Constraint Validation API
|
|
189
|
-
* @see https://conform.guide/api/react#validateconstraint
|
|
190
|
-
*/
|
|
191
|
-
export declare function validateConstraint(options: {
|
|
192
|
-
form: HTMLFormElement;
|
|
193
|
-
formData?: FormData;
|
|
194
|
-
constraint?: Record<Lowercase<string>, (value: string, context: {
|
|
195
|
-
formData: FormData;
|
|
196
|
-
attributeValue: string;
|
|
197
|
-
}) => boolean>;
|
|
198
|
-
formatMessages?: ({ name, validity, constraint, defaultErrors, }: {
|
|
199
|
-
name: string;
|
|
200
|
-
validity: ValidityState;
|
|
201
|
-
constraint: Record<string, boolean>;
|
|
202
|
-
defaultErrors: string[];
|
|
203
|
-
}) => string[];
|
|
204
|
-
}): Submission;
|
|
205
|
-
export declare function getUniqueKey(): string;
|
|
206
|
-
export declare function reportSubmission(form: HTMLFormElement, submission: SubmissionResult): void;
|
|
207
|
-
export declare function getScope(intent: ReturnType<typeof parseIntent>): string | null;
|
|
208
|
-
export {};
|