@prismicio/types-internal 4.8.0 → 4.9.0-pr.40.3e5a801

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,10 @@ function blockLegacyToValue(block) {
32
32
  };
33
33
  }
34
34
  function blockValueToLegacy(block) {
35
+ if (block.depth === 0) {
36
+ const { depth: _depth, ...withoutDepth } = block;
37
+ return blockValueToLegacy(withoutDepth);
38
+ }
35
39
  if (block.type === RichTextNodeType.embed) return {
36
40
  ...block,
37
41
  data: embedContentToLegacy(block.data)
@@ -1 +1 @@
1
- {"version":3,"file":"richText.js","names":[],"sources":["../../../src/content/codec/richText.ts"],"sourcesContent":["import type { RichTextLegacy, RichTextLegacyBlock, RichTextLegacySpan } from \"../legacy/richText\"\nimport {\n\tRichTextLegacyBlockSchema,\n\tRichTextLegacySchema,\n\tRichTextNodeType,\n} from \"../legacy/richText\"\nimport type { RichTextContent, RichTextContentBlock, RichTextContentSpan } from \"../richText\"\nimport { RichTextContentSchema, RichTextContentType } from \"../richText\"\nimport { embedContentToLegacy, embedLegacyToContent } from \"./embed\"\nimport { imageLegacyToContent } from \"./image\"\nimport type { LegacyCodec, LegacyContentCtx } from \"./legacyContentCtx\"\nimport { linkLegacyToValue, linkValueToLegacy } from \"./link\"\n\n// Also used by content/codec/table\nexport function blockLegacyToValue(block: RichTextLegacyBlock): RichTextContentBlock {\n\tif (block.type === RichTextNodeType.embed) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: embedLegacyToContent(block.data),\n\t\t}\n\t}\n\n\tif (block.type === RichTextNodeType.image) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: {\n\t\t\t\t...imageLegacyToContent(block.data),\n\t\t\t\t...(block.data.linkTo ? { linkTo: linkLegacyToValue(block.data.linkTo) } : {}),\n\t\t\t},\n\t\t}\n\t}\n\n\tconst spans: RichTextContentSpan[] = []\n\tfor (const span of block.content.spans ?? []) {\n\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t// Legacy documents can have hyperlink spans with null data. We\n\t\t\t// drop them since a hyperlink without link data is meaningless.\n\t\t\tif (span.data) {\n\t\t\t\tspans.push({ ...span, data: linkLegacyToValue(span.data) })\n\t\t\t}\n\t\t} else {\n\t\t\tspans.push(span)\n\t\t}\n\t}\n\n\treturn { ...block, content: { ...block.content, spans } }\n}\n\n// Also used by content/codec/table\nexport function blockValueToLegacy(block: RichTextContentBlock): RichTextLegacyBlock {\n\tif (block.type === RichTextNodeType.embed) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: embedContentToLegacy(block.data),\n\t\t}\n\t}\n\n\tif (block.type === RichTextNodeType.image) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: {\n\t\t\t\t...block.data,\n\t\t\t\t...(block.data.linkTo ? { linkTo: linkValueToLegacy(block.data.linkTo) } : {}),\n\t\t\t},\n\t\t}\n\t}\n\n\tif (\"content\" in block) {\n\t\tconst spans: RichTextLegacySpan[] = []\n\t\tfor (const span of block.content.spans ?? []) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\t// Legacy documents can have hyperlink spans with null data. We\n\t\t\t\t// drop them since a hyperlink without link data is meaningless.\n\t\t\t\tif (span.data) {\n\t\t\t\t\tspans.push({ ...span, data: linkValueToLegacy(span.data) })\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tspans.push(span)\n\t\t\t}\n\t\t}\n\n\t\treturn { ...block, content: { ...block.content, spans } }\n\t}\n\n\treturn RichTextLegacyBlockSchema.parse(block)\n}\n\nexport const RichTextLegacyCodec = (\n\tctx: LegacyContentCtx,\n): LegacyCodec<RichTextContent, RichTextLegacy> => ({\n\tname: \"RichTextLegacy\",\n\n\tis(input): input is RichTextContent {\n\t\treturn RichTextContentSchema.safeParse(input).success\n\t},\n\n\ttoContent(input) {\n\t\tconst parsed = RichTextLegacySchema.safeParse(input)\n\t\tif (!parsed.success) {\n\t\t\treturn parsed\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\tvalue: parsed.data.map((block) => blockLegacyToValue(block)),\n\t\t\t\t__TYPE__: RichTextContentType,\n\t\t\t},\n\t\t}\n\t},\n\n\tfromContent(input) {\n\t\treturn {\n\t\t\tcontent: input.value.map((block) => blockValueToLegacy(block)),\n\t\t\ttypes: { [ctx.keyOfType]: \"StructuredText\" },\n\t\t\tkeys: {},\n\t\t}\n\t},\n})\n"],"mappings":";;;;;;AAcA,SAAgB,mBAAmB,OAAkD;CACpF,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM,qBAAqB,MAAM,IAAI;CACtC;CAGD,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM;GACL,GAAG,qBAAqB,MAAM,IAAI;GAClC,GAAI,MAAM,KAAK,SAAS,EAAE,QAAQ,kBAAkB,MAAM,KAAK,MAAM,EAAE,IAAI,CAAC;EAC7E;CACD;CAGD,MAAM,QAA+B,CAAC;CACtC,KAAK,MAAM,QAAQ,MAAM,QAAQ,SAAS,CAAC,GAC1C,IAAI,KAAK,SAAS,iBAAiB;MAG9B,KAAK,MACR,MAAM,KAAK;GAAE,GAAG;GAAM,MAAM,kBAAkB,KAAK,IAAI;EAAE,CAAC;CAAA,OAG3D,MAAM,KAAK,IAAI;CAIjB,OAAO;EAAE,GAAG;EAAO,SAAS;GAAE,GAAG,MAAM;GAAS;EAAM;CAAE;AACzD;AAGA,SAAgB,mBAAmB,OAAkD;CACpF,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM,qBAAqB,MAAM,IAAI;CACtC;CAGD,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM;GACL,GAAG,MAAM;GACT,GAAI,MAAM,KAAK,SAAS,EAAE,QAAQ,kBAAkB,MAAM,KAAK,MAAM,EAAE,IAAI,CAAC;EAC7E;CACD;CAGD,IAAI,aAAa,OAAO;EACvB,MAAM,QAA8B,CAAC;EACrC,KAAK,MAAM,QAAQ,MAAM,QAAQ,SAAS,CAAC,GAC1C,IAAI,KAAK,SAAS,iBAAiB;OAG9B,KAAK,MACR,MAAM,KAAK;IAAE,GAAG;IAAM,MAAM,kBAAkB,KAAK,IAAI;GAAE,CAAC;EAAA,OAG3D,MAAM,KAAK,IAAI;EAIjB,OAAO;GAAE,GAAG;GAAO,SAAS;IAAE,GAAG,MAAM;IAAS;GAAM;EAAE;CACzD;CAEA,OAAO,0BAA0B,MAAM,KAAK;AAC7C;AAEA,MAAa,uBACZ,SACmD;CACnD,MAAM;CAEN,GAAG,OAAiC;EACnC,OAAO,sBAAsB,UAAU,KAAK,CAAC,CAAC;CAC/C;CAEA,UAAU,OAAO;EAChB,MAAM,SAAS,qBAAqB,UAAU,KAAK;EACnD,IAAI,CAAC,OAAO,SACX,OAAO;EAGR,OAAO;GACN,SAAS;GACT,MAAM;IACL,OAAO,OAAO,KAAK,KAAK,UAAU,mBAAmB,KAAK,CAAC;IAC3D,UAAU;GACX;EACD;CACD;CAEA,YAAY,OAAO;EAClB,OAAO;GACN,SAAS,MAAM,MAAM,KAAK,UAAU,mBAAmB,KAAK,CAAC;GAC7D,OAAO,GAAG,IAAI,YAAY,iBAAiB;GAC3C,MAAM,CAAC;EACR;CACD;AACD"}
1
+ {"version":3,"file":"richText.js","names":[],"sources":["../../../src/content/codec/richText.ts"],"sourcesContent":["import type { RichTextLegacy, RichTextLegacyBlock, RichTextLegacySpan } from \"../legacy/richText\"\nimport {\n\tRichTextLegacyBlockSchema,\n\tRichTextLegacySchema,\n\tRichTextNodeType,\n} from \"../legacy/richText\"\nimport type { RichTextContent, RichTextContentBlock, RichTextContentSpan } from \"../richText\"\nimport { RichTextContentSchema, RichTextContentType } from \"../richText\"\nimport { embedContentToLegacy, embedLegacyToContent } from \"./embed\"\nimport { imageLegacyToContent } from \"./image\"\nimport type { LegacyCodec, LegacyContentCtx } from \"./legacyContentCtx\"\nimport { linkLegacyToValue, linkValueToLegacy } from \"./link\"\n\n// Also used by content/codec/table\nexport function blockLegacyToValue(block: RichTextLegacyBlock): RichTextContentBlock {\n\tif (block.type === RichTextNodeType.embed) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: embedLegacyToContent(block.data),\n\t\t}\n\t}\n\n\tif (block.type === RichTextNodeType.image) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: {\n\t\t\t\t...imageLegacyToContent(block.data),\n\t\t\t\t...(block.data.linkTo ? { linkTo: linkLegacyToValue(block.data.linkTo) } : {}),\n\t\t\t},\n\t\t}\n\t}\n\n\tconst spans: RichTextContentSpan[] = []\n\tfor (const span of block.content.spans ?? []) {\n\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t// Legacy documents can have hyperlink spans with null data. We\n\t\t\t// drop them since a hyperlink without link data is meaningless.\n\t\t\tif (span.data) {\n\t\t\t\tspans.push({ ...span, data: linkLegacyToValue(span.data) })\n\t\t\t}\n\t\t} else {\n\t\t\tspans.push(span)\n\t\t}\n\t}\n\n\treturn { ...block, content: { ...block.content, spans } }\n}\n\n// Also used by content/codec/table\nexport function blockValueToLegacy(block: RichTextContentBlock): RichTextLegacyBlock {\n\tif (block.depth === 0) {\n\t\tconst { depth: _depth, ...withoutDepth } = block\n\t\treturn blockValueToLegacy(withoutDepth)\n\t}\n\tif (block.type === RichTextNodeType.embed) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: embedContentToLegacy(block.data),\n\t\t}\n\t}\n\n\tif (block.type === RichTextNodeType.image) {\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: {\n\t\t\t\t...block.data,\n\t\t\t\t...(block.data.linkTo ? { linkTo: linkValueToLegacy(block.data.linkTo) } : {}),\n\t\t\t},\n\t\t}\n\t}\n\n\tif (\"content\" in block) {\n\t\tconst spans: RichTextLegacySpan[] = []\n\t\tfor (const span of block.content.spans ?? []) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\t// Legacy documents can have hyperlink spans with null data. We\n\t\t\t\t// drop them since a hyperlink without link data is meaningless.\n\t\t\t\tif (span.data) {\n\t\t\t\t\tspans.push({ ...span, data: linkValueToLegacy(span.data) })\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tspans.push(span)\n\t\t\t}\n\t\t}\n\n\t\treturn { ...block, content: { ...block.content, spans } }\n\t}\n\n\treturn RichTextLegacyBlockSchema.parse(block)\n}\n\nexport const RichTextLegacyCodec = (\n\tctx: LegacyContentCtx,\n): LegacyCodec<RichTextContent, RichTextLegacy> => ({\n\tname: \"RichTextLegacy\",\n\n\tis(input): input is RichTextContent {\n\t\treturn RichTextContentSchema.safeParse(input).success\n\t},\n\n\ttoContent(input) {\n\t\tconst parsed = RichTextLegacySchema.safeParse(input)\n\t\tif (!parsed.success) {\n\t\t\treturn parsed\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\tvalue: parsed.data.map((block) => blockLegacyToValue(block)),\n\t\t\t\t__TYPE__: RichTextContentType,\n\t\t\t},\n\t\t}\n\t},\n\n\tfromContent(input) {\n\t\treturn {\n\t\t\tcontent: input.value.map((block) => blockValueToLegacy(block)),\n\t\t\ttypes: { [ctx.keyOfType]: \"StructuredText\" },\n\t\t\tkeys: {},\n\t\t}\n\t},\n})\n"],"mappings":";;;;;;AAcA,SAAgB,mBAAmB,OAAkD;CACpF,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM,qBAAqB,MAAM,IAAI;CACtC;CAGD,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM;GACL,GAAG,qBAAqB,MAAM,IAAI;GAClC,GAAI,MAAM,KAAK,SAAS,EAAE,QAAQ,kBAAkB,MAAM,KAAK,MAAM,EAAE,IAAI,CAAC;EAC7E;CACD;CAGD,MAAM,QAA+B,CAAC;CACtC,KAAK,MAA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AAO,SACX,OAAO;EAGR,OAAO;GACN,SAAS;GACT,MAAM;IACL,OAAO,OAAO,KAAK,KAAK,UAAU,mBAAmB,KAAK,CAAC;IAC3D,UAAU;GACX;EACD;CACD;CAEA,YAAY,OAAO;EAClB,OAAO;GACN,SAAS,MAAM,MAAM,KAAK,UAAU,mBAAmB,KAAK,CAAC;GAC7D,OAAO,GAAG,IAAI,YAAY,iBAAiB;GAC3C,MAAM,CAAC;EACR;CACD;AACD"}
@@ -66,6 +66,7 @@ declare const TextBlockLegacySchema: z.ZodMiniObject<{
66
66
  }, z.core.$strip>;
67
67
  label: z.ZodMiniOptional<z.ZodMiniString<string>>;
68
68
  direction: z.ZodMiniOptional<z.ZodMiniString<string>>;
69
+ depth: z.ZodMiniOptional<z.ZodMiniNumberFormat>;
69
70
  }, z.core.$strip>;
70
71
  type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>;
71
72
  declare const ImageBlockLegacySchema: z.ZodMiniObject<{
@@ -95,6 +96,7 @@ declare const ImageBlockLegacySchema: z.ZodMiniObject<{
95
96
  }, z.core.$strip>;
96
97
  label: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
97
98
  direction: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
99
+ depth: z.ZodMiniOptional<z.ZodMiniLiteral<0>>;
98
100
  }, z.core.$strip>;
99
101
  type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>;
100
102
  declare const EmbedBlockLegacySchema: z.ZodMiniObject<{
@@ -116,6 +118,7 @@ declare const EmbedBlockLegacySchema: z.ZodMiniObject<{
116
118
  }, z.core.$loose>;
117
119
  label: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
118
120
  direction: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
121
+ depth: z.ZodMiniOptional<z.ZodMiniLiteral<0>>;
119
122
  }, z.core.$strip>;
120
123
  type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>;
121
124
  type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy;
@@ -1 +1 @@
1
- {"version":3,"file":"richText.d.ts","names":[],"sources":["../../../src/content/legacy/richText.ts"],"mappings":";;;;;;;;cAYa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;KAGW,4BAA4B,+BAA+B;KAGlE,cAAc,cAAc,wBAAwB;EACxD,aAAa,iBAAiB;EAC9B;EACA;EACA,MAAM;;cAeD,iBAAe,EAAA;;;;;;KAShB,YAAY,EAAE,aAAa;cAE1B,iBAAe,EAAA;;;;;KAShB,YAAY,EAAE,aAAa;KAEpB,KAAK,cAAc,wBAAwB,0BACpD,cAAc,SACd,YACA;cA6DG,uBAAqB,EAAA;;;;;;;;;;;;;;;;;;;;;;;KAEtB,kBAAkB,EAAE,aAAa;cAmBhC,wBAAsB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKvB,mBAAmB,EAAE,aAAa;cAgBjC,wBAAsB,EAAA;;;;;;;;;;;;;;;;;;;;KAEvB,mBAAmB,EAAE,aAAa;KAQ3B,sBAAsB,kBAAkB,mBAAmB"}
1
+ {"version":3,"file":"richText.d.ts","names":[],"sources":["../../../src/content/legacy/richText.ts"],"mappings":";;;;;;;;cAaa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;KAGW,4BAA4B,+BAA+B;KAGlE,cAAc,cAAc,wBAAwB;EACxD,aAAa,iBAAiB;EAC9B;EACA;EACA,MAAM;;cAeD,iBAAe,EAAA;;;;;;KAShB,YAAY,EAAE,aAAa;cAE1B,iBAAe,EAAA;;;;;KAShB,YAAY,EAAE,aAAa;KAEpB,KAAK,cAAc,wBAAwB,0BACpD,cAAc,SACd,YACA;cA0EG,uBAAqB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;KAEtB,kBAAkB,EAAE,aAAa;cAoBhC,wBAAsB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKvB,mBAAmB,EAAE,aAAa;cAiBjC,wBAAsB,EAAA;;;;;;;;;;;;;;;;;;;;;KAEvB,mBAAmB,EAAE,aAAa;KAQ3B,sBAAsB,kBAAkB,mBAAmB"}
@@ -1,5 +1,6 @@
1
1
  import { EmbedLegacyLooseSchema } from "./embed.js";
2
2
  import { ImageLegacyViewSchema } from "./image.js";
3
+ import { getInvalidListDepth } from "../listDepth.js";
3
4
  import { FilledLinkLegacyValueSchema } from "./link.js";
4
5
  import { z } from "zod/mini";
5
6
  //#region src/content/legacy/richText.ts
@@ -71,21 +72,30 @@ const getTextBlockSchema = (linkSchema) => z.object({
71
72
  })))
