Template
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95b191eeb8 | ||
|
|
ff4adba2fb | ||
|
|
8602e03079 | ||
|
|
3442f19816 | ||
|
|
ebdb0bee2f | ||
|
|
b139b30273 | ||
|
|
c88613de03 | ||
|
|
64af00e702 | ||
|
|
526982691c | ||
|
|
1592b265a1 |
@@ -1,5 +1,3 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import AccountForm from '@/components/shopify/account-form';
|
import AccountForm from '@/components/shopify/account-form';
|
||||||
|
|
||||||
export const metadata = { title: 'Activate your account — Shop' };
|
export const metadata = { title: 'Activate your account — Shop' };
|
||||||
@@ -13,27 +11,23 @@ export default async function Page({
|
|||||||
const { id, token } = await params;
|
const { id, token } = await params;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
||||||
<Header storeName="Shop" logoUrl="" />
|
<AccountForm
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
title="Activate your account"
|
||||||
<AccountForm
|
description="Choose a password to finish setting up your account."
|
||||||
title="Activate your account"
|
fields={[
|
||||||
description="Choose a password to finish setting up your account."
|
{
|
||||||
fields={[
|
name: 'password',
|
||||||
{
|
label: 'Password',
|
||||||
name: 'password',
|
type: 'password',
|
||||||
label: 'Password',
|
autoComplete: 'new-password',
|
||||||
type: 'password',
|
},
|
||||||
autoComplete: 'new-password',
|
]}
|
||||||
},
|
submitLabel="Activate account"
|
||||||
]}
|
endpoint="/api/account/activate"
|
||||||
submitLabel="Activate account"
|
extraPayload={{ id, activationToken: token }}
|
||||||
endpoint="/api/account/activate"
|
redirectTo="/account"
|
||||||
extraPayload={{ id, activationToken: token }}
|
/>
|
||||||
redirectTo="/account"
|
</main>
|
||||||
/>
|
|
||||||
</main>
|
|
||||||
<Footer storeName="Shop" copyright="© 2026 Shop. All rights reserved." />
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-35
@@ -1,44 +1,38 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import AccountForm, { AccountFormLink } from '@/components/shopify/account-form';
|
import AccountForm, { AccountFormLink } from '@/components/shopify/account-form';
|
||||||
|
|
||||||
export const metadata = { title: 'Sign in — Shop' };
|
export const metadata = { title: 'Sign in — Shop' };
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
||||||
<Header storeName="Shop" logoUrl="" />
|
<AccountForm
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
title="Sign in"
|
||||||
<AccountForm
|
fields={[
|
||||||
title="Sign in"
|
{ name: 'email', label: 'Email', type: 'email', autoComplete: 'email' },
|
||||||
fields={[
|
{
|
||||||
{ name: 'email', label: 'Email', type: 'email', autoComplete: 'email' },
|
name: 'password',
|
||||||
{
|
label: 'Password',
|
||||||
name: 'password',
|
type: 'password',
|
||||||
label: 'Password',
|
autoComplete: 'current-password',
|
||||||
type: 'password',
|
},
|
||||||
autoComplete: 'current-password',
|
]}
|
||||||
},
|
submitLabel="Sign in"
|
||||||
]}
|
endpoint="/api/account/login"
|
||||||
submitLabel="Sign in"
|
redirectTo="/account"
|
||||||
endpoint="/api/account/login"
|
footer={
|
||||||
redirectTo="/account"
|
<>
|
||||||
footer={
|
<span>
|
||||||
<>
|
New here?{' '}
|
||||||
<span>
|
<AccountFormLink href="/account/register">
|
||||||
New here?{' '}
|
Create an account
|
||||||
<AccountFormLink href="/account/register">
|
|
||||||
Create an account
|
|
||||||
</AccountFormLink>
|
|
||||||
</span>
|
|
||||||
<AccountFormLink href="/account/recover">
|
|
||||||
Forgot your password?
|
|
||||||
</AccountFormLink>
|
</AccountFormLink>
|
||||||
</>
|
</span>
|
||||||
}
|
<AccountFormLink href="/account/recover">
|
||||||
/>
|
Forgot your password?
|
||||||
</main>
|
</AccountFormLink>
|
||||||
<Footer storeName="Shop" copyright="© 2026 Shop. All rights reserved." />
|
</>
|
||||||
</>
|
}
|
||||||
|
/>
|
||||||
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-19
@@ -1,6 +1,4 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import OrderHistory from '@/components/shopify/order-history';
|
import OrderHistory from '@/components/shopify/order-history';
|
||||||
import { getSessionToken } from '@/services/shopify/session';
|
import { getSessionToken } from '@/services/shopify/session';
|
||||||
import { getCustomer } from '@/services/shopify/customer';
|
import { getCustomer } from '@/services/shopify/customer';
|
||||||
@@ -16,23 +14,17 @@ export default async function Page() {
|
|||||||
if (!customer) redirect('/account/login');
|
if (!customer) redirect('/account/login');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-8 py-12">
|
||||||
<Header storeName="Shop" logoUrl="" />
|
<h1 className="text-2xl md:text-3xl font-normal text-foreground">
|
||||||
|
Order history
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
{customer.displayName} · {customer.email}
|
||||||
|
</p>
|
||||||
|
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-8 py-12">
|
<div className="mt-10">
|
||||||
<h1 className="text-2xl md:text-3xl font-normal text-foreground">
|
<OrderHistory customer={customer} />
|
||||||
Order history
|
</div>
|
||||||
</h1>
|
</main>
|
||||||
<p className="mt-1 text-sm text-muted-foreground">
|
|
||||||
{customer.displayName} · {customer.email}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="mt-10">
|
|
||||||
<OrderHistory customer={customer} />
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<Footer storeName="Shop" copyright="© 2026 Shop. All rights reserved." />
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import AccountForm, { AccountFormLink } from '@/components/shopify/account-form';
|
import AccountForm, { AccountFormLink } from '@/components/shopify/account-form';
|
||||||
|
|
||||||
export const metadata = { title: 'Reset password — Shop' };
|
export const metadata = { title: 'Reset password — Shop' };
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
||||||
<Header storeName="Shop" logoUrl="" />
|
<AccountForm
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
title="Reset password"
|
||||||
<AccountForm
|
description="Enter your email and we'll send you a link to set a new password."
|
||||||
title="Reset password"
|
fields={[
|
||||||
description="Enter your email and we'll send you a link to set a new password."
|
{ name: 'email', label: 'Email', type: 'email', autoComplete: 'email' },
|
||||||
fields={[
|
]}
|
||||||
{ name: 'email', label: 'Email', type: 'email', autoComplete: 'email' },
|
submitLabel="Send reset link"
|
||||||
]}
|
endpoint="/api/account/recover"
|
||||||
submitLabel="Send reset link"
|
successMessage="If that email has an account, a reset link is on its way."
|
||||||
endpoint="/api/account/recover"
|
footer={
|
||||||
successMessage="If that email has an account, a reset link is on its way."
|
<AccountFormLink href="/account/login">Back to sign in</AccountFormLink>
|
||||||
footer={
|
}
|
||||||
<AccountFormLink href="/account/login">Back to sign in</AccountFormLink>
|
/>
|
||||||
}
|
</main>
|
||||||
/>
|
|
||||||
</main>
|
|
||||||
<Footer storeName="Shop" copyright="© 2026 Shop. All rights reserved." />
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,43 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import AccountForm, { AccountFormLink } from '@/components/shopify/account-form';
|
import AccountForm, { AccountFormLink } from '@/components/shopify/account-form';
|
||||||
|
|
||||||
export const metadata = { title: 'Create account — Shop' };
|
export const metadata = { title: 'Create account — Shop' };
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
||||||
<Header storeName="Shop" logoUrl="" />
|
<AccountForm
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
title="Create account"
|
||||||
<AccountForm
|
fields={[
|
||||||
title="Create account"
|
{
|
||||||
fields={[
|
name: 'firstName',
|
||||||
{
|
label: 'First name',
|
||||||
name: 'firstName',
|
autoComplete: 'given-name',
|
||||||
label: 'First name',
|
required: false,
|
||||||
autoComplete: 'given-name',
|
},
|
||||||
required: false,
|
{
|
||||||
},
|
name: 'lastName',
|
||||||
{
|
label: 'Last name',
|
||||||
name: 'lastName',
|
autoComplete: 'family-name',
|
||||||
label: 'Last name',
|
required: false,
|
||||||
autoComplete: 'family-name',
|
},
|
||||||
required: false,
|
{ name: 'email', label: 'Email', type: 'email', autoComplete: 'email' },
|
||||||
},
|
{
|
||||||
{ name: 'email', label: 'Email', type: 'email', autoComplete: 'email' },
|
name: 'password',
|
||||||
{
|
label: 'Password',
|
||||||
name: 'password',
|
type: 'password',
|
||||||
label: 'Password',
|
autoComplete: 'new-password',
|
||||||
type: 'password',
|
},
|
||||||
autoComplete: 'new-password',
|
]}
|
||||||
},
|
submitLabel="Create account"
|
||||||
]}
|
endpoint="/api/account/register"
|
||||||
submitLabel="Create account"
|
redirectTo="/account"
|
||||||
endpoint="/api/account/register"
|
footer={
|
||||||
redirectTo="/account"
|
<span>
|
||||||
footer={
|
Already have an account?{' '}
|
||||||
<span>
|
<AccountFormLink href="/account/login">Sign in</AccountFormLink>
|
||||||
Already have an account?{' '}
|
</span>
|
||||||
<AccountFormLink href="/account/login">Sign in</AccountFormLink>
|
}
|
||||||
</span>
|
/>
|
||||||
}
|
</main>
|
||||||
/>
|
|
||||||
</main>
|
|
||||||
<Footer storeName="Shop" copyright="© 2026 Shop. All rights reserved." />
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import AccountForm from '@/components/shopify/account-form';
|
import AccountForm from '@/components/shopify/account-form';
|
||||||
|
|
||||||
export const metadata = { title: 'Set a new password — Shop' };
|
export const metadata = { title: 'Set a new password — Shop' };
|
||||||
@@ -13,26 +11,22 @@ export default async function Page({
|
|||||||
const { id, token } = await params;
|
const { id, token } = await params;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
||||||
<Header storeName="Shop" logoUrl="" />
|
<AccountForm
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-8 py-16">
|
title="Set a new password"
|
||||||
<AccountForm
|
fields={[
|
||||||
title="Set a new password"
|
{
|
||||||
fields={[
|
name: 'password',
|
||||||
{
|
label: 'New password',
|
||||||
name: 'password',
|
type: 'password',
|
||||||
label: 'New password',
|
autoComplete: 'new-password',
|
||||||
type: 'password',
|
},
|
||||||
autoComplete: 'new-password',
|
]}
|
||||||
},
|
submitLabel="Save password"
|
||||||
]}
|
endpoint="/api/account/reset"
|
||||||
submitLabel="Save password"
|
extraPayload={{ id, resetToken: token }}
|
||||||
endpoint="/api/account/reset"
|
redirectTo="/account"
|
||||||
extraPayload={{ id, resetToken: token }}
|
/>
|
||||||
redirectTo="/account"
|
</main>
|
||||||
/>
|
|
||||||
</main>
|
|
||||||
<Footer storeName="Shop" copyright="© 2026 Shop. All rights reserved." />
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -7,6 +7,8 @@ import {
|
|||||||
getProductsPage,
|
getProductsPage,
|
||||||
getCollections,
|
getCollections,
|
||||||
getCollectionProductsPage,
|
getCollectionProductsPage,
|
||||||
|
isDefaultTitleOption,
|
||||||
|
isDefaultTitleSelection,
|
||||||
} from '@/services/shopify/catalog';
|
} from '@/services/shopify/catalog';
|
||||||
|
|
||||||
// Streaming needs the Node runtime here because the Storefront helpers run
|
// Streaming needs the Node runtime here because the Storefront helpers run
|
||||||
@@ -63,10 +65,12 @@ const summariseProduct = (product: {
|
|||||||
description: product.description?.slice(0, 300) ?? null,
|
description: product.description?.slice(0, 300) ?? null,
|
||||||
productType: product.productType || null,
|
productType: product.productType || null,
|
||||||
tags: product.tags ?? [],
|
tags: product.tags ?? [],
|
||||||
options: product.options?.map((option) => ({
|
options: product.options
|
||||||
name: option.name,
|
?.filter((option) => !isDefaultTitleOption(option))
|
||||||
values: option.values,
|
.map((option) => ({
|
||||||
})),
|
name: option.name,
|
||||||
|
values: option.values,
|
||||||
|
})),
|
||||||
inStock: product.variants?.edges.some((edge) => edge.node.availableForSale),
|
inStock: product.variants?.edges.some((edge) => edge.node.availableForSale),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,7 +136,9 @@ export async function POST(req: Request) {
|
|||||||
title: node.title,
|
title: node.title,
|
||||||
available: node.availableForSale,
|
available: node.availableForSale,
|
||||||
price: `${node.price.amount} ${node.price.currencyCode}`,
|
price: `${node.price.amount} ${node.price.currencyCode}`,
|
||||||
options: node.selectedOptions,
|
options: node.selectedOptions?.filter(
|
||||||
|
(option) => !isDefaultTitleSelection(option)
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import CollectionDetail from '@/components/shopify/collection-detail';
|
import CollectionDetail from '@/components/shopify/collection-detail';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return <CollectionDetail />;
|
||||||
<>
|
|
||||||
<Header
|
|
||||||
storeName="Shop"
|
|
||||||
logoUrl=""
|
|
||||||
links={[
|
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<CollectionDetail />
|
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import Collections from '@/components/shopify/collections';
|
import Collections from '@/components/shopify/collections';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return <Collections title="Our Collections" />;
|
||||||
<>
|
|
||||||
<Header
|
|
||||||
storeName="Shop"
|
|
||||||
logoUrl=""
|
|
||||||
links={[
|
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<Collections title="Our Collections" />
|
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ export default function Error({
|
|||||||
reset: () => void;
|
reset: () => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center min-h-screen">
|
<div className="flex items-center justify-center min-h-[60vh]">
|
||||||
<div className="flex items-center gap-6">
|
<div className="flex items-center gap-6">
|
||||||
<div className="text-lg font-medium text-black font-sans whitespace-nowrap">
|
<div className="text-lg font-medium text-black font-sans whitespace-nowrap">
|
||||||
Something went wrong
|
Something went wrong
|
||||||
|
|||||||
+13
-4
@@ -1,9 +1,10 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import './globals.css';
|
import './globals.css';
|
||||||
import { Geist, Geist_Mono } from 'next/font/google';
|
import { Geist, Geist_Mono } from 'next/font/google';
|
||||||
|
import Header from '@/components/shopify/header';
|
||||||
|
import Footer from '@/components/shopify/footer';
|
||||||
import StoreAssistant from '@/components/shopify/store-assistant';
|
import StoreAssistant from '@/components/shopify/store-assistant';
|
||||||
|
import { site } from '@/config/site';
|
||||||
|
|
||||||
const geist = Geist({
|
const geist = Geist({
|
||||||
subsets: ['latin'],
|
subsets: ['latin'],
|
||||||
@@ -22,8 +23,16 @@ export default function RootLayout({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<html lang="en" className={`${geist.variable} ${geistMono.variable}`}>
|
<html lang="en" className={`${geist.variable} ${geistMono.variable}`}>
|
||||||
<body className="font-body antialiased bg-background text-foreground m-0 p-0">
|
<body className="font-body antialiased bg-background text-foreground m-0 p-0 flex min-h-screen flex-col">
|
||||||
{children}
|
{/* Header owns the cart drawer, search and account menu, so every
|
||||||
|
route gets them by rendering here rather than page by page. */}
|
||||||
|
<Header
|
||||||
|
storeName={site.storeName}
|
||||||
|
logoUrl={site.logoUrl}
|
||||||
|
links={site.navLinks}
|
||||||
|
/>
|
||||||
|
<div className="flex-1">{children}</div>
|
||||||
|
<Footer storeName={site.storeName} copyright={site.copyright} />
|
||||||
<StoreAssistant />
|
<StoreAssistant />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import Link from 'next/link';
|
|||||||
|
|
||||||
export default function NotFound() {
|
export default function NotFound() {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center min-h-screen">
|
<div className="flex items-center justify-center min-h-[60vh]">
|
||||||
<div className="flex items-center gap-6">
|
<div className="flex items-center gap-6">
|
||||||
<div className="text-lg font-medium text-black font-sans whitespace-nowrap">
|
<div className="text-lg font-medium text-black font-sans whitespace-nowrap">
|
||||||
404
|
404
|
||||||
|
|||||||
+4
-20
@@ -1,26 +1,10 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import Products from '@/components/shopify/products';
|
import Products from '@/components/shopify/products';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<Products
|
||||||
<Header
|
title="Shopify Hydrogen Storefront"
|
||||||
storeName="Shop"
|
subtitle="An agent-friendly Shopify storefront built with Next.js and Hydrogen."
|
||||||
logoUrl=""
|
/>
|
||||||
links={[
|
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<Products
|
|
||||||
title="Shopify Hydrogen Storefront"
|
|
||||||
subtitle="An agent-friendly Shopify storefront built with Next.js and Hydrogen."
|
|
||||||
/>
|
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import { getShopPolicy, POLICY_HANDLES } from '@/hooks/use-shopify-policies';
|
import { getShopPolicy, POLICY_HANDLES } from '@/hooks/use-shopify-policies';
|
||||||
|
|
||||||
export function generateStaticParams() {
|
export function generateStaticParams() {
|
||||||
@@ -33,33 +31,17 @@ export default async function PolicyPage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<main className="max-w-screen-2xl mx-auto w-full px-5 lg:px-10 py-16">
|
||||||
<Header
|
<div className="max-w-2xl mx-auto">
|
||||||
storeName="Shop"
|
<h1 className="text-3xl md:text-4xl font-normal text-foreground">
|
||||||
logoUrl=""
|
{policy.title}
|
||||||
links={[
|
</h1>
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<main className="max-w-screen-2xl mx-auto w-full px-5 lg:px-10 py-16">
|
<div
|
||||||
<div className="max-w-2xl mx-auto">
|
className="policy-body mt-8 text-[15px] leading-7 text-foreground"
|
||||||
<h1 className="text-3xl md:text-4xl font-normal text-foreground">
|
dangerouslySetInnerHTML={{ __html: policy.body }}
|
||||||
{policy.title}
|
/>
|
||||||
</h1>
|
</div>
|
||||||
|
</main>
|
||||||
<div
|
|
||||||
className="policy-body mt-8 text-[15px] leading-7 text-foreground"
|
|
||||||
dangerouslySetInnerHTML={{ __html: policy.body }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,11 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import ProductDetail from '@/components/shopify/product-detail';
|
import ProductDetail from '@/components/shopify/product-detail';
|
||||||
import ProductRecommendations from '@/components/shopify/product-recommendations';
|
import ProductRecommendations from '@/components/shopify/product-recommendations';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header
|
|
||||||
storeName="Shop"
|
|
||||||
logoUrl=""
|
|
||||||
links={[
|
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<ProductDetail addToCartLabel="Add to Cart" />
|
<ProductDetail addToCartLabel="Add to Cart" />
|
||||||
<ProductRecommendations title="You May Also Like" />
|
<ProductRecommendations title="You May Also Like" />
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-22
@@ -1,6 +1,4 @@
|
|||||||
import { Suspense } from 'react';
|
import { Suspense } from 'react';
|
||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import SearchResults from '@/components/shopify/search-results';
|
import SearchResults from '@/components/shopify/search-results';
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
@@ -9,25 +7,9 @@ export const metadata = {
|
|||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
// useSearchParams needs a Suspense boundary to prerender this route.
|
||||||
<Header
|
<Suspense fallback={<div className="py-10" />}>
|
||||||
storeName="Shop"
|
<SearchResults />
|
||||||
logoUrl=""
|
</Suspense>
|
||||||
links={[
|
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* useSearchParams needs a Suspense boundary to prerender this route. */}
|
|
||||||
<Suspense fallback={<div className="py-10" />}>
|
|
||||||
<SearchResults />
|
|
||||||
</Suspense>
|
|
||||||
|
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
import Header from '@/components/shopify/header';
|
|
||||||
import Footer from '@/components/shopify/footer';
|
|
||||||
import Collections from '@/components/shopify/collections';
|
import Collections from '@/components/shopify/collections';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return <Collections title="Our Collections" />;
|
||||||
<>
|
|
||||||
<Header
|
|
||||||
storeName="Shop"
|
|
||||||
logoUrl=""
|
|
||||||
links={[
|
|
||||||
{ label: 'Products', url: '/' },
|
|
||||||
{ label: 'Collections', url: '/shop/collections' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<Collections title="Our Collections" />
|
|
||||||
<Footer
|
|
||||||
storeName="Shop"
|
|
||||||
copyright="© 2026 Shop. All rights reserved."
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,562 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
||||||
import type { ComponentProps, CSSProperties, HTMLAttributes } from "react";
|
|
||||||
import {
|
|
||||||
createContext,
|
|
||||||
memo,
|
|
||||||
useCallback,
|
|
||||||
useContext,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import type {
|
|
||||||
BundledLanguage,
|
|
||||||
BundledTheme,
|
|
||||||
HighlighterGeneric,
|
|
||||||
ThemedToken,
|
|
||||||
} from "shiki";
|
|
||||||
import { createHighlighter } from "shiki";
|
|
||||||
|
|
||||||
// Shiki uses bitflags for font styles: 1=italic, 2=bold, 4=underline
|
|
||||||
// oxlint-disable-next-line eslint(no-bitwise)
|
|
||||||
const isItalic = (fontStyle: number | undefined) => fontStyle && fontStyle & 1;
|
|
||||||
// oxlint-disable-next-line eslint(no-bitwise)
|
|
||||||
const isBold = (fontStyle: number | undefined) => fontStyle && fontStyle & 2;
|
|
||||||
const isUnderline = (fontStyle: number | undefined) =>
|
|
||||||
// oxlint-disable-next-line eslint(no-bitwise)
|
|
||||||
fontStyle && fontStyle & 4;
|
|
||||||
|
|
||||||
// Transform tokens to include pre-computed keys to avoid noArrayIndexKey lint
|
|
||||||
interface KeyedToken {
|
|
||||||
token: ThemedToken;
|
|
||||||
key: string;
|
|
||||||
}
|
|
||||||
interface KeyedLine {
|
|
||||||
tokens: KeyedToken[];
|
|
||||||
key: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const addKeysToTokens = (lines: ThemedToken[][]): KeyedLine[] =>
|
|
||||||
lines.map((line, lineIdx) => ({
|
|
||||||
key: `line-${lineIdx}`,
|
|
||||||
tokens: line.map((token, tokenIdx) => ({
|
|
||||||
key: `line-${lineIdx}-${tokenIdx}`,
|
|
||||||
token,
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Token rendering component
|
|
||||||
const TokenSpan = ({ token }: { token: ThemedToken }) => (
|
|
||||||
<span
|
|
||||||
className="dark:!bg-[var(--shiki-dark-bg)] dark:!text-[var(--shiki-dark)]"
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
backgroundColor: token.bgColor,
|
|
||||||
color: token.color,
|
|
||||||
fontStyle: isItalic(token.fontStyle) ? "italic" : undefined,
|
|
||||||
fontWeight: isBold(token.fontStyle) ? "bold" : undefined,
|
|
||||||
textDecoration: isUnderline(token.fontStyle) ? "underline" : undefined,
|
|
||||||
...token.htmlStyle,
|
|
||||||
} as CSSProperties
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{token.content}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Line number styles using CSS counters
|
|
||||||
const LINE_NUMBER_CLASSES = cn(
|
|
||||||
"block",
|
|
||||||
"before:content-[counter(line)]",
|
|
||||||
"before:inline-block",
|
|
||||||
"before:[counter-increment:line]",
|
|
||||||
"before:w-8",
|
|
||||||
"before:mr-4",
|
|
||||||
"before:text-right",
|
|
||||||
"before:text-muted-foreground/50",
|
|
||||||
"before:font-mono",
|
|
||||||
"before:select-none"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Line rendering component
|
|
||||||
const LineSpan = ({
|
|
||||||
keyedLine,
|
|
||||||
showLineNumbers,
|
|
||||||
}: {
|
|
||||||
keyedLine: KeyedLine;
|
|
||||||
showLineNumbers: boolean;
|
|
||||||
}) => (
|
|
||||||
<span className={showLineNumbers ? LINE_NUMBER_CLASSES : "block"}>
|
|
||||||
{keyedLine.tokens.length === 0
|
|
||||||
? "\n"
|
|
||||||
: keyedLine.tokens.map(({ token, key }) => (
|
|
||||||
<TokenSpan key={key} token={token} />
|
|
||||||
))}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Types
|
|
||||||
type CodeBlockProps = HTMLAttributes<HTMLDivElement> & {
|
|
||||||
code: string;
|
|
||||||
language: BundledLanguage;
|
|
||||||
showLineNumbers?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface TokenizedCode {
|
|
||||||
tokens: ThemedToken[][];
|
|
||||||
fg: string;
|
|
||||||
bg: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CodeBlockContextType {
|
|
||||||
code: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Context
|
|
||||||
const CodeBlockContext = createContext<CodeBlockContextType>({
|
|
||||||
code: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Highlighter cache (singleton per language)
|
|
||||||
const highlighterCache = new Map<
|
|
||||||
string,
|
|
||||||
Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
|
|
||||||
>();
|
|
||||||
|
|
||||||
// Token cache
|
|
||||||
const tokensCache = new Map<string, TokenizedCode>();
|
|
||||||
|
|
||||||
// Subscribers for async token updates
|
|
||||||
const subscribers = new Map<string, Set<(result: TokenizedCode) => void>>();
|
|
||||||
|
|
||||||
const getTokensCacheKey = (code: string, language: BundledLanguage) => {
|
|
||||||
const start = code.slice(0, 100);
|
|
||||||
const end = code.length > 100 ? code.slice(-100) : "";
|
|
||||||
return `${language}:${code.length}:${start}:${end}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getHighlighter = (
|
|
||||||
language: BundledLanguage
|
|
||||||
): Promise<HighlighterGeneric<BundledLanguage, BundledTheme>> => {
|
|
||||||
const cached = highlighterCache.get(language);
|
|
||||||
if (cached) {
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
const highlighterPromise = createHighlighter({
|
|
||||||
langs: [language],
|
|
||||||
themes: ["github-light", "github-dark"],
|
|
||||||
});
|
|
||||||
|
|
||||||
highlighterCache.set(language, highlighterPromise);
|
|
||||||
return highlighterPromise;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create raw tokens for immediate display while highlighting loads
|
|
||||||
const createRawTokens = (code: string): TokenizedCode => ({
|
|
||||||
bg: "transparent",
|
|
||||||
fg: "inherit",
|
|
||||||
tokens: code.split("\n").map((line) =>
|
|
||||||
line === ""
|
|
||||||
? []
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
color: "inherit",
|
|
||||||
content: line,
|
|
||||||
} as ThemedToken,
|
|
||||||
]
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Synchronous highlight with callback for async results
|
|
||||||
export const highlightCode = (
|
|
||||||
code: string,
|
|
||||||
language: BundledLanguage,
|
|
||||||
// oxlint-disable-next-line eslint-plugin-promise(prefer-await-to-callbacks)
|
|
||||||
callback?: (result: TokenizedCode) => void
|
|
||||||
): TokenizedCode | null => {
|
|
||||||
const tokensCacheKey = getTokensCacheKey(code, language);
|
|
||||||
|
|
||||||
// Return cached result if available
|
|
||||||
const cached = tokensCache.get(tokensCacheKey);
|
|
||||||
if (cached) {
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe callback if provided
|
|
||||||
if (callback) {
|
|
||||||
if (!subscribers.has(tokensCacheKey)) {
|
|
||||||
subscribers.set(tokensCacheKey, new Set());
|
|
||||||
}
|
|
||||||
subscribers.get(tokensCacheKey)?.add(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start highlighting in background - fire-and-forget async pattern
|
|
||||||
getHighlighter(language)
|
|
||||||
// oxlint-disable-next-line eslint-plugin-promise(prefer-await-to-then)
|
|
||||||
.then((highlighter) => {
|
|
||||||
const availableLangs = highlighter.getLoadedLanguages();
|
|
||||||
const langToUse = availableLangs.includes(language) ? language : "text";
|
|
||||||
|
|
||||||
const result = highlighter.codeToTokens(code, {
|
|
||||||
lang: langToUse,
|
|
||||||
themes: {
|
|
||||||
dark: "github-dark",
|
|
||||||
light: "github-light",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const tokenized: TokenizedCode = {
|
|
||||||
bg: result.bg ?? "transparent",
|
|
||||||
fg: result.fg ?? "inherit",
|
|
||||||
tokens: result.tokens,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cache the result
|
|
||||||
tokensCache.set(tokensCacheKey, tokenized);
|
|
||||||
|
|
||||||
// Notify all subscribers
|
|
||||||
const subs = subscribers.get(tokensCacheKey);
|
|
||||||
if (subs) {
|
|
||||||
for (const sub of subs) {
|
|
||||||
sub(tokenized);
|
|
||||||
}
|
|
||||||
subscribers.delete(tokensCacheKey);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// oxlint-disable-next-line eslint-plugin-promise(prefer-await-to-then), eslint-plugin-promise(prefer-await-to-callbacks)
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Failed to highlight code:", error);
|
|
||||||
subscribers.delete(tokensCacheKey);
|
|
||||||
});
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CodeBlockBody = memo(
|
|
||||||
({
|
|
||||||
tokenized,
|
|
||||||
showLineNumbers,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
tokenized: TokenizedCode;
|
|
||||||
showLineNumbers: boolean;
|
|
||||||
className?: string;
|
|
||||||
}) => {
|
|
||||||
const preStyle = useMemo(
|
|
||||||
() => ({
|
|
||||||
backgroundColor: tokenized.bg,
|
|
||||||
color: tokenized.fg,
|
|
||||||
}),
|
|
||||||
[tokenized.bg, tokenized.fg]
|
|
||||||
);
|
|
||||||
|
|
||||||
const keyedLines = useMemo(
|
|
||||||
() => addKeysToTokens(tokenized.tokens),
|
|
||||||
[tokenized.tokens]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<pre
|
|
||||||
className={cn(
|
|
||||||
"dark:!bg-[var(--shiki-dark-bg)] dark:!text-[var(--shiki-dark)] m-0 p-4 text-sm",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
style={preStyle}
|
|
||||||
>
|
|
||||||
<code
|
|
||||||
className={cn(
|
|
||||||
"font-mono text-sm",
|
|
||||||
showLineNumbers && "[counter-increment:line_0] [counter-reset:line]"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{keyedLines.map((keyedLine) => (
|
|
||||||
<LineSpan
|
|
||||||
key={keyedLine.key}
|
|
||||||
keyedLine={keyedLine}
|
|
||||||
showLineNumbers={showLineNumbers}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</code>
|
|
||||||
</pre>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(prevProps, nextProps) =>
|
|
||||||
prevProps.tokenized === nextProps.tokenized &&
|
|
||||||
prevProps.showLineNumbers === nextProps.showLineNumbers &&
|
|
||||||
prevProps.className === nextProps.className
|
|
||||||
);
|
|
||||||
|
|
||||||
CodeBlockBody.displayName = "CodeBlockBody";
|
|
||||||
|
|
||||||
export const CodeBlockContainer = ({
|
|
||||||
className,
|
|
||||||
language,
|
|
||||||
style,
|
|
||||||
...props
|
|
||||||
}: HTMLAttributes<HTMLDivElement> & { language: string }) => (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
"group relative w-full overflow-hidden rounded-md border bg-background text-foreground",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
data-language={language}
|
|
||||||
style={{
|
|
||||||
containIntrinsicSize: "auto 200px",
|
|
||||||
contentVisibility: "auto",
|
|
||||||
...style,
|
|
||||||
}}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const CodeBlockHeader = ({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
"flex items-center justify-between border-b bg-muted/80 px-3 py-2 text-muted-foreground text-xs",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const CodeBlockTitle = ({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div className={cn("flex items-center gap-2", className)} {...props}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const CodeBlockFilename = ({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: HTMLAttributes<HTMLSpanElement>) => (
|
|
||||||
<span className={cn("font-mono", className)} {...props}>
|
|
||||||
{children}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const CodeBlockActions = ({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div
|
|
||||||
className={cn("-my-1 -mr-1 flex items-center gap-2", className)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const CodeBlockContent = ({
|
|
||||||
code,
|
|
||||||
language,
|
|
||||||
showLineNumbers = false,
|
|
||||||
}: {
|
|
||||||
code: string;
|
|
||||||
language: BundledLanguage;
|
|
||||||
showLineNumbers?: boolean;
|
|
||||||
}) => {
|
|
||||||
// Memoized raw tokens for immediate display
|
|
||||||
const rawTokens = useMemo(() => createRawTokens(code), [code]);
|
|
||||||
|
|
||||||
// Synchronous cache lookup — avoids setState in effect for cached results
|
|
||||||
const syncTokens = useMemo(
|
|
||||||
() => highlightCode(code, language) ?? rawTokens,
|
|
||||||
[code, language, rawTokens]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Async highlighting result (populated after shiki loads)
|
|
||||||
const [asyncTokens, setAsyncTokens] = useState<TokenizedCode | null>(null);
|
|
||||||
const asyncKeyRef = useRef({ code, language });
|
|
||||||
|
|
||||||
// Invalidate stale async tokens synchronously during render
|
|
||||||
if (
|
|
||||||
asyncKeyRef.current.code !== code ||
|
|
||||||
asyncKeyRef.current.language !== language
|
|
||||||
) {
|
|
||||||
asyncKeyRef.current = { code, language };
|
|
||||||
setAsyncTokens(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let cancelled = false;
|
|
||||||
|
|
||||||
highlightCode(code, language, (result) => {
|
|
||||||
if (!cancelled) {
|
|
||||||
setAsyncTokens(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [code, language]);
|
|
||||||
|
|
||||||
const tokenized = asyncTokens ?? syncTokens;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="relative overflow-auto">
|
|
||||||
<CodeBlockBody showLineNumbers={showLineNumbers} tokenized={tokenized} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const CodeBlock = ({
|
|
||||||
code,
|
|
||||||
language,
|
|
||||||
showLineNumbers = false,
|
|
||||||
className,
|
|
||||||
children,
|
|
||||||
...props
|
|
||||||
}: CodeBlockProps) => {
|
|
||||||
const contextValue = useMemo(() => ({ code }), [code]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CodeBlockContext.Provider value={contextValue}>
|
|
||||||
<CodeBlockContainer className={className} language={language} {...props}>
|
|
||||||
{children}
|
|
||||||
<CodeBlockContent
|
|
||||||
code={code}
|
|
||||||
language={language}
|
|
||||||
showLineNumbers={showLineNumbers}
|
|
||||||
/>
|
|
||||||
</CodeBlockContainer>
|
|
||||||
</CodeBlockContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CodeBlockCopyButtonProps = ComponentProps<typeof Button> & {
|
|
||||||
onCopy?: () => void;
|
|
||||||
onError?: (error: Error) => void;
|
|
||||||
timeout?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const CodeBlockCopyButton = ({
|
|
||||||
onCopy,
|
|
||||||
onError,
|
|
||||||
timeout = 2000,
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: CodeBlockCopyButtonProps) => {
|
|
||||||
const [isCopied, setIsCopied] = useState(false);
|
|
||||||
const timeoutRef = useRef<number>(0);
|
|
||||||
const { code } = useContext(CodeBlockContext);
|
|
||||||
|
|
||||||
const copyToClipboard = useCallback(async () => {
|
|
||||||
if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
|
|
||||||
onError?.(new Error("Clipboard API not available"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!isCopied) {
|
|
||||||
await navigator.clipboard.writeText(code);
|
|
||||||
setIsCopied(true);
|
|
||||||
onCopy?.();
|
|
||||||
timeoutRef.current = window.setTimeout(
|
|
||||||
() => setIsCopied(false),
|
|
||||||
timeout
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
onError?.(error as Error);
|
|
||||||
}
|
|
||||||
}, [code, onCopy, onError, timeout, isCopied]);
|
|
||||||
|
|
||||||
useEffect(
|
|
||||||
() => () => {
|
|
||||||
window.clearTimeout(timeoutRef.current);
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const Icon = isCopied ? CheckIcon : CopyIcon;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
className={cn("shrink-0", className)}
|
|
||||||
onClick={copyToClipboard}
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children ?? <Icon size={14} />}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CodeBlockLanguageSelectorProps = ComponentProps<typeof Select>;
|
|
||||||
|
|
||||||
export const CodeBlockLanguageSelector = (
|
|
||||||
props: CodeBlockLanguageSelectorProps
|
|
||||||
) => <Select {...props} />;
|
|
||||||
|
|
||||||
export type CodeBlockLanguageSelectorTriggerProps = ComponentProps<
|
|
||||||
typeof SelectTrigger
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const CodeBlockLanguageSelectorTrigger = ({
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: CodeBlockLanguageSelectorTriggerProps) => (
|
|
||||||
<SelectTrigger
|
|
||||||
className={cn(
|
|
||||||
"h-7 border-none bg-transparent px-2 text-xs shadow-none",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
size="sm"
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
export type CodeBlockLanguageSelectorValueProps = ComponentProps<
|
|
||||||
typeof SelectValue
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const CodeBlockLanguageSelectorValue = (
|
|
||||||
props: CodeBlockLanguageSelectorValueProps
|
|
||||||
) => <SelectValue {...props} />;
|
|
||||||
|
|
||||||
export type CodeBlockLanguageSelectorContentProps = ComponentProps<
|
|
||||||
typeof SelectContent
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const CodeBlockLanguageSelectorContent = ({
|
|
||||||
align = "end",
|
|
||||||
...props
|
|
||||||
}: CodeBlockLanguageSelectorContentProps) => (
|
|
||||||
<SelectContent align={align} {...props} />
|
|
||||||
);
|
|
||||||
|
|
||||||
export type CodeBlockLanguageSelectorItemProps = ComponentProps<
|
|
||||||
typeof SelectItem
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const CodeBlockLanguageSelectorItem = (
|
|
||||||
props: CodeBlockLanguageSelectorItemProps
|
|
||||||
) => <SelectItem {...props} />;
|
|
||||||
@@ -0,0 +1,295 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import Link from "next/link";
|
||||||
|
import type { Nodes } from "hast";
|
||||||
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
||||||
|
import type { Components } from "hast-util-to-jsx-runtime";
|
||||||
|
import type { ComponentProps, HTMLAttributes, MouseEvent } from "react";
|
||||||
|
import { Fragment, memo, useCallback, useMemo, useState } from "react";
|
||||||
|
import { jsx, jsxs } from "react/jsx-runtime";
|
||||||
|
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
|
||||||
|
import remarkGfm from "remark-gfm";
|
||||||
|
import remarkParse from "remark-parse";
|
||||||
|
import remarkRehype from "remark-rehype";
|
||||||
|
import remend from "remend";
|
||||||
|
import { unified } from "unified";
|
||||||
|
|
||||||
|
// Raw HTML never reaches the tree: remark-rehype drops it (allowDangerousHtml
|
||||||
|
// is off by default) and rehype-sanitize is the second line of defence, mainly
|
||||||
|
// for its href protocol allow-list — that is what stops `javascript:` URLs.
|
||||||
|
// Relative hrefs carry no protocol, so storefront links pass through untouched.
|
||||||
|
const schema = {
|
||||||
|
...defaultSchema,
|
||||||
|
attributes: {
|
||||||
|
...defaultSchema.attributes,
|
||||||
|
// GFM task lists render as disabled checkboxes. The default schema allows
|
||||||
|
// `type` and `disabled` but not `checked`, so every box would read unticked.
|
||||||
|
input: [...(defaultSchema.attributes?.input ?? []), "checked"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const processor = unified()
|
||||||
|
.use(remarkParse)
|
||||||
|
.use(remarkGfm)
|
||||||
|
.use(remarkRehype)
|
||||||
|
.use(rehypeSanitize, schema);
|
||||||
|
|
||||||
|
// `text-only` leaves a half-streamed `[label](htt` as plain text. remend's
|
||||||
|
// default instead emits a `streamdown:incomplete-link` placeholder href, which
|
||||||
|
// the sanitizer would strip anyway.
|
||||||
|
const REMEND_OPTIONS = { linkMode: "text-only" } as const;
|
||||||
|
|
||||||
|
// remend only ever runs on text that is still arriving. On finished text it can
|
||||||
|
// do damage: it reads `*$89*` as an unclosed italic (the `$` throws off its
|
||||||
|
// closing-delimiter scan) and appends a stray `*`, which then parses as an empty
|
||||||
|
// bullet. Prices in italics are ordinary storefront copy, so settled messages
|
||||||
|
// render verbatim and only the in-flight one gets repaired.
|
||||||
|
const repair = (markdown: string, isStreaming: boolean) =>
|
||||||
|
isStreaming ? remend(markdown, REMEND_OPTIONS) : markdown;
|
||||||
|
|
||||||
|
export interface LinkSafetyConfig {
|
||||||
|
enabled: boolean;
|
||||||
|
/** Return true for links that may open without a confirmation step. */
|
||||||
|
onLinkCheck?: (url: string) => boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type AnchorProps = ComponentProps<"a"> & {
|
||||||
|
linkSafety?: LinkSafetyConfig;
|
||||||
|
onUntrusted: (url: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LINK_CLASS =
|
||||||
|
"font-medium underline underline-offset-4 hover:text-foreground";
|
||||||
|
|
||||||
|
// Route-relative hrefs are the storefront links the assistant emits. Deciding
|
||||||
|
// this from the string alone keeps the server and client passes identical;
|
||||||
|
// `linkSafety.onLinkCheck` does the origin-aware check later, at click time.
|
||||||
|
const isRouteHref = (href: string) => /^[/#?]/.test(href);
|
||||||
|
|
||||||
|
const MarkdownLink = ({
|
||||||
|
href,
|
||||||
|
linkSafety,
|
||||||
|
onUntrusted,
|
||||||
|
...props
|
||||||
|
}: AnchorProps) => {
|
||||||
|
// Runs on click rather than on render so it can read `window.location`,
|
||||||
|
// which is unavailable during the server pass.
|
||||||
|
const handleClick = useCallback(
|
||||||
|
(event: MouseEvent<HTMLAnchorElement>) => {
|
||||||
|
if (!href || !linkSafety?.enabled || !linkSafety.onLinkCheck) return;
|
||||||
|
if (linkSafety.onLinkCheck(href)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
onUntrusted(href);
|
||||||
|
},
|
||||||
|
[href, linkSafety, onUntrusted]
|
||||||
|
);
|
||||||
|
|
||||||
|
// In-app destinations navigate client-side in the same tab; sending a shopper
|
||||||
|
// to a product page in a new tab would strand the conversation behind it.
|
||||||
|
if (href && isRouteHref(href)) {
|
||||||
|
return <Link className={LINK_CLASS} href={href} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
className={LINK_CLASS}
|
||||||
|
href={href}
|
||||||
|
onClick={handleClick}
|
||||||
|
rel="noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fenced code renders as plain preformatted text — no tokenizer, no themes.
|
||||||
|
const buildComponents = (
|
||||||
|
linkSafety: LinkSafetyConfig | undefined,
|
||||||
|
onUntrusted: (url: string) => void
|
||||||
|
): Partial<Components> => ({
|
||||||
|
a: (props: ComponentProps<"a">) => (
|
||||||
|
<MarkdownLink {...props} linkSafety={linkSafety} onUntrusted={onUntrusted} />
|
||||||
|
),
|
||||||
|
blockquote: (props: ComponentProps<"blockquote">) => (
|
||||||
|
<blockquote
|
||||||
|
className="my-3 border-border border-l-2 pl-3 text-muted-foreground"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
code: ({ className, ...props }: ComponentProps<"code">) => {
|
||||||
|
// Only fenced blocks carry a language class, and those already sit inside a
|
||||||
|
// <pre>, so they must not get the inline pill treatment.
|
||||||
|
const isBlock =
|
||||||
|
typeof className === "string" && className.includes("language-");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<code
|
||||||
|
className={cn(
|
||||||
|
isBlock
|
||||||
|
? "font-mono text-xs"
|
||||||
|
: "rounded bg-muted px-1 py-0.5 font-mono text-[0.85em]",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
em: (props: ComponentProps<"em">) => <em className="italic" {...props} />,
|
||||||
|
h1: (props: ComponentProps<"h1">) => (
|
||||||
|
<h1 className="mt-4 mb-2 font-semibold text-base" {...props} />
|
||||||
|
),
|
||||||
|
h2: (props: ComponentProps<"h2">) => (
|
||||||
|
<h2 className="mt-4 mb-2 font-semibold text-base" {...props} />
|
||||||
|
),
|
||||||
|
h3: (props: ComponentProps<"h3">) => (
|
||||||
|
<h3 className="mt-3 mb-1.5 font-semibold text-sm" {...props} />
|
||||||
|
),
|
||||||
|
h4: (props: ComponentProps<"h4">) => (
|
||||||
|
<h4 className="mt-3 mb-1.5 font-semibold text-sm" {...props} />
|
||||||
|
),
|
||||||
|
h5: (props: ComponentProps<"h5">) => (
|
||||||
|
<h5 className="mt-3 mb-1.5 font-semibold text-sm" {...props} />
|
||||||
|
),
|
||||||
|
h6: (props: ComponentProps<"h6">) => (
|
||||||
|
<h6 className="mt-3 mb-1.5 font-semibold text-sm" {...props} />
|
||||||
|
),
|
||||||
|
hr: (props: ComponentProps<"hr">) => (
|
||||||
|
<hr className="my-4 border-border" {...props} />
|
||||||
|
),
|
||||||
|
// GFM task-list boxes are display only; readOnly silences React's warning
|
||||||
|
// about a `checked` input with no change handler.
|
||||||
|
input: (props: ComponentProps<"input">) => (
|
||||||
|
<input className="mr-1.5 align-middle" readOnly {...props} />
|
||||||
|
),
|
||||||
|
img: ({ alt, ...props }: ComponentProps<"img">) => (
|
||||||
|
// biome-ignore lint/nursery/noImgElement: model output, not a known asset
|
||||||
|
<img alt={alt ?? ""} className="my-2 max-w-full rounded-md" {...props} />
|
||||||
|
),
|
||||||
|
li: (props: ComponentProps<"li">) => <li className="my-0.5" {...props} />,
|
||||||
|
ol: (props: ComponentProps<"ol">) => (
|
||||||
|
<ol className="my-2 list-decimal space-y-0.5 pl-5" {...props} />
|
||||||
|
),
|
||||||
|
p: (props: ComponentProps<"p">) => (
|
||||||
|
<p className="my-2 leading-relaxed" {...props} />
|
||||||
|
),
|
||||||
|
pre: (props: ComponentProps<"pre">) => (
|
||||||
|
<pre
|
||||||
|
className="my-2 overflow-x-auto rounded-md bg-muted p-3 text-xs"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
strong: (props: ComponentProps<"strong">) => (
|
||||||
|
<strong className="font-semibold" {...props} />
|
||||||
|
),
|
||||||
|
table: (props: ComponentProps<"table">) => (
|
||||||
|
<div className="my-3 overflow-x-auto">
|
||||||
|
<table className="w-full border-collapse text-left text-xs" {...props} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
td: (props: ComponentProps<"td">) => (
|
||||||
|
<td className="border border-border px-2 py-1" {...props} />
|
||||||
|
),
|
||||||
|
th: (props: ComponentProps<"th">) => (
|
||||||
|
<th
|
||||||
|
className="border border-border bg-muted px-2 py-1 font-medium"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
ul: (props: ComponentProps<"ul">) => (
|
||||||
|
<ul className="my-2 list-disc space-y-0.5 pl-5" {...props} />
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type MarkdownProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
||||||
|
children: string;
|
||||||
|
/** True while tokens are still arriving; enables incomplete-syntax repair. */
|
||||||
|
isAnimating?: boolean;
|
||||||
|
linkSafety?: LinkSafetyConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Markdown = memo(
|
||||||
|
({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
isAnimating,
|
||||||
|
linkSafety,
|
||||||
|
...props
|
||||||
|
}: MarkdownProps) => {
|
||||||
|
const [pending, setPending] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const handleUntrusted = useCallback((url: string) => setPending(url), []);
|
||||||
|
|
||||||
|
const content = useMemo(() => {
|
||||||
|
// While streaming, close syntax the model has not finished emitting so a
|
||||||
|
// partial `**bold` renders as bold rather than as literal asterisks.
|
||||||
|
const source = repair(children ?? "", isAnimating === true);
|
||||||
|
const tree = processor.runSync(processor.parse(source)) as Nodes;
|
||||||
|
|
||||||
|
return toJsxRuntime(tree, {
|
||||||
|
components: buildComponents(linkSafety, handleUntrusted),
|
||||||
|
Fragment,
|
||||||
|
jsx,
|
||||||
|
jsxs,
|
||||||
|
});
|
||||||
|
}, [children, isAnimating, linkSafety, handleUntrusted]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
<Dialog
|
||||||
|
onOpenChange={(open) => !open && setPending(null)}
|
||||||
|
open={pending !== null}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Leave this site?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
This link points somewhere outside the store. Continue only if
|
||||||
|
you trust it.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<p className="break-all rounded-md bg-muted px-3 py-2 font-mono text-xs">
|
||||||
|
{pending}
|
||||||
|
</p>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button onClick={() => setPending(null)} variant="outline">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
if (pending) {
|
||||||
|
window.open(pending, "_blank", "noopener,noreferrer");
|
||||||
|
}
|
||||||
|
setPending(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
(prev, next) =>
|
||||||
|
prev.children === next.children && prev.isAnimating === next.isAnimating
|
||||||
|
);
|
||||||
|
|
||||||
|
Markdown.displayName = "Markdown";
|
||||||
@@ -12,23 +12,19 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { cjk } from "@streamdown/cjk";
|
|
||||||
import { code } from "@streamdown/code";
|
|
||||||
import { math } from "@streamdown/math";
|
|
||||||
import { mermaid } from "@streamdown/mermaid";
|
|
||||||
import type { UIMessage } from "ai";
|
import type { UIMessage } from "ai";
|
||||||
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
||||||
import type { ComponentProps, HTMLAttributes, ReactElement } from "react";
|
import type { ComponentProps, HTMLAttributes, ReactElement } from "react";
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
memo,
|
|
||||||
useCallback,
|
useCallback,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { Streamdown } from "streamdown";
|
|
||||||
|
import { Markdown } from "./markdown";
|
||||||
|
|
||||||
export type MessageProps = HTMLAttributes<HTMLDivElement> & {
|
export type MessageProps = HTMLAttributes<HTMLDivElement> & {
|
||||||
from: UIMessage["role"];
|
from: UIMessage["role"];
|
||||||
@@ -319,27 +315,10 @@ export const MessageBranchPage = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MessageResponseProps = ComponentProps<typeof Streamdown>;
|
export type MessageResponseProps = ComponentProps<typeof Markdown>;
|
||||||
|
|
||||||
const streamdownPlugins = { cjk, code, math, mermaid };
|
// Markdown already memoises on children/isAnimating.
|
||||||
|
export const MessageResponse = Markdown;
|
||||||
export const MessageResponse = memo(
|
|
||||||
({ className, ...props }: MessageResponseProps) => (
|
|
||||||
<Streamdown
|
|
||||||
className={cn(
|
|
||||||
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
plugins={streamdownPlugins}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
(prevProps, nextProps) =>
|
|
||||||
prevProps.children === nextProps.children &&
|
|
||||||
nextProps.isAnimating === prevProps.isAnimating
|
|
||||||
);
|
|
||||||
|
|
||||||
MessageResponse.displayName = "MessageResponse";
|
|
||||||
|
|
||||||
export type MessageToolbarProps = ComponentProps<"div">;
|
export type MessageToolbarProps = ComponentProps<"div">;
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ import {
|
|||||||
CollapsibleTrigger,
|
CollapsibleTrigger,
|
||||||
} from "@/components/ui/collapsible";
|
} from "@/components/ui/collapsible";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { cjk } from "@streamdown/cjk";
|
|
||||||
import { code } from "@streamdown/code";
|
|
||||||
import { math } from "@streamdown/math";
|
|
||||||
import { mermaid } from "@streamdown/mermaid";
|
|
||||||
import { BrainIcon, ChevronDownIcon } from "lucide-react";
|
import { BrainIcon, ChevronDownIcon } from "lucide-react";
|
||||||
import type { ComponentProps, ReactNode } from "react";
|
import type { ComponentProps, ReactNode } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -23,8 +19,8 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { Streamdown } from "streamdown";
|
|
||||||
|
|
||||||
|
import { Markdown } from "./markdown";
|
||||||
import { Shimmer } from "./shimmer";
|
import { Shimmer } from "./shimmer";
|
||||||
|
|
||||||
interface ReasoningContextValue {
|
interface ReasoningContextValue {
|
||||||
@@ -204,21 +200,23 @@ export type ReasoningContentProps = ComponentProps<
|
|||||||
children: string;
|
children: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const streamdownPlugins = { cjk, code, math, mermaid };
|
|
||||||
|
|
||||||
export const ReasoningContent = memo(
|
export const ReasoningContent = memo(
|
||||||
({ className, children, ...props }: ReasoningContentProps) => (
|
({ className, children, ...props }: ReasoningContentProps) => {
|
||||||
<CollapsibleContent
|
const { isStreaming } = useReasoning();
|
||||||
className={cn(
|
|
||||||
"mt-4 text-sm",
|
return (
|
||||||
"data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
|
<CollapsibleContent
|
||||||
className
|
className={cn(
|
||||||
)}
|
"mt-4 text-sm",
|
||||||
{...props}
|
"data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
|
||||||
>
|
className
|
||||||
<Streamdown plugins={streamdownPlugins}>{children}</Streamdown>
|
)}
|
||||||
</CollapsibleContent>
|
{...props}
|
||||||
)
|
>
|
||||||
|
<Markdown isAnimating={isStreaming}>{children}</Markdown>
|
||||||
|
</CollapsibleContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Reasoning.displayName = "Reasoning";
|
Reasoning.displayName = "Reasoning";
|
||||||
|
|||||||
@@ -1,173 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import {
|
|
||||||
Collapsible,
|
|
||||||
CollapsibleContent,
|
|
||||||
CollapsibleTrigger,
|
|
||||||
} from "@/components/ui/collapsible";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
import type { DynamicToolUIPart, ToolUIPart } from "ai";
|
|
||||||
import {
|
|
||||||
CheckCircleIcon,
|
|
||||||
ChevronDownIcon,
|
|
||||||
CircleIcon,
|
|
||||||
ClockIcon,
|
|
||||||
WrenchIcon,
|
|
||||||
XCircleIcon,
|
|
||||||
} from "lucide-react";
|
|
||||||
import type { ComponentProps, ReactNode } from "react";
|
|
||||||
import { isValidElement } from "react";
|
|
||||||
|
|
||||||
import { CodeBlock } from "./code-block";
|
|
||||||
|
|
||||||
export type ToolProps = ComponentProps<typeof Collapsible>;
|
|
||||||
|
|
||||||
export const Tool = ({ className, ...props }: ToolProps) => (
|
|
||||||
<Collapsible
|
|
||||||
className={cn("group not-prose mb-4 w-full rounded-md border", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
export type ToolPart = ToolUIPart | DynamicToolUIPart;
|
|
||||||
|
|
||||||
export type ToolHeaderProps = {
|
|
||||||
title?: string;
|
|
||||||
className?: string;
|
|
||||||
} & (
|
|
||||||
| { type: ToolUIPart["type"]; state: ToolUIPart["state"]; toolName?: never }
|
|
||||||
| {
|
|
||||||
type: DynamicToolUIPart["type"];
|
|
||||||
state: DynamicToolUIPart["state"];
|
|
||||||
toolName: string;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const statusLabels: Record<ToolPart["state"], string> = {
|
|
||||||
"approval-requested": "Awaiting Approval",
|
|
||||||
"approval-responded": "Responded",
|
|
||||||
"input-available": "Running",
|
|
||||||
"input-streaming": "Pending",
|
|
||||||
"output-available": "Completed",
|
|
||||||
"output-denied": "Denied",
|
|
||||||
"output-error": "Error",
|
|
||||||
};
|
|
||||||
|
|
||||||
const statusIcons: Record<ToolPart["state"], ReactNode> = {
|
|
||||||
"approval-requested": <ClockIcon className="size-4 text-yellow-600" />,
|
|
||||||
"approval-responded": <CheckCircleIcon className="size-4 text-blue-600" />,
|
|
||||||
"input-available": <ClockIcon className="size-4 animate-pulse" />,
|
|
||||||
"input-streaming": <CircleIcon className="size-4" />,
|
|
||||||
"output-available": <CheckCircleIcon className="size-4 text-green-600" />,
|
|
||||||
"output-denied": <XCircleIcon className="size-4 text-orange-600" />,
|
|
||||||
"output-error": <XCircleIcon className="size-4 text-red-600" />,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getStatusBadge = (status: ToolPart["state"]) => (
|
|
||||||
<Badge className="gap-1.5 rounded-full text-xs" variant="secondary">
|
|
||||||
{statusIcons[status]}
|
|
||||||
{statusLabels[status]}
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const ToolHeader = ({
|
|
||||||
className,
|
|
||||||
title,
|
|
||||||
type,
|
|
||||||
state,
|
|
||||||
toolName,
|
|
||||||
...props
|
|
||||||
}: ToolHeaderProps) => {
|
|
||||||
const derivedName =
|
|
||||||
type === "dynamic-tool" ? toolName : type.split("-").slice(1).join("-");
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CollapsibleTrigger
|
|
||||||
className={cn(
|
|
||||||
"flex w-full items-center justify-between gap-4 p-3",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<WrenchIcon className="size-4 text-muted-foreground" />
|
|
||||||
<span className="font-medium text-sm">{title ?? derivedName}</span>
|
|
||||||
{getStatusBadge(state)}
|
|
||||||
</div>
|
|
||||||
<ChevronDownIcon className="size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" />
|
|
||||||
</CollapsibleTrigger>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ToolContentProps = ComponentProps<typeof CollapsibleContent>;
|
|
||||||
|
|
||||||
export const ToolContent = ({ className, ...props }: ToolContentProps) => (
|
|
||||||
<CollapsibleContent
|
|
||||||
className={cn(
|
|
||||||
"data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 space-y-4 p-4 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
export type ToolInputProps = ComponentProps<"div"> & {
|
|
||||||
input: ToolPart["input"];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ToolInput = ({ className, input, ...props }: ToolInputProps) => (
|
|
||||||
<div className={cn("space-y-2 overflow-hidden", className)} {...props}>
|
|
||||||
<h4 className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
|
|
||||||
Parameters
|
|
||||||
</h4>
|
|
||||||
<div className="rounded-md bg-muted/50">
|
|
||||||
<CodeBlock code={JSON.stringify(input, null, 2)} language="json" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
export type ToolOutputProps = ComponentProps<"div"> & {
|
|
||||||
output: ToolPart["output"];
|
|
||||||
errorText: ToolPart["errorText"];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ToolOutput = ({
|
|
||||||
className,
|
|
||||||
output,
|
|
||||||
errorText,
|
|
||||||
...props
|
|
||||||
}: ToolOutputProps) => {
|
|
||||||
if (!(output || errorText)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Output = <div>{output as ReactNode}</div>;
|
|
||||||
|
|
||||||
if (typeof output === "object" && !isValidElement(output)) {
|
|
||||||
Output = (
|
|
||||||
<CodeBlock code={JSON.stringify(output, null, 2)} language="json" />
|
|
||||||
);
|
|
||||||
} else if (typeof output === "string") {
|
|
||||||
Output = <CodeBlock code={output} language="json" />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={cn("space-y-2", className)} {...props}>
|
|
||||||
<h4 className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
|
|
||||||
{errorText ? "Error" : "Result"}
|
|
||||||
</h4>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
"overflow-x-auto rounded-md text-xs [&_table]:w-full",
|
|
||||||
errorText
|
|
||||||
? "bg-destructive/10 text-destructive"
|
|
||||||
: "bg-muted/50 text-foreground"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{errorText && <div>{errorText}</div>}
|
|
||||||
{Output}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
interface LogoProps {
|
||||||
|
/** Logo image URL. Falls back to the store name as a wordmark when absent. */
|
||||||
|
src?: string | null;
|
||||||
|
/** Wordmark text, and the image's alt text. */
|
||||||
|
storeName?: string;
|
||||||
|
/** Where the logo links to. Pass null to render it unwrapped. */
|
||||||
|
href?: string | null;
|
||||||
|
/** Sizing for the image — height only, so the aspect ratio is preserved. */
|
||||||
|
imageClassName?: string;
|
||||||
|
/** Sizing and weight for the wordmark fallback. */
|
||||||
|
textClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Logo: React.FC<LogoProps> = ({
|
||||||
|
src,
|
||||||
|
storeName = 'Shop',
|
||||||
|
href = '/',
|
||||||
|
imageClassName = 'h-6',
|
||||||
|
textClassName = 'text-xl',
|
||||||
|
}) => {
|
||||||
|
const mark = src ? (
|
||||||
|
<img
|
||||||
|
src={src}
|
||||||
|
alt={storeName}
|
||||||
|
className={`w-auto object-contain ${imageClassName}`}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span
|
||||||
|
className={`font-medium tracking-tight text-foreground ${textClassName}`}
|
||||||
|
>
|
||||||
|
{storeName}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (href === null) {
|
||||||
|
return <span className="flex items-center">{mark}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link href={href} className="flex items-center">
|
||||||
|
{mark}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Logo;
|
||||||
@@ -4,7 +4,7 @@ import React, { useState } from 'react';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
|
|
||||||
export interface AccountFormField {
|
export interface AccountFormField {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useCartStore, redirectToCheckout } from '@/hooks/use-shopify-cart';
|
import { useCartStore, redirectToCheckout } from '@/hooks/use-shopify-cart';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
import {
|
import {
|
||||||
Sheet,
|
Sheet,
|
||||||
SheetContent,
|
SheetContent,
|
||||||
@@ -25,6 +25,7 @@ import {
|
|||||||
EmptyDescription,
|
EmptyDescription,
|
||||||
EmptyContent,
|
EmptyContent,
|
||||||
} from '@/components/ui/empty';
|
} from '@/components/ui/empty';
|
||||||
|
import { isDefaultTitleSelection } from '@/services/shopify/catalog';
|
||||||
|
|
||||||
const CartDrawer: React.FC = () => {
|
const CartDrawer: React.FC = () => {
|
||||||
const isOpen = useCartStore((s) => s.isOpen);
|
const isOpen = useCartStore((s) => s.isOpen);
|
||||||
@@ -102,7 +103,10 @@ const CartDrawer: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getSelectedOptions = (item: (typeof items)[0]) => {
|
const getSelectedOptions = (item: (typeof items)[0]) => {
|
||||||
return item.merchandise.selectedOptions ?? [];
|
// Single-SKU items carry a synthetic `Title: Default Title` — not worth a line.
|
||||||
|
return (item.merchandise.selectedOptions ?? []).filter(
|
||||||
|
(option) => !isDefaultTitleSelection(option)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import ProductCard from './product-card';
|
|||||||
import ProductFilters, { type ProductFilterFacet } from './product-filters';
|
import ProductFilters, { type ProductFilterFacet } from './product-filters';
|
||||||
import ProductToolbar from './product-toolbar';
|
import ProductToolbar from './product-toolbar';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
import {
|
import {
|
||||||
getCollectionProductsPage,
|
getCollectionProductsPage,
|
||||||
type CollectionSortKey,
|
type CollectionSortKey,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
RiTiktokLine,
|
RiTiktokLine,
|
||||||
RiFacebookFill,
|
RiFacebookFill,
|
||||||
} from '@remixicon/react';
|
} from '@remixicon/react';
|
||||||
|
import Logo from '@/components/logo';
|
||||||
|
|
||||||
export interface FooterLink {
|
export interface FooterLink {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -12,6 +13,7 @@ export interface FooterLink {
|
|||||||
|
|
||||||
interface FooterProps {
|
interface FooterProps {
|
||||||
storeName?: string;
|
storeName?: string;
|
||||||
|
logoUrl?: string;
|
||||||
copyright?: string;
|
copyright?: string;
|
||||||
links?: FooterLink[];
|
links?: FooterLink[];
|
||||||
instagramUrl?: string;
|
instagramUrl?: string;
|
||||||
@@ -21,6 +23,7 @@ interface FooterProps {
|
|||||||
|
|
||||||
const Footer: React.FC<FooterProps> = ({
|
const Footer: React.FC<FooterProps> = ({
|
||||||
storeName = 'Shop',
|
storeName = 'Shop',
|
||||||
|
logoUrl,
|
||||||
copyright,
|
copyright,
|
||||||
links = [
|
links = [
|
||||||
{ label: 'Terms of Service', url: '/policies/terms-of-service' },
|
{ label: 'Terms of Service', url: '/policies/terms-of-service' },
|
||||||
@@ -46,6 +49,13 @@ const Footer: React.FC<FooterProps> = ({
|
|||||||
assistant launcher. Links and socials sit on separate rows so the
|
assistant launcher. Links and socials sit on separate rows so the
|
||||||
icons aren't crammed onto the end of the link list. */}
|
icons aren't crammed onto the end of the link list. */}
|
||||||
<div className="flex flex-col items-center gap-y-5 sm:items-start">
|
<div className="flex flex-col items-center gap-y-5 sm:items-start">
|
||||||
|
<Logo
|
||||||
|
src={logoUrl}
|
||||||
|
storeName={storeName}
|
||||||
|
imageClassName="h-5"
|
||||||
|
textClassName="text-base"
|
||||||
|
/>
|
||||||
|
|
||||||
<nav className="flex flex-wrap items-center justify-center gap-x-5 gap-y-2 sm:justify-start">
|
<nav className="flex flex-wrap items-center justify-center gap-x-5 gap-y-2 sm:justify-start">
|
||||||
{links.map((link) => (
|
{links.map((link) => (
|
||||||
<a
|
<a
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import { useCartStore } from '@/hooks/use-shopify-cart';
|
|||||||
import CartDrawer from '@/components/shopify/cart-drawer';
|
import CartDrawer from '@/components/shopify/cart-drawer';
|
||||||
import SearchDialog from '@/components/shopify/search-dialog';
|
import SearchDialog from '@/components/shopify/search-dialog';
|
||||||
import AccountMenu from '@/components/shopify/account-menu';
|
import AccountMenu from '@/components/shopify/account-menu';
|
||||||
|
import ShopMenu from '@/components/shopify/shop-menu';
|
||||||
import { RiShoppingBagLine, RiCloseLine, RiMenu3Line } from '@remixicon/react';
|
import { RiShoppingBagLine, RiCloseLine, RiMenu3Line } from '@remixicon/react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import Logo from '@/components/logo';
|
||||||
|
|
||||||
const CartIcon: React.FC = () => {
|
const CartIcon: React.FC = () => {
|
||||||
const toggleCart = useCartStore((s) => s.toggleCart);
|
const toggleCart = useCartStore((s) => s.toggleCart);
|
||||||
@@ -63,7 +65,7 @@ const Header: React.FC<HeaderProps> = ({
|
|||||||
<>
|
<>
|
||||||
{/* Sits above the sticky nav, so it scrolls away on its own. */}
|
{/* Sits above the sticky nav, so it scrolls away on its own. */}
|
||||||
{announcement && (
|
{announcement && (
|
||||||
<div className="bg-foreground text-background">
|
<div className="bg-muted text-foreground">
|
||||||
<div className="max-w-screen-2xl mx-auto flex h-9 items-center justify-center px-8 text-center text-xs">
|
<div className="max-w-screen-2xl mx-auto flex h-9 items-center justify-center px-8 text-center text-xs">
|
||||||
{announcementUrl ? (
|
{announcementUrl ? (
|
||||||
<Link
|
<Link
|
||||||
@@ -83,22 +85,11 @@ const Header: React.FC<HeaderProps> = ({
|
|||||||
<div className="max-w-screen-2xl mx-auto px-8">
|
<div className="max-w-screen-2xl mx-auto px-8">
|
||||||
<div className="flex justify-between items-center h-14">
|
<div className="flex justify-between items-center h-14">
|
||||||
{/* Logo */}
|
{/* Logo */}
|
||||||
<Link href="/" className="flex items-center">
|
<Logo src={logoUrl} storeName={storeName} />
|
||||||
{logoUrl ? (
|
|
||||||
<img
|
|
||||||
src={logoUrl}
|
|
||||||
alt={storeName}
|
|
||||||
className="h-6 w-auto object-contain"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<span className="text-xl font-medium tracking-tight text-foreground">
|
|
||||||
{storeName}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
{/* Desktop Navigation */}
|
{/* Desktop Navigation */}
|
||||||
<div className="hidden md:flex items-center gap-x-8 text-sm">
|
<div className="hidden md:flex items-center gap-x-8 text-sm">
|
||||||
|
<ShopMenu />
|
||||||
{links.map((link, index) => (
|
{links.map((link, index) => (
|
||||||
<Link
|
<Link
|
||||||
key={index}
|
key={index}
|
||||||
@@ -138,6 +129,7 @@ const Header: React.FC<HeaderProps> = ({
|
|||||||
{menuOpen && (
|
{menuOpen && (
|
||||||
<div className="md:hidden bg-background">
|
<div className="md:hidden bg-background">
|
||||||
<div className="max-w-screen-2xl mx-auto px-8 pb-6 flex flex-col gap-y-4 text-sm">
|
<div className="max-w-screen-2xl mx-auto px-8 pb-6 flex flex-col gap-y-4 text-sm">
|
||||||
|
<ShopMenu mobile onNavigate={() => setMenuOpen(false)} />
|
||||||
{links.map((link, index) => (
|
{links.map((link, index) => (
|
||||||
<Link
|
<Link
|
||||||
key={index}
|
key={index}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
import { RiSubtractLine, RiAddLine } from '@remixicon/react';
|
import { RiSubtractLine, RiAddLine } from '@remixicon/react';
|
||||||
import ShopPayButton from '@/components/shopify/shop-pay-button';
|
import ShopPayButton from '@/components/shopify/shop-pay-button';
|
||||||
import type { ProductOption, ProductOptionValue } from '@/hooks/use-shopify-products';
|
import type { ProductOption, ProductOptionValue } from '@/hooks/use-shopify-products';
|
||||||
import { isSwatchOptionName, swatchColorForName } from '@/config/swatches';
|
import { isSwatchOptionName, swatchColorForName } from '@/config/swatches';
|
||||||
|
import { isDefaultTitleOption } from '@/services/shopify/catalog';
|
||||||
|
|
||||||
interface ProductPrice {
|
interface ProductPrice {
|
||||||
amount: string;
|
amount: string;
|
||||||
@@ -103,9 +104,10 @@ const ProductDetailInfo: React.FC<ProductDetailInfoProps> = ({
|
|||||||
isSwatchOptionName(option.name);
|
isSwatchOptionName(option.name);
|
||||||
|
|
||||||
// Some products return Size before Color; show the swatches first either way.
|
// Some products return Size before Color; show the swatches first either way.
|
||||||
const orderedOptions = [...(product.options ?? [])].sort(
|
// Single-SKU products expose a synthetic `Title: Default Title` option — drop it.
|
||||||
(a, b) => Number(isSwatchOption(b)) - Number(isSwatchOption(a))
|
const orderedOptions = [...(product.options ?? [])]
|
||||||
);
|
.filter((option) => !isDefaultTitleOption(option))
|
||||||
|
.sort((a, b) => Number(isSwatchOption(b)) - Number(isSwatchOption(a)));
|
||||||
|
|
||||||
// `optionValues` carries the swatch data; fall back to plain `values`.
|
// `optionValues` carries the swatch data; fall back to plain `values`.
|
||||||
const optionValuesFor = (option: ProductOption): ProductOptionValue[] =>
|
const optionValuesFor = (option: ProductOption): ProductOptionValue[] =>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import ProductCard from './product-card';
|
import ProductCard from './product-card';
|
||||||
import { getProductsPage } from '@/hooks/use-shopify-products';
|
import { getProductsPage } from '@/hooks/use-shopify-products';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
|
|
||||||
interface ProductImage {
|
interface ProductImage {
|
||||||
url: string;
|
url: string;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
CommandItem,
|
CommandItem,
|
||||||
} from '@/components/ui/command';
|
} from '@/components/ui/command';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
import { RiSearchLine, RiImageLine, RiCloseLine } from '@remixicon/react';
|
import { RiSearchLine, RiImageLine, RiCloseLine } from '@remixicon/react';
|
||||||
import {
|
import {
|
||||||
searchSuggestions,
|
searchSuggestions,
|
||||||
@@ -111,7 +111,7 @@ const SearchDialog: React.FC = () => {
|
|||||||
if (event.key === 'Enter') goToSearchPage();
|
if (event.key === 'Enter') goToSearchPage();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div className="absolute right-2 top-0 flex h-9 items-center gap-1">
|
<div className="absolute right-2 top-0 flex h-12 items-center gap-1">
|
||||||
{hasQuery && (
|
{hasQuery && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setTerm('')}
|
onClick={() => setTerm('')}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import ProductCard from './product-card';
|
|||||||
import ProductFilters from './product-filters';
|
import ProductFilters from './product-filters';
|
||||||
import ProductToolbar from './product-toolbar';
|
import ProductToolbar from './product-toolbar';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
import {
|
import {
|
||||||
searchProducts,
|
searchProducts,
|
||||||
type SearchFilter,
|
type SearchFilter,
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { RiArrowDownSLine } from '@remixicon/react';
|
||||||
|
import { useCollectionsOnDemand } from '@/hooks/use-shopify-collections';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface ShopMenuProps {
|
||||||
|
label?: string;
|
||||||
|
/** Renders inline inside the mobile menu instead of as a floating panel. */
|
||||||
|
mobile?: boolean;
|
||||||
|
/** Fires after a collection is picked, so the mobile menu can close itself. */
|
||||||
|
onNavigate?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ShopMenu: React.FC<ShopMenuProps> = ({
|
||||||
|
label = 'Shop',
|
||||||
|
mobile = false,
|
||||||
|
onNavigate,
|
||||||
|
}) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const { collections, loading, error, load } = useCollectionsOnDemand();
|
||||||
|
|
||||||
|
// The collection list is only worth fetching once someone opens the menu.
|
||||||
|
const toggle = () => {
|
||||||
|
const next = !open;
|
||||||
|
setOpen(next);
|
||||||
|
if (next) load();
|
||||||
|
};
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
setOpen(false);
|
||||||
|
onNavigate?.();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Escape') setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const itemClasses = cn(
|
||||||
|
'block text-sm text-foreground hover:bg-accent transition-colors',
|
||||||
|
mobile ? 'px-3 py-2' : 'px-4 py-2'
|
||||||
|
);
|
||||||
|
|
||||||
|
const body = (
|
||||||
|
<>
|
||||||
|
{loading &&
|
||||||
|
Array.from({ length: 5 }).map((_, index) => (
|
||||||
|
<div key={index} className={cn(itemClasses, 'py-2.5')}>
|
||||||
|
<div className="h-3 w-2/3 animate-pulse bg-muted" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className={cn(itemClasses, 'hover:bg-transparent')}>
|
||||||
|
<p className="text-muted-foreground">{error}</p>
|
||||||
|
<button
|
||||||
|
onClick={load}
|
||||||
|
className="mt-1 underline underline-offset-2 hover:text-muted-foreground"
|
||||||
|
>
|
||||||
|
Try again
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!loading && !error && collections.length === 0 && (
|
||||||
|
<p className={cn(itemClasses, 'text-muted-foreground hover:bg-transparent')}>
|
||||||
|
No collections yet.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{collections.map((collection) => (
|
||||||
|
<Link
|
||||||
|
key={collection.id}
|
||||||
|
href={`/collections/${collection.handle}`}
|
||||||
|
onClick={close}
|
||||||
|
className={itemClasses}
|
||||||
|
>
|
||||||
|
{collection.title}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{collections.length > 0 && (
|
||||||
|
<>
|
||||||
|
<div className="my-1 h-px bg-border" />
|
||||||
|
<Link
|
||||||
|
href="/collections"
|
||||||
|
onClick={close}
|
||||||
|
className={cn(itemClasses, 'text-muted-foreground')}
|
||||||
|
>
|
||||||
|
View all collections
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const trigger = (
|
||||||
|
<button
|
||||||
|
onClick={toggle}
|
||||||
|
aria-expanded={open}
|
||||||
|
className={cn(
|
||||||
|
'flex items-center gap-x-1 text-foreground hover:text-muted-foreground transition-colors',
|
||||||
|
mobile && 'w-full justify-between'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<span>{label}</span>
|
||||||
|
<RiArrowDownSLine
|
||||||
|
className={cn('size-4 transition-transform', open && 'rotate-180')}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (mobile) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{trigger}
|
||||||
|
{open && (
|
||||||
|
<div className="mt-2 flex flex-col border-l border-border pl-1">
|
||||||
|
{body}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative">
|
||||||
|
{trigger}
|
||||||
|
|
||||||
|
{open && (
|
||||||
|
<>
|
||||||
|
{/* Catches the click that dismisses the panel. */}
|
||||||
|
<div className="fixed inset-0 z-40" onClick={() => setOpen(false)} />
|
||||||
|
<div className="absolute left-0 top-full z-50 mt-2 max-h-[70vh] w-64 overflow-y-auto rounded-md border border-border bg-background py-1 shadow-md">
|
||||||
|
{body}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ShopMenu;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { SHOPIFY_STORE_DOMAIN } from '@/services/shopify/client';
|
import { SHOPIFY_STORE_DOMAIN } from '@/services/shopify/client';
|
||||||
import ShopPayLogo from '@/components/shopify/shop-pay-logo';
|
import ShopPayLogo from '@/components/shopify/shop-pay-logo';
|
||||||
import { Loader } from '@/app/components/ui/loader';
|
import { Loader } from '@/components/ui/loader';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
export interface ShopPayVariant {
|
export interface ShopPayVariant {
|
||||||
|
|||||||
@@ -393,6 +393,11 @@ const StoreAssistant: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<MessageResponse
|
<MessageResponse
|
||||||
key={index}
|
key={index}
|
||||||
|
// Only repair half-written markdown while it streams;
|
||||||
|
// settled text is rendered exactly as sent.
|
||||||
|
isAnimating={
|
||||||
|
status === 'streaming' && part.state === 'streaming'
|
||||||
|
}
|
||||||
linkSafety={{
|
linkSafety={{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
onLinkCheck: isInternalLink,
|
onLinkCheck: isInternalLink,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ function Command({
|
|||||||
data-slot="command"
|
data-slot="command"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
||||||
|
"transition-none animate-none",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -53,7 +54,13 @@ function CommandDialog({
|
|||||||
<DialogDescription>{description}</DialogDescription>
|
<DialogDescription>{description}</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className={cn("overflow-hidden p-0", className)}
|
className={cn(
|
||||||
|
"overflow-hidden p-0",
|
||||||
|
// No fade/zoom on the command palette — it should appear instantly.
|
||||||
|
"transition-none animate-none duration-0",
|
||||||
|
"data-[state=closed]:animate-none data-[state=open]:animate-none",
|
||||||
|
className
|
||||||
|
)}
|
||||||
showCloseButton={showCloseButton}
|
showCloseButton={showCloseButton}
|
||||||
>
|
>
|
||||||
<Command shouldFilter={shouldFilter} className="**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[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 shouldFilter={shouldFilter} className="**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[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">
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import type { NavLink } from '@/components/shopify/header';
|
||||||
|
|
||||||
|
/** Chrome shared by every route — rendered once in the root layout. */
|
||||||
|
export const site = {
|
||||||
|
storeName: 'Shop',
|
||||||
|
logoUrl: '',
|
||||||
|
copyright: '© 2026 Shop. All rights reserved.',
|
||||||
|
navLinks: [
|
||||||
|
{ label: 'Products', url: '/' },
|
||||||
|
{ label: 'Collections', url: '/collections' },
|
||||||
|
] as NavLink[],
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||||
import {
|
import {
|
||||||
getCollections,
|
getCollections,
|
||||||
getCollectionProducts,
|
getCollectionProducts,
|
||||||
@@ -60,6 +60,36 @@ export function useCollections(first = 50) {
|
|||||||
return { collections, loading, error, refetch: fetchCollections };
|
return { collections, loading, error, refetch: fetchCollections };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deferred variant of useCollections: nothing is requested until `load` runs,
|
||||||
|
// so a menu can hold off until it's actually opened. The fetch happens once —
|
||||||
|
// re-opening reuses what's already in state.
|
||||||
|
export function useCollectionsOnDemand(first = 50) {
|
||||||
|
const [collections, setCollections] = useState<Collection[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const requested = useRef(false);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
if (requested.current) return;
|
||||||
|
requested.current = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
setCollections(await getCollections(first));
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching collections:', err);
|
||||||
|
// Let the next open (or a retry) try again.
|
||||||
|
requested.current = false;
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to load collections');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [first]);
|
||||||
|
|
||||||
|
return { collections, loading, error, load };
|
||||||
|
}
|
||||||
|
|
||||||
// Hook for fetching products in a collection
|
// Hook for fetching products in a collection
|
||||||
export function useCollectionProducts(
|
export function useCollectionProducts(
|
||||||
handle: string | null,
|
handle: string | null,
|
||||||
|
|||||||
+10
-9
@@ -12,20 +12,17 @@
|
|||||||
"@ai-sdk/react": "^4.0.47",
|
"@ai-sdk/react": "^4.0.47",
|
||||||
"@next/swc-wasm-web": "16.2.10",
|
"@next/swc-wasm-web": "16.2.10",
|
||||||
"@openrouter/ai-sdk-provider": "^3.0.0",
|
"@openrouter/ai-sdk-provider": "^3.0.0",
|
||||||
|
"@radix-ui/react-slot": "^1.3.3",
|
||||||
"@radix-ui/react-use-controllable-state": "^1.2.6",
|
"@radix-ui/react-use-controllable-state": "^1.2.6",
|
||||||
"@remixicon/react": "^4.9.0",
|
"@remixicon/react": "^4.9.0",
|
||||||
"@shopify/storefront-api-client": "^1.0.0",
|
"@shopify/storefront-api-client": "^1.0.0",
|
||||||
"@streamdown/cjk": "^1.0.3",
|
|
||||||
"@streamdown/code": "^1.1.1",
|
|
||||||
"@streamdown/math": "^1.0.2",
|
|
||||||
"@streamdown/mermaid": "^1.0.2",
|
|
||||||
"@supabase/supabase-js": "^2.51.0",
|
|
||||||
"ai": "^7",
|
"ai": "^7",
|
||||||
"class-variance-authority": "0.7.1",
|
"class-variance-authority": "0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "^1.1.1",
|
"cmdk": "^1.1.1",
|
||||||
"embla-carousel-react": "^8.6.0",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"framer-motion": "12.42.2",
|
"framer-motion": "12.42.2",
|
||||||
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
||||||
"input-otp": "^1.4.2",
|
"input-otp": "^1.4.2",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
"motion": "^12.23.26",
|
"motion": "^12.23.26",
|
||||||
@@ -34,22 +31,26 @@
|
|||||||
"radix-ui": "^1.6.7",
|
"radix-ui": "^1.6.7",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"shiki": "^3.19.0",
|
"rehype-sanitize": "^6.0.0",
|
||||||
|
"remark-gfm": "^4.0.1",
|
||||||
|
"remark-parse": "^11.0.0",
|
||||||
|
"remark-rehype": "^11.1.2",
|
||||||
|
"remend": "^1.3.0",
|
||||||
"sonner": "^2.0.7",
|
"sonner": "^2.0.7",
|
||||||
"streamdown": "^2.5.0",
|
|
||||||
"tailwind-merge": "^3.4.0",
|
"tailwind-merge": "^3.4.0",
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"tw-animate-css": "1.4.0",
|
"tw-animate-css": "1.4.0",
|
||||||
|
"unified": "^11.0.5",
|
||||||
"use-stick-to-bottom": "^1.1.6",
|
"use-stick-to-bottom": "^1.1.6",
|
||||||
"zod": "^4.4.3",
|
"zod": "^4.4.3",
|
||||||
"zustand": "^5.0.11"
|
"zustand": "^5.0.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
|
"@types/hast": "^3.0.5",
|
||||||
"@types/node": "^22",
|
"@types/node": "^22",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
},
|
}
|
||||||
"packageManager": "yarn@4.18.0+sha512.fcb8716fe7cd0eece141ffc18b92193a9df9204c1ba83189c288835223fc0bbe64af473bab0d5e9927a7daeb5caf2bb07eb2787cc9338ca040ea125f2a1f2f7e"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,25 @@ export interface ProductOption {
|
|||||||
optionValues?: ProductOptionValue[];
|
optionValues?: ProductOptionValue[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single-variant products still carry one synthetic option — `Title` with the
|
||||||
|
* lone value `Default Title`. It isn't a real choice, so keep it out of the UI.
|
||||||
|
*/
|
||||||
|
export const isDefaultTitleOption = (option: {
|
||||||
|
name: string;
|
||||||
|
values: string[];
|
||||||
|
}): boolean =>
|
||||||
|
option.name === 'Title' &&
|
||||||
|
option.values.length === 1 &&
|
||||||
|
option.values[0] === 'Default Title';
|
||||||
|
|
||||||
|
/** Same synthetic option, as it appears on a variant's `selectedOptions`. */
|
||||||
|
export const isDefaultTitleSelection = (selection: {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}): boolean =>
|
||||||
|
selection.name === 'Title' && selection.value === 'Default Title';
|
||||||
|
|
||||||
export interface Product {
|
export interface Product {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user