@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/src/organisms/Dialog.ts
CHANGED
|
@@ -43,12 +43,11 @@ import {
|
|
|
43
43
|
createContext,
|
|
44
44
|
html,
|
|
45
45
|
inject,
|
|
46
|
-
onUnmount,
|
|
47
46
|
provide,
|
|
48
47
|
signal,
|
|
49
48
|
type TemplateResult,
|
|
50
49
|
} from "@c9up/aurora";
|
|
51
|
-
import {
|
|
50
|
+
import { buttonVariants } from "../atoms/Button.js";
|
|
52
51
|
import type { Child, Parts, Slot } from "../lib/children.js";
|
|
53
52
|
import { slot } from "../lib/children.js";
|
|
54
53
|
import { cn } from "../lib/cn.js";
|
|
@@ -58,7 +57,7 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
|
|
|
58
57
|
import { type Reactive, read } from "../lib/props.js";
|
|
59
58
|
import { controllable } from "../primitives/controllable.js";
|
|
60
59
|
import { modalSurface } from "../primitives/modalSurface.js";
|
|
61
|
-
import {
|
|
60
|
+
import { portalOnMount } from "../primitives/portal.js";
|
|
62
61
|
|
|
63
62
|
export const dialogBackdropClasses =
|
|
64
63
|
"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";
|
|
@@ -233,11 +232,10 @@ export interface DialogPortalProps {
|
|
|
233
232
|
* rather than standing in as a passthrough.
|
|
234
233
|
*/
|
|
235
234
|
export const DialogPortal = component<DialogPortalProps>((props) => {
|
|
236
|
-
|
|
235
|
+
portalOnMount(html`${slot(props.children)}`, {
|
|
237
236
|
container: props.container,
|
|
237
|
+
slot: "dialog-portal",
|
|
238
238
|
});
|
|
239
|
-
mounted.host.setAttribute("data-slot", "dialog-portal");
|
|
240
|
-
onUnmount(() => mounted.close());
|
|
241
239
|
return html``;
|
|
242
240
|
});
|
|
243
241
|
|
|
@@ -301,8 +299,9 @@ export const DialogFooter = component<DialogFooterProps>((props) => {
|
|
|
301
299
|
? html`<button
|
|
302
300
|
type="button"
|
|
303
301
|
data-slot="dialog-close"
|
|
302
|
+
class="${buttonVariants({ variant: "outline" })}"
|
|
304
303
|
@click="${() => dialog.setOpen(false)}"
|
|
305
|
-
>${
|
|
304
|
+
>${props.closeLabel ?? "Close"}</button>`
|
|
306
305
|
: null;
|
|
307
306
|
return html`<div
|
|
308
307
|
data-slot="dialog-footer"
|
package/src/organisms/Sidebar.ts
CHANGED
|
@@ -89,10 +89,15 @@ export function sidebarCollapsed(): boolean {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export interface SidebarApi {
|
|
92
|
+
/** The column's state: persisted, and what the wide layout shows. */
|
|
92
93
|
readonly open: () => boolean;
|
|
94
|
+
/** The drawer's state on a phone: closed on every load, never persisted. */
|
|
95
|
+
readonly openMobile: () => boolean;
|
|
93
96
|
readonly isMobile: () => boolean;
|
|
94
97
|
readonly state: () => "expanded" | "collapsed";
|
|
95
98
|
setOpen(next: boolean): void;
|
|
99
|
+
setOpenMobile(next: boolean): void;
|
|
100
|
+
/** The drawer on a phone, the column otherwise. */
|
|
96
101
|
toggleSidebar(): void;
|
|
97
102
|
}
|
|
98
103
|
|
|
@@ -124,6 +129,10 @@ export interface SidebarProviderProps {
|
|
|
124
129
|
export const SidebarProvider = component<SidebarProviderProps>((props) => {
|
|
125
130
|
const open = sidebarState(props.defaultOpen ?? true);
|
|
126
131
|
const mobile = signal(false);
|
|
132
|
+
// Apart from the column's, as upstream: sharing it opened the drawer over
|
|
133
|
+
// the page on every load, since the column is open by default and its
|
|
134
|
+
// state outlives the page in the cookie.
|
|
135
|
+
const openMobile = signal(false);
|
|
127
136
|
|
|
128
137
|
function setOpen(next: boolean): void {
|
|
129
138
|
open(next);
|
|
@@ -131,7 +140,8 @@ export const SidebarProvider = component<SidebarProviderProps>((props) => {
|
|
|
131
140
|
}
|
|
132
141
|
|
|
133
142
|
function toggleSidebar(): void {
|
|
134
|
-
|
|
143
|
+
if (mobile()) openMobile(!openMobile());
|
|
144
|
+
else setOpen(!open());
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
function onKeyDown(event: KeyboardEvent): void {
|
|
@@ -167,9 +177,11 @@ export const SidebarProvider = component<SidebarProviderProps>((props) => {
|
|
|
167
177
|
|
|
168
178
|
const api = provide<SidebarApi>(SidebarContext, {
|
|
169
179
|
open: current,
|
|
180
|
+
openMobile: () => openMobile(),
|
|
170
181
|
isMobile: () => mobile(),
|
|
171
182
|
state: () => (current() ? "expanded" : "collapsed"),
|
|
172
183
|
setOpen,
|
|
184
|
+
setOpenMobile: (next) => openMobile(next),
|
|
173
185
|
toggleSidebar,
|
|
174
186
|
});
|
|
175
187
|
provide(NearestSidebar, api);
|
|
@@ -202,8 +214,8 @@ export const Sidebar = component<SidebarProps>((props) => {
|
|
|
202
214
|
return html`<div data-slot="sidebar-root">${() =>
|
|
203
215
|
sidebar.isMobile()
|
|
204
216
|
? Sheet({
|
|
205
|
-
open: () => sidebar.
|
|
206
|
-
onOpenChange: (next) => sidebar.
|
|
217
|
+
open: () => sidebar.openMobile(),
|
|
218
|
+
onOpenChange: (next) => sidebar.setOpenMobile(next),
|
|
207
219
|
children: () =>
|
|
208
220
|
SheetContent({
|
|
209
221
|
side,
|
|
@@ -562,18 +574,28 @@ export interface SidebarMenuSkeletonProps {
|
|
|
562
574
|
*
|
|
563
575
|
* The widths vary per row, which is what stops a loading column from reading
|
|
564
576
|
* as a bar chart. Seeded from a random draw the moment the row is built, so it
|
|
565
|
-
* does not shift on every re-render.
|
|
577
|
+
* does not shift on every re-render. The draw picks a class, not a `style`
|
|
578
|
+
* attribute, which a Content-Security-Policy without `'unsafe-inline'` blocks.
|
|
566
579
|
*/
|
|
580
|
+
const SKELETON_WIDTHS: readonly string[] = [
|
|
581
|
+
"max-w-[50%]",
|
|
582
|
+
"max-w-[60%]",
|
|
583
|
+
"max-w-[70%]",
|
|
584
|
+
"max-w-[80%]",
|
|
585
|
+
"max-w-[90%]",
|
|
586
|
+
];
|
|
587
|
+
|
|
567
588
|
export const SidebarMenuSkeleton = component<SidebarMenuSkeletonProps>(
|
|
568
589
|
(props) => {
|
|
569
|
-
const width =
|
|
590
|
+
const width =
|
|
591
|
+
SKELETON_WIDTHS[Math.floor(Math.random() * SKELETON_WIDTHS.length)];
|
|
570
592
|
return html`<div
|
|
571
593
|
data-slot="sidebar-menu-skeleton"
|
|
572
594
|
class="${() =>
|
|
573
595
|
cn("flex h-8 items-center gap-2 rounded-md px-2", read(props.class))}"
|
|
574
596
|
>${
|
|
575
597
|
props.showIcon === true ? Skeleton({ class: "size-4 rounded-md" }) : null
|
|
576
|
-
}<div class="flex-1"
|
|
598
|
+
}<div class="${cn("flex-1", width)}">${Skeleton({
|
|
577
599
|
class: "h-4 w-full",
|
|
578
600
|
})}</div></div>`;
|
|
579
601
|
},
|
package/src/organisms/Sonner.ts
CHANGED
|
@@ -872,6 +872,13 @@ export const Toaster = component<ToasterProps>((props) => {
|
|
|
872
872
|
const resolvedTheme = (): "light" | "dark" =>
|
|
873
873
|
state.theme === "system" ? (prefersDark() ? "dark" : "light") : state.theme;
|
|
874
874
|
|
|
875
|
+
/**
|
|
876
|
+
* The list's placement, bound as a `.style` property: the CSSOM is not
|
|
877
|
+
* subject to a Content-Security-Policy, where a `style` attribute is blocked
|
|
878
|
+
* by any policy without `'unsafe-inline'` — and the list then fell into the
|
|
879
|
+
* page flow. The server writes no property, so the list also carries `fixed`
|
|
880
|
+
* as a class: before hydration it is empty, and still out of the flow.
|
|
881
|
+
*/
|
|
875
882
|
function listStyle(corner: Position): string {
|
|
876
883
|
const { x, y } = axesOf(corner);
|
|
877
884
|
const rules = [
|
|
@@ -910,8 +917,8 @@ export const Toaster = component<ToasterProps>((props) => {
|
|
|
910
917
|
data-x-position="${() => axesOf(corner()).x}"
|
|
911
918
|
dir="${props.dir === "auto" ? undefined : props.dir}"
|
|
912
919
|
tabindex="-1"
|
|
913
|
-
class="${() => cn("m-0 box-border list-none p-0 outline-none", read(props.class))}"
|
|
914
|
-
style="${() => listStyle(corner())}"
|
|
920
|
+
class="${() => cn("fixed z-[999999999] m-0 box-border list-none p-0 outline-none", read(props.class))}"
|
|
921
|
+
.style="${() => listStyle(corner())}"
|
|
915
922
|
@pointerenter="${() => expanded(true)}"
|
|
916
923
|
@pointermove="${() => expanded(true)}"
|
|
917
924
|
@pointerleave="${() => {
|
|
@@ -1338,7 +1345,7 @@ const ToastRow = component<ToastRowProps>((props) => {
|
|
|
1338
1345
|
data-expanded="${() => String(isExpanded())}"
|
|
1339
1346
|
data-testid="${() => record().testId}"
|
|
1340
1347
|
class="${surfaceClasses}"
|
|
1341
|
-
style="${style}"
|
|
1348
|
+
.style="${style}"
|
|
1342
1349
|
>${renderClose}${renderIcon}<div
|
|
1343
1350
|
data-content
|
|
1344
1351
|
class="${() =>
|
|
@@ -1360,7 +1367,7 @@ const ToastRow = component<ToastRowProps>((props) => {
|
|
|
1360
1367
|
? html`<span
|
|
1361
1368
|
aria-hidden="true"
|
|
1362
1369
|
class="absolute left-0 bottom-full w-full"
|
|
1363
|
-
style="${`height:${state.gap + 1}px`}"
|
|
1370
|
+
.style="${`height:${state.gap + 1}px`}"
|
|
1364
1371
|
></span>`
|
|
1365
1372
|
: null}</li>`;
|
|
1366
1373
|
});
|
package/src/organisms/index.ts
CHANGED
|
@@ -13,6 +13,26 @@
|
|
|
13
13
|
* restoration, hiding the page from assistive technology) exist once.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
export {
|
|
17
|
+
Agenda,
|
|
18
|
+
type AgendaChange,
|
|
19
|
+
type AgendaColumn,
|
|
20
|
+
type AgendaEvent,
|
|
21
|
+
type AgendaLabels,
|
|
22
|
+
type AgendaProps,
|
|
23
|
+
type AgendaRange,
|
|
24
|
+
type AgendaSlot,
|
|
25
|
+
type AgendaTone,
|
|
26
|
+
clampEnd,
|
|
27
|
+
clampMove,
|
|
28
|
+
clockOf,
|
|
29
|
+
isoDay,
|
|
30
|
+
type Lane,
|
|
31
|
+
lanesOf,
|
|
32
|
+
minutesOf,
|
|
33
|
+
snapDown,
|
|
34
|
+
snapNearest,
|
|
35
|
+
} from "./Agenda.js";
|
|
16
36
|
export {
|
|
17
37
|
AlertDialog,
|
|
18
38
|
AlertDialogAction,
|
|
@@ -57,10 +77,16 @@ export {
|
|
|
57
77
|
} from "./Carousel.js";
|
|
58
78
|
export {
|
|
59
79
|
Chart,
|
|
80
|
+
type ChartBound,
|
|
81
|
+
type ChartCategory,
|
|
60
82
|
type ChartDatum,
|
|
61
83
|
type ChartProps,
|
|
62
84
|
type ChartSeries,
|
|
85
|
+
niceTicks,
|
|
86
|
+
type ValueAxisOptions,
|
|
87
|
+
valueAxis,
|
|
63
88
|
valueRange,
|
|
89
|
+
visibleCategories,
|
|
64
90
|
} from "./Chart.js";
|
|
65
91
|
export {
|
|
66
92
|
Combobox,
|
|
@@ -87,10 +87,20 @@ interface Live {
|
|
|
87
87
|
*/
|
|
88
88
|
readonly anchor: HTMLElement;
|
|
89
89
|
readonly element: HTMLElement;
|
|
90
|
+
/**
|
|
91
|
+
* What makes it behave as an open surface: `null` from the moment it
|
|
92
|
+
* closes, through its exit animation. A surface reopened mid-exit is armed
|
|
93
|
+
* again — reusing the node without this brought it back with no dismiss
|
|
94
|
+
* layer, no repositioning and no focus trap.
|
|
95
|
+
*/
|
|
96
|
+
armed: Armed | null;
|
|
97
|
+
cancelExit: (() => void) | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface Armed {
|
|
90
101
|
readonly position: AutoPosition;
|
|
91
102
|
readonly layer: DismissableLayer;
|
|
92
103
|
readonly trap: FocusTrap | null;
|
|
93
|
-
cancelExit: (() => void) | null;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
/**
|
|
@@ -102,37 +112,11 @@ interface Live {
|
|
|
102
112
|
export function floatingSurface(options: FloatingSurfaceOptions): void {
|
|
103
113
|
let live: Live | null = null;
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (live.anchor === anchor) {
|
|
111
|
-
// The SAME anchor, already open and possibly mid-exit: cancel
|
|
112
|
-
// the teardown and reuse the node rather than stacking a second
|
|
113
|
-
// copy on top of the one fading out.
|
|
114
|
-
live.cancelExit?.();
|
|
115
|
-
live.cancelExit = null;
|
|
116
|
-
live.element.setAttribute("data-state", "open");
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// A DIFFERENT anchor. Content is built once per open, so reusing
|
|
120
|
-
// this node would show the previous anchor's content — one surface
|
|
121
|
-
// shared by the rows of a table showed the first row's entries
|
|
122
|
-
// however many rows were clicked. Its position, dismissal listeners
|
|
123
|
-
// and focus trap all belong to the old anchor too.
|
|
124
|
-
teardown();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const mount = portal(options.content());
|
|
128
|
-
const element = mount.host.firstElementChild;
|
|
129
|
-
if (!(element instanceof HTMLElement)) {
|
|
130
|
-
mount.close();
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
element.setAttribute("data-state", "open");
|
|
135
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Position, dismissal and focus, in that order: the layer registers once
|
|
117
|
+
* the content exists, the trap focuses a surface already positioned.
|
|
118
|
+
*/
|
|
119
|
+
function arm(anchor: HTMLElement, element: HTMLElement): Armed {
|
|
136
120
|
const position = autoPosition(anchor, element, {
|
|
137
121
|
placement: options.placement,
|
|
138
122
|
offset: options.offset,
|
|
@@ -164,20 +148,72 @@ export function floatingSurface(options: FloatingSurfaceOptions): void {
|
|
|
164
148
|
} else if (options.autoFocus === true) {
|
|
165
149
|
focusSilently(options.initialFocus?.(element) ?? firstFocusable(element));
|
|
166
150
|
}
|
|
151
|
+
return { position, layer, trap };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function disarm(current: Live): void {
|
|
155
|
+
const armed = current.armed;
|
|
156
|
+
if (armed === null) return;
|
|
157
|
+
current.armed = null;
|
|
158
|
+
armed.layer.remove();
|
|
159
|
+
armed.position.stop();
|
|
160
|
+
armed.trap?.release();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function show(): void {
|
|
164
|
+
const anchor = options.anchor();
|
|
165
|
+
if (anchor === null) return;
|
|
167
166
|
|
|
168
|
-
live
|
|
167
|
+
if (live !== null) {
|
|
168
|
+
if (live.anchor === anchor) {
|
|
169
|
+
// The SAME anchor, already open and possibly mid-exit: cancel
|
|
170
|
+
// the teardown and reuse the node rather than stacking a second
|
|
171
|
+
// copy on top of the one fading out.
|
|
172
|
+
live.cancelExit?.();
|
|
173
|
+
live.cancelExit = null;
|
|
174
|
+
live.element.setAttribute("data-state", "open");
|
|
175
|
+
if (live.armed === null) {
|
|
176
|
+
live.armed = arm(anchor, live.element);
|
|
177
|
+
// `onClosed` ran when it started closing, so the component
|
|
178
|
+
// unwired its items; it is open again and rewires them.
|
|
179
|
+
options.onOpened?.(live.element);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
// A DIFFERENT anchor. Content is built once per open, so reusing
|
|
184
|
+
// this node would show the previous anchor's content — one surface
|
|
185
|
+
// shared by the rows of a table showed the first row's entries
|
|
186
|
+
// however many rows were clicked. Its position, dismissal listeners
|
|
187
|
+
// and focus trap all belong to the old anchor too.
|
|
188
|
+
teardown();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const mount = portal(options.content());
|
|
192
|
+
const element = mount.host.firstElementChild;
|
|
193
|
+
if (!(element instanceof HTMLElement)) {
|
|
194
|
+
mount.close();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
element.setAttribute("data-state", "open");
|
|
199
|
+
|
|
200
|
+
live = {
|
|
201
|
+
mount,
|
|
202
|
+
anchor,
|
|
203
|
+
element,
|
|
204
|
+
armed: arm(anchor, element),
|
|
205
|
+
cancelExit: null,
|
|
206
|
+
};
|
|
169
207
|
options.onOpened?.(element);
|
|
170
208
|
}
|
|
171
209
|
|
|
172
210
|
function hide(): void {
|
|
173
211
|
const current = live;
|
|
174
|
-
if (current === null) return;
|
|
212
|
+
if (current === null || current.armed === null) return;
|
|
175
213
|
|
|
176
214
|
// Detach behaviour first, then animate out. A surface that is fading
|
|
177
215
|
// should not still be answering Escape or repositioning itself.
|
|
178
|
-
current
|
|
179
|
-
current.position.stop();
|
|
180
|
-
current.trap?.release();
|
|
216
|
+
disarm(current);
|
|
181
217
|
returnFocusToAnchor(current.element, current.anchor);
|
|
182
218
|
current.element.setAttribute("data-state", "closed");
|
|
183
219
|
options.onClosed?.();
|
|
@@ -216,9 +252,7 @@ export function floatingSurface(options: FloatingSurfaceOptions): void {
|
|
|
216
252
|
if (current === null) return;
|
|
217
253
|
live = null;
|
|
218
254
|
current.cancelExit?.();
|
|
219
|
-
current
|
|
220
|
-
current.position.stop();
|
|
221
|
-
current.trap?.release();
|
|
255
|
+
disarm(current);
|
|
222
256
|
current.mount.close();
|
|
223
257
|
}
|
|
224
258
|
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
menuSubTriggerClasses,
|
|
50
50
|
registerSubmenu,
|
|
51
51
|
} from "./menu.js";
|
|
52
|
-
import {
|
|
52
|
+
import { portalOnMount } from "./portal.js";
|
|
53
53
|
|
|
54
54
|
/** What a row needs from the menu it is in. */
|
|
55
55
|
export interface MenuOwner {
|
|
@@ -347,10 +347,10 @@ export function createMenuParts(
|
|
|
347
347
|
});
|
|
348
348
|
|
|
349
349
|
const Portal = component<MenuPortalProps>((props) => {
|
|
350
|
-
|
|
350
|
+
portalOnMount(html`${slot(props.children)}`, {
|
|
351
351
|
container: props.container,
|
|
352
|
+
slot: `${prefix}-portal`,
|
|
352
353
|
});
|
|
353
|
-
mounted.host.setAttribute("data-slot", `${prefix}-portal`);
|
|
354
354
|
return html``;
|
|
355
355
|
});
|
|
356
356
|
|
package/src/primitives/portal.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* content and the discipline to tear both down together.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { render, type TemplateResult } from "@c9up/aurora";
|
|
15
|
+
import { onMount, render, type TemplateResult } from "@c9up/aurora";
|
|
16
16
|
|
|
17
17
|
export interface PortalOptions {
|
|
18
18
|
/** Where to mount. Defaults to `document.body`. */
|
|
@@ -59,3 +59,29 @@ export function portal(
|
|
|
59
59
|
},
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
export interface PortalPartOptions extends PortalOptions {
|
|
64
|
+
/** The host's `data-slot`, naming the part that put it there. */
|
|
65
|
+
slot: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Portal `content` once the calling component is mounted, and close it when
|
|
70
|
+
* the component unmounts. Call it from a component's setup.
|
|
71
|
+
*
|
|
72
|
+
* Setup also runs inside `renderToString`, where there is no document to
|
|
73
|
+
* append a host to, so the portal waits for the mount: the server renders
|
|
74
|
+
* nothing in place and the content is client-only, as a portal that renders
|
|
75
|
+
* only after its mount effect is. The close rides on the same hook, so a part
|
|
76
|
+
* cannot open a portal without also taking it away.
|
|
77
|
+
*/
|
|
78
|
+
export function portalOnMount(
|
|
79
|
+
content: TemplateResult,
|
|
80
|
+
options: PortalPartOptions,
|
|
81
|
+
): void {
|
|
82
|
+
onMount(() => {
|
|
83
|
+
const mounted = portal(content, options);
|
|
84
|
+
mounted.host.setAttribute("data-slot", options.slot);
|
|
85
|
+
return () => mounted.close();
|
|
86
|
+
});
|
|
87
|
+
}
|