@prismicio/next 0.2.0-alpha.0 → 0.2.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.
Files changed (82) hide show
  1. package/README.md +3 -1
  2. package/dist/PrismicNextImage.cjs +86 -0
  3. package/dist/PrismicNextImage.cjs.map +1 -0
  4. package/dist/PrismicNextImage.d.ts +52 -0
  5. package/dist/PrismicNextImage.js +69 -0
  6. package/dist/PrismicNextImage.js.map +1 -0
  7. package/dist/PrismicPreview.cjs +83 -0
  8. package/dist/PrismicPreview.cjs.map +1 -0
  9. package/dist/PrismicPreview.d.ts +42 -0
  10. package/dist/PrismicPreview.js +66 -0
  11. package/dist/PrismicPreview.js.map +1 -0
  12. package/dist/enableAutoPreviews.cjs +17 -0
  13. package/dist/enableAutoPreviews.cjs.map +1 -0
  14. package/dist/enableAutoPreviews.d.ts +38 -0
  15. package/dist/enableAutoPreviews.js +17 -0
  16. package/dist/enableAutoPreviews.js.map +1 -0
  17. package/dist/exitPreview.cjs +8 -0
  18. package/dist/exitPreview.cjs.map +1 -0
  19. package/dist/exitPreview.d.ts +30 -0
  20. package/dist/exitPreview.js +8 -0
  21. package/dist/exitPreview.js.map +1 -0
  22. package/dist/imgixLoader.cjs +17 -0
  23. package/dist/imgixLoader.cjs.map +1 -0
  24. package/dist/imgixLoader.d.ts +9 -0
  25. package/dist/imgixLoader.js +17 -0
  26. package/dist/imgixLoader.js.map +1 -0
  27. package/dist/index.cjs +17 -182
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.ts +8 -204
  30. package/dist/index.js +17 -153
  31. package/dist/index.js.map +1 -0
  32. package/dist/lib/__PRODUCTION__.cjs +5 -0
  33. package/dist/lib/__PRODUCTION__.cjs.map +1 -0
  34. package/dist/lib/__PRODUCTION__.d.ts +7 -0
  35. package/dist/lib/__PRODUCTION__.js +5 -0
  36. package/dist/lib/__PRODUCTION__.js.map +1 -0
  37. package/dist/lib/devMsg.cjs +8 -0
  38. package/dist/lib/devMsg.cjs.map +1 -0
  39. package/dist/lib/devMsg.d.ts +16 -0
  40. package/dist/lib/devMsg.js +8 -0
  41. package/dist/lib/devMsg.js.map +1 -0
  42. package/dist/lib/getPreviewCookieRepositoryName.cjs +7 -0
  43. package/dist/lib/getPreviewCookieRepositoryName.cjs.map +1 -0
  44. package/dist/lib/getPreviewCookieRepositoryName.d.ts +9 -0
  45. package/dist/lib/getPreviewCookieRepositoryName.js +7 -0
  46. package/dist/lib/getPreviewCookieRepositoryName.js.map +1 -0
  47. package/dist/lib/getPrismicPreviewCookie.cjs +38 -0
  48. package/dist/lib/getPrismicPreviewCookie.cjs.map +1 -0
  49. package/dist/lib/getPrismicPreviewCookie.d.ts +9 -0
  50. package/dist/lib/getPrismicPreviewCookie.js +21 -0
  51. package/dist/lib/getPrismicPreviewCookie.js.map +1 -0
  52. package/dist/package.json.cjs +5 -0
  53. package/dist/package.json.cjs.map +1 -0
  54. package/dist/package.json.js +5 -0
  55. package/dist/package.json.js.map +1 -0
  56. package/dist/redirectToPreviewURL.cjs +22 -0
  57. package/dist/redirectToPreviewURL.cjs.map +1 -0
  58. package/dist/redirectToPreviewURL.d.ts +59 -0
  59. package/dist/redirectToPreviewURL.js +22 -0
  60. package/dist/redirectToPreviewURL.js.map +1 -0
  61. package/dist/setPreviewData.cjs +28 -0
  62. package/dist/setPreviewData.cjs.map +1 -0
  63. package/dist/setPreviewData.d.ts +29 -0
  64. package/dist/setPreviewData.js +11 -0
  65. package/dist/setPreviewData.js.map +1 -0
  66. package/dist/types.d.ts +21 -0
  67. package/package.json +40 -35
  68. package/src/PrismicNextImage.tsx +141 -0
  69. package/src/PrismicPreview.tsx +80 -93
  70. package/src/enableAutoPreviews.ts +4 -2
  71. package/src/exitPreview.ts +15 -7
  72. package/src/imgixLoader.ts +25 -0
  73. package/src/index.ts +16 -11
  74. package/src/lib/__PRODUCTION__.ts +7 -0
  75. package/src/lib/devMsg.ts +20 -0
  76. package/src/lib/getPreviewCookieRepositoryName.ts +14 -0
  77. package/src/lib/getPrismicPreviewCookie.ts +33 -0
  78. package/src/redirectToPreviewURL.ts +11 -6
  79. package/src/setPreviewData.ts +7 -2
  80. package/src/types.ts +3 -2
  81. package/src/lib/extractPreviewRefRepositoryName.ts +0 -60
  82. package/src/lib/getCookie.ts +0 -51
