@prismicio/mock
Version:
Generate mock Prismic documents, fields, Slices, and models for development and testing environments
52 lines (51 loc) • 1.19 kB
JavaScript
import * as prismic from "@prismicio/client";
import { createFaker } from "../lib/createFaker.js";
import { richText } from "./richText/index.js";
const table = (config) => {
const faker = config.faker || createFaker(config.seed);
const cells = faker.range(1, 10);
const bodyRows = faker.range(1, 10);
return config.state === "empty" ? null : {
head: {
rows: [
{
cells: Array.from({ length: cells }, () => mockTableCell({
type: "header",
faker
}))
}
]
},
body: {
rows: Array.from({ length: bodyRows }, () => ({
cells: Array.from({ length: cells }, () => mockTableCell({
type: "data",
faker
}))
}))
}
};
};
const TableCell = {
type: "StructuredText",
config: {
multi: [
prismic.RichTextNodeType.paragraph,
prismic.RichTextNodeType.strong,
prismic.RichTextNodeType.em,
prismic.RichTextNodeType.hyperlink
].join(",")
}
};
const mockTableCell = ({ type, faker }) => ({
type,
content: richText({
faker,
model: TableCell
})
});
export {
TableCell,
table
};
//# sourceMappingURL=table.js.map