doccupine 0.0.157 → 0.0.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -2
- package/dist/generator/app-scaffolder.js +11 -3
- package/dist/generator/generated-page-publisher.d.ts +6 -6
- package/dist/generator/generated-page-publisher.js +7 -5
- package/dist/generator/icon-registry-generator.d.ts +8 -5
- package/dist/generator/icon-registry-generator.js +19 -11
- package/dist/generator/mdx-pass-builder.d.ts +4 -4
- package/dist/generator/mdx-pass-builder.js +8 -1
- package/dist/generator/mdx-reconciliation-coordinator.d.ts +23 -9
- package/dist/generator/mdx-reconciliation-coordinator.js +63 -9
- package/dist/generator/page-catalog.d.ts +2 -4
- package/dist/generator/page-catalog.js +7 -2
- package/dist/generator/page-renderer.d.ts +15 -5
- package/dist/generator/page-renderer.js +38 -11
- package/dist/generator/project-config-repository.d.ts +4 -1
- package/dist/generator/project-config-repository.js +26 -0
- package/dist/generator/public-asset-manager.d.ts +10 -0
- package/dist/generator/public-asset-manager.js +63 -3
- package/dist/generator/section-index-generator.d.ts +10 -1
- package/dist/generator/section-index-generator.js +43 -15
- package/dist/generator/section-resolver.d.ts +8 -0
- package/dist/generator/site-artifacts.d.ts +4 -3
- package/dist/generator/site-artifacts.js +94 -9
- package/dist/generator/watch-coordinator.js +6 -1
- package/dist/lib/generated-artifacts.d.ts +3 -0
- package/dist/lib/generated-artifacts.js +36 -0
- package/dist/lib/icon-registry.d.ts +10 -4
- package/dist/lib/icon-registry.js +13 -4
- package/dist/lib/layout.d.ts +6 -3
- package/dist/lib/layout.js +107 -4
- package/dist/lib/metadata.d.ts +7 -0
- package/dist/lib/metadata.js +33 -10
- package/dist/lib/structures.js +20 -0
- package/dist/lib/types.d.ts +28 -0
- package/dist/lib/ui-strings.d.ts +44 -0
- package/dist/lib/ui-strings.js +48 -0
- package/dist/lib/variants.d.ts +91 -0
- package/dist/lib/variants.js +411 -0
- package/dist/mdx-to-nextjs-generator.d.ts +22 -5
- package/dist/mdx-to-nextjs-generator.js +92 -12
- package/dist/templates/app/api/mcp/route.d.ts +1 -1
- package/dist/templates/app/api/mcp/route.js +14 -1
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +13 -2
- package/dist/templates/app/api/search/route.d.ts +1 -1
- package/dist/templates/app/api/search/route.js +16 -1
- package/dist/templates/app/sitemap.d.ts +2 -0
- package/dist/templates/app/sitemap.js +48 -3
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +40 -12
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +5 -2
- package/dist/templates/components/DocsSideBar.d.ts +1 -1
- package/dist/templates/components/DocsSideBar.js +3 -1
- package/dist/templates/components/SearchDocs.d.ts +1 -1
- package/dist/templates/components/SearchDocs.js +17 -3
- package/dist/templates/components/SearchModalContent.d.ts +1 -1
- package/dist/templates/components/SearchModalContent.js +22 -14
- package/dist/templates/components/SectionNavProvider.d.ts +1 -1
- package/dist/templates/components/SectionNavProvider.js +32 -20
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +26 -12
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +9 -7
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +6 -3
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +38 -5
- package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
- package/dist/templates/components/layout/DocsNavigation.js +4 -2
- package/dist/templates/components/layout/Dropdown.d.ts +1 -0
- package/dist/templates/components/layout/Dropdown.js +308 -0
- package/dist/templates/components/layout/FocusModeToggle.d.ts +1 -1
- package/dist/templates/components/layout/FocusModeToggle.js +7 -4
- package/dist/templates/components/layout/Footer.d.ts +1 -1
- package/dist/templates/components/layout/Footer.js +4 -2
- package/dist/templates/components/layout/Header.d.ts +1 -1
- package/dist/templates/components/layout/Header.js +18 -8
- package/dist/templates/components/layout/SectionBar.d.ts +1 -1
- package/dist/templates/components/layout/SectionBar.js +16 -10
- package/dist/templates/components/layout/VariantSwitchers.d.ts +1 -0
- package/dist/templates/components/layout/VariantSwitchers.js +313 -0
- package/dist/templates/components/useStrings.d.ts +1 -0
- package/dist/templates/components/useStrings.js +10 -0
- package/dist/templates/components/useVariant.d.ts +1 -0
- package/dist/templates/components/useVariant.js +13 -0
- package/dist/templates/llms/llmsIndex.d.ts +13 -0
- package/dist/templates/llms/llmsIndex.js +18 -3
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +2 -0
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +2 -0
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +1 -1
- package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
- package/dist/templates/mdx/fonts.mdx.js +1 -1
- package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
- package/dist/templates/mdx/footer-links.mdx.js +1 -1
- package/dist/templates/mdx/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/index.mdx.js +2 -0
- package/dist/templates/mdx/languages.mdx.d.ts +1 -0
- package/dist/templates/mdx/languages.mdx.js +94 -0
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +6 -0
- package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
- package/dist/templates/mdx/navigation.mdx.js +2 -0
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +2 -0
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +2 -0
- package/dist/templates/mdx/platform/file-editor.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/file-editor.mdx.js +2 -0
- package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/index.mdx.js +1 -1
- package/dist/templates/mdx/platform/languages.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/languages.mdx.js +50 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +2 -0
- package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.js +2 -0
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +4 -0
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +2 -0
- package/dist/templates/mdx/platform/versions.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/versions.mdx.js +33 -0
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +1 -1
- package/dist/templates/mdx/theme.mdx.d.ts +1 -1
- package/dist/templates/mdx/theme.mdx.js +1 -1
- package/dist/templates/mdx/versions.mdx.d.ts +1 -0
- package/dist/templates/mdx/versions.mdx.js +78 -0
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +2 -0
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +54 -10
- package/dist/templates/services/mcp/tools.d.ts +1 -1
- package/dist/templates/services/mcp/tools.js +81 -6
- package/dist/templates/services/mcp/types.d.ts +1 -1
- package/dist/templates/services/mcp/types.js +10 -0
- package/dist/templates/services/search.d.ts +1 -1
- package/dist/templates/services/search.js +34 -4
- package/dist/templates/utils/orderNavItems.d.ts +1 -1
- package/dist/templates/utils/orderNavItems.js +2 -0
- package/dist/templates/utils/strings.d.ts +1 -0
- package/dist/templates/utils/strings.js +27 -0
- package/dist/templates/utils/variants.d.ts +1 -0
- package/dist/templates/utils/variants.js +170 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_DESCRIPTION } from "../../lib/constants.js";
|
|
2
2
|
export const sectionNavProviderTemplate = `"use client";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
-
import { usePathname } from "next/navigation";
|
|
5
4
|
import { SideBar } from "@/components/SideBar";
|
|
5
|
+
import { useVariant } from "@/components/useVariant";
|
|
6
6
|
import { DocsNavigation } from "@/components/layout/DocsNavigation";
|
|
7
7
|
import { SectionBarProvider } from "@/components/layout/DocsComponents";
|
|
8
8
|
import { Footer } from "@/components/layout/Footer";
|
|
@@ -11,9 +11,12 @@ import {
|
|
|
11
11
|
transformPagesToGroupedStructure,
|
|
12
12
|
type PagesProps,
|
|
13
13
|
} from "@/utils/orderNavItems";
|
|
14
|
+
import { navigationScopeKey, pageVariantPrefix } from "@/utils/variants";
|
|
14
15
|
import rawNavigation from "@/navigation.json";
|
|
15
16
|
|
|
16
|
-
// navigation.json can be an array (root
|
|
17
|
+
// navigation.json can be an array (root scope only) or an object keyed by the
|
|
18
|
+
// URL prefix of each scope: a section slug ("api"), a language or version
|
|
19
|
+
// prefix ("de", "v1", "de/v1"), or both ("de/api").
|
|
17
20
|
type NavLink = {
|
|
18
21
|
slug?: string;
|
|
19
22
|
title: string;
|
|
@@ -25,15 +28,15 @@ type NavigationConfig = NavItem[] | Record<string, NavItem[]>;
|
|
|
25
28
|
|
|
26
29
|
const navigation = rawNavigation as NavigationConfig;
|
|
27
30
|
|
|
28
|
-
function
|
|
31
|
+
function getNavigationForScope(
|
|
29
32
|
nav: NavigationConfig,
|
|
30
|
-
|
|
33
|
+
scopeKey: string,
|
|
31
34
|
): NavItem[] | null {
|
|
32
35
|
if (Array.isArray(nav)) {
|
|
33
|
-
return
|
|
36
|
+
return scopeKey === "" && nav.length ? nav : null;
|
|
34
37
|
}
|
|
35
|
-
const
|
|
36
|
-
return
|
|
38
|
+
const scopeNav = nav[scopeKey];
|
|
39
|
+
return scopeNav && scopeNav.length ? scopeNav : null;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
interface SectionConfig {
|
|
@@ -46,6 +49,8 @@ interface SectionNavProviderProps {
|
|
|
46
49
|
sections: SectionConfig[];
|
|
47
50
|
allPages: PagesProps[];
|
|
48
51
|
hideBranding: boolean;
|
|
52
|
+
/** False when the site has no section bar (languages or versions only). */
|
|
53
|
+
hasSectionBar?: boolean;
|
|
49
54
|
children: React.ReactNode;
|
|
50
55
|
}
|
|
51
56
|
|
|
@@ -53,30 +58,34 @@ function SectionNavProvider({
|
|
|
53
58
|
sections,
|
|
54
59
|
allPages,
|
|
55
60
|
hideBranding,
|
|
61
|
+
hasSectionBar = true,
|
|
56
62
|
children,
|
|
57
63
|
}: SectionNavProviderProps) {
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
// Sections and pages are matched inside the current language/version, so
|
|
65
|
+
// the sidebar of /de/api lists the German API pages only.
|
|
66
|
+
const { prefix, rest } = useVariant();
|
|
60
67
|
|
|
61
68
|
const activeSectionSlug = useMemo(() => {
|
|
62
69
|
const match = sections.find((section) => {
|
|
63
70
|
if (section.slug === "") return false;
|
|
64
|
-
return (
|
|
65
|
-
currentPath === section.slug ||
|
|
66
|
-
currentPath.startsWith(section.slug + "/")
|
|
67
|
-
);
|
|
71
|
+
return rest === section.slug || rest.startsWith(section.slug + "/");
|
|
68
72
|
});
|
|
69
73
|
return match ? match.slug : "";
|
|
70
|
-
}, [sections,
|
|
74
|
+
}, [sections, rest]);
|
|
71
75
|
|
|
72
76
|
const result = useMemo(() => {
|
|
73
|
-
const
|
|
74
|
-
|
|
77
|
+
const scopeNav = getNavigationForScope(
|
|
78
|
+
navigation,
|
|
79
|
+
navigationScopeKey(prefix, activeSectionSlug),
|
|
80
|
+
);
|
|
81
|
+
if (scopeNav) return scopeNav;
|
|
75
82
|
const filtered = allPages.filter(
|
|
76
|
-
(page) =>
|
|
83
|
+
(page) =>
|
|
84
|
+
pageVariantPrefix(page) === prefix &&
|
|
85
|
+
(page.section || "") === activeSectionSlug,
|
|
77
86
|
);
|
|
78
87
|
return transformPagesToGroupedStructure(filtered);
|
|
79
|
-
}, [allPages, activeSectionSlug]);
|
|
88
|
+
}, [allPages, activeSectionSlug, prefix]);
|
|
80
89
|
|
|
81
90
|
// Fallback when no pages exist yet (also defined in layout.tsx for the non-sections path)
|
|
82
91
|
const defaultPages = [
|
|
@@ -96,8 +105,11 @@ function SectionNavProvider({
|
|
|
96
105
|
const defaultResults = transformPagesToGroupedStructure(defaultPages);
|
|
97
106
|
|
|
98
107
|
return (
|
|
99
|
-
<SectionBarProvider hasSectionBar={
|
|
100
|
-
<SideBar
|
|
108
|
+
<SectionBarProvider hasSectionBar={hasSectionBar}>
|
|
109
|
+
<SideBar
|
|
110
|
+
result={result.length ? result : defaultResults}
|
|
111
|
+
pages={allPages}
|
|
112
|
+
/>
|
|
101
113
|
{children}
|
|
102
114
|
<DocsNavigation result={result.length ? result : defaultResults} />
|
|
103
115
|
<StaticLinks />
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const sideBarTemplate = "\"use client\";\nimport { useContext, useEffect, useId, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Flex, Space, ThemeToggle } from \"cherry-styled-components\";\nimport { httpMethodBadgeColor } from \"@/components/layout/Badge\";\nimport {\n DocsSidebar,\n SectionBarContext,\n StyledSidebar,\n StyledSidebarList,\n StyledSidebarListItem,\n StyledStrong,\n StyledSidebarListItemLink,\n StyledSidebarMethodTag,\n StyledSidebarGroupButton,\n StyledSidebarGroupRow,\n StyledSidebarGroupLink,\n StyledSidebarGroupChevron,\n StyledSidebarGroupContent,\n StyledSidebarFooter,\n StyleMobileBar,\n StyledMobileBurger,\n} from \"@/components/layout/DocsComponents\";\nimport { FocusModeToggle } from \"@/components/layout/FocusModeToggle\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\n\n// A link can be a leaf (slug + title) or a group with nested children. Both the\n// category icon and the per-link icon are optional Lucide names.\ntype NavItemLink = {\n slug?: string;\n title: string;\n icon?: string;\n httpMethod?: string;\n links?: NavItemLink[];\n};\n\ntype NavItem = {\n label: string;\n icon?: string;\n links: NavItemLink[];\n};\n\ninterface SideBarProps {\n result: NavItem[];\n}\n\nfunction linkContainsActivePath(link: NavItemLink, pathname: string): boolean {\n if (link.slug !== undefined && pathname === `/${link.slug}`) {\n return true;\n }\n return (link.links ?? []).some((child) =>\n linkContainsActivePath(child, pathname),\n );\n}\n\nfunction SidebarNavLink({\n link,\n depth,\n pathname,\n onNavigate,\n}: {\n link: NavItemLink;\n depth: number;\n pathname: string;\n onNavigate: () => void;\n}) {\n const children = link.links ?? [];\n const hasChildren = children.length > 0;\n const href = link.slug !== undefined ? `/${link.slug}` : undefined;\n const isActive = href !== undefined && pathname === href;\n const indent = { paddingLeft: `${20 + depth * 14}px` };\n const groupContentId = useId();\n\n // Open collapsible groups that contain the active page so deep links land\n // with their ancestors already expanded.\n const [isOpen, setIsOpen] = useState(\n hasChildren\n ? children.some((child) => linkContainsActivePath(child, pathname))\n : false,\n );\n\n if (!hasChildren) {\n return (\n <StyledSidebarListItem>\n <StyledSidebarListItemLink\n href={href ?? \"#\"}\n $isActive={isActive}\n aria-current={isActive ? \"page\" : undefined}\n onClick={onNavigate}\n style={indent}\n >\n {link.httpMethod && (\n <StyledSidebarMethodTag\n mono\n solid={isActive}\n size=\"xs\"\n color={httpMethodBadgeColor(link.httpMethod)}\n >\n {link.httpMethod}\n </StyledSidebarMethodTag>\n )}\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarListItemLink>\n </StyledSidebarListItem>\n );\n }\n\n const toggle = () => setIsOpen((prev) => !prev);\n const toggleLabel = isOpen\n ? `Collapse ${link.title}`\n : `Expand ${link.title}`;\n const groupActive = linkContainsActivePath(link, pathname);\n\n return (\n <li>\n {href !== undefined ? (\n <StyledSidebarGroupRow\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n >\n <StyledSidebarGroupLink\n href={href}\n aria-current={pathname === href ? \"page\" : undefined}\n onClick={onNavigate}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarGroupLink>\n <StyledSidebarGroupChevron\n type=\"button\"\n onClick={toggle}\n aria-expanded={isOpen}\n aria-controls={groupContentId}\n aria-label={toggleLabel}\n >\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupChevron>\n </StyledSidebarGroupRow>\n ) : (\n <StyledSidebarGroupButton\n type=\"button\"\n onClick={toggle}\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n aria-expanded={isOpen}\n aria-controls={groupContentId}\n aria-label={toggleLabel}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupButton>\n )}\n <StyledSidebarGroupContent id={groupContentId} $isOpen={isOpen}>\n {children.map((child: NavItemLink, index: number) => (\n <SidebarNavLink\n key={index}\n link={child}\n depth={depth + 1}\n pathname={pathname}\n onNavigate={onNavigate}\n />\n ))}\n </StyledSidebarGroupContent>\n </li>\n );\n}\n\nfunction SideBar({ result }: SideBarProps) {\n const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const sidebarId = useId();\n const navRef = useRef<HTMLElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n\n useLockBodyScroll(isMobileMenuOpen);\n\n // Bring the current page's link into view within the sidebar's own scroll\n // area when it starts off-screen (deep pages, in-content links, search).\n // Scoped to the nav via scrollTo so the main document never jumps.\n useEffect(() => {\n const nav = navRef.current;\n if (!nav) return;\n const active = nav.querySelector<HTMLElement>('[aria-current=\"page\"]');\n if (!active) return;\n\n const navRect = nav.getBoundingClientRect();\n const activeRect = active.getBoundingClientRect();\n\n // The theme-toggle footer is sticky over the bottom of the scroll area\n // (~60px tall), so links underneath it are covered rather than visible.\n // Clamp the visible bottom to the footer's top edge when it's pinned.\n const footerRect = footerRef.current?.getBoundingClientRect();\n const visibleBottom = footerRect\n ? Math.min(navRect.bottom, footerRect.top)\n : navRect.bottom;\n\n const isOutOfView =\n activeRect.top < navRect.top || activeRect.bottom > visibleBottom;\n if (!isOutOfView) return;\n\n // Center within the visible band (nav top .. footer top), not the full\n // nav height, so the link never settles behind the footer.\n const visibleHeight = visibleBottom - navRect.top;\n const target =\n nav.scrollTop +\n (activeRect.top - navRect.top) -\n (visibleHeight - active.clientHeight) / 2;\n\n // Animate the scroll, but honor users who opt out of motion.\n const prefersReducedMotion = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n ).matches;\n nav.scrollTo({\n top: Math.max(0, target),\n behavior: prefersReducedMotion ? \"auto\" : \"smooth\",\n });\n }, [pathname]);\n\n return (\n <DocsSidebar>\n <StyleMobileBar\n onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}\n $isActive={isMobileMenuOpen}\n aria-label={\n isMobileMenuOpen ? \"Close navigation menu\" : \"Open navigation menu\"\n }\n aria-expanded={isMobileMenuOpen}\n aria-controls={sidebarId}\n >\n <StyledMobileBurger $isActive={isMobileMenuOpen} />\n </StyleMobileBar>\n\n <StyledSidebar\n id={sidebarId}\n ref={navRef}\n $isActive={isMobileMenuOpen}\n $hasSectionBar={hasSectionBar}\n >\n {result &&\n result.map((item: NavItem, index: number) => {\n return (\n <StyledSidebarList key={index}>\n <StyledSidebarListItem>\n <StyledStrong>\n {item.icon && <Icon name={item.icon} size={16} />}\n {item.label}\n </StyledStrong>{\" \"}\n </StyledSidebarListItem>\n <li>\n <Space $size={20} />\n </li>\n {item.links &&\n item.links.map((link: NavItemLink, indexChild: number) => (\n <SidebarNavLink\n key={indexChild}\n link={link}\n depth={0}\n pathname={pathname}\n onNavigate={() => setIsMobileMenuOpen(false)}\n />\n ))}\n <li aria-hidden=\"true\">\n <Space $size={20} />\n </li>\n </StyledSidebarList>\n );\n })}\n <StyledSidebarFooter ref={footerRef}>\n <Flex $xsJustifyContent=\"flex-start\" $lgJustifyContent=\"flex-end\">\n <ThemeToggle $shortcut />\n </Flex>\n </StyledSidebarFooter>\n </StyledSidebar>\n\n {/* Outside StyledSidebar on purpose: focus mode slides that whole\n column away, and the toggle has to survive it. */}\n <FocusModeToggle />\n </DocsSidebar>\n );\n}\n\nexport { SideBar };\n";
|
|
1
|
+
export declare const sideBarTemplate = "\"use client\";\nimport { useContext, useEffect, useId, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { useStrings } from \"@/components/useStrings\";\nimport { Space, ThemeToggle } from \"cherry-styled-components\";\nimport { httpMethodBadgeColor } from \"@/components/layout/Badge\";\nimport {\n DocsSidebar,\n SectionBarContext,\n StyledSidebar,\n StyledSidebarList,\n StyledSidebarListItem,\n StyledStrong,\n StyledSidebarListItemLink,\n StyledSidebarMethodTag,\n StyledSidebarGroupButton,\n StyledSidebarGroupRow,\n StyledSidebarGroupLink,\n StyledSidebarGroupChevron,\n StyledSidebarGroupContent,\n StyledSidebarFooter,\n StyledSidebarFooterToggle,\n StyleMobileBar,\n StyledMobileBurger,\n} from \"@/components/layout/DocsComponents\";\nimport { FocusModeToggle } from \"@/components/layout/FocusModeToggle\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { VariantSwitchers } from \"@/components/layout/VariantSwitchers\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\nimport type { PagesProps } from \"@/utils/orderNavItems\";\n\n// A link can be a leaf (slug + title) or a group with nested children. Both the\n// category icon and the per-link icon are optional Lucide names.\ntype NavItemLink = {\n slug?: string;\n title: string;\n icon?: string;\n httpMethod?: string;\n links?: NavItemLink[];\n};\n\ntype NavItem = {\n label: string;\n icon?: string;\n links: NavItemLink[];\n};\n\ninterface SideBarProps {\n result: NavItem[];\n /** Every page of the site. The language and version switchers in the footer\n resolve the current page's counterpart from it; sites without\n languages.json or versions.json never render them. */\n pages?: PagesProps[];\n}\n\nfunction linkContainsActivePath(link: NavItemLink, pathname: string): boolean {\n if (link.slug !== undefined && pathname === `/${link.slug}`) {\n return true;\n }\n return (link.links ?? []).some((child) =>\n linkContainsActivePath(child, pathname),\n );\n}\n\nfunction SidebarNavLink({\n link,\n depth,\n pathname,\n onNavigate,\n}: {\n link: NavItemLink;\n depth: number;\n pathname: string;\n onNavigate: () => void;\n}) {\n const children = link.links ?? [];\n const hasChildren = children.length > 0;\n const href = link.slug !== undefined ? `/${link.slug}` : undefined;\n const isActive = href !== undefined && pathname === href;\n const indent = { paddingLeft: `${20 + depth * 14}px` };\n const groupContentId = useId();\n const t = useStrings();\n\n // Open collapsible groups that contain the active page so deep links land\n // with their ancestors already expanded.\n const [isOpen, setIsOpen] = useState(\n hasChildren\n ? children.some((child) => linkContainsActivePath(child, pathname))\n : false,\n );\n\n if (!hasChildren) {\n return (\n <StyledSidebarListItem>\n <StyledSidebarListItemLink\n href={href ?? \"#\"}\n $isActive={isActive}\n aria-current={isActive ? \"page\" : undefined}\n onClick={onNavigate}\n style={indent}\n >\n {link.httpMethod && (\n <StyledSidebarMethodTag\n mono\n solid={isActive}\n size=\"xs\"\n color={httpMethodBadgeColor(link.httpMethod)}\n >\n {link.httpMethod}\n </StyledSidebarMethodTag>\n )}\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarListItemLink>\n </StyledSidebarListItem>\n );\n }\n\n const toggle = () => setIsOpen((prev) => !prev);\n const toggleLabel = (isOpen ? t.collapseGroup : t.expandGroup).replace(\n \"{title}\",\n link.title,\n );\n const groupActive = linkContainsActivePath(link, pathname);\n\n return (\n <li>\n {href !== undefined ? (\n <StyledSidebarGroupRow\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n >\n <StyledSidebarGroupLink\n href={href}\n aria-current={pathname === href ? \"page\" : undefined}\n onClick={onNavigate}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarGroupLink>\n <StyledSidebarGroupChevron\n type=\"button\"\n onClick={toggle}\n aria-expanded={isOpen}\n aria-controls={groupContentId}\n aria-label={toggleLabel}\n >\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupChevron>\n </StyledSidebarGroupRow>\n ) : (\n <StyledSidebarGroupButton\n type=\"button\"\n onClick={toggle}\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n aria-expanded={isOpen}\n aria-controls={groupContentId}\n aria-label={toggleLabel}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupButton>\n )}\n <StyledSidebarGroupContent id={groupContentId} $isOpen={isOpen}>\n {children.map((child: NavItemLink, index: number) => (\n <SidebarNavLink\n key={index}\n link={child}\n depth={depth + 1}\n pathname={pathname}\n onNavigate={onNavigate}\n />\n ))}\n </StyledSidebarGroupContent>\n </li>\n );\n}\n\nfunction SideBar({ result, pages = [] }: SideBarProps) {\n const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const t = useStrings();\n const sidebarId = useId();\n const navRef = useRef<HTMLElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n\n useLockBodyScroll(isMobileMenuOpen);\n\n // Bring the current page's link into view within the sidebar's own scroll\n // area when it starts off-screen (deep pages, in-content links, search).\n // Scoped to the nav via scrollTo so the main document never jumps.\n useEffect(() => {\n const nav = navRef.current;\n if (!nav) return;\n const active = nav.querySelector<HTMLElement>('[aria-current=\"page\"]');\n if (!active) return;\n\n const navRect = nav.getBoundingClientRect();\n const activeRect = active.getBoundingClientRect();\n\n // The sidebar footer - theme toggle plus the language and version\n // switchers - is sticky over the bottom of the scroll area, so links\n // underneath it are covered rather than visible.\n // Clamp the visible bottom to the footer's top edge when it's pinned.\n const footerRect = footerRef.current?.getBoundingClientRect();\n const visibleBottom = footerRect\n ? Math.min(navRect.bottom, footerRect.top)\n : navRect.bottom;\n\n const isOutOfView =\n activeRect.top < navRect.top || activeRect.bottom > visibleBottom;\n if (!isOutOfView) return;\n\n // Center within the visible band (nav top .. footer top), not the full\n // nav height, so the link never settles behind the footer.\n const visibleHeight = visibleBottom - navRect.top;\n const target =\n nav.scrollTop +\n (activeRect.top - navRect.top) -\n (visibleHeight - active.clientHeight) / 2;\n\n // Animate the scroll, but honor users who opt out of motion.\n const prefersReducedMotion = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n ).matches;\n nav.scrollTo({\n top: Math.max(0, target),\n behavior: prefersReducedMotion ? \"auto\" : \"smooth\",\n });\n }, [pathname]);\n\n return (\n <DocsSidebar>\n <StyleMobileBar\n onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}\n $isActive={isMobileMenuOpen}\n aria-label={isMobileMenuOpen ? t.closeNavigation : t.openNavigation}\n aria-expanded={isMobileMenuOpen}\n aria-controls={sidebarId}\n >\n <StyledMobileBurger $isActive={isMobileMenuOpen} />\n </StyleMobileBar>\n\n <StyledSidebar\n id={sidebarId}\n ref={navRef}\n $isActive={isMobileMenuOpen}\n $hasSectionBar={hasSectionBar}\n >\n {result &&\n result.map((item: NavItem, index: number) => {\n return (\n <StyledSidebarList key={index}>\n <StyledSidebarListItem>\n <StyledStrong>\n {item.icon && <Icon name={item.icon} size={16} />}\n {item.label}\n </StyledStrong>{\" \"}\n </StyledSidebarListItem>\n <li>\n <Space $size={20} />\n </li>\n {item.links &&\n item.links.map((link: NavItemLink, indexChild: number) => (\n <SidebarNavLink\n key={indexChild}\n link={link}\n depth={0}\n pathname={pathname}\n onNavigate={() => setIsMobileMenuOpen(false)}\n />\n ))}\n <li aria-hidden=\"true\">\n <Space $size={20} />\n </li>\n </StyledSidebarList>\n );\n })}\n {/* One row of 30px controls. The focus-mode toggle is fixed over its\n left end, the switchers follow, and the theme toggle holds the\n right end of the rail. */}\n <StyledSidebarFooter ref={footerRef}>\n <VariantSwitchers pages={pages} />\n <StyledSidebarFooterToggle>\n <ThemeToggle $shortcut />\n </StyledSidebarFooterToggle>\n </StyledSidebarFooter>\n </StyledSidebar>\n\n {/* Outside StyledSidebar on purpose: focus mode slides that whole\n column away, and the toggle has to survive it. */}\n <FocusModeToggle />\n </DocsSidebar>\n );\n}\n\nexport { SideBar };\n";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export const sideBarTemplate = `"use client";
|
|
2
2
|
import { useContext, useEffect, useId, useRef, useState } from "react";
|
|
3
3
|
import { usePathname } from "next/navigation";
|
|
4
|
-
import {
|
|
4
|
+
import { useStrings } from "@/components/useStrings";
|
|
5
|
+
import { Space, ThemeToggle } from "cherry-styled-components";
|
|
5
6
|
import { httpMethodBadgeColor } from "@/components/layout/Badge";
|
|
6
7
|
import {
|
|
7
8
|
DocsSidebar,
|
|
@@ -18,12 +19,15 @@ import {
|
|
|
18
19
|
StyledSidebarGroupChevron,
|
|
19
20
|
StyledSidebarGroupContent,
|
|
20
21
|
StyledSidebarFooter,
|
|
22
|
+
StyledSidebarFooterToggle,
|
|
21
23
|
StyleMobileBar,
|
|
22
24
|
StyledMobileBurger,
|
|
23
25
|
} from "@/components/layout/DocsComponents";
|
|
24
26
|
import { FocusModeToggle } from "@/components/layout/FocusModeToggle";
|
|
25
27
|
import { Icon } from "@/components/layout/Icon";
|
|
28
|
+
import { VariantSwitchers } from "@/components/layout/VariantSwitchers";
|
|
26
29
|
import { useLockBodyScroll } from "@/components/LockBodyScroll";
|
|
30
|
+
import type { PagesProps } from "@/utils/orderNavItems";
|
|
27
31
|
|
|
28
32
|
// A link can be a leaf (slug + title) or a group with nested children. Both the
|
|
29
33
|
// category icon and the per-link icon are optional Lucide names.
|
|
@@ -43,6 +47,10 @@ type NavItem = {
|
|
|
43
47
|
|
|
44
48
|
interface SideBarProps {
|
|
45
49
|
result: NavItem[];
|
|
50
|
+
/** Every page of the site. The language and version switchers in the footer
|
|
51
|
+
resolve the current page's counterpart from it; sites without
|
|
52
|
+
languages.json or versions.json never render them. */
|
|
53
|
+
pages?: PagesProps[];
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
function linkContainsActivePath(link: NavItemLink, pathname: string): boolean {
|
|
@@ -71,6 +79,7 @@ function SidebarNavLink({
|
|
|
71
79
|
const isActive = href !== undefined && pathname === href;
|
|
72
80
|
const indent = { paddingLeft: \`\${20 + depth * 14}px\` };
|
|
73
81
|
const groupContentId = useId();
|
|
82
|
+
const t = useStrings();
|
|
74
83
|
|
|
75
84
|
// Open collapsible groups that contain the active page so deep links land
|
|
76
85
|
// with their ancestors already expanded.
|
|
@@ -108,9 +117,10 @@ function SidebarNavLink({
|
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
const toggle = () => setIsOpen((prev) => !prev);
|
|
111
|
-
const toggleLabel = isOpen
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
const toggleLabel = (isOpen ? t.collapseGroup : t.expandGroup).replace(
|
|
121
|
+
"{title}",
|
|
122
|
+
link.title,
|
|
123
|
+
);
|
|
114
124
|
const groupActive = linkContainsActivePath(link, pathname);
|
|
115
125
|
|
|
116
126
|
return (
|
|
@@ -170,10 +180,11 @@ function SidebarNavLink({
|
|
|
170
180
|
);
|
|
171
181
|
}
|
|
172
182
|
|
|
173
|
-
function SideBar({ result }: SideBarProps) {
|
|
183
|
+
function SideBar({ result, pages = [] }: SideBarProps) {
|
|
174
184
|
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
|
175
185
|
const hasSectionBar = useContext(SectionBarContext);
|
|
176
186
|
const pathname = usePathname();
|
|
187
|
+
const t = useStrings();
|
|
177
188
|
const sidebarId = useId();
|
|
178
189
|
const navRef = useRef<HTMLElement>(null);
|
|
179
190
|
const footerRef = useRef<HTMLDivElement>(null);
|
|
@@ -192,8 +203,9 @@ function SideBar({ result }: SideBarProps) {
|
|
|
192
203
|
const navRect = nav.getBoundingClientRect();
|
|
193
204
|
const activeRect = active.getBoundingClientRect();
|
|
194
205
|
|
|
195
|
-
// The
|
|
196
|
-
//
|
|
206
|
+
// The sidebar footer - theme toggle plus the language and version
|
|
207
|
+
// switchers - is sticky over the bottom of the scroll area, so links
|
|
208
|
+
// underneath it are covered rather than visible.
|
|
197
209
|
// Clamp the visible bottom to the footer's top edge when it's pinned.
|
|
198
210
|
const footerRect = footerRef.current?.getBoundingClientRect();
|
|
199
211
|
const visibleBottom = footerRect
|
|
@@ -227,9 +239,7 @@ function SideBar({ result }: SideBarProps) {
|
|
|
227
239
|
<StyleMobileBar
|
|
228
240
|
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
|
|
229
241
|
$isActive={isMobileMenuOpen}
|
|
230
|
-
aria-label={
|
|
231
|
-
isMobileMenuOpen ? "Close navigation menu" : "Open navigation menu"
|
|
232
|
-
}
|
|
242
|
+
aria-label={isMobileMenuOpen ? t.closeNavigation : t.openNavigation}
|
|
233
243
|
aria-expanded={isMobileMenuOpen}
|
|
234
244
|
aria-controls={sidebarId}
|
|
235
245
|
>
|
|
@@ -271,10 +281,14 @@ function SideBar({ result }: SideBarProps) {
|
|
|
271
281
|
</StyledSidebarList>
|
|
272
282
|
);
|
|
273
283
|
})}
|
|
284
|
+
{/* One row of 30px controls. The focus-mode toggle is fixed over its
|
|
285
|
+
left end, the switchers follow, and the theme toggle holds the
|
|
286
|
+
right end of the rail. */}
|
|
274
287
|
<StyledSidebarFooter ref={footerRef}>
|
|
275
|
-
<
|
|
288
|
+
<VariantSwitchers pages={pages} />
|
|
289
|
+
<StyledSidebarFooterToggle>
|
|
276
290
|
<ThemeToggle $shortcut />
|
|
277
|
-
</
|
|
291
|
+
</StyledSidebarFooterToggle>
|
|
278
292
|
</StyledSidebarFooter>
|
|
279
293
|
</StyledSidebar>
|
|
280
294
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const actionBarTemplate = "\"use client\";\nimport { useContext, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport styled, { css } from \"styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n interactiveStyles,\n resetButton,\n Textarea,\n} from \"cherry-styled-components\";\nimport { SectionBarContext } from \"@/components/layout/DocsComponents\";\nimport { StyledSmallButton } from \"@/components/layout/SharedStyled\";\n\ninterface ActionBarProps {\n children: React.ReactNode;\n content: string;\n // When set, an RSS button linking to this page's feed renders next to the\n // copy pill.\n rssHref?: string;\n}\n\nconst StyledActionBar = styled.div<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n left: 0;\n padding: 12px 0;\n display: flex;\n justify-content: space-between;\n width: 100%;\n max-width: 640px;\n margin: auto;\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 12px 0;\n }\n`;\n\nconst StyledActionBarContent = styled.div`\n display: flex;\n gap: 12px;\n margin: auto 0;\n`;\n\nconst StyledCopyButton = styled(StyledSmallButton)<{\n theme: Theme;\n $copied: boolean;\n}>`\n border: solid 1px\n ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayLight};\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n }\n`;\n\n// StyledSmallButton carries a -6px right margin for edge alignment; inside\n// the pill group that would eat into the gap, so it is neutralized here.\nconst StyledActionBarGroup = styled.div`\n display: flex;\n gap: 12px;\n\n & > * {\n margin-right: 0;\n }\n`;\n\nconst StyledRssLink = styled(StyledSmallButton)<{ theme: Theme }>`\n text-decoration: none;\n color: ${({ theme }) => theme.colors.primary};\n padding: 2px 8px;\n\n & svg.lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\n// Mirrors the geometry and interaction of Cherry's ThemeToggle so every pill\n// on this side of the bar looks identical: interactiveStyles supplies the\n// border highlight + focus/active rings (no scale effect), and the 30px\n// height with a fully rounded radius matches the toggle's knob track.\nconst actionPillStyles = (theme: Theme) => css`\n height: 30px;\n border-radius: 30px;\n display: flex;\n align-items: center;\n margin: auto 0;\n background: ${theme.colors.light};\n border-color: ${theme.colors.grayLight};\n\n & svg {\n width: 16px;\n height: 16px;\n object-fit: contain;\n transition: all 0.3s ease;\n position: relative;\n z-index: 2;\n }\n\n & svg[stroke] {\n stroke: ${theme.colors.primary};\n }\n\n &:hover svg[stroke] {\n stroke: ${theme.colors.accent};\n }\n`;\n\nconst StyledMarkdownLink = styled.a<{ theme: Theme }>`\n ${resetButton}\n ${interactiveStyles}\n ${({ theme }) => actionPillStyles(theme)}\n width: 30px;\n justify-content: center;\n text-decoration: none;\n`;\n\n// The space-between layout with 6px padding puts each 16px icon's center\n// exactly where the 24px knob's center sits in its resting (left: 2px) and\n// active (translateX(26px)) positions.\nconst StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n ${({ theme }) => actionPillStyles(theme)}\n width: 56px;\n justify-content: space-between;\n padding: 0 6px;\n position: relative;\n\n &::after {\n content: \"\";\n position: absolute;\n top: 2px;\n left: 2px;\n width: 24px;\n height: 24px;\n border-radius: 50%;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n transition: all 0.3s ease;\n z-index: 1;\n ${({ $isActive }) =>\n !$isActive &&\n css`\n transform: translateX(26px);\n `}\n }\n`;\n\n// The raw-content view renders a full-viewport textarea. That rule is scoped to\n// the raw view (`$raw`) so it never leaks into textareas rendered inside page\n// content - e.g. the API playground's request-body editor, which sits inside\n// this same ActionBar in the normal (view) mode.\nconst StyledContent = styled.div<{\n theme: Theme;\n $hasSectionBar?: boolean;\n $raw?: boolean;\n}>`\n padding-top: 20px;\n transition: all 0.3s ease;\n\n ${({ $raw, $hasSectionBar }) =>\n $raw &&\n css`\n & textarea {\n max-width: 640px;\n margin: auto;\n width: 100%;\n height: 100%;\n min-height: calc(100vh - ${$hasSectionBar ? 202 : 160}px);\n\n ${mq(\"lg\")} {\n min-height: calc(100vh - 159px);\n }\n }\n `}\n`;\n\n// Every page ships a static markdown mirror under public/: \"/\" serves\n// \"/index.md\" and \"/{slug}\" serves \"/{slug}.md\".\nfunction toMarkdownHref(pathname: string) {\n const base = pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname;\n return `${base === \"\" ? \"/index\" : base}.md`;\n}\n\nfunction ActionBar({ children, content, rssHref }: ActionBarProps) {\n const [isView, setIsView] = useState(true);\n const [copied, setCopied] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n\n const handleCopyContent = async () => {\n try {\n await navigator.clipboard.writeText(content);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy:\", err);\n }\n };\n\n return (\n <>\n <StyledActionBar data-markdown-ignore>\n <StyledActionBarGroup>\n <StyledCopyButton onClick={handleCopyContent} $copied={copied}>\n {copied ? (\n <>\n <Icon name=\"check\" size={16} />\n
|
|
1
|
+
export declare const actionBarTemplate = "\"use client\";\nimport { useContext, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { useStrings } from \"@/components/useStrings\";\nimport styled, { css } from \"styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n interactiveStyles,\n resetButton,\n Textarea,\n} from \"cherry-styled-components\";\nimport { SectionBarContext } from \"@/components/layout/DocsComponents\";\nimport { StyledSmallButton } from \"@/components/layout/SharedStyled\";\n\ninterface ActionBarProps {\n children: React.ReactNode;\n content: string;\n // When set, an RSS button linking to this page's feed renders next to the\n // copy pill.\n rssHref?: string;\n}\n\nconst StyledActionBar = styled.div<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n left: 0;\n padding: 12px 0;\n display: flex;\n justify-content: space-between;\n width: 100%;\n max-width: 640px;\n margin: auto;\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 12px 0;\n }\n`;\n\nconst StyledActionBarContent = styled.div`\n display: flex;\n gap: 12px;\n margin: auto 0;\n`;\n\nconst StyledCopyButton = styled(StyledSmallButton)<{\n theme: Theme;\n $copied: boolean;\n}>`\n border: solid 1px\n ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayLight};\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n }\n`;\n\n// StyledSmallButton carries a -6px right margin for edge alignment; inside\n// the pill group that would eat into the gap, so it is neutralized here.\nconst StyledActionBarGroup = styled.div`\n display: flex;\n gap: 12px;\n\n & > * {\n margin-right: 0;\n }\n`;\n\nconst StyledRssLink = styled(StyledSmallButton)<{ theme: Theme }>`\n text-decoration: none;\n color: ${({ theme }) => theme.colors.primary};\n padding: 2px 8px;\n\n & svg.lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\n// Mirrors the geometry and interaction of Cherry's ThemeToggle so every pill\n// on this side of the bar looks identical: interactiveStyles supplies the\n// border highlight + focus/active rings (no scale effect), and the 30px\n// height with a fully rounded radius matches the toggle's knob track.\nconst actionPillStyles = (theme: Theme) => css`\n height: 30px;\n border-radius: 30px;\n display: flex;\n align-items: center;\n margin: auto 0;\n background: ${theme.colors.light};\n border-color: ${theme.colors.grayLight};\n\n & svg {\n width: 16px;\n height: 16px;\n object-fit: contain;\n transition: all 0.3s ease;\n position: relative;\n z-index: 2;\n }\n\n & svg[stroke] {\n stroke: ${theme.colors.primary};\n }\n\n &:hover svg[stroke] {\n stroke: ${theme.colors.accent};\n }\n`;\n\nconst StyledMarkdownLink = styled.a<{ theme: Theme }>`\n ${resetButton}\n ${interactiveStyles}\n ${({ theme }) => actionPillStyles(theme)}\n width: 30px;\n justify-content: center;\n text-decoration: none;\n`;\n\n// The space-between layout with 6px padding puts each 16px icon's center\n// exactly where the 24px knob's center sits in its resting (left: 2px) and\n// active (translateX(26px)) positions.\nconst StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n ${({ theme }) => actionPillStyles(theme)}\n width: 56px;\n justify-content: space-between;\n padding: 0 6px;\n position: relative;\n\n &::after {\n content: \"\";\n position: absolute;\n top: 2px;\n left: 2px;\n width: 24px;\n height: 24px;\n border-radius: 50%;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n transition: all 0.3s ease;\n z-index: 1;\n ${({ $isActive }) =>\n !$isActive &&\n css`\n transform: translateX(26px);\n `}\n }\n`;\n\n// The raw-content view renders a full-viewport textarea. That rule is scoped to\n// the raw view (`$raw`) so it never leaks into textareas rendered inside page\n// content - e.g. the API playground's request-body editor, which sits inside\n// this same ActionBar in the normal (view) mode.\nconst StyledContent = styled.div<{\n theme: Theme;\n $hasSectionBar?: boolean;\n $raw?: boolean;\n}>`\n padding-top: 20px;\n transition: all 0.3s ease;\n\n ${({ $raw, $hasSectionBar }) =>\n $raw &&\n css`\n & textarea {\n max-width: 640px;\n margin: auto;\n width: 100%;\n height: 100%;\n min-height: calc(100vh - ${$hasSectionBar ? 202 : 160}px);\n\n ${mq(\"lg\")} {\n min-height: calc(100vh - 159px);\n }\n }\n `}\n`;\n\n// Every page ships a static markdown mirror under public/: \"/\" serves\n// \"/index.md\" and \"/{slug}\" serves \"/{slug}.md\".\nfunction toMarkdownHref(pathname: string) {\n const base = pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname;\n return `${base === \"\" ? \"/index\" : base}.md`;\n}\n\nfunction ActionBar({ children, content, rssHref }: ActionBarProps) {\n const [isView, setIsView] = useState(true);\n const [copied, setCopied] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const t = useStrings();\n\n const handleCopyContent = async () => {\n try {\n await navigator.clipboard.writeText(content);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy:\", err);\n }\n };\n\n return (\n <>\n <StyledActionBar data-markdown-ignore>\n <StyledActionBarGroup>\n <StyledCopyButton onClick={handleCopyContent} $copied={copied}>\n {copied ? (\n <>\n <Icon name=\"check\" size={16} />\n {t.copied}\n </>\n ) : (\n <>\n <Icon name=\"copy\" size={16} />\n {t.copyContent}\n </>\n )}\n </StyledCopyButton>\n {rssHref && (\n <StyledRssLink as=\"a\" href={rssHref} aria-label={t.rssFeed}>\n <Icon name=\"rss\" size={16} />\n {t.rss}\n </StyledRssLink>\n )}\n </StyledActionBarGroup>\n <StyledActionBarContent>\n <StyledMarkdownLink\n href={toMarkdownHref(pathname)}\n aria-label={t.viewAsMarkdown}\n title={t.viewAsMarkdown}\n >\n <Icon name=\"FileText\" />\n </StyledMarkdownLink>\n <StyledToggle\n onClick={() => setIsView(!isView)}\n aria-label={t.toggleView}\n $isActive={isView}\n >\n <Icon name=\"Eye\" />\n <Icon name=\"CodeXml\" />\n </StyledToggle>\n </StyledActionBarContent>\n </StyledActionBar>\n {isView && (\n <StyledContent $hasSectionBar={hasSectionBar}>{children}</StyledContent>\n )}\n {!isView && (\n <StyledContent $hasSectionBar={hasSectionBar} $raw>\n <Textarea defaultValue={content} $fullWidth />\n </StyledContent>\n )}\n </>\n );\n}\n\nexport { ActionBar };\n";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const actionBarTemplate = `"use client";
|
|
2
2
|
import { useContext, useState } from "react";
|
|
3
3
|
import { usePathname } from "next/navigation";
|
|
4
|
+
import { useStrings } from "@/components/useStrings";
|
|
4
5
|
import styled, { css } from "styled-components";
|
|
5
6
|
import { Icon } from "@/components/layout/Icon";
|
|
6
7
|
import { mq, Theme } from "@/app/theme";
|
|
@@ -195,6 +196,7 @@ function ActionBar({ children, content, rssHref }: ActionBarProps) {
|
|
|
195
196
|
const [copied, setCopied] = useState(false);
|
|
196
197
|
const hasSectionBar = useContext(SectionBarContext);
|
|
197
198
|
const pathname = usePathname();
|
|
199
|
+
const t = useStrings();
|
|
198
200
|
|
|
199
201
|
const handleCopyContent = async () => {
|
|
200
202
|
try {
|
|
@@ -214,33 +216,33 @@ function ActionBar({ children, content, rssHref }: ActionBarProps) {
|
|
|
214
216
|
{copied ? (
|
|
215
217
|
<>
|
|
216
218
|
<Icon name="check" size={16} />
|
|
217
|
-
|
|
219
|
+
{t.copied}
|
|
218
220
|
</>
|
|
219
221
|
) : (
|
|
220
222
|
<>
|
|
221
223
|
<Icon name="copy" size={16} />
|
|
222
|
-
|
|
224
|
+
{t.copyContent}
|
|
223
225
|
</>
|
|
224
226
|
)}
|
|
225
227
|
</StyledCopyButton>
|
|
226
228
|
{rssHref && (
|
|
227
|
-
<StyledRssLink as="a" href={rssHref} aria-label=
|
|
229
|
+
<StyledRssLink as="a" href={rssHref} aria-label={t.rssFeed}>
|
|
228
230
|
<Icon name="rss" size={16} />
|
|
229
|
-
|
|
231
|
+
{t.rss}
|
|
230
232
|
</StyledRssLink>
|
|
231
233
|
)}
|
|
232
234
|
</StyledActionBarGroup>
|
|
233
235
|
<StyledActionBarContent>
|
|
234
236
|
<StyledMarkdownLink
|
|
235
237
|
href={toMarkdownHref(pathname)}
|
|
236
|
-
aria-label=
|
|
237
|
-
title=
|
|
238
|
+
aria-label={t.viewAsMarkdown}
|
|
239
|
+
title={t.viewAsMarkdown}
|
|
238
240
|
>
|
|
239
241
|
<Icon name="FileText" />
|
|
240
242
|
</StyledMarkdownLink>
|
|
241
243
|
<StyledToggle
|
|
242
244
|
onClick={() => setIsView(!isView)}
|
|
243
|
-
aria-label=
|
|
245
|
+
aria-label={t.toggleView}
|
|
244
246
|
$isActive={isView}
|
|
245
247
|
>
|
|
246
248
|
<Icon name="Eye" />
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const codeTemplate = "\"use client\";\nimport { useState, useCallback, useMemo, useId } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport {\n interactiveStyles,\n resetButton,\n styledCode,\n} from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeStringify from \"rehype-stringify\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { thinScrollbar } from \"@/components/layout/SharedStyled\";\n\ninterface CodeProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n \"theme\"\n> {\n code: string;\n language?: string;\n title?: string;\n theme?: Theme;\n}\n\ninterface CodeTab {\n label: string;\n code: string;\n language?: string;\n}\n\ninterface CodeTabsProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n \"theme\"\n> {\n tabs: CodeTab[];\n theme?: Theme;\n}\n\nconst CodeWrapper = styled.span<{ theme: Theme }>`\n position: relative;\n z-index: 2;\n display: block;\n width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n background: ${({ theme }) => theme.colors.light};\n`;\n\n/* Code block uses a fixed GitHub-style palette for the syntax tokens in both\n modes so highlighting stays legible regardless of brand colors. The dark-mode\n surface, however, matches the left sidebar's translucent brand tint\n (color-mix of theme.colors.primaryLight over the black page) instead of\n GitHub's #0d1117, so the window sits on the same background as the nav. Dark\n variants live in :root[data-theme=\"dark\"] & blocks so the swap happens via the active\n <html> class with no re-render. */\nconst TopBar = styled.div<{ theme: Theme }>`\n position: relative;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n border-top-left-radius: ${({ theme }) => theme.spacing.radius.lg};\n border-top-right-radius: ${({ theme }) => theme.spacing.radius.lg};\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n height: 33px;\n width: 100%;\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 5px;\n padding: 0 10px;\n`;\n\nconst DotsContainer = styled.div`\n display: flex;\n gap: 5px;\n`;\n\nconst Dot = styled.span<{ theme: Theme }>`\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background: rgba(0, 0, 0, 0.1);\n\n :root[data-theme=\"dark\"] & {\n background: rgba(255, 255, 255, 0.1);\n }\n`;\n\n/* Icon-only copy button. interactiveStyles supplies the border highlight on\n hover plus the focus/active rings (no scale effect). Colors come from theme\n tokens (grayLight border, success/grayDark icon) that swap for dark mode via\n the theme prop, so no :root[data-theme=\"dark\"] & override is needed and the copied state\n reads consistently in both modes. */\nconst CopyButton = styled.button<{ theme: Theme; $copied: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n background: ${({ theme }) => theme.colors.light};\n border-color: ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n margin-right: -6px;\n\n & svg.lucide {\n margin: 0;\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayDark};\n }\n`;\n\n/* Centered file name in the TopBar. Sits absolutely over the flex row so the\n dots and copy button keep their edge alignment. Monospace + a muted grayDark\n token that swaps for dark mode via the theme prop. pointer-events off so\n clicks fall through to nothing and never steal focus from the buttons. */\nconst TopBarTitle = styled.span<{ theme: Theme }>`\n position: absolute;\n left: 50%;\n transform: translateX(-50%);\n max-width: 60%;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n pointer-events: none;\n font-family: ${({ theme }) => theme.fonts.mono};\n font-size: 12px;\n line-height: 2;\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\n/* Segmented control living in the TopBar for CodeTabs. Scrolls horizontally\n with the thin scrollbar when the labels overflow the 33px bar. */\nconst TabList = styled.div<{ theme: Theme }>`\n display: flex;\n align-items: center;\n gap: 2px;\n min-width: 0;\n overflow-x: auto;\n ${thinScrollbar};\n padding: 2px;\n margin-left: -8px;\n`;\n\nconst CodeTab = styled.button<{ theme: Theme; $active: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n flex: 0 0 auto;\n font-family: ${({ theme }) => theme.fonts.mono};\n font-size: 12px;\n line-height: 1;\n padding: 5px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n cursor: pointer;\n white-space: nowrap;\n transition: all 0.3s ease;\n border: solid 1px\n ${({ theme, $active }) =>\n $active ? theme.colors.grayLight : \"transparent\"};\n background: ${({ theme, $active }) =>\n $active ? theme.colors.light : \"transparent\"};\n color: ${({ theme, $active }) =>\n $active ? theme.colors.dark : theme.colors.grayDark};\n box-shadow: 0 0 0 0px ${({ theme }) => theme.colors.primary};\n\n &:hover {\n color: ${({ theme }) => theme.colors.dark};\n background: ${({ theme, $active }) =>\n $active\n ? theme.colors.light\n : `color-mix(in srgb, ${theme.colors.dark} 4%, transparent)`};\n }\n\n &:focus {\n border-color: ${({ theme }) => theme.colors.primary};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n\n &:active {\n box-shadow: 0 0 0 1px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\n/* GitHub Light syntax highlighting by default; GitHub Dark in :root[data-theme=\"dark\"].\n Browser resolves which rule wins based on the active <html> class with no\n JS or React re-render involved. */\nconst lightSyntaxHighlight = css`\n & .hljs {\n color: #24292f;\n background: #ffffff;\n }\n & .hljs-doctag,\n & .hljs-keyword,\n & .hljs-meta .hljs-keyword,\n & .hljs-template-tag,\n & .hljs-template-variable,\n & .hljs-type,\n & .hljs-variable.language_ {\n color: #cf222e;\n }\n & .hljs-title,\n & .hljs-title.class_,\n & .hljs-title.class_.inherited__,\n & .hljs-title.function_ {\n color: #8250df;\n }\n & .hljs-attr,\n & .hljs-attribute,\n & .hljs-literal,\n & .hljs-meta,\n & .hljs-number,\n & .hljs-operator,\n & .hljs-selector-attr,\n & .hljs-selector-class,\n & .hljs-selector-id,\n & .hljs-variable {\n color: #0550ae;\n }\n & .hljs-meta .hljs-string,\n & .hljs-regexp,\n & .hljs-string {\n color: #0a3069;\n }\n & .hljs-built_in,\n & .hljs-symbol {\n color: #953800;\n }\n & .hljs-code,\n & .hljs-comment,\n & .hljs-formula {\n color: #6e7781;\n }\n & .hljs-name,\n & .hljs-quote,\n & .hljs-selector-pseudo,\n & .hljs-selector-tag {\n color: #116329;\n }\n & .hljs-subst {\n color: #24292f;\n }\n & .hljs-section {\n color: #0550ae;\n font-weight: 700;\n }\n & .hljs-bullet {\n color: #953800;\n }\n & .hljs-emphasis {\n color: #24292f;\n font-style: italic;\n }\n & .hljs-strong {\n color: #24292f;\n font-weight: 700;\n }\n`;\n\nconst darkSyntaxHighlight = css`\n & .hljs {\n color: #c9d1d9;\n background: transparent;\n }\n & .hljs-doctag,\n & .hljs-keyword,\n & .hljs-meta .hljs-keyword,\n & .hljs-template-tag,\n & .hljs-template-variable,\n & .hljs-type,\n & .hljs-variable.language_ {\n color: #ff7b72;\n }\n & .hljs-title,\n & .hljs-title.class_,\n & .hljs-title.class_.inherited__,\n & .hljs-title.function_ {\n color: #d2a8ff;\n }\n & .hljs-attr,\n & .hljs-attribute,\n & .hljs-literal,\n & .hljs-meta,\n & .hljs-number,\n & .hljs-operator,\n & .hljs-selector-attr,\n & .hljs-selector-class,\n & .hljs-selector-id,\n & .hljs-variable {\n color: #79c0ff;\n }\n & .hljs-meta .hljs-string,\n & .hljs-regexp,\n & .hljs-string {\n color: #a5d6ff;\n }\n & .hljs-built_in,\n & .hljs-symbol {\n color: #ffa657;\n }\n & .hljs-code,\n & .hljs-comment,\n & .hljs-formula {\n color: #8b949e;\n }\n & .hljs-name,\n & .hljs-quote,\n & .hljs-selector-pseudo,\n & .hljs-selector-tag {\n color: #7ee787;\n }\n & .hljs-subst {\n color: #c9d1d9;\n }\n & .hljs-section {\n color: #1f6feb;\n font-weight: 700;\n }\n & .hljs-bullet {\n color: #f2cc60;\n }\n & .hljs-emphasis {\n color: #c9d1d9;\n font-style: italic;\n }\n & .hljs-strong {\n color: #c9d1d9;\n font-weight: 700;\n }\n`;\n\nconst Body = styled.div<{ theme: Theme }>`\n background: #ffffff;\n border-bottom-left-radius: ${({ theme }) => theme.spacing.radius.lg};\n border-bottom-right-radius: ${({ theme }) => theme.spacing.radius.lg};\n color: #24292f;\n padding: 20px 0;\n font-family: ${({ theme }) => theme.fonts.mono};\n text-align: left;\n overflow-x: auto;\n overflow-y: auto;\n max-height: calc(100dvh - 400px);\n ${thinScrollbar};\n ${({ theme }) => styledCode(theme)};\n ${lightSyntaxHighlight};\n\n /* The 20px side gutter sits on the <code> element instead of the Body so it\n scrolls with the content: the right gutter survives a scroll to the end of\n a long line, and diff rows can bleed back through it to the window edge. */\n & .hljs {\n display: block;\n width: 100%;\n min-width: min-content;\n padding: 0 20px;\n }\n\n /* Diff rows: highlight.js wraps each +/- line in its own span, so tinting it\n edge to edge reads like a GitHub diff. inline-table keeps the trailing\n newline as the line break instead of adding an empty row, and the negative\n margin pulls the row back through the gutter so the accent bar sits flush\n against the window edge. border-left + padding-left add up to the same\n 20px, keeping the code itself aligned with the untouched lines. The tints\n are the success/error tokens at low alpha, so a custom theme.json palette\n carries through and the syntax colors underneath stay legible. */\n & .hljs-addition,\n & .hljs-deletion {\n display: inline-table;\n width: calc(100% + 40px);\n margin: 0 -20px;\n padding: 0 20px 0 17px;\n border-left: solid 3px transparent;\n }\n\n & .hljs-addition {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.success} 12%, transparent)`};\n border-left-color: ${({ theme }) => theme.colors.success};\n }\n\n & .hljs-deletion {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.error} 12%, transparent)`};\n border-left-color: ${({ theme }) => theme.colors.error};\n }\n\n :root[data-theme=\"dark\"] & {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n color: #ffffff;\n ${darkSyntaxHighlight};\n\n /* The tints sit on a near-black surface in dark mode, so they need a few\n more points of alpha to read at the same strength as in light. */\n & .hljs-addition {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.success} 16%, transparent)`};\n }\n\n & .hljs-deletion {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.error} 16%, transparent)`};\n }\n }\n`;\n\nconst escapeHtml = (unsafe: string): string => {\n return unsafe\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n};\n\nconst sanitizeLanguage = (lang: string): string =>\n lang.replace(/[^a-zA-Z0-9_-]/g, \"\");\n\nconst highlightCode = (code: string, language: string): string => {\n const escapedCode = escapeHtml(code);\n const safeLang = sanitizeLanguage(language);\n const result = unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeHighlight, {\n detect: true,\n ignoreMissing: true,\n })\n .use(rehypeStringify)\n .processSync(\n `<pre><code class=\"language-${safeLang}\">${escapedCode}</code></pre>`,\n );\n\n return String(result);\n};\n\nfunction Code({\n code,\n language = \"javascript\",\n title,\n theme,\n className,\n}: CodeProps) {\n const [copied, setCopied] = useState(false);\n const highlightedCode = useMemo(\n () => highlightCode(code, language),\n [code, language],\n );\n\n const handleCopy = useCallback(async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy code:\", err);\n }\n }, [code]);\n\n return (\n <CodeWrapper\n className={`${className ?? \"\"} code-wrapper`.trim()}\n theme={theme}\n >\n <TopBar theme={theme}>\n <DotsContainer>\n <Dot theme={theme} />\n <Dot theme={theme} />\n <Dot theme={theme} />\n </DotsContainer>\n {title ? <TopBarTitle theme={theme}>{title}</TopBarTitle> : null}\n <CopyButton\n onClick={handleCopy}\n $copied={copied}\n theme={theme}\n aria-label={copied ? \"Copied\" : \"Copy code\"}\n >\n <Icon name={copied ? \"check\" : \"copy\"} size={12} />\n </CopyButton>\n </TopBar>\n <Body\n dangerouslySetInnerHTML={{ __html: highlightedCode }}\n theme={theme}\n className=\"code-wrapper-body\"\n />\n </CodeWrapper>\n );\n}\n\n/* Multi-variant code block (npm / pnpm / yarn, etc). Tabs replace the macOS\n dots in the TopBar as a keyboard-accessible tablist; the copy button copies\n whichever tab is active and resets its copied state when the tab changes. */\nfunction CodeTabs({ tabs, theme, className }: CodeTabsProps) {\n const baseId = useId();\n const [active, setActive] = useState(0);\n const [copied, setCopied] = useState(false);\n\n const safeActive = active < tabs.length ? active : 0;\n const activeTab = tabs[safeActive];\n\n const highlightedCode = useMemo(\n () =>\n activeTab\n ? highlightCode(activeTab.code, activeTab.language ?? \"bash\")\n : \"\",\n [activeTab],\n );\n\n const handleSelect = useCallback((index: number) => {\n setActive(index);\n setCopied(false);\n }, []);\n\n const handleCopy = useCallback(async () => {\n if (!activeTab) return;\n try {\n await navigator.clipboard.writeText(activeTab.code);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy code:\", err);\n }\n }, [activeTab]);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent<HTMLButtonElement>) => {\n let next = safeActive;\n if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") {\n next = (safeActive + 1) % tabs.length;\n } else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") {\n next = (safeActive - 1 + tabs.length) % tabs.length;\n } else if (event.key === \"Home\") {\n next = 0;\n } else if (event.key === \"End\") {\n next = tabs.length - 1;\n } else {\n return;\n }\n event.preventDefault();\n handleSelect(next);\n const target = document.getElementById(`${baseId}-tab-${next}`);\n if (target) target.focus();\n },\n [baseId, handleSelect, safeActive, tabs.length],\n );\n\n if (!tabs || tabs.length === 0) return null;\n\n return (\n <CodeWrapper\n className={`${className ?? \"\"} code-wrapper`.trim()}\n theme={theme}\n >\n <TopBar theme={theme}>\n <TabList role=\"tablist\" aria-label=\"Code variants\">\n {tabs.map((tab, index) => (\n <CodeTab\n key={`${tab.label}-${index}`}\n type=\"button\"\n role=\"tab\"\n id={`${baseId}-tab-${index}`}\n aria-selected={index === safeActive}\n aria-controls={`${baseId}-panel`}\n tabIndex={index === safeActive ? 0 : -1}\n onClick={() => handleSelect(index)}\n onKeyDown={handleKeyDown}\n $active={index === safeActive}\n theme={theme}\n >\n {tab.label}\n </CodeTab>\n ))}\n </TabList>\n <CopyButton\n onClick={handleCopy}\n $copied={copied}\n theme={theme}\n aria-label={copied ? \"Copied\" : \"Copy code\"}\n >\n <Icon name={copied ? \"check\" : \"copy\"} size={12} />\n </CopyButton>\n </TopBar>\n <Body\n id={`${baseId}-panel`}\n role=\"tabpanel\"\n aria-labelledby={`${baseId}-tab-${safeActive}`}\n dangerouslySetInnerHTML={{ __html: highlightedCode }}\n theme={theme}\n className=\"code-wrapper-body\"\n />\n </CodeWrapper>\n );\n}\n\nexport { Code, CodeTabs };\n";
|
|
1
|
+
export declare const codeTemplate = "\"use client\";\nimport { useState, useCallback, useMemo, useId } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport {\n interactiveStyles,\n resetButton,\n styledCode,\n} from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeStringify from \"rehype-stringify\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { thinScrollbar } from \"@/components/layout/SharedStyled\";\nimport { useStrings } from \"@/components/useStrings\";\n\ninterface CodeProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n \"theme\"\n> {\n code: string;\n language?: string;\n title?: string;\n theme?: Theme;\n}\n\ninterface CodeTab {\n label: string;\n code: string;\n language?: string;\n}\n\ninterface CodeTabsProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n \"theme\"\n> {\n tabs: CodeTab[];\n theme?: Theme;\n}\n\nconst CodeWrapper = styled.span<{ theme: Theme }>`\n position: relative;\n z-index: 2;\n display: block;\n width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n background: ${({ theme }) => theme.colors.light};\n`;\n\n/* Code block uses a fixed GitHub-style palette for the syntax tokens in both\n modes so highlighting stays legible regardless of brand colors. The dark-mode\n surface, however, matches the left sidebar's translucent brand tint\n (color-mix of theme.colors.primaryLight over the black page) instead of\n GitHub's #0d1117, so the window sits on the same background as the nav. Dark\n variants live in :root[data-theme=\"dark\"] & blocks so the swap happens via the active\n <html> class with no re-render. */\nconst TopBar = styled.div<{ theme: Theme }>`\n position: relative;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n border-top-left-radius: ${({ theme }) => theme.spacing.radius.lg};\n border-top-right-radius: ${({ theme }) => theme.spacing.radius.lg};\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n height: 33px;\n width: 100%;\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 5px;\n padding: 0 10px;\n`;\n\nconst DotsContainer = styled.div`\n display: flex;\n gap: 5px;\n`;\n\nconst Dot = styled.span<{ theme: Theme }>`\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background: rgba(0, 0, 0, 0.1);\n\n :root[data-theme=\"dark\"] & {\n background: rgba(255, 255, 255, 0.1);\n }\n`;\n\n/* Icon-only copy button. interactiveStyles supplies the border highlight on\n hover plus the focus/active rings (no scale effect). Colors come from theme\n tokens (grayLight border, success/grayDark icon) that swap for dark mode via\n the theme prop, so no :root[data-theme=\"dark\"] & override is needed and the copied state\n reads consistently in both modes. */\nconst CopyButton = styled.button<{ theme: Theme; $copied: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n background: ${({ theme }) => theme.colors.light};\n border-color: ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n margin-right: -6px;\n\n & svg.lucide {\n margin: 0;\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayDark};\n }\n`;\n\n/* Centered file name in the TopBar. Sits absolutely over the flex row so the\n dots and copy button keep their edge alignment. Monospace + a muted grayDark\n token that swaps for dark mode via the theme prop. pointer-events off so\n clicks fall through to nothing and never steal focus from the buttons. */\nconst TopBarTitle = styled.span<{ theme: Theme }>`\n position: absolute;\n left: 50%;\n transform: translateX(-50%);\n max-width: 60%;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n pointer-events: none;\n font-family: ${({ theme }) => theme.fonts.mono};\n font-size: 12px;\n line-height: 2;\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\n/* Segmented control living in the TopBar for CodeTabs. Scrolls horizontally\n with the thin scrollbar when the labels overflow the 33px bar. */\nconst TabList = styled.div<{ theme: Theme }>`\n display: flex;\n align-items: center;\n gap: 2px;\n min-width: 0;\n overflow-x: auto;\n ${thinScrollbar};\n padding: 2px;\n margin-left: -8px;\n`;\n\nconst CodeTab = styled.button<{ theme: Theme; $active: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n flex: 0 0 auto;\n font-family: ${({ theme }) => theme.fonts.mono};\n font-size: 12px;\n line-height: 1;\n padding: 5px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n cursor: pointer;\n white-space: nowrap;\n transition: all 0.3s ease;\n border: solid 1px\n ${({ theme, $active }) =>\n $active ? theme.colors.grayLight : \"transparent\"};\n background: ${({ theme, $active }) =>\n $active ? theme.colors.light : \"transparent\"};\n color: ${({ theme, $active }) =>\n $active ? theme.colors.dark : theme.colors.grayDark};\n box-shadow: 0 0 0 0px ${({ theme }) => theme.colors.primary};\n\n &:hover {\n color: ${({ theme }) => theme.colors.dark};\n background: ${({ theme, $active }) =>\n $active\n ? theme.colors.light\n : `color-mix(in srgb, ${theme.colors.dark} 4%, transparent)`};\n }\n\n &:focus {\n border-color: ${({ theme }) => theme.colors.primary};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n\n &:active {\n box-shadow: 0 0 0 1px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\n/* GitHub Light syntax highlighting by default; GitHub Dark in :root[data-theme=\"dark\"].\n Browser resolves which rule wins based on the active <html> class with no\n JS or React re-render involved. */\nconst lightSyntaxHighlight = css`\n & .hljs {\n color: #24292f;\n background: #ffffff;\n }\n & .hljs-doctag,\n & .hljs-keyword,\n & .hljs-meta .hljs-keyword,\n & .hljs-template-tag,\n & .hljs-template-variable,\n & .hljs-type,\n & .hljs-variable.language_ {\n color: #cf222e;\n }\n & .hljs-title,\n & .hljs-title.class_,\n & .hljs-title.class_.inherited__,\n & .hljs-title.function_ {\n color: #8250df;\n }\n & .hljs-attr,\n & .hljs-attribute,\n & .hljs-literal,\n & .hljs-meta,\n & .hljs-number,\n & .hljs-operator,\n & .hljs-selector-attr,\n & .hljs-selector-class,\n & .hljs-selector-id,\n & .hljs-variable {\n color: #0550ae;\n }\n & .hljs-meta .hljs-string,\n & .hljs-regexp,\n & .hljs-string {\n color: #0a3069;\n }\n & .hljs-built_in,\n & .hljs-symbol {\n color: #953800;\n }\n & .hljs-code,\n & .hljs-comment,\n & .hljs-formula {\n color: #6e7781;\n }\n & .hljs-name,\n & .hljs-quote,\n & .hljs-selector-pseudo,\n & .hljs-selector-tag {\n color: #116329;\n }\n & .hljs-subst {\n color: #24292f;\n }\n & .hljs-section {\n color: #0550ae;\n font-weight: 700;\n }\n & .hljs-bullet {\n color: #953800;\n }\n & .hljs-emphasis {\n color: #24292f;\n font-style: italic;\n }\n & .hljs-strong {\n color: #24292f;\n font-weight: 700;\n }\n`;\n\nconst darkSyntaxHighlight = css`\n & .hljs {\n color: #c9d1d9;\n background: transparent;\n }\n & .hljs-doctag,\n & .hljs-keyword,\n & .hljs-meta .hljs-keyword,\n & .hljs-template-tag,\n & .hljs-template-variable,\n & .hljs-type,\n & .hljs-variable.language_ {\n color: #ff7b72;\n }\n & .hljs-title,\n & .hljs-title.class_,\n & .hljs-title.class_.inherited__,\n & .hljs-title.function_ {\n color: #d2a8ff;\n }\n & .hljs-attr,\n & .hljs-attribute,\n & .hljs-literal,\n & .hljs-meta,\n & .hljs-number,\n & .hljs-operator,\n & .hljs-selector-attr,\n & .hljs-selector-class,\n & .hljs-selector-id,\n & .hljs-variable {\n color: #79c0ff;\n }\n & .hljs-meta .hljs-string,\n & .hljs-regexp,\n & .hljs-string {\n color: #a5d6ff;\n }\n & .hljs-built_in,\n & .hljs-symbol {\n color: #ffa657;\n }\n & .hljs-code,\n & .hljs-comment,\n & .hljs-formula {\n color: #8b949e;\n }\n & .hljs-name,\n & .hljs-quote,\n & .hljs-selector-pseudo,\n & .hljs-selector-tag {\n color: #7ee787;\n }\n & .hljs-subst {\n color: #c9d1d9;\n }\n & .hljs-section {\n color: #1f6feb;\n font-weight: 700;\n }\n & .hljs-bullet {\n color: #f2cc60;\n }\n & .hljs-emphasis {\n color: #c9d1d9;\n font-style: italic;\n }\n & .hljs-strong {\n color: #c9d1d9;\n font-weight: 700;\n }\n`;\n\nconst Body = styled.div<{ theme: Theme }>`\n background: #ffffff;\n border-bottom-left-radius: ${({ theme }) => theme.spacing.radius.lg};\n border-bottom-right-radius: ${({ theme }) => theme.spacing.radius.lg};\n color: #24292f;\n padding: 20px 0;\n font-family: ${({ theme }) => theme.fonts.mono};\n text-align: left;\n overflow-x: auto;\n overflow-y: auto;\n max-height: calc(100dvh - 400px);\n ${thinScrollbar};\n ${({ theme }) => styledCode(theme)};\n ${lightSyntaxHighlight};\n\n /* The 20px side gutter sits on the <code> element instead of the Body so it\n scrolls with the content: the right gutter survives a scroll to the end of\n a long line, and diff rows can bleed back through it to the window edge. */\n & .hljs {\n display: block;\n width: 100%;\n min-width: min-content;\n padding: 0 20px;\n }\n\n /* Diff rows: highlight.js wraps each +/- line in its own span, so tinting it\n edge to edge reads like a GitHub diff. inline-table keeps the trailing\n newline as the line break instead of adding an empty row, and the negative\n margin pulls the row back through the gutter so the accent bar sits flush\n against the window edge. border-left + padding-left add up to the same\n 20px, keeping the code itself aligned with the untouched lines. The tints\n are the success/error tokens at low alpha, so a custom theme.json palette\n carries through and the syntax colors underneath stay legible. */\n & .hljs-addition,\n & .hljs-deletion {\n display: inline-table;\n width: calc(100% + 40px);\n margin: 0 -20px;\n padding: 0 20px 0 17px;\n border-left: solid 3px transparent;\n }\n\n & .hljs-addition {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.success} 12%, transparent)`};\n border-left-color: ${({ theme }) => theme.colors.success};\n }\n\n & .hljs-deletion {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.error} 12%, transparent)`};\n border-left-color: ${({ theme }) => theme.colors.error};\n }\n\n :root[data-theme=\"dark\"] & {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n color: #ffffff;\n ${darkSyntaxHighlight};\n\n /* The tints sit on a near-black surface in dark mode, so they need a few\n more points of alpha to read at the same strength as in light. */\n & .hljs-addition {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.success} 16%, transparent)`};\n }\n\n & .hljs-deletion {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.error} 16%, transparent)`};\n }\n }\n`;\n\nconst escapeHtml = (unsafe: string): string => {\n return unsafe\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n};\n\nconst sanitizeLanguage = (lang: string): string =>\n lang.replace(/[^a-zA-Z0-9_-]/g, \"\");\n\nconst highlightCode = (code: string, language: string): string => {\n const escapedCode = escapeHtml(code);\n const safeLang = sanitizeLanguage(language);\n const result = unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeHighlight, {\n detect: true,\n ignoreMissing: true,\n })\n .use(rehypeStringify)\n .processSync(\n `<pre><code class=\"language-${safeLang}\">${escapedCode}</code></pre>`,\n );\n\n return String(result);\n};\n\nfunction Code({\n code,\n language = \"javascript\",\n title,\n theme,\n className,\n}: CodeProps) {\n const [copied, setCopied] = useState(false);\n const t = useStrings();\n const highlightedCode = useMemo(\n () => highlightCode(code, language),\n [code, language],\n );\n\n const handleCopy = useCallback(async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy code:\", err);\n }\n }, [code]);\n\n return (\n <CodeWrapper\n className={`${className ?? \"\"} code-wrapper`.trim()}\n theme={theme}\n >\n <TopBar theme={theme}>\n <DotsContainer>\n <Dot theme={theme} />\n <Dot theme={theme} />\n <Dot theme={theme} />\n </DotsContainer>\n {title ? <TopBarTitle theme={theme}>{title}</TopBarTitle> : null}\n <CopyButton\n onClick={handleCopy}\n $copied={copied}\n theme={theme}\n aria-label={copied ? t.copied : t.copyCode}\n >\n <Icon name={copied ? \"check\" : \"copy\"} size={12} />\n </CopyButton>\n </TopBar>\n <Body\n dangerouslySetInnerHTML={{ __html: highlightedCode }}\n theme={theme}\n className=\"code-wrapper-body\"\n />\n </CodeWrapper>\n );\n}\n\n/* Multi-variant code block (npm / pnpm / yarn, etc). Tabs replace the macOS\n dots in the TopBar as a keyboard-accessible tablist; the copy button copies\n whichever tab is active and resets its copied state when the tab changes. */\nfunction CodeTabs({ tabs, theme, className }: CodeTabsProps) {\n const baseId = useId();\n const [active, setActive] = useState(0);\n const [copied, setCopied] = useState(false);\n const t = useStrings();\n\n const safeActive = active < tabs.length ? active : 0;\n const activeTab = tabs[safeActive];\n\n const highlightedCode = useMemo(\n () =>\n activeTab\n ? highlightCode(activeTab.code, activeTab.language ?? \"bash\")\n : \"\",\n [activeTab],\n );\n\n const handleSelect = useCallback((index: number) => {\n setActive(index);\n setCopied(false);\n }, []);\n\n const handleCopy = useCallback(async () => {\n if (!activeTab) return;\n try {\n await navigator.clipboard.writeText(activeTab.code);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy code:\", err);\n }\n }, [activeTab]);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent<HTMLButtonElement>) => {\n let next = safeActive;\n if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") {\n next = (safeActive + 1) % tabs.length;\n } else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") {\n next = (safeActive - 1 + tabs.length) % tabs.length;\n } else if (event.key === \"Home\") {\n next = 0;\n } else if (event.key === \"End\") {\n next = tabs.length - 1;\n } else {\n return;\n }\n event.preventDefault();\n handleSelect(next);\n const target = document.getElementById(`${baseId}-tab-${next}`);\n if (target) target.focus();\n },\n [baseId, handleSelect, safeActive, tabs.length],\n );\n\n if (!tabs || tabs.length === 0) return null;\n\n return (\n <CodeWrapper\n className={`${className ?? \"\"} code-wrapper`.trim()}\n theme={theme}\n >\n <TopBar theme={theme}>\n <TabList role=\"tablist\" aria-label={t.codeVariants}>\n {tabs.map((tab, index) => (\n <CodeTab\n key={`${tab.label}-${index}`}\n type=\"button\"\n role=\"tab\"\n id={`${baseId}-tab-${index}`}\n aria-selected={index === safeActive}\n aria-controls={`${baseId}-panel`}\n tabIndex={index === safeActive ? 0 : -1}\n onClick={() => handleSelect(index)}\n onKeyDown={handleKeyDown}\n $active={index === safeActive}\n theme={theme}\n >\n {tab.label}\n </CodeTab>\n ))}\n </TabList>\n <CopyButton\n onClick={handleCopy}\n $copied={copied}\n theme={theme}\n aria-label={copied ? t.copied : t.copyCode}\n >\n <Icon name={copied ? \"check\" : \"copy\"} size={12} />\n </CopyButton>\n </TopBar>\n <Body\n id={`${baseId}-panel`}\n role=\"tabpanel\"\n aria-labelledby={`${baseId}-tab-${safeActive}`}\n dangerouslySetInnerHTML={{ __html: highlightedCode }}\n theme={theme}\n className=\"code-wrapper-body\"\n />\n </CodeWrapper>\n );\n}\n\nexport { Code, CodeTabs };\n";
|
|
@@ -13,6 +13,7 @@ import rehypeHighlight from "rehype-highlight";
|
|
|
13
13
|
import rehypeStringify from "rehype-stringify";
|
|
14
14
|
import { Icon } from "@/components/layout/Icon";
|
|
15
15
|
import { thinScrollbar } from "@/components/layout/SharedStyled";
|
|
16
|
+
import { useStrings } from "@/components/useStrings";
|
|
16
17
|
|
|
17
18
|
interface CodeProps extends Omit<
|
|
18
19
|
React.HTMLAttributes<HTMLDivElement>,
|
|
@@ -440,6 +441,7 @@ function Code({
|
|
|
440
441
|
className,
|
|
441
442
|
}: CodeProps) {
|
|
442
443
|
const [copied, setCopied] = useState(false);
|
|
444
|
+
const t = useStrings();
|
|
443
445
|
const highlightedCode = useMemo(
|
|
444
446
|
() => highlightCode(code, language),
|
|
445
447
|
[code, language],
|
|
@@ -471,7 +473,7 @@ function Code({
|
|
|
471
473
|
onClick={handleCopy}
|
|
472
474
|
$copied={copied}
|
|
473
475
|
theme={theme}
|
|
474
|
-
aria-label={copied ?
|
|
476
|
+
aria-label={copied ? t.copied : t.copyCode}
|
|
475
477
|
>
|
|
476
478
|
<Icon name={copied ? "check" : "copy"} size={12} />
|
|
477
479
|
</CopyButton>
|
|
@@ -492,6 +494,7 @@ function CodeTabs({ tabs, theme, className }: CodeTabsProps) {
|
|
|
492
494
|
const baseId = useId();
|
|
493
495
|
const [active, setActive] = useState(0);
|
|
494
496
|
const [copied, setCopied] = useState(false);
|
|
497
|
+
const t = useStrings();
|
|
495
498
|
|
|
496
499
|
const safeActive = active < tabs.length ? active : 0;
|
|
497
500
|
const activeTab = tabs[safeActive];
|
|
@@ -550,7 +553,7 @@ function CodeTabs({ tabs, theme, className }: CodeTabsProps) {
|
|
|
550
553
|
theme={theme}
|
|
551
554
|
>
|
|
552
555
|
<TopBar theme={theme}>
|
|
553
|
-
<TabList role="tablist" aria-label=
|
|
556
|
+
<TabList role="tablist" aria-label={t.codeVariants}>
|
|
554
557
|
{tabs.map((tab, index) => (
|
|
555
558
|
<CodeTab
|
|
556
559
|
key={\`\${tab.label}-\${index}\`}
|
|
@@ -573,7 +576,7 @@ function CodeTabs({ tabs, theme, className }: CodeTabsProps) {
|
|
|
573
576
|
onClick={handleCopy}
|
|
574
577
|
$copied={copied}
|
|
575
578
|
theme={theme}
|
|
576
|
-
aria-label={copied ?
|
|
579
|
+
aria-label={copied ? t.copied : t.copyCode}
|
|
577
580
|
>
|
|
578
581
|
<Icon name={copied ? "check" : "copy"} size={12} />
|
|
579
582
|
</CopyButton>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const docsComponentsTemplate = "\"use client\";\nimport React, { createContext } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport {\n Button,\n resetButton,\n styledSmall,\n styledStrong,\n styledText,\n useChat,\n} from \"cherry-styled-components\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n focusModeColumn,\n focusModeHide,\n sidePanelOffset,\n styledAnchor,\n styledTable,\n stylesLists,\n} from \"@/components/layout/SharedStyled\";\nimport { Badge } from \"@/components/layout/Badge\";\n\nconst SectionBarContext = createContext(false);\n\nfunction SectionBarProvider({\n hasSectionBar,\n children,\n}: {\n hasSectionBar: boolean;\n children: React.ReactNode;\n}) {\n return (\n <SectionBarContext.Provider value={hasSectionBar}>\n {children}\n </SectionBarContext.Provider>\n );\n}\n\ninterface DocsProps {\n children: React.ReactNode;\n}\n\nconst StyledDocsWrapper = styled.div<{ theme: Theme }>`\n position: relative;\n`;\n\nconst StyledDocsSidebar = styled.div<{ theme: Theme }>`\n clear: both;\n`;\n\n// The <main> landmark wraps only the article content: the sidebar, footer,\n// and nav render outside it so content extractors and assistive tech start at\n// the article.\nconst StyledDocsContainer = styled.main<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n position: relative;\n padding: 0 20px 100px 20px;\n width: 100%;\n ${({ theme }) => styledText(theme)};\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 0 300px 80px 300px;\n\n ${({ $isChatOpen }) =>\n $isChatOpen &&\n css`\n padding: 0 440px 80px 300px;\n `}\n }\n\n ${sidePanelOffset};\n ${({ $isChatOpen }) => !$isChatOpen && focusModeColumn};\n\n & p {\n color: ${({ theme }) => theme.colors.grayDark};\n hyphens: auto;\n }\n\n & pre {\n max-width: 100%;\n }\n\n ${styledAnchor};\n ${stylesLists};\n ${styledTable};\n\n & img,\n & video,\n & iframe {\n max-width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n\n & code:not([class]),\n & kbd {\n max-width: max-content;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n color: ${({ theme }) => theme.colors.dark};\n padding: 2px 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n overflow-wrap: anywhere;\n }\n\n & .lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n\n & .aspect-video {\n aspect-ratio: 16 / 9;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n`;\n\nexport const StyledMarkdownContainer = styled.div`\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex: 1;\n max-width: 640px;\n margin: auto;\n`;\n\ninterface Props {\n theme?: Theme;\n $isActive?: boolean;\n $isOpen?: boolean;\n $hasSectionBar?: boolean;\n}\n\nexport const StyledSidebar = styled.nav<Props>`\n position: fixed;\n overflow-y: auto;\n max-height: calc(\n 100dvh - ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px\n );\n width: 100%;\n z-index: 99;\n top: ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px;\n height: 100%;\n padding: 20px;\n opacity: 0;\n pointer-events: none;\n visibility: hidden;\n transition:\n transform 0.3s ease,\n opacity 0.3s ease,\n visibility 0s linear 0.3s;\n transform: translateY(30px);\n left: 0;\n background: ${({ theme }) => theme.colors.light};\n -webkit-overflow-scrolling: touch;\n display: flex;\n flex-direction: column;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n border-right: solid 1px ${({ theme }) => theme.colors.grayLight};\n transition: none;\n max-height: 100dvh;\n padding: 82px 20px 20px 20px;\n opacity: 1;\n pointer-events: all;\n visibility: visible;\n transform: translateY(0);\n /* Mixed over the page background rather than transparent so the panel\n reads as a filled surface in both modes. */\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 8%, ${theme.colors.light})`};\n top: 0;\n width: 280px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n transform: translateY(0);\n opacity: 1;\n pointer-events: all;\n visibility: visible;\n transition-delay: 0s;\n `}\n\n ${focusModeHide(\"left\")};\n\n ${mq(\"lg\")} {\n html[data-focus-mode] & {\n visibility: hidden;\n transition:\n transform 0.3s ease,\n opacity 0.3s ease,\n visibility 0s linear 0.3s;\n }\n }\n`;\n\nexport const StyledSidebarFooter = styled.div`\n padding: 22px 20px;\n position: sticky;\n border-top: 1px solid ${({ theme }) => theme.colors.grayLight};\n /* Same opaque mix as the sidebar panel so the sticky footer blends into it\n while still masking the list scrolling underneath. */\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 8%, ${theme.colors.light})`};\n margin: 0 -20px -20px;\n bottom: -20px;\n\n ${mq(\"lg\")} {\n padding: 16px 20px;\n }\n`;\n\nexport const StyledIndexSidebar = styled.ul<{ theme: Theme }>`\n display: none;\n list-style: none;\n margin: 0;\n padding: 0;\n position: fixed;\n top: 0;\n right: 0;\n width: 280px;\n height: 100dvh;\n overflow-y: auto;\n z-index: 1;\n padding: 82px 20px 20px 20px;\n background: ${({ theme }) => theme.colors.light};\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n -webkit-overflow-scrolling: touch;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n display: block;\n }\n\n & li {\n padding: 5px 0;\n }\n\n ${focusModeHide(\"right\")};\n\n ${mq(\"lg\")} {\n html[data-focus-mode] & {\n visibility: hidden;\n transition:\n transform 0.3s ease,\n opacity 0.3s ease,\n visibility 0s linear 0.3s;\n }\n }\n`;\n\nexport const StyledIndexSidebarLabel = styled.span<{ theme: Theme }>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\nexport const StyledIndexSidebarLi = styled.li<{\n theme: Theme;\n $isActive: boolean;\n}>`\n &::before {\n content: \"\";\n display: block;\n position: absolute;\n left: 0;\n height: 20px;\n width: 1px;\n background: transparent;\n transition: all 0.3s ease;\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n &::before {\n background: ${theme.colors.primary};\n }\n `}\n`;\n\nexport const StyledIndexSidebarLink = styled.a<{\n theme: Theme;\n $isActive: boolean;\n}>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme, $isActive }) =>\n $isActive ? theme.colors.primary : theme.colors.dark};\n font-weight: ${({ $isActive }) => ($isActive ? \"600\" : \"400\")};\n text-decoration: none;\n transition: all 0.3s ease;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\nexport const StyledSidebarList = styled.ul`\n list-style: none;\n margin: 0;\n padding: 0;\n\n &:last-of-type {\n margin-bottom: auto;\n }\n`;\n\nexport const StyledStrong = styled.strong<{ theme: Theme }>`\n font-weight: 600;\n ${({ theme }) => styledStrong(theme)};\n color: ${({ theme }) => theme.colors.accentStrong};\n display: inline-flex;\n align-items: center;\n gap: 8px;\n\n & svg {\n flex-shrink: 0;\n }\n`;\n\nexport const StyledSidebarListItem = styled.li`\n display: flex;\n gap: 10px;\n clear: both;\n`;\n\n// Shared appearance for every sidebar row - leaf links AND nested group\n// headers - so hover, active state, and the left rail read identically.\nconst sidebarRowStyles = css<Props>`\n text-decoration: none;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: 1.6;\n color: ${({ theme }) => theme.colors.accentMuted};\n padding: 5px 0 5px 20px;\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n transition: all 0.3s ease;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n\n & svg {\n flex-shrink: 0;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.accent};\n border-color: ${({ theme }) => theme.colors.primary};\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n color: ${theme.colors.accentStrong};\n border-color: ${theme.colors.primary};\n font-weight: 600;\n `};\n`;\n\n// The collapse chevron points right when closed and rotates to point down\n// when the group is open.\nconst sidebarChevron = css<Props>`\n & .lucide-chevron-right {\n margin-left: auto;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: rotate(90deg);\n `}\n }\n`;\n\nexport const StyledSidebarListItemLink = styled(Link)<Props>`\n ${sidebarRowStyles};\n`;\n\n// Compact HTTP-method label shown before a generated API endpoint link, colored\n// by verb so endpoints are scannable in the sidebar. Only rendered when a link\n// carries an `httpMethod` (endpoint pages do; hand-written pages do not).\n// The look is Badge's mono variation (tinted, solid when active); only\n// sidebar metrics are adjusted here.\nexport const StyledSidebarMethodTag = styled(Badge)`\n flex-shrink: 0;\n font-size: 9px;\n letter-spacing: 0.02em;\n padding: 1px 4px;\n border: none;\n`;\n\n// Nested navigation group. The header shares the link appearance/hover; a\n// non-navigable group is a single toggle button, while a group that is also a\n// page pairs a link with a chevron toggle. Children live in\n// StyledSidebarGroupContent, which animates open/closed via height 0 <-> auto\n// (enabled by interpolate-size in GlobalStyles, same as the Accordion).\nexport const StyledSidebarGroupButton = styled(Button)<Props>`\n ${resetButton};\n ${sidebarRowStyles};\n ${sidebarChevron};\n width: 100%;\n height: auto;\n min-height: 0;\n text-align: left;\n\n /* Buttons aren't covered by the global a:focus-visible ring, so this\n nav-row toggle carries its own copy of it. */\n &:focus-visible {\n outline: none;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupRow = styled.div<Props>`\n ${sidebarRowStyles};\n ${sidebarChevron};\n\n /* The row is a plain div, so it never matches :focus-visible itself. Ring the\n whole row when its inner link or chevron takes keyboard focus instead, to\n match the leaf-row focus treatment. */\n &:has(:focus-visible) {\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupLink = styled(Link)`\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n color: inherit;\n text-decoration: none;\n\n & svg {\n flex-shrink: 0;\n }\n\n /* Ring is drawn on the parent row via :has(:focus-visible); suppress the\n global a:focus-visible glow so it isn't drawn twice. */\n &:focus-visible {\n outline: none;\n box-shadow: none;\n }\n`;\n\nexport const StyledSidebarGroupChevron = styled(Button)`\n ${resetButton};\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: auto;\n height: auto;\n min-height: 0;\n padding: 0;\n border: 0;\n background: none;\n color: inherit;\n cursor: pointer;\n\n /* Ring is drawn on the parent row via :has(:focus-visible). */\n &:focus-visible {\n outline: none;\n }\n`;\n\nexport const StyledSidebarGroupContent = styled.ul.attrs<Props>(\n ({ $isOpen }) => ({\n \"aria-hidden\": !$isOpen,\n inert: !$isOpen,\n }),\n)<Props>`\n list-style: none;\n margin: 0;\n padding: 0;\n height: 0;\n overflow: clip;\n visibility: hidden;\n transition:\n height 0.3s ease,\n visibility 0s linear 0.3s;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n height: auto;\n visibility: visible;\n transition-delay: 0s;\n `}\n\n @media (prefers-reduced-motion: reduce) {\n transition: none;\n }\n`;\n\nexport const StyleMobileBar = styled(Button)<Props>`\n ${resetButton};\n position: fixed;\n z-index: 999;\n bottom: 0;\n right: 20px;\n font-size: ${({ theme }) => theme.fontSizes.strong.lg};\n line-height: ${({ theme }) => theme.fontSizes.strong.lg};\n box-shadow: ${({ theme }) => theme.shadows.sm};\n background: ${({ theme }) => theme.colors.primary};\n color: ${({ theme }) => theme.colors.surface};\n backdrop-filter: blur(10px);\n -webkit-backdrop-filter: blur(10px);\n padding: 10px;\n border-radius: 100px;\n margin: 0 0 20px 0;\n font-weight: 600;\n display: flex;\n justify-content: flex-start;\n width: auto;\n height: auto;\n min-height: 0;\n\n ${mq(\"lg\")} {\n display: none;\n }\n\n ${({ $isActive }) => $isActive && `position: fixed;`};\n`;\n\nexport const StyledMobileBurger = styled.span<Props>`\n display: block;\n margin: auto 0;\n width: 18px;\n height: 18px;\n position: relative;\n overflow: hidden;\n background: transparent;\n position: relative;\n transform: scale(0.8);\n\n &::before,\n &::after {\n content: \"\";\n display: block;\n position: absolute;\n width: 18px;\n height: 3px;\n border-radius: 3px;\n background: ${({ theme }) => theme.colors.surface};\n transition: all 0.3s ease;\n }\n\n &::before {\n top: 3px;\n }\n\n &::after {\n bottom: 3px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n &::before {\n transform: translateY(5px) rotate(45deg);\n }\n\n &::after {\n transform: translateY(-4px) rotate(-45deg);\n }\n `};\n`;\n\n// Visually hidden but present for crawlers and agents: points at llms.txt and\n// the .md mirrors. Rendered as the first element of the site layout.\nconst StyledLlmsDirective = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n border: 0;\n`;\n\nfunction LlmsDirective() {\n return (\n <StyledLlmsDirective data-markdown-ignore>\n <a href=\"/llms.txt\">Documentation index for AI agents (llms.txt)</a>.\n Markdown versions of every page are available by appending .md to the page\n URL. The full corpus is at <a href=\"/llms-full.txt\">/llms-full.txt</a>.\n </StyledLlmsDirective>\n );\n}\n\ninterface DocsWrapperProps {\n children: React.ReactNode;\n}\n\nfunction DocsWrapper({ children }: DocsWrapperProps) {\n return <StyledDocsWrapper>{children}</StyledDocsWrapper>;\n}\n\nfunction DocsSidebar({ children }: DocsProps) {\n return <StyledDocsSidebar>{children}</StyledDocsSidebar>;\n}\n\nfunction DocsContainer({ children }: DocsProps) {\n const { isOpen } = useChat();\n\n return (\n <StyledDocsContainer $isChatOpen={isOpen}>{children}</StyledDocsContainer>\n );\n}\n\nexport {\n DocsWrapper,\n DocsSidebar,\n DocsContainer,\n LlmsDirective,\n SectionBarContext,\n SectionBarProvider,\n};\n";
|
|
1
|
+
export declare const docsComponentsTemplate = "\"use client\";\nimport React, { createContext } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport {\n Button,\n resetButton,\n styledSmall,\n styledStrong,\n styledText,\n useChat,\n} from \"cherry-styled-components\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n focusModeColumn,\n focusModeHide,\n sidePanelOffset,\n styledAnchor,\n styledTable,\n stylesLists,\n} from \"@/components/layout/SharedStyled\";\nimport { Badge } from \"@/components/layout/Badge\";\nimport { useVariant } from \"@/components/useVariant\";\nimport { joinVariantSlug } from \"@/utils/variants\";\n\nconst SectionBarContext = createContext(false);\n\nfunction SectionBarProvider({\n hasSectionBar,\n children,\n}: {\n hasSectionBar: boolean;\n children: React.ReactNode;\n}) {\n return (\n <SectionBarContext.Provider value={hasSectionBar}>\n {children}\n </SectionBarContext.Provider>\n );\n}\n\ninterface DocsProps {\n children: React.ReactNode;\n}\n\nconst StyledDocsWrapper = styled.div<{ theme: Theme }>`\n position: relative;\n`;\n\nconst StyledDocsSidebar = styled.div<{ theme: Theme }>`\n clear: both;\n`;\n\n// The <main> landmark wraps only the article content: the sidebar, footer,\n// and nav render outside it so content extractors and assistive tech start at\n// the article.\nconst StyledDocsContainer = styled.main<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n position: relative;\n padding: 0 20px 100px 20px;\n width: 100%;\n ${({ theme }) => styledText(theme)};\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 0 300px 80px 300px;\n\n ${({ $isChatOpen }) =>\n $isChatOpen &&\n css`\n padding: 0 440px 80px 300px;\n `}\n }\n\n ${sidePanelOffset};\n ${({ $isChatOpen }) => !$isChatOpen && focusModeColumn};\n\n & p {\n color: ${({ theme }) => theme.colors.grayDark};\n hyphens: auto;\n }\n\n & pre {\n max-width: 100%;\n }\n\n ${styledAnchor};\n ${stylesLists};\n ${styledTable};\n\n & img,\n & video,\n & iframe {\n max-width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n\n & code:not([class]),\n & kbd {\n max-width: max-content;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n color: ${({ theme }) => theme.colors.dark};\n padding: 2px 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n overflow-wrap: anywhere;\n }\n\n & .lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n\n & .aspect-video {\n aspect-ratio: 16 / 9;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n`;\n\nexport const StyledMarkdownContainer = styled.div`\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex: 1;\n max-width: 640px;\n margin: auto;\n`;\n\ninterface Props {\n theme?: Theme;\n $isActive?: boolean;\n $isOpen?: boolean;\n $hasSectionBar?: boolean;\n}\n\nexport const StyledSidebar = styled.nav<Props>`\n position: fixed;\n overflow-y: auto;\n max-height: calc(\n 100dvh - ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px\n );\n width: 100%;\n z-index: 99;\n top: ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px;\n height: 100%;\n padding: 20px;\n opacity: 0;\n pointer-events: none;\n visibility: hidden;\n transition:\n transform 0.3s ease,\n opacity 0.3s ease,\n visibility 0s linear 0.3s;\n transform: translateY(30px);\n left: 0;\n background: ${({ theme }) => theme.colors.light};\n -webkit-overflow-scrolling: touch;\n display: flex;\n flex-direction: column;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n border-right: solid 1px ${({ theme }) => theme.colors.grayLight};\n transition: none;\n max-height: 100dvh;\n padding: 82px 20px 20px 20px;\n opacity: 1;\n pointer-events: all;\n visibility: visible;\n transform: translateY(0);\n /* Mixed over the page background rather than transparent so the panel\n reads as a filled surface in both modes. */\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 8%, ${theme.colors.light})`};\n top: 0;\n width: 280px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n transform: translateY(0);\n opacity: 1;\n pointer-events: all;\n visibility: visible;\n transition-delay: 0s;\n `}\n\n ${focusModeHide(\"left\")};\n\n ${mq(\"lg\")} {\n html[data-focus-mode] & {\n visibility: hidden;\n transition:\n transform 0.3s ease,\n opacity 0.3s ease,\n visibility 0s linear 0.3s;\n }\n }\n`;\n\n// One row of 30px controls: the focus-mode toggle, the language and version\n// switchers, then the theme toggle. The focus toggle is fixed rather than a\n// child (it outlives the sidebar in focus mode), so on the rail the row's own\n// padding leaves its 30px plus a gap free at the left.\nexport const StyledSidebarFooter = styled.div`\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 22px 20px;\n position: sticky;\n border-top: 1px solid ${({ theme }) => theme.colors.grayLight};\n /* Same opaque mix as the sidebar panel so the sticky footer blends into it\n while still masking the list scrolling underneath. */\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 8%, ${theme.colors.light})`};\n margin: 0 -20px -20px;\n bottom: -20px;\n\n ${mq(\"lg\")} {\n padding: 16px 20px 16px 58px;\n }\n`;\n\n// The theme toggle's slot takes whatever the switchers leave, so the toggle\n// stays beside them in the mobile menu and holds the right end of the rail.\n// A plain flex row rather than Cherry's Flex: the slot has to grow, which is a\n// property of the child, and styled(Flex) would swallow Flex's own $-prefixed\n// props on the way through.\nexport const StyledSidebarFooterToggle = styled.div`\n display: flex;\n flex: 1;\n justify-content: flex-start;\n\n /* On the rail the switchers claim the free width when both are configured,\n so the toggle keeps its own size and is pushed to the right end. */\n ${mq(\"lg\")} {\n flex: 0 0 auto;\n margin-left: auto;\n }\n`;\n\nexport const StyledIndexSidebar = styled.ul<{ theme: Theme }>`\n display: none;\n list-style: none;\n margin: 0;\n padding: 0;\n position: fixed;\n top: 0;\n right: 0;\n width: 280px;\n height: 100dvh;\n overflow-y: auto;\n z-index: 1;\n padding: 82px 20px 20px 20px;\n background: ${({ theme }) => theme.colors.light};\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n -webkit-overflow-scrolling: touch;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n display: block;\n }\n\n & li {\n padding: 5px 0;\n }\n\n ${focusModeHide(\"right\")};\n\n ${mq(\"lg\")} {\n html[data-focus-mode] & {\n visibility: hidden;\n transition:\n transform 0.3s ease,\n opacity 0.3s ease,\n visibility 0s linear 0.3s;\n }\n }\n`;\n\nexport const StyledIndexSidebarLabel = styled.span<{ theme: Theme }>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\nexport const StyledIndexSidebarLi = styled.li<{\n theme: Theme;\n $isActive: boolean;\n}>`\n &::before {\n content: \"\";\n display: block;\n position: absolute;\n left: 0;\n height: 20px;\n width: 1px;\n background: transparent;\n transition: all 0.3s ease;\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n &::before {\n background: ${theme.colors.primary};\n }\n `}\n`;\n\nexport const StyledIndexSidebarLink = styled.a<{\n theme: Theme;\n $isActive: boolean;\n}>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme, $isActive }) =>\n $isActive ? theme.colors.primary : theme.colors.dark};\n font-weight: ${({ $isActive }) => ($isActive ? \"600\" : \"400\")};\n text-decoration: none;\n transition: all 0.3s ease;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\nexport const StyledSidebarList = styled.ul`\n list-style: none;\n margin: 0;\n padding: 0;\n\n &:last-of-type {\n margin-bottom: auto;\n }\n`;\n\nexport const StyledStrong = styled.strong<{ theme: Theme }>`\n font-weight: 600;\n ${({ theme }) => styledStrong(theme)};\n color: ${({ theme }) => theme.colors.accentStrong};\n display: inline-flex;\n align-items: center;\n gap: 8px;\n\n & svg {\n flex-shrink: 0;\n }\n`;\n\nexport const StyledSidebarListItem = styled.li`\n display: flex;\n gap: 10px;\n clear: both;\n`;\n\n// Shared appearance for every sidebar row - leaf links AND nested group\n// headers - so hover, active state, and the left rail read identically.\nconst sidebarRowStyles = css<Props>`\n text-decoration: none;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: 1.6;\n color: ${({ theme }) => theme.colors.accentMuted};\n padding: 5px 0 5px 20px;\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n transition: all 0.3s ease;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n\n & svg {\n flex-shrink: 0;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.accent};\n border-color: ${({ theme }) => theme.colors.primary};\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n color: ${theme.colors.accentStrong};\n border-color: ${theme.colors.primary};\n font-weight: 600;\n `};\n`;\n\n// The collapse chevron points right when closed and rotates to point down\n// when the group is open.\nconst sidebarChevron = css<Props>`\n & .lucide-chevron-right {\n margin-left: auto;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: rotate(90deg);\n `}\n }\n`;\n\nexport const StyledSidebarListItemLink = styled(Link)<Props>`\n ${sidebarRowStyles};\n`;\n\n// Compact HTTP-method label shown before a generated API endpoint link, colored\n// by verb so endpoints are scannable in the sidebar. Only rendered when a link\n// carries an `httpMethod` (endpoint pages do; hand-written pages do not).\n// The look is Badge's mono variation (tinted, solid when active); only\n// sidebar metrics are adjusted here.\nexport const StyledSidebarMethodTag = styled(Badge)`\n flex-shrink: 0;\n font-size: 9px;\n letter-spacing: 0.02em;\n padding: 1px 4px;\n border: none;\n`;\n\n// Nested navigation group. The header shares the link appearance/hover; a\n// non-navigable group is a single toggle button, while a group that is also a\n// page pairs a link with a chevron toggle. Children live in\n// StyledSidebarGroupContent, which animates open/closed via height 0 <-> auto\n// (enabled by interpolate-size in GlobalStyles, same as the Accordion).\nexport const StyledSidebarGroupButton = styled(Button)<Props>`\n ${resetButton};\n ${sidebarRowStyles};\n ${sidebarChevron};\n width: 100%;\n height: auto;\n min-height: 0;\n text-align: left;\n\n /* Buttons aren't covered by the global a:focus-visible ring, so this\n nav-row toggle carries its own copy of it. */\n &:focus-visible {\n outline: none;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupRow = styled.div<Props>`\n ${sidebarRowStyles};\n ${sidebarChevron};\n\n /* The row is a plain div, so it never matches :focus-visible itself. Ring the\n whole row when its inner link or chevron takes keyboard focus instead, to\n match the leaf-row focus treatment. */\n &:has(:focus-visible) {\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupLink = styled(Link)`\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n color: inherit;\n text-decoration: none;\n\n & svg {\n flex-shrink: 0;\n }\n\n /* Ring is drawn on the parent row via :has(:focus-visible); suppress the\n global a:focus-visible glow so it isn't drawn twice. */\n &:focus-visible {\n outline: none;\n box-shadow: none;\n }\n`;\n\nexport const StyledSidebarGroupChevron = styled(Button)`\n ${resetButton};\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: auto;\n height: auto;\n min-height: 0;\n padding: 0;\n border: 0;\n background: none;\n color: inherit;\n cursor: pointer;\n\n /* Ring is drawn on the parent row via :has(:focus-visible). */\n &:focus-visible {\n outline: none;\n }\n`;\n\nexport const StyledSidebarGroupContent = styled.ul.attrs<Props>(\n ({ $isOpen }) => ({\n \"aria-hidden\": !$isOpen,\n inert: !$isOpen,\n }),\n)<Props>`\n list-style: none;\n margin: 0;\n padding: 0;\n height: 0;\n overflow: clip;\n visibility: hidden;\n transition:\n height 0.3s ease,\n visibility 0s linear 0.3s;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n height: auto;\n visibility: visible;\n transition-delay: 0s;\n `}\n\n @media (prefers-reduced-motion: reduce) {\n transition: none;\n }\n`;\n\nexport const StyleMobileBar = styled(Button)<Props>`\n ${resetButton};\n position: fixed;\n z-index: 999;\n bottom: 0;\n right: 20px;\n font-size: ${({ theme }) => theme.fontSizes.strong.lg};\n line-height: ${({ theme }) => theme.fontSizes.strong.lg};\n box-shadow: ${({ theme }) => theme.shadows.sm};\n background: ${({ theme }) => theme.colors.primary};\n color: ${({ theme }) => theme.colors.surface};\n backdrop-filter: blur(10px);\n -webkit-backdrop-filter: blur(10px);\n padding: 10px;\n border-radius: 100px;\n margin: 0 0 20px 0;\n font-weight: 600;\n display: flex;\n justify-content: flex-start;\n width: auto;\n height: auto;\n min-height: 0;\n\n ${mq(\"lg\")} {\n display: none;\n }\n\n ${({ $isActive }) => $isActive && `position: fixed;`};\n`;\n\nexport const StyledMobileBurger = styled.span<Props>`\n display: block;\n margin: auto 0;\n width: 18px;\n height: 18px;\n position: relative;\n overflow: hidden;\n background: transparent;\n position: relative;\n transform: scale(0.8);\n\n &::before,\n &::after {\n content: \"\";\n display: block;\n position: absolute;\n width: 18px;\n height: 3px;\n border-radius: 3px;\n background: ${({ theme }) => theme.colors.surface};\n transition: all 0.3s ease;\n }\n\n &::before {\n top: 3px;\n }\n\n &::after {\n bottom: 3px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n &::before {\n transform: translateY(5px) rotate(45deg);\n }\n\n &::after {\n transform: translateY(-4px) rotate(-45deg);\n }\n `};\n`;\n\n// Visually hidden but present for crawlers and agents: points at llms.txt and\n// the .md mirrors. Rendered as the first element of the site layout.\nconst StyledLlmsDirective = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n border: 0;\n`;\n\nfunction LlmsDirective() {\n // Every language and version has its own llms.txt under its URL prefix.\n const { prefix } = useVariant();\n const indexHref = \"/\" + joinVariantSlug(prefix, \"llms.txt\");\n const fullHref = \"/\" + joinVariantSlug(prefix, \"llms-full.txt\");\n return (\n <StyledLlmsDirective data-markdown-ignore>\n <a href={indexHref}>Documentation index for AI agents (llms.txt)</a>.\n Markdown versions of every page are available by appending .md to the page\n URL. The full corpus is at <a href={fullHref}>{fullHref}</a>.\n </StyledLlmsDirective>\n );\n}\n\ninterface DocsWrapperProps {\n children: React.ReactNode;\n}\n\nfunction DocsWrapper({ children }: DocsWrapperProps) {\n return <StyledDocsWrapper>{children}</StyledDocsWrapper>;\n}\n\nfunction DocsSidebar({ children }: DocsProps) {\n return <StyledDocsSidebar>{children}</StyledDocsSidebar>;\n}\n\nfunction DocsContainer({ children, lang }: DocsProps & { lang?: string }) {\n const { isOpen } = useChat();\n\n return (\n <StyledDocsContainer $isChatOpen={isOpen} lang={lang}>\n {children}\n </StyledDocsContainer>\n );\n}\n\nexport {\n DocsWrapper,\n DocsSidebar,\n DocsContainer,\n LlmsDirective,\n SectionBarContext,\n SectionBarProvider,\n};\n";
|