@mortenbrudvik/waveui 0.10.0 → 0.12.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 (258) hide show
  1. package/README.md +454 -74
  2. package/dist/components/button/Link.cjs +1 -1
  3. package/dist/components/button/Link.cjs.map +1 -1
  4. package/dist/components/button/Link.mjs +4 -4
  5. package/dist/components/button/Toolbar.cjs +1 -1
  6. package/dist/components/button/Toolbar.cjs.map +1 -1
  7. package/dist/components/button/Toolbar.mjs +25 -30
  8. package/dist/components/button/Toolbar.mjs.map +1 -1
  9. package/dist/components/button/Toolbar.navigation.cjs +2 -0
  10. package/dist/components/button/Toolbar.navigation.cjs.map +1 -0
  11. package/dist/components/button/Toolbar.navigation.mjs +17 -0
  12. package/dist/components/button/Toolbar.navigation.mjs.map +1 -0
  13. package/dist/components/data-display/Avatar.cjs +1 -1
  14. package/dist/components/data-display/Avatar.cjs.map +1 -1
  15. package/dist/components/data-display/Avatar.context.cjs +2 -0
  16. package/dist/components/data-display/Avatar.context.cjs.map +1 -0
  17. package/dist/components/data-display/Avatar.context.mjs +9 -0
  18. package/dist/components/data-display/Avatar.context.mjs.map +1 -0
  19. package/dist/components/data-display/Avatar.mjs +66 -61
  20. package/dist/components/data-display/Avatar.mjs.map +1 -1
  21. package/dist/components/data-display/AvatarGroup.cjs +1 -1
  22. package/dist/components/data-display/AvatarGroup.cjs.map +1 -1
  23. package/dist/components/data-display/AvatarGroup.mjs +10 -10
  24. package/dist/components/data-display/InfoButton.cjs +1 -1
  25. package/dist/components/data-display/InfoButton.cjs.map +1 -1
  26. package/dist/components/data-display/InfoButton.mjs +12 -12
  27. package/dist/components/data-display/InteractionTag.cjs +2 -0
  28. package/dist/components/data-display/InteractionTag.cjs.map +1 -0
  29. package/dist/components/data-display/InteractionTag.mjs +234 -0
  30. package/dist/components/data-display/InteractionTag.mjs.map +1 -0
  31. package/dist/components/data-display/Tag.cjs +1 -1
  32. package/dist/components/data-display/Tag.cjs.map +1 -1
  33. package/dist/components/data-display/Tag.mjs +222 -90
  34. package/dist/components/data-display/Tag.mjs.map +1 -1
  35. package/dist/components/data-display/TagGroup.cjs +2 -0
  36. package/dist/components/data-display/TagGroup.cjs.map +1 -0
  37. package/dist/components/data-display/TagGroup.context.cjs +2 -0
  38. package/dist/components/data-display/TagGroup.context.cjs.map +1 -0
  39. package/dist/components/data-display/TagGroup.context.mjs +113 -0
  40. package/dist/components/data-display/TagGroup.context.mjs.map +1 -0
  41. package/dist/components/data-display/TagGroup.mjs +149 -0
  42. package/dist/components/data-display/TagGroup.mjs.map +1 -0
  43. package/dist/components/data-display/tagStyles.cjs +2 -0
  44. package/dist/components/data-display/tagStyles.cjs.map +1 -0
  45. package/dist/components/data-display/tagStyles.mjs +108 -0
  46. package/dist/components/data-display/tagStyles.mjs.map +1 -0
  47. package/dist/components/feedback/Toaster.cjs +1 -1
  48. package/dist/components/feedback/Toaster.cjs.map +1 -1
  49. package/dist/components/feedback/Toaster.mjs +287 -255
  50. package/dist/components/feedback/Toaster.mjs.map +1 -1
  51. package/dist/components/input/Combobox.cjs +1 -1
  52. package/dist/components/input/Combobox.cjs.map +1 -1
  53. package/dist/components/input/Combobox.expand.cjs +1 -1
  54. package/dist/components/input/Combobox.expand.cjs.map +1 -1
  55. package/dist/components/input/Combobox.expand.mjs +7 -7
  56. package/dist/components/input/Combobox.expand.mjs.map +1 -1
  57. package/dist/components/input/Combobox.mjs +176 -175
  58. package/dist/components/input/Combobox.mjs.map +1 -1
  59. package/dist/components/input/DatePicker.cjs +1 -1
  60. package/dist/components/input/DatePicker.cjs.map +1 -1
  61. package/dist/components/input/DatePicker.mjs +188 -187
  62. package/dist/components/input/DatePicker.mjs.map +1 -1
  63. package/dist/components/input/Dropdown.cjs +1 -1
  64. package/dist/components/input/Dropdown.cjs.map +1 -1
  65. package/dist/components/input/Dropdown.mjs +41 -40
  66. package/dist/components/input/Dropdown.mjs.map +1 -1
  67. package/dist/components/input/Option.cjs +1 -1
  68. package/dist/components/input/Option.cjs.map +1 -1
  69. package/dist/components/input/Option.mjs +101 -94
  70. package/dist/components/input/Option.mjs.map +1 -1
  71. package/dist/components/input/SwatchPicker.cjs.map +1 -1
  72. package/dist/components/input/SwatchPicker.context.cjs.map +1 -1
  73. package/dist/components/input/SwatchPicker.context.mjs.map +1 -1
  74. package/dist/components/input/SwatchPicker.mjs.map +1 -1
  75. package/dist/components/input/TagPicker.cjs +1 -1
  76. package/dist/components/input/TagPicker.cjs.map +1 -1
  77. package/dist/components/input/TagPicker.context.cjs +2 -0
  78. package/dist/components/input/TagPicker.context.cjs.map +1 -0
  79. package/dist/components/input/TagPicker.context.mjs +20 -0
  80. package/dist/components/input/TagPicker.context.mjs.map +1 -0
  81. package/dist/components/input/TagPicker.create.cjs +2 -0
  82. package/dist/components/input/TagPicker.create.cjs.map +1 -0
  83. package/dist/components/input/TagPicker.create.mjs +24 -0
  84. package/dist/components/input/TagPicker.create.mjs.map +1 -0
  85. package/dist/components/input/TagPicker.mjs +13 -279
  86. package/dist/components/input/TagPicker.mjs.map +1 -1
  87. package/dist/components/input/TagPicker.option.cjs +2 -0
  88. package/dist/components/input/TagPicker.option.cjs.map +1 -0
  89. package/dist/components/input/TagPicker.option.mjs +45 -0
  90. package/dist/components/input/TagPicker.option.mjs.map +1 -0
  91. package/dist/components/input/TagPicker.overflow.cjs +2 -0
  92. package/dist/components/input/TagPicker.overflow.cjs.map +1 -0
  93. package/dist/components/input/TagPicker.overflow.mjs +153 -0
  94. package/dist/components/input/TagPicker.overflow.mjs.map +1 -0
  95. package/dist/components/input/TagPicker.parts.cjs +2 -0
  96. package/dist/components/input/TagPicker.parts.cjs.map +1 -0
  97. package/dist/components/input/TagPicker.parts.mjs +425 -0
  98. package/dist/components/input/TagPicker.parts.mjs.map +1 -0
  99. package/dist/components/input/TagPicker.root.cjs +2 -0
  100. package/dist/components/input/TagPicker.root.cjs.map +1 -0
  101. package/dist/components/input/TagPicker.root.mjs +417 -0
  102. package/dist/components/input/TagPicker.root.mjs.map +1 -0
  103. package/dist/components/input/TimePicker.cjs +1 -1
  104. package/dist/components/input/TimePicker.cjs.map +1 -1
  105. package/dist/components/input/TimePicker.mjs +156 -154
  106. package/dist/components/input/TimePicker.mjs.map +1 -1
  107. package/dist/components/layout/Accordion.cjs.map +1 -1
  108. package/dist/components/layout/Accordion.mjs.map +1 -1
  109. package/dist/components/navigation/Hamburger.cjs +2 -0
  110. package/dist/components/navigation/Hamburger.cjs.map +1 -0
  111. package/dist/components/navigation/Hamburger.mjs +54 -0
  112. package/dist/components/navigation/Hamburger.mjs.map +1 -0
  113. package/dist/components/navigation/Menu.popover.cjs +1 -1
  114. package/dist/components/navigation/Menu.popover.cjs.map +1 -1
  115. package/dist/components/navigation/Menu.popover.mjs +137 -127
  116. package/dist/components/navigation/Menu.popover.mjs.map +1 -1
  117. package/dist/components/navigation/Menu.root.cjs +1 -1
  118. package/dist/components/navigation/Menu.root.cjs.map +1 -1
  119. package/dist/components/navigation/Menu.root.mjs +4 -4
  120. package/dist/components/navigation/Nav.cjs +1 -1
  121. package/dist/components/navigation/Nav.cjs.map +1 -1
  122. package/dist/components/navigation/Nav.context.cjs +2 -0
  123. package/dist/components/navigation/Nav.context.cjs.map +1 -0
  124. package/dist/components/navigation/Nav.context.mjs +137 -0
  125. package/dist/components/navigation/Nav.context.mjs.map +1 -0
  126. package/dist/components/navigation/Nav.mjs +151 -258
  127. package/dist/components/navigation/Nav.mjs.map +1 -1
  128. package/dist/components/navigation/Nav.parts.cjs +2 -0
  129. package/dist/components/navigation/Nav.parts.cjs.map +1 -0
  130. package/dist/components/navigation/Nav.parts.mjs +77 -0
  131. package/dist/components/navigation/Nav.parts.mjs.map +1 -0
  132. package/dist/components/navigation/Nav.root.cjs +2 -0
  133. package/dist/components/navigation/Nav.root.cjs.map +1 -0
  134. package/dist/components/navigation/Nav.root.mjs +78 -0
  135. package/dist/components/navigation/Nav.root.mjs.map +1 -0
  136. package/dist/components/navigation/NavDrawer.cjs +2 -0
  137. package/dist/components/navigation/NavDrawer.cjs.map +1 -0
  138. package/dist/components/navigation/NavDrawer.context.cjs +2 -0
  139. package/dist/components/navigation/NavDrawer.context.cjs.map +1 -0
  140. package/dist/components/navigation/NavDrawer.context.mjs +11 -0
  141. package/dist/components/navigation/NavDrawer.context.mjs.map +1 -0
  142. package/dist/components/navigation/NavDrawer.mjs +179 -0
  143. package/dist/components/navigation/NavDrawer.mjs.map +1 -0
  144. package/dist/components/overlays/Dialog.cjs +1 -1
  145. package/dist/components/overlays/Dialog.cjs.map +1 -1
  146. package/dist/components/overlays/Dialog.mjs +188 -123
  147. package/dist/components/overlays/Dialog.mjs.map +1 -1
  148. package/dist/components/overlays/Dialog.shared.cjs +1 -1
  149. package/dist/components/overlays/Dialog.shared.cjs.map +1 -1
  150. package/dist/components/overlays/Dialog.shared.mjs +157 -81
  151. package/dist/components/overlays/Dialog.shared.mjs.map +1 -1
  152. package/dist/components/overlays/Dialog.slots.cjs +2 -0
  153. package/dist/components/overlays/Dialog.slots.cjs.map +1 -0
  154. package/dist/components/overlays/Dialog.slots.mjs +129 -0
  155. package/dist/components/overlays/Dialog.slots.mjs.map +1 -0
  156. package/dist/components/overlays/Drawer.cjs +1 -1
  157. package/dist/components/overlays/Drawer.cjs.map +1 -1
  158. package/dist/components/overlays/Drawer.context.cjs +2 -0
  159. package/dist/components/overlays/Drawer.context.cjs.map +1 -0
  160. package/dist/components/overlays/Drawer.context.mjs +29 -0
  161. package/dist/components/overlays/Drawer.context.mjs.map +1 -0
  162. package/dist/components/overlays/Drawer.mjs +12 -187
  163. package/dist/components/overlays/Drawer.mjs.map +1 -1
  164. package/dist/components/overlays/Drawer.panel.cjs +2 -0
  165. package/dist/components/overlays/Drawer.panel.cjs.map +1 -0
  166. package/dist/components/overlays/Drawer.panel.mjs +159 -0
  167. package/dist/components/overlays/Drawer.panel.mjs.map +1 -0
  168. package/dist/components/overlays/Drawer.parts.cjs +2 -0
  169. package/dist/components/overlays/Drawer.parts.cjs.map +1 -0
  170. package/dist/components/overlays/Drawer.parts.mjs +152 -0
  171. package/dist/components/overlays/Drawer.parts.mjs.map +1 -0
  172. package/dist/components/overlays/Drawer.root.cjs +2 -0
  173. package/dist/components/overlays/Drawer.root.cjs.map +1 -0
  174. package/dist/components/overlays/Drawer.root.mjs +207 -0
  175. package/dist/components/overlays/Drawer.root.mjs.map +1 -0
  176. package/dist/components/overlays/Drawer.scroll.cjs +2 -0
  177. package/dist/components/overlays/Drawer.scroll.cjs.map +1 -0
  178. package/dist/components/overlays/Drawer.scroll.mjs +42 -0
  179. package/dist/components/overlays/Drawer.scroll.mjs.map +1 -0
  180. package/dist/components/overlays/Popover.cjs +1 -1
  181. package/dist/components/overlays/Popover.cjs.map +1 -1
  182. package/dist/components/overlays/Popover.mjs +173 -162
  183. package/dist/components/overlays/Popover.mjs.map +1 -1
  184. package/dist/components/overlays/TeachingPopover.cjs +1 -1
  185. package/dist/components/overlays/TeachingPopover.cjs.map +1 -1
  186. package/dist/components/overlays/TeachingPopover.mjs +96 -91
  187. package/dist/components/overlays/TeachingPopover.mjs.map +1 -1
  188. package/dist/components/overlays/Tooltip.cjs +1 -1
  189. package/dist/components/overlays/Tooltip.cjs.map +1 -1
  190. package/dist/components/overlays/Tooltip.mjs +47 -47
  191. package/dist/components/overlays/Tooltip.mjs.map +1 -1
  192. package/dist/components/portal/Portal.cjs +1 -1
  193. package/dist/components/portal/Portal.cjs.map +1 -1
  194. package/dist/components/portal/Portal.mjs +5 -5
  195. package/dist/components/table/DataGrid.cjs +1 -1
  196. package/dist/components/table/DataGrid.cjs.map +1 -1
  197. package/dist/components/table/DataGrid.mjs +1 -1
  198. package/dist/hooks/useDismiss.cjs.map +1 -1
  199. package/dist/hooks/useDismiss.mjs.map +1 -1
  200. package/dist/hooks/useFocusTrap.cjs +1 -1
  201. package/dist/hooks/useFocusTrap.cjs.map +1 -1
  202. package/dist/hooks/useFocusTrap.mjs +115 -98
  203. package/dist/hooks/useFocusTrap.mjs.map +1 -1
  204. package/dist/hooks/useFocusVisible.cjs +2 -0
  205. package/dist/hooks/useFocusVisible.cjs.map +1 -0
  206. package/dist/hooks/useFocusVisible.mjs +49 -0
  207. package/dist/hooks/useFocusVisible.mjs.map +1 -0
  208. package/dist/hooks/useFocusableGroup.cjs +2 -0
  209. package/dist/hooks/useFocusableGroup.cjs.map +1 -0
  210. package/dist/hooks/useFocusableGroup.mjs +70 -0
  211. package/dist/hooks/useFocusableGroup.mjs.map +1 -0
  212. package/dist/hooks/useModalLayer.cjs +1 -1
  213. package/dist/hooks/useModalLayer.cjs.map +1 -1
  214. package/dist/hooks/useModalLayer.mjs +34 -21
  215. package/dist/hooks/useModalLayer.mjs.map +1 -1
  216. package/dist/hooks/useModalOpen.cjs +2 -0
  217. package/dist/hooks/useModalOpen.cjs.map +1 -0
  218. package/dist/hooks/useModalOpen.mjs +14 -0
  219. package/dist/hooks/useModalOpen.mjs.map +1 -0
  220. package/dist/hooks/usePopupPosition.cjs +1 -1
  221. package/dist/hooks/usePopupPosition.cjs.map +1 -1
  222. package/dist/hooks/usePopupPosition.mjs +82 -53
  223. package/dist/hooks/usePopupPosition.mjs.map +1 -1
  224. package/dist/hooks/useResolvedTarget.cjs +2 -0
  225. package/dist/hooks/useResolvedTarget.cjs.map +1 -0
  226. package/dist/hooks/useResolvedTarget.mjs +37 -0
  227. package/dist/hooks/useResolvedTarget.mjs.map +1 -0
  228. package/dist/hooks/useRestoreFocus.cjs +1 -1
  229. package/dist/hooks/useRestoreFocus.cjs.map +1 -1
  230. package/dist/hooks/useRestoreFocus.mjs +91 -78
  231. package/dist/hooks/useRestoreFocus.mjs.map +1 -1
  232. package/dist/hooks/useRovingGrid.cjs +1 -1
  233. package/dist/hooks/useRovingGrid.cjs.map +1 -1
  234. package/dist/hooks/useRovingGrid.mjs +8 -57
  235. package/dist/hooks/useRovingGrid.mjs.map +1 -1
  236. package/dist/hooks/useRovingTabIndex.cjs +1 -1
  237. package/dist/hooks/useRovingTabIndex.cjs.map +1 -1
  238. package/dist/hooks/useRovingTabIndex.mjs +180 -121
  239. package/dist/hooks/useRovingTabIndex.mjs.map +1 -1
  240. package/dist/index.cjs +1 -1
  241. package/dist/index.d.cts +3070 -269
  242. package/dist/index.d.ts +3070 -269
  243. package/dist/index.mjs +127 -107
  244. package/dist/lib/classNames.cjs +1 -1
  245. package/dist/lib/classNames.cjs.map +1 -1
  246. package/dist/lib/classNames.mjs +137 -77
  247. package/dist/lib/classNames.mjs.map +1 -1
  248. package/dist/lib/icons.cjs +1 -1
  249. package/dist/lib/icons.cjs.map +1 -1
  250. package/dist/lib/icons.mjs +13 -6
  251. package/dist/lib/icons.mjs.map +1 -1
  252. package/dist/lib/layers.cjs +1 -1
  253. package/dist/lib/layers.cjs.map +1 -1
  254. package/dist/lib/layers.mjs +120 -111
  255. package/dist/lib/layers.mjs.map +1 -1
  256. package/dist/styles.css +1 -1
  257. package/package.json +1 -1
  258. package/src/styles/tokens.css +25 -0
