@pack/react 2.1.4 → 2.1.6

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.
@@ -3,6 +3,6 @@ interface RenderSectionsProps {
3
3
  content?: any;
4
4
  }
5
5
  export declare function RenderSections(props: RenderSectionsProps): React.JSX.Element | null;
6
- export declare function useSections(props: RenderSectionsProps): any;
6
+ export declare function useSections(props: RenderSectionsProps): (React.JSX.Element | null)[] | null;
7
7
  export {};
8
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,KAAkB,MAAM,OAAO,CAAC;AAiCvC,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAiBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,OAMrD"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAmCvC,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAiBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,uCAOrD"}
@@ -1,25 +1,25 @@
1
1
  import React, { useMemo } from "react";
2
2
  import { usePreviewContext } from "./preview-content";
3
3
  import { sectionMap } from "../register-section";
4
+ function renderSectionContent(sections) {
5
+ if (!sections)
6
+ return null;
7
+ return sections
8
+ .map((section) => {
9
+ const key = section.id || section.clientId;
10
+ const data = section.data || section;
11
+ data.dataSource = section.dataSource;
12
+ const schemaKey = data._template;
13
+ const Component = sectionMap.get(schemaKey);
14
+ if (!Component)
15
+ return null;
16
+ return data?.sectionVisibility === "hidden" ? null : (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key },
17
+ React.createElement(Component, { "comp-name": schemaKey, cms: data })));
18
+ })
19
+ .filter(Boolean);
20
+ }
4
21
  function Sections({ sections }) {
5
- const renderedSections = useMemo(() => {
6
- return sections
7
- .map((section) => {
8
- // TODO: Return a consistent data structure from the API and the customizer
9
- // Normalize section data
10
- const key = section.id || section.clientId;
11
- const data = section.data || section;
12
- // Attach dataSource to the provided cms data
13
- data.dataSource = section.dataSource;
14
- const schemaKey = data._template;
15
- const Component = sectionMap.get(schemaKey);
16
- if (!Component)
17
- return null;
18
- return data?.sectionVisibility === "hidden" ? null : (React.createElement("section", { key: key, "data-comp": schemaKey, "data-comp-id": key },
19
- React.createElement(Component, { "comp-name": schemaKey, cms: data })));
20
- })
21
- .filter(Boolean);
22
- }, [sections]);
22
+ const renderedSections = useMemo(() => renderSectionContent(sections), [sections]);
23
23
  return React.createElement(React.Fragment, null, renderedSections);
24
24
  }
25
25
  function useRenderSections({ content }) {
@@ -42,8 +42,6 @@ export function RenderSections(props) {
42
42
  }
43
43
  export function useSections(props) {
44
44
  const sections = useRenderSections(props);
45
- if (!sections)
46
- return null;
47
- const visibleSections = Sections({ sections });
48
- return visibleSections?.props?.children || null;
45
+ const renderedSections = useMemo(() => renderSectionContent(sections), [sections]);
46
+ return renderedSections;
49
47
  }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "2.1.4";
1
+ export const VERSION = "2.1.6";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "2.1.4",
4
+ "version": "2.1.6",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "devDependencies": {
25
- "@pack/types": "^0.0.2",
25
+ "@pack/types": "^0.0.3",
26
26
  "@types/react": "^18.2.20",
27
27
  "react": "^18.2.0",
28
28
  "react-dom": "^18.2.0"