@arcblock/ux 2.10.43 → 2.10.44
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/Address/compact-text.d.ts +3 -1
- package/lib/Address/compact-text.js +2 -1
- package/lib/Address/did-address.d.ts +22 -3
- package/lib/Address/did-address.js +37 -59
- package/lib/Address/index.d.ts +4 -13
- package/lib/Address/index.js +10 -13
- package/lib/Address/responsive-did-address.d.ts +8 -22
- package/lib/Address/responsive-did-address.js +15 -19
- package/lib/BlockletV2/blocklet.js +1 -0
- package/lib/BlockletV2/components/icon-text.d.ts +3 -1
- package/lib/BlockletV2/components/icon-text.js +4 -3
- package/lib/DID/index.d.ts +25 -22
- package/lib/DID/index.js +56 -60
- package/lib/type.d.ts +1 -0
- package/package.json +5 -5
- package/src/Address/compact-text.jsx +2 -1
- package/src/Address/did-address.tsx +215 -0
- package/src/Address/index.tsx +18 -0
- package/src/Address/responsive-did-address.tsx +90 -0
- package/src/BlockletV2/blocklet.tsx +3 -1
- package/src/BlockletV2/components/icon-text.tsx +8 -2
- package/src/DID/{index.jsx → index.tsx} +90 -58
- package/src/type.d.ts +1 -0
- package/src/Address/did-address.jsx +0 -220
- package/src/Address/index.jsx +0 -18
- package/src/Address/responsive-did-address.jsx +0 -79
@@ -1,220 +0,0 @@
|
|
1
|
-
import React, { useRef, useState, forwardRef } from 'react';
|
2
|
-
import PropTypes from 'prop-types';
|
3
|
-
import '@fontsource/ubuntu-mono/400.css';
|
4
|
-
import { green } from '@mui/material/colors';
|
5
|
-
import { Tooltip, Box } from '@mui/material';
|
6
|
-
import copy from 'copy-to-clipboard';
|
7
|
-
import { ContentCopy as CopyIcon, Check as CheckIcon } from '@mui/icons-material';
|
8
|
-
import noop from 'lodash/noop';
|
9
|
-
|
10
|
-
import { styled } from '../Theme';
|
11
|
-
import { getFontSize } from '../Util';
|
12
|
-
import CompactText from './compact-text';
|
13
|
-
|
14
|
-
const translations = {
|
15
|
-
en: {
|
16
|
-
copy: 'Click To Copy',
|
17
|
-
copied: 'Copied!',
|
18
|
-
},
|
19
|
-
zh: {
|
20
|
-
copy: '点击复制',
|
21
|
-
copied: '已复制!',
|
22
|
-
},
|
23
|
-
};
|
24
|
-
|
25
|
-
/**
|
26
|
-
* DidAddress 组件 (新版设计)
|
27
|
-
*
|
28
|
-
* - 样式调整
|
29
|
-
* - click-to-copy 调整
|
30
|
-
* - 长文本截断处理 (Ellipsis)
|
31
|
-
* - 支持 inline 或 block 的显示方式
|
32
|
-
* - 支持紧凑模式, 该模式下:
|
33
|
-
* - 占用宽度较小, 因此不考虑水平空间不够用的情况, 且忽略末尾省略号
|
34
|
-
* - 对于多层元素结构的 children, 保持元素结构, 将最内层 text 替换为 CompactText 组件
|
35
|
-
* - 为保证 copy 功能正常工作, 原 children 始终渲染, 但在紧凑式下会隐藏
|
36
|
-
* - 可配合 useMediaQuery 使用
|
37
|
-
*/
|
38
|
-
const DidAddress = forwardRef(
|
39
|
-
(
|
40
|
-
{
|
41
|
-
component,
|
42
|
-
size,
|
43
|
-
copyable,
|
44
|
-
content,
|
45
|
-
children,
|
46
|
-
prepend,
|
47
|
-
append,
|
48
|
-
compact,
|
49
|
-
startChars,
|
50
|
-
endChars,
|
51
|
-
locale,
|
52
|
-
showCopyButtonInTooltip,
|
53
|
-
...rest
|
54
|
-
},
|
55
|
-
ref
|
56
|
-
) => {
|
57
|
-
if (!translations[locale]) {
|
58
|
-
// eslint-disable-next-line no-param-reassign
|
59
|
-
locale = 'en';
|
60
|
-
}
|
61
|
-
|
62
|
-
const [copied, setCopied] = useState(false);
|
63
|
-
const textRef = useRef();
|
64
|
-
|
65
|
-
const onCopy = (e) => {
|
66
|
-
e.stopPropagation();
|
67
|
-
e.preventDefault();
|
68
|
-
copy(content || textRef.current.textContent);
|
69
|
-
setCopied(true);
|
70
|
-
// 恢复 copied 状态
|
71
|
-
setTimeout(() => {
|
72
|
-
setCopied(false);
|
73
|
-
}, 1500);
|
74
|
-
};
|
75
|
-
|
76
|
-
let copyElement = null;
|
77
|
-
if (copyable) {
|
78
|
-
copyElement = (
|
79
|
-
<span className="did-address-copy-wrapper" title={copied ? '' : translations[locale].copy}>
|
80
|
-
{copied ? (
|
81
|
-
<Tooltip title={translations[locale].copied} placement="bottom" arrow open={copied}>
|
82
|
-
<CheckIcon className="did-address-copy" style={{ color: green[500] }} />
|
83
|
-
</Tooltip>
|
84
|
-
) : (
|
85
|
-
/* title prop 直接加在 icon 上不生效 */
|
86
|
-
<CopyIcon className="did-address-copy" onClick={onCopy} />
|
87
|
-
)}
|
88
|
-
</span>
|
89
|
-
);
|
90
|
-
}
|
91
|
-
|
92
|
-
return (
|
93
|
-
<Root as={component} size={size} {...rest} ref={ref}>
|
94
|
-
{prepend}
|
95
|
-
<Box sx={{ display: 'none' }} ref={textRef}>
|
96
|
-
{children}
|
97
|
-
</Box>
|
98
|
-
{/* 注意: 该元素必须渲染(可以隐藏), 以便 compact 模式下复制的文本是完整的 */}
|
99
|
-
<Tooltip title={copyable ? '' : translations[locale].copied} placement="bottom" arrow open={copied}>
|
100
|
-
{compact ? (
|
101
|
-
<Box
|
102
|
-
component="span"
|
103
|
-
className="did-address-text"
|
104
|
-
sx={{
|
105
|
-
cursor: copyable ? 'unset' : 'pointer',
|
106
|
-
}}
|
107
|
-
onDoubleClick={copyable ? noop : onCopy}>
|
108
|
-
<CompactText
|
109
|
-
startChars={startChars}
|
110
|
-
endChars={endChars}
|
111
|
-
showCopyButtonInTooltip={showCopyButtonInTooltip}>
|
112
|
-
{children}
|
113
|
-
</CompactText>
|
114
|
-
</Box>
|
115
|
-
) : (
|
116
|
-
<Box
|
117
|
-
component="span"
|
118
|
-
className="did-address-text did-address-truncate"
|
119
|
-
sx={{
|
120
|
-
display: compact ? 'none' : 'inline',
|
121
|
-
cursor: copyable ? 'unset' : 'pointer',
|
122
|
-
}}
|
123
|
-
onDoubleClick={copyable ? noop : onCopy}>
|
124
|
-
{children}
|
125
|
-
</Box>
|
126
|
-
)}
|
127
|
-
</Tooltip>
|
128
|
-
{copyElement}
|
129
|
-
{append}
|
130
|
-
</Root>
|
131
|
-
);
|
132
|
-
}
|
133
|
-
);
|
134
|
-
|
135
|
-
export default DidAddress;
|
136
|
-
|
137
|
-
DidAddress.propTypes = {
|
138
|
-
component: PropTypes.string,
|
139
|
-
size: PropTypes.number,
|
140
|
-
copyable: PropTypes.bool,
|
141
|
-
// compact mode 下, hover 时会在 tooltip 中显示完整地址, showCopyButtonInTooltip = true 时会在完整地址后显示一个复制按钮
|
142
|
-
showCopyButtonInTooltip: PropTypes.bool,
|
143
|
-
children: PropTypes.any,
|
144
|
-
content: PropTypes.string,
|
145
|
-
inline: PropTypes.bool,
|
146
|
-
prepend: PropTypes.any,
|
147
|
-
append: PropTypes.any,
|
148
|
-
// 紧凑模式
|
149
|
-
compact: PropTypes.bool,
|
150
|
-
startChars: PropTypes.number,
|
151
|
-
endChars: PropTypes.number,
|
152
|
-
locale: PropTypes.oneOf(['en', 'zh']),
|
153
|
-
};
|
154
|
-
|
155
|
-
DidAddress.defaultProps = {
|
156
|
-
component: 'span',
|
157
|
-
size: 0,
|
158
|
-
copyable: true,
|
159
|
-
showCopyButtonInTooltip: false,
|
160
|
-
children: null,
|
161
|
-
content: '',
|
162
|
-
inline: false,
|
163
|
-
prepend: null,
|
164
|
-
append: null,
|
165
|
-
compact: false,
|
166
|
-
startChars: 6,
|
167
|
-
endChars: 6,
|
168
|
-
locale: 'en',
|
169
|
-
};
|
170
|
-
|
171
|
-
const Root = styled(Box, { shouldForwardProp: (prop) => prop !== 'inline' })`
|
172
|
-
font-family: 'Ubuntu Mono', monospace;
|
173
|
-
&& {
|
174
|
-
display: ${({ inline }) => (inline ? 'inline-flex' : 'flex')};
|
175
|
-
align-items: center;
|
176
|
-
max-width: 100%;
|
177
|
-
overflow: hidden;
|
178
|
-
color: #ccc;
|
179
|
-
font-size: ${(props) => getFontSize(props.size)};
|
180
|
-
font-weight: 400;
|
181
|
-
|
182
|
-
svg {
|
183
|
-
fill: currentColor;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
.did-address-text {
|
188
|
-
color: #666;
|
189
|
-
}
|
190
|
-
/* truncate string with ellipsis */
|
191
|
-
.did-address-truncate {
|
192
|
-
white-space: nowrap;
|
193
|
-
overflow: hidden;
|
194
|
-
text-overflow: ellipsis;
|
195
|
-
}
|
196
|
-
|
197
|
-
.did-address-copy-wrapper {
|
198
|
-
display: flex;
|
199
|
-
justify-content: center;
|
200
|
-
align-items: center;
|
201
|
-
width: 1em;
|
202
|
-
height: 1em;
|
203
|
-
margin-left: 8px;
|
204
|
-
}
|
205
|
-
.did-address-copy {
|
206
|
-
flex: 0 0 auto;
|
207
|
-
font-size: 1em;
|
208
|
-
color: #999;
|
209
|
-
cursor: pointer;
|
210
|
-
}
|
211
|
-
|
212
|
-
/* link */
|
213
|
-
a {
|
214
|
-
color: #666;
|
215
|
-
}
|
216
|
-
&:hover a {
|
217
|
-
color: #222;
|
218
|
-
text-decoration: underline;
|
219
|
-
}
|
220
|
-
`;
|
package/src/Address/index.jsx
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
import PropTypes from 'prop-types';
|
2
|
-
import DidAddress from './did-address';
|
3
|
-
import ResponsiveDidAddress from './responsive-did-address';
|
4
|
-
|
5
|
-
export default function DidAddressWrapper({ responsive, ...rest }) {
|
6
|
-
if (responsive) {
|
7
|
-
return <ResponsiveDidAddress {...rest} />;
|
8
|
-
}
|
9
|
-
return <DidAddress {...rest} />;
|
10
|
-
}
|
11
|
-
|
12
|
-
DidAddressWrapper.propTypes = {
|
13
|
-
responsive: PropTypes.bool,
|
14
|
-
};
|
15
|
-
|
16
|
-
DidAddressWrapper.defaultProps = {
|
17
|
-
responsive: true,
|
18
|
-
};
|
@@ -1,79 +0,0 @@
|
|
1
|
-
import { useState, createRef, useEffect, useRef } from 'react';
|
2
|
-
import PropTypes from 'prop-types';
|
3
|
-
import { useSize } from 'ahooks';
|
4
|
-
import { styled } from '../Theme';
|
5
|
-
|
6
|
-
import DidAddress from './did-address';
|
7
|
-
|
8
|
-
/**
|
9
|
-
* 根据父容器宽度自动切换 compact 模式
|
10
|
-
*
|
11
|
-
* 实现逻辑:
|
12
|
-
* - DidAddress 外层包裹一个容器, 其宽度自动撑满父容器宽度 (即这个容器需要是块级元素或 100% 宽的 inline-block)
|
13
|
-
* - DidAddress 本身以 inline 形式渲染 (方便探测 did-address 的 full-width)
|
14
|
-
* - 组件 mounted 时记录 did address 的 full-width (非 compact 模式的宽度)
|
15
|
-
* - 监听容器宽度变化, 当容器宽度变化时, 对比容器宽度和 did address full-width, => 切换 compact 模式
|
16
|
-
* - TODO: 初始化时, 在确定是否应该以 compact 模式渲染前, 隐藏显示, 避免闪烁问题
|
17
|
-
*/
|
18
|
-
export default function ResponsiveDidAddress({ style, className, component, ...rest }) {
|
19
|
-
const [compact, setCompact] = useState(false);
|
20
|
-
// did address 完整显示时的宽度
|
21
|
-
const [addressFullWidth, setAddressFullWidth] = useState(null);
|
22
|
-
const containerRef = useRef(null);
|
23
|
-
const size = useSize(containerRef);
|
24
|
-
const containerWidth = size?.width || 0;
|
25
|
-
const ref = createRef();
|
26
|
-
// 存储完整显示时 address 组件的宽度
|
27
|
-
useEffect(() => {
|
28
|
-
if (!compact && addressFullWidth === null) {
|
29
|
-
setAddressFullWidth(ref.current.offsetWidth);
|
30
|
-
}
|
31
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
32
|
-
}, []);
|
33
|
-
|
34
|
-
useEffect(() => {
|
35
|
-
if (containerWidth && addressFullWidth) {
|
36
|
-
setCompact(containerWidth < addressFullWidth);
|
37
|
-
}
|
38
|
-
}, [containerWidth, addressFullWidth]);
|
39
|
-
return (
|
40
|
-
<Root as={component} ref={containerRef} style={style} className={className}>
|
41
|
-
<StyledDidAddress {...rest} component={component} inline compact={compact} ref={ref} />
|
42
|
-
</Root>
|
43
|
-
);
|
44
|
-
}
|
45
|
-
|
46
|
-
ResponsiveDidAddress.propTypes = {
|
47
|
-
style: PropTypes.object,
|
48
|
-
className: PropTypes.string,
|
49
|
-
component: PropTypes.string,
|
50
|
-
};
|
51
|
-
|
52
|
-
ResponsiveDidAddress.defaultProps = {
|
53
|
-
style: {},
|
54
|
-
className: '',
|
55
|
-
component: 'span',
|
56
|
-
};
|
57
|
-
|
58
|
-
const Root = styled('div')`
|
59
|
-
display: block;
|
60
|
-
overflow: hidden;
|
61
|
-
${({ inline }) =>
|
62
|
-
inline &&
|
63
|
-
`
|
64
|
-
display: inline-block;
|
65
|
-
width: 100%;
|
66
|
-
`}
|
67
|
-
`;
|
68
|
-
|
69
|
-
const StyledDidAddress = styled(DidAddress)`
|
70
|
-
&& {
|
71
|
-
max-width: none;
|
72
|
-
}
|
73
|
-
.did-address-text {
|
74
|
-
/* 禁止文本 Ellipsis/截断, 以便测量真实的宽度 */
|
75
|
-
white-space: nowrap;
|
76
|
-
overflow: visible;
|
77
|
-
text-overflow: unset;
|
78
|
-
}
|
79
|
-
`;
|