@pack/react 0.0.12 → 0.0.14-canary.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.
|
@@ -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;AAyClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAiC9C"}
|
package/dist/render-sections.js
CHANGED
|
@@ -5,12 +5,15 @@ import { sectionMap } from "./register-section";
|
|
|
5
5
|
import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
6
6
|
function Sections({ sections }) {
|
|
7
7
|
const renderedSections = useMemo(() => {
|
|
8
|
+
console.log('sections', sections);
|
|
8
9
|
return sections
|
|
9
10
|
.map((section) => {
|
|
10
11
|
// TODO: Return a consistent data structure from the API and the customizer
|
|
11
12
|
// Normalize section data
|
|
12
13
|
const key = section.id || section.clientId;
|
|
13
14
|
const data = section.data || section;
|
|
15
|
+
// Attach dataSource to the provided cms data
|
|
16
|
+
data.dataSource = section.dataSource;
|
|
14
17
|
const schemaKey = data._template;
|
|
15
18
|
const Component = sectionMap.get(schemaKey);
|
|
16
19
|
if (!Component)
|
|
@@ -24,6 +27,7 @@ function Sections({ sections }) {
|
|
|
24
27
|
}
|
|
25
28
|
export function RenderSections({ content }) {
|
|
26
29
|
const { isPreview, setPreviewStorefrontSettings } = usePreviewContext();
|
|
30
|
+
console.log('test 123');
|
|
27
31
|
const { content: liveContent, storefrontSettings } = useCustomizerShell({
|
|
28
32
|
environment: "production",
|
|
29
33
|
isPreview,
|
|
@@ -43,6 +47,7 @@ export function RenderSections({ content }) {
|
|
|
43
47
|
setPreviewStorefrontSettings({ settings: storefrontSettings });
|
|
44
48
|
}, [setPreviewStorefrontSettings, storefrontSettings]);
|
|
45
49
|
const sections = useMemo(() => {
|
|
50
|
+
console.log('live content', liveContent?.sections?.nodes || liveContent?.sections);
|
|
46
51
|
return liveContent?.sections?.nodes || liveContent?.sections;
|
|
47
52
|
}, [liveContent?.sections]);
|
|
48
53
|
if (!sections)
|
|
@@ -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;;;
|
|
1
|
+
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAkIL,CAAC"}
|
|
@@ -5,9 +5,16 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
|
|
|
5
5
|
const [content, setContent] = useState(data.content);
|
|
6
6
|
const [storefrontSettings, setStorefrontSettings] = useState(null);
|
|
7
7
|
const [parentConnection, setParentConnection] = useState(null);
|
|
8
|
+
const [shouldConnectToParent, setShouldConnectToParent] = useState(false);
|
|
8
9
|
const navigate = (path) => {
|
|
9
10
|
window.location.href = path;
|
|
10
11
|
};
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const isIframe = window.self !== window.top;
|
|
14
|
+
if (!isIframe)
|
|
15
|
+
return;
|
|
16
|
+
setShouldConnectToParent(true);
|
|
17
|
+
}, []);
|
|
11
18
|
useEffect(() => {
|
|
12
19
|
setLocation(window.location);
|
|
13
20
|
}, [data.handle]);
|
|
@@ -47,7 +54,7 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
|
|
|
47
54
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
55
|
}, [data.handle, parentConnection, storefrontSettingsSchema]);
|
|
49
56
|
useEffect(() => {
|
|
50
|
-
if (!isPreview || !location?.pathname)
|
|
57
|
+
if (!isPreview || !location?.pathname || !shouldConnectToParent)
|
|
51
58
|
return;
|
|
52
59
|
const connection = connectToParent({
|
|
53
60
|
methods: {
|
|
@@ -86,6 +93,7 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
|
|
|
86
93
|
useEffect(() => {
|
|
87
94
|
if (!isPreview)
|
|
88
95
|
return;
|
|
96
|
+
console.log('refreshing sections');
|
|
89
97
|
refreshSections();
|
|
90
98
|
refreshStorefrontSettingsSchema();
|
|
91
99
|
}, [
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pack/react",
|
|
3
3
|
"description": "React",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.14-canary.0",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"engines": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@shopify/remix-oxygen": "^1.1.3",
|
|
26
25
|
"@types/react": "^18.2.20",
|
|
27
26
|
"react": "^18.2.0",
|
|
28
27
|
"react-dom": "^18.2.0"
|