@citrusworx/juiceui 0.9.6 → 0.9.7

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.
@@ -21,12 +21,12 @@
21
21
  * `aria-activedescendant` plus `combobox-option="active"` paint.
22
22
  * Committed choice is `aria-selected="true"`.
23
23
  *
24
- * Open on input focus, typing, or trigger click. Close on Escape
25
- * (yields when an open [modal-overlay], [drawer-overlay],
26
- * [popover-root], or [menu] exists — those surfaces own Escape first;
27
- * menu sits with popover in the dialog-adjacent band),
28
- * outside click, blur (option mousedown preventDefault so the input
29
- * keeps focus through click-to-select), or after select.
24
+ * Open on input focus, typing, or trigger click. Close on Escape from
25
+ * the layer stack (the last layer opened owns it; this runtime does not
26
+ * handle Escape itself), outside pointerdown when this list is the top
27
+ * layer, blur (option mousedown preventDefault so the input keeps focus
28
+ * through click-to-select), or after select. A cascade close uses the
29
+ * same hide path and does not move focus.
30
30
  *
31
31
  * Filter: case-insensitive substring against option text and, when
32
32
  * present, `data-value`. Non-matches get `hidden` on the option.
@@ -38,7 +38,7 @@
38
38
  * Home / End first / last visible option while open
39
39
  * (closed: native input cursor)
40
40
  * Enter select the active option
41
- * Escape close (yields to open dialog / popover / menu)
41
+ * Escape close when this list is the top layer
42
42
  * Tab close without committing the active option
43
43
  * (APG manual selection). Focus moves on.
44
44
  *
@@ -7,9 +7,16 @@
7
7
  * Enter removes `hidden`, then plays. Exit plays first; `hidden` is set
8
8
  * only after it finishes. Focus moves in when `hidden` is removed and
9
9
  * restores when `hidden` is set. Reduced motion (or a zero computed
10
- * duration) does both in the same turn. An in-flight exit stays the open
11
- * dialog for Escape and the focus trap until that commit, and a new open
12
- * cancels it.
10
+ * duration) does both in the same turn. An in-flight exit stays on the
11
+ * layer stack for Escape and the focus trap until that commit, and a new
12
+ * open cancels it. Escape and backdrop presses follow open order on the
13
+ * internal layer stack. This runtime does not handle Escape itself, so a
14
+ * defaultPrevented Escape never closes the dialog. Tab and focus-in trap
15
+ * only when this overlay is the top of the stack and that layer is modal.
16
+ * A non-modal layer on top suspends the trap until it closes. Replacing
17
+ * another open drawer pops it, so layers above that drawer dismiss with
18
+ * reason 'cascade'. A cascade close does not return focus. Escape, an
19
+ * explicit close, and a backdrop close still do.
13
20
  *
14
21
  * Openers: any element whose `aria-controls` token list includes a
15
22
  * `[drawer-overlay]` id. `[drawer-close]` closes the containing overlay.
@@ -29,17 +29,18 @@
29
29
  * Open on opener click / Enter / Space (native buttons use click).
30
30
  * ArrowDown on a closed opener opens and focuses the first enabled item
31
31
  * (or the previously active item). ArrowUp opens onto the last enabled
