@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.
Files changed (304) hide show
  1. package/README.md +3 -3
  2. package/dist/buildQueryURL.cjs.map +1 -1
  3. package/dist/buildQueryURL.d.ts +1 -1
  4. package/dist/buildQueryURL.js.map +1 -1
  5. package/dist/cookie.cjs.map +1 -1
  6. package/dist/cookie.js.map +1 -1
  7. package/dist/createClient.cjs +31 -31
  8. package/dist/createClient.cjs.map +1 -1
  9. package/dist/createClient.d.ts +35 -35
  10. package/dist/createClient.js +31 -31
  11. package/dist/createClient.js.map +1 -1
  12. package/dist/errors/ForbiddenError.cjs.map +1 -1
  13. package/dist/errors/ForbiddenError.js.map +1 -1
  14. package/dist/errors/NotFoundError.cjs.map +1 -1
  15. package/dist/errors/NotFoundError.js.map +1 -1
  16. package/dist/errors/ParsingError.cjs.map +1 -1
  17. package/dist/errors/ParsingError.js.map +1 -1
  18. package/dist/errors/PreviewTokenExpired.cjs.map +1 -1
  19. package/dist/errors/PreviewTokenExpired.js.map +1 -1
  20. package/dist/errors/PrismicError.cjs.map +1 -1
  21. package/dist/errors/PrismicError.js.map +1 -1
  22. package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -1
  23. package/dist/errors/PrismicRichTextSerializerError.js.map +1 -1
  24. package/dist/errors/RefExpiredError.cjs.map +1 -1
  25. package/dist/errors/RefExpiredError.js.map +1 -1
  26. package/dist/errors/RefNotFoundError.cjs.map +1 -1
  27. package/dist/errors/RefNotFoundError.js.map +1 -1
  28. package/dist/errors/RepositoryNotFoundError.cjs.map +1 -1
  29. package/dist/errors/RepositoryNotFoundError.js.map +1 -1
  30. package/dist/filter.cjs.map +1 -1
  31. package/dist/filter.js.map +1 -1
  32. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  33. package/dist/getGraphQLEndpoint.js.map +1 -1
  34. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  35. package/dist/getRepositoryEndpoint.js.map +1 -1
  36. package/dist/getRepositoryName.cjs.map +1 -1
  37. package/dist/getRepositoryName.js.map +1 -1
  38. package/dist/getToolbarSrc.cjs.map +1 -1
  39. package/dist/getToolbarSrc.js.map +1 -1
  40. package/dist/helpers/asDate.cjs.map +1 -1
  41. package/dist/helpers/asDate.js.map +1 -1
  42. package/dist/helpers/asHTML.cjs.map +1 -1
  43. package/dist/helpers/asHTML.d.ts +2 -2
  44. package/dist/helpers/asHTML.js.map +1 -1
  45. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  46. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +2 -2
  47. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  48. package/dist/helpers/asImageSrc.cjs.map +1 -1
  49. package/dist/helpers/asImageSrc.d.ts +2 -2
  50. package/dist/helpers/asImageSrc.js.map +1 -1
  51. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  52. package/dist/helpers/asImageWidthSrcSet.d.ts +2 -2
  53. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  54. package/dist/helpers/asLink.cjs.map +1 -1
  55. package/dist/helpers/asLink.d.ts +2 -4
  56. package/dist/helpers/asLink.js.map +1 -1
  57. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  58. package/dist/helpers/asLinkAttrs.d.ts +2 -2
  59. package/dist/helpers/asLinkAttrs.js.map +1 -1
  60. package/dist/helpers/asText.cjs.map +1 -1
  61. package/dist/helpers/asText.d.ts +1 -1
  62. package/dist/helpers/asText.js.map +1 -1
  63. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  64. package/dist/helpers/documentToLinkField.js.map +1 -1
  65. package/dist/helpers/isFilled.cjs.map +1 -1
  66. package/dist/helpers/isFilled.js.map +1 -1
  67. package/dist/helpers/mapSliceZone.cjs.map +1 -1
  68. package/dist/helpers/mapSliceZone.d.ts +1 -1
  69. package/dist/helpers/mapSliceZone.js.map +1 -1
  70. package/dist/helpers/unstable_htmlAsRichText.cjs.map +1 -1
  71. package/dist/helpers/unstable_htmlAsRichText.d.ts +4 -4
  72. package/dist/helpers/unstable_htmlAsRichText.js.map +1 -1
  73. package/dist/helpers/unstable_markdownAsRichText.cjs.map +1 -1
  74. package/dist/helpers/unstable_markdownAsRichText.d.ts +2 -2
  75. package/dist/helpers/unstable_markdownAsRichText.js.map +1 -1
  76. package/dist/index.cjs.map +1 -1
  77. package/dist/index.js.map +1 -1
  78. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  79. package/dist/isRepositoryEndpoint.js.map +1 -1
  80. package/dist/isRepositoryName.cjs.map +1 -1
  81. package/dist/isRepositoryName.js.map +1 -1
  82. package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
  83. package/dist/lib/RichTextFieldBuilder.d.ts +1 -1
  84. package/dist/lib/RichTextFieldBuilder.js.map +1 -1
  85. package/dist/lib/appendFilters.cjs.map +1 -1
  86. package/dist/lib/appendFilters.js.map +1 -1
  87. package/dist/lib/castArray.cjs.map +1 -1
  88. package/dist/lib/castArray.js.map +1 -1
  89. package/dist/lib/castThunk.cjs.map +1 -1
  90. package/dist/lib/castThunk.js.map +1 -1
  91. package/dist/lib/devMsg.cjs.map +1 -1
  92. package/dist/lib/devMsg.d.ts +1 -1
  93. package/dist/lib/devMsg.js.map +1 -1
  94. package/dist/lib/escapeHTML.cjs.map +1 -1
  95. package/dist/lib/escapeHTML.js.map +1 -1
  96. package/dist/lib/everyTagFilter.cjs.map +1 -1
  97. package/dist/lib/everyTagFilter.js.map +1 -1
  98. package/dist/lib/filterRichTextField.cjs.map +1 -1
  99. package/dist/lib/filterRichTextField.d.ts +3 -3
  100. package/dist/lib/filterRichTextField.js.map +1 -1
  101. package/dist/lib/findMasterRef.cjs.map +1 -1
  102. package/dist/lib/findMasterRef.d.ts +1 -1
  103. package/dist/lib/findMasterRef.js.map +1 -1
  104. package/dist/lib/findRef.cjs.map +1 -1
  105. package/dist/lib/findRef.d.ts +1 -1
  106. package/dist/lib/findRef.js.map +1 -1
  107. package/dist/lib/findRefByID.cjs.map +1 -1
  108. package/dist/lib/findRefByID.d.ts +1 -1
  109. package/dist/lib/findRefByID.js.map +1 -1
  110. package/dist/lib/findRefByLabel.cjs.map +1 -1
  111. package/dist/lib/findRefByLabel.d.ts +1 -1
  112. package/dist/lib/findRefByLabel.js.map +1 -1
  113. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  114. package/dist/lib/getPreviewCookie.js.map +1 -1
  115. package/dist/lib/hastSerializerHelpers.cjs.map +1 -1
  116. package/dist/lib/hastSerializerHelpers.d.ts +3 -3
  117. package/dist/lib/hastSerializerHelpers.js.map +1 -1
  118. package/dist/lib/hastToRichText.cjs +3 -4
  119. package/dist/lib/hastToRichText.cjs.map +1 -1
  120. package/dist/lib/hastToRichText.d.ts +4 -4
  121. package/dist/lib/hastToRichText.js +3 -4
  122. package/dist/lib/hastToRichText.js.map +1 -1
  123. package/dist/lib/isInternalURL.cjs.map +1 -1
  124. package/dist/lib/isInternalURL.js.map +1 -1
  125. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
  126. package/dist/lib/minifyGraphQLQuery.js.map +1 -1
  127. package/dist/lib/rehypeRichText.cjs.map +1 -1
  128. package/dist/lib/rehypeRichText.d.ts +5 -5
  129. package/dist/lib/rehypeRichText.js.map +1 -1
  130. package/dist/lib/serializerHelpers.cjs.map +1 -1
  131. package/dist/lib/serializerHelpers.d.ts +2 -2
  132. package/dist/lib/serializerHelpers.js.map +1 -1
  133. package/dist/lib/someTagsFilter.cjs.map +1 -1
  134. package/dist/lib/someTagsFilter.js.map +1 -1
  135. package/dist/lib/typeFilter.cjs.map +1 -1
  136. package/dist/lib/typeFilter.js.map +1 -1
  137. package/dist/package.json.cjs +1 -1
  138. package/dist/package.json.js +1 -1
  139. package/dist/richtext/asText.cjs.map +1 -1
  140. package/dist/richtext/asText.d.ts +1 -1
  141. package/dist/richtext/asText.js.map +1 -1
  142. package/dist/richtext/asTree.cjs.map +1 -1
  143. package/dist/richtext/asTree.d.ts +2 -2
  144. package/dist/richtext/asTree.js.map +1 -1
  145. package/dist/richtext/composeSerializers.cjs.map +1 -1
  146. package/dist/richtext/composeSerializers.d.ts +1 -1
  147. package/dist/richtext/composeSerializers.js.map +1 -1
  148. package/dist/richtext/serialize.cjs.map +1 -1
  149. package/dist/richtext/serialize.d.ts +1 -1
  150. package/dist/richtext/serialize.js.map +1 -1
  151. package/dist/richtext/types.cjs.map +1 -1
  152. package/dist/richtext/types.d.ts +1 -1
  153. package/dist/richtext/types.js.map +1 -1
  154. package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
  155. package/dist/richtext/wrapMapSerializer.d.ts +1 -1
  156. package/dist/richtext/wrapMapSerializer.js.map +1 -1
  157. package/dist/types/api/query.d.ts +1 -1
  158. package/dist/types/api/release.d.ts +1 -1
  159. package/dist/types/api/repository.d.ts +1 -1
  160. package/dist/types/model/customType.d.ts +1 -1
  161. package/dist/types/model/link.cjs.map +1 -1
  162. package/dist/types/model/link.js.map +1 -1
  163. package/dist/types/model/slice.cjs.map +1 -1
  164. package/dist/types/model/slice.js.map +1 -1
  165. package/dist/types/model/sliceZone.cjs.map +1 -1
  166. package/dist/types/model/sliceZone.js.map +1 -1
  167. package/dist/types/model/title.d.ts +1 -1
  168. package/dist/types/model/types.cjs.map +1 -1
  169. package/dist/types/model/types.js.map +1 -1
  170. package/dist/types/value/document.d.ts +4 -4
  171. package/dist/types/value/embed.cjs.map +1 -1
  172. package/dist/types/value/embed.js.map +1 -1
  173. package/dist/types/value/link.cjs.map +1 -1
  174. package/dist/types/value/link.js.map +1 -1
  175. package/dist/types/value/richText.cjs.map +1 -1
  176. package/dist/types/value/richText.js.map +1 -1
  177. package/dist/types/webhook/apiUpdate.d.ts +1 -1
  178. package/dist/types/webhook/testTrigger.d.ts +1 -1
  179. package/dist/types/webhook/types.cjs.map +1 -1
  180. package/dist/types/webhook/types.d.ts +2 -2
  181. package/dist/types/webhook/types.js.map +1 -1
  182. package/package.json +1 -1
  183. package/src/buildQueryURL.ts +51 -51
  184. package/src/cookie.ts +1 -1
  185. package/src/createClient.ts +293 -293
  186. package/src/errors/ForbiddenError.ts +6 -6
  187. package/src/errors/NotFoundError.ts +1 -1
  188. package/src/errors/ParsingError.ts +8 -8
  189. package/src/errors/PreviewTokenExpired.ts +4 -4
  190. package/src/errors/PrismicError.ts +5 -5
  191. package/src/errors/PrismicRichTextSerializerError.ts +1 -1
  192. package/src/errors/RefExpiredError.ts +4 -4
  193. package/src/errors/RefNotFoundError.ts +4 -4
  194. package/src/errors/RepositoryNotFoundError.ts +1 -1
  195. package/src/filter.ts +22 -22
  196. package/src/getGraphQLEndpoint.ts +5 -5
  197. package/src/getRepositoryEndpoint.ts +5 -5
  198. package/src/getRepositoryName.ts +4 -4
  199. package/src/getToolbarSrc.ts +5 -5
  200. package/src/helpers/asDate.ts +7 -7
  201. package/src/helpers/asHTML.ts +54 -56
  202. package/src/helpers/asImagePixelDensitySrcSet.ts +14 -17
  203. package/src/helpers/asImageSrc.ts +9 -8
  204. package/src/helpers/asImageWidthSrcSet.ts +19 -22
  205. package/src/helpers/asLink.ts +26 -27
  206. package/src/helpers/asLinkAttrs.ts +30 -29
  207. package/src/helpers/asText.ts +15 -15
  208. package/src/helpers/documentToLinkField.ts +6 -6
  209. package/src/helpers/isFilled.ts +53 -53
  210. package/src/helpers/mapSliceZone.ts +34 -34
  211. package/src/helpers/unstable_htmlAsRichText.ts +23 -22
  212. package/src/helpers/unstable_markdownAsRichText.ts +14 -13
  213. package/src/index.ts +119 -119
  214. package/src/isRepositoryEndpoint.ts +4 -4
  215. package/src/isRepositoryName.ts +2 -2
  216. package/src/lib/RichTextFieldBuilder.ts +36 -41
  217. package/src/lib/appendFilters.ts +4 -4
  218. package/src/lib/castArray.ts +2 -2
  219. package/src/lib/castThunk.ts +2 -2
  220. package/src/lib/devMsg.ts +4 -4
  221. package/src/lib/escapeHTML.ts +24 -24
  222. package/src/lib/everyTagFilter.ts +4 -4
  223. package/src/lib/filterRichTextField.ts +31 -31
  224. package/src/lib/findMasterRef.ts +4 -4
  225. package/src/lib/findRef.ts +6 -6
  226. package/src/lib/findRefByID.ts +4 -4
  227. package/src/lib/findRefByLabel.ts +4 -4
  228. package/src/lib/getPreviewCookie.ts +11 -11
  229. package/src/lib/hastSerializerHelpers.ts +41 -37
  230. package/src/lib/hastToRichText.ts +74 -73
  231. package/src/lib/isInternalURL.ts +4 -4
  232. package/src/lib/minifyGraphQLQuery.ts +2 -2
  233. package/src/lib/rehypeRichText.ts +42 -41
  234. package/src/lib/serializerHelpers.ts +53 -54
  235. package/src/lib/someTagsFilter.ts +4 -4
  236. package/src/lib/typeFilter.ts +3 -3
  237. package/src/richtext/asText.ts +5 -5
  238. package/src/richtext/asTree.ts +53 -53
  239. package/src/richtext/composeSerializers.ts +6 -6
  240. package/src/richtext/index.ts +7 -7
  241. package/src/richtext/serialize.ts +11 -11
  242. package/src/richtext/types.ts +38 -38
  243. package/src/richtext/wrapMapSerializer.ts +6 -9
  244. package/src/types/api/query.ts +9 -9
  245. package/src/types/api/ref.ts +5 -5
  246. package/src/types/api/release.ts +2 -2
  247. package/src/types/api/repository.ts +24 -24
  248. package/src/types/api/tags.ts +1 -1
  249. package/src/types/model/boolean.ts +7 -7
  250. package/src/types/model/color.ts +5 -5
  251. package/src/types/model/contentRelationship.ts +9 -9
  252. package/src/types/model/customType.ts +9 -9
  253. package/src/types/model/date.ts +6 -6
  254. package/src/types/model/embed.ts +5 -5
  255. package/src/types/model/geoPoint.ts +4 -4
  256. package/src/types/model/group.ts +6 -6
  257. package/src/types/model/image.ts +9 -9
  258. package/src/types/model/integration.ts +6 -6
  259. package/src/types/model/keyText.ts +5 -5
  260. package/src/types/model/link.ts +8 -8
  261. package/src/types/model/linkToMedia.ts +7 -7
  262. package/src/types/model/number.ts +7 -7
  263. package/src/types/model/range.ts +8 -8
  264. package/src/types/model/richText.ts +16 -16
  265. package/src/types/model/select.ts +7 -7
  266. package/src/types/model/separator.ts +4 -4
  267. package/src/types/model/sharedSlice.ts +7 -7
  268. package/src/types/model/sharedSliceVariation.ts +9 -9
  269. package/src/types/model/slice.ts +12 -12
  270. package/src/types/model/sliceZone.ts +11 -11
  271. package/src/types/model/timestamp.ts +6 -6
  272. package/src/types/model/title.ts +2 -2
  273. package/src/types/model/types.ts +26 -26
  274. package/src/types/model/uid.ts +5 -5
  275. package/src/types/value/boolean.ts +1 -1
  276. package/src/types/value/color.ts +2 -2
  277. package/src/types/value/contentRelationship.ts +15 -15
  278. package/src/types/value/date.ts +2 -2
  279. package/src/types/value/document.ts +23 -23
  280. package/src/types/value/embed.ts +33 -33
  281. package/src/types/value/geoPoint.ts +4 -4
  282. package/src/types/value/group.ts +3 -3
  283. package/src/types/value/image.ts +21 -21
  284. package/src/types/value/integration.ts +2 -2
  285. package/src/types/value/keyText.ts +2 -2
  286. package/src/types/value/link.ts +12 -12
  287. package/src/types/value/linkToMedia.ts +11 -11
  288. package/src/types/value/number.ts +2 -2
  289. package/src/types/value/richText.ts +58 -58
  290. package/src/types/value/select.ts +2 -2
  291. package/src/types/value/sharedSlice.ts +5 -5
  292. package/src/types/value/sharedSliceVariation.ts +5 -5
  293. package/src/types/value/slice.ts +6 -6
  294. package/src/types/value/sliceZone.ts +4 -4
  295. package/src/types/value/timestamp.ts +3 -3
  296. package/src/types/value/title.ts +4 -4
  297. package/src/types/value/types.ts +22 -22
  298. package/src/types/webhook/apiUpdate.ts +18 -18
  299. package/src/types/webhook/testTrigger.ts +2 -2
  300. package/src/types/webhook/types.ts +8 -8
  301. package/dist/_node_modules/hast-util-whitespace/lib/index.cjs +0 -11
  302. package/dist/_node_modules/hast-util-whitespace/lib/index.cjs.map +0 -1
  303. package/dist/_node_modules/hast-util-whitespace/lib/index.js +0 -11
  304. package/dist/_node_modules/hast-util-whitespace/lib/index.js.map +0 -1
