@c9up/nebula 0.2.4 → 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.
Files changed (47) hide show
  1. package/README.md +2 -2
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/NativeSelect.d.ts +10 -0
  5. package/dist/atoms/NativeSelect.js +4 -1
  6. package/dist/atoms/Progress.d.ts +9 -1
  7. package/dist/atoms/Progress.js +21 -5
  8. package/dist/atoms/Switch.d.ts +7 -1
  9. package/dist/atoms/Switch.js +7 -1
  10. package/dist/cli/diff.d.ts +46 -0
  11. package/dist/cli/diff.js +73 -2
  12. package/dist/console/DiffCommand.js +6 -11
  13. package/dist/molecules/Accordion.js +1 -2
  14. package/dist/molecules/Collapsible.js +1 -2
  15. package/dist/molecules/Resizable.d.ts +6 -0
  16. package/dist/molecules/Resizable.js +8 -2
  17. package/dist/organisms/AlertDialog.js +4 -5
  18. package/dist/organisms/Chart.d.ts +103 -15
  19. package/dist/organisms/Chart.js +518 -99
  20. package/dist/organisms/Dialog.js +7 -7
  21. package/dist/organisms/Sidebar.d.ts +5 -7
  22. package/dist/organisms/Sidebar.js +23 -6
  23. package/dist/organisms/Sonner.js +11 -4
  24. package/dist/organisms/index.d.ts +1 -1
  25. package/dist/organisms/index.js +1 -1
  26. package/dist/primitives/menuParts.js +3 -3
  27. package/dist/primitives/portal.d.ts +15 -0
  28. package/dist/primitives/portal.js +18 -1
  29. package/nebula.css +1 -1
  30. package/package.json +1 -1
  31. package/src/atoms/AspectRatio.ts +21 -6
  32. package/src/atoms/NativeSelect.ts +14 -1
  33. package/src/atoms/Progress.ts +21 -5
  34. package/src/atoms/Switch.ts +7 -1
  35. package/src/cli/diff.ts +123 -2
  36. package/src/console/DiffCommand.ts +12 -15
  37. package/src/molecules/Accordion.ts +1 -2
  38. package/src/molecules/Collapsible.ts +1 -3
  39. package/src/molecules/Resizable.ts +8 -2
  40. package/src/organisms/AlertDialog.ts +3 -5
  41. package/src/organisms/Chart.ts +633 -125
  42. package/src/organisms/Dialog.ts +6 -7
  43. package/src/organisms/Sidebar.ts +28 -6
  44. package/src/organisms/Sonner.ts +11 -4
  45. package/src/organisms/index.ts +6 -0
  46. package/src/primitives/menuParts.ts +3 -3
  47. package/src/primitives/portal.ts +27 -1
@@ -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, onUnmount, provide, signal, } from "@c9up/aurora";
41
- import { Button } from "../atoms/Button.js";
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 { portal } from "../primitives/portal.js";
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
- const mounted = portal(html `${slot(props.children)}`, {
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
- >${Button({ variant: "outline", children: props.closeLabel ?? "Close" })}</button>`
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
- setOpen(!open());
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.open(),
142
- onOpenChange: (next) => sidebar.setOpen(next),
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 = `${Math.floor(Math.random() * 40) + 50}%`;
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" style="${`max-width: ${width}`}">${Skeleton({
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
  });
@@ -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
  });
@@ -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";
@@ -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";
@@ -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 { portal } from "./portal.js";
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
- const mounted = portal(html `${slot(props.children)}`, {
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
+ }