@prismicio/client 7.7.3 → 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 +1 -2
  119. package/dist/lib/hastToRichText.cjs.map +1 -1
  120. package/dist/lib/hastToRichText.d.ts +4 -4
  121. package/dist/lib/hastToRichText.js +1 -2
  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
@@ -10,5 +10,5 @@
10
10
  * @returns `a` as an array.
11
11
  */
12
12
  export const castArray = <A>(a: A | A[]): A[] => {
13
- return Array.isArray(a) ? a : [a];
14
- };
13
+ return Array.isArray(a) ? a : [a]
14
+ }
@@ -9,5 +9,5 @@
9
9
  * @returns `a` as a a thunk.
10
10
  */
11
11
  export const castThunk = <A>(a: A | (() => A)): (() => A) => {
12
- return typeof a === "function" ? (a as () => A) : () => a;
13
- };
12
+ return typeof a === "function" ? (a as () => A) : () => a
13
+ }
package/src/lib/devMsg.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { version } from "../../package.json";
1
+ import { version } from "../../package.json"
2
2
 
3
3
  /**
4
4
  * Returns a `prismic.dev/msg` URL for a given message slug.
@@ -6,7 +6,7 @@ import { version } from "../../package.json";
6
6
  * @example
7
7
  *
8
8
  * ```ts
9
- * devMsg("missing-param");
9
+ * devMsg("missing-param")
10
10
  * // => "https://prismic.dev/msg/client/v1.2.3/missing-param.md"
11
11
  * ```
12
12
  *
@@ -16,5 +16,5 @@ import { version } from "../../package.json";
16
16
  * @returns The `prismic.dev/msg` URL for the given slug.
17
17
  */
18
18
  export const devMsg = (slug: string): string => {
19
- return `https://prismic.dev/msg/client/v${version}/${slug}`;
20
- };
19
+ return `https://prismic.dev/msg/client/v${version}/${slug}`
20
+ }
@@ -3,49 +3,49 @@
3
3
  ** Many thanks to @component
4
4
  */
5
5
 
6
- const matchHtmlRegExp = /["'&<>]/;
6
+ const matchHtmlRegExp = /["'&<>]/
7
7
 
8
8
  export const escapeHTML = (string?: string | null): string => {
9
- const str = "" + string;
10
- const match = matchHtmlRegExp.exec(str);
9
+ const str = "" + string
10
+ const match = matchHtmlRegExp.exec(str)
11
11
 
12
12
  if (!match) {
13
- return str;
13
+ return str
14
14
  }
15
15
 
16
- let escape;
17
- let html = "";
18
- let index = 0;
19
- let lastIndex = 0;
16
+ let escape
17
+ let html = ""
18
+ let index = 0
19
+ let lastIndex = 0
20
20
 
21
21
  for (index = match.index; index < str.length; index++) {
22
22
  switch (str.charCodeAt(index)) {
23
23
  case 34: // "
24
- escape = "&quot;";
25
- break;
24
+ escape = "&quot;"
25
+ break
26
26
  case 38: // &
27
- escape = "&amp;";
28
- break;
27
+ escape = "&amp;"
28
+ break
29
29
  case 39: // '
30
- escape = "&#39;";
31
- break;
30
+ escape = "&#39;"
31
+ break
32
32
  case 60: // <
33
- escape = "&lt;";
34
- break;
33
+ escape = "&lt;"
34
+ break
35
35
  case 62: // >
36
- escape = "&gt;";
37
- break;
36
+ escape = "&gt;"
37
+ break
38
38
  default:
39
- continue;
39
+ continue
40
40
  }
41
41
 
42
42
  if (lastIndex !== index) {
43
- html += str.substring(lastIndex, index);
43
+ html += str.substring(lastIndex, index)
44
44
  }
45
45
 
46
- lastIndex = index + 1;
47
- html += escape;
46
+ lastIndex = index + 1
47
+ html += escape
48
48
  }
49
49
 
50
- return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
51
- };
50
+ return lastIndex !== index ? html + str.substring(lastIndex, index) : html
51
+ }
@@ -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. All tags are required on
@@ -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 everyTagFilter = (tags: string | string[]): string => {
14
- return filter.at("document.tags", castArray(tags));
15
- };
14
+ return filter.at("document.tags", castArray(tags))
15
+ }
@@ -1,14 +1,14 @@
1
- import { CustomTypeModelRichTextField } from "../types/model/richText";
2
- import { LinkType } from "../types/value/link";
3
- import {
1
+ import type { CustomTypeModelRichTextField } from "../types/model/richText"
2
+ import { LinkType } from "../types/value/link"
3
+ import type {
4
4
  RTImageNode,
5
5
  RTNode,
6
6
  RTTextNode,
7
7
  RichTextField,
8
- RichTextNodeType,
9
8
  RichTextNodeTypes,
10
- } from "../types/value/richText";
11
- import { TitleField } from "../types/value/title";
9
+ } from "../types/value/richText"
10
+ import { RichTextNodeType } from "../types/value/richText"
11
+ import type { TitleField } from "../types/value/title"
12
12
 
