From aae3763ddb8aa5516fa8b3bfc724124fbdeef928 Mon Sep 17 00:00:00 2001 From: ladybluenotes Date: Mon, 12 Jan 2026 10:28:59 -0800 Subject: [PATCH 1/3] feat: add framework support to documentation components --- src/components/Doc.tsx | 14 +++ src/components/Toc.tsx | 16 ++- .../$version.docs.framework.$framework.$.tsx | 3 +- src/utils/markdown/plugins/collectHeadings.ts | 28 +++++ .../plugins/transformFrameworkComponent.ts | 101 +++++++++++------- src/utils/markdown/processor.ts | 7 +- 6 files changed, 122 insertions(+), 47 deletions(-) diff --git a/src/components/Doc.tsx b/src/components/Doc.tsx index 76d6c94ce..c099efbb0 100644 --- a/src/components/Doc.tsx +++ b/src/components/Doc.tsx @@ -9,6 +9,8 @@ import { renderMarkdown } from '~/utils/markdown' import { DocBreadcrumb } from './DocBreadcrumb' import { MarkdownContent } from '~/components/markdown' import type { ConfigSchema } from '~/utils/config' +import { useLocalCurrentFramework } from './FrameworkSelect' +import { useParams } from '@tanstack/react-router' type DocProps = { title: string @@ -28,6 +30,8 @@ type DocProps = { config?: ConfigSchema // Footer content rendered after markdown footer?: React.ReactNode + // Optional framework to use (overrides URL and local storage) + framework?: string } export function Doc({ @@ -45,6 +49,7 @@ export function Doc({ pagePath, config, footer, + framework: frameworkProp, }: DocProps) { // Extract headings synchronously during render to avoid hydration mismatch const { headings, markup } = React.useMemo( @@ -52,6 +57,14 @@ export function Doc({ [content], ) + // Get current framework from prop, URL params, or local storage + const { framework: paramsFramework } = useParams({ strict: false }) + const localCurrentFramework = useLocalCurrentFramework() + const currentFramework = React.useMemo(() => { + const fw = frameworkProp || paramsFramework || localCurrentFramework.currentFramework || 'react' + return typeof fw === 'string' ? fw.toLowerCase() : fw + }, [frameworkProp, paramsFramework, localCurrentFramework.currentFramework]) + const isTocVisible = shouldRenderToc && headings.length > 1 const markdownContainerRef = React.useRef(null) @@ -170,6 +183,7 @@ export function Doc({ colorFrom={colorFrom} colorTo={colorTo} textColor={textColor} + currentFramework={currentFramework} /> )} diff --git a/src/components/Toc.tsx b/src/components/Toc.tsx index b4c4f84ce..9f2e59669 100644 --- a/src/components/Toc.tsx +++ b/src/components/Toc.tsx @@ -18,9 +18,21 @@ type TocProps = { colorTo?: string textColor?: string activeHeadings: Array + currentFramework?: string } -export function Toc({ headings, textColor, activeHeadings }: TocProps) { +export function Toc({ headings, textColor, activeHeadings, currentFramework }: TocProps) { + // Filter headings based on framework scope + const visibleHeadings = React.useMemo(() => { + return headings.filter((heading) => { + console.log(heading) + if (heading.framework) { + return currentFramework && heading.framework === currentFramework.toLowerCase() + } + // If no framework attribute, always show (not framework-scoped) + return true + }) + }, [headings, currentFramework]) return (