@prismicio/svelte 0.0.11 → 0.1.0

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 (57) hide show
  1. package/README.md +29 -30
  2. package/dist/PrismicEmbed.svelte +8 -7
  3. package/dist/PrismicEmbed.svelte.d.ts +7 -7
  4. package/dist/PrismicImage.svelte +58 -64
  5. package/dist/PrismicImage.svelte.d.ts +270 -44
  6. package/dist/PrismicLink.svelte +16 -13
  7. package/dist/PrismicLink.svelte.d.ts +242 -35
  8. package/dist/PrismicRichText/DefaultComponent.svelte +1 -8
  9. package/dist/PrismicRichText/DefaultComponent.svelte.d.ts +4 -9
  10. package/dist/PrismicRichText/PrismicRichText.svelte +8 -14
  11. package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +12 -33
  12. package/dist/PrismicRichText/Serialize.svelte +16 -15
  13. package/dist/PrismicRichText/Serialize.svelte.d.ts +7 -8
  14. package/dist/PrismicText.svelte +28 -4
  15. package/dist/PrismicText.svelte.d.ts +7 -10
  16. package/dist/SliceZone/SliceZone.svelte +12 -9
  17. package/dist/SliceZone/SliceZone.svelte.d.ts +41 -13
  18. package/dist/SliceZone/{TodoSliceComponent.svelte → TodoComponent.svelte} +2 -1
  19. package/dist/SliceZone/TodoComponent.svelte.d.ts +20 -0
  20. package/dist/index.d.ts +1 -0
  21. package/dist/lib/devMsg.d.ts +16 -0
  22. package/dist/lib/devMsg.js +19 -0
  23. package/dist/types.d.ts +7 -0
  24. package/dist/types.js +1 -0
  25. package/package.json +52 -112
  26. package/src/PrismicEmbed.svelte +30 -0
  27. package/src/PrismicImage.svelte +168 -0
  28. package/src/PrismicLink.svelte +60 -0
  29. package/{dist/src/lib → src}/PrismicRichText/DefaultComponent.svelte +3 -15
  30. package/src/PrismicRichText/PrismicRichText.svelte +32 -0
  31. package/src/PrismicRichText/Serialize.svelte +36 -0
  32. package/src/PrismicText.svelte +58 -0
  33. package/{dist/src/lib → src}/SliceZone/SliceZone.svelte +29 -21
  34. package/{dist/src/lib/SliceZone/TodoSliceComponent.svelte → src/SliceZone/TodoComponent.svelte} +2 -1
  35. package/{dist/src/lib → src}/index.ts +2 -0
  36. package/src/lib/devMsg.ts +20 -0
  37. package/src/types.ts +15 -0
  38. package/dist/SliceZone/TodoSliceComponent.svelte.d.ts +0 -20
  39. package/dist/src/app.html +0 -12
  40. package/dist/src/global.d.ts +0 -1
  41. package/dist/src/lib/PrismicEmbed.svelte +0 -29
  42. package/dist/src/lib/PrismicImage.svelte +0 -192
  43. package/dist/src/lib/PrismicLink.svelte +0 -64
  44. package/dist/src/lib/PrismicRichText/PrismicRichText.svelte +0 -67
  45. package/dist/src/lib/PrismicRichText/Serialize.svelte +0 -33
  46. package/dist/src/lib/PrismicText.svelte +0 -29
  47. package/dist/src/routes/+page.server.ts +0 -19
  48. package/dist/src/routes/+page.svelte +0 -62
  49. package/dist/src/routes/components/Emphasis.svelte +0 -3
  50. package/dist/src/routes/slices/CodeSnippet.svelte +0 -19
  51. package/dist/src/routes/slices/RichText.svelte +0 -12
  52. package/dist/src/types/CodeSnippetSlice.type.ts +0 -7
  53. package/dist/src/types/ExampleDocument.type.ts +0 -8
  54. package/dist/src/types/PageDocument.type.ts +0 -7
  55. package/dist/src/types/RichTextSlice.type.ts +0 -7
  56. package/dist/src/types/Route.type.ts +0 -14
  57. package/dist/src/types/index.ts +0 -5
package/README.md CHANGED
@@ -1,13 +1,3 @@
1
- <!--
2
-
3
- Replace all on all files (README.md, CONTRIBUTING.md, bug_report.md, package.json):
4
- - @prismicio/svelte
5
- - Svelte components and helpers to fetch and present Prismic content
6
- - prismicio/prismic-svelte
7
- - prismic-svelte
8
-
9
- -->
10
-
11
1
  # @prismicio/svelte
