@gem-sdk/pages 1.5.7 → 1.5.23
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/cjs/components/ErrorBoundary.js +32 -24
- package/dist/cjs/components/ErrorFallback.js +19 -2
- package/dist/cjs/components/FacebookPixel.js +25 -20
- package/dist/cjs/components/Footer.js +462 -0
- package/dist/cjs/components/GoogleAnalytic.js +49 -23
- package/dist/cjs/components/Header.js +211 -0
- package/dist/cjs/components/TikTokPixel.js +9 -6
- package/dist/cjs/components/builder/Toolbox.js +215 -188
- package/dist/cjs/layouts/main.js +19 -5
- package/dist/cjs/libs/api/get-builder-props.js +26 -24
- package/dist/cjs/libs/api/get-collection-props.js +59 -55
- package/dist/cjs/libs/api/get-home-page-props-v2.js +121 -114
- package/dist/cjs/libs/api/get-home-page-props.js +133 -123
- package/dist/cjs/libs/api/get-preview-props.js +10 -10
- package/dist/cjs/libs/api/get-product-props.js +64 -62
- package/dist/cjs/libs/api/get-static-page-props-preview.js +128 -121
- package/dist/cjs/libs/api/get-static-page-props-v2.js +126 -119
- package/dist/cjs/libs/api/get-static-page-props.js +130 -120
- package/dist/cjs/libs/fetcher.js +59 -63
- package/dist/cjs/libs/get-layout.js +5 -2
- package/dist/cjs/libs/get-storefront-api.js +7 -7
- package/dist/cjs/libs/getStaticPaths.js +5 -5
- package/dist/cjs/libs/google-fonts.js +54 -61
- package/dist/cjs/libs/helpers/gen-css.js +103 -94
- package/dist/cjs/libs/helpers/generate-manifres.js +1 -1
- package/dist/cjs/libs/helpers/get-fallback.js +24 -22
- package/dist/cjs/libs/helpers/normalize.js +82 -80
- package/dist/cjs/libs/helpers/parse-json.js +10 -12
- package/dist/cjs/libs/helpers/user-agent.js +2 -2
- package/dist/cjs/libs/hooks/use-tracking-view.js +36 -31
- package/dist/cjs/libs/parse-html.js +33 -26
- package/dist/cjs/pages/404.js +34 -2
- package/dist/cjs/pages/500.js +63 -8
- package/dist/cjs/pages/builder.js +69 -14
- package/dist/cjs/pages/collection-detail.js +48 -7
- package/dist/cjs/pages/preview.js +18 -12
- package/dist/cjs/pages/product-detail.js +53 -7
- package/dist/cjs/pages/static-v2.js +62 -7
- package/dist/cjs/pages/static.js +60 -6
- package/dist/esm/components/ErrorBoundary.js +32 -24
- package/dist/esm/components/ErrorFallback.js +19 -2
- package/dist/esm/components/FacebookPixel.js +25 -20
- package/dist/esm/components/Footer.js +458 -0
- package/dist/esm/components/GoogleAnalytic.js +49 -23
- package/dist/esm/components/Header.js +207 -0
- package/dist/esm/components/TikTokPixel.js +9 -6
- package/dist/esm/components/builder/Toolbox.js +217 -190
- package/dist/esm/layouts/main.js +19 -5
- package/dist/esm/libs/api/get-builder-props.js +26 -24
- package/dist/esm/libs/api/get-collection-props.js +59 -55
- package/dist/esm/libs/api/get-home-page-props-v2.js +121 -114
- package/dist/esm/libs/api/get-home-page-props.js +133 -123
- package/dist/esm/libs/api/get-preview-props.js +10 -10
- package/dist/esm/libs/api/get-product-props.js +64 -62
- package/dist/esm/libs/api/get-static-page-props-preview.js +128 -121
- package/dist/esm/libs/api/get-static-page-props-v2.js +126 -119
- package/dist/esm/libs/api/get-static-page-props.js +130 -120
- package/dist/esm/libs/fetcher.js +59 -63
- package/dist/esm/libs/get-layout.js +5 -2
- package/dist/esm/libs/get-storefront-api.js +7 -7
- package/dist/esm/libs/getStaticPaths.js +5 -5
- package/dist/esm/libs/google-fonts.js +54 -61
- package/dist/esm/libs/helpers/gen-css.js +103 -94
- package/dist/esm/libs/helpers/generate-manifres.js +1 -1
- package/dist/esm/libs/helpers/get-fallback.js +24 -22
- package/dist/esm/libs/helpers/normalize.js +82 -80
- package/dist/esm/libs/helpers/parse-json.js +10 -12
- package/dist/esm/libs/helpers/user-agent.js +2 -2
- package/dist/esm/libs/hooks/use-tracking-view.js +36 -31
- package/dist/esm/libs/parse-html.js +33 -26
- package/dist/esm/pages/404.js +34 -2
- package/dist/esm/pages/500.js +63 -8
- package/dist/esm/pages/builder.js +69 -14
- package/dist/esm/pages/collection-detail.js +48 -7
- package/dist/esm/pages/preview.js +18 -12
- package/dist/esm/pages/product-detail.js +53 -7
- package/dist/esm/pages/static-v2.js +62 -7
- package/dist/esm/pages/static.js +60 -6
- package/package.json +3 -3
|
@@ -2,199 +2,226 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
var core = require('@gem-sdk/core');
|
|
6
7
|
var react = require('react');
|
|
7
8
|
var googleFonts = require('../../libs/google-fonts.js');
|
|
8
9
|
var genCss = require('../../libs/helpers/gen-css.js');
|
|
9
10
|
var getStorefrontApi = require('../../libs/get-storefront-api.js');
|
|
10
11
|
|
|
11
|
-
const globalStyleId = 'global-style';
|
|
12
|
-
const globalFontId = 'google-font-builder';
|
|
13
|
-
const Toolbox = ()
|
|
14
|
-
const matchMutate = core.useMatchMutate();
|
|
15
|
-
const provider = core.useShopStore((s)
|
|
16
|
-
const changeStorefrontInfo = core.useShopStore((s)
|
|
17
|
-
const initState = core.useBuilderPreviewStore((s)
|
|
18
|
-
const initNormalizeState = core.useBuilderPreviewStore((s)
|
|
19
|
-
const changeItemPropByKey = core.useBuilderPreviewStore((s)
|
|
20
|
-
const addItem = core.useBuilderPreviewStore((s)
|
|
21
|
-
const moveItem = core.useBuilderPreviewStore((s)
|
|
22
|
-
const removeItem = core.useBuilderPreviewStore((s)
|
|
23
|
-
const addSection = core.useSectionStore((s)
|
|
24
|
-
const changeSwatches = core.useShopStore((s)
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
onAddEntity
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
12
|
+
const globalStyleId = 'global-style';
|
|
13
|
+
const globalFontId = 'google-font-builder';
|
|
14
|
+
const Toolbox = ()=>{
|
|
15
|
+
const matchMutate = core.useMatchMutate();
|
|
16
|
+
const provider = core.useShopStore((s)=>s.provider);
|
|
17
|
+
const changeStorefrontInfo = core.useShopStore((s)=>s.changeStorefrontInfo);
|
|
18
|
+
const initState = core.useBuilderPreviewStore((s)=>s.initState);
|
|
19
|
+
const initNormalizeState = core.useBuilderPreviewStore((s)=>s.forceChangeState);
|
|
20
|
+
const changeItemPropByKey = core.useBuilderPreviewStore((s)=>s.changeItemPropByKey);
|
|
21
|
+
const addItem = core.useBuilderPreviewStore((s)=>s.addItem);
|
|
22
|
+
const moveItem = core.useBuilderPreviewStore((s)=>s.moveItem);
|
|
23
|
+
const removeItem = core.useBuilderPreviewStore((s)=>s.removeItem);
|
|
24
|
+
const addSection = core.useSectionStore((s)=>s.addSection);
|
|
25
|
+
const changeSwatches = core.useShopStore((s)=>s.changeSwatches);
|
|
26
|
+
const changeLayoutSettings = core.useShopStore((s)=>s.changeLayoutSettings);
|
|
27
|
+
const [initEventSuccess, setInitEventSuccess] = react.useState(false);
|
|
28
|
+
// Revalidate all query with key match query/
|
|
29
|
+
const onRevalidateQuery = react.useCallback(()=>{
|
|
30
|
+
matchMutate(/query\//);
|
|
31
|
+
}, [
|
|
32
|
+
matchMutate
|
|
33
|
+
]);
|
|
34
|
+
// Update shop info
|
|
35
|
+
const onChangeShopInfo = react.useCallback((e)=>{
|
|
36
|
+
const detail = e.detail;
|
|
37
|
+
changeStorefrontInfo({
|
|
38
|
+
url: detail.shopHandle ? getStorefrontApi.getStorefrontApi(detail.shopHandle, provider) : undefined,
|
|
39
|
+
token: detail.shopToken
|
|
40
|
+
});
|
|
41
|
+
}, [
|
|
42
|
+
changeStorefrontInfo,
|
|
43
|
+
provider
|
|
44
|
+
]);
|
|
45
|
+
const onChangeGlobalStyle = react.useCallback((e)=>{
|
|
46
|
+
const detail = e.detail;
|
|
47
|
+
try {
|
|
48
|
+
if (detail.data) {
|
|
49
|
+
const themeStyle = genCss.genCSS(detail.data, detail.mobileOnly);
|
|
50
|
+
const font = Object.entries(detail.data?.font).map(([, value])=>{
|
|
51
|
+
return value;
|
|
52
|
+
});
|
|
53
|
+
const fontUrl = googleFonts.createFontUrl(font);
|
|
54
|
+
const globalStyle = document.getElementById(globalStyleId);
|
|
55
|
+
const googleFont = document.getElementById(globalFontId);
|
|
56
|
+
if (googleFont) {
|
|
57
|
+
googleFont.getAttribute('href') !== fontUrl && googleFont.setAttribute('href', fontUrl);
|
|
58
|
+
//
|
|
59
|
+
} else {
|
|
60
|
+
const link = document.createElement('link');
|
|
61
|
+
link.id = globalFontId;
|
|
62
|
+
link.href = fontUrl;
|
|
63
|
+
link.rel = 'stylesheet';
|
|
64
|
+
document.head.appendChild(link);
|
|
65
|
+
}
|
|
66
|
+
if (globalStyle) {
|
|
67
|
+
globalStyle.innerHTML = themeStyle;
|
|
68
|
+
} else {
|
|
69
|
+
const style = document.createElement('style');
|
|
70
|
+
style.id = globalStyleId;
|
|
71
|
+
style.innerHTML = themeStyle;
|
|
72
|
+
document.head.appendChild(style);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
//
|
|
77
|
+
}
|
|
78
|
+
}, []);
|
|
79
|
+
// Init builder data
|
|
80
|
+
const onInitBuilder = react.useCallback((e)=>{
|
|
81
|
+
try {
|
|
82
|
+
const detail = e.detail;
|
|
83
|
+
if (detail.data) {
|
|
84
|
+
if (detail.type === 'flat') {
|
|
85
|
+
initNormalizeState(detail.data);
|
|
86
|
+
} else {
|
|
87
|
+
initState(detail.data);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
//
|
|
92
|
+
}
|
|
93
|
+
}, [
|
|
94
|
+
initNormalizeState,
|
|
95
|
+
initState
|
|
96
|
+
]);
|
|
97
|
+
// Add new entity
|
|
98
|
+
const onAddEntity = react.useCallback((e)=>{
|
|
99
|
+
try {
|
|
100
|
+
const detail = e.detail;
|
|
101
|
+
if (detail.entity) {
|
|
102
|
+
addItem({
|
|
103
|
+
data: detail.entity,
|
|
104
|
+
id: detail.id,
|
|
105
|
+
position: detail.position,
|
|
106
|
+
type: detail.type ?? 'component'
|
|
107
|
+
});
|
|
108
|
+
if (detail?.type === 'section' && !Array.isArray(detail.entity)) {
|
|
109
|
+
addSection(detail.entity.uid, detail.entity);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
//
|
|
114
|
+
}
|
|
115
|
+
}, [
|
|
116
|
+
addItem,
|
|
117
|
+
addSection
|
|
118
|
+
]);
|
|
119
|
+
// Update props of entity
|
|
120
|
+
const onUpdateEntityProp = react.useCallback((e)=>{
|
|
121
|
+
try {
|
|
122
|
+
const detail = e.detail;
|
|
123
|
+
if (detail.uid && detail.propName) {
|
|
124
|
+
changeItemPropByKey({
|
|
125
|
+
id: detail.uid,
|
|
126
|
+
key: detail.propName,
|
|
127
|
+
data: detail.propValue,
|
|
128
|
+
group: detail.group
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
} catch {
|
|
132
|
+
//
|
|
133
|
+
}
|
|
134
|
+
}, [
|
|
135
|
+
changeItemPropByKey
|
|
136
|
+
]);
|
|
137
|
+
// Move entity
|
|
138
|
+
const onMoveEntity = react.useCallback((e)=>{
|
|
139
|
+
try {
|
|
140
|
+
const detail = e.detail;
|
|
141
|
+
if (detail.to && detail.uid) {
|
|
142
|
+
moveItem(detail.uid, detail.to, Number(detail.position) ?? 0);
|
|
143
|
+
}
|
|
144
|
+
} catch {
|
|
145
|
+
//
|
|
146
|
+
}
|
|
147
|
+
}, [
|
|
148
|
+
moveItem
|
|
149
|
+
]);
|
|
150
|
+
// Remove entity
|
|
151
|
+
const onRemoveEntity = react.useCallback((e)=>{
|
|
152
|
+
try {
|
|
153
|
+
const detail = e.detail;
|
|
154
|
+
if (detail.uid) {
|
|
155
|
+
removeItem(detail.uid);
|
|
156
|
+
}
|
|
157
|
+
} catch {
|
|
158
|
+
//
|
|
159
|
+
}
|
|
160
|
+
}, [
|
|
161
|
+
removeItem
|
|
162
|
+
]);
|
|
163
|
+
// Change Swatches Data
|
|
164
|
+
const onChangeSwatchesData = react.useCallback((e)=>{
|
|
165
|
+
const detail = e.detail;
|
|
166
|
+
try {
|
|
167
|
+
if (detail.data) {
|
|
168
|
+
changeSwatches(detail.data);
|
|
169
|
+
}
|
|
170
|
+
} catch {
|
|
171
|
+
//
|
|
172
|
+
}
|
|
173
|
+
}, [
|
|
174
|
+
changeSwatches
|
|
175
|
+
]);
|
|
176
|
+
const onChangeLayoutSettingData = react.useCallback((e)=>{
|
|
177
|
+
const detail = e.detail;
|
|
178
|
+
if (!detail) return;
|
|
179
|
+
changeLayoutSettings(detail);
|
|
180
|
+
}, [
|
|
181
|
+
changeLayoutSettings
|
|
182
|
+
]);
|
|
183
|
+
react.useEffect(()=>{
|
|
184
|
+
window.addEventListener('update-shop-info', onChangeShopInfo);
|
|
185
|
+
window.addEventListener('revalidate-query', onRevalidateQuery);
|
|
186
|
+
window.addEventListener('init-builder', onInitBuilder);
|
|
187
|
+
window.addEventListener('add-entity', onAddEntity);
|
|
188
|
+
window.addEventListener('remove-entity', onRemoveEntity);
|
|
189
|
+
window.addEventListener('move-entity', onMoveEntity);
|
|
190
|
+
window.addEventListener('update-entity-prop', onUpdateEntityProp);
|
|
191
|
+
window.addEventListener('set-global-style', onChangeGlobalStyle);
|
|
192
|
+
window.addEventListener('update-global-swatches-data', onChangeSwatchesData);
|
|
193
|
+
window.addEventListener('on-off-header-footer', onChangeLayoutSettingData);
|
|
194
|
+
setInitEventSuccess(true);
|
|
195
|
+
return ()=>{
|
|
196
|
+
window.removeEventListener('update-shop-info', onChangeShopInfo);
|
|
197
|
+
window.removeEventListener('revalidate-query', onRevalidateQuery);
|
|
198
|
+
window.removeEventListener('init-builder', onInitBuilder);
|
|
199
|
+
window.removeEventListener('add-entity', onAddEntity);
|
|
200
|
+
window.removeEventListener('remove-entity', onRemoveEntity);
|
|
201
|
+
window.removeEventListener('move-entity', onMoveEntity);
|
|
202
|
+
window.removeEventListener('update-entity-prop', onUpdateEntityProp);
|
|
203
|
+
window.removeEventListener('set-global-style', onChangeGlobalStyle);
|
|
204
|
+
window.removeEventListener('update-global-swatches-data', onChangeSwatchesData);
|
|
205
|
+
window.addEventListener('on-off-header-footer', onChangeLayoutSettingData);
|
|
206
|
+
};
|
|
207
|
+
}, [
|
|
208
|
+
onAddEntity,
|
|
209
|
+
onUpdateEntityProp,
|
|
210
|
+
onInitBuilder,
|
|
211
|
+
onMoveEntity,
|
|
212
|
+
onRemoveEntity,
|
|
213
|
+
onChangeGlobalStyle,
|
|
214
|
+
onChangeSwatchesData,
|
|
215
|
+
onRevalidateQuery,
|
|
216
|
+
onChangeShopInfo,
|
|
217
|
+
onChangeLayoutSettingData
|
|
218
|
+
]);
|
|
219
|
+
return /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
220
|
+
className: core.cls({
|
|
221
|
+
"toolbox": initEventSuccess
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
var Toolbox$1 = /*#__PURE__*/ react.memo(Toolbox);
|
|
199
226
|
|
|
200
227
|
exports.default = Toolbox$1;
|
package/dist/cjs/layouts/main.js
CHANGED
|
@@ -6,11 +6,25 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var core = require('@gem-sdk/core');
|
|
7
7
|
var parseHtml = require('../libs/parse-html.js');
|
|
8
8
|
|
|
9
|
-
const MainLayout = ({ children, ...props })
|
|
10
|
-
const mobileOnly = core.useShopStore((s)
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const MainLayout = ({ children , ...props })=>{
|
|
10
|
+
const mobileOnly = core.useShopStore((s)=>s.mobileOnly);
|
|
11
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
12
|
+
children: [
|
|
13
|
+
parseHtml.parseHtml(props?.customCodeBody),
|
|
14
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
15
|
+
className: core.cls({
|
|
16
|
+
'max-w-mobile mx-auto w-full': mobileOnly
|
|
17
|
+
}),
|
|
18
|
+
children: children
|
|
19
|
+
}),
|
|
20
|
+
/*#__PURE__*/ jsxRuntime.jsx(core.AddOn, {
|
|
21
|
+
name: "cookie-bar"
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ jsxRuntime.jsx(core.AddOn, {
|
|
24
|
+
name: "cart-drawer"
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
});
|
|
14
28
|
};
|
|
15
29
|
|
|
16
30
|
exports.default = MainLayout;
|
|
@@ -4,30 +4,32 @@ var core = require('@gem-sdk/core');
|
|
|
4
4
|
var adapterShopify = require('@gem-sdk/adapter-shopify');
|
|
5
5
|
var parseJson = require('../helpers/parse-json.js');
|
|
6
6
|
|
|
7
|
-
const getBuilderProps = async (fetcher, shopifyFetcher)
|
|
8
|
-
const [storeProperty, shopifyMeta] = await Promise.allSettled([
|
|
9
|
-
fetcher([
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
const getBuilderProps = async (fetcher, shopifyFetcher)=>{
|
|
8
|
+
const [storeProperty, shopifyMeta] = await Promise.allSettled([
|
|
9
|
+
fetcher([
|
|
10
|
+
core.StorePropertyDocument
|
|
11
|
+
]),
|
|
12
|
+
shopifyFetcher([
|
|
13
|
+
adapterShopify.ShopMetaDocument
|
|
14
|
+
])
|
|
15
|
+
]);
|
|
16
|
+
const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
|
|
17
|
+
const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
|
|
18
|
+
const seo = shopMeta ? {
|
|
19
|
+
titleTemplate: `%s | ${shopMeta.shop.name}`,
|
|
20
|
+
defaultTitle: shopMeta?.shop.name,
|
|
21
|
+
title: 'Preview',
|
|
22
|
+
description: shopMeta?.shop.description
|
|
23
|
+
} : {};
|
|
24
|
+
return parseJson.serializableJson({
|
|
25
|
+
currency: shopMeta?.localization.country.currency.isoCode ?? null,
|
|
26
|
+
locale: shopMeta?.localization.country.isoCode ?? null,
|
|
27
|
+
swatches: parseJson.parseJson(shopData?.storeProperty?.swatchesConfig),
|
|
28
|
+
swr: {
|
|
29
|
+
revalidateOnMount: true
|
|
30
|
+
},
|
|
31
|
+
seo
|
|
32
|
+
});
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
exports.getBuilderProps = getBuilderProps;
|
|
@@ -5,60 +5,64 @@ var genCss = require('../helpers/gen-css.js');
|
|
|
5
5
|
var normalize = require('../helpers/normalize.js');
|
|
6
6
|
var parseJson = require('../helpers/parse-json.js');
|
|
7
7
|
|
|
8
|
-
const getCollectionProps = (fetcher)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
8
|
+
const getCollectionProps = (fetcher)=>async (handle)=>{
|
|
9
|
+
const pageType = 'COLLECTION';
|
|
10
|
+
const variables = {
|
|
11
|
+
slug: handle,
|
|
12
|
+
slugType: pageType
|
|
13
|
+
};
|
|
14
|
+
const [collectionData, theme] = await Promise.all([
|
|
15
|
+
fetcher([
|
|
16
|
+
core.CollectionDocument,
|
|
17
|
+
{
|
|
18
|
+
handle
|
|
19
|
+
}
|
|
20
|
+
]),
|
|
21
|
+
fetcher([
|
|
22
|
+
core.PublishedThemePagesDocument,
|
|
23
|
+
variables
|
|
24
|
+
])
|
|
25
|
+
]);
|
|
26
|
+
const dataBuilder = theme.publishedThemePages?.[0];
|
|
27
|
+
const collectionTemplate = normalize.parseBuilderTemplate(dataBuilder);
|
|
28
|
+
if (!collectionData || !collectionData?.collection || !dataBuilder) {
|
|
29
|
+
throw new Error('Collection not found');
|
|
30
|
+
}
|
|
31
|
+
const { collection } = collectionData;
|
|
32
|
+
const queries = core.prefetchQueries(collectionTemplate);
|
|
33
|
+
const datas = await Promise.allSettled(queries.map(({ query , variables , func })=>{
|
|
34
|
+
if (func) {
|
|
35
|
+
return func(fetcher, variables);
|
|
36
|
+
}
|
|
37
|
+
if (query) return fetcher([
|
|
38
|
+
query,
|
|
39
|
+
variables
|
|
40
|
+
]);
|
|
41
|
+
return {};
|
|
42
|
+
}));
|
|
43
|
+
const fallback = queries.reduce((acc, { key }, index)=>{
|
|
44
|
+
const res = datas[index];
|
|
45
|
+
if (res?.status === 'fulfilled') {
|
|
46
|
+
return {
|
|
47
|
+
...acc,
|
|
48
|
+
[key]: res.value
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return acc;
|
|
52
|
+
}, {});
|
|
53
|
+
return parseJson.serializableJson({
|
|
54
|
+
builderData: collectionTemplate,
|
|
55
|
+
collection,
|
|
56
|
+
pageType,
|
|
57
|
+
themeStyle: genCss.genCSS(dataBuilder.pageStyle?.data),
|
|
58
|
+
swr: {
|
|
59
|
+
fallback
|
|
60
|
+
},
|
|
61
|
+
seo: {
|
|
62
|
+
title: collection.title,
|
|
63
|
+
description: collection.description
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
63
67
|
|
|
64
68
|
exports.getCollectionProps = getCollectionProps;
|