import { ClientOnly, CodeBlock, IconButton } from "@chakra-ui/react"; import { type ComponentProps, useMemo } from "react"; import type { MarkOptional } from "ts-essentials"; import { safeStringify } from "../../core/StringUtils"; import { shikiAdapter } from "./shikiAdapter"; // const shikiAdapter = createShikiAdapter>({ // async load() { // const { createHighlighter } = await import("shiki") // return createHighlighter({ // langs: ["json", "plaintext"], // themes: ["github-dark", "github-light"], // }) // }, // theme: { // light: "github-light", // dark: "github-dark", // }, // }); export interface ChakraCodeBaseProps { language?: string title?: string maxHeight?: string maxLines?: number collapsedMaxHeight?: string } export type ChakraCodelessBlock = Omit, 'code'> export type ChakraCodeBlockProps = Omit & ChakraCodeBaseProps & { code: string | object } const DEFAULT_MAX_HEIGHT = '70vh', DEFAULT_COLLAPSED_MAX_HEIGHT = '320px', DEFAULT_LANGUAGE = 'json'; export const ChakraCodeBlock = (props: ChakraCodeBlockProps) => { const { maxHeight = DEFAULT_MAX_HEIGHT, maxLines, collapsedMaxHeight = DEFAULT_COLLAPSED_MAX_HEIGHT, language = DEFAULT_LANGUAGE, code = '', ...rest } = props; const contentProps: ComponentProps = maxLines === undefined ? { maxHeight, overflowY: 'auto' } : { css: { "--code-block-max-height": collapsedMaxHeight } }; const codeVal = useMemo(() => { if (typeof code === 'string') { return code; } return safeStringify(code); }, [code]); return ( Loading...}> {() => ( {props.title ?? ' '} )} ) } export const ChakraCodeBlockShort = (props: ChakraCodeBlockProps) => ; export type ChakraPlainBlockProps = MarkOptional & ChakraCodeBaseProps & {code?: string | object}; export const ChakraPlainBlock = (props: ChakraPlainBlockProps) => { const { maxHeight = DEFAULT_MAX_HEIGHT, maxLines, collapsedMaxHeight = DEFAULT_COLLAPSED_MAX_HEIGHT, code, ...rest } = props; const contentProps: ComponentProps = maxLines === undefined ? { maxHeight, overflowY: 'auto' } : { css: { "--code-block-max-height": collapsedMaxHeight } }; const codeVal = useMemo(() => { if(code === undefined) { return ' '; } if (typeof code === 'string') { return code; } return safeStringify(code); }, [code]); let header: React.JSX.Element | null; if(props.title === undefined && maxLines === undefined) { header = null; } else { header = ( {props.title} {maxLines !== undefined ? ( ) : null} ); } return ( {header} {props.children ?? } ); } export const ChakraPlainBlockShort = (props: ChakraPlainBlockProps) => ;