@c9up/nebula 0.2.3 → 0.2.5
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 +9 -8
- package/dist/atoms/AspectRatio.d.ts +10 -4
- package/dist/atoms/AspectRatio.js +21 -6
- package/dist/atoms/Avatar.d.ts +14 -0
- package/dist/atoms/Avatar.js +46 -8
- package/dist/atoms/NativeSelect.d.ts +10 -0
- package/dist/atoms/NativeSelect.js +4 -1
- package/dist/atoms/Progress.d.ts +9 -1
- package/dist/atoms/Progress.js +21 -5
- package/dist/atoms/Switch.d.ts +7 -1
- package/dist/atoms/Switch.js +7 -1
- package/dist/cli/add.d.ts +2 -0
- package/dist/cli/add.js +4 -1
- package/dist/cli/diff.d.ts +48 -0
- package/dist/cli/diff.js +77 -3
- 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 +12 -12
- 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/Accordion.js +1 -2
- package/dist/molecules/Collapsible.js +1 -2
- package/dist/molecules/InputOTP.d.ts +12 -0
- package/dist/molecules/InputOTP.js +68 -27
- package/dist/molecules/Resizable.d.ts +6 -0
- package/dist/molecules/Resizable.js +8 -2
- package/dist/molecules/index.d.ts +1 -1
- package/dist/molecules/index.js +1 -1
- package/dist/organisms/AlertDialog.js +4 -5
- package/dist/organisms/Chart.d.ts +103 -15
- package/dist/organisms/Chart.js +518 -99
- 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/Dialog.js +7 -7
- 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 +9 -9
- package/dist/organisms/Sidebar.js +77 -32
- package/dist/organisms/Sonner.d.ts +243 -0
- package/dist/organisms/Sonner.js +916 -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 +7 -1
- package/dist/organisms/index.js +7 -1
- 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/menuParts.js +3 -3
- package/dist/primitives/modalSurface.js +70 -36
- package/dist/primitives/portal.d.ts +15 -0
- package/dist/primitives/portal.js +18 -1
- 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/AspectRatio.ts +21 -6
- package/src/atoms/Avatar.ts +54 -7
- package/src/atoms/NativeSelect.ts +14 -1
- package/src/atoms/Progress.ts +21 -5
- package/src/atoms/Switch.ts +7 -1
- package/src/cli/add.ts +7 -1
- package/src/cli/diff.ts +130 -3
- package/src/cli/projectConfig.ts +71 -0
- package/src/console/AddCommand.ts +6 -1
- package/src/console/DiffCommand.ts +18 -16
- package/src/lib/icons.ts +28 -0
- package/src/lib/image.ts +13 -1
- package/src/molecules/Accordion.ts +1 -2
- package/src/molecules/Collapsible.ts +1 -3
- package/src/molecules/InputOTP.ts +81 -27
- package/src/molecules/Resizable.ts +8 -2
- package/src/molecules/index.ts +3 -0
- package/src/organisms/AlertDialog.ts +3 -5
- package/src/organisms/Chart.ts +633 -125
- package/src/organisms/Combobox.ts +18 -2
- package/src/organisms/Command.ts +66 -7
- package/src/organisms/Dialog.ts +6 -7
- package/src/organisms/Form.ts +21 -0
- package/src/organisms/Select.ts +7 -4
- package/src/organisms/Sidebar.ts +75 -25
- package/src/organisms/Sonner.ts +1373 -0
- package/src/organisms/Toaster.ts +30 -6
- package/src/organisms/Tooltip.ts +4 -0
- package/src/organisms/index.ts +29 -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/menuParts.ts +3 -3
- package/src/primitives/modalSurface.ts +77 -40
- package/src/primitives/portal.ts +27 -1
- package/src/primitives/presence.ts +12 -9
|
@@ -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
|
|
@@ -86,6 +91,8 @@ export type ToastMessage = Child | Omit<ToastOptions, "id" | "variant">;
|
|
|
86
91
|
* Raise a toast. Returns its id, which `dismiss` accepts.
|
|
87
92
|
*
|
|
88
93
|
* Callable from anywhere — no component, no context, no handle.
|
|
94
|
+
*
|
|
95
|
+
* @deprecated Use `toast` from `organisms/Sonner.ts`, shadcn's current toaster.
|
|
89
96
|
*/
|
|
90
97
|
export declare const toast: {
|
|
91
98
|
show: typeof show;
|
|
@@ -132,6 +139,8 @@ export interface ToasterProps {
|
|
|
132
139
|
* `data-nebula-live` marks it as exempt from the `aria-hidden` sweep a modal
|
|
133
140
|
* performs over its siblings — a toast raised while a dialog is open still has
|
|
134
141
|
* to be announced.
|
|
142
|
+
*
|
|
143
|
+
* @deprecated Use `Toaster` from `organisms/Sonner.ts`, shadcn's current toaster.
|
|
135
144
|
*/
|
|
136
145
|
export declare const Toaster: (props?: ToasterProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
137
146
|
export {};
|
|
@@ -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
|
|
@@ -35,7 +40,7 @@
|
|
|
35
40
|
* - Hovering pauses the timers. A toast that vanishes while being read is the
|
|
36
41
|
* single most common complaint about the pattern.
|
|
37
42
|
*/
|
|
38
|
-
import { component, html, signal } from "@c9up/aurora";
|
|
43
|
+
import { component, html, onMount, signal } from "@c9up/aurora";
|
|
39
44
|
import { cn } from "../lib/cn.js";
|
|
40
45
|
import { LoaderIcon, XIcon } from "../lib/icons.js";
|
|
41
46
|
import { fadeInOut } from "../lib/motion.js";
|
|
@@ -129,6 +134,10 @@ function show(options) {
|
|
|
129
134
|
else {
|
|
130
135
|
id = options.id;
|
|
131
136
|
}
|
|
137
|
+
// No document: the server, rendering one request in a process shared by
|
|
138
|
+
// every user. Kept here, the toast would reach the next user's markup.
|
|
139
|
+
if (typeof document === "undefined")
|
|
140
|
+
return id;
|
|
132
141
|
const variant = options.variant ?? "default";
|
|
133
142
|
const entry = { ...options, id, variant };
|
|
134
143
|
queue([...queue(), entry]);
|
|
@@ -171,16 +180,21 @@ function optionsOf(message) {
|
|
|
171
180
|
}
|
|
172
181
|
return { title: message };
|
|
173
182
|
}
|
|
183
|
+
/** A stage given as a function of the outcome, rather than as the message. */
|
|
184
|
+
function isMessageOf(message) {
|
|
185
|
+
return typeof message === "function";
|
|
186
|
+
}
|
|
174
187
|
function resolveMessage(message, value) {
|
|
175
|
-
if (
|
|
188
|
+
if (isMessageOf(message))
|
|
176
189
|
return optionsOf(message(value));
|
|
177
|
-
}
|
|
178
190
|
return optionsOf(message);
|
|
179
191
|
}
|
|
180
192
|
/**
|
|
181
193
|
* Raise a toast. Returns its id, which `dismiss` accepts.
|
|
182
194
|
*
|
|
183
195
|
* Callable from anywhere — no component, no context, no handle.
|
|
196
|
+
*
|
|
197
|
+
* @deprecated Use `toast` from `organisms/Sonner.ts`, shadcn's current toaster.
|
|
184
198
|
*/
|
|
185
199
|
export const toast = {
|
|
186
200
|
show,
|
|
@@ -257,11 +271,20 @@ const positionClasses = {
|
|
|
257
271
|
* `data-nebula-live` marks it as exempt from the `aria-hidden` sweep a modal
|
|
258
272
|
* performs over its siblings — a toast raised while a dialog is open still has
|
|
259
273
|
* to be announced.
|
|
274
|
+
*
|
|
275
|
+
* @deprecated Use `Toaster` from `organisms/Sonner.ts`, shadcn's current toaster.
|
|
260
276
|
*/
|
|
261
277
|
export const Toaster = component((props) => {
|
|
262
278
|
const position = props.position ?? "bottom-right";
|
|
263
279
|
const closeLabel = props.closeButtonAriaLabel ?? "Dismiss notification";
|
|
264
280
|
const render = (entry) => renderToast(entry, closeLabel);
|
|
281
|
+
// Empty until mounted, so the server's markup carries no toast and the
|
|
282
|
+
// browser adopts the same empty region before filling it.
|
|
283
|
+
const adopted = signal(false);
|
|
284
|
+
onMount(() => {
|
|
285
|
+
adopted(true);
|
|
286
|
+
});
|
|
287
|
+
const shown = () => (adopted() ? queue() : []);
|
|
265
288
|
return html `<div
|
|
266
289
|
data-slot="toaster"
|
|
267
290
|
data-nebula-live
|
|
@@ -270,12 +293,12 @@ export const Toaster = component((props) => {
|
|
|
270
293
|
@pointerleave="${() => resumeAll(1000)}"
|
|
271
294
|
>
|
|
272
295
|
<div role="status" aria-live="polite" aria-atomic="false" class="contents">
|
|
273
|
-
${() =>
|
|
296
|
+
${() => shown()
|
|
274
297
|
.filter((entry) => entry.variant !== "error")
|
|
275
298
|
.map(render)}
|
|
276
299
|
</div>
|
|
277
300
|
<div role="alert" aria-live="assertive" aria-atomic="false" class="contents">
|
|
278
|
-
${() =>
|
|
301
|
+
${() => shown()
|
|
279
302
|
.filter((entry) => entry.variant === "error")
|
|
280
303
|
.map(render)}
|
|
281
304
|
</div>
|
|
@@ -99,6 +99,10 @@ export interface TooltipContentProps {
|
|
|
99
99
|
/** Which edge of the trigger to sit on. Flips when there is no room. */
|
|
100
100
|
side?: Side;
|
|
101
101
|
align?: Align;
|
|
102
|
+
/**
|
|
103
|
+
* Gap past the arrow, in px. `0`, as upstream: the arrow's own length is
|
|
104
|
+
* added by the positioner, the way Radix's popper adds it.
|
|
105
|
+
*/
|
|
102
106
|
sideOffset?: number;
|
|
103
107
|
class?: Reactive<string>;
|
|
104
108
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
export { AlertDialog, AlertDialogAction, type AlertDialogButtonProps, AlertDialogCancel, AlertDialogContent, type AlertDialogContentProps, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogOverlay, AlertDialogPortal, type AlertDialogPortalProps, type AlertDialogProps, type AlertDialogSectionProps, AlertDialogTitle, AlertDialogTrigger, type AlertDialogTriggerProps, } from "./AlertDialog.js";
|
|
16
16
|
export { addDays, addMonths, Calendar, type CalendarLabels, type CalendarProps, type DateRange, isSameDay, monthGrid, startOfDay, } from "./Calendar.js";
|
|
17
17
|
export { Carousel, type CarouselButtonProps, CarouselContent, type CarouselContentProps, CarouselItem, type CarouselItemProps, CarouselNext, CarouselPrevious, type CarouselProps, } from "./Carousel.js";
|
|
18
|
-
export { Chart, type ChartDatum, type ChartProps, type ChartSeries, valueRange, } from "./Chart.js";
|
|
18
|
+
export { Chart, type ChartBound, type ChartCategory, type ChartDatum, type ChartProps, type ChartSeries, niceTicks, type ValueAxisOptions, valueAxis, valueRange, visibleCategories, } from "./Chart.js";
|
|
19
19
|
export { Combobox, type ComboboxOption, type ComboboxProps, } from "./Combobox.js";
|
|
20
20
|
export { Command, type CommandCandidate, CommandEmpty, type CommandEmptyProps, CommandGroup, type CommandGroupProps, CommandInput, type CommandInputProps, CommandItem, type CommandItemProps, CommandList, type CommandListProps, type CommandProps, CommandSeparator, type CommandSeparatorProps, CommandShortcut, type CommandShortcutProps, defaultFilter, } from "./Command.js";
|
|
21
21
|
export { CommandDialog, type CommandDialogProps } from "./CommandDialog.js";
|
|
@@ -36,5 +36,11 @@ export { type Answer, type Answers, type FreeformQuestion, isAnswered, type Mult
|
|
|
36
36
|
export { Select, SelectContent, type SelectContentProps, SelectGroup, type SelectGroupProps, SelectItem, type SelectItemProps, SelectLabel, type SelectLabelProps, type SelectProps, type SelectScrollButtonProps, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, type SelectSeparatorProps, SelectTrigger, type SelectTriggerProps, SelectValue, type SelectValueProps, selectContentClasses, selectTriggerClasses, } from "./Select.js";
|
|
37
37
|
export { Sheet, SheetClose, type SheetCloseProps, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, type SheetOverlayProps, type SheetProps, type SheetSectionProps, SheetTitle, type SheetTitleProps, SheetTrigger, type SheetTriggerProps, } from "./Sheet.js";
|
|
38
38
|
export { Sidebar, type SidebarActionProps, type SidebarApi, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, type SidebarInputProps, SidebarInset, type SidebarInsetProps, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, type SidebarMenuButtonProps, type SidebarMenuButtonVariants, SidebarMenuItem, SidebarMenuSkeleton, type SidebarMenuSkeletonProps, SidebarMenuSub, SidebarMenuSubButton, type SidebarMenuSubButtonProps, SidebarMenuSubItem, type SidebarProps, SidebarProvider, type SidebarProviderProps, SidebarRail, type SidebarRailProps, SidebarSeparator, type SidebarSeparatorProps, SidebarTrigger, type SidebarTriggerProps, sidebarCollapsed, sidebarMenuButtonVariants, sidebarState, useSidebar, } from "./Sidebar.js";
|
|
39
|
+
/**
|
|
40
|
+
* shadcn's `sonner`. Its file exports `Toaster` and `toast`, as upstream; the
|
|
41
|
+
* barrel renames them because the deprecated `Toaster` below still owns those
|
|
42
|
+
* names until apps have moved — `nebula add sonner` gives the file itself.
|
|
43
|
+
*/
|
|
44
|
+
export { type Action as SonnerAction, type ExternalToast, type Offset as SonnerOffset, type Position as SonnerPosition, type PromiseData as SonnerPromiseData, type PromiseExtendedResult as SonnerPromiseExtendedResult, type PromiseResult as SonnerPromiseResult, type ToastClassnames, Toaster as Sonner, type ToasterProps as SonnerProps, type ToastIcons, type ToastId as SonnerToastId, type ToastOptions as SonnerToastOptions, type ToastT, type ToastType, toast as sonnerToast, } from "./Sonner.js";
|
|
39
45
|
export { Toaster, type ToasterProps, type ToastId, type ToastMessage, type ToastOptions, type ToastVariant, toast, } from "./Toaster.js";
|
|
40
46
|
export { Tooltip, TooltipContent, type TooltipContentProps, type TooltipProps, TooltipProvider, type TooltipProviderProps, TooltipTrigger, type TooltipTriggerProps, } from "./Tooltip.js";
|
package/dist/organisms/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
export { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, } from "./AlertDialog.js";
|
|
16
16
|
export { addDays, addMonths, Calendar, isSameDay, monthGrid, startOfDay, } from "./Calendar.js";
|
|
17
17
|
export { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, } from "./Carousel.js";
|
|
18
|
-
export { Chart, valueRange, } from "./Chart.js";
|
|
18
|
+
export { Chart, niceTicks, valueAxis, valueRange, visibleCategories, } from "./Chart.js";
|
|
19
19
|
export { Combobox, } from "./Combobox.js";
|
|
20
20
|
export { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, defaultFilter, } from "./Command.js";
|
|
21
21
|
export { CommandDialog } from "./CommandDialog.js";
|
|
@@ -36,5 +36,11 @@ export { isAnswered, Questionnaire, } from "./Questionnaire.js";
|
|
|
36
36
|
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, selectContentClasses, selectTriggerClasses, } from "./Select.js";
|
|
37
37
|
export { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetTitle, SheetTrigger, } from "./Sheet.js";
|
|
38
38
|
export { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, sidebarCollapsed, sidebarMenuButtonVariants, sidebarState, useSidebar, } from "./Sidebar.js";
|
|
39
|
+
/**
|
|
40
|
+
* shadcn's `sonner`. Its file exports `Toaster` and `toast`, as upstream; the
|
|
41
|
+
* barrel renames them because the deprecated `Toaster` below still owns those
|
|
42
|
+
* names until apps have moved — `nebula add sonner` gives the file itself.
|
|
43
|
+
*/
|
|
44
|
+
export { Toaster as Sonner, toast as sonnerToast, } from "./Sonner.js";
|
|
39
45
|
export { Toaster, toast, } from "./Toaster.js";
|
|
40
46
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "./Tooltip.js";
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* So layers live in one stack and the rules are applied once, globally:
|
|
10
10
|
*
|
|
11
|
-
* - **Escape** reaches only the topmost layer that
|
|
12
|
-
*
|
|
11
|
+
* - **Escape** reaches only the topmost layer, skipping those that pass it
|
|
12
|
+
* through. One that refuses it dismisses nothing below.
|
|
13
13
|
* - **Pointer outside** walks the stack top-down and stops at the first layer
|
|
14
14
|
* the event landed inside. Layers above it close, layers below it stay. A
|
|
15
15
|
* click in a parent menu therefore closes the submenu and nothing else.
|
|
@@ -32,8 +32,15 @@ export interface DismissableOptions {
|
|
|
32
32
|
* immediately reopen on click.
|
|
33
33
|
*/
|
|
34
34
|
exclude?: () => ReadonlyArray<HTMLElement | null | undefined>;
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Escape dismisses this layer when it is topmost. Default `true`.
|
|
37
|
+
*
|
|
38
|
+
* `false` refuses it: while this layer is on top, Escape dismisses nothing,
|
|
39
|
+
* as a Radix layer that prevents its `onEscapeKeyDown`. `"passthrough"`
|
|
40
|
+
* hands it to the layer below, for a surface that is part of the one under
|
|
41
|
+
* it — a submenu, whose Escape closes the whole menu.
|
|
42
|
+
*/
|
|
43
|
+
escapeKey?: boolean | "passthrough";
|
|
37
44
|
/** A pointer press outside dismisses. Default `true`. */
|
|
38
45
|
outsidePointer?: boolean;
|
|
39
46
|
/** Focus moving outside dismisses. Default `false`. */
|
|
@@ -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.
|
|
@@ -76,15 +76,17 @@ function stopListeningIfIdle() {
|
|
|
76
76
|
function onKeyDown(event) {
|
|
77
77
|
if (event.key !== "Escape")
|
|
78
78
|
return;
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
79
|
+
// The topmost layer decides, past the ones that pass Escape through. One
|
|
80
|
+
// that refuses it stops here: falling through would close the sheet behind
|
|
81
|
+
// a dialog that has to be answered.
|
|
82
82
|
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
83
83
|
const layer = stack[i];
|
|
84
84
|
if (layer === undefined)
|
|
85
85
|
continue;
|
|
86
|
-
if (layer.escapeKey ===
|
|
86
|
+
if (layer.escapeKey === "passthrough")
|
|
87
87
|
continue;
|
|
88
|
+
if (layer.escapeKey === false)
|
|
89
|
+
return;
|
|
88
90
|
event.stopPropagation();
|
|
89
91
|
layer.onDismiss("escape");
|
|
90
92
|
return;
|
|
@@ -48,7 +48,11 @@ export interface PositionOptions {
|
|
|
48
48
|
flip?: boolean;
|
|
49
49
|
/** Slide along the cross axis to stay on screen. Default `true`. */
|
|
50
50
|
shift?: boolean;
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Arrow size in px; centres the arrow and keeps it off the corners. It is
|
|
53
|
+
* also added to `offset`, so the surface stands an arrow's length away
|
|
54
|
+
* from the anchor (the arrow is square, so its width is its height).
|
|
55
|
+
*/
|
|
52
56
|
arrowSize?: number;
|
|
53
57
|
/**
|
|
54
58
|
* Mirror the placement for a right-to-left writing direction.
|
|
@@ -35,7 +35,10 @@ const DEFAULT_PADDING = 8;
|
|
|
35
35
|
* make room on a side that should have been abandoned entirely.
|
|
36
36
|
*/
|
|
37
37
|
export function resolvePosition(anchor, floating, viewport, options = {}) {
|
|
38
|
-
|
|
38
|
+
// The arrow stands in the gap, so the gap starts past it — Radix's popper
|
|
39
|
+
// offsets by `sideOffset + arrowHeight` for the same reason. That is why
|
|
40
|
+
// shadcn's `sideOffset = 0` still leaves the arrow clear of the trigger.
|
|
41
|
+
const offset = (options.offset ?? DEFAULT_OFFSET) + (options.arrowSize ?? 0);
|
|
39
42
|
const padding = options.padding ?? DEFAULT_PADDING;
|
|
40
43
|
const requested = options.placement ?? "bottom";
|
|
41
44
|
const [physicalSide, physicalAlign] = splitPlacement(requested);
|
|
@@ -283,6 +286,10 @@ export function autoPosition(anchor, floating, options = {}) {
|
|
|
283
286
|
floating.setAttribute("data-side", position.side);
|
|
284
287
|
floating.setAttribute("data-align", position.align);
|
|
285
288
|
const arrowEl = options.arrow?.();
|
|
289
|
+
// The arrow's `data-[side=…]` classes read the arrow's OWN attribute, so it
|
|
290
|
+
// is written here on every placement: without it none of them applied and
|
|
291
|
+
// the arrow sat in the text, and a flip has to turn it around.
|
|
292
|
+
arrowEl?.setAttribute("data-side", position.side);
|
|
286
293
|
if (arrowEl && position.arrow) {
|
|
287
294
|
const { x, y } = position.arrow;
|
|
288
295
|
arrowEl.style.position = "absolute";
|
package/dist/primitives/menu.js
CHANGED
|
@@ -245,7 +245,8 @@ export function wireMenu(panel, options) {
|
|
|
245
245
|
element: () => element,
|
|
246
246
|
exclude: () => [trigger, panel],
|
|
247
247
|
onDismiss: () => closeSubmenusFrom(0),
|
|
248
|
-
|
|
248
|
+
// Escape in a submenu closes the whole menu, as Radix's does.
|
|
249
|
+
escapeKey: "passthrough",
|
|
249
250
|
});
|
|
250
251
|
const inner = wireMenu(element, {
|
|
251
252
|
...options,
|
|
@@ -29,7 +29,7 @@ import { uid } from "../lib/id.js";
|
|
|
29
29
|
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
30
30
|
import { read } from "../lib/props.js";
|
|
31
31
|
import { menuCheckItemClasses, menuIndicatorClasses, menuItemClasses, menuLabelClasses, menuSeparatorClasses, menuShortcutClasses, menuSubPanelClasses, menuSubTriggerClasses, registerSubmenu, } from "./menu.js";
|
|
32
|
-
import {
|
|
32
|
+
import { portalOnMount } from "./portal.js";
|
|
33
33
|
/**
|
|
34
34
|
* Build one menu's fifteen rows.
|
|
35
35
|
*
|
|
@@ -184,10 +184,10 @@ export function createMenuParts(prefix, owner) {
|
|
|
184
184
|
return html ``;
|
|
185
185
|
});
|
|
186
186
|
const Portal = component((props) => {
|
|
187
|
-
|
|
187
|
+
portalOnMount(html `${slot(props.children)}`, {
|
|
188
188
|
container: props.container,
|
|
189
|
+
slot: `${prefix}-portal`,
|
|
189
190
|
});
|
|
190
|
-
mounted.host.setAttribute("data-slot", `${prefix}-portal`);
|
|
191
191
|
return html ``;
|
|
192
192
|
});
|
|
193
193
|
return {
|
|
@@ -27,11 +27,39 @@ import { onExitFinished } from "./presence.js";
|
|
|
27
27
|
import { lockScroll } from "./scrollLock.js";
|
|
28
28
|
export function modalSurface(options) {
|
|
29
29
|
let live = null;
|
|
30
|
+
function arm(host, panel) {
|
|
31
|
+
const restoreSiblings = hideSiblingsFrom(host);
|
|
32
|
+
const trap = focusTrap(panel, {
|
|
33
|
+
initialFocus: () => options.initialFocus?.(panel) ?? null,
|
|
34
|
+
returnFocus: options.returnFocus,
|
|
35
|
+
});
|
|
36
|
+
const layer = dismissable({
|
|
37
|
+
element: () => panel,
|
|
38
|
+
onDismiss: options.onClose,
|
|
39
|
+
escapeKey: options.dismissOnEscape !== false,
|
|
40
|
+
outsidePointer: options.dismissOnOutside !== false,
|
|
41
|
+
outsideFocus: false,
|
|
42
|
+
});
|
|
43
|
+
return { layer, trap, restoreSiblings };
|
|
44
|
+
}
|
|
45
|
+
function disarm(current) {
|
|
46
|
+
const armed = current.armed;
|
|
47
|
+
if (armed === null)
|
|
48
|
+
return;
|
|
49
|
+
current.armed = null;
|
|
50
|
+
armed.layer.remove();
|
|
51
|
+
armed.trap.release();
|
|
52
|
+
armed.restoreSiblings();
|
|
53
|
+
}
|
|
30
54
|
function show() {
|
|
31
55
|
if (live !== null) {
|
|
56
|
+
// Reopened while its exit was still playing: the same node comes
|
|
57
|
+
// back, and it is a modal again, not a panel the page reads through.
|
|
32
58
|
live.cancelExit?.();
|
|
33
59
|
live.cancelExit = null;
|
|
34
60
|
live.element.setAttribute("data-state", "open");
|
|
61
|
+
if (live.armed === null)
|
|
62
|
+
live.armed = arm(live.mount.host, live.panel);
|
|
35
63
|
return;
|
|
36
64
|
}
|
|
37
65
|
const mount = portal(options.content());
|
|
@@ -43,36 +71,21 @@ export function modalSurface(options) {
|
|
|
43
71
|
element.setAttribute("data-state", "open");
|
|
44
72
|
const panel = options.panel?.(element) ?? element;
|
|
45
73
|
const unlock = options.lockScroll === false ? () => { } : lockScroll();
|
|
46
|
-
const restoreSiblings = hideSiblingsFrom(mount.host);
|
|
47
|
-
const trap = focusTrap(panel, {
|
|
48
|
-
initialFocus: () => options.initialFocus?.(panel) ?? null,
|
|
49
|
-
returnFocus: options.returnFocus,
|
|
50
|
-
});
|
|
51
|
-
const layer = dismissable({
|
|
52
|
-
element: () => panel,
|
|
53
|
-
onDismiss: options.onClose,
|
|
54
|
-
escapeKey: options.dismissOnEscape !== false,
|
|
55
|
-
outsidePointer: options.dismissOnOutside !== false,
|
|
56
|
-
outsideFocus: false,
|
|
57
|
-
});
|
|
58
74
|
live = {
|
|
59
75
|
mount,
|
|
60
76
|
element,
|
|
61
|
-
|
|
62
|
-
trap,
|
|
77
|
+
panel,
|
|
63
78
|
unlock,
|
|
64
|
-
|
|
79
|
+
armed: arm(mount.host, panel),
|
|
65
80
|
cancelExit: null,
|
|
66
81
|
};
|
|
67
82
|
options.onOpened?.(panel);
|
|
68
83
|
}
|
|
69
84
|
function hide() {
|
|
70
85
|
const current = live;
|
|
71
|
-
if (current === null)
|
|
86
|
+
if (current === null || current.armed === null)
|
|
72
87
|
return;
|
|
73
|
-
current
|
|
74
|
-
current.trap.release();
|
|
75
|
-
current.restoreSiblings();
|
|
88
|
+
disarm(current);
|
|
76
89
|
current.element.setAttribute("data-state", "closed");
|
|
77
90
|
options.onClosed?.();
|
|
78
91
|
// Scroll stays locked through the exit animation. Releasing it first
|
|
@@ -90,9 +103,7 @@ export function modalSurface(options) {
|
|
|
90
103
|
return;
|
|
91
104
|
live = null;
|
|
92
105
|
current.cancelExit?.();
|
|
93
|
-
current
|
|
94
|
-
current.trap.release();
|
|
95
|
-
current.restoreSiblings();
|
|
106
|
+
disarm(current);
|
|
96
107
|
current.unlock();
|
|
97
108
|
current.mount.close();
|
|
98
109
|
}
|
|
@@ -109,38 +120,61 @@ export function modalSurface(options) {
|
|
|
109
120
|
};
|
|
110
121
|
});
|
|
111
122
|
}
|
|
123
|
+
/** How many open modals hide each node; it is shown again at zero. */
|
|
124
|
+
const hiddenBy = new WeakMap();
|
|
125
|
+
/** Nodes that were already `aria-hidden` when the first modal reached them. */
|
|
126
|
+
const hiddenBefore = new WeakSet();
|
|
112
127
|
/**
|
|
113
128
|
* Hide everything except the overlay from assistive technology.
|
|
114
129
|
*
|
|
115
|
-
* Marks each sibling of the portal host
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
130
|
+
* Marks each sibling of the portal host. Counted per node, as the
|
|
131
|
+
* `aria-hidden` package Radix modals use does: stacked modals hide the same
|
|
132
|
+
* page, and they close in any order — a confirm that closes its parent sheet
|
|
133
|
+
* before itself is enough — so a node is shown again only when the last
|
|
134
|
+
* modal hiding it lets go. A node the application had hidden itself is never
|
|
135
|
+
* touched.
|
|
119
136
|
*
|
|
120
|
-
* Only siblings of the host, not the whole page: a second modal
|
|
121
|
-
*
|
|
122
|
-
*
|
|
137
|
+
* Only siblings of the host, not the whole page: a second modal hides the
|
|
138
|
+
* first one's host along with the page, and shows it again when it closes.
|
|
139
|
+
*
|
|
140
|
+
* The returned release runs once, however many paths reach it.
|
|
123
141
|
*/
|
|
124
142
|
function hideSiblingsFrom(host) {
|
|
125
143
|
const parent = host.parentElement;
|
|
126
144
|
if (parent === null)
|
|
127
145
|
return () => { };
|
|
128
|
-
const
|
|
146
|
+
const hidden = [];
|
|
129
147
|
for (const sibling of parent.children) {
|
|
130
148
|
if (sibling === host)
|
|
131
149
|
continue;
|
|
132
150
|
// A live region announcing outside the dialog (a toast) is deliberate.
|
|
133
151
|
if (sibling.hasAttribute("data-nebula-live"))
|
|
134
152
|
continue;
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
const count = (hiddenBy.get(sibling) ?? 0) + 1;
|
|
154
|
+
hiddenBy.set(sibling, count);
|
|
155
|
+
hidden.push(sibling);
|
|
156
|
+
const attribute = sibling.getAttribute("aria-hidden");
|
|
157
|
+
const alreadyHidden = attribute !== null && attribute !== "false";
|
|
158
|
+
if (count === 1 && alreadyHidden)
|
|
159
|
+
hiddenBefore.add(sibling);
|
|
160
|
+
if (!alreadyHidden)
|
|
161
|
+
sibling.setAttribute("aria-hidden", "true");
|
|
137
162
|
}
|
|
163
|
+
let released = false;
|
|
138
164
|
return () => {
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
if (released)
|
|
166
|
+
return;
|
|
167
|
+
released = true;
|
|
168
|
+
for (const element of hidden) {
|
|
169
|
+
const count = (hiddenBy.get(element) ?? 1) - 1;
|
|
170
|
+
if (count > 0) {
|
|
171
|
+
hiddenBy.set(element, count);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
hiddenBy.delete(element);
|
|
175
|
+
if (!hiddenBefore.has(element))
|
|
141
176
|
element.removeAttribute("aria-hidden");
|
|
142
|
-
|
|
143
|
-
element.setAttribute("aria-hidden", previous);
|
|
177
|
+
hiddenBefore.delete(element);
|
|
144
178
|
}
|
|
145
179
|
};
|
|
146
180
|
}
|
|
@@ -32,3 +32,18 @@ export interface Portal {
|
|
|
32
32
|
* test — or a developer in the inspector — can see what put it there.
|
|
33
33
|
*/
|
|
34
34
|
export declare function portal(content: TemplateResult, options?: PortalOptions): Portal;
|
|
35
|
+
export interface PortalPartOptions extends PortalOptions {
|
|
36
|
+
/** The host's `data-slot`, naming the part that put it there. */
|
|
37
|
+
slot: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Portal `content` once the calling component is mounted, and close it when
|
|
41
|
+
* the component unmounts. Call it from a component's setup.
|
|
42
|
+
*
|
|
43
|
+
* Setup also runs inside `renderToString`, where there is no document to
|
|
44
|
+
* append a host to, so the portal waits for the mount: the server renders
|
|
45
|
+
* nothing in place and the content is client-only, as a portal that renders
|
|
46
|
+
* only after its mount effect is. The close rides on the same hook, so a part
|
|
47
|
+
* cannot open a portal without also taking it away.
|
|
48
|
+
*/
|
|
49
|
+
export declare function portalOnMount(content: TemplateResult, options: PortalPartOptions): void;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* back a disposer, so a portal is that call plus a host element to hold the
|
|
12
12
|
* content and the discipline to tear both down together.
|
|
13
13
|
*/
|
|
14
|
-
import { render } from "@c9up/aurora";
|
|
14
|
+
import { onMount, render } from "@c9up/aurora";
|
|
15
15
|
/**
|
|
16
16
|
* Mount `content` into a fresh host element appended to the container.
|
|
17
17
|
*
|
|
@@ -40,3 +40,20 @@ export function portal(content, options = {}) {
|
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Portal `content` once the calling component is mounted, and close it when
|
|
45
|
+
* the component unmounts. Call it from a component's setup.
|
|
46
|
+
*
|
|
47
|
+
* Setup also runs inside `renderToString`, where there is no document to
|
|
48
|
+
* append a host to, so the portal waits for the mount: the server renders
|
|
49
|
+
* nothing in place and the content is client-only, as a portal that renders
|
|
50
|
+
* only after its mount effect is. The close rides on the same hook, so a part
|
|
51
|
+
* cannot open a portal without also taking it away.
|
|
52
|
+
*/
|
|
53
|
+
export function portalOnMount(content, options) {
|
|
54
|
+
onMount(() => {
|
|
55
|
+
const mounted = portal(content, options);
|
|
56
|
+
mounted.host.setAttribute("data-slot", options.slot);
|
|
57
|
+
return () => mounted.close();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -372,15 +372,18 @@ function containsKeyframes(rules, name) {
|
|
|
372
372
|
return true;
|
|
373
373
|
// `cssRules` on a group rule (media, supports, layer); absent on others.
|
|
374
374
|
const nested = Reflect.get(rule, "cssRules");
|
|
375
|
-
if (nested
|
|
376
|
-
typeof nested === "object" &&
|
|
377
|
-
typeof Reflect.get(nested, "length") === "number" &&
|
|
378
|
-
containsKeyframes(nested, name)) {
|
|
375
|
+
if (isRuleList(nested) && containsKeyframes(nested, name))
|
|
379
376
|
return true;
|
|
380
|
-
}
|
|
381
377
|
}
|
|
382
378
|
return false;
|
|
383
379
|
}
|
|
380
|
+
/** A `CSSRuleList`, read structurally: not every DOM exposes the class. */
|
|
381
|
+
function isRuleList(value) {
|
|
382
|
+
return (typeof value === "object" &&
|
|
383
|
+
value !== null &&
|
|
384
|
+
typeof Reflect.get(value, "length") === "number" &&
|
|
385
|
+
typeof Reflect.get(value, "item") === "function");
|
|
386
|
+
}
|
|
384
387
|
/**
|
|
385
388
|
* Are all the animations this element declares actually defined?
|
|
386
389
|
*
|