import { createImageBlockConfig, imageParse } from "@blocknote/core"; import { RiImage2Fill } from "react-icons/ri"; import { createReactBlockSpec, ReactCustomBlockRenderProps, } from "../../schema/ReactBlockSpec.js"; import { useResolveUrl } from "../File/useResolveUrl.js"; import { FigureWithCaption } from "../File/helpers/toExternalHTML/FigureWithCaption.js"; import { ResizableFileBlockWrapper } from "../File/helpers/render/ResizableFileBlockWrapper.js"; import { LinkWithCaption } from "../File/helpers/toExternalHTML/LinkWithCaption.js"; export const ImagePreview = ( props: Omit< ReactCustomBlockRenderProps, "contentRef" >, ) => { const resolved = useResolveUrl(props.block.props.url!); return ( {props.block.props.caption ); }; export const ImageToExternalHTML = ( props: Omit< ReactCustomBlockRenderProps, "contentRef" >, ) => { if (!props.block.props.url) { return

Add image

; } const image = props.block.props.showPreview ? ( { ) : ( {props.block.props.name || props.block.props.url} ); if (props.block.props.caption) { return props.block.props.showPreview ? ( {image} ) : ( {image} ); } return image; }; export const ImageBlock = ( props: ReactCustomBlockRenderProps, ) => { return ( } > ); }; export const ReactImageBlock = createReactBlockSpec( createImageBlockConfig, (config) => ({ meta: { fileBlockAccept: ["image/*"], }, render: ImageBlock, parse: imageParse(config), toExternalHTML: ImageToExternalHTML, runsBefore: ["file"], }), );