@@ -1,55 +1,56 @@
1
- import type { RichTextMapSerializer } from "../richtext/types";
2
- import { LinkType } from "../types/value/link";
3
- import { RTAnyNode } from "../types/value/richText";
1
+ import type { RichTextMapSerializer } from "../richtext/types"
2
+ import { LinkType } from "../types/value/link"
3
+ import type { RTAnyNode } from "../types/value/richText"
4
4
 
5
- import {
5
+ import type {
6
6
  HTMLRichTextMapSerializer,
7
7
  HTMLStrictRichTextMapSerializer,
8
- } from "../helpers/asHTML";
9
- import { LinkResolverFunction, asLink } from "../helpers/asLink";
8
+ } from "../helpers/asHTML"
9
+ import type { LinkResolverFunction } from "../helpers/asLink"
10
+ import { asLink } from "../helpers/asLink"
10
11
 
11
- import { escapeHTML } from "./escapeHTML";
12
+ import { escapeHTML } from "./escapeHTML"
12
13
 
13
- type Attributes = Record<string, string | boolean | null | undefined>;
14
+ type Attributes = Record<string, string | boolean | null | undefined>
14
15
  const formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {
15
- const _attributes = { ...attributes };
16
+ const _attributes = { ...attributes }
16
17
 
17
18
  // Add label to attributes
18
19
  if ("data" in node && "label" in node.data && node.data.label) {
19
20
  _attributes.class = _attributes.class
20
21
  ? `${_attributes.class} ${node.data.label}`
21
- : node.data.label;
22
+ : node.data.label
22
23
  }
23
24
 
24
- const result = [];
25
+ const result = []
25
26
 
26
27
  for (const key in _attributes) {
27
- const value = _attributes[key];
28
+ const value = _attributes[key]
28
29
 
29
30
  if (value) {
30
31
  if (typeof value === "boolean") {
31
- result.push(key);
32
+ result.push(key)
32
33
  } else {
33
- result.push(`${key}="${escapeHTML(value)}"`);
34
+ result.push(`${key}="${escapeHTML(value)}"`)
34
35
  }
35
36
  }
36
37
  }
37
38
 
38
39
  // Add a space at the beginning if there's any result
39
40
  if (result.length) {
40
- result.unshift("");
41
+ result.unshift("")
41
42
  }
42
43
 
43
- return result.join(" ");
44
- };
44
+ return result.join(" ")
45
+ }
45
46
 
