import { z } from "zod/mini" // It's important to only import the types here to // avoid runtime circular dependencies! import type { RichTextContentSchema } from "../richText" import { RichTextLegacySchema } from "./richText" // Cell const getTableCellSchema = < TContent extends typeof RichTextLegacySchema | typeof RichTextContentSchema, >( content: TContent, ) => z.object({ key: z.transform((value) => z.uuidv4().safeParse(value).data || crypto.randomUUID()), type: z.union([z.literal("tableHeader"), z.literal("tableCell")]), content, columnWidth: z.optional(z.number()), }) // Row // oxlint-disable-next-line explicit-module-boundary-types export const getTableRowSchema = < TRichText extends typeof RichTextLegacySchema | typeof RichTextContentSchema, >( richTextSchema: TRichText, ) => z.strictObject({ key: z.transform((value) => z.uuidv4().safeParse(value).data || crypto.randomUUID()), type: z.literal("tableRow"), content: z.array(getTableCellSchema(richTextSchema)), }) // Table export const TableLegacySchema = z.strictObject({ content: z.array(getTableRowSchema(RichTextLegacySchema)), }) export type TableLegacy = z.infer