@arcblock/ux 2.10.39 → 2.10.41
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/BlockletV2/blocklet.d.ts +2 -1
- package/lib/BlockletV2/blocklet.js +7 -6
- package/lib/Center/index.d.ts +7 -3
- package/lib/Center/index.js +3 -2
- package/lib/Locale/context.d.ts +22 -38
- package/lib/Locale/context.js +5 -24
- package/package.json +5 -5
- package/src/BlockletV2/blocklet.tsx +8 -14
- package/src/Center/index.js +3 -2
- package/src/Locale/{context.jsx → context.tsx} +35 -31
@@ -1,5 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
|
2
|
+
import { CardProps } from '@mui/material';
|
3
|
+
export interface IBlockletStore extends CardProps {
|
3
4
|
did?: string;
|
4
5
|
title: string;
|
5
6
|
description?: string;
|
@@ -61,15 +61,16 @@ export default function BlockletStore(props) {
|
|
61
61
|
};
|
62
62
|
return /*#__PURE__*/_jsxs(Card, {
|
63
63
|
variant: "outlined",
|
64
|
+
onClick: handleMainClick,
|
65
|
+
...rest,
|
64
66
|
sx: {
|
65
67
|
p: {
|
66
68
|
xs: 2,
|
67
69
|
md: 3
|
68
70
|
},
|
69
|
-
borderRadius: 2
|
71
|
+
borderRadius: 2,
|
72
|
+
...rest.sx
|
70
73
|
},
|
71
|
-
onClick: handleMainClick,
|
72
|
-
...rest,
|
73
74
|
children: [/*#__PURE__*/_jsxs(Stack, {
|
74
75
|
flex: 1,
|
75
76
|
direction: "row",
|
@@ -79,13 +80,13 @@ export default function BlockletStore(props) {
|
|
79
80
|
children: [/*#__PURE__*/_jsx(Avatar, {
|
80
81
|
src: cover,
|
81
82
|
did: did,
|
82
|
-
size:
|
83
|
+
size: 48,
|
83
84
|
variant: "rounded"
|
84
85
|
}), /*#__PURE__*/_jsx(Typography, {
|
85
86
|
flex: 1,
|
87
|
+
fontWeight: "typography.fontWeightMedium",
|
86
88
|
sx: {
|
87
89
|
fontSize: 16,
|
88
|
-
fontWeight: 500,
|
89
90
|
textOverflow: 'ellipsis',
|
90
91
|
whiteSpace: 'nowrap',
|
91
92
|
overflow: 'hidden'
|
@@ -100,7 +101,7 @@ export default function BlockletStore(props) {
|
|
100
101
|
borderColor: theme.palette.grey[300],
|
101
102
|
borderRadius: 8,
|
102
103
|
fontSize: 13,
|
103
|
-
fontWeight:
|
104
|
+
fontWeight: theme.typography.fontWeightMedium
|
104
105
|
},
|
105
106
|
onClick: handleButtonClick,
|
106
107
|
children: [buttonLoading && /*#__PURE__*/_jsx(CircularProgress, {
|
package/lib/Center/index.d.ts
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
/**
|
2
|
-
*
|
3
|
-
* @param {
|
2
|
+
* @param {Object} props 属性
|
3
|
+
* @param {*} props.children 子元素
|
4
|
+
* @param {'screen'|'parent'} [props.relative='screen'] 容器相对尺寸,默认相对屏幕(screen),可设置为父容器(parent)
|
4
5
|
* @returns react component element
|
5
6
|
*/
|
6
|
-
declare function Center({ children, relative }:
|
7
|
+
declare function Center({ children, relative }: {
|
8
|
+
children: any;
|
9
|
+
relative?: "screen" | "parent" | undefined;
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
7
11
|
declare namespace Center {
|
8
12
|
namespace propTypes {
|
9
13
|
let children: PropTypes.Validator<any>;
|
package/lib/Center/index.js
CHANGED
@@ -3,8 +3,9 @@ import PropTypes from 'prop-types';
|
|
3
3
|
import { styled } from '../Theme';
|
4
4
|
|
5
5
|
/**
|
6
|
-
*
|
7
|
-
* @param {
|
6
|
+
* @param {Object} props 属性
|
7
|
+
* @param {*} props.children 子元素
|
8
|
+
* @param {'screen'|'parent'} [props.relative='screen'] 容器相对尺寸,默认相对屏幕(screen),可设置为父容器(parent)
|
8
9
|
* @returns react component element
|
9
10
|
*/
|
10
11
|
export default function Center({
|
package/lib/Locale/context.d.ts
CHANGED
@@ -1,39 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
code: PropTypes.Requireable<string>;
|
19
|
-
name: PropTypes.Requireable<string>;
|
20
|
-
}> | null | undefined)[]>;
|
21
|
-
}
|
22
|
-
namespace defaultProps {
|
23
|
-
let locale_1: string;
|
24
|
-
export { locale_1 as locale };
|
25
|
-
let fallbackLocale_1: string;
|
26
|
-
export { fallbackLocale_1 as fallbackLocale };
|
27
|
-
let languages_1: never[];
|
28
|
-
export { languages_1 as languages };
|
29
|
-
export function onLoadingTranslation_1(): void;
|
30
|
-
export { onLoadingTranslation_1 as onLoadingTranslation };
|
31
|
-
}
|
1
|
+
import React, { ReactNode } from 'react';
|
2
|
+
declare const getLocale: (languages?: {
|
3
|
+
code: string;
|
4
|
+
}[]) => string;
|
5
|
+
declare const setLocale: (locale: string) => void;
|
6
|
+
interface LocaleProviderProps {
|
7
|
+
children: ReactNode;
|
8
|
+
locale?: string;
|
9
|
+
fallbackLocale?: string;
|
10
|
+
translations: Record<string, any>;
|
11
|
+
onLoadingTranslation?: (locale: string, languages: {
|
12
|
+
code: string;
|
13
|
+
}[]) => void;
|
14
|
+
languages?: {
|
15
|
+
code: string;
|
16
|
+
name: string;
|
17
|
+
}[];
|
32
18
|
}
|
33
|
-
declare const
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
export
|
38
|
-
import PropTypes from 'prop-types';
|
39
|
-
export { Consumer as LocaleConsumer };
|
19
|
+
declare const LocaleContext: React.Context<any>;
|
20
|
+
declare const Consumer: React.Consumer<any>;
|
21
|
+
declare function LocaleProvider({ children, locale, fallbackLocale, translations, onLoadingTranslation, languages, ...rest }: LocaleProviderProps): import("react/jsx-runtime").JSX.Element;
|
22
|
+
declare function useLocaleContext(): any;
|
23
|
+
export { LocaleProvider, Consumer as LocaleConsumer, LocaleContext, useLocaleContext, setLocale, getLocale };
|
package/lib/Locale/context.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
/* eslint-disable no-prototype-builtins */
|
3
|
-
import { createContext, useState, useEffect, useContext, useRef, useCallback } from 'react';
|
3
|
+
import React, { createContext, useState, useEffect, useContext, useRef, useCallback } from 'react';
|
4
4
|
import get from 'lodash/get';
|
5
|
-
import PropTypes from 'prop-types';
|
6
5
|
import Cookie from 'js-cookie';
|
7
6
|
import browserLang from './browser-lang';
|
8
7
|
import { translate } from './util';
|
@@ -53,7 +52,7 @@ const getLanguages = arg => {
|
|
53
52
|
name: '简体中文'
|
54
53
|
}];
|
55
54
|
};
|
56
|
-
const LocaleContext = /*#__PURE__*/createContext();
|
55
|
+
const LocaleContext = /*#__PURE__*/createContext(null);
|
57
56
|
const {
|
58
57
|
Provider,
|
59
58
|
Consumer
|
@@ -64,13 +63,13 @@ function LocaleProvider({
|
|
64
63
|
fallbackLocale,
|
65
64
|
translations,
|
66
65
|
onLoadingTranslation,
|
67
|
-
languages,
|
66
|
+
languages = [],
|
68
67
|
...rest
|
69
68
|
}) {
|
70
69
|
const langs = getLanguages(languages);
|
71
70
|
// eslint-disable-next-line prefer-const
|
72
71
|
let [currentLocale, setCurrentLocale] = useState(locale || getLocale(langs));
|
73
|
-
const lastCurrentLocale = useRef(fallbackLocale);
|
72
|
+
const lastCurrentLocale = useRef(fallbackLocale || '');
|
74
73
|
const [, setForceUpdate] = useState(0);
|
75
74
|
const changeLocale = newLocale => {
|
76
75
|
setCurrentLocale(newLocale);
|
@@ -97,7 +96,7 @@ function LocaleProvider({
|
|
97
96
|
} catch (err) {
|
98
97
|
console.error(err);
|
99
98
|
}
|
100
|
-
onLoadingTranslation(tmpLocale, langs);
|
99
|
+
onLoadingTranslation?.(tmpLocale, langs);
|
101
100
|
currentLocale = lastCurrentLocale.current;
|
102
101
|
} else {
|
103
102
|
lastCurrentLocale.current = currentLocale;
|
@@ -118,22 +117,4 @@ function useLocaleContext() {
|
|
118
117
|
const context = useContext(LocaleContext);
|
119
118
|
return context;
|
120
119
|
}
|
121
|
-
LocaleProvider.propTypes = {
|
122
|
-
children: PropTypes.any.isRequired,
|
123
|
-
translations: PropTypes.object.isRequired,
|
124
|
-
onLoadingTranslation: PropTypes.func,
|
125
|
-
locale: PropTypes.string,
|
126
|
-
// 会影响 translate(key) 的结果 - 当 key 无效时查找 fallbackLocale 对应的翻译结果
|
127
|
-
fallbackLocale: PropTypes.string,
|
128
|
-
languages: PropTypes.arrayOf(PropTypes.shape({
|
129
|
-
code: PropTypes.string,
|
130
|
-
name: PropTypes.string
|
131
|
-
}))
|
132
|
-
};
|
133
|
-
LocaleProvider.defaultProps = {
|
134
|
-
locale: '',
|
135
|
-
fallbackLocale: '',
|
136
|
-
languages: [],
|
137
|
-
onLoadingTranslation: () => {}
|
138
|
-
};
|
139
120
|
export { LocaleProvider, Consumer as LocaleConsumer, LocaleContext, useLocaleContext, setLocale, getLocale };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.10.
|
3
|
+
"version": "2.10.41",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -64,12 +64,12 @@
|
|
64
64
|
"react": ">=18.2.0",
|
65
65
|
"react-router-dom": ">=6.22.3"
|
66
66
|
},
|
67
|
-
"gitHead": "
|
67
|
+
"gitHead": "d24cb6aab78d9ad2c0e6f4018da00aa3c8cb18fb",
|
68
68
|
"dependencies": {
|
69
69
|
"@arcblock/did-motif": "^1.1.13",
|
70
|
-
"@arcblock/icons": "^2.10.
|
71
|
-
"@arcblock/nft-display": "^2.10.
|
72
|
-
"@arcblock/react-hooks": "^2.10.
|
70
|
+
"@arcblock/icons": "^2.10.41",
|
71
|
+
"@arcblock/nft-display": "^2.10.41",
|
72
|
+
"@arcblock/react-hooks": "^2.10.41",
|
73
73
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
74
74
|
"@fontsource/inter": "^5.0.16",
|
75
75
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
@@ -2,15 +2,14 @@ import React, { isValidElement } from 'react';
|
|
2
2
|
|
3
3
|
import Download from '@iconify-icons/tabler/cloud-download';
|
4
4
|
import { Icon } from '@iconify/react';
|
5
|
-
import { Card, CircularProgress, Stack, Typography } from '@mui/material';
|
5
|
+
import { Card, CardProps, CircularProgress, Stack, Typography } from '@mui/material';
|
6
6
|
import Avatar from '../Avatar';
|
7
7
|
import Button from '../Button';
|
8
8
|
import { useTheme } from '../Theme';
|
9
9
|
import IconText from './components/icon-text';
|
10
10
|
import { formatDownloadCount, strippedString } from './utils';
|
11
11
|
|
12
|
-
export interface IBlockletStore
|
13
|
-
extends Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'title' | 'className'> {
|
12
|
+
export interface IBlockletStore extends CardProps {
|
14
13
|
did?: string;
|
15
14
|
title: string;
|
16
15
|
description?: string;
|
@@ -79,20 +78,15 @@ export default function BlockletStore(props: IBlockletStore) {
|
|
79
78
|
return (
|
80
79
|
<Card
|
81
80
|
variant="outlined"
|
82
|
-
sx={{
|
83
|
-
p: {
|
84
|
-
xs: 2,
|
85
|
-
md: 3,
|
86
|
-
},
|
87
|
-
borderRadius: 2,
|
88
|
-
}}
|
89
81
|
onClick={handleMainClick}
|
90
|
-
{...rest}
|
82
|
+
{...rest}
|
83
|
+
sx={{ p: { xs: 2, md: 3 }, borderRadius: 2, ...rest.sx }}>
|
91
84
|
<Stack flex={1} direction="row" gap={2} alignItems="center" overflow="hidden">
|
92
|
-
<Avatar src={cover} did={did} size={
|
85
|
+
<Avatar src={cover} did={did} size={48} variant="rounded" />
|
93
86
|
<Typography
|
94
87
|
flex={1}
|
95
|
-
|
88
|
+
fontWeight="typography.fontWeightMedium"
|
89
|
+
sx={{ fontSize: 16, textOverflow: 'ellipsis', whiteSpace: 'nowrap', overflow: 'hidden' }}
|
96
90
|
{...titleProps}
|
97
91
|
/>
|
98
92
|
{button ||
|
@@ -106,7 +100,7 @@ export default function BlockletStore(props: IBlockletStore) {
|
|
106
100
|
borderColor: theme.palette.grey[300],
|
107
101
|
borderRadius: 8,
|
108
102
|
fontSize: 13,
|
109
|
-
fontWeight:
|
103
|
+
fontWeight: theme.typography.fontWeightMedium,
|
110
104
|
}}
|
111
105
|
onClick={handleButtonClick}>
|
112
106
|
{buttonLoading && <CircularProgress size={15} style={{ marginRight: 3, color: 'inherit' }} />}
|
package/src/Center/index.js
CHANGED
@@ -3,8 +3,9 @@ import PropTypes from 'prop-types';
|
|
3
3
|
import { styled } from '../Theme';
|
4
4
|
|
5
5
|
/**
|
6
|
-
*
|
7
|
-
* @param {
|
6
|
+
* @param {Object} props 属性
|
7
|
+
* @param {*} props.children 子元素
|
8
|
+
* @param {'screen'|'parent'} [props.relative='screen'] 容器相对尺寸,默认相对屏幕(screen),可设置为父容器(parent)
|
8
9
|
* @returns react component element
|
9
10
|
*/
|
10
11
|
export default function Center({ children, relative }) {
|
@@ -1,7 +1,6 @@
|
|
1
1
|
/* eslint-disable no-prototype-builtins */
|
2
|
-
import { createContext, useState, useEffect, useContext, useRef, useCallback } from 'react';
|
2
|
+
import React, { createContext, useState, useEffect, useContext, useRef, useCallback, ReactNode } from 'react';
|
3
3
|
import get from 'lodash/get';
|
4
|
-
import PropTypes from 'prop-types';
|
5
4
|
import Cookie from 'js-cookie';
|
6
5
|
|
7
6
|
import browserLang from './browser-lang';
|
@@ -12,7 +11,10 @@ import { getCookieOptions } from '../Util';
|
|
12
11
|
const cookieName = 'nf_lang';
|
13
12
|
|
14
13
|
// 跨应用传递多语言选择的方式是在 query string 中添加 locale 参数,LocaleSelector 要高优先级遵守这个参数
|
15
|
-
const getLocaleFromSearchParams = (
|
14
|
+
const getLocaleFromSearchParams = (
|
15
|
+
languages: { code: string }[],
|
16
|
+
url: string = window.location.href
|
17
|
+
): string | null => {
|
16
18
|
const locale = new URL(url).searchParams.get('locale');
|
17
19
|
if (languages.find((x) => x.code === locale)) {
|
18
20
|
return locale;
|
@@ -20,7 +22,7 @@ const getLocaleFromSearchParams = (languages, url = window.location.href) => {
|
|
20
22
|
return null;
|
21
23
|
};
|
22
24
|
|
23
|
-
const setLocaleParam = (locale, url = window.location.href) => {
|
25
|
+
const setLocaleParam = (locale: string, url: string = window.location.href) => {
|
24
26
|
const urlObj = new URL(url);
|
25
27
|
const hasLocaleParam = urlObj.searchParams.has('locale');
|
26
28
|
if (hasLocaleParam) {
|
@@ -29,7 +31,7 @@ const setLocaleParam = (locale, url = window.location.href) => {
|
|
29
31
|
}
|
30
32
|
};
|
31
33
|
|
32
|
-
const getLocale = (languages = []) => {
|
34
|
+
const getLocale = (languages: { code: string }[] = []): string => {
|
33
35
|
const langParams = {
|
34
36
|
languages: languages.map((item) => item.code),
|
35
37
|
// 取 languages 首个元素的 code 值, 如果不存在则取 'en'
|
@@ -38,12 +40,12 @@ const getLocale = (languages = []) => {
|
|
38
40
|
return getLocaleFromSearchParams(languages) || Cookie.get(cookieName) || browserLang(langParams);
|
39
41
|
};
|
40
42
|
|
41
|
-
const setLocale = (locale) => {
|
43
|
+
const setLocale = (locale: string) => {
|
42
44
|
Cookie.set(cookieName, locale, getCookieOptions());
|
43
45
|
setLocaleParam(locale);
|
44
46
|
};
|
45
47
|
|
46
|
-
const getLanguages = (arg) => {
|
48
|
+
const getLanguages = (arg?: { code: string; name: string }[]): { code: string; name: string }[] => {
|
47
49
|
const env = get(window, 'blocklet.languages');
|
48
50
|
if (Array.isArray(env) && env.length) {
|
49
51
|
return env;
|
@@ -59,16 +61,35 @@ const getLanguages = (arg) => {
|
|
59
61
|
];
|
60
62
|
};
|
61
63
|
|
62
|
-
|
64
|
+
interface LocaleProviderProps {
|
65
|
+
children: ReactNode;
|
66
|
+
locale?: string;
|
67
|
+
fallbackLocale?: string;
|
68
|
+
translations: Record<string, any>;
|
69
|
+
// eslint-disable-next-line no-unused-vars
|
70
|
+
onLoadingTranslation?: (locale: string, languages: { code: string }[]) => void;
|
71
|
+
languages?: { code: string; name: string }[];
|
72
|
+
}
|
73
|
+
|
74
|
+
const LocaleContext = createContext<any>(null);
|
63
75
|
const { Provider, Consumer } = LocaleContext;
|
64
|
-
|
76
|
+
|
77
|
+
function LocaleProvider({
|
78
|
+
children,
|
79
|
+
locale,
|
80
|
+
fallbackLocale,
|
81
|
+
translations,
|
82
|
+
onLoadingTranslation,
|
83
|
+
languages = [],
|
84
|
+
...rest
|
85
|
+
}: LocaleProviderProps) {
|
65
86
|
const langs = getLanguages(languages);
|
66
87
|
// eslint-disable-next-line prefer-const
|
67
|
-
let [currentLocale, setCurrentLocale] = useState(locale || getLocale(langs));
|
68
|
-
const lastCurrentLocale = useRef(fallbackLocale);
|
88
|
+
let [currentLocale, setCurrentLocale] = useState<string>(locale || getLocale(langs));
|
89
|
+
const lastCurrentLocale = useRef<string>(fallbackLocale || '');
|
69
90
|
const [, setForceUpdate] = useState(0);
|
70
91
|
|
71
|
-
const changeLocale = (newLocale) => {
|
92
|
+
const changeLocale = (newLocale: string) => {
|
72
93
|
setCurrentLocale(newLocale);
|
73
94
|
setLocale(newLocale);
|
74
95
|
};
|
@@ -95,14 +116,14 @@ function LocaleProvider({ children, locale, fallbackLocale, translations, onLoad
|
|
95
116
|
console.error(err);
|
96
117
|
}
|
97
118
|
|
98
|
-
onLoadingTranslation(tmpLocale, langs);
|
119
|
+
onLoadingTranslation?.(tmpLocale, langs);
|
99
120
|
currentLocale = lastCurrentLocale.current;
|
100
121
|
} else {
|
101
122
|
lastCurrentLocale.current = currentLocale;
|
102
123
|
}
|
103
124
|
|
104
125
|
const t = useCallback(
|
105
|
-
(key, data) => translate(translations, key, currentLocale, fallbackLocale, data),
|
126
|
+
(key: string, data?: any) => translate(translations, key, currentLocale, fallbackLocale, data),
|
106
127
|
[translations, currentLocale, fallbackLocale]
|
107
128
|
);
|
108
129
|
|
@@ -114,21 +135,4 @@ function useLocaleContext() {
|
|
114
135
|
return context;
|
115
136
|
}
|
116
137
|
|
117
|
-
LocaleProvider.propTypes = {
|
118
|
-
children: PropTypes.any.isRequired,
|
119
|
-
translations: PropTypes.object.isRequired,
|
120
|
-
onLoadingTranslation: PropTypes.func,
|
121
|
-
locale: PropTypes.string,
|
122
|
-
// 会影响 translate(key) 的结果 - 当 key 无效时查找 fallbackLocale 对应的翻译结果
|
123
|
-
fallbackLocale: PropTypes.string,
|
124
|
-
languages: PropTypes.arrayOf(PropTypes.shape({ code: PropTypes.string, name: PropTypes.string })),
|
125
|
-
};
|
126
|
-
|
127
|
-
LocaleProvider.defaultProps = {
|
128
|
-
locale: '',
|
129
|
-
fallbackLocale: '',
|
130
|
-
languages: [],
|
131
|
-
onLoadingTranslation: () => {},
|
132
|
-
};
|
133
|
-
|
134
138
|
export { LocaleProvider, Consumer as LocaleConsumer, LocaleContext, useLocaleContext, setLocale, getLocale };
|