@blocklet/ui-react 2.4.28 → 2.4.30

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.
@@ -65,15 +65,16 @@ function Dashboard(_ref) {
65
65
  const {
66
66
  locale
67
67
  } = (0, _context.useLocaleContext)() || {};
68
- const blocklet = Object.assign({}, window.blocklet, meta);
69
68
  const formattedBlocklet = (0, _react.useMemo)(() => {
69
+ const blocklet = Object.assign({}, window.blocklet, meta);
70
+
70
71
  try {
71
72
  return (0, _blocklets.formatBlockletInfo)(blocklet);
72
73
  } catch (e) {
73
74
  console.error('Failed to format blocklet info', e, blocklet);
74
75
  return blocklet;
75
76
  }
76
- }, [blocklet]);
77
+ }, [meta]);
77
78
  const {
78
79
  localizedNav,
79
80
  flattened,
@@ -100,8 +101,8 @@ function Dashboard(_ref) {
100
101
  const flattened = (0, _utils.flatRecursive)(localizedNav).filter(item => !!item.url);
101
102
  const matchedIndex = (0, _utils.matchPaths)(flattened.map(item => item.url));
102
103
 
103
- if (flattened !== null && flattened !== void 0 && flattened.length) {
104
- flattened[matchedIndex === -1 ? 0 : matchedIndex].active = true;
104
+ if (matchedIndex !== -1) {
105
+ flattened[matchedIndex].active = true;
105
106
  }
106
107
 
107
108
  return {
@@ -130,9 +131,9 @@ function Dashboard(_ref) {
130
131
  }
131
132
  } // eslint-disable-next-line react-hooks/exhaustive-deps
132
133
 
133
- }, [invalidPathFallback]);
134
+ }, [invalidPathFallback, flattened, matchedIndex]);
134
135
 
135
- if (!blocklet.appName) {
136
+ if (!formattedBlocklet.appName) {
136
137
  return null;
137
138
  }
138
139
 
@@ -152,7 +153,8 @@ function Dashboard(_ref) {
152
153
  title: appName,
153
154
  fullWidth: true,
154
155
  sidebarWidth: 128,
155
- legacy: false
156
+ legacy: false,
157
+ links: localizedNav
156
158
  }, rest), {}, {
157
159
  headerProps: _objectSpread({
158
160
  brand: appName,
@@ -178,8 +180,7 @@ function Dashboard(_ref) {
178
180
  })
179
181
  }),
180
182
  addons: _headerAddons
181
- }, rest.headerProps),
182
- links: localizedNav
183
+ }, rest.headerProps)
183
184
  }));
184
185
  }
185
186
 
@@ -73,4 +73,4 @@ Brand.defaultProps = {
73
73
  logo: '',
74
74
  description: ''
75
75
  };
76
- const Root = (0, _Theme.styled)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n font-size: 14px;\n a {\n text-decoration: none;\n color: inherit;\n }\n > div:first-child {\n display: flex;\n align-items: center;\n }\n .footer-brand-logo {\n display: flex;\n align-items: center;\n margin-right: 16px;\n line-height: 1;\n img,\n svg {\n width: auto;\n height: 44px;\n max-height: 44px;\n }\n }\n .footer-brand-name {\n font-size: 16px;\n font-weight: bold;\n }\n .footer-brand-desc {\n margin-top: 16px;\n }\n\n ", " {\n width: auto;\n }\n\n ", " {\n .footer-brand-logo {\n img,\n svg {\n height: 32px;\n max-height: 32px;\n }\n }\n }\n"])), props => props.theme.breakpoints.down('sm'), props => props.theme.breakpoints.down('md'));
76
+ const Root = (0, _Theme.styled)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n font-size: 14px;\n a {\n text-decoration: none;\n color: inherit;\n }\n > div:first-of-type {\n display: flex;\n align-items: center;\n }\n .footer-brand-logo {\n display: flex;\n align-items: center;\n margin-right: 16px;\n line-height: 1;\n img,\n svg {\n width: auto;\n height: 44px;\n max-height: 44px;\n }\n }\n .footer-brand-name {\n font-size: 16px;\n font-weight: bold;\n }\n .footer-brand-desc {\n margin-top: 16px;\n }\n\n ", " {\n width: auto;\n }\n\n ", " {\n .footer-brand-logo {\n img,\n svg {\n height: 32px;\n max-height: 32px;\n }\n }\n }\n"])), props => props.theme.breakpoints.down('sm'), props => props.theme.breakpoints.down('md'));
@@ -11,8 +11,6 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _Theme = require("@arcblock/ux/lib/Theme");
13
13
 
14
- var _Box = _interopRequireDefault(require("@mui/material/Box"));
15
-
16
14
  var _reactErrorBoundary = require("react-error-boundary");
17
15
 
18
16
  var _context = require("@arcblock/ux/lib/Locale/context");
@@ -53,7 +51,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
53
51
  * 专门用于 (composable) blocklet 的 Footer 组件, 基于 blocklet meta 中的数据渲染
54
52
  */
55
53
  function Footer(_ref) {
56
- var _formattedBlocklet$na, _formattedBlocklet$na2, _formattedBlocklet$na3, _theme$background, _window, _window$blocklet;
54
+ var _formattedBlocklet$na, _formattedBlocklet$na2, _formattedBlocklet$na3, _theme$background;
57
55
 
58
56
  let {
59
57
  meta,
@@ -64,17 +62,18 @@ function Footer(_ref) {
64
62
  const {
65
63
  locale
66
64
  } = (0, _context.useLocaleContext)() || {};
67
- const blocklet = Object.assign({}, window.blocklet, meta);
68
65
  const formattedBlocklet = (0, _react.useMemo)(() => {
66
+ const blocklet = Object.assign({}, window.blocklet, meta);
67
+
69
68
  try {
70
69
  return (0, _blocklets.formatBlockletInfo)(blocklet);
71
70
  } catch (e) {
72
71
  console.error('Failed to format blocklet info', e, blocklet);
73
72
  return blocklet;
74
73
  }
75
- }, [blocklet]);
74
+ }, [meta]);
76
75
 
77
- if (!blocklet.appName) {
76
+ if (!formattedBlocklet.appName) {
78
77
  return null;
79
78
  }
80
79
 
@@ -107,23 +106,11 @@ function Footer(_ref) {
107
106
  label: item.title
108
107
  }))
109
108
  };
110
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_overridableThemeProvider.default, {
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_overridableThemeProvider.default, {
111
110
  theme: themeOverrides,
112
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(StyledInternalFooter, _objectSpread(_objectSpread(_objectSpread({}, props), rest), {}, {
111
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledInternalFooter, _objectSpread(_objectSpread(_objectSpread({}, props), rest), {}, {
113
112
  $bgcolor: theme === null || theme === void 0 ? void 0 : (_theme$background = theme.background) === null || _theme$background === void 0 ? void 0 : _theme$background.footer
114
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
115
- position: "absolute",
116
- right: 0,
117
- bottom: 0,
118
- sx: {
119
- color: 'transparent',
120
- '::selection': {
121
- background: '#000',
122
- color: '#fff'
123
- }
124
- },
125
- children: (_window = window) === null || _window === void 0 ? void 0 : (_window$blocklet = _window.blocklet) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.version
126
- })]
113
+ }))
127
114
  });
128
115
  }
129
116
 
@@ -136,7 +123,7 @@ Footer.defaultProps = {
136
123
  meta: {},
137
124
  theme: null
138
125
  };
