@pack/react 0.1.4 → 2.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 { PreviewProvider } from "./preview/preview-provider";
3
- import { usePreviewContext } from "./preview/preview-content";
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, usePreviewContext, useSiteSettings, useOverlayScript, 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,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,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 { PreviewProvider } from "./preview/preview-provider";
3
- import { usePreviewContext } from "./preview/preview-content";
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, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, useSections, };
7
+ export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
@@ -1,14 +1,16 @@
1
1
  /// <reference types="react" />
2
- type PackContextValue = {
2
+ type PackCustomizerMeta = {
3
+ environment?: string;
4
+ overlay?: {
5
+ src?: string;
6
+ version?: string;
7
+ };
8
+ [key: string]: any;
9
+ };
10
+ export type PackContextValue = {
3
11
  isPreview: boolean;
4
12
  siteSettings: any;
5
- customizerMeta?: {
6
- overlay?: {
7
- src?: string;
8
- version?: string;
9
- };
10
- [key: string]: any;
11
- };
13
+ customizerMeta?: PackCustomizerMeta | null;
12
14
  previewStorefrontSettings?: any;
13
15
  setPreviewStorefrontSettings: (siteSettings: any) => void;
14
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":";AAEA,KAAK,gBAAgB,GAAG;IACtB,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,WAAW,2CAKtB,CAAC;AAEH,eAAO,MAAM,cAAc,wBAAgC,CAAC;AAE5D,eAAO,MAAM,cAAc,2CAAc,CAAC;AAE1C,eAAO,MAAM,iBAAiB,wBAAiB,CAAC"}
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,15 +1,10 @@
1
1
  import React, { ReactNode } from "react";
2
+ import { PackContextValue } from "./pack-context";
2
3
  interface PackContentProps {
3
4
  children: ReactNode;
4
5
  siteSettings: any;
5
6
  isPreviewModeEnabled?: boolean;
6
- customizerMeta?: {
7
- overlay?: {
8
- src?: string;
9
- version?: string;
10
- };
11
- [key: string]: any;
12
- };
7
+ customizerMeta?: PackContextValue["customizerMeta"];
13
8
  }
14
9
  export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PackContentProps): React.JSX.Element;
15
10
  export declare const PreviewProvider: typeof PackProvider;
@@ -1 +1 @@
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;AAKnD,UAAU,gBAAgB;IACxB,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,YAAY,CAAC,EAC3B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,gBAAgB,qBAqBlB;AAED,eAAO,MAAM,eAAe,qBAAe,CAAC"}
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,7 +1,6 @@
1
- /// <reference types="react" />
1
+ import React, { type ReactNode } from "react";
2
2
  type PreviewContextValue = {
3
3
  isPreview: boolean;
4
- siteSettings: any;
5
4
  customizerMeta?: {
6
5
  overlay?: {
7
6
  src?: string;
@@ -9,10 +8,31 @@ type PreviewContextValue = {
9
8
  };
10
9
  [key: string]: any;
11
10
  };
12
- previewStorefrontSettings?: any;
13
- setPreviewStorefrontSettings: (siteSettings: any) => void;
11
+ siteSettings: any;
12
+ setSiteSettings: (siteSettings: any) => void;
13
+ content: any;
14
+ setContent: (content: any) => void;
15
+ pathname: string;
14
16
  };
15
- export declare const PreviewContext: import("react").Context<PreviewContextValue>;
17
+ export declare const PreviewContext: React.Context<PreviewContextValue>;
16
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;
17
37
  export {};
18
38
  //# 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":";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
+ {"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"}
@@ -1,8 +1,57 @@
1
- import { createContext, useContext } from "react";
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";
2
5
  export const PreviewContext = createContext({
3
6
  isPreview: false,
4
- setPreviewStorefrontSettings: () => { },
7
+ setSiteSettings: () => { },
5
8
  siteSettings: undefined,
6
9
  customizerMeta: undefined,
10
+ content: null,
11
+ setContent: () => { },
12
+ pathname: "",
7
13
  });
8
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
+ }
@@ -1,16 +1,11 @@
1
- import React, { ReactNode } from "react";
2
- interface PreviewContentProps {
3
- children: ReactNode;
4
- siteSettings: any;
1
+ /// <reference types="react" />
2
+ interface PreviewProviderProps {
3
+ customizerMeta?: any;
5
4
  isPreviewModeEnabled?: boolean;
6
- customizerMeta?: {
7
- overlay?: {
8
- src?: string;
9
- version?: string;
10
- };
11
- [key: string]: any;
12
- };
5
+ siteSettings?: any;
6
+ location?: Location;
7
+ children: (sections: React.ReactNode) => React.ReactNode;
13
8
  }
14
- export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PreviewContentProps): React.JSX.Element;
9
+ export declare function PreviewProvider({ customizerMeta, isPreviewModeEnabled, siteSettings, location, children, }: PreviewProviderProps): void;
15
10
  export {};
16
11
  //# 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;AAKnD,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,qBAqBrB"}
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,17 +1,11 @@
1
- import React, { useState } from "react";
2
- import { usePackTrack } from "./pack-analytics";
3
- import { PreviewContext } from "./preview-content";
4
- import { PreviewToast } from "./preview-toast";
5
- export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
6
- const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
7
- usePackTrack();
8
- return (React.createElement(PreviewContext.Provider, { value: {
9
- isPreview: !!isPreviewModeEnabled,
10
- previewStorefrontSettings,
11
- setPreviewStorefrontSettings,
12
- siteSettings,
13
- customizerMeta,
14
- } },
15
- children,
16
- React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
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 ...
17
11
  }
@@ -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"}
@@ -26,7 +26,7 @@ function Sections({ sections }) {
26
26
  }, [sections]);
27
27
  return React.createElement(React.Fragment, null, renderedSections);
28
28
  }
