@prismicio/client 7.7.3 → 7.7.4
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/README.md +3 -3
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +1 -1
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.cjs.map +1 -1
- package/dist/cookie.js.map +1 -1
- package/dist/createClient.cjs +31 -31
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +35 -35
- package/dist/createClient.js +31 -31
- package/dist/createClient.js.map +1 -1
- package/dist/errors/ForbiddenError.cjs.map +1 -1
- package/dist/errors/ForbiddenError.js.map +1 -1
- package/dist/errors/NotFoundError.cjs.map +1 -1
- package/dist/errors/NotFoundError.js.map +1 -1
- package/dist/errors/ParsingError.cjs.map +1 -1
- package/dist/errors/ParsingError.js.map +1 -1
- package/dist/errors/PreviewTokenExpired.cjs.map +1 -1
- package/dist/errors/PreviewTokenExpired.js.map +1 -1
- package/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/errors/PrismicError.js.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.js.map +1 -1
- package/dist/errors/RefExpiredError.cjs.map +1 -1
- package/dist/errors/RefExpiredError.js.map +1 -1
- package/dist/errors/RefNotFoundError.cjs.map +1 -1
- package/dist/errors/RefNotFoundError.js.map +1 -1
- package/dist/errors/RepositoryNotFoundError.cjs.map +1 -1
- package/dist/errors/RepositoryNotFoundError.js.map +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +2 -2
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +2 -2
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +2 -2
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +2 -2
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +2 -4
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +2 -2
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +1 -1
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +1 -1
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/helpers/unstable_htmlAsRichText.cjs.map +1 -1
- package/dist/helpers/unstable_htmlAsRichText.d.ts +4 -4
- package/dist/helpers/unstable_htmlAsRichText.js.map +1 -1
- package/dist/helpers/unstable_markdownAsRichText.cjs.map +1 -1
- package/dist/helpers/unstable_markdownAsRichText.d.ts +2 -2
- package/dist/helpers/unstable_markdownAsRichText.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
- package/dist/lib/RichTextFieldBuilder.d.ts +1 -1
- package/dist/lib/RichTextFieldBuilder.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.d.ts +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/everyTagFilter.js.map +1 -1
- package/dist/lib/filterRichTextField.cjs.map +1 -1
- package/dist/lib/filterRichTextField.d.ts +3 -3
- package/dist/lib/filterRichTextField.js.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +1 -1
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +1 -1
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +1 -1
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +1 -1
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/hastSerializerHelpers.cjs.map +1 -1
- package/dist/lib/hastSerializerHelpers.d.ts +3 -3
- package/dist/lib/hastSerializerHelpers.js.map +1 -1
- package/dist/lib/hastToRichText.cjs +1 -2
- package/dist/lib/hastToRichText.cjs.map +1 -1
- package/dist/lib/hastToRichText.d.ts +4 -4
- package/dist/lib/hastToRichText.js +1 -2
- package/dist/lib/hastToRichText.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
- package/dist/lib/minifyGraphQLQuery.js.map +1 -1
- package/dist/lib/rehypeRichText.cjs.map +1 -1
- package/dist/lib/rehypeRichText.d.ts +5 -5
- package/dist/lib/rehypeRichText.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +2 -2
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs.map +1 -1
- package/dist/lib/someTagsFilter.js.map +1 -1
- package/dist/lib/typeFilter.cjs.map +1 -1
- package/dist/lib/typeFilter.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.ts +1 -1
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.ts +2 -2
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +1 -1
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +1 -1
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/api/query.d.ts +1 -1
- package/dist/types/api/release.d.ts +1 -1
- package/dist/types/api/repository.d.ts +1 -1
- package/dist/types/model/customType.d.ts +1 -1
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.js.map +1 -1
- package/dist/types/model/slice.cjs.map +1 -1
- package/dist/types/model/slice.js.map +1 -1
- package/dist/types/model/sliceZone.cjs.map +1 -1
- package/dist/types/model/sliceZone.js.map +1 -1
- package/dist/types/model/title.d.ts +1 -1
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/value/document.d.ts +4 -4
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.js.map +1 -1
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.js.map +1 -1
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.js.map +1 -1
- package/dist/types/webhook/apiUpdate.d.ts +1 -1
- package/dist/types/webhook/testTrigger.d.ts +1 -1
- package/dist/types/webhook/types.cjs.map +1 -1
- package/dist/types/webhook/types.d.ts +2 -2
- package/dist/types/webhook/types.js.map +1 -1
- package/package.json +1 -1
- package/src/buildQueryURL.ts +51 -51
- package/src/cookie.ts +1 -1
- package/src/createClient.ts +293 -293
- package/src/errors/ForbiddenError.ts +6 -6
- package/src/errors/NotFoundError.ts +1 -1
- package/src/errors/ParsingError.ts +8 -8
- package/src/errors/PreviewTokenExpired.ts +4 -4
- package/src/errors/PrismicError.ts +5 -5
- package/src/errors/PrismicRichTextSerializerError.ts +1 -1
- package/src/errors/RefExpiredError.ts +4 -4
- package/src/errors/RefNotFoundError.ts +4 -4
- package/src/errors/RepositoryNotFoundError.ts +1 -1
- package/src/filter.ts +22 -22
- package/src/getGraphQLEndpoint.ts +5 -5
- package/src/getRepositoryEndpoint.ts +5 -5
- package/src/getRepositoryName.ts +4 -4
- package/src/getToolbarSrc.ts +5 -5
- package/src/helpers/asDate.ts +7 -7
- package/src/helpers/asHTML.ts +54 -56
- package/src/helpers/asImagePixelDensitySrcSet.ts +14 -17
- package/src/helpers/asImageSrc.ts +9 -8
- package/src/helpers/asImageWidthSrcSet.ts +19 -22
- package/src/helpers/asLink.ts +26 -27
- package/src/helpers/asLinkAttrs.ts +30 -29
- package/src/helpers/asText.ts +15 -15
- package/src/helpers/documentToLinkField.ts +6 -6
- package/src/helpers/isFilled.ts +53 -53
- package/src/helpers/mapSliceZone.ts +34 -34
- package/src/helpers/unstable_htmlAsRichText.ts +23 -22
- package/src/helpers/unstable_markdownAsRichText.ts +14 -13
- package/src/index.ts +119 -119
- package/src/isRepositoryEndpoint.ts +4 -4
- package/src/isRepositoryName.ts +2 -2
- package/src/lib/RichTextFieldBuilder.ts +36 -41
- package/src/lib/appendFilters.ts +4 -4
- package/src/lib/castArray.ts +2 -2
- package/src/lib/castThunk.ts +2 -2
- package/src/lib/devMsg.ts +4 -4
- package/src/lib/escapeHTML.ts +24 -24
- package/src/lib/everyTagFilter.ts +4 -4
- package/src/lib/filterRichTextField.ts +31 -31
- package/src/lib/findMasterRef.ts +4 -4
- package/src/lib/findRef.ts +6 -6
- package/src/lib/findRefByID.ts +4 -4
- package/src/lib/findRefByLabel.ts +4 -4
- package/src/lib/getPreviewCookie.ts +11 -11
- package/src/lib/hastSerializerHelpers.ts +41 -37
- package/src/lib/hastToRichText.ts +74 -73
- package/src/lib/isInternalURL.ts +4 -4
- package/src/lib/minifyGraphQLQuery.ts +2 -2
- package/src/lib/rehypeRichText.ts +42 -41
- package/src/lib/serializerHelpers.ts +53 -54
- package/src/lib/someTagsFilter.ts +4 -4
- package/src/lib/typeFilter.ts +3 -3
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/asTree.ts +53 -53
- package/src/richtext/composeSerializers.ts +6 -6
- package/src/richtext/index.ts +7 -7
- package/src/richtext/serialize.ts +11 -11
- package/src/richtext/types.ts +38 -38
- package/src/richtext/wrapMapSerializer.ts +6 -9
- package/src/types/api/query.ts +9 -9
- package/src/types/api/ref.ts +5 -5
- package/src/types/api/release.ts +2 -2
- package/src/types/api/repository.ts +24 -24
- package/src/types/api/tags.ts +1 -1
- package/src/types/model/boolean.ts +7 -7
- package/src/types/model/color.ts +5 -5
- package/src/types/model/contentRelationship.ts +9 -9
- package/src/types/model/customType.ts +9 -9
- package/src/types/model/date.ts +6 -6
- package/src/types/model/embed.ts +5 -5
- package/src/types/model/geoPoint.ts +4 -4
- package/src/types/model/group.ts +6 -6
- package/src/types/model/image.ts +9 -9
- package/src/types/model/integration.ts +6 -6
- package/src/types/model/keyText.ts +5 -5
- package/src/types/model/link.ts +8 -8
- package/src/types/model/linkToMedia.ts +7 -7
- package/src/types/model/number.ts +7 -7
- package/src/types/model/range.ts +8 -8
- package/src/types/model/richText.ts +16 -16
- package/src/types/model/select.ts +7 -7
- package/src/types/model/separator.ts +4 -4
- package/src/types/model/sharedSlice.ts +7 -7
- package/src/types/model/sharedSliceVariation.ts +9 -9
- package/src/types/model/slice.ts +12 -12
- package/src/types/model/sliceZone.ts +11 -11
- package/src/types/model/timestamp.ts +6 -6
- package/src/types/model/title.ts +2 -2
- package/src/types/model/types.ts +26 -26
- package/src/types/model/uid.ts +5 -5
- package/src/types/value/boolean.ts +1 -1
- package/src/types/value/color.ts +2 -2
- package/src/types/value/contentRelationship.ts +15 -15
- package/src/types/value/date.ts +2 -2
- package/src/types/value/document.ts +23 -23
- package/src/types/value/embed.ts +33 -33
- package/src/types/value/geoPoint.ts +4 -4
- package/src/types/value/group.ts +3 -3
- package/src/types/value/image.ts +21 -21
- package/src/types/value/integration.ts +2 -2
- package/src/types/value/keyText.ts +2 -2
- package/src/types/value/link.ts +12 -12
- package/src/types/value/linkToMedia.ts +11 -11
- package/src/types/value/number.ts +2 -2
- package/src/types/value/richText.ts +58 -58
- package/src/types/value/select.ts +2 -2
- package/src/types/value/sharedSlice.ts +5 -5
- package/src/types/value/sharedSliceVariation.ts +5 -5
- package/src/types/value/slice.ts +6 -6
- package/src/types/value/sliceZone.ts +4 -4
- package/src/types/value/timestamp.ts +3 -3
- package/src/types/value/title.ts +4 -4
- package/src/types/value/types.ts +22 -22
- package/src/types/webhook/apiUpdate.ts +18 -18
- package/src/types/webhook/testTrigger.ts +2 -2
- package/src/types/webhook/types.ts +8 -8
- package/dist/_node_modules/hast-util-whitespace/lib/index.cjs +0 -11
- package/dist/_node_modules/hast-util-whitespace/lib/index.cjs.map +0 -1
- package/dist/_node_modules/hast-util-whitespace/lib/index.js +0 -11
- package/dist/_node_modules/hast-util-whitespace/lib/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findMasterRef.js","sources":["../../../src/lib/findMasterRef.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findMasterRef.js","sources":["../../../src/lib/findMasterRef.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { findRef } from \"./findRef\"\n\n/**\n * Returns the master ref from a list of given refs.\n *\n * @param refs - A list of refs to search.\n *\n * @returns The master ref from the list.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findMasterRef = (refs: Ref[]): Ref => {\n\treturn findRef(refs, (ref) => ref.isMasterRef)\n}\n"],"names":[],"mappings":";AAaa,MAAA,gBAAgB,CAAC,SAAoB;AACjD,SAAO,QAAQ,MAAM,CAAC,QAAQ,IAAI,WAAW;AAC9C;"}
|
package/dist/lib/findRef.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findRef.cjs","sources":["../../../src/lib/findRef.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findRef.cjs","sources":["../../../src/lib/findRef.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { PrismicError } from \"../errors/PrismicError\"\n\n/**\n * Returns the first ref from a list that passes a filter (a function that\n * returns true).\n *\n * @param refs - A list of refs to search.\n * @param filter - A function that determines if a ref from the list matches the\n * criteria.\n *\n * @returns The first matching ref.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {\n\tconst ref = refs.find((ref) => filter(ref))\n\n\tif (!ref) {\n\t\tthrow new PrismicError(\"Ref could not be found.\", undefined, undefined)\n\t}\n\n\treturn ref\n}\n"],"names":["ref","PrismicError"],"mappings":";;;AAgBa,MAAA,UAAU,CAAC,MAAa,WAAsC;AAC1E,QAAM,MAAM,KAAK,KAAK,CAACA,SAAQ,OAAOA,IAAG,CAAC;AAE1C,MAAI,CAAC,KAAK;AACT,UAAM,IAAIC,aAAA,aAAa,2BAA2B,QAAW,MAAS;AAAA,EACvE;AAEO,SAAA;AACR;;"}
|
package/dist/lib/findRef.d.ts
CHANGED
package/dist/lib/findRef.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findRef.js","sources":["../../../src/lib/findRef.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findRef.js","sources":["../../../src/lib/findRef.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { PrismicError } from \"../errors/PrismicError\"\n\n/**\n * Returns the first ref from a list that passes a filter (a function that\n * returns true).\n *\n * @param refs - A list of refs to search.\n * @param filter - A function that determines if a ref from the list matches the\n * criteria.\n *\n * @returns The first matching ref.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {\n\tconst ref = refs.find((ref) => filter(ref))\n\n\tif (!ref) {\n\t\tthrow new PrismicError(\"Ref could not be found.\", undefined, undefined)\n\t}\n\n\treturn ref\n}\n"],"names":["ref"],"mappings":";AAgBa,MAAA,UAAU,CAAC,MAAa,WAAsC;AAC1E,QAAM,MAAM,KAAK,KAAK,CAACA,SAAQ,OAAOA,IAAG,CAAC;AAE1C,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,aAAa,2BAA2B,QAAW,MAAS;AAAA,EACvE;AAEO,SAAA;AACR;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findRefByID.cjs","sources":["../../../src/lib/findRefByID.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findRefByID.cjs","sources":["../../../src/lib/findRefByID.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { findRef } from \"./findRef\"\n\n/**\n * Returns the ref from a list of given refs with a matching ID.\n *\n * @param refs - A list of refs to search.\n * @param id - The ID of the ref to find.\n *\n * @returns The ref with a matching ID from the list.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRefByID = (refs: Ref[], id: string): Ref => {\n\treturn findRef(refs, (ref) => ref.id === id)\n}\n"],"names":["findRef"],"mappings":";;;AAca,MAAA,cAAc,CAAC,MAAa,OAAmB;AAC3D,SAAOA,QAAAA,QAAQ,MAAM,CAAC,QAAQ,IAAI,OAAO,EAAE;AAC5C;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findRefByID.js","sources":["../../../src/lib/findRefByID.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findRefByID.js","sources":["../../../src/lib/findRefByID.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { findRef } from \"./findRef\"\n\n/**\n * Returns the ref from a list of given refs with a matching ID.\n *\n * @param refs - A list of refs to search.\n * @param id - The ID of the ref to find.\n *\n * @returns The ref with a matching ID from the list.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRefByID = (refs: Ref[], id: string): Ref => {\n\treturn findRef(refs, (ref) => ref.id === id)\n}\n"],"names":[],"mappings":";AAca,MAAA,cAAc,CAAC,MAAa,OAAmB;AAC3D,SAAO,QAAQ,MAAM,CAAC,QAAQ,IAAI,OAAO,EAAE;AAC5C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findRefByLabel.cjs","sources":["../../../src/lib/findRefByLabel.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findRefByLabel.cjs","sources":["../../../src/lib/findRefByLabel.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { findRef } from \"./findRef\"\n\n/**\n * Returns the ref from a list of given refs with a matching label.\n *\n * @param refs - A list of refs to search.\n * @param id - The label of the ref to find.\n *\n * @returns The ref with a matching label from the list.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRefByLabel = (refs: Ref[], label: string): Ref => {\n\treturn findRef(refs, (ref) => ref.label === label)\n}\n"],"names":["findRef"],"mappings":";;;AAca,MAAA,iBAAiB,CAAC,MAAa,UAAsB;AACjE,SAAOA,QAAAA,QAAQ,MAAM,CAAC,QAAQ,IAAI,UAAU,KAAK;AAClD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findRefByLabel.js","sources":["../../../src/lib/findRefByLabel.ts"],"sourcesContent":["import { Ref } from \"../types/api/ref\"
|
|
1
|
+
{"version":3,"file":"findRefByLabel.js","sources":["../../../src/lib/findRefByLabel.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { findRef } from \"./findRef\"\n\n/**\n * Returns the ref from a list of given refs with a matching label.\n *\n * @param refs - A list of refs to search.\n * @param id - The label of the ref to find.\n *\n * @returns The ref with a matching label from the list.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRefByLabel = (refs: Ref[], label: string): Ref => {\n\treturn findRef(refs, (ref) => ref.label === label)\n}\n"],"names":[],"mappings":";AAca,MAAA,iBAAiB,CAAC,MAAa,UAAsB;AACjE,SAAO,QAAQ,MAAM,CAAC,QAAQ,IAAI,UAAU,KAAK;AAClD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPreviewCookie.cjs","sources":["../../../src/lib/getPreviewCookie.ts"],"sourcesContent":["import { preview as previewCookieName } from \"../cookie\"
|
|
1
|
+
{"version":3,"file":"getPreviewCookie.cjs","sources":["../../../src/lib/getPreviewCookie.ts"],"sourcesContent":["import { preview as previewCookieName } from \"../cookie\"\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\")\n}\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nexport const getPreviewCookie = (cookieJar: string): string | undefined => {\n\tconst cookies = cookieJar.split(\"; \")\n\n\tlet value: string | undefined\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\")\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\")\n\n\t\tif (name === previewCookieName) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"))\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn value\n}\n"],"names":["cookie","previewCookieName"],"mappings":";;;AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,mBAAmB,CAAC,cAAyC;AACnE,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAWA,YAAU,SAAS;AACvB,UAAA,QAAQA,SAAO,MAAM,GAAG;AACxB,UAAA,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAEpD,QAAI,SAASC,OAAAA,SAAmB;AAC/B,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AACR;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPreviewCookie.js","sources":["../../../src/lib/getPreviewCookie.ts"],"sourcesContent":["import { preview as previewCookieName } from \"../cookie\"
|
|
1
|
+
{"version":3,"file":"getPreviewCookie.js","sources":["../../../src/lib/getPreviewCookie.ts"],"sourcesContent":["import { preview as previewCookieName } from \"../cookie\"\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\")\n}\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nexport const getPreviewCookie = (cookieJar: string): string | undefined => {\n\tconst cookies = cookieJar.split(\"; \")\n\n\tlet value: string | undefined\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\")\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\")\n\n\t\tif (name === previewCookieName) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"))\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn value\n}\n"],"names":["previewCookieName"],"mappings":";AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,mBAAmB,CAAC,cAAyC;AACnE,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AACxB,UAAA,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAEpD,QAAI,SAASA,SAAmB;AAC/B,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AACR;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hastSerializerHelpers.cjs","sources":["../../../src/lib/hastSerializerHelpers.ts"],"sourcesContent":["import { Element } from \"hast\"
|
|
1
|
+
{"version":3,"file":"hastSerializerHelpers.cjs","sources":["../../../src/lib/hastSerializerHelpers.ts"],"sourcesContent":["import type { Element } from \"hast\"\nimport { toHtml } from \"hast-util-to-html\"\n\nimport { OEmbedType } from \"../types/value/embed\"\nimport { LinkType } from \"../types/value/link\"\nimport type {\n\tRTEmbedNode,\n\tRTImageNode,\n\tRTLinkNode,\n} from \"../types/value/richText\"\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\"\n\nimport type { RTPartialInlineNode } from \"./RichTextFieldBuilder\"\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTImageNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTImageNode}.\n */\nexport const serializeImage = (node: Element): RTImageNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `img` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst url = new URL(src, \"https://noop.com\")\n\n\tlet width = node.properties?.width as number | undefined\n\tlet height = node.properties?.height as number | undefined\n\tlet x = 0\n\tlet y = 0\n\tlet zoom = 1\n\n\t// Attempt to infer the image dimensions from the URL imgix parameters.\n\tif (url.hostname === \"images.prismic.io\") {\n\t\tif (url.searchParams.has(\"w\")) {\n\t\t\twidth = Number(url.searchParams.get(\"w\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"h\")) {\n\t\t\theight = Number(url.searchParams.get(\"h\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"rect\")) {\n\t\t\tconst [rectX, rextY, rectW, _rectH] = url.searchParams\n\t\t\t\t.get(\"rect\")!\n\t\t\t\t.split(\",\")\n\n\t\t\tx = Number(rectX)\n\t\t\ty = Number(rextY)\n\n\t\t\t// This is not perfect but it's supposed to work on images without constraints.\n\t\t\tif (width) {\n\t\t\t\tzoom = Math.max(1, width / Number(rectW))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: \"image\",\n\t\tid: \"\",\n\t\turl: src,\n\t\talt: (node.properties?.alt as string) ?? \"\",\n\t\tcopyright: (node.properties?.copyright as string) ?? null,\n\t\t// This is not accurate. We're doing the casting because it seems the migration API\n\t\t// accepts `undefined` values for those fields which is more convenient to us here.\n\t\t// See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185\n\t\tdimensions: { width: width as number, height: height as number },\n\t\tedit: { x, y, zoom, background: \"transparent\" },\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTEmbedNode}.\n */\nexport const serializeEmbed = (node: Element): RTEmbedNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `embed` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst oembedBase = {\n\t\tversion: \"1.0\",\n\t\tembed_url: src,\n\t\thtml: toHtml(node),\n\t\ttitle: node.properties?.title as string | undefined,\n\t}\n\n\tconst width = node.properties?.width as number | undefined\n\tconst height = node.properties?.height as number | undefined\n\n\t// Remove the children of the embed node as we don't want to process them.\n\tnode.children = []\n\n\tif (width && height) {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Rich, width, height },\n\t\t}\n\t} else {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Link },\n\t\t}\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.\n *\n * @param node - A hast node to serialize.\n * @param rtPartialInlineNode - A partial rich text node.\n *\n * @returns Equivalent {@link RTPartialInlineNode}.\n */\nexport const serializeSpan = (\n\tnode: Element,\n\trtPartialInlineNode:\n\t\t| RTPartialInlineNode\n\t\t| Omit<RTLinkNode, \"start\" | \"end\" | \"data\">,\n): RTPartialInlineNode => {\n\tif (\n\t\trtPartialInlineNode.type === \"hyperlink\" &&\n\t\t!(\"data\" in rtPartialInlineNode)\n\t) {\n\t\tconst url = node.properties?.href as string | undefined\n\t\tif (!url) {\n\t\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\t\"Element of type `hyperlink` is missing an `href` attribute\",\n\t\t\t)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"hyperlink\",\n\t\t\tdata: {\n\t\t\t\tlink_type: LinkType.Web,\n\t\t\t\turl,\n\t\t\t\ttarget: node.properties?.target as string | undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn rtPartialInlineNode\n}\n"],"names":["PrismicRichTextSerializerError","toHtml","OEmbedType","LinkType"],"mappings":";;;;;;AAsBa,MAAA,iBAAiB,CAAC,SAA8B;;AACtD,QAAA,OAAM,UAAK,eAAL,mBAAiB;AAE7B,MAAI,CAAC,KAAK;AACH,UAAA,IAAIA,+BAAAA,+BACT,qDAAqD;AAAA,EAEvD;AAEA,QAAM,MAAM,IAAI,IAAI,KAAK,kBAAkB;AAEvC,MAAA,SAAQ,UAAK,eAAL,mBAAiB;AACzB,MAAA,UAAS,UAAK,eAAL,mBAAiB;AAC9B,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAI,OAAO;AAGP,MAAA,IAAI,aAAa,qBAAqB;AACzC,QAAI,IAAI,aAAa,IAAI,GAAG,GAAG;AAC9B,cAAQ,OAAO,IAAI,aAAa,IAAI,GAAG,CAAC;AAAA,IACzC;AAEA,QAAI,IAAI,aAAa,IAAI,GAAG,GAAG;AAC9B,eAAS,OAAO,IAAI,aAAa,IAAI,GAAG,CAAC;AAAA,IAC1C;AAEA,QAAI,IAAI,aAAa,IAAI,MAAM,GAAG;AACjC,YAAM,CAAC,OAAO,OAAO,OAAO,MAAM,IAAI,IAAI,aACxC,IAAI,MAAM,EACV,MAAM,GAAG;AAEX,UAAI,OAAO,KAAK;AAChB,UAAI,OAAO,KAAK;AAGhB,UAAI,OAAO;AACV,eAAO,KAAK,IAAI,GAAG,QAAQ,OAAO,KAAK,CAAC;AAAA,MACzC;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AAAA,IACN,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,OAAM,UAAK,eAAL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AAA;AACR;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Element } from "hast";
|
|
2
|
-
import { RTEmbedNode, RTImageNode, RTLinkNode } from "../types/value/richText";
|
|
3
|
-
import { RTPartialInlineNode } from "./RichTextFieldBuilder";
|
|
1
|
+
import type { Element } from "hast";
|
|
2
|
+
import type { RTEmbedNode, RTImageNode, RTLinkNode } from "../types/value/richText";
|
|
3
|
+
import type { RTPartialInlineNode } from "./RichTextFieldBuilder";
|
|
4
4
|
/**
|
|
5
5
|
* Serializes a hast {@link Element} node to a {@link RTImageNode}.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hastSerializerHelpers.js","sources":["../../../src/lib/hastSerializerHelpers.ts"],"sourcesContent":["import { Element } from \"hast\"
|
|
1
|
+
{"version":3,"file":"hastSerializerHelpers.js","sources":["../../../src/lib/hastSerializerHelpers.ts"],"sourcesContent":["import type { Element } from \"hast\"\nimport { toHtml } from \"hast-util-to-html\"\n\nimport { OEmbedType } from \"../types/value/embed\"\nimport { LinkType } from \"../types/value/link\"\nimport type {\n\tRTEmbedNode,\n\tRTImageNode,\n\tRTLinkNode,\n} from \"../types/value/richText\"\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\"\n\nimport type { RTPartialInlineNode } from \"./RichTextFieldBuilder\"\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTImageNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTImageNode}.\n */\nexport const serializeImage = (node: Element): RTImageNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `img` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst url = new URL(src, \"https://noop.com\")\n\n\tlet width = node.properties?.width as number | undefined\n\tlet height = node.properties?.height as number | undefined\n\tlet x = 0\n\tlet y = 0\n\tlet zoom = 1\n\n\t// Attempt to infer the image dimensions from the URL imgix parameters.\n\tif (url.hostname === \"images.prismic.io\") {\n\t\tif (url.searchParams.has(\"w\")) {\n\t\t\twidth = Number(url.searchParams.get(\"w\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"h\")) {\n\t\t\theight = Number(url.searchParams.get(\"h\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"rect\")) {\n\t\t\tconst [rectX, rextY, rectW, _rectH] = url.searchParams\n\t\t\t\t.get(\"rect\")!\n\t\t\t\t.split(\",\")\n\n\t\t\tx = Number(rectX)\n\t\t\ty = Number(rextY)\n\n\t\t\t// This is not perfect but it's supposed to work on images without constraints.\n\t\t\tif (width) {\n\t\t\t\tzoom = Math.max(1, width / Number(rectW))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: \"image\",\n\t\tid: \"\",\n\t\turl: src,\n\t\talt: (node.properties?.alt as string) ?? \"\",\n\t\tcopyright: (node.properties?.copyright as string) ?? null,\n\t\t// This is not accurate. We're doing the casting because it seems the migration API\n\t\t// accepts `undefined` values for those fields which is more convenient to us here.\n\t\t// See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185\n\t\tdimensions: { width: width as number, height: height as number },\n\t\tedit: { x, y, zoom, background: \"transparent\" },\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTEmbedNode}.\n */\nexport const serializeEmbed = (node: Element): RTEmbedNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `embed` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst oembedBase = {\n\t\tversion: \"1.0\",\n\t\tembed_url: src,\n\t\thtml: toHtml(node),\n\t\ttitle: node.properties?.title as string | undefined,\n\t}\n\n\tconst width = node.properties?.width as number | undefined\n\tconst height = node.properties?.height as number | undefined\n\n\t// Remove the children of the embed node as we don't want to process them.\n\tnode.children = []\n\n\tif (width && height) {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Rich, width, height },\n\t\t}\n\t} else {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Link },\n\t\t}\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.\n *\n * @param node - A hast node to serialize.\n * @param rtPartialInlineNode - A partial rich text node.\n *\n * @returns Equivalent {@link RTPartialInlineNode}.\n */\nexport const serializeSpan = (\n\tnode: Element,\n\trtPartialInlineNode:\n\t\t| RTPartialInlineNode\n\t\t| Omit<RTLinkNode, \"start\" | \"end\" | \"data\">,\n): RTPartialInlineNode => {\n\tif (\n\t\trtPartialInlineNode.type === \"hyperlink\" &&\n\t\t!(\"data\" in rtPartialInlineNode)\n\t) {\n\t\tconst url = node.properties?.href as string | undefined\n\t\tif (!url) {\n\t\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\t\"Element of type `hyperlink` is missing an `href` attribute\",\n\t\t\t)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"hyperlink\",\n\t\t\tdata: {\n\t\t\t\tlink_type: LinkType.Web,\n\t\t\t\turl,\n\t\t\t\ttarget: node.properties?.target as string | undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn rtPartialInlineNode\n}\n"],"names":[],"mappings":";;;;AAsBa,MAAA,iBAAiB,CAAC,SAA8B;;AACtD,QAAA,OAAM,UAAK,eAAL,mBAAiB;AAE7B,MAAI,CAAC,KAAK;AACH,UAAA,IAAI,+BACT,qDAAqD;AAAA,EAEvD;AAEA,QAAM,MAAM,IAAI,IAAI,KAAK,kBAAkB;AAEvC,MAAA,SAAQ,UAAK,eAAL,mBAAiB;AACzB,MAAA,UAAS,UAAK,eAAL,mBAAiB;AAC9B,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAI,OAAO;AAGP,MAAA,IAA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ACN,QAAQ,EAAE,GAAG,YAAY,MAAM,WAAW,MAAM,OAAO,OAAQ;AAAA,IAAA;AAAA,SAE1D;AACC,WAAA;AAAA,MACN,MAAM;AAAA,MACN,QAAQ,EAAE,GAAG,YAAY,MAAM,WAAW,KAAM;AAAA,IAAA;AAAA,EAElD;AACD;AAUa,MAAA,gBAAgB,CAC5B,MACA,wBAGwB;;AACxB,MACC,oBAAoB,SAAS,eAC7B,EAAE,UAAU,sBACX;AACK,UAAA,OAAM,UAAK,eAAL,mBAAiB;AAC7B,QAAI,CAAC,KAAK;AACH,YAAA,IAAI,+BACT,4DAA4D;AAAA,IAE9D;AAEO,WAAA;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,QACL,WAAW,SAAS;AAAA,QACpB;AAAA,QACA,SAAQ,UAAK,eAAL,mBAAiB;AAAA,MACzB;AAAA,IAAA;AAAA,EAEH;AAEO,SAAA;AACR;"}
|
|
@@ -6,7 +6,6 @@ const richText = require("../types/value/richText.cjs");
|
|
|
6
6
|
const PrismicRichTextSerializerError = require("../errors/PrismicRichTextSerializerError.cjs");
|
|
7
7
|
const RichTextFieldBuilder = require("./RichTextFieldBuilder.cjs");
|
|
8
8
|
const hastSerializerHelpers = require("./hastSerializerHelpers.cjs");
|
|
9
|
-
const index = require('./../_node_modules/hast-util-whitespace/lib/index.cjs');
|
|
10
9
|
const DEFAULT_SERIALIZER = {
|
|
11
10
|
h1: "heading1",
|
|
12
11
|
h2: "heading2",
|
|
@@ -149,7 +148,7 @@ const hastToRichText = (tree, file, config) => {
|
|
|
149
148
|
throw error;
|
|
150
149
|
}
|
|
151
150
|
} else if (node.type === "text") {
|
|
152
|
-
if (!
|
|
151
|
+
if (!(node.value.replace(/[ \t\n\f\r]/g, "") === "")) {
|
|
153
152
|
try {
|
|
154
153
|
builder.appendText(node.value);
|
|
155
154
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hastToRichText.cjs","sources":["../../../src/lib/hastToRichText.ts"],"sourcesContent":["import { Element, Root } from \"hast\";\nimport { whitespace } from \"hast-util-whitespace\";\nimport { toString } from \"mdast-util-to-string\";\nimport { visit } from \"unist-util-visit\";\nimport { VFile } from \"vfile\";\n\nimport {\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTLabelNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeType,\n} from \"../types/value/richText\";\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\";\n\nimport {\n\tRichTextHTMLMapSerializer,\n\tRichTextHTMLMapSerializerFunction,\n\tRichTextHTMLMapSerializerShorthand,\n} from \"../helpers/unstable_htmlAsRichText\";\n\nimport { RichTextFieldBuilder } from \"./RichTextFieldBuilder\";\nimport {\n\tserializeEmbed,\n\tserializeImage,\n\tserializeSpan,\n} from \"./hastSerializerHelpers\";\n\n/**\n * Pick keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-pick.d.ts\n */\ntype DistributedPick<\n\tObjectType,\n\tKeyType extends keyof ObjectType,\n> = ObjectType extends unknown ? Pick<ObjectType, KeyType> : never;\n\nconst DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {\n\th1: \"heading1\",\n\th2: \"heading2\",\n\th3: \"heading3\",\n\th4: \"heading4\",\n\th5: \"heading5\",\n\th6: \"heading6\",\n\tp: \"paragraph\",\n\tpre: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tli: ({ context }) =>\n\t\tcontext.listType === \"group-o-list-item\" ? \"o-list-item\" : \"list-item\",\n\tul: \"group-list-item\",\n\tol: \"group-o-list-item\",\n\timg: \"image\",\n\tiframe: \"embed\",\n\ta: \"hyperlink\",\n};\n\nconst VFILE_RULE = \"failed-to-serialize-node\";\nconst VFILE_SOURCE = \"prismic\";\n\n/**\n * Configuration that determines the output of `toRichText`.\n */\nexport type HASTToRichTextConfig = {\n\t/**\n\t * An optional HTML to rich text serializer. Will be merged with the default\n\t * HTML to rich text serializer.\n\t */\n\tserializer?: RichTextHTMLMapSerializer;\n\n\t/**\n\t * Whether or not the text processed should be marked as right-to-left.\n\t *\n\t * @defaultValue `false`\n\t */\n\tdirection?: \"ltr\" | \"rtl\";\n};\n\n/**\n * Transfor a hast tree to a rich text field.\n *\n * @param tree - The hast tree to transform.\n * @param file - The vfile to attach warnings to.\n * @param config - Configuration that determines the output of the function.\n *\n * @returns The rich text field equivalent of the provided hast tree.\n */\nexport const hastToRichText = (\n\ttree: Root | Element,\n\tfile: VFile,\n\tconfig?: HASTToRichTextConfig,\n): RichTextField => {\n\tconst builder = new RichTextFieldBuilder();\n\n\t// Merge the default serializer with the user-provided one.\n\tconst serializer = {\n\t\t...DEFAULT_SERIALIZER,\n\t\t...config?.serializer,\n\t};\n\n\t// Keep track of the last text node type to append text nodes to in\n\t// case of an image or an embed node is present inside a paragraph.\n\tlet lastRTTextNodeType: RTTextNode[\"type\"] = RichTextNodeType.paragraph;\n\n\t// Keep track of the last list type to know whether we need to append\n\t// `list-item` or `o-list-item` nodes.\n\tlet lastListType: \"group-list-item\" | \"group-o-list-item\" | undefined =\n\t\tundefined;\n\n\tvisit(tree, (node) => {\n\t\tif (node.type === \"element\") {\n\t\t\t// Transforms line break elements to line breaks\n\t\t\tif (node.tagName === \"br\") {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(\"\\n\");\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolves the serializer responsible for the current node.\n\t\t\tlet serializerOrShorthand:\n\t\t\t\t| RichTextHTMLMapSerializerShorthand\n\t\t\t\t| RichTextHTMLMapSerializerFunction;\n\n\t\t\t// We give priority to CSS selectors over tag names.\n\t\t\tif (node.matchesSerializer && node.matchesSerializer in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.matchesSerializer];\n\t\t\t} else if (node.tagName in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.tagName];\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet shorthand: RichTextHTMLMapSerializerShorthand;\n\t\t\tif (typeof serializerOrShorthand === \"function\") {\n\t\t\t\tconst shorthandOrNode = serializerOrShorthand({\n\t\t\t\t\tnode,\n\t\t\t\t\tcontext: { listType: lastListType },\n\t\t\t\t});\n\n\t\t\t\tif (!shorthandOrNode) {\n\t\t\t\t\t// Exit on unhandled node.\n\t\t\t\t\treturn;\n\t\t\t\t} else if (\n\t\t\t\t\ttypeof shorthandOrNode === \"object\" &&\n\t\t\t\t\t\"type\" in shorthandOrNode\n\t\t\t\t) {\n\t\t\t\t\t// When the serializer returns a rich text node, we append it and return.\n\t\t\t\t\tswitch (shorthandOrNode.type) {\n\t\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\t\tconst length = toString(node).trimEnd().length;\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length);\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction);\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode);\n\n\t\t\t\t\t\t\treturn;\n\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tlastRTTextNodeType = shorthandOrNode.type;\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode);\n\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Else it's a shorthand.\n\t\t\t\tshorthand = shorthandOrNode;\n\t\t\t} else {\n\t\t\t\tshorthand = serializerOrShorthand;\n\t\t\t}\n\n\t\t\tlet match:\n\t\t\t\t| DistributedPick<\n\t\t\t\t\t\tRTBlockNode | Exclude<RTInlineNode, RTLabelNode>,\n\t\t\t\t\t\t\"type\"\n\t\t\t\t >\n\t\t\t\t| { type: \"label\"; data: { label: string } };\n\t\t\tif (typeof shorthand === \"string\") {\n\t\t\t\tmatch = { type: shorthand };\n\t\t\t} else {\n\t\t\t\tmatch = { type: RichTextNodeType.label, data: shorthand };\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tswitch (match.type) {\n\t\t\t\t\tcase RichTextNodeType.heading1:\n\t\t\t\t\tcase RichTextNodeType.heading2:\n\t\t\t\t\tcase RichTextNodeType.heading3:\n\t\t\t\t\tcase RichTextNodeType.heading4:\n\t\t\t\t\tcase RichTextNodeType.heading5:\n\t\t\t\t\tcase RichTextNodeType.heading6:\n\t\t\t\t\tcase RichTextNodeType.paragraph:\n\t\t\t\t\tcase RichTextNodeType.preformatted:\n\t\t\t\t\tcase RichTextNodeType.listItem:\n\t\t\t\t\tcase RichTextNodeType.oListItem:\n\t\t\t\t\t\tlastRTTextNodeType = match.type;\n\t\t\t\t\t\tbuilder.appendTextNode(match.type, config?.direction);\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.list:\n\t\t\t\t\tcase RichTextNodeType.oList:\n\t\t\t\t\t\tlastListType = match.type;\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tbuilder.appendNode(serializeImage(node));\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\tbuilder.appendNode(serializeEmbed(node));\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\tconst span = serializeSpan(node, match);\n\t\t\t\t\t\tconst length = toString(node).trimEnd().length;\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction);\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Unknown rich text node type: \\`${\n\t\t\t\t\t\t\t\t(match as { type: string }).type\n\t\t\t\t\t\t\t}\\``,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof PrismicRichTextSerializerError) {\n\t\t\t\t\tfile.message(error.message, {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tplace: node.position,\n\t\t\t\t\t\truleId: VFILE_RULE,\n\t\t\t\t\t\tsource: VFILE_SOURCE,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} else if (node.type === \"text\") {\n\t\t\tif (!whitespace(node)) {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(node.value);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode. The last RT\n\t\t\t\t\t// node type is then an image/embed node, so we need to resume a new RT text node.\n\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction);\n\t\t\t\t\tbuilder.appendText(node.value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We ignore the following node types:\n\t\t// root, doctype, comment, raw\n\t});\n\n\treturn builder.build();\n};\n"],"names":["RichTextFieldBuilder","RichTextNodeType","visit","toString","serializeImage","serializeEmbed","serializeSpan","PrismicRichTextSerializerError","whitespace"],"mappings":";;;;;;;;;AA0CA,MAAM,qBAAgD;AAAA,EACrD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,GAAG;AAAA,EACH,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,IAAI,CAAC,EAAE,cACN,QAAQ,aAAa,sBAAsB,gBAAgB;AAAA,EAC5D,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,GAAG;;AAGJ,MAAM,aAAa;AACnB,MAAM,eAAe;AA6Bd,MAAM,iBAAiB,CAC7B,MACA,MACA,WACkB;AACZ,QAAA,UAAU,IAAIA,qBAAAA;AAGpB,QAAM,aAAa;AAAA,IAClB,GAAG;AAAA,IACH,GAAG,iCAAQ;AAAA,EAAA;AAKZ,MAAI,qBAAyCC,SAAiB,iBAAA;AAI9D,MAAI,eACH;AAEKC,uBAAA,MAAM,CAAC,SAAQ;AAChB,QAAA,KAAK,SAAS,WAAW;AAExB,UAAA,KAAK,YAAY,MAAM;AACtB,YAAA;AACH,kBAAQ,WAAW,IAAI;AAAA,iBACf,OAAO;AAAA,QAEhB;AAAA,MACD;AAGI,UAAA;AAKJ,UAAI,KAAK,qBAAqB,KAAK,qBAAqB,YAAY;AAC3C,gCAAA,WAAW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AQ;AAAA,UAAA,CACR;AAED;AAAA,QACD;AAEM,cAAA;AAAA,MACP;AAAA,IAAA,WACU,KAAK,SAAS,QAAQ;AAC5B,UAAA,CAACC,MAAAA,WAAW,IAAI,GAAG;AAClB,YAAA;AACK,kBAAA,WAAW,KAAK,KAAK;AAAA,iBACrB,OAAO;AAGP,kBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,kBAAA,WAAW,KAAK,KAAK;AAAA,QAC9B;AAAA,MACD;AAAA,IACD;AAAA,EAAA,CAIA;AAED,SAAO,QAAQ;AAChB;;"}
|
|
1
|
+
{"version":3,"file":"hastToRichText.cjs","sources":["../../../src/lib/hastToRichText.ts"],"sourcesContent":["import type { Element, Root } from \"hast\"\nimport { toString } from \"mdast-util-to-string\"\nimport { visit } from \"unist-util-visit\"\nimport type { VFile } from \"vfile\"\n\nimport type {\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTLabelNode,\n\tRTTextNode,\n\tRichTextField,\n} from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\"\n\nimport type {\n\tRichTextHTMLMapSerializer,\n\tRichTextHTMLMapSerializerFunction,\n\tRichTextHTMLMapSerializerShorthand,\n} from \"../helpers/unstable_htmlAsRichText\"\n\nimport { RichTextFieldBuilder } from \"./RichTextFieldBuilder\"\nimport {\n\tserializeEmbed,\n\tserializeImage,\n\tserializeSpan,\n} from \"./hastSerializerHelpers\"\n\n/**\n * Pick keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-pick.d.ts\n */\ntype DistributedPick<\n\tObjectType,\n\tKeyType extends keyof ObjectType,\n> = ObjectType extends unknown ? Pick<ObjectType, KeyType> : never\n\nconst DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {\n\th1: \"heading1\",\n\th2: \"heading2\",\n\th3: \"heading3\",\n\th4: \"heading4\",\n\th5: \"heading5\",\n\th6: \"heading6\",\n\tp: \"paragraph\",\n\tpre: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tli: ({ context }) =>\n\t\tcontext.listType === \"group-o-list-item\" ? \"o-list-item\" : \"list-item\",\n\tul: \"group-list-item\",\n\tol: \"group-o-list-item\",\n\timg: \"image\",\n\tiframe: \"embed\",\n\ta: \"hyperlink\",\n}\n\nconst VFILE_RULE = \"failed-to-serialize-node\"\nconst VFILE_SOURCE = \"prismic\"\n\n/**\n * Configuration that determines the output of `toRichText`.\n */\nexport type HASTToRichTextConfig = {\n\t/**\n\t * An optional HTML to rich text serializer. Will be merged with the default\n\t * HTML to rich text serializer.\n\t */\n\tserializer?: RichTextHTMLMapSerializer\n\n\t/**\n\t * Whether or not the text processed should be marked as right-to-left.\n\t *\n\t * @defaultValue `false`\n\t */\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Transfor a hast tree to a rich text field.\n *\n * @param tree - The hast tree to transform.\n * @param file - The vfile to attach warnings to.\n * @param config - Configuration that determines the output of the function.\n *\n * @returns The rich text field equivalent of the provided hast tree.\n */\nexport const hastToRichText = (\n\ttree: Root | Element,\n\tfile: VFile,\n\tconfig?: HASTToRichTextConfig,\n): RichTextField => {\n\tconst builder = new RichTextFieldBuilder()\n\n\t// Merge the default serializer with the user-provided one.\n\tconst serializer = {\n\t\t...DEFAULT_SERIALIZER,\n\t\t...config?.serializer,\n\t}\n\n\t// Keep track of the last text node type to append text nodes to in\n\t// case of an image or an embed node is present inside a paragraph.\n\tlet lastRTTextNodeType: RTTextNode[\"type\"] = RichTextNodeType.paragraph\n\n\t// Keep track of the last list type to know whether we need to append\n\t// `list-item` or `o-list-item` nodes.\n\tlet lastListType: \"group-list-item\" | \"group-o-list-item\" | undefined =\n\t\tundefined\n\n\tvisit(tree, (node) => {\n\t\tif (node.type === \"element\") {\n\t\t\t// Transforms line break elements to line breaks\n\t\t\tif (node.tagName === \"br\") {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(\"\\n\")\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolves the serializer responsible for the current node.\n\t\t\tlet serializerOrShorthand:\n\t\t\t\t| RichTextHTMLMapSerializerShorthand\n\t\t\t\t| RichTextHTMLMapSerializerFunction\n\n\t\t\t// We give priority to CSS selectors over tag names.\n\t\t\tif (node.matchesSerializer && node.matchesSerializer in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.matchesSerializer]\n\t\t\t} else if (node.tagName in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.tagName]\n\t\t\t} else {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tlet shorthand: RichTextHTMLMapSerializerShorthand\n\t\t\tif (typeof serializerOrShorthand === \"function\") {\n\t\t\t\tconst shorthandOrNode = serializerOrShorthand({\n\t\t\t\t\tnode,\n\t\t\t\t\tcontext: { listType: lastListType },\n\t\t\t\t})\n\n\t\t\t\tif (!shorthandOrNode) {\n\t\t\t\t\t// Exit on unhandled node.\n\t\t\t\t\treturn\n\t\t\t\t} else if (\n\t\t\t\t\ttypeof shorthandOrNode === \"object\" &&\n\t\t\t\t\t\"type\" in shorthandOrNode\n\t\t\t\t) {\n\t\t\t\t\t// When the serializer returns a rich text node, we append it and return.\n\t\t\t\t\tswitch (shorthandOrNode.type) {\n\t\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\t\tconst length = toString(node).trimEnd().length\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length)\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction)\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode)\n\n\t\t\t\t\t\t\treturn\n\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tlastRTTextNodeType = shorthandOrNode.type\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode)\n\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Else it's a shorthand.\n\t\t\t\tshorthand = shorthandOrNode\n\t\t\t} else {\n\t\t\t\tshorthand = serializerOrShorthand\n\t\t\t}\n\n\t\t\tlet match:\n\t\t\t\t| DistributedPick<\n\t\t\t\t\t\tRTBlockNode | Exclude<RTInlineNode, RTLabelNode>,\n\t\t\t\t\t\t\"type\"\n\t\t\t\t >\n\t\t\t\t| { type: \"label\"; data: { label: string } }\n\t\t\tif (typeof shorthand === \"string\") {\n\t\t\t\tmatch = { type: shorthand }\n\t\t\t} else {\n\t\t\t\tmatch = { type: RichTextNodeType.label, data: shorthand }\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tswitch (match.type) {\n\t\t\t\t\tcase RichTextNodeType.heading1:\n\t\t\t\t\tcase RichTextNodeType.heading2:\n\t\t\t\t\tcase RichTextNodeType.heading3:\n\t\t\t\t\tcase RichTextNodeType.heading4:\n\t\t\t\t\tcase RichTextNodeType.heading5:\n\t\t\t\t\tcase RichTextNodeType.heading6:\n\t\t\t\t\tcase RichTextNodeType.paragraph:\n\t\t\t\t\tcase RichTextNodeType.preformatted:\n\t\t\t\t\tcase RichTextNodeType.listItem:\n\t\t\t\t\tcase RichTextNodeType.oListItem:\n\t\t\t\t\t\tlastRTTextNodeType = match.type\n\t\t\t\t\t\tbuilder.appendTextNode(match.type, config?.direction)\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.list:\n\t\t\t\t\tcase RichTextNodeType.oList:\n\t\t\t\t\t\tlastListType = match.type\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tbuilder.appendNode(serializeImage(node))\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\tbuilder.appendNode(serializeEmbed(node))\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\tconst span = serializeSpan(node, match)\n\t\t\t\t\t\tconst length = toString(node).trimEnd().length\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length)\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction)\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Unknown rich text node type: \\`${\n\t\t\t\t\t\t\t\t(match as { type: string }).type\n\t\t\t\t\t\t\t}\\``,\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof PrismicRichTextSerializerError) {\n\t\t\t\t\tfile.message(error.message, {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tplace: node.position,\n\t\t\t\t\t\truleId: VFILE_RULE,\n\t\t\t\t\t\tsource: VFILE_SOURCE,\n\t\t\t\t\t})\n\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tthrow error\n\t\t\t}\n\t\t} else if (node.type === \"text\") {\n\t\t\t// Inspired from `hast-util-whitespace`, see:\n\t\t\t// https://github.com/syntax-tree/hast-util-whitespace/blob/main/lib/index.js\n\t\t\tif (!(node.value.replace(/[ \\t\\n\\f\\r]/g, \"\") === \"\")) {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(node.value)\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode. The last RT\n\t\t\t\t\t// node type is then an image/embed node, so we need to resume a new RT text node.\n\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction)\n\t\t\t\t\tbuilder.appendText(node.value)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We ignore the following node types:\n\t\t// root, doctype, comment, raw\n\t})\n\n\treturn builder.build()\n}\n"],"names":["RichTextFieldBuilder","RichTextNodeType","visit","toString","serializeImage","serializeEmbed","serializeSpan","PrismicRichTextSerializerError"],"mappings":";;;;;;;;AAyCA,MAAM,qBAAgD;AAAA,EACrD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,GAAG;AAAA,EACH,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,IAAI,CAAC,EAAE,cACN,QAAQ,aAAa,sBAAsB,gBAAgB;AAAA,EAC5D,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,GAAG;;AAGJ,MAAM,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OAAOK,sBAAAA,cAAc,MAAM,KAAK;AACtC,kBAAM,SAASH,kBAAAA,SAAS,IAAI,EAAE,UAAU;AAEpC,gBAAA;AACK,sBAAA,WAAW,MAAM,MAAM;AAAA,qBACvB,OAAO;AAIP,sBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,sBAAA,WAAW,MAAM,MAAM;AAAA,YAChC;AACA;AAAA,UACD;AAAA,UAEA;AACC,kBAAM,IAAI,MACT,kCACE,MAA2B,IAC7B,IAAI;AAAA,QAEP;AAAA,eACQ,OAAO;AACf,YAAI,iBAAiBI,+BAAAA,gCAAgC;AAC/C,eAAA,QAAQ,MAAM,SAAS;AAAA,YAC3B,OAAO;AAAA,YACP,OAAO,KAAK;AAAA,YACZ,QAAQ;AAAA,YACR,QAAQ;AAAA,UAAA,CACR;AAED;AAAA,QACD;AAEM,cAAA;AAAA,MACP;AAAA,IAAA,WACU,KAAK,SAAS,QAAQ;AAGhC,UAAI,EAAE,KAAK,MAAM,QAAQ,gBAAgB,EAAE,MAAM,KAAK;AACjD,YAAA;AACK,kBAAA,WAAW,KAAK,KAAK;AAAA,iBACrB,OAAO;AAGP,kBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,kBAAA,WAAW,KAAK,KAAK;AAAA,QAC9B;AAAA,MACD;AAAA,IACD;AAAA,EAAA,CAIA;AAED,SAAO,QAAQ;AAChB;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Element, Root } from "hast";
|
|
2
|
-
import { VFile } from "vfile";
|
|
3
|
-
import { RichTextField } from "../types/value/richText";
|
|
4
|
-
import { RichTextHTMLMapSerializer } from "../helpers/unstable_htmlAsRichText";
|
|
1
|
+
import type { Element, Root } from "hast";
|
|
2
|
+
import type { VFile } from "vfile";
|
|
3
|
+
import type { RichTextField } from "../types/value/richText";
|
|
4
|
+
import type { RichTextHTMLMapSerializer } from "../helpers/unstable_htmlAsRichText";
|
|
5
5
|
/**
|
|
6
6
|
* Configuration that determines the output of `toRichText`.
|
|
7
7
|
*/
|
|
@@ -4,7 +4,6 @@ import { RichTextNodeType } from "../types/value/richText.js";
|
|
|
4
4
|
import { PrismicRichTextSerializerError } from "../errors/PrismicRichTextSerializerError.js";
|
|
5
5
|
import { RichTextFieldBuilder } from "./RichTextFieldBuilder.js";
|
|
6
6
|
import { serializeSpan, serializeEmbed, serializeImage } from "./hastSerializerHelpers.js";
|
|
7
|
-
import { whitespace } from './../_node_modules/hast-util-whitespace/lib/index.js';
|
|
8
7
|
const DEFAULT_SERIALIZER = {
|
|
9
8
|
h1: "heading1",
|
|
10
9
|
h2: "heading2",
|
|
@@ -147,7 +146,7 @@ const hastToRichText = (tree, file, config) => {
|
|
|
147
146
|
throw error;
|
|
148
147
|
}
|
|
149
148
|
} else if (node.type === "text") {
|
|
150
|
-
if (!
|
|
149
|
+
if (!(node.value.replace(/[ \t\n\f\r]/g, "") === "")) {
|
|
151
150
|
try {
|
|
152
151
|
builder.appendText(node.value);
|
|
153
152
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hastToRichText.js","sources":["../../../src/lib/hastToRichText.ts"],"sourcesContent":["import { Element, Root } from \"hast\";\nimport { whitespace } from \"hast-util-whitespace\";\nimport { toString } from \"mdast-util-to-string\";\nimport { visit } from \"unist-util-visit\";\nimport { VFile } from \"vfile\";\n\nimport {\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTLabelNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeType,\n} from \"../types/value/richText\";\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\";\n\nimport {\n\tRichTextHTMLMapSerializer,\n\tRichTextHTMLMapSerializerFunction,\n\tRichTextHTMLMapSerializerShorthand,\n} from \"../helpers/unstable_htmlAsRichText\";\n\nimport { RichTextFieldBuilder } from \"./RichTextFieldBuilder\";\nimport {\n\tserializeEmbed,\n\tserializeImage,\n\tserializeSpan,\n} from \"./hastSerializerHelpers\";\n\n/**\n * Pick keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-pick.d.ts\n */\ntype DistributedPick<\n\tObjectType,\n\tKeyType extends keyof ObjectType,\n> = ObjectType extends unknown ? Pick<ObjectType, KeyType> : never;\n\nconst DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {\n\th1: \"heading1\",\n\th2: \"heading2\",\n\th3: \"heading3\",\n\th4: \"heading4\",\n\th5: \"heading5\",\n\th6: \"heading6\",\n\tp: \"paragraph\",\n\tpre: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tli: ({ context }) =>\n\t\tcontext.listType === \"group-o-list-item\" ? \"o-list-item\" : \"list-item\",\n\tul: \"group-list-item\",\n\tol: \"group-o-list-item\",\n\timg: \"image\",\n\tiframe: \"embed\",\n\ta: \"hyperlink\",\n};\n\nconst VFILE_RULE = \"failed-to-serialize-node\";\nconst VFILE_SOURCE = \"prismic\";\n\n/**\n * Configuration that determines the output of `toRichText`.\n */\nexport type HASTToRichTextConfig = {\n\t/**\n\t * An optional HTML to rich text serializer. Will be merged with the default\n\t * HTML to rich text serializer.\n\t */\n\tserializer?: RichTextHTMLMapSerializer;\n\n\t/**\n\t * Whether or not the text processed should be marked as right-to-left.\n\t *\n\t * @defaultValue `false`\n\t */\n\tdirection?: \"ltr\" | \"rtl\";\n};\n\n/**\n * Transfor a hast tree to a rich text field.\n *\n * @param tree - The hast tree to transform.\n * @param file - The vfile to attach warnings to.\n * @param config - Configuration that determines the output of the function.\n *\n * @returns The rich text field equivalent of the provided hast tree.\n */\nexport const hastToRichText = (\n\ttree: Root | Element,\n\tfile: VFile,\n\tconfig?: HASTToRichTextConfig,\n): RichTextField => {\n\tconst builder = new RichTextFieldBuilder();\n\n\t// Merge the default serializer with the user-provided one.\n\tconst serializer = {\n\t\t...DEFAULT_SERIALIZER,\n\t\t...config?.serializer,\n\t};\n\n\t// Keep track of the last text node type to append text nodes to in\n\t// case of an image or an embed node is present inside a paragraph.\n\tlet lastRTTextNodeType: RTTextNode[\"type\"] = RichTextNodeType.paragraph;\n\n\t// Keep track of the last list type to know whether we need to append\n\t// `list-item` or `o-list-item` nodes.\n\tlet lastListType: \"group-list-item\" | \"group-o-list-item\" | undefined =\n\t\tundefined;\n\n\tvisit(tree, (node) => {\n\t\tif (node.type === \"element\") {\n\t\t\t// Transforms line break elements to line breaks\n\t\t\tif (node.tagName === \"br\") {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(\"\\n\");\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolves the serializer responsible for the current node.\n\t\t\tlet serializerOrShorthand:\n\t\t\t\t| RichTextHTMLMapSerializerShorthand\n\t\t\t\t| RichTextHTMLMapSerializerFunction;\n\n\t\t\t// We give priority to CSS selectors over tag names.\n\t\t\tif (node.matchesSerializer && node.matchesSerializer in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.matchesSerializer];\n\t\t\t} else if (node.tagName in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.tagName];\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet shorthand: RichTextHTMLMapSerializerShorthand;\n\t\t\tif (typeof serializerOrShorthand === \"function\") {\n\t\t\t\tconst shorthandOrNode = serializerOrShorthand({\n\t\t\t\t\tnode,\n\t\t\t\t\tcontext: { listType: lastListType },\n\t\t\t\t});\n\n\t\t\t\tif (!shorthandOrNode) {\n\t\t\t\t\t// Exit on unhandled node.\n\t\t\t\t\treturn;\n\t\t\t\t} else if (\n\t\t\t\t\ttypeof shorthandOrNode === \"object\" &&\n\t\t\t\t\t\"type\" in shorthandOrNode\n\t\t\t\t) {\n\t\t\t\t\t// When the serializer returns a rich text node, we append it and return.\n\t\t\t\t\tswitch (shorthandOrNode.type) {\n\t\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\t\tconst length = toString(node).trimEnd().length;\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length);\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction);\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode);\n\n\t\t\t\t\t\t\treturn;\n\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tlastRTTextNodeType = shorthandOrNode.type;\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode);\n\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Else it's a shorthand.\n\t\t\t\tshorthand = shorthandOrNode;\n\t\t\t} else {\n\t\t\t\tshorthand = serializerOrShorthand;\n\t\t\t}\n\n\t\t\tlet match:\n\t\t\t\t| DistributedPick<\n\t\t\t\t\t\tRTBlockNode | Exclude<RTInlineNode, RTLabelNode>,\n\t\t\t\t\t\t\"type\"\n\t\t\t\t >\n\t\t\t\t| { type: \"label\"; data: { label: string } };\n\t\t\tif (typeof shorthand === \"string\") {\n\t\t\t\tmatch = { type: shorthand };\n\t\t\t} else {\n\t\t\t\tmatch = { type: RichTextNodeType.label, data: shorthand };\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tswitch (match.type) {\n\t\t\t\t\tcase RichTextNodeType.heading1:\n\t\t\t\t\tcase RichTextNodeType.heading2:\n\t\t\t\t\tcase RichTextNodeType.heading3:\n\t\t\t\t\tcase RichTextNodeType.heading4:\n\t\t\t\t\tcase RichTextNodeType.heading5:\n\t\t\t\t\tcase RichTextNodeType.heading6:\n\t\t\t\t\tcase RichTextNodeType.paragraph:\n\t\t\t\t\tcase RichTextNodeType.preformatted:\n\t\t\t\t\tcase RichTextNodeType.listItem:\n\t\t\t\t\tcase RichTextNodeType.oListItem:\n\t\t\t\t\t\tlastRTTextNodeType = match.type;\n\t\t\t\t\t\tbuilder.appendTextNode(match.type, config?.direction);\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.list:\n\t\t\t\t\tcase RichTextNodeType.oList:\n\t\t\t\t\t\tlastListType = match.type;\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tbuilder.appendNode(serializeImage(node));\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\tbuilder.appendNode(serializeEmbed(node));\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\tconst span = serializeSpan(node, match);\n\t\t\t\t\t\tconst length = toString(node).trimEnd().length;\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction);\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Unknown rich text node type: \\`${\n\t\t\t\t\t\t\t\t(match as { type: string }).type\n\t\t\t\t\t\t\t}\\``,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof PrismicRichTextSerializerError) {\n\t\t\t\t\tfile.message(error.message, {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tplace: node.position,\n\t\t\t\t\t\truleId: VFILE_RULE,\n\t\t\t\t\t\tsource: VFILE_SOURCE,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} else if (node.type === \"text\") {\n\t\t\tif (!whitespace(node)) {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(node.value);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode. The last RT\n\t\t\t\t\t// node type is then an image/embed node, so we need to resume a new RT text node.\n\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction);\n\t\t\t\t\tbuilder.appendText(node.value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We ignore the following node types:\n\t\t// root, doctype, comment, raw\n\t});\n\n\treturn builder.build();\n};\n"],"names":[],"mappings":";;;;;;;AA0CA,MAAM,qBAAgD;AAAA,EACrD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,GAAG;AAAA,EACH,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,IAAI,CAAC,EAAE,cACN,QA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MAAM;AAAA,qBACvB,OAAO;AAIP,sBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,sBAAA,WAAW,MAAM,MAAM;AAAA,YAChC;AACA;AAAA,UACD;AAAA,UAEA;AACC,kBAAM,IAAI,MACT,kCACE,MAA2B,IAC7B,IAAI;AAAA,QAEP;AAAA,eACQ,OAAO;AACf,YAAI,iBAAiB,gCAAgC;AAC/C,eAAA,QAAQ,MAAM,SAAS;AAAA,YAC3B,OAAO;AAAA,YACP,OAAO,KAAK;AAAA,YACZ,QAAQ;AAAA,YACR,QAAQ;AAAA,UAAA,CACR;AAED;AAAA,QACD;AAEM,cAAA;AAAA,MACP;AAAA,IAAA,WACU,KAAK,SAAS,QAAQ;AAC5B,UAAA,CAAC,WAAW,IAAI,GAAG;AAClB,YAAA;AACK,kBAAA,WAAW,KAAK,KAAK;AAAA,iBACrB,OAAO;AAGP,kBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,kBAAA,WAAW,KAAK,KAAK;AAAA,QAC9B;AAAA,MACD;AAAA,IACD;AAAA,EAAA,CAIA;AAED,SAAO,QAAQ;AAChB;"}
|
|
1
|
+
{"version":3,"file":"hastToRichText.js","sources":["../../../src/lib/hastToRichText.ts"],"sourcesContent":["import type { Element, Root } from \"hast\"\nimport { toString } from \"mdast-util-to-string\"\nimport { visit } from \"unist-util-visit\"\nimport type { VFile } from \"vfile\"\n\nimport type {\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTLabelNode,\n\tRTTextNode,\n\tRichTextField,\n} from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\"\n\nimport type {\n\tRichTextHTMLMapSerializer,\n\tRichTextHTMLMapSerializerFunction,\n\tRichTextHTMLMapSerializerShorthand,\n} from \"../helpers/unstable_htmlAsRichText\"\n\nimport { RichTextFieldBuilder } from \"./RichTextFieldBuilder\"\nimport {\n\tserializeEmbed,\n\tserializeImage,\n\tserializeSpan,\n} from \"./hastSerializerHelpers\"\n\n/**\n * Pick keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-pick.d.ts\n */\ntype DistributedPick<\n\tObjectType,\n\tKeyType extends keyof ObjectType,\n> = ObjectType extends unknown ? Pick<ObjectType, KeyType> : never\n\nconst DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {\n\th1: \"heading1\",\n\th2: \"heading2\",\n\th3: \"heading3\",\n\th4: \"heading4\",\n\th5: \"heading5\",\n\th6: \"heading6\",\n\tp: \"paragraph\",\n\tpre: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tli: ({ context }) =>\n\t\tcontext.listType === \"group-o-list-item\" ? \"o-list-item\" : \"list-item\",\n\tul: \"group-list-item\",\n\tol: \"group-o-list-item\",\n\timg: \"image\",\n\tiframe: \"embed\",\n\ta: \"hyperlink\",\n}\n\nconst VFILE_RULE = \"failed-to-serialize-node\"\nconst VFILE_SOURCE = \"prismic\"\n\n/**\n * Configuration that determines the output of `toRichText`.\n */\nexport type HASTToRichTextConfig = {\n\t/**\n\t * An optional HTML to rich text serializer. Will be merged with the default\n\t * HTML to rich text serializer.\n\t */\n\tserializer?: RichTextHTMLMapSerializer\n\n\t/**\n\t * Whether or not the text processed should be marked as right-to-left.\n\t *\n\t * @defaultValue `false`\n\t */\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Transfor a hast tree to a rich text field.\n *\n * @param tree - The hast tree to transform.\n * @param file - The vfile to attach warnings to.\n * @param config - Configuration that determines the output of the function.\n *\n * @returns The rich text field equivalent of the provided hast tree.\n */\nexport const hastToRichText = (\n\ttree: Root | Element,\n\tfile: VFile,\n\tconfig?: HASTToRichTextConfig,\n): RichTextField => {\n\tconst builder = new RichTextFieldBuilder()\n\n\t// Merge the default serializer with the user-provided one.\n\tconst serializer = {\n\t\t...DEFAULT_SERIALIZER,\n\t\t...config?.serializer,\n\t}\n\n\t// Keep track of the last text node type to append text nodes to in\n\t// case of an image or an embed node is present inside a paragraph.\n\tlet lastRTTextNodeType: RTTextNode[\"type\"] = RichTextNodeType.paragraph\n\n\t// Keep track of the last list type to know whether we need to append\n\t// `list-item` or `o-list-item` nodes.\n\tlet lastListType: \"group-list-item\" | \"group-o-list-item\" | undefined =\n\t\tundefined\n\n\tvisit(tree, (node) => {\n\t\tif (node.type === \"element\") {\n\t\t\t// Transforms line break elements to line breaks\n\t\t\tif (node.tagName === \"br\") {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(\"\\n\")\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolves the serializer responsible for the current node.\n\t\t\tlet serializerOrShorthand:\n\t\t\t\t| RichTextHTMLMapSerializerShorthand\n\t\t\t\t| RichTextHTMLMapSerializerFunction\n\n\t\t\t// We give priority to CSS selectors over tag names.\n\t\t\tif (node.matchesSerializer && node.matchesSerializer in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.matchesSerializer]\n\t\t\t} else if (node.tagName in serializer) {\n\t\t\t\tserializerOrShorthand = serializer[node.tagName]\n\t\t\t} else {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tlet shorthand: RichTextHTMLMapSerializerShorthand\n\t\t\tif (typeof serializerOrShorthand === \"function\") {\n\t\t\t\tconst shorthandOrNode = serializerOrShorthand({\n\t\t\t\t\tnode,\n\t\t\t\t\tcontext: { listType: lastListType },\n\t\t\t\t})\n\n\t\t\t\tif (!shorthandOrNode) {\n\t\t\t\t\t// Exit on unhandled node.\n\t\t\t\t\treturn\n\t\t\t\t} else if (\n\t\t\t\t\ttypeof shorthandOrNode === \"object\" &&\n\t\t\t\t\t\"type\" in shorthandOrNode\n\t\t\t\t) {\n\t\t\t\t\t// When the serializer returns a rich text node, we append it and return.\n\t\t\t\t\tswitch (shorthandOrNode.type) {\n\t\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\t\tconst length = toString(node).trimEnd().length\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length)\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction)\n\t\t\t\t\t\t\t\tbuilder.appendSpan(shorthandOrNode, length)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode)\n\n\t\t\t\t\t\t\treturn\n\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tlastRTTextNodeType = shorthandOrNode.type\n\t\t\t\t\t\t\tbuilder.appendNode(shorthandOrNode)\n\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Else it's a shorthand.\n\t\t\t\tshorthand = shorthandOrNode\n\t\t\t} else {\n\t\t\t\tshorthand = serializerOrShorthand\n\t\t\t}\n\n\t\t\tlet match:\n\t\t\t\t| DistributedPick<\n\t\t\t\t\t\tRTBlockNode | Exclude<RTInlineNode, RTLabelNode>,\n\t\t\t\t\t\t\"type\"\n\t\t\t\t >\n\t\t\t\t| { type: \"label\"; data: { label: string } }\n\t\t\tif (typeof shorthand === \"string\") {\n\t\t\t\tmatch = { type: shorthand }\n\t\t\t} else {\n\t\t\t\tmatch = { type: RichTextNodeType.label, data: shorthand }\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tswitch (match.type) {\n\t\t\t\t\tcase RichTextNodeType.heading1:\n\t\t\t\t\tcase RichTextNodeType.heading2:\n\t\t\t\t\tcase RichTextNodeType.heading3:\n\t\t\t\t\tcase RichTextNodeType.heading4:\n\t\t\t\t\tcase RichTextNodeType.heading5:\n\t\t\t\t\tcase RichTextNodeType.heading6:\n\t\t\t\t\tcase RichTextNodeType.paragraph:\n\t\t\t\t\tcase RichTextNodeType.preformatted:\n\t\t\t\t\tcase RichTextNodeType.listItem:\n\t\t\t\t\tcase RichTextNodeType.oListItem:\n\t\t\t\t\t\tlastRTTextNodeType = match.type\n\t\t\t\t\t\tbuilder.appendTextNode(match.type, config?.direction)\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.list:\n\t\t\t\t\tcase RichTextNodeType.oList:\n\t\t\t\t\t\tlastListType = match.type\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.image:\n\t\t\t\t\t\tbuilder.appendNode(serializeImage(node))\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.embed:\n\t\t\t\t\t\tbuilder.appendNode(serializeEmbed(node))\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase RichTextNodeType.strong:\n\t\t\t\t\tcase RichTextNodeType.em:\n\t\t\t\t\tcase RichTextNodeType.label:\n\t\t\t\t\tcase RichTextNodeType.hyperlink: {\n\t\t\t\t\t\tconst span = serializeSpan(node, match)\n\t\t\t\t\t\tconst length = toString(node).trimEnd().length\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length)\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode and that\n\t\t\t\t\t\t\t// the next children is a span. The last RT node type is then an image/embed\n\t\t\t\t\t\t\t// node, so we need to resume a new RT text node.\n\t\t\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction)\n\t\t\t\t\t\t\tbuilder.appendSpan(span, length)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Unknown rich text node type: \\`${\n\t\t\t\t\t\t\t\t(match as { type: string }).type\n\t\t\t\t\t\t\t}\\``,\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof PrismicRichTextSerializerError) {\n\t\t\t\t\tfile.message(error.message, {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tplace: node.position,\n\t\t\t\t\t\truleId: VFILE_RULE,\n\t\t\t\t\t\tsource: VFILE_SOURCE,\n\t\t\t\t\t})\n\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tthrow error\n\t\t\t}\n\t\t} else if (node.type === \"text\") {\n\t\t\t// Inspired from `hast-util-whitespace`, see:\n\t\t\t// https://github.com/syntax-tree/hast-util-whitespace/blob/main/lib/index.js\n\t\t\tif (!(node.value.replace(/[ \\t\\n\\f\\r]/g, \"\") === \"\")) {\n\t\t\t\ttry {\n\t\t\t\t\tbuilder.appendText(node.value)\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Happens when we extract an image/embed node inside an RTTextNode. The last RT\n\t\t\t\t\t// node type is then an image/embed node, so we need to resume a new RT text node.\n\t\t\t\t\tbuilder.appendTextNode(lastRTTextNodeType, config?.direction)\n\t\t\t\t\tbuilder.appendText(node.value)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We ignore the following node types:\n\t\t// root, doctype, comment, raw\n\t})\n\n\treturn builder.build()\n}\n"],"names":[],"mappings":";;;;;;AAyCA,MAAM,qBAAgD;AAAA,EACrD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ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AAiB,WAAW;AAC1B,kBAAA,OAAO,cAAc,MAAM,KAAK;AACtC,kBAAM,SAAS,SAAS,IAAI,EAAE,UAAU;AAEpC,gBAAA;AACK,sBAAA,WAAW,MAAM,MAAM;AAAA,qBACvB,OAAO;AAIP,sBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,sBAAA,WAAW,MAAM,MAAM;AAAA,YAChC;AACA;AAAA,UACD;AAAA,UAEA;AACC,kBAAM,IAAI,MACT,kCACE,MAA2B,IAC7B,IAAI;AAAA,QAEP;AAAA,eACQ,OAAO;AACf,YAAI,iBAAiB,gCAAgC;AAC/C,eAAA,QAAQ,MAAM,SAAS;AAAA,YAC3B,OAAO;AAAA,YACP,OAAO,KAAK;AAAA,YACZ,QAAQ;AAAA,YACR,QAAQ;AAAA,UAAA,CACR;AAED;AAAA,QACD;AAEM,cAAA;AAAA,MACP;AAAA,IAAA,WACU,KAAK,SAAS,QAAQ;AAGhC,UAAI,EAAE,KAAK,MAAM,QAAQ,gBAAgB,EAAE,MAAM,KAAK;AACjD,YAAA;AACK,kBAAA,WAAW,KAAK,KAAK;AAAA,iBACrB,OAAO;AAGP,kBAAA,eAAe,oBAAoB,iCAAQ,SAAS;AACpD,kBAAA,WAAW,KAAK,KAAK;AAAA,QAC9B;AAAA,MACD;AAAA,IACD;AAAA,EAAA,CAIA;AAED,SAAO,QAAQ;AAChB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isInternalURL.cjs","sources":["../../../src/lib/isInternalURL.ts"],"sourcesContent":["/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport const isInternalURL = (url: string): boolean => {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url)
|
|
1
|
+
{"version":3,"file":"isInternalURL.cjs","sources":["../../../src/lib/isInternalURL.ts"],"sourcesContent":["/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport const isInternalURL = (url: string): boolean => {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url)\n\tconst isSpecialLink = !isInternal && !/^https?:\\/\\//.test(url)\n\n\treturn isInternal && !isSpecialLink\n}\n"],"names":[],"mappings":";;AAQa,MAAA,gBAAgB,CAAC,QAAwB;AAC/C,QAAA,aAAa,gBAAgB,KAAK,GAAG;AAC3C,QAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,GAAG;AAE7D,SAAO,cAAc,CAAC;AACvB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isInternalURL.js","sources":["../../../src/lib/isInternalURL.ts"],"sourcesContent":["/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport const isInternalURL = (url: string): boolean => {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url)
|
|
1
|
+
{"version":3,"file":"isInternalURL.js","sources":["../../../src/lib/isInternalURL.ts"],"sourcesContent":["/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport const isInternalURL = (url: string): boolean => {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url)\n\tconst isSpecialLink = !isInternal && !/^https?:\\/\\//.test(url)\n\n\treturn isInternal && !isSpecialLink\n}\n"],"names":[],"mappings":"AAQa,MAAA,gBAAgB,CAAC,QAAwB;AAC/C,QAAA,aAAa,gBAAgB,KAAK,GAAG;AAC3C,QAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,GAAG;AAE7D,SAAO,cAAc,CAAC;AACvB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minifyGraphQLQuery.cjs","sources":["../../../src/lib/minifyGraphQLQuery.ts"],"sourcesContent":["/**\n * Minifies a GraphQL query by removing whitespace where possible.\n *\n * @param query - GraphQL query to minify.\n *\n * @returns A minified version of `query`.\n */\nexport const minifyGraphQLQuery = (query: string): string => {\n\treturn query.replace(\n\t\t/(\\n| )*( |{|})(\\n| )*/gm,\n\t\t(_chars, _spaces, brackets) => brackets,\n\t)
|
|
1
|
+
{"version":3,"file":"minifyGraphQLQuery.cjs","sources":["../../../src/lib/minifyGraphQLQuery.ts"],"sourcesContent":["/**\n * Minifies a GraphQL query by removing whitespace where possible.\n *\n * @param query - GraphQL query to minify.\n *\n * @returns A minified version of `query`.\n */\nexport const minifyGraphQLQuery = (query: string): string => {\n\treturn query.replace(\n\t\t/(\\n| )*( |{|})(\\n| )*/gm,\n\t\t(_chars, _spaces, brackets) => brackets,\n\t)\n}\n"],"names":[],"mappings":";;AAOa,MAAA,qBAAqB,CAAC,UAAyB;AAC3D,SAAO,MAAM,QACZ,2BACA,CAAC,QAAQ,SAAS,aAAa,QAAQ;AAEzC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minifyGraphQLQuery.js","sources":["../../../src/lib/minifyGraphQLQuery.ts"],"sourcesContent":["/**\n * Minifies a GraphQL query by removing whitespace where possible.\n *\n * @param query - GraphQL query to minify.\n *\n * @returns A minified version of `query`.\n */\nexport const minifyGraphQLQuery = (query: string): string => {\n\treturn query.replace(\n\t\t/(\\n| )*( |{|})(\\n| )*/gm,\n\t\t(_chars, _spaces, brackets) => brackets,\n\t)
|
|
1
|
+
{"version":3,"file":"minifyGraphQLQuery.js","sources":["../../../src/lib/minifyGraphQLQuery.ts"],"sourcesContent":["/**\n * Minifies a GraphQL query by removing whitespace where possible.\n *\n * @param query - GraphQL query to minify.\n *\n * @returns A minified version of `query`.\n */\nexport const minifyGraphQLQuery = (query: string): string => {\n\treturn query.replace(\n\t\t/(\\n| )*( |{|})(\\n| )*/gm,\n\t\t(_chars, _spaces, brackets) => brackets,\n\t)\n}\n"],"names":[],"mappings":"AAOa,MAAA,qBAAqB,CAAC,UAAyB;AAC3D,SAAO,MAAM,QACZ,2BACA,CAAC,QAAQ,SAAS,aAAa,QAAQ;AAEzC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehypeRichText.cjs","sources":["../../../src/lib/rehypeRichText.ts"],"sourcesContent":["import { Element, Root } from \"hast\"
|
|
1
|
+
{"version":3,"file":"rehypeRichText.cjs","sources":["../../../src/lib/rehypeRichText.ts"],"sourcesContent":["import type { Element, Root } from \"hast\"\nimport { select, selectAll } from \"hast-util-select\"\nimport rehypeMinifyWhitespace from \"rehype-minify-whitespace\"\nimport type { Plugin, Processor } from \"unified\"\nimport { remove } from \"unist-util-remove\"\nimport { SKIP, visit } from \"unist-util-visit\"\nimport type { VFile } from \"vfile\"\n\nimport type { CustomTypeModelRichTextField } from \"../types/model/richText\"\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport { filterRichTextField } from \"./filterRichTextField\"\nimport type { HASTToRichTextConfig } from \"./hastToRichText\"\nimport { hastToRichText } from \"./hastToRichText\"\n\n/**\n * Configuration options for {@link rehypeRichText}.\n */\nexport type RehypeRichTextConfig = {\n\t/**\n\t * A CSS selector that targets the section of the document to convert to rich\n\t * text.\n\t *\n\t * @example `div.post`\n\t *\n\t * @defaultValue `\":root\"` - The top-level element of the document.\n\t */\n\tcontainer?: string\n\n\t/**\n\t * A list of CSS selectors to exclude matching nodes from the document to\n\t * process.\n\t *\n\t * @example `[\".hidden\", \"aside\"]`\n\t *\n\t * @defaultValue `[]` - No nodes are excluded.\n\t */\n\texclude?: string[]\n\n\t/**\n\t * A list of CSS selectors to include only matching nodes from the document to\n\t * process.\n\t *\n\t * @example `[\"p\", \"img\"]`\n\t *\n\t * @defaultValue `[]` - All nodes are included.\n\t */\n\tinclude?: string[]\n\n\t/**\n\t * A rich text or title field model definition. When provided the serializer\n\t * will filter out any node types not allowed by the model.\n\t *\n\t * @defaultValue `undefined` - No filtering is applied.\n\t */\n\tmodel?: CustomTypeModelRichTextField\n} & HASTToRichTextConfig\n\n/**\n * A unified plugin that compiles a hast tree to a Prismic rich text field.\n *\n * @param config - Configuration options for the rehype rich text processor.\n */\n// unified requires the function to be typed directly with the\n// `Plugin` type to properly infer return types on processors.\nexport const rehypeRichText: Plugin<\n\t[config?: RehypeRichTextConfig],\n\tRoot,\n\tRichTextField\n> = function rehypeRichText(config) {\n\t// This is a bit dirty, but it seems like that's how rehype intends\n\t// it to be due to JSDocs limitations(?), see:\n\t// https://github.com/rehypejs/rehype/blob/f6912ac680704f1ef4b558ac57cbf0dd62ed0892/packages/rehype-stringify/lib/index.js#L18-L20\n\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\tconst self = this as unknown as Processor<\n\t\tundefined,\n\t\tundefined,\n\t\tundefined,\n\t\tRoot,\n\t\tRichTextField\n\t>\n\n\t// We need to exclude nodes _before_ we minify the tree as excluding\n\t// nodes could end up in more whitespaces to trim.\n\tself.use(() => {\n\t\treturn (tree: Root) => {\n\t\t\t// Extract container node if any is specified.\n\t\t\tif (config?.container) {\n\t\t\t\tconst element = select(config.container, tree)\n\n\t\t\t\tif (!element) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No container matching \\`${config?.container}\\` could be found in the input AST.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\t// We cannot reassign the tree itself, so we instead replace\n\t\t\t\t// its children with the found element.\n\t\t\t\ttree.children = [element]\n\t\t\t}\n\n\t\t\t// Remove excluded nodes if any are specified\n\t\t\tif (config?.exclude) {\n\t\t\t\t// We join selector to only run one query\n\t\t\t\tconst nodesToExclude = selectAll(config.exclude.join(\", \"), tree)\n\n\t\t\t\tremove(tree, (node) => nodesToExclude.includes(node as Element))\n\t\t\t}\n\n\t\t\t// Include only nodes to include\n\t\t\tif (config?.include) {\n\t\t\t\tconst nodesToInclude: Element[] = []\n\n\t\t\t\t// We join selector to only run one query\n\t\t\t\tconst selector = config.include.join(\", \")\n\t\t\t\tconst rawNodesToInclude = selectAll(selector, tree)\n\n\t\t\t\t// We walk the tree to exclude matching nodes that are children of other matching nodes.\n\t\t\t\tvisit(tree, (node) => {\n\t\t\t\t\tif (rawNodesToInclude.includes(node as Element)) {\n\t\t\t\t\t\tnodesToInclude.push(node as Element)\n\n\t\t\t\t\t\t// Stop traversing this part of the tree since we found its matching parent node.\n\t\t\t\t\t\treturn SKIP\n\t\t\t\t\t}\n\t\t\t\t})\n\n\t\t\t\t// We cannot reassign the tree itself, so we instead replace\n\t\t\t\t// its children with the found element.\n\t\t\t\ttree.children = nodesToInclude\n\t\t\t}\n\n\t\t\t// Mark nodes matching CSS selectors\n\t\t\tif (config?.serializer) {\n\t\t\t\tfor (const key in config.serializer) {\n\t\t\t\t\t// HTML tag names are single word, lowercase strings, a-z and 1-6 (headings).\n\t\t\t\t\t// Here we want to match anything that's not a valid HTML tag name and treat\n\t\t\t\t\t// it as a CSS selector. See: https://regex101.com/r/LILLWH/1\n\t\t\t\t\tif (!/^[a-z]+[1-6]?$/.test(key)) {\n\t\t\t\t\t\tconst matches = selectAll(key, tree)\n\n\t\t\t\t\t\tfor (let i = 0; i < matches.length; i++) {\n\t\t\t\t\t\t\tmatches[i].matchesSerializer = key\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}\n\t})\n\n\t// `rehypeRichText` _depends_ on `rehypeMinifyWhitespace`, that's why it's\n\t// registered within the plugin rather than on the processor directly.\n\tself.use(rehypeMinifyWhitespace)\n\n\tself.compiler = compiler\n\n\tfunction compiler(tree: Root, file: VFile): RichTextField {\n\t\tconst richTextField = hastToRichText(tree, file, config)\n\n\t\tif (config?.model) {\n\t\t\treturn filterRichTextField(richTextField, config.model)\n\t\t}\n\n\t\treturn richTextField\n\t}\n}\n\ndeclare module \"unified\" {\n\t// Register unified processor the result type.\n\tinterface CompileResultMap {\n\t\tRichTextField: RichTextField\n\t}\n}\n\ndeclare module \"hast\" {\n\t// Extend hast node with a rich text value.\n\tinterface Element {\n\t\t/**\n\t\t * A serializer this node matches to. Nodes are marked with this property\n\t\t * when they match a CSS selector from the serializer map.\n\t\t */\n\t\tmatchesSerializer?: string\n\t}\n}\n"],"names":["rehypeRichText","select","selectAll","remove","visit","SKIP","hastToRichText","filterRichTextField"],"mappings":";;;;;;;;AAiEa,MAAA,iBAIT,SAASA,gBAAe,QAAM;AAKjC,QAAM,OAAO;AAUb,OAAK,IAAI,MAAK;AACb,WAAO,CAAC,SAAc;AAErB,UAAI,iCAAQ,WAAW;AACtB,cAAM,UAAUC,eAAA,OAAO,OAAO,WAAW,IAAI;AAE7C,YAAI,CAAC,SAAS;AACb,gBAAM,IAAI,MACT,2BAA2B,iCAAQ,SAAS,qCAAqC;AAAA,QAEnF;AAIK,aAAA,WAAW,CAAC,OAAO;AAAA,MACzB;AAGA,UAAI,iCAAQ,SAAS;AAEpB,cAAM,iBAAiBC,eAAU,UAAA,OAAO,QAAQ,KAAK,IAAI,GAAG,IAAI;AAEhEC,wBAAA,OAAO,MAAM,CAAC,SAAS,eAAe,SAAS,IAAe,CAAC;AAAA,MAChE;AAGA,UAAI,iCAAQ,SAAS;AACpB,cAAM,iBAA4B,CAAA;AAGlC,cAAM,WAAW,OAAO,QAAQ,KAAK,IAAI;AACnC,cAAA,oBAAoBD,eAAAA,UAAU,UAAU,IAAI;AAG5CE,6BAAA,MAAM,CAAC,SAAQ;AAChB,cAAA,kBAAkB,SAAS,IAAe,GAAG;AAChD,2BAAe,KAAK,IAAe;AAG5B,mBAAAC;UACR;AAAA,QAAA,CACA;AAID,aAAK,WAAW;AAAA,MACjB;AAGA,UAAI,iCAAQ,YAAY;AACZ,mBAAA,OAAO,OAAO,YAAY;AAIpC,cAAI,CAAC,iBAAiB,KAAK,GAAG,GAAG;AAC1B,kBAAA,UAAUH,eAAAA,UAAU,KAAK,IAAI;AAEnC,qBAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AAChC,sBAAA,CAAC,EAAE,oBAAoB;AAAA,YAChC;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IAAA;AAAA,EACD,CACA;AAID,OAAK,IAAI,sBAAsB;AAE/B,OAAK,WAAW;AAEP,WAAA,SAAS,MAAY,MAAW;AACxC,UAAM,gBAAgBI,eAAA,eAAe,MAAM,MAAM,MAAM;AAEvD,QAAI,iCAAQ,OAAO;AACX,aAAAC,wCAAoB,eAAe,OAAO,KAAK;AAAA,IACvD;AAEO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Root } from "hast";
|
|
2
|
-
import { Plugin } from "unified";
|
|
3
|
-
import { CustomTypeModelRichTextField } from "../types/model/richText";
|
|
4
|
-
import { RichTextField } from "../types/value/richText";
|
|
5
|
-
import { HASTToRichTextConfig } from "./hastToRichText";
|
|
1
|
+
import type { Root } from "hast";
|
|
2
|
+
import type { Plugin } from "unified";
|
|
3
|
+
import type { CustomTypeModelRichTextField } from "../types/model/richText";
|
|
4
|
+
import type { RichTextField } from "../types/value/richText";
|
|
5
|
+
import type { HASTToRichTextConfig } from "./hastToRichText";
|
|
6
6
|
/**
|
|
7
7
|
* Configuration options for {@link rehypeRichText}.
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehypeRichText.js","sources":["../../../src/lib/rehypeRichText.ts"],"sourcesContent":["import { Element, Root } from \"hast\"
|
|
1
|
+
{"version":3,"file":"rehypeRichText.js","sources":["../../../src/lib/rehypeRichText.ts"],"sourcesContent":["import type { Element, Root } from \"hast\"\nimport { select, selectAll } from \"hast-util-select\"\nimport rehypeMinifyWhitespace from \"rehype-minify-whitespace\"\nimport type { Plugin, Processor } from \"unified\"\nimport { remove } from \"unist-util-remove\"\nimport { SKIP, visit } from \"unist-util-visit\"\nimport type { VFile } from \"vfile\"\n\nimport type { CustomTypeModelRichTextField } from \"../types/model/richText\"\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport { filterRichTextField } from \"./filterRichTextField\"\nimport type { HASTToRichTextConfig } from \"./hastToRichText\"\nimport { hastToRichText } from \"./hastToRichText\"\n\n/**\n * Configuration options for {@link rehypeRichText}.\n */\nexport type RehypeRichTextConfig = {\n\t/**\n\t * A CSS selector that targets the section of the document to convert to rich\n\t * text.\n\t *\n\t * @example `div.post`\n\t *\n\t * @defaultValue `\":root\"` - The top-level element of the document.\n\t */\n\tcontainer?: string\n\n\t/**\n\t * A list of CSS selectors to exclude matching nodes from the document to\n\t * process.\n\t *\n\t * @example `[\".hidden\", \"aside\"]`\n\t *\n\t * @defaultValue `[]` - No nodes are excluded.\n\t */\n\texclude?: string[]\n\n\t/**\n\t * A list of CSS selectors to include only matching nodes from the document to\n\t * process.\n\t *\n\t * @example `[\"p\", \"img\"]`\n\t *\n\t * @defaultValue `[]` - All nodes are included.\n\t */\n\tinclude?: string[]\n\n\t/**\n\t * A rich text or title field model definition. When provided the serializer\n\t * will filter out any node types not allowed by the model.\n\t *\n\t * @defaultValue `undefined` - No filtering is applied.\n\t */\n\tmodel?: CustomTypeModelRichTextField\n} & HASTToRichTextConfig\n\n/**\n * A unified plugin that compiles a hast tree to a Prismic rich text field.\n *\n * @param config - Configuration options for the rehype rich text processor.\n */\n// unified requires the function to be typed directly with the\n// `Plugin` type to properly infer return types on processors.\nexport const rehypeRichText: Plugin<\n\t[config?: RehypeRichTextConfig],\n\tRoot,\n\tRichTextField\n> = function rehypeRichText(config) {\n\t// This is a bit dirty, but it seems like that's how rehype intends\n\t// it to be due to JSDocs limitations(?), see:\n\t// https://github.com/rehypejs/rehype/blob/f6912ac680704f1ef4b558ac57cbf0dd62ed0892/packages/rehype-stringify/lib/index.js#L18-L20\n\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\tconst self = this as unknown as Processor<\n\t\tundefined,\n\t\tundefined,\n\t\tundefined,\n\t\tRoot,\n\t\tRichTextField\n\t>\n\n\t// We need to exclude nodes _before_ we minify the tree as excluding\n\t// nodes could end up in more whitespaces to trim.\n\tself.use(() => {\n\t\treturn (tree: Root) => {\n\t\t\t// Extract container node if any is specified.\n\t\t\tif (config?.container) {\n\t\t\t\tconst element = select(config.container, tree)\n\n\t\t\t\tif (!element) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No container matching \\`${config?.container}\\` could be found in the input AST.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\t// We cannot reassign the tree itself, so we instead replace\n\t\t\t\t// its children with the found element.\n\t\t\t\ttree.children = [element]\n\t\t\t}\n\n\t\t\t// Remove excluded nodes if any are specified\n\t\t\tif (config?.exclude) {\n\t\t\t\t// We join selector to only run one query\n\t\t\t\tconst nodesToExclude = selectAll(config.exclude.join(\", \"), tree)\n\n\t\t\t\tremove(tree, (node) => nodesToExclude.includes(node as Element))\n\t\t\t}\n\n\t\t\t// Include only nodes to include\n\t\t\tif (config?.include) {\n\t\t\t\tconst nodesToInclude: Element[] = []\n\n\t\t\t\t// We join selector to only run one query\n\t\t\t\tconst selector = config.include.join(\", \")\n\t\t\t\tconst rawNodesToInclude = selectAll(selector, tree)\n\n\t\t\t\t// We walk the tree to exclude matching nodes that are children of other matching nodes.\n\t\t\t\tvisit(tree, (node) => {\n\t\t\t\t\tif (rawNodesToInclude.includes(node as Element)) {\n\t\t\t\t\t\tnodesToInclude.push(node as Element)\n\n\t\t\t\t\t\t// Stop traversing this part of the tree since we found its matching parent node.\n\t\t\t\t\t\treturn SKIP\n\t\t\t\t\t}\n\t\t\t\t})\n\n\t\t\t\t// We cannot reassign the tree itself, so we instead replace\n\t\t\t\t// its children with the found element.\n\t\t\t\ttree.children = nodesToInclude\n\t\t\t}\n\n\t\t\t// Mark nodes matching CSS selectors\n\t\t\tif (config?.serializer) {\n\t\t\t\tfor (const key in config.serializer) {\n\t\t\t\t\t// HTML tag names are single word, lowercase strings, a-z and 1-6 (headings).\n\t\t\t\t\t// Here we want to match anything that's not a valid HTML tag name and treat\n\t\t\t\t\t// it as a CSS selector. See: https://regex101.com/r/LILLWH/1\n\t\t\t\t\tif (!/^[a-z]+[1-6]?$/.test(key)) {\n\t\t\t\t\t\tconst matches = selectAll(key, tree)\n\n\t\t\t\t\t\tfor (let i = 0; i < matches.length; i++) {\n\t\t\t\t\t\t\tmatches[i].matchesSerializer = key\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}\n\t})\n\n\t// `rehypeRichText` _depends_ on `rehypeMinifyWhitespace`, that's why it's\n\t// registered within the plugin rather than on the processor directly.\n\tself.use(rehypeMinifyWhitespace)\n\n\tself.compiler = compiler\n\n\tfunction compiler(tree: Root, file: VFile): RichTextField {\n\t\tconst richTextField = hastToRichText(tree, file, config)\n\n\t\tif (config?.model) {\n\t\t\treturn filterRichTextField(richTextField, config.model)\n\t\t}\n\n\t\treturn richTextField\n\t}\n}\n\ndeclare module \"unified\" {\n\t// Register unified processor the result type.\n\tinterface CompileResultMap {\n\t\tRichTextField: RichTextField\n\t}\n}\n\ndeclare module \"hast\" {\n\t// Extend hast node with a rich text value.\n\tinterface Element {\n\t\t/**\n\t\t * A serializer this node matches to. Nodes are marked with this property\n\t\t * when they match a CSS selector from the serializer map.\n\t\t */\n\t\tmatchesSerializer?: string\n\t}\n}\n"],"names":["rehypeRichText"],"mappings":";;;;;;AAiEa,MAAA,iBAIT,SAASA,gBAAe,QAAM;AAKjC,QAAM,OAAO;AAUb,OAAK,IAAI,MAAK;AACb,WAAO,CAAC,SAAc;AAErB,UAAI,iCAAQ,WAAW;AACtB,cAAM,UAAU,OAAO,OAAO,WAAW,IAAI;AAE7C,YA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from \"../richtext/types\"
|
|
1
|
+
{"version":3,"file":"serializerHelpers.cjs","sources":["../../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\n\nimport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\n\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"names":["escapeHTML","LinkType","asLink"],"mappings":";;;;;AAcA,MAAM,mBAAmB,CAAC,MAAiB,eAAkC;AACtE,QAAA,cAAc,EAAE,GAAG;AAGzB,MAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,OAAO;AAC9D,gBAAY,QAA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iB,MAAM,UAAU,CAAC,IAAI,QAAQ;AAAA,EAAA;AAE5D;AAEO,MAAM,gBAAgB,MAEzB;AACI,SAAA,CAAC,EAAE,WAAkB;AAC3B,WAAO,OAAOD,WAAW,WAAA,IAAI,EAAE,QAAQ,OAAO,QAAQ,IAAI;AAAA,EAAA;AAE5D;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RichTextMapSerializer } from "../richtext/types";
|
|
2
|
-
import { HTMLRichTextMapSerializer, HTMLStrictRichTextMapSerializer } from "../helpers/asHTML";
|
|
3
|
-
import { LinkResolverFunction } from "../helpers/asLink";
|
|
2
|
+
import type { HTMLRichTextMapSerializer, HTMLStrictRichTextMapSerializer } from "../helpers/asHTML";
|
|
3
|
+
import type { LinkResolverFunction } from "../helpers/asLink";
|
|
4
4
|
export declare const serializeStandardTag: <BlockType extends keyof RichTextMapSerializer<string>>(tag: string, serializerOrShorthand?: HTMLRichTextMapSerializer[BlockType]) => NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>;
|
|
5
5
|
export declare const serializePreFormatted: (serializerOrShorthand?: HTMLRichTextMapSerializer["preformatted"]) => NonNullable<HTMLStrictRichTextMapSerializer["preformatted"]>;
|
|
6
6
|
export declare const serializeImage: (linkResolver: LinkResolverFunction<string | null | undefined> | undefined | null, serializerOrShorthand?: HTMLRichTextMapSerializer["image"]) => NonNullable<HTMLStrictRichTextMapSerializer["image"]>;
|