@pack/react 2.1.6 → 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.map +1 -1
- package/dist/preview/render-sections.js +12 -3
- 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
|
+
}
|
|
@@ -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,6 +1,7 @@
|
|
|
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";
|
|
4
5
|
function renderSectionContent(sections) {
|
|
5
6
|
if (!sections)
|
|
6
7
|
return null;
|
|
@@ -8,13 +9,19 @@ function renderSectionContent(sections) {
|
|
|
8
9
|
.map((section) => {
|
|
9
10
|
const key = section.id || section.clientId;
|
|
10
11
|
const data = section.data || section;
|
|
12
|
+
const elementStyles = section.styles?.elements || [];
|
|
11
13
|
data.dataSource = section.dataSource;
|
|
12
14
|
const schemaKey = data._template;
|
|
13
15
|
const Component = sectionMap.get(schemaKey);
|
|
14
16
|
if (!Component)
|
|
15
17
|
return null;
|
|
16
|
-
|
|
17
|
-
|
|
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 }))));
|
|
18
25
|
})
|
|
19
26
|
.filter(Boolean);
|
|
20
27
|
}
|
|
@@ -26,7 +33,9 @@ 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;
|
|
@@ -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";
|