ublo-lib 1.7.10 → 1.8.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.
@@ -1,18 +1,50 @@
1
1
  import * as React from "react";
2
+ import Script from "next/script";
3
+ import getConfig from "next/config";
4
+ import { useRouter } from "next/router";
2
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
+ const {
7
+ publicRuntimeConfig
8
+ } = getConfig();
9
+ const {
10
+ disableClientRouting
11
+ } = publicRuntimeConfig;
3
12
  const DEFAULT_SOURCE = "https://plausible.io/js/script.file-downloads.outbound-links.js";
4
- const Script = ({
13
+ const PlausibleScript = ({
5
14
  lang,
6
15
  plausibleDomain,
7
16
  source = DEFAULT_SOURCE
8
17
  }) => {
9
- if (!plausibleDomain) return null;
10
- const domain = typeof plausibleDomain === "object" ? plausibleDomain[lang] : plausibleDomain;
11
- if (!domain) return null;
12
- return _jsx("script", {
13
- defer: true,
18
+ const [loaded, setLoaded] = React.useState(false);
19
+ const router = useRouter();
20
+ const hasI18n = typeof plausibleDomain === "object";
21
+ if (hasI18n && !lang) {
22
+ console.warn("PlausibleScript: the lang props is mandatory if you want to use a specific domain for each lang");
23
+ }
24
+ const domain = hasI18n ? plausibleDomain[lang] : plausibleDomain;
25
+ const sendPageView = React.useCallback(() => {
26
+ window.plausible("pageview", {
27
+ url: window.location.href,
28
+ domain,
29
+ screen_width: window.innerWidth
30
+ });
31
+ }, [domain]);
32
+ React.useEffect(() => {
33
+ if (!disableClientRouting && domain && loaded) {
34
+ router.events.on("routeChangeComplete", sendPageView);
35
+ return () => {
36
+ router.events.off("routeChangeComplete", sendPageView);
37
+ };
38
+ }
39
+ }, [domain, loaded, sendPageView]);
40
+ if (!domain) {
41
+ console.warn("PlausibleScript: domain is missing or undefined");
42
+ return null;
43
+ }
44
+ return _jsx(Script, {
14
45
  "data-domain": domain,
15
- src: source
46
+ src: source,
47
+ onLoad: () => setLoaded(true)
16
48
  });
17
49
  };
18
- export default Script;
50
+ export default PlausibleScript;
@@ -30,8 +30,6 @@ const LEVELS = {
30
30
  "2-snowboard": "SNOEN2",
31
31
  "3-snowboard": "SNOEN3",
32
32
  "snowboard-expert": "SNOEXP",
33
- "ptit-freestyler": "FREE",
34
- "freestyler-inter": "FREE",
35
33
  freestyler: "FREE",
36
34
  "freestyler-expert": "FREEXP",
37
35
  "freestyler-pro": "FREPRO",
@@ -89,7 +87,7 @@ const Level = ({
89
87
  const clicked = name => e => {
90
88
  if (levelRef.current) {
91
89
  levelRef.current.scrollIntoView({
92
- behaviour: "smooth",
90
+ behavior: "smooth",
93
91
  block: "center",
94
92
  inline: "center"
95
93
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.7.10",
3
+ "version": "1.8.0",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.1.0",
6
6
  "next": "^12.0.0 || ^13.0.0",