@@ -10,26 +10,26 @@ import { FOCUSABLE_SELECTOR as c, getFirstTabbable as l } from "../../lib/focus.
10
10
  import { useMergedRefs as u } from "../../hooks/useMergedRefs.mjs";
11
11
  import { useIsClient as d } from "../../hooks/useIsClient.mjs";
12
12
  import { joinIds as f } from "../../lib/aria.mjs";
13
- import { useDismiss as p } from "../../hooks/useDismiss.mjs";
14
- import { Portal as ee } from "../portal/Portal.mjs";
15
- import { usePopupPosition as te } from "../../hooks/usePopupPosition.mjs";
16
- import { STATE_ARIA as ne, isCloneableElement as re, renderTrigger as ie, unwrapFragment as ae } from "../../lib/renderTrigger.mjs";
17
- import * as m from "react";
18
- import { jsx as h, jsxs as g } from "react/jsx-runtime";
13
+ import { resolvePositioning as p, usePopupPosition as ee } from "../../hooks/usePopupPosition.mjs";
14
+ import { useDismiss as te } from "../../hooks/useDismiss.mjs";
15
+ import { Portal as ne } from "../portal/Portal.mjs";
16
+ import { STATE_ARIA as re, isCloneableElement as ie, renderTrigger as ae, unwrapFragment as m } from "../../lib/renderTrigger.mjs";
17
+ import * as h from "react";
18
+ import { jsx as g, jsxs as oe } from "react/jsx-runtime";
19
19
  //#region src/components/overlays/Tooltip.tsx
20
- var oe = {
20
+ var se = {
21
21
  dark: "inverted",
22
22
  light: "normal"
23
- }, se = {
23
+ }, ce = {
24
24
  inverted: "border border-inverted-border bg-inverted text-inverted-foreground",
25
25
  normal: "border border-border bg-background text-foreground"
26
- }, ce = `max-w-60 whitespace-normal break-words rounded px-3 py-1.5 text-caption-1 font-normal normal-case tracking-normal text-start shadow-8 ${[
26
+ }, le = `max-w-60 whitespace-normal break-words rounded px-3 py-1.5 text-caption-1 font-normal normal-case tracking-normal text-start shadow-8 ${[
27
27
  "before:absolute",
28
28
  "data-[side=top]:before:inset-x-0 data-[side=top]:before:top-full data-[side=top]:before:h-2",
29
29
  "data-[side=bottom]:before:inset-x-0 data-[side=bottom]:before:bottom-full data-[side=bottom]:before:h-2",
30
30
  "data-[side=left]:before:inset-y-0 data-[side=left]:before:left-full data-[side=left]:before:w-2",
31
31
  "data-[side=right]:before:inset-y-0 data-[side=right]:before:right-full data-[side=right]:before:w-2"
32
- ].join(" ")}`, _ = /^on[A-Z]/, le = ["aria-label", "aria-labelledby"];
32
+ ].join(" ")}`, _ = /^on[A-Z]/, ue = ["aria-label", "aria-labelledby"];
33
33
  function v(e) {
34
34
  return e.currentTarget.contains(e.target);
35
35
  }
@@ -38,7 +38,7 @@ function y(e) {
38
38
  v(t) && e(t);
39
39
  };
40
40
  }
