@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.
Files changed (79) hide show
  1. package/dist/cjs/components/ErrorBoundary.js +32 -24
  2. package/dist/cjs/components/ErrorFallback.js +19 -2
  3. package/dist/cjs/components/FacebookPixel.js +25 -20
  4. package/dist/cjs/components/Footer.js +462 -0
  5. package/dist/cjs/components/GoogleAnalytic.js +49 -23
  6. package/dist/cjs/components/Header.js +211 -0
  7. package/dist/cjs/components/TikTokPixel.js +9 -6
  8. package/dist/cjs/components/builder/Toolbox.js +215 -188
  9. package/dist/cjs/layouts/main.js +19 -5
  10. package/dist/cjs/libs/api/get-builder-props.js +26 -24
  11. package/dist/cjs/libs/api/get-collection-props.js +59 -55
  12. package/dist/cjs/libs/api/get-home-page-props-v2.js +121 -114
  13. package/dist/cjs/libs/api/get-home-page-props.js +133 -123
  14. package/dist/cjs/libs/api/get-preview-props.js +10 -10
  15. package/dist/cjs/libs/api/get-product-props.js +64 -62
  16. package/dist/cjs/libs/api/get-static-page-props-preview.js +128 -121
  17. package/dist/cjs/libs/api/get-static-page-props-v2.js +126 -119
  18. package/dist/cjs/libs/api/get-static-page-props.js +130 -120
  19. package/dist/cjs/libs/fetcher.js +59 -63
  20. package/dist/cjs/libs/get-layout.js +5 -2
  21. package/dist/cjs/libs/get-storefront-api.js +7 -7
  22. package/dist/cjs/libs/getStaticPaths.js +5 -5
  23. package/dist/cjs/libs/google-fonts.js +54 -61
  24. package/dist/cjs/libs/helpers/gen-css.js +103 -94
  25. package/dist/cjs/libs/helpers/generate-manifres.js +1 -1
  26. package/dist/cjs/libs/helpers/get-fallback.js +24 -22
  27. package/dist/cjs/libs/helpers/normalize.js +82 -80
  28. package/dist/cjs/libs/helpers/parse-json.js +10 -12
  29. package/dist/cjs/libs/helpers/user-agent.js +2 -2
  30. package/dist/cjs/libs/hooks/use-tracking-view.js +36 -31
  31. package/dist/cjs/libs/parse-html.js +33 -26
  32. package/dist/cjs/pages/404.js +34 -2
  33. package/dist/cjs/pages/500.js +63 -8
  34. package/dist/cjs/pages/builder.js +69 -14
  35. package/dist/cjs/pages/collection-detail.js +48 -7
  36. package/dist/cjs/pages/preview.js +18 -12
  37. package/dist/cjs/pages/product-detail.js +53 -7
  38. package/dist/cjs/pages/static-v2.js +62 -7
  39. package/dist/cjs/pages/static.js +60 -6
  40. package/dist/esm/components/ErrorBoundary.js +32 -24
  41. package/dist/esm/components/ErrorFallback.js +19 -2
  42. package/dist/esm/components/FacebookPixel.js +25 -20
  43. package/dist/esm/components/Footer.js +458 -0
  44. package/dist/esm/components/GoogleAnalytic.js +49 -23
  45. package/dist/esm/components/Header.js +207 -0
  46. package/dist/esm/components/TikTokPixel.js +9 -6
  47. package/dist/esm/components/builder/Toolbox.js +217 -190
  48. package/dist/esm/layouts/main.js +19 -5
  49. package/dist/esm/libs/api/get-builder-props.js +26 -24
  50. package/dist/esm/libs/api/get-collection-props.js +59 -55
  51. package/dist/esm/libs/api/get-home-page-props-v2.js +121 -114
  52. package/dist/esm/libs/api/get-home-page-props.js +133 -123
  53. package/dist/esm/libs/api/get-preview-props.js +10 -10
  54. package/dist/esm/libs/api/get-product-props.js +64 -62
  55. package/dist/esm/libs/api/get-static-page-props-preview.js +128 -121
  56. package/dist/esm/libs/api/get-static-page-props-v2.js +126 -119
  57. package/dist/esm/libs/api/get-static-page-props.js +130 -120
  58. package/dist/esm/libs/fetcher.js +59 -63
  59. package/dist/esm/libs/get-layout.js +5 -2
  60. package/dist/esm/libs/get-storefront-api.js +7 -7
  61. package/dist/esm/libs/getStaticPaths.js +5 -5
  62. package/dist/esm/libs/google-fonts.js +54 -61
  63. package/dist/esm/libs/helpers/gen-css.js +103 -94
  64. package/dist/esm/libs/helpers/generate-manifres.js +1 -1
  65. package/dist/esm/libs/helpers/get-fallback.js +24 -22
  66. package/dist/esm/libs/helpers/normalize.js +82 -80
  67. package/dist/esm/libs/helpers/parse-json.js +10 -12
  68. package/dist/esm/libs/helpers/user-agent.js +2 -2
  69. package/dist/esm/libs/hooks/use-tracking-view.js +36 -31
  70. package/dist/esm/libs/parse-html.js +33 -26
  71. package/dist/esm/pages/404.js +34 -2
  72. package/dist/esm/pages/500.js +63 -8
  73. package/dist/esm/pages/builder.js +69 -14
  74. package/dist/esm/pages/collection-detail.js +48 -7
  75. package/dist/esm/pages/preview.js +18 -12
  76. package/dist/esm/pages/product-detail.js +53 -7
  77. package/dist/esm/pages/static-v2.js +62 -7
  78. package/dist/esm/pages/static.js +60 -6
  79. 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, { ...pageProps, children: page });
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 (provider) {
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,8 +1,8 @@
1
- const getStaticPaths = async () => {
2
- return {
3
- paths: [],
4
- fallback: true,
5
- };
1
+ const getStaticPaths = async ()=>{
2
+ return {
3
+ paths: [],
4
+ fallback: true
5
+ };
6
6
  };
7
7
 
8
8
  export { getStaticPaths };
@@ -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) => res.text());
9
- }
10
- const createFontUrl = (fonts, option) => {
11
- const params = new URLSearchParams();
12
- const display = option?.display || 'swap';
13
- const family = fonts
14
- .filter((font, index, arr) => {
15
- return index === arr.findIndex((t) => t.family === font.family);
16
- })
17
- .map((font) => {
18
- return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
19
- })
20
- .join('|');
21
- params.append('family', family);
22
- params.append('display', display);
23
- if (option?.subset) {
24
- params.append('subset', option.subset);
25
- }
26
- if (option?.effect) {
27
- params.append('effect', option.effect);
28
- }
29
- return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
30
- };
31
- async function getFonts(fonts, option) {
32
- /**
33
- * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
34
- * CSS cascading 🤷‍♂️.
35
- */
36
- const url = createFontUrl(fonts, option);
37
- try {
38
- const [ie, chrome] = await Promise.all([
39
- getFontForUA(url, IE_UA),
40
- getFontForUA(url, CHROME_UA),
41
- ]);
42
- return ie + chrome;
43
- }
44
- catch (e) {
45
- return '';
46
- }
47
- }
48
- const getFontFromGlobalStyle = (data) => {
49
- if (!data)
50
- return '';
51
- try {
52
- const globalStyle = JSON.parse(data);
53
- const fonts = globalStyle?.font ?? {};
54
- const font = Object.entries(fonts).map(([, value]) => {
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
- Object.assign(acc, flattenObject(obj[k], pre + k));
13
- else
14
- acc[pre + k] = obj[k];
15
- return acc;
16
- }, {});
17
- };
18
- const devicesOrder = ['desktop', 'tablet', 'mobile'];
19
- const mapObject = (obj) => {
20
- return Object.entries(obj ?? {}).reduce((acc, [k, v]) => {
21
- return {
22
- ...acc,
23
- [getShortName(k)]: typeof v === 'object' ? mapObject(v) : v,
24
- };
25
- }, {});
26
- };
27
- const getValueByDevice = (data, device) => {
28
- const deviceData = {
29
- typography: Object.fromEntries(Object.entries(data?.typography ?? {}).map(([key, value]) => {
30
- const typo = { ...value?.[device] };
31
- if (!typo)
32
- return [key, undefined];
33
- if (typo.fontFamily) {
34
- typo.fontFamily = `var(--g-font-${typo.fontFamily}, ${typo.fontFamily})`;
35
- }
36
- return [key, typo];
37
- })),
38
- spacing: Object.fromEntries(Object.entries(data?.spacing ?? {}).map(([key, value]) => {
39
- return [key, value?.[device]];
40
- })),
41
- container: Object.fromEntries(Object.entries(data?.container ?? {}).map(([key, value]) => {
42
- return [key, value?.[device]];
43
- })),
44
- font: Object.fromEntries(Object.entries(data?.font ?? {}).map(([key, value]) => {
45
- return [key, value?.family];
46
- })),
47
- };
48
- return deviceData;
49
- };
50
- const genCSSVariable = (deviceData) => {
51
- return Object.entries(mapObject(flattenObject(deviceData)))
52
- .map(([key, value]) => {
53
- if (value === undefined)
54
- return undefined;
55
- return `--g-${key}:${value}`;
56
- })
57
- .filter((v) => v !== undefined)
58
- .join(';');
59
- };
60
- const genCSS = (input, mobileOnly) => {
61
- if (!input)
62
- return '';
63
- let data = {};
64
- try {
65
- if (typeof input === 'string') {
66
- data = JSON.parse(input);
67
- }
68
- else {
69
- data = input;
70
- }
71
- if (mobileOnly) {
72
- const desktop = getValueByDevice(data, 'desktop');
73
- const mobile = getValueByDevice(data, 'mobile');
74
- const deviceData = merge(desktop, mobile);
75
- deviceData.color = data.color;
76
- deviceData.radius = data.radius;
77
- const cssData = genCSSVariable(deviceData);
78
- return `:root{${cssData}}`;
79
- }
80
- return devicesOrder
81
- .map((device) => {
82
- const deviceData = getValueByDevice(data, device);
83
- if (device === 'desktop') {
84
- deviceData.color = data.color;
85
- deviceData.radius = data.radius;
86
- }
87
- const cssData = genCSSVariable(deviceData);
88
- if (device === 'desktop') {
89
- return `:root{${cssData}}`;
90
- }
91
- return `@media (max-width: ${baseDevices[device]}) {:root{${cssData}}}`;
92
- })
93
- .join('\n');
94
- }
95
- catch {
96
- return '';
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,3 +1,3 @@
1
- const generateManifest = (data) => `data:application/manifest+json,${encodeURIComponent(JSON.stringify(data))}`;
1
+ const generateManifest = (data)=>`data:application/manifest+json,${encodeURIComponent(JSON.stringify(data))}`;
2
2
 
3
3
  export { generateManifest };
@@ -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) => 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)
11
- return fetcher([query, variables]);
12
- return {};
13
- }));
14
- const fallback = queries.reduce((acc, { key }, index) => {
15
- const res = datas[index];
16
- if (res?.status === 'fulfilled') {
17
- return {
18
- ...acc,
19
- [key]: res.value,
20
- };
21
- }
22
- return acc;
23
- }, {});
24
- return fallback;
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
- else {
10
- const items = childrens?.map((child) => child?.uid) ?? [];
11
- currData[rest.uid] = { ...rest, childrens: items };
12
- if (childrens) {
13
- childrens.map((child) => compose(child, currData));
14
- }
15
- }
16
- }
17
- }
18
- compose(data, result);
19
- return { ...result };
20
- };
21
- const orderSection = (sections, orders) => {
22
- // Filter out sections that are not in the order list
23
- const ids = orders?.filter((id) => sections?.some((v) => v?.id === id));
24
- // Return the ordered sections
25
- const orderedSections = ids?.map((id) => sections?.find((v) => v?.id === id)) ?? [];
26
- // Return the sections that are not in the order list
27
- const sectionsNotInOrder = sections?.filter((v) => !v?.id || !ids?.includes(v.id)) ?? [];
28
- // Return the ordered sections + the sections that are not in the order list
29
- return orderedSections.concat(sectionsNotInOrder);
30
- };
31
- function normalizePageSectionResponse(sections, orders) {
32
- const sortedSections = orderSection(sections, orders);
33
- const childrens = sortedSections
34
- .map((item) => {
35
- if (!item?.component)
36
- return false;
37
- try {
38
- const data = JSON.parse(item.component);
39
- return data;
40
- }
41
- catch {
42
- return false;
43
- }
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
55
- .map((item) => {
56
- if (!item?.component)
57
- return false;
58
- try {
59
- const data = JSON.parse(item.component);
60
- return data;
61
- }
62
- catch {
63
- return false;
64
- }
65
- })
66
- .filter(Boolean);
67
- return childrens.map((v) => {
68
- return {
69
- uid: v.uid,
70
- lazy: Boolean(v.settings?.lazy),
71
- priority: Boolean(v.settings?.priority),
72
- data: normalizeBuilderData(v),
73
- };
74
- });
75
- }
76
- const parseBuilderTemplateV2 = (data) => {
77
- return normalizePageSectionResponseV2([...(data?.pageSections ?? []), ...(data?.themePageCustomSections ?? [])], data?.sectionPosition);
78
- };
79
- const parseBuilderTemplate = (data) => {
80
- return normalizePageSectionResponse([...(data?.pageSections ?? []), ...(data?.themePageCustomSections ?? [])], data?.sectionPosition);
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
- return null;
4
- try {
5
- return JSON.parse(json);
6
- }
7
- catch (e) {
8
- return null;
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 };