@pack/react 0.0.14 → 0.1.1
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 +8 -1
- package/dist/preview/preview-provider.d.ts.map +1 -1
- package/dist/preview/preview-provider.js +2 -1
- package/dist/render-sections.d.ts.map +1 -1
- package/dist/render-sections.js +4 -2
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +20 -11
- 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/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);
|
|
@@ -3,7 +3,14 @@ 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,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;
|
|
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,13 +1,14 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
import { PreviewContext } from "./preview-content";
|
|
3
3
|
import { PreviewToast } from "./preview-toast";
|
|
4
|
-
export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, }) {
|
|
4
|
+
export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
|
|
5
5
|
const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
|
|
6
6
|
return (React.createElement(PreviewContext.Provider, { value: {
|
|
7
7
|
isPreview: !!isPreviewModeEnabled,
|
|
8
8
|
previewStorefrontSettings,
|
|
9
9
|
setPreviewStorefrontSettings,
|
|
10
10
|
siteSettings,
|
|
11
|
+
customizerMeta,
|
|
11
12
|
} },
|
|
12
13
|
children,
|
|
13
14
|
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
|
|
@@ -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;AAoClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAiC9C"}
|
package/dist/render-sections.js
CHANGED
|
@@ -3,6 +3,7 @@ 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
9
|
return sections
|
|
@@ -17,7 +18,7 @@ function Sections({ sections }) {
|
|
|
17
18
|
const Component = sectionMap.get(schemaKey);
|
|
18
19
|
if (!Component)
|
|
19
20
|
return null;
|
|
20
|
-
return (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key
|
|
21
|
+
return data?.sectionVisibility === "hidden" ? null : (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key },
|
|
21
22
|
React.createElement(Component, { "comp-name": schemaKey, cms: data })));
|
|
22
23
|
})
|
|
23
24
|
.filter(Boolean);
|
|
@@ -25,7 +26,7 @@ function Sections({ sections }) {
|
|
|
25
26
|
return React.createElement(React.Fragment, null, renderedSections);
|
|
26
27
|
}
|
|
27
28
|
export function RenderSections({ content }) {
|
|
28
|
-
const { isPreview, setPreviewStorefrontSettings } = usePreviewContext();
|
|
29
|
+
const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
|
|
29
30
|
const { content: liveContent, storefrontSettings } = useCustomizerShell({
|
|
30
31
|
environment: "production",
|
|
31
32
|
isPreview,
|
|
@@ -40,6 +41,7 @@ export function RenderSections({ content }) {
|
|
|
40
41
|
},
|
|
41
42
|
storefrontSettingsSchema,
|
|
42
43
|
});
|
|
44
|
+
useOverlayScript({ isPreview, overlay: customizerMeta?.overlay || {} });
|
|
43
45
|
useEffect(() => {
|
|
44
46
|
storefrontSettings &&
|
|
45
47
|
setPreviewStorefrontSettings({ settings: storefrontSettings });
|
|
@@ -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;;;CAkJL,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { connectToParent, ErrorCode } from "penpal";
|
|
3
3
|
export const useCustomizerShell = ({ environment = "production", isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
|
|
4
|
-
const
|
|
4
|
+
const windowLocationRef = useRef();
|
|
5
5
|
const [content, setContent] = useState(data.content);
|
|
6
6
|
const [storefrontSettings, setStorefrontSettings] = useState(null);
|
|
7
7
|
const [parentConnection, setParentConnection] = useState(null);
|
|
@@ -10,17 +10,17 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
|
|
|
10
10
|
window.location.href = path;
|
|
11
11
|
};
|
|
12
12
|
useEffect(() => {
|
|
13
|
-
const isIframe = window.self !== window.top;
|
|
14
13
|
/*
|
|
15
14
|
* Should not try to connect to customizer
|
|
16
15
|
* if not in an iframe or not in preview mode
|
|
17
16
|
*/
|
|
17
|
+
const isIframe = window.self !== window.top;
|
|
18
18
|
if (!isIframe || !isPreview)
|
|
19
19
|
return;
|
|
20
20
|
setShouldConnectToParent(true);
|
|
21
21
|
}, []);
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
|
|
23
|
+
windowLocationRef.current = window.location;
|
|
24
24
|
}, [data.handle]);
|
|
25
25
|
const refreshSections = useCallback(() => {
|
|
26
26
|
if (!sectionComponents || !parentConnection)
|
|
@@ -58,7 +58,9 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
|
|
|
58
58
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
59
|
}, [data.handle, parentConnection, storefrontSettingsSchema]);
|
|
60
60
|
useEffect(() => {
|
|
61
|
-
if (!isPreview ||
|
|
61
|
+
if (!isPreview ||
|
|
62
|
+
!windowLocationRef.current?.pathname ||
|
|
63
|
+
!shouldConnectToParent)
|
|
62
64
|
return;
|
|
63
65
|
const connection = connectToParent({
|
|
64
66
|
methods: {
|
|
@@ -79,21 +81,28 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
|
|
|
79
81
|
},
|
|
80
82
|
});
|
|
81
83
|
connection.promise.then((parent) => {
|
|
82
|
-
const { template, templateType,
|
|
84
|
+
const { template, templateType, handle, title, description } = data;
|
|
83
85
|
parent.sendStorefrontSettings();
|
|
84
86
|
parent.setCurrentRoute({
|
|
85
87
|
environment,
|
|
86
|
-
currentPath:
|
|
88
|
+
currentPath: windowLocationRef.current?.pathname,
|
|
87
89
|
template,
|
|
88
90
|
templateType,
|
|
89
|
-
handle
|
|
90
|
-
title
|
|
91
|
-
description
|
|
91
|
+
handle,
|
|
92
|
+
title,
|
|
93
|
+
description,
|
|
92
94
|
});
|
|
93
95
|
setParentConnection(parent);
|
|
94
96
|
});
|
|
95
97
|
return () => connection.destroy();
|
|
96
|
-
}, [
|
|
98
|
+
}, [
|
|
99
|
+
shouldConnectToParent,
|
|
100
|
+
data.handle,
|
|
101
|
+
data.title,
|
|
102
|
+
data.description,
|
|
103
|
+
data.template,
|
|
104
|
+
data.templateType,
|
|
105
|
+
]);
|
|
97
106
|
useEffect(() => {
|
|
98
107
|
if (!isPreview)
|
|
99
108
|
return;
|
|
@@ -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,4BAG1B;IACD,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,SAkBA,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
|
+
};
|