@prismicio/types-internal 4.8.1-pr.43.84185d3 → 4.8.1-pr.44.80cfc63
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 +10 -8
- package/dist/content/codec/richText.js.map +1 -1
- package/dist/io-ts.d.ts +1313 -1313
- package/dist/io-ts.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/content/codec/richText.ts +3 -3
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RichTextLegacyBlockSchema, RichTextLegacySchema, RichTextNodeType } from "../legacy/richText.js";
|
|
2
2
|
import { RichTextContentSchema, RichTextContentType } from "../richText.js";
|
|
3
3
|
import { embedContentToLegacy, embedLegacyToContent } from "./embed.js";
|
|
4
|
-
import { imageLegacyToContent } from "./image.js";
|
|
5
4
|
import { linkLegacyToValue, linkValueToLegacy } from "./link.js";
|
|
6
5
|
//#region src/content/codec/richText.ts
|
|
7
6
|
function blockLegacyToValue(block) {
|
|
@@ -9,13 +8,16 @@ function blockLegacyToValue(block) {
|
|
|
9
8
|
...block,
|
|
10
9
|
data: embedLegacyToContent(block.data)
|
|
11
10
|
};
|
|
12
|
-
if (block.type === RichTextNodeType.image)
|
|
13
|
-
...block
|
|
14
|
-
|
|
15
|
-
...
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
if (block.type === RichTextNodeType.image) {
|
|
12
|
+
const { linkTo, ...imageData } = block.data;
|
|
13
|
+
return {
|
|
14
|
+
...block,
|
|
15
|
+
data: {
|
|
16
|
+
...imageData,
|
|
17
|
+
...linkTo !== void 0 ? { linkTo: linkTo ? linkLegacyToValue(linkTo) : null } : {}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
19
21
|
const spans = [];
|
|
20
22
|
for (const span of block.content.spans ?? []) if (span.type === RichTextNodeType.hyperlink) {
|
|
21
23
|
if (span.data) spans.push({
|
|
@@ -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
|
|
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 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\tconst { linkTo, ...imageData } = block.data\n\t\treturn {\n\t\t\t...block,\n\t\t\tdata: {\n\t\t\t\t...imageData,\n\t\t\t\t...(linkTo !== undefined ? { linkTo: linkTo ? linkLegacyToValue(linkTo) : null } : {}),\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":";;;;;AAaA,SAAgB,mBAAmB,OAAkD;CACpF,IAAI,MAAM,SAAS,iBAAiB,OACnC,OAAO;EACN,GAAG;EACH,MAAM,qBAAqB,MAAM,IAAI;CACtC;CAGD,IAAI,MAAM,SAAS,iBAAiB,OAAO;EAC1C,MAAM,EAAE,QAAQ,GAAG,cAAc,MAAM;EACvC,OAAO;GACN,GAAG;GACH,MAAM;IACL,GAAG;IACH,GAAI,WAAW,KAAA,IAAY,EAAE,QAAQ,SAAS,kBAAkB,MAAM,IAAI,KAAK,IAAI,CAAC;GACrF;EACD;CACD;CAEA,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;CA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