@prismicio/svelte 2.2.2 → 2.2.3
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/dist/PrismicEmbed.svelte +6 -8
- package/dist/PrismicEmbed.svelte.d.ts +1 -3
- package/dist/PrismicImage.svelte +46 -68
- package/dist/PrismicImage.svelte.d.ts +11 -17
- package/dist/PrismicLink.svelte +23 -34
- package/dist/PrismicLink.svelte.d.ts +5 -10
- package/dist/PrismicRichText/DefaultComponent.svelte +9 -13
- package/dist/PrismicRichText/PrismicRichText.svelte +11 -16
- package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +2 -6
- package/dist/PrismicRichText/Serialize.svelte +11 -19
- package/dist/PrismicTable.svelte +26 -41
- package/dist/PrismicTable.svelte.d.ts +4 -8
- package/dist/PrismicText.svelte +16 -20
- package/dist/PrismicText.svelte.d.ts +4 -8
- package/dist/SliceSimulator.svelte +28 -17
- package/dist/SliceSimulator.svelte.d.ts +7 -6
- package/dist/SliceZone/SliceZone.svelte +21 -26
- package/dist/SliceZone/SliceZone.svelte.d.ts +12 -16
- package/dist/SliceZone/TodoComponent.svelte +7 -7
- package/dist/index.d.ts +1 -3
- package/dist/kit/PrismicPreview.svelte +32 -48
- package/dist/kit/PrismicPreview.svelte.d.ts +5 -9
- package/dist/kit/enableAutoPreviews.d.ts +5 -10
- package/dist/kit/enableAutoPreviews.js +1 -2
- package/dist/kit/redirectToPreviewURL.d.ts +13 -21
- package/dist/kit/redirectToPreviewURL.js +10 -11
- package/dist/kit/types.d.ts +3 -6
- package/dist/lib/devMsg.d.ts +6 -8
- package/dist/lib/devMsg.js +6 -8
- package/dist/types.d.ts +23 -39
- package/package.json +41 -44
- package/src/PrismicEmbed.svelte +6 -8
- package/src/PrismicImage.svelte +46 -68
- package/src/PrismicLink.svelte +23 -34
- package/src/PrismicRichText/DefaultComponent.svelte +9 -13
- package/src/PrismicRichText/PrismicRichText.svelte +11 -16
- package/src/PrismicRichText/Serialize.svelte +11 -19
- package/src/PrismicTable.svelte +26 -41
- package/src/PrismicText.svelte +16 -20
- package/src/SliceSimulator.svelte +28 -17
- package/src/SliceZone/SliceZone.svelte +21 -26
- package/src/SliceZone/TodoComponent.svelte +7 -7
- package/src/index.ts +13 -15
- package/src/kit/PrismicPreview.svelte +32 -48
- package/src/kit/enableAutoPreviews.ts +14 -19
- package/src/kit/index.ts +6 -6
- package/src/kit/redirectToPreviewURL.ts +28 -38
- package/src/kit/types.ts +7 -10
- package/src/lib/devMsg.ts +9 -11
- package/src/types.ts +84 -106
package/dist/PrismicText.svelte
CHANGED
|
@@ -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
|
-
|
|
11
|
-
*/
|
|
12
|
-
field: RichTextField;
|
|
9
|
+
/** A Rich Text or Title field from Prismic. */
|
|
10
|
+
field: RichTextField
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
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
|
-
*
|
|
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>
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { RichTextField } from "@prismicio/client";
|
|
2
2
|
type Props = {
|
|
3
|
-
/**
|
|
4
|
-
* A Rich Text or Title field from Prismic.
|
|
5
|
-
*/
|
|
3
|
+
/** A Rich Text or Title field from Prismic. */
|
|
6
4
|
field: RichTextField;
|
|
7
|
-
/**
|
|
8
|
-
* The separator used between blocks. Defaults to `\n`.
|
|
9
|
-
*/
|
|
5
|
+
/** The separator used between blocks. Defaults to `\n`. */
|
|
10
6
|
separator?: string | undefined;
|
|
11
7
|
/**
|
|
12
|
-
* The string rendered when the field is empty. If a fallback is not given,
|
|
13
|
-
*
|
|
8
|
+
* The string rendered when the field is empty. If a fallback is not given, `null` will be
|
|
9
|
+
* rendered.
|
|
14
10
|
*/
|
|
15
11
|
fallback?: string | undefined;
|
|
16
12
|
};
|
|
@@ -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
|
-
|
|
17
|
-
|
|
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} {
|
|
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
|
|
63
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
55
64
|
<div
|
|
56
65
|
id="root"
|
|
57
66
|
class={simulatorRootClass}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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,3 +1,8 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
zIndex?: number;
|
|
3
|
+
background?: string;
|
|
4
|
+
class?: string;
|
|
5
|
+
};
|
|
1
6
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
7
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
8
|
$$bindings?: Bindings;
|
|
@@ -16,11 +21,7 @@ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
|
16
21
|
} ? Props extends Record<string, never> ? any : {
|
|
17
22
|
children?: any;
|
|
18
23
|
} : {});
|
|
19
|
-
declare const SliceSimulator: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
20
|
-
[x: string]: any;
|
|
21
|
-
zIndex?: number | undefined;
|
|
22
|
-
background?: string | undefined;
|
|
23
|
-
}, {
|
|
24
|
+
declare const SliceSimulator: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<Props, {
|
|
24
25
|
default: {
|
|
25
26
|
slices: import("@prismicio/client").SliceZone;
|
|
26
27
|
};
|
|
@@ -30,6 +31,6 @@ declare const SliceSimulator: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_
|
|
|
30
31
|
default: {
|
|
31
32
|
slices: import("@prismicio/client").SliceZone;
|
|
32
33
|
};
|
|
33
|
-
}, {},
|
|
34
|
+
}, {}, "">;
|
|
34
35
|
type SliceSimulator = InstanceType<typeof SliceSimulator>;
|
|
35
36
|
export default SliceSimulator;
|
|
@@ -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
|
-
|
|
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
|
|
14
|
+
* @example
|
|
15
|
+
* An example map:
|
|
19
16
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import BlockQuote from "./BlockQuote.svelte";
|
|
19
|
+
* import HeroImage from "./HeroImage.svelte";
|
|
23
20
|
*
|
|
24
|
-
*
|
|
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
|
-
*
|
|
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,34 +1,30 @@
|
|
|
1
1
|
import type { Component } from "svelte";
|
|
2
2
|
import type { SliceComponentProps, SliceZoneLike } from "../types";
|
|
3
3
|
type Props = {
|
|
4
|
-
/**
|
|
5
|
-
* An array of Prismic Slices, such as the `slices` property from a Prismic
|
|
6
|
-
* document.
|
|
7
|
-
*/
|
|
4
|
+
/** An array of Prismic Slices, such as the `slices` property from a Prismic document. */
|
|
8
5
|
slices?: SliceZoneLike;
|
|
9
6
|
/**
|
|
10
7
|
* An object that maps Slice components to their corresponding API IDs.
|
|
11
8
|
*
|
|
12
|
-
* @example
|
|
9
|
+
* @example
|
|
10
|
+
* An example map:
|
|
13
11
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* ```js
|
|
13
|
+
* import BlockQuote from "./BlockQuote.svelte";
|
|
14
|
+
* import HeroImage from "./HeroImage.svelte";
|
|
17
15
|
*
|
|
18
|
-
*
|
|
16
|
+
* const components = {
|
|
19
17
|
* block_quote: BlockQuote,
|
|
20
18
|
* hero_image: HeroImage,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
23
21
|
*/
|
|
24
22
|
components?: Record<string, Component<any>>;
|
|
25
|
-
/**
|
|
26
|
-
* Arbitrary data passed to all Slice components as a `context` prop.
|
|
27
|
-
*/
|
|
23
|
+
/** Arbitrary data passed to all Slice components as a `context` prop. */
|
|
28
24
|
context?: any;
|
|
29
25
|
/**
|
|
30
|
-
* The Svelte component rendered if a component mapping from the
|
|
31
|
-
*
|
|
26
|
+
* The Svelte component rendered if a component mapping from the `components` prop cannot be
|
|
27
|
+
* found.
|
|
32
28
|
*/
|
|
33
29
|
defaultComponent?: Component<SliceComponentProps> | undefined;
|
|
34
30
|
};
|
|
@@ -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/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,7 @@ export { default as PrismicTable } from "./PrismicTable.svelte";
|
|
|
7
7
|
export { default as PrismicText } from "./PrismicText.svelte";
|
|
8
8
|
export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
|
|
9
9
|
export { default as SliceSimulator } from "./SliceSimulator.svelte";
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Replaced with `RichTextComponents`
|
|
12
|
-
*/
|
|
10
|
+
/** @deprecated Replaced with `RichTextComponents` */
|
|
13
11
|
export type SvelteRichTextSerializer = RichTextComponents;
|
|
14
12
|
export type { RichTextComponents };
|
|
15
13
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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,19 +1,15 @@
|
|
|
1
1
|
type Props = {
|
|
2
2
|
/**
|
|
3
|
-
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
4
|
-
*
|
|
3
|
+
* The name of your Prismic repository. A Prismic Toolbar will be registered using this
|
|
4
|
+
* repository.
|
|
5
5
|
*/
|
|
6
6
|
repositoryName: string;
|
|
7
|
-
/**
|
|
8
|
-
* The route parameter prefixed during preview sessions.
|
|
9
|
-
*/
|
|
7
|
+
/** The route parameter prefixed during preview sessions. */
|
|
10
8
|
routePrefix?: string;
|
|
11
9
|
/**
|
|
12
|
-
* The name of the preview-specific route parameter prefixed during preview
|
|
13
|
-
* sessions.
|
|
10
|
+
* The name of the preview-specific route parameter prefixed during preview sessions.
|
|
14
11
|
*
|
|
15
|
-
* Only set this value if the route parameter's name differs from the
|
|
16
|
-
* parameter's value.
|
|
12
|
+
* Only set this value if the route parameter's name differs from the parameter's value.
|
|
17
13
|
*/
|
|
18
14
|
routePrefixName?: string;
|
|
19
15
|
};
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
import type { Cookies } from "@sveltejs/kit";
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for `enableAutoPreviews`.
|
|
5
|
-
*/
|
|
3
|
+
/** Configuration for `enableAutoPreviews`. */
|
|
6
4
|
export type EnableAutoPreviewsConfig = {
|
|
7
|
-
/**
|
|
8
|
-
* Prismic client with which automatic previews will be enabled.
|
|
9
|
-
*/
|
|
5
|
+
/** Prismic client with which automatic previews will be enabled. */
|
|
10
6
|
client: Pick<prismic.Client, "queryContentFromRef">;
|
|
11
7
|
/**
|
|
12
|
-
* The `cookies` object provided to a route's `load()` function. This
|
|
13
|
-
*
|
|
8
|
+
* The `cookies` object provided to a route's `load()` function. This parameter is required to
|
|
9
|
+
* load previews.
|
|
14
10
|
*/
|
|
15
11
|
cookies?: Cookies;
|
|
16
12
|
};
|
|
17
13
|
/**
|
|
18
|
-
* Configures a Prismic client to automatically query draft content during a
|
|
19
|
-
* preview session.
|
|
14
|
+
* Configures a Prismic client to automatically query draft content during a preview session.
|
|
20
15
|
*
|
|
21
16
|
* @param config - Configuration for the function.
|
|
22
17
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
/**
|
|
3
|
-
* Configures a Prismic client to automatically query draft content during a
|
|
4
|
-
* preview session.
|
|
3
|
+
* Configures a Prismic client to automatically query draft content during a preview session.
|
|
5
4
|
*
|
|
6
5
|
* @param config - Configuration for the function.
|
|
7
6
|
*/
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
import type { Cookies } from "@sveltejs/kit";
|
|
3
3
|
export type RedirectToPreviewURLConfig = {
|
|
4
|
-
/**
|
|
5
|
-
* The Prismic client configured for the preview session's repository.
|
|
6
|
-
*/
|
|
4
|
+
/** The Prismic client configured for the preview session's repository. */
|
|
7
5
|
client: Pick<prismic.Client, "resolvePreviewURL">;
|
|
8
6
|
/**
|
|
9
7
|
* The `request` object from a `+server` file.
|
|
@@ -17,33 +15,27 @@ export type RedirectToPreviewURLConfig = {
|
|
|
17
15
|
* @see SvelteKit `+server` docs: \<https://kit.svelte.dev/docs/routing#server\>
|
|
18
16
|
*/
|
|
19
17
|
cookies: Cookies;
|
|
20
|
-
/**
|
|
21
|
-
* The default redirect URL if a URL cannot be determined for the previewed
|
|
22
|
-
* document.
|
|
23
|
-
*/
|
|
18
|
+
/** The default redirect URL if a URL cannot be determined for the previewed document. */
|
|
24
19
|
defaultURL?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The route parameter prefixed during preview sessions.
|
|
27
|
-
*/
|
|
20
|
+
/** The route parameter prefixed during preview sessions. */
|
|
28
21
|
routePrefix?: string;
|
|
29
22
|
};
|
|
30
23
|
/**
|
|
31
|
-
* Redirects a visitor to the URL of a previewed Prismic document from within a
|
|
32
|
-
*
|
|
24
|
+
* Redirects a visitor to the URL of a previewed Prismic document from within a SvelteKit `+server`
|
|
25
|
+
* file.
|
|
33
26
|
*
|
|
34
27
|
* Return the created `Response` in your `+server` file.
|
|
35
28
|
*
|
|
36
29
|
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { createClient } from "$lib/prismicio.js"
|
|
32
|
+
* import { redirectToPreviewURL } from "@prismicio/svelte/kit"
|
|
37
33
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* import { redirectToPreviewURL } from "@prismicio/svelte/kit";
|
|
41
|
-
*
|
|
42
|
-
* export async function GET({ fetch, request }) {
|
|
43
|
-
* const client = createClient({ fetch });
|
|
34
|
+
* export async function GET({ fetch, request }) {
|
|
35
|
+
* const client = createClient({ fetch })
|
|
44
36
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
37
|
+
* return await redirectToPreviewURL({ client, request })
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
48
40
|
*/
|
|
49
41
|
export declare const redirectToPreviewURL: (config: RedirectToPreviewURLConfig) => Promise<Response>;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
/**
|
|
3
|
-
* Redirects a visitor to the URL of a previewed Prismic document from within a
|
|
4
|
-
*
|
|
3
|
+
* Redirects a visitor to the URL of a previewed Prismic document from within a SvelteKit `+server`
|
|
4
|
+
* file.
|
|
5
5
|
*
|
|
6
6
|
* Return the created `Response` in your `+server` file.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createClient } from "$lib/prismicio.js"
|
|
11
|
+
* import { redirectToPreviewURL } from "@prismicio/svelte/kit"
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* import { redirectToPreviewURL } from "@prismicio/svelte/kit";
|
|
13
|
+
* export async function GET({ fetch, request }) {
|
|
14
|
+
* const client = createClient({ fetch })
|
|
13
15
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* return await redirectToPreviewURL({ client, request });
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
16
|
+
* return await redirectToPreviewURL({ client, request })
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
20
19
|
*/
|
|
21
20
|
export const redirectToPreviewURL = async (config) => {
|
|
22
21
|
const previewToken = new URL(config.request.url).searchParams.get("token") ?? undefined;
|
package/dist/kit/types.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { ClientConfig } from "@prismicio/client";
|
|
2
2
|
import type { Cookies } from "@sveltejs/kit";
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for creating a Prismic client with automatic preview support in
|
|
5
|
-
* SvelteKit apps.
|
|
6
|
-
*/
|
|
3
|
+
/** Configuration for creating a Prismic client with automatic preview support in SvelteKit apps. */
|
|
7
4
|
export type CreateClientConfig = ClientConfig & {
|
|
8
5
|
/**
|
|
9
|
-
* The `cookies` object provided to a route's `load()` function. This
|
|
10
|
-
*
|
|
6
|
+
* The `cookies` object provided to a route's `load()` function. This parameter is required to
|
|
7
|
+
* load previews.
|
|
11
8
|
*/
|
|
12
9
|
cookies?: Cookies;
|
|
13
10
|
};
|