@prismicio/svelte 1.6.0-alpha.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/PrismicEmbed.svelte +12 -2
- package/dist/PrismicEmbed.svelte.d.ts +8 -19
- package/dist/PrismicImage.svelte +140 -59
- package/dist/PrismicImage.svelte.d.ts +54 -66
- package/dist/PrismicLink.svelte +55 -18
- package/dist/PrismicLink.svelte.d.ts +30 -40
- package/dist/PrismicRichText/DefaultComponent.svelte +35 -22
- package/dist/PrismicRichText/DefaultComponent.svelte.d.ts +7 -19
- package/dist/PrismicRichText/PrismicRichText.svelte +23 -5
- package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +12 -22
- package/dist/PrismicRichText/Serialize.svelte +35 -16
- package/dist/PrismicRichText/Serialize.svelte.d.ts +7 -18
- package/dist/PrismicTable/DefaultComponent.svelte +12 -2
- package/dist/PrismicTable/DefaultComponent.svelte.d.ts +7 -19
- package/dist/PrismicTable/PrismicTable.svelte +46 -30
- package/dist/PrismicTable/PrismicTable.svelte.d.ts +18 -27
- package/dist/PrismicText.svelte +49 -23
- package/dist/PrismicText.svelte.d.ts +17 -20
- package/dist/SliceZone/SliceZone.svelte +53 -9
- package/dist/SliceZone/SliceZone.svelte.d.ts +36 -84
- package/dist/SliceZone/TodoComponent.svelte +19 -9
- package/dist/SliceZone/TodoComponent.svelte.d.ts +8 -20
- package/dist/index.d.ts +1 -1
- package/dist/kit/PrismicPreview.svelte +107 -58
- package/dist/kit/PrismicPreview.svelte.d.ts +21 -30
- package/dist/lib/devMsg.js +1 -1
- package/dist/types.d.ts +93 -75
- package/package.json +27 -24
- package/src/PrismicEmbed.svelte +8 -4
- package/src/PrismicImage.svelte +65 -69
- package/src/PrismicLink.svelte +23 -19
- package/src/PrismicRichText/DefaultComponent.svelte +27 -19
- package/src/PrismicRichText/PrismicRichText.svelte +14 -10
- package/src/PrismicRichText/Serialize.svelte +12 -6
- package/src/PrismicTable/DefaultComponent.svelte +10 -2
- package/src/PrismicTable/PrismicTable.svelte +37 -43
- package/src/PrismicText.svelte +30 -22
- package/src/SliceZone/SliceZone.svelte +42 -91
- package/src/SliceZone/TodoComponent.svelte +14 -8
- package/src/index.ts +1 -1
- package/src/kit/PrismicPreview.svelte +30 -22
- package/src/lib/devMsg.ts +1 -1
- package/src/types.ts +117 -44
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ For more clarity on this project and its structure you can also check out the de
|
|
|
51
51
|
## License
|
|
52
52
|
|
|
53
53
|
```
|
|
54
|
-
Copyright 2013-
|
|
54
|
+
Copyright 2013-2025 Prismic <contact@prismic.io> (https://prismic.io)
|
|
55
55
|
|
|
56
56
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
57
57
|
you may not use this file except in compliance with the License.
|
package/dist/PrismicEmbed.svelte
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { EmbedField } from "@prismicio/client";
|
|
3
|
+
import { isFilled } from "@prismicio/client";
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
/**
|
|
7
|
+
* An Embed field from Prismic.
|
|
8
|
+
*/
|
|
9
|
+
field: EmbedField;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const { field }: Props = $props();
|
|
3
13
|
</script>
|
|
4
14
|
|
|
5
15
|
<!--
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import type { EmbedField } from "@prismicio/client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
events: {
|
|
10
|
-
[evt: string]: CustomEvent<any>;
|
|
11
|
-
};
|
|
12
|
-
slots: {};
|
|
13
|
-
exports?: {} | undefined;
|
|
14
|
-
bindings?: string | undefined;
|
|
2
|
+
type Props = {
|
|
3
|
+
/**
|
|
4
|
+
* An Embed field from Prismic.
|
|
5
|
+
*/
|
|
6
|
+
field: EmbedField;
|
|
15
7
|
};
|
|
16
|
-
export type PrismicEmbedProps = typeof __propDef.props;
|
|
17
|
-
export type PrismicEmbedEvents = typeof __propDef.events;
|
|
18
|
-
export type PrismicEmbedSlots = typeof __propDef.slots;
|
|
19
8
|
/**
|
|
20
9
|
* Component to render a Prismic embed field.
|
|
21
10
|
*
|
|
@@ -24,6 +13,6 @@ export type PrismicEmbedSlots = typeof __propDef.slots;
|
|
|
24
13
|
* <PrismicEmbed field={document.data.example_embed} />
|
|
25
14
|
* ```
|
|
26
15
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
16
|
+
declare const PrismicEmbed: import("svelte").Component<Props, {}, "">;
|
|
17
|
+
type PrismicEmbed = ReturnType<typeof PrismicEmbed>;
|
|
18
|
+
export default PrismicEmbed;
|
package/dist/PrismicImage.svelte
CHANGED
|
@@ -1,61 +1,142 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
type ImageFieldImage,
|
|
4
|
+
asImagePixelDensitySrcSet,
|
|
5
|
+
asImageWidthSrcSet,
|
|
6
|
+
isFilled,
|
|
7
|
+
} from "@prismicio/client";
|
|
8
|
+
import type { ImgixURLParams } from "imgix-url-builder";
|
|
9
|
+
import type { HTMLImgAttributes } from "svelte/elements";
|
|
10
|
+
|
|
11
|
+
type Props = Omit<HTMLImgAttributes, "src" | "srcset" | "alt"> & {
|
|
12
|
+
/**
|
|
13
|
+
* The Prismic image field or thumbnail to render.
|
|
14
|
+
*/
|
|
15
|
+
field: ImageFieldImage | null | undefined;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An object of Imgix URL API parameters to transform the image.
|
|
19
|
+
*
|
|
20
|
+
* See: https://docs.imgix.com/apis/rendering
|
|
21
|
+
*/
|
|
22
|
+
imgixParams?: ImgixURLParams;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Declare an image as decorative by providing `alt=""`.
|
|
26
|
+
*
|
|
27
|
+
* See:
|
|
28
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
|
+
*/
|
|
30
|
+
alt?: "";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Declare an image as decorative only if the Image field does not have
|
|
34
|
+
* alternative text by providing `fallbackAlt=""`.
|
|
35
|
+
*
|
|
36
|
+
* See:
|
|
37
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
38
|
+
*/
|
|
39
|
+
fallbackAlt?: "";
|
|
40
|
+
} & (
|
|
41
|
+
| {
|
|
42
|
+
/**
|
|
43
|
+
* Widths used to build a `srcset` value for the Image field.
|
|
44
|
+
*
|
|
45
|
+
* If a `widths` prop is not given or `"defaults"` is passed, the
|
|
46
|
+
* following widths will be used: 640, 750, 828, 1080, 1200, 1920,
|
|
47
|
+
* 2048, 3840.
|
|
48
|
+
*
|
|
49
|
+
* If the Image field contains responsive views, each responsive view
|
|
50
|
+
* can be used as a width in the resulting `srcset` by passing
|
|
51
|
+
* `"thumbnails"` as the `widths` prop.
|
|
52
|
+
*/
|
|
53
|
+
widths?:
|
|
54
|
+
| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"]
|
|
55
|
+
| "defaults";
|
|
56
|
+
pixelDensities?: never;
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
/**
|
|
60
|
+
* Pixel densities used to build a `srcset` value for the Image field.
|
|
61
|
+
*
|
|
62
|
+
* If a `pixelDensities` prop is passed `"defaults"`, the following
|
|
63
|
+
* pixel densities will be used: 1, 2, 3.
|
|
64
|
+
*/
|
|
65
|
+
pixelDensities:
|
|
66
|
+
| NonNullable<
|
|
67
|
+
Parameters<typeof asImagePixelDensitySrcSet>[1]
|
|
68
|
+
>["pixelDensities"]
|
|
69
|
+
| "defaults";
|
|
70
|
+
widths?: never;
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const {
|
|
75
|
+
field,
|
|
76
|
+
imgixParams = {},
|
|
77
|
+
alt,
|
|
78
|
+
fallbackAlt,
|
|
79
|
+
width,
|
|
80
|
+
height,
|
|
81
|
+
widths,
|
|
82
|
+
pixelDensities,
|
|
83
|
+
...restProps
|
|
84
|
+
}: Props = $props();
|
|
85
|
+
|
|
86
|
+
const { resolvedWidth, resolvedHeight } = $derived.by(() => {
|
|
87
|
+
if (!isFilled.imageThumbnail(field))
|
|
88
|
+
return { resolvedWidth: undefined, resolvedHeight: undefined };
|
|
89
|
+
|
|
90
|
+
const ar = field.dimensions.width / field.dimensions.height;
|
|
91
|
+
|
|
92
|
+
let resolvedWidth = castInt(width) ?? field.dimensions.width;
|
|
93
|
+
let resolvedHeight = castInt(height) ?? field.dimensions.height;
|
|
94
|
+
if (resolvedWidth != null && resolvedHeight == null) {
|
|
95
|
+
resolvedHeight = resolvedWidth / ar;
|
|
96
|
+
} else if (resolvedWidth == null && resolvedHeight != null) {
|
|
97
|
+
resolvedWidth = resolvedHeight * ar;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return { resolvedWidth, resolvedHeight };
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const { src, srcset } = $derived.by(() => {
|
|
104
|
+
if (!isFilled.imageThumbnail(field))
|
|
105
|
+
return { src: undefined, srcset: undefined };
|
|
106
|
+
|
|
107
|
+
if (pixelDensities) {
|
|
108
|
+
return asImagePixelDensitySrcSet(field, {
|
|
109
|
+
...imgixParams,
|
|
110
|
+
pixelDensities:
|
|
111
|
+
pixelDensities === "defaults" ? undefined : pixelDensities,
|
|
112
|
+
} as ImgixURLParams);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return asImageWidthSrcSet(field, {
|
|
116
|
+
...imgixParams,
|
|
117
|
+
widths: widths === "defaults" ? undefined : widths,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
function castInt(
|
|
122
|
+
input: string | number | null | undefined,
|
|
123
|
+
): number | null | undefined {
|
|
124
|
+
if (
|
|
125
|
+
typeof input === "number" ||
|
|
126
|
+
typeof input === "undefined" ||
|
|
127
|
+
input === null
|
|
128
|
+
) {
|
|
129
|
+
return input;
|
|
130
|
+
} else {
|
|
131
|
+
const parsed = Number.parseInt(input);
|
|
132
|
+
|
|
133
|
+
if (Number.isNaN(parsed)) {
|
|
134
|
+
return undefined;
|
|
135
|
+
} else {
|
|
136
|
+
return parsed;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
59
140
|
</script>
|
|
60
141
|
|
|
61
142
|
<!--
|
|
@@ -78,6 +159,6 @@ $: {
|
|
|
78
159
|
alt={alt ?? (field.alt || fallbackAlt)}
|
|
79
160
|
width={resolvedWidth}
|
|
80
161
|
height={resolvedHeight}
|
|
81
|
-
{
|
|
162
|
+
{...restProps}
|
|
82
163
|
/>
|
|
83
164
|
{/if}
|
|
@@ -1,68 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { asImageWidthSrcSet, asImagePixelDensitySrcSet, type ImageFieldImage } from "@prismicio/client";
|
|
1
|
+
import { type ImageFieldImage, asImagePixelDensitySrcSet, asImageWidthSrcSet } from "@prismicio/client";
|
|
3
2
|
import type { ImgixURLParams } from "imgix-url-builder";
|
|
4
3
|
import type { HTMLImgAttributes } from "svelte/elements";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}));
|
|
56
|
-
events: {
|
|
57
|
-
[evt: string]: CustomEvent<any>;
|
|
58
|
-
};
|
|
59
|
-
slots: {};
|
|
60
|
-
exports?: {} | undefined;
|
|
61
|
-
bindings?: string | undefined;
|
|
62
|
-
};
|
|
63
|
-
export type PrismicImageProps = typeof __propDef.props;
|
|
64
|
-
export type PrismicImageEvents = typeof __propDef.events;
|
|
65
|
-
export type PrismicImageSlots = typeof __propDef.slots;
|
|
4
|
+
type Props = Omit<HTMLImgAttributes, "src" | "srcset" | "alt"> & {
|
|
5
|
+
/**
|
|
6
|
+
* The Prismic image field or thumbnail to render.
|
|
7
|
+
*/
|
|
8
|
+
field: ImageFieldImage | null | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* An object of Imgix URL API parameters to transform the image.
|
|
11
|
+
*
|
|
12
|
+
* See: https://docs.imgix.com/apis/rendering
|
|
13
|
+
*/
|
|
14
|
+
imgixParams?: ImgixURLParams;
|
|
15
|
+
/**
|
|
16
|
+
* Declare an image as decorative by providing `alt=""`.
|
|
17
|
+
*
|
|
18
|
+
* See:
|
|
19
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
20
|
+
*/
|
|
21
|
+
alt?: "";
|
|
22
|
+
/**
|
|
23
|
+
* Declare an image as decorative only if the Image field does not have
|
|
24
|
+
* alternative text by providing `fallbackAlt=""`.
|
|
25
|
+
*
|
|
26
|
+
* See:
|
|
27
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
28
|
+
*/
|
|
29
|
+
fallbackAlt?: "";
|
|
30
|
+
} & ({
|
|
31
|
+
/**
|
|
32
|
+
* Widths used to build a `srcset` value for the Image field.
|
|
33
|
+
*
|
|
34
|
+
* If a `widths` prop is not given or `"defaults"` is passed, the
|
|
35
|
+
* following widths will be used: 640, 750, 828, 1080, 1200, 1920,
|
|
36
|
+
* 2048, 3840.
|
|
37
|
+
*
|
|
38
|
+
* If the Image field contains responsive views, each responsive view
|
|
39
|
+
* can be used as a width in the resulting `srcset` by passing
|
|
40
|
+
* `"thumbnails"` as the `widths` prop.
|
|
41
|
+
*/
|
|
42
|
+
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults";
|
|
43
|
+
pixelDensities?: never;
|
|
44
|
+
} | {
|
|
45
|
+
/**
|
|
46
|
+
* Pixel densities used to build a `srcset` value for the Image field.
|
|
47
|
+
*
|
|
48
|
+
* If a `pixelDensities` prop is passed `"defaults"`, the following
|
|
49
|
+
* pixel densities will be used: 1, 2, 3.
|
|
50
|
+
*/
|
|
51
|
+
pixelDensities: NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
|
|
52
|
+
widths?: never;
|
|
53
|
+
});
|
|
66
54
|
/**
|
|
67
55
|
* Component to render a Prismic image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
|
|
68
56
|
*
|
|
@@ -74,6 +62,6 @@ export type PrismicImageSlots = typeof __propDef.slots;
|
|
|
74
62
|
* />
|
|
75
63
|
* ```
|
|
76
64
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export
|
|
65
|
+
declare const PrismicImage: import("svelte").Component<Props, {}, "">;
|
|
66
|
+
type PrismicImage = ReturnType<typeof PrismicImage>;
|
|
67
|
+
export default PrismicImage;
|
package/dist/PrismicLink.svelte
CHANGED
|
@@ -1,13 +1,56 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
type AsLinkAttrsConfig,
|
|
4
|
+
type LinkField,
|
|
5
|
+
type PrismicDocument,
|
|
6
|
+
asLinkAttrs,
|
|
7
|
+
} from "@prismicio/client";
|
|
8
|
+
import type { HTMLAnchorAttributes } from "svelte/elements";
|
|
9
|
+
|
|
10
|
+
type Props = Omit<HTMLAnchorAttributes, "rel" | "href"> & {
|
|
11
|
+
/**
|
|
12
|
+
* The `rel` attribute for the link. By default, `"noreferrer"` is provided
|
|
13
|
+
* if the link's URL is external. This prop can be provided a function to
|
|
14
|
+
* use the link's metadata to determine the `rel` value.
|
|
15
|
+
*/
|
|
16
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
17
|
+
} & (
|
|
18
|
+
| {
|
|
19
|
+
/**
|
|
20
|
+
* A Prismic link field, content relationship field, or link to media
|
|
21
|
+
* field.
|
|
22
|
+
*/
|
|
23
|
+
field: LinkField | null | undefined;
|
|
24
|
+
document?: never;
|
|
25
|
+
href?: never;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
/**
|
|
29
|
+
* A Prismic document.
|
|
30
|
+
*/
|
|
31
|
+
document: PrismicDocument | null | undefined;
|
|
32
|
+
field?: never;
|
|
33
|
+
href?: never;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
href: HTMLAnchorAttributes["href"];
|
|
37
|
+
document: never;
|
|
38
|
+
field?: never;
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const { field, document, rel, children, ...restProps }: Props = $props();
|
|
43
|
+
|
|
44
|
+
const linkAttrs = $derived(
|
|
45
|
+
asLinkAttrs(field ?? document, {
|
|
46
|
+
rel: typeof rel === "function" ? rel : undefined,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
const href = $derived(
|
|
50
|
+
("href" in restProps ? restProps.href : linkAttrs.href) || "",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const resolvedRel = $derived(typeof rel === "string" ? rel : linkAttrs.rel);
|
|
11
54
|
</script>
|
|
12
55
|
|
|
13
56
|
<!--
|
|
@@ -20,12 +63,6 @@ $: resolvedRel = typeof rel === "string" ? rel : linkAttrs.rel;
|
|
|
20
63
|
```
|
|
21
64
|
-->
|
|
22
65
|
|
|
23
|
-
<a
|
|
24
|
-
{
|
|
25
|
-
rel={resolvedRel}
|
|
26
|
-
href={linkAttrs.href}
|
|
27
|
-
on:click
|
|
28
|
-
{...$$restProps}
|
|
29
|
-
>
|
|
30
|
-
<slot>{field?.text}</slot>
|
|
66
|
+
<a {...linkAttrs} rel={resolvedRel} {href} {...restProps}>
|
|
67
|
+
{#if children}{@render children?.()}{:else}{field?.text}{/if}
|
|
31
68
|
</a>
|
|
@@ -1,42 +1,32 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import { type AsLinkAttrsConfig, type LinkField, type PrismicDocument } from "@prismicio/client";
|
|
3
2
|
import type { HTMLAnchorAttributes } from "svelte/elements";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
slots: {
|
|
32
|
-
default: {};
|
|
33
|
-
};
|
|
34
|
-
exports?: {} | undefined;
|
|
35
|
-
bindings?: string | undefined;
|
|
36
|
-
};
|
|
37
|
-
export type PrismicLinkProps = typeof __propDef.props;
|
|
38
|
-
export type PrismicLinkEvents = typeof __propDef.events;
|
|
39
|
-
export type PrismicLinkSlots = typeof __propDef.slots;
|
|
3
|
+
type Props = Omit<HTMLAnchorAttributes, "rel" | "href"> & {
|
|
4
|
+
/**
|
|
5
|
+
* The `rel` attribute for the link. By default, `"noreferrer"` is provided
|
|
6
|
+
* if the link's URL is external. This prop can be provided a function to
|
|
7
|
+
* use the link's metadata to determine the `rel` value.
|
|
8
|
+
*/
|
|
9
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
10
|
+
} & ({
|
|
11
|
+
/**
|
|
12
|
+
* A Prismic link field, content relationship field, or link to media
|
|
13
|
+
* field.
|
|
14
|
+
*/
|
|
15
|
+
field: LinkField | null | undefined;
|
|
16
|
+
document?: never;
|
|
17
|
+
href?: never;
|
|
18
|
+
} | {
|
|
19
|
+
/**
|
|
20
|
+
* A Prismic document.
|
|
21
|
+
*/
|
|
22
|
+
document: PrismicDocument | null | undefined;
|
|
23
|
+
field?: never;
|
|
24
|
+
href?: never;
|
|
25
|
+
} | {
|
|
26
|
+
href: HTMLAnchorAttributes["href"];
|
|
27
|
+
document: never;
|
|
28
|
+
field?: never;
|
|
29
|
+
});
|
|
40
30
|
/**
|
|
41
31
|
* Component to render a Prismic link, link to media, content relationship, or whole document as an `a` tag.
|
|
42
32
|
*
|
|
@@ -45,6 +35,6 @@ export type PrismicLinkSlots = typeof __propDef.slots;
|
|
|
45
35
|
* <PrismicLink field={document.data.example_link} />
|
|
46
36
|
* ```
|
|
47
37
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export
|
|
38
|
+
declare const PrismicLink: import("svelte").Component<Props, {}, "">;
|
|
39
|
+
type PrismicLink = ReturnType<typeof PrismicLink>;
|
|
40
|
+
export default PrismicLink;
|
|
@@ -1,38 +1,51 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { RTAnyNode } from "@prismicio/client";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
|
|
5
|
+
import PrismicEmbed from "../PrismicEmbed.svelte";
|
|
6
|
+
import PrismicImage from "../PrismicImage.svelte";
|
|
7
|
+
import PrismicLink from "../PrismicLink.svelte";
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
node: RTAnyNode;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const { node, children }: Props = $props();
|
|
15
|
+
|
|
16
|
+
const dirProp = $derived(
|
|
17
|
+
"direction" in node && node.direction === "rtl" ? { direction: "rtl" } : {},
|
|
18
|
+
);
|
|
6
19
|
</script>
|
|
7
20
|
|
|
8
21
|
{#if node.type === "heading1"}
|
|
9
|
-
<h1 {
|
|
22
|
+
<h1 {...dirProp}>{@render children?.()}</h1>
|
|
10
23
|
{:else if node.type === "heading2"}
|
|
11
|
-
<h2 {
|
|
24
|
+
<h2 {...dirProp}>{@render children?.()}</h2>
|
|
12
25
|
{:else if node.type === "heading3"}
|
|
13
|
-
<h3 {
|
|
26
|
+
<h3 {...dirProp}>{@render children?.()}</h3>
|
|
14
27
|
{:else if node.type === "heading4"}
|
|
15
|
-
<h4 {
|
|
28
|
+
<h4 {...dirProp}>{@render children?.()}</h4>
|
|
16
29
|
{:else if node.type === "heading5"}
|
|
17
|
-
<h5 {
|
|
30
|
+
<h5 {...dirProp}>{@render children?.()}</h5>
|
|
18
31
|
{:else if node.type === "heading6"}
|
|
19
|
-
<h6 {
|
|
32
|
+
<h6 {...dirProp}>{@render children?.()}</h6>
|
|
20
33
|
{:else if node.type === "paragraph"}
|
|
21
|
-
<p {
|
|
34
|
+
<p {...dirProp}>{@render children?.()}</p>
|
|
22
35
|
{:else if node.type === "preformatted"}
|
|
23
|
-
<pre
|
|
36
|
+
<pre>{@render children?.()}</pre>
|
|
24
37
|
{:else if node.type === "strong"}
|
|
25
|
-
<strong
|
|
38
|
+
<strong>{@render children?.()}</strong>
|
|
26
39
|
{:else if node.type === "em"}
|
|
27
|
-
<em
|
|
40
|
+
<em>{@render children?.()}</em>
|
|
28
41
|
{:else if node.type === "list-item"}
|
|
29
|
-
<li {
|
|
42
|
+
<li {...dirProp}>{@render children?.()}</li>
|
|
30
43
|
{:else if node.type === "o-list-item"}
|
|
31
|
-
<li {
|
|
44
|
+
<li {...dirProp}>{@render children?.()}</li>
|
|
32
45
|
{:else if node.type === "group-list-item"}
|
|
33
|
-
<ul
|
|
46
|
+
<ul>{@render children?.()}</ul>
|
|
34
47
|
{:else if node.type === "group-o-list-item"}
|
|
35
|
-
<ol
|
|
48
|
+
<ol>{@render children?.()}</ol>
|
|
36
49
|
{:else if node.type === "image"}
|
|
37
50
|
<p class="block-img">
|
|
38
51
|
<PrismicImage field={node} />
|
|
@@ -40,11 +53,11 @@ $: dir = "direction" in node && node.direction === "rtl" ? "rtl" : void 0;
|
|
|
40
53
|
{:else if node.type === "embed"}
|
|
41
54
|
<PrismicEmbed field={node.oembed} />
|
|
42
55
|
{:else if node.type === "hyperlink"}
|
|
43
|
-
<PrismicLink field={node.data}
|
|
56
|
+
<PrismicLink field={node.data}>{@render children?.()}</PrismicLink>
|
|
44
57
|
{:else if node.type === "label"}
|
|
45
|
-
<span class={node.data.label}
|
|
58
|
+
<span class={node.data.label}>{@render children?.()}</span>
|
|
46
59
|
{:else}
|
|
47
|
-
{#each node.text.split("\n") as line, index}
|
|
60
|
+
{#each node.text.split("\n") as line, index (index)}
|
|
48
61
|
{#if index > 0}<br />{/if}{line}
|
|
49
62
|
{/each}
|
|
50
63
|
{/if}
|