@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20
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-item.mjs +2 -2
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +3 -20
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
- package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
- package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
- package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
- package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
- package/dist/alert-dialog/index.d.mts +33 -0
- package/dist/alert-dialog/index.d.mts.map +1 -0
- package/dist/alert-dialog/index.mjs +33 -0
- package/dist/alert-dialog/index.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
- package/dist/collapsible/collapsible-context.mjs +8 -0
- package/dist/collapsible/collapsible-context.mjs.map +1 -0
- package/dist/collapsible/collapsible-panel.d.mts +53 -0
- package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
- package/dist/collapsible/collapsible-panel.mjs +41 -0
- package/dist/collapsible/collapsible-panel.mjs.map +1 -0
- package/dist/collapsible/collapsible-root.d.mts +108 -0
- package/dist/collapsible/collapsible-root.d.mts.map +1 -0
- package/dist/collapsible/collapsible-root.mjs +147 -0
- package/dist/collapsible/collapsible-root.mjs.map +1 -0
- package/dist/collapsible/collapsible-trigger.d.mts +45 -0
- package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
- package/dist/collapsible/collapsible-trigger.mjs +62 -0
- package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
- package/dist/collapsible/index.d.mts +21 -0
- package/dist/collapsible/index.d.mts.map +1 -0
- package/dist/collapsible/index.mjs +21 -0
- package/dist/collapsible/index.mjs.map +1 -0
- package/dist/combobox/chip-text.mjs +24 -0
- package/dist/combobox/chip-text.mjs.map +1 -0
- package/dist/combobox/combobox-chips.d.mts +159 -0
- package/dist/combobox/combobox-chips.d.mts.map +1 -0
- package/dist/combobox/combobox-chips.mjs +198 -0
- package/dist/combobox/combobox-chips.mjs.map +1 -0
- package/dist/combobox/combobox-clear.d.mts +5 -2
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +3 -1
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs +4 -5
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +10 -3
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +13 -5
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +50 -4
- package/dist/combobox/combobox-keyboard.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts +1 -1
- package/dist/combobox/combobox-list.mjs +2 -1
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts +5 -2
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +4 -3
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +127 -35
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +396 -44
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/index.d.mts +8 -2
- package/dist/combobox/index.d.mts.map +1 -1
- package/dist/combobox/index.mjs +7 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +2 -3
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +9 -5
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +19 -8
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.d.mts +2 -0
- package/dist/dialog/dialog-context.mjs +14 -2
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-description.d.mts +2 -1
- package/dist/dialog/dialog-description.d.mts.map +1 -1
- package/dist/dialog/dialog-description.mjs +8 -4
- package/dist/dialog/dialog-description.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 +11 -6
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +2 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +23 -14
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +2 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +15 -5
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-title.d.mts +2 -1
- package/dist/dialog/dialog-title.d.mts.map +1 -1
- package/dist/dialog/dialog-title.mjs +8 -4
- package/dist/dialog/dialog-title.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +2 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +14 -9
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +2 -0
- package/dist/docs/components/alert-dialog.md +546 -0
- package/dist/docs/components/collapsible.md +408 -0
- package/dist/docs/components/combobox.md +288 -26
- package/dist/docs/components/dialog.md +7 -5
- package/dist/docs/components/field.md +180 -3
- package/dist/docs/components/hover-card.md +494 -0
- package/dist/docs/components/multi-select.md +622 -0
- package/dist/docs/components/number-field.md +1 -1
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/select.md +9 -1
- package/dist/docs/components/separator.md +182 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/experimental.md +3 -3
- package/dist/docs/concepts/server-components.md +1 -1
- package/dist/docs/index.md +7 -2
- package/dist/docs/roadmap.md +8 -0
- package/dist/field/field-control.d.mts +13 -4
- package/dist/field/field-control.d.mts.map +1 -1
- package/dist/field/field-control.mjs +39 -10
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-label.d.mts +6 -2
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +12 -2
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +9 -1
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/hover-card/hover-card-context.mjs +13 -0
- package/dist/hover-card/hover-card-context.mjs.map +1 -0
- package/dist/hover-card/hover-card-popup.d.mts +102 -0
- package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
- package/dist/hover-card/hover-card-popup.mjs +80 -0
- package/dist/hover-card/hover-card-popup.mjs.map +1 -0
- package/dist/hover-card/hover-card-root.d.mts +94 -0
- package/dist/hover-card/hover-card-root.d.mts.map +1 -0
- package/dist/hover-card/hover-card-root.mjs +74 -0
- package/dist/hover-card/hover-card-root.mjs.map +1 -0
- package/dist/hover-card/hover-card-trigger.d.mts +65 -0
- package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
- package/dist/hover-card/hover-card-trigger.mjs +109 -0
- package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
- package/dist/hover-card/index.d.mts +24 -0
- package/dist/hover-card/index.d.mts.map +1 -0
- package/dist/hover-card/index.mjs +24 -0
- package/dist/hover-card/index.mjs.map +1 -0
- package/dist/hover-card/use-hover-card-interest.mjs +242 -0
- package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +6 -1
- package/dist/internal/action/use-multiple-selection.mjs +83 -0
- package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
- package/dist/internal/details-summary.mjs +56 -0
- package/dist/internal/details-summary.mjs.map +1 -0
- package/dist/internal/form/field-context.mjs.map +1 -1
- package/dist/internal/form/hidden-values.mjs +29 -0
- package/dist/internal/form/hidden-values.mjs.map +1 -0
- package/dist/internal/form/validity.mjs +3 -1
- package/dist/internal/form/validity.mjs.map +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-close.mjs +5 -3
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +4 -1
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-popup.mjs +20 -7
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
- package/dist/internal/typeahead.mjs +52 -0
- package/dist/internal/typeahead.mjs.map +1 -0
- package/dist/{combobox → internal}/use-active-option.mjs +8 -6
- package/dist/internal/use-active-option.mjs.map +1 -0
- package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
- package/dist/internal/use-deferred-leave.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +57 -1
- package/dist/internal/use-name-warning.mjs.map +1 -1
- package/dist/internal/use-option-registry.mjs +70 -0
- package/dist/internal/use-option-registry.mjs.map +1 -0
- package/dist/menu/use-menu-keyboard.mjs +7 -27
- package/dist/menu/use-menu-keyboard.mjs.map +1 -1
- package/dist/multi-select/index.d.mts +37 -0
- package/dist/multi-select/index.d.mts.map +1 -0
- package/dist/multi-select/index.mjs +37 -0
- package/dist/multi-select/index.mjs.map +1 -0
- package/dist/multi-select/multi-select-context.mjs +19 -0
- package/dist/multi-select/multi-select-context.mjs.map +1 -0
- package/dist/multi-select/multi-select-group.d.mts +120 -0
- package/dist/multi-select/multi-select-group.d.mts.map +1 -0
- package/dist/multi-select/multi-select-group.mjs +111 -0
- package/dist/multi-select/multi-select-group.mjs.map +1 -0
- package/dist/multi-select/multi-select-keyboard.mjs +145 -0
- package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
- package/dist/multi-select/multi-select-label.d.mts +42 -0
- package/dist/multi-select/multi-select-label.d.mts.map +1 -0
- package/dist/multi-select/multi-select-label.mjs +41 -0
- package/dist/multi-select/multi-select-label.mjs.map +1 -0
- package/dist/multi-select/multi-select-list.d.mts +47 -0
- package/dist/multi-select/multi-select-list.d.mts.map +1 -0
- package/dist/multi-select/multi-select-list.mjs +65 -0
- package/dist/multi-select/multi-select-list.mjs.map +1 -0
- package/dist/multi-select/multi-select-option.d.mts +68 -0
- package/dist/multi-select/multi-select-option.d.mts.map +1 -0
- package/dist/multi-select/multi-select-option.mjs +93 -0
- package/dist/multi-select/multi-select-option.mjs.map +1 -0
- package/dist/multi-select/multi-select-popup.d.mts +58 -0
- package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
- package/dist/multi-select/multi-select-popup.mjs +71 -0
- package/dist/multi-select/multi-select-popup.mjs.map +1 -0
- package/dist/multi-select/multi-select-root.d.mts +125 -0
- package/dist/multi-select/multi-select-root.d.mts.map +1 -0
- package/dist/multi-select/multi-select-root.mjs +257 -0
- package/dist/multi-select/multi-select-root.mjs.map +1 -0
- package/dist/multi-select/multi-select-trigger.d.mts +66 -0
- package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
- package/dist/multi-select/multi-select-trigger.mjs +169 -0
- package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
- package/dist/multi-select/multi-select-value.d.mts +57 -0
- package/dist/multi-select/multi-select-value.d.mts.map +1 -0
- package/dist/multi-select/multi-select-value.mjs +41 -0
- package/dist/multi-select/multi-select-value.mjs.map +1 -0
- package/dist/number-field/number-field-root.mjs +1 -1
- package/dist/number-field/use-step-button.d.mts.map +1 -1
- package/dist/number-field/use-step-button.mjs +11 -2
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +6 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/select/select-root.d.mts +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +5 -1
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/separator/index.d.mts +3 -0
- package/dist/separator/index.mjs +1 -0
- package/dist/separator/separator.d.mts +58 -0
- package/dist/separator/separator.d.mts.map +1 -0
- package/dist/separator/separator.mjs +41 -0
- package/dist/separator/separator.mjs.map +1 -0
- package/dist/slider/slider-root.mjs +1 -0
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.mjs +1 -1
- package/package.json +6 -1
- package/skills/funstack-ui-knowledge/SKILL.md +14 -9
- package/dist/combobox/use-active-option.mjs.map +0 -1
- package/dist/combobox/use-deferred-leave.mjs.map +0 -1
- package/dist/combobox/use-option-registry.mjs +0 -52
- package/dist/combobox/use-option-registry.mjs.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/hover-card/hover-card-trigger.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* State of `HoverCard.Trigger`, passed to the function forms of `className`, `style`, `children`
|
|
6
|
+
* and `render`.
|
|
7
|
+
*/
|
|
8
|
+
export interface HoverCardTriggerState {
|
|
9
|
+
/** Optimistic open state. */
|
|
10
|
+
readonly open: boolean;
|
|
11
|
+
/** The Root's transition is pending: the card is loading. */
|
|
12
|
+
readonly pending: boolean;
|
|
13
|
+
/** The Root's `disabled`. */
|
|
14
|
+
readonly disabled: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Props of `HoverCard.Trigger`.
|
|
18
|
+
*
|
|
19
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
20
|
+
*/
|
|
21
|
+
export interface HoverCardTriggerProps extends Omit<ComponentPropsWithRef<"a">, "className" | "style" | "children"> {
|
|
22
|
+
/**
|
|
23
|
+
* Experimental (Chromium 142+). Writes `interestfor` (after hydration, through the ref) and
|
|
24
|
+
* renders `interest-delay-start` / `-end` from the Root's `delay` / `closeDelay`, so the
|
|
25
|
+
* browser decides when interest starts and ends (long-press on touch included); the library
|
|
26
|
+
* still owns the open, Escape and a press outside. No effect in other engines, or on an element
|
|
27
|
+
* that does not implement `interestForElement`: the JS path runs.
|
|
28
|
+
*
|
|
29
|
+
* @defaultValue `false`
|
|
30
|
+
*/
|
|
31
|
+
experimental_interestFor?: boolean;
|
|
32
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
33
|
+
className?: StateValue<string | undefined, HoverCardTriggerState>;
|
|
34
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
35
|
+
style?: StateValue<CSSProperties | undefined, HoverCardTriggerState>;
|
|
36
|
+
/** Content, or a function of the part's state. Rendered from optimistic state; must not suspend. */
|
|
37
|
+
children?: StateValue<ReactNode, HoverCardTriggerState>;
|
|
38
|
+
/**
|
|
39
|
+
* A link (default), a router link component, or a button whose click opens nothing of this
|
|
40
|
+
* kind (element form), or take over rendering (function form).
|
|
41
|
+
*/
|
|
42
|
+
render?: RenderProp<ComponentPropsWithRef<"a">, HoverCardTriggerState>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The element the user hovers or focuses: an `<a>` by default, with `href` and every other
|
|
46
|
+
* anchor prop passed through. The card is opened by interest only; the Trigger's click is the
|
|
47
|
+
* consumer's (a link navigates), and a press on it closes the card. The element must be
|
|
48
|
+
* focusable (a development warning fires when it is not).
|
|
49
|
+
*
|
|
50
|
+
* The library attaches its listeners with `addEventListener` from `HoverCard.Root`, so every
|
|
51
|
+
* `on*` prop passes through untouched (`onPointerEnter={preload}` starts loading during the
|
|
52
|
+
* delay).
|
|
53
|
+
*
|
|
54
|
+
* Owned keys (conventions 1.2): `data-open` (optimistic), `data-pending`, `data-disabled`, and
|
|
55
|
+
* `interestfor` while `experimental_interestFor` is on (written through the ref, removed while
|
|
56
|
+
* disabled). No ARIA attribute.
|
|
57
|
+
*
|
|
58
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
59
|
+
*/
|
|
60
|
+
export declare function HoverCardTrigger({ experimental_interestFor, className, style, children, render, ...rest }: HoverCardTriggerProps): ReactNode;
|
|
61
|
+
export declare namespace HoverCardTrigger {
|
|
62
|
+
var displayName: string;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//# sourceMappingURL=hover-card-trigger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-trigger.d.mts","names":[],"sources":["../../src/hover-card/hover-card-trigger.tsx"],"mappings":";;;;;;;iBAgBiB;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM,8BAA8B,KAC7C;;;;;;;;;;EAYA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;;;;EAKjC,SAAS,WAAW,4BAA4B;;;;;;;;;;;;;;;;;;wBAkClC,mBACd,0BACA,WACA,OACA,UACA,WACG,QACF,wBAAqB;yBAPR"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
4
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
5
|
+
import { useLatest } from "../internal/use-latest.mjs";
|
|
6
|
+
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
7
|
+
import { useHoverCardContext } from "./hover-card-context.mjs";
|
|
8
|
+
import { registerTrigger } from "../internal/overlay/trigger-ref.mjs";
|
|
9
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
10
|
+
//#region src/hover-card/hover-card-trigger.tsx
|
|
11
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
12
|
+
/**
|
|
13
|
+
* Whether keyboard users can reach the Trigger (design 1.2): `tabIndex >= 0`, and an `<a>` has an
|
|
14
|
+
* `href` or an explicit `tabindex` (an `<a>` without `href` reports `tabIndex` 0 but is not
|
|
15
|
+
* focusable).
|
|
16
|
+
*/
|
|
17
|
+
function isFocusable(target) {
|
|
18
|
+
if (target.tabIndex < 0) return false;
|
|
19
|
+
if (target.localName === "a" && !target.hasAttribute("href")) return target.hasAttribute("tabindex");
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The element the user hovers or focuses: an `<a>` by default, with `href` and every other
|
|
24
|
+
* anchor prop passed through. The card is opened by interest only; the Trigger's click is the
|
|
25
|
+
* consumer's (a link navigates), and a press on it closes the card. The element must be
|
|
26
|
+
* focusable (a development warning fires when it is not).
|
|
27
|
+
*
|
|
28
|
+
* The library attaches its listeners with `addEventListener` from `HoverCard.Root`, so every
|
|
29
|
+
* `on*` prop passes through untouched (`onPointerEnter={preload}` starts loading during the
|
|
30
|
+
* delay).
|
|
31
|
+
*
|
|
32
|
+
* Owned keys (conventions 1.2): `data-open` (optimistic), `data-pending`, `data-disabled`, and
|
|
33
|
+
* `interestfor` while `experimental_interestFor` is on (written through the ref, removed while
|
|
34
|
+
* disabled). No ARIA attribute.
|
|
35
|
+
*
|
|
36
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
37
|
+
*/
|
|
38
|
+
function HoverCardTrigger({ experimental_interestFor = false, className, style, children, render, ...rest }) {
|
|
39
|
+
const ctx = useHoverCardContext("HoverCard.Trigger");
|
|
40
|
+
const { disabled, ids, triggerRef, setTriggerElement, setInterestForRequested } = ctx;
|
|
41
|
+
const native = experimental_interestFor && !disabled;
|
|
42
|
+
const element = useRef(null);
|
|
43
|
+
const writes = useLatest({
|
|
44
|
+
native,
|
|
45
|
+
popupId: ids.popup
|
|
46
|
+
});
|
|
47
|
+
const writeInterestFor = (target) => {
|
|
48
|
+
const { native: on, popupId } = writes.current;
|
|
49
|
+
if (on) target.setAttribute("interestfor", popupId);
|
|
50
|
+
else target.removeAttribute("interestfor");
|
|
51
|
+
};
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
if (element.current !== null) writeInterestFor(element.current);
|
|
54
|
+
setInterestForRequested(native);
|
|
55
|
+
}, [
|
|
56
|
+
native,
|
|
57
|
+
ids.popup,
|
|
58
|
+
setInterestForRequested
|
|
59
|
+
]);
|
|
60
|
+
const checkElement = useElementCheck(isDev && ((target) => isFocusable(target) ? null : "HoverCard.Trigger: the trigger is not focusable; keyboard users cannot open the card. Render a link with `href` or a button, or set tabIndex={0}."));
|
|
61
|
+
const ref = useCallback((target) => {
|
|
62
|
+
checkElement?.(target);
|
|
63
|
+
element.current = target;
|
|
64
|
+
const unregister = registerTrigger(triggerRef, target, "HoverCard.Trigger");
|
|
65
|
+
setTriggerElement(target);
|
|
66
|
+
if (writes.current.native) writeInterestFor(target);
|
|
67
|
+
return () => {
|
|
68
|
+
unregister();
|
|
69
|
+
if (writes.current.native) target.removeAttribute("interestfor");
|
|
70
|
+
if (element.current === target) element.current = null;
|
|
71
|
+
setTriggerElement(null);
|
|
72
|
+
};
|
|
73
|
+
}, [
|
|
74
|
+
checkElement,
|
|
75
|
+
triggerRef,
|
|
76
|
+
setTriggerElement,
|
|
77
|
+
writes
|
|
78
|
+
]);
|
|
79
|
+
const state = {
|
|
80
|
+
open: ctx.optimistic,
|
|
81
|
+
pending: ctx.pending,
|
|
82
|
+
disabled
|
|
83
|
+
};
|
|
84
|
+
const libraryProps = {
|
|
85
|
+
"data-open": dataAttr(state.open),
|
|
86
|
+
"data-pending": dataAttr(state.pending),
|
|
87
|
+
"data-disabled": dataAttr(disabled)
|
|
88
|
+
};
|
|
89
|
+
return useRender({
|
|
90
|
+
defaultElement: "a",
|
|
91
|
+
render,
|
|
92
|
+
state,
|
|
93
|
+
className,
|
|
94
|
+
style: experimental_interestFor ? (s) => ({
|
|
95
|
+
interestDelayStart: `${ctx.delay}ms`,
|
|
96
|
+
interestDelayEnd: `${ctx.closeDelay}ms`,
|
|
97
|
+
...resolveStateValue(style, s)
|
|
98
|
+
}) : style,
|
|
99
|
+
children,
|
|
100
|
+
props: rest,
|
|
101
|
+
libraryProps,
|
|
102
|
+
ref
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
HoverCardTrigger.displayName = "HoverCardTrigger";
|
|
106
|
+
//#endregion
|
|
107
|
+
export { HoverCardTrigger };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=hover-card-trigger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-trigger.mjs","names":[],"sources":["../../src/hover-card/hover-card-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { registerTrigger } from \"../internal/overlay/trigger-ref.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 { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useHoverCardContext } from \"./hover-card-context.js\";\n\n/**\n * State of `HoverCard.Trigger`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface HoverCardTriggerState {\n /** Optimistic open state. */\n readonly open: boolean;\n /** The Root's transition is pending: the card is loading. */\n readonly pending: boolean;\n /** The Root's `disabled`. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `HoverCard.Trigger`.\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport interface HoverCardTriggerProps extends Omit<\n ComponentPropsWithRef<\"a\">,\n \"className\" | \"style\" | \"children\"\n> {\n /**\n * Experimental (Chromium 142+). Writes `interestfor` (after hydration, through the ref) and\n * renders `interest-delay-start` / `-end` from the Root's `delay` / `closeDelay`, so the\n * browser decides when interest starts and ends (long-press on touch included); the library\n * still owns the open, Escape and a press outside. No effect in other engines, or on an element\n * that does not implement `interestForElement`: the JS path runs.\n *\n * @defaultValue `false`\n */\n experimental_interestFor?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, HoverCardTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, HoverCardTriggerState>;\n /** Content, or a function of the part's state. Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, HoverCardTriggerState>;\n /**\n * A link (default), a router link component, or a button whose click opens nothing of this\n * kind (element form), or take over rendering (function form).\n */\n render?: RenderProp<ComponentPropsWithRef<\"a\">, HoverCardTriggerState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Whether keyboard users can reach the Trigger (design 1.2): `tabIndex >= 0`, and an `<a>` has an\n * `href` or an explicit `tabindex` (an `<a>` without `href` reports `tabIndex` 0 but is not\n * focusable).\n */\nfunction isFocusable(target: HTMLElement): boolean {\n if (target.tabIndex < 0) return false;\n if (target.localName === \"a\" && !target.hasAttribute(\"href\")) {\n return target.hasAttribute(\"tabindex\");\n }\n return true;\n}\n\n/**\n * The element the user hovers or focuses: an `<a>` by default, with `href` and every other\n * anchor prop passed through. The card is opened by interest only; the Trigger's click is the\n * consumer's (a link navigates), and a press on it closes the card. The element must be\n * focusable (a development warning fires when it is not).\n *\n * The library attaches its listeners with `addEventListener` from `HoverCard.Root`, so every\n * `on*` prop passes through untouched (`onPointerEnter={preload}` starts loading during the\n * delay).\n *\n * Owned keys (conventions 1.2): `data-open` (optimistic), `data-pending`, `data-disabled`, and\n * `interestfor` while `experimental_interestFor` is on (written through the ref, removed while\n * disabled). No ARIA attribute.\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport function HoverCardTrigger({\n experimental_interestFor = false,\n className,\n style,\n children,\n render,\n ...rest\n}: HoverCardTriggerProps) {\n const ctx = useHoverCardContext(\"HoverCard.Trigger\");\n const { disabled, ids, triggerRef, setTriggerElement, setInterestForRequested } = ctx;\n const native = experimental_interestFor && !disabled;\n\n // The attribute is written after hydration (design 2.3): a hover before hydration would\n // otherwise open an empty card.\n const element = useRef<HTMLElement | null>(null);\n const writes = useLatest({ native, popupId: ids.popup });\n const writeInterestFor = (target: HTMLElement): void => {\n const { native: on, popupId } = writes.current;\n if (on) target.setAttribute(\"interestfor\", popupId);\n else target.removeAttribute(\"interestfor\");\n };\n useLayoutEffect(() => {\n if (element.current !== null) writeInterestFor(element.current);\n setInterestForRequested(native);\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- `writeInterestFor` reads the ref\n }, [native, ids.popup, setInterestForRequested]);\n\n const checkElement = useElementCheck(\n isDev &&\n ((target: HTMLElement) =>\n isFocusable(target)\n ? null\n : \"HoverCard.Trigger: the trigger is not focusable; keyboard users cannot open the \" +\n \"card. Render a link with `href` or a button, or set tabIndex={0}.\"),\n );\n\n const ref = useCallback(\n (target: HTMLElement) => {\n checkElement?.(target);\n element.current = target;\n const unregister = registerTrigger(triggerRef, target, \"HoverCard.Trigger\");\n setTriggerElement(target);\n if (writes.current.native) writeInterestFor(target);\n return () => {\n unregister();\n if (writes.current.native) target.removeAttribute(\"interestfor\");\n if (element.current === target) element.current = null;\n setTriggerElement(null);\n };\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- `writeInterestFor` reads the ref\n [checkElement, triggerRef, setTriggerElement, writes],\n );\n\n const state: HoverCardTriggerState = {\n open: ctx.optimistic,\n pending: ctx.pending,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"a\"> & DataAttributes = {\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"a\">, HoverCardTriggerState>({\n defaultElement: \"a\",\n render,\n state,\n className,\n // The native delays sit under the consumer's style: the consumer wins. Inert without the\n // `interestfor` attribute, so they are in the server HTML too.\n style: experimental_interestFor\n ? (s) => ({\n interestDelayStart: `${ctx.delay}ms`,\n interestDelayEnd: `${ctx.closeDelay}ms`,\n ...resolveStateValue(style, s),\n })\n : style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nHoverCardTrigger.displayName = \"HoverCardTrigger\";\n"],"mappings":";;;;;;;;;;AAyDA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;AAOvC,SAAS,YAAY,QAA8B;CACjD,IAAI,OAAO,WAAW,GAAG,OAAO;CAChC,IAAI,OAAO,cAAc,OAAO,CAAC,OAAO,aAAa,MAAM,GACzD,OAAO,OAAO,aAAa,UAAU;CAEvC,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,SAAgB,iBAAiB,EAC/B,2BAA2B,OAC3B,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,MAAM,oBAAoB,mBAAmB;CACnD,MAAM,EAAE,UAAU,KAAK,YAAY,mBAAmB,4BAA4B;CAClF,MAAM,SAAS,4BAA4B,CAAC;CAI5C,MAAM,UAAU,OAA2B,IAAI;CAC/C,MAAM,SAAS,UAAU;EAAE;EAAQ,SAAS,IAAI;CAAM,CAAC;CACvD,MAAM,oBAAoB,WAA8B;EACtD,MAAM,EAAE,QAAQ,IAAI,YAAY,OAAO;EACvC,IAAI,IAAI,OAAO,aAAa,eAAe,OAAO;OAC7C,OAAO,gBAAgB,aAAa;CAC3C;CACA,sBAAsB;EACpB,IAAI,QAAQ,YAAY,MAAM,iBAAiB,QAAQ,OAAO;EAC9D,wBAAwB,MAAM;CAEhC,GAAG;EAAC;EAAQ,IAAI;EAAO;CAAuB,CAAC;CAE/C,MAAM,eAAe,gBACnB,WACI,WACA,YAAY,MAAM,IACd,OACA,oJAEV;CAEA,MAAM,MAAM,aACT,WAAwB;EACvB,eAAe,MAAM;EACrB,QAAQ,UAAU;EAClB,MAAM,aAAa,gBAAgB,YAAY,QAAQ,mBAAmB;EAC1E,kBAAkB,MAAM;EACxB,IAAI,OAAO,QAAQ,QAAQ,iBAAiB,MAAM;EAClD,aAAa;GACX,WAAW;GACX,IAAI,OAAO,QAAQ,QAAQ,OAAO,gBAAgB,aAAa;GAC/D,IAAI,QAAQ,YAAY,QAAQ,QAAQ,UAAU;GAClD,kBAAkB,IAAI;EACxB;CACF,GAEA;EAAC;EAAc;EAAY;EAAmB;CAAM,CACtD;CAEA,MAAM,QAA+B;EACnC,MAAM,IAAI;EACV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAA4D;EAChE,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA6D;EAClE,gBAAgB;EAChB;EACA;EACA;EAGA,OAAO,4BACF,OAAO;GACN,oBAAoB,GAAG,IAAI,MAAM;GACjC,kBAAkB,GAAG,IAAI,WAAW;GACpC,GAAG,kBAAkB,OAAO,CAAC;EAC/B,KACA;EACJ;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "../internal/platform-attributes.mjs";
|
|
2
|
+
import { HoverCardAlign, HoverCardPopup, HoverCardPopupProps, HoverCardPopupState, HoverCardSide } from "./hover-card-popup.mjs";
|
|
3
|
+
import { HoverCardOpenChangeDetails, HoverCardRoot, HoverCardRootProps, HoverCardRootState } from "./hover-card-root.mjs";
|
|
4
|
+
import { HoverCardTrigger, HoverCardTriggerProps, HoverCardTriggerState } from "./hover-card-trigger.mjs";
|
|
5
|
+
//#region src/hover-card/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A rich preview shown while the user shows interest in a link (hover or keyboard focus, after a
|
|
8
|
+
* delay): `Root` (no DOM) > `Trigger` (`a`) + `Popup` (`div[popover=manual][role=group]`, right
|
|
9
|
+
* after the Trigger). Unlike a Tooltip the card may hold links and buttons and is not the
|
|
10
|
+
* Trigger's description; unlike a Popover nothing is clicked to open it and opening never moves
|
|
11
|
+
* focus. Opening is a request (`openChangeAction(true)`, a transition: the content mounts and may
|
|
12
|
+
* suspend, the Trigger is `data-pending` meanwhile); every close the user causes is a fact
|
|
13
|
+
* (`onOpenChange(false)`).
|
|
14
|
+
*
|
|
15
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
16
|
+
*/
|
|
17
|
+
export declare const HoverCard: {
|
|
18
|
+
readonly Root: typeof HoverCardRoot;
|
|
19
|
+
readonly Trigger: typeof HoverCardTrigger;
|
|
20
|
+
readonly Popup: typeof HoverCardPopup;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export type { HoverCardAlign, HoverCardOpenChangeDetails, HoverCardPopupProps, HoverCardPopupState, HoverCardRootProps, HoverCardRootState, HoverCardSide, HoverCardTriggerProps, HoverCardTriggerState };
|
|
24
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/hover-card/index.ts"],"mappings":";;;;;;;;;;;;;;;;qBAkBa;WACX,aAAI;WACJ,gBAAO;WACP,cAAK"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HoverCardPopup } from "./hover-card-popup.mjs";
|
|
2
|
+
import { HoverCardRoot } from "./hover-card-root.mjs";
|
|
3
|
+
import { HoverCardTrigger } from "./hover-card-trigger.mjs";
|
|
4
|
+
//#region src/hover-card/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* A rich preview shown while the user shows interest in a link (hover or keyboard focus, after a
|
|
7
|
+
* delay): `Root` (no DOM) > `Trigger` (`a`) + `Popup` (`div[popover=manual][role=group]`, right
|
|
8
|
+
* after the Trigger). Unlike a Tooltip the card may hold links and buttons and is not the
|
|
9
|
+
* Trigger's description; unlike a Popover nothing is clicked to open it and opening never moves
|
|
10
|
+
* focus. Opening is a request (`openChangeAction(true)`, a transition: the content mounts and may
|
|
11
|
+
* suspend, the Trigger is `data-pending` meanwhile); every close the user causes is a fact
|
|
12
|
+
* (`onOpenChange(false)`).
|
|
13
|
+
*
|
|
14
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
15
|
+
*/
|
|
16
|
+
const HoverCard = {
|
|
17
|
+
Root: HoverCardRoot,
|
|
18
|
+
Trigger: HoverCardTrigger,
|
|
19
|
+
Popup: HoverCardPopup
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { HoverCard };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/hover-card/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`interestfor`, `interest-delay-*`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { HoverCardPopup } from \"./hover-card-popup.js\";\nimport { HoverCardRoot } from \"./hover-card-root.js\";\nimport { HoverCardTrigger } from \"./hover-card-trigger.js\";\n\n/**\n * A rich preview shown while the user shows interest in a link (hover or keyboard focus, after a\n * delay): `Root` (no DOM) > `Trigger` (`a`) + `Popup` (`div[popover=manual][role=group]`, right\n * after the Trigger). Unlike a Tooltip the card may hold links and buttons and is not the\n * Trigger's description; unlike a Popover nothing is clicked to open it and opening never moves\n * focus. Opening is a request (`openChangeAction(true)`, a transition: the content mounts and may\n * suspend, the Trigger is `data-pending` meanwhile); every close the user causes is a fact\n * (`onOpenChange(false)`).\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport const HoverCard = {\n Root: HoverCardRoot,\n Trigger: HoverCardTrigger,\n Popup: HoverCardPopup,\n} as const;\n\nexport type {\n HoverCardRootProps,\n HoverCardRootState,\n HoverCardOpenChangeDetails,\n} from \"./hover-card-root.js\";\nexport type { HoverCardTriggerProps, HoverCardTriggerState } from \"./hover-card-trigger.js\";\nexport type {\n HoverCardPopupProps,\n HoverCardPopupState,\n HoverCardSide,\n HoverCardAlign,\n} from \"./hover-card-popup.js\";\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,YAAY;CACvB,MAAM;CACN,SAAS;CACT,OAAO;AACT"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
3
|
+
import { createDelayedPair } from "../internal/use-delayed-pair.mjs";
|
|
4
|
+
import { useCallback, useEffect, useEffectEvent, useRef } from "react";
|
|
5
|
+
//#region src/hover-card/use-hover-card-interest.ts
|
|
6
|
+
/**
|
|
7
|
+
* When a HoverCard opens and closes (design/components/hover-card.md 2.2 to 2.4): the JS path's
|
|
8
|
+
* hover and keyboard-focus tracking with the `delay` / `closeDelay` timer pair (the helper
|
|
9
|
+
* Tooltip and Menu use), or, where the Trigger carries `interestfor` and implements
|
|
10
|
+
* `interestForElement`, nothing of that (the browser decides; the Popup hook routes its interest
|
|
11
|
+
* show and lost interest). On both paths: a press on the Trigger closes the card and cancels a
|
|
12
|
+
* coming open, Escape and a press outside close it while it is intended open, and the
|
|
13
|
+
* "no open until fresh interest" flag. Listeners go through `addEventListener` (conventions 7.4),
|
|
14
|
+
* so every `on*` prop of the Trigger passes through.
|
|
15
|
+
*
|
|
16
|
+
* Outcomes go through the Root: an open is `requestOpen(event, "activate")` (a request); a
|
|
17
|
+
* close of a shown card is a dismissal (an intent recorded, then `hidePopover()`; the `toggle`
|
|
18
|
+
* reports the fact, 2.5); a close while the open is still pending is
|
|
19
|
+
* `requestClose(event, "dismiss")`, which supersedes the open.
|
|
20
|
+
*/
|
|
21
|
+
function useHoverCardInterest(root, trigger, popup, options) {
|
|
22
|
+
const { disabled, interestForRequested, suppressed, active } = options;
|
|
23
|
+
const getEnv = useEffectEvent(() => ({
|
|
24
|
+
delay: options.delay,
|
|
25
|
+
closeDelay: options.closeDelay,
|
|
26
|
+
active: options.active,
|
|
27
|
+
root
|
|
28
|
+
}));
|
|
29
|
+
const controller = useRef(null);
|
|
30
|
+
const wasDisabled = useRef(disabled);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (popup === null) return;
|
|
33
|
+
const becameDisabled = disabled && !wasDisabled.current;
|
|
34
|
+
wasDisabled.current = disabled;
|
|
35
|
+
const attached = attachInterest(trigger, popup, {
|
|
36
|
+
disabled,
|
|
37
|
+
interestForRequested,
|
|
38
|
+
suppressed,
|
|
39
|
+
env: () => getEnv()
|
|
40
|
+
});
|
|
41
|
+
controller.current = attached;
|
|
42
|
+
attached.listenDocument(getEnv().active);
|
|
43
|
+
if (becameDisabled) attached.dismiss(void 0, false);
|
|
44
|
+
return () => {
|
|
45
|
+
attached.detach();
|
|
46
|
+
if (controller.current === attached) controller.current = null;
|
|
47
|
+
};
|
|
48
|
+
}, [
|
|
49
|
+
trigger,
|
|
50
|
+
popup,
|
|
51
|
+
disabled,
|
|
52
|
+
interestForRequested,
|
|
53
|
+
suppressed
|
|
54
|
+
]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
controller.current?.listenDocument(active);
|
|
57
|
+
}, [active]);
|
|
58
|
+
return { listenDocumentNow: useCallback(() => {
|
|
59
|
+
controller.current?.listenDocument(true);
|
|
60
|
+
}, []) };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Blurs the element focused inside `popup` (the popup itself included), so a hide that must
|
|
64
|
+
* return no focus to the Trigger leaves it on `<body>`: neither the Popup hook's focus-return
|
|
65
|
+
* fallback nor a `hint` popover's own restore applies (design 6.2). Returns whether focus was
|
|
66
|
+
* inside.
|
|
67
|
+
*/
|
|
68
|
+
function blurFocusInside(popup) {
|
|
69
|
+
const active = popup.ownerDocument.activeElement;
|
|
70
|
+
if (!(active instanceof HTMLElement) || !popup.contains(active)) return false;
|
|
71
|
+
active.blur();
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function attachInterest(trigger, popup, { disabled, interestForRequested, suppressed, env }) {
|
|
75
|
+
const doc = popup.ownerDocument;
|
|
76
|
+
const timers = createDelayedPair();
|
|
77
|
+
let watchingRelease = false;
|
|
78
|
+
const shown = () => popup.isConnected && isPopoverOpen(popup);
|
|
79
|
+
const dismiss = (event, returnFocus) => {
|
|
80
|
+
const { root } = env();
|
|
81
|
+
stopWatchingRelease();
|
|
82
|
+
if (shown()) {
|
|
83
|
+
const active = doc.activeElement;
|
|
84
|
+
const focusInside = active instanceof HTMLElement && active !== popup && popup.contains(active) || active === popup;
|
|
85
|
+
if (focusInside && !returnFocus && active instanceof HTMLElement) active.blur();
|
|
86
|
+
if (focusInside && returnFocus) suppressed.current = true;
|
|
87
|
+
root.recordCloseIntent({
|
|
88
|
+
reason: "dismiss",
|
|
89
|
+
event
|
|
90
|
+
});
|
|
91
|
+
popup.hidePopover();
|
|
92
|
+
if (focusInside && returnFocus && trigger !== null && trigger.isConnected && doc.activeElement !== trigger) trigger.focus();
|
|
93
|
+
} else if (root.intended() && !root.hiddenBeforeToggle()) root.requestClose(event, "dismiss");
|
|
94
|
+
timers.cancel();
|
|
95
|
+
};
|
|
96
|
+
const onDocumentKeyDown = (event) => {
|
|
97
|
+
if (event.key !== "Escape" || event.isComposing || event.defaultPrevented) return;
|
|
98
|
+
const isShown = shown();
|
|
99
|
+
if (!isShown && !env().root.intended()) return;
|
|
100
|
+
if (containsOpenLayer(popup)) return;
|
|
101
|
+
suppressed.current = true;
|
|
102
|
+
dismiss(event, true);
|
|
103
|
+
if (isShown) event.preventDefault();
|
|
104
|
+
};
|
|
105
|
+
const handled = /* @__PURE__ */ new WeakSet();
|
|
106
|
+
const onDocumentPointerDown = (event) => {
|
|
107
|
+
const path = event.composedPath();
|
|
108
|
+
if (path.includes(popup)) return;
|
|
109
|
+
if (!shown() && !env().root.intended()) return;
|
|
110
|
+
if (trigger !== null && path.includes(trigger)) suppressed.current = true;
|
|
111
|
+
handled.add(event);
|
|
112
|
+
dismiss(event, false);
|
|
113
|
+
};
|
|
114
|
+
let listening = false;
|
|
115
|
+
const listenDocument = (listen) => {
|
|
116
|
+
if (listen === listening) return;
|
|
117
|
+
listening = listen;
|
|
118
|
+
if (listen) {
|
|
119
|
+
doc.addEventListener("keydown", onDocumentKeyDown);
|
|
120
|
+
doc.addEventListener("pointerdown", onDocumentPointerDown, true);
|
|
121
|
+
} else {
|
|
122
|
+
doc.removeEventListener("keydown", onDocumentKeyDown);
|
|
123
|
+
doc.removeEventListener("pointerdown", onDocumentPointerDown, true);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const startOpen = (event) => {
|
|
127
|
+
const { root, delay } = env();
|
|
128
|
+
if (root.intended()) {
|
|
129
|
+
timers.cancel();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
timers.open(delay, () => {
|
|
133
|
+
if (trigger === null || !trigger.isConnected || !popup.isConnected) return;
|
|
134
|
+
if (env().root.intended()) return;
|
|
135
|
+
listenDocument(true);
|
|
136
|
+
env().root.requestOpen(event, "activate");
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
const startClose = (event) => {
|
|
140
|
+
const { root, closeDelay } = env();
|
|
141
|
+
if (!root.intended() && !shown()) {
|
|
142
|
+
timers.cancel();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
timers.close(closeDelay, () => dismiss(event, false));
|
|
146
|
+
};
|
|
147
|
+
function stopWatchingRelease() {
|
|
148
|
+
if (!watchingRelease) return;
|
|
149
|
+
watchingRelease = false;
|
|
150
|
+
doc.removeEventListener("pointerup", onRelease, true);
|
|
151
|
+
}
|
|
152
|
+
function onRelease(event) {
|
|
153
|
+
stopWatchingRelease();
|
|
154
|
+
startClose(event);
|
|
155
|
+
}
|
|
156
|
+
const cleanups = [];
|
|
157
|
+
const listen = (target, type, listener) => {
|
|
158
|
+
target.addEventListener(type, listener);
|
|
159
|
+
cleanups.push(() => target.removeEventListener(type, listener));
|
|
160
|
+
};
|
|
161
|
+
if (trigger !== null) {
|
|
162
|
+
listen(trigger, "pointerdown", (event) => {
|
|
163
|
+
suppressed.current = true;
|
|
164
|
+
if (handled.has(event)) timers.cancel();
|
|
165
|
+
else dismiss(event, false);
|
|
166
|
+
});
|
|
167
|
+
listen(trigger, "keydown", (event) => {
|
|
168
|
+
if (event.key !== "Escape" || event.isComposing) return;
|
|
169
|
+
suppressed.current = true;
|
|
170
|
+
timers.cancel();
|
|
171
|
+
});
|
|
172
|
+
const freshInterest = () => {
|
|
173
|
+
suppressed.current = false;
|
|
174
|
+
};
|
|
175
|
+
listen(trigger, "pointerleave", freshInterest);
|
|
176
|
+
listen(trigger, "blur", freshInterest);
|
|
177
|
+
listen(trigger, "pointerenter", freshInterest);
|
|
178
|
+
if (!(interestForRequested && trigger.hasAttribute("interestfor") && "interestForElement" in trigger) && !disabled) {
|
|
179
|
+
listen(trigger, "pointerenter", (event) => {
|
|
180
|
+
if (event.pointerType !== "touch") startOpen(event);
|
|
181
|
+
});
|
|
182
|
+
listen(trigger, "focus", (event) => {
|
|
183
|
+
if (suppressed.current || !trigger.matches(":focus-visible")) return;
|
|
184
|
+
startOpen(event);
|
|
185
|
+
});
|
|
186
|
+
listen(trigger, "pointerleave", startClose);
|
|
187
|
+
listen(trigger, "blur", startClose);
|
|
188
|
+
listen(popup, "pointerenter", () => {
|
|
189
|
+
stopWatchingRelease();
|
|
190
|
+
timers.cancelClose();
|
|
191
|
+
});
|
|
192
|
+
listen(popup, "pointerleave", (event) => {
|
|
193
|
+
if (!shown()) return;
|
|
194
|
+
if (event.buttons !== 0) {
|
|
195
|
+
if (!watchingRelease) {
|
|
196
|
+
watchingRelease = true;
|
|
197
|
+
doc.addEventListener("pointerup", onRelease, true);
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
startClose(event);
|
|
202
|
+
});
|
|
203
|
+
listen(popup, "focusin", () => timers.cancelClose());
|
|
204
|
+
listen(popup, "focusout", (event) => {
|
|
205
|
+
if (!shown()) return;
|
|
206
|
+
const next = event.relatedTarget;
|
|
207
|
+
if (next instanceof Node && (popup.contains(next) || trigger.contains(next))) return;
|
|
208
|
+
startClose(event);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
listenDocument,
|
|
214
|
+
dismiss,
|
|
215
|
+
detach: () => {
|
|
216
|
+
timers.cancel();
|
|
217
|
+
stopWatchingRelease();
|
|
218
|
+
listenDocument(false);
|
|
219
|
+
for (const cleanup of cleanups) cleanup();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Whether a popover or a modal dialog is open inside the card (design 2.6). Walks the elements and
|
|
225
|
+
* asks each, rather than one `querySelector(":popover-open")`, which the jsdom shim cannot answer.
|
|
226
|
+
*/
|
|
227
|
+
function containsOpenLayer(popup) {
|
|
228
|
+
for (const element of popup.querySelectorAll("[popover]")) if (isPopoverOpen(element)) return true;
|
|
229
|
+
for (const dialog of popup.querySelectorAll("dialog")) if (dialog.open && isModal(dialog)) return true;
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
function isModal(dialog) {
|
|
233
|
+
try {
|
|
234
|
+
return dialog.matches(":modal");
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { blurFocusInside, useHoverCardInterest };
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=use-hover-card-interest.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hover-card-interest.mjs","names":[],"sources":["../../src/hover-card/use-hover-card-interest.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useEffectEvent, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport { createDelayedPair } from \"../internal/use-delayed-pair.js\";\n\nexport interface HoverCardInterestOptions {\n readonly delay: number;\n readonly closeDelay: number;\n readonly disabled: boolean;\n /** The Trigger writes `interestfor` (flag on, not disabled). Re-runs the detection. */\n readonly interestForRequested: boolean;\n /** \"No open until fresh interest\" (design 2.4), shared with the Popup's interception. */\n readonly suppressed: RefObject<boolean>;\n /**\n * The document listeners are wanted: the card is intended open or shown (optimistic or\n * committed `open`). They also attach at the dispatch of an open, before that commit.\n */\n readonly active: boolean;\n}\n\n/** The Root's requests and refs the interest tracking drives. */\ntype Root = Pick<\n PopoverRootValue,\n \"intended\" | \"requestOpen\" | \"requestClose\" | \"recordCloseIntent\" | \"hiddenBeforeToggle\"\n>;\n\n/** What the effect's attached listeners expose to the second effect. */\ninterface InterestController {\n /** Attach (`true`) or detach the document Escape and outside-press listeners. */\n readonly listenDocument: (listen: boolean) => void;\n}\n\n/**\n * When a HoverCard opens and closes (design/components/hover-card.md 2.2 to 2.4): the JS path's\n * hover and keyboard-focus tracking with the `delay` / `closeDelay` timer pair (the helper\n * Tooltip and Menu use), or, where the Trigger carries `interestfor` and implements\n * `interestForElement`, nothing of that (the browser decides; the Popup hook routes its interest\n * show and lost interest). On both paths: a press on the Trigger closes the card and cancels a\n * coming open, Escape and a press outside close it while it is intended open, and the\n * \"no open until fresh interest\" flag. Listeners go through `addEventListener` (conventions 7.4),\n * so every `on*` prop of the Trigger passes through.\n *\n * Outcomes go through the Root: an open is `requestOpen(event, \"activate\")` (a request); a\n * close of a shown card is a dismissal (an intent recorded, then `hidePopover()`; the `toggle`\n * reports the fact, 2.5); a close while the open is still pending is\n * `requestClose(event, \"dismiss\")`, which supersedes the open.\n */\nexport function useHoverCardInterest(\n root: Root,\n trigger: HTMLElement | null,\n popup: HTMLElement | null,\n options: HoverCardInterestOptions,\n): HoverCardInterest {\n const { disabled, interestForRequested, suppressed, active } = options;\n const getEnv = useEffectEvent(() => ({\n delay: options.delay,\n closeDelay: options.closeDelay,\n active: options.active,\n root,\n }));\n const controller = useRef<InterestController | null>(null);\n // `disabled` of the previous run: becoming disabled closes a shown card (design 3.1).\n const wasDisabled = useRef(disabled);\n\n useEffect(() => {\n if (popup === null) return;\n const becameDisabled = disabled && !wasDisabled.current;\n wasDisabled.current = disabled;\n const attached = attachInterest(trigger, popup, {\n disabled,\n interestForRequested,\n suppressed,\n // The effect event is called (from the listeners this effect sets up), never passed itself.\n env: () => getEnv(),\n });\n controller.current = attached;\n attached.listenDocument(getEnv().active);\n if (becameDisabled) attached.dismiss(undefined, false);\n return () => {\n attached.detach();\n if (controller.current === attached) controller.current = null;\n };\n }, [trigger, popup, disabled, interestForRequested, suppressed]);\n\n useEffect(() => {\n controller.current?.listenDocument(active);\n }, [active]);\n\n const listenDocumentNow = useCallback(() => {\n controller.current?.listenDocument(true);\n }, []);\n return { listenDocumentNow };\n}\n\n/** What the Root passes on to its parts. */\nexport interface HoverCardInterest {\n /**\n * Attach the document Escape and outside-press listeners now: an open routed at the Popup's\n * `beforetoggle` (the flagged path's interest show), before its optimistic commit. Stable.\n */\n readonly listenDocumentNow: () => void;\n}\n\n/**\n * Blurs the element focused inside `popup` (the popup itself included), so a hide that must\n * return no focus to the Trigger leaves it on `<body>`: neither the Popup hook's focus-return\n * fallback nor a `hint` popover's own restore applies (design 6.2). Returns whether focus was\n * inside.\n */\nexport function blurFocusInside(popup: HTMLElement): boolean {\n const active = popup.ownerDocument.activeElement;\n if (!(active instanceof HTMLElement) || !popup.contains(active)) return false;\n active.blur();\n return true;\n}\n\ninterface AttachOptions {\n readonly disabled: boolean;\n readonly interestForRequested: boolean;\n readonly suppressed: RefObject<boolean>;\n readonly env: () => {\n readonly delay: number;\n readonly closeDelay: number;\n readonly active: boolean;\n readonly root: Root;\n };\n}\n\ninterface Attached extends InterestController {\n /** Close now (design 2.2, \"close now\"); `returnFocus`: Escape's focus return (6.2). */\n readonly dismiss: (event: Event | undefined, returnFocus: boolean) => void;\n readonly detach: () => void;\n}\n\nfunction attachInterest(\n trigger: HTMLElement | null,\n popup: HTMLElement,\n { disabled, interestForRequested, suppressed, env }: AttachOptions,\n): Attached {\n const doc = popup.ownerDocument;\n const timers = createDelayedPair();\n // A text selection dragged out of the card: the close timer starts at the release (2.2).\n let watchingRelease = false;\n\n const shown = (): boolean => popup.isConnected && isPopoverOpen(popup);\n\n const dismiss = (event: Event | undefined, returnFocus: boolean): void => {\n const { root } = env();\n stopWatchingRelease();\n if (shown()) {\n const active = doc.activeElement;\n const inside = active instanceof HTMLElement && active !== popup && popup.contains(active);\n const focusInside = inside || active === popup;\n // Lost interest and a press outside never focus the Trigger (6.2). Blurring first keeps\n // the platform from restoring focus too (a `hint` popover restores the element focused at\n // its show when focus is inside at the hide): focus goes to <body>, and a press then puts\n // it where the press lands.\n if (focusInside && !returnFocus && active instanceof HTMLElement) active.blur();\n // Escape with focus inside: the focus return that follows is not interest (2.4). Set\n // before the hide, which may restore focus to the Trigger itself (`hint`).\n if (focusInside && returnFocus) suppressed.current = true;\n // Recorded right before the hide, so its one-task clear cannot run first.\n root.recordCloseIntent({ reason: \"dismiss\", event });\n popup.hidePopover();\n if (\n focusInside &&\n returnFocus &&\n trigger !== null &&\n trigger.isConnected &&\n doc.activeElement !== trigger\n ) {\n trigger.focus();\n }\n } else if (root.intended() && !root.hiddenBeforeToggle()) {\n // Nothing shown yet: the open is still pending, and this supersedes it. Not a card that\n // was just hidden and whose `toggle` (the fact) has not arrived.\n root.requestClose(event, \"dismiss\");\n }\n timers.cancel();\n };\n\n // --- Document listeners, while the card is intended open ------------------------------------\n\n const onDocumentKeyDown = (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.isComposing || event.defaultPrevented) return;\n const isShown = shown();\n if (!isShown && !env().root.intended()) return;\n // The innermost closes first (2.6): a popover or modal dialog open inside the card takes\n // this Escape; the next one closes the card.\n if (containsOpenLayer(popup)) return;\n suppressed.current = true;\n dismiss(event, true);\n // This Escape was the card's: an enclosing modal dialog or `auto` popover stays open.\n if (isShown) event.preventDefault();\n };\n // The presses the document listener handled; the Trigger's own listener sees them next.\n const handled = new WeakSet<Event>();\n const onDocumentPointerDown = (event: PointerEvent): void => {\n const path = event.composedPath();\n if (path.includes(popup)) return;\n if (!shown() && !env().root.intended()) return;\n if (trigger !== null && path.includes(trigger)) suppressed.current = true;\n handled.add(event);\n dismiss(event, false);\n };\n let listening = false;\n const listenDocument = (listen: boolean): void => {\n if (listen === listening) return;\n listening = listen;\n if (listen) {\n doc.addEventListener(\"keydown\", onDocumentKeyDown);\n doc.addEventListener(\"pointerdown\", onDocumentPointerDown, true);\n } else {\n doc.removeEventListener(\"keydown\", onDocumentKeyDown);\n doc.removeEventListener(\"pointerdown\", onDocumentPointerDown, true);\n }\n };\n\n // --- Timers (the JS path) -------------------------------------------------------------------\n\n const startOpen = (event: Event): void => {\n const { root, delay } = env();\n // Already intended open (the pointer came back, Shift+Tab from the card): stay.\n if (root.intended()) {\n timers.cancel();\n return;\n }\n timers.open(delay, () => {\n if (trigger === null || !trigger.isConnected || !popup.isConnected) return;\n if (env().root.intended()) return;\n listenDocument(true);\n env().root.requestOpen(event, \"activate\");\n });\n };\n const startClose = (event: Event): void => {\n const { root, closeDelay } = env();\n // Nothing intended and nothing shown: only a coming open to cancel.\n if (!root.intended() && !shown()) {\n timers.cancel();\n return;\n }\n timers.close(closeDelay, () => dismiss(event, false));\n };\n\n function stopWatchingRelease(): void {\n if (!watchingRelease) return;\n watchingRelease = false;\n doc.removeEventListener(\"pointerup\", onRelease, true);\n }\n function onRelease(event: PointerEvent): void {\n stopWatchingRelease();\n startClose(event);\n }\n\n // --- Trigger and Popup listeners --------------------------------------------------------------\n\n const cleanups: (() => void)[] = [];\n const listen = <K extends keyof HTMLElementEventMap>(\n target: HTMLElement,\n type: K,\n listener: (event: HTMLElementEventMap[K]) => void,\n ): void => {\n target.addEventListener(type, listener);\n cleanups.push(() => target.removeEventListener(type, listener));\n };\n\n if (trigger !== null) {\n // Both paths: a press on the Trigger closes the card and cancels a coming open, and nothing\n // opens until fresh interest (2.4). The document's capture listener has already closed a\n // card that is intended open; this covers the open timer and the flagged path's interest.\n listen(trigger, \"pointerdown\", (event) => {\n suppressed.current = true;\n if (handled.has(event)) timers.cancel();\n else dismiss(event, false);\n });\n // Escape before anything is intended: cancel the coming open.\n listen(trigger, \"keydown\", (event) => {\n if (event.key !== \"Escape\" || event.isComposing) return;\n suppressed.current = true;\n timers.cancel();\n });\n // Fresh interest: the pointer comes back, or focus leaves (and later returns).\n const freshInterest = () => {\n suppressed.current = false;\n };\n listen(trigger, \"pointerleave\", freshInterest);\n listen(trigger, \"blur\", freshInterest);\n listen(trigger, \"pointerenter\", freshInterest);\n\n // Flagged path (conventions 8): the browser decides when interest starts and ends where the\n // flag wrote `interestfor` and the element implements it; a `render`ed element without\n // `interestForElement` keeps the JS path.\n const native =\n interestForRequested &&\n trigger.hasAttribute(\"interestfor\") &&\n \"interestForElement\" in trigger;\n if (!native && !disabled) {\n listen(trigger, \"pointerenter\", (event) => {\n // No hover on touch (7): a tap follows the link.\n if (event.pointerType !== \"touch\") startOpen(event);\n });\n listen(trigger, \"focus\", (event) => {\n // Keyboard focus only; the library's own focus return is not interest (2.4).\n if (suppressed.current || !trigger.matches(\":focus-visible\")) return;\n startOpen(event);\n });\n listen(trigger, \"pointerleave\", startClose);\n listen(trigger, \"blur\", startClose);\n listen(popup, \"pointerenter\", () => {\n stopWatchingRelease();\n timers.cancelClose();\n });\n listen(popup, \"pointerleave\", (event) => {\n if (!shown()) return;\n if (event.buttons !== 0) {\n if (!watchingRelease) {\n watchingRelease = true;\n doc.addEventListener(\"pointerup\", onRelease, true);\n }\n return;\n }\n startClose(event);\n });\n listen(popup, \"focusin\", () => timers.cancelClose());\n listen(popup, \"focusout\", (event) => {\n // The platform's focus fixup after a hide is no interest change.\n if (!shown()) return;\n const next = event.relatedTarget;\n if (next instanceof Node && (popup.contains(next) || trigger.contains(next))) return;\n startClose(event);\n });\n }\n }\n\n return {\n listenDocument,\n dismiss,\n detach: () => {\n timers.cancel();\n stopWatchingRelease();\n listenDocument(false);\n for (const cleanup of cleanups) cleanup();\n },\n };\n}\n\n/**\n * Whether a popover or a modal dialog is open inside the card (design 2.6). Walks the elements and\n * asks each, rather than one `querySelector(\":popover-open\")`, which the jsdom shim cannot answer.\n */\nfunction containsOpenLayer(popup: HTMLElement): boolean {\n for (const element of popup.querySelectorAll(\"[popover]\")) {\n if (isPopoverOpen(element)) return true;\n }\n for (const dialog of popup.querySelectorAll(\"dialog\")) {\n if (dialog.open && isModal(dialog)) return true;\n }\n return false;\n}\n\nfunction isModal(dialog: HTMLDialogElement): boolean {\n try {\n return dialog.matches(\":modal\");\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,qBACd,MACA,SACA,OACA,SACmB;CACnB,MAAM,EAAE,UAAU,sBAAsB,YAAY,WAAW;CAC/D,MAAM,SAAS,sBAAsB;EACnC,OAAO,QAAQ;EACf,YAAY,QAAQ;EACpB,QAAQ,QAAQ;EAChB;CACF,EAAE;CACF,MAAM,aAAa,OAAkC,IAAI;CAEzD,MAAM,cAAc,OAAO,QAAQ;CAEnC,gBAAgB;EACd,IAAI,UAAU,MAAM;EACpB,MAAM,iBAAiB,YAAY,CAAC,YAAY;EAChD,YAAY,UAAU;EACtB,MAAM,WAAW,eAAe,SAAS,OAAO;GAC9C;GACA;GACA;GAEA,WAAW,OAAO;EACpB,CAAC;EACD,WAAW,UAAU;EACrB,SAAS,eAAe,OAAO,CAAC,CAAC,MAAM;EACvC,IAAI,gBAAgB,SAAS,QAAQ,KAAA,GAAW,KAAK;EACrD,aAAa;GACX,SAAS,OAAO;GAChB,IAAI,WAAW,YAAY,UAAU,WAAW,UAAU;EAC5D;CACF,GAAG;EAAC;EAAS;EAAO;EAAU;EAAsB;CAAU,CAAC;CAE/D,gBAAgB;EACd,WAAW,SAAS,eAAe,MAAM;CAC3C,GAAG,CAAC,MAAM,CAAC;CAKX,OAAO,EAAE,mBAHiB,kBAAkB;EAC1C,WAAW,SAAS,eAAe,IAAI;CACzC,GAAG,CAAC,CACqB,EAAE;AAC7B;;;;;;;AAiBA,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,S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