@public-ui/react-hook-form-adapter 4.0.0-alpha.1 → 4.0.0-alpha.10

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.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
- return React.forwardRef((props, ref) => {
7
- const { name, control, rules, defaultValue, ...rest } = props;
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 componentProps = {
18
- ...rest,
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: props._disabled || field.disabled,
30
+ _disabled: componentProps._disabled || disabled || field.disabled,
22
31
  _msg: fieldState.error ? {
23
32
  _type: "error",
24
- _description: typeof fieldState.error === "string" ? fieldState.error : fieldState.error?.message ?? ""
33
+ _description: fieldState.error.message || String(fieldState.error)
25
34
  } : void 0,
26
35
  _on: {
27
- ...userEventHandlers,
28
- onInput: (e, value) => {
36
+ ...userHandlers || {},
37
+ onInput: (event, value) => {
29
38
  field.onChange(value);
30
- if (userEventHandlers.onInput) {
31
- userEventHandlers.onInput(e, value);
32
- }
39
+ userHandlers?.onInput?.(event, value);
33
40
  },
34
- onChange: (e, value) => {
41
+ onChange: (event, value) => {
35
42
  field.onChange(value);
36
- if (userEventHandlers.onChange) {
37
- userEventHandlers.onChange(e, value);
38
- }
43
+ userHandlers?.onChange?.(event, value);
39
44
  },
40
- onBlur: (e) => {
45
+ onBlur: (event) => {
41
46
  field.onBlur();
42
- if (userEventHandlers.onBlur) {
43
- userEventHandlers.onBlur(e);
44
- }
47
+ userHandlers?.onBlur?.(event);
45
48
  }
46
49
  }
47
50
  };
48
51
  if (valueProp) {
49
- componentProps[valueProp] = field.value;
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, void 0);
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");
@@ -81,4 +74,4 @@ const KolSingleSelectController = withController(KolSingleSelect, "_value");
81
74
  const KolInputRadioController = withController(KolInputRadio, "_value");
82
75
  const KolInputCheckboxController = withController(KolInputCheckbox, "_checked");
83
76
 
84
- export { KolComboboxController, KolInputCheckboxController, KolInputColorController, KolInputDateController, KolInputEmailController, KolInputFileController, KolInputNumberController, KolInputPasswordController, KolInputRadioController, KolInputRangeController, KolInputTextController, KolSelectController, KolSingleSelectController, KolTextareaController, withController };
77
+ export { KolComboboxController, KolInputCheckboxController, KolInputColorController, KolInputDateController, KolInputEmailController, KolInputFileController, KolInputNumberController, KolInputPasswordController, KolInputRadioController, KolInputRangeController, KolInputTextController, KolSelectController, KolSingleSelectController, KolTextareaController };
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.1",
3
+ "version": "4.0.0-alpha.10",
4
4
  "license": "EUPL-1.2",
5
5
  "homepage": "https://public-ui.github.io",
6
6
  "repository": {
@@ -46,24 +46,25 @@
46
46
  "react-hook-form"
47
47
  ],
48
48
  "devDependencies": {
49
- "@types/react": "18.3.24",
50
- "@types/react-dom": "18.3.7",
49
+ "@types/react": "19.2.7",
50
+ "@types/react-dom": "19.2.3",
51
51
  "@typescript-eslint/eslint-plugin": "7.18.0",
52
52
  "@typescript-eslint/parser": "7.18.0",
53
53
  "eslint": "8.57.1",
54
- "prettier": "3.6.2",
55
- "react": "19.1.1",
56
- "react-dom": "19.1.1",
54
+ "prettier": "3.7.4",
55
+ "prettier-plugin-organize-imports": "4.3.0",
56
+ "react": "19.2.0",
57
+ "react-dom": "19.2.3",
57
58
  "react-hook-form": "7.63.0",
58
- "typescript": "5.9.2",
59
+ "typescript": "5.9.3",
59
60
  "unbuild": "3.6.1",
60
- "@public-ui/components": "4.0.0-alpha.1",
61
- "@public-ui/react-v19": "4.0.0-alpha.1"
61
+ "@public-ui/components": "4.0.0-alpha.10",
62
+ "@public-ui/react-v19": "4.0.0-alpha.10"
62
63
  },
63
64
  "peerDependencies": {
64
65
  "react": "^19",
65
66
  "react-hook-form": "^7",
66
- "@public-ui/react-v19": "4.0.0-alpha.1"
67
+ "@public-ui/react-v19": "4.0.0-alpha.10"
67
68
  },
68
69
  "sideEffects": false,
69
70
  "type": "module",
@@ -83,8 +84,8 @@
83
84
  "scripts": {
84
85
  "build": "unbuild",
85
86
  "format": "prettier --check src",
86
- "-lint": "pnpm lint:eslint && pnpm lint:tsc",
87
- "-lint:eslint": "eslint src",
88
- "-lint:tsc": "tsc --noemit"
87
+ "lint": "pnpm lint:eslint && pnpm lint:tsc",
88
+ "lint:eslint": "eslint src",
89
+ "lint:tsc": "tsc --noemit"
89
90
  }
90
91
  }