@gem-sdk/pages 1.0.3 → 1.4.0
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/index.js +4 -0
- package/dist/cjs/layouts/main.js +3 -2
- package/dist/cjs/libs/api/get-home-page-props-v2.js +1 -0
- package/dist/cjs/libs/api/get-static-page-props-preview.js +2 -0
- package/dist/cjs/libs/api/get-static-page-props-v2.js +3 -0
- package/dist/cjs/libs/get-layout.js +2 -2
- package/dist/cjs/libs/helpers/user-agent.js +7 -0
- package/dist/cjs/libs/hooks/use-tracking-view.js +40 -0
- package/dist/cjs/libs/parse-html.js +35 -0
- package/dist/cjs/pages/static-v2.js +5 -2
- package/dist/esm/index.js +2 -0
- package/dist/esm/layouts/main.js +3 -2
- package/dist/esm/libs/api/get-home-page-props-v2.js +1 -0
- package/dist/esm/libs/api/get-static-page-props-preview.js +2 -0
- package/dist/esm/libs/api/get-static-page-props-v2.js +3 -0
- package/dist/esm/libs/get-layout.js +2 -2
- package/dist/esm/libs/helpers/user-agent.js +5 -0
- package/dist/esm/libs/hooks/use-tracking-view.js +38 -0
- package/dist/esm/libs/parse-html.js +33 -0
- package/dist/esm/pages/static-v2.js +5 -2
- package/dist/types/index.d.ts +10 -3
- package/package.json +4 -3
package/dist/cjs/index.js
CHANGED
|
@@ -12,6 +12,8 @@ var getStaticPagePropsPreview = require('./libs/api/get-static-page-props-previe
|
|
|
12
12
|
var fetcher = require('./libs/fetcher.js');
|
|
13
13
|
var getLayout = require('./libs/get-layout.js');
|
|
14
14
|
var genCss = require('./libs/helpers/gen-css.js');
|
|
15
|
+
var useTrackingView = require('./libs/hooks/use-tracking-view.js');
|
|
16
|
+
var userAgent = require('./libs/helpers/user-agent.js');
|
|
15
17
|
var collectionDetail = require('./pages/collection-detail.js');
|
|
16
18
|
var preview = require('./pages/preview.js');
|
|
17
19
|
var productDetail = require('./pages/product-detail.js');
|
|
@@ -44,6 +46,8 @@ exports.createFetcher = fetcher.createFetcher;
|
|
|
44
46
|
exports.createShopifyFetcher = fetcher.createShopifyFetcher;
|
|
45
47
|
exports.getLayout = getLayout.getLayout;
|
|
46
48
|
exports.genCSS = genCss.genCSS;
|
|
49
|
+
exports.useTrackingView = useTrackingView.useTrackingView;
|
|
50
|
+
exports.isBot = userAgent.isBot;
|
|
47
51
|
exports.CollectionDetailPage = collectionDetail.default;
|
|
48
52
|
exports.PreviewPage = preview.PreviewPage;
|
|
49
53
|
exports.ProductDetailPage = productDetail.default;
|
package/dist/cjs/layouts/main.js
CHANGED
|
@@ -4,10 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var core = require('@gem-sdk/core');
|
|
7
|
+
var parseHtml = require('../libs/parse-html.js');
|
|
7
8
|
|
|
8
|
-
const MainLayout = ({ children }) => {
|
|
9
|
+
const MainLayout = ({ children, ...props }) => {
|
|
9
10
|
const mobileOnly = core.useShopStore((s) => s.mobileOnly);
|
|
10
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: core.cls({
|
|
11
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [parseHtml.parseHtml(props?.customCodeBody), jsxRuntime.jsx("div", { className: core.cls({
|
|
11
12
|
'max-w-mobile mx-auto w-full': mobileOnly,
|
|
12
13
|
}), children: children }), jsxRuntime.jsx(core.AddOn, { name: "cookie-bar" }), jsxRuntime.jsx(core.AddOn, { name: "cart-drawer" })] }));
|
|
13
14
|
};
|
|
@@ -116,6 +116,7 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher) => async () => {
|
|
|
116
116
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
117
117
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
118
118
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
119
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
catch (err) {
|
|
@@ -122,6 +122,8 @@ const getStaticPagePropsPreview = (fetcher, shopifyFetcher) => async (slug) => {
|
|
|
122
122
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
123
123
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
124
124
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
125
|
+
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
126
|
+
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
125
127
|
});
|
|
126
128
|
}
|
|
127
129
|
catch (err) {
|
|
@@ -119,6 +119,9 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher) => async (slug) => {
|
|
|
119
119
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
120
120
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
121
121
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
122
|
+
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
123
|
+
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
124
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
122
125
|
});
|
|
123
126
|
}
|
|
124
127
|
catch (err) {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var main = require('../layouts/main.js');
|
|
5
5
|
|
|
6
|
-
const getLayout = (page) => {
|
|
7
|
-
return jsxRuntime.jsx(main.default, { children: page });
|
|
6
|
+
const getLayout = (page, pageProps) => {
|
|
7
|
+
return jsxRuntime.jsx(main.default, { ...pageProps, children: page });
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
exports.getLayout = getLayout;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function isBot(input) {
|
|
4
|
+
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|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);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
exports.isBot = isBot;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var userAgent = require('../helpers/user-agent.js');
|
|
6
|
+
|
|
7
|
+
const useTrackingView = (token, handle, isFallback) => {
|
|
8
|
+
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
9
|
+
const apiURL = process.env.NEXT_PUBLIC_API_URL;
|
|
10
|
+
const sendTracking = react.useCallback((handle) => {
|
|
11
|
+
if (!apiURL || !shopToken)
|
|
12
|
+
return;
|
|
13
|
+
const bot = userAgent.isBot(navigator.userAgent);
|
|
14
|
+
const variables = {
|
|
15
|
+
pageHandle: handle,
|
|
16
|
+
userAgent: bot ? 'BOT' : 'BROWSER',
|
|
17
|
+
};
|
|
18
|
+
const headers = {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'X-GemX-Shop-Token': shopToken,
|
|
21
|
+
};
|
|
22
|
+
fetch(apiURL, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers,
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
query: core.PageViewUpDocument,
|
|
27
|
+
variables,
|
|
28
|
+
}),
|
|
29
|
+
}).finally(() => {
|
|
30
|
+
//
|
|
31
|
+
});
|
|
32
|
+
}, [apiURL, shopToken]);
|
|
33
|
+
react.useEffect(() => {
|
|
34
|
+
if (!handle || isFallback)
|
|
35
|
+
return;
|
|
36
|
+
sendTracking(handle);
|
|
37
|
+
}, [handle, sendTracking, isFallback]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.useTrackingView = useTrackingView;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var parse = require('html-react-parser');
|
|
5
|
+
var Script = require('next/script');
|
|
6
|
+
|
|
7
|
+
const parseHtml = (html, isHead) => {
|
|
8
|
+
if (!html)
|
|
9
|
+
return undefined;
|
|
10
|
+
try {
|
|
11
|
+
return parse(html, {
|
|
12
|
+
replace: (node) => {
|
|
13
|
+
if (node.type === 'script' && node instanceof parse.Element) {
|
|
14
|
+
const child = node.children?.[0];
|
|
15
|
+
if (child instanceof parse.Text) {
|
|
16
|
+
if (isHead)
|
|
17
|
+
return jsxRuntime.jsx("script", { ...node.attribs, dangerouslySetInnerHTML: { __html: child.data } });
|
|
18
|
+
else
|
|
19
|
+
return jsxRuntime.jsx(Script, { ...node.attribs, dangerouslySetInnerHTML: { __html: child.data } });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (!isHead) {
|
|
23
|
+
return jsxRuntime.jsx(Script, { ...node.attribs });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.parseHtml = parseHtml;
|
|
@@ -5,13 +5,16 @@ var core = require('@gem-sdk/core');
|
|
|
5
5
|
var nextSeo = require('next-seo');
|
|
6
6
|
var Head = require('next/head');
|
|
7
7
|
var router = require('next/router');
|
|
8
|
+
var useTrackingView = require('../libs/hooks/use-tracking-view.js');
|
|
9
|
+
var parseHtml = require('../libs/parse-html.js');
|
|
8
10
|
|
|
9
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, }) => {
|
|
11
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, shopToken, pageHandle, }) => {
|
|
10
12
|
const router$1 = router.useRouter();
|
|
13
|
+
useTrackingView.useTrackingView(shopToken, pageHandle, router$1.isFallback);
|
|
11
14
|
if (router$1.isFallback) {
|
|
12
15
|
return (jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: jsxRuntime.jsxs("div", { className: "flex gap-2", children: [jsxRuntime.jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_alternate] rounded-full bg-slate-800" }), jsxRuntime.jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_200ms_linear_alternate] rounded-full bg-slate-800" }), jsxRuntime.jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_500ms_alternate] rounded-full bg-slate-800" })] }) }));
|
|
13
16
|
}
|
|
14
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(nextSeo.NextSeo, { ...seo }), jsxRuntime.jsxs(Head, { children: [themeStyle && (jsxRuntime.jsx("style", { "data-id": "global-style", type: "text/css", dangerouslySetInnerHTML: { __html: themeStyle } })), fontStyle && (jsxRuntime.jsx("style", { "data-id": "google-fonts", type: "text/css", dangerouslySetInnerHTML: { __html: fontStyle } }))] }), jsxRuntime.jsx(core.BuilderComponentProvider, { components: components, children: jsxRuntime.jsx(core.SectionProvider, { data: sectionData, children: builderData?.map((builder) => (jsxRuntime.jsx(core.BuilderProvider, { state: builder.data, lazy: builder.lazy, priority: builder.priority, children: jsxRuntime.jsx(core.Render, { uid: builder.uid }) }, builder.uid))) }) })] }));
|
|
17
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(nextSeo.NextSeo, { ...seo }), jsxRuntime.jsxs(Head, { children: [parseHtml.parseHtml(customCodeHeader, true), themeStyle && (jsxRuntime.jsx("style", { "data-id": "global-style", type: "text/css", dangerouslySetInnerHTML: { __html: themeStyle } })), fontStyle && (jsxRuntime.jsx("style", { "data-id": "google-fonts", type: "text/css", dangerouslySetInnerHTML: { __html: fontStyle } }))] }), jsxRuntime.jsx(core.BuilderComponentProvider, { components: components, children: jsxRuntime.jsx(core.SectionProvider, { data: sectionData, children: builderData?.map((builder) => (jsxRuntime.jsx(core.BuilderProvider, { state: builder.data, lazy: builder.lazy, priority: builder.priority, children: jsxRuntime.jsx(core.Render, { uid: builder.uid }) }, builder.uid))) }) })] }));
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
exports.StaticPageV2 = StaticPageV2;
|
package/dist/esm/index.js
CHANGED
|
@@ -10,6 +10,8 @@ export { getStaticPagePropsPreview } from './libs/api/get-static-page-props-prev
|
|
|
10
10
|
export { createFetcher, createShopifyFetcher } from './libs/fetcher.js';
|
|
11
11
|
export { getLayout } from './libs/get-layout.js';
|
|
12
12
|
export { genCSS } from './libs/helpers/gen-css.js';
|
|
13
|
+
export { useTrackingView } from './libs/hooks/use-tracking-view.js';
|
|
14
|
+
export { isBot } from './libs/helpers/user-agent.js';
|
|
13
15
|
export { default as CollectionDetailPage } from './pages/collection-detail.js';
|
|
14
16
|
export { PreviewPage } from './pages/preview.js';
|
|
15
17
|
export { default as ProductDetailPage } from './pages/product-detail.js';
|
package/dist/esm/layouts/main.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useShopStore, cls, AddOn } from '@gem-sdk/core';
|
|
3
|
+
import { parseHtml } from '../libs/parse-html.js';
|
|
3
4
|
|
|
4
|
-
const MainLayout = ({ children }) => {
|
|
5
|
+
const MainLayout = ({ children, ...props }) => {
|
|
5
6
|
const mobileOnly = useShopStore((s) => s.mobileOnly);
|
|
6
|
-
return (jsxs(Fragment, { children: [jsx("div", { className: cls({
|
|
7
|
+
return (jsxs(Fragment, { children: [parseHtml(props?.customCodeBody), jsx("div", { className: cls({
|
|
7
8
|
'max-w-mobile mx-auto w-full': mobileOnly,
|
|
8
9
|
}), children: children }), jsx(AddOn, { name: "cookie-bar" }), jsx(AddOn, { name: "cart-drawer" })] }));
|
|
9
10
|
};
|
|
@@ -114,6 +114,7 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher) => async () => {
|
|
|
114
114
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
115
115
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
116
116
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
117
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
catch (err) {
|
|
@@ -120,6 +120,8 @@ const getStaticPagePropsPreview = (fetcher, shopifyFetcher) => async (slug) => {
|
|
|
120
120
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
121
121
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
122
122
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
123
|
+
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
124
|
+
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
catch (err) {
|
|
@@ -117,6 +117,9 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher) => async (slug) => {
|
|
|
117
117
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
118
118
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
119
119
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
120
|
+
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
121
|
+
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
122
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
120
123
|
});
|
|
121
124
|
}
|
|
122
125
|
catch (err) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import MainLayout from '../layouts/main.js';
|
|
3
3
|
|
|
4
|
-
const getLayout = (page) => {
|
|
5
|
-
return jsx(MainLayout, { children: page });
|
|
4
|
+
const getLayout = (page, pageProps) => {
|
|
5
|
+
return jsx(MainLayout, { ...pageProps, children: page });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export { getLayout };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function isBot(input) {
|
|
2
|
+
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|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
|
+
}
|
|
4
|
+
|
|
5
|
+
export { isBot };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PageViewUpDocument } from '@gem-sdk/core';
|
|
2
|
+
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { isBot } from '../helpers/user-agent.js';
|
|
4
|
+
|
|
5
|
+
const useTrackingView = (token, handle, isFallback) => {
|
|
6
|
+
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
7
|
+
const apiURL = process.env.NEXT_PUBLIC_API_URL;
|
|
8
|
+
const sendTracking = useCallback((handle) => {
|
|
9
|
+
if (!apiURL || !shopToken)
|
|
10
|
+
return;
|
|
11
|
+
const bot = isBot(navigator.userAgent);
|
|
12
|
+
const variables = {
|
|
13
|
+
pageHandle: handle,
|
|
14
|
+
userAgent: bot ? 'BOT' : 'BROWSER',
|
|
15
|
+
};
|
|
16
|
+
const headers = {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
'X-GemX-Shop-Token': shopToken,
|
|
19
|
+
};
|
|
20
|
+
fetch(apiURL, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers,
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
query: PageViewUpDocument,
|
|
25
|
+
variables,
|
|
26
|
+
}),
|
|
27
|
+
}).finally(() => {
|
|
28
|
+
//
|
|
29
|
+
});
|
|
30
|
+
}, [apiURL, shopToken]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!handle || isFallback)
|
|
33
|
+
return;
|
|
34
|
+
sendTracking(handle);
|
|
35
|
+
}, [handle, sendTracking, isFallback]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { useTrackingView };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import parse, { Element, Text } from 'html-react-parser';
|
|
3
|
+
import Script from 'next/script';
|
|
4
|
+
|
|
5
|
+
const parseHtml = (html, isHead) => {
|
|
6
|
+
if (!html)
|
|
7
|
+
return undefined;
|
|
8
|
+
try {
|
|
9
|
+
return parse(html, {
|
|
10
|
+
replace: (node) => {
|
|
11
|
+
if (node.type === 'script' && node instanceof Element) {
|
|
12
|
+
const child = node.children?.[0];
|
|
13
|
+
if (child instanceof Text) {
|
|
14
|
+
if (isHead)
|
|
15
|
+
return jsx("script", { ...node.attribs, dangerouslySetInnerHTML: { __html: child.data } });
|
|
16
|
+
else
|
|
17
|
+
return jsx(Script, { ...node.attribs, dangerouslySetInnerHTML: { __html: child.data } });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (!isHead) {
|
|
21
|
+
return jsx(Script, { ...node.attribs });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { parseHtml };
|
|
@@ -3,13 +3,16 @@ import { BuilderComponentProvider, SectionProvider, BuilderProvider, Render } fr
|
|
|
3
3
|
import { NextSeo } from 'next-seo';
|
|
4
4
|
import Head from 'next/head';
|
|
5
5
|
import { useRouter } from 'next/router';
|
|
6
|
+
import { useTrackingView } from '../libs/hooks/use-tracking-view.js';
|
|
7
|
+
import { parseHtml } from '../libs/parse-html.js';
|
|
6
8
|
|
|
7
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, }) => {
|
|
9
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, shopToken, pageHandle, }) => {
|
|
8
10
|
const router = useRouter();
|
|
11
|
+
useTrackingView(shopToken, pageHandle, router.isFallback);
|
|
9
12
|
if (router.isFallback) {
|
|
10
13
|
return (jsx("div", { className: "flex h-full items-center justify-center", children: jsxs("div", { className: "flex gap-2", children: [jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_alternate] rounded-full bg-slate-800" }), jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_200ms_linear_alternate] rounded-full bg-slate-800" }), jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_500ms_alternate] rounded-full bg-slate-800" })] }) }));
|
|
11
14
|
}
|
|
12
|
-
return (jsxs(Fragment, { children: [jsx(NextSeo, { ...seo }), jsxs(Head, { children: [themeStyle && (jsx("style", { "data-id": "global-style", type: "text/css", dangerouslySetInnerHTML: { __html: themeStyle } })), fontStyle && (jsx("style", { "data-id": "google-fonts", type: "text/css", dangerouslySetInnerHTML: { __html: fontStyle } }))] }), jsx(BuilderComponentProvider, { components: components, children: jsx(SectionProvider, { data: sectionData, children: builderData?.map((builder) => (jsx(BuilderProvider, { state: builder.data, lazy: builder.lazy, priority: builder.priority, children: jsx(Render, { uid: builder.uid }) }, builder.uid))) }) })] }));
|
|
15
|
+
return (jsxs(Fragment, { children: [jsx(NextSeo, { ...seo }), jsxs(Head, { children: [parseHtml(customCodeHeader, true), themeStyle && (jsx("style", { "data-id": "global-style", type: "text/css", dangerouslySetInnerHTML: { __html: themeStyle } })), fontStyle && (jsx("style", { "data-id": "google-fonts", type: "text/css", dangerouslySetInnerHTML: { __html: fontStyle } }))] }), jsx(BuilderComponentProvider, { components: components, children: jsx(SectionProvider, { data: sectionData, children: builderData?.map((builder) => (jsx(BuilderProvider, { state: builder.data, lazy: builder.lazy, priority: builder.priority, children: jsx(Render, { uid: builder.uid }) }, builder.uid))) }) })] }));
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
export { StaticPageV2 };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ type PageBuilderProps = {
|
|
|
18
18
|
storefrontToken?: string | null;
|
|
19
19
|
storefrontHandle?: string | null;
|
|
20
20
|
shopToken?: string | null;
|
|
21
|
+
pageHandle?: string | null;
|
|
21
22
|
currency?: string | null;
|
|
22
23
|
locale?: string | null;
|
|
23
24
|
favicon?: string | null;
|
|
@@ -27,6 +28,8 @@ type PageBuilderProps = {
|
|
|
27
28
|
gaTrackingId?: string | null;
|
|
28
29
|
tiktokPixelId?: string | null;
|
|
29
30
|
facebookPixelId?: string | null;
|
|
31
|
+
customCodeHeader?: string | null;
|
|
32
|
+
customCodeBody?: string | null;
|
|
30
33
|
};
|
|
31
34
|
type PageBuilderPropsV2 = {
|
|
32
35
|
builderData?: {
|
|
@@ -40,7 +43,7 @@ type AdditionalPageBuilderProps = {
|
|
|
40
43
|
components: Record<string, React.ComponentType<any>>;
|
|
41
44
|
};
|
|
42
45
|
type NextPageWithLayout<P = PageBuilderProps, IP = P> = NextPage<P, IP> & {
|
|
43
|
-
getLayout?: (page: React.ReactElement) => React.ReactNode;
|
|
46
|
+
getLayout?: (page: React.ReactElement, pageProps?: any) => React.ReactNode;
|
|
44
47
|
};
|
|
45
48
|
type AppPropsWithLayout<P = PageBuilderProps> = AppProps<P> & {
|
|
46
49
|
Component: NextPageWithLayout;
|
|
@@ -78,10 +81,14 @@ declare const getStaticPagePropsPreview: (fetcher: FetchFunc, shopifyFetcher: Fe
|
|
|
78
81
|
declare const createFetcher: (token?: string | null) => FetchFunc;
|
|
79
82
|
declare const createShopifyFetcher: (storefrontToken?: string, handle?: string) => FetchFunc;
|
|
80
83
|
|
|
81
|
-
declare const getLayout: (page: React.ReactElement) => JSX.Element;
|
|
84
|
+
declare const getLayout: (page: React.ReactElement, pageProps?: any) => JSX.Element;
|
|
82
85
|
|
|
83
86
|
declare const genCSS: (input?: string | Record<string, any>, mobileOnly?: boolean) => string;
|
|
84
87
|
|
|
88
|
+
declare const useTrackingView: (token?: string | null, handle?: string | null, isFallback?: boolean) => void;
|
|
89
|
+
|
|
90
|
+
declare function isBot(input: string): boolean;
|
|
91
|
+
|
|
85
92
|
type PreviewPageProps = {
|
|
86
93
|
components: Record<string, React.ComponentType<any>>;
|
|
87
94
|
pageType: ShopType.PublishedThemePageType;
|
|
@@ -170,4 +177,4 @@ type Props = {
|
|
|
170
177
|
};
|
|
171
178
|
declare const TikTokPixel: ({ pixelId }: Props) => JSX.Element | null;
|
|
172
179
|
|
|
173
|
-
export { AppPropsWithLayout, BuilderPage, CollectionDetailPage, CollectionPageProps, ErrorBoundary, ErrorFallback, FacebookPixel, GoogleAnalytic, NextPageWithLayout, Page404, Page500, PageBuilderProps, PreviewPage, ProductDetailPage, ProductPageProps, StaticPage, StaticPageProps, StaticPagePropsV2, StaticPageV2, TikTokPixel, createFetcher, createShopifyFetcher, genCSS, getBuilderProps, getCollectionProps, getFonts, getHomePageProps, getHomePagePropsV2, getLayout, getPreviewProps, getProductProps, getStaticPageProps, getStaticPagePropsPreview, getStaticPagePropsV2, getStaticPaths, getStorefrontApi };
|
|
180
|
+
export { AppPropsWithLayout, BuilderPage, CollectionDetailPage, CollectionPageProps, ErrorBoundary, ErrorFallback, FacebookPixel, GoogleAnalytic, NextPageWithLayout, Page404, Page500, PageBuilderProps, PreviewPage, ProductDetailPage, ProductPageProps, StaticPage, StaticPageProps, StaticPagePropsV2, StaticPageV2, TikTokPixel, createFetcher, createShopifyFetcher, genCSS, getBuilderProps, getCollectionProps, getFonts, getHomePageProps, getHomePagePropsV2, getLayout, getPreviewProps, getProductProps, getStaticPageProps, getStaticPagePropsPreview, getStaticPagePropsV2, getStaticPaths, getStorefrontApi, isBot, useTrackingView };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/pages",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@sentry/nextjs": "7.21.1",
|
|
23
23
|
"deepmerge": "4.2.2",
|
|
24
|
+
"html-react-parser": "^3.0.7",
|
|
24
25
|
"next-seo": "^5.15.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
28
|
+
"@gem-sdk/core": "*",
|
|
27
29
|
"@gem-sdk/plugin-cookie-bar": "*",
|
|
28
30
|
"@gem-sdk/plugin-quick-view": "*",
|
|
29
|
-
"@gem-sdk/plugin-sticky-add-to-cart": "*"
|
|
30
|
-
"@gem-sdk/core": "*"
|
|
31
|
+
"@gem-sdk/plugin-sticky-add-to-cart": "*"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"next": ">=13"
|