@blocklet/ui-react 2.1.55 → 2.1.56

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.
@@ -45,7 +45,7 @@ var _utils = require("../utils");
45
45
 
46
46
  var _blocklets = require("../blocklets");
47
47
 
48
- const _excluded = ["meta", "addons", "sessionManagerProps"];
48
+ const _excluded = ["meta", "addons", "sessionManagerProps", "homeLink"];
49
49
 
50
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
51
 
@@ -128,7 +128,8 @@ function Header(_ref) {
128
128
  let {
129
129
  meta,
130
130
  addons,
131
- sessionManagerProps
131
+ sessionManagerProps,
132
+ homeLink
132
133
  } = _ref,
133
134
  rest = _objectWithoutProperties(_ref, _excluded);
134
135
 
@@ -159,10 +160,11 @@ function Header(_ref) {
159
160
  enableLocale = true
160
161
  } = formattedBlocklet;
161
162
  const navigation = (0, _blocklets.getLocalizedNavigation)(formattedBlocklet === null || formattedBlocklet === void 0 ? void 0 : (_formattedBlocklet$na = formattedBlocklet.navigation) === null || _formattedBlocklet$na === void 0 ? void 0 : _formattedBlocklet$na.header, locale);
163
+ const parsedNavigation = parseNavigation(navigation);
162
164
  const {
163
165
  navItems,
164
166
  activeId
165
- } = parseNavigation(navigation);
167
+ } = parsedNavigation;
166
168
 
167
169
  const renderAddons = () => {
168
170
  // 不关心内置的 session manager 和 locale selector, 直接覆盖 UX Header 的 addons
@@ -187,18 +189,21 @@ function Header(_ref) {
187
189
 
188
190
 
189
191
  if (typeof addons === 'function') {
190
- addonsArray = addons(addonsArray) || [];
192
+ addonsArray = addons(addonsArray, {
193
+ navigation: parsedNavigation
194
+ }) || [];
191
195
  }
192
196
 
193
197
  return addonsArray;
194
198
  };
195
199
 
196
- const addonList = /*#__PURE__*/(0, _react.createElement)(_jsxRuntime.Fragment, null, ...renderAddons());
200
+ const renderedAddons = renderAddons();
201
+ const addonList = /*#__PURE__*/(0, _react.createElement)(_jsxRuntime.Fragment, null, ...(Array.isArray(renderedAddons) ? renderedAddons : [renderedAddons]));
197
202
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
198
203
  theme: muiTheme,
199
204
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledUxHeader, _objectSpread(_objectSpread({
200
205
  logo: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
201
- href: _blocklets.publicPath,
206
+ href: homeLink,
202
207
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
203
208
  src: appLogo,
204
209
  alt: "logo"
@@ -245,14 +250,16 @@ Header.propTypes = {
245
250
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
246
251
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
247
252
  addons: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
248
- sessionManagerProps: _types.sessionManagerProps
253
+ sessionManagerProps: _types.sessionManagerProps,
254
+ homeLink: _propTypes.default.string
249
255
  };
250
256
  Header.defaultProps = {
251
257
  meta: {},
252
258
  addons: null,
253
259
  sessionManagerProps: {
254
260
  showRole: true
255
- }
261
+ },
262
+ homeLink: _blocklets.publicPath
256
263
  };
257
264
  const StyledUxHeader = (0, _styledComponents.default)(_Header.ResponsiveHeader).withConfig({
258
265
  displayName: "Header__StyledUxHeader",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.1.55",
3
+ "version": "2.1.56",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -34,8 +34,8 @@
34
34
  "url": "https://github.com/ArcBlock/ux/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@arcblock/did-connect": "^2.1.55",
38
- "@arcblock/ux": "^2.1.55",
37
+ "@arcblock/did-connect": "^2.1.56",
38
+ "@arcblock/ux": "^2.1.56",
39
39
  "@iconify/iconify": "^2.2.1",
40
40
  "@mui/material": "^5.6.4",
41
41
  "core-js": "^3.6.4",
@@ -57,5 +57,5 @@
57
57
  "eslint-plugin-react-hooks": "^4.2.0",
58
58
  "jest": "^24.1.0"
59
59
  },
60
- "gitHead": "8cfcdd2b41ec392d73b0f7cb906e83309f36aec2"
60
+ "gitHead": "5a8e5ecc8cad24b64ef38558457b32657e18ef44"
61
61
  }
@@ -67,7 +67,7 @@ const parseNavigation = (navigation) => {
67
67
  * 专门用于 (composable) blocklet 的 Header 组件, 解析 blocklet meta 中的数据, 通过组合 UX 中的 Header & NavMenu 组件来渲染
68
68
  */
69
69
  // eslint-disable-next-line no-shadow
70
- function Header({ meta, addons, sessionManagerProps, ...rest }) {
70
+ function Header({ meta, addons, sessionManagerProps, homeLink, ...rest }) {
71
71
  const sessionInfo = useContext(SessionContext);
72
72
  const { locale } = useLocaleContext() || {};
73
73
  const blocklet = Object.assign({}, window.blocklet, meta);
@@ -85,7 +85,8 @@ function Header({ meta, addons, sessionManagerProps, ...rest }) {
85
85
  }
86
86
  const { did, appLogo, appName, theme, enableConnect = true, enableLocale = true } = formattedBlocklet;
87
87
  const navigation = getLocalizedNavigation(formattedBlocklet?.navigation?.header, locale);
88
- const { navItems, activeId } = parseNavigation(navigation);
88
+ const parsedNavigation = parseNavigation(navigation);
89
+ const { navItems, activeId } = parsedNavigation;
89
90
 
90
91
  const renderAddons = () => {
91
92
  // 不关心内置的 session manager 和 locale selector, 直接覆盖 UX Header 的 addons
@@ -103,18 +104,27 @@ function Header({ meta, addons, sessionManagerProps, ...rest }) {
103
104
  }
104
105
  // 在内置 addons 基础上定制 addons
105
106
  if (typeof addons === 'function') {
106
- addonsArray = addons(addonsArray) || [];
107
+ addonsArray =
108
+ addons(addonsArray, {
109
+ navigation: parsedNavigation,
110
+ }) || [];
107
111
  }
108
112
  return addonsArray;
109
113
  };
110
114
 
111
- const addonList = createElement(Fragment, null, ...renderAddons());
115
+ const renderedAddons = renderAddons();
116
+
117
+ const addonList = createElement(
118
+ Fragment,
119
+ null,
120
+ ...(Array.isArray(renderedAddons) ? renderedAddons : [renderedAddons])
121
+ );
112
122
 
113
123
  return (
114
124
  <ThemeProvider theme={muiTheme}>
115
125
  <StyledUxHeader
116
126
  logo={
117
- <a href={publicPath}>
127
+ <a href={homeLink}>
118
128
  <img src={appLogo} alt="logo" />
119
129
  </a>
120
130
  }
@@ -161,6 +171,7 @@ Header.propTypes = {
161
171
  addons: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
162
172
 
163
173
  sessionManagerProps,
174
+ homeLink: PropTypes.string,
164
175
  };
165
176
 
166
177
  Header.defaultProps = {
@@ -169,6 +180,7 @@ Header.defaultProps = {
169
180
  sessionManagerProps: {
170
181
  showRole: true,
171
182
  },
183
+ homeLink: publicPath,
172
184
  };
173
185
 
174
186
  const StyledUxHeader = styled(ResponsiveHeader)`