@blocklet/ui-react 2.4.32 → 2.4.34

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.
@@ -138,7 +138,7 @@ function Dashboard(_ref) {
138
138
  }
139
139
 
140
140
  const {
141
- did,
141
+ appId: did,
142
142
  appLogo,
143
143
  appName
144
144
  } = formattedBlocklet;
@@ -150,7 +150,7 @@ function Header(_ref) {
150
150
  }
151
151
 
152
152
  const {
153
- did,
153
+ appId: did,
154
154
  appLogo,
155
155
  appName,
156
156
  theme
package/lib/blocklets.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.publicPath = exports.parseNavigation = exports.getLocalizedNavigation = exports.formatTheme = exports.formatNavigation = exports.formatBlockletInfo = exports.filterNavByRole = void 0;
6
+ exports.publicPath = exports.parseNavigation = exports.getLocalizedNavigation = exports.formatTheme = exports.formatNavigation = exports.formatBlockletInfo = exports.filterValidNavItems = exports.filterNavByRole = void 0;
7
7
 
8
8
  var _utils = require("./utils");
9
9
 
@@ -179,9 +179,24 @@ const formatBlockletInfo = blockletInfo => {
179
179
 
180
180
  formatted.theme = formatTheme(formatted.theme); // navigation
181
181
 
182
- formatted.navigation = parseNavigation(formatted.navigation);
182
+ formatted.navigation = parseNavigation(filterValidNavItems(formatted.navigation));
183
183
  return formatted;
184
184
  };
185
+ /**
186
+ * 过滤掉无效结点 (无 link 且子元素为空)
187
+ */
188
+
189
+
190
+ exports.formatBlockletInfo = formatBlockletInfo;
191
+
192
+ const filterValidNavItems = function filterValidNavItems() {
193
+ let navigation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
194
+ return (0, _utils.filterRecursive)(navigation, (item, context) => {
195
+ var _context$filteredChil;
196
+
197
+ return !!item.link || ((_context$filteredChil = context.filteredChildren) === null || _context$filteredChil === void 0 ? void 0 : _context$filteredChil.length);
198
+ }, 'items');
199
+ };
185
200
  /**
186
201
  * 根据 role 筛选 nav, 规则:
187
202
  * - 如果是枝结点, 必须至少存在一个符合条件的子结点
@@ -194,16 +209,16 @@ const formatBlockletInfo = blockletInfo => {
194
209
  */
195
210
 
196
211
 
197
- exports.formatBlockletInfo = formatBlockletInfo;
212
+ exports.filterValidNavItems = filterValidNavItems;
198
213
 
199
214
  const filterNavByRole = (nav, userRole) => {
200
215
  return (0, _utils.filterRecursive)(nav, (item, context) => {
201
216
  const isRoleMatched = !item.role || userRole && item.role.includes(userRole);
202
217
 
203
218
  if (!context.isLeaf) {
204
- var _context$filteredChil;
219
+ var _context$filteredChil2;
205
220
 
206
- return isRoleMatched && ((_context$filteredChil = context.filteredChildren) === null || _context$filteredChil === void 0 ? void 0 : _context$filteredChil.length);
221
+ return isRoleMatched && ((_context$filteredChil2 = context.filteredChildren) === null || _context$filteredChil2 === void 0 ? void 0 : _context$filteredChil2.length);
207
222
  }
208
223
 
209
224
  return isRoleMatched;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.4.32",
3
+ "version": "2.4.34",
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.32",
34
- "@arcblock/ux": "^2.4.32",
33
+ "@arcblock/did-connect": "^2.4.34",
34
+ "@arcblock/ux": "^2.4.34",
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": "2d5ae94d1098073c5483f53af3613f0976841a5a"
56
+ "gitHead": "02c1622ae5619e5e15293111d2465e2d94a8e5ec"
57
57
  }
@@ -79,7 +79,7 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
79
79
  if (!formattedBlocklet.appName) {
80
80
  return null;
81
81
  }
82
- const { did, appLogo, appName } = formattedBlocklet;
82
+ const { appId: did, appLogo, appName } = formattedBlocklet;
83
83
  const _headerAddons = (
84
84
  <HeaderAddons
85
85
  formattedBlocklet={formattedBlocklet}
@@ -75,7 +75,7 @@ function Header({ meta, addons, sessionManagerProps, homeLink, theme: themeOverr
75
75
  if (!formattedBlocklet.appName) {
76
76
  return null;
77
77
  }
78
- const { did, appLogo, appName, theme } = formattedBlocklet;
78
+ const { appId: did, appLogo, appName, theme } = formattedBlocklet;
79
79
  const navigation = getLocalizedNavigation(formattedBlocklet?.navigation?.header, locale);
80
80
  const parsedNavigation = parseNavigation(navigation);
81
81
  const { navItems, activeId } = parsedNavigation;
package/src/blocklets.js CHANGED
@@ -140,10 +140,17 @@ export const formatBlockletInfo = (blockletInfo) => {
140
140
  // theme
141
141
  formatted.theme = formatTheme(formatted.theme);
142
142
  // navigation
143
- formatted.navigation = parseNavigation(formatted.navigation);
143
+ formatted.navigation = parseNavigation(filterValidNavItems(formatted.navigation));
144
144
  return formatted;
145
145
  };
146
146
 
147
+ /**
148
+ * 过滤掉无效结点 (无 link 且子元素为空)
149
+ */
150
+ export const filterValidNavItems = (navigation = []) => {
151
+ return filterRecursive(navigation, (item, context) => !!item.link || context.filteredChildren?.length, 'items');
152
+ };
153
+
147
154
  /**
148
155
  * 根据 role 筛选 nav, 规则:
149
156
  * - 如果是枝结点, 必须至少存在一个符合条件的子结点