@prismicio/types-internal 4.8.0-pr.39.a4627e7 → 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.
- package/dist/content/codec/richText.js +4 -0
- package/dist/content/codec/richText.js.map +1 -1
- package/dist/content/legacy/richText.d.ts +3 -0
- package/dist/content/legacy/richText.d.ts.map +1 -1
- package/dist/content/legacy/richText.js +22 -5
- package/dist/content/legacy/richText.js.map +1 -1
- package/dist/content/listDepth.d.ts +11 -0
- package/dist/content/listDepth.d.ts.map +1 -0
- package/dist/content/listDepth.js +32 -0
- package/dist/content/listDepth.js.map +1 -0
- package/dist/content/richText.d.ts +3 -0
- package/dist/content/richText.d.ts.map +1 -1
- package/dist/content/richText.js +9 -1
- package/dist/content/richText.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/model/group.d.ts +32 -32
- package/package.json +4 -4
- package/src/content/codec/richText.ts +4 -0
- package/src/content/legacy/richText.ts +50 -24
- package/src/content/listDepth.ts +39 -0
- package/src/content/richText.ts +12 -1
- package/src/index.ts +1 -0
|
@@ -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,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,UAAU,GAAG;EACtB,MAAM,EAAE,OAAO,QAAQ,GAAG,iBAAiB;EAC3C,OAAO,mBAAmB,YAAY;CACvC;CACA,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"}
|
|
@@ -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":";;;;;;;;
|
|
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":"
|
|
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,EAAG,CACpF;AACD,CAAC;AAGD,MAAM,kBAAkB,EAAE,OAAO;CAChC,MAAM,EAAE,MAAM;EACb,EAAE,QAAQ,iBAAiB,MAAM;EACjC,EAAE,QAAQ,iBAAiB,EAAE;EAC7B,EAAE,QAAQ,WAAW;CACtB,CAAC;CACD,OAAO,EAAE,OAAO;CAChB,KAAK,EAAE,OAAO;AACf,CAAC;AAWD,MAAa,iBAGZ,eAEA,EAAE,mBAAmB,QAAQ;CAC5B,uBAAuB,UAAU;CACjC;CACA;AACD,CAAC;AAGF,MAAM,sBAAsB,EAAE,MAAM;CACnC,EAAE,QAAQ,iBAAiB,SAAS;CACpC,EAAE,QAAQ,iBAAiB,QAAQ;CACnC,EAAE,QAAQ,iBAAiB,QAAQ;CACnC,EAAE,QAAQ,iBAAiB,QAAQ;CACnC,EAAE,QAAQ,iBAAiB,QAAQ;CACnC,EAAE,QAAQ,iBAAiB,QAAQ;CACnC,EAAE,QAAQ,iBAAiB,QAAQ;CACnC,EAAE,QAAQ,iBAAiB,YAAY;CACvC,EAAE,QAAQ,iBAAiB,SAAS;CACpC,EAAE,QAAQ,iBAAiB,QAAQ;AACpC,CAAC;AAGD,MAAa,sBAGZ,eAEA,EACE,OAAO;CACP,MAAM;CACN,SAAS,EAAE,OAAO;EACjB,MAAM,EAAE,OAAO;EACf,OAAO,EAAE,SACR,EAAE,KACD,EAAE,MAAM,EAAE,QAAQ,CAAC,GACnB,EAAE,WAAW,UAAU;GACtB,MAAM,aAAa,cAAc,UAAU;GAG3C,OAAO,MACL,SAAS,cAAc;IACvB,MAAM,SAAS,WAAW,UAAU,SAAS;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;CAChC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CACD,MACA,EAAE,aAAa,OAAO,QAAQ;CAC7B,IAAI,MAAM,SAAS,MAAM,SAAS,eAAe,MAAM,SAAS,eAC/D,IAAI,SAAS;EACZ,MAAM;EACN,MAAM,CAAC,OAAO;EACd,SAAS;CACV,CAAC;AAEH,CAAC,CACF;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;CAC/B,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAC/B,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;CAC/B,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAEF,MAAM,yBAAyB,oBAAoB,sBAAsB;AAKzE,MAAa,4BAAgE,EAAE,mBAC9E,QACA;CAAC;CAAuB;CAAwB;AAAsB,CACvE;AAIA,MAAa,uBAAuB,EAAE,MAAM,yBAAyB,CAAC,CAAC,MACtE,EAAE,aAAa,QAAQ,QAAQ;CAC9B,MAAM,QAAQ,oBAAoB,MAAM;CACxC,IAAI,UAAU,KAAA,GACb,IAAI,SAAS;EACZ,MAAM;EACN,MAAM,CAAC,OAAO,OAAO;EACrB,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":";;;;
|
|
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"}
|
package/dist/content/richText.js
CHANGED
|
@@ -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":"
|
|
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/dist/model/group.d.ts
CHANGED
|
@@ -202,6 +202,22 @@ declare const GroupModelSchema: z.ZodMiniObject<{
|
|
|
202
202
|
label?: string | null | undefined;
|
|
203
203
|
repeat?: boolean | undefined;
|
|
204
204
|
fields?: Record<string, {
|
|
205
|
+
type: "StructuredText";
|
|
206
|
+
fieldset?: string | null | undefined;
|
|
207
|
+
config?: {
|
|
208
|
+
label?: string | null | undefined;
|
|
209
|
+
placeholder?: string | undefined;
|
|
210
|
+
useAsTitle?: boolean | undefined;
|
|
211
|
+
single?: string | undefined;
|
|
212
|
+
multi?: string | undefined;
|
|
213
|
+
imageConstraint?: {
|
|
214
|
+
width?: number | null | undefined;
|
|
215
|
+
height?: number | null | undefined;
|
|
216
|
+
} | undefined;
|
|
217
|
+
labels?: string[] | undefined;
|
|
218
|
+
allowTargetBlank?: boolean | undefined;
|
|
219
|
+
} | undefined;
|
|
220
|
+
} | {
|
|
205
221
|
type: "Boolean";
|
|
206
222
|
config?: {
|
|
207
223
|
label?: string | null | undefined;
|
|
@@ -322,22 +338,6 @@ declare const GroupModelSchema: z.ZodMiniObject<{
|
|
|
322
338
|
max?: number | undefined;
|
|
323
339
|
step?: number | undefined;
|
|
324
340
|
} | undefined;
|
|
325
|
-
} | {
|
|
326
|
-
type: "StructuredText";
|
|
327
|
-
fieldset?: string | null | undefined;
|
|
328
|
-
config?: {
|
|
329
|
-
label?: string | null | undefined;
|
|
330
|
-
placeholder?: string | undefined;
|
|
331
|
-
useAsTitle?: boolean | undefined;
|
|
332
|
-
single?: string | undefined;
|
|
333
|
-
multi?: string | undefined;
|
|
334
|
-
imageConstraint?: {
|
|
335
|
-
width?: number | null | undefined;
|
|
336
|
-
height?: number | null | undefined;
|
|
337
|
-
} | undefined;
|
|
338
|
-
labels?: string[] | undefined;
|
|
339
|
-
allowTargetBlank?: boolean | undefined;
|
|
340
|
-
} | undefined;
|
|
341
341
|
} | {
|
|
342
342
|
type: "Select";
|
|
343
343
|
fieldset?: string | null | undefined;
|
|
@@ -384,6 +384,22 @@ declare const GroupModelSchema: z.ZodMiniObject<{
|
|
|
384
384
|
label?: string | null | undefined;
|
|
385
385
|
repeat?: boolean | undefined;
|
|
386
386
|
fields?: Record<string, {
|
|
387
|
+
type: "StructuredText";
|
|
388
|
+
fieldset?: string | null | undefined;
|
|
389
|
+
config?: {
|
|
390
|
+
label?: string | null | undefined;
|
|
391
|
+
placeholder?: string | undefined;
|
|
392
|
+
useAsTitle?: boolean | undefined;
|
|
393
|
+
single?: string | undefined;
|
|
394
|
+
multi?: string | undefined;
|
|
395
|
+
imageConstraint?: {
|
|
396
|
+
width?: number | null | undefined;
|
|
397
|
+
height?: number | null | undefined;
|
|
398
|
+
} | undefined;
|
|
399
|
+
labels?: string[] | undefined;
|
|
400
|
+
allowTargetBlank?: boolean | undefined;
|
|
401
|
+
} | undefined;
|
|
402
|
+
} | {
|
|
387
403
|
type: "Boolean";
|
|
388
404
|
config?: {
|
|
389
405
|
label?: string | null | undefined;
|
|
@@ -504,22 +520,6 @@ declare const GroupModelSchema: z.ZodMiniObject<{
|
|
|
504
520
|
max?: number | undefined;
|
|
505
521
|
step?: number | undefined;
|
|
506
522
|
} | undefined;
|
|
507
|
-
} | {
|
|
508
|
-
type: "StructuredText";
|
|
509
|
-
fieldset?: string | null | undefined;
|
|
510
|
-
config?: {
|
|
511
|
-
label?: string | null | undefined;
|
|
512
|
-
placeholder?: string | undefined;
|
|
513
|
-
useAsTitle?: boolean | undefined;
|
|
514
|
-
single?: string | undefined;
|
|
515
|
-
multi?: string | undefined;
|
|
516
|
-
imageConstraint?: {
|
|
517
|
-
width?: number | null | undefined;
|
|
518
|
-
height?: number | null | undefined;
|
|
519
|
-
} | undefined;
|
|
520
|
-
labels?: string[] | undefined;
|
|
521
|
-
allowTargetBlank?: boolean | undefined;
|
|
522
|
-
} | undefined;
|
|
523
523
|
} | {
|
|
524
524
|
type: "Select";
|
|
525
525
|
fieldset?: string | null | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/types-internal",
|
|
3
|
-
"version": "4.
|
|
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,6 +54,9 @@
|
|
|
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",
|
|
@@ -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
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
z.
|
|
120
|
-
z.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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
|
+
}
|
package/src/content/richText.ts
CHANGED
|
@@ -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,
|