@prismicio/client 7.1.1 → 7.3.0

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.
Files changed (120) hide show
  1. package/dist/createClient.cjs +24 -1
  2. package/dist/createClient.cjs.map +1 -1
  3. package/dist/createClient.d.ts +7 -0
  4. package/dist/createClient.js +24 -1
  5. package/dist/createClient.js.map +1 -1
  6. package/dist/errors/ForbiddenError.cjs.map +1 -1
  7. package/dist/errors/ForbiddenError.d.ts +1 -1
  8. package/dist/errors/ForbiddenError.js.map +1 -1
  9. package/dist/errors/NotFoundError.cjs.map +1 -1
  10. package/dist/errors/NotFoundError.d.ts +1 -1
  11. package/dist/errors/NotFoundError.js.map +1 -1
  12. package/dist/errors/ParsingError.cjs.map +1 -1
  13. package/dist/errors/ParsingError.d.ts +1 -1
  14. package/dist/errors/ParsingError.js.map +1 -1
  15. package/dist/errors/RefExpiredError.cjs +7 -0
  16. package/dist/errors/RefExpiredError.cjs.map +1 -0
  17. package/dist/errors/RefExpiredError.d.ts +8 -0
  18. package/dist/errors/RefExpiredError.js +7 -0
  19. package/dist/errors/RefExpiredError.js.map +1 -0
  20. package/dist/errors/RefNotFoundError.cjs +7 -0
  21. package/dist/errors/RefNotFoundError.cjs.map +1 -0
  22. package/dist/errors/RefNotFoundError.d.ts +8 -0
  23. package/dist/errors/RefNotFoundError.js +7 -0
  24. package/dist/errors/RefNotFoundError.js.map +1 -0
  25. package/dist/helpers/asHTML.cjs +43 -50
  26. package/dist/helpers/asHTML.cjs.map +1 -1
  27. package/dist/helpers/asHTML.d.ts +31 -6
  28. package/dist/helpers/asHTML.js +42 -49
  29. package/dist/helpers/asHTML.js.map +1 -1
  30. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +1 -1
  31. package/dist/helpers/asImageSrc.d.ts +1 -1
  32. package/dist/helpers/asImageWidthSrcSet.cjs +1 -1
  33. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  34. package/dist/helpers/asImageWidthSrcSet.d.ts +1 -1
  35. package/dist/helpers/asImageWidthSrcSet.js +1 -1
  36. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  37. package/dist/helpers/asLinkAttrs.d.ts +1 -1
  38. package/dist/helpers/asText.cjs +2 -2
  39. package/dist/helpers/asText.cjs.map +1 -1
  40. package/dist/helpers/asText.js +1 -1
  41. package/dist/helpers/asText.js.map +1 -1
  42. package/dist/helpers/isFilled.d.ts +10 -13
  43. package/dist/index.cjs +8 -7
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.ts +28 -2
  46. package/dist/index.js +6 -2
  47. package/dist/index.js.map +1 -1
  48. package/dist/lib/serializerHelpers.cjs +91 -35
  49. package/dist/lib/serializerHelpers.cjs.map +1 -1
  50. package/dist/lib/serializerHelpers.d.ts +8 -8
  51. package/dist/lib/serializerHelpers.js +91 -35
  52. package/dist/lib/serializerHelpers.js.map +1 -1
  53. package/dist/package.json.cjs +1 -1
  54. package/dist/package.json.js +1 -1
  55. package/dist/richtext/asText.cjs +13 -0
  56. package/dist/richtext/asText.cjs.map +1 -0
  57. package/dist/richtext/asText.d.ts +12 -0
  58. package/dist/richtext/asText.js +13 -0
  59. package/dist/richtext/asText.js.map +1 -0
  60. package/dist/richtext/asTree.cjs +123 -0
  61. package/dist/richtext/asTree.cjs.map +1 -0
  62. package/dist/richtext/asTree.d.ts +14 -0
  63. package/dist/richtext/asTree.js +123 -0
  64. package/dist/richtext/asTree.js.map +1 -0
  65. package/dist/richtext/composeSerializers.cjs +17 -0
  66. package/dist/richtext/composeSerializers.cjs.map +1 -0
  67. package/dist/richtext/composeSerializers.d.ts +16 -0
  68. package/dist/richtext/composeSerializers.js +17 -0
  69. package/dist/richtext/composeSerializers.js.map +1 -0
  70. package/dist/richtext/index.d.ts +7 -0
  71. package/dist/richtext/serialize.cjs +19 -0
  72. package/dist/richtext/serialize.cjs.map +1 -0
  73. package/dist/richtext/serialize.d.ts +19 -0
  74. package/dist/richtext/serialize.js +19 -0
  75. package/dist/richtext/serialize.js.map +1 -0
  76. package/dist/richtext/types.cjs +11 -0
  77. package/dist/richtext/types.cjs.map +1 -0
  78. package/dist/richtext/types.d.ts +71 -0
  79. package/dist/richtext/types.js +11 -0
  80. package/dist/richtext/types.js.map +1 -0
  81. package/dist/richtext/wrapMapSerializer.cjs +24 -0
  82. package/dist/richtext/wrapMapSerializer.cjs.map +1 -0
  83. package/dist/richtext/wrapMapSerializer.d.ts +15 -0
  84. package/dist/richtext/wrapMapSerializer.js +24 -0
  85. package/dist/richtext/wrapMapSerializer.js.map +1 -0
  86. package/dist/richtext.cjs +15 -0
  87. package/dist/richtext.cjs.map +1 -0
  88. package/dist/richtext.js +15 -0
  89. package/dist/richtext.js.map +1 -0
  90. package/dist/types/value/image.d.ts +9 -0
  91. package/dist/types/value/linkToMedia.d.ts +1 -0
  92. package/dist/types/value/richText.cjs.map +1 -1
  93. package/dist/types/value/richText.d.ts +7 -0
  94. package/dist/types/value/richText.js.map +1 -1
  95. package/dist/types/value/sharedSlice.d.ts +1 -1
  96. package/dist/types/value/slice.d.ts +1 -1
  97. package/package.json +34 -15
  98. package/src/createClient.ts +55 -4
  99. package/src/errors/ForbiddenError.ts +5 -3
  100. package/src/errors/NotFoundError.ts +3 -1
  101. package/src/errors/ParsingError.ts +3 -1
  102. package/src/errors/RefExpiredError.ts +14 -0
  103. package/src/errors/RefNotFoundError.ts +14 -0
  104. package/src/helpers/asHTML.ts +166 -76
  105. package/src/helpers/asImageWidthSrcSet.ts +2 -0
  106. package/src/helpers/asText.ts +2 -2
  107. package/src/index.ts +9 -4
  108. package/src/lib/serializerHelpers.ts +140 -67
  109. package/src/richtext/asText.ts +27 -0
  110. package/src/richtext/asTree.ts +211 -0
  111. package/src/richtext/composeSerializers.ts +36 -0
  112. package/src/richtext/index.ts +14 -0
  113. package/src/richtext/serialize.ts +54 -0
  114. package/src/richtext/types.ts +153 -0
  115. package/src/richtext/wrapMapSerializer.ts +46 -0
  116. package/src/types/value/image.ts +9 -0
  117. package/src/types/value/linkToMedia.ts +1 -0
  118. package/src/types/value/richText.ts +7 -0
  119. package/src/types/value/sharedSlice.ts +1 -1
  120. package/src/types/value/slice.ts +1 -1
