@pack/react 2.0.0 → 2.0.1

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.
@@ -10,17 +10,19 @@ type PreviewContextValue = {
10
10
  };
11
11
  siteSettings: any;
12
12
  setSiteSettings: (siteSettings: any) => void;
13
- content: any;
14
- setContent: (content: any) => void;
13
+ previewContent: any;
14
+ setPreviewContent: (content: any) => void;
15
15
  pathname: string;
16
+ contentEnvironment: string;
16
17
  };
17
18
  export declare const PreviewContext: React.Context<PreviewContextValue>;
18
19
  export declare const usePreviewContext: () => PreviewContextValue;
19
20
  interface PreviewProviderProps {
20
- children: (sections: ReactNode) => ReactNode;
21
+ children: ReactNode;
21
22
  siteSettings: any;
22
23
  pathname: string;
23
24
  isPreviewModeEnabled?: boolean;
25
+ contentEnvironment?: string;
24
26
  customizerMeta?: {
25
27
  overlay?: {
26
28
  src?: string;
@@ -29,10 +31,10 @@ interface PreviewProviderProps {
29
31
  [key: string]: any;
30
32
  };
31
33
  }
32
- export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, pathname, }: PreviewProviderProps): React.JSX.Element;
34
+ export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, pathname, contentEnvironment, }: PreviewProviderProps): React.JSX.Element;
33
35
  export declare function RenderContent({ content }: {
34
36
  content: any;
35
- }): null;
37
+ }): React.JSX.Element;
36
38
  export declare function usePackContent(content: any): void;
37
39
  export {};
38
40
  //# sourceMappingURL=preview-content.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAMf,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC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D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,QAS1C"}
@@ -1,4 +1,4 @@
1
- import React, { createContext, useContext, useState, useEffect, useMemo, } from "react";
1
+ import React, { createContext, useContext, useState, useMemo, } from "react";
2
2
  import { RenderSections } from "./render-sections";
3
3
  import { usePackTrack } from "./pack-analytics";
4
4
  import { PreviewToast } from "./preview-toast";
@@ -7,13 +7,14 @@ export const PreviewContext = createContext({
7
7
  setSiteSettings: () => { },
8
8
  siteSettings: undefined,
9
9
  customizerMeta: undefined,
10
- content: null,
11
- setContent: () => { },
10
+ previewContent: null,
11
+ setPreviewContent: () => { },
12
12
  pathname: "",
13
+ contentEnvironment: "",
13
14
  });
14
15
  export const usePreviewContext = () => useContext(PreviewContext);