@@ -1,60 +0,0 @@
1
- /**
2
- * Returns the repository name from an object-style Prismic ref.
3
- *
4
- * @param host - Host string
5
- */
6
- const extractFirstSubdomain = (host: string): string => host.split(".")[0];
7
-
8
- /**
9
- * Parses ref object from cookie and returns proper preview link
10
- *
11
- * @param previewRef - Prismic Preview reference
12
- */
13
- const extractRepositoryNameFromObjectRef = (
14
- previewRef: string,
15
- ): string | undefined => {
16
- try {
17
- const parsed = JSON.parse(decodeURIComponent(previewRef));
18
- const keys = Object.keys(parsed);
19
- const domainKey = keys.find((key) => /\.prismic\.io$/.test(key));
20
-
21
- if (domainKey) {
22
- return extractFirstSubdomain(domainKey);
23
- } else {
24
- return undefined;
25
- }
26
- } catch {
27
- return undefined;
28
- }
29
- };
30
-
31
- /**
32
- * Returns the repository name from a URL-style Prismic ref.
33
- *
34
- * @param previewRef - Preview ref from getCookie()
35
- */
36
- const extractRepositoryNameFromURLRef = (
37
- previewRef: string,
38
- ): string | undefined => {
39
- try {
40
- const url = new URL(previewRef);
41
-
42
- return extractFirstSubdomain(url.host);
43
- } catch {
44
- return undefined;
45
- }
46
- };
47
-
48
- /**
49
- * Extracts preview reference repo name from stringified Prismic preview cookie
50
- *
51
- * @param previewRef - Preview Reference
52
- */
53
- export const extractPreviewRefRepositoryName = (
54
- previewRef: string,
55
- ): string | undefined => {
56
- return (
57
- extractRepositoryNameFromObjectRef(previewRef) ||
58
- extractRepositoryNameFromURLRef(previewRef)
59
- );
60
- };
@@ -1,51 +0,0 @@
1
- /**
2
- * The following code is a modifed version of `es-cookie` taken from
3
- * https://github.com/theodorejb/es-cookie
4
- *
5
- * It only contains a simplified version of `get()`.
6
- *
7
- * Copyright 2017 Theodore Brown
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy
10
- * of this software and associated documentation files (the "Software"), to deal
11
- * in the Software without restriction, including without limitation the rights
12
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- * copies of the Software, and to permit persons to whom the Software is
14
- * furnished to do so, subject to the following conditions:
15
- *
16
- * The above copyright notice and this permission notice shall be included in
17
- * all copies or substantial portions of the Software.
18
- *
19
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- * SOFTWARE.*
26
- */
27
-
28
- const readValue = (value: string): string => {
29
- return value.replace(/%3B/g, ";");
30
- };
31
-
32
- /**
33
- * Returns the value of a cookie from a given cookie store.
34
- *
35
- * @param name - Of the cookie.
36
- *
37
- * @returns The value of the cookie, if it exists.
38
- */
39
- export const getCookie = (name: string): string | undefined => {
40
- const cookies = document.cookie.split("; ");
41
-
42
- for (const cookie of cookies) {
43
- const parts = cookie.split("=");
44
- const value = parts.slice(1).join("=");
45
- const thisName = readValue(parts[0]).replace(/%3D/g, "=");
46
-
47
- if (thisName === name) {
48
- return readValue(value);
49
- }
50
- }
51
- };