@blocklet/ui-react 3.0.9 → 3.0.10

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.
Files changed (51) hide show
  1. package/lib/BlockletStudio/index.js +70 -71
  2. package/lib/ComponentInstaller/index.js +85 -88
  3. package/lib/ComponentInstaller/installer-item.js +47 -53
  4. package/lib/ComponentInstaller/use-component-installed.js +32 -38
  5. package/lib/ComponentManager/components/add-component.js +47 -50
  6. package/lib/ComponentManager/components/publish-component.js +30 -31
  7. package/lib/ComponentManager/components/resource-dialog.js +28 -30
  8. package/lib/Dashboard/index.d.ts +1 -1
  9. package/lib/Dashboard/index.js +59 -61
  10. package/lib/Footer/index.js +51 -52
  11. package/lib/Footer/internal-footer.js +43 -47
  12. package/lib/Footer/layout/standard.js +11 -12
  13. package/lib/Footer/links.js +25 -28
  14. package/lib/Footer/social-media.js +17 -17
  15. package/lib/Header/index.js +81 -83
  16. package/lib/Notifications/Snackbar.js +76 -77
  17. package/lib/Notifications/hooks/use-title.js +34 -34
  18. package/lib/Notifications/utils.js +56 -60
  19. package/lib/UserCenter/components/config-inviter.js +17 -18
  20. package/lib/UserCenter/components/danger-zone.js +49 -52
  21. package/lib/UserCenter/components/nft.js +44 -45
  22. package/lib/UserCenter/components/notification.js +92 -99
  23. package/lib/UserCenter/components/passport.js +22 -22
  24. package/lib/UserCenter/components/privacy.js +6 -6
  25. package/lib/UserCenter/components/settings.js +40 -43
  26. package/lib/UserCenter/components/status-dialog/date-picker.js +7 -8
  27. package/lib/UserCenter/components/status-dialog/index.js +112 -114
  28. package/lib/UserCenter/components/status-selector/duration-menu.js +35 -36
  29. package/lib/UserCenter/components/status-selector/index.js +13 -13
  30. package/lib/UserCenter/components/storage/action.js +21 -22
  31. package/lib/UserCenter/components/storage/delete.js +24 -24
  32. package/lib/UserCenter/components/third-party-login/index.js +53 -53
  33. package/lib/UserCenter/components/third-party-login/third-party-item.js +87 -89
  34. package/lib/UserCenter/components/user-center.js +198 -207
  35. package/lib/UserCenter/components/user-info/metadata.js +343 -353
  36. package/lib/UserCenter/components/user-info/switch-role.js +17 -20
  37. package/lib/UserCenter/components/user-info/user-basic-info.js +79 -82
  38. package/lib/UserCenter/components/user-info/user-info.js +40 -40
  39. package/lib/UserCenter/components/user-info/user-status.js +97 -99
  40. package/lib/UserCenter/components/user-info/utils.js +34 -35
  41. package/lib/UserSessions/components/user-session-info.js +25 -28
  42. package/lib/UserSessions/components/user-sessions.js +169 -181
  43. package/lib/blocklets.js +62 -72
  44. package/lib/common/domain-warning.js +31 -31
  45. package/lib/common/header-addons.d.ts +1 -1
  46. package/lib/common/header-addons.js +49 -53
  47. package/lib/common/notification-addon.js +29 -32
  48. package/lib/common/ws.js +17 -18
  49. package/lib/contexts/config-user-space.js +16 -19
  50. package/lib/utils.js +44 -48
  51. package/package.json +6 -6
