@funstack/ui 0.1.0-alpha.8 → 0.1.0-alpha.9

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 (68) hide show
  1. package/dist/combobox/combobox-popup.mjs +1 -1
  2. package/dist/combobox/combobox-popup.mjs.map +1 -1
  3. package/dist/csp/csp-provider.d.mts +25 -0
  4. package/dist/csp/csp-provider.d.mts.map +1 -0
  5. package/dist/csp/csp-provider.mjs +24 -0
  6. package/dist/csp/csp-provider.mjs.map +1 -0
  7. package/dist/csp/index.d.mts +3 -0
  8. package/dist/csp/index.mjs +3 -0
  9. package/dist/csp/style-hashes.d.mts +19 -0
  10. package/dist/csp/style-hashes.d.mts.map +1 -0
  11. package/dist/csp/style-hashes.mjs +21 -0
  12. package/dist/csp/style-hashes.mjs.map +1 -0
  13. package/dist/index.d.mts +7 -3
  14. package/dist/index.mjs +3 -1
  15. package/dist/internal/anchor-position.d.mts +11 -3
  16. package/dist/internal/anchor-position.d.mts.map +1 -1
  17. package/dist/internal/anchor-position.mjs +169 -18
  18. package/dist/internal/anchor-position.mjs.map +1 -1
  19. package/dist/internal/csp-context.mjs +8 -0
  20. package/dist/internal/csp-context.mjs.map +1 -0
  21. package/dist/internal/tooltip-warm.mjs +29 -0
  22. package/dist/internal/tooltip-warm.mjs.map +1 -0
  23. package/dist/internal/use-resolved-placement.mjs +146 -0
  24. package/dist/internal/use-resolved-placement.mjs.map +1 -0
  25. package/dist/menu/menu-context-trigger.d.mts.map +1 -1
  26. package/dist/menu/menu-context-trigger.mjs +198 -19
  27. package/dist/menu/menu-context-trigger.mjs.map +1 -1
  28. package/dist/menu/menu-context.mjs +11 -1
  29. package/dist/menu/menu-context.mjs.map +1 -1
  30. package/dist/menu/menu-dom.mjs +9 -5
  31. package/dist/menu/menu-dom.mjs.map +1 -1
  32. package/dist/menu/menu-popup.d.mts +20 -6
  33. package/dist/menu/menu-popup.d.mts.map +1 -1
  34. package/dist/menu/menu-popup.mjs +119 -26
  35. package/dist/menu/menu-popup.mjs.map +1 -1
  36. package/dist/menu/menu-root.d.mts.map +1 -1
  37. package/dist/menu/menu-root.mjs +11 -3
  38. package/dist/menu/menu-root.mjs.map +1 -1
  39. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  40. package/dist/menu/menu-submenu-trigger.mjs +27 -11
  41. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  42. package/dist/popover/popover-popup.d.mts +21 -7
  43. package/dist/popover/popover-popup.d.mts.map +1 -1
  44. package/dist/popover/popover-popup.mjs +16 -6
  45. package/dist/popover/popover-popup.mjs.map +1 -1
  46. package/dist/tooltip/index.d.mts +8 -5
  47. package/dist/tooltip/index.d.mts.map +1 -1
  48. package/dist/tooltip/index.mjs +6 -3
  49. package/dist/tooltip/index.mjs.map +1 -1
  50. package/dist/tooltip/tooltip-arrow.d.mts +30 -0
  51. package/dist/tooltip/tooltip-arrow.d.mts.map +1 -0
  52. package/dist/tooltip/tooltip-arrow.mjs +45 -0
  53. package/dist/tooltip/tooltip-arrow.mjs.map +1 -0
  54. package/dist/tooltip/tooltip-context.d.mts +7 -0
  55. package/dist/tooltip/tooltip-context.d.mts.map +1 -1
  56. package/dist/tooltip/tooltip-context.mjs +2 -1
  57. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  58. package/dist/tooltip/tooltip-popup.d.mts +21 -6
  59. package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
  60. package/dist/tooltip/tooltip-popup.mjs +28 -6
  61. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  62. package/dist/tooltip/tooltip-trigger.d.mts +9 -2
  63. package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
  64. package/dist/tooltip/tooltip-trigger.mjs +21 -5
  65. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  66. package/dist/tooltip/use-tooltip-interaction.mjs +26 -2
  67. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  68. package/package.json +2 -1
@@ -4,6 +4,7 @@ import { resolveStateValue } from "../internal/render-element.mjs";
4
4
  import { useDelayedPair } from "../internal/use-delayed-pair.mjs";
5
5
  import { usePopoverRoot } from "../internal/use-popover-root.mjs";
6
6
  import { ANCHOR_PLACEMENT, MenuContext, MenuListContext, MenuRegionContext } from "./menu-context.mjs";
7
+ import { isRtl } from "./menu-dom.mjs";
7
8
  import { use, useCallback, useMemo, useRef, useState } from "react";
8
9
  import { jsx } from "react/jsx-runtime";
9
10
  //#region src/menu/menu-root.tsx
@@ -49,16 +50,19 @@ function MenuRoot({ open, defaultOpen, openChangeAction, loop = true, delay, clo
49
50
  if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);
50
51
  }
51
52
  });
52
- const { intended, requestOpen } = popover;
53
+ const { intended, requestOpen, popupRef } = popover;
53
54
  const openAt = useCallback((point, options) => {
54
55
  const generation = ++placementGeneration.current;
56
+ const popup = popupRef.current;
55
57
  setPlacement({
56
58
  kind: "point",
57
59
  x: point.x,
58
60
  y: point.y,
59
61
  generation,
60
62
  source: options.source,
61
- pointerId: options.pointerId
63
+ pointerId: options.pointerId,
64
+ direction: popup !== null && isRtl(popup) ? "rtl" : "ltr",
65
+ offset: options.offset
62
66
  });
63
67
  const focus = {
64
68
  cause: "first",
@@ -75,7 +79,11 @@ function MenuRoot({ open, defaultOpen, openChangeAction, loop = true, delay, clo
75
79
  } finally {
76
80
  pointDispatch.current = false;
77
81
  }
78
- }, [intended, requestOpen]);
82
+ }, [
83
+ intended,
84
+ requestOpen,
85
+ popupRef
86
+ ]);
79
87
  const resetPlacement = useCallback((generation) => {
80
88
  setPlacement((current) => current.kind === "point" && current.generation === generation ? ANCHOR_PLACEMENT : current);
81
89
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { ActionDetails, ChangeAction, ChangeReason, StateValue } from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverRoot } from \"../internal/use-popover-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport {\n ANCHOR_PLACEMENT,\n MenuContext,\n MenuListContext,\n MenuRegionContext,\n} from \"./menu-context.js\";\nimport type {\n MenuContextValue,\n MenuOpenAtOptions,\n MenuOpenFocus,\n MenuPlacement,\n} from \"./menu-context.js\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n /**\n * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the\n * pointer rather than against the Trigger.\n */\n readonly context: boolean;\n}\n\nexport interface MenuRootProps {\n /** Controlled open state. `undefined` means uncontrolled. */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the\n * closes the user asks a part for (Trigger toggle, an item's activation, ArrowLeft in a\n * submenu); a notification for dismissals (Escape, a click outside, Tab, the parent menu\n * closing). May be a Server Function. A `setState` placed after your own `await` needs\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /** Arrow keys wrap from the last item to the first and back. Default `true`. */\n loop?: boolean;\n /** Submenu only: milliseconds from hovering the SubmenuTrigger to the open. Default 100. */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close. Default 150.\n */\n closeDelay?: number;\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are transitions (pending Trigger, items render from committed state,\n * `showPopover()` / `hidePopover()` once the change has committed); dismissals are the\n * browser's and `openChangeAction(false)` is a notification.\n */\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n const inRegion = use(MenuRegionContext);\n useDevWarning(\n parent !== null && !submenu && !inRegion,\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n // Placement of the current open (context-menu.md 3.1). Written urgently, not in a transition:\n // while closed it renders nothing visible, and a move of an open menu (4.3) answers the\n // right-click at once, where a transition would be entangled with any pending async action\n // (an item's, the open's) and the menu would stay at the old point until it settled.\n const [placement, setPlacement] = useState<MenuPlacement>(ANCHOR_PLACEMENT);\n const placementGeneration = useRef(0);\n // Set by `openAt` around its `requestOpen`: the dispatch is a point open.\n const pointDispatch = useRef(false);\n\n const popover = usePopoverRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n // Every other open (Trigger, foreign invoker, mount reconciliation) is anchored.\n if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);\n },\n });\n\n const { intended, requestOpen } = popover;\n const openAt = useCallback(\n (point: { readonly x: number; readonly y: number }, options: MenuOpenAtOptions) => {\n const generation = ++placementGeneration.current;\n setPlacement({\n kind: \"point\",\n x: point.x,\n y: point.y,\n generation,\n source: options.source,\n pointerId: options.pointerId,\n });\n const focus: MenuOpenFocus = { cause: \"first\", pointer: options.pointer };\n if (intended()) {\n // A move, or a right-click while the open is still pending: no dispatch. The re-show\n // (or the open being shown) focuses the first item by this event's modality.\n openCause.current = focus;\n return;\n }\n nextCause.current = focus;\n pointDispatch.current = true;\n try {\n requestOpen(options.event, \"activate\");\n } finally {\n pointDispatch.current = false;\n }\n },\n [intended, requestOpen],\n );\n const resetPlacement = useCallback((generation: number) => {\n setPlacement((current) =>\n current.kind === \"point\" && current.generation === generation ? ANCHOR_PLACEMENT : current,\n );\n }, []);\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // `popover` is memoised by `usePopoverRoot` (#48) and the other members are stable, so this\n // changes only with the open state, pending and the props listed below.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n context: popover.optimistic && placement.kind === \"point\",\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoFA,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;AAEtE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,OAAO,IAAI,eAAe;CAEhC,MAAM,aAAa,SAAS,OAAO,KAAK,OAAO;CAC/C,MAAM,UAAU,eAAe;CAE/B,cACE,CAAC,YAAY,UAAU,KAAA,KAAa,eAAe,KAAA,IACnD,yIAEF;CACA,MAAM,WAAW,IAAI,iBAAiB;CACtC,cACE,WAAW,QAAQ,CAAC,WAAW,CAAC,UAChC,gIAEF;CAEA,MAAM,SAAS,eAAe;CAG9B,MAAM,YAAY,OAA6B,IAAI;CACnD,MAAM,YAAY,OAA6B,IAAI;CAMnD,MAAM,CAAC,WAAW,gBAAgB,SAAwB,gBAAgB;CAC1E,MAAM,sBAAsB,OAAO,CAAC;CAEpC,MAAM,gBAAgB,OAAO,KAAK;CAElC,MAAM,UAAU,eAAsC;EACpD,WAAW;EACX,MAAM;EACN,MAAM;EACN;EACA;EACA;EACA,aAAa,SAAS;GAEpB,OAAO,OAAO;GACd,IAAI,MAAM,UAAU,UAAU,UAAU,WAAW;GACnD,UAAU,UAAU;GAEpB,IAAI,QAAQ,CAAC,cAAc,SAAS,aAAa,gBAAgB;EACnE;CACF,CAAC;CAED,MAAM,EAAE,UAAU,gBAAgB;CAClC,MAAM,SAAS,aACZ,OAAmD,YAA+B;EACjF,MAAM,aAAa,EAAE,oBAAoB;EACzC,aAAa;GACX,MAAM;GACN,GAAG,MAAM;GACT,GAAG,MAAM;GACT;GACA,QAAQ,QAAQ;GAChB,WAAW,QAAQ;EACrB,CAAC;EACD,MAAM,QAAuB;GAAE,OAAO;GAAS,SAAS,QAAQ;EAAQ;EACxE,IAAI,SAAS,GAAG;GAGd,UAAU,UAAU;GACpB;EACF;EACA,UAAU,UAAU;EACpB,cAAc,UAAU;EACxB,IAAI;GACF,YAAY,QAAQ,OAAO,UAAU;EACvC,UAAU;GACR,cAAc,UAAU;EAC1B;CACF,GACA,CAAC,UAAU,WAAW,CACxB;CACA,MAAM,iBAAiB,aAAa,eAAuB;EACzD,cAAc,YACZ,QAAQ,SAAS,WAAW,QAAQ,eAAe,aAAa,mBAAmB,OACrF;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,eAAe,aAAa,OAA+B,UAAU,UAAU;EACnF,UAAU,UAAU;GAAE;GAAO;EAAQ;CACvC,GAAG,CAAC,CAAC;CACL,MAAM,gBAAgB,kBAAkB;EACtC,MAAM,QAAQ,UAAU,WAAW;EACnC,UAAU,UAAU;EACpB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,SAAS;CAC/B,MAAM,qBAAqB,cAAc;CAGzC,MAAM,QAAQ,cAAgC;EAC5C,MAAM,OAAyB;GAC7B;GACA;GAEA,IAAI,OAAO;IACT,OAAO,YAAY,QAAQ;GAC7B;GACA,QAAQ;GACR;GACA,OAAO;GACP,YAAY;GACZ,WAAW,GAAG,QAAQ,IAAI,MAAM;GAChC;GACA;GACA;GACA;GACA;GACA;EACF;EACA,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;EACA,SAAS,QAAQ,cAAc,UAAU,SAAS;CACpD;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
1
+ {"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { ActionDetails, ChangeAction, ChangeReason, StateValue } from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverRoot } from \"../internal/use-popover-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport {\n ANCHOR_PLACEMENT,\n MenuContext,\n MenuListContext,\n MenuRegionContext,\n} from \"./menu-context.js\";\nimport type {\n MenuContextValue,\n MenuOpenAtOptions,\n MenuOpenFocus,\n MenuPlacement,\n} from \"./menu-context.js\";\nimport { isRtl } from \"./menu-dom.js\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n /**\n * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the\n * pointer rather than against the Trigger.\n */\n readonly context: boolean;\n}\n\nexport interface MenuRootProps {\n /** Controlled open state. `undefined` means uncontrolled. */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the\n * closes the user asks a part for (Trigger toggle, an item's activation, ArrowLeft in a\n * submenu); a notification for dismissals (Escape, a click outside, Tab, the parent menu\n * closing). May be a Server Function. A `setState` placed after your own `await` needs\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /** Arrow keys wrap from the last item to the first and back. Default `true`. */\n loop?: boolean;\n /** Submenu only: milliseconds from hovering the SubmenuTrigger to the open. Default 100. */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close. Default 150.\n */\n closeDelay?: number;\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are transitions (pending Trigger, items render from committed state,\n * `showPopover()` / `hidePopover()` once the change has committed); dismissals are the\n * browser's and `openChangeAction(false)` is a notification.\n */\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n const inRegion = use(MenuRegionContext);\n useDevWarning(\n parent !== null && !submenu && !inRegion,\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n // Placement of the current open (context-menu.md 3.1). Written urgently, not in a transition:\n // while closed it renders nothing visible, and a move of an open menu (4.3) answers the\n // right-click at once, where a transition would be entangled with any pending async action\n // (an item's, the open's) and the menu would stay at the old point until it settled.\n const [placement, setPlacement] = useState<MenuPlacement>(ANCHOR_PLACEMENT);\n const placementGeneration = useRef(0);\n // Set by `openAt` around its `requestOpen`: the dispatch is a point open.\n const pointDispatch = useRef(false);\n\n const popover = usePopoverRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n // Every other open (Trigger, foreign invoker, mount reconciliation) is anchored.\n if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);\n },\n });\n\n const { intended, requestOpen, popupRef } = popover;\n const openAt = useCallback(\n (point: { readonly x: number; readonly y: number }, options: MenuOpenAtOptions) => {\n const generation = ++placementGeneration.current;\n // The popup's direction picks the edge at the point (context-menu.md 4.6, conventions\n // 13.4): the popup element exists while closed and `direction` is inherited, so it\n // computes without a box. Stored, so the Popup's style stays a function of state.\n const popup = popupRef.current;\n setPlacement({\n kind: \"point\",\n x: point.x,\n y: point.y,\n generation,\n source: options.source,\n pointerId: options.pointerId,\n direction: popup !== null && isRtl(popup) ? \"rtl\" : \"ltr\",\n // A touch or pen open is placed above the finger (4.7); re-evaluated on every move.\n offset: options.offset,\n });\n const focus: MenuOpenFocus = { cause: \"first\", pointer: options.pointer };\n if (intended()) {\n // A move, or a right-click while the open is still pending: no dispatch. The re-show\n // (or the open being shown) focuses the first item by this event's modality.\n openCause.current = focus;\n return;\n }\n nextCause.current = focus;\n pointDispatch.current = true;\n try {\n requestOpen(options.event, \"activate\");\n } finally {\n pointDispatch.current = false;\n }\n },\n [intended, requestOpen, popupRef],\n );\n const resetPlacement = useCallback((generation: number) => {\n setPlacement((current) =>\n current.kind === \"point\" && current.generation === generation ? ANCHOR_PLACEMENT : current,\n );\n }, []);\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // `popover` is memoised by `usePopoverRoot` (#48) and the other members are stable, so this\n // changes only with the open state, pending and the props listed below.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n context: popover.optimistic && placement.kind === \"point\",\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqFA,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;AAEtE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,OAAO,IAAI,eAAe;CAEhC,MAAM,aAAa,SAAS,OAAO,KAAK,OAAO;CAC/C,MAAM,UAAU,eAAe;CAE/B,cACE,CAAC,YAAY,UAAU,KAAA,KAAa,eAAe,KAAA,IACnD,yIAEF;CACA,MAAM,WAAW,IAAI,iBAAiB;CACtC,cACE,WAAW,QAAQ,CAAC,WAAW,CAAC,UAChC,gIAEF;CAEA,MAAM,SAAS,eAAe;CAG9B,MAAM,YAAY,OAA6B,IAAI;CACnD,MAAM,YAAY,OAA6B,IAAI;CAMnD,MAAM,CAAC,WAAW,gBAAgB,SAAwB,gBAAgB;CAC1E,MAAM,sBAAsB,OAAO,CAAC;CAEpC,MAAM,gBAAgB,OAAO,KAAK;CAElC,MAAM,UAAU,eAAsC;EACpD,WAAW;EACX,MAAM;EACN,MAAM;EACN;EACA;EACA;EACA,aAAa,SAAS;GAEpB,OAAO,OAAO;GACd,IAAI,MAAM,UAAU,UAAU,UAAU,WAAW;GACnD,UAAU,UAAU;GAEpB,IAAI,QAAQ,CAAC,cAAc,SAAS,aAAa,gBAAgB;EACnE;CACF,CAAC;CAED,MAAM,EAAE,UAAU,aAAa,aAAa;CAC5C,MAAM,SAAS,aACZ,OAAmD,YAA+B;EACjF,MAAM,aAAa,EAAE,oBAAoB;EAIzC,MAAM,QAAQ,SAAS;EACvB,aAAa;GACX,MAAM;GACN,GAAG,MAAM;GACT,GAAG,MAAM;GACT;GACA,QAAQ,QAAQ;GAChB,WAAW,QAAQ;GACnB,WAAW,UAAU,QAAQ,MAAM,KAAK,IAAI,QAAQ;GAEpD,QAAQ,QAAQ;EAClB,CAAC;EACD,MAAM,QAAuB;GAAE,OAAO;GAAS,SAAS,QAAQ;EAAQ;EACxE,IAAI,SAAS,GAAG;GAGd,UAAU,UAAU;GACpB;EACF;EACA,UAAU,UAAU;EACpB,cAAc,UAAU;EACxB,IAAI;GACF,YAAY,QAAQ,OAAO,UAAU;EACvC,UAAU;GACR,cAAc,UAAU;EAC1B;CACF,GACA;EAAC;EAAU;EAAa;CAAQ,CAClC;CACA,MAAM,iBAAiB,aAAa,eAAuB;EACzD,cAAc,YACZ,QAAQ,SAAS,WAAW,QAAQ,eAAe,aAAa,mBAAmB,OACrF;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,eAAe,aAAa,OAA+B,UAAU,UAAU;EACnF,UAAU,UAAU;GAAE;GAAO;EAAQ;CACvC,GAAG,CAAC,CAAC;CACL,MAAM,gBAAgB,kBAAkB;EACtC,MAAM,QAAQ,UAAU,WAAW;EACnC,UAAU,UAAU;EACpB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,SAAS;CAC/B,MAAM,qBAAqB,cAAc;CAGzC,MAAM,QAAQ,cAAgC;EAC5C,MAAM,OAAyB;GAC7B;GACA;GAEA,IAAI,OAAO;IACT,OAAO,YAAY,QAAQ;GAC7B;GACA,QAAQ;GACR;GACA,OAAO;GACP,YAAY;GACZ,WAAW,GAAG,QAAQ,IAAI,MAAM;GAChC;GACA;GACA;GACA;GACA;GACA;EACF;EACA,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;EACA,SAAS,QAAQ,cAAc,UAAU,SAAS;CACpD;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"menu-submenu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"mappings":";;;;;YAoBY,0BAA0B;iBAErB,gCAAgC,KAC/C;EAYA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,qBACd,UACA,OACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBARV"}
1
+ {"version":3,"file":"menu-submenu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"mappings":";;;;;YAuBY,0BAA0B;iBAErB,gCAAgC,KAC/C;EAYA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,qBACd,UACA,OACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBARV"}
@@ -1,12 +1,15 @@
1
1
  "use client";
2
2
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
3
+ import { mergeRefs } from "../internal/merge-props.mjs";
3
4
  import { useRender } from "../internal/use-render.mjs";
5
+ import { useLatest } from "../internal/use-latest.mjs";
4
6
  import { usePopoverTrigger } from "../internal/use-popover-trigger.mjs";
5
- import { useMenuContext } from "./menu-context.mjs";
7
+ import { registerSubmenuHover, useMenuContext } from "./menu-context.mjs";
6
8
  import { hasModifier, isRtl } from "./menu-dom.mjs";
7
9
  import { useMenuItem } from "./use-menu-item.mjs";
8
10
  import { scheduleHoverClose } from "./menu-hover.mjs";
9
11
  import { openMenuWithFocus } from "./menu-trigger.mjs";
12
+ import { useCallback, useMemo } from "react";
10
13
  //#region src/menu/menu-submenu-trigger.tsx
11
14
  /**
12
15
  * The item that opens a submenu: an item of the parent menu (`role="menuitem"`, roving
@@ -39,7 +42,26 @@ function MenuSubmenuTrigger({ disabled = false, label, className, style, childre
39
42
  event.preventDefault();
40
43
  open(event.nativeEvent);
41
44
  };
42
- const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {
45
+ const hoverEnter = (native) => {
46
+ if (disabled) return;
47
+ menu.timers.open(menu.delay, () => {
48
+ menu.setOpenCause("none");
49
+ menu.popover.requestOpen(native, "activate");
50
+ });
51
+ };
52
+ const hoverLeave = (native) => {
53
+ if (menu.popover.intended()) scheduleHoverClose(menu, native);
54
+ else menu.timers.cancel();
55
+ };
56
+ const latestHover = useLatest({
57
+ enter: hoverEnter,
58
+ leave: hoverLeave
59
+ });
60
+ const hoverRef = useCallback((element) => registerSubmenuHover(element, {
61
+ enter: (event) => latestHover.current.enter(event),
62
+ leave: (event) => latestHover.current.leave(event)
63
+ }), [latestHover]);
64
+ const { state, libraryProps, ref: triggerRef } = usePopoverTrigger(menu.popover, {
43
65
  part: "Menu.SubmenuTrigger",
44
66
  disabled,
45
67
  render,
@@ -51,21 +73,15 @@ function MenuSubmenuTrigger({ disabled = false, label, className, style, childre
51
73
  },
52
74
  onPointerMove: item.libraryProps.onPointerMove,
53
75
  onPointerEnter: (event) => {
54
- if (disabled || event.pointerType === "touch") return;
55
- const native = event.nativeEvent;
56
- menu.timers.open(menu.delay, () => {
57
- menu.setOpenCause("none");
58
- menu.popover.requestOpen(native, "activate");
59
- });
76
+ if (event.pointerType !== "touch") hoverEnter(event.nativeEvent);
60
77
  },
61
78
  onPointerLeave: (event) => {
62
- if (event.pointerType === "touch") return;
63
- if (menu.popover.intended()) scheduleHoverClose(menu, event.nativeEvent);
64
- else menu.timers.cancel();
79
+ if (event.pointerType !== "touch") hoverLeave(event.nativeEvent);
65
80
  }
66
81
  },
67
82
  activate: (event) => open(event.nativeEvent)
68
83
  });
84
+ const ref = useMemo(() => mergeRefs(triggerRef, hoverRef), [triggerRef, hoverRef]);
69
85
  return useRender({
70
86
  defaultElement: "button",
71
87
  render,
@@ -1 +1 @@
1
- {"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`commandfor`,\n * `command=\"toggle-popover\"`, `aria-haspopup=\"menu\"`, `aria-expanded`). ArrowRight (ArrowLeft in\n * RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens\n * the submenu after the Root's `delay` and leaves focus where it is.\n *\n * Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `commandfor`, `command`,\n * `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`) and the item's (`role`,\n * `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,\n * `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).\n */\nexport function MenuSubmenuTrigger({\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuSubmenuTriggerProps) {\n const menu = useMenuContext(\"Menu.SubmenuTrigger\");\n useDevWarning(\n !menu.submenu,\n \"Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root \" +\n \"inside the parent's Menu.Popup.\",\n );\n\n const open = (event: Event) => openMenuWithFocus(menu, event, \"first\");\n\n // The item half: role, roving tabindex, aria-disabled, Enter / Space, pointer focus. Its\n // activation is the click, which the trigger half handles (`activate` below).\n const item = useMenuItem({\n part: \"Menu.SubmenuTrigger\",\n role: \"menuitem\",\n disabled,\n label,\n activate: open,\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.defaultPrevented || hasModifier(event) || disabled) return;\n const parentPopup = event.currentTarget.closest('[role=\"menu\"]');\n const forward = parentPopup !== null && isRtl(parentPopup) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== forward) return;\n event.preventDefault();\n open(event.nativeEvent);\n };\n\n const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {\n part: \"Menu.SubmenuTrigger\",\n disabled,\n render,\n disabledAs: \"aria\",\n // Item first (Enter / Space activation, pointer focus), then the submenu keys.\n handlers: {\n onKeyDown: (event) => {\n item.libraryProps.onKeyDown(event);\n onKeyDown(event);\n },\n onPointerMove: item.libraryProps.onPointerMove,\n onPointerEnter: (event: PointerEvent<HTMLButtonElement>) => {\n if (disabled || event.pointerType === \"touch\") return;\n const native = event.nativeEvent;\n menu.timers.open(menu.delay, () => {\n menu.setOpenCause(\"none\");\n menu.popover.requestOpen(native, \"activate\");\n });\n },\n onPointerLeave: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType === \"touch\") return;\n // Leaving before the open delay cancels it; leaving an open submenu's trigger starts the\n // close delay (cancelled by entering the submenu).\n if (menu.popover.intended()) scheduleHoverClose(menu, event.nativeEvent);\n else menu.timers.cancel();\n },\n },\n // A click opens (or moves focus into the open submenu); it never closes.\n activate: (event) => open(event.nativeEvent),\n });\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n role: item.libraryProps.role,\n tabIndex: item.libraryProps.tabIndex,\n \"data-typeahead\": item.libraryProps[\"data-typeahead\"],\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuSubmenuTrigger.displayName = \"MenuSubmenuTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,mBAAmB,EACjC,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,eAAe,qBAAqB;CACjD,cACE,CAAC,KAAK,SACN,4HAEF;CAEA,MAAM,QAAQ,UAAiB,kBAAkB,MAAM,OAAO,OAAO;CAIrE,MAAM,OAAO,YAAY;EACvB,MAAM;EACN,MAAM;EACN;EACA;EACA,UAAU;CACZ,CAAC;CAED,MAAM,aAAa,UAA4C;EAC7D,IAAI,MAAM,oBAAoB,YAAY,KAAK,KAAK,UAAU;EAC9D,MAAM,cAAc,MAAM,cAAc,QAAQ,iBAAe;EAC/D,MAAM,UAAU,gBAAgB,QAAQ,MAAM,WAAW,IAAI,cAAc;EAC3E,IAAI,MAAM,QAAQ,SAAS;EAC3B,MAAM,eAAe;EACrB,KAAK,MAAM,WAAW;CACxB;CAEA,MAAM,EAAE,OAAO,cAAc,QAAQ,kBAAkB,KAAK,SAAS;EACnE,MAAM;EACN;EACA;EACA,YAAY;EAEZ,UAAU;GACR,YAAY,UAAU;IACpB,KAAK,aAAa,UAAU,KAAK;IACjC,UAAU,KAAK;GACjB;GACA,eAAe,KAAK,aAAa;GACjC,iBAAiB,UAA2C;IAC1D,IAAI,YAAY,MAAM,gBAAgB,SAAS;IAC/C,MAAM,SAAS,MAAM;IACrB,KAAK,OAAO,KAAK,KAAK,aAAa;KACjC,KAAK,aAAa,MAAM;KACxB,KAAK,QAAQ,YAAY,QAAQ,UAAU;IAC7C,CAAC;GACH;GACA,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS;IAGnC,IAAI,KAAK,QAAQ,SAAS,GAAG,mBAAmB,MAAM,MAAM,WAAW;SAClE,KAAK,OAAO,OAAO;GAC1B;EACF;EAEA,WAAW,UAAU,KAAK,MAAM,WAAW;CAC7C,CAAC;CAED,OAAO,UAAoE;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,MAAM,KAAK,aAAa;GACxB,UAAU,KAAK,aAAa;GAC5B,kBAAkB,KAAK,aAAa;GACpC,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
1
+ {"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useMemo } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { mergeRefs } from \"../internal/merge-props.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { registerSubmenuHover, useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`commandfor`,\n * `command=\"toggle-popover\"`, `aria-haspopup=\"menu\"`, `aria-expanded`). ArrowRight (ArrowLeft in\n * RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens\n * the submenu after the Root's `delay` and leaves focus where it is.\n *\n * Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `commandfor`, `command`,\n * `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`) and the item's (`role`,\n * `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,\n * `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).\n */\nexport function MenuSubmenuTrigger({\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuSubmenuTriggerProps) {\n const menu = useMenuContext(\"Menu.SubmenuTrigger\");\n useDevWarning(\n !menu.submenu,\n \"Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root \" +\n \"inside the parent's Menu.Popup.\",\n );\n\n const open = (event: Event) => openMenuWithFocus(menu, event, \"first\");\n\n // The item half: role, roving tabindex, aria-disabled, Enter / Space, pointer focus. Its\n // activation is the click, which the trigger half handles (`activate` below).\n const item = useMenuItem({\n part: \"Menu.SubmenuTrigger\",\n role: \"menuitem\",\n disabled,\n label,\n activate: open,\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.defaultPrevented || hasModifier(event) || disabled) return;\n const parentPopup = event.currentTarget.closest('[role=\"menu\"]');\n const forward = parentPopup !== null && isRtl(parentPopup) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== forward) return;\n event.preventDefault();\n open(event.nativeEvent);\n };\n\n // Hover intent (design/components/menu.md 7), shared by the pointer handlers and a\n // press-drag-release gesture of a context menu, whose captured pointer never enters this element\n // (context-menu.md 2.6).\n const hoverEnter = (native: Event) => {\n if (disabled) return;\n menu.timers.open(menu.delay, () => {\n menu.setOpenCause(\"none\");\n menu.popover.requestOpen(native, \"activate\");\n });\n };\n const hoverLeave = (native: Event) => {\n // Leaving before the open delay cancels it; leaving an open submenu's trigger starts the\n // close delay (cancelled by entering the submenu).\n if (menu.popover.intended()) scheduleHoverClose(menu, native);\n else menu.timers.cancel();\n };\n const latestHover = useLatest({ enter: hoverEnter, leave: hoverLeave });\n const hoverRef = useCallback(\n (element: HTMLElement) =>\n registerSubmenuHover(element, {\n enter: (event) => latestHover.current.enter(event),\n leave: (event) => latestHover.current.leave(event),\n }),\n [latestHover],\n );\n\n const {\n state,\n libraryProps,\n ref: triggerRef,\n } = usePopoverTrigger(menu.popover, {\n part: \"Menu.SubmenuTrigger\",\n disabled,\n render,\n disabledAs: \"aria\",\n // Item first (Enter / Space activation, pointer focus), then the submenu keys.\n handlers: {\n onKeyDown: (event) => {\n item.libraryProps.onKeyDown(event);\n onKeyDown(event);\n },\n onPointerMove: item.libraryProps.onPointerMove,\n onPointerEnter: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType !== \"touch\") hoverEnter(event.nativeEvent);\n },\n onPointerLeave: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType !== \"touch\") hoverLeave(event.nativeEvent);\n },\n },\n // A click opens (or moves focus into the open submenu); it never closes.\n activate: (event) => open(event.nativeEvent),\n });\n const ref = useMemo(() => mergeRefs(triggerRef, hoverRef), [triggerRef, hoverRef]);\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n role: item.libraryProps.role,\n tabIndex: item.libraryProps.tabIndex,\n \"data-typeahead\": item.libraryProps[\"data-typeahead\"],\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuSubmenuTrigger.displayName = \"MenuSubmenuTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,mBAAmB,EACjC,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,eAAe,qBAAqB;CACjD,cACE,CAAC,KAAK,SACN,4HAEF;CAEA,MAAM,QAAQ,UAAiB,kBAAkB,MAAM,OAAO,OAAO;CAIrE,MAAM,OAAO,YAAY;EACvB,MAAM;EACN,MAAM;EACN;EACA;EACA,UAAU;CACZ,CAAC;CAED,MAAM,aAAa,UAA4C;EAC7D,IAAI,MAAM,oBAAoB,YAAY,KAAK,KAAK,UAAU;EAC9D,MAAM,cAAc,MAAM,cAAc,QAAQ,iBAAe;EAC/D,MAAM,UAAU,gBAAgB,QAAQ,MAAM,WAAW,IAAI,cAAc;EAC3E,IAAI,MAAM,QAAQ,SAAS;EAC3B,MAAM,eAAe;EACrB,KAAK,MAAM,WAAW;CACxB;CAKA,MAAM,cAAc,WAAkB;EACpC,IAAI,UAAU;EACd,KAAK,OAAO,KAAK,KAAK,aAAa;GACjC,KAAK,aAAa,MAAM;GACxB,KAAK,QAAQ,YAAY,QAAQ,UAAU;EAC7C,CAAC;CACH;CACA,MAAM,cAAc,WAAkB;EAGpC,IAAI,KAAK,QAAQ,SAAS,GAAG,mBAAmB,MAAM,MAAM;OACvD,KAAK,OAAO,OAAO;CAC1B;CACA,MAAM,cAAc,UAAU;EAAE,OAAO;EAAY,OAAO;CAAW,CAAC;CACtE,MAAM,WAAW,aACd,YACC,qBAAqB,SAAS;EAC5B,QAAQ,UAAU,YAAY,QAAQ,MAAM,KAAK;EACjD,QAAQ,UAAU,YAAY,QAAQ,MAAM,KAAK;CACnD,CAAC,GACH,CAAC,WAAW,CACd;CAEA,MAAM,EACJ,OACA,cACA,KAAK,eACH,kBAAkB,KAAK,SAAS;EAClC,MAAM;EACN;EACA;EACA,YAAY;EAEZ,UAAU;GACR,YAAY,UAAU;IACpB,KAAK,aAAa,UAAU,KAAK;IACjC,UAAU,KAAK;GACjB;GACA,eAAe,KAAK,aAAa;GACjC,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS,WAAW,MAAM,WAAW;GACjE;GACA,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS,WAAW,MAAM,WAAW;GACjE;EACF;EAEA,WAAW,UAAU,KAAK,MAAM,WAAW;CAC7C,CAAC;CACD,MAAM,MAAM,cAAc,UAAU,YAAY,QAAQ,GAAG,CAAC,YAAY,QAAQ,CAAC;CAEjF,OAAO,UAAoE;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,MAAM,KAAK,aAAa;GACxB,UAAU,KAAK,aAAa;GAC5B,kBAAkB,KAAK,aAAa;GACpC,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
@@ -1,22 +1,34 @@
1
1
  import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
2
3
  import { CSSProperties, ComponentPropsWithRef, ReactNode, RefObject, ViewTransitionClass } from "react";
3
4
  //#region src/popover/popover-popup.d.ts
4
- export type PopoverSide = "top" | "bottom" | "left" | "right";
5
- export type PopoverAlign = "start" | "center" | "end";
5
+ /** `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). */
6
+ export type PopoverSide = AnchorSide;
7
+ export type PopoverAlign = AnchorAlign;
6
8
  export interface PopoverPopupState {
7
9
  /** Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the DOM truth. */
8
10
  readonly open: boolean;
11
+ /**
12
+ * While shown: the physical side the browser placed the popup on (after any fallback flip;
13
+ * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`.
14
+ */
9
15
  readonly side: PopoverSide | null;
16
+ /** While shown: the resolved alignment; otherwise the `align` prop. */
10
17
  readonly align: PopoverAlign;
11
18
  }
12
19
  export interface PopoverPopupProps extends Omit<ComponentPropsWithRef<"dialog">, "id" | "popover" | "open" | "aria-modal" | "onToggle" | "onBeforeToggle" | "className" | "style" | "children"> {
13
20
  /**
14
21
  * Placement relative to the Trigger through inline `position-area`, with
15
- * `position-try-fallbacks` flipping it when it does not fit. Default `"bottom"`. `null` emits
16
- * no inline positioning (and no `data-side` / `data-align`), so a stylesheet owns placement.
22
+ * `position-try-fallbacks` flipping it when it does not fit. Default `"bottom"`.
23
+ * `"inline-start"` / `"inline-end"` follow the popup's direction. `null` emits no inline
24
+ * positioning (and no `data-side` / `data-align`), so a stylesheet owns placement.
17
25
  */
18
26
  side?: PopoverSide | null;
19
- /** Alignment along the side. Default `"center"`. Ignored when `side` is `null`. */
27
+ /**
28
+ * Alignment along the side. Default `"center"`. On a top / bottom side `start` / `end` are
29
+ * inline-relative (mirrored under `direction: rtl`); on the other sides the top / bottom
30
+ * edges. Ignored when `side` is `null`.
31
+ */
20
32
  align?: PopoverAlign;
21
33
  /**
22
34
  * Library mode: what happens to the children while the popover is closed.
@@ -62,7 +74,9 @@ export interface PopoverPopupProps extends Omit<ComponentPropsWithRef<"dialog">,
62
74
  * The popover itself: a `<dialog popover="auto" aria-modal="false" role="dialog">` with the id
63
75
  * the Trigger's `commandfor` names, placed against the Trigger with CSS Anchor Positioning and
64
76
  * wired to Title and Description through `aria-labelledby` / `aria-describedby`. Style it with
65
- * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
77
+ * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While shown, those are
78
+ * where the browser placed it (the applied `position-try-fallbacks` option; conventions 13.2),
79
+ * in both modes; otherwise the requested values.
66
80
  *
67
81
  * In library mode the children render from committed state, so content that suspends keeps the
68
82
  * popover closed (and the Trigger pending) until it is ready; `showPopover({ source: trigger })`
@@ -74,7 +88,7 @@ export interface PopoverPopupProps extends Omit<ComponentPropsWithRef<"dialog">,
74
88
  * `aria-describedby` (token-merged), and `data-side` / `data-align` unless `side` is `null`.
75
89
  * `role` is a default (`"dialog"`) the consumer may override.
76
90
  */
77
- export declare function PopoverPopup({ side, align, keepMounted, initialFocus, transition, className, style, children, render, ...rest }: PopoverPopupProps): ReactNode;
91
+ export declare function PopoverPopup({ side: sideProp, align: alignProp, keepMounted, initialFocus, transition, className, style, children, render, ...rest }: PopoverPopupProps): ReactNode;
78
92
  export declare namespace PopoverPopup {
79
93
  var displayName: string;
80
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"popover-popup.d.mts","names":[],"sources":["../../src/popover/popover-popup.tsx"],"mappings":";;;YAmBY;YACA;iBAEK;;WAEN;WACA,MAAM;WACN,OAAO;;iBAGD,0BAA0B,KACzC;;;;;;EAgBA,OAAO;;EAEP,QAAQ;;;;;;;;;;;EAWR;;;;;;;;;;EAUA,eAAe,UAAU;;;;;;;;;;;;;EAazB,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;wBAmBvC,eACd,MACA,OACA,aACA,cACA,YACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBAXJ"}
1
+ {"version":3,"file":"popover-popup.d.mts","names":[],"sources":["../../src/popover/popover-popup.tsx"],"mappings":";;;;;YAuBY,cAAc;YACd,eAAe;iBAEV;;WAEN;;;;;WAKA,MAAM;;WAEN,OAAO;;iBAGD,0BAA0B,KACzC;;;;;;;EAiBA,OAAO;;;;;;EAMP,QAAQ;;;;;;;;;;;EAWR;;;;;;;;;;EAUA,eAAe,UAAU;;;;;;;;;;;;;EAazB,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;wBAqBvC,eACd,MAAM,UACN,OAAO,WACP,aACA,cACA,YACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBAXJ"}
@@ -2,19 +2,23 @@
2
2
  import { ToolbarContext } from "../internal/toolbar-context.mjs";
3
3
  import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
4
4
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
5
+ import { mergeRefs } from "../internal/merge-props.mjs";
5
6
  import { resolveStateValue } from "../internal/render-element.mjs";
6
7
  import { useRender } from "../internal/use-render.mjs";
7
8
  import { POSITION_TRY_FALLBACKS, positionArea } from "../internal/anchor-position.mjs";
9
+ import { useResolvedPlacement } from "../internal/use-resolved-placement.mjs";
8
10
  import { PopoverPopupContext, usePopoverContext } from "./popover-context.mjs";
9
11
  import { usePopoverPopup } from "../internal/use-popover-popup.mjs";
10
- import { Activity } from "react";
12
+ import { Activity, useMemo } from "react";
11
13
  import { jsx } from "react/jsx-runtime";
12
14
  //#region src/popover/popover-popup.tsx
13
15
  /**
14
16
  * The popover itself: a `<dialog popover="auto" aria-modal="false" role="dialog">` with the id
15
17
  * the Trigger's `commandfor` names, placed against the Trigger with CSS Anchor Positioning and
16
18
  * wired to Title and Description through `aria-labelledby` / `aria-describedby`. Style it with
17
- * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
19
+ * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While shown, those are
20
+ * where the browser placed it (the applied `position-try-fallbacks` option; conventions 13.2),
21
+ * in both modes; otherwise the requested values.
18
22
  *
19
23
  * In library mode the children render from committed state, so content that suspends keeps the
20
24
  * popover closed (and the Trigger pending) until it is ready; `showPopover({ source: trigger })`
@@ -26,7 +30,7 @@ import { jsx } from "react/jsx-runtime";
26
30
  * `aria-describedby` (token-merged), and `data-side` / `data-align` unless `side` is `null`.
27
31
  * `role` is a default (`"dialog"`) the consumer may override.
28
32
  */
29
- function PopoverPopup({ side = "bottom", align = "center", keepMounted, initialFocus, transition, className, style, children, render, ...rest }) {
33
+ function PopoverPopup({ side: sideProp = "bottom", align: alignProp = "center", keepMounted, initialFocus, transition, className, style, children, render, ...rest }) {
30
34
  const ctx = usePopoverContext("Popover.Popup");
31
35
  const isLibrary = ctx.mode === "library";
32
36
  const { ids } = ctx;
@@ -38,6 +42,12 @@ function PopoverPopup({ side = "bottom", align = "center", keepMounted, initialF
38
42
  keepMounted,
39
43
  transition: isLibrary ? transition : void 0
40
44
  });
45
+ const placement = useResolvedPlacement({
46
+ side: sideProp,
47
+ align: alignProp
48
+ });
49
+ const { side, align } = placement;
50
+ const ref = useMemo(() => mergeRefs(setElement, placement.ref), [setElement, placement.ref]);
41
51
  const state = {
42
52
  open: ctx.committed,
43
53
  side,
@@ -76,8 +86,8 @@ function PopoverPopup({ side = "bottom", align = "center", keepMounted, initialF
76
86
  render,
77
87
  state,
78
88
  className,
79
- style: side === null ? style : (s) => ({
80
- positionArea: positionArea(side, align),
89
+ style: sideProp === null ? style : (s) => ({
90
+ positionArea: positionArea(sideProp, alignProp),
81
91
  positionTryFallbacks: POSITION_TRY_FALLBACKS,
82
92
  ...resolveStateValue(style, s)
83
93
  }),
@@ -87,7 +97,7 @@ function PopoverPopup({ side = "bottom", align = "center", keepMounted, initialF
87
97
  ...rest
88
98
  },
89
99
  libraryProps,
90
- ref: setElement
100
+ ref
91
101
  });
92
102
  return useTransitionBoundary("Popover.Popup", isLibrary ? transition : void 0, element);
93
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"popover-popup.mjs","names":[],"sources":["../../src/popover/popover-popup.tsx"],"sourcesContent":["\"use client\";\nimport { Activity } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n ViewTransitionClass,\n} from \"react\";\nimport { POSITION_TRY_FALLBACKS, positionArea } from \"../internal/anchor-position.js\";\nimport { ToolbarContext } from \"../internal/toolbar-context.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { PopoverPopupContext, usePopoverContext } from \"./popover-context.js\";\n\nexport type PopoverSide = \"top\" | \"bottom\" | \"left\" | \"right\";\nexport type PopoverAlign = \"start\" | \"center\" | \"end\";\n\nexport interface PopoverPopupState {\n /** Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n readonly side: PopoverSide | null;\n readonly align: PopoverAlign;\n}\n\nexport interface PopoverPopupProps extends Omit<\n ComponentPropsWithRef<\"dialog\">,\n | \"id\"\n | \"popover\"\n | \"open\"\n | \"aria-modal\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement relative to the Trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. Default `\"bottom\"`. `null` emits\n * no inline positioning (and no `data-side` / `data-align`), so a stylesheet owns placement.\n */\n side?: PopoverSide | null;\n /** Alignment along the side. Default `\"center\"`. Ignored when `side` is `null`. */\n align?: PopoverAlign;\n /**\n * Library mode: what happens to the children while the popover is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open until it is ready. Unmount waits for the popover's\n * exit animation (CSS), or happens in the close commit when `transition` is set.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped, pre-rendered at low priority. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted).\n */\n keepMounted?: boolean;\n /**\n * Element to focus when the popover opens: a ref, or a selector resolved inside the popup.\n * The library writes `autofocus` on it right before `showPopover()` and the platform focuses\n * it. Default: the platform's choice for a `<dialog>` (first focusable descendant; the popup\n * itself if none); for `render={<div />}` focus stays on the Trigger.\n *\n * In JS-free mode the browser opens the popover itself, so the attribute is written after\n * hydration and kept while mounted; before hydration only `autoFocus` in the markup works.\n */\n initialFocus?: RefObject<HTMLElement | null> | string;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the popover element\n * itself. Animates the opening commit, content changes while open, and every library-driven\n * close (Trigger, Close, controlled `open={false}`), in all engines; dismissals (Escape,\n * click outside) are the browser's and animate with CSS only. Ignored (dev warning) in JS-free\n * mode.\n *\n * Static: without `transition` the part renders no `<ViewTransition>`; changing it between\n * `undefined` and a value remounts the element. A Root inserted by a transition with\n * `transition` set on its Popup pays the page cross-fade (issue #35); a plain open does not,\n * because the children mount under the already-mounted popover element.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, PopoverPopupState>;\n style?: StateValue<CSSProperties | undefined, PopoverPopupState>;\n children?: StateValue<ReactNode, PopoverPopupState>;\n /** A `<dialog>` (default) or a `<div>` (focus stays on the Trigger). */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, PopoverPopupState>;\n}\n\n/**\n * The popover itself: a `<dialog popover=\"auto\" aria-modal=\"false\" role=\"dialog\">` with the id\n * the Trigger's `commandfor` names, placed against the Trigger with CSS Anchor Positioning and\n * wired to Title and Description through `aria-labelledby` / `aria-describedby`. Style it with\n * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.\n *\n * In library mode the children render from committed state, so content that suspends keeps the\n * popover closed (and the Trigger pending) until it is ready; `showPopover({ source: trigger })`\n * runs in the layout effect of the commit that mounted them, and a library-driven close runs\n * `hidePopover()` in the commit that ends it. Dismissals are the browser's: the native `toggle`\n * event becomes `openChangeAction(false, { reason: \"dismiss\" })`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `open`, `aria-modal`, `aria-labelledby` and\n * `aria-describedby` (token-merged), and `data-side` / `data-align` unless `side` is `null`.\n * `role` is a default (`\"dialog\"`) the consumer may override.\n */\nexport function PopoverPopup({\n side = \"bottom\",\n align = \"center\",\n keepMounted,\n initialFocus,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: PopoverPopupProps) {\n const ctx = usePopoverContext(\"Popover.Popup\");\n const isLibrary = ctx.mode === \"library\";\n const { ids } = ctx;\n\n useDevWarning(\n !isLibrary && transition !== undefined,\n \"Popover.Popup: `transition` has no effect in JS-free mode; the browser opens and closes the \" +\n \"popover outside any React transition. Animate it with CSS (`@starting-style`).\",\n );\n useDevWarning(\n !isLibrary && keepMounted === false,\n \"Popover.Popup: `keepMounted={false}` cannot be honoured in JS-free mode; the content is \" +\n \"always mounted so that the server HTML is complete.\",\n );\n\n const { setElement, visible, wrapContent } = usePopoverPopup(ctx, {\n part: \"Popover.Popup\",\n initialFocus,\n keepMounted,\n transition: isLibrary ? transition : undefined,\n });\n\n const state: PopoverPopupState = { open: ctx.committed, side, align };\n\n const content = (s: PopoverPopupState): ReactNode => {\n let node: ReactNode;\n if (!isLibrary) {\n node = resolveStateValue(children, s);\n } else if (keepMounted === true) {\n // The mode changes with committed state, inside the Root's transition (conventions 5.5);\n // it stays visible while an exit animation runs.\n node = (\n <Activity mode={visible ? \"visible\" : \"hidden\"}>\n {wrapContent(resolveStateValue(children, s))}\n </Activity>\n );\n } else {\n node = visible ? wrapContent(resolveStateValue(children, s)) : null;\n }\n // Popup content is not part of an enclosing Toolbar's sequence (the engine excludes\n // `[popover]`), so parts inside it must not see the Toolbar either.\n return (\n <PopoverPopupContext value={s}>\n <ToolbarContext value={null}>{node}</ToolbarContext>\n </PopoverPopupContext>\n );\n };\n\n const libraryProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n id: ids.popup,\n popover: \"auto\",\n // Never rendered: `showPopover()` does not set it, and an `open` attribute would show the\n // <dialog> outside the top layer. Owned so a `render` element cannot add it.\n open: undefined,\n // Chromium exposes a <dialog popover> as modal without it (research; issue #44).\n \"aria-modal\": \"false\",\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n const element = useRender<ComponentPropsWithRef<\"dialog\">, PopoverPopupState>({\n defaultElement: \"dialog\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins (design 8).\n style:\n side === null\n ? style\n : (s) => ({\n positionArea: positionArea(side, align),\n positionTryFallbacks: POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children: content,\n // `role` is a default the consumer's `rest` overrides (design 3.3): WebKit implements no\n // minimum role for `[popover]`, and a `<div>` popup needs it.\n props: { role: \"dialog\", ...rest },\n libraryProps,\n ref: setElement,\n });\n\n return useTransitionBoundary(\"Popover.Popup\", isLibrary ? transition : undefined, element);\n}\n\nPopoverPopup.displayName = \"PopoverPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0GA,SAAgB,aAAa,EAC3B,OAAO,UACP,QAAQ,UACR,aACA,cACA,YACA,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,QAAQ;CAEhB,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,4KAEF;CACA,cACE,CAAC,aAAa,gBAAgB,OAC9B,6IAEF;CAEA,MAAM,EAAE,YAAY,SAAS,gBAAgB,gBAAgB,KAAK;EAChE,MAAM;EACN;EACA;EACA,YAAY,YAAY,aAAa,KAAA;CACvC,CAAC;CAED,MAAM,QAA2B;EAAE,MAAM,IAAI;EAAW;EAAM;CAAM;CAEpE,MAAM,WAAW,MAAoC;EACnD,IAAI;EACJ,IAAI,CAAC,WACH,OAAO,kBAAkB,UAAU,CAAC;OAC/B,IAAI,gBAAgB,MAGzB,OACE,oBAAC,UAAD;GAAU,MAAM,UAAU,YAAY;GACnC,UAAA,YAAY,kBAAkB,UAAU,CAAC,CAAC;EACnC,CAAA;OAGZ,OAAO,UAAU,YAAY,kBAAkB,UAAU,CAAC,CAAC,IAAI;EAIjE,OACE,oBAAC,qBAAD;GAAqB,OAAO;GAC1B,UAAA,oBAAC,gBAAD;IAAgB,OAAO;IAAO,UAAA;GAAqB,CAAA;EAChC,CAAA;CAEzB;CAEA,MAAM,eAAiE;EACrE,IAAI,IAAI;EACR,SAAS;EAGT,MAAM,KAAA;EAEN,cAAc;EACd,mBAAmB,IAAI;EACvB,oBAAoB,IAAI;EAExB,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAM;CAChE;CAEA,MAAM,UAAU,UAA8D;EAC5E,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,SAAS,OACL,SACC,OAAO;GACN,cAAc,aAAa,MAAM,KAAK;GACtC,sBAAsB;GACtB,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACN,UAAU;EAGV,OAAO;GAAE,MAAM;GAAU,GAAG;EAAK;EACjC;EACA,KAAK;CACP,CAAC;CAED,OAAO,sBAAsB,iBAAiB,YAAY,aAAa,KAAA,GAAW,OAAO;AAC3F;AAEA,aAAa,cAAc"}
1
+ {"version":3,"file":"popover-popup.mjs","names":[],"sources":["../../src/popover/popover-popup.tsx"],"sourcesContent":["\"use client\";\nimport { Activity, useMemo } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n ViewTransitionClass,\n} from \"react\";\nimport { POSITION_TRY_FALLBACKS, positionArea } from \"../internal/anchor-position.js\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { mergeRefs } from \"../internal/merge-props.js\";\nimport { ToolbarContext } from \"../internal/toolbar-context.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useResolvedPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { PopoverPopupContext, usePopoverContext } from \"./popover-context.js\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). */\nexport type PopoverSide = AnchorSide;\nexport type PopoverAlign = AnchorAlign;\n\nexport interface PopoverPopupState {\n /** Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`.\n */\n readonly side: PopoverSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: PopoverAlign;\n}\n\nexport interface PopoverPopupProps extends Omit<\n ComponentPropsWithRef<\"dialog\">,\n | \"id\"\n | \"popover\"\n | \"open\"\n | \"aria-modal\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement relative to the Trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. Default `\"bottom\"`.\n * `\"inline-start\"` / `\"inline-end\"` follow the popup's direction. `null` emits no inline\n * positioning (and no `data-side` / `data-align`), so a stylesheet owns placement.\n */\n side?: PopoverSide | null;\n /**\n * Alignment along the side. Default `\"center\"`. On a top / bottom side `start` / `end` are\n * inline-relative (mirrored under `direction: rtl`); on the other sides the top / bottom\n * edges. Ignored when `side` is `null`.\n */\n align?: PopoverAlign;\n /**\n * Library mode: what happens to the children while the popover is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open until it is ready. Unmount waits for the popover's\n * exit animation (CSS), or happens in the close commit when `transition` is set.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped, pre-rendered at low priority. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted).\n */\n keepMounted?: boolean;\n /**\n * Element to focus when the popover opens: a ref, or a selector resolved inside the popup.\n * The library writes `autofocus` on it right before `showPopover()` and the platform focuses\n * it. Default: the platform's choice for a `<dialog>` (first focusable descendant; the popup\n * itself if none); for `render={<div />}` focus stays on the Trigger.\n *\n * In JS-free mode the browser opens the popover itself, so the attribute is written after\n * hydration and kept while mounted; before hydration only `autoFocus` in the markup works.\n */\n initialFocus?: RefObject<HTMLElement | null> | string;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the popover element\n * itself. Animates the opening commit, content changes while open, and every library-driven\n * close (Trigger, Close, controlled `open={false}`), in all engines; dismissals (Escape,\n * click outside) are the browser's and animate with CSS only. Ignored (dev warning) in JS-free\n * mode.\n *\n * Static: without `transition` the part renders no `<ViewTransition>`; changing it between\n * `undefined` and a value remounts the element. A Root inserted by a transition with\n * `transition` set on its Popup pays the page cross-fade (issue #35); a plain open does not,\n * because the children mount under the already-mounted popover element.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, PopoverPopupState>;\n style?: StateValue<CSSProperties | undefined, PopoverPopupState>;\n children?: StateValue<ReactNode, PopoverPopupState>;\n /** A `<dialog>` (default) or a `<div>` (focus stays on the Trigger). */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, PopoverPopupState>;\n}\n\n/**\n * The popover itself: a `<dialog popover=\"auto\" aria-modal=\"false\" role=\"dialog\">` with the id\n * the Trigger's `commandfor` names, placed against the Trigger with CSS Anchor Positioning and\n * wired to Title and Description through `aria-labelledby` / `aria-describedby`. Style it with\n * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While shown, those are\n * where the browser placed it (the applied `position-try-fallbacks` option; conventions 13.2),\n * in both modes; otherwise the requested values.\n *\n * In library mode the children render from committed state, so content that suspends keeps the\n * popover closed (and the Trigger pending) until it is ready; `showPopover({ source: trigger })`\n * runs in the layout effect of the commit that mounted them, and a library-driven close runs\n * `hidePopover()` in the commit that ends it. Dismissals are the browser's: the native `toggle`\n * event becomes `openChangeAction(false, { reason: \"dismiss\" })`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `open`, `aria-modal`, `aria-labelledby` and\n * `aria-describedby` (token-merged), and `data-side` / `data-align` unless `side` is `null`.\n * `role` is a default (`\"dialog\"`) the consumer may override.\n */\nexport function PopoverPopup({\n side: sideProp = \"bottom\",\n align: alignProp = \"center\",\n keepMounted,\n initialFocus,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: PopoverPopupProps) {\n const ctx = usePopoverContext(\"Popover.Popup\");\n const isLibrary = ctx.mode === \"library\";\n const { ids } = ctx;\n\n useDevWarning(\n !isLibrary && transition !== undefined,\n \"Popover.Popup: `transition` has no effect in JS-free mode; the browser opens and closes the \" +\n \"popover outside any React transition. Animate it with CSS (`@starting-style`).\",\n );\n useDevWarning(\n !isLibrary && keepMounted === false,\n \"Popover.Popup: `keepMounted={false}` cannot be honoured in JS-free mode; the content is \" +\n \"always mounted so that the server HTML is complete.\",\n );\n\n const { setElement, visible, wrapContent } = usePopoverPopup(ctx, {\n part: \"Popover.Popup\",\n initialFocus,\n keepMounted,\n transition: isLibrary ? transition : undefined,\n });\n\n // Resolved while shown, in library and JS-free mode alike (it hangs off the element's ref and\n // the platform's `toggle`, not off library state).\n const placement = useResolvedPlacement({ side: sideProp, align: alignProp });\n const { side, align } = placement;\n const ref = useMemo(() => mergeRefs(setElement, placement.ref), [setElement, placement.ref]);\n\n const state: PopoverPopupState = { open: ctx.committed, side, align };\n\n const content = (s: PopoverPopupState): ReactNode => {\n let node: ReactNode;\n if (!isLibrary) {\n node = resolveStateValue(children, s);\n } else if (keepMounted === true) {\n // The mode changes with committed state, inside the Root's transition (conventions 5.5);\n // it stays visible while an exit animation runs.\n node = (\n <Activity mode={visible ? \"visible\" : \"hidden\"}>\n {wrapContent(resolveStateValue(children, s))}\n </Activity>\n );\n } else {\n node = visible ? wrapContent(resolveStateValue(children, s)) : null;\n }\n // Popup content is not part of an enclosing Toolbar's sequence (the engine excludes\n // `[popover]`), so parts inside it must not see the Toolbar either.\n return (\n <PopoverPopupContext value={s}>\n <ToolbarContext value={null}>{node}</ToolbarContext>\n </PopoverPopupContext>\n );\n };\n\n const libraryProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n id: ids.popup,\n popover: \"auto\",\n // Never rendered: `showPopover()` does not set it, and an `open` attribute would show the\n // <dialog> outside the top layer. Owned so a `render` element cannot add it.\n open: undefined,\n // Chromium exposes a <dialog popover> as modal without it (research; issue #44).\n \"aria-modal\": \"false\",\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n const element = useRender<ComponentPropsWithRef<\"dialog\">, PopoverPopupState>({\n defaultElement: \"dialog\",\n render,\n state,\n className,\n // The inline placement is the requested one (the browser keeps choosing from it) and sits\n // under the consumer's style: the consumer wins (design 8).\n style:\n sideProp === null\n ? style\n : (s) => ({\n positionArea: positionArea(sideProp, alignProp),\n positionTryFallbacks: POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children: content,\n // `role` is a default the consumer's `rest` overrides (design 3.3): WebKit implements no\n // minimum role for `[popover]`, and a `<div>` popup needs it.\n props: { role: \"dialog\", ...rest },\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Popover.Popup\", isLibrary ? transition : undefined, element);\n}\n\nPopoverPopup.displayName = \"PopoverPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,SAAgB,aAAa,EAC3B,MAAM,WAAW,UACjB,OAAO,YAAY,UACnB,aACA,cACA,YACA,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,QAAQ;CAEhB,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,4KAEF;CACA,cACE,CAAC,aAAa,gBAAgB,OAC9B,6IAEF;CAEA,MAAM,EAAE,YAAY,SAAS,gBAAgB,gBAAgB,KAAK;EAChE,MAAM;EACN;EACA;EACA,YAAY,YAAY,aAAa,KAAA;CACvC,CAAC;CAID,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAU,OAAO;CAAU,CAAC;CAC3E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,MAAM,cAAc,UAAU,YAAY,UAAU,GAAG,GAAG,CAAC,YAAY,UAAU,GAAG,CAAC;CAE3F,MAAM,QAA2B;EAAE,MAAM,IAAI;EAAW;EAAM;CAAM;CAEpE,MAAM,WAAW,MAAoC;EACnD,IAAI;EACJ,IAAI,CAAC,WACH,OAAO,kBAAkB,UAAU,CAAC;OAC/B,IAAI,gBAAgB,MAGzB,OACE,oBAAC,UAAD;GAAU,MAAM,UAAU,YAAY;GACnC,UAAA,YAAY,kBAAkB,UAAU,CAAC,CAAC;EACnC,CAAA;OAGZ,OAAO,UAAU,YAAY,kBAAkB,UAAU,CAAC,CAAC,IAAI;EAIjE,OACE,oBAAC,qBAAD;GAAqB,OAAO;GAC1B,UAAA,oBAAC,gBAAD;IAAgB,OAAO;IAAO,UAAA;GAAqB,CAAA;EAChC,CAAA;CAEzB;CAEA,MAAM,eAAiE;EACrE,IAAI,IAAI;EACR,SAAS;EAGT,MAAM,KAAA;EAEN,cAAc;EACd,mBAAmB,IAAI;EACvB,oBAAoB,IAAI;EAExB,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAM;CAChE;CAEA,MAAM,UAAU,UAA8D;EAC5E,gBAAgB;EAChB;EACA;EACA;EAGA,OACE,aAAa,OACT,SACC,OAAO;GACN,cAAc,aAAa,UAAU,SAAS;GAC9C,sBAAsB;GACtB,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACN,UAAU;EAGV,OAAO;GAAE,MAAM;GAAU,GAAG;EAAK;EACjC;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,iBAAiB,YAAY,aAAa,KAAA,GAAW,OAAO;AAC3F;AAEA,aAAa,cAAc"}
@@ -1,20 +1,23 @@
1
1
  import "../internal/platform-attributes.mjs";
2
- import { TooltipAlign, TooltipPopup, TooltipPopupProps, TooltipPopupState, TooltipSide } from "./tooltip-popup.mjs";
3
- import { TooltipProvides } from "./tooltip-context.mjs";
2
+ import { TooltipAlign, TooltipProvides, TooltipSide } from "./tooltip-context.mjs";
3
+ import { TooltipArrow, TooltipArrowProps, TooltipArrowState } from "./tooltip-arrow.mjs";
4
+ import { TooltipPopup, TooltipPopupProps, TooltipPopupState } from "./tooltip-popup.mjs";
4
5
  import { TooltipRoot, TooltipRootProps, TooltipRootState } from "./tooltip-root.mjs";
5
6
  import { TooltipTrigger, TooltipTriggerProps, TooltipTriggerState } from "./tooltip-trigger.mjs";
6
7
  //#region src/tooltip/index.d.ts
7
8
  /**
8
9
  * Tooltip (WAI-ARIA APG Tooltip pattern): `Root` (no DOM) owns the id and the interaction,
9
10
  * `Trigger` (button) is hovered or focused, `Popup` (`div[popover] role="tooltip"`) lives in the
10
- * top layer and is placed with CSS Anchor Positioning. Open state is browser-owned: no `open`
11
- * prop, no action, style with `:popover-open`. Render the Popup immediately after the Trigger.
11
+ * top layer and is placed with CSS Anchor Positioning, `Arrow` (decorative `span`) echoes the
12
+ * Popup's resolved side. Open state is browser-owned: no `open` prop, no action, style with
13
+ * `:popover-open`. Render the Popup immediately after the Trigger.
12
14
  */
13
15
  export declare const Tooltip: {
14
16
  readonly Root: typeof TooltipRoot;
15
17
  readonly Trigger: typeof TooltipTrigger;
16
18
  readonly Popup: typeof TooltipPopup;
19
+ readonly Arrow: typeof TooltipArrow;
17
20
  };
18
21
  //#endregion
19
- export type { TooltipAlign, TooltipPopupProps, TooltipPopupState, TooltipProvides, TooltipRootProps, TooltipRootState, TooltipSide, TooltipTriggerProps, TooltipTriggerState };
22
+ export type { TooltipAlign, TooltipArrowProps, TooltipArrowState, TooltipPopupProps, TooltipPopupState, TooltipProvides, TooltipRootProps, TooltipRootState, TooltipSide, TooltipTriggerProps, TooltipTriggerState };
20
23
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/tooltip/index.ts"],"mappings":";;;;;;;;;;;;qBAaa;WACX,aAAI;WACJ,gBAAO;WACP,cAAK"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/tooltip/index.ts"],"mappings":";;;;;;;;;;;;;;qBAea;WACX,aAAI;WACJ,gBAAO;WACP,cAAK;WACL,cAAK"}
@@ -1,3 +1,4 @@
1
+ import { TooltipArrow } from "./tooltip-arrow.mjs";
1
2
  import { TooltipPopup } from "./tooltip-popup.mjs";
2
3
  import { TooltipRoot } from "./tooltip-root.mjs";
3
4
  import { TooltipTrigger } from "./tooltip-trigger.mjs";
@@ -5,13 +6,15 @@ import { TooltipTrigger } from "./tooltip-trigger.mjs";
5
6
  /**
6
7
  * Tooltip (WAI-ARIA APG Tooltip pattern): `Root` (no DOM) owns the id and the interaction,
7
8
  * `Trigger` (button) is hovered or focused, `Popup` (`div[popover] role="tooltip"`) lives in the
8
- * top layer and is placed with CSS Anchor Positioning. Open state is browser-owned: no `open`
9
- * prop, no action, style with `:popover-open`. Render the Popup immediately after the Trigger.
9
+ * top layer and is placed with CSS Anchor Positioning, `Arrow` (decorative `span`) echoes the
10
+ * Popup's resolved side. Open state is browser-owned: no `open` prop, no action, style with
11
+ * `:popover-open`. Render the Popup immediately after the Trigger.
10
12
  */
11
13
  const Tooltip = {
12
14
  Root: TooltipRoot,
13
15
  Trigger: TooltipTrigger,
14
- Popup: TooltipPopup
16
+ Popup: TooltipPopup,
17
+ Arrow: TooltipArrow
15
18
  };
16
19
  //#endregion
17
20
  export { Tooltip };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/tooltip/index.ts"],"sourcesContent":["// Ships the platform attribute typings with this subpath (conventions 7.4). Type-only: the\n// built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { TooltipPopup } from \"./tooltip-popup.js\";\nimport { TooltipRoot } from \"./tooltip-root.js\";\nimport { TooltipTrigger } from \"./tooltip-trigger.js\";\n\n/**\n * Tooltip (WAI-ARIA APG Tooltip pattern): `Root` (no DOM) owns the id and the interaction,\n * `Trigger` (button) is hovered or focused, `Popup` (`div[popover] role=\"tooltip\"`) lives in the\n * top layer and is placed with CSS Anchor Positioning. Open state is browser-owned: no `open`\n * prop, no action, style with `:popover-open`. Render the Popup immediately after the Trigger.\n */\nexport const Tooltip = {\n Root: TooltipRoot,\n Trigger: TooltipTrigger,\n Popup: TooltipPopup,\n} as const;\n\nexport type { TooltipRootProps, TooltipRootState, TooltipProvides } from \"./tooltip-root.js\";\nexport type { TooltipTriggerProps, TooltipTriggerState } from \"./tooltip-trigger.js\";\nexport type {\n TooltipPopupProps,\n TooltipPopupState,\n TooltipSide,\n TooltipAlign,\n} from \"./tooltip-popup.js\";\n"],"mappings":";;;;;;;;;;AAaA,MAAa,UAAU;CACrB,MAAM;CACN,SAAS;CACT,OAAO;AACT"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/tooltip/index.ts"],"sourcesContent":["// Ships the platform attribute typings with this subpath (conventions 7.4). Type-only: the\n// built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { TooltipArrow } from \"./tooltip-arrow.js\";\nimport { TooltipPopup } from \"./tooltip-popup.js\";\nimport { TooltipRoot } from \"./tooltip-root.js\";\nimport { TooltipTrigger } from \"./tooltip-trigger.js\";\n\n/**\n * Tooltip (WAI-ARIA APG Tooltip pattern): `Root` (no DOM) owns the id and the interaction,\n * `Trigger` (button) is hovered or focused, `Popup` (`div[popover] role=\"tooltip\"`) lives in the\n * top layer and is placed with CSS Anchor Positioning, `Arrow` (decorative `span`) echoes the\n * Popup's resolved side. Open state is browser-owned: no `open` prop, no action, style with\n * `:popover-open`. Render the Popup immediately after the Trigger.\n */\nexport const Tooltip = {\n Root: TooltipRoot,\n Trigger: TooltipTrigger,\n Popup: TooltipPopup,\n Arrow: TooltipArrow,\n} as const;\n\nexport type { TooltipRootProps, TooltipRootState, TooltipProvides } from \"./tooltip-root.js\";\nexport type { TooltipTriggerProps, TooltipTriggerState } from \"./tooltip-trigger.js\";\nexport type {\n TooltipPopupProps,\n TooltipPopupState,\n TooltipSide,\n TooltipAlign,\n} from \"./tooltip-popup.js\";\nexport type { TooltipArrowProps, TooltipArrowState } from \"./tooltip-arrow.js\";\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,UAAU;CACrB,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;AACT"}
@@ -0,0 +1,30 @@
1
+ import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import { TooltipAlign, TooltipSide } from "./tooltip-context.mjs";
3
+ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
4
+ //#region src/tooltip/tooltip-arrow.d.ts
5
+ export interface TooltipArrowState {
6
+ /** The Popup's side: resolved while shown (after any flip), requested otherwise. */
7
+ readonly side: TooltipSide | null;
8
+ readonly align: TooltipAlign;
9
+ }
10
+ export interface TooltipArrowProps extends Omit<ComponentPropsWithRef<"span">, "aria-hidden" | "className" | "style" | "children"> {
11
+ className?: StateValue<string | undefined, TooltipArrowState>;
12
+ style?: StateValue<CSSProperties | undefined, TooltipArrowState>;
13
+ children?: StateValue<ReactNode, TooltipArrowState>;
14
+ render?: RenderProp<ComponentPropsWithRef<"span">, TooltipArrowState>;
15
+ }
16
+ /**
17
+ * A decorative `<span aria-hidden="true">` inside `Tooltip.Popup` that draws nothing itself: it
18
+ * echoes the Popup's `data-side` / `data-align`, which are the **resolved** placement while the
19
+ * tooltip is shown (design 7.4), so CSS keyed on `[data-side]` puts it on the edge that faces the
20
+ * trigger, after a `position-try-fallbacks` flip as well.
21
+ *
22
+ * Owned keys (conventions 1.2): `aria-hidden`, and `data-side` / `data-align` unless the Popup's
23
+ * `side` is `null`.
24
+ */
25
+ export declare function TooltipArrow({ className, style, children, render, ...rest }: TooltipArrowProps): ReactNode;
26
+ export declare namespace TooltipArrow {
27
+ var displayName: string;
28
+ }
29
+ //#endregion
30
+ //# sourceMappingURL=tooltip-arrow.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip-arrow.d.mts","names":[],"sources":["../../src/tooltip/tooltip-arrow.tsx"],"mappings":";;;;iBASiB;;WAEN,MAAM;WACN,OAAO;;iBAGD,0BAA0B,KACzC;EAGA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,+BAA+B;;;;;;;;;;;wBAYrC,eAAe,WAAW,OAAO,UAAU,WAAW,QAAQ,oBAAiB;yBAA/E"}
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ import { useRender } from "../internal/use-render.mjs";
3
+ import { TooltipPopupContext } from "./tooltip-context.mjs";
4
+ import { use } from "react";
5
+ //#region src/tooltip/tooltip-arrow.tsx
6
+ /**
7
+ * A decorative `<span aria-hidden="true">` inside `Tooltip.Popup` that draws nothing itself: it
8
+ * echoes the Popup's `data-side` / `data-align`, which are the **resolved** placement while the
9
+ * tooltip is shown (design 7.4), so CSS keyed on `[data-side]` puts it on the edge that faces the
10
+ * trigger, after a `position-try-fallbacks` flip as well.
11
+ *
12
+ * Owned keys (conventions 1.2): `aria-hidden`, and `data-side` / `data-align` unless the Popup's
13
+ * `side` is `null`.
14
+ */
15
+ function TooltipArrow({ className, style, children, render, ...rest }) {
16
+ const placement = use(TooltipPopupContext);
17
+ if (placement === null) throw new Error("Tooltip.Arrow must be rendered inside a Tooltip.Popup.");
18
+ const { side, align } = placement;
19
+ const state = {
20
+ side,
21
+ align
22
+ };
23
+ const libraryProps = {
24
+ "aria-hidden": true,
25
+ ...side !== null && {
26
+ "data-side": side,
27
+ "data-align": align
28
+ }
29
+ };
30
+ return useRender({
31
+ defaultElement: "span",
32
+ render,
33
+ state,
34
+ className,
35
+ style,
36
+ children,
37
+ props: rest,
38
+ libraryProps
39
+ });
40
+ }
41
+ TooltipArrow.displayName = "TooltipArrow";
42
+ //#endregion
43
+ export { TooltipArrow };
44
+
45
+ //# sourceMappingURL=tooltip-arrow.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip-arrow.mjs","names":[],"sources":["../../src/tooltip/tooltip-arrow.tsx"],"sourcesContent":["\"use client\";\nimport { use } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { TooltipPopupContext } from \"./tooltip-context.js\";\nimport type { TooltipAlign, TooltipSide } from \"./tooltip-context.js\";\n\nexport interface TooltipArrowState {\n /** The Popup's side: resolved while shown (after any flip), requested otherwise. */\n readonly side: TooltipSide | null;\n readonly align: TooltipAlign;\n}\n\nexport interface TooltipArrowProps extends Omit<\n ComponentPropsWithRef<\"span\">,\n \"aria-hidden\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, TooltipArrowState>;\n style?: StateValue<CSSProperties | undefined, TooltipArrowState>;\n children?: StateValue<ReactNode, TooltipArrowState>;\n render?: RenderProp<ComponentPropsWithRef<\"span\">, TooltipArrowState>;\n}\n\n/**\n * A decorative `<span aria-hidden=\"true\">` inside `Tooltip.Popup` that draws nothing itself: it\n * echoes the Popup's `data-side` / `data-align`, which are the **resolved** placement while the\n * tooltip is shown (design 7.4), so CSS keyed on `[data-side]` puts it on the edge that faces the\n * trigger, after a `position-try-fallbacks` flip as well.\n *\n * Owned keys (conventions 1.2): `aria-hidden`, and `data-side` / `data-align` unless the Popup's\n * `side` is `null`.\n */\nexport function TooltipArrow({ className, style, children, render, ...rest }: TooltipArrowProps) {\n const placement = use(TooltipPopupContext);\n if (placement === null) {\n throw new Error(\"Tooltip.Arrow must be rendered inside a Tooltip.Popup.\");\n }\n const { side, align } = placement;\n const state: TooltipArrowState = { side, align };\n\n const libraryProps: ComponentPropsWithRef<\"span\"> & DataAttributes = {\n \"aria-hidden\": true,\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n return useRender<ComponentPropsWithRef<\"span\">, TooltipArrowState>({\n defaultElement: \"span\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n });\n}\n\nTooltipArrow.displayName = \"TooltipArrow\";\n"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAgB,aAAa,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAA2B;CAC/F,MAAM,YAAY,IAAI,mBAAmB;CACzC,IAAI,cAAc,MAChB,MAAM,IAAI,MAAM,wDAAwD;CAE1E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,QAA2B;EAAE;EAAM;CAAM;CAE/C,MAAM,eAA+D;EACnE,eAAe;EACf,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAM;CAChE;CAEA,OAAO,UAA4D;EACjE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
@@ -1,4 +1,11 @@
1
+ import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
1
2
  //#region src/tooltip/tooltip-context.d.ts
3
+ /**
4
+ * `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). While
5
+ * shown, the state carries the resolved physical side.
6
+ */
7
+ export type TooltipSide = AnchorSide;
8
+ export type TooltipAlign = AnchorAlign;
2
9
  /** Which accessibility relation the tooltip provides for its trigger (design section 5.1). */
3
10
  export type TooltipProvides = "description" | "name";
4
11
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-context.d.mts","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"mappings":";;YAIY"}
1
+ {"version":3,"file":"tooltip-context.d.mts","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"mappings":";;;;;;YAQY,cAAc;YACd,eAAe;;YAGf"}
@@ -2,12 +2,13 @@
2
2
  import { createContext, use } from "react";
3
3
  //#region src/tooltip/tooltip-context.ts
4
4
  const TooltipContext = createContext(null);
5
+ const TooltipPopupContext = createContext(null);
5
6
  function useTooltipContext(part) {
6
7
  const context = use(TooltipContext);
7
8
  if (context === null) throw new Error(`${part} must be rendered inside a Tooltip.Root.`);
8
9
  return context;
9
10
  }
10
11
  //#endregion
11
- export { TooltipContext, useTooltipContext };
12
+ export { TooltipContext, TooltipPopupContext, useTooltipContext };
12
13
 
13
14
  //# sourceMappingURL=tooltip-context.mjs.map