@prismicio/svelte 2.2.2 → 2.2.3-canary.bc6ed14

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 (50) hide show
  1. package/dist/PrismicEmbed.svelte +6 -8
  2. package/dist/PrismicEmbed.svelte.d.ts +1 -3
  3. package/dist/PrismicImage.svelte +46 -68
  4. package/dist/PrismicImage.svelte.d.ts +11 -17
  5. package/dist/PrismicLink.svelte +23 -34
  6. package/dist/PrismicLink.svelte.d.ts +5 -10
  7. package/dist/PrismicRichText/DefaultComponent.svelte +9 -13
  8. package/dist/PrismicRichText/PrismicRichText.svelte +11 -16
  9. package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +2 -6
  10. package/dist/PrismicRichText/Serialize.svelte +11 -19
  11. package/dist/PrismicTable.svelte +26 -41
  12. package/dist/PrismicTable.svelte.d.ts +4 -8
  13. package/dist/PrismicText.svelte +16 -20
  14. package/dist/PrismicText.svelte.d.ts +4 -8
  15. package/dist/SliceSimulator.svelte +28 -17
  16. package/dist/SliceSimulator.svelte.d.ts +7 -6
  17. package/dist/SliceZone/SliceZone.svelte +21 -26
  18. package/dist/SliceZone/SliceZone.svelte.d.ts +12 -16
  19. package/dist/SliceZone/TodoComponent.svelte +7 -7
  20. package/dist/index.d.ts +1 -3
  21. package/dist/kit/PrismicPreview.svelte +32 -48
  22. package/dist/kit/PrismicPreview.svelte.d.ts +5 -9
  23. package/dist/kit/enableAutoPreviews.d.ts +5 -10
  24. package/dist/kit/enableAutoPreviews.js +1 -2
  25. package/dist/kit/redirectToPreviewURL.d.ts +13 -21
  26. package/dist/kit/redirectToPreviewURL.js +10 -11
  27. package/dist/kit/types.d.ts +3 -6
  28. package/dist/lib/devMsg.d.ts +6 -8
  29. package/dist/lib/devMsg.js +6 -8
  30. package/dist/types.d.ts +23 -39
  31. package/package.json +41 -44
  32. package/src/PrismicEmbed.svelte +6 -8
  33. package/src/PrismicImage.svelte +46 -68
  34. package/src/PrismicLink.svelte +23 -34
  35. package/src/PrismicRichText/DefaultComponent.svelte +9 -13
  36. package/src/PrismicRichText/PrismicRichText.svelte +11 -16
  37. package/src/PrismicRichText/Serialize.svelte +11 -19
  38. package/src/PrismicTable.svelte +26 -41
  39. package/src/PrismicText.svelte +16 -20
  40. package/src/SliceSimulator.svelte +28 -17
  41. package/src/SliceZone/SliceZone.svelte +21 -26
  42. package/src/SliceZone/TodoComponent.svelte +7 -7
  43. package/src/index.ts +13 -15
  44. package/src/kit/PrismicPreview.svelte +32 -48
  45. package/src/kit/enableAutoPreviews.ts +14 -19
  46. package/src/kit/index.ts +6 -6
  47. package/src/kit/redirectToPreviewURL.ts +28 -38
  48. package/src/kit/types.ts +7 -10
  49. package/src/lib/devMsg.ts +9 -11
  50. package/src/types.ts +84 -106
@@ -1,34 +1,29 @@
1
1
  <script lang="ts">
2
- import type { asTree } from "@prismicio/client/richtext";
2
+ import type { asTree } from "@prismicio/client/richtext"
3
3
 
4
- import type {
5
- ComponentShorthand,
6
- RichTextComponent,
7
- RichTextComponents,
8
- } from "../types";
9
-
10
- import DefaultComponent from "./DefaultComponent.svelte";
11
- import Serialize from "./Serialize.svelte";
4
+ import type { ComponentShorthand, RichTextComponent, RichTextComponents } from "../types"
5
+ import DefaultComponent from "./DefaultComponent.svelte"
6
+ import Serialize from "./Serialize.svelte"
12
7
 
13
8
  type Props = {
14
- components: RichTextComponents;
15
- children: ReturnType<typeof asTree>["children"];
16
- };
9
+ components: RichTextComponents
10
+ children: ReturnType<typeof asTree>["children"]
11
+ }
17
12
 
18
- const { components, children }: Props = $props();
13
+ const { components, children }: Props = $props()
19
14
 
20
15
  const CHILD_TYPE_RENAMES = {
21
16
  "list-item": "listItem",
22
17
  "o-list-item": "oListItem",
23
18
  "group-list-item": "list",
24
19
  "group-o-list-item": "oList",
25
- } as const;
20
+ } as const
26
21
 
27
22
  function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
28
23
  return components[
29
24
  CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
30
25
  (child.type as keyof typeof components)
31
- ] as RichTextComponent | ComponentShorthand;
26
+ ] as RichTextComponent | ComponentShorthand
32
27
  }
33
28
  </script>
34
29
 
@@ -36,10 +31,7 @@
36
31
  {@const Component = getComponent(child)}
37
32
  {#snippet serializedChildren()}
38
33
  <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
39
- {#if child.children.length > 0}<Serialize
40
- children={child.children}
41
- {components}
42
- />{/if}
34
+ {#if child.children.length > 0}<Serialize children={child.children} {components} />{/if}
43
35
  {/snippet}
44
36
  {#if typeof Component === "function"}
45
37
  <Component node={child.node}>{@render serializedChildren()}</Component>
@@ -7,40 +7,35 @@
7
7
  TableFieldHead,
8
8
  TableFieldHeadRow,
9
9
  TableFieldHeaderCell,
10
- } from "@prismicio/client";
11
- import { isFilled } from "@prismicio/client";
12
- import type { Component } from "svelte";
10
+ } from "@prismicio/client"
11
+ import { isFilled } from "@prismicio/client"
12
+ import type { Component } from "svelte"
13
13
 
14
- import type { RichTextComponents, TableComponents } from "./types";
15
-
16
- import PrismicRichText from "./PrismicRichText/PrismicRichText.svelte";
14
+ import PrismicRichText from "./PrismicRichText/PrismicRichText.svelte"
15
+ import type { RichTextComponents, TableComponents } from "./types"
17
16
 
18
17
  type Props = {
19
- /**
20
- * The Prismic table field to render.
21
- */
22
- field: TableField;
18
+ /** The Prismic table field to render. */
19
+ field: TableField
23
20
 
24
- /**
25
- * An object that maps a rich text block type to a Svelte component.
26
- */
27
- components?: TableComponents & RichTextComponents;
21
+ /** An object that maps a rich text block type to a Svelte component. */
22
+ components?: TableComponents & RichTextComponents
28
23
 
29
24
  /**
30
- * The component rendered when the field is empty. If a fallback is not
31
- * given, `null` will be rendered.
25
+ * The component rendered when the field is empty. If a fallback is not given, `null` will be
26
+ * rendered.
32
27
  */
33
- fallback?: Component;
34
- };
28
+ fallback?: Component
29
+ }
35
30
 
36
- const { field, components = {}, fallback: Fallback }: Props = $props();
31
+ const { field, components = {}, fallback: Fallback }: Props = $props()
37
32
 
38
- const Table = components.table;
39
- const Thead = components.thead;
40
- const Tbody = components.tbody;
41
- const Tr = components.tr;
42
- const Th = components.th;
43
- const Td = components.td;
33
+ const Table = components.table
34
+ const Thead = components.thead
35
+ const Tbody = components.tbody
36
+ const Tr = components.tr
37
+ const Th = components.th
38
+ const Td = components.td
44
39
  </script>
45
40
 
46
41
  {#snippet thead(head: TableFieldHead)}
@@ -72,31 +67,21 @@
72
67
  {/snippet}
73
68
 
74
69
  {#snippet th(cell: TableFieldHeaderCell)}
75
- {#if typeof Th === "function"}<Th {cell}
76
- ><PrismicRichText field={cell.content} {components} /></Th
77
- >{:else}<th {...Th}
78
- ><PrismicRichText field={cell.content} {components} /></th
79
- >{/if}
70
+ {#if typeof Th === "function"}<Th {cell}><PrismicRichText field={cell.content} {components} /></Th
71
+ >{:else}<th {...Th}><PrismicRichText field={cell.content} {components} /></th>{/if}
80
72
  {/snippet}
81
73
 
82
74
  {#snippet td(cell: TableFieldDataCell)}
83
- {#if typeof Td === "function"}<Td {cell}
84
- ><PrismicRichText field={cell.content} {components} /></Td
85
- >{:else}<td {...Td}
86
- ><PrismicRichText field={cell.content} {components} /></td
87
- >{/if}
75
+ {#if typeof Td === "function"}<Td {cell}><PrismicRichText field={cell.content} {components} /></Td
76
+ >{:else}<td {...Td}><PrismicRichText field={cell.content} {components} /></td>{/if}
88
77
  {/snippet}
89
78
 
90
79
  <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
91
80
  {#if isFilled.table(field)}
92
81
  {#if typeof Table === "function"}<Table table={field}
93
- >{#if field?.head}{@render thead(field.head)}{/if}{@render tbody(
94
- field.body,
95
- )}</Table
82
+ >{#if field?.head}{@render thead(field.head)}{/if}{@render tbody(field.body)}</Table
96
83
  >{:else}<table {...Table}>
97
- {#if field?.head}{@render thead(field.head)}{/if}{@render tbody(
98
- field.body,
99
- )}
84
+ {#if field?.head}{@render thead(field.head)}{/if}{@render tbody(field.body)}
100
85
  </table>{/if}
101
86
  {:else if Fallback}
102
87
  <Fallback />
@@ -1,29 +1,25 @@
1
1
  <script lang="ts">
2
- import type { RichTextField } from "@prismicio/client";
3
- import { asText, isFilled } from "@prismicio/client";
4
- import { DEV } from "esm-env";
2
+ import type { RichTextField } from "@prismicio/client"
3
+ import { asText, isFilled } from "@prismicio/client"
4
+ import { DEV } from "esm-env"
5
5
 
6
- import { devMsg } from "./lib/devMsg";
6
+ import { devMsg } from "./lib/devMsg"
7
7
 
8
8
  type Props = {
9
- /**
10
- * A Rich Text or Title field from Prismic.
11
- */
12
- field: RichTextField;
9
+ /** A Rich Text or Title field from Prismic. */
10
+ field: RichTextField
13
11
 
14
- /**
15
- * The separator used between blocks. Defaults to `\n`.
16
- */
17
- separator?: string | undefined;
12
+ /** The separator used between blocks. Defaults to `\n`. */
13
+ separator?: string | undefined
18
14
 
19
15
  /**
20
- * The string rendered when the field is empty. If a fallback is not given,
21
- * `null` will be rendered.
16
+ * The string rendered when the field is empty. If a fallback is not given, `null` will be
17
+ * rendered.
22
18
  */
23
- fallback?: string | undefined;
24
- };
19
+ fallback?: string | undefined
20
+ }
25
21
 
26
- const { field, separator, fallback, ...restProps }: Props = $props();
22
+ const { field, separator, fallback, ...restProps }: Props = $props()
27
23
 
28
24
  $effect(() => {
29
25
  if (DEV) {
@@ -33,10 +29,10 @@
33
29
  "classname-is-not-a-valid-prop",
34
30
  )}.`,
35
31
  $state.snapshot(field),
36
- );
32
+ )
37
33
  }
38
34
  }
39
- });
35
+ })
40
36
 
41
37
  if (DEV) {
42
38
  if (typeof field === "string") {
@@ -44,7 +40,7 @@
44
40
  `[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
41
  "prismictext-works-only-with-rich-text-and-title-fields",
46
42
  )}`,
47
- );
43
+ )
48
44
  }
49
45
  }
50
46
  </script>
@@ -9,40 +9,49 @@
9
9
  onClickHandler,
10
10
  simulatorClass,
11
11
  simulatorRootClass,
12
- } from "@prismicio/simulator/kit";
12
+ } from "@prismicio/simulator/kit"
13
13
 
14
- const defaultProps = getDefaultProps();
14
+ const defaultProps = getDefaultProps()
15
15
 
16
- export let zIndex = defaultProps.zIndex;
17
- export let background = defaultProps.background;
16
+ type Props = {
17
+ zIndex?: number
18
+ background?: string
19
+ class?: string
20
+ }
21
+
22
+ const {
23
+ zIndex = defaultProps.zIndex,
24
+ background = defaultProps.background,
25
+ class: className,
26
+ }: Props = $props()
18
27
 
19
- let slices = getDefaultSlices();
20
- let message = getDefaultMessage();
28
+ let slices = $state.raw(getDefaultSlices())
29
+ let message = $state(getDefaultMessage())
21
30
 
22
31
  if (typeof window !== "undefined") {
23
- const simulatorManager = new SimulatorManager();
32
+ const simulatorManager = new SimulatorManager()
24
33
 
25
34
  simulatorManager.state.on(
26
35
  StateEventType.Slices,
27
36
  (newSlices) => {
28
- slices = newSlices;
37
+ slices = newSlices
29
38
  },
30
39
  "simulator-slices",
31
- );
40
+ )
32
41
  simulatorManager.state.on(
33
42
  StateEventType.Message,
34
43
  (newMessage) => {
35
- message = newMessage;
44
+ message = newMessage
36
45
  },
37
46
  "simulator-message",
38
- );
47
+ )
39
48
 
40
- simulatorManager.init();
49
+ simulatorManager.init()
41
50
  }
42
51
  </script>
43
52
 
44
53
  <div
45
- class="{simulatorClass} {$$props.class}"
54
+ class="{simulatorClass} {className}"
46
55
  style="z-index: {zIndex}; position: fixed; top: 0; left: 0; width: 100%; height: 100vh; overflow: auto; background: {background}"
47
56
  >
48
57
  {#if message}
@@ -51,14 +60,16 @@
51
60
  {@html message}
52
61
  </article>
53
62
  {:else if slices.length}
54
- <!-- svelte-ignore a11y-no-static-element-interactions -->
63
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
55
64
  <div
56
65
  id="root"
57
66
  class={simulatorRootClass}
58
- on:click={onClickHandler}
59
- on:submit={disableEventHandler}
60
- on:keypress={disableEventHandler}
67
+ onclick={onClickHandler}
68
+ onsubmit={disableEventHandler}
69
+ onkeypress={disableEventHandler}
61
70
  >
71
+ <!-- TODO: Use a snippet in the next major; it would break `let:slices`. -->
72
+ <!-- svelte-ignore slot_element_deprecated -->
62
73
  <slot {slices} />
63
74
  </div>
64
75
  {/if}
@@ -1,54 +1,49 @@
1
1
  <script lang="ts">
2
- import type { Component } from "svelte";
2
+ import type { Component } from "svelte"
3
3
 
4
- import type { SliceComponentProps, SliceZoneLike } from "../types";
5
-
6
- import TodoComponent from "./TodoComponent.svelte";
4
+ import type { SliceComponentProps, SliceZoneLike } from "../types"
5
+ import TodoComponent from "./TodoComponent.svelte"
7
6
 
8
7
  type Props = {
9
- /**
10
- * An array of Prismic Slices, such as the `slices` property from a Prismic
11
- * document.
12
- */
13
- slices?: SliceZoneLike;
8
+ /** An array of Prismic Slices, such as the `slices` property from a Prismic document. */
9
+ slices?: SliceZoneLike
14
10
 
15
11
  /**
16
12
  * An object that maps Slice components to their corresponding API IDs.
17
13
  *
18
- * @example An example map:
14
+ * @example
15
+ * An example map:
19
16
  *
20
- * ```js
21
- * import BlockQuote from "./BlockQuote.svelte";
22
- * import HeroImage from "./HeroImage.svelte";
17
+ * ```js
18
+ * import BlockQuote from "./BlockQuote.svelte";
19
+ * import HeroImage from "./HeroImage.svelte";
23
20
  *
24
- * const components = {
21
+ * const components = {
25
22
  * block_quote: BlockQuote,
26
23
  * hero_image: HeroImage,
27
- * };
28
- * ```
24
+ * };
25
+ * ```
29
26
  */
30
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- components?: Record<string, Component<any>>;
28
+ components?: Record<string, Component<any>>
32
29
 
33
- /**
34
- * Arbitrary data passed to all Slice components as a `context` prop.
35
- */
30
+ /** Arbitrary data passed to all Slice components as a `context` prop. */
36
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- context?: any;
32
+ context?: any
38
33
 
39
34
  /**
40
- * The Svelte component rendered if a component mapping from the
41
- * `components` prop cannot be found.
35
+ * The Svelte component rendered if a component mapping from the `components` prop cannot be
36
+ * found.
42
37
  */
43
- defaultComponent?: Component<SliceComponentProps> | undefined;
44
- };
38
+ defaultComponent?: Component<SliceComponentProps> | undefined
39
+ }
45
40
 
46
41
  const {
47
42
  slices = [],
48
43
  components = {},
49
44
  context = {},
50
45
  defaultComponent = undefined,
51
- }: Props = $props();
46
+ }: Props = $props()
52
47
  </script>
53
48
 
54
49
  <!--
@@ -1,22 +1,22 @@
1
1
  <script lang="ts">
2
- import { DEV } from "esm-env";
2
+ import { DEV } from "esm-env"
3
3
 
4
4
  type Props = {
5
- slice: { slice_type: string } | { type: string };
6
- };
5
+ slice: { slice_type: string } | { type: string }
6
+ }
7
7
 
8
- const { slice }: Props = $props();
8
+ const { slice }: Props = $props()
9
9
 
10
- const type = $derived("slice_type" in slice ? slice.slice_type : slice.type);
10
+ const type = $derived("slice_type" in slice ? slice.slice_type : slice.type)
11
11
 
12
12
  $effect(() => {
13
13
  if (DEV) {
14
14
  console.warn(
15
15
  `[SliceZone] Could not find a component for Slice type "${type}"`,
16
16
  $state.snapshot(slice),
17
- );
17
+ )
18
18
  }
19
- });
19
+ })
20
20
  </script>
21
21
 
22
22
  {#if DEV}
package/src/index.ts CHANGED
@@ -1,19 +1,17 @@
1
- import type { RichTextComponents } from "./types";
1
+ import type { RichTextComponents } from "./types"
2
2
 
3
- export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
4
- export { default as PrismicImage } from "./PrismicImage.svelte";
5
- export { default as PrismicLink } from "./PrismicLink.svelte";
6
- export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
7
- export { default as PrismicTable } from "./PrismicTable.svelte";
8
- export { default as PrismicText } from "./PrismicText.svelte";
9
- export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
10
- export { default as SliceSimulator } from "./SliceSimulator.svelte";
3
+ export { default as PrismicEmbed } from "./PrismicEmbed.svelte"
4
+ export { default as PrismicImage } from "./PrismicImage.svelte"
5
+ export { default as PrismicLink } from "./PrismicLink.svelte"
6
+ export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte"
7
+ export { default as PrismicTable } from "./PrismicTable.svelte"
8
+ export { default as PrismicText } from "./PrismicText.svelte"
9
+ export { default as SliceZone } from "./SliceZone/SliceZone.svelte"
10
+ export { default as SliceSimulator } from "./SliceSimulator.svelte"
11
11
 
12
- /**
13
- * @deprecated Replaced with `RichTextComponents`
14
- */
12
+ /** @deprecated Replaced with `RichTextComponents` */
15
13
  // TODO: Remove in v3.
16
- export type SvelteRichTextSerializer = RichTextComponents;
17
- export type { RichTextComponents };
14
+ export type SvelteRichTextSerializer = RichTextComponents
15
+ export type { RichTextComponents }
18
16
 
19
- export type { RichTextComponentProps, SliceComponentProps } from "./types";
17
+ export type { RichTextComponentProps, SliceComponentProps } from "./types"
@@ -1,62 +1,51 @@
1
1
  <script lang="ts">
2
- import { beforeNavigate, goto, invalidateAll } from "$app/navigation";
3
- import { getToolbarSrc } from "@prismicio/client";
4
- import { onMount } from "svelte";
2
+ import { beforeNavigate, goto, invalidateAll } from "$app/navigation"
3
+ import { getToolbarSrc } from "@prismicio/client"
4
+ import { onMount } from "svelte"
5
5
 
6
6
  type Props = {
7
7
  /**
8
- * The name of your Prismic repository. A Prismic Toolbar will be registered
9
- * using this repository.
8
+ * The name of your Prismic repository. A Prismic Toolbar will be registered using this
9
+ * repository.
10
10
  */
11
- repositoryName: string;
11
+ repositoryName: string
12
12
 
13
- /**
14
- * The route parameter prefixed during preview sessions.
15
- */
16
- routePrefix?: string;
13
+ /** The route parameter prefixed during preview sessions. */
14
+ routePrefix?: string
17
15
 
18
16
  /**
19
- * The name of the preview-specific route parameter prefixed during preview
20
- * sessions.
17
+ * The name of the preview-specific route parameter prefixed during preview sessions.
21
18
  *
22
- * Only set this value if the route parameter's name differs from the
23
- * parameter's value.
19
+ * Only set this value if the route parameter's name differs from the parameter's value.
24
20
  */
25
- routePrefixName?: string;
26
- };
21
+ routePrefixName?: string
22
+ }
27
23
 
28
- const {
29
- repositoryName,
30
- routePrefix = "preview",
31
- routePrefixName = routePrefix,
32
- }: Props = $props();
24
+ const { repositoryName, routePrefix = "preview", routePrefixName = routePrefix }: Props = $props()
33
25
 
34
- const toolbarSrc = $derived(getToolbarSrc(repositoryName));
26
+ const toolbarSrc = $derived(getToolbarSrc(repositoryName))
35
27
 
36
- /**
37
- * Set to `true` when the next `beforeNavigate()` call should not prefix the
38
- * route.
39
- */
40
- let endingPreview = $state(false);
28
+ /** Set to `true` when the next `beforeNavigate()` call should not prefix the route. */
29
+ let endingPreview = $state(false)
41
30
 
42
31
  // Register Prismic toolbar event handlers to refresh data on content updates.
43
32
  onMount(() => {
44
- const controller = new AbortController();
33
+ const controller = new AbortController()
45
34
 
46
35
  window.addEventListener(
47
36
  "prismicPreviewUpdate",
48
37
  (event) => {
49
- event.preventDefault();
50
- invalidateAll();
38
+ event.preventDefault()
39
+ invalidateAll()
51
40
  },
52
41
  { signal: controller.signal },
53
- );
42
+ )
54
43
  window.addEventListener(
55
44
  "prismicPreviewEnd",
56
45
  (event) => {
57
- event.preventDefault();
46
+ event.preventDefault()
58
47
 
59
- endingPreview = true;
48
+ endingPreview = true
60
49
 
61
50
  goto(
62
51
  new URL(
@@ -70,15 +59,15 @@
70
59
  invalidateAll: true,
71
60
  noScroll: true,
72
61
  },
73
- );
62
+ )
74
63
  },
75
64
  { signal: controller.signal },
76
- );
65
+ )
77
66
 
78
67
  return () => {
79
- controller.abort();
80
- };
81
- });
68
+ controller.abort()
69
+ }
70
+ })
82
71
 
83
72
  beforeNavigate((navigation) => {
84
73
  // Prefix links with the preview route parameter if the current
@@ -92,19 +81,14 @@
92
81
  // event, don't prefix the route. The exception is only
93
82
  // valid for one call.
94
83
  if (endingPreview) {
95
- endingPreview = false;
96
- return;
84
+ endingPreview = false
85
+ return
97
86
  }
98
87
 
99
- navigation.cancel();
100
- goto(
101
- new URL(
102
- routePrefix + navigation.to.url.pathname,
103
- navigation.to.url.origin,
104
- ),
105
- );
88
+ navigation.cancel()
89
+ goto(new URL(routePrefix + navigation.to.url.pathname, navigation.to.url.origin))
106
90
  }
107
- });
91
+ })
108
92
  </script>
109
93
 
110
94
  <svelte:head>
@@ -1,36 +1,31 @@
1
- import * as prismic from "@prismicio/client";
2
- import type { Cookies } from "@sveltejs/kit";
1
+ import * as prismic from "@prismicio/client"
2
+ import type { Cookies } from "@sveltejs/kit"
3
3
 
4
- /**
5
- * Configuration for `enableAutoPreviews`.
6
- */
4
+ /** Configuration for `enableAutoPreviews`. */
7
5
  export type EnableAutoPreviewsConfig = {
8
- /**
9
- * Prismic client with which automatic previews will be enabled.
10
- */
6
+ /** Prismic client with which automatic previews will be enabled. */
11
7
  // `Pick` is used to use the smallest possible subset of `Client`. Doing
12
8
  // this reduces the surface area for breaking type changes.
13
- client: Pick<prismic.Client, "queryContentFromRef">;
9
+ client: Pick<prismic.Client, "queryContentFromRef">
14
10
 
15
11
  /**
16
- * The `cookies` object provided to a route's `load()` function. This
17
- * parameter is required to load previews.
12
+ * The `cookies` object provided to a route's `load()` function. This parameter is required to
13
+ * load previews.
18
14
  */
19
- cookies?: Cookies;
20
- };
15
+ cookies?: Cookies
16
+ }
21
17
 
22
18
  /**
23
- * Configures a Prismic client to automatically query draft content during a
24
- * preview session.
19
+ * Configures a Prismic client to automatically query draft content during a preview session.
25
20
  *
26
21
  * @param config - Configuration for the function.
27
22
  */
28
23
  export const enableAutoPreviews = (config: EnableAutoPreviewsConfig): void => {
29
24
  if (!config.cookies) {
30
- return;
25
+ return
31
26
  }
32
27
 
33
- const cookie = config.cookies.get(prismic.cookie.preview);
28
+ const cookie = config.cookies.get(prismic.cookie.preview)
34
29
 
35
30
  // We only return the cookie if a Prismic Preview session is active.
36
31
  //
@@ -47,6 +42,6 @@ export const enableAutoPreviews = (config: EnableAutoPreviewsConfig): void => {
47
42
  // }
48
43
  // }
49
44
  if (cookie && /\.prismic\.io/.test(cookie)) {
50
- config.client.queryContentFromRef(cookie);
45
+ config.client.queryContentFromRef(cookie)
51
46
  }
52
- };
47
+ }
package/src/kit/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { default as PrismicPreview } from "./PrismicPreview.svelte";
1
+ export { default as PrismicPreview } from "./PrismicPreview.svelte"
2
2
 
3
- export { enableAutoPreviews } from "./enableAutoPreviews";
4
- export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
3
+ export { enableAutoPreviews } from "./enableAutoPreviews"
4
+ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
5
5
 
6
- export { redirectToPreviewURL } from "./redirectToPreviewURL";
7
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
6
+ export { redirectToPreviewURL } from "./redirectToPreviewURL"
7
+ export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
8
8
 
9
- export type { CreateClientConfig } from "./types";
9
+ export type { CreateClientConfig } from "./types"