import type { GenericNode } from 'mystjs'; import { OutputSummaryKind } from '@curvenote/blocks/dist/blocks/output'; import { DangerousHTML, MaybeLongContent } from './components'; import classNames from 'classnames'; const SUPORTED_KINDS = new Set([ OutputSummaryKind.stream, OutputSummaryKind.image, OutputSummaryKind.error, OutputSummaryKind.text, // Both of these kinds are OK as **long as this is a static site** OutputSummaryKind.json, OutputSummaryKind.html, ]); const PRIORITIZED_FALLBACK_KINDS = [OutputSummaryKind.image, OutputSummaryKind.text]; export const Output = (node: GenericNode) => { let outputComponent = null; let data: | { kind: string; content: string; content_type?: string; path?: string } | undefined; if (SUPORTED_KINDS.has(node.data.kind)) { // The kind is the default if it is supported here! data = node.data.items[node.data.kind]; } else { // if we don't support the primary kind, try and find a fallback PRIORITIZED_FALLBACK_KINDS.forEach((kind) => { if (!data && node.data.items[kind]) data = node.data.items[kind]; }); } switch (data?.kind) { case OutputSummaryKind.image: outputComponent = ; break; case OutputSummaryKind.error: outputComponent = (
{content}
} /> ); break; case OutputSummaryKind.text: outputComponent = (

{content}

} /> ); break; case OutputSummaryKind.stream: case OutputSummaryKind.json: outputComponent = ( (
{content}
)} /> ); break; case OutputSummaryKind.html: outputComponent = ( } /> ); break; default: console.log(node.data); console.log(`Missing output: ${node.data.kind}`); } return (
{outputComponent}
); }; export const outputRenderers = { output: Output, };