@blocklet/ui-react 3.4.6 → 3.4.8

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,6 +1,6 @@
1
1
  import { jsx as e, jsxs as f } from "react/jsx-runtime";
2
2
  import { useState as I, useMemo as C } from "react";
3
- import { styled as k, Box as p, Typography as y, IconButton as D, Button as U, useTheme as S, FormControl as B, TextField as F } from "@mui/material";
3
+ import { Box as p, Typography as y, IconButton as k, Button as D, useTheme as U, styled as S, FormControl as B, TextField as F } from "@mui/material";
4
4
  import { Remove as T, Add as _ } from "@mui/icons-material";
5
5
  import { translate as z } from "@arcblock/ux/lib/Locale/util";
6
6
  import { useMemoizedFn as E } from "ahooks";
@@ -83,14 +83,14 @@ function q({ links: t = [], onChange: s }) {
83
83
  },
84
84
  children: [
85
85
  /* @__PURE__ */ e($, { value: o, onChange: (c) => b(n, c), errorMsg: a }),
86
- /* @__PURE__ */ e(D, { onClick: () => L(n), children: /* @__PURE__ */ e(T, { sx: { color: "text.secondary" } }) })
86
+ /* @__PURE__ */ e(k, { onClick: () => L(n), children: /* @__PURE__ */ e(T, { sx: { color: "text.secondary" } }) })
87
87
  ]
88
88
  },
89
89
  n
90
90
  );
91
91
  }),