41
- function ue(e) {
41
+ function de(e) {
42
42
  let t = {}, n = {};
43
43
  for (let [r, i] of Object.entries(e)) r === "id" || r.startsWith("aria-") ? t[r] = i : n[r] = _.test(r) && typeof i == "function" ? y(i) : i;
44
44
  return {
@@ -46,7 +46,7 @@ function ue(e) {
46
46
  wrapperProps: n
47
47
  };
48
48
  }
49
- function de(e, t) {
49
+ function fe(e, t) {
50
50
  let n = { ...e };
51
51
  for (let e of t) delete n[e];
52
52
  return n;
@@ -58,9 +58,9 @@ function x(e, t, n) {
58
58
  let r = (e.getAttribute(t) ?? "").split(/\s+/).filter((e) => e && e !== n);
59
59
  r.length > 0 ? e.setAttribute(t, r.join(" ")) : e.removeAttribute(t);
60
60
  }
61
- function fe(e, t, r, i) {
62
- let a = m.useRef(null), o = r === "label" ? "aria-labelledby" : "aria-describedby";
63
- m.useLayoutEffect(() => {
61
+ function pe(e, t, r, i) {
62
+ let a = h.useRef(null), o = r === "label" ? "aria-labelledby" : "aria-describedby";
63
+ h.useLayoutEffect(() => {
64
64
  let r = e.current;
65
65
  if (!r) return;
66
66
  let s = () => {
@@ -80,74 +80,74 @@ function fe(e, t, r, i) {
80
80
  }), () => u.disconnect();
81
81
  });
82
82
  }
83
- var S = ({ content: n, appearance: c, variant: l, openDelay: _, closeDelay: b = 100, delay: x, open: S, defaultOpen: pe, onOpenChange: me, relationship: C = "description", side: w = "top", align: T = "center", children: E, className: D, onMouseEnter: O, onMouseLeave: k, onFocus: A, onBlur: j, ref: M, ...N }) => {
84
- let P = t("Tooltip", c, l === void 0 ? void 0 : oe[l], "variant", "appearance") ?? "inverted", F = t("Tooltip", _, x, "delay", "openDelay") ?? 200, [I, L] = o(S, pe ?? !1, me), R = d(), z = I && R, B = m.useRef(void 0), V = m.useRef(null), H = m.useRef(null), U = s("tooltip"), { setReference: he, setFloating: ge, floatingProps: _e } = te({
83
+ var S = ({ content: n, appearance: c, variant: l, openDelay: _, closeDelay: b = 100, delay: x, open: S, defaultOpen: me, onOpenChange: he, relationship: C = "description", side: w = "top", align: T = "center", positioning: E, children: D, className: O, onMouseEnter: k, onMouseLeave: A, onFocus: j, onBlur: M, ref: N, ...P }) => {
84
+ let F = t("Tooltip", c, l === void 0 ? void 0 : se[l], "variant", "appearance") ?? "inverted", I = t("Tooltip", _, x, "delay", "openDelay") ?? 200, [L, R] = o(S, me ?? !1, he), ge = d(), z = L && ge, B = h.useRef(void 0), V = h.useRef(null), H = h.useRef(null), U = s("tooltip"), { setReference: _e, setFloating: ve, floatingProps: ye } = ee({
85
85
  open: z,
86
86
  side: w,
87
87
  align: T,
88
- offset: 8
89
- }), ve = u(M, V, he), ye = u(H, ge), W = a(() => {
88
+ ...p(E, { offset: 8 })
89
+ }), be = u(N, V, _e), xe = u(H, ve), W = a(() => {
90
90
  B.current !== void 0 && (clearTimeout(B.current), B.current = void 0);
91
91
  }), G = a(() => {
92
92
  if (W(), !z) {
93
- if (F <= 0) {
94
- L(!0);
93
+ if (I <= 0) {
94
+ R(!0);
95
95
  return;
96
96
  }
97
97
  B.current = setTimeout(() => {
98
- B.current = void 0, L(!0);
99
- }, F);
98
+ B.current = void 0, R(!0);
99
+ }, I);
100
100
  }
101
101
  }), K = a(() => {
102
- W(), L(!1);
103
- }), q = a(() => {
102
+ W(), R(!1);
103
+ }), Se = a(() => {
104
104
  W(), z && (B.current = setTimeout(() => {
105
- B.current = void 0, L(!1);
105
+ B.current = void 0, R(!1);
106
106
  }, b));
107
107
  });
108
- p({
108
+ te({
109
109
  open: z,
110
110
  onDismiss: K,
111
111
  refs: [V, H],
112
112
  anchorRef: V,
113
113
  kind: "tooltip",
114
114
  outsidePress: !1
115
- }), m.useEffect(() => {
115
+ }), h.useEffect(() => {
116
116
  let e = B;
117
117
  return () => clearTimeout(e.current);
118
118
  }, []);
119
- let be = a((e) => {
119
+ let q = a((e) => {
120
120
  (v(e) || H.current?.contains(e.target)) && G();
121
- }), xe = a((e) => {
121
+ }), Ce = a((e) => {
122
122
  !v(e) && !H.current?.contains(e.target) && K();
123
- }), { childProps: J, wrapperProps: Y } = ue(N), X = ae(E), Z = !re(X), Q = C === "label" ? "aria-labelledby" : "aria-describedby", $ = Z ? de(J, [...ne, ...le]) : { ...J };
123
+ }), { childProps: J, wrapperProps: Y } = de(P), X = m(D), Z = !ie(X), Q = C === "label" ? "aria-labelledby" : "aria-describedby", $ = Z ? fe(J, [...re, ...ue]) : { ...J };
124
124
  (!Z || C === "description") && ($[Q] = f(J[Q], U));
125
- let Se = ie(X, $, { componentName: "Tooltip" });
126
- return fe(V, U, C, Z), /* @__PURE__ */ g("span", {
127
- ref: ve,
125
+ let we = ae(X, $, { componentName: "Tooltip" });
126
+ return pe(V, U, C, Z), /* @__PURE__ */ oe("span", {
127
+ ref: be,
128
128
  ...Y,
129
- className: e(i.root, "inline-block", D),
130
- onMouseEnter: r(O, be),
131
- onMouseLeave: r(k, q),
132
- onMouseOver: r(Y.onMouseOver, xe),
133
- onFocus: y(r(A, G)),
134
- onBlur: y(r(j, K)),
129
+ className: e(i.root, "inline-block", O),
130
+ onMouseEnter: r(k, q),
131
+ onMouseLeave: r(A, Se),
132
+ onMouseOver: r(Y.onMouseOver, Ce),
133
+ onFocus: y(r(j, G)),
134
+ onBlur: y(r(M, K)),
135
135
  children: [
136
- Se,
137
- /* @__PURE__ */ h("span", {
136
+ we,
137
+ /* @__PURE__ */ g("span", {
138
138
  id: U,
139
139
  role: "tooltip",
140
140
  hidden: !0,
141
141
  children: n
142
142
  }),
143
- z && /* @__PURE__ */ h(ee, {
143
+ z && /* @__PURE__ */ g(ne, {
144
144
  layer: "tooltip",
145
- children: /* @__PURE__ */ h("span", {
146
- ref: ye,
145
+ children: /* @__PURE__ */ g("span", {
146
+ ref: xe,
147
147
  "aria-hidden": "true",
148
148
  "data-wave-tooltip-surface": "",
149
- ..._e,
150
- className: e(i.content, ce, se[P]),
149
+ ...ye,
150
+ className: e(i.content, le, ce[F]),
151
151
  children: n
152
152
  })
153
153
  })
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.mjs","names":["useId","useId$1","React","VARIANT_APPEARANCE","appearanceClasses","surfaceClasses","HANDLER_KEY","NAMING_ARIA","isOwnEvent","event","ownEventsOnly","handler","splitProps","childProps","wrapperProps","key","value","props","omit","result","keys","hasIdRef","el","attribute","id","removeIdRef","rest","useRelationshipTarget","appliedRef","relationship","wrapper","wrapperRef","update","applied","target","tooltipId","FOCUSABLE_SELECTOR","getFirstTabbable","joinIds","childIsFallback","warnOnce","observer","Tooltip","appearanceProp","openDelayProp","openProp","appearance","resolveDeprecatedProp","variant","openDelay","delay","open","setOpen","useControllable","defaultOpen","onOpenChange","isClient","useIsClient","visible","timerRef","surfaceRef","usePopupPosition","wrapperElementRef","useMergedRefs","ref","setReference","surfaceElementRef","setFloating","clearTimer","useEventCallback","show","hide","scheduleHide","closeDelay","useDismiss","timer","showOnEnter","hideOverPortaledPopup","unwrapFragment","children","isCloneableElement","triggerProps","STATE_ARIA","child","renderTrigger","cn","tooltipClassNames","className","composeEventHandlers","onMouseEnter","onMouseLeave","onFocus","onBlur","content","Portal","floatingProps"],"sources":["../../../src/components/overlays/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../lib/cn';\nimport { joinIds } from '../../lib/aria';\nimport { tooltipClassNames } from '../../lib/classNames';\nimport { resolveDeprecatedProp, warnOnce } from '../../lib/dev';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { FOCUSABLE_SELECTOR, getFirstTabbable } from '../../lib/focus';\nimport {\n isCloneableElement,\n renderTrigger,\n STATE_ARIA,\n unwrapFragment,\n} from '../../lib/renderTrigger';\nimport type { PopupAlign, PopupSide } from '../../lib/types';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useId } from '../../hooks/useId';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useDismiss } from '../../hooks/useDismiss';\nimport { usePopupPosition } from '../../hooks/usePopupPosition';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { useEventCallback } from '../../hooks/useEventCallback';\nimport { Portal } from '../portal/Portal';\n\n/** Color treatment of a tooltip (`TooltipProps.appearance`). */\nexport type TooltipAppearance = 'inverted' | 'normal';\n\n/** Properties for the Tooltip component. */\nexport interface TooltipProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'content'> {\n /** Content to display inside the tooltip (short, non-interactive text). */\n content: React.ReactNode;\n /**\n * Color treatment: `inverted` (dark surface in the light theme) or `normal` (the page\n * background with a border).\n * @default 'inverted'\n */\n appearance?: TooltipAppearance;\n /**\n * @deprecated Use `appearance` (`'dark'` → `'inverted'`, `'light'` → `'normal'`).\n */\n variant?: 'dark' | 'light';\n /**\n * Milliseconds before the tooltip appears when the pointer rests on the child or the child\n * receives keyboard focus (Fluent's `showDelay`; unlike Menu's and Popover's `openDelay`, it\n * applies to focus too).\n * @default 200\n */\n openDelay?: number;\n /**\n * Milliseconds before it hides once the pointer has left the child and the tooltip (Fluent's\n * `hideDelay`); blur and Escape hide it at once.\n * @default 100\n */\n closeDelay?: number;\n /** @deprecated Use `openDelay`. */\n delay?: number;\n /**\n * Controlled open state (Fluent's `visible`). The tooltip still asks to open on hover and focus\n * (after `openDelay`) and to close on leave, blur and Escape through `onOpenChange`. The surface\n * renders only in the browser: an open tooltip is closed in the server HTML and opens once it\n * has hydrated.\n */\n open?: boolean;\n /**\n * Initial open state for uncontrolled usage.\n * @default false\n */\n defaultOpen?: boolean;\n /**\n * Called with the new open state when it changes (Fluent's `onVisibleChange`). It has no\n * `details` argument yet.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * How the tooltip relates to its child: `description` adds it to the child's\n * `aria-describedby`; `label` adds it to the child's `aria-labelledby`, naming an icon-only\n * button.\n * @default 'description'\n */\n relationship?: 'description' | 'label';\n /**\n * Side of the target the tooltip opens on. `start`/`end` follow the writing direction; the\n * tooltip flips to the opposite side when there is not enough room.\n * @default 'top'\n */\n side?: PopupSide;\n /** Alignment along the target's edge.\n * @default 'center'\n */\n align?: PopupAlign;\n /**\n * A single element that triggers the tooltip on hover and focus: it receives the\n * `aria-describedby`/`aria-labelledby`, plus any `id` and `aria-*` props given to the Tooltip\n * (a Fragment around one element counts as that element). Other children are wrapped in a\n * described `<span>` with a development warning, and their first focusable element gets the\n * relationship.\n */\n children: React.ReactElement;\n /** Ref to the wrapper `<span>` (the positioning anchor). */\n ref?: React.Ref<HTMLSpanElement>;\n}\n\nconst VARIANT_APPEARANCE: Record<'dark' | 'light', TooltipAppearance> = {\n dark: 'inverted',\n light: 'normal',\n};\n\nconst appearanceClasses: Record<TooltipAppearance, string> = {\n inverted: 'border border-inverted-border bg-inverted text-inverted-foreground',\n normal: 'border border-border bg-background text-foreground',\n};\n\n/**\n * Transparent `::before` hover bridge across the 8px gap (the positioning offset) on the side that\n * faces the trigger only, so the pointer can move onto the tooltip; the other sides get no bridge,\n * which would otherwise catch hovers and clicks meant for neighbouring controls.\n */\nconst bridgeClasses = [\n 'before:absolute',\n // Tooltip above the trigger: a strip below it.\n 'data-[side=top]:before:inset-x-0 data-[side=top]:before:top-full data-[side=top]:before:h-2',\n // Tooltip below the trigger: a strip above it.\n 'data-[side=bottom]:before:inset-x-0 data-[side=bottom]:before:bottom-full data-[side=bottom]:before:h-2',\n // wave-allow-physical: data-side is the physical side resolved by the positioning\n 'data-[side=left]:before:inset-y-0 data-[side=left]:before:left-full data-[side=left]:before:w-2',\n // wave-allow-physical: data-side is the physical side resolved by the positioning\n 'data-[side=right]:before:inset-y-0 data-[side=right]:before:right-full data-[side=right]:before:w-2',\n].join(' ');\n\n/**\n * The visual surface: wrapping text, typography reset against the host (header cells, muted\n * panels), and the hover bridge towards the trigger.\n */\nconst surfaceClasses = `max-w-60 whitespace-normal break-words rounded px-3 py-1.5 text-caption-1 font-normal normal-case tracking-normal text-start shadow-8 ${bridgeClasses}`;\n\ntype UnknownProps = Record<string, unknown>;\ntype Relationship = NonNullable<TooltipProps['relationship']>;\n\nconst HANDLER_KEY = /^on[A-Z]/;\n\n/** Naming attributes a generic element such as the fallback `<span>` must not carry. */\nconst NAMING_ARIA = ['aria-label', 'aria-labelledby'] as const;\n\n/**\n * Whether an event reached the wrapper from its own DOM subtree — the child — rather than through\n * a portal: React bubbles events from portaled content (the tooltip surface, a popup the child\n * renders in a portal) through the component tree.\n */\nfunction isOwnEvent(event: React.SyntheticEvent): boolean {\n return (event.currentTarget as Node).contains(event.target as Node);\n}\n\n/** `handler`, called only for the wrapper's own events (see {@link isOwnEvent}). */\nfunction ownEventsOnly<E extends React.SyntheticEvent>(\n handler: (event: E) => void,\n): (event: E) => void {\n return (event) => {\n if (isOwnEvent(event)) handler(event);\n };\n}\n\n/**\n * Splits the props the Tooltip receives, from its consumer or from a parent that clones its child\n * (Menu.Trigger, Popover.Trigger, Dialog.Trigger, Field): `id` and `aria-*` describe the element\n * the Tooltip is attached to, so they go to the child; the rest stays on the wrapper `<span>`.\n */\nfunction splitProps(props: UnknownProps): { childProps: UnknownProps; wrapperProps: UnknownProps } {\n const childProps: UnknownProps = {};\n const wrapperProps: UnknownProps = {};\n for (const [key, value] of Object.entries(props)) {\n if (key === 'id' || key.startsWith('aria-')) childProps[key] = value;\n else if (HANDLER_KEY.test(key) && typeof value === 'function') {\n // The wrapper sees the child's events as they bubble, but not those that reach it through\n // a portal, such as a click on the tooltip surface (it would toggle a parent trigger).\n wrapperProps[key] = ownEventsOnly(value as (event: React.SyntheticEvent) => void);\n } else wrapperProps[key] = value;\n }\n return { childProps, wrapperProps };\n}\n\nfunction omit(props: UnknownProps, keys: readonly string[]): UnknownProps {\n const result = { ...props };\n for (const key of keys) delete result[key];\n return result;\n}\n\nfunction hasIdRef(el: Element, attribute: string, id: string): boolean {\n return (el.getAttribute(attribute) ?? '').split(/\\s+/).includes(id);\n}\n\nfunction removeIdRef(el: Element, attribute: string, id: string): void {\n const rest = (el.getAttribute(attribute) ?? '')\n .split(/\\s+/)\n .filter((value) => value && value !== id);\n if (rest.length > 0) el.setAttribute(attribute, rest.join(' '));\n else el.removeAttribute(attribute);\n}\n\n/**\n * Makes sure the element people focus carries the tooltip relationship. After each commit, when no\n * focusable element inside the wrapper references `tooltipId` through `attribute` — children in the\n * fallback span, a non-focusable child element, or a child component that drops the prop (a\n * Popover or Dialog root) — the id is added to the first tabbable element inside the wrapper and\n * kept there while the subtree changes; a development warning explains the nesting, except for\n * the fallback span, whose children shape `renderTrigger` already warned about.\n */\nfunction useRelationshipTarget(\n wrapperRef: React.RefObject<HTMLSpanElement | null>,\n tooltipId: string,\n relationship: Relationship,\n childIsFallback: boolean,\n): void {\n const appliedRef = React.useRef<{ element: Element; attribute: string } | null>(null);\n const attribute = relationship === 'label' ? 'aria-labelledby' : 'aria-describedby';\n\n React.useLayoutEffect(() => {\n const wrapper = wrapperRef.current;\n if (!wrapper) return;\n\n const update = () => {\n const applied = appliedRef.current;\n const carriers = Array.from(wrapper.querySelectorAll(`[${attribute}]`)).filter(\n (el) =>\n !(applied && applied.element === el && applied.attribute === attribute) &&\n hasIdRef(el, attribute, tooltipId),\n );\n const reached = carriers.some((el) => el.matches(FOCUSABLE_SELECTOR));\n const target = reached ? null : getFirstTabbable(wrapper);\n if (applied && (applied.element !== target || applied.attribute !== attribute)) {\n removeIdRef(applied.element, applied.attribute, tooltipId);\n appliedRef.current = null;\n }\n if (!target) return;\n if (!hasIdRef(target, attribute, tooltipId)) {\n target.setAttribute(attribute, joinIds(target.getAttribute(attribute), tooltipId) ?? '');\n }\n appliedRef.current = { element: target, attribute };\n if (!childIsFallback) {\n warnOnce(\n 'Tooltip:focus-target',\n `Tooltip: the element that takes focus inside it did not get \\`${attribute}\\` (the child is not focusable, or is a component, such as a Popover or Dialog root, that does not pass the prop on), so it was added to the first focusable element inside. Put the Tooltip directly around the focusable element, e.g. <Popover.Trigger><Tooltip content=\"…\"><Button /></Tooltip></Popover.Trigger>.`,\n );\n }\n };\n\n update();\n if (!appliedRef.current || typeof MutationObserver === 'undefined') return;\n // Keep it on the focusable element when the child replaces it or rewrites the attribute\n // without the Tooltip re-rendering.\n const observer = new MutationObserver(update);\n observer.observe(wrapper, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: [attribute],\n });\n return () => observer.disconnect();\n });\n}\n\n/**\n * Shows a short text label or description for its child on hover and keyboard focus.\n *\n * - The text is always present as a hidden `role=\"tooltip\"` element referenced by the child's\n * `aria-describedby` (or `aria-labelledby` with `relationship=\"label\"`), so screen readers get\n * it on focus without waiting for the delay; the child's own ids are kept.\n * - The visual surface is rendered in a portal only while visible (it is `aria-hidden`, a copy of\n * the description), positioned on `side`/`align` with flipping and shifting to stay in view.\n * - It appears `openDelay` after the pointer rests on the child or the child takes keyboard focus,\n * stays visible while the pointer moves onto it, hides `closeDelay` after the pointer leaves or\n * immediately on blur, and Escape hides it without closing an enclosing dialog or popover. Focus\n * and hover inside a popup the child renders in a portal (a DatePicker calendar, a listbox) do\n * not show it, and the pointer moving onto such a popup hides it.\n * - The open state is uncontrolled by default (`defaultOpen`). With `open` and `onOpenChange`\n * (Fluent's `visible` and `onVisibleChange`) the parent owns it: hover, focus, leave, blur and\n * Escape then only ask for a change, and `open` alone shows the surface.\n * - `id` and `aria-*` props given to the Tooltip go to its child, merged with the child's own (the\n * child's `id` wins, id lists are joined, `aria-expanded`/`aria-controls`/`aria-haspopup` from\n * the Tooltip win). `className`, `style`, `ref`, `data-*` and event handlers stay on the wrapper\n * `<span>`; the handlers see the child's events as they bubble, not events from portaled\n * content such as the tooltip surface or a popup the child renders in a portal (a DatePicker\n * calendar, a listbox). `onMouseEnter` and `onMouseLeave` are the exception: React fires them\n * along the component tree, so they also fire when the pointer moves onto or off the tooltip\n * surface or such a popup. So the Tooltip can sit inside a trigger, and the trigger's\n * id and state reach the button: `<Menu.Trigger><Tooltip content=\"…\"><Button /></Tooltip>\n * </Menu.Trigger>` (also `Popover.Trigger`, `Dialog.Trigger`, `Drawer.Trigger`). Around a\n * trigger works too, since triggers pass `aria-describedby` on to their child.\n * - Wrap the focusable element itself. When the element that takes focus does not get the\n * relationship (a Popover or Dialog root, a component that drops props, a non-focusable\n * wrapper element), it is added to the first focusable element inside, with a development\n * warning.\n *\n * @example\n * <Menu>\n * <Menu.Trigger>\n * <Tooltip content=\"Edit, duplicate or delete the item\">\n * <Button>Actions</Button>\n * </Tooltip>\n * </Menu.Trigger>\n * <Menu.Popover>…</Menu.Popover>\n * </Menu>\n */\nexport const Tooltip = ({\n content,\n appearance: appearanceProp,\n variant,\n openDelay: openDelayProp,\n closeDelay = 100,\n delay,\n open: openProp,\n defaultOpen,\n onOpenChange,\n relationship = 'description',\n side = 'top',\n align = 'center',\n children,\n className,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n ref,\n ...rest\n}: TooltipProps) => {\n const appearance =\n resolveDeprecatedProp(\n 'Tooltip',\n appearanceProp,\n variant === undefined ? undefined : VARIANT_APPEARANCE[variant],\n 'variant',\n 'appearance',\n ) ?? 'inverted';\n const openDelay =\n resolveDeprecatedProp('Tooltip', openDelayProp, delay, 'delay', 'openDelay') ?? 200;\n const [open, setOpen] = useControllable(openProp, defaultOpen ?? false, onOpenChange);\n // The surface lives in a portal, which renders only in the browser: until then (the server HTML,\n // hydration) the tooltip is closed; the hidden description is rendered either way.\n const isClient = useIsClient();\n const visible = open && isClient;\n const timerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const wrapperRef = React.useRef<HTMLSpanElement | null>(null);\n const surfaceRef = React.useRef<HTMLSpanElement | null>(null);\n const tooltipId = useId('tooltip');\n\n // Destructured: react-hooks/refs treats an object whose member is passed to `ref` as a ref.\n const { setReference, setFloating, floatingProps } = usePopupPosition({\n open: visible,\n side,\n align,\n offset: 8,\n });\n const wrapperElementRef = useMergedRefs<HTMLSpanElement>(ref, wrapperRef, setReference);\n const surfaceElementRef = useMergedRefs<HTMLSpanElement>(surfaceRef, setFloating);\n\n // Timer handlers are event callbacks (stable, latest state): they are composed with the\n // consumer's handlers during render but only run from events and timers.\n const clearTimer = useEventCallback(() => {\n if (timerRef.current !== undefined) {\n clearTimeout(timerRef.current);\n timerRef.current = undefined;\n }\n });\n\n // show, hide and scheduleHide ask for the new state; a controlled tooltip changes only when the\n // parent updates `open`.\n const show = useEventCallback(() => {\n clearTimer();\n if (visible) return;\n if (openDelay <= 0) {\n setOpen(true);\n return;\n }\n timerRef.current = setTimeout(() => {\n timerRef.current = undefined;\n setOpen(true);\n }, openDelay);\n });\n\n const hide = useEventCallback(() => {\n clearTimer();\n setOpen(false);\n });\n\n // The grace period after the pointer leaves lets it move onto the tooltip.\n const scheduleHide = useEventCallback(() => {\n clearTimer();\n if (!visible) return;\n timerRef.current = setTimeout(() => {\n timerRef.current = undefined;\n setOpen(false);\n }, closeDelay);\n });\n\n // An Escape-only layer while visible: Escape hides the tooltip before any enclosing overlay. The\n // wrapper is its anchor (its trigger, not its surface): Tab from the child inside a focus trap\n // moves on from the popover, portal or dialog around the wrapper.\n useDismiss({\n open: visible,\n onDismiss: hide,\n refs: [wrapperRef, surfaceRef],\n anchorRef: wrapperRef,\n kind: 'tooltip',\n outsidePress: false,\n });\n\n React.useEffect(() => {\n const timer = timerRef;\n return () => clearTimeout(timer.current);\n }, []);\n\n // The tooltip's own reactions ignore a popup the child renders in a portal: its focus and blur\n // are not the child's, entering it does not show the tooltip, and the pointer moving onto it\n // (no mouseleave reaches the wrapper then) hides the tooltip, which would cover it. The tooltip\n // surface itself is portaled too but belongs to the tooltip: it stays hoverable.\n const showOnEnter = useEventCallback((event: React.MouseEvent<HTMLSpanElement>) => {\n if (isOwnEvent(event) || surfaceRef.current?.contains(event.target as Node)) show();\n });\n const hideOverPortaledPopup = useEventCallback((event: React.MouseEvent<HTMLSpanElement>) => {\n if (!isOwnEvent(event) && !surfaceRef.current?.contains(event.target as Node)) hide();\n });\n\n const { childProps, wrapperProps } = splitProps(rest);\n const target = unwrapFragment(children);\n const childIsFallback = !isCloneableElement(target);\n const attribute = relationship === 'label' ? 'aria-labelledby' : 'aria-describedby';\n // Props given to the Tooltip come first, as if the child had them; then the tooltip's own id.\n // The fallback span is a generic element: no state ARIA and no naming on it (the relationship\n // then reaches its first focusable element through useRelationshipTarget).\n const triggerProps: UnknownProps = childIsFallback\n ? omit(childProps, [...STATE_ARIA, ...NAMING_ARIA])\n : { ...childProps };\n if (!childIsFallback || relationship === 'description') {\n triggerProps[attribute] = joinIds(childProps[attribute] as string | undefined, tooltipId);\n }\n const child = renderTrigger(target, triggerProps, { componentName: 'Tooltip' });\n useRelationshipTarget(wrapperRef, tooltipId, relationship, childIsFallback);\n\n return (\n <span\n ref={wrapperElementRef}\n {...wrapperProps}\n className={cn(tooltipClassNames.root, 'inline-block', className)}\n onMouseEnter={composeEventHandlers(onMouseEnter, showOnEnter)}\n onMouseLeave={composeEventHandlers(onMouseLeave, scheduleHide)}\n onMouseOver={composeEventHandlers(\n wrapperProps.onMouseOver as React.MouseEventHandler<HTMLSpanElement> | undefined,\n hideOverPortaledPopup,\n )}\n onFocus={ownEventsOnly(composeEventHandlers(onFocus, show))}\n onBlur={ownEventsOnly(composeEventHandlers(onBlur, hide))}\n >\n {child}\n <span id={tooltipId} role=\"tooltip\" hidden>\n {content}\n </span>\n {visible && (\n <Portal layer=\"tooltip\">\n <span\n ref={surfaceElementRef}\n aria-hidden=\"true\"\n data-wave-tooltip-surface=\"\"\n {...floatingProps}\n className={cn(tooltipClassNames.content, surfaceClasses, appearanceClasses[appearance])}\n >\n {content}\n </span>\n </Portal>\n )}\n </span>\n );\n};\n\nTooltip.displayName = 'Tooltip';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqGA,IAAMG,KAAkE;CACtE,MAAM;CACN,OAAO;AACT,GAEMC,KAAuD;CAC3D,UAAU;CACV,QAAQ;AACV,GAuBMC,KAAiB,yIAhBD;CACpB;CAEA;CAEA;CAEA;CAEA;AACF,CAAC,CAAC,KAAK,GAMyJ,KAK1JC,IAAc,YAGdC,KAAc,CAAC,cAAc,iBAAiB;AAOpD,SAASC,EAAW,GAAsC;CACxD,OAAQC,EAAM,cAAuB,SAASA,EAAM,MAAc;AACpE;AAGA,SAASC,EACP,GACoB;CACpB,QAAQ,MAAU;EAChB,AAAIF,EAAWC,CAAK,KAAGE,EAAQF,CAAK;CACtC;AACF;AAOA,SAASG,GAAW,GAA+E;CACjG,IAAMC,IAA2B,CAAC,GAC5BC,IAA6B,CAAC;CACpC,KAAK,IAAM,CAACC,GAAKC,MAAU,OAAO,QAAQC,CAAK,GAC7C,AAAIF,MAAQ,QAAQA,EAAI,WAAW,OA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C,GAAmB9C,CAAM,GAC5CX,IAAYM,MAAiB,UAAU,oBAAoB,oBAI3DoD,IAA6B1C,IAC/BrB,GAAKL,GAAY,CAAC,GAAGqE,IAAY,GAAG3E,EAAW,CAAC,IAChD,EAAE,GAAGM,EAAW;CACpB,CAAI,CAAC0B,KAAmBV,MAAiB,mBACvC,EAAaN,KAAae,EAAQzB,EAAWU,IAAkCY,CAAS;CAE1F,IAAMgD,KAAQC,GAAclD,GAAQ+C,GAAc,EAAE,eAAe,UAAU,CAAC;CAG9E,OAFAtD,GAAsBI,GAAYI,GAAWN,GAAcU,CAAe,GAGxE,kBAAC,QAAD;EACE,KAAKuB;EACL,GAAIhD;EACJ,WAAWuE,EAAGC,EAAkB,MAAM,gBAAgBC,CAAS;EAC/D,cAAcC,EAAqBC,GAAcb,EAAW;EAC5D,cAAcY,EAAqBE,GAAclB,CAAY;EAC7D,aAAagB,EACX1E,EAAa,aACb+D,EACF;EACA,SAASnE,EAAc8E,EAAqBG,GAASrB,CAAI,CAAC;EAC1D,QAAQ5D,EAAc8E,EAAqBI,GAAQrB,CAAI,CAAC;EAX1D,UAAA;GAaGY;GACD,kBAAC,QAAD;IAAM,IAAIhD;IAAW,MAAK;IAAU,QAAA;IACjC,UAAA0D;GACG,CAAA;GACLnC,KACC,kBAACoC,IAAD;IAAQ,OAAM;IACZ,UAAA,kBAAC,QAAD;KACE,KAAK5B;KACL,eAAY;KACZ,6BAA0B;KAC1B,GAAI6B;KACJ,WAAWV,EAAGC,EAAkB,SAASjF,IAAgBD,GAAkB0C,EAAW;KAErF,UAAA+C;IACG,CAAA;GACA,CAAA;EAEN;;AAEV;AAEA,EAAQ,cAAc"}
1
+ {"version":3,"file":"Tooltip.mjs","names":["useId","useId$1","React","VARIANT_APPEARANCE","appearanceClasses","surfaceClasses","HANDLER_KEY","NAMING_ARIA","isOwnEvent","event","ownEventsOnly","handler","splitProps","childProps","wrapperProps","key","value","props","omit","result","keys","hasIdRef","el","attribute","id","removeIdRef","rest","useRelationshipTarget","appliedRef","relationship","wrapper","wrapperRef","update","applied","target","tooltipId","FOCUSABLE_SELECTOR","getFirstTabbable","joinIds","childIsFallback","warnOnce","observer","Tooltip","appearanceProp","openDelayProp","openProp","appearance","resolveDeprecatedProp","variant","openDelay","delay","open","setOpen","useControllable","defaultOpen","onOpenChange","isClient","useIsClient","visible","timerRef","surfaceRef","usePopupPosition","resolvePositioning","positioning","wrapperElementRef","useMergedRefs","ref","setReference","surfaceElementRef","setFloating","clearTimer","useEventCallback","show","hide","scheduleHide","closeDelay","useDismiss","timer","showOnEnter","hideOverPortaledPopup","unwrapFragment","children","isCloneableElement","triggerProps","STATE_ARIA","child","renderTrigger","cn","tooltipClassNames","className","composeEventHandlers","onMouseEnter","onMouseLeave","onFocus","onBlur","content","Portal","floatingProps"],"sources":["../../../src/components/overlays/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../lib/cn';\nimport { joinIds } from '../../lib/aria';\nimport { tooltipClassNames } from '../../lib/classNames';\nimport { resolveDeprecatedProp, warnOnce } from '../../lib/dev';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { FOCUSABLE_SELECTOR, getFirstTabbable } from '../../lib/focus';\nimport {\n isCloneableElement,\n renderTrigger,\n STATE_ARIA,\n unwrapFragment,\n} from '../../lib/renderTrigger';\nimport type { PopupAlign, PopupPositioningOptions, PopupSide } from '../../lib/types';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useId } from '../../hooks/useId';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useDismiss } from '../../hooks/useDismiss';\nimport { resolvePositioning, usePopupPosition } from '../../hooks/usePopupPosition';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { useEventCallback } from '../../hooks/useEventCallback';\nimport { Portal } from '../portal/Portal';\n\n/** Color treatment of a tooltip (`TooltipProps.appearance`). */\nexport type TooltipAppearance = 'inverted' | 'normal';\n\n/** Properties for the Tooltip component. */\nexport interface TooltipProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'content'> {\n /** Content to display inside the tooltip (short, non-interactive text). */\n content: React.ReactNode;\n /**\n * Color treatment: `inverted` (dark surface in the light theme) or `normal` (the page\n * background with a border).\n * @default 'inverted'\n */\n appearance?: TooltipAppearance;\n /**\n * @deprecated Use `appearance` (`'dark'` → `'inverted'`, `'light'` → `'normal'`).\n */\n variant?: 'dark' | 'light';\n /**\n * Milliseconds before the tooltip appears when the pointer rests on the child or the child\n * receives keyboard focus (Fluent's `showDelay`; unlike Menu's and Popover's `openDelay`, it\n * applies to focus too).\n * @default 200\n */\n openDelay?: number;\n /**\n * Milliseconds before it hides once the pointer has left the child and the tooltip (Fluent's\n * `hideDelay`); blur and Escape hide it at once.\n * @default 100\n */\n closeDelay?: number;\n /** @deprecated Use `openDelay`. */\n delay?: number;\n /**\n * Controlled open state (Fluent's `visible`). The tooltip still asks to open on hover and focus\n * (after `openDelay`) and to close on leave, blur and Escape through `onOpenChange`. The surface\n * renders only in the browser: an open tooltip is closed in the server HTML and opens once it\n * has hydrated.\n */\n open?: boolean;\n /**\n * Initial open state for uncontrolled usage.\n * @default false\n */\n defaultOpen?: boolean;\n /**\n * Called with the new open state when it changes (Fluent's `onVisibleChange`). It has no\n * `details` argument yet.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * How the tooltip relates to its child: `description` adds it to the child's\n * `aria-describedby`; `label` adds it to the child's `aria-labelledby`, naming an icon-only\n * button.\n * @default 'description'\n */\n relationship?: 'description' | 'label';\n /**\n * Side of the target the tooltip opens on. `start`/`end` follow the writing direction; the\n * tooltip flips to the opposite side when there is not enough room.\n * @default 'top'\n */\n side?: PopupSide;\n /** Alignment along the target's edge.\n * @default 'center'\n */\n align?: PopupAlign;\n /**\n * Advanced positioning (Fluent's `positioning`): `offset`, `fitViewport`, `matchReferenceWidth`\n * and `fallbackPlacements`. `side` and `align` stay separate props. The hover bridge across the\n * gap covers the default 8px, so a larger `offset` leaves a gap the pointer cannot cross.\n * @default `{ offset: 8 }`\n */\n positioning?: PopupPositioningOptions;\n /**\n * A single element that triggers the tooltip on hover and focus: it receives the\n * `aria-describedby`/`aria-labelledby`, plus any `id` and `aria-*` props given to the Tooltip\n * (a Fragment around one element counts as that element). Other children are wrapped in a\n * described `<span>` with a development warning, and their first focusable element gets the\n * relationship.\n */\n children: React.ReactElement;\n /** Ref to the wrapper `<span>` (the positioning anchor). */\n ref?: React.Ref<HTMLSpanElement>;\n}\n\nconst VARIANT_APPEARANCE: Record<'dark' | 'light', TooltipAppearance> = {\n dark: 'inverted',\n light: 'normal',\n};\n\nconst appearanceClasses: Record<TooltipAppearance, string> = {\n inverted: 'border border-inverted-border bg-inverted text-inverted-foreground',\n normal: 'border border-border bg-background text-foreground',\n};\n\n/**\n * Transparent `::before` hover bridge across the 8px gap (the positioning offset) on the side that\n * faces the trigger only, so the pointer can move onto the tooltip; the other sides get no bridge,\n * which would otherwise catch hovers and clicks meant for neighbouring controls.\n */\nconst bridgeClasses = [\n 'before:absolute',\n // Tooltip above the trigger: a strip below it.\n 'data-[side=top]:before:inset-x-0 data-[side=top]:before:top-full data-[side=top]:before:h-2',\n // Tooltip below the trigger: a strip above it.\n 'data-[side=bottom]:before:inset-x-0 data-[side=bottom]:before:bottom-full data-[side=bottom]:before:h-2',\n // wave-allow-physical: data-side is the physical side resolved by the positioning\n 'data-[side=left]:before:inset-y-0 data-[side=left]:before:left-full data-[side=left]:before:w-2',\n // wave-allow-physical: data-side is the physical side resolved by the positioning\n 'data-[side=right]:before:inset-y-0 data-[side=right]:before:right-full data-[side=right]:before:w-2',\n].join(' ');\n\n/**\n * The visual surface: wrapping text, typography reset against the host (header cells, muted\n * panels), and the hover bridge towards the trigger.\n */\nconst surfaceClasses = `max-w-60 whitespace-normal break-words rounded px-3 py-1.5 text-caption-1 font-normal normal-case tracking-normal text-start shadow-8 ${bridgeClasses}`;\n\ntype UnknownProps = Record<string, unknown>;\ntype Relationship = NonNullable<TooltipProps['relationship']>;\n\nconst HANDLER_KEY = /^on[A-Z]/;\n\n/** Naming attributes a generic element such as the fallback `<span>` must not carry. */\nconst NAMING_ARIA = ['aria-label', 'aria-labelledby'] as const;\n\n/**\n * Whether an event reached the wrapper from its own DOM subtree — the child — rather than through\n * a portal: React bubbles events from portaled content (the tooltip surface, a popup the child\n * renders in a portal) through the component tree.\n */\nfunction isOwnEvent(event: React.SyntheticEvent): boolean {\n return (event.currentTarget as Node).contains(event.target as Node);\n}\n\n/** `handler`, called only for the wrapper's own events (see {@link isOwnEvent}). */\nfunction ownEventsOnly<E extends React.SyntheticEvent>(\n handler: (event: E) => void,\n): (event: E) => void {\n return (event) => {\n if (isOwnEvent(event)) handler(event);\n };\n}\n\n/**\n * Splits the props the Tooltip receives, from its consumer or from a parent that clones its child\n * (Menu.Trigger, Popover.Trigger, Dialog.Trigger, Field): `id` and `aria-*` describe the element\n * the Tooltip is attached to, so they go to the child; the rest stays on the wrapper `<span>`.\n */\nfunction splitProps(props: UnknownProps): { childProps: UnknownProps; wrapperProps: UnknownProps } {\n const childProps: UnknownProps = {};\n const wrapperProps: UnknownProps = {};\n for (const [key, value] of Object.entries(props)) {\n if (key === 'id' || key.startsWith('aria-')) childProps[key] = value;\n else if (HANDLER_KEY.test(key) && typeof value === 'function') {\n // The wrapper sees the child's events as they bubble, but not those that reach it through\n // a portal, such as a click on the tooltip surface (it would toggle a parent trigger).\n wrapperProps[key] = ownEventsOnly(value as (event: React.SyntheticEvent) => void);\n } else wrapperProps[key] = value;\n }\n return { childProps, wrapperProps };\n}\n\nfunction omit(props: UnknownProps, keys: readonly string[]): UnknownProps {\n const result = { ...props };\n for (const key of keys) delete result[key];\n return result;\n}\n\nfunction hasIdRef(el: Element, attribute: string, id: string): boolean {\n return (el.getAttribute(attribute) ?? '').split(/\\s+/).includes(id);\n}\n\nfunction removeIdRef(el: Element, attribute: string, id: string): void {\n const rest = (el.getAttribute(attribute) ?? '')\n .split(/\\s+/)\n .filter((value) => value && value !== id);\n if (rest.length > 0) el.setAttribute(attribute, rest.join(' '));\n else el.removeAttribute(attribute);\n}\n\n/**\n * Makes sure the element people focus carries the tooltip relationship. After each commit, when no\n * focusable element inside the wrapper references `tooltipId` through `attribute` — children in the\n * fallback span, a non-focusable child element, or a child component that drops the prop (a\n * Popover or Dialog root) — the id is added to the first tabbable element inside the wrapper and\n * kept there while the subtree changes; a development warning explains the nesting, except for\n * the fallback span, whose children shape `renderTrigger` already warned about.\n */\nfunction useRelationshipTarget(\n wrapperRef: React.RefObject<HTMLSpanElement | null>,\n tooltipId: string,\n relationship: Relationship,\n childIsFallback: boolean,\n): void {\n const appliedRef = React.useRef<{ element: Element; attribute: string } | null>(null);\n const attribute = relationship === 'label' ? 'aria-labelledby' : 'aria-describedby';\n\n React.useLayoutEffect(() => {\n const wrapper = wrapperRef.current;\n if (!wrapper) return;\n\n const update = () => {\n const applied = appliedRef.current;\n const carriers = Array.from(wrapper.querySelectorAll(`[${attribute}]`)).filter(\n (el) =>\n !(applied && applied.element === el && applied.attribute === attribute) &&\n hasIdRef(el, attribute, tooltipId),\n );\n const reached = carriers.some((el) => el.matches(FOCUSABLE_SELECTOR));\n const target = reached ? null : getFirstTabbable(wrapper);\n if (applied && (applied.element !== target || applied.attribute !== attribute)) {\n removeIdRef(applied.element, applied.attribute, tooltipId);\n appliedRef.current = null;\n }\n if (!target) return;\n if (!hasIdRef(target, attribute, tooltipId)) {\n target.setAttribute(attribute, joinIds(target.getAttribute(attribute), tooltipId) ?? '');\n }\n appliedRef.current = { element: target, attribute };\n if (!childIsFallback) {\n warnOnce(\n 'Tooltip:focus-target',\n `Tooltip: the element that takes focus inside it did not get \\`${attribute}\\` (the child is not focusable, or is a component, such as a Popover or Dialog root, that does not pass the prop on), so it was added to the first focusable element inside. Put the Tooltip directly around the focusable element, e.g. <Popover.Trigger><Tooltip content=\"…\"><Button /></Tooltip></Popover.Trigger>.`,\n );\n }\n };\n\n update();\n if (!appliedRef.current || typeof MutationObserver === 'undefined') return;\n // Keep it on the focusable element when the child replaces it or rewrites the attribute\n // without the Tooltip re-rendering.\n const observer = new MutationObserver(update);\n observer.observe(wrapper, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: [attribute],\n });\n return () => observer.disconnect();\n });\n}\n\n/**\n * Shows a short text label or description for its child on hover and keyboard focus.\n *\n * - The text is always present as a hidden `role=\"tooltip\"` element referenced by the child's\n * `aria-describedby` (or `aria-labelledby` with `relationship=\"label\"`), so screen readers get\n * it on focus without waiting for the delay; the child's own ids are kept.\n * - The visual surface is rendered in a portal only while visible (it is `aria-hidden`, a copy of\n * the description), positioned on `side`/`align` with flipping and shifting to stay in view.\n * - It appears `openDelay` after the pointer rests on the child or the child takes keyboard focus,\n * stays visible while the pointer moves onto it, hides `closeDelay` after the pointer leaves or\n * immediately on blur, and Escape hides it without closing an enclosing dialog or popover. Focus\n * and hover inside a popup the child renders in a portal (a DatePicker calendar, a listbox) do\n * not show it, and the pointer moving onto such a popup hides it.\n * - The open state is uncontrolled by default (`defaultOpen`). With `open` and `onOpenChange`\n * (Fluent's `visible` and `onVisibleChange`) the parent owns it: hover, focus, leave, blur and\n * Escape then only ask for a change, and `open` alone shows the surface.\n * - `id` and `aria-*` props given to the Tooltip go to its child, merged with the child's own (the\n * child's `id` wins, id lists are joined, `aria-expanded`/`aria-controls`/`aria-haspopup` from\n * the Tooltip win). `className`, `style`, `ref`, `data-*` and event handlers stay on the wrapper\n * `<span>`; the handlers see the child's events as they bubble, not events from portaled\n * content such as the tooltip surface or a popup the child renders in a portal (a DatePicker\n * calendar, a listbox). `onMouseEnter` and `onMouseLeave` are the exception: React fires them\n * along the component tree, so they also fire when the pointer moves onto or off the tooltip\n * surface or such a popup. So the Tooltip can sit inside a trigger, and the trigger's\n * id and state reach the button: `<Menu.Trigger><Tooltip content=\"…\"><Button /></Tooltip>\n * </Menu.Trigger>` (also `Popover.Trigger`, `Dialog.Trigger`, `Drawer.Trigger`). Around a\n * trigger works too, since triggers pass `aria-describedby` on to their child.\n * - Wrap the focusable element itself. When the element that takes focus does not get the\n * relationship (a Popover or Dialog root, a component that drops props, a non-focusable\n * wrapper element), it is added to the first focusable element inside, with a development\n * warning.\n *\n * @example\n * <Menu>\n * <Menu.Trigger>\n * <Tooltip content=\"Edit, duplicate or delete the item\">\n * <Button>Actions</Button>\n * </Tooltip>\n * </Menu.Trigger>\n * <Menu.Popover>…</Menu.Popover>\n * </Menu>\n */\nexport const Tooltip = ({\n content,\n appearance: appearanceProp,\n variant,\n openDelay: openDelayProp,\n closeDelay = 100,\n delay,\n open: openProp,\n defaultOpen,\n onOpenChange,\n relationship = 'description',\n side = 'top',\n align = 'center',\n positioning,\n children,\n className,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n ref,\n ...rest\n}: TooltipProps) => {\n const appearance =\n resolveDeprecatedProp(\n 'Tooltip',\n appearanceProp,\n variant === undefined ? undefined : VARIANT_APPEARANCE[variant],\n 'variant',\n 'appearance',\n ) ?? 'inverted';\n const openDelay =\n resolveDeprecatedProp('Tooltip', openDelayProp, delay, 'delay', 'openDelay') ?? 200;\n const [open, setOpen] = useControllable(openProp, defaultOpen ?? false, onOpenChange);\n // The surface lives in a portal, which renders only in the browser: until then (the server HTML,\n // hydration) the tooltip is closed; the hidden description is rendered either way.\n const isClient = useIsClient();\n const visible = open && isClient;\n const timerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const wrapperRef = React.useRef<HTMLSpanElement | null>(null);\n const surfaceRef = React.useRef<HTMLSpanElement | null>(null);\n const tooltipId = useId('tooltip');\n\n // Destructured: react-hooks/refs treats an object whose member is passed to `ref` as a ref.\n const { setReference, setFloating, floatingProps } = usePopupPosition({\n open: visible,\n side,\n align,\n ...resolvePositioning(positioning, { offset: 8 }),\n });\n const wrapperElementRef = useMergedRefs<HTMLSpanElement>(ref, wrapperRef, setReference);\n const surfaceElementRef = useMergedRefs<HTMLSpanElement>(surfaceRef, setFloating);\n\n // Timer handlers are event callbacks (stable, latest state): they are composed with the\n // consumer's handlers during render but only run from events and timers.\n const clearTimer = useEventCallback(() => {\n if (timerRef.current !== undefined) {\n clearTimeout(timerRef.current);\n timerRef.current = undefined;\n }\n });\n\n // show, hide and scheduleHide ask for the new state; a controlled tooltip changes only when the\n // parent updates `open`.\n const show = useEventCallback(() => {\n clearTimer();\n if (visible) return;\n if (openDelay <= 0) {\n setOpen(true);\n return;\n }\n timerRef.current = setTimeout(() => {\n timerRef.current = undefined;\n setOpen(true);\n }, openDelay);\n });\n\n const hide = useEventCallback(() => {\n clearTimer();\n setOpen(false);\n });\n\n // The grace period after the pointer leaves lets it move onto the tooltip.\n const scheduleHide = useEventCallback(() => {\n clearTimer();\n if (!visible) return;\n timerRef.current = setTimeout(() => {\n timerRef.current = undefined;\n setOpen(false);\n }, closeDelay);\n });\n\n // An Escape-only layer while visible: Escape hides the tooltip before any enclosing overlay. The\n // wrapper is its anchor (its trigger, not its surface): Tab from the child inside a focus trap\n // moves on from the popover, portal or dialog around the wrapper.\n useDismiss({\n open: visible,\n onDismiss: hide,\n refs: [wrapperRef, surfaceRef],\n anchorRef: wrapperRef,\n kind: 'tooltip',\n outsidePress: false,\n });\n\n React.useEffect(() => {\n const timer = timerRef;\n return () => clearTimeout(timer.current);\n }, []);\n\n // The tooltip's own reactions ignore a popup the child renders in a portal: its focus and blur\n // are not the child's, entering it does not show the tooltip, and the pointer moving onto it\n // (no mouseleave reaches the wrapper then) hides the tooltip, which would cover it. The tooltip\n // surface itself is portaled too but belongs to the tooltip: it stays hoverable.\n const showOnEnter = useEventCallback((event: React.MouseEvent<HTMLSpanElement>) => {\n if (isOwnEvent(event) || surfaceRef.current?.contains(event.target as Node)) show();\n });\n const hideOverPortaledPopup = useEventCallback((event: React.MouseEvent<HTMLSpanElement>) => {\n if (!isOwnEvent(event) && !surfaceRef.current?.contains(event.target as Node)) hide();\n });\n\n const { childProps, wrapperProps } = splitProps(rest);\n const target = unwrapFragment(children);\n const childIsFallback = !isCloneableElement(target);\n const attribute = relationship === 'label' ? 'aria-labelledby' : 'aria-describedby';\n // Props given to the Tooltip come first, as if the child had them; then the tooltip's own id.\n // The fallback span is a generic element: no state ARIA and no naming on it (the relationship\n // then reaches its first focusable element through useRelationshipTarget).\n const triggerProps: UnknownProps = childIsFallback\n ? omit(childProps, [...STATE_ARIA, ...NAMING_ARIA])\n : { ...childProps };\n if (!childIsFallback || relationship === 'description') {\n triggerProps[attribute] = joinIds(childProps[attribute] as string | undefined, tooltipId);\n }\n const child = renderTrigger(target, triggerProps, { componentName: 'Tooltip' });\n useRelationshipTarget(wrapperRef, tooltipId, relationship, childIsFallback);\n\n return (\n <span\n ref={wrapperElementRef}\n {...wrapperProps}\n className={cn(tooltipClassNames.root, 'inline-block', className)}\n onMouseEnter={composeEventHandlers(onMouseEnter, showOnEnter)}\n onMouseLeave={composeEventHandlers(onMouseLeave, scheduleHide)}\n onMouseOver={composeEventHandlers(\n wrapperProps.onMouseOver as React.MouseEventHandler<HTMLSpanElement> | undefined,\n hideOverPortaledPopup,\n )}\n onFocus={ownEventsOnly(composeEventHandlers(onFocus, show))}\n onBlur={ownEventsOnly(composeEventHandlers(onBlur, hide))}\n >\n {child}\n <span id={tooltipId} role=\"tooltip\" hidden>\n {content}\n </span>\n {visible && (\n <Portal layer=\"tooltip\">\n <span\n ref={surfaceElementRef}\n aria-hidden=\"true\"\n data-wave-tooltip-surface=\"\"\n {...floatingProps}\n className={cn(tooltipClassNames.content, surfaceClasses, appearanceClasses[appearance])}\n >\n {content}\n </span>\n </Portal>\n )}\n </span>\n );\n};\n\nTooltip.displayName = 'Tooltip';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4GA,IAAMG,KAAkE;CACtE,MAAM;CACN,OAAO;AACT,GAEMC,KAAuD;CAC3D,UAAU;CACV,QAAQ;AACV,GAuBMC,KAAiB,yIAhBD;CACpB;CAEA;CAEA;CAEA;CAEA;AACF,CAAC,CAAC,KAAK,GAMyJ,KAK1JC,IAAc,YAGdC,KAAc,CAAC,cAA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,OAAM;IACZ,UAAA,kBAAC,QAAD;KACE,KAAK5B;KACL,eAAY;KACZ,6BAA0B;KAC1B,GAAI6B;KACJ,WAAWV,EAAGC,EAAkB,SAASnF,IAAgBD,GAAkB0C,EAAW;KAErF,UAAAiD;IACG,CAAA;GACA,CAAA;EAEN;;AAEV;AAEA,EAAQ,cAAc"}
@@ -1,2 +1,2 @@
1
- "use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/classNames.cjs"),r=require("../../hooks/useMergedRefs.cjs"),i=require("../../hooks/useIsClient.cjs"),a=require("../provider/WaveProvider.cjs"),o=require("../../lib/layers.cjs"),s=require("../../hooks/useDirection.cjs"),c=require("../../hooks/useDismiss.cjs");let l=require("react");l=e.__toESM(l,1);let u=require("react/jsx-runtime"),d=require("react-dom");var f=l.createContext(0);f.displayName=`PortalDepthContext`;var p=({children:e,container:p,layer:m=`overlay`,layerId:h,disabled:g=!1,className:_,ref:v})=>{let y=i.useIsClient(),{themeClassName:b,portalContainer:x}=a.useWaveTheme(),S=s.useDirection(),C=l.useContext(f),w=l.useContext(c.DismissLayerContext),T=l.useCallback(e=>{if(e&&w!==null)return o.registerLayerElement(w,e)},[w]),E=r.useMergedRefs(v,T),D=h===void 0?e:(0,u.jsx)(c.DismissLayerProvider,{layerId:h,children:e});if(g)return(0,u.jsx)(u.Fragment,{children:D});if(!y)return null;let O=p??x??document.body;return(0,d.createPortal)((0,u.jsx)(`div`,{ref:E,className:t.cn(n.portalClassNames.root,b,_),dir:S,"data-wave-portal":``,"data-layer":m,style:{position:`relative`,zIndex:`calc(${o.Z_INDEX[m]} + ${C})`},children:(0,u.jsx)(f.Provider,{value:C+1,children:D})}),O)};p.displayName=`Portal`,exports.Portal=p,exports.PortalDepthContext=f;
1
+ "use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/classNames.cjs"),r=require("../../hooks/useMergedRefs.cjs"),i=require("../../hooks/useIsClient.cjs"),a=require("../provider/WaveProvider.cjs"),o=require("../../hooks/useDirection.cjs"),s=require("../../lib/layers.cjs"),c=require("../../hooks/useDismiss.cjs");let l=require("react");l=e.__toESM(l,1);let u=require("react/jsx-runtime"),d=require("react-dom");var f=l.createContext(0);f.displayName=`PortalDepthContext`;var p=({children:e,container:p,layer:m=`overlay`,layerId:h,disabled:g=!1,className:_,ref:v})=>{let y=i.useIsClient(),{themeClassName:b,portalContainer:x}=a.useWaveTheme(),S=o.useDirection(),C=l.useContext(f),w=l.useContext(c.DismissLayerContext),T=l.useCallback(e=>{if(e&&w!==null)return s.registerLayerElement(w,e)},[w]),E=r.useMergedRefs(v,T),D=h===void 0?e:(0,u.jsx)(c.DismissLayerProvider,{layerId:h,children:e});if(g)return(0,u.jsx)(u.Fragment,{children:D});if(!y)return null;let O=p??x??document.body;return(0,d.createPortal)((0,u.jsx)(`div`,{ref:E,className:t.cn(n.portalClassNames.root,b,_),dir:S,"data-wave-portal":``,"data-layer":m,style:{position:`relative`,zIndex:`calc(${s.Z_INDEX[m]} + ${C})`},children:(0,u.jsx)(f.Provider,{value:C+1,children:D})}),O)};p.displayName=`Portal`,exports.Portal=p,exports.PortalDepthContext=f;
2
2
  //# sourceMappingURL=Portal.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Portal.cjs","names":["React","useIsClient","useWaveTheme","useDirection","DismissLayerContext","registerLayerElement","useMergedRefs","DismissLayerProvider","_Fragment","createPortal","cn","portalClassNames","Z_INDEX","require_runtime","require_cn","require_classNames","require_useMergedRefs","require_useIsClient","require_WaveProvider","require_layers","require_useDirection","require_useDismiss","react","react_jsx_runtime","react_dom","PortalDepthContext","Portal","isClient","dir","depth","parentLayerId","registerWithParent","el","wrapperRef","ref","content","layerId","children","disabled","target","container","portalContainer","themeClassName","className","layer"],"sources":["../../../src/components/portal/Portal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../lib/cn';\nimport { portalClassNames } from '../../lib/classNames';\nimport { Z_INDEX, registerLayerElement } from '../../lib/layers';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useDirection } from '../../hooks/useDirection';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { DismissLayerContext, DismissLayerProvider } from '../../hooks/useDismiss';\nimport { useWaveTheme } from '../provider/WaveProvider';\n\n/** Props accepted by {@link Portal}. */\nexport interface PortalProps {\n /** Content rendered into the portal. */\n children: React.ReactNode;\n /** Element to render into. @default WaveProvider `portalContainer`, else `document.body` */\n container?: HTMLElement | null;\n /**\n * Stacking layer: `--wave-z-overlay` (dialogs, popovers, menus, listboxes), `--wave-z-toast`\n * (above overlays) or `--wave-z-tooltip`. The portal's nesting depth is added.\n * @default 'overlay'\n */\n layer?: 'overlay' | 'toast' | 'tooltip';\n /**\n * The dismiss layer of the content (from `useDismiss`). Provided to the children through\n * `DismissLayerProvider`, so layers opened inside become its descendants.\n */\n layerId?: string;\n /** Render the children inline instead (no portal, no wrapper). @default false */\n disabled?: boolean;\n /** Extra classes for the portal wrapper. */\n className?: string;\n /** Ref to the portal wrapper `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/**\n * Nesting depth of portals: `0` outside any portal; each `Portal` provides `depth + 1` to its\n * children. Portals add it to their z-index so a surface opened from inside another overlay always\n * stacks above it — also when both mount in the same commit.\n */\nexport const PortalDepthContext = React.createContext(0);\nPortalDepthContext.displayName = 'PortalDepthContext';\n\n/**\n * Renders its children into `document.body` (or the WaveProvider `portalContainer`), wrapped in a\n * `<div class=\"wave-portal …\">` that carries the provider's theme classes, direction and font, so\n * portaled overlays look like the rest of the themed tree. The wrapper paints no background.\n *\n * - **Client only, first commit**: nothing is rendered on the server or during hydration (no\n * mismatch); in every other client render the portal exists in the first commit, so layout\n * effects and ref callbacks of the content see connected elements.\n * - **Stacking**: `z-index: calc(<layer variable> + depth)`, where depth is the number of portals\n * it is rendered in, so a surface opened from inside another overlay always stacks above it,\n * also when both mount in the same commit.\n * - **Layers**: the wrapper is registered with the enclosing dismiss layer (the parent), so presses\n * and focus inside the portal count as inside that layer; `layerId` is provided only to the\n * children.\n *\n * Content that must exist on the server or before an overlay opens (tooltip descriptions, closed\n * listboxes) is rendered inline instead.\n */\nexport const Portal = ({\n children,\n container,\n layer = 'overlay',\n layerId,\n disabled = false,\n className,\n ref,\n}: PortalProps) => {\n const isClient = useIsClient();\n const { themeClassName, portalContainer } = useWaveTheme();\n const dir = useDirection();\n const depth = React.useContext(PortalDepthContext);\n const parentLayerId = React.useContext(DismissLayerContext);\n\n const registerWithParent = React.useCallback(\n (el: HTMLDivElement | null) => {\n if (!el || parentLayerId === null) return;\n return registerLayerElement(parentLayerId, el);\n },\n [parentLayerId],\n );\n const wrapperRef = useMergedRefs<HTMLDivElement>(ref, registerWithParent);\n\n const content =\n layerId === undefined ? (\n children\n ) : (\n <DismissLayerProvider layerId={layerId}>{children}</DismissLayerProvider>\n );\n\n if (disabled) return <>{content}</>;\n if (!isClient) return null;\n\n const target = container ?? portalContainer ?? document.body;\n\n return createPortal(\n <div\n ref={wrapperRef}\n className={cn(portalClassNames.root, themeClassName, className)}\n dir={dir}\n data-wave-portal=\"\"\n data-layer={layer}\n style={{ position: 'relative', zIndex: `calc(${Z_INDEX[layer]} + ${depth})` }}\n >\n <PortalDepthContext.Provider value={depth + 1}>{content}</PortalDepthContext.Provider>\n </div>,\n target,\n );\n};\n\nPortal.displayName = 'Portal';\n"],"mappings":"6dAyCA,IAAayB,EAAqBzB,EAAM,cAAc,CAAC,EACvD,EAAmB,YAAc,qBAoBjC,IAAa0B,GAAU,CACrB,WACA,YACA,QAAQ,UACR,UACA,WAAW,GACX,YACA,SACiB,CACjB,IAAMC,EAAW1B,EAAAA,YAAY,EACvB,CAAE,iBAAgB,mBAAoBC,EAAAA,aAAa,EACnD0B,EAAMzB,EAAAA,aAAa,EACnB0B,EAAQ7B,EAAM,WAAWyB,CAAkB,EAC3CK,EAAgB9B,EAAM,WAAWI,EAAAA,mBAAmB,EAEpD2B,EAAqB/B,EAAM,YAC9B,GAA8B,CAC7B,GAAKgC,GAAMF,IAAkB,KAC7B,OAAOzB,EAAAA,qBAAqByB,EAAeE,CAAE,CAC/C,EACA,CAACF,CAAa,CAChB,EACMG,EAAa3B,EAAAA,cAA8B4B,EAAKH,CAAkB,EAElEI,EACJC,IAAY,IAAA,GACVC,GAEA,EAAAd,EAAA,IAAA,CAAChB,EAAAA,qBAAD,CAA+B,UAAU,UAA+B,CAAA,EAG5E,GAAI+B,EAAU,OAAO,EAAAf,EAAA,IAAA,CAAAf,EAAAA,SAAA,CAAA,SAAG2B,CAAU,CAAA,EAClC,GAAI,CAACR,EAAU,OAAO,KAEtB,IAAMY,EAASC,GAAaC,GAAmB,SAAS,KAExD,OAAA,EAAOhC,EAAAA,aAAAA,EACL,EAAAc,EAAA,IAAA,CAAC,MAAD,CACE,IAAKU,EACL,UAAWvB,EAAAA,GAAGC,EAAAA,iBAAiB,KAAM+B,EAAgBC,CAAS,EACzD,MACL,mBAAiB,GACjB,aAAYC,EACZ,MAAO,CAAE,SAAU,WAAY,OAAQ,QAAQhC,EAAAA,QAAQgC,GAAO,KAAKf,EAAM,EAAG,EAE5E,UAAA,EAAAN,EAAA,IAAA,CAACE,EAAmB,SAApB,CAA6B,MAAOI,EAAQ,EAAI,SAAAM,CAAqC,CAAA,CAClF,CAAA,EACLI,CACF,CACF,EAEA,EAAO,YAAc"}
1
+ {"version":3,"file":"Portal.cjs","names":["React","useIsClient","useWaveTheme","useDirection","DismissLayerContext","registerLayerElement","useMergedRefs","DismissLayerProvider","_Fragment","createPortal","cn","portalClassNames","Z_INDEX","require_runtime","require_cn","require_classNames","require_useMergedRefs","require_useIsClient","require_WaveProvider","require_useDirection","require_layers","require_useDismiss","react","react_jsx_runtime","react_dom","PortalDepthContext","Portal","isClient","dir","depth","parentLayerId","registerWithParent","el","wrapperRef","ref","content","layerId","children","disabled","target","container","portalContainer","themeClassName","className","layer"],"sources":["../../../src/components/portal/Portal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../lib/cn';\nimport { portalClassNames } from '../../lib/classNames';\nimport { Z_INDEX, registerLayerElement } from '../../lib/layers';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useDirection } from '../../hooks/useDirection';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { DismissLayerContext, DismissLayerProvider } from '../../hooks/useDismiss';\nimport { useWaveTheme } from '../provider/WaveProvider';\n\n/** Props accepted by {@link Portal}. */\nexport interface PortalProps {\n /** Content rendered into the portal. */\n children: React.ReactNode;\n /** Element to render into. @default WaveProvider `portalContainer`, else `document.body` */\n container?: HTMLElement | null;\n /**\n * Stacking layer: `--wave-z-overlay` (dialogs, popovers, menus, listboxes), `--wave-z-toast`\n * (above overlays) or `--wave-z-tooltip`. The portal's nesting depth is added.\n * @default 'overlay'\n */\n layer?: 'overlay' | 'toast' | 'tooltip';\n /**\n * The dismiss layer of the content (from `useDismiss`). Provided to the children through\n * `DismissLayerProvider`, so layers opened inside become its descendants.\n */\n layerId?: string;\n /** Render the children inline instead (no portal, no wrapper). @default false */\n disabled?: boolean;\n /** Extra classes for the portal wrapper. */\n className?: string;\n /** Ref to the portal wrapper `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/**\n * Nesting depth of portals: `0` outside any portal; each `Portal` provides `depth + 1` to its\n * children. Portals add it to their z-index so a surface opened from inside another overlay always\n * stacks above it — also when both mount in the same commit.\n */\nexport const PortalDepthContext = React.createContext(0);\nPortalDepthContext.displayName = 'PortalDepthContext';\n\n/**\n * Renders its children into `document.body` (or the WaveProvider `portalContainer`), wrapped in a\n * `<div class=\"wave-portal …\">` that carries the provider's theme classes, direction and font, so\n * portaled overlays look like the rest of the themed tree. The wrapper paints no background.\n *\n * - **Client only, first commit**: nothing is rendered on the server or during hydration (no\n * mismatch); in every other client render the portal exists in the first commit, so layout\n * effects and ref callbacks of the content see connected elements.\n * - **Stacking**: `z-index: calc(<layer variable> + depth)`, where depth is the number of portals\n * it is rendered in, so a surface opened from inside another overlay always stacks above it,\n * also when both mount in the same commit.\n * - **Layers**: the wrapper is registered with the enclosing dismiss layer (the parent), so presses\n * and focus inside the portal count as inside that layer; `layerId` is provided only to the\n * children.\n *\n * Content that must exist on the server or before an overlay opens (tooltip descriptions, closed\n * listboxes) is rendered inline instead.\n */\nexport const Portal = ({\n children,\n container,\n layer = 'overlay',\n layerId,\n disabled = false,\n className,\n ref,\n}: PortalProps) => {\n const isClient = useIsClient();\n const { themeClassName, portalContainer } = useWaveTheme();\n const dir = useDirection();\n const depth = React.useContext(PortalDepthContext);\n const parentLayerId = React.useContext(DismissLayerContext);\n\n const registerWithParent = React.useCallback(\n (el: HTMLDivElement | null) => {\n if (!el || parentLayerId === null) return;\n return registerLayerElement(parentLayerId, el);\n },\n [parentLayerId],\n );\n const wrapperRef = useMergedRefs<HTMLDivElement>(ref, registerWithParent);\n\n const content =\n layerId === undefined ? (\n children\n ) : (\n <DismissLayerProvider layerId={layerId}>{children}</DismissLayerProvider>\n );\n\n if (disabled) return <>{content}</>;\n if (!isClient) return null;\n\n const target = container ?? portalContainer ?? document.body;\n\n return createPortal(\n <div\n ref={wrapperRef}\n className={cn(portalClassNames.root, themeClassName, className)}\n dir={dir}\n data-wave-portal=\"\"\n data-layer={layer}\n style={{ position: 'relative', zIndex: `calc(${Z_INDEX[layer]} + ${depth})` }}\n >\n <PortalDepthContext.Provider value={depth + 1}>{content}</PortalDepthContext.Provider>\n </div>,\n target,\n );\n};\n\nPortal.displayName = 'Portal';\n"],"mappings":"6dAyCA,IAAayB,EAAqBzB,EAAM,cAAc,CAAC,EACvD,EAAmB,YAAc,qBAoBjC,IAAa0B,GAAU,CACrB,WACA,YACA,QAAQ,UACR,UACA,WAAW,GACX,YACA,SACiB,CACjB,IAAMC,EAAW1B,EAAAA,YAAY,EACvB,CAAE,iBAAgB,mBAAoBC,EAAAA,aAAa,EACnD0B,EAAMzB,EAAAA,aAAa,EACnB0B,EAAQ7B,EAAM,WAAWyB,CAAkB,EAC3CK,EAAgB9B,EAAM,WAAWI,EAAAA,mBAAmB,EAEpD2B,EAAqB/B,EAAM,YAC9B,GAA8B,CAC7B,GAAKgC,GAAMF,IAAkB,KAC7B,OAAOzB,EAAAA,qBAAqByB,EAAeE,CAAE,CAC/C,EACA,CAACF,CAAa,CAChB,EACMG,EAAa3B,EAAAA,cAA8B4B,EAAKH,CAAkB,EAElEI,EACJC,IAAY,IAAA,GACVC,GAEA,EAAAd,EAAA,IAAA,CAAChB,EAAAA,qBAAD,CAA+B,UAAU,UAA+B,CAAA,EAG5E,GAAI+B,EAAU,OAAO,EAAAf,EAAA,IAAA,CAAAf,EAAAA,SAAA,CAAA,SAAG2B,CAAU,CAAA,EAClC,GAAI,CAACR,EAAU,OAAO,KAEtB,IAAMY,EAASC,GAAaC,GAAmB,SAAS,KAExD,OAAA,EAAOhC,EAAAA,aAAAA,EACL,EAAAc,EAAA,IAAA,CAAC,MAAD,CACE,IAAKU,EACL,UAAWvB,EAAAA,GAAGC,EAAAA,iBAAiB,KAAM+B,EAAgBC,CAAS,EACzD,MACL,mBAAiB,GACjB,aAAYC,EACZ,MAAO,CAAE,SAAU,WAAY,OAAQ,QAAQhC,EAAAA,QAAQgC,GAAO,KAAKf,EAAM,EAAG,EAE5E,UAAA,EAAAN,EAAA,IAAA,CAACE,EAAmB,SAApB,CAA6B,MAAOI,EAAQ,EAAI,SAAAM,CAAqC,CAAA,CAClF,CAAA,EACLI,CACF,CACF,EAEA,EAAO,YAAc"}
@@ -4,8 +4,8 @@ import { portalClassNames as t } from "../../lib/classNames.mjs";
4
4
  import { useMergedRefs as n } from "../../hooks/useMergedRefs.mjs";
5
5
  import { useIsClient as r } from "../../hooks/useIsClient.mjs";
6
6
  import { useWaveTheme as i } from "../provider/WaveProvider.mjs";
7
- import { Z_INDEX as a, registerLayerElement as o } from "../../lib/layers.mjs";
8
- import { useDirection as s } from "../../hooks/useDirection.mjs";
7
+ import { useDirection as a } from "../../hooks/useDirection.mjs";
8
+ import { Z_INDEX as o, registerLayerElement as s } from "../../lib/layers.mjs";
9
9
  import { DismissLayerContext as c, DismissLayerProvider as l } from "../../hooks/useDismiss.mjs";
10
10
  import * as u from "react";
11
11
  import { Fragment as d, jsx as f } from "react/jsx-runtime";
@@ -14,8 +14,8 @@ import { createPortal as p } from "react-dom";
14
14
  var m = u.createContext(0);
15
15
  m.displayName = "PortalDepthContext";
16
16
  var h = ({ children: h, container: g, layer: _ = "overlay", layerId: v, disabled: y = !1, className: b, ref: x }) => {
17
- let S = r(), { themeClassName: C, portalContainer: w } = i(), T = s(), E = u.useContext(m), D = u.useContext(c), O = u.useCallback((e) => {
18
- if (e && D !== null) return o(D, e);
17
+ let S = r(), { themeClassName: C, portalContainer: w } = i(), T = a(), E = u.useContext(m), D = u.useContext(c), O = u.useCallback((e) => {
18
+ if (e && D !== null) return s(D, e);
19
19
  }, [D]), k = n(x, O), A = v === void 0 ? h : /* @__PURE__ */ f(l, {
20
20
  layerId: v,
21
21
  children: h
@@ -31,7 +31,7 @@ var h = ({ children: h, container: g, layer: _ = "overlay", layerId: v, disabled
31
31
  "data-layer": _,
32
32
  style: {
33
33
  position: "relative",
34
- zIndex: `calc(${a[_]} + ${E})`
34
+ zIndex: `calc(${o[_]} + ${E})`
35
35
  },
36
36
  children: /* @__PURE__ */ f(m.Provider, {
37
37
  value: E + 1,
@@ -1,2 +1,2 @@
1
- "use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/children.cjs"),r=require("../../lib/dev.cjs"),i=require("../../lib/composeEventHandlers.cjs"),a=require("../../lib/classNames.cjs"),o=require("../../hooks/useControllable.cjs"),s=require("../../hooks/useId.cjs"),c=require("../../hooks/useMergedRefs.cjs"),l=require("../../lib/styles.cjs"),u=require("./useGridNavigation.cjs");let d=require("react");d=e.__toESM(d,1);let f=require("react/jsx-runtime");var p=`Select all rows`,m=`Selection`;function h(e,t=!1){let n=new Set(e),r=new Map,i=0,a=`none`,o=t,s,c=new Set,l=new Set,u=e=>{for(let t of Array.from(e))t()},d=()=>{if(s!==void 0)return s;let e=null;for(let t of n){if(r.has(t)){e=t;break}e??=t}return s=e,e},f=e=>{if(n.size<2||!n.has(e))return;let t=s;s=void 0,o&&d()!==t&&u(c)},p=()=>{let e=i===0?`none`:i===r.size?`all`:`some`;e!==a&&(a=e,u(l))},m=e=>t=>(e.add(t),()=>{e.delete(t)});return{subscribe:m(c),subscribeSelectAll:m(l),register(e){let t=r.get(e)??0;r.set(e,t+1),t===0&&n.has(e)&&(i+=1),p(),t===0&&f(e);let a=!1;return()=>{if(a)return;a=!0;let t=(r.get(e)??0)-1;if(t>0){r.set(e,t);return}r.delete(e),n.has(e)&&--i,p(),f(e)}},setSelected(e){let t=new Set(e);if(!(t.size===n.size&&e.every(e=>n.has(e)))){n=t,s=void 0,i=0;for(let e of t)r.has(e)&&(i+=1);u(c),p()}},setSingleMode(e){o=e},isSelected(e,t=!1){return t?d()===e:n.has(e)},countRegistrations(e){return r.get(e)??0},getSelectAllState(){return a},getRegistered(){return Array.from(r.keys())},prune(e){return e.filter(e=>r.has(e))}}}function g(){let e=new Map,t=new Set,n=null,r=()=>{let r=null,i=null;for(let[t,a]of e){let o=a();if(!o){if(n!==null&&e.has(n))return;continue}(!i||o.compareDocumentPosition(i)&Node.DOCUMENT_POSITION_FOLLOWING)&&(r=t,i=o)}if(r===null&&(r=e.keys().next().value??null),r!==n){n=r;for(let e of Array.from(t))e()}};return{subscribe(e){return t.add(e),()=>{t.delete(e)}},register(t,n){return e.set(t,n),r(),()=>{e.delete(t),r()}},getFirst:()=>n,refresh:r}}var _=d.createContext(null),v=d.createContext(null),y=d.createContext(`body`),b=d.createContext(null),x=d.createContext(!0),S={selectionMode:`none`,store:h([]),toggleRow:()=>{},toggleAll:()=>{},radioName:``,selectAllLabel:p,selectionHeaderLabel:m},C={sort:null,requestSort:()=>{}};function w(e){return d.useContext(_)||(r.reportMissingContext(e,`DataGrid`),S)}function T(e){return d.useContext(v)||(r.reportMissingContext(e,`DataGrid`),C)}var E=[];function D(e){return e===void 0?void 0:Array.from(e)}function O(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function k({key:e,node:t}){return(0,f.jsx)(d.Fragment,{children:t},e)}function ee(e){r.warnOnce(`DataGrid:duplicate-rowId:${e}`,`DataGrid: several rows share the rowId "${e}". Row ids must be unique within a DataGrid; rows with the same rowId are selected and deselected together.`)}var A=`px-4 py-3 border-b border-border`,j=`w-10 px-3 py-3 border-b border-border`,M=`accent-primary cursor-pointer`,N=e=>{let{sort:l,defaultSort:g,sortColumn:y,defaultSortColumn:b,sortDirection:x,defaultSortDirection:S,onSortChange:C,selectionMode:w=`none`,selectedItems:T,defaultSelectedItems:ee,onSelectedItemsChange:A,selectedKeys:j,defaultSelectedKeys:M,onSelectionChange:N,labels:P,columns:F,containerProps:I,children:L,className:z,onKeyDown:V,onFocus:H,onBlur:U,ref:te,...ne}=e,W=l!==void 0||g!==void 0,[re,ie]=d.useState(W);W&&!re&&ie(!0);let ae=re||W,oe=y!==void 0||x!==void 0;y!==void 0&&r.warnDeprecated(`DataGrid`,`sortColumn`,`sort`),x!==void 0&&r.warnDeprecated(`DataGrid`,`sortDirection`,`sort`),b!==void 0&&r.warnDeprecated(`DataGrid`,`defaultSortColumn`,`defaultSort`),S!==void 0&&r.warnDeprecated(`DataGrid`,`defaultSortDirection`,`defaultSort`);let se=W&&(oe||b!==void 0||S!==void 0);d.useEffect(()=>{se&&r.warnOnce(`DataGrid:mixed-sort`,"DataGrid: do not mix `sort`/`defaultSort` with the deprecated `sortColumn`/`sortDirection`/`defaultSortColumn`/`defaultSortDirection`. `sort`/`defaultSort` win.")},[se]),d.useEffect(()=>{W||(y!==void 0&&x===void 0?r.warnOnce(`DataGrid:sortColumn-without-sortDirection`,"DataGrid: `sortColumn` is controlled but `sortDirection` is not (mixed control). The direction is kept internally and toggles on repeated clicks, as in 0.4. Pass `sort` (`{ columnId, direction }`) to control both."):x!==void 0&&y===void 0&&r.warnOnce(`DataGrid:sortDirection-without-sortColumn`,"DataGrid: `sortDirection` is controlled but `sortColumn` is not (mixed control). The column is kept internally and follows the clicked header, as in 0.4. Pass `sort` (`{ columnId, direction }`) to control both."))},[W,y,x]);let[G,ce]=d.useState(()=>({column:b??``,direction:S??`ascending`})),le=d.useMemo(()=>{if(y===void 0&&x===void 0)return;let e=y??G.column;return e===``?null:{columnId:e,direction:x??G.direction}},[y,x,G]),ue=d.useMemo(()=>b?{columnId:b,direction:S??`ascending`}:null,[b,S]),de=W?l:le,fe=g===void 0?ue:g,[pe,me]=o.useControllable(de,fe,e=>{e&&(W||ce(t=>t.column===e.columnId&&t.direction===e.direction?t:{column:e.columnId,direction:e.direction}),C&&(ae?C(e):C(e.columnId,e.direction)))}),he=d.useCallback(e=>{me(t=>({columnId:e,direction:t?.columnId===e&&t.direction===`ascending`?`descending`:`ascending`}))},[me]),ge=d.useMemo(()=>({sort:pe,requestSort:he}),[pe,he]);N!==void 0&&r.warnDeprecated(`DataGrid`,`onSelectionChange`,`onSelectedItemsChange`);let _e=d.useMemo(()=>D(j),[j]),ve=d.useMemo(()=>D(M),[M]),ye=r.resolveDeprecatedProp(`DataGrid`,T,_e,`selectedKeys`,`selectedItems`),be=r.resolveDeprecatedProp(`DataGrid`,ee,ve,`defaultSelectedKeys`,`defaultSelectedItems`)??E,[K,q]=o.useControllable(ye,be,e=>{A?.([...e]),N?.(new Set(e))}),J=w===`single`,[Y]=d.useState(()=>h(K,J));d.useLayoutEffect(()=>{Y.setSelected(K)},[Y,K]),d.useLayoutEffect(()=>{Y.setSingleMode(J)},[Y,J]);let xe=d.useCallback(e=>{q(t=>{let n=Y.prune(t),r;return r=J?n[0]===e?[]:[e]:n.includes(e)?n.filter(t=>t!==e):[...n,e],O(r,t)?t:r})},[J,q,Y]),X=K.length;d.useEffect(()=>{J&&X>1&&r.warnOnce(`DataGrid:single-several-selected`,`DataGrid: a single-selection grid (selectionMode "single") has ${X} selected row ids; only the first one that is rendered is selected. Pass at most one id in \`selectedItems\`/\`defaultSelectedItems\`, or use selectionMode="multiple".`)},[J,X]);let Se=d.useCallback(()=>{q(e=>{let t=Y.prune(e),n=Y.getRegistered(),r=n.length>0&&n.every(e=>t.includes(e))?[]:n;return O(r,e)?e:r})},[q,Y]),Ce=s.useId(`wave-datagrid-selection`),we=P?.selectAll??p,Te=P?.selectionHeader??m,Ee=d.useMemo(()=>({selectionMode:w,store:Y,toggleRow:xe,toggleAll:Se,radioName:Ce,selectAllLabel:we,selectionHeaderLabel:Te}),[w,Y,xe,Se,Ce,we,Te]),{gridRef:De,gridProps:Z}=u.useGridNavigation(),Oe=c.useMergedRefs(te,De),ke=L,Q=F?n.flattenChildren(L):[];if(F&&!Q.some(({node:e})=>n.isElementOfType(e,R))){let e=({node:e})=>n.isElementOfType(e,`caption`);ke=(0,f.jsxs)(f.Fragment,{children:[Q.filter(e).map(k),(0,f.jsx)(R,{children:(0,f.jsx)(`tr`,{children:F.map(e=>(0,f.jsx)(B,{columnId:e.id,sortable:e.sortable,children:e.label},e.id))})}),Q.filter(t=>!e(t)).map(k)]})}let{className:Ae,"aria-label":je,"aria-labelledby":Me,...Ne}=I??{},$=Ne.role!==void 0,Pe=!$&&(je!==void 0||Me!==void 0);return d.useEffect(()=>{Pe&&r.warnOnce(`DataGrid:container-name-without-role`,'DataGrid: `containerProps["aria-label"]`/`["aria-labelledby"]` is ignored because the wrapper has no role. Name the grid itself (`aria-label` on DataGrid), or pass a `role` (e.g. "region") in `containerProps` too.')},[Pe]),(0,f.jsx)(_.Provider,{value:Ee,children:(0,f.jsx)(v.Provider,{value:ge,children:(0,f.jsx)(`div`,{...Ne,"aria-label":$?je:void 0,"aria-labelledby":$?Me:void 0,className:t.cn(a.dataGridClassNames.container,`overflow-x-auto rounded-md border border-border`,Ae),children:(0,f.jsx)(`table`,{ref:Oe,role:`grid`,"aria-multiselectable":w===`multiple`||void 0,className:t.cn(a.dataGridClassNames.root,`w-full border-separate border-spacing-0`,z),...ne,onKeyDown:i.composeEventHandlers(V,Z.onKeyDown),onFocus:i.composeEventHandlers(H,Z.onFocus,{checkDefaultPrevented:!1}),onBlur:i.composeEventHandlers(U,Z.onBlur,{checkDefaultPrevented:!1}),children:ke})})})})};N.displayName=`DataGrid`;function P({selectionMode:e,ref:n}){let{store:r,toggleAll:i,selectAllLabel:o,selectionHeaderLabel:s}=w(`DataGrid.Header`),c=d.useSyncExternalStore(r.subscribeSelectAll,r.getSelectAllState,r.getSelectAllState),u=d.useRef(null),[p,m]=d.useState(0);return d.useLayoutEffect(()=>{u.current&&(u.current.indeterminate=c===`some`)},[c,p]),(0,f.jsx)(`th`,{ref:n,scope:`col`,"data-selection-cell":``,className:t.cn(a.dataGridHeaderClassNames.selectionCell,j,`text-start`,l.focusRingInset),children:e===`multiple`?(0,f.jsx)(`input`,{ref:u,type:`checkbox`,"aria-label":o,checked:c===`all`,onChange:()=>{m(e=>e+1),i()},className:t.cn(a.dataGridHeaderClassNames.selectAllCheckbox,M,l.focusRingInset)}):(0,f.jsx)(`span`,{className:`sr-only`,children:s})})}var F={subscribe:()=>()=>{},register:()=>()=>{},getFirst:()=>null,refresh:()=>{}};function I({selectionMode:e,initialFirst:n}){let r=d.useContext(b)??F,[i]=d.useState(()=>({})),o=d.useRef(null),s=d.useCallback(()=>{let e=r.getFirst();return e===null?n:e===i},[r,i,n]),c=d.useCallback(()=>n,[n]),u=d.useSyncExternalStore(r.subscribe,s,c);return d.useLayoutEffect(()=>r.register(i,()=>o.current),[r,i]),u?(0,f.jsx)(P,{ref:o,selectionMode:e}):(0,f.jsx)(`td`,{ref:o,"data-selection-cell":``,className:t.cn(a.dataGridHeaderClassNames.selectionCell,j,l.focusRingInset)})}function L(e,t){let r=!0,i=e=>d.Children.map(e,e=>{if(n.isElementOfType(e,d.Fragment))return d.cloneElement(e,void 0,i(e.props.children));if(!d.isValidElement(e))return e;let a=r;if(r=!1,n.isElementOfType(e,`tr`)){let n=t===`none`?null:(0,f.jsx)(I,{selectionMode:t,initialFirst:a});return d.cloneElement(e,void 0,n,e.props.children)}return(0,f.jsx)(x.Provider,{value:a,children:e})});return i(e)}var R=({children:e,className:n,ref:i,...o})=>{let{selectionMode:s}=w(`DataGrid.Header`),[l,u]=d.useState(null),p=c.useMergedRefs(i,u),[m]=d.useState(g),h=L(e,s);return d.useLayoutEffect(()=>{m.refresh()}),d.useEffect(()=>{r.isDev&&l&&s!==`none`&&Array.from(l.rows).some(e=>e.cells.length>0&&!e.cells[0].hasAttribute(`data-selection-cell`))&&r.warnOnce(`DataGrid.Header:missing-selection-cell`,"DataGrid.Header: a header row has no selection column header cell, so the header has one column fewer than the selectable rows. Render header rows as `<tr>` children of DataGrid.Header (a Fragment is fine), or use `DataGrid.Row` for a header row that another component renders.")}),(0,f.jsx)(y.Provider,{value:`header`,children:(0,f.jsx)(b.Provider,{value:m,children:(0,f.jsx)(`thead`,{ref:p,className:t.cn(a.dataGridHeaderClassNames.root,`bg-card`,n),...o,children:h})})})};R.displayName=`DataGridHeader`;var z=e=>(0,f.jsx)(`svg`,{className:t.cn(a.dataGridHeaderCellClassNames.sortIcon,`h-3 w-3 shrink-0`),viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":`true`,focusable:`false`,children:e===`ascending`?(0,f.jsx)(`path`,{d:`M6 2L10 8H2L6 2Z`}):(0,f.jsx)(`path`,{d:`M6 10L2 4H10L6 10Z`})}),B=({columnId:e,sortable:n=!1,children:o,className:s,onClick:c,ref:u,...p})=>{let{sort:m,requestSort:h}=T(`DataGrid.HeaderCell`),g=n&&e?e:void 0,_=g!==void 0&&m?.columnId===g?m.direction:null,v=e=>{let t=e.currentTarget.firstElementChild;g!==void 0&&t?.localName===`button`&&t.contains(e.target)&&h(g)};return d.useEffect(()=>{n&&!e&&r.warnOnce(`DataGrid.HeaderCell:sortable-without-columnId`,"DataGrid.HeaderCell: `sortable` needs a `columnId`; the header is rendered as not sortable.")},[n,e]),(0,f.jsx)(`th`,{ref:u,scope:`col`,"aria-sort":g===void 0?void 0:_??`none`,className:t.cn(a.dataGridHeaderCellClassNames.root,A,`text-start align-middle font-semibold text-caption-1 uppercase tracking-wider`,l.focusRingInset,g!==void 0&&`p-0 hover:bg-subtle-hover`,s),...p,onClick:g===void 0?c:i.composeEventHandlers(c,v),children:g===void 0?(0,f.jsx)(`span`,{className:`inline-flex items-center gap-1`,children:o}):(0,f.jsxs)(`button`,{type:`button`,className:t.cn(a.dataGridHeaderCellClassNames.button,`inline-flex w-full cursor-pointer select-none items-center gap-1 border-0 bg-transparent px-4 py-3 text-start text-inherit [font:inherit] uppercase tracking-wider`,l.focusRingInset),children:[o,_&&z(_)]})})};B.displayName=`DataGridHeaderCell`;var V=({children:e,className:n,ref:r,...i})=>(0,f.jsx)(y.Provider,{value:`body`,children:(0,f.jsx)(`tbody`,{ref:r,className:t.cn(a.dataGridBodyClassNames.root,n),...i,children:e})});V.displayName=`DataGridBody`;var H=({rowId:e,selectionLabel:o,children:c,className:u,onKeyDown:p,ref:m,...h})=>{let{selectionMode:g,store:_,toggleRow:v,radioName:b}=w(`DataGrid.Row`),S=d.useContext(y),C=d.useContext(x),T=S===`header`,E=g!==`none`&&!T,D=s.useId(`wave-datagrid-row-label`),O=g===`single`,A=d.useCallback(()=>e!==void 0&&_.isSelected(e,O),[e,_,O]),N=d.useSyncExternalStore(_.subscribe,A,A);d.useLayoutEffect(()=>{if(e===void 0||T)return;let t=_.register(e);return r.isDev&&_.countRegistrations(e)>1&&ee(e),t},[_,e,T]),d.useEffect(()=>{E&&e===void 0&&r.warnOnce(`DataGrid.Row:missing-rowId`,"DataGrid.Row: a selectable grid needs a `rowId` on every row; this row has no selection control.")},[E,e]);let P=E&&e!==void 0&&o===void 0,F=t=>{if(!E||e===void 0||t.key!==` `)return;let n=t.target;(n===t.currentTarget||n.parentElement===t.currentTarget)&&(t.preventDefault(),v(e))},L=n.flattenChildren(c),R,z=-1;if(P){let e=L.findIndex(({node:e})=>n.isElementOfType(e,U,`td`,`th`));if(e>=0){let t=L[e].node;R=t.props.id??D,t.props.id===void 0&&(z=e)}}let B=L.map(({key:e,node:t},n)=>k({key:e,node:n===z?d.cloneElement(t,{id:D}):t})),V=P&&R===void 0;d.useEffect(()=>{V&&r.warnOnce(`DataGrid.Row:selection-label`,'DataGrid.Row: no child is a `DataGrid.Cell`, `<td>` or `<th>` element, so the row selection control is named "Select row". Pass `selectionLabel` (a cell rendered by another component is not seen).')},[V]);let H=null;return T&&g!==`none`?H=(0,f.jsx)(I,{selectionMode:g,initialFirst:C}):E&&(H=(0,f.jsx)(`td`,{role:`gridcell`,"data-selection-cell":``,className:t.cn(a.dataGridRowClassNames.selectionCell,j,l.focusRingInset),children:e!==void 0&&(0,f.jsx)(`input`,{type:g===`multiple`?`checkbox`:`radio`,name:g===`single`?b:void 0,form:g===`single`?``:void 0,checked:N,onChange:()=>v(e),"aria-label":o??(R?void 0:`Select row`),"aria-labelledby":o===void 0?R:void 0,className:t.cn(a.dataGridRowClassNames.selectionControl,M,`focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring`)})})),(0,f.jsxs)(`tr`,{ref:m,className:t.cn(a.dataGridRowClassNames.root,!T&&`hover:bg-subtle-hover data-[selected]:bg-selected transition-colors motion-reduce:transition-none`,E&&N&&l.forcedColors.selectedContainer,u),"aria-selected":E?N:void 0,"data-selected":E&&N?``:void 0,...h,onKeyDown:i.composeEventHandlers(p,F),children:[H,B]})};H.displayName=`DataGridRow`;var U=({children:e,className:n,ref:r,...i})=>(0,f.jsx)(`td`,{ref:r,role:`gridcell`,className:t.cn(a.dataGridCellClassNames.root,A,`text-body-1`,l.focusRingInset,n),...i,children:e});U.displayName=`DataGridCell`;var te=Object.assign(N,{Header:R,HeaderCell:B,Body:V,Row:H,Cell:U});exports.DataGrid=te,exports.DataGridBody=V,exports.DataGridCell=U,exports.DataGridHeader=R,exports.DataGridHeaderCell=B,exports.DataGridRow=H,exports.createSelectionStore=h;
1
+ "use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/children.cjs"),r=require("../../lib/dev.cjs"),i=require("../../lib/composeEventHandlers.cjs"),a=require("../../lib/classNames.cjs"),o=require("../../hooks/useControllable.cjs"),s=require("../../hooks/useId.cjs"),c=require("../../hooks/useMergedRefs.cjs"),l=require("./useGridNavigation.cjs"),u=require("../../lib/styles.cjs");let d=require("react");d=e.__toESM(d,1);let f=require("react/jsx-runtime");var p=`Select all rows`,m=`Selection`;function h(e,t=!1){let n=new Set(e),r=new Map,i=0,a=`none`,o=t,s,c=new Set,l=new Set,u=e=>{for(let t of Array.from(e))t()},d=()=>{if(s!==void 0)return s;let e=null;for(let t of n){if(r.has(t)){e=t;break}e??=t}return s=e,e},f=e=>{if(n.size<2||!n.has(e))return;let t=s;s=void 0,o&&d()!==t&&u(c)},p=()=>{let e=i===0?`none`:i===r.size?`all`:`some`;e!==a&&(a=e,u(l))},m=e=>t=>(e.add(t),()=>{e.delete(t)});return{subscribe:m(c),subscribeSelectAll:m(l),register(e){let t=r.get(e)??0;r.set(e,t+1),t===0&&n.has(e)&&(i+=1),p(),t===0&&f(e);let a=!1;return()=>{if(a)return;a=!0;let t=(r.get(e)??0)-1;if(t>0){r.set(e,t);return}r.delete(e),n.has(e)&&--i,p(),f(e)}},setSelected(e){let t=new Set(e);if(!(t.size===n.size&&e.every(e=>n.has(e)))){n=t,s=void 0,i=0;for(let e of t)r.has(e)&&(i+=1);u(c),p()}},setSingleMode(e){o=e},isSelected(e,t=!1){return t?d()===e:n.has(e)},countRegistrations(e){return r.get(e)??0},getSelectAllState(){return a},getRegistered(){return Array.from(r.keys())},prune(e){return e.filter(e=>r.has(e))}}}function g(){let e=new Map,t=new Set,n=null,r=()=>{let r=null,i=null;for(let[t,a]of e){let o=a();if(!o){if(n!==null&&e.has(n))return;continue}(!i||o.compareDocumentPosition(i)&Node.DOCUMENT_POSITION_FOLLOWING)&&(r=t,i=o)}if(r===null&&(r=e.keys().next().value??null),r!==n){n=r;for(let e of Array.from(t))e()}};return{subscribe(e){return t.add(e),()=>{t.delete(e)}},register(t,n){return e.set(t,n),r(),()=>{e.delete(t),r()}},getFirst:()=>n,refresh:r}}var _=d.createContext(null),v=d.createContext(null),y=d.createContext(`body`),b=d.createContext(null),x=d.createContext(!0),S={selectionMode:`none`,store:h([]),toggleRow:()=>{},toggleAll:()=>{},radioName:``,selectAllLabel:p,selectionHeaderLabel:m},C={sort:null,requestSort:()=>{}};function w(e){return d.useContext(_)||(r.reportMissingContext(e,`DataGrid`),S)}function T(e){return d.useContext(v)||(r.reportMissingContext(e,`DataGrid`),C)}var E=[];function D(e){return e===void 0?void 0:Array.from(e)}function O(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function k({key:e,node:t}){return(0,f.jsx)(d.Fragment,{children:t},e)}function ee(e){r.warnOnce(`DataGrid:duplicate-rowId:${e}`,`DataGrid: several rows share the rowId "${e}". Row ids must be unique within a DataGrid; rows with the same rowId are selected and deselected together.`)}var A=`px-4 py-3 border-b border-border`,j=`w-10 px-3 py-3 border-b border-border`,M=`accent-primary cursor-pointer`,N=e=>{let{sort:u,defaultSort:g,sortColumn:y,defaultSortColumn:b,sortDirection:x,defaultSortDirection:S,onSortChange:C,selectionMode:w=`none`,selectedItems:T,defaultSelectedItems:ee,onSelectedItemsChange:A,selectedKeys:j,defaultSelectedKeys:M,onSelectionChange:N,labels:P,columns:F,containerProps:I,children:L,className:z,onKeyDown:V,onFocus:H,onBlur:U,ref:te,...ne}=e,W=u!==void 0||g!==void 0,[re,ie]=d.useState(W);W&&!re&&ie(!0);let ae=re||W,oe=y!==void 0||x!==void 0;y!==void 0&&r.warnDeprecated(`DataGrid`,`sortColumn`,`sort`),x!==void 0&&r.warnDeprecated(`DataGrid`,`sortDirection`,`sort`),b!==void 0&&r.warnDeprecated(`DataGrid`,`defaultSortColumn`,`defaultSort`),S!==void 0&&r.warnDeprecated(`DataGrid`,`defaultSortDirection`,`defaultSort`);let se=W&&(oe||b!==void 0||S!==void 0);d.useEffect(()=>{se&&r.warnOnce(`DataGrid:mixed-sort`,"DataGrid: do not mix `sort`/`defaultSort` with the deprecated `sortColumn`/`sortDirection`/`defaultSortColumn`/`defaultSortDirection`. `sort`/`defaultSort` win.")},[se]),d.useEffect(()=>{W||(y!==void 0&&x===void 0?r.warnOnce(`DataGrid:sortColumn-without-sortDirection`,"DataGrid: `sortColumn` is controlled but `sortDirection` is not (mixed control). The direction is kept internally and toggles on repeated clicks, as in 0.4. Pass `sort` (`{ columnId, direction }`) to control both."):x!==void 0&&y===void 0&&r.warnOnce(`DataGrid:sortDirection-without-sortColumn`,"DataGrid: `sortDirection` is controlled but `sortColumn` is not (mixed control). The column is kept internally and follows the clicked header, as in 0.4. Pass `sort` (`{ columnId, direction }`) to control both."))},[W,y,x]);let[G,ce]=d.useState(()=>({column:b??``,direction:S??`ascending`})),le=d.useMemo(()=>{if(y===void 0&&x===void 0)return;let e=y??G.column;return e===``?null:{columnId:e,direction:x??G.direction}},[y,x,G]),ue=d.useMemo(()=>b?{columnId:b,direction:S??`ascending`}:null,[b,S]),de=W?u:le,fe=g===void 0?ue:g,[pe,me]=o.useControllable(de,fe,e=>{e&&(W||ce(t=>t.column===e.columnId&&t.direction===e.direction?t:{column:e.columnId,direction:e.direction}),C&&(ae?C(e):C(e.columnId,e.direction)))}),he=d.useCallback(e=>{me(t=>({columnId:e,direction:t?.columnId===e&&t.direction===`ascending`?`descending`:`ascending`}))},[me]),ge=d.useMemo(()=>({sort:pe,requestSort:he}),[pe,he]);N!==void 0&&r.warnDeprecated(`DataGrid`,`onSelectionChange`,`onSelectedItemsChange`);let _e=d.useMemo(()=>D(j),[j]),ve=d.useMemo(()=>D(M),[M]),ye=r.resolveDeprecatedProp(`DataGrid`,T,_e,`selectedKeys`,`selectedItems`),be=r.resolveDeprecatedProp(`DataGrid`,ee,ve,`defaultSelectedKeys`,`defaultSelectedItems`)??E,[K,q]=o.useControllable(ye,be,e=>{A?.([...e]),N?.(new Set(e))}),J=w===`single`,[Y]=d.useState(()=>h(K,J));d.useLayoutEffect(()=>{Y.setSelected(K)},[Y,K]),d.useLayoutEffect(()=>{Y.setSingleMode(J)},[Y,J]);let xe=d.useCallback(e=>{q(t=>{let n=Y.prune(t),r;return r=J?n[0]===e?[]:[e]:n.includes(e)?n.filter(t=>t!==e):[...n,e],O(r,t)?t:r})},[J,q,Y]),X=K.length;d.useEffect(()=>{J&&X>1&&r.warnOnce(`DataGrid:single-several-selected`,`DataGrid: a single-selection grid (selectionMode "single") has ${X} selected row ids; only the first one that is rendered is selected. Pass at most one id in \`selectedItems\`/\`defaultSelectedItems\`, or use selectionMode="multiple".`)},[J,X]);let Se=d.useCallback(()=>{q(e=>{let t=Y.prune(e),n=Y.getRegistered(),r=n.length>0&&n.every(e=>t.includes(e))?[]:n;return O(r,e)?e:r})},[q,Y]),Ce=s.useId(`wave-datagrid-selection`),we=P?.selectAll??p,Te=P?.selectionHeader??m,Ee=d.useMemo(()=>({selectionMode:w,store:Y,toggleRow:xe,toggleAll:Se,radioName:Ce,selectAllLabel:we,selectionHeaderLabel:Te}),[w,Y,xe,Se,Ce,we,Te]),{gridRef:De,gridProps:Z}=l.useGridNavigation(),Oe=c.useMergedRefs(te,De),ke=L,Q=F?n.flattenChildren(L):[];if(F&&!Q.some(({node:e})=>n.isElementOfType(e,R))){let e=({node:e})=>n.isElementOfType(e,`caption`);ke=(0,f.jsxs)(f.Fragment,{children:[Q.filter(e).map(k),(0,f.jsx)(R,{children:(0,f.jsx)(`tr`,{children:F.map(e=>(0,f.jsx)(B,{columnId:e.id,sortable:e.sortable,children:e.label},e.id))})}),Q.filter(t=>!e(t)).map(k)]})}let{className:Ae,"aria-label":je,"aria-labelledby":Me,...Ne}=I??{},$=Ne.role!==void 0,Pe=!$&&(je!==void 0||Me!==void 0);return d.useEffect(()=>{Pe&&r.warnOnce(`DataGrid:container-name-without-role`,'DataGrid: `containerProps["aria-label"]`/`["aria-labelledby"]` is ignored because the wrapper has no role. Name the grid itself (`aria-label` on DataGrid), or pass a `role` (e.g. "region") in `containerProps` too.')},[Pe]),(0,f.jsx)(_.Provider,{value:Ee,children:(0,f.jsx)(v.Provider,{value:ge,children:(0,f.jsx)(`div`,{...Ne,"aria-label":$?je:void 0,"aria-labelledby":$?Me:void 0,className:t.cn(a.dataGridClassNames.container,`overflow-x-auto rounded-md border border-border`,Ae),children:(0,f.jsx)(`table`,{ref:Oe,role:`grid`,"aria-multiselectable":w===`multiple`||void 0,className:t.cn(a.dataGridClassNames.root,`w-full border-separate border-spacing-0`,z),...ne,onKeyDown:i.composeEventHandlers(V,Z.onKeyDown),onFocus:i.composeEventHandlers(H,Z.onFocus,{checkDefaultPrevented:!1}),onBlur:i.composeEventHandlers(U,Z.onBlur,{checkDefaultPrevented:!1}),children:ke})})})})};N.displayName=`DataGrid`;function P({selectionMode:e,ref:n}){let{store:r,toggleAll:i,selectAllLabel:o,selectionHeaderLabel:s}=w(`DataGrid.Header`),c=d.useSyncExternalStore(r.subscribeSelectAll,r.getSelectAllState,r.getSelectAllState),l=d.useRef(null),[p,m]=d.useState(0);return d.useLayoutEffect(()=>{l.current&&(l.current.indeterminate=c===`some`)},[c,p]),(0,f.jsx)(`th`,{ref:n,scope:`col`,"data-selection-cell":``,className:t.cn(a.dataGridHeaderClassNames.selectionCell,j,`text-start`,u.focusRingInset),children:e===`multiple`?(0,f.jsx)(`input`,{ref:l,type:`checkbox`,"aria-label":o,checked:c===`all`,onChange:()=>{m(e=>e+1),i()},className:t.cn(a.dataGridHeaderClassNames.selectAllCheckbox,M,u.focusRingInset)}):(0,f.jsx)(`span`,{className:`sr-only`,children:s})})}var F={subscribe:()=>()=>{},register:()=>()=>{},getFirst:()=>null,refresh:()=>{}};function I({selectionMode:e,initialFirst:n}){let r=d.useContext(b)??F,[i]=d.useState(()=>({})),o=d.useRef(null),s=d.useCallback(()=>{let e=r.getFirst();return e===null?n:e===i},[r,i,n]),c=d.useCallback(()=>n,[n]),l=d.useSyncExternalStore(r.subscribe,s,c);return d.useLayoutEffect(()=>r.register(i,()=>o.current),[r,i]),l?(0,f.jsx)(P,{ref:o,selectionMode:e}):(0,f.jsx)(`td`,{ref:o,"data-selection-cell":``,className:t.cn(a.dataGridHeaderClassNames.selectionCell,j,u.focusRingInset)})}function L(e,t){let r=!0,i=e=>d.Children.map(e,e=>{if(n.isElementOfType(e,d.Fragment))return d.cloneElement(e,void 0,i(e.props.children));if(!d.isValidElement(e))return e;let a=r;if(r=!1,n.isElementOfType(e,`tr`)){let n=t===`none`?null:(0,f.jsx)(I,{selectionMode:t,initialFirst:a});return d.cloneElement(e,void 0,n,e.props.children)}return(0,f.jsx)(x.Provider,{value:a,children:e})});return i(e)}var R=({children:e,className:n,ref:i,...o})=>{let{selectionMode:s}=w(`DataGrid.Header`),[l,u]=d.useState(null),p=c.useMergedRefs(i,u),[m]=d.useState(g),h=L(e,s);return d.useLayoutEffect(()=>{m.refresh()}),d.useEffect(()=>{r.isDev&&l&&s!==`none`&&Array.from(l.rows).some(e=>e.cells.length>0&&!e.cells[0].hasAttribute(`data-selection-cell`))&&r.warnOnce(`DataGrid.Header:missing-selection-cell`,"DataGrid.Header: a header row has no selection column header cell, so the header has one column fewer than the selectable rows. Render header rows as `<tr>` children of DataGrid.Header (a Fragment is fine), or use `DataGrid.Row` for a header row that another component renders.")}),(0,f.jsx)(y.Provider,{value:`header`,children:(0,f.jsx)(b.Provider,{value:m,children:(0,f.jsx)(`thead`,{ref:p,className:t.cn(a.dataGridHeaderClassNames.root,`bg-card`,n),...o,children:h})})})};R.displayName=`DataGridHeader`;var z=e=>(0,f.jsx)(`svg`,{className:t.cn(a.dataGridHeaderCellClassNames.sortIcon,`h-3 w-3 shrink-0`),viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":`true`,focusable:`false`,children:e===`ascending`?(0,f.jsx)(`path`,{d:`M6 2L10 8H2L6 2Z`}):(0,f.jsx)(`path`,{d:`M6 10L2 4H10L6 10Z`})}),B=({columnId:e,sortable:n=!1,children:o,className:s,onClick:c,ref:l,...p})=>{let{sort:m,requestSort:h}=T(`DataGrid.HeaderCell`),g=n&&e?e:void 0,_=g!==void 0&&m?.columnId===g?m.direction:null,v=e=>{let t=e.currentTarget.firstElementChild;g!==void 0&&t?.localName===`button`&&t.contains(e.target)&&h(g)};return d.useEffect(()=>{n&&!e&&r.warnOnce(`DataGrid.HeaderCell:sortable-without-columnId`,"DataGrid.HeaderCell: `sortable` needs a `columnId`; the header is rendered as not sortable.")},[n,e]),(0,f.jsx)(`th`,{ref:l,scope:`col`,"aria-sort":g===void 0?void 0:_??`none`,className:t.cn(a.dataGridHeaderCellClassNames.root,A,`text-start align-middle font-semibold text-caption-1 uppercase tracking-wider`,u.focusRingInset,g!==void 0&&`p-0 hover:bg-subtle-hover`,s),...p,onClick:g===void 0?c:i.composeEventHandlers(c,v),children:g===void 0?(0,f.jsx)(`span`,{className:`inline-flex items-center gap-1`,children:o}):(0,f.jsxs)(`button`,{type:`button`,className:t.cn(a.dataGridHeaderCellClassNames.button,`inline-flex w-full cursor-pointer select-none items-center gap-1 border-0 bg-transparent px-4 py-3 text-start text-inherit [font:inherit] uppercase tracking-wider`,u.focusRingInset),children:[o,_&&z(_)]})})};B.displayName=`DataGridHeaderCell`;var V=({children:e,className:n,ref:r,...i})=>(0,f.jsx)(y.Provider,{value:`body`,children:(0,f.jsx)(`tbody`,{ref:r,className:t.cn(a.dataGridBodyClassNames.root,n),...i,children:e})});V.displayName=`DataGridBody`;var H=({rowId:e,selectionLabel:o,children:c,className:l,onKeyDown:p,ref:m,...h})=>{let{selectionMode:g,store:_,toggleRow:v,radioName:b}=w(`DataGrid.Row`),S=d.useContext(y),C=d.useContext(x),T=S===`header`,E=g!==`none`&&!T,D=s.useId(`wave-datagrid-row-label`),O=g===`single`,A=d.useCallback(()=>e!==void 0&&_.isSelected(e,O),[e,_,O]),N=d.useSyncExternalStore(_.subscribe,A,A);d.useLayoutEffect(()=>{if(e===void 0||T)return;let t=_.register(e);return r.isDev&&_.countRegistrations(e)>1&&ee(e),t},[_,e,T]),d.useEffect(()=>{E&&e===void 0&&r.warnOnce(`DataGrid.Row:missing-rowId`,"DataGrid.Row: a selectable grid needs a `rowId` on every row; this row has no selection control.")},[E,e]);let P=E&&e!==void 0&&o===void 0,F=t=>{if(!E||e===void 0||t.key!==` `)return;let n=t.target;(n===t.currentTarget||n.parentElement===t.currentTarget)&&(t.preventDefault(),v(e))},L=n.flattenChildren(c),R,z=-1;if(P){let e=L.findIndex(({node:e})=>n.isElementOfType(e,U,`td`,`th`));if(e>=0){let t=L[e].node;R=t.props.id??D,t.props.id===void 0&&(z=e)}}let B=L.map(({key:e,node:t},n)=>k({key:e,node:n===z?d.cloneElement(t,{id:D}):t})),V=P&&R===void 0;d.useEffect(()=>{V&&r.warnOnce(`DataGrid.Row:selection-label`,'DataGrid.Row: no child is a `DataGrid.Cell`, `<td>` or `<th>` element, so the row selection control is named "Select row". Pass `selectionLabel` (a cell rendered by another component is not seen).')},[V]);let H=null;return T&&g!==`none`?H=(0,f.jsx)(I,{selectionMode:g,initialFirst:C}):E&&(H=(0,f.jsx)(`td`,{role:`gridcell`,"data-selection-cell":``,className:t.cn(a.dataGridRowClassNames.selectionCell,j,u.focusRingInset),children:e!==void 0&&(0,f.jsx)(`input`,{type:g===`multiple`?`checkbox`:`radio`,name:g===`single`?b:void 0,form:g===`single`?``:void 0,checked:N,onChange:()=>v(e),"aria-label":o??(R?void 0:`Select row`),"aria-labelledby":o===void 0?R:void 0,className:t.cn(a.dataGridRowClassNames.selectionControl,M,`focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring`)})})),(0,f.jsxs)(`tr`,{ref:m,className:t.cn(a.dataGridRowClassNames.root,!T&&`hover:bg-subtle-hover data-[selected]:bg-selected transition-colors motion-reduce:transition-none`,E&&N&&u.forcedColors.selectedContainer,l),"aria-selected":E?N:void 0,"data-selected":E&&N?``:void 0,...h,onKeyDown:i.composeEventHandlers(p,F),children:[H,B]})};H.displayName=`DataGridRow`;var U=({children:e,className:n,ref:r,...i})=>(0,f.jsx)(`td`,{ref:r,role:`gridcell`,className:t.cn(a.dataGridCellClassNames.root,A,`text-body-1`,u.focusRingInset,n),...i,children:e});U.displayName=`DataGridCell`;var te=Object.assign(N,{Header:R,HeaderCell:B,Body:V,Row:H,Cell:U});exports.DataGrid=te,exports.DataGridBody=V,exports.DataGridCell=U,exports.DataGridHeader=R,exports.DataGridHeaderCell=B,exports.DataGridRow=H,exports.createSelectionStore=h;
2
2
  //# sourceMappingURL=DataGrid.cjs.map