@blocklet/ui-react 2.5.58 → 2.5.60
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.
- package/lib/Dashboard/index.js +31 -57
- package/lib/Footer/brand.js +8 -23
- package/lib/Footer/copyright.js +7 -20
- package/lib/Footer/index.js +10 -38
- package/lib/Footer/internal-footer.js +12 -42
- package/lib/Footer/layout/plain.js +10 -26
- package/lib/Footer/layout/row.js +7 -23
- package/lib/Footer/layout/standard.js +10 -27
- package/lib/Footer/links.js +14 -37
- package/lib/Footer/social-media.js +6 -22
- package/lib/Header/index.js +11 -55
- package/lib/Icon/index.js +15 -35
- package/lib/blocklets.js +23 -61
- package/lib/common/header-addons.js +11 -34
- package/lib/common/link-blocker.js +4 -12
- package/lib/common/overridable-theme-provider.js +1 -7
- package/lib/common/wallet-hidden-topbar.js +0 -6
- package/lib/types.js +1 -6
- package/lib/utils.js +16 -36
- package/package.json +4 -4
package/lib/blocklets.js
CHANGED
|
@@ -4,29 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.publicPath = exports.parseNavigation = exports.getLocalizedNavigation = exports.formatTheme = exports.formatNavigation = exports.formatBlockletInfo = exports.filterValidNavItems = exports.filterNavByRole = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("./utils");
|
|
9
|
-
|
|
10
8
|
var _window, _window$blocklet, _window2, _window2$blocklet;
|
|
11
|
-
|
|
12
9
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
|
|
14
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
14
|
const publicPath = ((_window = window) === null || _window === void 0 ? void 0 : (_window$blocklet = _window.blocklet) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.groupPrefix) || ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$blocklet = _window2.blocklet) === null || _window2$blocklet === void 0 ? void 0 : _window2$blocklet.prefix) || '/';
|
|
15
|
+
|
|
19
16
|
/**
|
|
20
17
|
* 格式化 theme (目前仅考虑 background)
|
|
21
18
|
*/
|
|
22
|
-
|
|
23
19
|
exports.publicPath = publicPath;
|
|
24
|
-
|
|
25
20
|
const formatTheme = theme => {
|
|
26
21
|
const formatted = _objectSpread({}, theme);
|
|
27
|
-
|
|
28
22
|
const background = theme === null || theme === void 0 ? void 0 : theme.background;
|
|
29
|
-
|
|
30
23
|
if (typeof background === 'string') {
|
|
31
24
|
formatted.background = {
|
|
32
25
|
header: background,
|
|
@@ -40,37 +33,29 @@ const formatTheme = theme => {
|
|
|
40
33
|
default: background.default
|
|
41
34
|
};
|
|
42
35
|
}
|
|
43
|
-
|
|
44
36
|
return formatted;
|
|
45
37
|
};
|
|
38
|
+
|
|
46
39
|
/**
|
|
47
40
|
* 获取指定 locale 对应的 navigation 数据, 仅考虑 zh/en
|
|
48
41
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
42
|
exports.formatTheme = formatTheme;
|
|
52
|
-
|
|
53
43
|
const getLocalizedNavigation = function getLocalizedNavigation(navigation) {
|
|
54
44
|
let locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
|
|
55
|
-
|
|
56
45
|
if (!(navigation !== null && navigation !== void 0 && navigation.length)) {
|
|
57
46
|
return navigation;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
}
|
|
48
|
+
// eslint-disable-next-line no-shadow
|
|
61
49
|
const getTitle = (title, locale) => {
|
|
62
50
|
if (typeof title === 'string') {
|
|
63
51
|
return title;
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
if (typeof title === 'object') {
|
|
67
54
|
return title[locale] || (title === null || title === void 0 ? void 0 : title.en) || (title === null || title === void 0 ? void 0 : title.zh);
|
|
68
55
|
}
|
|
69
|
-
|
|
70
56
|
return title;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
};
|
|
58
|
+
// eslint-disable-next-line no-shadow
|
|
74
59
|
const getLink = (link, locale) => {
|
|
75
60
|
if (typeof link === 'string') {
|
|
76
61
|
// http[s] 开头的 url
|
|
@@ -79,22 +64,17 @@ const getLocalizedNavigation = function getLocalizedNavigation(navigation) {
|
|
|
79
64
|
url.searchParams.set('locale', locale);
|
|
80
65
|
return url.href;
|
|
81
66
|
}
|
|
82
|
-
|
|
83
67
|
const url = new URL(link, window.location.origin);
|
|
84
68
|
url.searchParams.set('locale', locale);
|
|
85
69
|
return url.pathname + url.search;
|
|
86
70
|
}
|
|
87
|
-
|
|
88
71
|
if (typeof link === 'object') {
|
|
89
72
|
return link[locale] || (link === null || link === void 0 ? void 0 : link.en) || (link === null || link === void 0 ? void 0 : link.zh);
|
|
90
73
|
}
|
|
91
|
-
|
|
92
74
|
return link;
|
|
93
75
|
};
|
|
94
|
-
|
|
95
76
|
return (0, _utils.mapRecursive)(navigation, item => {
|
|
96
77
|
var _item$items;
|
|
97
|
-
|
|
98
78
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
99
79
|
title: getTitle(item.title, locale),
|
|
100
80
|
// 仅对叶结点进行处理
|
|
@@ -102,15 +82,13 @@ const getLocalizedNavigation = function getLocalizedNavigation(navigation) {
|
|
|
102
82
|
});
|
|
103
83
|
}, 'items');
|
|
104
84
|
};
|
|
85
|
+
|
|
105
86
|
/**
|
|
106
87
|
* 格式化 navigation
|
|
107
88
|
*
|
|
108
89
|
* - role 统一为数组形式
|
|
109
90
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
91
|
exports.getLocalizedNavigation = getLocalizedNavigation;
|
|
113
|
-
|
|
114
92
|
const formatNavigation = navigation => {
|
|
115
93
|
return (0, _utils.mapRecursive)(navigation, item => {
|
|
116
94
|
if (item.role) {
|
|
@@ -118,18 +96,14 @@ const formatNavigation = navigation => {
|
|
|
118
96
|
role: Array.isArray(item.role) ? item.role : [item.role]
|
|
119
97
|
});
|
|
120
98
|
}
|
|
121
|
-
|
|
122
99
|
return item;
|
|
123
100
|
}, 'items');
|
|
124
101
|
};
|
|
125
|
-
|
|
126
102
|
exports.formatNavigation = formatNavigation;
|
|
127
|
-
|
|
128
103
|
const parseNavigation = navigation => {
|
|
129
104
|
if (!(navigation !== null && navigation !== void 0 && navigation.length)) {
|
|
130
105
|
return null;
|
|
131
106
|
}
|
|
132
|
-
|
|
133
107
|
const formattedNav = formatNavigation(navigation);
|
|
134
108
|
const sections = {
|
|
135
109
|
header: [],
|
|
@@ -142,61 +116,56 @@ const parseNavigation = navigation => {
|
|
|
142
116
|
dashboard: [],
|
|
143
117
|
// session manager menus
|
|
144
118
|
sessionManager: []
|
|
145
|
-
};
|
|
119
|
+
};
|
|
146
120
|
|
|
121
|
+
// 对 navigation 顶层元素按 section 分组
|
|
147
122
|
formattedNav.forEach(item => {
|
|
148
123
|
// item#section 为空时, 表示只存在于 header
|
|
149
124
|
if (!item.section) {
|
|
150
|
-
sections.header.push(item);
|
|
125
|
+
sections.header.push(item);
|
|
126
|
+
// item 出现在指定几个 section 中 (array)
|
|
151
127
|
} else if (Array.isArray(item.section)) {
|
|
152
128
|
item.section.forEach(sectionKey => {
|
|
153
129
|
var _sections$sectionKey;
|
|
154
|
-
|
|
155
130
|
(_sections$sectionKey = sections[sectionKey]) === null || _sections$sectionKey === void 0 ? void 0 : _sections$sectionKey.push(item);
|
|
156
|
-
});
|
|
131
|
+
});
|
|
132
|
+
// item 出现在指定的一个 section 中 (string)
|
|
157
133
|
} else if (typeof item.section === 'string') {
|
|
158
134
|
var _sections$item$sectio;
|
|
159
|
-
|
|
160
135
|
(_sections$item$sectio = sections[item.section]) === null || _sections$item$sectio === void 0 ? void 0 : _sections$item$sectio.push(item);
|
|
161
136
|
}
|
|
162
137
|
});
|
|
163
138
|
return sections;
|
|
164
139
|
};
|
|
140
|
+
|
|
165
141
|
/**
|
|
166
142
|
* 格式化 blocklet info 数据
|
|
167
143
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
144
|
exports.parseNavigation = parseNavigation;
|
|
171
|
-
|
|
172
145
|
const formatBlockletInfo = blockletInfo => {
|
|
173
146
|
if (!blockletInfo) {
|
|
174
147
|
return null;
|
|
175
148
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
formatted.theme = formatTheme(formatted.theme); // navigation
|
|
181
|
-
|
|
149
|
+
const formatted = _objectSpread({}, blockletInfo);
|
|
150
|
+
// theme
|
|
151
|
+
formatted.theme = formatTheme(formatted.theme);
|
|
152
|
+
// navigation
|
|
182
153
|
formatted.navigation = parseNavigation(filterValidNavItems(formatted.navigation));
|
|
183
154
|
return formatted;
|
|
184
155
|
};
|
|
156
|
+
|
|
185
157
|
/**
|
|
186
158
|
* 过滤掉无效结点 (无 link 且子元素为空)
|
|
187
159
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
160
|
exports.formatBlockletInfo = formatBlockletInfo;
|
|
191
|
-
|
|
192
161
|
const filterValidNavItems = function filterValidNavItems() {
|
|
193
162
|
let navigation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
194
163
|
return (0, _utils.filterRecursive)(navigation, (item, context) => {
|
|
195
164
|
var _context$filteredChil;
|
|
196
|
-
|
|
197
165
|
return !!item.link || ((_context$filteredChil = context.filteredChildren) === null || _context$filteredChil === void 0 ? void 0 : _context$filteredChil.length);
|
|
198
166
|
}, 'items');
|
|
199
167
|
};
|
|
168
|
+
|
|
200
169
|
/**
|
|
201
170
|
* 根据 role 筛选 nav, 规则:
|
|
202
171
|
* - 如果是枝结点, 必须至少存在一个符合条件的子结点
|
|
@@ -207,22 +176,15 @@ const filterValidNavItems = function filterValidNavItems() {
|
|
|
207
176
|
* @param {string} userRole 当前用户 role
|
|
208
177
|
* @returns 符合 role 权限的导航菜单数据
|
|
209
178
|
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
179
|
exports.filterValidNavItems = filterValidNavItems;
|
|
213
|
-
|
|
214
180
|
const filterNavByRole = (nav, userRole) => {
|
|
215
181
|
return (0, _utils.filterRecursive)(nav, (item, context) => {
|
|
216
182
|
const isRoleMatched = !item.role || userRole && item.role.includes(userRole);
|
|
217
|
-
|
|
218
183
|
if (!context.isLeaf) {
|
|
219
184
|
var _context$filteredChil2;
|
|
220
|
-
|
|
221
185
|
return isRoleMatched && ((_context$filteredChil2 = context.filteredChildren) === null || _context$filteredChil2 === void 0 ? void 0 : _context$filteredChil2.length);
|
|
222
186
|
}
|
|
223
|
-
|
|
224
187
|
return isRoleMatched;
|
|
225
188
|
}, 'items');
|
|
226
189
|
};
|
|
227
|
-
|
|
228
190
|
exports.filterNavByRole = filterNavByRole;
|
|
@@ -4,37 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = HeaderAddons;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
|
|
14
10
|
var _Session = require("@arcblock/did-connect/lib/Session");
|
|
15
|
-
|
|
16
11
|
var _SessionManager = _interopRequireDefault(require("@arcblock/did-connect/lib/SessionManager"));
|
|
17
|
-
|
|
18
12
|
var _selector = _interopRequireDefault(require("@arcblock/ux/lib/Locale/selector"));
|
|
19
|
-
|
|
20
13
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
21
|
-
|
|
22
14
|
var _types = require("../types");
|
|
23
|
-
|
|
24
15
|
var _blocklets = require("../blocklets");
|
|
25
|
-
|
|
26
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
17
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
-
|
|
30
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
19
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
21
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // FIXME: 直接从 react 中 import Fragment 可能会在 vite 下出错,先暂时从 react/jsx-runtime 导入 Fragment 来跳过这个问题
|
|
34
22
|
// eslint-disable-next-line no-shadow
|
|
35
23
|
function HeaderAddons(_ref) {
|
|
36
24
|
var _sessionCtx$session, _formattedBlocklet$na, _sessionCtx$session2, _sessionCtx$session2$;
|
|
37
|
-
|
|
38
25
|
let {
|
|
39
26
|
formattedBlocklet,
|
|
40
27
|
addons,
|
|
@@ -49,30 +36,25 @@ function HeaderAddons(_ref) {
|
|
|
49
36
|
enableLocale = true
|
|
50
37
|
} = formattedBlocklet;
|
|
51
38
|
const authenticated = !!(sessionCtx !== null && sessionCtx !== void 0 && (_sessionCtx$session = sessionCtx.session) !== null && _sessionCtx$session !== void 0 && _sessionCtx$session.user);
|
|
52
|
-
let localizedNav = (0, _blocklets.getLocalizedNavigation)(formattedBlocklet === null || formattedBlocklet === void 0 ? void 0 : (_formattedBlocklet$na = formattedBlocklet.navigation) === null || _formattedBlocklet$na === void 0 ? void 0 : _formattedBlocklet$na.sessionManager, locale) || [];
|
|
53
|
-
|
|
39
|
+
let localizedNav = (0, _blocklets.getLocalizedNavigation)(formattedBlocklet === null || formattedBlocklet === void 0 ? void 0 : (_formattedBlocklet$na = formattedBlocklet.navigation) === null || _formattedBlocklet$na === void 0 ? void 0 : _formattedBlocklet$na.sessionManager, locale) || [];
|
|
40
|
+
// 根据 role 筛选 nav 数据
|
|
54
41
|
localizedNav = (0, _blocklets.filterNavByRole)(localizedNav, sessionCtx === null || sessionCtx === void 0 ? void 0 : (_sessionCtx$session2 = sessionCtx.session) === null || _sessionCtx$session2 === void 0 ? void 0 : (_sessionCtx$session2$ = _sessionCtx$session2.user) === null || _sessionCtx$session2$ === void 0 ? void 0 : _sessionCtx$session2$.role);
|
|
55
|
-
|
|
56
42
|
const renderAddons = () => {
|
|
57
43
|
// 不关心内置的 session manager 和 locale selector, 直接覆盖 UX Header 的 addons
|
|
58
44
|
if (addons && typeof addons !== 'function') {
|
|
59
45
|
return Array.isArray(addons) ? addons : [addons];
|
|
60
46
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
let addonsArray = [];
|
|
48
|
+
// 启用了多语言并且检测到了 locale context
|
|
64
49
|
if (enableLocale && locale) {
|
|
65
50
|
addonsArray.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_selector.default, {
|
|
66
51
|
showText: false
|
|
67
52
|
}, "locale-selector"));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
}
|
|
54
|
+
// 启用了连接钱包并且检测到了 session context
|
|
71
55
|
if (enableConnect && sessionCtx) {
|
|
72
56
|
var _localizedNav;
|
|
73
|
-
|
|
74
57
|
const menu = [];
|
|
75
|
-
|
|
76
58
|
if (authenticated && (_localizedNav = localizedNav) !== null && _localizedNav !== void 0 && _localizedNav[0]) {
|
|
77
59
|
const firstItem = localizedNav[0];
|
|
78
60
|
menu.push({
|
|
@@ -90,28 +72,23 @@ function HeaderAddons(_ref) {
|
|
|
90
72
|
key: firstItem.link
|
|
91
73
|
});
|
|
92
74
|
}
|
|
93
|
-
|
|
94
75
|
addonsArray.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SessionManager.default, _objectSpread({
|
|
95
76
|
session: sessionCtx.session,
|
|
96
77
|
locale: locale,
|
|
97
78
|
menu: menu,
|
|
98
79
|
showRole: true
|
|
99
80
|
}, sessionManagerProps), "session-manager"));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
}
|
|
82
|
+
// 在内置 addons 基础上定制 addons
|
|
103
83
|
if (typeof addons === 'function') {
|
|
104
84
|
addonsArray = addons(addonsArray) || [];
|
|
105
85
|
}
|
|
106
|
-
|
|
107
86
|
return addonsArray;
|
|
108
87
|
};
|
|
109
|
-
|
|
110
88
|
const renderedAddons = renderAddons();
|
|
111
89
|
const addonList = /*#__PURE__*/(0, _react.createElement)(_jsxRuntime.Fragment, null, ...(Array.isArray(renderedAddons) ? renderedAddons : [renderedAddons]));
|
|
112
90
|
return addonList;
|
|
113
91
|
}
|
|
114
|
-
|
|
115
92
|
HeaderAddons.propTypes = {
|
|
116
93
|
formattedBlocklet: _propTypes.default.object.isRequired,
|
|
117
94
|
// 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
|
|
@@ -4,40 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
-
|
|
10
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
-
|
|
12
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
13
|
function hasParentOfType(node, type) {
|
|
17
14
|
if (!node) return false;
|
|
18
15
|
if (type === node.nodeName) return true;
|
|
19
16
|
return hasParentOfType(node.parentNode, type);
|
|
20
17
|
}
|
|
18
|
+
|
|
21
19
|
/**
|
|
22
20
|
* 适用于 header/footer/dashboard "preview mode", 阻止内部组件中所有 link 的默认点击行为
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
22
|
function LinkBlocker(_ref) {
|
|
27
23
|
let rest = Object.assign({}, _ref);
|
|
28
|
-
|
|
29
24
|
const handleOnClick = e => {
|
|
30
25
|
const isInsideLink = hasParentOfType(e.target, 'A');
|
|
31
|
-
|
|
32
26
|
if (isInsideLink) {
|
|
33
27
|
e.preventDefault();
|
|
34
28
|
}
|
|
35
29
|
};
|
|
36
|
-
|
|
37
30
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({
|
|
38
31
|
onClick: handleOnClick
|
|
39
32
|
}, rest));
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
var _default = LinkBlocker;
|
|
43
35
|
exports.default = _default;
|
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = OverridableThemeProvider;
|
|
7
|
-
|
|
8
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
|
|
10
8
|
var _Theme = require("@arcblock/ux/lib/Theme");
|
|
11
|
-
|
|
12
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
const defaultTheme = (0, _Theme.createTheme)();
|
|
12
|
+
|
|
17
13
|
/**
|
|
18
14
|
* 允许 theme 被覆盖的 ThemeProvider 组件, 默认使用 ux default theme, 可以传入 theme 进行覆盖
|
|
19
15
|
*/
|
|
20
|
-
|
|
21
16
|
function OverridableThemeProvider(_ref) {
|
|
22
17
|
let {
|
|
23
18
|
theme: themeOverrides,
|
|
@@ -29,7 +24,6 @@ function OverridableThemeProvider(_ref) {
|
|
|
29
24
|
children: children
|
|
30
25
|
});
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
OverridableThemeProvider.propTypes = {
|
|
34
28
|
children: _propTypes.default.any.isRequired,
|
|
35
29
|
theme: _propTypes.default.object
|
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useWalletHiddenTopbar = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
|
|
11
|
-
|
|
12
9
|
var _dsbridge = _interopRequireDefault(require("dsbridge"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
// 在 wallet webview 环境中, 隐藏 wallet topbar
|
|
17
12
|
// eslint-disable-next-line import/prefer-default-export
|
|
18
13
|
const useWalletHiddenTopbar = () => {
|
|
@@ -23,5 +18,4 @@ const useWalletHiddenTopbar = () => {
|
|
|
23
18
|
}
|
|
24
19
|
}, [browser]);
|
|
25
20
|
};
|
|
26
|
-
|
|
27
21
|
exports.useWalletHiddenTopbar = useWalletHiddenTopbar;
|
package/lib/types.js
CHANGED
|
@@ -4,12 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.sessionManagerProps = exports.blockletMetaProps = void 0;
|
|
7
|
-
|
|
8
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
/* eslint-disable import/prefer-default-export */
|
|
10
|
+
|
|
13
11
|
const blockletMetaProps = _propTypes.default.shape({
|
|
14
12
|
appLogo: _propTypes.default.node,
|
|
15
13
|
appName: _propTypes.default.string,
|
|
@@ -28,9 +26,7 @@ const blockletMetaProps = _propTypes.default.shape({
|
|
|
28
26
|
}))
|
|
29
27
|
}))
|
|
30
28
|
});
|
|
31
|
-
|
|
32
29
|
exports.blockletMetaProps = blockletMetaProps;
|
|
33
|
-
|
|
34
30
|
const sessionManagerProps = _propTypes.default.shape({
|
|
35
31
|
showText: _propTypes.default.bool,
|
|
36
32
|
showRole: _propTypes.default.bool,
|
|
@@ -48,5 +44,4 @@ const sessionManagerProps = _propTypes.default.shape({
|
|
|
48
44
|
dark: _propTypes.default.bool,
|
|
49
45
|
size: _propTypes.default.number
|
|
50
46
|
});
|
|
51
|
-
|
|
52
47
|
exports.sessionManagerProps = sessionManagerProps;
|
package/lib/utils.js
CHANGED
|
@@ -4,13 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.matchPaths = exports.matchPath = exports.mapRecursive = exports.isUrl = exports.isIconifyString = exports.flatRecursive = exports.filterRecursive = exports.countRecursive = void 0;
|
|
7
|
-
|
|
8
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
-
|
|
10
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
9
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
12
|
const mapRecursive = function mapRecursive(array, fn) {
|
|
15
13
|
let childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
16
14
|
return array.map(item => {
|
|
@@ -19,106 +17,88 @@ const mapRecursive = function mapRecursive(array, fn) {
|
|
|
19
17
|
[childrenKey]: mapRecursive(item[childrenKey], fn, childrenKey)
|
|
20
18
|
}));
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
return fn(item);
|
|
24
21
|
});
|
|
25
|
-
};
|
|
26
|
-
|
|
22
|
+
};
|
|
27
23
|
|
|
24
|
+
// 展平有层级结构的 array
|
|
28
25
|
exports.mapRecursive = mapRecursive;
|
|
29
|
-
|
|
30
26
|
const flatRecursive = function flatRecursive(array) {
|
|
31
27
|
let childrenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children';
|
|
32
28
|
const result = [];
|
|
33
29
|
mapRecursive(array, item => result.push(item), childrenKey);
|
|
34
30
|
return result;
|
|
35
|
-
};
|
|
36
|
-
|
|
31
|
+
};
|
|
37
32
|
|
|
33
|
+
// 对有层级结构的 array 元素计数
|
|
38
34
|
exports.flatRecursive = flatRecursive;
|
|
39
|
-
|
|
40
35
|
const countRecursive = function countRecursive(array) {
|
|
41
36
|
let childrenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children';
|
|
42
37
|
let counter = 0;
|
|
43
38
|
mapRecursive(array, () => counter++, childrenKey);
|
|
44
39
|
return counter;
|
|
45
|
-
};
|
|
46
|
-
// 因为是 DFS 遍历, 可以借助 context.filteredChildren 在过滤/保留子结的同时保持父子结构 (即使父结点不满足筛选条件)
|
|
47
|
-
|
|
40
|
+
};
|
|
48
41
|
|
|
42
|
+
// 对有层级结构的 array 进行 filter 处理
|
|
43
|
+
// 因为是 DFS 遍历, 可以借助 context.filteredChildren 在过滤/保留子结的同时保持父子结构 (即使父结点不满足筛选条件)
|
|
49
44
|
exports.countRecursive = countRecursive;
|
|
50
|
-
|
|
51
45
|
const filterRecursive = function filterRecursive(array, predicate) {
|
|
52
46
|
let childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
53
47
|
return array.map(item => _objectSpread({}, item)).filter(item => {
|
|
54
48
|
const children = item[childrenKey];
|
|
55
|
-
|
|
56
49
|
if (Array.isArray(children)) {
|
|
57
50
|
const filtered = filterRecursive(children, predicate, childrenKey);
|
|
58
51
|
item[childrenKey] = filtered !== null && filtered !== void 0 && filtered.length ? filtered : undefined;
|
|
59
52
|
}
|
|
60
|
-
|
|
61
53
|
const context = {
|
|
62
54
|
filteredChildren: item[childrenKey],
|
|
63
55
|
isLeaf: !(children !== null && children !== void 0 && children.length)
|
|
64
56
|
};
|
|
65
57
|
return predicate(item, context);
|
|
66
58
|
});
|
|
67
|
-
};
|
|
68
|
-
|
|
59
|
+
};
|
|
69
60
|
|
|
61
|
+
// "http://", "https://" 2 种情况
|
|
70
62
|
exports.filterRecursive = filterRecursive;
|
|
71
|
-
|
|
72
63
|
const isUrl = str => {
|
|
73
64
|
return /^https?:\/\//.test(str);
|
|
74
65
|
};
|
|
75
|
-
|
|
76
66
|
exports.isUrl = isUrl;
|
|
77
|
-
|
|
78
67
|
const isIconifyString = str => {
|
|
79
68
|
return /^[\w-]+:[\w-]+$/.test(str);
|
|
80
69
|
};
|
|
70
|
+
|
|
81
71
|
/**
|
|
82
72
|
* 检测 path 是否匹配当前 location, path 只考虑 "/" 开头的相对路径
|
|
83
73
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
74
|
exports.isIconifyString = isIconifyString;
|
|
87
|
-
|
|
88
75
|
const matchPath = path => {
|
|
89
76
|
if (!path || !(path !== null && path !== void 0 && path.startsWith('/'))) {
|
|
90
77
|
return false;
|
|
91
78
|
}
|
|
92
|
-
|
|
93
79
|
const ensureTrailingSlash = str => str.endsWith('/') ? str : "".concat(str, "/");
|
|
94
|
-
|
|
95
80
|
const pathname = ensureTrailingSlash(window.location.pathname);
|
|
96
81
|
const normalizedPath = ensureTrailingSlash(new URL(path, window.location.origin).pathname);
|
|
97
82
|
return pathname.startsWith(normalizedPath);
|
|
98
83
|
};
|
|
84
|
+
|
|
99
85
|
/**
|
|
100
86
|
* 从一组 paths 中, 找到匹配当前 location 的 path, 返回序号
|
|
101
87
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
88
|
exports.matchPath = matchPath;
|
|
105
|
-
|
|
106
89
|
const matchPaths = function matchPaths() {
|
|
107
90
|
let paths = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
108
91
|
const matched = paths.map((item, index) => ({
|
|
109
92
|
path: item,
|
|
110
93
|
index
|
|
111
94
|
})).filter(item => matchPath(item.path));
|
|
112
|
-
|
|
113
95
|
if (!(matched !== null && matched !== void 0 && matched.length)) {
|
|
114
96
|
return -1;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
97
|
+
}
|
|
98
|
+
// 多个 path 都匹配时, 取一个最具体 (最长的) path
|
|
118
99
|
const mostSpecific = matched.slice(1).reduce((prev, cur) => {
|
|
119
100
|
return prev.path.length >= cur.path.length ? prev : cur;
|
|
120
101
|
}, matched[0]);
|
|
121
102
|
return mostSpecific.index;
|
|
122
103
|
};
|
|
123
|
-
|
|
124
104
|
exports.matchPaths = matchPaths;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.60",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@arcblock/did-connect": "^2.5.
|
|
35
|
-
"@arcblock/ux": "^2.5.
|
|
34
|
+
"@arcblock/did-connect": "^2.5.60",
|
|
35
|
+
"@arcblock/ux": "^2.5.60",
|
|
36
36
|
"@emotion/react": "^11.10.4",
|
|
37
37
|
"@emotion/styled": "^11.10.4",
|
|
38
38
|
"@iconify/iconify": "^2.2.1",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
55
55
|
"jest": "^28.1.3"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "50a0f90ecfb1d239e04cdfebc16e30d3947db4a2"
|
|
58
58
|
}
|