editor-react-parser
Version:
A renderer for editorjs block data for react
34 lines (33 loc) • 2.56 kB
JavaScript
import React from "react";
import AlertBlock from "./BlockParsers/alert";
import ParagraphBlock from "./BlockParsers/paragraph";
import CodeBlock from "./BlockParsers/code";
import DelimiterBlock from "./BlockParsers/delimiter";
import HeaderBlock from "./BlockParsers/header";
import ImageBlock from "./BlockParsers/image";
import ColumnsBlock from "./BlockParsers/columns";
import QuoteBlock from "./BlockParsers/quote";
import TableBlock from "./BlockParsers/table";
import ListBlock from "./BlockParsers/list";
import ErrorBlock from "./BlockParsers/error";
import Raw from "./BlockParsers/raw";
export var BlockParser = function (_a) {
var data = _a.data, config = _a.config;
return data.blocks.map(function (blockData) { return parseData(blockData, config); });
};
var parseData = function (item, config) {
return ({
raw: React.createElement(Raw, { key: item.id, item: item }),
header: React.createElement(HeaderBlock, { key: item.id, item: item }),
code: React.createElement(CodeBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.code }),
list: React.createElement(ListBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.list }),
alert: React.createElement(AlertBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.alert }),
quote: React.createElement(QuoteBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.quote }),
table: React.createElement(TableBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.table }),
image: React.createElement(ImageBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.image }),
delimiter: (React.createElement(DelimiterBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.delimiter })),
paragraph: (React.createElement(ParagraphBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.paragraph })),
columns: (React.createElement(ColumnsBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.columns, blockRendererConfig: config })),
}[item.type] || (React.createElement(ErrorBlock, { key: item.id, item: item, config: config === null || config === void 0 ? void 0 : config.error })));
};
export default BlockParser;