@funstack/ui 0.1.0-alpha.16 → 0.1.0-alpha.17

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 (143) hide show
  1. package/dist/accordion/accordion-root.mjs +1 -1
  2. package/dist/accordion/accordion-root.mjs.map +1 -1
  3. package/dist/button/button.d.mts +21 -8
  4. package/dist/button/button.d.mts.map +1 -1
  5. package/dist/button/button.mjs +8 -6
  6. package/dist/button/button.mjs.map +1 -1
  7. package/dist/checkbox-group/checkbox-group-root.mjs +5 -1
  8. package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
  9. package/dist/combobox/combobox-popup.d.mts +4 -1
  10. package/dist/combobox/combobox-popup.d.mts.map +1 -1
  11. package/dist/combobox/combobox-popup.mjs.map +1 -1
  12. package/dist/combobox/combobox-root.d.mts +15 -5
  13. package/dist/combobox/combobox-root.d.mts.map +1 -1
  14. package/dist/combobox/combobox-root.mjs +9 -11
  15. package/dist/combobox/combobox-root.mjs.map +1 -1
  16. package/dist/combobox/combobox-trigger.mjs +7 -2
  17. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  18. package/dist/dialog/dialog-close.d.mts +13 -3
  19. package/dist/dialog/dialog-close.d.mts.map +1 -1
  20. package/dist/dialog/dialog-close.mjs +3 -2
  21. package/dist/dialog/dialog-close.mjs.map +1 -1
  22. package/dist/dialog/dialog-context.mjs.map +1 -1
  23. package/dist/dialog/dialog-form.d.mts +2 -1
  24. package/dist/dialog/dialog-form.d.mts.map +1 -1
  25. package/dist/dialog/dialog-form.mjs.map +1 -1
  26. package/dist/dialog/dialog-popup.d.mts +9 -4
  27. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  28. package/dist/dialog/dialog-popup.mjs +12 -20
  29. package/dist/dialog/dialog-popup.mjs.map +1 -1
  30. package/dist/dialog/dialog-root.d.mts +38 -24
  31. package/dist/dialog/dialog-root.d.mts.map +1 -1
  32. package/dist/dialog/dialog-root.mjs +10 -8
  33. package/dist/dialog/dialog-root.mjs.map +1 -1
  34. package/dist/dialog/dialog-trigger.d.mts +3 -3
  35. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  36. package/dist/dialog/index.d.mts +5 -5
  37. package/dist/dialog/index.mjs +5 -5
  38. package/dist/dialog/index.mjs.map +1 -1
  39. package/dist/docs/components/button.md +65 -21
  40. package/dist/docs/components/checkbox-group.md +12 -3
  41. package/dist/docs/components/combobox.md +85 -22
  42. package/dist/docs/components/context-menu.md +8 -8
  43. package/dist/docs/components/dialog.md +42 -36
  44. package/dist/docs/components/menu.md +106 -25
  45. package/dist/docs/components/popover.md +101 -36
  46. package/dist/docs/components/progress.md +1 -1
  47. package/dist/docs/components/slider.md +1 -1
  48. package/dist/docs/components/toast.md +37 -14
  49. package/dist/docs/components/toolbar.md +2 -1
  50. package/dist/docs/components/tooltip.md +1 -1
  51. package/dist/docs/concepts/action-props.md +55 -25
  52. package/dist/docs/concepts/browser-owned-state.md +27 -12
  53. package/dist/docs/concepts/pending-and-optimistic.md +15 -2
  54. package/dist/docs/concepts/render.md +23 -0
  55. package/dist/docs/concepts/server-components.md +15 -1
  56. package/dist/docs/concepts/suspense.md +8 -3
  57. package/dist/docs/concepts/transitions.md +3 -9
  58. package/dist/docs/getting-started.md +9 -22
  59. package/dist/docs/index.md +5 -4
  60. package/dist/docs/roadmap.md +54 -0
  61. package/dist/docs/why.md +7 -3
  62. package/dist/index.d.mts +2 -2
  63. package/dist/internal/call-urgent-handler.mjs +37 -0
  64. package/dist/internal/call-urgent-handler.mjs.map +1 -0
  65. package/dist/internal/css-transition-cut.mjs +66 -0
  66. package/dist/internal/css-transition-cut.mjs.map +1 -0
  67. package/dist/internal/overlay-popup.mjs.map +1 -1
  68. package/dist/internal/report-dropped.mjs +45 -0
  69. package/dist/internal/report-dropped.mjs.map +1 -0
  70. package/dist/internal/types.d.mts +33 -7
  71. package/dist/internal/types.d.mts.map +1 -1
  72. package/dist/internal/use-action-trigger.mjs +32 -17
  73. package/dist/internal/use-action-trigger.mjs.map +1 -1
  74. package/dist/internal/use-controllable-action.mjs +52 -16
  75. package/dist/internal/use-controllable-action.mjs.map +1 -1
  76. package/dist/internal/use-exit-animation.mjs +1 -1
  77. package/dist/internal/use-exit-animation.mjs.map +1 -1
  78. package/dist/internal/use-native-group-reconciliation.mjs +4 -2
  79. package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
  80. package/dist/internal/use-overlay-close.mjs +10 -4
  81. package/dist/internal/use-overlay-close.mjs.map +1 -1
  82. package/dist/internal/use-overlay-root.mjs +40 -7
  83. package/dist/internal/use-overlay-root.mjs.map +1 -1
  84. package/dist/internal/use-popover-popup.mjs +22 -7
  85. package/dist/internal/use-popover-popup.mjs.map +1 -1
  86. package/dist/internal/use-popover-trigger.d.mts +1 -1
  87. package/dist/internal/use-popover-trigger.d.mts.map +1 -1
  88. package/dist/internal/use-popover-trigger.mjs +11 -3
  89. package/dist/internal/use-popover-trigger.mjs.map +1 -1
  90. package/dist/menu/menu-checkbox-item.d.mts +1 -1
  91. package/dist/menu/menu-checkbox-item.mjs.map +1 -1
  92. package/dist/menu/menu-item.d.mts +15 -4
  93. package/dist/menu/menu-item.d.mts.map +1 -1
  94. package/dist/menu/menu-item.mjs +10 -5
  95. package/dist/menu/menu-item.mjs.map +1 -1
  96. package/dist/menu/menu-outside.mjs +2 -2
  97. package/dist/menu/menu-outside.mjs.map +1 -1
  98. package/dist/menu/menu-popup.d.mts +3 -0
  99. package/dist/menu/menu-popup.d.mts.map +1 -1
  100. package/dist/menu/menu-popup.mjs.map +1 -1
  101. package/dist/menu/menu-root.d.mts +27 -12
  102. package/dist/menu/menu-root.d.mts.map +1 -1
  103. package/dist/menu/menu-root.mjs +5 -4
  104. package/dist/menu/menu-root.mjs.map +1 -1
  105. package/dist/number-field/number-field-root.d.mts.map +1 -1
  106. package/dist/number-field/number-field-root.mjs +2 -8
  107. package/dist/number-field/number-field-root.mjs.map +1 -1
  108. package/dist/popover/index.d.mts +3 -3
  109. package/dist/popover/index.mjs +3 -3
  110. package/dist/popover/index.mjs.map +1 -1
  111. package/dist/popover/popover-close.d.mts +14 -3
  112. package/dist/popover/popover-close.d.mts.map +1 -1
  113. package/dist/popover/popover-close.mjs +4 -2
  114. package/dist/popover/popover-close.mjs.map +1 -1
  115. package/dist/popover/popover-popup.d.mts +6 -3
  116. package/dist/popover/popover-popup.d.mts.map +1 -1
  117. package/dist/popover/popover-popup.mjs +3 -2
  118. package/dist/popover/popover-popup.mjs.map +1 -1
  119. package/dist/popover/popover-root.d.mts +31 -18
  120. package/dist/popover/popover-root.d.mts.map +1 -1
  121. package/dist/popover/popover-root.mjs +9 -7
  122. package/dist/popover/popover-root.mjs.map +1 -1
  123. package/dist/slider/slider-root.d.mts.map +1 -1
  124. package/dist/slider/slider-root.mjs +2 -8
  125. package/dist/slider/slider-root.mjs.map +1 -1
  126. package/dist/toast/toast-action.d.mts +14 -3
  127. package/dist/toast/toast-action.d.mts.map +1 -1
  128. package/dist/toast/toast-action.mjs +6 -4
  129. package/dist/toast/toast-action.mjs.map +1 -1
  130. package/dist/toast/toast-context.mjs.map +1 -1
  131. package/dist/toast/toast-queue.mjs.map +1 -1
  132. package/dist/toast/toast-viewport.d.mts.map +1 -1
  133. package/dist/toast/toast-viewport.mjs +15 -15
  134. package/dist/toast/toast-viewport.mjs.map +1 -1
  135. package/dist/toast/toast.d.mts +10 -7
  136. package/dist/toast/toast.d.mts.map +1 -1
  137. package/dist/toast/toast.mjs.map +1 -1
  138. package/dist/toggle-group/toggle-group-root.mjs +1 -1
  139. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  140. package/package.json +1 -1
  141. package/skills/funstack-ui-knowledge/SKILL.md +6 -6
  142. package/dist/internal/use-superseded-rejection.mjs +0 -47
  143. package/dist/internal/use-superseded-rejection.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { listenInvokerPresses } from \"../internal/invokers.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { capturePointer } from \"../internal/pointer-capture.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport { edgeItem } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport { listenOutside } from \"./menu-outside.js\";\nimport { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from \"./menu-point.js\";\nimport { useMenuKeyboard } from \"./use-menu-keyboard.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type MenuSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type MenuAlign = AnchorAlign;\n\n/**\n * State of `Menu.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Popup`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. A submenu's `\"inline-end\"` is the right of the item in LTR,\n * its left in RTL; its fallback is `flip-inline` only. `\"left\"` / `\"right\"` stay physical.\n * `null` emits no inline positioning (and no `data-side` / `data-align`): the stylesheet owns\n * placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n *\n * @defaultValue `\"bottom\"` for a top-level menu, `\"inline-end\"` for a submenu\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side: inline-relative on a top / bottom side (mirrored under\n * `direction: rtl`), the top edges on the others. Ignored when `side` is `null`.\n *\n * @defaultValue `\"start\"` (both levels)\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines.\n *\n * @defaultValue `false`\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);\n * a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no\n * focus, so that button's click closes the menu as `\"activate\"`.\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`.\n * Such an open is placed at the pointer: `--menu-point-x` / `--menu-point-y` inline and, unless\n * `side` is `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules it renders as a hoisted `<style>`. A top-level menu\n * closes at once on a right- or middle-click outside it.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to.\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useAnchoredPlacement({\n side: requestedSide,\n align,\n fallbacks: submenu ? \"flip-inline\" : undefined,\n });\n const { side, align: resolvedAlign, ref: placementRef } = placement;\n\n const nativeFocusgroup = useNativeFocusgroup(experimental_focusgroup);\n const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);\n\n const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so.\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n // The outside right- / middle-click listeners and the foreign invoker press guard of a\n // top-level menu.\n whileShown: submenu\n ? undefined\n : (element) => {\n const stopListening = listenOutside(element, menu, () => latestPlacement.current);\n const stopPresses = listenInvokerPresses(element);\n return () => {\n stopListening();\n stopPresses();\n };\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused.\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (isPopoverOpen(element)) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"DIALOG\"\n ? \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\"\n : null),\n );\n const pressRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it.\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n },\n [checkElement],\n );\n const ref = useMergedRefs(setElement, pressRef, placementRef);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...placement.dataAttributes,\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => (\n <MenuListContext value={listContext}>\n {pointRules}\n {renderContent(() => resolveStateValue(children, s))}\n </MenuListContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAiHvC,MAAM,qBACJ;;;;;;;;;;;;;;;;;;;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EAExB,UAAU;EACV,GAAI,2BAA2B,EAAE,YAAY,QAAQ,OAAO,SAAS,WAAW;EAChF;EACA;EACA;EAGA,gBAAgB,UAAmC;GACjD,MAAM,eAAe;EACvB;EACA,GAAI,WAAW;GACb,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,KAAK,OAAO,YAAY;GAC7D;GACA,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,mBAAmB,MAAM,MAAM,WAAW;GAC/E;EACF;EACA,GAAG,UAAU;EACb,gBAAgB,UAAU,OAAO,KAAK,KAAA;CACxC;CAKA,MAAM,aACJ,UAAU,QAAQ,eAAe,OAC/B,oBAAC,SAAD;EAAO,MAAM;EAAiB,YAAY;EAAiB,OAAO,KAAK;EACpE,UAAA;CACI,CAAA,IACL;CAEN,MAAM,WAAW,MACf,qBAAC,iBAAD;EAAiB,OAAO;EAAxB,UAAA,CACG,YACA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC,CACpC;;CAGnB,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,UAAU,MAAM,KAAK;EAC3B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