@@ -19,6 +19,8 @@ import { ForbiddenError } from "./errors/ForbiddenError";
19
19
  import { NotFoundError } from "./errors/NotFoundError";
20
20
  import { ParsingError } from "./errors/ParsingError";
21
21
  import { PrismicError } from "./errors/PrismicError";
22
+ import { RefExpiredError } from "./errors/RefExpiredError";
23
+ import { RefNotFoundError } from "./errors/RefNotFoundError";
22
24
 
23
25
  import { LinkResolverFunction, asLink } from "./helpers/asLink";
24
26
 
@@ -51,6 +53,15 @@ export const REPOSITORY_CACHE_TTL = 5000;
51
53
  */
52
54
  export const GET_ALL_QUERY_DELAY = 500;
53
55
 
56
+ /**
57
+ * The default number of milliseconds to wait before retrying a rate-limited
58
+ * `fetch()` request (429 response code). The default value is only used if the
59
+ * response does not include a `retry-after` header.
60
+ *
61
+ * The API allows up to 200 requests per second.
62
+ */
63
+ const DEFUALT_RETRY_AFTER_MS = 1000;
64
+
54
65
  /**
55
66
  * Extracts one or more Prismic document types that match a given Prismic
56
67
  * document type. If no matches are found, no extraction is performed and the
@@ -120,10 +131,18 @@ export interface RequestInitLike extends Pick<RequestInit, "cache"> {
120
131
  */