139
- const StyledInternalFooter = (0, _Theme.styled)(_internalFooter.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n border-top: 1px solid #eee;\n color: ", ";\n ", "\n font-family: Lato, Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,\n 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n"])), props => props.theme.palette.grey[600], _ref2 => {
126
+ const StyledInternalFooter = (0, _Theme.styled)(_internalFooter.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n border-top: 1px solid #eee;\n color: ", ";\n ", "\n font-family: Lato, Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,\n 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n"])), props => props.theme.palette.grey[600], _ref2 => {
140
127
  let {
141
128
  $bgcolor
142
129
  } = _ref2;
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
10
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
11
+
10
12
  var _brand = _interopRequireDefault(require("./brand"));
11
13
 
12
14
  var _links = _interopRequireDefault(require("./links"));
@@ -58,6 +60,8 @@ const layoutsKeyByName = layouts.reduce((acc, cur) => _objectSpread(_objectSprea
58
60
  */
59
61
 
60
62
  function InternalFooter(props) {
63
+ var _window, _window$blocklet;
64
+
61
65
  const {
62
66
  brand,
63
67
  navigation,
@@ -126,10 +130,26 @@ function InternalFooter(props) {
126
130
  throw new Error("layout ".concat(layout, " is not supported."));
127
131
  }
128
132
 
129
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(LayoutComponent, _objectSpread({
130
- elements: elements,
131
- data: props
132
- }, rest));
133
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
134
+ position: "relative",
135
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(LayoutComponent, _objectSpread({
136
+ elements: elements,
137
+ data: props
138
+ }, rest)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
139
+ position: "absolute",
140
+ right: 16,
141
+ bottom: 0,
142
+ fontSize: 12,
143
+ sx: {
144
+ color: 'transparent',
145
+ '::selection': {
146
+ background: '#000',
147
+ color: '#fff'
148
+ }
149
+ },
150
+ children: (_window = window) === null || _window === void 0 ? void 0 : (_window$blocklet = _window.blocklet) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.version
151
+ })]
152
+ });
133
153
  }
134
154
 
135
155
  InternalFooter.propTypes = {
@@ -134,17 +134,18 @@ function Header(_ref) {
134
134
  const {
135
135
  locale
136
136
  } = (0, _context.useLocaleContext)() || {};
137
- const blocklet = Object.assign({}, window.blocklet, meta);
138
137
  const formattedBlocklet = (0, _react.useMemo)(() => {
138
+ const blocklet = Object.assign({}, window.blocklet, meta);
139
+
139
140
  try {
140
141
  return (0, _blocklets.formatBlockletInfo)(blocklet);
141
142
  } catch (e) {
142
143
  console.error('Failed to format blocklet info', e, blocklet);
143
144
  return blocklet;
144
145
  }
145
- }, [blocklet]);
146
+ }, [meta]);
146
147
 
147
- if (!blocklet.appName) {
148
+ if (!formattedBlocklet.appName) {
148
149
  return null;
149
150
  }
150
151
 
@@ -95,7 +95,8 @@ function HeaderAddons(_ref) {
95
95
  addonsArray.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SessionManager.default, _objectSpread({
96
96
  session: sessionCtx.session,
97
97
  locale: locale,
98
- menu: menu
98
+ menu: menu,
99
+ showRole: true
99
100
  }, sessionManagerProps), "session-manager"));
100
101
  } // 在内置 addons 基础上定制 addons
101
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.4.28",
3
+ "version": "2.4.30",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -30,8 +30,8 @@
30
30
  "url": "https://github.com/ArcBlock/ux/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@arcblock/did-connect": "^2.4.28",
34
- "@arcblock/ux": "^2.4.28",
33
+ "@arcblock/did-connect": "^2.4.30",
34
+ "@arcblock/ux": "^2.4.30",
35
35
  "@emotion/react": "^11.10.0",
36
36
  "@emotion/styled": "^11.10.0",
37
37
  "@iconify/iconify": "^2.2.1",
@@ -53,5 +53,5 @@
53
53
  "eslint-plugin-react-hooks": "^4.6.0",
