@pack/react 0.1.4-ab-test.0 → 1.0.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 CHANGED
@@ -1,9 +1,8 @@
1
- import { RenderSections, useSections } from "./render-sections";
2
- import { PackProvider, PreviewProvider } from "./pack/pack-provider";
3
- import { usePackContext, usePreviewContext } from "./pack/pack-context";
1
+ import { RenderSections, useSections } from "./preview/render-sections";
2
+ import { PreviewProvider, RenderContent, usePreviewContext } from "./preview/preview-content";
4
3
  import { useSiteSettings } from "./use-site-settings";
5
4
  import { useOverlayScript } from "./use-overlay-script";
6
5
  import { registerSection } from "./register-section";
7
6
  import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
8
- export { registerSection, registerStorefrontSettingsSchema, usePackContext, usePreviewContext, useSiteSettings, useOverlayScript, PackProvider, PreviewProvider, RenderSections, useSections, };
7
+ export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxE,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,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,WAAW,GACZ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EACL,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,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,eAAe,EACf,gCAAgC,EAChC,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACZ,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
- import { RenderSections, useSections } from "./render-sections";
2
- import { PackProvider, PreviewProvider } from "./pack/pack-provider";
3
- import { usePackContext, usePreviewContext } from "./pack/pack-context";
1
+ import { RenderSections, useSections } from "./preview/render-sections";
2
+ import { PreviewProvider, RenderContent, usePreviewContext, } from "./preview/preview-content";
4
3
  import { useSiteSettings } from "./use-site-settings";
5
4
  import { useOverlayScript } from "./use-overlay-script";
6
5
  import { registerSection } from "./register-section";
7
6
  import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
