@arcblock/ux 3.1.48 → 3.1.49

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.
@@ -15,6 +15,7 @@ export declare function useConfig(): {
15
15
  changeMode: (mode: import('@mui/material').PaletteMode) => void;
16
16
  prefer?: import('../Theme').Prefer;
17
17
  locale: import('../type').Locale;
18
+ defaultLocale: import('../type').Locale;
18
19
  changeLocale: (locale: import('../type').Locale) => void;
19
20
  t: (key: string, data?: Record<string, any>) => string;
20
21
  languages: {
@@ -1,6 +1,7 @@
1
1
  import { UserPublicInfo } from '@blocklet/js-sdk';
2
2
  declare function SwitchRole({ user, switchPassport, }: {
3
3
  user: UserPublicInfo & {
4
+ role: string;
4
5
  passports: {
5
6
  name: string;
6
7
  title: string;
@@ -19,6 +19,7 @@ export interface LocaleProviderProps {
19
19
  }
20
20
  export interface LocaleContextType {
21
21
  locale: Locale;
22
+ defaultLocale: Locale;
22
23
  changeLocale: (locale: Locale) => void;
23
24
  t: (key: string, data?: Record<string, any>) => string;
24
25
  languages: {
@@ -1,80 +1,80 @@
1
- import { jsx as y } from "react/jsx-runtime";
2
- import { createContext as x, use as k, useState as h, useRef as A, useEffect as R, useCallback as b } from "react";
3
- import j from "lodash/get";
4
- import i from "js-cookie";
5
- import S from "./browser-lang.js";
6
- import { translate as U } from "./util.js";
7
- import { getCookieOptions as D, resolveRootDomain as E } from "../Util/index.js";
8
- const l = "nf_lang", F = (e, o = window.location.href) => {
1
+ import { jsx as x } from "react/jsx-runtime";
2
+ import { createContext as k, use as A, useState as h, useRef as R, useEffect as b, useCallback as j } from "react";
3
+ import S from "lodash/get";
4
+ import l from "js-cookie";
5
+ import U from "./browser-lang.js";
6
+ import { translate as D } from "./util.js";
7
+ import { getCookieOptions as E, resolveRootDomain as F } from "../Util/index.js";
8
+ const i = "nf_lang", O = (e, o = window.location.href) => {
9
9
  const t = new URL(o).searchParams.get("locale");
10
10
  return e.find((c) => c.code === t) ? t : null;
11
- }, O = (e, o = window.location.href) => {
11
+ }, z = (e, o = window.location.href) => {
12
12
  const t = new URL(o);
13
13
  t.searchParams.has("locale") && (t.searchParams.set("locale", e), window.history.replaceState({}, "", t.href));
14
- }, d = (e = []) => {
14
+ }, g = (e = []) => {
15
15
  const o = {
16
16
  languages: e.map((t) => t.code),
17
17
  // 取 languages 首个元素的 code 值, 如果不存在则取 'en'
18
18
  fallback: e?.[0]?.code || "en"
19
19
  };
20
- return F(e) || i.get(l) || S(o);
21
- }, z = (e) => {
22
- const o = D();
20
+ return O(e) || l.get(i) || U(o);
21
+ }, N = (e) => {
22
+ const o = E();
23
23
  if (!o.domain) {
24
- const t = E();
25
- t && i.remove(l, { path: o.path || "/", domain: t });
24
+ const t = F();
25
+ t && l.remove(i, { path: o.path || "/", domain: t });
26
26
  }
27
- i.set(l, e, o), O(e);
28
- }, N = (e) => {
29
- const o = j(window, "blocklet.languages");
27
+ l.set(i, e, o), z(e);
28
+ }, _ = (e) => {
29
+ const o = S(window, "blocklet.languages");
30
30
  return Array.isArray(o) && o.length ? o : Array.isArray(e) && e.length ? e : [
31
31
  { code: "en", name: "English" },
32
32
  { code: "zh", name: "简体中文" }
33
33
  ];
34
- }, g = x(null), { Provider: _, Consumer: M } = g;
35
- function Q({
34
+ }, p = k(null), { Provider: q, Consumer: Q } = p;
35
+ function T({
36
36
  children: e,
37
37
  locale: o = void 0,
38
- fallbackLocale: t = void 0,
38
+ fallbackLocale: t = "en",
39
39
  translations: c,
40
- onLoadingTranslation: p = void 0,
41
- languages: L = [],
42
- ...P
40
+ onLoadingTranslation: L = void 0,
41
+ languages: P = [],
42
+ ...C
43
43
  }) {
44
- const s = N(L);
45
- let [n, v] = h(o || d(s));
46
- const m = A(t || ""), [, C] = h(0), u = (r) => {
47
- v(r), z(r);
44
+ const s = _(P);
45
+ let [n, v] = h(o || g(s));
46
+ const m = s?.[0]?.code ?? t, u = R(m), [, w] = h(0), f = (r) => {
47
+ v(r), N(r);
48
48
  };
49
- if (R(() => {
50
- const r = o || d(s);
51
- r !== n && u(r);
49
+ if (b(() => {
50
+ const r = o || g(s);
51
+ r !== n && f(r);
52
52
  }, [o]), n && c[n] && typeof c[n] == "function") {
53
53
  const r = n;
54
54
  try {
55
55
  Promise.resolve(c[r]()).then((a) => {
56
- a && typeof a == "object" && (c[r] = a, C((f) => f > 999 ? 0 : f + 1));
56
+ a && typeof a == "object" && (c[r] = a, w((d) => d > 999 ? 0 : d + 1));
57
57
  });
58
58
  } catch (a) {
59
59
  console.error(a);
60
60
  }
61
- p?.(r, s), n = m.current;
61
+ L?.(r, s), n = u.current;
62
62
  } else
63
- m.current = n;
64
- const w = b(
65
- (r, a) => U(c, r, n, t, a),
63
+ u.current = n;
64
+ const y = j(
65
+ (r, a) => D(c, r, n, t, a),
66
66
  [c, n, t]
67
67
  );
68
- return /* @__PURE__ */ y(_, { value: { locale: n, changeLocale: u, t: w, languages: s, ...P }, children: e });
68
+ return /* @__PURE__ */ x(q, { value: { locale: n, changeLocale: f, t: y, languages: s, defaultLocale: m, ...C }, children: e });
69
69
  }
70
- function T() {
71
- return k(g);
70
+ function V() {
71
+ return A(p);
72
72
  }
73
73
  export {
74
- M as LocaleConsumer,
75
- g as LocaleContext,
76
- Q as LocaleProvider,
77
- d as getLocale,
78
- z as setLocale,
79
- T as useLocaleContext
74
+ Q as LocaleConsumer,
75
+ p as LocaleContext,
76
+ T as LocaleProvider,
77
+ g as getLocale,
78
+ N as setLocale,
79
+ V as useLocaleContext
80
80
  };
@@ -1,4 +1,4 @@
1
- const e = "3.1.48", s = { "@blocklet/js-sdk": "1.16.52" }, n = {
1
+ const e = "3.1.49", s = { "@blocklet/js-sdk": "1.16.52" }, n = {
2
2
  version: e,
3
3
  dependencies: s
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "3.1.48",
3
+ "version": "3.1.49",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -68,16 +68,16 @@
68
68
  "react": "^19.0.0",
69
69
  "react-router-dom": "^6.22.3"
70
70
  },
71
- "gitHead": "49a6dabae8a06667e517c6811f5f7939ff907ce1",
71
+ "gitHead": "4612b57a1452bd4330755b53d093505a6ae7dea5",
72
72
  "dependencies": {
73
- "@arcblock/bridge": "3.1.48",
73
+ "@arcblock/bridge": "3.1.49",
74
74
  "@arcblock/did": "^1.25.6",
75
75
  "@arcblock/did-motif": "^1.1.14",
76
- "@arcblock/icons": "3.1.48",
77
- "@arcblock/nft-display": "3.1.48",
78
- "@arcblock/react-hooks": "3.1.48",
76
+ "@arcblock/icons": "3.1.49",
77
+ "@arcblock/nft-display": "3.1.49",
78
+ "@arcblock/react-hooks": "3.1.49",
79
79
  "@blocklet/js-sdk": "1.16.52",
80
- "@blocklet/theme": "3.1.48",
80
+ "@blocklet/theme": "3.1.49",
81
81
  "@fontsource/roboto": "~5.1.1",
82
82
  "@fontsource/ubuntu-mono": "^5.2.6",
83
83
  "@iconify-icons/logos": "^1.2.36",
@@ -9,7 +9,7 @@ function SwitchRole({
9
9
  user,
10
10
  switchPassport,
11
11
  }: {
12
- user: UserPublicInfo & { passports: { name: string; title: string; role: string }[] };
12
+ user: UserPublicInfo & { role: string; passports: { name: string; title: string; role: string }[] };
13
13
  switchPassport: () => void;
14
14
  }) {
15
15
  const currentRole = useCreation(
@@ -83,6 +83,7 @@ export interface LocaleProviderProps {
83
83
 
84
84
  export interface LocaleContextType {
85
85
  locale: Locale;
86
+ defaultLocale: Locale;
86
87
  changeLocale: (locale: Locale) => void;
87
88
  t: (key: string, data?: Record<string, any>) => string;
88
89
  languages: { code: string; name: string }[];
@@ -95,7 +96,7 @@ const { Provider, Consumer } = LocaleContext;
95
96
  function LocaleProvider({
96
97
  children,
97
98
  locale = undefined,
98
- fallbackLocale = undefined,
99
+ fallbackLocale = 'en',
99
100
  translations,
100
101
  onLoadingTranslation = undefined,
101
102
  languages = [],
@@ -104,7 +105,8 @@ function LocaleProvider({
104
105
  const langs = getLanguages(languages);
105
106
  // eslint-disable-next-line prefer-const
106
107
  let [currentLocale, setCurrentLocale] = useState<Locale>(locale || getLocale(langs));
107
- const lastCurrentLocale = useRef<string>(fallbackLocale || '');
108
+ const defaultLocale = langs?.[0]?.code ?? fallbackLocale;
109
+ const lastCurrentLocale = useRef<string>(defaultLocale);
108
110
  const [, setForceUpdate] = useState(0);
109
111
 
110
112
  const changeLocale = (newLocale: Locale) => {
@@ -145,7 +147,11 @@ function LocaleProvider({
145
147
  [translations, currentLocale, fallbackLocale]
146
148
  );
147
149
 
148
- return <Provider value={{ locale: currentLocale, changeLocale, t, languages: langs, ...rest }}>{children}</Provider>;
150
+ return (
151
+ <Provider value={{ locale: currentLocale, changeLocale, t, languages: langs, defaultLocale, ...rest }}>
152
+ {children}
153
+ </Provider>
154
+ );
149
155
  }
150
156
 
151
157
  function useLocaleContext() {