@gem-sdk/pages 1.56.0 → 1.57.0-dev.53
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/builder/Body.js +38 -0
- package/dist/cjs/components/builder/Footer.js +2 -2
- package/dist/cjs/components/builder/Header.js +4 -1
- package/dist/cjs/components/builder/InteractionSelectOnPageHeader.js +191 -0
- package/dist/cjs/components/builder/SwitchView.js +1 -0
- package/dist/cjs/components/builder/Toolbar.js +130 -340
- package/dist/cjs/components/builder/Toolbox.js +69 -2
- package/dist/cjs/components/builder/toolbar/const.js +7 -0
- package/dist/cjs/components/builder/toolbar/utils/findDOMClosest.js +41 -0
- package/dist/cjs/components/builder/toolbar/utils/findOverflowParent.js +20 -0
- package/dist/cjs/components/builder/toolbar/utils/getChildrenByAttrSelector.js +18 -0
- package/dist/cjs/components/builder/toolbar/utils/getDOMElementParents.js +32 -0
- package/dist/cjs/components/builder/toolbar/utils/isOverParent.js +16 -0
- package/dist/cjs/components/builder/toolbar/utils/isOverToolbarPosition.js +12 -0
- package/dist/cjs/components/builder/toolbar/utils/isSection.js +8 -0
- package/dist/cjs/components/builder/toolbar/utils/notVisible.js +8 -0
- package/dist/cjs/components/builder/toolbar/utils/waitForElementToExist.js +27 -0
- package/dist/cjs/components/image-to-layout/DropElement.js +2 -0
- package/dist/cjs/libs/api/get-static-page-props-v2.js +15 -4
- package/dist/cjs/libs/google-fonts.js +20 -11
- package/dist/cjs/libs/helpers/check-option-font.js +65 -0
- package/dist/cjs/pages/builder.js +4 -11
- package/dist/cjs/pages/static-v2.js +18 -5
- package/dist/cjs/store/libs-store.js +14 -0
- package/dist/esm/components/builder/Body.js +34 -0
- package/dist/esm/components/builder/Footer.js +2 -2
- package/dist/esm/components/builder/Header.js +5 -2
- package/dist/esm/components/builder/InteractionSelectOnPageHeader.js +187 -0
- package/dist/esm/components/builder/SwitchView.js +1 -0
- package/dist/esm/components/builder/Toolbar.js +102 -312
- package/dist/esm/components/builder/Toolbox.js +69 -2
- package/dist/esm/components/builder/toolbar/const.js +4 -0
- package/dist/esm/components/builder/toolbar/utils/findDOMClosest.js +39 -0
- package/dist/esm/components/builder/toolbar/utils/findOverflowParent.js +18 -0
- package/dist/esm/components/builder/toolbar/utils/getChildrenByAttrSelector.js +16 -0
- package/dist/esm/components/builder/toolbar/utils/getDOMElementParents.js +30 -0
- package/dist/esm/components/builder/toolbar/utils/isOverParent.js +14 -0
- package/dist/esm/components/builder/toolbar/utils/isOverToolbarPosition.js +10 -0
- package/dist/esm/components/builder/toolbar/utils/isSection.js +6 -0
- package/dist/esm/components/builder/toolbar/utils/notVisible.js +6 -0
- package/dist/esm/components/builder/toolbar/utils/waitForElementToExist.js +25 -0
- package/dist/esm/components/image-to-layout/DropElement.js +2 -0
- package/dist/esm/libs/api/get-static-page-props-v2.js +16 -5
- package/dist/esm/libs/google-fonts.js +20 -11
- package/dist/esm/libs/helpers/check-option-font.js +63 -0
- package/dist/esm/pages/builder.js +5 -12
- package/dist/esm/pages/static-v2.js +18 -5
- package/dist/esm/store/libs-store.js +12 -0
- package/dist/types/index.d.ts +6 -3
- package/package.json +5 -5
- package/dist/cjs/components/builder/toolbar/Onboarding.js +0 -110
- package/dist/esm/components/builder/toolbar/Onboarding.js +0 -106
|
@@ -6,6 +6,8 @@ import { createFontUrl } from '../../libs/google-fonts.js';
|
|
|
6
6
|
import { genCSS } from '../../libs/helpers/gen-css.js';
|
|
7
7
|
import { getFontsFromDataBuilder } from '../../libs/helpers/gen-fonts.js';
|
|
8
8
|
import { shopifyCdnWithGoogleFonts } from '../../libs/shopify-cdn-with-google-fonts.js';
|
|
9
|
+
import { libsStore } from '../../store/libs-store.js';
|
|
10
|
+
import { checkNotInOptionFont } from '../../libs/helpers/check-option-font.js';
|
|
9
11
|
|
|
10
12
|
const globalStyleId = 'global-style';
|
|
11
13
|
const Toolbox = ()=>{
|
|
@@ -31,8 +33,15 @@ const Toolbox = ()=>{
|
|
|
31
33
|
const changeLayoutSettings = useShopStore((s)=>s.changeLayoutSettings);
|
|
32
34
|
const changeCreateThemeSectionCount = useShopStore((s)=>s.changeCreateThemeSectionCount);
|
|
33
35
|
const changeShopPlan = useShopStore((s)=>s.changeShopPlan);
|
|
36
|
+
const changeFontType = libsStore((s)=>s.changeFontType);
|
|
37
|
+
const fontType = libsStore((s)=>s.fontType);
|
|
34
38
|
const clearModal = useModalStore((s)=>s.clearModal);
|
|
35
39
|
const changeLimitCreateThemeSection = useShopStore((s)=>s.changeLimitCreateThemeSection);
|
|
40
|
+
const setInteractionIsSelectOnPage = usePageStore((s)=>s.setInteractionIsSelectOnPage);
|
|
41
|
+
const setInteractionItem = usePageStore((s)=>s.setInteractionItem);
|
|
42
|
+
const setInteractionSelectType = usePageStore((s)=>s.setInteractionSelectType);
|
|
43
|
+
const setInteractionSettingType = usePageStore((s)=>s.setInteractionSettingType);
|
|
44
|
+
const setSidebarMode = usePageStore((s)=>s.setSidebarMode);
|
|
36
45
|
const fonts = useMemo(()=>getFontsFromDataBuilder(state), [
|
|
37
46
|
state
|
|
38
47
|
]);
|
|
@@ -61,6 +70,12 @@ const Toolbox = ()=>{
|
|
|
61
70
|
});
|
|
62
71
|
// append new fonts
|
|
63
72
|
for (const font of fonts){
|
|
73
|
+
if ([
|
|
74
|
+
'bunny',
|
|
75
|
+
'google'
|
|
76
|
+
].includes(font.type) && checkNotInOptionFont(font.family, fontType)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
64
79
|
if (font.type !== 'custom') {
|
|
65
80
|
if (font.variants?.length) {
|
|
66
81
|
for (const variant of font.variants){
|
|
@@ -72,7 +87,7 @@ const Toolbox = ()=>{
|
|
|
72
87
|
const variantName = variant;
|
|
73
88
|
const url = createFontUrl([
|
|
74
89
|
cloneFont
|
|
75
|
-
]);
|
|
90
|
+
], undefined, fontType);
|
|
76
91
|
if (url) {
|
|
77
92
|
const googleFont = document.querySelector(`.${className}[data-font="${fontName}"][data-font-variant="${variantName}"]`);
|
|
78
93
|
if (googleFont) {
|
|
@@ -275,6 +290,13 @@ const Toolbox = ()=>{
|
|
|
275
290
|
}, [
|
|
276
291
|
changeShopPlan
|
|
277
292
|
]);
|
|
293
|
+
const onUpdateFontType = useCallback((e)=>{
|
|
294
|
+
const fontType = e.detail;
|
|
295
|
+
if (!fontType) return;
|
|
296
|
+
changeFontType(fontType);
|
|
297
|
+
}, [
|
|
298
|
+
changeFontType
|
|
299
|
+
]);
|
|
278
300
|
const onUpdateDynamicProduct = useCallback((e)=>{
|
|
279
301
|
const product = e.detail;
|
|
280
302
|
if (!product) return;
|
|
@@ -333,6 +355,37 @@ const Toolbox = ()=>{
|
|
|
333
355
|
}, [
|
|
334
356
|
changeLimitCreateThemeSection
|
|
335
357
|
]);
|
|
358
|
+
const onUpdateInteractionIsSelectOnPage = useCallback((e)=>{
|
|
359
|
+
const isSelectOnPage = e.detail.value;
|
|
360
|
+
const mode = e.detail.mode;
|
|
361
|
+
const settingType = e.detail.settingType;
|
|
362
|
+
setInteractionIsSelectOnPage(isSelectOnPage);
|
|
363
|
+
setInteractionSelectType(mode);
|
|
364
|
+
setInteractionSettingType(settingType);
|
|
365
|
+
}, [
|
|
366
|
+
setInteractionIsSelectOnPage,
|
|
367
|
+
setInteractionSelectType,
|
|
368
|
+
setInteractionSettingType
|
|
369
|
+
]);
|
|
370
|
+
const onUpdateInteractionSettingType = useCallback((e)=>{
|
|
371
|
+
const settingType = e.detail.settingType;
|
|
372
|
+
setInteractionSettingType(settingType);
|
|
373
|
+
}, [
|
|
374
|
+
setInteractionSettingType
|
|
375
|
+
]);
|
|
376
|
+
const onChangeSidebarMode = useCallback((e)=>{
|
|
377
|
+
const mode = e.detail.mode;
|
|
378
|
+
console.log(mode);
|
|
379
|
+
setSidebarMode(mode);
|
|
380
|
+
}, [
|
|
381
|
+
setSidebarMode
|
|
382
|
+
]);
|
|
383
|
+
const onUpdateInteractionItem = useCallback((e)=>{
|
|
384
|
+
const interactionItem = e.detail;
|
|
385
|
+
setInteractionItem(interactionItem);
|
|
386
|
+
}, [
|
|
387
|
+
setInteractionItem
|
|
388
|
+
]);
|
|
336
389
|
useEffect(()=>{
|
|
337
390
|
if (fonts) {
|
|
338
391
|
setFontsToHead('google-font-element', fonts);
|
|
@@ -361,6 +414,11 @@ const Toolbox = ()=>{
|
|
|
361
414
|
window.addEventListener('set-product-offer', onUpdateProductOffers);
|
|
362
415
|
window.addEventListener('update-sale-page-product-id', onUpdateSalePageProductId);
|
|
363
416
|
window.addEventListener('limit-create-theme-section', onLimitCreateThemeSection);
|
|
417
|
+
window.addEventListener('update-interaction-is-select-on-page', onUpdateInteractionIsSelectOnPage);
|
|
418
|
+
window.addEventListener('update-interaction-item', onUpdateInteractionItem);
|
|
419
|
+
window.addEventListener('update-interaction-setting-type', onUpdateInteractionSettingType);
|
|
420
|
+
window.addEventListener('change-sidebar-mode', onChangeSidebarMode);
|
|
421
|
+
window.addEventListener('update-font-type', onUpdateFontType);
|
|
364
422
|
return ()=>{
|
|
365
423
|
window.removeEventListener('update-shop-info', onChangeShopInfo);
|
|
366
424
|
window.removeEventListener('revalidate-query', onRevalidateQuery);
|
|
@@ -381,6 +439,10 @@ const Toolbox = ()=>{
|
|
|
381
439
|
window.removeEventListener('set-product-offer', onUpdateProductOffers);
|
|
382
440
|
window.removeEventListener('update-sale-page-product-id', onUpdateSalePageProductId);
|
|
383
441
|
window.removeEventListener('limit-create-theme-section', onLimitCreateThemeSection);
|
|
442
|
+
window.removeEventListener('update-interaction-is-select-on-page', onUpdateInteractionIsSelectOnPage);
|
|
443
|
+
window.removeEventListener('update-interaction-item', onUpdateInteractionItem);
|
|
444
|
+
window.removeEventListener('update-interaction-setting-type', onUpdateInteractionSettingType);
|
|
445
|
+
window.removeEventListener('update-font-type', onUpdateFontType);
|
|
384
446
|
};
|
|
385
447
|
}, [
|
|
386
448
|
onAddEntity,
|
|
@@ -402,7 +464,12 @@ const Toolbox = ()=>{
|
|
|
402
464
|
onUpdateItemAttribute,
|
|
403
465
|
onUpdateProductOffers,
|
|
404
466
|
onUpdateSalePageProductId,
|
|
405
|
-
onLimitCreateThemeSection
|
|
467
|
+
onLimitCreateThemeSection,
|
|
468
|
+
onUpdateInteractionItem,
|
|
469
|
+
onUpdateInteractionIsSelectOnPage,
|
|
470
|
+
onUpdateInteractionSettingType,
|
|
471
|
+
onUpdateFontType,
|
|
472
|
+
onChangeSidebarMode
|
|
406
473
|
]);
|
|
407
474
|
return /*#__PURE__*/ jsx("div", {
|
|
408
475
|
className: "toolbox"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const findDOMClosest = ($target, selectors)=>{
|
|
2
|
+
const closestElements = {
|
|
3
|
+
$childrenSlot: null,
|
|
4
|
+
$productFeatureImg: null,
|
|
5
|
+
$section: null,
|
|
6
|
+
$component: null,
|
|
7
|
+
$disableIframeClick: null,
|
|
8
|
+
$stickyMinimize: null,
|
|
9
|
+
$toolbar: null,
|
|
10
|
+
$gpText: null,
|
|
11
|
+
$imageDetection: null,
|
|
12
|
+
$popupTriggerButton: null
|
|
13
|
+
};
|
|
14
|
+
let currentElement = $target;
|
|
15
|
+
while(currentElement){
|
|
16
|
+
// Check for stop conditions
|
|
17
|
+
if (currentElement.matches('[data-uid="ROOT"], .builder, #storefront')) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
// Check if currentElement matches any of the selectors
|
|
21
|
+
for (const [key, selector] of Object.entries(selectors)){
|
|
22
|
+
if (!closestElements[key] && currentElement.matches(selector)) {
|
|
23
|
+
closestElements[key] = currentElement;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// If all closest elements are found, break the loop
|
|
27
|
+
if (Object.values(closestElements).every((el)=>el !== null)) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
// Move up to the parent element
|
|
31
|
+
currentElement = currentElement.parentElement;
|
|
32
|
+
}
|
|
33
|
+
// Reset ram
|
|
34
|
+
currentElement = null;
|
|
35
|
+
// Return
|
|
36
|
+
return closestElements;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { findDOMClosest };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isOverToolbarPosition } from './isOverToolbarPosition.js';
|
|
2
|
+
import { isSection } from './isSection.js';
|
|
3
|
+
import { notVisible } from './notVisible.js';
|
|
4
|
+
|
|
5
|
+
const findOverflowParent = (element, initEl)=>{
|
|
6
|
+
const thisEl = element;
|
|
7
|
+
const origEl = initEl || thisEl;
|
|
8
|
+
if (!thisEl) return;
|
|
9
|
+
if (isSection(thisEl)) return;
|
|
10
|
+
if (notVisible(thisEl) && isOverToolbarPosition(initEl, thisEl)) return thisEl;
|
|
11
|
+
if (thisEl.parentElement) {
|
|
12
|
+
return findOverflowParent(thisEl.parentElement, origEl);
|
|
13
|
+
} else {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { findOverflowParent };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const getChildrenByAttrSelector = ($el, attrSelector)=>{
|
|
2
|
+
const childLen = $el.children.length;
|
|
3
|
+
if (childLen) {
|
|
4
|
+
for(let i = 0; i < childLen; i++){
|
|
5
|
+
const children = $el.children[i];
|
|
6
|
+
if (children) {
|
|
7
|
+
const is = children.getAttribute(attrSelector);
|
|
8
|
+
if (is) {
|
|
9
|
+
return children;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { getChildrenByAttrSelector };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const getDOMElementParents = ($el, selector, limit)=>{
|
|
2
|
+
// Set up a parent array
|
|
3
|
+
const parents = [];
|
|
4
|
+
// Push each parent $elms to the array
|
|
5
|
+
while($el){
|
|
6
|
+
$el = $el.parentElement ?? undefined;
|
|
7
|
+
if ($el) {
|
|
8
|
+
if ($el.tagName === 'BODY' || $el.getAttribute('data-uid') === 'ROOT') {
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
if (selector) {
|
|
12
|
+
if ($el.matches(selector)) {
|
|
13
|
+
parents.push($el);
|
|
14
|
+
if (limit && parents.length == limit) {
|
|
15
|
+
return parents;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
parents.push($el);
|
|
21
|
+
if (limit && parents.length == limit) {
|
|
22
|
+
return parents;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Return our parent array
|
|
27
|
+
return parents;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { getDOMElementParents };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TOOLBAR_HOVER_HEIGHT } from '../const.js';
|
|
2
|
+
|
|
3
|
+
const isOverParent = ({ current, parent, index, revert })=>{
|
|
4
|
+
for(let i = 0; i < index; i++){
|
|
5
|
+
let is = current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.top && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.top + parent.height || current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.top + parent.height && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.top;
|
|
6
|
+
if (revert) {
|
|
7
|
+
is = current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.bottom && current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.bottom - parent.height || current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.bottom - parent.height && current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.bottom;
|
|
8
|
+
}
|
|
9
|
+
if (is) return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { isOverParent };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TOOLBAR_ACTIVE_HEIGHT } from '../const.js';
|
|
2
|
+
|
|
3
|
+
const isOverToolbarPosition = (el, parent)=>{
|
|
4
|
+
const rect = el.getBoundingClientRect();
|
|
5
|
+
const rectP = parent.getBoundingClientRect();
|
|
6
|
+
// 32px = toolbar active height
|
|
7
|
+
return rect.top - rectP.top < TOOLBAR_ACTIVE_HEIGHT + 1;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { isOverToolbarPosition };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const waitForElementToExist = (selector, timeout = 200)=>{
|
|
2
|
+
return new Promise((resolve)=>{
|
|
3
|
+
let intervalID = null;
|
|
4
|
+
let timeoutID = null;
|
|
5
|
+
const findEl = ()=>{
|
|
6
|
+
const el = document.body.querySelector('#storefront')?.querySelector(selector);
|
|
7
|
+
if (el) {
|
|
8
|
+
if (intervalID) clearInterval(intervalID);
|
|
9
|
+
if (timeoutID) clearTimeout(timeoutID);
|
|
10
|
+
resolve(el);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
findEl();
|
|
14
|
+
intervalID = setInterval(()=>{
|
|
15
|
+
findEl();
|
|
16
|
+
}, 50);
|
|
17
|
+
timeoutID = setTimeout(()=>{
|
|
18
|
+
if (intervalID) clearInterval(intervalID);
|
|
19
|
+
if (timeoutID) clearTimeout(timeoutID);
|
|
20
|
+
resolve(null);
|
|
21
|
+
}, timeout);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { waitForElementToExist };
|
|
@@ -104,11 +104,13 @@ const DropElement = ()=>{
|
|
|
104
104
|
className: "gp-flex gp-w-[291px] gp-justify-between",
|
|
105
105
|
children: [
|
|
106
106
|
/*#__PURE__*/ jsx("button", {
|
|
107
|
+
"data-button-add-section": true,
|
|
107
108
|
onClick: ()=>dispatchEventBuildWithSectionActiveTab(true),
|
|
108
109
|
className: "gp-flex gp-h-[40px] gp-w-[136px] gp-items-center gp-font-medium gp-justify-center gp-rounded-[8px] gp-bg-[#1C1C1C] gp-text-[14px] gp-text-white hover:gp-bg-[#3B3B3B]",
|
|
109
110
|
children: "Add sections"
|
|
110
111
|
}),
|
|
111
112
|
/*#__PURE__*/ jsx("button", {
|
|
113
|
+
"data-button-add-elements": true,
|
|
112
114
|
onClick: ()=>dispatchEventBuildWithSectionActiveTab(false),
|
|
113
115
|
className: "gp-flex gp-h-[40px] gp-w-[136px] gp-items-center gp-font-medium gp-justify-center gp-rounded-[8px] gp-bg-[#f4f4f4] gp-text-[14px] gp-text-[#212121] hover:gp-bg-[#E2E2E2]",
|
|
114
116
|
children: "Add elements"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublishedThemePagesDocument, StorePropertyDocument } from '@gem-sdk/core';
|
|
1
|
+
import { PublishedThemePagesDocument, StorePropertyDocument, PublishedShopMetasDocument } from '@gem-sdk/core';
|
|
2
2
|
import { ShopMetaDocument } from '@gem-sdk/adapter-shopify';
|
|
3
3
|
import { getFontStyleFromPageTemplate, getFontFromGlobalStyle } from '../google-fonts.js';
|
|
4
4
|
import { genCSS } from '../helpers/gen-css.js';
|
|
@@ -16,7 +16,7 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
|
16
16
|
slug,
|
|
17
17
|
slugType: pageType
|
|
18
18
|
};
|
|
19
|
-
const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
|
|
19
|
+
const [theme, storeProperty, shopifyMeta, publishedShopMetas] = await Promise.allSettled([
|
|
20
20
|
fetcher([
|
|
21
21
|
PublishedThemePagesDocument,
|
|
22
22
|
variables
|
|
@@ -26,11 +26,21 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
|
26
26
|
]),
|
|
27
27
|
shopifyFetcher([
|
|
28
28
|
ShopMetaDocument
|
|
29
|
+
]),
|
|
30
|
+
fetcher([
|
|
31
|
+
PublishedShopMetasDocument,
|
|
32
|
+
{
|
|
33
|
+
keys: [
|
|
34
|
+
'source_font'
|
|
35
|
+
]
|
|
36
|
+
}
|
|
29
37
|
])
|
|
30
38
|
]);
|
|
31
39
|
if (theme.status === 'rejected') {
|
|
32
40
|
throw new Error(theme.reason?.[0]);
|
|
33
41
|
}
|
|
42
|
+
const publishedShopMetaValue = publishedShopMetas.status === 'fulfilled' ? publishedShopMetas.value : undefined;
|
|
43
|
+
const sourceFont = publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === 'source_font');
|
|
34
44
|
const dataBuilder = theme.value.publishedThemePages?.[0];
|
|
35
45
|
const themePageCustomFonts = theme.value?.publishedThemePages?.[0]?.themePageCustomFonts;
|
|
36
46
|
if (!dataBuilder) {
|
|
@@ -38,8 +48,8 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
|
38
48
|
}
|
|
39
49
|
const pageTemplate = parseBuilderTemplateV2(dataBuilder);
|
|
40
50
|
const [elementFontStyle, fontStyle, fallback, customFonts] = await Promise.all([
|
|
41
|
-
getFontStyleFromPageTemplate(pageTemplate),
|
|
42
|
-
getFontFromGlobalStyle(dataBuilder?.pageStyle?.data),
|
|
51
|
+
getFontStyleFromPageTemplate(pageTemplate, sourceFont?.value),
|
|
52
|
+
getFontFromGlobalStyle(dataBuilder?.pageStyle?.data, sourceFont?.value),
|
|
43
53
|
getFallbackV2(fetcher, pageTemplate),
|
|
44
54
|
getCustomFonts(themePageCustomFonts)
|
|
45
55
|
]);
|
|
@@ -139,7 +149,8 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
|
139
149
|
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
140
150
|
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
141
151
|
pageHandle: dataBuilder.handle ?? null,
|
|
142
|
-
customFonts
|
|
152
|
+
customFonts,
|
|
153
|
+
interaction: dataBuilder?.interaction
|
|
143
154
|
});
|
|
144
155
|
} catch (err) {
|
|
145
156
|
captureException(err);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkNotInOptionFont } from './helpers/check-option-font.js';
|
|
1
2
|
import { getFontsFromDataBuilder } from './helpers/gen-fonts.js';
|
|
2
3
|
|
|
3
4
|
const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36';
|
|
@@ -33,12 +34,17 @@ const composeFonts = (fonts)=>{
|
|
|
33
34
|
};
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
|
-
const createFontUrl = (fonts, option)=>{
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const createFontUrl = (fonts, option, fontType)=>{
|
|
38
|
+
const mainFonts = fonts.filter((font)=>{
|
|
39
|
+
return !([
|
|
40
|
+
'bunny',
|
|
41
|
+
'google'
|
|
42
|
+
].includes(font.type) && checkNotInOptionFont(font.family, fontType || 'google')) && (font.type === 'google' || font.type === 'bunny' || !font.type);
|
|
43
|
+
});
|
|
44
|
+
if (!mainFonts.length) return;
|
|
39
45
|
const params = new URLSearchParams();
|
|
40
46
|
const display = option?.display || 'swap';
|
|
41
|
-
const uniqFonts =
|
|
47
|
+
const uniqFonts = mainFonts.filter((font, index, arr)=>{
|
|
42
48
|
return index === arr.findIndex((t)=>t.family === font.family);
|
|
43
49
|
});
|
|
44
50
|
const family = composeFonts(uniqFonts).map((font)=>{
|
|
@@ -52,13 +58,16 @@ const createFontUrl = (fonts, option)=>{
|
|
|
52
58
|
if (option?.effect) {
|
|
53
59
|
params.append('effect', option.effect);
|
|
54
60
|
}
|
|
55
|
-
|
|
61
|
+
const bunnyFontUrl = `https://fonts.bunny.net/css?family=${family}`;
|
|
62
|
+
const googleFontUrl = `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
|
|
63
|
+
return fontType === 'bunny' ? bunnyFontUrl : googleFontUrl;
|
|
56
64
|
};
|
|
57
|
-
|
|
65
|
+
// eslint-disable-next-line max-params
|
|
66
|
+
async function getFonts(fonts, option, isImportFontByUrl = true, fontType) {
|
|
58
67
|
/**
|
|
59
68
|
* The order of IE -> Chrome is important, other wise chrome starts loading woff1.
|
|
60
69
|
* CSS cascading 🤷♂️.
|
|
61
|
-
*/ const url = createFontUrl(fonts, option);
|
|
70
|
+
*/ const url = createFontUrl(fonts, option, fontType);
|
|
62
71
|
if (!url) return '';
|
|
63
72
|
try {
|
|
64
73
|
if (isImportFontByUrl) return `@import url('${url}');`;
|
|
@@ -80,7 +89,7 @@ async function getFonts(fonts, option, isImportFontByUrl = true) {
|
|
|
80
89
|
return '';
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
|
-
const getFontFromGlobalStyle = (data)=>{
|
|
92
|
+
const getFontFromGlobalStyle = (data, sourceFont)=>{
|
|
84
93
|
if (!data) return '';
|
|
85
94
|
try {
|
|
86
95
|
const globalStyle = JSON.parse(data);
|
|
@@ -88,14 +97,14 @@ const getFontFromGlobalStyle = (data)=>{
|
|
|
88
97
|
const fonts = Object.entries(fontData).map(([, value])=>{
|
|
89
98
|
return value;
|
|
90
99
|
});
|
|
91
|
-
return getFonts(fonts);
|
|
100
|
+
return getFonts(fonts, undefined, undefined, sourceFont);
|
|
92
101
|
} catch {
|
|
93
102
|
return '';
|
|
94
103
|
}
|
|
95
104
|
};
|
|
96
|
-
async function getFontStyleFromPageTemplate(pageTemplate) {
|
|
105
|
+
async function getFontStyleFromPageTemplate(pageTemplate, sourceFont) {
|
|
97
106
|
const fontStyle = pageTemplate.map((sectionData)=>{
|
|
98
|
-
return getFonts(getFontsFromDataBuilder(sectionData.data));
|
|
107
|
+
return getFonts(getFontsFromDataBuilder(sectionData.data), undefined, undefined, sourceFont);
|
|
99
108
|
});
|
|
100
109
|
return await Promise.all(fontStyle);
|
|
101
110
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const listFontsNotInBunny = [
|
|
2
|
+
'Anton SC',
|
|
3
|
+
'Arsenal SC',
|
|
4
|
+
'Baskervville SC',
|
|
5
|
+
'Beiruti',
|
|
6
|
+
'Bodoni Moda SC',
|
|
7
|
+
'Bona Nova SC',
|
|
8
|
+
'Bungee Tint',
|
|
9
|
+
'Edu AU VIC WA NT Hand',
|
|
10
|
+
'Fustat',
|
|
11
|
+
'Ga Maamli',
|
|
12
|
+
'Kalnia Glaze',
|
|
13
|
+
'Maname',
|
|
14
|
+
'Matemasie',
|
|
15
|
+
'Material Icons',
|
|
16
|
+
'Material Icons Outlined',
|
|
17
|
+
'Material Icons Round',
|
|
18
|
+
'Material Icons Sharp',
|
|
19
|
+
'Material Icons Two Tone',
|
|
20
|
+
'Material Symbols Outlined',
|
|
21
|
+
'Material Symbols Rounded',
|
|
22
|
+
'Material Symbols Sharp',
|
|
23
|
+
'Moderustic',
|
|
24
|
+
'New Amsterdam',
|
|
25
|
+
'Playwrite AR',
|
|
26
|
+
'Playwrite AT',
|
|
27
|
+
'Playwrite BE VLG',
|
|
28
|
+
'Playwrite BE WAL',
|
|
29
|
+
'Playwrite CL',
|
|
30
|
+
'Playwrite CU',
|
|
31
|
+
'Playwrite CZ',
|
|
32
|
+
'Playwrite DK Loopet',
|
|
33
|
+
'Playwrite DK Uloopet',
|
|
34
|
+
'Playwrite HR',
|
|
35
|
+
'Playwrite HR Lijeva',
|
|
36
|
+
'Playwrite HU',
|
|
37
|
+
'Playwrite PE',
|
|
38
|
+
'SUSE',
|
|
39
|
+
'Sankofa Display',
|
|
40
|
+
'Wittgenstein',
|
|
41
|
+
'Zain'
|
|
42
|
+
];
|
|
43
|
+
const listFontsNotInGoogle = [
|
|
44
|
+
'Arima Madurai',
|
|
45
|
+
'Coda Caption',
|
|
46
|
+
'Fredoka One',
|
|
47
|
+
'Gentium Book Basic',
|
|
48
|
+
'Kantumruy',
|
|
49
|
+
'Merienda One',
|
|
50
|
+
'Source Sans Pro',
|
|
51
|
+
'Source Serif Pro',
|
|
52
|
+
'Briem Hand',
|
|
53
|
+
'Pushster'
|
|
54
|
+
];
|
|
55
|
+
const objectFont = {
|
|
56
|
+
bunny: listFontsNotInBunny,
|
|
57
|
+
google: listFontsNotInGoogle
|
|
58
|
+
};
|
|
59
|
+
const checkNotInOptionFont = (currentfont, type)=>{
|
|
60
|
+
return objectFont?.[type]?.includes(currentfont);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { checkNotInOptionFont };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { PageProvider, BuilderComponentProvider, SectionProvider, BuilderPreviewProvider
|
|
2
|
+
import { PageProvider, BuilderComponentProvider, SectionProvider, BuilderPreviewProvider } from '@gem-sdk/core';
|
|
3
3
|
import { NextSeo } from 'next-seo';
|
|
4
4
|
import Head from 'next/head';
|
|
5
5
|
import { useState, useMemo, useEffect } from 'react';
|
|
6
6
|
import Toolbox from '../components/builder/Toolbox.js';
|
|
7
7
|
import Header from '../components/builder/Header.js';
|
|
8
8
|
import Footer from '../components/builder/Footer.js';
|
|
9
|
-
import CollectionGlobalProvider from './CollectionGlobalProvider.js';
|
|
10
9
|
import PopupManager from '../components/builder/PopupManager.js';
|
|
11
10
|
import ImageToLayout from '../components/image-to-layout/ImageToLayout.js';
|
|
12
11
|
import AddSectionImageToLayout from '../components/image-to-layout/AddSectionImageToLayout.js';
|
|
13
12
|
import Toolbar from '../components/builder/Toolbar.js';
|
|
14
13
|
import Devices from '../components/builder/SwitchView.js';
|
|
14
|
+
import Body from '../components/builder/Body.js';
|
|
15
15
|
|
|
16
16
|
const BuilderPage = ({ components, seo, themeStyle, fontStyle, sectionData, pageType, editorImageToLayout, isThemeSectionEditor, hiddenToolbar, pageName, isOriginTemplate })=>{
|
|
17
17
|
const [loadSuccess, setLoadSuccess] = useState(false);
|
|
@@ -81,16 +81,9 @@ const BuilderPage = ({ components, seo, themeStyle, fontStyle, sectionData, page
|
|
|
81
81
|
isOriginTemplate: isOriginTemplate,
|
|
82
82
|
openPageSetting: openPageSetting
|
|
83
83
|
})),
|
|
84
|
-
/*#__PURE__*/ jsx(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
children: pageType === 'GP_COLLECTION' ? /*#__PURE__*/ jsx(CollectionGlobalProvider, {
|
|
88
|
-
children: /*#__PURE__*/ jsx(RenderPreview, {
|
|
89
|
-
uid: "ROOT"
|
|
90
|
-
})
|
|
91
|
-
}) : /*#__PURE__*/ jsx(RenderPreview, {
|
|
92
|
-
uid: "ROOT"
|
|
93
|
-
})
|
|
84
|
+
/*#__PURE__*/ jsx(Body, {
|
|
85
|
+
pageType: pageType,
|
|
86
|
+
isThemeSectionEditor: isThemeSectionEditor
|
|
94
87
|
}),
|
|
95
88
|
/*#__PURE__*/ jsx(ImageToLayout, {
|
|
96
89
|
editorImageToLayout: editorImageToLayout || false
|
|
@@ -7,9 +7,11 @@ import { useTrackingView } from '../libs/hooks/use-tracking-view.js';
|
|
|
7
7
|
import { parseHtml } from '../libs/parse-html.js';
|
|
8
8
|
import Header from '../components/builder/Header.js';
|
|
9
9
|
import FooterForPostPurchase from '../components/FooterForPostPurchase.js';
|
|
10
|
+
import Script from 'next/script';
|
|
10
11
|
|
|
11
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, customFonts, isPostPurchase, shopName, productOffers, publicStoreFrontData, isPreview })=>{
|
|
12
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, customFonts, isPostPurchase, shopName, productOffers, publicStoreFrontData, isPreview, interaction })=>{
|
|
12
13
|
const router = useRouter();
|
|
14
|
+
const baseAssetURL = process.env.NEXT_GP_BASE_ASSET_URL || 'https://d3kbi0je7pp4lw.cloudfront.net';
|
|
13
15
|
useTrackingView(shopToken, pageHandle, router.isFallback);
|
|
14
16
|
if (router.isFallback) {
|
|
15
17
|
return /*#__PURE__*/ jsx("div", {
|
|
@@ -79,17 +81,28 @@ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, f
|
|
|
79
81
|
isPostPurchase && /*#__PURE__*/ jsx(Header, {
|
|
80
82
|
pageType: "POST_PURCHASE"
|
|
81
83
|
}),
|
|
84
|
+
/*#__PURE__*/ jsx("div", {
|
|
85
|
+
dangerouslySetInnerHTML: {
|
|
86
|
+
__html: `<div id="gp-interaction" style="display: none;">${JSON.stringify(interaction?.value || [])}</div>`
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
82
89
|
/*#__PURE__*/ jsx(SectionProvider, {
|
|
83
90
|
data: sectionData,
|
|
84
|
-
children: builderData?.map((builder)=>/*#__PURE__*/
|
|
91
|
+
children: builderData?.map((builder)=>/*#__PURE__*/ jsxs(BuilderProvider, {
|
|
85
92
|
state: builder.data,
|
|
86
93
|
lazy: builder.lazy,
|
|
87
94
|
priority: builder.priority,
|
|
88
95
|
isPostPurchase: isPostPurchase,
|
|
89
96
|
isPreview: isPreview,
|
|
90
|
-
children:
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
children: [
|
|
98
|
+
/*#__PURE__*/ jsx(Render, {
|
|
99
|
+
uid: builder.uid
|
|
100
|
+
}),
|
|
101
|
+
/*#__PURE__*/ jsx(Script, {
|
|
102
|
+
defer: true,
|
|
103
|
+
src: `${baseAssetURL}/assets-v2/gp-flow-action-lip.js`
|
|
104
|
+
})
|
|
105
|
+
]
|
|
93
106
|
}, builder.uid))
|
|
94
107
|
}),
|
|
95
108
|
isPostPurchase && /*#__PURE__*/ jsx(FooterForPostPurchase, {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ type PageBuilderProps = {
|
|
|
40
40
|
customCodeBody?: string | null;
|
|
41
41
|
isStorefront?: boolean;
|
|
42
42
|
customFonts?: string | null;
|
|
43
|
+
interaction?: ShopType.Maybe<Pick<ShopType.PublishedPageInteraction, "id" | "value">>;
|
|
43
44
|
};
|
|
44
45
|
type PageBuilderPropsV2 = {
|
|
45
46
|
builderData?: {
|
|
@@ -188,7 +189,9 @@ declare const BuilderPage: React.FC<BuilderPageProps>;
|
|
|
188
189
|
|
|
189
190
|
declare const getStaticPaths: GetStaticPaths;
|
|
190
191
|
|
|
191
|
-
type TypographyV2FontFamilyType = 'google' | 'custom' | 'theme';
|
|
192
|
+
type TypographyV2FontFamilyType = 'google' | 'custom' | 'theme' | 'bunny';
|
|
193
|
+
|
|
194
|
+
type FontType = 'bunny' | 'google';
|
|
192
195
|
|
|
193
196
|
type FontItem = {
|
|
194
197
|
type: TypographyV2FontFamilyType;
|
|
@@ -201,8 +204,8 @@ type FontOption = {
|
|
|
201
204
|
subset?: string;
|
|
202
205
|
effect?: string;
|
|
203
206
|
};
|
|
204
|
-
declare function getFonts(fonts: FontItem[], option?: FontOption, isImportFontByUrl?: boolean): Promise<string>;
|
|
205
|
-
declare const getFontFromGlobalStyle: (data?: string) => "" | Promise<string>;
|
|
207
|
+
declare function getFonts(fonts: FontItem[], option?: FontOption, isImportFontByUrl?: boolean, fontType?: FontType): Promise<string>;
|
|
208
|
+
declare const getFontFromGlobalStyle: (data?: string, sourceFont?: FontType) => "" | Promise<string>;
|
|
206
209
|
|
|
207
210
|
declare const getFontsFromDataBuilder: (dataBuilder: Record<string, any>) => FontItem[];
|
|
208
211
|
declare const getFontFromGroupSetting: (fonts: FontItem[], groupSetting: Record<string, any>) => void;
|