@gem-sdk/pages 1.58.0-staging.43 → 1.58.0-staging.54

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.
@@ -11,7 +11,7 @@ const MainLayout = ({ children, ...props })=>{
11
11
  const mobileOnly = core.useShopStore((s)=>s.mobileOnly);
12
12
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
13
13
  children: [
14
- parseHtml.parseHtml(props?.customCodeBody),
14
+ parseHtml.parseHtml('custom-code-body', props?.customCodeBody),
15
15
  /*#__PURE__*/ jsxRuntime.jsx("div", {
16
16
  className: core.cls({
17
17
  'gp-max-w-mobile gp-mx-auto gp-w-full': mobileOnly
@@ -2,35 +2,27 @@
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var parse = require('html-react-parser');
5
- var Script = require('next/script');
6
5
 
7
- const parseHtml = (html, isHead)=>{
6
+ const parseHtml = (key, html, isHead)=>{
8
7
  if (!html) return undefined;
9
8
  try {
10
9
  return parse(html, {
11
10
  replace: (node)=>{
12
- if (node.type === 'script' && node instanceof parse.Element) {
13
- const child = node.children?.[0];
14
- if (child instanceof parse.Text) {
15
- if (isHead) return /*#__PURE__*/ jsxRuntime.jsx("script", {
16
- ...node.attribs,
17
- dangerouslySetInnerHTML: {
18
- __html: child.data
19
- }
20
- });
21
- else return /*#__PURE__*/ jsxRuntime.jsx(Script, {
22
- ...node.attribs,
23
- dangerouslySetInnerHTML: {
24
- __html: child.data
25
- }
26
- });
27
- } else {
28
- if (!isHead) {
29
- return /*#__PURE__*/ jsxRuntime.jsx(Script, {
30
- ...node.attribs
31
- });
11
+ if (node.type !== 'script' || !(node instanceof parse.Element)) return null;
12
+ const child = node.children?.[0];
13
+ if (!child) return null;
14
+ if (!(child instanceof parse.Text) && !isHead) return /*#__PURE__*/ jsxRuntime.jsx("script", {
15
+ id: key,
16
+ ...node.attribs
17
+ }, key);
18
+ if (child instanceof parse.Text && isHead) {
19
+ return /*#__PURE__*/ jsxRuntime.jsx("script", {
20
+ id: key,
21
+ ...node.attribs,
22
+ dangerouslySetInnerHTML: {
23
+ __html: child.data
32
24
  }
33
- }
25
+ }, key);
34
26
  }
35
27
  }
36
28
  });
@@ -10,11 +10,13 @@ var parseHtml = require('../libs/parse-html.js');
10
10
  var Header = require('../components/builder/Header.js');
11
11
  var FooterForPostPurchase = require('../components/FooterForPostPurchase.js');
12
12
  var Script = require('next/script');
13
+ var react = require('react');
13
14
 
14
15
  const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, customFonts, isPostPurchase, shopName, productOffers, publicStoreFrontData, isPreview, interaction })=>{
15
16
  const router$1 = router.useRouter();
16
17
  const baseAssetURL = process.env.NEXT_GP_BASE_ASSET_URL || 'https://d3kbi0je7pp4lw.cloudfront.net';
17
18
  useTrackingView.useTrackingView(shopToken, pageHandle, router$1.isFallback);
19
+ const customCodeHeaderID = 'custom-code-header';
18
20
  if (router$1.isFallback) {
19
21
  return /*#__PURE__*/ jsxRuntime.jsx("div", {
20
22
  className: "gp-flex gp-h-[100vh] gp-items-center gp-justify-center",
@@ -34,6 +36,14 @@ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, f
34
36
  })
35
37
  });
36
38
  }
39
+ react.useEffect(()=>{
40
+ const customCodeHeaderElement = document.querySelectorAll(`#${customCodeHeaderID}`);
41
+ if (customCodeHeaderElement.length > 1) {
42
+ customCodeHeaderElement.forEach((script, index)=>{
43
+ if (index !== 0) script.remove();
44
+ });
45
+ }
46
+ }, []);
37
47
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
38
48
  children: [
39
49
  /*#__PURE__*/ jsxRuntime.jsx(nextSeo.NextSeo, {
@@ -41,21 +51,21 @@ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, f
41
51
  }),
42
52
  /*#__PURE__*/ jsxRuntime.jsxs(Head, {
43
53
  children: [
44
- parseHtml.parseHtml(customCodeHeader, true),
54
+ parseHtml.parseHtml(customCodeHeaderID, customCodeHeader, true),
45
55
  themeStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
46
56
  "data-id": "global-style",
47
57
  type: "text/css",
48
58
  dangerouslySetInnerHTML: {
49
59
  __html: themeStyle
50
60
  }
51
- }),
61
+ }, "global-style"),
52
62
  fontStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
53
63
  "data-id": "google-fonts",
54
64
  type: "text/css",
55
65
  dangerouslySetInnerHTML: {
56
66
  __html: fontStyle
57
67
  }
58
- }),
68
+ }, "google-fonts"),
59
69
  elementFontStyle && elementFontStyle.map((fontStyle)=>/*#__PURE__*/ jsxRuntime.jsx("style", {
60
70
  "data-id": "google-element-fonts",
61
71
  type: "text/css",
@@ -7,7 +7,7 @@ const MainLayout = ({ children, ...props })=>{
7
7
  const mobileOnly = useShopStore((s)=>s.mobileOnly);
8
8
  return /*#__PURE__*/ jsxs(Fragment, {
9
9
  children: [
10
- parseHtml(props?.customCodeBody),
10
+ parseHtml('custom-code-body', props?.customCodeBody),
11
11
  /*#__PURE__*/ jsx("div", {
12
12
  className: cls({
13
13
  'gp-max-w-mobile gp-mx-auto gp-w-full': mobileOnly
@@ -1,34 +1,26 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import parse, { Element, Text } from 'html-react-parser';
3
- import Script from 'next/script';
4
3
 
5
- const parseHtml = (html, isHead)=>{
4
+ const parseHtml = (key, html, isHead)=>{
6
5
  if (!html) return undefined;
7
6
  try {
8
7
  return parse(html, {
9
8
  replace: (node)=>{
10
- if (node.type === 'script' && node instanceof Element) {
11
- const child = node.children?.[0];
12
- if (child instanceof Text) {
13
- if (isHead) return /*#__PURE__*/ jsx("script", {
14
- ...node.attribs,
15
- dangerouslySetInnerHTML: {
16
- __html: child.data
17
- }
18
- });
19
- else return /*#__PURE__*/ jsx(Script, {
20
- ...node.attribs,
21
- dangerouslySetInnerHTML: {
22
- __html: child.data
23
- }
24
- });
25
- } else {
26
- if (!isHead) {
27
- return /*#__PURE__*/ jsx(Script, {
28
- ...node.attribs
29
- });
9
+ if (node.type !== 'script' || !(node instanceof Element)) return null;
10
+ const child = node.children?.[0];
11
+ if (!child) return null;
12
+ if (!(child instanceof Text) && !isHead) return /*#__PURE__*/ jsx("script", {
13
+ id: key,
14
+ ...node.attribs
15
+ }, key);
16
+ if (child instanceof Text && isHead) {
17
+ return /*#__PURE__*/ jsx("script", {
18
+ id: key,
19
+ ...node.attribs,
20
+ dangerouslySetInnerHTML: {
21
+ __html: child.data
30
22
  }
31
- }
23
+ }, key);
32
24
  }
33
25
  }
34
26
  });
@@ -8,11 +8,13 @@ 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
10
  import Script from 'next/script';
11
+ import { useEffect } from 'react';
11
12
 
12
13
  const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, customFonts, isPostPurchase, shopName, productOffers, publicStoreFrontData, isPreview, interaction })=>{
13
14
  const router = useRouter();
14
15
  const baseAssetURL = process.env.NEXT_GP_BASE_ASSET_URL || 'https://d3kbi0je7pp4lw.cloudfront.net';
15
16
  useTrackingView(shopToken, pageHandle, router.isFallback);
17
+ const customCodeHeaderID = 'custom-code-header';
16
18
  if (router.isFallback) {
17
19
  return /*#__PURE__*/ jsx("div", {
18
20
  className: "gp-flex gp-h-[100vh] gp-items-center gp-justify-center",
@@ -32,6 +34,14 @@ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, f
32
34
  })
33
35
  });
34
36
  }
37
+ useEffect(()=>{
38
+ const customCodeHeaderElement = document.querySelectorAll(`#${customCodeHeaderID}`);
39
+ if (customCodeHeaderElement.length > 1) {
40
+ customCodeHeaderElement.forEach((script, index)=>{
41
+ if (index !== 0) script.remove();
42
+ });
43
+ }
44
+ }, []);
35
45
  return /*#__PURE__*/ jsxs(Fragment, {
36
46
  children: [
37
47
  /*#__PURE__*/ jsx(NextSeo, {
@@ -39,21 +49,21 @@ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, f
39
49
  }),
40
50
  /*#__PURE__*/ jsxs(Head, {
41
51
  children: [
42
- parseHtml(customCodeHeader, true),
52
+ parseHtml(customCodeHeaderID, customCodeHeader, true),
43
53
  themeStyle && /*#__PURE__*/ jsx("style", {
44
54
  "data-id": "global-style",
45
55
  type: "text/css",
46
56
  dangerouslySetInnerHTML: {
47
57
  __html: themeStyle
48
58
  }
49
- }),
59
+ }, "global-style"),
50
60
  fontStyle && /*#__PURE__*/ jsx("style", {
51
61
  "data-id": "google-fonts",
52
62
  type: "text/css",
53
63
  dangerouslySetInnerHTML: {
54
64
  __html: fontStyle
55
65
  }
56
- }),
66
+ }, "google-fonts"),
57
67
  elementFontStyle && elementFontStyle.map((fontStyle)=>/*#__PURE__*/ jsx("style", {
58
68
  "data-id": "google-element-fonts",
59
69
  type: "text/css",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "1.58.0-staging.43",
3
+ "version": "1.58.0-staging.54",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -26,7 +26,7 @@
26
26
  "next": "latest"
27
27
  },
28
28
  "devDependencies": {
29
- "@gem-sdk/core": "1.58.0-staging.39",
29
+ "@gem-sdk/core": "1.58.0-staging.48",
30
30
  "@gem-sdk/plugin-cookie-bar": "1.58.0-staging.25",
31
31
  "@gem-sdk/plugin-quick-view": "1.58.0-staging.25",
32
32
  "@gem-sdk/plugin-sticky-add-to-cart": "1.58.0-staging.25"