13
13
  /**
14
14
  * Get allowed nodes types from a rich text or title field custom type model.
@@ -20,26 +20,26 @@ import { TitleField } from "../types/value/title";
20
20
  const getAllowedNodeTypes = (
21
21
  model: CustomTypeModelRichTextField,
22
22
  ): RichTextNodeTypes[] => {
23
- const allowedNodeTypes: RichTextNodeTypes[] = []; // An empty array means no nodes are allowed by default.
23
+ const allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.
24
24
 
25
25
  if (model.config) {
26
26
  if ("multi" in model.config && model.config.multi) {
27
27
  allowedNodeTypes.push(
28
28
  ...(model.config.multi.split(",") as RichTextNodeTypes[]),
29
- );
29
+ )
30
30
  } else if ("single" in model.config && model.config.single) {
31
31
  allowedNodeTypes.push(
32
32
  ...(model.config.single.split(",") as RichTextNodeTypes[]),
33
- );
33
+ )
34
34
  }
35
35
 
36
36
  if (model.config.labels?.length) {
37
- allowedNodeTypes.push("label");
37
+ allowedNodeTypes.push("label")
38
38
  }
39
39
  }
40
40
 
41
- return allowedNodeTypes;
42
- };
41
+ return allowedNodeTypes
42
+ }
43
43
 
44
44
  /**
45
45
  * Filter an image node based on given model.
@@ -63,11 +63,11 @@ const filterImageNode = (
63
63
  ...node.linkTo,
64
64
  target: undefined,
65
65
  },
66
- };
66
+ }
67
67
  }
68
68
 
69
- return node;
70
- };
69
+ return node
70
+ }
71
71
 
72
72
  /**
73
73
  * Filter a text node based on given model.
@@ -86,10 +86,10 @@ const filterTextNode = (
86
86
  const filteredNode: RTTextNode = {
87
87
  ...node,
88
88
  spans: [],
89
- };
89
+ }
90
90
 
91
91
  for (let i = 0; i < node.spans.length; i++) {
92
- const span = node.spans[i];
92
+ const span = node.spans[i]
93
93
 
94
94
  if (allowedNodeTypes.includes(span.type)) {
95
95
  if (span.type === RichTextNodeType.hyperlink) {
@@ -103,22 +103,22 @@ const filterTextNode = (
103
103
  ...span.data,
104
104
  target: undefined,
105
105
  },
106
- });
106
+ })
107
107
  } else {
108
- filteredNode.spans.push(span);
108
+ filteredNode.spans.push(span)
109
109
  }
110
110
  } else if (span.type === RichTextNodeType.label) {
111
111
  if (model.config?.labels?.includes(span.data.label)) {
112
- filteredNode.spans.push(span);
112
+ filteredNode.spans.push(span)
113
113
  }
114
114
  } else {
115
- filteredNode.spans.push(span);
115
+ filteredNode.spans.push(span)
116
116
  }
117
117
  }
118
118
  }
119
119
 
120
- return filteredNode;
121
- };
120
+ return filteredNode
121
+ }
122
122
 
123
123
  /**
124
124
  * Filter a rich text field based on given model.
@@ -132,9 +132,9 @@ export const filterRichTextField = <Field extends RichTextField | TitleField>(
132
132
  richTextField: Field,
133
133
  model: CustomTypeModelRichTextField,
134
134
  ): Field => {
135
- const nodes: RTNode[] = [];
135
+ const nodes: RTNode[] = []
136
136
 
137
- const allowedNodeTypes = getAllowedNodeTypes(model);
137
+ const allowedNodeTypes = getAllowedNodeTypes(model)
138
138
 
139
139
  for (
140
140
  let i = 0;
@@ -142,18 +142,18 @@ export const filterRichTextField = <Field extends RichTextField | TitleField>(
142
142
  i < (model.config && "multi" in model.config ? richTextField.length : 1);
143
143
  i++
144
144
  ) {
145
- const node = richTextField[i];
145
+ const node = richTextField[i]
146
146
 
147
147
  if (allowedNodeTypes.includes(node.type)) {
148
148
  if (node.type === RichTextNodeType.image) {
149
- nodes.push(filterImageNode(node, model));
149
+ nodes.push(filterImageNode(node, model))
150
150
  } else if (node.type === RichTextNodeType.embed) {
151
- nodes.push(node);
151
+ nodes.push(node)
152
152
  } else {
153
- nodes.push(filterTextNode(node, model, allowedNodeTypes));
153
+ nodes.push(filterTextNode(node, model, allowedNodeTypes))
154
154
  }
155
155
  }
156
156
  }
157
157
 
158
- return nodes as Field;
159
- };
158
+ return nodes as Field
159
+ }
@@ -1,6 +1,6 @@
1
- import { Ref } from "../types/api/ref";
1
+ import type { Ref } from "../types/api/ref"
2
2
 
3
- import { findRef } from "./findRef";
3
+ import { findRef } from "./findRef"
4
4
 
5
5
  /**
6
6
  * Returns the master ref from a list of given refs.
@@ -12,5 +12,5 @@ import { findRef } from "./findRef";
12
12
  * @throws If a matching ref cannot be found.
13
13
  */