8
- export { registerSection, registerStorefrontSettingsSchema, usePackContext, usePreviewContext, useSiteSettings, useOverlayScript, PackProvider, PreviewProvider, RenderSections, useSections, };
7
+ export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-analytics.d.ts","sourceRoot":"","sources":["../../src/preview/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"}
@@ -0,0 +1,65 @@
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
+ }
@@ -0,0 +1,38 @@
1
+ import React, { type ReactNode } from "react";
2
+ type PreviewContextValue = {
3
+ isPreview: boolean;
4
+ customizerMeta?: {
5
+ overlay?: {
6
+ src?: string;
7
+ version?: string;
8
+ };
9
+ [key: string]: any;
10
+ };
11
+ siteSettings: any;
12
+ setSiteSettings: (siteSettings: any) => void;
13
+ content: any;
14
+ setContent: (content: any) => void;
15
+ pathname: string;
16
+ };
17
+ export declare const PreviewContext: React.Context<PreviewContextValue>;
18
+ export declare const usePreviewContext: () => PreviewContextValue;
19
+ interface PreviewProviderProps {
20
+ children: (sections: ReactNode) => ReactNode;
21
+ siteSettings: any;
22
+ pathname: string;
23
+ isPreviewModeEnabled?: boolean;
24
+ customizerMeta?: {
25
+ overlay?: {
26
+ src?: string;
27
+ version?: string;
28
+ };
29
+ [key: string]: any;
30
+ };
31
+ }
32
+ export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, pathname, }: PreviewProviderProps): React.JSX.Element;
33
+ export declare function RenderContent({ content }: {
34
+ content: any;
35
+ }): null;
36
+ export declare function usePackContent(content: any): void;
37
+ export {};
38
+ //# sourceMappingURL=preview-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAMZ,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,OAAO,EAAE,GAAG,CAAC;IACb,UAAU,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,cAAc,oCAQzB,CAAC;AAEH,eAAO,MAAM,iBAAiB,2BAAmC,CAAC;AAElE,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,SAAS,CAAC;IAC7C,YAAY,EAAE,GAAG,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,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,oBAA4B,EAC5B,YAAY,EAAE,yBAAyB,EACvC,cAAc,EACd,QAAQ,GACT,EAAE,oBAAoB,qBAyCtB;AAED,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,QAQ1D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,QAQ1C"}
@@ -0,0 +1,57 @@
1
+ import React, { createContext, useContext, useState, useEffect, useMemo, } from "react";
2
+ import { RenderSections } from "./render-sections";
3
+ import { usePackTrack } from "./pack-analytics";
4
+ import { PreviewToast } from "./preview-toast";
5
+ export const PreviewContext = createContext({
6
+ isPreview: false,
7
+ setSiteSettings: () => { },
8
+ siteSettings: undefined,
9
+ customizerMeta: undefined,
10
+ content: null,
11
+ setContent: () => { },
12
+ pathname: "",
13
+ });
14
+ export const usePreviewContext = () => useContext(PreviewContext);
15
+ export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, pathname, }) {
16
+ const [content, setContent] = useState(null);
17
+ const [siteSettings, setSiteSettings] = useState(previewStorefrontSettings);
18
+ usePackTrack();
19
+ const value = useMemo(() => ({
20
+ isPreview: !!isPreviewModeEnabled,
21
+ customizerMeta,
22
+ siteSettings,
23
+ setSiteSettings,
24
+ content,
25
+ setContent,
26
+ pathname,
27
+ }), [
28
+ isPreviewModeEnabled,
29
+ siteSettings,
30
+ customizerMeta,
31
+ setSiteSettings,
32
+ content,
33
+ pathname,
34
+ ]);
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
+ return (React.createElement(PreviewContext.Provider, { value: value },
41
+ children(sections),
42
+ React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
43
+ }
44
+ export function RenderContent({ content }) {
45
+ const { setContent } = usePreviewContext();
46
+ useEffect(() => {
47
+ setContent(content);
48
+ }, [content, setContent]);
49
+ return null;
50
+ }
51
+ export function usePackContent(content) {
52
+ const context = usePreviewContext();
53
+ useEffect(() => {
54
+ context.setContent(content);
55
+ }, [content, context]);
56
+ return;
57
+ }
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,11 @@
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
+ }
@@ -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
+ };
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ export declare function useSections(): any;
3
+ export declare function RenderSections(): React.JSX.Element | null;
4
+ //# sourceMappingURL=render-sections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AA6DlD,wBAAgB,WAAW,QAM1B;AAED,wBAAgB,cAAc,6BAM7B"}
@@ -0,0 +1,60 @@
1
+ import React, { useMemo } from "react";
2
+ import { useMatches } from "@remix-run/react";
3
+ import { usePreviewContext } from "./preview-content";
4
+ import { sectionMap } from "../register-section";
5
+ import { storefrontSettingsSchema } from "../register-storefront-settings-schema";
6
+ import { useCustomizerShell } from "../use-customizer-shell";
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() {
30
+ const [root] = useMatches();
31
+ const { ENV } = root?.data;
32
+ const { content: liveContent } = useCustomizerShell({
33
+ environment: ENV?.PUBLIC_PACK_CONTENT_ENVIRONMENT,
34
+ sectionComponents: sectionMap,
35
+ storefrontSettingsSchema,
36
+ });
37
+ useOverlayScript();
38
+ const sections = useMemo(() => {
39
+ return liveContent?.sections?.nodes || liveContent?.sections;
40
+ }, [liveContent?.sections]);
41
+ return {
42
+ sections,
43
+ };
44
+ }
45
+ export function useSections() {
46
+ const { sections } = useRenderSections();
47
+ if (!sections)
48
+ return null;
49
+ const visibleSections = Sections({ sections });
50
+ return visibleSections?.props?.children || null;
51
+ }
52
+ export function RenderSections() {
53
+ const { content } = usePreviewContext();
54
+ if (!content)
55
+ return null;
56
+ const { sections } = useRenderSections();
57
+ if (!sections)
58
+ return null;
59
+ return React.createElement(Sections, { sections: sections });
60
+ }
@@ -1,4 +1,8 @@
1
1
  import React from "react";
