@prismicio/svelte 2.2.2 → 2.2.3-pr.64.25522e1

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 +31 -18
  16. package/dist/SliceSimulator.svelte.d.ts +13 -34
  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 +38 -52
  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 +43 -46
  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 +31 -18
  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 +38 -52
  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,26 +1,21 @@
1
1
  <script lang="ts">
2
- import type { RichTextField } from "@prismicio/client";
3
- import { asTree } from "@prismicio/client/richtext";
2
+ import type { RichTextField } from "@prismicio/client"
3
+ import { asTree } from "@prismicio/client/richtext"
4
4
 
5
- import type { RichTextComponents } from "../types";
6
-
7
- import Serialize from "./Serialize.svelte";
5
+ import type { RichTextComponents } from "../types"
6
+ import Serialize from "./Serialize.svelte"
8
7
 
9
8
  type Props = {
10
- /**
11
- * The Prismic rich text field to render.
12
- */
13
- field: RichTextField;
9
+ /** The Prismic rich text field to render. */
10
+ field: RichTextField
14
11
 
15
- /**
16
- * An object that maps a rich text block type to a Svelte component.
17
- */
18
- components?: RichTextComponents;
19
- };
12
+ /** An object that maps a rich text block type to a Svelte component. */
13
+ components?: RichTextComponents
14
+ }
20
15
 
21
- const { field, components = {} }: Props = $props();
16
+ const { field, components = {} }: Props = $props()
22
17
 
23
- const children = $derived(asTree(field).children);
18
+ const children = $derived(asTree(field).children)
24
19
  </script>
25
20
 
26
21
  <!--
@@ -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 = $derived(components.table)
34
+ const Thead = $derived(components.thead)
35
+ const Tbody = $derived(components.tbody)
36
+ const Tr = $derived(components.tr)
37
+ const Th = $derived(components.th)
38
+ const Td = $derived(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,53 @@
9
9
  onClickHandler,
10
10
  simulatorClass,
11
11
  simulatorRootClass,
12
- } from "@prismicio/simulator/kit";
12
+ } from "@prismicio/simulator/kit"
13
+ import type { Snippet } from "svelte"
14
+ import type { ClassValue } from "svelte/elements"
13
15
 
14
- const defaultProps = getDefaultProps();
16
+ const defaultProps = getDefaultProps()
15
17
 
16
- export let zIndex = defaultProps.zIndex;
17
- export let background = defaultProps.background;
18
+ type Props = {
19
+ zIndex?: number
20
+ background?: string
21
+ class?: ClassValue
22
+ children?: Snippet<[{ slices: ReturnType<typeof getDefaultSlices> }]>
23
+ }
24
+
25
+ const {
26
+ zIndex = defaultProps.zIndex,
27
+ background = defaultProps.background,
28
+ class: className,
29
+ children,
30
+ }: Props = $props()
18
31
 
19
- let slices = getDefaultSlices();
20
- let message = getDefaultMessage();
32
+ let slices = $state.raw(getDefaultSlices())
33
+ let message = $state(getDefaultMessage())
21
34
 
22
35
  if (typeof window !== "undefined") {
23
- const simulatorManager = new SimulatorManager();
36
+ const simulatorManager = new SimulatorManager()
24
37
 
25
38
  simulatorManager.state.on(
26
39
  StateEventType.Slices,
27
40
  (newSlices) => {
28
- slices = newSlices;
41
+ slices = newSlices
29
42
  },
30
43
  "simulator-slices",
31
- );
44
+ )
32
45
  simulatorManager.state.on(
33
46
  StateEventType.Message,
34
47
  (newMessage) => {
35
- message = newMessage;
48
+ message = newMessage
36
49
  },
37
50
  "simulator-message",
38
- );
51
+ )
39
52
 
40
- simulatorManager.init();
53
+ simulatorManager.init()
41
54
  }
42
55
  </script>
43
56
 
44
57
  <div
45
- class="{simulatorClass} {$$props.class}"
58
+ class={[simulatorClass, className]}
46
59
  style="z-index: {zIndex}; position: fixed; top: 0; left: 0; width: 100%; height: 100vh; overflow: auto; background: {background}"
47
60
  >
48
61
  {#if message}
@@ -51,15 +64,15 @@
51
64
  {@html message}
52
65
  </article>
53
66
  {:else if slices.length}
54
- <!-- svelte-ignore a11y-no-static-element-interactions -->
67
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
55
68
  <div
56
69
  id="root"
57
70
  class={simulatorRootClass}
58
- on:click={onClickHandler}
59
- on:submit={disableEventHandler}
60
- on:keypress={disableEventHandler}
71
+ onclick={onClickHandler}
72
+ onsubmit={disableEventHandler}
73
+ onkeypress={disableEventHandler}
61
74
  >
62
- <slot {slices} />
75
+ {@render children?.({ slices })}
63
76
  </div>
64
77
  {/if}
65
78
  </div>
@@ -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,52 @@
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, refreshAll } from "$app/navigation"
3
+ import { getToolbarSrc } from "@prismicio/client"
4
+ import { VERSION } from "@sveltejs/kit"
5
+ import { onMount } from "svelte"
5
6
 
