@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.
- package/dist/accordion/accordion-root.mjs +1 -1
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/button/button.d.mts +21 -8
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +8 -6
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +5 -1
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts +4 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +15 -5
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +9 -11
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +7 -2
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +13 -3
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +3 -2
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts +2 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +9 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +12 -20
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +38 -24
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +10 -8
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +3 -3
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/dialog/index.d.mts +5 -5
- package/dist/dialog/index.mjs +5 -5
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/docs/components/button.md +65 -21
- package/dist/docs/components/checkbox-group.md +12 -3
- package/dist/docs/components/combobox.md +85 -22
- package/dist/docs/components/context-menu.md +8 -8
- package/dist/docs/components/dialog.md +42 -36
- package/dist/docs/components/menu.md +106 -25
- package/dist/docs/components/popover.md +101 -36
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/toast.md +37 -14
- package/dist/docs/components/toolbar.md +2 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/action-props.md +55 -25
- package/dist/docs/concepts/browser-owned-state.md +27 -12
- package/dist/docs/concepts/pending-and-optimistic.md +15 -2
- package/dist/docs/concepts/render.md +23 -0
- package/dist/docs/concepts/server-components.md +15 -1
- package/dist/docs/concepts/suspense.md +8 -3
- package/dist/docs/concepts/transitions.md +3 -9
- package/dist/docs/getting-started.md +9 -22
- package/dist/docs/index.md +5 -4
- package/dist/docs/roadmap.md +54 -0
- package/dist/docs/why.md +7 -3
- package/dist/index.d.mts +2 -2
- package/dist/internal/call-urgent-handler.mjs +37 -0
- package/dist/internal/call-urgent-handler.mjs.map +1 -0
- package/dist/internal/css-transition-cut.mjs +66 -0
- package/dist/internal/css-transition-cut.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs.map +1 -1
- package/dist/internal/report-dropped.mjs +45 -0
- package/dist/internal/report-dropped.mjs.map +1 -0
- package/dist/internal/types.d.mts +33 -7
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +32 -17
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-controllable-action.mjs +52 -16
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-native-group-reconciliation.mjs +4 -2
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +10 -4
- package/dist/internal/use-overlay-close.mjs.map +1 -1
- package/dist/internal/use-overlay-root.mjs +40 -7
- package/dist/internal/use-overlay-root.mjs.map +1 -1
- package/dist/internal/use-popover-popup.mjs +22 -7
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +1 -1
- package/dist/internal/use-popover-trigger.d.mts.map +1 -1
- package/dist/internal/use-popover-trigger.mjs +11 -3
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/menu/menu-checkbox-item.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-item.d.mts +15 -4
- package/dist/menu/menu-item.d.mts.map +1 -1
- package/dist/menu/menu-item.mjs +10 -5
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +2 -2
- package/dist/menu/menu-outside.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +3 -0
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +27 -12
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +5 -4
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +2 -8
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/popover/index.d.mts +3 -3
- package/dist/popover/index.mjs +3 -3
- package/dist/popover/index.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +14 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +4 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +6 -3
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +3 -2
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.d.mts +31 -18
- package/dist/popover/popover-root.d.mts.map +1 -1
- package/dist/popover/popover-root.mjs +9 -7
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +2 -8
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-action.d.mts +14 -3
- package/dist/toast/toast-action.d.mts.map +1 -1
- package/dist/toast/toast-action.mjs +6 -4
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-queue.mjs.map +1 -1
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +15 -15
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.d.mts +10 -7
- package/dist/toast/toast.d.mts.map +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +1 -1
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/funstack-ui-knowledge/SKILL.md +6 -6
- package/dist/internal/use-superseded-rejection.mjs +0 -47
- package/dist/internal/use-superseded-rejection.mjs.map +0 -1
package/dist/docs/roadmap.md
CHANGED
|
@@ -10,29 +10,83 @@ Alpha releases (`0.1.0-alpha.N`) are published on npm under the `alpha` dist-tag
|
|
|
10
10
|
|
|
11
11
|
Changes an upgrade may notice, newest first. Each component page documents the current behaviour.
|
|
12
12
|
|
|
13
|
+
- A popup with both a CSS exit and `transition` no longer needs the rule `html:active-view-transition .my-popup { transition: none; }` ([#147](https://github.com/uhyo/funstack-ui/issues/147); [A popup with a CSS exit and a view transition](concepts/transitions.md#css-exit)). While a view transition runs, the library turns the popup's CSS transitions off for the moment of its own show or hide, with an inline `transition: none !important` that it removes right after. The rule is not needed: remove it. Keeping it breaks nothing, but an unrelated view transition of the page then still cuts a dismissal's CSS fade.
|
|
14
|
+
|
|
15
|
+
- **Breaking:** requests and facts ([#148](https://github.com/uhyo/funstack-ui/issues/148); [Requests and facts](concepts/browser-owned-state.md#requests-and-facts)). On `Popover.Root`, `Menu.Root`, `Combobox.Root` and `Dialog.Root`:
|
|
16
|
+
|
|
17
|
+
- `openChangeAction` is no longer called for a close the library did not perform on request: Escape, a click outside, focus leaving the popup, a parent menu closing its submenu, your own invoker button closing the popup, script `hidePopover()` / `close()`, and so on. These closes are [facts](concepts/action-props.md#fact), reported to the new `onOpenChange` instead. Code that checks `reason === "dismiss"` inside `openChangeAction` must move to `onOpenChange`.
|
|
18
|
+
- A controlled Root needs `onOpenChange` as well: `open={open} openChangeAction={setOpen} onOpenChange={setOpen}`. Without it the popup re-opens after every dismissal (development warns); a Menu re-opened this way leaves focus where the dismissal put it ([#155](https://github.com/uhyo/funstack-ui/issues/155)).
|
|
19
|
+
- `onOpenChange` must set state directly, not in `startTransition` and not after an `await`.
|
|
20
|
+
- A dismissal is no longer pending: no `data-pending` on the Trigger, `state.pending` stays `false`, the committed state is `false` at once, and the callback is not awaited.
|
|
21
|
+
- A dismissal starts no view transition and carries no `fsui-<component>-close` type: `transition` on a Popup animates opens and the closes a part asks for; a dismissal is animated by CSS only.
|
|
22
|
+
- A controlled Root that keeps `open={true}` after a dismissal is re-opened at once, not after the callback settled.
|
|
23
|
+
- Errors: a failing dismissal callback no longer reaches an Error Boundary; a rejected promise returned from `onOpenChange`, or a throw, goes to `reportError`.
|
|
24
|
+
- A dismissal during a pending close is reported at once; a request that was in flight is superseded (its rejection goes to `reportError`). `Dialog.Root` no longer holds such a dismissal back.
|
|
25
|
+
- A Server Function passed to `openChangeAction` no longer hears dismissals; pass it to `onOpenChange` too.
|
|
26
|
+
- JS-free mode (Popover, Dialog): `onOpenChange` on the Root selects library mode.
|
|
27
|
+
|
|
28
|
+
Not changing: a popup opened before hydration is still a request, `openChangeAction(true, { reason: "platform" })`. Two closes keep `reason: "dismiss"` and stay requests to `openChangeAction`: the pointer leaving a hover-opened submenu, and lost interest while an `interestfor` open is still pending.
|
|
29
|
+
|
|
30
|
+
- **Breaking:** `toast({ closeAction })` is renamed `onClose`. It is called synchronously when the toast closes, is not awaited, no longer holds other transitions, and its rejection goes to `reportError` instead of the Error Boundary above the Viewport ([#148](https://github.com/uhyo/funstack-ui/issues/148)).
|
|
31
|
+
|
|
32
|
+
- `Combobox.Root`'s `onInputValueChange` may return a promise: the development warning is gone, and a rejection or a throw goes to `reportError`. Every `on*` handler the library defines follows that rule ([Action props](concepts/action-props.md#handlers), [#148](https://github.com/uhyo/funstack-ui/issues/148)).
|
|
33
|
+
|
|
34
|
+
- **Breaking:** a pending `Button` no longer ignores clicks or renders `aria-disabled="true"`: every click, Enter or Space runs its `action` (or submits its function `formAction`) again. Add `whilePending="ignore"` to keep the old behaviour, for a Save, Pay or Delete that must not run twice. A `Menu.Item` with `closeOnActivate={false}` and a `Toast.Action` with `closeOnSettle={false}` now run every activation too. The Close parts, a closing `Menu.Item` and a closing `Toast.Action` still ignore a second activation by default; `whilePending="run"` opts out. In `"run"` mode the runs overlap, so an older run's rejection goes to `reportError` ([#146](https://github.com/uhyo/funstack-ui/issues/146)).
|
|
35
|
+
|
|
36
|
+
- An action that rejects after its component unmounted (a `Toast.Action` whose toast was closed meanwhile, a `Menu.Item` whose menu closed) or while it is hidden (an `<Activity>`, a closed `keepMounted` overlay, a Suspense boundary showing its fallback) is passed to the global `reportError` instead of being lost ([#152](https://github.com/uhyo/funstack-ui/issues/152)).
|
|
37
|
+
|
|
38
|
+
- Resetting the form of an uncontrolled CheckboxGroup while a change is pending lands on the default even when a pending change rejects later ([#151](https://github.com/uhyo/funstack-ui/issues/151)).
|
|
39
|
+
|
|
40
|
+
- When an older action rejects after a newer one started, the rejection no longer replaces the component with the Error Boundary: it is passed to the global `reportError` (a window `error` event) and the UI keeps the newer intent. The latest action's rejection still reaches the Error Boundary ([#145](https://github.com/uhyo/funstack-ui/issues/145)).
|
|
41
|
+
|
|
42
|
+
- Uncontrolled CheckboxGroup, and ToggleGroup and Accordion without `exclusive`, no longer commit a change whose action rejected when a later change's action resolved ([#150](https://github.com/uhyo/funstack-ui/issues/150)).
|
|
43
|
+
|
|
13
44
|
- **Breaking (types):** `Combobox.Input` owns `onFocus`, which is no longer in its props type; use `onFocusCapture` to react to focus ([#132](https://github.com/uhyo/funstack-ui/issues/132)).
|
|
45
|
+
|
|
14
46
|
- A `Combobox.Trigger` that is disabled but stays focusable (a component `render` with `aria-disabled`) is no invoker, like the other overlay Triggers: it renders `aria-expanded` and no `popovertarget`, and pressing it while the listbox is shown light-dismisses it ([#132](https://github.com/uhyo/funstack-ui/issues/132)).
|
|
47
|
+
|
|
15
48
|
- A Popover opened by an `interestfor` button that is not its Trigger (Chromium) hides when interest is lost, reported as `"dismiss"` ([#127](https://github.com/uhyo/funstack-ui/issues/127)).
|
|
49
|
+
|
|
16
50
|
- Pressing a button of yours that targets an open Menu or Combobox (a [foreign invoker](concepts/browser-owned-state.md#foreign-invoker)) no longer moves focus out of it first; the button's own close is the only close ([#126](https://github.com/uhyo/funstack-ui/issues/126)).
|
|
51
|
+
|
|
17
52
|
- A foreign `popovertarget` button that closes a Popover, Menu or Combobox is reported as `"activate"` instead of `"dismiss"` ([#125](https://github.com/uhyo/funstack-ui/issues/125)).
|
|
53
|
+
|
|
18
54
|
- **Breaking:** `Popover.Trigger`, `Menu.Trigger`, `Menu.SubmenuTrigger` and `Combobox.Trigger` name their popup with `popovertarget` instead of `commandfor` + `command="toggle-popover"`, and a `<button>` Trigger renders no `aria-expanded`: every browser exposes the popup's state on it. Move CSS from `[aria-expanded="true"]` to `[data-open]` (now also written in Popover's JS-free mode), or to `:has(+ :popover-open)` on a page that never hydrates. A Trigger rendered as a link or another element through `render` keeps `aria-expanded`. Replace `[commandfor]` selectors on these Triggers with `[data-open]` or a class of your own. `commandfor`, `command`, `popoverTarget` and `popoverTargetAction` are owned by these Triggers ([#121](https://github.com/uhyo/funstack-ui/issues/121)).
|
|
55
|
+
|
|
19
56
|
- Clicking the Trigger of an open Menu or Combobox is a library-owned close on every engine: the popup stays shown with `data-pending` until `openChangeAction(false)` settles, and the exit view transition runs ([#110](https://github.com/uhyo/funstack-ui/issues/110), [#112](https://github.com/uhyo/funstack-ui/issues/112)).
|
|
57
|
+
|
|
20
58
|
- An overlay Trigger's `aria-expanded` and the Combobox input's report whether the popup is actually shown; `data-open` stays optimistic. With `defaultOpen` the server HTML has `aria-expanded="false"` until the popup is shown after hydration ([#118](https://github.com/uhyo/funstack-ui/issues/118)).
|
|
59
|
+
|
|
21
60
|
- A Trigger click on an open non-modal `lightDismiss` Dialog dismisses it on every engine ([#116](https://github.com/uhyo/funstack-ui/issues/116)).
|
|
61
|
+
|
|
22
62
|
- Popover and Menu Triggers rendered as something other than a `<button>` are no longer invokers; a development warning explains that they close through light dismiss ([#115](https://github.com/uhyo/funstack-ui/issues/115)).
|
|
63
|
+
|
|
23
64
|
- The fallback live region is removed: announcements use `ariaNotify` only ([#113](https://github.com/uhyo/funstack-ui/issues/113)).
|
|
65
|
+
|
|
24
66
|
- Combobox: a press on the input while the listbox is open no longer closes it ([#123](https://github.com/uhyo/funstack-ui/issues/123)); pressing a label while typing no longer discards or commits the typed text ([#111](https://github.com/uhyo/funstack-ui/issues/111)).
|
|
67
|
+
|
|
25
68
|
- Toast: ArrowUp and ArrowDown inside a text field in a toast move the caret instead of switching toasts ([#113](https://github.com/uhyo/funstack-ui/issues/113)).
|
|
69
|
+
|
|
26
70
|
- **Breaking:** `MenuTriggerProps` no longer accepts `onMouseDown` ([#110](https://github.com/uhyo/funstack-ui/issues/110)); `ComboboxTriggerProps` no longer accepts `commandfor` or `command` ([#112](https://github.com/uhyo/funstack-ui/issues/112)); `Combobox.Input` owns `onPointerDown` ([#123](https://github.com/uhyo/funstack-ui/issues/123)).
|
|
71
|
+
|
|
27
72
|
- CheckboxGroup compares a controlled `value` by content, so an inline array with the same items does not re-render every Item ([#108](https://github.com/uhyo/funstack-ui/issues/108)).
|
|
73
|
+
|
|
28
74
|
- Slider and NumberField: when a newer action supersedes one that then rejects, the rejection reaches the Error Boundary at once instead of waiting for the action on the other channel (step or commit) to settle ([#105](https://github.com/uhyo/funstack-ui/issues/105)).
|
|
75
|
+
|
|
29
76
|
- **Breaking:** `TabsValueChangeDetails.reason` and `AccordionValueChangeDetails.reason` are the shared `ChangeReason` type ([#102](https://github.com/uhyo/funstack-ui/issues/102)).
|
|
77
|
+
|
|
30
78
|
- **Breaking:** `Combobox.Root`'s `inputValueChangeAction` is renamed `onInputValueChange` and the type `UrgentChangeAction` is renamed `UrgentChangeHandler`; an action prop always means a transition ([#96](https://github.com/uhyo/funstack-ui/issues/96)).
|
|
79
|
+
|
|
31
80
|
- While a tooltip is showing, the next one opens at once ([#21](https://github.com/uhyo/funstack-ui/issues/21)).
|
|
81
|
+
|
|
32
82
|
- **Breaking:** `data-side` / `data-align` on Tooltip, Popover and Menu report the side the browser chose while shown, not the requested one; the `side` type gains `"inline-start"` / `"inline-end"` and `align` start / end mirror under RTL; a submenu opens on the inline-end side (the left in RTL) ([#20](https://github.com/uhyo/funstack-ui/issues/20), [#53](https://github.com/uhyo/funstack-ui/issues/53)).
|
|
83
|
+
|
|
33
84
|
- Every Menu closes on a right- or middle-click outside; a wheel over a menu never scrolls the page ([#45](https://github.com/uhyo/funstack-ui/issues/45), [#88](https://github.com/uhyo/funstack-ui/issues/88)).
|
|
85
|
+
|
|
34
86
|
- `disabled` on a link or component `render` renders `aria-disabled="true"` instead of native `disabled` on Toggle, ToggleGroup.Item, Menu.Trigger, Combobox.Trigger and Clear, NumberField.Increment and Decrement, and the Dialog and Popover Trigger and Close parts where they handle the click; a disabled link ToggleGroup.Item is reached by the arrow keys. Form.Submit keeps native `disabled` ([#83](https://github.com/uhyo/funstack-ui/issues/83)).
|
|
87
|
+
|
|
35
88
|
- `Dialog.Close`, `Popover.Close`, `Menu.Item` and `Toast.Action` ignore a second click while their own action is pending, with `aria-disabled` meanwhile; before, a second click ran the action again ([#81](https://github.com/uhyo/funstack-ui/issues/81)).
|
|
89
|
+
|
|
36
90
|
- **Breaking:** `Toolbar.Button` is removed; use [Button](components/button.md), which behaves the same inside a toolbar ([#79](https://github.com/uhyo/funstack-ui/issues/79)).
|
|
37
91
|
|
|
38
92
|
## Done
|
package/dist/docs/why.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Why FUNSTACK UI
|
|
2
2
|
|
|
3
|
-
React 19 added actions
|
|
3
|
+
React 18 brought transitions and Suspense for data fetching. React 19 added actions and `useOptimistic`, and React 19.3 made `<ViewTransition>` stable. FUNSTACK UI is a headless component library that uses them for you, so the async work around every button, tab and dialog is already done.
|
|
4
|
+
|
|
5
|
+
## <a id="async-react"></a>Built for Async React
|
|
6
|
+
|
|
7
|
+
Async React is the React team's name for using these features together (the [Async React talks at React Conf 2025](https://react.dev/blog/2025/10/16/react-conf-2025-recap)). The idea is good async UX built in: while data loads or a request runs, the screen stays responsive, shows what is pending, and switches to the result when it is ready, without each app wiring that by hand.
|
|
8
|
+
|
|
9
|
+
FUNSTACK UI bets on this idea and is **Async React-native**: the components start the transitions, show optimistic and pending state and wait for Suspense themselves. You get good async UI by using them, without wiring it yourself.
|
|
4
10
|
|
|
5
11
|
## What you stop writing
|
|
6
12
|
|
|
@@ -71,11 +77,9 @@ Most established headless React libraries were designed before React's async fea
|
|
|
71
77
|
| | Typical headless library | FUNSTACK UI |
|
|
72
78
|
| - | - | - |
|
|
73
79
|
| **Callbacks** | Event handlers (`onValueChange`, `onOpenChange`). Transitions, optimistic state and pending flags are yours to add. | [Action props](concepts/action-props.md): run in a transition, may be async. Optimistic and pending state built in. |
|
|
74
|
-
| **Content that loads data** | Usually updated urgently, so content that suspends shows its fallback unless you add a transition. | [Old content stays on screen](concepts/suspense.md) until the new content is ready. |
|
|
75
80
|
| **Popups** | JavaScript for positioning, layering and dismissal, so older browsers work too. | The [platform](concepts/browser-owned-state.md): Popover API, `<dialog>`, CSS Anchor Positioning. Some components work before hydration. |
|
|
76
81
|
| **Animation** | CSS, with exit-animation states built in. No `<ViewTransition>` integration. | CSS, plus `<ViewTransition>` through the parts' `transition` prop ([Transitions](concepts/transitions.md)). |
|
|
77
82
|
| **Browsers** | Wide support, including older versions. | Latest stable Chrome, Edge, Safari and Firefox. No fallbacks. |
|
|
78
|
-
| **Maturity** | Stable APIs, large component sets. | Experimental alpha. APIs change without notice. |
|
|
79
83
|
|
|
80
84
|
## Who it is for
|
|
81
85
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./internal/platform-attributes.mjs";
|
|
2
|
-
import { Action, ActionDetails, ChangeAction, ChangeReason, RenderProp, StateValue, UrgentChangeHandler } from "./internal/types.mjs";
|
|
2
|
+
import { Action, ActionDetails, ChangeAction, ChangeReason, RenderProp, StateValue, UrgentChangeHandler, UrgentHandler, WhilePending } from "./internal/types.mjs";
|
|
3
3
|
import { AccordionItemProps, AccordionItemState } from "./accordion/accordion-item.mjs";
|
|
4
4
|
import { AccordionPanelProps, AccordionPanelState } from "./accordion/accordion-panel.mjs";
|
|
5
5
|
import { AccordionRootExclusiveProps, AccordionRootMultipleProps, AccordionRootProps, AccordionRootState, AccordionValueChangeDetails } from "./accordion/accordion-root.mjs";
|
|
@@ -133,4 +133,4 @@ import { MeterLabelProps } from "./meter/meter-label.mjs";
|
|
|
133
133
|
import { MeterTrackProps } from "./meter/meter-track.mjs";
|
|
134
134
|
import { MeterValueProps } from "./meter/meter-value.mjs";
|
|
135
135
|
import { Meter } from "./meter/index.mjs";
|
|
136
|
-
export { Accordion, type AccordionItemProps, type AccordionItemState, type AccordionPanelProps, type AccordionPanelState, type AccordionRootExclusiveProps, type AccordionRootMultipleProps, type AccordionRootProps, type AccordionRootState, type AccordionTriggerProps, type AccordionTriggerState, type AccordionValueChangeDetails, type Action, type ActionDetails, Button, type ButtonActionDetails, type ButtonProps, type ButtonState, CSPProvider, type CSPProviderProps, type ChangeAction, type ChangeReason, Checkbox, type CheckboxCheckedChangeDetails, CheckboxGroup, type CheckboxGroupItemProps, type CheckboxGroupItemState, type CheckboxGroupLabelProps, type CheckboxGroupParentProps, type CheckboxGroupParentState, type CheckboxGroupRootProps, type CheckboxGroupRootState, type CheckboxGroupValueChangeDetails, type CheckboxProps, type CheckboxState, Combobox, type ComboboxClearProps, type ComboboxClearState, type ComboboxEmptyProps, type ComboboxEmptyState, type ComboboxGroupLabelProps, type ComboboxGroupLabelState, type ComboboxGroupProps, type ComboboxGroupState, type ComboboxInputProps, type ComboboxInputState, type ComboboxInputValueChangeDetails, type ComboboxLabelProps, type ComboboxLabelState, type ComboboxListProps, type ComboboxListState, type ComboboxOpenChangeDetails, type ComboboxOptionProps, type ComboboxOptionState, type ComboboxPopupProps, type ComboboxPopupState, type ComboboxRootProps, type ComboboxRootState, type ComboboxStatusProps, type ComboboxStatusState, type ComboboxTriggerProps, type ComboboxTriggerState, type ComboboxValueChangeDetails, Dialog, type DialogCloseDetails, type DialogCloseProps, type DialogCloseState, type DialogDescriptionProps, type DialogDescriptionState, type DialogFormProps, type DialogFormState, type DialogOpenChangeDetails, type DialogPopupProps, type DialogPopupState, type DialogRootProps, type DialogRootState, type DialogTitleProps, type DialogTitleState, type DialogTriggerProps, type DialogTriggerState, Field, type FieldControlProps, type FieldDescriptionProps, type FieldErrorProps, type FieldErrorValue, type FieldLabelProps, type FieldRootProps, type FieldState, type FieldValidate, type FieldValidity, Form, type FormErrors, type FormRootProps, type FormRootState, type FormSubmitProps, type FormSubmitState, Menu, type MenuAlign, type MenuCheckboxItemProps, type MenuCheckboxItemState, type MenuContextTriggerProps, type MenuContextTriggerState, type MenuGroupLabelProps, type MenuGroupLabelState, type MenuGroupProps, type MenuGroupState, type MenuItemDetails, type MenuItemProps, type MenuItemState, type MenuOpenChangeDetails, type MenuPopupProps, type MenuPopupState, type MenuRadioGroupProps, type MenuRadioGroupState, type MenuRadioItemProps, type MenuRadioItemState, type MenuRootProps, type MenuRootState, type MenuSeparatorProps, type MenuSeparatorState, type MenuSide, type MenuSubmenuTriggerProps, type MenuSubmenuTriggerState, type MenuTriggerProps, type MenuTriggerState, Meter, type MeterIndicatorProps, type MeterLabelProps, type MeterRegion, type MeterRootProps, type MeterState, type MeterTrackProps, type MeterValueProps, NumberField, type NumberFieldButtonState, type NumberFieldDecrementProps, type NumberFieldIncrementProps, type NumberFieldInputProps, type NumberFieldLabelProps, type NumberFieldRootProps, type NumberFieldState, type NumberFieldValueChangeDetails, Popover, type PopoverAlign, type PopoverCloseProps, type PopoverCloseState, type PopoverDescriptionProps, type PopoverDescriptionState, type PopoverOpenChangeDetails, type PopoverPopupProps, type PopoverPopupState, type PopoverRootProps, type PopoverRootState, type PopoverSide, type PopoverTitleProps, type PopoverTitleState, type PopoverTriggerProps, type PopoverTriggerState, Progress, type ProgressIndicatorProps, type ProgressLabelProps, type ProgressRootProps, type ProgressState, type ProgressTrackProps, type ProgressValueProps, RadioGroup, type RadioGroupItemProps, type RadioGroupItemState, type RadioGroupLabelProps, type RadioGroupRootProps, type RadioGroupRootState, type RadioGroupValueChangeDetails, type RenderProp, STYLE_SHA256, Select, type SelectGroupLabelProps, type SelectGroupProps, type SelectOptionProps, type SelectOptionState, type SelectRootProps, type SelectRootState, type SelectSeparatorProps, type SelectTriggerProps, type SelectValueChangeDetails, type SelectValueProps, Slider, type SliderIndicatorProps, type SliderIndicatorState, type SliderLabelProps, type SliderOrientation, type SliderRootProps, type SliderRootState, type SliderThumbProps, type SliderThumbState, type SliderTrackProps, type SliderTrackState, type SliderValue, type SliderValueChangeDetails, type SliderValueCommitDetails, type SliderValueProps, type SliderValueState, type StateValue, Switch, type SwitchCheckedChangeDetails, type SwitchProps, type SwitchState, Tabs, type TabsActivationMode, type TabsIndicatorProps, type TabsIndicatorState, type TabsListProps, type TabsListState, type TabsOrientation, type TabsPanelProps, type TabsPanelState, type TabsRootProps, type TabsRootState, type TabsTabProps, type TabsTabState, type TabsValueChangeDetails, Toast, type ToastActionDetails, type ToastActionOptions, type ToastActionProps, type ToastActionState, type ToastCloseDetails, type ToastCloseProps, type ToastCloseState, type ToastDescriptionProps, type ToastItem, type ToastManager, type ToastOptions, type ToastPriority, type ToastPromiseOptions, type ToastRootProps, type ToastRootState, type ToastTitleProps, type ToastViewportProps, type ToastViewportState, Toggle, ToggleGroup, type ToggleGroupExclusiveProps, type ToggleGroupItemProps, type ToggleGroupItemState, type ToggleGroupMultipleProps, type ToggleGroupOrientation, type ToggleGroupRootProps, type ToggleGroupRootState, type ToggleGroupValueChangeDetails, type TogglePressedChangeDetails, type ToggleProps, type ToggleState, Toolbar, type ToolbarOrientation, type ToolbarRootProps, type ToolbarRootState, type ToolbarSeparatorProps, type ToolbarSeparatorState, Tooltip, type TooltipAlign, type TooltipArrowProps, type TooltipArrowState, type TooltipPopupProps, type TooltipPopupState, type TooltipProvides, type TooltipRootProps, type TooltipRootState, type TooltipSide, type TooltipTriggerProps, type TooltipTriggerState, type UrgentChangeHandler, createToastManager, toast };
|
|
136
|
+
export { Accordion, type AccordionItemProps, type AccordionItemState, type AccordionPanelProps, type AccordionPanelState, type AccordionRootExclusiveProps, type AccordionRootMultipleProps, type AccordionRootProps, type AccordionRootState, type AccordionTriggerProps, type AccordionTriggerState, type AccordionValueChangeDetails, type Action, type ActionDetails, Button, type ButtonActionDetails, type ButtonProps, type ButtonState, CSPProvider, type CSPProviderProps, type ChangeAction, type ChangeReason, Checkbox, type CheckboxCheckedChangeDetails, CheckboxGroup, type CheckboxGroupItemProps, type CheckboxGroupItemState, type CheckboxGroupLabelProps, type CheckboxGroupParentProps, type CheckboxGroupParentState, type CheckboxGroupRootProps, type CheckboxGroupRootState, type CheckboxGroupValueChangeDetails, type CheckboxProps, type CheckboxState, Combobox, type ComboboxClearProps, type ComboboxClearState, type ComboboxEmptyProps, type ComboboxEmptyState, type ComboboxGroupLabelProps, type ComboboxGroupLabelState, type ComboboxGroupProps, type ComboboxGroupState, type ComboboxInputProps, type ComboboxInputState, type ComboboxInputValueChangeDetails, type ComboboxLabelProps, type ComboboxLabelState, type ComboboxListProps, type ComboboxListState, type ComboboxOpenChangeDetails, type ComboboxOptionProps, type ComboboxOptionState, type ComboboxPopupProps, type ComboboxPopupState, type ComboboxRootProps, type ComboboxRootState, type ComboboxStatusProps, type ComboboxStatusState, type ComboboxTriggerProps, type ComboboxTriggerState, type ComboboxValueChangeDetails, Dialog, type DialogCloseDetails, type DialogCloseProps, type DialogCloseState, type DialogDescriptionProps, type DialogDescriptionState, type DialogFormProps, type DialogFormState, type DialogOpenChangeDetails, type DialogPopupProps, type DialogPopupState, type DialogRootProps, type DialogRootState, type DialogTitleProps, type DialogTitleState, type DialogTriggerProps, type DialogTriggerState, Field, type FieldControlProps, type FieldDescriptionProps, type FieldErrorProps, type FieldErrorValue, type FieldLabelProps, type FieldRootProps, type FieldState, type FieldValidate, type FieldValidity, Form, type FormErrors, type FormRootProps, type FormRootState, type FormSubmitProps, type FormSubmitState, Menu, type MenuAlign, type MenuCheckboxItemProps, type MenuCheckboxItemState, type MenuContextTriggerProps, type MenuContextTriggerState, type MenuGroupLabelProps, type MenuGroupLabelState, type MenuGroupProps, type MenuGroupState, type MenuItemDetails, type MenuItemProps, type MenuItemState, type MenuOpenChangeDetails, type MenuPopupProps, type MenuPopupState, type MenuRadioGroupProps, type MenuRadioGroupState, type MenuRadioItemProps, type MenuRadioItemState, type MenuRootProps, type MenuRootState, type MenuSeparatorProps, type MenuSeparatorState, type MenuSide, type MenuSubmenuTriggerProps, type MenuSubmenuTriggerState, type MenuTriggerProps, type MenuTriggerState, Meter, type MeterIndicatorProps, type MeterLabelProps, type MeterRegion, type MeterRootProps, type MeterState, type MeterTrackProps, type MeterValueProps, NumberField, type NumberFieldButtonState, type NumberFieldDecrementProps, type NumberFieldIncrementProps, type NumberFieldInputProps, type NumberFieldLabelProps, type NumberFieldRootProps, type NumberFieldState, type NumberFieldValueChangeDetails, Popover, type PopoverAlign, type PopoverCloseProps, type PopoverCloseState, type PopoverDescriptionProps, type PopoverDescriptionState, type PopoverOpenChangeDetails, type PopoverPopupProps, type PopoverPopupState, type PopoverRootProps, type PopoverRootState, type PopoverSide, type PopoverTitleProps, type PopoverTitleState, type PopoverTriggerProps, type PopoverTriggerState, Progress, type ProgressIndicatorProps, type ProgressLabelProps, type ProgressRootProps, type ProgressState, type ProgressTrackProps, type ProgressValueProps, RadioGroup, type RadioGroupItemProps, type RadioGroupItemState, type RadioGroupLabelProps, type RadioGroupRootProps, type RadioGroupRootState, type RadioGroupValueChangeDetails, type RenderProp, STYLE_SHA256, Select, type SelectGroupLabelProps, type SelectGroupProps, type SelectOptionProps, type SelectOptionState, type SelectRootProps, type SelectRootState, type SelectSeparatorProps, type SelectTriggerProps, type SelectValueChangeDetails, type SelectValueProps, Slider, type SliderIndicatorProps, type SliderIndicatorState, type SliderLabelProps, type SliderOrientation, type SliderRootProps, type SliderRootState, type SliderThumbProps, type SliderThumbState, type SliderTrackProps, type SliderTrackState, type SliderValue, type SliderValueChangeDetails, type SliderValueCommitDetails, type SliderValueProps, type SliderValueState, type StateValue, Switch, type SwitchCheckedChangeDetails, type SwitchProps, type SwitchState, Tabs, type TabsActivationMode, type TabsIndicatorProps, type TabsIndicatorState, type TabsListProps, type TabsListState, type TabsOrientation, type TabsPanelProps, type TabsPanelState, type TabsRootProps, type TabsRootState, type TabsTabProps, type TabsTabState, type TabsValueChangeDetails, Toast, type ToastActionDetails, type ToastActionOptions, type ToastActionProps, type ToastActionState, type ToastCloseDetails, type ToastCloseProps, type ToastCloseState, type ToastDescriptionProps, type ToastItem, type ToastManager, type ToastOptions, type ToastPriority, type ToastPromiseOptions, type ToastRootProps, type ToastRootState, type ToastTitleProps, type ToastViewportProps, type ToastViewportState, Toggle, ToggleGroup, type ToggleGroupExclusiveProps, type ToggleGroupItemProps, type ToggleGroupItemState, type ToggleGroupMultipleProps, type ToggleGroupOrientation, type ToggleGroupRootProps, type ToggleGroupRootState, type ToggleGroupValueChangeDetails, type TogglePressedChangeDetails, type ToggleProps, type ToggleState, Toolbar, type ToolbarOrientation, type ToolbarRootProps, type ToolbarRootState, type ToolbarSeparatorProps, type ToolbarSeparatorState, Tooltip, type TooltipAlign, type TooltipArrowProps, type TooltipArrowState, type TooltipPopupProps, type TooltipPopupState, type TooltipProvides, type TooltipRootProps, type TooltipRootState, type TooltipSide, type TooltipTriggerProps, type TooltipTriggerState, type UrgentChangeHandler, type UrgentHandler, type WhilePending, createToastManager, toast };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/internal/call-urgent-handler.ts
|
|
2
|
+
/** Whether `value` is a thenable (a promise, or anything with a callable `then`). */
|
|
3
|
+
function isThenable(value) {
|
|
4
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Calls an `on*` handler under the rule every handler the library defines follows (conventions
|
|
8
|
+
* 2.1, #148): synchronously, in the caller's event, not awaited and with no pending state. A
|
|
9
|
+
* synchronous throw is caught and passed to `reportError`, so the library's own bookkeeping after
|
|
10
|
+
* the call still runs; a returned thenable gets a rejection handler that passes the reason to
|
|
11
|
+
* `reportError`. Nothing reaches an Error Boundary, and a returned promise is never a warning.
|
|
12
|
+
* Used by `onOpenChange` (the overlay Roots), a toast's `onClose` and Combobox's
|
|
13
|
+
* `onInputValueChange`. A missing handler is a no-op.
|
|
14
|
+
*
|
|
15
|
+
* Directive-free: no client-only API (it does not import `report-dropped.ts`, a client module,
|
|
16
|
+
* and repeats its two-line `reportError` fallback instead).
|
|
17
|
+
*/
|
|
18
|
+
function callUrgentHandler(handler, ...args) {
|
|
19
|
+
if (handler === void 0) return;
|
|
20
|
+
let result;
|
|
21
|
+
try {
|
|
22
|
+
result = handler(...args);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
report(error);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (isThenable(result)) result.then(void 0, report);
|
|
28
|
+
}
|
|
29
|
+
/** `reportError`, or `console.error` where it does not exist (jsdom), as `reportDropped`. */
|
|
30
|
+
function report(error) {
|
|
31
|
+
if (typeof reportError === "function") reportError(error);
|
|
32
|
+
else console.error(error);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { callUrgentHandler };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=call-urgent-handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-urgent-handler.mjs","names":[],"sources":["../../src/internal/call-urgent-handler.ts"],"sourcesContent":["/** Whether `value` is a thenable (a promise, or anything with a callable `then`). */\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === \"object\" || typeof value === \"function\") &&\n value !== null &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\n/**\n * Calls an `on*` handler under the rule every handler the library defines follows (conventions\n * 2.1, #148): synchronously, in the caller's event, not awaited and with no pending state. A\n * synchronous throw is caught and passed to `reportError`, so the library's own bookkeeping after\n * the call still runs; a returned thenable gets a rejection handler that passes the reason to\n * `reportError`. Nothing reaches an Error Boundary, and a returned promise is never a warning.\n * Used by `onOpenChange` (the overlay Roots), a toast's `onClose` and Combobox's\n * `onInputValueChange`. A missing handler is a no-op.\n *\n * Directive-free: no client-only API (it does not import `report-dropped.ts`, a client module,\n * and repeats its two-line `reportError` fallback instead).\n */\nexport function callUrgentHandler<Args extends readonly unknown[]>(\n handler: ((...args: Args) => unknown) | undefined,\n ...args: Args\n): void {\n if (handler === undefined) return;\n let result: unknown;\n try {\n result = handler(...args);\n } catch (error) {\n report(error);\n return;\n }\n if (isThenable(result)) result.then(undefined, report);\n}\n\n/** `reportError`, or `console.error` where it does not exist (jsdom), as `reportDropped`. */\nfunction report(error: unknown): void {\n if (typeof reportError === \"function\") reportError(error);\n else console.error(error);\n}\n"],"mappings":";;AACA,SAAS,WAAW,OAA+C;CACjE,QACG,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,UAAU,QACV,OAAQ,MAA6B,SAAS;AAElD;;;;;;;;;;;;;AAcA,SAAgB,kBACd,SACA,GAAG,MACG;CACN,IAAI,YAAY,KAAA,GAAW;CAC3B,IAAI;CACJ,IAAI;EACF,SAAS,QAAQ,GAAG,IAAI;CAC1B,SAAS,OAAO;EACd,OAAO,KAAK;EACZ;CACF;CACA,IAAI,WAAW,MAAM,GAAG,OAAO,KAAK,KAAA,GAAW,MAAM;AACvD;;AAGA,SAAS,OAAO,OAAsB;CACpC,IAAI,OAAO,gBAAgB,YAAY,YAAY,KAAK;MACnD,QAAQ,MAAM,KAAK;AAC1B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/internal/css-transition-cut.ts
|
|
2
|
+
/** What `transition: none` sets, each restored on its own. */
|
|
3
|
+
const LONGHANDS = [
|
|
4
|
+
"transition-property",
|
|
5
|
+
"transition-duration",
|
|
6
|
+
"transition-timing-function",
|
|
7
|
+
"transition-delay",
|
|
8
|
+
"transition-behavior"
|
|
9
|
+
];
|
|
10
|
+
/** Elements inside a cut right now: a nested call (Menu's `reshow`) runs inside the outer one. */
|
|
11
|
+
const cutting = /* @__PURE__ */ new WeakSet();
|
|
12
|
+
/** Whether a document view transition is running (`html:active-view-transition`). */
|
|
13
|
+
function viewTransitionActive(element) {
|
|
14
|
+
try {
|
|
15
|
+
return element.ownerDocument.documentElement.matches(":active-view-transition");
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Runs the library's own show or hide of a popup (`showPopover()`, `hidePopover()`,
|
|
22
|
+
* `showModal()`, `show()`, `close()`) with the popup's CSS transitions cut, when the Popup has a
|
|
23
|
+
* `transition` prop and a view transition is running (conventions 5.1, issue #147). The view
|
|
24
|
+
* transition animates that show or hide; a CSS `transition` on the popup would run next to it
|
|
25
|
+
* (the open's `@starting-style` enter under the view transition's enter; in Chromium the close's
|
|
26
|
+
* `display` / `overlay` fade keeps the hidden box in the new snapshot, a double image).
|
|
27
|
+
*
|
|
28
|
+
* One synchronous step: an inline `transition: none !important`, the call, a forced style
|
|
29
|
+
* recalculation (without it Chromium sees the restored value and the fade runs), and the inline
|
|
30
|
+
* `transition` longhands restored as they were, so nothing is left for React's `style` diffing.
|
|
31
|
+
* Everything goes through CSSOM, never the `style` attribute: a CSP without `'unsafe-inline'`
|
|
32
|
+
* for styles blocks an attribute write (React's `style` prop is CSSOM too). Only CSS
|
|
33
|
+
* transitions are cut, not a `@keyframes` animation. Dismissals (Escape, light dismiss) never
|
|
34
|
+
* come here: their CSS exit plays.
|
|
35
|
+
*/
|
|
36
|
+
function withCssTransitionCut(element, hasTransition, run) {
|
|
37
|
+
if (!hasTransition || cutting.has(element) || !viewTransitionActive(element)) return run();
|
|
38
|
+
const { style } = element;
|
|
39
|
+
const hadAttribute = element.hasAttribute("style");
|
|
40
|
+
const shorthand = style.getPropertyValue("transition");
|
|
41
|
+
const shorthandPriority = style.getPropertyPriority("transition");
|
|
42
|
+
const longhands = LONGHANDS.map((name) => [
|
|
43
|
+
name,
|
|
44
|
+
style.getPropertyValue(name),
|
|
45
|
+
style.getPropertyPriority(name)
|
|
46
|
+
]);
|
|
47
|
+
cutting.add(element);
|
|
48
|
+
style.setProperty("transition", "none", "important");
|
|
49
|
+
try {
|
|
50
|
+
return run();
|
|
51
|
+
} finally {
|
|
52
|
+
getComputedStyle(element).opacity;
|
|
53
|
+
const ours = (name) => style.getPropertyValue(name) === "none" && style.getPropertyPriority(name) === "important";
|
|
54
|
+
if (ours("transition-property") || ours("transition")) {
|
|
55
|
+
style.removeProperty("transition");
|
|
56
|
+
if (shorthand !== "") style.setProperty("transition", shorthand, shorthandPriority);
|
|
57
|
+
else for (const [name, value, priority] of longhands) if (value !== "") style.setProperty(name, value, priority);
|
|
58
|
+
}
|
|
59
|
+
if (!hadAttribute && style.length === 0) element.removeAttribute("style");
|
|
60
|
+
cutting.delete(element);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { withCssTransitionCut };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=css-transition-cut.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-transition-cut.mjs","names":[],"sources":["../../src/internal/css-transition-cut.ts"],"sourcesContent":["// No directive: a DOM helper (conventions 7.1).\n\n/** What `transition: none` sets, each restored on its own. */\nconst LONGHANDS = [\n \"transition-property\",\n \"transition-duration\",\n \"transition-timing-function\",\n \"transition-delay\",\n \"transition-behavior\",\n] as const;\n\n/** Elements inside a cut right now: a nested call (Menu's `reshow`) runs inside the outer one. */\nconst cutting = new WeakSet<HTMLElement>();\n\n/** Whether a document view transition is running (`html:active-view-transition`). */\nfunction viewTransitionActive(element: HTMLElement): boolean {\n try {\n return element.ownerDocument.documentElement.matches(\":active-view-transition\");\n } catch {\n // An engine (or jsdom) that does not know the pseudo-class has no view transition to avoid.\n return false;\n }\n}\n\n/**\n * Runs the library's own show or hide of a popup (`showPopover()`, `hidePopover()`,\n * `showModal()`, `show()`, `close()`) with the popup's CSS transitions cut, when the Popup has a\n * `transition` prop and a view transition is running (conventions 5.1, issue #147). The view\n * transition animates that show or hide; a CSS `transition` on the popup would run next to it\n * (the open's `@starting-style` enter under the view transition's enter; in Chromium the close's\n * `display` / `overlay` fade keeps the hidden box in the new snapshot, a double image).\n *\n * One synchronous step: an inline `transition: none !important`, the call, a forced style\n * recalculation (without it Chromium sees the restored value and the fade runs), and the inline\n * `transition` longhands restored as they were, so nothing is left for React's `style` diffing.\n * Everything goes through CSSOM, never the `style` attribute: a CSP without `'unsafe-inline'`\n * for styles blocks an attribute write (React's `style` prop is CSSOM too). Only CSS\n * transitions are cut, not a `@keyframes` animation. Dismissals (Escape, light dismiss) never\n * come here: their CSS exit plays.\n */\nexport function withCssTransitionCut<T>(\n element: HTMLElement,\n hasTransition: boolean,\n run: () => T,\n): T {\n if (!hasTransition || cutting.has(element) || !viewTransitionActive(element)) return run();\n const { style } = element;\n const hadAttribute = element.hasAttribute(\"style\");\n // The shorthand, and the longhands for a consumer who set only some of them (the shorthand\n // then reads as \"\").\n const shorthand = style.getPropertyValue(\"transition\");\n const shorthandPriority = style.getPropertyPriority(\"transition\");\n const longhands = LONGHANDS.map(\n (name) => [name, style.getPropertyValue(name), style.getPropertyPriority(name)] as const,\n );\n cutting.add(element);\n style.setProperty(\"transition\", \"none\", \"important\");\n try {\n return run();\n } finally {\n // The show or hide's style change is processed while the cut is in place.\n void getComputedStyle(element).opacity;\n // Only while the cut is still ours: a listener inside the call that wrote its own\n // `transition` keeps it.\n const ours = (name: string) =>\n style.getPropertyValue(name) === \"none\" && style.getPropertyPriority(name) === \"important\";\n if (ours(\"transition-property\") || ours(\"transition\")) {\n style.removeProperty(\"transition\");\n if (shorthand !== \"\") {\n style.setProperty(\"transition\", shorthand, shorthandPriority);\n } else {\n for (const [name, value, priority] of longhands) {\n if (value !== \"\") style.setProperty(name, value, priority);\n }\n }\n }\n // `removeAttribute` parses nothing, so CSP does not block it.\n if (!hadAttribute && style.length === 0) element.removeAttribute(\"style\");\n cutting.delete(element);\n }\n}\n"],"mappings":";;AAGA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,0BAAU,IAAI,QAAqB;;AAGzC,SAAS,qBAAqB,SAA+B;CAC3D,IAAI;EACF,OAAO,QAAQ,cAAc,gBAAgB,QAAQ,yBAAyB;CAChF,QAAQ;EAEN,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,qBACd,SACA,eACA,KACG;CACH,IAAI,CAAC,iBAAiB,QAAQ,IAAI,OAAO,KAAK,CAAC,qBAAqB,OAAO,GAAG,OAAO,IAAI;CACzF,MAAM,EAAE,UAAU;CAClB,MAAM,eAAe,QAAQ,aAAa,OAAO;CAGjD,MAAM,YAAY,MAAM,iBAAiB,YAAY;CACrD,MAAM,oBAAoB,MAAM,oBAAoB,YAAY;CAChE,MAAM,YAAY,UAAU,KACzB,SAAS;EAAC;EAAM,MAAM,iBAAiB,IAAI;EAAG,MAAM,oBAAoB,IAAI;CAAC,CAChF;CACA,QAAQ,IAAI,OAAO;CACnB,MAAM,YAAY,cAAc,QAAQ,WAAW;CACnD,IAAI;EACF,OAAO,IAAI;CACb,UAAU;EAER,iBAAsB,OAAO,CAAC,CAAC;EAG/B,MAAM,QAAQ,SACZ,MAAM,iBAAiB,IAAI,MAAM,UAAU,MAAM,oBAAoB,IAAI,MAAM;EACjF,IAAI,KAAK,qBAAqB,KAAK,KAAK,YAAY,GAAG;GACrD,MAAM,eAAe,YAAY;GACjC,IAAI,cAAc,IAChB,MAAM,YAAY,cAAc,WAAW,iBAAiB;QAE5D,KAAK,MAAM,CAAC,MAAM,OAAO,aAAa,WACpC,IAAI,UAAU,IAAI,MAAM,YAAY,MAAM,OAAO,QAAQ;EAG/D;EAEA,IAAI,CAAC,gBAAgB,MAAM,WAAW,GAAG,QAAQ,gBAAgB,OAAO;EACxE,QAAQ,OAAO,OAAO;CACxB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-popup.mjs","names":[],"sources":["../../src/internal/overlay-popup.tsx"],"sourcesContent":["\"use client\";\n// The pieces Dialog.Popup shares with usePopoverPopup (Popover, Menu, Combobox). The two stay\n// separate: Dialog has showModal / show, `close` / `cancel` / `submit` and light dismiss.\nimport { Activity, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject, ViewTransitionClass } from \"react\";\nimport { ToolbarContext } from \"./toolbar-context.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport { useExitAnimation } from \"./use-exit-animation.js\";\nimport type { ExitAnimation } from \"./use-exit-animation.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface OverlayContentOptions {\n readonly isLibrary: boolean;\n readonly keepMounted: boolean | undefined;\n /** Committed open, or held while the exit animates (design/components/popover.md 4.4). */\n readonly visible: boolean;\n readonly wrapContent: (children: ReactNode) => ReactNode;\n}\n\n/**\n * The children of a popup (Popover, Dialog, Menu, Combobox). JS-free mode: always rendered.\n * Library mode: rendered while `visible`, or with `keepMounted` inside an `<Activity>` whose mode\n * changes with committed state, inside the Root's transition (conventions 5.5). The content is\n * not part of an enclosing Toolbar's sequence (the engine excludes `[popover]` and `dialog`), so\n * parts inside it see no Toolbar. `children` is called only when rendered.\n */\nexport function renderOverlayContent(\n { isLibrary, keepMounted, visible, wrapContent }: OverlayContentOptions,\n children: () => ReactNode,\n): ReactNode {\n let node: ReactNode;\n if (!isLibrary) {\n node = children();\n } else if (keepMounted === true) {\n node = <Activity mode={visible ? \"visible\" : \"hidden\"}>{wrapContent(children())}</Activity>;\n } else {\n node = visible ? wrapContent(children()) : null;\n }\n return <ToolbarContext value={null}>{node}</ToolbarContext>;\n}\n\nexport interface CloseHold extends ExitAnimation {\n /**\n * The close's native event (`toggle` / `close`) arrived: hold the content until the exit\n * animations settle, or release a hold now when nothing animates (Firefox, or no CSS exit: the\n * popup is already `display: none`, the commit is invisible). Call before the
|
|
1
|
+
{"version":3,"file":"overlay-popup.mjs","names":[],"sources":["../../src/internal/overlay-popup.tsx"],"sourcesContent":["\"use client\";\n// The pieces Dialog.Popup shares with usePopoverPopup (Popover, Menu, Combobox). The two stay\n// separate: Dialog has showModal / show, `close` / `cancel` / `submit` and light dismiss.\nimport { Activity, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject, ViewTransitionClass } from \"react\";\nimport { ToolbarContext } from \"./toolbar-context.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport { useExitAnimation } from \"./use-exit-animation.js\";\nimport type { ExitAnimation } from \"./use-exit-animation.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface OverlayContentOptions {\n readonly isLibrary: boolean;\n readonly keepMounted: boolean | undefined;\n /** Committed open, or held while the exit animates (design/components/popover.md 4.4). */\n readonly visible: boolean;\n readonly wrapContent: (children: ReactNode) => ReactNode;\n}\n\n/**\n * The children of a popup (Popover, Dialog, Menu, Combobox). JS-free mode: always rendered.\n * Library mode: rendered while `visible`, or with `keepMounted` inside an `<Activity>` whose mode\n * changes with committed state, inside the Root's transition (conventions 5.5). The content is\n * not part of an enclosing Toolbar's sequence (the engine excludes `[popover]` and `dialog`), so\n * parts inside it see no Toolbar. `children` is called only when rendered.\n */\nexport function renderOverlayContent(\n { isLibrary, keepMounted, visible, wrapContent }: OverlayContentOptions,\n children: () => ReactNode,\n): ReactNode {\n let node: ReactNode;\n if (!isLibrary) {\n node = children();\n } else if (keepMounted === true) {\n node = <Activity mode={visible ? \"visible\" : \"hidden\"}>{wrapContent(children())}</Activity>;\n } else {\n node = visible ? wrapContent(children()) : null;\n }\n return <ToolbarContext value={null}>{node}</ToolbarContext>;\n}\n\nexport interface CloseHold extends ExitAnimation {\n /**\n * The close's native event (`toggle` / `close`) arrived: hold the content until the exit\n * animations settle, or release a hold now when nothing animates (Firefox, or no CSS exit: the\n * popup is already `display: none`, the commit is invisible). Call before reporting the fact,\n * so its commit keeps the children. Nothing for the library's own close (`echo`) with\n * `transition`: the close commit's view transition carried the content out.\n */\n readonly afterClose: (popup: Element, echo: boolean) => void;\n /**\n * The apply effect's release rule: a hold the close commit set (or a fact's commit) that no\n * exit animation is going to release, the popup being hidden and its close event handled.\n */\n readonly releaseIfIdle: (committed: boolean, awaitingClose: boolean, shown: boolean) => void;\n}\n\n/**\n * `held` for a popup (design/components/popover.md 4.4): the children stay mounted while the\n * close animates. A library-driven close commits `false` first and hides in the layout effect,\n * so without `transition` the children are held through the close commit (\"previous value in\n * state\"). With `transition` the close commit unmounts them inside the view transition, whose old\n * snapshot carries the content out.\n */\nexport function useCloseHold(\n committed: boolean,\n isLibrary: boolean,\n transition: ViewTransitionClass | undefined,\n): CloseHold {\n const exit = useExitAnimation();\n const [prevCommitted, setPrevCommitted] = useState(committed);\n if (prevCommitted !== committed) {\n setPrevCommitted(committed);\n if (isLibrary && prevCommitted && transition === undefined) exit.holdDuringRender();\n }\n return {\n ...exit,\n afterClose: (popup, echo) => {\n if (echo && transition !== undefined) return;\n const animations = exit.exitAnimations(popup);\n if (animations.length > 0) exit.holdUntil(animations);\n else exit.release();\n },\n releaseIfIdle: (isCommitted, awaitingClose, shown) => {\n if (exit.held && !isCommitted && !exit.waiting() && !awaitingClose && !shown) {\n exit.release();\n }\n },\n };\n}\n\n/** The lower-cased `command` of a `command` event. */\nexport function commandOf(event: Event): string {\n return String((event as Event & { command?: string }).command ?? \"\").toLowerCase();\n}\n\n/** Resolves `initialFocus` against the popup (a ref, or a selector inside the popup). */\nexport function resolveInitialFocus(\n popup: HTMLElement,\n initialFocus: RefObject<HTMLElement | null> | string,\n): HTMLElement | null {\n if (typeof initialFocus === \"string\") return popup.querySelector<HTMLElement>(initialFocus);\n return initialFocus.current;\n}\n\nexport type InitialFocusTarget = (\n popup: HTMLElement,\n initialFocus: RefObject<HTMLElement | null> | string | undefined,\n) => HTMLElement | null;\n\n/**\n * `initialFocus` resolved right before a library open (design 6.1): the target, or `null` (the\n * platform picks) without one, or when it resolves to nothing or outside the popup; those two\n * warn once per instance in development. `noun` names the popup in the warning.\n */\nexport function useInitialFocusTarget(part: string, noun: string): InitialFocusTarget {\n const warned = useRef(false);\n return (popup, initialFocus) => {\n if (initialFocus === undefined) return null;\n const target = resolveInitialFocus(popup, initialFocus);\n if (target !== null && popup.contains(target)) return target;\n if (isDev && !warned.current) {\n warned.current = true;\n console.error(\n target === null\n ? `${part}: \\`initialFocus\\` resolved to no element; the platform picks the focus target.`\n : `${part}: \\`initialFocus\\` is outside the ${noun}; the platform picks the focus target.`,\n );\n }\n return null;\n };\n}\n\n/**\n * Design 6.2 rule 2, after a close that began with focus inside (or whose commit unmounted the\n * focused content): when focus is now on `<body>` or still inside the hidden popup, focus the\n * Trigger (connected, and `canFocus` when given), else blur what holds focus.\n */\nexport function returnFocusToTrigger(\n popup: HTMLElement,\n trigger: HTMLElement | null,\n canFocus?: (trigger: HTMLElement) => boolean,\n): void {\n const doc = popup.ownerDocument;\n const active = doc.activeElement;\n if (active !== null && active !== doc.body && !popup.contains(active)) return;\n if (trigger !== null && trigger.isConnected && (canFocus === undefined || canFocus(trigger))) {\n trigger.focus();\n } else if (active instanceof HTMLElement && active !== doc.body) {\n active.blur();\n }\n}\n\n/** The development warnings for a Popup's library-only props in JS-free mode. */\nexport function useJsFreePropWarnings(\n part: string,\n noun: string,\n isLibrary: boolean,\n transition: ViewTransitionClass | undefined,\n keepMounted: boolean | undefined,\n): void {\n useDevWarning(\n !isLibrary && transition !== undefined,\n isDev &&\n `${part}: \\`transition\\` has no effect in JS-free mode; the browser opens and closes the ` +\n `${noun} outside any React transition. Animate it with CSS (\\`@starting-style\\`).`,\n );\n useDevWarning(\n !isLibrary && keepMounted === false,\n isDev &&\n `${part}: \\`keepMounted={false}\\` cannot be honoured in JS-free mode; the content is ` +\n \"always mounted so that the server HTML is complete.\",\n );\n}\n"],"mappings":";;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;AAiBvC,SAAgB,qBACd,EAAE,WAAW,aAAa,SAAS,eACnC,UACW;CACX,IAAI;CACJ,IAAI,CAAC,WACH,OAAO,SAAS;MACX,IAAI,gBAAgB,MACzB,OAAO,oBAAC,UAAD;EAAU,MAAM,UAAU,YAAY;EAAW,UAAA,YAAY,SAAS,CAAC;CAAY,CAAA;MAE1F,OAAO,UAAU,YAAY,SAAS,CAAC,IAAI;CAE7C,OAAO,oBAAC,gBAAD;EAAgB,OAAO;EAAO,UAAA;CAAqB,CAAA;AAC5D;;;;;;;;AAyBA,SAAgB,aACd,WACA,WACA,YACW;CACX,MAAM,OAAO,iBAAiB;CAC9B,MAAM,CAAC,eAAe,oBAAoB,SAAS,SAAS;CAC5D,IAAI,kBAAkB,WAAW;EAC/B,iBAAiB,SAAS;EAC1B,IAAI,aAAa,iBAAiB,eAAe,KAAA,GAAW,KAAK,iBAAiB;CACpF;CACA,OAAO;EACL,GAAG;EACH,aAAa,OAAO,SAAS;GAC3B,IAAI,QAAQ,eAAe,KAAA,GAAW;GACtC,MAAM,aAAa,KAAK,eAAe,KAAK;GAC5C,IAAI,WAAW,SAAS,GAAG,KAAK,UAAU,UAAU;QAC/C,KAAK,QAAQ;EACpB;EACA,gBAAgB,aAAa,eAAe,UAAU;GACpD,IAAI,KAAK,QAAQ,CAAC,eAAe,CAAC,KAAK,QAAQ,KAAK,CAAC,iBAAiB,CAAC,OACrE,KAAK,QAAQ;EAEjB;CACF;AACF;;AAGA,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAQ,MAAuC,WAAW,EAAE,CAAC,CAAC,YAAY;AACnF;;AAGA,SAAgB,oBACd,OACA,cACoB;CACpB,IAAI,OAAO,iBAAiB,UAAU,OAAO,MAAM,cAA2B,YAAY;CAC1F,OAAO,aAAa;AACtB;;;;;;AAYA,SAAgB,sBAAsB,MAAc,MAAkC;CACpF,MAAM,SAAS,OAAO,KAAK;CAC3B,QAAQ,OAAO,iBAAiB;EAC9B,IAAI,iBAAiB,KAAA,GAAW,OAAO;EACvC,MAAM,SAAS,oBAAoB,OAAO,YAAY;EACtD,IAAI,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG,OAAO;EACtD,IAAI,SAAS,CAAC,OAAO,SAAS;GAC5B,OAAO,UAAU;GACjB,QAAQ,MACN,WAAW,OACP,GAAG,KAAK,mFACR,GAAG,KAAK,oCAAoC,KAAK,uCACvD;EACF;EACA,OAAO;CACT;AACF;;;;;;AAOA,SAAgB,qBACd,OACA,SACA,UACM;CACN,MAAM,MAAM,MAAM;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,WAAW,QAAQ,WAAW,IAAI,QAAQ,CAAC,MAAM,SAAS,MAAM,GAAG;CACvE,IAAI,YAAY,QAAQ,QAAQ,gBAAgB,aAAa,KAAA,KAAa,SAAS,OAAO,IACxF,QAAQ,MAAM;MACT,IAAI,kBAAkB,eAAe,WAAW,IAAI,MACzD,OAAO,KAAK;AAEhB;;AAGA,SAAgB,sBACd,MACA,MACA,WACA,YACA,aACM;CACN,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,SACE,GAAG,KAAK,mFACH,KAAK,0EACd;CACA,cACE,CAAC,aAAa,gBAAgB,OAC9B,SACE,GAAG,KAAK,iIAEZ;AACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLayoutEffect, useRef } from "react";
|
|
3
|
+
//#region src/internal/report-dropped.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reports an action rejection that React would drop (conventions 2.4), for `useControllableAction`
|
|
6
|
+
* and `useActionTrigger`. React routes a transition's rejection only by unwrapping the newest
|
|
7
|
+
* thenable of a `useTransition` in a render of the component that owns it, so two rejections reach
|
|
8
|
+
* no Error Boundary:
|
|
9
|
+
*
|
|
10
|
+
* - a **superseded** run's (a later run of the same hook replaced its thenable), and
|
|
11
|
+
* - the **latest** run's once the owner is **gone**: unmounted, or hidden (a consumer's
|
|
12
|
+
* `<Activity>`, the library's `keepMounted` overlays in `overlay-popup.tsx`, Toast's Suspense
|
|
13
|
+
* guard, any Suspense boundary showing its fallback): no render reads it (#152). Hidden counts
|
|
14
|
+
* as gone: the rejection is reported once and does not reach the boundary on re-show, where
|
|
15
|
+
* React would deliver it (a deliberate deviation, conventions resolved question 43).
|
|
16
|
+
*
|
|
17
|
+
* The library passes them to the global `reportError` instead, as React's standalone
|
|
18
|
+
* `startTransition` does with every rejection: a window `error` event, seen by monitoring tools
|
|
19
|
+
* and by test runners, while the UI stays up. `console.error` where there is no `reportError`.
|
|
20
|
+
*/
|
|
21
|
+
function reportDropped(error) {
|
|
22
|
+
if (typeof reportError === "function") reportError(error);
|
|
23
|
+
else console.error(error);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether the calling component's effects are connected: `true` from its mount layout effect until
|
|
27
|
+
* that effect is cleaned up, which happens on unmount, when an `<Activity>` hides it (`keepMounted`
|
|
28
|
+
* included) and when a Suspense boundary above it re-suspends and shows its fallback. Read from
|
|
29
|
+
* action continuations only, to decide between rethrowing a latest rejection (React routes it to
|
|
30
|
+
* the boundary) and `reportDropped`.
|
|
31
|
+
*/
|
|
32
|
+
function useConnected() {
|
|
33
|
+
const connected = useRef(false);
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
connected.current = true;
|
|
36
|
+
return () => {
|
|
37
|
+
connected.current = false;
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
return connected;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { reportDropped, useConnected };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=report-dropped.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-dropped.mjs","names":[],"sources":["../../src/internal/report-dropped.ts"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\n/**\n * Reports an action rejection that React would drop (conventions 2.4), for `useControllableAction`\n * and `useActionTrigger`. React routes a transition's rejection only by unwrapping the newest\n * thenable of a `useTransition` in a render of the component that owns it, so two rejections reach\n * no Error Boundary:\n *\n * - a **superseded** run's (a later run of the same hook replaced its thenable), and\n * - the **latest** run's once the owner is **gone**: unmounted, or hidden (a consumer's\n * `<Activity>`, the library's `keepMounted` overlays in `overlay-popup.tsx`, Toast's Suspense\n * guard, any Suspense boundary showing its fallback): no render reads it (#152). Hidden counts\n * as gone: the rejection is reported once and does not reach the boundary on re-show, where\n * React would deliver it (a deliberate deviation, conventions resolved question 43).\n *\n * The library passes them to the global `reportError` instead, as React's standalone\n * `startTransition` does with every rejection: a window `error` event, seen by monitoring tools\n * and by test runners, while the UI stays up. `console.error` where there is no `reportError`.\n */\nexport function reportDropped(error: unknown): void {\n if (typeof reportError === \"function\") reportError(error);\n else console.error(error);\n}\n\n/**\n * Whether the calling component's effects are connected: `true` from its mount layout effect until\n * that effect is cleaned up, which happens on unmount, when an `<Activity>` hides it (`keepMounted`\n * included) and when a Suspense boundary above it re-suspends and shows its fallback. Read from\n * action continuations only, to decide between rethrowing a latest rejection (React routes it to\n * the boundary) and `reportDropped`.\n */\nexport function useConnected(): RefObject<boolean> {\n const connected = useRef(false);\n useLayoutEffect(() => {\n connected.current = true;\n return () => {\n connected.current = false;\n };\n }, []);\n return connected;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,cAAc,OAAsB;CAClD,IAAI,OAAO,gBAAgB,YAAY,YAAY,KAAK;MACnD,QAAQ,MAAM,KAAK;AAC1B;;;;;;;;AASA,SAAgB,eAAmC;CACjD,MAAM,YAAY,OAAO,KAAK;CAC9B,sBAAsB;EACpB,UAAU,UAAU;EACpB,aAAa;GACX,UAAU,UAAU;EACtB;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
|
|
@@ -19,13 +19,23 @@ export interface ActionDetails {
|
|
|
19
19
|
/** An action called with the next value of a controllable state. */
|
|
20
20
|
export type ChangeAction<T, Details extends ActionDetails = ActionDetails> = Action<[next: T, details: Details]>;
|
|
21
21
|
/**
|
|
22
|
-
* A change **handler
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `(next) =>
|
|
26
|
-
*
|
|
22
|
+
* A change **handler**: the library reports a fact about a state, a change it could not hold
|
|
23
|
+
* (conventions 2.1, the handler rule; #96, #148). Called synchronously in the event that reports
|
|
24
|
+
* it, outside any Transition, and not awaited: nothing is pending or optimistic for it, so
|
|
25
|
+
* `(next) => setOpen(next)` is an urgent update. Used by Combobox's `onInputValueChange` (the
|
|
26
|
+
* text of a controlled input) and the overlay Roots' `onOpenChange` (a dismissal). Not an action.
|
|
27
|
+
*
|
|
28
|
+
* It may return a promise (an `async` function, a Server Function): a rejection, like a
|
|
29
|
+
* synchronous throw, is passed to `reportError`. Nothing reaches an Error Boundary and nothing
|
|
30
|
+
* warns.
|
|
27
31
|
*/
|
|
28
32
|
export type UrgentChangeHandler<T, Details extends ActionDetails = ActionDetails> = (next: T, details: Details) => void;
|
|
33
|
+
/**
|
|
34
|
+
* A handler for a fact that carries no state (a toast's `onClose`). Same rule as
|
|
35
|
+
* `UrgentChangeHandler`: synchronous, outside any Transition, not awaited; a returned promise's
|
|
36
|
+
* rejection or a synchronous throw goes to `reportError`.
|
|
37
|
+
*/
|
|
38
|
+
export type UrgentHandler<Details extends ActionDetails = ActionDetails> = (details: Details) => void;
|
|
29
39
|
/**
|
|
30
40
|
* Why a change action was dispatched (conventions 2.2). One library-wide vocabulary: every
|
|
31
41
|
* `<Component><State>ChangeDetails` that exposes `reason` declares it with this type.
|
|
@@ -33,14 +43,30 @@ export type UrgentChangeHandler<T, Details extends ActionDetails = ActionDetails
|
|
|
33
43
|
* - `"activate"`: the user acted on a trigger part (click, Enter/Space, label click, focus in an
|
|
34
44
|
* automatic-activation mode). `details.event` is the native event.
|
|
35
45
|
* - `"dismiss"`: the user closed the component without acting on one of its parts: Escape,
|
|
36
|
-
* Android back, an assistive-technology dismiss gesture, or a click outside (light dismiss)
|
|
37
|
-
*
|
|
46
|
+
* Android back, an assistive-technology dismiss gesture, or a click outside (light dismiss);
|
|
47
|
+
* also a close nobody caused through the component (script, another top-layer element, focus
|
|
48
|
+
* leaving). `details.event` is the platform's `close` or `toggle` event. On an overlay Root most
|
|
49
|
+
* such closes are facts, reported to `onOpenChange`, not to `openChangeAction` (#148).
|
|
38
50
|
* - `"platform"`: the browser changed the state itself: find-in-page, a form reset (`event` is
|
|
39
51
|
* the `reset` event), or interaction before hydration found at mount (`event` is `undefined`).
|
|
40
52
|
* - `"timeout"`: the library's own timer closed the component; no user gesture and no platform
|
|
41
53
|
* event (`event` is `undefined`). Toast's auto-dismiss is the only user.
|
|
42
54
|
*/
|
|
43
55
|
export type ChangeReason = "activate" | "dismiss" | "platform" | "timeout";
|
|
56
|
+
/**
|
|
57
|
+
* What a pure trigger (`Button`, `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`)
|
|
58
|
+
* does with an activation that arrives while its own action is pending (conventions 2.5.1):
|
|
59
|
+
*
|
|
60
|
+
* - `"run"`: the activation runs the action again, in the same transition; the part shows
|
|
61
|
+
* `data-pending` until every run has settled and is never `aria-disabled` because of pending.
|
|
62
|
+
* - `"ignore"`: the activation starts nothing and its default action (a link's navigation, a
|
|
63
|
+
* form submission, a command) is cancelled; the part renders `aria-disabled="true"` while
|
|
64
|
+
* pending.
|
|
65
|
+
*
|
|
66
|
+
* The default depends on the part: `"run"` where the action is the user's alone (`Button`),
|
|
67
|
+
* `"ignore"` where the library closes something after it (a Close part, a closing menu item).
|
|
68
|
+
*/
|
|
69
|
+
export type WhilePending = "run" | "ignore";
|
|
44
70
|
/** A prop value that is either a plain value or a function of the part's state. */
|
|
45
71
|
export type StateValue<T, State> = T | ((state: State) => T);
|
|
46
72
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internal/types.ts"],"mappings":";;;YAGY;;;;;;;YAQA,OAAO,4CAA4C,MAAM;;;;iBAKpD;;WAEN,OAAO;;;YAIN,aAAa,GAAG,gBAAgB,gBAAgB,iBAAiB,QAC1E,MAAM,GAAG,SAAS
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internal/types.ts"],"mappings":";;;YAGY;;;;;;;YAQA,OAAO,4CAA4C,MAAM;;;;iBAKpD;;WAEN,OAAO;;;YAIN,aAAa,GAAG,gBAAgB,gBAAgB,iBAAiB,QAC1E,MAAM,GAAG,SAAS;;;;;;;;;;;;YAcT,oBAAoB,GAAG,gBAAgB,gBAAgB,kBACjE,MAAM,GACN,SAAS;;;;;;YAQC,cAAc,gBAAgB,gBAAgB,kBACxD,SAAS;;;;;;;;;;;;;;;;;YAmBC;;;;;;;;;;;;;;YAeA;;YAGA,WAAW,GAAG,SAAS,MAAM,OAAO,UAAU;;;;;;YAO9C,WAAW,OAAO,SAC1B,aAAa,QAAQ,YACnB,OAAO,OAAO,OAAO,UAAU"}
|
|
@@ -1,42 +1,57 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { reportDropped, useConnected } from "./report-dropped.mjs";
|
|
3
3
|
import { useRef, useTransition } from "react";
|
|
4
4
|
//#region src/internal/use-action-trigger.ts
|
|
5
5
|
/**
|
|
6
6
|
* The transition of a pure-trigger part: an `action` with no state of its own (`Button`,
|
|
7
|
-
* `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`; conventions 3.4)
|
|
8
|
-
*
|
|
7
|
+
* `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`; conventions 3.4), and the steps
|
|
8
|
+
* of the continuous controls (`Slider`, `NumberField`). A second `run` while one is in flight is
|
|
9
|
+
* ignored only with `ignoreWhilePending` (a part whose `whilePending` is `"ignore"`, conventions
|
|
10
|
+
* 2.5.1).
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* thenable per `useTransition`, so the rejection of a run that a later run superseded
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Without it (`whilePending="run"`, the steps) runs overlap, and the hook handles superseded
|
|
13
|
+
* rejections as `useControllableAction` does: React keeps only the newest
|
|
14
|
+
* thenable per `useTransition`, so the rejection of a run that a later run superseded reaches no
|
|
15
|
+
* boundary. The hook passes it to `reportError` (`reportDropped`); the latest run's rejection
|
|
16
|
+
* is rethrown inside the transition and reaches the boundary. In both modes, a latest rejection
|
|
17
|
+
* that arrives after the part unmounted or was hidden by `<Activity>` is reported too (#152):
|
|
18
|
+
* React would route it only through a render of the part.
|
|
15
19
|
*/
|
|
16
20
|
function useActionTrigger(options = {}) {
|
|
17
|
-
const { openGeneration, ignoreWhilePending =
|
|
18
|
-
const ownCapture = useSupersededRejection();
|
|
19
|
-
const captureSuperseded = options.captureSuperseded ?? ownCapture;
|
|
21
|
+
const { openGeneration, ignoreWhilePending = false } = options;
|
|
20
22
|
const [pending, startOwnTransition] = useTransition();
|
|
21
23
|
const latest = useRef(0);
|
|
22
24
|
const inFlight = useRef(0);
|
|
25
|
+
const connected = useConnected();
|
|
26
|
+
const resolvedThen = useRef(null);
|
|
27
|
+
const settled = () => {
|
|
28
|
+
inFlight.current--;
|
|
29
|
+
if (inFlight.current > 0) return;
|
|
30
|
+
const continuation = resolvedThen.current;
|
|
31
|
+
resolvedThen.current = null;
|
|
32
|
+
continuation?.();
|
|
33
|
+
};
|
|
23
34
|
const run = (work, then) => {
|
|
24
35
|
if (ignoreWhilePending && inFlight.current > 0) return false;
|
|
25
36
|
inFlight.current++;
|
|
26
37
|
const id = ++latest.current;
|
|
27
38
|
const generation = openGeneration?.();
|
|
39
|
+
resolvedThen.current = null;
|
|
28
40
|
startOwnTransition(async () => {
|
|
29
41
|
try {
|
|
30
42
|
await work();
|
|
31
43
|
} catch (error) {
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
44
|
+
const rethrow = id === latest.current && connected.current;
|
|
45
|
+
if (!rethrow) reportDropped(error);
|
|
46
|
+
settled();
|
|
47
|
+
if (rethrow) throw error;
|
|
35
48
|
return;
|
|
36
49
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
if (id === latest.current && then !== void 0) resolvedThen.current = () => {
|
|
51
|
+
if (openGeneration !== void 0 && openGeneration() !== generation) return;
|
|
52
|
+
then();
|
|
53
|
+
};
|
|
54
|
+
settled();
|
|
40
55
|
});
|
|
41
56
|
return true;
|
|
42
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-action-trigger.mjs","names":[],"sources":["../../src/internal/use-action-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useRef, useTransition } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"file":"use-action-trigger.mjs","names":[],"sources":["../../src/internal/use-action-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useRef, useTransition } from \"react\";\nimport { reportDropped, useConnected } from \"./report-dropped.js\";\n\nexport interface ActionTriggerOptions {\n /**\n * Open generation of the overlay a `then` belongs to: `then` is skipped when a newer open of\n * the overlay started after the run began.\n */\n readonly openGeneration?: (() => number) | undefined;\n /**\n * Ignore `run` while a run is in flight (conventions 2.5.1): `run` returns `false` and starts\n * nothing. In flight means the hook's synchronous in-flight counter is non-zero (it also sees\n * two activations in one task, before React re-rendered); the last render's `pending` is not\n * consulted, so a click in a settled-but-held commit window runs. Default `false`: runs\n * overlap, as with React's own `useTransition`. A pure trigger passes\n * `(whilePending ?? <its default>) === \"ignore\"`, read per render (#146).\n */\n readonly ignoreWhilePending?: boolean | undefined;\n}\n\nexport interface ActionTrigger {\n /** A run started through this hook is in flight (the part's own transition). */\n readonly pending: boolean;\n /**\n * Runs `work` inside the part's own transition and, once it resolves, `then` (still inside the\n * transition: a Close part's close, a menu item's close). With overlapping runs, `then` runs\n * once, when the last run in flight settles, and only if the latest run resolved: it is the\n * latest run's `then` (#146 review F1). A rejection skips `then` and reaches\n * the nearest Error Boundary above the part; a run that a later run superseded, or any run\n * once the part unmounted or was hidden by `<Activity>`, passes its rejection to `reportError`\n * instead (conventions 2.4). With\n * `openGeneration`, `then` is skipped when a newer open of the overlay started after the run\n * began. Returns `false` when the run was ignored (a run is in flight and `ignoreWhilePending`\n * is on), so the part can\n * `preventDefault()` the activation, and `true` otherwise.\n */\n readonly run: (work: () => unknown, then?: () => void) => boolean;\n}\n\n/**\n * The transition of a pure-trigger part: an `action` with no state of its own (`Button`,\n * `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`; conventions 3.4), and the steps\n * of the continuous controls (`Slider`, `NumberField`). A second `run` while one is in flight is\n * ignored only with `ignoreWhilePending` (a part whose `whilePending` is `\"ignore\"`, conventions\n * 2.5.1).\n *\n * Without it (`whilePending=\"run\"`, the steps) runs overlap, and the hook handles superseded\n * rejections as `useControllableAction` does: React keeps only the newest\n * thenable per `useTransition`, so the rejection of a run that a later run superseded reaches no\n * boundary. The hook passes it to `reportError` (`reportDropped`); the latest run's rejection\n * is rethrown inside the transition and reaches the boundary. In both modes, a latest rejection\n * that arrives after the part unmounted or was hidden by `<Activity>` is reported too (#152):\n * React would route it only through a render of the part.\n */\nexport function useActionTrigger(options: ActionTriggerOptions = {}): ActionTrigger {\n const { openGeneration, ignoreWhilePending = false } = options;\n\n const [pending, startOwnTransition] = useTransition();\n const latest = useRef(0);\n // Runs whose work has not settled yet. Updated synchronously, so a second activation in the\n // same task (React's `pending` is still the stale render value) is seen (conventions 2.5).\n const inFlight = useRef(0);\n const connected = useConnected();\n // The latest run's continuation once it resolved, waiting for the other runs in flight to\n // settle. Cleared by every new run: only the latest run's outcome decides (#146 review F1).\n const resolvedThen = useRef<(() => void) | null>(null);\n\n // A run settled. When it was the last in flight, the latest run's continuation runs if that\n // run resolved; a rejected latest run (or a newer run since) left nothing to run.\n const settled = () => {\n inFlight.current--;\n if (inFlight.current > 0) return;\n const continuation = resolvedThen.current;\n resolvedThen.current = null;\n continuation?.();\n };\n\n const run = (work: () => unknown, then?: () => void): boolean => {\n // The own counter only, not the rendered `pending` (design/components/button.md 5.2): after\n // the work settled, a commit held by entanglement must not drop a new activation.\n if (ignoreWhilePending && inFlight.current > 0) return false;\n inFlight.current++;\n const id = ++latest.current;\n // The open this run belongs to (design/components/popover.md 3.4): if the\n // user dismisses and re-opens while the action runs, its close must not close the new open.\n const generation = openGeneration?.();\n resolvedThen.current = null;\n startOwnTransition(async () => {\n try {\n await work();\n } catch (error) {\n // The latest run's rejection takes React's own route to the boundary while the part is\n // there to render it; otherwise React would drop it, as it drops a superseded one (2.4).\n const rethrow = id === latest.current && connected.current;\n if (!rethrow) reportDropped(error);\n settled();\n if (rethrow) throw error;\n return;\n }\n if (id === latest.current && then !== undefined) {\n resolvedThen.current = () => {\n if (openGeneration !== undefined && openGeneration() !== generation) return;\n then();\n };\n }\n settled();\n });\n return true;\n };\n\n return { pending, run };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,iBAAiB,UAAgC,CAAC,GAAkB;CAClF,MAAM,EAAE,gBAAgB,qBAAqB,UAAU;CAEvD,MAAM,CAAC,SAAS,sBAAsB,cAAc;CACpD,MAAM,SAAS,OAAO,CAAC;CAGvB,MAAM,WAAW,OAAO,CAAC;CACzB,MAAM,YAAY,aAAa;CAG/B,MAAM,eAAe,OAA4B,IAAI;CAIrD,MAAM,gBAAgB;EACpB,SAAS;EACT,IAAI,SAAS,UAAU,GAAG;EAC1B,MAAM,eAAe,aAAa;EAClC,aAAa,UAAU;EACvB,eAAe;CACjB;CAEA,MAAM,OAAO,MAAqB,SAA+B;EAG/D,IAAI,sBAAsB,SAAS,UAAU,GAAG,OAAO;EACvD,SAAS;EACT,MAAM,KAAK,EAAE,OAAO;EAGpB,MAAM,aAAa,iBAAiB;EACpC,aAAa,UAAU;EACvB,mBAAmB,YAAY;GAC7B,IAAI;IACF,MAAM,KAAK;GACb,SAAS,OAAO;IAGd,MAAM,UAAU,OAAO,OAAO,WAAW,UAAU;IACnD,IAAI,CAAC,SAAS,cAAc,KAAK;IACjC,QAAQ;IACR,IAAI,SAAS,MAAM;IACnB;GACF;GACA,IAAI,OAAO,OAAO,WAAW,SAAS,KAAA,GACpC,aAAa,gBAAgB;IAC3B,IAAI,mBAAmB,KAAA,KAAa,eAAe,MAAM,YAAY;IACrE,KAAK;GACP;GAEF,QAAQ;EACV,CAAC;EACD,OAAO;CACT;CAEA,OAAO;EAAE;EAAS;CAAI;AACxB"}
|