@prismicio/vue
Advanced tools
Comparing version 4.3.0 to 4.3.1
export { PrismicEmbedImpl, PrismicEmbed } from "./PrismicEmbed"; | ||
export type { PrismicEmbedProps } from "./PrismicEmbed"; | ||
export { usePrismicImage, PrismicImageImpl, PrismicImage, } from "./PrismicImage"; | ||
export { usePrismicImage, PrismicImageImpl, PrismicImage } from "./PrismicImage"; | ||
export type { UsePrismicImageOptions, PrismicImageProps } from "./PrismicImage"; | ||
@@ -5,0 +5,0 @@ export { usePrismicLink, PrismicLinkImpl, PrismicLink } from "./PrismicLink"; |
@@ -1,3 +0,3 @@ | ||
import { EmbedField } from "@prismicio/client"; | ||
import { AllowedComponentProps, ComponentCustomProps, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import type { EmbedField } from "@prismicio/client"; | ||
import type { AllowedComponentProps, ComponentCustomProps, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
/** | ||
@@ -24,3 +24,3 @@ * Props for `<PrismicEmbed />`. | ||
*/ | ||
export declare const PrismicEmbedImpl: DefineComponent<{ | ||
export declare const PrismicEmbedImpl: DefineComponent<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -35,5 +35,5 @@ type: PropType<EmbedField>; | ||
}; | ||
}, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
}>, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}>), unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
}>), {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -48,5 +48,5 @@ type: PropType<EmbedField>; | ||
}; | ||
}>>, { | ||
}>> & Readonly<{}>, { | ||
wrapper: string | ConcreteComponent | Raw<DefineComponent>; | ||
}, {}>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>; | ||
/** | ||
@@ -53,0 +53,0 @@ * Component to render a Prismic embed field. |
@@ -1,4 +0,5 @@ | ||
import { ImageField, asImagePixelDensitySrcSet, asImageSrc, asImageWidthSrcSet } from "@prismicio/client"; | ||
import { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import { VueUseOptions } from "../types"; | ||
import type { ImageField } from "@prismicio/client"; | ||
import { asImagePixelDensitySrcSet, asImageSrc, asImageWidthSrcSet } from "@prismicio/client"; | ||
import type { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import type { VueUseOptions } from "../types"; | ||
/** | ||
@@ -20,2 +21,3 @@ * Props for `<PrismicImage />`. | ||
* receive an additional `copyright` props. | ||
* | ||
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"img"` otherwise. | ||
@@ -96,3 +98,3 @@ */ | ||
*/ | ||
export declare const PrismicImageImpl: DefineComponent<{ | ||
export declare const PrismicImageImpl: DefineComponent<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -122,5 +124,5 @@ type: PropType<ImageField | ImageField<string>>; | ||
}; | ||
}, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
}>, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}>), unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
}>), {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -150,3 +152,3 @@ type: PropType<ImageField | ImageField<string>>; | ||
}; | ||
}>>, { | ||
}>> & Readonly<{}>, { | ||
widths: number[] | "thumbnails" | "defaults" | undefined; | ||
@@ -156,3 +158,3 @@ pixelDensities: number[] | "defaults" | undefined; | ||
imgixParams: import("imgix-url-builder/*").ImgixURLParams | undefined; | ||
}, {}>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>; | ||
/** | ||
@@ -159,0 +161,0 @@ * Component to render a Prismic image field. |
@@ -1,4 +0,4 @@ | ||
import { LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client"; | ||
import { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import { VueUseOptions } from "../types"; | ||
import type { LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client"; | ||
import type { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import type { VueUseOptions } from "../types"; | ||
/** | ||
@@ -46,2 +46,3 @@ * Props for `<PrismicLink />`. | ||
* (`to` props). | ||
* | ||
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise. | ||
@@ -60,2 +61,3 @@ */ | ||
* (`to` props). | ||
* | ||
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise. | ||
@@ -108,3 +110,3 @@ */ | ||
*/ | ||
export declare const PrismicLinkImpl: DefineComponent<{ | ||
export declare const PrismicLinkImpl: DefineComponent<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -144,5 +146,5 @@ type: PropType<LinkField | PrismicDocument>; | ||
}; | ||
}, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
}>, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}>), unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
}>), {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -182,3 +184,3 @@ type: PropType<LinkField | PrismicDocument>; | ||
}; | ||
}>>, { | ||
}>> & Readonly<{}>, { | ||
target: string | null; | ||
@@ -190,3 +192,3 @@ linkResolver: LinkResolverFunction; | ||
externalComponent: string | ConcreteComponent | Raw<DefineComponent>; | ||
}, {}>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>; | ||
/** | ||
@@ -193,0 +195,0 @@ * Component to render a Prismic link field. |
@@ -1,4 +0,4 @@ | ||
import { HTMLFunctionSerializer, HTMLMapSerializer, LinkResolverFunction, RichTextField } from "@prismicio/client"; | ||
import { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import { VueUseOptions } from "../types"; | ||
import type { HTMLFunctionSerializer, HTMLMapSerializer, LinkResolverFunction, RichTextField } from "@prismicio/client"; | ||
import type { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNodeProps } from "vue"; | ||
import type { VueUseOptions } from "../types"; | ||
/** | ||
@@ -79,3 +79,3 @@ * Props for `<PrismicRichText />`. | ||
*/ | ||
export declare const PrismicRichTextImpl: DefineComponent<{ | ||
export declare const PrismicRichTextImpl: DefineComponent<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -111,5 +111,5 @@ type: PropType<RichTextField | null | undefined>; | ||
}; | ||
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -145,3 +145,3 @@ type: PropType<RichTextField | null | undefined>; | ||
}; | ||
}>>, { | ||
}>> & Readonly<{}>, { | ||
wrapper: string | ConcreteComponent | Raw<DefineComponent>; | ||
@@ -153,3 +153,3 @@ field: RichTextField | null | undefined; | ||
htmlSerializer: import("@prismicio/client").HTMLRichTextFunctionSerializer | import("@prismicio/client").HTMLRichTextMapSerializer; | ||
}, {}>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>; | ||
/** | ||
@@ -156,0 +156,0 @@ * Component to render a Prismic rich text field as HTML. |
@@ -1,4 +0,4 @@ | ||
import { RichTextField } from "@prismicio/client"; | ||
import { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNode, VNodeProps } from "vue"; | ||
import { VueUseOptions } from "../types"; | ||
import type { RichTextField } from "@prismicio/client"; | ||
import type { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, DefineComponent, PropType, Raw, VNode, VNodeProps } from "vue"; | ||
import type { VueUseOptions } from "../types"; | ||
/** | ||
@@ -59,3 +59,3 @@ * Props for `<PrismicText />`. | ||
*/ | ||
export declare const PrismicTextImpl: DefineComponent<{ | ||
export declare const PrismicTextImpl: DefineComponent<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -81,5 +81,5 @@ type: PropType<RichTextField | null | undefined>; | ||
}; | ||
}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
}>, () => VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
field: { | ||
@@ -105,3 +105,3 @@ type: PropType<RichTextField | null | undefined>; | ||
}; | ||
}>>, { | ||
}>> & Readonly<{}>, { | ||
wrapper: string | ConcreteComponent | Raw<DefineComponent>; | ||
@@ -111,3 +111,3 @@ field: RichTextField | null | undefined; | ||
fallback: string; | ||
}, {}>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>; | ||
/** | ||
@@ -114,0 +114,0 @@ * Component to render a Prismic rich text field as plain text. |
@@ -1,3 +0,3 @@ | ||
import { Slice } from "@prismicio/client"; | ||
import { AllowedComponentProps, ComponentCustomProps, ConcreteComponent, DefineComponent, FunctionalComponent, PropType, Raw, VNodeProps, defineAsyncComponent } from "vue"; | ||
import type { Slice } from "@prismicio/client"; | ||
import type { AllowedComponentProps, ComponentCustomProps, ConcreteComponent, DefineComponent, FunctionalComponent, PropType, Raw, VNodeProps, defineAsyncComponent } from "vue"; | ||
/** | ||
@@ -119,7 +119,7 @@ * Returns the type of a `SliceLike` type. | ||
* // Defining a new slice component | ||
* import { getSliceComponentProps } from "@prismicio/vue"; | ||
* import { getSliceComponentProps } from "@prismicio/vue" | ||
* | ||
* export default { | ||
* props: getSliceComponentProps(), | ||
* }; | ||
* } | ||
* ``` | ||
@@ -131,7 +131,7 @@ * | ||
* // Defining a new slice component with visual hint | ||
* import { getSliceComponentProps } from "@prismicio/vue"; | ||
* import { getSliceComponentProps } from "@prismicio/vue" | ||
* | ||
* export default { | ||
* props: getSliceComponentProps(["slice", "index", "slices", "context"]), | ||
* }; | ||
* } | ||
* ``` | ||
@@ -142,2 +142,3 @@ * | ||
* available to all Slice components | ||
* | ||
* @param propsHint - An optional array of prop names used for the sole purpose | ||
@@ -164,3 +165,3 @@ * of having a visual hint of which props are made available to the slice, | ||
*/ | ||
export declare const TODOSliceComponent: import("vue").ComponentOptions<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions, any, any, any, any> | FunctionalComponent<any, {}, any, {}> | { | ||
export declare const TODOSliceComponent: import("vue").ComponentOptions<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, import("vue").ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | { | ||
new (...args: any[]): any; | ||
@@ -190,2 +191,3 @@ __isFragment?: never; | ||
* applied on each components, improving performances. | ||
* | ||
* @example | ||
@@ -298,3 +300,3 @@ * | ||
*/ | ||
export declare const SliceZoneImpl: DefineComponent<{ | ||
export declare const SliceZoneImpl: DefineComponent<import("vue").ExtractPropTypes<{ | ||
slices: { | ||
@@ -329,7 +331,7 @@ type: PropType<SliceZoneLike<SliceLike & Record<string, unknown>>>; | ||
}; | ||
}, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
}>, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}> | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
[key: string]: any; | ||
}>[]), unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
}>[]), {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{ | ||
slices: { | ||
@@ -364,3 +366,3 @@ type: PropType<SliceZoneLike<SliceLike & Record<string, unknown>>>; | ||
}; | ||
}>>, { | ||
}>> & Readonly<{}>, { | ||
context: any; | ||
@@ -371,3 +373,3 @@ components: SliceZoneComponents<SliceLike<string>, unknown>; | ||
wrapper: string | ConcreteComponent | Raw<DefineComponent>; | ||
}, {}>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>; | ||
/** | ||
@@ -374,0 +376,0 @@ * Component to render a Prismic Slice Zone. |
@@ -1,3 +0,3 @@ | ||
import { PrismicDocument, Query } from "@prismicio/client"; | ||
import { ClientComposableReturnType, ComposableOnlyParameters } from "./useStatefulPrismicClientMethod"; | ||
import type { PrismicDocument, Query } from "@prismicio/client"; | ||
import type { ClientComposableReturnType, ClientMethodParameters, ComposableOnlyParameters } from "./useStatefulPrismicClientMethod"; | ||
/** | ||
@@ -9,2 +9,3 @@ * A composable that queries content from the Prismic repository. | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -26,2 +27,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -43,2 +45,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -61,2 +64,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -79,2 +83,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -99,2 +104,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -118,2 +124,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -137,2 +144,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -158,2 +166,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -176,2 +185,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -194,2 +204,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -214,2 +225,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -232,2 +244,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -252,2 +265,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -271,2 +285,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -292,2 +307,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -311,2 +327,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -337,2 +354,3 @@ * | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -339,0 +357,0 @@ * |
@@ -1,2 +0,2 @@ | ||
import { ConcreteComponent, Slots, VNode } from "vue"; | ||
import { type ConcreteComponent, type Slot, type Slots, type VNode } from "vue"; | ||
/** | ||
@@ -14,2 +14,2 @@ * Get the appropriate `slots` object/array according to the provided parent, | ||
*/ | ||
export declare const getSlots: (parent: string | ConcreteComponent, slots: Slots, defaultPayload?: unknown, fallback?: string) => VNode[] | undefined | Slots | string; | ||
export declare const getSlots: (parent: string | ConcreteComponent, slots: Slots, defaultPayload?: unknown, fallback?: string) => VNode[] | Slots | Slot | undefined; |
@@ -0,13 +1,15 @@ | ||
import { h, Text } from "vue"; | ||
const getSlots = (parent, slots, defaultPayload, fallback) => { | ||
const fallbackSlot = fallback ? () => [h(Text, fallback)] : void 0; | ||
if (typeof parent === "string") { | ||
return slots.default ? slots.default(defaultPayload) : fallback; | ||
return slots.default ? slots.default(defaultPayload) : fallbackSlot == null ? void 0 : fallbackSlot(); | ||
} else { | ||
if (slots.default) { | ||
const content = slots.default(defaultPayload); | ||
return content.length ? { | ||
return { | ||
...slots, | ||
default: () => content | ||
} : fallback; | ||
default: content.length ? () => content : fallbackSlot | ||
}; | ||
} else { | ||
return fallback; | ||
return fallbackSlot; | ||
} | ||
@@ -14,0 +16,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ConcreteComponent, DefineComponent, Raw, VNode } from "vue"; | ||
import type { ConcreteComponent, DefineComponent, Raw, VNode } from "vue"; | ||
/** | ||
@@ -3,0 +3,0 @@ * A stricter version of {@link resolveDynamicComponent} that resolves only type |
@@ -25,2 +25,3 @@ import type { ClientConfig, CreateClient, HTMLRichTextFunctionSerializer, HTMLRichTextMapSerializer, LinkResolverFunction, asDate, asHTML, asImagePixelDensitySrcSet, asImageSrc, asImageWidthSrcSet, asLink, asLinkAttrs, asText, cookie, documentToLinkField, filter, isFilled } from "@prismicio/client"; | ||
* (`to` props). | ||
* | ||
* @defaultValue {@link RouterLink} | ||
@@ -39,2 +40,3 @@ */ | ||
* (`to` props). | ||
* | ||
* @defaultValue `"a"` | ||
@@ -51,2 +53,3 @@ */ | ||
* additional `copyright` props. | ||
* | ||
* @defaultValue `"img"` | ||
@@ -62,2 +65,3 @@ */ | ||
* images in the editor. | ||
* | ||
* @defaultValue `@prismicio/client` defaults | ||
@@ -139,2 +143,3 @@ */ | ||
* `usePrismic().client`. | ||
* | ||
* @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript} | ||
@@ -170,2 +175,3 @@ */ | ||
* `usePrismic().client`. | ||
* | ||
* @example | ||
@@ -175,6 +181,6 @@ * | ||
* // A repository ID | ||
* "my-repo"; | ||
* "my-repo" | ||
* | ||
* //A full repository endpoint | ||
* "https://my-repo.cdn.prismic.io/api/v2"; | ||
* "https://my-repo.cdn.prismic.io/api/v2" | ||
* ``` | ||
@@ -276,2 +282,3 @@ * | ||
* to the plugin at {@link PrismicPluginOptions.htmlSerializer} if available. | ||
* | ||
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles} | ||
@@ -287,2 +294,3 @@ */ | ||
* the plugin at {@link PrismicPluginOptions.linkResolver} if available. | ||
* | ||
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships} | ||
@@ -298,2 +306,3 @@ */ | ||
* the plugin at {@link PrismicPluginOptions.linkResolver} if available. | ||
* | ||
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships} | ||
@@ -300,0 +309,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
import { PrismicPlugin } from "./types"; | ||
import type { PrismicPlugin } from "./types"; | ||
/** | ||
@@ -9,11 +9,11 @@ * Accesses `@prismicio/vue` plugin interface. | ||
* // With the composition API | ||
* import { usePrismic } from "@prismicio/vue"; | ||
* import { usePrismic } from "@prismicio/vue" | ||
* | ||
* export default { | ||
* setup() { | ||
* const prismic = usePrismic(); | ||
* const prismic = usePrismic() | ||
* | ||
* return {}; | ||
* return {} | ||
* }, | ||
* }; | ||
* } | ||
* ``` | ||
@@ -20,0 +20,0 @@ * |
@@ -1,4 +0,5 @@ | ||
import { Client, ForbiddenError, ParsingError, PrismicError } from "@prismicio/client"; | ||
import { Ref } from "vue"; | ||
import { PrismicClientComposableState, VueUseParameters } from "./types"; | ||
import type { Client, ForbiddenError, ParsingError, PrismicError } from "@prismicio/client"; | ||
import type { Ref } from "vue"; | ||
import type { VueUseParameters } from "./types"; | ||
import { PrismicClientComposableState } from "./types"; | ||
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T; | ||
@@ -5,0 +6,0 @@ type ClientMethodLike = (...args: any[]) => Promise<any> | any; |
{ | ||
"name": "@prismicio/vue", | ||
"version": "4.3.0", | ||
"version": "4.3.1", | ||
"description": "Vue plugin, components, and composables to fetch and present Prismic content", | ||
@@ -51,5 +51,5 @@ "keywords": [ | ||
"release:beta:dry": "standard-version --release-as major --prerelease beta --dry-run", | ||
"lint": "eslint --ext .js,.ts .", | ||
"types": "vitest typecheck --run && tsc --noEmit", | ||
"types:watch": "vitest typecheck", | ||
"lint": "eslint", | ||
"types": "vitest --typecheck.only --run && tsc --noEmit", | ||
"types:watch": "vitest --typecheck.only", | ||
"unit": "vitest run --coverage", | ||
@@ -61,34 +61,33 @@ "unit:watch": "vitest watch", | ||
"dependencies": { | ||
"@prismicio/client": "^7.11.0", | ||
"@prismicio/client": "^7.12.0", | ||
"isomorphic-unfetch": "^3.1.0", | ||
"vue-router": "^4.4.3" | ||
"vue-router": "^4.5.0" | ||
}, | ||
"devDependencies": { | ||
"@prismicio/mock": "0.4.0", | ||
"@size-limit/preset-small-lib": "^8.2.6", | ||
"@eslint/js": "^9.16.0", | ||
"@prismicio/mock": "^0.4.0", | ||
"@size-limit/preset-small-lib": "^11.1.6", | ||
"@trivago/prettier-plugin-sort-imports": "^4.3.0", | ||
"@types/jsdom-global": "^3.0.7", | ||
"@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"@typescript-eslint/parser": "^5.62.0", | ||
"@vitejs/plugin-vue": "^4.6.2", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"@vue/compiler-sfc": "^3.4.38", | ||
"@vue/eslint-config-typescript": "^11.0.3", | ||
"@vitejs/plugin-vue": "^5.2.1", | ||
"@vitest/coverage-v8": "^2.1.8", | ||
"@vue/eslint-config-typescript": "^14.1.4", | ||
"@vue/test-utils": "^2.4.6", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^8.10.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-tsdoc": "^0.2.17", | ||
"eslint-plugin-vue": "^9.27.0", | ||
"jsdom": "^24.0.0", | ||
"eslint": "^9.16.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"eslint-plugin-tsdoc": "^0.4.0", | ||
"eslint-plugin-vue": "^9.32.0", | ||
"jsdom": "^25.0.1", | ||
"jsdom-global": "^3.0.2", | ||
"prettier": "^2.8.8", | ||
"prettier-plugin-jsdoc": "^0.4.2", | ||
"size-limit": "^8.2.6", | ||
"prettier": "^3.4.1", | ||
"prettier-plugin-jsdoc": "^1.3.0", | ||
"size-limit": "^11.1.6", | ||
"standard-version": "^9.5.0", | ||
"typescript": "^5.5.4", | ||
"vite": "^5.4.2", | ||
"vite-plugin-sdk": "^0.1.2", | ||
"vitest": "^0.34.6", | ||
"vue": "^3.4.38" | ||
"typescript": "^5.7.2", | ||
"typescript-eslint": "^8.17.0", | ||
"vite": "^6.0.2", | ||
"vite-plugin-sdk": "^0.1.3", | ||
"vitest": "^2.1.8", | ||
"vue": "^3.5.13" | ||
}, | ||
@@ -95,0 +94,0 @@ "peerDependencies": { |
@@ -1,16 +0,12 @@ | ||
export { PrismicEmbedImpl, PrismicEmbed } from "./PrismicEmbed"; | ||
export type { PrismicEmbedProps } from "./PrismicEmbed"; | ||
export { PrismicEmbedImpl, PrismicEmbed } from "./PrismicEmbed" | ||
export type { PrismicEmbedProps } from "./PrismicEmbed" | ||
export { | ||
usePrismicImage, | ||
PrismicImageImpl, | ||
PrismicImage, | ||
} from "./PrismicImage"; | ||
export type { UsePrismicImageOptions, PrismicImageProps } from "./PrismicImage"; | ||
export { usePrismicImage, PrismicImageImpl, PrismicImage } from "./PrismicImage" | ||
export type { UsePrismicImageOptions, PrismicImageProps } from "./PrismicImage" | ||
export { usePrismicLink, PrismicLinkImpl, PrismicLink } from "./PrismicLink"; | ||
export type { UsePrismicLinkOptions, PrismicLinkProps } from "./PrismicLink"; | ||
export { usePrismicLink, PrismicLinkImpl, PrismicLink } from "./PrismicLink" | ||
export type { UsePrismicLinkOptions, PrismicLinkProps } from "./PrismicLink" | ||
export { usePrismicText, PrismicTextImpl, PrismicText } from "./PrismicText"; | ||
export type { UsePrismicTextOptions, PrismicTextProps } from "./PrismicText"; | ||
export { usePrismicText, PrismicTextImpl, PrismicText } from "./PrismicText" | ||
export type { UsePrismicTextOptions, PrismicTextProps } from "./PrismicText" | ||
@@ -21,7 +17,7 @@ export { | ||
PrismicRichText, | ||
} from "./PrismicRichText"; | ||
} from "./PrismicRichText" | ||
export type { | ||
UsePrismicRichTextOptions, | ||
PrismicRichTextProps, | ||
} from "./PrismicRichText"; | ||
} from "./PrismicRichText" | ||
@@ -34,3 +30,3 @@ export { | ||
SliceZone, | ||
} from "./SliceZone"; | ||
} from "./SliceZone" | ||
export type { | ||
@@ -48,2 +44,2 @@ DefineComponentSliceComponentProps, | ||
SliceZoneProps, | ||
} from "./SliceZone"; | ||
} from "./SliceZone" |
@@ -1,3 +0,3 @@ | ||
import { EmbedField } from "@prismicio/client"; | ||
import { | ||
import type { EmbedField } from "@prismicio/client" | ||
import type { | ||
AllowedComponentProps, | ||
@@ -10,7 +10,6 @@ ComponentCustomProps, | ||
VNodeProps, | ||
defineComponent, | ||
h, | ||
} from "vue"; | ||
} from "vue" | ||
import { defineComponent, h } from "vue" | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent"; | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent" | ||
@@ -20,3 +19,3 @@ /** | ||
*/ | ||
const defaultWrapper = "div"; | ||
const defaultWrapper = "div" | ||
@@ -30,3 +29,3 @@ /** | ||
*/ | ||
field: EmbedField; | ||
field: EmbedField | ||
@@ -39,4 +38,4 @@ /** | ||
*/ | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent>; | ||
}; | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent> | ||
} | ||
@@ -66,3 +65,3 @@ /** | ||
if (!props.field) { | ||
return () => null; | ||
return () => null | ||
} | ||
@@ -76,6 +75,6 @@ | ||
innerHTML: props.field.html || null, | ||
}); | ||
}; | ||
}) | ||
} | ||
}, | ||
}); | ||
}) | ||
@@ -95,4 +94,4 @@ // export the public type for h/tsx inference | ||
VNodeProps & | ||
PrismicEmbedProps; | ||
}; | ||
}; | ||
PrismicEmbedProps | ||
} | ||
} |
@@ -0,3 +1,3 @@ | ||
import type { ImageField } from "@prismicio/client" | ||
import { | ||
ImageField, | ||
asImagePixelDensitySrcSet, | ||
@@ -7,4 +7,4 @@ asImageSrc, | ||
isFilled, | ||
} from "@prismicio/client"; | ||
import { | ||
} from "@prismicio/client" | ||
import type { | ||
AllowedComponentProps, | ||
@@ -18,14 +18,11 @@ ComponentCustomProps, | ||
VNodeProps, | ||
computed, | ||
defineComponent, | ||
h, | ||
unref, | ||
} from "vue"; | ||
} from "vue" | ||
import { computed, defineComponent, h, unref } from "vue" | ||
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"; | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent"; | ||
import { __PRODUCTION__ } from "../lib/__PRODUCTION__" | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent" | ||
import { VueUseOptions } from "../types"; | ||
import type { VueUseOptions } from "../types" | ||
import { usePrismic } from "../usePrismic"; | ||
import { usePrismic } from "../usePrismic" | ||
@@ -35,3 +32,3 @@ /** | ||
*/ | ||
const defaultImageComponent = "img"; | ||
const defaultImageComponent = "img" | ||
@@ -45,3 +42,3 @@ /** | ||
*/ | ||
field: ImageField | ImageField<string>; | ||
field: ImageField | ImageField<string> | ||
@@ -56,5 +53,6 @@ /** | ||
* receive an additional `copyright` props. | ||
* | ||
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"img"` otherwise. | ||
*/ | ||
imageComponent?: string | ConcreteComponent | Raw<DefineComponent>; | ||
imageComponent?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -66,3 +64,3 @@ /** | ||
*/ | ||
imgixParams?: Parameters<typeof asImageSrc>[1]; | ||
imgixParams?: Parameters<typeof asImageSrc>[1] | ||
@@ -85,3 +83,3 @@ /** | ||
| "thumbnails" | ||
| "defaults"; | ||
| "defaults" | ||
@@ -103,4 +101,4 @@ /** | ||
>["pixelDensities"] | ||
| "defaults"; | ||
}; | ||
| "defaults" | ||
} | ||
@@ -112,3 +110,3 @@ /** | ||
Omit<PrismicImageProps, "imageComponent"> | ||
>; | ||
> | ||
@@ -122,3 +120,3 @@ /** | ||
*/ | ||
src: ComputedRef<string | null>; | ||
src: ComputedRef<string | null> | ||
@@ -128,3 +126,3 @@ /** | ||
*/ | ||
srcset: ComputedRef<string | null>; | ||
srcset: ComputedRef<string | null> | ||
@@ -134,3 +132,3 @@ /** | ||
*/ | ||
alt: ComputedRef<string>; | ||
alt: ComputedRef<string> | ||
@@ -140,4 +138,4 @@ /** | ||
*/ | ||
copyright: ComputedRef<string | null>; | ||
}; | ||
copyright: ComputedRef<string | null> | ||
} | ||
@@ -155,6 +153,6 @@ /** | ||
): UsePrismicImageReturnType => { | ||
const { options } = usePrismic(); | ||
const { options } = usePrismic() | ||
const asImage = computed(() => { | ||
const field = unref(props.field); | ||
const field = unref(props.field) | ||
@@ -165,8 +163,8 @@ if (!isFilled.image(field)) { | ||
srcset: null, | ||
}; | ||
} | ||
} | ||
const imgixParams = unref(props.imgixParams); | ||
const widths = unref(props.widths); | ||
const pixelDensities = unref(props.pixelDensities); | ||
const imgixParams = unref(props.imgixParams) | ||
const widths = unref(props.widths) | ||
const pixelDensities = unref(props.pixelDensities) | ||
@@ -178,3 +176,3 @@ if (widths) { | ||
props, | ||
); | ||
) | ||
} | ||
@@ -188,3 +186,3 @@ | ||
: widths, | ||
}); | ||
}) | ||
} else if (pixelDensities) { | ||
@@ -197,3 +195,3 @@ return asImagePixelDensitySrcSet(field, { | ||
: pixelDensities, | ||
}); | ||
}) | ||
} else { | ||
@@ -203,18 +201,18 @@ return { | ||
srcset: null, | ||
}; | ||
} | ||
} | ||
}); | ||
}) | ||
const src = computed(() => { | ||
return asImage.value.src; | ||
}); | ||
return asImage.value.src | ||
}) | ||
const srcset = computed(() => { | ||
return asImage.value.srcset; | ||
}); | ||
return asImage.value.srcset | ||
}) | ||
const alt = computed(() => { | ||
return unref(props.field).alt || ""; | ||
}); | ||
return unref(props.field).alt || "" | ||
}) | ||
const copyright = computed(() => { | ||
return unref(props.field).copyright || null; | ||
}); | ||
return unref(props.field).copyright || null | ||
}) | ||
@@ -226,4 +224,4 @@ return { | ||
copyright, | ||
}; | ||
}; | ||
} | ||
} | ||
@@ -277,6 +275,6 @@ /** | ||
if (!props.field) { | ||
return () => null; | ||
return () => null | ||
} | ||
const { options } = usePrismic(); | ||
const { options } = usePrismic() | ||
@@ -288,6 +286,6 @@ const type = computed(() => { | ||
defaultImageComponent | ||
); | ||
}); | ||
) | ||
}) | ||
const { src, srcset, alt, copyright } = usePrismicImage(props); | ||
const { src, srcset, alt, copyright } = usePrismicImage(props) | ||
@@ -299,3 +297,3 @@ return () => { | ||
alt: alt.value, | ||
}; | ||
} | ||
@@ -305,3 +303,3 @@ switch (type.value) { | ||
// Fitting img tag interface | ||
return h("img", attributes); | ||
return h("img", attributes) | ||
@@ -312,7 +310,7 @@ default: | ||
copyright: copyright.value, | ||
}); | ||
}) | ||
} | ||
}; | ||
} | ||
}, | ||
}); | ||
}) | ||
@@ -332,4 +330,4 @@ // export the public type for h/tsx inference | ||
VNodeProps & | ||
PrismicImageProps; | ||
}; | ||
}; | ||
PrismicImageProps | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
import { | ||
import type { | ||
LinkField, | ||
LinkResolverFunction, | ||
PrismicDocument, | ||
asLink, | ||
} from "@prismicio/client"; | ||
import { | ||
} from "@prismicio/client" | ||
import { asLink } from "@prismicio/client" | ||
import type { | ||
AllowedComponentProps, | ||
@@ -16,16 +16,12 @@ ComponentCustomProps, | ||
VNodeProps, | ||
computed, | ||
defineComponent, | ||
h, | ||
reactive, | ||
unref, | ||
} from "vue"; | ||
} from "vue" | ||
import { computed, defineComponent, h, reactive, unref } from "vue" | ||
import { getSlots } from "../lib/getSlots"; | ||
import { isInternalURL } from "../lib/isInternalURL"; | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent"; | ||
import { getSlots } from "../lib/getSlots" | ||
import { isInternalURL } from "../lib/isInternalURL" | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent" | ||
import { VueUseOptions } from "../types"; | ||
import type { VueUseOptions } from "../types" | ||
import { usePrismic } from "../usePrismic"; | ||
import { usePrismic } from "../usePrismic" | ||
@@ -35,3 +31,3 @@ /** | ||
*/ | ||
const defaultInternalComponent = "router-link"; | ||
const defaultInternalComponent = "router-link" | ||
@@ -41,3 +37,3 @@ /** | ||
*/ | ||
const defaultExternalComponent = "a"; | ||
const defaultExternalComponent = "a" | ||
@@ -47,3 +43,3 @@ /** | ||
*/ | ||
const defaultBlankTargetRelAttribute = "noopener noreferrer"; | ||
const defaultBlankTargetRelAttribute = "noopener noreferrer" | ||
@@ -57,3 +53,3 @@ /** | ||
*/ | ||
field: LinkField | PrismicDocument; | ||
field: LinkField | PrismicDocument | ||
@@ -68,3 +64,3 @@ /** | ||
*/ | ||
linkResolver?: LinkResolverFunction; | ||
linkResolver?: LinkResolverFunction | ||
@@ -74,3 +70,3 @@ /** | ||
*/ | ||
target?: string | null; | ||
target?: string | null | ||
@@ -80,3 +76,3 @@ /** | ||
*/ | ||
rel?: string | null; | ||
rel?: string | null | ||
@@ -89,3 +85,3 @@ /** | ||
*/ | ||
blankTargetRelAttribute?: string | null; | ||
blankTargetRelAttribute?: string | null | ||
@@ -102,5 +98,6 @@ /** | ||
* (`to` props). | ||
* | ||
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise. | ||
*/ | ||
internalComponent?: string | ConcreteComponent | Raw<DefineComponent>; | ||
internalComponent?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -117,6 +114,7 @@ /** | ||
* (`to` props). | ||
* | ||
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise. | ||
*/ | ||
externalComponent?: string | ConcreteComponent | Raw<DefineComponent>; | ||
}; | ||
externalComponent?: string | ConcreteComponent | Raw<DefineComponent> | ||
} | ||
@@ -126,3 +124,3 @@ /** | ||
*/ | ||
export type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>; | ||
export type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps> | ||
@@ -136,3 +134,3 @@ /** | ||
*/ | ||
type: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>>; | ||
type: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>> | ||
@@ -142,3 +140,3 @@ /** | ||
*/ | ||
href: ComputedRef<string>; | ||
href: ComputedRef<string> | ||
@@ -148,3 +146,3 @@ /** | ||
*/ | ||
target: ComputedRef<string | null>; | ||
target: ComputedRef<string | null> | ||
@@ -154,3 +152,3 @@ /** | ||
*/ | ||
rel: ComputedRef<string | null>; | ||
rel: ComputedRef<string | null> | ||
@@ -160,4 +158,4 @@ /** | ||
*/ | ||
text: ComputedRef<string | undefined>; | ||
}; | ||
text: ComputedRef<string | undefined> | ||
} | ||
@@ -175,3 +173,3 @@ /** | ||
): UsePrismicLinkReturnType => { | ||
const { options } = usePrismic(); | ||
const { options } = usePrismic() | ||
@@ -182,3 +180,3 @@ const type = computed(() => { | ||
options.components?.linkInternalComponent || | ||
defaultInternalComponent; | ||
defaultInternalComponent | ||
@@ -188,34 +186,34 @@ const externalComponent = | ||
options.components?.linkExternalComponent || | ||
defaultExternalComponent; | ||
defaultExternalComponent | ||
return href.value && isInternalURL(href.value) && !target.value | ||
? internalComponent | ||
: externalComponent; | ||
}); | ||
: externalComponent | ||
}) | ||
const href = computed(() => { | ||
const field = unref(props.field); | ||
const linkResolver = unref(props.linkResolver) ?? options.linkResolver; | ||
const field = unref(props.field) | ||
const linkResolver = unref(props.linkResolver) ?? options.linkResolver | ||
return asLink(field, linkResolver) ?? ""; | ||
}); | ||
return asLink(field, linkResolver) ?? "" | ||
}) | ||
const target = computed(() => { | ||
const field = unref(props.field); | ||
const target = unref(props.target); | ||
const field = unref(props.field) | ||
const target = unref(props.target) | ||
if (typeof target !== "undefined") { | ||
return target; | ||
return target | ||
} else { | ||
return field && "target" in field && field.target ? field.target : null; | ||
return field && "target" in field && field.target ? field.target : null | ||
} | ||
}); | ||
}) | ||
const rel = computed(() => { | ||
const rel = unref(props.rel); | ||
const rel = unref(props.rel) | ||
if (typeof rel !== "undefined") { | ||
return rel; | ||
return rel | ||
} else if (target.value === "_blank") { | ||
const blankTargetRelAttribute = unref(props.blankTargetRelAttribute); | ||
const blankTargetRelAttribute = unref(props.blankTargetRelAttribute) | ||
if (typeof blankTargetRelAttribute !== "undefined") { | ||
return blankTargetRelAttribute; | ||
return blankTargetRelAttribute | ||
} else { | ||
@@ -225,14 +223,14 @@ return typeof options.components?.linkBlankTargetRelAttribute !== | ||
? options.components.linkBlankTargetRelAttribute | ||
: defaultBlankTargetRelAttribute; | ||
: defaultBlankTargetRelAttribute | ||
} | ||
} else { | ||
return null; | ||
return null | ||
} | ||
}); | ||
}) | ||
const text = computed(() => { | ||
const field = unref(props.field); | ||
const field = unref(props.field) | ||
return field && "text" in field ? field.text : undefined; | ||
}); | ||
return field && "text" in field ? field.text : undefined | ||
}) | ||
@@ -245,4 +243,4 @@ return { | ||
text, | ||
}; | ||
}; | ||
} | ||
} | ||
@@ -299,10 +297,10 @@ /** | ||
if (!props.field) { | ||
return () => null; | ||
return () => null | ||
} | ||
const { type, href, target, rel, text } = usePrismicLink(props); | ||
const { type, href, target, rel, text } = usePrismicLink(props) | ||
return () => { | ||
const parent = | ||
type.value === "a" ? "a" : simplyResolveComponent(type.value); | ||
type.value === "a" ? "a" : simplyResolveComponent(type.value) | ||
const computedSlots = getSlots( | ||
@@ -313,3 +311,3 @@ parent, | ||
text.value, | ||
); | ||
) | ||
@@ -322,3 +320,3 @@ if (typeof parent === "string") { | ||
computedSlots, | ||
); | ||
) | ||
} else { | ||
@@ -330,7 +328,7 @@ // Fitting Vue Router Link interface | ||
computedSlots, | ||
); | ||
) | ||
} | ||
}; | ||
} | ||
}, | ||
}); | ||
}) | ||
@@ -350,4 +348,4 @@ // export the public type for h/tsx inference | ||
VNodeProps & | ||
PrismicLinkProps; | ||
}; | ||
}; | ||
PrismicLinkProps | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { | ||
import type { | ||
HTMLFunctionSerializer, | ||
@@ -6,6 +6,5 @@ HTMLMapSerializer, | ||
RichTextField, | ||
asHTML, | ||
isFilled, | ||
} from "@prismicio/client"; | ||
import { | ||
} from "@prismicio/client" | ||
import { asHTML, isFilled } from "@prismicio/client" | ||
import type { | ||
AllowedComponentProps, | ||
@@ -20,2 +19,4 @@ Component, | ||
VNodeProps, | ||
} from "vue" | ||
import { | ||
computed, | ||
@@ -30,11 +31,11 @@ defineComponent, | ||
watch, | ||
} from "vue"; | ||
import { routerKey } from "vue-router"; | ||
} from "vue" | ||
import { routerKey } from "vue-router" | ||
import { isInternalURL } from "../lib/isInternalURL"; | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent"; | ||
import { isInternalURL } from "../lib/isInternalURL" | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent" | ||
import { VueUseOptions } from "../types"; | ||
import type { VueUseOptions } from "../types" | ||
import { usePrismic } from "../usePrismic"; | ||
import { usePrismic } from "../usePrismic" | ||
@@ -44,3 +45,3 @@ /** | ||
*/ | ||
const defaultWrapper = "div"; | ||
const defaultWrapper = "div" | ||
@@ -54,3 +55,3 @@ /** | ||
*/ | ||
field: RichTextField | null | undefined; | ||
field: RichTextField | null | undefined | ||
@@ -65,3 +66,3 @@ /** | ||
*/ | ||
linkResolver?: LinkResolverFunction; | ||
linkResolver?: LinkResolverFunction | ||
@@ -75,3 +76,3 @@ /** | ||
*/ | ||
serializer?: HTMLFunctionSerializer | HTMLMapSerializer; | ||
serializer?: HTMLFunctionSerializer | HTMLMapSerializer | ||
@@ -87,3 +88,3 @@ /** | ||
*/ | ||
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer; | ||
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer | ||
@@ -96,3 +97,3 @@ /** | ||
*/ | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent>; | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -103,4 +104,4 @@ /** | ||
*/ | ||
fallback?: string; | ||
}; | ||
fallback?: string | ||
} | ||
@@ -112,3 +113,3 @@ /** | ||
Omit<PrismicRichTextProps, "wrapper"> | ||
>; | ||
> | ||
@@ -122,4 +123,4 @@ /** | ||
*/ | ||
html: ComputedRef<string>; | ||
}; | ||
html: ComputedRef<string> | ||
} | ||
@@ -137,12 +138,12 @@ /** | ||
): UsePrismicRichTextReturnType => { | ||
const { options } = usePrismic(); | ||
const { options } = usePrismic() | ||
const html = computed(() => { | ||
const field = unref(props.field); | ||
const field = unref(props.field) | ||
if (!isFilled.richText(field)) { | ||
return unref(props.fallback) ?? ""; | ||
return unref(props.fallback) ?? "" | ||
} | ||
const linkResolver = unref(props.linkResolver) ?? options.linkResolver; | ||
const linkResolver = unref(props.linkResolver) ?? options.linkResolver | ||
const serializer = | ||
@@ -152,11 +153,11 @@ unref(props.serializer) ?? | ||
options.richTextSerializer ?? | ||
options.htmlSerializer; | ||
options.htmlSerializer | ||
return asHTML(unref(field), linkResolver, serializer); | ||
}); | ||
return asHTML(unref(field), linkResolver, serializer) | ||
}) | ||
return { | ||
html, | ||
}; | ||
}; | ||
} | ||
} | ||
@@ -209,13 +210,13 @@ /** | ||
setup(props) { | ||
const { html } = usePrismicRichText(props); | ||
const { html } = usePrismicRichText(props) | ||
const root = ref<HTMLElement | Comment | Component | null>(null); | ||
const root = ref<HTMLElement | Comment | Component | null>(null) | ||
const maybeRouter = inject(routerKey, null); | ||
const maybeRouter = inject(routerKey, null) | ||
if (maybeRouter) { | ||
type InternalLink = { | ||
element: HTMLAnchorElement; | ||
listener: EventListener; | ||
}; | ||
let links: InternalLink[] = []; | ||
element: HTMLAnchorElement | ||
listener: EventListener | ||
} | ||
let links: InternalLink[] = [] | ||
@@ -226,9 +227,9 @@ const navigate: EventListener = function ( | ||
) { | ||
event.preventDefault(); | ||
maybeRouter.push(this.href); | ||
}; | ||
event.preventDefault() | ||
maybeRouter.push(this.href) | ||
} | ||
const addListeners = () => { | ||
const node: HTMLElement | Comment | null = | ||
root.value && "$el" in root.value ? root.value.$el : root.value; | ||
root.value && "$el" in root.value ? root.value.$el : root.value | ||
if (node && "querySelectorAll" in node) { | ||
@@ -238,16 +239,16 @@ // Get all internal link tags and add listeners on them | ||
.map((element) => { | ||
const href = element.getAttribute("href"); | ||
const href = element.getAttribute("href") | ||
if (href && isInternalURL(href)) { | ||
const listener = navigate.bind({ href }); | ||
element.addEventListener("click", listener); | ||
const listener = navigate.bind({ href }) | ||
element.addEventListener("click", listener) | ||
return { element, listener }; | ||
return { element, listener } | ||
} else { | ||
return false; | ||
return false | ||
} | ||
}) | ||
.filter((link): link is InternalLink => link as boolean); | ||
.filter((link): link is InternalLink => link as boolean) | ||
} | ||
}; | ||
} | ||
@@ -257,5 +258,5 @@ const removeListeners = () => { | ||
element.removeEventListener("click", listener), | ||
); | ||
links = []; | ||
}; | ||
) | ||
links = [] | ||
} | ||
@@ -265,11 +266,11 @@ watch( | ||
() => { | ||
removeListeners(); | ||
nextTick(addListeners); | ||
removeListeners() | ||
nextTick(addListeners) | ||
}, | ||
{ immediate: true }, | ||
); | ||
) | ||
onBeforeUnmount(() => { | ||
removeListeners(); | ||
}); | ||
removeListeners() | ||
}) | ||
} | ||
@@ -281,6 +282,6 @@ | ||
ref: root, | ||
}); | ||
}; | ||
}) | ||
} | ||
}, | ||
}); | ||
}) | ||
@@ -300,4 +301,4 @@ // export the public type for h/tsx inference | ||
VNodeProps & | ||
PrismicRichTextProps; | ||
}; | ||
}; | ||
PrismicRichTextProps | ||
} | ||
} |
@@ -1,3 +0,4 @@ | ||
import { RichTextField, asText, isFilled } from "@prismicio/client"; | ||
import { | ||
import type { RichTextField } from "@prismicio/client" | ||
import { asText, isFilled } from "@prismicio/client" | ||
import type { | ||
AllowedComponentProps, | ||
@@ -12,11 +13,8 @@ ComponentCustomProps, | ||
VNodeProps, | ||
computed, | ||
defineComponent, | ||
h, | ||
unref, | ||
} from "vue"; | ||
} from "vue" | ||
import { computed, defineComponent, h, unref } from "vue" | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent"; | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent" | ||
import { VueUseOptions } from "../types"; | ||
import type { VueUseOptions } from "../types" | ||
@@ -26,3 +24,3 @@ /** | ||
*/ | ||
const defaultWrapper = "div"; | ||
const defaultWrapper = "div" | ||
/** | ||
@@ -35,3 +33,3 @@ * Props for `<PrismicText />`. | ||
*/ | ||
field: RichTextField | null | undefined; | ||
field: RichTextField | null | undefined | ||
@@ -43,3 +41,3 @@ /** | ||
*/ | ||
separator?: string; | ||
separator?: string | ||
@@ -52,3 +50,3 @@ /** | ||
*/ | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent>; | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -59,4 +57,4 @@ /** | ||
*/ | ||
fallback?: string; | ||
}; | ||
fallback?: string | ||
} | ||
@@ -68,3 +66,3 @@ /** | ||
Omit<PrismicTextProps, "wrapper"> | ||
>; | ||
> | ||
@@ -78,4 +76,4 @@ /** | ||
*/ | ||
text: ComputedRef<string>; | ||
}; | ||
text: ComputedRef<string> | ||
} | ||
@@ -95,15 +93,15 @@ /** | ||
const text = computed(() => { | ||
const field = unref(props.field); | ||
const field = unref(props.field) | ||
if (!isFilled.richText(field)) { | ||
return unref(props.fallback) ?? ""; | ||
return unref(props.fallback) ?? "" | ||
} | ||
return asText(unref(field), unref(props.separator)); | ||
}); | ||
return asText(unref(field), unref(props.separator)) | ||
}) | ||
return { | ||
text, | ||
}; | ||
}; | ||
} | ||
} | ||
@@ -142,6 +140,6 @@ /** | ||
setup(props) { | ||
const { text } = usePrismicText(props); | ||
const { text } = usePrismicText(props) | ||
return () => { | ||
const parent = simplyResolveComponent(props.wrapper || defaultWrapper); | ||
const parent = simplyResolveComponent(props.wrapper || defaultWrapper) | ||
@@ -157,6 +155,6 @@ // This works but is absurd | ||
default: () => text.value, | ||
}); | ||
}; | ||
}) | ||
} | ||
}, | ||
}); | ||
}) | ||
@@ -176,4 +174,4 @@ // export the public type for h/tsx inference | ||
VNodeProps & | ||
PrismicTextProps; | ||
}; | ||
}; | ||
PrismicTextProps | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
import { Slice } from "@prismicio/client"; | ||
import { | ||
import type { Slice } from "@prismicio/client" | ||
import type { | ||
AllowedComponentProps, | ||
@@ -11,14 +11,10 @@ ComponentCustomProps, | ||
VNodeProps, | ||
computed, | ||
defineAsyncComponent, | ||
defineComponent, | ||
h, | ||
markRaw, | ||
watchEffect, | ||
} from "vue"; | ||
} from "vue" | ||
import { computed, defineComponent, h, markRaw, watchEffect } from "vue" | ||
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"; | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent"; | ||
import { __PRODUCTION__ } from "../lib/__PRODUCTION__" | ||
import { simplyResolveComponent } from "../lib/simplyResolveComponent" | ||
import { usePrismic } from "../usePrismic"; | ||
import { usePrismic } from "../usePrismic" | ||
@@ -33,4 +29,4 @@ /** | ||
: TSlice extends SliceLikeGraphQL | ||
? TSlice["type"] | ||
: never; | ||
? TSlice["type"] | ||
: never | ||
@@ -49,3 +45,3 @@ /** | ||
"id" | "slice_type" | ||
>; | ||
> | ||
@@ -59,4 +55,4 @@ /** | ||
export type SliceLikeGraphQL<TSliceType extends string = string> = { | ||
type: Slice<TSliceType>["slice_type"]; | ||
}; | ||
type: Slice<TSliceType>["slice_type"] | ||
} | ||
@@ -82,4 +78,4 @@ /** | ||
*/ | ||
__mapped?: true; | ||
}; | ||
__mapped?: true | ||
} | ||
@@ -96,3 +92,3 @@ /** | ||
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = | ||
readonly TSlice[]; | ||
readonly TSlice[] | ||
@@ -114,3 +110,3 @@ /** | ||
*/ | ||
slice: TSlice; | ||
slice: TSlice | ||
@@ -120,3 +116,3 @@ /** | ||
*/ | ||
index: number; | ||
index: number | ||
@@ -132,3 +128,3 @@ /** | ||
TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2 | ||
>; | ||
> | ||
@@ -139,4 +135,4 @@ /** | ||
*/ | ||
context: TContext; | ||
}; | ||
context: TContext | ||
} | ||
@@ -157,18 +153,18 @@ /** | ||
slice: { | ||
type: PropType<SliceComponentProps<TSlice, TContext>["slice"]>; | ||
required: true; | ||
}; | ||
type: PropType<SliceComponentProps<TSlice, TContext>["slice"]> | ||
required: true | ||
} | ||
index: { | ||
type: PropType<SliceComponentProps<TSlice, TContext>["index"]>; | ||
required: true; | ||
}; | ||
type: PropType<SliceComponentProps<TSlice, TContext>["index"]> | ||
required: true | ||
} | ||
slices: { | ||
type: PropType<SliceComponentProps<TSlice, TContext>["slices"]>; | ||
required: true; | ||
}; | ||
type: PropType<SliceComponentProps<TSlice, TContext>["slices"]> | ||
required: true | ||
} | ||
context: { | ||
type: PropType<SliceComponentProps<TSlice, TContext>["context"]>; | ||
required: true; | ||
}; | ||
}; | ||
type: PropType<SliceComponentProps<TSlice, TContext>["context"]> | ||
required: true | ||
} | ||
} | ||
@@ -185,7 +181,7 @@ /** | ||
* // Defining a new slice component | ||
* import { getSliceComponentProps } from "@prismicio/vue"; | ||
* import { getSliceComponentProps } from "@prismicio/vue" | ||
* | ||
* export default { | ||
* props: getSliceComponentProps(), | ||
* }; | ||
* } | ||
* ``` | ||
@@ -197,7 +193,7 @@ * | ||
* // Defining a new slice component with visual hint | ||
* import { getSliceComponentProps } from "@prismicio/vue"; | ||
* import { getSliceComponentProps } from "@prismicio/vue" | ||
* | ||
* export default { | ||
* props: getSliceComponentProps(["slice", "index", "slices", "context"]), | ||
* }; | ||
* } | ||
* ``` | ||
@@ -208,2 +204,3 @@ * | ||
* available to all Slice components | ||
* | ||
* @param propsHint - An optional array of prop names used for the sole purpose | ||
@@ -241,3 +238,3 @@ * of having a visual hint of which props are made available to the slice, | ||
}, | ||
}); | ||
}) | ||
@@ -256,3 +253,3 @@ /** | ||
// For reference within TypeScript files when `*.vue` type cannot be inferred | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types | ||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any | ||
| DefineComponent<{}, {}, any> | ||
@@ -262,3 +259,3 @@ // Likewise, for reference with TypeScript files. | ||
| DefineComponent<SliceComponentProps<TSlice, TContext>> | ||
| FunctionalComponent<SliceComponentProps<TSlice, TContext>>; | ||
| FunctionalComponent<SliceComponentProps<TSlice, TContext>> | ||
@@ -274,4 +271,4 @@ /** | ||
? ((() => null) as FunctionalComponent<{ | ||
slice: SliceLike; | ||
}>) | ||
slice: SliceLike | ||
}>) | ||
: /*#__PURE__*/ (defineComponent({ | ||
@@ -289,4 +286,4 @@ name: "TODOSliceComponent", | ||
? props.slice.slice_type | ||
: props.slice.type; | ||
}); | ||
: props.slice.type | ||
}) | ||
@@ -297,4 +294,4 @@ watchEffect(() => { | ||
props.slice, | ||
); | ||
}); | ||
) | ||
}) | ||
@@ -309,6 +306,6 @@ return () => { | ||
[`Could not find a component for Slice type "${type.value}"`], | ||
); | ||
}; | ||
) | ||
} | ||
}, | ||
}) as SliceComponentType); | ||
}) as SliceComponentType) | ||
@@ -338,4 +335,4 @@ /** | ||
| SliceComponentType<Extract<TSlice, SliceLike<SliceType>>, TContext> | ||
| string; | ||
}; | ||
| string | ||
} | ||
@@ -349,2 +346,3 @@ /** | ||
* applied on each components, improving performances. | ||
* | ||
* @example | ||
@@ -383,7 +381,7 @@ * | ||
): SliceZoneComponents<TSlice, TContext> => { | ||
const result = {} as SliceZoneComponents<TSlice, TContext>; | ||
const result = {} as SliceZoneComponents<TSlice, TContext> | ||
let type: keyof typeof components; | ||
let type: keyof typeof components | ||
for (type in components) { | ||
const component = components[type]; | ||
const component = components[type] | ||
result[type] = | ||
@@ -397,7 +395,7 @@ typeof component === "string" | ||
>, | ||
); | ||
) | ||
} | ||
return result; | ||
}; | ||
return result | ||
} | ||
@@ -411,3 +409,3 @@ /** | ||
*/ | ||
slice: TSlice; | ||
slice: TSlice | ||
@@ -417,3 +415,3 @@ /** | ||
*/ | ||
sliceName: ExtractSliceType<TSlice>; | ||
sliceName: ExtractSliceType<TSlice> | ||
@@ -423,4 +421,4 @@ /** | ||
*/ | ||
i: number; | ||
}; | ||
i: number | ||
} | ||
@@ -446,3 +444,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
) => SliceComponentType<any, TContext> | string | undefined | null; | ||
) => SliceComponentType<any, TContext> | string | undefined | null | ||
@@ -458,3 +456,3 @@ /** | ||
*/ | ||
slices: SliceZoneLike; | ||
slices: SliceZoneLike | ||
@@ -464,3 +462,3 @@ /** | ||
*/ | ||
components?: SliceZoneComponents; | ||
components?: SliceZoneComponents | ||
@@ -479,3 +477,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
resolver?: SliceZoneResolver<any, TContext>; | ||
resolver?: SliceZoneResolver<any, TContext> | ||
@@ -485,3 +483,3 @@ /** | ||
*/ | ||
context?: TContext; | ||
context?: TContext | ||
@@ -498,3 +496,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
defaultComponent?: SliceComponentType<any, TContext>; | ||
defaultComponent?: SliceComponentType<any, TContext> | ||
@@ -505,4 +503,4 @@ /** | ||
*/ | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent>; | ||
}; | ||
wrapper?: string | ConcreteComponent | Raw<DefineComponent> | ||
} | ||
@@ -554,3 +552,3 @@ /** | ||
if (!props.slices) { | ||
return () => null; | ||
return () => null | ||
} | ||
@@ -563,7 +561,7 @@ | ||
"The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.", | ||
); | ||
) | ||
} | ||
} | ||
const { options } = usePrismic(); | ||
const { options } = usePrismic() | ||
@@ -573,3 +571,3 @@ const renderedSlices = computed(() => { | ||
const type = | ||
"slice_type" in slice ? (slice.slice_type as string) : slice.type; | ||
"slice_type" in slice ? (slice.slice_type as string) : slice.type | ||
@@ -580,3 +578,3 @@ let component = | ||
: props.defaultComponent || | ||
options.components?.sliceZoneDefaultComponent; | ||
options.components?.sliceZoneDefaultComponent | ||
@@ -589,6 +587,6 @@ // TODO: Remove `resolver` in v5 in favor of `components`. | ||
i: index, | ||
}); | ||
}) | ||
if (resolvedComponent) { | ||
component = resolvedComponent; | ||
component = resolvedComponent | ||
} | ||
@@ -600,7 +598,7 @@ } | ||
? slice.id | ||
: `${index}-${JSON.stringify(slice)}`; | ||
: `${index}-${JSON.stringify(slice)}` | ||
if (component) { | ||
if (slice.__mapped) { | ||
const { __mapped, ...mappedProps } = slice; | ||
const { __mapped, ...mappedProps } = slice | ||
@@ -610,3 +608,3 @@ return h(simplyResolveComponent(component as ConcreteComponent), { | ||
...mappedProps, | ||
}); | ||
}) | ||
} | ||
@@ -620,3 +618,3 @@ | ||
slices: props.slices, | ||
}); | ||
}) | ||
} else { | ||
@@ -626,22 +624,22 @@ return h( | ||
{ key, slice }, | ||
); | ||
) | ||
} | ||
}); | ||
}); | ||
}) | ||
}) | ||
return () => { | ||
if (props.wrapper) { | ||
const parent = simplyResolveComponent(props.wrapper); | ||
const parent = simplyResolveComponent(props.wrapper) | ||
if (typeof parent === "string") { | ||
return h(parent, null, renderedSlices.value); | ||
return h(parent, null, renderedSlices.value) | ||
} else { | ||
return h(parent, null, { default: () => renderedSlices.value }); | ||
return h(parent, null, { default: () => renderedSlices.value }) | ||
} | ||
} else { | ||
return renderedSlices.value; | ||
return renderedSlices.value | ||
} | ||
}; | ||
} | ||
}, | ||
}); | ||
}) | ||
@@ -661,4 +659,4 @@ // export the public type for h/tsx inference | ||
VNodeProps & | ||
SliceZoneProps; | ||
}; | ||
}; | ||
SliceZoneProps | ||
} | ||
} |
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// Imports for @link references: | ||
import type { Client } from "@prismicio/client"; | ||
import type { Client } from "@prismicio/client" | ||
/* eslint-enable @typescript-eslint/no-unused-vars */ | ||
import { PrismicDocument, Query } from "@prismicio/client"; | ||
import type { PrismicDocument, Query } from "@prismicio/client" | ||
import { | ||
import type { | ||
ClientComposableReturnType, | ||
ClientMethodParameters, | ||
ComposableOnlyParameters, | ||
useStatefulPrismicClientMethod, | ||
} from "./useStatefulPrismicClientMethod"; | ||
} from "./useStatefulPrismicClientMethod" | ||
import { useStatefulPrismicClientMethod } from "./useStatefulPrismicClientMethod" | ||
@@ -23,2 +23,3 @@ // Composables | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -37,3 +38,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("get", args); | ||
useStatefulPrismicClientMethod("get", args) | ||
@@ -47,2 +48,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -61,3 +63,3 @@ * | ||
): ClientComposableReturnType<TDocument> => | ||
useStatefulPrismicClientMethod("getFirst", args); | ||
useStatefulPrismicClientMethod("getFirst", args) | ||
@@ -71,2 +73,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -87,3 +90,3 @@ * | ||
): ClientComposableReturnType<TDocument> => | ||
useStatefulPrismicClientMethod("getByID", args); | ||
useStatefulPrismicClientMethod("getByID", args) | ||
@@ -97,2 +100,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -113,3 +117,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("getByIDs", args); | ||
useStatefulPrismicClientMethod("getByIDs", args) | ||
@@ -123,2 +127,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -140,3 +145,3 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("getAllByIDs", args); | ||
useStatefulPrismicClientMethod("getAllByIDs", args) | ||
@@ -150,2 +155,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -168,3 +174,3 @@ * | ||
): ClientComposableReturnType<TDocument> => | ||
useStatefulPrismicClientMethod("getByUID", args); | ||
useStatefulPrismicClientMethod("getByUID", args) | ||
@@ -178,2 +184,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -196,3 +203,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("getByUIDs", args); | ||
useStatefulPrismicClientMethod("getByUIDs", args) | ||
@@ -206,2 +213,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -225,3 +233,3 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("getAllByUIDs", args); | ||
useStatefulPrismicClientMethod("getAllByUIDs", args) | ||
@@ -235,2 +243,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of the Prismic document returned | ||
@@ -251,3 +260,3 @@ * | ||
): ClientComposableReturnType<TDocument> => | ||
useStatefulPrismicClientMethod("getSingle", args); | ||
useStatefulPrismicClientMethod("getSingle", args) | ||
@@ -261,2 +270,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -277,3 +287,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("getByType", args); | ||
useStatefulPrismicClientMethod("getByType", args) | ||
@@ -287,2 +297,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -304,3 +315,3 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("getAllByType", args); | ||
useStatefulPrismicClientMethod("getAllByType", args) | ||
@@ -314,2 +325,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -330,3 +342,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("getByTag", args); | ||
useStatefulPrismicClientMethod("getByTag", args) | ||
@@ -340,2 +352,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -357,3 +370,3 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("getAllByTag", args); | ||
useStatefulPrismicClientMethod("getAllByTag", args) | ||
@@ -367,2 +380,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -386,3 +400,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("getByEveryTag", args); | ||
useStatefulPrismicClientMethod("getByEveryTag", args) | ||
@@ -397,2 +411,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -416,3 +431,3 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("getAllByEveryTag", args); | ||
useStatefulPrismicClientMethod("getAllByEveryTag", args) | ||
@@ -427,2 +442,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -446,3 +462,3 @@ * | ||
): ClientComposableReturnType<Query<TDocument>> => | ||
useStatefulPrismicClientMethod("getBySomeTags", args); | ||
useStatefulPrismicClientMethod("getBySomeTags", args) | ||
@@ -457,2 +473,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -476,3 +493,3 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("getAllBySomeTags", args); | ||
useStatefulPrismicClientMethod("getAllBySomeTags", args) | ||
@@ -492,2 +509,3 @@ /** | ||
* `params.client`. | ||
* | ||
* @typeParam TDocument - Type of Prismic documents returned | ||
@@ -509,2 +527,2 @@ * | ||
): ClientComposableReturnType<TDocument[]> => | ||
useStatefulPrismicClientMethod("dangerouslyGetAll", args); | ||
useStatefulPrismicClientMethod("dangerouslyGetAll", args) |
@@ -1,5 +0,9 @@ | ||
import { | ||
import type { | ||
Client, | ||
FetchLike, | ||
HTMLRichTextFunctionSerializer, | ||
HTMLRichTextMapSerializer, | ||
LinkResolverFunction, | ||
} from "@prismicio/client" | ||
import { | ||
asDate, | ||
@@ -18,4 +22,4 @@ asHTML, | ||
isFilled, | ||
} from "@prismicio/client"; | ||
import { App } from "vue"; | ||
} from "@prismicio/client" | ||
import type { App } from "vue" | ||
@@ -27,3 +31,3 @@ import type { | ||
PrismicPluginOptions, | ||
} from "./types"; | ||
} from "./types" | ||
@@ -37,4 +41,4 @@ import { | ||
SliceZone, | ||
} from "./components"; | ||
import { prismicKey } from "./injectionSymbols"; | ||
} from "./components" | ||
import { prismicKey } from "./injectionSymbols" | ||
@@ -53,19 +57,19 @@ /** | ||
// Create plugin client | ||
let client: Client; | ||
let client: Client | ||
if (options.client) { | ||
client = options.client; | ||
client = options.client | ||
} else { | ||
client = createClient(options.endpoint, { | ||
fetch: async (endpoint, options) => { | ||
let fetchFunction: FetchLike; | ||
let fetchFunction: FetchLike | ||
if (typeof globalThis.fetch === "function") { | ||
fetchFunction = globalThis.fetch; | ||
fetchFunction = globalThis.fetch | ||
} else { | ||
fetchFunction = (await import("isomorphic-unfetch")).default; | ||
fetchFunction = (await import("isomorphic-unfetch")).default | ||
} | ||
return await fetchFunction(endpoint, options); | ||
return await fetchFunction(endpoint, options) | ||
}, | ||
...options.clientConfig, | ||
}); | ||
}) | ||
} | ||
@@ -77,3 +81,3 @@ | ||
cookie, | ||
}; | ||
} | ||
@@ -84,3 +88,3 @@ // Create plugin helpers | ||
asHTML: (richTextField, ...config) => { | ||
const [configOrLinkResolver, maybeHTMLSerializer] = config; | ||
const [configOrLinkResolver, maybeHTMLSerializer] = config | ||
@@ -94,6 +98,8 @@ return asHTML( | ||
serializer: | ||
maybeHTMLSerializer || | ||
(maybeHTMLSerializer as | ||
| HTMLRichTextFunctionSerializer | ||
| HTMLRichTextMapSerializer) || | ||
options.richTextSerializer || | ||
options.htmlSerializer, | ||
} | ||
} | ||
: { | ||
@@ -103,4 +109,4 @@ linkResolver: options.linkResolver, | ||
...configOrLinkResolver, | ||
}, | ||
); | ||
}, | ||
) | ||
}, | ||
@@ -117,4 +123,4 @@ asLink: (linkField, config) => { | ||
...(config as any), | ||
}, | ||
); | ||
}, | ||
) | ||
}, | ||
@@ -127,3 +133,3 @@ asLinkAttrs: (linkField, config) => { | ||
...config, | ||
}); | ||
}) | ||
}, | ||
@@ -136,3 +142,3 @@ asDate, | ||
documentToLinkField, | ||
}; | ||
} | ||
@@ -147,17 +153,17 @@ // Create plugin interface | ||
install(app: App): void { | ||
app.provide(prismicKey, this); | ||
app.config.globalProperties.$prismic = this; | ||
app.provide(prismicKey, this) | ||
app.config.globalProperties.$prismic = this | ||
if (options.injectComponents !== false) { | ||
app.component(PrismicLink.name, PrismicLink); | ||
app.component(PrismicEmbed.name, PrismicEmbed); | ||
app.component(PrismicImage.name, PrismicImage); | ||
app.component(PrismicText.name, PrismicText); | ||
app.component(PrismicRichText.name, PrismicRichText); | ||
app.component(SliceZone.name, SliceZone); | ||
app.component(PrismicLink.name, PrismicLink) | ||
app.component(PrismicEmbed.name, PrismicEmbed) | ||
app.component(PrismicImage.name, PrismicImage) | ||
app.component(PrismicText.name, PrismicText) | ||
app.component(PrismicRichText.name, PrismicRichText) | ||
app.component(SliceZone.name, SliceZone) | ||
} | ||
}, | ||
}; | ||
} | ||
return prismic; | ||
}; | ||
return prismic | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { PrismicPlugin } from "./types"; | ||
import type { PrismicPlugin } from "./types" | ||
@@ -10,4 +10,4 @@ declare module "vue" { | ||
*/ | ||
$prismic: PrismicPlugin; | ||
$prismic: PrismicPlugin | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
export { createPrismic } from "./createPrismic"; | ||
export { usePrismic } from "./usePrismic"; | ||
export { createPrismic } from "./createPrismic" | ||
export { usePrismic } from "./usePrismic" | ||
@@ -21,3 +21,3 @@ export { | ||
SliceZone, | ||
} from "./components"; | ||
} from "./components" | ||
export type { | ||
@@ -46,3 +46,3 @@ // Composables | ||
SliceZoneProps, | ||
} from "./components"; | ||
} from "./components" | ||
@@ -68,11 +68,11 @@ export { | ||
dangerouslyUseAllPrismicDocuments, | ||
} from "./composables"; | ||
} from "./composables" | ||
export type { ClientComposableReturnType } from "./useStatefulPrismicClientMethod"; | ||
export type { ClientComposableReturnType } from "./useStatefulPrismicClientMethod" | ||
export { PrismicClientComposableState } from "./types"; | ||
export type { PrismicPluginOptions, PrismicPlugin } from "./types"; | ||
export { PrismicClientComposableState } from "./types" | ||
export type { PrismicPluginOptions, PrismicPlugin } from "./types" | ||
export { prismicKey } from "./injectionSymbols"; | ||
export { prismicKey } from "./injectionSymbols" | ||
export * from "./globalExtensions"; | ||
export * from "./globalExtensions" |
@@ -1,8 +0,8 @@ | ||
import type { InjectionKey } from "vue"; | ||
import type { InjectionKey } from "vue" | ||
import type { PrismicPlugin } from "./types"; | ||
import type { PrismicPlugin } from "./types" | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// Imports for @link references: | ||
import type { usePrismic } from "./usePrismic"; | ||
import type { usePrismic } from "./usePrismic" | ||
@@ -17,2 +17,2 @@ /* eslint-enable @typescript-eslint/no-unused-vars */ | ||
*/ | ||
export const prismicKey = Symbol("prismic") as InjectionKey<PrismicPlugin>; | ||
export const prismicKey = Symbol("prismic") as InjectionKey<PrismicPlugin> |
// We need to polyfill process if it doesn't exist, such as in the browser. | ||
if (typeof process === "undefined") { | ||
globalThis.process = { env: {} } as typeof process; | ||
globalThis.process = { env: {} } as typeof process | ||
} | ||
@@ -12,2 +12,2 @@ | ||
*/ | ||
export const __PRODUCTION__ = process.env.NODE_ENV === "production"; | ||
export const __PRODUCTION__ = process.env.NODE_ENV === "production" |
@@ -1,2 +0,9 @@ | ||
import { ConcreteComponent, Slots, VNode } from "vue"; | ||
import { | ||
type ConcreteComponent, | ||
type Slot, | ||
type Slots, | ||
Text, | ||
type VNode, | ||
h, | ||
} from "vue" | ||
@@ -20,19 +27,18 @@ /** | ||
fallback?: string, | ||
): VNode[] | undefined | Slots | string => { | ||
): VNode[] | Slots | Slot | undefined => { | ||
const fallbackSlot = fallback ? () => [h(Text, fallback)] : undefined | ||
if (typeof parent === "string") { | ||
return slots.default ? slots.default(defaultPayload) : fallback; | ||
return slots.default ? slots.default(defaultPayload) : fallbackSlot?.() | ||
} else { | ||
if (slots.default) { | ||
const content = slots.default(defaultPayload); | ||
const content = slots.default(defaultPayload) | ||
return content.length | ||
? { | ||
...slots, | ||
default: () => content, | ||
} | ||
: fallback; | ||
return { | ||
...slots, | ||
default: content.length ? () => content : fallbackSlot, | ||
} | ||
} else { | ||
return fallback; | ||
return fallbackSlot | ||
} | ||
} | ||
}; | ||
} |
@@ -13,9 +13,9 @@ /** | ||
*/ | ||
const isInternal = /^\/(?!\/)/.test(url); | ||
const isInternal = /^\/(?!\/)/.test(url) | ||
/** | ||
* @see Regex101 expression: {@link https://regex101.com/r/RnUseS/1} | ||
*/ | ||
const isSpecialLink = !isInternal && !/^https?:\/\//i.test(url); | ||
const isSpecialLink = !isInternal && !/^https?:\/\//i.test(url) | ||
return isInternal && !isSpecialLink; | ||
}; | ||
return isInternal && !isSpecialLink | ||
} |
@@ -1,8 +0,3 @@ | ||
import { | ||
ConcreteComponent, | ||
DefineComponent, | ||
Raw, | ||
VNode, | ||
resolveDynamicComponent, | ||
} from "vue"; | ||
import type { ConcreteComponent, DefineComponent, Raw, VNode } from "vue" | ||
import { resolveDynamicComponent } from "vue" | ||
@@ -22,3 +17,3 @@ /** | ||
): string | VNode => { | ||
return resolveDynamicComponent(component) as string | VNode; | ||
}; | ||
return resolveDynamicComponent(component) as string | VNode | ||
} |
113
src/types.ts
@@ -19,8 +19,8 @@ import type { | ||
isFilled, | ||
} from "@prismicio/client"; | ||
import type { App, ConcreteComponent, DefineComponent, Raw, Ref } from "vue"; | ||
} from "@prismicio/client" | ||
import type { App, ConcreteComponent, DefineComponent, Raw, Ref } from "vue" | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// Imports for @link references: | ||
import type { RouterLink } from "vue-router"; | ||
import type { RouterLink } from "vue-router" | ||
@@ -31,5 +31,5 @@ import type { | ||
TODOSliceComponent, | ||
} from "./components/SliceZone"; | ||
} from "./components/SliceZone" | ||
import type { usePrismicDocuments } from "./composables"; | ||
import type { usePrismicDocuments } from "./composables" | ||
@@ -48,3 +48,3 @@ /* eslint-enable @typescript-eslint/no-unused-vars */ | ||
*/ | ||
linkBlankTargetRelAttribute?: string; | ||
linkBlankTargetRelAttribute?: string | ||
@@ -61,5 +61,6 @@ /** | ||
* (`to` props). | ||
* | ||
* @defaultValue {@link RouterLink} | ||
*/ | ||
linkInternalComponent?: string | ConcreteComponent | Raw<DefineComponent>; | ||
linkInternalComponent?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -76,5 +77,6 @@ /** | ||
* (`to` props). | ||
* | ||
* @defaultValue `"a"` | ||
*/ | ||
linkExternalComponent?: string | ConcreteComponent | Raw<DefineComponent>; | ||
linkExternalComponent?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -89,5 +91,6 @@ /** | ||
* additional `copyright` props. | ||
* | ||
* @defaultValue `"img"` | ||
*/ | ||
imageComponent?: string | ConcreteComponent | Raw<DefineComponent>; | ||
imageComponent?: string | ConcreteComponent | Raw<DefineComponent> | ||
@@ -101,5 +104,6 @@ /** | ||
* images in the editor. | ||
* | ||
* @defaultValue `@prismicio/client` defaults | ||
*/ | ||
imageWidthSrcSetDefaults?: number[]; | ||
imageWidthSrcSetDefaults?: number[] | ||
@@ -112,3 +116,3 @@ /** | ||
*/ | ||
imagePixelDensitySrcSetDefaults?: number[]; | ||
imagePixelDensitySrcSetDefaults?: number[] | ||
@@ -124,4 +128,4 @@ /** | ||
*/ | ||
sliceZoneDefaultComponent?: SliceComponentType; | ||
}; | ||
sliceZoneDefaultComponent?: SliceComponentType | ||
} | ||
@@ -139,3 +143,3 @@ /** | ||
*/ | ||
linkResolver?: LinkResolverFunction; | ||
linkResolver?: LinkResolverFunction | ||
@@ -150,3 +154,3 @@ /** | ||
| HTMLRichTextFunctionSerializer | ||
| HTMLRichTextMapSerializer; | ||
| HTMLRichTextMapSerializer | ||
@@ -162,3 +166,3 @@ /** | ||
// TODO: Remove in v5 | ||
htmlSerializer?: HTMLRichTextFunctionSerializer | HTMLRichTextMapSerializer; | ||
htmlSerializer?: HTMLRichTextFunctionSerializer | HTMLRichTextMapSerializer | ||
@@ -170,3 +174,3 @@ /** | ||
*/ | ||
injectComponents?: boolean; | ||
injectComponents?: boolean | ||
@@ -178,4 +182,4 @@ /** | ||
*/ | ||
components?: PrismicPluginComponentsOptions; | ||
}; | ||
components?: PrismicPluginComponentsOptions | ||
} | ||
@@ -196,5 +200,6 @@ /** | ||
* `usePrismic().client`. | ||
* | ||
* @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript} | ||
*/ | ||
client: ReturnType<CreateClient>; | ||
client: ReturnType<CreateClient> | ||
@@ -206,3 +211,3 @@ /** | ||
*/ | ||
endpoint?: never; | ||
endpoint?: never | ||
@@ -214,4 +219,4 @@ /** | ||
*/ | ||
clientConfig?: never; | ||
}; | ||
clientConfig?: never | ||
} | ||
@@ -232,2 +237,3 @@ /** | ||
* `usePrismic().client`. | ||
* | ||
* @example | ||
@@ -237,6 +243,6 @@ * | ||
* // A repository ID | ||
* "my-repo"; | ||
* "my-repo" | ||
* | ||
* //A full repository endpoint | ||
* "https://my-repo.cdn.prismic.io/api/v2"; | ||
* "https://my-repo.cdn.prismic.io/api/v2" | ||
* ``` | ||
@@ -246,3 +252,3 @@ * | ||
*/ | ||
endpoint: string; | ||
endpoint: string | ||
@@ -284,3 +290,3 @@ /** | ||
*/ | ||
clientConfig?: ClientConfig; | ||
clientConfig?: ClientConfig | ||
@@ -292,4 +298,4 @@ /** | ||
*/ | ||
client?: never; | ||
}; | ||
client?: never | ||
} | ||
@@ -304,3 +310,3 @@ /** | ||
| PrismicPluginOptionsWithClient | ||
| PrismicPluginOptionsWithEndpoint; | ||
| PrismicPluginOptionsWithEndpoint | ||
@@ -316,3 +322,3 @@ /** | ||
*/ | ||
client: ReturnType<CreateClient>; | ||
client: ReturnType<CreateClient> | ||
@@ -322,3 +328,3 @@ /** | ||
*/ | ||
filter: typeof filter; | ||
filter: typeof filter | ||
@@ -328,4 +334,4 @@ /** | ||
*/ | ||
cookie: typeof cookie; | ||
}; | ||
cookie: typeof cookie | ||
} | ||
@@ -343,3 +349,3 @@ /** | ||
*/ | ||
asText: typeof asText; | ||
asText: typeof asText | ||
@@ -356,5 +362,6 @@ /** | ||
* to the plugin at {@link PrismicPluginOptions.htmlSerializer} if available. | ||
* | ||
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles} | ||
*/ | ||
asHTML: typeof asHTML; | ||
asHTML: typeof asHTML | ||
@@ -368,5 +375,6 @@ /** | ||
* the plugin at {@link PrismicPluginOptions.linkResolver} if available. | ||
* | ||
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships} | ||
*/ | ||
asLink: typeof asLink; | ||
asLink: typeof asLink | ||
@@ -380,5 +388,6 @@ /** | ||
* the plugin at {@link PrismicPluginOptions.linkResolver} if available. | ||
* | ||
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships} | ||
*/ | ||
asLinkAttrs: typeof asLinkAttrs; | ||
asLinkAttrs: typeof asLinkAttrs | ||
@@ -389,3 +398,3 @@ /** | ||
*/ | ||
asDate: typeof asDate; | ||
asDate: typeof asDate | ||
@@ -397,3 +406,3 @@ /** | ||
*/ | ||
asImageSrc: typeof asImageSrc; | ||
asImageSrc: typeof asImageSrc | ||
@@ -405,3 +414,3 @@ /** | ||
*/ | ||
asImageWidthSrcSet: typeof asImageWidthSrcSet; | ||
asImageWidthSrcSet: typeof asImageWidthSrcSet | ||
@@ -413,3 +422,3 @@ /** | ||
*/ | ||
asImagePixelDensitySrcSet: typeof asImagePixelDensitySrcSet; | ||
asImagePixelDensitySrcSet: typeof asImagePixelDensitySrcSet | ||
@@ -420,3 +429,3 @@ /** | ||
*/ | ||
isFilled: typeof isFilled; | ||
isFilled: typeof isFilled | ||
@@ -429,4 +438,4 @@ /** | ||
*/ | ||
documentToLinkField: typeof documentToLinkField; | ||
}; | ||
documentToLinkField: typeof documentToLinkField | ||
} | ||
@@ -443,3 +452,3 @@ /** | ||
*/ | ||
readonly options: PrismicPluginOptions; | ||
readonly options: PrismicPluginOptions | ||
@@ -451,5 +460,5 @@ /** | ||
*/ | ||
install: (app: App) => void; | ||
install: (app: App) => void | ||
} & PrismicPluginClient & | ||
PrismicPluginHelpers; | ||
PrismicPluginHelpers | ||
@@ -490,4 +499,4 @@ /** | ||
export type VueUseOptions<T> = { | ||
[K in keyof T]: Ref<T[K]> | T[K]; | ||
}; | ||
[K in keyof T]: Ref<T[K]> | T[K] | ||
} | ||
@@ -500,3 +509,3 @@ /** | ||
export type VueUseParameters<T> = { | ||
[K in keyof T]: T extends number ? Ref<T[K]> | T[K] : T[K]; | ||
}; | ||
[K in keyof T]: T extends number ? Ref<T[K]> | T[K] : T[K] | ||
} |
@@ -1,6 +0,6 @@ | ||
import { inject } from "vue"; | ||
import { inject } from "vue" | ||
import { PrismicPlugin } from "./types"; | ||
import type { PrismicPlugin } from "./types" | ||
import { prismicKey } from "./injectionSymbols"; | ||
import { prismicKey } from "./injectionSymbols" | ||
@@ -14,11 +14,11 @@ /** | ||
* // With the composition API | ||
* import { usePrismic } from "@prismicio/vue"; | ||
* import { usePrismic } from "@prismicio/vue" | ||
* | ||
* export default { | ||
* setup() { | ||
* const prismic = usePrismic(); | ||
* const prismic = usePrismic() | ||
* | ||
* return {}; | ||
* return {} | ||
* }, | ||
* }; | ||
* } | ||
* ``` | ||
@@ -29,3 +29,3 @@ * | ||
export const usePrismic = (): PrismicPlugin => { | ||
return inject(prismicKey, { options: { endpoint: "" } } as PrismicPlugin); | ||
}; | ||
return inject(prismicKey, { options: { endpoint: "" } } as PrismicPlugin) | ||
} |
@@ -1,2 +0,2 @@ | ||
import { | ||
import type { | ||
Client, | ||
@@ -6,15 +6,17 @@ ForbiddenError, | ||
PrismicError, | ||
} from "@prismicio/client"; | ||
import { Ref, isRef, ref, shallowRef, unref, watch } from "vue"; | ||
} from "@prismicio/client" | ||
import type { Ref } from "vue" | ||
import { isRef, ref, shallowRef, unref, watch } from "vue" | ||
import { PrismicClientComposableState, VueUseParameters } from "./types"; | ||
import type { VueUseParameters } from "./types" | ||
import { PrismicClientComposableState } from "./types" | ||
import { usePrismic } from "./usePrismic"; | ||
import { usePrismic } from "./usePrismic" | ||
// Helpers | ||
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T; | ||
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type ClientMethodLike = (...args: any[]) => Promise<any> | any; | ||
type ClientMethods = typeof Client.prototype; | ||
type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError; | ||
type ClientMethodLike = (...args: any[]) => Promise<any> | any | ||
type ClientMethods = typeof Client.prototype | ||
type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError | ||
@@ -29,3 +31,3 @@ // Interfaces | ||
? VueUseParameters<Parameters<ClientMethods[TMethodName]>> | ||
: never; | ||
: never | ||
@@ -38,3 +40,3 @@ /** | ||
? ReturnType<ClientMethods[TMethodName]> | ||
: never; | ||
: never | ||
@@ -45,4 +47,4 @@ /** | ||
export type ComposableOnlyParameters = { | ||
client?: Ref<Client> | Client; | ||
}; | ||
client?: Ref<Client> | Client | ||
} | ||
@@ -59,3 +61,3 @@ /** | ||
*/ | ||
state: Ref<PrismicClientComposableState>; | ||
state: Ref<PrismicClientComposableState> | ||
@@ -65,3 +67,3 @@ /** | ||
*/ | ||
data: Ref<TData | null>; | ||
data: Ref<TData | null> | ||
@@ -72,3 +74,3 @@ /** | ||
*/ | ||
error: Ref<ClientError | Error | null>; | ||
error: Ref<ClientError | Error | null> | ||
@@ -78,4 +80,4 @@ /** | ||
*/ | ||
refresh: () => Promise<void>; | ||
}; | ||
refresh: () => Promise<void> | ||
} | ||
@@ -94,4 +96,4 @@ /** | ||
// This is a *very* naive check. | ||
return typeof value === "object" && value !== null && !Array.isArray(value); | ||
}; | ||
return typeof value === "object" && value !== null && !Array.isArray(value) | ||
} | ||
@@ -124,19 +126,19 @@ /** | ||
): ClientComposableReturnType<TClientMethodReturnType> => { | ||
const { client } = usePrismic(); | ||
const { client } = usePrismic() | ||
const state = ref<PrismicClientComposableState>( | ||
PrismicClientComposableState.Idle, | ||
); | ||
const data = shallowRef<TClientMethodReturnType | null>(null); | ||
const error = ref<ClientError | Error | null>(null); | ||
) | ||
const data = shallowRef<TClientMethodReturnType | null>(null) | ||
const error = ref<ClientError | Error | null>(null) | ||
const refresh = async (): Promise<void> => { | ||
const lastArg = unref(args[args.length - 1]); | ||
const lastArg = unref(args[args.length - 1]) | ||
const { client: explicitClient, ...params } = isParams(lastArg) | ||
? (lastArg as ClientMethodParameters<"get">[0] & ComposableOnlyParameters) | ||
: ({} as ComposableOnlyParameters); | ||
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args; | ||
: ({} as ComposableOnlyParameters) | ||
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args | ||
state.value = PrismicClientComposableState.Pending; | ||
data.value = null; | ||
error.value = null; | ||
state.value = PrismicClientComposableState.Pending | ||
data.value = null | ||
error.value = null | ||
try { | ||
@@ -148,20 +150,20 @@ data.value = await ( | ||
params, | ||
); | ||
state.value = PrismicClientComposableState.Success; | ||
) | ||
state.value = PrismicClientComposableState.Success | ||
} catch (err) { | ||
state.value = PrismicClientComposableState.Error; | ||
error.value = err as ClientError | Error; | ||
state.value = PrismicClientComposableState.Error | ||
error.value = err as ClientError | Error | ||
} | ||
}; | ||
} | ||
// Watch reactive args | ||
const refArgs = args.filter((arg) => isRef(arg)); | ||
const refArgs = args.filter((arg) => isRef(arg)) | ||
if (refArgs.length) { | ||
watch(refArgs, refresh, { deep: true }); | ||
watch(refArgs, refresh, { deep: true }) | ||
} | ||
// Fetch once | ||
refresh(); | ||
refresh() | ||
return { state, data, error, refresh }; | ||
}; | ||
return { state, data, error, refresh } | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
449335
26
7015
0
Updated@prismicio/client@^7.12.0
Updatedvue-router@^4.5.0