15
- export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, pathname, }) {
16
- const [content, setContent] = useState(null);
16
+ export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, pathname, contentEnvironment = "", }) {
17
+ const [previewContent, setPreviewContent] = useState(null);
17
18
  const [siteSettings, setSiteSettings] = useState(previewStorefrontSettings);
18
19
  usePackTrack();
19
20
  const value = useMemo(() => ({
@@ -21,37 +22,41 @@ export function PreviewProvider({ children, isPreviewModeEnabled = false, siteSe
21
22
  customizerMeta,
22
23
  siteSettings,
23
24
  setSiteSettings,
24
- content,
25
- setContent,
25
+ previewContent,
26
+ setPreviewContent,
26
27
  pathname,
28
+ contentEnvironment,
27
29
  }), [
28
30
  isPreviewModeEnabled,
29
31
  siteSettings,
30
32
  customizerMeta,
31
33
  setSiteSettings,
32
- content,
34
+ previewContent,
33
35
  pathname,
36
+ contentEnvironment,
34
37
  ]);
35
- // Clear content when navigating to a new page
36
- useEffect(() => {
37
- content && setContent(null);
38
- }, [pathname]);
39
- const sections = content ? React.createElement(RenderSections, null) : null;
40
38
  return (React.createElement(PreviewContext.Provider, { value: value },
41
- children(sections),
39
+ children,
42
40
  React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
43
41
  }
44
42
  export function RenderContent({ content }) {
45
- const { setContent } = usePreviewContext();
46
- useEffect(() => {
47
- setContent(content);
48
- }, [content, setContent]);
49
- return null;
43
+ const { isPreview, setPreviewContent } = usePreviewContext();
44
+ // Update content in context for preview mode
45
+ useMemo(() => {
46
+ setPreviewContent(content);
47
+ }, [content, setPreviewContent]);
48
+ // If in preview mode, RenderSections will handle rendering with live content
49
+ if (isPreview) {
50
+ return React.createElement(RenderSections, null);
51
+ }
52
+ // For SSR, pass the content directly
53
+ return React.createElement(RenderSections, { content: content });
50
54
  }
51
55
  export function usePackContent(content) {
52
- const context = usePreviewContext();
53
- useEffect(() => {
54
- context.setContent(content);
55
- }, [content, context]);
56
+ const { setPreviewContent } = usePreviewContext();
57
+ // Update preview content
58
+ useMemo(() => {
59
+ setPreviewContent(content);
60
+ }, [content, setPreviewContent]);
56
61
  return;
57
62
  }
@@ -1,4 +1,8 @@
1
1
  import React from "react";
2
- export declare function useSections(): any;
3
- export declare function RenderSections(): React.JSX.Element | null;
2
+ interface RenderSectionsProps {
3
+ content?: any;
4
+ }
5
+ export declare function RenderSections(props: RenderSectionsProps): React.JSX.Element | null;
6
+ export declare function useSections(props: RenderSectionsProps): any;
7
+ export {};
4
8
  //# sourceMappingURL=render-sections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AA6DlD,wBAAgB,WAAW,QAM1B;AAED,wBAAgB,cAAc,6BAM7B"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAoCvC,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAuBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAOxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,OAMrD"}
@@ -1,5 +1,4 @@
1
1
  import React, { useMemo } from "react";
2
- import { useMatches } from "@remix-run/react";
3
2
  import { usePreviewContext } from "./preview-content";
4
3
  import { sectionMap } from "../register-section";
5
4
  import { storefrontSettingsSchema } from "../register-storefront-settings-schema";
@@ -26,35 +25,34 @@ function Sections({ sections }) {
26
25
  }, [sections]);
27
26
  return React.createElement(React.Fragment, null, renderedSections);
28
27
  }
29
- function useRenderSections() {
30
- const [root] = useMatches();
31
- const { ENV } = root?.data;
32
- const { content: liveContent } = useCustomizerShell({
33
- environment: ENV?.PUBLIC_PACK_CONTENT_ENVIRONMENT,
34
- sectionComponents: sectionMap,
35
- storefrontSettingsSchema,
36
- });
37
- useOverlayScript();
38
- const sections = useMemo(() => {
28
+ function useRenderSections({ content: ssrContent }) {
29
+ const { previewContent, isPreview, contentEnvironment } = usePreviewContext();
30
+ // In preview mode, use the customizer shell to get live content
31
+ if (isPreview) {
32
+ const { content: liveContent } = useCustomizerShell({
33
+ environment: contentEnvironment,
34
+ sectionComponents: sectionMap,
35
+ storefrontSettingsSchema,
36
+ });
39
37
  return liveContent?.sections?.nodes || liveContent?.sections;
40
- }, [liveContent?.sections]);
41
- return {
42
- sections,
43
- };
38
+ }
39
+ // For SSR and non-preview mode, use the passed in content
40
+ const contentToRender = ssrContent || previewContent;
41
+ if (!contentToRender)
42
+ return null;
43
+ return contentToRender?.sections?.nodes || contentToRender?.sections;
44
44
  }
45
- export function useSections() {
46
- const { sections } = useRenderSections();
45
+ export function RenderSections(props) {
46
+ useOverlayScript();
47
+ const sections = useRenderSections(props);
47
48
  if (!sections)
48
49
  return null;
49
- const visibleSections = Sections({ sections });
50
- return visibleSections?.props?.children || null;
50
+ return React.createElement(Sections, { sections: sections });
51
51
  }
52
- export function RenderSections() {
53
- const { content } = usePreviewContext();
54
- if (!content)
55
- return null;
56
- const { sections } = useRenderSections();
52
+ export function useSections(props) {
53
+ const sections = useRenderSections(props);
57
54
  if (!sections)
58
55
  return null;
59
- return React.createElement(Sections, { sections: sections });
56
+ const visibleSections = Sections({ sections });
57
+ return visibleSections?.props?.children || null;
60
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,kBAAkB;iBAKhB,MAAM;uBACA,GAAG;+BACK,GAAG;;;CAiQ/B,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,kBAAkB;iBAKhB,MAAM;uBACA,GAAG;+BACK,GAAG;;;CAsQ/B,CAAC"}
@@ -2,14 +2,14 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "
2
2
  import { VERSION } from "./version";
3
3
  import { PreviewContext } from "./preview/preview-content";
4
4
  export const useCustomizerShell = ({ environment, sectionComponents, storefrontSettingsSchema, }) => {
5
- const { content, isPreview, pathname, setContent, setSiteSettings } = useContext(PreviewContext);
5
+ const { previewContent, isPreview, pathname, setPreviewContent, setSiteSettings, } = useContext(PreviewContext);
6
6
  const data = {
7
- content,
8
- template: content.template?.type,
9
- templateType: content.template?.type,
10
- handle: content.handle,
11
- title: content.title,
12
- description: content.description,
7
+ content: previewContent,
8
+ template: previewContent?.template?.type,
9
+ templateType: previewContent?.template?.type,
10
+ handle: previewContent?.handle,
11
+ title: previewContent?.title,
12
+ description: previewContent?.description,
13
13
  };
14
14
  const [hasInit, setHasInit] = useState(false);
15
15
  const pendingMessagesRef = useRef(new Map());
@@ -95,7 +95,7 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
95
95
  }
96
96
  break;
97
97
  case "SET_PAGE_DATA":
98
- setContent(message.pack.data?.content);
98
+ setPreviewContent(message.pack.data?.content);
99
99
  break;
100
100
  case "SET_STOREFRONT_SETTINGS":
101
101
  setSiteSettings({
@@ -200,12 +200,12 @@ export const useCustomizerShell = ({ environment, sectionComponents, storefrontS
200
200
  ]);
201
201
  if (!isPreview) {
202
202
  return {
203
- content,
203
+ content: previewContent,
204
204
  };
205
205
  }
206
206
  return useMemo(() => {
207
- return { content };
208
- }, [content]);
207
+ return { content: previewContent };
208
+ }, [previewContent]);
209
209
  };
210
210
  const useCanConnectCheck = ({ isPreview }) => {
211
211
  const [canConnect, setCanConnect] = useState(false);
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "2.0.0";
1
+ export const VERSION = "2.0.1";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -1,16 +0,0 @@
1
- export type BrowserData = {
2
- userAgent: string;
3
- pathname: string;
4
- query: string;
5
- screen: string;
6
- referrer: string;
7
- hostname: string;
8
- language: string;
9
- locale: string;
10
- userTimeZone: string;
11
- connection: string;
12
- deviceCategory: string;
13
- href: string;
14
- };
15
- export declare function usePackTrack(): void;
16
- //# sourceMappingURL=pack-analytics.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pack-analytics.d.ts","sourceRoot":"","sources":["../../src/pack/pack-analytics.tsx"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAiDF,wBAAgB,YAAY,SA0B3B"}
@@ -1,65 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- function getBrowserData() {
3
- let userTimeZone;
4
- let userLocale;
5
- try {
6
- userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
7
- userLocale =
8
- navigator.languages && navigator.languages.length
9
- ? navigator.languages[0]
10
- : navigator.userLanguage ||
11
- navigator.language ||
12
- navigator.browserLanguage ||
13
- "unknown";
14
- }
15
- catch (error) { }
16
- const connection = navigator.connection ||
17
- navigator.mozConnection ||
18
- navigator.webkitConnection;
19
- const minWidth = 768;
20
- // prettier-ignore
21
- const hasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
22
- let deviceCategory = "desktop";
23
- if (hasTouchSupport) {
24
- const hasSmallScreen = window.screen.width < minWidth;
25
- deviceCategory = hasSmallScreen ? "mobile" : "tablet";
26
- }
27
- return {
28
- userAgent: window.navigator.userAgent,
29
- pathname: window.location.pathname,
30
- query: window.location.search,
31
- screen: `${window.screen.width}x${window.screen.height}`,
32
- referrer: document.referrer,
33
- hostname: window.location.hostname,
34
- language: navigator.language,
35
- locale: userLocale,
36
- userTimeZone: userTimeZone || "unknown",
37
- connection: connection?.effectiveType || "unknown",
38
- deviceCategory,
39
- href: window.location.href,
40
- };
41
- }
42
- export function usePackTrack() {
43
- const [pathname, setPathname] = useState();
44
- const analytics = async () => {
45
- const browserData = getBrowserData();
46
- if (pathname === browserData.pathname)
47
- return;
48
- setPathname(browserData.pathname);
49
- try {
50
- await fetch("/pack/track", {
51
- method: "POST",
52
- headers: {
53
- "Content-Type": "application/json",
54
- },
55
- body: JSON.stringify(getBrowserData()),
56
- });
57
- }
58
- catch (error) {
59
- console.error("Error hit /pack/track: ", error.message);
60
- }
61
- };
62
- useEffect(() => {
63
- analytics();
64
- }, [analytics]);
65
- }
@@ -1,22 +0,0 @@
1
- /// <reference types="react" />
2
- type PackCustomizerMeta = {
3
- environment?: string;
4
- overlay?: {
5
- src?: string;
6
- version?: string;
7
- };
8
- [key: string]: any;
9
- };
10
- export type PackContextValue = {
11
- isPreview: boolean;
12
- siteSettings: any;
13
- customizerMeta?: PackCustomizerMeta | null;
14
- previewStorefrontSettings?: any;
15
- setPreviewStorefrontSettings: (siteSettings: any) => void;
16
- };
17
- export declare const PackContext: import("react").Context<PackContextValue>;
18
- export declare const usePackContext: () => PackContextValue;
19
- export declare const PreviewContext: import("react").Context<PackContextValue>;
20
- export declare const usePreviewContext: () => PackContextValue;
21
- export {};
22
- //# sourceMappingURL=pack-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":";AAEA,KAAK,kBAAkB,GAAG;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,cAAc,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC3C,yBAAyB,CAAC,EAAE,GAAG,CAAC;IAChC,4BAA4B,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,WAAW,2CAKtB,CAAC;AAEH,eAAO,MAAM,cAAc,wBAAgC,CAAC;AAE5D,eAAO,MAAM,cAAc,2CAAc,CAAC;AAE1C,eAAO,MAAM,iBAAiB,wBAAiB,CAAC"}
@@ -1,10 +0,0 @@
1
- import { createContext, useContext } from "react";
2
- export const PackContext = createContext({
3
- isPreview: false,
4
- setPreviewStorefrontSettings: () => { },
5
- siteSettings: undefined,
6
- customizerMeta: undefined,
7
- });
8
- export const usePackContext = () => useContext(PackContext);
9
- export const PreviewContext = PackContext;
10
- export const usePreviewContext = usePackContext;
@@ -1,12 +0,0 @@
1
- import React, { ReactNode } from "react";
2
- import { PackContextValue } from "./pack-context";
3
- interface PackContentProps {
4
- children: ReactNode;
5
- siteSettings: any;
6
- isPreviewModeEnabled?: boolean;
7
- customizerMeta?: PackContextValue["customizerMeta"];
8
- }
9
- export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PackContentProps): React.JSX.Element;
10
- export declare const PreviewProvider: typeof PackProvider;
11
- export {};
12
- //# sourceMappingURL=pack-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pack-provider.d.ts","sourceRoot":"","sources":["../../src/pack/pack-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AACnD,OAAO,EAAe,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAI/D,UAAU,gBAAgB;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CACrD;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,gBAAgB,qBAqBlB;AAED,eAAO,MAAM,eAAe,qBAAe,CAAC"}
@@ -1,18 +0,0 @@
1
- import React, { useState } from "react";
2
- import { PackContext } from "./pack-context";
3
- import { usePackTrack } from "./pack-analytics";
4
- import { PreviewToast } from "./preview-toast";
5
- export function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
6
- const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
7
- usePackTrack();
8
- return (React.createElement(PackContext.Provider, { value: {
9
- isPreview: !!isPreviewModeEnabled,
10
- previewStorefrontSettings,
11
- setPreviewStorefrontSettings,
12
- siteSettings,
13
- customizerMeta,
14
- } },
15
- children,
16
- React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
17
- }
18
- export const PreviewProvider = PackProvider;
@@ -1,7 +0,0 @@
1
- import React from "react";
2
- interface PreviewToastProps {
3
- isPreviewModeEnabled: boolean;
4
- }
5
- export declare const PreviewToast: ({ isPreviewModeEnabled }: PreviewToastProps) => React.JSX.Element | null;
6
- export {};
7
- //# sourceMappingURL=preview-toast.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preview-toast.d.ts","sourceRoot":"","sources":["../../src/pack/preview-toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,UAAU,iBAAiB;IACzB,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAsBD,eAAO,MAAM,YAAY,6BAA8B,iBAAiB,6BA+GvE,CAAC"}
@@ -1,85 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- const Eye = (props) => {
3
- return (React.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props },
4
- React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M2.75 12c0-.338.136-.905.493-1.591a7.858 7.858 0 0 1 1.64-2.108C6.374 6.926 8.694 5.75 12 5.75c3.308 0 5.627 1.176 7.116 2.551a7.86 7.86 0 0 1 1.64 2.108c.358.686.494 1.253.494 1.591 0 .338-.136.905-.493 1.591a7.86 7.86 0 0 1-1.64 2.108c-1.49 1.375-3.81 2.551-7.117 2.551-3.308 0-5.627-1.176-7.116-2.551a7.858 7.858 0 0 1-1.64-2.108c-.358-.686-.494-1.253-.494-1.591ZM12 4.25c-3.692 0-6.373 1.324-8.134 2.949a9.356 9.356 0 0 0-1.953 2.517c-.424.814-.663 1.622-.663 2.284 0 .662.24 1.47.663 2.284a9.356 9.356 0 0 0 1.953 2.517C5.627 18.426 8.308 19.75 12 19.75s6.373-1.324 8.134-2.949a9.356 9.356 0 0 0 1.953-2.517c.424-.814.663-1.622.663-2.284 0-.662-.24-1.47-.663-2.284a9.355 9.355 0 0 0-1.953-2.517C18.373 5.574 15.692 4.25 12 4.25ZM9.75 12a2.25 2.25 0 1 1 4.5 0 2.25 2.25 0 0 1-4.5 0ZM12 8.25a3.75 3.75 0 1 0 0 7.5 3.75 3.75 0 0 0 0-7.5Z", fill: "currentColor" })));
5
- };
6
- export const PreviewToast = ({ isPreviewModeEnabled }) => {
7
- const [showToast, setShowToast] = useState(false);
8
- const exitPreviewMode = async () => {
9
- try {
10
- const response = await fetch("/api/edit", {
11
- method: "POST",
12
- headers: {
13
- "Content-Type": "application/x-www-form-urlencoded",
14
- },
15
- });
16
- if (!response.ok) {
17
- throw new Error(`HTTP error! Status: ${response.status}`);
18
- }
19
- window.location.reload();
20
- }
21
- catch (error) {
22
- console.error("Error exiting preview:", error.message);
23
- }
24
- };
25
- useEffect(() => {
26
- const isIframe = window.self !== window.top;
27
- if (isPreviewModeEnabled && !isIframe) {
28
- setShowToast(true);
29
- }
30
- }, [isPreviewModeEnabled]);
31
- if (showToast) {
32
- return (React.createElement("div", { style: {
33
- position: "fixed",
34
- zIndex: "2147483647",
35
- left: "50%",
36
- transform: "translateX(-50%)",
37
- padding: "0 16px",
38
- bottom: "16px",
39
- width: "100%",
40
- pointerEvents: "none",
41
- } },
42
- React.createElement("div", { style: {
43
- margin: "0 auto",
44
- pointerEvents: "auto",
45
- maxWidth: "640px",
46
- boxShadow: "0px 2px 10px 0px rgba(0, 0, 0, 0.10), 0px 0px 2px 0px rgba(0, 0, 0, 0.10)",
47
- width: "100%",
48
- padding: "8px 16px",
49
- backgroundColor: "#1f2937",
50
- color: "#f9fafb",
51
- borderRadius: "8px",
52
- display: "flex",
53
- alignItems: "center",
54
- fontFamily: '"Inter", sans-serif',
55
- justifyContent: "space-between",
56
- gap: "8px",
57
- } },
58
- React.createElement("div", { style: {
59
- display: "flex",
60
- alignItems: "center",
61
- gap: "8px",
62
- overflow: "hidden",
63
- } },
64
- React.createElement(Eye, { style: { width: 16, height: 16, minWidth: 16 } }),
65
- React.createElement("p", { style: {
66
- flex: 1,
67
- fontSize: "14px",
68
- lineHeight: "20px",
69
- whiteSpace: "nowrap",
70
- textOverflow: "ellipsis",
71
- overflow: "hidden",
72
- } }, "You are currently previewing your storefront with draft content")),
73
- React.createElement("span", { role: "button", tabIndex: 0, onClick: exitPreviewMode, onKeyDown: (e) => {
74
- if (e.key === "Enter" || e.key === " ") {
75
- exitPreviewMode();
76
- }
77
- }, style: {
78
- cursor: "pointer",
79
- fontSize: 13,
80
- fontWeight: "500",
81
- flexShrink: "0",
82
- } }, "Exit preview mode"))));
83
- }
84
- return null;
85
- };
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- interface PreviewProviderProps {
3
- customizerMeta?: any;
4
- isPreviewModeEnabled?: boolean;
5
- siteSettings?: any;
6
- location?: Location;
7
- children: (sections: React.ReactNode) => React.ReactNode;
8
- }
9
- export declare function PreviewProvider({ customizerMeta, isPreviewModeEnabled, siteSettings, location, children, }: PreviewProviderProps): void;
10
- export {};
11
- //# sourceMappingURL=preview-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":";AAAA,UAAU,oBAAoB;IAC5B,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC;CAC1D;AAED,wBAAgB,eAAe,CAAC,EAC9B,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,QAAQ,EACR,QAAQ,GACT,EAAE,oBAAoB,QAWtB"}
@@ -1,11 +0,0 @@
1
- export function PreviewProvider({ customizerMeta, isPreviewModeEnabled, siteSettings, location, children, }) {
2
- const { content, storefrontSettings } = useCustomizerShell({
3
- environment: customizerMeta?.environment,
4
- isPreview: isPreviewModeEnabled,
5
- sectionComponents: customizerMeta?.sectionComponents,
6
- data: customizerMeta,
7
- storefrontSettingsSchema: siteSettings?.schema,
8
- location,
9
- });
10
- // ... rest of the component remains the same ...
11
- }
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- export declare function useSections({ content }: any): any;
3
- type RenderSectionProps = {
4
- pathname?: string;
5
- };
6
- export declare function RenderSections({ pathname }: RenderSectionProps): React.JSX.Element | null;
7
- export {};
8
- //# sourceMappingURL=render-sections.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAqFlD,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,OAM3C;AAED,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,4BAM9D"}
@@ -1,75 +0,0 @@
1
- import React, { useEffect, useMemo } from "react";
2
- import { useMatches } from "@remix-run/react";
3
- import { useCustomizerShell } from "./use-customizer-shell";
4
- import { usePreviewContext } from "./preview/preview-content";
5
- import { sectionMap } from "./register-section";
6
- import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
7
- import { useOverlayScript } from "./use-overlay-script";
8
- function Sections({ sections }) {
9
- const renderedSections = useMemo(() => {
10
- return sections
11
- .map((section) => {
12
- // TODO: Return a consistent data structure from the API and the customizer
13
- // Normalize section data
14
- const key = section.id || section.clientId;
15
- const data = section.data || section;
16
- // Attach dataSource to the provided cms data
17
- data.dataSource = section.dataSource;
18
- const schemaKey = data._template;
19
- const Component = sectionMap.get(schemaKey);
20
- if (!Component)
21
- return null;
22
- return data?.sectionVisibility === "hidden" ? null : (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key },
23
- React.createElement(Component, { "comp-name": schemaKey, cms: data })));
24
- })
25
- .filter(Boolean);
26
- }, [sections]);
27
- return React.createElement(React.Fragment, null, renderedSections);
28
- }
29
- function useRenderSections({ content, pathname, }) {
30
- const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
31
- const [root] = useMatches();
32
- const { ENV } = root?.data;
33
- const { content: liveContent, storefrontSettings } = useCustomizerShell({
34
- environment: ENV?.PUBLIC_PACK_CONTENT_ENVIRONMENT,
35
- isPreview,
36
- sectionComponents: sectionMap,
37
- data: {
38
- content,
39
- template: content.template?.type,
40
- templateType: content.template?.type,
41
- handle: content.handle,
42
- title: content.title,
43
- description: content.description,
44
- },
45
- storefrontSettingsSchema,
46
- pathname,
47
- });
48
- useOverlayScript({ isPreview, overlay: customizerMeta?.overlay || {} });
49
- useEffect(() => {
50
- storefrontSettings &&
51
- setPreviewStorefrontSettings({ settings: storefrontSettings });
52
- }, [setPreviewStorefrontSettings, storefrontSettings]);
53
- const sections = useMemo(() => {
54
- return liveContent?.sections?.nodes || liveContent?.sections;
55
- }, [liveContent?.sections]);
56
- return {
57
- sections,
58
- };
59
- }
60
- export function useSections({ content }) {
61
- const { sections } = useRenderSections({ content });
62
- if (!sections)
63
- return null;
64
- const visibleSections = Sections({ sections });
65
- return visibleSections?.props?.children || null;
66
- }
67
- export function RenderSections({ pathname }) {
68
- const { content } = usePreviewContext();
69
- if (!content)
70
- return null;
71
- const { sections } = useRenderSections({ content, pathname });
72
- if (!sections)
73
- return null;
74
- return React.createElement(Sections, { sections: sections });
75
- }