@pack/react 2.1.5 → 2.2.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/lib/style-utils.d.ts +12 -0
- package/dist/lib/style-utils.d.ts.map +1 -0
- package/dist/lib/style-utils.js +23 -0
- package/dist/preview/render-sections.d.ts +1 -1
- package/dist/preview/render-sections.d.ts.map +1 -1
- package/dist/preview/render-sections.js +30 -23
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +3 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a style object to CSS string format
|
|
3
|
+
*/
|
|
4
|
+
export declare function objectToCssString(styles: Record<string, string | number>): string;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a CSS stylesheet for a section including element-specific styles
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateSectionStylesheet(sectionId: string, elementStyles?: Array<{
|
|
9
|
+
selector: string;
|
|
10
|
+
styles: Record<string, string | number>;
|
|
11
|
+
}>): string;
|
|
12
|
+
//# sourceMappingURL=style-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-utils.d.ts","sourceRoot":"","sources":["../../src/lib/style-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GACtC,MAAM,CAOR;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,aAAa,GAAE,KAAK,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CACzC,CAAM,GACN,MAAM,CAWR"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a style object to CSS string format
|
|
3
|
+
*/
|
|
4
|
+
export function objectToCssString(styles) {
|
|
5
|
+
return Object.entries(styles)
|
|
6
|
+
.map(([prop, value]) => {
|
|
7
|
+
const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
8
|
+
return `${cssProperty}: ${value};`;
|
|
9
|
+
})
|
|
10
|
+
.join(" ");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generate a CSS stylesheet for a section including element-specific styles
|
|
14
|
+
*/
|
|
15
|
+
export function generateSectionStylesheet(sectionId, elementStyles = []) {
|
|
16
|
+
let stylesheet = "";
|
|
17
|
+
// Generate element-level styles
|
|
18
|
+
elementStyles.forEach((element) => {
|
|
19
|
+
const fullSelector = `section[data-comp-id="${sectionId}"] ${element.selector}:not([data-pack-style-disabled]):not([data-pack-style-disabled] *)`;
|
|
20
|
+
stylesheet += `${fullSelector} { ${objectToCssString(element.styles)} }\n`;
|
|
21
|
+
});
|
|
22
|
+
return stylesheet;
|
|
23
|
+
}
|
|
@@ -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):
|
|
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;
|
|
1
|
+
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/preview/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAiDvC,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAoBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,uCAOrD"}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import { usePreviewContext } from "./preview-content";
|
|
3
3
|
import { sectionMap } from "../register-section";
|
|
4
|
+
import { generateSectionStylesheet } from "../lib/style-utils";
|
|
5
|
+
function renderSectionContent(sections) {
|
|
6
|
+
if (!sections)
|
|
7
|
+
return null;
|
|
8
|
+
return sections
|
|
9
|
+
.map((section) => {
|
|
10
|
+
const key = section.id || section.clientId;
|
|
11
|
+
const data = section.data || section;
|
|
12
|
+
const elementStyles = section.styles?.elements || [];
|
|
13
|
+
data.dataSource = section.dataSource;
|
|
14
|
+
const schemaKey = data._template;
|
|
15
|
+
const Component = sectionMap.get(schemaKey);
|
|
16
|
+
if (!Component)
|
|
17
|
+
return null;
|
|
18
|
+
const stylesheet = generateSectionStylesheet(key, elementStyles);
|
|
19
|
+
return data?.sectionVisibility === "hidden" ? null : (React.createElement(React.Fragment, { key: key },
|
|
20
|
+
React.createElement("style", { id: `section-styles-${key}`, dangerouslySetInnerHTML: {
|
|
21
|
+
__html: stylesheet,
|
|
22
|
+
} }),
|
|
23
|
+
React.createElement("section", { "data-comp": schemaKey, "data-comp-id": key },
|
|
24
|
+
React.createElement(Component, { "comp-name": schemaKey, cms: data }))));
|
|
25
|
+
})
|
|
26
|
+
.filter(Boolean);
|
|
27
|
+
}
|
|
4
28
|
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]);
|
|
29
|
+
const renderedSections = useMemo(() => renderSectionContent(sections), [sections]);
|
|
23
30
|
return React.createElement(React.Fragment, null, renderedSections);
|
|
24
31
|
}
|
|
25
32
|
function useRenderSections({ content }) {
|
|
26
33
|
const { isPreview, liveContent, setLiveContent } = usePreviewContext();
|
|
27
34
|
// Update content in context for preview mode
|
|
28
35
|
useMemo(() => {
|
|
29
|
-
|
|
36
|
+
if (isPreview) {
|
|
37
|
+
setLiveContent(content);
|
|
38
|
+
}
|
|
30
39
|
}, [content, isPreview, setLiveContent]);
|
|
31
40
|
// For SSR, use the passed in content
|
|
32
41
|
const contentToRender = liveContent || content;
|
|
@@ -42,8 +51,6 @@ export function RenderSections(props) {
|
|
|
42
51
|
}
|
|
43
52
|
export function useSections(props) {
|
|
44
53
|
const sections = useRenderSections(props);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const visibleSections = Sections({ sections });
|
|
48
|
-
return visibleSections?.props?.children || null;
|
|
54
|
+
const renderedSections = useMemo(() => renderSectionContent(sections), [sections]);
|
|
55
|
+
return renderedSections;
|
|
49
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAwBA,eAAO,MAAM,kBAAkB,YAkQ9B,CAAC"}
|
|
@@ -3,7 +3,10 @@ import { VERSION } from "./version";
|
|
|
3
3
|
import { PreviewContext } from "./preview/preview-content";
|
|
4
4
|
import { sectionMap as sectionComponents } from "./register-section";
|
|
5
5
|
import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
6
|
+
import debug from "debug";
|
|
7
|
+
const debugCustomizer = debug("customizer:shell");
|
|
6
8
|
export const useCustomizerShell = () => {
|
|
9
|
+
debugCustomizer("useCustomizerShell running");
|
|
7
10
|
const { contentEnvironment: environment, isPreview, liveContent, setLiveContent, setSiteSettings, } = useContext(PreviewContext);
|
|
8
11
|
const data = {
|
|
9
12
|
template: liveContent?.template?.type,
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.
|
|
1
|
+
export const VERSION = "2.2.0";
|