import { BlockMapping, DefaultBlockSchema, DefaultProps, createPageBreakBlockConfig, StyledText, } from "@blocknote/core"; import { multiColumnSchema } from "@blocknote/xl-multi-column"; import { Image, Link, Path, Svg, Text, View } from "@react-pdf/renderer"; import { BULLET_MARKER, CHECK_MARKER_CHECKED, CHECK_MARKER_UNCHECKED, CHEVRON_MARKER, ListItem, } from "../util/listItem.js"; import { Table } from "../util/table/Table.js"; const PIXELS_PER_POINT = 0.75; const FONT_SIZE = 16; export const pdfBlockMappingForDefaultSchema: BlockMapping< DefaultBlockSchema & { pageBreak: ReturnType; } & typeof multiColumnSchema.blockSchema, any, any, React.ReactElement, React.ReactElement | React.ReactElement > = { paragraph: (block, exporter) => { // const style = blocknoteDefaultPropsToReactPDFStyle(block.props); return ( {exporter.transformInlineContent(block.content)} ); }, toggleListItem: (block, exporter) => { return ( {exporter.transformInlineContent(block.content)} ); }, bulletListItem: (block, exporter) => { // const style = t(block.props); return ( {exporter.transformInlineContent(block.content)} ); }, numberedListItem: (block, exporter, _nestingLevel, numberedListIndex) => { // const style = blocknoteDefaultPropsToReactPDFStyle(block.props); // console.log("NUMBERED LIST ITEM", block.props.textAlignment, style); return ( {exporter.transformInlineContent(block.content)} ); }, // would be nice to have pdf checkboxes: // https://github.com/diegomura/react-pdf/issues/2103 checkListItem: (block, exporter) => { return ( {exporter.transformInlineContent(block.content)} ); }, heading: (block, exporter) => { const levelFontSizeEM = { 1: 2, 2: 1.5, 3: 1.17, 4: 1, 5: 0.83, 6: 0.67, }[block.props.level as 1 | 2 | 3 | 4 | 5 | 6]; return ( {exporter.transformInlineContent(block.content)} ); }, quote: (block, exporter) => { return ( {exporter.transformInlineContent(block.content)} ); }, codeBlock: (block) => { // Code blocks should always contain a single `StyledText` inline content. // However, if this is not the case for whatever reason, we can merge the // text content of all `StyledText` content in them. const textContent = (block.content as StyledText[]) .map((item) => item.text) .join(""); const lines = textContent.split("\n").map((line, index) => { const indent = line.match(/^\s*/)?.[0].length || 0; return ( {line.trimStart() || <> } ); }); return ( {lines} ); }, pageBreak: () => { return ; }, divider: () => { return ( ); }, column: (block, _exporter, _nestingLevel, _numberedListIndex, children) => { return {children}; }, columnList: ( _block, _exporter, _nestingLevel, _numberedListIndex, children, ) => { return ( {children} ); }, audio: (block, exporter) => { return ( {file( block.props, "Open audio file", , exporter, )} {caption(block.props, exporter)} ); }, video: (block, exporter) => { return ( {file( block.props, "Open video file", , exporter, )} {caption(block.props, exporter)} ); }, file: (block, exporter) => { return ( {file( block.props, "Open file", , exporter, )} {caption(block.props, exporter)} ); }, image: async (block, t) => { return ( {caption(block.props, t)} ); }, table: (block, t) => { return ( ); }, }; function file( props: Partial, defaultText: string, icon: React.ReactElement, _exporter: any, ) { const PIXELS_PER_POINT = 0.75; return ( {icon} {props.name || defaultText} ); } function caption( props: Partial, _exporter: any, ) { if (!props.caption) { return undefined; } return ( {props.caption} ); }