@prismicio/react 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PrismicImage.d.ts +90 -8
- package/dist/PrismicToolbar.cjs +0 -1
- package/dist/PrismicToolbar.cjs.map +1 -1
- package/dist/PrismicToolbar.js +0 -1
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +1 -4
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +1 -4
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +4 -3
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +2 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +7 -6
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +3 -2
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +2 -2
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs +13 -0
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js +13 -0
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js.map +1 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs +10 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs.map +1 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js +10 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js.map +1 -0
- package/dist/_node_modules/imgix-url-builder/dist/{index.cjs → buildURL.cjs} +1 -13
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs.map +1 -0
- package/dist/_node_modules/imgix-url-builder/dist/{index.js → buildURL.js} +2 -14
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js.map +1 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs +10 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs.map +1 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js +10 -0
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js.map +1 -0
- package/dist/clientHooks.d.ts +18 -72
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/react-server/PrismicLink.cjs +4 -4
- package/dist/react-server/PrismicLink.cjs.map +1 -1
- package/dist/react-server/PrismicLink.d.ts +6 -1
- package/dist/react-server/PrismicLink.js +4 -4
- package/dist/react-server/PrismicLink.js.map +1 -1
- package/dist/useStatefulPrismicClientMethod.cjs +1 -5
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +1 -1
- package/dist/useStatefulPrismicClientMethod.js +1 -5
- package/dist/useStatefulPrismicClientMethod.js.map +1 -1
- package/package.json +3 -3
- package/src/react-server/PrismicLink.tsx +23 -7
- package/src/useStatefulPrismicClientMethod.ts +2 -6
- package/dist/_node_modules/imgix-url-builder/dist/index.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/index.js.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { buildURL } from "./buildURL.js";
|
|
2
|
+
const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
|
|
3
|
+
return pixelDensities.map((dpr) => {
|
|
4
|
+
return `${buildURL(url, { ...params, dpr })} ${dpr}x`;
|
|
5
|
+
}).join(", ");
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
buildPixelDensitySrcSet
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=buildPixelDensitySrcSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPixelDensitySrcSet.js","sources":["../../../../node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js"],"sourcesContent":["import { buildURL } from \"./buildURL.js\";\nconst buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {\n return pixelDensities.map((dpr) => {\n return `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n }).join(\", \");\n};\nexport {\n buildPixelDensitySrcSet\n};\n//# sourceMappingURL=buildPixelDensitySrcSet.js.map\n"],"names":[],"mappings":";AACK,MAAC,0BAA0B,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAM,MAAO;AACtE,SAAO,eAAe,IAAI,CAAC,QAAQ;AACjC,WAAO,GAAG,SAAS,KAAK,EAAE,GAAG,QAAQ,IAAG,CAAE,KAAK;AAAA,EACnD,CAAG,EAAE,KAAK,IAAI;AACd;","x_google_ignoreList":[0]}
|
|
@@ -25,17 +25,5 @@ const buildURL = (url, params) => {
|
|
|
25
25
|
}
|
|
26
26
|
return instance.toString();
|
|
27
27
|
};
|
|
28
|
-
const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
|
|
29
|
-
return pixelDensities.map((dpr) => {
|
|
30
|
-
return `${buildURL(url, { ...params, dpr })} ${dpr}x`;
|
|
31
|
-
}).join(", ");
|
|
32
|
-
};
|
|
33
|
-
const buildWidthSrcSet = (url, { widths, ...params }) => {
|
|
34
|
-
return widths.map((width) => {
|
|
35
|
-
return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;
|
|
36
|
-
}).join(", ");
|
|
37
|
-
};
|
|
38
|
-
exports.buildPixelDensitySrcSet = buildPixelDensitySrcSet;
|
|
39
28
|
exports.buildURL = buildURL;
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=index.cjs.map
|
|
29
|
+
//# sourceMappingURL=buildURL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildURL.cjs","sources":["../../../../node_modules/imgix-url-builder/dist/buildURL.js"],"sourcesContent":["const camelCaseToParamCase = (input) => {\n return input.replace(/[A-Z]/g, (match) => {\n return `-${match.toLowerCase()}`;\n });\n};\nconst buildURL = (url, params) => {\n const instance = new URL(url);\n for (const camelCasedParamKey in params) {\n const paramKey = camelCaseToParamCase(camelCasedParamKey);\n const paramValue = params[camelCasedParamKey];\n if (paramValue === void 0) {\n instance.searchParams.delete(paramKey);\n } else if (Array.isArray(paramValue)) {\n instance.searchParams.set(paramKey, paramValue.join(\",\"));\n } else {\n instance.searchParams.set(paramKey, `${paramValue}`);\n }\n }\n const s = instance.searchParams.get(\"s\");\n if (s) {\n instance.searchParams.delete(\"s\");\n instance.searchParams.append(\"s\", s);\n }\n return instance.toString();\n};\nexport {\n buildURL\n};\n//# sourceMappingURL=buildURL.js.map\n"],"names":[],"mappings":";;AAAA,MAAM,uBAAuB,CAAC,UAAU;AACtC,SAAO,MAAM,QAAQ,UAAU,CAAC,UAAU;AACxC,WAAO,IAAI,MAAM,YAAW;AAAA,EAChC,CAAG;AACH;AACK,MAAC,WAAW,CAAC,KAAK,WAAW;AAChC,QAAM,WAAW,IAAI,IAAI,GAAG;AAC5B,aAAW,sBAAsB,QAAQ;AACvC,UAAM,WAAW,qBAAqB,kBAAkB;AACxD,UAAM,aAAa,OAAO,kBAAkB;AAC5C,QAAI,eAAe,QAAQ;AACzB,eAAS,aAAa,OAAO,QAAQ;AAAA,IACtC,WAAU,MAAM,QAAQ,UAAU,GAAG;AACpC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK,GAAG,CAAC;AAAA,IAC9D,OAAW;AACL,eAAS,aAAa,IAAI,UAAU,GAAG,YAAY;AAAA,IACpD;AAAA,EACF;AACD,QAAM,IAAI,SAAS,aAAa,IAAI,GAAG;AACvC,MAAI,GAAG;AACL,aAAS,aAAa,OAAO,GAAG;AAChC,aAAS,aAAa,OAAO,KAAK,CAAC;AAAA,EACpC;AACD,SAAO,SAAS;AAClB;;","x_google_ignoreList":[0]}
|
|
@@ -23,19 +23,7 @@ const buildURL = (url, params) => {
|
|
|
23
23
|
}
|
|
24
24
|
return instance.toString();
|
|
25
25
|
};
|
|
26
|
-
const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
|
|
27
|
-
return pixelDensities.map((dpr) => {
|
|
28
|
-
return `${buildURL(url, { ...params, dpr })} ${dpr}x`;
|
|
29
|
-
}).join(", ");
|
|
30
|
-
};
|
|
31
|
-
const buildWidthSrcSet = (url, { widths, ...params }) => {
|
|
32
|
-
return widths.map((width) => {
|
|
33
|
-
return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;
|
|
34
|
-
}).join(", ");
|
|
35
|
-
};
|
|
36
26
|
export {
|
|
37
|
-
|
|
38
|
-
buildURL,
|
|
39
|
-
buildWidthSrcSet
|
|
27
|
+
buildURL
|
|
40
28
|
};
|
|
41
|
-
//# sourceMappingURL=
|
|
29
|
+
//# sourceMappingURL=buildURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildURL.js","sources":["../../../../node_modules/imgix-url-builder/dist/buildURL.js"],"sourcesContent":["const camelCaseToParamCase = (input) => {\n return input.replace(/[A-Z]/g, (match) => {\n return `-${match.toLowerCase()}`;\n });\n};\nconst buildURL = (url, params) => {\n const instance = new URL(url);\n for (const camelCasedParamKey in params) {\n const paramKey = camelCaseToParamCase(camelCasedParamKey);\n const paramValue = params[camelCasedParamKey];\n if (paramValue === void 0) {\n instance.searchParams.delete(paramKey);\n } else if (Array.isArray(paramValue)) {\n instance.searchParams.set(paramKey, paramValue.join(\",\"));\n } else {\n instance.searchParams.set(paramKey, `${paramValue}`);\n }\n }\n const s = instance.searchParams.get(\"s\");\n if (s) {\n instance.searchParams.delete(\"s\");\n instance.searchParams.append(\"s\", s);\n }\n return instance.toString();\n};\nexport {\n buildURL\n};\n//# sourceMappingURL=buildURL.js.map\n"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,CAAC,UAAU;AACtC,SAAO,MAAM,QAAQ,UAAU,CAAC,UAAU;AACxC,WAAO,IAAI,MAAM,YAAW;AAAA,EAChC,CAAG;AACH;AACK,MAAC,WAAW,CAAC,KAAK,WAAW;AAChC,QAAM,WAAW,IAAI,IAAI,GAAG;AAC5B,aAAW,sBAAsB,QAAQ;AACvC,UAAM,WAAW,qBAAqB,kBAAkB;AACxD,UAAM,aAAa,OAAO,kBAAkB;AAC5C,QAAI,eAAe,QAAQ;AACzB,eAAS,aAAa,OAAO,QAAQ;AAAA,IACtC,WAAU,MAAM,QAAQ,UAAU,GAAG;AACpC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK,GAAG,CAAC;AAAA,IAC9D,OAAW;AACL,eAAS,aAAa,IAAI,UAAU,GAAG,YAAY;AAAA,IACpD;AAAA,EACF;AACD,QAAM,IAAI,SAAS,aAAa,IAAI,GAAG;AACvC,MAAI,GAAG;AACL,aAAS,aAAa,OAAO,GAAG;AAChC,aAAS,aAAa,OAAO,KAAK,CAAC;AAAA,EACpC;AACD,SAAO,SAAS;AAClB;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const buildURL = require("./buildURL.cjs");
|
|
4
|
+
const buildWidthSrcSet = (url, { widths, ...params }) => {
|
|
5
|
+
return widths.map((width) => {
|
|
6
|
+
return `${buildURL.buildURL(url, { ...params, w: void 0, width })} ${width}w`;
|
|
7
|
+
}).join(", ");
|
|
8
|
+
};
|
|
9
|
+
exports.buildWidthSrcSet = buildWidthSrcSet;
|
|
10
|
+
//# sourceMappingURL=buildWidthSrcSet.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildWidthSrcSet.cjs","sources":["../../../../node_modules/imgix-url-builder/dist/buildWidthSrcSet.js"],"sourcesContent":["import { buildURL } from \"./buildURL.js\";\nconst buildWidthSrcSet = (url, { widths, ...params }) => {\n return widths.map((width) => {\n return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;\n }).join(\", \");\n};\nexport {\n buildWidthSrcSet\n};\n//# sourceMappingURL=buildWidthSrcSet.js.map\n"],"names":["buildURL"],"mappings":";;;AACK,MAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAM,MAAO;AACvD,SAAO,OAAO,IAAI,CAAC,UAAU;AAC3B,WAAO,GAAGA,SAAQ,SAAC,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAQ,MAAK,CAAE,KAAK;AAAA,EAChE,CAAG,EAAE,KAAK,IAAI;AACd;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { buildURL } from "./buildURL.js";
|
|
2
|
+
const buildWidthSrcSet = (url, { widths, ...params }) => {
|
|
3
|
+
return widths.map((width) => {
|
|
4
|
+
return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;
|
|
5
|
+
}).join(", ");
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
buildWidthSrcSet
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=buildWidthSrcSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildWidthSrcSet.js","sources":["../../../../node_modules/imgix-url-builder/dist/buildWidthSrcSet.js"],"sourcesContent":["import { buildURL } from \"./buildURL.js\";\nconst buildWidthSrcSet = (url, { widths, ...params }) => {\n return widths.map((width) => {\n return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;\n }).join(\", \");\n};\nexport {\n buildWidthSrcSet\n};\n//# sourceMappingURL=buildWidthSrcSet.js.map\n"],"names":[],"mappings":";AACK,MAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAM,MAAO;AACvD,SAAO,OAAO,IAAI,CAAC,UAAU;AAC3B,WAAO,GAAG,SAAS,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAQ,MAAK,CAAE,KAAK;AAAA,EAChE,CAAG,EAAE,KAAK,IAAI;AACd;","x_google_ignoreList":[0]}
|
package/dist/clientHooks.d.ts
CHANGED
|
@@ -14,10 +14,7 @@ import { ClientHookReturnType, HookOnlyParameters } from "./useStatefulPrismicCl
|
|
|
14
14
|
*
|
|
15
15
|
* @see Underlying `@prismicio/client` method {@link proto.get}
|
|
16
16
|
*/
|
|
17
|
-
export declare const usePrismicDocuments: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
18
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
19
|
-
signal?: any;
|
|
20
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
17
|
+
export declare const usePrismicDocuments: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
21
18
|
/**
|
|
22
19
|
* A hook that queries content from the Prismic repository and returns only the
|
|
23
20
|
* first result, if any.
|
|
@@ -33,10 +30,7 @@ export declare const usePrismicDocuments: <TDocument extends prismic.PrismicDocu
|
|
|
33
30
|
*
|
|
34
31
|
* @see Underlying `@prismicio/client` method {@link proto.getFirst}
|
|
35
32
|
*/
|
|
36
|
-
export declare const useFirstPrismicDocument: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
37
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
38
|
-
signal?: any;
|
|
39
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
33
|
+
export declare const useFirstPrismicDocument: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
40
34
|
/**
|
|
41
35
|
* A hook that queries content from the Prismic repository and returns all
|
|
42
36
|
* matching content. If no predicates are provided, all documents will be
|
|
@@ -55,10 +49,7 @@ export declare const useFirstPrismicDocument: <TDocument extends prismic.Prismic
|
|
|
55
49
|
*/
|
|
56
50
|
export declare const useAllPrismicDocumentsDangerously: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(params?: (Partial<Omit<prismic.BuildQueryURLArgs, "page">> & {
|
|
57
51
|
limit?: number | undefined;
|
|
58
|
-
} &
|
|
59
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
60
|
-
signal?: any;
|
|
61
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
52
|
+
} & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
62
53
|
/**
|
|
63
54
|
* A hook that queries a document from the Prismic repository with a specific
|
|
64
55
|
* ID.
|
|
@@ -75,10 +66,7 @@ export declare const useAllPrismicDocumentsDangerously: <TDocument extends prism
|
|
|
75
66
|
*
|
|
76
67
|
* @see Underlying `@prismicio/client` method {@link proto.getByID}
|
|
77
68
|
*/
|
|
78
|
-
export declare const usePrismicDocumentByID: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(id: string, params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
79
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
80
|
-
signal?: any;
|
|
81
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
69
|
+
export declare const usePrismicDocumentByID: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(id: string, params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
82
70
|
/**
|
|
83
71
|
* A hook that queries documents from the Prismic repository with specific IDs.
|
|
84
72
|
*
|
|
@@ -94,10 +82,7 @@ export declare const usePrismicDocumentByID: <TDocument extends prismic.PrismicD
|
|
|
94
82
|
*
|
|
95
83
|
* @see Underlying `@prismicio/client` method {@link proto.getByIDs}
|
|
96
84
|
*/
|
|
97
|
-
export declare const usePrismicDocumentsByIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(id: string[], params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
98
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
99
|
-
signal?: any;
|
|
100
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
85
|
+
export declare const usePrismicDocumentsByIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(id: string[], params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
101
86
|
/**
|
|
102
87
|
* A hook that queries all documents from the Prismic repository with specific
|
|
103
88
|
* IDs.
|
|
@@ -116,10 +101,7 @@ export declare const usePrismicDocumentsByIDs: <TDocument extends prismic.Prismi
|
|
|
116
101
|
*/
|
|
117
102
|
export declare const useAllPrismicDocumentsByIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(id: string[], params?: (Partial<prismic.BuildQueryURLArgs> & {
|
|
118
103
|
limit?: number | undefined;
|
|
119
|
-
} &
|
|
120
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
121
|
-
signal?: any;
|
|
122
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
104
|
+
} & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
123
105
|
/**
|
|
124
106
|
* A hook that queries a document from the Prismic repository with a specific
|
|
125
107
|
* UID and Custom Type.
|
|
@@ -137,10 +119,7 @@ export declare const useAllPrismicDocumentsByIDs: <TDocument extends prismic.Pri
|
|
|
137
119
|
*
|
|
138
120
|
* @see Underlying `@prismicio/client` method {@link proto.getByUID}
|
|
139
121
|
*/
|
|
140
|
-
export declare const usePrismicDocumentByUID: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, uid: string, params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
141
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
142
|
-
signal?: any;
|
|
143
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
122
|
+
export declare const usePrismicDocumentByUID: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, uid: string, params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
144
123
|
/**
|
|
145
124
|
* A hook that queries documents from the Prismic repository with specific UIDs
|
|
146
125
|
* of a Custom Type.
|
|
@@ -158,10 +137,7 @@ export declare const usePrismicDocumentByUID: <TDocument extends prismic.Prismic
|
|
|
158
137
|
*
|
|
159
138
|
* @see Underlying `@prismicio/client` method {@link proto.getByUID}
|
|
160
139
|
*/
|
|
161
|
-
export declare const usePrismicDocumentsByUIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, uids: string[], params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
162
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
163
|
-
signal?: any;
|
|
164
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
140
|
+
export declare const usePrismicDocumentsByUIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, uids: string[], params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
165
141
|
/**
|
|
166
142
|
* A hook that queries all documents from the Prismic repository with specific
|
|
167
143
|
* UIDs of a Custom Type.
|
|
@@ -179,10 +155,7 @@ export declare const usePrismicDocumentsByUIDs: <TDocument extends prismic.Prism
|
|
|
179
155
|
*
|
|
180
156
|
* @see Underlying `@prismicio/client` method {@link proto.getByUID}
|
|
181
157
|
*/
|
|
182
|
-
export declare const useAllPrismicDocumentsByUIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, uids: string[], params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
183
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
184
|
-
signal?: any;
|
|
185
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
158
|
+
export declare const useAllPrismicDocumentsByUIDs: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, uids: string[], params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
186
159
|
/**
|
|
187
160
|
* A hook that queries a singleton document from the Prismic repository for a
|
|
188
161
|
* specific Custom Type.
|
|
@@ -199,10 +172,7 @@ export declare const useAllPrismicDocumentsByUIDs: <TDocument extends prismic.Pr
|
|
|
199
172
|
*
|
|
200
173
|
* @see Underlying `@prismicio/client` method {@link proto.getSingle}
|
|
201
174
|
*/
|
|
202
|
-
export declare const useSinglePrismicDocument: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
203
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
204
|
-
signal?: any;
|
|
205
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
175
|
+
export declare const useSinglePrismicDocument: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument>;
|
|
206
176
|
/**
|
|
207
177
|
* A hook that queries documents from the Prismic repository for a specific
|
|
208
178
|
* Custom Type.
|
|
@@ -219,10 +189,7 @@ export declare const useSinglePrismicDocument: <TDocument extends prismic.Prismi
|
|
|
219
189
|
*
|
|
220
190
|
* @see Underlying `@prismicio/client` method {@link proto.getByType}
|
|
221
191
|
*/
|
|
222
|
-
export declare const usePrismicDocumentsByType: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
223
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
224
|
-
signal?: any;
|
|
225
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
192
|
+
export declare const usePrismicDocumentsByType: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
226
193
|
/**
|
|
227
194
|
* A hook that queries all documents from the Prismic repository for a specific
|
|
228
195
|
* Custom Type.
|
|
@@ -241,10 +208,7 @@ export declare const usePrismicDocumentsByType: <TDocument extends prismic.Prism
|
|
|
241
208
|
*/
|
|
242
209
|
export declare const useAllPrismicDocumentsByType: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(documentType: any, params?: (Partial<Omit<prismic.BuildQueryURLArgs, "page">> & {
|
|
243
210
|
limit?: number | undefined;
|
|
244
|
-
} &
|
|
245
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
246
|
-
signal?: any;
|
|
247
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
211
|
+
} & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
248
212
|
/**
|
|
249
213
|
* A hook that queries documents from the Prismic repository with a specific
|
|
250
214
|
* tag.
|
|
@@ -261,10 +225,7 @@ export declare const useAllPrismicDocumentsByType: <TDocument extends prismic.Pr
|
|
|
261
225
|
*
|
|
262
226
|
* @see Underlying `@prismicio/client` method {@link proto.getByTag}
|
|
263
227
|
*/
|
|
264
|
-
export declare const usePrismicDocumentsByTag: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string, params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
265
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
266
|
-
signal?: any;
|
|
267
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
228
|
+
export declare const usePrismicDocumentsByTag: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string, params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
268
229
|
/**
|
|
269
230
|
* A hook that queries all documents from the Prismic repository with a specific
|
|
270
231
|
* tag.
|
|
@@ -283,10 +244,7 @@ export declare const usePrismicDocumentsByTag: <TDocument extends prismic.Prismi
|
|
|
283
244
|
*/
|
|
284
245
|
export declare const useAllPrismicDocumentsByTag: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string, params?: (Partial<Omit<prismic.BuildQueryURLArgs, "page">> & {
|
|
285
246
|
limit?: number | undefined;
|
|
286
|
-
} &
|
|
287
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
288
|
-
signal?: any;
|
|
289
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
247
|
+
} & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
290
248
|
/**
|
|
291
249
|
* A hook that queries documents from the Prismic repository with specific tags.
|
|
292
250
|
* A document must be tagged with at least one of the queried tags to be
|
|
@@ -304,10 +262,7 @@ export declare const useAllPrismicDocumentsByTag: <TDocument extends prismic.Pri
|
|
|
304
262
|
*
|
|
305
263
|
* @see Underlying `@prismicio/client` method {@link proto.getByTags}
|
|
306
264
|
*/
|
|
307
|
-
export declare const usePrismicDocumentsBySomeTags: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string[], params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
308
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
309
|
-
signal?: any;
|
|
310
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
265
|
+
export declare const usePrismicDocumentsBySomeTags: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string[], params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
311
266
|
/**
|
|
312
267
|
* A hook that queries all documents from the Prismic repository with specific
|
|
313
268
|
* tags. A document must be tagged with at least one of the queried tags to be
|
|
@@ -327,10 +282,7 @@ export declare const usePrismicDocumentsBySomeTags: <TDocument extends prismic.P
|
|
|
327
282
|
*/
|
|
328
283
|
export declare const useAllPrismicDocumentsBySomeTags: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string[], params?: (Partial<Omit<prismic.BuildQueryURLArgs, "page">> & {
|
|
329
284
|
limit?: number | undefined;
|
|
330
|
-
} &
|
|
331
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
332
|
-
signal?: any;
|
|
333
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
285
|
+
} & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
334
286
|
/**
|
|
335
287
|
* A hook that queries documents from the Prismic repository with specific tags.
|
|
336
288
|
* A document must be tagged with all of the queried tags to be included.
|
|
@@ -347,10 +299,7 @@ export declare const useAllPrismicDocumentsBySomeTags: <TDocument extends prismi
|
|
|
347
299
|
*
|
|
348
300
|
* @see Underlying `@prismicio/client` method {@link proto.getByTags}
|
|
349
301
|
*/
|
|
350
|
-
export declare const usePrismicDocumentsByEveryTag: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string[], params?: (Partial<prismic.BuildQueryURLArgs> &
|
|
351
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
352
|
-
signal?: any;
|
|
353
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
302
|
+
export declare const usePrismicDocumentsByEveryTag: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string[], params?: (Partial<prismic.BuildQueryURLArgs> & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<prismic.Query<TDocument>>;
|
|
354
303
|
/**
|
|
355
304
|
* A hook that queries all documents from the Prismic repository with specific
|
|
356
305
|
* tags. A document must be tagged with all of the queried tags to be included.
|
|
@@ -369,7 +318,4 @@ export declare const usePrismicDocumentsByEveryTag: <TDocument extends prismic.P
|
|
|
369
318
|
*/
|
|
370
319
|
export declare const useAllPrismicDocumentsByEveryTag: <TDocument extends prismic.PrismicDocument<Record<string, any>, string, string>>(tag: string[], params?: (Partial<Omit<prismic.BuildQueryURLArgs, "page">> & {
|
|
371
320
|
limit?: number | undefined;
|
|
372
|
-
} &
|
|
373
|
-
fetchOptions?: prismic.RequestInitLike | undefined;
|
|
374
|
-
signal?: any;
|
|
375
|
-
} & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
|
321
|
+
} & import("@prismicio/client/dist/BaseClient").FetchParams & HookOnlyParameters) | undefined) => ClientHookReturnType<TDocument[]>;
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const asLinkAttrs = require('./../_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs');
|
|
6
|
-
require("@prismicio/richtext");
|
|
7
6
|
const devMsg = require("../lib/devMsg.cjs");
|
|
8
7
|
const isInternalURL = require("../lib/isInternalURL.cjs");
|
|
9
8
|
function _interopNamespaceDefault(e) {
|
|
@@ -24,14 +23,15 @@ function _interopNamespaceDefault(e) {
|
|
|
24
23
|
}
|
|
25
24
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
26
25
|
const defaultComponent = "a";
|
|
27
|
-
const PrismicLink = React__namespace.forwardRef(function PrismicLink2(
|
|
26
|
+
const PrismicLink = React__namespace.forwardRef(function PrismicLink2(props, ref) {
|
|
27
|
+
const { field, document: doc, linkResolver, internalComponent, externalComponent, children, ...restProps } = props;
|
|
28
28
|
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
29
29
|
if (field) {
|
|
30
30
|
if (!field.link_type) {
|
|
31
31
|
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
32
32
|
`, field);
|
|
33
33
|
throw new Error(`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg.devMsg("missing-link-properties")}`);
|
|
34
|
-
} else if (Object.keys(field).length > 1 && !("url" in field || "uid" in field || "id" in field)) {
|
|
34
|
+
} else if (("text" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) && !("url" in field || "uid" in field || "id" in field)) {
|
|
35
35
|
console.warn(`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg.devMsg("missing-link-properties")}`, field);
|
|
36
36
|
}
|
|
37
37
|
} else if (doc) {
|
|
@@ -52,7 +52,7 @@ const PrismicLink = React__namespace.forwardRef(function PrismicLink2({ field, d
|
|
|
52
52
|
const InternalComponent = internalComponent || defaultComponent;
|
|
53
53
|
const ExternalComponent = externalComponent || defaultComponent;
|
|
54
54
|
const Component = href && isInternalURL.isInternalURL(href) ? InternalComponent : ExternalComponent;
|
|
55
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, ...attrs, ...restProps, href, rel });
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, ...attrs, ...restProps, href, rel, children: "children" in props ? children : field == null ? void 0 : field.text });
|
|
56
56
|
});
|
|
57
57
|
exports.PrismicLink = PrismicLink;
|
|
58
58
|
exports.defaultComponent = defaultComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.cjs","sources":["../../../src/react-server/PrismicLink.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n\tAsLinkAttrsConfig,\n} from \"@prismicio/client\";\n\nimport { devMsg } from \"../lib/devMsg\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered for internal and external links.\n */\nexport const defaultComponent = \"a\";\n\n/**\n * Props provided to a component when rendered with `<PrismicLink>`.\n */\nexport interface LinkProps {\n\t/**\n\t * The URL to link.\n\t */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: React.HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n> = Omit
|
|
1
|
+
{"version":3,"file":"PrismicLink.cjs","sources":["../../../src/react-server/PrismicLink.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n\tAsLinkAttrsConfig,\n} from \"@prismicio/client\";\n\nimport { devMsg } from \"../lib/devMsg\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered for internal and external links.\n */\nexport const defaultComponent = \"a\";\n\n/**\n * Props provided to a component when rendered with `<PrismicLink>`.\n */\nexport interface LinkProps {\n\t/**\n\t * The URL to link.\n\t */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: React.HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n> = Omit<\n\tInternalComponentProps & ExternalComponentProps,\n\t\"rel\" | \"href\" | \"children\"\n> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if\n\t * the link's URL is external. This prop can be provided a function to use the\n\t * link's metadata to determine the `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The Link Resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses Route Resolvers when querying for your Prismic\n\t * repository's content, a Link Resolver does not need to be provided.\n\t * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link\n\t * component, provide the Link component to this prop.\n\t */\n\tinternalComponent?: React.ElementType<InternalComponentProps>;\n\n\t/**\n\t * The component rendered for external URLs. Defaults to `<a>`.\n\t */\n\texternalComponent?: React.ComponentType<ExternalComponentProps>;\n\n\t/**\n\t * The children to render for the link. If no children are provided, the\n\t * link's `text` property will be used.\n\t */\n\tchildren?: React.ReactNode;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\nexport const PrismicLink = React.forwardRef(function PrismicLink<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: React.ForwardedRef<Element>,\n): JSX.Element {\n\tconst {\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t(\"text\" in field\n\t\t\t\t\t? Object.keys(field).length > 2\n\t\t\t\t\t: Object.keys(field).length > 1) &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent ||\n\t\tdefaultComponent) as React.ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent ||\n\t\tdefaultComponent) as React.ComponentType<LinkProps>;\n\tconst Component =\n\t\thref && isInternalURL(href) ? InternalComponent : ExternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Component>\n\t);\n}) as <\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: React.ForwardedRef<Element>;\n\t},\n) => JSX.Element;\n"],"names":["React","PrismicLink","devMsg","asLinkAttrs","isInternalURL","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,mBAAmB;AAyFzB,MAAM,cAAcA,iBAAM,WAAW,SAASC,aAIpD,OACA,KAAgC;AAE1B,QAAA,EACL,OACA,UAAU,KACV,cACA,mBACA,mBACA,UACA,GAAG,UAAA,IACA;AAEJ,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8IC,OAAA,OAC7I,yBAAyB,GACvB;AAAA,MAAA,YAGH,UAAU,QACR,OAAO,KAAK,KAAK,EAAE,SAAS,IAC5B,OAAO,KAAK,KAAK,EAAE,SAAS,MAC/B,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,QAC7C;AACD,gBAAQ,KACP,uJAAuJA,OAAAA,OACtJ,yBAAyB,KAE1B,KAAK;AAAA,MAEN;AAAA,eACS,KAAK;AACf,UAAI,EAAE,SAAS,OAAO,QAAQ,MAAM;AACnC,gBAAQ,KACP,0JAA0JA,OAAAA,OACzJ,yBAAyB,KAE1B,GAAG;AAAA,MAEJ;AAAA,IACD;AAAA,EACD;AAEK,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACAC,YAAAA,YAAY,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,MAAI,MAA0B;AAC9B,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAChB;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,QAAM,oBAAqB,qBAC1B;AACD,QAAM,oBAAqB,qBAC1B;AACD,QAAM,YACL,QAAQC,cAAAA,cAAc,IAAI,IAAI,oBAAoB;AAEnD,SACEC,2BAAAA,IAAA,WAAA,EAAU,KAAc,GAAA,OAAW,GAAA,WAAW,MAAY,KACzD,UAAA,cAAc,QAAQ,WAAW,+BAAO,KAC1C,CAAA;AAEF,CAAC;;;"}
|
|
@@ -27,7 +27,7 @@ export interface LinkProps {
|
|
|
27
27
|
*/
|
|
28
28
|
children?: React.ReactNode;
|
|
29
29
|
}
|
|
30
|
-
export type PrismicLinkProps<InternalComponentProps = React.ComponentProps<typeof defaultComponent>, ExternalComponentProps = React.ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href"> & {
|
|
30
|
+
export type PrismicLinkProps<InternalComponentProps = React.ComponentProps<typeof defaultComponent>, ExternalComponentProps = React.ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & {
|
|
31
31
|
/**
|
|
32
32
|
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if
|
|
33
33
|
* the link's URL is external. This prop can be provided a function to use the
|
|
@@ -54,6 +54,11 @@ export type PrismicLinkProps<InternalComponentProps = React.ComponentProps<typeo
|
|
|
54
54
|
* The component rendered for external URLs. Defaults to `<a>`.
|
|
55
55
|
*/
|
|
56
56
|
externalComponent?: React.ComponentType<ExternalComponentProps>;
|
|
57
|
+
/**
|
|
58
|
+
* The children to render for the link. If no children are provided, the
|
|
59
|
+
* link's `text` property will be used.
|
|
60
|
+
*/
|
|
61
|
+
children?: React.ReactNode;
|
|
57
62
|
} & ({
|
|
58
63
|
document: PrismicDocument | null | undefined;
|
|
59
64
|
href?: never;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { asLinkAttrs } from './../_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js';
|
|
4
|
-
import "@prismicio/richtext";
|
|
5
4
|
import { devMsg } from "../lib/devMsg.js";
|
|
6
5
|
import { isInternalURL } from "../lib/isInternalURL.js";
|
|
7
6
|
const defaultComponent = "a";
|
|
8
|
-
const PrismicLink = React.forwardRef(function PrismicLink2(
|
|
7
|
+
const PrismicLink = React.forwardRef(function PrismicLink2(props, ref) {
|
|
8
|
+
const { field, document: doc, linkResolver, internalComponent, externalComponent, children, ...restProps } = props;
|
|
9
9
|
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
10
10
|
if (field) {
|
|
11
11
|
if (!field.link_type) {
|
|
12
12
|
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
13
13
|
`, field);
|
|
14
14
|
throw new Error(`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg("missing-link-properties")}`);
|
|
15
|
-
} else if (Object.keys(field).length > 1 && !("url" in field || "uid" in field || "id" in field)) {
|
|
15
|
+
} else if (("text" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) && !("url" in field || "uid" in field || "id" in field)) {
|
|
16
16
|
console.warn(`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg("missing-link-properties")}`, field);
|
|
17
17
|
}
|
|
18
18
|
} else if (doc) {
|
|
@@ -33,7 +33,7 @@ const PrismicLink = React.forwardRef(function PrismicLink2({ field, document: do
|
|
|
33
33
|
const InternalComponent = internalComponent || defaultComponent;
|
|
34
34
|
const ExternalComponent = externalComponent || defaultComponent;
|
|
35
35
|
const Component = href && isInternalURL(href) ? InternalComponent : ExternalComponent;
|
|
36
|
-
return /* @__PURE__ */ jsx(Component, { ref, ...attrs, ...restProps, href, rel });
|
|
36
|
+
return /* @__PURE__ */ jsx(Component, { ref, ...attrs, ...restProps, href, rel, children: "children" in props ? children : field == null ? void 0 : field.text });
|
|
37
37
|
});
|
|
38
38
|
export {
|
|
39
39
|
PrismicLink,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.js","sources":["../../../src/react-server/PrismicLink.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n\tAsLinkAttrsConfig,\n} from \"@prismicio/client\";\n\nimport { devMsg } from \"../lib/devMsg\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered for internal and external links.\n */\nexport const defaultComponent = \"a\";\n\n/**\n * Props provided to a component when rendered with `<PrismicLink>`.\n */\nexport interface LinkProps {\n\t/**\n\t * The URL to link.\n\t */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: React.HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n> = Omit
|
|
1
|
+
{"version":3,"file":"PrismicLink.js","sources":["../../../src/react-server/PrismicLink.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n\tAsLinkAttrsConfig,\n} from \"@prismicio/client\";\n\nimport { devMsg } from \"../lib/devMsg\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered for internal and external links.\n */\nexport const defaultComponent = \"a\";\n\n/**\n * Props provided to a component when rendered with `<PrismicLink>`.\n */\nexport interface LinkProps {\n\t/**\n\t * The URL to link.\n\t */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: React.HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n> = Omit<\n\tInternalComponentProps & ExternalComponentProps,\n\t\"rel\" | \"href\" | \"children\"\n> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if\n\t * the link's URL is external. This prop can be provided a function to use the\n\t * link's metadata to determine the `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The Link Resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses Route Resolvers when querying for your Prismic\n\t * repository's content, a Link Resolver does not need to be provided.\n\t * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link\n\t * component, provide the Link component to this prop.\n\t */\n\tinternalComponent?: React.ElementType<InternalComponentProps>;\n\n\t/**\n\t * The component rendered for external URLs. Defaults to `<a>`.\n\t */\n\texternalComponent?: React.ComponentType<ExternalComponentProps>;\n\n\t/**\n\t * The children to render for the link. If no children are provided, the\n\t * link's `text` property will be used.\n\t */\n\tchildren?: React.ReactNode;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\nexport const PrismicLink = React.forwardRef(function PrismicLink<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: React.ForwardedRef<Element>,\n): JSX.Element {\n\tconst {\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t(\"text\" in field\n\t\t\t\t\t? Object.keys(field).length > 2\n\t\t\t\t\t: Object.keys(field).length > 1) &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent ||\n\t\tdefaultComponent) as React.ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent ||\n\t\tdefaultComponent) as React.ComponentType<LinkProps>;\n\tconst Component =\n\t\thref && isInternalURL(href) ? InternalComponent : ExternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Component>\n\t);\n}) as <\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: React.ForwardedRef<Element>;\n\t},\n) => JSX.Element;\n"],"names":["PrismicLink"],"mappings":";;;;;AAeO,MAAM,mBAAmB;AAyFzB,MAAM,cAAc,MAAM,WAAW,SAASA,aAIpD,OACA,KAAgC;AAE1B,QAAA,EACL,OACA,UAAU,KACV,cACA,mBACA,mBACA,UACA,GAAG,UAAA,IACA;AAEJ,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8I,OAC7I,yBAAyB,GACvB;AAAA,MAAA,YAGH,UAAU,QACR,OAAO,KAAK,KAAK,EAAE,SAAS,IAC5B,OAAO,KAAK,KAAK,EAAE,SAAS,MAC/B,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,QAC7C;AACD,gBAAQ,KACP,uJAAuJ,OACtJ,yBAAyB,KAE1B,KAAK;AAAA,MAEN;AAAA,eACS,KAAK;AACf,UAAI,EAAE,SAAS,OAAO,QAAQ,MAAM;AACnC,gBAAQ,KACP,0JAA0J,OACzJ,yBAAyB,KAE1B,GAAG;AAAA,MAEJ;AAAA,IACD;AAAA,EACD;AAEK,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,MAAI,MAA0B;AAC9B,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAChB;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,QAAM,oBAAqB,qBAC1B;AACD,QAAM,oBAAqB,qBAC1B;AACD,QAAM,YACL,QAAQ,cAAc,IAAI,IAAI,oBAAoB;AAEnD,SACE,oBAAA,WAAA,EAAU,KAAc,GAAA,OAAW,GAAA,WAAW,MAAY,KACzD,UAAA,cAAc,QAAQ,WAAW,+BAAO,KAC1C,CAAA;AAEF,CAAC;"}
|
|
@@ -54,11 +54,7 @@ const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
|
54
54
|
{
|
|
55
55
|
dispatch(["start"]);
|
|
56
56
|
}
|
|
57
|
-
client[methodName].call(
|
|
58
|
-
client,
|
|
59
|
-
...argsWithoutParams,
|
|
60
|
-
params
|
|
61
|
-
).then((result) => {
|
|
57
|
+
client[methodName].call(client, ...argsWithoutParams, params).then((result) => {
|
|
62
58
|
{
|
|
63
59
|
dispatch(["succeed", result]);
|
|
64
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStatefulPrismicClientMethod.cjs","sources":["../../src/useStatefulPrismicClientMethod.ts"],"sourcesContent":["import type * as prismic from \"@prismicio/client\";\n\nimport * as React from \"react\";\n\nimport { PrismicClientHookState } from \"./types\";\nimport { usePrismicClient } from \"./usePrismicClient\";\n\ntype StateMachineState<TData> = {\n\tstate: PrismicClientHookState;\n\tdata?: TData;\n\terror?: Error;\n};\n\ntype StateMachineAction<TData> =\n\t| [type: \"start\"]\n\t| [type: \"succeed\", payload: TData]\n\t| [type: \"fail\", payload: Error];\n\nconst reducer = <TData>(\n\tstate: StateMachineState<TData>,\n\taction: StateMachineAction<TData>,\n): StateMachineState<TData> => {\n\tswitch (action[0]) {\n\t\tcase \"start\": {\n\t\t\treturn { state: \"loading\" };\n\t\t}\n\n\t\tcase \"succeed\": {\n\t\t\treturn { state: \"loaded\", data: action[1] };\n\t\t}\n\n\t\tcase \"fail\": {\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tstate: \"failed\",\n\t\t\t\terror: action[1],\n\t\t\t};\n\t\t}\n\t}\n};\n\nconst initialState: StateMachineState<never> = {\n\tstate: \"idle\",\n};\n\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n\ntype ClientPrototype = typeof prismic.Client.prototype;\n\ntype ClientMethod<MethodName extends keyof ClientPrototype> =\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tClientPrototype[MethodName] extends (...args: any[]) => any\n\t\t? ClientPrototype[MethodName]\n\t\t: never;\n\ntype ClientMethodName = keyof {\n\t[P in keyof prismic.Client as prismic.Client[P] extends (\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t...args: any[]\n\t) => // eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tPromise<any>\n\t\t? P\n\t\t: never]: unknown;\n};\n\nexport type ClientMethodParameters<MethodName extends keyof ClientPrototype> =\n\tParameters<ClientMethod<MethodName>>;\n\nexport type HookOnlyParameters = {\n\tclient?: prismic.Client;\n\tskip?: boolean;\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] & HookOnlyParameters => {\n\t// This is a *very* naive check.\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\n/**\n * The return value of a `@prismicio/client` React hook.\n *\n * @typeParam TData - Data returned by the client.\n */\nexport type ClientHookReturnType<TData = unknown> = [\n\t/**\n\t * Data returned by the client.\n\t */\n\tdata: TData | undefined,\n\n\t/**\n\t * The current state of the hook's client method call.\n\t */\n\tstate: Pick<StateMachineState<TData>, \"state\" | \"error\">,\n];\n\n/**\n * Creates a React hook that forwards arguments to a specific method of a\n * `@prismicio/client` instance. The created hook has its own internal state\n * manager to report async status, such as pending or error statuses.\n *\n * @param methodName - The `@prismicio/client` method to which hook arguments\n * will be forwarded.\n *\n * @returns A new React hook configured for the provided method.\n *\n * @internal\n */\nexport const useStatefulPrismicClientMethod = <\n\tTMethodName extends ClientMethodName,\n\tTArgs extends Parameters<ClientMethod<TMethodName>>,\n\tTData extends UnwrapPromise<ReturnType<ClientMethod<TMethodName>>>,\n>(\n\tmethodName: TMethodName,\n\targs: TArgs,\n\texplicitClient?: prismic.Client,\n): ClientHookReturnType<TData> => {\n\tconst lastArg = args[args.length - 1];\n\tconst {\n\t\tclient: lastArgExplicitClient,\n\t\tskip,\n\t\t...params\n\t} = isParams(lastArg) ? lastArg : ({} as HookOnlyParameters);\n\tconst argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;\n\n\tconst client = usePrismicClient(explicitClient || lastArgExplicitClient);\n\n\tconst [state, dispatch] = React.useReducer<\n\t\tReact.Reducer<StateMachineState<TData>, StateMachineAction<TData>>\n\t>(reducer, initialState);\n\n\tReact.useEffect(\n\t\t() => {\n\t\t\t// Used to prevent dispatching an action if the hook was cleaned up.\n\t\t\tlet didCancel = false;\n\n\t\t\tif (!skip) {\n\t\t\t\tif (!didCancel) {\n\t\t\t\t\tdispatch([\"start\"]);\n\t\t\t\t}\n\n\t\t\t\
|
|
1
|
+
{"version":3,"file":"useStatefulPrismicClientMethod.cjs","sources":["../../src/useStatefulPrismicClientMethod.ts"],"sourcesContent":["import type * as prismic from \"@prismicio/client\";\n\nimport * as React from \"react\";\n\nimport { PrismicClientHookState } from \"./types\";\nimport { usePrismicClient } from \"./usePrismicClient\";\n\ntype StateMachineState<TData> = {\n\tstate: PrismicClientHookState;\n\tdata?: TData;\n\terror?: Error;\n};\n\ntype StateMachineAction<TData> =\n\t| [type: \"start\"]\n\t| [type: \"succeed\", payload: TData]\n\t| [type: \"fail\", payload: Error];\n\nconst reducer = <TData>(\n\tstate: StateMachineState<TData>,\n\taction: StateMachineAction<TData>,\n): StateMachineState<TData> => {\n\tswitch (action[0]) {\n\t\tcase \"start\": {\n\t\t\treturn { state: \"loading\" };\n\t\t}\n\n\t\tcase \"succeed\": {\n\t\t\treturn { state: \"loaded\", data: action[1] };\n\t\t}\n\n\t\tcase \"fail\": {\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tstate: \"failed\",\n\t\t\t\terror: action[1],\n\t\t\t};\n\t\t}\n\t}\n};\n\nconst initialState: StateMachineState<never> = {\n\tstate: \"idle\",\n};\n\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n\ntype ClientPrototype = typeof prismic.Client.prototype;\n\ntype ClientMethod<MethodName extends keyof ClientPrototype> =\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tClientPrototype[MethodName] extends (...args: any[]) => any\n\t\t? ClientPrototype[MethodName]\n\t\t: never;\n\ntype ClientMethodName = keyof {\n\t[P in keyof prismic.Client as prismic.Client[P] extends (\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t...args: any[]\n\t) => // eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tPromise<any>\n\t\t? P\n\t\t: never]: unknown;\n};\n\nexport type ClientMethodParameters<MethodName extends keyof ClientPrototype> =\n\tParameters<ClientMethod<MethodName>>;\n\nexport type HookOnlyParameters = {\n\tclient?: prismic.Client;\n\tskip?: boolean;\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] & HookOnlyParameters => {\n\t// This is a *very* naive check.\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\n/**\n * The return value of a `@prismicio/client` React hook.\n *\n * @typeParam TData - Data returned by the client.\n */\nexport type ClientHookReturnType<TData = unknown> = [\n\t/**\n\t * Data returned by the client.\n\t */\n\tdata: TData | undefined,\n\n\t/**\n\t * The current state of the hook's client method call.\n\t */\n\tstate: Pick<StateMachineState<TData>, \"state\" | \"error\">,\n];\n\n/**\n * Creates a React hook that forwards arguments to a specific method of a\n * `@prismicio/client` instance. The created hook has its own internal state\n * manager to report async status, such as pending or error statuses.\n *\n * @param methodName - The `@prismicio/client` method to which hook arguments\n * will be forwarded.\n *\n * @returns A new React hook configured for the provided method.\n *\n * @internal\n */\nexport const useStatefulPrismicClientMethod = <\n\tTMethodName extends ClientMethodName,\n\tTArgs extends Parameters<ClientMethod<TMethodName>>,\n\tTData extends UnwrapPromise<ReturnType<ClientMethod<TMethodName>>>,\n>(\n\tmethodName: TMethodName,\n\targs: TArgs,\n\texplicitClient?: prismic.Client,\n): ClientHookReturnType<TData> => {\n\tconst lastArg = args[args.length - 1];\n\tconst {\n\t\tclient: lastArgExplicitClient,\n\t\tskip,\n\t\t...params\n\t} = isParams(lastArg) ? lastArg : ({} as HookOnlyParameters);\n\tconst argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;\n\n\tconst client = usePrismicClient(explicitClient || lastArgExplicitClient);\n\n\tconst [state, dispatch] = React.useReducer<\n\t\tReact.Reducer<StateMachineState<TData>, StateMachineAction<TData>>\n\t>(reducer, initialState);\n\n\tReact.useEffect(\n\t\t() => {\n\t\t\t// Used to prevent dispatching an action if the hook was cleaned up.\n\t\t\tlet didCancel = false;\n\n\t\t\tif (!skip) {\n\t\t\t\tif (!didCancel) {\n\t\t\t\t\tdispatch([\"start\"]);\n\t\t\t\t}\n\n\t\t\t\t// @ts-expect-error - Merging method arg types is too complex\n\t\t\t\tclient[methodName]\n\t\t\t\t\t.call(client, ...argsWithoutParams, params)\n\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\tif (!didCancel) {\n\t\t\t\t\t\t\tdispatch([\"succeed\", result as TData]);\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error) => {\n\t\t\t\t\t\tif (!didCancel) {\n\t\t\t\t\t\t\tdispatch([\"fail\", error]);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Ensure we don't dispatch an action if the hook is cleaned up.\n\t\t\t() => {\n\t\t\t\tdidCancel = true;\n\t\t\t};\n\t\t},\n\t\t// We must disable exhaustive-deps since we are using\n\t\t// JSON.stringify on params (effectively a deep equality check).\n\t\t// We want this effect to run again anytime params change.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[\n\t\t\tclient,\n\t\t\tmethodName,\n\t\t\tskip,\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\tJSON.stringify(argsWithoutParams),\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\tJSON.stringify(params),\n\t\t],\n\t);\n\n\treturn React.useMemo(\n\t\t() => [\n\t\t\tstate.data,\n\t\t\t{\n\t\t\t\tstate: state.state,\n\t\t\t\terror: state.error,\n\t\t\t},\n\t\t],\n\t\t[state],\n\t);\n};\n"],"names":["usePrismicClient","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,UAAU,CACf,OACA,WAC6B;AACrB,UAAA,OAAO,CAAC,GAAG;AAAA,IAClB,KAAK,SAAS;AACN,aAAA,EAAE,OAAO;IAChB;AAAA,IAED,KAAK,WAAW;AACf,aAAO,EAAE,OAAO,UAAU,MAAM,OAAO,CAAC;IACxC;AAAA,IAED,KAAK,QAAQ;AACL,aAAA;AAAA,QACN,GAAG;AAAA,QACH,OAAO;AAAA,QACP,OAAO,OAAO,CAAC;AAAA,MAAA;AAAA,IAEhB;AAAA,EACD;AACF;AAEA,MAAM,eAAyC;AAAA,EAC9C,OAAO;;AAuCR,MAAM,WAAW,CAChB,UACmE;AAE5D,SAAA,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;AA+BO,MAAM,iCAAiC,CAK7C,YACA,MACA,mBACgC;AAChC,QAAM,UAAU,KAAK,KAAK,SAAS,CAAC;AAC9B,QAAA,EACL,QAAQ,uBACR,MACA,GAAG,WACA,SAAS,OAAO,IAAI,UAAW;AAC7B,QAAA,oBAAoB,SAAS,OAAO,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI;AAE5D,QAAA,SAASA,iBAAAA,iBAAiB,kBAAkB,qBAAqB;AAEvE,QAAM,CAAC,OAAO,QAAQ,IAAIC,iBAAM,WAE9B,SAAS,YAAY;AAEjBA,mBAAA;AAAA,IACL,MAAK;AAIJ,UAAI,CAAC,MAAM;AACM;AACN,mBAAA,CAAC,OAAO,CAAC;AAAA,QAClB;AAGM,eAAA,UAAU,EACf,KAAK,QAAQ,GAAG,mBAAmB,MAAM,EACzC,KAAK,CAAC,WAAU;AACA;AACN,qBAAA,CAAC,WAAW,MAAe,CAAC;AAAA,UACrC;AAAA,QAAA,CACD,EACA,MAAM,CAAC,UAAS;AACA;AACN,qBAAA,CAAC,QAAQ,KAAK,CAAC;AAAA,UACxB;AAAA,QAAA,CACD;AAAA,MACF;AAAA,IAMF;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,KAAK,UAAU,iBAAiB;AAAA;AAAA,MAEhC,KAAK,UAAU,MAAM;AAAA,IACrB;AAAA,EAAA;AAGK,SAAAA,iBAAM,QACZ,MAAM;AAAA,IACL,MAAM;AAAA,IACN;AAAA,MACC,OAAO,MAAM;AAAA,MACb,OAAO,MAAM;AAAA,IACb;AAAA,EAAA,GAEF,CAAC,KAAK,CAAC;AAET;;"}
|
|
@@ -40,5 +40,5 @@ export type ClientHookReturnType<TData = unknown> = [
|
|
|
40
40
|
*
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
|
-
export declare const useStatefulPrismicClientMethod: <TMethodName extends "
|
|
43
|
+
export declare const useStatefulPrismicClientMethod: <TMethodName extends "get" | "getFirst" | "dangerouslyGetAll" | "getByID" | "getByIDs" | "getAllByIDs" | "getByUID" | "getByUIDs" | "getAllByUIDs" | "getSingle" | "getByType" | "getAllByType" | "getByTag" | "getAllByTag" | "getByEveryTag" | "getAllByEveryTag" | "getBySomeTags" | "getAllBySomeTags" | "getRepository" | "getRefs" | "getRefByID" | "getRefByLabel" | "getMasterRef" | "getReleases" | "getReleaseByID" | "getReleaseByLabel" | "getTags" | "buildQueryURL" | "resolvePreviewURL" | "graphQLFetch" | "fetchFn", TArgs extends Parameters<ClientMethod<TMethodName>>, TData extends UnwrapPromise<ReturnType<ClientMethod<TMethodName>>>>(methodName: TMethodName, args: TArgs, explicitClient?: prismic.Client) => ClientHookReturnType<TData>;
|
|
44
44
|
export {};
|
|
@@ -35,11 +35,7 @@ const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
|
35
35
|
{
|
|
36
36
|
dispatch(["start"]);
|
|
37
37
|
}
|
|
38
|
-
client[methodName].call(
|
|
39
|
-
client,
|
|
40
|
-
...argsWithoutParams,
|
|
41
|
-
params
|
|
42
|
-
).then((result) => {
|
|
38
|
+
client[methodName].call(client, ...argsWithoutParams, params).then((result) => {
|
|
43
39
|
{
|
|
44
40
|
dispatch(["succeed", result]);
|
|
45
41
|
}
|