@conform-to/react 0.6.0-pre.0 → 0.6.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/README.md +187 -133
- package/helpers.d.ts +17 -20
- package/helpers.js +50 -65
- package/hooks.d.ts +31 -24
- package/hooks.js +121 -140
- package/index.d.ts +2 -2
- package/index.js +2 -6
- package/module/helpers.js +48 -66
- package/module/hooks.js +123 -142
- package/module/index.js +1 -1
- package/package.json +7 -3
- package/base.d.ts +0 -17
- package/base.js +0 -112
- package/module/base.js +0 -107
package/helpers.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
5
6
|
var dom = require('@conform-to/dom');
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -19,90 +20,75 @@ var hiddenStyle = {
|
|
|
19
20
|
whiteSpace: 'nowrap',
|
|
20
21
|
border: 0
|
|
21
22
|
};
|
|
22
|
-
function
|
|
23
|
-
var _config$
|
|
24
|
-
var
|
|
25
|
-
var attributes = {
|
|
23
|
+
function getFormControlProps(config, options) {
|
|
24
|
+
var _config$error;
|
|
25
|
+
var props = {
|
|
26
26
|
id: config.id,
|
|
27
|
-
type: options.type,
|
|
28
27
|
name: config.name,
|
|
29
28
|
form: config.form,
|
|
30
|
-
required: config.required
|
|
29
|
+
required: config.required
|
|
30
|
+
};
|
|
31
|
+
if (config.id) {
|
|
32
|
+
props.id = config.id;
|
|
33
|
+
}
|
|
34
|
+
if (config.descriptionId && options !== null && options !== void 0 && options.description) {
|
|
35
|
+
props['aria-describedby'] = config.descriptionId;
|
|
36
|
+
}
|
|
37
|
+
if (config.errorId && (_config$error = config.error) !== null && _config$error !== void 0 && _config$error.length) {
|
|
38
|
+
props['aria-invalid'] = true;
|
|
39
|
+
props['aria-describedby'] = config.descriptionId && options !== null && options !== void 0 && options.description ? "".concat(config.errorId, " ").concat(config.descriptionId) : config.errorId;
|
|
40
|
+
}
|
|
41
|
+
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
42
|
+
props.autoFocus = true;
|
|
43
|
+
}
|
|
44
|
+
if (options !== null && options !== void 0 && options.hidden) {
|
|
45
|
+
props.style = hiddenStyle;
|
|
46
|
+
props.tabIndex = -1;
|
|
47
|
+
props['aria-hidden'] = true;
|
|
48
|
+
}
|
|
49
|
+
return props;
|
|
50
|
+
}
|
|
51
|
+
function input(config) {
|
|
52
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
53
|
+
var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
54
|
+
type: options.type,
|
|
31
55
|
minLength: config.minLength,
|
|
32
56
|
maxLength: config.maxLength,
|
|
33
57
|
min: config.min,
|
|
34
58
|
max: config.max,
|
|
35
59
|
step: config.step,
|
|
36
60
|
pattern: config.pattern,
|
|
37
|
-
multiple: config.multiple
|
|
38
|
-
|
|
39
|
-
'aria-describedby': config.errorId
|
|
40
|
-
};
|
|
41
|
-
if (options !== null && options !== void 0 && options.hidden) {
|
|
42
|
-
attributes.style = hiddenStyle;
|
|
43
|
-
attributes.tabIndex = -1;
|
|
44
|
-
attributes['aria-hidden'] = true;
|
|
45
|
-
}
|
|
46
|
-
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
47
|
-
attributes.autoFocus = true;
|
|
48
|
-
}
|
|
61
|
+
multiple: config.multiple
|
|
62
|
+
});
|
|
49
63
|
if (options.type === 'checkbox' || options.type === 'radio') {
|
|
50
64
|
var _options$value;
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
props.value = (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : 'on';
|
|
66
|
+
props.defaultChecked = config.defaultValue === props.value;
|
|
53
67
|
} else if (options.type !== 'file') {
|
|
54
|
-
|
|
68
|
+
props.defaultValue = config.defaultValue;
|
|
55
69
|
}
|
|
56
|
-
return
|
|
70
|
+
return props;
|
|
57
71
|
}
|
|
58
72
|
function select(config, options) {
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
defaultValue: config.multiple ? Array.isArray(config.defaultValue) ? config.defaultValue : [] : "".concat((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : ''),
|
|
65
|
-
required: config.required,
|
|
66
|
-
multiple: config.multiple,
|
|
67
|
-
'aria-invalid': Boolean((_config$initialError2 = config.initialError) === null || _config$initialError2 === void 0 ? void 0 : _config$initialError2.length),
|
|
68
|
-
'aria-describedby': config.errorId
|
|
69
|
-
};
|
|
70
|
-
if (options !== null && options !== void 0 && options.hidden) {
|
|
71
|
-
attributes.style = hiddenStyle;
|
|
72
|
-
attributes.tabIndex = -1;
|
|
73
|
-
attributes['aria-hidden'] = true;
|
|
74
|
-
}
|
|
75
|
-
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
76
|
-
attributes.autoFocus = true;
|
|
77
|
-
}
|
|
78
|
-
return attributes;
|
|
73
|
+
var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
74
|
+
defaultValue: config.defaultValue,
|
|
75
|
+
multiple: config.multiple
|
|
76
|
+
});
|
|
77
|
+
return props;
|
|
79
78
|
}
|
|
80
79
|
function textarea(config, options) {
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
id: config.id,
|
|
84
|
-
name: config.name,
|
|
85
|
-
form: config.form,
|
|
86
|
-
defaultValue: "".concat((_config$defaultValue2 = config.defaultValue) !== null && _config$defaultValue2 !== void 0 ? _config$defaultValue2 : ''),
|
|
87
|
-
required: config.required,
|
|
80
|
+
var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
81
|
+
defaultValue: config.defaultValue,
|
|
88
82
|
minLength: config.minLength,
|
|
89
|
-
maxLength: config.maxLength
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
'aria-describedby': config.errorId
|
|
93
|
-
};
|
|
94
|
-
if (options !== null && options !== void 0 && options.hidden) {
|
|
95
|
-
attributes.style = hiddenStyle;
|
|
96
|
-
attributes.tabIndex = -1;
|
|
97
|
-
attributes['aria-hidden'] = true;
|
|
98
|
-
}
|
|
99
|
-
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
100
|
-
attributes.autoFocus = true;
|
|
101
|
-
}
|
|
102
|
-
return attributes;
|
|
83
|
+
maxLength: config.maxLength
|
|
84
|
+
});
|
|
85
|
+
return props;
|
|
103
86
|
}
|
|
104
|
-
var intent = '__intent__';
|
|
105
87
|
|
|
88
|
+
Object.defineProperty(exports, 'INTENT', {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return dom.INTENT; }
|
|
91
|
+
});
|
|
106
92
|
Object.defineProperty(exports, 'VALIDATION_SKIPPED', {
|
|
107
93
|
enumerable: true,
|
|
108
94
|
get: function () { return dom.VALIDATION_SKIPPED; }
|
|
@@ -112,6 +98,5 @@ Object.defineProperty(exports, 'VALIDATION_UNDEFINED', {
|
|
|
112
98
|
get: function () { return dom.VALIDATION_UNDEFINED; }
|
|
113
99
|
});
|
|
114
100
|
exports.input = input;
|
|
115
|
-
exports.intent = intent;
|
|
116
101
|
exports.select = select;
|
|
117
102
|
exports.textarea = textarea;
|
package/hooks.d.ts
CHANGED
|
@@ -7,20 +7,35 @@ export interface FormConfig<Schema extends Record<string, any>, ClientSubmission
|
|
|
7
7
|
*/
|
|
8
8
|
id?: string;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* A form ref object. Conform will fallback to its own ref object if it is not provided.
|
|
11
|
+
*/
|
|
12
|
+
ref?: RefObject<HTMLFormElement>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `shouldValidate` and `shouldRevalidate` instead.
|
|
15
|
+
*/
|
|
16
|
+
initialReport?: 'onSubmit' | 'onChange' | 'onBlur';
|
|
17
|
+
/**
|
|
18
|
+
* Define when conform should start validation.
|
|
11
19
|
* Support "onSubmit", "onChange", "onBlur".
|
|
12
20
|
*
|
|
13
21
|
* Default to `onSubmit`.
|
|
14
22
|
*/
|
|
15
|
-
|
|
23
|
+
shouldValidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
24
|
+
/**
|
|
25
|
+
* Define when conform should revalidate again.
|
|
26
|
+
* Support "onSubmit", "onChange", "onBlur".
|
|
27
|
+
*
|
|
28
|
+
* Default to `onInput`.
|
|
29
|
+
*/
|
|
30
|
+
shouldRevalidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
16
31
|
/**
|
|
17
32
|
* An object representing the initial value of the form.
|
|
18
33
|
*/
|
|
19
34
|
defaultValue?: FieldValue<Schema>;
|
|
20
35
|
/**
|
|
21
|
-
* An object describing the
|
|
36
|
+
* An object describing the result of the last submission
|
|
22
37
|
*/
|
|
23
|
-
|
|
38
|
+
lastSubmission?: Submission;
|
|
24
39
|
/**
|
|
25
40
|
* An object describing the constraint of each field
|
|
26
41
|
*/
|
|
@@ -60,17 +75,20 @@ export interface FormConfig<Schema extends Record<string, any>, ClientSubmission
|
|
|
60
75
|
* Properties to be applied to the form element
|
|
61
76
|
*/
|
|
62
77
|
interface FormProps {
|
|
63
|
-
ref: RefObject<HTMLFormElement>;
|
|
64
78
|
id?: string;
|
|
79
|
+
ref: RefObject<HTMLFormElement>;
|
|
65
80
|
onSubmit: (event: FormEvent<HTMLFormElement>) => void;
|
|
66
81
|
noValidate: boolean;
|
|
82
|
+
'aria-invalid'?: 'true';
|
|
83
|
+
'aria-describedby'?: string;
|
|
67
84
|
}
|
|
68
|
-
interface Form
|
|
85
|
+
interface Form {
|
|
69
86
|
id?: string;
|
|
70
|
-
|
|
87
|
+
errorId?: string;
|
|
71
88
|
error: string;
|
|
89
|
+
errors: string[];
|
|
90
|
+
ref: RefObject<HTMLFormElement>;
|
|
72
91
|
props: FormProps;
|
|
73
|
-
config: FieldsetConfig<Schema>;
|
|
74
92
|
}
|
|
75
93
|
/**
|
|
76
94
|
* Returns properties required to hook into form events.
|
|
@@ -78,20 +96,12 @@ interface Form<Schema extends Record<string, any>> {
|
|
|
78
96
|
*
|
|
79
97
|
* @see https://conform.guide/api/react#useform
|
|
80
98
|
*/
|
|
81
|
-
export declare function useForm<Schema extends Record<string, any>, ClientSubmission extends Submission | Submission<Schema> = Submission>(config?: FormConfig<Schema, ClientSubmission>): [Form
|
|
82
|
-
/**
|
|
83
|
-
* All the information of the field, including state and config.
|
|
84
|
-
*/
|
|
85
|
-
export type Field<Schema> = {
|
|
86
|
-
config: FieldConfig<Schema>;
|
|
87
|
-
error?: string;
|
|
88
|
-
errors?: string[];
|
|
89
|
-
};
|
|
99
|
+
export declare function useForm<Schema extends Record<string, any>, ClientSubmission extends Submission | Submission<Schema> = Submission>(config?: FormConfig<Schema, ClientSubmission>): [Form, Fieldset<Schema>];
|
|
90
100
|
/**
|
|
91
|
-
* A set of field
|
|
101
|
+
* A set of field configuration
|
|
92
102
|
*/
|
|
93
103
|
export type Fieldset<Schema extends Record<string, any>> = {
|
|
94
|
-
[Key in keyof Schema]-?:
|
|
104
|
+
[Key in keyof Schema]-?: FieldConfig<Schema[Key]>;
|
|
95
105
|
};
|
|
96
106
|
export interface FieldsetConfig<Schema extends Record<string, any>> {
|
|
97
107
|
/**
|
|
@@ -111,7 +121,7 @@ export interface FieldsetConfig<Schema extends Record<string, any>> {
|
|
|
111
121
|
*/
|
|
112
122
|
constraint?: FieldsetConstraint<Schema>;
|
|
113
123
|
/**
|
|
114
|
-
* The id of the form, connecting each field to a form remotely
|
|
124
|
+
* The id of the form, connecting each field to a form remotely
|
|
115
125
|
*/
|
|
116
126
|
form?: string;
|
|
117
127
|
}
|
|
@@ -130,10 +140,7 @@ export declare function useFieldset<Schema extends Record<string, any>>(ref: Ref
|
|
|
130
140
|
*/
|
|
131
141
|
export declare function useFieldList<Payload = any>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Array<Payload>>): Array<{
|
|
132
142
|
key: string;
|
|
133
|
-
|
|
134
|
-
errors: string[] | undefined;
|
|
135
|
-
config: FieldConfig<Payload>;
|
|
136
|
-
}>;
|
|
143
|
+
} & FieldConfig<Payload>>;
|
|
137
144
|
interface InputControl {
|
|
138
145
|
change: (eventOrValue: {
|
|
139
146
|
target: {
|