@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.
- package/lib/Config/config-provider.d.ts +1 -0
- package/lib/DIDConnect/auth-apps/switch-role.d.ts +1 -0
- package/lib/Locale/context.d.ts +1 -0
- package/lib/Locale/context.js +45 -45
- package/lib/package.json.js +1 -1
- package/package.json +7 -7
- package/src/DIDConnect/auth-apps/switch-role.tsx +1 -1
- package/src/Locale/context.tsx +9 -3
@@ -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: {
|
package/lib/Locale/context.d.ts
CHANGED
package/lib/Locale/context.js
CHANGED
@@ -1,80 +1,80 @@
|
|
1
|
-
import { jsx as
|
2
|
-
import { createContext as
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import { translate as
|
7
|
-
import { getCookieOptions as
|
8
|
-
const
|
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
|
-
},
|
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
|
-
},
|
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
|
21
|
-
},
|
22
|
-
const o =
|
20
|
+
return O(e) || l.get(i) || U(o);
|
21
|
+
}, N = (e) => {
|
22
|
+
const o = E();
|
23
23
|
if (!o.domain) {
|
24
|
-
const t =
|
25
|
-
t &&
|
24
|
+
const t = F();
|
25
|
+
t && l.remove(i, { path: o.path || "/", domain: t });
|
26
26
|
}
|
27
|
-
|
28
|
-
},
|
29
|
-
const o =
|
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
|
-
},
|
35
|
-
function
|
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 =
|
38
|
+
fallbackLocale: t = "en",
|
39
39
|
translations: c,
|
40
|
-
onLoadingTranslation:
|
41
|
-
languages:
|
42
|
-
...
|
40
|
+
onLoadingTranslation: L = void 0,
|
41
|
+
languages: P = [],
|
42
|
+
...C
|
43
43
|
}) {
|
44
|
-
const s =
|
45
|
-
let [n, v] = h(o ||
|
46
|
-
const m =
|
47
|
-
v(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 (
|
50
|
-
const r = o ||
|
51
|
-
r !== n &&
|
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,
|
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
|
-
|
61
|
+
L?.(r, s), n = u.current;
|
62
62
|
} else
|
63
|
-
|
64
|
-
const
|
65
|
-
(r, 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__ */
|
68
|
+
return /* @__PURE__ */ x(q, { value: { locale: n, changeLocale: f, t: y, languages: s, defaultLocale: m, ...C }, children: e });
|
69
69
|
}
|
70
|
-
function
|
71
|
-
return
|
70
|
+
function V() {
|
71
|
+
return A(p);
|
72
72
|
}
|
73
73
|
export {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
};
|
package/lib/package.json.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "3.1.
|
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": "
|
71
|
+
"gitHead": "4612b57a1452bd4330755b53d093505a6ae7dea5",
|
72
72
|
"dependencies": {
|
73
|
-
"@arcblock/bridge": "3.1.
|
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.
|
77
|
-
"@arcblock/nft-display": "3.1.
|
78
|
-
"@arcblock/react-hooks": "3.1.
|
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.
|
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(
|
package/src/Locale/context.tsx
CHANGED
@@ -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 =
|
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
|
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
|
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() {
|