@prismicio/svelte 1.0.2 → 1.1.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 CHANGED
@@ -7,8 +7,6 @@
7
7
  [![Conventional Commits][conventional-commits-src]][conventional-commits-href]
8
8
  [![License][license-src]][license-href]
9
9
 
10
- > ⚠  This project is in an experimental state. Use it at your own risk or stay tuned for the official release!
11
-
12
10
  [Svelte][svelte] components to present [Prismic][prismic] content.
13
11
 
14
12
  - 📝  Display content from Prismic like [Rich Text][prismic-rich-text] and [Link][prismic-link] fields;
@@ -3,7 +3,7 @@ import type { asTree } from "@prismicio/richtext";
3
3
  declare const __propDef: {
4
4
  props: {
5
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;
6
+ node: import("@prismicio/client/*").RTAnyNode;
7
7
  }>, any, any>>> | undefined;
8
8
  children: ReturnType<typeof asTree>["children"];
9
9
  };
@@ -25,7 +25,12 @@ export let defaultComponent = void 0;
25
25
  {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
26
26
  {@const Component = components[type] || defaultComponent}
27
27
  {#if Component}
28
- <svelte:component this={Component} {slice} {slices} {context} {index} />
28
+ {#if slice.__mapped}
29
+ {@const { __mapped, ...mappedProps } = slice}
30
+ <svelte:component this={Component} {...mappedProps} />
31
+ {:else}
32
+ <svelte:component this={Component} {slice} {slices} {context} {index} />
33
+ {/if}
29
34
  {:else}
30
35
  <TodoComponent {slice} />
31
36
  {/if}
@@ -4,10 +4,18 @@ declare const __propDef: {
4
4
  /**
5
5
  * An array of Prismic Slices, such as the `slices` property from a Prismic
6
6
  * document.
7
- */ slices?: ({
7
+ */ slices?: (({
8
8
  slice_type: string;
9
9
  } | {
10
10
  type: string;
11
+ }) & {
12
+ /**
13
+ * If `true`, this Slice has been modified from its original value using a
14
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
15
+ *
16
+ * @internal
17
+ */
18
+ __mapped?: true | undefined;
11
19
  })[] | undefined;
12
20
  /**
13
21
  * An object that maps Slice components to their corresponding API IDs.
@@ -24,15 +32,31 @@ declare const __propDef: {
24
32
  * };
25
33
  * ```
26
34
  */ components?: Record<string, new (...args: any[]) => SvelteComponent<{
27
- slice?: ({
35
+ slice?: (({
28
36
  slice_type: string;
29
37
  } | {
30
38
  type: string;
39
+ }) & {
40
+ /**
41
+ * If `true`, this Slice has been modified from its original value using a
42
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
43
+ *
44
+ * @internal
45
+ */
46
+ __mapped?: true | undefined;
31
47
  }) | undefined;
32
- slices?: ({
48
+ slices?: (({
33
49
  slice_type: string;
34
50
  } | {
35
51
  type: string;
52
+ }) & {
53
+ /**
54
+ * If `true`, this Slice has been modified from its original value using a
55
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
56
+ *
57
+ * @internal
58
+ */
59
+ __mapped?: true | undefined;
36
60
  })[] | undefined;
37
61
  context?: unknown;
38
62
  index?: number | undefined;
@@ -44,15 +68,31 @@ declare const __propDef: {
44
68
  * The Svelte component rendered if a component mapping from the `components`
45
69
  * prop cannot be found.
46
70
  */ defaultComponent?: (new (...args: any[]) => SvelteComponent<{
47
- slice?: ({
71
+ slice?: (({
48
72
  slice_type: string;
49
73
  } | {
50
74
  type: string;
75
+ }) & {
76
+ /**
77
+ * If `true`, this Slice has been modified from its original value using a
78
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
79
+ *
80
+ * @internal
81
+ */
82
+ __mapped?: true | undefined;
51
83
  }) | undefined;
52
- slices?: ({
84
+ slices?: (({
53
85
  slice_type: string;
54
86
  } | {
55
87
  type: string;
88
+ }) & {
89
+ /**
90
+ * If `true`, this Slice has been modified from its original value using a
91
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
92
+ *
93
+ * @internal
94
+ */
95
+ __mapped?: true | undefined;
56
96
  })[] | undefined;
57
97
  context?: unknown;
58
98
  index?: number | undefined;
@@ -9,8 +9,8 @@ export type EnableAutoPreviewsConfig = {
9
9
  */
10
10
  client: Pick<prismic.Client, "queryContentFromRef">;
11
11
  /**
12
- * The `cookies` object provided to a route's `load()` function. This parmeter
13
- * is required to load previews.
12
+ * The `cookies` object provided to a route's `load()` function. This
13
+ * parameter is required to load previews.
14
14
  */
15
15
  cookies?: Cookies;
16
16
  };
@@ -6,8 +6,8 @@ import { Cookies } from "@sveltejs/kit";
6
6
  */
7
7
  export type CreateClientConfig = ClientConfig & {
8
8
  /**
9
- * The `cookies` object provided to a route's `load()` function. This parmeter
10
- * is required to load previews.
9
+ * The `cookies` object provided to a route's `load()` function. This
10
+ * parameter is required to load previews.
11
11
  */
12
12
  cookies?: Cookies;
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/svelte",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Svelte components to present Prismic content.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -55,8 +55,8 @@
55
55
  "release:dry": "standard-version --dry-run",
56
56
  "size": "size-limit",
57
57
  "test": "npm run lint && npm run types && npm run unit && npm run build && npm run size",
58
- "types": "vitest typecheck --run && tsc --noEmit",
59
- "types:watch": "vitest typecheck",
58
+ "types": "vitest --typecheck.only --run && tsc --noEmit",
59
+ "types:watch": "vitest watch --typecheck.only",
60
60
  "unit": "vitest run --coverage",
61
61
  "unit:watch": "vitest watch"
62
62
  },
@@ -65,31 +65,31 @@
65
65
  "esm-env": "^1.0.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@prismicio/client": "^7.2.0",
68
+ "@prismicio/client": "^7.4.0",
69
69
  "@prismicio/mock": "^0.3.1",
70
- "@size-limit/preset-small-lib": "^9.0.0",
71
- "@sveltejs/kit": "^1.25.1",
72
- "@sveltejs/package": "^2.2.2",
73
- "@sveltejs/vite-plugin-svelte": "^2.4.6",
74
- "@testing-library/svelte": "^4.0.3",
75
- "@trivago/prettier-plugin-sort-imports": "^4.2.0",
76
- "@typescript-eslint/eslint-plugin": "^6.7.4",
77
- "@typescript-eslint/parser": "^6.7.4",
78
- "@vitest/coverage-v8": "^0.34.6",
79
- "eslint": "^8.50.0",
80
- "eslint-config-prettier": "^9.0.0",
81
- "eslint-plugin-prettier": "^5.0.0",
82
- "eslint-plugin-svelte": "^2.33.2",
70
+ "@size-limit/preset-small-lib": "^11.0.1",
71
+ "@sveltejs/kit": "^2.0.0",
72
+ "@sveltejs/package": "^2.2.3",
73
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
74
+ "@testing-library/svelte": "^4.0.5",
75
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
76
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
77
+ "@typescript-eslint/parser": "^6.14.0",
78
+ "@vitest/coverage-v8": "^1.0.4",
79
+ "eslint": "^8.55.0",
80
+ "eslint-config-prettier": "^9.1.0",
81
+ "eslint-plugin-prettier": "^5.0.1",
82
+ "eslint-plugin-svelte": "^2.35.1",
83
83
  "eslint-plugin-tsdoc": "^0.2.17",
84
- "happy-dom": "^12.7.0",
85
- "prettier": "^3.0.3",
86
- "prettier-plugin-jsdoc": "^1.0.2",
87
- "prettier-plugin-svelte": "^3.0.3",
88
- "size-limit": "^9.0.0",
84
+ "happy-dom": "^12.10.3",
85
+ "prettier": "^3.1.1",
86
+ "prettier-plugin-jsdoc": "^1.1.1",
87
+ "prettier-plugin-svelte": "^3.1.2",
88
+ "size-limit": "^11.0.1",
89
89
  "standard-version": "^9.5.0",
90
90
  "svelte": "^4.2.0",
91
- "typescript": "^5.2.2",
92
- "vitest": "^0.34.6"
91
+ "typescript": "^5.3.3",
92
+ "vitest": "^1.0.4"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "@prismicio/client": ">=7",
@@ -48,9 +48,18 @@
48
48
  *
49
49
  * @typeParam SliceType - Type name of the Slice.
50
50
  */
51
- type SliceLike<SliceType extends string = string> =
51
+ type SliceLike<SliceType extends string = string> = (
52
52
  | SliceLikeRestV2<SliceType>
53
- | SliceLikeGraphQL<SliceType>;
53
+ | SliceLikeGraphQL<SliceType>
54
+ ) & {
55
+ /**
56
+ * If `true`, this Slice has been modified from its original value using a
57
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
58
+ *
59
+ * @internal
60
+ */
61
+ __mapped?: true;
62
+ };
54
63
 
55
64
  /**
56
65
  * An array of Prismic Slices, such as the `slices` property from a Prismic
@@ -108,7 +117,12 @@
108
117
  {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
109
118
  {@const Component = components[type] || defaultComponent}
110
119
  {#if Component}
111
- <svelte:component this={Component} {slice} {slices} {context} {index} />
120
+ {#if slice.__mapped}
121
+ {@const { __mapped, ...mappedProps } = slice}
122
+ <svelte:component this={Component} {...mappedProps} />
123
+ {:else}
124
+ <svelte:component this={Component} {slice} {slices} {context} {index} />
125
+ {/if}
112
126
  {:else}
113
127
  <TodoComponent {slice} />
114
128
  {/if}
@@ -13,8 +13,8 @@ export type EnableAutoPreviewsConfig = {
13
13
  client: Pick<prismic.Client, "queryContentFromRef">;
14
14
 
15
15
  /**
16
- * The `cookies` object provided to a route's `load()` function. This parmeter
17
- * is required to load previews.
16
+ * The `cookies` object provided to a route's `load()` function. This
17
+ * parameter is required to load previews.
18
18
  */
19
19
  cookies?: Cookies;
20
20
  };
package/src/kit/types.ts CHANGED
@@ -7,8 +7,8 @@ import { Cookies } from "@sveltejs/kit";
7
7
  */
8
8
  export type CreateClientConfig = ClientConfig & {
9
9
  /**
10
- * The `cookies` object provided to a route's `load()` function. This parmeter
11
- * is required to load previews.
10
+ * The `cookies` object provided to a route's `load()` function. This
11
+ * parameter is required to load previews.
12
12
  */
13
13
  cookies?: Cookies;
14
14
  };