Beautiful map components. 100% Free, Zero config, one command setup.
TypeScript
feat(site): add blocks grid view, palette actions, and docs polish
Anmol6338a0757518
diff --git a/public/r/delivery-tracker.json b/public/r/delivery-tracker.jsonindex a4ce870..c4d5f73 100644--- a/public/r/delivery-tracker.json+++ b/public/r/delivery-tracker.json@@ -30,6 +30,7 @@"iframeHeight": "720px"},"categories": [+ "logistics","tracking","delivery"],diff --git a/public/r/registry.json b/public/r/registry.jsonindex 2b0996c..94941e3 100644--- a/public/r/registry.json+++ b/public/r/registry.json@@ -229,6 +229,7 @@}],"categories": [+ "logistics","tracking","delivery"],@@ -268,6 +269,7 @@}],"categories": [+ "analytics","monitoring","status"],@@ -378,6 +380,7 @@}],"categories": [+ "location","store-locator","locator"],diff --git a/public/r/store-locator.json b/public/r/store-locator.jsonindex 4972bea..aaea5c6 100644--- a/public/r/store-locator.json+++ b/public/r/store-locator.json@@ -41,6 +41,7 @@"iframeHeight": "800px"},"categories": [+ "location","store-locator","locator"],diff --git a/public/r/uptime-monitor.json b/public/r/uptime-monitor.jsonindex 7653a5a..4bef3c9 100644--- a/public/r/uptime-monitor.json+++ b/public/r/uptime-monitor.json@@ -37,6 +37,7 @@"iframeHeight": "720px"},"categories": [+ "analytics","monitoring","status"],diff --git a/registry.json b/registry.jsonindex 2b0996c..94941e3 100644--- a/registry.json+++ b/registry.json@@ -229,6 +229,7 @@}],"categories": [+ "logistics","tracking","delivery"],@@ -268,6 +269,7 @@}],"categories": [+ "analytics","monitoring","status"],@@ -378,6 +380,7 @@}],"categories": [+ "location","store-locator","locator"],diff --git a/src/app/(main)/(home)/_components/examples-grid.tsx b/src/app/(main)/(home)/_components/examples-grid.tsxindex 16e68c1..52d1e59 100644--- a/src/app/(main)/(home)/_components/examples-grid.tsx+++ b/src/app/(main)/(home)/_components/examples-grid.tsx@@ -9,13 +9,36 @@ import {export function ExamplesGrid() {return (- <div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4">- <AnalyticsExample />- <TrailExample />- <ArcExample />- <EVChargingExample />- <FlyToExample />- <DeliveryExample />+ <div>+ <div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4">+ <AnalyticsExample />+ <TrailExample />+ <ArcExample />+ <EVChargingExample />+ <FlyToExample />+ <DeliveryExample />+ </div>++ <p className="text-muted-foreground mt-3 text-right text-xs">+ Map data ©{" "}+ <a+ href="https://www.openstreetmap.org/copyright"+ target="_blank"+ rel="noopener noreferrer"+ className="hover:text-foreground transition-colors"+ >+ OpenStreetMap+ </a>{" "}+ contributors · ©{" "}+ <a+ href="https://carto.com/attributions"+ target="_blank"+ rel="noopener noreferrer"+ className="hover:text-foreground transition-colors"+ >+ CARTO+ </a>+ </p></div>);}diff --git a/src/app/(main)/(home)/_components/examples/analytics-example.tsx b/src/app/(main)/(home)/_components/examples/analytics-example.tsxindex f1305f6..cbd2996 100644--- a/src/app/(main)/(home)/_components/examples/analytics-example.tsx+++ b/src/app/(main)/(home)/_components/examples/analytics-example.tsx@@ -35,6 +35,7 @@ export function AnalyticsExample() {</div><Map+ attributionControl={false}center={[0, 30]}scrollZoom={false}dragRotate={false}diff --git a/src/app/(main)/(home)/_components/examples/arc-example.tsx b/src/app/(main)/(home)/_components/examples/arc-example.tsxindex 6d79237..eb99081 100644--- a/src/app/(main)/(home)/_components/examples/arc-example.tsx+++ b/src/app/(main)/(home)/_components/examples/arc-example.tsx@@ -29,6 +29,7 @@ export function ArcExample() {return (<ExampleCard className="aspect-square"><Map+ attributionControl={false}center={[-0.1276, 41.5074]}zoom={1}projection={{ type: "globe" }}diff --git a/src/app/(main)/(home)/_components/examples/delivery-example.tsx b/src/app/(main)/(home)/_components/examples/delivery-example.tsxindex 59734fc..96f4e12 100644--- a/src/app/(main)/(home)/_components/examples/delivery-example.tsx+++ b/src/app/(main)/(home)/_components/examples/delivery-example.tsx@@ -88,6 +88,7 @@ export function DeliveryExample() {return (<ExampleCard className="aspect-square sm:col-span-2 sm:aspect-video lg:aspect-auto"><Map+ attributionControl={false}center={[-0.105, 51.511]}zoom={12.6}scrollZoom={false}diff --git a/src/app/(main)/(home)/_components/examples/ev-charging-example.tsx b/src/app/(main)/(home)/_components/examples/ev-charging-example.tsxindex 8179071..2b27fcc 100644--- a/src/app/(main)/(home)/_components/examples/ev-charging-example.tsx+++ b/src/app/(main)/(home)/_components/examples/ev-charging-example.tsx@@ -119,6 +119,7 @@ export function EVChargingExample() {return (<ExampleCard className="aspect-square"><Map+ attributionControl={false}center={[-122.434, 37.776]}zoom={11}scrollZoom={false}diff --git a/src/app/(main)/(home)/_components/examples/flyto-example.tsx b/src/app/(main)/(home)/_components/examples/flyto-example.tsxindex 5c45a5a..f1b5974 100644--- a/src/app/(main)/(home)/_components/examples/flyto-example.tsx+++ b/src/app/(main)/(home)/_components/examples/flyto-example.tsx@@ -32,6 +32,7 @@ export function FlyToExample() {return (<ExampleCard className="aspect-square"><Map+ attributionControl={false}ref={mapRef}center={active.center}zoom={5.5}diff --git a/src/app/(main)/(home)/_components/examples/trail-example.tsx b/src/app/(main)/(home)/_components/examples/trail-example.tsxindex 03e6469..5e8d4d4 100644--- a/src/app/(main)/(home)/_components/examples/trail-example.tsx+++ b/src/app/(main)/(home)/_components/examples/trail-example.tsx@@ -54,6 +54,7 @@ export function TrailExample() {</div><Map+ attributionControl={false}center={[-73.97, 40.782]}zoom={11.8}scrollZoom={false}diff --git a/src/app/(main)/blocks/_components/block-card.tsx b/src/app/(main)/blocks/_components/block-card.tsxnew file mode 100644index 0000000..005c164--- /dev/null+++ b/src/app/(main)/blocks/_components/block-card.tsx@@ -0,0 +1,35 @@+import type { RegistryBlockItem } from "@/lib/blocks";+import { BlockThumbnail } from "./block-thumbnail";+import { OpenBlockLink } from "./blocks-view";++interface BlockCardProps {+ block: RegistryBlockItem;+}++export function BlockCard({ block }: BlockCardProps) {+ const title = block.title ?? block.name;++ return (+ <article className="bg-muted/30 dark:hover:bg-muted/40 hover:bg-muted/80 has-[a:focus-visible]:border-ring has-[a:focus-visible]:ring-ring/50 relative rounded-xl border p-1.5 transition-[color,background-color,box-shadow] has-[a:focus-visible]:ring-[3px]">+ <div className="bg-background overflow-hidden rounded-md border">+ <BlockThumbnail src={`/view/${block.name}`} title={title} />+ </div>++ <div className="min-w-0 px-3 pt-3.5 pb-2.5">+ <h3 className="text-base font-medium tracking-tight">+ <OpenBlockLink+ name={block.name}+ className="inline-block max-w-full truncate text-left align-top outline-none after:absolute after:inset-0 after:rounded-xl after:content-['']"+ >+ {title}+ </OpenBlockLink>+ </h3>+ {block.description && (+ <p className="text-muted-foreground mt-1 truncate text-sm">+ {block.description}+ </p>+ )}+ </div>+ </article>+ );+}diff --git a/src/app/(main)/blocks/_components/block-display.tsx b/src/app/(main)/blocks/_components/block-display.tsxindex b619dfe..42dfa2d 100644--- a/src/app/(main)/blocks/_components/block-display.tsx+++ b/src/app/(main)/blocks/_components/block-display.tsx@@ -1,18 +1,18 @@-import { getAllBlocks, createFileTreeForRegistryItemFiles } from "@/lib/blocks";+import {+ createFileTreeForRegistryItemFiles,+ type RegistryBlockItem,+} from "@/lib/blocks";import { getBlockFileSource } from "@/lib/get-block-file-source";import { highlightCode } from "@/lib/highlight";import { BlockPreview } from "./block-preview";import { IframePreview } from "./iframe-preview";interface BlockDisplayProps {- name: string;+ block: RegistryBlockItem;}-export async function BlockDisplay({ name }: BlockDisplayProps) {- const blocks = getAllBlocks();- const block = blocks.find((b) => b.name === name);-- if (!block || !block.files?.length) {+export async function BlockDisplay({ block }: BlockDisplayProps) {+ if (!block.files?.length) {return null;}@@ -29,12 +29,15 @@ export async function BlockDisplay({ name }: BlockDisplayProps) {content,highlightedContent,};- })+ }),);return (<BlockPreview block={block} tree={tree} highlightedFiles={highlightedFiles}>- <IframePreview src={`/view/${block.name}`} title={block.title ?? block.name} />+ <IframePreview+ src={`/view/${block.name}`}+ title={block.title ?? block.name}+ /></BlockPreview>);}diff --git a/src/app/(main)/blocks/_components/block-preview.tsx b/src/app/(main)/blocks/_components/block-preview.tsxindex 4d3bc73..b8f34da 100644--- a/src/app/(main)/blocks/_components/block-preview.tsx+++ b/src/app/(main)/blocks/_components/block-preview.tsx@@ -4,7 +4,7 @@ import { useState } from "react";import { Check, Maximize, Terminal } from "lucide-react";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";import { Button } from "@/components/ui/button";-import { RegistryBlockItem, type FileTree } from "@/lib/blocks";+import { type FileTree, type RegistryBlockItem } from "@/lib/blocks";import { trackEvent } from "@/lib/events";import { BlockViewerCode, type HighlightedFile } from "./block-viewer-code";import { Separator } from "@/components/ui/separator";@@ -35,64 +35,76 @@ export function BlockPreview({return (<div- className="space-y-4"+ id={name}+ className="scroll-mt-24"style={{"--block-preview-height": meta?.iframeHeight ?? "930px",} as React.CSSProperties}>- <div>- <h2 className="text-lg font-semibold tracking-tight">{title}</h2>- {description && (- <p className="text-muted-foreground mt-0.5 text-sm">{description}</p>- )}- </div>+ <Tabs defaultValue="preview" className="w-full gap-4">+ <div className="flex flex-col gap-4 xl:flex-row xl:items-end xl:justify-between xl:gap-6">+ <div className="min-w-0">+ <h3 className="text-lg font-semibold tracking-tight">{title}</h3>+ {description && (+ <p className="text-muted-foreground mt-0.5 text-sm">+ {description}+ </p>+ )}+ </div>- <Tabs defaultValue="preview" className="w-full">- <div className="flex items-center justify-between">- <TabsList className="h-8!">- <TabsTrigger value="preview" className="text-xs">- Preview- </TabsTrigger>- <TabsTrigger value="code" className="text-xs">- Code- </TabsTrigger>- </TabsList>+ <div className="flex shrink-0 items-center gap-3">+ <TabsList className="h-8! gap-0.5 border bg-transparent p-0.5">+ <TabsTrigger value="preview" className={tabTriggerClassName}>+ Preview+ </TabsTrigger>+ <TabsTrigger value="code" className={tabTriggerClassName}>+ Code+ </TabsTrigger>+ </TabsList>- <div className="hidden items-center gap-2.5 md:flex">- <Button- onClick={copyCli}- variant="outline"- aria-label="Copy CLI command"- size="sm"- className="font-mono text-xs"- >- {copiedType === "cli" ? <Check /> : <Terminal />}- npx shadcn add @mapcn/{name}- </Button>- <Separator orientation="vertical" className="h-4!" />- <Button- variant="outline"- size="icon-sm"- asChild- aria-label="Open in new tab"- >- <Link href={`/view/${name}`} target="_blank">- <Maximize />- </Link>- </Button>+ <div className="hidden items-center gap-2 md:flex">+ <Separator orientation="vertical" className="mr-1 h-5!" />+ <Button+ onClick={copyCli}+ variant="outline"+ aria-label="Copy CLI command"+ size="sm"+ className="font-mono text-xs"+ >+ {copiedType === "cli" ? <Check /> : <Terminal />}+ npx shadcn add @mapcn/{name}+ </Button>+ <Button+ variant="outline"+ size="icon-sm"+ asChild+ aria-label="Open in new tab"+ >+ <Link href={`/view/${name}`} target="_blank">+ <Maximize />+ </Link>+ </Button>+ </div></div></div>- <TabsContent value="preview" className="mt-3">+ <TabsContent+ value="preview"+ forceMount+ className="data-[state=inactive]:hidden"+ >{children}</TabsContent>- <TabsContent value="code" className="mt-3">+ <TabsContent value="code"><BlockViewerCode tree={tree} highlightedFiles={highlightedFiles} /></TabsContent></Tabs></div>);}++const tabTriggerClassName =+ "text-muted-foreground hover:text-foreground data-[state=active]:bg-accent data-[state=active]:text-foreground dark:data-[state=active]:bg-accent px-3 text-xs data-[state=active]:shadow-none! dark:data-[state=active]:border-transparent";diff --git a/src/app/(main)/blocks/_components/block-thumbnail.tsx b/src/app/(main)/blocks/_components/block-thumbnail.tsxnew file mode 100644index 0000000..9b3f1df--- /dev/null+++ b/src/app/(main)/blocks/_components/block-thumbnail.tsx@@ -0,0 +1,76 @@+"use client";++import { useEffect, useRef, useState } from "react";+import { cn } from "@/lib/utils";+import { useInView } from "./use-in-view";++// Blocks are designed as full pages, so the thumbnail renders them at a+// desktop width and scales the whole frame down to fit the card.+const FRAME_WIDTH = 1280;+const FRAME_HEIGHT = 800;++interface BlockThumbnailProps {+ src: string;+ title: string;+}++export function BlockThumbnail({ src, title }: BlockThumbnailProps) {+ const ref = useRef<HTMLDivElement>(null);+ // Frames stay mounted once loaded so scrolling back never reloads them. Each+ // one holds a WebGL context and Chrome caps those at about 16, so past ~14+ // blocks switch to `{ once: false }` or static screenshots.+ const inView = useInView(ref);+ const [scale, setScale] = useState(0);++ useEffect(() => {+ const element = ref.current;+ if (!element) return;++ const observer = new ResizeObserver(([entry]) => {+ setScale(entry.contentRect.width / FRAME_WIDTH);+ });++ observer.observe(element);+ return () => observer.disconnect();+ }, []);++ return (+ <div+ ref={ref}+ className="bg-muted/40 relative aspect-[16/10] w-full overflow-hidden"+ >+ {inView && scale > 0 && (+ <ThumbnailFrame src={src} title={title} scale={scale} />+ )}+ </div>+ );+}++// Owns the load state so a frame that remounts fades in again.+function ThumbnailFrame({+ src,+ title,+ scale,+}: BlockThumbnailProps & { scale: number }) {+ const [loaded, setLoaded] = useState(false);++ return (+ <iframe+ src={src}+ title={`${title} preview`}+ // inert keeps the map's controls out of the tab order and away from+ // assistive tech; the card's own button is the only target.+ inert+ onLoad={() => setLoaded(true)}+ className={cn(+ "pointer-events-none absolute top-0 left-0 origin-top-left border-0 transition-opacity duration-500",+ loaded ? "opacity-100" : "opacity-0",+ )}+ style={{+ width: FRAME_WIDTH,+ height: FRAME_HEIGHT,+ transform: `scale(${scale})`,+ }}+ />+ );+}diff --git a/src/app/(main)/blocks/_components/block-viewer-code.tsx b/src/app/(main)/blocks/_components/block-viewer-code.tsxindex 308c435..4d31bb9 100644--- a/src/app/(main)/blocks/_components/block-viewer-code.tsx+++ b/src/app/(main)/blocks/_components/block-viewer-code.tsx@@ -73,7 +73,7 @@ export function BlockViewerCode({<BlockViewerCodeCtx.Providervalue={{ activeFile, setActiveFile, highlightedFiles, tree }}>- <div className="flex h-(--block-preview-height) overflow-hidden rounded-xl border">+ <div className="bg-background flex h-(--block-preview-height) overflow-hidden rounded-xl border"><div className="w-64 shrink-0"><FileTreeSidebar /></div>diff --git a/src/app/(main)/blocks/_components/blocks-view.tsx b/src/app/(main)/blocks/_components/blocks-view.tsxnew file mode 100644index 0000000..fc12f9d--- /dev/null+++ b/src/app/(main)/blocks/_components/blocks-view.tsx@@ -0,0 +1,154 @@+"use client";++import {+ createContext,+ useCallback,+ useContext,+ useEffect,+ useRef,+ useState,+} from "react";+import { LayoutGrid, Rows2 } from "lucide-react";+import { cn } from "@/lib/utils";++type BlocksViewMode = "grid" | "single";++const BlocksViewContext = createContext<{+ view: BlocksViewMode;+ setView: (view: BlocksViewMode) => void;+ openBlock: (name: string) => void;+} | null>(null);++function useBlocksView() {+ const context = useContext(BlocksViewContext);+ if (!context) {+ throw new Error("useBlocksView must be used within BlocksViewProvider");+ }+ return context;+}++export function BlocksViewProvider({+ blockNames,+ children,+}: {+ blockNames: string[];+ children: React.ReactNode;+}) {+ const [view, setView] = useState<BlocksViewMode>("grid");+ // Bumped on every open so the scroll runs even when the view is unchanged.+ const [openRequest, setOpenRequest] = useState(0);+ const targetRef = useRef<string | null>(null);++ const openBlock = useCallback((name: string) => {+ targetRef.current = name;+ setView("single");+ setOpenRequest((request) => request + 1);+ if (window.location.hash !== `#${name}`) {+ window.history.replaceState(null, "", `#${name}`);+ }+ }, []);++ // A shared link like /blocks#store-locator opens that block directly.+ useEffect(() => {+ function openFromHash() {+ const name = window.location.hash.slice(1);+ if (blockNames.includes(name)) openBlock(name);+ }++ openFromHash();+ window.addEventListener("hashchange", openFromHash);+ return () => window.removeEventListener("hashchange", openFromHash);+ }, [blockNames, openBlock]);++ useEffect(() => {+ const target = targetRef.current;+ if (view !== "single" || !target) return;+ document.getElementById(target)?.scrollIntoView({ block: "start" });+ targetRef.current = null;+ }, [view, openRequest]);++ return (+ <BlocksViewContext.Provider value={{ view, setView, openBlock }}>+ {children}+ </BlocksViewContext.Provider>+ );+}++export function BlocksView({+ mode,+ children,+}: {+ mode: BlocksViewMode;+ children: React.ReactNode;+}) {+ const { view } = useBlocksView();+ return view === mode ? children : null;+}++export function BlocksViewSwitch() {+ const { view, setView } = useBlocksView();++ const options = [+ { mode: "grid", label: "Grid view", icon: LayoutGrid },+ { mode: "single", label: "List view", icon: Rows2 },+ ] as const;++ return (+ <div+ role="group"+ aria-label="Blocks layout"+ className="flex items-center gap-0.5 rounded-lg border p-0.5"+ >+ {options.map(({ mode, label, icon: Icon }) => (+ <button+ key={mode}+ type="button"+ aria-label={label}+ aria-pressed={view === mode}+ onClick={() => {+ setView(mode);+ window.history.replaceState(null, "", window.location.pathname);+ }}+ className={cn(+ "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex size-8 items-center justify-center rounded-md transition-colors outline-none focus-visible:ring-[3px]",+ view === mode && "bg-accent text-foreground",+ )}+ >+ <Icon className="size-4" />+ </button>+ ))}+ </div>+ );+}++// A real link to /blocks#name, so the card can be opened in a new tab or have+// its link copied. Plain clicks switch to list view in place instead.+export function OpenBlockLink({+ name,+ children,+ ...props+}: Omit<React.ComponentProps<"a">, "href" | "onClick"> & { name: string }) {+ const { openBlock } = useBlocksView();++ return (+ <a+ href={`#${name}`}+ onClick={(event) => {+ if (+ event.button !== 0 ||+ event.metaKey ||+ event.ctrlKey ||+ event.shiftKey ||+ event.altKey+ ) {+ return;+ }+ event.preventDefault();+ openBlock(name);+ }}+ {...props}+ >+ {children}+ </a>+ );+}diff --git a/src/app/(main)/blocks/_components/iframe-preview.tsx b/src/app/(main)/blocks/_components/iframe-preview.tsxindex e0c9d4d..922de2a 100644--- a/src/app/(main)/blocks/_components/iframe-preview.tsx+++ b/src/app/(main)/blocks/_components/iframe-preview.tsx@@ -1,14 +1,35 @@"use client";+import { useRef, useState } from "react";+import { cn } from "@/lib/utils";+import { useInView } from "./use-in-view";+interface IframePreviewProps {src: string;title: string;}export function IframePreview({ src, title }: IframePreviewProps) {+ const ref = useRef<HTMLDivElement>(null);+ const inView = useInView(ref);+ const [loaded, setLoaded] = useState(false);+return (- <div className="relative h-(--block-preview-height) w-full overflow-hidden rounded-xl border">- <iframe src={src} title={title} className="size-full border-0" />+ <div+ ref={ref}+ className="bg-background relative h-(--block-preview-height) w-full overflow-hidden rounded-xl border"+ >+ {inView && (+ <iframe+ src={src}+ title={title}+ onLoad={() => setLoaded(true)}+ className={cn(+ "size-full border-0 transition-opacity duration-500",+ loaded ? "opacity-100" : "opacity-0",+ )}+ />+ )}</div>);}diff --git a/src/app/(main)/blocks/_components/use-in-view.ts b/src/app/(main)/blocks/_components/use-in-view.tsnew file mode 100644index 0000000..5f8d37e--- /dev/null+++ b/src/app/(main)/blocks/_components/use-in-view.ts@@ -0,0 +1,42 @@+"use client";++import { useEffect, useState, type RefObject } from "react";++interface UseInViewOptions {+ rootMargin?: string;+ /**+ * Stay true after the first time the element comes near the viewport, so a+ * map preview mounts once and keeps its state while scrolling. Turn off to+ * follow visibility both ways and release offscreen previews.+ */+ once?: boolean;+}++export function useInView(+ ref: RefObject<Element | null>,+ { rootMargin = "200px", once = true }: UseInViewOptions = {},+) {+ const [inView, setInView] = useState(false);++ useEffect(() => {+ const element = ref.current;+ if (!element) return;++ const observer = new IntersectionObserver(+ ([entry]) => {+ if (!once) {+ setInView(entry.isIntersecting);+ } else if (entry.isIntersecting) {+ setInView(true);+ observer.disconnect();+ }+ },+ { rootMargin },+ );++ observer.observe(element);+ return () => observer.disconnect();+ }, [ref, rootMargin, once]);++ return inView;+}diff --git a/src/app/(main)/blocks/page.tsx b/src/app/(main)/blocks/page.tsxindex 2d2aa5d..5deff38 100644--- a/src/app/(main)/blocks/page.tsx+++ b/src/app/(main)/blocks/page.tsx@@ -1,12 +1,23 @@import {+ PageActions,PageHeader,PageHeaderDescription,PageHeaderHeading,} from "@/components/page-header";import { Footer } from "@/components/footer";import { Metadata } from "next";-import { getAllBlocks } from "@/lib/blocks";+import {+ getAllBlocks,+ getBlockCategories,+ type BlockCategory,+} from "@/lib/blocks";+import { BlockCard } from "./_components/block-card";import { BlockDisplay } from "./_components/block-display";+import {+ BlocksView,+ BlocksViewProvider,+ BlocksViewSwitch,+} from "./_components/blocks-view";import { type CSSProperties } from "react";export const metadata: Metadata = {@@ -17,32 +28,85 @@ export const metadata: Metadata = {export default async function Page() {const blocks = getAllBlocks();+ const categories = getBlockCategories();return (- <>- <PageHeader align="left" size="sm">- <PageHeaderHeading>Blocks</PageHeaderHeading>- <PageHeaderDescription>- Pre-built, ready-to-use map blocks. Browse, preview, and copy them- into your app with one command.- </PageHeaderDescription>+ <BlocksViewProvider blockNames={blocks.map((block) => block.name)}>+ <PageHeader+ align="left"+ size="sm"+ className="md:flex-row md:items-end md:justify-between"+ >+ <div className="flex flex-col gap-3">+ <PageHeaderHeading>Blocks</PageHeaderHeading>+ <PageHeaderDescription className="max-w-4xl">+ Ready-to-use map blocks. Browse, preview, and copy them into your+ app with one command.+ </PageHeaderDescription>+ </div>+ <PageActions className="mt-0">+ <BlocksViewSwitch />+ </PageActions></PageHeader><section- className="animate-fade-up animate-stagger container scroll-mt-20 space-y-20"+ className="animate-fade-up animate-stagger container scroll-mt-20 space-y-20 pb-24"id="blocks"style={{- "--stagger": 3.5,+ "--stagger": 4,} as CSSProperties}>- {blocks.map((block) => (- <BlockDisplay key={block.name} name={block.name} />- ))}+ <BlocksView mode="grid">+ <div className="space-y-16">+ {categories.map((category) => (+ <CategorySection key={category.slug} category={category}>+ <div className="grid grid-cols-1 gap-6 md:grid-cols-2">+ {category.blocks.map((block) => (+ <BlockCard key={block.name} block={block} />+ ))}+ </div>+ </CategorySection>+ ))}+ </div>+ </BlocksView>++ <BlocksView mode="single">+ <div className="space-y-20">+ {categories+ .flatMap((category) => category.blocks)+ .map((block) => (+ <BlockDisplay key={block.name} block={block} />+ ))}+ </div>+ </BlocksView></section><Footer />- </>+ </BlocksViewProvider>+ );+}++function CategorySection({+ category: { slug, title, blocks },+ children,+}: {+ category: BlockCategory;+ children: React.ReactNode;+}) {+ return (+ <section aria-labelledby={`category-${slug}`} className="space-y-6">+ <h2+ id={`category-${slug}`}+ className="text-foreground flex items-baseline gap-2 text-lg font-medium tracking-tight"+ >+ {title}+ <span className="text-muted-foreground font-mono text-sm font-normal">+ {blocks.length}+ </span>+ </h2>+ {children}+ </section>);}diff --git a/src/app/(main)/docs/_components/component-preview-client.tsx b/src/app/(main)/docs/_components/component-preview-client.tsxindex b13126f..8fa4309 100644--- a/src/app/(main)/docs/_components/component-preview-client.tsx+++ b/src/app/(main)/docs/_components/component-preview-client.tsx@@ -43,19 +43,19 @@ export function ComponentPreviewClient({className={cn(expanded? "max-h-[420px] overflow-auto"- : "max-h-32 overflow-hidden",+ : "max-h-26 overflow-hidden",)}html={highlightedCode}/>{!expanded && (- <div className="from-surface to-surface/0 pointer-events-none absolute inset-x-0 bottom-0 flex w-full items-center justify-center bg-linear-to-t pt-20 pb-4">+ <div className="from-surface to-surface/0 pointer-events-none absolute inset-x-0 bottom-0 flex w-full items-center justify-center bg-linear-to-t pt-12 pb-3"><Buttonvariant="outline"size="sm"onClick={() => setExpanded(true)}aria-expanded={expanded}aria-controls={codeId}- className="bg-background hover:bg-muted dark:bg-background dark:hover:bg-muted pointer-events-auto"+ className="dark:bg-background dark:hover:bg-muted pointer-events-auto">View Code</Button>diff --git a/src/app/(main)/docs/_components/docs-sidebar.tsx b/src/app/(main)/docs/_components/docs-sidebar.tsxindex 7bfaecc..8f6c1c9 100644--- a/src/app/(main)/docs/_components/docs-sidebar.tsx+++ b/src/app/(main)/docs/_components/docs-sidebar.tsx@@ -22,7 +22,7 @@ export function DocsSidebar() {return (<Sidebar- className="sticky top-14 z-30 hidden h-[calc(100svh-3.5rem)] w-55 shrink-0 overscroll-none bg-transparent lg:flex"+ className="sticky top-14 z-30 hidden h-[calc(100svh-3.5rem)] w-44 shrink-0 overscroll-none bg-transparent lg:flex"collapsible="none"><SidebarContent className="pt-10">@@ -36,7 +36,7 @@ export function DocsSidebar() {<SidebarMenuButtonasChildisActive={pathname === item.href}- className="font-medium"+ className="text-foreground hover:bg-sidebar-accent/50 data-[active=true]:font-medium"><Linkhref={item.href}diff --git a/src/app/(main)/docs/_components/docs-toc.tsx b/src/app/(main)/docs/_components/docs-toc.tsxindex 3b2f322..a22b70d 100644--- a/src/app/(main)/docs/_components/docs-toc.tsx+++ b/src/app/(main)/docs/_components/docs-toc.tsx@@ -60,7 +60,7 @@ export function DocsToc({ items, className }: DocsTocProps) {return (<nav aria-label="On this page" className={cn("flex flex-col", className)}>- <p className="text-muted-foreground/70 mb-3 text-[11px] font-semibold tracking-wide uppercase">+ <p className="text-muted-foreground mb-4 text-xs font-medium">On This Page</p>@@ -72,7 +72,7 @@ export function DocsToc({ items, className }: DocsTocProps) {key={item.slug}href={`#${item.slug}`}className={cn(- "py-0.5 text-sm no-underline transition-colors",+ "py-0.5 text-[0.8rem] no-underline transition-colors",isActive? "text-foreground font-medium": "text-muted-foreground hover:text-foreground",diff --git a/src/app/(main)/docs/_components/docs.tsx b/src/app/(main)/docs/_components/docs.tsxindex 15583cb..5416047 100644--- a/src/app/(main)/docs/_components/docs.tsx+++ b/src/app/(main)/docs/_components/docs.tsx@@ -89,9 +89,11 @@ export function DocsLayout({return (<div className="flex min-w-0 flex-1">- <div className="mx-auto flex max-w-[50rem] min-w-0 flex-1 flex-col pt-10 pb-20 lg:px-4">+ <div className="mx-auto flex max-w-[52rem] min-w-0 flex-1 flex-col pt-10 pb-20 lg:px-12 lg:pt-12"><DocsTitle title={title} description={description} />- <div className="mt-12 mb-12 space-y-12">{children}</div>+ <div className="mt-12 mb-12 space-y-14 [&>*:has(+[data-slot=docs-note])]:mb-6">+ {children}+ </div>{(prev || next) && (<div className="mt-auto flex items-center justify-between gap-4">{prev ? (@@ -124,8 +126,8 @@ export function DocsLayout({)}</div>- <aside className="hidden w-48 shrink-0 xl:block">- <nav className="sticky top-14 max-h-[calc(100svh-3.5rem)] overflow-y-auto pt-10 pb-10 [scrollbar-gutter:stable]">+ <aside className="hidden w-42 shrink-0 xl:block">+ <nav className="sticky top-14 max-h-[calc(100svh-3.5rem)] overflow-y-auto pt-12 pb-10 [scrollbar-gutter:stable]">{tocItems.length > 0 && <DocsToc items={tocItems} />}</nav></aside>@@ -142,7 +144,7 @@ interface DocsSectionProps {export function DocsSection({ title, children }: DocsSectionProps) {const id = title ? slugify(title) : undefined;return (- <section className="scroll-m-24 space-y-5" id={id}>+ <section className="scroll-m-24 space-y-4" id={id}>{title && (<div className="group flex w-fit items-baseline gap-2"><h2 className="text-foreground text-xl font-semibold tracking-tight">@@ -157,7 +159,7 @@ export function DocsSection({ title, children }: DocsSectionProps) {</a></div>)}- <div className="[&_em]:text-muted-foreground space-y-4 text-base leading-7 [&_strong]:font-medium [&>ol]:list-decimal [&>ol]:space-y-2 [&>ol]:pl-5 [&>ol>li]:leading-7 [&>p]:leading-7 [&>ul]:list-disc [&>ul]:space-y-2 [&>ul]:pl-5 [&>ul>li]:leading-7">+ <div className="[&_em]:text-muted-foreground space-y-4 text-[15px] leading-[1.75] [&_strong]:font-medium [&>ol]:list-decimal [&>ol]:space-y-2 [&>ol]:pl-5 [&>ol>li]:leading-[1.75] [&>p]:leading-[1.75] [&>ul]:list-disc [&>ul]:space-y-2 [&>ul]:pl-5 [&>ul>li]:leading-[1.75]">{children}</div></section>@@ -171,7 +173,10 @@ interface DocsNoteProps {export function DocsNote({ children }: DocsNoteProps) {return (- <div className="bg-surface text-foreground/80 [&_strong]:text-foreground rounded-lg px-5 py-4 text-[15px] leading-relaxed [&_strong]:font-medium">+ <div+ data-slot="docs-note"+ className="bg-surface text-foreground/80 [&_strong]:text-foreground rounded-lg px-5 py-4 text-[15px] leading-[1.75] [&_strong]:font-medium"+ >{children}</div>);@@ -190,7 +195,7 @@ export function DocsLink({ href, children, external }: DocsLinkProps) {href={href}target={external ? "_blank" : undefined}rel={external ? "noopener noreferrer" : undefined}- className="text-foreground font-medium underline underline-offset-4"+ className="decoration-foreground/25 hover:text-foreground hover:decoration-foreground/60 underline decoration-1 underline-offset-[5px] transition-colors">{children}</Link>diff --git a/src/app/(main)/docs/page.tsx b/src/app/(main)/docs/page.tsxindex 63347ae..ebd9f86 100644--- a/src/app/(main)/docs/page.tsx+++ b/src/app/(main)/docs/page.tsx@@ -155,19 +155,17 @@ export default function IntroductionPage() {</DocsSection><DocsSection title="Features">- <div className="not-prose mt-4 grid gap-4 sm:grid-cols-2">+ <div className="grid gap-4 sm:grid-cols-2">{features.map((feature) => (<divkey={feature.title}- className="bg-surface space-y-3 rounded-lg p-4"+ className="bg-surface space-y-1.5 rounded-lg p-4"><div className="flex items-center gap-2.5"><feature.icon className="text-muted-foreground size-4" />- <h3 className="text-foreground text-base font-medium">- {feature.title}- </h3>+ <h3 className="text-foreground font-medium">{feature.title}</h3></div>- <p className="text-muted-foreground text-sm">+ <p className="text-muted-foreground text-sm leading-relaxed">{feature.description}</p></div>diff --git a/src/app/layout.tsx b/src/app/layout.tsxindex 039477e..4deb734 100644--- a/src/app/layout.tsx+++ b/src/app/layout.tsx@@ -1,6 +1,6 @@import type { Metadata } from "next";import { Geist, Geist_Mono } from "next/font/google";-import { Analytics } from "@vercel/analytics/next";+import { SiteAnalytics } from "@/components/site-analytics";import "@/styles/globals.css";@@ -105,7 +105,7 @@ export default function RootLayout({<body className="font-sans antialiased"><ThemeProvider><TooltipProvider>{children}</TooltipProvider>- <Analytics />+ <SiteAnalytics /></ThemeProvider></body></html>diff --git a/src/components/command-search.tsx b/src/components/command-search.tsxindex 8dbbcfb..a75dec3 100644--- a/src/components/command-search.tsx+++ b/src/components/command-search.tsx@@ -5,9 +5,14 @@ import { useRouter } from "next/navigation";import {ArrowDown,ArrowUp,+ Bot,+ Check,CornerDownLeft,FileText,+ Moon,SearchIcon,+ Sun,+ Terminal,} from "lucide-react";import {@@ -19,37 +24,86 @@ import {CommandList,} from "@/components/ui/command";import { Kbd } from "@/components/ui/kbd";-import { siteNavigation } from "@/lib/site-navigation";+import { GitHubIcon } from "@/components/github-icon";+import { THEME_HOTKEY } from "@/components/theme-provider";+import { useThemeToggle } from "@/components/theme-toggle";+import { githubRepoUrl, siteNavigation } from "@/lib/site-navigation";+import { mapInstallAgentPrompt, mapInstallCommand } from "@/lib/llm-prompts";+import { trackEvent, type Event } from "@/lib/events";import { Button } from "./ui/button";import { cn } from "@/lib/utils";export function CommandSearch({ className }: { className?: string }) {const [open, setOpen] = React.useState(false);+ const [copyStatus, setCopyStatus] = React.useState<CopyStatus | null>(null);+ const closeTimer = React.useRef<number | undefined>(undefined);const router = useRouter();+ const { resolvedTheme, toggleTheme } = useThemeToggle();React.useEffect(() => {function handleKeyDown(e: KeyboardEvent) {if ((e.metaKey || e.ctrlKey) && e.key === "k") {e.preventDefault();+ window.clearTimeout(closeTimer.current);+ setCopyStatus(null);setOpen((open) => !open);}}document.addEventListener("keydown", handleKeyDown);- return () => document.removeEventListener("keydown", handleKeyDown);+ return () => {+ document.removeEventListener("keydown", handleKeyDown);+ window.clearTimeout(closeTimer.current);+ };}, []);+ // Every open and close goes through here, so a pending auto-close from a+ // copy can never shut a palette that was reopened in the meantime.+ function handleOpenChange(open: boolean) {+ window.clearTimeout(closeTimer.current);+ setCopyStatus(null);+ setOpen(open);+ }+function handleSelect(href: string) {- setOpen(false);+ handleOpenChange(false);router.push(href);}+ function runAction(action: () => void) {+ handleOpenChange(false);+ action();+ }++ // Shows the result on the item; closes the palette only after a success.+ async function copy(id: CopyId, text: string, event: Event["name"]) {+ window.clearTimeout(closeTimer.current);+ try {+ await navigator.clipboard.writeText(text);+ } catch {+ setCopyStatus({ id, ok: false });+ return;+ }+ trackEvent({ name: event, properties: { source: "command-palette" } });+ setCopyStatus({ id, ok: true });+ closeTimer.current = window.setTimeout(() => handleOpenChange(false), 600);+ }++ function isCopied(id: CopyId) {+ return copyStatus?.id === id && copyStatus.ok;+ }++ function copyLabel(id: CopyId, label: string) {+ if (copyStatus?.id !== id) return label;+ return copyStatus.ok ? "Copied" : "Couldn't copy, try again";+ }+return (<><Buttonvariant="outline"size="sm"- onClick={() => setOpen(true)}+ onClick={() => handleOpenChange(true)}aria-label="Jump to pages, components, and docs"className={cn("text-muted-foreground hover:text-foreground mr-2.5 hidden w-48 justify-start bg-transparent font-normal md:flex dark:bg-transparent",@@ -64,16 +118,17 @@ export function CommandSearch({ className }: { className?: string }) {</Button><CommandDialogopen={open}- onOpenChange={setOpen}+ onOpenChange={handleOpenChange}title="Search..."description="Jump to pages, components, and docs"showCloseButton={false}+ className="shadow-2xl"><CommandInputplaceholder="Search..."- className="h-10 border-none text-sm"+ className="h-full border-none text-sm"/>- <CommandList>+ <CommandList className="max-h-[296px]"><CommandEmpty className="text-muted-foreground py-8 text-sm"><div className="flex flex-col items-center gap-1.5"><FileText className="size-5 opacity-40" />@@ -94,8 +149,53 @@ export function CommandSearch({ className }: { className?: string }) {))}</CommandGroup>))}+ <CommandGroup heading="Actions">+ <CommandItem+ value="Toggle theme"+ keywords={["switch", "dark", "light", "mode", "appearance"]}+ onSelect={() => runAction(toggleTheme)}+ >+ {resolvedTheme === "dark" ? <Sun /> : <Moon />}+ <span>+ Switch to {resolvedTheme === "dark" ? "light" : "dark"} theme+ </span>+ <Kbd className="ml-auto">{THEME_HOTKEY.toUpperCase()}</Kbd>+ </CommandItem>+ <CommandItem+ value="Open GitHub repository"+ keywords={["source", "star", "repo", "code"]}+ onSelect={() =>+ runAction(() =>+ window.open(githubRepoUrl, "_blank", "noopener,noreferrer"),+ )+ }+ >+ <GitHubIcon />+ <span>Open GitHub repository</span>+ </CommandItem>+ <CommandItem+ value="Copy install command"+ keywords={["npx", "shadcn", "cli", "add"]}+ onSelect={() =>+ copy("install", mapInstallCommand, "copy_install_command")+ }+ >+ {isCopied("install") ? <Check /> : <Terminal />}+ <span>{copyLabel("install", "Copy install command")}</span>+ </CommandItem>+ <CommandItem+ value="Copy prompt for your agent"+ keywords={["ai", "llm", "claude", "cursor"]}+ onSelect={() =>+ copy("prompt", mapInstallAgentPrompt, "copy_agent_prompt")+ }+ >+ {isCopied("prompt") ? <Check /> : <Bot />}+ <span>{copyLabel("prompt", "Copy prompt for your agent")}</span>+ </CommandItem>+ </CommandGroup></CommandList>- <div className="text-muted-foreground/80 flex items-center justify-between border-t p-3 text-xs">+ <div className="text-muted-foreground bg-muted/30 mt-1 flex items-center justify-between border-t px-5 py-2.5 text-xs"><div className="flex items-center gap-2.5"><span className="flex items-center gap-1.5"><Kbd>@@ -122,3 +222,10 @@ export function CommandSearch({ className }: { className?: string }) {</>);}++type CopyId = "install" | "prompt";++interface CopyStatus {+ id: CopyId;+ ok: boolean;+}diff --git a/src/components/github-button.tsx b/src/components/github-button.tsxindex f512446..53b9757 100644--- a/src/components/github-button.tsx+++ b/src/components/github-button.tsx@@ -1,4 +1,6 @@import Link from "next/link";+import { GitHubIcon } from "@/components/github-icon";+import { githubRepoUrl } from "@/lib/site-navigation";import { Button } from "@/components/ui/button";import { Suspense } from "react";import { Skeleton } from "@/components/ui/skeleton";@@ -7,19 +9,12 @@ export function GitHubButton({ withCount = true }: { withCount?: boolean }) {return (<Button variant="ghost" size="sm" asChild><Link- href="https://github.com/AnmolSaini16/mapcn"+ href={githubRepoUrl}target="_blank"rel="noopener noreferrer"+ aria-label="mapcn on GitHub">- <svg viewBox="0 0 1024 1024" fill="currentColor" className="size-4">- <path- fillRule="evenodd"- clipRule="evenodd"- d="M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z"- transform="scale(64)"- fill="currentColor"- />- </svg>+ <GitHubIcon />{withCount && (<Suspense fallback={<Skeleton className="h-4 w-6 rounded" />}><StarCount />diff --git a/src/components/github-icon.tsx b/src/components/github-icon.tsxnew file mode 100644index 0000000..fe45691--- /dev/null+++ b/src/components/github-icon.tsx@@ -0,0 +1,19 @@+import { cn } from "@/lib/utils";++export function GitHubIcon({ className }: { className?: string }) {+ return (+ <svg+ viewBox="0 0 1024 1024"+ fill="currentColor"+ aria-hidden+ className={cn("size-4", className)}+ >+ <path+ fillRule="evenodd"+ clipRule="evenodd"+ d="M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z"+ transform="scale(64)"+ />+ </svg>+ );+}diff --git a/src/components/header.tsx b/src/components/header.tsxindex 8e6f98f..60da865 100644--- a/src/components/header.tsx+++ b/src/components/header.tsx@@ -19,7 +19,7 @@ export function Header({ className }: { className?: string }) {<MobileNav /><Logo className="hidden shrink-0 lg:flex" /><Separator- className="bg-primary/15 ml-2.5 hidden h-4! lg:block"+ className="bg-primary/15 mr-1 ml-4 hidden h-4! lg:block"orientation="vertical"/><MainNav className="hidden lg:flex" />diff --git a/src/components/main-nav.tsx b/src/components/main-nav.tsxindex 5272d34..929b993 100644--- a/src/components/main-nav.tsx+++ b/src/components/main-nav.tsx@@ -1,10 +1,20 @@+"use client";+import Link from "next/link";+import { usePathname } from "next/navigation";-import { siteNavigation } from "@/lib/site-navigation";+import { docsNavigation, siteNavigation } from "@/lib/site-navigation";import { Button } from "@/components/ui/button";import { cn } from "@/lib/utils";+const componentHrefs = new Set(+ docsNavigation+ .find((group) => group.title === "Components")+ ?.items.map((item) => item.href),+);+export function MainNav({ className, ...props }: React.ComponentProps<"nav">) {+ const pathname = usePathname();const navItems = siteNavigation.find((group) => group.title === "Pages")?.items.filter((item) => item.title !== "Home");@@ -13,13 +23,34 @@ export function MainNav({ className, ...props }: React.ComponentProps<"nav">) {return (<nav className={cn("flex items-center gap-0.5", className)} {...props}>- {navItems.map((item) => (- <Button key={item.href} variant="ghost" asChild size="sm">- <Link href={item.href}>- <span>{item.title}</span>- </Link>- </Button>- ))}+ {navItems.map((item) => {+ const isActive = isActiveSection(item.href, pathname);+ return (+ <Button+ key={item.href}+ variant="ghost"+ asChild+ size="sm"+ className={cn(+ isActive+ ? "text-foreground"+ : "text-muted-foreground hover:text-foreground",+ )}+ >+ <Link href={item.href} aria-current={isActive ? "page" : undefined}>+ <span>{item.title}</span>+ </Link>+ </Button>+ );+ })}</nav>);}++function isActiveSection(href: string, pathname: string) {+ if (componentHrefs.has(href)) return componentHrefs.has(pathname);+ if (href === "/docs") {+ return pathname.startsWith("/docs") && !componentHrefs.has(pathname);+ }+ return pathname === href || pathname.startsWith(`${href}/`);+}diff --git a/src/components/page-header.tsx b/src/components/page-header.tsxindex 5bf3f94..740634b 100644--- a/src/components/page-header.tsx+++ b/src/components/page-header.tsx@@ -40,7 +40,7 @@ function PageHeader({"container mx-auto flex w-full max-w-6xl flex-col",size === "sm"? "gap-3 py-14 md:py-18"- : "gap-4 py-16 md:py-20 lg:py-24 lg:pb-20",+ : "gap-4 py-16 md:gap-5 md:py-20 lg:py-24 lg:pb-20",align === "center"? "items-center text-center": "items-start text-left",@@ -69,7 +69,7 @@ function PageHeaderHeading({return (<CompclassName={cn(- "animate-fade-up animate-stagger text-primary max-w-4xl font-bold tracking-tight",+ "animate-fade-up animate-stagger text-primary max-w-4xl font-bold tracking-tight text-balance",size === "sm"? "text-4xl font-semibold md:text-5xl": "text-4xl sm:text-5xl md:text-6xl",@@ -101,7 +101,7 @@ function PageHeaderDescription({return (<pclassName={cn(- "text-foreground/80 animate-fade-up animate-stagger max-w-2xl leading-relaxed",+ "text-foreground/80 animate-fade-up animate-stagger max-w-2xl leading-relaxed text-pretty",size === "sm"? "text-muted-foreground text-base sm:text-lg": "sm:text-lg md:text-xl",diff --git a/src/components/site-analytics.tsx b/src/components/site-analytics.tsxnew file mode 100644index 0000000..9baaa7b--- /dev/null+++ b/src/components/site-analytics.tsx@@ -0,0 +1,13 @@+"use client";++import { Analytics } from "@vercel/analytics/next";++// Block previews embed /view pages in iframes. Count only top-level pages so a+// visit to /blocks doesn't also log a pageview for every preview it loads.+export function SiteAnalytics() {+ return (+ <Analytics+ beforeSend={(event) => (window.self === window.top ? event : null)}+ />+ );+}diff --git a/src/components/theme-provider.tsx b/src/components/theme-provider.tsxindex ca00799..fafc651 100644--- a/src/components/theme-provider.tsx+++ b/src/components/theme-provider.tsx@@ -3,6 +3,9 @@import * as React from "react";import { ThemeProvider as NextThemesProvider, useTheme } from "next-themes";+/** Pressing this key anywhere outside a text field toggles the theme. */+const THEME_HOTKEY = "t";+function ThemeProvider({children,...props@@ -47,7 +50,7 @@ function ThemeHotkey() {return;}- if (event.key.toLowerCase() !== "t") {+ if (event.key.toLowerCase() !== THEME_HOTKEY) {return;}@@ -68,4 +71,4 @@ function ThemeHotkey() {return null;}-export { ThemeProvider };+export { ThemeProvider, THEME_HOTKEY };diff --git a/src/components/theme-toggle.tsx b/src/components/theme-toggle.tsxindex 17677b5..c7ff7cb 100644--- a/src/components/theme-toggle.tsx+++ b/src/components/theme-toggle.tsx@@ -5,15 +5,22 @@ import { useTheme } from "next-themes";import { Button } from "@/components/ui/button";import { Moon, Sun } from "lucide-react";import { Skeleton } from "./ui/skeleton";+import { THEME_HOTKEY } from "./theme-provider";-export function ThemeToggle() {+export function useThemeToggle() {const { resolvedTheme, setTheme } = useTheme();- const [mounted, setMounted] = useState(false);const toggleTheme = useCallback(() => {setTheme(resolvedTheme === "dark" ? "light" : "dark");}, [resolvedTheme, setTheme]);+ return { resolvedTheme, toggleTheme };+}++export function ThemeToggle() {+ const { resolvedTheme, toggleTheme } = useThemeToggle();+ const [mounted, setMounted] = useState(false);+useEffect(() => {// eslint-disable-next-line react-hooks/set-state-in-effectsetMounted(true);@@ -28,6 +35,7 @@ export function ThemeToggle() {onClick={toggleTheme}variant="ghost"aria-label="Toggle theme"+ aria-keyshortcuts={THEME_HOTKEY.toUpperCase()}size="icon-sm">{resolvedTheme === "dark" ? <Moon /> : <Sun />}diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsxindex e81382e..a67bf9b 100644--- a/src/components/ui/command.tsx+++ b/src/components/ui/command.tsx@@ -50,12 +50,12 @@ function CommandDialog({</DialogHeader><DialogContentclassName={cn(- "top-[min(22vh,10rem)] translate-y-0 overflow-hidden p-0",+ "top-[min(22vh,10rem)] translate-y-0 overflow-hidden rounded-xl p-0",className,)}showCloseButton={showCloseButton}>- <Command className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">+ <Command className="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:pt-3 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-item]]:gap-3 [&_[cmdk-item]]:rounded-lg [&_[cmdk-item]]:px-3 [&_[cmdk-item]]:py-2.5 [&_[cmdk-item]_svg]:size-4">{children}</Command></DialogContent>@@ -70,9 +70,9 @@ function CommandInput({return (<divdata-slot="command-input-wrapper"- className="flex h-9 items-center gap-2 border-b px-3"+ className="bg-muted m-2 mb-0 flex h-9 items-center gap-3 rounded-lg px-3">- <SearchIcon className="size-4 shrink-0 opacity-50" />+ <SearchIcon className="text-muted-foreground size-4 shrink-0" /><CommandPrimitive.Inputdata-slot="command-input"className={cn(diff --git a/src/lib/blocks.ts b/src/lib/blocks.tsindex 33a2262..a590113 100644--- a/src/lib/blocks.ts+++ b/src/lib/blocks.ts@@ -1,4 +1,5 @@import registry from "../../registry.json";+import { slugToTitle } from "@/lib/utils";export interface RegistryBlockItem {name: string;@@ -97,3 +98,30 @@ export function createFileTreeForRegistryItemFiles(return root;}++export interface BlockCategory {+ slug: string;+ title: string;+ blocks: RegistryBlockItem[];+}++const UNCATEGORIZED = "more";++export function getBlockCategories(): BlockCategory[] {+ const groups = new Map<string, RegistryBlockItem[]>();++ for (const block of getAllBlocks()) {+ const slug = block.categories?.[0] ?? UNCATEGORIZED;+ groups.set(slug, [...(groups.get(slug) ?? []), block]);+ }++ const uncategorized = groups.get(UNCATEGORIZED);+ groups.delete(UNCATEGORIZED);+ if (uncategorized) groups.set(UNCATEGORIZED, uncategorized);++ return Array.from(groups, ([slug, blocks]) => ({+ slug,+ title: slugToTitle(slug),+ blocks,+ }));+}diff --git a/src/lib/get-block-file-source.ts b/src/lib/get-block-file-source.tsindex 4fd693d..37deb27 100644--- a/src/lib/get-block-file-source.ts+++ b/src/lib/get-block-file-source.ts@@ -1,10 +1,12 @@import fs from "fs";import path from "path";-const SRC_DIR = process.cwd();+// Registry file paths start with "src/". Joining under a fixed "src" folder+// keeps the bundler's file tracing scoped to it instead of the whole project.+const SRC_DIR = path.join(process.cwd(), "src");export function getBlockFileSource(registryPath: string): string {- const filePath = path.join(SRC_DIR, registryPath);+ const filePath = path.join(SRC_DIR, path.relative("src", registryPath));const source = fs.readFileSync(filePath, "utf-8");return source.replace(/@\/registry\/map/g, "@/components/ui/map");diff --git a/src/lib/site-navigation.ts b/src/lib/site-navigation.tsindex 9c7a1cc..47936ce 100644--- a/src/lib/site-navigation.ts+++ b/src/lib/site-navigation.ts@@ -1,5 +1,7 @@import { BookOpen, CornerDownRight, Layers2, LucideIcon } from "lucide-react";+export const githubRepoUrl = "https://github.com/AnmolSaini16/mapcn";+export interface MainNavItem {href: string;label: string;