@c9up/nebula 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +7 -6
  2. package/dist/atoms/Avatar.d.ts +14 -0
  3. package/dist/atoms/Avatar.js +46 -8
  4. package/dist/cli/add.d.ts +2 -0
  5. package/dist/cli/add.js +4 -1
  6. package/dist/cli/diff.d.ts +2 -0
  7. package/dist/cli/diff.js +4 -1
  8. package/dist/cli/projectConfig.d.ts +16 -0
  9. package/dist/cli/projectConfig.js +61 -0
  10. package/dist/console/AddCommand.js +6 -1
  11. package/dist/console/DiffCommand.js +6 -1
  12. package/dist/lib/icons.d.ts +8 -0
  13. package/dist/lib/icons.js +8 -0
  14. package/dist/lib/image.js +12 -1
  15. package/dist/molecules/InputOTP.d.ts +12 -0
  16. package/dist/molecules/InputOTP.js +68 -27
  17. package/dist/molecules/index.d.ts +1 -1
  18. package/dist/molecules/index.js +1 -1
  19. package/dist/organisms/Combobox.d.ts +13 -0
  20. package/dist/organisms/Combobox.js +5 -2
  21. package/dist/organisms/Command.js +56 -8
  22. package/dist/organisms/Form.d.ts +15 -0
  23. package/dist/organisms/Form.js +10 -0
  24. package/dist/organisms/Select.d.ts +6 -4
  25. package/dist/organisms/Select.js +1 -0
  26. package/dist/organisms/Sidebar.d.ts +4 -2
  27. package/dist/organisms/Sidebar.js +54 -26
  28. package/dist/organisms/Sonner.d.ts +243 -0
  29. package/dist/organisms/Sonner.js +909 -0
  30. package/dist/organisms/Toaster.d.ts +9 -0
  31. package/dist/organisms/Toaster.js +28 -5
  32. package/dist/organisms/Tooltip.d.ts +4 -0
  33. package/dist/organisms/index.d.ts +6 -0
  34. package/dist/organisms/index.js +6 -0
  35. package/dist/primitives/dismissable.d.ts +11 -4
  36. package/dist/primitives/dismissable.js +8 -6
  37. package/dist/primitives/floating.d.ts +5 -1
  38. package/dist/primitives/floating.js +8 -1
  39. package/dist/primitives/menu.js +2 -1
  40. package/dist/primitives/modalSurface.js +70 -36
  41. package/dist/primitives/presence.js +8 -5
  42. package/nebula.css +2 -2
  43. package/package.json +1 -1
  44. package/registry.json +13 -0
  45. package/src/atoms/Avatar.ts +54 -7
  46. package/src/cli/add.ts +7 -1
  47. package/src/cli/diff.ts +7 -1
  48. package/src/cli/projectConfig.ts +71 -0
  49. package/src/console/AddCommand.ts +6 -1
  50. package/src/console/DiffCommand.ts +6 -1
  51. package/src/lib/icons.ts +28 -0
  52. package/src/lib/image.ts +13 -1
  53. package/src/molecules/InputOTP.ts +81 -27
  54. package/src/molecules/index.ts +3 -0
  55. package/src/organisms/Combobox.ts +18 -2
  56. package/src/organisms/Command.ts +66 -7
  57. package/src/organisms/Form.ts +21 -0
  58. package/src/organisms/Select.ts +7 -4
  59. package/src/organisms/Sidebar.ts +47 -19
  60. package/src/organisms/Sonner.ts +1366 -0
  61. package/src/organisms/Toaster.ts +30 -6
  62. package/src/organisms/Tooltip.ts +4 -0
  63. package/src/organisms/index.ts +23 -0
  64. package/src/primitives/dismissable.ts +16 -8
  65. package/src/primitives/floating.ts +13 -2
  66. package/src/primitives/menu.ts +2 -1
  67. package/src/primitives/modalSurface.ts +77 -40
  68. package/src/primitives/presence.ts +12 -9
