@prismicio/svelte 1.5.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.
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 -17
  4. package/dist/PrismicImage.svelte +140 -59
  5. package/dist/PrismicImage.svelte.d.ts +54 -64
  6. package/dist/PrismicLink.svelte +55 -20
  7. package/dist/PrismicLink.svelte.d.ts +30 -38
  8. package/dist/PrismicRichText/DefaultComponent.svelte +35 -23
  9. package/dist/PrismicRichText/DefaultComponent.svelte.d.ts +7 -17
  10. package/dist/PrismicRichText/PrismicRichText.svelte +23 -6
  11. package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +13 -22
  12. package/dist/PrismicRichText/Serialize.svelte +35 -16
  13. package/dist/PrismicRichText/Serialize.svelte.d.ts +9 -19
  14. package/dist/PrismicTable/DefaultComponent.svelte +12 -2
  15. package/dist/PrismicTable/DefaultComponent.svelte.d.ts +7 -17
  16. package/dist/PrismicTable/PrismicTable.svelte +46 -30
  17. package/dist/PrismicTable/PrismicTable.svelte.d.ts +19 -31
  18. package/dist/PrismicText.svelte +49 -23
  19. package/dist/PrismicText.svelte.d.ts +17 -18
  20. package/dist/SliceZone/SliceZone.svelte +53 -8
  21. package/dist/SliceZone/SliceZone.svelte.d.ts +36 -110
  22. package/dist/SliceZone/TodoComponent.svelte +19 -9
  23. package/dist/SliceZone/TodoComponent.svelte.d.ts +8 -18
  24. package/dist/index.d.ts +1 -1
  25. package/dist/kit/PrismicPreview.svelte +107 -59
  26. package/dist/kit/PrismicPreview.svelte.d.ts +21 -28
  27. package/dist/lib/devMsg.js +1 -1
  28. package/dist/types.d.ts +95 -20
  29. package/package.json +35 -33
  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 +27 -19
  34. package/src/PrismicRichText/PrismicRichText.svelte +14 -10
  35. package/src/PrismicRichText/Serialize.svelte +13 -7
  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 -89
  40. package/src/SliceZone/TodoComponent.svelte +14 -8
  41. package/src/index.ts +1 -1
  42. package/src/kit/PrismicPreview.svelte +30 -22
  43. package/src/lib/devMsg.ts +1 -1
  44. package/src/types.ts +105 -18
