@funstack/ui 0.1.0-alpha.21 → 0.1.0-alpha.22

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 (83) hide show
  1. package/dist/docs/components/menu.md +1 -1
  2. package/dist/docs/components/menubar.md +309 -0
  3. package/dist/docs/components/meter.md +1 -1
  4. package/dist/docs/components/navigation-menu.md +501 -0
  5. package/dist/docs/components/number-field.md +2 -2
  6. package/dist/docs/components/otp-field.md +8 -1
  7. package/dist/docs/components/progress.md +1 -1
  8. package/dist/docs/components/radio-group.md +1 -1
  9. package/dist/docs/components/slider.md +1 -1
  10. package/dist/docs/concepts/direction-and-locales.md +106 -0
  11. package/dist/docs/index.md +4 -1
  12. package/dist/docs/roadmap.md +7 -0
  13. package/dist/index.d.mts +11 -2
  14. package/dist/index.mjs +3 -1
  15. package/dist/internal/menubar-context.mjs +12 -0
  16. package/dist/internal/menubar-context.mjs.map +1 -0
  17. package/dist/internal/overlay/trigger-ref.mjs +1 -1
  18. package/dist/internal/overlay/trigger-ref.mjs.map +1 -1
  19. package/dist/internal/overlay/use-overlay-root.mjs +3 -2
  20. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
  21. package/dist/internal/overlay/use-popover-trigger.mjs +2 -2
  22. package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -1
  23. package/dist/internal/range-value.mjs +5 -3
  24. package/dist/internal/range-value.mjs.map +1 -1
  25. package/dist/menu/menu-popup.d.mts.map +1 -1
  26. package/dist/menu/menu-popup.mjs +33 -6
  27. package/dist/menu/menu-popup.mjs.map +1 -1
  28. package/dist/menu/menu-trigger.d.mts +10 -3
  29. package/dist/menu/menu-trigger.d.mts.map +1 -1
  30. package/dist/menu/menu-trigger.mjs +53 -5
  31. package/dist/menu/menu-trigger.mjs.map +1 -1
  32. package/dist/menubar/index.d.mts +3 -0
  33. package/dist/menubar/index.mjs +1 -0
  34. package/dist/menubar/menubar.d.mts +49 -0
  35. package/dist/menubar/menubar.d.mts.map +1 -0
  36. package/dist/menubar/menubar.mjs +147 -0
  37. package/dist/menubar/menubar.mjs.map +1 -0
  38. package/dist/meter/meter-root.d.mts +3 -2
  39. package/dist/meter/meter-root.d.mts.map +1 -1
  40. package/dist/meter/meter-root.mjs.map +1 -1
  41. package/dist/multi-select/multi-select-root.mjs +1 -1
  42. package/dist/multi-select/multi-select-trigger.mjs +1 -1
  43. package/dist/navigation-menu/index.d.mts +32 -0
  44. package/dist/navigation-menu/index.d.mts.map +1 -0
  45. package/dist/navigation-menu/index.mjs +32 -0
  46. package/dist/navigation-menu/index.mjs.map +1 -0
  47. package/dist/navigation-menu/navigation-menu-context.mjs +19 -0
  48. package/dist/navigation-menu/navigation-menu-context.mjs.map +1 -0
  49. package/dist/navigation-menu/navigation-menu-item.d.mts +79 -0
  50. package/dist/navigation-menu/navigation-menu-item.d.mts.map +1 -0
  51. package/dist/navigation-menu/navigation-menu-item.mjs +80 -0
  52. package/dist/navigation-menu/navigation-menu-item.mjs.map +1 -0
  53. package/dist/navigation-menu/navigation-menu-link.d.mts +48 -0
  54. package/dist/navigation-menu/navigation-menu-link.d.mts.map +1 -0
  55. package/dist/navigation-menu/navigation-menu-link.mjs +66 -0
  56. package/dist/navigation-menu/navigation-menu-link.mjs.map +1 -0
  57. package/dist/navigation-menu/navigation-menu-list.d.mts +33 -0
  58. package/dist/navigation-menu/navigation-menu-list.d.mts.map +1 -0
  59. package/dist/navigation-menu/navigation-menu-list.mjs +30 -0
  60. package/dist/navigation-menu/navigation-menu-list.mjs.map +1 -0
  61. package/dist/navigation-menu/navigation-menu-popup.d.mts +102 -0
  62. package/dist/navigation-menu/navigation-menu-popup.d.mts.map +1 -0
  63. package/dist/navigation-menu/navigation-menu-popup.mjs +93 -0
  64. package/dist/navigation-menu/navigation-menu-popup.mjs.map +1 -0
  65. package/dist/navigation-menu/navigation-menu-root.d.mts +33 -0
  66. package/dist/navigation-menu/navigation-menu-root.d.mts.map +1 -0
  67. package/dist/navigation-menu/navigation-menu-root.mjs +27 -0
  68. package/dist/navigation-menu/navigation-menu-root.mjs.map +1 -0
  69. package/dist/navigation-menu/navigation-menu-trigger.d.mts +32 -0
  70. package/dist/navigation-menu/navigation-menu-trigger.d.mts.map +1 -0
  71. package/dist/navigation-menu/navigation-menu-trigger.mjs +42 -0
  72. package/dist/navigation-menu/navigation-menu-trigger.mjs.map +1 -0
  73. package/dist/otp-field/otp-field-root.d.mts +9 -0
  74. package/dist/otp-field/otp-field-root.d.mts.map +1 -1
  75. package/dist/otp-field/otp-field-root.mjs +5 -2
  76. package/dist/otp-field/otp-field-root.mjs.map +1 -1
  77. package/dist/popover/index.d.mts +1 -1
  78. package/dist/popover/popover-trigger.mjs +1 -1
  79. package/dist/progress/progress-root.d.mts +3 -2
  80. package/dist/progress/progress-root.d.mts.map +1 -1
  81. package/dist/progress/progress-root.mjs.map +1 -1
  82. package/package.json +4 -1
  83. package/skills/funstack-ui-knowledge/SKILL.md +3 -0