46
47
  const getGeneralAttributes = (
47
48
  serializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],
48
49
  ): Attributes => {
49
50
  return serializerOrShorthand && typeof serializerOrShorthand !== "function"
50
51
  ? serializerOrShorthand
51
- : {};
52
- };
52
+ : {}
53
+ }
53
54
 
54
55
  export const serializeStandardTag = <
55
56
  BlockType extends keyof RichTextMapSerializer<string>,
@@ -57,27 +58,27 @@ export const serializeStandardTag = <
57
58
  tag: string,
58
59
  serializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],
59
60
  ): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {
60
- const generalAttributes = getGeneralAttributes(serializerOrShorthand);
61
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand)
61
62
 
62
63
  return (({ node, children }) => {
63
64
  return `<${tag}${formatAttributes(
64
65
  node,
65
66
  generalAttributes,
66
- )}>${children}</${tag}>`;
67
- }) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>;
68
- };
67
+ )}>${children}</${tag}>`
68
+ }) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>
69
+ }
69
70
 
70
71
  export const serializePreFormatted = (
71
72
  serializerOrShorthand?: HTMLRichTextMapSerializer["preformatted"],
72
73
  ): NonNullable<HTMLStrictRichTextMapSerializer["preformatted"]> => {
73
- const generalAttributes = getGeneralAttributes(serializerOrShorthand);
74
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand)
74
75
 
75
76
  return ({ node }) => {
76
77
  return `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(
77
78
  node.text,
78
- )}</pre>`;
79
- };
80
- };
79
+ )}</pre>`
80
+ }
81
+ }
81
82
 
