@prismicio/svelte 0.0.8-dev.2 → 0.0.10

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 (47) hide show
  1. package/dist/{components/PrismicEmbed.svelte → PrismicEmbed.svelte} +0 -3
  2. package/dist/PrismicImage.svelte +89 -0
  3. package/dist/{components/PrismicImage.svelte.d.ts → PrismicImage.svelte.d.ts} +10 -2
  4. package/dist/{components/PrismicLink.svelte → PrismicLink.svelte} +6 -5
  5. package/dist/{components/PrismicLink.svelte.d.ts → PrismicLink.svelte.d.ts} +18 -12
  6. package/dist/{components/PrismicRichText → PrismicRichText}/DefaultComponent.svelte +10 -2
  7. package/dist/{components/PrismicRichText → PrismicRichText}/DefaultComponent.svelte.d.ts +5 -2
  8. package/dist/PrismicRichText/PrismicRichText.svelte +23 -0
  9. package/dist/{components/PrismicRichText → PrismicRichText}/PrismicRichText.svelte.d.ts +6 -6
  10. package/dist/{components/PrismicRichText → PrismicRichText}/Serialize.svelte +5 -2
  11. package/dist/{components/PrismicText.svelte → PrismicText.svelte} +1 -7
  12. package/dist/SliceZone/SliceZone.svelte +29 -0
  13. package/dist/{components → SliceZone}/SliceZone.svelte.d.ts +2 -5
  14. package/dist/{components → SliceZone}/TodoSliceComponent.svelte +8 -5
  15. package/dist/{components → SliceZone}/TodoSliceComponent.svelte.d.ts +0 -1
  16. package/dist/index.d.ts +6 -1
  17. package/dist/index.js +6 -3
  18. package/dist/src/lib/{components/PrismicImage.svelte → PrismicImage.svelte} +21 -7
  19. package/dist/src/lib/{components/PrismicLink.svelte → PrismicLink.svelte} +12 -2
  20. package/dist/src/lib/{components/PrismicRichText → PrismicRichText}/DefaultComponent.svelte +15 -3
  21. package/dist/src/lib/{components/PrismicRichText → PrismicRichText}/PrismicRichText.svelte +10 -12
  22. package/dist/src/lib/{components/PrismicRichText → PrismicRichText}/Serialize.svelte +4 -1
  23. package/dist/src/lib/{components → SliceZone}/SliceZone.svelte +5 -10
  24. package/dist/src/lib/{components → SliceZone}/TodoSliceComponent.svelte +4 -3
  25. package/dist/src/lib/index.ts +6 -9
  26. package/dist/src/routes/+page.server.ts +5 -6
  27. package/dist/src/routes/+page.svelte +3 -2
  28. package/dist/src/routes/slices/RichText.svelte +12 -0
  29. package/package.json +4 -3
  30. package/dist/__PRODUCTION__.d.ts +0 -7
  31. package/dist/__PRODUCTION__.js +0 -11
  32. package/dist/components/PrismicImage.svelte +0 -90
  33. package/dist/components/PrismicRichText/PrismicRichText.svelte +0 -49
  34. package/dist/components/SliceZone.svelte +0 -59
  35. package/dist/components/index.d.ts +0 -6
  36. package/dist/components/index.js +0 -6
  37. package/dist/src/lib/__PRODUCTION__.ts +0 -12
  38. package/dist/src/lib/components/index.ts +0 -11
  39. package/dist/src/routes/components/index.js +0 -1
  40. package/dist/src/routes/slices/RichText/index.svelte +0 -9
  41. package/dist/src/routes/slices/index.ts +0 -2
  42. /package/dist/{components/PrismicEmbed.svelte.d.ts → PrismicEmbed.svelte.d.ts} +0 -0
  43. /package/dist/{components/PrismicRichText → PrismicRichText}/Serialize.svelte.d.ts +0 -0
  44. /package/dist/{components/PrismicText.svelte.d.ts → PrismicText.svelte.d.ts} +0 -0
  45. /package/dist/src/lib/{components/PrismicEmbed.svelte → PrismicEmbed.svelte} +0 -0
  46. /package/dist/src/lib/{components/PrismicText.svelte → PrismicText.svelte} +0 -0
  47. /package/dist/src/routes/slices/{CodeSnippet/index.svelte → CodeSnippet.svelte} +0 -0
@@ -1,7 +1,4 @@
1
1
  <script>import * as prismicH from "@prismicio/helpers";
2
- /**
3
- * An Embed field from Prismic.
4
- */
5
2
  export let field;
6
3
  </script>
7
4
 
