@arcblock/ux 3.4.6 → 3.4.7

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,92 +1,98 @@
1
- import { jsxs as b, jsx as o } from "react/jsx-runtime";
2
- import { useState as l, useRef as $, useEffect as c } from "react";
3
- import { useTheme as M, Skeleton as E } from "@mui/material";
1
+ import { jsxs as T, jsx as s } from "react/jsx-runtime";
2
+ import { lazy as M, useState as l, useRef as z, useEffect as m, Suspense as E } from "react";
3
+ import { useTheme as F, Skeleton as P } from "@mui/material";
4
4
  import n from "prop-types";
5
- import F from "react-lottie-player";
6
- import P from "lodash/noop";
7
- import { styled as R } from "../Theme/index.js";
8
- function W({
9
- animationData: m = null,
10
- size: s = 256,
5
+ import R from "lodash/noop";
6
+ import { styled as W } from "../Theme/index.js";
7
+ const q = M(() => import("react-lottie-player"));
8
+ function B({
9
+ animationData: c = null,
10
+ size: o = 256,
11
11
  message: r = "",
12
12
  messageDuration: f = 5e3,
13
- messageLoop: T = !0,
13
+ messageLoop: v = !0,
14
14
  tips: a = [],
15
15
  tipsDuration: u = 5e3,
16
- maybeDuration: v = 12e4,
16
+ maybeDuration: x = 12e4,
17
17
  speed: h = 1,
18
- increaseSpeed: x = 0,
19
- ...I
18
+ increaseSpeed: I = 0,
19
+ ...k
20
20
  }) {
21
- const g = M(), [d, N] = l(0), [y, k] = l(h), [w, A] = l(0), [O, S] = l(null), [j, p] = l(!m), C = $((/* @__PURE__ */ new Date()).getTime());
22
- Array.isArray(r) || (r = [r]), c(() => {
23
- m || (p(!0), (async () => {
21
+ const g = F(), [d, N] = l(0), [y, A] = l(h), [w, S] = l(0), [O, j] = l(null), [C, p] = l(!c), L = z((/* @__PURE__ */ new Date()).getTime());
22
+ Array.isArray(r) || (r = [r]), m(() => {
23
+ c || (p(!0), (async () => {
24
24
  try {
25
25
  const e = await (g.palette.mode === "dark" ? import("./dark-animation.json.js") : import("./default-animation.json.js"));
26
- S(e.default || e), p(!1);
26
+ j(e.default || e), p(!1);
27
27
  } catch (e) {
28
28
  console.error("Failed to load animation:", e), p(!1);
29
29
  }
30
30
  })());
31
- }, [m, g.palette.mode]), c(() => {
31
+ }, [c, g.palette.mode]), m(() => {
32
32
  if (!r)
33
33
  return;
34
34
  let t = 0;
35
35
  const e = setInterval(() => {
36
- t++, t >= r.length && (T ? t = 0 : t = r.length - 1), A(t);
36
+ t++, t >= r.length && (v ? t = 0 : t = r.length - 1), S(t);
37
37
  }, f);
38
38
  return () => {
39
39
  clearInterval(e);
40
40
  };
41
- }, [r, f]), c(() => {
41
+ }, [r, f]), m(() => {
42
42
  if (!a.length)
43
- return P;
43
+ return R;
44
44
  const t = setTimeout(() => {
45
45
  let e = d + 1;
46
46
  e >= a.length && (e = 0), N(e);
47
47
  }, u);
48
48
  return () => clearTimeout(t);
49
- }, [a, u, d]), c(() => {
49
+ }, [a, u, d]), m(() => {
50
50
  const t = setTimeout(() => {
51
- let i = ((/* @__PURE__ */ new Date()).getTime() - C.current) / v;
51
+ let i = ((/* @__PURE__ */ new Date()).getTime() - L.current) / x;
52
52
  i > 1 && (i = 1);
53
- const D = h + x * i;
54
- k(D);
53
+ const $ = h + I * i;
54
+ A($);
55
55
  }, 1e3);
56
56
  return () => clearTimeout(t);
57
57
  }, [y]);
58
- const L = (t) => {
58
+ const D = (t) => {
59
59
  let e = "message-before";
60
60
  return w === t ? e = "show-message" : w < t && (e = "message-after"), e;
61
- };
62
- return /* @__PURE__ */ b(q, { ...I, children: [
63
- j ? /* @__PURE__ */ o("div", { style: { width: s, height: s, display: "flex", justifyContent: "center", alignItems: "center" }, children: /* @__PURE__ */ o(E, { variant: "rounded", width: s * 0.4, height: s * 0.4 }) }) : /* @__PURE__ */ o(
64
- F,
65
- {
66
- loop: !0,
67
- animationData: m || O,
68
- play: !0,
69
- speed: y,
70
- style: {
71
- width: s,
72
- height: s
61
+ }, b = /* @__PURE__ */ s("div", { style: { width: o, height: o, display: "flex", justifyContent: "center", alignItems: "center" }, children: /* @__PURE__ */ s(P, { variant: "rounded", width: o * 0.4, height: o * 0.4 }) });
62
+ return /* @__PURE__ */ T(G, { ...k, children: [
63
+ C ? (
64
+ // 当正在加载默认动画时直接展示 fallback
65
+ b
66
+ ) : (
67
+ // 否则使用 Suspense 包裹懒加载的 Lottie,Suspense 会在 Lottie 本身未加载完成时展示 fallback
68
+ /* @__PURE__ */ s(E, { fallback: b, children: /* @__PURE__ */ s(
69
+ q,
70
+ {
71
+ loop: !0,
72
+ animationData: c || O,
73
+ play: !0,
74
+ speed: y,
75
+ style: {
76
+ width: o,
77
+ height: o
78
+ }
73
79
  }
74
- }
80
+ ) })
75
81
  ),
76
- r && /* @__PURE__ */ o("div", { className: "waiter-message", children: r.map((t, e) => {
77
- const i = L(e);
78
- return /* @__PURE__ */ b(
82
+ r && /* @__PURE__ */ s("div", { className: "waiter-message", children: r.map((t, e) => {
83
+ const i = D(e);
84
+ return /* @__PURE__ */ T(
79
85
  "div",
80
86
  {
81
87
  children: [
82
- /* @__PURE__ */ o("span", { className: `message-block ${i}`, children: t }),
83
- /* @__PURE__ */ o("span", { className: `placeholder-message ${i}`, children: t })
88
+ /* @__PURE__ */ s("span", { className: `message-block ${i}`, children: t }),
89
+ /* @__PURE__ */ s("span", { className: `placeholder-message ${i}`, children: t })
84
90
  ]
85
91
  },
86
92
  e
87
93
  );
88
94
  }) }),
89
- a.length ? /* @__PURE__ */ o("div", { className: "waiter-tips-container", children: a.map((t, e) => /* @__PURE__ */ o(
95
+ a.length ? /* @__PURE__ */ s("div", { className: "waiter-tips-container", children: a.map((t, e) => /* @__PURE__ */ s(
90
96
  "div",
91
97
  {
92
98
  className: `waiter-tips-block ${d === e ? "show-tips" : ""}`,
@@ -96,7 +102,7 @@ function W({
96
102
  )) }) : ""
97
103
  ] });
98
104
  }
99
- W.propTypes = {
105
+ B.propTypes = {
100
106
  animationData: n.oneOfType([n.object, n.oneOf([null])]),
101
107
  size: n.oneOfType([n.number, n.string]),
102
108
  message: n.oneOfType([n.string, n.arrayOf(n.node)]),
@@ -108,7 +114,7 @@ W.propTypes = {
108
114
  maybeDuration: n.number,
109
115
  increaseSpeed: n.number
110
116
  };
111
- const q = R("div")`
117
+ const G = W("div")`
112
118
  display: flex;
113
119
  justify-content: center;
114
120
  align-items: center;
@@ -179,5 +185,5 @@ const q = R("div")`
179
185
  }
180
186
  `;
181
187
  export {
182
- W as default
188
+ B as default
183
189
  };
@@ -1,64 +1,64 @@
1
- import { createTheme as p, responsiveFontSizes as O } from "@mui/material";
2
- import A from "webfontloader";
3
- import { DEFAULT_FONTS as _, getDefaultThemePrefer as b, mergeThemeOptions as f, getBlockletThemeOptions as d, mergeAllThemeOptions as C, BLOCKLET_THEME_DARK as k, BLOCKLET_THEME_LIGHT as x } from "@blocklet/theme";
1
+ import { createTheme as f, responsiveFontSizes as A } from "@mui/material";
2
+ import _ from "webfontloader";
3
+ import { DEFAULT_FONTS as b, getDefaultThemePrefer as C, mergeThemeOptions as d, getBlockletThemeOptions as h, mergeAllThemeOptions as k, BLOCKLET_THEME_DARK as x, BLOCKLET_THEME_LIGHT as E } from "@blocklet/theme";
4
4
  import { mergeThemeOptions as Q, mergeAllThemeOptions as V } from "@blocklet/theme";
5
- import { cleanedObj as c } from "../Util/index.js";
5
+ import { cleanedObj as m } from "../Util/index.js";
6
6
  import "@fontsource/roboto/latin-400.css";
7
7
  import "@fontsource/roboto/latin-500.css";
8
8
  import "@fontsource/roboto/latin-700.css";
9
9
  import "@fontsource/roboto/latin-ext-400.css";
10
10
  import "@fontsource/roboto/latin-ext-500.css";
11
11
  import "@fontsource/roboto/latin-ext-700.css";
12
- function E(e) {
12
+ function D(e) {
13
13
  return e && typeof e == "object" && e.palette && typeof e.palette.getContrastText == "function";
14
14
  }
15
15
  function R(e) {
16
- return E(e) && e.__isUxTheme__ === !0;
16
+ return D(e) && e.__isUxTheme__ === !0;
17
17
  }
18
- function h(e, t = /* @__PURE__ */ new Set()) {
18
+ function u(e, t = /* @__PURE__ */ new Set()) {
19
19
  return !e || typeof e != "object" || (typeof e.fontFamily == "string" && e.fontFamily.replace(/"/g, "").split(",").map((o) => o.trim()).filter(Boolean).forEach((o) => t.add(o)), Object.values(e).forEach((o) => {
20
- typeof o == "object" && h(o, t);
20
+ typeof o == "object" && u(o, t);
21
21
  })), t;
22
22
  }
23
- const l = new Set(_.concat("inherit"));
24
- function D(e) {
25
- const t = e.filter((n) => !l.has(n));
23
+ const a = new Set(b.concat("inherit"));
24
+ function w(e) {
25
+ const t = e.filter((r) => !a.has(r));
26
26
  if (t.length === 0)
27
27
  return Promise.resolve(!0);
28
- t.forEach((n) => l.add(n));
28
+ t.forEach((r) => a.add(r));
29
29
  const o = t.length - 1;
30
- return t[o] = `${t[o]}&display=swap`, new Promise((n) => {
31
- A.load({
30
+ return t[o] = `${t[o]}&display=swap`, new Promise((r) => {
31
+ _.load({
32
32
  google: {
33
33
  families: t
34
34
  },
35
- active: () => n(!0),
36
- inactive: () => n(!0),
37
- fontinactive: (r, i) => {
38
- l.delete(r), console.warn(`font ${r} ${i} download failed`);
35
+ active: () => r(!0),
36
+ inactive: () => r(!0),
37
+ fontinactive: (n, i) => {
38
+ a.delete(n), console.warn(`font ${n} ${i} download failed`);
39
39
  }
40
40
  });
41
41
  });
42
42
  }
43
- function u(e = "light") {
44
- return e === "dark" ? k : x;
43
+ function T(e = "light") {
44
+ return e === "dark" ? x : E;
45
45
  }
46
- function w(e) {
46
+ function v(e) {
47
47
  let t = null;
48
48
  return () => {
49
49
  if (t) return t;
50
- const o = f(u(e), d(e));
51
- return t = p(o), t;
50
+ const o = d(T(e), h(e));
51
+ return t = f(o), t;
52
52
  };
53
53
  }
54
- const m = ({ palette: e, components: t, overrides: o, ...n }) => ({
54
+ const p = ({ palette: e, components: t, overrides: o, ...r }) => ({
55
55
  palette: e,
56
56
  components: {
57
57
  ...o,
58
58
  ...t
59
59
  },
60
- ...n
61
- }), v = {
60
+ ...r
61
+ }), L = {
62
62
  themeName: "ArcBlock",
63
63
  pageWidth: "md",
64
64
  disableBlockletTheme: !1,
@@ -83,25 +83,24 @@ const m = ({ palette: e, components: t, overrides: o, ...n }) => ({
83
83
  danger: "#D0021B",
84
84
  lightGrey: "#BCBCBC"
85
85
  }
86
- }, L = (...e) => {
87
- const t = b(), o = w(t), n = e.reduce(
88
- (B, a) => f(B, m(typeof a == "function" ? a(o()) : a)),
89
- m(v)
90
- ), r = n.mode || n.palette?.mode || t, i = d(r), T = u(r), { disableBlockletTheme: g } = n, F = C(
86
+ }, U = (...e) => {
87
+ const t = C(), o = v(t), r = e.reduce(
88
+ (O, s) => d(O, p(typeof s == "function" ? s(o()) : s)),
89
+ p(L)
90
+ ), n = r.mode || r.palette?.mode || t, i = h(n), g = T(n), { disableBlockletTheme: F } = r, y = k(
91
91
  [
92
- T,
93
- !g && c(i),
94
- c(n),
92
+ g,
93
+ !F && m(i),
94
+ m(r),
95
95
  // 确保 mode 跟 prefer 一致
96
96
  {
97
- mode: r,
98
- palette: { mode: r }
97
+ mode: n,
98
+ palette: { mode: n }
99
99
  }
100
100
  ].filter(Boolean)
101
- ), s = p(F);
102
- s.__isUxTheme__ = !0;
103
- const y = h(s.typography);
104
- return D(Array.from(y)), O(s, {
101
+ ), l = f(y);
102
+ l.__isUxTheme__ = !0;
103
+ const c = A(l, {
105
104
  breakpoints: ["xs", "sm", "md", "lg"],
106
105
  disableAlign: !1,
107
106
  factor: 3,
@@ -120,17 +119,18 @@ const m = ({ palette: e, components: t, overrides: o, ...n }) => ({
120
119
  "button",
121
120
  "overline"
122
121
  ]
123
- });
124
- }, W = L;
122
+ }), B = u(c.typography);
123
+ return w(Array.from(B)), c;
124
+ }, W = U;
125
125
  export {
126
- h as collectFontFamilies,
127
- L as create,
128
- u as createDefaultThemeOptions,
126
+ u as collectFontFamilies,
127
+ U as create,
128
+ T as createDefaultThemeOptions,
129
129
  W as createTheme,
130
130
  Q as deepmerge,
131
131
  V as deepmergeAll,
132
- E as isTheme,
132
+ D as isTheme,
133
133
  R as isUxTheme,
134
- w as lazyCreateDefaultTheme,
135
- D as loadFonts
134
+ v as lazyCreateDefaultTheme,
135
+ w as loadFonts
136
136
  };
@@ -1,18 +1,21 @@
1
1
  import n from "debug";
2
- const c = n, u = (o) => new Proxy(window.console, {
2
+ const d = n;
3
+ let t = !1;
4
+ const u = () => {
5
+ t || (t = !0, window.blocklet?.ENABLE_DEBUG_TMP === "false" ? n.disable() : window.blocklet?.ENABLE_DEBUG_TMP && n.enable(window.blocklet?.ENABLE_DEBUG_TMP));
6
+ }, b = (i) => (u(), new Proxy(window.console, {
3
7
  get(r, e) {
4
- return (...i) => {
8
+ return (...o) => {
5
9
  try {
6
- return ["log", "debug", "info", "warn", "error"].includes(e) ? r[e](o, ...i) : r[e] instanceof Function ? r[e](...i) : r[e];
10
+ return ["log", "debug", "info", "warn", "error"].includes(e) ? r[e](i, ...o) : r[e] instanceof Function ? r[e](...o) : r[e];
7
11
  } catch (l) {
8
- console.error(`Logger error in ${o}:`, l);
12
+ console.error(`Logger error in ${i}:`, l);
9
13
  return;
10
14
  }
11
15
  };
12
16
  }
13
- });
14
- window.blocklet?.ENABLE_DEBUG_TMP === "false" ? n.disable() : window.blocklet?.ENABLE_DEBUG_TMP && n.enable(window.blocklet?.ENABLE_DEBUG_TMP);
17
+ }));
15
18
  export {
16
- c as createDebug,
17
- u as createLogger
19
+ d as createDebug,
20
+ b as createLogger
18
21
  };
@@ -1,10 +1,10 @@
1
1
  import { useCallback as p, useState as l, useEffect as d } from "react";
2
2
  import e from "dayjs";
3
+ import "dayjs/locale/zh-cn";
4
+ import "dayjs/locale/en";
3
5
  import h from "dayjs/plugin/utc";
4
6
  import T from "dayjs/plugin/timezone";
5
7
  import z from "dayjs/plugin/localizedFormat";
6
- import "dayjs/locale/zh-cn";
7
- import "dayjs/locale/en";
8
8
  import { formatToDatetime as I } from "../Util/index.js";
9
9
  e.extend(h);
10
10
  e.extend(T);
@@ -1,4 +1,4 @@
1
- const e = "3.4.6", s = { "@blocklet/js-sdk": "^1.17.7" }, n = {
1
+ const e = "3.4.7", s = { "@blocklet/js-sdk": "^1.17.7" }, n = {
2
2
  version: e,
3
3
  dependencies: s
4
4
  };
@@ -1,26 +1,28 @@
1
- import { jsx as p } from "react/jsx-runtime";
2
- import { useLocation as f } from "react-router-dom";
3
- import { useMount as s, useDeepCompareEffect as u } from "ahooks";
4
- import r from "react-ga4";
5
- import { default as A } from "react-ga4";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { useLocation as u } from "react-router-dom";
3
+ import { useMount as l, useDeepCompareEffect as d } from "ahooks";
4
+ import i from "react-ga4";
5
+ import { default as E } from "react-ga4";
6
6
  import { googleAnalyticsMeasurementId as n } from "./env.js";
7
- n && r.initialize(n);
8
- const h = (i) => {
7
+ let r = !1;
8
+ const c = () => {
9
+ n && !r && (i.initialize(n), r = !0);
10
+ }, x = (m) => {
9
11
  const a = (o, t = document.title) => {
10
- n && r.send({ hitType: "pageview", page: o, title: t });
11
- }, c = (o, t, e, m) => {
12
- n && r.event({ category: o, action: t, label: e, value: m, transport: "beacon" });
12
+ c(), n && i.send({ hitType: "pageview", page: o, title: t });
13
+ }, s = (o, t, e, p) => {
14
+ c(), n && i.event({ category: o, action: t, label: e, value: p, transport: "beacon" });
13
15
  };
14
- return window.trackPage = a, window.trackEvent = c, function(t) {
15
- const e = f();
16
- return s(() => {
16
+ return window.trackPage = a, window.trackEvent = s, function(t) {
17
+ const e = u();
18
+ return l(() => {
17
19
  a(e.pathname);
18
- }), u(() => {
20
+ }), d(() => {
19
21
  a(e.pathname);
20
- }, [e.pathname]), /* @__PURE__ */ p(i, { ...t });
22
+ }, [e.pathname]), /* @__PURE__ */ f(m, { ...t });
21
23
  };
22
24
  };
23
25
  export {
24
- A as ReactGA,
25
- h as default
26
+ E as ReactGA,
27
+ x as default
26
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "3.4.6",
3
+ "version": "3.4.7",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -30,6 +30,12 @@
30
30
  "bugs": {
31
31
  "url": "https://github.com/ArcBlock/ux/issues"
32
32
  },
33
+ "sideEffects": [
34
+ "**/*.css",
35
+ "**/*.scss",
36
+ "**/*.svg?react",
37
+ "**/*.svg"
38
+ ],
33
39
  "publishConfig": {
34
40
  "access": "public"
35
41
  },
@@ -68,16 +74,16 @@
68
74
  "react": "^19.0.0",
69
75
  "react-router-dom": "^6.22.3"
70
76
  },
71
- "gitHead": "aea3f5520b4d9ba35ef714a8036eb8f4994ce733",
77
+ "gitHead": "eb0fca0015ba4ee80affb3b03d47505c45f8ec1c",
72
78
  "dependencies": {
73
- "@arcblock/bridge": "3.4.6",
74
- "@arcblock/did": "^1.28.2",
79
+ "@arcblock/bridge": "3.4.7",
80
+ "@arcblock/did": "^1.28.5",
75
81
  "@arcblock/did-motif": "^1.1.14",
76
- "@arcblock/icons": "3.4.6",
77
- "@arcblock/nft-display": "3.4.6",
78
- "@arcblock/react-hooks": "3.4.6",
82
+ "@arcblock/icons": "3.4.7",
83
+ "@arcblock/nft-display": "3.4.7",
84
+ "@arcblock/react-hooks": "3.4.7",
79
85
  "@blocklet/js-sdk": "^1.17.7",
80
- "@blocklet/theme": "3.4.6",
86
+ "@blocklet/theme": "3.4.7",
81
87
  "@fontsource/roboto": "~5.1.1",
82
88
  "@fontsource/ubuntu-mono": "^5.2.6",
83
89
  "@iconify-icons/logos": "^1.2.36",
@@ -85,7 +91,7 @@
85
91
  "@iconify-icons/mdi": "^1.2.48",
86
92
  "@iconify-icons/tabler": "^1.2.95",
87
93
  "@iconify/react": "^5.2.1",
88
- "@ocap/mcrypto": "^1.28.2",
94
+ "@ocap/mcrypto": "^1.28.5",
89
95
  "@solana/qr-code-styling": "^1.6.0",
90
96
  "@types/dompurify": "^3.2.0",
91
97
  "@types/mui-datatables": "^4.3.12",
@@ -1,12 +1,13 @@
1
- import { useState, useEffect, useRef } from 'react';
1
+ import { lazy, Suspense, useState, useEffect, useRef } from 'react';
2
2
  import { Skeleton } from '@mui/material';
3
3
 
4
4
  import PropTypes from 'prop-types';
5
- import Lottie from 'react-lottie-player';
6
5
  import noop from 'lodash/noop';
7
6
 
8
7
  import { styled, useTheme } from '../Theme';
9
8
 
9
+ const Lottie = lazy(() => import('react-lottie-player'));
10
+
10
11
  /**
11
12
  * 用于长时间等待的用的动画组件
12
13
  * 动画会随着时间的变化而逐步加快播放速度,好适应用户的等待心理
@@ -147,24 +148,33 @@ export default function AnimationWaiter({
147
148
  return className;
148
149
  };
149
150
 
151
+ const fallback = (
152
+ <div style={{ width: size, height: size, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
153
+ <Skeleton variant="rounded" width={size * 0.4} height={size * 0.4} />
154
+ </div>
155
+ );
156
+
150
157
  return (
151
158
  <Container {...rest}>
152
159
  {isLoading ? (
153
- <div style={{ width: size, height: size, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
154
- <Skeleton variant="rounded" width={size * 0.4} height={size * 0.4} />
155
- </div>
160
+ // 当正在加载默认动画时直接展示 fallback
161
+ fallback
156
162
  ) : (
157
- <Lottie
158
- loop
159
- animationData={animationData || defaultAnimation}
160
- play
161
- speed={currentSpeed}
162
- style={{
163
- width: size,
164
- height: size,
165
- }}
166
- />
163
+ // 否则使用 Suspense 包裹懒加载的 Lottie,Suspense 会在 Lottie 本身未加载完成时展示 fallback
164
+ <Suspense fallback={fallback}>
165
+ <Lottie
166
+ loop
167
+ animationData={animationData || defaultAnimation}
168
+ play
169
+ speed={currentSpeed}
170
+ style={{
171
+ width: size,
172
+ height: size,
173
+ }}
174
+ />
175
+ </Suspense>
167
176
  )}
177
+
168
178
  {message && (
169
179
  <div className="waiter-message">
170
180
  {message.map((text, index) => {
@@ -186,10 +186,6 @@ export const create = (...args: Array<UxThemeOptions | ((baseTheme: Theme) => Ux
186
186
  const theme = _createTheme(mergedThemeOptions);
187
187
  theme.__isUxTheme__ = true;
188
188
 
189
- // 异步加载字体
190
- const fonts = collectFontFamilies(theme.typography);
191
- loadFonts(Array.from(fonts));
192
-
193
189
  /**
194
190
  * 支持响应式字体,theme.typography.$variant 中会添加 @media 分支,比如
195
191
  * {
@@ -222,6 +218,10 @@ export const create = (...args: Array<UxThemeOptions | ((baseTheme: Theme) => Ux
222
218
  ],
223
219
  });
224
220
 
221
+ // 异步加载字体
222
+ const fonts = collectFontFamilies(enhanced.typography);
223
+ loadFonts(Array.from(fonts));
224
+
225
225
  return enhanced;
226
226
  };
227
227
 
@@ -3,7 +3,24 @@ import debug from 'debug';
3
3
 
4
4
  export const createDebug = debug;
5
5
 
6
+ let debugInitialized = false;
7
+
8
+ const initializeDebug = () => {
9
+ if (debugInitialized) {
10
+ return;
11
+ }
12
+ debugInitialized = true;
13
+
14
+ if (window.blocklet?.ENABLE_DEBUG_TMP === 'false') {
15
+ debug.disable();
16
+ } else if (window.blocklet?.ENABLE_DEBUG_TMP) {
17
+ debug.enable(window.blocklet?.ENABLE_DEBUG_TMP);
18
+ }
19
+ };
20
+
6
21
  export const createLogger = (namespace: string) => {
22
+ initializeDebug();
23
+
7
24
  return new Proxy(window.console, {
8
25
  get(target, prop: keyof Console) {
9
26
  return (...args: any[]) => {
@@ -25,9 +42,3 @@ export const createLogger = (namespace: string) => {
25
42
  },
26
43
  });
27
44
  };
28
-
29
- if (window.blocklet?.ENABLE_DEBUG_TMP === 'false') {
30
- debug.disable();
31
- } else if (window.blocklet?.ENABLE_DEBUG_TMP) {
32
- debug.enable(window.blocklet?.ENABLE_DEBUG_TMP);
33
- }
@@ -1,10 +1,10 @@
1
1
  import { useState, useEffect, useCallback } from 'react';
2
2
  import dayjs from 'dayjs';
3
+ import 'dayjs/locale/zh-cn';
4
+ import 'dayjs/locale/en';
3
5
  import utc from 'dayjs/plugin/utc';
4
6
  import timezonePlugin from 'dayjs/plugin/timezone';
5
7
  import localizedFormat from 'dayjs/plugin/localizedFormat';
6
- import 'dayjs/locale/zh-cn';
7
- import 'dayjs/locale/en';
8
8
 
9
9
  import { formatToDatetime } from '../Util';
10
10
 
@@ -3,19 +3,27 @@ import { useMount, useDeepCompareEffect } from 'ahooks';
3
3
  import ReactGA from 'react-ga4';
4
4
  import { googleAnalyticsMeasurementId } from './env';
5
5
 
6
- if (googleAnalyticsMeasurementId) {
7
- ReactGA.initialize(googleAnalyticsMeasurementId);
8
- }
6
+ let isInitialized = false;
7
+
8
+ const initializeGA = () => {
9
+ if (googleAnalyticsMeasurementId && !isInitialized) {
10
+ ReactGA.initialize(googleAnalyticsMeasurementId);
11
+ isInitialized = true;
12
+ }
13
+ };
9
14
 
10
15
  export { ReactGA };
16
+
11
17
  export default <P extends object>(WrappedComponent: React.ComponentType<P>) => {
12
18
  const trackPage = (page: string, title = document.title) => {
19
+ initializeGA();
13
20
  if (googleAnalyticsMeasurementId) {
14
21
  ReactGA.send({ hitType: 'pageview', page, title });
15
22
  }
16
23
  };
17
24
 
18
25
  const trackEvent = (category: string, action: string, label: string, value: number) => {
26
+ initializeGA();
19
27
  if (googleAnalyticsMeasurementId) {
20
28
  ReactGA.event({ category, action, label, value, transport: 'beacon' });
21
29
  }