@prismicio/client 6.7.3 → 7.0.0-alpha.1
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 +4 -4
- package/dist/buildQueryURL.cjs +25 -6
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +207 -130
- package/dist/buildQueryURL.js +25 -6
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.d.ts +5 -5
- package/dist/createClient.cjs +1142 -0
- package/dist/createClient.cjs.map +1 -0
- package/dist/{client.d.ts → createClient.d.ts} +980 -929
- package/dist/createClient.js +1142 -0
- package/dist/createClient.js.map +1 -0
- package/dist/errors/ForbiddenError.cjs.map +1 -0
- package/dist/{ForbiddenError.d.ts → errors/ForbiddenError.d.ts} +11 -11
- package/dist/errors/ForbiddenError.js.map +1 -0
- package/dist/errors/NotFoundError.cjs.map +1 -0
- package/dist/{NotFoundError.d.ts → errors/NotFoundError.d.ts} +3 -3
- package/dist/errors/NotFoundError.js.map +1 -0
- package/dist/errors/ParsingError.cjs.map +1 -0
- package/dist/{ParsingError.d.ts → errors/ParsingError.d.ts} +12 -12
- package/dist/errors/ParsingError.js.map +1 -0
- package/dist/errors/PrismicError.cjs.map +1 -0
- package/dist/{PrismicError.d.ts → errors/PrismicError.d.ts} +5 -5
- package/dist/errors/PrismicError.js.map +1 -0
- package/dist/filter.cjs +247 -0
- package/dist/filter.cjs.map +1 -0
- package/dist/filter.d.ts +209 -0
- package/dist/filter.js +247 -0
- package/dist/filter.js.map +1 -0
- package/dist/getGraphQLEndpoint.cjs +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.d.ts +9 -9
- package/dist/getGraphQLEndpoint.js +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +10 -10
- package/dist/getRepositoryEndpoint.js +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.d.ts +13 -13
- package/dist/getRepositoryName.js +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs +13 -0
- package/dist/getToolbarSrc.cjs.map +1 -0
- package/dist/getToolbarSrc.d.ts +34 -0
- package/dist/getToolbarSrc.js +13 -0
- package/dist/getToolbarSrc.js.map +1 -0
- package/dist/helpers/asDate.cjs +14 -0
- package/dist/helpers/asDate.cjs.map +1 -0
- package/dist/helpers/asDate.d.ts +16 -0
- package/dist/helpers/asDate.js +14 -0
- package/dist/helpers/asDate.js.map +1 -0
- package/dist/helpers/asHTML.cjs +80 -0
- package/dist/helpers/asHTML.cjs.map +1 -0
- package/dist/helpers/asHTML.d.ts +77 -0
- package/dist/helpers/asHTML.js +80 -0
- package/dist/helpers/asHTML.js.map +1 -0
- package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -0
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -0
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -0
- package/dist/helpers/asImagePixelDensitySrcSet.js +21 -0
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -0
- package/dist/helpers/asImageSrc.cjs +13 -0
- package/dist/helpers/asImageSrc.cjs.map +1 -0
- package/dist/helpers/asImageSrc.d.ts +27 -0
- package/dist/helpers/asImageSrc.js +13 -0
- package/dist/helpers/asImageSrc.js.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.cjs +45 -0
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.d.ts +60 -0
- package/dist/helpers/asImageWidthSrcSet.js +45 -0
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
- package/dist/helpers/asLink.cjs +38 -0
- package/dist/helpers/asLink.cjs.map +1 -0
- package/dist/helpers/asLink.d.ts +34 -0
- package/dist/helpers/asLink.js +38 -0
- package/dist/helpers/asLink.js.map +1 -0
- package/dist/helpers/asLinkAttrs.cjs +28 -0
- package/dist/helpers/asLinkAttrs.cjs.map +1 -0
- package/dist/helpers/asLinkAttrs.d.ts +63 -0
- package/dist/helpers/asLinkAttrs.js +28 -0
- package/dist/helpers/asLinkAttrs.js.map +1 -0
- package/dist/helpers/asText.cjs +12 -0
- package/dist/helpers/asText.cjs.map +1 -0
- package/dist/helpers/asText.d.ts +16 -0
- package/dist/helpers/asText.js +12 -0
- package/dist/helpers/asText.js.map +1 -0
- package/dist/helpers/documentToLinkField.cjs +26 -0
- package/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/helpers/documentToLinkField.d.ts +15 -0
- package/dist/helpers/documentToLinkField.js +26 -0
- package/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/helpers/isFilled.cjs +67 -0
- package/dist/helpers/isFilled.cjs.map +1 -0
- package/dist/helpers/isFilled.d.ts +172 -0
- package/dist/helpers/isFilled.js +67 -0
- package/dist/helpers/isFilled.js.map +1 -0
- package/dist/index.cjs +56 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +138 -88
- package/dist/index.js +50 -16
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +10 -10
- package/dist/isRepositoryName.d.ts +9 -9
- package/dist/lib/appendFilters.cjs +11 -0
- package/dist/lib/appendFilters.cjs.map +1 -0
- package/dist/lib/appendFilters.d.ts +18 -0
- package/dist/lib/appendFilters.js +11 -0
- package/dist/lib/appendFilters.js.map +1 -0
- package/dist/lib/castArray.cjs +3 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.d.ts +11 -11
- package/dist/lib/castArray.js +3 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs +3 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.d.ts +10 -10
- package/dist/lib/castThunk.js +3 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs +8 -0
- package/dist/lib/devMsg.cjs.map +1 -0
- package/dist/lib/devMsg.d.ts +16 -0
- package/dist/lib/devMsg.js +8 -0
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/escapeHTML.cjs +43 -0
- package/dist/lib/escapeHTML.cjs.map +1 -0
- package/dist/lib/escapeHTML.d.ts +1 -0
- package/dist/lib/escapeHTML.js +43 -0
- package/dist/lib/escapeHTML.js.map +1 -0
- package/dist/lib/everyTagFilter.cjs +9 -0
- package/dist/lib/everyTagFilter.cjs.map +1 -0
- package/dist/lib/everyTagFilter.d.ts +9 -0
- package/dist/lib/everyTagFilter.js +9 -0
- package/dist/lib/everyTagFilter.js.map +1 -0
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +10 -10
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs +3 -3
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +13 -13
- package/dist/lib/findRef.js +3 -3
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +11 -11
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +11 -11
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.d.ts +9 -9
- package/dist/lib/getPreviewCookie.js +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs +9 -0
- package/dist/lib/isInternalURL.cjs.map +1 -0
- package/dist/lib/isInternalURL.d.ts +8 -0
- package/dist/lib/isInternalURL.js +9 -0
- package/dist/lib/isInternalURL.js.map +1 -0
- package/dist/lib/minifyGraphQLQuery.d.ts +8 -8
- package/dist/lib/serializerHelpers.cjs +54 -0
- package/dist/lib/serializerHelpers.cjs.map +1 -0
- package/dist/lib/serializerHelpers.d.ts +9 -0
- package/dist/lib/serializerHelpers.js +54 -0
- package/dist/lib/serializerHelpers.js.map +1 -0
- package/dist/lib/someTagsFilter.cjs +9 -0
- package/dist/lib/someTagsFilter.cjs.map +1 -0
- package/dist/lib/someTagsFilter.d.ts +9 -0
- package/dist/lib/someTagsFilter.js +9 -0
- package/dist/lib/someTagsFilter.js.map +1 -0
- package/dist/lib/typeFilter.cjs +8 -0
- package/dist/lib/typeFilter.cjs.map +1 -0
- package/dist/lib/typeFilter.d.ts +8 -0
- package/dist/lib/typeFilter.js +8 -0
- package/dist/lib/typeFilter.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/package.json.js +5 -0
- package/dist/package.json.js.map +1 -0
- package/dist/types/api/query.d.ts +42 -0
- package/dist/types/api/ref.d.ts +32 -0
- package/dist/types/api/release.d.ts +10 -0
- package/dist/types/api/repository.d.ts +100 -0
- package/dist/types/api/tags.d.ts +8 -0
- package/dist/types/model/boolean.d.ts +15 -0
- package/dist/types/model/color.d.ts +13 -0
- package/dist/types/model/contentRelationship.d.ts +18 -0
- package/dist/types/model/customType.d.ts +42 -0
- package/dist/types/model/date.d.ts +14 -0
- package/dist/types/model/embed.d.ts +13 -0
- package/dist/types/model/geoPoint.d.ts +12 -0
- package/dist/types/model/group.d.ts +15 -0
- package/dist/types/model/image.d.ts +31 -0
- package/dist/types/model/integrationFields.d.ts +14 -0
- package/dist/types/model/keyText.d.ts +13 -0
- package/dist/types/model/link.cjs +9 -0
- package/dist/types/model/link.cjs.map +1 -0
- package/dist/types/model/link.d.ts +27 -0
- package/dist/types/model/link.js +9 -0
- package/dist/types/model/link.js.map +1 -0
- package/dist/types/model/linkToMedia.d.ts +16 -0
- package/dist/types/model/number.d.ts +15 -0
- package/dist/types/model/range.d.ts +14 -0
- package/dist/types/model/richText.d.ts +35 -0
- package/dist/types/model/select.d.ts +18 -0
- package/dist/types/model/separator.d.ts +10 -0
- package/dist/types/model/sharedSlice.d.ts +16 -0
- package/dist/types/model/sharedSliceVariation.d.ts +19 -0
- package/dist/types/model/slice.cjs +8 -0
- package/dist/types/model/slice.cjs.map +1 -0
- package/dist/types/model/slice.d.ts +33 -0
- package/dist/types/model/slice.js +8 -0
- package/dist/types/model/slice.js.map +1 -0
- package/dist/types/model/sliceZone.cjs +8 -0
- package/dist/types/model/sliceZone.cjs.map +1 -0
- package/dist/types/model/sliceZone.d.ts +41 -0
- package/dist/types/model/sliceZone.js +8 -0
- package/dist/types/model/sliceZone.js.map +1 -0
- package/dist/types/model/timestamp.d.ts +14 -0
- package/dist/types/model/title.d.ts +7 -0
- package/dist/types/model/types.cjs +34 -0
- package/dist/types/model/types.cjs.map +1 -0
- package/dist/types/model/types.d.ts +62 -0
- package/dist/types/model/types.js +34 -0
- package/dist/types/model/types.js.map +1 -0
- package/dist/types/model/uid.d.ts +13 -0
- package/dist/types/value/boolean.d.ts +6 -0
- package/dist/types/value/color.d.ts +8 -0
- package/dist/types/value/contentRelationship.d.ts +29 -0
- package/dist/types/value/date.d.ts +8 -0
- package/dist/types/value/document.d.ts +113 -0
- package/dist/types/value/embed.cjs +10 -0
- package/dist/types/value/embed.cjs.map +1 -0
- package/dist/types/value/embed.d.ts +167 -0
- package/dist/types/value/embed.js +10 -0
- package/dist/types/value/embed.js.map +1 -0
- package/dist/types/value/geoPoint.d.ts +11 -0
- package/dist/types/value/group.d.ts +7 -0
- package/dist/types/value/image.d.ts +36 -0
- package/dist/types/value/integrationFields.d.ts +9 -0
- package/dist/types/value/keyText.d.ts +8 -0
- package/dist/types/value/link.cjs +10 -0
- package/dist/types/value/link.cjs.map +1 -0
- package/dist/types/value/link.d.ts +40 -0
- package/dist/types/value/link.js +10 -0
- package/dist/types/value/link.js.map +1 -0
- package/dist/types/value/linkToMedia.d.ts +20 -0
- package/dist/types/value/number.d.ts +8 -0
- package/dist/types/value/richText.cjs +25 -0
- package/dist/types/value/richText.cjs.map +1 -0
- package/dist/types/value/richText.d.ts +203 -0
- package/dist/types/value/richText.js +25 -0
- package/dist/types/value/richText.js.map +1 -0
- package/dist/types/value/select.d.ts +9 -0
- package/dist/types/value/sharedSlice.d.ts +11 -0
- package/dist/types/value/sharedSliceVariation.d.ts +7 -0
- package/dist/types/value/slice.d.ts +13 -0
- package/dist/types/value/sliceZone.d.ts +12 -0
- package/dist/types/value/timestamp.d.ts +8 -0
- package/dist/types/value/title.d.ts +12 -0
- package/dist/types/value/types.d.ts +40 -0
- package/dist/types/webhook/apiUpdate.d.ts +52 -0
- package/dist/types/webhook/testTrigger.d.ts +9 -0
- package/dist/types/webhook/types.cjs +8 -0
- package/dist/types/webhook/types.cjs.map +1 -0
- package/dist/types/webhook/types.d.ts +18 -0
- package/dist/types/webhook/types.js +8 -0
- package/dist/types/webhook/types.js.map +1 -0
- package/package.json +42 -36
- package/src/buildQueryURL.ts +179 -32
- package/src/{client.ts → createClient.ts} +248 -186
- package/src/filter.ts +356 -0
- package/src/getGraphQLEndpoint.ts +2 -1
- package/src/getRepositoryEndpoint.ts +2 -1
- package/src/getRepositoryName.ts +1 -1
- package/src/getToolbarSrc.ts +50 -0
- package/src/helpers/asDate.ts +48 -0
- package/src/helpers/asHTML.ts +249 -0
- package/src/helpers/asImagePixelDensitySrcSet.ts +96 -0
- package/src/helpers/asImageSrc.ts +41 -0
- package/src/helpers/asImageWidthSrcSet.ts +139 -0
- package/src/helpers/asLink.ts +118 -0
- package/src/helpers/asLinkAttrs.ts +127 -0
- package/src/helpers/asText.ts +29 -0
- package/src/helpers/documentToLinkField.ts +47 -0
- package/src/helpers/isFilled.ts +288 -0
- package/src/index.ts +277 -31
- package/src/lib/appendFilters.ts +26 -0
- package/src/lib/castArray.ts +3 -1
- package/src/lib/castThunk.ts +3 -2
- package/src/lib/devMsg.ts +20 -0
- package/src/lib/escapeHTML.ts +51 -0
- package/src/lib/everyTagFilter.ts +15 -0
- package/src/lib/findMasterRef.ts +2 -2
- package/src/lib/findRef.ts +6 -9
- package/src/lib/findRefByID.ts +2 -2
- package/src/lib/findRefByLabel.ts +2 -5
- package/src/lib/getPreviewCookie.ts +1 -1
- package/src/lib/isInternalURL.ts +14 -0
- package/src/lib/serializerHelpers.ts +101 -0
- package/src/lib/someTagsFilter.ts +15 -0
- package/src/lib/typeFilter.ts +12 -0
- package/src/types/api/query.ts +50 -0
- package/src/types/api/ref.ts +36 -0
- package/src/types/api/release.ts +11 -0
- package/src/types/api/repository.ts +117 -0
- package/src/types/api/tags.ts +8 -0
- package/src/types/model/boolean.ts +16 -0
- package/src/types/model/color.ts +14 -0
- package/src/types/model/contentRelationship.ts +23 -0
- package/src/types/model/customType.ts +61 -0
- package/src/types/model/date.ts +15 -0
- package/src/types/model/embed.ts +14 -0
- package/src/types/model/geoPoint.ts +13 -0
- package/src/types/model/group.ts +24 -0
- package/src/types/model/image.ts +37 -0
- package/src/types/model/integrationFields.ts +15 -0
- package/src/types/model/keyText.ts +14 -0
- package/src/types/model/link.ts +31 -0
- package/src/types/model/linkToMedia.ts +18 -0
- package/src/types/model/number.ts +16 -0
- package/src/types/model/range.ts +15 -0
- package/src/types/model/richText.ts +40 -0
- package/src/types/model/select.ts +22 -0
- package/src/types/model/separator.ts +11 -0
- package/src/types/model/sharedSlice.ts +20 -0
- package/src/types/model/sharedSliceVariation.ts +30 -0
- package/src/types/model/slice.ts +50 -0
- package/src/types/model/sliceZone.ts +60 -0
- package/src/types/model/timestamp.ts +15 -0
- package/src/types/model/title.ts +8 -0
- package/src/types/model/types.ts +87 -0
- package/src/types/model/uid.ts +14 -0
- package/src/types/value/boolean.ts +6 -0
- package/src/types/value/color.ts +10 -0
- package/src/types/value/contentRelationship.ts +47 -0
- package/src/types/value/date.ts +10 -0
- package/src/types/value/document.ts +143 -0
- package/src/types/value/embed.ts +196 -0
- package/src/types/value/geoPoint.ts +15 -0
- package/src/types/value/group.ts +14 -0
- package/src/types/value/image.ts +67 -0
- package/src/types/value/integrationFields.ts +13 -0
- package/src/types/value/keyText.ts +10 -0
- package/src/types/value/link.ts +59 -0
- package/src/types/value/linkToMedia.ts +26 -0
- package/src/types/value/number.ts +10 -0
- package/src/types/value/richText.ts +287 -0
- package/src/types/value/select.ts +13 -0
- package/src/types/value/sharedSlice.ts +15 -0
- package/src/types/value/sharedSliceVariation.ts +18 -0
- package/src/types/value/slice.ts +24 -0
- package/src/types/value/sliceZone.ts +17 -0
- package/src/types/value/timestamp.ts +13 -0
- package/src/types/value/title.ts +32 -0
- package/src/types/value/types.ts +58 -0
- package/src/types/webhook/apiUpdate.ts +56 -0
- package/src/types/webhook/testTrigger.ts +10 -0
- package/src/types/webhook/types.ts +21 -0
- package/dist/ForbiddenError.cjs.map +0 -1
- package/dist/ForbiddenError.js.map +0 -1
- package/dist/NotFoundError.cjs.map +0 -1
- package/dist/NotFoundError.js.map +0 -1
- package/dist/ParsingError.cjs.map +0 -1
- package/dist/ParsingError.js.map +0 -1
- package/dist/PrismicError.cjs.map +0 -1
- package/dist/PrismicError.js.map +0 -1
- package/dist/client.cjs +0 -436
- package/dist/client.cjs.map +0 -1
- package/dist/client.js +0 -419
- package/dist/client.js.map +0 -1
- package/dist/lib/appendPredicates.cjs +0 -14
- package/dist/lib/appendPredicates.cjs.map +0 -1
- package/dist/lib/appendPredicates.d.ts +0 -18
- package/dist/lib/appendPredicates.js +0 -14
- package/dist/lib/appendPredicates.js.map +0 -1
- package/dist/lib/orElseThrow.d.ts +0 -11
- package/dist/predicate.cjs +0 -68
- package/dist/predicate.cjs.map +0 -1
- package/dist/predicate.d.ts +0 -209
- package/dist/predicate.js +0 -68
- package/dist/predicate.js.map +0 -1
- package/dist/types.d.ts +0 -156
- package/src/lib/appendPredicates.ts +0 -29
- package/src/lib/orElseThrow.ts +0 -17
- package/src/predicate.ts +0 -359
- package/src/types.ts +0 -191
- /package/dist/{ForbiddenError.cjs → errors/ForbiddenError.cjs} +0 -0
- /package/dist/{ForbiddenError.js → errors/ForbiddenError.js} +0 -0
- /package/dist/{NotFoundError.cjs → errors/NotFoundError.cjs} +0 -0
- /package/dist/{NotFoundError.js → errors/NotFoundError.js} +0 -0
- /package/dist/{ParsingError.cjs → errors/ParsingError.cjs} +0 -0
- /package/dist/{ParsingError.js → errors/ParsingError.js} +0 -0
- /package/dist/{PrismicError.cjs → errors/PrismicError.cjs} +0 -0
- /package/dist/{PrismicError.js → errors/PrismicError.js} +0 -0
- /package/src/{ForbiddenError.ts → errors/ForbiddenError.ts} +0 -0
- /package/src/{NotFoundError.ts → errors/NotFoundError.ts} +0 -0
- /package/src/{ParsingError.ts → errors/ParsingError.ts} +0 -0
- /package/src/{PrismicError.ts → errors/PrismicError.ts} +0 -0
package/src/index.ts
CHANGED
|
@@ -1,50 +1,296 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// Use for deprecations.
|
|
2
|
+
import type {
|
|
3
|
+
HTMLRichTextFunctionSerializer,
|
|
4
|
+
HTMLRichTextMapSerializer,
|
|
5
|
+
} from "./helpers/asHTML";
|
|
6
|
+
|
|
7
|
+
import { filter } from "./filter";
|
|
8
|
+
|
|
9
|
+
//=============================================================================
|
|
10
|
+
// Client - Query content from Prismic.
|
|
11
|
+
//=============================================================================
|
|
12
|
+
|
|
13
|
+
// Primary Client API.
|
|
14
|
+
export { createClient, Client } from "./createClient";
|
|
15
|
+
|
|
16
|
+
// API endpoint helpers.
|
|
17
|
+
export { getRepositoryEndpoint } from "./getRepositoryEndpoint";
|
|
9
18
|
export { getRepositoryName } from "./getRepositoryName";
|
|
10
19
|
export { getGraphQLEndpoint } from "./getGraphQLEndpoint";
|
|
11
20
|
export { isRepositoryName } from "./isRepositoryName";
|
|
12
21
|
export { isRepositoryEndpoint } from "./isRepositoryEndpoint";
|
|
13
22
|
export { buildQueryURL } from "./buildQueryURL";
|
|
14
|
-
export { createClient, Client } from "./client";
|
|
15
23
|
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @deprecated Renamed to `predicate` (without an "s").
|
|
21
|
-
*/
|
|
22
|
-
// TODO: Remove in v3.
|
|
23
|
-
export const predicates = predicate;
|
|
24
|
+
// Toolbar helpers.
|
|
25
|
+
export { getToolbarSrc } from "./getToolbarSrc";
|
|
26
|
+
|
|
27
|
+
// Query filters API.
|
|
24
28
|
/**
|
|
25
|
-
* @deprecated Renamed to `
|
|
29
|
+
* @deprecated Renamed to `filter`
|
|
26
30
|
*/
|
|
27
|
-
// TODO: Remove
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Custom errors used by Client.
|
|
31
|
-
export { PrismicError } from "./PrismicError";
|
|
32
|
-
export { ForbiddenError } from "./ForbiddenError";
|
|
33
|
-
export { ParsingError } from "./ParsingError";
|
|
34
|
-
export { NotFoundError } from "./NotFoundError";
|
|
31
|
+
// TODO: Remove when we remove support for deprecated `predicate` export.
|
|
32
|
+
const predicate = filter;
|
|
33
|
+
export { filter, predicate };
|
|
35
34
|
|
|
36
35
|
// A collection of well-known cookie names shared between Prismic libraries and systems.
|
|
37
36
|
export * as cookie from "./cookie";
|
|
38
37
|
|
|
39
|
-
// General types used
|
|
40
|
-
export type { CreateClient, ClientConfig } from "./client";
|
|
41
|
-
export type { QueryParams, BuildQueryURLArgs } from "./buildQueryURL";
|
|
38
|
+
// General types used to query content from Prismic. These are made public to allow users to better type their projects.
|
|
42
39
|
export type {
|
|
43
40
|
AbortSignalLike,
|
|
41
|
+
ClientConfig,
|
|
42
|
+
CreateClient,
|
|
44
43
|
FetchLike,
|
|
45
44
|
HttpRequestLike,
|
|
46
|
-
Ordering,
|
|
47
45
|
RequestInitLike,
|
|
48
46
|
ResponseLike,
|
|
47
|
+
} from "./createClient";
|
|
48
|
+
export type {
|
|
49
|
+
BuildQueryURLArgs,
|
|
50
|
+
Ordering,
|
|
51
|
+
QueryParams,
|
|
49
52
|
Route,
|
|
50
|
-
} from "./
|
|
53
|
+
} from "./buildQueryURL";
|
|
54
|
+
|
|
55
|
+
//=============================================================================
|
|
56
|
+
// Helpers - Manipulate content from Prismic.
|
|
57
|
+
//=============================================================================
|
|
58
|
+
|
|
59
|
+
// Primary Helpers API.
|
|
60
|
+
export { asDate } from "./helpers/asDate";
|
|
61
|
+
export { asLink } from "./helpers/asLink";
|
|
62
|
+
export { asLinkAttrs } from "./helpers/asLinkAttrs";
|
|
63
|
+
export { asText } from "./helpers/asText";
|
|
64
|
+
export { asHTML } from "./helpers/asHTML";
|
|
65
|
+
export { asImageSrc } from "./helpers/asImageSrc";
|
|
66
|
+
export { asImageWidthSrcSet } from "./helpers/asImageWidthSrcSet";
|
|
67
|
+
export { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet";
|
|
68
|
+
export * as isFilled from "./helpers/isFilled";
|
|
69
|
+
|
|
70
|
+
// Conversion helper.
|
|
71
|
+
export { documentToLinkField } from "./helpers/documentToLinkField";
|
|
72
|
+
|
|
73
|
+
// RichText element types.
|
|
74
|
+
export { Element } from "@prismicio/richtext";
|
|
75
|
+
|
|
76
|
+
export type { LinkResolverFunction } from "./helpers/asLink";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated Renamed to `HTMLRichTextMapSerializer`
|
|
80
|
+
*/
|
|
81
|
+
type HTMLMapSerializer = HTMLRichTextMapSerializer;
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Renamed to `HTMLRichTextFunctionSerializer`
|
|
84
|
+
*/
|
|
85
|
+
type HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;
|
|
86
|
+
export type {
|
|
87
|
+
HTMLRichTextMapSerializer,
|
|
88
|
+
HTMLRichTextFunctionSerializer,
|
|
89
|
+
HTMLMapSerializer,
|
|
90
|
+
HTMLFunctionSerializer,
|
|
91
|
+
};
|
|
92
|
+
export type { HTMLRichTextSerializer } from "./helpers/asHTML";
|
|
93
|
+
|
|
94
|
+
//=============================================================================
|
|
95
|
+
// Errors - Custom errors for Prismic APIs.
|
|
96
|
+
//=============================================================================
|
|
97
|
+
|
|
98
|
+
export { PrismicError } from "./errors/PrismicError";
|
|
99
|
+
export { ForbiddenError } from "./errors/ForbiddenError";
|
|
100
|
+
export { NotFoundError } from "./errors/NotFoundError";
|
|
101
|
+
export { ParsingError } from "./errors/ParsingError";
|
|
102
|
+
|
|
103
|
+
//=============================================================================
|
|
104
|
+
// Types - Types representing Prismic content, models, and API payloads.
|
|
105
|
+
//=============================================================================
|
|
106
|
+
|
|
107
|
+
// Values - Types representing Prismic content.
|
|
108
|
+
export { RichTextNodeType } from "./types/value/richText";
|
|
109
|
+
export { LinkType } from "./types/value/link";
|
|
110
|
+
export { OEmbedType } from "./types/value/embed";
|
|
111
|
+
|
|
112
|
+
export type {
|
|
113
|
+
PrismicDocument,
|
|
114
|
+
PrismicDocumentWithUID,
|
|
115
|
+
PrismicDocumentWithoutUID,
|
|
116
|
+
PrismicDocumentHeader,
|
|
117
|
+
AlternateLanguage,
|
|
118
|
+
} from "./types/value/document";
|
|
119
|
+
|
|
120
|
+
export type {
|
|
121
|
+
// RichText & Title
|
|
122
|
+
RichTextField,
|
|
123
|
+
// RichText & Title (block nodes)
|
|
124
|
+
RTTextNodeBase,
|
|
125
|
+
RTHeading1Node,
|
|
126
|
+
RTHeading2Node,
|
|
127
|
+
RTHeading3Node,
|
|
128
|
+
RTHeading4Node,
|
|
129
|
+
RTHeading5Node,
|
|
130
|
+
RTHeading6Node,
|
|
131
|
+
RTParagraphNode,
|
|
132
|
+
RTPreformattedNode,
|
|
133
|
+
RTListItemNode,
|
|
134
|
+
RTOListItemNode,
|
|
135
|
+
// RichText & Title (span nodes)
|
|
136
|
+
RTSpanNodeBase,
|
|
137
|
+
RTStrongNode,
|
|
138
|
+
RTEmNode,
|
|
139
|
+
RTLabelNode,
|
|
140
|
+
// RichText & Title (media nodes)
|
|
141
|
+
RTImageNode,
|
|
142
|
+
RTEmbedNode,
|
|
143
|
+
// RichText & Title (link nodes)
|
|
144
|
+
RTLinkNode,
|
|
145
|
+
// RichText & Title (serialization related nodes)
|
|
146
|
+
RTListNode,
|
|
147
|
+
RTOListNode,
|
|
148
|
+
RTSpanNode,
|
|
149
|
+
// RichText & Title (helpers)
|
|
150
|
+
RTNode,
|
|
151
|
+
RTTextNode,
|
|
152
|
+
RTBlockNode,
|
|
153
|
+
RTInlineNode,
|
|
154
|
+
RTAnyNode,
|
|
155
|
+
} from "./types/value/richText";
|
|
156
|
+
export type { TitleField } from "./types/value/title";
|
|
157
|
+
|
|
158
|
+
export type {
|
|
159
|
+
ImageField,
|
|
160
|
+
ImageFieldImage,
|
|
161
|
+
FilledImageFieldImage,
|
|
162
|
+
EmptyImageFieldImage,
|
|
163
|
+
} from "./types/value/image";
|
|
164
|
+
|
|
165
|
+
export type {
|
|
166
|
+
EmptyLinkField,
|
|
167
|
+
LinkField,
|
|
168
|
+
FilledLinkToWebField,
|
|
169
|
+
} from "./types/value/link";
|
|
170
|
+
export type {
|
|
171
|
+
ContentRelationshipField,
|
|
172
|
+
FilledContentRelationshipField,
|
|
173
|
+
} from "./types/value/contentRelationship";
|
|
174
|
+
export type {
|
|
175
|
+
LinkToMediaField,
|
|
176
|
+
FilledLinkToMediaField,
|
|
177
|
+
} from "./types/value/linkToMedia";
|
|
178
|
+
|
|
179
|
+
export type {
|
|
180
|
+
OEmbedExtra,
|
|
181
|
+
PhotoOEmbed,
|
|
182
|
+
VideoOEmbed,
|
|
183
|
+
LinkOEmbed,
|
|
184
|
+
RichOEmbed,
|
|
185
|
+
AnyOEmbed,
|
|
186
|
+
EmbedField,
|
|
187
|
+
} from "./types/value/embed";
|
|
188
|
+
|
|
189
|
+
export type { BooleanField } from "./types/value/boolean";
|
|
190
|
+
export type { ColorField } from "./types/value/color";
|
|
191
|
+
export type { DateField } from "./types/value/date";
|
|
192
|
+
export type { KeyTextField } from "./types/value/keyText";
|
|
193
|
+
export type { NumberField } from "./types/value/number";
|
|
194
|
+
export type { SelectField } from "./types/value/select";
|
|
195
|
+
export type { TimestampField } from "./types/value/timestamp";
|
|
196
|
+
export type { GeoPointField } from "./types/value/geoPoint";
|
|
197
|
+
|
|
198
|
+
export type { IntegrationFields } from "./types/value/integrationFields";
|
|
199
|
+
|
|
200
|
+
export type { GroupField } from "./types/value/group";
|
|
201
|
+
|
|
202
|
+
export type { SliceZone } from "./types/value/sliceZone";
|
|
203
|
+
export type { Slice } from "./types/value/slice";
|
|
204
|
+
export type { SharedSlice } from "./types/value/sharedSlice";
|
|
205
|
+
export type { SharedSliceVariation } from "./types/value/sharedSliceVariation";
|
|
206
|
+
|
|
207
|
+
export type { FieldState, AnyRegularField } from "./types/value/types";
|
|
208
|
+
|
|
209
|
+
// Models - Types representing Prismic content models.
|
|
210
|
+
export { CustomTypeModelFieldType } from "./types/model/types";
|
|
211
|
+
export { CustomTypeModelLinkSelectType } from "./types/model/link";
|
|
212
|
+
export { CustomTypeModelSliceType } from "./types/model/sliceZone";
|
|
213
|
+
export { CustomTypeModelSliceDisplay } from "./types/model/slice";
|
|
214
|
+
|
|
215
|
+
export type {
|
|
216
|
+
CustomTypeModel,
|
|
217
|
+
CustomTypeModelDefinition,
|
|
218
|
+
CustomTypeModelTab,
|
|
219
|
+
} from "./types/model/customType";
|
|
220
|
+
|
|
221
|
+
export type {
|
|
222
|
+
CustomTypeModelRichTextField,
|
|
223
|
+
CustomTypeModelRichTextMultiField,
|
|
224
|
+
CustomTypeModelRichTextSingleField,
|
|
225
|
+
} from "./types/model/richText";
|
|
226
|
+
export type { CustomTypeModelTitleField } from "./types/model/title";
|
|
227
|
+
|
|
228
|
+
export type {
|
|
229
|
+
CustomTypeModelImageField,
|
|
230
|
+
CustomTypeModelImageConstraint,
|
|
231
|
+
CustomTypeModelImageThumbnail,
|
|
232
|
+
} from "./types/model/image";
|
|
233
|
+
|
|
234
|
+
export type { CustomTypeModelContentRelationshipField } from "./types/model/contentRelationship";
|
|
235
|
+
export type { CustomTypeModelLinkField } from "./types/model/link";
|
|
236
|
+
export type { CustomTypeModelLinkToMediaField } from "./types/model/linkToMedia";
|
|
237
|
+
|
|
238
|
+
export type { CustomTypeModelEmbedField } from "./types/model/embed";
|
|
239
|
+
|
|
240
|
+
export type { CustomTypeModelBooleanField } from "./types/model/boolean";
|
|
241
|
+
export type { CustomTypeModelColorField } from "./types/model/color";
|
|
242
|
+
export type { CustomTypeModelDateField } from "./types/model/date";
|
|
243
|
+
export type { CustomTypeModelKeyTextField } from "./types/model/keyText";
|
|
244
|
+
export type { CustomTypeModelNumberField } from "./types/model/number";
|
|
245
|
+
export type { CustomTypeModelSelectField } from "./types/model/select";
|
|
246
|
+
export type { CustomTypeModelTimestampField } from "./types/model/timestamp";
|
|
247
|
+
export type { CustomTypeModelGeoPointField } from "./types/model/geoPoint";
|
|
248
|
+
|
|
249
|
+
export type { CustomTypeModelIntegrationFieldsField } from "./types/model/integrationFields";
|
|
250
|
+
export type { CustomTypeModelGroupField } from "./types/model/group";
|
|
251
|
+
export type {
|
|
252
|
+
CustomTypeModelSliceZoneField,
|
|
253
|
+
CustomTypeModelSliceLabel,
|
|
254
|
+
CustomTypeModelSharedSlice,
|
|
255
|
+
} from "./types/model/sliceZone";
|
|
256
|
+
export type {
|
|
257
|
+
CustomTypeModelSlice,
|
|
258
|
+
CustomTypeModelLegacySlice,
|
|
259
|
+
} from "./types/model/slice";
|
|
260
|
+
export type { SharedSliceModel } from "./types/model/sharedSlice";
|
|
261
|
+
export type { SharedSliceModelVariation } from "./types/model/sharedSliceVariation";
|
|
262
|
+
|
|
263
|
+
export type { CustomTypeModelUIDField } from "./types/model/uid";
|
|
264
|
+
|
|
265
|
+
export type { CustomTypeModelRangeField } from "./types/model/range";
|
|
266
|
+
export type { CustomTypeModelSeparatorField } from "./types/model/separator";
|
|
267
|
+
|
|
268
|
+
export type {
|
|
269
|
+
CustomTypeModelField,
|
|
270
|
+
CustomTypeModelFieldForGroup,
|
|
271
|
+
} from "./types/model/types";
|
|
272
|
+
|
|
273
|
+
// API - Types representing Prismic Rest API V2 responses.
|
|
274
|
+
export type { Query } from "./types/api/query";
|
|
275
|
+
|
|
276
|
+
export type { Ref } from "./types/api/ref";
|
|
277
|
+
|
|
278
|
+
export type { Release } from "./types/api/release";
|
|
279
|
+
|
|
280
|
+
export type {
|
|
281
|
+
Repository,
|
|
282
|
+
Language,
|
|
283
|
+
Form,
|
|
284
|
+
FormField,
|
|
285
|
+
} from "./types/api/repository";
|
|
286
|
+
|
|
287
|
+
export type { Tags } from "./types/api/tags";
|
|
288
|
+
|
|
289
|
+
// Webhook - Types representing Prismic webhooks.
|
|
290
|
+
export { WebhookType } from "./types/webhook/types";
|
|
291
|
+
|
|
292
|
+
export type { WebhookBody } from "./types/webhook/types";
|
|
293
|
+
|
|
294
|
+
export type { WebhookBodyAPIUpdate } from "./types/webhook/apiUpdate";
|
|
295
|
+
|
|
296
|
+
export type { WebhookBodyTestTrigger } from "./types/webhook/testTrigger";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { castArray } from "./castArray";
|
|
2
|
+
|
|
3
|
+
interface WithFilters {
|
|
4
|
+
filters?: string | string[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Adds one or more filters to an object with a `filters` property.
|
|
9
|
+
* Appended filters are added to the end of the existing list.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - Object to which filters will be append.
|
|
12
|
+
* @param objWithFilters - Object to append filters on the `filters`
|
|
13
|
+
* property.
|
|
14
|
+
* @param filters - One or more filters to append.
|
|
15
|
+
*
|
|
16
|
+
* @returns The object with the appended filters.
|
|
17
|
+
*/
|
|
18
|
+
export const appendFilters = <T extends WithFilters>(
|
|
19
|
+
objWithFilters: T = {} as T,
|
|
20
|
+
filters: string | string[],
|
|
21
|
+
): T & { filters: string[] } => {
|
|
22
|
+
return {
|
|
23
|
+
...objWithFilters,
|
|
24
|
+
filters: [...(objWithFilters.filters || []), ...castArray(filters)],
|
|
25
|
+
};
|
|
26
|
+
};
|
package/src/lib/castArray.ts
CHANGED
package/src/lib/castThunk.ts
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @returns `a` as a a thunk.
|
|
9
9
|
*/
|
|
10
|
-
export const castThunk = <A>(a: A | (() => A)): (() => A) =>
|
|
11
|
-
typeof a === "function" ? (a as () => A) : () => a;
|
|
10
|
+
export const castThunk = <A>(a: A | (() => A)): (() => A) => {
|
|
11
|
+
return typeof a === "function" ? (a as () => A) : () => a;
|
|
12
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { version } from "../../package.json";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* devMsg("missing-param");
|
|
10
|
+
* // => "https://prismic.dev/msg/client/v1.2.3/missing-param.md"
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
14
|
+
* the Git repository's `/messages` directory.
|
|
15
|
+
*
|
|
16
|
+
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
17
|
+
*/
|
|
18
|
+
export const devMsg = (slug: string): string => {
|
|
19
|
+
return `https://prismic.dev/msg/client/v${version}/${slug}`;
|
|
20
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** Core logic from https://github.com/component/escape-html
|
|
3
|
+
** Many thanks to @component
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const matchHtmlRegExp = /["'&<>]/;
|
|
7
|
+
|
|
8
|
+
export const escapeHTML = (string?: string | null): string => {
|
|
9
|
+
const str = "" + string;
|
|
10
|
+
const match = matchHtmlRegExp.exec(str);
|
|
11
|
+
|
|
12
|
+
if (!match) {
|
|
13
|
+
return str;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let escape;
|
|
17
|
+
let html = "";
|
|
18
|
+
let index = 0;
|
|
19
|
+
let lastIndex = 0;
|
|
20
|
+
|
|
21
|
+
for (index = match.index; index < str.length; index++) {
|
|
22
|
+
switch (str.charCodeAt(index)) {
|
|
23
|
+
case 34: // "
|
|
24
|
+
escape = """;
|
|
25
|
+
break;
|
|
26
|
+
case 38: // &
|
|
27
|
+
escape = "&";
|
|
28
|
+
break;
|
|
29
|
+
case 39: // '
|
|
30
|
+
escape = "'";
|
|
31
|
+
break;
|
|
32
|
+
case 60: // <
|
|
33
|
+
escape = "<";
|
|
34
|
+
break;
|
|
35
|
+
case 62: // >
|
|
36
|
+
escape = ">";
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (lastIndex !== index) {
|
|
43
|
+
html += str.substring(lastIndex, index);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
lastIndex = index + 1;
|
|
47
|
+
html += escape;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
51
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { filter } from "../filter";
|
|
2
|
+
|
|
3
|
+
import { castArray } from "./castArray";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a filter to filter content by document tags. All tags are required
|
|
7
|
+
* on the document.
|
|
8
|
+
*
|
|
9
|
+
* @param tags - Document tags to filter queried content.
|
|
10
|
+
*
|
|
11
|
+
* @returns A filter that can be used in a Prismic REST API V2 request.
|
|
12
|
+
*/
|
|
13
|
+
export const everyTagFilter = (tags: string | string[]): string => {
|
|
14
|
+
return filter.at("document.tags", castArray(tags));
|
|
15
|
+
};
|
package/src/lib/findMasterRef.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { findRef } from "./findRef";
|
|
4
4
|
|
|
@@ -10,6 +10,6 @@ import { findRef } from "./findRef";
|
|
|
10
10
|
* @returns The master ref from the list.
|
|
11
11
|
* @throws If a matching ref cannot be found.
|
|
12
12
|
*/
|
|
13
|
-
export const findMasterRef = (refs:
|
|
13
|
+
export const findMasterRef = (refs: Ref[]): Ref => {
|
|
14
14
|
return findRef(refs, (ref) => ref.isMasterRef);
|
|
15
15
|
};
|
package/src/lib/findRef.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
|
-
import { PrismicError } from "../PrismicError";
|
|
3
|
+
import { PrismicError } from "../errors/PrismicError";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Returns the first ref from a list that passes a
|
|
6
|
+
* Returns the first ref from a list that passes a filter (a function that
|
|
7
7
|
* returns true).
|
|
8
8
|
*
|
|
9
9
|
* @param refs - A list of refs to search.
|
|
10
|
-
* @param
|
|
10
|
+
* @param filter - A function that determines if a ref from the list matches
|
|
11
11
|
* the criteria.
|
|
12
12
|
*
|
|
13
13
|
* @returns The first matching ref.
|
|
14
14
|
* @throws If a matching ref cannot be found.
|
|
15
15
|
*/
|
|
16
|
-
export const findRef = (
|
|
17
|
-
refs
|
|
18
|
-
predicate: (ref: prismicT.Ref) => boolean,
|
|
19
|
-
): prismicT.Ref => {
|
|
20
|
-
const ref = refs.find((ref) => predicate(ref));
|
|
16
|
+
export const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {
|
|
17
|
+
const ref = refs.find((ref) => filter(ref));
|
|
21
18
|
|
|
22
19
|
if (!ref) {
|
|
23
20
|
throw new PrismicError("Ref could not be found.", undefined, undefined);
|
package/src/lib/findRefByID.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { findRef } from "./findRef";
|
|
4
4
|
|
|
@@ -11,6 +11,6 @@ import { findRef } from "./findRef";
|
|
|
11
11
|
* @returns The ref with a matching ID from the list.
|
|
12
12
|
* @throws If a matching ref cannot be found.
|
|
13
13
|
*/
|
|
14
|
-
export const findRefByID = (refs:
|
|
14
|
+
export const findRefByID = (refs: Ref[], id: string): Ref => {
|
|
15
15
|
return findRef(refs, (ref) => ref.id === id);
|
|
16
16
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { findRef } from "./findRef";
|
|
4
4
|
|
|
@@ -11,9 +11,6 @@ import { findRef } from "./findRef";
|
|
|
11
11
|
* @returns The ref with a matching label from the list.
|
|
12
12
|
* @throws If a matching ref cannot be found.
|
|
13
13
|
*/
|
|
14
|
-
export const findRefByLabel = (
|
|
15
|
-
refs: prismicT.Ref[],
|
|
16
|
-
label: string,
|
|
17
|
-
): prismicT.Ref => {
|
|
14
|
+
export const findRefByLabel = (refs: Ref[], label: string): Ref => {
|
|
18
15
|
return findRef(refs, (ref) => ref.label === label);
|
|
19
16
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a URL is internal or external.
|
|
3
|
+
*
|
|
4
|
+
* @param url - The URL to check if internal or external.
|
|
5
|
+
*
|
|
6
|
+
* @returns `true` if `url` is internal, `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a "/" or "#"`.
|
|
9
|
+
export const isInternalURL = (url: string): boolean => {
|
|
10
|
+
const isInternal = /^(\/(?!\/)|#)/.test(url);
|
|
11
|
+
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
|
|
12
|
+
|
|
13
|
+
return isInternal && !isSpecialLink;
|
|
14
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { LinkType } from "../types/value/link";
|
|
2
|
+
import {
|
|
3
|
+
RTBlockNode,
|
|
4
|
+
RTEmbedNode,
|
|
5
|
+
RTImageNode,
|
|
6
|
+
RTInlineNode,
|
|
7
|
+
RTLinkNode,
|
|
8
|
+
RTPreformattedNode,
|
|
9
|
+
RichTextNodeType,
|
|
10
|
+
} from "../types/value/richText";
|
|
11
|
+
|
|
12
|
+
import { LinkResolverFunction, asLink } from "../helpers/asLink";
|
|
13
|
+
|
|
14
|
+
import { escapeHTML } from "./escapeHTML";
|
|
15
|
+
|
|
16
|
+
export const getLabel = (node: RTBlockNode | RTInlineNode): string => {
|
|
17
|
+
return "data" in node && "label" in node.data
|
|
18
|
+
? ` class="${node.data.label}"`
|
|
19
|
+
: "";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const serializeStandardTag = (
|
|
23
|
+
tag: string,
|
|
24
|
+
node: RTBlockNode | RTInlineNode,
|
|
25
|
+
children: string[],
|
|
26
|
+
): string => {
|
|
27
|
+
return `<${tag}${getLabel(node)}>${children.join("")}</${tag}>`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const serializePreFormatted = (node: RTPreformattedNode): string => {
|
|
31
|
+
return `<pre${getLabel(node)}>${escapeHTML(node.text)}</pre>`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const serializeImage = (
|
|
35
|
+
linkResolver:
|
|
36
|
+
| LinkResolverFunction<string | null | undefined>
|
|
37
|
+
| undefined
|
|
38
|
+
| null,
|
|
39
|
+
node: RTImageNode,
|
|
40
|
+
): string => {
|
|
41
|
+
let imageTag = `<img src="${node.url}" alt="${escapeHTML(node.alt)}"${
|
|
42
|
+
node.copyright ? ` copyright="${escapeHTML(node.copyright)}"` : ""
|
|
43
|
+
} />`;
|
|
44
|
+
|
|
45
|
+
// If the image has a link, we wrap it with an anchor tag
|
|
46
|
+
if (node.linkTo) {
|
|
47
|
+
imageTag = serializeHyperlink(
|
|
48
|
+
linkResolver,
|
|
49
|
+
{
|
|
50
|
+
type: RichTextNodeType.hyperlink,
|
|
51
|
+
data: node.linkTo,
|
|
52
|
+
start: 0,
|
|
53
|
+
end: 0,
|
|
54
|
+
},
|
|
55
|
+
[imageTag],
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return `<p class="block-img">${imageTag}</p>`;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const serializeEmbed = (node: RTEmbedNode): string => {
|
|
63
|
+
return `<div data-oembed="${node.oembed.embed_url}" data-oembed-type="${
|
|
64
|
+
node.oembed.type
|
|
65
|
+
}" data-oembed-provider="${node.oembed.provider_name}"${getLabel(node)}>${
|
|
66
|
+
node.oembed.html
|
|
67
|
+
}</div>`;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const serializeHyperlink = (
|
|
71
|
+
linkResolver:
|
|
72
|
+
| LinkResolverFunction<string | null | undefined>
|
|
73
|
+
| undefined
|
|
74
|
+
| null,
|
|
75
|
+
node: RTLinkNode,
|
|
76
|
+
children: string[],
|
|
77
|
+
): string => {
|
|
78
|
+
switch (node.data.link_type) {
|
|
79
|
+
case LinkType.Web: {
|
|
80
|
+
return `<a href="${escapeHTML(node.data.url)}" ${
|
|
81
|
+
node.data.target ? `target="${node.data.target}" ` : ""
|
|
82
|
+
}rel="noopener noreferrer"${getLabel(node)}>${children.join("")}</a>`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
case LinkType.Document: {
|
|
86
|
+
return `<a href="${asLink(node.data, linkResolver)}"${getLabel(
|
|
87
|
+
node,
|
|
88
|
+
)}>${children.join("")}</a>`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
case LinkType.Media: {
|
|
92
|
+
return `<a href="${node.data.url}"${getLabel(node)}>${children.join(
|
|
93
|
+
"",
|
|
94
|
+
)}</a>`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const serializeSpan = (content?: string): string => {
|
|
100
|
+
return content ? escapeHTML(content).replace(/\n/g, "<br />") : "";
|
|
101
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { filter } from "../filter";
|
|
2
|
+
|
|
3
|
+
import { castArray } from "./castArray";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a filter to filter content by document tags. At least one matching
|
|
7
|
+
* tag is required on the document.
|
|
8
|
+
*
|
|
9
|
+
* @param tags - Document tags to filter queried content.
|
|
10
|
+
*
|
|
11
|
+
* @returns A filter that can be used in a Prismic REST API V2 request.
|
|
12
|
+
*/
|
|
13
|
+
export const someTagsFilter = (tags: string | string[]): string => {
|
|
14
|
+
return filter.any("document.tags", castArray(tags));
|
|
15
|
+
};
|