@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.
@@ -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
- {#if index > 0}
48
- <br />
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 rewrittenNodeTypes = {
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
- this={components[rewrittenNodeTypes[child.type] || child.type] ||
15
- DefaultComponent}
16
- node={child.node}
17
- key={child.key}
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: unknown;
38
- index: number;
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: unknown;
58
- index: number;
56
+ })[] | undefined;
57
+ context?: unknown;
58
+ index?: number | undefined;
59
59
  }, any, any>) | undefined;
60
60
  };
61
61
  events: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/svelte",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Svelte components to present Prismic content.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -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
- {#if index > 0}
52
- <br />
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 rewrittenNodeTypes: Partial<
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
- this={components[rewrittenNodeTypes[child.type] || child.type] ||
28
- DefaultComponent}
29
- node={child.node}
30
- key={child.key}
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: SliceLike;
12
- slices: SliceLike[];
13
- context: unknown;
14
- index: number;
11
+ slice?: SliceLike;
12
+ slices?: SliceLike[];
13
+ context?: unknown;
14
+ index?: number;
15
15
  }>;
16
16
 
17
17
  type SliceComponents = Record<string, SvelteSliceComponent>;