14
14
  export const findMasterRef = (refs: Ref[]): Ref => {
15
- return findRef(refs, (ref) => ref.isMasterRef);
16
- };
15
+ return findRef(refs, (ref) => ref.isMasterRef)
16
+ }
@@ -1,6 +1,6 @@
1
- import { Ref } from "../types/api/ref";
1
+ import type { Ref } from "../types/api/ref"
2
2
 
3
- import { PrismicError } from "../errors/PrismicError";
3
+ import { PrismicError } from "../errors/PrismicError"
4
4
 
5
5
  /**
6
6
  * Returns the first ref from a list that passes a filter (a function that
@@ -15,11 +15,11 @@ import { PrismicError } from "../errors/PrismicError";
15
15
  * @throws If a matching ref cannot be found.
16
16
  */
17
17
  export const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {
18
- const ref = refs.find((ref) => filter(ref));
18
+ const ref = refs.find((ref) => filter(ref))
19
19
 
20
20
  if (!ref) {
21
- throw new PrismicError("Ref could not be found.", undefined, undefined);
21
+ throw new PrismicError("Ref could not be found.", undefined, undefined)
22
22
  }
23
23
 
24
- return ref;
25
- };
24
+ return ref
25
+ }
@@ -1,6 +1,6 @@
1
- import { Ref } from "../types/api/ref";
1
+ import type { Ref } from "../types/api/ref"
2
2
 
3
- import { findRef } from "./findRef";
3
+ import { findRef } from "./findRef"
4
4
 
5
5
  /**
6
6
  * Returns the ref from a list of given refs with a matching ID.
@@ -13,5 +13,5 @@ import { findRef } from "./findRef";
13
13
  * @throws If a matching ref cannot be found.
14
14
  */
15
15
  export const findRefByID = (refs: Ref[], id: string): Ref => {
16
- return findRef(refs, (ref) => ref.id === id);
17
- };
16
+ return findRef(refs, (ref) => ref.id === id)
17
+ }
@@ -1,6 +1,6 @@
1
- import { Ref } from "../types/api/ref";
1
+ import type { Ref } from "../types/api/ref"
2
2
 
3
- import { findRef } from "./findRef";
3
+ import { findRef } from "./findRef"
4
4
 