92
92
  t.length < g ? /* @__PURE__ */ f(
93
- U,
93
+ D,
94
94
  {
95
95
  fullWidth: !0,
96
96
  variant: "outlined",
@@ -122,7 +122,7 @@ function q({ links: t = [], onChange: s }) {
122
122
  );
123
123
  }
124
124
  function G({ link: t }) {
125
- const l = S().palette.mode === "dark";
125
+ const l = U().palette.mode === "dark";
126
126
  if (!t)
127
127
  return null;
128
128
  const { icon: r, options: i } = W(t) || {};
@@ -174,7 +174,7 @@ function ut({
174
174
  }
175
175
  );
176
176
  }
177
- const H = k("span")`
177
+ const H = S("span")`
178
178
  flex: 1;
179
179
  white-space: nowrap;
180
180
  overflow: hidden;
@@ -1,7 +1,7 @@
1
1
  import { jsxs as y, Fragment as B, jsx as t } from "react/jsx-runtime";
2
- import { memo as te, createElement as re, useState as R, useRef as ie, useEffect as ae, useMemo as D } from "react";
2
+ import { useState as R, useRef as te, useEffect as re, useMemo as D, memo as ie, createElement as ae } from "react";
3
3
  import { Icon as le } from "@iconify/react";
4
- import { Backdrop as de, Box as m, useMediaQuery as ce, SwipeableDrawer as pe, Typography as L, Tooltip as se } from "@mui/material";
4
+ import { useMediaQuery as de, SwipeableDrawer as ce, Box as m, Typography as L, Tooltip as se, Backdrop as pe } from "@mui/material";
5
5
  import me from "@emotion/styled";
6
6
  import N from "@arcblock/ux/lib/Button";
7
7
  import F, { detectCountryFromPhone as T, getCountryNameByCountry as ue, validatePhoneNumber as he, getDialCodeByCountry as fe } from "@arcblock/ux/lib/PhoneInput";
@@ -29,12 +29,12 @@ import Se from "./address.js";
29
29
  const E = {
30
30
  width: 20,
31
31
  height: 20
32
- }, H = 200, Q = te(function({
32
+ }, H = 200, Q = ie(function({
33
33
  ref: r,
34
34
  ...I
35
35
  }) {
36
- return /* @__PURE__ */ re(
37
- de,
36
+ return /* @__PURE__ */ ae(
37
+ pe,
38
38
  {
39
39
  ref: r,
40
40
  component: "div",
@@ -50,12 +50,12 @@ const E = {
50
50
  });
51
51
  Q.displayName = "BackdropWrap";
52
52
  function mo({
53
- isMyself: p,
53
+ isMyself: s,
54
54
  user: r,
55
55
  onSave: I,
56
56
  isMobile: x
57
57
  }) {
58
- const [U, P] = R(!1), [Y, C] = R(!1), _ = ie(null), q = we(), b = ce("(max-width:640px)") || q.mobile.any, c = w({
58
+ const [U, P] = R(!1), [Y, C] = R(!1), _ = te(null), q = we(), b = de("(max-width:640px)") || q.mobile.any, c = w({
59
59
  email: "",
60
60
  phone: ""
61
61
  }), u = w({
@@ -66,7 +66,7 @@ function mo({
66
66
  line2: "",
67
67
  postalCode: ""
68
68
  });
69
- ae(() => {
69
+ re(() => {
70
70
  b || C(!1);
71
71
  }, [b]);
72
72
  const j = k(() => r?.phoneVerified ?? !1, [r?.phoneVerified]), A = k(() => r?.emailVerified ?? !1, [r?.emailVerified]), { locale: z } = ve(), d = be((o, n = {}) => ge(Ve, o, z, "en", n)), a = w(
@@ -108,10 +108,10 @@ function mo({
108
108
  country: h,
109
109
  phone: ""
110
110
  };
111
- }, [a.phone, r?.phone, h]), s = (o, n) => {
111
+ }, [a.phone, r?.phone, h]), p = (o, n) => {
112
112
  a[n] = o;
113
113
  }, K = (o, n) => {
114
- l[o] = n, o === "city" && s(n, "location"), o === "postalCode" ? u.postalCode = n && !$(n, "any") ? d("profile.address.invalidPostalCode") : "" : u[o] = "";
114
+ l[o] = n, o === "city" && p(n, "location"), o === "postalCode" ? u.postalCode = n && !$(n, "any") ? d("profile.address.invalidPostalCode") : "" : u[o] = "";
115
115
  }, S = () => {
116
116
  b ? C(!0) : P(!0);
117
117
  }, O = () => {
@@ -147,7 +147,7 @@ function mo({
147
147
  favicon: e
148
148
  };
149
149
  });
150
- s(n, "links");
150
+ p(n, "links");
151
151
  }, ee = () => {
152
152
  if (Object.keys(a).forEach((n) => {
153
153
  const e = n, i = a[e];
@@ -176,7 +176,7 @@ function mo({
176
176
  g,
177
177
  {
178
178
  value: a.bio ?? "",
179
- onChange: (e) => s(e, "bio"),
179
+ onChange: (e) => p(e, "bio"),
180
180
  editable: o,
181
181
  placeholder: "Bio",
182
182
  component: "textarea",
@@ -189,7 +189,7 @@ function mo({
189
189
  }
190
190
  }
191
191
  ),
192
- !o && p ? /* @__PURE__ */ t(
192
+ !o && s ? /* @__PURE__ */ t(
193
193
  N,
194
194
  {
195
195
  size: x ? "small" : "large",
@@ -205,7 +205,7 @@ function mo({
205
205
  children: d("profile.editProfile")
206
206
  }
207
207
  ) : null,
208
- o && p && J ? /* @__PURE__ */ t(
208
+ o && s && J ? /* @__PURE__ */ t(
209
209
  Se,
210
210
  {
211
211
  address: l,
@@ -217,11 +217,11 @@ function mo({
217
217
  g,
218
218
  {
219
219
  value: a.location ?? r?.address?.city ?? "",
220
- onChange: (e) => s(e, "location"),
220
+ onChange: (e) => p(e, "location"),
221
221
  editable: o,
222
222
  placeholder: "Location",
223
223
  label: d("profile.location"),
224
- tooltip: p && (l.line1 || l.line2) ? /* @__PURE__ */ t(B, { children: ["line1", "line2"].map((e) => l[e] ? /* @__PURE__ */ y(m, { children: [
224
+ tooltip: s && (l.line1 || l.line2) ? /* @__PURE__ */ t(B, { children: ["line1", "line2"].map((e) => l[e] ? /* @__PURE__ */ y(m, { children: [
225
225
  /* @__PURE__ */ t(
226
226
  L,
227
227
  {
@@ -247,7 +247,7 @@ function mo({
247
247
  g,
248
248
  {
249
249
  value: a.timezone || "",
250
- onChange: (e) => s(e, "timezone"),
250
+ onChange: (e) => p(e, "timezone"),
251
251
  editable: o,
252
252
  placeholder: "timezone",
253
253
  icon: /* @__PURE__ */ t(Pe, { ...E }),
@@ -257,7 +257,7 @@ function mo({
257
257
  Ae,
258
258
  {
259
259
  value: a.timezone ?? "",
260
- onChange: (e) => s(e, "timezone"),
260
+ onChange: (e) => p(e, "timezone"),
261
261
  disabled: !o,
262
262
  mode: n
263
263
  }
@@ -269,7 +269,7 @@ function mo({
269
269
  {
270
270
  value: a.email ?? r?.email ?? "",
271
271
  editable: o,
272
- hidePreview: !p,
272
+ hidePreview: !s,
273
273
  disabled: r?.sourceProvider === M.EMAIL,
274
274
  canEdit: !A,
275
275
  verified: A,
@@ -289,9 +289,9 @@ function mo({
289
289
  }
290
290
  ) }) : null
291
291
  ] }),
292
- onChange: (e) => s(e, "email"),
292
+ onChange: (e) => p(e, "email"),
293
293
  errorMsg: c.email,
294
- renderValue: (e) => p ? /* @__PURE__ */ t(
294
+ renderValue: (e) => s ? /* @__PURE__ */ t(
295
295
  "a",
296
296
  {
297
297
  href: `mailto:${e}`,
@@ -313,29 +313,31 @@ function mo({
313
313
  {
314
314
  value: V.phone,
315
315
  editable: o,
316
- hidePreview: !p,
316
+ hidePreview: !s,
317
317
  canEdit: !j,
318
318
  verified: j,
319
319
  placeholder: "Phone",
320
320
  icon: /* @__PURE__ */ t(Ie, { ...E }),
321
- onChange: (e) => s(e, "phone"),
321
+ onChange: (e) => p(e, "phone"),
322
322
  label: d("profile.phone"),
323
- renderValue: () => p ? /* @__PURE__ */ t(F, { value: V, preview: !0 }) : null,
323
+ renderValue: () => s ? /* @__PURE__ */ t(F, { value: V, preview: !0 }) : null,
324
324
  children: /* @__PURE__ */ t(
325
325
  F,
326
326
  {
327
327
  variant: "outlined",
328
328
  className: "editable-field",
329
- InputProps: {
330
- sx: { backgroundColor: "transparent" },
331
- placeholder: "Phone"
329
+ slotProps: {
330
+ input: {
331
+ sx: { backgroundColor: "transparent" },
332
+ placeholder: "Phone"
333
+ }
332
334
  },
333
335
  value: V,
334
336
  error: !!c.phone,
335
337
  helperText: c.phone,
336
338
  sx: xe(Be, c.phone ? {} : Le),
337
339
  onChange: (e) => {
338
- he(e.phone, e.country) ? c.phone = "" : c.phone = d("profile.phoneInvalid"), s(
340
+ he(e.phone, e.country) ? c.phone = "" : c.phone = d("profile.phoneInvalid"), p(
339
341
  {
340
342
  country: e.country,
341
343
  phoneNumber: e.phone
@@ -348,7 +350,7 @@ function mo({
348
350
  }
349
351
  ),
350
352
  /* @__PURE__ */ t(Ne, { editable: o, links: X, onChange: Z }),
351
- o && p ? /* @__PURE__ */ y(
353
+ o && s ? /* @__PURE__ */ y(
352
354
  m,
353
355
  {
354
356
  style: { width: "100%" },
@@ -397,7 +399,7 @@ function mo({
397
399
  return /* @__PURE__ */ y(B, { children: [
398
400
  W(U),
399
401
  b && /* @__PURE__ */ y(
400
- pe,
402
+ ce,
401
403
  {
402
404
  sx: {
403
405
  zIndex: 9999
@@ -6,19 +6,19 @@ import { useMemoizedFn as V } from "ahooks";
6
6
  import { translate as Y } from "@arcblock/ux/lib/Locale/util";
7
7
  import { useLocaleContext as $ } from "@arcblock/ux/lib/Locale/context";
8
8
  import q from "lodash/noop";
9
- import { useState as C, useEffect as j } from "react";
9
+ import { lazy as G, useState as C, useEffect as j } from "react";
10
10
  import I from "@arcblock/ux/lib/Toast";
11
- import { parseURL as G, joinURL as H } from "ufo";
12
- import { KeyboardArrowUp as J, KeyboardArrowDown as X } from "@mui/icons-material";
13
- import { getBlockletSDK as Z } from "@blocklet/js-sdk";
14
- import { translations as _ } from "../../libs/locales.js";
11
+ import { parseURL as H, joinURL as J } from "ufo";
12
+ import { KeyboardArrowUp as X, KeyboardArrowDown as Z } from "@mui/icons-material";
13
+ import { getBlockletSDK as _ } from "@blocklet/js-sdk";
14
+ import { translations as P } from "../../libs/locales.js";
15
15
  import { formatAxiosError as R } from "../../libs/utils.js";
16
- import { currentTimezone as P, getStatusDuration as M, isValidUrl as tt, isDuplicateUrl as rt } from "./utils.js";
17
- import et from "./switch-role.js";
18
- import ot from "./metadata.js";
16
+ import { currentTimezone as M, getStatusDuration as tt, isValidUrl as rt, isDuplicateUrl as et } from "./utils.js";
17
+ import ot from "./switch-role.js";
19
18
  import at from "./user-status.js";
20
19
  import nt from "./user-info.js";
21
20
  import it from "./social-actions/index.js";
21
+ const lt = G(() => import("./metadata.js"));
22
22
  function kt({
23
23
  user: t,
24
24
  isMyself: o = !0,
@@ -31,7 +31,7 @@ function kt({
31
31
  isShowSocialActions: D = !1,
32
32
  ...m
33
33
  }) {
34
- const h = Z(), { locale: x } = $(), [g, v] = C(void 0), w = V((i, e = {}) => Y(_, i, x, "en", e)), [d, S] = C(!a || c);
34
+ const h = _(), { locale: x } = $(), [g, v] = C(void 0), w = V((i, e = {}) => Y(P, i, x, "en", e)), [d, S] = C(!a || c);
35
35
  j(() => {
36
36
  v(t?.metadata?.status);
37
37
  }, [t]), j(() => {
@@ -41,7 +41,7 @@ function kt({
41
41
  if (o)
42
42
  try {
43
43
  if (i) {
44
- const e = M(i);
44
+ const e = tt(i);
45
45
  i.dateRange = e.length > 0 ? e : g?.dateRange ?? [];
46
46
  }
47
47
  v(i), await h.user.saveProfile({
@@ -62,10 +62,10 @@ function kt({
62
62
  const { metadata: e, address: E } = i;
63
63
  try {
64
64
  const p = e?.links?.map((n, U) => {
65
- if (!n.url || !tt(n.url) || U > 0 && e.links?.slice(0, U)?.some((K) => rt(K.url, n.url)))
65
+ if (!n.url || !rt(n.url) || U > 0 && e.links?.slice(0, U)?.some((K) => et(K.url, n.url)))
66
66
  return null;
67
67
  try {
68
- return G(n.url).protocol || (n.url = H("https://", n.url)), n;
68
+ return H(n.url).protocol || (n.url = J("https://", n.url)), n;
69
69
  } catch {
70
70
  return console.error("Invalid URL:", n.url), null;
71
71
  }
@@ -146,7 +146,7 @@ function kt({
146
146
  isMobile: a,
147
147
  size: m.size || (a ? 64 : 100),
148
148
  isMyself: o,
149
- timezone: t?.metadata?.timezone || P,
149
+ timezone: t?.metadata?.timezone || M,
150
150
  status: g,
151
151
  onChange: L
152
152
  }
@@ -188,7 +188,7 @@ function kt({
188
188
  children: t?.fullName
189
189
  }
190
190
  ),
191
- o ? /* @__PURE__ */ r(et, { user: t, switchPassport: k }) : null
191
+ o ? /* @__PURE__ */ r(ot, { user: t, switchPassport: k }) : null
192
192
  ]
193
193
  }
194
194
  ),
@@ -211,7 +211,7 @@ function kt({
211
211
  }
212
212
  ),
213
213
  !o && D ? /* @__PURE__ */ r(s, { sx: { mt: 2 }, children: /* @__PURE__ */ r(it, { user: t }) }) : null,
214
- /* @__PURE__ */ r(ot, { isMobile: a, isMyself: o, user: t, onSave: B }),
214
+ /* @__PURE__ */ r(lt, { isMobile: a, isMyself: o, user: t, onSave: B }),
215
215
  o ? /* @__PURE__ */ l(N, { children: [
216
216
  /* @__PURE__ */ r(T, { sx: { my: a ? 1 : 3 } }),
217
217
  a && !c ? /* @__PURE__ */ r(
@@ -234,7 +234,7 @@ function kt({
234
234
  opacity: 0.8
235
235
  }
236
236
  },
237
- children: d ? /* @__PURE__ */ r(J, {}) : /* @__PURE__ */ r(X, {})
237
+ children: d ? /* @__PURE__ */ r(X, {}) : /* @__PURE__ */ r(Z, {})
238
238
  }
239
239
  )
240
240
  }
@@ -1,59 +1,51 @@
1
- import { jsx as i, Fragment as b } from "react/jsx-runtime";
1
+ import { jsx as s, Fragment as b } from "react/jsx-runtime";
2
2
  import "iconify-icon";
3
- import a from "prop-types";
4
- import { use as L, createElement as v } from "react";
5
- import { SessionContext as N } from "@arcblock/did-connect-react/lib/Session";
6
- import T from "@arcblock/ux/lib/Config/theme-mode-toggle";
7
- import { useLocaleContext as k } from "@arcblock/ux/lib/Locale/context";
3
+ import r from "prop-types";
4
+ import { use as L, createElement as k } from "react";
5
+ import { SessionContext as w } from "@arcblock/did-connect-react/lib/Session";
6
+ import N from "@arcblock/ux/lib/Config/theme-mode-toggle";
7
+ import { useLocaleContext as T } from "@arcblock/ux/lib/Locale/context";
8
8
  import C from "@arcblock/ux/lib/Locale/selector";
9
- import S from "@arcblock/ux/lib/SessionBlocklet";
10
- import D from "@arcblock/ux/lib/SessionUser";
11
- import { WELLKNOWN_BLOCKLET_ADMIN_PATH as E } from "@abtnode/constant";
12
- import { getLocalizedNavigation as M, filterNavByRole as O } from "../blocklets.js";
13
- import { SessionManagerProps as R } from "../types.js";
14
- import W from "./domain-warning.js";
15
- import P from "./notification-addon.js";
16
- import B from "./org-switch/index.js";
17
- const _ = () => !!(window?.blocklet?.navigation ?? []).find((o) => o.id === "/userCenter/notification"), j = (n) => {
18
- const { settings: o = {} } = n ?? window?.blocklet ?? {};
19
- return o?.org?.enabled || !1;
20
- }, x = () => {
21
- const { pathname: n = "" } = window.location || {};
22
- return n.startsWith(E);
23
- };
9
+ import R from "@arcblock/ux/lib/SessionBlocklet";
10
+ import S from "@arcblock/ux/lib/SessionUser";
11
+ import { getLocalizedNavigation as M, filterNavByRole as B } from "../blocklets.js";
12
+ import { SessionManagerProps as D } from "../types.js";
13
+ import P from "./domain-warning.js";
14
+ import j from "./notification-addon.js";
15
+ const x = () => !!(window?.blocklet?.navigation ?? []).find((o) => o.id === "/userCenter/notification");
24
16
  function z({
25
- formattedBlocklet: n,
17
+ formattedBlocklet: l,
26
18
  addons: o = null,
27
19
  showDomainWarningDialog: m = !0,
28
20
  sessionManagerProps: u = { showRole: !0 }
29
21
  }) {
30
- const e = L(N), { locale: t, languages: p, defaultLocale: g } = k() || {}, { enableConnect: d = !0, enableLocale: h = !0 } = n, y = !!e?.session?.user;
31
- let l = M({
32
- navigation: n?.navigation?.sessionManager,
33
- locale: t,
22
+ const n = L(w), { locale: i, languages: p, defaultLocale: g } = T() || {}, { enableConnect: d = !0, enableLocale: h = !0 } = l, y = !!n?.session?.user;
23
+ let a = M({
24
+ navigation: l?.navigation?.sessionManager,
25
+ locale: i,
34
26
  defaultLocale: g
35
27
  }) || [];
36
- l = O(l, e?.session?.user?.role);
28
+ a = B(a, n?.session?.user?.role);
37
29
  const c = (() => {
38
30
  if (o && typeof o != "function")
39
31
  return Array.isArray(o) ? o : [o];
40
- let s = [];
41
- if (_() && s.push(/* @__PURE__ */ i(P, { session: e.session }, "notification-addon")), h && t && p.length > 1 && s.push(/* @__PURE__ */ i(C, { showText: !1 }, "locale-selector")), s.push(/* @__PURE__ */ i(T, {}, "theme-mode-toggle")), d && e) {
32
+ let e = [];
33
+ if (x() && e.push(/* @__PURE__ */ s(j, { session: n.session }, "notification-addon")), h && i && p.length > 1 && e.push(/* @__PURE__ */ s(C, { showText: !1 }, "locale-selector")), e.push(/* @__PURE__ */ s(N, {}, "theme-mode-toggle")), d && n) {
42
34
  const f = [];
43
- y && (l ? l.slice(0, 5) : []).forEach((r) => {
35
+ y && (a ? a.slice(0, 5) : []).forEach((t) => {
44
36
  f.push({
45
- label: r.title,
46
- icon: r.icon ? /* @__PURE__ */ i("iconify-icon", { icon: r.icon, height: 24, style: { marginRight: 8 } }) : null,
37
+ label: t.title,
38
+ icon: t.icon ? /* @__PURE__ */ s("iconify-icon", { icon: t.icon, height: 24, style: { marginRight: 8 } }) : null,
47
39
  component: "a",
48
- href: r.link,
49
- key: r.link
40
+ href: t.link,
41
+ key: t.link
50
42
  });
51
- }), s.push(/* @__PURE__ */ i(S, { session: e.session, locale: t }, "session-blocklet")), s.push(
52
- /* @__PURE__ */ i(
53
- D,
43
+ }), e.push(/* @__PURE__ */ s(R, { session: n.session, locale: i }, "session-blocklet")), e.push(
44
+ /* @__PURE__ */ s(
45
+ S,
54
46
  {
55
- session: e.session,
56
- locale: t,
47
+ session: n.session,
48
+ locale: i,
57
49
  menu: f,
58
50
  showRole: !0,
59
51
  ...u
@@ -62,21 +54,21 @@ function z({
62
54
  )
63
55
  );
64
56
  }
65
- return !x() && j(n) && e?.session?.user && s.unshift(/* @__PURE__ */ i(B, { session: e.session, locale: t }, "orgs-switch")), typeof o == "function" && (s = o(s) || []), s;
66
- })(), w = Array.isArray(c) ? c : [c], A = [
67
- m ? /* @__PURE__ */ i(W, { session: e?.session, locale: t }) : null,
68
- ...w
57
+ return typeof o == "function" && (e = o(e) || []), e;
58
+ })(), v = Array.isArray(c) ? c : [c], A = [
59
+ m ? /* @__PURE__ */ s(P, { session: n?.session, locale: i }) : null,
60
+ ...v
69
61
  ].filter(Boolean);
70
- return v(b, null, ...A);
62
+ return k(b, null, ...A);
71
63
  }
72
64
  z.propTypes = {
73
- formattedBlocklet: a.object.isRequired,
65
+ formattedBlocklet: r.object.isRequired,
74
66
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
75
67
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
76
68
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
77
- addons: a.oneOfType([a.func, a.node]),
78
- sessionManagerProps: R,
79
- showDomainWarningDialog: a.bool
69
+ addons: r.oneOfType([r.func, r.node]),
70
+ sessionManagerProps: D,
71
+ showDomainWarningDialog: r.bool
80
72
  };
81
73
  export {
82
74
  z as default
@@ -0,0 +1,30 @@
1
+ import { default as PropTypes } from 'prop-types';
2
+ declare function AvatarUploader({ org, size, teamDid: teamDidProp, prefix, locale, headers, onChange, onError, editable, }: {
3
+ org?: null | undefined;
4
+ size?: number | undefined;
5
+ teamDid?: string | undefined;
6
+ prefix?: string | undefined;
7
+ locale?: string | undefined;
8
+ headers?: ((...args: any[]) => void) | undefined;
9
+ onChange?: ((...args: any[]) => void) | undefined;
10
+ onError?: ((...args: any[]) => void) | undefined;
11
+ editable?: boolean | undefined;
12
+ }): import("react/jsx-runtime").JSX.Element;
13
+ declare namespace AvatarUploader {
14
+ namespace propTypes {
15
+ let org: PropTypes.Requireable<PropTypes.InferProps<{
16
+ id: PropTypes.Requireable<string>;
17
+ name: PropTypes.Requireable<string>;
18
+ avatar: PropTypes.Requireable<string>;
19
+ }>>;
20
+ let size: PropTypes.Requireable<number>;
21
+ let teamDid: PropTypes.Requireable<string>;
22
+ let prefix: PropTypes.Requireable<string>;
23
+ let headers: PropTypes.Requireable<(...args: any[]) => any>;
24
+ let onChange: PropTypes.Requireable<(...args: any[]) => any>;
25
+ let onError: PropTypes.Requireable<(...args: any[]) => any>;
26
+ let editable: PropTypes.Requireable<boolean>;
27
+ let locale: PropTypes.Requireable<string>;
28
+ }
29
+ }
30
+ export default AvatarUploader;
@@ -0,0 +1,170 @@
1
+ import { jsxs as E, jsx as n, Fragment as k } from "react/jsx-runtime";
2
+ import { lazy as M, useRef as D, useState as I, useMemo as g, Suspense as T } from "react";
3
+ import v from "lodash/noop";
4
+ import e from "prop-types";
5
+ import { Box as b, CircularProgress as X } from "@mui/material";
6
+ import { styled as Z } from "@arcblock/ux/lib/Theme";
7
+ import { joinURL as y } from "ufo";
8
+ import { useMemoizedFn as l } from "ahooks";
9
+ import $ from "@mui/icons-material/CameraAlt";
10
+ import { translate as K } from "@arcblock/ux/lib/Locale/util";
11
+ import q from "@arcblock/ux/lib/Img";
12
+ import B from "./locales.js";
13
+ const H = M(() => import("@blocklet/uploader").then((t) => ({ default: t.Uploader }))), P = "/blocklet", V = [".png", ".jpg", ".jpeg", ".webp", ".bmp", ".ico"], G = 5 * 1024 * 1024, A = 256, S = 3;
14
+ function J(t, o, a) {
15
+ return y(t, P, o, "orgs", "avatar", a);
16
+ }
17
+ function Q(t, o) {
18
+ return y(t, P, o, "orgs", "avatar", "upload");
19
+ }
20
+ function Y({
21
+ org: t = null,
22
+ size: o = 80,
23
+ teamDid: a = "",
24
+ prefix: i = "/.well-known/service",
25
+ locale: U = "en",
26
+ headers: R = v,
27
+ onChange: O = v,
28
+ onError: x = v,
29
+ editable: p = !0
30
+ }) {
31
+ const C = l((r, h = {}) => K(B, r, U, "en", h)), u = D(null), [d, c] = I(!1), [m, F] = I(""), s = g(() => a || (typeof window < "u" ? window.blocklet?.did : ""), [a]), f = g(() => s ? Q(i, s) : null, [i, s]), _ = p && !!f, z = l(() => {
32
+ _ && !d && u.current?.open();
33
+ }), L = l((r) => {
34
+ u.current?.close(), c(!1);
35
+ const { avatarPath: h } = r.data;
36
+ F(r.uploadURL), O(h);
37
+ }), N = l(() => {
38
+ c(!0);
39
+ }), W = l((r) => {
40
+ c(!1), console.error("Avatar upload failed:", r), x(r);
41
+ }), w = g(() => {
42
+ if (m)
43
+ return m;
44
+ const r = t?.avatar;
45
+ return r ? t?.id ? J(i, s, r) : r.startsWith("http://") || r.startsWith("https://") || r.startsWith("/") ? r : y(i, r) : null;
46
+ }, [m, t?.avatar, t?.id, i, s]), j = t?.name || "";
47
+ return /* @__PURE__ */ E(tt, { $size: o, $editable: p, $uploading: d, onClick: z, children: [
48
+ f && /* @__PURE__ */ n(T, { fallback: null, children: /* @__PURE__ */ n(
49
+ H,
50
+ {
51
+ ref: u,
52
+ locale: U,
53
+ popup: !0,
54
+ onUploadFinish: L,
55
+ onUploadStart: N,
56
+ onError: W,
57
+ plugins: ["ImageEditor"],
58
+ installerProps: { disabled: !0 },
59
+ apiPathProps: {
60
+ uploader: f,
61
+ disableMediaKitPrefix: !0,
62
+ disableMediaKitStatus: !0
63
+ },
64
+ coreProps: {
65
+ restrictions: {
66
+ allowedFileExts: V,
67
+ maxFileSize: G,
68
+ maxNumberOfFiles: 1
69
+ }
70
+ },
71
+ dashboardProps: {
72
+ autoOpen: "imageEditor"
73
+ },
74
+ imageEditorProps: {
75
+ actions: {
76
+ revert: !0,
77
+ rotate: !0,
78
+ granularRotate: !0,
79
+ flip: !0,
80
+ zoomIn: !0,
81
+ zoomOut: !0,
82
+ cropSquare: !1,
83
+ cropWidescreen: !1,
84
+ cropWidescreenVertical: !1
85
+ },
86
+ cropperOptions: {
87
+ autoCrop: !0,
88
+ autoCropArea: 1,
89
+ aspectRatio: 1,
90
+ initialAspectRatio: 1,
91
+ croppedCanvasOptions: {
92
+ minWidth: A,
93
+ minHeight: A
94
+ }
95
+ }
96
+ },
97
+ tusProps: {
98
+ headers: R
99
+ }
100
+ }
101
+ ) }),
102
+ /* @__PURE__ */ n(
103
+ q,
104
+ {
105
+ src: w || "",
106
+ alt: j,
107
+ width: o,
108
+ height: o,
109
+ ratio: 1,
110
+ size: "cover",
111
+ position: "center",
112
+ lazy: !1,
113
+ style: {
114
+ borderRadius: "50%",
115
+ overflow: "hidden"
116
+ }
117
+ },
118
+ w || "no-avatar"
119
+ ),
120
+ p && /* @__PURE__ */ n(b, { className: "upload-overlay", children: d ? /* @__PURE__ */ n(X, { size: o / S, sx: { color: "white" } }) : /* @__PURE__ */ E(k, { children: [
121
+ /* @__PURE__ */ n($, { sx: { fontSize: o / S, color: "white" } }),
122
+ /* @__PURE__ */ n(b, { component: "span", sx: { fontSize: 12, color: "white" }, children: C("upload") })
123
+ ] }) })
124
+ ] });
125
+ }
126
+ Y.propTypes = {
127
+ org: e.shape({
128
+ id: e.string,
129
+ name: e.string,
130
+ avatar: e.string
131
+ }),
132
+ size: e.number,
133
+ teamDid: e.string,
134
+ prefix: e.string,
135
+ headers: e.func,
136
+ onChange: e.func,
137
+ onError: e.func,
138
+ editable: e.bool,
139
+ locale: e.string
140
+ };
141
+ const tt = Z(b, {
142
+ shouldForwardProp: (t) => !["$size", "$editable", "$uploading"].includes(t)
143
+ })(({ $size: t, $editable: o, $uploading: a }) => ({
144
+ position: "relative",
145
+ width: t,
146
+ height: t,
147
+ borderRadius: "50%",
148
+ overflow: "hidden",
149
+ cursor: o && !a ? "pointer" : "default",
150
+ ".upload-overlay": {
151
+ position: "absolute",
152
+ top: 0,
153
+ left: 0,
154
+ right: 0,
155
+ bottom: 0,
156
+ display: "flex",
157
+ flexDirection: "column",
158
+ alignItems: "center",
159
+ justifyContent: "center",
160
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
161
+ opacity: a ? 1 : 0,
162
+ transition: "opacity 0.2s ease-in-out"
163
+ },
164
+ "&:hover .upload-overlay": {
165
+ opacity: o ? 1 : 0
166
+ }
167
+ }));
168
+ export {
169
+ Y as default
170
+ };