package/README.md CHANGED
@@ -8,7 +8,7 @@ Part of **[Ream](https://github.com/C9up/ream)** — a Rust-powered, AdonisJS-co
8
8
 
9
9
  shadcn/ui is React. [Aurora](https://github.com/C9up/aurora) is a tagged-template DOM runtime with signals and no build step. nebula is the shadcn component set — the same markup, the same Tailwind classes, the same behaviour — written for Aurora.
10
10
 
11
- Seventy-four components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
11
+ Seventy-six components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
12
12
 
13
13
  ## Installation
14
14
 
@@ -67,9 +67,9 @@ shadcn stands on Radix, `clsx`, `tailwind-merge`, `class-variance-authority`, `l
67
67
  | `class-variance-authority` | `lib/cva.ts` — reimplemented, and it runs its result through `cn` |
68
68
  | Radix UI | `primitives/` — focus trap, dismissable layers, roving focus, type-ahead, presence, portals |
69
69
  | `@floating-ui/dom` | `primitives/floating.ts` — offset, flip, shift, arrow, available height |
70
- | `lucide-react` | `lib/icons.ts` — the eighteen glyphs the set needs, inlined |
70
+ | `lucide-react` | `lib/icons.ts` — the twenty-six glyphs the set needs, inlined |
71
71
  | `cmdk` | `organisms/Command.ts` |
72
- | `sonner` | `organisms/Toaster.ts` |
72
+ | `sonner` | `organisms/Sonner.ts` |
73
73
  | `react-day-picker` + `date-fns` | `organisms/Calendar.ts` — `Date` and `Intl` |
74
74
  | `@tanstack/react-table` | `organisms/DataTable.ts` — sort, filter, page, select |
75
75
  | `recharts` | `organisms/Chart.ts` — line, area and bar, as inline SVG |
@@ -90,7 +90,8 @@ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvide
90
90
  | DataTable | TanStack Table (column grouping, virtualisation, pinning, faceted filters, server-side) | sort, filter, page, select — in memory |
91
91
  | Sidebar | ~15 parts | the parts that are not re-skinned atoms — see below |
92
92
  | Carousel | embla (loop, autoplay, N slides per view) | scroll-snap, one slide per view, no loop or autoplay |
93
- | Toaster | Base UI's manager (display priority, anchored toasts, typed payload) — or sonner, with six positions | five variants, promise toasts, update and dedup by id, action, `onClose`, pause on hover, four corners |
93
+ | Sonner | sonner, in full | sonner's `toast` API and Toaster props, six positions, the stack that fans out on hover, rich colours, `Alt+T`; no swipe to dismiss, no `getHistory`, and `toast.promise` returns `{ id, unwrap }` |
94
+ | Toaster (deprecated) | Base UI's manager (display priority, anchored toasts, typed payload) — shadcn has deprecated it for sonner, and so has nebula | five variants, promise toasts, update and dedup by id, action, `onClose`, pause on hover, four corners |
94
95
  | Resizable | arbitrary nesting, persisted layouts, collapse-to-zero | two panes, one handle |
95
96
  | Combobox | single, multi-select and creatable recipes | single-select |
96
97
  | ScrollArea | scrollbars redrawn by Radix | native scrollbars, styled |
@@ -194,13 +195,13 @@ resources/pages/
194
195
  The rule is composition, not complexity. Slider is an atom though it is interactive, because it is one input. Card is a molecule though it is trivial, because it assembles parts.
195
196
 
196
197
  <details>
197
- <summary><strong>All 75 components</strong></summary>
198
+ <summary><strong>All 76 components</strong></summary>
198
199
 
199
200
  **atoms (22)** — AccessibleIcon, AspectRatio, Avatar, Badge, Button, Checkbox, Image, Input, Kbd, Label, Marker, NativeSelect, Progress, ScrollArea, Separator, Skeleton, Slider, Spinner, Switch, Textarea, Toggle, VisuallyHidden
200
201
 
201
202
  **molecules (24)** — Accordion, Alert, Attachment, Breadcrumb, Bubble, ButtonGroup, Card, Collapsible, Empty, Field, InputGroup, InputOTP, Item, Message, Pagination, Picture, PieceMap, RadioGroup, Resizable, Table, Tabs, ToggleGroup, Toolbar, Typography
202
203
 
203
- **organisms (26)** — AlertDialog, Calendar, Carousel, Chart, Combobox, Command, CommandDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, Dialog, Drawer, DropdownMenu, Form, HoverCard, Menubar, MessageScroller, NavigationMenu, Popover, Questionnaire, Select, Sheet, Sidebar, Toaster, Tooltip
204
+ **organisms (27)** — AlertDialog, Calendar, Carousel, Chart, Combobox, Command, CommandDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, Dialog, Drawer, DropdownMenu, Form, HoverCard, Menubar, MessageScroller, NavigationMenu, Popover, Questionnaire, Select, Sheet, Sidebar, Sonner, Toaster, Tooltip
204
205
 
205
206
  **templates (3)** — AppShell, AuthLayout, SettingsLayout
206
207
 
@@ -26,8 +26,22 @@ export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/
26
26
  export interface AvatarImageProps {
27
27
  src?: Reactive<string | undefined>;
28
28
  alt?: Reactive<string>;
29
+ /**
30
+ * Sent with the request for the picture. `"no-referrer"` keeps the page's
31
+ * URL from a host the picture comes from — a user-supplied avatar URL.
32
+ */
33
+ referrerPolicy?: ReferrerPolicy;
34
+ crossOrigin?: "anonymous" | "use-credentials";
29
35
  class?: Reactive<string>;
30
36
  }
37
+ /**
38
+ * The picture, once it has loaded.
39
+ *
40
+ * As Radix's `useImageLoadingStatus`: the source is preloaded off-document,
41
+ * with its referrer policy and CORS mode, and tried again whenever it
42
+ * changes — a broken avatar replaced by a new upload shows the new one. The
43
+ * `<img>` is rendered only once loaded, so a broken picture is never painted.
44
+ */
31
45
  export declare const AvatarImage: (props?: AvatarImageProps | undefined) => import("@c9up/aurora").TemplateResult;
32
46
  export interface AvatarFallbackProps {
33
47
  children?: Slot;
@@ -15,7 +15,7 @@
15
15
  * the fallback reads it, and neither knows the other exists. Radix needs the
16
16
  * same three pieces for the same reason.
17
17
  */
18
- import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
18
+ import { component, createContext, effect, html, inject, onMount, provide, signal, } from "@c9up/aurora";
19
19
  import { slot } from "../lib/children.js";
20
20
  import { cn } from "../lib/cn.js";
21
21
  import { read, readOr } from "../lib/props.js";
@@ -35,23 +35,61 @@ export const Avatar = component((props) => {
35
35
  class="${() => cn("group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6", read(props.class))}"
36
36
  >${props.children?.()}</span>`;
37
37
  });
