@pack/react 1.0.0 → 2.0.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/preview/preview-content.d.ts +7 -5
- package/dist/preview/preview-content.d.ts.map +1 -1
- package/dist/preview/preview-content.js +28 -23
- package/dist/preview/render-sections.d.ts +6 -2
- package/dist/preview/render-sections.d.ts.map +1 -1
- package/dist/preview/render-sections.js +23 -25
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/use-customizer-shell.d.ts +5 -1
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +167 -82
- package/dist/version.js +1 -1
- package/package.json +3 -5
- package/dist/pack/pack-analytics.d.ts +0 -16
- package/dist/pack/pack-analytics.d.ts.map +0 -1
- package/dist/pack/pack-analytics.js +0 -65
- package/dist/pack/pack-context.d.ts +0 -22
- package/dist/pack/pack-context.d.ts.map +0 -1
- package/dist/pack/pack-context.js +0 -10
- package/dist/pack/pack-provider.d.ts +0 -12
- package/dist/pack/pack-provider.d.ts.map +0 -1
- package/dist/pack/pack-provider.js +0 -18
- package/dist/pack/preview-toast.d.ts +0 -7
- package/dist/pack/preview-toast.d.ts.map +0 -1
- package/dist/pack/preview-toast.js +0 -85
- package/dist/preview/preview-provider.d.ts +0 -11
- package/dist/preview/preview-provider.d.ts.map +0 -1
- package/dist/preview/preview-provider.js +0 -11
- package/dist/render-sections.d.ts +0 -8
- package/dist/render-sections.d.ts.map +0 -1
- package/dist/render-sections.js +0 -75
|
@@ -10,17 +10,19 @@ type PreviewContextValue = {
|
|
|
10
10
|
};
|
|
11
11
|
siteSettings: any;
|
|
12
12
|
setSiteSettings: (siteSettings: any) => void;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
previewContent: any;
|
|
14
|
+
setPreviewContent: (content: any) => void;
|
|
15
15
|
pathname: string;
|
|
16
|
+
contentEnvironment: string;
|
|
16
17
|
};
|
|
17
18
|
export declare const PreviewContext: React.Context<PreviewContextValue>;
|
|
18
19
|
export declare const usePreviewContext: () => PreviewContextValue;
|
|
19
20
|
interface PreviewProviderProps {
|
|
20
|
-
children:
|
|
21
|
+
children: ReactNode;
|
|
21
22
|
siteSettings: any;
|
|
22
23
|
pathname: string;
|
|
23
24
|
isPreviewModeEnabled?: boolean;
|
|
25
|
+
contentEnvironment?: string;
|
|
24
26
|
customizerMeta?: {
|
|
25
27
|
overlay?: {
|
|
26
28
|
src?: string;
|
|
@@ -29,10 +31,10 @@ interface PreviewProviderProps {
|
|
|
29
31
|
[key: string]: any;
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
|
-
export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, pathname, }: PreviewProviderProps): React.JSX.Element;
|
|
34
|
+
export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, pathname, contentEnvironment, }: PreviewProviderProps): React.JSX.Element;
|
|
33
35
|
export declare function RenderContent({ content }: {
|
|
34
36
|
content: any;
|
|
35
|
-
}):
|
|
37
|
+
}): React.JSX.Element;
|
|
36
38
|
export declare function usePackContent(content: any): void;
|
|
37
39
|
export {};
|
|
38
40
|
//# sourceMappingURL=preview-content.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAMf,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,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,YAAY,EAAE,GAAG,CAAC;IAClB,eAAe,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;IAC7C,cAAc,EAAE,GAAG,CAAC;IACpB,iBAAiB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,cAAc,oCASzB,CAAC;AAEH,eAAO,MAAM,iBAAiB,2BAAmC,CAAC;AAElE,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,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,oBAA4B,EAC5B,YAAY,EAAE,yBAAyB,EACvC,cAAc,EACd,QAAQ,EACR,kBAAuB,GACxB,EAAE,oBAAoB,qBAoCtB;AAED,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,qBAe1D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,QAS1C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState,
|
|
1
|
+
import React, { createContext, useContext, useState, useMemo, } from "react";
|
|
2
2
|
import { RenderSections } from "./render-sections";
|
|
3
3
|
import { usePackTrack } from "./pack-analytics";
|
|
4
4
|
import { PreviewToast } from "./preview-toast";
|
|
@@ -7,13 +7,14 @@ export const PreviewContext = createContext({
|
|
|
7
7
|
setSiteSettings: () => { },
|
|
8
8
|
siteSettings: undefined,
|
|
9
9
|
customizerMeta: undefined,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
previewContent: null,
|
|
11
|
+
setPreviewContent: () => { },
|
|
12
12
|
pathname: "",
|
|
13
|
+
contentEnvironment: "",
|
|
13
14
|
});
|
|
14
15
|
export const usePreviewContext = () => useContext(PreviewContext);
|
|
15
|
-
export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, pathname, }) {
|
|
16
|
-
const [
|
|
16
|
+
export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, pathname, contentEnvironment = "", }) {
|
|
17
|
+
const [previewContent, setPreviewContent] = useState(null);
|
|
17
18
|
const [siteSettings, setSiteSettings] = useState(previewStorefrontSettings);
|
|
18
19
|
usePackTrack();
|
|
19
20
|
const value = useMemo(() => ({
|
|
@@ -21,37 +22,41 @@ export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSe
|
|
|
21
22
|
customizerMeta,
|
|
22
23
|
siteSettings,
|
|
23
24
|
setSiteSettings,
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
previewContent,
|
|
26
|
+
setPreviewContent,
|
|
26
27
|
pathname,
|
|
28
|
+
contentEnvironment,
|
|
27
29
|
}), [
|
|
28
30
|
isPreviewModeEnabled,
|
|
29
31
|
siteSettings,
|
|
30
32
|
customizerMeta,
|
|
31
33
|
setSiteSettings,
|
|
32
|
-
|
|
34
|
+
previewContent,
|
|
33
35
|
pathname,
|
|
36
|
+
contentEnvironment,
|
|
34
37
|
]);
|
|
35
|
-
// Clear content when navigating to a new page
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
content && setContent(null);
|
|
38
|
-
}, [pathname]);
|
|
39
|
-
const sections = content ? React.createElement(RenderSections, null) : null;
|
|
40
38
|
return (React.createElement(PreviewContext.Provider, { value: value },
|
|
41
|
-
children
|
|
39
|
+
children,
|
|
42
40
|
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
|
|
43
41
|
}
|
|
44
42
|
export function RenderContent({ content }) {
|
|
45
|
-
const {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
const { isPreview, setPreviewContent } = usePreviewContext();
|
|
44
|
+
// Update content in context for preview mode
|
|
45
|
+
useMemo(() => {
|
|
46
|
+
setPreviewContent(content);
|
|
47
|
+
}, [content, setPreviewContent]);
|
|
48
|
+
// If in preview mode, RenderSections will handle rendering with live content
|
|
49
|
+
if (isPreview) {
|
|
50
|
+
return React.createElement(RenderSections, null);
|
|
51
|
+
}
|
|
52
|
+
// For SSR, pass the content directly
|
|
53
|
+
return React.createElement(RenderSections, { content: content });
|
|
50
54
|
}
|
|
51
55
|
export function usePackContent(content) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const { setPreviewContent } = usePreviewContext();
|
|
57
|
+
// Update preview content
|
|
58
|
+
useMemo(() => {
|
|
59
|
+
setPreviewContent(content);
|
|
60
|
+
}, [content, setPreviewContent]);
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface RenderSectionsProps {
|
|
3
|
+
content?: any;
|
|
4
|
+
}
|
|
5
|
+
export declare function RenderSections(props: RenderSectionsProps): React.JSX.Element | null;
|
|
6
|
+
export declare function useSections(props: RenderSectionsProps): any;
|
|
7
|
+
export {};
|
|
4
8
|
//# sourceMappingURL=render-sections.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAoCvC,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAuBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAOxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,OAMrD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
|
-
import { useMatches } from "@remix-run/react";
|
|
3
2
|
import { usePreviewContext } from "./preview-content";
|
|
4
3
|
import { sectionMap } from "../register-section";
|
|
5
4
|
import { storefrontSettingsSchema } from "../register-storefront-settings-schema";
|
|
@@ -26,35 +25,34 @@ function Sections({ sections }) {
|
|
|
26
25
|
}, [sections]);
|
|
27
26
|
return React.createElement(React.Fragment, null, renderedSections);
|
|
28
27
|
}
|
|
29
|
-
function useRenderSections() {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const sections = useMemo(() => {
|
|
28
|
+
function useRenderSections({ content: ssrContent }) {
|
|
29
|
+
const { previewContent, isPreview, contentEnvironment } = usePreviewContext();
|
|
30
|
+
// In preview mode, use the customizer shell to get live content
|
|
31
|
+
if (isPreview) {
|
|
32
|
+
const { content: liveContent } = useCustomizerShell({
|
|
33
|
+
environment: contentEnvironment,
|
|
34
|
+
sectionComponents: sectionMap,
|
|
35
|
+
storefrontSettingsSchema,
|
|
36
|
+
});
|
|
39
37
|
return liveContent?.sections?.nodes || liveContent?.sections;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
}
|
|
39
|
+
// For SSR and non-preview mode, use the passed in content
|
|
40
|
+
const contentToRender = ssrContent || previewContent;
|
|
41
|
+
if (!contentToRender)
|
|
42
|
+
return null;
|
|
43
|
+
return contentToRender?.sections?.nodes || contentToRender?.sections;
|
|
44
44
|
}
|
|
45
|
-
export function
|
|
46
|
-
|
|
45
|
+
export function RenderSections(props) {
|
|
46
|
+
useOverlayScript();
|
|
47
|
+
const sections = useRenderSections(props);
|
|
47
48
|
if (!sections)
|
|
48
49
|
return null;
|
|
49
|
-
|
|
50
|
-
return visibleSections?.props?.children || null;
|
|
50
|
+
return React.createElement(Sections, { sections: sections });
|
|
51
51
|
}
|
|
52
|
-
export function
|
|
53
|
-
const
|
|
54
|
-
if (!content)
|
|
55
|
-
return null;
|
|
56
|
-
const { sections } = useRenderSections();
|
|
52
|
+
export function useSections(props) {
|
|
53
|
+
const sections = useRenderSections(props);
|
|
57
54
|
if (!sections)
|
|
58
55
|
return null;
|
|
59
|
-
|
|
56
|
+
const visibleSections = Sections({ sections });
|
|
57
|
+
return visibleSections?.props?.children || null;
|
|
60
58
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,4 +7,64 @@ export type SectionConfig = {
|
|
|
7
7
|
name: string;
|
|
8
8
|
};
|
|
9
9
|
export type SectionMap = Map<string, Section>;
|
|
10
|
+
export interface MessageTypeDataMap {
|
|
11
|
+
INIT: {
|
|
12
|
+
version: string;
|
|
13
|
+
storefrontMeta: any[];
|
|
14
|
+
};
|
|
15
|
+
ACK: {
|
|
16
|
+
messageId: string;
|
|
17
|
+
};
|
|
18
|
+
PING: never;
|
|
19
|
+
PONG: {
|
|
20
|
+
url: string;
|
|
21
|
+
};
|
|
22
|
+
ERROR: {
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
DISPLAY_ERROR: {
|
|
27
|
+
message: string;
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
};
|
|
30
|
+
NAVIGATE_TO_PAGE: {
|
|
31
|
+
path: string;
|
|
32
|
+
};
|
|
33
|
+
SET_CURRENT_ROUTE: {
|
|
34
|
+
currentPath: string;
|
|
35
|
+
description: string;
|
|
36
|
+
environment: string;
|
|
37
|
+
handle: string;
|
|
38
|
+
title: string;
|
|
39
|
+
template?: string;
|
|
40
|
+
templateType?: string;
|
|
41
|
+
};
|
|
42
|
+
SET_SECTIONS_SCHEMAS: {
|
|
43
|
+
schema: string;
|
|
44
|
+
};
|
|
45
|
+
SET_STOREFRONT_SETTINGS_SCHEMA: {
|
|
46
|
+
schema: string;
|
|
47
|
+
};
|
|
48
|
+
SET_PAGE_DATA: {
|
|
49
|
+
content: Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
SEND_STOREFRONT_SETTINGS: never;
|
|
52
|
+
SET_STOREFRONT_SETTINGS: {
|
|
53
|
+
settings: Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
SCROLL_TO_SECTION: {
|
|
56
|
+
sectionId: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface MessageProtocol<T extends keyof MessageTypeDataMap = keyof MessageTypeDataMap> {
|
|
60
|
+
pack: {
|
|
61
|
+
type: T;
|
|
62
|
+
data?: MessageTypeDataMap[T];
|
|
63
|
+
origin: string;
|
|
64
|
+
version: string;
|
|
65
|
+
messageId: string;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
errorCode?: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
10
70
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACzC,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACzC,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAG9C,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,GAAG,EAAE,CAAC;KACvB,CAAC;IACF,GAAG,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,aAAa,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAGvD,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,iBAAiB,EAAE;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IAGF,oBAAoB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,8BAA8B,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAGnD,aAAa,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IACpD,wBAAwB,EAAE,KAAK,CAAC;IAChC,uBAAuB,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAG/D,iBAAiB,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,MAAM,kBAAkB,GAAG,MAAM,kBAAkB;IAE7D,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC;QACR,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export declare const useCustomizerShell: ({ environment, sectionComponents, storefrontSettingsSchema, }:
|
|
1
|
+
export declare const useCustomizerShell: ({ environment, sectionComponents, storefrontSettingsSchema, }: {
|
|
2
|
+
environment: string;
|
|
3
|
+
sectionComponents: any;
|
|
4
|
+
storefrontSettingsSchema?: any;
|
|
5
|
+
}) => {
|
|
2
6
|
content: any;
|
|
3
7
|
};
|
|
4
8
|
//# sourceMappingURL=use-customizer-shell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,kBAAkB;iBAKhB,MAAM;uBACA,GAAG;+BACK,GAAG;;;CAsQ/B,CAAC"}
|
|
@@ -1,37 +1,129 @@
|
|
|
1
1
|
import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { VERSION } from "./version";
|
|
3
3
|
import { PreviewContext } from "./preview/preview-content";
|
|
4
4
|
export const useCustomizerShell = ({ environment, sectionComponents, storefrontSettingsSchema, }) => {
|
|
5
|
-
const { isPreview,
|
|
5
|
+
const { previewContent, isPreview, pathname, setPreviewContent, setSiteSettings, } = useContext(PreviewContext);
|
|
6
6
|
const data = {
|
|
7
|
-
content,
|
|
8
|
-
template:
|
|
9
|
-
templateType:
|
|
10
|
-
handle:
|
|
11
|
-
title:
|
|
12
|
-
description:
|
|
7
|
+
content: previewContent,
|
|
8
|
+
template: previewContent?.template?.type,
|
|
9
|
+
templateType: previewContent?.template?.type,
|
|
10
|
+
handle: previewContent?.handle,
|
|
11
|
+
title: previewContent?.title,
|
|
12
|
+
description: previewContent?.description,
|
|
13
13
|
};
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
const [hasInit, setHasInit] = useState(false);
|
|
15
|
+
const pendingMessagesRef = useRef(new Map());
|
|
16
|
+
const currentPathRef = useRef();
|
|
17
|
+
const canConnectToParent = useCanConnectCheck({ isPreview });
|
|
18
|
+
const sendToParent = useCallback(async (type, data) => {
|
|
19
|
+
const messageId = crypto.randomUUID();
|
|
20
|
+
const message = {
|
|
21
|
+
pack: {
|
|
22
|
+
type,
|
|
23
|
+
data,
|
|
24
|
+
origin: "*",
|
|
25
|
+
version: VERSION,
|
|
26
|
+
messageId,
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
if (type === "ACK") {
|
|
31
|
+
window.parent.postMessage(message, "*");
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
}
|
|
34
|
+
const messagePromise = new Promise((resolve, reject) => {
|
|
35
|
+
const timeout = setTimeout(() => {
|
|
36
|
+
pendingMessagesRef.current.delete(messageId);
|
|
37
|
+
reject(new Error(`Message ${messageId} timed out waiting for ACK`));
|
|
38
|
+
}, 2000);
|
|
39
|
+
pendingMessagesRef.current.set(messageId, {
|
|
40
|
+
messageId,
|
|
41
|
+
resolve,
|
|
42
|
+
reject,
|
|
43
|
+
timeout,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
window.parent.postMessage(message, "*");
|
|
47
|
+
return messagePromise;
|
|
29
48
|
}, []);
|
|
30
49
|
useEffect(() => {
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
if (!isPreview || !canConnectToParent || hasInit)
|
|
51
|
+
return;
|
|
52
|
+
sendToParent("INIT", {
|
|
53
|
+
storefrontMeta: [],
|
|
54
|
+
version: VERSION,
|
|
55
|
+
}).catch((error) => {
|
|
56
|
+
console.error("Failed to initialize:", error);
|
|
57
|
+
});
|
|
58
|
+
setHasInit(true);
|
|
59
|
+
const handleParentMessages = (event) => {
|
|
60
|
+
if (!event.data?.pack) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const message = event.data;
|
|
64
|
+
// Handle ACK messages
|
|
65
|
+
if (message.pack.type === "ACK") {
|
|
66
|
+
const acknowledgedMessageId = message.pack.data?.messageId;
|
|
67
|
+
const pendingMessage = pendingMessagesRef.current.get(acknowledgedMessageId);
|
|
68
|
+
if (pendingMessage) {
|
|
69
|
+
clearTimeout(pendingMessage.timeout);
|
|
70
|
+
pendingMessage.resolve();
|
|
71
|
+
pendingMessagesRef.current.delete(acknowledgedMessageId);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// Handle other message types
|
|
76
|
+
sendToParent("ACK", { messageId: message.pack.messageId }).catch(console.error);
|
|
77
|
+
switch (message.pack.type) {
|
|
78
|
+
case "PING":
|
|
79
|
+
sendToParent("PONG", {
|
|
80
|
+
url: window.location.href,
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
83
|
+
case "NAVIGATE_TO_PAGE":
|
|
84
|
+
const path = message.pack.data?.path;
|
|
85
|
+
if (path) {
|
|
86
|
+
window.location.href = path;
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case "SCROLL_TO_SECTION":
|
|
90
|
+
const sectionId = message.pack.data?.sectionId;
|
|
91
|
+
if (sectionId) {
|
|
92
|
+
const sectionEl = document.querySelector(`[data-comp-id="${sectionId}"]`);
|
|
93
|
+
if (sectionEl)
|
|
94
|
+
sectionEl.scrollIntoView({ behavior: "smooth" });
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case "SET_PAGE_DATA":
|
|
98
|
+
setPreviewContent(message.pack.data?.content);
|
|
99
|
+
break;
|
|
100
|
+
case "SET_STOREFRONT_SETTINGS":
|
|
101
|
+
setSiteSettings({
|
|
102
|
+
data: {
|
|
103
|
+
siteSettings: {
|
|
104
|
+
settings: message.pack
|
|
105
|
+
.data?.settings,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
window.addEventListener("message", handleParentMessages);
|
|
115
|
+
return () => {
|
|
116
|
+
window.removeEventListener("message", handleParentMessages);
|
|
117
|
+
// Clean up any pending messages
|
|
118
|
+
pendingMessagesRef.current.forEach((pending) => {
|
|
119
|
+
clearTimeout(pending.timeout);
|
|
120
|
+
pending.reject(new Error("Component unmounted"));
|
|
121
|
+
});
|
|
122
|
+
pendingMessagesRef.current.clear();
|
|
123
|
+
};
|
|
124
|
+
}, [canConnectToParent, isPreview, sendToParent]);
|
|
33
125
|
const refreshSections = useCallback(() => {
|
|
34
|
-
if (!sectionComponents
|
|
126
|
+
if (!sectionComponents)
|
|
35
127
|
return [];
|
|
36
128
|
const sectionSchemas = Array.from(sectionComponents)
|
|
37
129
|
.map(([, section]) => {
|
|
@@ -41,78 +133,60 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
|
|
|
41
133
|
})
|
|
42
134
|
.filter(Boolean);
|
|
43
135
|
try {
|
|
44
|
-
|
|
136
|
+
sendToParent("SET_SECTIONS_SCHEMAS", {
|
|
137
|
+
schema: JSON.stringify(sectionSchemas),
|
|
138
|
+
});
|
|
45
139
|
}
|
|
46
140
|
catch (error) {
|
|
47
|
-
if (error.code !==
|
|
48
|
-
|
|
141
|
+
if (error.code !== "ConnectionDestroyed") {
|
|
142
|
+
sendToParent("DISPLAY_ERROR", {
|
|
143
|
+
message: "Something went wrong parsing sections",
|
|
144
|
+
});
|
|
49
145
|
}
|
|
50
146
|
}
|
|
51
147
|
return;
|
|
52
|
-
}, [data.handle,
|
|
148
|
+
}, [data.handle, sectionComponents, sendToParent]);
|
|
53
149
|
const refreshStorefrontSettingsSchema = useCallback(() => {
|
|
54
|
-
if (!storefrontSettingsSchema || !
|
|
150
|
+
if (!storefrontSettingsSchema || !sectionComponents) {
|
|
55
151
|
return [];
|
|
56
152
|
}
|
|
57
153
|
try {
|
|
58
|
-
|
|
154
|
+
sendToParent("SET_STOREFRONT_SETTINGS_SCHEMA", {
|
|
155
|
+
schema: JSON.stringify(storefrontSettingsSchema),
|
|
156
|
+
});
|
|
59
157
|
}
|
|
60
158
|
catch (error) {
|
|
61
|
-
if (error.code !==
|
|
62
|
-
|
|
159
|
+
if (error.code !== "ConnectionDestroyed") {
|
|
160
|
+
sendToParent("DISPLAY_ERROR", {
|
|
161
|
+
message: "Something went wrong parsing settings",
|
|
162
|
+
});
|
|
63
163
|
}
|
|
64
164
|
}
|
|
65
165
|
return;
|
|
66
166
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
-
}, [data.handle,
|
|
167
|
+
}, [data.handle, sendToParent, storefrontSettingsSchema]);
|
|
168
|
+
// Update the ref whenever pathname changes
|
|
68
169
|
useEffect(() => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
170
|
+
currentPathRef.current = pathname;
|
|
171
|
+
}, [pathname]);
|
|
172
|
+
// Tell the parent window about the current route
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (!hasInit || !currentPathRef.current)
|
|
72
175
|
return;
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
setPageData(content) {
|
|
84
|
-
setContent(content);
|
|
85
|
-
},
|
|
86
|
-
setStorefrontSettings(settings) {
|
|
87
|
-
setSiteSettings({ data: { siteSettings: { settings } } });
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
connection.promise.then((parent) => {
|
|
92
|
-
const { template, templateType, handle, title, description } = data;
|
|
93
|
-
parent.sendStorefrontSettings();
|
|
94
|
-
parent.setCurrentRoute({
|
|
95
|
-
environment,
|
|
96
|
-
currentPath: windowLocationRef.current?.pathname,
|
|
97
|
-
template,
|
|
98
|
-
templateType,
|
|
99
|
-
handle,
|
|
100
|
-
title,
|
|
101
|
-
description,
|
|
102
|
-
});
|
|
103
|
-
setParentConnection(parent);
|
|
176
|
+
const { template, templateType, handle, title, description } = data;
|
|
177
|
+
sendToParent("SET_CURRENT_ROUTE", {
|
|
178
|
+
environment,
|
|
179
|
+
currentPath: currentPathRef.current,
|
|
180
|
+
template,
|
|
181
|
+
templateType,
|
|
182
|
+
handle,
|
|
183
|
+
title,
|
|
184
|
+
description,
|
|
104
185
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
shouldConnectToParent,
|
|
108
|
-
data.handle,
|
|
109
|
-
data.title,
|
|
110
|
-
data.description,
|
|
111
|
-
data.template,
|
|
112
|
-
data.templateType,
|
|
113
|
-
]);
|
|
186
|
+
}, [hasInit, environment, data.handle, sendToParent]);
|
|
187
|
+
// Refresh sections and storefront settings schema
|
|
114
188
|
useEffect(() => {
|
|
115
|
-
if (!isPreview)
|
|
189
|
+
if (!isPreview || !hasInit)
|
|
116
190
|
return;
|
|
117
191
|
refreshSections();
|
|
118
192
|
refreshStorefrontSettingsSchema();
|
|
@@ -122,13 +196,24 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
|
|
|
122
196
|
refreshSections,
|
|
123
197
|
refreshStorefrontSettingsSchema,
|
|
124
198
|
sectionComponents,
|
|
199
|
+
hasInit,
|
|
125
200
|
]);
|
|
126
201
|
if (!isPreview) {
|
|
127
202
|
return {
|
|
128
|
-
content,
|
|
203
|
+
content: previewContent,
|
|
129
204
|
};
|
|
130
205
|
}
|
|
131
206
|
return useMemo(() => {
|
|
132
|
-
return { content };
|
|
133
|
-
}, [
|
|
207
|
+
return { content: previewContent };
|
|
208
|
+
}, [previewContent]);
|
|
209
|
+
};
|
|
210
|
+
const useCanConnectCheck = ({ isPreview }) => {
|
|
211
|
+
const [canConnect, setCanConnect] = useState(false);
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
const isIframe = window.self !== window.top;
|
|
214
|
+
if (!isIframe || !isPreview)
|
|
215
|
+
return;
|
|
216
|
+
setCanConnect(isIframe);
|
|
217
|
+
}, [isPreview]);
|
|
218
|
+
return canConnect;
|
|
134
219
|
};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1
|
|
1
|
+
export const VERSION = "2.0.1";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pack/react",
|
|
3
3
|
"description": "React",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"engines": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"clean": "npx rimraf dist",
|
|
15
|
-
"build": "
|
|
15
|
+
"build": "node scripts/build.js",
|
|
16
16
|
"test": "npx vitest run",
|
|
17
17
|
"test:watch": "npx vitest"
|
|
18
18
|
},
|
|
@@ -30,7 +30,5 @@
|
|
|
30
30
|
"react": "^18.0.0",
|
|
31
31
|
"react-dom": "^18.0.0"
|
|
32
32
|
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"penpal": "^6.2.2"
|
|
35
|
-
}
|
|
33
|
+
"dependencies": {}
|
|
36
34
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type BrowserData = {
|
|
2
|
-
userAgent: string;
|
|
3
|
-
pathname: string;
|
|
4
|
-
query: string;
|
|
5
|
-
screen: string;
|
|
6
|
-
referrer: string;
|
|
7
|
-
hostname: string;
|
|
8
|
-
language: string;
|
|
9
|
-
locale: string;
|
|
10
|
-
userTimeZone: string;
|
|
11
|
-
connection: string;
|
|
12
|
-
deviceCategory: string;
|
|
13
|
-
href: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function usePackTrack(): void;
|
|
16
|
-
//# sourceMappingURL=pack-analytics.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pack-analytics.d.ts","sourceRoot":"","sources":["../../src/pack/pack-analytics.tsx"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAiDF,wBAAgB,YAAY,SA0B3B"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
function getBrowserData() {
|
|
3
|
-
let userTimeZone;
|
|
4
|
-
let userLocale;
|
|
5
|
-
try {
|
|
6
|
-
userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
7
|
-
userLocale =
|
|
8
|
-
navigator.languages && navigator.languages.length
|
|
9
|
-
? navigator.languages[0]
|
|
10
|
-
: navigator.userLanguage ||
|
|
11
|
-
navigator.language ||
|
|
12
|
-
navigator.browserLanguage ||
|
|
13
|
-
"unknown";
|
|
14
|
-
}
|
|
15
|
-
catch (error) { }
|
|
16
|
-
const connection = navigator.connection ||
|
|
17
|
-
navigator.mozConnection ||
|
|
18
|
-
navigator.webkitConnection;
|
|
19
|
-
const minWidth = 768;
|
|
20
|
-
// prettier-ignore
|
|
21
|
-
const hasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
22
|
-
let deviceCategory = "desktop";
|
|
23
|
-
if (hasTouchSupport) {
|
|
24
|
-
const hasSmallScreen = window.screen.width < minWidth;
|
|
25
|
-
deviceCategory = hasSmallScreen ? "mobile" : "tablet";
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
userAgent: window.navigator.userAgent,
|
|
29
|
-
pathname: window.location.pathname,
|
|
30
|
-
query: window.location.search,
|
|
31
|
-
screen: `${window.screen.width}x${window.screen.height}`,
|
|
32
|
-
referrer: document.referrer,
|
|
33
|
-
hostname: window.location.hostname,
|
|
34
|
-
language: navigator.language,
|
|
35
|
-
locale: userLocale,
|
|
36
|
-
userTimeZone: userTimeZone || "unknown",
|
|
37
|
-
connection: connection?.effectiveType || "unknown",
|
|
38
|
-
deviceCategory,
|
|
39
|
-
href: window.location.href,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export function usePackTrack() {
|
|
43
|
-
const [pathname, setPathname] = useState();
|
|
44
|
-
const analytics = async () => {
|
|
45
|
-
const browserData = getBrowserData();
|
|
46
|
-
if (pathname === browserData.pathname)
|
|
47
|
-
return;
|
|
48
|
-
setPathname(browserData.pathname);
|
|
49
|
-
try {
|
|
50
|
-
await fetch("/pack/track", {
|
|
51
|
-
method: "POST",
|
|
52
|
-
headers: {
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
},
|
|
55
|
-
body: JSON.stringify(getBrowserData()),
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error("Error hit /pack/track: ", error.message);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
analytics();
|
|
64
|
-
}, [analytics]);
|
|
65
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
type PackCustomizerMeta = {
|
|
3
|
-
environment?: string;
|
|
4
|
-
overlay?: {
|
|
5
|
-
src?: string;
|
|
6
|
-
version?: string;
|
|
7
|
-
};
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
};
|
|
10
|
-
export type PackContextValue = {
|
|
11
|
-
isPreview: boolean;
|
|
12
|
-
siteSettings: any;
|
|
13
|
-
customizerMeta?: PackCustomizerMeta | null;
|
|
14
|
-
previewStorefrontSettings?: any;
|
|
15
|
-
setPreviewStorefrontSettings: (siteSettings: any) => void;
|
|
16
|
-
};
|
|
17
|
-
export declare const PackContext: import("react").Context<PackContextValue>;
|
|
18
|
-
export declare const usePackContext: () => PackContextValue;
|
|
19
|
-
export declare const PreviewContext: import("react").Context<PackContextValue>;
|
|
20
|
-
export declare const usePreviewContext: () => PackContextValue;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=pack-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":";AAEA,KAAK,kBAAkB,GAAG;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,cAAc,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC3C,yBAAyB,CAAC,EAAE,GAAG,CAAC;IAChC,4BAA4B,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,WAAW,2CAKtB,CAAC;AAEH,eAAO,MAAM,cAAc,wBAAgC,CAAC;AAE5D,eAAO,MAAM,cAAc,2CAAc,CAAC;AAE1C,eAAO,MAAM,iBAAiB,wBAAiB,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from "react";
|
|
2
|
-
export const PackContext = createContext({
|
|
3
|
-
isPreview: false,
|
|
4
|
-
setPreviewStorefrontSettings: () => { },
|
|
5
|
-
siteSettings: undefined,
|
|
6
|
-
customizerMeta: undefined,
|
|
7
|
-
});
|
|
8
|
-
export const usePackContext = () => useContext(PackContext);
|
|
9
|
-
export const PreviewContext = PackContext;
|
|
10
|
-
export const usePreviewContext = usePackContext;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from "react";
|
|
2
|
-
import { PackContextValue } from "./pack-context";
|
|
3
|
-
interface PackContentProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
siteSettings: any;
|
|
6
|
-
isPreviewModeEnabled?: boolean;
|
|
7
|
-
customizerMeta?: PackContextValue["customizerMeta"];
|
|
8
|
-
}
|
|
9
|
-
export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PackContentProps): React.JSX.Element;
|
|
10
|
-
export declare const PreviewProvider: typeof PackProvider;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=pack-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pack-provider.d.ts","sourceRoot":"","sources":["../../src/pack/pack-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AACnD,OAAO,EAAe,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAI/D,UAAU,gBAAgB;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CACrD;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,gBAAgB,qBAqBlB;AAED,eAAO,MAAM,eAAe,qBAAe,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import { PackContext } from "./pack-context";
|
|
3
|
-
import { usePackTrack } from "./pack-analytics";
|
|
4
|
-
import { PreviewToast } from "./preview-toast";
|
|
5
|
-
export function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
|
|
6
|
-
const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
|
|
7
|
-
usePackTrack();
|
|
8
|
-
return (React.createElement(PackContext.Provider, { value: {
|
|
9
|
-
isPreview: !!isPreviewModeEnabled,
|
|
10
|
-
previewStorefrontSettings,
|
|
11
|
-
setPreviewStorefrontSettings,
|
|
12
|
-
siteSettings,
|
|
13
|
-
customizerMeta,
|
|
14
|
-
} },
|
|
15
|
-
children,
|
|
16
|
-
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
|
|
17
|
-
}
|
|
18
|
-
export const PreviewProvider = PackProvider;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview-toast.d.ts","sourceRoot":"","sources":["../../src/pack/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"}
|
|
@@ -1,85 +0,0 @@
|
|
|
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,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
interface PreviewProviderProps {
|
|
3
|
-
customizerMeta?: any;
|
|
4
|
-
isPreviewModeEnabled?: boolean;
|
|
5
|
-
siteSettings?: any;
|
|
6
|
-
location?: Location;
|
|
7
|
-
children: (sections: React.ReactNode) => React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
export declare function PreviewProvider({ customizerMeta, isPreviewModeEnabled, siteSettings, location, children, }: PreviewProviderProps): void;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=preview-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":";AAAA,UAAU,oBAAoB;IAC5B,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC;CAC1D;AAED,wBAAgB,eAAe,CAAC,EAC9B,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,QAAQ,EACR,QAAQ,GACT,EAAE,oBAAoB,QAWtB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function PreviewProvider({ customizerMeta, isPreviewModeEnabled, siteSettings, location, children, }) {
|
|
2
|
-
const { content, storefrontSettings } = useCustomizerShell({
|
|
3
|
-
environment: customizerMeta?.environment,
|
|
4
|
-
isPreview: isPreviewModeEnabled,
|
|
5
|
-
sectionComponents: customizerMeta?.sectionComponents,
|
|
6
|
-
data: customizerMeta,
|
|
7
|
-
storefrontSettingsSchema: siteSettings?.schema,
|
|
8
|
-
location,
|
|
9
|
-
});
|
|
10
|
-
// ... rest of the component remains the same ...
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export declare function useSections({ content }: any): any;
|
|
3
|
-
type RenderSectionProps = {
|
|
4
|
-
pathname?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function RenderSections({ pathname }: RenderSectionProps): React.JSX.Element | null;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=render-sections.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAqFlD,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,OAM3C;AAED,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,4BAM9D"}
|
package/dist/render-sections.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useMemo } from "react";
|
|
2
|
-
import { useMatches } from "@remix-run/react";
|
|
3
|
-
import { useCustomizerShell } from "./use-customizer-shell";
|
|
4
|
-
import { usePreviewContext } from "./preview/preview-content";
|
|
5
|
-
import { sectionMap } from "./register-section";
|
|
6
|
-
import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
7
|
-
import { useOverlayScript } from "./use-overlay-script";
|
|
8
|
-
function Sections({ sections }) {
|
|
9
|
-
const renderedSections = useMemo(() => {
|
|
10
|
-
return sections
|
|
11
|
-
.map((section) => {
|
|
12
|
-
// TODO: Return a consistent data structure from the API and the customizer
|
|
13
|
-
// Normalize section data
|
|
14
|
-
const key = section.id || section.clientId;
|
|
15
|
-
const data = section.data || section;
|
|
16
|
-
// Attach dataSource to the provided cms data
|
|
17
|
-
data.dataSource = section.dataSource;
|
|
18
|
-
const schemaKey = data._template;
|
|
19
|
-
const Component = sectionMap.get(schemaKey);
|
|
20
|
-
if (!Component)
|
|
21
|
-
return null;
|
|
22
|
-
return data?.sectionVisibility === "hidden" ? null : (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key },
|
|
23
|
-
React.createElement(Component, { "comp-name": schemaKey, cms: data })));
|
|
24
|
-
})
|
|
25
|
-
.filter(Boolean);
|
|
26
|
-
}, [sections]);
|
|
27
|
-
return React.createElement(React.Fragment, null, renderedSections);
|
|
28
|
-
}
|
|
29
|
-
function useRenderSections({ content, pathname, }) {
|
|
30
|
-
const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
|
|
31
|
-
const [root] = useMatches();
|
|
32
|
-
const { ENV } = root?.data;
|
|
33
|
-
const { content: liveContent, storefrontSettings } = useCustomizerShell({
|
|
34
|
-
environment: ENV?.PUBLIC_PACK_CONTENT_ENVIRONMENT,
|
|
35
|
-
isPreview,
|
|
36
|
-
sectionComponents: sectionMap,
|
|
37
|
-
data: {
|
|
38
|
-
content,
|
|
39
|
-
template: content.template?.type,
|
|
40
|
-
templateType: content.template?.type,
|
|
41
|
-
handle: content.handle,
|
|
42
|
-
title: content.title,
|
|
43
|
-
description: content.description,
|
|
44
|
-
},
|
|
45
|
-
storefrontSettingsSchema,
|
|
46
|
-
pathname,
|
|
47
|
-
});
|
|
48
|
-
useOverlayScript({ isPreview, overlay: customizerMeta?.overlay || {} });
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
storefrontSettings &&
|
|
51
|
-
setPreviewStorefrontSettings({ settings: storefrontSettings });
|
|
52
|
-
}, [setPreviewStorefrontSettings, storefrontSettings]);
|
|
53
|
-
const sections = useMemo(() => {
|
|
54
|
-
return liveContent?.sections?.nodes || liveContent?.sections;
|
|
55
|
-
}, [liveContent?.sections]);
|
|
56
|
-
return {
|
|
57
|
-
sections,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export function useSections({ content }) {
|
|
61
|
-
const { sections } = useRenderSections({ content });
|
|
62
|
-
if (!sections)
|
|
63
|
-
return null;
|
|
64
|
-
const visibleSections = Sections({ sections });
|
|
65
|
-
return visibleSections?.props?.children || null;
|
|
66
|
-
}
|
|
67
|
-
export function RenderSections({ pathname }) {
|
|
68
|
-
const { content } = usePreviewContext();
|
|
69
|
-
if (!content)
|
|
70
|
-
return null;
|
|
71
|
-
const { sections } = useRenderSections({ content, pathname });
|
|
72
|
-
if (!sections)
|
|
73
|
-
return null;
|
|
74
|
-
return React.createElement(Sections, { sections: sections });
|
|
75
|
-
}
|