@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
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import MainLayout from '../layouts/main.js';
|
|
3
3
|
|
|
4
|
-
const getLayout = (page, pageProps)
|
|
5
|
-
return jsx(MainLayout, {
|
|
4
|
+
const getLayout = (page, pageProps)=>{
|
|
5
|
+
return /*#__PURE__*/ jsx(MainLayout, {
|
|
6
|
+
...pageProps,
|
|
7
|
+
children: page
|
|
8
|
+
});
|
|
6
9
|
};
|
|
7
10
|
|
|
8
11
|
export { getLayout };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const getStorefrontApi = (handle, provider)
|
|
2
|
-
switch
|
|
3
|
-
case 'BIGCOMMERCE':
|
|
4
|
-
return `https://${handle}.bigcommerce.com`;
|
|
5
|
-
default:
|
|
6
|
-
return `https://${handle}.myshopify.com/api/2022-07/graphql.json`;
|
|
7
|
-
}
|
|
1
|
+
const getStorefrontApi = (handle, provider)=>{
|
|
2
|
+
switch(provider){
|
|
3
|
+
case 'BIGCOMMERCE':
|
|
4
|
+
return `https://${handle}.bigcommerce.com`;
|
|
5
|
+
default:
|
|
6
|
+
return `https://${handle}.myshopify.com/api/2022-07/graphql.json`;
|
|
7
|
+
}
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export { getStorefrontApi };
|
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
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';
|
|
2
|
-
const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
|
|
3
|
-
async function getFontForUA(url, UA) {
|
|
4
|
-
return fetch(url, {
|
|
5
|
-
headers: {
|
|
6
|
-
'User-Agent': UA
|
|
7
|
-
}
|
|
8
|
-
}).then((res)
|
|
9
|
-
}
|
|
10
|
-
const createFontUrl = (fonts, option)
|
|
11
|
-
const params = new URLSearchParams();
|
|
12
|
-
const display = option?.display || 'swap';
|
|
13
|
-
const family = fonts
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (option?.
|
|
24
|
-
params.append('
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return value;
|
|
56
|
-
});
|
|
57
|
-
return getFonts(font);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return '';
|
|
61
|
-
}
|
|
1
|
+
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';
|
|
2
|
+
const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
|
|
3
|
+
async function getFontForUA(url, UA) {
|
|
4
|
+
return fetch(url, {
|
|
5
|
+
headers: {
|
|
6
|
+
'User-Agent': UA
|
|
7
|
+
}
|
|
8
|
+
}).then((res)=>res.text());
|
|
9
|
+
}
|
|
10
|
+
const createFontUrl = (fonts, option)=>{
|
|
11
|
+
const params = new URLSearchParams();
|
|
12
|
+
const display = option?.display || 'swap';
|
|
13
|
+
const family = fonts.filter((font, index, arr)=>{
|
|
14
|
+
return index === arr.findIndex((t)=>t.family === font.family);
|
|
15
|
+
}).map((font)=>{
|
|
16
|
+
return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
|
|
17
|
+
}).join('|');
|
|
18
|
+
params.append('family', family);
|
|
19
|
+
params.append('display', display);
|
|
20
|
+
if (option?.subset) {
|
|
21
|
+
params.append('subset', option.subset);
|
|
22
|
+
}
|
|
23
|
+
if (option?.effect) {
|
|
24
|
+
params.append('effect', option.effect);
|
|
25
|
+
}
|
|
26
|
+
return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
|
|
27
|
+
};
|
|
28
|
+
async function getFonts(fonts, option) {
|
|
29
|
+
/**
|
|
30
|
+
* The order of IE -> Chrome is important, other wise chrome starts loading woff1.
|
|
31
|
+
* CSS cascading 🤷♂️.
|
|
32
|
+
*/ const url = createFontUrl(fonts, option);
|
|
33
|
+
try {
|
|
34
|
+
const [ie, chrome] = await Promise.all([
|
|
35
|
+
getFontForUA(url, IE_UA),
|
|
36
|
+
getFontForUA(url, CHROME_UA)
|
|
37
|
+
]);
|
|
38
|
+
return ie + chrome;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const getFontFromGlobalStyle = (data)=>{
|
|
44
|
+
if (!data) return '';
|
|
45
|
+
try {
|
|
46
|
+
const globalStyle = JSON.parse(data);
|
|
47
|
+
const fonts = globalStyle?.font ?? {};
|
|
48
|
+
const font = Object.entries(fonts).map(([, value])=>{
|
|
49
|
+
return value;
|
|
50
|
+
});
|
|
51
|
+
return getFonts(font);
|
|
52
|
+
} catch {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
62
55
|
};
|
|
63
56
|
|
|
64
57
|
export { createFontUrl, getFontFromGlobalStyle, getFonts };
|
|
@@ -1,100 +1,109 @@
|
|
|
1
1
|
import { getShortName } from '@gem-sdk/core';
|
|
2
2
|
import merge from 'deepmerge';
|
|
3
3
|
|
|
4
|
-
const baseDevices = {
|
|
5
|
-
tablet: '1023px',
|
|
6
|
-
mobile: '767px'
|
|
7
|
-
};
|
|
8
|
-
const flattenObject = (obj, prefix)
|
|
9
|
-
return Object.keys(obj).reduce((acc, k)
|
|
10
|
-
const pre = prefix ? `${prefix}-` : '';
|
|
11
|
-
if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0)
|
|
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
|
-
return [
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
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
|
-
|
|
4
|
+
const baseDevices = {
|
|
5
|
+
tablet: '1023px',
|
|
6
|
+
mobile: '767px'
|
|
7
|
+
};
|
|
8
|
+
const flattenObject = (obj, prefix)=>{
|
|
9
|
+
return Object.keys(obj).reduce((acc, k)=>{
|
|
10
|
+
const pre = prefix ? `${prefix}-` : '';
|
|
11
|
+
if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0) Object.assign(acc, flattenObject(obj[k], pre + k));
|
|
12
|
+
else acc[pre + k] = obj[k];
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
};
|
|
16
|
+
const devicesOrder = [
|
|
17
|
+
'desktop',
|
|
18
|
+
'tablet',
|
|
19
|
+
'mobile'
|
|
20
|
+
];
|
|
21
|
+
const mapObject = (obj)=>{
|
|
22
|
+
return Object.entries(obj ?? {}).reduce((acc, [k, v])=>{
|
|
23
|
+
return {
|
|
24
|
+
...acc,
|
|
25
|
+
[getShortName(k)]: typeof v === 'object' ? mapObject(v) : v
|
|
26
|
+
};
|
|
27
|
+
}, {});
|
|
28
|
+
};
|
|
29
|
+
const getValueByDevice = (data, device)=>{
|
|
30
|
+
const deviceData = {
|
|
31
|
+
typography: Object.fromEntries(Object.entries(data?.typography ?? {}).map(([key, value])=>{
|
|
32
|
+
const typo = {
|
|
33
|
+
...value?.[device]
|
|
34
|
+
};
|
|
35
|
+
if (!typo) return [
|
|
36
|
+
key,
|
|
37
|
+
undefined
|
|
38
|
+
];
|
|
39
|
+
if (typo.fontFamily) {
|
|
40
|
+
typo.fontFamily = `var(--g-font-${typo.fontFamily}, ${typo.fontFamily})`;
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
key,
|
|
44
|
+
typo
|
|
45
|
+
];
|
|
46
|
+
})),
|
|
47
|
+
spacing: Object.fromEntries(Object.entries(data?.spacing ?? {}).map(([key, value])=>{
|
|
48
|
+
return [
|
|
49
|
+
key,
|
|
50
|
+
value?.[device]
|
|
51
|
+
];
|
|
52
|
+
})),
|
|
53
|
+
container: Object.fromEntries(Object.entries(data?.container ?? {}).map(([key, value])=>{
|
|
54
|
+
return [
|
|
55
|
+
key,
|
|
56
|
+
value?.[device]
|
|
57
|
+
];
|
|
58
|
+
})),
|
|
59
|
+
font: Object.fromEntries(Object.entries(data?.font ?? {}).map(([key, value])=>{
|
|
60
|
+
return [
|
|
61
|
+
key,
|
|
62
|
+
value?.family
|
|
63
|
+
];
|
|
64
|
+
}))
|
|
65
|
+
};
|
|
66
|
+
return deviceData;
|
|
67
|
+
};
|
|
68
|
+
const genCSSVariable = (deviceData)=>{
|
|
69
|
+
return Object.entries(mapObject(flattenObject(deviceData))).map(([key, value])=>{
|
|
70
|
+
if (value === undefined) return undefined;
|
|
71
|
+
return `--g-${key}:${value}`;
|
|
72
|
+
}).filter((v)=>v !== undefined).join(';');
|
|
73
|
+
};
|
|
74
|
+
const genCSS = (input, mobileOnly)=>{
|
|
75
|
+
if (!input) return '';
|
|
76
|
+
let data = {};
|
|
77
|
+
try {
|
|
78
|
+
if (typeof input === 'string') {
|
|
79
|
+
data = JSON.parse(input);
|
|
80
|
+
} else {
|
|
81
|
+
data = input;
|
|
82
|
+
}
|
|
83
|
+
if (mobileOnly) {
|
|
84
|
+
const desktop = getValueByDevice(data, 'desktop');
|
|
85
|
+
const mobile = getValueByDevice(data, 'mobile');
|
|
86
|
+
const deviceData = merge(desktop, mobile);
|
|
87
|
+
deviceData.color = data.color;
|
|
88
|
+
deviceData.radius = data.radius;
|
|
89
|
+
const cssData = genCSSVariable(deviceData);
|
|
90
|
+
return `:root{${cssData}}`;
|
|
91
|
+
}
|
|
92
|
+
return devicesOrder.map((device)=>{
|
|
93
|
+
const deviceData = getValueByDevice(data, device);
|
|
94
|
+
if (device === 'desktop') {
|
|
95
|
+
deviceData.color = data.color;
|
|
96
|
+
deviceData.radius = data.radius;
|
|
97
|
+
}
|
|
98
|
+
const cssData = genCSSVariable(deviceData);
|
|
99
|
+
if (device === 'desktop') {
|
|
100
|
+
return `:root{${cssData}}`;
|
|
101
|
+
}
|
|
102
|
+
return `@media (max-width: ${baseDevices[device]}) {:root{${cssData}}}`;
|
|
103
|
+
}).join('\n');
|
|
104
|
+
} catch {
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
98
107
|
};
|
|
99
108
|
|
|
100
109
|
export { genCSS };
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { prefetchQueries } from '@gem-sdk/core';
|
|
2
2
|
|
|
3
|
-
const getFallbackV2 = async (fetcher, data)
|
|
4
|
-
const isSample = !process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
|
|
5
|
-
const queries = data.map((v)
|
|
6
|
-
const datas = await Promise.allSettled(queries.map(({ query, variables, func
|
|
7
|
-
if (func) {
|
|
8
|
-
return func(fetcher, variables);
|
|
9
|
-
}
|
|
10
|
-
if (query)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
const getFallbackV2 = async (fetcher, data)=>{
|
|
4
|
+
const isSample = !process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
|
|
5
|
+
const queries = data.map((v)=>prefetchQueries(v.data, isSample)).flat();
|
|
6
|
+
const datas = await Promise.allSettled(queries.map(({ query , variables , func })=>{
|
|
7
|
+
if (func) {
|
|
8
|
+
return func(fetcher, variables);
|
|
9
|
+
}
|
|
10
|
+
if (query) return fetcher([
|
|
11
|
+
query,
|
|
12
|
+
variables
|
|
13
|
+
]);
|
|
14
|
+
return {};
|
|
15
|
+
}));
|
|
16
|
+
const fallback = queries.reduce((acc, { key }, index)=>{
|
|
17
|
+
const res = datas[index];
|
|
18
|
+
if (res?.status === 'fulfilled') {
|
|
19
|
+
return {
|
|
20
|
+
...acc,
|
|
21
|
+
[key]: res.value
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
return fallback;
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export { getFallbackV2 };
|
|
@@ -1,83 +1,85 @@
|
|
|
1
|
-
const normalizeBuilderData = (data)
|
|
2
|
-
const result = {};
|
|
3
|
-
function compose(cData, currData = {}) {
|
|
4
|
-
if (cData) {
|
|
5
|
-
const { childrens, dateModified, editorConfigs, ...rest } = cData;
|
|
6
|
-
if (rest.type === 'section') {
|
|
7
|
-
currData[rest.uid] = rest;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
const
|
|
28
|
-
// Return the ordered sections
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return normalizeBuilderData({
|
|
47
|
-
uid: 'ROOT',
|
|
48
|
-
tag: 'Root',
|
|
49
|
-
childrens
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function normalizePageSectionResponseV2(sections, orders) {
|
|
53
|
-
const sortedSections = orderSection(sections, orders);
|
|
54
|
-
const childrens = sortedSections
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
const normalizeBuilderData = (data)=>{
|
|
2
|
+
const result = {};
|
|
3
|
+
function compose(cData, currData = {}) {
|
|
4
|
+
if (cData) {
|
|
5
|
+
const { childrens , dateModified , editorConfigs , ...rest } = cData;
|
|
6
|
+
if (rest.type === 'section') {
|
|
7
|
+
currData[rest.uid] = rest;
|
|
8
|
+
} else {
|
|
9
|
+
const items = childrens?.map((child)=>child?.uid) ?? [];
|
|
10
|
+
currData[rest.uid] = {
|
|
11
|
+
...rest,
|
|
12
|
+
childrens: items
|
|
13
|
+
};
|
|
14
|
+
if (childrens) {
|
|
15
|
+
childrens.map((child)=>compose(child, currData));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
compose(data, result);
|
|
21
|
+
return {
|
|
22
|
+
...result
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const orderSection = (sections, orders)=>{
|
|
26
|
+
// Filter out sections that are not in the order list
|
|
27
|
+
const ids = orders?.filter((id)=>sections?.some((v)=>v?.id === id));
|
|
28
|
+
// Return the ordered sections
|
|
29
|
+
const orderedSections = ids?.map((id)=>sections?.find((v)=>v?.id === id)) ?? [];
|
|
30
|
+
// Return the sections that are not in the order list
|
|
31
|
+
const sectionsNotInOrder = sections?.filter((v)=>!v?.id || !ids?.includes(v.id)) ?? [];
|
|
32
|
+
// Return the ordered sections + the sections that are not in the order list
|
|
33
|
+
return orderedSections.concat(sectionsNotInOrder);
|
|
34
|
+
};
|
|
35
|
+
function normalizePageSectionResponse(sections, orders) {
|
|
36
|
+
const sortedSections = orderSection(sections, orders);
|
|
37
|
+
const childrens = sortedSections.map((item)=>{
|
|
38
|
+
if (!item?.component) return false;
|
|
39
|
+
try {
|
|
40
|
+
const data = JSON.parse(item.component);
|
|
41
|
+
return data;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}).filter(Boolean);
|
|
46
|
+
return normalizeBuilderData({
|
|
47
|
+
uid: 'ROOT',
|
|
48
|
+
tag: 'Root',
|
|
49
|
+
childrens
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function normalizePageSectionResponseV2(sections, orders) {
|
|
53
|
+
const sortedSections = orderSection(sections, orders);
|
|
54
|
+
const childrens = sortedSections.map((item)=>{
|
|
55
|
+
if (!item?.component) return false;
|
|
56
|
+
try {
|
|
57
|
+
const data = JSON.parse(item.component);
|
|
58
|
+
return data;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}).filter(Boolean);
|
|
63
|
+
return childrens.map((v)=>{
|
|
64
|
+
return {
|
|
65
|
+
uid: v.uid,
|
|
66
|
+
lazy: Boolean(v.settings?.lazy),
|
|
67
|
+
priority: Boolean(v.settings?.priority),
|
|
68
|
+
data: normalizeBuilderData(v)
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const parseBuilderTemplateV2 = (data)=>{
|
|
73
|
+
return normalizePageSectionResponseV2([
|
|
74
|
+
...data?.pageSections ?? [],
|
|
75
|
+
...data?.themePageCustomSections ?? []
|
|
76
|
+
], data?.sectionPosition);
|
|
77
|
+
};
|
|
78
|
+
const parseBuilderTemplate = (data)=>{
|
|
79
|
+
return normalizePageSectionResponse([
|
|
80
|
+
...data?.pageSections ?? [],
|
|
81
|
+
...data?.themePageCustomSections ?? []
|
|
82
|
+
], data?.sectionPosition);
|
|
81
83
|
};
|
|
82
84
|
|
|
83
85
|
export { normalizeBuilderData, parseBuilderTemplate, parseBuilderTemplateV2 };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
const parseJson = (json)
|
|
2
|
-
if (!json)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const serializableJson = (props) => {
|
|
12
|
-
return JSON.parse(JSON.stringify(props));
|
|
1
|
+
const parseJson = (json)=>{
|
|
2
|
+
if (!json) return null;
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(json);
|
|
5
|
+
} catch (e) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const serializableJson = (props)=>{
|
|
10
|
+
return JSON.parse(JSON.stringify(props));
|
|
13
11
|
};
|
|
14
12
|
|
|
15
13
|
export { parseJson, serializableJson };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function isBot(input) {
|
|
2
|
-
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Chrome-Lighthouse|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(input);
|
|
1
|
+
function isBot(input) {
|
|
2
|
+
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Chrome-Lighthouse|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(input);
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export { isBot };
|