@prismicio/vue 3.1.4 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/PrismicEmbed.cjs.map +1 -1
- package/dist/components/PrismicEmbed.d.ts +57 -63
- package/dist/components/PrismicEmbed.js.map +1 -1
- package/dist/components/PrismicImage.cjs +2 -2
- package/dist/components/PrismicImage.cjs.map +1 -1
- package/dist/components/PrismicImage.d.ts +162 -162
- package/dist/components/PrismicImage.js +2 -2
- package/dist/components/PrismicImage.js.map +1 -1
- package/dist/components/PrismicLink.cjs +3 -3
- package/dist/components/PrismicLink.cjs.map +1 -1
- package/dist/components/PrismicLink.d.ts +191 -191
- package/dist/components/PrismicLink.js +3 -3
- package/dist/components/PrismicLink.js.map +1 -1
- package/dist/components/PrismicRichText.cjs +10 -5
- package/dist/components/PrismicRichText.cjs.map +1 -1
- package/dist/components/PrismicRichText.d.ts +160 -139
- package/dist/components/PrismicRichText.js +10 -5
- package/dist/components/PrismicRichText.js.map +1 -1
- package/dist/components/PrismicText.cjs +1 -1
- package/dist/components/PrismicText.cjs.map +1 -1
- package/dist/components/PrismicText.d.ts +117 -117
- package/dist/components/PrismicText.js +1 -1
- package/dist/components/PrismicText.js.map +1 -1
- package/dist/components/SliceZone.cjs +1 -1
- package/dist/components/SliceZone.cjs.map +1 -1
- package/dist/components/SliceZone.d.ts +357 -359
- package/dist/components/SliceZone.js +1 -1
- package/dist/components/SliceZone.js.map +1 -1
- package/dist/components/index.d.ts +12 -12
- package/dist/composables.cjs.map +1 -1
- package/dist/composables.d.ts +366 -366
- package/dist/composables.js.map +1 -1
- package/dist/createPrismic.cjs +3 -3
- package/dist/createPrismic.cjs.map +1 -1
- package/dist/createPrismic.d.ts +12 -12
- package/dist/createPrismic.js +3 -3
- package/dist/createPrismic.js.map +1 -1
- package/dist/globalExtensions.d.ts +11 -11
- package/dist/index.cjs +16 -16
- package/dist/index.d.ts +10 -10
- package/dist/index.js +3 -3
- package/dist/injectionSymbols.cjs.map +1 -1
- package/dist/injectionSymbols.d.ts +9 -9
- package/dist/injectionSymbols.js.map +1 -1
- package/dist/lib/__PRODUCTION__.d.ts +7 -7
- package/dist/lib/getSlots.d.ts +14 -14
- package/dist/lib/isInternalURL.d.ts +8 -8
- package/dist/lib/simplyResolveComponent.cjs.map +1 -1
- package/dist/lib/simplyResolveComponent.d.ts +12 -12
- package/dist/lib/simplyResolveComponent.js.map +1 -1
- package/dist/types.d.ts +366 -357
- package/dist/usePrismic.cjs.map +1 -1
- package/dist/usePrismic.d.ts +21 -21
- package/dist/usePrismic.js.map +1 -1
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +64 -64
- package/dist/useStatefulPrismicClientMethod.js.map +1 -1
- package/package.json +31 -23
- package/src/components/PrismicEmbed.ts +10 -5
- package/src/components/PrismicImage.ts +20 -15
- package/src/components/PrismicLink.ts +23 -16
- package/src/components/PrismicRichText.ts +44 -18
- package/src/components/PrismicText.ts +13 -9
- package/src/components/SliceZone.ts +12 -8
- package/src/composables.ts +2 -5
- package/src/createPrismic.ts +18 -21
- package/src/injectionSymbols.ts +0 -2
- package/src/lib/simplyResolveComponent.ts +8 -2
- package/src/types.ts +24 -16
- package/src/usePrismic.ts +2 -1
- package/src/useStatefulPrismicClientMethod.ts +3 -3
- package/vetur/attributes.json +1 -6
- package/vetur/tags.json +17 -3
package/dist/usePrismic.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrismic.cjs","sources":["../../src/usePrismic.ts"],"sourcesContent":["import { inject } from \"vue\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"usePrismic.cjs","sources":["../../src/usePrismic.ts"],"sourcesContent":["import { inject } from \"vue\";\n\nimport { PrismicPlugin } from \"./types\";\n\nimport { prismicKey } from \"./injectionSymbols\";\n\n/**\n * Accesses `@prismicio/vue` plugin interface.\n *\n * @example With the composition API:\n *\n * ```javascript\n * import { usePrismic } from \"@prismicio/vue\";\n *\n * export default {\n * \tsetup() {\n * \t\tconst prismic = usePrismic();\n *\n * \t\treturn {};\n * \t},\n * };\n * ```\n *\n * @returns The interface {@link PrismicPlugin}\n */\nexport const usePrismic = (): PrismicPlugin => {\n\treturn inject(prismicKey, { options: { endpoint: \"\" } } as PrismicPlugin);\n};\n"],"names":["inject","prismicKey"],"mappings":";;;;AAyBO,MAAM,aAAa,MAAoB;AACtC,SAAAA,IAAAA,OAAOC,iBAAAA,YAAY,EAAE,SAAS,EAAE,UAAU,MAAuB;AACzE;;"}
|
package/dist/usePrismic.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { PrismicPlugin } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Accesses `@prismicio/vue` plugin interface.
|
|
4
|
-
*
|
|
5
|
-
* @example With the composition API:
|
|
6
|
-
*
|
|
7
|
-
* ```javascript
|
|
8
|
-
* import { usePrismic } from "@prismicio/vue";
|
|
9
|
-
*
|
|
10
|
-
* export default {
|
|
11
|
-
* setup() {
|
|
12
|
-
* const prismic = usePrismic();
|
|
13
|
-
*
|
|
14
|
-
* return {};
|
|
15
|
-
* },
|
|
16
|
-
* };
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @returns The interface {@link PrismicPlugin}
|
|
20
|
-
*/
|
|
21
|
-
export declare const usePrismic: () => PrismicPlugin;
|
|
1
|
+
import { PrismicPlugin } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Accesses `@prismicio/vue` plugin interface.
|
|
4
|
+
*
|
|
5
|
+
* @example With the composition API:
|
|
6
|
+
*
|
|
7
|
+
* ```javascript
|
|
8
|
+
* import { usePrismic } from "@prismicio/vue";
|
|
9
|
+
*
|
|
10
|
+
* export default {
|
|
11
|
+
* setup() {
|
|
12
|
+
* const prismic = usePrismic();
|
|
13
|
+
*
|
|
14
|
+
* return {};
|
|
15
|
+
* },
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @returns The interface {@link PrismicPlugin}
|
|
20
|
+
*/
|
|
21
|
+
export declare const usePrismic: () => PrismicPlugin;
|
package/dist/usePrismic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrismic.js","sources":["../../src/usePrismic.ts"],"sourcesContent":["import { inject } from \"vue\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"usePrismic.js","sources":["../../src/usePrismic.ts"],"sourcesContent":["import { inject } from \"vue\";\n\nimport { PrismicPlugin } from \"./types\";\n\nimport { prismicKey } from \"./injectionSymbols\";\n\n/**\n * Accesses `@prismicio/vue` plugin interface.\n *\n * @example With the composition API:\n *\n * ```javascript\n * import { usePrismic } from \"@prismicio/vue\";\n *\n * export default {\n * \tsetup() {\n * \t\tconst prismic = usePrismic();\n *\n * \t\treturn {};\n * \t},\n * };\n * ```\n *\n * @returns The interface {@link PrismicPlugin}\n */\nexport const usePrismic = (): PrismicPlugin => {\n\treturn inject(prismicKey, { options: { endpoint: \"\" } } as PrismicPlugin);\n};\n"],"names":[],"mappings":";;AAyBO,MAAM,aAAa,MAAoB;AACtC,SAAA,OAAO,YAAY,EAAE,SAAS,EAAE,UAAU,MAAuB;AACzE;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStatefulPrismicClientMethod.cjs","sources":["../../src/useStatefulPrismicClientMethod.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useStatefulPrismicClientMethod.cjs","sources":["../../src/useStatefulPrismicClientMethod.ts"],"sourcesContent":["import {\n\tClient,\n\tForbiddenError,\n\tParsingError,\n\tPrismicError,\n} from \"@prismicio/client\";\nimport { Ref, isRef, ref, shallowRef, unref, watch } from \"vue\";\n\nimport { PrismicClientComposableState, VueUseParameters } from \"./types\";\n\nimport { usePrismic } from \"./usePrismic\";\n\n// Helpers\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ClientMethodLike = (...args: any[]) => Promise<any> | any;\ntype ClientMethods = typeof Client.prototype;\ntype ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;\n\n// Interfaces\n\n/**\n * @internal\n */\nexport type ClientMethodParameters<TMethodName extends keyof ClientMethods> =\n\tClientMethods[TMethodName] extends ClientMethodLike\n\t\t? VueUseParameters<Parameters<ClientMethods[TMethodName]>>\n\t\t: never;\n\n/**\n * @internal\n */\nexport type ClientMethodReturnType<TMethodName extends keyof ClientMethods> =\n\tClientMethods[TMethodName] extends ClientMethodLike\n\t\t? ReturnType<ClientMethods[TMethodName]>\n\t\t: never;\n\n/**\n * @internal\n */\nexport type ComposableOnlyParameters = {\n\tclient?: Ref<Client> | Client;\n};\n\n/**\n * The return type of a `@prismicio/client` Vue composable.\n *\n * @typeParam TData - The expected format of the `data` property of the returned\n * object\n */\nexport type ClientComposableReturnType<TData = unknown> = {\n\t/**\n\t * The current state of the composable's client method call.\n\t */\n\tstate: Ref<PrismicClientComposableState>;\n\n\t/**\n\t * Data returned by the client.\n\t */\n\tdata: Ref<TData | null>;\n\n\t/**\n\t * Error returned by the composable's client method call if in an errror\n\t * state.\n\t */\n\terror: Ref<ClientError | Error | null>;\n\n\t/**\n\t * Perform the composable's client method call again.\n\t */\n\trefresh: () => Promise<void>;\n};\n\n/**\n * Determines if a value is a `@prismicio/client` params object.\n *\n * @param value - The value to check\n *\n * @returns `true` if `value` is a `@prismicio/client` params object, `false`\n * otherwise\n */\nconst isParams = (\n\tvalue: unknown,\n): value is ClientMethodParameters<\"get\">[0] & ComposableOnlyParameters => {\n\t// This is a *very* naive check.\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\n/**\n * A low level Vue composable that uses provided method name on plugin or\n * provided client with given arguments. The composable has its own internal\n * state manager to report async status, such as pending or error statuses.\n *\n * @typeParam TClientMethodName - A method name from `@prismicio/client`\n * @typeParam TClientMethodArguments - The method expected arguments\n * @typeParam TClientMethodReturnType - The method expected return type\n *\n * @param method - The `@prismicio/client` method name to use\n * @param args - The arguments to use with requested method\n *\n * @returns The composable payload {@link ClientComposableReturnType}\n *\n * @internal\n */\nexport const useStatefulPrismicClientMethod = <\n\tTClientMethodName extends keyof ClientMethods,\n\tTClientMethodArguments extends ClientMethodParameters<TClientMethodName>,\n\tTClientMethodReturnType extends UnwrapPromise<\n\t\tClientMethodReturnType<TClientMethodName>\n\t>,\n>(\n\tmethodName: TClientMethodName,\n\targs: TClientMethodArguments,\n): ClientComposableReturnType<TClientMethodReturnType> => {\n\tconst { client } = usePrismic();\n\n\tconst state = ref<PrismicClientComposableState>(\n\t\tPrismicClientComposableState.Idle,\n\t);\n\tconst data = shallowRef<TClientMethodReturnType | null>(null);\n\tconst error = ref<ClientError | Error | null>(null);\n\tconst refresh = async (): Promise<void> => {\n\t\tconst lastArg = unref(args[args.length - 1]);\n\t\tconst { client: explicitClient, ...params } = isParams(lastArg)\n\t\t\t? (lastArg as ClientMethodParameters<\"get\">[0] & ComposableOnlyParameters)\n\t\t\t: ({} as ComposableOnlyParameters);\n\t\tconst argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;\n\n\t\tstate.value = PrismicClientComposableState.Pending;\n\t\tdata.value = null;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tdata.value = await (\n\t\t\t\t(unref(explicitClient) || client)[methodName] as ClientMethodLike\n\t\t\t)(\n\t\t\t\t...argsWithoutParams.map((arg: Ref<unknown> | unknown) => unref(arg)),\n\t\t\t\tparams,\n\t\t\t);\n\t\t\tstate.value = PrismicClientComposableState.Success;\n\t\t} catch (err) {\n\t\t\tstate.value = PrismicClientComposableState.Error;\n\t\t\terror.value = err as ClientError | Error;\n\t\t}\n\t};\n\n\t// Watch reactive args\n\tconst refArgs = args.filter((arg) => isRef(arg));\n\tif (refArgs.length) {\n\t\twatch(refArgs, refresh, { deep: true });\n\t}\n\n\t// Fetch once\n\trefresh();\n\n\treturn { state, data, error, refresh };\n};\n"],"names":["usePrismic","ref","shallowRef","unref","isRef","watch"],"mappings":";;;;AAiFA,MAAM,WAAW,CAChB,UACyE;AAElE,SAAA,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;AAkBa,MAAA,iCAAiC,CAO7C,YACA,SACwD;AAClD,QAAA,EAAE,WAAWA,WAAAA;AAEnB,QAAM,QAAQC,IAAA;AAAA,IAAG;AAAA;AAAA,EAAA;AAGX,QAAA,OAAOC,eAA2C,IAAI;AACtD,QAAA,QAAQD,QAAgC,IAAI;AAClD,QAAM,UAAU,YAA0B;AACzC,UAAM,UAAUE,IAAAA,MAAM,KAAK,KAAK,SAAS,CAAC,CAAC;AACrC,UAAA,EAAE,QAAQ,gBAAgB,GAAG,OAAA,IAAW,SAAS,OAAO,IAC1D,UACA;AACE,UAAA,oBAAoB,SAAS,OAAO,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI;AAElE,UAAM,QAAK;AACX,SAAK,QAAQ;AACb,UAAM,QAAQ;AACV,QAAA;AACH,WAAK,QAAQ,OACXA,IAAAA,MAAM,cAAc,KAAK,QAAQ,UAAU,EAE5C,GAAG,kBAAkB,IAAI,CAAC,QAAgCA,IAAAA,MAAM,GAAG,CAAC,GACpE,MAAM;AAEP,YAAM,QAAK;AAAA,aACH;AACR,YAAM,QAAK;AACX,YAAM,QAAQ;AAAA,IACd;AAAA,EAAA;AAIF,QAAM,UAAU,KAAK,OAAO,CAAC,QAAQC,IAAA,MAAM,GAAG,CAAC;AAC/C,MAAI,QAAQ,QAAQ;AACnBC,QAAA,MAAM,SAAS,SAAS,EAAE,MAAM,KAAM,CAAA;AAAA,EACtC;;AAKD,SAAO,EAAE,OAAO,MAAM,OAAO,QAAO;AACrC;;"}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { PrismicClientComposableState, VueUseParameters } from "./types";
|
|
4
|
-
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
5
|
-
type ClientMethodLike = (...args: any[]) => Promise<any> | any;
|
|
6
|
-
type ClientMethods = typeof Client.prototype;
|
|
7
|
-
type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export type ClientMethodParameters<TMethodName extends keyof ClientMethods> = ClientMethods[TMethodName] extends ClientMethodLike ? VueUseParameters<Parameters<ClientMethods[TMethodName]>> : never;
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export type ClientMethodReturnType<TMethodName extends keyof ClientMethods> = ClientMethods[TMethodName] extends ClientMethodLike ? ReturnType<ClientMethods[TMethodName]> : never;
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export type ComposableOnlyParameters = {
|
|
20
|
-
client?: Ref<Client> | Client;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* The return type of a `@prismicio/client` Vue composable.
|
|
24
|
-
*
|
|
25
|
-
* @typeParam TData - The expected format of the `data` property of the returned
|
|
26
|
-
* object
|
|
27
|
-
*/
|
|
28
|
-
export type ClientComposableReturnType<TData = unknown> = {
|
|
29
|
-
/**
|
|
30
|
-
* The current state of the composable's client method call.
|
|
31
|
-
*/
|
|
32
|
-
state: Ref<PrismicClientComposableState>;
|
|
33
|
-
/**
|
|
34
|
-
* Data returned by the client.
|
|
35
|
-
*/
|
|
36
|
-
data: Ref<TData | null>;
|
|
37
|
-
/**
|
|
38
|
-
* Error returned by the composable's client method call if in an errror
|
|
39
|
-
* state.
|
|
40
|
-
*/
|
|
41
|
-
error: Ref<ClientError | Error | null>;
|
|
42
|
-
/**
|
|
43
|
-
* Perform the composable's client method call again.
|
|
44
|
-
*/
|
|
45
|
-
refresh: () => Promise<void>;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* A low level Vue composable that uses provided method name on plugin or
|
|
49
|
-
* provided client with given arguments. The composable has its own internal
|
|
50
|
-
* state manager to report async status, such as pending or error statuses.
|
|
51
|
-
*
|
|
52
|
-
* @typeParam TClientMethodName - A method name from `@prismicio/client`
|
|
53
|
-
* @typeParam TClientMethodArguments - The method expected arguments
|
|
54
|
-
* @typeParam TClientMethodReturnType - The method expected return type
|
|
55
|
-
*
|
|
56
|
-
* @param method - The `@prismicio/client` method name to use
|
|
57
|
-
* @param args - The arguments to use with requested method
|
|
58
|
-
*
|
|
59
|
-
* @returns The composable payload {@link ClientComposableReturnType}
|
|
60
|
-
*
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
export declare const useStatefulPrismicClientMethod: <TClientMethodName extends keyof Client<any>, TClientMethodArguments extends ClientMethodParameters<TClientMethodName>, TClientMethodReturnType extends UnwrapPromise<ClientMethodReturnType<TClientMethodName>>>(methodName: TClientMethodName, args: TClientMethodArguments) => ClientComposableReturnType<TClientMethodReturnType>;
|
|
64
|
-
export {};
|
|
1
|
+
import { Client, ForbiddenError, ParsingError, PrismicError } from "@prismicio/client";
|
|
2
|
+
import { Ref } from "vue";
|
|
3
|
+
import { PrismicClientComposableState, VueUseParameters } from "./types";
|
|
4
|
+
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
5
|
+
type ClientMethodLike = (...args: any[]) => Promise<any> | any;
|
|
6
|
+
type ClientMethods = typeof Client.prototype;
|
|
7
|
+
type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export type ClientMethodParameters<TMethodName extends keyof ClientMethods> = ClientMethods[TMethodName] extends ClientMethodLike ? VueUseParameters<Parameters<ClientMethods[TMethodName]>> : never;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export type ClientMethodReturnType<TMethodName extends keyof ClientMethods> = ClientMethods[TMethodName] extends ClientMethodLike ? ReturnType<ClientMethods[TMethodName]> : never;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type ComposableOnlyParameters = {
|
|
20
|
+
client?: Ref<Client> | Client;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The return type of a `@prismicio/client` Vue composable.
|
|
24
|
+
*
|
|
25
|
+
* @typeParam TData - The expected format of the `data` property of the returned
|
|
26
|
+
* object
|
|
27
|
+
*/
|
|
28
|
+
export type ClientComposableReturnType<TData = unknown> = {
|
|
29
|
+
/**
|
|
30
|
+
* The current state of the composable's client method call.
|
|
31
|
+
*/
|
|
32
|
+
state: Ref<PrismicClientComposableState>;
|
|
33
|
+
/**
|
|
34
|
+
* Data returned by the client.
|
|
35
|
+
*/
|
|
36
|
+
data: Ref<TData | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Error returned by the composable's client method call if in an errror
|
|
39
|
+
* state.
|
|
40
|
+
*/
|
|
41
|
+
error: Ref<ClientError | Error | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Perform the composable's client method call again.
|
|
44
|
+
*/
|
|
45
|
+
refresh: () => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A low level Vue composable that uses provided method name on plugin or
|
|
49
|
+
* provided client with given arguments. The composable has its own internal
|
|
50
|
+
* state manager to report async status, such as pending or error statuses.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam TClientMethodName - A method name from `@prismicio/client`
|
|
53
|
+
* @typeParam TClientMethodArguments - The method expected arguments
|
|
54
|
+
* @typeParam TClientMethodReturnType - The method expected return type
|
|
55
|
+
*
|
|
56
|
+
* @param method - The `@prismicio/client` method name to use
|
|
57
|
+
* @param args - The arguments to use with requested method
|
|
58
|
+
*
|
|
59
|
+
* @returns The composable payload {@link ClientComposableReturnType}
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare const useStatefulPrismicClientMethod: <TClientMethodName extends keyof Client<any>, TClientMethodArguments extends ClientMethodParameters<TClientMethodName>, TClientMethodReturnType extends UnwrapPromise<ClientMethodReturnType<TClientMethodName>>>(methodName: TClientMethodName, args: TClientMethodArguments) => ClientComposableReturnType<TClientMethodReturnType>;
|
|
64
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStatefulPrismicClientMethod.js","sources":["../../src/useStatefulPrismicClientMethod.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useStatefulPrismicClientMethod.js","sources":["../../src/useStatefulPrismicClientMethod.ts"],"sourcesContent":["import {\n\tClient,\n\tForbiddenError,\n\tParsingError,\n\tPrismicError,\n} from \"@prismicio/client\";\nimport { Ref, isRef, ref, shallowRef, unref, watch } from \"vue\";\n\nimport { PrismicClientComposableState, VueUseParameters } from \"./types\";\n\nimport { usePrismic } from \"./usePrismic\";\n\n// Helpers\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ClientMethodLike = (...args: any[]) => Promise<any> | any;\ntype ClientMethods = typeof Client.prototype;\ntype ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;\n\n// Interfaces\n\n/**\n * @internal\n */\nexport type ClientMethodParameters<TMethodName extends keyof ClientMethods> =\n\tClientMethods[TMethodName] extends ClientMethodLike\n\t\t? VueUseParameters<Parameters<ClientMethods[TMethodName]>>\n\t\t: never;\n\n/**\n * @internal\n */\nexport type ClientMethodReturnType<TMethodName extends keyof ClientMethods> =\n\tClientMethods[TMethodName] extends ClientMethodLike\n\t\t? ReturnType<ClientMethods[TMethodName]>\n\t\t: never;\n\n/**\n * @internal\n */\nexport type ComposableOnlyParameters = {\n\tclient?: Ref<Client> | Client;\n};\n\n/**\n * The return type of a `@prismicio/client` Vue composable.\n *\n * @typeParam TData - The expected format of the `data` property of the returned\n * object\n */\nexport type ClientComposableReturnType<TData = unknown> = {\n\t/**\n\t * The current state of the composable's client method call.\n\t */\n\tstate: Ref<PrismicClientComposableState>;\n\n\t/**\n\t * Data returned by the client.\n\t */\n\tdata: Ref<TData | null>;\n\n\t/**\n\t * Error returned by the composable's client method call if in an errror\n\t * state.\n\t */\n\terror: Ref<ClientError | Error | null>;\n\n\t/**\n\t * Perform the composable's client method call again.\n\t */\n\trefresh: () => Promise<void>;\n};\n\n/**\n * Determines if a value is a `@prismicio/client` params object.\n *\n * @param value - The value to check\n *\n * @returns `true` if `value` is a `@prismicio/client` params object, `false`\n * otherwise\n */\nconst isParams = (\n\tvalue: unknown,\n): value is ClientMethodParameters<\"get\">[0] & ComposableOnlyParameters => {\n\t// This is a *very* naive check.\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\n/**\n * A low level Vue composable that uses provided method name on plugin or\n * provided client with given arguments. The composable has its own internal\n * state manager to report async status, such as pending or error statuses.\n *\n * @typeParam TClientMethodName - A method name from `@prismicio/client`\n * @typeParam TClientMethodArguments - The method expected arguments\n * @typeParam TClientMethodReturnType - The method expected return type\n *\n * @param method - The `@prismicio/client` method name to use\n * @param args - The arguments to use with requested method\n *\n * @returns The composable payload {@link ClientComposableReturnType}\n *\n * @internal\n */\nexport const useStatefulPrismicClientMethod = <\n\tTClientMethodName extends keyof ClientMethods,\n\tTClientMethodArguments extends ClientMethodParameters<TClientMethodName>,\n\tTClientMethodReturnType extends UnwrapPromise<\n\t\tClientMethodReturnType<TClientMethodName>\n\t>,\n>(\n\tmethodName: TClientMethodName,\n\targs: TClientMethodArguments,\n): ClientComposableReturnType<TClientMethodReturnType> => {\n\tconst { client } = usePrismic();\n\n\tconst state = ref<PrismicClientComposableState>(\n\t\tPrismicClientComposableState.Idle,\n\t);\n\tconst data = shallowRef<TClientMethodReturnType | null>(null);\n\tconst error = ref<ClientError | Error | null>(null);\n\tconst refresh = async (): Promise<void> => {\n\t\tconst lastArg = unref(args[args.length - 1]);\n\t\tconst { client: explicitClient, ...params } = isParams(lastArg)\n\t\t\t? (lastArg as ClientMethodParameters<\"get\">[0] & ComposableOnlyParameters)\n\t\t\t: ({} as ComposableOnlyParameters);\n\t\tconst argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;\n\n\t\tstate.value = PrismicClientComposableState.Pending;\n\t\tdata.value = null;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tdata.value = await (\n\t\t\t\t(unref(explicitClient) || client)[methodName] as ClientMethodLike\n\t\t\t)(\n\t\t\t\t...argsWithoutParams.map((arg: Ref<unknown> | unknown) => unref(arg)),\n\t\t\t\tparams,\n\t\t\t);\n\t\t\tstate.value = PrismicClientComposableState.Success;\n\t\t} catch (err) {\n\t\t\tstate.value = PrismicClientComposableState.Error;\n\t\t\terror.value = err as ClientError | Error;\n\t\t}\n\t};\n\n\t// Watch reactive args\n\tconst refArgs = args.filter((arg) => isRef(arg));\n\tif (refArgs.length) {\n\t\twatch(refArgs, refresh, { deep: true });\n\t}\n\n\t// Fetch once\n\trefresh();\n\n\treturn { state, data, error, refresh };\n};\n"],"names":[],"mappings":";;AAiFA,MAAM,WAAW,CAChB,UACyE;AAElE,SAAA,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;AAkBa,MAAA,iCAAiC,CAO7C,YACA,SACwD;AAClD,QAAA,EAAE,WAAW;AAEnB,QAAM,QAAQ;AAAA,IAAG;AAAA;AAAA,EAAA;AAGX,QAAA,OAAO,WAA2C,IAAI;AACtD,QAAA,QAAQ,IAAgC,IAAI;AAClD,QAAM,UAAU,YAA0B;AACzC,UAAM,UAAU,MAAM,KAAK,KAAK,SAAS,CAAC,CAAC;AACrC,UAAA,EAAE,QAAQ,gBAAgB,GAAG,OAAA,IAAW,SAAS,OAAO,IAC1D,UACA;AACE,UAAA,oBAAoB,SAAS,OAAO,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI;AAElE,UAAM,QAAK;AACX,SAAK,QAAQ;AACb,UAAM,QAAQ;AACV,QAAA;AACH,WAAK,QAAQ,OACX,MAAM,cAAc,KAAK,QAAQ,UAAU,EAE5C,GAAG,kBAAkB,IAAI,CAAC,QAAgC,MAAM,GAAG,CAAC,GACpE,MAAM;AAEP,YAAM,QAAK;AAAA,aACH;AACR,YAAM,QAAK;AACX,YAAM,QAAQ;AAAA,IACd;AAAA,EAAA;AAIF,QAAM,UAAU,KAAK,OAAO,CAAC,QAAQ,MAAM,GAAG,CAAC;AAC/C,MAAI,QAAQ,QAAQ;AACnB,UAAM,SAAS,SAAS,EAAE,MAAM,KAAM,CAAA;AAAA,EACtC;;AAKD,SAAO,EAAE,OAAO,MAAM,OAAO,QAAO;AACrC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/vue",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Vue plugin, components, and composables to fetch and present Prismic content",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -18,8 +18,14 @@
|
|
|
18
18
|
"type": "module",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"require":
|
|
22
|
-
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
23
29
|
},
|
|
24
30
|
"./package.json": "./package.json"
|
|
25
31
|
},
|
|
@@ -35,7 +41,6 @@
|
|
|
35
41
|
"build": "vite build",
|
|
36
42
|
"dev": "vite build --watch",
|
|
37
43
|
"format": "prettier --write .",
|
|
38
|
-
"lint": "eslint --ext .js,.ts .",
|
|
39
44
|
"playground:build": "vite build playground",
|
|
40
45
|
"playground:dev": "vite playground",
|
|
41
46
|
"prepare": "npm run build",
|
|
@@ -43,46 +48,49 @@
|
|
|
43
48
|
"release:beta": "npm run test && standard-version --release-as major --prerelease beta && git push --follow-tags && npm run build && npm publish --tag beta",
|
|
44
49
|
"release:beta:dry": "standard-version --release-as major --prerelease beta --dry-run",
|
|
45
50
|
"release:dry": "standard-version --dry-run",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"types": "
|
|
51
|
+
"lint": "eslint --ext .js,.ts .",
|
|
52
|
+
"types": "vitest typecheck --run && tsc --noEmit",
|
|
53
|
+
"types:watch": "vitest typecheck",
|
|
49
54
|
"unit": "vitest run --coverage",
|
|
50
|
-
"unit:watch": "vitest watch"
|
|
55
|
+
"unit:watch": "vitest watch",
|
|
56
|
+
"size": "size-limit",
|
|
57
|
+
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
|
|
51
58
|
},
|
|
52
59
|
"dependencies": {
|
|
53
60
|
"@prismicio/client": "^6.7.3",
|
|
54
61
|
"@prismicio/helpers": "^2.3.9",
|
|
55
62
|
"@prismicio/types": "^0.2.7",
|
|
56
63
|
"isomorphic-unfetch": "^3.1.0",
|
|
57
|
-
"vue-router": "^4.1
|
|
64
|
+
"vue-router": "^4.2.1"
|
|
58
65
|
},
|
|
59
66
|
"devDependencies": {
|
|
60
67
|
"@prismicio/mock": "^0.2.0",
|
|
61
68
|
"@size-limit/preset-small-lib": "^8.2.4",
|
|
69
|
+
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
|
|
62
70
|
"@types/jsdom-global": "^3.0.4",
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
64
|
-
"@typescript-eslint/parser": "^5.
|
|
65
|
-
"@vitejs/plugin-vue": "^4.
|
|
66
|
-
"@vitest/coverage-c8": "^0.
|
|
67
|
-
"@vue/compiler-sfc": "^3.
|
|
68
|
-
"@vue/eslint-config-typescript": "^11.0.
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
72
|
+
"@typescript-eslint/parser": "^5.59.7",
|
|
73
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
74
|
+
"@vitest/coverage-c8": "^0.31.1",
|
|
75
|
+
"@vue/compiler-sfc": "^3.3.4",
|
|
76
|
+
"@vue/eslint-config-typescript": "^11.0.3",
|
|
69
77
|
"@vue/test-utils": "^2.3.2",
|
|
70
|
-
"eslint": "^8.
|
|
78
|
+
"eslint": "^8.41.0",
|
|
71
79
|
"eslint-config-prettier": "^8.8.0",
|
|
72
80
|
"eslint-plugin-prettier": "^4.2.1",
|
|
73
81
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
74
|
-
"eslint-plugin-vue": "^9.
|
|
75
|
-
"jsdom": "^
|
|
82
|
+
"eslint-plugin-vue": "^9.14.0",
|
|
83
|
+
"jsdom": "^22.0.0",
|
|
76
84
|
"jsdom-global": "^3.0.2",
|
|
77
|
-
"prettier": "^2.8.
|
|
85
|
+
"prettier": "^2.8.8",
|
|
78
86
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
79
87
|
"size-limit": "^8.2.4",
|
|
80
88
|
"standard-version": "^9.5.0",
|
|
81
|
-
"typescript": "^
|
|
82
|
-
"vite": "^4.
|
|
89
|
+
"typescript": "^5.0.4",
|
|
90
|
+
"vite": "^4.3.8",
|
|
83
91
|
"vite-plugin-sdk": "^0.1.1",
|
|
84
|
-
"vitest": "^0.
|
|
85
|
-
"vue": "^3.
|
|
92
|
+
"vitest": "^0.31.1",
|
|
93
|
+
"vue": "^3.3.4"
|
|
86
94
|
},
|
|
87
95
|
"peerDependencies": {
|
|
88
96
|
"vue": "^3.0.0"
|
|
@@ -2,15 +2,18 @@ import {
|
|
|
2
2
|
AllowedComponentProps,
|
|
3
3
|
ComponentCustomProps,
|
|
4
4
|
ConcreteComponent,
|
|
5
|
-
|
|
6
|
-
h,
|
|
5
|
+
DefineComponent,
|
|
7
6
|
PropType,
|
|
7
|
+
Raw,
|
|
8
8
|
VNodeProps,
|
|
9
|
+
defineComponent,
|
|
10
|
+
h,
|
|
9
11
|
} from "vue";
|
|
10
12
|
|
|
11
|
-
import { EmbedField } from "@prismicio/types";
|
|
12
13
|
import { simplyResolveComponent } from "../lib/simplyResolveComponent";
|
|
13
14
|
|
|
15
|
+
import { EmbedField } from "@prismicio/types";
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* The default component rendered to wrap the embed.
|
|
16
19
|
*/
|
|
@@ -31,7 +34,7 @@ export type PrismicEmbedProps = {
|
|
|
31
34
|
*
|
|
32
35
|
* @defaultValue `"div"`
|
|
33
36
|
*/
|
|
34
|
-
wrapper?: string | ConcreteComponent
|
|
37
|
+
wrapper?: string | ConcreteComponent | Raw<DefineComponent>;
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -47,7 +50,9 @@ export const PrismicEmbedImpl = /*#__PURE__*/ defineComponent({
|
|
|
47
50
|
required: true,
|
|
48
51
|
},
|
|
49
52
|
wrapper: {
|
|
50
|
-
type: [String, Object, Function] as PropType<
|
|
53
|
+
type: [String, Object, Function] as PropType<
|
|
54
|
+
string | ConcreteComponent | Raw<DefineComponent>
|
|
55
|
+
>,
|
|
51
56
|
default: undefined,
|
|
52
57
|
required: false,
|
|
53
58
|
},
|
|
@@ -1,28 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asImagePixelDensitySrcSet,
|
|
3
|
+
asImageSrc,
|
|
4
|
+
asImageWidthSrcSet,
|
|
5
|
+
isFilled,
|
|
6
|
+
} from "@prismicio/helpers";
|
|
1
7
|
import {
|
|
2
8
|
AllowedComponentProps,
|
|
3
9
|
ComponentCustomProps,
|
|
4
|
-
computed,
|
|
5
|
-
ConcreteComponent,
|
|
6
10
|
ComputedRef,
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
ConcreteComponent,
|
|
12
|
+
DefineComponent,
|
|
9
13
|
PropType,
|
|
14
|
+
Raw,
|
|
10
15
|
VNodeProps,
|
|
16
|
+
computed,
|
|
17
|
+
defineComponent,
|
|
18
|
+
h,
|
|
11
19
|
unref,
|
|
12
20
|
} from "vue";
|
|
13
21
|
|
|
22
|
+
import { __PRODUCTION__ } from "../lib/__PRODUCTION__";
|
|
23
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent";
|
|
24
|
+
|
|
25
|
+
import { VueUseOptions } from "../types";
|
|
14
26
|
import { ImageField } from "@prismicio/types";
|
|
15
|
-
import {
|
|
16
|
-
asImageSrc,
|
|
17
|
-
asImageWidthSrcSet,
|
|
18
|
-
asImagePixelDensitySrcSet,
|
|
19
|
-
isFilled,
|
|
20
|
-
} from "@prismicio/helpers";
|
|
21
27
|
|
|
22
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent";
|
|
23
|
-
import { __PRODUCTION__ } from "../lib/__PRODUCTION__";
|
|
24
28
|
import { usePrismic } from "../usePrismic";
|
|
25
|
-
import { VueUseOptions } from "../types";
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* The default component rendered for images.
|
|
@@ -48,7 +51,7 @@ export type PrismicImageProps = {
|
|
|
48
51
|
* receive an additional `copyright` props.
|
|
49
52
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"img"` otherwise.
|
|
50
53
|
*/
|
|
51
|
-
imageComponent?: string | ConcreteComponent
|
|
54
|
+
imageComponent?: string | ConcreteComponent | Raw<DefineComponent>;
|
|
52
55
|
|
|
53
56
|
/**
|
|
54
57
|
* An object of Imgix URL API parameters.
|
|
@@ -217,7 +220,9 @@ export const PrismicImageImpl = /*#__PURE__*/ defineComponent({
|
|
|
217
220
|
required: true,
|
|
218
221
|
},
|
|
219
222
|
imageComponent: {
|
|
220
|
-
type: [String, Object] as PropType<
|
|
223
|
+
type: [String, Object] as PropType<
|
|
224
|
+
string | ConcreteComponent | Raw<DefineComponent>
|
|
225
|
+
>,
|
|
221
226
|
default: undefined,
|
|
222
227
|
required: false,
|
|
223
228
|
},
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
+
import { LinkResolverFunction, asLink } from "@prismicio/helpers";
|
|
1
2
|
import {
|
|
2
3
|
AllowedComponentProps,
|
|
3
4
|
ComponentCustomProps,
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
ComputedRef,
|
|
6
|
+
ConcreteComponent,
|
|
7
|
+
DefineComponent,
|
|
6
8
|
PropType,
|
|
9
|
+
Raw,
|
|
7
10
|
VNodeProps,
|
|
8
|
-
unref,
|
|
9
|
-
reactive,
|
|
10
|
-
ConcreteComponent,
|
|
11
11
|
computed,
|
|
12
|
-
|
|
12
|
+
defineComponent,
|
|
13
|
+
h,
|
|
14
|
+
reactive,
|
|
15
|
+
unref,
|
|
13
16
|
} from "vue";
|
|
14
17
|
|
|
15
|
-
import {
|
|
18
|
+
import { getSlots } from "../lib/getSlots";
|
|
19
|
+
import { isInternalURL } from "../lib/isInternalURL";
|
|
20
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent";
|
|
21
|
+
|
|
22
|
+
import { VueUseOptions } from "../types";
|
|
16
23
|
import { LinkField, PrismicDocument } from "@prismicio/types";
|
|
17
24
|
|
|
18
|
-
import { isInternalURL } from "../lib/isInternalURL";
|
|
19
25
|
import { usePrismic } from "../usePrismic";
|
|
20
|
-
import { VueUseOptions } from "../types";
|
|
21
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent";
|
|
22
|
-
import { getSlots } from "../lib/getSlots";
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* The default component rendered for internal URLs.
|
|
@@ -85,7 +88,7 @@ export type PrismicLinkProps = {
|
|
|
85
88
|
* (`to` props).
|
|
86
89
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
|
|
87
90
|
*/
|
|
88
|
-
internalComponent?: string | ConcreteComponent
|
|
91
|
+
internalComponent?: string | ConcreteComponent | Raw<DefineComponent>;
|
|
89
92
|
|
|
90
93
|
/**
|
|
91
94
|
* An HTML tag name, a component, or a functional component used to render
|
|
@@ -99,7 +102,7 @@ export type PrismicLinkProps = {
|
|
|
99
102
|
* (`to` props).
|
|
100
103
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
|
|
101
104
|
*/
|
|
102
|
-
externalComponent?: string | ConcreteComponent
|
|
105
|
+
externalComponent?: string | ConcreteComponent | Raw<DefineComponent>;
|
|
103
106
|
};
|
|
104
107
|
|
|
105
108
|
/**
|
|
@@ -114,7 +117,7 @@ export type UsePrismicLinkReturnType = {
|
|
|
114
117
|
/**
|
|
115
118
|
* Suggested component to render for provided link field.
|
|
116
119
|
*/
|
|
117
|
-
type: ComputedRef<string | ConcreteComponent
|
|
120
|
+
type: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>>;
|
|
118
121
|
|
|
119
122
|
/**
|
|
120
123
|
* Resolved anchor `href` value.
|
|
@@ -238,12 +241,16 @@ export const PrismicLinkImpl = /*#__PURE__*/ defineComponent({
|
|
|
238
241
|
required: false,
|
|
239
242
|
},
|
|
240
243
|
internalComponent: {
|
|
241
|
-
type: [String, Object, Function] as PropType<
|
|
244
|
+
type: [String, Object, Function] as PropType<
|
|
245
|
+
string | ConcreteComponent | Raw<DefineComponent>
|
|
246
|
+
>,
|
|
242
247
|
default: undefined,
|
|
243
248
|
required: false,
|
|
244
249
|
},
|
|
245
250
|
externalComponent: {
|
|
246
|
-
type: [String, Object, Function] as PropType<
|
|
251
|
+
type: [String, Object, Function] as PropType<
|
|
252
|
+
string | ConcreteComponent | Raw<DefineComponent>
|
|
253
|
+
>,
|
|
247
254
|
default: undefined,
|
|
248
255
|
required: false,
|
|
249
256
|
},
|