82
83
  export const serializeImage = (
83
84
  linkResolver:
@@ -86,7 +87,7 @@ export const serializeImage = (
86
87
  | null,
87
88
  serializerOrShorthand?: HTMLRichTextMapSerializer["image"],
88
89
  ): NonNullable<HTMLStrictRichTextMapSerializer["image"]> => {
89
- const generalAttributes = getGeneralAttributes(serializerOrShorthand);
90
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand)
90
91
 
91
92
  return ({ node }) => {
92
93
  const attributes = {
@@ -94,9 +95,9 @@ export const serializeImage = (
94
95
  src: node.url,
95
96
  alt: node.alt,
96
97
  copyright: node.copyright,
97
- };
98
+ }
98
99
 
99
- let imageTag = `<img${formatAttributes(node, attributes)} />`;
100
+ let imageTag = `<img${formatAttributes(node, attributes)} />`
100
101
 
101
102
  // If the image has a link, we wrap it with an anchor tag
102
103
  if (node.linkTo) {
@@ -111,17 +112,17 @@ export const serializeImage = (
111
112
  text: "",
112
113
  children: imageTag,
113
114
  key: "",
114
- })!;
115
+ })!
115
116
  }
116
117
 
117
- return `<p class="block-img">${imageTag}</p>`;
118
- };
119
- };
118
+ return `<p class="block-img">${imageTag}</p>`
119
+ }
120
+ }
120
121
 