@@ -1,19 +1,9 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { RTAnyNode } from "@prismicio/client";
3
- declare const __propDef: {
4
- props: {
5
- node: RTAnyNode;
6
- };
7
- events: {
8
- [evt: string]: CustomEvent<any>;
9
- };
10
- slots: {
11
- default: {};
12
- };
2
+ import type { Snippet } from "svelte";
3
+ type Props = {
4
+ node: RTAnyNode;
5
+ children?: Snippet;
13
6
  };
14
- export type DefaultComponentProps = typeof __propDef.props;
15
- export type DefaultComponentEvents = typeof __propDef.events;
16
- export type DefaultComponentSlots = typeof __propDef.slots;
17
- export default class DefaultComponent extends SvelteComponent<DefaultComponentProps, DefaultComponentEvents, DefaultComponentSlots> {
18
- }
19
- export {};
7
+ declare const DefaultComponent: import("svelte").Component<Props, {}, "">;
8
+ type DefaultComponent = ReturnType<typeof DefaultComponent>;
9
+ export default DefaultComponent;
@@ -1,9 +1,26 @@
1
- <script>import { asTree } from "@prismicio/richtext";
2
- import Serialize from "./Serialize.svelte";
3
- export let field;
4
- export let components = {};
5
- $:
6
- children = asTree(field).children;
1
+ <script lang="ts">
2
+ import type { RichTextField } from "@prismicio/client";
3
+ import { asTree } from "@prismicio/client/richtext";
4
+
5
+ import type { SvelteRichTextSerializer } from "../types";
6
+
7
+ import Serialize from "./Serialize.svelte";
8
+
9
+ type Props = {
10
+ /**
11
+ * The Prismic rich text field to render.
12
+ */
13
+ field: RichTextField;
14
+
15
+ /**
16
+ * An object that maps a rich text block type to a Svelte component.
17
+ */
18
+ components?: SvelteRichTextSerializer;
19
+ };
20
+
21
+ const { field, components = {} }: Props = $props();
22
+
23
+ const children = $derived(asTree(field).children);
7
24
  </script>
8
25
 
9
26
  <!--
@@ -1,24 +1,15 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { RichTextField } from "@prismicio/client";
3
- declare const __propDef: {
4
- props: {
5
- /**
6
- * The Prismic rich text field to render.
7
- */ field: RichTextField;
8
- /**
9
- * An object that maps a rich text block type to a Svelte component.
10
- */ components?: Partial<Record<"heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "paragraph" | "preformatted" | "strong" | "em" | "listItem" | "oListItem" | "list" | "oList" | "image" | "embed" | "hyperlink" | "label" | "span", new (...args: any[]) => SvelteComponent<Partial<{
11
- node: import("@prismicio/client").RTAnyNode;
12
- }>, any, any>>> | undefined;
13
- };
14
- events: {
15
- [evt: string]: CustomEvent<any>;
16
- };
17
- slots: {};
2
+ import type { SvelteRichTextSerializer } from "../types";
3
+ type Props = {
4
+ /**
5
+ * The Prismic rich text field to render.
6
+ */
7
+ field: RichTextField;
8
+ /**
9
+ * An object that maps a rich text block type to a Svelte component.
10
+ */
11
+ components?: SvelteRichTextSerializer;
18
12
  };
19
- export type PrismicRichTextProps = typeof __propDef.props;
20
- export type PrismicRichTextEvents = typeof __propDef.events;
21
- export type PrismicRichTextSlots = typeof __propDef.slots;
22
13
  /**
23
14
  * Component to render a Prismic rich text field.
24
15
  *
@@ -27,6 +18,6 @@ export type PrismicRichTextSlots = typeof __propDef.slots;
27
18
  * <PrismicRichText field={document.data.example_rich_text} />
28
19
  * ```
29
20
  */
30
- export default class PrismicRichText extends SvelteComponent<PrismicRichTextProps, PrismicRichTextEvents, PrismicRichTextSlots> {
31
- }
32
- export {};
21
+ declare const PrismicRichText: import("svelte").Component<Props, {}, "">;
22
+ type PrismicRichText = ReturnType<typeof PrismicRichText>;
23
+ export default PrismicRichText;
@@ -1,23 +1,42 @@
1
- <script>import DefaultComponent from "./DefaultComponent.svelte";
2
- export let components = {};
3
- export let children;
4
- const CHILD_TYPE_RENAMES = {
5
- "list-item": "listItem",
6
- "o-list-item": "oListItem",
7
- "group-list-item": "list",
8
- "group-o-list-item": "oList"
9
- };
10
- function getComponent(child) {
11
- return components[CHILD_TYPE_RENAMES[child.type] || child.type] || DefaultComponent;
12
- }
1
+ <script lang="ts">
2
+ import type { asTree } from "@prismicio/client/richtext";
3
+
4
+ import type { SvelteRichTextSerializer } from "../types";
5
+
6
+ import DefaultComponent from "./DefaultComponent.svelte";
7
+ import Serialize from "./Serialize.svelte";
8
+
9
+ type Props = {
10
+ components: SvelteRichTextSerializer;
11
+ children: ReturnType<typeof asTree>["children"];
12
+ };
13
+
14
+ const { components, children }: Props = $props();
15
+
16
+ const CHILD_TYPE_RENAMES = {
17
+ "list-item": "listItem",
18
+ "o-list-item": "oListItem",
19
+ "group-list-item": "list",
20
+ "group-o-list-item": "oList",
21
+ } as const;
22
+
23
+ function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
24
+ return (
25
+ components[
26
+ CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
27
+ (child.type as keyof typeof components)
28
+ ] || DefaultComponent
29
+ );
30
+ }
13
31
  </script>
14
32
 