121
132
  export interface ResponseLike {
122
133
  status: number;
134
+ headers: HeadersLike;
123
135
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
136
  json(): Promise<any>;
125
137
  }
126
138
 
139
+ /**
140
+ * The minimum required properties from Headers.
141
+ */
142
+ export interface HeadersLike {
143
+ get(name: string): string | null;
144
+ }
145
+
127
146
  /**
128
147
  * The minimum required properties to treat as an HTTP Request for automatic
129
148
  * Prismic preview support.
@@ -342,6 +361,7 @@ type ResolvePreviewArgs<LinkResolverReturnType> = {
342
361
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
343
362
  type FetchJobResult<TJSON = any> = {
344
363
  status: number;
364
+ headers: HeadersLike;
345
365
  json: TJSON;
346
366
  };
347
367
 
@@ -1839,6 +1859,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1839
1859
 
1840
1860
  return {
1841
1861
  status: res.status,
1862
+ headers: res.headers,
1842
1863
  json,
1843
1864
  };
1844
1865
  })
@@ -1881,21 +1902,51 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1881
1902
  // - Incorrect access token for query endpoint
1882
1903
  case 403: {
1883
1904
  throw new ForbiddenError(
1884
- "error" in res.json ? res.json.error : res.json.message,
1905
+ res.json.error || res.json.message,
1885
1906
  url,
1886
1907
  res.json,
1887
1908
  );
1888
1909
  }
1889
1910
 
1890
- // Not Found (this response has an empty body)
1891
- // - Incorrect repository name
1911
+ // Not Found
1912
+ // - Incorrect repository name (this response has an empty body)
1913
+ // - Ref does not exist
1892
1914
  case 404: {
1915
+ if (res.json && res.json.type === "api_notfound_error") {
1916
+ throw new RefNotFoundError(res.json.message, url, res.json);
1917
+ }
1918
+
1893
1919
  throw new NotFoundError(
1894
1920
  `Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`,
1895
1921
  url,
1896
- undefined,
1922
+ undefined, // res.json is empty
1897
1923
  );
1898
1924
  }
1925
+
1926
+ // Gone
1927
+ // - Ref is expired
1928
+ case 410: {
1929
+ throw new RefExpiredError(res.json.message, url, res.json);
1930
+ }
1931
+
1932
+ // Too Many Requests
1933
+ // - Exceeded the maximum number of requests per second
1934
+ case 429: {
1935
+ const parsedRetryAfter = Number(res.headers.get("retry-after"));
1936
+ const delay = Number.isNaN(parsedRetryAfter)
1937
+ ? DEFUALT_RETRY_AFTER_MS
1938
+ : parsedRetryAfter;
1939
+
1940
+ return await new Promise((resolve, reject) => {
1941
+ setTimeout(async () => {
1942
+ try {
1943
+ resolve(await this.fetch(url, params));
1944
+ } catch (error) {
1945
+ reject(error);
1946
+ }
1947
+ }, delay);
1948
+ });
1949
+ }
1899
1950
  }
1900
1951
 
1901
1952
  throw new PrismicError(undefined, url, res.json);
@@ -9,6 +9,8 @@ type ForbiddenErrorQueryAPIResponse = {
9
9
  error: string;
10
10
  };
11
11
 
12
- export class ForbiddenError extends PrismicError<
13
- ForbiddenErrorRepositoryAPIResponse | ForbiddenErrorQueryAPIResponse
14
- > {}
12
+ export class ForbiddenError<
13
+ TResponse =
14
+ | ForbiddenErrorRepositoryAPIResponse
15
+ | ForbiddenErrorQueryAPIResponse,
16
+ > extends PrismicError<TResponse> {}
@@ -1,3 +1,5 @@
1
1
  import { PrismicError } from "./PrismicError";
2
2
 
3
- export class NotFoundError extends PrismicError<undefined> {}
3
+ export class NotFoundError<
4
+ TResponse = undefined,
5
+ > extends PrismicError<TResponse> {}
@@ -9,4 +9,6 @@ type ParsingErrorAPIResponse = {
9
9
  location: string;
10
10
  };
11
11
 
12
- export class ParsingError extends PrismicError<ParsingErrorAPIResponse> {}
12
+ export class ParsingError<
13
+ TResponse = ParsingErrorAPIResponse,
14
+ > extends PrismicError<TResponse> {}
@@ -0,0 +1,14 @@
1
+ import { ForbiddenError } from "./ForbiddenError";
2
+
3
+ type RefExpiredErrorAPIResponse = {
4
+ type: "api_validation_error";
5
+ message: string;
6
+ };
7
+
8
+ // This error extends `ForbiddenError` for backwards compatibility. Before the
9
+ // API started returning 410 for expired refs, it returnd 403, which threw a
10
+ // `ForbiddenError`.
11
+ // TODO: Extend this error from `PrismicError` in v8.
12
+ export class RefExpiredError<
13
+ TResponse = RefExpiredErrorAPIResponse,
14
+ > extends ForbiddenError<TResponse> {}
@@ -0,0 +1,14 @@
1
+ import { ForbiddenError } from "./ForbiddenError";
2
+
3
+ type RefNotFoundErrorAPIResponse = {
4
+ type: "api_notfound_error";
5
+ message: string;
6
+ };
7
+
8
+ // This error extends `ForbiddenError` for backwards compatibility. Before the
9
+ // API started returning 404 for not found refs, it returnd 403, which threw a
10
+ // `ForbiddenError`.
11
+ // TODO: Extend this error from `PrismicError` in v8.
12
+ export class RefNotFoundError<
13
+ TResponse = RefNotFoundErrorAPIResponse,
14
+ > extends ForbiddenError<TResponse> {}
@@ -1,13 +1,3 @@
1
- import {
2
- Element,
3
- RichTextFunctionSerializer,
4
- RichTextMapSerializer,
5
- RichTextMapSerializerFunction,
6
- composeSerializers,
7
- serialize,
8
- wrapMapSerializer,
9
- } from "@prismicio/richtext";
10
-
11
1
  import {
12
2
  serializeEmbed,
13
3
  serializeHyperlink,
@@ -19,14 +9,23 @@ import {
19
9
 
20
10
  import type { RichTextField } from "../types/value/richText";
21
11
 
12
+ import {
13
+ RichTextFunctionSerializer,
14
+ RichTextMapSerializer,
15
+ RichTextMapSerializerFunction,
16
+ composeSerializers,
17
+ serialize,
18
+ wrapMapSerializer,
19
+ } from "../richtext";
20
+
22
21
  import { LinkResolverFunction } from "./asLink";
23
22
 
24
23
  /**
25
24
  * Serializes a node from a rich text or title field with a function to HTML.
26
25
  *
27
- * Unlike a typical `@prismicio/richtext` function serializer, this serializer
28
- * converts the `children` argument to a single string rather than an array of
29
- * strings.
26
+ * Unlike a typical `@prismicio/client/richtext` function serializer, this
27
+ * serializer converts the `children` argument to a single string rather than an
28
+ * array of strings.
30
29
  *
31
30
  * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
32
31
  */
