@c9up/nebula 0.2.3 → 0.2.4
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/README.md +7 -6
- package/dist/atoms/Avatar.d.ts +14 -0
- package/dist/atoms/Avatar.js +46 -8
- package/dist/cli/add.d.ts +2 -0
- package/dist/cli/add.js +4 -1
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.js +4 -1
- package/dist/cli/projectConfig.d.ts +16 -0
- package/dist/cli/projectConfig.js +61 -0
- package/dist/console/AddCommand.js +6 -1
- package/dist/console/DiffCommand.js +6 -1
- package/dist/lib/icons.d.ts +8 -0
- package/dist/lib/icons.js +8 -0
- package/dist/lib/image.js +12 -1
- package/dist/molecules/InputOTP.d.ts +12 -0
- package/dist/molecules/InputOTP.js +68 -27
- package/dist/molecules/index.d.ts +1 -1
- package/dist/molecules/index.js +1 -1
- package/dist/organisms/Combobox.d.ts +13 -0
- package/dist/organisms/Combobox.js +5 -2
- package/dist/organisms/Command.js +56 -8
- package/dist/organisms/Form.d.ts +15 -0
- package/dist/organisms/Form.js +10 -0
- package/dist/organisms/Select.d.ts +6 -4
- package/dist/organisms/Select.js +1 -0
- package/dist/organisms/Sidebar.d.ts +4 -2
- package/dist/organisms/Sidebar.js +54 -26
- package/dist/organisms/Sonner.d.ts +243 -0
- package/dist/organisms/Sonner.js +909 -0
- package/dist/organisms/Toaster.d.ts +9 -0
- package/dist/organisms/Toaster.js +28 -5
- package/dist/organisms/Tooltip.d.ts +4 -0
- package/dist/organisms/index.d.ts +6 -0
- package/dist/organisms/index.js +6 -0
- package/dist/primitives/dismissable.d.ts +11 -4
- package/dist/primitives/dismissable.js +8 -6
- package/dist/primitives/floating.d.ts +5 -1
- package/dist/primitives/floating.js +8 -1
- package/dist/primitives/menu.js +2 -1
- package/dist/primitives/modalSurface.js +70 -36
- package/dist/primitives/presence.js +8 -5
- package/nebula.css +2 -2
- package/package.json +1 -1
- package/registry.json +13 -0
- package/src/atoms/Avatar.ts +54 -7
- package/src/cli/add.ts +7 -1
- package/src/cli/diff.ts +7 -1
- package/src/cli/projectConfig.ts +71 -0
- package/src/console/AddCommand.ts +6 -1
- package/src/console/DiffCommand.ts +6 -1
- package/src/lib/icons.ts +28 -0
- package/src/lib/image.ts +13 -1
- package/src/molecules/InputOTP.ts +81 -27
- package/src/molecules/index.ts +3 -0
- package/src/organisms/Combobox.ts +18 -2
- package/src/organisms/Command.ts +66 -7
- package/src/organisms/Form.ts +21 -0
- package/src/organisms/Select.ts +7 -4
- package/src/organisms/Sidebar.ts +47 -19
- package/src/organisms/Sonner.ts +1366 -0
- package/src/organisms/Toaster.ts +30 -6
- package/src/organisms/Tooltip.ts +4 -0
- package/src/organisms/index.ts +23 -0
- package/src/primitives/dismissable.ts +16 -8
- package/src/primitives/floating.ts +13 -2
- package/src/primitives/menu.ts +2 -1
- package/src/primitives/modalSurface.ts +77 -40
- package/src/primitives/presence.ts +12 -9
package/src/organisms/Toaster.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Toaster — transient notifications.
|
|
3
3
|
*
|
|
4
|
+
* @deprecated shadcn has deprecated its `toast` component in favour of
|
|
5
|
+
* `sonner`, and so does nebula: use `organisms/Sonner.ts` (`nebula add
|
|
6
|
+
* sonner`), whose `Toaster` and `toast` follow sonner's API. This one stays
|
|
7
|
+
* until apps have moved.
|
|
8
|
+
*
|
|
4
9
|
* shadcn ships two: `sonner`, which wraps a third-party library, and `toast`,
|
|
5
10
|
* its own, built on Base UI. nebula keeps it in-house with zero dependencies
|
|
6
11
|
* and follows the SECOND — the shape is the same: one region mounted once near
|
|
@@ -36,7 +41,7 @@
|
|
|
36
41
|
* single most common complaint about the pattern.
|
|
37
42
|
*/
|
|
38
43
|
|
|
39
|
-
import { component, html, signal } from "@c9up/aurora";
|
|
44
|
+
import { component, html, onMount, signal } from "@c9up/aurora";
|
|
40
45
|
import type { Child } from "../lib/children.js";
|
|
41
46
|
import { cn } from "../lib/cn.js";
|
|
42
47
|
import { LoaderIcon, XIcon } from "../lib/icons.js";
|
|
@@ -180,6 +185,9 @@ function show(options: ToastOptions): ToastId {
|
|
|
180
185
|
} else {
|
|
181
186
|
id = options.id;
|
|
182
187
|
}
|
|
188
|
+
// No document: the server, rendering one request in a process shared by
|
|
189
|
+
// every user. Kept here, the toast would reach the next user's markup.
|
|
190
|
+
if (typeof document === "undefined") return id;
|
|
183
191
|
const variant = options.variant ?? "default";
|
|
184
192
|
const entry: ActiveToast = { ...options, id, variant };
|
|
185
193
|
queue([...queue(), entry]);
|
|
@@ -230,13 +238,18 @@ function optionsOf(message: ToastMessage): Omit<ToastOptions, "id"> {
|
|
|
230
238
|
return { title: message };
|
|
231
239
|
}
|
|
232
240
|
|
|
241
|
+
/** A stage given as a function of the outcome, rather than as the message. */
|
|
242
|
+
function isMessageOf<T>(
|
|
243
|
+
message: ToastMessage | ((value: T) => ToastMessage),
|
|
244
|
+
): message is (value: T) => ToastMessage {
|
|
245
|
+
return typeof message === "function";
|
|
246
|
+
}
|
|
247
|
+
|
|
233
248
|
function resolveMessage<T>(
|
|
234
249
|
message: ToastMessage | ((value: T) => ToastMessage),
|
|
235
250
|
value: T,
|
|
236
251
|
): Omit<ToastOptions, "id"> {
|
|
237
|
-
if (
|
|
238
|
-
return optionsOf((message as (v: T) => ToastMessage)(value));
|
|
239
|
-
}
|
|
252
|
+
if (isMessageOf(message)) return optionsOf(message(value));
|
|
240
253
|
return optionsOf(message);
|
|
241
254
|
}
|
|
242
255
|
|
|
@@ -244,6 +257,8 @@ function resolveMessage<T>(
|
|
|
244
257
|
* Raise a toast. Returns its id, which `dismiss` accepts.
|
|
245
258
|
*
|
|
246
259
|
* Callable from anywhere — no component, no context, no handle.
|
|
260
|
+
*
|
|
261
|
+
* @deprecated Use `toast` from `organisms/Sonner.ts`, shadcn's current toaster.
|
|
247
262
|
*/
|
|
248
263
|
export const toast = {
|
|
249
264
|
show,
|
|
@@ -345,11 +360,20 @@ const positionClasses: Record<NonNullable<ToasterProps["position"]>, string> = {
|
|
|
345
360
|
* `data-nebula-live` marks it as exempt from the `aria-hidden` sweep a modal
|
|
346
361
|
* performs over its siblings — a toast raised while a dialog is open still has
|
|
347
362
|
* to be announced.
|
|
363
|
+
*
|
|
364
|
+
* @deprecated Use `Toaster` from `organisms/Sonner.ts`, shadcn's current toaster.
|
|
348
365
|
*/
|
|
349
366
|
export const Toaster = component<ToasterProps>((props) => {
|
|
350
367
|
const position = props.position ?? "bottom-right";
|
|
351
368
|
const closeLabel = props.closeButtonAriaLabel ?? "Dismiss notification";
|
|
352
369
|
const render = (entry: ActiveToast): Child => renderToast(entry, closeLabel);
|
|
370
|
+
// Empty until mounted, so the server's markup carries no toast and the
|
|
371
|
+
// browser adopts the same empty region before filling it.
|
|
372
|
+
const adopted = signal(false);
|
|
373
|
+
onMount(() => {
|
|
374
|
+
adopted(true);
|
|
375
|
+
});
|
|
376
|
+
const shown = (): readonly ActiveToast[] => (adopted() ? queue() : []);
|
|
353
377
|
|
|
354
378
|
return html`<div
|
|
355
379
|
data-slot="toaster"
|
|
@@ -365,13 +389,13 @@ export const Toaster = component<ToasterProps>((props) => {
|
|
|
365
389
|
>
|
|
366
390
|
<div role="status" aria-live="polite" aria-atomic="false" class="contents">
|
|
367
391
|
${() =>
|
|
368
|
-
|
|
392
|
+
shown()
|
|
369
393
|
.filter((entry) => entry.variant !== "error")
|
|
370
394
|
.map(render)}
|
|
371
395
|
</div>
|
|
372
396
|
<div role="alert" aria-live="assertive" aria-atomic="false" class="contents">
|
|
373
397
|
${() =>
|
|
374
|
-
|
|
398
|
+
shown()
|
|
375
399
|
.filter((entry) => entry.variant === "error")
|
|
376
400
|
.map(render)}
|
|
377
401
|
</div>
|
package/src/organisms/Tooltip.ts
CHANGED
|
@@ -294,6 +294,10 @@ export interface TooltipContentProps {
|
|
|
294
294
|
/** Which edge of the trigger to sit on. Flips when there is no room. */
|
|
295
295
|
side?: Side;
|
|
296
296
|
align?: Align;
|
|
297
|
+
/**
|
|
298
|
+
* Gap past the arrow, in px. `0`, as upstream: the arrow's own length is
|
|
299
|
+
* added by the positioner, the way Radix's popper adds it.
|
|
300
|
+
*/
|
|
297
301
|
sideOffset?: number;
|
|
298
302
|
class?: Reactive<string>;
|
|
299
303
|
}
|
package/src/organisms/index.ts
CHANGED
|
@@ -391,6 +391,29 @@ export {
|
|
|
391
391
|
sidebarState,
|
|
392
392
|
useSidebar,
|
|
393
393
|
} from "./Sidebar.js";
|
|
394
|
+
/**
|
|
395
|
+
* shadcn's `sonner`. Its file exports `Toaster` and `toast`, as upstream; the
|
|
396
|
+
* barrel renames them because the deprecated `Toaster` below still owns those
|
|
397
|
+
* names until apps have moved — `nebula add sonner` gives the file itself.
|
|
398
|
+
*/
|
|
399
|
+
export {
|
|
400
|
+
type Action as SonnerAction,
|
|
401
|
+
type ExternalToast,
|
|
402
|
+
type Offset as SonnerOffset,
|
|
403
|
+
type Position as SonnerPosition,
|
|
404
|
+
type PromiseData as SonnerPromiseData,
|
|
405
|
+
type PromiseExtendedResult as SonnerPromiseExtendedResult,
|
|
406
|
+
type PromiseResult as SonnerPromiseResult,
|
|
407
|
+
type ToastClassnames,
|
|
408
|
+
Toaster as Sonner,
|
|
409
|
+
type ToasterProps as SonnerProps,
|
|
410
|
+
type ToastIcons,
|
|
411
|
+
type ToastId as SonnerToastId,
|
|
412
|
+
type ToastOptions as SonnerToastOptions,
|
|
413
|
+
type ToastT,
|
|
414
|
+
type ToastType,
|
|
415
|
+
toast as sonnerToast,
|
|
416
|
+
} from "./Sonner.js";
|
|
394
417
|
export {
|
|
395
418
|
Toaster,
|
|
396
419
|
type ToasterProps,
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* So layers live in one stack and the rules are applied once, globally:
|
|
11
11
|
*
|
|
12
|
-
* - **Escape** reaches only the topmost layer that
|
|
13
|
-
*
|
|
12
|
+
* - **Escape** reaches only the topmost layer, skipping those that pass it
|
|
13
|
+
* through. One that refuses it dismisses nothing below.
|
|
14
14
|
* - **Pointer outside** walks the stack top-down and stops at the first layer
|
|
15
15
|
* the event landed inside. Layers above it close, layers below it stay. A
|
|
16
16
|
* click in a parent menu therefore closes the submenu and nothing else.
|
|
@@ -35,8 +35,15 @@ export interface DismissableOptions {
|
|
|
35
35
|
* immediately reopen on click.
|
|
36
36
|
*/
|
|
37
37
|
exclude?: () => ReadonlyArray<HTMLElement | null | undefined>;
|
|
38
|
-
/**
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Escape dismisses this layer when it is topmost. Default `true`.
|
|
40
|
+
*
|
|
41
|
+
* `false` refuses it: while this layer is on top, Escape dismisses nothing,
|
|
42
|
+
* as a Radix layer that prevents its `onEscapeKeyDown`. `"passthrough"`
|
|
43
|
+
* hands it to the layer below, for a surface that is part of the one under
|
|
44
|
+
* it — a submenu, whose Escape closes the whole menu.
|
|
45
|
+
*/
|
|
46
|
+
escapeKey?: boolean | "passthrough";
|
|
40
47
|
/** A pointer press outside dismisses. Default `true`. */
|
|
41
48
|
outsidePointer?: boolean;
|
|
42
49
|
/** Focus moving outside dismisses. Default `false`. */
|
|
@@ -110,13 +117,14 @@ function stopListeningIfIdle(): void {
|
|
|
110
117
|
function onKeyDown(event: KeyboardEvent): void {
|
|
111
118
|
if (event.key !== "Escape") return;
|
|
112
119
|
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
120
|
+
// The topmost layer decides, past the ones that pass Escape through. One
|
|
121
|
+
// that refuses it stops here: falling through would close the sheet behind
|
|
122
|
+
// a dialog that has to be answered.
|
|
116
123
|
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
117
124
|
const layer = stack[i];
|
|
118
125
|
if (layer === undefined) continue;
|
|
119
|
-
if (layer.escapeKey ===
|
|
126
|
+
if (layer.escapeKey === "passthrough") continue;
|
|
127
|
+
if (layer.escapeKey === false) return;
|
|
120
128
|
event.stopPropagation();
|
|
121
129
|
layer.onDismiss("escape");
|
|
122
130
|
return;
|
|
@@ -55,7 +55,11 @@ export interface PositionOptions {
|
|
|
55
55
|
flip?: boolean;
|
|
56
56
|
/** Slide along the cross axis to stay on screen. Default `true`. */
|
|
57
57
|
shift?: boolean;
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Arrow size in px; centres the arrow and keeps it off the corners. It is
|
|
60
|
+
* also added to `offset`, so the surface stands an arrow's length away
|
|
61
|
+
* from the anchor (the arrow is square, so its width is its height).
|
|
62
|
+
*/
|
|
59
63
|
arrowSize?: number;
|
|
60
64
|
/**
|
|
61
65
|
* Mirror the placement for a right-to-left writing direction.
|
|
@@ -105,7 +109,10 @@ export function resolvePosition(
|
|
|
105
109
|
viewport: Viewport,
|
|
106
110
|
options: PositionOptions = {},
|
|
107
111
|
): Position {
|
|
108
|
-
|
|
112
|
+
// The arrow stands in the gap, so the gap starts past it — Radix's popper
|
|
113
|
+
// offsets by `sideOffset + arrowHeight` for the same reason. That is why
|
|
114
|
+
// shadcn's `sideOffset = 0` still leaves the arrow clear of the trigger.
|
|
115
|
+
const offset = (options.offset ?? DEFAULT_OFFSET) + (options.arrowSize ?? 0);
|
|
109
116
|
const padding = options.padding ?? DEFAULT_PADDING;
|
|
110
117
|
const requested = options.placement ?? "bottom";
|
|
111
118
|
const [physicalSide, physicalAlign] = splitPlacement(requested);
|
|
@@ -453,6 +460,10 @@ export function autoPosition(
|
|
|
453
460
|
floating.setAttribute("data-align", position.align);
|
|
454
461
|
|
|
455
462
|
const arrowEl = options.arrow?.();
|
|
463
|
+
// The arrow's `data-[side=…]` classes read the arrow's OWN attribute, so it
|
|
464
|
+
// is written here on every placement: without it none of them applied and
|
|
465
|
+
// the arrow sat in the text, and a flip has to turn it around.
|
|
466
|
+
arrowEl?.setAttribute("data-side", position.side);
|
|
456
467
|
if (arrowEl && position.arrow) {
|
|
457
468
|
const { x, y } = position.arrow;
|
|
458
469
|
arrowEl.style.position = "absolute";
|
package/src/primitives/menu.ts
CHANGED
|
@@ -403,7 +403,8 @@ export function wireMenu(
|
|
|
403
403
|
element: () => element,
|
|
404
404
|
exclude: () => [trigger, panel],
|
|
405
405
|
onDismiss: () => closeSubmenusFrom(0),
|
|
406
|
-
|
|
406
|
+
// Escape in a submenu closes the whole menu, as Radix's does.
|
|
407
|
+
escapeKey: "passthrough",
|
|
407
408
|
});
|
|
408
409
|
|
|
409
410
|
const inner = wireMenu(element, {
|
|
@@ -63,25 +63,59 @@ export interface ModalSurfaceOptions {
|
|
|
63
63
|
onClosed?: () => void;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
interface Armed {
|
|
67
|
+
readonly layer: DismissableLayer;
|
|
68
|
+
readonly trap: FocusTrap;
|
|
69
|
+
readonly restoreSiblings: () => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
66
72
|
interface Live {
|
|
67
73
|
readonly mount: Portal;
|
|
68
74
|
/** Carries `data-state`; the exit animation is watched here. */
|
|
69
75
|
readonly element: HTMLElement;
|
|
70
|
-
readonly
|
|
71
|
-
readonly trap: FocusTrap;
|
|
76
|
+
readonly panel: HTMLElement;
|
|
72
77
|
readonly unlock: () => void;
|
|
73
|
-
|
|
78
|
+
/** What makes it modal: `null` once closed, through its exit. */
|
|
79
|
+
armed: Armed | null;
|
|
74
80
|
cancelExit: (() => void) | null;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
export function modalSurface(options: ModalSurfaceOptions): void {
|
|
78
84
|
let live: Live | null = null;
|
|
79
85
|
|
|
86
|
+
function arm(host: HTMLElement, panel: HTMLElement): Armed {
|
|
87
|
+
const restoreSiblings = hideSiblingsFrom(host);
|
|
88
|
+
const trap = focusTrap(panel, {
|
|
89
|
+
initialFocus: () => options.initialFocus?.(panel) ?? null,
|
|
90
|
+
returnFocus: options.returnFocus,
|
|
91
|
+
});
|
|
92
|
+
const layer = dismissable({
|
|
93
|
+
element: () => panel,
|
|
94
|
+
onDismiss: options.onClose,
|
|
95
|
+
escapeKey: options.dismissOnEscape !== false,
|
|
96
|
+
outsidePointer: options.dismissOnOutside !== false,
|
|
97
|
+
outsideFocus: false,
|
|
98
|
+
});
|
|
99
|
+
return { layer, trap, restoreSiblings };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function disarm(current: Live): void {
|
|
103
|
+
const armed = current.armed;
|
|
104
|
+
if (armed === null) return;
|
|
105
|
+
current.armed = null;
|
|
106
|
+
armed.layer.remove();
|
|
107
|
+
armed.trap.release();
|
|
108
|
+
armed.restoreSiblings();
|
|
109
|
+
}
|
|
110
|
+
|
|
80
111
|
function show(): void {
|
|
81
112
|
if (live !== null) {
|
|
113
|
+
// Reopened while its exit was still playing: the same node comes
|
|
114
|
+
// back, and it is a modal again, not a panel the page reads through.
|
|
82
115
|
live.cancelExit?.();
|
|
83
116
|
live.cancelExit = null;
|
|
84
117
|
live.element.setAttribute("data-state", "open");
|
|
118
|
+
if (live.armed === null) live.armed = arm(live.mount.host, live.panel);
|
|
85
119
|
return;
|
|
86
120
|
}
|
|
87
121
|
|
|
@@ -95,28 +129,13 @@ export function modalSurface(options: ModalSurfaceOptions): void {
|
|
|
95
129
|
|
|
96
130
|
const panel = options.panel?.(element) ?? element;
|
|
97
131
|
const unlock = options.lockScroll === false ? () => {} : lockScroll();
|
|
98
|
-
const restoreSiblings = hideSiblingsFrom(mount.host);
|
|
99
|
-
|
|
100
|
-
const trap = focusTrap(panel, {
|
|
101
|
-
initialFocus: () => options.initialFocus?.(panel) ?? null,
|
|
102
|
-
returnFocus: options.returnFocus,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const layer = dismissable({
|
|
106
|
-
element: () => panel,
|
|
107
|
-
onDismiss: options.onClose,
|
|
108
|
-
escapeKey: options.dismissOnEscape !== false,
|
|
109
|
-
outsidePointer: options.dismissOnOutside !== false,
|
|
110
|
-
outsideFocus: false,
|
|
111
|
-
});
|
|
112
132
|
|
|
113
133
|
live = {
|
|
114
134
|
mount,
|
|
115
135
|
element,
|
|
116
|
-
|
|
117
|
-
trap,
|
|
136
|
+
panel,
|
|
118
137
|
unlock,
|
|
119
|
-
|
|
138
|
+
armed: arm(mount.host, panel),
|
|
120
139
|
cancelExit: null,
|
|
121
140
|
};
|
|
122
141
|
options.onOpened?.(panel);
|
|
@@ -124,11 +143,9 @@ export function modalSurface(options: ModalSurfaceOptions): void {
|
|
|
124
143
|
|
|
125
144
|
function hide(): void {
|
|
126
145
|
const current = live;
|
|
127
|
-
if (current === null) return;
|
|
146
|
+
if (current === null || current.armed === null) return;
|
|
128
147
|
|
|
129
|
-
current
|
|
130
|
-
current.trap.release();
|
|
131
|
-
current.restoreSiblings();
|
|
148
|
+
disarm(current);
|
|
132
149
|
current.element.setAttribute("data-state", "closed");
|
|
133
150
|
options.onClosed?.();
|
|
134
151
|
|
|
@@ -146,9 +163,7 @@ export function modalSurface(options: ModalSurfaceOptions): void {
|
|
|
146
163
|
if (current === null) return;
|
|
147
164
|
live = null;
|
|
148
165
|
current.cancelExit?.();
|
|
149
|
-
current
|
|
150
|
-
current.trap.release();
|
|
151
|
-
current.restoreSiblings();
|
|
166
|
+
disarm(current);
|
|
152
167
|
current.unlock();
|
|
153
168
|
current.mount.close();
|
|
154
169
|
}
|
|
@@ -165,35 +180,57 @@ export function modalSurface(options: ModalSurfaceOptions): void {
|
|
|
165
180
|
});
|
|
166
181
|
}
|
|
167
182
|
|
|
183
|
+
/** How many open modals hide each node; it is shown again at zero. */
|
|
184
|
+
const hiddenBy = new WeakMap<Element, number>();
|
|
185
|
+
/** Nodes that were already `aria-hidden` when the first modal reached them. */
|
|
186
|
+
const hiddenBefore = new WeakSet<Element>();
|
|
187
|
+
|
|
168
188
|
/**
|
|
169
189
|
* Hide everything except the overlay from assistive technology.
|
|
170
190
|
*
|
|
171
|
-
* Marks each sibling of the portal host
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
191
|
+
* Marks each sibling of the portal host. Counted per node, as the
|
|
192
|
+
* `aria-hidden` package Radix modals use does: stacked modals hide the same
|
|
193
|
+
* page, and they close in any order — a confirm that closes its parent sheet
|
|
194
|
+
* before itself is enough — so a node is shown again only when the last
|
|
195
|
+
* modal hiding it lets go. A node the application had hidden itself is never
|
|
196
|
+
* touched.
|
|
197
|
+
*
|
|
198
|
+
* Only siblings of the host, not the whole page: a second modal hides the
|
|
199
|
+
* first one's host along with the page, and shows it again when it closes.
|
|
175
200
|
*
|
|
176
|
-
*
|
|
177
|
-
* the first must not hide it, and it will not, because it appends its own host
|
|
178
|
-
* after the first one and only touches what is beside it.
|
|
201
|
+
* The returned release runs once, however many paths reach it.
|
|
179
202
|
*/
|
|
180
203
|
function hideSiblingsFrom(host: HTMLElement): () => void {
|
|
181
204
|
const parent = host.parentElement;
|
|
182
205
|
if (parent === null) return () => {};
|
|
183
206
|
|
|
184
|
-
const
|
|
207
|
+
const hidden: Element[] = [];
|
|
185
208
|
for (const sibling of parent.children) {
|
|
186
209
|
if (sibling === host) continue;
|
|
187
210
|
// A live region announcing outside the dialog (a toast) is deliberate.
|
|
188
211
|
if (sibling.hasAttribute("data-nebula-live")) continue;
|
|
189
|
-
|
|
190
|
-
|
|
212
|
+
const count = (hiddenBy.get(sibling) ?? 0) + 1;
|
|
213
|
+
hiddenBy.set(sibling, count);
|
|
214
|
+
hidden.push(sibling);
|
|
215
|
+
const attribute = sibling.getAttribute("aria-hidden");
|
|
216
|
+
const alreadyHidden = attribute !== null && attribute !== "false";
|
|
217
|
+
if (count === 1 && alreadyHidden) hiddenBefore.add(sibling);
|
|
218
|
+
if (!alreadyHidden) sibling.setAttribute("aria-hidden", "true");
|
|
191
219
|
}
|
|
192
220
|
|
|
221
|
+
let released = false;
|
|
193
222
|
return (): void => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
223
|
+
if (released) return;
|
|
224
|
+
released = true;
|
|
225
|
+
for (const element of hidden) {
|
|
226
|
+
const count = (hiddenBy.get(element) ?? 1) - 1;
|
|
227
|
+
if (count > 0) {
|
|
228
|
+
hiddenBy.set(element, count);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
hiddenBy.delete(element);
|
|
232
|
+
if (!hiddenBefore.has(element)) element.removeAttribute("aria-hidden");
|
|
233
|
+
hiddenBefore.delete(element);
|
|
197
234
|
}
|
|
198
235
|
};
|
|
199
236
|
}
|
|
@@ -408,19 +408,22 @@ function containsKeyframes(rules: CSSRuleList, name: string): boolean {
|
|
|
408
408
|
for (const rule of Array.from(rules)) {
|
|
409
409
|
if (isKeyframesNamed(rule, name)) return true;
|
|
410
410
|
// `cssRules` on a group rule (media, supports, layer); absent on others.
|
|
411
|
-
const nested = Reflect.get(rule, "cssRules");
|
|
412
|
-
if (
|
|
413
|
-
nested !== null &&
|
|
414
|
-
typeof nested === "object" &&
|
|
415
|
-
typeof Reflect.get(nested, "length") === "number" &&
|
|
416
|
-
containsKeyframes(nested as CSSRuleList, name)
|
|
417
|
-
) {
|
|
418
|
-
return true;
|
|
419
|
-
}
|
|
411
|
+
const nested: unknown = Reflect.get(rule, "cssRules");
|
|
412
|
+
if (isRuleList(nested) && containsKeyframes(nested, name)) return true;
|
|
420
413
|
}
|
|
421
414
|
return false;
|
|
422
415
|
}
|
|
423
416
|
|
|
417
|
+
/** A `CSSRuleList`, read structurally: not every DOM exposes the class. */
|
|
418
|
+
function isRuleList(value: unknown): value is CSSRuleList {
|
|
419
|
+
return (
|
|
420
|
+
typeof value === "object" &&
|
|
421
|
+
value !== null &&
|
|
422
|
+
typeof Reflect.get(value, "length") === "number" &&
|
|
423
|
+
typeof Reflect.get(value, "item") === "function"
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
424
427
|
/**
|
|
425
428
|
* Are all the animations this element declares actually defined?
|
|
426
429
|
*
|