@arcblock/ux 2.9.91 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/ActionButton/index.js +36 -48
- package/lib/ActivityIndicator/index.js +122 -75
- package/lib/Address/compact-text.js +48 -66
- package/lib/Address/did-address.js +114 -87
- package/lib/Address/index.js +15 -27
- package/lib/Address/responsive-did-address.js +48 -50
- package/lib/Alert/index.js +58 -52
- package/lib/AnimationWaiter/index.js +123 -69
- package/lib/Async/index.js +8 -22
- package/lib/Avatar/did-motif.js +38 -52
- package/lib/Avatar/etherscan-blockies.js +4 -10
- package/lib/Avatar/index.js +71 -77
- package/lib/Badge/index.js +49 -56
- package/lib/Blocklet/blocklet.js +181 -97
- package/lib/Blocklet/index.js +4 -24
- package/lib/Blocklet/utils.js +50 -13
- package/lib/BlockletContext/index.js +21 -31
- package/lib/BlockletNFT/index.js +255 -115
- package/lib/Button/index.js +5 -11
- package/lib/Button/wrap.js +45 -56
- package/lib/ButtonGroup/index.js +3 -9
- package/lib/CardSelector/index.js +67 -43
- package/lib/Center/index.js +19 -20
- package/lib/ClickToCopy/copy-button.js +37 -50
- package/lib/ClickToCopy/hook.js +10 -18
- package/lib/ClickToCopy/index.js +54 -66
- package/lib/CodeBlock/LightBox.js +84 -11
- package/lib/CodeBlock/index.js +175 -101
- package/lib/Colors/index.js +3 -20
- package/lib/Colors/themes/default.js +1 -7
- package/lib/Colors/themes/temp.js +1 -7
- package/lib/ContactForm/index.js +95 -60
- package/lib/CookieConsent/index.js +58 -52
- package/lib/CountDown/index.js +90 -59
- package/lib/DID/index.js +80 -96
- package/lib/Datatable/CustomToolbar.js +188 -137
- package/lib/Datatable/DatatableContext.js +14 -21
- package/lib/Datatable/TableSearch.js +99 -58
- package/lib/Datatable/index.js +312 -139
- package/lib/Datatable/utils.js +9 -17
- package/lib/Dialog/confirm.js +46 -58
- package/lib/Dialog/dialog.js +110 -66
- package/lib/Dialog/index.js +4 -27
- package/lib/Dialog/use-confirm.js +40 -65
- package/lib/DidLogo/index.js +14 -22
- package/lib/DriftBot/index.js +34 -19
- package/lib/Earth/index.js +214 -110
- package/lib/Earth/util.js +6 -19
- package/lib/Empty/index.js +33 -38
- package/lib/ErrorBoundary/fallback.js +45 -43
- package/lib/ErrorBoundary/index.js +1 -16
- package/lib/Footer/index.js +96 -48
- package/lib/Header/auto-hidden.js +28 -31
- package/lib/Header/header.js +151 -69
- package/lib/Header/index.js +2 -20
- package/lib/Header/responsive-header.js +67 -60
- package/lib/Icon/image.js +41 -45
- package/lib/Icon/index.js +51 -53
- package/lib/Img/index.js +77 -88
- package/lib/InfoRow/index.js +66 -48
- package/lib/Layout/dashboard/external-link.js +38 -53
- package/lib/Layout/dashboard/full-page.js +27 -41
- package/lib/Layout/dashboard/index.js +177 -132
- package/lib/Layout/dashboard/sidebar.js +164 -61
- package/lib/Layout/dashboard-legacy/header.js +119 -66
- package/lib/Layout/dashboard-legacy/index.js +90 -79
- package/lib/Layout/dashboard-legacy/sidebar.js +95 -62
- package/lib/Layout/index.js +200 -106
- package/lib/LoadingMask/index.js +31 -38
- package/lib/Locale/browser-lang.js +2 -8
- package/lib/Locale/context.js +46 -69
- package/lib/Locale/languages.js +6 -15
- package/lib/Locale/selector.js +116 -92
- package/lib/Locale/util.js +7 -16
- package/lib/Logo/index.js +54 -57
- package/lib/Metric/index.js +103 -40
- package/lib/NFTDisplay/aspect-ratio-container.js +33 -40
- package/lib/NFTDisplay/broken.js +68 -52
- package/lib/NFTDisplay/index.js +140 -129
- package/lib/NFTDisplay/loading.js +14 -13
- package/lib/NFTDisplay/svg-embedder/img.js +18 -33
- package/lib/NFTDisplay/svg-embedder/inline-svg.js +28 -32
- package/lib/NavMenu/index.js +2 -13
- package/lib/NavMenu/nav-menu.js +133 -148
- package/lib/NavMenu/style.js +179 -12
- package/lib/PageScroller/index.js +82 -93
- package/lib/PageScroller/story/FifthComponent.js +4 -10
- package/lib/PageScroller/story/FirstComponent.js +4 -10
- package/lib/PageScroller/story/FourthComponent.js +4 -10
- package/lib/PageScroller/story/FullPage.js +21 -28
- package/lib/PageScroller/story/PageContain.js +23 -30
- package/lib/PageScroller/story/SecondComponent.js +4 -10
- package/lib/PageScroller/story/ThirdComponent.js +4 -10
- package/lib/PageScroller/usePrevValue.js +4 -11
- package/lib/Passport/index.js +2 -9
- package/lib/Passport/passport.js +38 -51
- package/lib/PoweredByArcBlock/index.js +19 -33
- package/lib/PricingTable/PricingPlan.js +90 -34
- package/lib/PricingTable/index.js +28 -26
- package/lib/QRCode/index.js +38 -50
- package/lib/RelativeTime/index.js +44 -59
- package/lib/Result/common.js +85 -107
- package/lib/Result/index.js +22 -34
- package/lib/Result/result.js +35 -41
- package/lib/Result/translations.js +1 -7
- package/lib/Screenshot/BaseScreenshot/index.js +65 -43
- package/lib/Screenshot/BaseScreenshot/shells/Macbook.js +17 -27
- package/lib/Screenshot/BaseScreenshot/shells/Phone.js +14 -25
- package/lib/Screenshot/index.js +103 -92
- package/lib/SessionBlocklet/index.js +125 -143
- package/lib/SessionManager/index.js +2 -9
- package/lib/SessionPermission/index.js +13 -23
- package/lib/SessionUser/components/logged-in.js +139 -158
- package/lib/SessionUser/components/session-user-item.js +44 -58
- package/lib/SessionUser/components/session-user-switch.js +133 -152
- package/lib/SessionUser/components/un-login.js +27 -35
- package/lib/SessionUser/components/user-info.js +62 -74
- package/lib/SessionUser/index.js +26 -34
- package/lib/SessionUser/libs/translation.js +1 -7
- package/lib/SessionUser/libs/utils.js +13 -34
- package/lib/Sparkline/index.js +4 -10
- package/lib/Spinner/index.js +11 -17
- package/lib/SplitButton/index.js +72 -68
- package/lib/Success/index.js +28 -34
- package/lib/Switch/index.js +64 -75
- package/lib/Tabs/index.js +84 -103
- package/lib/Tag/index.js +52 -56
- package/lib/TextCollapse/index.js +57 -50
- package/lib/Theme/index.js +8 -47
- package/lib/Theme/theme-provider.js +19 -26
- package/lib/Theme/theme.js +49 -62
- package/lib/Toast/index.js +41 -73
- package/lib/Typography/index.js +44 -55
- package/lib/Util/constant.js +16 -22
- package/lib/Util/deprecate.js +14 -26
- package/lib/Util/federated.js +16 -38
- package/lib/Util/index.js +63 -113
- package/lib/Util/passport.js +23 -33
- package/lib/Util/wallet.js +5 -14
- package/lib/Video/index.js +34 -34
- package/lib/Wallet/Action.js +72 -49
- package/lib/Wallet/Download.js +132 -115
- package/lib/Wallet/Open.js +26 -25
- package/lib/WalletOSIcon/index.js +33 -42
- package/lib/WebWalletSWKeeper/index.js +42 -55
- package/lib/WechatPrompt/index.js +53 -33
- package/lib/index.js +38 -265
- package/lib/withTheme/index.js +53 -33
- package/lib/withTracker/error_boundary.js +7 -18
- package/lib/withTracker/index.js +25 -34
- package/package.json +9 -316
- package/src/WalletOSIcon/index.jsx +1 -1
- package/es/ActionButton/index.js +0 -99
- package/es/ActivityIndicator/index.js +0 -180
- package/es/Address/compact-text.js +0 -105
- package/es/Address/did-address.js +0 -222
- package/es/Address/index.js +0 -23
- package/es/Address/responsive-did-address.js +0 -87
- package/es/Alert/index.js +0 -134
- package/es/AnimationWaiter/default-animation.json +0 -1
- package/es/AnimationWaiter/index.js +0 -240
- package/es/Async/index.js +0 -38
- package/es/Avatar/did-motif.js +0 -68
- package/es/Avatar/etherscan-blockies.js +0 -83
- package/es/Avatar/index.js +0 -179
- package/es/Badge/index.js +0 -98
- package/es/Blocklet/blocklet.js +0 -298
- package/es/Blocklet/index.js +0 -4
- package/es/Blocklet/utils.js +0 -52
- package/es/BlockletContext/index.js +0 -65
- package/es/BlockletNFT/index.js +0 -412
- package/es/Button/index.js +0 -8
- package/es/Button/wrap.js +0 -140
- package/es/ButtonGroup/index.js +0 -6
- package/es/CardSelector/index.js +0 -149
- package/es/Center/index.js +0 -41
- package/es/ClickToCopy/copy-button.js +0 -72
- package/es/ClickToCopy/hook.js +0 -39
- package/es/ClickToCopy/index.js +0 -92
- package/es/CodeBlock/LightBox.js +0 -85
- package/es/CodeBlock/index.js +0 -222
- package/es/Colors/index.js +0 -3
- package/es/Colors/themes/default.js +0 -77
- package/es/Colors/themes/temp.js +0 -41
- package/es/ContactForm/index.js +0 -230
- package/es/CookieConsent/index.js +0 -113
- package/es/CountDown/index.js +0 -178
- package/es/DID/index.js +0 -249
- package/es/Datatable/CustomToolbar.js +0 -396
- package/es/Datatable/DatatableContext.js +0 -34
- package/es/Datatable/TableSearch.js +0 -166
- package/es/Datatable/index.js +0 -629
- package/es/Datatable/utils.js +0 -132
- package/es/Dialog/confirm.js +0 -123
- package/es/Dialog/dialog.js +0 -201
- package/es/Dialog/index.js +0 -4
- package/es/Dialog/types.d.ts +0 -17
- package/es/Dialog/use-confirm.js +0 -133
- package/es/DidLogo/index.js +0 -31
- package/es/DriftBot/index.js +0 -70
- package/es/Earth/countries.json +0 -8057
- package/es/Earth/index.js +0 -521
- package/es/Earth/util.js +0 -51
- package/es/Empty/index.js +0 -65
- package/es/ErrorBoundary/fallback.js +0 -73
- package/es/ErrorBoundary/index.js +0 -1
- package/es/Footer/index.js +0 -172
- package/es/Header/auto-hidden.js +0 -35
- package/es/Header/header.js +0 -223
- package/es/Header/index.js +0 -2
- package/es/Header/responsive-header.js +0 -146
- package/es/Icon/image.js +0 -65
- package/es/Icon/index.js +0 -84
- package/es/Img/index.js +0 -218
- package/es/InfoRow/index.js +0 -87
- package/es/Layout/dashboard/external-link.js +0 -58
- package/es/Layout/dashboard/full-page.js +0 -53
- package/es/Layout/dashboard/index.js +0 -282
- package/es/Layout/dashboard/sidebar.js +0 -209
- package/es/Layout/dashboard-legacy/header.js +0 -174
- package/es/Layout/dashboard-legacy/index.js +0 -148
- package/es/Layout/dashboard-legacy/sidebar.js +0 -129
- package/es/Layout/index.js +0 -335
- package/es/LoadingMask/index.js +0 -102
- package/es/Locale/browser-lang.js +0 -52
- package/es/Locale/context.js +0 -139
- package/es/Locale/languages.js +0 -60
- package/es/Locale/selector.js +0 -186
- package/es/Locale/util.js +0 -21
- package/es/Logo/images/logo-dark-text.svg +0 -3
- package/es/Logo/images/logo-dark-top.svg +0 -6
- package/es/Logo/images/logo-light-text.svg +0 -3
- package/es/Logo/images/logo-light-top.svg +0 -6
- package/es/Logo/index.js +0 -136
- package/es/Metric/index.js +0 -132
- package/es/NFTDisplay/NFTBroken.svg +0 -34
- package/es/NFTDisplay/README.md +0 -59
- package/es/NFTDisplay/aspect-ratio-container.js +0 -39
- package/es/NFTDisplay/broken.js +0 -132
- package/es/NFTDisplay/demo/data/asset-state-display-url.json +0 -7
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-1-1.json +0 -10
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-374-130.json +0 -10
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-with-foreign-object.json +0 -20
- package/es/NFTDisplay/demo/data/asset-state-svg.json +0 -29
- package/es/NFTDisplay/demo/data/asset-state-url.json +0 -10
- package/es/NFTDisplay/index.js +0 -328
- package/es/NFTDisplay/loading.js +0 -18
- package/es/NFTDisplay/svg-embedder/img.js +0 -45
- package/es/NFTDisplay/svg-embedder/inline-svg.js +0 -39
- package/es/NavMenu/index.js +0 -2
- package/es/NavMenu/nav-menu.js +0 -358
- package/es/NavMenu/style.js +0 -181
- package/es/PageScroller/index.js +0 -286
- package/es/PageScroller/story/FifthComponent.js +0 -9
- package/es/PageScroller/story/FirstComponent.js +0 -9
- package/es/PageScroller/story/FourthComponent.js +0 -12
- package/es/PageScroller/story/FullPage.js +0 -47
- package/es/PageScroller/story/PageContain.js +0 -59
- package/es/PageScroller/story/SecondComponent.js +0 -9
- package/es/PageScroller/story/ThirdComponent.js +0 -9
- package/es/PageScroller/story/index.css +0 -115
- package/es/PageScroller/usePrevValue.js +0 -9
- package/es/Passport/index.js +0 -2
- package/es/Passport/passport.js +0 -103
- package/es/PoweredByArcBlock/index.js +0 -31
- package/es/PricingTable/PricingPlan.js +0 -124
- package/es/PricingTable/index.js +0 -53
- package/es/QRCode/index.js +0 -73
- package/es/RelativeTime/index.js +0 -107
- package/es/Result/common.js +0 -140
- package/es/Result/demo/fixtures/result-image-404.svg +0 -1
- package/es/Result/index.js +0 -33
- package/es/Result/result.js +0 -59
- package/es/Result/translations.js +0 -54
- package/es/Screenshot/BaseScreenshot/index.js +0 -91
- package/es/Screenshot/BaseScreenshot/shells/Macbook.js +0 -51
- package/es/Screenshot/BaseScreenshot/shells/Phone.js +0 -36
- package/es/Screenshot/demo/images/bg-00.jpg +0 -0
- package/es/Screenshot/demo/images/bg-01.jpg +0 -0
- package/es/Screenshot/demo/images/bg-02.jpg +0 -0
- package/es/Screenshot/demo/images/bg-03.jpg +0 -0
- package/es/Screenshot/demo/images/bg-04.jpg +0 -0
- package/es/Screenshot/demo/images/bg-05.jpg +0 -0
- package/es/Screenshot/demo/images/bg-06.jpg +0 -0
- package/es/Screenshot/demo/images/bg-07.jpg +0 -0
- package/es/Screenshot/demo/images/bg-08.jpg +0 -0
- package/es/Screenshot/demo/images/bg-09.jpg +0 -0
- package/es/Screenshot/devices.css +0 -1366
- package/es/Screenshot/index.js +0 -299
- package/es/SessionBlocklet/index.js +0 -173
- package/es/SessionManager/index.js +0 -2
- package/es/SessionPermission/index.js +0 -28
- package/es/SessionUser/components/logged-in.js +0 -229
- package/es/SessionUser/components/session-user-item.js +0 -102
- package/es/SessionUser/components/session-user-switch.js +0 -223
- package/es/SessionUser/components/un-login.js +0 -64
- package/es/SessionUser/components/user-info.js +0 -167
- package/es/SessionUser/index.js +0 -49
- package/es/SessionUser/libs/translation.js +0 -19
- package/es/SessionUser/libs/utils.js +0 -29
- package/es/Sparkline/index.js +0 -193
- package/es/Spinner/index.js +0 -28
- package/es/SplitButton/index.js +0 -145
- package/es/Success/index.js +0 -175
- package/es/Switch/index.js +0 -96
- package/es/Tabs/index.js +0 -214
- package/es/Tag/index.js +0 -108
- package/es/TextCollapse/index.js +0 -92
- package/es/Theme/index.js +0 -16
- package/es/Theme/theme-provider.js +0 -39
- package/es/Theme/theme.js +0 -145
- package/es/Toast/index.js +0 -97
- package/es/Typography/index.js +0 -95
- package/es/Util/constant.js +0 -42
- package/es/Util/deprecate.js +0 -28
- package/es/Util/federated.js +0 -91
- package/es/Util/index.js +0 -363
- package/es/Util/passport.js +0 -62
- package/es/Util/wallet.js +0 -32
- package/es/Video/index.js +0 -89
- package/es/Wallet/Action.js +0 -119
- package/es/Wallet/Download.js +0 -331
- package/es/Wallet/Open.js +0 -45
- package/es/Wallet/images/abtwallet.png +0 -0
- package/es/Wallet/images/android_download.svg +0 -23
- package/es/Wallet/images/app-store.svg +0 -20
- package/es/Wallet/images/google-play.svg +0 -70
- package/es/WalletOSIcon/index.js +0 -82
- package/es/WebWalletSWKeeper/index.js +0 -117
- package/es/WechatPrompt/images/android.png +0 -0
- package/es/WechatPrompt/images/ios.png +0 -0
- package/es/WechatPrompt/index.js +0 -88
- package/es/index.js +0 -38
- package/es/withTheme/index.js +0 -69
- package/es/withTracker/README.md +0 -34
- package/es/withTracker/error_boundary.js +0 -34
- package/es/withTracker/index.js +0 -55
package/lib/Locale/context.js
CHANGED
@@ -1,43 +1,23 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.LocaleContext = exports.LocaleConsumer = void 0;
|
7
|
-
exports.LocaleProvider = LocaleProvider;
|
8
|
-
exports.setLocale = exports.getLocale = void 0;
|
9
|
-
exports.useLocaleContext = useLocaleContext;
|
10
|
-
var _react = require("react");
|
11
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
13
|
-
var _jsCookie = _interopRequireDefault(require("js-cookie"));
|
14
|
-
var _browserLang = _interopRequireDefault(require("./browser-lang"));
|
15
|
-
var _util = require("./util");
|
16
|
-
var _Util = require("../Util");
|
17
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
18
|
-
const _excluded = ["children", "locale", "fallbackLocale", "translations", "onLoadingTranslation", "languages"];
|
19
1
|
/* eslint-disable no-prototype-builtins */
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
2
|
+
import { createContext, useState, useEffect, useContext, useRef, useCallback } from 'react';
|
3
|
+
import get from 'lodash/get';
|
4
|
+
import PropTypes from 'prop-types';
|
5
|
+
import Cookie from 'js-cookie';
|
6
|
+
import browserLang from './browser-lang';
|
7
|
+
import { translate } from './util';
|
8
|
+
import { getCookieOptions } from '../Util';
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
28
10
|
const cookieName = 'nf_lang';
|
29
11
|
|
30
12
|
// 跨应用传递多语言选择的方式是在 query string 中添加 locale 参数,LocaleSelector 要高优先级遵守这个参数
|
31
|
-
const getLocaleFromSearchParams =
|
32
|
-
let url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.href;
|
13
|
+
const getLocaleFromSearchParams = (languages, url = window.location.href) => {
|
33
14
|
const locale = new URL(url).searchParams.get('locale');
|
34
15
|
if (languages.find(x => x.code === locale)) {
|
35
16
|
return locale;
|
36
17
|
}
|
37
18
|
return null;
|
38
19
|
};
|
39
|
-
const setLocaleParam =
|
40
|
-
let url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.href;
|
20
|
+
const setLocaleParam = (locale, url = window.location.href) => {
|
41
21
|
const urlObj = new URL(url);
|
42
22
|
const hasLocaleParam = urlObj.searchParams.has('locale');
|
43
23
|
if (hasLocaleParam) {
|
@@ -45,23 +25,20 @@ const setLocaleParam = function setLocaleParam(locale) {
|
|
45
25
|
window.history.replaceState({}, '', urlObj.href);
|
46
26
|
}
|
47
27
|
};
|
48
|
-
const getLocale =
|
49
|
-
var _languages$;
|
50
|
-
let languages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
28
|
+
const getLocale = (languages = []) => {
|
51
29
|
const langParams = {
|
52
30
|
languages: languages.map(item => item.code),
|
53
31
|
// 取 languages 首个元素的 code 值, 如果不存在则取 'en'
|
54
|
-
fallback:
|
32
|
+
fallback: languages?.[0]?.code || 'en'
|
55
33
|
};
|
56
|
-
return getLocaleFromSearchParams(languages) ||
|
34
|
+
return getLocaleFromSearchParams(languages) || Cookie.get(cookieName) || browserLang(langParams);
|
57
35
|
};
|
58
36
|
const setLocale = locale => {
|
59
|
-
|
37
|
+
Cookie.set(cookieName, locale, getCookieOptions());
|
60
38
|
setLocaleParam(locale);
|
61
39
|
};
|
62
|
-
exports.setLocale = setLocale;
|
63
40
|
const getLanguages = arg => {
|
64
|
-
const env = (
|
41
|
+
const env = get(window, 'blocklet.languages');
|
65
42
|
if (Array.isArray(env) && env.length) {
|
66
43
|
return env;
|
67
44
|
}
|
@@ -76,32 +53,30 @@ const getLanguages = arg => {
|
|
76
53
|
name: '简体中文'
|
77
54
|
}];
|
78
55
|
};
|
79
|
-
const LocaleContext =
|
56
|
+
const LocaleContext = /*#__PURE__*/createContext();
|
80
57
|
const {
|
81
58
|
Provider,
|
82
59
|
Consumer
|
83
60
|
} = LocaleContext;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
} = _ref,
|
94
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
61
|
+
function LocaleProvider({
|
62
|
+
children,
|
63
|
+
locale,
|
64
|
+
fallbackLocale,
|
65
|
+
translations,
|
66
|
+
onLoadingTranslation,
|
67
|
+
languages,
|
68
|
+
...rest
|
69
|
+
}) {
|
95
70
|
const langs = getLanguages(languages);
|
96
71
|
// eslint-disable-next-line prefer-const
|
97
|
-
let [currentLocale, setCurrentLocale] =
|
98
|
-
const lastCurrentLocale =
|
99
|
-
const [, setForceUpdate] =
|
72
|
+
let [currentLocale, setCurrentLocale] = useState(locale || getLocale(langs));
|
73
|
+
const lastCurrentLocale = useRef(fallbackLocale);
|
74
|
+
const [, setForceUpdate] = useState(0);
|
100
75
|
const changeLocale = newLocale => {
|
101
76
|
setCurrentLocale(newLocale);
|
102
77
|
setLocale(newLocale);
|
103
78
|
};
|
104
|
-
|
79
|
+
useEffect(() => {
|
105
80
|
const tmpLocale = locale || getLocale(langs);
|
106
81
|
if (tmpLocale !== currentLocale) {
|
107
82
|
changeLocale(tmpLocale);
|
@@ -127,31 +102,32 @@ function LocaleProvider(_ref) {
|
|
127
102
|
} else {
|
128
103
|
lastCurrentLocale.current = currentLocale;
|
129
104
|
}
|
130
|
-
const t =
|
131
|
-
return /*#__PURE__*/(
|
132
|
-
value:
|
105
|
+
const t = useCallback((key, data) => translate(translations, key, currentLocale, fallbackLocale, data), [translations, currentLocale, fallbackLocale]);
|
106
|
+
return /*#__PURE__*/_jsx(Provider, {
|
107
|
+
value: {
|
133
108
|
locale: currentLocale,
|
134
109
|
changeLocale,
|
135
110
|
t,
|
136
|
-
languages: langs
|
137
|
-
|
111
|
+
languages: langs,
|
112
|
+
...rest
|
113
|
+
},
|
138
114
|
children: children
|
139
115
|
});
|
140
116
|
}
|
141
117
|
function useLocaleContext() {
|
142
|
-
const context =
|
118
|
+
const context = useContext(LocaleContext);
|
143
119
|
return context;
|
144
120
|
}
|
145
121
|
LocaleProvider.propTypes = {
|
146
|
-
children:
|
147
|
-
translations:
|
148
|
-
onLoadingTranslation:
|
149
|
-
locale:
|
122
|
+
children: PropTypes.any.isRequired,
|
123
|
+
translations: PropTypes.object.isRequired,
|
124
|
+
onLoadingTranslation: PropTypes.func,
|
125
|
+
locale: PropTypes.string,
|
150
126
|
// 会影响 translate(key) 的结果 - 当 key 无效时查找 fallbackLocale 对应的翻译结果
|
151
|
-
fallbackLocale:
|
152
|
-
languages:
|
153
|
-
code:
|
154
|
-
name:
|
127
|
+
fallbackLocale: PropTypes.string,
|
128
|
+
languages: PropTypes.arrayOf(PropTypes.shape({
|
129
|
+
code: PropTypes.string,
|
130
|
+
name: PropTypes.string
|
155
131
|
}))
|
156
132
|
};
|
157
133
|
LocaleProvider.defaultProps = {
|
@@ -159,4 +135,5 @@ LocaleProvider.defaultProps = {
|
|
159
135
|
fallbackLocale: '',
|
160
136
|
languages: [],
|
161
137
|
onLoadingTranslation: () => {}
|
162
|
-
};
|
138
|
+
};
|
139
|
+
export { LocaleProvider, Consumer as LocaleConsumer, LocaleContext, useLocaleContext, setLocale, getLocale };
|
package/lib/Locale/languages.js
CHANGED
@@ -1,16 +1,5 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.map = exports.default = void 0;
|
7
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
8
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
9
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
10
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
11
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
12
1
|
// from: https://github.com/meikidd/iso-639-1/blob/master/src/data.js
|
13
|
-
const languages =
|
2
|
+
const languages = {
|
14
3
|
ar: {
|
15
4
|
name: 'Arabic',
|
16
5
|
nativeName: 'اَلْعَرَبِيَّةُ'
|
@@ -64,6 +53,8 @@ const languages = exports.map = {
|
|
64
53
|
nativeName: '繁體中文'
|
65
54
|
}
|
66
55
|
};
|
67
|
-
|
68
|
-
code
|
69
|
-
|
56
|
+
export default Object.keys(languages).map(code => ({
|
57
|
+
code,
|
58
|
+
...languages[code]
|
59
|
+
}));
|
60
|
+
export { languages as map };
|
package/lib/Locale/selector.js
CHANGED
@@ -1,52 +1,35 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = LocaleSelector;
|
7
|
-
var _react = require("react");
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
|
-
var _material = require("@mui/material");
|
10
|
-
var _react2 = require("@iconify/react");
|
11
|
-
var _check = _interopRequireDefault(require("@iconify-icons/material-symbols/check"));
|
12
|
-
var _language = _interopRequireDefault(require("iconify-icons-material-symbols-400/language"));
|
13
|
-
var _noop = _interopRequireDefault(require("lodash/noop"));
|
14
|
-
var _Util = require("../Util");
|
15
|
-
var _Colors = require("../Colors");
|
16
|
-
var _context = require("./context");
|
17
|
-
var _Theme = require("../Theme");
|
18
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
19
|
-
var _templateObject, _templateObject2;
|
20
|
-
const _excluded = ["showText", "popperProps", "popperType", "icon", "size"];
|
21
1
|
/* eslint-disable react/jsx-no-bind */
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
2
|
+
import { useState, useContext, useRef, useMemo } from 'react';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
import { Button, Typography, IconButton, Popper, MenuItem, MenuList, Box, ClickAwayListener } from '@mui/material';
|
5
|
+
import { Icon as IconifyIcon } from '@iconify/react';
|
6
|
+
import CheckIcon from '@iconify-icons/material-symbols/check';
|
7
|
+
import LanguageIcon from 'iconify-icons-material-symbols-400/language';
|
8
|
+
import noop from 'lodash/noop';
|
9
|
+
import { getColor, getBackground } from '../Util';
|
10
|
+
import { temp as colors } from '../Colors';
|
11
|
+
import { LocaleContext } from './context';
|
12
|
+
import { styled, useTheme } from '../Theme';
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
14
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
15
|
+
export default function LocaleSelector(props) {
|
33
16
|
const {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
17
|
+
showText,
|
18
|
+
popperProps,
|
19
|
+
popperType,
|
20
|
+
icon: Icon,
|
21
|
+
size,
|
22
|
+
...rest
|
23
|
+
} = props;
|
41
24
|
const {
|
42
25
|
locale,
|
43
26
|
changeLocale,
|
44
27
|
languages
|
45
|
-
} =
|
46
|
-
const anchorEl =
|
47
|
-
const [open, setOpen] =
|
48
|
-
const theme =
|
49
|
-
const dark =
|
28
|
+
} = useContext(LocaleContext);
|
29
|
+
const anchorEl = useRef(null);
|
30
|
+
const [open, setOpen] = useState(false);
|
31
|
+
const theme = useTheme();
|
32
|
+
const dark = theme?.palette?.mode === 'dark';
|
50
33
|
const onSelect = newLocale => {
|
51
34
|
changeLocale(newLocale);
|
52
35
|
setOpen(false);
|
@@ -55,13 +38,12 @@ function LocaleSelector(props) {
|
|
55
38
|
}
|
56
39
|
};
|
57
40
|
const onClose = e => {
|
58
|
-
|
59
|
-
if ((_anchorEl$current = anchorEl.current) !== null && _anchorEl$current !== void 0 && _anchorEl$current.contains(e.target)) {
|
41
|
+
if (anchorEl.current?.contains(e.target)) {
|
60
42
|
return;
|
61
43
|
}
|
62
44
|
setOpen(false);
|
63
45
|
};
|
64
|
-
const ButtonComponent = showText ?
|
46
|
+
const ButtonComponent = showText ? Button : IconButton;
|
65
47
|
const handleEventProps = popperType === 'hover' ? {
|
66
48
|
onMouseEnter: () => {
|
67
49
|
setOpen(true);
|
@@ -74,89 +56,131 @@ function LocaleSelector(props) {
|
|
74
56
|
setOpen(!open);
|
75
57
|
}
|
76
58
|
};
|
77
|
-
const renderIcon =
|
59
|
+
const renderIcon = useMemo(() => {
|
78
60
|
if (Icon) {
|
79
|
-
return /*#__PURE__*/(
|
61
|
+
return /*#__PURE__*/_jsx(Icon, {});
|
80
62
|
}
|
81
|
-
return /*#__PURE__*/(
|
82
|
-
icon:
|
63
|
+
return /*#__PURE__*/_jsx(IconifyIcon, {
|
64
|
+
icon: LanguageIcon,
|
83
65
|
fontSize: size,
|
84
66
|
style: {
|
85
67
|
transform: 'scale(1.10)'
|
86
68
|
}
|
87
69
|
});
|
88
70
|
}, [Icon, size]);
|
89
|
-
return /*#__PURE__*/(
|
71
|
+
return /*#__PURE__*/_jsxs(Div, {
|
90
72
|
component: "div",
|
91
73
|
dark: dark,
|
92
|
-
theme: theme
|
93
|
-
|
94
|
-
|
74
|
+
theme: theme,
|
75
|
+
...rest,
|
76
|
+
...handleEventProps,
|
77
|
+
children: [/*#__PURE__*/_jsx(ButtonComponent, {
|
95
78
|
ref: anchorEl,
|
96
79
|
className: "trigger",
|
97
80
|
role: "button",
|
98
81
|
"aria-label": "Locale selector button",
|
99
|
-
children: /*#__PURE__*/(
|
82
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
100
83
|
display: "flex",
|
101
84
|
alignItems: "center",
|
102
|
-
children: [renderIcon, showText ? /*#__PURE__*/(
|
85
|
+
children: [renderIcon, showText ? /*#__PURE__*/_jsx(Typography, {
|
103
86
|
component: "strong",
|
104
87
|
className: "trigger-text",
|
105
88
|
children: languages.find(x => x.code === locale).name
|
106
89
|
}) : '']
|
107
90
|
})
|
108
|
-
}), /*#__PURE__*/(
|
91
|
+
}), /*#__PURE__*/_jsx(StyledPopper, {
|
109
92
|
open: open,
|
110
|
-
anchorEl: anchorEl.current
|
111
|
-
|
93
|
+
anchorEl: anchorEl.current,
|
94
|
+
...popperProps,
|
112
95
|
disablePortal: true,
|
113
|
-
children: /*#__PURE__*/(
|
96
|
+
children: /*#__PURE__*/_jsx("div", {
|
114
97
|
className: "locales",
|
115
|
-
children: /*#__PURE__*/(
|
98
|
+
children: /*#__PURE__*/_jsx(ClickAwayListener, {
|
116
99
|
onClickAway: onClose,
|
117
|
-
children: /*#__PURE__*/(
|
118
|
-
children: languages.map(
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
}), name]
|
130
|
-
}, code);
|
131
|
-
})
|
100
|
+
children: /*#__PURE__*/_jsx(MenuList, {
|
101
|
+
children: languages.map(({
|
102
|
+
code,
|
103
|
+
name
|
104
|
+
}) => /*#__PURE__*/_jsxs(MenuItem, {
|
105
|
+
className: "locale-item",
|
106
|
+
onClick: () => onSelect(code, name),
|
107
|
+
children: [/*#__PURE__*/_jsx(IconifyIcon, {
|
108
|
+
icon: CheckIcon,
|
109
|
+
className: code === locale ? 'check-icon check-icon-visible' : 'check-icon'
|
110
|
+
}), name]
|
111
|
+
}, code))
|
132
112
|
})
|
133
113
|
})
|
134
114
|
})
|
135
|
-
})
|
136
|
-
})
|
115
|
+
})]
|
116
|
+
});
|
137
117
|
}
|
138
118
|
LocaleSelector.propTypes = {
|
139
|
-
size:
|
140
|
-
showText:
|
141
|
-
popperProps:
|
142
|
-
onChange:
|
143
|
-
popperType:
|
144
|
-
icon:
|
119
|
+
size: PropTypes.number,
|
120
|
+
showText: PropTypes.bool,
|
121
|
+
popperProps: PropTypes.object,
|
122
|
+
onChange: PropTypes.func,
|
123
|
+
popperType: PropTypes.oneOf(['hover', 'click']),
|
124
|
+
icon: PropTypes.any
|
145
125
|
};
|
146
126
|
LocaleSelector.defaultProps = {
|
147
127
|
showText: true,
|
148
128
|
size: 24,
|
149
129
|
popperProps: {},
|
150
|
-
onChange:
|
130
|
+
onChange: noop,
|
151
131
|
popperType: 'click',
|
152
132
|
icon: null
|
153
133
|
};
|
154
|
-
const Div =
|
134
|
+
const Div = styled('div', {
|
155
135
|
shouldForwardProp: prop => prop !== 'dark'
|
156
|
-
})
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
136
|
+
})`
|
137
|
+
display: inline-block;
|
138
|
+
|
139
|
+
.trigger {
|
140
|
+
display: flex;
|
141
|
+
flex-direction: column;
|
142
|
+
justify-content: center;
|
143
|
+
font-size: 14px;
|
144
|
+
white-space: nowrap;
|
145
|
+
|
146
|
+
.trigger-text {
|
147
|
+
margin-left: 5px;
|
148
|
+
font-size: 14px;
|
149
|
+
color: ${props => getColor(props)};
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
.locales {
|
154
|
+
background: ${props => getBackground(props)};
|
155
|
+
box-shadow: 0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6};
|
156
|
+
border-radius: 8px;
|
157
|
+
}
|
158
|
+
|
159
|
+
.locale-item {
|
160
|
+
font-size: 16px;
|
161
|
+
font-style: normal;
|
162
|
+
font-stretch: normal;
|
163
|
+
line-height: normal;
|
164
|
+
letter-spacing: 2px;
|
165
|
+
text-align: center;
|
166
|
+
color: ${props => getColor(props)};
|
167
|
+
cursor: pointer;
|
168
|
+
display: flex;
|
169
|
+
padding: 16px;
|
170
|
+
align-items: center;
|
171
|
+
.check-icon {
|
172
|
+
visibility: hidden;
|
173
|
+
margin-right: 4px;
|
174
|
+
}
|
175
|
+
.check-icon-visible {
|
176
|
+
visibility: visible;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
`;
|
180
|
+
const StyledPopper = styled(Popper)`
|
181
|
+
z-index: ${({
|
182
|
+
theme
|
183
|
+
}) => {
|
161
184
|
return theme.zIndex.tooltip + 10;
|
162
|
-
}
|
185
|
+
}};
|
186
|
+
`;
|
package/lib/Locale/util.js
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
-
|
1
|
+
import get from 'lodash/get';
|
2
2
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.translate = exports.t = exports.replace = void 0;
|
7
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
3
|
/* eslint-disable no-prototype-builtins */
|
10
|
-
const replace = (template, data) => template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
|
11
|
-
|
12
|
-
const translate = exports.translate = function translate(translations, key, locale) {
|
13
|
-
let fallbackLocale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'en';
|
14
|
-
let data = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
4
|
+
export const replace = (template, data) => template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
|
5
|
+
export const translate = (translations, key, locale, fallbackLocale = 'en', data = {}) => {
|
15
6
|
const translation = translations[locale];
|
16
|
-
const translationValue = (
|
17
|
-
const fallbackValue = (
|
7
|
+
const translationValue = get(translation, key);
|
8
|
+
const fallbackValue = get(translations[fallbackLocale], key);
|
18
9
|
if (!translation || !translationValue) {
|
19
|
-
console.warn(
|
10
|
+
console.warn(`Warning: no ${key} translation of ${locale}`);
|
20
11
|
if (fallbackLocale && fallbackValue) {
|
21
12
|
return replace(fallbackValue, data);
|
22
13
|
}
|
@@ -27,4 +18,4 @@ const translate = exports.translate = function translate(translations, key, loca
|
|
27
18
|
}
|
28
19
|
return replace(translationValue, data);
|
29
20
|
};
|
30
|
-
const t =
|
21
|
+
export const t = translate;
|