@pack/react 0.0.14-canary.1 → 0.1.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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/preview/preview-content.d.ts +7 -0
- package/dist/preview/preview-content.d.ts.map +1 -1
- package/dist/preview/preview-content.js +2 -1
- package/dist/preview/preview-provider.d.ts +9 -2
- package/dist/preview/preview-provider.d.ts.map +1 -1
- package/dist/preview/preview-provider.js +8 -4
- package/dist/preview/preview-toast.d.ts +7 -0
- package/dist/preview/preview-toast.d.ts.map +1 -0
- package/dist/preview/preview-toast.js +85 -0
- package/dist/render-sections.d.ts.map +1 -1
- package/dist/render-sections.js +3 -4
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +5 -2
- package/dist/use-overlay-script.d.ts +15 -0
- package/dist/use-overlay-script.d.ts.map +1 -0
- package/dist/use-overlay-script.js +16 -0
- package/dist/use-site-settings.d.ts.map +1 -1
- package/dist/use-site-settings.js +11 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { RenderSections } from "./render-sections";
|
|
|
2
2
|
import { PreviewProvider } from "./preview/preview-provider";
|
|
3
3
|
import { usePreviewContext } from "./preview/preview-content";
|
|
4
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
5
|
+
import { useOverlayScript } from "./use-overlay-script";
|
|
5
6
|
import { registerSection } from "./register-section";
|
|
6
7
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
7
|
-
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, PreviewProvider, RenderSections, };
|
|
8
|
+
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, };
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,gCAAgC,EAChC,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,cAAc,GACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,gCAAgC,EAChC,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,cAAc,GACf,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { RenderSections } from "./render-sections";
|
|
|
2
2
|
import { PreviewProvider } from "./preview/preview-provider";
|
|
3
3
|
import { usePreviewContext } from "./preview/preview-content";
|
|
4
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
5
|
+
import { useOverlayScript } from "./use-overlay-script";
|
|
5
6
|
import { registerSection } from "./register-section";
|
|
6
7
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
7
|
-
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, PreviewProvider, RenderSections, };
|
|
8
|
+
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, };
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
type PreviewContextValue = {
|
|
3
3
|
isPreview: boolean;
|
|
4
4
|
siteSettings: any;
|
|
5
|
+
customizerMeta?: {
|
|
6
|
+
overlay?: {
|
|
7
|
+
src?: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
};
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
5
12
|
previewStorefrontSettings?: any;
|
|
6
13
|
setPreviewStorefrontSettings: (siteSettings: any) => void;
|
|
7
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":";AAEA,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,yBAAyB,CAAC,EAAE,GAAG,CAAC;IAChC,4BAA4B,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":";AAEA,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,yBAAyB,CAAC,EAAE,GAAG,CAAC;IAChC,4BAA4B,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,cAAc,8CAKzB,CAAC;AAEH,eAAO,MAAM,iBAAiB,2BAAmC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createContext, useContext } from
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
2
|
export const PreviewContext = createContext({
|
|
3
3
|
isPreview: false,
|
|
4
4
|
setPreviewStorefrontSettings: () => { },
|
|
5
5
|
siteSettings: undefined,
|
|
6
|
+
customizerMeta: undefined,
|
|
6
7
|
});
|
|
7
8
|
export const usePreviewContext = () => useContext(PreviewContext);
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import React, { ReactNode } from
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
2
|
interface PreviewContentProps {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
siteSettings: any;
|
|
5
5
|
isPreviewModeEnabled?: boolean;
|
|
6
|
+
customizerMeta?: {
|
|
7
|
+
overlay?: {
|
|
8
|
+
src?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
};
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
6
13
|
}
|
|
7
|
-
export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, }: PreviewContentProps): React.JSX.Element;
|
|
14
|
+
export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PreviewContentProps): React.JSX.Element;
|
|
8
15
|
export {};
|
|
9
16
|
//# sourceMappingURL=preview-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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;IAC/B,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,mBAAmB,qBAmBrB"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import React, { useState } from
|
|
2
|
-
import { PreviewContext } from
|
|
3
|
-
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { PreviewContext } from "./preview-content";
|
|
3
|
+
import { PreviewToast } from "./preview-toast";
|
|
4
|
+
export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
|
|
4
5
|
const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
|
|
5
6
|
return (React.createElement(PreviewContext.Provider, { value: {
|
|
6
7
|
isPreview: !!isPreviewModeEnabled,
|
|
7
8
|
previewStorefrontSettings,
|
|
8
9
|
setPreviewStorefrontSettings,
|
|
9
10
|
siteSettings,
|
|
10
|
-
|
|
11
|
+
customizerMeta,
|
|
12
|
+
} },
|
|
13
|
+
children,
|
|
14
|
+
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
|
|
11
15
|
}
|
|
@@ -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;
|
|
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"}
|
package/dist/render-sections.js
CHANGED
|
@@ -3,9 +3,9 @@ import { useCustomizerShell } from "./use-customizer-shell";
|
|
|
3
3
|
import { usePreviewContext } from "./preview/preview-content";
|
|
4
4
|
import { sectionMap } from "./register-section";
|
|
5
5
|
import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
6
|
+
import { useOverlayScript } from "./use-overlay-script";
|
|
6
7
|
function Sections({ sections }) {
|
|
7
8
|
const renderedSections = useMemo(() => {
|
|
8
|
-
console.log('DEBUG: sections', sections);
|
|
9
9
|
return sections
|
|
10
10
|
.map((section) => {
|
|
11
11
|
// TODO: Return a consistent data structure from the API and the customizer
|
|
@@ -16,7 +16,6 @@ function Sections({ sections }) {
|
|
|
16
16
|
data.dataSource = section.dataSource;
|
|
17
17
|
const schemaKey = data._template;
|
|
18
18
|
const Component = sectionMap.get(schemaKey);
|
|
19
|
-
console.log('DEBUG: Component', Component);
|
|
20
19
|
if (!Component)
|
|
21
20
|
return null;
|
|
22
21
|
return (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key, hidden: data?.sectionVisibility === "hidden" },
|
|
@@ -27,7 +26,7 @@ function Sections({ sections }) {
|
|
|
27
26
|
return React.createElement(React.Fragment, null, renderedSections);
|
|
28
27
|
}
|
|
29
28
|
export function RenderSections({ content }) {
|
|
30
|
-
const { isPreview, setPreviewStorefrontSettings } = usePreviewContext();
|
|
29
|
+
const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
|
|
31
30
|
const { content: liveContent, storefrontSettings } = useCustomizerShell({
|
|
32
31
|
environment: "production",
|
|
33
32
|
isPreview,
|
|
@@ -42,12 +41,12 @@ export function RenderSections({ content }) {
|
|
|
42
41
|
},
|
|
43
42
|
storefrontSettingsSchema,
|
|
44
43
|
});
|
|
44
|
+
useOverlayScript({ isPreview, overlay: customizerMeta?.overlay || {} });
|
|
45
45
|
useEffect(() => {
|
|
46
46
|
storefrontSettings &&
|
|
47
47
|
setPreviewStorefrontSettings({ settings: storefrontSettings });
|
|
48
48
|
}, [setPreviewStorefrontSettings, storefrontSettings]);
|
|
49
49
|
const sections = useMemo(() => {
|
|
50
|
-
console.log('DEBUG: liveContent', liveContent?.sections?.nodes || liveContent?.sections);
|
|
51
50
|
return liveContent?.sections?.nodes || liveContent?.sections;
|
|
52
51
|
}, [liveContent?.sections]);
|
|
53
52
|
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;;;
|
|
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
|
-
|
|
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('DEBUG: refreshing sections');
|
|
97
100
|
refreshSections();
|
|
98
101
|
refreshStorefrontSettingsSchema();
|
|
99
102
|
}, [
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
pack?: {
|
|
4
|
+
isOverlayScriptInjected: boolean;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare const useOverlayScript: ({ isPreview, overlay, }: {
|
|
9
|
+
isPreview: boolean;
|
|
10
|
+
overlay: {
|
|
11
|
+
src?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
};
|
|
14
|
+
}) => void;
|
|
15
|
+
//# sourceMappingURL=use-overlay-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-overlay-script.d.ts","sourceRoot":"","sources":["../src/use-overlay-script.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE;YACL,uBAAuB,EAAE,OAAO,CAAC;SAClC,CAAC;KACH;CACF;AAED,eAAO,MAAM,gBAAgB;eAIhB,OAAO;aACT;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;UAmB5C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
export const useOverlayScript = ({ isPreview, overlay, }) => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
if (isPreview &&
|
|
5
|
+
(overlay?.src || overlay?.version) &&
|
|
6
|
+
!window.pack?.isOverlayScriptInjected) {
|
|
7
|
+
const script = document.createElement("script");
|
|
8
|
+
script.src =
|
|
9
|
+
overlay?.src ||
|
|
10
|
+
`https://d3dizc9fcooe02.cloudfront.net/overlay@${overlay?.version}/dist/overlay.js`;
|
|
11
|
+
script.async = true;
|
|
12
|
+
document.body.appendChild(script);
|
|
13
|
+
window.pack = { ...window.pack, isOverlayScriptInjected: true };
|
|
14
|
+
}
|
|
15
|
+
}, [isPreview, overlay]);
|
|
16
|
+
};
|
|
@@ -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,
|
|
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
|
|
1
|
+
import { usePreviewContext } from "./preview/preview-content";
|
|
2
2
|
export const useSiteSettings = () => {
|
|
3
3
|
const { isPreview, previewStorefrontSettings, siteSettings } = usePreviewContext();
|
|
4
|
-
|
|
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
|
};
|