@conform-to/react 0.5.0 → 0.6.0-pre.0
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 +33 -58
- package/_virtual/_rollupPluginBabelHelpers.js +17 -0
- package/helpers.d.ts +17 -10
- package/helpers.js +47 -5
- package/hooks.d.ts +30 -32
- package/hooks.js +254 -169
- package/index.d.ts +1 -1
- package/index.js +7 -11
- package/module/_virtual/_rollupPluginBabelHelpers.js +16 -1
- package/module/helpers.js +39 -6
- package/module/hooks.js +256 -171
- package/module/index.js +2 -2
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -12,10 +12,6 @@ Object.defineProperty(exports, 'getFormElements', {
|
|
|
12
12
|
enumerable: true,
|
|
13
13
|
get: function () { return dom.getFormElements; }
|
|
14
14
|
});
|
|
15
|
-
Object.defineProperty(exports, 'hasError', {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return dom.hasError; }
|
|
18
|
-
});
|
|
19
15
|
Object.defineProperty(exports, 'list', {
|
|
20
16
|
enumerable: true,
|
|
21
17
|
get: function () { return dom.list; }
|
|
@@ -24,24 +20,24 @@ Object.defineProperty(exports, 'parse', {
|
|
|
24
20
|
enumerable: true,
|
|
25
21
|
get: function () { return dom.parse; }
|
|
26
22
|
});
|
|
27
|
-
Object.defineProperty(exports, '
|
|
23
|
+
Object.defineProperty(exports, 'requestIntent', {
|
|
28
24
|
enumerable: true,
|
|
29
|
-
get: function () { return dom.
|
|
25
|
+
get: function () { return dom.requestIntent; }
|
|
30
26
|
});
|
|
31
27
|
Object.defineProperty(exports, 'requestSubmit', {
|
|
32
28
|
enumerable: true,
|
|
33
29
|
get: function () { return dom.requestSubmit; }
|
|
34
30
|
});
|
|
35
|
-
Object.defineProperty(exports, 'shouldValidate', {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function () { return dom.shouldValidate; }
|
|
38
|
-
});
|
|
39
31
|
Object.defineProperty(exports, 'validate', {
|
|
40
32
|
enumerable: true,
|
|
41
33
|
get: function () { return dom.validate; }
|
|
42
34
|
});
|
|
43
|
-
exports
|
|
35
|
+
Object.defineProperty(exports, 'validateConstraint', {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return dom.validateConstraint; }
|
|
38
|
+
});
|
|
44
39
|
exports.useFieldList = hooks.useFieldList;
|
|
45
40
|
exports.useFieldset = hooks.useFieldset;
|
|
46
41
|
exports.useForm = hooks.useForm;
|
|
42
|
+
exports.useInputEvent = hooks.useInputEvent;
|
|
47
43
|
exports.conform = helpers;
|
|
@@ -20,6 +20,7 @@ function _objectSpread2(target) {
|
|
|
20
20
|
return target;
|
|
21
21
|
}
|
|
22
22
|
function _defineProperty(obj, key, value) {
|
|
23
|
+
key = _toPropertyKey(key);
|
|
23
24
|
if (key in obj) {
|
|
24
25
|
Object.defineProperty(obj, key, {
|
|
25
26
|
value: value,
|
|
@@ -32,5 +33,19 @@ function _defineProperty(obj, key, value) {
|
|
|
32
33
|
}
|
|
33
34
|
return obj;
|
|
34
35
|
}
|
|
36
|
+
function _toPrimitive(input, hint) {
|
|
37
|
+
if (typeof input !== "object" || input === null) return input;
|
|
38
|
+
var prim = input[Symbol.toPrimitive];
|
|
39
|
+
if (prim !== undefined) {
|
|
40
|
+
var res = prim.call(input, hint || "default");
|
|
41
|
+
if (typeof res !== "object") return res;
|
|
42
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
43
|
+
}
|
|
44
|
+
return (hint === "string" ? String : Number)(input);
|
|
45
|
+
}
|
|
46
|
+
function _toPropertyKey(arg) {
|
|
47
|
+
var key = _toPrimitive(arg, "string");
|
|
48
|
+
return typeof key === "symbol" ? key : String(key);
|
|
49
|
+
}
|
|
35
50
|
|
|
36
|
-
export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2 };
|
|
51
|
+
export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
|
package/module/helpers.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
export { VALIDATION_SKIPPED, VALIDATION_UNDEFINED } from '@conform-to/dom';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Style to make the input element visually hidden
|
|
5
|
+
* Based on the `sr-only` class from tailwindcss
|
|
6
|
+
*/
|
|
7
|
+
var hiddenStyle = {
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
width: '1px',
|
|
10
|
+
height: '1px',
|
|
11
|
+
padding: 0,
|
|
12
|
+
margin: '-1px',
|
|
13
|
+
overflow: 'hidden',
|
|
14
|
+
clip: 'rect(0,0,0,0)',
|
|
15
|
+
whiteSpace: 'nowrap',
|
|
16
|
+
border: 0
|
|
17
|
+
};
|
|
1
18
|
function input(config) {
|
|
2
19
|
var _config$initialError;
|
|
3
20
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -17,7 +34,12 @@ function input(config) {
|
|
|
17
34
|
'aria-invalid': Boolean((_config$initialError = config.initialError) === null || _config$initialError === void 0 ? void 0 : _config$initialError.length),
|
|
18
35
|
'aria-describedby': config.errorId
|
|
19
36
|
};
|
|
20
|
-
if (
|
|
37
|
+
if (options !== null && options !== void 0 && options.hidden) {
|
|
38
|
+
attributes.style = hiddenStyle;
|
|
39
|
+
attributes.tabIndex = -1;
|
|
40
|
+
attributes['aria-hidden'] = true;
|
|
41
|
+
}
|
|
42
|
+
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
21
43
|
attributes.autoFocus = true;
|
|
22
44
|
}
|
|
23
45
|
if (options.type === 'checkbox' || options.type === 'radio') {
|
|
@@ -29,7 +51,7 @@ function input(config) {
|
|
|
29
51
|
}
|
|
30
52
|
return attributes;
|
|
31
53
|
}
|
|
32
|
-
function select(config) {
|
|
54
|
+
function select(config, options) {
|
|
33
55
|
var _config$defaultValue, _config$initialError2;
|
|
34
56
|
var attributes = {
|
|
35
57
|
id: config.id,
|
|
@@ -41,12 +63,17 @@ function select(config) {
|
|
|
41
63
|
'aria-invalid': Boolean((_config$initialError2 = config.initialError) === null || _config$initialError2 === void 0 ? void 0 : _config$initialError2.length),
|
|
42
64
|
'aria-describedby': config.errorId
|
|
43
65
|
};
|
|
44
|
-
if (
|
|
66
|
+
if (options !== null && options !== void 0 && options.hidden) {
|
|
67
|
+
attributes.style = hiddenStyle;
|
|
68
|
+
attributes.tabIndex = -1;
|
|
69
|
+
attributes['aria-hidden'] = true;
|
|
70
|
+
}
|
|
71
|
+
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
45
72
|
attributes.autoFocus = true;
|
|
46
73
|
}
|
|
47
74
|
return attributes;
|
|
48
75
|
}
|
|
49
|
-
function textarea(config) {
|
|
76
|
+
function textarea(config, options) {
|
|
50
77
|
var _config$defaultValue2, _config$initialError3;
|
|
51
78
|
var attributes = {
|
|
52
79
|
id: config.id,
|
|
@@ -60,10 +87,16 @@ function textarea(config) {
|
|
|
60
87
|
'aria-invalid': Boolean((_config$initialError3 = config.initialError) === null || _config$initialError3 === void 0 ? void 0 : _config$initialError3.length),
|
|
61
88
|
'aria-describedby': config.errorId
|
|
62
89
|
};
|
|
63
|
-
if (
|
|
90
|
+
if (options !== null && options !== void 0 && options.hidden) {
|
|
91
|
+
attributes.style = hiddenStyle;
|
|
92
|
+
attributes.tabIndex = -1;
|
|
93
|
+
attributes['aria-hidden'] = true;
|
|
94
|
+
}
|
|
95
|
+
if (config.initialError && Object.entries(config.initialError).length > 0) {
|
|
64
96
|
attributes.autoFocus = true;
|
|
65
97
|
}
|
|
66
98
|
return attributes;
|
|
67
99
|
}
|
|
100
|
+
var intent = '__intent__';
|
|
68
101
|
|
|
69
|
-
export { input, select, textarea };
|
|
102
|
+
export { input, intent, select, textarea };
|