38
+ /**
39
+ * The picture, once it has loaded.
40
+ *
41
+ * As Radix's `useImageLoadingStatus`: the source is preloaded off-document,
42
+ * with its referrer policy and CORS mode, and tried again whenever it
43
+ * changes — a broken avatar replaced by a new upload shows the new one. The
44
+ * `<img>` is rendered only once loaded, so a broken picture is never painted.
45
+ */
38
46
  export const AvatarImage = component((props) => {
39
47
  const avatar = inject(AvatarContext);
40
- const hasSrc = () => {
48
+ const source = () => {
41
49
  const src = read(props.src);
42
- return src !== undefined && src !== "";
50
+ return src === undefined || src === "" ? undefined : src;
43
51
  };
44
52
  // Reported during setup, so the fallback built after it already reads the
45
53
  // right state rather than flashing through `absent`.
46
- avatar.setState(hasSrc() ? "pending" : "absent");
47
- return html `${() => hasSrc() && avatar.state() !== "failed"
54
+ avatar.setState(source() === undefined ? "absent" : "pending");
55
+ onMount(() => effect(() => {
56
+ const src = source();
57
+ if (src === undefined) {
58
+ avatar.setState("absent");
59
+ return;
60
+ }
61
+ avatar.setState("pending");
62
+ // A load still in flight for a source it has moved past must not
63
+ // decide the state of the current one.
64
+ let current = true;
65
+ const settle = (next) => {
66
+ if (current)
67
+ avatar.setState(next);
68
+ };
69
+ const image = new Image();
70
+ image.addEventListener("load", () => {
71
+ settle(image.naturalWidth > 0 ? "loaded" : "failed");
72
+ });
73
+ image.addEventListener("error", () => settle("failed"));
74
+ if (props.referrerPolicy !== undefined) {
75
+ image.referrerPolicy = props.referrerPolicy;
76
+ }
77
+ image.crossOrigin = props.crossOrigin ?? null;
78
+ image.src = src;
79
+ if (image.complete && image.naturalWidth > 0)
80
+ settle("loaded");
81
+ return () => {
82
+ current = false;
83
+ };
84
+ }));
85
+ return html `${() => avatar.state() === "loaded"
48
86
  ? html `<img
49
87
  data-slot="avatar-image"
50
- src="${() => read(props.src)}"
88
+ src="${source}"
51
89
  alt="${() => readOr(props.alt, "")}"
90
+ referrerpolicy="${props.referrerPolicy}"
91
+ crossorigin="${props.crossOrigin}"
52
92
  class="${() => cn("aspect-square size-full object-cover", read(props.class))}"
53
- @load="${() => avatar.setState("loaded")}"
54
- @error="${() => avatar.setState("failed")}"
55
93
  />`
56
94
  : null}`;
57
95
  });
package/dist/cli/add.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface AddOptions {
21
21
  paths?: Partial<NebulaPaths>;
22
22
  /** Overrides both the detected language and the configured one. */
23
23
  language?: Language;
24
+ /** The configured language: used when the tree says nothing. */
25
+ defaultLanguage?: Language;
24
26
  force?: boolean;
25
27
  /** Print what would happen and write nothing. */
26
28
  dryRun?: boolean;
package/dist/cli/add.js CHANGED
@@ -60,7 +60,10 @@ export function add(options) {
60
60
  const registry = loadRegistry(join(root, "registry.json"));
61
61
  const items = resolveItems(registry, options.names);
62
62
  const target = join(options.cwd, options.paths?.components ?? defaultPaths.components);
63
- const language = options.language ?? detectLanguage(target) ?? "js";
63
+ const language = options.language ??
64
+ detectLanguage(target) ??
65
+ options.defaultLanguage ??
66
+ "js";
64
67
  // The compiled output is what a browser can load. It ships in the package
65
68
  // and `prepublishOnly` rebuilds it, so an installed copy always has it;
66
69
  // inside this workspace it needs `pnpm build` first.
@@ -33,6 +33,8 @@ export interface DiffOptions {
33
33
  cwd: string;
34
34
  paths?: Partial<NebulaPaths>;
35
35
  language?: Language;
36
+ /** The configured language: used when the tree says nothing. */
37
+ defaultLanguage?: Language;
36
38
  }
37
39
  export interface DiffResult {
38
40
  entries: DiffEntry[];
package/dist/cli/diff.js CHANGED
@@ -27,7 +27,10 @@ import { loadRegistry, packageRoot } from "./registry.js";
27
27
  export function diff(options) {
28
28
  const paths = { ...defaultPaths, ...options.paths };
29
29
  const target = join(options.cwd, paths.components);
30
- const language = options.language ?? detectLanguage(target) ?? "js";
30
+ const language = options.language ??
31
+ detectLanguage(target) ??
32
+ options.defaultLanguage ??
33
+ "js";
31
34
  const root = packageRoot(join(options.cwd, "package.json"));
32
35
  const sourceRoot = join(root, language === "ts" ? "src" : "dist");
33
36
  const registry = loadRegistry(join(root, "registry.json"));
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The app's `config/nebula.ts`, as the copying commands read it.
3
+ *
4
+ * shadcn's CLI reads `components.json` on every `add` and `diff`; these read
5
+ * the config file the same way. Imported directly rather than taken from the
6
+ * booted application: the console kernel hands the app — and its config —
7
+ * only to a command that starts it, and starting it opens the connections a
8
+ * file copy has no use for, and fails where they are not running.
9
+ */
10
+ import type { Language, NebulaPaths } from "../config.js";
11
+ export interface ProjectConfig {
12
+ paths?: Partial<NebulaPaths>;
13
+ language?: Language;
14
+ }
15
+ /** The config under `<cwd>/config`, or nothing when the app has none. */
16
+ export declare function loadProjectConfig(cwd: string): Promise<ProjectConfig>;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The app's `config/nebula.ts`, as the copying commands read it.
3
+ *
4
+ * shadcn's CLI reads `components.json` on every `add` and `diff`; these read
5
+ * the config file the same way. Imported directly rather than taken from the
6
+ * booted application: the console kernel hands the app — and its config —
7
+ * only to a command that starts it, and starting it opens the connections a
8
+ * file copy has no use for, and fails where they are not running.
9
+ */
10
+ import { existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { pathToFileURL } from "node:url";
13
+ /** Tried in order; the first that exists is the config. */
14
+ const CANDIDATES = ["nebula.ts", "nebula.js", "nebula.mjs"];
15
+ function isRecord(value) {
16
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17
+ }
18
+ function pathsOf(value, file) {
19
+ if (value === undefined)
20
+ return undefined;
21
+ if (!isRecord(value)) {
22
+ throw new Error(`${file}: \`paths\` must be an object.`);
23
+ }
24
+ const paths = {};
25
+ for (const key of ["components", "css", "output"]) {
26
+ const entry = value[key];
27
+ if (entry === undefined)
28
+ continue;
29
+ if (typeof entry !== "string" || entry === "") {
30
+ throw new Error(`${file}: \`paths.${key}\` must be a non-empty string.`);
31
+ }
32
+ paths[key] = entry;
33
+ }
34
+ return paths;
35
+ }
36
+ function languageOf(value, file) {
37
+ if (value === undefined)
38
+ return undefined;
39
+ if (value === "ts" || value === "js")
40
+ return value;
41
+ throw new Error(`${file}: \`language\` must be "ts" or "js".`);
42
+ }
43
+ /** The config under `<cwd>/config`, or nothing when the app has none. */
44
+ export async function loadProjectConfig(cwd) {
45
+ for (const name of CANDIDATES) {
46
+ const file = join(cwd, "config", name);
47
+ if (!existsSync(file))
48
+ continue;
49
+ const label = `config/${name}`;
50
+ const loaded = await import(pathToFileURL(file).href);
51
+ const config = isRecord(loaded) ? loaded.default : undefined;
52
+ if (!isRecord(config)) {
53
+ throw new Error(`${label} must export its config as the default export.`);
54
+ }
55
+ return {
56
+ paths: pathsOf(config.paths, label),
57
+ language: languageOf(config.language, label),
58
+ };
59
+ }
60
+ return {};
61
+ }
@@ -11,6 +11,7 @@
11
11
  * of a Rust binary, and that binary is not on crates.io.