2
2
  export declare function useSections({ content }: any): any;
3
- export declare function RenderSections({ content }: any): React.JSX.Element | null;
3
+ type RenderSectionProps = {
4
+ pathname?: string;
5
+ };
6
+ export declare function RenderSections({ pathname }: RenderSectionProps): React.JSX.Element | null;
7
+ export {};
4
8
  //# sourceMappingURL=render-sections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AA8ElD,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,OAM3C;AAED,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAI9C"}
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"}
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import { useMatches } from "@remix-run/react";
3
3
  import { useCustomizerShell } from "./use-customizer-shell";
4
- import { usePackContext } from "./pack/pack-context";
4
+ import { usePreviewContext } from "./preview/preview-content";
5
5
  import { sectionMap } from "./register-section";
6
6
  import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
7
7
  import { useOverlayScript } from "./use-overlay-script";
@@ -26,8 +26,8 @@ function Sections({ sections }) {
26
26
  }, [sections]);
27
27
  return React.createElement(React.Fragment, null, renderedSections);
28
28
  }
29
- function useRenderSections({ content }) {
30
- const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePackContext();
29
+ function useRenderSections({ content, pathname, }) {
30
+ const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
31
31
  const [root] = useMatches();
32
32
  const { ENV } = root?.data;
33
33
  const { content: liveContent, storefrontSettings } = useCustomizerShell({
@@ -36,13 +36,14 @@ function useRenderSections({ content }) {
36
36
  sectionComponents: sectionMap,
37
37
  data: {
38
38
  content,
39
- template: content?.template?.type,
40
- templateType: content?.template?.type,
41
- handle: content?.handle,
42
- title: content?.title,
43
- description: content?.description,
39
+ template: content.template?.type,
40
+ templateType: content.template?.type,
41
+ handle: content.handle,
42
+ title: content.title,
43
+ description: content.description,
44
44
  },
45
45
  storefrontSettingsSchema,
46
+ pathname,
46
47
  });
47
48
  useOverlayScript({ isPreview, overlay: customizerMeta?.overlay || {} });
48
49
  useEffect(() => {
@@ -63,8 +64,11 @@ export function useSections({ content }) {
63
64
  const visibleSections = Sections({ sections });
64
65
  return visibleSections?.props?.children || null;
65
66
  }
66
- export function RenderSections({ content }) {
67
- const { sections } = useRenderSections({ content });
67
+ export function RenderSections({ pathname }) {
68
+ const { content } = usePreviewContext();
69
+ if (!content)
70
+ return null;
71
+ const { sections } = useRenderSections({ content, pathname });
68
72
  if (!sections)
69
73
  return null;
70
74
  return React.createElement(Sections, { sections: sections });
@@ -1,5 +1,4 @@
1
- export declare const useCustomizerShell: ({ environment, isPreview, sectionComponents, data, storefrontSettingsSchema, }: any) => {
1
+ export declare const useCustomizerShell: ({ environment, sectionComponents, storefrontSettingsSchema, }: any) => {
2
2
  content: any;
3
- storefrontSettings: any;
4
3
  };
5
4
  //# 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":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAkJL,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAWA,eAAO,MAAM,kBAAkB,kEAI5B,GAAG;;CA4JL,CAAC"}
@@ -1,9 +1,17 @@
1
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
2
2
  import { connectToParent, ErrorCode } from "penpal";
3
- export const useCustomizerShell = ({ environment, isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
3
+ import { PreviewContext } from "./preview/preview-content";
4
+ export const useCustomizerShell = ({ environment, sectionComponents, storefrontSettingsSchema, }) => {
5
+ const { isPreview, content, setContent, setSiteSettings } = useContext(PreviewContext);
6
+ const data = {
7
+ content,
8
+ template: content.template?.type,
9
+ templateType: content.template?.type,
10
+ handle: content.handle,
11
+ title: content.title,
12
+ description: content.description,
13
+ };
4
14
  const windowLocationRef = useRef();
5
- const [content, setContent] = useState(data.content);
6
- const [storefrontSettings, setStorefrontSettings] = useState(null);
7
15
  const [parentConnection, setParentConnection] = useState(null);
8
16
  const [shouldConnectToParent, setShouldConnectToParent] = useState(false);
9
17
  const navigate = (path) => {
@@ -76,7 +84,7 @@ export const useCustomizerShell = ({ environment, isPreview, sectionComponents,
76
84
  setContent(content);
77
85
  },
78
86
  setStorefrontSettings(settings) {
79
- setStorefrontSettings(settings);
87
+ setSiteSettings({ data: { siteSettings: { settings } } });
80
88
  },
81
89
  },
82
90
  });
@@ -117,11 +125,10 @@ export const useCustomizerShell = ({ environment, isPreview, sectionComponents,
117
125
  ]);
118
126
  if (!isPreview) {
119
127
  return {
120
- content: data.content,
121
- storefrontSettings: data.settings?.settings,
128
+ content,
122
129
  };
123
130
  }
124
131
  return useMemo(() => {
125
- return { content, storefrontSettings };
126
- }, [content, storefrontSettings]);
132
+ return { content };
133
+ }, [content]);
127
134
  };
@@ -5,11 +5,5 @@ declare global {
5
5
  };
6
6
  }
7
7
  }
8
- export declare const useOverlayScript: ({ isPreview, overlay, }: {
9
- isPreview: boolean;
10
- overlay: {
11
- src?: string;
12
- version?: string;
13
- };
14
- }) => void;
8
+ export declare const useOverlayScript: () => void;
15
9
  //# sourceMappingURL=use-overlay-script.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"use-overlay-script.d.ts","sourceRoot":"","sources":["../src/use-overlay-script.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE;YACL,uBAAuB,EAAE,OAAO,CAAC;SAClC,CAAC;KACH;CACF;AAED,eAAO,MAAM,gBAAgB,YAsB5B,CAAC"}
@@ -1,5 +1,8 @@
1
1
  import { useEffect } from "react";
2
- export const useOverlayScript = ({ isPreview, overlay, }) => {
2
+ import { usePreviewContext } from "./preview/preview-content";
3
+ export const useOverlayScript = () => {
4
+ const { isPreview, customizerMeta } = usePreviewContext();
5
+ const overlay = customizerMeta?.overlay || {};
3
6
  useEffect(() => {
4
7
  if (isPreview &&
5
8
  (overlay?.src || overlay?.version) &&
@@ -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,CAkBpD,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,CAepD,CAAC"}
@@ -1,6 +1,6 @@
1
- import { usePreviewContext } from "./pack/pack-context";
1
+ import { usePreviewContext } from "./preview/preview-content";
2
2
  export const useSiteSettings = () => {
3
- const { isPreview, previewStorefrontSettings, siteSettings } = usePreviewContext();
3
+ const { siteSettings } = usePreviewContext();
4
4
  let isIframe = false;
5
5
  if (!(typeof document === "undefined")) {
6
6
  isIframe = window.self !== window.top;
@@ -10,7 +10,5 @@ export const useSiteSettings = () => {
10
10
  * in an iFrame we want to show the live customizer
11
11
  * preview data. Else, we show the normal site settings data
12
12
  * */
13
- return isPreview && isIframe
14
- ? previewStorefrontSettings
15
- : siteSettings?.data?.siteSettings;
13
+ return siteSettings?.data?.siteSettings;
16
14
  };
@@ -0,0 +1,2 @@
1
+ export declare const VERSION: string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,EAAE,MAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ export const VERSION = "0.1.4";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.1.4-ab-test.0",
4
+ "version": "1.0.0",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {