@prismicio/react 2.5.1 → 2.6.0-alpha.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.cjs +7 -11
- package/dist/PrismicImage.cjs.map +1 -1
- package/dist/PrismicImage.d.ts +162 -163
- package/dist/PrismicImage.js +6 -10
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.cjs +4 -66
- package/dist/PrismicLink.cjs.map +1 -1
- package/dist/PrismicLink.d.ts +6 -105
- package/dist/PrismicLink.js +4 -65
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicProvider.cjs.map +1 -1
- package/dist/PrismicProvider.d.ts +83 -84
- package/dist/PrismicProvider.js.map +1 -1
- package/dist/PrismicRichText.cjs +4 -71
- package/dist/PrismicRichText.cjs.map +1 -1
- package/dist/PrismicRichText.d.ts +4 -116
- package/dist/PrismicRichText.js +5 -70
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicText.cjs +4 -4
- package/dist/PrismicText.cjs.map +1 -1
- package/dist/PrismicText.d.ts +39 -39
- package/dist/PrismicText.js +3 -3
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.cjs +6 -4
- package/dist/PrismicToolbar.cjs.map +1 -1
- package/dist/PrismicToolbar.d.ts +23 -21
- package/dist/PrismicToolbar.js +6 -4
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.cjs +4 -17
- package/dist/SliceZone.cjs.map +1 -1
- package/dist/SliceZone.d.ts +127 -188
- package/dist/SliceZone.js +4 -17
- package/dist/SliceZone.js.map +1 -1
- package/dist/clientHooks.d.ts +357 -357
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -46
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/__PRODUCTION__.d.ts +7 -7
- package/dist/lib/devMsg.d.ts +16 -16
- package/dist/lib/invariant.d.ts +24 -24
- package/dist/lib/isInternalURL.d.ts +8 -8
- package/dist/lib/pascalCase.d.ts +26 -26
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/react-server/PrismicLink.cjs +59 -0
- package/dist/react-server/PrismicLink.cjs.map +1 -0
- package/dist/react-server/PrismicLink.d.ts +72 -0
- package/dist/react-server/PrismicLink.js +42 -0
- package/dist/react-server/PrismicLink.js.map +1 -0
- package/dist/react-server/PrismicRichText.cjs +92 -0
- package/dist/react-server/PrismicRichText.cjs.map +1 -0
- package/dist/react-server/PrismicRichText.d.ts +104 -0
- package/dist/react-server/PrismicRichText.js +73 -0
- package/dist/react-server/PrismicRichText.js.map +1 -0
- package/dist/react-server/index.d.ts +4 -0
- package/dist/react-server/unsupported.cjs +97 -0
- package/dist/react-server/unsupported.cjs.map +1 -0
- package/dist/react-server/unsupported.d.ts +22 -0
- package/dist/react-server/unsupported.js +97 -0
- package/dist/react-server/unsupported.js.map +1 -0
- package/dist/react-server.cjs +44 -0
- package/dist/react-server.cjs.map +1 -0
- package/dist/react-server.js +41 -0
- package/dist/react-server.js.map +1 -0
- package/dist/types.d.ts +19 -19
- package/dist/usePrismicClient.d.ts +11 -11
- package/dist/usePrismicContext.d.ts +8 -8
- package/dist/usePrismicPreviewResolver.d.ts +45 -45
- package/dist/useStatefulPrismicClientMethod.cjs +6 -0
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +44 -44
- package/dist/useStatefulPrismicClientMethod.js +6 -0
- package/dist/useStatefulPrismicClientMethod.js.map +1 -1
- package/package.json +42 -47
- package/src/PrismicImage.tsx +30 -37
- package/src/PrismicLink.tsx +29 -259
- package/src/PrismicProvider.tsx +9 -8
- package/src/PrismicRichText.tsx +28 -275
- package/src/PrismicText.tsx +4 -5
- package/src/PrismicToolbar.tsx +7 -6
- package/src/SliceZone.tsx +8 -129
- package/src/index.ts +1 -9
- package/src/react-server/PrismicLink.tsx +179 -0
- package/src/react-server/PrismicRichText.tsx +267 -0
- package/src/react-server/index.ts +38 -0
- package/src/react-server/unsupported.ts +98 -0
- package/dist/lib/pascalCase.cjs +0 -10
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.js +0 -10
- package/dist/lib/pascalCase.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,6 @@ const SliceZone = require("./SliceZone.cjs");
|
|
|
12
12
|
const PrismicToolbar = require("./PrismicToolbar.cjs");
|
|
13
13
|
const usePrismicPreviewResolver = require("./usePrismicPreviewResolver.cjs");
|
|
14
14
|
const clientHooks = require("./clientHooks.cjs");
|
|
15
|
-
const Elements = prismicR.Element;
|
|
16
15
|
exports.PrismicProvider = PrismicProvider.PrismicProvider;
|
|
17
16
|
exports.usePrismicContext = usePrismicContext.usePrismicContext;
|
|
18
17
|
exports.usePrismicClient = usePrismicClient.usePrismicClient;
|
|
@@ -46,5 +45,4 @@ exports.usePrismicDocumentsByTag = clientHooks.usePrismicDocumentsByTag;
|
|
|
46
45
|
exports.usePrismicDocumentsByType = clientHooks.usePrismicDocumentsByType;
|
|
47
46
|
exports.usePrismicDocumentsByUIDs = clientHooks.usePrismicDocumentsByUIDs;
|
|
48
47
|
exports.useSinglePrismicDocument = clientHooks.useSinglePrismicDocument;
|
|
49
|
-
exports.Elements = Elements;
|
|
50
48
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,21 @@
|
|
|
1
|
-
export { PrismicProvider } from "./PrismicProvider";
|
|
2
|
-
export type { PrismicProviderProps, PrismicContextValue, } from "./PrismicProvider";
|
|
3
|
-
export { usePrismicContext } from "./usePrismicContext";
|
|
4
|
-
export { usePrismicClient } from "./usePrismicClient";
|
|
5
|
-
export { PrismicLink } from "./PrismicLink";
|
|
6
|
-
export type { PrismicLinkProps, LinkProps } from "./PrismicLink";
|
|
7
|
-
export { PrismicText } from "./PrismicText";
|
|
8
|
-
export type { PrismicTextProps } from "./PrismicText";
|
|
9
|
-
export { PrismicRichText } from "./PrismicRichText";
|
|
10
|
-
export type { PrismicRichTextProps } from "./PrismicRichText";
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
readonly heading6: "heading6";
|
|
23
|
-
readonly paragraph: "paragraph";
|
|
24
|
-
readonly preformatted: "preformatted";
|
|
25
|
-
readonly strong: "strong";
|
|
26
|
-
readonly em: "em";
|
|
27
|
-
readonly listItem: "list-item";
|
|
28
|
-
readonly oListItem: "o-list-item";
|
|
29
|
-
readonly list: "group-list-item";
|
|
30
|
-
readonly oList: "group-o-list-item";
|
|
31
|
-
readonly image: "image";
|
|
32
|
-
readonly embed: "embed";
|
|
33
|
-
readonly hyperlink: "hyperlink";
|
|
34
|
-
readonly label: "label";
|
|
35
|
-
readonly span: "span";
|
|
36
|
-
};
|
|
37
|
-
export { PrismicImage } from "./PrismicImage";
|
|
38
|
-
export type { PrismicImageProps } from "./PrismicImage";
|
|
39
|
-
export { SliceZone, TODOSliceComponent } from "./SliceZone";
|
|
40
|
-
export type { SliceComponentProps, SliceComponentType, SliceLikeRestV2, SliceLikeGraphQL, SliceLike, SliceZoneComponents, SliceZoneLike, SliceZoneProps, SliceZoneResolver, } from "./SliceZone";
|
|
41
|
-
export { PrismicToolbar } from "./PrismicToolbar";
|
|
42
|
-
export type { PrismicToolbarProps } from "./PrismicToolbar";
|
|
43
|
-
export { usePrismicPreviewResolver } from "./usePrismicPreviewResolver";
|
|
44
|
-
export type { UsePrismicPreviewResolverArgs } from "./usePrismicPreviewResolver";
|
|
45
|
-
export { useAllPrismicDocumentsDangerously, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument, } from "./clientHooks";
|
|
46
|
-
export type { JSXMapSerializer, JSXFunctionSerializer, PrismicClientHookState, } from "./types";
|
|
1
|
+
export { PrismicProvider } from "./PrismicProvider";
|
|
2
|
+
export type { PrismicProviderProps, PrismicContextValue, } from "./PrismicProvider";
|
|
3
|
+
export { usePrismicContext } from "./usePrismicContext";
|
|
4
|
+
export { usePrismicClient } from "./usePrismicClient";
|
|
5
|
+
export { PrismicLink } from "./PrismicLink";
|
|
6
|
+
export type { PrismicLinkProps, LinkProps } from "./PrismicLink";
|
|
7
|
+
export { PrismicText } from "./PrismicText";
|
|
8
|
+
export type { PrismicTextProps } from "./PrismicText";
|
|
9
|
+
export { PrismicRichText } from "./PrismicRichText";
|
|
10
|
+
export type { PrismicRichTextProps } from "./PrismicRichText";
|
|
11
|
+
export { Element } from "@prismicio/richtext";
|
|
12
|
+
export { PrismicImage } from "./PrismicImage";
|
|
13
|
+
export type { PrismicImageProps } from "./PrismicImage";
|
|
14
|
+
export { SliceZone, TODOSliceComponent } from "./SliceZone";
|
|
15
|
+
export type { SliceComponentProps, SliceComponentType, SliceLikeRestV2, SliceLikeGraphQL, SliceLike, SliceZoneLike, SliceZoneProps, } from "./SliceZone";
|
|
16
|
+
export { PrismicToolbar } from "./PrismicToolbar";
|
|
17
|
+
export type { PrismicToolbarProps } from "./PrismicToolbar";
|
|
18
|
+
export { usePrismicPreviewResolver } from "./usePrismicPreviewResolver";
|
|
19
|
+
export type { UsePrismicPreviewResolverArgs } from "./usePrismicPreviewResolver";
|
|
20
|
+
export { useAllPrismicDocumentsDangerously, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument, } from "./clientHooks";
|
|
21
|
+
export type { JSXMapSerializer, JSXFunctionSerializer, PrismicClientHookState, } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -5,16 +5,13 @@ import { PrismicLink } from "./PrismicLink.js";
|
|
|
5
5
|
import { PrismicText } from "./PrismicText.js";
|
|
6
6
|
import { PrismicRichText } from "./PrismicRichText.js";
|
|
7
7
|
import { Element } from "@prismicio/richtext";
|
|
8
|
-
import { Element as Element2 } from "@prismicio/richtext";
|
|
9
8
|
import { PrismicImage } from "./PrismicImage.js";
|
|
10
9
|
import { SliceZone, TODOSliceComponent } from "./SliceZone.js";
|
|
11
10
|
import { PrismicToolbar } from "./PrismicToolbar.js";
|
|
12
11
|
import { usePrismicPreviewResolver } from "./usePrismicPreviewResolver.js";
|
|
13
12
|
import { useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument } from "./clientHooks.js";
|
|
14
|
-
const Elements = Element;
|
|
15
13
|
export {
|
|
16
|
-
|
|
17
|
-
Elements,
|
|
14
|
+
Element,
|
|
18
15
|
PrismicImage,
|
|
19
16
|
PrismicLink,
|
|
20
17
|
PrismicProvider,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `true` if in the production environment, `false` otherwise.
|
|
3
|
-
*
|
|
4
|
-
* This boolean can be used to perform actions only in development environments,
|
|
5
|
-
* such as logging.
|
|
6
|
-
*/
|
|
7
|
-
export declare const __PRODUCTION__: boolean;
|
|
1
|
+
/**
|
|
2
|
+
* `true` if in the production environment, `false` otherwise.
|
|
3
|
+
*
|
|
4
|
+
* This boolean can be used to perform actions only in development environments,
|
|
5
|
+
* such as logging.
|
|
6
|
+
*/
|
|
7
|
+
export declare const __PRODUCTION__: boolean;
|
package/dist/lib/devMsg.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* devMsg("missing-param");
|
|
8
|
-
* // => "https://prismic.dev/msg/react/v1.2.3/missing-param.md"
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
12
|
-
* the Git repository's `/messages` directory.
|
|
13
|
-
*
|
|
14
|
-
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
15
|
-
*/
|
|
16
|
-
export declare const devMsg: (slug: string) => string;
|
|
1
|
+
/**
|
|
2
|
+
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* devMsg("missing-param");
|
|
8
|
+
* // => "https://prismic.dev/msg/react/v1.2.3/missing-param.md"
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
12
|
+
* the Git repository's `/messages` directory.
|
|
13
|
+
*
|
|
14
|
+
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
15
|
+
*/
|
|
16
|
+
export declare const devMsg: (slug: string) => string;
|
package/dist/lib/invariant.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2019 Alexander Reardon
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in
|
|
14
|
-
* all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
export declare function invariant(condition: unknown, message?: string): asserts condition;
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 Alexander Reardon
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
export declare function invariant(condition: unknown, message?: string): asserts condition;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines if a URL is internal or external.
|
|
3
|
-
*
|
|
4
|
-
* @param url - The URL to check if internal or external.
|
|
5
|
-
*
|
|
6
|
-
* @returns `true` if `url` is internal, `false` otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export declare const isInternalURL: (url: string) => boolean;
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a URL is internal or external.
|
|
3
|
+
*
|
|
4
|
+
* @param url - The URL to check if internal or external.
|
|
5
|
+
*
|
|
6
|
+
* @returns `true` if `url` is internal, `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isInternalURL: (url: string) => boolean;
|
package/dist/lib/pascalCase.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
type WordSeparators = "-" | "_" | " ";
|
|
2
|
-
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : S extends Delimiter ? [] : [S];
|
|
3
|
-
type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] ? FirstPart extends undefined ? "" : FirstPart extends "" ? InnerCamelCaseStringArray<RemainingParts, PreviousPart> : `${PreviousPart extends "" ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}` : "";
|
|
4
|
-
type CamelCaseStringArray<Parts extends readonly string[]> = Parts extends [
|
|
5
|
-
`${infer FirstPart}`,
|
|
6
|
-
...infer RemainingParts
|
|
7
|
-
] ? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`> : never;
|
|
8
|
-
type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>> : K;
|
|
9
|
-
/**
|
|
10
|
-
* Converts a string literal to Pascal case.
|
|
11
|
-
*
|
|
12
|
-
* Taken from the `type-fest` package.
|
|
13
|
-
*
|
|
14
|
-
* See:
|
|
15
|
-
* https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/pascal-case.d.ts
|
|
16
|
-
*/
|
|
17
|
-
export type PascalCase<Value> = CamelCase<Value> extends string ? Capitalize<CamelCase<Value>> : CamelCase<Value>;
|
|
18
|
-
/**
|
|
19
|
-
* Converts a string to Pascal case.
|
|
20
|
-
*
|
|
21
|
-
* @param input - The string to convert.
|
|
22
|
-
*
|
|
23
|
-
* @returns `input` as Pascal case.
|
|
24
|
-
*/
|
|
25
|
-
export declare const pascalCase: <Input extends string>(input: Input) => PascalCase<Input>;
|
|
26
|
-
export {};
|
|
1
|
+
type WordSeparators = "-" | "_" | " ";
|
|
2
|
+
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : S extends Delimiter ? [] : [S];
|
|
3
|
+
type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] ? FirstPart extends undefined ? "" : FirstPart extends "" ? InnerCamelCaseStringArray<RemainingParts, PreviousPart> : `${PreviousPart extends "" ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}` : "";
|
|
4
|
+
type CamelCaseStringArray<Parts extends readonly string[]> = Parts extends [
|
|
5
|
+
`${infer FirstPart}`,
|
|
6
|
+
...infer RemainingParts
|
|
7
|
+
] ? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`> : never;
|
|
8
|
+
type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>> : K;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a string literal to Pascal case.
|
|
11
|
+
*
|
|
12
|
+
* Taken from the `type-fest` package.
|
|
13
|
+
*
|
|
14
|
+
* See:
|
|
15
|
+
* https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/pascal-case.d.ts
|
|
16
|
+
*/
|
|
17
|
+
export type PascalCase<Value> = CamelCase<Value> extends string ? Capitalize<CamelCase<Value>> : CamelCase<Value>;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a string to Pascal case.
|
|
20
|
+
*
|
|
21
|
+
* @param input - The string to convert.
|
|
22
|
+
*
|
|
23
|
+
* @returns `input` as Pascal case.
|
|
24
|
+
*/
|
|
25
|
+
export declare const pascalCase: <Input extends string>(input: Input) => PascalCase<Input>;
|
|
26
|
+
export {};
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const prismic = require("@prismicio/client");
|
|
6
|
+
const __PRODUCTION__ = require("../lib/__PRODUCTION__.cjs");
|
|
7
|
+
const devMsg = require("../lib/devMsg.cjs");
|
|
8
|
+
const isInternalURL = require("../lib/isInternalURL.cjs");
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== "default") {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
26
|
+
const defaultComponent = "a";
|
|
27
|
+
const PrismicLink = React__namespace.forwardRef(function PrismicLink2({ field, document: doc, linkResolver, internalComponent, externalComponent, ...restProps }, ref) {
|
|
28
|
+
if (!__PRODUCTION__.__PRODUCTION__) {
|
|
29
|
+
if (field) {
|
|
30
|
+
if (!field.link_type) {
|
|
31
|
+
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
32
|
+
`, field);
|
|
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)) {
|
|
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
|
+
}
|
|
37
|
+
} else if (doc) {
|
|
38
|
+
if (!("url" in doc || "id" in doc)) {
|
|
39
|
+
console.warn(`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg.devMsg("missing-link-properties")}`, doc);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const { href: computedHref, rel: computedRel, ...attrs } = prismic.asLinkAttrs(field ?? doc, {
|
|
44
|
+
linkResolver,
|
|
45
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : void 0
|
|
46
|
+
});
|
|
47
|
+
let rel = computedRel;
|
|
48
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
49
|
+
rel = restProps.rel;
|
|
50
|
+
}
|
|
51
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
52
|
+
const InternalComponent = internalComponent || defaultComponent;
|
|
53
|
+
const ExternalComponent = externalComponent || defaultComponent;
|
|
54
|
+
const Component = href && isInternalURL.isInternalURL(href) ? InternalComponent : ExternalComponent;
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, ...attrs, ...restProps, href, rel });
|
|
56
|
+
});
|
|
57
|
+
exports.PrismicLink = PrismicLink;
|
|
58
|
+
exports.defaultComponent = defaultComponent;
|
|
59
|
+
//# sourceMappingURL=PrismicLink.cjs.map
|
|
@@ -0,0 +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 { __PRODUCTION__ } from \"../lib/__PRODUCTION__\";\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<InternalComponentProps & ExternalComponentProps, \"rel\" | \"href\"> & {\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\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\t{\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\t...restProps\n\t}: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: React.ForwardedRef<Element>,\n): JSX.Element {\n\tif (!__PRODUCTION__) {\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\tObject.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);\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","__PRODUCTION__","devMsg","asLinkAttrs","isInternalURL","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,MAAM,mBAAmB;AAgFzB,MAAM,cAAcA,iBAAM,WAAW,SAASC,aAIpD,EACC,OACA,UAAU,KACV,cACA,mBACA,mBACA,GAAG,UAAA,GAEJ,KAAgC;AAEhC,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8IC,OAAA,OAC7I,yBAAyB,GACvB;AAAA,MAGJ,WAAA,OAAO,KAAK,KAAK,EAAE,SAAS,KAC5B,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,QAAAA,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;AAGlD,SAAAC,2BAAA,IAAC,aAAU,KAAc,GAAA,OAAO,GAAI,WAAW,MAAY,IAAS,CAAA;AAEtE,CAAC;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { LinkField, LinkResolverFunction, PrismicDocument, AsLinkAttrsConfig } from "@prismicio/client";
|
|
3
|
+
/**
|
|
4
|
+
* The default component rendered for internal and external links.
|
|
5
|
+
*/
|
|
6
|
+
export declare const defaultComponent = "a";
|
|
7
|
+
/**
|
|
8
|
+
* Props provided to a component when rendered with `<PrismicLink>`.
|
|
9
|
+
*/
|
|
10
|
+
export interface LinkProps {
|
|
11
|
+
/**
|
|
12
|
+
* The URL to link.
|
|
13
|
+
*/
|
|
14
|
+
href: string;
|
|
15
|
+
/**
|
|
16
|
+
* The `target` attribute for anchor elements. If the Prismic field is
|
|
17
|
+
* configured to open in a new window, this prop defaults to `_blank`.
|
|
18
|
+
*/
|
|
19
|
+
target?: React.HTMLAttributeAnchorTarget;
|
|
20
|
+
/**
|
|
21
|
+
* The `rel` attribute for anchor elements. If the `target` prop is set to
|
|
22
|
+
* `"_blank"`, this prop defaults to `"noopener noreferrer"`.
|
|
23
|
+
*/
|
|
24
|
+
rel?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Children for the component. *
|
|
27
|
+
*/
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export type PrismicLinkProps<InternalComponentProps = React.ComponentProps<typeof defaultComponent>, ExternalComponentProps = React.ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href"> & {
|
|
31
|
+
/**
|
|
32
|
+
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if
|
|
33
|
+
* the link's URL is external. This prop can be provided a function to use the
|
|
34
|
+
* link's metadata to determine the `rel` value.
|
|
35
|
+
*/
|
|
36
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
37
|
+
/**
|
|
38
|
+
* The Link Resolver used to resolve links.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* If your app uses Route Resolvers when querying for your Prismic
|
|
42
|
+
* repository's content, a Link Resolver does not need to be provided.
|
|
43
|
+
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
44
|
+
*/
|
|
45
|
+
linkResolver?: LinkResolverFunction;
|
|
46
|
+
/**
|
|
47
|
+
* The component rendered for internal URLs. Defaults to `<a>`.
|
|
48
|
+
*
|
|
49
|
+
* If your app uses a client-side router that requires a special Link
|
|
50
|
+
* component, provide the Link component to this prop.
|
|
51
|
+
*/
|
|
52
|
+
internalComponent?: React.ElementType<InternalComponentProps>;
|
|
53
|
+
/**
|
|
54
|
+
* The component rendered for external URLs. Defaults to `<a>`.
|
|
55
|
+
*/
|
|
56
|
+
externalComponent?: React.ComponentType<ExternalComponentProps>;
|
|
57
|
+
} & ({
|
|
58
|
+
document: PrismicDocument | null | undefined;
|
|
59
|
+
href?: never;
|
|
60
|
+
field?: never;
|
|
61
|
+
} | {
|
|
62
|
+
field: LinkField | null | undefined;
|
|
63
|
+
href?: never;
|
|
64
|
+
document?: never;
|
|
65
|
+
} | {
|
|
66
|
+
href: LinkProps["href"];
|
|
67
|
+
field?: LinkField | null | undefined;
|
|
68
|
+
document?: never;
|
|
69
|
+
});
|
|
70
|
+
export declare const PrismicLink: <InternalComponentProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, ExternalComponentProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
|
|
71
|
+
ref?: React.ForwardedRef<Element> | undefined;
|
|
72
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { asLinkAttrs } from "@prismicio/client";
|
|
4
|
+
import { __PRODUCTION__ } from "../lib/__PRODUCTION__.js";
|
|
5
|
+
import { devMsg } from "../lib/devMsg.js";
|
|
6
|
+
import { isInternalURL } from "../lib/isInternalURL.js";
|
|
7
|
+
const defaultComponent = "a";
|
|
8
|
+
const PrismicLink = React.forwardRef(function PrismicLink2({ field, document: doc, linkResolver, internalComponent, externalComponent, ...restProps }, ref) {
|
|
9
|
+
if (!__PRODUCTION__) {
|
|
10
|
+
if (field) {
|
|
11
|
+
if (!field.link_type) {
|
|
12
|
+
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
13
|
+
`, field);
|
|
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)) {
|
|
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
|
+
}
|
|
18
|
+
} else if (doc) {
|
|
19
|
+
if (!("url" in doc || "id" in doc)) {
|
|
20
|
+
console.warn(`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg("missing-link-properties")}`, doc);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const { href: computedHref, rel: computedRel, ...attrs } = asLinkAttrs(field ?? doc, {
|
|
25
|
+
linkResolver,
|
|
26
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : void 0
|
|
27
|
+
});
|
|
28
|
+
let rel = computedRel;
|
|
29
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
30
|
+
rel = restProps.rel;
|
|
31
|
+
}
|
|
32
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
33
|
+
const InternalComponent = internalComponent || defaultComponent;
|
|
34
|
+
const ExternalComponent = externalComponent || defaultComponent;
|
|
35
|
+
const Component = href && isInternalURL(href) ? InternalComponent : ExternalComponent;
|
|
36
|
+
return /* @__PURE__ */ jsx(Component, { ref, ...attrs, ...restProps, href, rel });
|
|
37
|
+
});
|
|
38
|
+
export {
|
|
39
|
+
PrismicLink,
|
|
40
|
+
defaultComponent
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=PrismicLink.js.map
|
|
@@ -0,0 +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 { __PRODUCTION__ } from \"../lib/__PRODUCTION__\";\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<InternalComponentProps & ExternalComponentProps, \"rel\" | \"href\"> & {\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\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\t{\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\t...restProps\n\t}: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: React.ForwardedRef<Element>,\n): JSX.Element {\n\tif (!__PRODUCTION__) {\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\tObject.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);\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":";;;;;;AAgBO,MAAM,mBAAmB;AAgFzB,MAAM,cAAc,MAAM,WAAW,SAASA,aAIpD,EACC,OACA,UAAU,KACV,cACA,mBACA,mBACA,GAAG,UAAA,GAEJ,KAAgC;AAEhC,MAAI,CAAC,gBAAgB;AACpB,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8I,OAC7I,yBAAyB,GACvB;AAAA,MAGJ,WAAA,OAAO,KAAK,KAAK,EAAE,SAAS,KAC5B,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;AAGlD,SAAA,oBAAC,aAAU,KAAc,GAAA,OAAO,GAAI,WAAW,MAAY,IAAS,CAAA;AAEtE,CAAC;"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const prismic = require("@prismicio/client");
|
|
6
|
+
const prismicR = require("@prismicio/richtext");
|
|
7
|
+
const PrismicLink = require("./PrismicLink.cjs");
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
25
|
+
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
|
|
26
|
+
const prismicR__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicR);
|
|
27
|
+
const createDefaultSerializer = (args) => prismicR__namespace.wrapMapSerializer({
|
|
28
|
+
heading1: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("h1", { children }, key),
|
|
29
|
+
heading2: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("h2", { children }, key),
|
|
30
|
+
heading3: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("h3", { children }, key),
|
|
31
|
+
heading4: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("h4", { children }, key),
|
|
32
|
+
heading5: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("h5", { children }, key),
|
|
33
|
+
heading6: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("h6", { children }, key),
|
|
34
|
+
paragraph: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("p", { children }, key),
|
|
35
|
+
preformatted: ({ node, key }) => /* @__PURE__ */ jsxRuntime.jsx("pre", { children: node.text }, key),
|
|
36
|
+
strong: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("strong", { children }, key),
|
|
37
|
+
em: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("em", { children }, key),
|
|
38
|
+
listItem: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("li", { children }, key),
|
|
39
|
+
oListItem: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("li", { children }, key),
|
|
40
|
+
list: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("ul", { children }, key),
|
|
41
|
+
oList: ({ children, key }) => /* @__PURE__ */ jsxRuntime.jsx("ol", { children }, key),
|
|
42
|
+
image: ({ node, key }) => {
|
|
43
|
+
const img = /* @__PURE__ */ jsxRuntime.jsx("img", { src: node.url, alt: node.alt ?? void 0, "data-copyright": node.copyright ? node.copyright : void 0 });
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "block-img", children: node.linkTo ? /* @__PURE__ */ jsxRuntime.jsx(PrismicLink.PrismicLink, { linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, field: node.linkTo, children: img }) : img }, key);
|
|
45
|
+
},
|
|
46
|
+
embed: ({ node, key }) => /* @__PURE__ */ jsxRuntime.jsx("div", { "data-oembed": node.oembed.embed_url, "data-oembed-type": node.oembed.type, "data-oembed-provider": node.oembed.provider_name, dangerouslySetInnerHTML: { __html: node.oembed.html ?? "" } }, key),
|
|
47
|
+
hyperlink: ({ node, children, key }) => /* @__PURE__ */ jsxRuntime.jsx(PrismicLink.PrismicLink, { field: node.data, linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, children }, key),
|
|
48
|
+
label: ({ node, children, key }) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: node.data.label, children }, key),
|
|
49
|
+
span: ({ text, key }) => {
|
|
50
|
+
const result = [];
|
|
51
|
+
let i = 0;
|
|
52
|
+
for (const line of text.split("\n")) {
|
|
53
|
+
if (i > 0) {
|
|
54
|
+
result.push(/* @__PURE__ */ jsxRuntime.jsx("br", {}, `${i}__break`));
|
|
55
|
+
}
|
|
56
|
+
result.push(/* @__PURE__ */ jsxRuntime.jsx(React__namespace.Fragment, { children: line }, `${i}__line`));
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React__namespace.Fragment, { children: result }, key);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
function PrismicRichText({ linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent }) {
|
|
63
|
+
return React__namespace.useMemo(() => {
|
|
64
|
+
if (prismic__namespace.isFilled.richText(field)) {
|
|
65
|
+
const serializer = prismicR__namespace.composeSerializers(typeof components === "object" ? prismicR__namespace.wrapMapSerializer(components) : components, createDefaultSerializer({
|
|
66
|
+
linkResolver,
|
|
67
|
+
internalLinkComponent,
|
|
68
|
+
externalLinkComponent
|
|
69
|
+
}));
|
|
70
|
+
const serialized = prismicR__namespace.serialize(field, (type, node, text, children, key) => {
|
|
71
|
+
const result = serializer(type, node, text, children, key);
|
|
72
|
+
if (React__namespace.isValidElement(result) && result.key == null) {
|
|
73
|
+
return React__namespace.cloneElement(result, { key });
|
|
74
|
+
} else {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: serialized });
|
|
79
|
+
} else {
|
|
80
|
+
return fallback != null ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
81
|
+
}
|
|
82
|
+
}, [
|
|
83
|
+
field,
|
|
84
|
+
internalLinkComponent,
|
|
85
|
+
externalLinkComponent,
|
|
86
|
+
components,
|
|
87
|
+
linkResolver,
|
|
88
|
+
fallback
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
exports.PrismicRichText = PrismicRichText;
|
|
92
|
+
//# sourceMappingURL=PrismicRichText.cjs.map
|