@pack/react 0.0.4 → 0.0.6
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":"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":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAkHL,CAAC"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const navigate = useNavigate();
|
|
6
|
-
const location = useLocation();
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { connectToParent } from "penpal";
|
|
3
|
+
export const useCustomizerShell = ({ environment = "production", isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
|
|
4
|
+
const [location, setLocation] = useState();
|
|
7
5
|
const [content, setContent] = useState(data.content);
|
|
8
6
|
const [storefrontSettings, setStorefrontSettings] = useState(null);
|
|
9
7
|
const [parentConnection, setParentConnection] = useState(null);
|
|
8
|
+
const navigate = (path) => {
|
|
9
|
+
window.location.href = path;
|
|
10
|
+
};
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setLocation(window.location);
|
|
13
|
+
}, []);
|
|
10
14
|
const refreshSections = useCallback(() => {
|
|
11
15
|
if (!sectionComponents || !parentConnection)
|
|
12
16
|
return [];
|
|
13
17
|
const sectionSchemas = Array.from(sectionComponents)
|
|
14
18
|
.map(([, section]) => {
|
|
15
|
-
return typeof section.Schema ===
|
|
19
|
+
return typeof section.Schema === "function"
|
|
16
20
|
? section.Schema(data)
|
|
17
21
|
: section.Schema;
|
|
18
22
|
})
|
|
@@ -21,7 +25,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
|
|
|
21
25
|
parentConnection.setSectionsSchemas(JSON.stringify(sectionSchemas));
|
|
22
26
|
}
|
|
23
27
|
catch (error) {
|
|
24
|
-
parentConnection.displayError(
|
|
28
|
+
parentConnection.displayError("Something went wrong parsing sections");
|
|
25
29
|
}
|
|
26
30
|
return;
|
|
27
31
|
}, [data, parentConnection, sectionComponents]);
|
|
@@ -34,7 +38,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
|
|
|
34
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
39
|
}, [data, parentConnection, storefrontSettingsSchema]);
|
|
36
40
|
useEffect(() => {
|
|
37
|
-
if (!isPreview)
|
|
41
|
+
if (!isPreview || !location)
|
|
38
42
|
return;
|
|
39
43
|
const connection = connectToParent({
|
|
40
44
|
methods: {
|
|
@@ -44,7 +48,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
|
|
|
44
48
|
scrollToSection(sectionId) {
|
|
45
49
|
const sectionEl = document.querySelector(`[data-comp-id="${sectionId}"]`);
|
|
46
50
|
if (sectionEl)
|
|
47
|
-
sectionEl.scrollIntoView({ behavior:
|
|
51
|
+
sectionEl.scrollIntoView({ behavior: "smooth" });
|
|
48
52
|
},
|
|
49
53
|
setPageData(content) {
|
|
50
54
|
setContent(content);
|
|
@@ -59,7 +63,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
|
|
|
59
63
|
parent.sendStorefrontSettings();
|
|
60
64
|
parent.setCurrentRoute({
|
|
61
65
|
environment,
|
|
62
|
-
currentPath: location
|
|
66
|
+
currentPath: location?.pathname,
|
|
63
67
|
template,
|
|
64
68
|
templateType,
|
|
65
69
|
handle: content.handle,
|
|
@@ -71,7 +75,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
|
|
|
71
75
|
return () => {
|
|
72
76
|
connection.destroy();
|
|
73
77
|
};
|
|
74
|
-
}, []);
|
|
78
|
+
}, [location]);
|
|
75
79
|
useEffect(() => {
|
|
76
80
|
if (!isPreview)
|
|
77
81
|
return;
|
|
@@ -85,7 +89,10 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
|
|
|
85
89
|
sectionComponents,
|
|
86
90
|
]);
|
|
87
91
|
if (!isPreview) {
|
|
88
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
content: data.content,
|
|
94
|
+
storefrontSettings: data.settings?.settings,
|
|
95
|
+
};
|
|
89
96
|
}
|
|
90
97
|
return { content, storefrontSettings };
|
|
91
98
|
};
|
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.6",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"engines": {
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@remix-run/react": "^1.19.3",
|
|
27
26
|
"@shopify/remix-oxygen": "^1.1.3",
|
|
28
27
|
"@types/react": "^18.2.20",
|
|
29
28
|
"@types/uuid": "^9.0.2",
|