@pack/react 0.1.0 → 0.1.1-ab-test.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/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { RenderSections } from "./render-sections";
2
- import { PreviewProvider } from "./preview/preview-provider";
3
- import { usePreviewContext } from "./preview/preview-content";
2
+ import { PackProvider, PreviewProvider } from "./pack/pack-provider";
3
+ import { usePackContext, usePreviewContext } from "./pack/pack-context";
4
4
  import { useSiteSettings } from "./use-site-settings";
5
5
  import { useOverlayScript } from "./use-overlay-script";
6
6
  import { registerSection } from "./register-section";
7
7
  import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
8
- export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, };
8
+ export { registerSection, registerStorefrontSettingsSchema, usePackContext, usePreviewContext, useSiteSettings, useOverlayScript, PackProvider, PreviewProvider, RenderSections, };
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,gCAAgC,EAChC,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,cAAc,GACf,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,gCAAgC,EAChC,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,cAAc,GACf,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { RenderSections } from "./render-sections";
2
- import { PreviewProvider } from "./preview/preview-provider";
3
- import { usePreviewContext } from "./preview/preview-content";
2
+ import { PackProvider, PreviewProvider } from "./pack/pack-provider";
3
+ import { usePackContext, usePreviewContext } from "./pack/pack-context";
4
4
  import { useSiteSettings } from "./use-site-settings";
5
5
  import { useOverlayScript } from "./use-overlay-script";
6
6
  import { registerSection } from "./register-section";
7
7
  import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
8
- export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, };
8
+ export { registerSection, registerStorefrontSettingsSchema, usePackContext, usePreviewContext, useSiteSettings, useOverlayScript, PackProvider, PreviewProvider, RenderSections, };
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ type PackContextValue = {
3
+ isPreview: boolean;
4
+ siteSettings: any;
5
+ customizerMeta?: {
6
+ overlay?: {
7
+ src?: string;
8
+ version?: string;
9
+ };
10
+ [key: string]: any;
11
+ };
12
+ previewStorefrontSettings?: any;
13
+ setPreviewStorefrontSettings: (siteSettings: any) => void;
14
+ };
15
+ export declare const PackContext: import("react").Context<PackContextValue>;
16
+ export declare const usePackContext: () => PackContextValue;
17
+ export declare const PreviewContext: import("react").Context<PackContextValue>;
18
+ export declare const usePreviewContext: () => PackContextValue;
19
+ export {};
20
+ //# sourceMappingURL=pack-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":";AAEA,KAAK,gBAAgB,GAAG;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,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"}
@@ -0,0 +1,10 @@
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,5 +1,5 @@
1
1
  import React, { ReactNode } from "react";
2
- interface PreviewContentProps {
2
+ interface PackContentProps {
3
3
  children: ReactNode;
4
4
  siteSettings: any;
5
5
  isPreviewModeEnabled?: boolean;
@@ -11,6 +11,7 @@ interface PreviewContentProps {
11
11
  [key: string]: any;
12
12
  };
13
13
  }
14
- export declare function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PreviewContentProps): React.JSX.Element;
14
+ export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }: PackContentProps): React.JSX.Element;
15
+ export declare const PreviewProvider: typeof PackProvider;
15
16
  export {};
16
- //# sourceMappingURL=preview-provider.d.ts.map
17
+ //# sourceMappingURL=pack-provider.d.ts.map
@@ -0,0 +1 @@
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;AAInD,UAAU,gBAAgB;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,gBAAgB,qBAmBlB;AAED,eAAO,MAAM,eAAe,qBAAe,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import React, { useState } from "react";
2
- import { PreviewContext } from "./preview-content";
2
+ import { PackContext } from "./pack-context";
3
3
  import { PreviewToast } from "./preview-toast";
4
- export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
4
+ export function PackProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
5
5
  const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
