@pack/react 0.0.14-canary.0 → 0.0.14

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.
@@ -1,4 +1,4 @@
1
- import React, { ReactNode } from 'react';
1
+ import React, { ReactNode } from "react";
2
2
  interface PreviewContentProps {
3
3
  children: ReactNode;
4
4
  siteSettings: any;
@@ -1 +1 @@
1
- {"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,SAAS,EAAW,MAAM,OAAO,CAAC;AAGjD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAAoB,EACpB,YAAY,GACb,EAAE,mBAAmB,qBAgBrB"}
1
+ {"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAInD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAAoB,EACpB,YAAY,GACb,EAAE,mBAAmB,qBAkBrB"}
@@ -1,5 +1,6 @@
1
- import React, { useState } from 'react';
2
- import { PreviewContext } from './preview-content';
1
+ import React, { useState } from "react";
2
+ import { PreviewContext } from "./preview-content";
3
+ import { PreviewToast } from "./preview-toast";
3
4
  export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, }) {
4
5
  const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
5
6
  return (React.createElement(PreviewContext.Provider, { value: {
@@ -7,5 +8,7 @@ export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings,
7
8
  previewStorefrontSettings,
8
9
  setPreviewStorefrontSettings,
9
10
  siteSettings,
10
- } }, children));
11
+ } },
12
+ children,
13
+ React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
11
14
  }
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ interface PreviewToastProps {
3
+ isPreviewModeEnabled: boolean;
4
+ }
5
+ export declare const PreviewToast: ({ isPreviewModeEnabled }: PreviewToastProps) => React.JSX.Element | null;
6
+ export {};
7
+ //# sourceMappingURL=preview-toast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-toast.d.ts","sourceRoot":"","sources":["../../src/preview/preview-toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,UAAU,iBAAiB;IACzB,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAsBD,eAAO,MAAM,YAAY,6BAA8B,iBAAiB,6BA+GvE,CAAC"}
@@ -0,0 +1,85 @@
1
+ import React, { useEffect, useState } from "react";
2
+ const Eye = (props) => {
3
+ return (React.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props },
4
+ React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M2.75 12c0-.338.136-.905.493-1.591a7.858 7.858 0 0 1 1.64-2.108C6.374 6.926 8.694 5.75 12 5.75c3.308 0 5.627 1.176 7.116 2.551a7.86 7.86 0 0 1 1.64 2.108c.358.686.494 1.253.494 1.591 0 .338-.136.905-.493 1.591a7.86 7.86 0 0 1-1.64 2.108c-1.49 1.375-3.81 2.551-7.117 2.551-3.308 0-5.627-1.176-7.116-2.551a7.858 7.858 0 0 1-1.64-2.108c-.358-.686-.494-1.253-.494-1.591ZM12 4.25c-3.692 0-6.373 1.324-8.134 2.949a9.356 9.356 0 0 0-1.953 2.517c-.424.814-.663 1.622-.663 2.284 0 .662.24 1.47.663 2.284a9.356 9.356 0 0 0 1.953 2.517C5.627 18.426 8.308 19.75 12 19.75s6.373-1.324 8.134-2.949a9.356 9.356 0 0 0 1.953-2.517c.424-.814.663-1.622.663-2.284 0-.662-.24-1.47-.663-2.284a9.355 9.355 0 0 0-1.953-2.517C18.373 5.574 15.692 4.25 12 4.25ZM9.75 12a2.25 2.25 0 1 1 4.5 0 2.25 2.25 0 0 1-4.5 0ZM12 8.25a3.75 3.75 0 1 0 0 7.5 3.75 3.75 0 0 0 0-7.5Z", fill: "currentColor" })));
5
+ };
6
+ export const PreviewToast = ({ isPreviewModeEnabled }) => {
7
+ const [showToast, setShowToast] = useState(false);
8
+ const exitPreviewMode = async () => {
9
+ try {
10
+ const response = await fetch("/api/edit", {
11
+ method: "POST",
12
+ headers: {
13
+ "Content-Type": "application/x-www-form-urlencoded",
14
+ },
15
+ });
16
+ if (!response.ok) {
17
+ throw new Error(`HTTP error! Status: ${response.status}`);
18
+ }
19
+ window.location.reload();
20
+ }
21
+ catch (error) {
22
+ console.error("Error exiting preview:", error.message);
23
+ }
24
+ };
25
+ useEffect(() => {
26
+ const isIframe = window.self !== window.top;
27
+ if (isPreviewModeEnabled && !isIframe) {
28
+ setShowToast(true);
29
+ }
30
+ }, [isPreviewModeEnabled]);
31
+ if (showToast) {
32
+ return (React.createElement("div", { style: {
33
+ position: "fixed",
34
+ zIndex: "2147483647",
35
+ left: "50%",
36
+ transform: "translateX(-50%)",
37
+ padding: "0 16px",
38
+ bottom: "16px",
39
+ width: "100%",
40
+ pointerEvents: "none",
41
+ } },
42
+ React.createElement("div", { style: {
43
+ margin: "0 auto",
44
+ pointerEvents: "auto",
45
+ maxWidth: "640px",
46
+ boxShadow: "0px 2px 10px 0px rgba(0, 0, 0, 0.10), 0px 0px 2px 0px rgba(0, 0, 0, 0.10)",
47
+ width: "100%",
48
+ padding: "8px 16px",
49
+ backgroundColor: "#1f2937",
50
+ color: "#f9fafb",
51
+ borderRadius: "8px",
52
+ display: "flex",
53
+ alignItems: "center",
54
+ fontFamily: '"Inter", sans-serif',
55
+ justifyContent: "space-between",
56
+ gap: "8px",
57
+ } },
58
+ React.createElement("div", { style: {
59
+ display: "flex",
60
+ alignItems: "center",
61
+ gap: "8px",
62
+ overflow: "hidden",
63
+ } },
64
+ React.createElement(Eye, { style: { width: 16, height: 16, minWidth: 16 } }),
65
+ React.createElement("p", { style: {
66
+ flex: 1,
67
+ fontSize: "14px",
68
+ lineHeight: "20px",
69
+ whiteSpace: "nowrap",
70
+ textOverflow: "ellipsis",
71
+ overflow: "hidden",
72
+ } }, "You are currently previewing your storefront with draft content")),
73
+ React.createElement("span", { role: "button", tabIndex: 0, onClick: exitPreviewMode, onKeyDown: (e) => {
74
+ if (e.key === "Enter" || e.key === " ") {
75
+ exitPreviewMode();
76
+ }
77
+ }, style: {
78
+ cursor: "pointer",
79
+ fontSize: 13,
80
+ fontWeight: "500",
81
+ flexShrink: "0",
82
+ } }, "Exit preview mode"))));
83
+ }
84
+ return null;
85
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAyClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAiC9C"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAwClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BA8B9C"}
@@ -5,7 +5,6 @@ import { sectionMap } from "./register-section";
5
5
  import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
