@prismicio/svelte 0.0.5 → 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.
- package/CHANGELOG.md +13 -2
- package/components/PrismicImage.svelte +0 -2
- package/components/PrismicLink.svelte +20 -39
- package/components/index.js +1 -1
- package/index.js +1 -1
- package/lib/components/PrismicLink.svelte.d.ts +11 -14
- package/lib/components/index.d.ts +1 -0
- package/lib/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/lib/components/PrismicImage.svelte +0 -2
- package/src/lib/components/PrismicLink.svelte +39 -54
- package/src/lib/components/index.ts +1 -1
- package/src/lib/index.ts +1 -1
- package/src/routes/+page.server.ts +8 -3
- package/src/routes/+page.svelte +14 -3
- package/src/types/CodeSnippetSlice.type.ts +4 -2
- package/src/types/ExampleDocument.type.ts +6 -0
- package/src/types/index.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [0.0.
|
|
5
|
+
### [0.0.6](https://github.com/prismicio/prismic-svelte/compare/v0.0.5...v0.0.6) (2023-02-24)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add `<PrismicLink>` component ([1db9dc0](https://github.com/prismicio/prismic-svelte/commit/1db9dc0cd6a24de87505b5e1486fe9458cb7be01))
|
|
6
11
|
|
|
7
12
|
|
|
8
13
|
### Chore
|
|
9
14
|
|
|
10
|
-
*
|
|
15
|
+
* fix slice typing ([16340b3](https://github.com/prismicio/prismic-svelte/commit/16340b320396f69127e89d26dae498baff8fa299))
|
|
16
|
+
|
|
17
|
+
### [0.0.5](https://github.com/prismicio/prismic-svelte/compare/v0.0.4...v0.0.5) (2023-02-23)
|
|
18
|
+
|
|
19
|
+
### Chore
|
|
20
|
+
|
|
21
|
+
- upgrade SvelteKit to 1.0 ([#3](https://github.com/prismicio/prismic-svelte/issues/3)) ([8d5addc](https://github.com/prismicio/prismic-svelte/commit/8d5addcdd669895ccacb666286b57af7825f4869))
|
|
11
22
|
|
|
12
23
|
### [0.0.4](https://github.com/prismicio/prismic-svelte/compare/v0.0.3...v0.0.4) (2022-05-27)
|
|
13
24
|
|
|
@@ -1,44 +1,25 @@
|
|
|
1
1
|
<script>import * as prismicH from "@prismicio/helpers";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export let
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
rels.push(...rel?.split(" "));
|
|
10
|
-
if ((field && "target" in field && field?.target === "_blank") ||
|
|
11
|
-
target === "_blank")
|
|
12
|
-
defaultBlankTargetRelAttribute.forEach((item) => {
|
|
13
|
-
if (!rels.includes(item))
|
|
14
|
-
rels.push(item);
|
|
15
|
-
});
|
|
16
|
-
if (field &&
|
|
17
|
-
"link_type" in field &&
|
|
18
|
-
field?.link_type === "Web" &&
|
|
19
|
-
!rels.includes("external"))
|
|
20
|
-
rels.push("external");
|
|
21
|
-
return rels.join(" ");
|
|
22
|
-
};
|
|
23
|
-
const attrs = {
|
|
24
|
-
download,
|
|
25
|
-
hreflang,
|
|
26
|
-
referrerpolicy,
|
|
27
|
-
target: target || field?.target || undefined,
|
|
28
|
-
rel: setRel(),
|
|
29
|
-
type,
|
|
30
|
-
};
|
|
31
|
-
const link = field
|
|
32
|
-
? prismicH.asLink(field, linkResolver || usePrismic().linkResolver)
|
|
33
|
-
: "";
|
|
34
|
-
const href = link || "";
|
|
2
|
+
export let field;
|
|
3
|
+
export let linkResolver = undefined;
|
|
4
|
+
export let target = undefined;
|
|
5
|
+
const resolvedTarget = target || (field && "target" in field && field.target) || undefined;
|
|
6
|
+
export let rel = undefined;
|
|
7
|
+
const resolvedRel = rel || (target === "_blank" ? "noopener noreferrer" : undefined);
|
|
8
|
+
const href = (field ? prismicH.asLink(field, linkResolver) : "") || "";
|
|
35
9
|
</script>
|
|
36
10
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
11
|
+
<!--
|
|
12
|
+
@component
|
|
13
|
+
Component to render a Prismic Link, Link to Media, Content Relationship, or whole Document as an `a` tag.
|
|
14
|
+
|
|
15
|
+
@example Rendering a Link field:
|
|
16
|
+
```svelte
|
|
17
|
+
<PrismicLink field={document.data.example_link}>
|
|
18
|
+
Example anchor text.
|
|
19
|
+
</PrismicLink>
|
|
20
|
+
```
|
|
21
|
+
-->
|
|
22
|
+
|
|
23
|
+
<a {href} {...$$restProps} rel={resolvedRel} target={resolvedTarget}>
|
|
43
24
|
<slot />
|
|
44
25
|
</a>
|
package/components/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
|
|
2
2
|
// export { default as PrismicImage } from "./PrismicImage.svelte";
|
|
3
|
-
|
|
3
|
+
export { default as PrismicLink } from "./PrismicLink.svelte";
|
|
4
4
|
// export { default as PrismicText } from "./PrismicText.svelte";
|
|
5
5
|
// export { default as PrismicRichText } from "./PrismicRichText.svelte";
|
|
6
6
|
// export { default as PrismicPreview } from "./PrismicPreview.svelte";
|
package/index.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import * as prismicH from "@prismicio/helpers";
|
|
3
|
-
import type * as prismicT from "@prismicio/types";
|
|
4
2
|
declare const __propDef: {
|
|
5
|
-
props:
|
|
6
|
-
field: prismicT.LinkField | prismicT.PrismicDocument | null | undefined;
|
|
7
|
-
linkResolver: prismicH.LinkResolverFunction | null | undefined;
|
|
8
|
-
download: boolean | null | undefined;
|
|
9
|
-
hreflang: string | undefined;
|
|
10
|
-
referrerpolicy: string | undefined;
|
|
11
|
-
rel: string | undefined;
|
|
12
|
-
target: string | undefined;
|
|
13
|
-
type: string | undefined;
|
|
14
|
-
prefetch: true | undefined;
|
|
15
|
-
noscroll: true | undefined;
|
|
16
|
-
};
|
|
3
|
+
props: any;
|
|
17
4
|
events: {
|
|
18
5
|
[evt: string]: CustomEvent<any>;
|
|
19
6
|
};
|
|
@@ -24,6 +11,16 @@ declare const __propDef: {
|
|
|
24
11
|
export type PrismicLinkProps = typeof __propDef.props;
|
|
25
12
|
export type PrismicLinkEvents = typeof __propDef.events;
|
|
26
13
|
export type PrismicLinkSlots = typeof __propDef.slots;
|
|
14
|
+
/**
|
|
15
|
+
* Component to render a Prismic Link, Link to Media, Content Relationship, or whole Document as an `a` tag.
|
|
16
|
+
*
|
|
17
|
+
* @example Rendering a Link field:
|
|
18
|
+
* ```svelte
|
|
19
|
+
* <PrismicLink field={document.data.example_link}>
|
|
20
|
+
* Example anchor text.
|
|
21
|
+
* </PrismicLink>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
27
24
|
export default class PrismicLink extends SvelteComponentTyped<PrismicLinkProps, PrismicLinkEvents, PrismicLinkSlots> {
|
|
28
25
|
}
|
|
29
26
|
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SliceZone, } from "./components";
|
|
1
|
+
export { PrismicLink, SliceZone, } from "./components";
|
package/package.json
CHANGED
|
@@ -2,66 +2,51 @@
|
|
|
2
2
|
import * as prismicH from "@prismicio/helpers";
|
|
3
3
|
import type * as prismicT from "@prismicio/types";
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// export { default as PrismicImage } from "./PrismicImage.svelte";
|
|
4
4
|
|
|
5
|
-
|
|
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
|
@@ -3,13 +3,18 @@ import type { PageDocument } from "../types/PageDocument.type"
|
|
|
3
3
|
import type { PageServerLoad } from "./$types";
|
|
4
4
|
|
|
5
5
|
export const load = (async ({ fetch }) => {
|
|
6
|
-
const endpoint = prismic.
|
|
6
|
+
const endpoint = prismic.getRepositoryEndpoint("svelte-package-dev");
|
|
7
7
|
const client = prismic.createClient(endpoint, { fetch });
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const pageDocument: PageDocument = await client.getSingle("homepage");
|
|
10
|
+
|
|
11
|
+
const exampleClient = prismic.createClient("example-prismic-repo", { fetch })
|
|
12
|
+
const exampleDocument = exampleClient.getFirst()
|
|
13
|
+
|
|
10
14
|
|
|
11
15
|
return {
|
|
12
|
-
|
|
16
|
+
pageDocument,
|
|
17
|
+
exampleDocument
|
|
13
18
|
};
|
|
14
19
|
// eslint-disable-next-line prettier/prettier
|
|
15
20
|
}) satisfies PageServerLoad;
|
package/src/routes/+page.svelte
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { SliceZone } from "$lib";
|
|
3
|
-
import { RichText, CodeSnippet } from "
|
|
2
|
+
import { SliceZone, PrismicLink } from "$lib";
|
|
3
|
+
import { RichText, CodeSnippet } from "./slices";
|
|
4
4
|
import type { PageData } from "./$types";
|
|
5
5
|
|
|
6
6
|
const components = {
|
|
@@ -13,7 +13,18 @@
|
|
|
13
13
|
|
|
14
14
|
<main>
|
|
15
15
|
<h1>Welcome to SvelteKit</h1>
|
|
16
|
-
<
|
|
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} />
|
|
17
28
|
</main>
|
|
18
29
|
|
|
19
30
|
<style>
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { CodeSnippetSlice } from "./CodeSnippetSlice.type";
|
|
2
|
-
export type {
|
|
2
|
+
export type { PageDocument } from "./PageDocument.type";
|
|
3
|
+
export type { ExampleDocument } from "./ExampleDocument.type";
|
|
3
4
|
export type { PrismicConfig } from "./PrismicConfig.type";
|
|
4
5
|
export type { PrismicContext } from "./PrismicContext.type";
|
|
5
6
|
export type { RichTextSlice } from "./RichTextSlice.type";
|