@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
package/src/Util/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import padStart from 'lodash/padStart';
3
3
  import { getDIDMotifInfo, colors } from '@arcblock/did-motif';
4
4
  import { DID_PREFIX, WELLKNOWN_SERVICE_PATH_PREFIX } from './constant';
5
- import type { $TSFixMe } from '../type';
5
+ import type { $TSFixMe, Locale } from '../type';
6
6
 
7
7
  let dateTool: $TSFixMe | null = null;
8
8
 
@@ -92,6 +92,11 @@ export const getBackground = (props: $TSFixMe) => {
92
92
  return props.theme.palette.common.white;
93
93
  };
94
94
 
95
+ /**
96
+ * 1. 将 props 中以 ::prop:: 开头的字符串替换为 component.defaultProps 中的值
97
+ * 2. 将 props 中由 jsonAttrs 指定的 json 字符串转换为对象
98
+ * 3. 最后将 props 中的 ::prop:: 字符串替换为 ''
99
+ */
95
100
  export function mergeProps<P extends object>(
96
101
  props: Record<string, any>,
97
102
  component: React.ComponentType<P>,
@@ -180,7 +185,7 @@ export function getDateTool() {
180
185
 
181
186
  const createDateFormatter =
182
187
  (format: string) =>
183
- (date: string, { locale, tz }: { locale?: string; tz?: string } = {}) => {
188
+ (date: string, { locale, tz }: { locale?: Locale; tz?: string } = {}) => {
184
189
  if (dateTool === null) {
185
190
  throw new Error('call setDateTool to set the date tool library, such as: setDateTool(dayjs)');
186
191
  }
@@ -207,7 +212,7 @@ const createDateFormatter =
207
212
  * Ensure that the setDateTool() function is called first to set the time tool library.
208
213
  * @returns formatted date string
209
214
  */
210
- export function formatToDate(date: string, { locale = 'en', tz }: { locale?: string; tz?: string } = {}) {
215
+ export function formatToDate(date: string, { locale = 'en', tz }: { locale?: Locale; tz?: string } = {}) {
211
216
  return createDateFormatter('ll')(date, { locale, tz });
212
217
  }
213
218
 
@@ -216,7 +221,7 @@ export function formatToDate(date: string, { locale = 'en', tz }: { locale?: str
216
221
  * Ensure that the setDateTool() function is called first to set the time tool library.
217
222
  * @returns formatted date string
218
223
  */
219
- export function formatToDatetime(date: string, { locale = 'en', tz }: { locale?: string; tz?: string } = {}) {
224
+ export function formatToDatetime(date: string, { locale = 'en', tz }: { locale?: Locale; tz?: string } = {}) {
220
225
  return createDateFormatter('lll')(date, { locale, tz });
221
226
  }
222
227
 
@@ -239,7 +244,7 @@ export function openWebWallet({
239
244
  }: {
240
245
  webWalletUrl: string;
241
246
  action?: string;
242
- locale?: string;
247
+ locale?: Locale;
243
248
  url: string;
244
249
  windowFeatures: $TSFixMe;
245
250
  }) {
@@ -409,15 +414,16 @@ type TranslationsObject = {
409
414
  * @return {string} The translated string based on the locale, with fallback options if necessary.
410
415
  */
411
416
  export const getTranslation = (
412
- translations: string | TranslationsObject,
413
- locale: string,
414
- options: { fallbackLocale?: string; defaultValue?: string } = {}
417
+ translations: TranslationsObject,
418
+ locale: Locale,
419
+ options: { fallbackLocale?: Locale; defaultValue?: string } = {}
415
420
  ) => {
416
421
  const { fallbackLocale = 'en', defaultValue = 'unknown' } = options;
417
422
 
418
423
  if (typeof translations === 'string') {
419
424
  return translations;
420
425
  }
426
+
421
427
  let translation;
422
428
  if (locale) {
423
429
  translation = translations[locale];
@@ -1,14 +1,18 @@
1
1
  import { useState } from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import Player from 'react-player';
4
3
  import CircularProgress from '@mui/material/CircularProgress';
5
4
 
6
5
  import { mergeProps } from '../Util';
7
6
  import { styled } from '../Theme';
8
7
 
9
- const { string, number, array, oneOfType, object } = PropTypes;
8
+ export interface VideoProps {
9
+ url: string;
10
+ width?: string | number;
11
+ height?: string | number;
12
+ style?: React.CSSProperties;
13
+ }
10
14
 
11
- export default function Video(props) {
15
+ export default function Video(props: VideoProps) {
12
16
  const newProps = mergeProps(props, Video, ['style']);
13
17
  const { url, width, height, style } = newProps;
14
18
  const [loaded, setLoaded] = useState(false);
@@ -36,13 +40,6 @@ export default function Video(props) {
36
40
  );
37
41
  }
38
42
 
39
- Video.propTypes = {
40
- url: oneOfType([string, array, object]).isRequired,
41
- width: oneOfType([string, number]),
42
- height: oneOfType([string, number]),
43
- style: oneOfType([string, object]),
44
- };
45
-
46
43
  Video.defaultProps = {
47
44
  width: 640,
48
45
  height: 400,
@@ -1,4 +1,3 @@
1
- import PropTypes from 'prop-types';
2
1
  import Typography from '@mui/material/Typography';
3
2
 
4
3
  import logo from './images/abtwallet.png';
@@ -7,7 +6,14 @@ import colors from '../Colors';
7
6
  import Button from '../Button';
8
7
  import { styled } from '../Theme';
9
8
 
10
- export default function WalletAction(props) {
9
+ export interface WalletActionProps {
10
+ action?: string;
11
+ size?: 'xlarge' | 'large' | 'medium' | 'small';
12
+ textLayout?: 'vertical' | 'horizontal';
13
+ style?: React.CSSProperties;
14
+ }
15
+
16
+ export default function WalletAction(props: WalletActionProps) {
11
17
  const newProps = mergeProps(props, WalletAction, ['style']);
12
18
  const { action, size, textLayout, style = {}, ...rest } = newProps;
13
19
  const styles = Object.assign({}, style, { border: 'none', padding: 0 });
@@ -32,17 +38,10 @@ export default function WalletAction(props) {
32
38
  );
33
39
  }
34
40
 
35
- WalletAction.propTypes = {
36
- action: PropTypes.string,
37
- size: PropTypes.oneOf(['xlarge', 'large', 'medium', 'small']),
38
- textLayout: PropTypes.oneOf(['vertical', 'horizontal']),
39
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
40
- };
41
-
42
41
  WalletAction.defaultProps = {
43
42
  action: 'Login',
44
- textLayout: 'vertical',
45
- size: 'medium',
43
+ textLayout: 'vertical' as const,
44
+ size: 'medium' as const,
46
45
  style: {},
47
46
  };
48
47
 
@@ -61,7 +60,12 @@ const sizes = {
61
60
  },
62
61
  };
63
62
 
64
- const Content = styled('div')`
63
+ type ContentProps = {
64
+ size: NonNullable<WalletActionProps['size']>;
65
+ color: string;
66
+ };
67
+
68
+ const Content = styled('div')<ContentProps>`
65
69
  display: flex;
66
70
  justify-content: center;
67
71
  align-items: center;
@@ -1,21 +1,31 @@
1
- import PropTypes from 'prop-types';
2
1
  import Typography from '@mui/material/Typography';
3
2
  import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
3
+ import { type SxProps } from '@mui/material';
4
4
 
5
- // eslint-disable-next-line import/no-unresolved
6
- import AppStoreIcon from './images/app-store.svg?react';
7
- // eslint-disable-next-line import/no-unresolved
8
- import GooglePlayIcon from './images/google-play.svg?react';
9
- // eslint-disable-next-line import/no-unresolved
10
- import AndroidDownloadIcon from './images/android_download.svg?react';
5
+ import { ReactComponent as AppStoreIcon } from './images/app-store.svg';
6
+ import { ReactComponent as GooglePlayIcon } from './images/google-play.svg';
7
+ import { ReactComponent as AndroidDownloadIcon } from './images/android_download.svg';
11
8
 
12
9
  import Button from '../Button';
13
10
  import { mergeProps } from '../Util';
14
11
  import { styled } from '../Theme';
12
+ import type { Locale } from '../type';
15
13
 
16
- export default function WalletDownload(props) {
14
+ export interface WalletDownloadProps extends React.HTMLAttributes<HTMLDivElement> {
15
+ title?: string;
16
+ layout?: 'vertical' | 'horizontal';
17
+ storeLayout?: 'vertical' | 'horizontal';
18
+ style?: React.CSSProperties;
19
+ iosLink?: string;
20
+ androidLink?: string;
21
+ androidDownLoadUrl?: string;
22
+ locale?: Locale;
23
+ sx?: SxProps;
24
+ }
25
+
26
+ export default function WalletDownload(props: WalletDownloadProps) {
17
27
  const browser = useBrowser();
18
- const newProps = mergeProps(props, WalletDownload, ['style']);
28
+ const newProps = mergeProps(props, WalletDownload, ['style']) as WalletDownloadProps;
19
29
  const { title, children, iosLink, androidLink, androidDownLoadUrl, locale, ...rest } = newProps;
20
30
 
21
31
  const isAndroid = browser.mobile.android.phone || browser.mobile.android.tablet;
@@ -77,17 +87,6 @@ export default function WalletDownload(props) {
77
87
  );
78
88
  }
79
89
 
80
- WalletDownload.propTypes = {
81
- title: PropTypes.string,
82
- layout: PropTypes.oneOf(['vertical', 'horizontal']),
83
- storeLayout: PropTypes.oneOf(['vertical', 'horizontal']),
84
- style: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
85
- iosLink: PropTypes.string,
86
- androidLink: PropTypes.string,
87
- androidDownLoadUrl: PropTypes.string,
88
- locale: PropTypes.oneOf(['en', 'zh']),
89
- };
90
-
91
90
  WalletDownload.defaultProps = {
92
91
  title: 'Download DID Wallet',
93
92
  layout: 'vertical',
@@ -97,9 +96,14 @@ WalletDownload.defaultProps = {
97
96
  androidDownLoadUrl: 'https://releases.arcblockio.cn/arcwallet_android/latest/abtwallet.apk',
98
97
  style: {},
99
98
  locale: 'zh',
99
+ } as const;
100
+
101
+ type ContainerProps = {
102
+ layout?: WalletDownloadProps['layout'];
103
+ storeLayout?: WalletDownloadProps['storeLayout'];
100
104
  };
101
105
 
102
- const Container = styled('div')`
106
+ const Container = styled('div')<ContainerProps>`
103
107
  display: flex;
104
108
  flex-direction: ${(props) => (props.layout === 'vertical' ? 'column' : 'row')};
105
109
  align-items: center;
@@ -1,10 +1,15 @@
1
- import PropTypes from 'prop-types';
2
1
  import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
3
2
  import Fab from '@mui/material/Fab';
4
3
 
5
4
  import { styled } from '../Theme';
5
+ import type { Locale } from '../type';
6
6
 
7
- export default function OpenInWallet({ locale, link }) {
7
+ export interface OpenInWalletProps {
8
+ link: string;
9
+ locale?: Locale;
10
+ }
11
+
12
+ export default function OpenInWallet({ link, locale = 'zh' }: OpenInWalletProps) {
8
13
  const buttonText = locale === 'zh' ? '在 DID 钱包打开' : 'Open in DID Wallet';
9
14
  const browser = useBrowser();
10
15
 
@@ -17,6 +22,7 @@ export default function OpenInWallet({ locale, link }) {
17
22
  href={deepLink}
18
23
  variant="extended"
19
24
  color="primary"
25
+ // @ts-expect-error
20
26
  rounded
21
27
  target="_blank"
22
28
  className="open-in-wallet-button">
@@ -27,15 +33,6 @@ export default function OpenInWallet({ locale, link }) {
27
33
  return null;
28
34
  }
29
35
 
30
- OpenInWallet.propTypes = {
31
- locale: PropTypes.oneOf(['en', 'zh']),
32
- link: PropTypes.string.isRequired,
33
- };
34
-
35
- OpenInWallet.defaultProps = {
36
- locale: 'zh',
37
- };
38
-
39
36
  const Button = styled(Fab)`
40
37
  && {
41
38
  font-size: 12px;
@@ -1,4 +1,3 @@
1
- import PropTypes from 'prop-types';
2
1
  import { Icon } from '@iconify/react';
3
2
  import ApiIcon from '@iconify-icons/mdi/api';
4
3
  import IOSRoundedIcon from '@iconify-icons/material-symbols/ios-rounded';
@@ -9,7 +8,14 @@ import QuestionMarkRoundedIcon from '@iconify-icons/material-symbols/question-ma
9
8
  import MailOutlineRoundedIcon from '@iconify-icons/material-symbols/mail-outline-rounded';
10
9
  import { LOGIN_PROVIDER } from '../Util/constant';
11
10
 
12
- export default function WalletOSIcon({ loading, walletOS, provider, color }) {
11
+ export interface WalletOSIconProps {
12
+ loading?: false | true;
13
+ walletOS?: string;
14
+ provider?: string;
15
+ color?: string;
16
+ }
17
+
18
+ export default function WalletOSIcon({ loading = false, walletOS, provider, color = 'black' }: WalletOSIconProps) {
13
19
  if (loading) {
14
20
  return <Icon icon={QuestionMarkRoundedIcon} style={{ color: 'transparent' }} />;
15
21
  }
@@ -31,17 +37,3 @@ export default function WalletOSIcon({ loading, walletOS, provider, color }) {
31
37
  }
32
38
  return null;
33
39
  }
34
-
35
- WalletOSIcon.propTypes = {
36
- loading: PropTypes.bool,
37
- walletOS: PropTypes.string,
38
- provider: PropTypes.string,
39
- color: PropTypes.string,
40
- };
41
-
42
- WalletOSIcon.defaultProps = {
43
- loading: false,
44
- walletOS: null,
45
- provider: null,
46
- color: 'black',
47
- };
@@ -1,5 +1,4 @@
1
1
  import { useEffect, useRef } from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import useIdle from 'react-use/lib/useIdle';
4
3
  import { useLocalStorageState } from 'ahooks';
5
4
  import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
@@ -12,21 +11,21 @@ const DEFAULT_MAX_IDLE_TIME = 1000 * 60 * 30;
12
11
  // 可使用 localStorage.setItem('wallet_sw_keeper_disabled', 1) 来禁用嵌入 wallet iframe
13
12
  const STORAGE_KEY_DISABLED = 'wallet_sw_keeper_disabled';
14
13
  // iframe id, 如果存在多个 WebWalletSWKeeper 组件实例, 共享此 id, 保证只有一个 iframe
15
- let id;
14
+ let id: string;
16
15
 
17
- const injectIframe = (webWalletUrl) => {
16
+ const injectIframe = (webWalletUrl: string) => {
18
17
  const iframe = document.createElement('iframe');
19
18
  iframe.title = 'abt wallet';
20
19
  iframe.id = id;
21
- iframe.style.width = 0;
22
- iframe.style.height = 0;
23
- iframe.style.border = 0;
20
+ iframe.style.width = '0';
21
+ iframe.style.height = '0';
22
+ iframe.style.border = '0';
24
23
  // https://stackoverflow.com/questions/27858989/iframe-with-0-height-creates-a-gap
25
24
  iframe.style.display = 'block';
26
25
  // fix: 页面自动滚动到底部问题 (https://github.com/blocklet/abt-wallet/issues/1160)
27
26
  // top: 0 可能不是必须的, 但测试中发现, 如果不设置, 在某些特殊情况下似乎也会导致页面自动滚动到底部
28
27
  iframe.style.position = 'absolute';
29
- iframe.style.top = 0;
28
+ iframe.style.top = '0';
30
29
  iframe.src = `${webWalletUrl}?action=iframe`;
31
30
  document.body.appendChild(iframe);
32
31
  };
@@ -40,18 +39,23 @@ const removeIframe = () => {
40
39
 
41
40
  const cleanup = () => {
42
41
  removeIframe();
43
- id = null;
42
+ id = '';
44
43
  };
45
44
 
46
- const enable = (webWalletUrl) => {
45
+ const enable = (webWalletUrl: string) => {
47
46
  if (!id) {
48
47
  id = `web_wallet_sw_keeper_${Date.now()}`;
49
48
  injectIframe(webWalletUrl);
50
49
  }
51
50
  };
52
51
 
52
+ interface WebWalletSWKeeperProps {
53
+ webWalletUrl: string;
54
+ maxIdleTime: number;
55
+ }
56
+
53
57
  // 该组件通过嵌入一个 web wallet iframe 帮助 web wallet service worker 延最大空闲时间
54
- function WebWalletSWKeeper({ webWalletUrl, maxIdleTime }) {
58
+ function WebWalletSWKeeper({ webWalletUrl, maxIdleTime = DEFAULT_MAX_IDLE_TIME }: WebWalletSWKeeperProps) {
55
59
  // 渲染前先记录是否已经存在一个 WebWalletSWKeeper 实例
56
60
  const instanceExists = useRef(!!id);
57
61
  const isIdle = useIdle(maxIdleTime);
@@ -75,20 +79,9 @@ function WebWalletSWKeeper({ webWalletUrl, maxIdleTime }) {
75
79
  return null;
76
80
  }
77
81
 
78
- WebWalletSWKeeper.propTypes = {
79
- webWalletUrl: PropTypes.string.isRequired,
80
- maxIdleTime: PropTypes.number,
81
- };
82
-
83
- WebWalletSWKeeper.defaultProps = {
84
- maxIdleTime: DEFAULT_MAX_IDLE_TIME,
85
- };
86
-
87
- export default WebWalletSWKeeper;
88
-
89
- export const withWebWalletSWKeeper = (Component) => {
82
+ export const withWebWalletSWKeeper = <P extends { webWalletUrl: string }>(Component: React.ComponentType<P>) => {
90
83
  // eslint-disable-next-line react/prop-types
91
- return function WithWebWalletSWKeeperComponent({ webWalletUrl, maxIdleTime, ...rest }) {
84
+ return function WithWebWalletSWKeeperComponent({ webWalletUrl, maxIdleTime, ...rest }: WebWalletSWKeeperProps & P) {
92
85
  const browser = useBrowser();
93
86
  // eslint-disable-next-line no-param-reassign
94
87
  webWalletUrl = webWalletUrl || getWebWalletUrl();
@@ -103,13 +96,17 @@ export const withWebWalletSWKeeper = (Component) => {
103
96
  // - 检查到 wallet 浏览器插件
104
97
  // - webWalletUrl 与当前页面 url 的 protocol 不同
105
98
  // - wallet webview
99
+
100
+ const props = { webWalletUrl, ...rest } as unknown as P;
106
101
  return (
107
102
  <>
108
103
  {!disabled && !extension && isSameProtocol && !isWalletWebview && (
109
104
  <WebWalletSWKeeper webWalletUrl={webWalletUrl} maxIdleTime={maxIdleTime} />
110
105
  )}
111
- <Component webWalletUrl={webWalletUrl} {...rest} />
106
+ <Component {...props} />
112
107
  </>
113
108
  );
114
109
  };
115
110
  };
111
+
112
+ export default WebWalletSWKeeper;
@@ -17,6 +17,7 @@ export default function WechatPrompt() {
17
17
  return null;
18
18
  }
19
19
 
20
+ // @ts-expect-error
20
21
  if (browser.android) {
21
22
  return (
22
23
  <Dialog open fullScreen>
package/src/global.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  declare module '@arcblock/did-motif';
2
+ declare module 'd3-geo';
3
+ declare module 'topojson-client';
4
+ declare module 'versor';
5
+ declare module 'axios/*';
6
+
7
+ // ux svg 由 babel-plugin-inline-react-svg 处理
8
+ declare module '*.svg' {
9
+ import * as React from 'react';
10
+ const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
11
+ export { ReactComponent };
12
+ }
13
+
14
+ declare module '*.png' {
15
+ export default string;
16
+ }
2
17
 
3
18
  type Blocklet = import('./type').Blocklet;
4
19
 
package/src/type.d.ts CHANGED
@@ -1,5 +1,14 @@
1
+ import type { Theme } from '@mui/material';
2
+ import type { LiteralUnion } from 'type-fest';
3
+
1
4
  export type $TSFixMe = any;
5
+ export type Translations = Record<string, Record<string, any>>;
6
+ export type Locale = LiteralUnion<'en' | 'zh', string>;
2
7
 
8
+ // TODO: 以下为 blocklet 应用专属的全局对象类型,可以更加具体
9
+ export type User = Record<string, any>;
10
+ export type Session = Record<string, any>;
11
+ export type Passport = Record<string, any>;
3
12
  export type Blocklet = {
4
13
  appId: string;
5
14
  appIds: string[];
@@ -16,15 +25,15 @@ export type Blocklet = {
16
25
  version: string;
17
26
  mode: string;
18
27
  tenantMode: 'single' | 'multiple';
19
- theme: TTheme;
20
- navigation: TNavigation[];
28
+ theme: Theme;
29
+ navigation: $TSFixMe[];
21
30
  preferences: Record<string, any>;
22
31
  languages: {
23
32
  code: string;
24
33
  name: string;
25
34
  }[];
26
35
  passportColor: string;
27
- componentMountPoints: TComponent[];
36
+ componentMountPoints: $TSFixMe[];
28
37
  alsoKnownAs: string[];
29
38
  trustedFactories: string[];
30
39
  [x: string]: any;
@@ -1,10 +1,20 @@
1
1
  import { useEffect } from 'react';
2
2
  import { Global, css } from '@emotion/react';
3
3
  import CssBaseline from '@mui/material/CssBaseline';
4
+ import { type PaletteOptions } from '@mui/material/styles/createPalette';
5
+ import { type TypographyOptions } from '@mui/material/styles/createTypography';
4
6
 
5
7
  import { createTheme, ThemeProvider } from '../Theme';
6
8
 
7
- function withTheme(Component, { mode = 'light', pageWidth = 'md', palette, typography } = {}) {
9
+ function withTheme<P extends object>(
10
+ Component: React.ComponentType<P>,
11
+ {
12
+ mode = 'light',
13
+ pageWidth = 'md',
14
+ palette,
15
+ typography,
16
+ }: { mode?: string; pageWidth?: string; palette?: PaletteOptions; typography?: TypographyOptions } = {}
17
+ ) {
8
18
  const theme = createTheme({ mode, pageWidth, palette, typography });
9
19
 
10
20
  const globalStyles = css`
@@ -41,7 +51,7 @@ function withTheme(Component, { mode = 'light', pageWidth = 'md', palette, typog
41
51
  }
42
52
  `;
43
53
 
44
- return function WithTheme(props) {
54
+ return function WithTheme(props: P) {
45
55
  useEffect(() => {
46
56
  const jssStyles = document.querySelector('#jss-server-side');
47
57
  if (jssStyles && jssStyles.parentNode) {
@@ -2,9 +2,9 @@ import { useLocation } from 'react-router-dom';
2
2
  import { useMount, useDeepCompareEffect } from 'ahooks';
3
3
  import ReactGA from 'react-ga4';
4
4
 
5
- export default (WrappedComponent) => {
5
+ export default <P extends object>(WrappedComponent: React.ComponentType<P>) => {
6
6
  const trackingId = window.blocklet?.GA_MEASUREMENT_ID || '';
7
- const trackPage = (page, title = document.title) => {
7
+ const trackPage = (page: string, title = document.title) => {
8
8
  if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
9
9
  return;
10
10
  }
@@ -14,7 +14,7 @@ export default (WrappedComponent) => {
14
14
  }
15
15
  };
16
16
 
17
- const trackEvent = (category, action, label, value) => {
17
+ const trackEvent = (category: string, action: string, label: string, value: number) => {
18
18
  if (trackingId) {
19
19
  ReactGA.event({ category, action, label, value, transport: 'beacon' });
20
20
  }
@@ -24,10 +24,12 @@ export default (WrappedComponent) => {
24
24
  ReactGA.initialize(trackingId);
25
25
  }
26
26
 
27
+ // @ts-ignore
27
28
  window.trackPage = trackPage;
29
+ // @ts-ignore
28
30
  window.trackEvent = trackEvent;
29
31
 
30
- return function TrackedComponent(props) {
32
+ return function TrackedComponent(props: P) {
31
33
  const location = useLocation();
32
34
 
33
35
  useMount(() => {
@@ -1,47 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { Link as RouterLink, NavLink as RouterNavLink } from 'react-router-dom';
3
-
4
- // 包裹 router Link/NavLink 组件, 支持 external link (external 为 true 时渲染为 a 标签)
5
- function ExternalLink({ children, routerLinkComponent: RouterLinkComponent, to, external, ...rest }) {
6
- if (external) {
7
- return (
8
- <a href={to} {...rest}>
9
- {children}
10
- </a>
11
- );
12
- }
13
- return (
14
- <RouterLinkComponent to={to} {...rest}>
15
- {children}
16
- </RouterLinkComponent>
17
- );
18
- }
19
-
20
- ExternalLink.propTypes = {
21
- children: PropTypes.any.isRequired,
22
- routerLinkComponent: PropTypes.elementType.isRequired,
23
- external: PropTypes.bool,
24
- to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
25
- };
26
-
27
- ExternalLink.defaultProps = {
28
- external: false,
29
- };
30
-
31
- export function Link(props) {
32
- return <ExternalLink routerLinkComponent={RouterLink} {...props} />;
33
- }
34
-
35
- export function NavLink({ className, ...rest }) {
36
- // NavLink#className 支持 function
37
- const classes = rest.external && typeof className === 'function' ? className({}) : className;
38
- return <ExternalLink routerLinkComponent={RouterNavLink} className={classes} {...rest} />;
39
- }
40
-
41
- NavLink.propTypes = {
42
- className: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
43
- };
44
-
45
- NavLink.defaultProps = {
46
- className: '',
47
- };
@@ -1,66 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- import { styled } from '../Theme';
4
-
5
- // eslint-disable-next-line import/no-unresolved
6
- import LightLogo from './images/logo-light-top.svg?react';
7
- // eslint-disable-next-line import/no-unresolved
8
- import LightText from './images/logo-light-text.svg?react';
9
- // eslint-disable-next-line import/no-unresolved
10
- import DarkLogo from './images/logo-dark-top.svg?react';
11
- // eslint-disable-next-line import/no-unresolved
12
- import DarkText from './images/logo-dark-text.svg?react';
13
-
14
- /**
15
- @typedef {import('react').HTMLAttributes<HTMLSpanElement> & {
16
- mode?: 'light' | 'dark',
17
- layout?: 'vertical' | 'horizontal',
18
- showText?: boolean,
19
- showLogo?: boolean,
20
- }} LogoProps
21
- */
22
-
23
- /**
24
- * @description
25
- * @export
26
- * @param {LogoProps} props
27
- * @return {React.ReactComponentElement}
28
- */
29
- export default function Logo({ showText, showLogo, mode, layout, ...rest }) {
30
- const logo = mode === 'light' ? <LightLogo /> : <DarkLogo />;
31
- const text = mode === 'light' ? <LightText className="logo-text" /> : <DarkText className="logo-text" />;
32
-
33
- return (
34
- <Container layout={layout} {...rest}>
35
- {showLogo && logo}
36
- {showText && text}
37
- </Container>
38
- );
39
- }
40
-
41
- Logo.propTypes = {
42
- mode: PropTypes.oneOf(['light', 'dark']),
43
- layout: PropTypes.oneOf(['vertical', 'horizontal']),
44
- showText: PropTypes.bool,
45
- showLogo: PropTypes.bool,
46
- };
47
-
48
- Logo.defaultProps = {
49
- mode: 'dark',
50
- layout: 'vertical',
51
- showText: true,
52
- showLogo: true,
53
- };
54
-
55
- /** @type {import('@emotion/styled').StyledComponent<HTMLSpanElement, {}, { ref?: React.Ref<any> | undefined;}>} */
56
- const Container = styled('span')`
57
- display: inline-flex;
58
- flex-direction: ${(props) => (props.layout === 'horizontal' ? 'row' : 'column')};
59
- justify-content: center;
60
- align-items: center;
61
-
62
- .logo-text {
63
- ${(props) => (props.layout === 'vertical' ? 'margin-top: 8px;' : '')}
64
- ${(props) => (props.layout === 'vertical' ? '' : 'margin-left: 8px;')};
65
- }
66
- `;