@public-ui/react-hook-form-adapter 4.0.0-alpha.1 → 4.0.0-alpha.3
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/dist/index.cjs +29 -36
- package/dist/index.d.cts +411 -8468
- package/dist/index.d.mts +411 -8468
- package/dist/index.d.ts +411 -8468
- package/dist/index.mjs +29 -36
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const reactV19 = require('@public-ui/react-v19');
|
|
3
4
|
const React = require('react');
|
|
4
5
|
const reactHookForm = require('react-hook-form');
|
|
5
|
-
const reactV19 = require('@public-ui/react-v19');
|
|
6
6
|
|
|
7
7
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
8
8
|
|
|
9
9
|
const React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
10
10
|
|
|
11
11
|
function withController(Component, valueProp) {
|
|
12
|
-
|
|
13
|
-
const { name, control, rules, defaultValue, ...
|
|
14
|
-
const userEventHandlers = props._on || {};
|
|
12
|
+
const ControllerWrapper = React__default.forwardRef((props, ref) => {
|
|
13
|
+
const { name, control, rules, defaultValue, shouldUnregister, disabled, ...componentProps } = props;
|
|
15
14
|
return /* @__PURE__ */ React__default.createElement(
|
|
16
15
|
reactHookForm.Controller,
|
|
17
16
|
{
|
|
@@ -19,58 +18,52 @@ function withController(Component, valueProp) {
|
|
|
19
18
|
control,
|
|
20
19
|
rules,
|
|
21
20
|
defaultValue,
|
|
21
|
+
shouldUnregister,
|
|
22
|
+
disabled,
|
|
22
23
|
render: ({ field, fieldState }) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
24
|
+
const userHandlers = componentProps._on;
|
|
25
|
+
const mergedProps = {
|
|
26
|
+
...componentProps,
|
|
27
|
+
ref: (element) => {
|
|
28
|
+
if (ref) {
|
|
29
|
+
if (typeof ref === "function") ref(element);
|
|
30
|
+
else ref.current = element;
|
|
31
|
+
}
|
|
32
|
+
if (element) field.ref(element);
|
|
33
|
+
},
|
|
25
34
|
_name: name,
|
|
26
35
|
_touched: fieldState.isTouched,
|
|
27
|
-
_disabled:
|
|
36
|
+
_disabled: componentProps._disabled || disabled || field.disabled,
|
|
28
37
|
_msg: fieldState.error ? {
|
|
29
38
|
_type: "error",
|
|
30
|
-
_description:
|
|
39
|
+
_description: fieldState.error.message || String(fieldState.error)
|
|
31
40
|
} : void 0,
|
|
32
41
|
_on: {
|
|
33
|
-
...
|
|
34
|
-
onInput: (
|
|
42
|
+
...userHandlers || {},
|
|
43
|
+
onInput: (event, value) => {
|
|
35
44
|
field.onChange(value);
|
|
36
|
-
|
|
37
|
-
userEventHandlers.onInput(e, value);
|
|
38
|
-
}
|
|
45
|
+
userHandlers?.onInput?.(event, value);
|
|
39
46
|
},
|
|
40
|
-
onChange: (
|
|
47
|
+
onChange: (event, value) => {
|
|
41
48
|
field.onChange(value);
|
|
42
|
-
|
|
43
|
-
userEventHandlers.onChange(e, value);
|
|
44
|
-
}
|
|
49
|
+
userHandlers?.onChange?.(event, value);
|
|
45
50
|
},
|
|
46
|
-
onBlur: (
|
|
51
|
+
onBlur: (event) => {
|
|
47
52
|
field.onBlur();
|
|
48
|
-
|
|
49
|
-
userEventHandlers.onBlur(e);
|
|
50
|
-
}
|
|
53
|
+
userHandlers?.onBlur?.(event);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
};
|
|
54
57
|
if (valueProp) {
|
|
55
|
-
|
|
58
|
+
mergedProps[valueProp] = field.value;
|
|
56
59
|
}
|
|
57
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
58
|
-
Component,
|
|
59
|
-
{
|
|
60
|
-
ref: (e) => {
|
|
61
|
-
if (ref) {
|
|
62
|
-
if (typeof ref === "function") ref(e);
|
|
63
|
-
else ref.current = e;
|
|
64
|
-
}
|
|
65
|
-
if (e && field.ref) field.ref(e);
|
|
66
|
-
},
|
|
67
|
-
...componentProps
|
|
68
|
-
}
|
|
69
|
-
);
|
|
60
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...mergedProps });
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
);
|
|
73
64
|
});
|
|
65
|
+
ControllerWrapper.displayName = `withController(${Component.displayName || Component.name || "Component"})`;
|
|
66
|
+
return ControllerWrapper;
|
|
74
67
|
}
|
|
75
68
|
const KolInputTextController = withController(reactV19.KolInputText, "_value");
|
|
76
69
|
const KolInputPasswordController = withController(reactV19.KolInputPassword, "_value");
|
|
@@ -79,7 +72,7 @@ const KolInputNumberController = withController(reactV19.KolInputNumber, "_value
|
|
|
79
72
|
const KolInputRangeController = withController(reactV19.KolInputRange, "_value");
|
|
80
73
|
const KolInputDateController = withController(reactV19.KolInputDate, "_value");
|
|
81
74
|
const KolInputColorController = withController(reactV19.KolInputColor, "_value");
|
|
82
|
-
const KolInputFileController = withController(reactV19.KolInputFile
|
|
75
|
+
const KolInputFileController = withController(reactV19.KolInputFile);
|
|
83
76
|
const KolTextareaController = withController(reactV19.KolTextarea, "_value");
|
|
84
77
|
const KolComboboxController = withController(reactV19.KolCombobox, "_value");
|
|
85
78
|
const KolSelectController = withController(reactV19.KolSelect, "_value");
|