@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.
- package/README.md +1 -1
- package/dist/PrismicEmbed.svelte +12 -2
- package/dist/PrismicEmbed.svelte.d.ts +8 -17
- package/dist/PrismicImage.svelte +140 -59
- package/dist/PrismicImage.svelte.d.ts +54 -64
- package/dist/PrismicLink.svelte +55 -20
- package/dist/PrismicLink.svelte.d.ts +30 -38
- package/dist/PrismicRichText/DefaultComponent.svelte +35 -23
- package/dist/PrismicRichText/DefaultComponent.svelte.d.ts +7 -17
- package/dist/PrismicRichText/PrismicRichText.svelte +23 -6
- package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +13 -22
- package/dist/PrismicRichText/Serialize.svelte +35 -16
- package/dist/PrismicRichText/Serialize.svelte.d.ts +9 -19
- package/dist/PrismicTable/DefaultComponent.svelte +12 -2
- package/dist/PrismicTable/DefaultComponent.svelte.d.ts +7 -17
- package/dist/PrismicTable/PrismicTable.svelte +46 -30
- package/dist/PrismicTable/PrismicTable.svelte.d.ts +19 -31
- package/dist/PrismicText.svelte +49 -23
- package/dist/PrismicText.svelte.d.ts +17 -18
- package/dist/SliceZone/SliceZone.svelte +53 -8
- package/dist/SliceZone/SliceZone.svelte.d.ts +36 -110
- package/dist/SliceZone/TodoComponent.svelte +19 -9
- package/dist/SliceZone/TodoComponent.svelte.d.ts +8 -18
- package/dist/index.d.ts +1 -1
- package/dist/kit/PrismicPreview.svelte +107 -59
- package/dist/kit/PrismicPreview.svelte.d.ts +21 -28
- package/dist/lib/devMsg.js +1 -1
- package/dist/types.d.ts +95 -20
- package/package.json +35 -33
- 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 +13 -7
- 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 -89
- 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 +105 -18
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import type { RTAnyNode } from "@prismicio/client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
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
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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}<
|
|
37
|
+
{#if child.children.length > 0}<Serialize
|
|
19
38
|
children={child.children}
|
|
20
39
|
{components}
|
|
21
|
-
/>{/if}</
|
|
40
|
+
/>{/if}</Component
|
|
22
41
|
>
|
|
23
42
|
{/each}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
export
|
|
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>
|
|
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}
|
|
14
|
+
<svelte:element this={type}>{@render children?.()}</svelte:element>
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
2
|
import type { TableComponents } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
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
|
|
2
|
-
import {} from "
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
41
|
+
<Table type="table" table={field}>
|
|
26
42
|
{#if field?.head}
|
|
27
|
-
<Thead
|
|
43
|
+
<Thead type="thead" head={field.head}>
|
|
28
44
|
{#each field.head.rows as row (row.key)}
|
|
29
|
-
<Tr
|
|
45
|
+
<Tr type="tr" {row}>
|
|
30
46
|
{#each row.cells as cell (cell.key)}
|
|
31
|
-
<Th
|
|
47
|
+
<Th type="th" {cell}>
|
|
32
48
|
<PrismicRichText field={cell.content} {components} /></Th
|
|
33
49
|
>{/each}</Tr
|
|
34
50
|
>{/each}</Thead
|
|
35
|
-
>{/if}<Tbody
|
|
51
|
+
>{/if}<Tbody type="tbody" body={field.body}>
|
|
36
52
|
{#each field.body.rows as row (row.key)}
|
|
37
|
-
<Tr
|
|
53
|
+
<Tr type="tr" {row}>
|
|
38
54
|
{#each row.cells as cell (cell.key)}
|
|
39
55
|
{#if cell.type === "header"}
|
|
40
|
-
<Th
|
|
56
|
+
<Th type="th" {cell}>
|
|
41
57
|
<PrismicRichText field={cell.content} {components} /></Th
|
|
42
|
-
>{:else}<Td
|
|
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
|
|
50
|
-
<
|
|
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
|
|
4
|
-
import type { TableComponents } from "../types";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
export
|
|
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;
|
package/dist/PrismicText.svelte
CHANGED
|
@@ -1,26 +1,52 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
<
|
|
75
|
+
<Component {...mappedProps} />
|
|
31
76
|
{:else}
|
|
32
|
-
<
|
|
77
|
+
<Component {slice} {slices} {context} {index} />
|
|
33
78
|
{/if}
|
|
34
79
|
{:else}
|
|
35
80
|
<TodoComponent {slice} />
|