@prismicio/react 2.6.0 → 2.6.2

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.
Files changed (77) hide show
  1. package/dist/PrismicImage.cjs +1 -2
  2. package/dist/PrismicImage.cjs.map +1 -1
  3. package/dist/PrismicImage.js +1 -2
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicText.cjs +4 -2
  6. package/dist/PrismicText.cjs.map +1 -1
  7. package/dist/PrismicText.js +4 -2
  8. package/dist/PrismicText.js.map +1 -1
  9. package/dist/PrismicToolbar.cjs +1 -1
  10. package/dist/PrismicToolbar.cjs.map +1 -1
  11. package/dist/PrismicToolbar.js +1 -1
  12. package/dist/PrismicToolbar.js.map +1 -1
  13. package/dist/SliceZone.cjs +26 -12
  14. package/dist/SliceZone.cjs.map +1 -1
  15. package/dist/SliceZone.d.ts +62 -1
  16. package/dist/SliceZone.js +26 -12
  17. package/dist/SliceZone.js.map +1 -1
  18. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +2 -2
  19. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  20. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +2 -2
  21. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  22. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +2 -2
  23. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  24. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +2 -2
  25. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  26. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +12 -3
  27. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -1
  28. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +12 -3
  29. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -1
  30. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +11 -2
  31. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +1 -1
  32. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +11 -2
  33. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +1 -1
  34. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +1 -1
  35. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +1 -1
  36. package/dist/clientHooks.d.ts +18 -90
  37. package/dist/index.d.ts +1 -1
  38. package/dist/lib/pascalCase.cjs +10 -0
  39. package/dist/lib/pascalCase.cjs.map +1 -0
  40. package/dist/lib/pascalCase.js +10 -0
  41. package/dist/lib/pascalCase.js.map +1 -0
  42. package/dist/package.json.cjs +1 -1
  43. package/dist/package.json.js +1 -1
  44. package/dist/react-server/PrismicLink.cjs +1 -2
  45. package/dist/react-server/PrismicLink.cjs.map +1 -1
  46. package/dist/react-server/PrismicLink.js +1 -2
  47. package/dist/react-server/PrismicLink.js.map +1 -1
  48. package/dist/react-server/PrismicRichText.cjs +7 -1
  49. package/dist/react-server/PrismicRichText.cjs.map +1 -1
  50. package/dist/react-server/PrismicRichText.d.ts +1 -1
  51. package/dist/react-server/PrismicRichText.js +7 -1
  52. package/dist/react-server/PrismicRichText.js.map +1 -1
  53. package/dist/usePrismicClient.cjs +3 -2
  54. package/dist/usePrismicClient.cjs.map +1 -1
  55. package/dist/usePrismicClient.js +3 -2
  56. package/dist/usePrismicClient.js.map +1 -1
  57. package/package.json +19 -7
  58. package/src/PrismicImage.tsx +4 -2
  59. package/src/PrismicText.tsx +13 -2
  60. package/src/PrismicToolbar.tsx +1 -1
  61. package/src/SliceZone.tsx +141 -18
  62. package/src/index.ts +3 -2
  63. package/src/react-server/PrismicLink.tsx +4 -2
  64. package/src/react-server/PrismicRichText.tsx +16 -0
  65. package/src/usePrismicClient.ts +6 -6
  66. package/dist/lib/__PRODUCTION__.cjs +0 -8
  67. package/dist/lib/__PRODUCTION__.cjs.map +0 -1
  68. package/dist/lib/__PRODUCTION__.d.ts +0 -7
  69. package/dist/lib/__PRODUCTION__.js +0 -8
  70. package/dist/lib/__PRODUCTION__.js.map +0 -1
  71. package/dist/lib/invariant.cjs +0 -15
  72. package/dist/lib/invariant.cjs.map +0 -1
  73. package/dist/lib/invariant.d.ts +0 -24
  74. package/dist/lib/invariant.js +0 -15
  75. package/dist/lib/invariant.js.map +0 -1
  76. package/src/lib/__PRODUCTION__.ts +0 -12
  77. package/src/lib/invariant.ts +0 -49
@@ -7,7 +7,6 @@ import {
7
7
  AsLinkAttrsConfig,
8
8
  } from "@prismicio/client";
9
9
 
10
- import { __PRODUCTION__ } from "../lib/__PRODUCTION__";
11
10
  import { devMsg } from "../lib/devMsg";
12
11
  import { isInternalURL } from "../lib/isInternalURL";
13
12
 
@@ -108,7 +107,10 @@ export const PrismicLink = React.forwardRef(function PrismicLink<
108
107
  }: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,
109
108
  ref: React.ForwardedRef<Element>,