121
122
  export const serializeEmbed = (
122
123
  serializerOrShorthand?: HTMLRichTextMapSerializer["embed"],
123
124
  ): NonNullable<HTMLStrictRichTextMapSerializer["embed"]> => {
124
- const generalAttributes = getGeneralAttributes(serializerOrShorthand);
125
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand)
125
126
 
126
127
  return ({ node }) => {
127
128
  const attributes = {
@@ -129,13 +130,11 @@ export const serializeEmbed = (
129
130
  ["data-oembed"]: node.oembed.embed_url,
130
131
  ["data-oembed-type"]: node.oembed.type,
131
132
  ["data-oembed-provider"]: node.oembed.provider_name,
132
- };
133
+ }
133
134
 
134
- return `<div${formatAttributes(node, attributes)}>${
135
- node.oembed.html
136
- }</div>`;
137
- };
138
- };
135
+ return `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`
136
+ }
137
+ }
139
138
 
140
139
  export const serializeHyperlink = (
141
140
  linkResolver:
@@ -144,31 +143,31 @@ export const serializeHyperlink = (
144
143
  | null,
145
144
  serializerOrShorthand?: HTMLRichTextMapSerializer["hyperlink"],
146
145
  ): NonNullable<HTMLStrictRichTextMapSerializer["hyperlink"]> => {
147
- const generalAttributes = getGeneralAttributes(serializerOrShorthand);
146
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand)
148
147
 
149
148
  return ({ node, children }): string => {
150
149
  const attributes = {
151
150
  ...generalAttributes,
152
- };
151
+ }
153
152
 
154
153
  if (node.data.link_type === LinkType.Web) {
155
- attributes.href = node.data.url;
156
- attributes.target = node.data.target;
157
- attributes.rel = "noopener noreferrer";
154
+ attributes.href = node.data.url
155
+ attributes.target = node.data.target
156
+ attributes.rel = "noopener noreferrer"
158
157
  } else if (node.data.link_type === LinkType.Document) {
159
- attributes.href = asLink(node.data, { linkResolver });
158
+ attributes.href = asLink(node.data, { linkResolver })
160
159
  } else if (node.data.link_type === LinkType.Media) {
161
- attributes.href = node.data.url;
160
+ attributes.href = node.data.url
162
161
  }
163
162
 
164
- return `<a${formatAttributes(node, attributes)}>${children}</a>`;
165
- };
166
- };
163
+ return `<a${formatAttributes(node, attributes)}>${children}</a>`
164
+ }
165
+ }
167
166
 