@@ -0,0 +1,89 @@
1
+ <script>import * as prismicH from "@prismicio/helpers";
2
+ import { DEV } from "esm-env";
3
+ export let field;
4
+ 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
+ export let alt = void 0;
10
+ 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;
22
+ }
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
+ }
51
+ }
52
+ </script>
53
+
54
+ <!--
55
+ @component
56
+ Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
57
+
58
+ @example Rendering an Image field:
59
+ ```svelte
60
+ <PrismicImage
61
+ field={document.data.example_image}
62
+ imgixParams={{ sat: -100 }}
63
+ />
64
+ ```
65
+ -->
66
+
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
+ })}
79
+ <img
80
+ {src}
81
+ {srcset}
82
+ alt={alt ?? field.alt ?? fallbackAlt}
83
+ width={width || height ? resolvedWidth : field.dimensions.width}
84
+ height={height || (width ? resolvedHeight : field.dimensions.height)}
85
+ {...$$restProps}
86
+ />
87
+ {:else}
88
+ <img alt={field.alt || ""} {...$$restProps} />
89
+ {/if}
@@ -12,8 +12,6 @@ declare const __propDef: {
12
12
  loading?: "eager" | "lazy" | null | undefined;
13
13
  referrerpolicy?: ReferrerPolicy | null | undefined;
14
14
  sizes?: string | null | undefined;
15
- src?: string | null | undefined;
16
- srcset?: string | null | undefined;
17
15
  usemap?: string | null | undefined;
18
16
  'bind:naturalWidth'?: number | null | undefined;
19
17
  'bind:naturalHeight'?: number | null | undefined;
@@ -267,6 +265,16 @@ declare const __propDef: {
267
265
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
268
266
  */
269
267
  fallbackAlt?: "" | undefined;
268
+ /**
269
+ * PrismicImage will ignore any provided `src` property. The `src` property
270
+ * is generated based on the provided `field`.
271
+ */
272
+ src?: undefined;
273
+ /**
274
+ * PrismicImage will ignore any provided `srcset` property. The `srcset`
275
+ * property is generated based on the provided `field`.
276
+ */
277
+ srcset?: undefined;
270
278
  };
271
279
  events: {
272
280
  [evt: string]: CustomEvent<any>;
@@ -1,11 +1,12 @@
1
1
  <script>import * as prismicH from "@prismicio/helpers";
2
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);
3
+ export let linkResolver = void 0;
4
+ export let target = void 0;
5
+ const resolvedTarget = target || field && "target" in field && field.target || void 0;
6
+ export let rel = void 0;
7
+ const resolvedRel = rel || (target === "_blank" ? "noopener noreferrer" : void 0);
8
8
  const href = (field ? prismicH.asLink(field, linkResolver) : "") || "";
9
+ delete $$restProps.href;
9
10
  </script>
10
11
 
11
12
  <!--
@@ -3,17 +3,8 @@ import * as prismicH from "@prismicio/helpers";
3
3
  import type * as prismicT from "@prismicio/types";
4
4
  declare const __propDef: {
5
5
  props: {
6
- download?: any;
7
- href?: string | null | undefined;
8
- hreflang?: string | null | undefined;
9
- media?: string | null | undefined;
10
- ping?: string | null | undefined;
11
- rel?: string | null | undefined;
12
- target?: import("svelte/elements").HTMLAttributeAnchorTarget | null | undefined;
13
- type?: string | null | undefined;
6
+ prefix?: string | null | undefined;
14
7
  referrerpolicy?: ReferrerPolicy | null | undefined;
15
- 'sapper:noscroll'?: true | null | undefined;
16
- 'sapper:prefetch'?: true | null | undefined;
17
8
  accesskey?: string | null | undefined;
18
9
  autofocus?: boolean | null | undefined;
19
10
  class?: string | null | undefined;
@@ -39,7 +30,6 @@ declare const __propDef: {
39
30
  about?: string | null | undefined;
40
31
  datatype?: string | null | undefined;
41
32
  inlist?: any;
42
- prefix?: string | null | undefined;
43
33
  property?: string | null | undefined;
44
34
  resource?: string | null | undefined;
45
35
  typeof?: string | null | undefined;
@@ -222,8 +212,18 @@ declare const __propDef: {
222
212
  'on:close'?: import("svelte/elements").EventHandler<Event, HTMLAnchorElement> | null | undefined;
223
213
  'on:fullscreenchange'?: import("svelte/elements").EventHandler<Event, HTMLAnchorElement> | null | undefined;
224
214
  'on:fullscreenerror'?: import("svelte/elements").EventHandler<Event, HTMLAnchorElement> | null | undefined;
215
+ download?: any;
216
+ hreflang?: string | null | undefined;
217
+ media?: string | null | undefined;
218
+ ping?: string | null | undefined;
219
+ rel?: string | null | undefined;
220
+ target?: import("svelte/elements").HTMLAttributeAnchorTarget | null | undefined;
221
+ type?: string | null | undefined;
222
+ 'sapper:noscroll'?: true | null | undefined;
223
+ 'sapper:prefetch'?: true | null | undefined;
225
224
  /**
226
- * A Prismic Link field, Content Relationship field, Link to Media field or Document.
225
+ * A Prismic Link field, Content Relationship field, Link to Media field or
226
+ * Document.
227
227
  */
228
228
  field: prismicT.LinkField | prismicT.PrismicDocument;
229
229
  /**
@@ -235,6 +235,12 @@ declare const __propDef: {
235
235
  * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
236
236
  */
237
237
  linkResolver?: prismicH.LinkResolverFunction | undefined;
238
+ /**
239
+ * PrismicLink does not accept an `href` property. The `href` attribute is
240
+ * generated based on the field provided. If an `href` attribute is
241
+ * provided, it will be ignored.
242
+ */
243
+ href?: undefined;
238
244
  };
239
245
  events: {
240
246
  [evt: string]: CustomEvent<any>;
@@ -1,6 +1,14 @@
1
- <script>import { PrismicImage, PrismicEmbed, PrismicLink } from "..";
1
+ <script>import PrismicEmbed from "../PrismicEmbed.svelte";
2
+ import PrismicImage from "../PrismicImage.svelte";
3
+ import PrismicLink from "../PrismicLink.svelte";
2
4
  export let node;
3
- export let linkResolver = undefined;
5
+ export let key;
6
+ export let text;
7
+ export let type;
8
+ key;
9
+ text;
10
+ type;
11
+ export let linkResolver = void 0;
4
12
  </script>
5
13
 
6
14
  {#if node.type === "heading1"}
@@ -1,9 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { LinkResolverFunction } from "@prismicio/helpers";
3
- import type { RTAnyNode } from "@prismicio/types";
3
+ import type { TreeNode } from "@prismicio/richtext";
4
4
  declare const __propDef: {
5
5
  props: {
6
- node: RTAnyNode;
6
+ node: TreeNode["node"];
7
+ key: TreeNode["key"];
8
+ text: TreeNode["text"];
9
+ type: TreeNode["type"];
7
10
  linkResolver?: LinkResolverFunction | undefined;
8
11
  };
9
12
  events: {
@@ -0,0 +1,23 @@
1
+ <script>import {
2
+ asTree,
3
+ wrapMapSerializer
4
+ } from "@prismicio/richtext";
5
+ import Serialize from "./Serialize.svelte";
6
+ export let field = [];
7
+ export let linkResolver = void 0;
8
+ export let components = void 0;
9
+ let resolvedSerializer = typeof components === "object" ? wrapMapSerializer(components) : components;
10
+ const nodes = asTree(field).children;
11
+ </script>
12
+
13
+ <!--
14
+ @component
15
+ Component to render a Prismic Rich Text or Title field as HTML.
16
+
17
+ @example Rendering a Link field:
18
+ ```svelte
19
+ <PrismicRichText field={document.data.example_rich_text} />
20
+ ```
21
+ -->
22
+
23
+ <Serialize {nodes} serializer={resolvedSerializer} {linkResolver} />
@@ -16,21 +16,21 @@ declare const __propDef: {
16
16
  * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/route-resolver}
17
17
  */ linkResolver?: LinkResolverFunction | undefined;
18
18
  /**
19
- * An object that maps Rich Text blocks to functions.
19
+ * An object that maps Rich Text blocks to Svelte components.
20
20
  *
21
- * @example A serializer that modififes `h1` and `em` elements:
21
+ * **Important**: Your components must be wrapped in a function. For example:
22
+ * `{ heading1: () => Heading }`, not: `{ heading1: Heading }`.
23
+ *
24
+ * @example A serializer that modififes `h1` elements:
22
25
  *
23
26
  * ```js
24
27
  * import Title from "./Title.svelte";
25
28
  *
26
- * const field = exampleRichText;
27
- *
28
29
  * const richTextSerializer = {
29
30
  * h1: () => Title,
30
- * em: ({ children }) => `<mark>${children}</mark>`,
31
31
  * };
32
32
  * ```
33
- */ richTextSerializer?: RichTextMapSerializer<typeof SvelteComponent, TreeNode> | RichTextFunctionSerializer<typeof SvelteComponent, TreeNode> | undefined;
33
+ */ components?: RichTextMapSerializer<typeof SvelteComponent, TreeNode> | RichTextFunctionSerializer<typeof SvelteComponent, TreeNode> | undefined;
34
34
  };
35
35
  events: {
36
36
  [evt: string]: CustomEvent<any>;
@@ -1,7 +1,7 @@
1
1
  <script>import Default from "./DefaultComponent.svelte";
2
2
  export let serializer;
3
3
  export let nodes = [];
4
- export let linkResolver = undefined;
4
+ export let linkResolver = void 0;
5
5
  </script>
6
6
 
7
7
  {#each nodes as node}
@@ -9,7 +9,10 @@ export let linkResolver = undefined;
9
9
  this={(serializer &&
10
10
  serializer(node.type, node.node, node.text, node.children, node.key)) ||
11
11
  Default}
12
- {...node}
12
+ type={node.type}
13
+ node={node.node}
14
+ text={node.text}
15
+ key={node.key}
13
16
  {linkResolver}
14
17
  >
15
18
  {#if node.children.length > 0}
@@ -1,12 +1,6 @@
1
1
  <script>import * as prismicH from "@prismicio/helpers";
2
- /**
3
- * A Rich Text or Title field from Prismic.
4
- */
5
2
  export let field;
6
- /**
7
- * The separator used between blocks. Defaults to `\n`.
8
- */
9
- export let separator = undefined;
3
+ export let separator = void 0;
10
4
  </script>
11
5
 
12
6
  <!--
@@ -0,0 +1,29 @@
1
+ <script>import TodoSliceComponent from "./TodoSliceComponent.svelte";
2
+ export let slices = [];
3
+ export let components = {};
4
+ export let context = {};
5
+ export let defaultComponent = void 0;
6
+ </script>
7
+
8
+ <!--
9
+ @component
10
+ Component to render an array of Prismic Slices.
11
+
12
+ @example Rendering a Rich Text field:
13
+ ```svelte
14
+ <SliceZone slices={document.data.slices} components={{
15
+ block_quote: BlockQuote,
16
+ hero_image: HeroImage
17
+ }} />
18
+ ```
19
+ -->
20
+
21
+ {#each slices as slice, index}
22
+ {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
23
+ {@const Component = components[type] || defaultComponent}
24
+ {#if Component}
25
+ <svelte:component this={Component} {slice} {slices} {context} {index} />
26
+ {:else}
27
+ <TodoSliceComponent {slice} />
28
+ {/if}
29
+ {/each}
@@ -3,7 +3,8 @@ import type { SvelteComponent } from "svelte";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  /**
6
- * An array of Prismic Slices, such as the `slices` property from a Prismic document.
6
+ * An array of Prismic Slices, such as the `slices` property from a Prismic
7
+ * document.
7
8
  */ slices?: ({
8
9
  slice_type: string;
9
10
  } | {
@@ -31,10 +32,6 @@ declare const __propDef: {
31
32
  * The Svelte component rendered if a component mapping from the `components`
32
33
  * prop cannot be found.
33
34
  */ defaultComponent?: SvelteComponent | (new (...args: any[]) => SvelteComponent) | undefined;
34
- /**
35
- * Whether the app is in development mode. When true, the SliceZone may
36
- * display error messages in the UI.
37
- */ dev?: boolean | undefined;
38
35
  };
39
36
  events: {
40
37
  [evt: string]: CustomEvent<any>;
@@ -1,11 +1,14 @@
1
- <script>export let slice;
2
- export let dev = false;
1
+ <script>import { DEV } from "esm-env";
2
+ export let slice;
3
3
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
4
- if (dev)
5
- console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
4
+ if (DEV)
5
+ console.warn(
6
+ `[SliceZone] Could not find a component for Slice type "${type}"`,
7
+ slice
8
+ );
6
9
  </script>
7
10
 
8
- {#if dev}
11
+ {#if DEV}
9
12
  <section data-slice-zone-todo-component="" data-slice-type={type}>
10
13
  Could not find a component for Slice type &ldquo;{type}&rdquo;
11
14
  </section>
@@ -6,7 +6,6 @@ declare const __propDef: {
6
6
  } | {
7
7
  type: string;
8
8
  };
9
- dev?: boolean | undefined;
10
9
  };
11
10
  events: {
12
11
  [evt: string]: CustomEvent<any>;
package/dist/index.d.ts CHANGED
@@ -1 +1,6 @@
1
- export { PrismicEmbed, PrismicImage, PrismicLink, PrismicText, PrismicRichText, SliceZone, } from "./components";
1
+ export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
+ export { default as PrismicImage } from "./PrismicImage.svelte";
3
+ export { default as PrismicLink } from "./PrismicLink.svelte";
4
+ export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
5
+ export { default as PrismicText } from "./PrismicText.svelte";
6
+ export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
- export {
2
- // Components
3
- PrismicEmbed, PrismicImage, PrismicLink, PrismicText, PrismicRichText, SliceZone, } from "./components";
1
+ export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
+ export { default as PrismicImage } from "./PrismicImage.svelte";
3
+ export { default as PrismicLink } from "./PrismicLink.svelte";
4
+ export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
5
+ export { default as PrismicText } from "./PrismicText.svelte";
6
+ export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
@@ -2,7 +2,7 @@
2
2
  import * as prismicH from "@prismicio/helpers";
3
3
  import type * as prismicT from "@prismicio/types";
4
4
  import type { HTMLImgAttributes } from "svelte/elements";
5
- import { __PRODUCTION__ } from "$lib/__PRODUCTION__";
5
+ import { DEV } from "esm-env";
6
6
 
7
7
  type PrismicImageProps = {
8
8
  /**
@@ -54,9 +54,20 @@
54
54
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
55
55
  */
56
56
  fallbackAlt?: "";
57
+ /**
58
+ * PrismicImage will ignore any provided `src` property. The `src` property
59
+ * is generated based on the provided `field`.
60
+ */
61
+ src?: undefined;
62
+ /**
63
+ * PrismicImage will ignore any provided `srcset` property. The `srcset`
64
+ * property is generated based on the provided `field`.
65
+ */
66
+ srcset?: undefined;
57
67
  };
58
68
 
59
- type $$Props = Omit<HTMLImgAttributes, "alt"> & PrismicImageProps;
69
+ type $$Props = Omit<HTMLImgAttributes, "alt" | "src" | "srcset"> &
70
+ PrismicImageProps;
60
71
 
61
72
  export let field: $$Props["field"];
62
73
 
@@ -74,6 +85,9 @@
74
85
 
75
86
  export let fallbackAlt: $$Props["fallbackAlt"] = undefined;
76
87
 
88
+ delete $$restProps.src;
89
+ delete $$restProps.srcset;
90
+
77
91
  const castInt = (
78
92
  input: string | number | null | undefined,
79
93
  ): number | undefined | null => {
@@ -119,7 +133,7 @@
119
133
  resolvedWidth = castedHeight * ar;
120
134
  }
121
135
 
122
- if (!__PRODUCTION__) {
136
+ if (DEV) {
123
137
  if (widths && pixelDensities) {
124
138
  console.warn(
125
139
  `[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.`,
@@ -140,14 +154,14 @@
140
154
  }
141
155
  </script>
142
156
 
143
- <!--
157
+ <!--
144
158
  @component
145
159
  Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
146
-
160
+
147
161
  @example Rendering an Image field:
148
162
  ```svelte
149
- <PrismicImage
150
- field={document.data.example_image}
163
+ <PrismicImage
164
+ field={document.data.example_image}
151
165
  imgixParams={{ sat: -100 }}
152
166
  />
153
167
  ```
@@ -6,7 +6,8 @@
6
6
 
7
7
  type PrismicLinkProps = {
8
8
  /**
9
- * A Prismic Link field, Content Relationship field, Link to Media field or Document.
9
+ * A Prismic Link field, Content Relationship field, Link to Media field or
10
+ * Document.
10
11
  */
11
12
  field: prismicT.LinkField | prismicT.PrismicDocument;
12
13
 
@@ -19,9 +20,16 @@
19
20
  * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
20
21
  */
21
22
  linkResolver?: prismicH.LinkResolverFunction | undefined;
23
+
24
+ /**
25
+ * PrismicLink does not accept an `href` property. The `href` attribute is
26
+ * generated based on the field provided. If an `href` attribute is
27
+ * provided, it will be ignored.
28
+ */
29
+ href?: undefined;
22
30
  };
23
31
 
24
- type $$Props = HTMLAnchorAttributes & PrismicLinkProps;
32
+ type $$Props = Omit<HTMLAnchorAttributes, "href"> & PrismicLinkProps;
25
33
 
26
34
  export let field: $$Props["field"];
27
35
  export let linkResolver: $$Props["linkResolver"] = undefined;
@@ -35,6 +43,8 @@
35
43
  rel || (target === "_blank" ? "noopener noreferrer" : undefined);
36
44
 
37
45
  const href = (field ? prismicH.asLink(field, linkResolver) : "") || "";
46
+
47
+ delete $$restProps.href;
38
48
  </script>
39
49
 
40
50
  <!--
@@ -1,9 +1,21 @@
1
1
  <script lang="ts">
2
- import { PrismicImage, PrismicEmbed, PrismicLink } from "$lib/components";
3
2
  import type { LinkResolverFunction } from "@prismicio/helpers";
4
- import type { RTAnyNode } from "@prismicio/types";
3
+ import type { TreeNode } from "@prismicio/richtext";
5
4
 
6
- export let node: RTAnyNode;
5
+ import PrismicEmbed from "../PrismicEmbed.svelte";
6
+ import PrismicImage from "../PrismicImage.svelte";
7
+ import PrismicLink from "../PrismicLink.svelte";
8
+
9
+ export let node: TreeNode["node"];
10
+ export let key: TreeNode["key"];
11
+ export let text: TreeNode["text"];
12
+ export let type: TreeNode["type"];
13
+
14
+ // These variables are not used in the component, but we need to
15
+ // superficially use them to supress development warnings.
16
+ key;
17
+ text;
18
+ type;
7
19
 
8
20
  export let linkResolver: LinkResolverFunction | undefined = undefined;
9
21
  </script>
@@ -28,38 +28,36 @@
28
28
  export let linkResolver: LinkResolverFunction | undefined = undefined;
29
29
 
30
30
  /**
31
- * An object that maps Rich Text blocks to functions.
31
+ * An object that maps Rich Text blocks to Svelte components.
32
32
  *
33
- * @example A serializer that modififes `h1` and `em` elements:
33
+ * **Important**: Your components must be wrapped in a function. For example:
34
+ * `{ heading1: () => Heading }`, not: `{ heading1: Heading }`.
35
+ *
36
+ * @example A serializer that modififes `h1` elements:
34
37
  *
35
38
  * ```js
36
39
  * import Title from "./Title.svelte";
37
40
  *
38
- * const field = exampleRichText;
39
- *
40
41
  * const richTextSerializer = {
41
42
  * h1: () => Title,
42
- * em: ({ children }) => `<mark>${children}</mark>`,
43
43
  * };
44
44
  * ```
45
45
  */
46
- export let richTextSerializer:
46
+ export let components:
47
47
  | RichTextMapSerializer<typeof SvelteComponent, TreeNode>
48
48
  | RichTextFunctionSerializer<typeof SvelteComponent, TreeNode>
49
49
  | undefined = undefined;
50
50
 
51
- const resolvedSerializer =
52
- typeof richTextSerializer === "object"
53
- ? wrapMapSerializer(richTextSerializer)
54
- : richTextSerializer;
51
+ let resolvedSerializer =
52
+ typeof components === "object" ? wrapMapSerializer(components) : components;
55
53
 
56
54
  const nodes = asTree(field).children;
57
55
  </script>
58
56
 
59
- <!--
57
+ <!--
60
58
  @component
61
59
  Component to render a Prismic Rich Text or Title field as HTML.
62
-
60
+
63
61
  @example Rendering a Link field:
64
62
  ```svelte
65
63
  <PrismicRichText field={document.data.example_rich_text} />
@@ -20,7 +20,10 @@
20
20
  this={(serializer &&
21
21
  serializer(node.type, node.node, node.text, node.children, node.key)) ||
22
22
  Default}
23
- {...node}
23
+ type={node.type}
24
+ node={node.node}
25
+ text={node.text}
26
+ key={node.key}
24
27
  {linkResolver}
25
28
  >
26
29
  {#if node.children.length > 0}
@@ -46,7 +46,8 @@
46
46
  | SliceLikeGraphQL<SliceType>;
47
47
 
48
48
  /**
49
- * An array of Prismic Slices, such as the `slices` property from a Prismic document.
49
+ * An array of Prismic Slices, such as the `slices` property from a Prismic
50
+ * document.
50
51
  */
51
52
  export let slices: SliceLike[] = [];
52
53
 
@@ -80,18 +81,12 @@
80
81
  | SvelteComponent
81
82
  | (new (...args: any[]) => SvelteComponent)
82
83
  | undefined = undefined;
83
-
84
- /**
85
- * Whether the app is in development mode. When true, the SliceZone may
86
- * display error messages in the UI.
87
- */
88
- export let dev: boolean = false;
89
84
  </script>
90
85
 
91
- <!--
86
+ <!--
92
87
  @component
93
88
  Component to render an array of Prismic Slices.
94
-
89
+
95
90
  @example Rendering a Rich Text field:
96
91
  ```svelte
97
92
  <SliceZone slices={document.data.slices} components={{
@@ -107,6 +102,6 @@
107
102
  {#if Component}
108
103
  <svelte:component this={Component} {slice} {slices} {context} {index} />
109
104
  {:else}
110
- <TodoSliceComponent {slice} {dev} />
105
+ <TodoSliceComponent {slice} />
111
106
  {/if}
112
107
  {/each}
@@ -1,17 +1,18 @@
1
1
  <script lang="ts">
2
+ import { DEV } from "esm-env";
3
+
2
4
  export let slice: { slice_type: string } | { type: string };
3
- export let dev: boolean = false;
4
5
 
5
6
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
6
7
 
7
- if (dev)
8
+ if (DEV)
8
9
  console.warn(
9
10
  `[SliceZone] Could not find a component for Slice type "${type}"`,
10
11
  slice,
11
12
  );
12
13
  </script>
13
14
 
14
- {#if dev}
15
+ {#if DEV}
15
16
  <section data-slice-zone-todo-component="" data-slice-type={type}>
16
17
  Could not find a component for Slice type &ldquo;{type}&rdquo;
17
18
  </section>
@@ -1,9 +1,6 @@
1
- export {
2
- // Components
3
- PrismicEmbed,
4
- PrismicImage,
5
- PrismicLink,
6
- PrismicText,
7
- PrismicRichText,
8
- SliceZone,
9
- } from "./components";
1
+ export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
+ export { default as PrismicImage } from "./PrismicImage.svelte";
3
+ export { default as PrismicLink } from "./PrismicLink.svelte";
4
+ export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
5
+ export { default as PrismicText } from "./PrismicText.svelte";
6
+ export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
@@ -1,5 +1,5 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import type { PageDocument } from "../types/PageDocument.type"
2
+ import type { PageDocument } from "../types/PageDocument.type";
3
3
  import type { PageServerLoad } from "./$types";
4
4
 
5
5
  export const load = (async ({ fetch }) => {
@@ -8,13 +8,12 @@ export const load = (async ({ fetch }) => {
8
8
 
9
9
  const pageDocument: PageDocument = await client.getSingle("homepage");
10
10
 
11
- const exampleClient = prismic.createClient("example-prismic-repo", { fetch })
12
- const exampleDocument = exampleClient.getFirst({ page: 11, pageSize: 1})
13
-
11
+ const exampleClient = prismic.createClient("example-prismic-repo", { fetch });
12
+ const exampleDocument = exampleClient.getFirst({ page: 11, pageSize: 1 });
14
13
 
15
14
  return {
16
15
  pageDocument,
17
- exampleDocument
16
+ exampleDocument,
18
17
  };
19
- // eslint-disable-next-line prettier/prettier
18
+ // eslint-disable-next-line prettier/prettier
20
19
  }) satisfies PageServerLoad;
@@ -7,10 +7,11 @@
7
7
  PrismicText,
8
8
  PrismicEmbed,
9
9
  } from "$lib";
10
- import { RichText, CodeSnippet } from "./slices";
11
10
 
12
11
  import type { PageData } from "./$types";
13
- import { page } from "$app/stores";
12
+
13
+ import CodeSnippet from "./slices/CodeSnippet.svelte";
14
+ import RichText from "./slices/RichText.svelte";
14
15
 
15
16
  const components = {
16
17
  rich_text: RichText,
@@ -0,0 +1,12 @@
1
+ <script lang="ts">
2
+ import { PrismicRichText } from "$lib";
3
+ import type { RichTextSlice } from "../../types";
4
+ import Emphasis from "../components/Emphasis.svelte";
5
+
6
+ export let slice: RichTextSlice;
7
+ </script>
8
+
9
+ <PrismicRichText
10
+ field={slice.primary.content}
11
+ components={{ em: () => Emphasis }}
12
+ />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/svelte",
3
- "version": "0.0.8-dev.2",
3
+ "version": "0.0.10",
4
4
  "description": "Svelte plugin, components, and composables to fetch and present Prismic content",
5
5
  "keywords": [
6
6
  "typescript",
@@ -31,7 +31,7 @@
31
31
  "build": "svelte-package -o dist package && shx cp -r src dist/src",
32
32
  "dev": "vite dev",
33
33
  "format": "prettier --write .",
34
- "prepare": "npm run build",
34
+ "prepare": "npm run build && svelte-kit sync",
35
35
  "release": "npm run build && npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
36
36
  "release:dry": "standard-version --dry-run",
37
37
  "release:alpha": "npm run build && npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
@@ -58,6 +58,7 @@
58
58
  "@prismicio/mock": "^0.2.0",
59
59
  "@prismicio/types": "^0.2.7",
60
60
  "@rollup/plugin-inject": "^5.0.3",
61
+ "@sveltejs/adapter-auto": "^2.0.0",
61
62
  "@sveltejs/package": "^2.0.0",
62
63
  "@typescript-eslint/eslint-plugin": "^5.53.0",
63
64
  "@typescript-eslint/parser": "^5.53.0",
@@ -81,7 +82,7 @@
81
82
  "vitest": "^0.28.5"
82
83
  },
83
84
  "engines": {
84
- "node": ">=12.7.0"
85
+ "node": ">=16.14.2"
85
86
  },
86
87
  "publishConfig": {
87
88
  "access": "public"
@@ -1,7 +0,0 @@
1
- /**
2
- * `true` if in the production environment, `false` otherwise.
3
- *
4
- * This boolean can be used to perform actions only in development environments,
5
- * such as logging.
6
- */
7
- export declare const __PRODUCTION__: boolean;
@@ -1,11 +0,0 @@
1
- // We need to polyfill process if it doesn't exist, such as in the browser.
2
- if (typeof process === "undefined") {
3
- globalThis.process = { env: {} };
4
- }
5
- /**
6
- * `true` if in the production environment, `false` otherwise.
7
- *
8
- * This boolean can be used to perform actions only in development environments,
9
- * such as logging.
10
- */
11
- export const __PRODUCTION__ = process.env.NODE_ENV === "production";
@@ -1,90 +0,0 @@
1
- <script>import * as prismicH from "@prismicio/helpers";
2
- import { __PRODUCTION__ } from "../__PRODUCTION__";
3
- export let field;
4
- export let imgixParams = {};
5
- export let widths = undefined;
6
- export let pixelDensities = undefined;
7
- export let width = undefined;
8
- export let height = undefined;
9
- export let alt = undefined;
10
- export let fallbackAlt = undefined;
11
- const castInt = (input) => {
12
- if (typeof input === "number" ||
13
- typeof input === "undefined" ||
14
- input === null) {
15
- return input;
16
- }
17
- else {
18
- const parsed = Number.parseInt(input);
19
- if (Number.isNaN(parsed)) {
20
- return undefined;
21
- }
22
- else {
23
- return parsed;
24
- }
25
- }
26
- };
27
- const ar = field.dimensions && field.dimensions.width / field.dimensions.height;
28
- const castedWidth = castInt(width);
29
- const castedHeight = castInt(height);
30
- let resolvedWidth = castedWidth ?? (field.dimensions && field.dimensions.width);
31
- let resolvedHeight = castedHeight ?? (field.dimensions && field.dimensions.height);
32
- if (ar &&
33
- castedWidth != null &&
34
- (castedHeight == null || typeof castedWidth !== "undefined")) {
35
- resolvedHeight = castedWidth / ar;
36
- }
37
- else if (ar &&
38
- castedHeight != null &&
39
- (castedWidth == null || typeof castedWidth !== "undefined")) {
40
- resolvedWidth = castedHeight * ar;
41
- }
42
- if (!__PRODUCTION__) {
43
- if (widths && pixelDensities) {
44
- console.warn(`[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.`);
45
- }
46
- if (typeof alt === "string" && alt !== "") {
47
- console.warn(`[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="".`);
48
- }
49
- if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
50
- console.warn(`[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="".`);
51
- }
52
- }
53
- </script>
54
-
55
- <!--
56
- @component
57
- Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
58
-
59
- @example Rendering an Image field:
60
- ```svelte
61
- <PrismicImage
62
- field={document.data.example_image}
63
- imgixParams={{ sat: -100 }}
64
- />
65
- ```
66
- -->
67
-
68
- {#if prismicH.isFilled.image(field)}
69
- {@const { src, srcset } =
70
- pixelDensities && !widths
71
- ? prismicH.asImagePixelDensitySrcSet(field, {
72
- pixelDensities:
73
- pixelDensities === "defaults" ? undefined : pixelDensities,
74
- ...imgixParams,
75
- })
76
- : prismicH.asImageWidthSrcSet(field, {
77
- widths: widths === "defaults" ? undefined : widths,
78
- ...imgixParams,
79
- })}
80
- <img
81
- {src}
82
- {srcset}
83
- alt={alt ?? field.alt ?? fallbackAlt}
84
- width={width || height ? resolvedWidth : field.dimensions.width}
85
- height={height || (width ? resolvedHeight : field.dimensions.height)}
86
- {...$$restProps}
87
- />
88
- {:else}
89
- <img alt={field.alt || ""} {...$$restProps} />
90
- {/if}
@@ -1,49 +0,0 @@
1
- <script>import { asTree, wrapMapSerializer, } from "@prismicio/richtext";
2
- import Serialize from "./Serialize.svelte";
3
- /**
4
- * The Prismic Rich Text field to render.
5
- */
6
- export let field = [];
7
- /**
8
- * The Link Resolver used to resolve links.
9
- *
10
- * @remarks
11
- * If your app uses Route Resolvers when querying for your Prismic
12
- * repository's content, a Link Resolver does not need to be provided.
13
- * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/route-resolver}
14
- */
15
- export let linkResolver = undefined;
16
- /**
17
- * An object that maps Rich Text blocks to functions.
18
- *
19
- * @example A serializer that modififes `h1` and `em` elements:
20
- *
21
- * ```js
22
- * import Title from "./Title.svelte";
23
- *
24
- * const field = exampleRichText;
25
- *
26
- * const richTextSerializer = {
27
- * h1: () => Title,
28
- * em: ({ children }) => `<mark>${children}</mark>`,
29
- * };
30
- * ```
31
- */
32
- export let richTextSerializer = undefined;
33
- const resolvedSerializer = typeof richTextSerializer === "object"
34
- ? wrapMapSerializer(richTextSerializer)
35
- : richTextSerializer;
36
- const nodes = asTree(field).children;
37
- </script>
38
-
39
- <!--
40
- @component
41
- Component to render a Prismic Rich Text or Title field as HTML.
42
-
43
- @example Rendering a Link field:
44
- ```svelte
45
- <PrismicRichText field={document.data.example_rich_text} />
46
- ```
47
- -->
48
-
49
- <Serialize {nodes} serializer={resolvedSerializer} {linkResolver} />
@@ -1,59 +0,0 @@
1
- <script>import TodoSliceComponent from "./TodoSliceComponent.svelte";
2
- /**
3
- * An array of Prismic Slices, such as the `slices` property from a Prismic document.
4
- */
5
- export let slices = [];
6
- /**
7
- * An object that maps Slice components to their corresponding API IDs
8
- *
9
- * @example An example map:
10
- *
11
- * ```js
12
- * import BlockQuote from "./BlockQuote.svelte";
13
- * import HeroImage from "./HeroImage.svelte";
14
- *
15
- * const components = {
16
- * block_quote: BlockQuote,
17
- * hero_image: HeroImage,
18
- * };
19
- * ```
20
- */
21
- export let components = {};
22
- /**
23
- * Arbitrary data passed to all Slice components as a `context` prop.
24
- */
25
- export let context = {};
26
- /**
27
- * The Svelte component rendered if a component mapping from the `components`
28
- * prop cannot be found.
29
- */
30
- export let defaultComponent = undefined;
31
- /**
32
- * Whether the app is in development mode. When true, the SliceZone may
33
- * display error messages in the UI.
34
- */
35
- export let dev = false;
36
- </script>
37
-
38
- <!--
39
- @component
40
- Component to render an array of Prismic Slices.
41
-
42
- @example Rendering a Rich Text field:
43
- ```svelte
44
- <SliceZone slices={document.data.slices} components={{
45
- block_quote: BlockQuote,
46
- hero_image: HeroImage
47
- }} />
48
- ```
49
- -->
50
-
51
- {#each slices as slice, index}
52
- {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
53
- {@const Component = components[type] || defaultComponent}
54
- {#if Component}
55
- <svelte:component this={Component} {slice} {slices} {context} {index} />
56
- {:else}
57
- <TodoSliceComponent {slice} {dev} />
58
- {/if}
59
- {/each}
@@ -1,6 +0,0 @@
1
- export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
- export { default as PrismicImage } from "./PrismicImage.svelte";
3
- export { default as PrismicLink } from "./PrismicLink.svelte";
4
- export { default as PrismicText } from "./PrismicText.svelte";
5
- export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
6
- export { default as SliceZone } from "./SliceZone.svelte";
@@ -1,6 +0,0 @@
1
- export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
- export { default as PrismicImage } from "./PrismicImage.svelte";
3
- export { default as PrismicLink } from "./PrismicLink.svelte";
4
- export { default as PrismicText } from "./PrismicText.svelte";
5
- export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
6
- export { default as SliceZone } from "./SliceZone.svelte";
@@ -1,12 +0,0 @@
1
- // We need to polyfill process if it doesn't exist, such as in the browser.
2
- if (typeof process === "undefined") {
3
- globalThis.process = { env: {} } as typeof process;
4
- }
5
-
6
- /**
7
- * `true` if in the production environment, `false` otherwise.
8
- *
9
- * This boolean can be used to perform actions only in development environments,
10
- * such as logging.
11
- */
12
- export const __PRODUCTION__ = process.env.NODE_ENV === "production";
@@ -1,11 +0,0 @@
1
- export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
-
3
- export { default as PrismicImage } from "./PrismicImage.svelte";
4
-
5
- export { default as PrismicLink } from "./PrismicLink.svelte";
6
-
7
- export { default as PrismicText } from "./PrismicText.svelte";
8
-
9
- export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
10
-
11
- export { default as SliceZone } from "./SliceZone.svelte";
@@ -1 +0,0 @@
1
- export { default as Em } from "./Emphasis.svelte";
@@ -1,9 +0,0 @@
1
- <script lang="ts">
2
- import type { RichTextSlice } from "./../../../types/RichTextSlice.type";
3
- import PrismicRichText from "$lib/components/PrismicRichText/PrismicRichText.svelte";
4
- import Emphasis from "./../../components/Emphasis.svelte";
5
-
6
- export let slice: RichTextSlice;
7
- </script>
8
-
9
- <PrismicRichText field={slice.primary.content} components={{ em: Emphasis }} />
@@ -1,2 +0,0 @@
1
- export { default as CodeSnippet } from "./CodeSnippet/index.svelte";
2
- export { default as RichText } from "./RichText/index.svelte";