@@ -0,0 +1,106 @@
1
+ # Direction and locales
2
+
3
+ FUNSTACK UI has no `DirectionProvider` and no `LocaleProvider`. Direction comes from the page, the way the browser reads it; a locale is a plain prop on the Root of each component that formats numbers.
4
+
5
+ ## Direction
6
+
7
+ **`dir` is the only switch.** Set it where the platform expects it: `<html dir="rtl">`, a container, or a part itself (every part passes native attributes through, so `<Tabs.List dir="rtl">` works). Each component reads the computed CSS `direction` of the relevant element (the table below) when a key is pressed or a gesture starts, so nothing is needed at render and Server Components and the server HTML are unaffected.
8
+
9
+ ```tsx
10
+ // <html lang="ar" dir="rtl"> in your document, then no setup:
11
+ <Tabs.Root defaultValue="a">
12
+ <Tabs.List>…</Tabs.List> {/* ArrowLeft moves to the next tab */}
13
+ </Tabs.Root>
14
+ ```
15
+
16
+ - **Why no provider.** A provider would be a second source of truth next to `dir`, the attribute the browser already uses for layout, logical properties, `:dir()` and anchor positioning. Libraries that have one ask you to set both, and when the two disagree the arrow keys and the layout point different ways. Reading the CSS cannot disagree with the layout, and a page with `<html dir="rtl">` needs no setup at all.
17
+ - **Direction islands work.** An RTL block inside an LTR page (a quoted Arabic form, a Hebrew sidebar), or the reverse, is handled per component, because each reads its own element. Nothing has to be nested to match the markup.
18
+ - Placement of popups follows direction in CSS: `side="inline-start"` / `"inline-end"` and `align="start"` / `"end"` use anchor-positioning keywords that resolve against the popup's direction. Drawer's `side` takes `"inline-start"` / `"inline-end"` too.
19
+ - A locale never sets the direction: `locale="ar"` on a NumberField changes its digits and separators, not its layout.
20
+
21
+ ### What mirrors
22
+
23
+ **Only ArrowLeft and ArrowRight in a horizontal orientation swap.** ArrowUp / ArrowDown, Home / End, PageUp / PageDown and every vertical orientation do the same under RTL as under LTR. `writing-mode` is not read.
24
+
25
+ | Component | What follows direction | Read from |
26
+ | - | - | - |
27
+ | [Tabs](../components/tabs.md) | ArrowLeft / ArrowRight between tabs (horizontal list) | the List |
28
+ | [ToggleGroup](../components/toggle-group.md), [Toolbar](../components/toolbar.md) | ArrowLeft / ArrowRight between items (horizontal) | the Root |
29
+ | [Slider](../components/slider.md) | ArrowLeft / ArrowRight follow the mirrored track (Right decreases); the value under the pointer | the thumb's input; the Track |
30
+ | [Menu](../components/menu.md) | the arrow that opens and closes a submenu (the inline-end one); the open key of a Trigger in a vertical Toolbar; which edge of a menu opened at a point sits at the pointer; the wheel hand-off of a horizontal scroller | the popup or its parent popup; the Trigger; the scroller |
31
+ | [Combobox](../components/combobox.md) `multiple` | the inline-start arrow from the input to the chips, and arrows between chips | the input; the chip |
32
+ | [Drawer](../components/drawer.md) | which way an `inline-start` / `inline-end` drawer swipes closed | the dialog |
33
+ | Tooltip, Popover, HoverCard, Menu, Select, Combobox, MultiSelect | logical sides and alignment; `data-side` / `data-align` report where the popup is | CSS anchor positioning |
34
+ | [RadioGroup](../components/radio-group.md) | arrows between radios (native; not in Safari, below) | the browser |
35
+ | [OTPField](../components/otp-field.md) | nothing: the Root is `ltr` by default (below) | – |
36
+ | Accordion, NumberField | nothing: vertical keys only | – |
37
+
38
+ ### Engine differences
39
+
40
+ - **RadioGroup in Safari, by design.** Radio arrows are the browser's own, and WebKit neither mirrors ArrowLeft / ArrowRight under RTL nor wraps at the ends: Right and Down always go to the next radio in document order. A FUNSTACK radio group behaves like every native radio group in Safari; the library adds no key handler ([RadioGroup](../components/radio-group.md#keyboard-and-aria)). Slider is the exception, because there the value moved against the drawn track.
41
+ - **Firefox misplaces popups in a direction island.** When a popup's parent box has another direction than the root element (an RTL block in an LTR page, or the reverse), Firefox mirrors the inline offset of its anchored position, physical sides included, so the popup lands away from its trigger ([#89](https://github.com/uhyo/funstack-ui/issues/89), Mozilla bug 2019601). Chromium and Safari place it correctly, a page whose `<html dir>` matches is unaffected, and the library ships no workaround.
42
+
43
+ ### OTPField is left to right
44
+
45
+ A one-time code is read left to right in every locale, so `OTPField.Root` renders `dir="ltr"` unless you pass `dir`: inside an RTL page Slot 0 stays the leftmost box and ArrowLeft moves to the previous character. The label and the messages outside the Root follow the page. Without the attribute the boxes would mirror while the input's text would not, and the engines disagree on the arrow keys there. See [OTPField](../components/otp-field.md#right-to-left-pages).
46
+
47
+ ## <a id="locale"></a>Locales
48
+
49
+ Components that format or parse numbers take a `locale` prop on their Root: [NumberField](../components/number-field.md), [Progress](../components/progress.md) and [Meter](../components/meter.md). The type is `string | readonly string[]`, what the `Intl` constructors take (a list is a preference order). The parts get the formatter from the Root.
50
+
51
+ - **The default is the runtime's locale**, on the server and in the browser. That suits a client-only app.
52
+ - **Pass it when the page is server-rendered.** The server's locale and the browser's can differ, and the formatted text would then not match at hydration. NumberField warns in development when `<html lang>` names another language and no `locale` was given.
53
+ - The library never reads `navigator.language` and never derives the locale from `lang`.
54
+
55
+ ### Why there is no LocaleProvider
56
+
57
+ `Progress.Root` and `Meter.Root` have no `"use client"` directive, so a Server Component renders them once, on the server. A context cannot reach them there, so a provider would silently not apply to them. And an app that localises already has a locale source, its i18n library; a second provider would have to be kept in step with it. The question is reopened by the first date or time component.
58
+
59
+ ### Recipe: the locale from your i18n library
60
+
61
+ Wrap the Root once in a client component that reads the locale from your i18n library, and use the wrapper everywhere:
62
+
63
+ ```tsx
64
+ "use client";
65
+ import { NumberField } from "@funstack/ui/number-field";
66
+ import type { ComponentProps } from "react";
67
+ import { useLocale } from "./i18n"; // your i18n library's hook
68
+
69
+ export function NumberFieldRoot(props: ComponentProps<typeof NumberField.Root>) {
70
+ const locale = useLocale();
71
+ return <NumberField.Root locale={locale} {...props} />;
72
+ }
73
+ ```
74
+
75
+ ### Recipe: from a Server Component
76
+
77
+ `locale` is plain data, so a Server Component passes it directly. Progress and Meter then format on the server, with nothing to mismatch:
78
+
79
+ ```tsx
80
+ import { Progress } from "@funstack/ui/progress";
81
+ import { getLocale } from "./i18n/server"; // however your server knows the request's locale
82
+
83
+ export async function UploadStatus({ done }: { done: number }) {
84
+ const locale = await getLocale(); // for example "ar-EG" or ["de-CH", "de"]
85
+ return (
86
+ <Progress.Root value={done} locale={locale} aria-label="Upload">
87
+ <Progress.Value />
88
+ <Progress.Track><Progress.Indicator /></Progress.Track>
89
+ </Progress.Root>
90
+ );
91
+ }
92
+ ```
93
+
94
+ ## Built-in strings
95
+
96
+ A few parts have an English default text, each with its own override; there is no strings provider either.
97
+
98
+ | Component | Default | Override |
99
+ | - | - | - |
100
+ | [Combobox](../components/combobox.md#props) | `"No results"`, `"1 result"`, `"N results"`; `"Japan removed"` with `multiple` | `announce`, `announceRemoved` on the Root |
101
+ | [Toast](../components/toast.md#props) | `"Notifications (F8)"`, the Viewport's name | `aria-label` on `Toast.Viewport` |
102
+ | [NumberField](../components/number-field.md#props) | `"Increase"` / `"Decrease"`, the buttons' names | `aria-label` on `Increment` / `Decrement` |
103
+
104
+ > **Not formatted by the library**
105
+ >
106
+ > Slider's `aria-valuetext` and Combobox filtering are yours: format and compare with `Intl` in your own function.
@@ -118,7 +118,7 @@ npm install @funstack/ui@alpha
118
118
 
119
119
  React 19.3 or later. Supported browsers: **the latest stable Blink, WebKit and Gecko. No fallbacks.** Platform features not yet in all three are opt-in [experimental props](concepts/experimental.md).
120
120
 
121
- Components: [Button](components/button.md), [Toggle](components/toggle.md), [ToggleGroup](components/toggle-group.md), [Toolbar](components/toolbar.md), [Tabs](components/tabs.md), [Accordion](components/accordion.md), [Collapsible](components/collapsible.md), [Tooltip](components/tooltip.md), [HoverCard](components/hover-card.md), [Popover](components/popover.md), [Dialog](components/dialog.md), [AlertDialog](components/alert-dialog.md), [Drawer](components/drawer.md), [Menu](components/menu.md), [Context menu (Menu)](components/context-menu.md), [Toast](components/toast.md), [Field and Form](components/field.md), [Checkbox](components/checkbox.md), [CheckboxGroup](components/checkbox-group.md), [RadioGroup](components/radio-group.md), [Switch](components/switch.md), [Select](components/select.md), [Combobox](components/combobox.md), [MultiSelect](components/multi-select.md), [Slider](components/slider.md), [NumberField](components/number-field.md), [OTPField](components/otp-field.md), [Progress](components/progress.md), [Meter](components/meter.md), [Avatar](components/avatar.md), [Separator](components/separator.md) and [Scroll areas (recipe)](components/scroll-area.md). More are coming; see the [roadmap](roadmap.md).
121
+ Components: [Button](components/button.md), [Toggle](components/toggle.md), [ToggleGroup](components/toggle-group.md), [Toolbar](components/toolbar.md), [Tabs](components/tabs.md), [Accordion](components/accordion.md), [Collapsible](components/collapsible.md), [NavigationMenu](components/navigation-menu.md), [Tooltip](components/tooltip.md), [HoverCard](components/hover-card.md), [Popover](components/popover.md), [Dialog](components/dialog.md), [AlertDialog](components/alert-dialog.md), [Drawer](components/drawer.md), [Menu](components/menu.md), [Context menu (Menu)](components/context-menu.md), [Menubar (Menu)](components/menubar.md), [Toast](components/toast.md), [Field and Form](components/field.md), [Checkbox](components/checkbox.md), [CheckboxGroup](components/checkbox-group.md), [RadioGroup](components/radio-group.md), [Switch](components/switch.md), [Select](components/select.md), [Combobox](components/combobox.md), [MultiSelect](components/multi-select.md), [Slider](components/slider.md), [NumberField](components/number-field.md), [OTPField](components/otp-field.md), [Progress](components/progress.md), [Meter](components/meter.md), [Avatar](components/avatar.md), [Separator](components/separator.md) and [Scroll areas (recipe)](components/scroll-area.md). More are coming; see the [roadmap](roadmap.md).
122
122
 
123
123
  ## The FUNSTACK family
124
124
 
@@ -147,6 +147,7 @@ FUNSTACK UI is part of the FUNSTACK family, which aims to be the most modern Rea
147
147
  ### Guides
148
148
 
149
149
  - [Replacing the element (render)](concepts/render.md): How the render prop replaces the element a FUNSTACK UI part renders: the element form, the function form, and how the part's props are merged into yours.
150
+ - [Direction and locales](concepts/direction-and-locales.md): Right-to-left pages and number formatting in FUNSTACK UI: dir is the only direction switch (no DirectionProvider), which keys mirror, the engine differences, OTPField's ltr default, and the locale prop per Root (no LocaleProvider) with SSR recipes.
150
151
  - [Experimental features](concepts/experimental.md): Platform features that are not in every engine yet are opt-in through experimental\_\* props on the part that uses them.
151
152
  - [Content Security Policy](concepts/content-security-policy.md): What a strict style-src needs for FUNSTACK UI: the SHA-256 of the two shipped stylesheets (STYLE_SHA256) or a nonce through CSPProvider, and style-src-attr for server-rendered inline styles.
152
153
  - [Using with AI agents](concepts/ai-agents.md): Give a coding agent FUNSTACK UI knowledge: install the funstack-ui-knowledge skill from the npm package, or point the agent at the Markdown docs bundled in the package and published as llms.txt.
@@ -160,6 +161,7 @@ FUNSTACK UI is part of the FUNSTACK family, which aims to be the most modern Rea
160
161
  - [Tabs](components/tabs.md): Tabs with optimistic selection, committed panels that may suspend, automatic or manual activation, an anchor-positioned indicator, and find-in-page support.
161
162
  - [Accordion](components/accordion.md): An accordion built on \<details>/\<summary>: no JavaScript when you need no state; actions, optimistic data-open and Suspense-friendly panels when you do.
162
163
  - [Collapsible](components/collapsible.md): One disclosure built on \<details>/\<summary>: no JavaScript when you need no state; actions, optimistic data-open and Suspense-friendly content when you do.
164
+ - [NavigationMenu](components/navigation-menu.md): A site's main navigation: a row of links and buttons that open panels of more links, built on the Popover API. It needs no JavaScript; a panel whose content loads on open is a transition.
163
165
  - [Tooltip](components/tooltip.md): A tooltip built on the Popover API and CSS Anchor Positioning, with a native interestfor path in Chromium. Open state belongs to the browser.
164
166
  - [HoverCard](components/hover-card.md): A rich preview that appears when the user rests the pointer on a link or focuses it: the open is a transition, so the content loads on interest and the card appears when it is ready; every close is a fact.
165
167
  - [Popover](components/popover.md): A non-modal popover on the Popover API: JS-free when you need no state; a transition-driven open, library-owned closes with a ViewTransition exit in every engine, and Suspense-ready content when you do.
@@ -168,6 +170,7 @@ FUNSTACK UI is part of the FUNSTACK family, which aims to be the most modern Rea
168
170
  - [Drawer](components/drawer.md): A dialog attached to an edge of the viewport that the user can swipe back to it, with mouse, pen or touch. A Dialog underneath: top layer, focus, Escape, the JS-free mode; the swipe is a dismissal reported to onOpenChange, and your CSS moves the drawer through three custom properties.
169
171
  - [Menu](components/menu.md): A menu button on the Popover API: items whose actions run in their own transition with pending state, optimistic checkbox and radio items, the APG keyboard model with typeahead, and submenus with hover intent.
170
172
  - [Context menu (Menu)](components/context-menu.md): Menu.ContextTrigger: a region whose right-click, Shift+F10 or touch long-press opens a Menu at the pointer, with the menu's pending items, optimistic checkbox and radio items and submenus unchanged.
173
+ - [Menubar (Menu)](components/menubar.md): The application menu of a desktop-style app: a row of ordinary Menu.Roots with one Tab stop, arrow keys between the menus and hover switching while a menu is open.
171
174
  - [Toast](components/toast.md): Notifications fed by a toast() function and rendered by your own Viewport: an urgent queue that shows while the action it reports on is still pending, promise toasts, an Undo action prop, an onClose handler for the Undo window, ariaNotify announcements, and a region that stays interactive above modal dialogs.
172
175
  - [Field and Form](components/field.md): Labelled, described, validated form fields on top of native constraint validation and :user-invalid, and a Form that runs its action in a transition, routes server errors to fields and resets only on success.
173
176
  - [Checkbox](components/checkbox.md): A native \<input type=checkbox> with an async checkedChangeAction, optimistic checked state, a controlled indeterminate state and native form participation.
@@ -10,6 +10,12 @@ Alpha releases (`0.1.0-alpha.N`) are published on npm under the `alpha` dist-tag
10
10
 
11
11
  Changes an upgrade may notice, newest first. Each component page documents the current behaviour.
12
12
 
13
+ - New component [Menubar](components/menubar.md) ([#170](https://github.com/uhyo/funstack-ui/issues/170)): a `<div role="menubar">` around ordinary `Menu.Root`s. A `Menu.Trigger` inside it renders `role="menuitem"`, and its `disabled` renders `aria-disabled` (it stays focusable); outside a bar nothing changes.
14
+
15
+ - New component [NavigationMenu](components/navigation-menu.md) ([#170](https://github.com/uhyo/funstack-ui/issues/170)): a site's main navigation as the disclosure pattern, each panel a `popover="auto"` next to its `popovertarget` button. It needs no JavaScript by default; after hydration focus leaving a panel and a followed `NavigationMenu.Link` close it. A panel whose content loads on open opts into library mode (`openChangeAction`, transition types `fsui-navigation-menu*`). Hover opening and arrow keys are not in this version.
16
+
17
+ - Direction and locale are decided ([#172](https://github.com/uhyo/funstack-ui/issues/172), [#188](https://github.com/uhyo/funstack-ui/issues/188)): `dir` is the only direction switch and there is no provider; `locale` is a prop of each Root that formats. See [Direction and locales](concepts/direction-and-locales.md). `OTPField.Root` now renders `dir="ltr"` unless you pass `dir`, so inside an RTL page its boxes no longer mirror. `locale` on `Progress.Root` and `Meter.Root` also takes a list of tags (`string | readonly string[]`), as on NumberField.
18
+
13
19
  - New component [Drawer](components/drawer.md) ([#168](https://github.com/uhyo/funstack-ui/issues/168)): a Dialog attached to an edge (`side`, rendered as `data-side`) that the user can swipe back to it with mouse, pen or touch. The swipe writes `data-swiping` and `--drawer-swipe-x` / `-y` / `-progress` for your CSS, finishes the slide, and closes the drawer as a dismissal reported to `onOpenChange`. Its transition types are `fsui-drawer*`. Snap points and the pull from a scrolled-to-top list are not in this version.
14
20
 
15
21
  - New component [OTPField](components/otp-field.md) ([#171](https://github.com/uhyo/funstack-ui/issues/171)): a one-time-code field that is one `autocomplete="one-time-code"` input drawn as a row of boxes, with `completeAction` for the complete code, `submitOnComplete` and `experimental_webOTP`.
@@ -133,6 +139,7 @@ Changes an upgrade may notice, newest first. Each component page documents the c
133
139
  - [Tooltip skip-delay](components/tooltip.md#skip-delay) ([#21](https://github.com/uhyo/funstack-ui/issues/21)).
134
140
  - [Content Security Policy](concepts/content-security-policy.md): `STYLE_SHA256` and `<CSPProvider nonce>` ([#88](https://github.com/uhyo/funstack-ui/issues/88)).
135
141
  - Directive-free variants of platform-native parts: considered and not built ([#19](https://github.com/uhyo/funstack-ui/issues/19)); [Server Components](concepts/server-components.md#js-free) defines "JS-free" and the form-control pages show the plain HTML alternative.
142
+ - Direction and locales: CSS `direction` is the one source, read per component at the event; a `locale` prop per Root, no provider ([#172](https://github.com/uhyo/funstack-ui/issues/172)). Guide: [Direction and locales](concepts/direction-and-locales.md).
136
143
 
137
144
  ## Next
138
145
 
package/dist/index.d.mts CHANGED
@@ -101,6 +101,14 @@ import { TooltipPopupProps, TooltipPopupState } from "./tooltip/tooltip-popup.mj
101
101
  import { TooltipRootProps, TooltipRootState } from "./tooltip/tooltip-root.mjs";
102
102
  import { TooltipTriggerProps, TooltipTriggerState } from "./tooltip/tooltip-trigger.mjs";
103
103
  import { Tooltip } from "./tooltip/index.mjs";
104
+ import { NavigationMenuItemProps, NavigationMenuItemState, NavigationMenuOpenChangeDetails } from "./navigation-menu/navigation-menu-item.mjs";
105
+ import { NavigationMenuLinkProps, NavigationMenuLinkState } from "./navigation-menu/navigation-menu-link.mjs";
106
+ import { NavigationMenuListProps, NavigationMenuListState } from "./navigation-menu/navigation-menu-list.mjs";
107
+ import { NavigationMenuAlign, NavigationMenuPopupProps, NavigationMenuPopupState, NavigationMenuSide } from "./navigation-menu/navigation-menu-popup.mjs";
108
+ import { NavigationMenuRootProps, NavigationMenuRootState } from "./navigation-menu/navigation-menu-root.mjs";
109
+ import { PopoverTriggerProps, PopoverTriggerState } from "./popover/popover-trigger.mjs";
110
+ import { NavigationMenuTriggerProps, NavigationMenuTriggerState } from "./navigation-menu/navigation-menu-trigger.mjs";
111
+ import { NavigationMenu } from "./navigation-menu/index.mjs";
104
112
  import { Switch, SwitchCheckedChangeDetails, SwitchProps, SwitchState } from "./switch/switch.mjs";
105
113
  import "./switch/index.mjs";
106
114
  import { PopoverCloseProps, PopoverCloseState } from "./popover/popover-close.mjs";
@@ -108,7 +116,6 @@ import { PopoverAlign, PopoverPopupProps, PopoverPopupState, PopoverSide } from
108
116
  import { PopoverDescriptionProps, PopoverDescriptionState } from "./popover/popover-description.mjs";
109
117
  import { PopoverOpenChangeDetails, PopoverRootProps, PopoverRootState } from "./popover/popover-root.mjs";
110
118
  import { PopoverTitleProps, PopoverTitleState } from "./popover/popover-title.mjs";
111
- import { PopoverTriggerProps, PopoverTriggerState } from "./popover/popover-trigger.mjs";
112
119
  import { Popover } from "./popover/index.mjs";
113
120
  import { MenuItemDetails, MenuItemProps, MenuItemState } from "./menu/menu-item.mjs";
114
121
  import { MenuCheckboxItemProps, MenuCheckboxItemState } from "./menu/menu-checkbox-item.mjs";
@@ -121,6 +128,8 @@ import { MenuRadioItemProps, MenuRadioItemState } from "./menu/menu-radio-item.m
121
128
  import { MenuOpenChangeDetails, MenuRootProps, MenuRootState } from "./menu/menu-root.mjs";
122
129
  import { MenuSubmenuTriggerProps, MenuSubmenuTriggerState } from "./menu/menu-submenu-trigger.mjs";
123
130
  import { Menu } from "./menu/index.mjs";
131
+ import { Menubar, MenubarProps, MenubarState } from "./menubar/menubar.mjs";
132
+ import "./menubar/index.mjs";
124
133
  import { RadioGroupItemProps, RadioGroupItemState } from "./radio-group/radio-group-item.mjs";
125
134
  import { RadioGroupRootProps, RadioGroupRootState, RadioGroupValueChangeDetails } from "./radio-group/radio-group-root.mjs";
126
135
  import { RadioGroupLabelProps } from "./radio-group/radio-group-label.mjs";
@@ -180,4 +189,4 @@ import { MeterLabelProps } from "./meter/meter-label.mjs";
180
189
  import { MeterTrackProps } from "./meter/meter-track.mjs";
181
190
  import { MeterValueProps } from "./meter/meter-value.mjs";
182
191
  import { Meter } from "./meter/index.mjs";
183
- export { Accordion, type AccordionItemProps, type AccordionItemState, type AccordionPanelProps, type AccordionPanelState, type AccordionRootExclusiveProps, type AccordionRootMultipleProps, type AccordionRootProps, type AccordionRootState, type AccordionTriggerProps, type AccordionTriggerState, type AccordionValueChangeDetails, type Action, type ActionDetails, AlertDialog, type AlertDialogActionDetails, type AlertDialogActionProps, type AlertDialogActionState, type AlertDialogCancelDetails, type AlertDialogCancelProps, type AlertDialogCancelState, type AlertDialogDescriptionProps, type AlertDialogDescriptionState, type AlertDialogFormProps, type AlertDialogFormState, type AlertDialogOpenChangeDetails, type AlertDialogPopupProps, type AlertDialogPopupState, type AlertDialogRootProps, type AlertDialogRootState, type AlertDialogTitleProps, type AlertDialogTitleState, type AlertDialogTriggerProps, type AlertDialogTriggerState, Avatar, type AvatarFallbackProps, type AvatarImageProps, type AvatarRootProps, type AvatarState, type AvatarStatus, Button, type ButtonActionDetails, type ButtonProps, type ButtonState, CSPProvider, type CSPProviderProps, type ChangeAction, type ChangeReason, Checkbox, type CheckboxCheckedChangeDetails, CheckboxGroup, type CheckboxGroupItemProps, type CheckboxGroupItemState, type CheckboxGroupLabelProps, type CheckboxGroupParentProps, type CheckboxGroupParentState, type CheckboxGroupRootProps, type CheckboxGroupRootState, type CheckboxGroupValueChangeDetails, type CheckboxProps, type CheckboxState, Collapsible, type CollapsibleOpenChangeDetails, type CollapsiblePanelProps, type CollapsiblePanelState, type CollapsibleRootProps, type CollapsibleRootState, type CollapsibleTriggerProps, type CollapsibleTriggerState, Combobox, type ComboboxChipProps, type ComboboxChipRemoveProps, type ComboboxChipRemoveState, type ComboboxChipState, type ComboboxChipsProps, type ComboboxChipsState, type ComboboxClearProps, type ComboboxClearState, type ComboboxEmptyProps, type ComboboxEmptyState, type ComboboxGroupLabelProps, type ComboboxGroupLabelState, type ComboboxGroupProps, type ComboboxGroupState, type ComboboxInputProps, type ComboboxInputState, type ComboboxInputValueChangeDetails, type ComboboxLabelProps, type ComboboxLabelState, type ComboboxListProps, type ComboboxListState, type ComboboxMultipleProps, type ComboboxMultipleRootState, type ComboboxMultipleValueChangeDetails, type ComboboxOpenChangeDetails, type ComboboxOptionProps, type ComboboxOptionState, type ComboboxPopupProps, type ComboboxPopupState, type ComboboxRootProps, type ComboboxRootState, type ComboboxSingleProps, type ComboboxStatusProps, type ComboboxStatusState, type ComboboxTriggerProps, type ComboboxTriggerState, type ComboboxValueChangeDetails, Dialog, type DialogCloseDetails, type DialogCloseProps, type DialogCloseState, type DialogDescriptionProps, type DialogDescriptionState, type DialogFormProps, type DialogFormState, type DialogOpenChangeDetails, type DialogPopupProps, type DialogPopupState, type DialogRootProps, type DialogRootState, type DialogTitleProps, type DialogTitleState, type DialogTriggerProps, type DialogTriggerState, Drawer, type DrawerCloseDetails, type DrawerCloseProps, type DrawerCloseState, type DrawerDescriptionProps, type DrawerDescriptionState, type DrawerFormProps, type DrawerFormState, type DrawerOpenChangeDetails, type DrawerPopupProps, type DrawerPopupState, type DrawerRootProps, type DrawerRootState, type DrawerSide, type DrawerTitleProps, type DrawerTitleState, type DrawerTriggerProps, type DrawerTriggerState, Field, type FieldControlProps, type FieldDescriptionProps, type FieldErrorProps, type FieldErrorValue, type FieldLabelProps, type FieldRootProps, type FieldState, type FieldValidate, type FieldValidity, Form, type FormErrors, type FormRootProps, type FormRootState, type FormSubmitProps, type FormSubmitState, HoverCard, type HoverCardAlign, type HoverCardOpenChangeDetails, type HoverCardPopupProps, type HoverCardPopupState, type HoverCardRootProps, type HoverCardRootState, type HoverCardSide, type HoverCardTriggerProps, type HoverCardTriggerState, Menu, type MenuAlign, type MenuCheckboxItemProps, type MenuCheckboxItemState, type MenuContextTriggerProps, type MenuContextTriggerState, type MenuGroupLabelProps, type MenuGroupLabelState, type MenuGroupProps, type MenuGroupState, type MenuItemDetails, type MenuItemProps, type MenuItemState, type MenuOpenChangeDetails, type MenuPopupProps, type MenuPopupState, type MenuRadioGroupProps, type MenuRadioGroupState, type MenuRadioItemProps, type MenuRadioItemState, type MenuRootProps, type MenuRootState, type MenuSeparatorProps, type MenuSeparatorState, type MenuSide, type MenuSubmenuTriggerProps, type MenuSubmenuTriggerState, type MenuTriggerProps, type MenuTriggerState, Meter, type MeterIndicatorProps, type MeterLabelProps, type MeterRegion, type MeterRootProps, type MeterState, type MeterTrackProps, type MeterValueProps, MultiSelect, type MultiSelectEmptyProps, type MultiSelectEmptyState, type MultiSelectGroupLabelProps, type MultiSelectGroupLabelState, type MultiSelectGroupProps, type MultiSelectGroupState, type MultiSelectLabelProps, type MultiSelectLabelState, type MultiSelectListProps, type MultiSelectListState, type MultiSelectOpenChangeDetails, type MultiSelectOptionProps, type MultiSelectOptionState, type MultiSelectPopupProps, type MultiSelectPopupState, type MultiSelectRootProps, type MultiSelectRootState, type MultiSelectStatusProps, type MultiSelectStatusState, type MultiSelectTriggerProps, type MultiSelectTriggerState, type MultiSelectValueChangeDetails, type MultiSelectValueProps, type MultiSelectValueState, NumberField, type NumberFieldButtonState, type NumberFieldDecrementProps, type NumberFieldIncrementProps, type NumberFieldInputProps, type NumberFieldLabelProps, type NumberFieldRootProps, type NumberFieldState, type NumberFieldValueChangeDetails, OTPField, type OTPFieldCharset, type OTPFieldCompleteDetails, type OTPFieldInputProps, type OTPFieldRootProps, type OTPFieldSlotProps, type OTPFieldSlotState, type OTPFieldState, type OTPFieldValueChangeDetails, Popover, type PopoverAlign, type PopoverCloseProps, type PopoverCloseState, type PopoverDescriptionProps, type PopoverDescriptionState, type PopoverOpenChangeDetails, type PopoverPopupProps, type PopoverPopupState, type PopoverRootProps, type PopoverRootState, type PopoverSide, type PopoverTitleProps, type PopoverTitleState, type PopoverTriggerProps, type PopoverTriggerState, Progress, type ProgressIndicatorProps, type ProgressLabelProps, type ProgressRootProps, type ProgressState, type ProgressTrackProps, type ProgressValueProps, RadioGroup, type RadioGroupItemProps, type RadioGroupItemState, type RadioGroupLabelProps, type RadioGroupRootProps, type RadioGroupRootState, type RadioGroupValueChangeDetails, type RenderProp, STYLE_SHA256, Select, type SelectGroupLabelProps, type SelectGroupProps, type SelectOptionProps, type SelectOptionState, type SelectRootProps, type SelectRootState, type SelectSeparatorProps, type SelectTriggerProps, type SelectValueChangeDetails, type SelectValueProps, Separator, type SeparatorOrientation, type SeparatorProps, type SeparatorState, Slider, type SliderIndicatorProps, type SliderIndicatorState, type SliderLabelProps, type SliderOrientation, type SliderRootProps, type SliderRootState, type SliderThumbProps, type SliderThumbState, type SliderTrackProps, type SliderTrackState, type SliderValue, type SliderValueChangeDetails, type SliderValueCommitDetails, type SliderValueProps, type SliderValueState, type StateValue, Switch, type SwitchCheckedChangeDetails, type SwitchProps, type SwitchState, Tabs, type TabsActivationMode, type TabsIndicatorProps, type TabsIndicatorState, type TabsListProps, type TabsListState, type TabsOrientation, type TabsPanelProps, type TabsPanelState, type TabsRootProps, type TabsRootState, type TabsTabProps, type TabsTabState, type TabsValueChangeDetails, Toast, type ToastActionDetails, type ToastActionOptions, type ToastActionProps, type ToastActionState, type ToastCloseDetails, type ToastCloseProps, type ToastCloseState, type ToastDescriptionProps, type ToastItem, type ToastManager, type ToastOptions, type ToastPriority, type ToastPromiseOptions, type ToastRootProps, type ToastRootState, type ToastTitleProps, type ToastViewportProps, type ToastViewportState, Toggle, ToggleGroup, type ToggleGroupExclusiveProps, type ToggleGroupItemProps, type ToggleGroupItemState, type ToggleGroupMultipleProps, type ToggleGroupOrientation, type ToggleGroupRootProps, type ToggleGroupRootState, type ToggleGroupValueChangeDetails, type TogglePressedChangeDetails, type ToggleProps, type ToggleState, Toolbar, type ToolbarOrientation, type ToolbarRootProps, type ToolbarRootState, type ToolbarSeparatorProps, type ToolbarSeparatorState, Tooltip, type TooltipAlign, type TooltipArrowProps, type TooltipArrowState, type TooltipPopupProps, type TooltipPopupState, type TooltipProvides, type TooltipRootProps, type TooltipRootState, type TooltipSide, type TooltipTriggerProps, type TooltipTriggerState, type UrgentChangeHandler, type UrgentHandler, type WhilePending, createToastManager, toast };
192
+ export { Accordion, type AccordionItemProps, type AccordionItemState, type AccordionPanelProps, type AccordionPanelState, type AccordionRootExclusiveProps, type AccordionRootMultipleProps, type AccordionRootProps, type AccordionRootState, type AccordionTriggerProps, type AccordionTriggerState, type AccordionValueChangeDetails, type Action, type ActionDetails, AlertDialog, type AlertDialogActionDetails, type AlertDialogActionProps, type AlertDialogActionState, type AlertDialogCancelDetails, type AlertDialogCancelProps, type AlertDialogCancelState, type AlertDialogDescriptionProps, type AlertDialogDescriptionState, type AlertDialogFormProps, type AlertDialogFormState, type AlertDialogOpenChangeDetails, type AlertDialogPopupProps, type AlertDialogPopupState, type AlertDialogRootProps, type AlertDialogRootState, type AlertDialogTitleProps, type AlertDialogTitleState, type AlertDialogTriggerProps, type AlertDialogTriggerState, Avatar, type AvatarFallbackProps, type AvatarImageProps, type AvatarRootProps, type AvatarState, type AvatarStatus, Button, type ButtonActionDetails, type ButtonProps, type ButtonState, CSPProvider, type CSPProviderProps, type ChangeAction, type ChangeReason, Checkbox, type CheckboxCheckedChangeDetails, CheckboxGroup, type CheckboxGroupItemProps, type CheckboxGroupItemState, type CheckboxGroupLabelProps, type CheckboxGroupParentProps, type CheckboxGroupParentState, type CheckboxGroupRootProps, type CheckboxGroupRootState, type CheckboxGroupValueChangeDetails, type CheckboxProps, type CheckboxState, Collapsible, type CollapsibleOpenChangeDetails, type CollapsiblePanelProps, type CollapsiblePanelState, type CollapsibleRootProps, type CollapsibleRootState, type CollapsibleTriggerProps, type CollapsibleTriggerState, Combobox, type ComboboxChipProps, type ComboboxChipRemoveProps, type ComboboxChipRemoveState, type ComboboxChipState, type ComboboxChipsProps, type ComboboxChipsState, type ComboboxClearProps, type ComboboxClearState, type ComboboxEmptyProps, type ComboboxEmptyState, type ComboboxGroupLabelProps, type ComboboxGroupLabelState, type ComboboxGroupProps, type ComboboxGroupState, type ComboboxInputProps, type ComboboxInputState, type ComboboxInputValueChangeDetails, type ComboboxLabelProps, type ComboboxLabelState, type ComboboxListProps, type ComboboxListState, type ComboboxMultipleProps, type ComboboxMultipleRootState, type ComboboxMultipleValueChangeDetails, type ComboboxOpenChangeDetails, type ComboboxOptionProps, type ComboboxOptionState, type ComboboxPopupProps, type ComboboxPopupState, type ComboboxRootProps, type ComboboxRootState, type ComboboxSingleProps, type ComboboxStatusProps, type ComboboxStatusState, type ComboboxTriggerProps, type ComboboxTriggerState, type ComboboxValueChangeDetails, Dialog, type DialogCloseDetails, type DialogCloseProps, type DialogCloseState, type DialogDescriptionProps, type DialogDescriptionState, type DialogFormProps, type DialogFormState, type DialogOpenChangeDetails, type DialogPopupProps, type DialogPopupState, type DialogRootProps, type DialogRootState, type DialogTitleProps, type DialogTitleState, type DialogTriggerProps, type DialogTriggerState, Drawer, type DrawerCloseDetails, type DrawerCloseProps, type DrawerCloseState, type DrawerDescriptionProps, type DrawerDescriptionState, type DrawerFormProps, type DrawerFormState, type DrawerOpenChangeDetails, type DrawerPopupProps, type DrawerPopupState, type DrawerRootProps, type DrawerRootState, type DrawerSide, type DrawerTitleProps, type DrawerTitleState, type DrawerTriggerProps, type DrawerTriggerState, Field, type FieldControlProps, type FieldDescriptionProps, type FieldErrorProps, type FieldErrorValue, type FieldLabelProps, type FieldRootProps, type FieldState, type FieldValidate, type FieldValidity, Form, type FormErrors, type FormRootProps, type FormRootState, type FormSubmitProps, type FormSubmitState, HoverCard, type HoverCardAlign, type HoverCardOpenChangeDetails, type HoverCardPopupProps, type HoverCardPopupState, type HoverCardRootProps, type HoverCardRootState, type HoverCardSide, type HoverCardTriggerProps, type HoverCardTriggerState, Menu, type MenuAlign, type MenuCheckboxItemProps, type MenuCheckboxItemState, type MenuContextTriggerProps, type MenuContextTriggerState, type MenuGroupLabelProps, type MenuGroupLabelState, type MenuGroupProps, type MenuGroupState, type MenuItemDetails, type MenuItemProps, type MenuItemState, type MenuOpenChangeDetails, type MenuPopupProps, type MenuPopupState, type MenuRadioGroupProps, type MenuRadioGroupState, type MenuRadioItemProps, type MenuRadioItemState, type MenuRootProps, type MenuRootState, type MenuSeparatorProps, type MenuSeparatorState, type MenuSide, type MenuSubmenuTriggerProps, type MenuSubmenuTriggerState, type MenuTriggerProps, type MenuTriggerState, Menubar, type MenubarProps, type MenubarState, Meter, type MeterIndicatorProps, type MeterLabelProps, type MeterRegion, type MeterRootProps, type MeterState, type MeterTrackProps, type MeterValueProps, MultiSelect, type MultiSelectEmptyProps, type MultiSelectEmptyState, type MultiSelectGroupLabelProps, type MultiSelectGroupLabelState, type MultiSelectGroupProps, type MultiSelectGroupState, type MultiSelectLabelProps, type MultiSelectLabelState, type MultiSelectListProps, type MultiSelectListState, type MultiSelectOpenChangeDetails, type MultiSelectOptionProps, type MultiSelectOptionState, type MultiSelectPopupProps, type MultiSelectPopupState, type MultiSelectRootProps, type MultiSelectRootState, type MultiSelectStatusProps, type MultiSelectStatusState, type MultiSelectTriggerProps, type MultiSelectTriggerState, type MultiSelectValueChangeDetails, type MultiSelectValueProps, type MultiSelectValueState, NavigationMenu, type NavigationMenuAlign, type NavigationMenuItemProps, type NavigationMenuItemState, type NavigationMenuLinkProps, type NavigationMenuLinkState, type NavigationMenuListProps, type NavigationMenuListState, type NavigationMenuOpenChangeDetails, type NavigationMenuPopupProps, type NavigationMenuPopupState, type NavigationMenuRootProps, type NavigationMenuRootState, type NavigationMenuSide, type NavigationMenuTriggerProps, type NavigationMenuTriggerState, NumberField, type NumberFieldButtonState, type NumberFieldDecrementProps, type NumberFieldIncrementProps, type NumberFieldInputProps, type NumberFieldLabelProps, type NumberFieldRootProps, type NumberFieldState, type NumberFieldValueChangeDetails, OTPField, type OTPFieldCharset, type OTPFieldCompleteDetails, type OTPFieldInputProps, type OTPFieldRootProps, type OTPFieldSlotProps, type OTPFieldSlotState, type OTPFieldState, type OTPFieldValueChangeDetails, Popover, type PopoverAlign, type PopoverCloseProps, type PopoverCloseState, type PopoverDescriptionProps, type PopoverDescriptionState, type PopoverOpenChangeDetails, type PopoverPopupProps, type PopoverPopupState, type PopoverRootProps, type PopoverRootState, type PopoverSide, type PopoverTitleProps, type PopoverTitleState, type PopoverTriggerProps, type PopoverTriggerState, Progress, type ProgressIndicatorProps, type ProgressLabelProps, type ProgressRootProps, type ProgressState, type ProgressTrackProps, type ProgressValueProps, RadioGroup, type RadioGroupItemProps, type RadioGroupItemState, type RadioGroupLabelProps, type RadioGroupRootProps, type RadioGroupRootState, type RadioGroupValueChangeDetails, type RenderProp, STYLE_SHA256, Select, type SelectGroupLabelProps, type SelectGroupProps, type SelectOptionProps, type SelectOptionState, type SelectRootProps, type SelectRootState, type SelectSeparatorProps, type SelectTriggerProps, type SelectValueChangeDetails, type SelectValueProps, Separator, type SeparatorOrientation, type SeparatorProps, type SeparatorState, Slider, type SliderIndicatorProps, type SliderIndicatorState, type SliderLabelProps, type SliderOrientation, type SliderRootProps, type SliderRootState, type SliderThumbProps, type SliderThumbState, type SliderTrackProps, type SliderTrackState, type SliderValue, type SliderValueChangeDetails, type SliderValueCommitDetails, type SliderValueProps, type SliderValueState, type StateValue, Switch, type SwitchCheckedChangeDetails, type SwitchProps, type SwitchState, Tabs, type TabsActivationMode, type TabsIndicatorProps, type TabsIndicatorState, type TabsListProps, type TabsListState, type TabsOrientation, type TabsPanelProps, type TabsPanelState, type TabsRootProps, type TabsRootState, type TabsTabProps, type TabsTabState, type TabsValueChangeDetails, Toast, type ToastActionDetails, type ToastActionOptions, type ToastActionProps, type ToastActionState, type ToastCloseDetails, type ToastCloseProps, type ToastCloseState, type ToastDescriptionProps, type ToastItem, type ToastManager, type ToastOptions, type ToastPriority, type ToastPromiseOptions, type ToastRootProps, type ToastRootState, type ToastTitleProps, type ToastViewportProps, type ToastViewportState, Toggle, ToggleGroup, type ToggleGroupExclusiveProps, type ToggleGroupItemProps, type ToggleGroupItemState, type ToggleGroupMultipleProps, type ToggleGroupOrientation, type ToggleGroupRootProps, type ToggleGroupRootState, type ToggleGroupValueChangeDetails, type TogglePressedChangeDetails, type ToggleProps, type ToggleState, Toolbar, type ToolbarOrientation, type ToolbarRootProps, type ToolbarRootState, type ToolbarSeparatorProps, type ToolbarSeparatorState, Tooltip, type TooltipAlign, type TooltipArrowProps, type TooltipArrowState, type TooltipPopupProps, type TooltipPopupState, type TooltipProvides, type TooltipRootProps, type TooltipRootState, type TooltipSide, type TooltipTriggerProps, type TooltipTriggerState, type UrgentChangeHandler, type UrgentHandler, type WhilePending, createToastManager, toast };
package/dist/index.mjs CHANGED
@@ -8,6 +8,7 @@ import { Collapsible } from "./collapsible/index.mjs";
8
8
  import { Tabs } from "./tabs/index.mjs";
9
9
  import { Tooltip } from "./tooltip/index.mjs";
10
10
  import { HoverCard } from "./hover-card/index.mjs";
11
+ import { NavigationMenu } from "./navigation-menu/index.mjs";
11
12
  import { Switch } from "./switch/switch.mjs";
12
13
  import { Checkbox } from "./checkbox/checkbox.mjs";
13
14
  import { Dialog } from "./dialog/index.mjs";
@@ -15,6 +16,7 @@ import { AlertDialog } from "./alert-dialog/index.mjs";
15
16
  import { Drawer } from "./drawer/index.mjs";
16
17
  import { Popover } from "./popover/index.mjs";
17
18
  import { Menu } from "./menu/index.mjs";
19
+ import { Menubar } from "./menubar/menubar.mjs";
18
20
  import { RadioGroup } from "./radio-group/index.mjs";
19
21
  import { CheckboxGroup } from "./checkbox-group/index.mjs";
20
22
  import { Select } from "./select/index.mjs";
@@ -32,4 +34,4 @@ import { Meter } from "./meter/index.mjs";
32
34
  import { Avatar } from "./avatar/index.mjs";
33
35
  import { CSPProvider } from "./csp/csp-provider.mjs";
34
36
  import { STYLE_SHA256 } from "./csp/style-hashes.mjs";
35
- export { Accordion, AlertDialog, Avatar, Button, CSPProvider, Checkbox, CheckboxGroup, Collapsible, Combobox, Dialog, Drawer, Field, Form, HoverCard, Menu, Meter, MultiSelect, NumberField, OTPField, Popover, Progress, RadioGroup, STYLE_SHA256, Select, Separator, Slider, Switch, Tabs, Toast, Toggle, ToggleGroup, Toolbar, Tooltip, createToastManager, toast };
37
+ export { Accordion, AlertDialog, Avatar, Button, CSPProvider, Checkbox, CheckboxGroup, Collapsible, Combobox, Dialog, Drawer, Field, Form, HoverCard, Menu, Menubar, Meter, MultiSelect, NavigationMenu, NumberField, OTPField, Popover, Progress, RadioGroup, STYLE_SHA256, Select, Separator, Slider, Switch, Tabs, Toast, Toggle, ToggleGroup, Toolbar, Tooltip, createToastManager, toast };
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { createContext, use } from "react";
3
+ //#region src/internal/menubar-context.ts
4
+ const MenubarContext = createContext(null);
5
+ /** The enclosing Menubar, or `null` outside one (and inside a `Menu.Popup`). */
6
+ function useMenubarContext() {
7
+ return use(MenubarContext);
8
+ }
9
+ //#endregion
10
+ export { MenubarContext, useMenubarContext };
11
+
12
+ //# sourceMappingURL=menubar-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menubar-context.mjs","names":[],"sources":["../../src/internal/menubar-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\n\n/**\n * Where focus goes when a switch opens a menu of the bar (design/components/menubar.md 2.2): the\n * first item (`\"first\"`, a switch from inside a menu), or nowhere (`\"none\"`: the arrow keys on a\n * Trigger and the pointer leave focus on the Trigger).\n */\nexport type MenubarOpenFocus = \"first\" | \"none\";\n\n/**\n * What a menu of the bar registers with it (menubar.md 2.1): read and called by the bar's\n * handlers only. Registered by `Menu.Trigger` from its ref callback, keyed by its element.\n */\nexport interface MenubarMenu {\n /** The `disabled` prop of the Trigger: focused by a switch, never opened. */\n readonly disabled: () => boolean;\n /** The menu's `intended()` (an open requested or shown). */\n readonly intended: () => boolean;\n /**\n * The browser hid the popup and its `toggle` has not arrived yet: the menu's own rule (Tab,\n * focus leaving the popup) already dismissed it, so there is nothing to supersede.\n */\n readonly hiddenBeforeToggle: () => boolean;\n /** The popup element (`:popover-open` tells whether it is shown). */\n readonly popup: () => HTMLElement | null;\n /** Request the open (`openChangeAction(true, \"activate\")`) with this focus target. */\n readonly open: (event: Event, focus: MenubarOpenFocus) => void;\n /** Supersede a pending open: `requestClose(event, \"dismiss\")`. */\n readonly supersede: (event: Event) => void;\n}\n\n/**\n * Provided by `Menubar`; read across folders by `Menu.Trigger` (an item of the bar, its\n * registration and the hover switch) and the top-level `Menu.Popup` (the arrow keys that switch\n * from inside a menu). A `Menu.Popup` provides `null` to its content: the bar's context ends\n * there, so a submenu is not a menu of the bar (menubar.md 1). Conventions 7.1.\n */\nexport interface MenubarContextValue {\n /** Register the menu whose Trigger is `trigger`; returns the unregistration. */\n readonly register: (trigger: HTMLElement, menu: MenubarMenu) => () => void;\n /**\n * The switch of menubar.md 2.2: focus `target` (quietly for the pointer), close the other\n * menus of the bar at once, request `target`'s open (unless it is disabled).\n */\n readonly switchTo: (\n target: HTMLElement,\n focus: MenubarOpenFocus,\n event: Event,\n pointer: boolean,\n ) => void;\n /**\n * From inside the menu whose Trigger is `from`: switch to the next (`1`) or previous (`-1`)\n * menu of the bar, first item focused. Wraps with the bar's `loop`. Returns whether it\n * switched (`false` at an end without `loop`, in a one-menu bar, or from a menu that is not\n * one of the bar's), so the caller consumes the key only then.\n */\n readonly step: (from: HTMLElement, delta: 1 | -1, event: Event) => boolean;\n /** Some menu of the bar other than `trigger`'s is intended open (menu mode, 2.1). */\n readonly otherIntended: (trigger: HTMLElement) => boolean;\n /** The bar's computed `direction` is `rtl`, read at the event (conventions 14.1). */\n readonly rtl: () => boolean;\n}\n\nexport const MenubarContext = createContext<MenubarContextValue | null>(null);\n\n/** The enclosing Menubar, or `null` outside one (and inside a `Menu.Popup`). */\nexport function useMenubarContext(): MenubarContextValue | null {\n return use(MenubarContext);\n}\n"],"mappings":";;;AAgEA,MAAa,iBAAiB,cAA0C,IAAI;;AAG5E,SAAgB,oBAAgD;CAC9D,OAAO,IAAI,cAAc;AAC3B"}
@@ -12,7 +12,7 @@ function registerTrigger(triggerRef, element, part) {
12
12
  if (isDev && triggerRef.current !== null) {
13
13
  if (!warned.has(triggerRef)) {
14
14
  warned.add(triggerRef);
15
- console.error(`${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: the popup only follows the last one mounted (its anchor, focus return and, without an action, data-open). Render one ${part} per Root.`);
15
+ console.error(`${part}: a second ${part} mounted for the same popup. A popup supports one ${part}: it only follows the last one mounted (its anchor, focus return and, without an action, data-open). Render one ${part} per popup.`);
16
16
  }
17
17
  }
18
18
  triggerRef.current = element;
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-ref.mjs","names":[],"sources":["../../../src/internal/overlay/trigger-ref.ts"],"sourcesContent":["import type { RefObject } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */\nconst warned = new WeakSet<RefObject<HTMLElement | null>>();\n\n/**\n * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns\n * the ref cleanup. In development, a second Trigger mounting while another is registered\n * warns once per Root (popover.md 14.2): only the registered one is the popup's `source` (anchor,\n * focus return) and, in JS-free mode, the one whose `data-open` is kept current.\n */\nexport function registerTrigger(\n triggerRef: RefObject<HTMLElement | null>,\n element: HTMLElement,\n part: string,\n): () => void {\n // A Trigger's own cleanup clears the ref first (a remount, StrictMode, a ref change), so a\n // registered element here is another, still mounted Trigger.\n if (isDev && triggerRef.current !== null) {\n if (!warned.has(triggerRef)) {\n warned.add(triggerRef);\n console.error(\n `${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: ` +\n \"the popup only follows the last one mounted (its anchor, focus return and, \" +\n `without an action, data-open). Render one ${part} per Root.`,\n );\n }\n }\n triggerRef.current = element;\n return () => {\n if (triggerRef.current === element) triggerRef.current = null;\n };\n}\n"],"mappings":";AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,yBAAS,IAAI,QAAuC;;;;;;;AAQ1D,SAAgB,gBACd,YACA,SACA,MACY;CAGZ,IAAI,SAAS,WAAW,YAAY,MAC9B;MAAA,CAAC,OAAO,IAAI,UAAU,GAAG;GAC3B,OAAO,IAAI,UAAU;GACrB,QAAQ,MACN,GAAG,KAAK,aAAa,KAAK,iDAAiD,KAAK,yHAEjC,KAAK,WACtD;EACF;;CAEF,WAAW,UAAU;CACrB,aAAa;EACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;CAC3D;AACF"}
1
+ {"version":3,"file":"trigger-ref.mjs","names":[],"sources":["../../../src/internal/overlay/trigger-ref.ts"],"sourcesContent":["import type { RefObject } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */\nconst warned = new WeakSet<RefObject<HTMLElement | null>>();\n\n/**\n * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns\n * the ref cleanup. In development, a second Trigger mounting while another is registered\n * warns once per Root (popover.md 14.2): only the registered one is the popup's `source` (anchor,\n * focus return) and, in JS-free mode, the one whose `data-open` is kept current.\n */\nexport function registerTrigger(\n triggerRef: RefObject<HTMLElement | null>,\n element: HTMLElement,\n part: string,\n): () => void {\n // A Trigger's own cleanup clears the ref first (a remount, StrictMode, a ref change), so a\n // registered element here is another, still mounted Trigger.\n if (isDev && triggerRef.current !== null) {\n if (!warned.has(triggerRef)) {\n warned.add(triggerRef);\n console.error(\n `${part}: a second ${part} mounted for the same popup. A popup supports one ${part}: ` +\n \"it only follows the last one mounted (its anchor, focus return and, \" +\n `without an action, data-open). Render one ${part} per popup.`,\n );\n }\n }\n triggerRef.current = element;\n return () => {\n if (triggerRef.current === element) triggerRef.current = null;\n };\n}\n"],"mappings":";AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,yBAAS,IAAI,QAAuC;;;;;;;AAQ1D,SAAgB,gBACd,YACA,SACA,MACY;CAGZ,IAAI,SAAS,WAAW,YAAY,MAC9B;MAAA,CAAC,OAAO,IAAI,UAAU,GAAG;GAC3B,OAAO,IAAI,UAAU;GACrB,QAAQ,MACN,GAAG,KAAK,aAAa,KAAK,oDAAoD,KAAK,kHAEpC,KAAK,YACtD;EACF;;CAEF,WAAW,UAAU;CACrB,aAAa;EACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;CAC3D;AACF"}
@@ -20,7 +20,8 @@ function clearLater(intentRef, intent, popupRef, isShown) {
20
20
  /** What the popup is called in the controlled-without-`onOpenChange` warning. */
21
21
  const nouns = {
22
22
  combobox: "listbox",
23
- "hover-card": "card"
23
+ "hover-card": "card",
24
+ "navigation-menu": "panel"
24
25
  };
25
26
  /** The `details` of a popover-like component: `{ reason }` (and `event`). */
26
27
  const popoverDetails = (event, reason) => createActionDetails(event, { reason });
@@ -35,7 +36,7 @@ function useOverlayRoot(options) {
35
36
  const mode = useMountFixed(isLibraryNow ? "library" : "static", isDev && `${part}: the mode changed after mount (\`open\`, \`defaultOpen\`, \`openChangeAction\` and \`onOpenChange\` were all absent on one render and present on another). Switching between JS-free and library mode is not supported.`);
36
37
  const isLibrary = mode === "library";
37
38
  const noun = nouns[component] ?? component;
38
- useDevWarning(isLibrary && open !== void 0 && onOpenChange === void 0, isDev && `${part}: \`open\` is set without \`onOpenChange\`. The browser can close this ${noun} without asking (Escape, a click outside), and \`onOpenChange\` is where a controlled Root is told. Without it the ${noun} re-opens after every dismissal. Pass \`onOpenChange={setOpen}\`, or \`onOpenChange={() => {}}\` if re-opening is what you want.`);
39
+ useDevWarning(isLibrary && open !== void 0 && onOpenChange === void 0, isDev && `${part}: \`open\` is set without \`onOpenChange\`. The browser can close this ${noun} without asking (Escape, a click outside), and \`onOpenChange\` is where a controlled ${part} is told. Without it the ${noun} re-opens after every dismissal. Pass \`onOpenChange={setOpen}\`, or \`onOpenChange={() => {}}\` if re-opening is what you want.`);
39
40
  const { committed, optimistic, pending, dispatch, latestInFlight, adoptFact, epoch } = useControllableAction({
40
41
  controlled: isLibrary ? open : void 0,
41
42
  defaultValue: isLibrary ? defaultOpen : void 0,
@@ -1 +1 @@
1
- {"version":3,"file":"use-overlay-root.mjs","names":[],"sources":["../../../src/internal/overlay/use-overlay-root.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"../action/action-details.js\";\nimport { callUrgentHandler } from \"../action/call-urgent-handler.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { transitionTypes } from \"../transition-types.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason, UrgentChangeHandler } from \"../types.js\";\nimport { intendedValue, useControllableAction } from \"../action/use-controllable-action.js\";\nimport { useDevWarning } from \"../use-dev-warning.js\";\nimport { useMountFixed } from \"../use-mount-fixed.js\";\nimport { useLatest } from \"../use-latest.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * \"static\": JS-free mode, the browser owns open and close through Invoker Commands. \"library\":\n * opening and part-initiated closing are library-owned requests (transitions keyed on committed\n * state, `openChangeAction`); dismissals are the browser's facts, adopted urgently and reported to\n * `onOpenChange` (design/components/popover.md section 2, conventions 3.9).\n */\nexport type OverlayMode = \"static\" | \"library\";\n\n/**\n * What caused the next close, recorded just before it happens (design 2.3). The `toggle` event\n * names no cause beyond its invoker (`ToggleEvent.source`: a `popovertarget`, `commandfor` or\n * `interestfor` button); without an intent a close is a `\"dismiss\"`.\n */\nexport interface OverlayCloseIntent {\n readonly reason: ChangeReason;\n readonly event: Event | undefined;\n}\n\n/**\n * The `details` every overlay `openChangeAction` and `onOpenChange` receives (Dialog's adds\n * `returnValue`).\n */\nexport interface OverlayDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\n/** What the parts render from (every part). */\nexport interface OverlayRootState {\n readonly mode: OverlayMode;\n /** `useId`-based ids: the popup, its Title and its Description. */\n readonly ids: { readonly popup: string; readonly title: string; readonly description: string };\n /** Committed open state (library mode); `false` in JS-free mode. */\n readonly committed: boolean;\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly optimistic: boolean;\n /** The Root's transition is pending (library mode). */\n readonly pending: boolean;\n /**\n * Grows with every fact (`notifyClosed`). No part reads it: it is part of the memoised value so\n * that a fact always re-renders the parts, even when a controlled parent keeps `open={true}` and\n * nothing else changed: the Popup's apply effect then re-opens the popup (design 2.4).\n */\n readonly epoch: number;\n}\n\n/**\n * How a part asks for an open or a close, from its handlers: the Triggers, the Close parts,\n * Menu's items, keys and hover intent, Combobox's handlers, Dialog's Form; the Popup too, for a\n * foreign open or close it catches.\n */\nexport interface OverlayRootRequests<CloseArgs extends unknown[]> {\n /**\n * What the user already intends: the latest in-flight dispatch's `next`, else the optimistic\n * value of the last commit. Safe to call from handlers and effects (layout effects included,\n * also in the commit that changed it), and after an `await`. Not during render.\n */\n readonly intended: () => boolean;\n /**\n * Open through the Root's transition (library mode): a Trigger click, a foreign open caught at\n * `beforetoggle`, or mount reconciliation. A no-op when `true` is already intended.\n */\n readonly requestOpen: (event: Event | undefined, reason: ChangeReason) => void;\n /**\n * A library-owned close (library mode): a Trigger click while open, a Close part, Menu's item\n * activation. `openChangeAction(false)` is awaited and the popup hides in the commit. A no-op\n * when `false` is already intended.\n */\n readonly requestClose: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /**\n * A counter that grows with every open (a requested open, or the popup being shown). A part\n * whose close runs after an `await` records it first and drops the close when it changed: the\n * user dismissed and re-opened meanwhile (Popover.Close, design 3.4). Handlers only.\n */\n readonly openGeneration: () => number;\n /**\n * Record what causes the next close. Cleared after a task if the popover did not close.\n * `unlessRecorded`: keep an intent already recorded for this close (the `command` listener runs\n * before the `beforetoggle` of the same click).\n */\n readonly recordCloseIntent: (\n intent: OverlayCloseIntent | undefined,\n options?: { readonly unlessRecorded?: boolean },\n ) => void;\n}\n\n/**\n * What only the Popup implementation calls (`usePopoverPopup`, Dialog.Popup and their shared\n * `useApplyOpenState`): the platform events' bookkeeping and the apply effect's in-flight check.\n */\nexport interface OverlayRootPopupChannel<CloseArgs extends unknown[]> {\n /**\n * A fact (#148, conventions 3.9.2): the browser hid the popup and the library did not\n * hide it (the caller has already excluded the library's own hide). Supersedes every request in\n * flight, writes committed `false` urgently (uncontrolled), and calls `onOpenChange(false,\n * details)` synchronously through the handler rule (`callUrgentHandler`). Call it from the\n * platform event's listener (`toggle` / `close`), never inside a transition.\n */\n readonly notifyClosed: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /** Advance `openGeneration` (the Popup's `beforetoggle` for an open). */\n readonly nextOpenGeneration: () => void;\n /** Read and clear the recorded intent (the Popup's `toggle` / `close` listener). */\n readonly takeCloseIntent: () => OverlayCloseIntent | undefined;\n /**\n * From `useControllableAction`: the latest in-flight intent, or `null`. Also read by\n * Dialog.Root, for its pending `returnValue`.\n */\n readonly latestInFlight: () => { readonly next: boolean } | null;\n}\n\n/** The two elements, each set by its own part and read by the others. */\nexport interface OverlayRootRefs<Popup extends HTMLElement> {\n /** The registered Trigger: `showPopover({ source })` and the focus-return fallback. */\n readonly triggerRef: RefObject<HTMLElement | null>;\n /** The popup element, set by the Popup's ref; how Close reaches `hidePopover()` / `close()`. */\n readonly popupRef: RefObject<Popup | null>;\n}\n\n/**\n * The Root's state and machinery, shared by Popover, Menu, Combobox (design 14) and Dialog,\n * grouped by who uses it. The component puts it in its own context (the popover-like ones\n * extend it, `PopoverRootValue`). `Popup` is the popup element's type; `CloseArgs` are the extra\n * arguments of a close (Dialog's `returnValue`), passed on to the `details` builder.\n */\nexport interface OverlayRootValue<Popup extends HTMLElement, CloseArgs extends unknown[]>\n extends\n OverlayRootState,\n OverlayRootRequests<CloseArgs>,\n OverlayRootPopupChannel<CloseArgs>,\n OverlayRootRefs<Popup> {}\n\n/**\n * The root value of the popover-like components (Popover, Menu, Combobox), from `usePopoverRoot`:\n * the overlay Root plus the `shown` mirror that their Popup (`usePopoverPopup`) writes and their\n * Triggers (`usePopoverTrigger`, Combobox.Trigger) and the Combobox Input read. Dialog has none.\n */\nexport interface PopoverRootValue extends OverlayRootValue<HTMLElement, []> {\n /**\n * The popup is in the top layer, mirrored from its `toggle` (urgent, conventions 3.5): what\n * `aria-expanded` renders on a non-button Trigger and the Combobox Input (a `<button>`\n * Trigger renders none). Written by the Popup in library mode.\n */\n readonly shown: boolean;\n /** Writes `shown` from the DOM (`:popover-open`); the Popup's `toggle`, ref attach and detach. */\n readonly setShown: (shown: boolean) => void;\n /**\n * The popup was shown at its last `toggle` and the DOM has it hidden now: the browser hid it\n * and its `toggle` has not arrived yet. A non-button Trigger's click lands in that window after\n * light dismiss hid the popup at `pointerup` (#115): it records an `\"activate\"` intent for the\n * fact instead of requesting a close. Handlers only.\n */\n readonly hiddenBeforeToggle: () => boolean;\n}\n\nexport interface UseOverlayRootOptions<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n> {\n /** Transition types and messages: `\"popover\"` gives `fsui-popover`, `fsui-popover-open`, … */\n readonly component: string;\n /** Public name of the Root part for development warnings (`\"Popover.Root\"`). */\n readonly part: string;\n readonly open: boolean | undefined;\n readonly defaultOpen: boolean | undefined;\n readonly openChangeAction: ChangeAction<boolean, Details> | undefined;\n /** The fact handler (#148): called for a hide the library did not perform. */\n readonly onOpenChange: UrgentChangeHandler<boolean, Details> | undefined;\n /**\n * `\"library\"` forces library mode whatever the props (Menu, which has no JS-free mode). Default:\n * detected from `open` / `defaultOpen` / `openChangeAction` / `onOpenChange` on the first\n * render.\n */\n readonly mode?: \"library\";\n /**\n * Called synchronously for every dispatch, before the action runs, and for every fact, before\n * `onOpenChange` (Menu: cancel hover timers, read the open cause).\n */\n readonly onDispatch?: (next: boolean, details: Details) => void;\n /** Builds the `details` of a dispatch (`popoverDetails`: `{ reason }`); an open passes no args. */\n readonly details: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs | []\n ) => Details;\n /**\n * Whether the popup is shown, for a stale close intent: `:popover-open` (`usePopoverRoot`), a\n * `<dialog>`'s `open` (Dialog).\n */\n readonly isShown: (popup: Popup) => boolean;\n}\n\n/** How long a recorded close intent survives when the popup did not close (design 2.3). */\nfunction clearLater<Popup extends HTMLElement>(\n intentRef: { current: OverlayCloseIntent | undefined },\n intent: OverlayCloseIntent,\n popupRef: { current: Popup | null },\n isShown: (popup: Popup) => boolean,\n): void {\n setTimeout(() => {\n // Closed: its `toggle` / `close` event (queued as a task) consumes the intent. Still open: the\n // close was cancelled or invalid, so the intent is stale.\n const popup = popupRef.current;\n if (intentRef.current === intent && popup !== null && isShown(popup)) {\n intentRef.current = undefined;\n }\n }, 0);\n}\n\n/** What the popup is called in the controlled-without-`onOpenChange` warning. */\nconst nouns: Record<string, string> = { combobox: \"listbox\", \"hover-card\": \"card\" };\n\n/** The `details` of a popover-like component: `{ reason }` (and `event`). */\nexport const popoverDetails = (event: Event | undefined, reason: ChangeReason): OverlayDetails =>\n createActionDetails(event, { reason });\n\n/**\n * The Root of an overlay without its public props: mode detection (once, from the first\n * render), `useControllableAction<boolean>`, ids, refs, close intents, the open generation and\n * the intent-aware `requestOpen` / `requestClose`, and `notifyClosed` for facts.\n */\nexport function useOverlayRoot<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n>(options: UseOverlayRootOptions<Details, Popup, CloseArgs>): OverlayRootValue<Popup, CloseArgs> {\n const {\n component,\n part,\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details,\n onDispatch,\n } = options;\n\n // Mode is decided once, from the first render's props (design 2).\n const isLibraryNow =\n options.mode === \"library\" ||\n open !== undefined ||\n defaultOpen !== undefined ||\n openChangeAction !== undefined ||\n onOpenChange !== undefined;\n const mode = useMountFixed<OverlayMode>(\n isLibraryNow ? \"library\" : \"static\",\n isDev &&\n `${part}: the mode changed after mount (\\`open\\`, \\`defaultOpen\\`, \\`openChangeAction\\` ` +\n \"and `onOpenChange` were all absent on one render and present on another). Switching \" +\n \"between JS-free and library mode is not supported.\",\n );\n const isLibrary = mode === \"library\";\n // W1 (conventions 3.9.13): React's `value` without `onChange`. Static only: a handler\n // that adopts late (in a transition, after an `await`) cannot be told from an intentional\n // re-open, so nothing at runtime warns.\n const noun = nouns[component] ?? component;\n useDevWarning(\n isLibrary && open !== undefined && onOpenChange === undefined,\n isDev &&\n `${part}: \\`open\\` is set without \\`onOpenChange\\`. The browser can close this ${noun} ` +\n \"without asking (Escape, a click outside), and `onOpenChange` is where a controlled Root \" +\n `is told. Without it the ${noun} re-opens after every dismissal. Pass ` +\n \"`onOpenChange={setOpen}`, or `onOpenChange={() => {}}` if re-opening is what you want.\",\n );\n\n // Hooks cannot be conditional: JS-free mode calls the hook too and never dispatches.\n const { committed, optimistic, pending, dispatch, latestInFlight, adoptFact, epoch } =\n useControllableAction<boolean, Details>({\n controlled: isLibrary ? open : undefined,\n defaultValue: isLibrary ? defaultOpen : undefined,\n initialValue: false,\n action: isLibrary ? openChangeAction : undefined,\n transitionTypes: (next) => transitionTypes(component, next ? \"open\" : \"close\"),\n warn: { component: part, prop: \"open\" },\n });\n\n const id = useId();\n const triggerRef = useRef<HTMLElement | null>(null);\n const popupRef = useRef<Popup | null>(null);\n const closeIntent = useRef<OverlayCloseIntent | undefined>(undefined);\n\n // The optimistic value of the last commit, for callers that run after an `await` (a Close\n // action's continuation) and would otherwise read the value of the render they were created in.\n // An insertion effect runs in the mutation phase, before any layout effect of the same commit\n // (a child's included), so `intended()` is current there too.\n const committedOptimistic = useLatest(optimistic);\n // `details`, `onDispatch` and `isShown` are usually inline functions: read the committed render's\n // through a ref so that the functions below, and with them the returned value, stay stable.\n const callbacks = useLatest({ details, onDispatch, onOpenChange, isShown: options.isShown });\n const generation = useRef(0);\n const openGeneration = useCallback(() => generation.current, []);\n const nextOpenGeneration = useCallback(() => {\n generation.current++;\n }, []);\n\n const recordCloseIntent = useCallback(\n (intent: OverlayCloseIntent | undefined, options?: { readonly unlessRecorded?: boolean }) => {\n if (options?.unlessRecorded === true && closeIntent.current !== undefined) return;\n closeIntent.current = intent;\n if (intent !== undefined) {\n clearLater(closeIntent, intent, popupRef, callbacks.current.isShown);\n }\n },\n [callbacks],\n );\n const takeCloseIntent = useCallback(() => {\n const intent = closeIntent.current;\n closeIntent.current = undefined;\n return intent;\n }, []);\n\n // Conventions 3.8 rule 1: judge no-ops against what the user already intends. That also\n // deduplicates the StrictMode re-run of the mount reconciliation and recognises the library's\n // own `hidePopover()` echoing back through `toggle`.\n const intended = useCallback(\n (): boolean => intendedValue(latestInFlight, committedOptimistic.current),\n [latestInFlight, committedOptimistic],\n );\n\n const send = useCallback(\n (next: boolean, event: Event | undefined, reason: ChangeReason, args: CloseArgs | []): void => {\n const { details, onDispatch } = callbacks.current;\n const built = details(event, reason, ...args);\n if (next) nextOpenGeneration();\n onDispatch?.(next, built);\n dispatch(next, built);\n },\n [callbacks, nextOpenGeneration, dispatch],\n );\n\n const requestOpen = useCallback(\n (event: Event | undefined, reason: ChangeReason): void => {\n if (!isLibrary || intended()) return;\n send(true, event, reason, []);\n },\n [isLibrary, intended, send],\n );\n\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary || !intended()) return;\n send(false, event, reason, args);\n },\n [isLibrary, intended, send],\n );\n\n const notifyClosed = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary) return;\n const { details, onDispatch, onOpenChange } = callbacks.current;\n const built = details(event, reason, ...args);\n onDispatch?.(false, built);\n // Supersede the requests in flight and write committed `false` (urgent), then tell the\n // consumer; both in the platform event, so one discrete commit follows (design 2.3).\n adoptFact(false);\n callUrgentHandler(onOpenChange, false, built);\n },\n [isLibrary, callbacks, adoptFact],\n );\n\n const ids = useMemo(\n () => ({ popup: id, title: `${id}-title`, description: `${id}-description` }),\n [id],\n );\n\n // Memoised: every function above is stable, so the value changes only with the open state and\n // pending, and the components' context values built on it are reused otherwise.\n return useMemo(\n () => ({\n mode,\n ids,\n committed: isLibrary && committed,\n optimistic: isLibrary && optimistic,\n pending: isLibrary && pending,\n epoch,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n notifyClosed,\n latestInFlight,\n triggerRef,\n popupRef,\n recordCloseIntent,\n takeCloseIntent,\n }),\n [\n mode,\n ids,\n isLibrary,\n committed,\n optimistic,\n pending,\n epoch,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n notifyClosed,\n latestInFlight,\n recordCloseIntent,\n takeCloseIntent,\n ],\n );\n}\n\n/**\n * The Root of a popover-like component (Popover, Menu, Combobox): `useOverlayRoot` over a\n * `popover` element (`:popover-open`), plus the `shown` mirror and `hiddenBeforeToggle`.\n */\nexport function usePopoverRoot<Details extends ActionDetails>(\n options: Omit<UseOverlayRootOptions<Details>, \"isShown\">,\n): PopoverRootValue {\n const root = useOverlayRoot<Details>({ ...options, isShown: isPopoverOpen });\n const { popupRef } = root;\n\n const [shown, setShownState] = useState(false);\n // The last value written, for handlers (`hiddenBeforeToggle`).\n const shownNow = useRef(false);\n const setShown = useCallback((next: boolean) => {\n shownNow.current = next;\n setShownState(next);\n }, []);\n const hiddenBeforeToggle = useCallback((): boolean => {\n const popup = popupRef.current;\n return shownNow.current && popup !== null && !isPopoverOpen(popup);\n }, [popupRef]);\n\n // Changes only with `root` and `shown`, so as rarely as `root` itself does.\n return useMemo(\n () => ({ ...root, shown, setShown, hiddenBeforeToggle }),\n [root, shown, setShown, hiddenBeforeToggle],\n );\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"use-overlay-root.mjs","names":[],"sources":["../../../src/internal/overlay/use-overlay-root.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"../action/action-details.js\";\nimport { callUrgentHandler } from \"../action/call-urgent-handler.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { transitionTypes } from \"../transition-types.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason, UrgentChangeHandler } from \"../types.js\";\nimport { intendedValue, useControllableAction } from \"../action/use-controllable-action.js\";\nimport { useDevWarning } from \"../use-dev-warning.js\";\nimport { useMountFixed } from \"../use-mount-fixed.js\";\nimport { useLatest } from \"../use-latest.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * \"static\": JS-free mode, the browser owns open and close through Invoker Commands. \"library\":\n * opening and part-initiated closing are library-owned requests (transitions keyed on committed\n * state, `openChangeAction`); dismissals are the browser's facts, adopted urgently and reported to\n * `onOpenChange` (design/components/popover.md section 2, conventions 3.9).\n */\nexport type OverlayMode = \"static\" | \"library\";\n\n/**\n * What caused the next close, recorded just before it happens (design 2.3). The `toggle` event\n * names no cause beyond its invoker (`ToggleEvent.source`: a `popovertarget`, `commandfor` or\n * `interestfor` button); without an intent a close is a `\"dismiss\"`.\n */\nexport interface OverlayCloseIntent {\n readonly reason: ChangeReason;\n readonly event: Event | undefined;\n}\n\n/**\n * The `details` every overlay `openChangeAction` and `onOpenChange` receives (Dialog's adds\n * `returnValue`).\n */\nexport interface OverlayDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\n/** What the parts render from (every part). */\nexport interface OverlayRootState {\n readonly mode: OverlayMode;\n /** `useId`-based ids: the popup, its Title and its Description. */\n readonly ids: { readonly popup: string; readonly title: string; readonly description: string };\n /** Committed open state (library mode); `false` in JS-free mode. */\n readonly committed: boolean;\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly optimistic: boolean;\n /** The Root's transition is pending (library mode). */\n readonly pending: boolean;\n /**\n * Grows with every fact (`notifyClosed`). No part reads it: it is part of the memoised value so\n * that a fact always re-renders the parts, even when a controlled parent keeps `open={true}` and\n * nothing else changed: the Popup's apply effect then re-opens the popup (design 2.4).\n */\n readonly epoch: number;\n}\n\n/**\n * How a part asks for an open or a close, from its handlers: the Triggers, the Close parts,\n * Menu's items, keys and hover intent, Combobox's handlers, Dialog's Form; the Popup too, for a\n * foreign open or close it catches.\n */\nexport interface OverlayRootRequests<CloseArgs extends unknown[]> {\n /**\n * What the user already intends: the latest in-flight dispatch's `next`, else the optimistic\n * value of the last commit. Safe to call from handlers and effects (layout effects included,\n * also in the commit that changed it), and after an `await`. Not during render.\n */\n readonly intended: () => boolean;\n /**\n * Open through the Root's transition (library mode): a Trigger click, a foreign open caught at\n * `beforetoggle`, or mount reconciliation. A no-op when `true` is already intended.\n */\n readonly requestOpen: (event: Event | undefined, reason: ChangeReason) => void;\n /**\n * A library-owned close (library mode): a Trigger click while open, a Close part, Menu's item\n * activation. `openChangeAction(false)` is awaited and the popup hides in the commit. A no-op\n * when `false` is already intended.\n */\n readonly requestClose: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /**\n * A counter that grows with every open (a requested open, or the popup being shown). A part\n * whose close runs after an `await` records it first and drops the close when it changed: the\n * user dismissed and re-opened meanwhile (Popover.Close, design 3.4). Handlers only.\n */\n readonly openGeneration: () => number;\n /**\n * Record what causes the next close. Cleared after a task if the popover did not close.\n * `unlessRecorded`: keep an intent already recorded for this close (the `command` listener runs\n * before the `beforetoggle` of the same click).\n */\n readonly recordCloseIntent: (\n intent: OverlayCloseIntent | undefined,\n options?: { readonly unlessRecorded?: boolean },\n ) => void;\n}\n\n/**\n * What only the Popup implementation calls (`usePopoverPopup`, Dialog.Popup and their shared\n * `useApplyOpenState`): the platform events' bookkeeping and the apply effect's in-flight check.\n */\nexport interface OverlayRootPopupChannel<CloseArgs extends unknown[]> {\n /**\n * A fact (#148, conventions 3.9.2): the browser hid the popup and the library did not\n * hide it (the caller has already excluded the library's own hide). Supersedes every request in\n * flight, writes committed `false` urgently (uncontrolled), and calls `onOpenChange(false,\n * details)` synchronously through the handler rule (`callUrgentHandler`). Call it from the\n * platform event's listener (`toggle` / `close`), never inside a transition.\n */\n readonly notifyClosed: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /** Advance `openGeneration` (the Popup's `beforetoggle` for an open). */\n readonly nextOpenGeneration: () => void;\n /** Read and clear the recorded intent (the Popup's `toggle` / `close` listener). */\n readonly takeCloseIntent: () => OverlayCloseIntent | undefined;\n /**\n * From `useControllableAction`: the latest in-flight intent, or `null`. Also read by\n * Dialog.Root, for its pending `returnValue`.\n */\n readonly latestInFlight: () => { readonly next: boolean } | null;\n}\n\n/** The two elements, each set by its own part and read by the others. */\nexport interface OverlayRootRefs<Popup extends HTMLElement> {\n /** The registered Trigger: `showPopover({ source })` and the focus-return fallback. */\n readonly triggerRef: RefObject<HTMLElement | null>;\n /** The popup element, set by the Popup's ref; how Close reaches `hidePopover()` / `close()`. */\n readonly popupRef: RefObject<Popup | null>;\n}\n\n/**\n * The Root's state and machinery, shared by Popover, Menu, Combobox (design 14) and Dialog,\n * grouped by who uses it. The component puts it in its own context (the popover-like ones\n * extend it, `PopoverRootValue`). `Popup` is the popup element's type; `CloseArgs` are the extra\n * arguments of a close (Dialog's `returnValue`), passed on to the `details` builder.\n */\nexport interface OverlayRootValue<Popup extends HTMLElement, CloseArgs extends unknown[]>\n extends\n OverlayRootState,\n OverlayRootRequests<CloseArgs>,\n OverlayRootPopupChannel<CloseArgs>,\n OverlayRootRefs<Popup> {}\n\n/**\n * The root value of the popover-like components (Popover, Menu, Combobox), from `usePopoverRoot`:\n * the overlay Root plus the `shown` mirror that their Popup (`usePopoverPopup`) writes and their\n * Triggers (`usePopoverTrigger`, Combobox.Trigger) and the Combobox Input read. Dialog has none.\n */\nexport interface PopoverRootValue extends OverlayRootValue<HTMLElement, []> {\n /**\n * The popup is in the top layer, mirrored from its `toggle` (urgent, conventions 3.5): what\n * `aria-expanded` renders on a non-button Trigger and the Combobox Input (a `<button>`\n * Trigger renders none). Written by the Popup in library mode.\n */\n readonly shown: boolean;\n /** Writes `shown` from the DOM (`:popover-open`); the Popup's `toggle`, ref attach and detach. */\n readonly setShown: (shown: boolean) => void;\n /**\n * The popup was shown at its last `toggle` and the DOM has it hidden now: the browser hid it\n * and its `toggle` has not arrived yet. A non-button Trigger's click lands in that window after\n * light dismiss hid the popup at `pointerup` (#115): it records an `\"activate\"` intent for the\n * fact instead of requesting a close. Handlers only.\n */\n readonly hiddenBeforeToggle: () => boolean;\n}\n\nexport interface UseOverlayRootOptions<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n> {\n /** Transition types and messages: `\"popover\"` gives `fsui-popover`, `fsui-popover-open`, … */\n readonly component: string;\n /** Public name of the Root part for development warnings (`\"Popover.Root\"`). */\n readonly part: string;\n readonly open: boolean | undefined;\n readonly defaultOpen: boolean | undefined;\n readonly openChangeAction: ChangeAction<boolean, Details> | undefined;\n /** The fact handler (#148): called for a hide the library did not perform. */\n readonly onOpenChange: UrgentChangeHandler<boolean, Details> | undefined;\n /**\n * `\"library\"` forces library mode whatever the props (Menu, which has no JS-free mode). Default:\n * detected from `open` / `defaultOpen` / `openChangeAction` / `onOpenChange` on the first\n * render.\n */\n readonly mode?: \"library\";\n /**\n * Called synchronously for every dispatch, before the action runs, and for every fact, before\n * `onOpenChange` (Menu: cancel hover timers, read the open cause).\n */\n readonly onDispatch?: (next: boolean, details: Details) => void;\n /** Builds the `details` of a dispatch (`popoverDetails`: `{ reason }`); an open passes no args. */\n readonly details: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs | []\n ) => Details;\n /**\n * Whether the popup is shown, for a stale close intent: `:popover-open` (`usePopoverRoot`), a\n * `<dialog>`'s `open` (Dialog).\n */\n readonly isShown: (popup: Popup) => boolean;\n}\n\n/** How long a recorded close intent survives when the popup did not close (design 2.3). */\nfunction clearLater<Popup extends HTMLElement>(\n intentRef: { current: OverlayCloseIntent | undefined },\n intent: OverlayCloseIntent,\n popupRef: { current: Popup | null },\n isShown: (popup: Popup) => boolean,\n): void {\n setTimeout(() => {\n // Closed: its `toggle` / `close` event (queued as a task) consumes the intent. Still open: the\n // close was cancelled or invalid, so the intent is stale.\n const popup = popupRef.current;\n if (intentRef.current === intent && popup !== null && isShown(popup)) {\n intentRef.current = undefined;\n }\n }, 0);\n}\n\n/** What the popup is called in the controlled-without-`onOpenChange` warning. */\nconst nouns: Record<string, string> = {\n combobox: \"listbox\",\n \"hover-card\": \"card\",\n \"navigation-menu\": \"panel\",\n};\n\n/** The `details` of a popover-like component: `{ reason }` (and `event`). */\nexport const popoverDetails = (event: Event | undefined, reason: ChangeReason): OverlayDetails =>\n createActionDetails(event, { reason });\n\n/**\n * The Root of an overlay without its public props: mode detection (once, from the first\n * render), `useControllableAction<boolean>`, ids, refs, close intents, the open generation and\n * the intent-aware `requestOpen` / `requestClose`, and `notifyClosed` for facts.\n */\nexport function useOverlayRoot<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n>(options: UseOverlayRootOptions<Details, Popup, CloseArgs>): OverlayRootValue<Popup, CloseArgs> {\n const {\n component,\n part,\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details,\n onDispatch,\n } = options;\n\n // Mode is decided once, from the first render's props (design 2).\n const isLibraryNow =\n options.mode === \"library\" ||\n open !== undefined ||\n defaultOpen !== undefined ||\n openChangeAction !== undefined ||\n onOpenChange !== undefined;\n const mode = useMountFixed<OverlayMode>(\n isLibraryNow ? \"library\" : \"static\",\n isDev &&\n `${part}: the mode changed after mount (\\`open\\`, \\`defaultOpen\\`, \\`openChangeAction\\` ` +\n \"and `onOpenChange` were all absent on one render and present on another). Switching \" +\n \"between JS-free and library mode is not supported.\",\n );\n const isLibrary = mode === \"library\";\n // W1 (conventions 3.9.13): React's `value` without `onChange`. Static only: a handler\n // that adopts late (in a transition, after an `await`) cannot be told from an intentional\n // re-open, so nothing at runtime warns.\n const noun = nouns[component] ?? component;\n useDevWarning(\n isLibrary && open !== undefined && onOpenChange === undefined,\n isDev &&\n `${part}: \\`open\\` is set without \\`onOpenChange\\`. The browser can close this ${noun} ` +\n \"without asking (Escape, a click outside), and `onOpenChange` is where a controlled \" +\n `${part} is told. Without it the ${noun} re-opens after every dismissal. Pass ` +\n \"`onOpenChange={setOpen}`, or `onOpenChange={() => {}}` if re-opening is what you want.\",\n );\n\n // Hooks cannot be conditional: JS-free mode calls the hook too and never dispatches.\n const { committed, optimistic, pending, dispatch, latestInFlight, adoptFact, epoch } =\n useControllableAction<boolean, Details>({\n controlled: isLibrary ? open : undefined,\n defaultValue: isLibrary ? defaultOpen : undefined,\n initialValue: false,\n action: isLibrary ? openChangeAction : undefined,\n transitionTypes: (next) => transitionTypes(component, next ? \"open\" : \"close\"),\n warn: { component: part, prop: \"open\" },\n });\n\n const id = useId();\n const triggerRef = useRef<HTMLElement | null>(null);\n const popupRef = useRef<Popup | null>(null);\n const closeIntent = useRef<OverlayCloseIntent | undefined>(undefined);\n\n // The optimistic value of the last commit, for callers that run after an `await` (a Close\n // action's continuation) and would otherwise read the value of the render they were created in.\n // An insertion effect runs in the mutation phase, before any layout effect of the same commit\n // (a child's included), so `intended()` is current there too.\n const committedOptimistic = useLatest(optimistic);\n // `details`, `onDispatch` and `isShown` are usually inline functions: read the committed render's\n // through a ref so that the functions below, and with them the returned value, stay stable.\n const callbacks = useLatest({ details, onDispatch, onOpenChange, isShown: options.isShown });\n const generation = useRef(0);\n const openGeneration = useCallback(() => generation.current, []);\n const nextOpenGeneration = useCallback(() => {\n generation.current++;\n }, []);\n\n const recordCloseIntent = useCallback(\n (intent: OverlayCloseIntent | undefined, options?: { readonly unlessRecorded?: boolean }) => {\n if (options?.unlessRecorded === true && closeIntent.current !== undefined) return;\n closeIntent.current = intent;\n if (intent !== undefined) {\n clearLater(closeIntent, intent, popupRef, callbacks.current.isShown);\n }\n },\n [callbacks],\n );\n const takeCloseIntent = useCallback(() => {\n const intent = closeIntent.current;\n closeIntent.current = undefined;\n return intent;\n }, []);\n\n // Conventions 3.8 rule 1: judge no-ops against what the user already intends. That also\n // deduplicates the StrictMode re-run of the mount reconciliation and recognises the library's\n // own `hidePopover()` echoing back through `toggle`.\n const intended = useCallback(\n (): boolean => intendedValue(latestInFlight, committedOptimistic.current),\n [latestInFlight, committedOptimistic],\n );\n\n const send = useCallback(\n (next: boolean, event: Event | undefined, reason: ChangeReason, args: CloseArgs | []): void => {\n const { details, onDispatch } = callbacks.current;\n const built = details(event, reason, ...args);\n if (next) nextOpenGeneration();\n onDispatch?.(next, built);\n dispatch(next, built);\n },\n [callbacks, nextOpenGeneration, dispatch],\n );\n\n const requestOpen = useCallback(\n (event: Event | undefined, reason: ChangeReason): void => {\n if (!isLibrary || intended()) return;\n send(true, event, reason, []);\n },\n [isLibrary, intended, send],\n );\n\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary || !intended()) return;\n send(false, event, reason, args);\n },\n [isLibrary, intended, send],\n );\n\n const notifyClosed = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary) return;\n const { details, onDispatch, onOpenChange } = callbacks.current;\n const built = details(event, reason, ...args);\n onDispatch?.(false, built);\n // Supersede the requests in flight and write committed `false` (urgent), then tell the\n // consumer; both in the platform event, so one discrete commit follows (design 2.3).\n adoptFact(false);\n callUrgentHandler(onOpenChange, false, built);\n },\n [isLibrary, callbacks, adoptFact],\n );\n\n const ids = useMemo(\n () => ({ popup: id, title: `${id}-title`, description: `${id}-description` }),\n [id],\n );\n\n // Memoised: every function above is stable, so the value changes only with the open state and\n // pending, and the components' context values built on it are reused otherwise.\n return useMemo(\n () => ({\n mode,\n ids,\n committed: isLibrary && committed,\n optimistic: isLibrary && optimistic,\n pending: isLibrary && pending,\n epoch,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n notifyClosed,\n latestInFlight,\n triggerRef,\n popupRef,\n recordCloseIntent,\n takeCloseIntent,\n }),\n [\n mode,\n ids,\n isLibrary,\n committed,\n optimistic,\n pending,\n epoch,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n notifyClosed,\n latestInFlight,\n recordCloseIntent,\n takeCloseIntent,\n ],\n );\n}\n\n/**\n * The Root of a popover-like component (Popover, Menu, Combobox): `useOverlayRoot` over a\n * `popover` element (`:popover-open`), plus the `shown` mirror and `hiddenBeforeToggle`.\n */\nexport function usePopoverRoot<Details extends ActionDetails>(\n options: Omit<UseOverlayRootOptions<Details>, \"isShown\">,\n): PopoverRootValue {\n const root = useOverlayRoot<Details>({ ...options, isShown: isPopoverOpen });\n const { popupRef } = root;\n\n const [shown, setShownState] = useState(false);\n // The last value written, for handlers (`hiddenBeforeToggle`).\n const shownNow = useRef(false);\n const setShown = useCallback((next: boolean) => {\n shownNow.current = next;\n setShownState(next);\n }, []);\n const hiddenBeforeToggle = useCallback((): boolean => {\n const popup = popupRef.current;\n return shownNow.current && popup !== null && !isPopoverOpen(popup);\n }, [popupRef]);\n\n // Changes only with `root` and `shown`, so as rarely as `root` itself does.\n return useMemo(\n () => ({ ...root, shown, setShown, hiddenBeforeToggle }),\n [root, shown, setShown, hiddenBeforeToggle],\n );\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AA0MvC,SAAS,WACP,WACA,QACA,UACA,SACM;CACN,iBAAiB;EAGf,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,YAAY,UAAU,UAAU,QAAQ,QAAQ,KAAK,GACjE,UAAU,UAAU,KAAA;CAExB,GAAG,CAAC;AACN;;AAGA,MAAM,QAAgC;CACpC,UAAU;CACV,cAAc;CACd,mBAAmB;AACrB;;AAGA,MAAa,kBAAkB,OAA0B,WACvD,oBAAoB,OAAO,EAAE,OAAO,CAAC;;;;;;AAOvC,SAAgB,eAId,SAA+F;CAC/F,MAAM,EACJ,WACA,MACA,MACA,aACA,kBACA,cACA,SACA,eACE;CAGJ,MAAM,eACJ,QAAQ,SAAS,aACjB,SAAS,KAAA,KACT,gBAAgB,KAAA,KAChB,qBAAqB,KAAA,KACrB,iBAAiB,KAAA;CACnB,MAAM,OAAO,cACX,eAAe,YAAY,UAC3B,SACE,GAAG,KAAK,yNAGZ;CACA,MAAM,YAAY,SAAS;CAI3B,MAAM,OAAO,MAAM,cAAc;CACjC,cACE,aAAa,SAAS,KAAA,KAAa,iBAAiB,KAAA,GACpD,SACE,GAAG,KAAK,yEAAyE,KAAK,wFAEjF,KAAK,2BAA2B,KAAK,iIAE9C;CAGA,MAAM,EAAE,WAAW,YAAY,SAAS,UAAU,gBAAgB,WAAW,UAC3E,sBAAwC;EACtC,YAAY,YAAY,OAAO,KAAA;EAC/B,cAAc,YAAY,cAAc,KAAA;EACxC,cAAc;EACd,QAAQ,YAAY,mBAAmB,KAAA;EACvC,kBAAkB,SAAS,gBAAgB,WAAW,OAAO,SAAS,OAAO;EAC7E,MAAM;GAAE,WAAW;GAAM,MAAM;EAAO;CACxC,CAAC;CAEH,MAAM,KAAK,MAAM;CACjB,MAAM,aAAa,OAA2B,IAAI;CAClD,MAAM,WAAW,OAAqB,IAAI;CAC1C,MAAM,cAAc,OAAuC,KAAA,CAAS;CAMpE,MAAM,sBAAsB,UAAU,UAAU;CAGhD,MAAM,YAAY,UAAU;EAAE;EAAS;EAAY;EAAc,SAAS,QAAQ;CAAQ,CAAC;CAC3F,MAAM,aAAa,OAAO,CAAC;CAC3B,MAAM,iBAAiB,kBAAkB,WAAW,SAAS,CAAC,CAAC;CAC/D,MAAM,qBAAqB,kBAAkB;EAC3C,WAAW;CACb,GAAG,CAAC,CAAC;CAEL,MAAM,oBAAoB,aACvB,QAAwC,YAAoD;EAC3F,IAAI,SAAS,mBAAmB,QAAQ,YAAY,YAAY,KAAA,GAAW;EAC3E,YAAY,UAAU;EACtB,IAAI,WAAW,KAAA,GACb,WAAW,aAAa,QAAQ,UAAU,UAAU,QAAQ,OAAO;CAEvE,GACA,CAAC,SAAS,CACZ;CACA,MAAM,kBAAkB,kBAAkB;EACxC,MAAM,SAAS,YAAY;EAC3B,YAAY,UAAU,KAAA;EACtB,OAAO;CACT,GAAG,CAAC,CAAC;CAKL,MAAM,WAAW,kBACA,cAAc,gBAAgB,oBAAoB,OAAO,GACxE,CAAC,gBAAgB,mBAAmB,CACtC;CAEA,MAAM,OAAO,aACV,MAAe,OAA0B,QAAsB,SAA+B;EAC7F,MAAM,EAAE,SAAS,eAAe,UAAU;EAC1C,MAAM,QAAQ,QAAQ,OAAO,QAAQ,GAAG,IAAI;EAC5C,IAAI,MAAM,mBAAmB;EAC7B,aAAa,MAAM,KAAK;EACxB,SAAS,MAAM,KAAK;CACtB,GACA;EAAC;EAAW;EAAoB;CAAQ,CAC1C;CAEA,MAAM,cAAc,aACjB,OAA0B,WAA+B;EACxD,IAAI,CAAC,aAAa,SAAS,GAAG;EAC9B,KAAK,MAAM,OAAO,QAAQ,CAAC,CAAC;CAC9B,GACA;EAAC;EAAW;EAAU;CAAI,CAC5B;CAEA,MAAM,eAAe,aAClB,OAA0B,QAAsB,GAAG,SAA0B;EAC5E,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG;EAC/B,KAAK,OAAO,OAAO,QAAQ,IAAI;CACjC,GACA;EAAC;EAAW;EAAU;CAAI,CAC5B;CAEA,MAAM,eAAe,aAClB,OAA0B,QAAsB,GAAG,SAA0B;EAC5E,IAAI,CAAC,WAAW;EAChB,MAAM,EAAE,SAAS,YAAY,iBAAiB,UAAU;EACxD,MAAM,QAAQ,QAAQ,OAAO,QAAQ,GAAG,IAAI;EAC5C,aAAa,OAAO,KAAK;EAGzB,UAAU,KAAK;EACf,kBAAkB,cAAc,OAAO,KAAK;CAC9C,GACA;EAAC;EAAW;EAAW;CAAS,CAClC;CAEA,MAAM,MAAM,eACH;EAAE,OAAO;EAAI,OAAO,GAAG,GAAG;EAAS,aAAa,GAAG,GAAG;CAAc,IAC3E,CAAC,EAAE,CACL;CAIA,OAAO,eACE;EACL;EACA;EACA,WAAW,aAAa;EACxB,YAAY,aAAa;EACzB,SAAS,aAAa;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;AACF;;;;;AAMA,SAAgB,eACd,SACkB;CAClB,MAAM,OAAO,eAAwB;EAAE,GAAG;EAAS,SAAS;CAAc,CAAC;CAC3E,MAAM,EAAE,aAAa;CAErB,MAAM,CAAC,OAAO,iBAAiB,SAAS,KAAK;CAE7C,MAAM,WAAW,OAAO,KAAK;CAC7B,MAAM,WAAW,aAAa,SAAkB;EAC9C,SAAS,UAAU;EACnB,cAAc,IAAI;CACpB,GAAG,CAAC,CAAC;CACL,MAAM,qBAAqB,kBAA2B;EACpD,MAAM,QAAQ,SAAS;EACvB,OAAO,SAAS,WAAW,UAAU,QAAQ,CAAC,cAAc,KAAK;CACnE,GAAG,CAAC,QAAQ,CAAC;CAGb,OAAO,eACE;EAAE,GAAG;EAAM;EAAO;EAAU;CAAmB,IACtD;EAAC;EAAM;EAAO;EAAU;CAAkB,CAC5C;AACF"}
@@ -68,7 +68,7 @@ function nonInvokerMessage(part, tag, popover, popup) {
68
68
  * Menu adds `aria-haspopup="menu"` and its own key handling on top.
69
69
  */
70
70
  function usePopoverTrigger(ctx, options) {
71
- const { part, disabled, render, handlers, onActivate, submenuItem = false } = options;
71
+ const { part, disabled, render, handlers, onActivate, submenuItem = false, alwaysFocusable = false } = options;
72
72
  const isLibrary = ctx.mode === "library";
73
73
  const { ids, triggerRef, popupRef } = ctx;
74
74
  const state = {
@@ -110,7 +110,7 @@ function usePopoverTrigger(ctx, options) {
110
110
  }
111
111
  const disabledProps = disabledButton(render, disabled, {
112
112
  handlesClick: isLibrary,
113
- alwaysFocusable: submenuItem
113
+ alwaysFocusable: submenuItem || alwaysFocusable
114
114
  });
115
115
  if (!isLibrary && !disabledProps.invoker) {
116
116
  const extra = handlers?.onClick;
@@ -1 +1 @@
1
- {"version":3,"file":"use-popover-trigger.mjs","names":[],"sources":["../../../src/internal/overlay/use-popover-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type { ComponentPropsWithRef, DOMAttributes, MouseEvent } from \"react\";\nimport { dataAttr } from \"../data-attr.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { registerTrigger } from \"./trigger-ref.js\";\nimport type { RenderProp } from \"../types.js\";\nimport { useElementCheck } from \"../use-element-check.js\";\nimport { cancelClick, disabledButton, rendersButton } from \"../use-render.js\";\nimport type { DataAttributes } from \"../use-render.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The click rule of a Trigger that toggles a popover-kind Root (popover.md 2.8): Popover.Trigger,\n * Menu.Trigger, Menu.SubmenuTrigger (through `usePopoverTrigger`) and Combobox.Trigger. It toggles\n * against what the user already intends (`intended()`, conventions 3.8 rule 1), not the DOM:\n *\n * - intended open, and the browser already hid the popup (a non-button Trigger, #115: light\n * dismiss hid it at `pointerup`, before this click): the hide is a fact, reported by its pending\n * `toggle`; the click only names its cause, an `\"activate\"` close intent;\n * - intended open otherwise: `requestClose(event, \"activate\")`;\n * - intended closed: `beforeOpen()`, then `requestOpen(event, \"activate\")`. First, because what\n * it records (Menu's open cause) must be in place before anything can show the popup. Today the\n * show waits for the apply effect, so the order is not observable.\n *\n * The caller cancels the click and checks `disabled` first. Handlers only.\n */\nexport function toggleFromTrigger(\n ctx: PopoverRootValue,\n event: Event,\n beforeOpen?: () => void,\n): void {\n if (ctx.intended()) {\n if (ctx.hiddenBeforeToggle()) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n ctx.requestClose(event, \"activate\");\n } else {\n beforeOpen?.();\n ctx.requestOpen(event, \"activate\");\n }\n}\n\n/**\n * Owned and never written on an overlay Trigger (Popover, Menu, Combobox): the default\n * `popovertarget` action, which a render element must not change, and an Invoker Command, which\n * would take precedence over `popovertarget` and act on another element.\n */\nexport const RESERVED_INVOKER_KEYS = {\n popoverTargetAction: undefined,\n commandfor: undefined,\n command: undefined,\n} as const;\n\n/**\n * The library-mode dev warning for a Trigger rendered as another element than a `<button>`: only\n * an invoker button is spared by the popover's light dismiss, so a press while the popup is open\n * hides it before the click. `popover` and `popup` are the nouns the text uses for it.\n */\nexport function nonInvokerMessage(\n part: string,\n tag: string,\n popover: string,\n popup: string,\n): string {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the ${popover}'s invoker: a press on ` +\n `this element while the ${popup} is open closes it through light dismiss before the ` +\n \"click, so the close is a dismissal (reported to onOpenChange) rather than a request: \" +\n \"openChangeAction(false) is not called, cannot veto it and there is no view transition. \" +\n \"Render a <button>.\"\n );\n}\n\n/** The state of an overlay Trigger (Popover.Trigger, Menu.Trigger and its siblings). */\nexport interface PopoverTriggerHookState {\n /** Optimistic open state. A Popover in JS-free mode (the browser owns it) reports `false`. */\n readonly open: boolean;\n /** The Root's transition is pending: an open or a part-initiated close (never a dismissal). */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Event handlers a component layers onto the Trigger's own (Menu's keys and hover intent). */\nexport type PopoverTriggerHandlers = Pick<\n DOMAttributes<HTMLButtonElement>,\n \"onClick\" | \"onKeyDown\" | \"onMouseDown\" | \"onPointerMove\" | \"onPointerEnter\" | \"onPointerLeave\"\n>;\n\nexport interface UsePopoverTriggerOptions<State> {\n /** Public name of the part for development warnings (`\"Popover.Trigger\"`). */\n readonly part: string;\n readonly disabled: boolean;\n readonly render: RenderProp<ComponentPropsWithRef<\"button\">, State> | undefined;\n /**\n * Extra handlers, merged in front of the Trigger's own: for a key both define, the extra one\n * runs first (the consumer's pass-through handler still runs before both, conventions 1.2).\n */\n readonly handlers?: PopoverTriggerHandlers;\n /**\n * What a click does in library mode, after the command has been cancelled and `disabled`\n * checked. Default: `toggleFromTrigger(ctx, event.nativeEvent)`, the toggle against\n * `intended()` (`requestOpen` / `requestClose`). Menu.Trigger toggles with its open cause;\n * Menu.SubmenuTrigger opens, or moves focus into an already open submenu.\n */\n readonly onActivate?: (event: MouseEvent<HTMLElement>) => void;\n /**\n * Menu.SubmenuTrigger: the Trigger is also an item of the parent menu, whose click\n * (`onActivate`) never closes the popup. `disabled` renders `aria-disabled=\"true\"` and no\n * `disabled` attribute, so the item stays focusable (the click handler still refuses); without\n * it `disabled` is the native attribute, so the button is no invoker at all (in library mode a\n * link or component `render` still gets `aria-disabled`, because native `disabled` means\n * nothing on a link and the installed click handler is what refuses). And the library-mode\n * non-button warning says a press while open dismisses the popup instead of moving focus into\n * it.\n */\n readonly submenuItem?: boolean;\n}\n\nexport interface PopoverTriggerHook {\n readonly state: PopoverTriggerHookState;\n /** Owned props (conventions 1.2) for `useRender`'s `libraryProps`. */\n readonly libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes;\n /** Registers the element as the Root's Trigger; pass as `useRender`'s `ref`. */\n readonly ref: (element: HTMLElement) => () => void;\n}\n\n/**\n * The Trigger of a popover-like component (design/components/popover.md 14.3):\n * `button[popoverTarget]`, with no `aria-expanded` on an invoker: every engine exposes the\n * popover's shown state from the invoker relationship. In JS-free mode the browser toggles\n * the popover and the Popup keeps `data-open` current on the element. In library mode the click\n * is cancelled (so the activation does not run) and toggles against what the user already\n * intends: an open through `requestOpen`, a library-owned close through `requestClose`. There\n * `data-open` and `state.open` are optimistic; a non-button `render` (no invoker) renders\n * `aria-expanded` from whether the popup is shown (in the top layer).\n *\n * Menu adds `aria-haspopup=\"menu\"` and its own key handling on top.\n */\nexport function usePopoverTrigger<State>(\n ctx: PopoverRootValue,\n options: UsePopoverTriggerOptions<State>,\n): PopoverTriggerHook {\n const { part, disabled, render, handlers, onActivate, submenuItem = false } = options;\n const isLibrary = ctx.mode === \"library\";\n const { ids, triggerRef, popupRef } = ctx;\n\n const state: PopoverTriggerHookState = {\n open: ctx.optimistic,\n // Opens and part-initiated closes belong to the Trigger (4.2); a dismissal is a fact and\n // pends nothing (conventions 3.9.7).\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n if (element.tagName === \"BUTTON\") return null;\n const tag = element.tagName.toLowerCase();\n // Library mode: the click handler works, but only an invoker button is spared by the\n // popover's light dismiss, so a press while open hides the popup before the click.\n if (isLibrary && submenuItem) {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the popover's invoker: a press on ` +\n \"this element while its popup is open dismisses the popup through light dismiss \" +\n \"instead of moving focus into it. Render a <button>.\"\n );\n }\n return isLibrary\n ? nonInvokerMessage(part, tag, \"popover\", \"popup\")\n : `${part}: rendered a <${tag}> in JS-free mode. Only a <button> is a ` +\n \"`popovertarget` invoker; this trigger will not open the popover. Render a \" +\n \"<button>, or put the component in library mode (`defaultOpen={false}`).\";\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n const unregister = registerTrigger(triggerRef, element, part);\n // JS-free mode: the DOM owns `data-open` (design 9). A Trigger that mounts after the\n // Popup (or is re-created) picks up the current state here.\n if (!isLibrary && popupRef.current !== null) {\n element.toggleAttribute(\"data-open\", isPopoverOpen(popupRef.current));\n }\n return unregister;\n },\n [isLibrary, checkElement, triggerRef, popupRef, part],\n );\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the popover toggle (it runs as the button's activation\n // behaviour, only if the click was not cancelled). Enter and Space synthesise the same click.\n event.preventDefault();\n if (disabled) return;\n if (onActivate !== undefined) onActivate(event);\n else toggleFromTrigger(ctx, event.nativeEvent);\n };\n\n // The component's handlers first, then the Trigger's (design/components/menu.md 14). The click\n // handler is only owned when installed, so a render element keeps its own `onClick` in JS-free\n // mode.\n const merged: PopoverTriggerHandlers = { ...handlers };\n if (isLibrary) {\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? onClick\n : (event) => {\n extra(event);\n onClick(event);\n };\n }\n // The click handler is installed in library mode only; in JS-free mode the activation needs\n // native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, {\n handlesClick: isLibrary,\n alwaysFocusable: submenuItem,\n });\n if (!isLibrary && !disabledProps.invoker) {\n // JS-free mode, disabled in the `aria-disabled` branch (a host link): nothing native stops the\n // click, so cancel it (a disabled link must not navigate). Only while disabled, after the\n // component's own handler.\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? cancelClick\n : (event) => {\n extra(event);\n cancelClick(event);\n };\n }\n\n const invoker = disabledProps.invoker && rendersButton(render);\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // `type` only applies to a <button>; on any other element the key is not owned.\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Trigger (in JS-free mode the browser\n // would toggle the popover).\n ...disabledProps.props,\n // Only on a button (or a component, assumed to render one): another element is no invoker,\n // and the attribute would claim otherwise.\n popoverTarget: invoker ? ids.popup : undefined,\n ...RESERVED_INVOKER_KEYS,\n // No `aria-expanded` on an invoker: every engine exposes the popover's shown state from\n // `popovertarget`, and ARIA in HTML forbids the attribute there. Otherwise nothing else\n // exposes the state: library mode renders shown (the popup is in the top layer; `data-open`\n // is the optimistic one), JS-free mode cannot know it and renders \"false\".\n \"aria-expanded\": invoker ? undefined : isLibrary ? ctx.shown : false,\n ...merged,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n // Every mode: the styling hook agrees with the rendered `disabled` / `aria-disabled`\n // (conventions 1.2).\n \"data-disabled\": dataAttr(disabled),\n };\n\n return { state, libraryProps, ref };\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;AAiBvC,SAAgB,kBACd,KACA,OACA,YACM;CACN,IAAI,IAAI,SAAS,GAAG;EAClB,IAAI,IAAI,mBAAmB,GAAG;GAC5B,IAAI,kBAAkB;IAAE,QAAQ;IAAY;GAAM,CAAC;GACnD;EACF;EACA,IAAI,aAAa,OAAO,UAAU;CACpC,OAAO;EACL,aAAa;EACb,IAAI,YAAY,OAAO,UAAU;CACnC;AACF;;;;;;AAOA,MAAa,wBAAwB;CACnC,qBAAqB,KAAA;CACrB,YAAY,KAAA;CACZ,SAAS,KAAA;AACX;;;;;;AAOA,SAAgB,kBACd,MACA,KACA,SACA,OACQ;CACR,OACE,GAAG,KAAK,gBAAgB,IAAI,4BAA4B,QAAQ,gDACtC,MAAM;AAKpC;;;;;;;;;;;;;AAoEA,SAAgB,kBACd,KACA,SACoB;CACpB,MAAM,EAAE,MAAM,UAAU,QAAQ,UAAU,YAAY,cAAc,UAAU;CAC9E,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,KAAK,YAAY,aAAa;CAEtC,MAAM,QAAiC;EACrC,MAAM,IAAI;EAGV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,IAAI,QAAQ,YAAY,UAAU,OAAO;EACzC,MAAM,MAAM,QAAQ,QAAQ,YAAY;EAGxC,IAAI,aAAa,aACf,OACE,GAAG,KAAK,gBAAgB,IAAI;EAKhC,OAAO,YACH,kBAAkB,MAAM,KAAK,WAAW,OAAO,IAC/C,GAAG,KAAK,gBAAgB,IAAI;CAGlC,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,MAAM,aAAa,gBAAgB,YAAY,SAAS,IAAI;EAG5D,IAAI,CAAC,aAAa,SAAS,YAAY,MACrC,QAAQ,gBAAgB,aAAa,cAAc,SAAS,OAAO,CAAC;EAEtE,OAAO;CACT,GACA;EAAC;EAAW;EAAc;EAAY;EAAU;CAAI,CACtD;CAEA,MAAM,WAAW,UAAmC;EAGlD,MAAM,eAAe;EACrB,IAAI,UAAU;EACd,IAAI,eAAe,KAAA,GAAW,WAAW,KAAK;OACzC,kBAAkB,KAAK,MAAM,WAAW;CAC/C;CAKA,MAAM,SAAiC,EAAE,GAAG,SAAS;CACrD,IAAI,WAAW;EACb,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,WACC,UAAU;GACT,MAAM,KAAK;GACX,QAAQ,KAAK;EACf;CACR;CAGA,MAAM,gBAAgB,eAAe,QAAQ,UAAU;EACrD,cAAc;EACd,iBAAiB;CACnB,CAAC;CACD,IAAI,CAAC,aAAa,CAAC,cAAc,SAAS;EAIxC,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,eACC,UAAU;GACT,MAAM,KAAK;GACX,YAAY,KAAK;EACnB;CACR;CAEA,MAAM,UAAU,cAAc,WAAW,cAAc,MAAM;CAyB7D,OAAO;EAAE;EAAO,cAAA;GArBd,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GAGvD,GAAG,cAAc;GAGjB,eAAe,UAAU,IAAI,QAAQ,KAAA;GACrC,GAAG;GAKH,iBAAiB,UAAU,KAAA,IAAY,YAAY,IAAI,QAAQ;GAC/D,GAAG;GACH,aAAa,SAAS,MAAM,IAAI;GAChC,gBAAgB,SAAS,MAAM,OAAO;GAGtC,iBAAiB,SAAS,QAAQ;EAGT;EAAG;CAAI;AACpC"}
1
+ {"version":3,"file":"use-popover-trigger.mjs","names":[],"sources":["../../../src/internal/overlay/use-popover-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type { ComponentPropsWithRef, DOMAttributes, MouseEvent } from \"react\";\nimport { dataAttr } from \"../data-attr.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { registerTrigger } from \"./trigger-ref.js\";\nimport type { RenderProp } from \"../types.js\";\nimport { useElementCheck } from \"../use-element-check.js\";\nimport { cancelClick, disabledButton, rendersButton } from \"../use-render.js\";\nimport type { DataAttributes } from \"../use-render.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The click rule of a Trigger that toggles a popover-kind Root (popover.md 2.8): Popover.Trigger,\n * Menu.Trigger, Menu.SubmenuTrigger (through `usePopoverTrigger`) and Combobox.Trigger. It toggles\n * against what the user already intends (`intended()`, conventions 3.8 rule 1), not the DOM:\n *\n * - intended open, and the browser already hid the popup (a non-button Trigger, #115: light\n * dismiss hid it at `pointerup`, before this click): the hide is a fact, reported by its pending\n * `toggle`; the click only names its cause, an `\"activate\"` close intent;\n * - intended open otherwise: `requestClose(event, \"activate\")`;\n * - intended closed: `beforeOpen()`, then `requestOpen(event, \"activate\")`. First, because what\n * it records (Menu's open cause) must be in place before anything can show the popup. Today the\n * show waits for the apply effect, so the order is not observable.\n *\n * The caller cancels the click and checks `disabled` first. Handlers only.\n */\nexport function toggleFromTrigger(\n ctx: PopoverRootValue,\n event: Event,\n beforeOpen?: () => void,\n): void {\n if (ctx.intended()) {\n if (ctx.hiddenBeforeToggle()) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n ctx.requestClose(event, \"activate\");\n } else {\n beforeOpen?.();\n ctx.requestOpen(event, \"activate\");\n }\n}\n\n/**\n * Owned and never written on an overlay Trigger (Popover, Menu, Combobox): the default\n * `popovertarget` action, which a render element must not change, and an Invoker Command, which\n * would take precedence over `popovertarget` and act on another element.\n */\nexport const RESERVED_INVOKER_KEYS = {\n popoverTargetAction: undefined,\n commandfor: undefined,\n command: undefined,\n} as const;\n\n/**\n * The library-mode dev warning for a Trigger rendered as another element than a `<button>`: only\n * an invoker button is spared by the popover's light dismiss, so a press while the popup is open\n * hides it before the click. `popover` and `popup` are the nouns the text uses for it.\n */\nexport function nonInvokerMessage(\n part: string,\n tag: string,\n popover: string,\n popup: string,\n): string {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the ${popover}'s invoker: a press on ` +\n `this element while the ${popup} is open closes it through light dismiss before the ` +\n \"click, so the close is a dismissal (reported to onOpenChange) rather than a request: \" +\n \"openChangeAction(false) is not called, cannot veto it and there is no view transition. \" +\n \"Render a <button>.\"\n );\n}\n\n/** The state of an overlay Trigger (Popover.Trigger, Menu.Trigger and its siblings). */\nexport interface PopoverTriggerHookState {\n /** Optimistic open state. A Popover in JS-free mode (the browser owns it) reports `false`. */\n readonly open: boolean;\n /** The Root's transition is pending: an open or a part-initiated close (never a dismissal). */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Event handlers a component layers onto the Trigger's own (Menu's keys and hover intent). */\nexport type PopoverTriggerHandlers = Pick<\n DOMAttributes<HTMLButtonElement>,\n \"onClick\" | \"onKeyDown\" | \"onMouseDown\" | \"onPointerMove\" | \"onPointerEnter\" | \"onPointerLeave\"\n>;\n\nexport interface UsePopoverTriggerOptions<State> {\n /** Public name of the part for development warnings (`\"Popover.Trigger\"`). */\n readonly part: string;\n readonly disabled: boolean;\n readonly render: RenderProp<ComponentPropsWithRef<\"button\">, State> | undefined;\n /**\n * Extra handlers, merged in front of the Trigger's own: for a key both define, the extra one\n * runs first (the consumer's pass-through handler still runs before both, conventions 1.2).\n */\n readonly handlers?: PopoverTriggerHandlers;\n /**\n * What a click does in library mode, after the command has been cancelled and `disabled`\n * checked. Default: `toggleFromTrigger(ctx, event.nativeEvent)`, the toggle against\n * `intended()` (`requestOpen` / `requestClose`). Menu.Trigger toggles with its open cause;\n * Menu.SubmenuTrigger opens, or moves focus into an already open submenu.\n */\n readonly onActivate?: (event: MouseEvent<HTMLElement>) => void;\n /**\n * Menu.SubmenuTrigger: the Trigger is also an item of the parent menu, whose click\n * (`onActivate`) never closes the popup. `disabled` renders `aria-disabled=\"true\"` and no\n * `disabled` attribute, so the item stays focusable (the click handler still refuses); without\n * it `disabled` is the native attribute, so the button is no invoker at all (in library mode a\n * link or component `render` still gets `aria-disabled`, because native `disabled` means\n * nothing on a link and the installed click handler is what refuses). And the library-mode\n * non-button warning says a press while open dismisses the popup instead of moving focus into\n * it.\n */\n readonly submenuItem?: boolean;\n /**\n * `Menu.Trigger` inside a `Menubar`: an item of the bar, so `disabled` renders\n * `aria-disabled=\"true\"` and the element stays focusable, as with `submenuItem`; the click\n * still toggles and the non-button warning is the ordinary one\n * (design/components/menubar.md 5).\n */\n readonly alwaysFocusable?: boolean;\n}\n\nexport interface PopoverTriggerHook {\n readonly state: PopoverTriggerHookState;\n /** Owned props (conventions 1.2) for `useRender`'s `libraryProps`. */\n readonly libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes;\n /** Registers the element as the Root's Trigger; pass as `useRender`'s `ref`. */\n readonly ref: (element: HTMLElement) => () => void;\n}\n\n/**\n * The Trigger of a popover-like component (design/components/popover.md 14.3):\n * `button[popoverTarget]`, with no `aria-expanded` on an invoker: every engine exposes the\n * popover's shown state from the invoker relationship. In JS-free mode the browser toggles\n * the popover and the Popup keeps `data-open` current on the element. In library mode the click\n * is cancelled (so the activation does not run) and toggles against what the user already\n * intends: an open through `requestOpen`, a library-owned close through `requestClose`. There\n * `data-open` and `state.open` are optimistic; a non-button `render` (no invoker) renders\n * `aria-expanded` from whether the popup is shown (in the top layer).\n *\n * Menu adds `aria-haspopup=\"menu\"` and its own key handling on top.\n */\nexport function usePopoverTrigger<State>(\n ctx: PopoverRootValue,\n options: UsePopoverTriggerOptions<State>,\n): PopoverTriggerHook {\n const {\n part,\n disabled,\n render,\n handlers,\n onActivate,\n submenuItem = false,\n alwaysFocusable = false,\n } = options;\n const isLibrary = ctx.mode === \"library\";\n const { ids, triggerRef, popupRef } = ctx;\n\n const state: PopoverTriggerHookState = {\n open: ctx.optimistic,\n // Opens and part-initiated closes belong to the Trigger (4.2); a dismissal is a fact and\n // pends nothing (conventions 3.9.7).\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n if (element.tagName === \"BUTTON\") return null;\n const tag = element.tagName.toLowerCase();\n // Library mode: the click handler works, but only an invoker button is spared by the\n // popover's light dismiss, so a press while open hides the popup before the click.\n if (isLibrary && submenuItem) {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the popover's invoker: a press on ` +\n \"this element while its popup is open dismisses the popup through light dismiss \" +\n \"instead of moving focus into it. Render a <button>.\"\n );\n }\n return isLibrary\n ? nonInvokerMessage(part, tag, \"popover\", \"popup\")\n : `${part}: rendered a <${tag}> in JS-free mode. Only a <button> is a ` +\n \"`popovertarget` invoker; this trigger will not open the popover. Render a \" +\n \"<button>, or put the component in library mode (`defaultOpen={false}`).\";\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n const unregister = registerTrigger(triggerRef, element, part);\n // JS-free mode: the DOM owns `data-open` (design 9). A Trigger that mounts after the\n // Popup (or is re-created) picks up the current state here.\n if (!isLibrary && popupRef.current !== null) {\n element.toggleAttribute(\"data-open\", isPopoverOpen(popupRef.current));\n }\n return unregister;\n },\n [isLibrary, checkElement, triggerRef, popupRef, part],\n );\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the popover toggle (it runs as the button's activation\n // behaviour, only if the click was not cancelled). Enter and Space synthesise the same click.\n event.preventDefault();\n if (disabled) return;\n if (onActivate !== undefined) onActivate(event);\n else toggleFromTrigger(ctx, event.nativeEvent);\n };\n\n // The component's handlers first, then the Trigger's (design/components/menu.md 14). The click\n // handler is only owned when installed, so a render element keeps its own `onClick` in JS-free\n // mode.\n const merged: PopoverTriggerHandlers = { ...handlers };\n if (isLibrary) {\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? onClick\n : (event) => {\n extra(event);\n onClick(event);\n };\n }\n // The click handler is installed in library mode only; in JS-free mode the activation needs\n // native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, {\n handlesClick: isLibrary,\n alwaysFocusable: submenuItem || alwaysFocusable,\n });\n if (!isLibrary && !disabledProps.invoker) {\n // JS-free mode, disabled in the `aria-disabled` branch (a host link): nothing native stops the\n // click, so cancel it (a disabled link must not navigate). Only while disabled, after the\n // component's own handler.\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? cancelClick\n : (event) => {\n extra(event);\n cancelClick(event);\n };\n }\n\n const invoker = disabledProps.invoker && rendersButton(render);\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // `type` only applies to a <button>; on any other element the key is not owned.\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Trigger (in JS-free mode the browser\n // would toggle the popover).\n ...disabledProps.props,\n // Only on a button (or a component, assumed to render one): another element is no invoker,\n // and the attribute would claim otherwise.\n popoverTarget: invoker ? ids.popup : undefined,\n ...RESERVED_INVOKER_KEYS,\n // No `aria-expanded` on an invoker: every engine exposes the popover's shown state from\n // `popovertarget`, and ARIA in HTML forbids the attribute there. Otherwise nothing else\n // exposes the state: library mode renders shown (the popup is in the top layer; `data-open`\n // is the optimistic one), JS-free mode cannot know it and renders \"false\".\n \"aria-expanded\": invoker ? undefined : isLibrary ? ctx.shown : false,\n ...merged,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n // Every mode: the styling hook agrees with the rendered `disabled` / `aria-disabled`\n // (conventions 1.2).\n \"data-disabled\": dataAttr(disabled),\n };\n\n return { state, libraryProps, ref };\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;AAiBvC,SAAgB,kBACd,KACA,OACA,YACM;CACN,IAAI,IAAI,SAAS,GAAG;EAClB,IAAI,IAAI,mBAAmB,GAAG;GAC5B,IAAI,kBAAkB;IAAE,QAAQ;IAAY;GAAM,CAAC;GACnD;EACF;EACA,IAAI,aAAa,OAAO,UAAU;CACpC,OAAO;EACL,aAAa;EACb,IAAI,YAAY,OAAO,UAAU;CACnC;AACF;;;;;;AAOA,MAAa,wBAAwB;CACnC,qBAAqB,KAAA;CACrB,YAAY,KAAA;CACZ,SAAS,KAAA;AACX;;;;;;AAOA,SAAgB,kBACd,MACA,KACA,SACA,OACQ;CACR,OACE,GAAG,KAAK,gBAAgB,IAAI,4BAA4B,QAAQ,gDACtC,MAAM;AAKpC;;;;;;;;;;;;;AA2EA,SAAgB,kBACd,KACA,SACoB;CACpB,MAAM,EACJ,MACA,UACA,QACA,UACA,YACA,cAAc,OACd,kBAAkB,UAChB;CACJ,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,KAAK,YAAY,aAAa;CAEtC,MAAM,QAAiC;EACrC,MAAM,IAAI;EAGV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,IAAI,QAAQ,YAAY,UAAU,OAAO;EACzC,MAAM,MAAM,QAAQ,QAAQ,YAAY;EAGxC,IAAI,aAAa,aACf,OACE,GAAG,KAAK,gBAAgB,IAAI;EAKhC,OAAO,YACH,kBAAkB,MAAM,KAAK,WAAW,OAAO,IAC/C,GAAG,KAAK,gBAAgB,IAAI;CAGlC,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,MAAM,aAAa,gBAAgB,YAAY,SAAS,IAAI;EAG5D,IAAI,CAAC,aAAa,SAAS,YAAY,MACrC,QAAQ,gBAAgB,aAAa,cAAc,SAAS,OAAO,CAAC;EAEtE,OAAO;CACT,GACA;EAAC;EAAW;EAAc;EAAY;EAAU;CAAI,CACtD;CAEA,MAAM,WAAW,UAAmC;EAGlD,MAAM,eAAe;EACrB,IAAI,UAAU;EACd,IAAI,eAAe,KAAA,GAAW,WAAW,KAAK;OACzC,kBAAkB,KAAK,MAAM,WAAW;CAC/C;CAKA,MAAM,SAAiC,EAAE,GAAG,SAAS;CACrD,IAAI,WAAW;EACb,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,WACC,UAAU;GACT,MAAM,KAAK;GACX,QAAQ,KAAK;EACf;CACR;CAGA,MAAM,gBAAgB,eAAe,QAAQ,UAAU;EACrD,cAAc;EACd,iBAAiB,eAAe;CAClC,CAAC;CACD,IAAI,CAAC,aAAa,CAAC,cAAc,SAAS;EAIxC,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,eACC,UAAU;GACT,MAAM,KAAK;GACX,YAAY,KAAK;EACnB;CACR;CAEA,MAAM,UAAU,cAAc,WAAW,cAAc,MAAM;CAyB7D,OAAO;EAAE;EAAO,cAAA;GArBd,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GAGvD,GAAG,cAAc;GAGjB,eAAe,UAAU,IAAI,QAAQ,KAAA;GACrC,GAAG;GAKH,iBAAiB,UAAU,KAAA,IAAY,YAAY,IAAI,QAAQ;GAC/D,GAAG;GACH,aAAa,SAAS,MAAM,IAAI;GAChC,gBAAgB,SAAS,MAAM,OAAO;GAGtC,iBAAiB,SAAS,QAAQ;EAGT;EAAG;CAAI;AACpC"}
@@ -20,14 +20,16 @@ const CACHE_LIMIT = 32;
20
20
  const formatters = /* @__PURE__ */ new Map();
21
21
  /**
22
22
  * One `Intl.NumberFormat` per `locale` + `format`, so an update loop does not construct one per
23
- * render. Bounded: past 32 entries the oldest is dropped.
23
+ * render. Bounded: past 32 entries the oldest is dropped. The key is JSON, as in
24
+ * `number-field/number-field-format.ts`, so a list and a string never collide.
24
25
  */
25
26
  function getNumberFormat(locale, format) {
26
27
  const options = format ?? PERCENT;
27
- const key = `${locale ?? ""}\u0000${JSON.stringify(options)}`;
28
+ const key = JSON.stringify([locale ?? null, options]);
28
29
  let formatter = formatters.get(key);
29
30
  if (formatter === void 0) {
30
- formatter = new Intl.NumberFormat(locale, options);
31
+ const locales = typeof locale === "string" || locale === void 0 ? locale : [...locale];
32
+ formatter = new Intl.NumberFormat(locales, options);
31
33
  if (formatters.size >= CACHE_LIMIT) {
32
34
  const oldest = formatters.keys().next().value;
33
35
  if (oldest !== void 0) formatters.delete(oldest);