@blocklet/ui-react 3.2.14 → 3.2.16

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.
@@ -14,7 +14,7 @@ declare function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddon
14
14
  showRole: boolean;
15
15
  onLogout: () => void;
16
16
  } | undefined;
17
- links?: any[] | undefined;
17
+ links?: never[] | undefined;
18
18
  showDomainWarningDialog?: boolean | undefined;
19
19
  }): import("react/jsx-runtime").JSX.Element | null;
20
20
  declare namespace Dashboard {
@@ -22,7 +22,7 @@ declare namespace Dashboard {
22
22
  export { BlockletMetaProps as meta };
23
23
  export let fallbackUrl: PropTypes.Requireable<string>;
24
24
  export let invalidPathFallback: PropTypes.Requireable<(...args: any[]) => any>;
25
- export let headerAddons: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.ReactNodeLike>>;
25
+ export let headerAddons: PropTypes.Requireable<NonNullable<PropTypes.ReactNodeLike | ((...args: any[]) => any)>>;
26
26
  export { SessionManagerProps as sessionManagerProps };
27
27
  export let links: PropTypes.Requireable<NonNullable<any[] | ((...args: any[]) => any) | null | undefined>>;
28
28
  export let showDomainWarningDialog: PropTypes.Requireable<boolean>;
@@ -4,7 +4,7 @@ import { default as PropTypes } from 'prop-types';
4
4
  */
5
5
  declare function Links({ links, flowLayout, columns, ...rest }: {
6
6
  [x: string]: any;
7
- links?: any[] | undefined;
7
+ links?: never[] | undefined;
8
8
  flowLayout?: boolean | undefined;
9
9
  columns: any;
10
10
  }): import("react/jsx-runtime").JSX.Element | null;
@@ -11,7 +11,7 @@ export function getLocalizedNavigation({ navigation, locale, defaultLocale, sect
11
11
  }>;
12
12
  locale: string;
13
13
  defaultLocale: string;
14
- section?: "footer" | "header" | undefined;
14
+ section?: "header" | "footer" | undefined;
15
15
  }): any[];
16
16
  export function formatNavigation(navigation: any): any;
17
17
  export function parseNavigation(navigation: any): {
@@ -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<((...args: any[]) => any) | PropTypes.ReactNodeLike>>;
14
+ export let addons: PropTypes.Requireable<NonNullable<PropTypes.ReactNodeLike | ((...args: any[]) => any)>>;
15
15
  export { SessionManagerProps as sessionManagerProps };
16
16
  export let showDomainWarningDialog: PropTypes.Requireable<boolean>;
17
17
  }
@@ -1,73 +1,77 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import U from "prop-types";
3
- import { useMemo as y, useCallback as I, useEffect as $ } from "react";
4
- import { IconButton as g, Badge as B } from "@mui/material";
5
- import { useSnackbar as D } from "notistack";
6
- import P from "@arcblock/icons/lib/Notification";
7
- import { useCreation as c } from "ahooks";
8
- import { WELLKNOWN_SERVICE_PATH_PREFIX as S, EVENTS as L } from "@abtnode/constant";
9
- import V from "@arcblock/react-hooks/lib/useBrowser";
10
- import { compareVersions as x } from "@arcblock/ux/lib/Util";
11
- import { joinURL as j, withQuery as A } from "ufo";
12
- import { useListenWsClient as F } from "./ws.js";
13
- import H from "../Notifications/Snackbar.js";
14
- const E = j(S, "user", "notifications"), K = (o) => A(E, {
15
- id: o.id,
16
- severity: o.severity || "all",
17
- componentDid: o.source === "system" ? "system" : o.componentDid || "all"
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import S from "prop-types";
3
+ import { useMemo as L, useCallback as T, useEffect as $ } from "react";
4
+ import { IconButton as B, Badge as P } from "@mui/material";
5
+ import { useSnackbar as V } from "notistack";
6
+ import x from "@arcblock/icons/lib/Notification";
7
+ import { useCreation as s } from "ahooks";
8
+ import { WELLKNOWN_SERVICE_PATH_PREFIX as W, ROLES as A, EVENTS as O } from "@abtnode/constant";
9
+ import j from "@arcblock/react-hooks/lib/useBrowser";
10
+ import { compareVersions as F } from "@arcblock/ux/lib/Util";
11
+ import { joinURL as H, withQuery as R } from "ufo";
12
+ import { useListenWsClient as K } from "./ws.js";
13
+ import M from "../Notifications/Snackbar.js";
14
+ const E = H(W, "user", "notifications"), z = (r) => R(E, {
15
+ id: r.id,
16
+ severity: r.severity || "all",
17
+ componentDid: r.source === "system" ? "system" : r.componentDid || "all"
18
18
  });
19
- function W({ session: o = {} }) {
20
- const { unReadCount: l, user: n, setUnReadCount: i } = o, e = c(() => n?.did, [n]), { enqueueSnackbar: k } = D(), d = V(), u = y(() => !e || n?.isPreviewUser || e === window.blocklet.did, [e, n]), N = y(() => d.arcSphere || d.wallet, [d]), T = c(() => window.blocklet?.serverVersion, []), t = F("user"), a = c(
21
- () => `${window.blocklet.did}/${e}/${L.NOTIFICATION_BLOCKLET_CREATE}`,
19
+ function q({ session: r = {} }) {
20
+ const { unReadCount: l, user: t, setUnReadCount: i } = r, e = s(() => t?.did, [t]), h = s(() => t?.role && [A.ADMIN, A.OWNER].includes(t?.role), [t?.role]), { enqueueSnackbar: N } = V(), d = j(), u = L(() => !e || t?.isPreviewUser || e === window.blocklet.did, [e, t]), k = L(() => d.arcSphere || d.wallet, [d]), y = s(() => window.blocklet?.serverVersion, []), n = K("user"), a = s(
21
+ () => `${window.blocklet.did}/${e}/${O.NOTIFICATION_BLOCKLET_CREATE}`,
22
22
  [e]
23
- ), m = c(
24
- () => `${window.blocklet.did}/${e}/${L.NOTIFICATION_BLOCKLET_READ}`,
23
+ ), m = s(
24
+ () => `${window.blocklet.did}/${e}/${O.NOTIFICATION_BLOCKLET_READ}`,
25
25
  [e]
26
- ), f = I(
27
- (r) => {
28
- const { receivers: v } = r ?? {}, { receiver: w } = v[0] ?? {};
29
- if (w === e) {
26
+ ), p = T(
27
+ (o) => {
28
+ const { receivers: v, source: w } = o ?? {}, { receiver: C } = v[0] ?? {};
29
+ if (C === e && (h || w !== "system")) {
30
30
  i((b) => b + 1);
31
- const C = x(T, "1.16.42-beta-20250407");
32
- if (!N && r.source === "component" && C) {
33
- const b = K(r), { severity: h, description: R } = r || {}, O = ["error", "warning"].includes(h) || r.sticky;
34
- k(R, {
35
- variant: h,
36
- autoHideDuration: O ? null : 5e3,
31
+ const U = F(y, "1.16.42-beta-20250407");
32
+ if (!k && o.source === "component" && U) {
33
+ const b = z(o), { severity: I, description: _ } = o || {}, g = ["error", "warning"].includes(I) || o.sticky;
34
+ N(_, {
35
+ variant: I,
36
+ autoHideDuration: g ? null : 5e3,
37
+ anchorOrigin: {
38
+ vertical: "top",
39
+ horizontal: "center"
40
+ },
37
41
  // eslint-disable-next-line react/no-unstable-nested-components
38
- content: (_) => /* @__PURE__ */ s(H, { viewAllUrl: b, keyId: _, notification: r })
42
+ content: (D) => /* @__PURE__ */ c(M, { viewAllUrl: b, keyId: D, notification: o })
39
43
  });
40
44
  }
41
45
  }
42
46
  },
43
- [e, i, k, T, N]
44
- ), p = I(
45
- (r) => {
46
- const { receiver: v, readCount: w } = r ?? {};
47
+ [e, i, N, y, k, h]
48
+ ), f = T(
49
+ (o) => {
50
+ const { receiver: v, readCount: w } = o ?? {};
47
51
  v === e && i((C) => Math.max(C - w, 0));
48
52
  },
49
53
  [e, i]
50
54
  );
51
- return $(() => (t && !u && (t.on(a, f), t.on(m, p)), () => {
52
- t && !u && (t.off(a, f), t.off(m, p));
53
- }), [t, i, f, a, p, m, u]), !o.user || !E ? null : /* @__PURE__ */ s(
54
- g,
55
+ return $(() => (n && !u && (n.on(a, p), n.on(m, f)), () => {
56
+ n && !u && (n.off(a, p), n.off(m, f));
57
+ }), [n, i, p, a, f, m, u]), !r.user || !E ? null : /* @__PURE__ */ c(
58
+ B,
55
59
  {
56
60
  size: "medium",
57
61
  variant: "outlined",
58
- href: A(E, { read: l <= 0 }),
62
+ href: R(E, { read: l <= 0 }),
59
63
  sx: {
60
64
  "&:hover": {
61
65
  borderRadius: "50%"
62
66
  }
63
67
  },
64
- children: /* @__PURE__ */ s(B, { badgeContent: l, color: "error", invisible: l === 0, children: /* @__PURE__ */ s(P, { style: { width: "auto", height: 24 } }) })
68
+ children: /* @__PURE__ */ c(P, { badgeContent: l, color: "error", invisible: l === 0, children: /* @__PURE__ */ c(x, { style: { width: "auto", height: 24 } }) })
65
69
  }
66
70
  );
67
71
  }
68
- W.propTypes = {
69
- session: U.object
72
+ q.propTypes = {
73
+ session: S.object
70
74
  };
71
75
  export {
72
- W as default
76
+ q as default
73
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "3.2.14",
3
+ "version": "3.2.16",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -33,14 +33,13 @@
33
33
  "url": "https://github.com/ArcBlock/ux/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@abtnode/constant": "1.17.4",
37
- "@abtnode/util": "1.17.4",
38
- "@arcblock/bridge": "3.2.14",
39
- "@arcblock/icons": "3.2.14",
40
- "@arcblock/react-hooks": "3.2.14",
41
- "@arcblock/ws": "^1.27.14",
42
- "@blocklet/constant": "1.17.4",
43
- "@blocklet/did-space-react": "^1.2.9",
36
+ "@abtnode/constant": "^1.17.5",
37
+ "@abtnode/util": "^1.17.5",
38
+ "@arcblock/bridge": "3.2.16",
39
+ "@arcblock/icons": "3.2.16",
40
+ "@arcblock/react-hooks": "3.2.16",
41
+ "@arcblock/ws": "^1.27.15",
42
+ "@blocklet/did-space-react": "^1.2.10",
44
43
  "@iconify-icons/logos": "^1.2.36",
45
44
  "@iconify-icons/material-symbols": "^1.2.58",
46
45
  "@iconify-icons/tabler": "^1.2.95",
@@ -71,7 +70,7 @@
71
70
  "peerDependencies": {
72
71
  "@arcblock/did-connect-react": "^3.1.0",
73
72
  "@arcblock/ux": "^3.1.0",
74
- "@blocklet/js-sdk": "^1.16.46",
73
+ "@blocklet/js-sdk": "^1.17.4",
75
74
  "@emotion/react": "^11.14.0",
76
75
  "@emotion/styled": "^11.14.0",
77
76
  "@mui/icons-material": "^7.2.0",
@@ -83,7 +82,7 @@
83
82
  "access": "public"
84
83
  },
85
84
  "devDependencies": {
86
- "@arcblock/did-connect-react": "3.2.14",
85
+ "@arcblock/did-connect-react": "3.2.16",
87
86
  "@types/dompurify": "^3.2.0",
88
87
  "@types/ua-parser-js": "^0.7.39",
89
88
  "@types/validator": "^13.15.2",
@@ -91,5 +90,5 @@
91
90
  "jest": "^29.7.0",
92
91
  "unbuild": "^2.0.0"
93
92
  },
94
- "gitHead": "731e897399abcbad25a7551b7af74094002a3ce1"
93
+ "gitHead": "cc7ec117370b11df3e5e1b60120af8f5e2e82cb7"
95
94
  }
@@ -4,7 +4,7 @@ import { IconButton, Badge } from '@mui/material';
4
4
  import { useSnackbar } from 'notistack';
5
5
  import NotificationsOutlinedIcon from '@arcblock/icons/lib/Notification';
6
6
  import { useCreation } from 'ahooks';
7
- import { EVENTS, WELLKNOWN_SERVICE_PATH_PREFIX } from '@abtnode/constant';
7
+ import { EVENTS, WELLKNOWN_SERVICE_PATH_PREFIX, ROLES } from '@abtnode/constant';
8
8
  import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
9
9
  import { compareVersions } from '@arcblock/ux/lib/Util';
10
10
  import { joinURL, withQuery } from 'ufo';
@@ -25,6 +25,8 @@ export default function NotificationAddon({ session = {} }) {
25
25
  const { unReadCount, user, setUnReadCount } = session;
26
26
  const userDid = useCreation(() => user?.did, [user]);
27
27
 
28
+ const isAdmin = useCreation(() => user?.role && [ROLES.ADMIN, ROLES.OWNER].includes(user?.role), [user?.role]);
29
+
28
30
  const { enqueueSnackbar } = useSnackbar();
29
31
  const browser = useBrowser();
30
32
 
@@ -54,11 +56,11 @@ export default function NotificationAddon({ session = {} }) {
54
56
 
55
57
  const listenCallback = useCallback(
56
58
  (notification) => {
57
- const { receivers } = notification ?? {};
59
+ const { receivers, source } = notification ?? {};
58
60
 
59
61
  const { receiver: notificationReceiver } = receivers[0] ?? {};
60
-
61
- if (notificationReceiver === userDid) {
62
+ const shouldUpdate = isAdmin || source !== 'system';
63
+ if (notificationReceiver === userDid && shouldUpdate) {
62
64
  setUnReadCount((x) => x + 1);
63
65
  // 显示通知, 如果是系统通知则不需要显示, 如果是移动端不需要显示
64
66
  // 兼容代码,如果 server 没有升级那么不需要提示
@@ -70,13 +72,17 @@ export default function NotificationAddon({ session = {} }) {
70
72
  enqueueSnackbar(description, {
71
73
  variant: severity,
72
74
  autoHideDuration: disableAutoHide ? null : 5000,
75
+ anchorOrigin: {
76
+ vertical: 'top',
77
+ horizontal: 'center',
78
+ },
73
79
  // eslint-disable-next-line react/no-unstable-nested-components
74
80
  content: (key) => <NotificationSnackbar viewAllUrl={link} keyId={key} notification={notification} />,
75
81
  });
76
82
  }
77
83
  }
78
84
  },
79
- [userDid, setUnReadCount, enqueueSnackbar, serverVersion, hiddenNotificationToast]
85
+ [userDid, setUnReadCount, enqueueSnackbar, serverVersion, hiddenNotificationToast, isAdmin]
80
86
  );
81
87
 
82
88
  const readListenCallback = useCallback(