@pack/react 0.1.4 → 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 +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/pack/pack-context.d.ts +10 -8
- package/dist/pack/pack-context.d.ts.map +1 -1
- package/dist/pack/pack-provider.d.ts +2 -7
- package/dist/pack/pack-provider.d.ts.map +1 -1
- package/dist/preview/preview-content.d.ts +25 -5
- package/dist/preview/preview-content.d.ts.map +1 -1
- package/dist/preview/preview-content.js +51 -2
- package/dist/preview/preview-provider.d.ts +7 -12
- package/dist/preview/preview-provider.d.ts.map +1 -1
- package/dist/preview/preview-provider.js +10 -16
- package/dist/preview/render-sections.d.ts +4 -0
- package/dist/preview/render-sections.d.ts.map +1 -0
- package/dist/preview/render-sections.js +60 -0
- package/dist/render-sections.d.ts +5 -1
- package/dist/render-sections.d.ts.map +1 -1
- package/dist/render-sections.js +7 -3
- package/dist/use-customizer-shell.d.ts +1 -2
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +16 -9
- package/dist/use-overlay-script.d.ts +1 -7
- package/dist/use-overlay-script.d.ts.map +1 -1
- package/dist/use-overlay-script.js +4 -1
- package/dist/use-site-settings.d.ts.map +1 -1
- package/dist/use-site-settings.js +2 -4
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { RenderSections, useSections } from "./render-sections";
|
|
2
|
-
import { PreviewProvider } from "./preview/preview-
|
|
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,
|
|
7
|
+
export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,
|
|
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-
|
|
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,
|
|
7
|
+
export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
type
|
|
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,
|
|
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;
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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:
|
|
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":";
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
interface
|
|
3
|
-
|
|
4
|
-
siteSettings: any;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface PreviewProviderProps {
|
|
3
|
+
customizerMeta?: any;
|
|
5
4
|
isPreviewModeEnabled?: boolean;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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({
|
|
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,
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 @@
|
|
|
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
|
-
|
|
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;
|
|
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
CHANGED
|
@@ -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({
|
|
67
|
-
const {
|
|
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,
|
|
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":"
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
121
|
-
storefrontSettings: data.settings?.settings,
|
|
128
|
+
content,
|
|
122
129
|
};
|
|
123
130
|
}
|
|
124
131
|
return useMemo(() => {
|
|
125
|
-
return { content
|
|
126
|
-
}, [content
|
|
132
|
+
return { content };
|
|
133
|
+
}, [content]);
|
|
127
134
|
};
|
|
@@ -5,11 +5,5 @@ declare global {
|
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
export declare const useOverlayScript: (
|
|
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":"
|
|
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
|
-
|
|
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,
|
|
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 {
|
|
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
|
|
14
|
-
? previewStorefrontSettings
|
|
15
|
-
: siteSettings?.data?.siteSettings;
|
|
13
|
+
return siteSettings?.data?.siteSettings;
|
|
16
14
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,EAAE,MAAgB,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "0.1.4";
|