29
- function useRenderSections({ content }) {
29
+ function useRenderSections({ content, pathname, }) {
30
30
  const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
31
31
  const [root] = useMatches();
32
32
  const { ENV } = root?.data;
@@ -43,6 +43,7 @@ function useRenderSections({ content }) {
43
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 });
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
@@ -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,5 +1,8 @@
1
- export declare const useCustomizerShell: ({ environment, isPreview, sectionComponents, data, storefrontSettingsSchema, }: any) => {
1
+ export declare const useCustomizerShell: ({ environment, sectionComponents, storefrontSettingsSchema, }: {
2
+ environment: string;
3
+ sectionComponents: any;
4
+ storefrontSettingsSchema?: any;
5
+ }) => {
2
6
  content: any;
3
- storefrontSettings: any;
4
7
  };
5
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":"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":"AAkBA,eAAO,MAAM,kBAAkB;iBAKhB,MAAM;uBACA,GAAG;+BACK,GAAG;;;CAiQ/B,CAAC"}
@@ -1,29 +1,129 @@
1
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
- import { connectToParent, ErrorCode } from "penpal";
3
- export const useCustomizerShell = ({ environment, isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
4
- const windowLocationRef = useRef();
5
- const [content, setContent] = useState(data.content);
6
- const [storefrontSettings, setStorefrontSettings] = useState(null);
7
- const [parentConnection, setParentConnection] = useState(null);
8
- const [shouldConnectToParent, setShouldConnectToParent] = useState(false);
9
- const navigate = (path) => {
10
- window.location.href = path;
1
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
2
+ import { VERSION } from "./version";
3
+ import { PreviewContext } from "./preview/preview-content";
4
+ export const useCustomizerShell = ({ environment, sectionComponents, storefrontSettingsSchema, }) => {
5
+ const { content, isPreview, pathname, 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,
11
13
  };
12
- useEffect(() => {
13
- /*
14
- * Should not try to connect to customizer
15
- * if not in an iframe or not in preview mode
16
- */
17
- const isIframe = window.self !== window.top;
18
- if (!isIframe || !isPreview)
19
- return;
20
- setShouldConnectToParent(true);
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;
21
48
  }, []);
22
49
  useEffect(() => {
23
- windowLocationRef.current = window.location;
24
- }, [data.handle]);
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
+ setContent(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]);
25
125
  const refreshSections = useCallback(() => {
26
- if (!sectionComponents || !parentConnection)
126
+ if (!sectionComponents)
27
127
  return [];
28
128
  const sectionSchemas = Array.from(sectionComponents)
29
129
  .map(([, section]) => {
@@ -33,78 +133,60 @@ export const useCustomizerShell = ({ environment, isPreview, sectionComponents,
33
133
  })
34
134
  .filter(Boolean);
35
135
  try {
36
- parentConnection?.setSectionsSchemas(JSON.stringify(sectionSchemas));
136
+ sendToParent("SET_SECTIONS_SCHEMAS", {
137
+ schema: JSON.stringify(sectionSchemas),
138
+ });
37
139
  }
38
140
  catch (error) {
39
- if (error.code !== ErrorCode.ConnectionDestroyed) {
40
- parentConnection?.displayError("Something went wrong parsing sections");
141
+ if (error.code !== "ConnectionDestroyed") {
142
+ sendToParent("DISPLAY_ERROR", {
143
+ message: "Something went wrong parsing sections",
144
+ });
41
145
  }
42
146
  }
43
147
  return;
44
- }, [data.handle, parentConnection, sectionComponents]);
148
+ }, [data.handle, sectionComponents, sendToParent]);
45
149
  const refreshStorefrontSettingsSchema = useCallback(() => {
46
- if (!storefrontSettingsSchema || !parentConnection || !sectionComponents) {
150
+ if (!storefrontSettingsSchema || !sectionComponents) {
47
151
  return [];
48
152
  }
49
153
  try {
50
- parentConnection.setStorefrontSettingsSchema(JSON.stringify(storefrontSettingsSchema));
154
+ sendToParent("SET_STOREFRONT_SETTINGS_SCHEMA", {
155
+ schema: JSON.stringify(storefrontSettingsSchema),
156
+ });
51
157
  }
52
158
  catch (error) {
53
- if (error.code !== ErrorCode.ConnectionDestroyed) {
54
- parentConnection?.displayError("Something went wrong parsing sections");
159
+ if (error.code !== "ConnectionDestroyed") {
160
+ sendToParent("DISPLAY_ERROR", {
161
+ message: "Something went wrong parsing settings",
162
+ });
55
163
  }
56
164
  }
57
165
  return;
58
166
  // eslint-disable-next-line react-hooks/exhaustive-deps
59
- }, [data.handle, parentConnection, storefrontSettingsSchema]);
167
+ }, [data.handle, sendToParent, storefrontSettingsSchema]);
168
+ // Update the ref whenever pathname changes
169
+ useEffect(() => {
170
+ currentPathRef.current = pathname;
171
+ }, [pathname]);
172
+ // Tell the parent window about the current route
60
173
  useEffect(() => {
61
- if (!isPreview ||
62
- !windowLocationRef.current?.pathname ||
63
- !shouldConnectToParent)
174
+ if (!hasInit || !currentPathRef.current)
64
175
  return;
65
- const connection = connectToParent({
66
- methods: {
67
- routeToPage(path) {
68
- navigate(path);
69
- },
70
- scrollToSection(sectionId) {
71
- const sectionEl = document.querySelector(`[data-comp-id="${sectionId}"]`);
72
- if (sectionEl)
73
- sectionEl.scrollIntoView({ behavior: "smooth" });
74
- },
75
- setPageData(content) {
76
- setContent(content);
77
- },
78
- setStorefrontSettings(settings) {
79
- setStorefrontSettings(settings);
80
- },
81
- },
82
- });
83
- connection.promise.then((parent) => {
84
- const { template, templateType, handle, title, description } = data;
85
- parent.sendStorefrontSettings();
86
- parent.setCurrentRoute({
87
- environment,
88
- currentPath: windowLocationRef.current?.pathname,
89
- template,
90
- templateType,
91
- handle,
92
- title,
93
- description,
94
- });
95
- 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,
96
185
  });
97
- return () => connection.destroy();
98
- }, [
99
- shouldConnectToParent,
100
- data.handle,
101
- data.title,
102
- data.description,
103
- data.template,
104
- data.templateType,
105
- ]);
186
+ }, [hasInit, environment, data.handle, sendToParent]);
187
+ // Refresh sections and storefront settings schema
106
188
  useEffect(() => {
107
- if (!isPreview)
189
+ if (!isPreview || !hasInit)
108
190
  return;
109
191
  refreshSections();
110
192
  refreshStorefrontSettingsSchema();
@@ -114,14 +196,24 @@ export const useCustomizerShell = ({ environment, isPreview, sectionComponents,
114
196
  refreshSections,
115
197
  refreshStorefrontSettingsSchema,
116
198
  sectionComponents,
199
+ hasInit,
117
200
  ]);
118
201
  if (!isPreview) {
119
202
  return {
120
- content: data.content,
121
- storefrontSettings: data.settings?.settings,
203
+ content,
122
204
  };
123
205
  }
124
206
  return useMemo(() => {
125
- return { content, storefrontSettings };
126
- }, [content, storefrontSettings]);
207
+ return { content };
208
+ }, [content]);
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;
127
219
  };
@@ -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
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 = "2.0.0";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.1.4",
4
+ "version": "2.0.0",
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": "npx tsc",
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
  }