72
73
  }),
73
74
  label: z.optional(z.string()),
74
- direction: z.optional(z.string())
75
- });
75
+ direction: z.optional(z.string()),
76
+ depth: z.optional(z.int().check(z.gte(0)))
77
+ }).check(z.superRefine((block, ctx) => {
78
+ if (block.depth && block.type !== "list-item" && block.type !== "o-list-item") ctx.addIssue({
79
+ code: "custom",
80
+ path: ["depth"],
81
+ message: "Only list items can have a positive depth"
82
+ });
83
+ }));
76
84
  const TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema);
77
85
  const getImageBlockSchema = (data, linkTo) => z.object({
78
86
  type: z.literal(RichTextNodeType.image),
79
87
  data: z.extend(data, { linkTo: z.nullish(linkTo) }),
80
88
  label: z.nullish(z.string()),
81
- direction: z.nullish(z.string())
89
+ direction: z.nullish(z.string()),
90
+ depth: z.optional(z.literal(0))
82
91
  });
83
92
  const ImageBlockLegacySchema = getImageBlockSchema(ImageLegacyViewSchema, FilledLinkLegacyValueSchema);
84
93
  const getEmbedBlockSchema = (data) => z.object({
85
94
  type: z.literal(RichTextNodeType.embed),
86
95
  data,
87
96
  label: z.nullish(z.string()),
88
- direction: z.nullish(z.string())
97
+ direction: z.nullish(z.string()),
98
+ depth: z.optional(z.literal(0))
89
99
  });
90
100
  const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema);
91
101
  const RichTextLegacyBlockSchema = z.discriminatedUnion("type", [
@@ -93,7 +103,14 @@ const RichTextLegacyBlockSchema = z.discriminatedUnion("type", [
93
103
  ImageBlockLegacySchema,
94
104
  EmbedBlockLegacySchema
95
105
  ]);
96
- const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema);
106
+ const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema).check(z.superRefine((blocks, ctx) => {
107
+ const index = getInvalidListDepth(blocks);
108
+ if (index !== void 0) ctx.addIssue({
109
+ code: "custom",
110
+ path: [index, "depth"],
111
+ message: "List depth requires a parent at the preceding level"
112
+ });
113
+ }));
97
114
  //#endregion
98
115
  export { RichTextLegacyBlockSchema, RichTextLegacySchema, RichTextNodeType, getEmbedBlockSchema, getImageBlockSchema, getSpanSchema, getTextBlockSchema };
99
116
 
@@ -1 +1 @@
1
- {"version":3,"file":"richText.js","names":[],"sources":["../../../src/content/legacy/richText.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\n// It's important to only import the types here to\n// avoid runtime circular dependencies!\nimport type { EmbedContentSchema } from \"../embed\"\nimport type { ImageContentViewSchema } from \"../image\"\nimport type { FilledLinkContentValue, FilledLinkContentValueSchema } from \"../link\"\nimport { EmbedLegacyLooseSchema } from \"./embed\"\nimport { ImageLegacyViewSchema } from \"./image\"\nimport { FilledLinkLegacyValueSchema } from \"./link\"\nimport type { FilledLinkLegacyValue } from \"./link\"\n\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\toListItem: \"o-list-item\",\n\tlistItem: \"list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tstrong: \"strong\",\n\tem: \"em\",\n} as const\n\nexport type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Spans\ntype HyperlinkSpan<TData extends FilledLinkLegacyValue | FilledLinkContentValue> = {\n\ttype: typeof RichTextNodeType.hyperlink\n\tstart: number\n\tend: number\n\tdata: TData\n}\n\nconst getHyperlinkSpanSchema = <\n\tTData extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tdata: TData,\n) =>\n\tz.object({\n\t\ttype: z.literal(RichTextNodeType.hyperlink),\n\t\tstart: z.number(),\n\t\tend: z.number(),\n\t\tdata,\n\t})\n\nconst LabelSpanSchema = z.object({\n\ttype: z.literal(\"label\"),\n\tstart: z.number(),\n\tend: z.number(),\n\tdata: z.pipe(\n\t\tz.unknown(),\n\t\tz.transform((value) => (typeof value === \"string\" && value.length > 0 ? value : \"\")),\n\t),\n})\ntype LabelSpan = z.infer<typeof LabelSpanSchema>\n\nconst BasicSpanSchema = z.object({\n\ttype: z.union([\n\t\tz.literal(RichTextNodeType.strong),\n\t\tz.literal(RichTextNodeType.em),\n\t\tz.literal(\"list-item\"), // legacy case\n\t]),\n\tstart: z.number(),\n\tend: z.number(),\n})\ntype BasicSpan = z.infer<typeof BasicSpanSchema>\n\nexport type Span<TLink extends FilledLinkLegacyValue | FilledLinkContentValue> =\n\t| HyperlinkSpan<TLink>\n\t| LabelSpan\n\t| BasicSpan\n\nexport type RichTextLegacySpan = Span<FilledLinkLegacyValue>\n\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getSpanSchema = <\n\tTLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tlinkSchema: TLinkSchema,\n) =>\n\tz.discriminatedUnion(\"type\", [\n\t\tgetHyperlinkSpanSchema(linkSchema),\n\t\tLabelSpanSchema,\n\t\tBasicSpanSchema,\n\t])\n\n// Text blocks\nconst TextBlockTypeSchema = z.union([\n\tz.literal(RichTextNodeType.paragraph),\n\tz.literal(RichTextNodeType.heading1),\n\tz.literal(RichTextNodeType.heading2),\n\tz.literal(RichTextNodeType.heading3),\n\tz.literal(RichTextNodeType.heading4),\n\tz.literal(RichTextNodeType.heading5),\n\tz.literal(RichTextNodeType.heading6),\n\tz.literal(RichTextNodeType.preformatted),\n\tz.literal(RichTextNodeType.oListItem),\n\tz.literal(RichTextNodeType.listItem),\n])\n\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getTextBlockSchema = <\n\tTLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tlinkSchema: TLinkSchema,\n) =>\n\tz.object({\n\t\ttype: TextBlockTypeSchema,\n\t\tcontent: z.object({\n\t\t\ttext: z.string(),\n\t\t\tspans: z.optional(\n\t\t\t\tz.pipe(\n\t\t\t\t\tz.array(z.unknown()),\n\t\t\t\t\tz.transform((spans) => {\n\t\t\t\t\t\tconst spanSchema = getSpanSchema(linkSchema)\n\n\t\t\t\t\t\t// Filter out invalid spans and order them by start position\n\t\t\t\t\t\treturn spans\n\t\t\t\t\t\t\t.flatMap((maybeSpan) => {\n\t\t\t\t\t\t\t\tconst parsed = spanSchema.safeParse(maybeSpan)\n\t\t\t\t\t\t\t\treturn parsed.success ? [parsed.data] : []\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.sort((a, b) => a.start - b.start)\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t}),\n\t\tlabel: z.optional(z.string()),\n\t\tdirection: z.optional(z.string()),\n\t})\n\nconst TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema)\n\ntype TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>\n\n// Image block\n\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getImageBlockSchema = <\n\tTData extends typeof ImageLegacyViewSchema | typeof ImageContentViewSchema,\n\tTLinkTo extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tdata: TData,\n\tlinkTo: TLinkTo,\n) =>\n\tz.object({\n\t\ttype: z.literal(RichTextNodeType.image),\n\t\tdata: z.extend(data, { linkTo: z.nullish(linkTo) }),\n\t\tlabel: z.nullish(z.string()),\n\t\tdirection: z.nullish(z.string()),\n\t})\n\nconst ImageBlockLegacySchema = getImageBlockSchema(\n\tImageLegacyViewSchema,\n\tFilledLinkLegacyValueSchema,\n)\n\ntype ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>\n\n// Embed block\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getEmbedBlockSchema = <\n\tTData extends typeof EmbedLegacyLooseSchema | typeof EmbedContentSchema,\n>(\n\tdata: TData,\n) =>\n\tz.object({\n\t\ttype: z.literal(RichTextNodeType.embed),\n\t\tdata,\n\t\tlabel: z.nullish(z.string()),\n\t\tdirection: z.nullish(z.string()),\n\t})\n\nconst EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)\n\ntype EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>\n\n// Blocks\nexport const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.discriminatedUnion(\n\t\"type\",\n\t[TextBlockLegacySchema, ImageBlockLegacySchema, EmbedBlockLegacySchema],\n)\n\nexport type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy\n\nexport const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema)\n\nexport type RichTextLegacy = z.infer<typeof RichTextLegacySchema>\n"],"mappings":";;;;;AAYA,MAAa,mBAAmB;CAC/B,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,WAAW;CACX,cAAc;CACd,WAAW;CACX,UAAU;CACV,OAAO;CACP,OAAO;CACP,WAAW;CACX,QAAQ;CACR,IAAI;AACL;AAYA,MAAM,0BAGL,SAEA,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,iBAAiB,SAAS;CAC1C,OAAO,EAAE,OAAO;CAChB,KAAK,EAAE,OAA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S;IAC7C,OAAO,OAAO,UAAU,CAAC,OAAO,IAAI,IAAI,CAAC;GAC1C,CAAC,CAAC,CACD,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;EACnC,CAAC,CACF,CACD;CACD,CAAC;CACD,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC;CAC5B,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC;AACjC,CAAC;AAEF,MAAM,wBAAwB,mBAAmB,2BAA2B;AAO5E,MAAa,uBAIZ,MACA,WAEA,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,iBAAiB,KAAK;CACtC,MAAM,EAAE,OAAO,MAAM,EAAE,QAAQ,EAAE,QAAQ,MAAM,EAAE,CAAC;CAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC;CAC3B,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC;AAChC,CAAC;AAEF,MAAM,yBAAyB,oBAC9B,uBACA,2BACD;AAMA,MAAa,uBAGZ,SAEA,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,iBAAiB,KAAK;CACtC;CACA,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC;CAC3B,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC;AAChC,CAAC;AAEF,MAAM,yBAAyB,oBAAoB,sBAAsB;AAKzE,MAAa,4BAAgE,EAAE,mBAC9E,QACA;CAAC;CAAuB;CAAwB;AAAsB,CACvE;AAIA,MAAa,uBAAuB,EAAE,MAAM,yBAAyB"}
1
+ {"version":3,"file":"richText.js","names":[],"sources":["../../../src/content/legacy/richText.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\n// It's important to only import the types here to\n// avoid runtime circular dependencies!\nimport type { EmbedContentSchema } from \"../embed\"\nimport type { ImageContentViewSchema } from \"../image\"\nimport type { FilledLinkContentValue, FilledLinkContentValueSchema } from \"../link\"\nimport { getInvalidListDepth } from \"../listDepth\"\nimport { EmbedLegacyLooseSchema } from \"./embed\"\nimport { ImageLegacyViewSchema } from \"./image\"\nimport { FilledLinkLegacyValueSchema } from \"./link\"\nimport type { FilledLinkLegacyValue } from \"./link\"\n\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\toListItem: \"o-list-item\",\n\tlistItem: \"list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tstrong: \"strong\",\n\tem: \"em\",\n} as const\n\nexport type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Spans\ntype HyperlinkSpan<TData extends FilledLinkLegacyValue | FilledLinkContentValue> = {\n\ttype: typeof RichTextNodeType.hyperlink\n\tstart: number\n\tend: number\n\tdata: TData\n}\n\nconst getHyperlinkSpanSchema = <\n\tTData extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tdata: TData,\n) =>\n\tz.object({\n\t\ttype: z.literal(RichTextNodeType.hyperlink),\n\t\tstart: z.number(),\n\t\tend: z.number(),\n\t\tdata,\n\t})\n\nconst LabelSpanSchema = z.object({\n\ttype: z.literal(\"label\"),\n\tstart: z.number(),\n\tend: z.number(),\n\tdata: z.pipe(\n\t\tz.unknown(),\n\t\tz.transform((value) => (typeof value === \"string\" && value.length > 0 ? value : \"\")),\n\t),\n})\ntype LabelSpan = z.infer<typeof LabelSpanSchema>\n\nconst BasicSpanSchema = z.object({\n\ttype: z.union([\n\t\tz.literal(RichTextNodeType.strong),\n\t\tz.literal(RichTextNodeType.em),\n\t\tz.literal(\"list-item\"), // legacy case\n\t]),\n\tstart: z.number(),\n\tend: z.number(),\n})\ntype BasicSpan = z.infer<typeof BasicSpanSchema>\n\nexport type Span<TLink extends FilledLinkLegacyValue | FilledLinkContentValue> =\n\t| HyperlinkSpan<TLink>\n\t| LabelSpan\n\t| BasicSpan\n\nexport type RichTextLegacySpan = Span<FilledLinkLegacyValue>\n\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getSpanSchema = <\n\tTLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tlinkSchema: TLinkSchema,\n) =>\n\tz.discriminatedUnion(\"type\", [\n\t\tgetHyperlinkSpanSchema(linkSchema),\n\t\tLabelSpanSchema,\n\t\tBasicSpanSchema,\n\t])\n\n// Text blocks\nconst TextBlockTypeSchema = z.union([\n\tz.literal(RichTextNodeType.paragraph),\n\tz.literal(RichTextNodeType.heading1),\n\tz.literal(RichTextNodeType.heading2),\n\tz.literal(RichTextNodeType.heading3),\n\tz.literal(RichTextNodeType.heading4),\n\tz.literal(RichTextNodeType.heading5),\n\tz.literal(RichTextNodeType.heading6),\n\tz.literal(RichTextNodeType.preformatted),\n\tz.literal(RichTextNodeType.oListItem),\n\tz.literal(RichTextNodeType.listItem),\n])\n\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getTextBlockSchema = <\n\tTLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tlinkSchema: TLinkSchema,\n) =>\n\tz\n\t\t.object({\n\t\t\ttype: TextBlockTypeSchema,\n\t\t\tcontent: z.object({\n\t\t\t\ttext: z.string(),\n\t\t\t\tspans: z.optional(\n\t\t\t\t\tz.pipe(\n\t\t\t\t\t\tz.array(z.unknown()),\n\t\t\t\t\t\tz.transform((spans) => {\n\t\t\t\t\t\t\tconst spanSchema = getSpanSchema(linkSchema)\n\n\t\t\t\t\t\t\t// Filter out invalid spans and order them by start position\n\t\t\t\t\t\t\treturn spans\n\t\t\t\t\t\t\t\t.flatMap((maybeSpan) => {\n\t\t\t\t\t\t\t\t\tconst parsed = spanSchema.safeParse(maybeSpan)\n\t\t\t\t\t\t\t\t\treturn parsed.success ? [parsed.data] : []\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t.sort((a, b) => a.start - b.start)\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tlabel: z.optional(z.string()),\n\t\t\tdirection: z.optional(z.string()),\n\t\t\tdepth: z.optional(z.int().check(z.gte(0))),\n\t\t})\n\t\t.check(\n\t\t\tz.superRefine((block, ctx) => {\n\t\t\t\tif (block.depth && block.type !== \"list-item\" && block.type !== \"o-list-item\") {\n\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\tpath: [\"depth\"],\n\t\t\t\t\t\tmessage: \"Only list items can have a positive depth\",\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\nconst TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema)\n\ntype TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>\n\n// Image block\n\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getImageBlockSchema = <\n\tTData extends typeof ImageLegacyViewSchema | typeof ImageContentViewSchema,\n\tTLinkTo extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,\n>(\n\tdata: TData,\n\tlinkTo: TLinkTo,\n) =>\n\tz.object({\n\t\ttype: z.literal(RichTextNodeType.image),\n\t\tdata: z.extend(data, { linkTo: z.nullish(linkTo) }),\n\t\tlabel: z.nullish(z.string()),\n\t\tdirection: z.nullish(z.string()),\n\t\tdepth: z.optional(z.literal(0)),\n\t})\n\nconst ImageBlockLegacySchema = getImageBlockSchema(\n\tImageLegacyViewSchema,\n\tFilledLinkLegacyValueSchema,\n)\n\ntype ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>\n\n// Embed block\n// oxlint-disable-next-line explicit-module-boundary-types\nexport const getEmbedBlockSchema = <\n\tTData extends typeof EmbedLegacyLooseSchema | typeof EmbedContentSchema,\n>(\n\tdata: TData,\n) =>\n\tz.object({\n\t\ttype: z.literal(RichTextNodeType.embed),\n\t\tdata,\n\t\tlabel: z.nullish(z.string()),\n\t\tdirection: z.nullish(z.string()),\n\t\tdepth: z.optional(z.literal(0)),\n\t})\n\nconst EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)\n\ntype EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>\n\n// Blocks\nexport const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.discriminatedUnion(\n\t\"type\",\n\t[TextBlockLegacySchema, ImageBlockLegacySchema, EmbedBlockLegacySchema],\n)\n\nexport type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy\n\nexport const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema).check(\n\tz.superRefine((blocks, ctx) => {\n\t\tconst index = getInvalidListDepth(blocks)\n\t\tif (index !== undefined)\n\t\t\tctx.addIssue({\n\t\t\t\tcode: \"custom\",\n\t\t\t\tpath: [index, \"depth\"],\n\t\t\t\tmessage: \"List depth requires a parent at the preceding level\",\n\t\t\t})\n\t}),\n)\n\nexport type RichTextLegacy = z.infer<typeof RichTextLegacySchema>\n"],"mappings":";;;;;;AAaA,MAAa,mBAAmB;CAC/B,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,WAAW;CACX,cAAc;CACd,WAAW;CACX,UAAU;CACV,OAAO;CACP,OAAO;CACP,WAAW;CACX,QAAQ;CACR,IAAI;AACL;AAYA,MAAM,0BAGL,SAEA,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,iBAAiB,SAAS;CAC1C,OAAO,EAAE,OAAO;CAChB,KAAK,EAAE,OAAO;CACd;AACD,CAAC;AAEF,MAAM,kBAAkB,EAAE,OAAO;CAChC,MAAM,EAAE,QAAQ,OAAO;CACvB,OAAO,EAAE,OAAO;CAChB,KAAK,EAAE,OAAO;CACd,MAAM,EAAE,KACP,EAAE,QAAQ,GACV,EAAE,WAAW,UAAW,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ,EAA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,SAAS;CACV,CAAC;AACH,CAAC,CACF"}
@@ -0,0 +1,11 @@
1
+ //#region src/content/listDepth.d.ts
2
+ /** Returns the first block whose list hierarchy cannot be represented. */
3
+ declare function getInvalidListDepth(blocks: readonly {
4
+ type: string;
5
+ depth?: number;
6
+ }[]): number | undefined;
7
+ /** Detect nesting anywhere in a document, including group and slice fields. */
8
+ declare function hasRichTextNesting(content: unknown): boolean;
9
+ //#endregion
10
+ export { getInvalidListDepth, hasRichTextNesting };
11
+ //# sourceMappingURL=listDepth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listDepth.d.ts","names":[],"sources":["../../src/content/listDepth.ts"],"mappings":";;iBACgB,oBACf;EAAmB;EAAc;;;iBAmBlB,mBAAmB"}
@@ -0,0 +1,32 @@
1
+ //#region src/content/listDepth.ts
2
+ /** Returns the first block whose list hierarchy cannot be represented. */
3
+ function getInvalidListDepth(blocks) {
4
+ let previousDepth = -1;
5
+ for (let index = 0; index < blocks.length; index++) {
6
+ const block = blocks[index];
7
+ const depth = block.depth ?? 0;
8
+ if (!Number.isSafeInteger(depth) || depth < 0) return index;
9
+ if (block.type !== "list-item" && block.type !== "o-list-item") {
10
+ if (depth > 0) return index;
11
+ previousDepth = -1;
12
+ continue;
13
+ }
14
+ if (depth > previousDepth + 1) return index;
15
+ previousDepth = depth;
16
+ }
17
+ }
18
+ /** Detect nesting anywhere in a document, including group and slice fields. */
19
+ function hasRichTextNesting(content) {
20
+ const pending = [content];
21
+ while (pending.length) {
22
+ const value = pending.pop();
23
+ if (!value || typeof value !== "object") continue;
24
+ if ("type" in value && (value.type === "list-item" || value.type === "o-list-item") && "depth" in value && typeof value.depth === "number" && Number.isSafeInteger(value.depth) && value.depth > 0) return true;
25
+ for (const child of Object.values(value)) pending.push(child);
26
+ }
27
+ return false;
28
+ }
29
+ //#endregion
30
+ export { getInvalidListDepth, hasRichTextNesting };
31
+
32
+ //# sourceMappingURL=listDepth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listDepth.js","names":[],"sources":["../../src/content/listDepth.ts"],"sourcesContent":["/** Returns the first block whose list hierarchy cannot be represented. */\nexport function getInvalidListDepth(\n\tblocks: readonly { type: string; depth?: number }[],\n): number | undefined {\n\tlet previousDepth = -1\n\tfor (let index = 0; index < blocks.length; index++) {\n\t\tconst block = blocks[index]\n\t\tconst depth = block.depth ?? 0\n\t\tif (!Number.isSafeInteger(depth) || depth < 0) return index\n\t\tif (block.type !== \"list-item\" && block.type !== \"o-list-item\") {\n\t\t\tif (depth > 0) return index\n\t\t\tpreviousDepth = -1\n\t\t\tcontinue\n\t\t}\n\t\tif (depth > previousDepth + 1) return index\n\t\tpreviousDepth = depth\n\t}\n\treturn undefined\n}\n\n/** Detect nesting anywhere in a document, including group and slice fields. */\nexport function hasRichTextNesting(content: unknown): boolean {\n\tconst pending: unknown[] = [content]\n\twhile (pending.length) {\n\t\tconst value = pending.pop()\n\t\tif (!value || typeof value !== \"object\") continue\n\t\tif (\n\t\t\t\"type\" in value &&\n\t\t\t(value.type === \"list-item\" || value.type === \"o-list-item\") &&\n\t\t\t\"depth\" in value &&\n\t\t\ttypeof value.depth === \"number\" &&\n\t\t\tNumber.isSafeInteger(value.depth) &&\n\t\t\tvalue.depth > 0\n\t\t)\n\t\t\treturn true\n\t\tfor (const child of Object.values(value)) pending.push(child)\n\t}\n\treturn false\n}\n"],"mappings":";;AACA,SAAgB,oBACf,QACqB;CACrB,IAAI,gBAAgB;CACpB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;EACnD,MAAM,QAAQ,OAAO;EACrB,MAAM,QAAQ,MAAM,SAAS;EAC7B,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG,OAAO;EACtD,IAAI,MAAM,SAAS,eAAe,MAAM,SAAS,eAAe;GAC/D,IAAI,QAAQ,GAAG,OAAO;GACtB,gBAAgB;GAChB;EACD;EACA,IAAI,QAAQ,gBAAgB,GAAG,OAAO;EACtC,gBAAgB;CACjB;AAED;;AAGA,SAAgB,mBAAmB,SAA2B;CAC7D,MAAM,UAAqB,CAAC,OAAO;CACnC,OAAO,QAAQ,QAAQ;EACtB,MAAM,QAAQ,QAAQ,IAAI;EAC1B,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU;EACzC,IACC,UAAU,UACT,MAAM,SAAS,eAAe,MAAM,SAAS,kBAC9C,WAAW,SACX,OAAO,MAAM,UAAU,YACvB,OAAO,cAAc,MAAM,KAAK,KAChC,MAAM,QAAQ,GAEd,OAAO;EACR,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,GAAG,QAAQ,KAAK,KAAK;CAC7D;CACA,OAAO;AACR"}
@@ -25,6 +25,7 @@ declare const RichTextContentTextBlockSchema: z.ZodMiniObject<{
25
25
  }, z.core.$strip>;
26
26
  label: z.ZodMiniOptional<z.ZodMiniString<string>>;
27
27
  direction: z.ZodMiniOptional<z.ZodMiniString<string>>;
28
+ depth: z.ZodMiniOptional<z.ZodMiniNumberFormat>;
28
29
  }, z.core.$strip>;
29
30
  type RichTextContentTextBlock = z.infer<typeof RichTextContentTextBlockSchema>;
30
31
  declare const RichTextContentImageBlockSchema: z.ZodMiniObject<{
@@ -54,6 +55,7 @@ declare const RichTextContentImageBlockSchema: z.ZodMiniObject<{
54
55
  }, z.core.$strip>;
55
56
  label: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
56
57
  direction: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
58
+ depth: z.ZodMiniOptional<z.ZodMiniLiteral<0>>;
57
59
  }, z.core.$strip>;
58
60
  type RichTextContentImageBlock = z.infer<typeof RichTextContentImageBlockSchema>;
59
61
  declare const RichTextContentEmbedBlockSchema: z.ZodMiniObject<{
@@ -77,6 +79,7 @@ declare const RichTextContentEmbedBlockSchema: z.ZodMiniObject<{
77
79
  }, z.core.$strip>;
78
80
  label: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
79
81
  direction: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
82
+ depth: z.ZodMiniOptional<z.ZodMiniLiteral<0>>;
80
83
  }, z.core.$strip>;
