@conform-to/react 0.7.0 → 0.7.2
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/helpers.d.ts +1 -1
- package/helpers.js +14 -11
- package/helpers.mjs +14 -11
- package/hooks.d.ts +7 -2
- package/hooks.js +24 -20
- package/hooks.mjs +25 -21
- package/package.json +2 -2
package/helpers.d.ts
CHANGED
package/helpers.js
CHANGED
|
@@ -10,11 +10,9 @@ function getFormControlProps(config, options) {
|
|
|
10
10
|
id: config.id,
|
|
11
11
|
name: config.name,
|
|
12
12
|
form: config.form,
|
|
13
|
-
required: config.required
|
|
13
|
+
required: config.required,
|
|
14
|
+
autoFocus: config.initialError && Object.entries(config.initialError).length > 0 ? true : undefined
|
|
14
15
|
};
|
|
15
|
-
if (config.id) {
|
|
16
|
-
props.id = config.id;
|
|
17
|
-
}
|
|
18
16
|
if (options !== null && options !== void 0 && options.ariaAttributes) {
|
|
19
17
|
var _config$error;
|
|
20
18
|
if (config.descriptionId && options !== null && options !== void 0 && options.description) {
|
|
@@ -25,17 +23,22 @@ function getFormControlProps(config, options) {
|
|
|
25
23
|
props['aria-describedby'] = config.descriptionId && options !== null && options !== void 0 && options.description ? "".concat(config.errorId, " ").concat(config.descriptionId) : config.errorId;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, props), options !== null && options !== void 0 && options.hidden ? hiddenProps : {});
|
|
27
|
+
}
|
|
28
|
+
function cleanup(props) {
|
|
29
|
+
for (var key in props) {
|
|
30
|
+
if (props[key] === undefined) {
|
|
31
|
+
delete props[key];
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
|
-
return
|
|
34
|
+
return props;
|
|
32
35
|
}
|
|
33
36
|
var hiddenProps = {
|
|
34
37
|
/**
|
|
35
38
|
* Style to make the input element visually hidden
|
|
36
39
|
* Based on the `sr-only` class from tailwindcss
|
|
37
40
|
*/
|
|
38
|
-
|
|
41
|
+
style: {
|
|
39
42
|
position: 'absolute',
|
|
40
43
|
width: '1px',
|
|
41
44
|
height: '1px',
|
|
@@ -68,14 +71,14 @@ function input(config) {
|
|
|
68
71
|
} else if (options.type !== 'file') {
|
|
69
72
|
props.defaultValue = config.defaultValue;
|
|
70
73
|
}
|
|
71
|
-
return props;
|
|
74
|
+
return cleanup(props);
|
|
72
75
|
}
|
|
73
76
|
function select(config, options) {
|
|
74
77
|
var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
75
78
|
defaultValue: config.defaultValue,
|
|
76
79
|
multiple: config.multiple
|
|
77
80
|
});
|
|
78
|
-
return props;
|
|
81
|
+
return cleanup(props);
|
|
79
82
|
}
|
|
80
83
|
function textarea(config, options) {
|
|
81
84
|
var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
@@ -83,7 +86,7 @@ function textarea(config, options) {
|
|
|
83
86
|
minLength: config.minLength,
|
|
84
87
|
maxLength: config.maxLength
|
|
85
88
|
});
|
|
86
|
-
return props;
|
|
89
|
+
return cleanup(props);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
Object.defineProperty(exports, 'INTENT', {
|
package/helpers.mjs
CHANGED
|
@@ -6,11 +6,9 @@ function getFormControlProps(config, options) {
|
|
|
6
6
|
id: config.id,
|
|
7
7
|
name: config.name,
|
|
8
8
|
form: config.form,
|
|
9
|
-
required: config.required
|
|
9
|
+
required: config.required,
|
|
10
|
+
autoFocus: config.initialError && Object.entries(config.initialError).length > 0 ? true : undefined
|
|
10
11
|
};
|
|
11
|
-
if (config.id) {
|
|
12
|
-
props.id = config.id;
|
|
13
|
-
}
|
|
14
12
|
if (options !== null && options !== void 0 && options.ariaAttributes) {
|
|
15
13
|
var _config$error;
|
|
16
14
|
if (config.descriptionId && options !== null && options !== void 0 && options.description) {
|
|
@@ -21,17 +19,22 @@ function getFormControlProps(config, options) {
|
|
|
21
19
|
props['aria-describedby'] = config.descriptionId && options !== null && options !== void 0 && options.description ? "".concat(config.errorId, " ").concat(config.descriptionId) : config.errorId;
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
return _objectSpread2(_objectSpread2({}, props), options !== null && options !== void 0 && options.hidden ? hiddenProps : {});
|
|
23
|
+
}
|
|
24
|
+
function cleanup(props) {
|
|
25
|
+
for (var key in props) {
|
|
26
|
+
if (props[key] === undefined) {
|
|
27
|
+
delete props[key];
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
|
-
return
|
|
30
|
+
return props;
|
|
28
31
|
}
|
|
29
32
|
var hiddenProps = {
|
|
30
33
|
/**
|
|
31
34
|
* Style to make the input element visually hidden
|
|
32
35
|
* Based on the `sr-only` class from tailwindcss
|
|
33
36
|
*/
|
|
34
|
-
|
|
37
|
+
style: {
|
|
35
38
|
position: 'absolute',
|
|
36
39
|
width: '1px',
|
|
37
40
|
height: '1px',
|
|
@@ -64,14 +67,14 @@ function input(config) {
|
|
|
64
67
|
} else if (options.type !== 'file') {
|
|
65
68
|
props.defaultValue = config.defaultValue;
|
|
66
69
|
}
|
|
67
|
-
return props;
|
|
70
|
+
return cleanup(props);
|
|
68
71
|
}
|
|
69
72
|
function select(config, options) {
|
|
70
73
|
var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
71
74
|
defaultValue: config.defaultValue,
|
|
72
75
|
multiple: config.multiple
|
|
73
76
|
});
|
|
74
|
-
return props;
|
|
77
|
+
return cleanup(props);
|
|
75
78
|
}
|
|
76
79
|
function textarea(config, options) {
|
|
77
80
|
var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
@@ -79,7 +82,7 @@ function textarea(config, options) {
|
|
|
79
82
|
minLength: config.minLength,
|
|
80
83
|
maxLength: config.maxLength
|
|
81
84
|
});
|
|
82
|
-
return props;
|
|
85
|
+
return cleanup(props);
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
export { hiddenProps, input, select, textarea };
|
package/hooks.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export interface FieldConfig<Schema> extends FieldConstraint<Schema> {
|
|
|
21
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
22
|
[Key in KeysOf<Schema>]?: FieldValue<ResolveType<Schema, Key>>;
|
|
23
23
|
} : any;
|
|
24
|
+
type SubmissionResult = {
|
|
25
|
+
intent: Submission['intent'];
|
|
26
|
+
payload: Submission['payload'] | null;
|
|
27
|
+
error: Submission['error'];
|
|
28
|
+
};
|
|
24
29
|
export interface FormConfig<Output extends Record<string, any>, Input extends Record<string, any> = Output> {
|
|
25
30
|
/**
|
|
26
31
|
* If the form id is provided, Id for label,
|
|
@@ -52,7 +57,7 @@ export interface FormConfig<Output extends Record<string, any>, Input extends Re
|
|
|
52
57
|
/**
|
|
53
58
|
* An object describing the result of the last submission
|
|
54
59
|
*/
|
|
55
|
-
lastSubmission?:
|
|
60
|
+
lastSubmission?: SubmissionResult;
|
|
56
61
|
/**
|
|
57
62
|
* An object describing the constraint of each field
|
|
58
63
|
*/
|
|
@@ -203,6 +208,6 @@ export declare function validateConstraint(options: {
|
|
|
203
208
|
defaultErrors: string[];
|
|
204
209
|
}) => string[];
|
|
205
210
|
}): Submission;
|
|
206
|
-
export declare function reportSubmission(form: HTMLFormElement, submission:
|
|
211
|
+
export declare function reportSubmission(form: HTMLFormElement, submission: SubmissionResult): void;
|
|
207
212
|
export declare function getScope(intent: ReturnType<typeof parseIntent>): string | null;
|
|
208
213
|
export {};
|
package/hooks.js
CHANGED
|
@@ -48,6 +48,14 @@ function useFormReporter(ref, lastSubmission) {
|
|
|
48
48
|
if (!form || !lastSubmission) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
+
if (!lastSubmission.payload) {
|
|
52
|
+
// If the default value is empty, we can safely reset the form.
|
|
53
|
+
// This ensure the behavior is consistent with and without JS.
|
|
54
|
+
form.reset();
|
|
55
|
+
|
|
56
|
+
// There is no need to report the submission anymore.
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
51
59
|
report(form, lastSubmission);
|
|
52
60
|
}, [ref, lastSubmission, report]);
|
|
53
61
|
react.useEffect(() => {
|
|
@@ -129,7 +137,7 @@ function useFormError(ref, config) {
|
|
|
129
137
|
* @see https://conform.guide/api/react#useform
|
|
130
138
|
*/
|
|
131
139
|
function useForm() {
|
|
132
|
-
var _config$lastSubmissio2;
|
|
140
|
+
var _config$lastSubmissio2, _config$lastSubmissio3;
|
|
133
141
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
134
142
|
var configRef = useConfigRef(config);
|
|
135
143
|
var ref = useFormRef(config.ref);
|
|
@@ -152,21 +160,14 @@ function useForm() {
|
|
|
152
160
|
}, [config.lastSubmission]);
|
|
153
161
|
// This payload from lastSubmission is only useful before hydration
|
|
154
162
|
// After hydration, any new payload on lastSubmission will be ignored
|
|
155
|
-
var [
|
|
163
|
+
var [defaultValueFromLastSubmission, setDefaultValueFromLastSubmission] = react.useState( // @ts-expect-error defaultValue is not in Submission type
|
|
164
|
+
(_config$lastSubmissio2 = (_config$lastSubmissio3 = config.lastSubmission) === null || _config$lastSubmissio3 === void 0 ? void 0 : _config$lastSubmissio3.payload) !== null && _config$lastSubmissio2 !== void 0 ? _config$lastSubmissio2 : null);
|
|
156
165
|
var fieldset = useFieldset(ref, {
|
|
157
|
-
defaultValue:
|
|
166
|
+
defaultValue: defaultValueFromLastSubmission !== null && defaultValueFromLastSubmission !== void 0 ? defaultValueFromLastSubmission : config.defaultValue,
|
|
158
167
|
initialError,
|
|
159
168
|
constraint: config.constraint,
|
|
160
169
|
form: config.id
|
|
161
170
|
});
|
|
162
|
-
var lastSubmissionRef = react.useRef(config.lastSubmission);
|
|
163
|
-
useSafeLayoutEffect(() => {
|
|
164
|
-
if (lastSubmissionRef.current !== config.lastSubmission && config.lastSubmission === null) {
|
|
165
|
-
var _ref$current;
|
|
166
|
-
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.reset();
|
|
167
|
-
}
|
|
168
|
-
lastSubmissionRef.current = config.lastSubmission;
|
|
169
|
-
}, [ref, config.lastSubmission]);
|
|
170
171
|
react.useEffect(() => {
|
|
171
172
|
// custom validate handler
|
|
172
173
|
var createValidateHandler = type => event => {
|
|
@@ -206,7 +207,7 @@ function useForm() {
|
|
|
206
207
|
_element.setCustomValidity('');
|
|
207
208
|
}
|
|
208
209
|
setErrors([]);
|
|
209
|
-
|
|
210
|
+
setDefaultValueFromLastSubmission(null);
|
|
210
211
|
};
|
|
211
212
|
var handleInput = createValidateHandler('onInput');
|
|
212
213
|
var handleBlur = createValidateHandler('onBlur');
|
|
@@ -278,8 +279,9 @@ function useForm() {
|
|
|
278
279
|
method: dom.getFormMethod(nativeEvent)
|
|
279
280
|
});
|
|
280
281
|
}
|
|
281
|
-
} catch (
|
|
282
|
-
console
|
|
282
|
+
} catch (error) {
|
|
283
|
+
// eslint-disable-next-line no-console
|
|
284
|
+
console.warn('Client validation failed', error);
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
}
|
|
@@ -477,24 +479,23 @@ function useInputEvent(options) {
|
|
|
477
479
|
onBlur: false
|
|
478
480
|
});
|
|
479
481
|
useSafeLayoutEffect(() => {
|
|
480
|
-
var
|
|
482
|
+
var createEventListener = listener => {
|
|
481
483
|
return event => {
|
|
482
484
|
var _optionsRef$current, _optionsRef$current2, _optionsRef$current3;
|
|
483
485
|
var element = typeof ((_optionsRef$current = optionsRef.current) === null || _optionsRef$current === void 0 ? void 0 : _optionsRef$current.ref) === 'function' ? (_optionsRef$current2 = optionsRef.current) === null || _optionsRef$current2 === void 0 ? void 0 : _optionsRef$current2.ref() : (_optionsRef$current3 = optionsRef.current) === null || _optionsRef$current3 === void 0 ? void 0 : _optionsRef$current3.ref.current;
|
|
484
486
|
if (dom.isFieldElement(element) && (listener === 'onReset' ? event.target === element.form : event.target === element)) {
|
|
485
487
|
var _optionsRef$current4, _optionsRef$current4$;
|
|
486
488
|
if (listener !== 'onReset') {
|
|
487
|
-
console.log(listener, 'dispatched');
|
|
488
489
|
eventDispatched.current[listener] = true;
|
|
489
490
|
}
|
|
490
491
|
(_optionsRef$current4 = optionsRef.current) === null || _optionsRef$current4 === void 0 ? void 0 : (_optionsRef$current4$ = _optionsRef$current4[listener]) === null || _optionsRef$current4$ === void 0 ? void 0 : _optionsRef$current4$.call(_optionsRef$current4, event);
|
|
491
492
|
}
|
|
492
493
|
};
|
|
493
494
|
};
|
|
494
|
-
var inputHandler =
|
|
495
|
-
var focusHandler =
|
|
496
|
-
var blurHandler =
|
|
497
|
-
var resetHandler =
|
|
495
|
+
var inputHandler = createEventListener('onInput');
|
|
496
|
+
var focusHandler = createEventListener('onFocus');
|
|
497
|
+
var blurHandler = createEventListener('onBlur');
|
|
498
|
+
var resetHandler = createEventListener('onReset');
|
|
498
499
|
|
|
499
500
|
// focus/blur event does not bubble
|
|
500
501
|
document.addEventListener('input', inputHandler, true);
|
|
@@ -514,6 +515,7 @@ function useInputEvent(options) {
|
|
|
514
515
|
var _optionsRef$current5, _optionsRef$current6, _optionsRef$current7;
|
|
515
516
|
var _element2 = typeof ((_optionsRef$current5 = optionsRef.current) === null || _optionsRef$current5 === void 0 ? void 0 : _optionsRef$current5.ref) === 'function' ? (_optionsRef$current6 = optionsRef.current) === null || _optionsRef$current6 === void 0 ? void 0 : _optionsRef$current6.ref() : (_optionsRef$current7 = optionsRef.current) === null || _optionsRef$current7 === void 0 ? void 0 : _optionsRef$current7.ref.current;
|
|
516
517
|
if (!dom.isFieldElement(_element2)) {
|
|
518
|
+
// eslint-disable-next-line no-console
|
|
517
519
|
console.warn('Failed to dispatch event; is the input mounted?');
|
|
518
520
|
return;
|
|
519
521
|
}
|
|
@@ -648,6 +650,7 @@ function validateConstraint(options) {
|
|
|
648
650
|
attributeValue
|
|
649
651
|
});
|
|
650
652
|
} else {
|
|
653
|
+
// eslint-disable-next-line no-console
|
|
651
654
|
console.warn("Found an \"".concat(constraintName, "\" constraint with undefined definition; Please specify it on the validateConstraint API."));
|
|
652
655
|
}
|
|
653
656
|
}
|
|
@@ -692,6 +695,7 @@ function reportSubmission(form, submission) {
|
|
|
692
695
|
if (item instanceof RadioNodeList) {
|
|
693
696
|
for (var field of item) {
|
|
694
697
|
if (field.type !== 'radio') {
|
|
698
|
+
// eslint-disable-next-line no-console
|
|
695
699
|
console.warn('Repeated field name is not supported.');
|
|
696
700
|
continue;
|
|
697
701
|
}
|
package/hooks.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { parseIntent, getFormData, parse, VALIDATION_UNDEFINED, VALIDATION_SKIPPED, getFormAction, getFormEncType, getFormMethod, getPaths, getName, isFieldElement, getErrors, getFormControls, getFormElement, updateList, getValidationMessage, focusFirstInvalidControl, isFocusableFormControl, requestIntent, validate } from '@conform-to/dom';
|
|
3
|
-
import { useState, useMemo, useRef,
|
|
3
|
+
import { useState, useMemo, useEffect, useRef, useCallback, useLayoutEffect } from 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Normalize error to an array of string.
|
|
@@ -44,6 +44,14 @@ function useFormReporter(ref, lastSubmission) {
|
|
|
44
44
|
if (!form || !lastSubmission) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
+
if (!lastSubmission.payload) {
|
|
48
|
+
// If the default value is empty, we can safely reset the form.
|
|
49
|
+
// This ensure the behavior is consistent with and without JS.
|
|
50
|
+
form.reset();
|
|
51
|
+
|
|
52
|
+
// There is no need to report the submission anymore.
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
47
55
|
report(form, lastSubmission);
|
|
48
56
|
}, [ref, lastSubmission, report]);
|
|
49
57
|
useEffect(() => {
|
|
@@ -125,7 +133,7 @@ function useFormError(ref, config) {
|
|
|
125
133
|
* @see https://conform.guide/api/react#useform
|
|
126
134
|
*/
|
|
127
135
|
function useForm() {
|
|
128
|
-
var _config$lastSubmissio2;
|
|
136
|
+
var _config$lastSubmissio2, _config$lastSubmissio3;
|
|
129
137
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
130
138
|
var configRef = useConfigRef(config);
|
|
131
139
|
var ref = useFormRef(config.ref);
|
|
@@ -148,21 +156,14 @@ function useForm() {
|
|
|
148
156
|
}, [config.lastSubmission]);
|
|
149
157
|
// This payload from lastSubmission is only useful before hydration
|
|
150
158
|
// After hydration, any new payload on lastSubmission will be ignored
|
|
151
|
-
var [
|
|
159
|
+
var [defaultValueFromLastSubmission, setDefaultValueFromLastSubmission] = useState( // @ts-expect-error defaultValue is not in Submission type
|
|
160
|
+
(_config$lastSubmissio2 = (_config$lastSubmissio3 = config.lastSubmission) === null || _config$lastSubmissio3 === void 0 ? void 0 : _config$lastSubmissio3.payload) !== null && _config$lastSubmissio2 !== void 0 ? _config$lastSubmissio2 : null);
|
|
152
161
|
var fieldset = useFieldset(ref, {
|
|
153
|
-
defaultValue:
|
|
162
|
+
defaultValue: defaultValueFromLastSubmission !== null && defaultValueFromLastSubmission !== void 0 ? defaultValueFromLastSubmission : config.defaultValue,
|
|
154
163
|
initialError,
|
|
155
164
|
constraint: config.constraint,
|
|
156
165
|
form: config.id
|
|
157
166
|
});
|
|
158
|
-
var lastSubmissionRef = useRef(config.lastSubmission);
|
|
159
|
-
useSafeLayoutEffect(() => {
|
|
160
|
-
if (lastSubmissionRef.current !== config.lastSubmission && config.lastSubmission === null) {
|
|
161
|
-
var _ref$current;
|
|
162
|
-
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.reset();
|
|
163
|
-
}
|
|
164
|
-
lastSubmissionRef.current = config.lastSubmission;
|
|
165
|
-
}, [ref, config.lastSubmission]);
|
|
166
167
|
useEffect(() => {
|
|
167
168
|
// custom validate handler
|
|
168
169
|
var createValidateHandler = type => event => {
|
|
@@ -202,7 +203,7 @@ function useForm() {
|
|
|
202
203
|
_element.setCustomValidity('');
|
|
203
204
|
}
|
|
204
205
|
setErrors([]);
|
|
205
|
-
|
|
206
|
+
setDefaultValueFromLastSubmission(null);
|
|
206
207
|
};
|
|
207
208
|
var handleInput = createValidateHandler('onInput');
|
|
208
209
|
var handleBlur = createValidateHandler('onBlur');
|
|
@@ -274,8 +275,9 @@ function useForm() {
|
|
|
274
275
|
method: getFormMethod(nativeEvent)
|
|
275
276
|
});
|
|
276
277
|
}
|
|
277
|
-
} catch (
|
|
278
|
-
console
|
|
278
|
+
} catch (error) {
|
|
279
|
+
// eslint-disable-next-line no-console
|
|
280
|
+
console.warn('Client validation failed', error);
|
|
279
281
|
}
|
|
280
282
|
}
|
|
281
283
|
}
|
|
@@ -473,24 +475,23 @@ function useInputEvent(options) {
|
|
|
473
475
|
onBlur: false
|
|
474
476
|
});
|
|
475
477
|
useSafeLayoutEffect(() => {
|
|
476
|
-
var
|
|
478
|
+
var createEventListener = listener => {
|
|
477
479
|
return event => {
|
|
478
480
|
var _optionsRef$current, _optionsRef$current2, _optionsRef$current3;
|
|
479
481
|
var element = typeof ((_optionsRef$current = optionsRef.current) === null || _optionsRef$current === void 0 ? void 0 : _optionsRef$current.ref) === 'function' ? (_optionsRef$current2 = optionsRef.current) === null || _optionsRef$current2 === void 0 ? void 0 : _optionsRef$current2.ref() : (_optionsRef$current3 = optionsRef.current) === null || _optionsRef$current3 === void 0 ? void 0 : _optionsRef$current3.ref.current;
|
|
480
482
|
if (isFieldElement(element) && (listener === 'onReset' ? event.target === element.form : event.target === element)) {
|
|
481
483
|
var _optionsRef$current4, _optionsRef$current4$;
|
|
482
484
|
if (listener !== 'onReset') {
|
|
483
|
-
console.log(listener, 'dispatched');
|
|
484
485
|
eventDispatched.current[listener] = true;
|
|
485
486
|
}
|
|
486
487
|
(_optionsRef$current4 = optionsRef.current) === null || _optionsRef$current4 === void 0 ? void 0 : (_optionsRef$current4$ = _optionsRef$current4[listener]) === null || _optionsRef$current4$ === void 0 ? void 0 : _optionsRef$current4$.call(_optionsRef$current4, event);
|
|
487
488
|
}
|
|
488
489
|
};
|
|
489
490
|
};
|
|
490
|
-
var inputHandler =
|
|
491
|
-
var focusHandler =
|
|
492
|
-
var blurHandler =
|
|
493
|
-
var resetHandler =
|
|
491
|
+
var inputHandler = createEventListener('onInput');
|
|
492
|
+
var focusHandler = createEventListener('onFocus');
|
|
493
|
+
var blurHandler = createEventListener('onBlur');
|
|
494
|
+
var resetHandler = createEventListener('onReset');
|
|
494
495
|
|
|
495
496
|
// focus/blur event does not bubble
|
|
496
497
|
document.addEventListener('input', inputHandler, true);
|
|
@@ -510,6 +511,7 @@ function useInputEvent(options) {
|
|
|
510
511
|
var _optionsRef$current5, _optionsRef$current6, _optionsRef$current7;
|
|
511
512
|
var _element2 = typeof ((_optionsRef$current5 = optionsRef.current) === null || _optionsRef$current5 === void 0 ? void 0 : _optionsRef$current5.ref) === 'function' ? (_optionsRef$current6 = optionsRef.current) === null || _optionsRef$current6 === void 0 ? void 0 : _optionsRef$current6.ref() : (_optionsRef$current7 = optionsRef.current) === null || _optionsRef$current7 === void 0 ? void 0 : _optionsRef$current7.ref.current;
|
|
512
513
|
if (!isFieldElement(_element2)) {
|
|
514
|
+
// eslint-disable-next-line no-console
|
|
513
515
|
console.warn('Failed to dispatch event; is the input mounted?');
|
|
514
516
|
return;
|
|
515
517
|
}
|
|
@@ -644,6 +646,7 @@ function validateConstraint(options) {
|
|
|
644
646
|
attributeValue
|
|
645
647
|
});
|
|
646
648
|
} else {
|
|
649
|
+
// eslint-disable-next-line no-console
|
|
647
650
|
console.warn("Found an \"".concat(constraintName, "\" constraint with undefined definition; Please specify it on the validateConstraint API."));
|
|
648
651
|
}
|
|
649
652
|
}
|
|
@@ -688,6 +691,7 @@ function reportSubmission(form, submission) {
|
|
|
688
691
|
if (item instanceof RadioNodeList) {
|
|
689
692
|
for (var field of item) {
|
|
690
693
|
if (field.type !== 'radio') {
|
|
694
|
+
// eslint-disable-next-line no-console
|
|
691
695
|
console.warn('Repeated field name is not supported.');
|
|
692
696
|
continue;
|
|
693
697
|
}
|
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": "0.7.
|
|
6
|
+
"version": "0.7.2",
|
|
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": "0.7.
|
|
33
|
+
"@conform-to/dom": "0.7.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=16.8"
|