Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions apps/registry/app/components/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { StorybookEmbed } from "@/components/storybook-embed";
import componentMetadata from "@/lib/component-metadata.json";
import {
breadcrumbLd,
jsonLdScript,
jsonLdScriptAttributes,
softwareSourceCodeLd,
} from "@/lib/jsonld";
import { generateOGMetadata, generateTwitterMetadata } from "@/lib/og";
Expand Down Expand Up @@ -172,24 +172,21 @@ export default async function ComponentPage(props: Props) {
return (
<>
<script
dangerouslySetInnerHTML={{
__html: jsonLdScript([
softwareSourceCodeLd({
description: displayDescription,
name: component.name,
title: displayTitle,
}),
breadcrumbLd([
{ name: "Home", url: SITE_URL },
{ name: "Components", url: `${SITE_URL}/components` },
{
name: displayTitle,
url: `${SITE_URL}/components/${component.name}`,
},
]),
{...jsonLdScriptAttributes([
softwareSourceCodeLd({
description: displayDescription,
name: component.name,
title: displayTitle,
}),
breadcrumbLd([
{ name: "Home", url: SITE_URL },
{ name: "Components", url: `${SITE_URL}/components` },
{
name: displayTitle,
url: `${SITE_URL}/components/${component.name}`,
},
]),
}}
type="application/ld+json"
])}
/>
<Sidebar sections={getSidebarSections(getCategoryForComponent(slug))} />
<main className="flex-1 overflow-y-auto bg-background overflow-x-hidden">
Expand Down
17 changes: 7 additions & 10 deletions apps/registry/app/docs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Breadcrumb, MDXContent, Sidebar } from "@vllnt/ui";
import type { Metadata } from "next";

import { getPageContent } from "@/lib/content";
import { breadcrumbLd, jsonLdScript } from "@/lib/jsonld";
import { breadcrumbLd, jsonLdScriptAttributes } from "@/lib/jsonld";
import { generateOGMetadata, generateTwitterMetadata } from "@/lib/og";
import { canonical } from "@/lib/seo";
import { getSidebarSections } from "@/lib/sidebar-sections";
Expand Down Expand Up @@ -36,15 +36,12 @@ export default async function DocumentationPage() {
return (
<>
<script
dangerouslySetInnerHTML={{
__html: jsonLdScript(
breadcrumbLd([
{ name: "Home", url: SITE_URL },
{ name: "Docs", url: `${SITE_URL}/docs` },
]),
),
}}
type="application/ld+json"
{...jsonLdScriptAttributes(
breadcrumbLd([
{ name: "Home", url: SITE_URL },
{ name: "Docs", url: `${SITE_URL}/docs` },
]),
)}
/>
<Sidebar sections={getSidebarSections()} />
<main className="flex-1 overflow-y-auto bg-background">
Expand Down
16 changes: 7 additions & 9 deletions apps/registry/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import type { Metadata } from "next";
import type React from "react";

import { Header } from "@/components/header";
import { jsonLdScript, organizationLd, websiteLd } from "@/lib/jsonld";
import {
jsonLdScriptAttributes,
organizationLd,
websiteLd,
} from "@/lib/jsonld";

import "./globals.css";

Expand Down Expand Up @@ -82,14 +86,8 @@ export default function RootLayout({
return (
<html lang="en" suppressHydrationWarning>
<head>
<script
dangerouslySetInnerHTML={{ __html: jsonLdScript(organizationLd()) }}
type="application/ld+json"
/>
<script
dangerouslySetInnerHTML={{ __html: jsonLdScript(websiteLd()) }}
type="application/ld+json"
/>
<script {...jsonLdScriptAttributes(organizationLd())} />
<script {...jsonLdScriptAttributes(websiteLd())} />
</head>
<body className="h-full overflow-hidden">
<ThemeProvider
Expand Down
14 changes: 10 additions & 4 deletions apps/registry/components/component-preview/component-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ type ComponentPreviewProps = {
componentName: string;
};

const DATE_PICKER_PREVIEW_DATE = new Date("2026-04-19T00:00:00.000Z");
const HORIZONTAL_SCROLL_ROW_CARDS = Array.from({ length: 6 }, (_, index) => ({
id: `featured-card-${index + 1}`,
label: `Card ${index + 1}`,
}));

// Simple text-based preview for components that need complex context
function SimplePreview({ description }: { description: string }) {
return (
Expand Down Expand Up @@ -314,7 +320,7 @@ function ComboboxPreview() {
function DatePickerPreview() {
return (
<div className="w-full max-w-sm">
<DatePicker value={new Date("2026-04-19T00:00:00.000Z")} />
<DatePicker value={DATE_PICKER_PREVIEW_DATE} />
</div>
);
}
Expand Down Expand Up @@ -1413,12 +1419,12 @@ function AlertDialogPreview() {
function HorizontalScrollRowPreview() {
return (
<HorizontalScrollRow description="Browse our picks" title="Featured">
{Array.from({ length: 6 }, (_, index) => (
{HORIZONTAL_SCROLL_ROW_CARDS.map((card) => (
<div
className="min-w-[180px] snap-start rounded-lg border bg-card p-4 text-sm"
key={index}
key={card.id}
>
Card {index + 1}
{card.label}
</div>
))}
</HorizontalScrollRow>
Expand Down
9 changes: 3 additions & 6 deletions apps/registry/components/landing/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ function Stats({
generatedAt?: string;
version: string;
}) {
const generatedDate = generatedAt?.slice(0, 10) ?? "—";

return (
<section className="border-b border-border bg-muted/30">
<div className="mx-auto grid max-w-7xl grid-cols-2 gap-6 px-4 py-12 lg:grid-cols-4 lg:px-8">
<Stat label="Components" value={String(componentCount)} />
<Stat label="Categories" value={String(categoryCount)} />
<Stat label="Library version" value={`v${version}`} />
<Stat
label="Last build"
value={
generatedAt ? new Date(generatedAt).toISOString().slice(0, 10) : "—"
}
/>
<Stat label="Last build" value={generatedDate} />
</div>
</section>
);
Expand Down
18 changes: 17 additions & 1 deletion apps/registry/lib/jsonld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ type JsonLdValue =

type JsonLdNode = { readonly [key: string]: JsonLdValue };

export type JsonLdScriptAttributes = {
readonly dangerouslySetInnerHTML: {
readonly __html: string;
};
readonly type: "application/ld+json";
};

export function organizationLd(): JsonLdNode {
return {
"@context": "https://schema.org",
Expand Down Expand Up @@ -86,5 +93,14 @@ export function breadcrumbLd(trail: ReadonlyArray<{
}

export function jsonLdScript(node: JsonLdNode | readonly JsonLdNode[]): string {
return JSON.stringify(node);
return JSON.stringify(node).replace(/</g, "\\u003c");
}

export function jsonLdScriptAttributes(
node: JsonLdNode | readonly JsonLdNode[],
): JsonLdScriptAttributes {
return {
dangerouslySetInnerHTML: { __html: jsonLdScript(node) },
type: "application/ld+json",
};
}
53 changes: 47 additions & 6 deletions apps/registry/registry/default/checklist/checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,58 @@ import { useState } from "react";
import { cn } from "@vllnt/ui";

export const CHECKLIST_PROGRESS_EVENT = "vllnt:checklist-progress-change";
export const CHECKLIST_STORAGE_VERSION = 1;

export type ChecklistItem = {
description?: string;
id: string;
label: string;
};

type ChecklistStoragePayload = {
checked: string[];
version: typeof CHECKLIST_STORAGE_VERSION;
};

function stringItemsFromUnknown(value: unknown): string[] {
return Array.isArray(value)
? value.filter((item): item is string => typeof item === "string")
: [];
}

export function parseChecklistStorageValue(saved: string): string[] {
try {
const parsed: unknown = JSON.parse(saved);

if (Array.isArray(parsed)) {
return stringItemsFromUnknown(parsed);
}

if (
typeof parsed === "object" &&
parsed !== null &&
"version" in parsed &&
"checked" in parsed &&
parsed.version === CHECKLIST_STORAGE_VERSION
) {
return stringItemsFromUnknown(parsed.checked);
}
} catch {
return [];
}

return [];
}

export function createChecklistStorageValue(ids: Iterable<string>): string {
const payload: ChecklistStoragePayload = {
checked: [...ids],
version: CHECKLIST_STORAGE_VERSION,
};

return JSON.stringify(payload);
}

type ChecklistItemRowProps = {
isChecked: boolean;
item: ChecklistItem;
Expand Down Expand Up @@ -140,11 +185,7 @@ export function Checklist({
if (typeof window !== "undefined" && persistKey) {
const saved = localStorage.getItem(`checklist:${persistKey}`);
if (saved) {
try {
return new Set(JSON.parse(saved) as string[]);
} catch {
/* skip */
}
return new Set(parseChecklistStorageValue(saved));
}
}
return new Set();
Expand All @@ -159,7 +200,7 @@ export function Checklist({
try {
localStorage.setItem(
`checklist:${persistKey}`,
JSON.stringify([...newChecked]),
createChecklistStorageValue(newChecked),
);
window.dispatchEvent(
new CustomEvent(CHECKLIST_PROGRESS_EVENT, {
Expand Down
53 changes: 47 additions & 6 deletions packages/ui/src/components/checklist/checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,58 @@ import { useState } from "react";
import { cn } from "../../lib/utils";

export const CHECKLIST_PROGRESS_EVENT = "vllnt:checklist-progress-change";
export const CHECKLIST_STORAGE_VERSION = 1;

export type ChecklistItem = {
description?: string;
id: string;
label: string;
};

type ChecklistStoragePayload = {
checked: string[];
version: typeof CHECKLIST_STORAGE_VERSION;
};

function stringItemsFromUnknown(value: unknown): string[] {
return Array.isArray(value)
? value.filter((item): item is string => typeof item === "string")
: [];
}

export function parseChecklistStorageValue(saved: string): string[] {
try {
const parsed: unknown = JSON.parse(saved);

if (Array.isArray(parsed)) {
return stringItemsFromUnknown(parsed);
}

if (
typeof parsed === "object" &&
parsed !== null &&
"version" in parsed &&
"checked" in parsed &&
parsed.version === CHECKLIST_STORAGE_VERSION
) {
return stringItemsFromUnknown(parsed.checked);
}
} catch {
return [];
}

return [];
}

export function createChecklistStorageValue(ids: Iterable<string>): string {
const payload: ChecklistStoragePayload = {
checked: [...ids],
version: CHECKLIST_STORAGE_VERSION,
};

return JSON.stringify(payload);
}

type ChecklistItemRowProps = {
isChecked: boolean;
item: ChecklistItem;
Expand Down Expand Up @@ -140,11 +185,7 @@ export function Checklist({
if (typeof window !== "undefined" && persistKey) {
const saved = localStorage.getItem(`checklist:${persistKey}`);
if (saved) {
try {
return new Set(JSON.parse(saved) as string[]);
} catch {
/* skip */
}
return new Set(parseChecklistStorageValue(saved));
}
}
return new Set();
Expand All @@ -159,7 +200,7 @@ export function Checklist({
try {
localStorage.setItem(
`checklist:${persistKey}`,
JSON.stringify([...newChecked]),
createChecklistStorageValue(newChecked),
);
window.dispatchEvent(
new CustomEvent(CHECKLIST_PROGRESS_EVENT, {
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/components/checklist/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export {
Checklist,
CHECKLIST_PROGRESS_EVENT,
CHECKLIST_STORAGE_VERSION,
type ChecklistItem,
type ChecklistProps,
createChecklistStorageValue,
parseChecklistStorageValue,
} from "./checklist";
Loading
Loading