haze-ui 1.6.1 → 1.7.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.
Files changed (127) hide show
  1. package/dist/components/Accordion/Accordion.js +1 -1
  2. package/dist/components/Accordion/AccordionItem.js +1 -1
  3. package/dist/components/Affix/Affix.js +1 -1
  4. package/dist/components/Alert/Alert.js +1 -1
  5. package/dist/components/ApprovalCard/ApprovalCard.js +1 -1
  6. package/dist/components/AspectRatio/AspectRatio.js +3 -2
  7. package/dist/components/Avatar/Avatar.js +1 -1
  8. package/dist/components/BackToTop/BackToTop.js +1 -1
  9. package/dist/components/Badge/Badge.js +1 -1
  10. package/dist/components/Banner/Banner.js +1 -1
  11. package/dist/components/BottomSheet/BottomSheet.js +1 -1
  12. package/dist/components/Breadcrumb/Breadcrumb.js +1 -1
  13. package/dist/components/Breadcrumb/BreadcrumbItem.js +1 -1
  14. package/dist/components/Button/Button.js +1 -1
  15. package/dist/components/Card/Card.js +1 -1
  16. package/dist/components/Carousel/Carousel.js +1 -1
  17. package/dist/components/Carousel/CarouselSlide.js +1 -1
  18. package/dist/components/ChatContainer/ChatContainer.js +1 -1
  19. package/dist/components/ChatInput/ChatInput.js +1 -1
  20. package/dist/components/ChatMessage/ChatMessage.js +1 -1
  21. package/dist/components/Checkbox/Checkbox.js +1 -1
  22. package/dist/components/Chip/Chip.js +3 -2
  23. package/dist/components/CodeBlock/CodeBlock.js +1 -1
  24. package/dist/components/Collapsible/Collapsible.js +1 -1
  25. package/dist/components/ColorPicker/ColorPicker.js +1 -1
  26. package/dist/components/Combobox/Combobox.js +12 -10
  27. package/dist/components/Combobox/ComboboxOption.js +1 -1
  28. package/dist/components/Command/Command.js +1 -1
  29. package/dist/components/ConfirmDialog/ConfirmDialog.js +1 -1
  30. package/dist/components/Container/Container.js +1 -1
  31. package/dist/components/ContextMenu/ContextMenu.js +4 -4
  32. package/dist/components/ContextMenu/ContextMenuContent.js +4 -4
  33. package/dist/components/ContextMenu/ContextMenuItem.js +4 -4
  34. package/dist/components/ContextMenu/ContextMenuSeparator.js +1 -1
  35. package/dist/components/ContextMenu/ContextMenuTrigger.js +4 -4
  36. package/dist/components/ConversationList/ConversationItem.js +1 -1
  37. package/dist/components/ConversationList/ConversationList.js +1 -1
  38. package/dist/components/DateRangePicker/DateRangePicker.js +1 -1
  39. package/dist/components/Datepicker/Calendar.js +1 -1
  40. package/dist/components/Datepicker/Datepicker.js +5 -5
  41. package/dist/components/Dialog/Dialog.js +1 -1
  42. package/dist/components/DiffViewer/DiffViewer.js +1 -1
  43. package/dist/components/Disclosure/Disclosure.js +1 -1
  44. package/dist/components/Divider/Divider.js +1 -1
  45. package/dist/components/Drawer/Drawer.js +1 -1
  46. package/dist/components/DropdownMenu/DropdownMenu.js +4 -4
  47. package/dist/components/DropdownMenu/DropdownMenuContent.js +4 -4
  48. package/dist/components/DropdownMenu/DropdownMenuItem.js +4 -4
  49. package/dist/components/DropdownMenu/DropdownMenuSeparator.js +1 -1
  50. package/dist/components/DropdownMenu/DropdownMenuTrigger.js +4 -4
  51. package/dist/components/Empty/Empty.js +1 -1
  52. package/dist/components/FileInput/FileInput.js +1 -1
  53. package/dist/components/Flex/Flex.js +10 -9
  54. package/dist/components/Grid/Grid.js +1 -1
  55. package/dist/components/Icon/Icon.js +3 -3
  56. package/dist/components/Image/Image.js +1 -1
  57. package/dist/components/InlineEdit/InlineEdit.js +1 -1
  58. package/dist/components/Input/Input.js +1 -1
  59. package/dist/components/List/List.js +1 -1
  60. package/dist/components/List/ListItem.js +1 -1
  61. package/dist/components/LogViewer/LogViewer.js +1 -1
  62. package/dist/components/MarkdownRenderer/MarkdownRenderer.js +3 -2
  63. package/dist/components/Menu/Menu.js +1 -1
  64. package/dist/components/Menu/MenuItem.js +1 -1
  65. package/dist/components/ModelPicker/ModelPicker.js +1 -1
  66. package/dist/components/NavigationBar/NavLink.js +1 -1
  67. package/dist/components/NavigationBar/NavigationBar.js +1 -1
  68. package/dist/components/NumberInput/NumberInput.js +1 -1
  69. package/dist/components/OTPInput/OTPInput.js +1 -1
  70. package/dist/components/Pagination/Pagination.js +1 -1
  71. package/dist/components/PasswordInput/PasswordInput.js +1 -1
  72. package/dist/components/Popover/Popover.js +1 -1
  73. package/dist/components/Progress/Progress.js +1 -1
  74. package/dist/components/Radio/Radio.js +4 -4
  75. package/dist/components/Radio/RadioGroup.js +4 -4
  76. package/dist/components/Rating/Rating.js +1 -1
  77. package/dist/components/Resizable/Resizable.js +3 -3
  78. package/dist/components/ScrollArea/ScrollArea.js +3 -2
  79. package/dist/components/Segmented/Segmented.js +1 -1
  80. package/dist/components/Select/Select.js +1 -1
  81. package/dist/components/Skeleton/Skeleton.js +6 -5
  82. package/dist/components/Slider/Slider.js +1 -1
  83. package/dist/components/Spinner/Spinner.js +1 -1
  84. package/dist/components/Stat/Stat.js +1 -1
  85. package/dist/components/StepTimeline/StepTimeline.js +1 -1
  86. package/dist/components/Stepper/Step.js +8 -8
  87. package/dist/components/Stepper/Stepper.js +6 -6
  88. package/dist/components/StreamingText/StreamingText.js +1 -1
  89. package/dist/components/SwipeAction/SwipeAction.js +1 -1
  90. package/dist/components/Switch/Switch.js +1 -1
  91. package/dist/components/Table/Table.js +1 -1
  92. package/dist/components/Table/TableBody.js +1 -1
  93. package/dist/components/Table/TableCell.js +1 -1
  94. package/dist/components/Table/TableHead.js +1 -1
  95. package/dist/components/Table/TableRow.js +1 -1
  96. package/dist/components/Tabs/Tab.js +4 -4
  97. package/dist/components/Tabs/TabList.js +1 -1
  98. package/dist/components/Tabs/TabPanel.js +4 -4
  99. package/dist/components/Tabs/Tabs.js +4 -4
  100. package/dist/components/Tag/Tag.js +1 -1
  101. package/dist/components/TagGroup/TagGroup.js +1 -1
  102. package/dist/components/TagGroup/TagGroupItem.js +1 -1
  103. package/dist/components/TagInput/TagInput.js +1 -1
  104. package/dist/components/Textarea/Textarea.js +1 -1
  105. package/dist/components/ThinkingIndicator/ThinkingIndicator.js +1 -1
  106. package/dist/components/TimePicker/TimePicker.js +1 -1
  107. package/dist/components/Timeline/Timeline.js +1 -1
  108. package/dist/components/Toast/Toast.js +1 -1
  109. package/dist/components/TokenCounter/TokenCounter.js +1 -1
  110. package/dist/components/ToolCallCard/ToolCallCard.js +1 -1
  111. package/dist/components/Tooltip/Tooltip.js +1 -1
  112. package/dist/components/Transfer/Transfer.js +1 -1
  113. package/dist/components/Tree/Tree.js +39 -39
  114. package/dist/components/Tree/TreeItem.js +1 -1
  115. package/dist/components/Typography/Typography.js +3 -2
  116. package/dist/components/Upload/Upload.js +10 -10
  117. package/dist/components/VirtualList/VirtualList.js +1 -1
  118. package/dist/form/FormItem.js +42 -0
  119. package/dist/form/useFormControl.js +54 -0
  120. package/dist/form.js +3 -0
  121. package/dist/haze-ui.css +1 -1
  122. package/dist/types/form/FormItem.d.ts +55 -0
  123. package/dist/types/form/index.d.ts +4 -0
  124. package/dist/types/form/useFormControl.d.ts +32 -0
  125. package/dist/types/utils/classnames.d.ts +1 -0
  126. package/dist/utils/classnames.js +13 -0
  127. package/package.json +36 -32
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  import { useControl as r } from "react-use-control";
5
5
  import { useCallback as i, useState as a } from "react";
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t } from "react/jsx-runtime";
4
4
  import { useControl as n } from "react-use-control";