110
109
  ): JSX.Element {
111
- if (!__PRODUCTION__) {
110
+ if (
111
+ typeof process !== "undefined" &&
112
+ process.env.NODE_ENV === "development"
113
+ ) {
112
114
  if (field) {
113
115
  if (!field.link_type) {
114
116
  console.error(
@@ -4,6 +4,7 @@ import * as prismicR from "@prismicio/richtext";
4
4
 
5
5
  import { JSXFunctionSerializer, JSXMapSerializer } from "../types";
6
6
  import { LinkProps, PrismicLink } from "./PrismicLink";
7
+ import { devMsg } from "../lib/devMsg";
7
8
 
8
9
  /**
9
10
  * Props for `<PrismicRichText>`.
@@ -222,8 +223,23 @@ export function PrismicRichText<
222
223
  components,
223
224
  externalLinkComponent,
224
225
  internalLinkComponent,
226
+ ...restProps
225
227
  }: PrismicRichTextProps<LinkResolverFunction>): JSX.Element | null {
226
228
  return React.useMemo(() => {
229
+ if (
230
+ typeof process !== "undefined" &&
231
+ process.env.NODE_ENV === "development"
232
+ ) {
233
+ if ("className" in restProps) {
234
+ console.warn(
235
+ `[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(
236
+ "classname-is-not-a-valid-prop",
237
+ )}.`,
238
+ field,
239
+ );
240
+ }
241
+ }
242
+
227
243
  if (prismic.isFilled.richText(field)) {
228
244
  const serializer = prismicR.composeSerializers(
229
245
  typeof components === "object"
@@ -1,7 +1,5 @@
1
1
  import type * as prismic from "@prismicio/client";
2
2
 
3
- import { invariant } from "./lib/invariant";
4
-
5
3
  import { usePrismicContext } from "./usePrismicContext";
6
4
 
7
5
  /**
@@ -19,10 +17,12 @@ export const usePrismicClient = (
19
17
  const context = usePrismicContext();
20
18
 
21
19
  const client = explicitClient || context?.client;
22
- invariant(
23
- client,
24
- "A @prismicio/client is required to query documents. Provide a client to the hook or to a <PrismicProvider> higher in your component tree.",
25
- );
20
+
21
+ if (!client) {
22
+ throw new Error(
23
+ "A @prismicio/client is required to query documents. Provide a client to the hook or to a <PrismicProvider> higher in your component tree.",
24
+ );
25
+ }
26
26
 
27
27
  return client;
28
28
  };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- if (typeof process === "undefined") {
4
- globalThis.process = { env: {} };
5
- }
6
- const __PRODUCTION__ = process.env.NODE_ENV === "production";
7
- exports.__PRODUCTION__ = __PRODUCTION__;
8
- //# sourceMappingURL=__PRODUCTION__.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"__PRODUCTION__.cjs","sources":["../../../src/lib/__PRODUCTION__.ts"],"sourcesContent":["// We need to polyfill process if it doesn't exist, such as in the browser.\nif (typeof process === \"undefined\") {\n\tglobalThis.process = { env: {} } as typeof process;\n}\n\n/**\n * `true` if in the production environment, `false` otherwise.\n *\n * This boolean can be used to perform actions only in development environments,\n * such as logging.\n */\nexport const __PRODUCTION__ = process.env.NODE_ENV === \"production\";\n"],"names":[],"mappings":";;AACA,IAAI,OAAO,YAAY,aAAa;AACnC,aAAW,UAAU,EAAE,KAAK;AAC5B;AAQY,MAAA,iBAAiB,QAAQ,IAAI,aAAa;;"}
@@ -1,7 +0,0 @@
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,8 +0,0 @@
1
- if (typeof process === "undefined") {
2
- globalThis.process = { env: {} };
3
- }
4
- const __PRODUCTION__ = process.env.NODE_ENV === "production";
5
- export {
6
- __PRODUCTION__
7
- };
8
- //# sourceMappingURL=__PRODUCTION__.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"__PRODUCTION__.js","sources":["../../../src/lib/__PRODUCTION__.ts"],"sourcesContent":["// We need to polyfill process if it doesn't exist, such as in the browser.\nif (typeof process === \"undefined\") {\n\tglobalThis.process = { env: {} } as typeof process;\n}\n\n/**\n * `true` if in the production environment, `false` otherwise.\n *\n * This boolean can be used to perform actions only in development environments,\n * such as logging.\n */\nexport const __PRODUCTION__ = process.env.NODE_ENV === \"production\";\n"],"names":[],"mappings":"AACA,IAAI,OAAO,YAAY,aAAa;AACnC,aAAW,UAAU,EAAE,KAAK;AAC5B;AAQY,MAAA,iBAAiB,QAAQ,IAAI,aAAa;"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const __PRODUCTION__ = require("./__PRODUCTION__.cjs");
4
- const prefix = "Invariant failed";
5
- function invariant(condition, message) {
6
- if (condition) {
7
- return;
8
- }
9
- if (__PRODUCTION__.__PRODUCTION__) {
10
- throw new Error(prefix);
11
- }
12
- throw new Error(`${prefix}: ${message || ""}`);
13
- }
14
- exports.invariant = invariant;
15
- //# sourceMappingURL=invariant.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invariant.cjs","sources":["../../../src/lib/invariant.ts"],"sourcesContent":["/**\n * MIT License\n *\n * Copyright (c) 2019 Alexander Reardon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { __PRODUCTION__ } from \"./__PRODUCTION__\";\n\nconst prefix = \"Invariant failed\";\n\n// Throw an error if the condition fails\n// Strip out error messages for production\n// > Not providing an inline default argument for message as the result is smaller\nexport function invariant(\n\tcondition: unknown,\n\tmessage?: string,\n): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\t// Condition not passed\n\n\t// In production we strip the message but still throw\n\tif (__PRODUCTION__) {\n\t\tthrow new Error(prefix);\n\t}\n\n\t// When not in production we allow the message to pass through\n\t// *This block will be removed in production builds*\n\tthrow new Error(`${prefix}: ${message || \"\"}`);\n}\n"],"names":["__PRODUCTION__"],"mappings":";;;AA0BA,MAAM,SAAS;AAKC,SAAA,UACf,WACA,SAAgB;AAEhB,MAAI,WAAW;AACd;AAAA,EACA;AAID,MAAIA,+BAAgB;AACb,UAAA,IAAI,MAAM,MAAM;AAAA,EACtB;AAID,QAAM,IAAI,MAAM,GAAG,WAAW,WAAW,IAAI;AAC9C;;"}
@@ -1,24 +0,0 @@
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,15 +0,0 @@
1
- import { __PRODUCTION__ } from "./__PRODUCTION__.js";
2
- const prefix = "Invariant failed";
3
- function invariant(condition, message) {
4
- if (condition) {
5
- return;
6
- }
7
- if (__PRODUCTION__) {
8
- throw new Error(prefix);
9
- }
10
- throw new Error(`${prefix}: ${message || ""}`);
11
- }
12
- export {
13
- invariant
14
- };
15
- //# sourceMappingURL=invariant.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invariant.js","sources":["../../../src/lib/invariant.ts"],"sourcesContent":["/**\n * MIT License\n *\n * Copyright (c) 2019 Alexander Reardon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { __PRODUCTION__ } from \"./__PRODUCTION__\";\n\nconst prefix = \"Invariant failed\";\n\n// Throw an error if the condition fails\n// Strip out error messages for production\n// > Not providing an inline default argument for message as the result is smaller\nexport function invariant(\n\tcondition: unknown,\n\tmessage?: string,\n): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\t// Condition not passed\n\n\t// In production we strip the message but still throw\n\tif (__PRODUCTION__) {\n\t\tthrow new Error(prefix);\n\t}\n\n\t// When not in production we allow the message to pass through\n\t// *This block will be removed in production builds*\n\tthrow new Error(`${prefix}: ${message || \"\"}`);\n}\n"],"names":[],"mappings":";AA0BA,MAAM,SAAS;AAKC,SAAA,UACf,WACA,SAAgB;AAEhB,MAAI,WAAW;AACd;AAAA,EACA;AAID,MAAI,gBAAgB;AACb,UAAA,IAAI,MAAM,MAAM;AAAA,EACtB;AAID,QAAM,IAAI,MAAM,GAAG,WAAW,WAAW,IAAI;AAC9C;"}
@@ -1,12 +0,0 @@
1
- // We need to polyfill process if it doesn't exist, such as in the browser.
2
- if (typeof process === "undefined") {
3
- globalThis.process = { env: {} } as typeof process;
4
- }
5
-
6
- /**
7
- * `true` if in the production environment, `false` otherwise.
8
- *
9
- * This boolean can be used to perform actions only in development environments,
10
- * such as logging.
11
- */
12
- export const __PRODUCTION__ = process.env.NODE_ENV === "production";
@@ -1,49 +0,0 @@
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
-
25
- import { __PRODUCTION__ } from "./__PRODUCTION__";
26
-
27
- const prefix = "Invariant failed";
28
-
29
- // Throw an error if the condition fails
30
- // Strip out error messages for production
31
- // > Not providing an inline default argument for message as the result is smaller
32
- export function invariant(
33
- condition: unknown,
34
- message?: string,
35
- ): asserts condition {
36
- if (condition) {
37
- return;
38
- }
39
- // Condition not passed
40
-
41
- // In production we strip the message but still throw
42
- if (__PRODUCTION__) {
43
- throw new Error(prefix);
44
- }
45
-
46
- // When not in production we allow the message to pass through
47
- // *This block will be removed in production builds*
48
- throw new Error(`${prefix}: ${message || ""}`);
49
- }