@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/module/base.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
-
import { forwardRef, createElement } from 'react';
|
|
3
|
-
|
|
4
|
-
var _excluded = ["hidden", "className", "style"];
|
|
5
|
-
/**
|
|
6
|
-
* Triggering react custom change event
|
|
7
|
-
* Solution based on dom-testing-library
|
|
8
|
-
* @see https://github.com/facebook/react/issues/10135#issuecomment-401496776
|
|
9
|
-
* @see https://github.com/testing-library/dom-testing-library/blob/main/src/events.js#L104-L123
|
|
10
|
-
*/
|
|
11
|
-
function setNativeValue(element, value) {
|
|
12
|
-
var {
|
|
13
|
-
set: valueSetter
|
|
14
|
-
} = Object.getOwnPropertyDescriptor(element, 'value') || {};
|
|
15
|
-
var prototype = Object.getPrototypeOf(element);
|
|
16
|
-
var {
|
|
17
|
-
set: prototypeValueSetter
|
|
18
|
-
} = Object.getOwnPropertyDescriptor(prototype, 'value') || {};
|
|
19
|
-
if (prototypeValueSetter && valueSetter !== prototypeValueSetter) {
|
|
20
|
-
prototypeValueSetter.call(element, value);
|
|
21
|
-
} else {
|
|
22
|
-
if (valueSetter) {
|
|
23
|
-
valueSetter.call(element, value);
|
|
24
|
-
} else {
|
|
25
|
-
throw new Error('The given element does not have a value setter');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function useInputControl(ref) {
|
|
30
|
-
function getInputElement() {
|
|
31
|
-
var $input = ref.current;
|
|
32
|
-
if (!$input) {
|
|
33
|
-
console.warn('input ref is not available; Maybe you forget to setup the ref?');
|
|
34
|
-
}
|
|
35
|
-
return $input;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
onChange(eventLikeOrString) {
|
|
39
|
-
var $input = getInputElement();
|
|
40
|
-
var value = typeof eventLikeOrString === 'string' ? eventLikeOrString : eventLikeOrString.target.value;
|
|
41
|
-
if ($input && $input.value !== value) {
|
|
42
|
-
$input.dispatchEvent(new InputEvent('beforeinput', {
|
|
43
|
-
bubbles: true,
|
|
44
|
-
cancelable: true
|
|
45
|
-
}));
|
|
46
|
-
setNativeValue($input, value);
|
|
47
|
-
$input.dispatchEvent(new InputEvent('input', {
|
|
48
|
-
bubbles: true,
|
|
49
|
-
cancelable: true
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
onInput(eventLikeOrString) {
|
|
54
|
-
this.onChange(eventLikeOrString);
|
|
55
|
-
},
|
|
56
|
-
onFocus() {
|
|
57
|
-
var $input = getInputElement();
|
|
58
|
-
if ($input) {
|
|
59
|
-
$input.dispatchEvent(new FocusEvent('focusin', {
|
|
60
|
-
bubbles: true,
|
|
61
|
-
cancelable: true
|
|
62
|
-
}));
|
|
63
|
-
$input.dispatchEvent(new FocusEvent('focus', {
|
|
64
|
-
cancelable: true
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
onBlur() {
|
|
69
|
-
var $input = getInputElement();
|
|
70
|
-
if ($input) {
|
|
71
|
-
$input.dispatchEvent(new FocusEvent('focusout', {
|
|
72
|
-
bubbles: true,
|
|
73
|
-
cancelable: true
|
|
74
|
-
}));
|
|
75
|
-
$input.dispatchEvent(new FocusEvent('blur', {
|
|
76
|
-
cancelable: true
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function BaseInputImpl(_ref, ref) {
|
|
83
|
-
var {
|
|
84
|
-
hidden = true,
|
|
85
|
-
className,
|
|
86
|
-
style
|
|
87
|
-
} = _ref,
|
|
88
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
89
|
-
return /*#__PURE__*/createElement('input', _objectSpread2({
|
|
90
|
-
ref,
|
|
91
|
-
className: hidden ? '' : className,
|
|
92
|
-
style: hidden ? {
|
|
93
|
-
position: 'absolute',
|
|
94
|
-
width: '1px',
|
|
95
|
-
height: '1px',
|
|
96
|
-
padding: 0,
|
|
97
|
-
margin: '-1px',
|
|
98
|
-
overflow: 'hidden',
|
|
99
|
-
clip: 'rect(0,0,0,0)',
|
|
100
|
-
whiteSpace: 'nowrap',
|
|
101
|
-
borderWidth: 0
|
|
102
|
-
} : style
|
|
103
|
-
}, props));
|
|
104
|
-
}
|
|
105
|
-
var BaseInput = /*#__PURE__*/forwardRef(BaseInputImpl);
|
|
106
|
-
|
|
107
|
-
export { BaseInput, useInputControl };
|