@prismicio/mock
Version:
Generate mock Prismic documents, fields, Slices, and models for development and testing environments
39 lines (38 loc) • 1.06 kB
JavaScript
import { createFaker } from "../lib/createFaker.js";
import { richText } from "./richText/index.js";
import * as prismic from "@prismicio/client";
//#region src/value/table.ts
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
})
});
//#endregion
export { table };
//# sourceMappingURL=table.js.map