@blocklet/ui-react 3.4.14 → 3.5.0

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.
Files changed (256) hide show
  1. package/lib/common/org-switch/use-org.d.ts +4 -4
  2. package/lib/common/ws.d.ts +22 -1
  3. package/package.json +10 -7
  4. package/.aigne/doc-smith/.local/afs-storage.sqlite3 +0 -0
  5. package/.aigne/doc-smith/config.yaml +0 -78
  6. package/.aigne/doc-smith/history.yaml +0 -14
  7. package/.aigne/doc-smith/media-description.yaml +0 -11
  8. package/.aigne/doc-smith/output/structure-plan.json +0 -255
  9. package/.aigne/doc-smith/translation-cache.yaml +0 -11
  10. package/.aigne/doc-smith/upload-cache.yaml +0 -528
  11. package/build.config.ts +0 -24
  12. package/docs/_sidebar.md +0 -19
  13. package/docs/assets/diagram/component-installer-diagram-0.ja.jpg +0 -0
  14. package/docs/assets/diagram/component-installer-diagram-0.jpg +0 -0
  15. package/docs/assets/diagram/component-installer-diagram-0.zh-TW.jpg +0 -0
  16. package/docs/assets/diagram/component-installer-diagram-0.zh.jpg +0 -0
  17. package/docs/assets/diagram/component-management-diagram-0.ja.jpg +0 -0
  18. package/docs/assets/diagram/component-management-diagram-0.jpg +0 -0
  19. package/docs/assets/diagram/component-management-diagram-0.zh-TW.jpg +0 -0
  20. package/docs/assets/diagram/component-management-diagram-0.zh.jpg +0 -0
  21. package/docs/assets/diagram/core-concepts-diagram-0.ja.jpg +0 -0
  22. package/docs/assets/diagram/core-concepts-diagram-0.jpg +0 -0
  23. package/docs/assets/diagram/core-concepts-diagram-0.zh-TW.jpg +0 -0
  24. package/docs/assets/diagram/core-concepts-diagram-0.zh.jpg +0 -0
  25. package/docs/assets/diagram/dashboard-diagram-0.ja.jpg +0 -0
  26. package/docs/assets/diagram/dashboard-diagram-0.jpg +0 -0
  27. package/docs/assets/diagram/dashboard-diagram-0.zh-TW.jpg +0 -0
  28. package/docs/assets/diagram/dashboard-diagram-0.zh.jpg +0 -0
  29. package/docs/assets/diagram/header-diagram-0.ja.jpg +0 -0
  30. package/docs/assets/diagram/header-diagram-0.jpg +0 -0
  31. package/docs/assets/diagram/header-diagram-0.zh-TW.jpg +0 -0
  32. package/docs/assets/diagram/header-diagram-0.zh.jpg +0 -0
  33. package/docs/assets/diagram/layout-diagram-0.ja.jpg +0 -0
  34. package/docs/assets/diagram/layout-diagram-0.jpg +0 -0
  35. package/docs/assets/diagram/layout-diagram-0.zh-TW.jpg +0 -0
  36. package/docs/assets/diagram/layout-diagram-0.zh.jpg +0 -0
  37. package/docs/assets/diagram/notifications-diagram-0.ja.jpg +0 -0
  38. package/docs/assets/diagram/notifications-diagram-0.jpg +0 -0
  39. package/docs/assets/diagram/notifications-diagram-0.zh-TW.jpg +0 -0
  40. package/docs/assets/diagram/notifications-diagram-0.zh.jpg +0 -0
  41. package/docs/assets/diagram/overview-diagram-0.ja.jpg +0 -0
  42. package/docs/assets/diagram/overview-diagram-0.jpg +0 -0
  43. package/docs/assets/diagram/overview-diagram-0.zh-TW.jpg +0 -0
  44. package/docs/assets/diagram/overview-diagram-0.zh.jpg +0 -0
  45. package/docs/assets/diagram/user-center-diagram-0.ja.jpg +0 -0
  46. package/docs/assets/diagram/user-center-diagram-0.jpg +0 -0
  47. package/docs/assets/diagram/user-center-diagram-0.zh-TW.jpg +0 -0
  48. package/docs/assets/diagram/user-center-diagram-0.zh.jpg +0 -0
  49. package/docs/assets/diagram/user-management-diagram-0.ja.jpg +0 -0
  50. package/docs/assets/diagram/user-management-diagram-0.jpg +0 -0
  51. package/docs/assets/diagram/user-management-diagram-0.zh-TW.jpg +0 -0
  52. package/docs/assets/diagram/user-management-diagram-0.zh.jpg +0 -0
  53. package/docs/assets/diagram/user-sessions-diagram-0.ja.jpg +0 -0
  54. package/docs/assets/diagram/user-sessions-diagram-0.jpg +0 -0
  55. package/docs/assets/diagram/user-sessions-diagram-0.zh-TW.jpg +0 -0
  56. package/docs/assets/diagram/user-sessions-diagram-0.zh.jpg +0 -0
  57. package/docs/components-component-management-blocklet-studio.ja.md +0 -194
  58. package/docs/components-component-management-blocklet-studio.md +0 -194
  59. package/docs/components-component-management-blocklet-studio.zh-TW.md +0 -194
  60. package/docs/components-component-management-blocklet-studio.zh.md +0 -194
  61. package/docs/components-component-management-component-installer.ja.md +0 -182
  62. package/docs/components-component-management-component-installer.md +0 -182
  63. package/docs/components-component-management-component-installer.zh-TW.md +0 -182
  64. package/docs/components-component-management-component-installer.zh.md +0 -182
  65. package/docs/components-component-management.ja.md +0 -30
  66. package/docs/components-component-management.md +0 -30
  67. package/docs/components-component-management.zh-TW.md +0 -30
  68. package/docs/components-component-management.zh.md +0 -30
  69. package/docs/components-layout-dashboard.ja.md +0 -185
  70. package/docs/components-layout-dashboard.md +0 -187
  71. package/docs/components-layout-dashboard.zh-TW.md +0 -185
  72. package/docs/components-layout-dashboard.zh.md +0 -185
  73. package/docs/components-layout-footer.ja.md +0 -165
  74. package/docs/components-layout-footer.md +0 -165
  75. package/docs/components-layout-footer.zh-TW.md +0 -165
  76. package/docs/components-layout-footer.zh.md +0 -165
  77. package/docs/components-layout-header.ja.md +0 -183
  78. package/docs/components-layout-header.md +0 -183
  79. package/docs/components-layout-header.zh-TW.md +0 -183
  80. package/docs/components-layout-header.zh.md +0 -183
  81. package/docs/components-layout.ja.md +0 -31
  82. package/docs/components-layout.md +0 -31
  83. package/docs/components-layout.zh-TW.md +0 -31
  84. package/docs/components-layout.zh.md +0 -31
  85. package/docs/components-notifications.ja.md +0 -125
  86. package/docs/components-notifications.md +0 -125
  87. package/docs/components-notifications.zh-TW.md +0 -125
  88. package/docs/components-notifications.zh.md +0 -125
  89. package/docs/components-user-management-user-center.ja.md +0 -148
  90. package/docs/components-user-management-user-center.md +0 -147
  91. package/docs/components-user-management-user-center.zh-TW.md +0 -148
  92. package/docs/components-user-management-user-center.zh.md +0 -148
  93. package/docs/components-user-management-user-sessions.ja.md +0 -121
  94. package/docs/components-user-management-user-sessions.md +0 -123
  95. package/docs/components-user-management-user-sessions.zh-TW.md +0 -121
  96. package/docs/components-user-management-user-sessions.zh.md +0 -121
  97. package/docs/components-user-management.ja.md +0 -49
  98. package/docs/components-user-management.md +0 -51
  99. package/docs/components-user-management.zh-TW.md +0 -49
  100. package/docs/components-user-management.zh.md +0 -49
  101. package/docs/components-utilities-icon.ja.md +0 -106
  102. package/docs/components-utilities-icon.md +0 -106
  103. package/docs/components-utilities-icon.zh-TW.md +0 -106
  104. package/docs/components-utilities-icon.zh.md +0 -106
  105. package/docs/components-utilities.ja.md +0 -136
  106. package/docs/components-utilities.md +0 -136
  107. package/docs/components-utilities.zh-TW.md +0 -136
  108. package/docs/components-utilities.zh.md +0 -136
  109. package/docs/components.ja.md +0 -27
  110. package/docs/components.md +0 -27
  111. package/docs/components.zh-TW.md +0 -27
  112. package/docs/components.zh.md +0 -27
  113. package/docs/core-concepts.ja.md +0 -134
  114. package/docs/core-concepts.md +0 -135
  115. package/docs/core-concepts.zh-TW.md +0 -134
  116. package/docs/core-concepts.zh.md +0 -134
  117. package/docs/getting-started.ja.md +0 -132
  118. package/docs/getting-started.md +0 -132
  119. package/docs/getting-started.zh-TW.md +0 -132
  120. package/docs/getting-started.zh.md +0 -132
  121. package/docs/hooks-api.ja.md +0 -214
  122. package/docs/hooks-api.md +0 -214
  123. package/docs/hooks-api.zh-TW.md +0 -214
  124. package/docs/hooks-api.zh.md +0 -214
  125. package/docs/how-to-guides.ja.md +0 -413
  126. package/docs/how-to-guides.md +0 -413
  127. package/docs/how-to-guides.zh-TW.md +0 -413
  128. package/docs/how-to-guides.zh.md +0 -413
  129. package/docs/overview.ja.md +0 -51
  130. package/docs/overview.md +0 -51
  131. package/docs/overview.zh-TW.md +0 -51
  132. package/docs/overview.zh.md +0 -51
  133. package/glossary.md +0 -12
  134. package/src/@types/index.ts +0 -230
  135. package/src/@types/shims.d.ts +0 -18
  136. package/src/BlockletStudio/README.md +0 -116
  137. package/src/BlockletStudio/index.tsx +0 -145
  138. package/src/ComponentInstaller/ComponentInstaller.stories.jsx +0 -16
  139. package/src/ComponentInstaller/index.jsx +0 -207
  140. package/src/ComponentInstaller/installer-item.jsx +0 -129
  141. package/src/ComponentInstaller/locales.js +0 -22
  142. package/src/ComponentInstaller/use-component-installed.js +0 -88
  143. package/src/ComponentManager/components/add-component.tsx +0 -136
  144. package/src/ComponentManager/components/check-component.tsx +0 -3
  145. package/src/ComponentManager/components/publish-component.tsx +0 -90
  146. package/src/ComponentManager/components/resource-dialog.tsx +0 -91
  147. package/src/ComponentManager/index.tsx +0 -3
  148. package/src/ComponentManager/libs/locales.ts +0 -15
  149. package/src/Dashboard/Dashboard.stories.jsx +0 -20
  150. package/src/Dashboard/app-shell/app-badge.stories.tsx +0 -64
  151. package/src/Dashboard/app-shell/app-badge.tsx +0 -94
  152. package/src/Dashboard/app-shell/app-header.tsx +0 -104
  153. package/src/Dashboard/app-shell/app-info-context.tsx +0 -182
  154. package/src/Dashboard/app-shell/badges/app-badge-default.tsx +0 -130
  155. package/src/Dashboard/app-shell/badges/app-badge-did.tsx +0 -28
  156. package/src/Dashboard/app-shell/badges/app-badge-state.tsx +0 -40
  157. package/src/Dashboard/app-shell/badges/app-badge-switch.tsx +0 -72
  158. package/src/Dashboard/app-shell/badges/app-badge-version.tsx +0 -60
  159. package/src/Dashboard/app-shell/index.ts +0 -5
  160. package/src/Dashboard/index.jsx +0 -184
  161. package/src/Footer/Footer.stories.jsx +0 -33
  162. package/src/Footer/brand.jsx +0 -81
  163. package/src/Footer/copyright.jsx +0 -22
  164. package/src/Footer/index.jsx +0 -111
  165. package/src/Footer/internal-footer.jsx +0 -139
  166. package/src/Footer/layout/plain.jsx +0 -55
  167. package/src/Footer/layout/row.jsx +0 -43
  168. package/src/Footer/layout/standard.jsx +0 -114
  169. package/src/Footer/links.jsx +0 -321
  170. package/src/Footer/social-media.jsx +0 -55
  171. package/src/Header/Header.stories.jsx +0 -30
  172. package/src/Header/index.tsx +0 -259
  173. package/src/Icon/Icon.stories.jsx +0 -12
  174. package/src/Icon/index.tsx +0 -87
  175. package/src/Notifications/Snackbar.tsx +0 -261
  176. package/src/Notifications/hooks/use-title.tsx +0 -254
  177. package/src/Notifications/hooks/use-width.tsx +0 -16
  178. package/src/Notifications/utils.ts +0 -246
  179. package/src/UserCenter/assets/banner.png +0 -0
  180. package/src/UserCenter/components/config-inviter.tsx +0 -48
  181. package/src/UserCenter/components/config-profile.tsx +0 -99
  182. package/src/UserCenter/components/danger-zone.tsx +0 -82
  183. package/src/UserCenter/components/editable-field.tsx +0 -273
  184. package/src/UserCenter/components/fallback.tsx +0 -57
  185. package/src/UserCenter/components/nft-preview.tsx +0 -84
  186. package/src/UserCenter/components/nft.tsx +0 -279
  187. package/src/UserCenter/components/notification.tsx +0 -319
  188. package/src/UserCenter/components/passport.tsx +0 -107
  189. package/src/UserCenter/components/privacy.tsx +0 -120
  190. package/src/UserCenter/components/settings.tsx +0 -170
  191. package/src/UserCenter/components/status-dialog/date-picker.tsx +0 -77
  192. package/src/UserCenter/components/status-dialog/index.tsx +0 -293
  193. package/src/UserCenter/components/status-selector/duration-menu.tsx +0 -90
  194. package/src/UserCenter/components/status-selector/index.tsx +0 -58
  195. package/src/UserCenter/components/status-selector/menu-item.tsx +0 -56
  196. package/src/UserCenter/components/storage/action.tsx +0 -49
  197. package/src/UserCenter/components/storage/connected.tsx +0 -61
  198. package/src/UserCenter/components/storage/delete.tsx +0 -72
  199. package/src/UserCenter/components/storage/disconnect.tsx +0 -40
  200. package/src/UserCenter/components/storage/icons/empty-spaces-nft.svg +0 -1
  201. package/src/UserCenter/components/storage/icons/long-arrow.svg +0 -5
  202. package/src/UserCenter/components/storage/icons/space-connected.svg +0 -3
  203. package/src/UserCenter/components/storage/icons/space-disconnect.svg +0 -3
  204. package/src/UserCenter/components/storage/index.tsx +0 -41
  205. package/src/UserCenter/components/storage/preview-nft.tsx +0 -72
  206. package/src/UserCenter/components/third-party-login/index.tsx +0 -199
  207. package/src/UserCenter/components/third-party-login/third-party-item.tsx +0 -296
  208. package/src/UserCenter/components/user-center.tsx +0 -787
  209. package/src/UserCenter/components/user-info/address.tsx +0 -143
  210. package/src/UserCenter/components/user-info/index.tsx +0 -4
  211. package/src/UserCenter/components/user-info/link-preview-input.tsx +0 -274
  212. package/src/UserCenter/components/user-info/metadata.tsx +0 -658
  213. package/src/UserCenter/components/user-info/social-actions/chat.tsx +0 -43
  214. package/src/UserCenter/components/user-info/social-actions/follow.tsx +0 -23
  215. package/src/UserCenter/components/user-info/social-actions/index.tsx +0 -17
  216. package/src/UserCenter/components/user-info/switch-role.tsx +0 -42
  217. package/src/UserCenter/components/user-info/timezone-select.tsx +0 -119
  218. package/src/UserCenter/components/user-info/user-basic-info.tsx +0 -292
  219. package/src/UserCenter/components/user-info/user-info-item.tsx +0 -54
  220. package/src/UserCenter/components/user-info/user-info.tsx +0 -91
  221. package/src/UserCenter/components/user-info/user-status.tsx +0 -234
  222. package/src/UserCenter/components/user-info/utils.ts +0 -320
  223. package/src/UserCenter/components/webhook-item.tsx +0 -248
  224. package/src/UserCenter/index.tsx +0 -1
  225. package/src/UserCenter/libs/locales.ts +0 -378
  226. package/src/UserCenter/libs/utils.ts +0 -30
  227. package/src/UserSessions/components/user-session-info.tsx +0 -78
  228. package/src/UserSessions/components/user-sessions.tsx +0 -545
  229. package/src/UserSessions/index.tsx +0 -1
  230. package/src/UserSessions/libs/locales.ts +0 -60
  231. package/src/UserSessions/libs/utils.ts +0 -82
  232. package/src/blocklets.js +0 -195
  233. package/src/common/domain-warning.jsx +0 -178
  234. package/src/common/header-addons.jsx +0 -119
  235. package/src/common/link-blocker.jsx +0 -20
  236. package/src/common/notification-addon.jsx +0 -135
  237. package/src/common/org-switch/avatar-uploader.jsx +0 -271
  238. package/src/common/org-switch/create.jsx +0 -267
  239. package/src/common/org-switch/index.jsx +0 -407
  240. package/src/common/org-switch/locales.js +0 -52
  241. package/src/common/org-switch/use-org.jsx +0 -79
  242. package/src/common/overridable-theme-provider.jsx +0 -17
  243. package/src/common/wallet-hidden-topbar.js +0 -14
  244. package/src/common/wizard-modal.jsx +0 -200
  245. package/src/common/ws.js +0 -68
  246. package/src/contexts/config-user-space.tsx +0 -88
  247. package/src/contexts/user-followers.tsx +0 -54
  248. package/src/hooks/use-follow.tsx +0 -75
  249. package/src/hooks/use-mobile.tsx +0 -6
  250. package/src/index.ts +0 -16
  251. package/src/libs/constant.ts +0 -1
  252. package/src/libs/spaces.tsx +0 -18
  253. package/src/libs/with-hide-when-embed.tsx +0 -24
  254. package/src/types.js +0 -45
  255. package/src/utils.js +0 -161
  256. package/vite.config.mjs +0 -34