168
167
  export const serializeSpan = (): NonNullable<
169
168
  HTMLStrictRichTextMapSerializer["span"]
170
169
  > => {
171
170
  return ({ text }): string => {
172
- return text ? escapeHTML(text).replace(/\n/g, "<br />") : "";
173
- };
174
- };
171
+ return text ? escapeHTML(text).replace(/\n/g, "<br />") : ""
172
+ }
173
+ }
@@ -1,6 +1,6 @@
1
- import { filter } from "../filter";
1
+ import { filter } from "../filter"
2
2
 
3
- import { castArray } from "./castArray";
3
+ import { castArray } from "./castArray"
4
4
 
5
5
  /**
6
6
  * Creates a filter to filter content by document tags. At least one matching
@@ -11,5 +11,5 @@ import { castArray } from "./castArray";
11
11
  * @returns A filter that can be used in a Prismic REST API V2 request.
12
12
  */
13
13
  export const someTagsFilter = (tags: string | string[]): string => {
14
- return filter.any("document.tags", castArray(tags));
15
- };
14
+ return filter.any("document.tags", castArray(tags))
15
+ }
@@ -1,4 +1,4 @@
1
- import { filter } from "../filter";
1
+ import { filter } from "../filter"
2
2
 
3
3
  /**
4
4
  * Creates a filter to filter content by document type.
@@ -8,5 +8,5 @@ import { filter } from "../filter";
8
8
  * @returns A filter that can be used in a Prismic REST API V2 request.
9
9
  */
10
10
  export const typeFilter = (documentType: string): string => {
11
- return filter.at("document.type", documentType);
12
- };
11
+ return filter.at("document.type", documentType)
12
+ }
@@ -1,4 +1,4 @@
1
- import { RTTextNode, RichTextField } from "../types/value/richText";
1
+ import type { RTTextNode, RichTextField } from "../types/value/richText"
2
2
 
3
3
  /**
4
4
  * Serializes a rich text or title field to a plain text string
@@ -14,14 +14,14 @@ export const asText = (
14
14
  richTextField: RichTextField,
15
15
  separator = " ",
16
16
  ): string => {
17
- let result = "";
17
+ let result = ""
18
18
 
19
19
  for (let i = 0; i < richTextField.length; i++) {
20
20
  if ("text" in richTextField[i]) {
21
21
  result +=
22
- (result ? separator : "") + (richTextField[i] as RTTextNode).text;
22
+ (result ? separator : "") + (richTextField[i] as RTTextNode).text
23
23
  }
24
24
  }
25
25
 
26
- return result;
27
- };
26
+ return result
27
+ }
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  RTAnyNode,
3
3
  RTBlockNode,
4
4
  RTInlineNode,
@@ -6,14 +6,14 @@ import {
6
6
  RTNode,
7
7
  RTOListItemNode,
8
8
  RTTextNode,
9
- RichTextNodeType,
10
- } from "../types/value/richText";
11
- import { Tree, TreeNode } from "./types";
9
+ } from "../types/value/richText"
10
+ import { RichTextNodeType } from "../types/value/richText"
11
+ import type { Tree, TreeNode } from "./types"
12
12
 
13
13
  const uuid = (): string => {
14
- return (++uuid.i).toString();
15
- };
16
- uuid.i = 0;
14
+ return (++uuid.i).toString()
15
+ }
16
+ uuid.i = 0
17
17
 
18
18
  /**
19
19
  * Parses a rich text or title field into a tree
@@ -27,18 +27,18 @@ uuid.i = 0;
27
27
  * @returns Tree from given rich text or title field
28
28
  */
29
29
  export const asTree = (nodes: RTNode[]): Tree => {
30
- const preparedNodes = prepareNodes(nodes);
30
+ const preparedNodes = prepareNodes(nodes)
31
31
 
32
- const children: TreeNode[] = [];
32
+ const children: TreeNode[] = []
33
33
  for (let i = 0; i < preparedNodes.length; i++) {
34
- children.push(nodeToTreeNode(preparedNodes[i]));
34
+ children.push(nodeToTreeNode(preparedNodes[i]))
35
35
  }
36
36
 
37
37
  return {
38
38
  key: uuid(),
39
39
  children,
40
- };
41
- };
40
+ }
41
+ }
42
42
 
43
43
  const createTreeNode = (
44
44
  node: RTAnyNode,
@@ -50,22 +50,22 @@ const createTreeNode = (
50
50
  text: "text" in node ? node.text : undefined,
51
51
  node,
52
52
  children,
53
- };
54
- };
53
+ }
54
+ }
55
55
 
