@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.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { KolInputText, KolInputPassword, KolInputEmail, KolInputNumber, KolInputRange, KolInputDate, KolInputColor, KolInputFile, KolTextarea, KolCombobox, KolSelect, KolSingleSelect, KolInputRadio, KolInputCheckbox } from '@public-ui/react-v19';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { Controller } from 'react-hook-form';
|
|
3
|
-
import { KolInputText, KolInputPassword, KolInputEmail, KolInputNumber, KolInputRange, KolInputDate, KolInputColor, KolInputFile, KolTextarea, KolCombobox, KolSelect, KolSingleSelect, KolInputRadio, KolInputCheckbox } from '@public-ui/react-v19';
|
|
4
4
|
|
|
5
5
|
function withController(Component, valueProp) {
|
|
6
|
-
|
|
7
|
-
const { name, control, rules, defaultValue, ...
|
|
8
|
-
const userEventHandlers = props._on || {};
|
|
6
|
+
const ControllerWrapper = React.forwardRef((props, ref) => {
|
|
7
|
+
const { name, control, rules, defaultValue, shouldUnregister, disabled, ...componentProps } = props;
|
|
9
8
|
return /* @__PURE__ */ React.createElement(
|
|
10
9
|
Controller,
|
|
11
10
|
{
|
|
@@ -13,58 +12,52 @@ function withController(Component, valueProp) {
|
|
|
13
12
|
control,
|
|
14
13
|
rules,
|
|
15
14
|
defaultValue,
|
|
15
|
+
shouldUnregister,
|
|
16
|
+
disabled,
|
|
16
17
|
render: ({ field, fieldState }) => {
|
|
17
|
-
const
|
|
18
|
-
|
|
18
|
+
const userHandlers = componentProps._on;
|
|
19
|
+
const mergedProps = {
|
|
20
|
+
...componentProps,
|
|
21
|
+
ref: (element) => {
|
|
22
|
+
if (ref) {
|
|
23
|
+
if (typeof ref === "function") ref(element);
|
|
24
|
+
else ref.current = element;
|
|
25
|
+
}
|
|
26
|
+
if (element) field.ref(element);
|
|
27
|
+
},
|
|
19
28
|
_name: name,
|
|
20
29
|
_touched: fieldState.isTouched,
|
|
21
|
-
_disabled:
|
|
30
|
+
_disabled: componentProps._disabled || disabled || field.disabled,
|
|
22
31
|
_msg: fieldState.error ? {
|
|
23
32
|
_type: "error",
|
|
24
|
-
_description:
|
|
33
|
+
_description: fieldState.error.message || String(fieldState.error)
|
|
25
34
|
} : void 0,
|
|
26
35
|
_on: {
|
|
27
|
-
...
|
|
28
|
-
onInput: (
|
|
36
|
+
...userHandlers || {},
|
|
37
|
+
onInput: (event, value) => {
|
|
29
38
|
field.onChange(value);
|
|
30
|
-
|
|
31
|
-
userEventHandlers.onInput(e, value);
|
|
32
|
-
}
|
|
39
|
+
userHandlers?.onInput?.(event, value);
|
|
33
40
|
},
|
|
34
|
-
onChange: (
|
|
41
|
+
onChange: (event, value) => {
|
|
35
42
|
field.onChange(value);
|
|
36
|
-
|
|
37
|
-
userEventHandlers.onChange(e, value);
|
|
38
|
-
}
|
|
43
|
+
userHandlers?.onChange?.(event, value);
|
|
39
44
|
},
|
|
40
|
-
onBlur: (
|
|
45
|
+
onBlur: (event) => {
|
|
41
46
|
field.onBlur();
|
|
42
|
-
|
|
43
|
-
userEventHandlers.onBlur(e);
|
|
44
|
-
}
|
|
47
|
+
userHandlers?.onBlur?.(event);
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
if (valueProp) {
|
|
49
|
-
|
|
52
|
+
mergedProps[valueProp] = field.value;
|
|
50
53
|
}
|
|
51
|
-
return /* @__PURE__ */ React.createElement(
|
|
52
|
-
Component,
|
|
53
|
-
{
|
|
54
|
-
ref: (e) => {
|
|
55
|
-
if (ref) {
|
|
56
|
-
if (typeof ref === "function") ref(e);
|
|
57
|
-
else ref.current = e;
|
|
58
|
-
}
|
|
59
|
-
if (e && field.ref) field.ref(e);
|
|
60
|
-
},
|
|
61
|
-
...componentProps
|
|
62
|
-
}
|
|
63
|
-
);
|
|
54
|
+
return /* @__PURE__ */ React.createElement(Component, { ...mergedProps });
|
|
64
55
|
}
|
|
65
56
|
}
|
|
66
57
|
);
|
|
67
58
|
});
|
|
59
|
+
ControllerWrapper.displayName = `withController(${Component.displayName || Component.name || "Component"})`;
|
|
60
|
+
return ControllerWrapper;
|
|
68
61
|
}
|
|
69
62
|
const KolInputTextController = withController(KolInputText, "_value");
|
|
70
63
|
const KolInputPasswordController = withController(KolInputPassword, "_value");
|
|
@@ -73,7 +66,7 @@ const KolInputNumberController = withController(KolInputNumber, "_value");
|
|
|
73
66
|
const KolInputRangeController = withController(KolInputRange, "_value");
|
|
74
67
|
const KolInputDateController = withController(KolInputDate, "_value");
|
|
75
68
|
const KolInputColorController = withController(KolInputColor, "_value");
|
|
76
|
-
const KolInputFileController = withController(KolInputFile
|
|
69
|
+
const KolInputFileController = withController(KolInputFile);
|
|
77
70
|
const KolTextareaController = withController(KolTextarea, "_value");
|
|
78
71
|
const KolComboboxController = withController(KolCombobox, "_value");
|
|
79
72
|
const KolSelectController = withController(KolSelect, "_value");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@public-ui/react-hook-form-adapter",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.3",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"homepage": "https://public-ui.github.io",
|
|
6
6
|
"repository": {
|
|
@@ -46,24 +46,24 @@
|
|
|
46
46
|
"react-hook-form"
|
|
47
47
|
],
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/react": "18.3.
|
|
49
|
+
"@types/react": "18.3.26",
|
|
50
50
|
"@types/react-dom": "18.3.7",
|
|
51
51
|
"@typescript-eslint/eslint-plugin": "7.18.0",
|
|
52
52
|
"@typescript-eslint/parser": "7.18.0",
|
|
53
53
|
"eslint": "8.57.1",
|
|
54
54
|
"prettier": "3.6.2",
|
|
55
55
|
"react": "19.1.1",
|
|
56
|
-
"react-dom": "19.
|
|
56
|
+
"react-dom": "19.2.0",
|
|
57
57
|
"react-hook-form": "7.63.0",
|
|
58
|
-
"typescript": "5.9.
|
|
58
|
+
"typescript": "5.9.3",
|
|
59
59
|
"unbuild": "3.6.1",
|
|
60
|
-
"@public-ui/components": "4.0.0-alpha.
|
|
61
|
-
"@public-ui/react-v19": "4.0.0-alpha.
|
|
60
|
+
"@public-ui/components": "4.0.0-alpha.3",
|
|
61
|
+
"@public-ui/react-v19": "4.0.0-alpha.3"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"react": "^19",
|
|
65
65
|
"react-hook-form": "^7",
|
|
66
|
-
"@public-ui/react-v19": "4.0.0-alpha.
|
|
66
|
+
"@public-ui/react-v19": "4.0.0-alpha.3"
|
|
67
67
|
},
|
|
68
68
|
"sideEffects": false,
|
|
69
69
|
"type": "module",
|