@pack/react 3.0.4 → 3.1.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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/pack/pack-context.d.ts +20 -1
- package/dist/pack/pack-context.d.ts.map +1 -1
- package/dist/pack/pack-context.js +12 -2
- package/dist/pack/preview-toast.d.ts +9 -1
- package/dist/pack/preview-toast.d.ts.map +1 -1
- package/dist/pack/preview-toast.js +31 -4
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +20 -1
- package/dist/use-locale.d.ts +7 -0
- package/dist/use-locale.d.ts.map +1 -0
- package/dist/use-locale.js +5 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { RenderSections, useSections } from "./pack/render-sections";
|
|
|
2
2
|
import { PackProvider, PreviewProvider } from "./pack/pack-context";
|
|
3
3
|
import { usePackContext } from "./pack/pack-context";
|
|
4
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
5
|
+
import { useLocale } from "./use-locale";
|
|
5
6
|
import { useOverlayScript } from "./use-overlay-script";
|
|
6
7
|
import { registerSection } from "./register-section";
|
|
7
8
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
8
|
-
export { PackProvider, PreviewProvider, RenderSections, registerSection, registerStorefrontSettingsSchema, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
9
|
+
export { PackProvider, PreviewProvider, RenderSections, registerSection, registerStorefrontSettingsSchema, useLocale, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
9
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,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrE,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,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,cAAc,EACd,eAAe,EACf,gCAAgC,EAChC,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,GAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrE,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,cAAc,EACd,eAAe,EACf,gCAAgC,EAChC,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,GAChB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { RenderSections, useSections } from "./pack/render-sections";
|
|
|
2
2
|
import { PackProvider, PreviewProvider } from "./pack/pack-context";
|
|
3
3
|
import { usePackContext } from "./pack/pack-context";
|
|
4
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
5
|
+
import { useLocale } from "./use-locale";
|
|
5
6
|
import { useOverlayScript } from "./use-overlay-script";
|
|
6
7
|
import { registerSection } from "./register-section";
|
|
7
8
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
8
|
-
export { PackProvider, PreviewProvider, RenderSections, registerSection, registerStorefrontSettingsSchema, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
9
|
+
export { PackProvider, PreviewProvider, RenderSections, registerSection, registerStorefrontSettingsSchema, useLocale, useOverlayScript, usePackContext, useSections, useSiteSettings, };
|
|
@@ -6,6 +6,13 @@ type PackContextValue = {
|
|
|
6
6
|
src?: string;
|
|
7
7
|
version?: string;
|
|
8
8
|
};
|
|
9
|
+
previewContext?: {
|
|
10
|
+
locale?: string;
|
|
11
|
+
pageDraft?: string;
|
|
12
|
+
siteSettingsDraft?: string;
|
|
13
|
+
testHandle?: string;
|
|
14
|
+
testVariantHandle?: string;
|
|
15
|
+
};
|
|
9
16
|
[key: string]: any;
|
|
10
17
|
};
|
|
11
18
|
siteSettings: any;
|
|
@@ -13,6 +20,14 @@ type PackContextValue = {
|
|
|
13
20
|
liveContent: any;
|
|
14
21
|
setLiveContent: (content: any) => void;
|
|
15
22
|
contentEnvironment: string;
|
|
23
|
+
locale: {
|
|
24
|
+
language: string;
|
|
25
|
+
country: string;
|
|
26
|
+
} | null;
|
|
27
|
+
setLocale: (locale: {
|
|
28
|
+
language: string;
|
|
29
|
+
country: string;
|
|
30
|
+
} | null) => void;
|
|
16
31
|
};
|
|
17
32
|
export declare const PackContext: React.Context<PackContextValue>;
|
|
18
33
|
export declare const usePackContext: () => PackContextValue;
|
|
@@ -22,9 +37,13 @@ interface PackContentProps {
|
|
|
22
37
|
isPreviewModeEnabled?: boolean;
|
|
23
38
|
customizerMeta?: PackContextValue["customizerMeta"];
|
|
24
39
|
contentEnvironment?: string;
|
|
40
|
+
locale?: {
|
|
41
|
+
language: string;
|
|
42
|
+
country: string;
|
|
43
|
+
} | null;
|
|
25
44
|
liveContent?: any;
|
|
26
45
|
}
|
|
27
|
-
export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment, }: PackContentProps): React.JSX.Element;
|
|
46
|
+
export declare function PackProvider({ children, isPreviewModeEnabled, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment, locale: previewLocale, }: PackContentProps): React.JSX.Element;
|
|
28
47
|
export declare const PreviewProvider: typeof PackProvider;
|
|
29
48
|
export {};
|
|
30
49
|
//# 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;AAMf,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,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,YAAY,EAAE,GAAG,CAAC;IAClB,eAAe,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,CAAC;IAC7C,WAAW,EAAE,GAAG,CAAC;IACjB,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACvC,kBAAkB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"pack-context.d.ts","sourceRoot":"","sources":["../../src/pack/pack-context.tsx"],"names":[],"mappings":"AAAA,OAAO,K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,CAAC;IACpD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG,IAAI,CAAC;IACT,WAAW,CAAC,EAAE,GAAG,CAAC;CACnB;AAUD,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,oBAA4B,EAC5B,YAAY,EAAE,yBAAyB,EACvC,cAAc,EACd,kBAAuB,EACvB,MAAM,EAAE,aAAoB,GAC7B,EAAE,gBAAgB,qBAuDlB;AAED,eAAO,MAAM,eAAe,qBAAe,CAAC"}
|
|
@@ -11,6 +11,8 @@ export const PackContext = createContext({
|
|
|
11
11
|
liveContent: null,
|
|
12
12
|
setLiveContent: () => { },
|
|
13
13
|
contentEnvironment: "",
|
|
14
|
+
locale: null,
|
|
15
|
+
setLocale: () => { },
|
|
14
16
|
});
|
|
15
17
|
export const usePackContext = () => useContext(PackContext);
|
|
16
18
|
const CustomizerShell = () => {
|
|
@@ -20,9 +22,13 @@ const CustomizerShell = () => {
|
|
|
20
22
|
useOverlayScript();
|
|
21
23
|
return null;
|
|
22
24
|
};
|
|
23
|
-
export function PackProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment = "", }) {
|
|
25
|
+
export function PackProvider({ children, isPreviewModeEnabled = false, siteSettings: previewStorefrontSettings, customizerMeta, contentEnvironment = "", locale: previewLocale = null, }) {
|
|
24
26
|
const [liveContent, setLiveContent] = useState(null);
|
|
25
27
|
const [siteSettings, setSiteSettings] = useState(previewStorefrontSettings);
|
|
28
|
+
const [locale, setLocale] = useState(previewLocale);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setLocale(previewLocale);
|
|
31
|
+
}, [previewLocale]);
|
|
26
32
|
const value = useMemo(() => ({
|
|
27
33
|
isPreview: !!isPreviewModeEnabled,
|
|
28
34
|
customizerMeta,
|
|
@@ -30,6 +36,8 @@ export function PackProvider({ children, isPreviewModeEnabled = false, siteSetti
|
|
|
30
36
|
setSiteSettings,
|
|
31
37
|
liveContent,
|
|
32
38
|
setLiveContent,
|
|
39
|
+
locale,
|
|
40
|
+
setLocale,
|
|
33
41
|
contentEnvironment: contentEnvironment || customizerMeta?.environment || "",
|
|
34
42
|
}), [
|
|
35
43
|
isPreviewModeEnabled,
|
|
@@ -37,6 +45,8 @@ export function PackProvider({ children, isPreviewModeEnabled = false, siteSetti
|
|
|
37
45
|
customizerMeta,
|
|
38
46
|
liveContent,
|
|
39
47
|
contentEnvironment,
|
|
48
|
+
locale,
|
|
49
|
+
setLocale,
|
|
40
50
|
]);
|
|
41
51
|
useEffect(() => {
|
|
42
52
|
setSiteSettings(previewStorefrontSettings);
|
|
@@ -45,6 +55,6 @@ export function PackProvider({ children, isPreviewModeEnabled = false, siteSetti
|
|
|
45
55
|
return (React.createElement(PackContext.Provider, { value: value },
|
|
46
56
|
React.createElement(CustomizerShell, null),
|
|
47
57
|
children,
|
|
48
|
-
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled })));
|
|
58
|
+
React.createElement(PreviewToast, { isPreviewModeEnabled: !!isPreviewModeEnabled, environment: value.contentEnvironment, previewContext: customizerMeta?.previewContext })));
|
|
49
59
|
}
|
|
50
60
|
export const PreviewProvider = PackProvider;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
interface PreviewToastProps {
|
|
3
3
|
isPreviewModeEnabled: boolean;
|
|
4
|
+
environment?: string;
|
|
5
|
+
previewContext?: {
|
|
6
|
+
locale?: string;
|
|
7
|
+
pageDraft?: string;
|
|
8
|
+
siteSettingsDraft?: string;
|
|
9
|
+
testHandle?: string;
|
|
10
|
+
testVariantHandle?: string;
|
|
11
|
+
};
|
|
4
12
|
}
|
|
5
|
-
export declare const PreviewToast: ({ isPreviewModeEnabled }: PreviewToastProps) => React.JSX.Element | null;
|
|
13
|
+
export declare const PreviewToast: ({ isPreviewModeEnabled, environment, previewContext, }: PreviewToastProps) => React.JSX.Element | null;
|
|
6
14
|
export {};
|
|
7
15
|
//# sourceMappingURL=preview-toast.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-toast.d.ts","sourceRoot":"","sources":["../../src/pack/preview-toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,UAAU,iBAAiB;IACzB,oBAAoB,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"preview-toast.d.ts","sourceRoot":"","sources":["../../src/pack/preview-toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,UAAU,iBAAiB;IACzB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH;AAsBD,eAAO,MAAM,YAAY,2DAItB,iBAAiB,6BAqJnB,CAAC"}
|
|
@@ -3,7 +3,7 @@ const Eye = (props) => {
|
|
|
3
3
|
return (React.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props },
|
|
4
4
|
React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M2.75 12c0-.338.136-.905.493-1.591a7.858 7.858 0 0 1 1.64-2.108C6.374 6.926 8.694 5.75 12 5.75c3.308 0 5.627 1.176 7.116 2.551a7.86 7.86 0 0 1 1.64 2.108c.358.686.494 1.253.494 1.591 0 .338-.136.905-.493 1.591a7.86 7.86 0 0 1-1.64 2.108c-1.49 1.375-3.81 2.551-7.117 2.551-3.308 0-5.627-1.176-7.116-2.551a7.858 7.858 0 0 1-1.64-2.108c-.358-.686-.494-1.253-.494-1.591ZM12 4.25c-3.692 0-6.373 1.324-8.134 2.949a9.356 9.356 0 0 0-1.953 2.517c-.424.814-.663 1.622-.663 2.284 0 .662.24 1.47.663 2.284a9.356 9.356 0 0 0 1.953 2.517C5.627 18.426 8.308 19.75 12 19.75s6.373-1.324 8.134-2.949a9.356 9.356 0 0 0 1.953-2.517c.424-.814.663-1.622.663-2.284 0-.662-.24-1.47-.663-2.284a9.355 9.355 0 0 0-1.953-2.517C18.373 5.574 15.692 4.25 12 4.25ZM9.75 12a2.25 2.25 0 1 1 4.5 0 2.25 2.25 0 0 1-4.5 0ZM12 8.25a3.75 3.75 0 1 0 0 7.5 3.75 3.75 0 0 0 0-7.5Z", fill: "currentColor" })));
|
|
5
5
|
};
|
|
6
|
-
export const PreviewToast = ({ isPreviewModeEnabled }) => {
|
|
6
|
+
export const PreviewToast = ({ isPreviewModeEnabled, environment, previewContext, }) => {
|
|
7
7
|
const [showToast, setShowToast] = useState(false);
|
|
8
8
|
const exitPreviewMode = async () => {
|
|
9
9
|
try {
|
|
@@ -28,6 +28,33 @@ export const PreviewToast = ({ isPreviewModeEnabled }) => {
|
|
|
28
28
|
setShowToast(true);
|
|
29
29
|
}
|
|
30
30
|
}, [isPreviewModeEnabled]);
|
|
31
|
+
const buildPreviewMessage = () => {
|
|
32
|
+
const contextParts = [];
|
|
33
|
+
if (previewContext?.locale) {
|
|
34
|
+
contextParts.push(`locale: ${previewContext.locale}`);
|
|
35
|
+
}
|
|
36
|
+
if (previewContext?.pageDraft) {
|
|
37
|
+
contextParts.push(`page: ${previewContext.pageDraft}`);
|
|
38
|
+
}
|
|
39
|
+
if (previewContext?.siteSettingsDraft) {
|
|
40
|
+
contextParts.push(`settings: ${previewContext.siteSettingsDraft}`);
|
|
41
|
+
}
|
|
42
|
+
if (previewContext?.testVariantHandle) {
|
|
43
|
+
contextParts.push(`test: ${previewContext.testVariantHandle}`);
|
|
44
|
+
}
|
|
45
|
+
if (contextParts.length === 0) {
|
|
46
|
+
const baseMessage = "You are currently previewing your storefront with draft content";
|
|
47
|
+
return environment
|
|
48
|
+
? `${baseMessage} on ${environment} environment`
|
|
49
|
+
: baseMessage;
|
|
50
|
+
}
|
|
51
|
+
const parts = ["Previewing"];
|
|
52
|
+
if (environment) {
|
|
53
|
+
parts.push(`${environment} environment`);
|
|
54
|
+
}
|
|
55
|
+
parts.push(...contextParts);
|
|
56
|
+
return parts.join(" • ");
|
|
57
|
+
};
|
|
31
58
|
if (showToast) {
|
|
32
59
|
return (React.createElement("div", { style: {
|
|
33
60
|
position: "fixed",
|
|
@@ -42,9 +69,9 @@ export const PreviewToast = ({ isPreviewModeEnabled }) => {
|
|
|
42
69
|
React.createElement("div", { style: {
|
|
43
70
|
margin: "0 auto",
|
|
44
71
|
pointerEvents: "auto",
|
|
45
|
-
|
|
72
|
+
minWidth: "640px",
|
|
46
73
|
boxShadow: "0px 2px 10px 0px rgba(0, 0, 0, 0.10), 0px 0px 2px 0px rgba(0, 0, 0, 0.10)",
|
|
47
|
-
width: "
|
|
74
|
+
width: "fit-content",
|
|
48
75
|
padding: "8px 16px",
|
|
49
76
|
backgroundColor: "#1f2937",
|
|
50
77
|
color: "#f9fafb",
|
|
@@ -69,7 +96,7 @@ export const PreviewToast = ({ isPreviewModeEnabled }) => {
|
|
|
69
96
|
whiteSpace: "nowrap",
|
|
70
97
|
textOverflow: "ellipsis",
|
|
71
98
|
overflow: "hidden",
|
|
72
|
-
} },
|
|
99
|
+
} }, buildPreviewMessage())),
|
|
73
100
|
React.createElement("span", { role: "button", tabIndex: 0, onClick: exitPreviewMode, onKeyDown: (e) => {
|
|
74
101
|
if (e.key === "Enter" || e.key === " ") {
|
|
75
102
|
exitPreviewMode();
|
package/dist/types.d.ts
CHANGED
|
@@ -43,6 +43,19 @@ export interface MessageTypeDataMap {
|
|
|
43
43
|
SET_STOREFRONT_SETTINGS: {
|
|
44
44
|
settings: Record<string, unknown>;
|
|
45
45
|
};
|
|
46
|
+
SET_LOCALE: {
|
|
47
|
+
locale: {
|
|
48
|
+
language: string;
|
|
49
|
+
country: string;
|
|
50
|
+
} | null;
|
|
51
|
+
};
|
|
52
|
+
SEND_LOCALE: {
|
|
53
|
+
locale: {
|
|
54
|
+
language: string;
|
|
55
|
+
country: string;
|
|
56
|
+
} | null;
|
|
57
|
+
};
|
|
58
|
+
REQUEST_CURRENT_LOCALE: never;
|
|
46
59
|
SCROLL_TO_SECTION: {
|
|
47
60
|
sectionId: string;
|
|
48
61
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,GAAG,EAAE,CAAC;KACvB,CAAC;IACF,GAAG,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,aAAa,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAGvD,gBAAgB,EAAE;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,GAAG,EAAE,CAAC;KACvB,CAAC;IACF,GAAG,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,IAAI,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E;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,MAAM,kBAAkB,GAAG,MAAM,kBAAkB;IAE7D,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC;QACR,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,kBAAkB,YA2R9B,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { storefrontSettingsSchema } from "./register-storefront-settings-schema"
|
|
|
4
4
|
import { usePackContext } from "./pack/pack-context";
|
|
5
5
|
const VERSION = "3.0.0";
|
|
6
6
|
export const useCustomizerShell = () => {
|
|
7
|
-
const { contentEnvironment: environment, isPreview, liveContent, setLiveContent, setSiteSettings, } = usePackContext();
|
|
7
|
+
const { contentEnvironment: environment, isPreview, liveContent, setLiveContent, setSiteSettings, setLocale, locale, } = usePackContext();
|
|
8
8
|
const data = {
|
|
9
9
|
template: liveContent?.template?.type,
|
|
10
10
|
templateType: liveContent?.template?.type,
|
|
@@ -15,6 +15,7 @@ export const useCustomizerShell = () => {
|
|
|
15
15
|
const [hasInit, setHasInit] = useState(false);
|
|
16
16
|
const pendingMessagesRef = useRef(new Map());
|
|
17
17
|
const currentPathRef = useRef(undefined);
|
|
18
|
+
const parentLocaleIdRef = useRef(null);
|
|
18
19
|
const sendToParent = useCallback(async (type, data) => {
|
|
19
20
|
const messageId = crypto.randomUUID();
|
|
20
21
|
const message = {
|
|
@@ -52,6 +53,9 @@ export const useCustomizerShell = () => {
|
|
|
52
53
|
sendToParent("INIT", {
|
|
53
54
|
storefrontMeta: [],
|
|
54
55
|
version: VERSION,
|
|
56
|
+
}).then(() => {
|
|
57
|
+
// Request current locale after successful init
|
|
58
|
+
sendToParent("REQUEST_CURRENT_LOCALE");
|
|
55
59
|
}).catch((error) => {
|
|
56
60
|
console.error("Failed to initialize:", error);
|
|
57
61
|
});
|
|
@@ -112,6 +116,11 @@ export const useCustomizerShell = () => {
|
|
|
112
116
|
});
|
|
113
117
|
}
|
|
114
118
|
break;
|
|
119
|
+
case "SET_LOCALE":
|
|
120
|
+
const newLocale = message.pack.data?.locale;
|
|
121
|
+
parentLocaleIdRef.current = newLocale?.language && newLocale?.country ? `${newLocale.language.toLowerCase()}-${newLocale.country.toLowerCase()}` : null;
|
|
122
|
+
setLocale(newLocale);
|
|
123
|
+
break;
|
|
115
124
|
default:
|
|
116
125
|
break;
|
|
117
126
|
}
|
|
@@ -192,6 +201,16 @@ export const useCustomizerShell = () => {
|
|
|
192
201
|
description,
|
|
193
202
|
});
|
|
194
203
|
}, [hasInit, environment, data.handle, sendToParent]);
|
|
204
|
+
// Notify parent when locale changes (but not when it came from parent)
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
if (!hasInit)
|
|
207
|
+
return;
|
|
208
|
+
// Only send if locale is set and is different from what parent last set
|
|
209
|
+
if (parentLocaleIdRef.current === `${locale?.language}-${locale?.country}`.toLowerCase() || !locale)
|
|
210
|
+
return;
|
|
211
|
+
parentLocaleIdRef.current = `${locale?.language}-${locale?.country}`.toLowerCase() || null;
|
|
212
|
+
sendToParent("SEND_LOCALE", { locale }).catch(console.error);
|
|
213
|
+
}, [locale, hasInit, sendToParent]);
|
|
195
214
|
// Refresh sections and storefront settings schema
|
|
196
215
|
useEffect(() => {
|
|
197
216
|
if (!isPreview || !hasInit)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-locale.d.ts","sourceRoot":"","sources":["../src/use-locale.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CAAC;AAET,eAAO,MAAM,SAAS,QAAO,MAG5B,CAAC"}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0
|
|
1
|
+
export const VERSION = "3.1.0";
|