@prismicio/svelte 1.6.0-alpha.0 → 2.0.0-alpha.1

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 (44) hide show
  1. package/README.md +1 -1
  2. package/dist/PrismicEmbed.svelte +12 -2
  3. package/dist/PrismicEmbed.svelte.d.ts +8 -19
  4. package/dist/PrismicImage.svelte +140 -59
  5. package/dist/PrismicImage.svelte.d.ts +54 -66
  6. package/dist/PrismicLink.svelte +55 -18
  7. package/dist/PrismicLink.svelte.d.ts +30 -40
  8. package/dist/PrismicRichText/DefaultComponent.svelte +31 -22
  9. package/dist/PrismicRichText/DefaultComponent.svelte.d.ts +5 -21
  10. package/dist/PrismicRichText/PrismicRichText.svelte +23 -5
  11. package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +13 -23
  12. package/dist/PrismicRichText/Serialize.svelte +35 -16
  13. package/dist/PrismicRichText/Serialize.svelte.d.ts +8 -19
  14. package/dist/PrismicTable/DefaultComponent.svelte +12 -2
  15. package/dist/PrismicTable/DefaultComponent.svelte.d.ts +7 -19
  16. package/dist/PrismicTable/PrismicTable.svelte +46 -30
  17. package/dist/PrismicTable/PrismicTable.svelte.d.ts +19 -28
  18. package/dist/PrismicText.svelte +49 -23
  19. package/dist/PrismicText.svelte.d.ts +17 -20
  20. package/dist/SliceZone/SliceZone.svelte +53 -9
  21. package/dist/SliceZone/SliceZone.svelte.d.ts +36 -84
  22. package/dist/SliceZone/TodoComponent.svelte +19 -9
  23. package/dist/SliceZone/TodoComponent.svelte.d.ts +8 -20
  24. package/dist/index.d.ts +7 -1
  25. package/dist/kit/PrismicPreview.svelte +107 -58
  26. package/dist/kit/PrismicPreview.svelte.d.ts +21 -30
  27. package/dist/lib/devMsg.js +1 -1
  28. package/dist/types.d.ts +121 -74
  29. package/package.json +27 -24
  30. package/src/PrismicEmbed.svelte +8 -4
  31. package/src/PrismicImage.svelte +65 -69
  32. package/src/PrismicLink.svelte +23 -19
  33. package/src/PrismicRichText/DefaultComponent.svelte +24 -20
  34. package/src/PrismicRichText/PrismicRichText.svelte +15 -11
  35. package/src/PrismicRichText/Serialize.svelte +15 -9
  36. package/src/PrismicTable/DefaultComponent.svelte +10 -2
  37. package/src/PrismicTable/PrismicTable.svelte +37 -43
  38. package/src/PrismicText.svelte +30 -22
  39. package/src/SliceZone/SliceZone.svelte +42 -91
  40. package/src/SliceZone/TodoComponent.svelte +14 -8
  41. package/src/index.ts +10 -1
  42. package/src/kit/PrismicPreview.svelte +30 -22
  43. package/src/lib/devMsg.ts +1 -1
  44. package/src/types.ts +178 -42
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-2023 Prismic <contact@prismic.io> (https://prismic.io)
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.
@@ -1,5 +1,15 @@
1
- <script>import { isFilled } from "@prismicio/client";
2
- export let field;
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
- declare const __propDef: {
4
- props: {
5
- /**
6
- * An Embed field from Prismic.
7
- */ field: EmbedField;
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
- export default class PrismicEmbed extends SvelteComponent<PrismicEmbedProps, PrismicEmbedEvents, PrismicEmbedSlots> {
28
- }
29
- export {};
16
+ declare const PrismicEmbed: import("svelte").Component<Props, {}, "">;
17
+ type PrismicEmbed = ReturnType<typeof PrismicEmbed>;
18
+ export default PrismicEmbed;
@@ -1,61 +1,142 @@
1
- <script>import {
2
- asImageWidthSrcSet,
3
- asImagePixelDensitySrcSet,
4
- isFilled
5
- } from "@prismicio/client";
6
- export let field;
7
- export let imgixParams = {};
8
- export let alt = void 0;
9
- export let fallbackAlt = void 0;
10
- export let width = void 0;
11
- export let height = void 0;
12
- export let widths = void 0;
13
- export let pixelDensities = void 0;
14
- let src = void 0;
15
- let srcset = void 0;
16
- let resolvedWidth = void 0;
17
- let resolvedHeight = void 0;
18
- $: {
19
- if (isFilled.imageThumbnail(field)) {
20
- const castInt = (input) => {
21
- if (typeof input === "number" || typeof input === "undefined" || input === null) {
22
- return input;
23
- } else {
24
- const parsed = Number.parseInt(input);
25
- if (Number.isNaN(parsed)) {
26
- return void 0;
27
- } else {
28
- return parsed;
29
- }
30
- }
31
- };
32
- const ar = field.dimensions.width / field.dimensions.height;
33
- const castedWidth = castInt(width);
34
- const castedHeight = castInt(height);
35
- resolvedWidth = castedWidth ?? field.dimensions.width;
36
- resolvedHeight = castedHeight ?? field.dimensions.height;
37
- if (castedWidth != null && castedHeight == null) {
38
- resolvedHeight = castedWidth / ar;
39
- } else if (castedWidth == null && castedHeight != null) {
40
- resolvedWidth = castedHeight * ar;
41
- }
42
- if (widths || !pixelDensities) {
43
- const res = asImageWidthSrcSet(field, {
44
- ...imgixParams,
45
- widths: widths === "defaults" ? void 0 : widths
46
- });
47
- src = res.src;
48
- srcset = res.srcset;
49
- } else if (pixelDensities) {
50
- const res = asImagePixelDensitySrcSet(field, {
51
- ...imgixParams,
52
- pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
53
- });
54
- src = res.src;
55
- srcset = res.srcset;
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
- {...$$restProps}
162
+ {...restProps}
82
163
  />
83
164
  {/if}
@@ -1,68 +1,56 @@
1
- import { SvelteComponent } from "svelte";
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
- declare const __propDef: {
6
- props: Omit<HTMLImgAttributes, "src" | "srcset" | "alt"> & ({
7
- /**
8
- * The Prismic image field or thumbnail to render.
9
- */
10
- field: ImageFieldImage | null | undefined;
11
- /**
12
- * An object of Imgix URL API parameters to transform the image.
13
- *
14
- * See: https://docs.imgix.com/apis/rendering
15
- */
16
- imgixParams?: ImgixURLParams;
17
- /**
18
- * Declare an image as decorative by providing `alt=""`.
19
- *
20
- * See:
21
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
22
- */
23
- alt?: "";
24
- /**
25
- * Declare an image as decorative only if the Image field does not have
26
- * alternative text by providing `fallbackAlt=""`.
27
- *
28
- * See:
29
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
30
- */
31
- fallbackAlt?: "";
32
- } & ({
33
- /**
34
- * Widths used to build a `srcset` value for the Image field.
35
- *
36
- * If a `widths` prop is not given or `"defaults"` is passed, the
37
- * following widths will be used: 640, 750, 828, 1080, 1200, 1920,
38
- * 2048, 3840.
39
- *
40
- * If the Image field contains responsive views, each responsive view
41
- * can be used as a width in the resulting `srcset` by passing
42
- * `"thumbnails"` as the `widths` prop.
43
- */
44
- widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults";
45
- pixelDensities?: never;
46
- } | {
47
- /**
48
- * Pixel densities used to build a `srcset` value for the Image field.
49
- *
50
- * If a `pixelDensities` prop is passed `"defaults"`, the following
51
- * pixel densities will be used: 1, 2, 3.
52
- */
53
- pixelDensities: NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
54
- widths?: never;
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
- export default class PrismicImage extends SvelteComponent<PrismicImageProps, PrismicImageEvents, PrismicImageSlots> {
78
- }
79
- export {};
65
+ declare const PrismicImage: import("svelte").Component<Props, {}, "">;
66
+ type PrismicImage = ReturnType<typeof PrismicImage>;
67
+ export default PrismicImage;
@@ -1,13 +1,56 @@
1
- <script>import {
2
- asLinkAttrs
3
- } from "@prismicio/client";
4
- export let field = void 0;
5
- export let document = void 0;
6
- export let rel = void 0;
7
- $: linkAttrs = asLinkAttrs(field ?? document, {
8
- rel: typeof rel === "function" ? rel : void 0
9
- });
10
- $: resolvedRel = typeof rel === "string" ? rel : linkAttrs.rel;
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
- {...linkAttrs}
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
- declare const __propDef: {
5
- props: Omit<HTMLAnchorAttributes, "rel" | "href"> & ({
6
- /**
7
- * The `rel` attribute for the link. By default, `"noreferrer"` is provided
8
- * if the link's URL is external. This prop can be provided a function to
9
- * use the link's metadata to determine the `rel` value.
10
- */
11
- rel?: string | AsLinkAttrsConfig["rel"];
12
- } & ({
13
- /**
14
- * A Prismic link field, content relationship field, or link to media
15
- * field.
16
- */
17
- field: LinkField;
18
- document?: never;
19
- } | {
20
- /**
21
- * A Prismic document.
22
- */
23
- document: PrismicDocument;
24
- field?: never;
25
- }));
26
- events: {
27
- click: MouseEvent;
28
- } & {
29
- [evt: string]: CustomEvent<any>;
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
- export default class PrismicLink extends SvelteComponent<PrismicLinkProps, PrismicLinkEvents, PrismicLinkSlots> {
49
- }
50
- export {};
38
+ declare const PrismicLink: import("svelte").Component<Props, {}, "">;
39
+ type PrismicLink = ReturnType<typeof PrismicLink>;
40
+ export default PrismicLink;
@@ -1,38 +1,47 @@
1
- <script>import PrismicEmbed from "../PrismicEmbed.svelte";
2
- import PrismicImage from "../PrismicImage.svelte";
3
- import PrismicLink from "../PrismicLink.svelte";
4
- export let node;
5
- $: dir = "direction" in node && node.direction === "rtl" ? "rtl" : void 0;
1
+ <script lang="ts">
2
+ import type { RichTextComponentProps } from "../types";
3
+
4
+ import PrismicEmbed from "../PrismicEmbed.svelte";
5
+ import PrismicImage from "../PrismicImage.svelte";
6
+ import PrismicLink from "../PrismicLink.svelte";
7
+
8
+ type Props = RichTextComponentProps;
9
+
10
+ const { node, children }: Props = $props();
11
+
12
+ const dirProp = $derived(
13
+ "direction" in node && node.direction === "rtl" ? { direction: "rtl" } : {},
14
+ );
6
15
  </script>
7
16
 
8
17
  {#if node.type === "heading1"}
9
- <h1 {dir}><slot /></h1>
18
+ <h1 {...dirProp}>{@render children()}</h1>
10
19
  {:else if node.type === "heading2"}
11
- <h2 {dir}><slot /></h2>
20
+ <h2 {...dirProp}>{@render children()}</h2>
12
21
  {:else if node.type === "heading3"}
13
- <h3 {dir}><slot /></h3>
22
+ <h3 {...dirProp}>{@render children()}</h3>
14
23
  {:else if node.type === "heading4"}
15
- <h4 {dir}><slot /></h4>
24
+ <h4 {...dirProp}>{@render children()}</h4>
16
25
  {:else if node.type === "heading5"}
17
- <h5 {dir}><slot /></h5>
26
+ <h5 {...dirProp}>{@render children()}</h5>
18
27
  {:else if node.type === "heading6"}
19
- <h6 {dir}><slot /></h6>
28
+ <h6 {...dirProp}>{@render children()}</h6>
20
29
  {:else if node.type === "paragraph"}
21
- <p {dir}><slot /></p>
30
+ <p {...dirProp}>{@render children()}</p>
22
31
  {:else if node.type === "preformatted"}
23
- <pre><slot /></pre>
32
+ <pre>{@render children()}</pre>
24
33
  {:else if node.type === "strong"}
25
- <strong><slot /></strong>
34
+ <strong>{@render children()}</strong>
26
35
  {:else if node.type === "em"}
27
- <em><slot /></em>
36
+ <em>{@render children()}</em>
28
37
  {:else if node.type === "list-item"}
29
- <li {dir}><slot /></li>
38
+ <li {...dirProp}>{@render children()}</li>
30
39
  {:else if node.type === "o-list-item"}
31
- <li {dir}><slot /></li>
40
+ <li {...dirProp}>{@render children()}</li>
32
41
  {:else if node.type === "group-list-item"}
33
- <ul><slot /></ul>
42
+ <ul>{@render children()}</ul>
34
43
  {:else if node.type === "group-o-list-item"}
35
- <ol><slot /></ol>
44
+ <ol>{@render children()}</ol>
36
45
  {:else if node.type === "image"}
37
46
  <p class="block-img">
38
47
  <PrismicImage field={node} />
@@ -40,11 +49,11 @@ $: dir = "direction" in node && node.direction === "rtl" ? "rtl" : void 0;
40
49
  {:else if node.type === "embed"}
41
50
  <PrismicEmbed field={node.oembed} />
42
51
  {:else if node.type === "hyperlink"}
43
- <PrismicLink field={node.data}><slot /></PrismicLink>
52
+ <PrismicLink field={node.data}>{@render children()}</PrismicLink>
44
53
  {:else if node.type === "label"}
45
- <span class={node.data.label}><slot /></span>
54
+ <span class={node.data.label}>{@render children()}</span>
46
55
  {:else}
47
- {#each node.text.split("\n") as line, index}
56
+ {#each node.text.split("\n") as line, index (index)}
48
57
  {#if index > 0}<br />{/if}{line}
49
58
  {/each}
50
59
  {/if}