@arcblock/ux 2.11.14 → 2.11.16

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.
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import React from "react";
3
+ import { useState } from 'react';
3
4
  import { useMemoizedFn } from 'ahooks';
4
5
  import { MenuItem, Divider } from '@mui/material';
5
6
  import { Icon } from '@iconify/react';
@@ -45,6 +46,7 @@ DIDSpaceIcon.defaultProps = {
45
46
  };
46
47
  import { DID_SPACE_URL } from '../../Util/constant';
47
48
  import { TBox } from '../../MuiWrap';
49
+ import Typography from '../../Typography';
48
50
  export default function DidSpace({
49
51
  session,
50
52
  locale = 'en',
@@ -54,6 +56,13 @@ export default function DidSpace({
54
56
  return translate(translations, key, locale, 'en', data);
55
57
  });
56
58
  const didSpace = session.user?.didSpace ?? {};
59
+ const [offset, setOffset] = useState(0);
60
+ const onShrink = useMemoizedFn(({
61
+ fontSize,
62
+ initialSize
63
+ }) => {
64
+ setOffset(Math.ceil((initialSize - fontSize) / 4));
65
+ });
57
66
  return /*#__PURE__*/_jsxs(_Fragment, {
58
67
  children: [/*#__PURE__*/_jsx(TBox, {
59
68
  component: "a",
@@ -68,26 +77,51 @@ export default function DidSpace({
68
77
  sx: {
69
78
  display: 'flex',
70
79
  alignItems: 'center',
71
- gap: 1,
80
+ gap: 0.5,
72
81
  '&:hover': {
73
82
  backgroundColor: `${colors.surfacePrimarySubtitle} !important`
74
83
  },
75
84
  py: 1
76
85
  },
77
- children: [/*#__PURE__*/_jsx(DIDSpaceIcon, {
86
+ children: [/*#__PURE__*/_jsx("div", {
87
+ style: {
88
+ display: 'flex',
89
+ alignItems: 'center'
90
+ },
91
+ children: /*#__PURE__*/_jsx(DIDSpaceIcon, {
92
+ style: {
93
+ height: '24px',
94
+ marginLeft: '-24px',
95
+ marginRight: '-28px'
96
+ }
97
+ })
98
+ }), /*#__PURE__*/_jsx("span", {
78
99
  style: {
79
- height: '24px',
80
- marginLeft: '-24px',
81
- marginRight: '-24px'
82
- }
83
- }), /*#__PURE__*/_jsxs("span", {
100
+ color: colors.foregroundsFgSubtile
101
+ },
102
+ children: ":"
103
+ }), /*#__PURE__*/_jsx("div", {
84
104
  style: {
85
105
  flexGrow: 1,
86
106
  minWidth: 0,
87
- color: didSpace.did ? colors.foregroundsFgSubtile : colors.textMuted
107
+ color: didSpace.did ? colors.foregroundsFgSubtile : colors.textMuted,
108
+ overflow: 'hidden',
109
+ whiteSpace: 'nowrap'
88
110
  },
89
- children: [": ", didSpace.did ? didSpace.name : t('disconnected')]
111
+ children: /*#__PURE__*/_jsx(Typography, {
112
+ fontSize: "auto",
113
+ minFontSize: 1,
114
+ sx: {
115
+ marginTop: `${offset}px`
116
+ },
117
+ onShrink: onShrink,
118
+ children: didSpace.did ? didSpace.name : t('disconnected')
119
+ })
90
120
  }), /*#__PURE__*/_jsx(Icon, {
121
+ style: {
122
+ marginTop: `${offset}px`,
123
+ flexShrink: 0
124
+ },
91
125
  icon: LensIcon,
92
126
  fontSize: 8,
93
127
  color: didSpace.did ? colors.surfaceSuccess : colors.gray6
@@ -2,5 +2,9 @@ import { type TypographyProps as MuiTypographyProps } from '@mui/material';
2
2
  export interface TypographyProps extends MuiTypographyProps {
3
3
  fontSize?: string | number;
4
4
  minFontSize?: number;
5
+ onShrink?: ({ fontSize, initialSize }: {
6
+ fontSize: number;
7
+ initialSize: number;
8
+ }) => void;
5
9
  }
6
- export default function Typography({ children, minFontSize, fontSize, sx, ...rest }: TypographyProps): import("react/jsx-runtime").JSX.Element;
10
+ export default function Typography({ children, minFontSize, fontSize, sx, onShrink, ...rest }: TypographyProps): import("react/jsx-runtime").JSX.Element;
@@ -2,11 +2,28 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Typography as MuiTypography, Skeleton } from '@mui/material';
3
3
  import { useCreation, useReactive, useSize } from 'ahooks';
4
4
  import { useEffect, useRef } from 'react';
5
+ const noop = (...args) => {};
6
+ let minBrowserFontSize = -1;
7
+ function detectMinimumFontSize() {
8
+ const testDiv = document.createElement('div');
9
+ Object.assign(testDiv.style, {
10
+ fontSize: '1px',
11
+ visibility: 'hidden',
12
+ position: 'absolute'
13
+ });
14
+ testDiv.textContent = 'Test';
15
+ document.body.appendChild(testDiv);
16
+ const size = parseFloat(getComputedStyle(testDiv).fontSize);
17
+ document.body.removeChild(testDiv);
18
+ return size;
19
+ }
5
20
  export default function Typography({
6
21
  children = null,
7
22
  minFontSize = 12,
23
+ /* 设置为 auto 时字体会自动收缩,直到达到浏览器最小字体限制 */
8
24
  fontSize,
9
25
  sx,
26
+ onShrink = noop,
10
27
  ...rest
11
28
  }) {
12
29
  const refMock = useRef(null);
@@ -26,11 +43,26 @@ export default function Typography({
26
43
  state.initialSize = Number(styleSize.replace('px', ''));
27
44
  state.fontSize = state.initialSize;
28
45
  }
29
- if (containerSize && mockSize) {
46
+ if (minBrowserFontSize < 0) {
47
+ minBrowserFontSize = detectMinimumFontSize();
48
+ }
49
+ // 达到浏览器最小字体限制,停止缩放
50
+ if (state.fontSize <= minBrowserFontSize) {
51
+ state.loading = false;
52
+ onShrink?.({
53
+ fontSize: state.fontSize,
54
+ initialSize: state.initialSize
55
+ });
56
+ } else if (containerSize && mockSize) {
57
+ // 超过容器宽度,尝试收缩
30
58
  if (containerSize.width < mockSize.width && state.fontSize > minFontSize) {
31
59
  state.fontSize--;
32
60
  } else {
33
61
  state.loading = false;
62
+ onShrink?.({
63
+ fontSize: state.fontSize,
64
+ initialSize: state.initialSize
65
+ });
34
66
  }
35
67
  }
36
68
  } else {
@@ -8,7 +8,7 @@ export declare const RELAY_SOCKET_PREFIX = "/.well-known/service";
8
8
  export declare const API_DID_PREFIX = "/api/did";
9
9
  export declare const DASHBOARD_URL = "/.well-known/service/admin";
10
10
  export declare const PROFILE_URL = "/.well-known/service/user";
11
- export declare const DID_SPACE_URL = "/.well-known/service/user/settings";
11
+ export declare const DID_SPACE_URL = "/.well-known/service/user/settings#storage";
12
12
  export declare const NAVIGATION_URL = "/.well-known/service/admin/navigation";
13
13
  export declare const DID_PREFIX = "did:abt:";
14
14
  export declare const PASSPORT_STATUS: {
@@ -8,7 +8,7 @@ export const RELAY_SOCKET_PREFIX = '/.well-known/service';
8
8
  export const API_DID_PREFIX = '/api/did';
9
9
  export const DASHBOARD_URL = `${AUTH_SERVICE_PREFIX}/admin`;
10
10
  export const PROFILE_URL = `${AUTH_SERVICE_PREFIX}/user`;
11
- export const DID_SPACE_URL = `${AUTH_SERVICE_PREFIX}/user/settings`;
11
+ export const DID_SPACE_URL = `${AUTH_SERVICE_PREFIX}/user/settings#storage`;
12
12
  export const NAVIGATION_URL = `${AUTH_SERVICE_PREFIX}/admin/navigation`;
13
13
  export const DID_PREFIX = 'did:abt:';
14
14
  export const PASSPORT_STATUS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.11.14",
3
+ "version": "2.11.16",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -68,12 +68,12 @@
68
68
  "react": ">=18.2.0",
69
69
  "react-router-dom": ">=6.22.3"
70
70
  },
71
- "gitHead": "6e1596d1a8ab9b74fd0588be21beb80eaeb68e35",
71
+ "gitHead": "1216fcd112e02c4135f5d748fe002cafaaebcfd9",
72
72
  "dependencies": {
73
73
  "@arcblock/did-motif": "^1.1.13",
74
- "@arcblock/icons": "^2.11.14",
75
- "@arcblock/nft-display": "^2.11.14",
76
- "@arcblock/react-hooks": "^2.11.14",
74
+ "@arcblock/icons": "^2.11.16",
75
+ "@arcblock/nft-display": "^2.11.16",
76
+ "@arcblock/react-hooks": "^2.11.16",
77
77
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
78
78
  "@fontsource/inter": "^5.0.16",
79
79
  "@fontsource/ubuntu-mono": "^5.0.18",
@@ -1,3 +1,4 @@
1
+ import { useState } from 'react';
1
2
  import { useMemoizedFn } from 'ahooks';
2
3
  import { MenuItem, BoxProps, Divider } from '@mui/material';
3
4
  import { Icon } from '@iconify/react';
@@ -9,6 +10,7 @@ import { translations } from '../libs/translation';
9
10
  import DIDSpaceIcon from '../images/did-spaces.svg?react';
10
11
  import { DID_SPACE_URL } from '../../Util/constant';
11
12
  import { TBox } from '../../MuiWrap';
13
+ import Typography from '../../Typography';
12
14
 
13
15
  export interface DidSpaceProps extends BoxProps {
14
16
  session: Session;
@@ -21,6 +23,10 @@ export default function DidSpace({ session, locale = 'en', ...rest }: DidSpacePr
21
23
  });
22
24
 
23
25
  const didSpace = session.user?.didSpace ?? {};
26
+ const [offset, setOffset] = useState(0);
27
+ const onShrink = useMemoizedFn(({ fontSize, initialSize }: { fontSize: number; initialSize: number }) => {
28
+ setOffset(Math.ceil((initialSize - fontSize) / 4));
29
+ });
24
30
 
25
31
  return (
26
32
  <>
@@ -29,22 +35,34 @@ export default function DidSpace({ session, locale = 'en', ...rest }: DidSpacePr
29
35
  sx={{
30
36
  display: 'flex',
31
37
  alignItems: 'center',
32
- gap: 1,
38
+ gap: 0.5,
33
39
  '&:hover': {
34
40
  backgroundColor: `${colors.surfacePrimarySubtitle} !important`,
35
41
  },
36
42
  py: 1,
37
43
  }}>
38
- <DIDSpaceIcon style={{ height: '24px', marginLeft: '-24px', marginRight: '-24px' }} />
39
- <span
44
+ <div style={{ display: 'flex', alignItems: 'center' }}>
45
+ <DIDSpaceIcon style={{ height: '24px', marginLeft: '-24px', marginRight: '-28px' }} />
46
+ </div>
47
+ <span style={{ color: colors.foregroundsFgSubtile }}>:</span>
48
+ <div
40
49
  style={{
41
50
  flexGrow: 1,
42
51
  minWidth: 0,
43
52
  color: didSpace.did ? colors.foregroundsFgSubtile : colors.textMuted,
53
+ overflow: 'hidden',
54
+ whiteSpace: 'nowrap',
44
55
  }}>
45
- : {didSpace.did ? didSpace.name : t('disconnected')}
46
- </span>
47
- <Icon icon={LensIcon} fontSize={8} color={didSpace.did ? colors.surfaceSuccess : colors.gray6} />
56
+ <Typography fontSize="auto" minFontSize={1} sx={{ marginTop: `${offset}px` }} onShrink={onShrink}>
57
+ {didSpace.did ? didSpace.name : t('disconnected')}
58
+ </Typography>
59
+ </div>
60
+ <Icon
61
+ style={{ marginTop: `${offset}px`, flexShrink: 0 }}
62
+ icon={LensIcon}
63
+ fontSize={8}
64
+ color={didSpace.did ? colors.surfaceSuccess : colors.gray6}
65
+ />
48
66
  </MenuItem>
49
67
  </TBox>
50
68
  <Divider sx={{ m: '0!important', borderColor: colors.strokeSep }} />
@@ -5,9 +5,37 @@ import { useEffect, useRef } from 'react';
5
5
  export interface TypographyProps extends MuiTypographyProps {
6
6
  fontSize?: string | number;
7
7
  minFontSize?: number;
8
+ onShrink?: ({ fontSize, initialSize }: { fontSize: number; initialSize: number }) => void;
8
9
  }
9
10
 
10
- export default function Typography({ children = null, minFontSize = 12, fontSize, sx, ...rest }: TypographyProps) {
11
+ const noop = (...args: any[]) => {};
12
+ let minBrowserFontSize = -1;
13
+
14
+ function detectMinimumFontSize() {
15
+ const testDiv = document.createElement('div');
16
+
17
+ Object.assign(testDiv.style, {
18
+ fontSize: '1px',
19
+ visibility: 'hidden',
20
+ position: 'absolute',
21
+ });
22
+ testDiv.textContent = 'Test';
23
+ document.body.appendChild(testDiv);
24
+
25
+ const size = parseFloat(getComputedStyle(testDiv).fontSize);
26
+ document.body.removeChild(testDiv);
27
+ return size;
28
+ }
29
+
30
+ export default function Typography({
31
+ children = null,
32
+ minFontSize = 12,
33
+ /* 设置为 auto 时字体会自动收缩,直到达到浏览器最小字体限制 */
34
+ fontSize,
35
+ sx,
36
+ onShrink = noop,
37
+ ...rest
38
+ }: TypographyProps) {
11
39
  const refMock = useRef<HTMLSpanElement>(null);
12
40
  const refContainer = useRef<HTMLDivElement>(null);
13
41
  const state = useReactive<{
@@ -30,11 +58,20 @@ export default function Typography({ children = null, minFontSize = 12, fontSize
30
58
  state.initialSize = Number(styleSize.replace('px', ''));
31
59
  state.fontSize = state.initialSize;
32
60
  }
33
- if (containerSize && mockSize) {
61
+ if (minBrowserFontSize < 0) {
62
+ minBrowserFontSize = detectMinimumFontSize();
63
+ }
64
+ // 达到浏览器最小字体限制,停止缩放
65
+ if (state.fontSize! <= minBrowserFontSize) {
66
+ state.loading = false;
67
+ onShrink?.({ fontSize: state.fontSize!, initialSize: state.initialSize! });
68
+ } else if (containerSize && mockSize) {
69
+ // 超过容器宽度,尝试收缩
34
70
  if (containerSize.width < mockSize.width && state.fontSize! > minFontSize) {
35
71
  state.fontSize!--;
36
72
  } else {
37
73
  state.loading = false;
74
+ onShrink?.({ fontSize: state.fontSize!, initialSize: state.initialSize! });
38
75
  }
39
76
  }
40
77
  } else {
@@ -10,7 +10,7 @@ export const API_DID_PREFIX = '/api/did';
10
10
 
11
11
  export const DASHBOARD_URL = `${AUTH_SERVICE_PREFIX}/admin`;
12
12
  export const PROFILE_URL = `${AUTH_SERVICE_PREFIX}/user`;
13
- export const DID_SPACE_URL = `${AUTH_SERVICE_PREFIX}/user/settings`;
13
+ export const DID_SPACE_URL = `${AUTH_SERVICE_PREFIX}/user/settings#storage`;
14
14
  export const NAVIGATION_URL = `${AUTH_SERVICE_PREFIX}/admin/navigation`;
15
15
 
16
16
  export const DID_PREFIX = 'did:abt:';