@prismicio/svelte 0.0.4 → 0.0.6

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 (65) hide show
  1. package/CHANGELOG.md +42 -32
  2. package/PrismicProvider.svelte +1 -2
  3. package/components/PrismicEmbed.svelte +8 -4
  4. package/components/PrismicImage.svelte +9 -16
  5. package/components/PrismicLink.svelte +20 -39
  6. package/components/PrismicPreview.svelte +9 -4
  7. package/components/PrismicText.svelte +1 -1
  8. package/components/SliceZone.svelte +8 -8
  9. package/components/TodoSliceComponent.svelte +4 -4
  10. package/components/index.js +1 -1
  11. package/index.js +1 -1
  12. package/{PrismicProvider.svelte.d.ts → lib/PrismicProvider.svelte.d.ts} +3 -3
  13. package/{components → lib/components}/PrismicEmbed.svelte.d.ts +3 -3
  14. package/{components → lib/components}/PrismicImage.svelte.d.ts +4 -4
  15. package/lib/components/PrismicLink.svelte.d.ts +26 -0
  16. package/{components → lib/components}/PrismicPreview.svelte.d.ts +3 -3
  17. package/{components → lib/components}/PrismicRichText.svelte.d.ts +3 -3
  18. package/{components → lib/components}/PrismicText.svelte.d.ts +3 -3
  19. package/{components → lib/components}/SliceZone.svelte.d.ts +4 -4
  20. package/{components → lib/components}/TodoSliceComponent.svelte.d.ts +3 -3
  21. package/lib/components/index.d.ts +2 -0
  22. package/lib/index.d.ts +1 -0
  23. package/lib/usePrismic.d.ts +2 -0
  24. package/package.json +25 -20
  25. package/src/app.html +2 -2
  26. package/src/lib/PrismicProvider.svelte +3 -3
  27. package/src/lib/components/PrismicEmbed.svelte +10 -5
  28. package/src/lib/components/PrismicImage.svelte +12 -26
  29. package/src/lib/components/PrismicLink.svelte +39 -54
  30. package/src/lib/components/PrismicPreview.svelte +24 -19
  31. package/src/lib/components/PrismicRichText.svelte +7 -7
  32. package/src/lib/components/PrismicText.svelte +6 -6
  33. package/src/lib/components/SliceZone.svelte +55 -50
  34. package/src/lib/components/TodoSliceComponent.svelte +12 -11
  35. package/src/lib/components/index.ts +1 -1
  36. package/src/lib/index.ts +1 -1
  37. package/src/lib/usePrismic.ts +1 -1
  38. package/src/routes/+page.server.ts +20 -0
  39. package/src/routes/+page.svelte +35 -0
  40. package/src/routes/slices/CodeSnippet/index.svelte +19 -0
  41. package/src/routes/slices/RichText/index.svelte +8 -0
  42. package/src/routes/slices/index.ts +2 -2
  43. package/src/types/CodeSnippetSlice.type.ts +7 -0
  44. package/src/types/ExampleDocument.type.ts +6 -0
  45. package/src/types/PageDocument.type.ts +7 -0
  46. package/src/types/PrismicConfig.type.ts +8 -0
  47. package/src/types/PrismicContext.type.ts +13 -0
  48. package/src/types/RichTextSlice.type.ts +7 -0
  49. package/src/types/Route.type.ts +14 -0
  50. package/src/types/index.ts +7 -0
  51. package/types/PrismicContext.type.d.ts +7 -0
  52. package/usePrismic.js +0 -1
  53. package/components/PrismicLink.svelte.d.ts +0 -29
  54. package/components/index.d.ts +0 -1
  55. package/index.d.ts +0 -1
  56. package/src/lib/types.ts +0 -35
  57. package/src/routes/index.svelte +0 -26
  58. package/src/routes/index.ts +0 -15
  59. package/src/routes/slices/CodeSnippet.svelte +0 -19
  60. package/src/routes/slices/RichText.svelte +0 -8
  61. package/types.d.ts +0 -27
  62. package/types.js +0 -1
  63. package/usePrismic.d.ts +0 -2
  64. /package/{configurePrismic.d.ts → lib/configurePrismic.d.ts} +0 -0
  65. /package/{injectionSymbols.d.ts → lib/injectionSymbols.d.ts} +0 -0