56
56
  const createTextTreeNode = (text: string): TreeNode => {
57
57
  return createTreeNode({
58
58
  type: RichTextNodeType.span,
59
59
  text,
60
60
  spans: [],
61
- });
62
- };
61
+ })
62
+ }
63
63
 
64
64
  const prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {
65
- const mutNodes: RTBlockNode[] = nodes.slice(0);
65
+ const mutNodes: RTBlockNode[] = nodes.slice(0)
66
66
 
67
67
  for (let i = 0; i < mutNodes.length; i++) {
68
- const node = mutNodes[i];
68
+ const node = mutNodes[i]
69
69
 
70
70
  if (
71
71
  node.type === RichTextNodeType.listItem ||
@@ -73,49 +73,49 @@ const prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {
73
73
  ) {
74
74
  const items: (RTListItemNode | RTOListItemNode)[] = [
75
75
  node as RTListItemNode | RTOListItemNode,
76
- ];
76
+ ]
77
77
 
78
78
  while (mutNodes[i + 1] && mutNodes[i + 1].type === node.type) {
79
- items.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode);
80
- mutNodes.splice(i, 1);
79
+ items.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode)
80
+ mutNodes.splice(i, 1)
81
81
  }
82
82
 
83
83
  if (node.type === RichTextNodeType.listItem) {
84
84
  mutNodes[i] = {
85
85
  type: RichTextNodeType.list,
86
86
  items: items as RTListItemNode[],
87
- };
87
+ }
88
88
  } else {
89
89
  mutNodes[i] = {
90
90
  type: RichTextNodeType.oList,
91
91
  items: items as RTOListItemNode[],
92
- };
92
+ }
93
93
  }
94
94
  }
95
95
  }
96
96
 
97
- return mutNodes;
98
- };
97
+ return mutNodes
98
+ }
99
99
 
100
100
  const nodeToTreeNode = (node: RTBlockNode): TreeNode => {
101
101
  if ("text" in node) {
102
102
  return createTreeNode(
103
103
  node,
104
104
  textNodeSpansToTreeNodeChildren(node.spans, node),
105
- );
105
+ )
106
106
  }
107
107
 
108
108
  if ("items" in node) {
109
- const children: TreeNode[] = [];
109
+ const children: TreeNode[] = []
110
110
  for (let i = 0; i < node.items.length; i++) {
111
- children.push(nodeToTreeNode(node.items[i]));
111
+ children.push(nodeToTreeNode(node.items[i]))
112
112
  }
113
113
 
114
- return createTreeNode(node, children);
114
+ return createTreeNode(node, children)
115
115
  }
116
116
 
117
- return createTreeNode(node);
118
- };
117
+ return createTreeNode(node)
118
+ }
119
119
 
120
120
  const textNodeSpansToTreeNodeChildren = (
121
121
  spans: RTInlineNode[],
@@ -123,10 +123,10 @@ const textNodeSpansToTreeNodeChildren = (
123
123
  parentSpan?: RTInlineNode,
124
124
  ): TreeNode[] => {
125
125
  if (!spans.length) {
126
- return [createTextTreeNode(node.text)];
126
+ return [createTextTreeNode(node.text)]
127
127
  }
128
128
 
129
- const mutSpans: RTInlineNode[] = spans.slice(0);
129
+ const mutSpans: RTInlineNode[] = spans.slice(0)
130
130
 
131
131
  // Sort spans using the following criteria:
132
132
  //
@@ -138,26 +138,26 @@ const textNodeSpansToTreeNodeChildren = (
138
138
  //
139
139
  // Sorting using this algorithm ensures proper detection of child
140
140
  // spans.
141
- mutSpans.sort((a, b) => a.start - b.start || b.end - a.end);
141
+ mutSpans.sort((a, b) => a.start - b.start || b.end - a.end)
142
142
 
143
- const children: TreeNode[] = [];
143
+ const children: TreeNode[] = []
144
144
 
145
145
  for (let i = 0; i < mutSpans.length; i++) {
146
- const span = mutSpans[i];
147
- const parentSpanStart = (parentSpan && parentSpan.start) || 0;
148
- const spanStart = span.start - parentSpanStart;
149
- const spanEnd = span.end - parentSpanStart;
150
- const text = node.text.slice(spanStart, spanEnd);
146
+ const span = mutSpans[i]
147
+ const parentSpanStart = (parentSpan && parentSpan.start) || 0
148
+ const spanStart = span.start - parentSpanStart
149
+ const spanEnd = span.end - parentSpanStart
150
+ const text = node.text.slice(spanStart, spanEnd)
151
151
 
152
- const childSpans: RTInlineNode[] = [];
152
+ const childSpans: RTInlineNode[] = []
153
153
  for (let j = i; j < mutSpans.length; j++) {
154
- const siblingSpan = mutSpans[j];
154
+ const siblingSpan = mutSpans[j]
155
155
 
156
156
  if (siblingSpan !== span) {
157
157
  if (siblingSpan.start >= span.start && siblingSpan.end <= span.end) {
158
- childSpans.push(siblingSpan);
159
- mutSpans.splice(j, 1);
160
- j--;
158
+ childSpans.push(siblingSpan)
159
+ mutSpans.splice(j, 1)
160
+ j--
161
161
  } else if (
162
162
  siblingSpan.start < span.end &&
163
163
  siblingSpan.end > span.start
@@ -165,20 +165,20 @@ const textNodeSpansToTreeNodeChildren = (
165
165
  childSpans.push({
166
166
  ...siblingSpan,
167
167
  end: span.end,
168
- });
168
+ })
169
169
  mutSpans[j] = {
170
170
  ...siblingSpan,
171
171
  start: span.end,
172
- };
172
+ }
173
173
  }
174
174
  }
175
175
  }
176
176
 
177
177
  if (i === 0 && spanStart > 0) {
178
- children.push(createTextTreeNode(node.text.slice(0, spanStart)));
178
+ children.push(createTextTreeNode(node.text.slice(0, spanStart)))
179
179
  }
180
180
 
181
- const spanWithText = { ...span, text };
181
+ const spanWithText = { ...span, text }
182
182
  children.push(
183
183
  createTreeNode(
184
184
  spanWithText,
@@ -191,7 +191,7 @@ const textNodeSpansToTreeNodeChildren = (
191
191
  span,
192
192
  ),
193
193
  ),
194
- );
194
+ )
195
195
 
196
196
  if (spanEnd < node.text.length) {
197
197
  children.push(
@@ -203,9 +203,9 @@ const textNodeSpansToTreeNodeChildren = (
203
203
  : undefined,
204
204
  ),
205
205
  ),
206
- );
206
+ )
207
207
  }
208
208
  }
209
209
 
210
- return children;
211
- };
210
+ return children
211
+ }
@@ -1,4 +1,4 @@
1
- import { RichTextFunctionSerializer } from "./types";
1
+ import type { RichTextFunctionSerializer } from "./types"
2
2
 
3
3
  /**
4
4
  * Takes an array of serializers and returns a serializer applying provided
@@ -22,15 +22,15 @@ export const composeSerializers = <SerializerReturnType>(
22
22
  ): RichTextFunctionSerializer<SerializerReturnType> => {
23
23
  return (...args) => {
24
24
  for (let i = 0; i < serializers.length; i++) {
25
- const serializer = serializers[i];
25
+ const serializer = serializers[i]
26
26
 
27
27
  if (serializer) {
28
- const res = serializer(...args);
28
+ const res = serializer(...args)
29
29
 
30
30
  if (res != null) {
31
- return res;
31
+ return res
32
32
  }
33
33
  }
34
34
  }
35
- };
36
- };
35
+ }
36
+ }
@@ -1,14 +1,14 @@
1
- export { asTree } from "./asTree";
2
- export { asText } from "./asText";
1
+ export { asTree } from "./asTree"
2
+ export { asText } from "./asText"
3
3
 
4
- export { serialize } from "./serialize";
5
- export { wrapMapSerializer } from "./wrapMapSerializer";
6
- export { composeSerializers } from "./composeSerializers";
4
+ export { serialize } from "./serialize"
5
+ export { wrapMapSerializer } from "./wrapMapSerializer"
6
+ export { composeSerializers } from "./composeSerializers"
7
7
 
8
- export { RichTextNodeType as Element } from "../types/value/richText";
8
+ export { RichTextNodeType as Element } from "../types/value/richText"
9
9
 
10
10
  export type {
11
11
  RichTextFunctionSerializer,
12
12
  RichTextMapSerializer,
13
13
  RichTextMapSerializerFunction,
14
- } from "./types";
14
+ } from "./types"
@@ -1,7 +1,7 @@
1
- import type { RichTextField } from "../types/value/richText";
2
- import { RichTextFunctionSerializer, TreeNode } from "./types";
1
+ import type { RichTextField } from "../types/value/richText"
2
+ import type { RichTextFunctionSerializer, TreeNode } from "./types"
3
3
 
4
- import { asTree } from "./asTree";
4
+ import { asTree } from "./asTree"
5
5
 
6
6
  /**
7
7
  * Serializes a rich text or title field with a given serializer
@@ -26,29 +26,29 @@ export const serialize = <SerializerReturnType>(
26
26
  return serializeTreeNodes<SerializerReturnType>(
27
27
  asTree(richTextField).children,
28
28
  serializer,
29
- );
30
- };
29
+ )
30
+ }
31
31
 
32
32
  const serializeTreeNodes = <T>(
33
33
  nodes: TreeNode[],
34
34
  serializer: RichTextFunctionSerializer<T>,
35
35
  ): T[] => {
36
- const serializedTreeNodes: T[] = [];
36
+ const serializedTreeNodes: T[] = []
37
37
 
38
38
  for (let i = 0; i < nodes.length; i++) {
39
- const treeNode = nodes[i];
39
+ const treeNode = nodes[i]
40
40
  const serializedTreeNode = serializer(
41
41
  treeNode.type,
42
42
  treeNode.node,
43
43
  treeNode.text,
44
44
  serializeTreeNodes(treeNode.children, serializer),
45
45
  treeNode.key,
46
- );
46
+ )
47
47
 
48
48
  if (serializedTreeNode != null) {
49
- serializedTreeNodes.push(serializedTreeNode);
49
+ serializedTreeNodes.push(serializedTreeNode)
50
50
  }
51
51
  }
52
52
 
53
- return serializedTreeNodes;
54
- };
53
+ return serializedTreeNodes
54
+ }