12
12
  */
13
13
  import { add } from "../cli/add.js";
14
+ import { loadProjectConfig } from "../cli/projectConfig.js";
14
15
  import { argument, flag } from "./contract.js";
15
16
  export default class NebulaAddCommand {
16
17
  static commandName = "nebula:add";
@@ -57,12 +58,16 @@ export default class NebulaAddCommand {
57
58
  process.exitCode = 1;
58
59
  return;
59
60
  }
61
+ const cwd = process.cwd();
62
+ const config = await loadProjectConfig(cwd);
60
63
  const result = add({
61
- cwd: process.cwd(),
64
+ cwd,
62
65
  names: this.components,
63
66
  force: this.force,
64
67
  dryRun: this.dryRun,
68
+ paths: config.paths,
65
69
  language: this.ts ? "ts" : this.js ? "js" : undefined,
70
+ defaultLanguage: config.language,
66
71
  });
67
72
  const out = [""];
68
73
  for (const path of result.written)
@@ -7,6 +7,7 @@
7
7
  * is the one place it becomes visible.
8
8
  */
9
9
  import { diff } from "../cli/diff.js";
10
+ import { loadProjectConfig } from "../cli/projectConfig.js";
10
11
  import { flag } from "./contract.js";
11
12
  /** What each state means, and what to do about it. */
12
13
  const EXPLAIN = {
@@ -44,9 +45,13 @@ export default class NebulaDiffCommand {
44
45
  ts = false;
45
46
  js = false;
46
47
  async run() {
48
+ const cwd = process.cwd();
49
+ const config = await loadProjectConfig(cwd);
47
50
  const result = diff({
48
- cwd: process.cwd(),
51
+ cwd,
52
+ paths: config.paths,
49
53
  language: this.ts ? "ts" : this.js ? "js" : undefined,
54
+ defaultLanguage: config.language,
50
55
  });
51
56
  if (result.entries.length === 0) {
52
57
  process.stdout.write("\n Every copied component matches the installed package.\n\n");
@@ -40,5 +40,13 @@ export declare const ArrowRightIcon: (props?: IconProps) => TemplateResult;
40
40
  export declare const CalendarIcon: (props?: IconProps) => TemplateResult;
41
41
  export declare const PanelLeftIcon: (props?: IconProps) => TemplateResult;
42
42
  export declare const GripVerticalIcon: (props?: IconProps) => TemplateResult;
43
+ /** Lucide `circle-check` — shadcn's Sonner success icon. */
44
+ export declare const CircleCheckIcon: (props?: IconProps) => TemplateResult;
45
+ /** Lucide `info` — shadcn's Sonner info icon. */
46
+ export declare const InfoIcon: (props?: IconProps) => TemplateResult;
47
+ /** Lucide `triangle-alert` — shadcn's Sonner warning icon. */
48
+ export declare const TriangleAlertIcon: (props?: IconProps) => TemplateResult;
49
+ /** Lucide `octagon-x` — shadcn's Sonner error icon. */
50
+ export declare const OctagonXIcon: (props?: IconProps) => TemplateResult;
43
51
  /** The arc Lucide uses for `loader-circle`; spun by the Spinner's animation. */
44
52
  export declare const LoaderIcon: (props?: IconProps) => TemplateResult;
package/dist/lib/icons.js CHANGED
@@ -75,5 +75,13 @@ export const GripVerticalIcon = (props) => svg(html `<circle cx="9" cy="12" r="1
75
75
  cy="19"
76
76
  r="1"
77
77
  />`, props);
78
+ /** Lucide `circle-check` — shadcn's Sonner success icon. */
79
+ export const CircleCheckIcon = (props) => svg(html `<circle cx="12" cy="12" r="10" /><path d="m16 9-5.5 5.5L8 12" />`, props);
80
+ /** Lucide `info` — shadcn's Sonner info icon. */
81
+ export const InfoIcon = (props) => svg(html `<circle cx="12" cy="12" r="10" /><path d="M12 16v-4" /><path d="M12 8h.01" />`, props);
82
+ /** Lucide `triangle-alert` — shadcn's Sonner warning icon. */
83
+ export const TriangleAlertIcon = (props) => svg(html `<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /><path d="M12 9v4" /><path d="M12 17h.01" />`, props);
84
+ /** Lucide `octagon-x` — shadcn's Sonner error icon. */
85
+ export const OctagonXIcon = (props) => svg(html `<path d="m15 9-6 6" /><path d="M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z" /><path d="m9 9 6 6" />`, props);
78
86
  /** The arc Lucide uses for `loader-circle`; spun by the Spinner's animation. */
79
87
  export const LoaderIcon = (props) => svg(html `<path d="M21 12a9 9 0 1 1-6.219-8.56" />`, props);
package/dist/lib/image.js CHANGED
@@ -224,6 +224,17 @@ let endpoint = "/__image";
224
224
  export function setImageEndpoint(path) {
225
225
  endpoint = path;
226
226
  }
227
+ /**
228
+ * A root-relative `src` as the path under the endpoint's public roots.
229
+ *
230
+ * `/photos/hero.png` is how a page names a public file, and the endpoint
231
+ * resolves `src` inside its roots, refusing an absolute path: sent as is,
232
+ * every variant is a 404. Exactly one slash goes, so a protocol-relative
233
+ * `//host/…` stays what it is and is left to an application's own resolver.
234
+ */
235
+ function relativeToRoots(src) {
236
+ return src.startsWith("/") && !src.startsWith("//") ? src.slice(1) : src;
237
+ }
227
238
  /**
228
239
  * The resolver used when an application installs none.
229
240
  *
@@ -233,7 +244,7 @@ export function setImageEndpoint(path) {
233
244
  */
234
245
  export const defaultImageResolver = (src, transform) => {
235
246
  const params = new URLSearchParams({
236
- src,
247
+ src: relativeToRoots(src),
237
248
  w: String(Math.round(transform.width)),
238
249
  });
239
250
  if (transform.format !== undefined)
@@ -19,9 +19,21 @@
19
19
  */
20
20
  import type { Parts, Slot } from "../lib/children.js";
21
21
  import { type Reactive } from "../lib/props.js";
22
+ /** input-otp's patterns, for the `pattern` prop. */
23
+ export declare const REGEXP_ONLY_DIGITS = "^\\d+$";
24
+ export declare const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
25
+ export declare const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
22
26
  export interface InputOTPProps {
23
27
  /** Number of boxes. Default `6` — and it must match the slots built. */
24
28
  length?: number;
29
+ /**
30
+ * What the code may hold, tested against the whole value as input-otp
31
+ * does: a character or a fill that would not match is refused. None by
32
+ * default, as input-otp; `REGEXP_ONLY_DIGITS` for a numeric code.
33
+ */
34
+ pattern?: RegExp | string;
35
+ /** The on-screen keyboard. Default `"numeric"`. */
36
+ inputMode?: "numeric" | "text";
25
37
  /** Each box's accessible name from its position. Default `"Character 2 of 6"`. */
26
38
  slotLabel?: (position: number, length: number) => string;
27
39
  name?: string;
@@ -25,6 +25,10 @@ import { uid } from "../lib/id.js";
25
25
  import { read, readOr } from "../lib/props.js";
26
26
  const slotClasses = "border-input relative flex size-9 items-center justify-center border-y border-r text-center text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md focus:border-ring focus:ring-ring/50 focus:z-10 focus:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
27
27
  const InputOTPContext = createContext("InputOTP");
28
+ /** input-otp's patterns, for the `pattern` prop. */
29
+ export const REGEXP_ONLY_DIGITS = "^\\d+$";
30
+ export const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
31
+ export const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
28
32
  export const InputOTP = component((props) => {
29
33
  const length = props.length ?? 6;
30
34
  const groupId = uid("input-otp");
@@ -58,8 +62,45 @@ export const InputOTP = component((props) => {
58
62
  next[index] = character;
59
63
  commit(next);
60
64
  }
65
+ const pattern = typeof props.pattern === "string"
66
+ ? new RegExp(props.pattern)
67
+ : props.pattern;
68
+ function accepts(next) {
69
+ const joined = next.join("");
70
+ return pattern === undefined || joined === "" || pattern.test(joined);
71
+ }
72
+ /** Put the boxes back to what the code holds. */
73
+ function reflect() {
74
+ const inputs = boxes();
75
+ characters().forEach((character, position) => {
76
+ const input = inputs[position];
77
+ if (input !== undefined)
78
+ input.value = character;
79
+ });
80
+ }
81
+ /**
82
+ * Share a run of characters out over the boxes from `index`: a paste, and
83
+ * a whole code an autofill or an IME put into one box.
84
+ */
85
+ function spread(index, text) {
86
+ const next = [...characters()];
87
+ let cursor = index;
88
+ for (const character of text) {
89
+ if (cursor >= length)
90
+ break;
91
+ next[cursor] = character;
92
+ cursor += 1;
93
+ }
94
+ if (accepts(next))
95
+ commit(next);
96
+ // The boxes are uncontrolled between keystrokes, so writing the signal
97
+ // alone would leave the characters invisible — or a refused fill in place.
98
+ reflect();
99
+ focusBox(Math.min(cursor, length - 1));
100
+ }
61
101
  provide(InputOTPContext, {
62
102
  length,
103
+ inputMode: props.inputMode ?? "numeric",
63
104
  disabled: () => readOr(props.disabled, false),
64
105
  slotLabel: props.slotLabel ??
65
106
  ((position, total) => `Character ${position} of ${total}`),
@@ -72,12 +113,30 @@ export const InputOTP = component((props) => {
72
113
  const target = event.target;
73
114
  if (!(target instanceof HTMLInputElement))
74
115
  return;
75
- // A box already holding a character receives the new one appended; keep
76
- // the last, which is what the user just typed.
77
- const typed = target.value.slice(-1);
78
- target.value = typed;
79
- write(index, typed);
80
- if (typed !== "" && index < length - 1)
116
+ const value = target.value;
117
+ // One key pressed in a box already holding a character: the box holds
118
+ // both, and the one just typed is what counts.
119
+ const typed = event instanceof InputEvent &&
120
+ event.inputType === "insertText" &&
121
+ event.data !== null &&
122
+ [...event.data].length === 1
123
+ ? event.data
124
+ : undefined;
125
+ if ([...value].length > 1 && typed === undefined) {
126
+ // A whole code at once: autofill, a password manager, an IME.
127
+ spread(index, value);
128
+ return;
129
+ }
130
+ const character = typed ?? value;
131
+ const next = [...characters()];
132
+ next[index] = character;
133
+ if (!accepts(next)) {
134
+ target.value = characters()[index] ?? "";
135
+ return;
136
+ }
137
+ target.value = character;
138
+ commit(next);
139
+ if (character !== "" && index < length - 1)
81
140
  focusBox(index + 1);
82
141
  },
83
142
  onKeyDown(index, event) {
@@ -104,25 +163,7 @@ export const InputOTP = component((props) => {
104
163
  if (pasted === "")
105
164
  return;
106
165
  event.preventDefault();
107
- const next = [...characters()];
108
- let cursor = index;
109
- for (const character of pasted) {
110
- if (cursor >= length)
111
- break;
112
- next[cursor] = character;
113
- cursor += 1;
114
- }
115
- commit(next);
116
- // Reflect into the DOM: the boxes are uncontrolled between keystrokes,
117
- // so writing the signal alone would leave the pasted characters
118
- // invisible.
119
- const inputs = boxes();
120
- next.forEach((character, position) => {
121
- const input = inputs[position];
122
- if (input !== undefined)
123
- input.value = character;
124
- });
125
- focusBox(Math.min(cursor, length - 1));
166
+ spread(index, pasted);
126
167
  },
127
168
  });
128
169
  return html `<div
@@ -155,9 +196,9 @@ export const InputOTPSlot = component((props) => {
155
196
  data-slot="input-otp-slot"
156
197
  data-otp-index="${index}"
157
198
  type="text"
158
- inputmode="numeric"
199
+ inputmode="${otp.inputMode}"
159
200
  autocomplete="${index === 0 ? "one-time-code" : "off"}"
160
- maxlength="1"
201
+ maxlength="${otp.length}"
161
202
  aria-label="${otp.slotLabel(index + 1, otp.length)}"
162
203
  ?disabled="${() => otp.disabled()}"
163
204
  class="${() => cn(slotClasses, read(props.class))}"
@@ -26,7 +26,7 @@ export { Collapsible, CollapsibleContent, type CollapsibleContentProps, type Col
26
26
  export { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, type EmptyProps, EmptyTitle, } from "./Empty.js";
27
27
  export { Field, FieldContent, FieldDescription, FieldError, type FieldErrorProps, FieldGroup, type FieldIds, FieldLabel, FieldLegend, type FieldLegendProps, type FieldProps, type FieldSectionProps, FieldSeparator, type FieldSeparatorProps, FieldSet, FieldTitle, fieldIds, } from "./Field.js";
28
28
  export { InputGroup, InputGroupAddon, type InputGroupAddonProps, InputGroupButton, type InputGroupButtonProps, InputGroupInput, type InputGroupProps, InputGroupText, InputGroupTextarea, type InputGroupTextProps, inputGroupControlClasses, } from "./InputGroup.js";
29
- export { InputOTP, InputOTPGroup, type InputOTPGroupProps, type InputOTPProps, InputOTPSeparator, type InputOTPSeparatorProps, InputOTPSlot, type InputOTPSlotProps, } from "./InputOTP.js";
29
+ export { InputOTP, InputOTPGroup, type InputOTPGroupProps, type InputOTPProps, InputOTPSeparator, type InputOTPSeparatorProps, InputOTPSlot, type InputOTPSlotProps, REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS, } from "./InputOTP.js";
30
30
  export { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, type ItemProps, ItemSeparator, ItemTitle, type ItemVariants, itemVariants, } from "./Item.js";
31
31
  export { Message, type MessageProps } from "./Message.js";
32
32
  export { type PageSlot, Pagination, PaginationContent, PaginationEllipsis, type PaginationEllipsisProps, PaginationItem, type PaginationLabels, PaginationLink, type PaginationLinkProps, type PaginationNavProps, PaginationNext, PaginationPrevious, type PaginationProps, type PaginationStepProps, pageWindow, } from "./Pagination.js";
@@ -26,7 +26,7 @@ export { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "./Collapsi
26
26
  export { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from "./Empty.js";
27
27
  export { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle, fieldIds, } from "./Field.js";
28
28
  export { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, inputGroupControlClasses, } from "./InputGroup.js";
29
- export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "./InputOTP.js";
29
+ export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS, } from "./InputOTP.js";
30
30
  export { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, ItemSeparator, ItemTitle, itemVariants, } from "./Item.js";
31
31
  export { Message } from "./Message.js";
32
32
  export { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, pageWindow, } from "./Pagination.js";
@@ -23,8 +23,21 @@ export interface ComboboxOption {
23
23
  disabled?: boolean;
24
24
  group?: string;
25
25
  }
26
+ /**
27
+ * `id`, `label`, `labelledBy` and `describedBy` name the trigger. Upstream's
28
+ * trigger is a Button that takes every button prop; these are the ones that
29
+ * name it — a `<Label for>` or a `FieldLabel` points at the `id`. Without them
30
+ * the combobox's only name was the value it showed.
31
+ */
26
32
  export interface ComboboxProps {
27
33
  options: readonly ComboboxOption[];
34
+ /** The trigger's id; a unique one is minted when left out. */
35
+ id?: string;
36
+ /** Accessible name (`aria-label`), for a combobox no `<label>` names. */
37
+ label?: Reactive<string | undefined>;
38
+ /** Id(s) of the element(s) that name it (`aria-labelledby`). */
39
+ labelledBy?: Reactive<string | undefined>;
40
+ describedBy?: Reactive<string | undefined>;
28
41
  name?: string;
29
42
  value?: Reactive<string | undefined>;
30
43
  defaultValue?: string;
@@ -19,14 +19,14 @@ import { cn } from "../lib/cn.js";
19
19
  import { ChevronsUpDownIcon } from "../lib/icons.js";
20
20
  import { uid } from "../lib/id.js";
21
21
  import { zoomInOut } from "../lib/motion.js";
22
- import { read, readOr } from "../lib/props.js";
22
+ import { accessor, read, readOr } from "../lib/props.js";
23
23
  import { controllable } from "../primitives/controllable.js";
24
24
  import { floatingSurface } from "../primitives/floatingSurface.js";
25
25
  import { focusSilently } from "../primitives/focusable.js";
26
26
  import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "./Command.js";
27
27
  import { selectTriggerClasses } from "./Select.js";
28
28
  export const Combobox = component((props) => {
29
- const triggerId = uid("combobox-trigger");
29
+ const triggerId = props.id ?? uid("combobox-trigger");
30
30
  const contentId = uid("combobox-content");
31
31
  const open = signal(false);
32
32
  const selection = controllable({
@@ -112,6 +112,9 @@ export const Combobox = component((props) => {
112
112
  type="button"
113
113
  data-slot="combobox-trigger"
114
114
  id="${triggerId}"
115
+ aria-label="${accessor(props.label, undefined)}"
116
+ aria-labelledby="${accessor(props.labelledBy, undefined)}"
117
+ aria-describedby="${accessor(props.describedBy, undefined)}"
115
118
  role="combobox"
116
119
  aria-haspopup="listbox"
117
120
  aria-expanded="${() => (open() ? "true" : "false")}"