54
54
  "jest": "^28.1.3"
55
55
  },
56
- "gitHead": "3133ed4e76d70eff05b08130fa7340dcc07611c4"
56
+ "gitHead": "ac31e48f3f02a3bfe0de05c41bea6fd55d3c03e1"
57
57
  }
@@ -20,15 +20,15 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
20
20
  const user = sessionCtx?.session?.user;
21
21
  const userRole = user?.role;
22
22
  const { locale } = useLocaleContext() || {};
23
- const blocklet = Object.assign({}, window.blocklet, meta);
24
23
  const formattedBlocklet = useMemo(() => {
24
+ const blocklet = Object.assign({}, window.blocklet, meta);
25
25
  try {
26
26
  return formatBlockletInfo(blocklet);
27
27
  } catch (e) {
28
28
  console.error('Failed to format blocklet info', e, blocklet);
29
29
  return blocklet;
30
30
  }
31
- }, [blocklet]);
31
+ }, [meta]);
32
32
  const { localizedNav, flattened, matchedIndex } = useMemo(() => {
33
33
  let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.dashboard, locale) || [];
34
34
  // 根据 role 筛选 nav 数据
@@ -49,8 +49,8 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
49
49
  // 展平后使用 matchPaths 检测 link#active 状态
50
50
  const flattened = flatRecursive(localizedNav).filter((item) => !!item.url);
51
51
  const matchedIndex = matchPaths(flattened.map((item) => item.url));
52
- if (flattened?.length) {
53
- flattened[matchedIndex === -1 ? 0 : matchedIndex].active = true;
52
+ if (matchedIndex !== -1) {
53
+ flattened[matchedIndex].active = true;
54
54
  }
55
55
  return { localizedNav, flattened, matchedIndex };
56
56
  }, [formattedBlocklet, locale, userRole]);
@@ -74,9 +74,9 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
74
74
  }
75
75
  }
76
76
  // eslint-disable-next-line react-hooks/exhaustive-deps
77
- }, [invalidPathFallback]);
77
+ }, [invalidPathFallback, flattened, matchedIndex]);
78
78
 
79
- if (!blocklet.appName) {
79
+ if (!formattedBlocklet.appName) {
80
80
  return null;
81
81
  }
82
82
  const { did, appLogo, appName } = formattedBlocklet;
@@ -94,6 +94,7 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
94
94
  fullWidth
95
95
  sidebarWidth={128}
96
96
  legacy={false}
97
+ links={localizedNav}
97
98
  {...rest}
98
99
  headerProps={{
99
100
  brand: appName,
@@ -115,7 +116,6 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
115
116
  addons: _headerAddons,
116
117
  ...rest.headerProps,
117
118
  }}
118
- links={localizedNav}
119
119
  />
120
120
  );
121
121
  }