81
84
  type RichTextContentEmbedBlock = z.infer<typeof RichTextContentEmbedBlockSchema>;
82
85
  type RichTextContentBlock = RichTextContentTextBlock | RichTextContentImageBlock | RichTextContentEmbedBlock;
@@ -1 +1 @@
1
- {"version":3,"file":"richText.d.ts","names":[],"sources":["../../src/content/richText.ts"],"mappings":";;;;KAkBY,sBAAsB,KAAK;cAOjC,gCAA8B,EAAA;;;;;;;;;;;;;;;;;;;;;;;KACxB,2BAA2B,EAAE,aAAa;cAEhD,iCAA+B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAIzB,4BAA4B,EAAE,aAAa;cAEjD,iCAA+B,EAAA;;;;;;;;;;;;;;;;;;;;;;KACzB,4BAA4B,EAAE,aAAa;KAY3C,uBACT,2BACA,4BACA;cAEU;KAED;EACX,iBAAiB;EACjB,OAAO"}
1
+ {"version":3,"file":"richText.d.ts","names":[],"sources":["../../src/content/richText.ts"],"mappings":";;;;KAmBY,sBAAsB,KAAK;cAOjC,gCAA8B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;KACxB,2BAA2B,EAAE,aAAa;cAEhD,iCAA+B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAIzB,4BAA4B,EAAE,aAAa;cAEjD,iCAA+B,EAAA;;;;;;;;;;;;;;;;;;;;;;;KACzB,4BAA4B,EAAE,aAAa;KAY3C,uBACT,2BACA,4BACA;cAEU;KAED;EACX,iBAAiB;EACjB,OAAO"}
@@ -1,5 +1,6 @@
1
1
  import { EmbedContentSchema } from "./embed.js";
2
2
  import { ImageContentViewSchema } from "./image.js";
3
+ import { getInvalidListDepth } from "./listDepth.js";
3
4
  import { RichTextNodeType, getEmbedBlockSchema, getImageBlockSchema, getSpanSchema, getTextBlockSchema } from "./legacy/richText.js";
4
5
  import { FilledLinkContentValueSchema } from "./link.js";
5
6
  import { z } from "zod/mini";
