@prismicio/svelte 0.1.0 → 0.1.2
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/PrismicRichText/DefaultComponent.svelte +2 -4
- package/dist/PrismicRichText/Serialize.svelte +10 -10
- package/dist/SliceZone/SliceZone.svelte.d.ts +12 -12
- package/package.json +1 -1
- package/src/PrismicRichText/DefaultComponent.svelte +2 -4
- package/src/PrismicRichText/Serialize.svelte +17 -17
- package/src/SliceZone/SliceZone.svelte +4 -4
|
@@ -44,9 +44,7 @@ export let node;
|
|
|
44
44
|
<span class={node.data.label}><slot /></span>
|
|
45
45
|
{:else}
|
|
46
46
|
{#each node.text.split("\n") as line, index}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
{/if}
|
|
50
|
-
{line}
|
|
47
|
+
<!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
|
|
48
|
+
{#if index > 0}<br />{/if}{line}
|
|
51
49
|
{/each}
|
|
52
50
|
{/if}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
<script>import DefaultComponent from "./DefaultComponent.svelte";
|
|
2
2
|
export let components = {};
|
|
3
3
|
export let children;
|
|
4
|
-
const
|
|
4
|
+
const CHILD_TYPE_RENAMES = {
|
|
5
5
|
"list-item": "listItem",
|
|
6
6
|
"o-list-item": "oListItem",
|
|
7
7
|
"group-list-item": "list",
|
|
8
8
|
"group-o-list-item": "oList"
|
|
9
9
|
};
|
|
10
|
+
function getComponent(child) {
|
|
11
|
+
return components[CHILD_TYPE_RENAMES[child.type] || child.type] || DefaultComponent;
|
|
12
|
+
}
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
15
|
{#each children as child}
|
|
13
|
-
<svelte:component
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
<svelte:component this={getComponent(child)} node={child.node}>
|
|
17
|
+
<!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
|
|
18
|
+
{#if child.children.length > 0}<svelte:self
|
|
19
|
+
children={child.children}
|
|
20
|
+
{components}
|
|
21
|
+
/>{/if}</svelte:component
|
|
18
22
|
>
|
|
19
|
-
{#if child.children.length > 0}
|
|
20
|
-
<svelte:self children={child.children} {components} />
|
|
21
|
-
{/if}
|
|
22
|
-
</svelte:component>
|
|
23
23
|
{/each}
|
|
@@ -24,18 +24,18 @@ declare const __propDef: {
|
|
|
24
24
|
* };
|
|
25
25
|
* ```
|
|
26
26
|
*/ components?: Record<string, new (...args: any[]) => SvelteComponent<{
|
|
27
|
-
slice
|
|
27
|
+
slice?: ({
|
|
28
28
|
slice_type: string;
|
|
29
29
|
} | {
|
|
30
30
|
type: string;
|
|
31
|
-
};
|
|
32
|
-
slices
|
|
31
|
+
}) | undefined;
|
|
32
|
+
slices?: ({
|
|
33
33
|
slice_type: string;
|
|
34
34
|
} | {
|
|
35
35
|
type: string;
|
|
36
|
-
})[];
|
|
37
|
-
context
|
|
38
|
-
index
|
|
36
|
+
})[] | undefined;
|
|
37
|
+
context?: unknown;
|
|
38
|
+
index?: number | undefined;
|
|
39
39
|
}, any, any>> | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* Arbitrary data passed to all Slice components as a `context` prop.
|
|
@@ -44,18 +44,18 @@ declare const __propDef: {
|
|
|
44
44
|
* The Svelte component rendered if a component mapping from the `components`
|
|
45
45
|
* prop cannot be found.
|
|
46
46
|
*/ defaultComponent?: (new (...args: any[]) => SvelteComponent<{
|
|
47
|
-
slice
|
|
47
|
+
slice?: ({
|
|
48
48
|
slice_type: string;
|
|
49
49
|
} | {
|
|
50
50
|
type: string;
|
|
51
|
-
};
|
|
52
|
-
slices
|
|
51
|
+
}) | undefined;
|
|
52
|
+
slices?: ({
|
|
53
53
|
slice_type: string;
|
|
54
54
|
} | {
|
|
55
55
|
type: string;
|
|
56
|
-
})[];
|
|
57
|
-
context
|
|
58
|
-
index
|
|
56
|
+
})[] | undefined;
|
|
57
|
+
context?: unknown;
|
|
58
|
+
index?: number | undefined;
|
|
59
59
|
}, any, any>) | undefined;
|
|
60
60
|
};
|
|
61
61
|
events: {
|
package/package.json
CHANGED
|
@@ -48,9 +48,7 @@
|
|
|
48
48
|
<span class={node.data.label}><slot /></span>
|
|
49
49
|
{:else}
|
|
50
50
|
{#each node.text.split("\n") as line, index}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{/if}
|
|
54
|
-
{line}
|
|
51
|
+
<!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
|
|
52
|
+
{#if index > 0}<br />{/if}{line}
|
|
55
53
|
{/each}
|
|
56
54
|
{/if}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { RichTextNodeType } from "@prismicio/client";
|
|
3
2
|
import type { asTree } from "@prismicio/richtext";
|
|
4
3
|
|
|
5
4
|
import type { SvelteRichTextSerializer } from "../types";
|
|
@@ -9,28 +8,29 @@
|
|
|
9
8
|
export let components: SvelteRichTextSerializer = {};
|
|
10
9
|
export let children: ReturnType<typeof asTree>["children"];
|
|
11
10
|
|
|
12
|
-
const
|
|
13
|
-
Record<
|
|
14
|
-
(typeof RichTextNodeType)[keyof typeof RichTextNodeType],
|
|
15
|
-
keyof typeof RichTextNodeType
|
|
16
|
-
>
|
|
17
|
-
> = {
|
|
11
|
+
const CHILD_TYPE_RENAMES = {
|
|
18
12
|
"list-item": "listItem",
|
|
19
13
|
"o-list-item": "oListItem",
|
|
20
14
|
"group-list-item": "list",
|
|
21
15
|
"group-o-list-item": "oList",
|
|
22
|
-
};
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
|
|
19
|
+
return (
|
|
20
|
+
components[
|
|
21
|
+
CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
|
|
22
|
+
(child.type as keyof typeof components)
|
|
23
|
+
] || DefaultComponent
|
|
24
|
+
);
|
|
25
|
+
}
|
|
23
26
|
</script>
|
|
24
27
|
|
|
25
28
|
{#each children as child}
|
|
26
|
-
<svelte:component
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
<svelte:component this={getComponent(child)} node={child.node}>
|
|
30
|
+
<!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
|
|
31
|
+
{#if child.children.length > 0}<svelte:self
|
|
32
|
+
children={child.children}
|
|
33
|
+
{components}
|
|
34
|
+
/>{/if}</svelte:component
|
|
31
35
|
>
|
|
32
|
-
{#if child.children.length > 0}
|
|
33
|
-
<svelte:self children={child.children} {components} />
|
|
34
|
-
{/if}
|
|
35
|
-
</svelte:component>
|
|
36
36
|
{/each}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
9
|
...args: any[]
|
|
10
10
|
) => SvelteComponent<{
|
|
11
|
-
slice
|
|
12
|
-
slices
|
|
13
|
-
context
|
|
14
|
-
index
|
|
11
|
+
slice?: SliceLike;
|
|
12
|
+
slices?: SliceLike[];
|
|
13
|
+
context?: unknown;
|
|
14
|
+
index?: number;
|
|
15
15
|
}>;
|
|
16
16
|
|
|
17
17
|
type SliceComponents = Record<string, SvelteSliceComponent>;
|