@pack/react 4.4.0 → 4.6.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/consent.d.ts +25 -0
- package/dist/pack/consent.d.ts.map +1 -0
- package/dist/pack/consent.js +171 -0
- package/dist/pack/pack-context.d.ts +2 -10
- package/dist/pack/pack-context.d.ts.map +1 -1
- package/dist/pack/pack-context.js +4 -2
- package/dist/pack/pack-debug.d.ts +1 -0
- package/dist/pack/pack-debug.d.ts.map +1 -1
- package/dist/pack/pack-debug.js +45 -9
- package/dist/pack/preview-toolbar.d.ts +47 -0
- package/dist/pack/preview-toolbar.d.ts.map +1 -0
- package/dist/pack/preview-toolbar.js +730 -0
- package/dist/use-customizer-shell.d.ts.map +1 -1
- package/dist/use-customizer-shell.js +20 -9
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/pack/preview-toast.d.ts +0 -20
- package/dist/pack/preview-toast.d.ts.map +0 -1
- package/dist/pack/preview-toast.js +0 -140
|
@@ -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,YAkU9B,CAAC"}
|
|
@@ -183,24 +183,35 @@ export const useCustomizerShell = () => {
|
|
|
183
183
|
// so SET_CURRENT_ROUTE fires even between pages that both lack CMS content.
|
|
184
184
|
useEffect(() => {
|
|
185
185
|
setCurrentPath(window.location.pathname);
|
|
186
|
-
|
|
186
|
+
let active = true;
|
|
187
|
+
const updatePath = () => {
|
|
188
|
+
if (active)
|
|
189
|
+
setCurrentPath(window.location.pathname);
|
|
190
|
+
};
|
|
187
191
|
// Intercept pushState/replaceState for client-side routing (e.g. React Router)
|
|
188
|
-
const originalPushState = history.pushState
|
|
189
|
-
const originalReplaceState = history.replaceState
|
|
190
|
-
|
|
191
|
-
originalPushState(
|
|
192
|
+
const originalPushState = history.pushState;
|
|
193
|
+
const originalReplaceState = history.replaceState;
|
|
194
|
+
const patchedPushState = function (...args) {
|
|
195
|
+
originalPushState.apply(this, args);
|
|
192
196
|
updatePath();
|
|
193
197
|
};
|
|
194
|
-
|
|
195
|
-
originalReplaceState(
|
|
198
|
+
const patchedReplaceState = function (...args) {
|
|
199
|
+
originalReplaceState.apply(this, args);
|
|
196
200
|
updatePath();
|
|
197
201
|
};
|
|
202
|
+
history.pushState = patchedPushState;
|
|
203
|
+
history.replaceState = patchedReplaceState;
|
|
198
204
|
// Handle back/forward navigation
|
|
199
205
|
window.addEventListener("popstate", updatePath);
|
|
200
206
|
return () => {
|
|
207
|
+
active = false;
|
|
201
208
|
window.removeEventListener("popstate", updatePath);
|
|
202
|
-
history.pushState
|
|
203
|
-
|
|
209
|
+
if (history.pushState === patchedPushState) {
|
|
210
|
+
history.pushState = originalPushState;
|
|
211
|
+
}
|
|
212
|
+
if (history.replaceState === patchedReplaceState) {
|
|
213
|
+
history.replaceState = originalReplaceState;
|
|
214
|
+
}
|
|
204
215
|
};
|
|
205
216
|
}, []);
|
|
206
217
|
// Tell the parent window about the current route
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "4.
|
|
1
|
+
export const VERSION = "4.6.0";
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
interface PreviewContext {
|
|
3
|
-
linkName?: string;
|
|
4
|
-
releaseId?: string;
|
|
5
|
-
releaseName?: string;
|
|
6
|
-
locale?: string;
|
|
7
|
-
pageDraft?: string;
|
|
8
|
-
siteSettingsDraft?: string;
|
|
9
|
-
testHandle?: string;
|
|
10
|
-
testVariantHandle?: string;
|
|
11
|
-
}
|
|
12
|
-
interface PreviewToastProps {
|
|
13
|
-
isPreviewModeEnabled: boolean;
|
|
14
|
-
environment?: string;
|
|
15
|
-
previewContext?: PreviewContext;
|
|
16
|
-
}
|
|
17
|
-
export declare const buildPreviewMessage: (environment?: string, previewContext?: PreviewContext) => string;
|
|
18
|
-
export declare const PreviewToast: ({ isPreviewModeEnabled, environment, previewContext, }: PreviewToastProps) => React.JSX.Element | null;
|
|
19
|
-
export {};
|
|
20
|
-
//# sourceMappingURL=preview-toast.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,UAAU,iBAAiB;IACzB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAsBD,eAAO,MAAM,mBAAmB,iBAChB,MAAM,mBACH,cAAc,WAgDhC,CAAC;AAEF,eAAO,MAAM,YAAY,2DAItB,iBAAiB,6BAkInB,CAAC"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
const Eye = (props) => {
|
|
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
|
-
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
|
-
};
|
|
6
|
-
export const buildPreviewMessage = (environment, previewContext) => {
|
|
7
|
-
const primaryContextParts = [];
|
|
8
|
-
const secondaryContextParts = [];
|
|
9
|
-
if (previewContext?.linkName) {
|
|
10
|
-
primaryContextParts.push(`preview link: ${previewContext.linkName}`);
|
|
11
|
-
}
|
|
12
|
-
else if (previewContext?.releaseName) {
|
|
13
|
-
primaryContextParts.push(`content release: ${previewContext.releaseName}`);
|
|
14
|
-
}
|
|
15
|
-
else if (previewContext?.releaseId) {
|
|
16
|
-
primaryContextParts.push("content release");
|
|
17
|
-
}
|
|
18
|
-
if (previewContext?.locale) {
|
|
19
|
-
secondaryContextParts.push(`locale: ${previewContext.locale}`);
|
|
20
|
-
}
|
|
21
|
-
if (previewContext?.pageDraft) {
|
|
22
|
-
secondaryContextParts.push(`page: ${previewContext.pageDraft}`);
|
|
23
|
-
}
|
|
24
|
-
if (previewContext?.siteSettingsDraft) {
|
|
25
|
-
secondaryContextParts.push(`settings: ${previewContext.siteSettingsDraft}`);
|
|
26
|
-
}
|
|
27
|
-
// Backpack uses a lone `control` variant as a neutral preview fallback.
|
|
28
|
-
// Only describe an A/B test when the preview carries a complete test context.
|
|
29
|
-
if (previewContext?.testHandle && previewContext.testVariantHandle) {
|
|
30
|
-
secondaryContextParts.push(`test: ${previewContext.testVariantHandle}`);
|
|
31
|
-
}
|
|
32
|
-
if (primaryContextParts.length === 0 && secondaryContextParts.length === 0) {
|
|
33
|
-
const baseMessage = "You are currently previewing your storefront with draft content";
|
|
34
|
-
return environment
|
|
35
|
-
? `${baseMessage} on ${environment} environment`
|
|
36
|
-
: baseMessage;
|
|
37
|
-
}
|
|
38
|
-
const parts = ["Previewing", ...primaryContextParts];
|
|
39
|
-
if (environment) {
|
|
40
|
-
parts.push(`${environment} environment`);
|
|
41
|
-
}
|
|
42
|
-
parts.push(...secondaryContextParts);
|
|
43
|
-
return parts.join(" • ");
|
|
44
|
-
};
|
|
45
|
-
export const PreviewToast = ({ isPreviewModeEnabled, environment, previewContext, }) => {
|
|
46
|
-
const [showToast, setShowToast] = useState(false);
|
|
47
|
-
const exitPreviewMode = async () => {
|
|
48
|
-
try {
|
|
49
|
-
const response = await fetch("/api/edit", {
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers: {
|
|
52
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
throw new Error(`ERR_RE_API_ERROR: HTTP error! Status: ${response.status} Doc: https://docs.packdigital.com/err/ERR_RE_API_ERROR`);
|
|
57
|
-
}
|
|
58
|
-
window.location.reload();
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error("Error exiting preview:", error.message);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
const isIframe = window.self !== window.top;
|
|
66
|
-
if (isPreviewModeEnabled && !isIframe) {
|
|
67
|
-
setShowToast(true);
|
|
68
|
-
}
|
|
69
|
-
}, [isPreviewModeEnabled]);
|
|
70
|
-
if (showToast) {
|
|
71
|
-
return (React.createElement("div", { "data-pack-preview-toast": true, style: {
|
|
72
|
-
position: "fixed",
|
|
73
|
-
zIndex: "2147483647",
|
|
74
|
-
left: 0,
|
|
75
|
-
right: 0,
|
|
76
|
-
paddingLeft: "max(16px, env(safe-area-inset-left))",
|
|
77
|
-
paddingRight: "max(16px, env(safe-area-inset-right))",
|
|
78
|
-
bottom: "max(16px, env(safe-area-inset-bottom))",
|
|
79
|
-
width: "100%",
|
|
80
|
-
boxSizing: "border-box",
|
|
81
|
-
pointerEvents: "none",
|
|
82
|
-
} },
|
|
83
|
-
React.createElement("div", { "data-pack-preview-toast-content": true, style: {
|
|
84
|
-
margin: "0 auto",
|
|
85
|
-
pointerEvents: "auto",
|
|
86
|
-
minWidth: "min(640px, 100%)",
|
|
87
|
-
maxWidth: "min(960px, 100%)",
|
|
88
|
-
boxShadow: "0px 2px 10px 0px rgba(0, 0, 0, 0.10), 0px 0px 2px 0px rgba(0, 0, 0, 0.10)",
|
|
89
|
-
width: "fit-content",
|
|
90
|
-
boxSizing: "border-box",
|
|
91
|
-
padding: "8px 12px",
|
|
92
|
-
backgroundColor: "#1f2937",
|
|
93
|
-
color: "#f9fafb",
|
|
94
|
-
borderRadius: "8px",
|
|
95
|
-
display: "flex",
|
|
96
|
-
alignItems: "center",
|
|
97
|
-
fontFamily: '"Inter", sans-serif',
|
|
98
|
-
justifyContent: "space-between",
|
|
99
|
-
gap: "8px",
|
|
100
|
-
} },
|
|
101
|
-
React.createElement("div", { style: {
|
|
102
|
-
display: "flex",
|
|
103
|
-
alignItems: "center",
|
|
104
|
-
gap: "8px",
|
|
105
|
-
overflow: "hidden",
|
|
106
|
-
flex: "1 1 auto",
|
|
107
|
-
minWidth: 0,
|
|
108
|
-
} },
|
|
109
|
-
React.createElement(Eye, { style: { width: 16, height: 16, minWidth: 16 } }),
|
|
110
|
-
React.createElement("p", { style: {
|
|
111
|
-
flex: 1,
|
|
112
|
-
minWidth: 0,
|
|
113
|
-
margin: 0,
|
|
114
|
-
fontSize: "14px",
|
|
115
|
-
lineHeight: "20px",
|
|
116
|
-
display: "-webkit-box",
|
|
117
|
-
WebkitBoxOrient: "vertical",
|
|
118
|
-
WebkitLineClamp: 2,
|
|
119
|
-
overflow: "hidden",
|
|
120
|
-
overflowWrap: "anywhere",
|
|
121
|
-
} }, buildPreviewMessage(environment, previewContext))),
|
|
122
|
-
React.createElement("button", { type: "button", "aria-label": "Exit preview mode", onClick: exitPreviewMode, style: {
|
|
123
|
-
cursor: "pointer",
|
|
124
|
-
fontSize: 13,
|
|
125
|
-
fontWeight: "500",
|
|
126
|
-
flexShrink: "0",
|
|
127
|
-
minHeight: 44,
|
|
128
|
-
padding: "6px 8px",
|
|
129
|
-
border: 0,
|
|
130
|
-
borderRadius: 4,
|
|
131
|
-
background: "transparent",
|
|
132
|
-
color: "inherit",
|
|
133
|
-
fontFamily: "inherit",
|
|
134
|
-
textDecoration: "underline",
|
|
135
|
-
textUnderlineOffset: 2,
|
|
136
|
-
whiteSpace: "nowrap",
|
|
137
|
-
} }, "Exit preview"))));
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
140
|
-
};
|