@@ -41,13 +40,28 @@ export type HTMLRichTextFunctionSerializer = (
41
40
  /**
42
41
  * Serializes a node from a rich text or title field with a map to HTML
43
42
  *
44
- * Unlike a typical `@prismicio/richtext` map serializer, this serializer
43
+ * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
45
44
  * converts the `children` property to a single string rather than an array of
46
- * strings.
45
+ * strings and accepts shorthand declarations.
47
46
  *
48
47
  * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
49
48
  */
50
49
  export type HTMLRichTextMapSerializer = {
50
+ [P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>["span"]
51
+ ? HTMLStrictRichTextMapSerializer[P]
52
+ : HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand;
53
+ };
54
+
55
+ /**
56
+ * Serializes a node from a rich text or title field with a map to HTML
57
+ *
58
+ * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
59
+ * converts the `children` property to a single string rather than an array of
60
+ * strings but doesn't accept shorthand declarations.
61
+ *
62
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
63
+ */
64
+ export type HTMLStrictRichTextMapSerializer = {
51
65
  [P in keyof RichTextMapSerializer<string>]: (payload: {
52
66
  type: Parameters<HTMLRichTextMapSerializerFunction<P>>[0]["type"];
53
67
  node: Parameters<HTMLRichTextMapSerializerFunction<P>>[0]["node"];
@@ -105,6 +119,21 @@ type ExtractTextTypeGeneric<T> = T extends RichTextMapSerializerFunction<
105
119
  ? U
106
120
  : never;
107
121
 
122
+ /**
123
+ * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.
124
+ */
125
+ export type HTMLRichTextMapSerializerShorthand = {
126
+ /**
127
+ * Classes to apply to the element type.
128
+ */
129
+ class?: string;
130
+
131
+ /**
132
+ * Other attributes to apply to the element type.
133
+ */
134
+ [Attribute: string]: string | boolean | null | undefined;
135
+ };
136
+
108
137
  /**
109
138
  * Serializes a node from a rich text or title field with a map or a function to
110
139
  * HTML
@@ -117,70 +146,126 @@ export type HTMLRichTextSerializer =
117
146
  | HTMLRichTextFunctionSerializer;
118
147
 
119
148
  /**
120
- * Creates a default HTML rich text serializer with a given link resolver
121
- * providing sensible and safe defaults for every node type
149
+ * Creates a HTML rich text serializer with a given link resolver and provide
150
+ * sensible and safe defaults for every node type
122
151
  *
123
152
  * @internal
124
153
  */
125
- const createDefaultHTMLRichTextSerializer = (
154
+ const createHTMLRichTextSerializer = (
126
155
  linkResolver: LinkResolverFunction | undefined | null,
156
+ serializer?: HTMLRichTextMapSerializer | null,
127
157
  ): RichTextFunctionSerializer<string> => {
128
- return (_type, node, text, children, _key) => {
129
- switch (node.type) {
130
- case Element.heading1:
131
- return serializeStandardTag("h1", node, children);
132
- case Element.heading2:
133
- return serializeStandardTag("h2", node, children);
134
- case Element.heading3:
135
- return serializeStandardTag("h3", node, children);
136
- case Element.heading4:
137
- return serializeStandardTag("h4", node, children);
138
- case Element.heading5:
139
- return serializeStandardTag("h5", node, children);
140
- case Element.heading6:
141
- return serializeStandardTag("h6", node, children);
142
- case Element.paragraph:
143
- return serializeStandardTag("p", node, children);
144
- case Element.preformatted:
145
- return serializePreFormatted(node);
146
- case Element.strong:
147
- return serializeStandardTag("strong", node, children);
148
- case Element.em:
149
- return serializeStandardTag("em", node, children);
150
- case Element.listItem:
151
- return serializeStandardTag("li", node, children);
152
- case Element.oListItem:
153
- return serializeStandardTag("li", node, children);
154
- case Element.list:
155
- return serializeStandardTag("ul", node, children);
156
- case Element.oList:
157
- return serializeStandardTag("ol", node, children);
158
- case Element.image:
159
- return serializeImage(linkResolver, node);
160
- case Element.embed:
161
- return serializeEmbed(node);
162
- case Element.hyperlink:
163
- return serializeHyperlink(linkResolver, node, children);
164
- case Element.label:
165
- return serializeStandardTag("span", node, children);
166
- case Element.span:
167
- default:
168
- return serializeSpan(text);
158
+ const useSerializerOrDefault = <
159
+ BlockType extends keyof RichTextMapSerializer<string>,
160
+ >(
161
+ nodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],
162
+ defaultWithShorthand: NonNullable<
163
+ HTMLStrictRichTextMapSerializer[BlockType]
164
+ >,
165
+ ): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {
166
+ if (typeof nodeSerializerOrShorthand === "function") {
167
+ return ((payload) => {
168
+ return (
169
+ (
170
+ nodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]
171
+ )(payload) || defaultWithShorthand(payload)
172
+ );
173
+ }) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>;
169
174
  }
175
+
176
+ return defaultWithShorthand;
177
+ };
178
+
179
+ const mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {
180
+ heading1: useSerializerOrDefault<"heading1">(
181
+ serializer?.heading1,
182
+ serializeStandardTag<"heading1">("h1", serializer?.heading1),
183
+ ),
184
+ heading2: useSerializerOrDefault<"heading2">(
185
+ serializer?.heading2,
186
+ serializeStandardTag<"heading2">("h2", serializer?.heading2),
187
+ ),
188
+ heading3: useSerializerOrDefault<"heading3">(
189
+ serializer?.heading3,
190
+ serializeStandardTag<"heading3">("h3", serializer?.heading3),
191
+ ),
192
+ heading4: useSerializerOrDefault<"heading4">(
193
+ serializer?.heading4,
194
+ serializeStandardTag<"heading4">("h4", serializer?.heading4),
195
+ ),
196
+ heading5: useSerializerOrDefault<"heading5">(
197
+ serializer?.heading5,
198
+ serializeStandardTag<"heading5">("h5", serializer?.heading5),
199
+ ),
200
+ heading6: useSerializerOrDefault<"heading6">(
201
+ serializer?.heading6,
202
+ serializeStandardTag<"heading6">("h6", serializer?.heading6),
203
+ ),
204
+ paragraph: useSerializerOrDefault<"paragraph">(
205
+ serializer?.paragraph,
206
+ serializeStandardTag<"paragraph">("p", serializer?.paragraph),
207
+ ),
208
+ preformatted: useSerializerOrDefault<"preformatted">(
209
+ serializer?.preformatted,
210
+ serializePreFormatted(serializer?.preformatted),
211
+ ),
212
+ strong: useSerializerOrDefault<"strong">(
213
+ serializer?.strong,
214
+ serializeStandardTag<"strong">("strong", serializer?.strong),
215
+ ),
216
+ em: useSerializerOrDefault<"em">(
217
+ serializer?.em,
218
+ serializeStandardTag<"em">("em", serializer?.em),
219
+ ),
220
+ listItem: useSerializerOrDefault<"listItem">(
221
+ serializer?.listItem,
222
+ serializeStandardTag<"listItem">("li", serializer?.listItem),
223
+ ),
224
+ oListItem: useSerializerOrDefault<"oListItem">(
225
+ serializer?.oListItem,
226
+ serializeStandardTag<"oListItem">("li", serializer?.oListItem),
227
+ ),
228
+ list: useSerializerOrDefault<"list">(
229
+ serializer?.list,
230
+ serializeStandardTag<"list">("ul", serializer?.list),
231
+ ),
232
+ oList: useSerializerOrDefault<"oList">(
233
+ serializer?.oList,
234
+ serializeStandardTag<"oList">("ol", serializer?.oList),
235
+ ),
236
+ image: useSerializerOrDefault<"image">(
237
+ serializer?.image,
238
+ serializeImage(linkResolver, serializer?.image),
239
+ ),
240
+ embed: useSerializerOrDefault<"embed">(
241
+ serializer?.embed,
242
+ serializeEmbed(serializer?.embed),
243
+ ),
244
+ hyperlink: useSerializerOrDefault<"hyperlink">(
245
+ serializer?.hyperlink,
246
+ serializeHyperlink(linkResolver, serializer?.hyperlink),
247
+ ),
248
+ label: useSerializerOrDefault<"label">(
249
+ serializer?.label,
250
+ serializeStandardTag<"label">("span", serializer?.label),
251
+ ),
252
+ span: useSerializerOrDefault<"span">(serializer?.span, serializeSpan()),
170
253
  };
254
+
255
+ return wrapMapSerializerWithStringChildren(mapSerializer);
171
256
  };
172
257
 
173
258
  /**
174
259
  * Wraps a map serializer into a regular function serializer. The given map
175
260
  * serializer should accept children as a string, not as an array of strings
176
- * like `@prismicio/richtext`'s `wrapMapSerializer`.
261
+ * like `@prismicio/client/richtext`'s `wrapMapSerializer`.
177
262
  *
178
263
  * @param mapSerializer - Map serializer to wrap
179
264
  *
180
265
  * @returns A regular function serializer
181
266
  */
182
267
  const wrapMapSerializerWithStringChildren = (
183
- mapSerializer: HTMLRichTextMapSerializer,
268
+ mapSerializer: HTMLStrictRichTextMapSerializer,
184
269
  ): RichTextFunctionSerializer<string> => {
185
270
  const modifiedMapSerializer = {} as RichTextMapSerializer<string>;
186
271
 
@@ -292,22 +377,27 @@ export const asHTML: {
292
377
 
293
378
  let serializer: RichTextFunctionSerializer<string>;
294
379
  if (config.serializer) {
295
- serializer = composeSerializers(
296
- typeof config.serializer === "object"
297
- ? wrapMapSerializerWithStringChildren(config.serializer)
298
- : (type, node, text, children, key) =>
299
- // TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.
300
- (config.serializer as HTMLRichTextFunctionSerializer)(
301
- type,
302
- node,
303
- text,
304
- children.join(""),
305
- key,
306
- ),
307
- createDefaultHTMLRichTextSerializer(config.linkResolver),
308
- );
380
+ if (typeof config.serializer === "function") {
381
+ serializer = composeSerializers(
382
+ (type, node, text, children, key) =>
383
+ // TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.
384
+ (config.serializer as HTMLRichTextFunctionSerializer)(
385
+ type,
386
+ node,
387
+ text,
388
+ children.join(""),
389
+ key,
390
+ ),
391
+ createHTMLRichTextSerializer(config.linkResolver),
392
+ );
393
+ } else {
394
+ serializer = createHTMLRichTextSerializer(
395
+ config.linkResolver,
396
+ config.serializer,
397
+ );
398
+ }
309
399
  } else {
310
- serializer = createDefaultHTMLRichTextSerializer(config.linkResolver);
400
+ serializer = createHTMLRichTextSerializer(config.linkResolver);
311
401
  }
312
402
 
313
403
  return serialize(richTextField, serializer).join(
@@ -94,8 +94,10 @@ export const asImageWidthSrcSet = <
94
94
  const {
95
95
  url,
96
96
  dimensions,
97
+ id: _id,
97
98
  alt: _alt,
98
99
  copyright: _copyright,
100
+ edit: _edit,
99
101
  ...responsiveViews
100
102
  } = field;
101
103
 
@@ -1,7 +1,7 @@
1
- import { asText as baseAsText } from "@prismicio/richtext";
2
-
3
1
  import { RichTextField } from "../types/value/richText";
4
2
 
3
+ import { asText as baseAsText } from "../richtext/asText";
4
+
5
5
  /**
6
6
  * Configuration that determines the output of `asText()`.
7
7
  */
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Imports are used for deprecations.
2
2
  import type { CustomTypeModelIntegrationField } from "./types/model/integration";
3
3
  import type { IntegrationField } from "./types/value/integration";
4
+ import { RichTextNodeType } from "./types/value/richText";
4
5
 
5
6
  import type {
6
7
  HTMLRichTextFunctionSerializer,
@@ -74,9 +75,6 @@ export * as isFilled from "./helpers/isFilled";
74
75
  // Conversion helper.
75
76
  export { documentToLinkField } from "./helpers/documentToLinkField";
76
77
 
77
- // RichText element types.
78
- export { Element } from "@prismicio/richtext";
79
-
80
78
  export type { LinkResolverFunction } from "./helpers/asLink";
81
79
  export type { AsLinkAttrsConfig } from "./helpers/asLinkAttrs";
82
80
 
@@ -103,6 +101,8 @@ export type { HTMLRichTextSerializer } from "./helpers/asHTML";
103
101
  export { PrismicError } from "./errors/PrismicError";
104
102
  export { ForbiddenError } from "./errors/ForbiddenError";
105
103
  export { NotFoundError } from "./errors/NotFoundError";
104
+ export { RefNotFoundError } from "./errors/RefNotFoundError";
105
+ export { RefExpiredError } from "./errors/RefExpiredError";
106
106
  export { ParsingError } from "./errors/ParsingError";
107
107
 
108
108
  //=============================================================================
@@ -110,7 +110,12 @@ export { ParsingError } from "./errors/ParsingError";
110
110
  //=============================================================================
111
111
 
112
112
  // Values - Types representing Prismic content.
113
- export { RichTextNodeType } from "./types/value/richText";
113
+ /**
114
+ * @deprecated Use {@link RichTextNodeType} instead.
115
+ */
116
+ // TODO: Remove in v8.
117
+ const Element = RichTextNodeType;
118
+ export { RichTextNodeType, Element };
114
119
  export { LinkType } from "./types/value/link";
115
120
  export { OEmbedType } from "./types/value/embed";
116
121