@@ -40,7 +40,7 @@ const Root = styled('div')`
40
40
  text-decoration: none;
41
41
  color: inherit;
42
42
  }
43
- > div:first-child {
43
+ > div:first-of-type {
44
44
  display: flex;
45
45
  align-items: center;
46
46
  }
@@ -1,7 +1,6 @@
1
1
  import { useMemo } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { styled } from '@arcblock/ux/lib/Theme';
4
- import Box from '@mui/material/Box';
5
4
  import { withErrorBoundary } from 'react-error-boundary';
6
5
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
7
6
  import { ErrorFallback } from '@arcblock/ux/lib/ErrorBoundary';
@@ -18,16 +17,16 @@ import { blockletMetaProps } from '../types';
18
17
  */
19
18
  function Footer({ meta, theme: themeOverrides, ...rest }) {
20
19
  const { locale } = useLocaleContext() || {};
21
- const blocklet = Object.assign({}, window.blocklet, meta);
22
20
  const formattedBlocklet = useMemo(() => {
21
+ const blocklet = Object.assign({}, window.blocklet, meta);
23
22
  try {
24
23
  return formatBlockletInfo(blocklet);
25
24
  } catch (e) {
26
25
  console.error('Failed to format blocklet info', e, blocklet);
27
26
  return blocklet;
28
27
  }
29
- }, [blocklet]);
30
- if (!blocklet.appName) {
28
+ }, [meta]);
29
+ if (!formattedBlocklet.appName) {
31
30
  return null;
32
31
  }
33
32
 
@@ -62,13 +61,6 @@ function Footer({ meta, theme: themeOverrides, ...rest }) {
62
61
  return (
63
62
  <OverridableThemeProvider theme={themeOverrides}>
64
63
  <StyledInternalFooter {...props} {...rest} $bgcolor={theme?.background?.footer} />
65
- <Box
66
- position="absolute"
67
- right={0}
68
- bottom={0}
69
- sx={{ color: 'transparent', '::selection': { background: '#000', color: '#fff' } }}>
70
- {window?.blocklet?.version}
71
- </Box>
72
64
  </OverridableThemeProvider>
73
65
  );
74
66
  }
@@ -85,7 +77,6 @@ Footer.defaultProps = {
85
77
  };
86
78
 
87
79
  const StyledInternalFooter = styled(InternalFooter)`
88
- position: relative;
89
80
  border-top: 1px solid #eee;
90
81
  color: ${(props) => props.theme.palette.grey[600]};
91
82
  ${({ $bgcolor }) => $bgcolor && `background-color: ${$bgcolor};`}
@@ -1,4 +1,5 @@
1
1
  import PropTypes from 'prop-types';
2
+ import Box from '@mui/material/Box';
2
3
  import Brand from './brand';
3
4
  import Links from './links';
4
5
  import SocialMedia from './social-media';
@@ -65,7 +66,19 @@ function InternalFooter(props) {
65
66
  if (!LayoutComponent) {
66
67
  throw new Error(`layout ${layout} is not supported.`);
67
68
  }
68
- return <LayoutComponent elements={elements} data={props} {...rest} />;
69
+ return (
70
+ <Box position="relative">
71
+ <LayoutComponent elements={elements} data={props} {...rest} />
72
+ <Box
73
+ position="absolute"
74
+ right={16}
75
+ bottom={0}
76
+ fontSize={12}
77
+ sx={{ color: 'transparent', '::selection': { background: '#000', color: '#fff' } }}>
78
+ {window?.blocklet?.version}
79
+ </Box>
80
+ </Box>
81
+ );
69
82
  }
70
83
 
71
84
  InternalFooter.propTypes = {
@@ -62,17 +62,17 @@ const parseNavigation = (navigation) => {
62
62
  // eslint-disable-next-line no-shadow
63
63
  function Header({ meta, addons, sessionManagerProps, homeLink, theme: themeOverrides, ...rest }) {
64
64
  const { locale } = useLocaleContext() || {};
65
- const blocklet = Object.assign({}, window.blocklet, meta);
66
65
  const formattedBlocklet = useMemo(() => {
66
+ const blocklet = Object.assign({}, window.blocklet, meta);
67
67
  try {
68
68
  return formatBlockletInfo(blocklet);
69
69
  } catch (e) {
70
70
  console.error('Failed to format blocklet info', e, blocklet);
71
71
  return blocklet;
72
72
  }
73
- }, [blocklet]);
73
+ }, [meta]);
74
74
 
75
- if (!blocklet.appName) {
75
+ if (!formattedBlocklet.appName) {
76
76
  return null;
77
77
  }
78
78
  const { did, appLogo, appName, theme } = formattedBlocklet;
@@ -51,6 +51,7 @@ export default function HeaderAddons({ formattedBlocklet, addons, sessionManager
51
51
  session={sessionCtx.session}
52
52
  locale={locale}
53
53
  menu={menu}
54
+ showRole
54
55
  {...sessionManagerProps}
55
56
  />
56
57
  );