@@ -16,7 +17,14 @@ const RichTextContentBlockSchema = z.discriminatedUnion("type", [
16
17
  const RichTextContentType = "StructuredTextContent";
17
18
  const RichTextContentSchema = z.object({
18
19
  __TYPE__: z.literal(RichTextContentType),
19
- value: z.array(RichTextContentBlockSchema)
20
+ value: z.array(RichTextContentBlockSchema).check(z.superRefine((blocks, ctx) => {
21
+ const index = getInvalidListDepth(blocks);
22
+ if (index !== void 0) ctx.addIssue({
23
+ code: "custom",
24
+ path: [index, "depth"],
25
+ message: "List depth requires a parent at the preceding level"
26
+ });
27
+ }))
20
28
  });
21
29
  //#endregion
22
30
  export { RichTextContentBlockSchema, RichTextContentSchema, RichTextContentSpanSchema, RichTextContentType, RichTextNodeType };
@@ -1 +1 @@
1
- {"version":3,"file":"richText.js","names":[],"sources":["../../src/content/richText.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { EmbedContentSchema } from \"./embed\"\nimport { ImageContentViewSchema } from \"./image\"\nimport {\n\tgetEmbedBlockSchema,\n\tgetImageBlockSchema,\n\tgetSpanSchema,\n\tgetTextBlockSchema,\n} from \"./legacy/richText\"\nimport type { Span } from \"./legacy/richText\"\nimport type { FilledLinkContentValue } from \"./link\"\nimport { FilledLinkContentValueSchema } from \"./link\"\n\nexport { RichTextNodeType } from \"./legacy/richText\"\nexport type { RichTextNodeTypes } from \"./legacy/richText\"\n\n// Spans\nexport type RichTextContentSpan = Span<FilledLinkContentValue>\n\nexport const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(\n\tFilledLinkContentValueSchema,\n)\n\n// Blocks\nconst RichTextContentTextBlockSchema = getTextBlockSchema(FilledLinkContentValueSchema)\nexport type RichTextContentTextBlock = z.infer<typeof RichTextContentTextBlockSchema>\n\nconst RichTextContentImageBlockSchema = getImageBlockSchema(\n\tImageContentViewSchema,\n\tFilledLinkContentValueSchema,\n)\nexport type RichTextContentImageBlock = z.infer<typeof RichTextContentImageBlockSchema>\n\nconst RichTextContentEmbedBlockSchema = getEmbedBlockSchema(EmbedContentSchema)\nexport type RichTextContentEmbedBlock = z.infer<typeof RichTextContentEmbedBlockSchema>\n\nexport const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.discriminatedUnion(\n\t\"type\",\n\t[\n\t\tRichTextContentTextBlockSchema,\n\t\tRichTextContentImageBlockSchema,\n\t\tRichTextContentEmbedBlockSchema,\n\t],\n)\n\n// Used by content/codec/richText\nexport type RichTextContentBlock =\n\t| RichTextContentTextBlock\n\t| RichTextContentImageBlock\n\t| RichTextContentEmbedBlock\n\nexport const RichTextContentType = \"StructuredTextContent\" as const\n\nexport type RichTextContent = {\n\t__TYPE__: typeof RichTextContentType\n\tvalue: RichTextContentBlock[]\n}\n\nexport const RichTextContentSchema = z.object({\n\t__TYPE__: z.literal(RichTextContentType),\n\tvalue: z.array(RichTextContentBlockSchema),\n})\n"],"mappings":";;;;;;AAoBA,MAAa,4BAAgE,cAC5E,4BACD;AAGA,MAAM,iCAAiC,mBAAmB,4BAA4B;AAGtF,MAAM,kCAAkC,oBACvC,wBACA,4BACD;AAGA,MAAM,kCAAkC,oBAAoB,kBAAkB;AAG9E,MAAa,6BAAkE,EAAE,mBAChF,QACA;CACC;CACA;CACA;AACD,CACD;AAQA,MAAa,sBAAsB;AAOnC,MAAa,wBAAwB,EAAE,OAAO;CAC7C,UAAU,EAAE,QAAQ,mBAAmB;CACvC,OAAO,EAAE,MAAM,0BAA0B;AAC1C,CAAC"}
1
+ {"version":3,"file":"richText.js","names":[],"sources":["../../src/content/richText.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { EmbedContentSchema } from \"./embed\"\nimport { ImageContentViewSchema } from \"./image\"\nimport {\n\tgetEmbedBlockSchema,\n\tgetImageBlockSchema,\n\tgetSpanSchema,\n\tgetTextBlockSchema,\n} from \"./legacy/richText\"\nimport type { Span } from \"./legacy/richText\"\nimport type { FilledLinkContentValue } from \"./link\"\nimport { FilledLinkContentValueSchema } from \"./link\"\nimport { getInvalidListDepth } from \"./listDepth\"\n\nexport { RichTextNodeType } from \"./legacy/richText\"\nexport type { RichTextNodeTypes } from \"./legacy/richText\"\n\n// Spans\nexport type RichTextContentSpan = Span<FilledLinkContentValue>\n\nexport const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(\n\tFilledLinkContentValueSchema,\n)\n\n// Blocks\nconst RichTextContentTextBlockSchema = getTextBlockSchema(FilledLinkContentValueSchema)\nexport type RichTextContentTextBlock = z.infer<typeof RichTextContentTextBlockSchema>\n\nconst RichTextContentImageBlockSchema = getImageBlockSchema(\n\tImageContentViewSchema,\n\tFilledLinkContentValueSchema,\n)\nexport type RichTextContentImageBlock = z.infer<typeof RichTextContentImageBlockSchema>\n\nconst RichTextContentEmbedBlockSchema = getEmbedBlockSchema(EmbedContentSchema)\nexport type RichTextContentEmbedBlock = z.infer<typeof RichTextContentEmbedBlockSchema>\n\nexport const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.discriminatedUnion(\n\t\"type\",\n\t[\n\t\tRichTextContentTextBlockSchema,\n\t\tRichTextContentImageBlockSchema,\n\t\tRichTextContentEmbedBlockSchema,\n\t],\n)\n\n// Used by content/codec/richText\nexport type RichTextContentBlock =\n\t| RichTextContentTextBlock\n\t| RichTextContentImageBlock\n\t| RichTextContentEmbedBlock\n\nexport const RichTextContentType = \"StructuredTextContent\" as const\n\nexport type RichTextContent = {\n\t__TYPE__: typeof RichTextContentType\n\tvalue: RichTextContentBlock[]\n}\n\nexport const RichTextContentSchema = z.object({\n\t__TYPE__: z.literal(RichTextContentType),\n\tvalue: z.array(RichTextContentBlockSchema).check(\n\t\tz.superRefine((blocks, ctx) => {\n\t\t\tconst index = getInvalidListDepth(blocks)\n\t\t\tif (index !== undefined)\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\tpath: [index, \"depth\"],\n\t\t\t\t\tmessage: \"List depth requires a parent at the preceding level\",\n\t\t\t\t})\n\t\t}),\n\t),\n})\n"],"mappings":";;;;;;;AAqBA,MAAa,4BAAgE,cAC5E,4BACD;AAGA,MAAM,iCAAiC,mBAAmB,4BAA4B;AAGtF,MAAM,kCAAkC,oBACvC,wBACA,4BACD;AAGA,MAAM,kCAAkC,oBAAoB,kBAAkB;AAG9E,MAAa,6BAAkE,EAAE,mBAChF,QACA;CACC;CACA;CACA;AACD,CACD;AAQA,MAAa,sBAAsB;AAOnC,MAAa,wBAAwB,EAAE,OAAO;CAC7C,UAAU,EAAE,QAAQ,mBAAmB;CACvC,OAAO,EAAE,MAAM,0BAA0B,CAAC,CAAC,MAC1C,EAAE,aAAa,QAAQ,QAAQ;EAC9B,MAAM,QAAQ,oBAAoB,MAAM;EACxC,IAAI,UAAU,KAAA,GACb,IAAI,SAAS;GACZ,MAAM;GACN,MAAM,CAAC,OAAO,OAAO;GACrB,SAAS;EACV,CAAC;CACH,CAAC,CACF;AACD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ import { CompositeSliceItemContent, LegacySliceItemContent, SharedSliceItemConte
23
23
  import { UIDContent } from "./content/uid.js";
24
24
  import { WidgetContent } from "./content/widget.js";
25
25
  import { DocumentContent } from "./content/document.js";
26
+ import { getInvalidListDepth, hasRichTextNesting } from "./content/listDepth.js";
26
27
  import { BooleanModel } from "./model/boolean.js";
27
28
  import { ColorModel } from "./model/color.js";
28
29
  import { DateModel } from "./model/date.js";
@@ -62,4 +63,4 @@ import { sliceModel_d_exports } from "./helpers/sliceModel.js";
62
63
  import { withDefaultContent_d_exports } from "./helpers/withDefaultContent.js";
63
64
  import { imageContent_d_exports } from "./helpers/imageContent.js";
64
65
  import { TraverseSliceContentWithModelFunction, TraverseWidgetContentWithModelFunction, traverseCompositeSliceContentWithModel, traverseDocumentContentWithModel, traverseGroupContentWithModel, traverseGroupItemsContentWithModel, traverseLegacySliceContentWithModel, traverseRepeatableContentWithModel, traverseSharedSliceContentWithModel, traverseSlicesContentWithModel, traverseTableContentWithModel } from "./helpers/traverseContentWithModel.js";
65
- export { type AddedDiff, type Asset, type BooleanContent, type BooleanModel, type ColorContent, type ColorModel, type CompositeSliceContent, type CompositeSliceItemContent, type CompositeSliceModel, type CustomTypeModel, type DateContent, type DateModel, type Diff, DiffOperation, type DocumentContent, type DynamicCustomTypeModel, type DynamicCustomTypeModelTab, type DynamicSliceModel, type DynamicSlicesModel, type DynamicWidgetModel, type Embed, type EmbedContent, type EmbedModel, type EmptyContent, type EmptyLinkContent, type FieldContent, type FieldModelType, type FieldOrSliceType, type FilledLinkContent, type FlattenedStaticCustomTypeModel, type GeoPointContent, type GeoPointModel, type GroupContent, type GroupItemContent, type GroupModel, type GroupWidgetDiff, type GroupWidgetWithFieldsDiff, type HexaColorCode, type ImageContent, type ImageContentView, type ImageModel, type IntegrationFieldContent, type IntegrationFieldModel, LegacyContentCtx, type LegacySliceContent, type LegacySliceItemContent, type LegacySliceModel, type LinkConfigCustomtypes, type LinkContent, type LinkModel, type NestableContent, type NestableModel, type NestableWidgetDiff, type NestedGroupModel, type NonEmptyString, type NumberContent, type NumberModel, type RangeContent, type RangeModel, type RemovedDiff, type RepeatableContent, type RichTextContent, type RichTextContentBlock, type RichTextContentEmbedBlock, type RichTextContentImageBlock, type RichTextContentSpan, type RichTextContentTextBlock, type RichTextModel, RichTextModelNodeType, type RichTextModelNodeTypes, RichTextNodeType, type RichTextNodeTypes, type SelectContent, type SelectModel, type SeparatorContent, type SeparatorModel, type SharedSliceContent, type SharedSliceItemContent, type SharedSliceModel, type SharedSliceModelVariation, type SharedSliceRefModel, type SharedSliceVariationContentModel, type SliceContent, type SliceContentModel, type SliceDiff, SliceDiffComparator, type SliceDiffMetadata, type SliceItemContent, type SliceModelType, type SlicePrimaryWidgetDiff, type SlicesContent, type StaticCustomTypeModel, type StaticCustomTypeModelTab, type StaticSliceModel, type StaticSlicesModel, type StaticWidgetModel, TableCellModel, TableCellModelNodeTypes, type TableContent, type TableModel, type TextContent, type TextModel, type TimestampContent, type TimestampModel, type TraverseSliceContentFunction, type TraverseSliceContentWithModelFunction, type TraverseWidgetContentFunction, type TraverseWidgetContentWithModelFunction, type UIDContent, type UIDModel, type UpdatedDiff, type VariationDiff, VariationDiffComparator, type VariationDiffMetadata, type WidgetContent, type WidgetKey, contentPath_d_exports as contentPath, customTypeModel_d_exports as customTypeModel, defaultCtx, documentContent_d_exports as documentContent, fieldModel_d_exports as fieldModel, getFieldCtx, imageContent_d_exports as imageContent, repository_d_exports as repository, sliceContent_d_exports as sliceContent, sliceModel_d_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_d_exports as withDefaultContent };
66
+ export { type AddedDiff, type Asset, type BooleanContent, type BooleanModel, type ColorContent, type ColorModel, type CompositeSliceContent, type CompositeSliceItemContent, type CompositeSliceModel, type CustomTypeModel, type DateContent, type DateModel, type Diff, DiffOperation, type DocumentContent, type DynamicCustomTypeModel, type DynamicCustomTypeModelTab, type DynamicSliceModel, type DynamicSlicesModel, type DynamicWidgetModel, type Embed, type EmbedContent, type EmbedModel, type EmptyContent, type EmptyLinkContent, type FieldContent, type FieldModelType, type FieldOrSliceType, type FilledLinkContent, type FlattenedStaticCustomTypeModel, type GeoPointContent, type GeoPointModel, type GroupContent, type GroupItemContent, type GroupModel, type GroupWidgetDiff, type GroupWidgetWithFieldsDiff, type HexaColorCode, type ImageContent, type ImageContentView, type ImageModel, type IntegrationFieldContent, type IntegrationFieldModel, LegacyContentCtx, type LegacySliceContent, type LegacySliceItemContent, type LegacySliceModel, type LinkConfigCustomtypes, type LinkContent, type LinkModel, type NestableContent, type NestableModel, type NestableWidgetDiff, type NestedGroupModel, type NonEmptyString, type NumberContent, type NumberModel, type RangeContent, type RangeModel, type RemovedDiff, type RepeatableContent, type RichTextContent, type RichTextContentBlock, type RichTextContentEmbedBlock, type RichTextContentImageBlock, type RichTextContentSpan, type RichTextContentTextBlock, type RichTextModel, RichTextModelNodeType, type RichTextModelNodeTypes, RichTextNodeType, type RichTextNodeTypes, type SelectContent, type SelectModel, type SeparatorContent, type SeparatorModel, type SharedSliceContent, type SharedSliceItemContent, type SharedSliceModel, type SharedSliceModelVariation, type SharedSliceRefModel, type SharedSliceVariationContentModel, type SliceContent, type SliceContentModel, type SliceDiff, SliceDiffComparator, type SliceDiffMetadata, type SliceItemContent, type SliceModelType, type SlicePrimaryWidgetDiff, type SlicesContent, type StaticCustomTypeModel, type StaticCustomTypeModelTab, type StaticSliceModel, type StaticSlicesModel, type StaticWidgetModel, TableCellModel, TableCellModelNodeTypes, type TableContent, type TableModel, type TextContent, type TextModel, type TimestampContent, type TimestampModel, type TraverseSliceContentFunction, type TraverseSliceContentWithModelFunction, type TraverseWidgetContentFunction, type TraverseWidgetContentWithModelFunction, type UIDContent, type UIDModel, type UpdatedDiff, type VariationDiff, VariationDiffComparator, type VariationDiffMetadata, type WidgetContent, type WidgetKey, contentPath_d_exports as contentPath, customTypeModel_d_exports as customTypeModel, defaultCtx, documentContent_d_exports as documentContent, fieldModel_d_exports as fieldModel, getFieldCtx, getInvalidListDepth, hasRichTextNesting, imageContent_d_exports as imageContent, repository_d_exports as repository, sliceContent_d_exports as sliceContent, sliceModel_d_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_d_exports as withDefaultContent };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getInvalidListDepth, hasRichTextNesting } from "./content/listDepth.js";
1
2
  import { RichTextNodeType } from "./content/legacy/richText.js";
2
3
  import "./content/richText.js";
3
4
  import { DiffOperation } from "./model/diff/changes.js";
@@ -17,4 +18,4 @@ import { sliceModel_exports } from "./helpers/sliceModel.js";
17
18
  import { withDefaultContent_exports } from "./helpers/withDefaultContent.js";
18
19
  import { imageContent_exports } from "./helpers/imageContent.js";
19
20
  import { traverseCompositeSliceContentWithModel, traverseDocumentContentWithModel, traverseGroupContentWithModel, traverseGroupItemsContentWithModel, traverseLegacySliceContentWithModel, traverseRepeatableContentWithModel, traverseSharedSliceContentWithModel, traverseSlicesContentWithModel, traverseTableContentWithModel } from "./helpers/traverseContentWithModel.js";
20
- export { DiffOperation, LegacyContentCtx, RichTextModelNodeType, RichTextNodeType, SliceDiffComparator, TableCellModel, TableCellModelNodeTypes, VariationDiffComparator, contentPath_exports as contentPath, customTypeModel_exports as customTypeModel, defaultCtx, documentContent_exports as documentContent, fieldModel_exports as fieldModel, getFieldCtx, imageContent_exports as imageContent, repository_exports as repository, sliceContent_exports as sliceContent, sliceModel_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_exports as withDefaultContent };
21
+ export { DiffOperation, LegacyContentCtx, RichTextModelNodeType, RichTextNodeType, SliceDiffComparator, TableCellModel, TableCellModelNodeTypes, VariationDiffComparator, contentPath_exports as contentPath, customTypeModel_exports as customTypeModel, defaultCtx, documentContent_exports as documentContent, fieldModel_exports as fieldModel, getFieldCtx, getInvalidListDepth, hasRichTextNesting, imageContent_exports as imageContent, repository_exports as repository, sliceContent_exports as sliceContent, sliceModel_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_exports as withDefaultContent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "4.8.0",
3
+ "version": "4.9.0-pr.40.3e5a801",
4
4
  "description": "TypeScript types and runtime parsers for Prismic data",
5
5
  "keywords": [
6
6
  "prismic",
@@ -54,18 +54,21 @@
54
54
  "bench:watch": "vitest bench",
55
55
  "test": "npm run lint && npm run types && npm run unit && npm run portability"
56
56
  },
57
+ "dependencies": {
58
+ "uuid": "^11.1.1"
59
+ },
57
60
  "devDependencies": {
58
61
  "@prismicio/e2e-tests-utils": "^1.19.0",
59
62
  "@prismicio/types-internal-v3": "npm:@prismicio/types-internal@^3.17.2",
60
63
  "@prismicio/types-internal-v4-1-0": "npm:@prismicio/types-internal@4.1.0",
61
64
  "@types/node": "^26.1.1",
62
- "@vitest/coverage-v8": "^4.1.10",
65
+ "@vitest/coverage-v8": "^4.1.11",
63
66
  "io-ts": "^2.2.22",
64
- "oxfmt": "^0.59.0",
67
+ "oxfmt": "^0.67.0",
65
68
  "oxlint": "^1.74.0",
66
69
  "tsdown": "^0.22.8",
67
70
  "typescript": "^7.0.2",
68
- "vitest": "^4.1.10",
71
+ "vitest": "^4.1.11",
69
72
  "zod": "^4.4.3"
70
73
  },
71
74
  "peerDependencies": {
@@ -79,8 +82,5 @@
79
82
  },
80
83
  "engines": {
81
84
  "node": ">=22"
82
- },
83
- "dependencies": {
84
- "uuid": "^11.1.1"
85
85
  }
86
86
  }
@@ -48,6 +48,10 @@ export function blockLegacyToValue(block: RichTextLegacyBlock): RichTextContentB
48
48
 
49
49
  // Also used by content/codec/table
50
50
  export function blockValueToLegacy(block: RichTextContentBlock): RichTextLegacyBlock {
51
+ if (block.depth === 0) {
52
+ const { depth: _depth, ...withoutDepth } = block
53
+ return blockValueToLegacy(withoutDepth)
54
+ }
51
55
  if (block.type === RichTextNodeType.embed) {
52
56
  return {
53
57
  ...block,
@@ -5,6 +5,7 @@ import { z } from "zod/mini"
5
5
  import type { EmbedContentSchema } from "../embed"
6
6
  import type { ImageContentViewSchema } from "../image"
7
7
  import type { FilledLinkContentValue, FilledLinkContentValueSchema } from "../link"
8
+ import { getInvalidListDepth } from "../listDepth"
8
9
  import { EmbedLegacyLooseSchema } from "./embed"
9
10
  import { ImageLegacyViewSchema } from "./image"
10
11
  import { FilledLinkLegacyValueSchema } from "./link"
@@ -111,30 +112,43 @@ export const getTextBlockSchema = <
111
112
  >(
112
113
  linkSchema: TLinkSchema,
113
114
  ) =>
114
- z.object({
115
- type: TextBlockTypeSchema,
116
- content: z.object({
117
- text: z.string(),
118
- spans: z.optional(
119
- z.pipe(
120
- z.array(z.unknown()),
121
- z.transform((spans) => {
122
- const spanSchema = getSpanSchema(linkSchema)
123
-
124
- // Filter out invalid spans and order them by start position
125
- return spans
126
- .flatMap((maybeSpan) => {
127
- const parsed = spanSchema.safeParse(maybeSpan)
128
- return parsed.success ? [parsed.data] : []
129
- })
130
- .sort((a, b) => a.start - b.start)
131
- }),
115
+ z
116
+ .object({
117
+ type: TextBlockTypeSchema,
118
+ content: z.object({
119
+ text: z.string(),
120
+ spans: z.optional(
121
+ z.pipe(
122
+ z.array(z.unknown()),
123
+ z.transform((spans) => {
124
+ const spanSchema = getSpanSchema(linkSchema)
125
+
126
+ // Filter out invalid spans and order them by start position
127
+ return spans
128
+ .flatMap((maybeSpan) => {
129
+ const parsed = spanSchema.safeParse(maybeSpan)
130
+ return parsed.success ? [parsed.data] : []
131
+ })
132
+ .sort((a, b) => a.start - b.start)
133
+ }),
134
+ ),
132
135
  ),
133
- ),
134
- }),
135
- label: z.optional(z.string()),
136
- direction: z.optional(z.string()),
137
- })
136
+ }),
137
+ label: z.optional(z.string()),
138
+ direction: z.optional(z.string()),
139
+ depth: z.optional(z.int().check(z.gte(0))),
140
+ })
141
+ .check(
142
+ z.superRefine((block, ctx) => {
143
+ if (block.depth && block.type !== "list-item" && block.type !== "o-list-item") {
144
+ ctx.addIssue({
145
+ code: "custom",
146
+ path: ["depth"],
147
+ message: "Only list items can have a positive depth",
148
+ })
149
+ }
150
+ }),
151
+ )
138
152
 
139
153
  const TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema)
140
154
 
@@ -155,6 +169,7 @@ export const getImageBlockSchema = <
155
169
  data: z.extend(data, { linkTo: z.nullish(linkTo) }),
156
170
  label: z.nullish(z.string()),
157
171
  direction: z.nullish(z.string()),
172
+ depth: z.optional(z.literal(0)),
158
173
  })
159
174
 
160
175
  const ImageBlockLegacySchema = getImageBlockSchema(
@@ -176,6 +191,7 @@ export const getEmbedBlockSchema = <
176
191
  data,
177
192
  label: z.nullish(z.string()),
178
193
  direction: z.nullish(z.string()),
194
+ depth: z.optional(z.literal(0)),
179
195
  })
180
196
 
181
197
  const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
@@ -190,6 +206,16 @@ export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.d
190
206
 
191
207
  export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
192
208
 
193
- export const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema)
209
+ export const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema).check(
210
+ z.superRefine((blocks, ctx) => {
211
+ const index = getInvalidListDepth(blocks)
212
+ if (index !== undefined)
213
+ ctx.addIssue({
214
+ code: "custom",
215
+ path: [index, "depth"],
216
+ message: "List depth requires a parent at the preceding level",
217
+ })
218
+ }),
219
+ )
194
220
 