32
- * item. Close on Escape (yields when an open [modal-overlay] or
33
- * [drawer-overlay] exists — menu sits with popover in the dialog-adjacent
34
- * band), outside click, Tab (closes without activating; focus returns
35
- * to the opener so Tab's default can move to the next/previous control),
36
- * or after activating an item. Activating an item clicks it and restores
37
- * focus to the opener. Disabled items are intercepted on capture so
38
- * author click handlers never run. Opening one managed menu closes the
39
- * others. Modal / drawer / popover are not auto-closed. ArrowUp/Down on
40
- * a closed menu apply only to the opener. A controller claims opener
41
- * clicks only when it can resolve a panel (custom `menuSelector` can
42
- * coexist with the auto singleton).
32
+ * item. Close on Escape from the layer stack (the last layer opened owns
33
+ * it; this runtime does not handle Escape itself), outside pointerdown
34
+ * when this menu is the top layer, Tab (closes without activating only
35
+ * while it is the top layer; focus returns to the opener so Tab's default
36
+ * can move to the next/previous control), or after activating an item.
37
+ * Activating an item clicks it and restores focus to the opener. A
38
+ * cascade close does not restore focus. Disabled items are intercepted
39
+ * on capture so author click handlers never run. Opening one managed
40
+ * menu closes the others. Modal / drawer / popover are not auto-closed.
41
+ * ArrowUp/Down on a closed menu apply only to the opener. A controller
42
+ * claims opener clicks only when it can resolve a panel (custom
43
+ * `menuSelector` can coexist with the auto singleton).
43
44
  */
44
45
  export type MenuOptions = {
45
46
  root?: ParentNode;
@@ -7,9 +7,16 @@
7
7
  * Enter removes `hidden`, then plays. Exit plays first; `hidden` is set
8
8
  * only after it finishes. Focus moves in when `hidden` is removed and
9
9
  * restores when `hidden` is set. Reduced motion (or a zero computed
10
- * duration) does both in the same turn. An in-flight exit stays the open
11
- * dialog for Escape and the focus trap until that commit, and a new open
12
- * cancels it.
10
+ * duration) does both in the same turn. An in-flight exit stays on the
11
+ * layer stack for Escape and the focus trap until that commit, and a new
12
+ * open cancels it. Escape and backdrop presses follow open order on the
13
+ * internal layer stack. This runtime does not handle Escape itself, so a
14
+ * defaultPrevented Escape never closes the dialog. Tab and focus-in trap
15
+ * only when this overlay is the top of the stack and that layer is modal.
16
+ * A non-modal layer on top suspends the trap until it closes. Replacing
17
+ * another open modal pops it, so layers above that modal dismiss with
18
+ * reason 'cascade'. A cascade close does not return focus. Escape, an
19
+ * explicit close, and a backdrop close still do.
13
20
  *
14
21
  * Openers: any element whose `aria-controls` token list includes a
15
22
  * `[modal-overlay]` id. `[modal-close]` closes the containing overlay.
@@ -34,13 +34,15 @@
34
34
  * No shift / size middleware. Repositions on open, window resize, and
35
35
  * capture scroll (rAF-throttled).
36
36
  *
37
- * Escape closes the open popover on bubble (after modal/drawer capture),
38
- * and also yields when an open [modal-overlay] or [drawer-overlay] exists
39
- * or the event is already defaultPrevented (those dialogs own Escape).
40
- * Menu sits in the same dialog-adjacent band as popover (peers do not
41
- * yield to each other). Combobox / toast / tooltip yield to an open
42
- * popover or menu. Opening one managed popover closes the others. Modal
43
- * / drawer / menu are not auto-closed.
37
+ * Escape and outside pointerdown come from the internal layer stack.
38
+ * The last layer opened owns them. This runtime does not handle Escape
39
+ * itself, so a defaultPrevented Escape never closes the popover. An
40
+ * outside pointer closes only this layer when it is on top. Closing a
41
+ * layer under this popover dismisses it with reason 'cascade' and does
42
+ * not restore focus; Escape and an explicit close still restore focus
43
+ * to the opener. Outside click does not. Tab traps only while this
44
+ * popover is the top of the stack. Opening one managed popover closes
45
+ * the others. Modal / drawer / menu are not auto-closed.
44
46
  */
45
47
  export type PopoverPlacement = 'top' | 'bottom' | 'left' | 'right';
46
48
  export type PopoverOptions = {
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Internal binding from modal, drawer, and sheet onto the layer stack.
3
+ * Not a public export.
4
+ *
5
+ * Each open overlay is one stack slot. push happens on open. pop happens
6
+ * when the close commits (hidden is set), so an in-flight exit stays the
7
+ * open dialog until then. Destroy drops the slot with no dismiss.
8
+ * Replacing an open dialog pops it, so layers above dismiss top-down with
9
+ * reason 'cascade'. A cascade dismiss closes that dialog and skips opener
10
+ * focus restore. The dialog that was popped still restores when its own
11
+ * close asked for one. The focus trap belongs to a runtime only when its
12
+ * overlay is the top of the stack and that layer is modal. A non-modal
13
+ * sheet on top suspends the trap until it closes.
14
+ *
15
+ * A backdrop press is a pointer whose target is the overlay element.
16
+ * The stack treats that press as outside every layer that does not
17
+ * contain the target, so a lower backdrop dismisses only the top dialog.
18
+ * The top dialog's own backdrop is inside its layer; the runtime closes
19
+ * that one from click, and only if it was the top layer when the press
20
+ * began. Presses on openers or the rest of the page are not backdrop
21
+ * presses, so they do not dismiss a dialog.
22
+ */
23
+ import { type LayerDismissReason, type LayerKind } from './layer-stack.js';
24
+ /**
25
+ * Cascade means a parent layer closed this dialog. That close skips
26
+ * opener restore. Escape and outside still restore.
27
+ */
28
+ export declare const dialogDismissRestoresFocus: (reason: LayerDismissReason) => reason is "escape" | "outside";
29
+ export type DialogLayerController = {
30
+ /** Stack an open overlay. bringToTop re-pushes an existing slot to the top. */
31
+ connect: (overlay: HTMLElement, bringToTop?: boolean) => void;
32
+ /** Remove this slot without dismissing layers above it. */
33
+ drop: (overlay: HTMLElement) => void;
34
+ /** Pop this slot. Layers above it dismiss with reason 'cascade'. */
35
+ pop: (overlay: HTMLElement) => void;
36
+ /** Match the stack to overlays that are currently open. */
37
+ reconcile: () => void;
38
+ destroy: () => void;
39
+ };
40
+ /**
41
+ * Top layer when the pointer went down, before the stack dismissed anyone.
42
+ * undefined when this click was not preceded by a pointerdown. Callers
43
+ * then read the live top, which is what click-only tests dispatch.
44
+ */
45
+ export declare const backdropPressTop: () => HTMLElement | null | undefined;
46
+ /**
47
+ * True when the latest pointerdown target is a dialog overlay element.
48
+ * Dialog dismiss('outside') ignores every other press.
49
+ */
50
+ export declare const outsidePressIsBackdrop: () => boolean;
51
+ /** Clears the backdrop-press snapshot. Test-only. */
52
+ export declare const __resetDialogLayersForTests: () => void;
53
+ export declare const createDialogLayers: (config: {
54
+ kind: Extract<LayerKind, "modal" | "drawer" | "sheet">;
55
+ selector: string;
56
+ getOverlays: () => readonly HTMLElement[];
57
+ isOpen: (overlay: HTMLElement) => boolean;
58
+ isClosing: (overlay: HTMLElement) => boolean;
59
+ isModal: (overlay: HTMLElement) => boolean;
60
+ shouldStack: (overlay: HTMLElement) => boolean;
61
+ dismiss: (overlay: HTMLElement, reason: LayerDismissReason) => void;
62
+ }) => DialogLayerController;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Internal open-order overlay stack. Not a public export.
3
+ *
4
+ * Modal, drawer, sheet, popover, menu, and combobox share this stack
5
+ * so the last one opened owns Escape and outside pointerdown. Dialog
6
+ * outside presses stay backdrop-only. Toast and tooltip stay off the
7
+ * stack. Sheet body scroll lock is acquireScrollLock. Modal and drawer
8
+ * do not lock scroll.
9
+ *
10
+ * Order is open time. The last push is the top. Pushing an element that
11
+ * is already stacked refreshes that slot in place (kind, modal, dismiss,
12
+ * focus opt-in, containsTarget). It does not move the slot and it does
13
+ * not add a second entry. Pop it and push it again to bring it to the
14
+ * top. Every pop function returned for that element closes the same
15
+ * slot. Calling pop again is a no-op.
16
+ *
17
+ * pop() removes this entry without calling its dismiss, because the
18
+ * caller is already closing it. Layers above it are dismissed first,
19
+ * top-down, with reason 'cascade', and then this entry is removed.
20
+ * Pass { cascade: false } or call removeLayer(el) to drop one entry
21
+ * with no dismiss calls and no focus return. That is the destroy path.
22
+ *
23
+ * Focus return is opt-in so a runtime that already restores focus does
24
+ * not do it twice. Omit restoreFocus to skip it. Set restoreFocus to an
25
+ * element or null to opt in. pop() focuses that opener when it is still
26
+ * connected and is not inside a layer this pop closed. Otherwise it
27
+ * focuses the new top layer's element, if one remains. The fallback
28
+ * focuses that element itself, not a descendant. When the element has
29
+ * no tabindex, the fallback sets tabindex="-1" so programmatic focus
30
+ * works without putting the layer in tab order. An existing tabindex
31
+ * is left as it is.
32
+ *
33
+ * One document keydown listener and one document pointerdown listener,
34
+ * both capture, attach on the first push and detach when the stack is
35
+ * empty. They call dismiss. They do not pop. dismiss must call the pop
36
+ * function or removeLayer, or that layer stays on top. An outside
37
+ * pointerdown walks from the top until a layer contains the target, or
38
+ * through the whole stack when none do. If dismiss leaves the same
39
+ * element on top, the walk stops.
40
+ *
41
+ * containsTarget is the portal seam. The default check is
42
+ * el.contains(target). TODO(portal): a portaled panel is not a
43
+ * descendant of el, so the runtime passes containsTarget that also
44
+ * includes the portaled node.
45
+ *
46
+ * acquireScrollLock is the ref-counted inline body overflow lock sheet
47
+ * uses. Modal and drawer do not lock scroll in S3.
48
+ * The first acquire saves body.style.overflow and sets 'hidden'. The
49
+ * last release restores the saved inline value. Release is idempotent.
50
+ * A stylesheet overflow is not read or written.
51
+ *
52
+ * Every function no-ops when document is undefined.
53
+ * __resetLayerStackForTests is for unit tests, not the public entry.
54
+ */
55
+ export type LayerKind = 'modal' | 'drawer' | 'sheet' | 'popover' | 'menu' | 'combobox';
56
+ export type LayerDismissReason = 'escape' | 'outside' | 'cascade';
57
+ export interface LayerEntry {
58
+ el: HTMLElement;
59
+ kind: LayerKind;
60
+ modal: boolean;
61
+ dismiss(reason: LayerDismissReason): void;
62
+ /**
63
+ * Opt in to stack-managed focus return. Omit the property when the
64
+ * runtime restores focus itself. null opts in with no opener.
65
+ */
66
+ restoreFocus?: HTMLElement | null;
67
+ /**
68
+ * Portal seam. Default containment is el.contains(target).
69
+ * TODO(portal): include the portaled node here. It is not inside el.
70
+ */
71
+ containsTarget?: (target: EventTarget | null) => boolean;
72
+ }
73
+ export type PopLayerOptions = {
74
+ /**
75
+ * When false, remove this entry only. Do not dismiss layers above it
76
+ * and do not run focus return. Default true.
77
+ */
78
+ cascade?: boolean;
79
+ };
80
+ export type PopLayer = (options?: PopLayerOptions) => void;
81
+ export declare const pushLayer: (entry: LayerEntry) => PopLayer;
82
+ export declare const removeLayer: (el: HTMLElement) => void;
83
+ export declare const topLayer: () => LayerEntry | null;
84
+ export declare const isTopLayer: (el: HTMLElement) => boolean;
85
+ export declare const topModalLayer: () => LayerEntry | null;
86
+ export declare const acquireScrollLock: () => (() => void);
87
+ /** Clears stack, listeners, and scroll-lock state. Test-only. */
88
+ export declare const __resetLayerStackForTests: () => void;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Internal binding from popover, menu, and combobox onto the layer stack.
3
+ * Not a public export.
4
+ *
5
+ * Each open widget is one stack slot. push happens on open. pop happens
6
+ * when the close commits, so a popover's in-flight exit stays the open
7
+ * layer until `hidden` is set. Destroy drops the slot and does not
8
+ * dismiss anything above it. These layers are not modal. Focus return
9
+ * stays in the runtime.
10
+ *
11
+ * Outside pointerdown dismisses only the top layer. dismiss('outside')
12
+ * hides the widget and removes the slot after the stack's pointer walk,
13
+ * so a lower layer stays up. The click that follows that pointer is not
14
+ * a second outside close. Openers that live outside the layer element
15
+ * belong in containsTarget, so pressing the opener is not outside and
16
+ * the click handler can still toggle.
17
+ *
18
+ * Toast and tooltip are not light layers. They stay off the stack.
19
+ */
20
+ import { type LayerDismissReason, type LayerKind } from './layer-stack.js';
21
+ export type LightLayerController = {
22
+ /** Stack an open widget. bringToTop re-pushes an existing slot to the top. */
23
+ connect: (el: HTMLElement, bringToTop?: boolean) => void;
24
+ /** Remove this slot without dismissing layers above it. */
25
+ drop: (el: HTMLElement) => void;
26
+ /** Pop this slot. Layers above it dismiss with reason 'cascade'. */
27
+ pop: (el: HTMLElement) => void;
28
+ /**
29
+ * Pop after the current stack pointer walk. dismiss('outside') uses
30
+ * this so the walk still sees this element on top and stops.
31
+ */
32
+ popAfterPointer: (el: HTMLElement) => void;
33
+ /** Match the stack to widgets that are currently open. */
34
+ reconcile: () => void;
35
+ destroy: () => void;
36
+ };
37
+ /**
38
+ * True when this click follows a stack outside-dismiss in the same
39
+ * gesture. Click handlers skip a second outside close.
40
+ */
41
+ export declare const lightOutsideAlreadyDismissed: () => boolean;
42
+ export declare const markLightOutsideDismissed: () => void;
43
+ /** Clears the outside-dismiss snapshot and handle map. Test-only. */
44
+ export declare const __resetLightLayersForTests: () => void;
45
+ export declare const createLightLayers: (config: {
46
+ kind: Extract<LayerKind, "popover" | "menu" | "combobox">;
47
+ getElements: () => readonly HTMLElement[];
48
+ isOpen: (el: HTMLElement) => boolean;
49
+ isClosing?: (el: HTMLElement) => boolean;
50
+ containsTarget?: (el: HTMLElement, target: EventTarget | null) => boolean;
51
+ dismiss: (el: HTMLElement, reason: LayerDismissReason) => void;
52
+ }) => LightLayerController;
@@ -1,12 +1,16 @@
1
1
  /**
2
- * Internal open-surface queries for Escape yield. Not a public export.
2
+ * Internal open-surface queries. Not a public export.
3
3
  * Selectors match the polish A/B overlay contract.
4
4
  *
5
- * Yield order (highest owns Escape first):
6
- * modal/drawer/sheet overlay → popover ≈ menu (same band) → combobox →
7
- * toast / tooltip. Menu closed vs open is native `hidden` on `[menu]`,
8
- * not on `[menu-root]`. Sheet closed vs open is native `hidden` on
9
- * `[sheet-overlay]`, including `sheet-overlay="none"`.
5
+ * Modal, drawer, sheet, popover, menu, and combobox take Escape from
6
+ * the layer stack (last opened wins). These queries stay because toast
7
+ * and disclosure are not stack layers and still yield when one of those
8
+ * surfaces is open in the DOM. Tooltip does not consult them: an open
9
+ * tip consumes Escape itself and does not close the layer under it.
10
+ *
11
+ * Menu closed vs open is native `hidden` on `[menu]`, not on
12
+ * `[menu-root]`. Sheet closed vs open is native `hidden` on
13
+ * `[sheet-overlay]`, including `sheet-overlay="none"`.
10
14
  */
11
15
  export declare const hasOpenDialogOverlay: () => boolean;
12
16
  export declare const hasOpenPopover: () => boolean;
@@ -9,8 +9,16 @@
9
9
  * only after it finishes. Focus moves in when a modal `hidden` is removed
10
10
  * and restores when that `hidden` is set. Reduced motion (or a zero
11
11
  * computed duration) does both in the same turn. An in-flight exit stays
12
- * the open dialog for Escape and the focus trap until that commit, and a
13
- * new open of that same overlay cancels it.
12
+ * on the layer stack for Escape and the focus trap until that commit, and
13
+ * a new open of that same overlay cancels it. Escape and backdrop presses
14
+ * follow open order on the internal layer stack. This runtime does not
15
+ * handle Escape itself, so a defaultPrevented Escape never closes the
16
+ * sheet. Tab and focus-in trap only when this overlay is the top of the
17
+ * stack and that layer is modal. `sheet-overlay="none"` never traps, and
18
+ * while that non-modal sheet is the top layer it suspends the trap of a
19
+ * modal underneath. The trap resumes when the sheet closes. Focus return
20
+ * stays here. A cascade close does not return focus. Escape, an explicit
21
+ * close, and a backdrop close still do.
14
22
  *
15
23
  * Openers: any element whose `aria-controls` token list includes a
16
24
  * `[sheet-overlay]` id. `[sheet-close]` closes the containing overlay.
@@ -18,11 +26,12 @@
18
26
  * `closeOnBackdrop` is false. `sheet-overlay="none"` is non-modal: no
19
27
  * focus trap, no scroll lock, no backdrop close. Escape still closes.
20
28
  *
21
- * Scroll lock is modal only (boolean / omitted / "static"). A shared
22
- * counter locks `document.body` overflow on the first modal sheet and
23
- * restores the previous inline overflow when the last one closes, so
24
- * nested and sibling modal sheets do not unlock early. Several sheets
25
- * may be open together. This runtime does not close siblings.
29
+ * Scroll lock is modal only (boolean / omitted / "static"). It uses the
30
+ * layer stack's ref-counted body overflow lock: the first modal sheet
31
+ * saves the inline overflow and sets `hidden`, and the last release
32
+ * restores that saved value. Nested and sibling modal sheets do not
33
+ * unlock early. Non-modal sheets do not lock. Several sheets may be
34
+ * open together. This runtime does not close siblings.
26
35
  *
27
36
  * Detents. `sheet-detents` on `[sheet]` is the allowed set (`~=` words).
28
37
  * Absent, or with no known word, the set is "half full". Rank is
@@ -23,11 +23,12 @@
23
23
  *
24
24
  * Auto-dismiss pauses while pointer or focus is inside the toast, then resumes.
25
25
  *
26
- * Escape dismisses the most recently shown visible toast, but only when no
27
- * open [modal-overlay], [drawer-overlay], [popover-root], [menu],
28
- * [combobox-list], or [tooltip-root] exists (those surfaces own Escape
29
- * first; menu sits with popover). An open tip hides while toasts remain
30
- * — toast does not steal Escape from tooltip.
26
+ * Escape dismisses the most recently shown visible toast, but only when
27
+ * the layer stack is empty and no open dialog, popover, menu, combobox
28
+ * list, or tooltip is in the DOM. Toast is not a stack layer. It listens
29
+ * on bubble, so a stack Escape (capture, stopPropagation) never reaches
30
+ * it, and it does not preventDefault when it yields. An open tip hides
31
+ * while toasts remain — toast does not steal Escape from tooltip.
31
32
  *
32
33
  * Live region: sync fills missing aria-live="polite" and
33
34
  * aria-relevant="additions" on [toast-region]. Opt into assertive with
@@ -32,11 +32,12 @@
32
32
  * flip once to the opposite side. Repositions on open, window resize,
33
33
  * and capture scroll (rAF-throttled).
34
34
  *
35
- * Escape hides the open tip on bubble, but yields when an open
36
- * [modal-overlay], [drawer-overlay], [popover-root], [menu], or
37
- * [combobox-list] exists, or the event is already defaultPrevented
38
- * (same courtesy as toast / popover). Menu sits with popover in the
39
- * dialog-adjacent band. Toast does not block tooltip Escape — the tip
35
+ * Escape hides the open tip on window capture, before the layer stack's
36
+ * document listener. The tip is not a stack layer, so it does not take
37
+ * a place in last-opened-wins. One Escape dismisses only the tip and
38
+ * does not close a dialog, popover, menu, or listbox underneath. The
39
+ * next Escape is the stack's. A defaultPrevented or composing Escape
40
+ * does not hide the tip. Toast does not block tooltip Escape — the tip
40
41
  * can hide while toasts remain. Opening one managed tooltip closes the
41
42
  * others.
42
43
  */