import React from "react";
import getImageUrl, { Image as ImageType } from "../../utils/getImageUrl";
import { Image } from "../Image";
import { Link } from "../Link";
import { Text } from "../Text";
import { VideoEmbed } from "../VideoEmbed";
import { View } from "../View";
import DescriptionListNode from "./DescriptionListNode";
import ListNode from "./ListNode";
import TextNode, { withText } from "./TextNode";
import { BlockSpec } from "./index";
import mapTree from "./mapTree";
/* eslint-disable camelcase */
const typeMap = {
blockquote: ({ children }) => {children},
heading: ({ node }) => (
{node.text}
),
paragraph: ({ children }) => {children},
image: ({ node }) => {
const imageSource = node.image
? getImageUrl({ file: node.image } as ImageType)
: getImageUrl(node);
const imageMeta = node.image
? node.image?.attributes?.meta
: node.file?.attributes?.meta;
return (
);
},
hard_break: View,
bullet_list: (props) => ,
ordered_list: (props) => ,
description_list: (props) => ,
description_item: ({ children }) => children,
list_item: ({ children }) => children,
// code_block: "code",
text: TextNode,
video: ({ node }) => (
),
};
/* eslint-enable camelcase */
const markMap = {
em: withText({ italic: true }),
strong: withText({ bold: true }),
code: withText({ as: "code" }),
link: Link,
};
type Props = {
content: BlockSpec[];
typeMap?: {};
markMap?: {};
};
const StructuredContent = (props: Props) => {
const options = {
typeMap: { ...typeMap, ...(props.typeMap || {}) },
markMap: { ...markMap, ...(props.markMap || {}) },
};
return (
<>{props.content.map((child, index) => mapTree(child, index, options))}>
);
};
export default StructuredContent;