@arcblock/ux 2.10.67 → 2.10.68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. package/lib/Address/did-address.d.ts +6 -5
  2. package/lib/Address/index.d.ts +1 -1
  3. package/lib/Avatar/index.d.ts +10 -8
  4. package/lib/Avatar/index.js +6 -4
  5. package/lib/Blocklet/blocklet.d.ts +4 -4
  6. package/lib/Blocklet/blocklet.js +2 -2
  7. package/lib/BlockletContext/index.d.ts +3 -3
  8. package/lib/BlockletNFT/index.d.ts +6 -6
  9. package/lib/BlockletNFT/index.js +3 -3
  10. package/lib/BlockletV2/blocklet.d.ts +2 -2
  11. package/lib/Button/wrap.d.ts +4 -4
  12. package/lib/Button/wrap.js +2 -2
  13. package/lib/CardSelector/index.js +0 -1
  14. package/lib/Center/index.d.ts +1 -1
  15. package/lib/ClickToCopy/copy-button.d.ts +5 -4
  16. package/lib/ClickToCopy/copy-button.js +0 -1
  17. package/lib/ClickToCopy/hook.d.ts +3 -8
  18. package/lib/ClickToCopy/index.d.ts +6 -4
  19. package/lib/CodeBlock/index.d.ts +3 -1
  20. package/lib/CookieConsent/index.d.ts +8 -29
  21. package/lib/CookieConsent/index.js +3 -17
  22. package/lib/CountDown/index.d.ts +21 -25
  23. package/lib/CountDown/index.js +12 -11
  24. package/lib/DID/index.d.ts +9 -8
  25. package/lib/Datatable/index.d.ts +5 -5
  26. package/lib/Datatable/index.js +5 -5
  27. package/lib/Dialog/confirm.d.ts +6 -6
  28. package/lib/Dialog/confirm.js +3 -3
  29. package/lib/Dialog/types.d.ts +1 -1
  30. package/lib/DidLogo/index.d.ts +5 -25
  31. package/lib/DidLogo/index.js +4 -15
  32. package/lib/DriftBot/index.d.ts +13 -19
  33. package/lib/DriftBot/index.js +5 -6
  34. package/lib/Earth/index.d.ts +28 -10
  35. package/lib/Earth/index.js +12 -52
  36. package/lib/Earth/util.d.ts +10 -5
  37. package/lib/Earth/util.js +1 -0
  38. package/lib/ErrorBoundary/fallback.d.ts +12 -19
  39. package/lib/ErrorBoundary/fallback.js +2 -19
  40. package/lib/ErrorBoundary/index.d.ts +1 -1
  41. package/lib/Footer/index.d.ts +17 -24
  42. package/lib/Footer/index.js +2 -11
  43. package/lib/Header/header.d.ts +2 -2
  44. package/lib/Icon/image.d.ts +3 -2
  45. package/lib/Icon/index.d.ts +6 -4
  46. package/lib/Img/index.d.ts +1 -1
  47. package/lib/Img/index.js +1 -1
  48. package/lib/InfoRow/index.d.ts +9 -32
  49. package/lib/InfoRow/index.js +10 -23
  50. package/lib/Layout/dashboard/external-link.d.ts +13 -14
  51. package/lib/Layout/dashboard/external-link.js +5 -22
  52. package/lib/Layout/dashboard/full-page.d.ts +19 -11
  53. package/lib/Layout/dashboard/full-page.js +2 -6
  54. package/lib/Layout/dashboard/index.d.ts +20 -39
  55. package/lib/Layout/dashboard/index.js +10 -38
  56. package/lib/Layout/dashboard/sidebar.d.ts +17 -20
  57. package/lib/Layout/dashboard/sidebar.js +3 -16
  58. package/lib/Layout/dashboard-legacy/header.d.ts +10 -36
  59. package/lib/Layout/dashboard-legacy/header.js +5 -24
  60. package/lib/Layout/dashboard-legacy/index.d.ts +17 -56
  61. package/lib/Layout/dashboard-legacy/index.js +12 -41
  62. package/lib/Layout/dashboard-legacy/sidebar.d.ts +15 -26
  63. package/lib/Layout/dashboard-legacy/sidebar.js +5 -15
  64. package/lib/Layout/index.d.ts +17 -56
  65. package/lib/Layout/index.js +24 -50
  66. package/lib/LoadingMask/index.d.ts +8 -31
  67. package/lib/LoadingMask/index.js +2 -18
  68. package/lib/Locale/browser-lang.d.ts +4 -1
  69. package/lib/Locale/browser-lang.js +8 -3
  70. package/lib/Locale/context.d.ts +18 -8
  71. package/lib/Locale/context.js +1 -1
  72. package/lib/Locale/languages.d.ts +9 -55
  73. package/lib/Locale/selector.d.ts +10 -26
  74. package/lib/Locale/selector.js +8 -25
  75. package/lib/Locale/util.d.ts +4 -3
  76. package/lib/Locale/util.js +0 -1
  77. package/lib/Logo/index.d.ts +9 -40
  78. package/lib/Logo/index.js +88 -46
  79. package/lib/Metric/index.d.ts +9 -31
  80. package/lib/Metric/index.js +5 -20
  81. package/lib/NFTDisplay/aspect-ratio-container.d.ts +5 -12
  82. package/lib/NFTDisplay/aspect-ratio-container.js +0 -5
  83. package/lib/NFTDisplay/broken.d.ts +3 -13
  84. package/lib/NFTDisplay/broken.js +80 -10
  85. package/lib/NFTDisplay/displayApi.d.ts +1 -1
  86. package/lib/NFTDisplay/index.d.ts +28 -6
  87. package/lib/NFTDisplay/index.js +17 -51
  88. package/lib/NFTDisplay/svg-embedder/img.d.ts +8 -23
  89. package/lib/NFTDisplay/svg-embedder/img.js +3 -17
  90. package/lib/NFTDisplay/svg-embedder/inline-svg.d.ts +7 -13
  91. package/lib/NFTDisplay/svg-embedder/inline-svg.js +1 -8
  92. package/lib/NavMenu/nav-menu.d.ts +2 -0
  93. package/lib/NavMenu/nav-menu.js +0 -1
  94. package/lib/PageScroller/index.d.ts +14 -13
  95. package/lib/PageScroller/index.js +12 -37
  96. package/lib/PageScroller/usePrevValue.d.ts +1 -1
  97. package/lib/PageScroller/usePrevValue.js +1 -2
  98. package/lib/Passport/index.d.ts +1 -1
  99. package/lib/Passport/passport.d.ts +10 -30
  100. package/lib/Passport/passport.js +5 -19
  101. package/lib/PoweredByArcBlock/index.d.ts +4 -14
  102. package/lib/PoweredByArcBlock/index.js +1 -8
  103. package/lib/PricingTable/PricingPlan.d.ts +11 -9
  104. package/lib/PricingTable/PricingPlan.js +0 -4
  105. package/lib/PricingTable/index.d.ts +5 -3
  106. package/lib/PricingTable/index.js +1 -5
  107. package/lib/QRCode/index.d.ts +11 -22
  108. package/lib/QRCode/index.js +1 -15
  109. package/lib/RelativeTime/index.d.ts +12 -40
  110. package/lib/RelativeTime/index.js +7 -27
  111. package/lib/Result/common.d.ts +26 -45
  112. package/lib/Result/common.js +2 -4
  113. package/lib/Result/index.d.ts +5 -18
  114. package/lib/Result/index.js +1 -9
  115. package/lib/Result/result.d.ts +7 -29
  116. package/lib/Result/result.js +2 -17
  117. package/lib/Result/translations.d.ts +2 -54
  118. package/lib/Screenshot/BaseScreenshot/index.d.ts +7 -24
  119. package/lib/Screenshot/BaseScreenshot/index.js +2 -15
  120. package/lib/Screenshot/BaseScreenshot/shells/Macbook.d.ts +25 -19
  121. package/lib/Screenshot/BaseScreenshot/shells/Phone.d.ts +25 -19
  122. package/lib/Screenshot/index.d.ts +84 -28
  123. package/lib/Screenshot/index.js +14 -43
  124. package/lib/SessionBlocklet/index.d.ts +6 -19
  125. package/lib/SessionBlocklet/index.js +3 -14
  126. package/lib/SessionManager/index.d.ts +1 -1
  127. package/lib/SessionPermission/index.d.ts +9 -17
  128. package/lib/SessionPermission/index.js +3 -11
  129. package/lib/SessionUser/components/logged-in.d.ts +9 -31
  130. package/lib/SessionUser/components/logged-in.js +13 -29
  131. package/lib/SessionUser/components/session-user-item.d.ts +8 -1
  132. package/lib/SessionUser/components/session-user-item.js +2 -12
  133. package/lib/SessionUser/components/session-user-switch.d.ts +9 -21
  134. package/lib/SessionUser/components/session-user-switch.js +3 -15
  135. package/lib/SessionUser/components/un-login.d.ts +7 -23
  136. package/lib/SessionUser/components/un-login.js +4 -16
  137. package/lib/SessionUser/components/user-info.d.ts +12 -29
  138. package/lib/SessionUser/components/user-info.js +4 -19
  139. package/lib/SessionUser/index.d.ts +7 -30
  140. package/lib/SessionUser/index.js +5 -26
  141. package/lib/SessionUser/libs/translation.d.ts +2 -31
  142. package/lib/SessionUser/libs/translation.js +1 -0
  143. package/lib/SessionUser/libs/utils.d.ts +10 -9
  144. package/lib/Sparkline/index.d.ts +22 -1
  145. package/lib/Sparkline/index.js +25 -17
  146. package/lib/Spinner/index.d.ts +6 -1
  147. package/lib/Spinner/index.js +4 -11
  148. package/lib/Success/index.d.ts +5 -21
  149. package/lib/Success/index.js +4 -16
  150. package/lib/Tabs/index.d.ts +12 -26
  151. package/lib/Tabs/index.js +7 -37
  152. package/lib/TextCollapse/index.d.ts +10 -10
  153. package/lib/TextCollapse/index.js +4 -21
  154. package/lib/Theme/index.js +0 -2
  155. package/lib/Theme/theme-provider.d.ts +1 -1
  156. package/lib/Theme/theme.d.ts +4 -1
  157. package/lib/Theme/theme.js +1 -2
  158. package/lib/Typography/index.d.ts +5 -24
  159. package/lib/Typography/index.js +5 -17
  160. package/lib/Util/index.d.ts +11 -6
  161. package/lib/Util/index.js +6 -0
  162. package/lib/Video/index.d.ts +12 -16
  163. package/lib/Video/index.js +0 -14
  164. package/lib/Wallet/Action.d.ts +13 -18
  165. package/lib/Wallet/Action.js +0 -7
  166. package/lib/Wallet/Download.d.ts +24 -30
  167. package/lib/Wallet/Download.js +201 -18
  168. package/lib/Wallet/Open.d.ts +5 -15
  169. package/lib/Wallet/Open.js +5 -11
  170. package/lib/WalletOSIcon/index.d.ts +6 -25
  171. package/lib/WalletOSIcon/index.js +3 -16
  172. package/lib/WebWalletSWKeeper/index.d.ts +8 -20
  173. package/lib/WebWalletSWKeeper/index.js +14 -19
  174. package/lib/WechatPrompt/index.js +2 -0
  175. package/lib/global.d.ts +15 -0
  176. package/lib/type.d.ts +12 -3
  177. package/lib/withTheme/index.d.ts +8 -6
  178. package/lib/withTracker/index.d.ts +1 -1
  179. package/lib/withTracker/index.js +3 -0
  180. package/package.json +9 -5
  181. package/src/Address/did-address.tsx +7 -6
  182. package/src/Address/index.tsx +1 -1
  183. package/src/Avatar/index.jsx +6 -4
  184. package/src/Blocklet/blocklet.jsx +2 -2
  185. package/src/BlockletContext/index.tsx +3 -3
  186. package/src/BlockletNFT/index.jsx +3 -3
  187. package/src/BlockletV2/blocklet.tsx +2 -2
  188. package/src/Button/wrap.jsx +2 -2
  189. package/src/CardSelector/index.tsx +0 -1
  190. package/src/Center/index.tsx +1 -1
  191. package/src/ClickToCopy/copy-button.tsx +4 -4
  192. package/src/ClickToCopy/hook.ts +3 -2
  193. package/src/ClickToCopy/index.tsx +6 -5
  194. package/src/CodeBlock/index.tsx +3 -1
  195. package/src/CookieConsent/{index.jsx → index.tsx} +16 -19
  196. package/src/CountDown/{index.jsx → index.tsx} +30 -16
  197. package/src/DID/index.tsx +9 -8
  198. package/src/Datatable/index.jsx +5 -5
  199. package/src/Dialog/confirm.jsx +3 -3
  200. package/src/Dialog/types.d.ts +1 -1
  201. package/src/DidLogo/{index.jsx → index.tsx} +7 -14
  202. package/src/DriftBot/{index.jsx → index.tsx} +13 -11
  203. package/src/Earth/{index.jsx → index.tsx} +94 -66
  204. package/src/Earth/{util.js → util.ts} +20 -17
  205. package/src/ErrorBoundary/{fallback.jsx → fallback.tsx} +20 -21
  206. package/src/Footer/{index.jsx → index.tsx} +17 -14
  207. package/src/Header/header.tsx +2 -3
  208. package/src/Header/responsive-header.tsx +0 -1
  209. package/src/Icon/image.tsx +3 -3
  210. package/src/Icon/index.tsx +7 -4
  211. package/src/Img/index.jsx +1 -1
  212. package/src/InfoRow/{index.jsx → index.tsx} +32 -25
  213. package/src/Layout/dashboard/external-link.tsx +46 -0
  214. package/src/Layout/dashboard/{full-page.jsx → full-page.tsx} +20 -9
  215. package/src/Layout/dashboard/{index.jsx → index.tsx} +42 -44
  216. package/src/Layout/dashboard/{sidebar.jsx → sidebar.tsx} +23 -20
  217. package/src/Layout/dashboard-legacy/{header.jsx → header.tsx} +16 -26
  218. package/src/Layout/dashboard-legacy/{index.jsx → index.tsx} +32 -46
  219. package/src/Layout/dashboard-legacy/{sidebar.jsx → sidebar.tsx} +27 -19
  220. package/src/Layout/{index.jsx → index.tsx} +41 -47
  221. package/src/LoadingMask/{index.jsx → index.tsx} +17 -19
  222. package/src/Locale/{browser-lang.js → browser-lang.ts} +9 -7
  223. package/src/Locale/context.tsx +18 -11
  224. package/src/Locale/{languages.js → languages.ts} +1 -1
  225. package/src/Locale/{selector.jsx → selector.tsx} +32 -29
  226. package/src/Locale/{util.js → util.ts} +9 -2
  227. package/src/Logo/index.tsx +58 -0
  228. package/src/Metric/{index.jsx → index.tsx} +23 -18
  229. package/src/NFTDisplay/{aspect-ratio-container.jsx → aspect-ratio-container.tsx} +9 -7
  230. package/src/NFTDisplay/{broken.jsx → broken.tsx} +7 -12
  231. package/src/NFTDisplay/{displayApi.js → displayApi.ts} +4 -4
  232. package/src/NFTDisplay/{index.jsx → index.tsx} +59 -64
  233. package/src/NFTDisplay/svg-embedder/{img.jsx → img.tsx} +10 -18
  234. package/src/NFTDisplay/svg-embedder/{inline-svg.jsx → inline-svg.tsx} +8 -9
  235. package/src/NavMenu/nav-menu.tsx +2 -3
  236. package/src/PageScroller/{index.jsx → index.tsx} +40 -53
  237. package/src/PageScroller/{usePrevValue.js → usePrevValue.ts} +2 -3
  238. package/src/Passport/{passport.jsx → passport.tsx} +22 -19
  239. package/src/PoweredByArcBlock/{index.jsx → index.tsx} +6 -11
  240. package/src/PricingTable/{PricingPlan.jsx → PricingPlan.tsx} +15 -5
  241. package/src/PricingTable/{index.jsx → index.tsx} +9 -6
  242. package/src/QRCode/{index.jsx → index.tsx} +13 -17
  243. package/src/RelativeTime/{index.jsx → index.tsx} +24 -24
  244. package/src/Result/{common.jsx → common.tsx} +17 -13
  245. package/src/Result/index.tsx +30 -0
  246. package/src/Result/{result.jsx → result.tsx} +8 -17
  247. package/src/Result/{translations.js → translations.ts} +3 -1
  248. package/src/Screenshot/BaseScreenshot/{index.jsx → index.tsx} +9 -15
  249. package/src/Screenshot/BaseScreenshot/shells/{Macbook.jsx → Macbook.tsx} +3 -1
  250. package/src/Screenshot/BaseScreenshot/shells/{Phone.jsx → Phone.tsx} +3 -1
  251. package/src/Screenshot/{index.jsx → index.tsx} +60 -54
  252. package/src/SessionBlocklet/{index.jsx → index.tsx} +8 -14
  253. package/src/SessionPermission/index.tsx +25 -0
  254. package/src/SessionUser/components/{logged-in.jsx → logged-in.tsx} +49 -31
  255. package/src/SessionUser/components/session-user-item.tsx +97 -0
  256. package/src/SessionUser/components/{session-user-switch.jsx → session-user-switch.tsx} +16 -21
  257. package/src/SessionUser/components/{un-login.jsx → un-login.tsx} +10 -15
  258. package/src/SessionUser/components/{user-info.jsx → user-info.tsx} +16 -22
  259. package/src/SessionUser/index.tsx +26 -0
  260. package/src/SessionUser/libs/{translation.js → translation.ts} +3 -1
  261. package/src/SessionUser/libs/utils.ts +39 -0
  262. package/src/Sparkline/{index.jsx → index.tsx} +38 -22
  263. package/src/Spinner/index.tsx +20 -0
  264. package/src/Success/{index.jsx → index.tsx} +7 -13
  265. package/src/Tabs/{index.jsx → index.tsx} +26 -40
  266. package/src/TextCollapse/{index.jsx → index.tsx} +26 -21
  267. package/src/Theme/index.ts +0 -1
  268. package/src/Theme/theme-provider.tsx +1 -1
  269. package/src/Theme/theme.ts +6 -3
  270. package/src/Typography/{index.jsx → index.tsx} +19 -22
  271. package/src/Util/index.ts +14 -8
  272. package/src/Video/{index.jsx → index.tsx} +7 -10
  273. package/src/Wallet/{Action.jsx → Action.tsx} +16 -12
  274. package/src/Wallet/{Download.jsx → Download.tsx} +25 -21
  275. package/src/Wallet/{Open.jsx → Open.tsx} +8 -11
  276. package/src/WalletOSIcon/{index.jsx → index.tsx} +8 -16
  277. package/src/WebWalletSWKeeper/{index.jsx → index.tsx} +21 -24
  278. package/src/WechatPrompt/{index.jsx → index.tsx} +1 -0
  279. package/src/global.d.ts +15 -0
  280. package/src/type.d.ts +12 -3
  281. package/src/withTheme/{index.jsx → index.tsx} +12 -2
  282. package/src/withTracker/{index.jsx → index.tsx} +6 -4
  283. package/src/Layout/dashboard/external-link.jsx +0 -47
  284. package/src/Logo/index.jsx +0 -66
  285. package/src/Result/index.jsx +0 -33
  286. package/src/SessionPermission/index.jsx +0 -28
  287. package/src/SessionUser/components/session-user-item.jsx +0 -93
  288. package/src/SessionUser/index.jsx +0 -38
  289. package/src/SessionUser/libs/utils.js +0 -37
  290. package/src/Spinner/index.jsx +0 -21
  291. /package/src/ErrorBoundary/{index.jsx → index.ts} +0 -0
  292. /package/src/NFTDisplay/{loading.jsx → loading.tsx} +0 -0
  293. /package/src/Passport/{index.jsx → index.ts} +0 -0
  294. /package/src/SessionManager/{index.jsx → index.tsx} +0 -0
