@gem-sdk/pages 1.0.3 → 1.1.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/layouts/main.js +3 -2
- package/dist/cjs/libs/api/get-static-page-props-preview.js +2 -0
- package/dist/cjs/libs/api/get-static-page-props-v2.js +2 -0
- package/dist/cjs/libs/get-layout.js +2 -2
- package/dist/cjs/libs/parse-html.js +35 -0
- package/dist/cjs/pages/static-v2.js +3 -2
- package/dist/esm/layouts/main.js +3 -2
- package/dist/esm/libs/api/get-static-page-props-preview.js +2 -0
- package/dist/esm/libs/api/get-static-page-props-v2.js +2 -0
- package/dist/esm/libs/get-layout.js +2 -2
- package/dist/esm/libs/parse-html.js +33 -0
- package/dist/esm/pages/static-v2.js +3 -2
- package/dist/types/index.d.ts +4 -2
- package/package.json +4 -3
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
|
};
|
|
@@ -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,8 @@ 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,
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
126
|
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,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,14 @@ 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 parseHtml = require('../libs/parse-html.js');
|
|
8
9
|
|
|
9
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, }) => {
|
|
10
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, }) => {
|
|
10
11
|
const router$1 = router.useRouter();
|
|
11
12
|
if (router$1.isFallback) {
|
|
12
13
|
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
14
|
}
|
|
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))) }) })] }));
|
|
15
|
+
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
16
|
};
|
|
16
17
|
|
|
17
18
|
exports.StaticPageV2 = StaticPageV2;
|
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
|
};
|
|
@@ -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,8 @@ 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,
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
124
|
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,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,14 @@ 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 { parseHtml } from '../libs/parse-html.js';
|
|
6
7
|
|
|
7
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, }) => {
|
|
8
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, }) => {
|
|
8
9
|
const router = useRouter();
|
|
9
10
|
if (router.isFallback) {
|
|
10
11
|
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
12
|
}
|
|
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))) }) })] }));
|
|
13
|
+
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
14
|
};
|
|
14
15
|
|
|
15
16
|
export { StaticPageV2 };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ type PageBuilderProps = {
|
|
|
27
27
|
gaTrackingId?: string | null;
|
|
28
28
|
tiktokPixelId?: string | null;
|
|
29
29
|
facebookPixelId?: string | null;
|
|
30
|
+
customCodeHeader?: string | null;
|
|
31
|
+
customCodeBody?: string | null;
|
|
30
32
|
};
|
|
31
33
|
type PageBuilderPropsV2 = {
|
|
32
34
|
builderData?: {
|
|
@@ -40,7 +42,7 @@ type AdditionalPageBuilderProps = {
|
|
|
40
42
|
components: Record<string, React.ComponentType<any>>;
|
|
41
43
|
};
|
|
42
44
|
type NextPageWithLayout<P = PageBuilderProps, IP = P> = NextPage<P, IP> & {
|
|
43
|
-
getLayout?: (page: React.ReactElement) => React.ReactNode;
|
|
45
|
+
getLayout?: (page: React.ReactElement, pageProps?: any) => React.ReactNode;
|
|
44
46
|
};
|
|
45
47
|
type AppPropsWithLayout<P = PageBuilderProps> = AppProps<P> & {
|
|
46
48
|
Component: NextPageWithLayout;
|
|
@@ -78,7 +80,7 @@ declare const getStaticPagePropsPreview: (fetcher: FetchFunc, shopifyFetcher: Fe
|
|
|
78
80
|
declare const createFetcher: (token?: string | null) => FetchFunc;
|
|
79
81
|
declare const createShopifyFetcher: (storefrontToken?: string, handle?: string) => FetchFunc;
|
|
80
82
|
|
|
81
|
-
declare const getLayout: (page: React.ReactElement) => JSX.Element;
|
|
83
|
+
declare const getLayout: (page: React.ReactElement, pageProps?: any) => JSX.Element;
|
|
82
84
|
|
|
83
85
|
declare const genCSS: (input?: string | Record<string, any>, mobileOnly?: boolean) => string;
|
|
84
86
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/pages",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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"
|