@@ -1,246 +0,0 @@
1
- import isEmpty from 'lodash/isEmpty';
2
- import DOMPurify from 'dompurify';
3
- import { Link, toTextList, getLink as getLinkUtil } from '@abtnode/util/lib/notification-preview/highlight';
4
- import { isSameAddr } from '@abtnode/util/lib/notification-preview/func';
5
- import { getBlockletSDK } from '@blocklet/js-sdk';
6
-
7
- /**
8
- * 通知对象的活动目标接口
9
- */
10
- interface ActivityTarget {
11
- type?: string;
12
- id?: string;
13
- }
14
-
15
- /**
16
- * 通知对象的活动元数据接口
17
- */
18
- interface ActivityMeta {
19
- id?: string;
20
- }
21
-
22
- /**
23
- * 活动对象接口
24
- */
25
- interface Activity {
26
- type?: string;
27
- actor?: string;
28
- target?: ActivityTarget;
29
- meta?: ActivityMeta;
30
- }
31
-
32
- /**
33
- * 通知对象接口
34
- */
35
- interface Notification {
36
- activity?: Activity;
37
- actorInfo?: any;
38
- severity?: string;
39
- title?: string;
40
- description?: string;
41
- items?: Notification[];
42
- }
43
-
44
- /**
45
- * 合并相邻的通知数据
46
- * 合并条件:
47
- * 1. 数据必须是相邻的
48
- * 2. activity.type 必须相同且不为 null 或 undefined
49
- * 3. 如果存在target对象,activity.target.type和activity.target.id都必须相同
50
- * 4. 如果相邻数据的 activity.type 相同但没有 activity.target 对象,则需要合并
51
- *
52
- * @param {Notification[]} notifications - 需要处理的通知数据
53
- * @returns {Notification[]} - 合并后的通知数组
54
- */
55
- export const mergeAdjacentNotifications = (notifications: Notification[]): Notification[] => {
56
- if (!notifications || !notifications.length) {
57
- return [];
58
- }
59
-
60
- const result: Notification[] = [];
61
- let currentGroup: Notification | null = null;
62
- let groupItems: Notification[] = [];
63
-
64
- notifications.forEach((notification: Notification) => {
65
- // 如果没有activity或activity.type为null/undefined或者这是第一条记录
66
- if (!notification.activity || !notification.activity.type || !currentGroup) {
67
- // 处理前一个分组(如果存在)
68
- if (currentGroup) {
69
- // 如果只有一个通知,直接添加原通知
70
- if (groupItems.length === 1) {
71
- result.push(groupItems[0]);
72
- } else {
73
- // 将items添加到第一个通知对象,并将其添加到结果中
74
- currentGroup.items = groupItems;
75
- result.push(currentGroup);
76
- }
77
- }
78
-
79
- // 处理当前通知
80
- if (notification.activity && notification.activity.type) {
81
- // 将第一个通知对象作为组的基础,不创建新对象
82
- currentGroup = notification;
83
- groupItems = [notification];
84
- } else {
85
- // 无activity或activity.type的记录直接添加到结果中
86
- result.push(notification);
87
- // 重置当前组
88
- currentGroup = null;
89
- groupItems = [];
90
- }
91
- return;
92
- }
93
-
94
- // 获取当前组和当前通知的activity信息
95
- const currentActivity = groupItems[0].activity;
96
- const currentType = currentActivity?.type;
97
- const currentTargetType = currentActivity?.target?.type;
98
- const currentTargetId = currentActivity?.target?.id;
99
-
100
- const newType = notification.activity.type;
101
- const newTargetType = notification.activity.target?.type;
102
- const newTargetId = notification.activity.target?.id;
103
-
104
- // 判断是否需要合并
105
- const shouldMerge =
106
- // activity.type 必须相同且不为null或undefined
107
- currentType &&
108
- newType &&
109
- currentType === newType &&
110
- // 如果都没有target,可以合并
111
- ((!currentActivity?.target && !notification.activity.target) ||
112
- // 如果都有target,则target.type和target.id都必须相同
113
- (currentActivity?.target &&
114
- notification.activity.target &&
115
- currentTargetType === newTargetType &&
116
- currentTargetId === newTargetId));
117
-
118
- if (shouldMerge) {
119
- // 合并到当前组
120
- groupItems.push(notification);
121
- } else {
122
- // 不满足合并条件,处理当前组
123
- // 如果只有一个通知,直接添加原通知
124
- if (groupItems.length === 1) {
125
- result.push(groupItems[0]);
126
- } else {
127
- // 将items添加到第一个通知对象,并将其添加到结果中
128
- // 使用Object.assign创建浅拷贝,避免修改原对象
129
- const groupToAdd = Object.assign({}, currentGroup, { items: groupItems });
130
- result.push(groupToAdd);
131
- }
132
-
133
- // 开始新的分组
134
- currentGroup = notification;
135
- groupItems = [notification];
136
- }
137
- });
138
-
139
- // 处理最后一个分组(如果有)
140
- if (currentGroup) {
141
- // 如果只有一个通知,直接添加原通知
142
- if (groupItems.length === 1) {
143
- result.push(groupItems[0]);
144
- } else {
145
- // 将items添加到第一个通知对象,并将其添加到结果中
146
- // 使用Object.assign创建浅拷贝,避免修改原对象
147
- const groupToAdd = Object.assign({}, currentGroup, { items: groupItems });
148
- result.push(groupToAdd);
149
- }
150
- }
151
-
152
- return result;
153
- };
154
-
155
- /**
156
- * 判断通知是否包含activity
157
- * @param {Notification} notification - 通知对象
158
- * @returns {boolean} - 是否包含activity
159
- */
160
- export const isIncludeActivity = (notification: Notification): boolean => {
161
- return !isEmpty(notification.activity) && !!notification.activity?.type && !!notification.activity?.actor;
162
- };
163
-
164
- /**
165
- * 是否可以自动已读
166
- */
167
- export const canAutoRead = (notification: Notification | null | undefined): boolean => {
168
- const { severity } = notification || {};
169
- return !!severity && ['normal', 'success', 'info'].includes(severity);
170
- };
171
-
172
- /**
173
- * 获取 activity 的链接
174
- * 链接的来源有两种
175
- * 1. activity.meta.id
176
- * 2. activity.target.id
177
- * @param {Activity} activity - 活动对象
178
- * @returns {Object | null} - 活动的链接
179
- */
180
- export const getActivityLink = (
181
- activity: Activity | null | undefined
182
- ): { metaLink?: string | null; targetLink?: string | null } | null => {
183
- if (!activity) {
184
- return null;
185
- }
186
- const { meta, target } = activity;
187
- return {
188
- metaLink: meta?.id,
189
- targetLink: target?.id,
190
- };
191
- };
192
-
193
- const getUserProfileUrl = async (did: string, locale: string) => {
194
- try {
195
- const client = getBlockletSDK();
196
- const profileUrl = await client.user.getProfileUrl({ did, locale });
197
- return profileUrl;
198
- } catch (error) {
199
- console.error(error);
200
- return undefined;
201
- }
202
- };
203
-
204
- const getLink = async (item: any, locale: string) => {
205
- const { type, did } = item;
206
- if (isSameAddr(type, 'did')) {
207
- const profileUrl = await getUserProfileUrl(did, locale);
208
- return profileUrl || getLinkUtil(item);
209
- }
210
- return getLinkUtil(item);
211
- };
212
-
213
- export const toClickableSpan = async (str: string, locale: string, isHighLight = true) => {
214
- const textList = toTextList(str);
215
- const result = await Promise.all(
216
- textList.map(async (item: any) => {
217
- if (item instanceof Link) {
218
- if (isHighLight) {
219
- const url = await getLink(item, locale);
220
- const { type, chainId, did } = item;
221
-
222
- // HACK: 邮件中无法支持 dapp 的展示,缺少 dapp 链接,只能作为加粗展示
223
- if (isSameAddr(type, 'dapp')) {
224
- return `<em class="dapp" data-type="${type}" data-chain-id="${chainId}" data-did="${did}">${item.text}</em>`;
225
- }
226
- if (url) {
227
- return `<a target="_blank" rel="noopener noreferrer" class="link" href="${url}">${item.text}</a>`;
228
- }
229
-
230
- // 默认展示为加粗
231
- return `<em class="common" data-type="${type}" data-chain-id="${chainId}" data-did="${did}">${item.text}</em>`;
232
- }
233
- return item.text;
234
- }
235
-
236
- return item;
237
- })
238
- ).then((results) => results.join(''));
239
- return result;
240
- };
241
-
242
- export const sanitize = (innerHtml: string) => {
243
- return DOMPurify.sanitize(innerHtml, {
244
- ALLOWED_ATTR: ['href', 'target', 'rel', 'class', 'id', 'style'],
245
- });
246
- };
Binary file
@@ -1,48 +0,0 @@
1
- import { Box, TextField } from '@mui/material';
2
- import { useMemoizedFn, useReactive } from 'ahooks';
3
- import Toast from '@arcblock/ux/lib/Toast';
4
- import { getBlockletSDK } from '@blocklet/js-sdk';
5
-
6
- import { User } from '../../@types';
7
- import { formatAxiosError } from '../libs/utils';
8
-
9
- export default function ConfigInviter({ user }: { user: User }) {
10
- const currentState = useReactive({
11
- inviter: user?.inviter,
12
- loading: false,
13
- });
14
- const client = getBlockletSDK();
15
-
16
- const handleChange = useMemoizedFn(async (e) => {
17
- try {
18
- const { value } = e.target;
19
- currentState.loading = true;
20
- await client.user.saveProfile({ inviter: value });
21
- currentState.inviter = value;
22
- } catch (err) {
23
- Toast.error(formatAxiosError(err as any));
24
- } finally {
25
- currentState.loading = false;
26
- }
27
- });
28
-
29
- if (!user) {
30
- return '-';
31
- }
32
-
33
- const inviteEnabled = !!window.blocklet?.settings?.invite?.enabled;
34
- if (!inviteEnabled) {
35
- return '-';
36
- }
37
-
38
- const hasInviter = !!user.inviter;
39
- if (hasInviter) {
40
- return '-';
41
- }
42
-
43
- return (
44
- <Box>
45
- <TextField size="small" fullWidth label="" value={currentState.inviter} onChange={handleChange} />
46
- </Box>
47
- );
48
- }
@@ -1,99 +0,0 @@
1
- import { Box, MenuItem, Select, SelectChangeEvent, LinearProgress } from '@mui/material';
2
- import { useMemoizedFn, useReactive } from 'ahooks';
3
- import { translate } from '@arcblock/ux/lib/Locale/util';
4
- import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
- import Toast from '@arcblock/ux/lib/Toast';
6
- import ArrowDownwardIcon from '@arcblock/icons/lib/ArrowDown';
7
- import { getBlockletSDK } from '@blocklet/js-sdk';
8
-
9
- import { translations } from '../libs/locales';
10
- import { User } from '../../@types';
11
- import { formatAxiosError } from '../libs/utils';
12
-
13
- const languages = [
14
- { name: 'English', code: 'en' },
15
- { name: '中文', code: 'zh' },
16
- ];
17
-
18
- export default function ConfigProfile({ user, onSave }: { user: User; onSave: (type: 'profile') => void }) {
19
- const { locale, changeLocale } = useLocaleContext();
20
- const client = getBlockletSDK();
21
- const t = useMemoizedFn((key, data = {}) => {
22
- return translate(translations, key, locale, 'en', data);
23
- });
24
- const currentState = useReactive({
25
- locale: user.locale,
26
- loading: false,
27
- });
28
-
29
- const handleChange = useMemoizedFn(async (e: SelectChangeEvent<string>) => {
30
- try {
31
- const { value } = e.target;
32
- currentState.loading = true;
33
- await client.user.saveProfile({
34
- locale: value,
35
- });
36
- await onSave('profile');
37
- changeLocale(value);
38
- currentState.locale = value;
39
- } catch (err) {
40
- Toast.error(formatAxiosError(err as any));
41
- } finally {
42
- currentState.loading = false;
43
- }
44
- });
45
- return (
46
- <Box
47
- sx={{
48
- gap: 1,
49
- display: 'grid',
50
- alignItems: 'center',
51
- gridTemplateColumns: {
52
- xs: '1fr',
53
- sm: 'max-content 1fr',
54
- },
55
- }}>
56
- <Box>{t('commonSetting.locale')}</Box>
57
- <Box>
58
- {currentState.loading ? (
59
- <LinearProgress
60
- color="primary"
61
- sx={{
62
- height: 2,
63
- }}
64
- />
65
- ) : (
66
- <Box
67
- sx={{
68
- height: 2,
69
- visibility: 'hidden',
70
- }}
71
- />
72
- )}
73
- <Select
74
- value={currentState.locale}
75
- onChange={handleChange}
76
- size="small"
77
- // eslint-disable-next-line react/no-unstable-nested-components
78
- IconComponent={(props) => <ArrowDownwardIcon {...props} width={20} height={20} />}
79
- sx={{
80
- minWidth: 200,
81
- '&:hover': {
82
- 'fieldset.MuiOutlinedInput-notchedOutline': {
83
- borderColor: 'divider',
84
- },
85
- },
86
- fieldset: {
87
- borderColor: 'divider',
88
- },
89
- }}>
90
- {(window.blocklet.languages || languages).map((x: { name: string; code: string }) => (
91
- <MenuItem value={x.code} key={x.code}>
92
- {x.name}
93
- </MenuItem>
94
- ))}
95
- </Select>
96
- </Box>
97
- </Box>
98
- );
99
- }
@@ -1,82 +0,0 @@
1
- import { use } from 'react';
2
- import { Box, Button, Typography } from '@mui/material';
3
- import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
4
- import { translate } from '@arcblock/ux/lib/Locale/util';
5
- import { useMemoizedFn } from 'ahooks';
6
- import { useConfirm } from '@arcblock/ux/lib/Dialog';
7
- import { SessionContext } from '@arcblock/did-connect-react/lib/Session';
8
- import Toast from '@arcblock/ux/lib/Toast';
9
-
10
- import { translations } from '../libs/locales';
11
- import type { SessionContext as TSessionContext } from '../../@types';
12
-
13
- export default function DangerZone({ onDestroySelf = undefined }: { onDestroySelf?: () => void }) {
14
- const { confirmHolder } = useConfirm();
15
-
16
- const { locale } = useLocaleContext();
17
- const { session } = use<TSessionContext>(SessionContext);
18
- const t = useMemoizedFn((key, data = {}) => {
19
- return translate(translations, key, locale, 'en', data);
20
- });
21
-
22
- const handleRemoveMyself = useMemoizedFn(async () => {
23
- if (!onDestroySelf || typeof onDestroySelf !== 'function') {
24
- return;
25
- }
26
-
27
- const handle = session.withSecondaryAuth(onDestroySelf, {
28
- extraParams: {
29
- locale,
30
- removeUserDid: session?.user?.did,
31
- input: {
32
- user: { did: session?.user?.did },
33
- teamDid: window?.blocklet?.did,
34
- },
35
- },
36
- operation: 'destroySelf',
37
- });
38
- try {
39
- await handle();
40
- session.logout();
41
- } catch (error: any) {
42
- Toast.error(error?.message || t('destroyMyself.error'));
43
- }
44
- });
45
-
46
- return (
47
- <>
48
- <Box>
49
- <Box
50
- sx={{
51
- display: 'flex',
52
- alignItems: 'center',
53
- gap: 1,
54
- justifyContent: 'space-between',
55
- flexWrap: 'wrap',
56
- }}>
57
- <Box>
58
- <Typography
59
- variant="h6"
60
- sx={{
61
- fontSize: '0.875rem !important',
62
- fontWeight: 'bold',
63
- }}>
64
- {t('dangerZone.deleteAccount')}
65
- </Typography>
66
- <Typography
67
- variant="caption"
68
- sx={{
69
- color: 'text.secondary',
70
- }}>
71
- {t('dangerZone.deleteAccountDescription')}
72
- </Typography>
73
- </Box>
74
- <Button variant="contained" color="error" size="small" onClick={handleRemoveMyself}>
75
- {t('dangerZone.delete')}
76
- </Button>
77
- </Box>
78
- </Box>
79
- {confirmHolder}
80
- </>
81
- );
82
- }