@prismicio/client 7.7.2 → 7.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +1 -1
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.cjs.map +1 -1
- package/dist/cookie.js.map +1 -1
- package/dist/createClient.cjs +31 -31
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +35 -35
- package/dist/createClient.js +31 -31
- package/dist/createClient.js.map +1 -1
- package/dist/errors/ForbiddenError.cjs.map +1 -1
- package/dist/errors/ForbiddenError.js.map +1 -1
- package/dist/errors/NotFoundError.cjs.map +1 -1
- package/dist/errors/NotFoundError.js.map +1 -1
- package/dist/errors/ParsingError.cjs.map +1 -1
- package/dist/errors/ParsingError.js.map +1 -1
- package/dist/errors/PreviewTokenExpired.cjs.map +1 -1
- package/dist/errors/PreviewTokenExpired.js.map +1 -1
- package/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/errors/PrismicError.js.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.js.map +1 -1
- package/dist/errors/RefExpiredError.cjs.map +1 -1
- package/dist/errors/RefExpiredError.js.map +1 -1
- package/dist/errors/RefNotFoundError.cjs.map +1 -1
- package/dist/errors/RefNotFoundError.js.map +1 -1
- package/dist/errors/RepositoryNotFoundError.cjs.map +1 -1
- package/dist/errors/RepositoryNotFoundError.js.map +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +2 -2
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +2 -2
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +2 -2
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +2 -2
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +2 -4
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +2 -2
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +1 -1
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +1 -1
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/helpers/unstable_htmlAsRichText.cjs.map +1 -1
- package/dist/helpers/unstable_htmlAsRichText.d.ts +4 -4
- package/dist/helpers/unstable_htmlAsRichText.js.map +1 -1
- package/dist/helpers/unstable_markdownAsRichText.cjs.map +1 -1
- package/dist/helpers/unstable_markdownAsRichText.d.ts +2 -2
- package/dist/helpers/unstable_markdownAsRichText.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
- package/dist/lib/RichTextFieldBuilder.d.ts +1 -1
- package/dist/lib/RichTextFieldBuilder.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.d.ts +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/everyTagFilter.js.map +1 -1
- package/dist/lib/filterRichTextField.cjs.map +1 -1
- package/dist/lib/filterRichTextField.d.ts +3 -3
- package/dist/lib/filterRichTextField.js.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +1 -1
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +1 -1
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +1 -1
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +1 -1
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/hastSerializerHelpers.cjs.map +1 -1
- package/dist/lib/hastSerializerHelpers.d.ts +3 -3
- package/dist/lib/hastSerializerHelpers.js.map +1 -1
- package/dist/lib/hastToRichText.cjs +3 -4
- package/dist/lib/hastToRichText.cjs.map +1 -1
- package/dist/lib/hastToRichText.d.ts +4 -4
- package/dist/lib/hastToRichText.js +3 -4
- package/dist/lib/hastToRichText.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
- package/dist/lib/minifyGraphQLQuery.js.map +1 -1
- package/dist/lib/rehypeRichText.cjs.map +1 -1
- package/dist/lib/rehypeRichText.d.ts +5 -5
- package/dist/lib/rehypeRichText.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +2 -2
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs.map +1 -1
- package/dist/lib/someTagsFilter.js.map +1 -1
- package/dist/lib/typeFilter.cjs.map +1 -1
- package/dist/lib/typeFilter.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.ts +1 -1
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.ts +2 -2
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +1 -1
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +1 -1
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/api/query.d.ts +1 -1
- package/dist/types/api/release.d.ts +1 -1
- package/dist/types/api/repository.d.ts +1 -1
- package/dist/types/model/customType.d.ts +1 -1
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.js.map +1 -1
- package/dist/types/model/slice.cjs.map +1 -1
- package/dist/types/model/slice.js.map +1 -1
- package/dist/types/model/sliceZone.cjs.map +1 -1
- package/dist/types/model/sliceZone.js.map +1 -1
- package/dist/types/model/title.d.ts +1 -1
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/value/document.d.ts +4 -4
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.js.map +1 -1
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.js.map +1 -1
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.js.map +1 -1
- package/dist/types/webhook/apiUpdate.d.ts +1 -1
- package/dist/types/webhook/testTrigger.d.ts +1 -1
- package/dist/types/webhook/types.cjs.map +1 -1
- package/dist/types/webhook/types.d.ts +2 -2
- package/dist/types/webhook/types.js.map +1 -1
- package/package.json +1 -1
- package/src/buildQueryURL.ts +51 -51
- package/src/cookie.ts +1 -1
- package/src/createClient.ts +293 -293
- package/src/errors/ForbiddenError.ts +6 -6
- package/src/errors/NotFoundError.ts +1 -1
- package/src/errors/ParsingError.ts +8 -8
- package/src/errors/PreviewTokenExpired.ts +4 -4
- package/src/errors/PrismicError.ts +5 -5
- package/src/errors/PrismicRichTextSerializerError.ts +1 -1
- package/src/errors/RefExpiredError.ts +4 -4
- package/src/errors/RefNotFoundError.ts +4 -4
- package/src/errors/RepositoryNotFoundError.ts +1 -1
- package/src/filter.ts +22 -22
- package/src/getGraphQLEndpoint.ts +5 -5
- package/src/getRepositoryEndpoint.ts +5 -5
- package/src/getRepositoryName.ts +4 -4
- package/src/getToolbarSrc.ts +5 -5
- package/src/helpers/asDate.ts +7 -7
- package/src/helpers/asHTML.ts +54 -56
- package/src/helpers/asImagePixelDensitySrcSet.ts +14 -17
- package/src/helpers/asImageSrc.ts +9 -8
- package/src/helpers/asImageWidthSrcSet.ts +19 -22
- package/src/helpers/asLink.ts +26 -27
- package/src/helpers/asLinkAttrs.ts +30 -29
- package/src/helpers/asText.ts +15 -15
- package/src/helpers/documentToLinkField.ts +6 -6
- package/src/helpers/isFilled.ts +53 -53
- package/src/helpers/mapSliceZone.ts +34 -34
- package/src/helpers/unstable_htmlAsRichText.ts +23 -22
- package/src/helpers/unstable_markdownAsRichText.ts +14 -13
- package/src/index.ts +119 -119
- package/src/isRepositoryEndpoint.ts +4 -4
- package/src/isRepositoryName.ts +2 -2
- package/src/lib/RichTextFieldBuilder.ts +36 -41
- package/src/lib/appendFilters.ts +4 -4
- package/src/lib/castArray.ts +2 -2
- package/src/lib/castThunk.ts +2 -2
- package/src/lib/devMsg.ts +4 -4
- package/src/lib/escapeHTML.ts +24 -24
- package/src/lib/everyTagFilter.ts +4 -4
- package/src/lib/filterRichTextField.ts +31 -31
- package/src/lib/findMasterRef.ts +4 -4
- package/src/lib/findRef.ts +6 -6
- package/src/lib/findRefByID.ts +4 -4
- package/src/lib/findRefByLabel.ts +4 -4
- package/src/lib/getPreviewCookie.ts +11 -11
- package/src/lib/hastSerializerHelpers.ts +41 -37
- package/src/lib/hastToRichText.ts +74 -73
- package/src/lib/isInternalURL.ts +4 -4
- package/src/lib/minifyGraphQLQuery.ts +2 -2
- package/src/lib/rehypeRichText.ts +42 -41
- package/src/lib/serializerHelpers.ts +53 -54
- package/src/lib/someTagsFilter.ts +4 -4
- package/src/lib/typeFilter.ts +3 -3
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/asTree.ts +53 -53
- package/src/richtext/composeSerializers.ts +6 -6
- package/src/richtext/index.ts +7 -7
- package/src/richtext/serialize.ts +11 -11
- package/src/richtext/types.ts +38 -38
- package/src/richtext/wrapMapSerializer.ts +6 -9
- package/src/types/api/query.ts +9 -9
- package/src/types/api/ref.ts +5 -5
- package/src/types/api/release.ts +2 -2
- package/src/types/api/repository.ts +24 -24
- package/src/types/api/tags.ts +1 -1
- package/src/types/model/boolean.ts +7 -7
- package/src/types/model/color.ts +5 -5
- package/src/types/model/contentRelationship.ts +9 -9
- package/src/types/model/customType.ts +9 -9
- package/src/types/model/date.ts +6 -6
- package/src/types/model/embed.ts +5 -5
- package/src/types/model/geoPoint.ts +4 -4
- package/src/types/model/group.ts +6 -6
- package/src/types/model/image.ts +9 -9
- package/src/types/model/integration.ts +6 -6
- package/src/types/model/keyText.ts +5 -5
- package/src/types/model/link.ts +8 -8
- package/src/types/model/linkToMedia.ts +7 -7
- package/src/types/model/number.ts +7 -7
- package/src/types/model/range.ts +8 -8
- package/src/types/model/richText.ts +16 -16
- package/src/types/model/select.ts +7 -7
- package/src/types/model/separator.ts +4 -4
- package/src/types/model/sharedSlice.ts +7 -7
- package/src/types/model/sharedSliceVariation.ts +9 -9
- package/src/types/model/slice.ts +12 -12
- package/src/types/model/sliceZone.ts +11 -11
- package/src/types/model/timestamp.ts +6 -6
- package/src/types/model/title.ts +2 -2
- package/src/types/model/types.ts +26 -26
- package/src/types/model/uid.ts +5 -5
- package/src/types/value/boolean.ts +1 -1
- package/src/types/value/color.ts +2 -2
- package/src/types/value/contentRelationship.ts +15 -15
- package/src/types/value/date.ts +2 -2
- package/src/types/value/document.ts +23 -23
- package/src/types/value/embed.ts +33 -33
- package/src/types/value/geoPoint.ts +4 -4
- package/src/types/value/group.ts +3 -3
- package/src/types/value/image.ts +21 -21
- package/src/types/value/integration.ts +2 -2
- package/src/types/value/keyText.ts +2 -2
- package/src/types/value/link.ts +12 -12
- package/src/types/value/linkToMedia.ts +11 -11
- package/src/types/value/number.ts +2 -2
- package/src/types/value/richText.ts +58 -58
- package/src/types/value/select.ts +2 -2
- package/src/types/value/sharedSlice.ts +5 -5
- package/src/types/value/sharedSliceVariation.ts +5 -5
- package/src/types/value/slice.ts +6 -6
- package/src/types/value/sliceZone.ts +4 -4
- package/src/types/value/timestamp.ts +3 -3
- package/src/types/value/title.ts +4 -4
- package/src/types/value/types.ts +22 -22
- package/src/types/webhook/apiUpdate.ts +18 -18
- package/src/types/webhook/testTrigger.ts +2 -2
- package/src/types/webhook/types.ts +8 -8
- package/dist/_node_modules/hast-util-whitespace/lib/index.cjs +0 -11
- package/dist/_node_modules/hast-util-whitespace/lib/index.cjs.map +0 -1
- package/dist/_node_modules/hast-util-whitespace/lib/index.js +0 -11
- package/dist/_node_modules/hast-util-whitespace/lib/index.js.map +0 -1
package/src/lib/castArray.ts
CHANGED
package/src/lib/castThunk.ts
CHANGED
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
|
+
}
|
package/src/lib/escapeHTML.ts
CHANGED
|
@@ -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 = """
|
|
25
|
-
break
|
|
24
|
+
escape = """
|
|
25
|
+
break
|
|
26
26
|
case 38: // &
|
|
27
|
-
escape = "&"
|
|
28
|
-
break
|
|
27
|
+
escape = "&"
|
|
28
|
+
break
|
|
29
29
|
case 39: // '
|
|
30
|
-
escape = "'"
|
|
31
|
-
break
|
|
30
|
+
escape = "'"
|
|
31
|
+
break
|
|
32
32
|
case 60: // <
|
|
33
|
-
escape = "<"
|
|
34
|
-
break
|
|
33
|
+
escape = "<"
|
|
34
|
+
break
|
|
35
35
|
case 62: // >
|
|
36
|
-
escape = ">"
|
|
37
|
-
break
|
|
36
|
+
escape = ">"
|
|
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 {
|
|
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[] = []
|
|
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
|
+
}
|
package/src/lib/findMasterRef.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/lib/findRef.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/lib/findRefByID.ts
CHANGED
|
@@ -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 {
|
|
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
|
+
}
|