@pack/react 0.0.9 → 0.0.11

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,3 +1,3 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  export declare function RenderSections({ content }: any): React.JSX.Element | null;
3
3
  //# 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,KAAkB,MAAM,OAAO,CAAC;AAmCvC,wBAAgB,cAAc,CAAC,EAAC,OAAO,EAAC,EAAE,GAAG,4BA4B5C"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAqClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BA8B9C"}
@@ -1,29 +1,31 @@
1
- import React, { useEffect } from 'react';
2
- import { v4 as uuidv4 } from 'uuid';
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
- function Sections({ content, sections }) {
8
- const renderedSections = sections
9
- .map((section) => {
10
- // TODO: Return a consistent data structure from the API and the customizer
11
- // Normalize section data
12
- const data = section.data || section;
13
- const schemaKey = data._template;
14
- const Component = sectionMap.get(schemaKey);
15
- if (!Component)
16
- return null;
17
- return (React.createElement("section", { key: uuidv4(), "data-comp": schemaKey, "data-comp-id": section?.id, hidden: data?.sectionVisibility === 'hidden' },
18
- React.createElement(Component, { "comp-name": schemaKey, cms: data })));
19
- })
20
- .filter(Boolean);
1
+ import React, { useEffect, useMemo } from "react";
2
+ import { useCustomizerShell } from "./use-customizer-shell";
3
+ import { usePreviewContext } from "./preview/preview-content";
4
+ import { sectionMap } from "./register-section";
5
+ import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
6
+ function Sections({ sections }) {
7
+ const renderedSections = useMemo(() => {
8
+ return sections
9
+ .map((section) => {
10
+ // TODO: Return a consistent data structure from the API and the customizer
11
+ // Normalize section data
12
+ const key = section.id || section.clientId;
13
+ const data = section.data || section;
14
+ const schemaKey = data._template;
15
+ const Component = sectionMap.get(schemaKey);
16
+ if (!Component)
17
+ return null;
18
+ return (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key, hidden: data?.sectionVisibility === "hidden" },
19
+ React.createElement(Component, { "comp-name": schemaKey, cms: data })));
20
+ })
21
+ .filter(Boolean);
22
+ }, [sections]);
21
23
  return React.createElement(React.Fragment, null, renderedSections);
22
24
  }
23
25
  export function RenderSections({ content }) {
24
26
  const { isPreview, setPreviewStorefrontSettings } = usePreviewContext();
25
27
  const { content: liveContent, storefrontSettings } = useCustomizerShell({
26
- environment: 'production',
28
+ environment: "production",
27
29
  isPreview,
28
30
  sectionComponents: sectionMap,
29
31
  data: {
@@ -40,8 +42,10 @@ export function RenderSections({ content }) {
40
42
  storefrontSettings &&
41
43
  setPreviewStorefrontSettings({ settings: storefrontSettings });
42
44
  }, [setPreviewStorefrontSettings, storefrontSettings]);
43
- const sections = liveContent?.sections?.nodes || liveContent?.sections;
45
+ const sections = useMemo(() => {
46
+ return liveContent?.sections?.nodes || liveContent?.sections;
47
+ }, [liveContent?.sections]);
44
48
  if (!sections)
45
49
  return null;
46
- return React.createElement(Sections, { content: liveContent, sections: sections });
50
+ return React.createElement(Sections, { sections: sections });
47
51
  }
@@ -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;;;CAkHL,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;;;CAoHL,CAAC"}
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { connectToParent, ErrorCode } from "penpal";
3
3
  export const useCustomizerShell = ({ environment = "production", isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
4
4
  const [location, setLocation] = useState();
@@ -94,5 +94,7 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
94
94
  storefrontSettings: data.settings?.settings,
95
95
  };
96
96
  }
97
- return { content, storefrontSettings };
97
+ return useMemo(() => {
98
+ return { content, storefrontSettings };
99
+ }, [content, storefrontSettings]);
98
100
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -24,7 +24,6 @@
24
24
  "devDependencies": {
25
25
  "@shopify/remix-oxygen": "^1.1.3",
26
26
  "@types/react": "^18.2.20",
27
- "@types/uuid": "^9.0.2",
28
27
  "react": "^18.2.0",
29
28
  "react-dom": "^18.2.0"
30
29
  },
@@ -33,7 +32,6 @@
33
32
  "react-dom": "^18.0.0"
34
33
  },
35
34
  "dependencies": {
36
- "penpal": "^6.2.2",
37
- "uuid": "^9.0.1"
35
+ "penpal": "^6.2.2"
38
36
  }
39
37
  }