@pack/react 0.1.0 → 0.1.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.
@@ -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"}
@@ -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);
@@ -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 +1 @@
1
- {"version":3,"file":"use-overlay-script.d.ts","sourceRoot":"","sources":["../src/use-overlay-script.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE;YACL,uBAAuB,EAAE,OAAO,CAAC;SAClC,CAAC;KACH;CACF;AAED,eAAO,MAAM,gBAAgB;eAIhB,OAAO;aACT;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;UAmB5C,CAAC"}
1
+ {"version":3,"file":"use-overlay-script.d.ts","sourceRoot":"","sources":["../src/use-overlay-script.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE;YACL,uBAAuB,EAAE,OAAO,CAAC;SAClC,CAAC;KACH;CACF;AAED,eAAO,MAAM,gBAAgB,4BAG1B;IACD,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,SAkBA,CAAC"}
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",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {