@prismicio/client 7.20.2-alpha.0 → 7.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WriteClient.cjs +22 -18
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.js +22 -18
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +29 -21
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +11 -8
- package/dist/createClient.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +9 -2
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +11 -4
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +34 -26
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +16 -15
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +11 -10
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +18 -17
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +32 -31
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +6 -9
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +20 -10
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/isFilled.cjs +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +14 -13
- package/dist/helpers/isFilled.js +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +10 -10
- package/dist/helpers/mapSliceZone.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.d.ts +2 -2
- package/dist/isRepositoryEndpoint.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 +5 -5
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +8 -8
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +6 -6
- package/dist/richtext/types.js.map +1 -1
- package/package.json +1 -1
- package/src/WriteClient.ts +32 -21
- package/src/buildQueryURL.ts +29 -21
- package/src/createClient.ts +11 -8
- package/src/getRepositoryEndpoint.ts +9 -2
- package/src/helpers/asDate.ts +11 -4
- package/src/helpers/asHTML.ts +34 -26
- package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
- package/src/helpers/asImageSrc.ts +11 -10
- package/src/helpers/asImageWidthSrcSet.ts +18 -17
- package/src/helpers/asLink.ts +33 -32
- package/src/helpers/asLinkAttrs.ts +6 -9
- package/src/helpers/asText.ts +20 -10
- package/src/helpers/isFilled.ts +15 -14
- package/src/helpers/mapSliceZone.ts +10 -10
- package/src/index.ts +1 -1
- package/src/isRepositoryEndpoint.ts +2 -2
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/serialize.ts +8 -8
- package/src/richtext/types.ts +6 -6
package/src/createClient.ts
CHANGED
|
@@ -14,26 +14,29 @@ export interface CreateClient {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Creates a Prismic client that can be used to query a repository.
|
|
17
|
+
* Creates a Prismic client that can be used to query content from a repository.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
*
|
|
21
21
|
* ```ts
|
|
22
|
-
* // With a repository name
|
|
23
|
-
* createClient("
|
|
22
|
+
* // With a repository name
|
|
23
|
+
* createClient("my-repo")
|
|
24
24
|
*
|
|
25
|
-
* //
|
|
26
|
-
* createClient("https://
|
|
25
|
+
* // With a full Prismic Content API endpoint
|
|
26
|
+
* createClient("https://my-repo.cdn.prismic.io/api/v2")
|
|
27
27
|
* ```
|
|
28
28
|
*
|
|
29
|
-
* @typeParam TDocuments - A union of Prismic
|
|
29
|
+
* @typeParam TDocuments - A union of Prismic page and custom types for the
|
|
30
|
+
* repository.
|
|
30
31
|
*
|
|
31
|
-
* @param repositoryNameOrEndpoint - The Prismic repository name or full
|
|
32
|
-
* API
|
|
32
|
+
* @param repositoryNameOrEndpoint - The Prismic repository name or full Content
|
|
33
|
+
* API endpoint for the repository.
|
|
33
34
|
* @param options - Configuration that determines how content will be queried
|
|
34
35
|
* from the Prismic repository.
|
|
35
36
|
*
|
|
36
37
|
* @returns A client that can query content from the repository.
|
|
38
|
+
*
|
|
39
|
+
* @see @prismicio/client technical reference: {@link https://prismic.io/docs/technical-reference/prismicio-client/v7}
|
|
37
40
|
*/
|
|
38
41
|
export const createClient: CreateClient = <TDocuments extends PrismicDocument>(
|
|
39
42
|
repositoryNameOrEndpoint: string,
|
|
@@ -3,13 +3,20 @@ import { PrismicError } from "./errors/PrismicError"
|
|
|
3
3
|
import { isRepositoryName } from "./isRepositoryName"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Get a repository's Prismic
|
|
6
|
+
* Get a repository's Prismic Content API endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* getRepositoryEndpoint("my-repo")
|
|
12
|
+
* // => "https://my-repo.cdn.prismic.io/api/v2"
|
|
13
|
+
* ```
|
|
7
14
|
*
|
|
8
15
|
* @typeParam RepositoryName - Name of the Prismic repository.
|
|
9
16
|
*
|
|
10
17
|
* @param repositoryName - Name of the repository.
|
|
11
18
|
*
|
|
12
|
-
* @returns The repository's Prismic
|
|
19
|
+
* @returns The repository's Prismic Content API endpoint.
|
|
13
20
|
*
|
|
14
21
|
* @throws {@link Error} Thrown if an invalid repository name is provided.
|
|
15
22
|
*/
|
package/src/helpers/asDate.ts
CHANGED
|
@@ -9,13 +9,20 @@ type AsDateReturnType<
|
|
|
9
9
|
> = Field extends DateField<"filled"> | TimestampField<"filled"> ? Date : null
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Converts a date or timestamp field to a JavaScript Date object.
|
|
13
13
|
*
|
|
14
|
-
* @
|
|
14
|
+
* @example
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const date = asDate(document.data.release_date)
|
|
18
|
+
* // => Date object or null
|
|
19
|
+
* ```
|
|
17
20
|
*
|
|
18
|
-
* @
|
|
21
|
+
* @param dateOrTimestampField - A date or timestamp field from Prismic.
|
|
22
|
+
*
|
|
23
|
+
* @returns A Date object, or `null` if the field is empty.
|
|
24
|
+
*
|
|
25
|
+
* @see Learn about date and timestamp fields: {@link https://prismic.io/docs/fields/date}
|
|
19
26
|
*/
|
|
20
27
|
export const asDate = <
|
|
21
28
|
Field extends DateField | TimestampField | null | undefined,
|
package/src/helpers/asHTML.ts
CHANGED
|
@@ -19,13 +19,13 @@ import { composeSerializers, serialize, wrapMapSerializer } from "../richtext"
|
|
|
19
19
|
import type { LinkResolverFunction } from "./asLink"
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Serializes a node from a rich text
|
|
22
|
+
* Serializes a node from a rich text field with a function to HTML.
|
|
23
23
|
*
|
|
24
24
|
* Unlike a typical `@prismicio/client/richtext` function serializer, this
|
|
25
25
|
* serializer converts the `children` argument to a single string rather than an
|
|
26
26
|
* array of strings.
|
|
27
27
|
*
|
|
28
|
-
* @see
|
|
28
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
29
29
|
*/
|
|
30
30
|
export type HTMLRichTextFunctionSerializer = (
|
|
31
31
|
type: Parameters<RichTextFunctionSerializer<string>>[0],
|
|
@@ -36,13 +36,13 @@ export type HTMLRichTextFunctionSerializer = (
|
|
|
36
36
|
) => string | null | undefined
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Serializes a node from a rich text
|
|
39
|
+
* Serializes a node from a rich text field with a map to HTML.
|
|
40
40
|
*
|
|
41
41
|
* Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
|
|
42
42
|
* converts the `children` property to a single string rather than an array of
|
|
43
43
|
* strings and accepts shorthand declarations.
|
|
44
44
|
*
|
|
45
|
-
* @see
|
|
45
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
46
46
|
*/
|
|
47
47
|
export type HTMLRichTextMapSerializer = {
|
|
48
48
|
[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>["span"]
|
|
@@ -51,13 +51,13 @@ export type HTMLRichTextMapSerializer = {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Serializes a node from a rich text
|
|
54
|
+
* Serializes a node from a rich text field with a map to HTML.
|
|
55
55
|
*
|
|
56
56
|
* Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
|
|
57
57
|
* converts the `children` property to a single string rather than an array of
|
|
58
58
|
* strings but doesn't accept shorthand declarations.
|
|
59
59
|
*
|
|
60
|
-
* @see
|
|
60
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
61
61
|
*/
|
|
62
62
|
export type HTMLStrictRichTextMapSerializer = {
|
|
63
63
|
[P in keyof RichTextMapSerializer<string>]: (payload: {
|
|
@@ -135,11 +135,10 @@ export type HTMLRichTextMapSerializerShorthand = {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
* Serializes a node from a rich text
|
|
139
|
-
* HTML
|
|
138
|
+
* Serializes a node from a rich text field with a map or a function to HTML.
|
|
140
139
|
*
|
|
141
140
|
* @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}
|
|
142
|
-
* @see
|
|
141
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
143
142
|
*/
|
|
144
143
|
export type HTMLRichTextSerializer =
|
|
145
144
|
| HTMLRichTextMapSerializer
|
|
@@ -291,14 +290,14 @@ const wrapMapSerializerWithStringChildren = (
|
|
|
291
290
|
*/
|
|
292
291
|
type AsHTMLConfig = {
|
|
293
292
|
/**
|
|
294
|
-
* An optional link resolver function to resolve links. Without it you're
|
|
295
|
-
* expected to use the `routes`
|
|
293
|
+
* An optional link resolver function to resolve links. Without it, you're
|
|
294
|
+
* expected to use the `routes` option from the API.
|
|
296
295
|
*/
|
|
297
296
|
linkResolver?: LinkResolverFunction | null
|
|
298
297
|
|
|
299
298
|
/**
|
|
300
|
-
* An optional rich text serializer
|
|
301
|
-
* default serializer
|
|
299
|
+
* An optional rich text serializer. Unhandled cases will fall back to the
|
|
300
|
+
* default serializer.
|
|
302
301
|
*/
|
|
303
302
|
serializer?: HTMLRichTextSerializer | null
|
|
304
303
|
}
|
|
@@ -321,14 +320,22 @@ type AsHTMLReturnType<Field extends RichTextField | null | undefined> =
|
|
|
321
320
|
// TODO: Remove overload when we remove support for deprecated tuple-style configuration.
|
|
322
321
|
export const asHTML: {
|
|
323
322
|
/**
|
|
324
|
-
*
|
|
323
|
+
* Converts a rich text field to an HTML string.
|
|
325
324
|
*
|
|
326
|
-
* @
|
|
327
|
-
* @param config - Configuration that determines the output of `asHTML()`
|
|
325
|
+
* @example
|
|
328
326
|
*
|
|
329
|
-
*
|
|
327
|
+
* ```ts
|
|
328
|
+
* const html = asHTML(document.data.content)
|
|
329
|
+
* // => "<p>Hello world</p>"
|
|
330
|
+
* ```
|
|
330
331
|
*
|
|
331
|
-
* @
|
|
332
|
+
* @param richTextField - A rich text field from Prismic.
|
|
333
|
+
* @param config - Configuration that determines the output of `asHTML()`.
|
|
334
|
+
*
|
|
335
|
+
* @returns HTML equivalent of the rich text field, or `null` if the field is
|
|
336
|
+
* empty.
|
|
337
|
+
*
|
|
338
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
332
339
|
*/
|
|
333
340
|
<Field extends RichTextField | null | undefined>(
|
|
334
341
|
richTextField: Field,
|
|
@@ -336,19 +343,20 @@ export const asHTML: {
|
|
|
336
343
|
): AsHTMLReturnType<Field>
|
|
337
344
|
|
|
338
345
|
/**
|
|
339
|
-
*
|
|
346
|
+
* Converts a rich text field to an HTML string.
|
|
340
347
|
*
|
|
341
348
|
* @deprecated Use object-style configuration instead.
|
|
342
349
|
*
|
|
343
|
-
* @param richTextField - A rich text
|
|
344
|
-
* @param linkResolver - An optional link resolver function to resolve links
|
|
345
|
-
*
|
|
346
|
-
* @param serializer - An optional rich text serializer
|
|
347
|
-
*
|
|
350
|
+
* @param richTextField - A rich text field from Prismic.
|
|
351
|
+
* @param linkResolver - An optional link resolver function to resolve links.
|
|
352
|
+
* Without it, you're expected to use the `routes` option from the API.
|
|
353
|
+
* @param serializer - An optional rich text serializer. Unhandled cases will
|
|
354
|
+
* fall back to the default serializer.
|
|
348
355
|
*
|
|
349
|
-
* @returns HTML equivalent of the
|
|
356
|
+
* @returns HTML equivalent of the rich text field, or `null` if the field is
|
|
357
|
+
* empty.
|
|
350
358
|
*
|
|
351
|
-
* @see
|
|
359
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
352
360
|
*/
|
|
353
361
|
<Field extends RichTextField | null | undefined>(
|
|
354
362
|
richTextField: Field,
|
|
@@ -28,13 +28,13 @@ type AsImagePixelDensitySrcSetReturnType<
|
|
|
28
28
|
Field extends ImageFieldImage<"filled">
|
|
29
29
|
? {
|
|
30
30
|
/**
|
|
31
|
-
* The image field's
|
|
31
|
+
* The image field's URL with imgix URL parameters (if given).
|
|
32
32
|
*/
|
|
33
33
|
src: string
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* A pixel-
|
|
37
|
-
*
|
|
36
|
+
* A pixel-density-based `srcset` attribute value for the image field
|
|
37
|
+
* with imgix URL parameters (if given).
|
|
38
38
|
*/
|
|
39
39
|
srcset: string
|
|
40
40
|
}
|
|
@@ -42,7 +42,7 @@ type AsImagePixelDensitySrcSetReturnType<
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Creates a pixel-density-based `srcset` from an image field with optional
|
|
45
|
-
* image transformations
|
|
45
|
+
* image transformations via imgix URL parameters.
|
|
46
46
|
*
|
|
47
47
|
* If a `pixelDensities` parameter is not given, the following pixel densities
|
|
48
48
|
* will be used by default: 1, 2, 3.
|
|
@@ -50,26 +50,27 @@ type AsImagePixelDensitySrcSetReturnType<
|
|
|
50
50
|
* @example
|
|
51
51
|
*
|
|
52
52
|
* ```ts
|
|
53
|
-
* const srcset = asImagePixelDensitySrcSet(document.data.
|
|
53
|
+
* const srcset = asImagePixelDensitySrcSet(document.data.photo, {
|
|
54
54
|
* pixelDensities: [1, 2],
|
|
55
55
|
* sat: -100,
|
|
56
56
|
* })
|
|
57
57
|
* // => {
|
|
58
|
-
* // src:
|
|
59
|
-
* // srcset:
|
|
60
|
-
* //
|
|
58
|
+
* // src: "https://images.prismic.io/repo/image.png?sat=-100",
|
|
59
|
+
* // srcset: "https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, " +
|
|
60
|
+
* // "https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x"
|
|
61
61
|
* // }
|
|
62
62
|
* ```
|
|
63
63
|
*
|
|
64
|
-
* @param field -
|
|
65
|
-
* an image URL.
|
|
66
|
-
* @param config - An object of
|
|
67
|
-
* parameter defines the resulting `srcset`
|
|
64
|
+
* @param field - An image field (or one of its responsive views) from which to
|
|
65
|
+
* get an image URL.
|
|
66
|
+
* @param config - An object of imgix URL API parameters. The `pixelDensities`
|
|
67
|
+
* parameter defines the resulting `srcset` pixel densities.
|
|
68
68
|
*
|
|
69
|
-
* @returns A `srcset` attribute value for the image field with
|
|
70
|
-
* parameters
|
|
69
|
+
* @returns A `srcset` attribute value for the image field with imgix URL
|
|
70
|
+
* parameters, or `null` if the field is empty.
|
|
71
71
|
*
|
|
72
|
-
* @see
|
|
72
|
+
* @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
|
|
73
|
+
* @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
|
|
73
74
|
*/
|
|
74
75
|
export const asImagePixelDensitySrcSet = <
|
|
75
76
|
Field extends ImageFieldImage | null | undefined,
|
|
@@ -12,24 +12,25 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =
|
|
|
12
12
|
Field extends ImageFieldImage<"filled"> ? string : null
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Returns the URL of an image field with optional image transformations
|
|
16
|
-
*
|
|
15
|
+
* Returns the URL of an image field with optional image transformations via
|
|
16
|
+
* imgix URL parameters.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
*
|
|
20
20
|
* ```ts
|
|
21
|
-
* const src = asImageSrc(document.data.
|
|
22
|
-
* // => https://images.prismic.io/repo/image.png?sat=-100
|
|
21
|
+
* const src = asImageSrc(document.data.photo, { sat: -100 })
|
|
22
|
+
* // => "https://images.prismic.io/repo/image.png?sat=-100"
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
|
-
* @param field -
|
|
26
|
-
* an image URL.
|
|
27
|
-
* @param config - An object of
|
|
25
|
+
* @param field - An image field (or one of its responsive views) from which to
|
|
26
|
+
* get an image URL.
|
|
27
|
+
* @param config - An object of imgix URL API parameters to transform the image.
|
|
28
28
|
*
|
|
29
|
-
* @returns The image field's
|
|
30
|
-
*
|
|
29
|
+
* @returns The image field's URL with transformations applied, or `null` if the
|
|
30
|
+
* field is empty.
|
|
31
31
|
*
|
|
32
|
-
* @see
|
|
32
|
+
* @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
|
|
33
|
+
* @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
|
|
33
34
|
*/
|
|
34
35
|
export const asImageSrc = <Field extends ImageFieldImage | null | undefined>(
|
|
35
36
|
field: Field,
|
|
@@ -19,13 +19,13 @@ type AsImageWidthSrcSetReturnType<
|
|
|
19
19
|
Field extends ImageFieldImage<"filled">
|
|
20
20
|
? {
|
|
21
21
|
/**
|
|
22
|
-
* The image field's
|
|
22
|
+
* The image field's URL with imgix URL parameters (if given).
|
|
23
23
|
*/
|
|
24
24
|
src: string
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* A width-based `srcset` attribute value for the image field
|
|
28
|
-
*
|
|
27
|
+
* A width-based `srcset` attribute value for the image field with imgix
|
|
28
|
+
* URL parameters (if given).
|
|
29
29
|
*/
|
|
30
30
|
srcset: string
|
|
31
31
|
}
|
|
@@ -40,10 +40,10 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Creates a width-based `srcset` from an image field with optional image
|
|
43
|
-
* transformations
|
|
43
|
+
* transformations via imgix URL parameters.
|
|
44
44
|
*
|
|
45
|
-
* If a `widths` parameter is not given, the following widths
|
|
46
|
-
* default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
45
|
+
* If a `widths` parameter is not given, the following widths (in pixels) will
|
|
46
|
+
* be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
47
47
|
*
|
|
48
48
|
* If the image field contains responsive views, each responsive view can be
|
|
49
49
|
* used as a width in the resulting `srcset` by passing `"thumbnails"` as the
|
|
@@ -52,28 +52,29 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
|
52
52
|
* @example
|
|
53
53
|
*
|
|
54
54
|
* ```ts
|
|
55
|
-
* const srcset = asImageWidthSrcSet(document.data.
|
|
55
|
+
* const srcset = asImageWidthSrcSet(document.data.photo, {
|
|
56
56
|
* widths: [400, 800, 1600],
|
|
57
57
|
* sat: -100,
|
|
58
58
|
* })
|
|
59
59
|
* // => {
|
|
60
|
-
* // src:
|
|
61
|
-
* // srcset:
|
|
62
|
-
* //
|
|
63
|
-
* //
|
|
60
|
+
* // src: "https://images.prismic.io/repo/image.png?sat=-100",
|
|
61
|
+
* // srcset: "https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, " +
|
|
62
|
+
* // "https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, " +
|
|
63
|
+
* // "https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w"
|
|
64
64
|
* // }
|
|
65
65
|
* ```
|
|
66
66
|
*
|
|
67
|
-
* @param field -
|
|
68
|
-
* an image URL.
|
|
69
|
-
* @param config - An object of
|
|
67
|
+
* @param field - An image field (or one of its responsive views) from which to
|
|
68
|
+
* get an image URL.
|
|
69
|
+
* @param config - An object of imgix URL API parameters. The `widths` parameter
|
|
70
70
|
* defines the resulting `srcset` widths. Pass `"thumbnails"` to automatically
|
|
71
71
|
* use the field's responsive views.
|
|
72
72
|
*
|
|
73
|
-
* @returns A `srcset` attribute value for the image field with
|
|
74
|
-
* parameters
|
|
73
|
+
* @returns A `srcset` attribute value for the image field with imgix URL
|
|
74
|
+
* parameters, or `null` if the field is empty.
|
|
75
75
|
*
|
|
76
|
-
* @see
|
|
76
|
+
* @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
|
|
77
|
+
* @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
|
|
77
78
|
*/
|
|
78
79
|
export const asImageWidthSrcSet = <
|
|
79
80
|
Field extends ImageFieldImage | null | undefined,
|
package/src/helpers/asLink.ts
CHANGED
|
@@ -7,16 +7,16 @@ import type { FilledLinkToMediaField } from "../types/value/linkToMedia"
|
|
|
7
7
|
import { documentToLinkField } from "./documentToLinkField"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Resolves a link to a Prismic
|
|
10
|
+
* Resolves a link to a Prismic page to a URL.
|
|
11
11
|
*
|
|
12
|
-
* @typeParam ReturnType - Return type of your link resolver function
|
|
13
|
-
* you prefer to return a complex object
|
|
12
|
+
* @typeParam ReturnType - Return type of your link resolver function. Useful if
|
|
13
|
+
* you prefer to return a complex object.
|
|
14
14
|
*
|
|
15
|
-
* @param linkToDocumentField - A
|
|
15
|
+
* @param linkToDocumentField - A page link field to resolve.
|
|
16
16
|
*
|
|
17
|
-
* @returns Resolved URL
|
|
17
|
+
* @returns Resolved URL.
|
|
18
18
|
*
|
|
19
|
-
* @see
|
|
19
|
+
* @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
|
|
20
20
|
*/
|
|
21
21
|
export type LinkResolverFunction<ReturnType = string | null | undefined> = (
|
|
22
22
|
linkToDocumentField: FilledContentRelationshipField,
|
|
@@ -28,8 +28,8 @@ export type LinkResolverFunction<ReturnType = string | null | undefined> = (
|
|
|
28
28
|
type AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =
|
|
29
29
|
{
|
|
30
30
|
/**
|
|
31
|
-
* An optional link resolver function. Without it, you
|
|
32
|
-
* the `routes`
|
|
31
|
+
* An optional link resolver function. Without it, you're expected to use
|
|
32
|
+
* the `routes` option from the API.
|
|
33
33
|
*/
|
|
34
34
|
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null
|
|
35
35
|
}
|
|
@@ -63,21 +63,25 @@ export type AsLinkReturnType<
|
|
|
63
63
|
// TODO: Remove overload when we remove support for deprecated tuple-style configuration.
|
|
64
64
|
export const asLink: {
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
66
|
+
* Converts any type of link field or Prismic page to a URL.
|
|
67
67
|
*
|
|
68
|
-
* @
|
|
69
|
-
* type
|
|
70
|
-
* @typeParam Field - Link field or Prismic document to resolve to a URL
|
|
68
|
+
* @example
|
|
71
69
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* const url = asLink(document.data.link)
|
|
72
|
+
* // => "/blog/my-post"
|
|
73
|
+
* ```
|
|
75
74
|
*
|
|
76
|
-
* @
|
|
77
|
-
*
|
|
75
|
+
* @typeParam LinkResolverFunctionReturnType - Link resolver function return
|
|
76
|
+
* type.
|
|
77
|
+
* @typeParam Field - Link field or Prismic page to resolve to a URL.
|
|
78
78
|
*
|
|
79
|
-
* @
|
|
80
|
-
* @
|
|
79
|
+
* @param linkFieldOrDocument - Any kind of link field or a page to resolve.
|
|
80
|
+
* @param config - Configuration that determines the output of `asLink()`.
|
|
81
|
+
*
|
|
82
|
+
* @returns Resolved URL, or `null` if the link field or page is empty.
|
|
83
|
+
*
|
|
84
|
+
* @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
|
|
81
85
|
*/
|
|
82
86
|
<
|
|
83
87
|
LinkResolverFunctionReturnType = string | null | undefined,
|
|
@@ -92,24 +96,21 @@ export const asLink: {
|
|
|
92
96
|
): AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
93
97
|
|
|
94
98
|
/**
|
|
95
|
-
*
|
|
99
|
+
* Converts any type of link field or Prismic page to a URL.
|
|
96
100
|
*
|
|
97
101
|
* @deprecated Use object-style configuration instead.
|
|
98
102
|
*
|
|
99
|
-
* @typeParam LinkResolverFunctionReturnType -
|
|
100
|
-
* type
|
|
101
|
-
* @typeParam Field - Link field or Prismic
|
|
103
|
+
* @typeParam LinkResolverFunctionReturnType - Link resolver function return
|
|
104
|
+
* type.
|
|
105
|
+
* @typeParam Field - Link field or Prismic page to resolve to a URL.
|
|
102
106
|
*
|
|
103
|
-
* @param linkFieldOrDocument - Any kind of link field or a
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* are expected to use the `routes` options from the API
|
|
107
|
+
* @param linkFieldOrDocument - Any kind of link field or a page to resolve.
|
|
108
|
+
* @param linkResolver - An optional link resolver function. Without it,
|
|
109
|
+
* you're expected to use the `routes` option from the API.
|
|
107
110
|
*
|
|
108
|
-
* @returns Resolved URL or
|
|
109
|
-
* `null`
|
|
111
|
+
* @returns Resolved URL, or `null` if the link field or page is empty.
|
|
110
112
|
*
|
|
111
|
-
* @see
|
|
112
|
-
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
113
|
+
* @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
|
|
113
114
|
*/
|
|
114
115
|
<
|
|
115
116
|
LinkResolverFunctionReturnType = string | null | undefined,
|
|
@@ -195,7 +196,7 @@ export const asLink: {
|
|
|
195
196
|
>
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
// When empty or
|
|
199
|
+
// When empty or route resolver and link resolver are not used...
|
|
199
200
|
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
200
201
|
}
|
|
201
202
|
|
|
@@ -67,26 +67,23 @@ type AsLinkAttrsReturnType<
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* Resolves any type of link field or Prismic
|
|
71
|
-
*
|
|
72
|
-
* like `<a>`.
|
|
70
|
+
* Resolves any type of link field or Prismic page to a set of link attributes.
|
|
71
|
+
* The attributes are designed to be passed to link HTML elements, like `<a>`.
|
|
73
72
|
*
|
|
74
73
|
* If a resolved URL is external (i.e. starts with a protocol like `https://`),
|
|
75
74
|
* `rel` is returned as `"noreferrer"`.
|
|
76
75
|
*
|
|
77
76
|
* @typeParam LinkResolverFunctionReturnType - link resolver function return
|
|
78
77
|
* type
|
|
79
|
-
* @typeParam Field - Link field or Prismic
|
|
80
|
-
* attributes
|
|
78
|
+
* @typeParam Field - Link field or Prismic page to resolve to link attributes
|
|
81
79
|
*
|
|
82
|
-
* @param linkFieldOrDocument - Any kind of link field or a
|
|
80
|
+
* @param linkFieldOrDocument - Any kind of link field or a page to resolve
|
|
83
81
|
* @param config - Configuration that determines the output of `asLinkAttrs()`
|
|
84
82
|
*
|
|
85
83
|
* @returns Resolved set of link attributes or, if the provided link field or
|
|
86
|
-
*
|
|
84
|
+
* page is empty, and empty object
|
|
87
85
|
*
|
|
88
|
-
* @see
|
|
89
|
-
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
86
|
+
* @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
|
|
90
87
|
*/
|
|
91
88
|
export const asLinkAttrs = <
|
|
92
89
|
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
package/src/helpers/asText.ts
CHANGED
|
@@ -28,14 +28,22 @@ type AsTextReturnType<Field extends RichTextField | null | undefined> =
|
|
|
28
28
|
|
|
29
29
|
export const asText: {
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Converts a rich text field to a plain text string.
|
|
32
32
|
*
|
|
33
|
-
* @
|
|
34
|
-
* @param config - Configuration that determines the output of `asText()`
|
|
33
|
+
* @example
|
|
35
34
|
*
|
|
36
|
-
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const text = asText(document.data.content)
|
|
37
|
+
* // => "Hello world"
|
|
38
|
+
* ```
|
|
37
39
|
*
|
|
38
|
-
* @
|
|
40
|
+
* @param richTextField - A rich text field from Prismic.
|
|
41
|
+
* @param config - Configuration that determines the output of `asText()`.
|
|
42
|
+
*
|
|
43
|
+
* @returns Plain text equivalent of the rich text field, or `null` if the
|
|
44
|
+
* field is empty.
|
|
45
|
+
*
|
|
46
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
39
47
|
*/
|
|
40
48
|
<Field extends RichTextField | null | undefined>(
|
|
41
49
|
richTextField: Field,
|
|
@@ -43,16 +51,18 @@ export const asText: {
|
|
|
43
51
|
): AsTextReturnType<Field>
|
|
44
52
|
|
|
45
53
|
/**
|
|
46
|
-
*
|
|
54
|
+
* Converts a rich text field to a plain text string.
|
|
47
55
|
*
|
|
48
56
|
* @deprecated Use object-style configuration instead.
|
|
49
57
|
*
|
|
50
|
-
* @param richTextField - A rich text
|
|
51
|
-
* @param separator - Separator used to join each element
|
|
58
|
+
* @param richTextField - A rich text field from Prismic.
|
|
59
|
+
* @param separator - Separator used to join each element. Defaults to a
|
|
60
|
+
* space.
|
|
52
61
|
*
|
|
53
|
-
* @returns Plain text equivalent of the
|
|
62
|
+
* @returns Plain text equivalent of the rich text field, or `null` if the
|
|
63
|
+
* field is empty.
|
|
54
64
|
*
|
|
55
|
-
* @see
|
|
65
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
56
66
|
*/
|
|
57
67
|
<Field extends RichTextField | null | undefined>(
|
|
58
68
|
richTextField: Field,
|