@@ -1,4 +1,4 @@
1
- import PropTypes from 'prop-types';
1
+ import { type SxProps } from '@mui/material';
2
2
 
3
3
  import phone from './shells/Phone';
4
4
  import macbook from './shells/Macbook';
@@ -9,10 +9,16 @@ const map = {
9
9
  macbook,
10
10
  };
11
11
 
12
- function Screenshot({ width, children, type, sx, ...rest }) {
12
+ export interface ScreenshotProps extends React.ComponentProps<'div'> {
13
+ width?: number;
14
+ type?: string;
15
+ sx?: SxProps;
16
+ }
17
+
18
+ function Screenshot({ width = 0, children, type = 'phone', ...rest }: ScreenshotProps) {
13
19
  const _type = type.toLowerCase();
14
20
 
15
- const { Shell, ratio, screenData, width: defaultWidth } = map[_type || 'phone'];
21
+ const { Shell, ratio, screenData, width: defaultWidth } = map[(_type as keyof typeof map) || 'phone'];
16
22
 
17
23
  const Root = styled('div')`
18
24
  position: relative;
@@ -64,16 +70,4 @@ function Screenshot({ width, children, type, sx, ...rest }) {
64
70
  );
65
71
  }
66
72
 
67
- Screenshot.propTypes = {
68
- width: PropTypes.number,
69
- type: PropTypes.string,
70
- children: PropTypes.node.isRequired,
71
- sx: PropTypes.object,
72
- };
73
- Screenshot.defaultProps = {
74
- width: 0,
75
- type: 'phone',
76
- sx: {},
77
- };
78
-
79
73
  export default Screenshot;
@@ -1,4 +1,6 @@
1
- export function Shell({ ...rest }) {
1
+ export interface ShellProps extends React.ComponentProps<'svg'> {}
2
+
3
+ export function Shell({ ...rest }: ShellProps) {
2
4
  return (
3
5
  <svg width="909" height="517" viewBox="0 0 909 517" fill="none" xmlns="http://www.w3.org/2000/svg" {...rest}>
4
6
  <path d="M48 16C48 7.16343 55.1634 0 64 0H845C853.837 0 861 7.16344 861 16V490H48V16Z" fill="black" />
@@ -1,7 +1,9 @@
1
1
  export const width = 268;
2
2
  export const height = 554;
3
3
 
4
- export function Shell({ ...rest }) {
4
+ export interface ShellProps extends React.ComponentProps<'svg'> {}
5
+
6
+ export function Shell({ ...rest }: ShellProps) {
5
7
  return (
6
8
  <svg width="268" height="554" viewBox="0 0 268 554" fill="none" xmlns="http://www.w3.org/2000/svg" {...rest}>
7
9
  <path
@@ -1,5 +1,5 @@
1
1
  import { createElement, Children, cloneElement, useEffect, useRef, useState } from 'react';
2
- import PropTypes from 'prop-types';
2
+ import { type SxProps } from '@mui/material';
3
3
 
4
4
  import { mergeProps } from '../Util';
5
5
  import { styled } from '../Theme';
@@ -7,6 +7,13 @@ import BaseScreenshot from './BaseScreenshot';
7
7
 
8
8
  import './devices.css';
9
9
 
10
+ type DeviceStyles = {
11
+ borderRadius: number;
12
+ width: number;
13
+ scale: number;
14
+ zIndex?: number;
15
+ };
16
+
10
17
  const types = {
11
18
  'iphone-x': {
12
19
  borderRadius: 32,
@@ -80,26 +87,26 @@ const childProps = {
80
87
  video: ['alt', 'title', 'muted', 'autoplay', 'loop', 'key', 'children'],
81
88
  };
82
89
 
83
- const createChild = (child) => [
90
+ const createChild = (child: React.ReactElement) => [
84
91
  createElement(
85
92
  child.type,
86
- childProps[child.type].reduce((acc, x) => {
93
+ childProps[child.type as keyof typeof childProps].reduce((acc: Record<string, any>, x: string) => {
87
94
  acc[x] = child.props[x];
88
95
  return acc;
89
96
  }, {})
90
97
  ),
91
98
  ];
92
99
 
93
- const findChildren = (children, returnArgWhenNotFound = true) => {
100
+ const findChildren = (children: React.ReactElement[], returnArgWhenNotFound = true): React.ReactElement[] | null => {
94
101
  for (let i = 0; i < children.length; i++) {
95
102
  const child = children[i];
96
103
 
97
- if (['img', 'video'].includes(child.type)) {
104
+ if (['img', 'video'].includes(child.type as string)) {
98
105
  return createChild(child);
99
106
  }
100
107
 
101
108
  if (child.props && child.props.children) {
102
- const subChildren = Children.toArray(child.props.children);
109
+ const subChildren = Children.toArray(child.props.children) as React.ReactElement[];
103
110
  const result = findChildren(subChildren, false);
104
111
  if (result) {
105
112
  return result;
@@ -114,18 +121,27 @@ const findChildren = (children, returnArgWhenNotFound = true) => {
114
121
  return null;
115
122
  };
116
123
 
124
+ export interface OldScreenshotProps extends React.ComponentProps<'div'> {
125
+ type?: keyof typeof types;
126
+ className?: string;
127
+ style?: React.CSSProperties;
128
+ width?: number;
129
+ height?: number;
130
+ sx?: SxProps;
131
+ }
132
+
117
133
  // This component is built upon the awesome device.css lib
118
134
  // By default it will find and only render img/video tags in the children
119
135
  // If neither of them are found, the whole child tree is rendered
120
- function OldScreenshot(props) {
121
- const newProps = mergeProps(props, OldScreenshot, ['style', 'width', 'height']);
136
+ function OldScreenshot(props: OldScreenshotProps) {
137
+ const newProps = mergeProps(props, OldScreenshot, ['style', 'width', 'height']) as OldScreenshotProps;
122
138
  const { type, children, style, className, width, height, ...rest } = newProps;
123
- const { zIndex = 0, borderRadius = 0 } = types[type] || {};
139
+ const { zIndex = 0, borderRadius = 0 } = (types[type!] || {}) as DeviceStyles;
124
140
 
125
141
  return (
126
142
  <Div
127
143
  {...rest}
128
- type={type}
144
+ type={type!}
129
145
  className={`device device-${type} ${className}`.trim()}
130
146
  style={style}
131
147
  contentRadius={borderRadius}
@@ -133,7 +149,9 @@ function OldScreenshot(props) {
133
149
  <div className="device-frame">
134
150
  <div className="device-content">
135
151
  {/* eslint-disable-next-line react/no-array-index-key */}
136
- {findChildren(Children.toArray(children)).map((item, index) => cloneElement(item, { key: index }))}
152
+ {findChildren(Children.toArray(children) as React.ReactElement[])?.map((item: any, index: number) =>
153
+ cloneElement(item, { key: index })
154
+ )}
137
155
  </div>
138
156
  </div>
139
157
  <div className="device-stripe" />
@@ -145,7 +163,21 @@ function OldScreenshot(props) {
145
163
  );
146
164
  }
147
165
 
148
- const Div = styled('div')`
166
+ OldScreenshot.defaultProps = {
167
+ type: 'iphone-x' as const,
168
+ className: '',
169
+ style: {},
170
+ width: 0,
171
+ height: 0,
172
+ };
173
+
174
+ type DivProps = {
175
+ type: keyof typeof types;
176
+ contentRadius: number;
177
+ contentZIndex: number;
178
+ };
179
+
180
+ const Div = styled('div')<DivProps>`
149
181
  @media (max-width: ${(props) => types[props.type].width}px) {
150
182
  transform-origin: 0 0;
151
183
  transform: scale(${(props) => types[props.type].scale});
@@ -165,41 +197,26 @@ const Div = styled('div')`
165
197
  }
166
198
  `;
167
199
 
168
- OldScreenshot.propTypes = {
169
- type: PropTypes.oneOf(Object.keys(types)),
170
- children: PropTypes.any.isRequired,
171
- className: PropTypes.string,
172
- width: PropTypes.number,
173
- height: PropTypes.number,
174
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
175
- };
176
-
177
- OldScreenshot.defaultProps = {
178
- type: 'iphone-x',
179
- className: '',
180
- style: '{}',
181
- width: 0,
182
- height: 0,
183
- };
200
+ export interface ScreenFixerProps extends OldScreenshotProps {}
184
201
 
185
202
  /**
186
203
  * 用于修正旧版 Screenshot 无法匹配尺寸的问题
187
204
  * @param {*} props params to OldScreenshot
188
205
  * @returns <OldScreenshot />
189
206
  */
190
- function ScreenFixer(props) {
191
- const screenEl = useRef(null);
192
- const [height, setHeight] = useState(undefined);
193
- const [scale, setScale] = useState(null);
207
+ function ScreenFixer(props: ScreenFixerProps) {
208
+ const screenEl = useRef<HTMLDivElement>(null);
209
+ const [height, setHeight] = useState<number>();
210
+ const [scale, setScale] = useState<number | null>(null);
194
211
 
195
212
  useEffect(() => {
196
- let resizeObs;
213
+ let resizeObs: ResizeObserver | null = null;
197
214
 
198
215
  const fixSize = () => {
199
- const { clientWidth } = screenEl.current;
216
+ const { clientWidth } = screenEl.current!;
200
217
 
201
218
  // 获取内部元素的宽高
202
- const { clientWidth: targetWidth, clientHeight: targetHeight } = screenEl.current.children[0];
219
+ const { clientWidth: targetWidth, clientHeight: targetHeight } = screenEl.current!.children[0];
203
220
 
204
221
  const realScale = clientWidth / targetWidth;
205
222
  if (realScale < 1) {
@@ -238,13 +255,18 @@ const ReScreen = styled('div')`
238
255
  }
