@pack/react 0.1.1 → 0.1.3
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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/preview/pack-analytics.d.ts +16 -0
- package/dist/preview/pack-analytics.d.ts.map +1 -0
- package/dist/preview/pack-analytics.js +65 -0
- package/dist/preview/preview-provider.d.ts.map +1 -1
- package/dist/preview/preview-provider.js +2 -0
- package/dist/render-sections.d.ts +1 -0
- package/dist/render-sections.d.ts.map +1 -1
- package/dist/render-sections.js +14 -1
- package/dist/use-overlay-script.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RenderSections } from "./render-sections";
|
|
1
|
+
import { RenderSections, useSections } from "./render-sections";
|
|
2
2
|
import { PreviewProvider } from "./preview/preview-provider";
|
|
3
3
|
import { usePreviewContext } from "./preview/preview-content";
|
|
4
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
5
5
|
import { useOverlayScript } from "./use-overlay-script";
|
|
6
6
|
import { registerSection } from "./register-section";
|
|
7
7
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
8
|
-
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, };
|
|
8
|
+
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, useSections, };
|
|
9
9
|
//# 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,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,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,eAAe,EACf,gCAAgC,EAChC,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,WAAW,GACZ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RenderSections } from "./render-sections";
|
|
1
|
+
import { RenderSections, useSections } from "./render-sections";
|
|
2
2
|
import { PreviewProvider } from "./preview/preview-provider";
|
|
3
3
|
import { usePreviewContext } from "./preview/preview-content";
|
|
4
4
|
import { useSiteSettings } from "./use-site-settings";
|
|
5
5
|
import { useOverlayScript } from "./use-overlay-script";
|
|
6
6
|
import { registerSection } from "./register-section";
|
|
7
7
|
import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
|
|
8
|
-
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, };
|
|
8
|
+
export { registerSection, registerStorefrontSettingsSchema, usePreviewContext, useSiteSettings, useOverlayScript, PreviewProvider, RenderSections, useSections, };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type BrowserData = {
|
|
2
|
+
userAgent: string;
|
|
3
|
+
pathname: string;
|
|
4
|
+
query: string;
|
|
5
|
+
screen: string;
|
|
6
|
+
referrer: string;
|
|
7
|
+
hostname: string;
|
|
8
|
+
language: string;
|
|
9
|
+
locale: string;
|
|
10
|
+
userTimeZone: string;
|
|
11
|
+
connection: string;
|
|
12
|
+
deviceCategory: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function usePackTrack(): void;
|
|
16
|
+
//# sourceMappingURL=pack-analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack-analytics.d.ts","sourceRoot":"","sources":["../../src/preview/pack-analytics.tsx"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAiDF,wBAAgB,YAAY,SA0B3B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
function getBrowserData() {
|
|
3
|
+
let userTimeZone;
|
|
4
|
+
let userLocale;
|
|
5
|
+
try {
|
|
6
|
+
userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
7
|
+
userLocale =
|
|
8
|
+
navigator.languages && navigator.languages.length
|
|
9
|
+
? navigator.languages[0]
|
|
10
|
+
: navigator.userLanguage ||
|
|
11
|
+
navigator.language ||
|
|
12
|
+
navigator.browserLanguage ||
|
|
13
|
+
"unknown";
|
|
14
|
+
}
|
|
15
|
+
catch (error) { }
|
|
16
|
+
const connection = navigator.connection ||
|
|
17
|
+
navigator.mozConnection ||
|
|
18
|
+
navigator.webkitConnection;
|
|
19
|
+
const minWidth = 768;
|
|
20
|
+
// prettier-ignore
|
|
21
|
+
const hasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
22
|
+
let deviceCategory = "desktop";
|
|
23
|
+
if (hasTouchSupport) {
|
|
24
|
+
const hasSmallScreen = window.screen.width < minWidth;
|
|
25
|
+
deviceCategory = hasSmallScreen ? "mobile" : "tablet";
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
userAgent: window.navigator.userAgent,
|
|
29
|
+
pathname: window.location.pathname,
|
|
30
|
+
query: window.location.search,
|
|
31
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
32
|
+
referrer: document.referrer,
|
|
33
|
+
hostname: window.location.hostname,
|
|
34
|
+
language: navigator.language,
|
|
35
|
+
locale: userLocale,
|
|
36
|
+
userTimeZone: userTimeZone || "unknown",
|
|
37
|
+
connection: connection?.effectiveType || "unknown",
|
|
38
|
+
deviceCategory,
|
|
39
|
+
href: window.location.href,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function usePackTrack() {
|
|
43
|
+
const [pathname, setPathname] = useState();
|
|
44
|
+
const analytics = async () => {
|
|
45
|
+
const browserData = getBrowserData();
|
|
46
|
+
if (pathname === browserData.pathname)
|
|
47
|
+
return;
|
|
48
|
+
setPathname(browserData.pathname);
|
|
49
|
+
try {
|
|
50
|
+
await fetch("/pack/track", {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify(getBrowserData()),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error("Error hit /pack/track: ", error.message);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
analytics();
|
|
64
|
+
}, [analytics]);
|
|
65
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAKnD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,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;CACH;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,mBAAmB,qBAqBrB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
|
+
import { usePackTrack } from "./pack-analytics";
|
|
2
3
|
import { PreviewContext } from "./preview-content";
|
|
3
4
|
import { PreviewToast } from "./preview-toast";
|
|
4
5
|
export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
|
|
5
6
|
const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
|
|
7
|
+
usePackTrack();
|
|
6
8
|
return (React.createElement(PreviewContext.Provider, { value: {
|
|
7
9
|
isPreview: !!isPreviewModeEnabled,
|
|
8
10
|
previewStorefrontSettings,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAuElD,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,OAM3C;AAED,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAI9C"}
|
package/dist/render-sections.js
CHANGED
|
@@ -25,7 +25,7 @@ function Sections({ sections }) {
|
|
|
25
25
|
}, [sections]);
|
|
26
26
|
return React.createElement(React.Fragment, null, renderedSections);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
function useRenderSections({ content }) {
|
|
29
29
|
const { isPreview, setPreviewStorefrontSettings, customizerMeta } = usePreviewContext();
|
|
30
30
|
const { content: liveContent, storefrontSettings } = useCustomizerShell({
|
|
31
31
|
environment: "production",
|
|
@@ -49,6 +49,19 @@ export function RenderSections({ content }) {
|
|
|
49
49
|
const sections = useMemo(() => {
|
|
50
50
|
return liveContent?.sections?.nodes || liveContent?.sections;
|
|
51
51
|
}, [liveContent?.sections]);
|
|
52
|
+
return {
|
|
53
|
+
sections,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function useSections({ content }) {
|
|
57
|
+
const { sections } = useRenderSections({ content });
|
|
58
|
+
if (!sections)
|
|
59
|
+
return null;
|
|
60
|
+
const visibleSections = Sections({ sections });
|
|
61
|
+
return visibleSections?.props?.children || null;
|
|
62
|
+
}
|
|
63
|
+
export function RenderSections({ content }) {
|
|
64
|
+
const { sections } = useRenderSections({ content });
|
|
52
65
|
if (!sections)
|
|
53
66
|
return null;
|
|
54
67
|
return React.createElement(Sections, { sections: sections });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-overlay-script.d.ts","sourceRoot":"","sources":["../src/use-overlay-script.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE;YACL,uBAAuB,EAAE,OAAO,CAAC;SAClC,CAAC;KACH;CACF;AAED,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"use-overlay-script.d.ts","sourceRoot":"","sources":["../src/use-overlay-script.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE;YACL,uBAAuB,EAAE,OAAO,CAAC;SAClC,CAAC;KACH;CACF;AAED,eAAO,MAAM,gBAAgB;eAIhB,OAAO;aACT;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;UAmB5C,CAAC"}
|