@prismicio/svelte 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PrismicEmbed.svelte +6 -8
- package/dist/PrismicEmbed.svelte.d.ts +1 -3
- package/dist/PrismicImage.svelte +46 -68
- package/dist/PrismicImage.svelte.d.ts +11 -17
- package/dist/PrismicLink.svelte +23 -34
- package/dist/PrismicLink.svelte.d.ts +5 -10
- package/dist/PrismicRichText/DefaultComponent.svelte +9 -13
- package/dist/PrismicRichText/PrismicRichText.svelte +11 -16
- package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +2 -6
- package/dist/PrismicRichText/Serialize.svelte +11 -19
- package/dist/PrismicTable.svelte +26 -41
- package/dist/PrismicTable.svelte.d.ts +4 -8
- package/dist/PrismicText.svelte +16 -20
- package/dist/PrismicText.svelte.d.ts +4 -8
- package/dist/SliceSimulator.svelte +28 -17
- package/dist/SliceSimulator.svelte.d.ts +7 -6
- package/dist/SliceZone/SliceZone.svelte +21 -26
- package/dist/SliceZone/SliceZone.svelte.d.ts +12 -16
- package/dist/SliceZone/TodoComponent.svelte +7 -7
- package/dist/index.d.ts +1 -3
- package/dist/kit/PrismicPreview.svelte +32 -48
- package/dist/kit/PrismicPreview.svelte.d.ts +5 -9
- package/dist/kit/enableAutoPreviews.d.ts +5 -10
- package/dist/kit/enableAutoPreviews.js +1 -2
- package/dist/kit/redirectToPreviewURL.d.ts +13 -21
- package/dist/kit/redirectToPreviewURL.js +10 -11
- package/dist/kit/types.d.ts +3 -6
- package/dist/lib/devMsg.d.ts +6 -8
- package/dist/lib/devMsg.js +6 -8
- package/dist/types.d.ts +23 -39
- package/package.json +41 -44
- package/src/PrismicEmbed.svelte +6 -8
- package/src/PrismicImage.svelte +46 -68
- package/src/PrismicLink.svelte +23 -34
- package/src/PrismicRichText/DefaultComponent.svelte +9 -13
- package/src/PrismicRichText/PrismicRichText.svelte +11 -16
- package/src/PrismicRichText/Serialize.svelte +11 -19
- package/src/PrismicTable.svelte +26 -41
- package/src/PrismicText.svelte +16 -20
- package/src/SliceSimulator.svelte +28 -17
- package/src/SliceZone/SliceZone.svelte +21 -26
- package/src/SliceZone/TodoComponent.svelte +7 -7
- package/src/index.ts +13 -15
- package/src/kit/PrismicPreview.svelte +32 -48
- package/src/kit/enableAutoPreviews.ts +14 -19
- package/src/kit/index.ts +6 -6
- package/src/kit/redirectToPreviewURL.ts +28 -38
- package/src/kit/types.ts +7 -10
- package/src/lib/devMsg.ts +9 -11
- package/src/types.ts +84 -106
package/dist/lib/devMsg.d.ts
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* devMsg("missing-param")
|
|
7
|
+
* // => "https://prismic.dev/msg/svelte/v1.2.3/missing-param.md"
|
|
8
|
+
* ```
|
|
5
9
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* // => "https://prismic.dev/msg/svelte/v1.2.3/missing-param.md"
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
12
|
-
* the Git repository's `/messages` directory.
|
|
13
|
-
*
|
|
10
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
|
|
11
|
+
* `/messages` directory.
|
|
14
12
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
15
13
|
*/
|
|
16
14
|
export declare const devMsg: (slug: string) => string;
|
package/dist/lib/devMsg.js
CHANGED
|
@@ -3,15 +3,13 @@ import { version } from "../../package.json";
|
|
|
3
3
|
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* devMsg("missing-param")
|
|
8
|
+
* // => "https://prismic.dev/msg/svelte/v1.2.3/missing-param.md"
|
|
9
|
+
* ```
|
|
6
10
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* // => "https://prismic.dev/msg/svelte/v1.2.3/missing-param.md"
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
13
|
-
* the Git repository's `/messages` directory.
|
|
14
|
-
*
|
|
11
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
|
|
12
|
+
* `/messages` directory.
|
|
15
13
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
16
14
|
*/
|
|
17
15
|
export const devMsg = (slug) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type { RTAnyNode, RTEmNode, RTEmbedNode, RTHeading1Node, RTHeading2Node, RTHeading3Node, RTHeading4Node, RTHeading5Node, RTHeading6Node, RTImageNode, RTLabelNode, RTLinkNode, RTListItemNode, RTListNode, RTOListItemNode, RTOListNode, RTParagraphNode, RTPreformattedNode, RTSpanNode, RTStrongNode, Slice, TableField, TableFieldBody, TableFieldBodyRow, TableFieldDataCell, TableFieldHead, TableFieldHeadRow, TableFieldHeaderCell } from "@prismicio/client";
|
|
2
2
|
import type { Component, Snippet } from "svelte";
|
|
3
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
-
/**
|
|
5
|
-
* A shorthand definition for `<PrismicRichText />` component types.
|
|
6
|
-
*/
|
|
4
|
+
/** A shorthand definition for `<PrismicRichText />` component types. */
|
|
7
5
|
export type ComponentShorthand = {
|
|
8
|
-
/**
|
|
9
|
-
* The HTML element type rendered for this node type.
|
|
10
|
-
*/
|
|
6
|
+
/** The HTML element type rendered for this node type. */
|
|
11
7
|
as?: string;
|
|
12
8
|
} & HTMLAttributes<HTMLElement>;
|
|
13
9
|
export type RichTextComponents = {
|
|
@@ -63,38 +59,28 @@ export type TableComponents = {
|
|
|
63
59
|
}> | HTMLAttributes<HTMLTableCellElement>;
|
|
64
60
|
};
|
|
65
61
|
/**
|
|
66
|
-
* Props for a component rendering content from a Prismic Slice using the
|
|
67
|
-
* `<SliceZone>` component.
|
|
62
|
+
* Props for a component rendering content from a Prismic Slice using the `<SliceZone>` component.
|
|
68
63
|
*
|
|
69
64
|
* @typeParam TSlice - The Slice passed as a prop.
|
|
70
|
-
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
|
|
71
|
-
*
|
|
65
|
+
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all Slice
|
|
66
|
+
* components.
|
|
72
67
|
*/
|
|
73
68
|
export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
74
|
-
/**
|
|
75
|
-
* Slice data for this component.
|
|
76
|
-
*/
|
|
69
|
+
/** Slice data for this component. */
|
|
77
70
|
slice: TSlice;
|
|
78
|
-
/**
|
|
79
|
-
* The index of the Slice in the Slice Zone.
|
|
80
|
-
*/
|
|
71
|
+
/** The index of the Slice in the Slice Zone. */
|
|
81
72
|
index: number;
|
|
82
|
-
/**
|
|
83
|
-
* All Slices from the Slice Zone to which the Slice belongs.
|
|
84
|
-
*/
|
|
73
|
+
/** All Slices from the Slice Zone to which the Slice belongs. */
|
|
85
74
|
slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
|
|
86
|
-
/**
|
|
87
|
-
* Arbitrary data passed to `<SliceZone>` and made available to all Slice
|
|
88
|
-
* components.
|
|
89
|
-
*/
|
|
75
|
+
/** Arbitrary data passed to `<SliceZone>` and made available to all Slice components. */
|
|
90
76
|
context: TContext;
|
|
91
77
|
};
|
|
92
78
|
/**
|
|
93
|
-
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
94
|
-
*
|
|
79
|
+
* The minimum required properties to represent a Prismic Slice from the Prismic Rest API V2 for the
|
|
80
|
+
* `<SliceZone>` component.
|
|
95
81
|
*
|
|
96
|
-
* If using Prismic's Rest API V2, use the `Slice` export from
|
|
97
|
-
*
|
|
82
|
+
* If using Prismic's Rest API V2, use the `Slice` export from `@prismicio/types` for a full
|
|
83
|
+
* interface.
|
|
98
84
|
*
|
|
99
85
|
* @typeParam SliceType - Type name of the Slice.
|
|
100
86
|
*/
|
|
@@ -102,8 +88,8 @@ type SliceLikeRestV2<SliceType extends string = string> = {
|
|
|
102
88
|
slice_type: Slice<SliceType>["slice_type"];
|
|
103
89
|
};
|
|
104
90
|
/**
|
|
105
|
-
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
106
|
-
*
|
|
91
|
+
* The minimum required properties to represent a Prismic Slice from the Prismic GraphQL API for the
|
|
92
|
+
* `<SliceZone>` component.
|
|
107
93
|
*
|
|
108
94
|
* @typeParam SliceType - Type name of the Slice.
|
|
109
95
|
*/
|
|
@@ -111,29 +97,27 @@ type SliceLikeGraphQL<SliceType extends string = string> = {
|
|
|
111
97
|
type: Slice<SliceType>["slice_type"];
|
|
112
98
|
};
|
|
113
99
|
/**
|
|
114
|
-
* The minimum required properties to represent a Prismic Slice for the
|
|
115
|
-
* `<SliceZone>` component.
|
|
100
|
+
* The minimum required properties to represent a Prismic Slice for the `<SliceZone>` component.
|
|
116
101
|
*
|
|
117
|
-
* If using Prismic's Rest API V2, use the `Slice` export from
|
|
118
|
-
*
|
|
102
|
+
* If using Prismic's Rest API V2, use the `Slice` export from `@prismicio/types` for a full
|
|
103
|
+
* interface.
|
|
119
104
|
*
|
|
120
105
|
* @typeParam SliceType - Type name of the Slice.
|
|
121
106
|
*/
|
|
122
107
|
type SliceLike<SliceType extends string = string> = (SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>) & {
|
|
123
108
|
/**
|
|
124
|
-
* If `true`, this Slice has been modified from its original value using a
|
|
125
|
-
*
|
|
109
|
+
* If `true`, this Slice has been modified from its original value using a mapper and
|
|
110
|
+
* `@prismicio/client`'s `mapSliceZone()`.
|
|
126
111
|
*
|
|
127
112
|
* @internal
|
|
128
113
|
*/
|
|
129
114
|
__mapped?: true;
|
|
130
115
|
};
|
|
131
116
|
/**
|
|
132
|
-
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
133
|
-
* `SliceLike`.
|
|
117
|
+
* A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`.
|
|
134
118
|
*
|
|
135
|
-
* If using Prismic's Rest API V2, use the `SliceZone` export from
|
|
136
|
-
*
|
|
119
|
+
* If using Prismic's Rest API V2, use the `SliceZone` export from `@prismicio/client` for the full
|
|
120
|
+
* type.
|
|
137
121
|
*
|
|
138
122
|
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
139
123
|
*/
|
package/package.json
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/svelte",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Svelte components to present Prismic content.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"prismic",
|
|
7
|
+
"typescript"
|
|
8
8
|
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "ssh://git@github.com/prismicio/prismic-svelte.git"
|
|
12
14
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
+
"files": [
|
|
16
|
+
"./dist",
|
|
17
|
+
"./src"
|
|
18
|
+
],
|
|
15
19
|
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"*": [
|
|
26
|
+
"dist/index.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"kit": [
|
|
29
|
+
"dist/kit/index.d.ts"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
16
33
|
"exports": {
|
|
17
34
|
".": {
|
|
18
35
|
"types": "./dist/index.d.ts",
|
|
@@ -26,27 +43,13 @@
|
|
|
26
43
|
},
|
|
27
44
|
"./package.json": "./package.json"
|
|
28
45
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"types": "./dist/index.d.ts",
|
|
32
|
-
"typesVersions": {
|
|
33
|
-
"*": {
|
|
34
|
-
"*": [
|
|
35
|
-
"dist/index.d.ts"
|
|
36
|
-
],
|
|
37
|
-
"kit": [
|
|
38
|
-
"dist/kit/index.d.ts"
|
|
39
|
-
]
|
|
40
|
-
}
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
41
48
|
},
|
|
42
|
-
"files": [
|
|
43
|
-
"./dist",
|
|
44
|
-
"./src"
|
|
45
|
-
],
|
|
46
49
|
"scripts": {
|
|
47
50
|
"build": "svelte-package --input ./src",
|
|
48
51
|
"dev": "svelte-package --input ./src --watch",
|
|
49
|
-
"format": "
|
|
52
|
+
"format": "oxfmt",
|
|
50
53
|
"prepare": "npm run build",
|
|
51
54
|
"lint": "oxlint --deny-warnings",
|
|
52
55
|
"types": "tsc --noEmit",
|
|
@@ -55,29 +58,26 @@
|
|
|
55
58
|
"test": "npm run lint && npm run types && npm run unit && npm run build"
|
|
56
59
|
},
|
|
57
60
|
"dependencies": {
|
|
58
|
-
"@prismicio/simulator": "^0.2.
|
|
61
|
+
"@prismicio/simulator": "^0.2.4",
|
|
59
62
|
"esm-env": "^1.2.2"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
|
-
"@prismicio/client": "^7.
|
|
65
|
+
"@prismicio/client": "^7.22.3",
|
|
63
66
|
"@prismicio/mock": "^0.7.2",
|
|
64
|
-
"@sveltejs/kit": "^2.
|
|
65
|
-
"@sveltejs/package": "^
|
|
66
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
67
|
-
"@testing-library/svelte": "^5.
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"oxlint": "^1.
|
|
74
|
-
"prettier": "^3.8.1",
|
|
75
|
-
"prettier-plugin-jsdoc": "^1.8.0",
|
|
76
|
-
"prettier-plugin-svelte": "^3.5.1",
|
|
67
|
+
"@sveltejs/kit": "^2.70.3",
|
|
68
|
+
"@sveltejs/package": "^3.0.0",
|
|
69
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
70
|
+
"@testing-library/svelte": "^5.4.2",
|
|
71
|
+
"@types/node": "^26.6.5",
|
|
72
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
73
|
+
"globals": "^17.13.0",
|
|
74
|
+
"happy-dom": "^20.14.6",
|
|
75
|
+
"oxfmt": "^0.72.0",
|
|
76
|
+
"oxlint": "^1.87.0",
|
|
77
77
|
"standard-version": "^9.5.0",
|
|
78
|
-
"svelte": "^5.
|
|
79
|
-
"typescript": "^6.0.
|
|
80
|
-
"vitest": "^
|
|
78
|
+
"svelte": "^5.57.2",
|
|
79
|
+
"typescript": "^6.0.3",
|
|
80
|
+
"vitest": "^5.0.3"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@prismicio/client": ">=7",
|
|
@@ -90,9 +90,6 @@
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
"engines": {
|
|
93
|
-
"node": ">=
|
|
94
|
-
},
|
|
95
|
-
"publishConfig": {
|
|
96
|
-
"access": "public"
|
|
93
|
+
"node": ">=22"
|
|
97
94
|
}
|
|
98
95
|
}
|
package/src/PrismicEmbed.svelte
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { EmbedField } from "@prismicio/client"
|
|
3
|
-
import { isFilled } from "@prismicio/client"
|
|
2
|
+
import type { EmbedField } from "@prismicio/client"
|
|
3
|
+
import { isFilled } from "@prismicio/client"
|
|
4
4
|
|
|
5
5
|
type Props = {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
field: EmbedField;
|
|
10
|
-
};
|
|
6
|
+
/** An Embed field from Prismic. */
|
|
7
|
+
field: EmbedField
|
|
8
|
+
}
|
|
11
9
|
|
|
12
|
-
const { field }: Props = $props()
|
|
10
|
+
const { field }: Props = $props()
|
|
13
11
|
</script>
|
|
14
12
|
|
|
15
13
|
<!--
|
package/src/PrismicImage.svelte
CHANGED
|
@@ -1,75 +1,61 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@prismicio/client";
|
|
7
|
-
import type { ImageFieldImage } from "@prismicio/client";
|
|
8
|
-
import type { ImgixURLParams } from "imgix-url-builder";
|
|
9
|
-
import type { HTMLImgAttributes } from "svelte/elements";
|
|
2
|
+
import { asImagePixelDensitySrcSet, asImageWidthSrcSet, isFilled } from "@prismicio/client"
|
|
3
|
+
import type { ImageFieldImage } from "@prismicio/client"
|
|
4
|
+
import type { ImgixURLParams } from "imgix-url-builder"
|
|
5
|
+
import type { HTMLImgAttributes } from "svelte/elements"
|
|
10
6
|
|
|
11
7
|
type Props = Omit<HTMLImgAttributes, "src" | "srcset" | "alt"> & {
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
field: ImageFieldImage | null | undefined;
|
|
8
|
+
/** The Prismic image field or thumbnail to render. */
|
|
9
|
+
field: ImageFieldImage | null | undefined
|
|
16
10
|
|
|
17
11
|
/**
|
|
18
12
|
* An object of Imgix URL API parameters to transform the image.
|
|
19
13
|
*
|
|
20
14
|
* See: https://docs.imgix.com/apis/rendering
|
|
21
15
|
*/
|
|
22
|
-
imgixParams?: ImgixURLParams
|
|
16
|
+
imgixParams?: ImgixURLParams
|
|
23
17
|
|
|
24
18
|
/**
|
|
25
19
|
* Declare an image as decorative by providing `alt=""`.
|
|
26
20
|
*
|
|
27
|
-
* See:
|
|
28
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
21
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
22
|
*/
|
|
30
|
-
alt?: ""
|
|
23
|
+
alt?: ""
|
|
31
24
|
|
|
32
25
|
/**
|
|
33
|
-
* Declare an image as decorative only if the Image field does not have
|
|
34
|
-
*
|
|
26
|
+
* Declare an image as decorative only if the Image field does not have alternative text by
|
|
27
|
+
* providing `fallbackAlt=""`.
|
|
35
28
|
*
|
|
36
|
-
* See:
|
|
37
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
38
30
|
*/
|
|
39
|
-
fallbackAlt?: ""
|
|
31
|
+
fallbackAlt?: ""
|
|
40
32
|
} & (
|
|
41
33
|
| {
|
|
42
34
|
/**
|
|
43
35
|
* Widths used to build a `srcset` value for the Image field.
|
|
44
36
|
*
|
|
45
|
-
* If a `widths` prop is not given or `"defaults"` is passed, the
|
|
46
|
-
*
|
|
47
|
-
* 2048, 3840.
|
|
37
|
+
* If a `widths` prop is not given or `"defaults"` is passed, the following widths will be
|
|
38
|
+
* used: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
48
39
|
*
|
|
49
|
-
* If the Image field contains responsive views, each responsive view
|
|
50
|
-
*
|
|
51
|
-
* `"thumbnails"` as the `widths` prop.
|
|
40
|
+
* If the Image field contains responsive views, each responsive view can be used as a
|
|
41
|
+
* width in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop.
|
|
52
42
|
*/
|
|
53
|
-
widths?:
|
|
54
|
-
|
|
55
|
-
| "defaults";
|
|
56
|
-
pixelDensities?: never;
|
|
43
|
+
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults"
|
|
44
|
+
pixelDensities?: never
|
|
57
45
|
}
|
|
58
46
|
| {
|
|
59
47
|
/**
|
|
60
48
|
* Pixel densities used to build a `srcset` value for the Image field.
|
|
61
49
|
*
|
|
62
|
-
* If a `pixelDensities` prop is passed `"defaults"`, the following
|
|
63
|
-
*
|
|
50
|
+
* If a `pixelDensities` prop is passed `"defaults"`, the following pixel densities will
|
|
51
|
+
* be used: 1, 2, 3.
|
|
64
52
|
*/
|
|
65
53
|
pixelDensities:
|
|
66
|
-
| NonNullable<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
| "defaults";
|
|
70
|
-
widths?: never;
|
|
54
|
+
| NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"]
|
|
55
|
+
| "defaults"
|
|
56
|
+
widths?: never
|
|
71
57
|
}
|
|
72
|
-
)
|
|
58
|
+
)
|
|
73
59
|
|
|
74
60
|
const {
|
|
75
61
|
field,
|
|
@@ -81,59 +67,51 @@
|
|
|
81
67
|
widths,
|
|
82
68
|
pixelDensities,
|
|
83
69
|
...restProps
|
|
84
|
-
}: Props = $props()
|
|
70
|
+
}: Props = $props()
|
|
85
71
|
|
|
86
72
|
const { resolvedWidth, resolvedHeight } = $derived.by(() => {
|
|
87
73
|
if (!isFilled.imageThumbnail(field))
|
|
88
|
-
return { resolvedWidth: undefined, resolvedHeight: undefined }
|
|
74
|
+
return { resolvedWidth: undefined, resolvedHeight: undefined }
|
|
89
75
|
|
|
90
|
-
const ar = field.dimensions.width / field.dimensions.height
|
|
76
|
+
const ar = field.dimensions.width / field.dimensions.height
|
|
91
77
|
|
|
92
|
-
let resolvedWidth = castInt(width) ?? field.dimensions.width
|
|
93
|
-
let resolvedHeight = castInt(height) ?? field.dimensions.height
|
|
78
|
+
let resolvedWidth = castInt(width) ?? field.dimensions.width
|
|
79
|
+
let resolvedHeight = castInt(height) ?? field.dimensions.height
|
|
94
80
|
if (resolvedWidth != null && resolvedHeight == null) {
|
|
95
|
-
resolvedHeight = resolvedWidth / ar
|
|
81
|
+
resolvedHeight = resolvedWidth / ar
|
|
96
82
|
} else if (resolvedWidth == null && resolvedHeight != null) {
|
|
97
|
-
resolvedWidth = resolvedHeight * ar
|
|
83
|
+
resolvedWidth = resolvedHeight * ar
|
|
98
84
|
}
|
|
99
85
|
|
|
100
|
-
return { resolvedWidth, resolvedHeight }
|
|
101
|
-
})
|
|
86
|
+
return { resolvedWidth, resolvedHeight }
|
|
87
|
+
})
|
|
102
88
|
|
|
103
89
|
const { src, srcset } = $derived.by(() => {
|
|
104
|
-
if (!isFilled.imageThumbnail(field))
|
|
105
|
-
return { src: undefined, srcset: undefined };
|
|
90
|
+
if (!isFilled.imageThumbnail(field)) return { src: undefined, srcset: undefined }
|
|
106
91
|
|
|
107
92
|
if (pixelDensities) {
|
|
108
93
|
return asImagePixelDensitySrcSet(field, {
|
|
109
94
|
...imgixParams,
|
|
110
|
-
pixelDensities:
|
|
111
|
-
|
|
112
|
-
} as ImgixURLParams);
|
|
95
|
+
pixelDensities: pixelDensities === "defaults" ? undefined : pixelDensities,
|
|
96
|
+
} as ImgixURLParams)
|
|
113
97
|
}
|
|
114
98
|
|
|
115
99
|
return asImageWidthSrcSet(field, {
|
|
116
100
|
...imgixParams,
|
|
117
101
|
widths: widths === "defaults" ? undefined : widths,
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
function castInt(
|
|
122
|
-
input
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
typeof input === "number" ||
|
|
126
|
-
typeof input === "undefined" ||
|
|
127
|
-
input === null
|
|
128
|
-
) {
|
|
129
|
-
return input;
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
function castInt(input: string | number | null | undefined): number | null | undefined {
|
|
106
|
+
if (typeof input === "number" || typeof input === "undefined" || input === null) {
|
|
107
|
+
return input
|
|
130
108
|
} else {
|
|
131
|
-
const parsed = Number.parseInt(input)
|
|
109
|
+
const parsed = Number.parseInt(input)
|
|
132
110
|
|
|
133
111
|
if (Number.isNaN(parsed)) {
|
|
134
|
-
return undefined
|
|
112
|
+
return undefined
|
|
135
113
|
} else {
|
|
136
|
-
return parsed
|
|
114
|
+
return parsed
|
|
137
115
|
}
|
|
138
116
|
}
|
|
139
117
|
}
|
package/src/PrismicLink.svelte
CHANGED
|
@@ -1,56 +1,45 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { asLinkAttrs } from "@prismicio/client"
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
LinkField,
|
|
6
|
-
PrismicDocument,
|
|
7
|
-
} from "@prismicio/client";
|
|
8
|
-
import type { HTMLAnchorAttributes } from "svelte/elements";
|
|
2
|
+
import { asLinkAttrs } from "@prismicio/client"
|
|
3
|
+
import type { AsLinkAttrsConfig, LinkField, PrismicDocument } from "@prismicio/client"
|
|
4
|
+
import type { HTMLAnchorAttributes } from "svelte/elements"
|
|
9
5
|
|
|
10
6
|
type Props = Omit<HTMLAnchorAttributes, "rel" | "href"> & {
|
|
11
7
|
/**
|
|
12
|
-
* The `rel` attribute for the link. By default, `"noreferrer"` is provided
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if the link's URL is
|
|
9
|
+
* external. This prop can be provided a function to use the link's metadata to determine the
|
|
10
|
+
* `rel` value.
|
|
15
11
|
*/
|
|
16
|
-
rel?: string | AsLinkAttrsConfig["rel"]
|
|
12
|
+
rel?: string | AsLinkAttrsConfig["rel"]
|
|
17
13
|
} & (
|
|
18
14
|
| {
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
field: LinkField | null | undefined;
|
|
24
|
-
document?: never;
|
|
25
|
-
href?: never;
|
|
15
|
+
/** A Prismic link field, content relationship field, or link to media field. */
|
|
16
|
+
field: LinkField | null | undefined
|
|
17
|
+
document?: never
|
|
18
|
+
href?: never
|
|
26
19
|
}
|
|
27
20
|
| {
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
field?: never;
|
|
33
|
-
href?: never;
|
|
21
|
+
/** A Prismic document. */
|
|
22
|
+
document: PrismicDocument | null | undefined
|
|
23
|
+
field?: never
|
|
24
|
+
href?: never
|
|
34
25
|
}
|
|
35
26
|
| {
|
|
36
|
-
href: HTMLAnchorAttributes["href"]
|
|
37
|
-
document: never
|
|
38
|
-
field?: never
|
|
27
|
+
href: HTMLAnchorAttributes["href"]
|
|
28
|
+
document: never
|
|
29
|
+
field?: never
|
|
39
30
|
}
|
|
40
|
-
)
|
|
31
|
+
)
|
|
41
32
|
|
|
42
|
-
const { field, document, rel, children, ...restProps }: Props = $props()
|
|
33
|
+
const { field, document, rel, children, ...restProps }: Props = $props()
|
|
43
34
|
|
|
44
35
|
const linkAttrs = $derived(
|
|
45
36
|
asLinkAttrs(field ?? document, {
|
|
46
37
|
rel: typeof rel === "function" ? rel : undefined,
|
|
47
38
|
}),
|
|
48
|
-
)
|
|
49
|
-
const href = $derived(
|
|
50
|
-
("href" in restProps ? restProps.href : linkAttrs.href) || "",
|
|
51
|
-
);
|
|
39
|
+
)
|
|
40
|
+
const href = $derived(("href" in restProps ? restProps.href : linkAttrs.href) || "")
|
|
52
41
|
|
|
53
|
-
const resolvedRel = $derived(typeof rel === "string" ? rel : linkAttrs.rel)
|
|
42
|
+
const resolvedRel = $derived(typeof rel === "string" ? rel : linkAttrs.rel)
|
|
54
43
|
</script>
|
|
55
44
|
|
|
56
45
|
<!--
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { HTMLAttributes } from "svelte/elements"
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements"
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import PrismicEmbed from "../PrismicEmbed.svelte"
|
|
5
|
+
import PrismicImage from "../PrismicImage.svelte"
|
|
6
|
+
import PrismicLink from "../PrismicLink.svelte"
|
|
7
|
+
import type { RichTextComponentProps } from "../types"
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
import PrismicImage from "../PrismicImage.svelte";
|
|
8
|
-
import PrismicLink from "../PrismicLink.svelte";
|
|
9
|
+
type Props = RichTextComponentProps & HTMLAttributes<HTMLElement> & { as?: string }
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
HTMLAttributes<HTMLElement> & { as?: string };
|
|
12
|
-
|
|
13
|
-
const { node, children, as, ...attrs }: Props = $props();
|
|
11
|
+
const { node, children, as, ...attrs }: Props = $props()
|
|
14
12
|
|
|
15
13
|
const dirProp = $derived(
|
|
16
14
|
"direction" in node && node.direction === "rtl" ? { direction: "rtl" } : {},
|
|
17
|
-
)
|
|
15
|
+
)
|
|
18
16
|
</script>
|
|
19
17
|
|
|
20
18
|
{#if as}
|
|
21
|
-
<svelte:element this={as} {...dirProp} {...attrs} {...attrs}
|
|
22
|
-
>{@render children()}</svelte:element
|
|
23
|
-
>
|
|
19
|
+
<svelte:element this={as} {...dirProp} {...attrs} {...attrs}>{@render children()}</svelte:element>
|
|
24
20
|
{:else if node.type === "heading1"}
|
|
25
21
|
<h1 {...dirProp} {...attrs}>{@render children()}</h1>
|
|
26
22
|
{:else if node.type === "heading2"}
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { RichTextField } from "@prismicio/client"
|
|
3
|
-
import { asTree } from "@prismicio/client/richtext"
|
|
2
|
+
import type { RichTextField } from "@prismicio/client"
|
|
3
|
+
import { asTree } from "@prismicio/client/richtext"
|
|
4
4
|
|
|
5
|
-
import type { RichTextComponents } from "../types"
|
|
6
|
-
|
|
7
|
-
import Serialize from "./Serialize.svelte";
|
|
5
|
+
import type { RichTextComponents } from "../types"
|
|
6
|
+
import Serialize from "./Serialize.svelte"
|
|
8
7
|
|
|
9
8
|
type Props = {
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
field: RichTextField;
|
|
9
|
+
/** The Prismic rich text field to render. */
|
|
10
|
+
field: RichTextField
|
|
14
11
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
components?: RichTextComponents;
|
|
19
|
-
};
|
|
12
|
+
/** An object that maps a rich text block type to a Svelte component. */
|
|
13
|
+
components?: RichTextComponents
|
|
14
|
+
}
|
|
20
15
|
|
|
21
|
-
const { field, components = {} }: Props = $props()
|
|
16
|
+
const { field, components = {} }: Props = $props()
|
|
22
17
|
|
|
23
|
-
const children = $derived(asTree(field).children)
|
|
18
|
+
const children = $derived(asTree(field).children)
|
|
24
19
|
</script>
|
|
25
20
|
|
|
26
21
|
<!--
|