195
221
  export type RichTextLegacy = z.infer<typeof RichTextLegacySchema>
@@ -0,0 +1,39 @@
1
+ /** Returns the first block whose list hierarchy cannot be represented. */
2
+ export function getInvalidListDepth(
3
+ blocks: readonly { type: string; depth?: number }[],
4
+ ): number | undefined {
5
+ let previousDepth = -1
6
+ for (let index = 0; index < blocks.length; index++) {
7
+ const block = blocks[index]
8
+ const depth = block.depth ?? 0
9
+ if (!Number.isSafeInteger(depth) || depth < 0) return index
10
+ if (block.type !== "list-item" && block.type !== "o-list-item") {
11
+ if (depth > 0) return index
12
+ previousDepth = -1
13
+ continue
14
+ }
15
+ if (depth > previousDepth + 1) return index
16
+ previousDepth = depth
17
+ }
18
+ return undefined
19
+ }
20
+
21
+ /** Detect nesting anywhere in a document, including group and slice fields. */
22
+ export function hasRichTextNesting(content: unknown): boolean {
23
+ const pending: unknown[] = [content]
24
+ while (pending.length) {
25
+ const value = pending.pop()
26
+ if (!value || typeof value !== "object") continue
27
+ if (
28
+ "type" in value &&
29
+ (value.type === "list-item" || value.type === "o-list-item") &&
30
+ "depth" in value &&
31
+ typeof value.depth === "number" &&
32
+ Number.isSafeInteger(value.depth) &&
33
+ value.depth > 0
34
+ )
35
+ return true
36
+ for (const child of Object.values(value)) pending.push(child)
37
+ }
38
+ return false
39
+ }
@@ -11,6 +11,7 @@ import {
11
11
  import type { Span } from "./legacy/richText"
12
12
  import type { FilledLinkContentValue } from "./link"
13
13
  import { FilledLinkContentValueSchema } from "./link"
14
+ import { getInvalidListDepth } from "./listDepth"
14
15
 
15
16
  export { RichTextNodeType } from "./legacy/richText"
16
17
  export type { RichTextNodeTypes } from "./legacy/richText"
@@ -59,5 +60,15 @@ export type RichTextContent = {
59
60
 
60
61
  export const RichTextContentSchema = z.object({
61
62
  __TYPE__: z.literal(RichTextContentType),
62
- value: z.array(RichTextContentBlockSchema),
63
+ value: z.array(RichTextContentBlockSchema).check(
64
+ z.superRefine((blocks, ctx) => {
65
+ const index = getInvalidListDepth(blocks)
66
+ if (index !== undefined)
67
+ ctx.addIssue({
68
+ code: "custom",
69
+ path: [index, "depth"],
70
+ message: "List depth requires a parent at the preceding level",
71
+ })
72
+ }),
73
+ ),
63
74
  })
package/src/index.ts CHANGED
@@ -37,6 +37,7 @@ export type {
37
37
  RichTextNodeTypes,
38
38
  } from "./content/richText"
39
39
  export { RichTextNodeType } from "./content/richText"
40
+ export { getInvalidListDepth, hasRichTextNesting } from "./content/listDepth"
40
41
  export type { SeparatorContent } from "./content/separator"
41
42
  export type {
42
43
  LegacySliceContent,