mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
c0991b4ff7
* Initial migration
* Remove ExperimentalPackageCallout
* Remove Callout imports
* Add missing dep
* Update postgres-world.mdx
* Add missing deps, remove unused files
* Restore homepage css
* Update logo, fix homepage
* Update run-anywhere.tsx
* Remove duplicate h1 tags
* Fix package install commands
* Update global.css
* Update code-block.tsx
* Fix framework descriptions
* Remove unused files
* Fix steps
* Update sidebar.tsx
* Remove excess horizontal rules
* Remove unused components
* Cleanup home code-block component
* Update route.ts
* Add missing feed dep
* Rename middleware to proxy
* Update next config
* Update route.tsx
* Move generateDefinition call into tsx
* Update page.tsx
* Update sidebar.tsx
* Update layout.tsx
* Remove unused files
* Fix nav
* Update route.ts
* Remove deprecated lint:links
* Load fonts locally
* Update layout.tsx
* Update route.ts
* Update Geistdocs
* Update hero.tsx
* Update search.tsx
* Update search.tsx
* docs: update url structure in chat tools example
* chore: replace gpt-5 reasoning with gpt-5.1
* docs: update instructions for llm to be more workflow-centric
* Revert "docs: update instructions for llm to be more workflow-centric"
This reverts commit 3852820988.
* Update pnpm-lock.yaml
* Update home-layout.tsx
* Update layout.tsx
* Update pnpm-workspace.yaml
---------
Co-authored-by: Adrian Lam <me@adriandlam.com>
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
'use client';
|
|
|
|
import { useTheme } from 'next-themes';
|
|
import { use, useEffect, useId, useState } from 'react';
|
|
|
|
export const Mermaid = ({ chart }: { chart: string }) => {
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
if (!mounted) {
|
|
return null;
|
|
}
|
|
|
|
return <MermaidContent chart={chart} />;
|
|
};
|
|
|
|
const cache = new Map<string, Promise<unknown>>();
|
|
|
|
function cachePromise<T>(
|
|
key: string,
|
|
setPromise: () => Promise<T>
|
|
): Promise<T> {
|
|
const cached = cache.get(key);
|
|
if (cached) {
|
|
return cached as Promise<T>;
|
|
}
|
|
|
|
const promise = setPromise();
|
|
cache.set(key, promise);
|
|
return promise;
|
|
}
|
|
|
|
function MermaidContent({ chart }: { chart: string }) {
|
|
const id = useId();
|
|
const { resolvedTheme } = useTheme();
|
|
const { default: mermaid } = use(
|
|
cachePromise('mermaid', () => import('mermaid'))
|
|
);
|
|
|
|
mermaid.initialize({
|
|
startOnLoad: false,
|
|
securityLevel: 'loose',
|
|
fontFamily: 'inherit',
|
|
themeCSS: 'margin: 1.5rem auto 0;',
|
|
theme: resolvedTheme === 'dark' ? 'dark' : 'default',
|
|
});
|
|
|
|
const { svg, bindFunctions } = use(
|
|
cachePromise(`${chart}-${resolvedTheme}`, () =>
|
|
mermaid.render(id, chart.replaceAll('\\n', '\n'))
|
|
)
|
|
);
|
|
|
|
return (
|
|
<div
|
|
// biome-ignore lint/security/noDangerouslySetInnerHtml: "this is needed."
|
|
dangerouslySetInnerHTML={{ __html: svg }}
|
|
ref={(container) => {
|
|
if (container) {
|
|
bindFunctions?.(container);
|
|
}
|
|
}}
|
|
/>
|
|
);
|
|
}
|