15
- {#each children as child}
16
- <svelte:component this={getComponent(child)} node={child.node}>
33
+ {#each children as child (child.key)}
34
+ {@const Component = getComponent(child)}
35
+ <Component node={child.node}>
17
36
  <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
18
- {#if child.children.length > 0}<svelte:self
37
+ {#if child.children.length > 0}<Serialize
19
38
  children={child.children}
20
39
  {components}
21
- />{/if}</svelte:component
40
+ />{/if}</Component
22
41
  >
23
42
  {/each}
@@ -1,20 +1,10 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { asTree } from "@prismicio/richtext";
3
- declare const __propDef: {
4
- props: {
5
- components?: Partial<Record<"heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "paragraph" | "preformatted" | "strong" | "em" | "listItem" | "oListItem" | "list" | "oList" | "image" | "embed" | "hyperlink" | "label" | "span", new (...args: any[]) => SvelteComponent<Partial<{
6
- node: import("@prismicio/client/*").RTAnyNode;
7
- }>, any, any>>> | undefined;
8
- children: ReturnType<typeof asTree>["children"];
9
- };
10
- events: {
11
- [evt: string]: CustomEvent<any>;
12
- };
13
- slots: {};
1
+ import type { asTree } from "@prismicio/client/richtext";
2
+ import type { SvelteRichTextSerializer } from "../types";
3
+ import Serialize from "./Serialize.svelte";
4
+ type Props = {
5
+ components: SvelteRichTextSerializer;
6
+ children: ReturnType<typeof asTree>["children"];
14
7
  };
15
- export type SerializeProps = typeof __propDef.props;
16
- export type SerializeEvents = typeof __propDef.events;
17
- export type SerializeSlots = typeof __propDef.slots;
18
- export default class Serialize extends SvelteComponent<SerializeProps, SerializeEvents, SerializeSlots> {
19
- }
20
- export {};
8
+ declare const Serialize: import("svelte").Component<Props, {}, "">;
9
+ type Serialize = ReturnType<typeof Serialize>;
10
+ export default Serialize;
@@ -1,4 +1,14 @@
1
- <script>export let type;
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+
4
+ import type { TableComponents } from "../types";
5
+
6
+ type Props = {
7
+ type: keyof TableComponents;
8
+ children?: Snippet;
9
+ };
10
+
11
+ const { type, children }: Props = $props();
2
12
  </script>
3
13
 
4
- <svelte:element this={type}><slot /></svelte:element>
14
+ <svelte:element this={type}>{@render children?.()}</svelte:element>
@@ -1,19 +1,9 @@
1
- import { SvelteComponent } from "svelte";
1
+ import type { Snippet } from "svelte";
2
2
  import type { TableComponents } from "../types";
3
- declare const __propDef: {
4
- props: {
5
- type: keyof TableComponents;
6
- };
7
- events: {
8
- [evt: string]: CustomEvent<any>;
9
- };
10
- slots: {
11
- default: {};
12
- };
3
+ type Props = {
4
+ type: keyof TableComponents;
5
+ children?: Snippet;
13
6
  };
14
- export type DefaultComponentProps = typeof __propDef.props;
15
- export type DefaultComponentEvents = typeof __propDef.events;
16
- export type DefaultComponentSlots = typeof __propDef.slots;
17
- export default class DefaultComponent extends SvelteComponent<DefaultComponentProps, DefaultComponentEvents, DefaultComponentSlots> {
18
- }
19
- export {};
7
+ declare const DefaultComponent: import("svelte").Component<Props, {}, "">;
8
+ type DefaultComponent = ReturnType<typeof DefaultComponent>;
9
+ export default DefaultComponent;
@@ -1,51 +1,67 @@
1
- <script>import { isFilled } from "@prismicio/client";
2
- import {} from "svelte";
3
- import PrismicRichText from "../PrismicRichText/PrismicRichText.svelte";
4
- import DefaultComponent from "./DefaultComponent.svelte";
5
- export let field;
6
- export let components = {};
7
- export let fallback = void 0;
8
- const createComponent = (type) => {
9
- const Component = components[type] ?? DefaultComponent;
10
- return {
11
- Component,
12
- props: Component === DefaultComponent ? { type } : {}
13
- };
14
- };
15
- const { Component: Table, props: tableProps } = createComponent("table");
16
- const { Component: Thead, props: theadProps } = createComponent("thead");
17
- const { Component: Tbody, props: tbodyProps } = createComponent("tbody");
18
- const { Component: Tr, props: trProps } = createComponent("tr");
19
- const { Component: Th, props: thProps } = createComponent("th");
20
- const { Component: Td, props: tdProps } = createComponent("td");
1
+ <script lang="ts">
2
+ import { type TableField, isFilled } from "@prismicio/client";
3
+ import { type Component } from "svelte";
4
+
5
+ import type { SvelteRichTextSerializer, TableComponents } from "../types";
6
+
7
+ import PrismicRichText from "../PrismicRichText/PrismicRichText.svelte";
8
+
9
+ import DefaultComponent from "./DefaultComponent.svelte";
10
+
11
+ type Props = {
12
+ /**
13
+ * The Prismic table field to render.
14
+ */
15
+ field: TableField;
16
+
17
+ /**
18
+ * An object that maps a rich text block type to a Svelte component.
19
+ */
20
+ components?: TableComponents & SvelteRichTextSerializer;
21
+
22
+ /**
23
+ * The component rendered when the field is empty. If a fallback is not
24
+ * given, `null` will be rendered.
25
+ */
26
+ fallback?: Component;
27
+ };
28
+
29
+ const { field, components = {}, fallback: Fallback }: Props = $props();
30
+
31
+ const Table = components.table ?? DefaultComponent;
32
+ const Thead = components.thead ?? DefaultComponent;
33
+ const Tbody = components.tbody ?? DefaultComponent;
34
+ const Tr = components.tr ?? DefaultComponent;
35
+ const Th = components.th ?? DefaultComponent;
36
+ const Td = components.td ?? DefaultComponent;
21
37
  </script>
22
38
 
23
39
  <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
24
40
  {#if isFilled.table(field)}
25
- <Table {...tableProps} table={field}>
41
+ <Table type="table" table={field}>
26
42
  {#if field?.head}
27
- <Thead {...theadProps} head={field.head}>
43
+ <Thead type="thead" head={field.head}>
28
44
  {#each field.head.rows as row (row.key)}
29
- <Tr {...trProps} {row}>
45
+ <Tr type="tr" {row}>
30
46
  {#each row.cells as cell (cell.key)}
31
- <Th {...thProps} {cell}>
47
+ <Th type="th" {cell}>
32
48
  <PrismicRichText field={cell.content} {components} /></Th
33
49
  >{/each}</Tr
34
50
  >{/each}</Thead
35
- >{/if}<Tbody {...tbodyProps} body={field.body}>
51
+ >{/if}<Tbody type="tbody" body={field.body}>
36
52
  {#each field.body.rows as row (row.key)}
37
- <Tr {...trProps} {row}>
53
+ <Tr type="tr" {row}>
38
54
  {#each row.cells as cell (cell.key)}
39
55
  {#if cell.type === "header"}
40
- <Th {...thProps} {cell}>
56
+ <Th type="th" {cell}>
41
57
  <PrismicRichText field={cell.content} {components} /></Th
42
- >{:else}<Td {...tdProps} {cell}>
58
+ >{:else}<Td type="td" {cell}>
43
59
  <PrismicRichText field={cell.content} {components} /></Td
44
60
  >{/if}{/each}</Tr
45
61
  >
46
62
  {/each}
47
63
  </Tbody>
48
64
  </Table>
49
- {:else if fallback !== undefined}
50
- <svelte:component this={fallback} />
65
+ {:else if Fallback}
66
+ <Fallback />
51
67
  {/if}
@@ -1,33 +1,21 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import { type TableField } from "@prismicio/client";
3
- import { type ComponentType } from "svelte";
4
- import type { TableComponents } from "../types";
5
- declare const __propDef: {
6
- props: {
7
- /**
8
- * The Prismic table field to render.
9
- */ field: TableField;
10
- /**
11
- * An object that maps a rich text block type to a Svelte component.
12
- */ components?: (TableComponents & Partial<Record<"heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "paragraph" | "preformatted" | "strong" | "em" | "listItem" | "oListItem" | "list" | "oList" | "image" | "embed" | "hyperlink" | "label" | "span", new (...args: any[]) => SvelteComponent<Partial<{
13
- /**
14
- * An object that maps a rich text block type to a Svelte component.
15
- */
16
- node: import("@prismicio/client").RTAnyNode;
17
- }>, any, any>>>) | undefined;
18
- /**
19
- * The component rendered when the field is empty. If a fallback is not given,
20
- * `null` will be rendered.
21
- */ fallback?: ComponentType | undefined;
22
- };
23
- events: {
24
- [evt: string]: CustomEvent<any>;
25
- };
26
- slots: {};
2
+ import { type Component } from "svelte";
3
+ import type { SvelteRichTextSerializer, TableComponents } from "../types";
4
+ type Props = {
5
+ /**
6
+ * The Prismic table field to render.
7
+ */
8
+ field: TableField;
9
+ /**
10
+ * An object that maps a rich text block type to a Svelte component.
11
+ */
12
+ components?: TableComponents & SvelteRichTextSerializer;
13
+ /**
14
+ * The component rendered when the field is empty. If a fallback is not
15
+ * given, `null` will be rendered.
16
+ */
17
+ fallback?: Component;
27
18
  };
28
- export type PrismicTableProps = typeof __propDef.props;
29
- export type PrismicTableEvents = typeof __propDef.events;
30
- export type PrismicTableSlots = typeof __propDef.slots;
31
- export default class PrismicTable extends SvelteComponent<PrismicTableProps, PrismicTableEvents, PrismicTableSlots> {
32
- }
33
- export {};
19
+ declare const PrismicTable: Component<Props, {}, "">;
20
+ type PrismicTable = ReturnType<typeof PrismicTable>;
21
+ export default PrismicTable;
@@ -1,26 +1,52 @@
1
- <script>import { isFilled, asText } from "@prismicio/client";
2
- import { DEV } from "esm-env";
3
- import { devMsg } from "./lib/devMsg";
4
- export let field;
5
- export let separator = void 0;
6
- export let fallback = void 0;
7
- if (DEV) {
8
- if ("className" in $$restProps) {
9
- console.warn(
10
- `[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg(
11
- "classname-is-not-a-valid-prop"
12
- )}.`,
13
- field
14
- );
15
- }
16
- if (typeof field === "string") {
17
- throw new Error(
18
- `[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
19
- "prismictext-works-only-with-rich-text-and-title-fields"
20
- )}`
21
- );
22
- }
23
- }
1
+ <script lang="ts">
2
+ import type { RichTextField } from "@prismicio/client";
3
+ import { asText, isFilled } from "@prismicio/client";
4
+ import { DEV } from "esm-env";
5
+
6
+ import { devMsg } from "./lib/devMsg";
7
+
8
+ type Props = {
9
+ /**
10
+ * A Rich Text or Title field from Prismic.
11
+ */
12
+ field: RichTextField;
13
+
14
+ /**
15
+ * The separator used between blocks. Defaults to `\n`.
16
+ */
17
+ separator?: string | undefined;
18
+
19
+ /**
20
+ * The string rendered when the field is empty. If a fallback is not given,
21
+ * `null` will be rendered.
22
+ */
23
+ fallback?: string | undefined;
24
+ };
25
+
26
+ const { field, separator, fallback, ...restProps }: Props = $props();
27
+
28
+ $effect(() => {
29
+ if (DEV) {
30
+ if ("className" in restProps) {
31
+ console.warn(
32
+ `[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg(
33
+ "classname-is-not-a-valid-prop",
34
+ )}.`,
35
+ $state.snapshot(field),
36
+ );
37
+ }
38
+ }
39
+ });
40
+
41
+ if (DEV) {
42
+ if (typeof field === "string") {
43
+ throw new Error(
44
+ `[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
45
+ "prismictext-works-only-with-rich-text-and-title-fields",
46
+ )}`,
47
+ );
48
+ }
49
+ }
24
50
  </script>
25
51
 
26
52
  <!--
@@ -1,20 +1,19 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { RichTextField } from "@prismicio/client";
3
- declare const __propDef: {
4
- props: {
5
- [x: string]: any;
6
- field: RichTextField;
7
- separator?: string | undefined;
8
- fallback?: string | undefined;
9
- };
10
- events: {
11
- [evt: string]: CustomEvent<any>;
12
- };
13
- slots: {};
2
+ type Props = {
3
+ /**
4
+ * A Rich Text or Title field from Prismic.
5
+ */
6
+ field: RichTextField;
7
+ /**
8
+ * The separator used between blocks. Defaults to `\n`.
9
+ */
10
+ separator?: string | undefined;
11
+ /**
12
+ * The string rendered when the field is empty. If a fallback is not given,
13
+ * `null` will be rendered.
14
+ */
15
+ fallback?: string | undefined;
14
16
  };
15
- export type PrismicTextProps = typeof __propDef.props;
16
- export type PrismicTextEvents = typeof __propDef.events;
17
- export type PrismicTextSlots = typeof __propDef.slots;
18
17
  /**
19
18
  * Component to render a Prismic Rich Text or Title field as plain text.
20
19
  *
@@ -23,6 +22,6 @@ export type PrismicTextSlots = typeof __propDef.slots;
23
22
  * <PrismicText field={document.data.example_rich_text} />
24
23
  * ```
25
24
  */
26
- export default class PrismicText extends SvelteComponent<PrismicTextProps, PrismicTextEvents, PrismicTextSlots> {
27
- }
28
- export {};
25
+ declare const PrismicText: import("svelte").Component<Props, {}, "">;
26
+ type PrismicText = ReturnType<typeof PrismicText>;
27
+ export default PrismicText;
@@ -1,8 +1,53 @@
1
- <script>import TodoComponent from "./TodoComponent.svelte";
2
- export let slices = [];
3
- export let components = {};
4
- export let context = {};
5
- export let defaultComponent = void 0;
1
+ <script lang="ts">
2
+ import type { Component } from "svelte";
3
+
4
+ import type { SliceComponentProps, SliceZoneLike } from "../types";
5
+
6
+ import TodoComponent from "./TodoComponent.svelte";
7
+
8
+ type Props = {
9
+ /**
10
+ * An array of Prismic Slices, such as the `slices` property from a Prismic
11
+ * document.
12
+ */
13
+ slices?: SliceZoneLike;
14
+
15
+ /**
16
+ * An object that maps Slice components to their corresponding API IDs.
17
+ *
18
+ * @example An example map:
19
+ *
20
+ * ```js
21
+ * import BlockQuote from "./BlockQuote.svelte";
22
+ * import HeroImage from "./HeroImage.svelte";
23
+ *
24
+ * const components = {
25
+ * block_quote: BlockQuote,
26
+ * hero_image: HeroImage,
27
+ * };
28
+ * ```
29
+ */
30
+ components?: Record<string, Component>;
31
+
32
+ /**
33
+ * Arbitrary data passed to all Slice components as a `context` prop.
34
+ */
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ context?: any;
37
+
38
+ /**
39
+ * The Svelte component rendered if a component mapping from the
40
+ * `components` prop cannot be found.
41
+ */
42
+ defaultComponent?: Component<SliceComponentProps> | undefined;
43
+ };
44
+
45
+ const {
46
+ slices = [],
47
+ components = {},
48
+ context = {},
49
+ defaultComponent = undefined,
50
+ }: Props = $props();
6
51
  </script>
7
52
 
8
53
  <!--
@@ -21,15 +66,15 @@ export let defaultComponent = void 0;
21
66
  ```
22
67
  -->
23
68
 
24
- {#each slices as slice, index}
69
+ {#each slices as slice, index ("id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`)}
25
70
  {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
26
71
  {@const Component = components[type] || defaultComponent}
27
72
  {#if Component}
28
73
  {#if slice.__mapped}
29
74
  {@const { __mapped, ...mappedProps } = slice}
30
- <svelte:component this={Component} {...mappedProps} />
75
+ <Component {...mappedProps} />
31
76
  {:else}
32
- <svelte:component this={Component} {slice} {slices} {context} {index} />
77
+ <Component {slice} {slices} {context} {index} />
33
78
  {/if}
34
79
  {:else}
35
80
  <TodoComponent {slice} />