@@ -1,9 +1,14 @@
1
- <!-- TODO: Why are embeds 200px wide? -->
2
-
3
1
  <script lang="ts">
4
- import type * as prismicT from "@prismicio/types"
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import type * as prismicT from "@prismicio/types";
4
+
5
+ export let field: prismicT.EmbedField;
5
6
 
6
- export let field:prismicT.EmbedField
7
+ if (!prismicH.isFilled.embed(field)) {
8
+ console.warn("Invalid prop");
9
+ }
7
10
  </script>
8
11
 
9
- {@html field.html}
12
+ {#if prismicH.isFilled.embed(field)}
13
+ {@html field.html}
14
+ {/if}
@@ -1,34 +1,20 @@
1
1
  <script lang="ts">
2
- import * as prismicT from "@prismicio/types";
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import type * as prismicT from "@prismicio/types";
4
+
3
5
  export let field: prismicT.ImageField;
6
+
4
7
  let className: string;
5
8
 
6
- // creates a `class` property, even
7
- // though it is a reserved word
8
9
  export { className as class };
9
-
10
- const usePrismicImage = (
11
- field: prismicT.ImageField,
12
- ): {
13
- url: string;
14
- width?: number;
15
- height?: number;
16
- alt?: string;
17
- copyright: string | undefined;
18
- } => {
19
- field.url;
20
- return {
21
- url: field.url || "",
22
- alt: field.alt || "",
23
- width: field.dimensions?.width || undefined,
24
- height: field.dimensions?.height || undefined,
25
- copyright: field.copyright || undefined,
26
- };
27
- };
28
-
29
- const image = usePrismicImage(field);
30
10
  </script>
31
11
 
32
- {#if field.url}
33
- <img src={image.url} alt={image.alt} height={image.height} />
12
+ {#if prismicH.isFilled.image(field)}
13
+ {@const { alt, dimensions } = field}
14
+ {@const { width, height } = dimensions}
15
+ {@const { src, srcset } = prismicH.asImageWidthSrcSet(field)}
16
+
17
+ <img {src} {srcset} {alt} {width} {height} class={className} />
18
+ {:else}
19
+ <img alt={field.alt || ""} class={className} />
34
20
  {/if}
@@ -2,66 +2,51 @@
2
2
  import * as prismicH from "@prismicio/helpers";
3
3
  import type * as prismicT from "@prismicio/types";
4
4
 
5
- import { usePrismic } from "../usePrismic";
5
+ type PrismicLinkProps = {
6
+ /**
7
+ * A Prismic Link field, Content Relationship field, Link to Media field or Document.
8
+ */
9
+ field: prismicT.LinkField | prismicT.PrismicDocument;
6
10
 
7
- // const defaultBlankTargetRelAttribute = "noopener noreferrer";
11
+ /**
12
+ * The Link Resolver used to resolve links.
13
+ *
14
+ * @remarks
15
+ * If your app uses Route Resolvers when querying for your Prismic
16
+ * repository's content, a Link Resolver does not need to be provided.
17
+ * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
18
+ */
19
+ linkResolver?: prismicH.LinkResolverFunction | undefined;
20
+ };
8
21
 
9
- export let field:
10
- | prismicT.LinkField
11
- | prismicT.PrismicDocument
12
- | null
13
- | undefined,
14
- linkResolver: prismicH.LinkResolverFunction | null | undefined,
15
- download: boolean | null | undefined,
16
- hreflang: string | undefined,
17
- referrerpolicy: string | undefined,
18
- rel: string | undefined,
19
- target: string | undefined,
20
- type: string | undefined,
21
- prefetch: true | undefined,
22
- noscroll: true | undefined;
22
+ type $$Props = svelteHTML.IntrinsicElements["a"] & PrismicLinkProps;
23
23
 
24
- const setRel = () => {
25
- let rels: string[] = [];
26
- const defaultBlankTargetRelAttribute = ["noopener", "noreferrer"];
27
- if (rel) rels.push(...rel?.split(" "));
28
- if (
29
- (field && "target" in field && field?.target === "_blank") ||
30
- target === "_blank"
31
- )
32
- defaultBlankTargetRelAttribute.forEach((item) => {
33
- if (!rels.includes(item)) rels.push(item);
34
- });
35
- if (
36
- field &&
37
- "link_type" in field &&
38
- field?.link_type === "Web" &&
39
- !rels.includes("external")
40
- )
41
- rels.push("external");
42
- return rels.join(" ");
43
- };
24
+ export let field: $$Props["field"];
25
+ export let linkResolver: $$Props["linkResolver"] = undefined;
44
26
 
45
- const attrs = {
46
- download,
47
- hreflang,
48
- referrerpolicy,
49
- target: target || field?.target || undefined,
50
- rel: setRel(),
51
- type,
52
- };
27
+ export let target: $$Props["target"] = undefined;
28
+ const resolvedTarget =
29
+ target || (field && "target" in field && field.target) || undefined;
53
30
 
54
- const link: string | null = field
55
- ? prismicH.asLink(field, linkResolver || usePrismic().linkResolver)
56
- : "";
57
- const href: string = link || "";
31
+ export let rel: $$Props["rel"] = undefined;
32
+ const resolvedRel =
33
+ rel || (target === "_blank" ? "noopener noreferrer" : undefined);
34
+
35
+ const href = (field ? prismicH.asLink(field, linkResolver) : "") || "";
58
36
  </script>
59
37
 
60
- <a
61
- {href}
62
- {...attrs}
63
- sveltekit:prefetch={prefetch}
64
- sveltekit:noscroll={noscroll}
65
- >
38
+ <!--
39
+ @component
40
+ Component to render a Prismic Link, Link to Media, Content Relationship, or whole Document as an `a` tag.
41
+
42
+ @example Rendering a Link field:
43
+ ```svelte
44
+ <PrismicLink field={document.data.example_link}>
45
+ Example anchor text.
46
+ </PrismicLink>
47
+ ```
48
+ -->
49
+
50
+ <a {href} {...$$restProps} rel={resolvedRel} target={resolvedTarget}>
66
51
  <slot />
67
52
  </a>
@@ -1,24 +1,29 @@
1
1
  <script lang="ts">
2
- import * as prismic from '@prismicio/client'
3
- import { goto } from '$app/navigation'
4
- import { onMount } from "svelte"
2
+ import * as prismic from "@prismicio/client";
3
+ import { goto } from "$app/navigation";
4
+ import { onMount } from "svelte";
5
5
 
6
- export let linkResolver:any
7
- export let defaultURL:string
8
- export let client:any
6
+ export let linkResolver: any;
7
+ export let defaultURL: string;
8
+ export let client: any;
9
9
 
10
- onMount(async () => {
11
- const urlParams = new URLSearchParams(window.location.search);
12
- const previewToken = urlParams.get("token")
13
- const documentID = urlParams.get("documentId")
14
- if(documentID && previewToken) {
15
- const redirect = await client.resolvePreviewURL({documentID, defaultURL, previewToken, linkResolver})
16
- await goto(redirect)
17
- return
18
- }
19
- console.log("Could not resolve preview URL.")
20
- // TODO: Handle else
21
- })
10
+ onMount(async () => {
11
+ const urlParams = new URLSearchParams(window.location.search);
12
+ const previewToken = urlParams.get("token");
13
+ const documentID = urlParams.get("documentId");
14
+ if (documentID && previewToken) {
15
+ const redirect = await client.resolvePreviewURL({
16
+ documentID,
17
+ defaultURL,
18
+ previewToken,
19
+ linkResolver,
20
+ });
21
+ await goto(redirect);
22
+ return;
23
+ }
24
+ console.log("Could not resolve preview URL.");
25
+ // TODO: Handle else
26
+ });
22
27
  </script>
23
28
 
24
- <slot></slot>
29
+ <slot />
@@ -1,14 +1,14 @@
1
1
  <script lang="ts">
2
- import * as prismicH from "@prismicio/helpers"
3
- import { usePrismic } from "./..";
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import { usePrismic } from "./..";
4
4
 
5
- import type { RichTextField as RichTextFieldType } from "@prismicio/types";
6
- import type { TitleField as TitleFieldType } from "@prismicio/types";
5
+ import type { RichTextField as RichTextFieldType } from "@prismicio/types";
6
+ import type { TitleField as TitleFieldType } from "@prismicio/types";
7
7
 
8
- let { htmlSerializer, linkResolver } = usePrismic()
8
+ let { htmlSerializer, linkResolver } = usePrismic();
9
9
 
10
- export let field:TitleFieldType | RichTextFieldType
11
- export { htmlSerializer, linkResolver }
10
+ export let field: TitleFieldType | RichTextFieldType;
11
+ export { htmlSerializer, linkResolver };
12
12
  </script>
13
13
 
14
14
  {@html prismicH.asHTML(field, linkResolver, htmlSerializer)}
@@ -1,12 +1,12 @@
1
1
  <script lang="ts">
2
- import * as prismicH from "@prismicio/helpers"
2
+ import * as prismicH from "@prismicio/helpers";
3
3
 
4
- import type { RichTextField as RichTextFieldType } from "@prismicio/types";
5
- import type { TitleField as TitleFieldType } from "@prismicio/types";
4
+ import type { RichTextField as RichTextFieldType } from "@prismicio/types";
5
+ import type { TitleField as TitleFieldType } from "@prismicio/types";
6
6
 
7
- export let field:TitleFieldType | RichTextFieldType
8
- export let separator:string
7
+ export let field: TitleFieldType | RichTextFieldType;
8
+ export let separator: string;
9
9
  </script>
10
10
 
11
11
  <!-- TODO: Separator not working for newlines `\n\n` -->
12
- {@html prismicH.asText(field, separator)}
12
+ {@html prismicH.asText(field, separator)}
@@ -1,61 +1,66 @@
1
1
  <script lang="ts">
2
- import TodoSliceComponent from './TodoSliceComponent.svelte';
3
-
4
- import type * as prismicT from "@prismicio/types"
5
- import type { SvelteComponent } from 'svelte';
2
+ import TodoSliceComponent from "./TodoSliceComponent.svelte";
6
3
 
7
- type SliceComponents = Record<string, SvelteComponent | (new (...args: any[]) => SvelteComponent)>
4
+ import type * as prismicT from "@prismicio/types";
5
+ import type { SvelteComponent } from "svelte";
8
6
 
9
- /**
10
- * The minimum required properties to represent a Prismic Slice from the Prismic
11
- * Rest API V2 for the `<SliceZone>` component.
12
- *
13
- * If using Prismic's Rest API V2, use the `Slice` export from
14
- * `@prismicio/types` for a full interface.
15
- *
16
- * @typeParam SliceType - Type name of the Slice.
17
- */
18
- type SliceLikeRestV2<SliceType extends string = string> = {
19
- slice_type: prismicT.Slice<SliceType>["slice_type"];
20
- };
7
+ type SliceComponents = Record<
8
+ string,
9
+ SvelteComponent | (new (...args: any[]) => SvelteComponent)
10
+ >;
21
11
 
22
- /**
23
- * The minimum required properties to represent a Prismic Slice from the Prismic
24
- * GraphQL API for the `<SliceZone>` component.
25
- *
26
- * @typeParam SliceType - Type name of the Slice.
27
- */
28
- type SliceLikeGraphQL<SliceType extends string = string> = {
29
- type: prismicT.Slice<SliceType>["slice_type"];
30
- };
12
+ /**
13
+ * The minimum required properties to represent a Prismic Slice from the
14
+ * Prismic Rest API V2 for the `<SliceZone>` component.
15
+ *
16
+ * If using Prismic's Rest API V2, use the `Slice` export from
17
+ * `@prismicio/types` for a full interface.
18
+ *
19
+ * @typeParam SliceType - Type name of the Slice.
20
+ */
21
+ type SliceLikeRestV2<SliceType extends string = string> = {
22
+ slice_type: prismicT.Slice<SliceType>["slice_type"];
23
+ };
31
24
 
32
- /**
33
- * The minimum required properties to represent a Prismic Slice for the
34
- * `<SliceZone>` component.
35
- *
36
- * If using Prismic's Rest API V2, use the `Slice` export from
37
- * `@prismicio/types` for a full interface.
38
- *
39
- * @typeParam SliceType - Type name of the Slice.
40
- */
41
- type SliceLike<SliceType extends string = string> =
42
- | SliceLikeRestV2<SliceType>
43
- | SliceLikeGraphQL<SliceType>;
25
+ /**
26
+ * The minimum required properties to represent a Prismic Slice from the
27
+ * Prismic GraphQL API for the `<SliceZone>` component.
28
+ *
29
+ * @typeParam SliceType - Type name of the Slice.
30
+ */
31
+ type SliceLikeGraphQL<SliceType extends string = string> = {
32
+ type: prismicT.Slice<SliceType>["slice_type"];
33
+ };
44
34
 
35
+ /**
36
+ * The minimum required properties to represent a Prismic Slice for the
37
+ * `<SliceZone>` component.
38
+ *
39
+ * If using Prismic's Rest API V2, use the `Slice` export from
40
+ * `@prismicio/types` for a full interface.
41
+ *
42
+ * @typeParam SliceType - Type name of the Slice.
43
+ */
44
+ type SliceLike<SliceType extends string = string> =
45
+ | SliceLikeRestV2<SliceType>
46
+ | SliceLikeGraphQL<SliceType>;
45
47
 
46
- export let slices:SliceLike[] = []
47
- export let components:SliceComponents = {}
48
- export let context:any = {}
49
- export let defaultComponent:SvelteComponent | (new (...args: any[]) => SvelteComponent) | undefined = undefined
50
- export let dev:boolean = false
48
+ export let slices: SliceLike[] = [];
49
+ export let components: SliceComponents = {};
50
+ export let context: any = {};
51
+ export let defaultComponent:
52
+ | SvelteComponent
53
+ | (new (...args: any[]) => SvelteComponent)
54
+ | undefined = undefined;
55
+ export let dev: boolean = false;
51
56
  </script>
52
57
 
53
58
  {#each slices as slice, index}
54
- {@const type = "slice_type" in slice ? slice.slice_type : slice.type }
55
- {@const Component = components[type] || defaultComponent}
56
- {#if Component}
57
- <svelte:component this={Component} {slice} {slices} {context} {index} />
58
- {:else}
59
- <TodoSliceComponent {slice} {dev} />
60
- {/if}
59
+ {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
60
+ {@const Component = components[type] || defaultComponent}
61
+ {#if Component}
62
+ <svelte:component this={Component} {slice} {slices} {context} {index} />
63
+ {:else}
64
+ <TodoSliceComponent {slice} {dev} />
65
+ {/if}
61
66
  {/each}
@@ -1,17 +1,18 @@
1
1
  <script lang="ts">
2
- export let slice:{slice_type: string} | {type: string}
3
- export let dev:boolean = false
2
+ export let slice: { slice_type: string } | { type: string };
3
+ export let dev: boolean = false;
4
4
 
5
- const type = "slice_type" in slice ? slice.slice_type : slice.type
5
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
6
6
 
7
- if(dev) console.warn(
8
- `[SliceZone] Could not find a component for Slice type "${type}"`,
9
- slice,
10
- )
7
+ if (dev)
8
+ console.warn(
9
+ `[SliceZone] Could not find a component for Slice type "${type}"`,
10
+ slice,
11
+ );
11
12
  </script>
12
13
 
13
14
  {#if dev}
14
- <section data-slice-zone-todo-component="" data-slice-type={type}>
15
- Could not find a component for Slice type &ldquo;{type}&rdquo;
16
- </section>
17
- {/if}
15
+ <section data-slice-zone-todo-component="" data-slice-type={type}>
16
+ Could not find a component for Slice type &ldquo;{type}&rdquo;
17
+ </section>
18
+ {/if}
@@ -2,7 +2,7 @@
2
2
 
3
3
  // export { default as PrismicImage } from "./PrismicImage.svelte";
4
4
 
5
- // export { default as PrismicLink } from "./PrismicLink.svelte";
5
+ export { default as PrismicLink } from "./PrismicLink.svelte";
6
6
 
7
7
  // export { default as PrismicText } from "./PrismicText.svelte";
8
8
 
package/src/lib/index.ts CHANGED
@@ -4,7 +4,7 @@ export {
4
4
  // Components
5
5
  // PrismicEmbed,
6
6
  // PrismicImage,
7
- // PrismicLink,
7
+ PrismicLink,
8
8
  // PrismicText,
9
9
  // PrismicRichText,
10
10
  // Slice Zone
@@ -1,7 +1,7 @@
1
1
  import { hasContext, getContext } from "svelte";
2
2
 
3
3
  import { prismicKey } from "./injectionSymbols";
4
- import { PrismicContext } from "./types";
4
+ import type { PrismicContext } from "../types/PrismicContext.type";
5
5
 
6
6
  export const usePrismic = (): PrismicContext => {
7
7
  if (hasContext(prismicKey)) {
@@ -0,0 +1,20 @@
1
+ import * as prismic from "@prismicio/client";
2
+ import type { PageDocument } from "../types/PageDocument.type"
3
+ import type { PageServerLoad } from "./$types";
4
+
5
+ export const load = (async ({ fetch }) => {
6
+ const endpoint = prismic.getRepositoryEndpoint("svelte-package-dev");
7
+ const client = prismic.createClient(endpoint, { fetch });
8
+
9
+ const pageDocument: PageDocument = await client.getSingle("homepage");
10
+
11
+ const exampleClient = prismic.createClient("example-prismic-repo", { fetch })
12
+ const exampleDocument = exampleClient.getFirst()
13
+
14
+
15
+ return {
16
+ pageDocument,
17
+ exampleDocument
18
+ };
19
+ // eslint-disable-next-line prettier/prettier
20
+ }) satisfies PageServerLoad;
@@ -0,0 +1,35 @@
1
+ <script lang="ts">
2
+ import { SliceZone, PrismicLink } from "$lib";
3
+ import { RichText, CodeSnippet } from "./slices";
4
+ import type { PageData } from "./$types";
5
+
6
+ const components = {
7
+ rich_text: RichText,
8
+ code_snippet: CodeSnippet,
9
+ };
10
+
11
+ export let data: PageData;
12
+ </script>
13
+
14
+ <main>
15
+ <h1>Welcome to SvelteKit</h1>
16
+ <h2>Prismic Link</h2>
17
+ <PrismicLink
18
+ data-sveltekit-noscroll
19
+ data-sveltekit-preload-code
20
+ data-sveltekit-preload-data
21
+ data-sveltekit-reload
22
+ rel="external"
23
+ class="doggo"
24
+ field={data.exampleDocument.data.example_link}>Link</PrismicLink
25
+ >
26
+ <h2>Slice Zone</h2>
27
+ <SliceZone slices={data.pageDocument.data.body} {components} />
28
+ </main>
29
+
30
+ <style>
31
+ main {
32
+ max-width: min(90%, 800px);
33
+ margin: auto;
34
+ }
35
+ </style>
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import type { CodeSnippetSlice } from "../../../types/CodeSnippetSlice.type";
4
+
5
+ export let slice: CodeSnippetSlice;
6
+ </script>
7
+
8
+ <pre>
9
+ {@html prismicH.asHTML(slice.primary.content)}
10
+ </pre>
11
+
12
+ <style>
13
+ pre {
14
+ background: #222;
15
+ color: white;
16
+ padding: 10px;
17
+ border-radius: 10px;
18
+ }
19
+ </style>
@@ -0,0 +1,8 @@
1
+ <script lang="ts">
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import type { RichTextSlice } from "./../../../types/RichTextSlice.type";
4
+
5
+ export let slice: RichTextSlice;
6
+ </script>
7
+
8
+ {@html prismicH.asHTML(slice.primary.content)}
@@ -1,2 +1,2 @@
1
- export { default as CodeSnippet } from "./CodeSnippet.svelte";
2
- export { default as RichText } from "./RichText.svelte";
1
+ export { default as CodeSnippet } from "./CodeSnippet/index.svelte";
2
+ export { default as RichText } from "./RichText/index.svelte";
@@ -0,0 +1,7 @@
1
+ import type * as prismicT from "@prismicio/types";
2
+
3
+ type PrimaryFields = {
4
+ content: prismicT.RichTextField;
5
+ };
6
+
7
+ export type CodeSnippetSlice = prismicT.Slice<"code_snippet", PrimaryFields>;
@@ -0,0 +1,6 @@
1
+ import type * as prismicT from "@prismicio/types";
2
+
3
+ export type ExampleDocument = prismicT.PrismicDocument<{
4
+ example_link: prismicT.LinkField;
5
+ example_content_relationship: prismicT.ContentRelationshipField;
6
+ }>;
@@ -0,0 +1,7 @@
1
+ import type * as prismicT from "@prismicio/types";
2
+ import type { CodeSnippetSlice } from "./CodeSnippetSlice.type";
3
+ import type { RichTextSlice } from "./RichTextSlice.type";
4
+
5
+ export type PageDocument = prismicT.PrismicDocument<{
6
+ body: prismicT.SliceZone<CodeSnippetSlice | RichTextSlice>;
7
+ }>;
@@ -0,0 +1,8 @@
1
+ import type { Route } from "./Route.type";
2
+
3
+ export interface PrismicConfig {
4
+ repoName: string;
5
+ routes?: Route[];
6
+ accessToken?: string;
7
+ options?: null;
8
+ }
@@ -0,0 +1,13 @@
1
+ import type { Client } from "@prismicio/client";
2
+ import type {
3
+ LinkResolverFunction,
4
+ HTMLFunctionSerializer,
5
+ HTMLMapSerializer,
6
+ } from "@prismicio/helpers";
7
+ // import type * as prismicH from "@prismicio/helpers";
8
+
9
+ export type PrismicContext = {
10
+ client?: Client;
11
+ linkResolver?: LinkResolverFunction;
12
+ htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;
13
+ };
@@ -0,0 +1,7 @@
1
+ import type * as prismicT from "@prismicio/types";
2
+
3
+ type PrimaryFields = {
4
+ content: prismicT.RichTextField;
5
+ };
6
+
7
+ export type RichTextSlice = prismicT.Slice<"rich_text", PrimaryFields>;
@@ -0,0 +1,14 @@
1
+ export interface Route {
2
+ /**
3
+ * The Custom Type of the document.
4
+ */
5
+ type: string;
6
+ /**
7
+ * The resolved path of the document with optional placeholders.
8
+ */
9
+ path: string;
10
+ /**
11
+ * An object that lists the API IDs of the Content Relationships in the route.
12
+ */
13
+ resolvers: Record<string, string>;
14
+ }
@@ -0,0 +1,7 @@
1
+ export type { CodeSnippetSlice } from "./CodeSnippetSlice.type";
2
+ export type { PageDocument } from "./PageDocument.type";
3
+ export type { ExampleDocument } from "./ExampleDocument.type";
4
+ export type { PrismicConfig } from "./PrismicConfig.type";
5
+ export type { PrismicContext } from "./PrismicContext.type";
6
+ export type { RichTextSlice } from "./RichTextSlice.type";
7
+ export type { Route } from "./Route.type";
@@ -0,0 +1,7 @@
1
+ import type { Client } from "@prismicio/client";
2
+ import type { LinkResolverFunction, HTMLFunctionSerializer, HTMLMapSerializer } from "@prismicio/helpers";
3
+ export type PrismicContext = {
4
+ client?: Client;
5
+ linkResolver?: LinkResolverFunction;
6
+ htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;
7
+ };
package/usePrismic.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { hasContext, getContext } from "svelte";
2
2
  import { prismicKey } from "./injectionSymbols";
3
- import "./types";
4
3
  export const usePrismic = () => {
5
4
  if (hasContext(prismicKey)) {
6
5
  return getContext(prismicKey);