package/lib/blocklets.js CHANGED
@@ -1,52 +1,48 @@
1
- import { mapRecursive as a, filterRecursive as l, isUrl as d } from "./utils.js";
2
- var c, u;
3
- const w = ((c = window == null ? void 0 : window.blocklet) == null ? void 0 : c.groupPrefix) || ((u = window == null ? void 0 : window.blocklet) == null ? void 0 : u.prefix) || "/", h = (r) => {
4
- const o = { ...r }, s = r == null ? void 0 : r.background;
5
- return typeof s == "string" ? o.background = { header: s, footer: s, default: s } : s && typeof s == "object" && (o.background = {
6
- header: s.header || s.default,
7
- footer: s.footer || s.default,
8
- default: s.default
9
- }), o;
10
- }, i = (r, o = "en") => {
11
- if (typeof r == "string") {
12
- if (d(r)) {
13
- const e = new URL(r);
14
- return e.searchParams.set("locale", o), e.href;
1
+ import { mapRecursive as s, filterRecursive as a, isUrl as f } from "./utils.js";
2
+ const g = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || "/", i = (o) => {
3
+ const r = { ...o }, e = o?.background;
4
+ return typeof e == "string" ? r.background = { header: e, footer: e, default: e } : e && typeof e == "object" && (r.background = {
5
+ header: e.header || e.default,
6
+ footer: e.footer || e.default,
7
+ default: e.default
8
+ }), r;
9
+ }, c = (o, r = "en") => {
10
+ if (typeof o == "string") {
11
+ if (f(o)) {
12
+ const t = new URL(o);
13
+ return t.searchParams.set("locale", r), t.href;
15
14
  }
16
- const s = new URL(r, window.location.origin);
17
- return s.searchParams.set("locale", o), s.pathname + s.search;
15
+ const e = new URL(o, window.location.origin);
16
+ return e.searchParams.set("locale", r), e.pathname + e.search;
18
17
  }
19
- return typeof r == "object" ? r[o] || (r == null ? void 0 : r.en) || (r == null ? void 0 : r.zh) : r;
20
- }, L = (r, o = "en") => {
21
- if (!(r != null && r.length))
22
- return r;
23
- const s = (e, t) => e && typeof e == "object" ? e[t] || (e == null ? void 0 : e.en) || (e == null ? void 0 : e.zh) : e;
24
- return a(
25
- r,
26
- (e) => {
27
- var t;
28
- return {
29
- ...e,
30
- title: s(e.title, o),
31
- description: s(e.description, o),
32
- // 仅对叶结点进行处理
33
- link: (t = e.items) != null && t.length ? e.link : i(e.link, o),
34
- _rawLink: e.link
35
- };
36
- },
18
+ return typeof o == "object" ? o[r] || o?.en || o?.zh : o;
19
+ }, p = (o, r = "en") => {
20
+ if (!o?.length)
21
+ return o;
22
+ const e = (t, n) => t && typeof t == "object" ? t[n] || t?.en || t?.zh : t;
23
+ return s(
24
+ o,
25
+ (t) => ({
26
+ ...t,
27
+ title: e(t.title, r),
28
+ description: e(t.description, r),
29
+ // 仅对叶结点进行处理
30
+ link: t.items?.length ? t.link : c(t.link, r),
31
+ _rawLink: t.link
32
+ }),
37
33
  "items"
38
34
  );
39
- }, p = (r) => a(
40
- r,
41
- (o) => o.role ? {
42
- ...o,
43
- role: Array.isArray(o.role) ? o.role : [o.role]
44
- } : o,
35
+ }, u = (o) => s(
36
+ o,
37
+ (r) => r.role ? {
38
+ ...r,
39
+ role: Array.isArray(r.role) ? r.role : [r.role]
40
+ } : r,
45
41
  "items"
46
- ), g = (r) => {
47
- if (!(r != null && r.length))
42
+ ), l = (o) => {
43
+ if (!o?.length)
48
44
  return null;
49
- const o = p(r), s = {
45
+ const r = u(o), e = {
50
46
  header: [],
51
47
  footer: [],
52
48
  // 对应 footer social media
@@ -59,38 +55,32 @@ const w = ((c = window == null ? void 0 : window.blocklet) == null ? void 0 : c.
59
55
  sessionManager: [],
60
56
  userCenter: []
61
57
  };
62
- return o.forEach((e) => {
63
- var t;
64
- e.section ? Array.isArray(e.section) ? e.section.forEach((n) => {
65
- var f;
66
- (f = s[n]) == null || f.push(e);
67
- }) : typeof e.section == "string" && ((t = s[e.section]) == null || t.push(e)) : s.header.push(e);
68
- }), s;
69
- }, N = (r) => {
70
- if (!r)
58
+ return r.forEach((t) => {
59
+ t.section ? Array.isArray(t.section) ? t.section.forEach((n) => {
60
+ e[n]?.push(t);
61
+ }) : typeof t.section == "string" && e[t.section]?.push(t) : e.header.push(t);
62
+ }), e;
63
+ }, b = (o) => {
64
+ if (!o)
71
65
  return null;
72
- const o = { ...r };
73
- return o.theme = h(o.theme), o.navigation = g(b(o.navigation)), o;
74
- }, b = (r = []) => l(r, (o, s) => {
75
- var e;
76
- return !!o.link || ((e = s.filteredChildren) == null ? void 0 : e.length);
77
- }, "items"), R = (r, o) => l(
78
- r,
79
- (s, e) => {
80
- var n;
81
- const t = !s.role || o && (s.role.includes(o) || s.role.includes("guest"));
82
- return e.isLeaf ? t : t && ((n = e.filteredChildren) == null ? void 0 : n.length);
66
+ const r = { ...o };
67
+ return r.theme = i(r.theme), r.navigation = l(d(r.navigation)), r;
68
+ }, d = (o = []) => a(o, (r, e) => !!r.link || e.filteredChildren?.length, "items"), y = (o, r) => a(
69
+ o,
70
+ (e, t) => {
71
+ const n = !e.role || r && (e.role.includes(r) || e.role.includes("guest"));
72
+ return t.isLeaf ? n : n && t.filteredChildren?.length;
83
73
  },
84
74
  "items"
85
75
  );
86
76
  export {
87
- R as filterNavByRole,
88
- b as filterValidNavItems,
89
- N as formatBlockletInfo,
90
- p as formatNavigation,
91
- h as formatTheme,
92
- i as getLink,
93
- L as getLocalizedNavigation,
94
- g as parseNavigation,
95
- w as publicPath
77
+ y as filterNavByRole,
78
+ d as filterValidNavItems,
79
+ b as formatBlockletInfo,
80
+ u as formatNavigation,
81
+ i as formatTheme,
82
+ c as getLink,
83
+ p as getLocalizedNavigation,
84
+ l as parseNavigation,
85
+ g as publicPath
96
86
  };
@@ -1,12 +1,12 @@
1
- import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
- import { useState as S, useMemo as p, useCallback as u } from "react";
3
- import f from "prop-types";
4
- import { Dialog as T, DialogContent as A, Typography as m, Box as C, DialogActions as W, Button as w } from "@mui/material";
1
+ import { jsxs as a, jsx as i } from "react/jsx-runtime";
2
+ import { useState as S, useMemo as d, useCallback as u } from "react";
3
+ import p from "prop-types";
4
+ import { Dialog as T, DialogContent as A, Typography as c, Box as C, DialogActions as W, Button as f } from "@mui/material";
5
5
  import { useMemoizedFn as v } from "ahooks";
6
6
  import { translate as M } from "@arcblock/ux/lib/Locale/util";
7
7
  import { joinURL as O } from "ufo";
8
8
  import j from "../hooks/use-mobile.js";
9
- const z = ["admin", "owner"], I = (i) => i.endsWith(".ip.abtnet.io"), E = (i) => i.endsWith(".did.abtnet.io"), H = {
9
+ const z = ["admin", "owner"], I = (t) => t.endsWith(".ip.abtnet.io"), E = (t) => t.endsWith(".did.abtnet.io"), H = {
10
10
  en: {
11
11
  guest: {
12
12
  title: "Notice: You are using a temporary domain",
@@ -41,21 +41,21 @@ const z = ["admin", "owner"], I = (i) => i.endsWith(".ip.abtnet.io"), E = (i) =>
41
41
  skip: "稍后提醒",
42
42
  bindDomain: "配置域名"
43
43
  }
44
- }, N = 1e3 * 60 * 60 * 24 * 30, h = ".well-known/service/admin/domains";
45
- function P({ locale: i = "en", session: s = {} }) {
46
- const o = s == null ? void 0 : s.user, b = j(), [g, a] = S(() => {
44
+ }, N = 1e3 * 60 * 60 * 24 * 30, w = ".well-known/service/admin/domains";
45
+ function P({ locale: t = "en", session: h = {} }) {
46
+ const l = h?.user, b = j(), [g, s] = S(() => {
47
47
  const e = window.localStorage.getItem("domain-warning-skip");
48
48
  if (!e) return !0;
49
- const c = +/* @__PURE__ */ new Date(), y = +new Date(e);
50
- return c - y > N;
51
- }), n = v((e, c = {}) => M(H, e, i, "en", c)), d = p(() => {
49
+ const r = +/* @__PURE__ */ new Date(), y = +new Date(e);
50
+ return r - y > N;
51
+ }), n = v((e, r = {}) => M(H, e, t, "en", r)), m = d(() => {
52
52
  try {
53
53
  const { hostname: e } = new URL(window.location.href);
54
54
  return e;
55
55
  } catch {
56
56
  return "";
57
57
  }
58
- }, []), x = p(
58
+ }, []), x = d(
59
59
  () => [
60
60
  n("owner.benefits1"),
61
61
  n("owner.benefits2"),
@@ -65,36 +65,36 @@ function P({ locale: i = "en", session: s = {} }) {
65
65
  ],
66
66
  [n]
67
67
  ), D = u(() => {
68
- window.localStorage.setItem("domain-warning-skip", (/* @__PURE__ */ new Date()).toISOString()), a(!1);
68
+ window.localStorage.setItem("domain-warning-skip", (/* @__PURE__ */ new Date()).toISOString()), s(!1);
69
69
  }, []), k = u(() => {
70
- const e = O(window.location.origin, h);
71
- e.startsWith("http") && window.open(e, "_blank"), a(!1);
72
- }, []), r = (o == null ? void 0 : o.role) && z.includes(o.role);
73
- return window.location.href.includes(h) || b || !I(d) && !E(d) ? null : /* @__PURE__ */ l(T, { open: g, disableEscapeKeyDown: !0, fullWidth: !0, maxWidth: "sm", onClose: () => a(!1), children: [
74
- /* @__PURE__ */ l(A, { sx: { padding: "20px !important" }, children: [
75
- /* @__PURE__ */ t(
76
- m,
70
+ const e = O(window.location.origin, w);
71
+ e.startsWith("http") && window.open(e, "_blank"), s(!1);
72
+ }, []), o = l?.role && z.includes(l.role);
73
+ return window.location.href.includes(w) || b || !I(m) && !E(m) ? null : /* @__PURE__ */ a(T, { open: g, disableEscapeKeyDown: !0, fullWidth: !0, maxWidth: "sm", onClose: () => s(!1), children: [
74
+ /* @__PURE__ */ a(A, { sx: { padding: "20px !important" }, children: [
75
+ /* @__PURE__ */ i(
76
+ c,
77
77
  {
78
78
  sx: {
79
79
  fontSize: "20px",
80
80
  fontWeight: "500"
81
81
  },
82
- children: n(r ? "owner.title" : "guest.title")
82
+ children: n(o ? "owner.title" : "guest.title")
83
83
  }
84
84
  ),
85
- /* @__PURE__ */ t(
86
- m,
85
+ /* @__PURE__ */ i(
86
+ c,
87
87
  {
88
88
  sx: {
89
89
  marginTop: "20px",
90
90
  fontSize: "14px",
91
91
  color: "#9397A1"
92
92
  },
93
- children: n(r ? "owner.description" : "guest.description")
93
+ children: n(o ? "owner.description" : "guest.description")
94
94
  }
95
95
  ),
96
- r && /* @__PURE__ */ t(C, { component: "ul", children: x.map((e) => /* @__PURE__ */ t(
97
- m,
96
+ o && /* @__PURE__ */ i(C, { component: "ul", children: x.map((e) => /* @__PURE__ */ i(
97
+ c,
98
98
  {
99
99
  component: "li",
100
100
  sx: {
@@ -106,15 +106,15 @@ function P({ locale: i = "en", session: s = {} }) {
106
106
  e
107
107
  )) })
108
108
  ] }),
109
- /* @__PURE__ */ l(W, { sx: { px: "12px !important" }, children: [
110
- /* @__PURE__ */ t(w, { onClick: D, children: n("skip") }),
111
- r && /* @__PURE__ */ t(w, { variant: "contained", onClick: k, children: n("bindDomain") })
109
+ /* @__PURE__ */ a(W, { sx: { px: "12px !important" }, children: [
110
+ /* @__PURE__ */ i(f, { onClick: D, children: n("skip") }),
111
+ o && /* @__PURE__ */ i(f, { variant: "contained", onClick: k, children: n("bindDomain") })
112
112
  ] })
113
113
  ] });
114
114
  }
115
115
  P.propTypes = {
116
- locale: f.string,
117
- session: f.object
116
+ locale: p.string,
117
+ session: p.object
118
118
  };
119
119
  export {
120
120
  P as default
@@ -11,7 +11,7 @@ declare function HeaderAddons({ formattedBlocklet, addons, showDomainWarningDial
11
11
  declare namespace HeaderAddons {
12
12
  namespace propTypes {
13
13
  export let formattedBlocklet: PropTypes.Validator<object>;
14
- export let addons: PropTypes.Requireable<NonNullable<PropTypes.ReactNodeLike | ((...args: any[]) => any)>>;
14
+ export let addons: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.ReactNodeLike>>;
15
15
  export { SessionManagerProps as sessionManagerProps };
16
16
  export let showDomainWarningDialog: PropTypes.Requireable<boolean>;
17
17
  }
@@ -1,75 +1,71 @@
1
- import { jsx as i, Fragment as N } from "react/jsx-runtime";
1
+ import { jsx as s, Fragment as v } from "react/jsx-runtime";
2
2
  import "iconify-icon";
3
- import { use as T, createElement as R } from "react";
4
- import a from "prop-types";
5
- import { SessionContext as S } from "@arcblock/did-connect/lib/Session";
6
- import M from "@arcblock/ux/lib/SessionUser";
7
- import D from "@arcblock/ux/lib/SessionBlocklet";
8
- import P from "@arcblock/ux/lib/Locale/selector";
9
- import { useLocaleContext as j } from "@arcblock/ux/lib/Locale/context";
10
- import k from "@arcblock/ux/lib/Config/theme-mode-toggle";
11
- import { SessionManagerProps as z } from "../types.js";
12
- import { getLocalizedNavigation as E, filterNavByRole as W } from "../blocklets.js";
13
- import q from "./notification-addon.js";
14
- import F from "./domain-warning.js";
15
- const H = () => {
16
- var e;
17
- return !!(((e = window == null ? void 0 : window.blocklet) == null ? void 0 : e.navigation) ?? []).find((c) => c.id === "/userCenter/notification");
18
- };
19
- function O({
20
- formattedBlocklet: s,
21
- addons: e = null,
22
- showDomainWarningDialog: c = !0,
23
- sessionManagerProps: d = { showRole: !0 }
3
+ import { use as b, createElement as k } from "react";
4
+ import r from "prop-types";
5
+ import { SessionContext as w } from "@arcblock/did-connect/lib/Session";
6
+ import L from "@arcblock/ux/lib/SessionUser";
7
+ import N from "@arcblock/ux/lib/SessionBlocklet";
8
+ import T from "@arcblock/ux/lib/Locale/selector";
9
+ import { useLocaleContext as C } from "@arcblock/ux/lib/Locale/context";
10
+ import R from "@arcblock/ux/lib/Config/theme-mode-toggle";
11
+ import { SessionManagerProps as S } from "../types.js";
12
+ import { getLocalizedNavigation as M, filterNavByRole as B } from "../blocklets.js";
13
+ import D from "./notification-addon.js";
14
+ import P from "./domain-warning.js";
15
+ const j = () => !!(window?.blocklet?.navigation ?? []).find((o) => o.id === "/userCenter/notification");
16
+ function x({
17
+ formattedBlocklet: l,
18
+ addons: o = null,
19
+ showDomainWarningDialog: m = !0,
20
+ sessionManagerProps: u = { showRole: !0 }
24
21
  }) {
25
- var m, u, p, g;
26
- const o = T(S), { locale: r, languages: y } = j() || {}, { enableConnect: A = !0, enableLocale: v = !0 } = s, b = !!((m = o == null ? void 0 : o.session) != null && m.user);
27
- let l = E((u = s == null ? void 0 : s.navigation) == null ? void 0 : u.sessionManager, r) || [];
28
- l = W(l, (g = (p = o == null ? void 0 : o.session) == null ? void 0 : p.user) == null ? void 0 : g.role);
29
- const f = (() => {
30
- if (e && typeof e != "function")
31
- return Array.isArray(e) ? e : [e];
32
- let n = [];
33
- if (H() && n.push(/* @__PURE__ */ i(q, { session: o.session }, "notification-addon")), v && r && y.length > 1 && n.push(/* @__PURE__ */ i(P, { showText: !1 }, "locale-selector")), n.push(/* @__PURE__ */ i(k, {}, "theme-mode-toggle")), A && o) {
34
- const h = [];
35
- b && (l ? l.slice(0, 5) : []).forEach((t) => {
36
- h.push({
22
+ const n = b(w), { locale: i, languages: p } = C() || {}, { enableConnect: g = !0, enableLocale: d = !0 } = l, h = !!n?.session?.user;
23
+ let a = M(l?.navigation?.sessionManager, i) || [];
24
+ a = B(a, n?.session?.user?.role);
25
+ const c = (() => {
26
+ if (o && typeof o != "function")
27
+ return Array.isArray(o) ? o : [o];
28
+ let e = [];
29
+ if (j() && e.push(/* @__PURE__ */ s(D, { session: n.session }, "notification-addon")), d && i && p.length > 1 && e.push(/* @__PURE__ */ s(T, { showText: !1 }, "locale-selector")), e.push(/* @__PURE__ */ s(R, {}, "theme-mode-toggle")), g && n) {
30
+ const f = [];
31
+ h && (a ? a.slice(0, 5) : []).forEach((t) => {
32
+ f.push({
37
33
  label: t.title,
38
- icon: t.icon ? /* @__PURE__ */ i("iconify-icon", { icon: t.icon, height: 24, style: { marginRight: 8 } }) : null,
34
+ icon: t.icon ? /* @__PURE__ */ s("iconify-icon", { icon: t.icon, height: 24, style: { marginRight: 8 } }) : null,
39
35
  component: "a",
40
36
  href: t.link,
41
37
  key: t.link
42
38
  });
43
- }), n.push(/* @__PURE__ */ i(D, { session: o.session, locale: r }, "session-blocklet")), n.push(
44
- /* @__PURE__ */ i(
45
- M,
39
+ }), e.push(/* @__PURE__ */ s(N, { session: n.session, locale: i }, "session-blocklet")), e.push(
40
+ /* @__PURE__ */ s(
41
+ L,
46
42
  {
47
- session: o.session,
48
- locale: r,
49
- menu: h,
43
+ session: n.session,
44
+ locale: i,
45
+ menu: f,
50
46
  showRole: !0,
51
- ...d
47
+ ...u
52
48
  },
53
49
  "session-user"
54
50
  )
55
51
  );
56
52
  }
57
- return typeof e == "function" && (n = e(n) || []), n;
58
- })(), w = Array.isArray(f) ? f : [f], L = [
59
- c ? /* @__PURE__ */ i(F, { session: o == null ? void 0 : o.session, locale: r }) : null,
60
- ...w
53
+ return typeof o == "function" && (e = o(e) || []), e;
54
+ })(), y = Array.isArray(c) ? c : [c], A = [
55
+ m ? /* @__PURE__ */ s(P, { session: n?.session, locale: i }) : null,
56
+ ...y
61
57
  ].filter(Boolean);
62
- return R(N, null, ...L);
58
+ return k(v, null, ...A);
63
59
  }
64
- O.propTypes = {
65
- formattedBlocklet: a.object.isRequired,
60
+ x.propTypes = {
61
+ formattedBlocklet: r.object.isRequired,
66
62
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
67
63
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
68
64
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
69
- addons: a.oneOfType([a.func, a.node]),
70
- sessionManagerProps: z,
71
- showDomainWarningDialog: a.bool
65
+ addons: r.oneOfType([r.func, r.node]),
66
+ sessionManagerProps: S,
67
+ showDomainWarningDialog: r.bool
72
68
  };
73
69
  export {
74
- O as default
70
+ x as default
75
71
  };
@@ -1,70 +1,67 @@
1
- import { jsx as s } from "react/jsx-runtime";
1
+ import { jsx as i } from "react/jsx-runtime";
2
2
  import R from "prop-types";
3
3
  import { useMemo as O, useCallback as h, useEffect as _ } from "react";
4
4
  import { IconButton as $, Badge as g } from "@mui/material";
5
5
  import { useSnackbar as B } from "notistack";
6
6
  import D from "@arcblock/icons/lib/Notification";
7
- import { useCreation as c } from "ahooks";
7
+ import { useCreation as s } from "ahooks";
8
8
  import { WELLKNOWN_SERVICE_PATH_PREFIX as S, EVENTS as y } from "@abtnode/constant";
9
9
  import V from "@arcblock/react-hooks/lib/useBrowser";
10
10
  import { joinURL as x, withQuery as U } from "ufo";
11
11
  import { useListenWsClient as j } from "./ws.js";
12
12
  import F from "../Notifications/Snackbar.js";
13
13
  import { compareVersions as H } from "../utils.js";
14
- const b = x(S, "user", "notifications"), K = (r) => U(b, {
14
+ const v = x(S, "user", "notifications"), K = (r) => U(v, {
15
15
  id: r.id,
16
16
  severity: r.severity || "all",
17
17
  componentDid: r.source === "system" ? "system" : r.componentDid || "all"
18
18
  });
19
19
  function P({ session: r = {} }) {
20
- const { unReadCount: w, user: i, setUnReadCount: n } = r, o = c(() => i == null ? void 0 : i.did, [i]), { enqueueSnackbar: E } = B(), l = V(), k = O(() => l.arcSphere || l.wallet, [l]), N = c(() => {
21
- var e;
22
- return (e = window.blocklet) == null ? void 0 : e.serverVersion;
23
- }, []), t = j("user"), d = c(
24
- () => `${window.blocklet.did}/${o}/${y.NOTIFICATION_BLOCKLET_CREATE}`,
25
- [o]
26
- ), a = c(
27
- () => `${window.blocklet.did}/${o}/${y.NOTIFICATION_BLOCKLET_READ}`,
28
- [o]
29
- ), u = h(
30
- (e) => {
31
- const { receivers: f } = e ?? {}, { receiver: p } = f[0] ?? {};
32
- if (p === o) {
33
- n((v) => v + 1);
34
- const C = H(N, "1.16.42-beta-20250407");
35
- if (!k && e.source === "component" && C) {
36
- const v = K(e), { severity: T, description: I } = e || {}, L = ["error", "warning"].includes(T) || e.sticky;
20
+ const { unReadCount: b, user: w, setUnReadCount: n } = r, e = s(() => w?.did, [w]), { enqueueSnackbar: E } = B(), c = V(), k = O(() => c.arcSphere || c.wallet, [c]), N = s(() => window.blocklet?.serverVersion, []), t = j("user"), l = s(
21
+ () => `${window.blocklet.did}/${e}/${y.NOTIFICATION_BLOCKLET_CREATE}`,
22
+ [e]
23
+ ), u = s(
24
+ () => `${window.blocklet.did}/${e}/${y.NOTIFICATION_BLOCKLET_READ}`,
25
+ [e]
26
+ ), d = h(
27
+ (o) => {
28
+ const { receivers: m } = o ?? {}, { receiver: f } = m[0] ?? {};
29
+ if (f === e) {
30
+ n((C) => C + 1);
31
+ const p = H(N, "1.16.42-beta-20250407");
32
+ if (!k && o.source === "component" && p) {
33
+ const C = K(o), { severity: T, description: I } = o || {}, L = ["error", "warning"].includes(T) || o.sticky;
37
34
  E(I, {
38
35
  variant: T,
39
36
  autoHideDuration: L ? null : 5e3,
40
37
  // eslint-disable-next-line react/no-unstable-nested-components
41
- content: (A) => /* @__PURE__ */ s(F, { viewAllUrl: v, keyId: A, notification: e })
38
+ content: (A) => /* @__PURE__ */ i(F, { viewAllUrl: C, keyId: A, notification: o })
42
39
  });
43
40
  }
44
41
  }
45
42
  },
46
- [o, n, E, N, k]
47
- ), m = h(
48
- (e) => {
49
- const { receiver: f, readCount: p } = e ?? {};
50
- f === o && n((C) => Math.max(C - p, 0));
43
+ [e, n, E, N, k]
44
+ ), a = h(
45
+ (o) => {
46
+ const { receiver: m, readCount: f } = o ?? {};
47
+ m === e && n((p) => Math.max(p - f, 0));
51
48
  },
52
- [o, n]
49
+ [e, n]
53
50
  );
54
- return _(() => (t && (t.on(d, u), t.on(a, m)), () => {
55
- t && (t.off(d, u), t.off(a, m));
56
- }), [t, n, u, d, m, a]), !r.user || !b ? null : /* @__PURE__ */ s(
51
+ return _(() => (t && (t.on(l, d), t.on(u, a)), () => {
52
+ t && (t.off(l, d), t.off(u, a));
53
+ }), [t, n, d, l, a, u]), !r.user || !v ? null : /* @__PURE__ */ i(
57
54
  $,
58
55
  {
59
56
  size: "medium",
60
57
  variant: "outlined",
61
- href: b,
58
+ href: v,
62
59
  sx: {
63
60
  "&:hover": {
64
61
  borderRadius: "50%"
65
62
  }
66
63
  },
67
- children: /* @__PURE__ */ s(g, { badgeContent: w, color: "error", invisible: w === 0, children: /* @__PURE__ */ s(D, { style: { width: "auto", height: 24 } }) })
64
+ children: /* @__PURE__ */ i(g, { badgeContent: b, color: "error", invisible: b === 0, children: /* @__PURE__ */ i(D, { style: { width: "auto", height: 24 } }) })
68
65
  }
69
66
  );
70
67
  }
package/lib/common/ws.js CHANGED
@@ -1,27 +1,26 @@
1
- import { use as o } from "react";
2
- import { WsClient as n } from "@arcblock/ws";
3
- import { SessionContext as f } from "@arcblock/did-connect/lib/Session";
4
- import { joinURL as m } from "ufo";
5
- import { BLOCKLET_SERVICE_PATH_PREFIX as a } from "@arcblock/ux/lib/Util/constant";
1
+ import { use as s } from "react";
2
+ import { WsClient as o } from "@arcblock/ws";
3
+ import { SessionContext as n } from "@arcblock/did-connect/lib/Session";
4
+ import { joinURL as f } from "ufo";
5
+ import { BLOCKLET_SERVICE_PATH_PREFIX as m } from "@arcblock/ux/lib/Util/constant";
6
6
  const e = {};
7
- function c(t = "admin") {
8
- var s;
7
+ function a(t = "admin") {
9
8
  let r = "/";
10
- !(window != null && window.blocklet) && ((s = window == null ? void 0 : window.env) != null && s.apiPrefix) && (r = window.env.apiPrefix);
11
- const i = m(r, a, t);
12
- return new n(i, {
9
+ !window?.blocklet && window?.env?.apiPrefix && (r = window.env.apiPrefix);
10
+ const i = f(r, m, t);
11
+ return new o(i, {
13
12
  heartbeatIntervalMs: 100 * 1e3
14
13
  });
15
14
  }
16
- function l(t = "admin") {
17
- return e[t] || (e[t] = c(t)), e[t];
15
+ function c(t = "admin") {
16
+ return e[t] || (e[t] = a(t)), e[t];
18
17
  }
19
- const E = (t = "admin") => {
20
- const r = o(f), { session: i } = r ?? {};
21
- return !e[t] && i.user && (e[t] = l(t), e[t].connect()), e[t];
18
+ const P = (t = "admin") => {
19
+ const r = s(n), { session: i } = r ?? {};
20
+ return !e[t] && i.user && (e[t] = c(t), e[t].connect()), e[t];
22
21
  };
23
22
  export {
24
- c as create,
25
- l as default,
26
- E as useListenWsClient
23
+ a as create,
24
+ c as default,
25
+ P as useListenWsClient
27
26
  };
@@ -1,32 +1,29 @@
1
- import { jsx as g } from "react/jsx-runtime";
2
- import { createContext as C, useState as p, use as r, useMemo as m, useEffect as u } from "react";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { createContext as g, useState as i, use as p, useMemo as C, useEffect as m } from "react";
3
3
  import { SessionContext as y } from "@arcblock/did-connect/lib/Session";
4
- const d = C({}), { Provider: w, Consumer: U } = d;
4
+ const d = g({}), { Provider: w, Consumer: U } = d;
5
5
  function h({ children: n }) {
6
- const [S] = p(!1), { session: a } = r(y), { user: e } = a, [s, o] = p(), c = m(() => {
7
- var t;
8
- return (t = e == null ? void 0 : e.didSpace) == null ? void 0 : t.endpoint;
9
- }, [e == null ? void 0 : e.didSpace]);
10
- u(() => {
11
- o(e == null ? void 0 : e.didSpace);
12
- }, [e == null ? void 0 : e.didSpace]);
13
- const f = async () => {
14
- o(void 0);
15
- }, i = (t) => {
6
+ const [S] = i(!1), { session: a } = p(y), { user: e } = a, [s, t] = i(), c = C(() => e?.didSpace?.endpoint, [e?.didSpace]);
7
+ m(() => {
8
+ t(e?.didSpace);
9
+ }, [e?.didSpace]);
10
+ const u = async () => {
11
+ t(void 0);
12
+ }, r = (o) => {
16
13
  };
17
- return /* @__PURE__ */ g(
14
+ return /* @__PURE__ */ f(
18
15
  w,
19
16
  {
20
17
  value: {
21
18
  loading: S,
22
19
  spaceGateway: s,
23
20
  session: a,
24
- deleteSpaceGateway: f,
25
- updateSpaceGateway: async (t) => {
26
- o(t), await i(t.endpoint);
21
+ deleteSpaceGateway: u,
22
+ updateSpaceGateway: async (o) => {
23
+ t(o), await r(o.endpoint);
27
24
  },
28
25
  storageEndpoint: c,
29
- settingStorageEndpoint: i,
26
+ settingStorageEndpoint: r,
30
27
  hasStorageEndpoint: !!(c && s)
31
28
  },
32
29
  children: n
@@ -34,7 +31,7 @@ function h({ children: n }) {
34
31
  );
35
32
  }
36
33
  function P() {
37
- return r(d);
34
+ return p(d);
38
35
  }
39
36
  export {
40
37
  U as ConfigUserSpaceConsumer,