5
5
  //#region src/lib/components/Textarea/Textarea.tsx
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  //#region src/lib/components/ThinkingIndicator/ThinkingIndicator.tsx
5
5
  var r = "haze-ThinkingIndicator__wrapper", i = "haze-ThinkingIndicator__dots", a = "haze-ThinkingIndicator__dot", o = "haze-ThinkingIndicator__dot2", s = "haze-ThinkingIndicator__dot3";
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t } from "react/jsx-runtime";
4
4
  import { useControl as n } from "react-use-control";
5
5
  //#region src/lib/components/TimePicker/TimePicker.tsx
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  //#region src/lib/components/Timeline/Timeline.tsx
5
5
  var r = "haze-Timeline__base";
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  import { useEffect as r } from "react";
5
5
  //#region src/lib/components/Toast/Toast.tsx
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  //#region src/lib/components/TokenCounter/TokenCounter.tsx
5
5
  var r = "haze-TokenCounter__wrapper", i = "haze-TokenCounter__bar", a = "haze-TokenCounter__fill", o = "haze-TokenCounter__fillNormal", s = "haze-TokenCounter__fillWarning", c = "haze-TokenCounter__fillDanger", l = "haze-TokenCounter__info", u = "haze-TokenCounter__count";
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  //#region src/lib/components/ToolCallCard/ToolCallCard.tsx
5
5
  var r = "haze-ToolCallCard__card", i = "haze-ToolCallCard__header", a = "haze-ToolCallCard__statusIcon", o = "haze-ToolCallCard__statusPending", s = "haze-ToolCallCard__statusRunning", c = "haze-ToolCallCard__statusDone", l = "haze-ToolCallCard__statusError", u = "haze-ToolCallCard__body", d = "haze-ToolCallCard__section", f = "haze-ToolCallCard__sectionLabel", p = "haze-ToolCallCard__content", m = {
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  import { useId as r } from "react";
5
5
  //#region src/lib/components/Tooltip/Tooltip.tsx
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  import { useControl as r } from "react-use-control";
5
5
  import { useState as i } from "react";
@@ -1,22 +1,22 @@
1
- import e from "./TreeItem.js";
2
- import { findNodeByKey as t, getChildKeys as n, getParentKey as r } from "./utils.js";
1
+ import { classnames as e } from "../../utils/classnames.js";
2
+ import t from "./TreeItem.js";
3
+ import { findNodeByKey as n, getChildKeys as r, getParentKey as i } from "./utils.js";
3
4
  /* empty css */
4
- import { classnames as i } from "babel-runtime-jsx-plus";
5
5
  import { jsx as a, jsxs as o } from "react/jsx-runtime";
6
6
  import { useControl as s } from "react-use-control";
7
7
  import { useMemo as c } from "react";
8
8
  //#region src/lib/components/Tree/Tree.tsx
9
9
  var l = "haze-Tree__base", u = "haze-Tree__group";
10
- function d(e, t, r) {
11
- if (r) return {
10
+ function d(e, t, n) {
11
+ if (n) return {
12
12
  checked: e,
13
13
  halfChecked: []
14
14
  };
15
15
  let i = new Set(e), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = (e) => {
16
- for (let r of e) if (r.children?.length) {
17
- s(r.children);
18
- let e = n(t, r.key), c = e.filter((e) => i.has(e));
19
- c.length === 0 ? o.add(r.key) : c.length < e.length && (a.add(r.key), o.add(r.key));
16
+ for (let n of e) if (n.children?.length) {
17
+ s(n.children);
18
+ let e = r(t, n.key), c = e.filter((e) => i.has(e));
19
+ c.length === 0 ? o.add(n.key) : c.length < e.length && (a.add(n.key), o.add(n.key));
20
20
  }
21
21
  };
22
22
  return s(t), {
@@ -31,56 +31,56 @@ function f({ treeData: f, multiple: p = !1, checkable: m = !1, checkStrictly: h
31
31
  h
32
32
  ]), B = z.checked, V = z.halfChecked;
33
33
  function H(e) {
34
- let n = M.includes(e), r = n ? M.filter((t) => t !== e) : [...M, e];
34
+ let t = M.includes(e), r = t ? M.filter((t) => t !== e) : [...M, e];
35
35
  N(r), k?.(r, {
36
- expanded: !n,
37
- node: t(f, e)
36
+ expanded: !t,
37
+ node: n(f, e)
38
38
  });
39
39
  }
40
40
  function U(e) {
41
- let n = t(f, e);
42
- if (!n?.selectable && n?.selectable !== void 0 || !g) return;
41
+ let t = n(f, e);
42
+ if (!t?.selectable && t?.selectable !== void 0 || !g) return;
43
43
  let r;
44
44
  r = p ? P.indexOf(e) >= 0 ? P.filter((t) => t !== e) : [...P, e] : P.includes(e) ? [] : [e], F(r), A?.(r, {
45
45
  selected: r.includes(e),
46
- selectedNodes: r.map((e) => t(f, e)).filter(Boolean),
47
- node: n
46
+ selectedNodes: r.map((e) => n(f, e)).filter(Boolean),
47
+ node: t
48
48
  });
49
49
  }
50
50
  function W(e) {
51
- if (!m || t(f, e)?.disableCheckbox) return;
52
- let i = B.includes(e), a;
53
- if (h) a = i ? B.filter((t) => t !== e) : [...B, e];
51
+ if (!m || n(f, e)?.disableCheckbox) return;
52
+ let t = B.includes(e), a;
53
+ if (h) a = t ? B.filter((t) => t !== e) : [...B, e];
54
54
  else {
55
- let t = n(f, e);
56
- if (i) {
57
- a = B.filter((n) => n !== e && !t.includes(n));
58
- let n = r(f, e);
59
- for (; n;) a = a.filter((e) => e !== n), n = r(f, n);
55
+ let n = r(f, e);
56
+ if (t) {
57
+ a = B.filter((t) => t !== e && !n.includes(t));
58
+ let t = i(f, e);
59
+ for (; t;) a = a.filter((e) => e !== t), t = i(f, t);
60
60
  } else {
61
- let i = [e, ...t].filter((e) => !B.includes(e));
62
- a = [...B, ...i];
63
- let o = r(f, e);
64
- for (; o;) n(f, o).every((e) => a.includes(e)) && !a.includes(o) && a.push(o), o = r(f, o);
61
+ let t = [e, ...n].filter((e) => !B.includes(e));
62
+ a = [...B, ...t];
63
+ let o = i(f, e);
64
+ for (; o;) r(f, o).every((e) => a.includes(e)) && !a.includes(o) && a.push(o), o = i(f, o);
65
65
  }
66
66
  }
67
67
  let o = d(a, f, h);
68
68
  L(h ? a : o.checked), j?.(h ? a : o, {
69
- checked: !i,
70
- checkedNodes: a.map((e) => t(f, e)).filter(Boolean),
71
- node: t(f, e),
69
+ checked: !t,
70
+ checkedNodes: a.map((e) => n(f, e)).filter(Boolean),
71
+ node: n(f, e),
72
72
  halfCheckedKeys: o.halfChecked
73
73
  });
74
74
  }
75
- function G(t, n, r) {
76
- return t.map((s, c) => {
77
- let l = !!s.children?.length, d = M.includes(s.key), f = P.includes(s.key), p = B.includes(s.key), h = V.includes(s.key), T = p ? "checked" : h ? "halfChecked" : "unchecked", E = c === t.length - 1, D = [...r, E];
75
+ function G(n, r, i) {
76
+ return n.map((s, c) => {
77
+ let l = !!s.children?.length, d = M.includes(s.key), f = P.includes(s.key), p = B.includes(s.key), h = V.includes(s.key), T = p ? "checked" : h ? "halfChecked" : "unchecked", E = c === n.length - 1, D = [...i, E];
78
78
  return /* @__PURE__ */ o("div", {
79
79
  role: "group",
80
- className: i(u),
81
- children: [/* @__PURE__ */ a(e, {
80
+ className: e(u),
81
+ children: [/* @__PURE__ */ a(t, {
82
82
  node: s,
83
- level: n,
83
+ level: r,
84
84
  expanded: d,
85
85
  selected: f,
86
86
  checked: T,
@@ -99,13 +99,13 @@ function f({ treeData: f, multiple: p = !1, checkable: m = !1, checkStrictly: h
99
99
  onToggle: () => H(s.key),
100
100
  onSelect: () => U(s.key),
101
101
  onCheck: () => W(s.key)
102
- }), l && d && /* @__PURE__ */ a("div", { children: G(s.children, n + 1, D) })]
102
+ }), l && d && /* @__PURE__ */ a("div", { children: G(s.children, r + 1, D) })]
103
103
  }, s.key);
104
104
  });
105
105
  }
106
106
  return /* @__PURE__ */ a("div", {
107
107
  role: "tree",
108
- className: i([l, O]),
108
+ className: e([l, O]),
109
109
  children: G(f, 0, [])
110
110
  });
111
111
  }
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
4
  //#region src/lib/components/Tree/TreeItem.tsx
5
5
  var r = "haze-TreeItem__item", i = "haze-TreeItem__blockItem", a = "haze-TreeItem__selectedStyle", o = "haze-TreeItem__disabledStyle", s = "haze-TreeItem__switcher", c = "haze-TreeItem__switcherExpanded", l = "haze-TreeItem__checkbox", u = "haze-TreeItem__checkboxChecked", d = "haze-TreeItem__checkboxHalfChecked", f = "haze-TreeItem__nodeIcon", p = "haze-TreeItem__title", m = "haze-TreeItem__loadingIcon", h = "haze-TreeItem__indentLine", g = "haze-TreeItem__indentLineWithBorder", _ = () => /* @__PURE__ */ t("svg", {
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t } from "react/jsx-runtime";
4
4
  //#region src/lib/components/Typography/Typography.tsx
5
5
  var n = "haze-Typography__titleBase", r = {
@@ -10,7 +10,8 @@ var n = "haze-Typography__titleBase", r = {
10
10
  5: "haze-Typography__5"
11
11
  };
12
12
  function i({ level: i = 1, className: a, children: o }) {
13
- return /* @__PURE__ */ t(`h${i}`, {
13
+ let s = `h${i}`;
14
+ return /* @__PURE__ */ t(s, {
14
15
  className: e([
15
16
  n,
16
17
  r[i],
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { Fragment as t, jsx as n, jsxs as r } from "react/jsx-runtime";
4
4
  import { useCallback as i, useRef as a } from "react";
5
5
  //#region src/lib/components/Upload/Upload.tsx
@@ -10,17 +10,17 @@ function l({ accept: l, multiple: u = !1, onChange: d, className: f, children: p
10
10
  }, []), g = i((e) => {
11
11
  let t = Array.from(e.target.files || []);
12
12
  t.length > 0 && d?.(t), e.target.value = "";
13
- }, [d]);
13
+ }, [d]), _ = i((e) => {
14
+ e.preventDefault();
15
+ let t = Array.from(e.dataTransfer.files);
16
+ t.length > 0 && d?.(t);
17
+ }, [d]), v = i((e) => {
18
+ e.preventDefault();
19
+ }, []);
14
20
  return /* @__PURE__ */ r("div", {
15
21
  onClick: h,
16
- onDrop: i((e) => {
17
- e.preventDefault();
18
- let t = Array.from(e.dataTransfer.files);
19
- t.length > 0 && d?.(t);
20
- }, [d]),
21
- onDragOver: i((e) => {
22
- e.preventDefault();
23
- }, []),
22
+ onDrop: _,
23
+ onDragOver: v,
24
24
  role: "button",
25
25
  tabIndex: 0,
26
26
  className: e([o, f]),
@@ -1,5 +1,5 @@
1
+ import { classnames as e } from "../../utils/classnames.js";
1
2
  /* empty css */
2
- import { classnames as e } from "babel-runtime-jsx-plus";
3
3
  import { jsx as t } from "react/jsx-runtime";
4
4
  import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
5
5
  //#region src/lib/components/VirtualList/VirtualList.tsx
@@ -0,0 +1,42 @@
1
+ import { classnames as e } from "../utils/classnames.js";
2
+ import { useFormControl as t } from "./useFormControl.js";
3
+ /* empty css */
4
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
5
+ import { useId as i } from "react";
6
+ import { useField as a, useFieldErrors as o } from "react-f0rm";
7
+ //#region src/lib/form/FormItem.tsx
8
+ var s = "haze-FormItem__item", c = "haze-FormItem__labelText", l = "haze-FormItem__errorText";
9
+ function u({ form: u, name: d, label: f, validate: p, className: m, children: h }) {
10
+ let g = `haze-field-${i()}`, _ = `${g}-error`;
11
+ a({
12
+ form: u,
13
+ name: d,
14
+ validate: p
15
+ });
16
+ let v = o(u, d), y = t(u, d), b = v.length > 0;
17
+ return /* @__PURE__ */ r("div", {
18
+ className: e([s, m]),
19
+ children: [
20
+ f !== void 0 && /* @__PURE__ */ n("label", {
21
+ htmlFor: g,
22
+ className: e(c),
23
+ children: f
24
+ }),
25
+ h({
26
+ id: g,
27
+ errorId: _,
28
+ invalid: b,
29
+ errors: v,
30
+ control: y
31
+ }),
32
+ b && /* @__PURE__ */ n("span", {
33
+ id: _,
34
+ role: "alert",
35
+ className: e(l),
36
+ children: v[0].message
37
+ })
38
+ ]
39
+ });
40
+ }
41
+ //#endregion
42
+ export { u as default };
@@ -0,0 +1,54 @@
1
+ import { useControl as e, useThru as t } from "react-use-control";
2
+ import { useMemo as n } from "react";
3
+ import { getValueByPath as r, setValueByPath as i, useValueByPath as a } from "react-f0rm";
4
+ //#region src/lib/form/useFormControl.ts
5
+ var o = /* @__PURE__ */ new Map();
6
+ function s(e) {
7
+ let t = [], n = "", r = () => {
8
+ t.push(n), n = "";
9
+ };
10
+ for (let i = 0; i < e.length; i++) {
11
+ let a = e[i];
12
+ if (a === ".") n !== "" && r();
13
+ else if (a === "[") {
14
+ n !== "" && r();
15
+ let a = e[i + 1];
16
+ if (a === "\"" || a === "'") {
17
+ let n = e.indexOf(a, i + 2);
18
+ if (n === -1) throw TypeError(`Unterminated quote in path: ${e}`);
19
+ if (e[n + 1] !== "]") throw TypeError(`Expected "]" after quoted segment in path: ${e}`);
20
+ t.push(e.slice(i + 2, n)), i = n + 1;
21
+ } else {
22
+ let n = e.indexOf("]", i + 1);
23
+ if (n === -1) throw TypeError(`Unterminated bracket in path: ${e}`);
24
+ let r = e.slice(i + 1, n);
25
+ t.push(/^-?\d+$/.test(r) ? Number(r) : r), i = n;
26
+ }
27
+ } else n += a;
28
+ }
29
+ return (n !== "" || t.length === 0) && r(), t;
30
+ }
31
+ function c(e) {
32
+ if (typeof e != "string") return {
33
+ value: e,
34
+ key: JSON.stringify(e)
35
+ };
36
+ let t = o.get(e);
37
+ return t || (t = s(e), o.set(e, t)), {
38
+ value: t,
39
+ key: JSON.stringify(t)
40
+ };
41
+ }
42
+ function l(e) {
43
+ let t = typeof e == "string" ? e : JSON.stringify(e);
44
+ return n(() => c(e), [t]);
45
+ }
46
+ function u(n, o) {
47
+ let s = l(o), c = a(n, s), [, , u] = e();
48
+ return t(u, () => [c, (e) => {
49
+ let t = r(n, s), a = typeof e == "function" ? e(t) : e;
50
+ i(n, s, a);
51
+ }]);
52
+ }
53
+ //#endregion
54
+ export { u as useFormControl };
package/dist/form.js ADDED
@@ -0,0 +1,3 @@
1
+ import { useFormControl as e } from "./form/useFormControl.js";
2
+ import t from "./form/FormItem.js";
3
+ export { t as FormItem, e as useFormControl };