@aphexcms/ui 0.8.5 → 0.8.7

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 ADDED
@@ -0,0 +1,51 @@
1
+ # @aphexcms/ui
2
+
3
+ The shared [shadcn-svelte](https://shadcn-svelte.com) component library behind the [AphexCMS](https://github.com/IcelandicIcecream/aphex) admin.
4
+
5
+ This exists so `cms-core` and first-party plugins render the same controls, and so a plugin author can build a settings panel that looks like the rest of the admin without copying components in. It is a peer dependency of `@aphexcms/cms-core`, not an optional add-on.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @aphexcms/ui
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Each component has its own entry point — there is no root barrel, deliberately, so importing a button doesn't pull the whole library into your chunk:
16
+
17
+ ```svelte
18
+ <script lang="ts">
19
+ import { Button } from '@aphexcms/ui/shadcn/button';
20
+ import { Input } from '@aphexcms/ui/shadcn/input';
21
+ import * as Dialog from '@aphexcms/ui/shadcn/dialog';
22
+ </script>
23
+
24
+ <Button variant="outline">Save</Button>
25
+ ```
26
+
27
+ Styling is Tailwind CSS v4 with shared CSS variables. Import them once, in your root stylesheet:
28
+
29
+ ```css
30
+ @import '@aphexcms/ui/shadcn/css';
31
+ ```
32
+
33
+ ## What's in it
34
+
35
+ Roughly thirty-five components: the shadcn-svelte set (button, input, select, dialog, dropdown-menu, popover, sidebar, tabs, tooltip, calendar, command, …) plus a few Aphex additions used by the admin — `bubble`, `marker`, `message`, `message-scroller` and `attachment`, which back the in-admin agent's chat surface.
36
+
37
+ `@aphexcms/ui/utils` exports `cn()` and the `WithElementRef` helper type that the components share.
38
+
39
+ ## Adding a component
40
+
41
+ In the Aphex monorepo:
42
+
43
+ ```bash
44
+ pnpm shadcn <component-name>
45
+ ```
46
+
47
+ That runs `shadcn-svelte add` against this package and regenerates the export map. Don't hand-edit `exports` — `scripts/generate-exports.js` owns it, and the build regenerates it.
48
+
49
+ ## License
50
+
51
+ MIT
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
3
  import type { HTMLAttributes } from 'svelte/elements';
4
- import { cn, type WithElementRef } from '../../../utils.js';
4
+ import { cn, randomId, type WithElementRef } from '../../../utils.js';
5
5
  import { useMessageScroller } from './message-scroller-context.svelte.js';
6
6
 
7
7
  type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
@@ -21,7 +21,7 @@
21
21
 
22
22
  onMount(() => {
23
23
  if (!ref) return;
24
- const id = messageId ?? crypto.randomUUID();
24
+ const id = messageId ?? randomId();
25
25
  const unregister = state.registerItem(id, ref, scrollAnchor);
26
26
  const observer = new IntersectionObserver(
27
27
  ([entry]) => state.setItemVisible(id, entry?.isIntersecting ?? false),
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,15 @@
1
1
  import { type ClassValue } from 'clsx';
2
2
  export declare function cn(...inputs: ClassValue[]): string;
3
+ /**
4
+ * A v4 UUID that also works outside a secure context.
5
+ *
6
+ * `crypto.randomUUID` is only defined on HTTPS or `localhost`, so opening the
7
+ * dev server's Network URL (`vite dev --host` prints one) from a phone or
8
+ * another machine leaves it `undefined` and every call throws. Kept here rather
9
+ * than imported from `@aphexcms/cms-core` because the dependency runs the other
10
+ * way — cms-core consumes this package.
11
+ */
12
+ export declare function randomId(): string;
3
13
  export type WithoutChild<T> = T extends {
4
14
  child?: any;
5
15
  } ? Omit<T, 'child'> : T;
package/dist/utils.js CHANGED
@@ -3,3 +3,26 @@ import { twMerge } from 'tailwind-merge';
3
3
  export function cn(...inputs) {
4
4
  return twMerge(clsx(inputs));
5
5
  }
6
+ /**
7
+ * A v4 UUID that also works outside a secure context.
8
+ *
9
+ * `crypto.randomUUID` is only defined on HTTPS or `localhost`, so opening the
10
+ * dev server's Network URL (`vite dev --host` prints one) from a phone or
11
+ * another machine leaves it `undefined` and every call throws. Kept here rather
12
+ * than imported from `@aphexcms/cms-core` because the dependency runs the other
13
+ * way — cms-core consumes this package.
14
+ */
15
+ export function randomId() {
16
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
17
+ return crypto.randomUUID();
18
+ }
19
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
20
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
21
+ const hex = Array.from(bytes, (byte, index) => {
22
+ const value = index === 6 ? (byte & 0x0f) | 0x40 : index === 8 ? (byte & 0x3f) | 0x80 : byte;
23
+ return value.toString(16).padStart(2, '0');
24
+ }).join('');
25
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
26
+ }
27
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aphexcms/ui",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Shared UI components for Aphex CMS (shadcn-svelte)",
5
5
  "license": "MIT",
6
6
  "publishConfig": {