12
2
 
13
3
  [![npm version][npm-version-src]][npm-version-href]
@@ -17,15 +7,24 @@ Replace all on all files (README.md, CONTRIBUTING.md, bug_report.md, package.jso
17
7
  [![Conventional Commits][conventional-commits-src]][conventional-commits-href]
18
8
  [![License][license-src]][license-href]
19
9
 
20
- <!-- TODO: Replacing link to Prismic with [Prismic][prismic] is useful here -->
21
-
22
10
  > ⚠ &nbsp;This project is in an experimental state. Use it at your own risk or stay tuned for the official release!
23
11
 
24
- [Svelte][svelte] components and helpers to fetch and present [Prismic][prismic] content.
12
+ [Svelte][svelte] components to present [Prismic][prismic] content.
25
13
 
26
14
  - 📝 &nbsp;Display content from Prismic like [Rich Text][prismic-rich-text] and [Link][prismic-link] fields;
27
15
  - 🍡 &nbsp;Render Prismic [Slice Zones][prismic-slices] declaratively with Svelte components;
28
- - 🎣 &nbsp;Fetch Prismic content.
16
+
17
+ <!--
18
+
19
+ TODO: Create a small list of package features:
20
+
21
+ - 🤔 &nbsp;A useful feature;
22
+ - 🥴 &nbsp;Another useful feature;
23
+ - 🙃 &nbsp;A final useful feature.
24
+
25
+ Non-breaking space: &nbsp; are here on purpose to fix emoji rendering on certain systems.
26
+
27
+ -->
29
28
 
30
29
  ## Install
31
30
 
@@ -54,34 +53,34 @@ For more clarity on this project and its structure you can also check out the de
54
53
  ## License
55
54
 
56
55
  ```
57
- Copyright 2013-2022 Prismic <contact@prismic.io> (https://prismic.io)
56
+ Copyright 2013-2023 Prismic <contact@prismic.io> (https://prismic.io)
58
57
 
59
- Licensed under the Apache License, Version 2.0 (the "License");
60
- you may not use this file except in compliance with the License.
61
- You may obtain a copy of the License at
58
+ Licensed under the Apache License, Version 2.0 (the "License");
59
+ you may not use this file except in compliance with the License.
60
+ You may obtain a copy of the License at
62
61
 
63
- http://www.apache.org/licenses/LICENSE-2.0
62
+ http://www.apache.org/licenses/LICENSE-2.0
64
63
 
65
- Unless required by applicable law or agreed to in writing, software
66
- distributed under the License is distributed on an "AS IS" BASIS,
67
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68
- See the License for the specific language governing permissions and
69
- limitations under the License.
64
+ Unless required by applicable law or agreed to in writing, software
65
+ distributed under the License is distributed on an "AS IS" BASIS,
66
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67
+ See the License for the specific language governing permissions and
68
+ limitations under the License.
70
69
  ```
71
70
 
72
71
  <!-- Links -->
73
72
 
74
73
  [prismic]: https://prismic.io
74
+ [svelte]: https://svelte.dev
75
+ [prismic-rich-text]: https://prismic.io/docs/core-concepts/rich-text-title
76
+ [prismic-link]: https://prismic.io/docs/core-concepts/link-content-relationship
77
+ [prismic-slices]: https://prismic.io/docs/core-concepts/slices
75
78
 
76
79
  <!-- TODO: Replace link with a more useful one if available -->
77
80
 
78
- [prismic-docs]: https://prismic.io/docs/technical-reference/prismicio-svelte
81
+ [prismic-docs]: https://prismic.io/docs
79
82
  [changelog]: ./CHANGELOG.md
80
83
  [contributing]: ./CONTRIBUTING.md
81
- [svelte]: https://svelte.dev
82
- [prismic-rich-text]: https://prismic.io/docs/core-concepts/rich-text-title
83
- [prismic-link]: https://prismic.io/docs/core-concepts/link-content-relationship
84
- [prismic-slices]: https://prismic.io/docs/core-concepts/slices
85
84
 
86
85
  <!-- TODO: Replace link with a more useful one if available -->
87
86
 
@@ -100,7 +99,7 @@ For more clarity on this project and its structure you can also check out the de
100
99
  [github-actions-ci-href]: https://github.com/prismicio/prismic-svelte/actions?query=workflow%3Aci
101
100
  [codecov-src]: https://img.shields.io/codecov/c/github/prismicio/prismic-svelte.svg
102
101
  [codecov-href]: https://codecov.io/gh/prismicio/prismic-svelte
103
- [conventional-commits-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
102
+ [conventional-commits-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white
104
103
  [conventional-commits-href]: https://conventionalcommits.org
105
104
  [license-src]: https://img.shields.io/npm/l/@prismicio/svelte.svg
106
105
  [license-href]: https://npmjs.com/package/@prismicio/svelte
@@ -1,23 +1,24 @@
1
- <script>import * as prismicH from "@prismicio/helpers";
1
+ <script>import { isFilled } from "@prismicio/client";
2
2
  export let field;
3
3
  </script>
4
4
 
5
- <!--
5
+ <!--
6
6
  @component
7
- Component to render a Prismic Embed field.
8
-
9
- @example Rendering an Embed field:
7
+ Component to render a Prismic embed field.
8
+
9
+ @example Rendering an embed field:
10
10
  ```svelte
11
11
  <PrismicEmbed field={document.data.example_embed} />
12
- ```
12
+ ```
13
13
  -->
14
14
 
15
- {#if prismicH.isFilled.embed(field)}
15
+ {#if isFilled.embed(field)}
16
16
  <div
17
17
  data-oembed={field.embed_url}
18
18
  data-oembed-type={field.type}
19
19
  data-oembed-provider={field.provider_name}
20
20
  >
21
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
21
22
  {@html field.html}
22
23
  </div>
23
24
  {/if}
@@ -1,10 +1,10 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import type * as prismicT from "@prismicio/types";
1
+ import { SvelteComponent } from "svelte";
2
+ import type { EmbedField } from "@prismicio/client";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  /**
6
6
  * An Embed field from Prismic.
7
- */ field: prismicT.EmbedField;
7
+ */ field: EmbedField;
8
8
  };
9
9
  events: {
10
10
  [evt: string]: CustomEvent<any>;
@@ -15,13 +15,13 @@ export type PrismicEmbedProps = typeof __propDef.props;
15
15
  export type PrismicEmbedEvents = typeof __propDef.events;
16
16
  export type PrismicEmbedSlots = typeof __propDef.slots;
17
17
  /**
18
- * Component to render a Prismic Embed field.
18
+ * Component to render a Prismic embed field.
19
19
  *
20
- * @example Rendering an Embed field:
20
+ * @example Rendering an embed field:
21
21
  * ```svelte
22
22
  * <PrismicEmbed field={document.data.example_embed} />
23
- * ```
23
+ * ```
24
24
  */
25
- export default class PrismicEmbed extends SvelteComponentTyped<PrismicEmbedProps, PrismicEmbedEvents, PrismicEmbedSlots> {
25
+ export default class PrismicEmbed extends SvelteComponent<PrismicEmbedProps, PrismicEmbedEvents, PrismicEmbedSlots> {
26
26
  }
27
27
  export {};
@@ -1,89 +1,83 @@
1
- <script>import * as prismicH from "@prismicio/helpers";
2
- import { DEV } from "esm-env";
1
+ <script>import {
2
+ asImageWidthSrcSet,
3
+ asImagePixelDensitySrcSet,
4
+ isFilled
5
+ } from "@prismicio/client";
3
6
  export let field;
4
7
  export let imgixParams = {};
5
- export let widths = void 0;
6
- export let pixelDensities = void 0;
7
- export let width = void 0;
8
- export let height = void 0;
9
8
  export let alt = void 0;
10
9
  export let fallbackAlt = void 0;
11
- delete $$restProps.src;
12
- delete $$restProps.srcset;
13
- const castInt = (input) => {
14
- if (typeof input === "number" || typeof input === "undefined" || input === null) {
15
- return input;
16
- } else {
17
- const parsed = Number.parseInt(input);
18
- if (Number.isNaN(parsed)) {
19
- return void 0;
20
- } else {
21
- return parsed;
10
+ export let width = void 0;
11
+ export let height = void 0;
12
+ export let widths = void 0;
13
+ export let pixelDensities = void 0;
14
+ let src = void 0;
15
+ let srcset = void 0;
16
+ let resolvedWidth = void 0;
17
+ let resolvedHeight = void 0;
18
+ $: {
19
+ if (isFilled.imageThumbnail(field)) {
20
+ const castInt = (input) => {
21
+ if (typeof input === "number" || typeof input === "undefined" || input === null) {
22
+ return input;
23
+ } else {
24
+ const parsed = Number.parseInt(input);
25
+ if (Number.isNaN(parsed)) {
26
+ return void 0;
27
+ } else {
28
+ return parsed;
29
+ }
30
+ }
31
+ };
32
+ const ar = field.dimensions.width / field.dimensions.height;
33
+ const castedWidth = castInt(width);
34
+ const castedHeight = castInt(height);
35
+ resolvedWidth = castedWidth ?? field.dimensions.width;
36
+ resolvedHeight = castedHeight ?? field.dimensions.height;
37
+ if (castedWidth != null && castedHeight == null) {
38
+ resolvedHeight = castedWidth / ar;
39
+ } else if (castedWidth == null && castedHeight != null) {
40
+ resolvedWidth = castedHeight * ar;
41
+ }
42
+ if (widths || !pixelDensities) {
43
+ const res = asImageWidthSrcSet(field, {
44
+ ...imgixParams,
45
+ widths: widths === "defaults" ? void 0 : widths
46
+ });
47
+ src = res.src;
48
+ srcset = res.srcset;
49
+ } else if (pixelDensities) {
50
+ const res = asImagePixelDensitySrcSet(field, {
51
+ ...imgixParams,
52
+ pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
53
+ });
54
+ src = res.src;
55
+ srcset = res.srcset;
22
56
  }
23
- }
24
- };
25
- const ar = field.dimensions && field.dimensions.width / field.dimensions.height;
26
- const castedWidth = castInt(width);
27
- const castedHeight = castInt(height);
28
- let resolvedWidth = castedWidth ?? (field.dimensions && field.dimensions.width);
29
- let resolvedHeight = castedHeight ?? (field.dimensions && field.dimensions.height);
30
- if (ar && castedWidth != null && (castedHeight == null || typeof castedWidth !== "undefined")) {
31
- resolvedHeight = castedWidth / ar;
32
- } else if (ar && castedHeight != null && (castedWidth == null || typeof castedWidth !== "undefined")) {
33
- resolvedWidth = castedHeight * ar;
34
- }
35
- if (DEV) {
36
- if (widths && pixelDensities) {
37
- console.warn(
38
- `[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`
39
- );
40
- }
41
- if (typeof alt === "string" && alt !== "") {
42
- console.warn(
43
- `[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="".`
44
- );
45
- }
46
- if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
47
- console.warn(
48
- `[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="".`
49
- );
50
57
  }
51
58
  }
52
59
  </script>
53
60
 
54
61
  <!--
55
62
  @component
56
- Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
63
+ Component to render a Prismic image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
57
64
 
58
- @example Rendering an Image field:
65
+ @example Rendering an image field:
59
66
  ```svelte
60
67
  <PrismicImage
61
68
  field={document.data.example_image}
62
69
  imgixParams={{ sat: -100 }}
63
70
  />
64
- ```
71
+ ```
65
72
  -->
66
73
 
67
- {#if prismicH.isFilled.image(field)}
68
- {@const { src, srcset } =
69
- pixelDensities && !widths
70
- ? prismicH.asImagePixelDensitySrcSet(field, {
71
- pixelDensities:
72
- pixelDensities === "defaults" ? undefined : pixelDensities,
73
- ...imgixParams,
74
- })
75
- : prismicH.asImageWidthSrcSet(field, {
76
- widths: widths === "defaults" ? undefined : widths,
77
- ...imgixParams,
78
- })}
74
+ {#if isFilled.imageThumbnail(field)}
79
75
  <img
80
76
  {src}
81
77
  {srcset}
82
- alt={alt ?? field.alt ?? fallbackAlt}
83
- width={width || height ? resolvedWidth : field.dimensions.width}
84
- height={height || (width ? resolvedHeight : field.dimensions.height)}
78
+ alt={alt ?? (field.alt || fallbackAlt)}
79
+ width={resolvedWidth}
80
+ height={resolvedHeight}
85
81
  {...$$restProps}
86
82
  />
87
- {:else}
88
- <img alt={field.alt || ""} {...$$restProps} />
89
83
  {/if}