6
6
  function Sections({ sections }) {
7
7
  const renderedSections = useMemo(() => {
8
- console.log('sections', sections);
9
8
  return sections
10
9
  .map((section) => {
11
10
  // TODO: Return a consistent data structure from the API and the customizer
@@ -27,7 +26,6 @@ function Sections({ sections }) {
27
26
  }
28
27
  export function RenderSections({ content }) {
29
28
  const { isPreview, setPreviewStorefrontSettings } = usePreviewContext();
30
- console.log('test 123');
31
29
  const { content: liveContent, storefrontSettings } = useCustomizerShell({
32
30
  environment: "production",
33
31
  isPreview,
@@ -47,7 +45,6 @@ export function RenderSections({ content }) {
47
45
  setPreviewStorefrontSettings({ settings: storefrontSettings });
48
46
  }, [setPreviewStorefrontSettings, storefrontSettings]);
49
47
  const sections = useMemo(() => {
50
- console.log('live content', liveContent?.sections?.nodes || liveContent?.sections);
51
48
  return liveContent?.sections?.nodes || liveContent?.sections;
52
49
  }, [liveContent?.sections]);
53
50
  if (!sections)
@@ -1 +1 @@
1
- {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAkIL,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAsIL,CAAC"}
@@ -11,7 +11,11 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
11
11
  };
12
12
  useEffect(() => {
13
13
  const isIframe = window.self !== window.top;
14
- if (!isIframe)
14
+ /*
15
+ * Should not try to connect to customizer
16
+ * if not in an iframe or not in preview mode
17
+ */
18
+ if (!isIframe || !isPreview)
15
19
  return;
16
20
  setShouldConnectToParent(true);
17
21
  }, []);
@@ -93,7 +97,6 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
93
97
  useEffect(() => {
94
98
  if (!isPreview)
95
99
  return;
96
- console.log('refreshing sections');
97
100
  refreshSections();
98
101
  refreshStorefrontSettingsSchema();
99
102
  }, [
@@ -1 +1 @@
1
- {"version":3,"file":"use-site-settings.d.ts","sourceRoot":"","sources":["../src/use-site-settings.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,QAAO,OAAO,MAAM,EAAE,GAAG,CAOpD,CAAC"}
1
+ {"version":3,"file":"use-site-settings.d.ts","sourceRoot":"","sources":["../src/use-site-settings.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,QAAO,OAAO,MAAM,EAAE,GAAG,CAkBpD,CAAC"}
@@ -1,7 +1,16 @@
1
- import { usePreviewContext } from './preview/preview-content';
1
+ import { usePreviewContext } from "./preview/preview-content";
2
2
  export const useSiteSettings = () => {
3
3
  const { isPreview, previewStorefrontSettings, siteSettings } = usePreviewContext();
4
- return isPreview
4
+ let isIframe = false;
5
+ if (!(typeof document === "undefined")) {
6
+ isIframe = window.self !== window.top;
7
+ }
8
+ /*
9
+ * If the storefront both in preview mode and
10
+ * in an iFrame we want to show the live customizer
11
+ * preview data. Else, we show the normal site settings data
12
+ * */
13
+ return isPreview && isIframe
5
14
  ? previewStorefrontSettings
6
15
  : siteSettings?.data?.siteSettings;
7
16
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.0.14-canary.0",
4
+ "version": "0.0.14",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {