@arcblock/ux 2.13.7 → 2.13.8
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/UserCard/Cards/avatar-only.d.ts +3 -2
- package/lib/UserCard/Cards/basic-info.d.ts +3 -2
- package/lib/UserCard/Cards/basic-info.js +12 -6
- package/lib/UserCard/Cards/index.d.ts +3 -2
- package/lib/UserCard/Cards/name-only.d.ts +4 -2
- package/lib/UserCard/Cards/name-only.js +3 -2
- package/lib/UserCard/Container/dialog.js +1 -1
- package/lib/UserCard/Content/basic.d.ts +2 -1
- package/lib/UserCard/Content/basic.js +195 -67
- package/lib/UserCard/Content/minimal.d.ts +2 -2
- package/lib/UserCard/Content/minimal.js +2 -0
- package/lib/UserCard/Content/tooltip-avatar.d.ts +4 -4
- package/lib/UserCard/Content/tooltip-avatar.js +4 -3
- package/lib/UserCard/components.d.ts +2 -2
- package/lib/UserCard/components.js +9 -3
- package/lib/UserCard/index.js +36 -4
- package/lib/UserCard/types.d.ts +7 -4
- package/lib/UserCard/utils.d.ts +2 -0
- package/lib/UserCard/utils.js +33 -0
- package/package.json +6 -6
- package/src/UserCard/Cards/avatar-only.tsx +3 -2
- package/src/UserCard/Cards/basic-info.tsx +17 -5
- package/src/UserCard/Cards/index.tsx +3 -2
- package/src/UserCard/Cards/name-only.tsx +4 -4
- package/src/UserCard/Container/dialog.tsx +1 -1
- package/src/UserCard/Content/basic.tsx +191 -57
- package/src/UserCard/Content/minimal.tsx +4 -3
- package/src/UserCard/Content/tooltip-avatar.tsx +10 -5
- package/src/UserCard/components.tsx +17 -7
- package/src/UserCard/index.tsx +41 -3
- package/src/UserCard/types.ts +11 -4
- package/src/UserCard/utils.ts +33 -0
package/src/UserCard/types.ts
CHANGED
@@ -64,7 +64,6 @@ export type UserAddress = {
|
|
64
64
|
};
|
65
65
|
|
66
66
|
export type User = UserPublicInfo & {
|
67
|
-
role: string;
|
68
67
|
email?: string;
|
69
68
|
phone?: string;
|
70
69
|
sourceProvider?: string;
|
@@ -76,7 +75,7 @@ export type User = UserPublicInfo & {
|
|
76
75
|
didSpace?: Record<string, any>;
|
77
76
|
connectedAccounts?: any[];
|
78
77
|
locale?: string;
|
79
|
-
url
|
78
|
+
url?: string;
|
80
79
|
inviter?: string;
|
81
80
|
emailVerified?: boolean;
|
82
81
|
phoneVerified?: boolean;
|
@@ -109,7 +108,8 @@ export enum InfoType {
|
|
109
108
|
|
110
109
|
// 定义UserCard属性接口
|
111
110
|
export interface UserCardProps {
|
112
|
-
user
|
111
|
+
user?: User;
|
112
|
+
did?: string;
|
113
113
|
cardType?: CardType;
|
114
114
|
infoType?: InfoType;
|
115
115
|
avatarSize?: number;
|
@@ -121,7 +121,7 @@ export interface UserCardProps {
|
|
121
121
|
popupAvatarProps?: Partial<AvatarProps>;
|
122
122
|
|
123
123
|
// 弹出层相关属性
|
124
|
-
tooltipProps?:
|
124
|
+
tooltipProps?: Partial<TooltipProps>;
|
125
125
|
|
126
126
|
// 样式相关属性
|
127
127
|
sx?: SxProps<Theme>;
|
@@ -131,10 +131,17 @@ export interface UserCardProps {
|
|
131
131
|
shortenLabelProps?: Partial<ShortenLabelProps>;
|
132
132
|
popupShortenLabelProps?: Partial<ShortenLabelProps>;
|
133
133
|
|
134
|
+
// 自定义渲染字段
|
135
|
+
renderFields?: string[];
|
136
|
+
popupRenderFields?: string[];
|
137
|
+
|
134
138
|
// 右上角内容相关属性
|
135
139
|
renderTopRightContent?: () => React.ReactNode;
|
136
140
|
topRightMaxWidth?: number;
|
137
141
|
|
138
142
|
// 自定义内容渲染函数
|
139
143
|
renderCustomContent?: () => React.ReactNode;
|
144
|
+
|
145
|
+
// 头像点击事件
|
146
|
+
onAvatarClick?: (user: User, e?: React.MouseEvent<HTMLDivElement>) => void;
|
140
147
|
}
|
package/src/UserCard/utils.ts
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
import { toTypeInfo } from '@arcblock/did';
|
2
|
+
import { types } from '@ocap/mcrypto';
|
3
|
+
import { BlockletSDK } from '@blocklet/js-sdk';
|
1
4
|
import { User } from './types';
|
2
5
|
|
6
|
+
let client: BlockletSDK | null = null;
|
7
|
+
try {
|
8
|
+
client = new BlockletSDK();
|
9
|
+
} catch (error) {
|
10
|
+
console.error('Failed to initialize BlockletSDK:', error);
|
11
|
+
client = null;
|
12
|
+
}
|
13
|
+
|
3
14
|
// 创建仅显示名称首字母的头像
|
4
15
|
// eslint-disable-next-line import/prefer-default-export
|
5
16
|
export function createNameOnlyAvatar(user: User) {
|
@@ -20,3 +31,25 @@ export function createNameOnlyAvatar(user: User) {
|
|
20
31
|
|
21
32
|
return content;
|
22
33
|
}
|
34
|
+
|
35
|
+
export function isUserDid(did: string) {
|
36
|
+
if (!did || typeof did !== 'string') return false;
|
37
|
+
try {
|
38
|
+
const didInfo = toTypeInfo(did);
|
39
|
+
return didInfo.role !== undefined && didInfo.role !== types.RoleType.ROLE_APPLICATION;
|
40
|
+
} catch (error) {
|
41
|
+
console.error('Failed to check if did is user did:', error);
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
export async function getUserByDid(did: string): Promise<User | null> {
|
47
|
+
if (!client) return null;
|
48
|
+
try {
|
49
|
+
const user = await client.user.getUserPublicInfo({ did });
|
50
|
+
return user as User;
|
51
|
+
} catch (error) {
|
52
|
+
console.error('Failed to get user by did:', error);
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
}
|