6
7
  type Props = {
7
8
  /**
8
- * The name of your Prismic repository. A Prismic Toolbar will be registered
9
- * using this repository.
9
+ * The name of your Prismic repository. A Prismic Toolbar will be registered using this
10
+ * repository.
10
11
  */
11
- repositoryName: string;
12
+ repositoryName: string
12
13
 
13
- /**
14
- * The route parameter prefixed during preview sessions.
15
- */
16
- routePrefix?: string;
14
+ /** The route parameter prefixed during preview sessions. */
15
+ routePrefix?: string
17
16
 
18
17
  /**
19
- * The name of the preview-specific route parameter prefixed during preview
20
- * sessions.
18
+ * The name of the preview-specific route parameter prefixed during preview sessions.
21
19
  *
22
- * Only set this value if the route parameter's name differs from the
23
- * parameter's value.
20
+ * Only set this value if the route parameter's name differs from the parameter's value.
24
21
  */
25
- routePrefixName?: string;
26
- };
22
+ routePrefixName?: string
23
+ }
27
24
 
28
- const {
29
- repositoryName,
30
- routePrefix = "preview",
31
- routePrefixName = routePrefix,
32
- }: Props = $props();
25
+ const { repositoryName, routePrefix = "preview", routePrefixName = routePrefix }: Props = $props()
33
26
 
34
- const toolbarSrc = $derived(getToolbarSrc(repositoryName));
27
+ const toolbarSrc = $derived(getToolbarSrc(repositoryName))
35
28
 
36
- /**
37
- * Set to `true` when the next `beforeNavigate()` call should not prefix the
38
- * route.
39
- */
40
- let endingPreview = $state(false);
29
+ /** Set to `true` when the next `beforeNavigate()` call should not prefix the route. */
30
+ let endingPreview = $state(false)
41
31
 
42
32
  // Register Prismic toolbar event handlers to refresh data on content updates.
43
33
  onMount(() => {
44
- const controller = new AbortController();
34
+ const controller = new AbortController()
45
35
 
46
36
  window.addEventListener(
47
37
  "prismicPreviewUpdate",
48
38
  (event) => {
49
- event.preventDefault();
50
- invalidateAll();
39
+ event.preventDefault()
40
+ refreshAll()
51
41
  },
52
42
  { signal: controller.signal },
53
- );
43
+ )
54
44
  window.addEventListener(
55
45
  "prismicPreviewEnd",
56
46
  (event) => {
57
- event.preventDefault();
47
+ event.preventDefault()
58
48
 
59
- endingPreview = true;
49
+ endingPreview = true
60
50
 
61
51
  goto(
62
52
  new URL(
@@ -66,19 +56,20 @@
66
56
  ),
67
57
  window.location.origin,
68
58
  ),
69
- {
70
- invalidateAll: true,
71
- noScroll: true,
72
- },
73
- );
59
+ // SvelteKit 3 replaced `noScroll` with `reset`, and
60
+ // throws if `noScroll` is passed.
61
+ (VERSION.startsWith("2.")
62
+ ? { invalidateAll: true, noScroll: true }
63
+ : { refreshAll: true, reset: false }) as Parameters<typeof goto>[1],
64
+ )
74
65
  },
75
66
  { signal: controller.signal },
76
- );
67
+ )
77
68
 
78
69
  return () => {
79
- controller.abort();
80
- };
81
- });
70
+ controller.abort()
71
+ }
72
+ })
82
73
 
83
74
  beforeNavigate((navigation) => {
84
75
  // Prefix links with the preview route parameter if the current
@@ -92,19 +83,14 @@
92
83
  // event, don't prefix the route. The exception is only
93
84
  // valid for one call.
94
85
  if (endingPreview) {
95
- endingPreview = false;
96
- return;
86
+ endingPreview = false
87
+ return
97
88
  }
98
89
 
99
- navigation.cancel();
100
- goto(
101
- new URL(
102
- routePrefix + navigation.to.url.pathname,
103
- navigation.to.url.origin,
104
- ),
105
- );
90
+ navigation.cancel()
91
+ goto(new URL(routePrefix + navigation.to.url.pathname, navigation.to.url.origin))
106
92
  }
107
- });
93
+ })
108
94
  </script>
109
95
 
110
96
  <svelte:head>