@prismicio/client 7.7.2 → 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 +3 -4
- package/dist/lib/hastToRichText.cjs.map +1 -1
- package/dist/lib/hastToRichText.d.ts +4 -4
- package/dist/lib/hastToRichText.js +3 -4
- 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,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
buildPixelDensitySrcSet,
|
|
4
|
-
buildURL,
|
|
5
|
-
} from "imgix-url-builder";
|
|
1
|
+
import type { BuildPixelDensitySrcSetParams } from "imgix-url-builder"
|
|
2
|
+
import { buildPixelDensitySrcSet, buildURL } from "imgix-url-builder"
|
|
6
3
|
|
|
7
|
-
import type { ImageFieldImage } from "../types/value/image"
|
|
4
|
+
import type { ImageFieldImage } from "../types/value/image"
|
|
8
5
|
|
|
9
|
-
import { imageThumbnail as isImageThumbnailFilled } from "./isFilled"
|
|
6
|
+
import { imageThumbnail as isImageThumbnailFilled } from "./isFilled"
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* The default pixel densities used to generate a `srcset` value.
|
|
13
10
|
*/
|
|
14
|
-
const DEFAULT_PIXEL_DENSITIES = [1, 2, 3]
|
|
11
|
+
const DEFAULT_PIXEL_DENSITIES = [1, 2, 3]
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* Configuration for `asImagePixelDensitySrcSet()`.
|
|
@@ -20,7 +17,7 @@ type AsImagePixelDensitySrcSetConfig = Omit<
|
|
|
20
17
|
BuildPixelDensitySrcSetParams,
|
|
21
18
|
"pixelDensities"
|
|
22
19
|
> &
|
|
23
|
-
Partial<Pick<BuildPixelDensitySrcSetParams, "pixelDensities"
|
|
20
|
+
Partial<Pick<BuildPixelDensitySrcSetParams, "pixelDensities">>
|
|
24
21
|
|
|
25
22
|
/**
|
|
26
23
|
* The return type of `asImagePixelDensitySrcSet()`.
|
|
@@ -33,15 +30,15 @@ type AsImagePixelDensitySrcSetReturnType<
|
|
|
33
30
|
/**
|
|
34
31
|
* The image field's image URL with Imgix URL parameters (if given).
|
|
35
32
|
*/
|
|
36
|
-
src: string
|
|
33
|
+
src: string
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* A pixel-densitye-based `srcset` attribute value for the image field's
|
|
40
37
|
* image with Imgix URL parameters (if given).
|
|
41
38
|
*/
|
|
42
|
-
srcset: string
|
|
39
|
+
srcset: string
|
|
43
40
|
}
|
|
44
|
-
: null
|
|
41
|
+
: null
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
44
|
* Creates a pixel-density-based `srcset` from an image field with optional
|
|
@@ -56,7 +53,7 @@ type AsImagePixelDensitySrcSetReturnType<
|
|
|
56
53
|
* const srcset = asImagePixelDensitySrcSet(document.data.imageField, {
|
|
57
54
|
* pixelDensities: [1, 2],
|
|
58
55
|
* sat: -100,
|
|
59
|
-
* })
|
|
56
|
+
* })
|
|
60
57
|
* // => {
|
|
61
58
|
* // src: 'https://images.prismic.io/repo/image.png?sat=-100',
|
|
62
59
|
* // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, ' +
|
|
@@ -83,7 +80,7 @@ export const asImagePixelDensitySrcSet = <
|
|
|
83
80
|
if (field && isImageThumbnailFilled(field)) {
|
|
84
81
|
// We are using destructuring to omit `pixelDensities` from the
|
|
85
82
|
// object we will pass to `buildURL()`.
|
|
86
|
-
const { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config
|
|
83
|
+
const { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config
|
|
87
84
|
|
|
88
85
|
return {
|
|
89
86
|
src: buildURL(field.url, imgixParams),
|
|
@@ -91,8 +88,8 @@ export const asImagePixelDensitySrcSet = <
|
|
|
91
88
|
...imgixParams,
|
|
92
89
|
pixelDensities,
|
|
93
90
|
}),
|
|
94
|
-
} as AsImagePixelDensitySrcSetReturnType<Field
|
|
91
|
+
} as AsImagePixelDensitySrcSetReturnType<Field>
|
|
95
92
|
} else {
|
|
96
|
-
return null as AsImagePixelDensitySrcSetReturnType<Field
|
|
93
|
+
return null as AsImagePixelDensitySrcSetReturnType<Field>
|
|
97
94
|
}
|
|
98
|
-
}
|
|
95
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { ImgixURLParams
|
|
1
|
+
import type { ImgixURLParams } from "imgix-url-builder"
|
|
2
|
+
import { buildURL } from "imgix-url-builder"
|
|
2
3
|
|
|
3
|
-
import type { ImageFieldImage } from "../types/value/image"
|
|
4
|
+
import type { ImageFieldImage } from "../types/value/image"
|
|
4
5
|
|
|
5
|
-
import { imageThumbnail as isImageThumbnailFilled } from "./isFilled"
|
|
6
|
+
import { imageThumbnail as isImageThumbnailFilled } from "./isFilled"
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The return type of `asImageSrc()`.
|
|
9
10
|
*/
|
|
10
11
|
type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =
|
|
11
|
-
Field extends ImageFieldImage<"filled"> ? string : null
|
|
12
|
+
Field extends ImageFieldImage<"filled"> ? string : null
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Returns the URL of an image field with optional image transformations (via
|
|
@@ -17,7 +18,7 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =
|
|
|
17
18
|
* @example
|
|
18
19
|
*
|
|
19
20
|
* ```ts
|
|
20
|
-
* const src = asImageSrc(document.data.imageField, { sat: -100 })
|
|
21
|
+
* const src = asImageSrc(document.data.imageField, { sat: -100 })
|
|
21
22
|
* // => https://images.prismic.io/repo/image.png?sat=-100
|
|
22
23
|
* ```
|
|
23
24
|
*
|
|
@@ -35,8 +36,8 @@ export const asImageSrc = <Field extends ImageFieldImage | null | undefined>(
|
|
|
35
36
|
config: ImgixURLParams = {},
|
|
36
37
|
): AsImageSrcReturnType<Field> => {
|
|
37
38
|
if (field && isImageThumbnailFilled(field)) {
|
|
38
|
-
return buildURL(field.url, config) as AsImageSrcReturnType<Field
|
|
39
|
+
return buildURL(field.url, config) as AsImageSrcReturnType<Field>
|
|
39
40
|
} else {
|
|
40
|
-
return null as AsImageSrcReturnType<Field
|
|
41
|
+
return null as AsImageSrcReturnType<Field>
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
+
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
buildURL,
|
|
4
|
-
buildWidthSrcSet,
|
|
5
|
-
} from "imgix-url-builder";
|
|
1
|
+
import type { BuildWidthSrcSetParams } from "imgix-url-builder"
|
|
2
|
+
import { buildURL, buildWidthSrcSet } from "imgix-url-builder"
|
|
6
3
|
|
|
7
|
-
import type { ImageFieldImage } from "../types/value/image"
|
|
4
|
+
import type { ImageFieldImage } from "../types/value/image"
|
|
8
5
|
|
|
9
|
-
import * as isFilled from "./isFilled"
|
|
6
|
+
import * as isFilled from "./isFilled"
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* The default widths used to generate a `srcset` value.
|
|
13
10
|
*/
|
|
14
|
-
const DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]
|
|
11
|
+
const DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* The return type of `asImageWidthSrcSet()`.
|
|
@@ -24,22 +21,22 @@ type AsImageWidthSrcSetReturnType<
|
|
|
24
21
|
/**
|
|
25
22
|
* The image field's image URL with Imgix URL parameters (if given).
|
|
26
23
|
*/
|
|
27
|
-
src: string
|
|
24
|
+
src: string
|
|
28
25
|
|
|
29
26
|
/**
|
|
30
27
|
* A width-based `srcset` attribute value for the image field's image
|
|
31
28
|
* with Imgix URL parameters (if given).
|
|
32
29
|
*/
|
|
33
|
-
srcset: string
|
|
30
|
+
srcset: string
|
|
34
31
|
}
|
|
35
|
-
: null
|
|
32
|
+
: null
|
|
36
33
|
|
|
37
34
|
/**
|
|
38
35
|
* Configuration for `asImageWidthSrcSet()`.
|
|
39
36
|
*/
|
|
40
37
|
type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
41
|
-
widths?: "thumbnails" | BuildWidthSrcSetParams["widths"]
|
|
42
|
-
}
|
|
38
|
+
widths?: "thumbnails" | BuildWidthSrcSetParams["widths"]
|
|
39
|
+
}
|
|
43
40
|
|
|
44
41
|
/**
|
|
45
42
|
* Creates a width-based `srcset` from an image field with optional image
|
|
@@ -58,7 +55,7 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
|
58
55
|
* const srcset = asImageWidthSrcSet(document.data.imageField, {
|
|
59
56
|
* widths: [400, 800, 1600],
|
|
60
57
|
* sat: -100,
|
|
61
|
-
* })
|
|
58
|
+
* })
|
|
62
59
|
* // => {
|
|
63
60
|
* // src: 'https://images.prismic.io/repo/image.png?sat=-100',
|
|
64
61
|
* // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, ' +
|
|
@@ -91,7 +88,7 @@ export const asImageWidthSrcSet = <
|
|
|
91
88
|
widths = DEFAULT_WIDTHS,
|
|
92
89
|
// eslint-disable-next-line prefer-const
|
|
93
90
|
...imgixParams
|
|
94
|
-
} = config
|
|
91
|
+
} = config
|
|
95
92
|
const {
|
|
96
93
|
url,
|
|
97
94
|
dimensions,
|
|
@@ -100,18 +97,18 @@ export const asImageWidthSrcSet = <
|
|
|
100
97
|
copyright: _copyright,
|
|
101
98
|
edit: _edit,
|
|
102
99
|
...responsiveViews
|
|
103
|
-
} = field
|
|
100
|
+
} = field
|
|
104
101
|
|
|
105
102
|
// The Prismic Rest API will always return thumbnail values if
|
|
106
103
|
// the base size is filled.
|
|
107
104
|
const responsiveViewObjects: ImageFieldImage<"filled">[] =
|
|
108
|
-
Object.values(responsiveViews)
|
|
105
|
+
Object.values(responsiveViews)
|
|
109
106
|
|
|
110
107
|
// If this `asImageWidthSrcSet()` call is configured to use
|
|
111
108
|
// thumbnail widths, but the field does not have thumbnails, we
|
|
112
109
|
// fall back to the default set of widths.
|
|
113
110
|
if (widths === "thumbnails" && responsiveViewObjects.length < 1) {
|
|
114
|
-
widths = DEFAULT_WIDTHS
|
|
111
|
+
widths = DEFAULT_WIDTHS
|
|
115
112
|
}
|
|
116
113
|
|
|
117
114
|
return {
|
|
@@ -129,15 +126,15 @@ export const asImageWidthSrcSet = <
|
|
|
129
126
|
return buildWidthSrcSet(thumbnail.url, {
|
|
130
127
|
...imgixParams,
|
|
131
128
|
widths: [thumbnail.dimensions.width],
|
|
132
|
-
})
|
|
129
|
+
})
|
|
133
130
|
}),
|
|
134
131
|
].join(", ")
|
|
135
132
|
: buildWidthSrcSet(field.url, {
|
|
136
133
|
...imgixParams,
|
|
137
134
|
widths,
|
|
138
135
|
}),
|
|
139
|
-
} as AsImageWidthSrcSetReturnType<Field
|
|
136
|
+
} as AsImageWidthSrcSetReturnType<Field>
|
|
140
137
|
} else {
|
|
141
|
-
return null as AsImageWidthSrcSetReturnType<Field
|
|
138
|
+
return null as AsImageWidthSrcSetReturnType<Field>
|
|
142
139
|
}
|
|
143
|
-
}
|
|
140
|
+
}
|
package/src/helpers/asLink.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { FilledContentRelationshipField } from "../types/value/contentRelationship"
|
|
2
|
-
import type { PrismicDocument } from "../types/value/document"
|
|
3
|
-
import { FilledLinkToWebField, LinkField
|
|
4
|
-
import
|
|
1
|
+
import type { FilledContentRelationshipField } from "../types/value/contentRelationship"
|
|
2
|
+
import type { PrismicDocument } from "../types/value/document"
|
|
3
|
+
import type { FilledLinkToWebField, LinkField } from "../types/value/link"
|
|
4
|
+
import { LinkType } from "../types/value/link"
|
|
5
|
+
import type { FilledLinkToMediaField } from "../types/value/linkToMedia"
|
|
5
6
|
|
|
6
|
-
import { documentToLinkField } from "./documentToLinkField"
|
|
7
|
+
import { documentToLinkField } from "./documentToLinkField"
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Resolves a link to a Prismic document to a URL
|
|
@@ -19,7 +20,7 @@ import { documentToLinkField } from "./documentToLinkField";
|
|
|
19
20
|
*/
|
|
20
21
|
export type LinkResolverFunction<ReturnType = string | null | undefined> = (
|
|
21
22
|
linkToDocumentField: FilledContentRelationshipField,
|
|
22
|
-
) => ReturnType
|
|
23
|
+
) => ReturnType
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Configuration that determines the output of `asLink()`.
|
|
@@ -30,8 +31,8 @@ type AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =
|
|
|
30
31
|
* An optional link resolver function. Without it, you are expected to use
|
|
31
32
|
* the `routes` options from the API.
|
|
32
33
|
*/
|
|
33
|
-
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null
|
|
34
|
-
}
|
|
34
|
+
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null
|
|
35
|
+
}
|
|
35
36
|
|
|
36
37
|
// TODO: Remove when we remove support for deprecated tuple-style configuration.
|
|
37
38
|
/**
|
|
@@ -39,9 +40,7 @@ type AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =
|
|
|
39
40
|
*/
|
|
40
41
|
type AsLinkDeprecatedTupleConfig<
|
|
41
42
|
LinkResolverFunctionReturnType = string | null | undefined,
|
|
42
|
-
> = [
|
|
43
|
-
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null,
|
|
44
|
-
];
|
|
43
|
+
> = [linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null]
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
46
|
* The return type of `asLink()`.
|
|
@@ -59,7 +58,7 @@ export type AsLinkReturnType<
|
|
|
59
58
|
| FilledContentRelationshipField
|
|
60
59
|
| PrismicDocument
|
|
61
60
|
? LinkResolverFunctionReturnType | string | null
|
|
62
|
-
: null
|
|
61
|
+
: null
|
|
63
62
|
|
|
64
63
|
// TODO: Remove overload when we remove support for deprecated tuple-style configuration.
|
|
65
64
|
export const asLink: {
|
|
@@ -90,7 +89,7 @@ export const asLink: {
|
|
|
90
89
|
>(
|
|
91
90
|
linkFieldOrDocument: Field,
|
|
92
91
|
config?: AsLinkConfig<LinkResolverFunctionReturnType>,
|
|
93
|
-
): AsLinkReturnType<LinkResolverFunctionReturnType, Field
|
|
92
|
+
): AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
94
93
|
|
|
95
94
|
/**
|
|
96
95
|
* Resolves any type of link field or Prismic document to a URL.
|
|
@@ -122,7 +121,7 @@ export const asLink: {
|
|
|
122
121
|
>(
|
|
123
122
|
linkFieldOrDocument: Field,
|
|
124
123
|
...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>
|
|
125
|
-
): AsLinkReturnType<LinkResolverFunctionReturnType, Field
|
|
124
|
+
): AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
126
125
|
} = <
|
|
127
126
|
LinkResolverFunctionReturnType = string | null | undefined,
|
|
128
127
|
Field extends LinkField | PrismicDocument | null | undefined =
|
|
@@ -138,7 +137,7 @@ export const asLink: {
|
|
|
138
137
|
| AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>
|
|
139
138
|
): AsLinkReturnType<LinkResolverFunctionReturnType, Field> => {
|
|
140
139
|
if (!linkFieldOrDocument) {
|
|
141
|
-
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field
|
|
140
|
+
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
// Converts document to link field if needed
|
|
@@ -151,20 +150,20 @@ export const asLink: {
|
|
|
151
150
|
"link_type" in linkFieldOrDocument
|
|
152
151
|
? linkFieldOrDocument
|
|
153
152
|
: documentToLinkField(linkFieldOrDocument)
|
|
154
|
-
) as LinkField
|
|
153
|
+
) as LinkField
|
|
155
154
|
|
|
156
155
|
// TODO: Remove when we remove support for deprecated tuple-style configuration.
|
|
157
|
-
const [configObjectOrLinkResolver] = configObjectOrTuple
|
|
158
|
-
let config: AsLinkConfig<LinkResolverFunctionReturnType
|
|
156
|
+
const [configObjectOrLinkResolver] = configObjectOrTuple
|
|
157
|
+
let config: AsLinkConfig<LinkResolverFunctionReturnType>
|
|
159
158
|
if (
|
|
160
159
|
typeof configObjectOrLinkResolver === "function" ||
|
|
161
160
|
configObjectOrLinkResolver == null
|
|
162
161
|
) {
|
|
163
162
|
config = {
|
|
164
163
|
linkResolver: configObjectOrLinkResolver,
|
|
165
|
-
}
|
|
164
|
+
}
|
|
166
165
|
} else {
|
|
167
|
-
config = { ...configObjectOrLinkResolver }
|
|
166
|
+
config = { ...configObjectOrLinkResolver }
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
switch (linkField.link_type) {
|
|
@@ -173,18 +172,18 @@ export const asLink: {
|
|
|
173
172
|
return ("url" in linkField ? linkField.url : null) as AsLinkReturnType<
|
|
174
173
|
LinkResolverFunctionReturnType,
|
|
175
174
|
Field
|
|
176
|
-
|
|
175
|
+
>
|
|
177
176
|
|
|
178
177
|
case LinkType.Document: {
|
|
179
178
|
if ("id" in linkField && config.linkResolver) {
|
|
180
179
|
// When using link resolver...
|
|
181
|
-
const resolvedURL = config.linkResolver(linkField)
|
|
180
|
+
const resolvedURL = config.linkResolver(linkField)
|
|
182
181
|
|
|
183
182
|
if (resolvedURL != null) {
|
|
184
183
|
return resolvedURL as AsLinkReturnType<
|
|
185
184
|
LinkResolverFunctionReturnType,
|
|
186
185
|
Field
|
|
187
|
-
|
|
186
|
+
>
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
189
|
|
|
@@ -193,15 +192,15 @@ export const asLink: {
|
|
|
193
192
|
return linkField.url as AsLinkReturnType<
|
|
194
193
|
LinkResolverFunctionReturnType,
|
|
195
194
|
Field
|
|
196
|
-
|
|
195
|
+
>
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
// When empty or link resolver and route resolver are not used...
|
|
200
|
-
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field
|
|
199
|
+
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
201
200
|
}
|
|
202
201
|
|
|
203
202
|
case LinkType.Any:
|
|
204
203
|
default:
|
|
205
|
-
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field
|
|
204
|
+
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
206
205
|
}
|
|
207
|
-
}
|
|
206
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { isInternalURL } from "../lib/isInternalURL"
|
|
1
|
+
import { isInternalURL } from "../lib/isInternalURL"
|
|
2
2
|
|
|
3
|
-
import type { FilledContentRelationshipField } from "../types/value/contentRelationship"
|
|
4
|
-
import type { PrismicDocument } from "../types/value/document"
|
|
5
|
-
import { FilledLinkToWebField, LinkField } from "../types/value/link"
|
|
6
|
-
import type { FilledLinkToMediaField } from "../types/value/linkToMedia"
|
|
3
|
+
import type { FilledContentRelationshipField } from "../types/value/contentRelationship"
|
|
4
|
+
import type { PrismicDocument } from "../types/value/document"
|
|
5
|
+
import type { FilledLinkToWebField, LinkField } from "../types/value/link"
|
|
6
|
+
import type { FilledLinkToMediaField } from "../types/value/linkToMedia"
|
|
7
7
|
|
|
8
|
-
import { AsLinkReturnType, LinkResolverFunction
|
|
9
|
-
import {
|
|
8
|
+
import type { AsLinkReturnType, LinkResolverFunction } from "./asLink"
|
|
9
|
+
import { asLink } from "./asLink"
|
|
10
|
+
import { link as isFilledLink } from "./isFilled"
|
|
10
11
|
|
|
11
12
|
type AsLinkAttrsConfigRelArgs<
|
|
12
13
|
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
|
@@ -18,10 +19,10 @@ type AsLinkAttrsConfigRelArgs<
|
|
|
18
19
|
> = {
|
|
19
20
|
href:
|
|
20
21
|
| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>
|
|
21
|
-
| undefined
|
|
22
|
-
isExternal: boolean
|
|
23
|
-
target?: string
|
|
24
|
-
}
|
|
22
|
+
| undefined
|
|
23
|
+
isExternal: boolean
|
|
24
|
+
target?: string
|
|
25
|
+
}
|
|
25
26
|
|
|
26
27
|
export type AsLinkAttrsConfig<
|
|
27
28
|
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
|
@@ -31,11 +32,11 @@ export type AsLinkAttrsConfig<
|
|
|
31
32
|
| null
|
|
32
33
|
| undefined,
|
|
33
34
|
> = {
|
|
34
|
-
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType
|
|
35
|
+
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType>
|
|
35
36
|
rel?: (
|
|
36
37
|
args: AsLinkAttrsConfigRelArgs<LinkResolverFunctionReturnType, Field>,
|
|
37
|
-
) => string | undefined | void
|
|
38
|
-
}
|
|
38
|
+
) => string | undefined | void
|
|
39
|
+
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* The return type of `asLinkAttrs()`.
|
|
@@ -55,15 +56,15 @@ type AsLinkAttrsReturnType<
|
|
|
55
56
|
? {
|
|
56
57
|
href:
|
|
57
58
|
| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>
|
|
58
|
-
| undefined
|
|
59
|
-
target?: string
|
|
60
|
-
rel?: string
|
|
59
|
+
| undefined
|
|
60
|
+
target?: string
|
|
61
|
+
rel?: string
|
|
61
62
|
}
|
|
62
63
|
: {
|
|
63
|
-
href?: undefined
|
|
64
|
-
target?: undefined
|
|
65
|
-
rel?: undefined
|
|
66
|
-
}
|
|
64
|
+
href?: undefined
|
|
65
|
+
target?: undefined
|
|
66
|
+
rel?: undefined
|
|
67
|
+
}
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Resolves any type of link field or Prismic document to a set of link
|
|
@@ -109,26 +110,26 @@ export const asLinkAttrs = <
|
|
|
109
110
|
const target =
|
|
110
111
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
111
112
|
// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
|
|
112
|
-
"target" in linkFieldOrDocument ? linkFieldOrDocument.target : undefined
|
|
113
|
+
"target" in linkFieldOrDocument ? linkFieldOrDocument.target : undefined
|
|
113
114
|
|
|
114
|
-
const rawHref = asLink(linkFieldOrDocument, config.linkResolver)
|
|
115
|
+
const rawHref = asLink(linkFieldOrDocument, config.linkResolver)
|
|
115
116
|
const href =
|
|
116
|
-
rawHref == null ? undefined : (rawHref as NonNullable<typeof rawHref>)
|
|
117
|
+
rawHref == null ? undefined : (rawHref as NonNullable<typeof rawHref>)
|
|
117
118
|
|
|
118
|
-
const isExternal = typeof href === "string" ? !isInternalURL(href) : false
|
|
119
|
+
const isExternal = typeof href === "string" ? !isInternalURL(href) : false
|
|
119
120
|
|
|
120
121
|
const rel = config.rel
|
|
121
122
|
? config.rel({ href, isExternal, target })
|
|
122
123
|
: isExternal
|
|
123
124
|
? "noreferrer"
|
|
124
|
-
: undefined
|
|
125
|
+
: undefined
|
|
125
126
|
|
|
126
127
|
return {
|
|
127
128
|
href,
|
|
128
129
|
target,
|
|
129
130
|
rel: rel == null ? undefined : rel,
|
|
130
|
-
}
|
|
131
|
+
}
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
return {}
|
|
134
|
-
}
|
|
134
|
+
return {}
|
|
135
|
+
}
|
package/src/helpers/asText.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RichTextField } from "../types/value/richText"
|
|
1
|
+
import type { RichTextField } from "../types/value/richText"
|
|
2
2
|
|
|
3
|
-
import { asText as baseAsText } from "../richtext/asText"
|
|
3
|
+
import { asText as baseAsText } from "../richtext/asText"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Configuration that determines the output of `asText()`.
|
|
@@ -11,20 +11,20 @@ type AsTextConfig = {
|
|
|
11
11
|
*
|
|
12
12
|
* @defaultValue ` ` (a space)
|
|
13
13
|
*/
|
|
14
|
-
separator?: string
|
|
15
|
-
}
|
|
14
|
+
separator?: string
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
// TODO: Remove when we remove support for deprecated tuple-style configuration.
|
|
18
18
|
/**
|
|
19
19
|
* @deprecated Use object-style configuration instead.
|
|
20
20
|
*/
|
|
21
|
-
type AsTextDeprecatedTupleConfig = [separator?: string]
|
|
21
|
+
type AsTextDeprecatedTupleConfig = [separator?: string]
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* The return type of `asText()`.
|
|
25
25
|
*/
|
|
26
26
|
type AsTextReturnType<Field extends RichTextField | null | undefined> =
|
|
27
|
-
Field extends RichTextField ? string : null
|
|
27
|
+
Field extends RichTextField ? string : null
|
|
28
28
|
|
|
29
29
|
export const asText: {
|
|
30
30
|
/**
|
|
@@ -40,7 +40,7 @@ export const asText: {
|
|
|
40
40
|
<Field extends RichTextField | null | undefined>(
|
|
41
41
|
richTextField: Field,
|
|
42
42
|
config?: AsTextConfig,
|
|
43
|
-
): AsTextReturnType<Field
|
|
43
|
+
): AsTextReturnType<Field>
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Serializes a rich text or title field to a plain text string.
|
|
@@ -57,7 +57,7 @@ export const asText: {
|
|
|
57
57
|
<Field extends RichTextField | null | undefined>(
|
|
58
58
|
richTextField: Field,
|
|
59
59
|
...config: AsTextDeprecatedTupleConfig
|
|
60
|
-
): AsTextReturnType<Field
|
|
60
|
+
): AsTextReturnType<Field>
|
|
61
61
|
} = <Field extends RichTextField | null | undefined>(
|
|
62
62
|
richTextField: Field,
|
|
63
63
|
// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.
|
|
@@ -65,21 +65,21 @@ export const asText: {
|
|
|
65
65
|
): AsTextReturnType<Field> => {
|
|
66
66
|
if (richTextField) {
|
|
67
67
|
// TODO: Remove when we remove support for deprecated tuple-style configuration.
|
|
68
|
-
const [configObjectOrSeparator] = configObjectOrTuple
|
|
69
|
-
let config: AsTextConfig
|
|
68
|
+
const [configObjectOrSeparator] = configObjectOrTuple
|
|
69
|
+
let config: AsTextConfig
|
|
70
70
|
if (typeof configObjectOrSeparator === "string") {
|
|
71
71
|
config = {
|
|
72
72
|
separator: configObjectOrSeparator,
|
|
73
|
-
}
|
|
73
|
+
}
|
|
74
74
|
} else {
|
|
75
|
-
config = { ...configObjectOrSeparator }
|
|
75
|
+
config = { ...configObjectOrSeparator }
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
return baseAsText(
|
|
79
79
|
richTextField,
|
|
80
80
|
config.separator,
|
|
81
|
-
) as AsTextReturnType<Field
|
|
81
|
+
) as AsTextReturnType<Field>
|
|
82
82
|
} else {
|
|
83
|
-
return null as AsTextReturnType<Field
|
|
83
|
+
return null as AsTextReturnType<Field>
|
|
84
84
|
}
|
|
85
|
-
}
|
|
85
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { FilledContentRelationshipField } from "../types/value/contentRelationship"
|
|
2
|
-
import type { PrismicDocument } from "../types/value/document"
|
|
3
|
-
import { LinkType } from "../types/value/link"
|
|
1
|
+
import type { FilledContentRelationshipField } from "../types/value/contentRelationship"
|
|
2
|
+
import type { PrismicDocument } from "../types/value/document"
|
|
3
|
+
import { LinkType } from "../types/value/link"
|
|
4
4
|
|
|
5
5
|
type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> &
|
|
6
|
-
Partial<Pick<T, Keys
|
|
6
|
+
Partial<Pick<T, Keys>>
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Converts a document into a link field, this is useful when crawling the API
|
|
@@ -45,5 +45,5 @@ export const documentToLinkField = <
|
|
|
45
45
|
...(prismicDocument.data && Object.keys(prismicDocument.data).length > 0
|
|
46
46
|
? { data: prismicDocument.data }
|
|
47
47
|
: {}),
|
|
48
|
-
}
|
|
49
|
-
}
|
|
48
|
+
}
|
|
49
|
+
}
|