@c9up/nebula 0.2.4 → 0.2.6
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 +4 -4
- package/dist/atoms/AspectRatio.d.ts +10 -4
- package/dist/atoms/AspectRatio.js +21 -6
- package/dist/atoms/NativeSelect.d.ts +16 -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/diff.d.ts +46 -0
- package/dist/cli/diff.js +73 -2
- package/dist/console/DiffCommand.js +6 -11
- package/dist/molecules/Accordion.js +1 -2
- package/dist/molecules/Collapsible.js +1 -2
- package/dist/molecules/Resizable.d.ts +6 -0
- package/dist/molecules/Resizable.js +8 -2
- package/dist/organisms/Agenda.d.ts +200 -0
- package/dist/organisms/Agenda.js +762 -0
- 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/Dialog.js +7 -7
- package/dist/organisms/Sidebar.d.ts +5 -7
- package/dist/organisms/Sidebar.js +23 -6
- package/dist/organisms/Sonner.js +11 -4
- package/dist/organisms/index.d.ts +2 -1
- package/dist/organisms/index.js +2 -1
- package/dist/primitives/floatingSurface.js +60 -36
- package/dist/primitives/menuParts.js +3 -3
- package/dist/primitives/portal.d.ts +15 -0
- package/dist/primitives/portal.js +18 -1
- package/nebula.css +1 -1
- package/package.json +1 -1
- package/registry.json +13 -0
- package/src/atoms/AspectRatio.ts +21 -6
- package/src/atoms/NativeSelect.ts +20 -1
- package/src/atoms/Progress.ts +21 -5
- package/src/atoms/Switch.ts +7 -1
- package/src/cli/diff.ts +123 -2
- package/src/console/DiffCommand.ts +12 -15
- package/src/molecules/Accordion.ts +1 -2
- package/src/molecules/Collapsible.ts +1 -3
- package/src/molecules/Resizable.ts +8 -2
- package/src/organisms/Agenda.ts +1061 -0
- package/src/organisms/AlertDialog.ts +3 -5
- package/src/organisms/Chart.ts +633 -125
- package/src/organisms/Dialog.ts +6 -7
- package/src/organisms/Sidebar.ts +28 -6
- package/src/organisms/Sonner.ts +11 -4
- package/src/organisms/index.ts +26 -0
- package/src/primitives/floatingSurface.ts +74 -40
- package/src/primitives/menuParts.ts +3 -3
- package/src/primitives/portal.ts +27 -1
package/dist/organisms/Dialog.js
CHANGED
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
* `DialogTitle` is warned about rather than tolerated — as Radix did through
|
|
38
38
|
* 1.1; 1.3 counts its titles and no longer warns.
|
|
39
39
|
*/
|
|
40
|
-
import { component, createContext, html, inject,
|
|
41
|
-
import {
|
|
40
|
+
import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
|
|
41
|
+
import { buttonVariants } from "../atoms/Button.js";
|
|
42
42
|
import { slot } from "../lib/children.js";
|
|
43
43
|
import { cn } from "../lib/cn.js";
|
|
44
44
|
import { XIcon } from "../lib/icons.js";
|
|
@@ -47,7 +47,7 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
|
|
|
47
47
|
import { read } from "../lib/props.js";
|
|
48
48
|
import { controllable } from "../primitives/controllable.js";
|
|
49
49
|
import { modalSurface } from "../primitives/modalSurface.js";
|
|
50
|
-
import {
|
|
50
|
+
import { portalOnMount } from "../primitives/portal.js";
|
|
51
51
|
export const dialogBackdropClasses = "fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0";
|
|
52
52
|
export const dialogPanelClasses = "bg-background fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg";
|
|
53
53
|
const closeButtonClasses = "ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0";
|
|
@@ -151,11 +151,10 @@ export const DialogOverlay = component((props) => html `<div
|
|
|
151
151
|
* rather than standing in as a passthrough.
|
|
152
152
|
*/
|
|
153
153
|
export const DialogPortal = component((props) => {
|
|
154
|
-
|
|
154
|
+
portalOnMount(html `${slot(props.children)}`, {
|
|
155
155
|
container: props.container,
|
|
156
|
+
slot: "dialog-portal",
|
|
156
157
|
});
|
|
157
|
-
mounted.host.setAttribute("data-slot", "dialog-portal");
|
|
158
|
-
onUnmount(() => mounted.close());
|
|
159
158
|
return html ``;
|
|
160
159
|
});
|
|
161
160
|
/**
|
|
@@ -188,8 +187,9 @@ export const DialogFooter = component((props) => {
|
|
|
188
187
|
? html `<button
|
|
189
188
|
type="button"
|
|
190
189
|
data-slot="dialog-close"
|
|
190
|
+
class="${buttonVariants({ variant: "outline" })}"
|
|
191
191
|
@click="${() => dialog.setOpen(false)}"
|
|
192
|
-
>${
|
|
192
|
+
>${props.closeLabel ?? "Close"}</button>`
|
|
193
193
|
: null;
|
|
194
194
|
return html `<div
|
|
195
195
|
data-slot="dialog-footer"
|
|
@@ -43,10 +43,15 @@ import { type Reactive } from "../lib/props.js";
|
|
|
43
43
|
export declare function sidebarState(defaultOpen?: boolean): Signal<boolean>;
|
|
44
44
|
export declare function sidebarCollapsed(): boolean;
|
|
45
45
|
export interface SidebarApi {
|
|
46
|
+
/** The column's state: persisted, and what the wide layout shows. */
|
|
46
47
|
readonly open: () => boolean;
|
|
48
|
+
/** The drawer's state on a phone: closed on every load, never persisted. */
|
|
49
|
+
readonly openMobile: () => boolean;
|
|
47
50
|
readonly isMobile: () => boolean;
|
|
48
51
|
readonly state: () => "expanded" | "collapsed";
|
|
49
52
|
setOpen(next: boolean): void;
|
|
53
|
+
setOpenMobile(next: boolean): void;
|
|
54
|
+
/** The drawer on a phone, the column otherwise. */
|
|
50
55
|
toggleSidebar(): void;
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
@@ -180,13 +185,6 @@ export interface SidebarMenuSkeletonProps {
|
|
|
180
185
|
showIcon?: boolean;
|
|
181
186
|
class?: Reactive<string>;
|
|
182
187
|
}
|
|
183
|
-
/**
|
|
184
|
-
* A placeholder row while the navigation loads.
|
|
185
|
-
*
|
|
186
|
-
* The widths vary per row, which is what stops a loading column from reading
|
|
187
|
-
* as a bar chart. Seeded from a random draw the moment the row is built, so it
|
|
188
|
-
* does not shift on every re-render.
|
|
189
|
-
*/
|
|
190
188
|
export declare const SidebarMenuSkeleton: (props?: SidebarMenuSkeletonProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
191
189
|
export declare const SidebarMenuSub: (props?: {
|
|
192
190
|
children?: Slot;
|
|
@@ -83,12 +83,19 @@ export function useSidebar() {
|
|
|
83
83
|
export const SidebarProvider = component((props) => {
|
|
84
84
|
const open = sidebarState(props.defaultOpen ?? true);
|
|
85
85
|
const mobile = signal(false);
|
|
86
|
+
// Apart from the column's, as upstream: sharing it opened the drawer over
|
|
87
|
+
// the page on every load, since the column is open by default and its
|
|
88
|
+
// state outlives the page in the cookie.
|
|
89
|
+
const openMobile = signal(false);
|
|
86
90
|
function setOpen(next) {
|
|
87
91
|
open(next);
|
|
88
92
|
props.onOpenChange?.(next);
|
|
89
93
|
}
|
|
90
94
|
function toggleSidebar() {
|
|
91
|
-
|
|
95
|
+
if (mobile())
|
|
96
|
+
openMobile(!openMobile());
|
|
97
|
+
else
|
|
98
|
+
setOpen(!open());
|
|
92
99
|
}
|
|
93
100
|
function onKeyDown(event) {
|
|
94
101
|
if (event.key !== "b" && event.key !== "B")
|
|
@@ -120,9 +127,11 @@ export const SidebarProvider = component((props) => {
|
|
|
120
127
|
}
|
|
121
128
|
const api = provide(SidebarContext, {
|
|
122
129
|
open: current,
|
|
130
|
+
openMobile: () => openMobile(),
|
|
123
131
|
isMobile: () => mobile(),
|
|
124
132
|
state: () => (current() ? "expanded" : "collapsed"),
|
|
125
133
|
setOpen,
|
|
134
|
+
setOpenMobile: (next) => openMobile(next),
|
|
126
135
|
toggleSidebar,
|
|
127
136
|
});
|
|
128
137
|
provide(NearestSidebar, api);
|
|
@@ -138,8 +147,8 @@ export const Sidebar = component((props) => {
|
|
|
138
147
|
const body = props.children?.();
|
|
139
148
|
return html `<div data-slot="sidebar-root">${() => sidebar.isMobile()
|
|
140
149
|
? Sheet({
|
|
141
|
-
open: () => sidebar.
|
|
142
|
-
onOpenChange: (next) => sidebar.
|
|
150
|
+
open: () => sidebar.openMobile(),
|
|
151
|
+
onOpenChange: (next) => sidebar.setOpenMobile(next),
|
|
143
152
|
children: () => SheetContent({
|
|
144
153
|
side,
|
|
145
154
|
closeLabel: props.closeLabel,
|
|
@@ -331,14 +340,22 @@ export const SidebarMenuBadge = component((props) => html `<div
|
|
|
331
340
|
*
|
|
332
341
|
* The widths vary per row, which is what stops a loading column from reading
|
|
333
342
|
* as a bar chart. Seeded from a random draw the moment the row is built, so it
|
|
334
|
-
* does not shift on every re-render.
|
|
343
|
+
* does not shift on every re-render. The draw picks a class, not a `style`
|
|
344
|
+
* attribute, which a Content-Security-Policy without `'unsafe-inline'` blocks.
|
|
335
345
|
*/
|
|
346
|
+
const SKELETON_WIDTHS = [
|
|
347
|
+
"max-w-[50%]",
|
|
348
|
+
"max-w-[60%]",
|
|
349
|
+
"max-w-[70%]",
|
|
350
|
+
"max-w-[80%]",
|
|
351
|
+
"max-w-[90%]",
|
|
352
|
+
];
|
|
336
353
|
export const SidebarMenuSkeleton = component((props) => {
|
|
337
|
-
const width =
|
|
354
|
+
const width = SKELETON_WIDTHS[Math.floor(Math.random() * SKELETON_WIDTHS.length)];
|
|
338
355
|
return html `<div
|
|
339
356
|
data-slot="sidebar-menu-skeleton"
|
|
340
357
|
class="${() => cn("flex h-8 items-center gap-2 rounded-md px-2", read(props.class))}"
|
|
341
|
-
>${props.showIcon === true ? Skeleton({ class: "size-4 rounded-md" }) : null}<div class="flex-1"
|
|
358
|
+
>${props.showIcon === true ? Skeleton({ class: "size-4 rounded-md" }) : null}<div class="${cn("flex-1", width)}">${Skeleton({
|
|
342
359
|
class: "h-4 w-full",
|
|
343
360
|
})}</div></div>`;
|
|
344
361
|
});
|
package/dist/organisms/Sonner.js
CHANGED
|
@@ -509,6 +509,13 @@ export const Toaster = component((props) => {
|
|
|
509
509
|
};
|
|
510
510
|
});
|
|
511
511
|
const resolvedTheme = () => state.theme === "system" ? (prefersDark() ? "dark" : "light") : state.theme;
|
|
512
|
+
/**
|
|
513
|
+
* The list's placement, bound as a `.style` property: the CSSOM is not
|
|
514
|
+
* subject to a Content-Security-Policy, where a `style` attribute is blocked
|
|
515
|
+
* by any policy without `'unsafe-inline'` — and the list then fell into the
|
|
516
|
+
* page flow. The server writes no property, so the list also carries `fixed`
|
|
517
|
+
* as a class: before hydration it is empty, and still out of the flow.
|
|
518
|
+
*/
|
|
512
519
|
function listStyle(corner) {
|
|
513
520
|
const { x, y } = axesOf(corner);
|
|
514
521
|
const rules = [
|
|
@@ -539,8 +546,8 @@ export const Toaster = component((props) => {
|
|
|
539
546
|
data-x-position="${() => axesOf(corner()).x}"
|
|
540
547
|
dir="${props.dir === "auto" ? undefined : props.dir}"
|
|
541
548
|
tabindex="-1"
|
|
542
|
-
class="${() => cn("m-0 box-border list-none p-0 outline-none", read(props.class))}"
|
|
543
|
-
style="${() => listStyle(corner())}"
|
|
549
|
+
class="${() => cn("fixed z-[999999999] m-0 box-border list-none p-0 outline-none", read(props.class))}"
|
|
550
|
+
.style="${() => listStyle(corner())}"
|
|
544
551
|
@pointerenter="${() => expanded(true)}"
|
|
545
552
|
@pointermove="${() => expanded(true)}"
|
|
546
553
|
@pointerleave="${() => {
|
|
@@ -892,7 +899,7 @@ const ToastRow = component((props) => {
|
|
|
892
899
|
data-expanded="${() => String(isExpanded())}"
|
|
893
900
|
data-testid="${() => record().testId}"
|
|
894
901
|
class="${surfaceClasses}"
|
|
895
|
-
style="${style}"
|
|
902
|
+
.style="${style}"
|
|
896
903
|
>${renderClose}${renderIcon}<div
|
|
897
904
|
data-content
|
|
898
905
|
class="${() => cn("flex min-w-0 flex-1 flex-col gap-0.5", state.options.classNames?.content, record().classNames?.content)}"
|
|
@@ -903,7 +910,7 @@ const ToastRow = component((props) => {
|
|
|
903
910
|
? html `<span
|
|
904
911
|
aria-hidden="true"
|
|
905
912
|
class="absolute left-0 bottom-full w-full"
|
|
906
|
-
style="${`height:${state.gap + 1}px`}"
|
|
913
|
+
.style="${`height:${state.gap + 1}px`}"
|
|
907
914
|
></span>`
|
|
908
915
|
: null}</li>`;
|
|
909
916
|
});
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
* ones — so the parts that are easy to get wrong (teardown order, focus
|
|
13
13
|
* restoration, hiding the page from assistive technology) exist once.
|
|
14
14
|
*/
|
|
15
|
+
export { Agenda, type AgendaChange, type AgendaColumn, type AgendaEvent, type AgendaLabels, type AgendaProps, type AgendaRange, type AgendaSlot, type AgendaTone, clampEnd, clampMove, clockOf, isoDay, type Lane, lanesOf, minutesOf, snapDown, snapNearest, } from "./Agenda.js";
|
|
15
16
|
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
17
|
export { addDays, addMonths, Calendar, type CalendarLabels, type CalendarProps, type DateRange, isSameDay, monthGrid, startOfDay, } from "./Calendar.js";
|
|
17
18
|
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";
|
|
19
|
+
export { Chart, type ChartBound, type ChartCategory, type ChartDatum, type ChartProps, type ChartSeries, niceTicks, type ValueAxisOptions, valueAxis, valueRange, visibleCategories, } from "./Chart.js";
|
|
19
20
|
export { Combobox, type ComboboxOption, type ComboboxProps, } from "./Combobox.js";
|
|
20
21
|
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
22
|
export { CommandDialog, type CommandDialogProps } from "./CommandDialog.js";
|
package/dist/organisms/index.js
CHANGED
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
* ones — so the parts that are easy to get wrong (teardown order, focus
|
|
13
13
|
* restoration, hiding the page from assistive technology) exist once.
|
|
14
14
|
*/
|
|
15
|
+
export { Agenda, clampEnd, clampMove, clockOf, isoDay, lanesOf, minutesOf, snapDown, snapNearest, } from "./Agenda.js";
|
|
15
16
|
export { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, } from "./AlertDialog.js";
|
|
16
17
|
export { addDays, addMonths, Calendar, isSameDay, monthGrid, startOfDay, } from "./Calendar.js";
|
|
17
18
|
export { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, } from "./Carousel.js";
|
|
18
|
-
export { Chart, valueRange, } from "./Chart.js";
|
|
19
|
+
export { Chart, niceTicks, valueAxis, valueRange, visibleCategories, } from "./Chart.js";
|
|
19
20
|
export { Combobox, } from "./Combobox.js";
|
|
20
21
|
export { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, defaultFilter, } from "./Command.js";
|
|
21
22
|
export { CommandDialog } from "./CommandDialog.js";
|
|
@@ -32,34 +32,11 @@ import { onExitFinished } from "./presence.js";
|
|
|
32
32
|
*/
|
|
33
33
|
export function floatingSurface(options) {
|
|
34
34
|
let live = null;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (live.anchor === anchor) {
|
|
41
|
-
// The SAME anchor, already open and possibly mid-exit: cancel
|
|
42
|
-
// the teardown and reuse the node rather than stacking a second
|
|
43
|
-
// copy on top of the one fading out.
|
|
44
|
-
live.cancelExit?.();
|
|
45
|
-
live.cancelExit = null;
|
|
46
|
-
live.element.setAttribute("data-state", "open");
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
// A DIFFERENT anchor. Content is built once per open, so reusing
|
|
50
|
-
// this node would show the previous anchor's content — one surface
|
|
51
|
-
// shared by the rows of a table showed the first row's entries
|
|
52
|
-
// however many rows were clicked. Its position, dismissal listeners
|
|
53
|
-
// and focus trap all belong to the old anchor too.
|
|
54
|
-
teardown();
|
|
55
|
-
}
|
|
56
|
-
const mount = portal(options.content());
|
|
57
|
-
const element = mount.host.firstElementChild;
|
|
58
|
-
if (!(element instanceof HTMLElement)) {
|
|
59
|
-
mount.close();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
element.setAttribute("data-state", "open");
|
|
35
|
+
/**
|
|
36
|
+
* Position, dismissal and focus, in that order: the layer registers once
|
|
37
|
+
* the content exists, the trap focuses a surface already positioned.
|
|
38
|
+
*/
|
|
39
|
+
function arm(anchor, element) {
|
|
63
40
|
const position = autoPosition(anchor, element, {
|
|
64
41
|
placement: options.placement,
|
|
65
42
|
offset: options.offset,
|
|
@@ -90,18 +67,67 @@ export function floatingSurface(options) {
|
|
|
90
67
|
else if (options.autoFocus === true) {
|
|
91
68
|
focusSilently(options.initialFocus?.(element) ?? firstFocusable(element));
|
|
92
69
|
}
|
|
93
|
-
|
|
70
|
+
return { position, layer, trap };
|
|
71
|
+
}
|
|
72
|
+
function disarm(current) {
|
|
73
|
+
const armed = current.armed;
|
|
74
|
+
if (armed === null)
|
|
75
|
+
return;
|
|
76
|
+
current.armed = null;
|
|
77
|
+
armed.layer.remove();
|
|
78
|
+
armed.position.stop();
|
|
79
|
+
armed.trap?.release();
|
|
80
|
+
}
|
|
81
|
+
function show() {
|
|
82
|
+
const anchor = options.anchor();
|
|
83
|
+
if (anchor === null)
|
|
84
|
+
return;
|
|
85
|
+
if (live !== null) {
|
|
86
|
+
if (live.anchor === anchor) {
|
|
87
|
+
// The SAME anchor, already open and possibly mid-exit: cancel
|
|
88
|
+
// the teardown and reuse the node rather than stacking a second
|
|
89
|
+
// copy on top of the one fading out.
|
|
90
|
+
live.cancelExit?.();
|
|
91
|
+
live.cancelExit = null;
|
|
92
|
+
live.element.setAttribute("data-state", "open");
|
|
93
|
+
if (live.armed === null) {
|
|
94
|
+
live.armed = arm(anchor, live.element);
|
|
95
|
+
// `onClosed` ran when it started closing, so the component
|
|
96
|
+
// unwired its items; it is open again and rewires them.
|
|
97
|
+
options.onOpened?.(live.element);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// A DIFFERENT anchor. Content is built once per open, so reusing
|
|
102
|
+
// this node would show the previous anchor's content — one surface
|
|
103
|
+
// shared by the rows of a table showed the first row's entries
|
|
104
|
+
// however many rows were clicked. Its position, dismissal listeners
|
|
105
|
+
// and focus trap all belong to the old anchor too.
|
|
106
|
+
teardown();
|
|
107
|
+
}
|
|
108
|
+
const mount = portal(options.content());
|
|
109
|
+
const element = mount.host.firstElementChild;
|
|
110
|
+
if (!(element instanceof HTMLElement)) {
|
|
111
|
+
mount.close();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
element.setAttribute("data-state", "open");
|
|
115
|
+
live = {
|
|
116
|
+
mount,
|
|
117
|
+
anchor,
|
|
118
|
+
element,
|
|
119
|
+
armed: arm(anchor, element),
|
|
120
|
+
cancelExit: null,
|
|
121
|
+
};
|
|
94
122
|
options.onOpened?.(element);
|
|
95
123
|
}
|
|
96
124
|
function hide() {
|
|
97
125
|
const current = live;
|
|
98
|
-
if (current === null)
|
|
126
|
+
if (current === null || current.armed === null)
|
|
99
127
|
return;
|
|
100
128
|
// Detach behaviour first, then animate out. A surface that is fading
|
|
101
129
|
// should not still be answering Escape or repositioning itself.
|
|
102
|
-
current
|
|
103
|
-
current.position.stop();
|
|
104
|
-
current.trap?.release();
|
|
130
|
+
disarm(current);
|
|
105
131
|
returnFocusToAnchor(current.element, current.anchor);
|
|
106
132
|
current.element.setAttribute("data-state", "closed");
|
|
107
133
|
options.onClosed?.();
|
|
@@ -137,9 +163,7 @@ export function floatingSurface(options) {
|
|
|
137
163
|
return;
|
|
138
164
|
live = null;
|
|
139
165
|
current.cancelExit?.();
|
|
140
|
-
current
|
|
141
|
-
current.position.stop();
|
|
142
|
-
current.trap?.release();
|
|
166
|
+
disarm(current);
|
|
143
167
|
current.mount.close();
|
|
144
168
|
}
|
|
145
169
|
onMount(() => {
|
|
@@ -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 {
|
|
@@ -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
|
+
}
|