239
256
  `;
240
257
 
241
- function Screenshot({ type, src, children, style, sx, ...rest }) {
258
+ export interface ScreenShotProps extends ScreenFixerProps {
259
+ type: keyof typeof types;
260
+ src?: string;
261
+ }
262
+
263
+ function Screenshot({ type, src = '', children, sx = {}, ...rest }: ScreenShotProps) {
242
264
  const _type = type.toLowerCase();
243
265
 
244
266
  // 新版采用容器采用BaseScreenshot,svg集成,更容易拓展,响应式更好
245
267
  if (['phone', 'macbook'].includes(_type)) {
246
268
  return (
247
- <BaseScreenshot type={_type} sx={{ ...sx, ...style }} {...rest}>
269
+ <BaseScreenshot type={_type} sx={sx} {...rest}>
248
270
  {children || (src ? <img src={src} alt="screenshot" /> : null)}
249
271
  </BaseScreenshot>
250
272
  );
@@ -252,25 +274,9 @@ function Screenshot({ type, src, children, style, sx, ...rest }) {
252
274
 
253
275
  // 旧版采用纯css制作,定制性欠缺,暂时保留使用
254
276
  return (
255
- <ScreenFixer type={type} {...rest} sx={{ ...sx, ...style, margin: 'auto' }}>
277
+ <ScreenFixer type={type} sx={{ ...sx, margin: 'auto' }} {...rest}>
256
278
  {children || (src ? <img src={src} alt="screenshot" /> : null)}
257
279
  </ScreenFixer>
258
280
  );
259
281
  }
260
-
261
- Screenshot.propTypes = {
262
- type: PropTypes.string.isRequired,
263
- src: PropTypes.string,
264
- style: PropTypes.object,
265
- sx: PropTypes.object,
266
- children: PropTypes.any,
267
- };
268
-
269
- Screenshot.defaultProps = {
270
- src: '',
271
- children: null,
272
- style: {},
273
- sx: {},
274
- };
275
-
276
282
  export default Screenshot;
@@ -1,5 +1,4 @@
1
1
  import { useRef } from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import {
4
3
  Box,
5
4
  ClickAwayListener,
@@ -22,8 +21,15 @@ import { temp as colors } from '../Colors';
22
21
  import { AUTH_SERVICE_PREFIX, NAVIGATION_URL } from '../Util/constant';
23
22
  import SessionPermission from '../SessionPermission';
24
23
  import { getTranslation } from '../Util';
24
+ import type { Locale } from '../type';
25
25
 
26
- export default function SessionBlocklet({ session, locale, size }) {
26
+ export interface SessionBlockletProps {
27
+ session: Record<string, any>;
28
+ locale?: Locale;
29
+ size?: number;
30
+ }
31
+
32
+ export default function SessionBlocklet({ session, locale = 'zh', size = 24 }: SessionBlockletProps) {
27
33
  const blocklet = window?.blocklet || {};
28
34
  const sessionMenuList = (blocklet.navigation || [])
29
35
  // HACK 过滤掉默认插入的 /sessionManager 菜单
@@ -60,7 +66,6 @@ export default function SessionBlocklet({ session, locale, size }) {
60
66
  </IconButton>
61
67
  <Popper
62
68
  open={currentState.open}
63
- onClose={() => onTogglePopper(false)}
64
69
  anchorEl={popperAnchorRef.current}
65
70
  transition
66
71
  placement="bottom-end"
@@ -169,14 +174,3 @@ export default function SessionBlocklet({ session, locale, size }) {
169
174
  </>
170
175
  );
171
176
  }
172
-
173
- SessionBlocklet.propTypes = {
174
- session: PropTypes.object.isRequired,
175
- locale: PropTypes.string,
176
- size: PropTypes.number,
177
- };
178
-
179
- SessionBlocklet.defaultProps = {
180
- locale: 'en',
181
- size: 24,
182
- };
@@ -0,0 +1,25 @@
1
+ import { useCreation } from 'ahooks';
2
+
3
+ const roleList = ['owner', 'admin', 'member', 'guest'] as const;
4
+
5
+ export interface SessionPermissionProps {
6
+ session: Record<string, any>;
7
+ roles?: (typeof roleList)[number][];
8
+ children: ((props: { hasPermission: boolean }) => JSX.Element | null) | JSX.Element;
9
+ }
10
+
11
+ export default function SessionPermission({ session, roles = ['owner', 'admin'], children }: SessionPermissionProps) {
12
+ const hasPermission = useCreation(() => {
13
+ return roles.includes(session?.user?.role || 'guest');
14
+ }, [session?.user?.role, roles]);
15
+
16
+ if (typeof children === 'function') {
17
+ return children({ hasPermission });
18
+ }
19
+
20
+ if (hasPermission) {
21
+ return children;
22
+ }
23
+
24
+ return null;
25
+ }
@@ -1,8 +1,18 @@
1
- import PropTypes from 'prop-types';
2
- import { useRef } from 'react';
1
+ import { ElementType, useRef } from 'react';
3
2
  import { useCreation, useMemoizedFn, useReactive } from 'ahooks';
4
- import { Box, ClickAwayListener, Divider, Fade, IconButton, MenuItem, MenuList, Paper, Popper } from '@mui/material';
5
- import { Icon } from '@iconify/react';
3
+ import {
4
+ Box,
5
+ type BoxProps,
6
+ ClickAwayListener,
7
+ Divider,
8
+ Fade,
9
+ IconButton,
10
+ MenuItem,
11
+ MenuList,
12
+ Paper,
13
+ Popper,
14
+ } from '@mui/material';
15
+ import { Icon, type IconifyIcon } from '@iconify/react';
6
16
  import PersonOutlineRoundedIcon from '@iconify-icons/material-symbols/person-outline-rounded';
7
17
  import FilterVintageOutlineRoundedIcon from '@iconify-icons/material-symbols/filter-vintage-outline-rounded';
8
18
  import AccountCircleOffOutlineRoundedIcon from '@iconify-icons/material-symbols/account-circle-off-outline-rounded';
@@ -19,20 +29,37 @@ import { DASHBOARD_URL, PROFILE_URL } from '../../Util/constant';
19
29
  import SessionPermission from '../../SessionPermission';
20
30
  import { translations } from '../libs/translation';
21
31
  import { translate } from '../../Locale/util';
32
+ import type { Locale, Session } from '../../type';
22
33
 
23
- const getInviteLink = (inviter) => {
34
+ const getInviteLink = (inviter: string) => {
24
35
  const url = new URL(window.location.href);
25
36
  url.searchParams.set('inviter', inviter);
26
37
  return url.toString();
27
38
  };
28
39
 
29
- export default function LoggedIn({ session, dark, onBindWallet, isBlocklet, locale, size }) {
40
+ export interface LoggedInProps {
41
+ session: Session;
42
+ dark?: false | true;
43
+ onBindWallet?: () => void;
44
+ isBlocklet?: true | false;
45
+ locale?: Locale;
46
+ size?: number;
47
+ }
48
+
49
+ export default function LoggedIn({
50
+ session,
51
+ dark = false,
52
+ onBindWallet = noop,
53
+ isBlocklet = true,
54
+ locale = 'en',
55
+ size = 24,
56
+ }: LoggedInProps) {
30
57
  const t = useMemoizedFn((key, data = {}) => {
31
58
  return translate(translations, key, locale, 'en', data);
32
59
  });
33
60
  const isInviteEnabled = useCreation(() => {
34
61
  return !!globalThis?.blocklet?.settings?.invite?.enabled;
35
- });
62
+ }, []);
36
63
  const popperAnchorRef = useRef(null);
37
64
  const currentState = useReactive({
38
65
  open: false,
@@ -47,8 +74,8 @@ export default function LoggedIn({ session, dark, onBindWallet, isBlocklet, loca
47
74
  session.switchPassport();
48
75
  });
49
76
  const handleSwitchAccount = useMemoizedFn(({ userSession } = {}) => {
50
- return new Promise((resolve) => {
51
- const options = {};
77
+ return new Promise<void>((resolve) => {
78
+ const options: Record<string, any> = {};
52
79
  if (!userSession) {
53
80
  onTogglePopper(false);
54
81
  options.showQuickConnect = false;
@@ -99,8 +126,8 @@ export default function LoggedIn({ session, dark, onBindWallet, isBlocklet, loca
99
126
 
100
127
  <Popper
101
128
  open={currentState.open}
102
- onClose={() => onTogglePopper(false)}
103
129
  anchorEl={popperAnchorRef.current}
130
+ // @ts-expect-error
104
131
  dark={dark}
105
132
  transition
106
133
  placement="bottom-end"
@@ -156,6 +183,7 @@ export default function LoggedIn({ session, dark, onBindWallet, isBlocklet, loca
156
183
  <SessionMenuItem
157
184
  icon={InviteIcon}
158
185
  title={t('invite')}
186
+ component="div"
159
187
  onClick={handleOpenInvite}
160
188
  sx={{ display: 'block', color: 'inherit' }}
161
189
  />
@@ -166,6 +194,7 @@ export default function LoggedIn({ session, dark, onBindWallet, isBlocklet, loca
166
194
  <SessionMenuItem
167
195
  icon={AccountCircleOffOutlineRoundedIcon}
168
196
  title={t('logout')}
197
+ component="div"
169
198
  sx={{ color: 'error.main' }}
170
199
  onClick={onLogout}
171
200
  data-cy="sessionManager-logout-trigger"
@@ -180,23 +209,17 @@ export default function LoggedIn({ session, dark, onBindWallet, isBlocklet, loca
180
209
  );
181
210
  }
182
211
 
183
- LoggedIn.propTypes = {
184
- session: PropTypes.object.isRequired,
185
- onBindWallet: PropTypes.func,
186
- dark: PropTypes.bool,
187
- isBlocklet: PropTypes.bool,
188
- locale: PropTypes.string,
189
- size: PropTypes.number,
190
- };
191
- LoggedIn.defaultProps = {
192
- dark: false,
193
- isBlocklet: true,
194
- onBindWallet: noop,
195
- locale: 'en',
196
- size: 24,
197
- };
212
+ interface SessionMenuItemProps {
213
+ icon: IconifyIcon | string;
214
+ title: string;
215
+ }
198
216
 
199
- function SessionMenuItem({ icon, title, ...rest }) {
217
+ // prop component is required
218
+ function SessionMenuItem<C extends ElementType>({
219
+ icon,
220
+ title,
221
+ ...rest
222
+ }: SessionMenuItemProps & BoxProps<C, { component: C }>) {
200
223
  return (
201
224
  <Box {...rest} sx={{ p: 0.5, ...rest?.sx }}>
202
225
  <MenuItem
@@ -216,8 +239,3 @@ function SessionMenuItem({ icon, title, ...rest }) {
216
239
  </Box>
217
240
  );
218
241
  }
219
-
220
- SessionMenuItem.propTypes = {
221
- icon: PropTypes.any.isRequired,
222
- title: PropTypes.string.isRequired,
223
- };
@@ -0,0 +1,97 @@
1
+ import { forwardRef } from 'react';
2
+ import { Box, type BoxProps, IconButton, Tooltip, Typography } from '@mui/material';
3
+ import { Icon } from '@iconify/react';
4
+ import LensIcon from '@iconify-icons/material-symbols/lens';
5
+
6
+ import WalletOSIcon from '../../WalletOSIcon';
7
+ import Avatar from '../../Avatar';
8
+ import DID from '../../DID';
9
+ import { temp as colors } from '../../Colors';
10
+ import { getSourceProvider } from '../libs/utils';
11
+ import { Session } from '../../type';
12
+
13
+ export interface SessionUserItemProps extends BoxProps {
14
+ sessionItem: Session;
15
+ statusContent?: React.ReactNode;
16
+ active?: false | true;
17
+ }
18
+
19
+ const SessionUserItem = forwardRef<HTMLDivElement, SessionUserItemProps>(
20
+ ({ sessionItem, statusContent = null, active = false, ...rest }, ref) => {
21
+ const isRawWalletAccount = getSourceProvider(sessionItem?.user) === 'wallet';
22
+
23
+ return (
24
+ <Box
25
+ {...rest}
26
+ ref={ref}
27
+ sx={{
28
+ display: 'flex',
29
+ alignItems: 'center',
30
+ justifyContent: 'space-between',
31
+ py: 0.75,
32
+ px: 1,
33
+ width: '100%',
34
+ ...rest?.sx,
35
+ }}>
36
+ <Box
37
+ sx={{
38
+ display: 'flex',
39
+ alignItems: 'center',
40
+ gap: 0.5,
41
+ overflow: 'hidden',
42
+ '& .did-address-avatar': {
43
+ display: 'none !important',
44
+ },
45
+ '& .did-address-text': {
46
+ color: `${colors.textBase} !important`,
47
+ },
48
+ }}>
49
+ <Box sx={{ mr: 0.5, fontSize: 0 }}>
50
+ <Avatar did={sessionItem.userDid} size={36} />
51
+ </Box>
52
+ <WalletOSIcon
53
+ loading={sessionItem.__isDefault}
54
+ provider={sessionItem?.extra?.provider}
55
+ walletOS={sessionItem?.extra?.walletOS}
56
+ />
57
+ {isRawWalletAccount ? (
58
+ <DID
59
+ did={sessionItem.userDid}
60
+ copyable={false}
61
+ size={14}
62
+ responsive={false}
63
+ compact
64
+ sx={{ lineHeight: 1 }}
65
+ />
66
+ ) : (
67
+ sessionItem.user.email && (
68
+ <Tooltip
69
+ title={sessionItem.user.email}
70
+ sx={{
71
+ zIndex: 1600,
72
+ }}
73
+ placement="top">
74
+ <Typography
75
+ sx={{
76
+ fontSize: 14,
77
+ overflow: 'hidden',
78
+ textOverflow: 'ellipsis',
79
+ }}>
80
+ {sessionItem.user.email}
81
+ </Typography>
82
+ </Tooltip>
83
+ )
84
+ )}
85
+ </Box>
86
+ {statusContent ||
87
+ (active && (
88
+ <IconButton size="small" disableRipple>
89
+ <Icon icon={LensIcon} fontSize={6} color={colors.surfaceSuccess} />
90
+ </IconButton>
91
+ ))}
92
+ </Box>
93
+ );
94
+ }
95
+ );
96
+
97
+ export default SessionUserItem;
@@ -1,4 +1,3 @@
1
- import PropTypes from 'prop-types';
2
1
  import {
3
2
  Box,
4
3
  ClickAwayListener,
@@ -23,8 +22,21 @@ import { temp as colors } from '../../Colors';
23
22
  import { getVisitorId } from '../../Util';
24
23
  import { translate } from '../../Locale/util';
25
24
  import { translations } from '../libs/translation';
25
+ import type { Locale, Session } from '../../type';
26
26
 
27
- export default function SessionUserSwitch({ session, onSwitch, isBlocklet, locale }) {
27
+ export interface SessionUserSwitchProps {
28
+ session: Session;
29
+ onSwitch: (params?: { userSession: Session }) => Promise<void> | void;
30
+ isBlocklet?: true | false;
31
+ locale?: Locale;
32
+ }
33
+
34
+ export default function SessionUserSwitch({
35
+ session,
36
+ onSwitch,
37
+ isBlocklet = true,
38
+ locale = 'en',
39
+ }: SessionUserSwitchProps) {
28
40
  const popperAnchorRef = useRef(null);
29
41
  const t = useMemoizedFn((key, data = {}) => {
30
42
  return translate(translations, key, locale, 'en', data);
@@ -32,7 +44,7 @@ export default function SessionUserSwitch({ session, onSwitch, isBlocklet, local
32
44
 
33
45
  const currentState = useReactive({
34
46
  open: false,
35
- userSessions: [],
47
+ userSessions: [] as Session[],
36
48
  loadingSessionId: null,
37
49
  });
38
50
 
@@ -136,12 +148,7 @@ export default function SessionUserSwitch({ session, onSwitch, isBlocklet, local
136
148
  onClick={() => onTogglePopper()}
137
149
  ref={popperAnchorRef}
138
150
  />
139
- <Popper
140
- open={currentState.open}
141
- onClose={() => onTogglePopper(false)}
142
- anchorEl={popperAnchorRef.current}
143
- transition
144
- sx={{ zIndex: 1600 }}>
151
+ <Popper open={currentState.open} anchorEl={popperAnchorRef.current} transition sx={{ zIndex: 1600 }}>
145
152
  {({ TransitionProps }) => (
146
153
  <ClickAwayListener
147
154
  onClickAway={(e) => {
@@ -223,15 +230,3 @@ export default function SessionUserSwitch({ session, onSwitch, isBlocklet, local
223
230
  </>
224
231
  );
225
232
  }
226
-
227
- SessionUserSwitch.propTypes = {
228
- session: PropTypes.object.isRequired,
229
- onSwitch: PropTypes.func.isRequired,
230
- isBlocklet: PropTypes.bool,
231
- locale: PropTypes.string,
232
- };
233
-
234
- SessionUserSwitch.defaultProps = {
235
- isBlocklet: true,
236
- locale: 'en',
237
- };