@pack/react 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/preview/preview-content.d.ts +3 -9
- package/dist/preview/preview-content.d.ts.map +1 -1
- package/dist/preview/preview-content.js +18 -33
- package/dist/preview/preview-toast.js +1 -1
- package/dist/preview/render-sections.d.ts.map +1 -1
- package/dist/preview/render-sections.js +8 -17
- package/dist/register-section.js +1 -1
- package/dist/use-customizer-shell.d.ts +1 -7
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +17 -22
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RenderSections, useSections } from "./preview/render-sections";
|
|
2
|
-
import { PreviewProvider,
|
|
2
|
+
import { PreviewProvider, usePreviewContext } from "./preview/preview-content";
|
|
3
3
|
import { useSiteSettings } from "./use-site-settings";
|
|
4
4
|
import { useOverlayScript } from "./use-overlay-script";
|
|
5
5
|
import { registerSection } from "./register-section";
|
|
6
6
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
7
|
-
export { PreviewProvider,
|
|
7
|
+
export { PreviewProvider, RenderSections, registerSection, registerStorefrontSettingsSchema, useOverlayScript, usePreviewContext, useSections, useSiteSettings, };
|
|
8
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,2BAA2B,CAAC;AACxE,OAAO,
|
|
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,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,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,cAAc,EACd,eAAe,EACf,gCAAgC,EAChC,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,eAAe,GAChB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RenderSections, useSections } from "./preview/render-sections";
|
|
2
|
-
import { PreviewProvider,
|
|
2
|
+
import { PreviewProvider, usePreviewContext } from "./preview/preview-content";
|
|
3
3
|
import { useSiteSettings } from "./use-site-settings";
|
|
4
4
|
import { useOverlayScript } from "./use-overlay-script";
|
|
5
5
|
import { registerSection } from "./register-section";
|
|
6
6
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
7
|
-
export { PreviewProvider,
|
|
7
|
+
export { PreviewProvider, RenderSections, registerSection, registerStorefrontSettingsSchema, useOverlayScript, usePreviewContext, useSections, useSiteSettings, };
|
|
@@ -10,9 +10,8 @@ type PreviewContextValue = {
|
|
|
10
10
|
};
|
|
11
11
|
siteSettings: any;
|
|
12
12
|
setSiteSettings: (siteSettings: any) => void;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
pathname: string;
|
|
13
|
+
liveContent: any;
|
|
14
|
+
setLiveContent: (content: any) => void;
|
|
16
15
|
contentEnvironment: string;
|
|
17
16
|
};
|
|
18
17
|
export declare const PreviewContext: React.Context<PreviewContextValue>;
|
|
@@ -20,7 +19,6 @@ export declare const usePreviewContext: () => PreviewContextValue;
|
|
|
20
19
|
interface PreviewProviderProps {
|
|
21
20
|
children: ReactNode;
|
|
22
21
|
siteSettings: any;
|
|
23
|
-
pathname: string;
|
|
24
22
|
isPreviewModeEnabled?: boolean;
|
|
25
23
|
contentEnvironment?: string;
|
|
26
24
|
customizerMeta?: {
|
|
@@ -31,10 +29,6 @@ interface PreviewProviderProps {
|
|
|
31
29
|
[key: string]: any;
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
|
-
export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta,
|
|
35
|
-
export declare function RenderContent({ content }: {
|
|
36
|
-
content: any;
|
|
37
|
-
}): React.JSX.Element;
|
|
38
|
-
export declare function usePackContent(content: any): void;
|
|
32
|
+
export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment, }: PreviewProviderProps): React.JSX.Element;
|
|
39
33
|
export {};
|
|
40
34
|
//# sourceMappingURL=preview-content.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAOf,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,WAAW,EAAE,GAAG,CAAC;IACjB,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACvC,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,cAAc,oCAQzB,CAAC;AAEH,eAAO,MAAM,iBAAiB,2BAAmC,CAAC;AAElE,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAUD,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAA4B,EAC5B,YAAY,EAAE,yBAAyB,EACvC,cAAc,EACd,kBAAuB,GACxB,EAAE,oBAAoB,qBAmCtB"}
|
|
@@ -1,62 +1,47 @@
|
|
|
1
1
|
import React, { createContext, useContext, useState, useMemo, } from "react";
|
|
2
|
-
import { RenderSections } from "./render-sections";
|
|
3
2
|
import { usePackTrack } from "./pack-analytics";
|
|
4
3
|
import { PreviewToast } from "./preview-toast";
|
|
4
|
+
import { useCustomizerShell } from "../use-customizer-shell";
|
|
5
|
+
import { useOverlayScript } from "../use-overlay-script";
|
|
5
6
|
export const PreviewContext = createContext({
|
|
6
7
|
isPreview: false,
|
|
7
8
|
setSiteSettings: () => { },
|
|
8
9
|
siteSettings: undefined,
|
|
9
10
|
customizerMeta: undefined,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pathname: "",
|
|
11
|
+
liveContent: null,
|
|
12
|
+
setLiveContent: () => { },
|
|
13
13
|
contentEnvironment: "",
|
|
14
14
|
});
|
|
15
15
|
export const usePreviewContext = () => useContext(PreviewContext);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const CustomizerShell = () => {
|
|
17
|
+
// Render inside the PreviewProvider so useCustomizerShell
|
|
18
|
+
// and useOverlayScript can access the context
|
|
19
|
+
useCustomizerShell();
|
|
20
|
+
useOverlayScript();
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment = "", }) {
|
|
24
|
+
const [liveContent, setLiveContent] = useState(null);
|
|
18
25
|
const [siteSettings, setSiteSettings] = useState(previewStorefrontSettings);
|
|
19
|
-
usePackTrack();
|
|
20
26
|
const value = useMemo(() => ({
|
|
21
27
|
isPreview: !!isPreviewModeEnabled,
|
|
22
28
|
customizerMeta,
|
|
23
29
|
siteSettings,
|
|
24
30
|
setSiteSettings,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pathname,
|
|
31
|
+
liveContent,
|
|
32
|
+
setLiveContent,
|
|
28
33
|
contentEnvironment,
|
|
29
34
|
}), [
|
|
30
35
|
isPreviewModeEnabled,
|
|
31
36
|
siteSettings,
|
|
32
37
|
customizerMeta,
|
|
33
38
|
setSiteSettings,
|
|
34
|
-
|
|
35
|
-
pathname,
|
|
39
|
+
liveContent,
|
|
36
40
|
contentEnvironment,
|
|
37
41
|
]);
|
|
42
|
+
usePackTrack();
|
|
38
43
|
return (React.createElement(PreviewContext.Provider, { value: value },
|
|
44
|
+
React.createElement(CustomizerShell, null),
|
|
39
45
|
children,
|
|
40
46
|
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
|
|
41
47
|
}
|
|
42
|
-
export function RenderContent({ content }) {
|
|
43
|
-
const { isPreview, setPreviewContent } = usePreviewContext();
|
|
44
|
-
// Update content in context for preview mode
|
|
45
|
-
useMemo(() => {
|
|
46
|
-
setPreviewContent(content);
|
|
47
|
-
}, [content, setPreviewContent]);
|
|
48
|
-
// If in preview mode, RenderSections will handle rendering with live content
|
|
49
|
-
if (isPreview) {
|
|
50
|
-
return React.createElement(RenderSections, null);
|
|
51
|
-
}
|
|
52
|
-
// For SSR, pass the content directly
|
|
53
|
-
return React.createElement(RenderSections, { content: content });
|
|
54
|
-
}
|
|
55
|
-
export function usePackContent(content) {
|
|
56
|
-
const { setPreviewContent } = usePreviewContext();
|
|
57
|
-
// Update preview content
|
|
58
|
-
useMemo(() => {
|
|
59
|
-
setPreviewContent(content);
|
|
60
|
-
}, [content, setPreviewContent]);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
@@ -14,7 +14,7 @@ export const PreviewToast = ({ isPreviewModeEnabled }) => {
|
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
16
|
if (!response.ok) {
|
|
17
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
17
|
+
throw new Error(`ERR_RE_API_ERROR: HTTP error! Status: ${response.status} Doc: https://docs.packdigital.com/err/ERR_RE_API_ERROR`);
|
|
18
18
|
}
|
|
19
19
|
window.location.reload();
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAiCvC,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAiBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,OAMrD"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import { usePreviewContext } from "./preview-content";
|
|
3
3
|
import { sectionMap } from "../register-section";
|
|
4
|
-
import { storefrontSettingsSchema } from "../register-storefront-settings-schema";
|
|
5
|
-
import { useCustomizerShell } from "../use-customizer-shell";
|
|
6
|
-
import { useOverlayScript } from "../use-overlay-script";
|
|
7
4
|
function Sections({ sections }) {
|
|
8
5
|
const renderedSections = useMemo(() => {
|
|
9
6
|
return sections
|
|
@@ -25,25 +22,19 @@ function Sections({ sections }) {
|
|
|
25
22
|
}, [sections]);
|
|
26
23
|
return React.createElement(React.Fragment, null, renderedSections);
|
|
27
24
|
}
|
|
28
|
-
function useRenderSections({ content
|
|
29
|
-
const {
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
return liveContent?.sections?.nodes || liveContent?.sections;
|
|
38
|
-
}
|
|
39
|
-
// For SSR and non-preview mode, use the passed in content
|
|
40
|
-
const contentToRender = ssrContent || previewContent;
|
|
25
|
+
function useRenderSections({ content }) {
|
|
26
|
+
const { isPreview, liveContent, setLiveContent } = usePreviewContext();
|
|
27
|
+
// Update content in context for preview mode
|
|
28
|
+
useMemo(() => {
|
|
29
|
+
isPreview && setLiveContent(content);
|
|
30
|
+
}, [content, isPreview, setLiveContent]);
|
|
31
|
+
// For SSR, use the passed in content
|
|
32
|
+
const contentToRender = liveContent || content;
|
|
41
33
|
if (!contentToRender)
|
|
42
34
|
return null;
|
|
43
35
|
return contentToRender?.sections?.nodes || contentToRender?.sections;
|
|
44
36
|
}
|
|
45
37
|
export function RenderSections(props) {
|
|
46
|
-
useOverlayScript();
|
|
47
38
|
const sections = useRenderSections(props);
|
|
48
39
|
if (!sections)
|
|
49
40
|
return null;
|
package/dist/register-section.js
CHANGED
|
@@ -2,7 +2,7 @@ import { SectionObjectSchema } from "@pack/types";
|
|
|
2
2
|
export const sectionMap = new Map();
|
|
3
3
|
export function registerSection(section, config) {
|
|
4
4
|
if (typeof section !== "function") {
|
|
5
|
-
throw new Error(`The section "${config.name}" is not a valid React component
|
|
5
|
+
throw new Error(`ERR_RE_RENDER_SECTION: The section "${config.name}" is not a valid React component. Doc: https://docs.packdigital.com/err/ERR_RE_RENDER_SECTION`);
|
|
6
6
|
}
|
|
7
7
|
if (!section.Schema) {
|
|
8
8
|
throw new Error(`The section "${config.name}" does not have a valid schema.`);
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export declare const useCustomizerShell: (
|
|
2
|
-
environment: string;
|
|
3
|
-
sectionComponents: any;
|
|
4
|
-
storefrontSettingsSchema?: any;
|
|
5
|
-
}) => {
|
|
6
|
-
content: any;
|
|
7
|
-
};
|
|
1
|
+
export declare const useCustomizerShell: () => void;
|
|
8
2
|
//# 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":"AAoBA,eAAO,MAAM,kBAAkB,YAgQ9B,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { useCallback, useContext, useEffect,
|
|
1
|
+
import { useCallback, useContext, useEffect, useRef, useState, } from "react";
|
|
2
2
|
import { VERSION } from "./version";
|
|
3
3
|
import { PreviewContext } from "./preview/preview-content";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { sectionMap as sectionComponents } from "./register-section";
|
|
5
|
+
import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
6
|
+
export const useCustomizerShell = () => {
|
|
7
|
+
const { contentEnvironment: environment, isPreview, liveContent, setLiveContent, setSiteSettings, } = useContext(PreviewContext);
|
|
6
8
|
const data = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
description: previewContent?.description,
|
|
9
|
+
template: liveContent?.template?.type,
|
|
10
|
+
templateType: liveContent?.template?.type,
|
|
11
|
+
handle: liveContent?.handle,
|
|
12
|
+
title: liveContent?.title,
|
|
13
|
+
description: liveContent?.description,
|
|
13
14
|
};
|
|
14
15
|
const [hasInit, setHasInit] = useState(false);
|
|
15
16
|
const pendingMessagesRef = useRef(new Map());
|
|
@@ -95,7 +96,7 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
|
|
|
95
96
|
}
|
|
96
97
|
break;
|
|
97
98
|
case "SET_PAGE_DATA":
|
|
98
|
-
|
|
99
|
+
setLiveContent(message.pack.data?.content);
|
|
99
100
|
break;
|
|
100
101
|
case "SET_STOREFRONT_SETTINGS":
|
|
101
102
|
setSiteSettings({
|
|
@@ -167,13 +168,15 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
|
|
|
167
168
|
}, [data.handle, sendToParent, storefrontSettingsSchema]);
|
|
168
169
|
// Update the ref whenever pathname changes
|
|
169
170
|
useEffect(() => {
|
|
170
|
-
currentPathRef.current = pathname;
|
|
171
|
-
}, [
|
|
171
|
+
currentPathRef.current = window.location.pathname;
|
|
172
|
+
}, [data.handle]);
|
|
172
173
|
// Tell the parent window about the current route
|
|
173
174
|
useEffect(() => {
|
|
174
|
-
if (!hasInit || !currentPathRef.current)
|
|
175
|
-
return;
|
|
176
175
|
const { template, templateType, handle, title, description } = data;
|
|
176
|
+
if (!hasInit ||
|
|
177
|
+
!currentPathRef.current ||
|
|
178
|
+
(!template && !templateType && !handle && !title && !description))
|
|
179
|
+
return;
|
|
177
180
|
sendToParent("SET_CURRENT_ROUTE", {
|
|
178
181
|
environment,
|
|
179
182
|
currentPath: currentPathRef.current,
|
|
@@ -198,14 +201,6 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
|
|
|
198
201
|
sectionComponents,
|
|
199
202
|
hasInit,
|
|
200
203
|
]);
|
|
201
|
-
if (!isPreview) {
|
|
202
|
-
return {
|
|
203
|
-
content: previewContent,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return useMemo(() => {
|
|
207
|
-
return { content: previewContent };
|
|
208
|
-
}, [previewContent]);
|
|
209
204
|
};
|
|
210
205
|
const useCanConnectCheck = ({ isPreview }) => {
|
|
211
206
|
const [canConnect, setCanConnect] = useState(false);
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.1.
|
|
1
|
+
export const VERSION = "2.1.2";
|