6
- return (React.createElement(PreviewContext.Provider, { value: {
6
+ return (React.createElement(PackContext.Provider, { value: {
7
7
  isPreview: !!isPreviewModeEnabled,
8
8
  previewStorefrontSettings,
9
9
  setPreviewStorefrontSettings,
@@ -13,3 +13,4 @@ export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings,
13
13
  children,
14
14
  React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
15
15
  }
16
+ export const PreviewProvider = PackProvider;
@@ -0,0 +1 @@
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 +1 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAyClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAiC9C"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAoClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAiC9C"}
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import { useCustomizerShell } from "./use-customizer-shell";
3
- import { usePreviewContext } from "./preview/preview-content";
3
+ import { usePackContext } from "./pack/pack-context";
4
4
  import { sectionMap } from "./register-section";
5
5
  import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
6
6
  import { useOverlayScript } from "./use-overlay-script";
@@ -18,7 +18,7 @@ function Sections({ sections }) {
18
18
  const Component = sectionMap.get(schemaKey);
19
19
  if (!Component)
20
20
  return null;
21
- return (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key, hidden: data?.sectionVisibility === "hidden" },
21
+ return data?.sectionVisibility === "hidden" ? null : (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key },
22
22
  React.createElement(Component, { "comp-name": schemaKey, cms: data })));
23
23
  })
24
24
  .filter(Boolean);
@@ -26,7 +26,7 @@ function Sections({ sections }) {
26
26
  return React.createElement(React.Fragment, null, renderedSections);
27
27
  }
28
28
  export function RenderSections({ content }) {
29
- const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
29
+ const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePackContext();
30
30
  const { content: liveContent, storefrontSettings } = useCustomizerShell({
31
31
  environment: "production",
32
32
  isPreview,
@@ -1 +1 @@
1
- {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAsIL,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAkJL,CAAC"}
@@ -1,7 +1,7 @@
1
- import { useCallback, useEffect, useMemo, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { connectToParent, ErrorCode } from "penpal";
3
3
  export const useCustomizerShell = ({ environment = "production", isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
4
- const [location, setLocation] = useState();
4
+ const windowLocationRef = useRef();
5
5
  const [content, setContent] = useState(data.content);
6
6
  const [storefrontSettings, setStorefrontSettings] = useState(null);
7
7
  const [parentConnection, setParentConnection] = useState(null);
@@ -10,17 +10,17 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
10
10
  window.location.href = path;
11
11
  };
12
12
  useEffect(() => {
13
- const isIframe = window.self !== window.top;
14
13
  /*
15
14
  * Should not try to connect to customizer
16
15
  * if not in an iframe or not in preview mode
17
16
  */
17
+ const isIframe = window.self !== window.top;
18
18
  if (!isIframe || !isPreview)
19
19
  return;
20
20
  setShouldConnectToParent(true);
21
21
  }, []);
22
22
  useEffect(() => {
23
- setLocation(window.location);
23
+ windowLocationRef.current = window.location;
24
24
  }, [data.handle]);
25
25
  const refreshSections = useCallback(() => {
26
26
  if (!sectionComponents || !parentConnection)
@@ -58,7 +58,9 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
58
58
  // eslint-disable-next-line react-hooks/exhaustive-deps
59
59
  }, [data.handle, parentConnection, storefrontSettingsSchema]);
60
60
  useEffect(() => {
61
- if (!isPreview || !location?.pathname || !shouldConnectToParent)
61
+ if (!isPreview ||
62
+ !windowLocationRef.current?.pathname ||
63
+ !shouldConnectToParent)
62
64
  return;
63
65
  const connection = connectToParent({
64
66
  methods: {
@@ -79,21 +81,28 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
79
81
  },
80
82
  });
81
83
  connection.promise.then((parent) => {
82
- const { template, templateType, content } = data;
84
+ const { template, templateType, handle, title, description } = data;
83
85
  parent.sendStorefrontSettings();
84
86
  parent.setCurrentRoute({
85
87
  environment,
86
- currentPath: location?.pathname,
88
+ currentPath: windowLocationRef.current?.pathname,
87
89
  template,
88
90
  templateType,
89
- handle: content.handle,
90
- title: content.title,
91
- description: content.description,
91
+ handle,
92
+ title,
93
+ description,
92
94
  });
93
95
  setParentConnection(parent);
94
96
  });
95
97
  return () => connection.destroy();
96
- }, [location?.pathname]);
98
+ }, [
99
+ shouldConnectToParent,
100
+ data.handle,
101
+ data.title,
102
+ data.description,
103
+ data.template,
104
+ data.templateType,
105
+ ]);
97
106
  useEffect(() => {
98
107
  if (!isPreview)
99
108
  return;
@@ -1,4 +1,4 @@
1
- import { usePreviewContext } from "./preview/preview-content";
1
+ import { usePreviewContext } from "./pack/pack-context";
2
2
  export const useSiteSettings = () => {
3
3
  const { isPreview, previewStorefrontSettings, siteSettings } = usePreviewContext();
4
4
  let isIframe = false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.1.0",
4
+ "version": "0.1.1-ab-test.0",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -1,18 +0,0 @@
1
- /// <reference types="react" />
2
- type PreviewContextValue = {
3
- isPreview: boolean;
4
- siteSettings: any;
5
- customizerMeta?: {
6
- overlay?: {
7
- src?: string;
8
- version?: string;
9
- };
10
- [key: string]: any;
11
- };
12
- previewStorefrontSettings?: any;
13
- setPreviewStorefrontSettings: (siteSettings: any) => void;
14
- };
15
- export declare const PreviewContext: import("react").Context<PreviewContextValue>;
16
- export declare const usePreviewContext: () => PreviewContextValue;
17
- export {};
18
- //# sourceMappingURL=preview-content.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preview-content.d.ts","sourceRoot":"","sources":["../../src/preview/preview-content.tsx"],"names":[],"mappings":";AAEA,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,yBAAyB,CAAC,EAAE,GAAG,CAAC;IAChC,4BAA4B,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,cAAc,8CAKzB,CAAC;AAEH,eAAO,MAAM,iBAAiB,2BAAmC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { createContext, useContext } from "react";
2
- export const PreviewContext = createContext({
3
- isPreview: false,
4
- setPreviewStorefrontSettings: () => { },
5
- siteSettings: undefined,
6
- customizerMeta: undefined,
7
- });
8
- export const usePreviewContext = () => useContext(PreviewContext);
@@ -1 +0,0 @@
1
- {"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAInD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,mBAAmB,qBAmBrB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"preview-toast.d.ts","sourceRoot":"","sources":["../../src/preview/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"}
File without changes
File without changes