@pack/react 0.1.0 → 0.1.2

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
- import { RenderSections } from "./render-sections";
1
+ import { RenderSections, useSections } from "./render-sections";
2
2
  import { PreviewProvider } from "./preview/preview-provider";
3
3
  import { usePreviewContext } from "./preview/preview-content";
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, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, useSections, };
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,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,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,EACd,WAAW,GACZ,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { RenderSections } from "./render-sections";
1
+ import { RenderSections, useSections } from "./render-sections";
2
2
  import { PreviewProvider } from "./preview/preview-provider";
3
3
  import { usePreviewContext } from "./preview/preview-content";
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, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, useSections, };
@@ -1,3 +1,4 @@
1
1
  import React from "react";
2
+ export declare function useSections({ content }: any): any;
2
3
  export declare function RenderSections({ content }: any): React.JSX.Element | null;
3
4
  //# sourceMappingURL=render-sections.d.ts.map
@@ -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;AAuElD,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,OAM3C;AAED,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAI9C"}
@@ -18,14 +18,14 @@ 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);
25
25
  }, [sections]);
26
26
  return React.createElement(React.Fragment, null, renderedSections);
27
27
  }
28
- export function RenderSections({ content }) {
28
+ function useRenderSections({ content }) {
29
29
  const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
30
30
  const { content: liveContent, storefrontSettings } = useCustomizerShell({
31
31
  environment: "production",
@@ -49,6 +49,19 @@ export function RenderSections({ content }) {
49
49
  const sections = useMemo(() => {
50
50
  return liveContent?.sections?.nodes || liveContent?.sections;
51
51
  }, [liveContent?.sections]);
52
+ return {
53
+ sections,
54
+ };
55
+ }
56
+ export function useSections({ content }) {
57
+ const { sections } = useRenderSections({ content });
58
+ if (!sections)
59
+ return null;
60
+ const visibleSections = Sections({ sections });
61
+ return visibleSections?.props?.children || null;
62
+ }
63
+ export function RenderSections({ content }) {
64
+ const { sections } = useRenderSections({ content });
52
65
  if (!sections)
53
66
  return null;
54
67
  return React.createElement(Sections, { sections: sections });
@@ -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;
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.2",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {