@pack/react 4.3.0 → 4.3.2
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/README.md +3 -14
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/pack/pack-context.d.ts +1 -4
- package/dist/pack/pack-context.d.ts.map +1 -1
- package/dist/pack/pack-context.js +2 -4
- package/dist/pack/render-sections.d.ts +2 -1
- package/dist/pack/render-sections.d.ts.map +1 -1
- package/dist/pack/render-sections.js +25 -12
- package/dist/version.js +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -15,26 +15,17 @@ npm install @pack/react
|
|
|
15
15
|
- `registerSection`
|
|
16
16
|
- `registerStorefrontSettingsSchema`
|
|
17
17
|
- `usePackContext`, `useSiteSettings`, `useLocale`
|
|
18
|
-
- `PackErrorBoundary`
|
|
19
18
|
|
|
20
19
|
## Usage
|
|
21
20
|
|
|
22
21
|
```tsx
|
|
23
|
-
import { PackProvider, RenderSections } from
|
|
24
|
-
|
|
25
|
-
export function App({
|
|
26
|
-
sections,
|
|
27
|
-
siteSettings,
|
|
28
|
-
packSessionId,
|
|
29
|
-
isPreviewModeEnabled,
|
|
30
|
-
packErrorTracking,
|
|
31
|
-
}: Props) {
|
|
22
|
+
import { PackProvider, RenderSections } from "@pack/react";
|
|
23
|
+
|
|
24
|
+
export function App({ sections, siteSettings, isPreviewModeEnabled }: Props) {
|
|
32
25
|
return (
|
|
33
26
|
<PackProvider
|
|
34
27
|
siteSettings={siteSettings}
|
|
35
|
-
packSessionId={packSessionId}
|
|
36
28
|
isPreviewModeEnabled={isPreviewModeEnabled}
|
|
37
|
-
packErrorTracking={packErrorTracking}
|
|
38
29
|
>
|
|
39
30
|
<RenderSections sections={sections} />
|
|
40
31
|
</PackProvider>
|
|
@@ -42,8 +33,6 @@ export function App({
|
|
|
42
33
|
}
|
|
43
34
|
```
|
|
44
35
|
|
|
45
|
-
`packSessionId` and `packErrorTracking` can be passed from `...pack.getPackContextData()` when using `@pack/hydrogen`.
|
|
46
|
-
|
|
47
36
|
## Development
|
|
48
37
|
|
|
49
38
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { RenderSection, RenderSections, useSections } from "./pack/render-sections";
|
|
2
2
|
import { PackProvider, PreviewProvider } from "./pack/pack-context";
|
|
3
3
|
import { usePackContext } from "./pack/pack-context";
|
|
4
|
-
import { PackErrorBoundary } from "@pack/errors-react";
|
|
5
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
6
5
|
import { useLocale } from "./use-locale";
|
|
7
6
|
import { useOverlayScript } from "./use-overlay-script";
|
|
8
7
|
import { registerSection } from "./register-section";
|
|
9
8
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
10
|
-
export
|
|
11
|
-
export { PackErrorBoundary, PackProvider, PreviewProvider, RenderSection, RenderSections, registerSection, registerStorefrontSettingsSchema, useLocale, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
9
|
+
export { PackProvider, PreviewProvider, RenderSection, RenderSections, registerSection, registerStorefrontSettingsSchema, useLocale, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
12
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,YAAY,EACZ,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,EACf,gCAAgC,EAChC,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,GAChB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { RenderSection, RenderSections, useSections } from "./pack/render-sections";
|
|
1
|
+
import { RenderSection, RenderSections, useSections, } from "./pack/render-sections";
|
|
2
2
|
import { PackProvider, PreviewProvider } from "./pack/pack-context";
|
|
3
3
|
import { usePackContext } from "./pack/pack-context";
|
|
4
|
-
import { PackErrorBoundary } from "@pack/errors-react";
|
|
5
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
6
5
|
import { useLocale } from "./use-locale";
|
|
7
6
|
import { useOverlayScript } from "./use-overlay-script";
|
|
8
7
|
import { registerSection } from "./register-section";
|
|
9
8
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
10
|
-
export {
|
|
9
|
+
export { PackProvider, PreviewProvider, RenderSection, RenderSections, registerSection, registerStorefrontSettingsSchema, useLocale, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { type ReactNode } from "react";
|
|
2
|
-
import { type ErrorTrackingOptions } from "@pack/errors-react";
|
|
3
2
|
import "./pack-debug";
|
|
4
3
|
type PackContextValue = {
|
|
5
4
|
isPreview: boolean;
|
|
@@ -36,7 +35,6 @@ export declare const usePackContext: () => PackContextValue;
|
|
|
36
35
|
interface PackContentProps {
|
|
37
36
|
children: ReactNode;
|
|
38
37
|
siteSettings: any;
|
|
39
|
-
packSessionId?: string;
|
|
40
38
|
isPreviewModeEnabled?: boolean;
|
|
41
39
|
customizerMeta?: PackContextValue["customizerMeta"];
|
|
42
40
|
contentEnvironment?: string;
|
|
@@ -45,9 +43,8 @@ interface PackContentProps {
|
|
|
45
43
|
country: string;
|
|
46
44
|
} | null;
|
|
47
45
|
liveContent?: any;
|
|
48
|
-
packErrorTracking?: ErrorTrackingOptions;
|
|
49
46
|
}
|
|
50
|
-
export declare function PackProvider({ children,
|
|
47
|
+
export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment, locale: previewLocale, }: PackContentProps): React.JSX.Element;
|
|
51
48
|
export declare const PreviewProvider: typeof PackProvider;
|
|
52
49
|
export {};
|
|
53
50
|
//# sourceMappingURL=pack-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAKf,OAAO,cAAc,CAAC;AAEtB,KAAK,gBAAgB,GAAG;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,cAAc,CAAC,EAAE;YACf,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B,UAAU,CAAC,EAAE,MAAM,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1,6 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext, useState, useMemo, useEffect, } from "react";
|
|
2
2
|
import { usePackTrack } from "./pack-analytics";
|
|
3
|
-
import { usePackErrorTrack, PackErrorBoundary, } from "@pack/errors-react";
|
|
4
3
|
import { PreviewToast } from "./preview-toast";
|
|
5
4
|
import { useOverlayScript } from "../use-overlay-script";
|
|
6
5
|
import { useCustomizerShell } from "../use-customizer-shell";
|
|
@@ -24,7 +23,7 @@ const CustomizerShell = () => {
|
|
|
24
23
|
useOverlayScript();
|
|
25
24
|
return null;
|
|
26
25
|
};
|
|
27
|
-
export function PackProvider({ children,
|
|
26
|
+
export function PackProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment = "", locale: previewLocale = null, }) {
|
|
28
27
|
const [liveContent, setLiveContent] = useState(null);
|
|
29
28
|
const [siteSettings, setSiteSettings] = useState(previewStorefrontSettings);
|
|
30
29
|
const [locale, setLocale] = useState(previewLocale);
|
|
@@ -54,10 +53,9 @@ export function PackProvider({ children, packSessionId, isPreviewModeEnabled = f
|
|
|
54
53
|
setSiteSettings(previewStorefrontSettings);
|
|
55
54
|
}, [previewStorefrontSettings]);
|
|
56
55
|
usePackTrack();
|
|
57
|
-
usePackErrorTrack(!!isPreviewModeEnabled, packErrorTracking, packSessionId);
|
|
58
56
|
return (React.createElement(PackContext.Provider, { value: value },
|
|
59
57
|
React.createElement(CustomizerShell, null),
|
|
60
|
-
|
|
58
|
+
children,
|
|
61
59
|
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled, environment: value.contentEnvironment, previewContext: customizerMeta?.previewContext })));
|
|
62
60
|
}
|
|
63
61
|
export const PreviewProvider = PackProvider;
|
|
@@ -8,10 +8,11 @@ interface RenderSectionProps {
|
|
|
8
8
|
* Use for nested-section blocks; for full-page rendering, use `RenderSections`.
|
|
9
9
|
*/
|
|
10
10
|
export declare function RenderSection({ section }: RenderSectionProps): React.JSX.Element | null;
|
|
11
|
+
export declare function renderSectionContent(sections: any[]): (React.JSX.Element | null)[] | null;
|
|
11
12
|
interface RenderSectionsProps {
|
|
12
13
|
content?: any;
|
|
13
14
|
}
|
|
14
15
|
export declare function RenderSections(props: RenderSectionsProps): React.JSX.Element | null;
|
|
15
|
-
export declare function useSections(props: RenderSectionsProps): React.JSX.Element[] | null;
|
|
16
|
+
export declare function useSections(props: RenderSectionsProps): (React.JSX.Element | null)[] | null;
|
|
16
17
|
export {};
|
|
17
18
|
//# sourceMappingURL=render-sections.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/pack/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/pack/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AAMrE,UAAU,kBAAkB;IAC1B,sDAAsD;IACtD,OAAO,EAAE,GAAG,CAAC;CACd;AAuCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,4BAG5D;AAGD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,EAAE,uCAYnD;AAUD,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AA8BD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,uCAOrD"}
|
|
@@ -2,11 +2,14 @@ import React, { useMemo, useEffect } from "react";
|
|
|
2
2
|
import { usePackContext } from "./pack-context";
|
|
3
3
|
import { sectionMap } from "../register-section";
|
|
4
4
|
import { generateSectionStylesheet } from "../lib/style-utils";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
// Builds the [<style>, <section>] element pair for one section, or null if the
|
|
6
|
+
// section is unregistered/hidden. Hookless, so it can be called directly from
|
|
7
|
+
// both RenderSection and renderSectionContent. Returning the pair (rather than a
|
|
8
|
+
// wrapping element) keeps useSections' element tree flat — consumers that walk
|
|
9
|
+
// fragment.props.children to find the `data-comp` <section> depend on that shape.
|
|
10
|
+
// The explicit ReactElement[] return type makes any future wrapping element
|
|
11
|
+
// (the regression this guards against) a compile error rather than only a test failure.
|
|
12
|
+
function buildSectionElements(section) {
|
|
10
13
|
if (!section)
|
|
11
14
|
return null;
|
|
12
15
|
const key = section.id || section.clientId;
|
|
@@ -20,21 +23,31 @@ export function RenderSection({ section }) {
|
|
|
20
23
|
if (data?.sectionVisibility === "hidden")
|
|
21
24
|
return null;
|
|
22
25
|
const stylesheet = generateSectionStylesheet(key, elementStyles);
|
|
23
|
-
return
|
|
24
|
-
React.createElement("style", { id: `section-styles-${key}`, dangerouslySetInnerHTML: {
|
|
26
|
+
return [
|
|
27
|
+
React.createElement("style", { key: `section-styles-${key}`, id: `section-styles-${key}`, dangerouslySetInnerHTML: {
|
|
25
28
|
__html: stylesheet,
|
|
26
29
|
} }),
|
|
27
|
-
React.createElement("section", { "data-comp": schemaKey, "data-comp-id": key },
|
|
28
|
-
React.createElement(Component, { "comp-name": schemaKey, cms: data }))
|
|
30
|
+
React.createElement("section", { key: `section-${key}`, "data-comp": schemaKey, "data-comp-id": key },
|
|
31
|
+
React.createElement(Component, { "comp-name": schemaKey, cms: data })),
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Renders one section against the registry populated by `registerSection`.
|
|
36
|
+
* Use for nested-section blocks; for full-page rendering, use `RenderSections`.
|
|
37
|
+
*/
|
|
38
|
+
export function RenderSection({ section }) {
|
|
39
|
+
const elements = buildSectionElements(section);
|
|
40
|
+
return elements ? React.createElement(React.Fragment, null, elements) : null;
|
|
29
41
|
}
|
|
30
|
-
|
|
42
|
+
// Exported for unit tests only — not re-exported from the package entry (index.ts).
|
|
43
|
+
export function renderSectionContent(sections) {
|
|
31
44
|
if (!sections)
|
|
32
45
|
return null;
|
|
33
46
|
return sections
|
|
34
47
|
.map((section) => {
|
|
35
48
|
const key = section.id || section.clientId;
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const elements = buildSectionElements(section);
|
|
50
|
+
return elements ? (React.createElement(React.Fragment, { key: key }, elements)) : null;
|
|
38
51
|
})
|
|
39
52
|
.filter(Boolean);
|
|
40
53
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "4.3.
|
|
1
|
+
export const VERSION = "4.3.2";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pack/react",
|
|
3
3
|
"description": "React",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.2",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"engines": {
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@pack/
|
|
26
|
-
"@pack/types": "^0.2.0"
|
|
25
|
+
"@pack/types": "^0.2.1"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@types/react": "^18.2.20",
|