5
5
  /**
6
6
  * Returns the ref from a list of given refs with a matching label.
@@ -13,5 +13,5 @@ import { findRef } from "./findRef";
13
13
  * @throws If a matching ref cannot be found.
14
14
  */
15
15
  export const findRefByLabel = (refs: Ref[], label: string): Ref => {
16
- return findRef(refs, (ref) => ref.label === label);
17
- };
16
+ return findRef(refs, (ref) => ref.label === label)
17
+ }
@@ -1,8 +1,8 @@
1
- import { preview as previewCookieName } from "../cookie";
1
+ import { preview as previewCookieName } from "../cookie"
2
2
 
3
3
  const readValue = (value: string): string => {
4
- return value.replace(/%3B/g, ";");
5
- };
4
+ return value.replace(/%3B/g, ";")
5
+ }
6
6
 
7
7
  /**
8
8
  * Returns the value of a cookie from a given cookie store.
@@ -13,19 +13,19 @@ const readValue = (value: string): string => {
13
13
  * @returns The value of the cookie, if it exists.
14
14
  */
15
15
  export const getPreviewCookie = (cookieJar: string): string | undefined => {
16
- const cookies = cookieJar.split("; ");
16
+ const cookies = cookieJar.split("; ")
17
17
 
18
- let value: string | undefined;
18
+ let value: string | undefined
19
19
 
20
20
  for (const cookie of cookies) {
21
- const parts = cookie.split("=");
22
- const name = readValue(parts[0]).replace(/%3D/g, "=");
21
+ const parts = cookie.split("=")
22
+ const name = readValue(parts[0]).replace(/%3D/g, "=")
23
23
 
24
24
  if (name === previewCookieName) {
25
- value = readValue(parts.slice(1).join("="));
26
- break;
25
+ value = readValue(parts.slice(1).join("="))
26
+ break
27
27
  }
28
28
  }
29
29
 
30
- return value;
31
- };
30
+ return value
31
+ }
@@ -1,13 +1,17 @@
1
- import { Element } from "hast";
2
- import { toHtml } from "hast-util-to-html";
1
+ import type { Element } from "hast"
2
+ import { toHtml } from "hast-util-to-html"
3
3
 
4
- import { OEmbedType } from "../types/value/embed";
5
- import { LinkType } from "../types/value/link";
6
- import { RTEmbedNode, RTImageNode, RTLinkNode } from "../types/value/richText";
4
+ import { OEmbedType } from "../types/value/embed"
5
+ import { LinkType } from "../types/value/link"
6
+ import type {
7
+ RTEmbedNode,
8
+ RTImageNode,
9
+ RTLinkNode,
10
+ } from "../types/value/richText"
7
11
 
8
- import { PrismicRichTextSerializerError } from "../errors/PrismicRichTextSerializerError";
12
+ import { PrismicRichTextSerializerError } from "../errors/PrismicRichTextSerializerError"
9
13
 
10
- import { RTPartialInlineNode } from "./RichTextFieldBuilder";
14
+ import type { RTPartialInlineNode } from "./RichTextFieldBuilder"
11
15
 
12
16
  /**
13
17
  * Serializes a hast {@link Element} node to a {@link RTImageNode}.
@@ -17,43 +21,43 @@ import { RTPartialInlineNode } from "./RichTextFieldBuilder";
17
21
  * @returns Equivalent {@link RTImageNode}.
18
22
  */
19
23
  export const serializeImage = (node: Element): RTImageNode => {
20
- const src = node.properties?.src as string | undefined;
24
+ const src = node.properties?.src as string | undefined
21
25
 
22
26
  if (!src) {
23
27
  throw new PrismicRichTextSerializerError(
24
28
  "Element of type `img` is missing an `src` attribute",
25
- );
29
+ )
26
30
  }
27
31
 
28
- const url = new URL(src, "https://noop.com");
32
+ const url = new URL(src, "https://noop.com")
29
33
 
30
- let width = node.properties?.width as number | undefined;
31
- let height = node.properties?.height as number | undefined;
32
- let x = 0;
33
- let y = 0;
34
- let zoom = 1;
34
+ let width = node.properties?.width as number | undefined
35
+ let height = node.properties?.height as number | undefined
36
+ let x = 0
37
+ let y = 0
38
+ let zoom = 1
35
39
 
36
40
  // Attempt to infer the image dimensions from the URL imgix parameters.
37
41
  if (url.hostname === "images.prismic.io") {
38
42
  if (url.searchParams.has("w")) {
39
- width = Number(url.searchParams.get("w"));
43
+ width = Number(url.searchParams.get("w"))
40
44
  }
41
45
 
42
46
  if (url.searchParams.has("h")) {
43
- height = Number(url.searchParams.get("h"));
47
+ height = Number(url.searchParams.get("h"))
44
48
  }
45
49
 
46
50
  if (url.searchParams.has("rect")) {
47
51
  const [rectX, rextY, rectW, _rectH] = url.searchParams
48
52
  .get("rect")!
49
- .split(",");
53
+ .split(",")
50
54
 
51
- x = Number(rectX);
52
- y = Number(rextY);
55
+ x = Number(rectX)
56
+ y = Number(rextY)
53
57
 
54
58
  // This is not perfect but it's supposed to work on images without constraints.
55
59
  if (width) {
56
- zoom = Math.max(1, width / Number(rectW));
60
+ zoom = Math.max(1, width / Number(rectW))
57
61
  }
58
62
  }
59
63
  }
@@ -69,8 +73,8 @@ export const serializeImage = (node: Element): RTImageNode => {
69
73
  // See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185
70
74
  dimensions: { width: width as number, height: height as number },
71
75
  edit: { x, y, zoom, background: "transparent" },
72
- };
73
- };
76
+ }
77
+ }
74
78
 
75
79
  /**
76
80
  * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.
@@ -80,12 +84,12 @@ export const serializeImage = (node: Element): RTImageNode => {
80
84
  * @returns Equivalent {@link RTEmbedNode}.
81
85
  */
82
86
  export const serializeEmbed = (node: Element): RTEmbedNode => {
83
- const src = node.properties?.src as string | undefined;
87
+ const src = node.properties?.src as string | undefined
84
88
 
85
89
  if (!src) {
86
90
  throw new PrismicRichTextSerializerError(
87
91
  "Element of type `embed` is missing an `src` attribute",
88
- );
92
+ )
89
93
  }
90
94
 
91
95
  const oembedBase = {
@@ -93,26 +97,26 @@ export const serializeEmbed = (node: Element): RTEmbedNode => {
93
97
  embed_url: src,
94
98
  html: toHtml(node),
95
99
  title: node.properties?.title as string | undefined,
96
- };
100
+ }
97
101
 
98
- const width = node.properties?.width as number | undefined;
99
- const height = node.properties?.height as number | undefined;
102
+ const width = node.properties?.width as number | undefined
103
+ const height = node.properties?.height as number | undefined
100
104
 
101
105
  // Remove the children of the embed node as we don't want to process them.
102
- node.children = [];
106
+ node.children = []
103
107
 
104
108
  if (width && height) {
105
109
  return {
106
110
  type: "embed",
107
111
  oembed: { ...oembedBase, type: OEmbedType.Rich, width, height },
108
- };
112
+ }
109
113
  } else {
110
114
  return {
111
115
  type: "embed",
112
116
  oembed: { ...oembedBase, type: OEmbedType.Link },
113
- };
117
+ }
114
118
  }
115
- };
119
+ }
116
120
 
117
121
  /**
118
122
  * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.
@@ -132,11 +136,11 @@ export const serializeSpan = (
132
136
  rtPartialInlineNode.type === "hyperlink" &&
133
137
  !("data" in rtPartialInlineNode)
134
138
  ) {
135
- const url = node.properties?.href as string | undefined;
139
+ const url = node.properties?.href as string | undefined
136
140
  if (!url) {
137
141
  throw new PrismicRichTextSerializerError(
138
142
  "Element of type `hyperlink` is missing an `href` attribute",
139
- );
143
+ )
140
144
  }
141
145
 
142
146
  return {
@@ -146,8 +150,8 @@ export const serializeSpan = (
146
150
  url,
147
151
  target: node.properties?.target as string | undefined,
148
152
  },
149
- };
153
+ }
150
154
  }
151
155
 
152
- return rtPartialInlineNode;
153
- };
156
+ return rtPartialInlineNode
157
+ }