@prismicio/react 2.9.2 → 3.0.0-alpha.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/README.md +10 -11
- package/dist/PrismicImage.d.ts +18 -633
- package/dist/PrismicImage.js +32 -33
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +77 -6
- package/dist/PrismicLink.js +42 -7
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +117 -4
- package/dist/PrismicRichText.js +74 -8
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicText.d.ts +9 -14
- package/dist/PrismicText.js +13 -14
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +3 -12
- package/dist/PrismicToolbar.js +7 -9
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +16 -70
- package/dist/SliceZone.js +17 -38
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.d.ts +13 -21
- package/dist/index.js +2 -29
- package/dist/index.js.map +1 -1
- package/dist/lib/devMsg.d.ts +2 -2
- package/dist/lib/devMsg.js +2 -2
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +54 -71
- package/src/PrismicImage.tsx +80 -65
- package/src/PrismicLink.tsx +196 -26
- package/src/PrismicRichText.tsx +333 -32
- package/src/PrismicText.tsx +25 -31
- package/src/PrismicToolbar.tsx +9 -29
- package/src/SliceZone.tsx +59 -151
- package/src/index.ts +17 -53
- package/src/lib/devMsg.ts +3 -3
- package/dist/PrismicImage.cjs +0 -68
- package/dist/PrismicImage.cjs.map +0 -1
- package/dist/PrismicLink.cjs +0 -29
- package/dist/PrismicLink.cjs.map +0 -1
- package/dist/PrismicProvider.cjs +0 -41
- package/dist/PrismicProvider.cjs.map +0 -1
- package/dist/PrismicProvider.d.ts +0 -83
- package/dist/PrismicProvider.js +0 -24
- package/dist/PrismicProvider.js.map +0 -1
- package/dist/PrismicRichText.cjs +0 -30
- package/dist/PrismicRichText.cjs.map +0 -1
- package/dist/PrismicText.cjs +0 -44
- package/dist/PrismicText.cjs.map +0 -1
- package/dist/PrismicToolbar.cjs +0 -43
- package/dist/PrismicToolbar.cjs.map +0 -1
- package/dist/SliceZone.cjs +0 -53
- package/dist/SliceZone.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +0 -22
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +0 -22
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +0 -46
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +0 -46
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +0 -21
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +0 -21
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -24
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -24
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs +0 -29
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js +0 -29
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js.map +0 -1
- package/dist/clientHooks.cjs +0 -40
- package/dist/clientHooks.cjs.map +0 -1
- package/dist/clientHooks.d.ts +0 -321
- package/dist/clientHooks.js +0 -40
- package/dist/clientHooks.js.map +0 -1
- package/dist/index.cjs +0 -48
- package/dist/index.cjs.map +0 -1
- package/dist/lib/devMsg.cjs +0 -8
- package/dist/lib/devMsg.cjs.map +0 -1
- package/dist/lib/isInternalURL.cjs +0 -9
- package/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/lib/isInternalURL.d.ts +0 -8
- package/dist/lib/isInternalURL.js +0 -9
- package/dist/lib/isInternalURL.js.map +0 -1
- package/dist/lib/pascalCase.cjs +0 -10
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.d.ts +0 -26
- package/dist/lib/pascalCase.js +0 -10
- package/dist/lib/pascalCase.js.map +0 -1
- package/dist/package.json.cjs +0 -5
- package/dist/package.json.cjs.map +0 -1
- package/dist/react-server/PrismicLink.cjs +0 -59
- package/dist/react-server/PrismicLink.cjs.map +0 -1
- package/dist/react-server/PrismicLink.d.ts +0 -77
- package/dist/react-server/PrismicLink.js +0 -42
- package/dist/react-server/PrismicLink.js.map +0 -1
- package/dist/react-server/PrismicRichText.cjs +0 -102
- package/dist/react-server/PrismicRichText.cjs.map +0 -1
- package/dist/react-server/PrismicRichText.d.ts +0 -104
- package/dist/react-server/PrismicRichText.js +0 -84
- package/dist/react-server/PrismicRichText.js.map +0 -1
- package/dist/react-server/index.d.ts +0 -4
- package/dist/react-server/unsupported.cjs +0 -97
- package/dist/react-server/unsupported.cjs.map +0 -1
- package/dist/react-server/unsupported.d.ts +0 -22
- package/dist/react-server/unsupported.js +0 -97
- package/dist/react-server/unsupported.js.map +0 -1
- package/dist/react-server.cjs +0 -44
- package/dist/react-server.cjs.map +0 -1
- package/dist/react-server.js +0 -41
- package/dist/react-server.js.map +0 -1
- package/dist/types.d.ts +0 -19
- package/dist/usePrismicClient.cjs +0 -13
- package/dist/usePrismicClient.cjs.map +0 -1
- package/dist/usePrismicClient.d.ts +0 -11
- package/dist/usePrismicClient.js +0 -13
- package/dist/usePrismicClient.js.map +0 -1
- package/dist/usePrismicContext.cjs +0 -26
- package/dist/usePrismicContext.cjs.map +0 -1
- package/dist/usePrismicContext.d.ts +0 -8
- package/dist/usePrismicContext.js +0 -9
- package/dist/usePrismicContext.js.map +0 -1
- package/dist/usePrismicPreviewResolver.cjs +0 -44
- package/dist/usePrismicPreviewResolver.cjs.map +0 -1
- package/dist/usePrismicPreviewResolver.d.ts +0 -45
- package/dist/usePrismicPreviewResolver.js +0 -27
- package/dist/usePrismicPreviewResolver.js.map +0 -1
- package/dist/useStatefulPrismicClientMethod.cjs +0 -91
- package/dist/useStatefulPrismicClientMethod.cjs.map +0 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +0 -44
- package/dist/useStatefulPrismicClientMethod.js +0 -74
- package/dist/useStatefulPrismicClientMethod.js.map +0 -1
- package/src/PrismicProvider.tsx +0 -132
- package/src/clientHooks.ts +0 -472
- package/src/lib/isInternalURL.ts +0 -14
- package/src/lib/pascalCase.ts +0 -79
- package/src/react-server/PrismicLink.tsx +0 -197
- package/src/react-server/PrismicRichText.tsx +0 -326
- package/src/react-server/index.ts +0 -38
- package/src/react-server/unsupported.ts +0 -184
- package/src/types.ts +0 -24
- package/src/usePrismicClient.ts +0 -30
- package/src/usePrismicContext.ts +0 -13
- package/src/usePrismicPreviewResolver.ts +0 -93
- package/src/useStatefulPrismicClientMethod.ts +0 -196
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const usePrismicClient = require("./usePrismicClient.cjs");
|
|
5
|
-
function _interopNamespaceDefault(e) {
|
|
6
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
|
-
const reducer = (state, action) => {
|
|
23
|
-
switch (action[0]) {
|
|
24
|
-
case "start": {
|
|
25
|
-
return { state: "loading" };
|
|
26
|
-
}
|
|
27
|
-
case "succeed": {
|
|
28
|
-
return { state: "loaded", data: action[1] };
|
|
29
|
-
}
|
|
30
|
-
case "fail": {
|
|
31
|
-
return {
|
|
32
|
-
...state,
|
|
33
|
-
state: "failed",
|
|
34
|
-
error: action[1]
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const initialState = {
|
|
40
|
-
state: "idle"
|
|
41
|
-
};
|
|
42
|
-
const isParams = (value) => {
|
|
43
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
|
-
};
|
|
45
|
-
const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
46
|
-
const lastArg = args[args.length - 1];
|
|
47
|
-
const { client: lastArgExplicitClient, skip, ...params } = isParams(lastArg) ? lastArg : {};
|
|
48
|
-
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
49
|
-
const client = usePrismicClient.usePrismicClient(explicitClient || lastArgExplicitClient);
|
|
50
|
-
const [state, dispatch] = React__namespace.useReducer(reducer, initialState);
|
|
51
|
-
React__namespace.useEffect(
|
|
52
|
-
() => {
|
|
53
|
-
if (!skip) {
|
|
54
|
-
{
|
|
55
|
-
dispatch(["start"]);
|
|
56
|
-
}
|
|
57
|
-
client[methodName].call(client, ...argsWithoutParams, params).then((result) => {
|
|
58
|
-
{
|
|
59
|
-
dispatch(["succeed", result]);
|
|
60
|
-
}
|
|
61
|
-
}).catch((error) => {
|
|
62
|
-
{
|
|
63
|
-
dispatch(["fail", error]);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
// We must disable exhaustive-deps since we are using
|
|
69
|
-
// JSON.stringify on params (effectively a deep equality check).
|
|
70
|
-
// We want this effect to run again anytime params change.
|
|
71
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
-
[
|
|
73
|
-
client,
|
|
74
|
-
methodName,
|
|
75
|
-
skip,
|
|
76
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
-
JSON.stringify(argsWithoutParams),
|
|
78
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
|
-
JSON.stringify(params)
|
|
80
|
-
]
|
|
81
|
-
);
|
|
82
|
-
return React__namespace.useMemo(() => [
|
|
83
|
-
state.data,
|
|
84
|
-
{
|
|
85
|
-
state: state.state,
|
|
86
|
-
error: state.error
|
|
87
|
-
}
|
|
88
|
-
], [state]);
|
|
89
|
-
};
|
|
90
|
-
exports.useStatefulPrismicClientMethod = useStatefulPrismicClientMethod;
|
|
91
|
-
//# sourceMappingURL=useStatefulPrismicClientMethod.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type * as prismic from "@prismicio/client";
|
|
2
|
-
import { PrismicClientHookState } from "./types";
|
|
3
|
-
type StateMachineState<TData> = {
|
|
4
|
-
state: PrismicClientHookState;
|
|
5
|
-
data?: TData;
|
|
6
|
-
error?: Error;
|
|
7
|
-
};
|
|
8
|
-
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
9
|
-
type ClientPrototype = typeof prismic.Client.prototype;
|
|
10
|
-
type ClientMethod<MethodName extends keyof ClientPrototype> = ClientPrototype[MethodName] extends (...args: any[]) => any ? ClientPrototype[MethodName] : never;
|
|
11
|
-
export type ClientMethodParameters<MethodName extends keyof ClientPrototype> = Parameters<ClientMethod<MethodName>>;
|
|
12
|
-
export type HookOnlyParameters = {
|
|
13
|
-
client?: prismic.Client;
|
|
14
|
-
skip?: boolean;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* The return value of a `@prismicio/client` React hook.
|
|
18
|
-
*
|
|
19
|
-
* @typeParam TData - Data returned by the client.
|
|
20
|
-
*/
|
|
21
|
-
export type ClientHookReturnType<TData = unknown> = [
|
|
22
|
-
/**
|
|
23
|
-
* Data returned by the client.
|
|
24
|
-
*/
|
|
25
|
-
data: TData | undefined,
|
|
26
|
-
/**
|
|
27
|
-
* The current state of the hook's client method call.
|
|
28
|
-
*/
|
|
29
|
-
state: Pick<StateMachineState<TData>, "state" | "error">
|
|
30
|
-
];
|
|
31
|
-
/**
|
|
32
|
-
* Creates a React hook that forwards arguments to a specific method of a
|
|
33
|
-
* `@prismicio/client` instance. The created hook has its own internal state
|
|
34
|
-
* manager to report async status, such as pending or error statuses.
|
|
35
|
-
*
|
|
36
|
-
* @param methodName - The `@prismicio/client` method to which hook arguments
|
|
37
|
-
* will be forwarded.
|
|
38
|
-
*
|
|
39
|
-
* @returns A new React hook configured for the provided method.
|
|
40
|
-
*
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
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
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { usePrismicClient } from "./usePrismicClient.js";
|
|
3
|
-
const reducer = (state, action) => {
|
|
4
|
-
switch (action[0]) {
|
|
5
|
-
case "start": {
|
|
6
|
-
return { state: "loading" };
|
|
7
|
-
}
|
|
8
|
-
case "succeed": {
|
|
9
|
-
return { state: "loaded", data: action[1] };
|
|
10
|
-
}
|
|
11
|
-
case "fail": {
|
|
12
|
-
return {
|
|
13
|
-
...state,
|
|
14
|
-
state: "failed",
|
|
15
|
-
error: action[1]
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const initialState = {
|
|
21
|
-
state: "idle"
|
|
22
|
-
};
|
|
23
|
-
const isParams = (value) => {
|
|
24
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
-
};
|
|
26
|
-
const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
27
|
-
const lastArg = args[args.length - 1];
|
|
28
|
-
const { client: lastArgExplicitClient, skip, ...params } = isParams(lastArg) ? lastArg : {};
|
|
29
|
-
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
30
|
-
const client = usePrismicClient(explicitClient || lastArgExplicitClient);
|
|
31
|
-
const [state, dispatch] = React.useReducer(reducer, initialState);
|
|
32
|
-
React.useEffect(
|
|
33
|
-
() => {
|
|
34
|
-
if (!skip) {
|
|
35
|
-
{
|
|
36
|
-
dispatch(["start"]);
|
|
37
|
-
}
|
|
38
|
-
client[methodName].call(client, ...argsWithoutParams, params).then((result) => {
|
|
39
|
-
{
|
|
40
|
-
dispatch(["succeed", result]);
|
|
41
|
-
}
|
|
42
|
-
}).catch((error) => {
|
|
43
|
-
{
|
|
44
|
-
dispatch(["fail", error]);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
// We must disable exhaustive-deps since we are using
|
|
50
|
-
// JSON.stringify on params (effectively a deep equality check).
|
|
51
|
-
// We want this effect to run again anytime params change.
|
|
52
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
|
-
[
|
|
54
|
-
client,
|
|
55
|
-
methodName,
|
|
56
|
-
skip,
|
|
57
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
JSON.stringify(argsWithoutParams),
|
|
59
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
-
JSON.stringify(params)
|
|
61
|
-
]
|
|
62
|
-
);
|
|
63
|
-
return React.useMemo(() => [
|
|
64
|
-
state.data,
|
|
65
|
-
{
|
|
66
|
-
state: state.state,
|
|
67
|
-
error: state.error
|
|
68
|
-
}
|
|
69
|
-
], [state]);
|
|
70
|
-
};
|
|
71
|
-
export {
|
|
72
|
-
useStatefulPrismicClientMethod
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=useStatefulPrismicClientMethod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStatefulPrismicClientMethod.js","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":[],"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,SAAS,iBAAiB,kBAAkB,qBAAqB;AAEvE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,WAE9B,SAAS,YAAY;AAEjB,QAAA;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,SAAA,MAAM,QACZ,MAAM;AAAA,IACL,MAAM;AAAA,IACN;AAAA,MACC,OAAO,MAAM;AAAA,MACb,OAAO,MAAM;AAAA,IACb;AAAA,EAAA,GAEF,CAAC,KAAK,CAAC;AAET;"}
|
package/src/PrismicProvider.tsx
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import * as prismic from "@prismicio/client";
|
|
5
|
-
|
|
6
|
-
import { JSXFunctionSerializer, JSXMapSerializer } from "./types";
|
|
7
|
-
import { LinkProps } from "./PrismicLink";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* React context value containing shared configuration for `@prismicio/react`
|
|
11
|
-
* components and hooks.
|
|
12
|
-
*/
|
|
13
|
-
export type PrismicContextValue<
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,
|
|
16
|
-
> = {
|
|
17
|
-
/**
|
|
18
|
-
* A `@prismicio/client` instance used to fetch content from a Prismic
|
|
19
|
-
* repository. This is used by `@prismicio/react` hooks, such as
|
|
20
|
-
* `usePrismicDocuments()`.
|
|
21
|
-
*/
|
|
22
|
-
client?: prismic.Client;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A Link Resolver used to resolve links for `<PrismicLink>` and
|
|
26
|
-
* `<PrismicRichText>`.
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* If your app uses Route Resolvers when querying for your Prismic
|
|
30
|
-
* repository's content, a Link Resolver does not need to be provided.
|
|
31
|
-
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
32
|
-
*/
|
|
33
|
-
linkResolver?: LinkResolverFunction;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* A map or function that maps a Rich Text block to a React component.
|
|
37
|
-
*
|
|
38
|
-
* @remarks
|
|
39
|
-
* Prefer using a map serializer over the function serializer when possible.
|
|
40
|
-
* The map serializer is simpler to maintain.
|
|
41
|
-
* @example A map serializer.
|
|
42
|
-
*
|
|
43
|
-
* ```jsx
|
|
44
|
-
* {
|
|
45
|
-
* heading1: ({children}) => <Heading>{children}</Heading>
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @example A function serializer.
|
|
50
|
-
*
|
|
51
|
-
* ```jsx
|
|
52
|
-
* (type, node, content, children) => {
|
|
53
|
-
* switch (type) {
|
|
54
|
-
* case "heading1": {
|
|
55
|
-
* return <Heading>{chidlren}</Heading>;
|
|
56
|
-
* }
|
|
57
|
-
* }
|
|
58
|
-
* };
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
richTextComponents?: JSXMapSerializer | JSXFunctionSerializer;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The component rendered by `<PrismicLink>` for internal URLs. Defaults to
|
|
65
|
-
* `<a>`.
|
|
66
|
-
*/
|
|
67
|
-
internalLinkComponent?: React.ComponentType<LinkProps>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The component rendered by `<PrismicLink>` for external URLs. Defaults to
|
|
71
|
-
* `<a>`.
|
|
72
|
-
*/
|
|
73
|
-
externalLinkComponent?: React.ComponentType<LinkProps>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Children for the component.
|
|
77
|
-
*/
|
|
78
|
-
children?: React.ReactNode;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* React context containing shared configuration for `@prismicio/react`
|
|
83
|
-
* components and hooks.
|
|
84
|
-
*/
|
|
85
|
-
export const PrismicContext = React.createContext<PrismicContextValue>({});
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Props for `<PrismicProvider>`.
|
|
89
|
-
*/
|
|
90
|
-
export type PrismicProviderProps<
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction<any>,
|
|
93
|
-
> = PrismicContextValue<LinkResolverFunction>;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* React context provider to share configuration for `@prismicio/react`
|
|
97
|
-
* components and hooks.
|
|
98
|
-
*
|
|
99
|
-
* @returns A React context provider with shared configuration.
|
|
100
|
-
*/
|
|
101
|
-
export const PrismicProvider = <
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any>,
|
|
104
|
-
>({
|
|
105
|
-
client,
|
|
106
|
-
linkResolver,
|
|
107
|
-
richTextComponents,
|
|
108
|
-
internalLinkComponent,
|
|
109
|
-
externalLinkComponent,
|
|
110
|
-
children,
|
|
111
|
-
}: PrismicProviderProps<LinkResolverFunction>): React.JSX.Element => {
|
|
112
|
-
const value = React.useMemo<PrismicContextValue<LinkResolverFunction>>(
|
|
113
|
-
() => ({
|
|
114
|
-
client,
|
|
115
|
-
linkResolver,
|
|
116
|
-
richTextComponents,
|
|
117
|
-
internalLinkComponent,
|
|
118
|
-
externalLinkComponent,
|
|
119
|
-
}),
|
|
120
|
-
[
|
|
121
|
-
client,
|
|
122
|
-
linkResolver,
|
|
123
|
-
richTextComponents,
|
|
124
|
-
internalLinkComponent,
|
|
125
|
-
externalLinkComponent,
|
|
126
|
-
],
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<PrismicContext.Provider value={value}>{children}</PrismicContext.Provider>
|
|
131
|
-
);
|
|
132
|
-
};
|