1
+ {"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { listenInvokerPresses } from \"../internal/invokers.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { capturePointer } from \"../internal/pointer-capture.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport { edgeItem } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport { listenOutside } from \"./menu-outside.js\";\nimport { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from \"./menu-point.js\";\nimport { useMenuKeyboard } from \"./use-menu-keyboard.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type MenuSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type MenuAlign = AnchorAlign;\n\n/**\n * State of `Menu.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Popup`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. A submenu's `\"inline-end\"` is the right of the item in LTR,\n * its left in RTL; its fallback is `flip-inline` only. `\"left\"` / `\"right\"` stay physical.\n * `null` emits no inline positioning (and no `data-side` / `data-align`): the stylesheet owns\n * placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n *\n * @defaultValue `\"bottom\"` for a top-level menu, `\"inline-end\"` for a submenu\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side: inline-relative on a top / bottom side (mirrored under\n * `direction: rtl`), the top edges on the others. Ignored when `side` is `null`.\n *\n * @defaultValue `\"start\"` (both levels)\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines.\n *\n * @defaultValue `false`\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n * While a view transition runs, the popup's CSS transitions are turned off for the moment of the\n * library's own show or hide (an inline `transition: none !important`, restored right after),\n * so that show or hide runs no CSS transition (a `@keyframes` animation is not cut).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);\n * a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no\n * focus, so that button's click closes the menu as `\"activate\"`.\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`.\n * Such an open is placed at the pointer: `--menu-point-x` / `--menu-point-y` inline and, unless\n * `side` is `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules it renders as a hoisted `<style>`. A top-level menu\n * closes at once on a right- or middle-click outside it.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to.\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useAnchoredPlacement({\n side: requestedSide,\n align,\n fallbacks: submenu ? \"flip-inline\" : undefined,\n });\n const { side, align: resolvedAlign, ref: placementRef } = placement;\n\n const nativeFocusgroup = useNativeFocusgroup(experimental_focusgroup);\n const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);\n\n const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so.\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n // The outside right- / middle-click listeners and the foreign invoker press guard of a\n // top-level menu.\n whileShown: submenu\n ? undefined\n : (element) => {\n const stopListening = listenOutside(element, menu, () => latestPlacement.current);\n const stopPresses = listenInvokerPresses(element);\n return () => {\n stopListening();\n stopPresses();\n };\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused.\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (isPopoverOpen(element)) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"DIALOG\"\n ? \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\"\n : null),\n );\n const pressRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it.\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n },\n [checkElement],\n );\n const ref = useMergedRefs(setElement, pressRef, placementRef);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...placement.dataAttributes,\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => (\n <MenuListContext value={listContext}>\n {pointRules}\n {renderContent(() => resolveStateValue(children, s))}\n </MenuListContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAoHvC,MAAM,qBACJ;;;;;;;;;;;;;;;;;;;;;;;;;AA0BF,SAAgB,UAAU,EACxB,MAAM,UACN,QAAQ,SACR,aACA,0BAA0B,OAC1B,YACA,WACA,OACA,UACA,QACA,GAAG,QACc;CACjB,MAAM,OAAO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;EACA,GAAI,WAAW;GACb,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,KAAK,OAAO,YAAY;GAC7D;GACA,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,mBAAmB,MAAM,MAAM,WAAW;GAC/E;EACF;EACA,GAAG,UAAU;EACb,gBAAgB,UAAU,OAAO,KAAK,KAAA;CACxC;CAKA,MAAM,aACJ,UAAU,QAAQ,eAAe,OAC/B,oBAAC,SAAD;EAAO,MAAM;EAAiB,YAAY;EAAiB,OAAO,KAAK;EACpE,UAAA;CACI,CAAA,IACL;CAEN,MAAM,WAAW,MACf,qBAAC,iBAAD;EAAiB,OAAO;EAAxB,UAAA,CACG,YACA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC,CACpC;;CAGnB,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,UAAU,MAAM,KAAK;EAC3B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
@@ -1,7 +1,7 @@
1
- import { ActionDetails, ChangeAction, ChangeReason, StateValue } from "../internal/types.mjs";
1
+ import { ActionDetails, ChangeAction, ChangeReason, StateValue, UrgentChangeHandler } from "../internal/types.mjs";
2
2
  import { ReactNode } from "react";
3
3
  //#region src/menu/menu-root.d.ts
4
- /** Details passed as the second argument of `Menu.Root`'s `openChangeAction`. */
4
+ /** Details passed as the second argument of `Menu.Root`'s `openChangeAction` and `onOpenChange`. */
5
5
  export interface MenuOpenChangeDetails extends ActionDetails {
6
6
  /**
7
7
  * `"activate"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,
@@ -34,18 +34,33 @@ export interface MenuRootState {
34
34
  * @see https://ui.funstack.work/components/menu
35
35
  */
36
36
  export interface MenuRootProps {
37
- /** Controlled open state. `undefined` means uncontrolled. */
37
+ /**
38
+ * Controlled open state. `undefined` means uncontrolled. A controlled Root needs
39
+ * `onOpenChange` too: the browser closes the menu without asking (development warns).
40
+ */
38
41
  open?: boolean;
39
42
  /** Initial open state when uncontrolled. Opens after hydration. */
40
43
  defaultOpen?: boolean;
41
44
  /**
42
- * Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the
43
- * closes the user asks a part for (Trigger toggle, an item's activation, ArrowLeft in a
44
- * submenu); a notification for dismissals (Escape, a click outside, Tab, the parent menu
45
- * closing). May be a Server Function. A `setState` placed after your own `await` needs
46
- * `startTransition` (React limitation).
45
+ * Requests only. Awaited for `true` (the menu opens when it resolves and the items have
46
+ * rendered) and for the closes the user asks a part for (Trigger toggle, an item's activation,
47
+ * ArrowLeft in a submenu, the pointer leaving a hover-opened submenu). Never called for a
48
+ * dismissal: that goes to `onOpenChange`. May be a Server Function. A `setState` placed after
49
+ * your own `await` needs `startTransition` (React limitation).
47
50
  */
48
51
  openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;
52
+ /**
53
+ * Facts only: the menu was closed without the library closing it on request (Escape, a click
54
+ * outside, Tab or focus leaving the menu, a right-click outside, a scroll under a context
55
+ * menu, the parent menu closing a submenu, a foreign invoker, script). Always `false`. Called
56
+ * synchronously in the platform's `toggle` event, outside any Transition, and not awaited:
57
+ * nothing is pending and no view transition runs.
58
+ *
59
+ * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in
60
+ * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the menu
61
+ * re-opened at once. May return a promise; a rejection or a throw goes to `reportError`.
62
+ */
63
+ onOpenChange?: UrgentChangeHandler<boolean, MenuOpenChangeDetails>;
49
64
  /**
50
65
  * Arrow keys wrap from the last item to the first and back.
51
66
  *
@@ -74,13 +89,13 @@ export interface MenuRootProps {
74
89
  * item of the parent menu) and its Popup opens beside that item.
75
90
  *
76
91
  * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a
77
- * part asks for are transitions (pending Trigger, items render from committed state,
78
- * `showPopover()` / `hidePopover()` once the change has committed); dismissals are the
79
- * browser's and `openChangeAction(false)` is a notification.
92
+ * part asks for are requests, transitions through `openChangeAction` (pending Trigger, items
93
+ * render from committed state, `showPopover()` / `hidePopover()` once the change has committed);
94
+ * dismissals are the browser's facts, reported to `onOpenChange`.
80
95
  *
81
96
  * @see https://ui.funstack.work/components/menu
82
97
  */
83
- export declare function MenuRoot({ open, defaultOpen, openChangeAction, loop, delay, closeDelay, children }: MenuRootProps): import("react").JSX.Element;
98
+ export declare function MenuRoot({ open, defaultOpen, openChangeAction, onOpenChange, loop, delay, closeDelay, children }: MenuRootProps): import("react").JSX.Element;
84
99
  export declare namespace MenuRoot {
85
100
  var displayName: string;
86
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"menu-root.d.mts","names":[],"sources":["../../src/menu/menu-root.tsx"],"mappings":";;;;iBAyBiB,8BAA8B;;;;;;;;;;WAUpC,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;;;;WAKA;;;;;;;iBAQM;;EAEf;;EAEA;;;;;;;;EAQA,mBAAmB,sBAAsB;;;;;;EAMzC;;;;;;EAMA;;;;;;;EAOA;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;;;wBAiBnB,WACd,MACA,aACA,kBACA,MACA,OACA,YACA,YACC,gCAAa,IAAA;yBARA"}
1
+ {"version":3,"file":"menu-root.d.mts","names":[],"sources":["../../src/menu/menu-root.tsx"],"mappings":";;;;iBA+BiB,8BAA8B;;;;;;;;;;WAUpC,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;;;;WAKA;;;;;;;iBAQM;;;;;EAKf;;EAEA;;;;;;;;EAQA,mBAAmB,sBAAsB;;;;;;;;;;;;EAYzC,eAAe,6BAA6B;;;;;;EAM5C;;;;;;EAMA;;;;;;;EAOA;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;;;wBAiBnB,WACd,MACA,aACA,kBACA,cACA,MACA,OACA,YACA,YACC,gCAAa,IAAA;yBATA"}
@@ -19,13 +19,13 @@ const DEFAULT_FOCUS = {
19
19
  * item of the parent menu) and its Popup opens beside that item.
20
20
  *
21
21
  * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a
22
- * part asks for are transitions (pending Trigger, items render from committed state,
23
- * `showPopover()` / `hidePopover()` once the change has committed); dismissals are the
24
- * browser's and `openChangeAction(false)` is a notification.
22
+ * part asks for are requests, transitions through `openChangeAction` (pending Trigger, items
23
+ * render from committed state, `showPopover()` / `hidePopover()` once the change has committed);
24
+ * dismissals are the browser's facts, reported to `onOpenChange`.
25
25
  *
26
26
  * @see https://ui.funstack.work/components/menu
27
27
  */
28
- function MenuRoot({ open, defaultOpen, openChangeAction, loop = true, delay, closeDelay, children }) {
28
+ function MenuRoot({ open, defaultOpen, openChangeAction, onOpenChange, loop = true, delay, closeDelay, children }) {
29
29
  const parent = use(MenuContext);
30
30
  const list = use(MenuListContext);
31
31
  const parentMenu = list !== null ? list.menu : null;
@@ -46,6 +46,7 @@ function MenuRoot({ open, defaultOpen, openChangeAction, loop = true, delay, clo
46
46
  open,
47
47
  defaultOpen,
48
48
  openChangeAction,
49
+ onOpenChange,
49
50
  details: popoverDetails,
50
51
  onDispatch: (next) => {
51
52
  timers.cancel();
@@ -1 +1 @@
1
- {"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { ActionDetails, ChangeAction, ChangeReason, StateValue } from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { popoverDetails, useOverlayRoot } from \"../internal/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport {\n ANCHOR_PLACEMENT,\n MenuContext,\n MenuListContext,\n MenuRegionContext,\n} from \"./menu-context.js\";\nimport type {\n MenuContextValue,\n MenuOpenAtOptions,\n MenuOpenFocus,\n MenuPlacement,\n} from \"./menu-context.js\";\nimport { isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\n/** State of `Menu.Root`, passed to the function forms of `children`. */\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n /**\n * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the\n * pointer rather than against the Trigger.\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Root`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuRootProps {\n /** Controlled open state. `undefined` means uncontrolled. */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the\n * closes the user asks a part for (Trigger toggle, an item's activation, ArrowLeft in a\n * submenu); a notification for dismissals (Escape, a click outside, Tab, the parent menu\n * closing). May be a Server Function. A `setState` placed after your own `await` needs\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /**\n * Arrow keys wrap from the last item to the first and back.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Submenu only: milliseconds from hovering the SubmenuTrigger to the open.\n *\n * @defaultValue `100`\n */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close.\n *\n * @defaultValue `150`\n */\n closeDelay?: number;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are transitions (pending Trigger, items render from committed state,\n * `showPopover()` / `hidePopover()` once the change has committed); dismissals are the\n * browser's and `openChangeAction(false)` is a notification.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n isDev &&\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n const inRegion = use(MenuRegionContext);\n useDevWarning(\n parent !== null && !submenu && !inRegion,\n isDev &&\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n // Placement of the current open (context-menu.md 3.1). Written urgently, not in a transition:\n // while closed it renders nothing visible, and a move of an open menu (4.3) answers the\n // right-click at once, where a transition would be entangled with any pending async action\n // (an item's, the open's) and the menu would stay at the old point until it settled.\n const [placement, setPlacement] = useState<MenuPlacement>(ANCHOR_PLACEMENT);\n const placementGeneration = useRef(0);\n // Set by `openAt` around its `requestOpen`: the dispatch is a point open.\n const pointDispatch = useRef(false);\n\n const popover = useOverlayRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n details: popoverDetails,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (design walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n // Every other open (Trigger, foreign invoker, mount reconciliation) is anchored.\n if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);\n },\n });\n\n const { intended, requestOpen, popupRef } = popover;\n const openAt = useCallback(\n (point: { readonly x: number; readonly y: number }, options: MenuOpenAtOptions) => {\n const generation = ++placementGeneration.current;\n // The popup's direction picks the edge at the point (context-menu.md 4.6, conventions\n // 13.4): the popup element exists while closed and `direction` is inherited, so it\n // computes without a box. Stored, so the Popup's style stays a function of state.\n const popup = popupRef.current;\n setPlacement({\n kind: \"point\",\n x: point.x,\n y: point.y,\n generation,\n source: options.source,\n pointerId: options.pointerId,\n direction: popup !== null && isRtl(popup) ? \"rtl\" : \"ltr\",\n // A touch or pen open is placed above the finger (4.7); re-evaluated on every move.\n offset: options.offset,\n });\n const focus: MenuOpenFocus = { cause: \"first\", pointer: options.pointer };\n if (intended()) {\n // A move, or a right-click while the open is still pending: no dispatch. The re-show\n // (or the open being shown) focuses the first item by this event's modality.\n openCause.current = focus;\n return;\n }\n nextCause.current = focus;\n pointDispatch.current = true;\n try {\n requestOpen(options.event, \"activate\");\n } finally {\n pointDispatch.current = false;\n }\n },\n [intended, requestOpen, popupRef],\n );\n const resetPlacement = useCallback((generation: number) => {\n setPlacement((current) =>\n current.kind === \"point\" && current.generation === generation ? ANCHOR_PLACEMENT : current,\n );\n }, []);\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // `popover` is memoised by `useOverlayRoot` and the other members are stable, so this\n // changes only with the open state, pending and the props listed below.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n context: popover.optimistic && placement.kind === \"point\",\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAwEvC,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;;;;;;;;;;;;;AActE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WA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,UAAU;GACR,cAAc,UAAU;EAC1B;CACF,GACA;EAAC;EAAU;EAAa;CAAQ,CAClC;CACA,MAAM,iBAAiB,aAAa,eAAuB;EACzD,cAAc,YACZ,QAAQ,SAAS,WAAW,QAAQ,eAAe,aAAa,mBAAmB,OACrF;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,eAAe,aAAa,OAA+B,UAAU,UAAU;EACnF,UAAU,UAAU;GAAE;GAAO;EAAQ;CACvC,GAAG,CAAC,CAAC;CACL,MAAM,gBAAgB,kBAAkB;EACtC,MAAM,QAAQ,UAAU,WAAW;EACnC,UAAU,UAAU;EACpB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,SAAS;CAC/B,MAAM,qBAAqB,cAAc;CAGzC,MAAM,QAAQ,cAAgC;EAC5C,MAAM,OAAyB;GAC7B;GACA;GAEA,IAAI,OAAO;IACT,OAAO,YAAY,QAAQ;GAC7B;GACA,QAAQ;GACR;GACA,OAAO;GACP,YAAY;GACZ,WAAW,GAAG,QAAQ,IAAI,MAAM;GAChC;GACA;GACA;GACA;GACA;GACA;EACF;EACA,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;EACA,SAAS,QAAQ,cAAc,UAAU,SAAS;CACpD;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
1
+ {"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { popoverDetails, useOverlayRoot } from \"../internal/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport {\n ANCHOR_PLACEMENT,\n MenuContext,\n MenuListContext,\n MenuRegionContext,\n} from \"./menu-context.js\";\nimport type {\n MenuContextValue,\n MenuOpenAtOptions,\n MenuOpenFocus,\n MenuPlacement,\n} from \"./menu-context.js\";\nimport { isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction` and `onOpenChange`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\n/** State of `Menu.Root`, passed to the function forms of `children`. */\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n /**\n * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the\n * pointer rather than against the Trigger.\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Root`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled. A controlled Root needs\n * `onOpenChange` too: the browser closes the menu without asking (development warns).\n */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the menu opens when it resolves and the items have\n * rendered) and for the closes the user asks a part for (Trigger toggle, an item's activation,\n * ArrowLeft in a submenu, the pointer leaving a hover-opened submenu). Never called for a\n * dismissal: that goes to `onOpenChange`. May be a Server Function. A `setState` placed after\n * your own `await` needs `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /**\n * Facts only: the menu was closed without the library closing it on request (Escape, a click\n * outside, Tab or focus leaving the menu, a right-click outside, a scroll under a context\n * menu, the parent menu closing a submenu, a foreign invoker, script). Always `false`. Called\n * synchronously in the platform's `toggle` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the menu\n * re-opened at once. May return a promise; a rejection or a throw goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, MenuOpenChangeDetails>;\n /**\n * Arrow keys wrap from the last item to the first and back.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Submenu only: milliseconds from hovering the SubmenuTrigger to the open.\n *\n * @defaultValue `100`\n */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close.\n *\n * @defaultValue `150`\n */\n closeDelay?: number;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are requests, transitions through `openChangeAction` (pending Trigger, items\n * render from committed state, `showPopover()` / `hidePopover()` once the change has committed);\n * dismissals are the browser's facts, reported to `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n isDev &&\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n const inRegion = use(MenuRegionContext);\n useDevWarning(\n parent !== null && !submenu && !inRegion,\n isDev &&\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n // Placement of the current open (context-menu.md 3.1). Written urgently, not in a transition:\n // while closed it renders nothing visible, and a move of an open menu (4.3) answers the\n // right-click at once, where a transition would be entangled with any pending async action\n // (an item's, the open's) and the menu would stay at the old point until it settled.\n const [placement, setPlacement] = useState<MenuPlacement>(ANCHOR_PLACEMENT);\n const placementGeneration = useRef(0);\n // Set by `openAt` around its `requestOpen`: the dispatch is a point open.\n const pointDispatch = useRef(false);\n\n const popover = useOverlayRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: popoverDetails,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (design walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n // Every other open (Trigger, foreign invoker, mount reconciliation) is anchored.\n if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);\n },\n });\n\n const { intended, requestOpen, popupRef } = popover;\n const openAt = useCallback(\n (point: { readonly x: number; readonly y: number }, options: MenuOpenAtOptions) => {\n const generation = ++placementGeneration.current;\n // The popup's direction picks the edge at the point (context-menu.md 4.6, conventions\n // 13.4): the popup element exists while closed and `direction` is inherited, so it\n // computes without a box. Stored, so the Popup's style stays a function of state.\n const popup = popupRef.current;\n setPlacement({\n kind: \"point\",\n x: point.x,\n y: point.y,\n generation,\n source: options.source,\n pointerId: options.pointerId,\n direction: popup !== null && isRtl(popup) ? \"rtl\" : \"ltr\",\n // A touch or pen open is placed above the finger (4.7); re-evaluated on every move.\n offset: options.offset,\n });\n const focus: MenuOpenFocus = { cause: \"first\", pointer: options.pointer };\n if (intended()) {\n // A move, or a right-click while the open is still pending: no dispatch. The re-show\n // (or the open being shown) focuses the first item by this event's modality.\n openCause.current = focus;\n return;\n }\n nextCause.current = focus;\n pointDispatch.current = true;\n try {\n requestOpen(options.event, \"activate\");\n } finally {\n pointDispatch.current = false;\n }\n },\n [intended, requestOpen, popupRef],\n );\n const resetPlacement = useCallback((generation: number) => {\n setPlacement((current) =>\n current.kind === \"point\" && current.generation === generation ? ANCHOR_PLACEMENT : current,\n );\n }, []);\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // `popover` is memoised by `useOverlayRoot` and the other members are stable, so this\n // changes only with the open state, pending and the props listed below.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n context: popover.optimistic && placement.kind === \"point\",\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuFvC,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;;;;;;;;;;;;;AActE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,cACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,OAAO,IAAI,eAAe;CAEhC,MAAM,aAAa,SAAS,OAAO,KAAK,OAAO;CAC/C,MAAM,UAAU,eAAe;CAE/B,cACE,CAAC,YAAY,UAAU,KAAA,KAAa,eAAe,KAAA,IACnD,SACE,yIAEJ;CACA,MAAM,WAAW,IAAI,iBAAiB;CACtC,cACE,WAAW,QAAQ,CAAC,WAAW,CAAC,UAChC,SACE,gIAEJ;CAEA,MAAM,SAAS,eAAe;CAG9B,MAAM,YAAY,OAA6B,IAAI;CACnD,MAAM,YAAY,OAA6B,IAAI;CAMnD,MAAM,CAAC,WAAW,gBAAgB,SAAwB,gBAAgB;CAC1E,MAAM,sBAAsB,OAAO,CAAC;CAEpC,MAAM,gBAAgB,OAAO,KAAK;CAElC,MAAM,UAAU,eAAsC;EACpD,WAAW;EACX,MAAM;EACN,MAAM;EACN;EACA;EACA;EACA;EACA,SAAS;EACT,aAAa,SAAS;GAEpB,OAAO,OAAO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R;GACA,OAAO;GACP,YAAY;GACZ,WAAW,GAAG,QAAQ,IAAI,MAAM;GAChC;GACA;GACA;GACA;GACA;GACA;EACF;EACA,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;EACA,SAAS,QAAQ,cAAc,UAAU,SAAS;CACpD;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"number-field-root.d.mts","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"mappings":";;;;;iBA+CiB,sCAAsC;;;;;;;;;WAS5C,QAAQ;;WAER,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,6BAA6B,KAC5C;;EAIA;;;;;;EAMA;;;;;;;EAOA,oBAAoB,4BAA4B;;;;;;;EAOhD,oBAAoB,4BAA4B;;EAEhD;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA,SAAS,KAAK;;;;;;;EAOd;;;;;;EAMA;;;;;;EAMA;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;EAOA,YAAY,sBAAsB,OAAO;;EAEzC,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBA2DpC,gBAAgB,OAAO,uCAAoB,IAAA;yBAA3C"}
1
+ {"version":3,"file":"number-field-root.d.mts","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"mappings":";;;;;iBA8CiB,sCAAsC;;;;;;;;;WAS5C,QAAQ;;WAER,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,6BAA6B,KAC5C;;EAIA;;;;;;EAMA;;;;;;;EAOA,oBAAoB,4BAA4B;;;;;;;EAOhD,oBAAoB,4BAA4B;;EAEhD;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA,SAAS,KAAK;;;;;;;EAOd;;;;;;EAMA;;;;;;EAMA;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;EAOA,YAAY,sBAAsB,OAAO;;EAEzC,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBA2DpC,gBAAgB,OAAO,uCAAoB,IAAA;yBAA3C"}
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { createActionDetails } from "../internal/action-details.mjs";
3
3
  import { dataAttr } from "../internal/data-attr.mjs";
4
- import { useSupersededRejection } from "../internal/use-superseded-rejection.mjs";
5
4
  import { useActionTrigger } from "../internal/use-action-trigger.mjs";
6
5
  import { mergeTokenLists } from "../internal/merge-props.mjs";
7
6
  import { useRender } from "../internal/use-render.mjs";
@@ -134,11 +133,7 @@ function NumberFieldRoot(props) {
134
133
  const message = hidden.validationMessage;
135
134
  if (visible.validationMessage !== message) visible.setCustomValidity(message);
136
135
  }, []);
137
- const captureSuperseded = useSupersededRejection();
138
- const { pending: stepPending, run: runStep } = useActionTrigger({
139
- ignoreWhilePending: false,
140
- captureSuperseded
141
- });
136
+ const { pending: stepPending, run: runStep } = useActionTrigger({ ignoreWhilePending: false });
142
137
  const runCommit = async (next, details) => {
143
138
  const seq = ++commitSeq.current;
144
139
  try {
@@ -160,8 +155,7 @@ function NumberFieldRoot(props) {
160
155
  warn: {
161
156
  component: "NumberField.Root",
162
157
  prop: "value"
163
- },
164
- captureSuperseded
158
+ }
165
159
  });
166
160
  const { optimistic, committed, dispatch } = commitState;
167
161
  const committedRef = useLatest(committed);
@@ -1 +1 @@
1
- {"version":3,"file":"number-field-root.mjs","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n use,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, RefObject } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { announce as speak } from \"../internal/announce.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FieldContext } from \"../internal/field-context.js\";\nimport { mergeTokenLists } from \"../internal/merge-props.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { resolveFieldDefaults, useFieldValueChange } from \"../internal/use-field-control.js\";\nimport type { FormAssociatedElement } from \"../internal/use-form-owner-event.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeGroupReconciliation } from \"../internal/use-native-group-reconciliation.js\";\nimport { useSupersededRejection } from \"../internal/use-superseded-rejection.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { keyStep, stepValue } from \"./number-field-arithmetic.js\";\nimport type { StepBounds } from \"./number-field-arithmetic.js\";\nimport { NumberFieldContext } from \"./number-field-context.js\";\nimport type {\n NumberFieldContextValue,\n NumberFieldSource,\n StepDirection,\n} from \"./number-field-context.js\";\nimport { createNumberFormatter, formatKey } from \"./number-field-format.js\";\nimport type { NumberFormatter } from \"./number-field-format.js\";\nimport { useNumberFieldDevWarnings } from \"./use-number-field-dev-warnings.js\";\n\n/** Details passed as the second argument of both NumberField actions. */\nexport interface NumberFieldValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user typed, pressed a key, a button or turned the wheel (`details.event` is\n * the `focusout` / Enter `keydown` of a typed value, the `keydown` of a key, the `pointerdown` /\n * `pointerup` of a button (`undefined` for the repeats of a held button and for a hold that\n * ended at its bound), the `wheel` event). `\"platform\"`: a form reset (the `reset`\n * event) or text typed before hydration (`undefined`). `\"dismiss\"`: the commit action rejected\n * and the field reverted to the committed value (uncontrolled; `valueChangeAction` only).\n */\n readonly reason: ChangeReason;\n /** What produced the value: typed text, a button, a key, the wheel; `null` for \"platform\" and \"dismiss\". */\n readonly source: NumberFieldSource;\n}\n\n/** The state every NumberField part's function props receive (one object, Field's precedent). */\nexport interface NumberFieldState {\n /** The shown value: the gesture's value while one is open or in flight, else the optimistic value; `null` when empty. */\n readonly value: number | null;\n /** The shown text: the draft while the user is editing, else `value` formatted. */\n readonly text: string;\n /** A step or commit dispatched through this NumberField is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop, or the enclosing Field's. */\n readonly disabled: boolean;\n /** The `readOnly` prop. */\n readonly readOnly: boolean;\n /** The `required` prop, or the enclosing Field's. */\n readonly required: boolean;\n}\n\n/**\n * Props of `NumberField.Root`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport interface NumberFieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"defaultValue\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` is empty, `undefined` uncontrolled. */\n value?: number | null;\n /**\n * Initial value in uncontrolled mode, and its form-reset target (latest).\n *\n * @defaultValue `null` (empty)\n */\n defaultValue?: number | null;\n /**\n * Runs inside the Root's step transition on every step: the parse of typed text at commit,\n * each key press, each tick of a hold, each wheel event, each platform change, and the revert\n * after a rejected commit (`reason: \"dismiss\"`, uncontrolled). Keep it cheap: adopt the value\n * (`setValue(next)` in the sync prefix is a transition update), start a deferred render.\n */\n valueChangeAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /**\n * Runs inside the Root's commit transition once per gesture: a typed text's blur or Enter, a\n * hold's release, each key press, each wheel event, a form reset, text typed before hydration.\n * Where the save goes; uncontrolled state is committed when it resolves and reverts when it\n * rejects. May be a Server Function.\n */\n valueCommitAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /** Native `min` on the hidden input (a constraint) and the lower bound of stepping. */\n min?: number;\n /** Native `max` on the hidden input (a constraint) and the upper bound of stepping. */\n max?: number;\n /**\n * Native `step` and the stepping grid from `min` (else `0`).\n *\n * @defaultValue `1`, or `0.01` when `format.style` is `\"percent\"`\n */\n step?: number;\n /**\n * The step of PageUp / PageDown and Shift+Arrow.\n *\n * @defaultValue `10 × step`\n */\n largeStep?: number;\n /**\n * `Intl.NumberFormatOptions` for the text: `style` `\"decimal\"` (default), `\"percent\"`,\n * `\"currency\"` (with `currency`), `\"unit\"` (with `unit`); fraction digits, grouping, sign\n * display. `notation: \"compact\"` is a dev warning (unparsable).\n */\n format?: Intl.NumberFormatOptions;\n /**\n * BCP 47 tag(s). Pass the page's `lang`; a dev warning fires when\n * `document.documentElement.lang` disagrees and this prop is absent.\n *\n * @defaultValue the runtime's locale (`Intl.NumberFormat().resolvedOptions().locale`)\n */\n locale?: string | readonly string[];\n /**\n * Step with the mouse wheel while the input is focused.\n *\n * @defaultValue `false`\n */\n stepOnWheel?: boolean;\n /**\n * Native `name` on the hidden input.\n *\n * @defaultValue the Field's `name` inside a `Field.Root`\n */\n name?: string;\n /** Native `form` on the hidden input. */\n form?: string;\n /**\n * Disables both inputs and the buttons; inherited by every part.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Native `readonly` on both inputs; no stepping (buttons disabled, keys and wheel inert).\n *\n * @defaultValue `false`\n */\n readOnly?: boolean;\n /**\n * Native `required` on the hidden input (empty is `valueMissing`); or the Field's.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /**\n * What is announced (`ariaNotify()`) after a key press, a wheel event, a click activation and a\n * hold's release. Return `null` to announce nothing.\n *\n * @defaultValue `(_, state) => state.text`\n */\n announce?: (value: number | null, state: NumberFieldState) => string | null;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NumberFieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NumberFieldState>;\n /** The parts. The function form receives the state. */\n children?: StateValue<ReactNode, NumberFieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, NumberFieldState>;\n}\n\nconst STEP_TYPES = transitionTypes(\"number-field\", \"change\");\nconst COMMIT_TYPES = transitionTypes(\"number-field\", \"commit\");\n\n/** A finite number, or `null` (`NaN` / `Infinity` are treated as empty). */\nfunction sanitize(value: number | null | undefined): number | null | undefined {\n if (value === undefined || value === null) return value;\n return Number.isFinite(value) ? value : null;\n}\n\n/** The hidden input's value for `value`. */\nfunction hiddenText(value: number | null): string {\n return value === null ? \"\" : String(value);\n}\n\n/**\n * Mount reconciliation's read of the visible input (design 4.5): the value the hydrated text\n * means. The client's own formatting of `current` is `current`. Focused text is still being typed\n * (even a partial `12,` or `-`): handed to `adoptDraft`, never overwritten under the caret; the\n * blur commits or reverts it by the ordinary rule. Otherwise the parsed text, or, for another\n * locale's formatting of the same value or text that is no number, `current` with the client's\n * text written back (react-dom kept the hydrated DOM value).\n */\nfunction readVisible(\n visible: HTMLInputElement | null,\n current: number | null,\n formatter: NumberFormatter,\n adoptDraft: (text: string) => void,\n): number | null {\n if (visible === null) return current;\n const domText = visible.value;\n if (domText === formatter.format(current)) return current;\n if (visible.ownerDocument.activeElement === visible) {\n adoptDraft(domText);\n return current;\n }\n const parsed = formatter.parse(domText);\n if (parsed === undefined || Object.is(parsed, current)) {\n visible.value = formatter.format(current);\n return current;\n }\n return parsed;\n}\n\n/**\n * Owns the number field's state (design/components/number-field.md 2): the committed value\n * through `useControllableAction` with `valueCommitAction` (once per gesture), each step through\n * its own transition (`valueChangeAction`), the urgent draft text, the urgent value of the open\n * gesture (`live`), the press-and-hold, the formatter and parser, the announcements, mount\n * reconciliation and form reset (through the hidden input the Input renders).\n *\n * Owned keys (conventions 1.2): `role=\"group\"`, `aria-labelledby` (token-merged: the consumer's,\n * then `NumberField.Label`'s id while one is mounted, then a Field's label id), `data-pending`,\n * `data-disabled`, `data-invalid` (inside a Field).\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport function NumberFieldRoot(props: NumberFieldRootProps) {\n const {\n value: valueProp,\n defaultValue: defaultValueProp,\n valueChangeAction,\n valueCommitAction,\n min,\n max,\n step: stepProp,\n largeStep: largeStepProp,\n format,\n locale,\n stepOnWheel = false,\n name: nameProp,\n form,\n disabled: disabledProp = false,\n readOnly = false,\n required: requiredProp = false,\n announce,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const value = sanitize(valueProp);\n const defaultValue = sanitize(defaultValueProp);\n\n // --- Format, bounds -----------------------------------------------------------------------\n\n const key = formatKey(format);\n const localeKey = locale === undefined ? \"\" : JSON.stringify(locale);\n // Memoised on the content of `format` and `locale`, not their identity (an inline object).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const formatter = useMemo(() => createNumberFormatter(locale, format), [localeKey, key]);\n const defaultStep = formatter.percent ? 0.01 : 1;\n const stepValid = stepProp === undefined || (Number.isFinite(stepProp) && stepProp > 0);\n const stepSize = stepProp !== undefined && stepValid ? stepProp : defaultStep;\n const largeStepValid =\n largeStepProp === undefined || (Number.isFinite(largeStepProp) && largeStepProp > 0);\n const largeStep = largeStepProp !== undefined && largeStepValid ? largeStepProp : 10 * stepSize;\n const bounds = useMemo<StepBounds>(\n () => ({\n min: Number.isFinite(min) ? min : undefined,\n max: Number.isFinite(max) ? max : undefined,\n step: stepSize,\n }),\n [min, max, stepSize],\n );\n\n // --- Field ----------------------------------------------------------------------------------\n\n // NumberField.Input registers the control (design 7.1); the Root only resolves the defaults.\n const fieldContext = use(FieldContext);\n const { disabled, required, name } = resolveFieldDefaults(fieldContext, {\n name: nameProp,\n disabled: disabledProp,\n required: requiredProp,\n });\n const fieldInvalid = fieldContext === null ? undefined : fieldContext.state.invalid;\n\n const id = useId();\n const inputId = fieldContext?.ids.control ?? `${id}-input`;\n const labelId = `${id}-label`;\n\n // --- State (design 2) -----------------------------------------------------------------------\n\n const [draft, setDraft] = useState<string | null>(null);\n const draftRef = useRef<string | null>(null);\n /** The value the open gesture has reached (`null` inside: an empty value). */\n const [live, setLive] = useState<{ readonly value: number | null } | null>(null);\n const [hold, setHold] = useState<StepDirection | null>(null);\n const [stepHeld, setStepHeld] = useState(false);\n const [pendingSource, setPendingSource] = useState<NumberFieldSource>(null);\n\n const liveRef = useRef<number | null>(null);\n /** The shown value when the open gesture began; `null` when no gesture is open. */\n const gestureStart = useRef<{ readonly value: number | null } | null>(null);\n /** The value the next tick of a hold steps from. */\n const holdBase = useRef<number | null>(null);\n const holdRef = useRef<StepDirection | null>(null);\n const commitSeq = useRef(0);\n const lastReason = useRef<ChangeReason | null>(null);\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const hiddenRef = useRef<HTMLInputElement | null>(null);\n\n const clearDraft = useCallback(() => {\n if (draftRef.current === null) return;\n draftRef.current = null;\n setDraft(null);\n }, []);\n\n /**\n * Writes `next` into the hidden input, then mirrors its validity onto the visible input, which\n * is invalid exactly when the hidden one is (6.2).\n */\n const syncHidden = useCallback((next: number | null) => {\n const hidden = hiddenRef.current;\n if (hidden !== null) {\n const text = hiddenText(next);\n if (hidden.value !== text) hidden.value = text;\n }\n const visible = visibleRef.current;\n if (hidden === null || visible === null) return;\n const message = hidden.validationMessage;\n if (visible.validationMessage !== message) visible.setCustomValidity(message);\n }, []);\n\n // One capture for both channels, before both transitions (see `captureSuperseded`).\n const captureSuperseded = useSupersededRejection();\n\n // A step is not a re-entry: a continuous control dispatches one step per key press or pointer\n // move and every step must run (design/components/button.md 16.1), so no in-flight guard.\n const { pending: stepPending, run: runStep } = useActionTrigger({\n ignoreWhilePending: false,\n captureSuperseded,\n });\n\n const runCommit = async (\n next: number | null,\n details: NumberFieldValueChangeDetails,\n ): Promise<void> => {\n const seq = ++commitSeq.current;\n try {\n await valueCommitAction?.(next, details);\n } catch (error) {\n // Design 2.4: in uncontrolled mode, tell the preview channel about the rollback, for the\n // latest commit only. Yield once to leave the commit's transition (conventions 2.6).\n if (valueProp === undefined && seq === commitSeq.current) {\n await undefined;\n // `step` and `committedRef` are declared below; this runs long after the render.\n step(committedRef.current, null, \"dismiss\", undefined);\n }\n throw error;\n }\n };\n\n const commitState = useControllableAction<number | null, NumberFieldValueChangeDetails>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: runCommit,\n transitionTypes: () => COMMIT_TYPES,\n warn: { component: \"NumberField.Root\", prop: \"value\" },\n captureSuperseded,\n });\n const { optimistic, committed, dispatch } = commitState;\n const committedRef = useLatest(committed);\n\n const held = hold !== null || stepHeld || stepPending || commitState.pending;\n const shown = held && live !== null ? live.value : optimistic;\n const pending = stepPending || commitState.pending;\n const text = draft ?? formatter.format(shown);\n // The value a button press steps from (4.3 step 3): the parsed draft while one is open.\n const parsedDraft = draft === null ? undefined : formatter.parse(draft);\n const stepBase = parsedDraft === undefined ? shown : parsedDraft;\n /** What the input shows, for handlers; also written by `step` ahead of the render. */\n const shownRef = useLatest(shown);\n\n const state = useMemo<NumberFieldState>(\n () => ({ value: shown, text, pending, disabled, readOnly, required }),\n [shown, text, pending, disabled, readOnly, required],\n );\n\n // A step, a key and a typed commit fire no `input` / `change` on the element the Field hears\n // for the value (the hidden input is written by script): tell it at the commit (design 7.2).\n useFieldValueChange(optimistic, () => {\n const edit = lastReason.current === \"activate\";\n lastReason.current = null;\n return edit;\n });\n\n const latest = useLatest({\n valueChangeAction,\n runStep,\n formatter,\n bounds,\n largeStep,\n disabled,\n readOnly,\n announce,\n state,\n });\n\n // --- Step and commit (design 2.4) -----------------------------------------------------------\n\n const step = useCallback(\n (\n next: number | null,\n source: NumberFieldSource,\n reason: ChangeReason,\n event: Event | undefined,\n ): boolean => {\n // What the text can show is what the form posts (5.4): a step finer than the format's\n // digits is rounded like a typed value.\n const { formatter: f } = latest.current;\n if (next !== null) next = f.round(next);\n // No-op against what the user sees (conventions 2.3 item 8).\n if (Object.is(next, shownRef.current)) return false;\n liveRef.current = next;\n shownRef.current = next;\n lastReason.current = reason;\n setLive({ value: next });\n clearDraft();\n setPendingSource(source);\n syncHidden(next);\n // A revert has no commit after it: the optimistic value already shows the committed one.\n if (reason !== \"dismiss\") setStepHeld(true);\n const { valueChangeAction: action, runStep: run } = latest.current;\n // Without a step action nothing runs and no transition starts (as Slider).\n if (action === undefined) return true;\n run(() => {\n for (const type of STEP_TYPES) addTransitionType(type);\n return action(next, createActionDetails(event, { reason, source }));\n });\n return true;\n },\n [clearDraft, latest, shownRef, syncHidden],\n );\n\n const announceValue = useCallback(\n (next: number | null) => {\n const visible = visibleRef.current;\n if (visible === null) return;\n const { announce: compose, formatter: f, state: s } = latest.current;\n const nextState: NumberFieldState = { ...s, value: next, text: f.format(next) };\n const message = compose === undefined ? nextState.text : compose(next, nextState);\n if (message !== null) speak(visible, message);\n },\n [latest],\n );\n\n const commit = useCallback(\n (source: NumberFieldSource, reason: ChangeReason, event: Event | undefined): boolean => {\n const start = gestureStart.current;\n gestureStart.current = null;\n // The commit's own pending state holds `live` from here (set in this same batch).\n setStepHeld(false);\n const next = liveRef.current;\n // Nothing changed since the gesture began (a hold that returned to its start).\n if (start === null || Object.is(next, start.value)) return false;\n lastReason.current = reason;\n setPendingSource(source);\n dispatch(next, createActionDetails(event, { reason, source }));\n if (reason === \"activate\" && source !== \"input\" && source !== null) announceValue(next);\n return true;\n },\n [announceValue, dispatch],\n );\n\n /** Opens a gesture at the shown value. */\n const openGesture = useCallback(() => {\n gestureStart.current = { value: shownRef.current };\n liveRef.current = shownRef.current;\n }, [shownRef]);\n\n /** The value a key or a button steps from: the parsed draft if one is open, else the shown value. */\n const resolveBase = useCallback((): number | null => {\n const open = draftRef.current;\n if (open !== null) {\n const parsed = latest.current.formatter.parse(open);\n clearDraft();\n if (parsed !== undefined) return parsed;\n }\n return shownRef.current;\n }, [clearDraft, latest, shownRef]);\n\n /** A one-step gesture: a key press, a wheel event, a click activation. */\n const oneStep = useCallback(\n (compute: (base: number | null) => number | null, source: NumberFieldSource, event: Event) => {\n const base = resolveBase();\n openGesture();\n step(compute(base), source, \"activate\", event);\n commit(source, \"activate\", event);\n },\n [commit, openGesture, resolveBase, step],\n );\n\n // --- Typing (design 4.1) ----------------------------------------------------------------------\n\n const typed = useCallback((next: string) => {\n draftRef.current = next;\n setDraft(next);\n }, []);\n\n const commitDraft = useCallback(\n (event: Event) => {\n const open = draftRef.current;\n if (open === null) return;\n const { formatter: f, disabled: off, readOnly: ro } = latest.current;\n if (off || ro) {\n clearDraft();\n return;\n }\n const parsed = f.parse(open);\n // Unparsable: revert to the committed value's text, no dispatch, no error.\n if (parsed === undefined || Object.is(parsed, shownRef.current)) {\n clearDraft();\n return;\n }\n openGesture();\n step(parsed, \"input\", \"activate\", event);\n commit(\"input\", \"activate\", event);\n },\n [clearDraft, commit, latest, openGesture, shownRef, step],\n );\n\n // --- Keyboard and wheel (design 4.2, 4.4) ----------------------------------------------------\n\n const keyDown = useCallback(\n (event: KeyboardEvent) => {\n const { disabled: off, readOnly: ro, bounds: b, largeStep: large } = latest.current;\n // WebKit fires `compositionend` before the confirming keydown, which then has\n // `isComposing === false` and `keyCode === 229` (Combobox's guard).\n if (off || ro || event.isComposing || event.keyCode === 229) return;\n if (event.key === \"Enter\") {\n commitDraft(event);\n return;\n }\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const compute = keyStep(event.key, event.shiftKey, b, large);\n if (compute === null) return;\n event.preventDefault();\n oneStep(compute, \"keyboard\", event);\n },\n [commitDraft, latest, oneStep],\n );\n\n const wheel = useCallback(\n (event: WheelEvent) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n const visible = visibleRef.current;\n if (off || ro || visible === null || event.deltaY === 0) return;\n // Only while the input is focused; unfocused, the page scrolls.\n if (visible.ownerDocument.activeElement !== visible) return;\n event.preventDefault();\n const n = event.deltaY < 0 ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), \"wheel\", event);\n },\n [latest, oneStep],\n );\n\n // --- Buttons (design 4.3) ---------------------------------------------------------------------\n\n const endHold = useCallback(\n (direction: StepDirection, event: Event | undefined) => {\n if (holdRef.current !== direction) return;\n holdRef.current = null;\n setHold(null);\n commit(direction, \"activate\", event);\n },\n [commit],\n );\n\n const tickHold = useCallback(\n (direction: StepDirection, event: Event | undefined): boolean => {\n if (holdRef.current !== direction) return false;\n const { bounds: b } = latest.current;\n const n = direction === \"increment\" ? 1 : -1;\n const next = stepValue(holdBase.current, n, b);\n holdBase.current = next;\n step(next, direction, \"activate\", event);\n // At the bound: end the hold now, before the button re-renders disabled (a disabled\n // element may not deliver the release).\n if (stepValue(next, n, b) === next) {\n endHold(direction, event);\n return false;\n }\n return true;\n },\n [endHold, latest, step],\n );\n\n const beginHold = useCallback(\n (direction: StepDirection, event: Event): boolean => {\n const { disabled: off, readOnly: ro } = latest.current;\n if (off || ro || holdRef.current !== null) return false;\n const base = resolveBase();\n openGesture();\n // A capture alone holds `live` on screen: start it from what is shown.\n setLive({ value: shownRef.current });\n holdBase.current = base;\n holdRef.current = direction;\n setHold(direction);\n return tickHold(direction, event);\n },\n [latest, openGesture, resolveBase, shownRef, tickHold],\n );\n\n const activate = useCallback(\n (direction: StepDirection, event: Event) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n if (off || ro || holdRef.current !== null) return;\n const n = direction === \"increment\" ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), direction, event);\n },\n [latest, oneStep],\n );\n\n // --- Labels ---------------------------------------------------------------------------------\n\n const [labelCount, setLabelCount] = useState(0);\n const registerLabel = useCallback(() => {\n setLabelCount((count) => count + 1);\n return () => setLabelCount((count) => count - 1);\n }, []);\n\n // --- Residual browser paths: mount reconciliation and form reset (design 4.5, 6.4) ----------\n\n const [mountValue] = useState(value);\n const resetTarget = (): number | null =>\n valueProp !== undefined ? (mountValue ?? null) : (defaultValue ?? null);\n const resetTargetText = hiddenText(resetTarget());\n\n const { onItemMounted } = useNativeGroupReconciliation<number | null>({\n element: hiddenRef as RefObject<FormAssociatedElement | null>,\n readCurrent: () =>\n readVisible(visibleRef.current, shownRef.current, formatter, (text) => {\n draftRef.current = text;\n setDraft(text);\n }),\n readDefault: () => {\n // A reset clears an open draft whatever the target.\n clearDraft();\n return resetTarget();\n },\n base: () => shownRef.current,\n onPlatformChange: (next, event) => {\n openGesture();\n step(next, null, \"platform\", event);\n commit(null, \"platform\", event);\n },\n onResetEvent: () => {\n // react-dom rewrites a controlled text input's `defaultValue` after every update; the\n // visible text's reset target is written right before the reset algorithm reads it.\n const visible = visibleRef.current;\n if (visible !== null) visible.defaultValue = formatter.format(resetTarget());\n },\n });\n\n // --- Development warnings -------------------------------------------------------------------\n\n useNumberFieldDevWarnings({\n value: valueProp,\n defaultValue: defaultValueProp,\n min,\n max,\n bounds,\n stepValid,\n largeStepValid,\n formatter,\n locale,\n });\n\n // An unmount mid-hold leaves nothing behind (the buttons detach their own listeners).\n useEffect(\n () => () => {\n holdRef.current = null;\n },\n [],\n );\n\n // --- Render ---------------------------------------------------------------------------------\n\n const context = useMemo<NumberFieldContextValue>(\n () => ({\n state,\n bounds,\n stepBase,\n pendingSource: pending ? pendingSource : null,\n inputId,\n labelId,\n name,\n form,\n allowsFractions: formatter.allowsFractions || !Number.isInteger(stepSize),\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n visibleRef,\n hiddenRef,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n syncHidden,\n registerLabel,\n onItemMounted,\n }),\n [\n state,\n bounds,\n stepBase,\n pending,\n pendingSource,\n inputId,\n labelId,\n name,\n form,\n formatter,\n stepSize,\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n syncHidden,\n registerLabel,\n onItemMounted,\n ],\n );\n\n const labelledBy = mergeTokenLists(labelCount > 0 ? labelId : undefined, fieldContext?.ids.label);\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: \"group\",\n ...(labelledBy !== \"\" ? { \"aria-labelledby\": labelledBy } : {}),\n ...(fieldContext !== null ? { \"data-invalid\": dataAttr(fieldInvalid === true) } : {}),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, NumberFieldState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n });\n\n return <NumberFieldContext value={context}>{element}</NumberFieldContext>;\n}\n\nNumberFieldRoot.displayName = \"NumberFieldRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0LA,MAAM,aAAa,gBAAgB,gBAAgB,QAAQ;AAC3D,MAAM,eAAe,gBAAgB,gBAAgB,QAAQ;;AAG7D,SAAS,SAAS,OAA6D;CAC7E,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO;CAClD,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;;AAGA,SAAS,WAAW,OAA8B;CAChD,OAAO,UAAU,OAAO,KAAK,OAAO,KAAK;AAC3C;;;;;;;;;AAUA,SAAS,YACP,SACA,SACA,WACA,YACe;CACf,IAAI,YAAY,MAAM,OAAO;CAC7B,MAAM,UAAU,QAAQ;CACxB,IAAI,YAAY,UAAU,OAAO,OAAO,GAAG,OAAO;CAClD,IAAI,QAAQ,cAAc,kBAAkB,SAAS;EACnD,WAAW,OAAO;EAClB,OAAO;CACT;CACA,MAAM,SAAS,UAAU,MAAM,OAAO;CACtC,IAAI,WAAW,KAAA,KAAa,OAAO,GAAG,QAAQ,OAAO,GAAG;EACtD,QAAQ,QAAQ,UAAU,OAAO,OAAO;EACxC,OAAO;CACT;CACA,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,EACJ,OAAO,WACP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AAC;CAID,0BAA0B;EACxB,OAAO;EACP,cAAc;EACd;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAGD,sBACc;EACV,QAAQ,UAAU;CACpB,GACA,CAAC,CACH;CAIA,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA,eAAe,UAAU,gBAAgB;EACzC;EACA;EACA;EACA;EACA,iBAAiB,UAAU,mBAAmB,CAAC,OAAO,UAAU,QAAQ;EACxE;EACA;EACA;EACA;EACA;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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,aAAa,gBAAgB,aAAa,IAAI,UAAU,KAAA,GAAW,cAAc,IAAI,KAAK;CAChG,MAAM,eAAuE;EAC3E,MAAM;EACN,GAAI,eAAe,KAAK,EAAE,mBAAmB,WAAW,IAAI,CAAC;EAC7D,GAAI,iBAAiB,OAAO,EAAE,gBAAgB,SAAS,iBAAiB,IAAI,EAAE,IAAI,CAAC;EACnF,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,MAAM,UAAU,UAA0D;EACxE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;CAED,OAAO,oBAAC,oBAAD;EAAoB,OAAO;EAAU,UAAA;CAA4B,CAAA;AAC1E;AAEA,gBAAgB,cAAc"}
1
+ {"version":3,"file":"number-field-root.mjs","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n use,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, RefObject } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { announce as speak } from \"../internal/announce.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FieldContext } from \"../internal/field-context.js\";\nimport { mergeTokenLists } from \"../internal/merge-props.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { resolveFieldDefaults, useFieldValueChange } from \"../internal/use-field-control.js\";\nimport type { FormAssociatedElement } from \"../internal/use-form-owner-event.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeGroupReconciliation } from \"../internal/use-native-group-reconciliation.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { keyStep, stepValue } from \"./number-field-arithmetic.js\";\nimport type { StepBounds } from \"./number-field-arithmetic.js\";\nimport { NumberFieldContext } from \"./number-field-context.js\";\nimport type {\n NumberFieldContextValue,\n NumberFieldSource,\n StepDirection,\n} from \"./number-field-context.js\";\nimport { createNumberFormatter, formatKey } from \"./number-field-format.js\";\nimport type { NumberFormatter } from \"./number-field-format.js\";\nimport { useNumberFieldDevWarnings } from \"./use-number-field-dev-warnings.js\";\n\n/** Details passed as the second argument of both NumberField actions. */\nexport interface NumberFieldValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user typed, pressed a key, a button or turned the wheel (`details.event` is\n * the `focusout` / Enter `keydown` of a typed value, the `keydown` of a key, the `pointerdown` /\n * `pointerup` of a button (`undefined` for the repeats of a held button and for a hold that\n * ended at its bound), the `wheel` event). `\"platform\"`: a form reset (the `reset`\n * event) or text typed before hydration (`undefined`). `\"dismiss\"`: the commit action rejected\n * and the field reverted to the committed value (uncontrolled; `valueChangeAction` only).\n */\n readonly reason: ChangeReason;\n /** What produced the value: typed text, a button, a key, the wheel; `null` for \"platform\" and \"dismiss\". */\n readonly source: NumberFieldSource;\n}\n\n/** The state every NumberField part's function props receive (one object, Field's precedent). */\nexport interface NumberFieldState {\n /** The shown value: the gesture's value while one is open or in flight, else the optimistic value; `null` when empty. */\n readonly value: number | null;\n /** The shown text: the draft while the user is editing, else `value` formatted. */\n readonly text: string;\n /** A step or commit dispatched through this NumberField is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop, or the enclosing Field's. */\n readonly disabled: boolean;\n /** The `readOnly` prop. */\n readonly readOnly: boolean;\n /** The `required` prop, or the enclosing Field's. */\n readonly required: boolean;\n}\n\n/**\n * Props of `NumberField.Root`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport interface NumberFieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"defaultValue\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` is empty, `undefined` uncontrolled. */\n value?: number | null;\n /**\n * Initial value in uncontrolled mode, and its form-reset target (latest).\n *\n * @defaultValue `null` (empty)\n */\n defaultValue?: number | null;\n /**\n * Runs inside the Root's step transition on every step: the parse of typed text at commit,\n * each key press, each tick of a hold, each wheel event, each platform change, and the revert\n * after a rejected commit (`reason: \"dismiss\"`, uncontrolled). Keep it cheap: adopt the value\n * (`setValue(next)` in the sync prefix is a transition update), start a deferred render.\n */\n valueChangeAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /**\n * Runs inside the Root's commit transition once per gesture: a typed text's blur or Enter, a\n * hold's release, each key press, each wheel event, a form reset, text typed before hydration.\n * Where the save goes; uncontrolled state is committed when it resolves and reverts when it\n * rejects. May be a Server Function.\n */\n valueCommitAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /** Native `min` on the hidden input (a constraint) and the lower bound of stepping. */\n min?: number;\n /** Native `max` on the hidden input (a constraint) and the upper bound of stepping. */\n max?: number;\n /**\n * Native `step` and the stepping grid from `min` (else `0`).\n *\n * @defaultValue `1`, or `0.01` when `format.style` is `\"percent\"`\n */\n step?: number;\n /**\n * The step of PageUp / PageDown and Shift+Arrow.\n *\n * @defaultValue `10 × step`\n */\n largeStep?: number;\n /**\n * `Intl.NumberFormatOptions` for the text: `style` `\"decimal\"` (default), `\"percent\"`,\n * `\"currency\"` (with `currency`), `\"unit\"` (with `unit`); fraction digits, grouping, sign\n * display. `notation: \"compact\"` is a dev warning (unparsable).\n */\n format?: Intl.NumberFormatOptions;\n /**\n * BCP 47 tag(s). Pass the page's `lang`; a dev warning fires when\n * `document.documentElement.lang` disagrees and this prop is absent.\n *\n * @defaultValue the runtime's locale (`Intl.NumberFormat().resolvedOptions().locale`)\n */\n locale?: string | readonly string[];\n /**\n * Step with the mouse wheel while the input is focused.\n *\n * @defaultValue `false`\n */\n stepOnWheel?: boolean;\n /**\n * Native `name` on the hidden input.\n *\n * @defaultValue the Field's `name` inside a `Field.Root`\n */\n name?: string;\n /** Native `form` on the hidden input. */\n form?: string;\n /**\n * Disables both inputs and the buttons; inherited by every part.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Native `readonly` on both inputs; no stepping (buttons disabled, keys and wheel inert).\n *\n * @defaultValue `false`\n */\n readOnly?: boolean;\n /**\n * Native `required` on the hidden input (empty is `valueMissing`); or the Field's.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /**\n * What is announced (`ariaNotify()`) after a key press, a wheel event, a click activation and a\n * hold's release. Return `null` to announce nothing.\n *\n * @defaultValue `(_, state) => state.text`\n */\n announce?: (value: number | null, state: NumberFieldState) => string | null;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NumberFieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NumberFieldState>;\n /** The parts. The function form receives the state. */\n children?: StateValue<ReactNode, NumberFieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, NumberFieldState>;\n}\n\nconst STEP_TYPES = transitionTypes(\"number-field\", \"change\");\nconst COMMIT_TYPES = transitionTypes(\"number-field\", \"commit\");\n\n/** A finite number, or `null` (`NaN` / `Infinity` are treated as empty). */\nfunction sanitize(value: number | null | undefined): number | null | undefined {\n if (value === undefined || value === null) return value;\n return Number.isFinite(value) ? value : null;\n}\n\n/** The hidden input's value for `value`. */\nfunction hiddenText(value: number | null): string {\n return value === null ? \"\" : String(value);\n}\n\n/**\n * Mount reconciliation's read of the visible input (design 4.5): the value the hydrated text\n * means. The client's own formatting of `current` is `current`. Focused text is still being typed\n * (even a partial `12,` or `-`): handed to `adoptDraft`, never overwritten under the caret; the\n * blur commits or reverts it by the ordinary rule. Otherwise the parsed text, or, for another\n * locale's formatting of the same value or text that is no number, `current` with the client's\n * text written back (react-dom kept the hydrated DOM value).\n */\nfunction readVisible(\n visible: HTMLInputElement | null,\n current: number | null,\n formatter: NumberFormatter,\n adoptDraft: (text: string) => void,\n): number | null {\n if (visible === null) return current;\n const domText = visible.value;\n if (domText === formatter.format(current)) return current;\n if (visible.ownerDocument.activeElement === visible) {\n adoptDraft(domText);\n return current;\n }\n const parsed = formatter.parse(domText);\n if (parsed === undefined || Object.is(parsed, current)) {\n visible.value = formatter.format(current);\n return current;\n }\n return parsed;\n}\n\n/**\n * Owns the number field's state (design/components/number-field.md 2): the committed value\n * through `useControllableAction` with `valueCommitAction` (once per gesture), each step through\n * its own transition (`valueChangeAction`), the urgent draft text, the urgent value of the open\n * gesture (`live`), the press-and-hold, the formatter and parser, the announcements, mount\n * reconciliation and form reset (through the hidden input the Input renders).\n *\n * Owned keys (conventions 1.2): `role=\"group\"`, `aria-labelledby` (token-merged: the consumer's,\n * then `NumberField.Label`'s id while one is mounted, then a Field's label id), `data-pending`,\n * `data-disabled`, `data-invalid` (inside a Field).\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport function NumberFieldRoot(props: NumberFieldRootProps) {\n const {\n value: valueProp,\n defaultValue: defaultValueProp,\n valueChangeAction,\n valueCommitAction,\n min,\n max,\n step: stepProp,\n largeStep: largeStepProp,\n format,\n locale,\n stepOnWheel = false,\n name: nameProp,\n form,\n disabled: disabledProp = false,\n readOnly = false,\n required: requiredProp = false,\n announce,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const value = sanitize(valueProp);\n const defaultValue = sanitize(defaultValueProp);\n\n // --- Format, bounds -----------------------------------------------------------------------\n\n const key = formatKey(format);\n const localeKey = locale === undefined ? \"\" : JSON.stringify(locale);\n // Memoised on the content of `format` and `locale`, not their identity (an inline object).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const formatter = useMemo(() => createNumberFormatter(locale, format), [localeKey, key]);\n const defaultStep = formatter.percent ? 0.01 : 1;\n const stepValid = stepProp === undefined || (Number.isFinite(stepProp) && stepProp > 0);\n const stepSize = stepProp !== undefined && stepValid ? stepProp : defaultStep;\n const largeStepValid =\n largeStepProp === undefined || (Number.isFinite(largeStepProp) && largeStepProp > 0);\n const largeStep = largeStepProp !== undefined && largeStepValid ? largeStepProp : 10 * stepSize;\n const bounds = useMemo<StepBounds>(\n () => ({\n min: Number.isFinite(min) ? min : undefined,\n max: Number.isFinite(max) ? max : undefined,\n step: stepSize,\n }),\n [min, max, stepSize],\n );\n\n // --- Field ----------------------------------------------------------------------------------\n\n // NumberField.Input registers the control (design 7.1); the Root only resolves the defaults.\n const fieldContext = use(FieldContext);\n const { disabled, required, name } = resolveFieldDefaults(fieldContext, {\n name: nameProp,\n disabled: disabledProp,\n required: requiredProp,\n });\n const fieldInvalid = fieldContext === null ? undefined : fieldContext.state.invalid;\n\n const id = useId();\n const inputId = fieldContext?.ids.control ?? `${id}-input`;\n const labelId = `${id}-label`;\n\n // --- State (design 2) -----------------------------------------------------------------------\n\n const [draft, setDraft] = useState<string | null>(null);\n const draftRef = useRef<string | null>(null);\n /** The value the open gesture has reached (`null` inside: an empty value). */\n const [live, setLive] = useState<{ readonly value: number | null } | null>(null);\n const [hold, setHold] = useState<StepDirection | null>(null);\n const [stepHeld, setStepHeld] = useState(false);\n const [pendingSource, setPendingSource] = useState<NumberFieldSource>(null);\n\n const liveRef = useRef<number | null>(null);\n /** The shown value when the open gesture began; `null` when no gesture is open. */\n const gestureStart = useRef<{ readonly value: number | null } | null>(null);\n /** The value the next tick of a hold steps from. */\n const holdBase = useRef<number | null>(null);\n const holdRef = useRef<StepDirection | null>(null);\n const commitSeq = useRef(0);\n const lastReason = useRef<ChangeReason | null>(null);\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const hiddenRef = useRef<HTMLInputElement | null>(null);\n\n const clearDraft = useCallback(() => {\n if (draftRef.current === null) return;\n draftRef.current = null;\n setDraft(null);\n }, []);\n\n /**\n * Writes `next` into the hidden input, then mirrors its validity onto the visible input, which\n * is invalid exactly when the hidden one is (6.2).\n */\n const syncHidden = useCallback((next: number | null) => {\n const hidden = hiddenRef.current;\n if (hidden !== null) {\n const text = hiddenText(next);\n if (hidden.value !== text) hidden.value = text;\n }\n const visible = visibleRef.current;\n if (hidden === null || visible === null) return;\n const message = hidden.validationMessage;\n if (visible.validationMessage !== message) visible.setCustomValidity(message);\n }, []);\n\n // A step is not a re-entry: a continuous control dispatches one step per key press or pointer\n // move and every step must run (design/components/button.md 16.1), so no in-flight guard.\n const { pending: stepPending, run: runStep } = useActionTrigger({\n ignoreWhilePending: false,\n });\n\n const runCommit = async (\n next: number | null,\n details: NumberFieldValueChangeDetails,\n ): Promise<void> => {\n const seq = ++commitSeq.current;\n try {\n await valueCommitAction?.(next, details);\n } catch (error) {\n // Design 2.4: in uncontrolled mode, tell the preview channel about the rollback, for the\n // latest commit only. Yield once to leave the commit's transition (conventions 2.6).\n if (valueProp === undefined && seq === commitSeq.current) {\n await undefined;\n // `step` and `committedRef` are declared below; this runs long after the render.\n step(committedRef.current, null, \"dismiss\", undefined);\n }\n throw error;\n }\n };\n\n const commitState = useControllableAction<number | null, NumberFieldValueChangeDetails>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: runCommit,\n transitionTypes: () => COMMIT_TYPES,\n warn: { component: \"NumberField.Root\", prop: \"value\" },\n });\n const { optimistic, committed, dispatch } = commitState;\n const committedRef = useLatest(committed);\n\n const held = hold !== null || stepHeld || stepPending || commitState.pending;\n const shown = held && live !== null ? live.value : optimistic;\n const pending = stepPending || commitState.pending;\n const text = draft ?? formatter.format(shown);\n // The value a button press steps from (4.3 step 3): the parsed draft while one is open.\n const parsedDraft = draft === null ? undefined : formatter.parse(draft);\n const stepBase = parsedDraft === undefined ? shown : parsedDraft;\n /** What the input shows, for handlers; also written by `step` ahead of the render. */\n const shownRef = useLatest(shown);\n\n const state = useMemo<NumberFieldState>(\n () => ({ value: shown, text, pending, disabled, readOnly, required }),\n [shown, text, pending, disabled, readOnly, required],\n );\n\n // A step, a key and a typed commit fire no `input` / `change` on the element the Field hears\n // for the value (the hidden input is written by script): tell it at the commit (design 7.2).\n useFieldValueChange(optimistic, () => {\n const edit = lastReason.current === \"activate\";\n lastReason.current = null;\n return edit;\n });\n\n const latest = useLatest({\n valueChangeAction,\n runStep,\n formatter,\n bounds,\n largeStep,\n disabled,\n readOnly,\n announce,\n state,\n });\n\n // --- Step and commit (design 2.4) -----------------------------------------------------------\n\n const step = useCallback(\n (\n next: number | null,\n source: NumberFieldSource,\n reason: ChangeReason,\n event: Event | undefined,\n ): boolean => {\n // What the text can show is what the form posts (5.4): a step finer than the format's\n // digits is rounded like a typed value.\n const { formatter: f } = latest.current;\n if (next !== null) next = f.round(next);\n // No-op against what the user sees (conventions 2.3 item 8).\n if (Object.is(next, shownRef.current)) return false;\n liveRef.current = next;\n shownRef.current = next;\n lastReason.current = reason;\n setLive({ value: next });\n clearDraft();\n setPendingSource(source);\n syncHidden(next);\n // A revert has no commit after it: the optimistic value already shows the committed one.\n if (reason !== \"dismiss\") setStepHeld(true);\n const { valueChangeAction: action, runStep: run } = latest.current;\n // Without a step action nothing runs and no transition starts (as Slider).\n if (action === undefined) return true;\n run(() => {\n for (const type of STEP_TYPES) addTransitionType(type);\n return action(next, createActionDetails(event, { reason, source }));\n });\n return true;\n },\n [clearDraft, latest, shownRef, syncHidden],\n );\n\n const announceValue = useCallback(\n (next: number | null) => {\n const visible = visibleRef.current;\n if (visible === null) return;\n const { announce: compose, formatter: f, state: s } = latest.current;\n const nextState: NumberFieldState = { ...s, value: next, text: f.format(next) };\n const message = compose === undefined ? nextState.text : compose(next, nextState);\n if (message !== null) speak(visible, message);\n },\n [latest],\n );\n\n const commit = useCallback(\n (source: NumberFieldSource, reason: ChangeReason, event: Event | undefined): boolean => {\n const start = gestureStart.current;\n gestureStart.current = null;\n // The commit's own pending state holds `live` from here (set in this same batch).\n setStepHeld(false);\n const next = liveRef.current;\n // Nothing changed since the gesture began (a hold that returned to its start).\n if (start === null || Object.is(next, start.value)) return false;\n lastReason.current = reason;\n setPendingSource(source);\n dispatch(next, createActionDetails(event, { reason, source }));\n if (reason === \"activate\" && source !== \"input\" && source !== null) announceValue(next);\n return true;\n },\n [announceValue, dispatch],\n );\n\n /** Opens a gesture at the shown value. */\n const openGesture = useCallback(() => {\n gestureStart.current = { value: shownRef.current };\n liveRef.current = shownRef.current;\n }, [shownRef]);\n\n /** The value a key or a button steps from: the parsed draft if one is open, else the shown value. */\n const resolveBase = useCallback((): number | null => {\n const open = draftRef.current;\n if (open !== null) {\n const parsed = latest.current.formatter.parse(open);\n clearDraft();\n if (parsed !== undefined) return parsed;\n }\n return shownRef.current;\n }, [clearDraft, latest, shownRef]);\n\n /** A one-step gesture: a key press, a wheel event, a click activation. */\n const oneStep = useCallback(\n (compute: (base: number | null) => number | null, source: NumberFieldSource, event: Event) => {\n const base = resolveBase();\n openGesture();\n step(compute(base), source, \"activate\", event);\n commit(source, \"activate\", event);\n },\n [commit, openGesture, resolveBase, step],\n );\n\n // --- Typing (design 4.1) ----------------------------------------------------------------------\n\n const typed = useCallback((next: string) => {\n draftRef.current = next;\n setDraft(next);\n }, []);\n\n const commitDraft = useCallback(\n (event: Event) => {\n const open = draftRef.current;\n if (open === null) return;\n const { formatter: f, disabled: off, readOnly: ro } = latest.current;\n if (off || ro) {\n clearDraft();\n return;\n }\n const parsed = f.parse(open);\n // Unparsable: revert to the committed value's text, no dispatch, no error.\n if (parsed === undefined || Object.is(parsed, shownRef.current)) {\n clearDraft();\n return;\n }\n openGesture();\n step(parsed, \"input\", \"activate\", event);\n commit(\"input\", \"activate\", event);\n },\n [clearDraft, commit, latest, openGesture, shownRef, step],\n );\n\n // --- Keyboard and wheel (design 4.2, 4.4) ----------------------------------------------------\n\n const keyDown = useCallback(\n (event: KeyboardEvent) => {\n const { disabled: off, readOnly: ro, bounds: b, largeStep: large } = latest.current;\n // WebKit fires `compositionend` before the confirming keydown, which then has\n // `isComposing === false` and `keyCode === 229` (Combobox's guard).\n if (off || ro || event.isComposing || event.keyCode === 229) return;\n if (event.key === \"Enter\") {\n commitDraft(event);\n return;\n }\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const compute = keyStep(event.key, event.shiftKey, b, large);\n if (compute === null) return;\n event.preventDefault();\n oneStep(compute, \"keyboard\", event);\n },\n [commitDraft, latest, oneStep],\n );\n\n const wheel = useCallback(\n (event: WheelEvent) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n const visible = visibleRef.current;\n if (off || ro || visible === null || event.deltaY === 0) return;\n // Only while the input is focused; unfocused, the page scrolls.\n if (visible.ownerDocument.activeElement !== visible) return;\n event.preventDefault();\n const n = event.deltaY < 0 ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), \"wheel\", event);\n },\n [latest, oneStep],\n );\n\n // --- Buttons (design 4.3) ---------------------------------------------------------------------\n\n const endHold = useCallback(\n (direction: StepDirection, event: Event | undefined) => {\n if (holdRef.current !== direction) return;\n holdRef.current = null;\n setHold(null);\n commit(direction, \"activate\", event);\n },\n [commit],\n );\n\n const tickHold = useCallback(\n (direction: StepDirection, event: Event | undefined): boolean => {\n if (holdRef.current !== direction) return false;\n const { bounds: b } = latest.current;\n const n = direction === \"increment\" ? 1 : -1;\n const next = stepValue(holdBase.current, n, b);\n holdBase.current = next;\n step(next, direction, \"activate\", event);\n // At the bound: end the hold now, before the button re-renders disabled (a disabled\n // element may not deliver the release).\n if (stepValue(next, n, b) === next) {\n endHold(direction, event);\n return false;\n }\n return true;\n },\n [endHold, latest, step],\n );\n\n const beginHold = useCallback(\n (direction: StepDirection, event: Event): boolean => {\n const { disabled: off, readOnly: ro } = latest.current;\n if (off || ro || holdRef.current !== null) return false;\n const base = resolveBase();\n openGesture();\n // A capture alone holds `live` on screen: start it from what is shown.\n setLive({ value: shownRef.current });\n holdBase.current = base;\n holdRef.current = direction;\n setHold(direction);\n return tickHold(direction, event);\n },\n [latest, openGesture, resolveBase, shownRef, tickHold],\n );\n\n const activate = useCallback(\n (direction: StepDirection, event: Event) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n if (off || ro || holdRef.current !== null) return;\n const n = direction === \"increment\" ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), direction, event);\n },\n [latest, oneStep],\n );\n\n // --- Labels ---------------------------------------------------------------------------------\n\n const [labelCount, setLabelCount] = useState(0);\n const registerLabel = useCallback(() => {\n setLabelCount((count) => count + 1);\n return () => setLabelCount((count) => count - 1);\n }, []);\n\n // --- Residual browser paths: mount reconciliation and form reset (design 4.5, 6.4) ----------\n\n const [mountValue] = useState(value);\n const resetTarget = (): number | null =>\n valueProp !== undefined ? (mountValue ?? null) : (defaultValue ?? null);\n const resetTargetText = hiddenText(resetTarget());\n\n const { onItemMounted } = useNativeGroupReconciliation<number | null>({\n element: hiddenRef as RefObject<FormAssociatedElement | null>,\n readCurrent: () =>\n readVisible(visibleRef.current, shownRef.current, formatter, (text) => {\n draftRef.current = text;\n setDraft(text);\n }),\n readDefault: () => {\n // A reset clears an open draft whatever the target.\n clearDraft();\n return resetTarget();\n },\n base: () => shownRef.current,\n onPlatformChange: (next, event) => {\n openGesture();\n step(next, null, \"platform\", event);\n commit(null, \"platform\", event);\n },\n onResetEvent: () => {\n // react-dom rewrites a controlled text input's `defaultValue` after every update; the\n // visible text's reset target is written right before the reset algorithm reads it.\n const visible = visibleRef.current;\n if (visible !== null) visible.defaultValue = formatter.format(resetTarget());\n },\n });\n\n // --- Development warnings -------------------------------------------------------------------\n\n useNumberFieldDevWarnings({\n value: valueProp,\n defaultValue: defaultValueProp,\n min,\n max,\n bounds,\n stepValid,\n largeStepValid,\n formatter,\n locale,\n });\n\n // An unmount mid-hold leaves nothing behind (the buttons detach their own listeners).\n useEffect(\n () => () => {\n holdRef.current = null;\n },\n [],\n );\n\n // --- Render ---------------------------------------------------------------------------------\n\n const context = useMemo<NumberFieldContextValue>(\n () => ({\n state,\n bounds,\n stepBase,\n pendingSource: pending ? pendingSource : null,\n inputId,\n labelId,\n name,\n form,\n allowsFractions: formatter.allowsFractions || !Number.isInteger(stepSize),\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n visibleRef,\n hiddenRef,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n syncHidden,\n registerLabel,\n onItemMounted,\n }),\n [\n state,\n bounds,\n stepBase,\n pending,\n pendingSource,\n inputId,\n labelId,\n name,\n form,\n formatter,\n stepSize,\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n syncHidden,\n registerLabel,\n onItemMounted,\n ],\n );\n\n const labelledBy = mergeTokenLists(labelCount > 0 ? labelId : undefined, fieldContext?.ids.label);\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: \"group\",\n ...(labelledBy !== \"\" ? { \"aria-labelledby\": labelledBy } : {}),\n ...(fieldContext !== null ? { \"data-invalid\": dataAttr(fieldInvalid === true) } : {}),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, NumberFieldState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n });\n\n return <NumberFieldContext value={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A;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,aAAa,gBAAgB,aAAa,IAAI,UAAU,KAAA,GAAW,cAAc,IAAI,KAAK;CAChG,MAAM,eAAuE;EAC3E,MAAM;EACN,GAAI,eAAe,KAAK,EAAE,mBAAmB,WAAW,IAAI,CAAC;EAC7D,GAAI,iBAAiB,OAAO,EAAE,gBAAgB,SAAS,iBAAiB,IAAI,EAAE,IAAI,CAAC;EACnF,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,MAAM,UAAU,UAA0D;EACxE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;CAED,OAAO,oBAAC,oBAAD;EAAoB,OAAO;EAAU,UAAA;CAA4B,CAAA;AAC1E;AAEA,gBAAgB,cAAc"}
@@ -11,9 +11,9 @@ import { PopoverTrigger, PopoverTriggerProps, PopoverTriggerState } from "./popo
11
11
  * (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >
12
12
  * `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,
13
13
  * nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /
14
- * `defaultOpen` / `openChangeAction`; otherwise opening and the closes a part asks for are
15
- * transitions (pending Trigger, content from committed state), and dismissals are notified
16
- * through `openChangeAction(false)`.
14
+ * `defaultOpen` / `openChangeAction` / `onOpenChange`; otherwise opening and the closes a part
15
+ * asks for are requests, transitions (pending Trigger, content from committed state), and
16
+ * dismissals are facts, reported to `onOpenChange(false)`.
17
17
  *
18
18
  * @see https://ui.funstack.work/components/popover
19
19
  */
@@ -10,9 +10,9 @@ import { PopoverTrigger } from "./popover-trigger.mjs";
10
10
  * (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >
11
11
  * `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,
12
12
  * nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /
13
- * `defaultOpen` / `openChangeAction`; otherwise opening and the closes a part asks for are
14
- * transitions (pending Trigger, content from committed state), and dismissals are notified
15
- * through `openChangeAction(false)`.
13
+ * `defaultOpen` / `openChangeAction` / `onOpenChange`; otherwise opening and the closes a part
14
+ * asks for are requests, transitions (pending Trigger, content from committed state), and
15
+ * dismissals are facts, reported to `onOpenChange(false)`.
16
16
  *
17
17
  * @see https://ui.funstack.work/components/popover
18
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/popover/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { PopoverClose } from \"./popover-close.js\";\nimport { PopoverDescription } from \"./popover-description.js\";\nimport { PopoverPopup } from \"./popover-popup.js\";\nimport { PopoverRoot } from \"./popover-root.js\";\nimport { PopoverTitle } from \"./popover-title.js\";\nimport { PopoverTrigger } from \"./popover-trigger.js\";\n\n/**\n * Popover built on `popover=\"auto\"` and Invoker Commands: `Root` (no DOM) > `Trigger`\n * (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >\n * `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,\n * nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /\n * `defaultOpen` / `openChangeAction`; otherwise opening and the closes a part asks for are\n * transitions (pending Trigger, content from committed state), and dismissals are notified\n * through `openChangeAction(false)`.\n *\n * @see https://ui.funstack.work/components/popover\n */\nexport const Popover = {\n Root: PopoverRoot,\n Trigger: PopoverTrigger,\n Popup: PopoverPopup,\n Close: PopoverClose,\n Title: PopoverTitle,\n Description: PopoverDescription,\n} as const;\n\nexport type {\n PopoverRootProps,\n PopoverRootState,\n PopoverOpenChangeDetails,\n} from \"./popover-root.js\";\nexport type { PopoverTriggerProps, PopoverTriggerState } from \"./popover-trigger.js\";\nexport type {\n PopoverPopupProps,\n PopoverPopupState,\n PopoverSide,\n PopoverAlign,\n} from \"./popover-popup.js\";\nexport type { PopoverCloseProps, PopoverCloseState } from \"./popover-close.js\";\nexport type { PopoverTitleProps, PopoverTitleState } from \"./popover-title.js\";\nexport type { PopoverDescriptionProps, PopoverDescriptionState } from \"./popover-description.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAa,UAAU;CACrB,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;CACP,OAAO;CACP,aAAa;AACf"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/popover/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { PopoverClose } from \"./popover-close.js\";\nimport { PopoverDescription } from \"./popover-description.js\";\nimport { PopoverPopup } from \"./popover-popup.js\";\nimport { PopoverRoot } from \"./popover-root.js\";\nimport { PopoverTitle } from \"./popover-title.js\";\nimport { PopoverTrigger } from \"./popover-trigger.js\";\n\n/**\n * Popover built on `popover=\"auto\"` and Invoker Commands: `Root` (no DOM) > `Trigger`\n * (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >\n * `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,\n * nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /\n * `defaultOpen` / `openChangeAction` / `onOpenChange`; otherwise opening and the closes a part\n * asks for are requests, transitions (pending Trigger, content from committed state), and\n * dismissals are facts, reported to `onOpenChange(false)`.\n *\n * @see https://ui.funstack.work/components/popover\n */\nexport const Popover = {\n Root: PopoverRoot,\n Trigger: PopoverTrigger,\n Popup: PopoverPopup,\n Close: PopoverClose,\n Title: PopoverTitle,\n Description: PopoverDescription,\n} as const;\n\nexport type {\n PopoverRootProps,\n PopoverRootState,\n PopoverOpenChangeDetails,\n} from \"./popover-root.js\";\nexport type { PopoverTriggerProps, PopoverTriggerState } from \"./popover-trigger.js\";\nexport type {\n PopoverPopupProps,\n PopoverPopupState,\n PopoverSide,\n PopoverAlign,\n} from \"./popover-popup.js\";\nexport type { PopoverCloseProps, PopoverCloseState } from \"./popover-close.js\";\nexport type { PopoverTitleProps, PopoverTitleState } from \"./popover-title.js\";\nexport type { PopoverDescriptionProps, PopoverDescriptionState } from \"./popover-description.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAa,UAAU;CACrB,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;CACP,OAAO;CACP,aAAa;AACf"}
@@ -1,4 +1,4 @@
1
- import { Action, ActionDetails, RenderProp, StateValue } from "../internal/types.mjs";
1
+ import { Action, ActionDetails, RenderProp, StateValue, WhilePending } from "../internal/types.mjs";
2
2
  import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
3
3
  //#region src/popover/popover-close.d.ts
4
4
  /**
@@ -26,6 +26,16 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
26
26
  * JS-free mode the button is a native `command="hide-popover"` invoker.
27
27
  */
28
28
  action?: Action<[details: ActionDetails]>;
29
+ /**
30
+ * What a click does while this part's `action` is pending. `"ignore"`: nothing (the click is
31
+ * cancelled, `aria-disabled="true"` meanwhile). `"run"`: the action runs again (`data-pending`
32
+ * until every run has settled); the popover closes once, when the last run settles and only
33
+ * if the latest run resolved (a rejection leaves it open, as in `"ignore"` mode). No effect
34
+ * without `action`.
35
+ *
36
+ * @defaultValue `"ignore"`
37
+ */
38
+ whilePending?: WhilePending;
29
39
  /**
30
40
  * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot
31
41
  * re-enable it. With a link or component `render` whose click this part handles (library mode,
@@ -48,7 +58,8 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
48
58
  * without `action` the browser hides the popover. In library mode the click is always cancelled
49
59
  * and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the
50
60
  * commit). With `action` the action runs first in this part's own transition (`data-pending` on
51
- * the button, with `aria-disabled`; a second click meanwhile is ignored); a rejection leaves the
61
+ * the button, with `aria-disabled`; a second click meanwhile is ignored unless
62
+ * `whilePending="run"`); a rejection leaves the
52
63
  * popover open. It keeps `commandfor` where the Trigger has `popovertarget`: an invoker
53
64
  * inside its own popover exposes no state either way, and the `command` event tells the Popup a
54
65
  * foreign hide's reason.
@@ -59,7 +70,7 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
59
70
  *
60
71
  * @see https://ui.funstack.work/components/popover
61
72
  */
62
- export declare function PopoverClose({ action, disabled, className, style, children, render, ...rest }: PopoverCloseProps): ReactNode;
73
+ export declare function PopoverClose({ action, whilePending, disabled, className, style, children, render, ...rest }: PopoverCloseProps): ReactNode;
63
74
  export declare namespace PopoverClose {
64
75
  var displayName: string;
65
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;;;;;iBAYiB;;WAEN;;WAEA;;;;;;;iBAQM,0BAA0B,KACzC;;;;;;;;;EAWA,SAAS,QAAQ,SAAS;;;;;;;;EAQ1B;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;wBAmBvC,eACd,QACA,UACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBARJ"}
1
+ {"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;;;;;iBAkBiB;;WAEN;;WAEA;;;;;;;iBAQM,0BAA0B,KACzC;;;;;;;;;EAWA,SAAS,QAAQ,SAAS;;;;;;;;;;EAU1B,eAAe;;;;;;;;EAQf;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;wBAoBvC,eACd,QACA,cACA,UACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBATJ"}