@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 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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,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,GACf,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;AAInD,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,qBAmBrB"}
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,3 +1,4 @@
1
1
  import React from "react";
2
+ export declare function useSections({ content }: any): any;
2
3
  export declare function RenderSections({ content }: any): React.JSX.Element | null;
3
4
  //# sourceMappingURL=render-sections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAoClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BAiC9C"}
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"}
@@ -25,7 +25,7 @@ function Sections({ sections }) {
25
25
  }, [sections]);
26
26
  return React.createElement(React.Fragment, null, renderedSections);
27
27
  }
28
- export function RenderSections({ content }) {
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,4BAG1B;IACD,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,SAkBA,CAAC"}
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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {